0024023: Revamp the OCCT Handle -- ambiguity
[occt.git] / src / IntTools / IntTools_Tools.cxx
... / ...
CommitLineData
1// Created on: 2000-11-16
2// Created by: Peter KURNEV
3// Copyright (c) 2000-2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#include <IntTools_Tools.ixx>
17
18#include <Precision.hxx>
19
20#include <TopExp_Explorer.hxx>
21#include <TopTools_IndexedDataMapOfShapeShape.hxx>
22
23#include <TopoDS.hxx>
24#include <TopoDS_Shape.hxx>
25#include <TopoDS_Vertex.hxx>
26#include <TopoDS_Edge.hxx>
27#include <TopoDS_Face.hxx>
28#include <TopoDS_Wire.hxx>
29#include <TopLoc_Location.hxx>
30
31#include <BRep_Builder.hxx>
32#include <BRep_Tool.hxx>
33#include <BRepAdaptor_Surface.hxx>
34#include <BRepAdaptor_Curve.hxx>
35#include <BRepAdaptor_Surface.hxx>
36
37#include <gp_Pnt.hxx>
38#include <gp_Pnt2d.hxx>
39#include <gp.hxx>
40#include <gp_Lin.hxx>
41#include <gp_Dir.hxx>
42#include <gp_Ax1.hxx>
43
44#include <Geom_Curve.hxx>
45#include <GeomAdaptor_Surface.hxx>
46#include <Geom_Surface.hxx>
47#include <GeomAPI_ProjectPointOnSurf.hxx>
48#include <GeomAPI_ProjectPointOnCurve.hxx>
49#include <GeomAdaptor_Curve.hxx>
50#include <GeomAbs_CurveType.hxx>
51#include <Geom_Line.hxx>
52#include <Geom2d_Curve.hxx>
53#include <Geom_BoundedCurve.hxx>
54#include <Geom_Geometry.hxx>
55#include <Geom_TrimmedCurve.hxx>
56#include <Geom2d_TrimmedCurve.hxx>
57
58#include <IntTools_FClass2d.hxx>
59#include <IntTools_Curve.hxx>
60#include <IntTools_SequenceOfCurves.hxx>
61
62static
63 void ParabolaTolerance(const Handle(Geom_Curve)& ,
64 const Standard_Real ,
65 const Standard_Real ,
66 const Standard_Real ,
67 Standard_Real& ,
68 Standard_Real& );
69
70//=======================================================================
71//function : HasInternalEdge
72//purpose :
73//=======================================================================
74 Standard_Boolean IntTools_Tools::HasInternalEdge(const TopoDS_Wire& aW)
75{
76 Standard_Boolean bFlag=Standard_True;
77
78 TopExp_Explorer anExp(aW, TopAbs_EDGE);
79 for (; anExp.More(); anExp.Next()) {
80 const TopoDS_Edge& aE=TopoDS::Edge(anExp.Current());
81 TopAbs_Orientation anOr=aE.Orientation();
82 if (anOr==TopAbs_INTERNAL) {
83 return bFlag;
84 }
85 }
86 return !bFlag;
87}
88
89//=======================================================================
90//function : IsClosed
91//purpose :
92//=======================================================================
93 Standard_Boolean IntTools_Tools::IsClosed (const Handle(Geom_Curve)& aC3D)
94{
95 Standard_Boolean bRet;
96 Standard_Real aF, aL, aDist, aPC;
97 gp_Pnt aP1, aP2;
98
99 Handle (Geom_BoundedCurve) aGBC=
100 Handle (Geom_BoundedCurve)::DownCast(aC3D);
101 if (aGBC.IsNull()) {
102 return Standard_False;
103 }
104
105 aF=aC3D->FirstParameter();
106 aL=aC3D-> LastParameter();
107
108 aC3D->D0(aF, aP1);
109 aC3D->D0(aL, aP2);
110
111
112 //
113 aPC=Precision::Confusion();
114 aPC=aPC*aPC;
115 aDist=aP1.SquareDistance(aP2);
116 bRet=aDist<aPC;
117 return bRet;
118}
119
120//=======================================================================
121//function : RejectLines
122//purpose :
123//=======================================================================
124 void IntTools_Tools::RejectLines(const IntTools_SequenceOfCurves& aSIn,
125 IntTools_SequenceOfCurves& aSOut)
126{
127 Standard_Integer i, j, aNb;
128 Standard_Boolean bFlag;
129 Handle (Geom_Curve) aC3D;
130
131 gp_Dir aD1, aD2;
132
133 aSOut.Clear();
134
135 aNb=aSIn.Length();
136 for (i=1; i<=aNb; i++) {
137 const IntTools_Curve& IC=aSIn(i);
138 aC3D=IC.Curve();
139 //
140 Handle (Geom_TrimmedCurve) aGTC=
141 Handle (Geom_TrimmedCurve)::DownCast(aC3D);
142
143 if (!aGTC.IsNull()) {
144 aC3D=aGTC->BasisCurve();
145 IntTools_Curve* pIC=(IntTools_Curve*) &IC;
146 pIC->SetCurve(aC3D);
147 }
148 //
149 Handle (Geom_Line) aGLine=
150 Handle (Geom_Line)::DownCast(aC3D);
151
152 if (aGLine.IsNull()) {
153 aSOut.Clear();
154 for (j=1; j<=aNb; j++) {
155 aSOut.Append(aSIn(j));
156 }
157 return;
158 }
159 //
160 gp_Lin aLin=aGLine->Lin();
161 aD2=aLin.Direction();
162 if (i==1) {
163 aSOut.Append(IC);
164 aD1=aD2;
165 continue;
166 }
167
168 bFlag=IntTools_Tools::IsDirsCoinside(aD1, aD2);
169 if (!bFlag) {
170 aSOut.Append(IC);
171 return;
172 }
173 }
174}
175
176//=======================================================================
177//function : IsDirsCoinside
178//purpose :
179//=======================================================================
180 Standard_Boolean IntTools_Tools::IsDirsCoinside (const gp_Dir& D1, const gp_Dir& D2)
181{
182 Standard_Boolean bFlag;
183 gp_Pnt P1(D1.X(), D1.Y(), D1.Z());
184 gp_Pnt P2(D2.X(), D2.Y(), D2.Z());
185 Standard_Real dLim=0.0002, d;
186 d=P1.Distance (P2);
187 bFlag= (d<dLim || fabs (2.-d)<dLim);
188 return bFlag;
189}
190
191//=======================================================================
192//function : IsDirsCoinside
193//purpose :
194//=======================================================================
195 Standard_Boolean IntTools_Tools::IsDirsCoinside (const gp_Dir& D1,
196 const gp_Dir& D2,
197 const Standard_Real dLim)
198{
199 Standard_Boolean bFlag;
200 Standard_Real d;
201 //
202 gp_Pnt P1(D1.X(), D1.Y(), D1.Z());
203 gp_Pnt P2(D2.X(), D2.Y(), D2.Z());
204 d=P1.Distance (P2);
205 bFlag= (d<dLim || fabs (2.-d)<dLim);
206 return bFlag;
207}
208//=======================================================================
209//function : SplitCurve
210//purpose :
211//=======================================================================
212 Standard_Integer IntTools_Tools::SplitCurve(const IntTools_Curve& IC,
213 IntTools_SequenceOfCurves& aCvs)
214{
215 Handle (Geom_Curve) aC3D =IC.Curve();
216 if(aC3D.IsNull())
217 return 0;
218 //
219 Handle (Geom2d_Curve) aC2D1=IC.FirstCurve2d();
220 Handle (Geom2d_Curve) aC2D2=IC.SecondCurve2d();
221 Standard_Boolean bIsClosed;
222
223 bIsClosed=IntTools_Tools::IsClosed(aC3D);
224 if (!bIsClosed) {
225 return 0;
226 }
227
228 Standard_Real aF, aL, aMid;
229
230 //
231 aF=aC3D->FirstParameter();
232 aL=aC3D->LastParameter();
233 aMid=0.5*(aF+aL);
234 GeomAdaptor_Curve aGAC(aC3D);
235 GeomAbs_CurveType aCT=aGAC.GetType();
236 if (aCT==GeomAbs_BSplineCurve ||
237 aCT==GeomAbs_BezierCurve) {
238 //aMid=0.5*aMid;
239 aMid=IntTools_Tools::IntermediatePoint(aF, aL);
240 }
241 //
242 Handle(Geom_Curve) aC3DNewF, aC3DNewL;
243 aC3DNewF =new Geom_TrimmedCurve (aC3D, aF, aMid);
244 aC3DNewL =new Geom_TrimmedCurve (aC3D, aMid, aL);
245
246 //
247 Handle (Geom2d_Curve) aC2D1F, aC2D1L, aC2D2F, aC2D2L;
248 //
249 if(!aC2D1.IsNull()) {
250 aC2D1F=new Geom2d_TrimmedCurve (aC2D1, aF, aMid);
251 aC2D1L=new Geom2d_TrimmedCurve (aC2D1, aMid, aL);
252 }
253
254 if(!aC2D2.IsNull()) {
255 aC2D2F=new Geom2d_TrimmedCurve (aC2D2, aF, aMid);
256 aC2D2L=new Geom2d_TrimmedCurve (aC2D2, aMid, aL);
257 }
258 //
259
260 IntTools_Curve aIC1(aC3DNewF, aC2D1F, aC2D2F);
261 IntTools_Curve aIC2(aC3DNewL, aC2D1L, aC2D2L);
262 //
263 aCvs.Append(aIC1);
264 //
265 aCvs.Append(aIC2);
266 //
267 return 2;
268}
269
270//=======================================================================
271//function : IntermediatePoint
272//purpose :
273//=======================================================================
274 Standard_Real IntTools_Tools::IntermediatePoint (const Standard_Real aFirst,
275 const Standard_Real aLast)
276{
277 //define parameter division number as 10*e^(-M_PI) = 0.43213918
278 const Standard_Real PAR_T = 0.43213918;
279 Standard_Real aParm;
280 aParm=(1.-PAR_T)*aFirst + PAR_T*aLast;
281 return aParm;
282}
283
284//=======================================================================
285//function : IsVertex
286//purpose :
287//=======================================================================
288 Standard_Boolean IntTools_Tools::IsVertex (const gp_Pnt& aP,
289 const Standard_Real aTolPV,
290 const TopoDS_Vertex& aV)
291{
292 Standard_Boolean bRet;
293 Standard_Real aTolV, aD, dTol;
294 gp_Pnt aPv;
295
296 aTolV=BRep_Tool::Tolerance(aV);
297 //
298 dTol=Precision::Confusion();
299 aTolV=aTolV+aTolPV+dTol;
300 //
301 aPv=BRep_Tool::Pnt(aV);
302 //
303 aD=aPv.SquareDistance(aP);
304 aTolV=aTolV*aTolV;
305 bRet=(aD<=aTolV);
306 return bRet;
307}
308
309
310//=======================================================================
311//function : IsVertex
312//purpose :
313//=======================================================================
314 Standard_Boolean IntTools_Tools::IsVertex (const IntTools_CommonPrt& aCmnPrt)
315{
316 Standard_Boolean anIsVertex;
317 Standard_Real aParam;
318
319 const TopoDS_Edge& aE1=aCmnPrt.Edge1();
320 const IntTools_Range& aR1=aCmnPrt.Range1();
321 aParam=0.5*(aR1.First()+aR1.Last());
322 anIsVertex=IntTools_Tools::IsVertex (aE1, aParam);
323
324 if (anIsVertex) {
325 return Standard_True;
326 }
327
328 const TopoDS_Edge& aE2=aCmnPrt.Edge2();
329 const IntTools_SequenceOfRanges& aRs2=aCmnPrt.Ranges2();
330 const IntTools_Range& aR2=aRs2(1);
331 aParam=0.5*(aR2.First()+aR2.Last());
332 anIsVertex=IntTools_Tools::IsVertex (aE2, aParam);
333 if (anIsVertex) {
334 return Standard_True;
335 }
336 return Standard_False;
337}
338
339//=======================================================================
340//function : IsVertex
341//purpose :
342//=======================================================================
343 Standard_Boolean IntTools_Tools::IsVertex (const TopoDS_Edge& aE,
344 const TopoDS_Vertex& aV,
345 const Standard_Real t)
346{
347 Standard_Real aTolV, aTolV2, d2;
348 gp_Pnt aPv, aPt;
349
350 BRepAdaptor_Curve aBAC(aE);
351 aBAC.D0(t, aPt);
352
353 aTolV=BRep_Tool::Tolerance(aV);
354 aTolV2=aTolV*aTolV;
355 aPv=BRep_Tool::Pnt(aV);
356 d2=aPv.SquareDistance (aPt);
357 if (d2 < aTolV2) {
358 return Standard_True;
359 }
360 return Standard_False;
361}
362//=======================================================================
363//function : IsVertex
364//purpose :
365//=======================================================================
366 Standard_Boolean IntTools_Tools::IsVertex (const TopoDS_Edge& aE,
367 const Standard_Real t)
368{
369 Standard_Real aTolV, aTolV2, d2;
370 TopoDS_Vertex aV;
371 gp_Pnt aPv, aPt;
372
373 BRepAdaptor_Curve aBAC(aE);
374 aBAC.D0(t, aPt);
375
376 TopExp_Explorer anExp(aE, TopAbs_VERTEX);
377 for (; anExp.More(); anExp.Next()) {
378 aV=TopoDS::Vertex (anExp.Current());
379 aTolV=BRep_Tool::Tolerance(aV);
380 aTolV2=aTolV*aTolV;
381 aTolV2=1.e-12;
382 aPv=BRep_Tool::Pnt(aV);
383 d2=aPv.SquareDistance (aPt);
384 if (d2 < aTolV2) {
385 return Standard_True;
386 }
387 }
388 return Standard_False;
389}
390
391
392//=======================================================================
393//function : ComputeVV
394//purpose :
395//=======================================================================
396 Standard_Integer IntTools_Tools::ComputeVV(const TopoDS_Vertex& aV1,
397 const TopoDS_Vertex& aV2)
398{
399 Standard_Real aTolV1, aTolV2, aTolSum, d;
400 gp_Pnt aP1, aP2;
401
402 aTolV1=BRep_Tool::Tolerance(aV1);
403 aTolV2=BRep_Tool::Tolerance(aV2);
404 aTolSum=aTolV1+aTolV2;
405
406 aP1=BRep_Tool::Pnt(aV1);
407 aP2=BRep_Tool::Pnt(aV2);
408 aTolSum=aTolSum*aTolSum;
409 d=aP1.SquareDistance(aP2);
410 if (d<aTolSum) {
411 return 0;
412 }
413 return -1;
414}
415
416//=======================================================================
417//function : MakeFaceFromWireAndFace
418//purpose :
419//=======================================================================
420 void IntTools_Tools::MakeFaceFromWireAndFace(const TopoDS_Wire& aW,
421 const TopoDS_Face& aF,
422 TopoDS_Face& aFNew)
423{
424 TopoDS_Face aFF;
425 aFF=aF;
426 aFF.Orientation(TopAbs_FORWARD);
427 aFNew=TopoDS::Face (aFF.EmptyCopied());
428 BRep_Builder BB;
429 BB.Add(aFNew, aW);
430}
431
432//=======================================================================
433//function : ClassifyPointByFace
434//purpose :
435//=======================================================================
436 TopAbs_State IntTools_Tools::ClassifyPointByFace(const TopoDS_Face& aF,
437 const gp_Pnt2d& aP2d)
438{
439 Standard_Real aFaceTolerance;
440 TopAbs_State aState;
441
442 aFaceTolerance=BRep_Tool::Tolerance(aF);
443 IntTools_FClass2d aClass2d(aF, aFaceTolerance);
444 aState=aClass2d.Perform(aP2d);
445
446 return aState;
447}
448
449//=======================================================================
450//function : IsMiddlePointsEqual
451//purpose :
452//=======================================================================
453 Standard_Boolean IntTools_Tools::IsMiddlePointsEqual(const TopoDS_Edge& aE1,
454 const TopoDS_Edge& aE2)
455
456{
457 Standard_Boolean bRet;
458 Standard_Real f1, l1, m1, f2, l2, m2, aTol1, aTol2, aSumTol, aD2;
459 gp_Pnt aP1, aP2;
460
461 aTol1=BRep_Tool::Tolerance(aE1);
462 Handle(Geom_Curve) C1=BRep_Tool::Curve(aE1, f1, l1);
463 m1=0.5*(f1+l1);
464 C1->D0(m1, aP1);
465
466 aTol2=BRep_Tool::Tolerance(aE2);
467 Handle(Geom_Curve) C2=BRep_Tool::Curve(aE2, f2, l2);
468 m2=0.5*(f2+l2);
469 C2->D0(m2, aP2);
470
471 aSumTol=aTol1+aTol2;
472 aSumTol=aSumTol*aSumTol;
473 aD2=aP1.SquareDistance(aP2);
474 bRet=aD2<aSumTol;
475 return bRet;
476}
477
478//=======================================================================
479//function : CurveTolerance
480//purpose :
481//=======================================================================
482 Standard_Real IntTools_Tools::CurveTolerance(const Handle(Geom_Curve)& aC3D,
483 const Standard_Real aTolBase)
484{
485 Standard_Real aTolReached, aTf, aTl, aTolMin, aTolMax;
486
487 aTolReached=aTolBase;
488 //
489 if (aC3D.IsNull()) {
490 return aTolReached;
491 }
492 //
493 Handle(Geom_TrimmedCurve) aCT3D=Handle(Geom_TrimmedCurve)::DownCast(aC3D);
494 if (aCT3D.IsNull()) {
495 return aTolReached;
496 }
497 //
498 aTolMin=aTolBase;
499 aTolMax=aTolBase;
500 //
501 aTf=aCT3D->FirstParameter();
502 aTl=aCT3D->LastParameter();
503 //
504 GeomAdaptor_Curve aGAC(aCT3D);
505 GeomAbs_CurveType aCType=aGAC.GetType();
506 //
507 if (aCType==GeomAbs_Parabola) {
508 Handle(Geom_Curve) aC3DBase=aCT3D->BasisCurve();
509 ParabolaTolerance(aC3DBase, aTf, aTl, aTolBase, aTolMin, aTolMax);
510 aTolReached=aTolMax;
511 }
512 //
513 return aTolReached;
514}
515
516#include <Geom_Parabola.hxx>
517#include <gp_Parab.hxx>
518#include <BndLib_Add3dCurve.hxx>
519#include <BRepLib_CheckCurveOnSurface.hxx>
520//=======================================================================
521//function : ParabolaTolerance
522//purpose :
523//=======================================================================
524void ParabolaTolerance(const Handle(Geom_Curve)& aC3D,
525 const Standard_Real aTf,
526 const Standard_Real aTl,
527 const Standard_Real aTol,
528 Standard_Real& aTolMin,
529 Standard_Real& aTolMax)
530{
531
532 aTolMin=aTol;
533 aTolMax=aTol;
534
535 Handle(Geom_Parabola) aGP=Handle(Geom_Parabola)::DownCast(aC3D);
536 if (aGP.IsNull()){
537 return;
538 }
539
540 Standard_Integer aNbPoints;
541 Standard_Real aFocal, aX1, aX2, aTol1, aTol2;
542 gp_Pnt aPf, aPl;
543 gp_Parab aParab=aGP->Parab();
544 gp_Ax1 aXAxis=aParab.XAxis();
545 Handle(Geom_Line) aGAxis=new Geom_Line(aXAxis);
546
547 aFocal=aGP->Focal();
548 if (aFocal==0.) {
549 return;
550 }
551 //
552 // aTol1
553 aTol1=aTol;
554 aX1=0.;
555 aGP->D0(aTf, aPf);
556 GeomAPI_ProjectPointOnCurve aProj1(aPf, aGAxis);
557 aNbPoints=aProj1.NbPoints();
558 if (aNbPoints) {
559 aX1=aProj1.LowerDistanceParameter();
560 }
561 if (aX1>=0.) {
562 aTol1=aTol*sqrt(0.5*aX1/aFocal);
563 }
564 if (aTol1==0.) {
565 aTol1=aTol;
566 }
567 //
568 // aTol2
569 aTol2=aTol;
570 aX2=0.;
571 aGP->D0(aTl, aPl);
572 GeomAPI_ProjectPointOnCurve aProj2(aPl, aGAxis);
573 aNbPoints=aProj2.NbPoints();
574 if (aNbPoints) {
575 aX2=aProj2.LowerDistanceParameter();
576 }
577
578 if (aX2>=0.) {
579 aTol2=aTol*sqrt(0.5*aX2/aFocal);
580 }
581 if (aTol2==0.) {
582 aTol2=aTol;
583 }
584 //
585 aTolMax=(aTol1>aTol2) ? aTol1 : aTol2;
586 aTolMin=(aTol1<aTol2) ? aTol1 : aTol2;
587}
588/////////////////////////////////////////////////////////////////////////
589//=======================================================================
590//function : CheckCurve
591//purpose :
592//=======================================================================
593Standard_Boolean IntTools_Tools::CheckCurve(const Handle (Geom_Curve)& aC3D,
594 const Standard_Real aTolR3D,
595 Bnd_Box& aBox)
596{
597 Standard_Boolean bRet;
598 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax, dX, dY, dZ;
599 Standard_Real dS, aTol;
600 GeomAdaptor_Curve aGAC;
601 //
602 aGAC.Load(aC3D);
603 BndLib_Add3dCurve::Add(aGAC, aTolR3D, aBox);
604 // 910/B1
605 aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
606 dX=aXmax-aXmin;
607 dY=aYmax-aYmin;
608 dZ=aZmax-aZmin;
609 dS=1.e-12;
610 aTol=2.*aTolR3D+dS;
611 bRet=(dX>aTol || dY>aTol || dZ>aTol);
612 //
613 return bRet;
614}
615//=======================================================================
616//function : IsOnPave
617//purpose :
618//=======================================================================
619Standard_Boolean IntTools_Tools::IsOnPave(const Standard_Real aT1,
620 const IntTools_Range& aRange,
621 const Standard_Real aTolerance)
622{
623 Standard_Boolean firstisonpave1, firstisonpave2, bIsOnPave;
624 //
625 firstisonpave1 = (Abs(aRange.First() - aT1) < aTolerance);
626 firstisonpave2 = (Abs(aRange.Last() - aT1) < aTolerance);
627 bIsOnPave=(firstisonpave1 || firstisonpave2);
628 return bIsOnPave;
629}
630//=======================================================================
631// function: VertexParameters
632// purpose:
633//=======================================================================
634void IntTools_Tools::VertexParameters(const IntTools_CommonPrt& aCPart,
635 Standard_Real& aT1,
636 Standard_Real& aT2)
637{
638 const IntTools_Range& aR1=aCPart.Range1();
639 aT1=0.5*(aR1.First()+aR1.Last());
640 //
641 if((aCPart.VertexParameter1() >= aR1.First()) &&
642 (aCPart.VertexParameter1() <= aR1.Last())) {
643 aT1 = aCPart.VertexParameter1();
644 }
645 //
646 const IntTools_SequenceOfRanges& aRanges2=aCPart.Ranges2();
647 const IntTools_Range& aR2=aRanges2(1);
648 aT2=0.5*(aR2.First()+aR2.Last());
649 //
650 if((aCPart.VertexParameter2() >= aR2.First()) &&
651 (aCPart.VertexParameter2() <= aR2.Last())) {
652 aT2 = aCPart.VertexParameter2();
653 }
654}
655//=======================================================================
656// function: VertexParameter
657// purpose:
658//=======================================================================
659void IntTools_Tools::VertexParameter(const IntTools_CommonPrt& aCPart,
660 Standard_Real& aT)
661{
662 const IntTools_Range& aR=aCPart.Range1();
663 aT=0.5*(aR.First()+aR.Last());
664 if((aCPart.VertexParameter1() >= aR.First()) &&
665 (aCPart.VertexParameter1() <= aR.Last())) {
666 aT = aCPart.VertexParameter1();
667 }
668}
669//=======================================================================
670// function: IsOnPave1
671// purpose:
672//=======================================================================
673Standard_Boolean IntTools_Tools::IsOnPave1(const Standard_Real aTR,
674 const IntTools_Range& aCPRange,
675 const Standard_Real aTolerance)
676{
677 Standard_Boolean bIsOnPave;
678 Standard_Real aT1, aT2, dT1, dT2;
679 //
680 aT1=aCPRange.First();
681 aT2=aCPRange.Last();
682 bIsOnPave=(aTR>=aT1 && aTR<=aT1);
683 if (bIsOnPave) {
684 return bIsOnPave;
685 }
686 //
687 dT1=Abs(aTR-aT1);
688 dT2=Abs(aTR-aT2);
689 bIsOnPave=(dT1<=aTolerance || dT2<=aTolerance);
690 return bIsOnPave;
691}
692//=======================================================================
693// function: IsInRange
694// purpose:
695//=======================================================================
696Standard_Boolean IntTools_Tools::IsInRange(const IntTools_Range& aRRef,
697 const IntTools_Range& aR,
698 const Standard_Real aTolerance)
699{
700 Standard_Boolean bIsIn;
701 Standard_Real aT1, aT2, aTRef1, aTRef2;
702 //
703 aR.Range(aT1, aT2);
704 aRRef.Range(aTRef1, aTRef2);
705 //
706 aTRef1-=aTolerance;
707 aTRef2+=aTolerance;
708 //
709 bIsIn = (aT1>=aTRef1 && aT1<=aTRef2) ||
710 (aT2>=aTRef1 && aT2<=aTRef2);
711 //
712 return bIsIn;
713}
714//=======================================================================
715//function : SegPln
716//purpose :
717//=======================================================================
718Standard_Integer IntTools_Tools::SegPln(const gp_Lin& theLin,
719 const Standard_Real theTLin1,
720 const Standard_Real theTLin2,
721 const Standard_Real theTolLin,
722 const gp_Pln& thePln,
723 const Standard_Real theTolPln,
724 gp_Pnt& theP,
725 Standard_Real& theTP,
726 Standard_Real& theTolP,
727 Standard_Real& theTPmin,
728 Standard_Real& theTPmax)
729{
730 Standard_Integer iRet;
731 Standard_Real aTol, aA, aB, aC, aD, aE, aH, aTP, aDist1, aDist2;
732 gp_Pnt aP1, aP2;
733 //
734 iRet=0;
735 aTol=theTolLin+theTolPln;
736 //
737 const gp_Ax3& aPosPln=thePln.Position();
738 const gp_Dir& aDirPln=aPosPln.Direction();
739 const gp_Pnt& aLocPln=aPosPln.Location();
740 //
741 const gp_Dir& aDirLin=theLin.Direction();
742 const gp_Pnt& aLocLin=theLin.Location();
743 //
744 aP1.SetXYZ(aLocLin.XYZ()+theTLin1*aDirLin.XYZ());
745 aDist1=aDirPln.X()*(aP1.X()-aLocPln.X())+
746 aDirPln.Y()*(aP1.Y()-aLocPln.Y())+
747 aDirPln.Z()*(aP1.Z()-aLocPln.Z());
748 //
749 aP2.SetXYZ(aLocLin.XYZ()+theTLin2*aDirLin.XYZ());
750 aDist2=aDirPln.X()*(aP2.X()-aLocPln.X())+
751 aDirPln.Y()*(aP2.Y()-aLocPln.Y())+
752 aDirPln.Z()*(aP2.Z()-aLocPln.Z());
753 //
754 if (aDist1<aTol && aDist2<aTol){
755 iRet=1; // common block
756 return iRet;
757 }
758 //
759 if (aDist1*aDist2 > 0.) {
760 iRet=2; // segment lays on one side to the Plane
761 return iRet;
762 }
763 //
764 thePln.Coefficients(aA, aB, aC, aD);
765 aE=aA*aLocLin.X()+aB*aLocLin.Y()+aC*aLocLin.Z()+aD;
766 aH=aA*aDirLin.X()+aB*aDirLin.Y()+aC*aDirLin.Z();
767 aTP=-aE/aH;
768 if (aTP < theTLin1-aTol || aTP > theTLin2+aTol) {
769 iRet=3; // no intersections due to range of the Line
770 return iRet;
771 }
772 //
773 theTP=aTP;
774 theP.SetXYZ(aLocLin.XYZ()+aTP*aDirLin.XYZ());
775 theTolP=aTol;
776 theTPmin=theTP-theTolPln;
777 theTPmax=theTP+theTolPln;
778 iRet=0; // intersection point
779 return iRet;
780}
781
782//=======================================================================
783// Function : ComputeTolerance
784// purpose :
785//=======================================================================
786Standard_Boolean IntTools_Tools::ComputeTolerance
787 (const Handle(Geom_Curve)& theCurve3D,
788 const Handle(Geom2d_Curve)& theCurve2D,
789 const Handle(Geom_Surface)& theSurf,
790 const Standard_Real theFirst,
791 const Standard_Real theLast,
792 Standard_Real& theMaxDist,
793 Standard_Real& theMaxPar)
794{
795 BRepLib_CheckCurveOnSurface aCS;
796 //
797 aCS.Init(theCurve3D, theCurve2D, theSurf, theFirst, theLast);
798 aCS.Perform();
799 if (!aCS.IsDone()) {
800 return Standard_False;
801 }
802 //
803 theMaxDist = aCS.MaxDistance();
804 theMaxPar = aCS.MaxParameter();
805 //
806 return Standard_True;
807}