1 // Copyright (C) 2007-2024 CEA, EDF, 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>
29 #include <Basics_OCCTVersion.hxx>
32 #include <BRepMesh_IncrementalMesh.hxx>
34 #include <BRepExtrema_DistShapeShape.hxx>
36 #include <BRep_Builder.hxx>
37 #include <BRep_Tool.hxx>
38 #include <BRepBndLib.hxx>
39 #include <BRepGProp.hxx>
40 #include <BRepTools.hxx>
42 #include <BRepClass_FaceClassifier.hxx>
43 #include <BRepClass3d_SolidClassifier.hxx>
45 #include <BRepBuilderAPI_MakeFace.hxx>
46 #include <BRepBuilderAPI_Sewing.hxx>
48 #include <BRepCheck_Analyzer.hxx>
50 #include <Bnd_Box.hxx>
52 #include <BOPAlgo_ArgumentAnalyzer.hxx>
53 #include <BOPTools_AlgoTools.hxx>
58 #include <TopoDS_Edge.hxx>
59 #include <TopoDS_Face.hxx>
60 #include <TopoDS_Shape.hxx>
61 #include <TopoDS_Vertex.hxx>
62 #include <TopoDS_Compound.hxx>
63 #include <TopoDS_Iterator.hxx>
64 #include <TopExp_Explorer.hxx>
65 #include <TopTools_MapOfShape.hxx>
66 #include <TopTools_ListOfShape.hxx>
67 #include <TopTools_ListIteratorOfListOfShape.hxx>
68 #include <TopTools_Array1OfShape.hxx>
70 #include <GeomAPI_ProjectPointOnSurf.hxx>
72 #include <Geom_Circle.hxx>
73 #include <Geom_Surface.hxx>
74 #include <Geom_Plane.hxx>
75 #include <Geom_SphericalSurface.hxx>
76 #include <Geom_ToroidalSurface.hxx>
77 #include <Geom_RectangularTrimmedSurface.hxx>
79 #include <GeomLProp_CLProps.hxx>
80 #include <GeomLProp_SLProps.hxx>
82 #include <GProp_GProps.hxx>
83 #include <GProp_PrincipalProps.hxx>
85 #include <TColStd_Array1OfReal.hxx>
90 #include <ShapeFix_Shape.hxx>
91 #include <ShapeFix_ShapeTolerance.hxx>
93 #include <ProjLib.hxx>
100 #include <Standard_Failure.hxx>
101 #include <Standard_NullObject.hxx>
102 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
104 #define MAX2(X, Y) (Abs(X) > Abs(Y) ? Abs(X) : Abs(Y))
105 #define MAX3(X, Y, Z) (MAX2(MAX2(X,Y), Z))
107 #define STD_SORT_ALGO 1
109 #define DEFAULT_TOLERANCE_TOLERANCE 1.e-02
110 #define DEFAULT_MAX_TOLERANCE_TOLERANCE 1.e-06
112 // When the following macro is defined, ShapeFix_ShapeTolerance function is used to set max tolerance of curve
113 // in GEOMUtils::FixShapeCurves function; otherwise less restrictive BRep_Builder::UpdateEdge/UpdateVertex
115 // VSR (29/12/2014): macro disabled
116 //#define USE_LIMIT_TOLERANCE
121 * This function constructs and returns modified shape from the original one
122 * for singular cases. It is used for the method GetMinDistanceSingular.
124 * \param theShape the original shape
125 * \param theModifiedShape output parameter. The modified shape.
126 * \param theAddDist output parameter. The added distance for modified shape.
127 * \retval true if the shape is modified; false otherwise.
131 Standard_Boolean ModifyShape(const TopoDS_Shape &theShape,
132 TopoDS_Shape &theModifiedShape,
133 Standard_Real &theAddDist)
135 TopExp_Explorer anExp;
139 theModifiedShape.Nullify();
141 for ( anExp.Init( theShape, TopAbs_FACE ); anExp.More(); anExp.Next() ) {
143 theModifiedShape = anExp.Current();
146 TopoDS_Shape sh = theShape;
147 while(sh.ShapeType()==TopAbs_COMPOUND) {
148 TopoDS_Iterator it(sh);
151 Handle(Geom_Surface) S = BRep_Tool::Surface(TopoDS::Face(theModifiedShape));
152 if( S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
153 S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ||
155 const Standard_Boolean isShell =
156 (sh.ShapeType()==TopAbs_SHELL || sh.ShapeType()==TopAbs_FACE);
158 if ( !isShell && S->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ) {
159 Handle(Geom_SphericalSurface) SS = Handle(Geom_SphericalSurface)::DownCast(S);
160 gp_Pnt PC = SS->Location();
163 B.MakeVertex(V,PC,1.e-7);
164 theModifiedShape = V;
165 theAddDist = SS->Radius();
166 return Standard_True;
168 if ( !isShell && S->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
169 Handle(Geom_ToroidalSurface) TS = Handle(Geom_ToroidalSurface)::DownCast(S);
170 gp_Ax3 ax3 = TS->Position();
171 Handle(Geom_Circle) C = new Geom_Circle(ax3.Ax2(),TS->MajorRadius());
174 B.MakeEdge(E,C,1.e-7);
175 theModifiedShape = E;
176 theAddDist = TS->MinorRadius();
177 return Standard_True;
180 // non solid case or any periodic surface (Mantis 22454).
182 BRepTools::UVBounds(TopoDS::Face(theModifiedShape),U1,U2,V1,V2);
183 // end of changes for 020677 (dmv)
184 Handle(Geom_RectangularTrimmedSurface) TrS1 =
185 new Geom_RectangularTrimmedSurface(S,U1,(U1+U2)/2.,V1,V2);
186 Handle(Geom_RectangularTrimmedSurface) TrS2 =
187 new Geom_RectangularTrimmedSurface(S,(U1+U2)/2.,U2,V1,V2);
188 TopoDS_Shape aMShape;
190 TopoDS_Face F1 = BRepBuilderAPI_MakeFace(TrS1, Precision::Confusion());
191 TopoDS_Face F2 = BRepBuilderAPI_MakeFace(TrS2, Precision::Confusion());
195 B.MakeCompound(TopoDS::Compound(aMShape));
199 // The original shape is a solid.
200 BRepBuilderAPI_Sewing aSewing (Precision::Confusion()*10.0);
204 aMShape = aSewing.SewedShape();
208 B.Add(aSolid, aMShape);
212 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
214 sfs->SetPrecision(1.e-6);
215 sfs->SetMaxTolerance(1.0);
217 theModifiedShape = sfs->Shape();
218 return Standard_True;
222 theModifiedShape = theShape;
223 return Standard_False;
226 void parseWard( const GEOMUtils::LevelsList &theLevelList, std::string &treeStr )
228 treeStr.append( "{" );
229 for( GEOMUtils::LevelsList::const_iterator j = theLevelList.begin();
230 j != theLevelList.end(); ++j ) {
231 if ( j != theLevelList.begin() ) {
232 treeStr.append( ";" );
234 GEOMUtils::LevelInfo level = (*j);
235 GEOMUtils::LevelInfo::iterator upIter;
236 for ( upIter = level.begin(); upIter != level.end(); ++upIter ) {
237 if ( upIter != level.begin() ) {
238 treeStr.append( "," );
240 treeStr.append( upIter->first );
241 for ( std::vector<std::string>::iterator k = upIter->second.begin(); k != upIter->second.end(); ++k ) {
242 treeStr.append( "_" );
243 treeStr.append( *k );
247 treeStr.append( "}" );
250 GEOMUtils::LevelsList parseWard( const std::string& theData, std::size_t& theCursor )
252 std::size_t indexStart = theData.find( "{", theCursor ) + 1;
253 std::size_t indexEnd = theData.find( "}", indexStart );
255 std::string ward = theData.substr( indexStart, indexEnd - indexStart );
256 std::stringstream ss(ward);
258 std::vector<std::string> levelsListStr;
259 while ( std::getline( ss, substr, ';' ) ) {
260 if ( !substr.empty() )
261 levelsListStr.push_back( substr );
263 GEOMUtils::LevelsList levelsListData;
264 for( size_t level = 0; level < levelsListStr.size(); level++ ) {
265 std::vector<std::string> namesListStr;
266 std::stringstream ss1( levelsListStr[level] );
267 while ( std::getline( ss1, substr, ',' ) ) {
268 if ( !substr.empty() )
269 namesListStr.push_back( substr );
271 GEOMUtils::LevelInfo levelInfoData;
272 for( size_t node = 0; node < namesListStr.size(); node++ ) {
273 std::vector<std::string> linksListStr;
274 std::stringstream ss2( namesListStr[node] );
275 while ( std::getline( ss2, substr, '_' ) ) {
276 if ( !substr.empty() )
277 linksListStr.push_back( substr );
279 std::string nodeItem = linksListStr[0];
280 if( !nodeItem.empty() ) {
281 GEOMUtils::NodeLinks linksListData;
282 for( size_t link = 1; link < linksListStr.size(); link++ ) {
283 std::string linkItem = linksListStr[link];
284 linksListData.push_back( linkItem );
286 levelInfoData[nodeItem] = linksListData;
289 levelsListData.push_back(levelInfoData);
292 theCursor = indexEnd + 1;
293 return levelsListData;
298 //=======================================================================
299 //function : ShapeToDouble
300 //purpose : used by CompareShapes::operator()
301 //=======================================================================
302 std::pair<double, double> GEOMUtils::ShapeToDouble (const TopoDS_Shape& S, bool isOldSorting)
304 // Computing of CentreOfMass
308 if (S.ShapeType() == TopAbs_VERTEX) {
309 GPoint = BRep_Tool::Pnt(TopoDS::Vertex(S));
310 Len = (double)S.Orientation();
314 // BEGIN: fix for Mantis issue 0020842
316 BRepGProp::LinearProperties(S, GPr);
319 if (S.ShapeType() == TopAbs_EDGE || S.ShapeType() == TopAbs_WIRE) {
320 BRepGProp::LinearProperties(S, GPr);
322 else if (S.ShapeType() == TopAbs_FACE || S.ShapeType() == TopAbs_SHELL) {
323 BRepGProp::SurfaceProperties(S, GPr);
326 BRepGProp::VolumeProperties(S, GPr);
329 // END: fix for Mantis issue 0020842
330 GPoint = GPr.CentreOfMass();
334 double dMidXYZ = GPoint.X() * 999.0 + GPoint.Y() * 99.0 + GPoint.Z() * 0.9;
335 return std::make_pair(dMidXYZ, Len);
338 //=======================================================================
339 //function : GetPosition
341 //=======================================================================
342 gp_Ax3 GEOMUtils::GetPosition (const TopoDS_Shape& theShape)
346 if (theShape.IsNull())
350 aResult.Transform(theShape.Location().Transformation());
351 if (theShape.ShapeType() == TopAbs_FACE) {
352 Handle(Geom_Surface) aGS = BRep_Tool::Surface(TopoDS::Face(theShape));
353 if (!aGS.IsNull() && aGS->IsKind(STANDARD_TYPE(Geom_Plane))) {
354 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast(aGS);
355 gp_Pln aPln = aGPlane->Pln();
356 aResult = aPln.Position();
357 // In case of reverse orinetation of the face invert the plane normal
358 // (the face's normal does not mathc the plane's normal in this case)
359 if(theShape.Orientation() == TopAbs_REVERSED)
361 gp_Dir Vx = aResult.XDirection();
362 gp_Dir N = aResult.Direction().Mirrored(Vx);
363 gp_Pnt P = aResult.Location();
364 aResult = gp_Ax3(P, N, Vx);
372 TopAbs_ShapeEnum aShType = theShape.ShapeType();
374 if (aShType == TopAbs_VERTEX) {
375 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(theShape));
378 if (aShType == TopAbs_COMPOUND) {
379 aShType = GetTypeOfSimplePart(theShape);
382 GProp_GProps aSystem;
383 if (aShType == TopAbs_EDGE || aShType == TopAbs_WIRE)
384 BRepGProp::LinearProperties(theShape, aSystem);
385 else if (aShType == TopAbs_FACE || aShType == TopAbs_SHELL)
386 BRepGProp::SurfaceProperties(theShape, aSystem);
388 BRepGProp::VolumeProperties(theShape, aSystem);
390 aPnt = aSystem.CentreOfMass();
393 aResult.SetLocation(aPnt);
398 //=======================================================================
399 //function : GetVector
401 //=======================================================================
402 gp_Vec GEOMUtils::GetVector (const TopoDS_Shape& theShape,
403 Standard_Boolean doConsiderOrientation)
405 if (theShape.IsNull())
406 Standard_NullObject::Raise("Null shape is given for a vector");
408 if (theShape.ShapeType() != TopAbs_EDGE)
409 Standard_TypeMismatch::Raise("Invalid shape is given, must be a vector or an edge");
411 TopoDS_Edge anE = TopoDS::Edge(theShape);
413 TopoDS_Vertex V1, V2;
414 TopExp::Vertices(anE, V1, V2, doConsiderOrientation);
416 if (V1.IsNull() || V2.IsNull())
417 Standard_NullObject::Raise("Invalid edge is given, it must have two points");
419 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
420 if (aV.Magnitude() < gp::Resolution()) {
421 Standard_ConstructionError::Raise("Vector of zero length is given");
427 //=======================================================================
428 //function : CompareShapes::operator()
429 //purpose : used by std::sort(), called from SortShapes()
430 //=======================================================================
431 bool GEOMUtils::CompareShapes::operator() (const TopoDS_Shape& theShape1,
432 const TopoDS_Shape& theShape2)
434 if (!myMap.IsBound(theShape1)) {
435 myMap.Bind(theShape1, ShapeToDouble(theShape1, myIsOldSorting));
438 if (!myMap.IsBound(theShape2)) {
439 myMap.Bind(theShape2, ShapeToDouble(theShape2, myIsOldSorting));
442 std::pair<double, double> val1 = myMap.Find(theShape1);
443 std::pair<double, double> val2 = myMap.Find(theShape2);
445 double tol = Precision::Confusion();
446 bool exchange = Standard_False;
448 double dMidXYZ = val1.first - val2.first;
449 if (dMidXYZ >= tol) {
450 exchange = Standard_True;
452 else if (Abs(dMidXYZ) < tol) {
453 double dLength = val1.second - val2.second;
454 if (dLength >= tol) {
455 exchange = Standard_True;
457 else if (Abs(dLength) < tol && theShape1.ShapeType() <= TopAbs_FACE) {
459 // equal values possible on shapes such as two halves of a sphere and
460 // a membrane inside the sphere
462 BRepBndLib::Add(theShape1, box1);
463 if (!box1.IsVoid()) {
464 BRepBndLib::Add(theShape2, box2);
465 Standard_Real dSquareExtent = box1.SquareExtent() - box2.SquareExtent();
466 if (dSquareExtent >= tol) {
467 exchange = Standard_True;
469 else if (Abs(dSquareExtent) < tol) {
470 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax, val1, val2;
471 box1.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
472 val1 = (aXmin+aXmax)*999.0 + (aYmin+aYmax)*99.0 + (aZmin+aZmax)*0.9;
473 box2.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
474 val2 = (aXmin+aXmax)*999.0 + (aYmin+aYmax)*99.0 + (aZmin+aZmax)*0.9;
475 if ((val1 - val2) >= tol) {
476 exchange = Standard_True;
483 //return val1 < val2;
487 //=======================================================================
488 //function : SortShapes
490 //=======================================================================
491 void GEOMUtils::SortShapes (TopTools_ListOfShape& SL,
492 const Standard_Boolean isOldSorting)
495 std::vector<TopoDS_Shape> aShapesVec;
496 aShapesVec.reserve(SL.Extent());
498 TopTools_ListIteratorOfListOfShape it (SL);
499 for (; it.More(); it.Next()) {
500 aShapesVec.push_back(it.Value());
504 CompareShapes shComp (isOldSorting);
505 std::stable_sort(aShapesVec.begin(), aShapesVec.end(), shComp);
506 //std::sort(aShapesVec.begin(), aShapesVec.end(), shComp);
508 std::vector<TopoDS_Shape>::const_iterator anIter = aShapesVec.begin();
509 for (; anIter != aShapesVec.end(); ++anIter) {
513 // old implementation
514 Standard_Integer MaxShapes = SL.Extent();
515 TopTools_Array1OfShape aShapes (1,MaxShapes);
516 TColStd_Array1OfInteger OrderInd(1,MaxShapes);
517 TColStd_Array1OfReal MidXYZ (1,MaxShapes); //X,Y,Z;
518 TColStd_Array1OfReal Length (1,MaxShapes); //X,Y,Z;
520 // Computing of CentreOfMass
521 Standard_Integer Index;
524 TopTools_ListIteratorOfListOfShape it(SL);
525 for (Index=1; it.More(); Index++)
527 TopoDS_Shape S = it.Value();
528 SL.Remove( it ); // == it.Next()
530 OrderInd.SetValue (Index, Index);
531 if (S.ShapeType() == TopAbs_VERTEX) {
532 GPoint = BRep_Tool::Pnt( TopoDS::Vertex( S ));
533 Length.SetValue( Index, (Standard_Real) S.Orientation());
536 // BEGIN: fix for Mantis issue 0020842
538 BRepGProp::LinearProperties (S, GPr);
541 if (S.ShapeType() == TopAbs_EDGE || S.ShapeType() == TopAbs_WIRE) {
542 BRepGProp::LinearProperties (S, GPr);
544 else if (S.ShapeType() == TopAbs_FACE || S.ShapeType() == TopAbs_SHELL) {
545 BRepGProp::SurfaceProperties(S, GPr);
548 BRepGProp::VolumeProperties(S, GPr);
551 // END: fix for Mantis issue 0020842
552 GPoint = GPr.CentreOfMass();
553 Length.SetValue(Index, GPr.Mass());
555 MidXYZ.SetValue(Index, GPoint.X()*999.0 + GPoint.Y()*99.0 + GPoint.Z()*0.9);
556 //cout << Index << " L: " << Length(Index) << "CG: " << MidXYZ(Index) << endl;
560 Standard_Integer aTemp;
561 Standard_Boolean exchange, Sort = Standard_True;
562 Standard_Real tol = Precision::Confusion();
565 Sort = Standard_False;
566 for (Index=1; Index < MaxShapes; Index++)
568 exchange = Standard_False;
569 Standard_Real dMidXYZ = MidXYZ(OrderInd(Index)) - MidXYZ(OrderInd(Index+1));
570 Standard_Real dLength = Length(OrderInd(Index)) - Length(OrderInd(Index+1));
571 if ( dMidXYZ >= tol ) {
572 // cout << "MidXYZ: " << MidXYZ(OrderInd(Index))<< " > " <<MidXYZ(OrderInd(Index+1))
573 // << " d: " << dMidXYZ << endl;
574 exchange = Standard_True;
576 else if ( Abs(dMidXYZ) < tol && dLength >= tol ) {
577 // cout << "Length: " << Length(OrderInd(Index))<< " > " <<Length(OrderInd(Index+1))
578 // << " d: " << dLength << endl;
579 exchange = Standard_True;
581 else if ( Abs(dMidXYZ) < tol && Abs(dLength) < tol &&
582 aShapes(OrderInd(Index)).ShapeType() <= TopAbs_FACE) {
584 // equal values possible on shapes such as two halves of a sphere and
585 // a membrane inside the sphere
587 BRepBndLib::Add( aShapes( OrderInd(Index) ), box1 );
588 if ( box1.IsVoid() ) continue;
589 BRepBndLib::Add( aShapes( OrderInd(Index+1) ), box2 );
590 Standard_Real dSquareExtent = box1.SquareExtent() - box2.SquareExtent();
591 if ( dSquareExtent >= tol ) {
592 // cout << "SquareExtent: " << box1.SquareExtent()<<" > "<<box2.SquareExtent() << endl;
593 exchange = Standard_True;
595 else if ( Abs(dSquareExtent) < tol ) {
596 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax, val1, val2;
597 box1.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
598 val1 = (aXmin+aXmax)*999 + (aYmin+aYmax)*99 + (aZmin+aZmax)*0.9;
599 box2.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
600 val2 = (aXmin+aXmax)*999 + (aYmin+aYmax)*99 + (aZmin+aZmax)*0.9;
601 //exchange = val1 > val2;
602 if ((val1 - val2) >= tol) {
603 exchange = Standard_True;
605 //cout << "box: " << val1<<" > "<<val2 << endl;
611 // cout << "exchange " << Index << " & " << Index+1 << endl;
612 aTemp = OrderInd(Index);
613 OrderInd(Index) = OrderInd(Index+1);
614 OrderInd(Index+1) = aTemp;
615 Sort = Standard_True;
620 for (Index=1; Index <= MaxShapes; Index++)
621 SL.Append( aShapes( OrderInd(Index) ));
625 //=======================================================================
626 //function : CompsolidToCompound
628 //=======================================================================
629 TopoDS_Shape GEOMUtils::CompsolidToCompound (const TopoDS_Shape& theCompsolid)
631 if (theCompsolid.ShapeType() != TopAbs_COMPSOLID) {
635 TopoDS_Compound aCompound;
637 B.MakeCompound(aCompound);
639 TopTools_MapOfShape mapShape;
640 TopoDS_Iterator It (theCompsolid, Standard_True, Standard_True);
642 for (; It.More(); It.Next()) {
643 TopoDS_Shape aShape_i = It.Value();
644 if (mapShape.Add(aShape_i)) {
645 B.Add(aCompound, aShape_i);
652 //=======================================================================
653 //function : AddSimpleShapes
655 //=======================================================================
656 void GEOMUtils::AddSimpleShapes (const TopoDS_Shape& theShape, TopTools_ListOfShape& theList)
658 if (theShape.ShapeType() != TopAbs_COMPOUND &&
659 theShape.ShapeType() != TopAbs_COMPSOLID) {
660 theList.Append(theShape);
664 TopTools_MapOfShape mapShape;
665 TopoDS_Iterator It (theShape, Standard_True, Standard_True);
667 for (; It.More(); It.Next()) {
668 TopoDS_Shape aShape_i = It.Value();
669 if (mapShape.Add(aShape_i)) {
670 if (aShape_i.ShapeType() == TopAbs_COMPOUND ||
671 aShape_i.ShapeType() == TopAbs_COMPSOLID) {
672 AddSimpleShapes(aShape_i, theList);
674 theList.Append(aShape_i);
680 //=======================================================================
681 //function : CheckTriangulation
683 //=======================================================================
684 bool GEOMUtils::CheckTriangulation (const TopoDS_Shape& aShape)
686 bool isTriangulation = true;
688 TopExp_Explorer exp (aShape, TopAbs_FACE);
691 TopLoc_Location aTopLoc;
692 Handle(Poly_Triangulation) aTRF;
693 aTRF = BRep_Tool::Triangulation(TopoDS::Face(exp.Current()), aTopLoc);
695 isTriangulation = false;
698 else // no faces, try edges
700 TopExp_Explorer expe (aShape, TopAbs_EDGE);
704 TopLoc_Location aLoc;
705 Handle(Poly_Polygon3D) aPE = BRep_Tool::Polygon3D(TopoDS::Edge(expe.Current()), aLoc);
707 isTriangulation = false;
711 if (!isTriangulation) {
712 // calculate deflection
713 Standard_Real aDeviationCoefficient = 0.001;
716 BRepBndLib::Add(aShape, B);
717 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
718 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
720 Standard_Real dx = aXmax - aXmin, dy = aYmax - aYmin, dz = aZmax - aZmin;
721 Standard_Real aDeflection = Max(Max(dx, dy), dz) * aDeviationCoefficient * 4;
722 Standard_Real aHLRAngle = 0.349066;
724 BRepMesh_IncrementalMesh Inc (aShape, aDeflection, Standard_False, aHLRAngle);
730 //=======================================================================
731 //function : GetTypeOfSimplePart
733 //=======================================================================
734 TopAbs_ShapeEnum GEOMUtils::GetTypeOfSimplePart (const TopoDS_Shape& theShape)
736 TopAbs_ShapeEnum aType = theShape.ShapeType();
737 if (aType == TopAbs_VERTEX) return TopAbs_VERTEX;
738 else if (aType == TopAbs_EDGE || aType == TopAbs_WIRE) return TopAbs_EDGE;
739 else if (aType == TopAbs_FACE || aType == TopAbs_SHELL) return TopAbs_FACE;
740 else if (aType == TopAbs_SOLID || aType == TopAbs_COMPSOLID) return TopAbs_SOLID;
741 else if (aType == TopAbs_COMPOUND) {
742 // Only the iType of the first shape in the compound is taken into account
743 TopoDS_Iterator It (theShape, Standard_False, Standard_False);
745 return GetTypeOfSimplePart(It.Value());
751 //=======================================================================
752 //function : GetEdgeNearPoint
754 //=======================================================================
755 TopoDS_Shape GEOMUtils::GetEdgeNearPoint (const TopoDS_Shape& theShape,
756 const TopoDS_Vertex& thePoint)
758 TopoDS_Shape aResult;
760 // 1. Explode the shape on edges
761 TopTools_MapOfShape mapShape;
762 Standard_Integer nbEdges = 0;
763 TopExp_Explorer exp (theShape, TopAbs_EDGE);
764 for (; exp.More(); exp.Next()) {
765 if (mapShape.Add(exp.Current())) {
771 Standard_NullObject::Raise("Given shape contains no edges");
774 Standard_Integer ind = 1;
775 TopTools_Array1OfShape anEdges (1, nbEdges);
776 TColStd_Array1OfReal aDistances (1, nbEdges);
777 for (exp.Init(theShape, TopAbs_EDGE); exp.More(); exp.Next()) {
778 if (mapShape.Add(exp.Current())) {
779 TopoDS_Shape anEdge = exp.Current();
780 anEdges(ind) = anEdge;
782 // 2. Classify the point relatively each edge
783 BRepExtrema_DistShapeShape aDistTool (thePoint, anEdges(ind));
784 if (!aDistTool.IsDone())
785 Standard_ConstructionError::Raise("Cannot find a distance from the given point to one of edges");
787 aDistances(ind) = aDistTool.Value();
792 // 3. Define edge, having minimum distance to the point
793 Standard_Real nearest = RealLast(), nbFound = 0;
794 Standard_Real prec = Precision::Confusion();
795 for (ind = 1; ind <= nbEdges; ind++) {
796 if (Abs(aDistances(ind) - nearest) < prec) {
799 else if (aDistances(ind) < nearest) {
800 nearest = aDistances(ind);
801 aResult = anEdges(ind);
808 Standard_ConstructionError::Raise("Multiple edges near the given point are found");
810 else if (nbFound == 0) {
811 Standard_ConstructionError::Raise("There are no edges near the given point");
819 //=======================================================================
820 //function : PreciseBoundingBox
822 //=======================================================================
823 Standard_Boolean GEOMUtils::PreciseBoundingBox
824 (const TopoDS_Shape &theShape, Bnd_Box &theBox)
826 if ( theBox.IsVoid() ) BRepBndLib::Add( theShape, theBox );
827 if ( theBox.IsVoid() ) return Standard_False;
829 Standard_Real aBound[6];
830 theBox.Get(aBound[0], aBound[2], aBound[4], aBound[1], aBound[3], aBound[5]);
833 const gp_Pnt aMid(0.5*(aBound[1] + aBound[0]), // XMid
834 0.5*(aBound[3] + aBound[2]), // YMid
835 0.5*(aBound[5] + aBound[4])); // ZMid
836 const gp_XYZ aSize(aBound[1] - aBound[0], // DX
837 aBound[3] - aBound[2], // DY
838 aBound[5] - aBound[4]); // DZ
839 const gp_Pnt aPnt[6] =
841 gp_Pnt(aBound[0] - (aBound[1] - aBound[0]), aMid.Y(), aMid.Z()), // XMin
842 gp_Pnt(aBound[1] + (aBound[1] - aBound[0]), aMid.Y(), aMid.Z()), // XMax
843 gp_Pnt(aMid.X(), aBound[2] - (aBound[3] - aBound[2]), aMid.Z()), // YMin
844 gp_Pnt(aMid.X(), aBound[3] + (aBound[3] - aBound[2]), aMid.Z()), // YMax
845 gp_Pnt(aMid.X(), aMid.Y(), aBound[4] - (aBound[5] - aBound[4])), // ZMin
846 gp_Pnt(aMid.X(), aMid.Y(), aBound[5] + (aBound[5] - aBound[4])) // ZMax
848 const gp_Dir aDir[3] = { gp::DX(), gp::DY(), gp::DZ() };
849 const Standard_Real aPlnSize[3] =
851 0.5*Max(aSize.Y(), aSize.Z()), // XMin, XMax planes
852 0.5*Max(aSize.X(), aSize.Z()), // YMin, YMax planes
853 0.5*Max(aSize.X(), aSize.Y()) // ZMin, ZMax planes
857 for (i = 0; i < 6; i++) {
858 const Standard_Integer iHalf = i/2;
859 const gp_Pln aPln(aPnt[i], aDir[iHalf]);
860 BRepBuilderAPI_MakeFace aMkFace(aPln, -aPlnSize[iHalf], aPlnSize[iHalf],
861 -aPlnSize[iHalf], aPlnSize[iHalf]);
863 if (!aMkFace.IsDone()) {
864 return Standard_False;
867 TopoDS_Shape aFace = aMkFace.Shape();
869 // Get minimal distance between planar face and shape.
870 Standard_Real aMinDist =
871 GEOMUtils::GetMinDistance(aFace, theShape, aPMin[0], aPMin[1]);
874 return Standard_False;
877 aBound[i] = aPMin[1].Coord(iHalf + 1);
880 // Update Bounding box with the new values.
882 theBox.Update(aBound[0], aBound[2], aBound[4], aBound[1], aBound[3], aBound[5]);
884 return Standard_True;
887 //=======================================================================
888 //function : GetMinDistanceSingular
890 //=======================================================================
891 double GEOMUtils::GetMinDistanceSingular(const TopoDS_Shape& aSh1,
892 const TopoDS_Shape& aSh2,
893 gp_Pnt& Ptmp1, gp_Pnt& Ptmp2)
897 Standard_Real AddDist1 = 0.;
898 Standard_Real AddDist2 = 0.;
899 Standard_Boolean IsChange1 = ModifyShape(aSh1, tmpSh1, AddDist1);
900 Standard_Boolean IsChange2 = ModifyShape(aSh2, tmpSh2, AddDist2);
902 if( !IsChange1 && !IsChange2 )
905 BRepExtrema_DistShapeShape dst(tmpSh1,tmpSh2);
907 double MinDist = 1.e9;
908 gp_Pnt PMin1, PMin2, P1, P2;
909 for (int i = 1; i <= dst.NbSolution(); i++) {
910 P1 = dst.PointOnShape1(i);
911 P2 = dst.PointOnShape2(i);
912 Standard_Real Dist = P1.Distance(P2);
913 if (MinDist > Dist) {
924 gp_Dir aDir(gp_Vec(PMin1,PMin2));
925 if( MinDist > (AddDist1+AddDist2) ) {
926 Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
927 PMin1.Y() + aDir.Y()*AddDist1,
928 PMin1.Z() + aDir.Z()*AddDist1 );
929 Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
930 PMin2.Y() - aDir.Y()*AddDist2,
931 PMin2.Z() - aDir.Z()*AddDist2 );
932 return (MinDist - AddDist1 - AddDist2);
936 Ptmp1 = gp_Pnt( PMin1.X() + aDir.X()*AddDist1,
937 PMin1.Y() + aDir.Y()*AddDist1,
938 PMin1.Z() + aDir.Z()*AddDist1 );
942 Ptmp2 = gp_Pnt( PMin2.X() - aDir.X()*AddDist2,
943 PMin2.Y() - aDir.Y()*AddDist2,
944 PMin2.Z() - aDir.Z()*AddDist2 );
949 double res = MinDist - AddDist1 - AddDist2;
950 if(res<0.) res = 0.0;
956 //=======================================================================
957 //function : GetMinDistance
959 //=======================================================================
960 Standard_Real GEOMUtils::GetMinDistance
961 (const TopoDS_Shape& theShape1,
962 const TopoDS_Shape& theShape2,
963 gp_Pnt& thePnt1, gp_Pnt& thePnt2)
965 Standard_Real aResult = 1.e9;
967 // Issue 0020231: A min distance bug with torus and vertex.
968 // Make GetMinDistance() return zero if a sole VERTEX is inside any of SOLIDs
970 // which of shapes consists of only one vertex?
971 TopExp_Explorer exp1(theShape1,TopAbs_VERTEX), exp2(theShape2,TopAbs_VERTEX);
972 TopoDS_Shape V1 = exp1.More() ? exp1.Current() : TopoDS_Shape();
973 TopoDS_Shape V2 = exp2.More() ? exp2.Current() : TopoDS_Shape();
974 exp1.Next(); exp2.Next();
975 if ( exp1.More() ) V1.Nullify();
976 if ( exp2.More() ) V2.Nullify();
977 // vertex and container of solids
978 TopoDS_Shape V = V1.IsNull() ? V2 : V1;
979 TopoDS_Shape S = V1.IsNull() ? theShape1 : theShape2;
981 // classify vertex against solids
982 gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( V ) );
983 for ( exp1.Init( S, TopAbs_SOLID ); exp1.More(); exp1.Next() ) {
984 BRepClass3d_SolidClassifier classifier( exp1.Current(), p, 1e-6);
985 if ( classifier.State() == TopAbs_IN ) {
995 // additional workaround for bugs 19899, 19908 and 19910 from Mantis
996 #if OCC_VERSION_LARGE < 0x07070000
997 aResult = GEOMUtils::GetMinDistanceSingular(theShape1, theShape2, thePnt1, thePnt2);
1006 BRepExtrema_DistShapeShape dst (theShape1, theShape2);
1010 for (int i = 1; i <= dst.NbSolution(); i++) {
1011 P1 = dst.PointOnShape1(i);
1012 P2 = dst.PointOnShape2(i);
1014 Standard_Real Dist = P1.Distance(P2);
1015 if (aResult < 0 || aResult > Dist) {
1026 //=======================================================================
1027 // function : ProjectPointOnFace()
1028 // purpose : Returns the projection (3d point) if found, throws an exception otherwise
1029 //=======================================================================
1030 gp_Pnt GEOMUtils::ProjectPointOnFace(const gp_Pnt& thePoint,
1031 const TopoDS_Shape& theFace,
1032 double& theU, double& theV,
1033 const double theTol)
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 GeomAPI_ProjectPointOnSurf proj;
1046 proj.Init(surface, U1, U2, V1, V2);
1047 proj.Perform(thePoint);
1049 StdFail_NotDone::Raise("Projection aborted : the algorithm failed");
1050 int nbPoints = proj.NbPoints();
1052 Standard_ConstructionError::Raise("Projection aborted : No solution found");
1053 proj.LowerDistanceParameters(theU, theV);
1054 gp_Pnt2d aProjPnt (theU, theV);
1057 Standard_Real tol = Max(theTol, 1.e-4);
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 Standard_Real 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;