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 <BRepExtrema_DistShapeShape.hxx>
26 #include <BRepGProp.hxx>
27 #include <BRepTopAdaptor_FClass2d.hxx>
28 #include <Geom_Curve.hxx>
29 #include <Geom2d_Curve.hxx>
30 #include <BRepLib_CheckCurveOnSurface.hxx>
31 #include <BRep_Tool.hxx>
32 #include <Geom_Plane.hxx>
33 #include <GeomLib_IsPlanarSurface.hxx>
34 #include <GeomLib_Tool.hxx>
35 #include <GeomProjLib.hxx>
37 #include <GProp_GProps.hxx>
38 #include <IntAna_IntConicQuad.hxx>
39 #include <IntAna_Quadric.hxx>
40 #include <NCollection_Vector.hxx>
41 #include <ShapeAnalysis.hxx>
42 #include <ShapeAnalysis_Surface.hxx>
43 #include <TopoDS_Builder.hxx>
44 #include <TopoDS_Edge.hxx>
45 #include <TopoDS_Face.hxx>
46 #include <TopoDS_Shape.hxx>
47 #include <TopoDS_Shell.hxx>
48 #include <TopoDS_Vertex.hxx>
50 #include <TopExp_Explorer.hxx>
52 //==================================================================================================
53 double GeomAlgoAPI_ShapeTools::volume(const std::shared_ptr<GeomAPI_Shape> theShape)
59 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
63 const Standard_Real anEps = 1.e-6;
64 BRepGProp::VolumeProperties(aShape, aGProps, anEps);
65 return aGProps.Mass();
68 //==================================================================================================
69 std::shared_ptr<GeomAPI_Pnt> GeomAlgoAPI_ShapeTools::centreOfMass(const std::shared_ptr<GeomAPI_Shape> theShape)
73 return std::shared_ptr<GeomAPI_Pnt>();
75 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
77 return std::shared_ptr<GeomAPI_Pnt>();
80 if(aShape.ShapeType() == TopAbs_VERTEX) {
81 aCentre = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
82 } else if(aShape.ShapeType() == TopAbs_EDGE || aShape.ShapeType() == TopAbs_WIRE) {
83 BRepGProp::LinearProperties(aShape, aGProps);
84 aCentre = aGProps.CentreOfMass();
86 BRepGProp::SurfaceProperties(aShape, aGProps);
87 aCentre = aGProps.CentreOfMass();
89 return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aCentre.X(), aCentre.Y(), aCentre.Z()));
92 //==================================================================================================
93 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::combineShapes(const std::shared_ptr<GeomAPI_Shape> theCompound,
94 const GeomAPI_Shape::ShapeType theType,
95 ListOfShape& theCombinedShapes,
96 ListOfShape& theFreeShapes)
98 GeomShapePtr aResult = theCompound;
100 if(!theCompound.get()) {
104 if(theType != GeomAPI_Shape::SHELL && theType != GeomAPI_Shape::COMPSOLID) {
108 TopAbs_ShapeEnum aTS = TopAbs_EDGE;
109 TopAbs_ShapeEnum aTA = TopAbs_FACE;
110 if(theType == GeomAPI_Shape::COMPSOLID) {
115 theCombinedShapes.clear();
116 theFreeShapes.clear();
119 const TopoDS_Shape& aShapesComp = theCompound->impl<TopoDS_Shape>();
120 for(TopoDS_Iterator anIter(aShapesComp); anIter.More(); anIter.Next() ) {
121 const TopoDS_Shape& aShape = anIter.Value();
122 if(aShape.ShapeType() > aTA) {
123 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
124 aGeomShape->setImpl<TopoDS_Shape>(new TopoDS_Shape(aShape));
125 theFreeShapes.push_back(aGeomShape);
129 // Map subshapes and shapes.
130 BOPCol_IndexedDataMapOfShapeListOfShape aMapSA;
131 BOPTools::MapShapesAndAncestors(aShapesComp, aTS, aTA, aMapSA);
132 if(aMapSA.IsEmpty()) {
136 // Get all shapes with common subshapes and free shapes.
137 NCollection_Map<TopoDS_Shape> aFreeShapes;
138 NCollection_Vector<NCollection_Map<TopoDS_Shape>> aShapesWithCommonSubshapes;
139 for(BOPCol_IndexedDataMapOfShapeListOfShape::Iterator anIter(aMapSA); anIter.More(); anIter.Next()) {
140 const TopoDS_Shape& aShape = anIter.Key();
141 BOPCol_ListOfShape& aListOfShape = anIter.ChangeValue();
142 if(aListOfShape.IsEmpty()) {
145 else if(aListOfShape.Size() == 1) {
146 const TopoDS_Shape& aF = aListOfShape.First();
148 aListOfShape.Clear();
150 NCollection_List<TopoDS_Shape> aTempList;
151 NCollection_Map<TopoDS_Shape> aTempMap;
152 const TopoDS_Shape& aF = aListOfShape.First();
153 const TopoDS_Shape& aL = aListOfShape.Last();
154 aTempList.Append(aF);
155 aTempList.Append(aL);
158 aFreeShapes.Remove(aF);
159 aFreeShapes.Remove(aL);
160 aListOfShape.Clear();
161 for(NCollection_List<TopoDS_Shape>::Iterator aTempIter(aTempList); aTempIter.More(); aTempIter.Next()) {
162 const TopoDS_Shape& aTempShape = aTempIter.Value();
163 for(BOPCol_IndexedDataMapOfShapeListOfShape::Iterator anIter(aMapSA); anIter.More(); anIter.Next()) {
164 BOPCol_ListOfShape& aTempListOfShape = anIter.ChangeValue();
165 if(aTempListOfShape.IsEmpty()) {
167 } else if(aTempListOfShape.Size() == 1 && aTempListOfShape.First() == aTempShape) {
168 aTempListOfShape.Clear();
169 } else if(aTempListOfShape.Size() > 1) {
170 if(aTempListOfShape.First() == aTempShape) {
171 const TopoDS_Shape& aTL = aTempListOfShape.Last();
172 if(aTempMap.Add(aTL)) {
173 aTempList.Append(aTL);
174 aFreeShapes.Remove(aTL);
176 aTempListOfShape.Clear();
177 } else if(aTempListOfShape.Last() == aTempShape) {
178 const TopoDS_Shape& aTF = aTempListOfShape.First();
179 if(aTempMap.Add(aTF)) {
180 aTempList.Append(aTF);
181 aFreeShapes.Remove(aTF);
183 aTempListOfShape.Clear();
188 aShapesWithCommonSubshapes.Append(aTempMap);
192 // Combine shapes with common subshapes.
193 for(NCollection_Vector<NCollection_Map<TopoDS_Shape>>::Iterator anIter(aShapesWithCommonSubshapes); anIter.More(); anIter.Next()) {
195 TopoDS_CompSolid aCSolid;
196 TopoDS_Builder aBuilder;
197 theType == GeomAPI_Shape::COMPSOLID ? aBuilder.MakeCompSolid(aCSolid) : aBuilder.MakeShell(aShell);
198 NCollection_Map<TopoDS_Shape>& aShapesMap = anIter.ChangeValue();
199 for(TopExp_Explorer anExp(aShapesComp, aTA); anExp.More(); anExp.Next()) {
200 const TopoDS_Shape& aShape = anExp.Current();
201 if(aShapesMap.Contains(aShape)) {
202 theType == GeomAPI_Shape::COMPSOLID ? aBuilder.Add(aCSolid, aShape) : aBuilder.Add(aShell, aShape);
203 aShapesMap.Remove(aShape);
206 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
207 TopoDS_Shape* aSh = theType == GeomAPI_Shape::COMPSOLID ? new TopoDS_Shape(aCSolid) : new TopoDS_Shape(aShell);
208 aGeomShape->setImpl<TopoDS_Shape>(aSh);
209 theCombinedShapes.push_back(aGeomShape);
212 // Adding free shapes.
213 for(TopExp_Explorer anExp(aShapesComp, aTA); anExp.More(); anExp.Next()) {
214 const TopoDS_Shape& aShape = anExp.Current();
215 if(aFreeShapes.Contains(aShape)) {
216 std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
217 aGeomShape->setImpl<TopoDS_Shape>(new TopoDS_Shape(aShape));
218 theFreeShapes.push_back(aGeomShape);
222 if(theCombinedShapes.size() == 1 && theFreeShapes.size() == 0) {
223 aResult = theCombinedShapes.front();
224 } else if (theCombinedShapes.size() > 1 || (theCombinedShapes.size() >= 1 && theFreeShapes.size() >= 1)) {
225 TopoDS_Compound aResultComp;
226 TopoDS_Builder aBuilder;
227 aBuilder.MakeCompound(aResultComp);
228 for(ListOfShape::const_iterator anIter = theCombinedShapes.cbegin(); anIter != theCombinedShapes.cend(); anIter++) {
229 aBuilder.Add(aResultComp, (*anIter)->impl<TopoDS_Shape>());
231 for(ListOfShape::const_iterator anIter = theFreeShapes.cbegin(); anIter != theFreeShapes.cend(); anIter++) {
232 aBuilder.Add(aResultComp, (*anIter)->impl<TopoDS_Shape>());
234 aResult->setImpl(new TopoDS_Shape(aResultComp));
240 //==================================================================================================
241 static void addSimpleShapeToList(const TopoDS_Shape& theShape, NCollection_List<TopoDS_Shape>& theList)
243 if(theShape.IsNull()) {
247 if(theShape.ShapeType() == TopAbs_COMPOUND) {
248 for(TopoDS_Iterator anIt(theShape); anIt.More(); anIt.Next()) {
249 addSimpleShapeToList(anIt.Value(), theList);
252 theList.Append(theShape);
256 //==================================================================================================
257 static TopoDS_Compound makeCompound(const NCollection_List<TopoDS_Shape> theShapes)
259 TopoDS_Compound aCompound;
261 BRep_Builder aBuilder;
262 aBuilder.MakeCompound(aCompound);
264 for(NCollection_List<TopoDS_Shape>::Iterator anIt(theShapes); anIt.More(); anIt.Next()) {
265 aBuilder.Add(aCompound, anIt.Value());
271 //==================================================================================================
272 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::groupSharedTopology(const std::shared_ptr<GeomAPI_Shape> theCompound)
274 GeomShapePtr aResult = theCompound;
276 if(!theCompound.get()) {
280 TopoDS_Shape anInShape = aResult->impl<TopoDS_Shape>();
281 NCollection_List<TopoDS_Shape> anUngroupedShapes;
282 addSimpleShapeToList(anInShape, anUngroupedShapes);
284 NCollection_Vector<NCollection_List<TopoDS_Shape>> aGroups;
285 while(!anUngroupedShapes.IsEmpty()) {
286 NCollection_List<TopoDS_Shape> aGroupedShapes;
287 aGroupedShapes.Append(anUngroupedShapes.First());
288 anUngroupedShapes.RemoveFirst();
289 for(NCollection_List<TopoDS_Shape>::Iterator aGroupIt(aGroupedShapes); aGroupIt.More(); aGroupIt.Next()) {
290 const TopoDS_Shape& aGroupShape = aGroupIt.Value();
291 for(NCollection_List<TopoDS_Shape>::Iterator anUngroupedIt(anUngroupedShapes); anUngroupedIt.More(); anUngroupedIt.Next()) {
292 const TopoDS_Shape& anUngroupedShape = anUngroupedIt.Value();
293 bool isFound = false;
294 for(TopExp_Explorer aGroupShapeExp(aGroupShape, TopAbs_VERTEX); aGroupShapeExp.More(); aGroupShapeExp.Next()) {
295 const TopoDS_Shape& aVertex1 = aGroupShapeExp.Current();
296 for(TopExp_Explorer anUngroupedShapeExp(anUngroupedShape, TopAbs_VERTEX); anUngroupedShapeExp.More(); anUngroupedShapeExp.Next()) {
297 const TopoDS_Shape& aVertex2 = anUngroupedShapeExp.Current();
298 if(aVertex1.IsSame(aVertex2)) {
299 aGroupedShapes.Append(anUngroupedShape);
300 anUngroupedShapes.Remove(anUngroupedIt);
309 if(!anUngroupedIt.More()) {
314 aGroups.Append(aGroupedShapes);
317 TopoDS_Compound aCompound;
318 BRep_Builder aBuilder;
319 aBuilder.MakeCompound(aCompound);
320 ListOfShape aCompSolids, aFreeSolids;
321 for(NCollection_Vector<NCollection_List<TopoDS_Shape>>::Iterator anIt(aGroups); anIt.More(); anIt.Next()) {
322 TopoDS_Compound aGroupCompound = makeCompound(anIt.Value());
323 GeomShapePtr aGeomShape(new GeomAPI_Shape());
324 aGeomShape->setImpl(new TopoDS_Shape(aGroupCompound));
325 aGeomShape = GeomAlgoAPI_ShapeTools::combineShapes(aGeomShape,
326 GeomAPI_Shape::COMPSOLID,
329 aBuilder.Add(aCompound, aGeomShape->impl<TopoDS_Shape>());
332 if(!aCompound.IsNull()) {
333 aResult->setImpl(new TopoDS_Shape(aCompound));
339 //==================================================================================================
340 std::list<std::shared_ptr<GeomAPI_Pnt> > GeomAlgoAPI_ShapeTools::getBoundingBox(const ListOfShape& theShapes, const double theEnlarge)
342 // Bounding box of all objects.
346 for (ListOfShape::const_iterator anObjectsIt = theShapes.begin(); anObjectsIt != theShapes.end(); anObjectsIt++) {
347 const TopoDS_Shape& aShape = (*anObjectsIt)->impl<TopoDS_Shape>();
348 BRepBndLib::Add(aShape, aBndBox);
351 if(theEnlarge != 0.0) {
352 // We enlarge bounding box just to be sure that plane will be large enough to cut all objects.
353 aBndBox.Enlarge(theEnlarge);
356 Standard_Real aXArr[2] = {aBndBox.CornerMin().X(), aBndBox.CornerMax().X()};
357 Standard_Real aYArr[2] = {aBndBox.CornerMin().Y(), aBndBox.CornerMax().Y()};
358 Standard_Real aZArr[2] = {aBndBox.CornerMin().Z(), aBndBox.CornerMax().Z()};
359 std::list<std::shared_ptr<GeomAPI_Pnt> > aResultPoints;
361 for(int i = 0; i < 2; i++) {
362 for(int j = 0; j < 2; j++) {
363 for(int k = 0; k < 2; k++) {
364 std::shared_ptr<GeomAPI_Pnt> aPnt(new GeomAPI_Pnt(aXArr[i], aYArr[j], aZArr[k]));
365 aResultPoints.push_back(aPnt);
370 return aResultPoints;
373 //==================================================================================================
374 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::faceToInfinitePlane(const std::shared_ptr<GeomAPI_Shape> theFace)
377 return std::shared_ptr<GeomAPI_Shape>();
379 TopoDS_Face aPlaneFace = TopoDS::Face(theFace->impl<TopoDS_Shape>());
380 if (aPlaneFace.IsNull())
381 return std::shared_ptr<GeomAPI_Shape>();
383 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(aPlaneFace));
385 return std::shared_ptr<GeomAPI_Shape>();
387 // make an infinity face on the plane
388 TopoDS_Shape anInfiniteFace = BRepBuilderAPI_MakeFace(aPlane->Pln()).Shape();
390 std::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape);
391 aResult->setImpl(new TopoDS_Shape(anInfiniteFace));
395 //==================================================================================================
396 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::fitPlaneToBox(const std::shared_ptr<GeomAPI_Shape> thePlane,
397 const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints)
399 std::shared_ptr<GeomAPI_Shape> aResultShape;
401 if(!thePlane.get()) {
405 const TopoDS_Shape& aShape = thePlane->impl<TopoDS_Shape>();
406 if(aShape.ShapeType() != TopAbs_FACE) {
410 TopoDS_Face aFace = TopoDS::Face(aShape);
411 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
416 GeomLib_IsPlanarSurface isPlanar(aSurf);
417 if(!isPlanar.IsPlanar()) {
421 if(thePoints.size() != 8) {
425 const gp_Pln& aFacePln = isPlanar.Plan();
426 Handle(Geom_Plane) aFacePlane = new Geom_Plane(aFacePln);
427 IntAna_Quadric aQuadric(aFacePln);
428 Standard_Real UMin, UMax, VMin, VMax;
429 UMin = UMax = VMin = VMax = 0;
430 for (std::list<std::shared_ptr<GeomAPI_Pnt> >::const_iterator aPointsIt = thePoints.begin(); aPointsIt != thePoints.end(); aPointsIt++) {
431 const gp_Pnt& aPnt = (*aPointsIt)->impl<gp_Pnt>();
432 gp_Lin aLin(aPnt, aFacePln.Axis().Direction());
433 IntAna_IntConicQuad anIntAna(aLin, aQuadric);
434 const gp_Pnt& aPntOnFace = anIntAna.Point(1);
435 Standard_Real aPntU(0), aPntV(0);
436 GeomLib_Tool::Parameters(aFacePlane, aPntOnFace, Precision::Confusion(), aPntU, aPntV);
437 if(aPntU < UMin) UMin = aPntU;
438 if(aPntU > UMax) UMax = aPntU;
439 if(aPntV < VMin) VMin = aPntV;
440 if(aPntV > VMax) VMax = aPntV;
442 aResultShape.reset(new GeomAPI_Shape);
443 aResultShape->setImpl(new TopoDS_Shape(BRepLib_MakeFace(aFacePln, UMin, UMax, VMin, VMax).Face()));
448 //==================================================================================================
449 void GeomAlgoAPI_ShapeTools::findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
450 std::shared_ptr<GeomAPI_Vertex>& theV1,
451 std::shared_ptr<GeomAPI_Vertex>& theV2)
453 if(!theShape.get()) {
454 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex);
455 aVertex->setImpl(new TopoDS_Vertex());
461 const TopoDS_Shape& aShape = theShape->impl<TopoDS_Shape>();
462 TopoDS_Vertex aV1, aV2;
463 ShapeAnalysis::FindBounds(aShape, aV1, aV2);
465 std::shared_ptr<GeomAPI_Vertex> aGeomV1(new GeomAPI_Vertex()), aGeomV2(new GeomAPI_Vertex());
466 aGeomV1->setImpl(new TopoDS_Vertex(aV1));
467 aGeomV2->setImpl(new TopoDS_Vertex(aV2));
472 //==================================================================================================
473 void GeomAlgoAPI_ShapeTools::makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
474 const std::shared_ptr<GeomAPI_Dir> theDirection,
475 const ListOfShape& theWires,
476 ListOfShape& theFaces)
478 BRepBuilderAPI_MakeFace aMKFace(gp_Pln(theOrigin->impl<gp_Pnt>(),
479 theDirection->impl<gp_Dir>()));
480 TopoDS_Face aFace = aMKFace.Face();
482 BRepAlgo_FaceRestrictor aFRestrictor;
483 aFRestrictor.Init(aFace, Standard_False, Standard_True);
484 for(ListOfShape::const_iterator anIt = theWires.cbegin();
485 anIt != theWires.cend();
487 TopoDS_Wire aWire = TopoDS::Wire((*anIt)->impl<TopoDS_Shape>());
488 aFRestrictor.Add(aWire);
491 aFRestrictor.Perform();
493 if(!aFRestrictor.IsDone()) {
497 for(; aFRestrictor.More(); aFRestrictor.Next()) {
498 GeomShapePtr aShape(new GeomAPI_Shape());
499 aShape->setImpl(new TopoDS_Shape(aFRestrictor.Current()));
500 theFaces.push_back(aShape);
504 //==================================================================================================
505 std::shared_ptr<GeomAPI_Pln> GeomAlgoAPI_ShapeTools::findPlane(const ListOfShape& theShapes)
507 TopoDS_Compound aCompound;
508 BRep_Builder aBuilder;
509 aBuilder.MakeCompound(aCompound);
511 for(ListOfShape::const_iterator anIt = theShapes.cbegin(); anIt != theShapes.cend(); ++anIt) {
512 aBuilder.Add(aCompound, (*anIt)->impl<TopoDS_Shape>());
514 BRepBuilderAPI_FindPlane aFindPlane(aCompound);
516 if(aFindPlane.Found() != Standard_True) {
517 return std::shared_ptr<GeomAPI_Pln>();
520 Handle(Geom_Plane) aPlane = aFindPlane.Plane();
521 gp_Pnt aLoc = aPlane->Location();
522 gp_Dir aDir = aPlane->Axis().Direction();
524 std::shared_ptr<GeomAPI_Pnt> aGeomPnt(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z()));
525 std::shared_ptr<GeomAPI_Dir> aGeomDir(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z()));
527 std::shared_ptr<GeomAPI_Pln> aPln(new GeomAPI_Pln(aGeomPnt, aGeomDir));
532 //==================================================================================================
533 bool GeomAlgoAPI_ShapeTools::isSubShapeInsideShape(const std::shared_ptr<GeomAPI_Shape> theSubShape,
534 const std::shared_ptr<GeomAPI_Shape> theBaseShape)
536 if(!theSubShape.get() || !theBaseShape.get()) {
540 const TopoDS_Shape& aSubShape = theSubShape->impl<TopoDS_Shape>();
541 const TopoDS_Shape& aBaseShape = theBaseShape->impl<TopoDS_Shape>();
543 if(aSubShape.ShapeType() == TopAbs_VERTEX) {
544 // If sub-shape is a vertex check distance to shape. If it is <= Precision::Confusion() then OK.
545 BRepExtrema_DistShapeShape aDist(aBaseShape, aSubShape);
547 if(!aDist.IsDone() || aDist.Value() > Precision::Confusion()) {
550 } else if (aSubShape.ShapeType() == TopAbs_EDGE) {
551 if(aBaseShape.ShapeType() == TopAbs_FACE) {
552 // Check that edge is on face surface.
553 TopoDS_Face aFace = TopoDS::Face(aBaseShape);
554 TopoDS_Edge anEdge = TopoDS::Edge(aSubShape);
555 BRepLib_CheckCurveOnSurface aCheck(anEdge, aFace);
557 if(!aCheck.IsDone() || aCheck.MaxDistance() > Precision::Confusion()) {
561 // Check intersections.
562 TopoDS_Vertex aV1, aV2;
563 ShapeAnalysis::FindBounds(anEdge, aV1, aV2);
564 gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
565 gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
566 for(TopExp_Explorer anExp(aBaseShape, TopAbs_EDGE); anExp.More(); anExp.Next()) {
567 const TopoDS_Shape& anEdgeOnFace = anExp.Current();
568 BRepExtrema_DistShapeShape aDist(anEdgeOnFace, anEdge);
570 if(aDist.IsDone() && aDist.Value() <= Precision::Confusion()) {
571 // Edge intersect face bound. Check that it is not on edge begin or end.
572 for(Standard_Integer anIndex = 1; anIndex <= aDist.NbSolution(); ++anIndex) {
573 gp_Pnt aPntOnSubShape = aDist.PointOnShape2(anIndex);
574 if(aPntOnSubShape.Distance(aPnt1) > Precision::Confusion()
575 && aPntOnSubShape.Distance(aPnt2) > Precision::Confusion()) {
582 // No intersections found. Edge is inside or outside face. Check it.
583 BRepAdaptor_Curve aCurveAdaptor(anEdge);
584 gp_Pnt aPointToCheck = aCurveAdaptor.Value((aCurveAdaptor.FirstParameter() + aCurveAdaptor.LastParameter()) / 2.0);
585 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace);
586 ShapeAnalysis_Surface aSAS(aSurface);
587 gp_Pnt2d aPointOnFace = aSAS.ValueOfUV(aPointToCheck, Precision::Confusion());
588 BRepTopAdaptor_FClass2d aFClass2d(aFace, Precision::Confusion());
589 if(aFClass2d.Perform(aPointOnFace) == TopAbs_OUT) {