1 // Created on: 2000-11-23
2 // Created by: Michael KLOKOV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <IntTools_FaceFace.ixx>
18 #include <Precision.hxx>
20 #include <TColStd_HArray1OfReal.hxx>
21 #include <TColStd_Array1OfReal.hxx>
22 #include <TColStd_Array1OfInteger.hxx>
23 #include <TColStd_SequenceOfReal.hxx>
24 #include <TColStd_ListOfInteger.hxx>
25 #include <TColStd_ListIteratorOfListOfInteger.hxx>
26 #include <TColStd_Array1OfListOfInteger.hxx>
28 #include <gp_Lin2d.hxx>
29 #include <gp_Ax22d.hxx>
30 #include <gp_Circ2d.hxx>
31 #include <gp_Torus.hxx>
32 #include <gp_Cylinder.hxx>
34 #include <Bnd_Box.hxx>
36 #include <TColgp_HArray1OfPnt2d.hxx>
37 #include <TColgp_SequenceOfPnt2d.hxx>
38 #include <TColgp_Array1OfPnt.hxx>
39 #include <TColgp_Array1OfPnt2d.hxx>
41 #include <IntAna_QuadQuadGeo.hxx>
43 #include <IntSurf_PntOn2S.hxx>
44 #include <IntSurf_LineOn2S.hxx>
45 #include <IntSurf_PntOn2S.hxx>
46 #include <IntSurf_ListOfPntOn2S.hxx>
47 #include <IntRes2d_Domain.hxx>
48 #include <ProjLib_Plane.hxx>
50 #include <IntPatch_GLine.hxx>
51 #include <IntPatch_RLine.hxx>
52 #include <IntPatch_WLine.hxx>
53 #include <IntPatch_ALine.hxx>
54 #include <IntPatch_ALineToWLine.hxx>
59 #include <Extrema_ExtCC.hxx>
60 #include <Extrema_POnCurv.hxx>
61 #include <BndLib_AddSurface.hxx>
63 #include <Adaptor3d_SurfacePtr.hxx>
64 #include <Adaptor2d_HLine2d.hxx>
66 #include <GeomAbs_SurfaceType.hxx>
67 #include <GeomAbs_CurveType.hxx>
69 #include <Geom_Surface.hxx>
70 #include <Geom_Line.hxx>
71 #include <Geom_Circle.hxx>
72 #include <Geom_Ellipse.hxx>
73 #include <Geom_Parabola.hxx>
74 #include <Geom_Hyperbola.hxx>
75 #include <Geom_TrimmedCurve.hxx>
76 #include <Geom_BSplineCurve.hxx>
77 #include <Geom_RectangularTrimmedSurface.hxx>
78 #include <Geom_OffsetSurface.hxx>
79 #include <Geom_Curve.hxx>
80 #include <Geom_Conic.hxx>
82 #include <Geom2d_TrimmedCurve.hxx>
83 #include <Geom2d_BSplineCurve.hxx>
84 #include <Geom2d_Line.hxx>
85 #include <Geom2d_Curve.hxx>
86 #include <Geom2d_Circle.hxx>
88 #include <Geom2dAPI_InterCurveCurve.hxx>
89 #include <Geom2dInt_GInter.hxx>
90 #include <GeomAdaptor_Curve.hxx>
91 #include <GeomAdaptor_HSurface.hxx>
92 #include <GeomAdaptor_Surface.hxx>
93 #include <GeomLib_CheckBSplineCurve.hxx>
94 #include <GeomLib_Check2dBSplineCurve.hxx>
96 #include <GeomInt_WLApprox.hxx>
97 #include <GeomProjLib.hxx>
98 #include <GeomAPI_ProjectPointOnSurf.hxx>
99 #include <Geom2dAdaptor_Curve.hxx>
100 #include <TopoDS.hxx>
101 #include <TopoDS_Edge.hxx>
102 #include <TopExp_Explorer.hxx>
104 #include <BRep_Tool.hxx>
105 #include <BRepTools.hxx>
106 #include <BRepAdaptor_Surface.hxx>
108 #include <IntTools_Curve.hxx>
109 #include <IntTools_Tools.hxx>
110 #include <IntTools_Tools.hxx>
111 #include <IntTools_TopolTool.hxx>
112 #include <IntTools_PntOnFace.hxx>
113 #include <IntTools_PntOn2Faces.hxx>
114 #include <IntTools_Context.hxx>
115 #include <IntSurf_ListIteratorOfListOfPntOn2S.hxx>
116 #include <GeomInt.hxx>
119 void RefineVector(gp_Vec2d& aV2D);
120 #ifdef OCCT_DEBUG_DUMPWLINE
122 void DumpWLine(const Handle(IntPatch_WLine)& aWLine);
126 void TolR3d(const TopoDS_Face& ,
130 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)&,
131 const Standard_Integer,
132 const Standard_Integer);
135 void Parameters(const Handle(GeomAdaptor_HSurface)&,
136 const Handle(GeomAdaptor_HSurface)&,
144 void BuildPCurves (Standard_Real f,Standard_Real l,Standard_Real& Tol,
145 const Handle (Geom_Surface)& S,
146 const Handle (Geom_Curve)& C,
147 Handle (Geom2d_Curve)& C2d);
150 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
151 const Standard_Real theTolerance,
152 Standard_Real& theumin,
153 Standard_Real& theumax,
154 Standard_Real& thevmin,
155 Standard_Real& thevmax);
157 Standard_Boolean NotUseSurfacesForApprox
158 (const TopoDS_Face& aF1,
159 const TopoDS_Face& aF2,
160 const Handle(IntPatch_WLine)& WL,
161 const Standard_Integer ifprm,
162 const Standard_Integer ilprm);
165 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine);
168 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
169 const Standard_Integer ideb,
170 const Standard_Integer ifin,
171 const Standard_Boolean onFirst);
174 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
175 const Handle(GeomAdaptor_HSurface)& theSurface1,
176 const Handle(GeomAdaptor_HSurface)& theSurface2,
177 const TopoDS_Face& theFace1,
178 const TopoDS_Face& theFace2,
179 const GeomInt_LineConstructor& theLConstructor,
180 const Standard_Boolean theAvoidLConstructor,
181 IntPatch_SequenceOfLine& theNewLines,
182 Standard_Real& theReachedTol3d,
183 const Handle(IntTools_Context)& );
186 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
187 const Handle(Geom_Curve)& theCurve,
188 const TopoDS_Face& theFace1,
189 const TopoDS_Face& theFace2,
190 const Standard_Real theOtherParameter,
191 const Standard_Boolean bIncreasePar,
192 Standard_Real& theNewParameter,
193 const Handle(IntTools_Context)& );
196 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve);
199 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
200 const Standard_Real theFirstBoundary,
201 const Standard_Real theSecondBoundary,
202 const Standard_Real theResolution,
203 Standard_Boolean& IsOnFirstBoundary);
205 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
206 const gp_Pnt2d& theLastPoint,
207 const Standard_Real theUmin,
208 const Standard_Real theUmax,
209 const Standard_Real theVmin,
210 const Standard_Real theVmax,
211 gp_Pnt2d& theNewPoint);
215 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
216 const Handle(GeomAdaptor_HSurface)& theSurface2,
217 const TopoDS_Face& theFace1,
218 const TopoDS_Face& theFace2,
219 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
220 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
221 Handle(TColStd_HArray1OfReal)& theResultRadius,
222 const Handle(IntTools_Context)& );
225 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
226 const gp_Pnt2d& theLastPoint,
227 const Standard_Real theUmin,
228 const Standard_Real theUmax,
229 const Standard_Real theVmin,
230 const Standard_Real theVmax,
231 const gp_Pnt2d& theTanZoneCenter,
232 const Standard_Real theZoneRadius,
233 Handle(GeomAdaptor_HSurface) theGASurface,
234 gp_Pnt2d& theNewPoint);
237 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
238 const gp_Pnt2d& theTanZoneCenter,
239 const Standard_Real theZoneRadius,
240 Handle(GeomAdaptor_HSurface) theGASurface);
243 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
244 const gp_Pnt2d& theOriginalPoint,
245 Handle(GeomAdaptor_HSurface) theGASurface);
247 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
248 const gp_Sphere& theSph);
250 static void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
251 const Handle(GeomAdaptor_HSurface)& theS2,
252 const Standard_Real TolAng,
253 const Standard_Real TolTang,
254 const Standard_Boolean theApprox1,
255 const Standard_Boolean theApprox2,
256 IntTools_SequenceOfCurves& theSeqOfCurve,
257 Standard_Boolean& theTangentFaces);
259 static Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
260 const gp_Lin2d& theLin2d,
261 const Standard_Real theTol,
262 Standard_Real& theP1,
263 Standard_Real& theP2);
266 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
267 const Handle(GeomAdaptor_HSurface)& aHS2,
268 Standard_Integer& iDegMin,
269 Standard_Integer& iNbIter,
270 Standard_Integer& iDegMax);
273 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
274 const Handle(GeomAdaptor_HSurface)& aHS2,
275 Standard_Real& aTolTang);
278 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
279 const GeomAbs_SurfaceType aType2);
281 Standard_Integer IndexType(const GeomAbs_SurfaceType aType);
285 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
286 const TopoDS_Face& aFace);
290 Standard_Real MaxDistance(const Handle(Geom_Curve)& theC,
291 const Standard_Real aT,
292 GeomAPI_ProjectPointOnSurf& theProjPS);
294 Standard_Real FindMaxDistance(const Handle(Geom_Curve)& theC,
295 const Standard_Real theFirst,
296 const Standard_Real theLast,
297 GeomAPI_ProjectPointOnSurf& theProjPS,
298 const Standard_Real theEps);
300 Standard_Real FindMaxDistance(const Handle(Geom_Curve)& theCurve,
301 const Standard_Real theFirst,
302 const Standard_Real theLast,
303 const TopoDS_Face& theFace,
304 const Handle(IntTools_Context)& theContext);
306 //=======================================================================
309 //=======================================================================
310 IntTools_FaceFace::IntTools_FaceFace()
312 myIsDone=Standard_False;
313 myTangentFaces=Standard_False;
315 myHS1 = new GeomAdaptor_HSurface ();
316 myHS2 = new GeomAdaptor_HSurface ();
319 SetParameters(Standard_True, Standard_True, Standard_True, 1.e-07);
322 //=======================================================================
323 //function : SetContext
325 //=======================================================================
326 void IntTools_FaceFace::SetContext(const Handle(IntTools_Context)& aContext)
330 //=======================================================================
333 //=======================================================================
334 const Handle(IntTools_Context)& IntTools_FaceFace::Context()const
338 //=======================================================================
341 //=======================================================================
342 const TopoDS_Face& IntTools_FaceFace::Face1() const
346 //=======================================================================
349 //=======================================================================
350 const TopoDS_Face& IntTools_FaceFace::Face2() const
354 //=======================================================================
355 //function : TangentFaces
357 //=======================================================================
358 Standard_Boolean IntTools_FaceFace::TangentFaces() const
360 return myTangentFaces;
362 //=======================================================================
365 //=======================================================================
366 const IntTools_SequenceOfPntOn2Faces& IntTools_FaceFace::Points() const
370 //=======================================================================
373 //=======================================================================
374 Standard_Boolean IntTools_FaceFace::IsDone() const
378 //=======================================================================
379 //function : TolReached3d
381 //=======================================================================
382 Standard_Real IntTools_FaceFace::TolReached3d() const
384 return myTolReached3d;
386 //=======================================================================
388 //purpose : return lines of intersection
389 //=======================================================================
390 const IntTools_SequenceOfCurves& IntTools_FaceFace::Lines() const
392 StdFail_NotDone_Raise_if
394 "IntTools_FaceFace::Lines() => myIntersector NOT DONE");
397 //=======================================================================
398 //function : TolReached2d
400 //=======================================================================
401 Standard_Real IntTools_FaceFace::TolReached2d() const
403 return myTolReached2d;
405 // =======================================================================
406 // function: SetParameters
408 // =======================================================================
409 void IntTools_FaceFace::SetParameters(const Standard_Boolean ToApproxC3d,
410 const Standard_Boolean ToApproxC2dOnS1,
411 const Standard_Boolean ToApproxC2dOnS2,
412 const Standard_Real ApproximationTolerance)
414 myApprox = ToApproxC3d;
415 myApprox1 = ToApproxC2dOnS1;
416 myApprox2 = ToApproxC2dOnS2;
417 myTolApprox = ApproximationTolerance;
419 //=======================================================================
422 //=======================================================================
423 void IntTools_FaceFace::SetList(IntSurf_ListOfPntOn2S& aListOfPnts)
425 myListOfPnts = aListOfPnts;
429 static Standard_Boolean isTreatAnalityc(const TopoDS_Face& theF1,
430 const TopoDS_Face& theF2)
432 const Standard_Real Tolang = 1.e-8;
433 const Standard_Real aTolF1=BRep_Tool::Tolerance(theF1);
434 const Standard_Real aTolF2=BRep_Tool::Tolerance(theF2);
435 const Standard_Real aTolSum = aTolF1 + aTolF2;
436 Standard_Real aHigh = 0.0;
438 const BRepAdaptor_Surface aBAS1(theF1), aBAS2(theF2);
439 const GeomAbs_SurfaceType aType1=aBAS1.GetType();
440 const GeomAbs_SurfaceType aType2=aBAS2.GetType();
444 if(aType1 == GeomAbs_Plane)
448 else if(aType2 == GeomAbs_Plane)
454 return Standard_True;
457 if(aType1 == GeomAbs_Cylinder)
459 aS2=aBAS1.Cylinder();
460 const Standard_Real VMin = aBAS1.FirstVParameter();
461 const Standard_Real VMax = aBAS1.LastVParameter();
463 if( Precision::IsNegativeInfinite(VMin) ||
464 Precision::IsPositiveInfinite(VMax))
465 return Standard_True;
469 else if(aType2 == GeomAbs_Cylinder)
471 aS2=aBAS2.Cylinder();
473 const Standard_Real VMin = aBAS2.FirstVParameter();
474 const Standard_Real VMax = aBAS2.LastVParameter();
476 if( Precision::IsNegativeInfinite(VMin) ||
477 Precision::IsPositiveInfinite(VMax))
478 return Standard_True;
484 return Standard_True;
487 IntAna_QuadQuadGeo inter;
488 inter.Perform(aS1,aS2,Tolang,aTolSum, aHigh);
489 if(inter.TypeInter() == IntAna_Ellipse)
491 const gp_Elips anEl = inter.Ellipse(1);
492 const Standard_Real aMajorR = anEl.MajorRadius();
493 const Standard_Real aMinorR = anEl.MinorRadius();
495 return (aMajorR < 100000.0 * aMinorR);
499 return inter.IsDone();
502 //=======================================================================
504 //purpose : intersect surfaces of the faces
505 //=======================================================================
506 void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
507 const TopoDS_Face& aF2)
509 Standard_Boolean RestrictLine = Standard_False, hasCone = Standard_False;
511 if (myContext.IsNull()) {
512 myContext=new IntTools_Context;
515 mySeqOfCurve.Clear();
518 myIsDone = Standard_False;
524 const BRepAdaptor_Surface aBAS1(myFace1, Standard_False);
525 const BRepAdaptor_Surface aBAS2(myFace2, Standard_False);
526 GeomAbs_SurfaceType aType1=aBAS1.GetType();
527 GeomAbs_SurfaceType aType2=aBAS2.GetType();
529 const Standard_Boolean bReverse=SortTypes(aType1, aType2);
534 aType1=aBAS2.GetType();
535 aType2=aBAS1.GetType();
537 if (myListOfPnts.Extent())
539 Standard_Real aU1,aV1,aU2,aV2;
540 IntSurf_ListIteratorOfListOfPntOn2S aItP2S;
542 aItP2S.Initialize(myListOfPnts);
543 for (; aItP2S.More(); aItP2S.Next())
545 IntSurf_PntOn2S& aP2S=aItP2S.Value();
546 aP2S.Parameters(aU1,aV1,aU2,aV2);
547 aP2S.SetValue(aU2,aV2,aU1,aV1);
551 Standard_Boolean anAproxTmp = myApprox1;
552 myApprox1 = myApprox2;
553 myApprox2 = anAproxTmp;
557 const Handle(Geom_Surface) S1=BRep_Tool::Surface(myFace1);
558 const Handle(Geom_Surface) S2=BRep_Tool::Surface(myFace2);
560 const Standard_Real aTolF1=BRep_Tool::Tolerance(myFace1);
561 const Standard_Real aTolF2=BRep_Tool::Tolerance(myFace2);
563 Standard_Real TolArc = aTolF1 + aTolF2;
564 Standard_Real TolTang = TolArc;
566 const Standard_Boolean isFace1Quad = (aType1 == GeomAbs_Cylinder ||
567 aType1 == GeomAbs_Cone ||
568 aType1 == GeomAbs_Torus);
570 const Standard_Boolean isFace2Quad = (aType2 == GeomAbs_Cylinder ||
571 aType2 == GeomAbs_Cone ||
572 aType2 == GeomAbs_Torus);
574 if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
575 Standard_Real umin, umax, vmin, vmax;
576 Standard_Real dU, dV;
578 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
585 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
587 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
594 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
596 Standard_Real TolAng = 1.e-8;
598 PerformPlanes(myHS1, myHS2, TolAng, TolTang, myApprox1, myApprox2,
599 mySeqOfCurve, myTangentFaces);
601 myIsDone = Standard_True;
603 if(!myTangentFaces) {
604 const Standard_Integer NbLinPP = mySeqOfCurve.Length();
606 Standard_Real aTolFMax;
607 myTolReached3d = 1.e-7;
608 aTolFMax=Max(aTolF1, aTolF2);
609 if (aTolFMax>myTolReached3d) {
610 myTolReached3d=aTolFMax;
613 myTolReached2d = myTolReached3d;
616 Handle(Geom2d_Curve) aC2D1, aC2D2;
617 const Standard_Integer aNbLin = mySeqOfCurve.Length();
618 for (Standard_Integer i = 1; i <= aNbLin; ++i) {
619 IntTools_Curve& aIC=mySeqOfCurve(i);
620 aC2D1=aIC.FirstCurve2d();
621 aC2D2=aIC.SecondCurve2d();
622 aIC.SetFirstCurve2d(aC2D2);
623 aIC.SetSecondCurve2d(aC2D1);
629 }//if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
631 if ((aType1==GeomAbs_Plane) && isFace2Quad)
633 Standard_Real dU, dV;
636 Standard_Real umin, umax, vmin, vmax;
637 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
645 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
647 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
648 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
649 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
651 if( aType2==GeomAbs_Cone ) {
653 hasCone = Standard_True;
656 else if ((aType2==GeomAbs_Plane) && isFace1Quad)
658 Standard_Real dU, dV;
661 Standard_Real umin, umax, vmin, vmax;
662 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
663 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
664 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
666 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
673 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
675 if( aType1==GeomAbs_Cone ) {
677 hasCone = Standard_True;
682 Standard_Real umin, umax, vmin, vmax;
683 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
684 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
685 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
686 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
687 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
688 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
691 const Handle(IntTools_TopolTool) dom1 = new IntTools_TopolTool(myHS1);
692 const Handle(IntTools_TopolTool) dom2 = new IntTools_TopolTool(myHS2);
694 myLConstruct.Load(dom1, dom2, myHS1, myHS2);
697 Tolerances(myHS1, myHS2, TolTang);
700 const Standard_Real UVMaxStep = 0.001;
701 const Standard_Real Deflection = (hasCone) ? 0.085 : 0.1;
702 myIntersector.SetTolerances(TolArc, TolTang, UVMaxStep, Deflection);
705 if((myHS1->IsUClosed() && !myHS1->IsUPeriodic()) ||
706 (myHS1->IsVClosed() && !myHS1->IsVPeriodic()) ||
707 (myHS2->IsUClosed() && !myHS2->IsUPeriodic()) ||
708 (myHS2->IsVClosed() && !myHS2->IsVPeriodic()))
710 RestrictLine = Standard_True;
713 if((aType1 != GeomAbs_BSplineSurface) &&
714 (aType1 != GeomAbs_BezierSurface) &&
715 (aType1 != GeomAbs_OtherSurface) &&
716 (aType2 != GeomAbs_BSplineSurface) &&
717 (aType2 != GeomAbs_BezierSurface) &&
718 (aType2 != GeomAbs_OtherSurface))
720 RestrictLine = Standard_True;
722 if ((aType1 == GeomAbs_Torus) ||
723 (aType2 == GeomAbs_Torus))
725 myListOfPnts.Clear();
732 TopExp_Explorer aExp;
733 for(Standard_Integer i = 0; (!RestrictLine) && (i < 2); i++)
735 const TopoDS_Face& aF=(!i) ? myFace1 : myFace2;
736 aExp.Init(aF, TopAbs_EDGE);
737 for(; aExp.More(); aExp.Next())
739 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
741 if(BRep_Tool::Degenerated(aE))
743 RestrictLine = Standard_True;
750 const Standard_Boolean isGeomInt = isTreatAnalityc(aF1, aF2);
751 myIntersector.Perform(myHS1, dom1, myHS2, dom2, TolArc, TolTang,
752 myListOfPnts, RestrictLine, isGeomInt);
754 myIsDone = myIntersector.IsDone();
758 myTangentFaces=myIntersector.TangentFaces();
759 if (myTangentFaces) {
764 myListOfPnts.Clear(); // to use LineConstructor
767 const Standard_Integer aNbLin = myIntersector.NbLines();
768 for (Standard_Integer i=1; i <= aNbLin; ++i) {
769 MakeCurve(i, dom1, dom2);
772 ComputeTolReached3d();
775 Handle(Geom2d_Curve) aC2D1, aC2D2;
777 const Standard_Integer aNbLin=mySeqOfCurve.Length();
778 for (Standard_Integer i=1; i<=aNbLin; ++i)
780 IntTools_Curve& aIC=mySeqOfCurve(i);
781 aC2D1=aIC.FirstCurve2d();
782 aC2D2=aIC.SecondCurve2d();
783 aIC.SetFirstCurve2d(aC2D2);
784 aIC.SetSecondCurve2d(aC2D1);
789 Standard_Real U1,V1,U2,V2;
790 IntTools_PntOnFace aPntOnF1, aPntOnF2;
791 IntTools_PntOn2Faces aPntOn2Faces;
793 const Standard_Integer aNbPnts = myIntersector.NbPnts();
794 for (Standard_Integer i=1; i <= aNbPnts; ++i)
796 const IntSurf_PntOn2S& aISPnt=myIntersector.Point(i).PntOn2S();
797 const gp_Pnt& aPnt=aISPnt.Value();
798 aISPnt.Parameters(U1,V1,U2,V2);
799 aPntOnF1.Init(myFace1, aPnt, U1, V1);
800 aPntOnF2.Init(myFace2, aPnt, U2, V2);
804 aPntOn2Faces.SetP1(aPntOnF1);
805 aPntOn2Faces.SetP2(aPntOnF2);
809 aPntOn2Faces.SetP2(aPntOnF1);
810 aPntOn2Faces.SetP1(aPntOnF2);
813 myPnts.Append(aPntOn2Faces);
818 //=======================================================================
819 //function : ComputeTolerance
821 //=======================================================================
822 Standard_Real IntTools_FaceFace::ComputeTolerance()
824 Standard_Integer i, j, aNbLin;
825 Standard_Real aFirst, aLast, aD, aDMax, aT, aDelta;
826 Handle(Geom_Surface) aS1, aS2;
829 aDelta = Precision::PConfusion();
830 aNbLin = mySeqOfCurve.Length();
832 aS1 = myHS1->ChangeSurface().Surface();
833 aS2 = myHS2->ChangeSurface().Surface();
835 for (i = 1; i <= aNbLin; ++i) {
836 const IntTools_Curve& aIC = mySeqOfCurve(i);
837 const Handle(Geom_Curve)& aC3D = aIC.Curve();
842 aFirst = aC3D->FirstParameter();
843 aLast = aC3D->LastParameter();
845 const Handle(Geom2d_Curve)& aC2D1 = aIC.FirstCurve2d();
846 const Handle(Geom2d_Curve)& aC2D2 = aIC.SecondCurve2d();
848 for (j = 0; j < 2; ++j) {
849 const Handle(Geom2d_Curve)& aC2D = !j ? aC2D1 : aC2D2;
850 const Handle(Geom_Surface)& aS = !j ? aS1 : aS2;
852 if (!aC2D.IsNull()) {
853 if (IntTools_Tools::ComputeTolerance
854 (aC3D, aC2D, aS, aFirst, aLast, aD, aT)) {
861 const TopoDS_Face& aF = !i ? myFace1 : myFace2;
862 aD = FindMaxDistance(aC3D, aFirst, aLast, aF, myContext);
872 //=======================================================================
873 //function :ComputeTolReached3d
875 //=======================================================================
876 void IntTools_FaceFace::ComputeTolReached3d()
878 Standard_Integer aNbLin, i;
879 GeomAbs_SurfaceType aType1, aType2;
881 aNbLin=myIntersector.NbLines();
886 aType1=myHS1->Surface().GetType();
887 aType2=myHS2->Surface().GetType();
889 if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
891 Handle(IntPatch_Line) aIL1, aIL2;
892 IntPatch_IType aTL1, aTL2;
894 aIL1=myIntersector.Line(1);
895 aIL2=myIntersector.Line(2);
896 aTL1=aIL1->ArcType();
897 aTL2=aIL2->ArcType();
898 if (aTL1==IntPatch_Lin && aTL2==IntPatch_Lin) {
899 Standard_Real aD, aDTresh, dTol;
905 aL1=Handle(IntPatch_GLine)::DownCast(aIL1)->Line();
906 aL2=Handle(IntPatch_GLine)::DownCast(aIL2)->Line();
907 aD=aL1.Distance(aL2);
910 myTolReached3d=aD+dTol;
916 if (aNbLin) {// Check the distances
919 aDMax = ComputeTolerance();
921 myTolReached3d = aDMax;
924 }// if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
927 else if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
928 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
932 aTolF1 = BRep_Tool::Tolerance(myFace1);
933 aTolF2 = BRep_Tool::Tolerance(myFace2);
934 aTolFMax=Max(aTolF1, aTolF2);
936 if (aTolFMax>aTolTresh) {
937 myTolReached3d=aTolFMax;
939 }//if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
942 else if((aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) ||
943 (aType2 == GeomAbs_Cylinder && aType1 == GeomAbs_Plane)) {
945 const Handle(IntPatch_Line)& aIL1 = myIntersector.Line(1);
946 if(aIL1->ArcType() == IntPatch_Circle) {
947 gp_Circ aCir = Handle(IntPatch_GLine)::DownCast(aIL1)->Circle();
948 gp_XYZ aCirDir = aCir.Axis().Direction().XYZ();
951 if(aType1 == GeomAbs_Plane) {
952 aPln = myHS1->Surface().Plane();
955 aPln = myHS2->Surface().Plane();
957 aPlDir = aPln.Axis().Direction().XYZ();
958 Standard_Real cs = aCirDir*aPlDir;
959 if(cs < 0.) aPlDir.Reverse();
960 Standard_Real eps = 1.e-14;
961 if(!aPlDir.IsEqual(aCirDir, eps)) {
962 Standard_Integer aNbP = 11;
963 Standard_Real dt = 2.*M_PI / (aNbP - 1), t;
964 for(t = 0.; t < 2.*M_PI; t += dt) {
965 Standard_Real d = aPln.Distance(ElCLib::Value(t, aCir));
966 if(myTolReached3d < d) myTolReached3d = d;
968 myTolReached3d *= 1.1;
970 } //aIL1->ArcType() == IntPatch_Circle
972 } // aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane)
973 //End IFV Bug OCC20297
975 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
976 (aType2==GeomAbs_Plane && aType1==GeomAbs_Torus)) {
977 aNbLin=mySeqOfCurve.Length();
982 Standard_Integer aNbP;
983 Standard_Real aT, aT1, aT2, dT, aUT, aVT, aUP, aVP;
984 Standard_Real aDP, aDT, aDmax;
989 const IntTools_Curve& aIC=mySeqOfCurve(1);
990 const Handle(Geom_Curve)& aC3D=aIC.Curve();
991 const Handle(Geom_BSplineCurve)& aBS=
992 Handle(Geom_BSplineCurve)::DownCast(aC3D);
997 aT1=aBS->FirstParameter();
998 aT2=aBS->LastParameter();
1000 aPln =(aType1==GeomAbs_Plane) ? myHS1->Plane() : myHS2->Plane();
1001 aTorus=(aType1==GeomAbs_Plane) ? myHS2->Torus() : myHS1->Torus();
1005 dT=(aT2-aT1)/(aNbP-1);
1006 for (i=0; i<aNbP; ++i) {
1014 ElSLib::Parameters(aPln, aP, aUP, aVP);
1015 aPP=ElSLib::Value(aUP, aVP, aPln);
1016 aDP=aP.SquareDistance(aPP);
1021 ElSLib::Parameters(aTorus, aP, aUT, aVT);
1022 aPT=ElSLib::Value(aUT, aVT, aTorus);
1023 aDT=aP.SquareDistance(aPT);
1029 if (aDmax > myTolReached3d*myTolReached3d) {
1030 myTolReached3d=sqrt(aDmax);
1031 myTolReached3d=1.1*myTolReached3d;
1033 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
1035 else if ((aType1==GeomAbs_SurfaceOfRevolution && aType2==GeomAbs_Cylinder) ||
1036 (aType2==GeomAbs_SurfaceOfRevolution && aType1==GeomAbs_Cylinder) ||
1037 (aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ||
1038 (aType2==GeomAbs_Plane && aType1==GeomAbs_Sphere) ||
1039 (aType1==GeomAbs_Plane && aType2==GeomAbs_SurfaceOfExtrusion) ||
1040 (aType2==GeomAbs_Plane && aType1==GeomAbs_SurfaceOfExtrusion) ||
1041 (aType1==GeomAbs_Plane && aType2==GeomAbs_BSplineSurface) ||
1042 (aType2==GeomAbs_Plane && aType1==GeomAbs_BSplineSurface) ||
1045 Standard_Real aDMax;
1047 aDMax = ComputeTolerance();
1048 if (aDMax > myTolReached3d) {
1049 myTolReached3d = aDMax;
1054 //=======================================================================
1055 //function : MakeCurve
1057 //=======================================================================
1058 void IntTools_FaceFace::MakeCurve(const Standard_Integer Index,
1059 const Handle(Adaptor3d_TopolTool)& dom1,
1060 const Handle(Adaptor3d_TopolTool)& dom2)
1062 Standard_Boolean bDone, rejectSurface, reApprox, bAvoidLineConstructor;
1063 Standard_Boolean ok, bPCurvesOk;
1064 Standard_Integer i, j, aNbParts;
1065 Standard_Real fprm, lprm;
1066 Standard_Real Tolpc;
1067 Handle(IntPatch_Line) L;
1068 IntPatch_IType typl;
1069 Handle(Geom_Curve) newc;
1071 const Standard_Real TOLCHECK =0.0000001;
1072 const Standard_Real TOLANGCHECK=0.1;
1074 rejectSurface = Standard_False;
1075 reApprox = Standard_False;
1077 bPCurvesOk = Standard_True;
1081 Tolpc = myTolApprox;
1082 bAvoidLineConstructor = Standard_False;
1083 L = myIntersector.Line(Index);
1084 typl = L->ArcType();
1086 if(typl==IntPatch_Walking) {
1087 Handle(IntPatch_Line) anewL;
1089 const Handle(IntPatch_WLine)& aWLine=
1090 Handle(IntPatch_WLine)::DownCast(L);
1091 //DumpWLine(aWLine);
1093 anewL = ComputePurgedWLine(aWLine);
1094 if(anewL.IsNull()) {
1099 //const Handle(IntPatch_WLine)& aWLineX = Handle(IntPatch_WLine)::DownCast(L);
1100 //DumpWLine(aWLineX);
1103 if(!myListOfPnts.IsEmpty()) {
1104 bAvoidLineConstructor = Standard_True;
1107 Standard_Integer nbp = aWLine->NbPnts();
1108 const IntSurf_PntOn2S& p1 = aWLine->Point(1);
1109 const IntSurf_PntOn2S& p2 = aWLine->Point(nbp);
1111 const gp_Pnt& P1 = p1.Value();
1112 const gp_Pnt& P2 = p2.Value();
1114 if(P1.SquareDistance(P2) < 1.e-14) {
1115 bAvoidLineConstructor = Standard_False;
1120 if(!bAvoidLineConstructor) {
1121 myLConstruct.Perform(L);
1123 bDone=myLConstruct.IsDone();
1124 aNbParts=myLConstruct.NbParts();
1125 if (!bDone|| !aNbParts) {
1133 //########################################
1134 // Line, Parabola, Hyperbola
1135 //########################################
1137 case IntPatch_Parabola:
1138 case IntPatch_Hyperbola: {
1139 if (typl == IntPatch_Lin) {
1141 new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line());
1144 else if (typl == IntPatch_Parabola) {
1146 new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola());
1149 else if (typl == IntPatch_Hyperbola) {
1151 new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola());
1155 if (typl == IntPatch_Lin) {
1156 TolR3d (myFace1, myFace2, myTolReached3d);
1159 aNbParts=myLConstruct.NbParts();
1160 for (i=1; i<=aNbParts; i++) {
1161 Standard_Boolean bFNIt, bLPIt;
1163 myLConstruct.Part(i, fprm, lprm);
1165 bFNIt=Precision::IsNegativeInfinite(fprm);
1166 bLPIt=Precision::IsPositiveInfinite(lprm);
1168 if (!bFNIt && !bLPIt) {
1170 IntTools_Curve aCurve;
1172 Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm);
1173 aCurve.SetCurve(aCT3D);
1174 if (typl == IntPatch_Parabola) {
1175 Standard_Real aTolF1, aTolF2, aTolBase;
1177 aTolF1 = BRep_Tool::Tolerance(myFace1);
1178 aTolF2 = BRep_Tool::Tolerance(myFace2);
1179 aTolBase=aTolF1+aTolF2;
1180 myTolReached3d=IntTools_Tools::CurveTolerance(aCT3D, aTolBase);
1183 aCurve.SetCurve(new Geom_TrimmedCurve(newc, fprm, lprm));
1185 Handle (Geom2d_Curve) C2d;
1186 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1187 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1188 myTolReached2d=Tolpc;
1191 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1194 Handle(Geom2d_BSplineCurve) H1;
1196 aCurve.SetFirstCurve2d(H1);
1200 Handle (Geom2d_Curve) C2d;
1201 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1202 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1203 myTolReached2d=Tolpc;
1206 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1209 Handle(Geom2d_BSplineCurve) H1;
1211 aCurve.SetSecondCurve2d(H1);
1213 mySeqOfCurve.Append(aCurve);
1214 } //if (!bFNIt && !bLPIt) {
1216 // on regarde si on garde
1218 Standard_Real aTestPrm, dT=100.;
1221 if (bFNIt && !bLPIt) {
1224 else if (!bFNIt && bLPIt) {
1228 // i.e, if (bFNIt && bLPIt)
1229 aTestPrm=IntTools_Tools::IntermediatePoint(-dT, dT);
1232 gp_Pnt ptref(newc->Value(aTestPrm));
1234 GeomAbs_SurfaceType typS1 = myHS1->GetType();
1235 GeomAbs_SurfaceType typS2 = myHS2->GetType();
1236 if( typS1 == GeomAbs_SurfaceOfExtrusion ||
1237 typS1 == GeomAbs_OffsetSurface ||
1238 typS1 == GeomAbs_SurfaceOfRevolution ||
1239 typS2 == GeomAbs_SurfaceOfExtrusion ||
1240 typS2 == GeomAbs_OffsetSurface ||
1241 typS2 == GeomAbs_SurfaceOfRevolution) {
1242 Handle(Geom2d_BSplineCurve) H1;
1243 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1247 Standard_Real u1, v1, u2, v2, Tol;
1249 Tol = Precision::Confusion();
1250 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1251 ok = (dom1->Classify(gp_Pnt2d(u1, v1), Tol) != TopAbs_OUT);
1253 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1256 Handle(Geom2d_BSplineCurve) H1;
1257 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1260 }// for (i=1; i<=aNbParts; i++) {
1261 }// case IntPatch_Lin: case IntPatch_Parabola: case IntPatch_Hyperbola:
1264 //########################################
1265 // Circle and Ellipse
1266 //########################################
1267 case IntPatch_Circle:
1268 case IntPatch_Ellipse: {
1270 if (typl == IntPatch_Circle) {
1271 newc = new Geom_Circle
1272 (Handle(IntPatch_GLine)::DownCast(L)->Circle());
1274 else { //IntPatch_Ellipse
1275 newc = new Geom_Ellipse
1276 (Handle(IntPatch_GLine)::DownCast(L)->Ellipse());
1280 TolR3d (myFace1, myFace2, myTolReached3d);
1282 aNbParts=myLConstruct.NbParts();
1284 Standard_Real aPeriod, aNul;
1285 TColStd_SequenceOfReal aSeqFprm, aSeqLprm;
1290 for (i=1; i<=aNbParts; i++) {
1291 myLConstruct.Part(i, fprm, lprm);
1293 if (fprm < aNul && lprm > aNul) {
1294 // interval that goes through 0. is divided on two intervals;
1295 while (fprm<aNul || fprm>aPeriod) fprm=fprm+aPeriod;
1296 while (lprm<aNul || lprm>aPeriod) lprm=lprm+aPeriod;
1298 if((aPeriod - fprm) > Tolpc) {
1299 aSeqFprm.Append(fprm);
1300 aSeqLprm.Append(aPeriod);
1303 gp_Pnt P1 = newc->Value(fprm);
1304 gp_Pnt P2 = newc->Value(aPeriod);
1305 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1306 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1308 if(P1.Distance(P2) > aTolDist) {
1309 Standard_Real anewpar = fprm;
1311 if(ParameterOutOfBoundary(fprm, newc, myFace1, myFace2,
1312 lprm, Standard_False, anewpar, myContext)) {
1315 aSeqFprm.Append(fprm);
1316 aSeqLprm.Append(aPeriod);
1321 if((lprm - aNul) > Tolpc) {
1322 aSeqFprm.Append(aNul);
1323 aSeqLprm.Append(lprm);
1326 gp_Pnt P1 = newc->Value(aNul);
1327 gp_Pnt P2 = newc->Value(lprm);
1328 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1329 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1331 if(P1.Distance(P2) > aTolDist) {
1332 Standard_Real anewpar = lprm;
1334 if(ParameterOutOfBoundary(lprm, newc, myFace1, myFace2,
1335 fprm, Standard_True, anewpar, myContext)) {
1338 aSeqFprm.Append(aNul);
1339 aSeqLprm.Append(lprm);
1345 aSeqFprm.Append(fprm);
1346 aSeqLprm.Append(lprm);
1351 aNbParts=aSeqFprm.Length();
1352 for (i=1; i<=aNbParts; i++) {
1356 Standard_Real aRealEpsilon=RealEpsilon();
1357 if (Abs(fprm) > aRealEpsilon || Abs(lprm-2.*M_PI) > aRealEpsilon) {
1358 //==============================================
1360 IntTools_Curve aCurve;
1361 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1362 aCurve.SetCurve(aTC3D);
1363 fprm=aTC3D->FirstParameter();
1364 lprm=aTC3D->LastParameter ();
1366 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {////
1368 Handle (Geom2d_Curve) C2d;
1369 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1370 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1371 myTolReached2d=Tolpc;
1374 aCurve.SetFirstCurve2d(C2d);
1377 Handle(Geom2d_BSplineCurve) H1;
1378 aCurve.SetFirstCurve2d(H1);
1383 Handle (Geom2d_Curve) C2d;
1384 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1385 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1386 myTolReached2d=Tolpc;
1389 aCurve.SetSecondCurve2d(C2d);
1392 Handle(Geom2d_BSplineCurve) H1;
1393 aCurve.SetSecondCurve2d(H1);
1398 Handle(Geom2d_BSplineCurve) H1;
1399 aCurve.SetFirstCurve2d(H1);
1400 aCurve.SetSecondCurve2d(H1);
1402 mySeqOfCurve.Append(aCurve);
1403 //==============================================
1404 } //if (Abs(fprm) > RealEpsilon() || Abs(lprm-2.*M_PI) > RealEpsilon())
1407 // on regarde si on garde
1410 // if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*M_PI) < RealEpsilon()) {
1411 if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*M_PI) <= aRealEpsilon) {
1412 IntTools_Curve aCurve;
1413 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1414 aCurve.SetCurve(aTC3D);
1415 fprm=aTC3D->FirstParameter();
1416 lprm=aTC3D->LastParameter ();
1419 Handle (Geom2d_Curve) C2d;
1420 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1421 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1422 myTolReached2d=Tolpc;
1425 aCurve.SetFirstCurve2d(C2d);
1428 Handle(Geom2d_BSplineCurve) H1;
1429 aCurve.SetFirstCurve2d(H1);
1433 Handle (Geom2d_Curve) C2d;
1434 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1435 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1436 myTolReached2d=Tolpc;
1439 aCurve.SetSecondCurve2d(C2d);
1442 Handle(Geom2d_BSplineCurve) H1;
1443 aCurve.SetSecondCurve2d(H1);
1445 mySeqOfCurve.Append(aCurve);
1450 Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol;
1452 aTwoPIdiv17=2.*M_PI/17.;
1454 for (j=0; j<=17; j++) {
1455 gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
1456 Tol = Precision::Confusion();
1458 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1459 ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT);
1461 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1464 IntTools_Curve aCurve;
1465 aCurve.SetCurve(newc);
1466 //==============================================
1467 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {
1470 Handle (Geom2d_Curve) C2d;
1471 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1472 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1473 myTolReached2d=Tolpc;
1476 aCurve.SetFirstCurve2d(C2d);
1479 Handle(Geom2d_BSplineCurve) H1;
1480 aCurve.SetFirstCurve2d(H1);
1484 Handle (Geom2d_Curve) C2d;
1485 BuildPCurves(fprm, lprm, Tolpc,myHS2->ChangeSurface().Surface(), newc, C2d);
1486 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1487 myTolReached2d=Tolpc;
1490 aCurve.SetSecondCurve2d(C2d);
1494 Handle(Geom2d_BSplineCurve) H1;
1495 aCurve.SetSecondCurve2d(H1);
1497 }// end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse)
1500 Handle(Geom2d_BSplineCurve) H1;
1502 aCurve.SetFirstCurve2d(H1);
1503 aCurve.SetSecondCurve2d(H1);
1505 //==============================================
1507 mySeqOfCurve.Append(aCurve);
1510 }// end of if (ok) {
1511 }// end of for (Standard_Integer j=0; j<=17; j++)
1512 }// end of else { on regarde si on garde
1513 }// for (i=1; i<=myLConstruct.NbParts(); i++)
1514 }// IntPatch_Circle: IntPatch_Ellipse:
1517 case IntPatch_Analytic: {
1518 IntSurf_Quadric quad1,quad2;
1519 GeomAbs_SurfaceType typs = myHS1->Surface().GetType();
1523 quad1.SetValue(myHS1->Surface().Plane());
1525 case GeomAbs_Cylinder:
1526 quad1.SetValue(myHS1->Surface().Cylinder());
1529 quad1.SetValue(myHS1->Surface().Cone());
1531 case GeomAbs_Sphere:
1532 quad1.SetValue(myHS1->Surface().Sphere());
1535 quad1.SetValue(myHS1->Surface().Torus());
1538 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 1");
1541 typs = myHS2->Surface().GetType();
1545 quad2.SetValue(myHS2->Surface().Plane());
1547 case GeomAbs_Cylinder:
1548 quad2.SetValue(myHS2->Surface().Cylinder());
1551 quad2.SetValue(myHS2->Surface().Cone());
1553 case GeomAbs_Sphere:
1554 quad2.SetValue(myHS2->Surface().Sphere());
1557 quad2.SetValue(myHS2->Surface().Torus());
1560 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 2");
1564 IntPatch_ALineToWLine convert (quad1, quad2);
1567 aNbParts=myLConstruct.NbParts();
1568 for (i=1; i<=aNbParts; i++) {
1569 myLConstruct.Part(i, fprm, lprm);
1570 Handle(IntPatch_WLine) WL =
1571 convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm);
1573 Handle(Geom2d_BSplineCurve) H1;
1574 Handle(Geom2d_BSplineCurve) H2;
1577 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1581 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1584 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1588 else { // myApprox=TRUE
1589 GeomInt_WLApprox theapp3d;
1591 Standard_Real tol2d = myTolApprox;
1593 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True);
1595 aNbParts=myLConstruct.NbParts();
1596 for (i=1; i<=aNbParts; i++) {
1597 myLConstruct.Part(i, fprm, lprm);
1598 Handle(IntPatch_WLine) WL =
1599 convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
1601 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
1603 if (!theapp3d.IsDone()) {
1605 Handle(Geom2d_BSplineCurve) H1;
1606 Handle(Geom2d_BSplineCurve) H2;
1609 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1613 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1616 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1620 if(myApprox1 || myApprox2) {
1621 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) {
1622 myTolReached2d = theapp3d.TolReached2d();
1626 if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) {
1627 myTolReached3d = theapp3d.TolReached3d();
1630 Standard_Integer aNbMultiCurves, nbpoles;
1631 aNbMultiCurves=theapp3d.NbMultiCurves();
1632 for (j=1; j<=aNbMultiCurves; j++) {
1633 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1634 nbpoles = mbspc.NbPoles();
1636 TColgp_Array1OfPnt tpoles(1, nbpoles);
1637 mbspc.Curve(1, tpoles);
1638 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1640 mbspc.Multiplicities(),
1643 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1644 Check.FixTangent(Standard_True,Standard_True);
1646 IntTools_Curve aCurve;
1647 aCurve.SetCurve(BS);
1650 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1651 mbspc.Curve(2,tpoles2d);
1652 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1654 mbspc.Multiplicities(),
1657 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1658 newCheck.FixTangent(Standard_True,Standard_True);
1660 aCurve.SetFirstCurve2d(BS2);
1663 Handle(Geom2d_BSplineCurve) H1;
1664 aCurve.SetFirstCurve2d(H1);
1668 TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
1669 Standard_Integer TwoOrThree;
1670 TwoOrThree=myApprox1 ? 3 : 2;
1671 mbspc.Curve(TwoOrThree, tpoles2d);
1672 Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
1674 mbspc.Multiplicities(),
1677 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1678 newCheck.FixTangent(Standard_True,Standard_True);
1680 aCurve.SetSecondCurve2d(BS2);
1683 Handle(Geom2d_BSplineCurve) H2;
1684 aCurve.SetSecondCurve2d(H2);
1687 mySeqOfCurve.Append(aCurve);
1689 }// for (j=1; j<=aNbMultiCurves; j++) {
1690 }// else from if (!theapp3d.IsDone())
1691 }// for (i=1; i<=aNbParts; i++) {
1692 }// else { // myApprox=TRUE
1693 }// case IntPatch_Analytic:
1696 case IntPatch_Walking:{
1697 Handle(IntPatch_WLine) WL =
1698 Handle(IntPatch_WLine)::DownCast(L);
1700 Standard_Integer ifprm, ilprm;
1704 if(!bAvoidLineConstructor){
1705 aNbParts=myLConstruct.NbParts();
1707 for (i=1; i<=aNbParts; ++i) {
1708 Handle(Geom2d_BSplineCurve) H1, H2;
1709 Handle(Geom_Curve) aBSp;
1711 if(bAvoidLineConstructor) {
1713 ilprm = WL->NbPnts();
1716 myLConstruct.Part(i, fprm, lprm);
1717 ifprm=(Standard_Integer)fprm;
1718 ilprm=(Standard_Integer)lprm;
1722 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1726 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1729 aBSp=MakeBSpline(WL, ifprm, ilprm);
1730 IntTools_Curve aIC(aBSp, H1, H2);
1731 mySeqOfCurve.Append(aIC);
1732 }// for (i=1; i<=aNbParts; ++i) {
1733 }// if (!myApprox) {
1736 Standard_Boolean bIsDecomposited;
1737 Standard_Integer nbiter, aNbSeqOfL;
1738 Standard_Real tol2d, aTolApproxImp;
1739 IntPatch_SequenceOfLine aSeqOfL;
1740 GeomInt_WLApprox theapp3d;
1741 Approx_ParametrizationType aParType = Approx_ChordLength;
1743 Standard_Boolean anApprox1 = myApprox1;
1744 Standard_Boolean anApprox2 = myApprox2;
1746 aTolApproxImp=1.e-5;
1747 tol2d = myTolApprox;
1749 GeomAbs_SurfaceType typs1, typs2;
1750 typs1 = myHS1->Surface().GetType();
1751 typs2 = myHS2->Surface().GetType();
1752 Standard_Boolean anWithPC = Standard_True;
1754 if(typs1 == GeomAbs_Cylinder && typs2 == GeomAbs_Sphere) {
1756 ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere());
1758 else if (typs1 == GeomAbs_Sphere && typs2 == GeomAbs_Cylinder) {
1760 ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere());
1764 myTolApprox = aTolApproxImp;//1.e-5;
1765 anApprox1 = Standard_False;
1766 anApprox2 = Standard_False;
1768 tol2d = myTolApprox;
1771 if(myHS1 == myHS2) {
1772 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1773 rejectSurface = Standard_True;
1776 if(reApprox && !rejectSurface)
1777 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1779 Standard_Integer iDegMax, iDegMin, iNbIter;
1781 ApproxParameters(myHS1, myHS2, iDegMin, iDegMax, iNbIter);
1782 theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, iNbIter, Standard_True, aParType);
1786 Standard_Real aReachedTol = Precision::Confusion();
1787 bIsDecomposited=DecompositionOfWLine(WL,
1793 bAvoidLineConstructor,
1797 if ( bIsDecomposited && ( myTolReached3d < aReachedTol ) ) {
1798 myTolReached3d = aReachedTol;
1801 aNbSeqOfL=aSeqOfL.Length();
1803 if (bIsDecomposited) {
1809 if (!bAvoidLineConstructor) {
1810 aNbParts=myLConstruct.NbParts();
1815 for(i = 1; i <= nbiter; ++i) {
1816 if(bIsDecomposited) {
1817 WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i));
1819 ilprm = WL->NbPnts();
1822 if(bAvoidLineConstructor) {
1824 ilprm = WL->NbPnts();
1827 myLConstruct.Part(i, fprm, lprm);
1828 ifprm = (Standard_Integer)fprm;
1829 ilprm = (Standard_Integer)lprm;
1833 //-- Si une des surfaces est un plan , on approxime en 2d
1834 //-- sur cette surface et on remonte les points 2d en 3d.
1835 if(typs1 == GeomAbs_Plane) {
1836 theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm);
1838 else if(typs2 == GeomAbs_Plane) {
1839 theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm);
1843 if (myHS1 != myHS2){
1844 if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) &&
1845 (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) {
1847 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType);
1849 Standard_Boolean bUseSurfaces;
1850 bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm, ilprm);
1853 rejectSurface = Standard_True;
1855 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1860 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm);
1863 if (!theapp3d.IsDone()) {
1864 Handle(Geom2d_BSplineCurve) H1;
1865 Handle(Geom2d_BSplineCurve) H2;
1867 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
1870 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1874 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1877 IntTools_Curve aIC(aBSp, H1, H2);
1878 mySeqOfCurve.Append(aIC);
1882 if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) {
1883 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) {
1884 myTolReached2d = theapp3d.TolReached2d();
1887 if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) {
1888 myTolReached3d = myTolReached2d;
1890 if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
1891 if (myTolReached3d<1.e-6) {
1892 myTolReached3d = theapp3d.TolReached3d();
1893 myTolReached3d=1.e-6;
1897 else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) {
1898 myTolReached3d = theapp3d.TolReached3d();
1901 Standard_Integer aNbMultiCurves, nbpoles;
1902 aNbMultiCurves=theapp3d.NbMultiCurves();
1903 for (j=1; j<=aNbMultiCurves; j++) {
1904 if(typs1 == GeomAbs_Plane) {
1905 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1906 nbpoles = mbspc.NbPoles();
1908 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1909 TColgp_Array1OfPnt tpoles(1,nbpoles);
1911 mbspc.Curve(1,tpoles2d);
1912 const gp_Pln& Pln = myHS1->Surface().Plane();
1914 Standard_Integer ik;
1915 for(ik = 1; ik<= nbpoles; ik++) {
1917 ElSLib::Value(tpoles2d.Value(ik).X(),
1918 tpoles2d.Value(ik).Y(),
1922 Handle(Geom_BSplineCurve) BS =
1923 new Geom_BSplineCurve(tpoles,
1925 mbspc.Multiplicities(),
1927 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1928 Check.FixTangent(Standard_True, Standard_True);
1930 IntTools_Curve aCurve;
1931 aCurve.SetCurve(BS);
1934 Handle(Geom2d_BSplineCurve) BS1 =
1935 new Geom2d_BSplineCurve(tpoles2d,
1937 mbspc.Multiplicities(),
1939 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
1940 Check1.FixTangent(Standard_True,Standard_True);
1942 // ############################################
1943 if(!rejectSurface && !reApprox) {
1944 Standard_Boolean isValid = IsCurveValid(BS1);
1946 reApprox = Standard_True;
1950 // ############################################
1951 aCurve.SetFirstCurve2d(BS1);
1954 Handle(Geom2d_BSplineCurve) H1;
1955 aCurve.SetFirstCurve2d(H1);
1959 mbspc.Curve(2, tpoles2d);
1961 Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
1963 mbspc.Multiplicities(),
1965 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1966 newCheck.FixTangent(Standard_True,Standard_True);
1968 // ###########################################
1969 if(!rejectSurface && !reApprox) {
1970 Standard_Boolean isValid = IsCurveValid(BS2);
1972 reApprox = Standard_True;
1976 // ###########################################
1978 aCurve.SetSecondCurve2d(BS2);
1981 Handle(Geom2d_BSplineCurve) H2;
1983 aCurve.SetSecondCurve2d(H2);
1986 mySeqOfCurve.Append(aCurve);
1987 }//if(typs1 == GeomAbs_Plane) {
1989 else if(typs2 == GeomAbs_Plane) {
1990 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1991 nbpoles = mbspc.NbPoles();
1993 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1994 TColgp_Array1OfPnt tpoles(1,nbpoles);
1995 mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d);
1996 const gp_Pln& Pln = myHS2->Surface().Plane();
1998 Standard_Integer ik;
1999 for(ik = 1; ik<= nbpoles; ik++) {
2001 ElSLib::Value(tpoles2d.Value(ik).X(),
2002 tpoles2d.Value(ik).Y(),
2007 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
2009 mbspc.Multiplicities(),
2011 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2012 Check.FixTangent(Standard_True,Standard_True);
2014 IntTools_Curve aCurve;
2015 aCurve.SetCurve(BS);
2018 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
2020 mbspc.Multiplicities(),
2022 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
2023 Check1.FixTangent(Standard_True,Standard_True);
2025 // ###########################################
2026 if(!rejectSurface && !reApprox) {
2027 Standard_Boolean isValid = IsCurveValid(BS1);
2029 reApprox = Standard_True;
2033 // ###########################################
2034 bPCurvesOk = CheckPCurve(BS1, myFace2);
2035 aCurve.SetSecondCurve2d(BS1);
2038 Handle(Geom2d_BSplineCurve) H2;
2039 aCurve.SetSecondCurve2d(H2);
2043 mbspc.Curve(1,tpoles2d);
2044 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
2046 mbspc.Multiplicities(),
2048 GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK);
2049 Check2.FixTangent(Standard_True,Standard_True);
2051 // ###########################################
2052 if(!rejectSurface && !reApprox) {
2053 Standard_Boolean isValid = IsCurveValid(BS2);
2055 reApprox = Standard_True;
2059 // ###########################################
2060 bPCurvesOk = bPCurvesOk && CheckPCurve(BS2, myFace1);
2061 aCurve.SetFirstCurve2d(BS2);
2064 Handle(Geom2d_BSplineCurve) H1;
2066 aCurve.SetFirstCurve2d(H1);
2069 //if points of the pcurves are out of the faces bounds
2070 //create 3d and 2d curves without approximation
2072 Handle(Geom2d_BSplineCurve) H1, H2;
2073 bPCurvesOk = Standard_True;
2075 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
2078 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
2079 bPCurvesOk = CheckPCurve(H1, myFace1);
2083 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
2084 bPCurvesOk = bPCurvesOk && CheckPCurve(H2, myFace2);
2087 //if pcurves created without approximation are out of the
2088 //faces bounds, use approximated 3d and 2d curves
2090 IntTools_Curve aIC(aBSp, H1, H2);
2091 mySeqOfCurve.Append(aIC);
2093 mySeqOfCurve.Append(aCurve);
2096 mySeqOfCurve.Append(aCurve);
2098 }// else if(typs2 == GeomAbs_Plane)
2100 else { //typs2 != GeomAbs_Plane && typs1 != GeomAbs_Plane
2101 Standard_Boolean bIsValid1, bIsValid2;
2102 Handle(Geom_BSplineCurve) BS;
2103 Handle(Geom2d_BSplineCurve) aH2D;
2104 IntTools_Curve aCurve;
2106 bIsValid1=Standard_True;
2107 bIsValid2=Standard_True;
2109 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2110 nbpoles = mbspc.NbPoles();
2111 TColgp_Array1OfPnt tpoles(1,nbpoles);
2112 mbspc.Curve(1,tpoles);
2113 BS=new Geom_BSplineCurve(tpoles,
2115 mbspc.Multiplicities(),
2117 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2118 Check.FixTangent(Standard_True,Standard_True);
2120 aCurve.SetCurve(BS);
2121 aCurve.SetFirstCurve2d(aH2D);
2122 aCurve.SetSecondCurve2d(aH2D);
2126 Handle(Geom2d_BSplineCurve) BS1;
2127 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2128 mbspc.Curve(2,tpoles2d);
2130 BS1=new Geom2d_BSplineCurve(tpoles2d,
2132 mbspc.Multiplicities(),
2134 GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK);
2135 newCheck.FixTangent(Standard_True,Standard_True);
2138 bIsValid1=CheckPCurve(BS1, myFace1);
2141 aCurve.SetFirstCurve2d(BS1);
2144 Handle(Geom2d_BSplineCurve) BS1;
2145 fprm = BS->FirstParameter();
2146 lprm = BS->LastParameter();
2148 Handle(Geom2d_Curve) C2d;
2149 Standard_Real aTol = myTolApprox;
2150 BuildPCurves(fprm, lprm, aTol, myHS1->ChangeSurface().Surface(), BS, C2d);
2151 BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2152 aCurve.SetFirstCurve2d(BS1);
2154 } // if(myApprox1) {
2158 Handle(Geom2d_BSplineCurve) BS2;
2159 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2160 mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d);
2161 BS2=new Geom2d_BSplineCurve(tpoles2d,
2163 mbspc.Multiplicities(),
2165 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2166 newCheck.FixTangent(Standard_True,Standard_True);
2169 bIsValid2=CheckPCurve(BS2, myFace2);
2171 aCurve.SetSecondCurve2d(BS2);
2174 Handle(Geom2d_BSplineCurve) BS2;
2175 fprm = BS->FirstParameter();
2176 lprm = BS->LastParameter();
2178 Handle(Geom2d_Curve) C2d;
2179 Standard_Real aTol = myTolApprox;
2180 BuildPCurves(fprm, lprm, aTol, myHS2->ChangeSurface().Surface(), BS, C2d);
2181 BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2182 aCurve.SetSecondCurve2d(BS2);
2185 if (!bIsValid1 || !bIsValid2) {
2186 myTolApprox=aTolApproxImp;//1.e-5;
2187 tol2d = myTolApprox;
2188 reApprox = Standard_True;
2192 mySeqOfCurve.Append(aCurve);
2198 }// case IntPatch_Walking:{
2201 case IntPatch_Restriction:
2209 //=======================================================================
2210 //function : BuildPCurves
2212 //=======================================================================
2213 void BuildPCurves (Standard_Real f,
2216 const Handle (Geom_Surface)& S,
2217 const Handle (Geom_Curve)& C,
2218 Handle (Geom2d_Curve)& C2d)
2220 if (!C2d.IsNull()) {
2224 Standard_Real umin,umax,vmin,vmax;
2226 S->Bounds(umin, umax, vmin, vmax);
2227 // in class ProjLib_Function the range of parameters is shrank by 1.e-09
2228 if((l - f) > 2.e-09) {
2229 C2d = GeomProjLib::Curve2d(C,f,l,S,umin,umax,vmin,vmax,Tol);
2232 // proj. a circle that goes through the pole on a sphere to the sphere
2233 Tol += Precision::Confusion();
2234 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2238 if((l - f) > Epsilon(Abs(f))) {
2239 GeomAPI_ProjectPointOnSurf aProjector1, aProjector2;
2240 gp_Pnt P1 = C->Value(f);
2241 gp_Pnt P2 = C->Value(l);
2242 aProjector1.Init(P1, S);
2243 aProjector2.Init(P2, S);
2245 if(aProjector1.IsDone() && aProjector2.IsDone()) {
2246 Standard_Real U=0., V=0.;
2247 aProjector1.LowerDistanceParameters(U, V);
2250 aProjector2.LowerDistanceParameters(U, V);
2253 if(p1.Distance(p2) > gp::Resolution()) {
2254 TColgp_Array1OfPnt2d poles(1,2);
2255 TColStd_Array1OfReal knots(1,2);
2256 TColStd_Array1OfInteger mults(1,2);
2261 mults(1) = mults(2) = 2;
2263 C2d = new Geom2d_BSplineCurve(poles,knots,mults,1);
2265 // compute reached tolerance.begin
2266 gp_Pnt PMid = C->Value((f + l) * 0.5);
2267 aProjector1.Perform(PMid);
2269 if(aProjector1.IsDone()) {
2270 aProjector1.LowerDistanceParameters(U, V);
2271 gp_Pnt2d pmidproj(U, V);
2272 gp_Pnt2d pmidcurve2d = C2d->Value((f + l) * 0.5);
2273 Standard_Real adist = pmidcurve2d.Distance(pmidproj);
2274 Tol = (adist > Tol) ? adist : Tol;
2276 // compute reached tolerance.end
2282 if (S->IsUPeriodic() && !C2d.IsNull()) {
2283 // Recadre dans le domaine UV de la face
2284 Standard_Real aTm, U0, aEps, period, du, U0x;
2285 Standard_Boolean bAdjust;
2287 aEps = Precision::PConfusion();
2288 period = S->UPeriod();
2291 gp_Pnt2d pm = C2d->Value(aTm);
2295 GeomInt::AdjustPeriodic(U0, umin, umax, period, U0x, du, aEps);
2297 gp_Vec2d T1(du, 0.);
2303 //=======================================================================
2304 //function : Parameters
2306 //=======================================================================
2307 void Parameters(const Handle(GeomAdaptor_HSurface)& HS1,
2308 const Handle(GeomAdaptor_HSurface)& HS2,
2309 const gp_Pnt& Ptref,
2316 IntSurf_Quadric quad1,quad2;
2317 GeomAbs_SurfaceType typs = HS1->Surface().GetType();
2321 quad1.SetValue(HS1->Surface().Plane());
2323 case GeomAbs_Cylinder:
2324 quad1.SetValue(HS1->Surface().Cylinder());
2327 quad1.SetValue(HS1->Surface().Cone());
2329 case GeomAbs_Sphere:
2330 quad1.SetValue(HS1->Surface().Sphere());
2333 quad1.SetValue(HS1->Surface().Torus());
2336 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2339 typs = HS2->Surface().GetType();
2342 quad2.SetValue(HS2->Surface().Plane());
2344 case GeomAbs_Cylinder:
2345 quad2.SetValue(HS2->Surface().Cylinder());
2348 quad2.SetValue(HS2->Surface().Cone());
2350 case GeomAbs_Sphere:
2351 quad2.SetValue(HS2->Surface().Sphere());
2354 quad2.SetValue(HS2->Surface().Torus());
2357 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2360 quad1.Parameters(Ptref,U1,V1);
2361 quad2.Parameters(Ptref,U2,V2);
2364 //=======================================================================
2365 //function : MakeBSpline
2367 //=======================================================================
2368 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL,
2369 const Standard_Integer ideb,
2370 const Standard_Integer ifin)
2372 Standard_Integer i,nbpnt = ifin-ideb+1;
2373 TColgp_Array1OfPnt poles(1,nbpnt);
2374 TColStd_Array1OfReal knots(1,nbpnt);
2375 TColStd_Array1OfInteger mults(1,nbpnt);
2376 Standard_Integer ipidebm1;
2377 for(i=1,ipidebm1=i+ideb-1; i<=nbpnt;ipidebm1++, i++) {
2378 poles(i) = WL->Point(ipidebm1).Value();
2382 mults(1) = mults(nbpnt) = 2;
2384 new Geom_BSplineCurve(poles,knots,mults,1);
2388 //=======================================================================
2389 //function : MakeBSpline2d
2391 //=======================================================================
2392 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
2393 const Standard_Integer ideb,
2394 const Standard_Integer ifin,
2395 const Standard_Boolean onFirst)
2397 Standard_Integer i, nbpnt = ifin-ideb+1;
2398 TColgp_Array1OfPnt2d poles(1,nbpnt);
2399 TColStd_Array1OfReal knots(1,nbpnt);
2400 TColStd_Array1OfInteger mults(1,nbpnt);
2401 Standard_Integer ipidebm1;
2403 for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) {
2406 theWLine->Point(ipidebm1).ParametersOnS1(U, V);
2408 theWLine->Point(ipidebm1).ParametersOnS2(U, V);
2409 poles(i).SetCoord(U, V);
2413 mults(1) = mults(nbpnt) = 2;
2415 return new Geom2d_BSplineCurve(poles,knots,mults,1);
2417 //=======================================================================
2418 //function : PrepareLines3D
2420 //=======================================================================
2421 void IntTools_FaceFace::PrepareLines3D(const Standard_Boolean bToSplit)
2423 Standard_Integer i, aNbCurves;
2424 GeomAbs_SurfaceType aType1, aType2;
2425 IntTools_SequenceOfCurves aNewCvs;
2427 // 1. Treatment closed curves
2428 aNbCurves=mySeqOfCurve.Length();
2429 for (i=1; i<=aNbCurves; ++i) {
2430 const IntTools_Curve& aIC=mySeqOfCurve(i);
2433 Standard_Integer j, aNbC;
2434 IntTools_SequenceOfCurves aSeqCvs;
2436 aNbC=IntTools_Tools::SplitCurve(aIC, aSeqCvs);
2438 for (j=1; j<=aNbC; ++j) {
2439 const IntTools_Curve& aICNew=aSeqCvs(j);
2440 aNewCvs.Append(aICNew);
2444 aNewCvs.Append(aIC);
2448 aNewCvs.Append(aIC);
2452 // 2. Plane\Cone intersection when we had 4 curves
2453 aType1=myHS1->GetType();
2454 aType2=myHS2->GetType();
2455 aNbCurves=aNewCvs.Length();
2457 if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone) ||
2458 (aType2==GeomAbs_Plane && aType1==GeomAbs_Cone)) {
2460 GeomAbs_CurveType aCType1;
2462 aCType1=aNewCvs(1).Type();
2463 if (aCType1==GeomAbs_Line) {
2464 IntTools_SequenceOfCurves aSeqIn, aSeqOut;
2466 for (i=1; i<=aNbCurves; ++i) {
2467 const IntTools_Curve& aIC=aNewCvs(i);
2471 IntTools_Tools::RejectLines(aSeqIn, aSeqOut);
2474 aNbCurves=aSeqOut.Length();
2475 for (i=1; i<=aNbCurves; ++i) {
2476 const IntTools_Curve& aIC=aSeqOut(i);
2477 aNewCvs.Append(aIC);
2481 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone)...
2483 // 3. Fill mySeqOfCurve
2484 mySeqOfCurve.Clear();
2485 aNbCurves=aNewCvs.Length();
2486 for (i=1; i<=aNbCurves; ++i) {
2487 const IntTools_Curve& aIC=aNewCvs(i);
2488 mySeqOfCurve.Append(aIC);
2491 //=======================================================================
2492 //function : CorrectSurfaceBoundaries
2494 //=======================================================================
2495 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
2496 const Standard_Real theTolerance,
2497 Standard_Real& theumin,
2498 Standard_Real& theumax,
2499 Standard_Real& thevmin,
2500 Standard_Real& thevmax)
2502 Standard_Boolean enlarge, isuperiodic, isvperiodic;
2503 Standard_Real uinf, usup, vinf, vsup, delta;
2504 GeomAbs_SurfaceType aType;
2505 Handle(Geom_Surface) aSurface;
2507 aSurface = BRep_Tool::Surface(theFace);
2508 aSurface->Bounds(uinf, usup, vinf, vsup);
2509 delta = theTolerance;
2510 enlarge = Standard_False;
2512 GeomAdaptor_Surface anAdaptorSurface(aSurface);
2514 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
2515 Handle(Geom_Surface) aBasisSurface =
2516 (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface))->BasisSurface();
2518 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2519 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2524 if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2525 Handle(Geom_Surface) aBasisSurface =
2526 (Handle(Geom_OffsetSurface)::DownCast(aSurface))->BasisSurface();
2528 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2529 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2534 isuperiodic = anAdaptorSurface.IsUPeriodic();
2535 isvperiodic = anAdaptorSurface.IsVPeriodic();
2537 aType=anAdaptorSurface.GetType();
2538 if((aType==GeomAbs_BezierSurface) ||
2539 (aType==GeomAbs_BSplineSurface) ||
2540 (aType==GeomAbs_SurfaceOfExtrusion) ||
2541 (aType==GeomAbs_SurfaceOfRevolution) ||
2542 (aType==GeomAbs_Cylinder)) {
2543 enlarge=Standard_True;
2546 if(!isuperiodic && enlarge) {
2548 if((theumin - uinf) > delta )
2554 if((usup - theumax) > delta )
2560 if(!isvperiodic && enlarge) {
2561 if((thevmin - vinf) > delta ) {
2567 if((vsup - thevmax) > delta ) {
2576 Standard_Integer aNbP;
2577 Standard_Real aXP, dXfact, aXmid, aX1, aX2, aTolPA;
2579 aTolPA=Precision::Angular();
2582 aXP=anAdaptorSurface.UPeriod();
2583 dXfact=theumax-theumin;
2584 if (dXfact-aTolPA>aXP) {
2585 aXmid=0.5*(theumax+theumin);
2586 aNbP=RealToInt(aXmid/aXP);
2591 if (theumin>aTolPA) {
2592 aX1=theumin+aNbP*aXP;
2605 aXP=anAdaptorSurface.VPeriod();
2606 dXfact=thevmax-thevmin;
2607 if (dXfact-aTolPA>aXP) {
2608 aXmid=0.5*(thevmax+thevmin);
2609 aNbP=RealToInt(aXmid/aXP);
2614 if (thevmin>aTolPA) {
2615 aX1=thevmin+aNbP*aXP;
2628 if(isuperiodic || isvperiodic) {
2629 Standard_Boolean correct = Standard_False;
2630 Standard_Boolean correctU = Standard_False;
2631 Standard_Boolean correctV = Standard_False;
2633 TopExp_Explorer anExp;
2635 for(anExp.Init(theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
2636 if(BRep_Tool::IsClosed(TopoDS::Edge(anExp.Current()), theFace)) {
2637 correct = Standard_True;
2639 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
2641 for(Standard_Integer i = 0; i < 2; i++) {
2643 anEdge.Orientation(TopAbs_FORWARD);
2646 anEdge.Orientation(TopAbs_REVERSED);
2648 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l);
2650 if(aCurve.IsNull()) {
2651 correct = Standard_False;
2654 Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve);
2656 if(aLine.IsNull()) {
2657 correct = Standard_False;
2660 gp_Dir2d anUDir(1., 0.);
2661 gp_Dir2d aVDir(0., 1.);
2662 Standard_Real anAngularTolerance = Precision::Angular();
2664 correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance);
2665 correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance);
2667 gp_Pnt2d pp1 = aCurve->Value(f);
2669 gp_Pnt2d pp2 = aCurve->Value(l);
2678 Standard_Real umin, vmin, umax, vmax;
2679 aBox.Get(umin, vmin, umax, vmax);
2681 if(isuperiodic && correctU) {
2686 if(theumax > umax) {
2690 if(isvperiodic && correctV) {
2702 // The block is dedicated to determine whether WLine [ifprm, ilprm]
2703 // crosses the degenerated zone on each given surface or not.
2704 // If Yes -> We will not use info about surfaces during approximation
2705 // because inside degenerated zone of the surface the approx. algo.
2706 // uses wrong values of normal, etc., and resulting curve will have
2707 // oscillations that we would not like to have.
2712 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2713 const Handle(Geom_Surface)& aS,
2714 const Standard_Integer iDir);
2716 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2717 const TopoDS_Face& aF1,
2718 const TopoDS_Face& aF2);
2719 //=======================================================================
2720 //function : NotUseSurfacesForApprox
2722 //=======================================================================
2723 Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1,
2724 const TopoDS_Face& aF2,
2725 const Handle(IntPatch_WLine)& WL,
2726 const Standard_Integer ifprm,
2727 const Standard_Integer ilprm)
2729 Standard_Boolean bPInDZ;
2731 Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve();
2733 const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm);
2734 bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2);
2739 const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm);
2740 bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2);
2744 //=======================================================================
2745 //function : IsPointInDegeneratedZone
2747 //=======================================================================
2748 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2749 const TopoDS_Face& aF1,
2750 const TopoDS_Face& aF2)
2753 Standard_Boolean bFlag=Standard_True;
2754 Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22;
2755 Standard_Real U1, V1, U2, V2, aDelta, aD;
2758 Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1);
2759 aS1->Bounds(US11, US12, VS11, VS12);
2760 GeomAdaptor_Surface aGAS1(aS1);
2762 Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2);
2763 aS1->Bounds(US21, US22, VS21, VS22);
2764 GeomAdaptor_Surface aGAS2(aS2);
2766 //const gp_Pnt& aP=aP2S.Value();
2767 aP2S.Parameters(U1, V1, U2, V2);
2771 aD=aGAS1.UResolution(aDelta);
2772 aP2d.SetCoord(U1, V1);
2773 if (fabs(U1-US11) < aD) {
2774 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2779 if (fabs(U1-US12) < aD) {
2780 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2785 aD=aGAS1.VResolution(aDelta);
2786 if (fabs(V1-VS11) < aDelta) {
2787 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2792 if (fabs(V1-VS12) < aDelta) {
2793 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2799 aD=aGAS2.UResolution(aDelta);
2800 aP2d.SetCoord(U2, V2);
2801 if (fabs(U2-US21) < aDelta) {
2802 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2807 if (fabs(U2-US22) < aDelta) {
2808 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2813 aD=aGAS2.VResolution(aDelta);
2814 if (fabs(V2-VS21) < aDelta) {
2815 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2820 if (fabs(V2-VS22) < aDelta) {
2821 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2829 //=======================================================================
2830 //function : IsDegeneratedZone
2832 //=======================================================================
2833 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2834 const Handle(Geom_Surface)& aS,
2835 const Standard_Integer iDir)
2837 Standard_Boolean bFlag=Standard_True;
2838 Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD;
2839 Standard_Real aXm, aYm, aXb, aYb, aXe, aYe;
2840 aS->Bounds(US1, US2, VS1, VS2);
2842 gp_Pnt aPm, aPb, aPe;
2847 aS->D0(aXm, aYm, aPm);
2864 aS->D0(aXb, aYb, aPb);
2865 aS->D0(aXe, aYe, aPe);
2867 d1=aPm.Distance(aPb);
2868 d2=aPm.Distance(aPe);
2869 if (d1 < dD && d2 < dD) {
2886 aS->D0(aXb, aYb, aPb);
2887 aS->D0(aXe, aYe, aPe);
2889 d1=aPm.Distance(aPb);
2890 d2=aPm.Distance(aPe);
2891 if (d1 < dD && d2 < dD) {
2899 //=========================================================================
2900 // static function : ComputePurgedWLine
2901 // purpose : Removes equal points (leave one of equal points) from theWLine
2902 // and recompute vertex parameters.
2903 // Returns new WLine or null WLine if the number
2904 // of the points is less than 2.
2905 //=========================================================================
2906 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine) {
2908 Standard_Integer i, k, v, nb, nbvtx;
2909 Handle(IntPatch_WLine) aResult;
2910 nbvtx = theWLine->NbVertex();
2911 nb = theWLine->NbPnts();
2913 const IntSurf_PntOn2S& p1 = theWLine->Point(1);
2914 const IntSurf_PntOn2S& p2 = theWLine->Point(2);
2915 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
2920 Handle(IntPatch_WLine) aLocalWLine;
2921 Handle(IntPatch_WLine) aTmpWLine = theWLine;
2922 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
2923 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2924 for(i = 1; i <= nb; i++) {
2925 aLineOn2S->Add(theWLine->Point(i));
2928 for(v = 1; v <= nbvtx; v++) {
2929 aLocalWLine->AddVertex(theWLine->Vertex(v));
2932 for(i = 1; i <= aLineOn2S->NbPoints(); i++) {
2933 Standard_Integer aStartIndex = i + 1;
2934 Standard_Integer anEndIndex = i + 5;
2935 nb = aLineOn2S->NbPoints();
2936 anEndIndex = (anEndIndex > nb) ? nb : anEndIndex;
2938 if((aStartIndex > nb) || (anEndIndex <= 1)) {
2943 while(k <= anEndIndex) {
2946 IntSurf_PntOn2S p1 = aLineOn2S->Value(i);
2947 IntSurf_PntOn2S p2 = aLineOn2S->Value(k);
2949 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
2950 aTmpWLine = aLocalWLine;
2951 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2953 for(v = 1; v <= aTmpWLine->NbVertex(); v++) {
2954 IntPatch_Point aVertex = aTmpWLine->Vertex(v);
2955 Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine();
2957 if(avertexindex >= k) {
2958 aVertex.SetParameter(aVertex.ParameterOnLine() - 1.);
2960 aLocalWLine->AddVertex(aVertex);
2962 aLineOn2S->RemovePoint(k);
2971 if(aLineOn2S->NbPoints() > 1) {
2972 aResult = aLocalWLine;
2977 //=======================================================================
2980 //=======================================================================
2981 void TolR3d(const TopoDS_Face& aF1,
2982 const TopoDS_Face& aF2,
2983 Standard_Real& myTolReached3d)
2985 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
2987 aTolTresh=2.999999e-3;
2988 aTolF1 = BRep_Tool::Tolerance(aF1);
2989 aTolF2 = BRep_Tool::Tolerance(aF2);
2990 aTolFMax=Max(aTolF1, aTolF2);
2992 if (aTolFMax>aTolTresh) {
2993 myTolReached3d=aTolFMax;
2996 //=======================================================================
2997 //function : IsPointOnBoundary
2999 //=======================================================================
3000 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
3001 const Standard_Real theFirstBoundary,
3002 const Standard_Real theSecondBoundary,
3003 const Standard_Real theResolution,
3004 Standard_Boolean& IsOnFirstBoundary)
3006 Standard_Boolean bRet;
3008 Standard_Real adist;
3010 bRet=Standard_False;
3011 for(i = 0; i < 2; ++i) {
3012 IsOnFirstBoundary = (i == 0);
3013 if (IsOnFirstBoundary) {
3014 adist = fabs(theParameter - theFirstBoundary);
3017 adist = fabs(theParameter - theSecondBoundary);
3019 if(adist < theResolution) {
3025 // ------------------------------------------------------------------------------------------------
3026 // static function: FindPoint
3028 // ------------------------------------------------------------------------------------------------
3029 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3030 const gp_Pnt2d& theLastPoint,
3031 const Standard_Real theUmin,
3032 const Standard_Real theUmax,
3033 const Standard_Real theVmin,
3034 const Standard_Real theVmax,
3035 gp_Pnt2d& theNewPoint) {
3037 gp_Vec2d aVec(theFirstPoint, theLastPoint);
3038 Standard_Integer i = 0, j = 0;
3040 for(i = 0; i < 4; i++) {
3041 gp_Vec2d anOtherVec;
3042 gp_Vec2d anOtherVecNormal;
3043 gp_Pnt2d aprojpoint = theLastPoint;
3046 anOtherVec.SetX(0.);
3047 anOtherVec.SetY(1.);
3048 anOtherVecNormal.SetX(1.);
3049 anOtherVecNormal.SetY(0.);
3052 aprojpoint.SetX(theUmin);
3054 aprojpoint.SetX(theUmax);
3057 anOtherVec.SetX(1.);
3058 anOtherVec.SetY(0.);
3059 anOtherVecNormal.SetX(0.);
3060 anOtherVecNormal.SetY(1.);
3063 aprojpoint.SetY(theVmin);
3065 aprojpoint.SetY(theVmax);
3067 gp_Vec2d anormvec = aVec;
3068 anormvec.Normalize();
3069 RefineVector(anormvec);
3070 Standard_Real adot1 = anormvec.Dot(anOtherVecNormal);
3072 if(fabs(adot1) < Precision::Angular())
3074 Standard_Real adist = 0.;
3075 Standard_Boolean bIsOut = Standard_False;
3078 adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax);
3079 bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax);
3082 adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax);
3083 bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax);
3085 Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1;
3087 for(j = 0; j < 2; j++) {
3088 anoffset = (j == 0) ? anoffset : -anoffset;
3089 gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset));
3090 gp_Vec2d acurvec(theLastPoint, acurpoint);
3094 Standard_Real aDotX, anAngleX;
3096 aDotX = aVec.Dot(acurvec);
3097 anAngleX = aVec.Angle(acurvec);
3099 if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) {
3101 if((acurpoint.Y() >= theVmin) &&
3102 (acurpoint.Y() <= theVmax)) {
3103 theNewPoint = acurpoint;
3104 return Standard_True;
3108 if((acurpoint.X() >= theUmin) &&
3109 (acurpoint.X() <= theUmax)) {
3110 theNewPoint = acurpoint;
3111 return Standard_True;
3117 return Standard_False;
3121 // ------------------------------------------------------------------------------------------------
3122 // static function: FindPoint
3123 // purpose: Find point on the boundary of radial tangent zone
3124 // ------------------------------------------------------------------------------------------------
3125 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3126 const gp_Pnt2d& theLastPoint,
3127 const Standard_Real theUmin,
3128 const Standard_Real theUmax,
3129 const Standard_Real theVmin,
3130 const Standard_Real theVmax,
3131 const gp_Pnt2d& theTanZoneCenter,
3132 const Standard_Real theZoneRadius,
3133 Handle(GeomAdaptor_HSurface) theGASurface,
3134 gp_Pnt2d& theNewPoint) {
3135 theNewPoint = theLastPoint;
3137 if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) )
3138 return Standard_False;
3140 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3141 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3143 Standard_Real aRadius = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3144 gp_Ax22d anAxis( theTanZoneCenter, gp_Dir2d(1, 0), gp_Dir2d(0, 1) );
3145 gp_Circ2d aCircle( anAxis, aRadius );
3148 gp_Vec2d aDir( theLastPoint.XY() - theFirstPoint.XY() );
3149 Standard_Real aLength = aDir.Magnitude();
3150 if ( aLength <= gp::Resolution() )
3151 return Standard_False;
3152 gp_Lin2d aLine( theFirstPoint, aDir );
3155 Handle(Geom2d_Line) aCLine = new Geom2d_Line( aLine );
3156 Handle(Geom2d_TrimmedCurve) aC1 = new Geom2d_TrimmedCurve( aCLine, 0, aLength );
3157 Handle(Geom2d_Circle) aC2 = new Geom2d_Circle( aCircle );
3159 Standard_Real aTol = aRadius * 0.001;
3160 aTol = ( aTol < Precision::PConfusion() ) ? Precision::PConfusion() : aTol;
3162 Geom2dAPI_InterCurveCurve anIntersector;
3163 anIntersector.Init( aC1, aC2, aTol );
3165 if ( anIntersector.NbPoints() == 0 )
3166 return Standard_False;
3168 Standard_Boolean aFound = Standard_False;
3169 Standard_Real aMinDist = aLength * aLength;
3170 Standard_Integer i = 0;
3171 for ( i = 1; i <= anIntersector.NbPoints(); i++ ) {
3172 gp_Pnt2d aPInt = anIntersector.Point( i );
3173 if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) {
3174 if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) &&
3175 ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) {
3176 theNewPoint = aPInt;
3177 aFound = Standard_True;
3185 // ------------------------------------------------------------------------------------------------
3186 // static function: IsInsideTanZone
3187 // purpose: Check if point is inside a radial tangent zone
3188 // ------------------------------------------------------------------------------------------------
3189 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
3190 const gp_Pnt2d& theTanZoneCenter,
3191 const Standard_Real theZoneRadius,
3192 Handle(GeomAdaptor_HSurface) theGASurface) {
3194 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3195 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3196 Standard_Real aRadiusSQR = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3197 aRadiusSQR *= aRadiusSQR;
3198 if ( thePoint.SquareDistance( theTanZoneCenter ) <= aRadiusSQR )
3199 return Standard_True;
3200 return Standard_False;
3203 // ------------------------------------------------------------------------------------------------
3204 // static function: CheckTangentZonesExist
3205 // purpose: Check if tangent zone exists
3206 // ------------------------------------------------------------------------------------------------
3207 Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& theSurface1,
3208 const Handle(GeomAdaptor_HSurface)& theSurface2 )
3210 if ( ( theSurface1->GetType() != GeomAbs_Torus ) ||
3211 ( theSurface2->GetType() != GeomAbs_Torus ) )
3212 return Standard_False;
3214 gp_Torus aTor1 = theSurface1->Torus();
3215 gp_Torus aTor2 = theSurface2->Torus();
3217 if ( aTor1.Location().Distance( aTor2.Location() ) > Precision::Confusion() )
3218 return Standard_False;
3220 if ( ( fabs( aTor1.MajorRadius() - aTor2.MajorRadius() ) > Precision::Confusion() ) ||
3221 ( fabs( aTor1.MinorRadius() - aTor2.MinorRadius() ) > Precision::Confusion() ) )
3222 return Standard_False;
3224 if ( ( aTor1.MajorRadius() < aTor1.MinorRadius() ) ||
3225 ( aTor2.MajorRadius() < aTor2.MinorRadius() ) )
3226 return Standard_False;
3227 return Standard_True;
3230 // ------------------------------------------------------------------------------------------------
3231 // static function: ComputeTangentZones
3233 // ------------------------------------------------------------------------------------------------
3234 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
3235 const Handle(GeomAdaptor_HSurface)& theSurface2,
3236 const TopoDS_Face& theFace1,
3237 const TopoDS_Face& theFace2,
3238 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
3239 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
3240 Handle(TColStd_HArray1OfReal)& theResultRadius,
3241 const Handle(IntTools_Context)& aContext)
3243 Standard_Integer aResult = 0;
3244 if ( !CheckTangentZonesExist( theSurface1, theSurface2 ) )
3248 TColgp_SequenceOfPnt2d aSeqResultS1, aSeqResultS2;
3249 TColStd_SequenceOfReal aSeqResultRad;
3251 gp_Torus aTor1 = theSurface1->Torus();
3252 gp_Torus aTor2 = theSurface2->Torus();
3254 gp_Ax2 anax1( aTor1.Location(), aTor1.Axis().Direction() );
3255 gp_Ax2 anax2( aTor2.Location(), aTor2.Axis().Direction() );
3256 Standard_Integer j = 0;
3258 for ( j = 0; j < 2; j++ ) {
3259 Standard_Real aCoef = ( j == 0 ) ? -1 : 1;
3260 Standard_Real aRadius1 = fabs(aTor1.MajorRadius() + aCoef * aTor1.MinorRadius());
3261 Standard_Real aRadius2 = fabs(aTor2.MajorRadius() + aCoef * aTor2.MinorRadius());
3263 gp_Circ aCircle1( anax1, aRadius1 );
3264 gp_Circ aCircle2( anax2, aRadius2 );
3266 // roughly compute radius of tangent zone for perpendicular case
3267 Standard_Real aCriteria = Precision::Confusion() * 0.5;
3269 Standard_Real aT1 = aCriteria;
3270 Standard_Real aT2 = aCriteria;
3272 // internal tangency
3273 Standard_Real aR = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3274 //aT1 = aCriteria * aCriteria + aR * aR - ( aR - aCriteria ) * ( aR - aCriteria );
3275 aT1 = 2. * aR * aCriteria;
3279 // external tangency
3280 Standard_Real aRb = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3281 Standard_Real aRm = ( aRadius1 < aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3282 Standard_Real aDelta = aRb - aCriteria;
3284 aDelta -= aRm * aRm;
3285 aDelta /= 2. * (aRb - aRm);
3286 aDelta -= 0.5 * (aRb - aRm);
3288 aT1 = 2. * aRm * (aRm - aDelta);
3291 aCriteria = ( aT1 > aT2) ? aT1 : aT2;
3292 if ( aCriteria > 0 )
3293 aCriteria = sqrt( aCriteria );
3295 if ( aCriteria > 0.5 * aTor1.MinorRadius() ) {
3296 // too big zone -> drop to minimum
3297 aCriteria = Precision::Confusion();
3300 GeomAdaptor_Curve aC1( new Geom_Circle(aCircle1) );
3301 GeomAdaptor_Curve aC2( new Geom_Circle(aCircle2) );
3302 Extrema_ExtCC anExtrema(aC1, aC2, 0, 2. * M_PI, 0, 2. * M_PI,
3303 Precision::PConfusion(), Precision::PConfusion());
3305 if ( anExtrema.IsDone() ) {
3307 Standard_Integer i = 0;
3308 for ( i = 1; i <= anExtrema.NbExt(); i++ ) {
3309 if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria )
3312 Extrema_POnCurv P1, P2;
3313 anExtrema.Points( i, P1, P2 );
3315 Standard_Boolean bFoundResult = Standard_True;
3318 Standard_Integer surfit = 0;
3319 for ( surfit = 0; surfit < 2; surfit++ ) {
3320 GeomAPI_ProjectPointOnSurf& aProjector =
3321 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3323 gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value();
3324 aProjector.Perform(aP3d);
3326 if(!aProjector.IsDone())
3327 bFoundResult = Standard_False;
3329 if(aProjector.LowerDistance() > aCriteria) {
3330 bFoundResult = Standard_False;
3333 Standard_Real foundU = 0, foundV = 0;
3334 aProjector.LowerDistanceParameters(foundU, foundV);
3336 pr1 = gp_Pnt2d( foundU, foundV );
3338 pr2 = gp_Pnt2d( foundU, foundV );
3342 if ( bFoundResult ) {
3343 aSeqResultS1.Append( pr1 );
3344 aSeqResultS2.Append( pr2 );
3345 aSeqResultRad.Append( aCriteria );
3347 // torus is u and v periodic
3348 const Standard_Real twoPI = M_PI + M_PI;
3349 Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()};
3350 Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()};
3352 // iteration on period bounds
3353 for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) {
3354 Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI;
3355 Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI;
3357 // iteration on surfaces
3358 for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) {
3359 Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp;
3360 Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp;
3361 TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2;
3362 TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2;
3364 if (fabs(arr1[0] - aBound) < Precision::PConfusion()) {
3365 aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) );
3366 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3367 aSeqResultRad.Append( aCriteria );
3369 if (fabs(arr1[1] - aBound) < Precision::PConfusion()) {
3370 aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) );
3371 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3372 aSeqResultRad.Append( aCriteria );
3380 aResult = aSeqResultRad.Length();
3382 if ( aResult > 0 ) {
3383 theResultOnS1 = new TColgp_HArray1OfPnt2d( 1, aResult );
3384 theResultOnS2 = new TColgp_HArray1OfPnt2d( 1, aResult );
3385 theResultRadius = new TColStd_HArray1OfReal( 1, aResult );
3387 for ( Standard_Integer i = 1 ; i <= aResult; i++ ) {
3388 theResultOnS1->SetValue( i, aSeqResultS1.Value(i) );
3389 theResultOnS2->SetValue( i, aSeqResultS2.Value(i) );
3390 theResultRadius->SetValue( i, aSeqResultRad.Value(i) );
3396 // ------------------------------------------------------------------------------------------------
3397 // static function: AdjustByNeighbour
3399 // ------------------------------------------------------------------------------------------------
3400 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
3401 const gp_Pnt2d& theOriginalPoint,
3402 Handle(GeomAdaptor_HSurface) theGASurface) {
3404 gp_Pnt2d ap1 = theaNeighbourPoint;
3405 gp_Pnt2d ap2 = theOriginalPoint;
3407 if ( theGASurface->IsUPeriodic() ) {
3408 Standard_Real aPeriod = theGASurface->UPeriod();
3409 gp_Pnt2d aPTest = ap2;
3410 Standard_Real aSqDistMin = 1.e+100;
3412 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3413 aPTest.SetX( theOriginalPoint.X() + aPeriod * pIt );
3414 Standard_Real dd = ap1.SquareDistance( aPTest );
3416 if ( dd < aSqDistMin ) {
3422 if ( theGASurface->IsVPeriodic() ) {
3423 Standard_Real aPeriod = theGASurface->VPeriod();
3424 gp_Pnt2d aPTest = ap2;
3425 Standard_Real aSqDistMin = 1.e+100;
3427 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3428 aPTest.SetY( theOriginalPoint.Y() + aPeriod * pIt );
3429 Standard_Real dd = ap1.SquareDistance( aPTest );
3431 if ( dd < aSqDistMin ) {
3440 // ------------------------------------------------------------------------------------------------
3441 //function: DecompositionOfWLine
3443 // ------------------------------------------------------------------------------------------------
3444 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
3445 const Handle(GeomAdaptor_HSurface)& theSurface1,
3446 const Handle(GeomAdaptor_HSurface)& theSurface2,
3447 const TopoDS_Face& theFace1,
3448 const TopoDS_Face& theFace2,
3449 const GeomInt_LineConstructor& theLConstructor,
3450 const Standard_Boolean theAvoidLConstructor,
3451 IntPatch_SequenceOfLine& theNewLines,
3452 Standard_Real& theReachedTol3d,
3453 const Handle(IntTools_Context)& aContext)
3456 Standard_Boolean bRet, bAvoidLineConstructor;
3457 Standard_Integer aNbPnts, aNbParts;
3459 bRet=Standard_False;
3460 aNbPnts=theWLine->NbPnts();
3461 bAvoidLineConstructor=theAvoidLConstructor;
3466 if (!bAvoidLineConstructor) {
3467 aNbParts=theLConstructor.NbParts();
3473 Standard_Boolean bIsPrevPointOnBoundary, bIsPointOnBoundary, bIsCurrentPointOnBoundary;
3474 Standard_Integer nblines, pit, i, j;
3476 TColStd_Array1OfListOfInteger anArrayOfLines(1, aNbPnts);
3477 TColStd_Array1OfInteger anArrayOfLineType(1, aNbPnts);
3478 TColStd_ListOfInteger aListOfPointIndex;
3480 Handle(TColgp_HArray1OfPnt2d) aTanZoneS1;
3481 Handle(TColgp_HArray1OfPnt2d) aTanZoneS2;
3482 Handle(TColStd_HArray1OfReal) aTanZoneRadius;
3483 Standard_Integer aNbZone = ComputeTangentZones( theSurface1, theSurface2, theFace1, theFace2,
3484 aTanZoneS1, aTanZoneS2, aTanZoneRadius, aContext);
3488 aTol=Precision::Confusion();
3490 bIsPrevPointOnBoundary=Standard_False;
3491 bIsPointOnBoundary=Standard_False;
3496 for(pit = 1; pit <= aNbPnts; ++pit) {
3497 Standard_Boolean bIsOnFirstBoundary, isperiodic;
3498 Standard_Real aResolution, aPeriod, alowerboundary, aupperboundary, U, V;
3499 Standard_Real aParameter, anoffset, anAdjustPar;
3500 Standard_Real umin, umax, vmin, vmax;
3502 bIsCurrentPointOnBoundary = Standard_False;
3503 const IntSurf_PntOn2S& aPoint = theWLine->Point(pit);
3506 for(i = 0; i < 2; ++i) {
3507 Handle(GeomAdaptor_HSurface) aGASurface = (!i) ? theSurface1 : theSurface2;
3508 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3510 aPoint.ParametersOnS1(U, V);
3513 aPoint.ParametersOnS2(U, V);
3516 for(j = 0; j < 2; j++) {
3517 isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3523 aResolution=aGASurface->UResolution(aTol);
3524 aPeriod=aGASurface->UPeriod();
3525 alowerboundary=umin;
3526 aupperboundary=umax;
3530 aResolution=aGASurface->VResolution(aTol);
3531 aPeriod=aGASurface->VPeriod();
3532 alowerboundary=vmin;
3533 aupperboundary=vmax;
3537 GeomInt::AdjustPeriodic(aParameter,
3544 bIsOnFirstBoundary = Standard_True;// ?
3546 IsPointOnBoundary(anAdjustPar,
3550 bIsOnFirstBoundary);
3552 if(bIsPointOnBoundary) {
3553 bIsCurrentPointOnBoundary = Standard_True;
3557 // check if a point belong to a tangent zone. Begin
3558 Standard_Integer zIt = 0;
3559 for ( zIt = 1; zIt <= aNbZone; zIt++ ) {
3560 gp_Pnt2d aPZone = (i == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3561 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3563 if ( IsInsideTanZone(gp_Pnt2d( U, V ), aPZone, aZoneRadius, aGASurface ) ) {
3564 // set boundary flag to split the curve by a tangent zone
3565 bIsPointOnBoundary = Standard_True;
3566 bIsCurrentPointOnBoundary = Standard_True;
3567 if ( theReachedTol3d < aZoneRadius ) {
3568 theReachedTol3d = aZoneRadius;
3574 }//for(j = 0; j < 2; j++) {
3576 if(bIsCurrentPointOnBoundary){
3579 }//for(i = 0; i < 2; ++i) {
3581 if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) {
3582 if(!aListOfPointIndex.IsEmpty()) {
3584 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3585 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3586 aListOfPointIndex.Clear();
3588 bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary;
3590 aListOfPointIndex.Append(pit);
3591 } //for(pit = 1; pit <= aNbPnts; ++pit) {
3593 if(!aListOfPointIndex.IsEmpty()) {
3595 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3596 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3597 aListOfPointIndex.Clear();
3601 return bRet; //Standard_False;
3605 // 2. Correct wlines.begin
3606 TColStd_Array1OfListOfInteger anArrayOfLineEnds(1, nblines);
3607 Handle(IntSurf_LineOn2S) aSeqOfPntOn2S = new IntSurf_LineOn2S();
3609 for(i = 1; i <= nblines; i++) {
3610 if(anArrayOfLineType.Value(i) != 0) {
3613 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3614 TColStd_ListOfInteger aListOfFLIndex;
3616 for(j = 0; j < 2; j++) {
3617 Standard_Integer aneighbourindex = (j == 0) ? (i - 1) : (i + 1);
3619 if((aneighbourindex < 1) || (aneighbourindex > nblines))
3622 if(anArrayOfLineType.Value(aneighbourindex) == 0)
3624 const TColStd_ListOfInteger& aNeighbour = anArrayOfLines.Value(aneighbourindex);
3625 Standard_Integer anIndex = (j == 0) ? aNeighbour.Last() : aNeighbour.First();
3626 const IntSurf_PntOn2S& aPoint = theWLine->Point(anIndex);
3628 IntSurf_PntOn2S aNewP = aPoint;
3629 if(aListOfIndex.Extent() < 2) {
3630 aSeqOfPntOn2S->Add(aNewP);
3631 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
3635 Standard_Integer iFirst = aListOfIndex.First();
3636 Standard_Integer iLast = aListOfIndex.Last();
3638 for(Standard_Integer surfit = 0; surfit < 2; surfit++) {
3640 Handle(GeomAdaptor_HSurface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2;
3641 Standard_Real umin=0., umax=0., vmin=0., vmax=0.;
3642 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3643 Standard_Real U=0., V=0.;
3646 aNewP.ParametersOnS1(U, V);
3648 aNewP.ParametersOnS2(U, V);
3649 Standard_Integer nbboundaries = 0;
3651 Standard_Boolean bIsNearBoundary = Standard_False;
3652 Standard_Integer aZoneIndex = 0;
3653 Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1
3654 Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1
3657 for(Standard_Integer parit = 0; parit < 2; parit++) {
3658 Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3660 Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
3661 Standard_Real alowerboundary = (parit == 0) ? umin : vmin;
3662 Standard_Real aupperboundary = (parit == 0) ? umax : vmax;
3664 Standard_Real aParameter = (parit == 0) ? U : V;
3665 Standard_Boolean bIsOnFirstBoundary = Standard_True;
3669 IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3670 if(bIsPointOnBoundary) {
3671 bIsUBoundary = (parit == 0);
3672 bIsFirstBoundary = bIsOnFirstBoundary;
3677 Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3678 Standard_Real anoffset, anAdjustPar;
3679 GeomInt::AdjustPeriodic(aParameter, alowerboundary, aupperboundary,
3680 aPeriod, anAdjustPar, anoffset);
3683 IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3684 if(bIsPointOnBoundary) {
3685 bIsUBoundary = (parit == 0);
3686 bIsFirstBoundary = bIsOnFirstBoundary;
3690 //check neighbourhood of boundary
3691 Standard_Real anEpsilon = aResolution * 100.;
3692 Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
3693 anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
3695 bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary,
3696 anEpsilon, bIsOnFirstBoundary);
3702 // check if a point belong to a tangent zone. Begin
3703 for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) {
3704 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3705 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3707 Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast;
3708 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3709 Standard_Real nU1, nV1;
3712 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3714 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3715 gp_Pnt2d ap1(nU1, nV1);
3716 gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface );
3719 if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) {
3721 bIsNearBoundary = Standard_True;
3722 if ( theReachedTol3d < aZoneRadius ) {
3723 theReachedTol3d = aZoneRadius;
3727 // check if a point belong to a tangent zone. End
3728 Standard_Boolean bComputeLineEnd = Standard_False;
3730 if(nbboundaries == 2) {
3732 bComputeLineEnd = Standard_True;
3735 else if(nbboundaries == 1) {
3736 Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3739 Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
3740 Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
3741 Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3742 Standard_Real aParameter = (bIsUBoundary) ? U : V;
3743 Standard_Real anoffset, anAdjustPar;
3744 GeomInt::AdjustPeriodic(aParameter, alowerboundary, aupperboundary,
3745 aPeriod, anAdjustPar, anoffset);
3747 Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
3748 Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
3749 anotherPar += anoffset;
3750 Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3751 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
3752 Standard_Real nU1, nV1;
3755 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3757 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3759 Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
3760 Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
3761 bComputeLineEnd = Standard_True;
3762 Standard_Boolean bCheckAngle1 = Standard_False;
3763 Standard_Boolean bCheckAngle2 = Standard_False;
3765 Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
3766 Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
3768 if(((adist1 - adist2) > Precision::PConfusion()) &&
3769 (adist2 < (aPeriod / 4.))) {
3770 bCheckAngle1 = Standard_True;
3771 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
3773 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3774 aNewP.SetValue((surfit == 0), anewU, anewV);
3775 bCheckAngle1 = Standard_False;
3778 else if(adist1 < (aPeriod / 4.)) {
3779 bCheckAngle2 = Standard_True;
3780 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
3782 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3783 bCheckAngle2 = Standard_False;
3787 if(bCheckAngle1 || bCheckAngle2) {
3788 // assume there are at least two points in line (see "if" above)
3789 Standard_Integer anindexother = aneighbourpointindex;
3791 while((anindexother <= iLast) && (anindexother >= iFirst)) {
3792 anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
3793 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
3794 Standard_Real nU2, nV2;
3797 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3799 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3800 gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
3802 if(aVecOld.SquareMagnitude() <= (gp::Resolution() * gp::Resolution())) {
3806 Standard_Real anAngle = aNewVec.Angle(aVecOld);
3808 if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
3811 Standard_Real U1, U2, V1, V2;
3812 IntSurf_PntOn2S atmppoint = aNewP;
3813 atmppoint.SetValue((surfit == 0), anewU, anewV);
3814 atmppoint.Parameters(U1, V1, U2, V2);
3815 gp_Pnt P1 = theSurface1->Value(U1, V1);
3816 gp_Pnt P2 = theSurface2->Value(U2, V2);
3817 gp_Pnt P0 = aPoint.Value();
3819 if(P0.IsEqual(P1, aTol) &&
3820 P0.IsEqual(P2, aTol) &&
3821 P1.IsEqual(P2, aTol)) {
3822 bComputeLineEnd = Standard_False;
3823 aNewP.SetValue((surfit == 0), anewU, anewV);
3828 bComputeLineEnd = Standard_False;
3833 } // end while(anindexother...)
3837 else if ( bIsNearBoundary ) {
3838 bComputeLineEnd = Standard_True;
3841 if(bComputeLineEnd) {
3844 Standard_Boolean found = Standard_False;
3846 if ( bIsNearBoundary ) {
3847 // re-compute point near natural boundary or near tangent zone
3848 Standard_Real u1, v1, u2, v2;
3849 aNewP.Parameters( u1, v1, u2, v2 );
3851 anewpoint = gp_Pnt2d( u1, v1 );
3853 anewpoint = gp_Pnt2d( u2, v2 );
3855 Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast;
3856 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3857 Standard_Real nU1, nV1;
3860 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3862 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3863 gp_Pnt2d ap1(nU1, nV1);
3868 // exclude point from a tangent zone
3869 anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3870 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex);
3871 Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex);
3873 if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax,
3874 aPZone, aZoneRadius, aGASurface, ap2) ) {
3876 found = Standard_True;
3879 else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
3880 // re-compute point near boundary if shifted on a period
3881 ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3883 if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
3884 ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
3885 found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
3889 aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
3895 Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast;
3896 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3897 Standard_Real nU1, nV1;
3900 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3902 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3903 gp_Pnt2d ap1(nU1, nV1);
3904 gp_Pnt2d ap2(nU1, nV1);
3905 Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
3907 while((aneighbourpointindex2 <= iLast) && (aneighbourpointindex2 >= iFirst)) {
3908 aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
3909 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
3910 Standard_Real nU2, nV2;
3913 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3915 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3919 if(ap1.SquareDistance(ap2) > (gp::Resolution() * gp::Resolution())) {
3923 found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
3928 Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
3929 GeomAPI_ProjectPointOnSurf& aProjector =
3930 (surfit == 0) ? aContext->ProjPS(theFace2) : aContext->ProjPS(theFace1);
3931 Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
3933 Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
3935 gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
3936 aProjector.Perform(aP3d);
3938 if(aProjector.IsDone()) {
3939 if(aProjector.LowerDistance() < aCriteria) {
3940 Standard_Real foundU = U, foundV = V;
3941 aProjector.LowerDistanceParameters(foundU, foundV);
3943 //Correction of projected coordinates. Begin
3944 //Note, it may be shifted on a period
3945 Standard_Integer aneindex1 = (j == 0) ? iFirst : iLast;
3946 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
3947 Standard_Real nUn, nVn;
3950 aNeighbourPoint.ParametersOnS2(nUn, nVn);
3952 aNeighbourPoint.ParametersOnS1(nUn, nVn);
3953 gp_Pnt2d aNeighbour2d(nUn, nVn);
3954 gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
3955 foundU = anAdjustedPoint.X();
3956 foundV = anAdjustedPoint.Y();
3958 if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
3959 ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
3960 // attempt to roughly re-compute point
3961 foundU = ( foundU < umin ) ? umin : foundU;
3962 foundU = ( foundU > umax ) ? umax : foundU;
3963 foundV = ( foundV < vmin ) ? vmin : foundV;
3964 foundV = ( foundV > vmax ) ? vmax : foundV;
3966 GeomAPI_ProjectPointOnSurf& aProjector2 =
3967 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3969 aP3d = aSurfaceOther->Value(foundU, foundV);
3970 aProjector2.Perform(aP3d);
3972 if(aProjector2.IsDone()) {
3973 if(aProjector2.LowerDistance() < aCriteria) {
3974 Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
3975 aProjector2.LowerDistanceParameters(foundU2, foundV2);
3976 anewpoint.SetX(foundU2);
3977 anewpoint.SetY(foundV2);
3981 //Correction of projected coordinates. End
3984 aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
3986 aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
3992 aSeqOfPntOn2S->Add(aNewP);
3993 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
3995 anArrayOfLineEnds.SetValue(i, aListOfFLIndex);
3997 // Correct wlines.end
3999 // Split wlines.begin
4000 Standard_Integer nbiter;
4003 if (!bAvoidLineConstructor) {
4004 nbiter=theLConstructor.NbParts();
4007 for(j = 1; j <= nbiter; ++j) {
4008 Standard_Real fprm, lprm;
4009 Standard_Integer ifprm, ilprm;
4011 if(bAvoidLineConstructor) {
4013 ilprm = theWLine->NbPnts();
4016 theLConstructor.Part(j, fprm, lprm);
4017 ifprm = (Standard_Integer)fprm;
4018 ilprm = (Standard_Integer)lprm;
4021 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
4023 for(i = 1; i <= nblines; i++) {
4024 if(anArrayOfLineType.Value(i) != 0) {
4027 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
4028 const TColStd_ListOfInteger& aListOfFLIndex = anArrayOfLineEnds.Value(i);
4029 Standard_Boolean bhasfirstpoint = (aListOfFLIndex.Extent() == 2);
4030 Standard_Boolean bhaslastpoint = (aListOfFLIndex.Extent() == 2);
4032 if(!bhasfirstpoint && !aListOfFLIndex.IsEmpty()) {
4033 bhasfirstpoint = (i != 1);
4036 if(!bhaslastpoint && !aListOfFLIndex.IsEmpty()) {
4037 bhaslastpoint = (i != nblines);
4040 Standard_Integer iFirst = aListOfIndex.First();
4041 Standard_Integer iLast = aListOfIndex.Last();
4042 Standard_Boolean bIsFirstInside = ((ifprm >= iFirst) && (ifprm <= iLast));
4043 Standard_Boolean bIsLastInside = ((ilprm >= iFirst) && (ilprm <= iLast));
4045 if(!bIsFirstInside && !bIsLastInside) {
4046 if((ifprm < iFirst) && (ilprm > iLast)) {
4047 // append whole line, and boundaries if neccesary
4048 if(bhasfirstpoint) {
4049 pit = aListOfFLIndex.First();
4050 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4053 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4055 for(; anIt.More(); anIt.Next()) {
4057 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4062 pit = aListOfFLIndex.Last();
4063 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4067 // check end of split line (end is almost always)
4068 Standard_Integer aneighbour = i + 1;
4069 Standard_Boolean bIsEndOfLine = Standard_True;
4071 if(aneighbour <= nblines) {
4072 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4074 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4075 (aListOfNeighbourIndex.IsEmpty())) {
4076 bIsEndOfLine = Standard_False;
4081 if(aLineOn2S->NbPoints() > 1) {
4082 Handle(IntPatch_WLine) aNewWLine =
4083 new IntPatch_WLine(aLineOn2S, Standard_False);
4084 theNewLines.Append(aNewWLine);
4086 aLineOn2S = new IntSurf_LineOn2S();
4091 // end if(!bIsFirstInside && !bIsLastInside)
4093 if(bIsFirstInside && bIsLastInside) {
4094 // append inside points between ifprm and ilprm
4095 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4097 for(; anIt.More(); anIt.Next()) {
4099 if((pit < ifprm) || (pit > ilprm))
4101 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4107 if(bIsFirstInside) {
4108 // append points from ifprm to last point + boundary point
4109 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4111 for(; anIt.More(); anIt.Next()) {
4115 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4120 pit = aListOfFLIndex.Last();
4121 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4124 // check end of split line (end is almost always)
4125 Standard_Integer aneighbour = i + 1;
4126 Standard_Boolean bIsEndOfLine = Standard_True;
4128 if(aneighbour <= nblines) {
4129 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4131 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4132 (aListOfNeighbourIndex.IsEmpty())) {
4133 bIsEndOfLine = Standard_False;
4138 if(aLineOn2S->NbPoints() > 1) {
4139 Handle(IntPatch_WLine) aNewWLine =
4140 new IntPatch_WLine(aLineOn2S, Standard_False);
4141 theNewLines.Append(aNewWLine);
4143 aLineOn2S = new IntSurf_LineOn2S();
4146 // end if(bIsFirstInside)
4149 // append points from first boundary point to ilprm
4150 if(bhasfirstpoint) {
4151 pit = aListOfFLIndex.First();
4152 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4155 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4157 for(; anIt.More(); anIt.Next()) {
4161 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4165 //end if(bIsLastInside)
4169 if(aLineOn2S->NbPoints() > 1) {
4170 Handle(IntPatch_WLine) aNewWLine =
4171 new IntPatch_WLine(aLineOn2S, Standard_False);
4172 theNewLines.Append(aNewWLine);
4177 return Standard_True;
4180 // ------------------------------------------------------------------------------------------------
4181 // static function: ParameterOutOfBoundary
4182 // purpose: Computes a new parameter for given curve. The corresponding 2d points
4183 // does not lay on any boundary of given faces
4184 // ------------------------------------------------------------------------------------------------
4185 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
4186 const Handle(Geom_Curve)& theCurve,
4187 const TopoDS_Face& theFace1,
4188 const TopoDS_Face& theFace2,
4189 const Standard_Real theOtherParameter,
4190 const Standard_Boolean bIncreasePar,
4191 Standard_Real& theNewParameter,
4192 const Handle(IntTools_Context)& aContext)
4194 Standard_Boolean bIsComputed = Standard_False;
4195 theNewParameter = theParameter;
4197 Standard_Real acurpar = theParameter;
4198 TopAbs_State aState = TopAbs_ON;
4199 Standard_Integer iter = 0;
4200 Standard_Real asumtol = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4201 Standard_Real adelta = asumtol * 0.1;
4202 adelta = (adelta < Precision::Confusion()) ? Precision::Confusion() : adelta;
4203 Handle(Geom_Surface) aSurf1 = BRep_Tool::Surface(theFace1);
4204 Handle(Geom_Surface) aSurf2 = BRep_Tool::Surface(theFace2);
4206 Standard_Real u1, u2, v1, v2;
4208 GeomAPI_ProjectPointOnSurf aPrj1;
4209 aSurf1->Bounds(u1, u2, v1, v2);
4210 aPrj1.Init(aSurf1, u1, u2, v1, v2);
4212 GeomAPI_ProjectPointOnSurf aPrj2;
4213 aSurf2->Bounds(u1, u2, v1, v2);
4214 aPrj2.Init(aSurf2, u1, u2, v1, v2);
4216 while(aState == TopAbs_ON) {
4221 gp_Pnt aPCurrent = theCurve->Value(acurpar);
4222 aPrj1.Perform(aPCurrent);
4223 Standard_Real U=0., V=0.;
4225 if(aPrj1.IsDone()) {
4226 aPrj1.LowerDistanceParameters(U, V);
4227 aState = aContext->StatePointFace(theFace1, gp_Pnt2d(U, V));
4230 if(aState != TopAbs_ON) {
4231 aPrj2.Perform(aPCurrent);
4233 if(aPrj2.IsDone()) {
4234 aPrj2.LowerDistanceParameters(U, V);
4235 aState = aContext->StatePointFace(theFace2, gp_Pnt2d(U, V));
4246 theNewParameter = acurpar;
4247 bIsComputed = Standard_True;
4250 if(acurpar >= theOtherParameter)
4251 theNewParameter = theOtherParameter;
4254 if(acurpar <= theOtherParameter)
4255 theNewParameter = theOtherParameter;
4261 //=======================================================================
4262 //function : IsCurveValid
4264 //=======================================================================
4265 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve)
4267 if(thePCurve.IsNull())
4268 return Standard_False;
4270 Standard_Real tolint = 1.e-10;
4271 Geom2dAdaptor_Curve PCA;
4272 IntRes2d_Domain PCD;
4273 Geom2dInt_GInter PCI;
4275 Standard_Real pf = 0., pl = 0.;
4276 gp_Pnt2d pntf, pntl;
4278 if(!thePCurve->IsClosed() && !thePCurve->IsPeriodic()) {
4279 pf = thePCurve->FirstParameter();
4280 pl = thePCurve->LastParameter();
4281 pntf = thePCurve->Value(pf);
4282 pntl = thePCurve->Value(pl);
4283 PCA.Load(thePCurve);
4284 if(!PCA.IsPeriodic()) {
4285 if(PCA.FirstParameter() > pf) pf = PCA.FirstParameter();
4286 if(PCA.LastParameter() < pl) pl = PCA.LastParameter();
4288 PCD.SetValues(pntf,pf,tolint,pntl,pl,tolint);
4289 PCI.Perform(PCA,PCD,tolint,tolint);
4291 if(PCI.NbPoints() > 0) {
4292 return Standard_False;
4296 return Standard_True;
4299 //=======================================================================
4300 //static function : ApproxWithPCurves
4301 //purpose : for bug 20964 only
4302 //=======================================================================
4303 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
4304 const gp_Sphere& theSph)
4306 Standard_Boolean bRes = Standard_True;
4307 Standard_Real R1 = theCyl.Radius(), R2 = theSph.Radius();
4310 Standard_Real aD2, aRc2, aEps;
4316 const gp_Ax3& aAx3Sph=theSph.Position();
4317 const gp_Pnt& aLocSph=aAx3Sph.Location();
4318 const gp_Dir& aDirSph=aAx3Sph.Direction();
4320 const gp_Ax1& aAx1Cyl=theCyl.Axis();
4321 gp_Lin aLinCyl(aAx1Cyl);
4323 aApexSph.SetXYZ(aLocSph.XYZ()+R2*aDirSph.XYZ());
4324 aD2=aLinCyl.SquareDistance(aApexSph);
4325 if (fabs(aD2-aRc2)<aEps) {
4329 aApexSph.SetXYZ(aLocSph.XYZ()-R2*aDirSph.XYZ());
4330 aD2=aLinCyl.SquareDistance(aApexSph);
4331 if (fabs(aD2-aRc2)<aEps) {
4340 gp_Lin anCylAx(theCyl.Axis());
4342 Standard_Real aDist = anCylAx.Distance(theSph.Location());
4343 Standard_Real aDRel = Abs(aDist - R1)/R2;
4345 if(aDRel > .2) return bRes;
4347 Standard_Real par = ElCLib::Parameter(anCylAx, theSph.Location());
4348 gp_Pnt aP = ElCLib::Value(par, anCylAx);
4349 gp_Vec aV(aP, theSph.Location());
4351 Standard_Real dd = aV.Dot(theSph.Position().XDirection());
4353 if(aDist < R1 && dd > 0.) return Standard_False;
4354 if(aDist > R1 && dd < 0.) return Standard_False;
4359 //=======================================================================
4360 //function : PerformPlanes
4362 //=======================================================================
4363 void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
4364 const Handle(GeomAdaptor_HSurface)& theS2,
4365 const Standard_Real TolAng,
4366 const Standard_Real TolTang,
4367 const Standard_Boolean theApprox1,
4368 const Standard_Boolean theApprox2,
4369 IntTools_SequenceOfCurves& theSeqOfCurve,
4370 Standard_Boolean& theTangentFaces)
4373 gp_Pln aPln1 = theS1->Surface().Plane();
4374 gp_Pln aPln2 = theS2->Surface().Plane();
4376 IntAna_QuadQuadGeo aPlnInter(aPln1, aPln2, TolAng, TolTang);
4378 if(!aPlnInter.IsDone()) {
4379 theTangentFaces = Standard_False;
4383 IntAna_ResultType aResType = aPlnInter.TypeInter();
4385 if(aResType == IntAna_Same) {
4386 theTangentFaces = Standard_True;
4390 theTangentFaces = Standard_False;
4392 if(aResType == IntAna_Empty) {
4396 gp_Lin aLin = aPlnInter.Line(1);
4398 ProjLib_Plane aProj;
4401 aProj.Project(aLin);
4402 gp_Lin2d aLin2d1 = aProj.Line();
4405 aProj.Project(aLin);
4406 gp_Lin2d aLin2d2 = aProj.Line();
4408 //classify line2d1 relatively first plane
4409 Standard_Real P11, P12;
4410 Standard_Boolean IsCrossed = ClassifyLin2d(theS1, aLin2d1, TolTang, P11, P12);
4411 if(!IsCrossed) return;
4412 //classify line2d2 relatively second plane
4413 Standard_Real P21, P22;
4414 IsCrossed = ClassifyLin2d(theS2, aLin2d2, TolTang, P21, P22);
4415 if(!IsCrossed) return;
4417 //Analysis of parametric intervals: must have common part
4419 if(P21 >= P12) return;
4420 if(P22 <= P11) return;
4422 Standard_Real pmin, pmax;
4423 pmin = Max(P11, P21);
4424 pmax = Min(P12, P22);
4426 if(pmax - pmin <= TolTang) return;
4428 Handle(Geom_Line) aGLin = new Geom_Line(aLin);
4430 IntTools_Curve aCurve;
4431 Handle(Geom_TrimmedCurve) aGTLin = new Geom_TrimmedCurve(aGLin, pmin, pmax);
4433 aCurve.SetCurve(aGTLin);
4436 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d1);
4437 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4440 Handle(Geom2d_Curve) H1;
4441 aCurve.SetFirstCurve2d(H1);
4444 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d2);
4445 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4448 Handle(Geom2d_Curve) H1;
4449 aCurve.SetFirstCurve2d(H1);
4452 theSeqOfCurve.Append(aCurve);
4456 //=======================================================================
4457 //function : ClassifyLin2d
4459 //=======================================================================
4460 static inline Standard_Boolean INTER(const Standard_Real d1,
4461 const Standard_Real d2,
4462 const Standard_Real tol)
4464 return (d1 > tol && d2 < -tol) ||
4465 (d1 < -tol && d2 > tol) ||
4466 ((d1 <= tol && d1 >= -tol) && (d2 > tol || d2 < -tol)) ||
4467 ((d2 <= tol && d2 >= -tol) && (d1 > tol || d1 < -tol));
4469 static inline Standard_Boolean COINC(const Standard_Real d1,
4470 const Standard_Real d2,
4471 const Standard_Real tol)
4473 return (d1 <= tol && d1 >= -tol) && (d2 <= tol && d2 >= -tol);
4475 Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
4476 const gp_Lin2d& theLin2d,
4477 const Standard_Real theTol,
4478 Standard_Real& theP1,
4479 Standard_Real& theP2)
4482 Standard_Real xmin, xmax, ymin, ymax, d1, d2, A, B, C;
4483 Standard_Real par[2];
4484 Standard_Integer nbi = 0;
4486 xmin = theS->Surface().FirstUParameter();
4487 xmax = theS->Surface().LastUParameter();
4488 ymin = theS->Surface().FirstVParameter();
4489 ymax = theS->Surface().LastVParameter();
4491 theLin2d.Coefficients(A, B, C);
4493 //xmin, ymin <-> xmin, ymax
4494 d1 = A*xmin + B*ymin + C;
4495 d2 = A*xmin + B*ymax + C;
4497 if(INTER(d1, d2, theTol)) {
4498 //Intersection with boundary
4499 Standard_Real y = -(C + A*xmin)/B;
4500 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, y));
4503 else if (COINC(d1, d2, theTol)) {
4504 //Coincidence with boundary
4505 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4506 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4512 if(fabs(par[0]-par[1]) > theTol) {
4513 theP1 = Min(par[0], par[1]);
4514 theP2 = Max(par[0], par[1]);
4515 return Standard_True;
4517 else return Standard_False;
4521 //xmin, ymax <-> xmax, ymax
4523 d2 = A*xmax + B*ymax + C;
4525 if(d1 > theTol || d1 < -theTol) {//to avoid checking of
4526 //coincidence with the same point
4527 if(INTER(d1, d2, theTol)) {
4528 Standard_Real x = -(C + B*ymax)/A;
4529 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymax));
4532 else if (COINC(d1, d2, theTol)) {
4533 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4534 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4541 if(fabs(par[0]-par[1]) > theTol) {
4542 theP1 = Min(par[0], par[1]);
4543 theP2 = Max(par[0], par[1]);
4544 return Standard_True;
4546 else return Standard_False;
4550 //xmax, ymax <-> xmax, ymin
4552 d2 = A*xmax + B*ymin + C;
4554 if(d1 > theTol || d1 < -theTol) {
4555 if(INTER(d1, d2, theTol)) {
4556 Standard_Real y = -(C + A*xmax)/B;
4557 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, y));
4560 else if (COINC(d1, d2, theTol)) {
4561 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4562 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4568 if(fabs(par[0]-par[1]) > theTol) {
4569 theP1 = Min(par[0], par[1]);
4570 theP2 = Max(par[0], par[1]);
4571 return Standard_True;
4573 else return Standard_False;
4576 //xmax, ymin <-> xmin, ymin
4578 d2 = A*xmin + B*ymin + C;
4580 if(d1 > theTol || d1 < -theTol) {
4581 if(INTER(d1, d2, theTol)) {
4582 Standard_Real x = -(C + B*ymin)/A;
4583 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymin));
4586 else if (COINC(d1, d2, theTol)) {
4587 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4588 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4594 if(fabs(par[0]-par[1]) > theTol) {
4595 theP1 = Min(par[0], par[1]);
4596 theP2 = Max(par[0], par[1]);
4597 return Standard_True;
4599 else return Standard_False;
4602 return Standard_False;
4606 //=======================================================================
4607 //function : ApproxParameters
4609 //=======================================================================
4610 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
4611 const Handle(GeomAdaptor_HSurface)& aHS2,
4612 Standard_Integer& iDegMin,
4613 Standard_Integer& iDegMax,
4614 Standard_Integer& iNbIter)
4617 GeomAbs_SurfaceType aTS1, aTS2;
4624 aTS1=aHS1->Surface().GetType();
4625 aTS2=aHS2->Surface().GetType();
4628 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4629 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4630 Standard_Real aRC, aRT, dR, aPC;
4631 gp_Cylinder aCylinder;
4634 aPC=Precision::Confusion();
4636 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4637 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4639 aRC=aCylinder.Radius();
4640 aRT=aTorus.MinorRadius();
4650 if (aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Cylinder) {
4654 //=======================================================================
4655 //function : Tolerances
4657 //=======================================================================
4658 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
4659 const Handle(GeomAdaptor_HSurface)& aHS2,
4660 Standard_Real& aTolTang)
4662 GeomAbs_SurfaceType aTS1, aTS2;
4664 aTS1=aHS1->Surface().GetType();
4665 aTS2=aHS2->Surface().GetType();
4668 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4669 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4670 Standard_Real aRC, aRT, dR, aPC;
4671 gp_Cylinder aCylinder;
4674 aPC=Precision::Confusion();
4676 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4677 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4679 aRC=aCylinder.Radius();
4680 aRT=aTorus.MinorRadius();
4687 aTolTang=0.1*aTolTang;
4691 //=======================================================================
4692 //function : SortTypes
4694 //=======================================================================
4695 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
4696 const GeomAbs_SurfaceType aType2)
4698 Standard_Boolean bRet;
4699 Standard_Integer aI1, aI2;
4701 bRet=Standard_False;
4703 aI1=IndexType(aType1);
4704 aI2=IndexType(aType2);
4710 //=======================================================================
4711 //function : IndexType
4713 //=======================================================================
4714 Standard_Integer IndexType(const GeomAbs_SurfaceType aType)
4716 Standard_Integer aIndex;
4720 if (aType==GeomAbs_Plane) {
4723 else if (aType==GeomAbs_Cylinder) {
4726 else if (aType==GeomAbs_Cone) {
4729 else if (aType==GeomAbs_Sphere) {
4732 else if (aType==GeomAbs_Torus) {
4735 else if (aType==GeomAbs_BezierSurface) {
4738 else if (aType==GeomAbs_BSplineSurface) {
4741 else if (aType==GeomAbs_SurfaceOfRevolution) {
4744 else if (aType==GeomAbs_SurfaceOfExtrusion) {
4747 else if (aType==GeomAbs_OffsetSurface) {
4750 else if (aType==GeomAbs_OtherSurface) {
4755 #ifdef OCCT_DEBUG_DUMPWLINE
4756 //=======================================================================
4757 //function : DumpWLine
4759 //=======================================================================
4760 void DumpWLine(const Handle(IntPatch_WLine)& aWLine)
4762 Standard_Integer i, aNbPnts;
4763 Standard_Real aX, aY, aZ, aU1, aV1, aU2, aV2;
4765 printf(" *WLine\n");
4766 aNbPnts=aWLine->NbPnts();
4767 for (i=1; i<=aNbPnts; ++i) {
4768 const IntSurf_PntOn2S aPntOn2S=aWLine->Point(i);
4769 const gp_Pnt& aP3D=aPntOn2S.Value();
4770 aP3D.Coord(aX, aY, aZ);
4771 aPntOn2S.Parameters(aU1, aV1, aU2, aV2);
4773 printf("point p_%d %lf %lf %lf\n", i, aX, aY, aZ);
4774 //printf("point p_%d %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf\n",
4775 // i, aX, aY, aZ, aU1, aV1, aU2, aV2);
4779 //=======================================================================
4780 //function : RefineVector
4782 //=======================================================================
4783 void RefineVector(gp_Vec2d& aV2D)
4785 Standard_Integer k,m;
4786 Standard_Real aC[2], aEps, aR1, aR2, aNum;
4792 aV2D.Coord(aC[0], aC[1]);
4794 for (k=0; k<2; ++k) {
4797 if (aNum>aR1 && aNum<aR2) {
4808 aV2D.SetCoord(aC[0], aC[1]);
4810 //=======================================================================
4811 // Function : FindMaxDistance
4813 //=======================================================================
4814 Standard_Real FindMaxDistance(const Handle(Geom_Curve)& theCurve,
4815 const Standard_Real theFirst,
4816 const Standard_Real theLast,
4817 const TopoDS_Face& theFace,
4818 const Handle(IntTools_Context)& theContext)
4820 Standard_Integer aNbS;
4821 Standard_Real aT1, aT2, aDt, aD, aDMax, anEps;
4824 aDt = (theLast - theFirst) / aNbS;
4826 anEps = 1.e-4 * aDt;
4828 GeomAPI_ProjectPointOnSurf& aProjPS = theContext->ProjPS(theFace);
4834 if (aT2 > theLast) {
4838 aD = FindMaxDistance(theCurve, aT1, aT2, aProjPS, anEps);
4846 //=======================================================================
4847 // Function : FindMaxDistance
4849 //=======================================================================
4850 Standard_Real FindMaxDistance(const Handle(Geom_Curve)& theC,
4851 const Standard_Real theFirst,
4852 const Standard_Real theLast,
4853 GeomAPI_ProjectPointOnSurf& theProjPS,
4854 const Standard_Real theEps)
4856 Standard_Real aA, aB, aCf, aX, aX1, aX2, aF1, aF2, aF;
4858 aCf = 0.61803398874989484820458683436564;//(sqrt(5.)-1)/2.;
4862 aX1 = aB - aCf * (aB - aA);
4863 aF1 = MaxDistance(theC, aX1, theProjPS);
4864 aX2 = aA + aCf * (aB - aA);
4865 aF2 = MaxDistance(theC, aX2, theProjPS);
4868 if ((aB - aA) < theEps) {
4876 aX1 = aB - aCf * (aB - aA);
4877 aF1 = MaxDistance(theC, aX1, theProjPS);
4883 aX2 = aA + aCf * (aB - aA);
4884 aF2 = MaxDistance(theC, aX2, theProjPS);
4888 aX = 0.5 * (aA + aB);
4889 aF = MaxDistance(theC, aX, theProjPS);
4901 //=======================================================================
4902 // Function : MaxDistance
4904 //=======================================================================
4905 Standard_Real MaxDistance(const Handle(Geom_Curve)& theC,
4906 const Standard_Real aT,
4907 GeomAPI_ProjectPointOnSurf& theProjPS)
4913 theProjPS.Perform(aP);
4914 aD = theProjPS.NbPoints() ? theProjPS.LowerDistance() : 0.;
4919 //=======================================================================
4920 //function : CheckPCurve
4921 //purpose : Checks if points of the pcurve are out of the face bounds.
4922 //=======================================================================
4923 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
4924 const TopoDS_Face& aFace)
4926 const Standard_Integer NPoints = 23;
4928 Standard_Real umin,umax,vmin,vmax;
4930 BRepTools::UVBounds(aFace, umin, umax, vmin, vmax);
4931 Standard_Real tolU = Max ((umax-umin)*0.01, Precision::Confusion());
4932 Standard_Real tolV = Max ((vmax-vmin)*0.01, Precision::Confusion());
4933 Standard_Real fp = aPC->FirstParameter();
4934 Standard_Real lp = aPC->LastParameter();
4937 // adjust domain for periodic surfaces
4938 TopLoc_Location aLoc;
4939 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc);
4940 if (aSurf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
4941 aSurf = (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf))->BasisSurface();
4943 gp_Pnt2d pnt = aPC->Value((fp+lp)/2);
4947 if (aSurf->IsUPeriodic()) {
4948 Standard_Real aPer = aSurf->UPeriod();
4949 Standard_Integer nshift = (Standard_Integer) ((u-umin)/aPer);
4950 if (u < umin+aPer*nshift) nshift--;
4951 umin += aPer*nshift;
4952 umax += aPer*nshift;
4954 if (aSurf->IsVPeriodic()) {
4955 Standard_Real aPer = aSurf->VPeriod();
4956 Standard_Integer nshift = (Standard_Integer) ((v-vmin)/aPer);
4957 if (v < vmin+aPer*nshift) nshift--;
4958 vmin += aPer*nshift;
4959 vmax += aPer*nshift;
4962 //--------------------------------------------------------
4963 Standard_Boolean bRet;
4964 Standard_Integer j, aNbIntervals;
4965 Standard_Real aT, dT;
4968 Geom2dAdaptor_Curve aGAC(aPC);
4969 aNbIntervals=aGAC.NbIntervals(GeomAbs_CN);
4971 TColStd_Array1OfReal aTI(1, aNbIntervals+1);
4972 aGAC.Intervals(aTI,GeomAbs_CN);
4974 bRet=Standard_False;
4976 aT=aGAC.FirstParameter();
4977 for (j=1; j<=aNbIntervals; ++j) {
4978 dT=(aTI(j+1)-aTI(j))/NPoints;
4980 for (i=1; i<NPoints; i++) {
4984 if (umin-u > tolU || u-umax > tolU ||
4985 vmin-v > tolV || v-vmax > tolV) {