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,MMgt_TShared)
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),
68 myPOnSTolerance(1.e-12)
71 //=======================================================================
74 //=======================================================================
75 IntTools_Context::IntTools_Context
76 (const Handle(NCollection_BaseAllocator)& theAllocator)
78 myAllocator(theAllocator),
79 myFClass2dMap(100, myAllocator),
80 myProjPSMap(100, myAllocator),
81 myProjPCMap(100, myAllocator),
82 mySClassMap(100, myAllocator),
83 myProjPTMap(100, myAllocator),
84 myHatcherMap(100, myAllocator),
85 myProjSDataMap(100, myAllocator),
86 myBndBoxDataMap(100, myAllocator),
88 myPOnSTolerance(1.e-12)
91 //=======================================================================
94 //=======================================================================
95 IntTools_Context::~IntTools_Context()
97 Standard_Address anAdr;
98 BOPCol_DataMapIteratorOfDataMapOfShapeAddress aIt;
99 BOPCol_DataMapIteratorOfDataMapOfTransientAddress aIt1;
101 IntTools_FClass2d* pFClass2d;
103 aIt.Initialize(myFClass2dMap);
104 for (; aIt.More(); aIt.Next()) {
106 pFClass2d=(IntTools_FClass2d*)anAdr;
107 (*pFClass2d).~IntTools_FClass2d();
108 myAllocator->Free(anAdr);
110 myFClass2dMap.Clear();
112 clearCachedPOnSProjectors();
114 GeomAPI_ProjectPointOnCurve* pProjPC;
115 aIt.Initialize(myProjPCMap);
116 for (; aIt.More(); aIt.Next()) {
118 pProjPC=(GeomAPI_ProjectPointOnCurve*)anAdr;
119 (*pProjPC).~GeomAPI_ProjectPointOnCurve();
120 myAllocator->Free(anAdr);
125 BRepClass3d_SolidClassifier* pSC;
126 aIt.Initialize(mySClassMap);
127 for (; aIt.More(); aIt.Next()) {
129 pSC=(BRepClass3d_SolidClassifier*)anAdr;
130 (*pSC).~BRepClass3d_SolidClassifier();
131 myAllocator->Free(anAdr);
135 GeomAPI_ProjectPointOnCurve* pProjPT;
136 aIt1.Initialize(myProjPTMap);
137 for (; aIt1.More(); aIt1.Next()) {
139 pProjPT=(GeomAPI_ProjectPointOnCurve*)anAdr;
140 (*pProjPT).~GeomAPI_ProjectPointOnCurve();
141 myAllocator->Free(anAdr);
145 Geom2dHatch_Hatcher* pHatcher;
146 aIt.Initialize(myHatcherMap);
147 for (; aIt.More(); aIt.Next()) {
149 pHatcher=(Geom2dHatch_Hatcher*)anAdr;
150 (*pHatcher).~Geom2dHatch_Hatcher();
151 myAllocator->Free(anAdr);
153 myHatcherMap.Clear();
155 IntTools_SurfaceRangeLocalizeData* pSData = NULL;
156 aIt.Initialize(myProjSDataMap);
157 for (; aIt.More(); aIt.Next()) {
159 pSData = (IntTools_SurfaceRangeLocalizeData*)anAdr;
160 (*pSData).~IntTools_SurfaceRangeLocalizeData();
161 myAllocator->Free(anAdr);
163 myProjSDataMap.Clear();
166 aIt.Initialize(myBndBoxDataMap);
167 for (; aIt.More(); aIt.Next()) {
169 pBox=(Bnd_Box*)anAdr;
171 myAllocator->Free(anAdr);
173 myBndBoxDataMap.Clear();
175 //=======================================================================
178 //=======================================================================
179 Bnd_Box& IntTools_Context::BndBox(const TopoDS_Shape& aS)
181 Standard_Address anAdr;
184 if (!myBndBoxDataMap.IsBound(aS)) {
186 pBox=(Bnd_Box*)myAllocator->Allocate(sizeof(Bnd_Box));
187 new (pBox) Bnd_Box();
190 BRepBndLib::Add(aS, aBox);
192 anAdr=(Standard_Address)pBox;
193 myBndBoxDataMap.Bind(aS, anAdr);
196 anAdr=myBndBoxDataMap.Find(aS);
197 pBox=(Bnd_Box*)anAdr;
201 //=======================================================================
202 //function : IsInfiniteFace
204 //=======================================================================
205 Standard_Boolean IntTools_Context::IsInfiniteFace
206 (const TopoDS_Face& aFace)
208 Standard_Boolean bRet;
214 if (!BRep_Tool::NaturalRestriction(aFace)) {
218 Bnd_Box& aBox=BndBox(aFace);
220 aBox.Get(aX[0], aX[1], aX[2], aX[3], aX[4], aX[5]);
222 for (i=0; (i<6) && (!bRet); ++i) {
223 bRet=Precision::IsInfinite(aX[i]);
228 //=======================================================================
229 //function : FClass2d
231 //=======================================================================
232 IntTools_FClass2d& IntTools_Context::FClass2d(const TopoDS_Face& aF)
234 Standard_Address anAdr;
235 IntTools_FClass2d* pFClass2d;
237 if (!myFClass2dMap.IsBound(aF)) {
242 aFF.Orientation(TopAbs_FORWARD);
243 aTolF=BRep_Tool::Tolerance(aFF);
245 pFClass2d=(IntTools_FClass2d*)myAllocator->Allocate(sizeof(IntTools_FClass2d));
246 new (pFClass2d) IntTools_FClass2d(aFF, aTolF);
248 anAdr=(Standard_Address)pFClass2d;
249 myFClass2dMap.Bind(aFF, anAdr);
252 anAdr=myFClass2dMap.Find(aF);
253 pFClass2d=(IntTools_FClass2d*)anAdr;
257 //=======================================================================
260 //=======================================================================
261 GeomAPI_ProjectPointOnSurf& IntTools_Context::ProjPS(const TopoDS_Face& aF)
263 Standard_Address anAdr;
264 GeomAPI_ProjectPointOnSurf* pProjPS;
266 if (!myProjPSMap.IsBound(aF)) {
267 Standard_Real Umin, Usup, Vmin, Vsup;
268 BRepAdaptor_Surface aBAS;
270 const Handle(Geom_Surface)& aS=BRep_Tool::Surface(aF);
271 aBAS.Initialize (aF, Standard_True);
273 Umin=aBAS.FirstUParameter();
274 Usup=aBAS.LastUParameter ();
275 Vmin=aBAS.FirstVParameter();
276 Vsup=aBAS.LastVParameter ();
278 pProjPS=(GeomAPI_ProjectPointOnSurf*)myAllocator->Allocate(sizeof(GeomAPI_ProjectPointOnSurf));
279 new (pProjPS) GeomAPI_ProjectPointOnSurf();
280 pProjPS->Init(aS ,Umin, Usup, Vmin, Vsup, myPOnSTolerance/*, Extrema_ExtAlgo_Tree*/);
281 Extrema_ExtPS& anExtAlgo = const_cast<Extrema_ExtPS&>(pProjPS->Extrema());
282 anExtAlgo.SetFlag(Extrema_ExtFlag_MIN);
284 anAdr=(Standard_Address)pProjPS;
285 myProjPSMap.Bind(aF, anAdr);
289 anAdr=myProjPSMap.Find(aF);
290 pProjPS=(GeomAPI_ProjectPointOnSurf*)anAdr;
294 //=======================================================================
297 //=======================================================================
298 GeomAPI_ProjectPointOnCurve& IntTools_Context::ProjPC(const TopoDS_Edge& aE)
300 Standard_Address anAdr;
301 GeomAPI_ProjectPointOnCurve* pProjPC;
303 if (!myProjPCMap.IsBound(aE)) {
306 Handle(Geom_Curve)aC3D=BRep_Tool::Curve (aE, f, l);
308 pProjPC=(GeomAPI_ProjectPointOnCurve*)myAllocator->Allocate(sizeof(GeomAPI_ProjectPointOnCurve));
309 new (pProjPC) GeomAPI_ProjectPointOnCurve();
310 pProjPC->Init(aC3D, f, l);
312 anAdr=(Standard_Address)pProjPC;
313 myProjPCMap.Bind(aE, anAdr);
317 anAdr=myProjPCMap.Find(aE);
318 pProjPC=(GeomAPI_ProjectPointOnCurve*)anAdr;
323 //=======================================================================
326 //=======================================================================
327 GeomAPI_ProjectPointOnCurve& IntTools_Context::ProjPT
328 (const Handle(Geom_Curve)& aC3D)
331 Standard_Address anAdr;
332 GeomAPI_ProjectPointOnCurve* pProjPT;
334 if (!myProjPTMap.IsBound(aC3D)) {
336 f=aC3D->FirstParameter();
337 l=aC3D->LastParameter();
339 pProjPT=(GeomAPI_ProjectPointOnCurve*)myAllocator->Allocate(sizeof(GeomAPI_ProjectPointOnCurve));
340 new (pProjPT) GeomAPI_ProjectPointOnCurve();
341 pProjPT->Init(aC3D, f, l);
343 anAdr=(Standard_Address)pProjPT;
344 myProjPTMap.Bind(aC3D, anAdr);
348 anAdr=myProjPTMap.Find(aC3D);
349 pProjPT=(GeomAPI_ProjectPointOnCurve*)anAdr;
353 //=======================================================================
354 //function : SolidClassifier
356 //=======================================================================
357 BRepClass3d_SolidClassifier& IntTools_Context::SolidClassifier
358 (const TopoDS_Solid& aSolid)
360 Standard_Address anAdr;
361 BRepClass3d_SolidClassifier* pSC;
363 if (!mySClassMap.IsBound(aSolid)) {
365 pSC=(BRepClass3d_SolidClassifier*)myAllocator->Allocate(sizeof(BRepClass3d_SolidClassifier));
366 new (pSC) BRepClass3d_SolidClassifier(aSolid);
368 anAdr=(Standard_Address)pSC;
369 mySClassMap.Bind(aSolid, anAdr);
373 anAdr=mySClassMap.Find(aSolid);
374 pSC =(BRepClass3d_SolidClassifier*)anAdr;
379 //=======================================================================
382 //=======================================================================
383 Geom2dHatch_Hatcher& IntTools_Context::Hatcher(const TopoDS_Face& aF)
385 Standard_Address anAdr;
386 Geom2dHatch_Hatcher* pHatcher;
388 if (!myHatcherMap.IsBound(aF)) {
389 Standard_Real aTolArcIntr, aTolTangfIntr, aTolHatch2D, aTolHatch3D;
390 Standard_Real aU1, aU2, aEpsT;
391 TopAbs_Orientation aOrE;
392 Handle(Geom_Surface) aS;
393 Handle(Geom2d_Curve) aC2D;
394 Handle(Geom2d_TrimmedCurve) aCT2D;
396 TopExp_Explorer aExp;
401 aTolTangfIntr=1.e-10;
402 aEpsT=Precision::PConfusion();
404 Geom2dHatch_Intersector aIntr(aTolArcIntr, aTolTangfIntr);
405 pHatcher=(Geom2dHatch_Hatcher*)
406 myAllocator->Allocate(sizeof(Geom2dHatch_Hatcher));
407 new (pHatcher) Geom2dHatch_Hatcher(aIntr,
408 aTolHatch2D, aTolHatch3D,
409 Standard_True, Standard_False);
412 aFF.Orientation(TopAbs_FORWARD);
413 aS=BRep_Tool::Surface(aFF);
415 aExp.Init (aFF, TopAbs_EDGE);
416 for (; aExp.More() ; aExp.Next()) {
417 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aExp.Current());
418 aOrE=aE.Orientation();
420 aC2D=BRep_Tool::CurveOnSurface (aE, aFF, aU1, aU2);
421 if (aC2D.IsNull() ) {
424 if (fabs(aU1-aU2) < aEpsT) {
428 aCT2D=new Geom2d_TrimmedCurve(aC2D, aU1, aU2);
429 Geom2dAdaptor_Curve aGAC (aCT2D);
430 pHatcher->AddElement(aGAC, aOrE);
431 }// for (; aExp.More() ; aExp.Next()) {
433 anAdr=(Standard_Address)pHatcher;
434 myHatcherMap.Bind(aFF, anAdr);
435 }//if (!myHatcherMap.IsBound(aF)) {
438 anAdr=myHatcherMap.Find(aF);
439 pHatcher=(Geom2dHatch_Hatcher*)anAdr;
445 //=======================================================================
446 //function : SurfaceData
448 //=======================================================================
449 IntTools_SurfaceRangeLocalizeData& IntTools_Context::SurfaceData
450 (const TopoDS_Face& aF)
452 Standard_Address anAdr;
453 IntTools_SurfaceRangeLocalizeData* pSData;
455 if (!myProjSDataMap.IsBound(aF)) {
456 pSData=(IntTools_SurfaceRangeLocalizeData*)
457 myAllocator->Allocate(sizeof(IntTools_SurfaceRangeLocalizeData));
458 new (pSData) IntTools_SurfaceRangeLocalizeData
461 10. * Precision::PConfusion(),
462 10. * Precision::PConfusion());
464 anAdr=(Standard_Address)pSData;
465 myProjSDataMap.Bind(aF, anAdr);
469 anAdr=myProjSDataMap.Find(aF);
470 pSData=(IntTools_SurfaceRangeLocalizeData*)anAdr;
476 //=======================================================================
477 //function : ComputePE
479 //=======================================================================
480 Standard_Integer IntTools_Context::ComputePE
482 const Standard_Real aTolP1,
483 const TopoDS_Edge& aE2,
486 if (!BRep_Tool::IsGeometric(aE2)) {
489 Standard_Real aDist, aTolE2, aTolSum;
490 Standard_Integer aNbProj;
492 GeomAPI_ProjectPointOnCurve& aProjector=ProjPC(aE2);
493 aProjector.Perform(aP1);
495 aNbProj=aProjector.NbPoints();
500 aDist=aProjector.LowerDistance();
502 aTolE2=BRep_Tool::Tolerance(aE2);
503 aTolSum = aTolP1 + aTolE2 + Precision::Confusion();
505 aT=aProjector.LowerDistanceParameter();
506 if (aDist > aTolSum) {
511 //=======================================================================
512 //function : ComputeVE
514 //=======================================================================
515 Standard_Integer IntTools_Context::ComputeVE
516 (const TopoDS_Vertex& aV1,
517 const TopoDS_Edge& aE2,
518 Standard_Real& aParam,
519 Standard_Real& aTolVnew)
521 if (BRep_Tool::Degenerated(aE2)) {
524 if (!BRep_Tool::IsGeometric(aE2)) {
527 Standard_Real aDist, aTolV1, aTolE2, aTolSum;
528 Standard_Integer aNbProj;
531 aP=BRep_Tool::Pnt(aV1);
533 GeomAPI_ProjectPointOnCurve& aProjector=ProjPC(aE2);
534 aProjector.Perform(aP);
536 aNbProj=aProjector.NbPoints();
541 aDist=aProjector.LowerDistance();
543 aTolV1=BRep_Tool::Tolerance(aV1);
544 aTolE2=BRep_Tool::Tolerance(aE2);
545 aTolSum = aTolV1 + aTolE2 + Precision::Confusion();
547 aTolVnew=aDist+aTolE2;
549 aParam=aProjector.LowerDistanceParameter();
550 if (aDist > aTolSum) {
555 //=======================================================================
556 //function : ComputeVF
558 //=======================================================================
559 Standard_Integer IntTools_Context::ComputeVF
560 (const TopoDS_Vertex& aV1,
561 const TopoDS_Face& aF2,
564 Standard_Real& aTolVnew)
566 Standard_Real aTolV1, aTolF2, aTolSum, aDist;
569 aP=BRep_Tool::Pnt(aV1);
571 // 1. Check if the point is projectable on the surface
572 GeomAPI_ProjectPointOnSurf& aProjector=ProjPS(aF2);
573 aProjector.Perform(aP);
575 if (!aProjector.IsDone()) { // the point is not projectable on the surface
579 // 2. Check the distance between the projection point and
580 // the original point
581 aDist=aProjector.LowerDistance();
583 aTolV1=BRep_Tool::Tolerance(aV1);
584 aTolF2=BRep_Tool::Tolerance(aF2);
586 aTolSum = aTolV1 + aTolF2 + Precision::Confusion();
587 aTolVnew = aDist + aTolF2;
589 if (aDist > aTolSum) {
590 // the distance is too large
593 aProjector.LowerDistanceParameters(U, V);
596 Standard_Boolean pri=IsPointInFace (aF2, aP2d);
597 if (!pri) {// the point lays on the surface but out of the face
602 //=======================================================================
603 //function : StatePointFace
605 //=======================================================================
606 TopAbs_State IntTools_Context::StatePointFace
607 (const TopoDS_Face& aF,
608 const gp_Pnt2d& aP2d)
611 IntTools_FClass2d& aClass2d=FClass2d(aF);
612 aState=aClass2d.Perform(aP2d);
615 //=======================================================================
616 //function : IsPointInFace
618 //=======================================================================
619 Standard_Boolean IntTools_Context::IsPointInFace
620 (const TopoDS_Face& aF,
621 const gp_Pnt2d& aP2d)
623 TopAbs_State aState=StatePointFace(aF, aP2d);
624 if (aState==TopAbs_OUT || aState==TopAbs_ON) {
625 return Standard_False;
627 return Standard_True;
629 //=======================================================================
630 //function : IsPointInFace
632 //=======================================================================
633 Standard_Boolean IntTools_Context::IsPointInFace
635 const TopoDS_Face& aF,
636 const Standard_Real aTol)
638 Standard_Boolean bIn;
641 GeomAPI_ProjectPointOnSurf& aProjector=ProjPS(aF);
642 aProjector.Perform(aP);
644 bIn = aProjector.IsDone();
646 aDist = aProjector.LowerDistance();
650 aProjector.LowerDistanceParameters(U, V);
652 bIn = IsPointInFace(aF, aP2D);
658 //=======================================================================
659 //function : IsPointInOnFace
661 //=======================================================================
662 Standard_Boolean IntTools_Context::IsPointInOnFace(const TopoDS_Face& aF,
663 const gp_Pnt2d& aP2d)
665 TopAbs_State aState=StatePointFace(aF, aP2d);
666 if (aState==TopAbs_OUT) {
667 return Standard_False;
669 return Standard_True;
671 //=======================================================================
672 //function : IsValidPointForFace
674 //=======================================================================
675 Standard_Boolean IntTools_Context::IsValidPointForFace
677 const TopoDS_Face& aF,
678 const Standard_Real aTol)
680 Standard_Boolean bFlag;
681 Standard_Real Umin, U, V;
683 GeomAPI_ProjectPointOnSurf& aProjector=ProjPS(aF);
684 aProjector.Perform(aP);
686 bFlag=aProjector.IsDone();
689 Umin=aProjector.LowerDistance();
690 //if (Umin > 1.e-3) { // it was
695 aProjector.LowerDistanceParameters(U, V);
697 bFlag=IsPointInOnFace (aF, aP2D);
701 //=======================================================================
702 //function : IsValidPointForFaces
704 //=======================================================================
705 Standard_Boolean IntTools_Context::IsValidPointForFaces
707 const TopoDS_Face& aF1,
708 const TopoDS_Face& aF2,
709 const Standard_Real aTol)
711 Standard_Boolean bFlag1, bFlag2;
713 bFlag1=IsValidPointForFace(aP, aF1, aTol);
717 bFlag2=IsValidPointForFace(aP, aF2, aTol);
720 //=======================================================================
721 //function : IsValidBlockForFace
723 //=======================================================================
724 Standard_Boolean IntTools_Context::IsValidBlockForFace
725 (const Standard_Real aT1,
726 const Standard_Real aT2,
727 const IntTools_Curve& aC,
728 const TopoDS_Face& aF,
729 const Standard_Real aTol)
731 Standard_Boolean bFlag;
732 Standard_Real aTInterm;
735 aTInterm=IntTools_Tools::IntermediatePoint(aT1, aT2);
737 Handle(Geom_Curve) aC3D=aC.Curve();
739 aC3D->D0(aTInterm, aPInterm);
741 bFlag=IsValidPointForFace (aPInterm, aF, aTol);
744 //=======================================================================
745 //function : IsValidBlockForFaces
747 //=======================================================================
748 Standard_Boolean IntTools_Context::IsValidBlockForFaces
749 (const Standard_Real aT1,
750 const Standard_Real aT2,
751 const IntTools_Curve& aC,
752 const TopoDS_Face& aF1,
753 const TopoDS_Face& aF2,
754 const Standard_Real aTol)
756 Standard_Boolean bFlag1, bFlag2;
758 Handle(Geom2d_Curve) aPC1 = aC.FirstCurve2d();
759 Handle(Geom2d_Curve) aPC2 = aC.SecondCurve2d();
760 if( !aPC1.IsNull() && !aPC2.IsNull() ) {
761 Standard_Real aMidPar = IntTools_Tools::IntermediatePoint(aT1, aT2);
765 aPC1->D0(aMidPar, aPnt2D);
766 bFlag1 = IsPointInOnFace(aF1, aPnt2D);
771 aPC2->D0(aMidPar, aPnt2D);
772 bFlag2 = IsPointInOnFace(aF2, aPnt2D);
777 bFlag1=IsValidBlockForFace (aT1, aT2, aC, aF1, aTol);
781 bFlag2=IsValidBlockForFace (aT1, aT2, aC, aF2, aTol);
784 //=======================================================================
785 //function : IsVertexOnLine
787 //=======================================================================
788 Standard_Boolean IntTools_Context::IsVertexOnLine
789 (const TopoDS_Vertex& aV,
790 const IntTools_Curve& aC,
791 const Standard_Real aTolC,
794 Standard_Boolean bRet;
797 aTolV=BRep_Tool::Tolerance(aV);
798 bRet=IntTools_Context::IsVertexOnLine(aV, aTolV, aC, aTolC , aT);
802 //=======================================================================
803 //function : IsVertexOnLine
805 //=======================================================================
806 Standard_Boolean IntTools_Context::IsVertexOnLine
807 (const TopoDS_Vertex& aV,
808 const Standard_Real aTolV,
809 const IntTools_Curve& aC,
810 const Standard_Real aTolC,
813 Standard_Real aFirst, aLast, aDist, aTolSum;
814 Standard_Integer aNbProj;
817 aPv=BRep_Tool::Pnt(aV);
819 Handle(Geom_Curve) aC3D=aC.Curve();
824 GeomAdaptor_Curve aGAC(aC3D);
825 GeomAbs_CurveType aType=aGAC.GetType();
826 if (aType==GeomAbs_BSplineCurve ||
827 aType==GeomAbs_BezierCurve) {
834 aTolSum=2.*aTolSum;//xft
839 aFirst=aC3D->FirstParameter();
840 aLast =aC3D->LastParameter();
842 //Checking extermities first
843 if (!Precision::IsInfinite(aFirst)) {
844 gp_Pnt aPCFirst=aC3D->Value(aFirst);
845 aDist=aPv.Distance(aPCFirst);
846 if (aDist < aTolSum) {
850 Extrema_LocateExtPC anExt(aPv, aGAC, aFirst, 1.e-10);
853 Extrema_POnCurv aPOncurve = anExt.Point();
854 aT = aPOncurve.Parameter();
856 if((aT > (aLast + aFirst) * 0.5) ||
857 (aPv.Distance(aPOncurve.Value()) > aTolSum) ||
858 (aPCFirst.Distance(aPOncurve.Value()) < Precision::Confusion()))
863 // Local search may fail. Try to use more precise algo.
864 Extrema_ExtPC anExt2(aPv, aGAC, 1.e-10);
865 Standard_Real aMinDist = RealLast();
866 Standard_Integer aMinIdx = -1;
867 if (anExt2.IsDone()) {
868 for (Standard_Integer anIdx = 1; anIdx <= anExt2.NbExt(); anIdx++)
870 if ( anExt2.IsMin(anIdx) &&
871 anExt2.SquareDistance(anIdx) < aMinDist )
873 aMinDist = anExt2.SquareDistance(anIdx);
880 const Extrema_POnCurv& aPOncurve = anExt2.Point(aMinIdx);
881 aT = aPOncurve.Parameter();
883 if((aT > (aLast + aFirst) * 0.5) ||
884 (aPv.Distance(aPOncurve.Value()) > aTolSum) ||
885 (aPCFirst.Distance(aPOncurve.Value()) < Precision::Confusion()))
892 return Standard_True;
896 //if (!Precision::IsInfinite(aFirst)) {
897 if (!Precision::IsInfinite(aLast)) {
898 gp_Pnt aPCLast=aC3D->Value(aLast);
899 aDist=aPv.Distance(aPCLast);
900 if (aDist < aTolSum) {
904 Extrema_LocateExtPC anExt(aPv, aGAC, aLast, 1.e-10);
907 Extrema_POnCurv aPOncurve = anExt.Point();
908 aT = aPOncurve.Parameter();
910 if((aT < (aLast + aFirst) * 0.5) ||
911 (aPv.Distance(aPOncurve.Value()) > aTolSum) ||
912 (aPCLast.Distance(aPOncurve.Value()) < Precision::Confusion()))
917 // Local search may fail. Try to use more precise algo.
918 Extrema_ExtPC anExt2(aPv, aGAC, 1.e-10);
919 Standard_Real aMinDist = RealLast();
920 Standard_Integer aMinIdx = -1;
921 if (anExt2.IsDone()) {
922 for (Standard_Integer anIdx = 1; anIdx <= anExt2.NbExt(); anIdx++)
924 if ( anExt2.IsMin(anIdx) &&
925 anExt2.SquareDistance(anIdx) < aMinDist )
927 aMinDist = anExt2.SquareDistance(anIdx);
934 const Extrema_POnCurv& aPOncurve = anExt2.Point(aMinIdx);
935 aT = aPOncurve.Parameter();
937 if((aT < (aLast + aFirst) * 0.5) ||
938 (aPv.Distance(aPOncurve.Value()) > aTolSum) ||
939 (aPCLast.Distance(aPOncurve.Value()) < Precision::Confusion()))
945 return Standard_True;
949 GeomAPI_ProjectPointOnCurve& aProjector=ProjPT(aC3D);
950 aProjector.Perform(aPv);
952 aNbProj=aProjector.NbPoints();
954 Handle(Geom_BoundedCurve) aBC=
955 Handle(Geom_BoundedCurve)::DownCast(aC3D);
957 gp_Pnt aPStart=aBC->StartPoint();
958 gp_Pnt aPEnd =aBC->EndPoint();
960 aDist=aPv.Distance(aPStart);
961 if (aDist < aTolSum) {
963 return Standard_True;
966 aDist=aPv.Distance(aPEnd);
967 if (aDist < aTolSum) {
969 return Standard_True;
973 return Standard_False;
976 aDist=aProjector.LowerDistance();
978 if (aDist > aTolSum) {
979 return Standard_False;
982 aT=aProjector.LowerDistanceParameter();
984 return Standard_True;
986 //=======================================================================
987 //function : ProjectPointOnEdge
989 //=======================================================================
990 Standard_Boolean IntTools_Context::ProjectPointOnEdge
992 const TopoDS_Edge& anEdge,
995 Standard_Integer aNbPoints;
997 GeomAPI_ProjectPointOnCurve& aProjector=ProjPC(anEdge);
998 aProjector.Perform(aP);
1000 aNbPoints=aProjector.NbPoints();
1002 aT=aProjector.LowerDistanceParameter();
1003 return Standard_True;
1005 return Standard_False;
1008 //=======================================================================
1009 //function : SetPOnSProjectionTolerance
1011 //=======================================================================
1012 void IntTools_Context::SetPOnSProjectionTolerance(const Standard_Real theValue)
1014 myPOnSTolerance = theValue;
1015 clearCachedPOnSProjectors();
1018 //=======================================================================
1019 //function : clearCachedPOnSProjectors
1021 //=======================================================================
1022 void IntTools_Context::clearCachedPOnSProjectors()
1024 GeomAPI_ProjectPointOnSurf* pProjPS;
1025 BOPCol_DataMapIteratorOfDataMapOfShapeAddress aIt(myProjPSMap);
1026 for (; aIt.More(); aIt.Next()) {
1027 Standard_Address anAdr=aIt.Value();
1028 pProjPS=(GeomAPI_ProjectPointOnSurf*)anAdr;
1029 (*pProjPS).~GeomAPI_ProjectPointOnSurf();
1030 myAllocator->Free(anAdr);
1032 myProjPSMap.Clear();