1 // Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <Standard_Stream.hxx>
25 #include <GEOMUtils.hxx>
27 #include <Utils_ExceptHandlers.hxx>
30 #include <BRepMesh_IncrementalMesh.hxx>
32 #include <BRepExtrema_DistShapeShape.hxx>
34 #include <BRep_Builder.hxx>
35 #include <BRep_Tool.hxx>
36 #include <BRepBndLib.hxx>
37 #include <BRepGProp.hxx>
38 #include <BRepTools.hxx>
40 #include <BRepClass_FaceClassifier.hxx>
41 #include <BRepClass3d_SolidClassifier.hxx>
43 #include <BRepBuilderAPI_MakeFace.hxx>
44 #include <BRepBuilderAPI_Sewing.hxx>
46 #include <BRepCheck_Analyzer.hxx>
48 #include <Bnd_Box.hxx>
50 #include <BOPAlgo_ArgumentAnalyzer.hxx>
51 #include <BOPTools_AlgoTools.hxx>
56 #include <TopoDS_Edge.hxx>
57 #include <TopoDS_Face.hxx>
58 #include <TopoDS_Shape.hxx>
59 #include <TopoDS_Vertex.hxx>
60 #include <TopoDS_Compound.hxx>
61 #include <TopoDS_Iterator.hxx>
62 #include <TopExp_Explorer.hxx>
63 #include <TopTools_MapOfShape.hxx>
64 #include <TopTools_ListOfShape.hxx>
65 #include <TopTools_ListIteratorOfListOfShape.hxx>
66 #include <TopTools_Array1OfShape.hxx>
68 #include <GeomAPI_ProjectPointOnSurf.hxx>
70 #include <Geom_Circle.hxx>
71 #include <Geom_Surface.hxx>
72 #include <Geom_Plane.hxx>
73 #include <Geom_SphericalSurface.hxx>
74 #include <Geom_ToroidalSurface.hxx>
75 #include <Geom_RectangularTrimmedSurface.hxx>
77 #include <GeomLProp_CLProps.hxx>
78 #include <GeomLProp_SLProps.hxx>
80 #include <GProp_GProps.hxx>
81 #include <GProp_PrincipalProps.hxx>
83 #include <TColStd_Array1OfReal.hxx>
88 #include <ShapeAnalysis.hxx>
89 #include <ShapeFix_Shape.hxx>
90 #include <ShapeFix_ShapeTolerance.hxx>
92 #include <ProjLib.hxx>
99 #include <V3d_Coordinate.hxx>
101 #include <Standard_Failure.hxx>
102 #include <Standard_NullObject.hxx>
103 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
105 #define MAX2(X, Y) (Abs(X) > Abs(Y) ? Abs(X) : Abs(Y))
106 #define MAX3(X, Y, Z) (MAX2(MAX2(X,Y), Z))
108 #define STD_SORT_ALGO 1
110 #define DEFAULT_TOLERANCE_TOLERANCE 1.e-02
111 #define DEFAULT_MAX_TOLERANCE_TOLERANCE 1.e-06
113 // When the following macro is defined, ShapeFix_ShapeTolerance function is used to set max tolerance of curve
114 // in GEOMUtils::FixShapeCurves function; otherwise less restrictive BRep_Builder::UpdateEdge/UpdateVertex
116 // VSR (29/12/2014): macro disabled
117 //#define USE_LIMIT_TOLERANCE
122 * This function constructs and returns modified shape from the original one
123 * for singular cases. It is used for the method GetMinDistanceSingular.
125 * \param theShape the original shape
126 * \param theModifiedShape output parameter. The modified shape.
127 * \param theAddDist output parameter. The added distance for modified shape.
128 * \retval true if the shape is modified; false otherwise.
132 Standard_Boolean ModifyShape(const TopoDS_Shape &theShape,
133 TopoDS_Shape &theModifiedShape,
134 Standard_Real &theAddDist)
136 TopExp_Explorer anExp;
140 theModifiedShape.Nullify();
142 for ( anExp.Init( theShape, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
144 theModifiedShape = anExp.Current();
147 TopoDS_Shape sh = theShape;
148 while(sh.ShapeType()==TopAbs_COMPOUND) {
149 TopoDS_Iterator it(sh);
152 Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(theModifiedShape));
153 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
154 S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ||
156 const Standard_Boolean isShell =
157 (sh.ShapeType()==TopAbs_SHELL || sh.ShapeType()==TopAbs_FACE);
159 if ( !isShell && S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
160 Handle(Geom_SphericalSurface) SS = Handle(Geom_SphericalSurface)::DownCast(S);
161 gp_Pnt PC = SS->Location();
164 B.MakeVertex(V,PC,1.e-7);
165 theModifiedShape = V;
166 theAddDist = SS->Radius();
167 return Standard_True;
169 if ( !isShell && S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
170 Handle(Geom_ToroidalSurface) TS = Handle(Geom_ToroidalSurface)::DownCast(S);
171 gp_Ax3 ax3 = TS->Position();
172 Handle(Geom_Circle) C = new Geom_Circle(ax3.Ax2(),TS->MajorRadius());
175 B.MakeEdge(E,C,1.e-7);
176 theModifiedShape = E;
177 theAddDist = TS->MinorRadius();
178 return Standard_True;
181 // non solid case or any periodic surface (Mantis 22454).
183 // changes for 0020677: EDF 1219 GEOM: MinDistance gives 0 instead of 20.88
184 //S->Bounds(U1,U2,V1,V2); changed by
185 ShapeAnalysis::GetFaceUVBounds(TopoDS::Face(theModifiedShape),U1,U2,V1,V2);
186 // end of changes for 020677 (dmv)
187 Handle(Geom_RectangularTrimmedSurface) TrS1 =
188 new Geom_RectangularTrimmedSurface(S,U1,(U1+U2)/2.,V1,V2);
189 Handle(Geom_RectangularTrimmedSurface) TrS2 =
190 new Geom_RectangularTrimmedSurface(S,(U1+U2)/2.,U2,V1,V2);
191 TopoDS_Shape aMShape;
193 TopoDS_Face F1 = BRepBuilderAPI_MakeFace(TrS1, Precision::Confusion());
194 TopoDS_Face F2 = BRepBuilderAPI_MakeFace(TrS2, Precision::Confusion());
198 B.MakeCompound(TopoDS::Compound(aMShape));
202 // The original shape is a solid.
203 BRepBuilderAPI_Sewing aSewing (Precision::Confusion()*10.0);
207 aMShape = aSewing.SewedShape();
211 B.Add(aSolid, aMShape);
215 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
217 sfs->SetPrecision(1.e-6);
218 sfs->SetMaxTolerance(1.0);
220 theModifiedShape = sfs->Shape();
221 return Standard_True;
225 theModifiedShape = theShape;
226 return Standard_False;
229 void parseWard( const GEOMUtils::LevelsList &theLevelList, std::string &treeStr )
231 treeStr.append( "{" );
232 for( GEOMUtils::LevelsList::const_iterator j = theLevelList.begin();
233 j != theLevelList.end(); ++j ) {
234 if ( j != theLevelList.begin() ) {
235 treeStr.append( ";" );
237 GEOMUtils::LevelInfo level = (*j);
238 GEOMUtils::LevelInfo::iterator upIter;
239 for ( upIter = level.begin(); upIter != level.end(); ++upIter ) {
240 if ( upIter != level.begin() ) {
241 treeStr.append( "," );
243 treeStr.append( upIter->first );
244 for ( std::vector<std::string>::iterator k = upIter->second.begin(); k != upIter->second.end(); ++k ) {
245 treeStr.append( "_" );
246 treeStr.append( *k );
250 treeStr.append( "}" );
253 GEOMUtils::LevelsList parseWard( const std::string& theData, std::size_t& theCursor )
255 std::size_t indexStart = theData.find( "{", theCursor ) + 1;
256 std::size_t indexEnd = theData.find( "}", indexStart );
258 std::string ward = theData.substr( indexStart, indexEnd - indexStart );
259 std::stringstream ss(ward);
261 std::vector<std::string> levelsListStr;
262 while ( std::getline( ss, substr, ';' ) ) {
263 if ( !substr.empty() )
264 levelsListStr.push_back( substr );
266 GEOMUtils::LevelsList levelsListData;
267 for( size_t level = 0; level < levelsListStr.size(); level++ ) {
268 std::vector<std::string> namesListStr;
269 std::stringstream ss1( levelsListStr[level] );
270 while ( std::getline( ss1, substr, ',' ) ) {
271 if ( !substr.empty() )
272 namesListStr.push_back( substr );
274 GEOMUtils::LevelInfo levelInfoData;
275 for( size_t node = 0; node < namesListStr.size(); node++ ) {
276 std::vector<std::string> linksListStr;
277 std::stringstream ss2( namesListStr[node] );
278 while ( std::getline( ss2, substr, '_' ) ) {
279 if ( !substr.empty() )
280 linksListStr.push_back( substr );
282 std::string nodeItem = linksListStr[0];
283 if( !nodeItem.empty() ) {
284 GEOMUtils::NodeLinks linksListData;
285 for( size_t link = 1; link < linksListStr.size(); link++ ) {
286 std::string linkItem = linksListStr[link];
287 linksListData.push_back( linkItem );
289 levelInfoData[nodeItem] = linksListData;
292 levelsListData.push_back(levelInfoData);
295 theCursor = indexEnd + 1;
296 return levelsListData;
301 //=======================================================================
302 //function : ShapeToDouble
303 //purpose : used by CompareShapes::operator()
304 //=======================================================================
305 std::pair<double, double> GEOMUtils::ShapeToDouble (const TopoDS_Shape& S, bool isOldSorting)
307 // Computing of CentreOfMass
311 if (S.ShapeType() == TopAbs_VERTEX) {
312 GPoint = BRep_Tool::Pnt(TopoDS::Vertex(S));
313 Len = (double)S.Orientation();
317 // BEGIN: fix for Mantis issue 0020842
319 BRepGProp::LinearProperties(S, GPr);
322 if (S.ShapeType() == TopAbs_EDGE || S.ShapeType() == TopAbs_WIRE) {
323 BRepGProp::LinearProperties(S, GPr);
325 else if (S.ShapeType() == TopAbs_FACE || S.ShapeType() == TopAbs_SHELL) {
326 BRepGProp::SurfaceProperties(S, GPr);
329 BRepGProp::VolumeProperties(S, GPr);
332 // END: fix for Mantis issue 0020842
333 GPoint = GPr.CentreOfMass();
337 double dMidXYZ = GPoint.X() * 999.0 + GPoint.Y() * 99.0 + GPoint.Z() * 0.9;
338 return std::make_pair(dMidXYZ, Len);
341 //=======================================================================
342 //function : GetPosition
344 //=======================================================================
345 gp_Ax3 GEOMUtils::GetPosition (const TopoDS_Shape& theShape)
349 if (theShape.IsNull())
353 aResult.Transform(theShape.Location().Transformation());
354 if (theShape.ShapeType() == TopAbs_FACE) {
355 Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(theShape));
356 if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
357 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS);
358 gp_Pln aPln = aGPlane->Pln();
359 aResult = aPln.Position();
360 // In case of reverse orinetation of the face invert the plane normal
361 // (the face's normal does not mathc the plane's normal in this case)
362 if(theShape.Orientation() == TopAbs_REVERSED)
364 gp_Dir Vx = aResult.XDirection();
365 gp_Dir N = aResult.Direction().Mirrored(Vx);
366 gp_Pnt P = aResult.Location();
367 aResult = gp_Ax3(P, N, Vx);
375 TopAbs_ShapeEnum aShType = theShape.ShapeType();
377 if (aShType == TopAbs_VERTEX) {
378 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(theShape));
381 if (aShType == TopAbs_COMPOUND) {
382 aShType = GetTypeOfSimplePart(theShape);
385 GProp_GProps aSystem;
386 if (aShType == TopAbs_EDGE || aShType == TopAbs_WIRE)
387 BRepGProp::LinearProperties(theShape, aSystem);
388 else if (aShType == TopAbs_FACE || aShType == TopAbs_SHELL)
389 BRepGProp::SurfaceProperties(theShape, aSystem);
391 BRepGProp::VolumeProperties(theShape, aSystem);
393 aPnt = aSystem.CentreOfMass();
396 aResult.SetLocation(aPnt);
401 //=======================================================================
402 //function : GetVector
404 //=======================================================================
405 gp_Vec GEOMUtils::GetVector (const TopoDS_Shape& theShape,
406 Standard_Boolean doConsiderOrientation)
408 if (theShape.IsNull())
409 Standard_NullObject::Raise("Null shape is given for a vector");
411 if (theShape.ShapeType() != TopAbs_EDGE)
412 Standard_TypeMismatch::Raise("Invalid shape is given, must be a vector or an edge");
414 TopoDS_Edge anE = TopoDS::Edge(theShape);
416 TopoDS_Vertex V1, V2;
417 TopExp::Vertices(anE, V1, V2, doConsiderOrientation);
419 if (V1.IsNull() || V2.IsNull())
420 Standard_NullObject::Raise("Invalid edge is given, it must have two points");
422 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
423 if (aV.Magnitude() < gp::Resolution()) {
424 Standard_ConstructionError::Raise("Vector of zero length is given");
430 //=======================================================================
431 //function : CompareShapes::operator()
432 //purpose : used by std::sort(), called from SortShapes()
433 //=======================================================================
434 bool GEOMUtils::CompareShapes::operator() (const TopoDS_Shape& theShape1,
435 const TopoDS_Shape& theShape2)
437 if (!myMap.IsBound(theShape1)) {
438 myMap.Bind(theShape1, ShapeToDouble(theShape1, myIsOldSorting));
441 if (!myMap.IsBound(theShape2)) {
442 myMap.Bind(theShape2, ShapeToDouble(theShape2, myIsOldSorting));
445 std::pair<double, double> val1 = myMap.Find(theShape1);
446 std::pair<double, double> val2 = myMap.Find(theShape2);
448 double tol = Precision::Confusion();
449 bool exchange = Standard_False;
451 double dMidXYZ = val1.first - val2.first;
452 if (dMidXYZ >= tol) {
453 exchange = Standard_True;
455 else if (Abs(dMidXYZ) < tol) {
456 double dLength = val1.second - val2.second;
457 if (dLength >= tol) {
458 exchange = Standard_True;
460 else if (Abs(dLength) < tol && theShape1.ShapeType() <= TopAbs_FACE) {
462 // equal values possible on shapes such as two halves of a sphere and
463 // a membrane inside the sphere
465 BRepBndLib::Add(theShape1, box1);
466 if (!box1.IsVoid()) {
467 BRepBndLib::Add(theShape2, box2);
468 Standard_Real dSquareExtent = box1.SquareExtent() - box2.SquareExtent();
469 if (dSquareExtent >= tol) {
470 exchange = Standard_True;
472 else if (Abs(dSquareExtent) < tol) {
473 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax, val1, val2;
474 box1.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
475 val1 = (aXmin+aXmax)*999.0 + (aYmin+aYmax)*99.0 + (aZmin+aZmax)*0.9;
476 box2.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
477 val2 = (aXmin+aXmax)*999.0 + (aYmin+aYmax)*99.0 + (aZmin+aZmax)*0.9;
478 if ((val1 - val2) >= tol) {
479 exchange = Standard_True;
486 //return val1 < val2;
490 //=======================================================================
491 //function : SortShapes
493 //=======================================================================
494 void GEOMUtils::SortShapes (TopTools_ListOfShape& SL,
495 const Standard_Boolean isOldSorting)
498 std::vector<TopoDS_Shape> aShapesVec;
499 aShapesVec.reserve(SL.Extent());
501 TopTools_ListIteratorOfListOfShape it (SL);
502 for (; it.More(); it.Next()) {
503 aShapesVec.push_back(it.Value());
507 CompareShapes shComp (isOldSorting);
508 std::stable_sort(aShapesVec.begin(), aShapesVec.end(), shComp);
509 //std::sort(aShapesVec.begin(), aShapesVec.end(), shComp);
511 std::vector<TopoDS_Shape>::const_iterator anIter = aShapesVec.begin();
512 for (; anIter != aShapesVec.end(); ++anIter) {
516 // old implementation
517 Standard_Integer MaxShapes = SL.Extent();
518 TopTools_Array1OfShape aShapes (1,MaxShapes);
519 TColStd_Array1OfInteger OrderInd(1,MaxShapes);
520 TColStd_Array1OfReal MidXYZ (1,MaxShapes); //X,Y,Z;
521 TColStd_Array1OfReal Length (1,MaxShapes); //X,Y,Z;
523 // Computing of CentreOfMass
524 Standard_Integer Index;
527 TopTools_ListIteratorOfListOfShape it(SL);
528 for (Index=1; it.More(); Index++)
530 TopoDS_Shape S = it.Value();
531 SL.Remove( it ); // == it.Next()
533 OrderInd.SetValue (Index, Index);
534 if (S.ShapeType() == TopAbs_VERTEX) {
535 GPoint = BRep_Tool::Pnt( TopoDS::Vertex( S ));
536 Length.SetValue( Index, (Standard_Real) S.Orientation());
539 // BEGIN: fix for Mantis issue 0020842
541 BRepGProp::LinearProperties (S, GPr);
544 if (S.ShapeType() == TopAbs_EDGE || S.ShapeType() == TopAbs_WIRE) {
545 BRepGProp::LinearProperties (S, GPr);
547 else if (S.ShapeType() == TopAbs_FACE || S.ShapeType() == TopAbs_SHELL) {
548 BRepGProp::SurfaceProperties(S, GPr);
551 BRepGProp::VolumeProperties(S, GPr);
554 // END: fix for Mantis issue 0020842
555 GPoint = GPr.CentreOfMass();
556 Length.SetValue(Index, GPr.Mass());
558 MidXYZ.SetValue(Index, GPoint.X()*999.0 + GPoint.Y()*99.0 + GPoint.Z()*0.9);
559 //cout << Index << " L: " << Length(Index) << "CG: " << MidXYZ(Index) << endl;
563 Standard_Integer aTemp;
564 Standard_Boolean exchange, Sort = Standard_True;
565 Standard_Real tol = Precision::Confusion();
568 Sort = Standard_False;
569 for (Index=1; Index < MaxShapes; Index++)
571 exchange = Standard_False;
572 Standard_Real dMidXYZ = MidXYZ(OrderInd(Index)) - MidXYZ(OrderInd(Index+1));
573 Standard_Real dLength = Length(OrderInd(Index)) - Length(OrderInd(Index+1));
574 if ( dMidXYZ >= tol ) {
575 // cout << "MidXYZ: " << MidXYZ(OrderInd(Index))<< " > " <<MidXYZ(OrderInd(Index+1))
576 // << " d: " << dMidXYZ << endl;
577 exchange = Standard_True;
579 else if ( Abs(dMidXYZ) < tol && dLength >= tol ) {
580 // cout << "Length: " << Length(OrderInd(Index))<< " > " <<Length(OrderInd(Index+1))
581 // << " d: " << dLength << endl;
582 exchange = Standard_True;
584 else if ( Abs(dMidXYZ) < tol && Abs(dLength) < tol &&
585 aShapes(OrderInd(Index)).ShapeType() <= TopAbs_FACE) {
587 // equal values possible on shapes such as two halves of a sphere and
588 // a membrane inside the sphere
590 BRepBndLib::Add( aShapes( OrderInd(Index) ), box1 );
591 if ( box1.IsVoid() ) continue;
592 BRepBndLib::Add( aShapes( OrderInd(Index+1) ), box2 );
593 Standard_Real dSquareExtent = box1.SquareExtent() - box2.SquareExtent();
594 if ( dSquareExtent >= tol ) {
595 // cout << "SquareExtent: " << box1.SquareExtent()<<" > "<<box2.SquareExtent() << endl;
596 exchange = Standard_True;
598 else if ( Abs(dSquareExtent) < tol ) {
599 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax, val1, val2;
600 box1.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
601 val1 = (aXmin+aXmax)*999 + (aYmin+aYmax)*99 + (aZmin+aZmax)*0.9;
602 box2.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
603 val2 = (aXmin+aXmax)*999 + (aYmin+aYmax)*99 + (aZmin+aZmax)*0.9;
604 //exchange = val1 > val2;
605 if ((val1 - val2) >= tol) {
606 exchange = Standard_True;
608 //cout << "box: " << val1<<" > "<<val2 << endl;
614 // cout << "exchange " << Index << " & " << Index+1 << endl;
615 aTemp = OrderInd(Index);
616 OrderInd(Index) = OrderInd(Index+1);
617 OrderInd(Index+1) = aTemp;
618 Sort = Standard_True;
623 for (Index=1; Index <= MaxShapes; Index++)
624 SL.Append( aShapes( OrderInd(Index) ));
628 //=======================================================================
629 //function : CompsolidToCompound
631 //=======================================================================
632 TopoDS_Shape GEOMUtils::CompsolidToCompound (const TopoDS_Shape& theCompsolid)
634 if (theCompsolid.ShapeType() != TopAbs_COMPSOLID) {
638 TopoDS_Compound aCompound;
640 B.MakeCompound(aCompound);
642 TopTools_MapOfShape mapShape;
643 TopoDS_Iterator It (theCompsolid, Standard_True, Standard_True);
645 for (; It.More(); It.Next()) {
646 TopoDS_Shape aShape_i = It.Value();
647 if (mapShape.Add(aShape_i)) {
648 B.Add(aCompound, aShape_i);
655 //=======================================================================
656 //function : AddSimpleShapes
658 //=======================================================================
659 void GEOMUtils::AddSimpleShapes (const TopoDS_Shape& theShape, TopTools_ListOfShape& theList)
661 if (theShape.ShapeType() != TopAbs_COMPOUND &&
662 theShape.ShapeType() != TopAbs_COMPSOLID) {
663 theList.Append(theShape);
667 TopTools_MapOfShape mapShape;
668 TopoDS_Iterator It (theShape, Standard_True, Standard_True);
670 for (; It.More(); It.Next()) {
671 TopoDS_Shape aShape_i = It.Value();
672 if (mapShape.Add(aShape_i)) {
673 if (aShape_i.ShapeType() == TopAbs_COMPOUND ||
674 aShape_i.ShapeType() == TopAbs_COMPSOLID) {
675 AddSimpleShapes(aShape_i, theList);
677 theList.Append(aShape_i);
683 //=======================================================================
684 //function : CheckTriangulation
686 //=======================================================================
687 bool GEOMUtils::CheckTriangulation (const TopoDS_Shape& aShape)
689 bool isTriangulation = true;
691 TopExp_Explorer exp (aShape, TopAbs_FACE);
694 TopLoc_Location aTopLoc;
695 Handle(Poly_Triangulation) aTRF;
696 aTRF = BRep_Tool::Triangulation(TopoDS::Face(exp.Current()), aTopLoc);
698 isTriangulation = false;
701 else // no faces, try edges
703 TopExp_Explorer expe (aShape, TopAbs_EDGE);
707 TopLoc_Location aLoc;
708 Handle(Poly_Polygon3D) aPE = BRep_Tool::Polygon3D(TopoDS::Edge(expe.Current()), aLoc);
710 isTriangulation = false;
714 if (!isTriangulation) {
715 // calculate deflection
716 Standard_Real aDeviationCoefficient = 0.001;
719 BRepBndLib::Add(aShape, B);
720 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
721 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
723 Standard_Real dx = aXmax - aXmin, dy = aYmax - aYmin, dz = aZmax - aZmin;
724 Standard_Real aDeflection = Max(Max(dx, dy), dz) * aDeviationCoefficient * 4;
725 Standard_Real aHLRAngle = 0.349066;
727 BRepMesh_IncrementalMesh Inc (aShape, aDeflection, Standard_False, aHLRAngle);
733 //=======================================================================
734 //function : GetTypeOfSimplePart
736 //=======================================================================
737 TopAbs_ShapeEnum GEOMUtils::GetTypeOfSimplePart (const TopoDS_Shape& theShape)
739 TopAbs_ShapeEnum aType = theShape.ShapeType();
740 if (aType == TopAbs_VERTEX) return TopAbs_VERTEX;
741 else if (aType == TopAbs_EDGE || aType == TopAbs_WIRE) return TopAbs_EDGE;
742 else if (aType == TopAbs_FACE || aType == TopAbs_SHELL) return TopAbs_FACE;
743 else if (aType == TopAbs_SOLID || aType == TopAbs_COMPSOLID) return TopAbs_SOLID;
744 else if (aType == TopAbs_COMPOUND) {
745 // Only the iType of the first shape in the compound is taken into account
746 TopoDS_Iterator It (theShape, Standard_False, Standard_False);
748 return GetTypeOfSimplePart(It.Value());
754 //=======================================================================
755 //function : GetEdgeNearPoint
757 //=======================================================================
758 TopoDS_Shape GEOMUtils::GetEdgeNearPoint (const TopoDS_Shape& theShape,
759 const TopoDS_Vertex& thePoint)
761 TopoDS_Shape aResult;
763 // 1. Explode the shape on edges
764 TopTools_MapOfShape mapShape;
765 Standard_Integer nbEdges = 0;
766 TopExp_Explorer exp (theShape, TopAbs_EDGE);
767 for (; exp.More(); exp.Next()) {
768 if (mapShape.Add(exp.Current())) {
774 Standard_NullObject::Raise("Given shape contains no edges");
777 Standard_Integer ind = 1;
778 TopTools_Array1OfShape anEdges (1, nbEdges);
779 TColStd_Array1OfReal aDistances (1, nbEdges);
780 for (exp.Init(theShape, TopAbs_EDGE); exp.More(); exp.Next()) {
781 if (mapShape.Add(exp.Current())) {
782 TopoDS_Shape anEdge = exp.Current();
783 anEdges(ind) = anEdge;
785 // 2. Classify the point relatively each edge
786 BRepExtrema_DistShapeShape aDistTool (thePoint, anEdges(ind));
787 if (!aDistTool.IsDone())
788 Standard_ConstructionError::Raise("Cannot find a distance from the given point to one of edges");
790 aDistances(ind) = aDistTool.Value();
795 // 3. Define edge, having minimum distance to the point
796 Standard_Real nearest = RealLast(), nbFound = 0;
797 Standard_Real prec = Precision::Confusion();
798 for (ind = 1; ind <= nbEdges; ind++) {
799 if (Abs(aDistances(ind) - nearest) < prec) {
802 else if (aDistances(ind) < nearest) {
803 nearest = aDistances(ind);
804 aResult = anEdges(ind);
811 Standard_ConstructionError::Raise("Multiple edges near the given point are found");
813 else if (nbFound == 0) {
814 Standard_ConstructionError::Raise("There are no edges near the given point");
822 //=======================================================================
823 //function : PreciseBoundingBox
825 //=======================================================================
826 Standard_Boolean GEOMUtils::PreciseBoundingBox
827 (const TopoDS_Shape &theShape, Bnd_Box &theBox)
829 if ( theBox.IsVoid() ) BRepBndLib::Add( theShape, theBox );
830 if ( theBox.IsVoid() ) return Standard_False;
832 Standard_Real aBound[6];
833 theBox.Get(aBound[0], aBound[2], aBound[4], aBound[1], aBound[3], aBound[5]);
836 const gp_Pnt aMid(0.5*(aBound[1] + aBound[0]), // XMid
837 0.5*(aBound[3] + aBound[2]), // YMid
838 0.5*(aBound[5] + aBound[4])); // ZMid
839 const gp_XYZ aSize(aBound[1] - aBound[0], // DX
840 aBound[3] - aBound[2], // DY
841 aBound[5] - aBound[4]); // DZ
842 const gp_Pnt aPnt[6] =
844 gp_Pnt(aBound[0] - (aBound[1] - aBound[0]), aMid.Y(), aMid.Z()), // XMin
845 gp_Pnt(aBound[1] + (aBound[1] - aBound[0]), aMid.Y(), aMid.Z()), // XMax
846 gp_Pnt(aMid.X(), aBound[2] - (aBound[3] - aBound[2]), aMid.Z()), // YMin
847 gp_Pnt(aMid.X(), aBound[3] + (aBound[3] - aBound[2]), aMid.Z()), // YMax
848 gp_Pnt(aMid.X(), aMid.Y(), aBound[4] - (aBound[5] - aBound[4])), // ZMin
849 gp_Pnt(aMid.X(), aMid.Y(), aBound[5] + (aBound[5] - aBound[4])) // ZMax
851 const gp_Dir aDir[3] = { gp::DX(), gp::DY(), gp::DZ() };
852 const Standard_Real aPlnSize[3] =
854 0.5*Max(aSize.Y(), aSize.Z()), // XMin, XMax planes
855 0.5*Max(aSize.X(), aSize.Z()), // YMin, YMax planes
856 0.5*Max(aSize.X(), aSize.Y()) // ZMin, ZMax planes
860 for (i = 0; i < 6; i++) {
861 const Standard_Integer iHalf = i/2;
862 const gp_Pln aPln(aPnt[i], aDir[iHalf]);
863 BRepBuilderAPI_MakeFace aMkFace(aPln, -aPlnSize[iHalf], aPlnSize[iHalf],
864 -aPlnSize[iHalf], aPlnSize[iHalf]);
866 if (!aMkFace.IsDone()) {
867 return Standard_False;
870 TopoDS_Shape aFace = aMkFace.Shape();
872 // Get minimal distance between planar face and shape.
873 Standard_Real aMinDist =
874 GEOMUtils::GetMinDistance(aFace, theShape, aPMin[0], aPMin[1]);
877 return Standard_False;
880 aBound[i] = aPMin[1].Coord(iHalf + 1);
883 // Update Bounding box with the new values.
885 theBox.Update(aBound[0], aBound[2], aBound[4], aBound[1], aBound[3], aBound[5]);
887 return Standard_True;
890 //=======================================================================
891 //function : GetMinDistanceSingular
893 //=======================================================================
894 double GEOMUtils::GetMinDistanceSingular(const TopoDS_Shape& aSh1,
895 const TopoDS_Shape& aSh2,
896 gp_Pnt& Ptmp1, gp_Pnt& Ptmp2)
900 Standard_Real AddDist1 = 0.;
901 Standard_Real AddDist2 = 0.;
902 Standard_Boolean IsChange1 = ModifyShape(aSh1, tmpSh1, AddDist1);
903 Standard_Boolean IsChange2 = ModifyShape(aSh2, tmpSh2, AddDist2);
905 if( !IsChange1 && !IsChange2 )
908 BRepExtrema_DistShapeShape dst(tmpSh1,tmpSh2);
910 double MinDist = 1.e9;
911 gp_Pnt PMin1, PMin2, P1, P2;
912 for (int i = 1; i <= dst.NbSolution(); i++) {
913 P1 = dst.PointOnShape1(i);
914 P2 = dst.PointOnShape2(i);
915 Standard_Real Dist = P1.Distance(P2);
916 if (MinDist > Dist) {
927 gp_Dir aDir(gp_Vec(PMin1,PMin2));
928 if( MinDist > (AddDist1+AddDist2) ) {
929 Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
930 PMin1.Y() + aDir.Y()*AddDist1,
931 PMin1.Z() + aDir.Z()*AddDist1 );
932 Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
933 PMin2.Y() - aDir.Y()*AddDist2,
934 PMin2.Z() - aDir.Z()*AddDist2 );
935 return (MinDist - AddDist1 - AddDist2);
939 Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
940 PMin1.Y() + aDir.Y()*AddDist1,
941 PMin1.Z() + aDir.Z()*AddDist1 );
945 Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
946 PMin2.Y() - aDir.Y()*AddDist2,
947 PMin2.Z() - aDir.Z()*AddDist2 );
952 double res = MinDist - AddDist1 - AddDist2;
953 if(res<0.) res = 0.0;
959 //=======================================================================
960 //function : GetMinDistance
962 //=======================================================================
963 Standard_Real GEOMUtils::GetMinDistance
964 (const TopoDS_Shape& theShape1,
965 const TopoDS_Shape& theShape2,
966 gp_Pnt& thePnt1, gp_Pnt& thePnt2)
968 Standard_Real aResult = 1.e9;
970 // Issue 0020231: A min distance bug with torus and vertex.
971 // Make GetMinDistance() return zero if a sole VERTEX is inside any of SOLIDs
973 // which of shapes consists of only one vertex?
974 TopExp_Explorer exp1(theShape1,TopAbs_VERTEX), exp2(theShape2,TopAbs_VERTEX);
975 TopoDS_Shape V1 = exp1.More() ? exp1.Current() : TopoDS_Shape();
976 TopoDS_Shape V2 = exp2.More() ? exp2.Current() : TopoDS_Shape();
977 exp1.Next(); exp2.Next();
978 if ( exp1.More() ) V1.Nullify();
979 if ( exp2.More() ) V2.Nullify();
980 // vertex and container of solids
981 TopoDS_Shape V = V1.IsNull() ? V2 : V1;
982 TopoDS_Shape S = V1.IsNull() ? theShape1 : theShape2;
984 // classify vertex against solids
985 gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( V ) );
986 for ( exp1.Init( S, TopAbs_SOLID ); exp1.More(); exp1.Next() ) {
987 BRepClass3d_SolidClassifier classifier( exp1.Current(), p, 1e-6);
988 if ( classifier.State() == TopAbs_IN ) {
998 // additional workaround for bugs 19899, 19908 and 19910 from Mantis
999 aResult = GEOMUtils::GetMinDistanceSingular(theShape1, theShape2, thePnt1, thePnt2);
1007 BRepExtrema_DistShapeShape dst (theShape1, theShape2);
1011 for (int i = 1; i <= dst.NbSolution(); i++) {
1012 P1 = dst.PointOnShape1(i);
1013 P2 = dst.PointOnShape2(i);
1015 Standard_Real Dist = P1.Distance(P2);
1016 if (aResult < 0 || aResult > Dist) {
1027 //=======================================================================
1028 // function : ProjectPointOnFace()
1029 // purpose : Returns the projection (3d point) if found, throws an exception otherwise
1030 //=======================================================================
1031 gp_Pnt GEOMUtils::ProjectPointOnFace(const gp_Pnt& thePoint,
1032 const TopoDS_Shape& theFace,
1033 double& theU, double& theV)
1035 if (theFace.IsNull() || theFace.ShapeType() != TopAbs_FACE)
1036 Standard_TypeMismatch::Raise
1037 ("Projection aborted : the target shape is not a face");
1039 TopoDS_Face aFace = TopoDS::Face(theFace);
1040 Handle(Geom_Surface) surface = BRep_Tool::Surface(aFace);
1041 double U1, U2, V1, V2;
1042 BRepTools::UVBounds(aFace, U1, U2, V1, V2);
1045 Standard_Real tol = 1.e-4;
1046 GeomAPI_ProjectPointOnSurf proj;
1047 proj.Init(surface, U1, U2, V1, V2, tol);
1048 proj.Perform(thePoint);
1050 StdFail_NotDone::Raise("Projection aborted : the algorithm failed");
1051 int nbPoints = proj.NbPoints();
1053 Standard_ConstructionError::Raise("Projection aborted : No solution found");
1054 proj.LowerDistanceParameters(theU, theV);
1055 gp_Pnt2d aProjPnt (theU, theV);
1058 BRepClass_FaceClassifier aClsf (aFace, aProjPnt, tol);
1059 if (aClsf.State() != TopAbs_IN && aClsf.State() != TopAbs_ON) {
1061 double minDist = RealLast();
1062 for (int i = 1; i <= nbPoints; i++) {
1063 Standard_Real Ui, Vi;
1064 proj.Parameters(i, Ui, Vi);
1065 aProjPnt = gp_Pnt2d(Ui, Vi);
1066 aClsf.Perform(aFace, aProjPnt, tol);
1067 if (aClsf.State() == TopAbs_IN || aClsf.State() == TopAbs_ON) {
1069 double dist = proj.Distance(i);
1070 if (dist < minDist) {
1078 Standard_ConstructionError::Raise("Projection aborted : No solution found");
1082 gp_Pnt surfPnt = surface->Value(theU, theV);
1086 //=======================================================================
1087 // function : ConvertClickToPoint()
1088 // purpose : Returns the point clicked in 3D view
1089 //=======================================================================
1090 gp_Pnt GEOMUtils::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView )
1092 // We can't rely on Eye and At points to get EyeDir, because they collapse
1093 // for views with flat bounding boxes. For example if you create a circle and
1094 // switch to the top view, then both camera's Eye and At points will fall to zero
1095 // inside V3d_View::FitMinMax() method. It's by occt design.
1096 // So, we should use camera direction instead.
1098 V3d_Coordinate XAt, YAt, ZAt;
1099 aView->At(XAt, YAt, ZAt);
1100 gp_Pnt AtPoint(XAt, YAt, ZAt);
1102 gp_Pln PlaneOfTheView = gp_Pln( AtPoint, aView->Camera()->Direction() );
1103 Standard_Real X, Y, Z;
1104 aView->Convert( x, y, X, Y, Z );
1105 gp_Pnt ConvertedPoint( X, Y, Z );
1107 gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint );
1108 gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView );
1112 //=======================================================================
1113 // function : ConvertTreeToString()
1114 // purpose : Returns the string representation of dependency tree
1115 //=======================================================================
1116 void GEOMUtils::ConvertTreeToString( const TreeModel& tree,
1117 std::string& dependencyStr )
1119 TreeModel::const_iterator i;
1120 for ( i = tree.begin(); i != tree.end(); ++i ) {
1121 dependencyStr.append( i->first );
1122 dependencyStr.append( "-" );
1123 std::vector<LevelInfo> upLevelList = i->second.first;
1124 dependencyStr.append( "upward" );
1125 parseWard( upLevelList, dependencyStr );
1126 std::vector<LevelInfo> downLevelList = i->second.second;
1127 dependencyStr.append( "downward" );
1128 parseWard( downLevelList, dependencyStr );
1132 //=======================================================================
1133 // function : ConvertStringToTree()
1134 // purpose : Returns the dependency tree
1135 //=======================================================================
1136 void GEOMUtils::ConvertStringToTree( const std::string& dependencyStr,
1139 std::size_t cursor = 0;
1141 while( dependencyStr.find('-',cursor) != std::string::npos ) //find next selected object
1143 std::size_t objectIndex = dependencyStr.find( '-', cursor );
1144 std::string objectEntry = dependencyStr.substr( cursor, objectIndex - cursor );
1145 cursor = objectIndex;
1147 //std::size_t upwardIndexBegin = dependencyStr.find("{",cursor) + 1;
1148 //std::size_t upwardIndexFinish = dependencyStr.find("}",upwardIndexBegin);
1149 LevelsList upwardList = parseWard( dependencyStr, cursor );
1151 LevelsList downwardList = parseWard( dependencyStr, cursor );
1153 tree[objectEntry] = std::pair<LevelsList,LevelsList>( upwardList, downwardList );
1157 bool GEOMUtils::CheckShape( TopoDS_Shape& shape,
1158 bool checkGeometry )
1160 BRepCheck_Analyzer analyzer( shape, checkGeometry );
1161 return analyzer.IsValid();
1164 bool GEOMUtils::CheckBOPArguments(const TopoDS_Shape &theShape)
1166 BOPAlgo_ArgumentAnalyzer aChecker;
1168 aChecker.SetShape1(theShape);
1170 // Set default options
1171 aChecker.ArgumentTypeMode() = Standard_True;
1172 aChecker.SelfInterMode() = Standard_True;
1173 aChecker.SmallEdgeMode() = Standard_True;
1174 aChecker.RebuildFaceMode() = Standard_True;
1175 aChecker.ContinuityMode() = Standard_True;
1176 aChecker.CurveOnSurfaceMode() = Standard_True;
1178 aChecker.StopOnFirstFaulty() = Standard_True;
1181 // process result of checking
1182 const bool isValid = !aChecker.HasFaulty();
1187 bool GEOMUtils::FixShapeTolerance( TopoDS_Shape& shape,
1188 TopAbs_ShapeEnum type,
1189 Standard_Real tolerance,
1190 bool checkGeometry )
1192 ShapeFix_ShapeTolerance aSft;
1193 aSft.LimitTolerance( shape, tolerance, tolerance, type );
1194 Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape( shape );
1196 shape = aSfs->Shape();
1197 return CheckShape( shape, checkGeometry );
1200 bool GEOMUtils::FixShapeTolerance( TopoDS_Shape& shape,
1201 Standard_Real tolerance,
1202 bool checkGeometry )
1204 return FixShapeTolerance( shape, TopAbs_SHAPE, tolerance, checkGeometry );
1207 bool GEOMUtils::FixShapeTolerance( TopoDS_Shape& shape,
1208 bool checkGeometry )
1210 return FixShapeTolerance( shape, Precision::Confusion(), checkGeometry );
1213 bool GEOMUtils::FixShapeCurves( TopoDS_Shape& shape )
1215 Standard_Real aT, aTolE, aD, aDMax;
1216 TopExp_Explorer aExpF, aExpE;
1217 NCollection_DataMap<TopoDS_Edge, Standard_Real, TopTools_ShapeMapHasher> aDMETol;
1218 aExpF.Init(shape, TopAbs_FACE);
1219 for (; aExpF.More(); aExpF.Next()) {
1220 const TopoDS_Face& aF = *(TopoDS_Face*)&aExpF.Current();
1221 aExpE.Init(aF, TopAbs_EDGE);
1222 for (; aExpE.More(); aExpE.Next()) {
1223 const TopoDS_Edge& aE = *(TopoDS_Edge*)&aExpE.Current();
1225 if (!BOPTools_AlgoTools::ComputeTolerance(aF, aE, aDMax, aT)) {
1232 aTolE = BRep_Tool::Tolerance(aE);
1233 if (aDMax < aTolE) continue;
1234 if (aDMETol.IsBound(aE)) {
1235 aD = aDMETol.Find(aE);
1238 aDMETol.Bind(aE, aDMax);
1242 aDMETol.Bind(aE, aDMax);
1246 NCollection_DataMap<TopoDS_Edge, Standard_Real, TopTools_ShapeMapHasher>::Iterator aDMETolIt(aDMETol);
1247 #ifdef USE_LIMIT_TOLERANCE
1248 ShapeFix_ShapeTolerance sat;
1252 for (; aDMETolIt.More(); aDMETolIt.Next()) {
1253 #ifdef USE_LIMIT_TOLERANCE
1254 sat.LimitTolerance(aDMETolIt.Key(), aDMETolIt.Value()*1.001);
1256 TopoDS_Iterator itv(aDMETolIt.Key());
1257 for (; itv.More(); itv.Next())
1258 b.UpdateVertex(TopoDS::Vertex(itv.Value()), aDMETolIt.Value()*1.001);
1259 b.UpdateEdge(aDMETolIt.Key(), aDMETolIt.Value()*1.001);
1262 return CheckShape( shape );
1265 bool GEOMUtils::Write( const TopoDS_Shape& shape, const char* fileName )
1267 return BRepTools::Write( shape, fileName );
1270 TopoDS_Shape GEOMUtils::ReduceCompound( const TopoDS_Shape& shape )
1272 TopoDS_Shape result = shape;
1274 if ( shape.ShapeType() == TopAbs_COMPOUND ||
1275 shape.ShapeType() == TopAbs_COMPSOLID ) {
1277 TopTools_ListOfShape l;
1279 TopoDS_Iterator it ( shape );
1280 for ( ; it.More(); it.Next() )
1281 l.Append( it.Value() );
1282 if ( l.Extent() == 1 && l.First() != shape )
1283 result = ReduceCompound( l.First() );
1289 void GEOMUtils::MeshShape( const TopoDS_Shape shape,
1290 double deflection, bool theForced )
1292 Standard_Real aDeflection = ( deflection <= 0 ) ? DefaultDeflection() : deflection;
1294 // Is shape triangulated?
1295 Standard_Boolean alreadyMeshed = true;
1297 TopLoc_Location aLoc;
1298 for ( ex.Init( shape, TopAbs_FACE ); ex.More() && alreadyMeshed; ex.Next() ) {
1299 const TopoDS_Face& aFace = TopoDS::Face( ex.Current() );
1300 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation( aFace, aLoc );
1301 alreadyMeshed = !aPoly.IsNull();
1304 if ( !alreadyMeshed || theForced ) {
1305 // Compute bounding box
1307 BRepBndLib::Add( shape, B );
1309 return; // NPAL15983 (Bug when displaying empty groups)
1310 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
1311 B.Get( aXmin, aYmin, aZmin, aXmax, aYmax, aZmax );
1313 // This magic line comes from Prs3d_ShadedShape.gxx in OCCT
1314 aDeflection = MAX3(aXmax-aXmin, aYmax-aYmin, aZmax-aZmin) * aDeflection * 4;
1316 // Clean triangulation before compute incremental mesh
1317 BRepTools::Clean( shape );
1319 // Compute triangulation
1320 BRepMesh_IncrementalMesh mesh( shape, aDeflection );
1324 double GEOMUtils::DefaultDeflection()
1329 //=======================================================================
1330 //function : IsOpenPath
1332 //=======================================================================
1333 bool GEOMUtils::IsOpenPath(const TopoDS_Shape &theShape)
1337 if (theShape.IsNull() == Standard_False) {
1338 if (theShape.Closed()) {
1339 // The shape is closed
1342 const TopAbs_ShapeEnum aType = theShape.ShapeType();
1344 if (aType == TopAbs_EDGE || aType == TopAbs_WIRE) {
1345 // Check if path ends are coincident.
1346 TopoDS_Vertex aV[2];
1348 if (aType == TopAbs_EDGE) {
1350 TopExp::Vertices(TopoDS::Edge(theShape), aV[0], aV[1]);
1353 TopExp::Vertices(TopoDS::Wire(theShape), aV[0], aV[1]);
1356 if (aV[0].IsNull() == Standard_False &&
1357 aV[1].IsNull() == Standard_False) {
1358 if (aV[0].IsSame(aV[1])) {
1359 // The shape is closed
1362 const Standard_Real aTol1 = BRep_Tool::Tolerance(aV[0]);
1363 const Standard_Real aTol2 = BRep_Tool::Tolerance(aV[1]);
1364 const gp_Pnt aPnt1 = BRep_Tool::Pnt(aV[0]);
1365 const gp_Pnt aPnt2 = BRep_Tool::Pnt(aV[1]);
1367 if (aPnt1.Distance(aPnt2) <= aTol1 + aTol2) {
1368 // The shape is closed
1380 //=======================================================================
1381 //function : CompareToleranceValues
1383 //=======================================================================
1384 int GEOMUtils::CompareToleranceValues(const double theTolShape,
1385 const double theTolRef)
1387 const double aTolTol = Min(DEFAULT_MAX_TOLERANCE_TOLERANCE,
1388 theTolRef*DEFAULT_TOLERANCE_TOLERANCE);
1392 if (theTolShape < theTolRef - aTolTol) {
1394 } else if (theTolShape > theTolRef + aTolTol) {
1401 //=======================================================================
1402 //function : IsFitCondition
1404 //=======================================================================
1405 bool GEOMUtils::IsFitCondition(const ComparisonCondition theCondition,
1406 const double theTolShape,
1407 const double theTolRef)
1409 const int aCompValue = CompareToleranceValues(theTolShape, theTolRef);
1412 switch (theCondition) {
1414 isFit = aCompValue == 1;
1416 case GEOMUtils::CC_GE:
1417 isFit = aCompValue != -1;
1419 case GEOMUtils::CC_LT:
1420 isFit = aCompValue == -1;
1422 case GEOMUtils::CC_LE:
1423 isFit = aCompValue != 1;