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 <BRepTools.hxx>
29 #include <BRepTopAdaptor_FClass2d.hxx>
30 #include <Geom_Curve.hxx>
31 #include <Geom2d_Curve.hxx>
32 #include <BRepLib_CheckCurveOnSurface.hxx>
33 #include <BRep_Tool.hxx>
34 #include <Geom_Plane.hxx>
35 #include <GeomLib_IsPlanarSurface.hxx>
36 #include <GeomLib_Tool.hxx>
37 #include <GeomProjLib.hxx>
39 #include <GProp_GProps.hxx>
40 #include <IntAna_IntConicQuad.hxx>
41 #include <IntAna_Quadric.hxx>
42 #include <NCollection_Vector.hxx>
43 #include <ShapeAnalysis.hxx>
44 #include <ShapeAnalysis_Surface.hxx>
45 #include <TopoDS_Builder.hxx>
46 #include <TopoDS_Edge.hxx>
47 #include <TopoDS_Face.hxx>
48 #include <TopoDS_Shape.hxx>
49 #include <TopoDS_Shell.hxx>
50 #include <TopoDS_Vertex.hxx>
52 #include <TopExp_Explorer.hxx>
54 //==================================================================================================
55 double GeomAlgoAPI_ShapeTools::volume(const std::shared_ptr<GeomAPI_Shape> theShape)
61 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
65 const Standard_Real anEps = 1.e-6;
66 BRepGProp::VolumeProperties(aShape, aGProps, anEps);
67 return aGProps.Mass();
70 //==================================================================================================
71 std::shared_ptr<GeomAPI_Pnt> GeomAlgoAPI_ShapeTools::centreOfMass(const std::shared_ptr<GeomAPI_Shape> theShape)
75 return std::shared_ptr<GeomAPI_Pnt>();
77 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
79 return std::shared_ptr<GeomAPI_Pnt>();
82 if(aShape.ShapeType() == TopAbs_VERTEX) {
83 aCentre = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
84 } else if(aShape.ShapeType() == TopAbs_EDGE || aShape.ShapeType() == TopAbs_WIRE) {
85 BRepGProp::LinearProperties(aShape, aGProps);
86 aCentre = aGProps.CentreOfMass();
88 BRepGProp::SurfaceProperties(aShape, aGProps);
89 aCentre = aGProps.CentreOfMass();
91 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aCentre.X(), aCentre.Y(), aCentre.Z()));
94 //==================================================================================================
95 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::combineShapes(const std::shared_ptr<GeomAPI_Shape> theCompound,
96 const GeomAPI_Shape::ShapeType theType,
97 ListOfShape& theCombinedShapes,
98 ListOfShape& theFreeShapes)
100 GeomShapePtr aResult = theCompound;
102 if(!theCompound.get()) {
106 if(theType != GeomAPI_Shape::SHELL && theType != GeomAPI_Shape::COMPSOLID) {
110 TopAbs_ShapeEnum aTS = TopAbs_EDGE;
111 TopAbs_ShapeEnum aTA = TopAbs_FACE;
112 if(theType == GeomAPI_Shape::COMPSOLID) {
117 theCombinedShapes.clear();
118 theFreeShapes.clear();
121 const TopoDS_Shape& aShapesComp = theCompound->impl<TopoDS_Shape>();
122 for(TopoDS_Iterator anIter(aShapesComp); anIter.More(); anIter.Next() ) {
123 const TopoDS_Shape& aShape = anIter.Value();
124 if(aShape.ShapeType() > aTA) {
125 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
126 aGeomShape->setImpl<TopoDS_Shape>(new TopoDS_Shape(aShape));
127 theFreeShapes.push_back(aGeomShape);
131 // Map subshapes and shapes.
132 BOPCol_IndexedDataMapOfShapeListOfShape aMapSA;
133 BOPTools::MapShapesAndAncestors(aShapesComp, aTS, aTA, aMapSA);
134 if(aMapSA.IsEmpty()) {
138 // Get all shapes with common subshapes and free shapes.
139 NCollection_Map<TopoDS_Shape> aFreeShapes;
140 NCollection_Vector<NCollection_Map<TopoDS_Shape>> aShapesWithCommonSubshapes;
141 for(BOPCol_IndexedDataMapOfShapeListOfShape::Iterator anIter(aMapSA); anIter.More(); anIter.Next()) {
142 const TopoDS_Shape& aShape = anIter.Key();
143 BOPCol_ListOfShape& aListOfShape = anIter.ChangeValue();
144 if(aListOfShape.IsEmpty()) {
147 else if(aListOfShape.Size() == 1) {
148 const TopoDS_Shape& aF = aListOfShape.First();
150 aListOfShape.Clear();
152 NCollection_List<TopoDS_Shape> aTempList;
153 NCollection_Map<TopoDS_Shape> aTempMap;
154 const TopoDS_Shape& aF = aListOfShape.First();
155 const TopoDS_Shape& aL = aListOfShape.Last();
156 aTempList.Append(aF);
157 aTempList.Append(aL);
160 aFreeShapes.Remove(aF);
161 aFreeShapes.Remove(aL);
162 aListOfShape.Clear();
163 for(NCollection_List<TopoDS_Shape>::Iterator aTempIter(aTempList); aTempIter.More(); aTempIter.Next()) {
164 const TopoDS_Shape& aTempShape = aTempIter.Value();
165 for(BOPCol_IndexedDataMapOfShapeListOfShape::Iterator anIter(aMapSA); anIter.More(); anIter.Next()) {
166 BOPCol_ListOfShape& aTempListOfShape = anIter.ChangeValue();
167 if(aTempListOfShape.IsEmpty()) {
169 } else if(aTempListOfShape.Size() == 1 && aTempListOfShape.First() == aTempShape) {
170 aTempListOfShape.Clear();
171 } else if(aTempListOfShape.Size() > 1) {
172 if(aTempListOfShape.First() == aTempShape) {
173 const TopoDS_Shape& aTL = aTempListOfShape.Last();
174 if(aTempMap.Add(aTL)) {
175 aTempList.Append(aTL);
176 aFreeShapes.Remove(aTL);
178 aTempListOfShape.Clear();
179 } else if(aTempListOfShape.Last() == aTempShape) {
180 const TopoDS_Shape& aTF = aTempListOfShape.First();
181 if(aTempMap.Add(aTF)) {
182 aTempList.Append(aTF);
183 aFreeShapes.Remove(aTF);
185 aTempListOfShape.Clear();
190 aShapesWithCommonSubshapes.Append(aTempMap);
194 // Combine shapes with common subshapes.
195 for(NCollection_Vector<NCollection_Map<TopoDS_Shape>>::Iterator anIter(aShapesWithCommonSubshapes); anIter.More(); anIter.Next()) {
197 TopoDS_CompSolid aCSolid;
198 TopoDS_Builder aBuilder;
199 theType == GeomAPI_Shape::COMPSOLID ? aBuilder.MakeCompSolid(aCSolid) : aBuilder.MakeShell(aShell);
200 NCollection_Map<TopoDS_Shape>& aShapesMap = anIter.ChangeValue();
201 for(TopExp_Explorer anExp(aShapesComp, aTA); anExp.More(); anExp.Next()) {
202 const TopoDS_Shape& aShape = anExp.Current();
203 if(aShapesMap.Contains(aShape)) {
204 theType == GeomAPI_Shape::COMPSOLID ? aBuilder.Add(aCSolid, aShape) : aBuilder.Add(aShell, aShape);
205 aShapesMap.Remove(aShape);
208 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
209 TopoDS_Shape* aSh = theType == GeomAPI_Shape::COMPSOLID ? new TopoDS_Shape(aCSolid) : new TopoDS_Shape(aShell);
210 aGeomShape->setImpl<TopoDS_Shape>(aSh);
211 theCombinedShapes.push_back(aGeomShape);
214 // Adding free shapes.
215 for(TopExp_Explorer anExp(aShapesComp, aTA); anExp.More(); anExp.Next()) {
216 const TopoDS_Shape& aShape = anExp.Current();
217 if(aFreeShapes.Contains(aShape)) {
218 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
219 aGeomShape->setImpl<TopoDS_Shape>(new TopoDS_Shape(aShape));
220 theFreeShapes.push_back(aGeomShape);
224 if(theCombinedShapes.size() == 1 && theFreeShapes.size() == 0) {
225 aResult = theCombinedShapes.front();
226 } else if (theCombinedShapes.size() > 1 || (theCombinedShapes.size() >= 1 && theFreeShapes.size() >= 1)) {
227 TopoDS_Compound aResultComp;
228 TopoDS_Builder aBuilder;
229 aBuilder.MakeCompound(aResultComp);
230 for(ListOfShape::const_iterator anIter = theCombinedShapes.cbegin(); anIter != theCombinedShapes.cend(); anIter++) {
231 aBuilder.Add(aResultComp, (*anIter)->impl<TopoDS_Shape>());
233 for(ListOfShape::const_iterator anIter = theFreeShapes.cbegin(); anIter != theFreeShapes.cend(); anIter++) {
234 aBuilder.Add(aResultComp, (*anIter)->impl<TopoDS_Shape>());
236 aResult->setImpl(new TopoDS_Shape(aResultComp));
242 //==================================================================================================
243 static void addSimpleShapeToList(const TopoDS_Shape& theShape, NCollection_List<TopoDS_Shape>& theList)
245 if(theShape.IsNull()) {
249 if(theShape.ShapeType() == TopAbs_COMPOUND) {
250 for(TopoDS_Iterator anIt(theShape); anIt.More(); anIt.Next()) {
251 addSimpleShapeToList(anIt.Value(), theList);
254 theList.Append(theShape);
258 //==================================================================================================
259 static TopoDS_Compound makeCompound(const NCollection_List<TopoDS_Shape> theShapes)
261 TopoDS_Compound aCompound;
263 BRep_Builder aBuilder;
264 aBuilder.MakeCompound(aCompound);
266 for(NCollection_List<TopoDS_Shape>::Iterator anIt(theShapes); anIt.More(); anIt.Next()) {
267 aBuilder.Add(aCompound, anIt.Value());
273 //==================================================================================================
274 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::groupSharedTopology(const std::shared_ptr<GeomAPI_Shape> theCompound)
276 GeomShapePtr aResult = theCompound;
278 if(!theCompound.get()) {
282 TopoDS_Shape anInShape = aResult->impl<TopoDS_Shape>();
283 NCollection_List<TopoDS_Shape> anUngroupedShapes;
284 addSimpleShapeToList(anInShape, anUngroupedShapes);
286 NCollection_Vector<NCollection_List<TopoDS_Shape>> aGroups;
287 while(!anUngroupedShapes.IsEmpty()) {
288 NCollection_List<TopoDS_Shape> aGroupedShapes;
289 aGroupedShapes.Append(anUngroupedShapes.First());
290 anUngroupedShapes.RemoveFirst();
291 for(NCollection_List<TopoDS_Shape>::Iterator aGroupIt(aGroupedShapes); aGroupIt.More(); aGroupIt.Next()) {
292 const TopoDS_Shape& aGroupShape = aGroupIt.Value();
293 for(NCollection_List<TopoDS_Shape>::Iterator anUngroupedIt(anUngroupedShapes); anUngroupedIt.More(); anUngroupedIt.Next()) {
294 const TopoDS_Shape& anUngroupedShape = anUngroupedIt.Value();
295 bool isFound = false;
296 for(TopExp_Explorer aGroupShapeExp(aGroupShape, TopAbs_VERTEX); aGroupShapeExp.More(); aGroupShapeExp.Next()) {
297 const TopoDS_Shape& aVertex1 = aGroupShapeExp.Current();
298 for(TopExp_Explorer anUngroupedShapeExp(anUngroupedShape, TopAbs_VERTEX); anUngroupedShapeExp.More(); anUngroupedShapeExp.Next()) {
299 const TopoDS_Shape& aVertex2 = anUngroupedShapeExp.Current();
300 if(aVertex1.IsSame(aVertex2)) {
301 aGroupedShapes.Append(anUngroupedShape);
302 anUngroupedShapes.Remove(anUngroupedIt);
311 if(!anUngroupedIt.More()) {
316 aGroups.Append(aGroupedShapes);
319 TopoDS_Compound aCompound;
320 BRep_Builder aBuilder;
321 aBuilder.MakeCompound(aCompound);
322 ListOfShape aCompSolids, aFreeSolids;
323 for(NCollection_Vector<NCollection_List<TopoDS_Shape>>::Iterator anIt(aGroups); anIt.More(); anIt.Next()) {
324 NCollection_List<TopoDS_Shape> aGroup = anIt.Value();
325 GeomShapePtr aGeomShape(new GeomAPI_Shape());
326 if(aGroup.Size() == 1) {
327 aGeomShape->setImpl(new TopoDS_Shape(aGroup.First()));
329 aGeomShape->setImpl(new TopoDS_Shape(makeCompound(anIt.Value())));
330 aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape,
331 GeomAPI_Shape::COMPSOLID,
335 aBuilder.Add(aCompound, aGeomShape->impl<TopoDS_Shape>());
338 if(!aCompound.IsNull()) {
339 aResult->setImpl(new TopoDS_Shape(aCompound));
345 //==================================================================================================
346 std::list<std::shared_ptr<GeomAPI_Pnt> > GeomAlgoAPI_ShapeTools::getBoundingBox(const ListOfShape& theShapes, const double theEnlarge)
348 // Bounding box of all objects.
352 for (ListOfShape::const_iterator anObjectsIt = theShapes.begin(); anObjectsIt != theShapes.end(); anObjectsIt++) {
353 const TopoDS_Shape& aShape = (*anObjectsIt)->impl<TopoDS_Shape>();
354 BRepBndLib::Add(aShape, aBndBox);
357 if(theEnlarge != 0.0) {
358 // We enlarge bounding box just to be sure that plane will be large enough to cut all objects.
359 aBndBox.Enlarge(theEnlarge);
362 Standard_Real aXArr[2] = {aBndBox.CornerMin().X(), aBndBox.CornerMax().X()};
363 Standard_Real aYArr[2] = {aBndBox.CornerMin().Y(), aBndBox.CornerMax().Y()};
364 Standard_Real aZArr[2] = {aBndBox.CornerMin().Z(), aBndBox.CornerMax().Z()};
365 std::list<std::shared_ptr<GeomAPI_Pnt> > aResultPoints;
367 for(int i = 0; i < 2; i++) {
368 for(int j = 0; j < 2; j++) {
369 for(int k = 0; k < 2; k++) {
370 std::shared_ptr<GeomAPI_Pnt> aPnt(new GeomAPI_Pnt(aXArr[i], aYArr[j], aZArr[k]));
371 aResultPoints.push_back(aPnt);
376 return aResultPoints;
379 //==================================================================================================
380 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::faceToInfinitePlane(const std::shared_ptr<GeomAPI_Shape> theFace)
383 return std::shared_ptr<GeomAPI_Shape>();
385 TopoDS_Face aPlaneFace = TopoDS::Face(theFace->impl<TopoDS_Shape>());
386 if (aPlaneFace.IsNull())
387 return std::shared_ptr<GeomAPI_Shape>();
389 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(aPlaneFace));
391 return std::shared_ptr<GeomAPI_Shape>();
393 // make an infinity face on the plane
394 TopoDS_Shape anInfiniteFace = BRepBuilderAPI_MakeFace(aPlane->Pln()).Shape();
396 std::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape);
397 aResult->setImpl(new TopoDS_Shape(anInfiniteFace));
401 //==================================================================================================
402 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::fitPlaneToBox(const std::shared_ptr<GeomAPI_Shape> thePlane,
403 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints)
405 std::shared_ptr<GeomAPI_Shape> aResultShape;
407 if(!thePlane.get()) {
411 const TopoDS_Shape& aShape = thePlane->impl<TopoDS_Shape>();
412 if(aShape.ShapeType() != TopAbs_FACE) {
416 TopoDS_Face aFace = TopoDS::Face(aShape);
417 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
422 GeomLib_IsPlanarSurface isPlanar(aSurf);
423 if(!isPlanar.IsPlanar()) {
427 if(thePoints.size() != 8) {
431 const gp_Pln& aFacePln = isPlanar.Plan();
432 Handle(Geom_Plane) aFacePlane = new Geom_Plane(aFacePln);
433 IntAna_Quadric aQuadric(aFacePln);
434 Standard_Real UMin, UMax, VMin, VMax;
435 UMin = UMax = VMin = VMax = 0;
436 for (std::list<std::shared_ptr<GeomAPI_Pnt> >::const_iterator aPointsIt = thePoints.begin(); aPointsIt != thePoints.end(); aPointsIt++) {
437 const gp_Pnt& aPnt = (*aPointsIt)->impl<gp_Pnt>();
438 gp_Lin aLin(aPnt, aFacePln.Axis().Direction());
439 IntAna_IntConicQuad anIntAna(aLin, aQuadric);
440 const gp_Pnt& aPntOnFace = anIntAna.Point(1);
441 Standard_Real aPntU(0), aPntV(0);
442 GeomLib_Tool::Parameters(aFacePlane, aPntOnFace, Precision::Confusion(), aPntU, aPntV);
443 if(aPntU < UMin) UMin = aPntU;
444 if(aPntU > UMax) UMax = aPntU;
445 if(aPntV < VMin) VMin = aPntV;
446 if(aPntV > VMax) VMax = aPntV;
448 aResultShape.reset(new GeomAPI_Shape);
449 aResultShape->setImpl(new TopoDS_Shape(BRepLib_MakeFace(aFacePln, UMin, UMax, VMin, VMax).Face()));
454 //==================================================================================================
455 void GeomAlgoAPI_ShapeTools::findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
456 std::shared_ptr<GeomAPI_Vertex>& theV1,
457 std::shared_ptr<GeomAPI_Vertex>& theV2)
459 if(!theShape.get()) {
460 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex);
461 aVertex->setImpl(new TopoDS_Vertex());
467 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
468 TopoDS_Vertex aV1, aV2;
469 ShapeAnalysis::FindBounds(aShape, aV1, aV2);
471 std::shared_ptr<GeomAPI_Vertex> aGeomV1(new GeomAPI_Vertex()), aGeomV2(new GeomAPI_Vertex());
472 aGeomV1->setImpl(new TopoDS_Vertex(aV1));
473 aGeomV2->setImpl(new TopoDS_Vertex(aV2));
478 //==================================================================================================
479 void GeomAlgoAPI_ShapeTools::makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
480 const std::shared_ptr<GeomAPI_Dir> theDirection,
481 const ListOfShape& theWires,
482 ListOfShape& theFaces)
484 BRepBuilderAPI_MakeFace aMKFace(gp_Pln(theOrigin->impl<gp_Pnt>(),
485 theDirection->impl<gp_Dir>()));
486 TopoDS_Face aFace = aMKFace.Face();
488 BRepAlgo_FaceRestrictor aFRestrictor;
489 aFRestrictor.Init(aFace, Standard_False, Standard_True);
490 for(ListOfShape::const_iterator anIt = theWires.cbegin();
491 anIt != theWires.cend();
493 TopoDS_Wire aWire = TopoDS::Wire((*anIt)->impl<TopoDS_Shape>());
494 aFRestrictor.Add(aWire);
497 aFRestrictor.Perform();
499 if(!aFRestrictor.IsDone()) {
503 for(; aFRestrictor.More(); aFRestrictor.Next()) {
504 GeomShapePtr aShape(new GeomAPI_Shape());
505 aShape->setImpl(new TopoDS_Shape(aFRestrictor.Current()));
506 theFaces.push_back(aShape);
510 //==================================================================================================
511 std::shared_ptr<GeomAPI_Pln> GeomAlgoAPI_ShapeTools::findPlane(const ListOfShape& theShapes)
513 TopoDS_Compound aCompound;
514 BRep_Builder aBuilder;
515 aBuilder.MakeCompound(aCompound);
517 for(ListOfShape::const_iterator anIt = theShapes.cbegin(); anIt != theShapes.cend(); ++anIt) {
518 aBuilder.Add(aCompound, (*anIt)->impl<TopoDS_Shape>());
520 BRepBuilderAPI_FindPlane aFindPlane(aCompound);
522 if(aFindPlane.Found() != Standard_True) {
523 return std::shared_ptr<GeomAPI_Pln>();
526 Handle(Geom_Plane) aPlane = aFindPlane.Plane();
527 gp_Pnt aLoc = aPlane->Location();
528 gp_Dir aDir = aPlane->Axis().Direction();
530 std::shared_ptr<GeomAPI_Pnt> aGeomPnt(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
531 std::shared_ptr<GeomAPI_Dir> aGeomDir(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
533 std::shared_ptr<GeomAPI_Pln> aPln(new GeomAPI_Pln(aGeomPnt, aGeomDir));
538 //==================================================================================================
539 bool GeomAlgoAPI_ShapeTools::isSubShapeInsideShape(const std::shared_ptr<GeomAPI_Shape> theSubShape,
540 const std::shared_ptr<GeomAPI_Shape> theBaseShape)
542 if(!theSubShape.get() || !theBaseShape.get()) {
546 const TopoDS_Shape& aSubShape = theSubShape->impl<TopoDS_Shape>();
547 const TopoDS_Shape& aBaseShape = theBaseShape->impl<TopoDS_Shape>();
549 if(aSubShape.ShapeType() == TopAbs_VERTEX) {
550 // If sub-shape is a vertex check distance to shape. If it is <= Precision::Confusion() then OK.
551 BRepExtrema_DistShapeShape aDist(aBaseShape, aSubShape);
553 if(!aDist.IsDone() || aDist.Value() > Precision::Confusion()) {
556 } else if (aSubShape.ShapeType() == TopAbs_EDGE) {
557 if(aBaseShape.ShapeType() == TopAbs_FACE) {
558 // Check that edge is on face surface.
559 TopoDS_Face aFace = TopoDS::Face(aBaseShape);
560 TopoDS_Edge anEdge = TopoDS::Edge(aSubShape);
561 BRepLib_CheckCurveOnSurface aCheck(anEdge, aFace);
563 if(!aCheck.IsDone() || aCheck.MaxDistance() > Precision::Confusion()) {
567 // Check intersections.
568 TopoDS_Vertex aV1, aV2;
569 ShapeAnalysis::FindBounds(anEdge, aV1, aV2);
570 gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
571 gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
572 for(TopExp_Explorer anExp(aBaseShape, TopAbs_EDGE); anExp.More(); anExp.Next()) {
573 const TopoDS_Shape& anEdgeOnFace = anExp.Current();
574 BRepExtrema_DistShapeShape aDist(anEdgeOnFace, anEdge);
576 if(aDist.IsDone() && aDist.Value() <= Precision::Confusion()) {
577 // Edge intersect face bound. Check that it is not on edge begin or end.
578 for(Standard_Integer anIndex = 1; anIndex <= aDist.NbSolution(); ++anIndex) {
579 gp_Pnt aPntOnSubShape = aDist.PointOnShape2(anIndex);
580 if(aPntOnSubShape.Distance(aPnt1) > Precision::Confusion()
581 && aPntOnSubShape.Distance(aPnt2) > Precision::Confusion()) {
588 // No intersections found. Edge is inside or outside face. Check it.
589 BRepAdaptor_Curve aCurveAdaptor(anEdge);
590 gp_Pnt aPointToCheck = aCurveAdaptor.Value((aCurveAdaptor.FirstParameter() + aCurveAdaptor.LastParameter()) / 2.0);
591 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace);
592 ShapeAnalysis_Surface aSAS(aSurface);
593 gp_Pnt2d aPointOnFace = aSAS.ValueOfUV(aPointToCheck, Precision::Confusion());
594 BRepTopAdaptor_FClass2d aFClass2d(aFace, Precision::Confusion());
595 if(aFClass2d.Perform(aPointOnFace) == TopAbs_OUT) {
609 //==================================================================================================
610 bool GeomAlgoAPI_ShapeTools::isShapeValid(const std::shared_ptr<GeomAPI_Shape> theShape)
612 if(!theShape.get()) {
616 BRepCheck_Analyzer aChecker(theShape->impl<TopoDS_Shape>());
617 return (aChecker.IsValid() == Standard_True);
620 //==================================================================================================
621 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::getFaceOuterWire(const std::shared_ptr<GeomAPI_Shape> theFace)
623 GeomShapePtr anOuterWire;
625 if(!theFace.get() || !theFace->isFace()) {
629 TopoDS_Face aFace = TopoDS::Face(theFace->impl<TopoDS_Shape>());
630 TopoDS_Wire aWire = BRepTools::OuterWire(aFace);
632 anOuterWire.reset(new GeomAPI_Shape());
633 anOuterWire->setImpl(new TopoDS_Shape(aWire));