4747#include < TColgp_Array1OfPnt2d.hxx>
4848#include < TColStd_Array1OfReal.hxx>
4949#include < TColStd_Array1OfInteger.hxx>
50+
5051#include < Geom_Line.hxx>
5152#include < Geom_Circle.hxx>
5253#include < Geom_Ellipse.hxx>
5354#include < Geom_TrimmedCurve.hxx>
5455
55- #include < BRepOffsetAPI_Sewing .hxx>
56+ #include < BRepBuilderAPI_MakeVertex .hxx>
5657#include < BRepBuilderAPI_MakeFace.hxx>
5758#include < BRepBuilderAPI_MakeEdge.hxx>
5859#include < BRepBuilderAPI_MakeWire.hxx>
60+ #include < BRepBuilderAPI_MakeShell.hxx>
61+ #include < BRepBuilderAPI_MakeSolid.hxx>
5962#include < BRepBuilderAPI_MakePolygon.hxx>
6063#include < BRepBuilderAPI_MakeVertex.hxx>
6164
6265#include < TopoDS.hxx>
6366#include < TopoDS_Wire.hxx>
6467#include < TopoDS_Face.hxx>
6568#include < TopExp_Explorer.hxx>
69+ #include < TopLoc_Location.hxx>
70+ #include < TopTools_ListOfShape.hxx>
6671
72+ #include < BRepAlgoAPI_Cut.hxx>
73+ #include < BRepOffsetAPI_Sewing.hxx>
6774#include < BRepPrimAPI_MakePrism.hxx>
68- #include < BRepBuilderAPI_MakeShell.hxx>
69- #include < BRepBuilderAPI_MakeSolid.hxx>
7075#include < BRepPrimAPI_MakeHalfSpace.hxx>
71- #include < BRepAlgoAPI_Cut.hxx>
76+ #include < BRepFilletAPI_MakeFillet2d.hxx>
77+
78+ #include < BRep_Tool.hxx>
7279
7380#include < ShapeFix_Shape.hxx>
7481#include < ShapeFix_ShapeTolerance.hxx>
7582#include < ShapeFix_Solid.hxx>
7683
77- #include < BRepFilletAPI_MakeFillet2d.hxx>
78-
79- #include < TopLoc_Location.hxx>
80-
81- #include < BRep_Tool.hxx>
82-
8384#include " ../ifcgeom/IfcGeom.h"
8485
8586bool IfcGeom::convert (const IfcSchema::IfcCompositeCurve* l, TopoDS_Wire& wire) {
@@ -274,13 +275,20 @@ bool IfcGeom::convert(const IfcSchema::IfcTrimmedCurve* l, TopoDS_Wire& wire) {
274275bool IfcGeom::convert (const IfcSchema::IfcPolyline* l, TopoDS_Wire& result) {
275276 IfcSchema::IfcCartesianPoint::list::ptr points = l->Points ();
276277
277- BRepBuilderAPI_MakeWire w;
278- gp_Pnt P1;gp_Pnt P2;
279- for ( IfcSchema::IfcCartesianPoint::list::it it = points->begin (); it != points->end (); ++ it ) {
280- IfcGeom::convert (*it,P2);
281- if ( it != points->begin () && ( !P1.IsEqual (P2,GetValue (GV_POINT_EQUALITY_TOLERANCE)) ) )
282- w.Add (BRepBuilderAPI_MakeEdge (P1,P2));
283- P1 = P2;
278+ // Parse and store the points in a sequence
279+ TColgp_SequenceOfPnt polygon;
280+ for (IfcSchema::IfcCartesianPoint::list::it it = points->begin (); it != points->end (); ++ it) {
281+ gp_Pnt pnt;
282+ IfcGeom::convert (*it, pnt);
283+ polygon.Append (pnt);
284+ }
285+
286+ // Remove points that are too close to one another
287+ remove_redundant_points_from_loop (polygon, false );
288+
289+ BRepBuilderAPI_MakePolygon w;
290+ for (int i = 1 ; i <= polygon.Length (); ++i) {
291+ w.Add (polygon.Value (i));
284292 }
285293
286294 result = w.Wire ();
@@ -290,24 +298,42 @@ bool IfcGeom::convert(const IfcSchema::IfcPolyline* l, TopoDS_Wire& result) {
290298bool IfcGeom::convert (const IfcSchema::IfcPolyLoop* l, TopoDS_Wire& result) {
291299 IfcSchema::IfcCartesianPoint::list::ptr points = l->Polygon ();
292300
293- BRepBuilderAPI_MakeWire w;
294- gp_Pnt P1;gp_Pnt P2;gp_Pnt F;
295- int count = 0 ;
296- for ( IfcSchema::IfcCartesianPoint::list::it it = points->begin (); it != points->end (); ++ it ) {
297- IfcGeom::convert (*it,P2);
298- if ( it != points->begin () && ( !P1.IsEqual (P2,GetValue (GV_POINT_EQUALITY_TOLERANCE)) ) ) {
299- w.Add (BRepBuilderAPI_MakeEdge (P1,P2));
300- count ++;
301- } else if ( ! count ) F = P2;
302- P1 = P2;
301+ // Parse and store the points in a sequence
302+ TColgp_SequenceOfPnt polygon;
303+ for (IfcSchema::IfcCartesianPoint::list::it it = points->begin (); it != points->end (); ++ it) {
304+ gp_Pnt pnt;
305+ IfcGeom::convert (*it, pnt);
306+ polygon.Append (pnt);
307+ }
308+
309+ // A loop should consist of at least three vertices
310+ int original_count = polygon.Length ();
311+ if (original_count < 3 ) {
312+ Logger::Message (Logger::LOG_ERROR, " Not enough edges for:" , l->entity );
313+ return false ;
303314 }
304- if ( !P1.IsEqual (F,GetValue (GV_POINT_EQUALITY_TOLERANCE)) ) {
305- w.Add (BRepBuilderAPI_MakeEdge (P1,F));
306- count ++;
315+
316+ // Remove points that are too close to one another
317+ remove_redundant_points_from_loop (polygon, true );
318+
319+ int count = polygon.Length ();
320+ if (original_count - count != 0 ) {
321+ std::stringstream ss; ss << (original_count - count) << " edges removed for:" ;
322+ Logger::Message (Logger::LOG_WARNING, ss.str (), l->entity );
307323 }
308- if ( count < 3 ) return false ;
309324
310- result = w.Wire ();
325+ if (count < 3 ) {
326+ Logger::Message (Logger::LOG_ERROR, " Not enough edges for:" , l->entity );
327+ return false ;
328+ }
329+
330+ BRepBuilderAPI_MakePolygon w;
331+ for (int i = 1 ; i <= polygon.Length (); ++i) {
332+ w.Add (polygon.Value (i));
333+ }
334+ w.Close ();
335+
336+ result = w.Wire ();
311337 return true ;
312338}
313339
0 commit comments