Add back support for IfcSphere

This commit is contained in:
Thomas Krijnen
2024-04-29 20:54:36 +02:00
parent ae2600afb9
commit 6fdf46f151
5 changed files with 60 additions and 25 deletions
+1
View File
@@ -50,6 +50,7 @@ namespace ifcopenshell { namespace geometry { namespace kernels {
virtual bool convert_impl(const taxonomy::revolve::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); } virtual bool convert_impl(const taxonomy::revolve::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
virtual bool convert_impl(const taxonomy::bspline_surface::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); } virtual bool convert_impl(const taxonomy::bspline_surface::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
virtual bool convert_impl(const taxonomy::cylinder::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); } virtual bool convert_impl(const taxonomy::cylinder::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
virtual bool convert_impl(const taxonomy::sphere::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
virtual bool convert_impl(const taxonomy::solid::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); } virtual bool convert_impl(const taxonomy::solid::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
virtual bool convert_impl(const taxonomy::surface_curve_sweep::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); } virtual bool convert_impl(const taxonomy::surface_curve_sweep::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
virtual bool convert_impl(const taxonomy::loft::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); } virtual bool convert_impl(const taxonomy::loft::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
+24 -7
View File
@@ -24,6 +24,7 @@
#include <BRepPrimAPI_MakePrism.hxx> #include <BRepPrimAPI_MakePrism.hxx>
#include <BRepAlgoAPI_Common.hxx> #include <BRepAlgoAPI_Common.hxx>
#include <ShapeFix_Solid.hxx> #include <ShapeFix_Solid.hxx>
#include <BRepPrimAPI_MakeSphere.hxx>
using namespace ifcopenshell::geometry; using namespace ifcopenshell::geometry;
using namespace ifcopenshell::geometry::kernels; using namespace ifcopenshell::geometry::kernels;
@@ -64,18 +65,34 @@ bool OpenCascadeKernel::convert(const taxonomy::solid::ptr solid, TopoDS_Shape&
result = halfspace; result = halfspace;
return true; return true;
} else if (solid->children.size() == 1
&& solid->children[0]->children.size() == 1
&& solid->children[0]->children[0]->basis
&& solid->children[0]->children[0]->basis->kind() == taxonomy::SPHERE)
{
auto sphere = taxonomy::cast<taxonomy::sphere>(solid->children[0]->children[0]->basis);
gp_GTrsf gtrsf;
convert(sphere->matrix, gtrsf);
BRepPrimAPI_MakeSphere builder(sphere->radius);
auto s = builder.Solid();
s.Move(gtrsf.Trsf());
result = s;
return true;
} }
for (auto& s : solid->children) { for (auto& s : solid->children) {
TopoDS_Shape shl; TopoDS_Shape shl;
convert(s, shl); if (convert(s, shl)) {
if (shl.ShapeType() == TopAbs_SHELL) { if (shl.ShapeType() == TopAbs_SHELL) {
ShapeFix_Solid solid; ShapeFix_Solid solid;
S = solid.SolidFromShell(TopoDS::Shell(shl)); S = solid.SolidFromShell(TopoDS::Shell(shl));
} else if (solid->children.size() == 1) { } else if (solid->children.size() == 1) {
S = shl; S = shl;
} else {
throw std::runtime_error("Unexpected configuration of subshapes");
}
} else { } else {
throw std::runtime_error("Unexpected configuration of subshapes"); Logger::Warning("Ignored shell", s->instance);
} }
} }
if (!S.IsNull()) { if (!S.IsNull()) {
+10 -14
View File
@@ -22,18 +22,14 @@
using namespace ifcopenshell::geometry; using namespace ifcopenshell::geometry;
taxonomy::ptr mapping::map_impl(const IfcSchema::IfcSphere* inst) { taxonomy::ptr mapping::map_impl(const IfcSchema::IfcSphere* inst) {
// @todo auto sol = taxonomy::make<taxonomy::solid>();
return nullptr; auto shl = taxonomy::make<taxonomy::shell>();
/* auto fac = taxonomy::make<taxonomy::face>();
const double r = inst->Radius() * length_unit_; auto spr = taxonomy::make<taxonomy::sphere>();
spr->matrix = taxonomy::cast<taxonomy::matrix4>(map(inst->Position()));
BRepPrimAPI_MakeSphere builder(r); spr->radius = inst->Radius() * length_unit_;
gp_Trsf trsf; fac->basis = spr;
IfcGeom::Kernel::convert(inst->Position(),trsf); shl->children.push_back(fac);
sol->children.push_back(shl);
// IfcCsgPrimitive3D.Position has unit scale factor return sol;
shape = builder.Solid().Moved(trsf);
return true;
*/
} }
+5 -1
View File
@@ -149,6 +149,10 @@ namespace {
throw std::runtime_error("not implemented"); throw std::runtime_error("not implemented");
} }
bool compare(const sphere&, const sphere&) {
throw std::runtime_error("not implemented");
}
bool compare(const surface_curve_sweep&, const surface_curve_sweep&) { bool compare(const surface_curve_sweep&, const surface_curve_sweep&) {
throw std::runtime_error("not implemented"); throw std::runtime_error("not implemented");
} }
@@ -512,7 +516,7 @@ const std::string& ifcopenshell::geometry::taxonomy::kind_to_string(kinds k) {
using namespace std::string_literals; using namespace std::string_literals;
static std::string values[] = { static std::string values[] = {
"matrix4"s, "point3"s, "direction3"s, "line"s, "circle"s, "ellipse"s, "bspline_curve"s, "offset_curve"s, "plane"s, "cylinder"s, "bspline_surface"s, "edge"s, "loop"s, "face"s, "shell"s, "solid"s, "loft"s, "extrusion"s, "revolve"s, "surface_curve_sweep"s, "node"s, "collection"s, "boolean_result"s, "piecewise_function"s, "colour"s, "style"s, "matrix4"s, "point3"s, "direction3"s, "line"s, "circle"s, "ellipse"s, "bspline_curve"s, "offset_curve"s, "plane"s, "cylinder"s, "sphere"s, "bspline_surface"s, "edge"s, "loop"s, "face"s, "shell"s, "solid"s, "loft"s, "extrusion"s, "revolve"s, "surface_curve_sweep"s, "node"s, "collection"s, "boolean_result"s, "piecewise_function"s, "colour"s, "style"s,
}; };
return values[k]; return values[k];
+20 -3
View File
@@ -90,7 +90,7 @@ typedef item const* ptr;
topology_error(const char* const s) : std::runtime_error(s) {} topology_error(const char* const s) : std::runtime_error(s) {}
}; };
enum kinds { MATRIX4, POINT3, DIRECTION3, LINE, CIRCLE, ELLIPSE, BSPLINE_CURVE, OFFSET_CURVE, PLANE, CYLINDER, BSPLINE_SURFACE, EDGE, LOOP, FACE, SHELL, SOLID, LOFT, EXTRUSION, REVOLVE, SURFACE_CURVE_SWEEP, NODE, COLLECTION, BOOLEAN_RESULT, PIECEWISE_FUNCTION, COLOUR, STYLE }; enum kinds { MATRIX4, POINT3, DIRECTION3, LINE, CIRCLE, ELLIPSE, BSPLINE_CURVE, OFFSET_CURVE, PLANE, CYLINDER, SPHERE, BSPLINE_SURFACE, EDGE, LOOP, FACE, SHELL, SOLID, LOFT, EXTRUSION, REVOLVE, SURFACE_CURVE_SWEEP, NODE, COLLECTION, BOOLEAN_RESULT, PIECEWISE_FUNCTION, COLOUR, STYLE };
const std::string& kind_to_string(kinds k); const std::string& kind_to_string(kinds k);
@@ -875,6 +875,23 @@ typedef item const* ptr;
} }
}; };
struct sphere : public surface {
DECLARE_PTR(sphere)
double radius;
virtual sphere* clone_() const { return new sphere(*this); }
virtual kinds kind() const { return SPHERE; }
void print(std::ostream& o, int) const {
o << "not implemented";
}
virtual size_t calc_hash() const {
auto v = std::make_tuple(static_cast<size_t>(SPHERE), matrix->hash_components());
return boost::hash<decltype(v)>{}(v);
}
};
struct bspline_surface : public surface { struct bspline_surface : public surface {
DECLARE_PTR(bspline_surface) DECLARE_PTR(bspline_surface)
@@ -1037,9 +1054,9 @@ typedef item const* ptr;
}; };
namespace impl { namespace impl {
typedef std::tuple<matrix4, point3, direction3, line, circle, ellipse, bspline_curve, offset_curve, plane, cylinder, bspline_surface, edge, loop, face, shell, solid, loft, extrusion, revolve, surface_curve_sweep, node, collection, boolean_result, piecewise_function> KindsTuple; typedef std::tuple<matrix4, point3, direction3, line, circle, ellipse, bspline_curve, offset_curve, plane, cylinder, sphere, bspline_surface, edge, loop, face, shell, solid, loft, extrusion, revolve, surface_curve_sweep, node, collection, boolean_result, piecewise_function> KindsTuple;
typedef std::tuple<line, circle, ellipse, bspline_curve, offset_curve, loop, edge> CurvesTuple; typedef std::tuple<line, circle, ellipse, bspline_curve, offset_curve, loop, edge> CurvesTuple;
typedef std::tuple<plane, cylinder, bspline_surface> SurfacesTuple; typedef std::tuple<plane, cylinder, sphere, bspline_surface> SurfacesTuple;
} }
struct type_by_kind { struct type_by_kind {