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>
50 //=======================================================================
53 //=======================================================================
54 IntTools_Context::IntTools_Context()
56 myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()),
57 myFClass2dMap(100, myAllocator),
58 myProjPSMap(100, myAllocator),
59 myProjPCMap(100, myAllocator),
60 mySClassMap(100, myAllocator),
61 myProjPTMap(100, myAllocator),
62 myHatcherMap(100, myAllocator),
63 myProjSDataMap(100, myAllocator),
64 myBndBoxDataMap(100, myAllocator),
66 myPOnSTolerance(1.e-12)
69 //=======================================================================
72 //=======================================================================
73 IntTools_Context::IntTools_Context
74 (const Handle(NCollection_BaseAllocator)& theAllocator)
76 myAllocator(theAllocator),
77 myFClass2dMap(100, myAllocator),
78 myProjPSMap(100, myAllocator),
79 myProjPCMap(100, myAllocator),
80 mySClassMap(100, myAllocator),
81 myProjPTMap(100, myAllocator),
82 myHatcherMap(100, myAllocator),
83 myProjSDataMap(100, myAllocator),
84 myBndBoxDataMap(100, myAllocator),
86 myPOnSTolerance(1.e-12)
89 //=======================================================================
92 //=======================================================================
93 IntTools_Context::~IntTools_Context()
95 Standard_Address anAdr;
96 BOPCol_DataMapIteratorOfDataMapOfShapeAddress aIt;
97 BOPCol_DataMapIteratorOfDataMapOfTransientAddress aIt1;
99 IntTools_FClass2d* pFClass2d;
101 aIt.Initialize(myFClass2dMap);
102 for (; aIt.More(); aIt.Next()) {
104 pFClass2d=(IntTools_FClass2d*)anAdr;
105 (*pFClass2d).~IntTools_FClass2d();
106 myAllocator->Free(anAdr);
108 myFClass2dMap.Clear();
110 clearCachedPOnSProjectors();
112 GeomAPI_ProjectPointOnCurve* pProjPC;
113 aIt.Initialize(myProjPCMap);
114 for (; aIt.More(); aIt.Next()) {
116 pProjPC=(GeomAPI_ProjectPointOnCurve*)anAdr;
117 (*pProjPC).~GeomAPI_ProjectPointOnCurve();
118 myAllocator->Free(anAdr);
123 BRepClass3d_SolidClassifier* pSC;
124 aIt.Initialize(mySClassMap);
125 for (; aIt.More(); aIt.Next()) {
127 pSC=(BRepClass3d_SolidClassifier*)anAdr;
128 (*pSC).~BRepClass3d_SolidClassifier();
129 myAllocator->Free(anAdr);
133 GeomAPI_ProjectPointOnCurve* pProjPT;
134 aIt1.Initialize(myProjPTMap);
135 for (; aIt1.More(); aIt1.Next()) {
137 pProjPT=(GeomAPI_ProjectPointOnCurve*)anAdr;
138 (*pProjPT).~GeomAPI_ProjectPointOnCurve();
139 myAllocator->Free(anAdr);
143 Geom2dHatch_Hatcher* pHatcher;
144 aIt.Initialize(myHatcherMap);
145 for (; aIt.More(); aIt.Next()) {
147 pHatcher=(Geom2dHatch_Hatcher*)anAdr;
148 (*pHatcher).~Geom2dHatch_Hatcher();
149 myAllocator->Free(anAdr);
151 myHatcherMap.Clear();
153 IntTools_SurfaceRangeLocalizeData* pSData = NULL;
154 aIt.Initialize(myProjSDataMap);
155 for (; aIt.More(); aIt.Next()) {
157 pSData = (IntTools_SurfaceRangeLocalizeData*)anAdr;
158 (*pSData).~IntTools_SurfaceRangeLocalizeData();
159 myAllocator->Free(anAdr);
161 myProjSDataMap.Clear();
164 aIt.Initialize(myBndBoxDataMap);
165 for (; aIt.More(); aIt.Next()) {
167 pBox=(Bnd_Box*)anAdr;
169 myAllocator->Free(anAdr);
171 myBndBoxDataMap.Clear();
173 //=======================================================================
176 //=======================================================================
177 Bnd_Box& IntTools_Context::BndBox(const TopoDS_Shape& aS)
179 Standard_Address anAdr;
182 if (!myBndBoxDataMap.IsBound(aS)) {
184 pBox=(Bnd_Box*)myAllocator->Allocate(sizeof(Bnd_Box));
185 new (pBox) Bnd_Box();
188 BRepBndLib::Add(aS, aBox);
190 anAdr=(Standard_Address)pBox;
191 myBndBoxDataMap.Bind(aS, anAdr);
194 anAdr=myBndBoxDataMap.Find(aS);
195 pBox=(Bnd_Box*)anAdr;
199 //=======================================================================
200 //function : IsInfiniteFace
202 //=======================================================================
203 Standard_Boolean IntTools_Context::IsInfiniteFace
204 (const TopoDS_Face& aFace)
206 Standard_Boolean bRet;
212 if (!BRep_Tool::NaturalRestriction(aFace)) {
216 Bnd_Box& aBox=BndBox(aFace);
218 aBox.Get(aX[0], aX[1], aX[2], aX[3], aX[4], aX[5]);
220 for (i=0; (i<6) && (!bRet); ++i) {
221 bRet=Precision::IsInfinite(aX[i]);
226 //=======================================================================
227 //function : FClass2d
229 //=======================================================================
230 IntTools_FClass2d& IntTools_Context::FClass2d(const TopoDS_Face& aF)
232 Standard_Address anAdr;
233 IntTools_FClass2d* pFClass2d;
235 if (!myFClass2dMap.IsBound(aF)) {
240 aFF.Orientation(TopAbs_FORWARD);
241 aTolF=BRep_Tool::Tolerance(aFF);
243 pFClass2d=(IntTools_FClass2d*)myAllocator->Allocate(sizeof(IntTools_FClass2d));
244 new (pFClass2d) IntTools_FClass2d(aFF, aTolF);
246 anAdr=(Standard_Address)pFClass2d;
247 myFClass2dMap.Bind(aFF, anAdr);
250 anAdr=myFClass2dMap.Find(aF);
251 pFClass2d=(IntTools_FClass2d*)anAdr;
255 //=======================================================================
258 //=======================================================================
259 GeomAPI_ProjectPointOnSurf& IntTools_Context::ProjPS(const TopoDS_Face& aF)
261 Standard_Address anAdr;
262 GeomAPI_ProjectPointOnSurf* pProjPS;
264 if (!myProjPSMap.IsBound(aF)) {
265 Standard_Real Umin, Usup, Vmin, Vsup;
266 BRepAdaptor_Surface aBAS;
268 const Handle(Geom_Surface)& aS=BRep_Tool::Surface(aF);
269 aBAS.Initialize (aF, Standard_True);
271 Umin=aBAS.FirstUParameter();
272 Usup=aBAS.LastUParameter ();
273 Vmin=aBAS.FirstVParameter();
274 Vsup=aBAS.LastVParameter ();
276 pProjPS=(GeomAPI_ProjectPointOnSurf*)myAllocator->Allocate(sizeof(GeomAPI_ProjectPointOnSurf));
277 new (pProjPS) GeomAPI_ProjectPointOnSurf();
278 pProjPS->Init(aS ,Umin, Usup, Vmin, Vsup, myPOnSTolerance/*, Extrema_ExtAlgo_Tree*/);
279 Extrema_ExtPS& anExtAlgo = const_cast<Extrema_ExtPS&>(pProjPS->Extrema());
280 anExtAlgo.SetFlag(Extrema_ExtFlag_MIN);
282 anAdr=(Standard_Address)pProjPS;
283 myProjPSMap.Bind(aF, anAdr);
287 anAdr=myProjPSMap.Find(aF);
288 pProjPS=(GeomAPI_ProjectPointOnSurf*)anAdr;
292 //=======================================================================
295 //=======================================================================
296 GeomAPI_ProjectPointOnCurve& IntTools_Context::ProjPC(const TopoDS_Edge& aE)
298 Standard_Address anAdr;
299 GeomAPI_ProjectPointOnCurve* pProjPC;
301 if (!myProjPCMap.IsBound(aE)) {
304 Handle(Geom_Curve)aC3D=BRep_Tool::Curve (aE, f, l);
306 pProjPC=(GeomAPI_ProjectPointOnCurve*)myAllocator->Allocate(sizeof(GeomAPI_ProjectPointOnCurve));
307 new (pProjPC) GeomAPI_ProjectPointOnCurve();
308 pProjPC->Init(aC3D, f, l);
310 anAdr=(Standard_Address)pProjPC;
311 myProjPCMap.Bind(aE, anAdr);
315 anAdr=myProjPCMap.Find(aE);
316 pProjPC=(GeomAPI_ProjectPointOnCurve*)anAdr;
321 //=======================================================================
324 //=======================================================================
325 GeomAPI_ProjectPointOnCurve& IntTools_Context::ProjPT
326 (const Handle(Geom_Curve)& aC3D)
329 Standard_Address anAdr;
330 GeomAPI_ProjectPointOnCurve* pProjPT;
332 if (!myProjPTMap.IsBound(aC3D)) {
334 f=aC3D->FirstParameter();
335 l=aC3D->LastParameter();
337 pProjPT=(GeomAPI_ProjectPointOnCurve*)myAllocator->Allocate(sizeof(GeomAPI_ProjectPointOnCurve));
338 new (pProjPT) GeomAPI_ProjectPointOnCurve();
339 pProjPT->Init(aC3D, f, l);
341 anAdr=(Standard_Address)pProjPT;
342 myProjPTMap.Bind(aC3D, anAdr);
346 anAdr=myProjPTMap.Find(aC3D);
347 pProjPT=(GeomAPI_ProjectPointOnCurve*)anAdr;
351 //=======================================================================
352 //function : SolidClassifier
354 //=======================================================================
355 BRepClass3d_SolidClassifier& IntTools_Context::SolidClassifier
356 (const TopoDS_Solid& aSolid)
358 Standard_Address anAdr;
359 BRepClass3d_SolidClassifier* pSC;
361 if (!mySClassMap.IsBound(aSolid)) {
363 pSC=(BRepClass3d_SolidClassifier*)myAllocator->Allocate(sizeof(BRepClass3d_SolidClassifier));
364 new (pSC) BRepClass3d_SolidClassifier(aSolid);
366 anAdr=(Standard_Address)pSC;
367 mySClassMap.Bind(aSolid, anAdr);
371 anAdr=mySClassMap.Find(aSolid);
372 pSC =(BRepClass3d_SolidClassifier*)anAdr;
377 //=======================================================================
380 //=======================================================================
381 Geom2dHatch_Hatcher& IntTools_Context::Hatcher(const TopoDS_Face& aF)
383 Standard_Address anAdr;
384 Geom2dHatch_Hatcher* pHatcher;
386 if (!myHatcherMap.IsBound(aF)) {
387 Standard_Real aTolArcIntr, aTolTangfIntr, aTolHatch2D, aTolHatch3D;
388 Standard_Real aU1, aU2, aEpsT;
389 TopAbs_Orientation aOrE;
390 Handle(Geom_Surface) aS;
391 Handle(Geom2d_Curve) aC2D;
392 Handle(Geom2d_TrimmedCurve) aCT2D;
394 TopExp_Explorer aExp;
399 aTolTangfIntr=1.e-10;
400 aEpsT=Precision::PConfusion();
402 Geom2dHatch_Intersector aIntr(aTolArcIntr, aTolTangfIntr);
403 pHatcher=new Geom2dHatch_Hatcher(aIntr,
404 aTolHatch2D, aTolHatch3D,
405 Standard_True, Standard_False);
409 aFF.Orientation(TopAbs_FORWARD);
410 aS=BRep_Tool::Surface(aFF);
412 aExp.Init (aFF, TopAbs_EDGE);
413 for (; aExp.More() ; aExp.Next()) {
414 const TopoDS_Edge& aE=*((TopoDS_Edge*)&aExp.Current());
415 aOrE=aE.Orientation();
417 aC2D=BRep_Tool::CurveOnSurface (aE, aFF, aU1, aU2);
418 if (aC2D.IsNull() ) {
421 if (fabs(aU1-aU2) < aEpsT) {
425 aCT2D=new Geom2d_TrimmedCurve(aC2D, aU1, aU2);
426 Geom2dAdaptor_Curve aGAC (aCT2D);
427 pHatcher->AddElement(aGAC, aOrE);
428 }// for (; aExp.More() ; aExp.Next()) {
430 anAdr=(Standard_Address)pHatcher;
431 myHatcherMap.Bind(aFF, anAdr);
432 }//if (!myHatcherMap.IsBound(aF)) {
435 anAdr=myHatcherMap.Find(aF);
436 pHatcher=(Geom2dHatch_Hatcher*)anAdr;
442 //=======================================================================
443 //function : SurfaceData
445 //=======================================================================
446 IntTools_SurfaceRangeLocalizeData& IntTools_Context::SurfaceData
447 (const TopoDS_Face& aF)
449 Standard_Address anAdr;
450 IntTools_SurfaceRangeLocalizeData* pSData;
452 if (!myProjSDataMap.IsBound(aF)) {
453 pSData=new IntTools_SurfaceRangeLocalizeData
456 10. * Precision::PConfusion(),
457 10. * Precision::PConfusion());
459 anAdr=(Standard_Address)pSData;
460 myProjSDataMap.Bind(aF, anAdr);
464 anAdr=myProjSDataMap.Find(aF);
465 pSData=(IntTools_SurfaceRangeLocalizeData*)anAdr;
471 //=======================================================================
472 //function : ComputePE
474 //=======================================================================
475 Standard_Integer IntTools_Context::ComputePE
477 const Standard_Real aTolP1,
478 const TopoDS_Edge& aE2,
481 if (!BRep_Tool::IsGeometric(aE2)) {
484 Standard_Real aDist, aTolE2, aTolSum;
485 Standard_Integer aNbProj;
487 GeomAPI_ProjectPointOnCurve& aProjector=ProjPC(aE2);
488 aProjector.Perform(aP1);
490 aNbProj=aProjector.NbPoints();
495 aDist=aProjector.LowerDistance();
497 aTolE2=BRep_Tool::Tolerance(aE2);
498 aTolSum=aTolP1+aTolE2;
500 aT=aProjector.LowerDistanceParameter();
501 if (aDist > aTolSum) {
506 //=======================================================================
507 //function : ComputeVE
509 //=======================================================================
510 Standard_Integer IntTools_Context::ComputeVE
511 (const TopoDS_Vertex& aV1,
512 const TopoDS_Edge& aE2,
515 if (BRep_Tool::Degenerated(aE2)) {
518 if (!BRep_Tool::IsGeometric(aE2)) {
521 Standard_Real aDist, aTolV1, aTolE2, aTolSum;
522 Standard_Integer aNbProj;
525 aP=BRep_Tool::Pnt(aV1);
527 GeomAPI_ProjectPointOnCurve& aProjector=ProjPC(aE2);
528 aProjector.Perform(aP);
530 aNbProj=aProjector.NbPoints();
535 aDist=aProjector.LowerDistance();
537 // tolerance of check for coincidence is sum of tolerances of edge and vertex
538 // extended by additional Precision::Confusion() to allow for interference where
539 // it is very close but not fit to tolerance (see #24108)
540 aTolV1=BRep_Tool::Tolerance(aV1);
541 aTolE2=BRep_Tool::Tolerance(aE2);
542 aTolSum = aTolV1 + aTolE2 + Precision::Confusion();
544 aT=aProjector.LowerDistanceParameter();
545 if (aDist > aTolSum) {
550 //=======================================================================
551 //function : ComputeVS
553 //=======================================================================
554 Standard_Integer IntTools_Context::ComputeVF
555 (const TopoDS_Vertex& aV1,
556 const TopoDS_Face& aF2,
560 Standard_Real aTolV1, aTolF2, aTolSum, aDist;
563 aP=BRep_Tool::Pnt(aV1);
565 // 1. Check if the point is projectable on the surface
566 GeomAPI_ProjectPointOnSurf& aProjector=ProjPS(aF2);
567 aProjector.Perform(aP);
569 if (!aProjector.IsDone()) { // the point is not projectable on the surface
573 // 2. Check the distance between the projection point and
574 // the original point
575 aDist=aProjector.LowerDistance();
577 aTolV1=BRep_Tool::Tolerance(aV1);
578 aTolF2=BRep_Tool::Tolerance(aF2);
579 aTolSum=aTolV1+aTolF2;
580 if (aDist > aTolSum) {
581 // the distance is too large
584 aProjector.LowerDistanceParameters(U, V);
587 Standard_Boolean pri=IsPointInFace (aF2, aP2d);
588 if (!pri) {// the point lays on the surface but out of the face
593 //=======================================================================
594 //function : StatePointFace
596 //=======================================================================
597 TopAbs_State IntTools_Context::StatePointFace
598 (const TopoDS_Face& aF,
599 const gp_Pnt2d& aP2d)
602 IntTools_FClass2d& aClass2d=FClass2d(aF);
603 aState=aClass2d.Perform(aP2d);
606 //=======================================================================
607 //function : IsPointInFace
609 //=======================================================================
610 Standard_Boolean IntTools_Context::IsPointInFace
611 (const TopoDS_Face& aF,
612 const gp_Pnt2d& aP2d)
614 TopAbs_State aState=StatePointFace(aF, aP2d);
615 if (aState==TopAbs_OUT || aState==TopAbs_ON) {
616 return Standard_False;
618 return Standard_True;
620 //=======================================================================
621 //function : IsPointInFace
623 //=======================================================================
624 Standard_Boolean IntTools_Context::IsPointInFace
626 const TopoDS_Face& aF,
627 const Standard_Real aTol)
629 Standard_Boolean bIn;
632 GeomAPI_ProjectPointOnSurf& aProjector=ProjPS(aF);
633 aProjector.Perform(aP);
635 bIn = aProjector.IsDone();
637 aDist = aProjector.LowerDistance();
641 aProjector.LowerDistanceParameters(U, V);
643 bIn = IsPointInFace(aF, aP2D);
649 //=======================================================================
650 //function : IsPointInOnFace
652 //=======================================================================
653 Standard_Boolean IntTools_Context::IsPointInOnFace(const TopoDS_Face& aF,
654 const gp_Pnt2d& aP2d)
656 TopAbs_State aState=StatePointFace(aF, aP2d);
657 if (aState==TopAbs_OUT) {
658 return Standard_False;
660 return Standard_True;
662 //=======================================================================
663 //function : IsValidPointForFace
665 //=======================================================================
666 Standard_Boolean IntTools_Context::IsValidPointForFace
668 const TopoDS_Face& aF,
669 const Standard_Real aTol)
671 Standard_Boolean bFlag;
672 Standard_Real Umin, U, V;
674 GeomAPI_ProjectPointOnSurf& aProjector=ProjPS(aF);
675 aProjector.Perform(aP);
677 bFlag=aProjector.IsDone();
680 Umin=aProjector.LowerDistance();
681 //if (Umin > 1.e-3) { // it was
686 aProjector.LowerDistanceParameters(U, V);
688 bFlag=IsPointInOnFace (aF, aP2D);
692 //=======================================================================
693 //function : IsValidPointForFaces
695 //=======================================================================
696 Standard_Boolean IntTools_Context::IsValidPointForFaces
698 const TopoDS_Face& aF1,
699 const TopoDS_Face& aF2,
700 const Standard_Real aTol)
702 Standard_Boolean bFlag1, bFlag2;
704 bFlag1=IsValidPointForFace(aP, aF1, aTol);
708 bFlag2=IsValidPointForFace(aP, aF2, aTol);
711 //=======================================================================
712 //function : IsValidBlockForFace
714 //=======================================================================
715 Standard_Boolean IntTools_Context::IsValidBlockForFace
716 (const Standard_Real aT1,
717 const Standard_Real aT2,
718 const IntTools_Curve& aC,
719 const TopoDS_Face& aF,
720 const Standard_Real aTol)
722 Standard_Boolean bFlag;
723 Standard_Real aTInterm;
726 aTInterm=IntTools_Tools::IntermediatePoint(aT1, aT2);
728 Handle(Geom_Curve) aC3D=aC.Curve();
730 aC3D->D0(aTInterm, aPInterm);
732 bFlag=IsValidPointForFace (aPInterm, aF, aTol);
735 //=======================================================================
736 //function : IsValidBlockForFaces
738 //=======================================================================
739 Standard_Boolean IntTools_Context::IsValidBlockForFaces
740 (const Standard_Real aT1,
741 const Standard_Real aT2,
742 const IntTools_Curve& aC,
743 const TopoDS_Face& aF1,
744 const TopoDS_Face& aF2,
745 const Standard_Real aTol)
747 Standard_Boolean bFlag1, bFlag2;
749 Handle(Geom2d_Curve) aPC1 = aC.FirstCurve2d();
750 Handle(Geom2d_Curve) aPC2 = aC.SecondCurve2d();
751 if( !aPC1.IsNull() && !aPC2.IsNull() ) {
752 Standard_Real aMidPar = IntTools_Tools::IntermediatePoint(aT1, aT2);
756 aPC1->D0(aMidPar, aPnt2D);
757 bFlag1 = IsPointInOnFace(aF1, aPnt2D);
762 aPC2->D0(aMidPar, aPnt2D);
763 bFlag2 = IsPointInOnFace(aF2, aPnt2D);
768 bFlag1=IsValidBlockForFace (aT1, aT2, aC, aF1, aTol);
772 bFlag2=IsValidBlockForFace (aT1, aT2, aC, aF2, aTol);
775 //=======================================================================
776 //function : IsVertexOnLine
778 //=======================================================================
779 Standard_Boolean IntTools_Context::IsVertexOnLine
780 (const TopoDS_Vertex& aV,
781 const IntTools_Curve& aC,
782 const Standard_Real aTolC,
785 Standard_Boolean bRet;
788 aTolV=BRep_Tool::Tolerance(aV);
789 bRet=IntTools_Context::IsVertexOnLine(aV, aTolV, aC, aTolC , aT);
793 //=======================================================================
794 //function : IsVertexOnLine
796 //=======================================================================
797 Standard_Boolean IntTools_Context::IsVertexOnLine
798 (const TopoDS_Vertex& aV,
799 const Standard_Real aTolV,
800 const IntTools_Curve& aC,
801 const Standard_Real aTolC,
804 Standard_Real aFirst, aLast, aDist, aTolSum;
805 Standard_Integer aNbProj;
808 aPv=BRep_Tool::Pnt(aV);
810 Handle(Geom_Curve) aC3D=aC.Curve();
815 GeomAdaptor_Curve aGAC(aC3D);
816 GeomAbs_CurveType aType=aGAC.GetType();
817 if (aType==GeomAbs_BSplineCurve ||
818 aType==GeomAbs_BezierCurve) {
825 aTolSum=2.*aTolSum;//xft
830 aFirst=aC3D->FirstParameter();
831 aLast =aC3D->LastParameter();
833 //Checking extermities first
834 if (!Precision::IsInfinite(aFirst)) {
835 gp_Pnt aPCFirst=aC3D->Value(aFirst);
836 aDist=aPv.Distance(aPCFirst);
837 if (aDist < aTolSum) {
841 Extrema_LocateExtPC anExt(aPv, aGAC, aFirst, 1.e-10);
844 Extrema_POnCurv aPOncurve = anExt.Point();
845 aT = aPOncurve.Parameter();
847 if((aT > (aLast + aFirst) * 0.5) ||
848 (aPv.Distance(aPOncurve.Value()) > aTolSum) ||
849 (aPCFirst.Distance(aPOncurve.Value()) < Precision::Confusion()))
854 return Standard_True;
858 //if (!Precision::IsInfinite(aFirst)) {
859 if (!Precision::IsInfinite(aLast)) {
860 gp_Pnt aPCLast=aC3D->Value(aLast);
861 aDist=aPv.Distance(aPCLast);
862 if (aDist < aTolSum) {
866 Extrema_LocateExtPC anExt(aPv, aGAC, aLast, 1.e-10);
869 Extrema_POnCurv aPOncurve = anExt.Point();
870 aT = aPOncurve.Parameter();
872 if((aT < (aLast + aFirst) * 0.5) ||
873 (aPv.Distance(aPOncurve.Value()) > aTolSum) ||
874 (aPCLast.Distance(aPOncurve.Value()) < Precision::Confusion()))
879 return Standard_True;
883 GeomAPI_ProjectPointOnCurve& aProjector=ProjPT(aC3D);
884 aProjector.Perform(aPv);
886 aNbProj=aProjector.NbPoints();
888 Handle(Geom_BoundedCurve) aBC=
889 Handle(Geom_BoundedCurve)::DownCast(aC3D);
891 gp_Pnt aPStart=aBC->StartPoint();
892 gp_Pnt aPEnd =aBC->EndPoint();
894 aDist=aPv.Distance(aPStart);
895 if (aDist < aTolSum) {
897 return Standard_True;
900 aDist=aPv.Distance(aPEnd);
901 if (aDist < aTolSum) {
903 return Standard_True;
907 return Standard_False;
910 aDist=aProjector.LowerDistance();
912 if (aDist > aTolSum) {
913 return Standard_False;
916 aT=aProjector.LowerDistanceParameter();
918 return Standard_True;
920 //=======================================================================
921 //function : ProjectPointOnEdge
923 //=======================================================================
924 Standard_Boolean IntTools_Context::ProjectPointOnEdge
926 const TopoDS_Edge& anEdge,
929 Standard_Integer aNbPoints;
931 GeomAPI_ProjectPointOnCurve& aProjector=ProjPC(anEdge);
932 aProjector.Perform(aP);
934 aNbPoints=aProjector.NbPoints();
936 aT=aProjector.LowerDistanceParameter();
937 return Standard_True;
939 return Standard_False;
942 //=======================================================================
943 //function : SetPOnSProjectionTolerance
945 //=======================================================================
946 void IntTools_Context::SetPOnSProjectionTolerance(const Standard_Real theValue)
948 myPOnSTolerance = theValue;
949 clearCachedPOnSProjectors();
952 //=======================================================================
953 //function : clearCachedPOnSProjectors
955 //=======================================================================
956 void IntTools_Context::clearCachedPOnSProjectors()
958 GeomAPI_ProjectPointOnSurf* pProjPS;
959 BOPCol_DataMapIteratorOfDataMapOfShapeAddress aIt(myProjPSMap);
960 for (; aIt.More(); aIt.Next()) {
961 Standard_Address anAdr=aIt.Value();
962 pProjPS=(GeomAPI_ProjectPointOnSurf*)anAdr;
963 (*pProjPS).~GeomAPI_ProjectPointOnSurf();
964 myAllocator->Free(anAdr);