Skip to content

Commit 453c88d

Browse files
Implement IfcGeometricSet geometry generation (#2)
1 parent 456d5ef commit 453c88d

File tree

1 file changed

+137
-7
lines changed

1 file changed

+137
-7
lines changed

include/ifcpp/Geometry/GeometryGenerator.h

Lines changed: 137 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,21 @@
2323
#include "ifcpp/Ifc/IfcFace.h"
2424
#include "ifcpp/Ifc/IfcFaceBasedSurfaceModel.h"
2525
#include "ifcpp/Ifc/IfcFeatureElementSubtraction.h"
26+
#include "ifcpp/Ifc/IfcGeometricCurveSet.h"
27+
#include "ifcpp/Ifc/IfcGeometricSet.h"
28+
#include "ifcpp/Ifc/IfcMappedItem.h"
2629
#include "ifcpp/Ifc/IfcObjectDefinition.h"
2730
#include "ifcpp/Ifc/IfcOpenShell.h"
2831
#include "ifcpp/Ifc/IfcProductRepresentation.h"
2932
#include "ifcpp/Ifc/IfcRelVoidsElement.h"
3033
#include "ifcpp/Ifc/IfcRepresentation.h"
34+
#include "ifcpp/Ifc/IfcRepresentationMap.h"
35+
#include "ifcpp/Ifc/IfcSectionedSpine.h"
3136
#include "ifcpp/Ifc/IfcShellBasedSurfaceModel.h"
3237
#include "ifcpp/Ifc/IfcSpace.h"
33-
#include "ifcpp/Ifc/IfcMappedItem.h"
34-
#include "ifcpp/Ifc/IfcRepresentationMap.h"
38+
#include "ifcpp/Ifc/IfcTessellatedItem.h"
39+
#include "ifcpp/Ifc/IfcTextLiteral.h"
40+
#include "ifcpp/Ifc/IfcAnnotationFillArea.h"
3541

3642

3743
namespace ifcpp {
@@ -145,8 +151,8 @@ class GeometryGenerator {
145151
std::copy( l.begin(), l.end(), std::back_inserter( polylines ) );
146152
}
147153

148-
auto matrix = TMatrix::GetScale( this->m_parameters->m_lengthFactor, this->m_parameters->m_lengthFactor, this->m_parameters->m_lengthFactor );
149-
TMatrix::Multiply( &matrix, this->m_primitivesConverter->ConvertPlacement( product->m_ObjectPlacement ) );
154+
auto matrix = this->m_primitivesConverter->ConvertPlacement( product->m_ObjectPlacement );
155+
TMatrix::Multiply( &matrix, TMatrix::GetScale( this->m_parameters->m_lengthFactor, this->m_parameters->m_lengthFactor, this->m_parameters->m_lengthFactor ) );
150156
this->m_adapter->Transform( &polygons, matrix );
151157
this->m_adapter->Transform( &polylines, matrix );
152158

@@ -176,11 +182,66 @@ class GeometryGenerator {
176182
std::copy( p.begin(), p.end(), std::back_inserter( polygons ) );
177183
std::copy( l.begin(), l.end(), std::back_inserter( polylines ) );
178184
}
185+
186+
const auto topologicalItem = std::dynamic_pointer_cast<IfcTopologicalRepresentationItem>( item );
187+
if( topologicalItem ) {
188+
auto [ p, l ] = this->ConvertTopologicalRepresentationItem( topologicalItem );
189+
std::copy( p.begin(), p.end(), std::back_inserter( polygons ) );
190+
std::copy( l.begin(), l.end(), std::back_inserter( polylines ) );
191+
}
179192
}
180193

181194
return { polygons, polylines };
182195
}
183196

