Skip to content

Commit 2554280

Browse files
committed
triangulation-type setting for non-triangulated polyhedral from iterator
1 parent 748fcce commit 2554280

File tree

12 files changed

+320
-154
lines changed

12 files changed

+320
-154
lines changed

src/ifcgeom/ConversionSettings.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,19 @@ std::istream& ifcopenshell::geometry::settings::operator>>(std::istream& in, Out
7878
}
7979
return in;
8080
}
81+
82+
std::istream& ifcopenshell::geometry::settings::operator>>(std::istream& in, TriangulationMethod& v) {
83+
std::string token;
84+
in >> token;
85+
boost::to_upper(token);
86+
if (token == "TRIANGLE_MESH") {
87+
v = TRIANGLE_MESH;
88+
} else if (token == "POLYHEDRON_WITHOUT_HOLES") {
89+
v = POLYHEDRON_WITHOUT_HOLES;
90+
} else if (token == "POLYHEDRON_WITH_HOLES") {
91+
v = POLYHEDRON_WITH_HOLES;
92+
} else {
93+
in.setstate(std::ios_base::failbit);
94+
}
95+
return in;
96+
}

src/ifcgeom/ConversionSettings.h

Lines changed: 18 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,28 @@ namespace ifcopenshell {
378378
static constexpr const char* const name = "model-rotation";
379379
static constexpr const char* const description = "Applies an arbitrary quaternion rotation of form 'x,y,z,w' to all placements.";
380380
};
381+
382+
enum TriangulationMethod {
383+
TRIANGLE_MESH,
384+
POLYHEDRON_WITHOUT_HOLES,
385+
POLYHEDRON_WITH_HOLES
386+
};
387+
388+
std::istream& operator>>(std::istream& in, TriangulationMethod& ioo);
389+
390+
struct TriangulationType : public SettingBase<TriangulationType, TriangulationMethod> {
391+
static constexpr const char* const name = "triangulation-type";
392+
static constexpr const char* const description = "Type of planar facet to be emitted";
393+
static constexpr TriangulationMethod defaultvalue = TRIANGLE_MESH;
394+
};
395+
396+
381397
}
382398

383399
template <typename settings_t>
384400
class IFC_GEOM_API SettingsContainer {
385401
public:
386-
typedef boost::variant<bool, int, double, std::string, std::set<int>, std::set<std::string>, std::vector<double>, IteratorOutputOptions, PiecewiseStepMethod, OutputDimensionalityTypes> value_variant_t;
402+
typedef boost::variant<bool, int, double, std::string, std::set<int>, std::set<std::string>, std::vector<double>, IteratorOutputOptions, PiecewiseStepMethod, OutputDimensionalityTypes, TriangulationMethod> value_variant_t;
387403
private:
388404
settings_t settings;
389405

@@ -470,73 +486,12 @@ namespace ifcopenshell {
470486
};
471487

472488
class IFC_GEOM_API Settings : public SettingsContainer<
473-
std::tuple<MesherLinearDeflection, MesherAngularDeflection, ReorientShells, LengthUnit, PlaneUnit, Precision, OutputDimensionality, LayersetFirst, DisableBooleanResult, NoWireIntersectionCheck, NoWireIntersectionTolerance, PrecisionFactor, DebugBooleanOperations, BooleanAttempt2d, 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>
489+
std::tuple<MesherLinearDeflection, MesherAngularDeflection, ReorientShells, LengthUnit, PlaneUnit, Precision, OutputDimensionality, LayersetFirst, DisableBooleanResult, NoWireIntersectionCheck, NoWireIntersectionTolerance, PrecisionFactor, DebugBooleanOperations, BooleanAttempt2d, 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>
474490
>
475491
{};
476492
}
477493
}
478494

