Skip to content

Commit d4efcd4

Browse files
committed
Advanced brep, sweeps and various fixes #4848 #4895
1 parent 9485190 commit d4efcd4

19 files changed

+537
-219
lines changed

src/ifcgeom/AbstractKernel.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ namespace ifcopenshell { namespace geometry { namespace kernels {
5454
virtual bool convert_impl(const taxonomy::bspline_surface::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
5555
virtual bool convert_impl(const taxonomy::cylinder::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
5656
virtual bool convert_impl(const taxonomy::sphere::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
57+
virtual bool convert_impl(const taxonomy::torus::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
5758
virtual bool convert_impl(const taxonomy::solid::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
58-
virtual bool convert_impl(const taxonomy::surface_curve_sweep::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
59+
virtual bool convert_impl(const taxonomy::sweep_along_curve::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
5960
virtual bool convert_impl(const taxonomy::loft::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
6061
virtual bool convert_impl(const taxonomy::collection::ptr, IfcGeom::ConversionResults&);
6162
virtual bool convert_impl(const taxonomy::piecewise_function::ptr item, IfcGeom::ConversionResults& cs);
@@ -107,7 +108,7 @@ namespace {
107108
static bool dispatch(const ifcopenshell::geometry::taxonomy::ptr item, T& visitor) {
108109
// @todo it should be possible to eliminate this dynamic_cast when there is a static equivalent to kind()
109110
auto v = ifcopenshell::geometry::taxonomy::template dcast<ifcopenshell::geometry::taxonomy::curves::type<N>>(item);
110-
if (v) {
111+
if (v && item->kind() == v->kind()) {
111112
visitor(v);
112113
return true;
113114
} else {
@@ -123,6 +124,28 @@ namespace {
123124
return false;
124125
}
125126
};
127+
128+
/* A compile-time for loop over the curve kinds */
129+
template <typename T, size_t N = 0>
130+
struct dispatch_surface_creation {
131+
static bool dispatch(const ifcopenshell::geometry::taxonomy::ptr item, T& visitor) {
132+
auto v = ifcopenshell::geometry::taxonomy::template dcast<ifcopenshell::geometry::taxonomy::surfaces::type<N>>(item);
133+
if (v && item->kind() == v->kind()) {
134+
visitor(v);
135+
return true;
136+
} else {
137+
return dispatch_surface_creation<T, N + 1>::dispatch(item, visitor);
138+
}
139+
}
140+
};
141+
142+
template <typename T>
143+
struct dispatch_surface_creation<T, ifcopenshell::geometry::taxonomy::surfaces::max> {
144+
static bool dispatch(const ifcopenshell::geometry::taxonomy::ptr item, T&) {
145+
Logger::Error("No conversion for " + std::to_string(item->kind()));
146+
return false;
147+
}
148+
};
126149
}
127150

128151
#endif

src/ifcgeom/kernels/cgal/CgalKernel.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ namespace {
354354
double u;
355355
typedef void result_type;
356356

357+
void operator()(const boost::blank&) {
358+
throw std::runtime_error("Unbounded curve not supported here");
359+
}
360+
357361
void operator()(const taxonomy::point3::ptr& p) {
358362
point_projection_visitor_ v{ *p };
359363
dispatch_curve_creation<point_projection_visitor_>::dispatch(curve, v);
@@ -1121,7 +1125,7 @@ bool CgalKernel::convert(const taxonomy::extrusion::ptr extrusion, cgal_shape_t
11211125
}
11221126

11231127
std::list<cgal_face_t> bottom_face;
1124-
if (!convert(extrusion->basis, bottom_face) || bottom_face.size() != 1) {
1128+
if (!convert(taxonomy::cast<taxonomy::face>(taxonomy::cast<taxonomy::face>(extrusion->basis)), bottom_face) || bottom_face.size() != 1) {
11251129
return false;
11261130
}
11271131

@@ -1542,8 +1546,9 @@ bool CgalKernel::process_as_2d_polygon(const taxonomy::boolean_result::ptr br, s
15421546
try {
15431547
std::transform(extrusions.begin(), extrusions.end(), std::back_inserter(wires), [this](extrusion_pair& p) {
15441548
auto ex = p.second;
1545-
if (ex->basis->children.size() == 1 && ex->basis->children[0]->kind() == taxonomy::LOOP) {
1546-
auto l = (taxonomy::loop::ptr) ex->basis->children[0];
1549+
auto ex_basis = taxonomy::cast<taxonomy::face>(ex->basis);
1550+
if (ex_basis->children.size() == 1 && ex_basis->children[0]->kind() == taxonomy::LOOP) {
1551+
auto l = (taxonomy::loop::ptr) ex_basis->children[0];
15471552
cgal_wire_t w;
15481553
cgal_placement_t trsf;
15491554
convert_placement(ex->matrix, trsf);

src/ifcgeom/kernels/opencascade/OpenCascadeKernel.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class IFC_GEOM_API OpenCascadeKernel : public ifcopenshell::geometry::kernels::A
135135
bool convert(const ifcopenshell::geometry::taxonomy::solid::ptr, TopoDS_Shape&);
136136
bool convert(const ifcopenshell::geometry::taxonomy::loft::ptr, TopoDS_Shape&);
137137
bool convert(const ifcopenshell::geometry::taxonomy::bspline_surface::ptr bs, Handle(Geom_Surface) surf);
138+
bool convert(const ifcopenshell::geometry::taxonomy::sweep_along_curve::ptr, TopoDS_Shape&);
138139

139140
virtual bool convert_impl(const ifcopenshell::geometry::taxonomy::edge::ptr, IfcGeom::ConversionResults&);
140141
virtual bool convert_impl(const ifcopenshell::geometry::taxonomy::loop::ptr, IfcGeom::ConversionResults&);
@@ -144,10 +145,15 @@ class IFC_GEOM_API OpenCascadeKernel : public ifcopenshell::geometry::kernels::A
144145
virtual bool convert_impl(const ifcopenshell::geometry::taxonomy::extrusion::ptr, IfcGeom::ConversionResults&);
145146
virtual bool convert_impl(const ifcopenshell::geometry::taxonomy::boolean_result::ptr, IfcGeom::ConversionResults&);
146147
virtual bool convert_impl(const ifcopenshell::geometry::taxonomy::loft::ptr, IfcGeom::ConversionResults&);
148+
virtual bool convert_impl(const ifcopenshell::geometry::taxonomy::sweep_along_curve::ptr, IfcGeom::ConversionResults&);
147149

148150
virtual bool convert_openings(const IfcUtil::IfcBaseEntity* entity, const std::vector<std::pair<ifcopenshell::geometry::taxonomy::ptr, ifcopenshell::geometry::taxonomy::matrix4>>& openings,
149151
const IfcGeom::ConversionResults& entity_shapes, const ifcopenshell::geometry::taxonomy::matrix4& entity_trsf, IfcGeom::ConversionResults& cut_shapes);
150152

153+
typedef boost::variant<Handle(Geom_Curve), TopoDS_Wire> curve_creation_visitor_result_type;
154+
curve_creation_visitor_result_type convert_curve(const ifcopenshell::geometry::taxonomy::ptr);
155+
Handle(Geom_Surface) convert_surface(const ifcopenshell::geometry::taxonomy::ptr);
156+
151157
template <typename T, typename U>
152158
static T convert_xyz(const U& u) {
153159
const auto& vs = u.ccomponents();

src/ifcgeom/kernels/opencascade/extrusion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ bool OpenCascadeKernel::convert(const taxonomy::extrusion::ptr extrusion, TopoDS
1515
}
1616

1717
TopoDS_Shape face;
18-
if (!convert(extrusion->basis, face)) {
18+
if (!convert(taxonomy::cast<taxonomy::face>(extrusion->basis), face)) {
1919
return false;
2020
}
2121

0 commit comments

Comments
 (0)