1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #include <Bnd_Box.hxx>
17 #include <BRep_Tool.hxx>
18 #include <BRepAdaptor_Surface.hxx>
19 #include <BRepBndLib.hxx>
20 #include <BRepClass3d_SolidClassifier.hxx>
21 #include <Extrema_LocateExtPC.hxx>
22 #include <Geom2d_Curve.hxx>
23 #include <Geom2d_TrimmedCurve.hxx>
24 #include <Geom2dHatch_Hatcher.hxx>
25 #include <Geom2dHatch_Intersector.hxx>
26 #include <Geom_BoundedCurve.hxx>
27 #include <Geom_Curve.hxx>
28 #include <GeomAdaptor_Curve.hxx>
29 #include <GeomAPI_ProjectPointOnCurve.hxx>
30 #include <GeomAPI_ProjectPointOnSurf.hxx>
32 #include <gp_Pnt2d.hxx>
33 #include <IntTools_Context.hxx>
34 #include <IntTools_Curve.hxx>
35 #include <IntTools_FClass2d.hxx>
36 #include <IntTools_SurfaceRangeLocalizeData.hxx>
37 #include <IntTools_Tools.hxx>
38 #include <Precision.hxx>
39 #include <Standard_Type.hxx>
40 #include <TopAbs_State.hxx>
41 #include <TopExp_Explorer.hxx>
43 #include <TopoDS_Edge.hxx>
44 #include <TopoDS_Face.hxx>
45 #include <TopoDS_Shape.hxx>
46 #include <TopoDS_Solid.hxx>
47 #include <TopoDS_Vertex.hxx>
49 IMPLEMENT_STANDARD_RTTIEXT(IntTools_Context,Standard_Transient)
52 //=======================================================================
55 //=======================================================================
56 IntTools_Context::IntTools_Context()
58 myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
59 myFClass2dMap(100, myAllocator),
60 myProjPSMap(100, myAllocator),
61 myProjPCMap(100, myAllocator),
62 mySClassMap(100, myAllocator),
63 myProjPTMap(100, myAllocator),
64 myHatcherMap(100, myAllocator),
65 myProjSDataMap(100, myAllocator),
66 myBndBoxDataMap(100, myAllocator),
67 mySurfAdaptorMap(100, myAllocator),
69 myPOnSTolerance(1.e-12)
72 //=======================================================================
75 //=======================================================================
76 IntTools_Context::IntTools_Context
77 (const Handle(NCollection_BaseAllocator)& theAllocator)
79 myAllocator(theAllocator),
80 myFClass2dMap(100, myAllocator),
81 myProjPSMap(100, myAllocator),
82 myProjPCMap(100, myAllocator),
83 mySClassMap(100, myAllocator),
84 myProjPTMap(100, myAllocator),
85 myHatcherMap(100, myAllocator),
86 myProjSDataMap(100, myAllocator),
87 myBndBoxDataMap(100, myAllocator),
88 mySurfAdaptorMap(100, myAllocator),
90 myPOnSTolerance(1.e-12)
93 //=======================================================================
96 //=======================================================================
97 IntTools_Context::~IntTools_Context()
99 Standard_Address anAdr;
100 BOPCol_DataMapIteratorOfDataMapOfShapeAddress aIt;
101 BOPCol_DataMapIteratorOfDataMapOfTransientAddress aIt1;
103 IntTools_FClass2d* pFClass2d;
105 aIt.Initialize(myFClass2dMap);
106 for (; aIt.More(); aIt.Next()) {
108 pFClass2d=(IntTools_FClass2d*)anAdr;
109 (*pFClass2d).~IntTools_FClass2d();
110 myAllocator->Free(anAdr);
112 myFClass2dMap.Clear();
114 clearCachedPOnSProjectors();
116 GeomAPI_ProjectPointOnCurve* pProjPC;
117 aIt.Initialize(myProjPCMap);
118 for (; aIt.More(); aIt.Next()) {
120 pProjPC=(GeomAPI_ProjectPointOnCurve*)anAdr;
121 (*pProjPC).~GeomAPI_ProjectPointOnCurve();
122 myAllocator->Free(anAdr);
127 BRepClass3d_SolidClassifier* pSC;
128 aIt.Initialize(mySClassMap);
129 for (; aIt.More(); aIt.Next()) {
131 pSC=(BRepClass3d_SolidClassifier*)anAdr;
132 (*pSC).~BRepClass3d_SolidClassifier();
133 myAllocator->Free(anAdr);
137 GeomAPI_ProjectPointOnCurve* pProjPT;
138 aIt1.Initialize(myProjPTMap);
139 for (; aIt1.More(); aIt1.Next()) {
141 pProjPT=(GeomAPI_ProjectPointOnCurve*)anAdr;
142 (*pProjPT).~GeomAPI_ProjectPointOnCurve();
143 myAllocator->Free(anAdr);
147 Geom2dHatch_Hatcher* pHatcher;
148 aIt.Initialize(myHatcherMap);
149 for (; aIt.More(); aIt.Next()) {
151 pHatcher=(Geom2dHatch_Hatcher*)anAdr;
152 (*pHatcher).~Geom2dHatch_Hatcher();
153 myAllocator->Free(anAdr);
155 myHatcherMap.Clear();
157 IntTools_SurfaceRangeLocalizeData* pSData = NULL;
158 aIt.Initialize(myProjSDataMap);
159 for (; aIt.More(); aIt.Next()) {
161 pSData = (IntTools_SurfaceRangeLocalizeData*)anAdr;
162 (*pSData).~IntTools_SurfaceRangeLocalizeData();
163 myAllocator->Free(anAdr);
165 myProjSDataMap.Clear();
168 aIt.Initialize(myBndBoxDataMap);
169 for (; aIt.More(); aIt.Next()) {
171 pBox=(Bnd_Box*)anAdr;
173 myAllocator->Free(anAdr);
175 myBndBoxDataMap.Clear();
177 BRepAdaptor_Surface* pSurfAdaptor;
178 aIt.Initialize(mySurfAdaptorMap);
179 for (; aIt.More(); aIt.Next()) {
181 pSurfAdaptor=(BRepAdaptor_Surface*)anAdr;
182 (*pSurfAdaptor).~BRepAdaptor_Surface();
183 myAllocator->Free(anAdr);
185 mySurfAdaptorMap.Clear();
187 //=======================================================================
190 //=======================================================================
191 Bnd_Box& IntTools_Context::BndBox(const TopoDS_Shape& aS)
193 Standard_Address anAdr;
196 if (!myBndBoxDataMap.IsBound(aS)) {
198 pBox=(Bnd_Box*)myAllocator->Allocate(sizeof(Bnd_Box));
199 new (pBox) Bnd_Box();
202 BRepBndLib::Add(aS, aBox);
204 anAdr=(Standard_Address)pBox;
205 myBndBoxDataMap.Bind(aS, anAdr);
208 anAdr=myBndBoxDataMap.Find(aS);
209 pBox=(Bnd_Box*)anAdr;
213 //=======================================================================
214 //function : IsInfiniteFace
216 //=======================================================================
217 Standard_Boolean IntTools_Context::IsInfiniteFace
218 (const TopoDS_Face& aFace)
220 Standard_Boolean bRet;
226 if (!BRep_Tool::NaturalRestriction(aFace)) {
230 Bnd_Box& aBox=BndBox(aFace);
232 aBox.Get(aX[0], aX[1], aX[2], aX[3], aX[4], aX[5]);
234 for (i=0; (i<6) && (!bRet); ++i) {
235 bRet=Precision::IsInfinite(aX[i]);
240 //=======================================================================
241 //function : FClass2d
243 //=======================================================================
244 IntTools_FClass2d& IntTools_Context::FClass2d(const TopoDS_Face& aF)
246 Standard_Address anAdr;
247 IntTools_FClass2d* pFClass2d;
249 if (!myFClass2dMap.IsBound(aF)) {
254 aFF.Orientation(TopAbs_FORWARD);
255 aTolF=BRep_Tool::Tolerance(aFF);
257 pFClass2d=(IntTools_FClass2d*)myAllocator->Allocate(sizeof(IntTools_FClass2d));
258 new (pFClass2d) IntTools_FClass2d(aFF, aTolF);
260 anAdr=(Standard_Address)pFClass2d;
261 myFClass2dMap.Bind(aFF, anAdr);
264 anAdr=myFClass2dMap.Find(aF);
265 pFClass2d=(IntTools_FClass2d*)anAdr;
269 //=======================================================================
272 //=======================================================================
273 GeomAPI_ProjectPointOnSurf& IntTools_Context::ProjPS(const TopoDS_Face& aF)
275 Standard_Address anAdr;
276 GeomAPI_ProjectPointOnSurf* pProjPS;
278 if (!myProjPSMap.IsBound(aF)) {
279 Standard_Real Umin, Usup, Vmin, Vsup;
280 UVBounds(aF, Umin, Usup, Vmin, Vsup);
281 const Handle(Geom_Surface)& aS=BRep_Tool::Surface(aF);
283 pProjPS=(GeomAPI_ProjectPointOnSurf*)myAllocator->Allocate(sizeof(GeomAPI_ProjectPointOnSurf));
284 new (pProjPS) GeomAPI_ProjectPointOnSurf();
285 pProjPS->Init(aS ,Umin, Usup, Vmin, Vsup, myPOnSTolerance/*, Extrema_ExtAlgo_Tree*/);
286 Extrema_ExtPS& anExtAlgo = const_cast<Extrema_ExtPS&>(pProjPS->Extrema());
287 anExtAlgo.SetFlag(Extrema_ExtFlag_MIN);
289 anAdr=(Standard_Address)pProjPS;
290 myProjPSMap.Bind(aF, anAdr);
294 anAdr=myProjPSMap.Find(aF);
295 pProjPS=(GeomAPI_ProjectPointOnSurf*)anAdr;
299 //=======================================================================
302 //=======================================================================
303 GeomAPI_ProjectPointOnCurve& IntTools_Context::ProjPC(const TopoDS_Edge& aE)
305 Standard_Address anAdr;
306 GeomAPI_ProjectPointOnCurve* pProjPC;
308 if (!myProjPCMap.IsBound(aE)) {
311 Handle(Geom_Curve)aC3D=BRep_Tool::Curve (aE, f, l);
313 pProjPC=(GeomAPI_ProjectPointOnCurve*)myAllocator->Allocate(sizeof(GeomAPI_ProjectPointOnCurve));
314 new (pProjPC) GeomAPI_ProjectPointOnCurve();
315 pProjPC->Init(aC3D, f, l);
317 anAdr=(Standard_Address)pProjPC;
318 myProjPCMap.Bind(aE, anAdr);
322 anAdr=myProjPCMap.Find(aE);
323 pProjPC=(GeomAPI_ProjectPointOnCurve*)anAdr;
328 //=======================================================================
331 //=======================================================================
332 GeomAPI_ProjectPointOnCurve& IntTools_Context::ProjPT
333 (const Handle(Geom_Curve)& aC3D)
336 Standard_Address anAdr;
337 GeomAPI_ProjectPointOnCurve* pProjPT;
339 if (!myProjPTMap.IsBound(aC3D)) {
341 f=aC3D->FirstParameter();
342 l=aC3D->LastParameter();
344 pProjPT=(GeomAPI_ProjectPointOnCurve*)myAllocator->Allocate(sizeof(GeomAPI_ProjectPointOnCurve));
345 new (pProjPT) GeomAPI_ProjectPointOnCurve();
346 pProjPT->Init(aC3D, f, l);
348 anAdr=(Standard_Address)pProjPT;
349 myProjPTMap.Bind(aC3D, anAdr);
353 anAdr=myProjPTMap.Find(aC3D);
354 pProjPT=(GeomAPI_ProjectPointOnCurve*)anAdr;
358 //=======================================================================
359 //function : SolidClassifier
361 //=======================================================================
362 BRepClass3d_SolidClassifier& IntTools_Context::SolidClassifier
363 (const TopoDS_Solid& aSolid)
365 Standard_Address anAdr;
366 BRepClass3d_SolidClassifier* pSC;
368 if (!mySClassMap.IsBound(aSolid)) {
370 pSC=(BRepClass3d_SolidClassifier*)myAllocator->Allocate(sizeof(BRepClass3d_SolidClassifier));
371 new (pSC) BRepClass3d_SolidClassifier(aSolid);
373 anAdr=(Standard_Address)pSC;
374 mySClassMap.Bind(aSolid, anAdr);
378 anAdr=mySClassMap.Find(aSolid);
379 pSC =(BRepClass3d_SolidClassifier*)anAdr;
384 //=======================================================================
385 //function : SurfaceAdaptor
387 //=======================================================================
388 BRepAdaptor_Surface& IntTools_Context::SurfaceAdaptor
389 (const TopoDS_Face& theFace)
391 Standard_Address anAdr;
392 BRepAdaptor_Surface* pBAS;
394 if (!mySurfAdaptorMap.IsBound(theFace)) {
396 pBAS=(BRepAdaptor_Surface*)myAllocator->Allocate(sizeof(BRepAdaptor_Surface));
397 new (pBAS) BRepAdaptor_Surface(theFace, Standard_True);
399 anAdr=(Standard_Address)pBAS;
400 mySurfAdaptorMap.Bind(theFace, anAdr);
404 anAdr=mySurfAdaptorMap.Find(theFace);
405 pBAS =(BRepAdaptor_Surface*)anAdr;
410 //=======================================================================
413 //=======================================================================
414 Geom2dHatch_Hatcher& IntTools_Context::Hatcher(const TopoDS_Face& aF)
416 Standard_Address anAdr;
417 Geom2dHatch_Hatcher* pHatcher;
419 if (!myHatcherMap.IsBound(aF)) {
420 Standard_Real aTolArcIntr, aTolTangfIntr, aTolHatch2D, aTolHatch3D;
421 Standard_Real aU1, aU2, aEpsT;
422 TopAbs_Orientation aOrE;
423 Handle(Geom_Surface) aS;
424 Handle(Geom2d_Curve) aC2D;
425 Handle(Geom2d_TrimmedCurve) aCT2D;
427 TopExp_Explorer aExp;
432 aTolTangfIntr=1.e-10;
433 aEpsT=Precision::PConfusion();
435 Geom2dHatch_Intersector aIntr(aTolArcIntr, aTolTangfIntr);
436 pHatcher=(Geom2dHatch_Hatcher*)
437 myAllocator->Allocate(sizeof(Geom2dHatch_Hatcher));
438 new (pHatcher) Geom2dHatch_Hatcher(aIntr,
439 aTolHatch2D, aTolHatch3D,
440 Standard_True, Standard_False);
443 aFF.Orientation(TopAbs_FORWARD);
444 aS=BRep_Tool::Surface(aFF);
446 aExp.Init (aFF, TopAbs_EDGE);
447 for (; aExp.More() ; aExp.Next()) {
448 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aExp.Current());
449 aOrE=aE.Orientation();
451 aC2D=BRep_Tool::CurveOnSurface (aE, aFF, aU1, aU2);
452 if (aC2D.IsNull() ) {
455 if (fabs(aU1-aU2) < aEpsT) {
459 aCT2D=new Geom2d_TrimmedCurve(aC2D, aU1, aU2);
460 Geom2dAdaptor_Curve aGAC (aCT2D);
461 pHatcher->AddElement(aGAC, aOrE);
462 }// for (; aExp.More() ; aExp.Next()) {
464 anAdr=(Standard_Address)pHatcher;
465 myHatcherMap.Bind(aFF, anAdr);
466 }//if (!myHatcherMap.IsBound(aF)) {
469 anAdr=myHatcherMap.Find(aF);
470 pHatcher=(Geom2dHatch_Hatcher*)anAdr;
476 //=======================================================================
477 //function : SurfaceData
479 //=======================================================================
480 IntTools_SurfaceRangeLocalizeData& IntTools_Context::SurfaceData
481 (const TopoDS_Face& aF)
483 Standard_Address anAdr;
484 IntTools_SurfaceRangeLocalizeData* pSData;
486 if (!myProjSDataMap.IsBound(aF)) {
487 pSData=(IntTools_SurfaceRangeLocalizeData*)
488 myAllocator->Allocate(sizeof(IntTools_SurfaceRangeLocalizeData));
489 new (pSData) IntTools_SurfaceRangeLocalizeData
492 10. * Precision::PConfusion(),
493 10. * Precision::PConfusion());
495 anAdr=(Standard_Address)pSData;
496 myProjSDataMap.Bind(aF, anAdr);
500 anAdr=myProjSDataMap.Find(aF);
501 pSData=(IntTools_SurfaceRangeLocalizeData*)anAdr;
507 //=======================================================================
508 //function : ComputePE
510 //=======================================================================
511 Standard_Integer IntTools_Context::ComputePE
513 const Standard_Real aTolP1,
514 const TopoDS_Edge& aE2,
516 Standard_Real& aDist)
518 if (!BRep_Tool::IsGeometric(aE2)) {
521 Standard_Real aTolE2, aTolSum;
522 Standard_Integer aNbProj;
524 GeomAPI_ProjectPointOnCurve& aProjector=ProjPC(aE2);
525 aProjector.Perform(aP1);
527 aNbProj=aProjector.NbPoints();
530 // point falls on the curve
531 aDist = aProjector.LowerDistance();
533 aTolE2 = BRep_Tool::Tolerance(aE2);
534 aTolSum = aTolP1 + aTolE2 + Precision::Confusion();
536 aT = aProjector.LowerDistanceParameter();
537 if (aDist > aTolSum) {
543 // point falls out of the curve, check distance to vertices
544 TopoDS_Edge aEFwd = TopoDS::Edge(aE2.Oriented(TopAbs_FORWARD));
545 TopoDS_Iterator itV(aEFwd);
547 for (; itV.More(); itV.Next())
549 const TopoDS_Vertex& aV = TopoDS::Vertex(itV.Value());
550 if (aV.Orientation() == TopAbs_FORWARD || aV.Orientation() == TopAbs_REVERSED)
552 gp_Pnt aPV = BRep_Tool::Pnt(aV);
553 aTolSum = aTolP1 + BRep_Tool::Tolerance(aV) + Precision::Confusion();
554 Standard_Real aDist1 = aP1.SquareDistance(aPV);
555 if (aDist1 < aDist && aDist1 < Square(aTolSum))
558 aT = BRep_Tool::Parameter(aV, aEFwd);
562 if (Precision::IsInfinite(aDist)) {
568 //=======================================================================
569 //function : ComputeVE
571 //=======================================================================
572 Standard_Integer IntTools_Context::ComputeVE
573 (const TopoDS_Vertex& theV,
574 const TopoDS_Edge& theE,
576 Standard_Real& theTol,
577 const Standard_Real theFuzz)
579 if (BRep_Tool::Degenerated(theE)) {
582 if (!BRep_Tool::IsGeometric(theE)) {
585 Standard_Real aDist, aTolV, aTolE, aTolSum;
586 Standard_Integer aNbProj;
589 aP=BRep_Tool::Pnt(theV);
591 GeomAPI_ProjectPointOnCurve& aProjector=ProjPC(theE);
592 aProjector.Perform(aP);
594 aNbProj=aProjector.NbPoints();
599 aDist=aProjector.LowerDistance();
601 aTolV=BRep_Tool::Tolerance(theV);
602 aTolE=BRep_Tool::Tolerance(theE);
603 aTolSum = aTolV + aTolE + Max(theFuzz, Precision::Confusion());
605 theTol = aDist + aTolE;
606 theT = aProjector.LowerDistanceParameter();
607 if (aDist > aTolSum) {
612 //=======================================================================
613 //function : ComputeVF
615 //=======================================================================
616 Standard_Integer IntTools_Context::ComputeVF
617 (const TopoDS_Vertex& theVertex,
618 const TopoDS_Face& theFace,
621 Standard_Real& theTol,
622 const Standard_Real theFuzz)
624 Standard_Real aTolV, aTolF, aTolSum, aDist;
627 aP = BRep_Tool::Pnt(theVertex);
629 // 1. Check if the point is projectable on the surface
630 GeomAPI_ProjectPointOnSurf& aProjector=ProjPS(theFace);
631 aProjector.Perform(aP);
633 if (!aProjector.IsDone()) { // the point is not projectable on the surface
637 // 2. Check the distance between the projection point and
638 // the original point
639 aDist = aProjector.LowerDistance();
641 aTolV = BRep_Tool::Tolerance(theVertex);
642 aTolF = BRep_Tool::Tolerance(theFace);
644 aTolSum = aTolV + aTolF + Max(theFuzz, Precision::Confusion());
645 theTol = aDist + aTolF;
646 aProjector.LowerDistanceParameters(theU, theV);
648 if (aDist > aTolSum) {
649 // the distance is too large
653 gp_Pnt2d aP2d(theU, theV);
654 Standard_Boolean pri = IsPointInFace (theFace, aP2d);
655 if (!pri) {// the point lays on the surface but out of the face
660 //=======================================================================
661 //function : StatePointFace
663 //=======================================================================
664 TopAbs_State IntTools_Context::StatePointFace
665 (const TopoDS_Face& aF,
666 const gp_Pnt2d& aP2d)
669 IntTools_FClass2d& aClass2d=FClass2d(aF);
670 aState=aClass2d.Perform(aP2d);
673 //=======================================================================
674 //function : IsPointInFace
676 //=======================================================================
677 Standard_Boolean IntTools_Context::IsPointInFace
678 (const TopoDS_Face& aF,
679 const gp_Pnt2d& aP2d)
681 TopAbs_State aState=StatePointFace(aF, aP2d);
682 if (aState==TopAbs_OUT || aState==TopAbs_ON) {
683 return Standard_False;
685 return Standard_True;
687 //=======================================================================
688 //function : IsPointInFace
690 //=======================================================================
691 Standard_Boolean IntTools_Context::IsPointInFace
693 const TopoDS_Face& aF,
694 const Standard_Real aTol)
696 Standard_Boolean bIn;
699 GeomAPI_ProjectPointOnSurf& aProjector=ProjPS(aF);
700 aProjector.Perform(aP);
702 bIn = aProjector.IsDone();
704 aDist = aProjector.LowerDistance();
708 aProjector.LowerDistanceParameters(U, V);
710 bIn = IsPointInFace(aF, aP2D);
716 //=======================================================================
717 //function : IsPointInOnFace
719 //=======================================================================
720 Standard_Boolean IntTools_Context::IsPointInOnFace(const TopoDS_Face& aF,
721 const gp_Pnt2d& aP2d)
723 TopAbs_State aState=StatePointFace(aF, aP2d);
724 if (aState==TopAbs_OUT) {
725 return Standard_False;
727 return Standard_True;
729 //=======================================================================
730 //function : IsValidPointForFace
732 //=======================================================================
733 Standard_Boolean IntTools_Context::IsValidPointForFace
735 const TopoDS_Face& aF,
736 const Standard_Real aTol)
738 Standard_Boolean bFlag;
739 Standard_Real Umin, U, V;
741 GeomAPI_ProjectPointOnSurf& aProjector=ProjPS(aF);
742 aProjector.Perform(aP);
744 bFlag=aProjector.IsDone();
747 Umin=aProjector.LowerDistance();
748 //if (Umin > 1.e-3) { // it was
753 aProjector.LowerDistanceParameters(U, V);
755 bFlag=IsPointInOnFace (aF, aP2D);
759 //=======================================================================
760 //function : IsValidPointForFaces
762 //=======================================================================
763 Standard_Boolean IntTools_Context::IsValidPointForFaces
765 const TopoDS_Face& aF1,
766 const TopoDS_Face& aF2,
767 const Standard_Real aTol)
769 Standard_Boolean bFlag1, bFlag2;
771 bFlag1=IsValidPointForFace(aP, aF1, aTol);
775 bFlag2=IsValidPointForFace(aP, aF2, aTol);
778 //=======================================================================
779 //function : IsValidBlockForFace
781 //=======================================================================
782 Standard_Boolean IntTools_Context::IsValidBlockForFace
783 (const Standard_Real aT1,
784 const Standard_Real aT2,
785 const IntTools_Curve& aC,
786 const TopoDS_Face& aF,
787 const Standard_Real aTol)
789 Standard_Boolean bFlag;
790 Standard_Real aTInterm;
793 aTInterm=IntTools_Tools::IntermediatePoint(aT1, aT2);
795 Handle(Geom_Curve) aC3D=aC.Curve();
797 aC3D->D0(aTInterm, aPInterm);
799 bFlag=IsValidPointForFace (aPInterm, aF, aTol);
802 //=======================================================================
803 //function : IsValidBlockForFaces
805 //=======================================================================
806 Standard_Boolean IntTools_Context::IsValidBlockForFaces
807 (const Standard_Real aT1,
808 const Standard_Real aT2,
809 const IntTools_Curve& aC,
810 const TopoDS_Face& aF1,
811 const TopoDS_Face& aF2,
812 const Standard_Real aTol)
814 Standard_Boolean bFlag1, bFlag2;
816 Handle(Geom2d_Curve) aPC1 = aC.FirstCurve2d();
817 Handle(Geom2d_Curve) aPC2 = aC.SecondCurve2d();
818 if( !aPC1.IsNull() && !aPC2.IsNull() ) {
819 Standard_Real aMidPar = IntTools_Tools::IntermediatePoint(aT1, aT2);
823 aPC1->D0(aMidPar, aPnt2D);
824 bFlag1 = IsPointInOnFace(aF1, aPnt2D);
829 aPC2->D0(aMidPar, aPnt2D);
830 bFlag2 = IsPointInOnFace(aF2, aPnt2D);
835 bFlag1=IsValidBlockForFace (aT1, aT2, aC, aF1, aTol);
839 bFlag2=IsValidBlockForFace (aT1, aT2, aC, aF2, aTol);
842 //=======================================================================
843 //function : IsVertexOnLine
845 //=======================================================================
846 Standard_Boolean IntTools_Context::IsVertexOnLine
847 (const TopoDS_Vertex& aV,
848 const IntTools_Curve& aC,
849 const Standard_Real aTolC,
852 Standard_Boolean bRet;
855 aTolV=BRep_Tool::Tolerance(aV);
856 bRet=IntTools_Context::IsVertexOnLine(aV, aTolV, aC, aTolC , aT);
860 //=======================================================================
861 //function : IsVertexOnLine
863 //=======================================================================
864 Standard_Boolean IntTools_Context::IsVertexOnLine
865 (const TopoDS_Vertex& aV,
866 const Standard_Real aTolV,
867 const IntTools_Curve& aC,
868 const Standard_Real aTolC,
871 Standard_Real aFirst, aLast, aDist, aTolSum;
872 Standard_Integer aNbProj;
875 aPv=BRep_Tool::Pnt(aV);
877 Handle(Geom_Curve) aC3D=aC.Curve();
882 GeomAdaptor_Curve aGAC(aC3D);
883 GeomAbs_CurveType aType=aGAC.GetType();
884 if (aType==GeomAbs_BSplineCurve ||
885 aType==GeomAbs_BezierCurve) {
892 aTolSum=2.*aTolSum;//xft
897 aFirst=aC3D->FirstParameter();
898 aLast =aC3D->LastParameter();
900 // Checking extermities first
901 // It is necessary to chose the closest bound to the point
902 Standard_Boolean bFirstValid = Standard_False;
903 Standard_Real aFirstDist = Precision::Infinite();
905 if (!Precision::IsInfinite(aFirst)) {
906 gp_Pnt aPCFirst=aC3D->Value(aFirst);
907 aFirstDist = aPv.Distance(aPCFirst);
908 if (aFirstDist < aTolSum) {
909 bFirstValid = Standard_True;
912 if (aFirstDist > aTolV) {
913 Extrema_LocateExtPC anExt(aPv, aGAC, aFirst, 1.e-10);
916 Extrema_POnCurv aPOncurve = anExt.Point();
917 aT = aPOncurve.Parameter();
919 if((aT > (aLast + aFirst) * 0.5) ||
920 (aPv.Distance(aPOncurve.Value()) > aTolSum) ||
921 (aPCFirst.Distance(aPOncurve.Value()) < Precision::Confusion()))
926 // Local search may fail. Try to use more precise algo.
927 Extrema_ExtPC anExt2(aPv, aGAC, 1.e-10);
928 Standard_Real aMinDist = RealLast();
929 Standard_Integer aMinIdx = -1;
930 if (anExt2.IsDone()) {
931 for (Standard_Integer anIdx = 1; anIdx <= anExt2.NbExt(); anIdx++)
933 if ( anExt2.IsMin(anIdx) &&
934 anExt2.SquareDistance(anIdx) < aMinDist )
936 aMinDist = anExt2.SquareDistance(anIdx);
943 const Extrema_POnCurv& aPOncurve = anExt2.Point(aMinIdx);
944 aT = aPOncurve.Parameter();
946 if((aT > (aLast + aFirst) * 0.5) ||
947 (aPv.Distance(aPOncurve.Value()) > aTolSum) ||
948 (aPCFirst.Distance(aPOncurve.Value()) < Precision::Confusion()))
957 if (!Precision::IsInfinite(aLast)) {
958 gp_Pnt aPCLast=aC3D->Value(aLast);
959 aDist=aPv.Distance(aPCLast);
960 if (bFirstValid && (aFirstDist < aDist)) {
961 return Standard_True;
964 if (aDist < aTolSum) {
968 Extrema_LocateExtPC anExt(aPv, aGAC, aLast, 1.e-10);
971 Extrema_POnCurv aPOncurve = anExt.Point();
972 aT = aPOncurve.Parameter();
974 if((aT < (aLast + aFirst) * 0.5) ||
975 (aPv.Distance(aPOncurve.Value()) > aTolSum) ||
976 (aPCLast.Distance(aPOncurve.Value()) < Precision::Confusion()))
981 // Local search may fail. Try to use more precise algo.
982 Extrema_ExtPC anExt2(aPv, aGAC, 1.e-10);
983 Standard_Real aMinDist = RealLast();
984 Standard_Integer aMinIdx = -1;
985 if (anExt2.IsDone()) {
986 for (Standard_Integer anIdx = 1; anIdx <= anExt2.NbExt(); anIdx++)
988 if ( anExt2.IsMin(anIdx) &&
989 anExt2.SquareDistance(anIdx) < aMinDist )
991 aMinDist = anExt2.SquareDistance(anIdx);
998 const Extrema_POnCurv& aPOncurve = anExt2.Point(aMinIdx);
999 aT = aPOncurve.Parameter();
1001 if((aT < (aLast + aFirst) * 0.5) ||
1002 (aPv.Distance(aPOncurve.Value()) > aTolSum) ||
1003 (aPCLast.Distance(aPOncurve.Value()) < Precision::Confusion()))
1009 return Standard_True;
1012 else if (bFirstValid) {
1013 return Standard_True;
1016 GeomAPI_ProjectPointOnCurve& aProjector=ProjPT(aC3D);
1017 aProjector.Perform(aPv);
1019 aNbProj=aProjector.NbPoints();
1021 Handle(Geom_BoundedCurve) aBC=
1022 Handle(Geom_BoundedCurve)::DownCast(aC3D);
1023 if (!aBC.IsNull()) {
1024 gp_Pnt aPStart=aBC->StartPoint();
1025 gp_Pnt aPEnd =aBC->EndPoint();
1027 aDist=aPv.Distance(aPStart);
1028 if (aDist < aTolSum) {
1030 return Standard_True;
1033 aDist=aPv.Distance(aPEnd);
1034 if (aDist < aTolSum) {
1036 return Standard_True;
1040 return Standard_False;
1043 aDist=aProjector.LowerDistance();
1045 if (aDist > aTolSum) {
1046 return Standard_False;
1049 aT=aProjector.LowerDistanceParameter();
1051 return Standard_True;
1053 //=======================================================================
1054 //function : ProjectPointOnEdge
1056 //=======================================================================
1057 Standard_Boolean IntTools_Context::ProjectPointOnEdge
1059 const TopoDS_Edge& anEdge,
1062 Standard_Integer aNbPoints;
1064 GeomAPI_ProjectPointOnCurve& aProjector=ProjPC(anEdge);
1065 aProjector.Perform(aP);
1067 aNbPoints=aProjector.NbPoints();
1069 aT=aProjector.LowerDistanceParameter();
1070 return Standard_True;
1072 return Standard_False;
1075 //=======================================================================
1076 //function : SetPOnSProjectionTolerance
1078 //=======================================================================
1079 void IntTools_Context::SetPOnSProjectionTolerance(const Standard_Real theValue)
1081 myPOnSTolerance = theValue;
1082 clearCachedPOnSProjectors();
1085 //=======================================================================
1086 //function : clearCachedPOnSProjectors
1088 //=======================================================================
1089 void IntTools_Context::clearCachedPOnSProjectors()
1091 GeomAPI_ProjectPointOnSurf* pProjPS;
1092 BOPCol_DataMapIteratorOfDataMapOfShapeAddress aIt(myProjPSMap);
1093 for (; aIt.More(); aIt.Next()) {
1094 Standard_Address anAdr=aIt.Value();
1095 pProjPS=(GeomAPI_ProjectPointOnSurf*)anAdr;
1096 (*pProjPS).~GeomAPI_ProjectPointOnSurf();
1097 myAllocator->Free(anAdr);
1099 myProjPSMap.Clear();
1102 //=======================================================================
1103 //function : UVBounds
1105 //=======================================================================
1106 void IntTools_Context::UVBounds(const TopoDS_Face& theFace,
1107 Standard_Real& UMin,
1108 Standard_Real& UMax,
1109 Standard_Real& VMin,
1110 Standard_Real& VMax)
1112 const BRepAdaptor_Surface& aBAS = SurfaceAdaptor(theFace);
1113 UMin = aBAS.FirstUParameter();
1114 UMax = aBAS.LastUParameter ();
1115 VMin = aBAS.FirstVParameter();
1116 VMax = aBAS.LastVParameter ();