479-
// namespace ifcopenshell {
480-
// namespace geometry {
481-
//
482-
// class IFC_GEOM_API ConversionSettings {
483-
// public:
484-
// // Tolerances and settings for various geometrical operations:
485-
// enum GeomValue {
486-
// //
487-
// // Default: 0.001m / 1mm
488-
// GV_DEFLECTION_TOLERANCE,
489-
//
490-
// // The length unit used the creation of TopoDS_Shapes, primarily affects the
491-
// // interpretation of IfcCartesianPoints and IfcVector magnitudes
492-
// // DefaultL 1.0
493-
// GV_LENGTH_UNIT,
494-
// // The plane angle unit used for the creation of TopoDS_Shapes, primarily affects
495-
// // the interpretation of IfcParamaterValues of IfcTrimmedCurves
496-
// // Default: -1.0 (= not set, fist try degrees, then radians)
497-
// GV_PLANEANGLE_UNIT,
498-
// // The precision used in boolean operations, setting this value too low results
499-
// // in artefacts and potentially modelling failures
500-
// // Default: 0.00001 (obtained from IfcGeometricRepresentationContext if available)
501-
// GV_PRECISION,
502-
// // Whether to process shapes of type Face or higher (1) Wire or lower (-1) or all (0)
503-
// GV_DIMENSIONALITY,
504-
// GV_LAYERSET_FIRST,
505-
// GV_DISABLE_BOOLEAN_RESULT,
506-
// GV_NO_WIRE_INTERSECTION_CHECK,
507-
// GV_PRECISION_FACTOR,
508-
// GV_NO_WIRE_INTERSECTION_TOLERANCE,
509-
// GV_DEBUG_BOOLEAN,
510-
// GV_BOOLEAN_ATTEMPT_2D,
511-
// NUM_SETTINGS
512-
// };
513-
//
514-
// void setValue(GeomValue var, double value);
515-
//
516-
// double getValue(GeomValue var) const;
517-
//
518-
// private:
519-
// std::array<double, NUM_SETTINGS> values_ = {
520-
// /* deflection_tolerance = */ 0.001,
521-
// // @todo make sure these 'read-only' variables work.
522-
// /* minimal_face_area = */ std::numeric_limits<double>::quiet_NaN(),
523-
// /* max_faces_to_orient = */ -1.0,
524-
// /* ifc_length_unit = */ 1.0,
525-
// /* ifc_planeangle_unit = */ -1.0,
526-
// /* modelling_precision = */ 0.00001,
527-
// /* dimensionality = */ 1.,
528-
// /* layerset_first = */ -1.,
529-
// /* disable_boolean_result = */ -1.
530-
// /* no_wire_intersection_check = */ -1.,
531-
// /* precision_factor = */ 10.,
532-
// /* no_wire_intersection_tolerance = */ -1.,
533-
// /* boolean_debug_setting = */ -1.,
534-
// /* boolean_attempt_2d = */ 1.
535-
// };
536-
// };
537-
// }
538-
// }
539-
540495
// @todo find a place
541496
namespace IfcGeom {
542497
class IFC_GEOM_API geometry_exception : public std::exception {

src/ifcgeom/IfcGeomRepresentation.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -332,23 +332,23 @@ IfcGeom::Representation::Triangulation::Triangulation(const BRep& shape_model)
332332

333333
int surface_style_id = -1;
334334
if (iit->hasStyle()) {
335-
auto jt = std::find(_materials.begin(), _materials.end(), iit->StylePtr());
336-
if (jt == _materials.end()) {
337-
surface_style_id = (int)_materials.size();
338-
_materials.push_back(iit->StylePtr());
335+
auto jt = std::find(materials_.begin(), materials_.end(), iit->StylePtr());
336+
if (jt == materials_.end()) {
337+
surface_style_id = (int)materials_.size();
338+
materials_.push_back(iit->StylePtr());
339339
} else {
340-
surface_style_id = (int)(jt - _materials.begin());
340+
surface_style_id = (int)(jt - materials_.begin());
341341
}
342342
}
343343

344344
if (settings().get<ifcopenshell::geometry::settings::ApplyDefaultMaterials>().get() && surface_style_id == -1) {
345345
const auto& material = IfcGeom::get_default_style(shape_model.entity());
346-
auto mit = std::find(_materials.begin(), _materials.end(), material);
347-
if (mit == _materials.end()) {
348-
surface_style_id = (int)_materials.size();
349-
_materials.push_back(material);
346+
auto mit = std::find(materials_.begin(), materials_.end(), material);
347+
if (mit == materials_.end()) {
348+
surface_style_id = (int)materials_.size();
349+
materials_.push_back(material);
350350
} else {
351-
surface_style_id = (int)(mit - _materials.begin());
351+
surface_style_id = (int)(mit - materials_.begin());
352352
}
353353
}
354354

@@ -393,17 +393,17 @@ int IfcGeom::Representation::Triangulation::addVertex(int item_id, int material_
393393
const double X = convert ? (pX /unit_magnitude) : pX;
394394
const double Y = convert ? (pY /unit_magnitude) : pY;
395395
const double Z = convert ? (pZ /unit_magnitude) : pZ;
396-
int i = (int)_verts.size() / 3;
396+
int i = (int)verts_.size() / 3;
397397
if (settings().get<ifcopenshell::geometry::settings::WeldVertices>().get()) {
398398
const VertexKey key = std::make_tuple(item_id, material_index, X, Y, Z);
399399
typename VertexKeyMap::const_iterator it = welds.find(key);
400400
if (it != welds.end()) return it->second;
401401
i = (int)(welds.size() + weld_offset_);
402402
welds[key] = i;
403403
}
404-
_verts.push_back(X);
405-
_verts.push_back(Y);
406-
_verts.push_back(Z);
404+
verts_.push_back(X);
405+
verts_.push_back(Y);
406+
verts_.push_back(Z);
407407
return i;
408408
}
409409

src/ifcgeom/IfcGeomRepresentation.h

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,20 @@ namespace IfcGeom {
103103
typedef std::map<VertexKey, int> VertexKeyMap;
104104
typedef std::pair<int, int> Edge;
105105

106-
std::vector<double> _verts;
107-
std::vector<int> _faces;
108-
std::vector<int> _edges;
109-
std::vector<double> _normals;
106+
std::vector<double> verts_;
107+
108+
// @nb only one of these is populated based on settings, we didn't want to go
109+
// all in with templates or subtypes because of reduced ease of use.
110+
std::vector<int> faces_;
111+
std::vector<std::vector<int>> polyhedral_faces_without_holes_;
112+
std::vector<std::vector<std::vector<int>>> polyhedral_faces_with_holes_;
113+
114+
std::vector<int> edges_;
115+
std::vector<double> normals_;
110116
std::vector<double> uvs_;
111-
std::vector<int> _material_ids;
112-
std::vector<ifcopenshell::geometry::taxonomy::style::ptr> _materials;
113-
std::vector<int> _item_ids;
117+
std::vector<int> material_ids_;
118+
std::vector<ifcopenshell::geometry::taxonomy::style::ptr> materials_;
119+
std::vector<int> item_ids_;
114120
size_t weld_offset_;
115121
VertexKeyMap welds;
116122

@@ -120,15 +126,17 @@ namespace IfcGeom {
120126
{}
121127

122128
public:
123-
const std::vector<double>& verts() const { return _verts; }
124-
const std::vector<int>& faces() const { return _faces; }
125-
const std::vector<int>& edges() const { return _edges; }
126-
const std::vector<double>& normals() const { return _normals; }
129+
const std::vector<double>& verts() const { return verts_; }
130+
const std::vector<int>& faces() const { return faces_; }
131+
const std::vector<std::vector<int>>& polyhedral_faces_without_holes() const { return polyhedral_faces_without_holes_; }
132+
const std::vector<std::vector<std::vector<int>>>& polyhedral_faces_with_holes() const { return polyhedral_faces_with_holes_; }
133+
const std::vector<int>& edges() const { return edges_; }
134+
const std::vector<double>& normals() const { return normals_; }
127135
std::vector<double>& uvs() { return uvs_; }
128136
const std::vector<double>& uvs() const { return uvs_; }
129-
const std::vector<int>& material_ids() const { return _material_ids; }
130-
const std::vector<ifcopenshell::geometry::taxonomy::style::ptr>& materials() const { return _materials; }
131-
const std::vector<int>& item_ids() const { return _item_ids; }
137+
const std::vector<int>& material_ids() const { return material_ids_; }
138+
const std::vector<ifcopenshell::geometry::taxonomy::style::ptr>& materials() const { return materials_; }
139+
const std::vector<int>& item_ids() const { return item_ids_; }
132140

133141
Triangulation(const BRep& shape_model);
134142

@@ -146,14 +154,14 @@ namespace IfcGeom {
146154
const std::vector<int>& item_ids
147155
)
148156
: Representation(settings, entity, id)
149-
, _verts(verts)
150-
, _faces(faces)
151-
, _edges(edges)
152-
, _normals(normals)
157+
, verts_(verts)
158+
, faces_(faces)
159+
, edges_(edges)
160+
, normals_(normals)
153161
, uvs_(uvs)
154-
, _material_ids(material_ids)
155-
, _materials(materials)
156-
, _item_ids(item_ids)
162+
, material_ids_(material_ids)
163+
, materials_(materials)
164+
, item_ids_(item_ids)
157165
{}
158166

159167
virtual ~Triangulation() {}
@@ -168,30 +176,44 @@ namespace IfcGeom {
168176
int addVertex(int item_index, int material_index, double X, double Y, double Z);
169177

170178
void addNormal(double X, double Y, double Z) {
171-
_normals.push_back(X);
172-
_normals.push_back(Y);
173-
_normals.push_back(Z);
179+
normals_.push_back(X);
180+
normals_.push_back(Y);
181+
normals_.push_back(Z);
174182
}
175183

176184
void addFace(int item_id, int style, int i0, int i1, int i2) {
177-
_faces.push_back(i0);
178-
_faces.push_back(i1);
179-
_faces.push_back(i2);
185+
faces_.push_back(i0);
186+
faces_.push_back(i1);
187+
faces_.push_back(i2);
180188

181-
_item_ids.push_back(item_id);
182-
_material_ids.push_back(style);
189+
item_ids_.push_back(item_id);
190+
material_ids_.push_back(style);
191+
}
192+
193+
void addFace(int item_id, int style, const std::vector<int>& outer_bound) {
194+
polyhedral_faces_without_holes_.push_back(outer_bound);
195+
196+
item_ids_.push_back(item_id);
197+
material_ids_.push_back(style);
198+
}
199+
200+
void addFace(int item_id, int style, const std::vector<std::vector<int>>& bounds) {
201+
polyhedral_faces_with_holes_.push_back(bounds);
202+
203+
item_ids_.push_back(item_id);
204+
material_ids_.push_back(style);
183205
}
184206

185207
void addEdge(int style, int i0, int i1) {
186-
_edges.push_back(i0);
187-
_edges.push_back(i1);
208+
edges_.push_back(i0);
209+
edges_.push_back(i1);
188210

189-
_material_ids.push_back(style);
211+
material_ids_.push_back(style);
190212
}
191213

192214
void registerEdge(int i0, int i1) {
193-
_edges.push_back(i0);
194-
_edges.push_back(i1);
215+
edges_.push_back(i0);
216+
edges_.push_back(i1);
195217
}
196218

197219
void addEdge(int n1, int n2, std::map<std::pair<int, int>, int>& edgecount);

0 commit comments

Comments
 (0)