197+
std::tuple<std::vector<TPolygon>, std::vector<TPolyline>>
198+
ConvertTopologicalRepresentationItem( const shared_ptr<IfcTopologicalRepresentationItem>& topological_item ) {
199+
// IfcTopologicalRepresentationItem ABSTRACT SUPERTYPE OF(ONEOF(IfcConnectedFaceSet, IfcEdge, IfcFace, IfcFaceBound, IfcLoop, IfcPath, IfcVertex))
200+
201+
const auto topo_connected_face_set = dynamic_pointer_cast<IfcConnectedFaceSet>( topological_item );
202+
if( topo_connected_face_set ) {
203+
std::vector<std::vector<TVector>> loops = this->m_geometryConverter->ConvertFaces( topo_connected_face_set->m_CfsFaces );
204+
205+
// TODO: Rework (try to fix points order)
206+
auto reversed = loops;
207+
for( auto& l: reversed ) {
208+
std::reverse( l.begin(), l.end() );
209+
}
210+
std::copy( std::begin( reversed ), std::end( reversed ), std::back_inserter( loops ) );
211+
212+
return { this->CreatePolygons( loops ), {} };
213+
}
214+
215+
const auto topo_edge = dynamic_pointer_cast<IfcEdge>( topological_item );
216+
if( topo_edge ) {
217+
return { {}, { this->m_adapter->CreatePolyline( this->m_geometryConverter->ConvertEdge( topo_edge ) ) } };
218+
}
219+
220+
const shared_ptr<IfcFace> topo_face = dynamic_pointer_cast<IfcFace>( topological_item );
221+
if( topo_face ) {
222+
auto loop = this->m_geometryConverter->ConvertFace( topo_face );
223+
auto rloop = loop;
224+
std::reverse( rloop.begin(), rloop.end() );
225+
return { this->CreatePolygons( { loop, rloop } ), {} };
226+
}
227+
228+
const auto topo_face_bound = dynamic_pointer_cast<IfcFaceBound>( topological_item );
229+
if( topo_face_bound ) {
230+
const auto loop = this->m_geometryConverter->ConvertLoop( topo_face_bound->m_Bound );
231+
auto rloop = loop;
232+
std::reverse( rloop.begin(), rloop.end() );
233+
return { this->CreatePolygons( { loop, rloop } ), {} };
234+
}
235+
236+
const auto topo_loop = dynamic_pointer_cast<IfcLoop>( topological_item );
237+
if( topo_loop ) {
238+
return { {}, { this->m_adapter->CreatePolyline( this->m_geometryConverter->ConvertLoop( topo_loop ) ) } };
239+
}
240+
241+
// TODO: Implement all
242+
return {};
243+
}
244+
184245
std::tuple<std::vector<TPolygon>, std::vector<TPolyline>> ConvertMappedItem( const std::shared_ptr<IfcMappedItem>& mappedItem ) {
185246
if( !mappedItem->m_MappingSource || !mappedItem->m_MappingSource->m_MappedRepresentation ) {
186247
// TODO: Log error
@@ -215,8 +276,8 @@ class GeometryGenerator {
215276
auto [ p, l ] = this->ConvertRepresentation( representation );
216277
std::copy( p.begin(), p.end(), std::back_inserter( polygons ) );
217278
}
218-
auto m = TMatrix::GetScale( this->m_parameters->m_lengthFactor, this->m_parameters->m_lengthFactor, this->m_parameters->m_lengthFactor );
219-
TMatrix::Multiply( &m, this->m_primitivesConverter->ConvertPlacement( opening->m_ObjectPlacement ) );
279+
auto m = this->m_primitivesConverter->ConvertPlacement( opening->m_ObjectPlacement );
280+
TMatrix::Multiply( &m, TMatrix::GetScale( this->m_parameters->m_lengthFactor, this->m_parameters->m_lengthFactor, this->m_parameters->m_lengthFactor ) );
220281
this->m_adapter->Transform( &polygons, m );
221282
std::copy( polygons.begin(), polygons.end(), std::back_inserter( resultPolygons ) );
222283
}
@@ -260,11 +321,80 @@ class GeometryGenerator {
260321
return this->ConvertShellBasedSurfaceModel( shellModel );
261322
}
262323

324+
const auto tessellatedItem = dynamic_pointer_cast<IfcTessellatedItem>( geometricRepresentation );
325+
if( tessellatedItem ) {
326+
// TODO: implement
327+
return {};
328+
}
329+
263330
const auto surface = dynamic_pointer_cast<IfcSurface>( geometricRepresentation );
264331
if( surface ) {
265332
return this->ConvertSurface( surface );
266333
}
267334

335+
const auto geometricSet = dynamic_pointer_cast<IfcGeometricSet>( geometricRepresentation );
336+
if( geometricSet ) {
337+
std::vector<TPolygon> polygons;
338+
std::vector<TPolyline> polylines;
339+
340+
for( const auto& geom_select: geometricSet->m_Elements ) {
341+
// TYPE IfcGeometricSetSelect = SELECT (IfcPoint, IfcCurve, IfcSurface);
342+
if( !geom_select ) {
343+
continue;
344+
}
345+
346+
shared_ptr<IfcPoint> point = dynamic_pointer_cast<IfcPoint>( geom_select );
347+
if( point ) {
348+
// TODO: Implement
349+
continue;
350+
}
351+
352+
shared_ptr<IfcCurve> select_curve = dynamic_pointer_cast<IfcCurve>( geom_select );
353+
if( select_curve ) {
354+
const auto [ p, l ] = this->ConvertGeometryRepresentation( select_curve );
355+
std::copy( p.begin(), p.end(), std::back_inserter( polygons ) );
356+
std::copy( l.begin(), l.end(), std::back_inserter( polylines ) );
357+
}
358+
359+
shared_ptr<IfcSurface> select_surface = dynamic_pointer_cast<IfcSurface>( geom_select );
360+
if( select_surface ) {
361+
const auto [ p, l ] = this->ConvertGeometryRepresentation( select_surface );
362+
std::copy( p.begin(), p.end(), std::back_inserter( polygons ) );
363+
std::copy( l.begin(), l.end(), std::back_inserter( polylines ) );
364+
}
365+
}
366+
367+
shared_ptr<IfcGeometricCurveSet> geometric_curve_set = dynamic_pointer_cast<IfcGeometricCurveSet>( geometricSet );
368+
if( geometric_curve_set ) {
369+
// no additional attributes
370+
}
371+
return { polygons, polylines };
372+
}
373+
374+
const auto sectioned_spine = dynamic_pointer_cast<IfcSectionedSpine>( geometricRepresentation );
375+
if( sectioned_spine ) {
376+
// TODO: Implement
377+
return {};
378+
}
379+
380+
const auto text_literal = dynamic_pointer_cast<IfcTextLiteral>( geometricRepresentation );
381+
if( text_literal ) {
382+
// TODO: Implement
383+
return {};
384+
}
385+
386+
const auto annotation_fill_area = dynamic_pointer_cast<IfcAnnotationFillArea>( geometricRepresentation );
387+
if( annotation_fill_area ) {
388+
// TODO: Implement
389+
return {};
390+
}
391+
392+
shared_ptr<IfcPoint> ifc_point = dynamic_pointer_cast<IfcPoint>( geometricRepresentation );
393+
if( ifc_point ) {
394+
// TODO: Implement
395+
return {};
396+
}
397+
268398
// TODO: Implement all
269399
return {};
270400
}
@@ -334,7 +464,7 @@ class GeometryGenerator {
334464
continue;
335465
}
336466
const auto indices = this->m_adapter->Triangulate( l );
337-
if( indices.size() < 3) {
467+
if( indices.size() < 3 ) {
338468
continue;
339469
}
340470
for( int i = 0; i < indices.size() - 2; i += 3 ) {

0 commit comments

Comments
 (0)