Skip to content

Commit 250fad6

Browse files
committed
--unify-shapes setting
1 parent 461e3d4 commit 250fad6

5 files changed

Lines changed: 39 additions & 204 deletions

File tree

src/ifcgeom/AbstractKernel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ namespace ifcopenshell { namespace geometry { namespace kernels {
7070
virtual bool apply_folded_layerset(IfcGeom::ConversionResults&, const ifcopenshell::geometry::layerset_information&, const std::map<IfcUtil::IfcBaseEntity*, ifcopenshell::geometry::layerset_information>&) { throw std::runtime_error("Not implemented"); }
7171
virtual bool convert_openings(const IfcUtil::IfcBaseEntity* entity, const std::vector<std::pair<taxonomy::ptr, ifcopenshell::geometry::taxonomy::matrix4>>& openings,
7272
const IfcGeom::ConversionResults& entity_shapes, const ifcopenshell::geometry::taxonomy::matrix4& entity_trsf, IfcGeom::ConversionResults& cut_shapes) = 0;
73-
73+
virtual bool unify_shapes(const IfcGeom::ConversionResults&, IfcGeom::ConversionResults&) { throw std::runtime_error("Unification of shapes not implemented in this kernel"); }
7474
};
7575

7676
AbstractKernel* construct(IfcParse::IfcFile* file, const std::string& geometry_library, Settings& conv_settings);

src/ifcgeom/ConversionSettings.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ namespace ifcopenshell {
201201
static constexpr bool defaultvalue = false;
202202
};
203203

204+
struct UnifyShapes : public SettingBase<UnifyShapes, bool> {
205+
static constexpr const char* const name = "unify-shapes";
206+
static constexpr const char* const description = "Unify adjacent co-planar and co-linear subshapes (topological entities "
207+
"sharing the same geometric domain) before triangulation or further processing";
208+
static constexpr bool defaultvalue = false;
209+
};
210+
204211
struct UseMaterialNames : public SettingBase<UseMaterialNames, bool> {
205212
static constexpr const char* const name = "use-material-names";
206213
static constexpr const char* const description = "Use material names instead of unique IDs for naming materials upon serialization. "
@@ -493,7 +500,7 @@ namespace ifcopenshell {
493500
};
494501

495502
class IFC_GEOM_API Settings : public SettingsContainer<
496-
std::tuple<MesherLinearDeflection, MesherAngularDeflection, ReorientShells, LengthUnit, PlaneUnit, Precision, OutputDimensionality, LayersetFirst, DisableBooleanResult, NoWireIntersectionCheck, NoWireIntersectionTolerance, PrecisionFactor, DebugBooleanOperations, BooleanAttempt2d, SurfaceColour, WeldVertices, UseWorldCoords, UseMaterialNames, ConvertBackUnits, ContextIds, ContextTypes, ContextIdentifiers, IteratorOutput, DisableOpeningSubtractions, ApplyDefaultMaterials, DontEmitNormals, GenerateUvs, ApplyLayerSets, UseElementHierarchy, ValidateQuantities, EdgeArrows, BuildingLocalPlacement, SiteLocalPlacement, ForceSpaceTransparency, CircleSegments, KeepBoundingBoxes, PiecewiseStepType, PiecewiseStepParam, NoParallelMapping, ModelOffset, ModelRotation, TriangulationType>
503+
std::tuple<MesherLinearDeflection, MesherAngularDeflection, ReorientShells, LengthUnit, PlaneUnit, Precision, OutputDimensionality, LayersetFirst, DisableBooleanResult, NoWireIntersectionCheck, NoWireIntersectionTolerance, PrecisionFactor, DebugBooleanOperations, BooleanAttempt2d, SurfaceColour, WeldVertices, UseWorldCoords, UnifyShapes, UseMaterialNames, ConvertBackUnits, ContextIds, ContextTypes, ContextIdentifiers, IteratorOutput, DisableOpeningSubtractions, ApplyDefaultMaterials, DontEmitNormals, GenerateUvs, ApplyLayerSets, UseElementHierarchy, ValidateQuantities, EdgeArrows, BuildingLocalPlacement, SiteLocalPlacement, ForceSpaceTransparency, CircleSegments, KeepBoundingBoxes, PiecewiseStepType, PiecewiseStepParam, NoParallelMapping, ModelOffset, ModelRotation, TriangulationType>
497504
>
498505
{};
499506
}

src/ifcgeom/Converter.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -208,29 +208,37 @@ IfcGeom::BRepElement* ifcopenshell::geometry::Converter::create_brep_for_represe
208208
Logger::Message(Logger::LOG_ERROR, "Error processing openings for:", product);
209209
}
210210

211-
if (caught_error && opened_shapes.size() < shapes.size()) {
212-
opened_shapes = shapes;
213-
}
214-
215-
if (settings_.get<ifcopenshell::geometry::settings::UseWorldCoords>().get()) {
216-
for (auto it = opened_shapes.begin(); it != opened_shapes.end(); ++it) {
217-
it->prepend(place);
211+
if (!(caught_error && opened_shapes.size() < shapes.size())) {
212+
if (settings_.get<ifcopenshell::geometry::settings::UseWorldCoords>().get()) {
213+
for (auto it = opened_shapes.begin(); it != opened_shapes.end(); ++it) {
214+
it->prepend(place);
215+
}
216+
place = ifcopenshell::geometry::taxonomy::make<ifcopenshell::geometry::taxonomy::matrix4>();
217+
representation_id_builder << "-world-coords";
218218
}
219-
place = ifcopenshell::geometry::taxonomy::make<ifcopenshell::geometry::taxonomy::matrix4>();
220-
representation_id_builder << "-world-coords";
219+
shapes = opened_shapes;
221220
}
222-
shape = new IfcGeom::Representation::BRep(settings_, product_type, representation_id_builder.str(), opened_shapes);
223221
} else if (settings_.get<ifcopenshell::geometry::settings::UseWorldCoords>().get()) {
224222
for (auto it = shapes.begin(); it != shapes.end(); ++it) {
225223
it->prepend(place);
226224
}
227225
place = ifcopenshell::geometry::taxonomy::make<ifcopenshell::geometry::taxonomy::matrix4>();
228226
representation_id_builder << "-world-coords";
229-
shape = new IfcGeom::Representation::BRep(settings_, product_type, representation_id_builder.str(), shapes);
230-
} else {
231-
shape = new IfcGeom::Representation::BRep(settings_, product_type, representation_id_builder.str(), shapes);
232227
}
233228

229+
if (settings_.get<ifcopenshell::geometry::settings::UnifyShapes>().get()) {
230+
IfcGeom::ConversionResults unified_shapes;
231+
try {
232+
if (kernel_->unify_shapes(shapes, unified_shapes)) {
233+
std::swap(shapes, unified_shapes);
234+
}
235+
} catch (std::exception& e) {
236+
Logger::Error(e);
237+
}
238+
}
239+
240+
shape = new IfcGeom::Representation::BRep(settings_, product_type, representation_id_builder.str(), shapes);
241+
234242
std::string context_string = "";
235243

236244
// IfcShapeRepresentation.

src/ifcgeom/kernels/opencascade/OpenCascadeKernel.cpp

Lines changed: 8 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -23,175 +23,12 @@
2323
* *
2424
********************************************************************************/
2525

26-
// #include <set>
27-
// #include <algorithm>
28-
// #include <numeric>
29-
//
30-
// #include <Standard_Version.hxx>
31-
//
32-
// #include <gp_Pnt.hxx>
33-
// #include <gp_Vec.hxx>
34-
// #include <gp_Dir.hxx>
35-
// #include <gp_Pnt2d.hxx>
36-
// #include <gp_GTrsf.hxx>
37-
// #include <gp_GTrsf2d.hxx>
38-
// #include <gp_Trsf.hxx>
39-
// #include <gp_Trsf2d.hxx>
40-
// #include <gp_Ax3.hxx>
41-
// #include <gp_Pln.hxx>
42-
//
43-
// #include <Geom_Line.hxx>
44-
// #include <Geom_Circle.hxx>
45-
//
46-
// #include <Geom_Plane.hxx>
47-
// #include <Geom_OffsetCurve.hxx>
48-
// #include <Geom_OffsetSurface.hxx>
49-
// #include <Geom_CylindricalSurface.hxx>
50-
// #include <Geom_SurfaceOfLinearExtrusion.hxx>
51-
//
52-
// #include <GeomAPI_IntCS.hxx>
53-
// #include <GeomAPI_IntSS.hxx>
54-
//
55-
// #include <BRepBndLib.hxx>
56-
// #include <BRepOffsetAPI_Sewing.hxx>
57-
// #include <BRepBuilderAPI_MakeFace.hxx>
58-
// #include <BRepBuilderAPI_MakeEdge.hxx>
59-
// #include <BRepBuilderAPI_MakeWire.hxx>
60-
// #include <BRepBuilderAPI_MakePolygon.hxx>
61-
// #include <BRepBuilderAPI_MakeVertex.hxx>
62-
//
63-
// #include <TopoDS.hxx>
64-
// #include <TopoDS_Wire.hxx>
65-
// #include <TopoDS_Face.hxx>
66-
// #include <TopoDS_CompSolid.hxx>
67-
//
68-
// #include <TopExp.hxx>
69-
// #include <TopExp_Explorer.hxx>
70-
//
71-
// #include <BRepPrimAPI_MakePrism.hxx>
72-
// #include <BRepBuilderAPI_MakeShell.hxx>
73-
// #include <BRepBuilderAPI_MakeSolid.hxx>
74-
// #include <BRepPrimAPI_MakeHalfSpace.hxx>
75-
// #include <BRepAlgoAPI_Cut.hxx>
76-
// #include <BRepAlgoAPI_Fuse.hxx>
77-
// #include <BRepAlgoAPI_Common.hxx>
78-
// #include <BRepAlgoAPI_BooleanOperation.hxx>
79-
// #if OCC_VERSION_HEX >= 0x70200
80-
// #include <BRepAlgoAPI_Splitter.hxx>
81-
// #endif
82-
//
83-
// #include <BRepAlgo_NormalProjection.hxx>
84-
//
85-
// #include <ShapeFix_Shape.hxx>
86-
// #include <ShapeFix_ShapeTolerance.hxx>
87-
// #include <ShapeFix_Solid.hxx>
88-
// #include <ShapeFix_Shell.hxx>
89-
//
90-
// #include <ShapeAnalysis_Curve.hxx>
91-
// #include <ShapeAnalysis_Surface.hxx>
92-
//
93-
//
94-
// #include <BRepFilletAPI_MakeFillet2d.hxx>
95-
//
96-
// #include <TopLoc_Location.hxx>
97-
//
98-
// #include <GProp_GProps.hxx>
99-
// #include <BRepGProp.hxx>
100-
//
101-
// #include <BRepBuilderAPI_Transform.hxx>
102-
// #include <BRepBuilderAPI_GTransform.hxx>
103-
//
104-
// #include <BRepGProp_Face.hxx>
105-
// #include <BRepCheck.hxx>
106-
// #include <BRepCheck_Analyzer.hxx>
107-
//
108-
// #include <BRepMesh_IncrementalMesh.hxx>
109-
// #include <BRepTools.hxx>
110-
// #include <BRepTools_WireExplorer.hxx>
111-
//
112-
// #include <Poly_Triangulation.hxx>
113-
// #include <Poly_Array1OfTriangle.hxx>
114-
//
115-
// #include <TopTools_IndexedMapOfShape.hxx>
116-
// #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
117-
//
118-
// #include <BOPAlgo_PaveFiller.hxx>
119-
//
120-
// #include <GCPnts_AbscissaPoint.hxx>
121-
//
122-
// #include <BRepClass3d_SolidClassifier.hxx>
123-
//
124-
// #include <GeomAPI_ExtremaCurveCurve.hxx>
125-
//
126-
// #include <Extrema_ExtCS.hxx>
127-
//
128-
// #include <ShapeAnalysis_Edge.hxx>
129-
//
130-
// #if OCC_VERSION_HEX >= 0x70200
131-
// #include <BOPAlgo_Alerts.hxx>
132-
// #endif
133-
//
134-
// #include "../../../ifcparse/macros.h"
135-
// #include "../../../ifcparse/IfcSIPrefix.h"
136-
//
137-
// #include "../../../ifcparse/IfcFile.h"
138-
//
139-
14026
#include "OpenCascadeKernel.h"
14127

142-
// #include "IfcGeomTree.h"
143-
14428
#include "boolean_utils.h"
145-
146-
// #include "wire_utils.h"
147-
14829
#include "base_utils.h"
14930

150-
// #include "layerset.h"
151-
//
152-
// #include <memory>
153-
// #include <thread>
154-
//
155-
// #if OCC_VERSION_HEX < 0x60900
156-
// #ifdef _MSC_VER
157-
// #pragma message("warning: You are linking against Open CASCADE version " OCC_VERSION_COMPLETE ". Version 6.9.0 introduces various improvements with relation to boolean operations. You are advised to upgrade.")
158-
// #else
159-
// #warning "You are linking against an older version of Open CASCADE. Version 6.9.0 introduces various improvements with relation to boolean operations. You are advised to upgrade."
160-
// #endif
161-
// #endif
162-
//
163-
// namespace {
164-
// struct POSTFIX_SCHEMA(factory_t) {
165-
// IfcGeom::Kernel* operator()(IfcParse::IfcFile* file) const {
166-
// IfcGeom::POSTFIX_SCHEMA(Kernel)* k = new IfcGeom::POSTFIX_SCHEMA(Kernel);
167-
// if (file) {
168-
//
169-
// }
170-
// return k;
171-
// }
172-
// };
173-
// }
174-
//
175-
// void MAKE_INIT_FN(KernelImplementation_)(IfcGeom::impl::KernelFactoryImplementation* mapping) {
176-
// static const std::string schema_name = STRINGIFY(IfcSchema);
177-
// POSTFIX_SCHEMA(factory_t) factory;
178-
// mapping->bind(schema_name, factory);
179-
// }
180-
//
181-
// #define Kernel POSTFIX_SCHEMA(Kernel)
182-
//
183-
// void IfcGeom::Kernel::set_offset(const std::array<double, 3> &p_offset) {
184-
// offset = gp_Vec(p_offset[0], p_offset[1], p_offset[2]);
185-
//
186-
// offset_and_rotation = util::combine_offset_and_rotation(offset, rotation);
187-
// }
188-
//
189-
// void IfcGeom::Kernel::set_rotation(const std::array<double, 4> &p_rotation) {
190-
// rotation = gp_Quaternion(p_rotation[0], p_rotation[1], p_rotation[2], p_rotation[3]);
191-
//
192-
// offset_and_rotation = util::combine_offset_and_rotation(offset, rotation);
193-
// }
194-
//
31+
#include <BRepPrimAPI_MakeRevol.hxx>
19532

19633
namespace {
19734
struct opening_sorter {
@@ -391,7 +228,13 @@ bool IfcGeom::OpenCascadeKernel::convert_openings(const IfcUtil::IfcBaseEntity*
391228
return true;
392229
}
393230

394-
#include <BRepPrimAPI_MakeRevol.hxx>
231+
bool IfcGeom::OpenCascadeKernel::unify_shapes(const IfcGeom::ConversionResults& input, IfcGeom::ConversionResults& output) {
232+
std::transform(input.begin(), input.end(), std::back_inserter(output), [this](auto v) {
233+
auto& s = std::static_pointer_cast<OpenCascadeShape>(v.Shape())->shape();
234+
return IfcGeom::ConversionResult(v.ItemId(), new OpenCascadeShape(util::unify(s, settings_.get<ifcopenshell::geometry::settings::Precision>().get())), v.StylePtr());
235+
});
236+
return true;
237+
}
395238

396239
bool IfcGeom::OpenCascadeKernel::convert_impl(const taxonomy::revolve::ptr r, IfcGeom::ConversionResults& results) {
397240

src/ifcgeom/kernels/opencascade/OpenCascadeKernel.h

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,6 @@ class IFC_GEOM_API OpenCascadeKernel : public ifcopenshell::geometry::kernels::A
7979
bool non_manifold_;
8080

8181
void loop_(const ifcopenshell::geometry::taxonomy::loop::ptr ps, const std::function<void(int, int, bool)>& callback);
82-
83-
/*
84-
bool construct(const IfcSchema::IfcCartesianPoint* cp, gp_Pnt* l);
85-
bool construct(const std::vector<double>& cp, gp_Pnt* l);
86-
87-
const void* get_idx(const IfcSchema::IfcCartesianPoint* cp) {
88-
return cp;
89-
}
90-
91-
const void* get_idx(const std::vector<double>& cp) {
92-
return &cp;
93-
}
94-
95-
std::vector<const void*> get_idxs(const IfcSchema::IfcPolyLoop* lp);
96-
std::vector<const void*> get_idxs(const std::vector<int>& it);
97-
*/
9882
public:
9983
faceset_helper(OpenCascadeKernel* kernel, const ifcopenshell::geometry::taxonomy::shell::ptr l);
10084
~faceset_helper();
@@ -111,15 +95,7 @@ class IFC_GEOM_API OpenCascadeKernel : public ifcopenshell::geometry::kernels::A
11195

11296
faceset_helper* faceset_helper_;
11397

114-
// @todo these should be moved to the mapping
115-
/*
116-
gp_Vec offset = gp_Vec{0.0, 0.0, 0.0};
117-
gp_Quaternion rotation = gp_Quaternion{};
118-
gp_Trsf offset_and_rotation = gp_Trsf();
119-
*/
120-
12198
double precision_;
122-
12399
public:
124100
OpenCascadeKernel(const ifcopenshell::geometry::Settings& settings)
125101
: AbstractKernel("opencascade", settings)
@@ -150,6 +126,7 @@ class IFC_GEOM_API OpenCascadeKernel : public ifcopenshell::geometry::kernels::A
150126

151127
virtual bool convert_openings(const IfcUtil::IfcBaseEntity* entity, const std::vector<std::pair<ifcopenshell::geometry::taxonomy::ptr, ifcopenshell::geometry::taxonomy::matrix4>>& openings,
152128
const IfcGeom::ConversionResults& entity_shapes, const ifcopenshell::geometry::taxonomy::matrix4& entity_trsf, IfcGeom::ConversionResults& cut_shapes);
129+
virtual bool unify_shapes(const IfcGeom::ConversionResults& input, IfcGeom::ConversionResults& output);
153130

154131
typedef boost::variant<Handle(Geom_Curve), TopoDS_Wire> curve_creation_visitor_result_type;
155132
curve_creation_visitor_result_type convert_curve(const ifcopenshell::geometry::taxonomy::ptr);

0 commit comments

Comments
 (0)