1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_ShapeTools.h
4 // Created: 3 August 2015
5 // Author: Dmitry Bobylev
7 #include "GeomAlgoAPI_ShapeTools.h"
9 #include "GeomAlgoAPI_SketchBuilder.h"
11 #include <GeomAPI_Dir.h>
12 #include <GeomAPI_PlanarEdges.h>
13 #include <GeomAPI_Pln.h>
14 #include <GeomAPI_Pnt.h>
16 #include <Bnd_Box.hxx>
17 #include <BOPTools.hxx>
18 #include <BRep_Builder.hxx>
19 #include <BRepAdaptor_Curve.hxx>
20 #include <BRepAlgo_FaceRestrictor.hxx>
21 #include <BRepBndLib.hxx>
22 #include <BRepBuilderAPI_FindPlane.hxx>
23 #include <BRepBuilderAPI_MakeEdge.hxx>
24 #include <BRepBuilderAPI_MakeFace.hxx>
25 #include <BRepCheck_Analyzer.hxx>
26 #include <BRepExtrema_DistShapeShape.hxx>
27 #include <BRepGProp.hxx>
28 #include <BRepTopAdaptor_FClass2d.hxx>
29 #include <Geom_Curve.hxx>
30 #include <Geom2d_Curve.hxx>
31 #include <BRepLib_CheckCurveOnSurface.hxx>
32 #include <BRep_Tool.hxx>
33 #include <Geom_Plane.hxx>
34 #include <GeomLib_IsPlanarSurface.hxx>
35 #include <GeomLib_Tool.hxx>
36 #include <GeomProjLib.hxx>
38 #include <GProp_GProps.hxx>
39 #include <IntAna_IntConicQuad.hxx>
40 #include <IntAna_Quadric.hxx>
41 #include <NCollection_Vector.hxx>
42 #include <ShapeAnalysis.hxx>
43 #include <ShapeAnalysis_Surface.hxx>
44 #include <TopoDS_Builder.hxx>
45 #include <TopoDS_Edge.hxx>
46 #include <TopoDS_Face.hxx>
47 #include <TopoDS_Shape.hxx>
48 #include <TopoDS_Shell.hxx>
49 #include <TopoDS_Vertex.hxx>
51 #include <TopExp_Explorer.hxx>
53 //==================================================================================================
54 double GeomAlgoAPI_ShapeTools::volume(const std::shared_ptr<GeomAPI_Shape> theShape)
60 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
64 const Standard_Real anEps = 1.e-6;
65 BRepGProp::VolumeProperties(aShape, aGProps, anEps);
66 return aGProps.Mass();
69 //==================================================================================================
70 std::shared_ptr<GeomAPI_Pnt> GeomAlgoAPI_ShapeTools::centreOfMass(const std::shared_ptr<GeomAPI_Shape> theShape)
74 return std::shared_ptr<GeomAPI_Pnt>();
76 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
78 return std::shared_ptr<GeomAPI_Pnt>();
81 if(aShape.ShapeType() == TopAbs_VERTEX) {
82 aCentre = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
83 } else if(aShape.ShapeType() == TopAbs_EDGE || aShape.ShapeType() == TopAbs_WIRE) {
84 BRepGProp::LinearProperties(aShape, aGProps);
85 aCentre = aGProps.CentreOfMass();
87 BRepGProp::SurfaceProperties(aShape, aGProps);
88 aCentre = aGProps.CentreOfMass();
90 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aCentre.X(), aCentre.Y(), aCentre.Z()));
93 //==================================================================================================
94 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::combineShapes(const std::shared_ptr<GeomAPI_Shape> theCompound,
95 const GeomAPI_Shape::ShapeType theType,
96 ListOfShape& theCombinedShapes,
97 ListOfShape& theFreeShapes)
99 GeomShapePtr aResult = theCompound;
101 if(!theCompound.get()) {
105 if(theType != GeomAPI_Shape::SHELL && theType != GeomAPI_Shape::COMPSOLID) {
109 TopAbs_ShapeEnum aTS = TopAbs_EDGE;
110 TopAbs_ShapeEnum aTA = TopAbs_FACE;
111 if(theType == GeomAPI_Shape::COMPSOLID) {
116 theCombinedShapes.clear();
117 theFreeShapes.clear();
120 const TopoDS_Shape& aShapesComp = theCompound->impl<TopoDS_Shape>();
121 for(TopoDS_Iterator anIter(aShapesComp); anIter.More(); anIter.Next() ) {
122 const TopoDS_Shape& aShape = anIter.Value();
123 if(aShape.ShapeType() > aTA) {
124 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
125 aGeomShape->setImpl<TopoDS_Shape>(new TopoDS_Shape(aShape));
126 theFreeShapes.push_back(aGeomShape);
130 // Map subshapes and shapes.
131 BOPCol_IndexedDataMapOfShapeListOfShape aMapSA;
132 BOPTools::MapShapesAndAncestors(aShapesComp, aTS, aTA, aMapSA);
133 if(aMapSA.IsEmpty()) {
137 // Get all shapes with common subshapes and free shapes.
138 NCollection_Map<TopoDS_Shape> aFreeShapes;
139 NCollection_Vector<NCollection_Map<TopoDS_Shape>> aShapesWithCommonSubshapes;
140 for(BOPCol_IndexedDataMapOfShapeListOfShape::Iterator anIter(aMapSA); anIter.More(); anIter.Next()) {
141 const TopoDS_Shape& aShape = anIter.Key();
142 BOPCol_ListOfShape& aListOfShape = anIter.ChangeValue();
143 if(aListOfShape.IsEmpty()) {
146 else if(aListOfShape.Size() == 1) {
147 const TopoDS_Shape& aF = aListOfShape.First();
149 aListOfShape.Clear();
151 NCollection_List<TopoDS_Shape> aTempList;
152 NCollection_Map<TopoDS_Shape> aTempMap;
153 const TopoDS_Shape& aF = aListOfShape.First();
154 const TopoDS_Shape& aL = aListOfShape.Last();
155 aTempList.Append(aF);
156 aTempList.Append(aL);
159 aFreeShapes.Remove(aF);
160 aFreeShapes.Remove(aL);
161 aListOfShape.Clear();
162 for(NCollection_List<TopoDS_Shape>::Iterator aTempIter(aTempList); aTempIter.More(); aTempIter.Next()) {
163 const TopoDS_Shape& aTempShape = aTempIter.Value();
164 for(BOPCol_IndexedDataMapOfShapeListOfShape::Iterator anIter(aMapSA); anIter.More(); anIter.Next()) {
165 BOPCol_ListOfShape& aTempListOfShape = anIter.ChangeValue();
166 if(aTempListOfShape.IsEmpty()) {
168 } else if(aTempListOfShape.Size() == 1 && aTempListOfShape.First() == aTempShape) {
169 aTempListOfShape.Clear();
170 } else if(aTempListOfShape.Size() > 1) {
171 if(aTempListOfShape.First() == aTempShape) {
172 const TopoDS_Shape& aTL = aTempListOfShape.Last();
173 if(aTempMap.Add(aTL)) {
174 aTempList.Append(aTL);
175 aFreeShapes.Remove(aTL);
177 aTempListOfShape.Clear();
178 } else if(aTempListOfShape.Last() == aTempShape) {
179 const TopoDS_Shape& aTF = aTempListOfShape.First();
180 if(aTempMap.Add(aTF)) {
181 aTempList.Append(aTF);
182 aFreeShapes.Remove(aTF);
184 aTempListOfShape.Clear();
189 aShapesWithCommonSubshapes.Append(aTempMap);
193 // Combine shapes with common subshapes.
194 for(NCollection_Vector<NCollection_Map<TopoDS_Shape>>::Iterator anIter(aShapesWithCommonSubshapes); anIter.More(); anIter.Next()) {
196 TopoDS_CompSolid aCSolid;
197 TopoDS_Builder aBuilder;
198 theType == GeomAPI_Shape::COMPSOLID ? aBuilder.MakeCompSolid(aCSolid) : aBuilder.MakeShell(aShell);
199 NCollection_Map<TopoDS_Shape>& aShapesMap = anIter.ChangeValue();
200 for(TopExp_Explorer anExp(aShapesComp, aTA); anExp.More(); anExp.Next()) {
201 const TopoDS_Shape& aShape = anExp.Current();
202 if(aShapesMap.Contains(aShape)) {
203 theType == GeomAPI_Shape::COMPSOLID ? aBuilder.Add(aCSolid, aShape) : aBuilder.Add(aShell, aShape);
204 aShapesMap.Remove(aShape);
207 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
208 TopoDS_Shape* aSh = theType == GeomAPI_Shape::COMPSOLID ? new TopoDS_Shape(aCSolid) : new TopoDS_Shape(aShell);
209 aGeomShape->setImpl<TopoDS_Shape>(aSh);
210 theCombinedShapes.push_back(aGeomShape);
213 // Adding free shapes.
214 for(TopExp_Explorer anExp(aShapesComp, aTA); anExp.More(); anExp.Next()) {
215 const TopoDS_Shape& aShape = anExp.Current();
216 if(aFreeShapes.Contains(aShape)) {
217 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
218 aGeomShape->setImpl<TopoDS_Shape>(new TopoDS_Shape(aShape));
219 theFreeShapes.push_back(aGeomShape);
223 if(theCombinedShapes.size() == 1 && theFreeShapes.size() == 0) {
224 aResult = theCombinedShapes.front();
225 } else if (theCombinedShapes.size() > 1 || (theCombinedShapes.size() >= 1 && theFreeShapes.size() >= 1)) {
226 TopoDS_Compound aResultComp;
227 TopoDS_Builder aBuilder;
228 aBuilder.MakeCompound(aResultComp);
229 for(ListOfShape::const_iterator anIter = theCombinedShapes.cbegin(); anIter != theCombinedShapes.cend(); anIter++) {
230 aBuilder.Add(aResultComp, (*anIter)->impl<TopoDS_Shape>());
232 for(ListOfShape::const_iterator anIter = theFreeShapes.cbegin(); anIter != theFreeShapes.cend(); anIter++) {
233 aBuilder.Add(aResultComp, (*anIter)->impl<TopoDS_Shape>());
235 aResult->setImpl(new TopoDS_Shape(aResultComp));
241 //==================================================================================================
242 static void addSimpleShapeToList(const TopoDS_Shape& theShape, NCollection_List<TopoDS_Shape>& theList)
244 if(theShape.IsNull()) {
248 if(theShape.ShapeType() == TopAbs_COMPOUND) {
249 for(TopoDS_Iterator anIt(theShape); anIt.More(); anIt.Next()) {
250 addSimpleShapeToList(anIt.Value(), theList);
253 theList.Append(theShape);
257 //==================================================================================================
258 static TopoDS_Compound makeCompound(const NCollection_List<TopoDS_Shape> theShapes)
260 TopoDS_Compound aCompound;
262 BRep_Builder aBuilder;
263 aBuilder.MakeCompound(aCompound);
265 for(NCollection_List<TopoDS_Shape>::Iterator anIt(theShapes); anIt.More(); anIt.Next()) {
266 aBuilder.Add(aCompound, anIt.Value());
272 //==================================================================================================
273 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::groupSharedTopology(const std::shared_ptr<GeomAPI_Shape> theCompound)
275 GeomShapePtr aResult = theCompound;
277 if(!theCompound.get()) {
281 TopoDS_Shape anInShape = aResult->impl<TopoDS_Shape>();
282 NCollection_List<TopoDS_Shape> anUngroupedShapes;
283 addSimpleShapeToList(anInShape, anUngroupedShapes);
285 NCollection_Vector<NCollection_List<TopoDS_Shape>> aGroups;
286 while(!anUngroupedShapes.IsEmpty()) {
287 NCollection_List<TopoDS_Shape> aGroupedShapes;
288 aGroupedShapes.Append(anUngroupedShapes.First());
289 anUngroupedShapes.RemoveFirst();
290 for(NCollection_List<TopoDS_Shape>::Iterator aGroupIt(aGroupedShapes); aGroupIt.More(); aGroupIt.Next()) {
291 const TopoDS_Shape& aGroupShape = aGroupIt.Value();
292 for(NCollection_List<TopoDS_Shape>::Iterator anUngroupedIt(anUngroupedShapes); anUngroupedIt.More(); anUngroupedIt.Next()) {
293 const TopoDS_Shape& anUngroupedShape = anUngroupedIt.Value();
294 bool isFound = false;
295 for(TopExp_Explorer aGroupShapeExp(aGroupShape, TopAbs_VERTEX); aGroupShapeExp.More(); aGroupShapeExp.Next()) {
296 const TopoDS_Shape& aVertex1 = aGroupShapeExp.Current();
297 for(TopExp_Explorer anUngroupedShapeExp(anUngroupedShape, TopAbs_VERTEX); anUngroupedShapeExp.More(); anUngroupedShapeExp.Next()) {
298 const TopoDS_Shape& aVertex2 = anUngroupedShapeExp.Current();
299 if(aVertex1.IsSame(aVertex2)) {
300 aGroupedShapes.Append(anUngroupedShape);
301 anUngroupedShapes.Remove(anUngroupedIt);
310 if(!anUngroupedIt.More()) {
315 aGroups.Append(aGroupedShapes);
318 TopoDS_Compound aCompound;
319 BRep_Builder aBuilder;
320 aBuilder.MakeCompound(aCompound);
321 ListOfShape aCompSolids, aFreeSolids;
322 for(NCollection_Vector<NCollection_List<TopoDS_Shape>>::Iterator anIt(aGroups); anIt.More(); anIt.Next()) {
323 TopoDS_Compound aGroupCompound = makeCompound(anIt.Value());
324 GeomShapePtr aGeomShape(new GeomAPI_Shape());
325 aGeomShape->setImpl(new TopoDS_Shape(aGroupCompound));
326 aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape,
327 GeomAPI_Shape::COMPSOLID,
330 aBuilder.Add(aCompound, aGeomShape->impl<TopoDS_Shape>());
333 if(!aCompound.IsNull()) {
334 aResult->setImpl(new TopoDS_Shape(aCompound));
340 //==================================================================================================
341 std::list<std::shared_ptr<GeomAPI_Pnt> > GeomAlgoAPI_ShapeTools::getBoundingBox(const ListOfShape& theShapes, const double theEnlarge)
343 // Bounding box of all objects.
347 for (ListOfShape::const_iterator anObjectsIt = theShapes.begin(); anObjectsIt != theShapes.end(); anObjectsIt++) {
348 const TopoDS_Shape& aShape = (*anObjectsIt)->impl<TopoDS_Shape>();
349 BRepBndLib::Add(aShape, aBndBox);
352 if(theEnlarge != 0.0) {
353 // We enlarge bounding box just to be sure that plane will be large enough to cut all objects.
354 aBndBox.Enlarge(theEnlarge);
357 Standard_Real aXArr[2] = {aBndBox.CornerMin().X(), aBndBox.CornerMax().X()};
358 Standard_Real aYArr[2] = {aBndBox.CornerMin().Y(), aBndBox.CornerMax().Y()};
359 Standard_Real aZArr[2] = {aBndBox.CornerMin().Z(), aBndBox.CornerMax().Z()};
360 std::list<std::shared_ptr<GeomAPI_Pnt> > aResultPoints;
362 for(int i = 0; i < 2; i++) {
363 for(int j = 0; j < 2; j++) {
364 for(int k = 0; k < 2; k++) {
365 std::shared_ptr<GeomAPI_Pnt> aPnt(new GeomAPI_Pnt(aXArr[i], aYArr[j], aZArr[k]));
366 aResultPoints.push_back(aPnt);
371 return aResultPoints;
374 //==================================================================================================
375 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::faceToInfinitePlane(const std::shared_ptr<GeomAPI_Shape> theFace)
378 return std::shared_ptr<GeomAPI_Shape>();
380 TopoDS_Face aPlaneFace = TopoDS::Face(theFace->impl<TopoDS_Shape>());
381 if (aPlaneFace.IsNull())
382 return std::shared_ptr<GeomAPI_Shape>();
384 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(aPlaneFace));
386 return std::shared_ptr<GeomAPI_Shape>();
388 // make an infinity face on the plane
389 TopoDS_Shape anInfiniteFace = BRepBuilderAPI_MakeFace(aPlane->Pln()).Shape();
391 std::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape);
392 aResult->setImpl(new TopoDS_Shape(anInfiniteFace));
396 //==================================================================================================
397 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::fitPlaneToBox(const std::shared_ptr<GeomAPI_Shape> thePlane,
398 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints)
400 std::shared_ptr<GeomAPI_Shape> aResultShape;
402 if(!thePlane.get()) {
406 const TopoDS_Shape& aShape = thePlane->impl<TopoDS_Shape>();
407 if(aShape.ShapeType() != TopAbs_FACE) {
411 TopoDS_Face aFace = TopoDS::Face(aShape);
412 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
417 GeomLib_IsPlanarSurface isPlanar(aSurf);
418 if(!isPlanar.IsPlanar()) {
422 if(thePoints.size() != 8) {
426 const gp_Pln& aFacePln = isPlanar.Plan();
427 Handle(Geom_Plane) aFacePlane = new Geom_Plane(aFacePln);
428 IntAna_Quadric aQuadric(aFacePln);
429 Standard_Real UMin, UMax, VMin, VMax;
430 UMin = UMax = VMin = VMax = 0;
431 for (std::list<std::shared_ptr<GeomAPI_Pnt> >::const_iterator aPointsIt = thePoints.begin(); aPointsIt != thePoints.end(); aPointsIt++) {
432 const gp_Pnt& aPnt = (*aPointsIt)->impl<gp_Pnt>();
433 gp_Lin aLin(aPnt, aFacePln.Axis().Direction());
434 IntAna_IntConicQuad anIntAna(aLin, aQuadric);
435 const gp_Pnt& aPntOnFace = anIntAna.Point(1);
436 Standard_Real aPntU(0), aPntV(0);
437 GeomLib_Tool::Parameters(aFacePlane, aPntOnFace, Precision::Confusion(), aPntU, aPntV);
438 if(aPntU < UMin) UMin = aPntU;
439 if(aPntU > UMax) UMax = aPntU;
440 if(aPntV < VMin) VMin = aPntV;
441 if(aPntV > VMax) VMax = aPntV;
443 aResultShape.reset(new GeomAPI_Shape);
444 aResultShape->setImpl(new TopoDS_Shape(BRepLib_MakeFace(aFacePln, UMin, UMax, VMin, VMax).Face()));
449 //==================================================================================================
450 void GeomAlgoAPI_ShapeTools::findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
451 std::shared_ptr<GeomAPI_Vertex>& theV1,
452 std::shared_ptr<GeomAPI_Vertex>& theV2)
454 if(!theShape.get()) {
455 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex);
456 aVertex->setImpl(new TopoDS_Vertex());
462 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
463 TopoDS_Vertex aV1, aV2;
464 ShapeAnalysis::FindBounds(aShape, aV1, aV2);
466 std::shared_ptr<GeomAPI_Vertex> aGeomV1(new GeomAPI_Vertex()), aGeomV2(new GeomAPI_Vertex());
467 aGeomV1->setImpl(new TopoDS_Vertex(aV1));
468 aGeomV2->setImpl(new TopoDS_Vertex(aV2));
473 //==================================================================================================
474 void GeomAlgoAPI_ShapeTools::makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
475 const std::shared_ptr<GeomAPI_Dir> theDirection,
476 const ListOfShape& theWires,
477 ListOfShape& theFaces)
479 BRepBuilderAPI_MakeFace aMKFace(gp_Pln(theOrigin->impl<gp_Pnt>(),
480 theDirection->impl<gp_Dir>()));
481 TopoDS_Face aFace = aMKFace.Face();
483 BRepAlgo_FaceRestrictor aFRestrictor;
484 aFRestrictor.Init(aFace, Standard_False, Standard_True);
485 for(ListOfShape::const_iterator anIt = theWires.cbegin();
486 anIt != theWires.cend();
488 TopoDS_Wire aWire = TopoDS::Wire((*anIt)->impl<TopoDS_Shape>());
489 aFRestrictor.Add(aWire);
492 aFRestrictor.Perform();
494 if(!aFRestrictor.IsDone()) {
498 for(; aFRestrictor.More(); aFRestrictor.Next()) {
499 GeomShapePtr aShape(new GeomAPI_Shape());
500 aShape->setImpl(new TopoDS_Shape(aFRestrictor.Current()));
501 theFaces.push_back(aShape);
505 //==================================================================================================
506 std::shared_ptr<GeomAPI_Pln> GeomAlgoAPI_ShapeTools::findPlane(const ListOfShape& theShapes)
508 TopoDS_Compound aCompound;
509 BRep_Builder aBuilder;
510 aBuilder.MakeCompound(aCompound);
512 for(ListOfShape::const_iterator anIt = theShapes.cbegin(); anIt != theShapes.cend(); ++anIt) {
513 aBuilder.Add(aCompound, (*anIt)->impl<TopoDS_Shape>());
515 BRepBuilderAPI_FindPlane aFindPlane(aCompound);
517 if(aFindPlane.Found() != Standard_True) {
518 return std::shared_ptr<GeomAPI_Pln>();
521 Handle(Geom_Plane) aPlane = aFindPlane.Plane();
522 gp_Pnt aLoc = aPlane->Location();
523 gp_Dir aDir = aPlane->Axis().Direction();
525 std::shared_ptr<GeomAPI_Pnt> aGeomPnt(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
526 std::shared_ptr<GeomAPI_Dir> aGeomDir(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
528 std::shared_ptr<GeomAPI_Pln> aPln(new GeomAPI_Pln(aGeomPnt, aGeomDir));
533 //==================================================================================================
534 bool GeomAlgoAPI_ShapeTools::isSubShapeInsideShape(const std::shared_ptr<GeomAPI_Shape> theSubShape,
535 const std::shared_ptr<GeomAPI_Shape> theBaseShape)
537 if(!theSubShape.get() || !theBaseShape.get()) {
541 const TopoDS_Shape& aSubShape = theSubShape->impl<TopoDS_Shape>();
542 const TopoDS_Shape& aBaseShape = theBaseShape->impl<TopoDS_Shape>();
544 if(aSubShape.ShapeType() == TopAbs_VERTEX) {
545 // If sub-shape is a vertex check distance to shape. If it is <= Precision::Confusion() then OK.
546 BRepExtrema_DistShapeShape aDist(aBaseShape, aSubShape);
548 if(!aDist.IsDone() || aDist.Value() > Precision::Confusion()) {
551 } else if (aSubShape.ShapeType() == TopAbs_EDGE) {
552 if(aBaseShape.ShapeType() == TopAbs_FACE) {
553 // Check that edge is on face surface.
554 TopoDS_Face aFace = TopoDS::Face(aBaseShape);
555 TopoDS_Edge anEdge = TopoDS::Edge(aSubShape);
556 BRepLib_CheckCurveOnSurface aCheck(anEdge, aFace);
558 if(!aCheck.IsDone() || aCheck.MaxDistance() > Precision::Confusion()) {
562 // Check intersections.
563 TopoDS_Vertex aV1, aV2;
564 ShapeAnalysis::FindBounds(anEdge, aV1, aV2);
565 gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
566 gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
567 for(TopExp_Explorer anExp(aBaseShape, TopAbs_EDGE); anExp.More(); anExp.Next()) {
568 const TopoDS_Shape& anEdgeOnFace = anExp.Current();
569 BRepExtrema_DistShapeShape aDist(anEdgeOnFace, anEdge);
571 if(aDist.IsDone() && aDist.Value() <= Precision::Confusion()) {
572 // Edge intersect face bound. Check that it is not on edge begin or end.
573 for(Standard_Integer anIndex = 1; anIndex <= aDist.NbSolution(); ++anIndex) {
574 gp_Pnt aPntOnSubShape = aDist.PointOnShape2(anIndex);
575 if(aPntOnSubShape.Distance(aPnt1) > Precision::Confusion()
576 && aPntOnSubShape.Distance(aPnt2) > Precision::Confusion()) {
583 // No intersections found. Edge is inside or outside face. Check it.
584 BRepAdaptor_Curve aCurveAdaptor(anEdge);
585 gp_Pnt aPointToCheck = aCurveAdaptor.Value((aCurveAdaptor.FirstParameter() + aCurveAdaptor.LastParameter()) / 2.0);
586 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace);
587 ShapeAnalysis_Surface aSAS(aSurface);
588 gp_Pnt2d aPointOnFace = aSAS.ValueOfUV(aPointToCheck, Precision::Confusion());
589 BRepTopAdaptor_FClass2d aFClass2d(aFace, Precision::Confusion());
590 if(aFClass2d.Perform(aPointOnFace) == TopAbs_OUT) {
604 //==================================================================================================
605 bool GeomAlgoAPI_ShapeTools::isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape)
607 if(!theShape.get()) {
611 BRepCheck_Analyzer aChecker(theShape->impl<TopoDS_Shape>());
612 return (aChecker.IsValid() == Standard_True);