From df2bcecf96bc009081ad2e341d98df4c6fed7d84 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Tue, 20 Mar 2012 09:32:51 +0000 Subject: [PATCH] - Fix a regression due to too high tolerance in Polyline -Loop creation. - Make tolerances slightly more explicit, ideally these should obviously be configurable at runtime. --- src/ifcgeom/IfcGeom.h | 8 ++++++++ src/ifcgeom/IfcGeomFunctions.cpp | 8 ++++---- src/ifcgeom/IfcGeomObjects.cpp | 2 +- src/ifcgeom/IfcGeomWires.cpp | 8 ++++---- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/ifcgeom/IfcGeom.h b/src/ifcgeom/IfcGeom.h index 9040d5f50a..dbe9d78412 100644 --- a/src/ifcgeom/IfcGeom.h +++ b/src/ifcgeom/IfcGeom.h @@ -42,6 +42,14 @@ #include "../ifcgeom/IfcShapeList.h" +// Tolerances for various geometrical operations: +// Specifies the deflection of the mesher +#define DEFLECTION_TOLERANCE 0.001 +// Specifies the tolerance of the wire builder, most notably for trimmed curves +#define WIRE_CREATION_TOLERANCE 0.0001 +// Specifies the treshold distance under which cartesian points are deemed equal +#define POINT_EQUALITY_TOLERANCE 0.000001 + #define FACESET_AS_COMPOUND 1 namespace IfcGeom { diff --git a/src/ifcgeom/IfcGeomFunctions.cpp b/src/ifcgeom/IfcGeomFunctions.cpp index 4b768921b0..915e83c8c4 100644 --- a/src/ifcgeom/IfcGeomFunctions.cpp +++ b/src/ifcgeom/IfcGeomFunctions.cpp @@ -278,8 +278,8 @@ bool IfcGeom::is_convex(const TopoDS_Wire& wire) { edge_points.push_back(P2); } if ( edge_points.size() != 2 ) continue; - if ( edge_points[0].IsEqual(P1,0.0001)) neighbors.push_back(edge_points[1]); - else if ( edge_points[1].IsEqual(P1,0.0001)) neighbors.push_back(edge_points[0]); + if ( edge_points[0].IsEqual(P1,POINT_EQUALITY_TOLERANCE)) neighbors.push_back(edge_points[1]); + else if ( edge_points[1].IsEqual(P1,POINT_EQUALITY_TOLERANCE)) neighbors.push_back(edge_points[0]); } // There should be two of these if ( neighbors.size() != 2 ) return false; @@ -288,10 +288,10 @@ bool IfcGeom::is_convex(const TopoDS_Wire& wire) { for ( TopExp_Explorer exp2(wire,TopAbs_VERTEX); exp2.More(); exp2.Next() ) { TopoDS_Vertex V2 = TopoDS::Vertex(exp2.Current()); gp_Pnt P2 = BRep_Tool::Pnt(V2); - if ( P1.IsEqual(P2,0.0001) ) continue; + if ( P1.IsEqual(P2,POINT_EQUALITY_TOLERANCE) ) continue; bool found = false; for( std::vector::const_iterator it = neighbors.begin(); it != neighbors.end(); ++ it ) { - if ( (*it).IsEqual(P2,0.0001) ) { found = true; break; } + if ( (*it).IsEqual(P2,POINT_EQUALITY_TOLERANCE) ) { found = true; break; } } if ( ! found ) non_neighbors.push_back(P2); } diff --git a/src/ifcgeom/IfcGeomObjects.cpp b/src/ifcgeom/IfcGeomObjects.cpp index b47333efb7..2e7b6058b4 100644 --- a/src/ifcgeom/IfcGeomObjects.cpp +++ b/src/ifcgeom/IfcGeomObjects.cpp @@ -103,7 +103,7 @@ IfcGeomObjects::IfcMesh::IfcMesh(int i, const IfcGeom::ShapeList& shapes) { // Triangulate the shape try { //BRepTools::Clean(s); - BRepMesh::Mesh(s,0.001f); + BRepMesh::Mesh(s,DEFLECTION_TOLERANCE); } catch(...) { Ifc::LogMessage("Error","Failed to triangulate mesh:",Ifc::EntityById(i)->entity); continue; diff --git a/src/ifcgeom/IfcGeomWires.cpp b/src/ifcgeom/IfcGeomWires.cpp index e32b64f9e4..d1258541ec 100644 --- a/src/ifcgeom/IfcGeomWires.cpp +++ b/src/ifcgeom/IfcGeomWires.cpp @@ -114,7 +114,7 @@ bool IfcGeom::convert(const Ifc2x3::IfcCompositeCurve::ptr l, TopoDS_Wire& wire) } if ( ! (*it)->SameSense() ) wire2.Reverse(); ShapeFix_ShapeTolerance FTol; - FTol.SetTolerance(wire2, 0.0001, TopAbs_WIRE); + FTol.SetTolerance(wire2, WIRE_CREATION_TOLERANCE, TopAbs_WIRE); /*if ( it != segments->begin() ) { TopExp_Explorer exp (wire2,TopAbs_VERTEX); const TopoDS_Vertex& first_vertex = TopoDS::Vertex(exp.Current()); @@ -201,7 +201,7 @@ bool IfcGeom::convert(const Ifc2x3::IfcPolyline::ptr l, TopoDS_Wire& result) { gp_Pnt P1;gp_Pnt P2; for( Ifc2x3::IfcCartesianPoint::it it = points->begin(); it != points->end(); ++ it ) { IfcGeom::convert(*it,P2); - if ( it != points->begin() && ( !P1.IsEqual(P2,0.0001) ) ) + if ( it != points->begin() && ( !P1.IsEqual(P2,POINT_EQUALITY_TOLERANCE) ) ) w.Add(BRepBuilderAPI_MakeEdge(P1,P2)); P1 = P2; } @@ -217,13 +217,13 @@ bool IfcGeom::convert(const Ifc2x3::IfcPolyLoop::ptr l, TopoDS_Wire& result) { int count = 0; for( Ifc2x3::IfcCartesianPoint::it it = points->begin(); it != points->end(); ++ it ) { IfcGeom::convert(*it,P2); - if ( it != points->begin() && ( !P1.IsEqual(P2,0.0001) ) ) { + if ( it != points->begin() && ( !P1.IsEqual(P2,POINT_EQUALITY_TOLERANCE) ) ) { w.Add(BRepBuilderAPI_MakeEdge(P1,P2)); count ++; } else if ( ! count ) F = P2; P1 = P2; } - if ( !P1.IsEqual(F,0.0001) ) { + if ( !P1.IsEqual(F,POINT_EQUALITY_TOLERANCE) ) { w.Add(BRepBuilderAPI_MakeEdge(P1,F)); count ++; }