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);
307 void CorrectPlaneBoundaries(Standard_Real& aUmin,
308 Standard_Real& aUmax,
309 Standard_Real& aVmin,
310 Standard_Real& aVmax);
312 //=======================================================================
315 //=======================================================================
316 IntTools_FaceFace::IntTools_FaceFace()
318 myIsDone=Standard_False;
319 myTangentFaces=Standard_False;
321 myHS1 = new GeomAdaptor_HSurface ();
322 myHS2 = new GeomAdaptor_HSurface ();
325 SetParameters(Standard_True, Standard_True, Standard_True, 1.e-07);
328 //=======================================================================
329 //function : SetContext
331 //=======================================================================
332 void IntTools_FaceFace::SetContext(const Handle(IntTools_Context)& aContext)
336 //=======================================================================
339 //=======================================================================
340 const Handle(IntTools_Context)& IntTools_FaceFace::Context()const
344 //=======================================================================
347 //=======================================================================
348 const TopoDS_Face& IntTools_FaceFace::Face1() const
352 //=======================================================================
355 //=======================================================================
356 const TopoDS_Face& IntTools_FaceFace::Face2() const
360 //=======================================================================
361 //function : TangentFaces
363 //=======================================================================
364 Standard_Boolean IntTools_FaceFace::TangentFaces() const
366 return myTangentFaces;
368 //=======================================================================
371 //=======================================================================
372 const IntTools_SequenceOfPntOn2Faces& IntTools_FaceFace::Points() const
376 //=======================================================================
379 //=======================================================================
380 Standard_Boolean IntTools_FaceFace::IsDone() const
384 //=======================================================================
385 //function : TolReached3d
387 //=======================================================================
388 Standard_Real IntTools_FaceFace::TolReached3d() const
390 return myTolReached3d;
392 //=======================================================================
394 //purpose : return lines of intersection
395 //=======================================================================
396 const IntTools_SequenceOfCurves& IntTools_FaceFace::Lines() const
398 StdFail_NotDone_Raise_if
400 "IntTools_FaceFace::Lines() => myIntersector NOT DONE");
403 //=======================================================================
404 //function : TolReached2d
406 //=======================================================================
407 Standard_Real IntTools_FaceFace::TolReached2d() const
409 return myTolReached2d;
411 // =======================================================================
412 // function: SetParameters
414 // =======================================================================
415 void IntTools_FaceFace::SetParameters(const Standard_Boolean ToApproxC3d,
416 const Standard_Boolean ToApproxC2dOnS1,
417 const Standard_Boolean ToApproxC2dOnS2,
418 const Standard_Real ApproximationTolerance)
420 myApprox = ToApproxC3d;
421 myApprox1 = ToApproxC2dOnS1;
422 myApprox2 = ToApproxC2dOnS2;
423 myTolApprox = ApproximationTolerance;
425 //=======================================================================
428 //=======================================================================
429 void IntTools_FaceFace::SetList(IntSurf_ListOfPntOn2S& aListOfPnts)
431 myListOfPnts = aListOfPnts;
435 static Standard_Boolean isTreatAnalityc(const TopoDS_Face& theF1,
436 const TopoDS_Face& theF2)
438 const Standard_Real Tolang = 1.e-8;
439 const Standard_Real aTolF1=BRep_Tool::Tolerance(theF1);
440 const Standard_Real aTolF2=BRep_Tool::Tolerance(theF2);
441 const Standard_Real aTolSum = aTolF1 + aTolF2;
442 Standard_Real aHigh = 0.0;
444 const BRepAdaptor_Surface aBAS1(theF1), aBAS2(theF2);
445 const GeomAbs_SurfaceType aType1=aBAS1.GetType();
446 const GeomAbs_SurfaceType aType2=aBAS2.GetType();
450 if(aType1 == GeomAbs_Plane)
454 else if(aType2 == GeomAbs_Plane)
460 return Standard_True;
463 if(aType1 == GeomAbs_Cylinder)
465 aS2=aBAS1.Cylinder();
466 const Standard_Real VMin = aBAS1.FirstVParameter();
467 const Standard_Real VMax = aBAS1.LastVParameter();
469 if( Precision::IsNegativeInfinite(VMin) ||
470 Precision::IsPositiveInfinite(VMax))
471 return Standard_True;
475 else if(aType2 == GeomAbs_Cylinder)
477 aS2=aBAS2.Cylinder();
479 const Standard_Real VMin = aBAS2.FirstVParameter();
480 const Standard_Real VMax = aBAS2.LastVParameter();
482 if( Precision::IsNegativeInfinite(VMin) ||
483 Precision::IsPositiveInfinite(VMax))
484 return Standard_True;
490 return Standard_True;
493 IntAna_QuadQuadGeo inter;
494 inter.Perform(aS1,aS2,Tolang,aTolSum, aHigh);
495 if(inter.TypeInter() == IntAna_Ellipse)
497 const gp_Elips anEl = inter.Ellipse(1);
498 const Standard_Real aMajorR = anEl.MajorRadius();
499 const Standard_Real aMinorR = anEl.MinorRadius();
501 return (aMajorR < 100000.0 * aMinorR);
505 return inter.IsDone();
508 //=======================================================================
510 //purpose : intersect surfaces of the faces
511 //=======================================================================
512 void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
513 const TopoDS_Face& aF2)
515 Standard_Boolean RestrictLine = Standard_False, hasCone = Standard_False;
517 if (myContext.IsNull()) {
518 myContext=new IntTools_Context;
521 mySeqOfCurve.Clear();
524 myIsDone = Standard_False;
530 const BRepAdaptor_Surface aBAS1(myFace1, Standard_False);
531 const BRepAdaptor_Surface aBAS2(myFace2, Standard_False);
532 GeomAbs_SurfaceType aType1=aBAS1.GetType();
533 GeomAbs_SurfaceType aType2=aBAS2.GetType();
535 const Standard_Boolean bReverse=SortTypes(aType1, aType2);
540 aType1=aBAS2.GetType();
541 aType2=aBAS1.GetType();
543 if (myListOfPnts.Extent())
545 Standard_Real aU1,aV1,aU2,aV2;
546 IntSurf_ListIteratorOfListOfPntOn2S aItP2S;
548 aItP2S.Initialize(myListOfPnts);
549 for (; aItP2S.More(); aItP2S.Next())
551 IntSurf_PntOn2S& aP2S=aItP2S.Value();
552 aP2S.Parameters(aU1,aV1,aU2,aV2);
553 aP2S.SetValue(aU2,aV2,aU1,aV1);
557 Standard_Boolean anAproxTmp = myApprox1;
558 myApprox1 = myApprox2;
559 myApprox2 = anAproxTmp;
563 const Handle(Geom_Surface) S1=BRep_Tool::Surface(myFace1);
564 const Handle(Geom_Surface) S2=BRep_Tool::Surface(myFace2);
566 const Standard_Real aTolF1=BRep_Tool::Tolerance(myFace1);
567 const Standard_Real aTolF2=BRep_Tool::Tolerance(myFace2);
569 Standard_Real TolArc = aTolF1 + aTolF2;
570 Standard_Real TolTang = TolArc;
572 const Standard_Boolean isFace1Quad = (aType1 == GeomAbs_Cylinder ||
573 aType1 == GeomAbs_Cone ||
574 aType1 == GeomAbs_Torus);
576 const Standard_Boolean isFace2Quad = (aType2 == GeomAbs_Cylinder ||
577 aType2 == GeomAbs_Cone ||
578 aType2 == GeomAbs_Torus);
580 if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
581 Standard_Real umin, umax, vmin, vmax;
583 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
584 CorrectPlaneBoundaries(umin, umax, vmin, vmax);
585 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
587 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
588 CorrectPlaneBoundaries(umin, umax, vmin, vmax);
589 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
591 Standard_Real TolAng = 1.e-8;
593 PerformPlanes(myHS1, myHS2, TolAng, TolTang, myApprox1, myApprox2,
594 mySeqOfCurve, myTangentFaces);
596 myIsDone = Standard_True;
598 if(!myTangentFaces) {
599 const Standard_Integer NbLinPP = mySeqOfCurve.Length();
601 Standard_Real aTolFMax;
602 myTolReached3d = 1.e-7;
603 aTolFMax=Max(aTolF1, aTolF2);
604 if (aTolFMax>myTolReached3d) {
605 myTolReached3d=aTolFMax;
608 myTolReached2d = myTolReached3d;
611 Handle(Geom2d_Curve) aC2D1, aC2D2;
612 const Standard_Integer aNbLin = mySeqOfCurve.Length();
613 for (Standard_Integer i = 1; i <= aNbLin; ++i) {
614 IntTools_Curve& aIC=mySeqOfCurve(i);
615 aC2D1=aIC.FirstCurve2d();
616 aC2D2=aIC.SecondCurve2d();
617 aIC.SetFirstCurve2d(aC2D2);
618 aIC.SetSecondCurve2d(aC2D1);
624 }//if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
626 if ((aType1==GeomAbs_Plane) && isFace2Quad)
628 Standard_Real umin, umax, vmin, vmax;
630 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
631 CorrectPlaneBoundaries(umin, umax, vmin, vmax);
632 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
634 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
635 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
636 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
638 if( aType2==GeomAbs_Cone ) {
640 hasCone = Standard_True;
643 else if ((aType2==GeomAbs_Plane) && isFace1Quad)
645 Standard_Real umin, umax, vmin, vmax;
647 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
648 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
649 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
651 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
652 CorrectPlaneBoundaries(umin, umax, vmin, vmax);
653 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
655 if( aType1==GeomAbs_Cone ) {
657 hasCone = Standard_True;
662 Standard_Real umin, umax, vmin, vmax;
663 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
664 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
665 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
666 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
667 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
668 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
671 const Handle(IntTools_TopolTool) dom1 = new IntTools_TopolTool(myHS1);
672 const Handle(IntTools_TopolTool) dom2 = new IntTools_TopolTool(myHS2);
674 myLConstruct.Load(dom1, dom2, myHS1, myHS2);
677 Tolerances(myHS1, myHS2, TolTang);
680 const Standard_Real UVMaxStep = 0.001;
681 const Standard_Real Deflection = (hasCone) ? 0.085 : 0.1;
682 myIntersector.SetTolerances(TolArc, TolTang, UVMaxStep, Deflection);
685 if((myHS1->IsUClosed() && !myHS1->IsUPeriodic()) ||
686 (myHS1->IsVClosed() && !myHS1->IsVPeriodic()) ||
687 (myHS2->IsUClosed() && !myHS2->IsUPeriodic()) ||
688 (myHS2->IsVClosed() && !myHS2->IsVPeriodic()))
690 RestrictLine = Standard_True;
693 if((aType1 != GeomAbs_BSplineSurface) &&
694 (aType1 != GeomAbs_BezierSurface) &&
695 (aType1 != GeomAbs_OtherSurface) &&
696 (aType2 != GeomAbs_BSplineSurface) &&
697 (aType2 != GeomAbs_BezierSurface) &&
698 (aType2 != GeomAbs_OtherSurface))
700 RestrictLine = Standard_True;
702 if ((aType1 == GeomAbs_Torus) ||
703 (aType2 == GeomAbs_Torus))
705 myListOfPnts.Clear();
712 TopExp_Explorer aExp;
713 for(Standard_Integer i = 0; (!RestrictLine) && (i < 2); i++)
715 const TopoDS_Face& aF=(!i) ? myFace1 : myFace2;
716 aExp.Init(aF, TopAbs_EDGE);
717 for(; aExp.More(); aExp.Next())
719 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
721 if(BRep_Tool::Degenerated(aE))
723 RestrictLine = Standard_True;
730 const Standard_Boolean isGeomInt = isTreatAnalityc(aF1, aF2);
731 myIntersector.Perform(myHS1, dom1, myHS2, dom2, TolArc, TolTang,
732 myListOfPnts, RestrictLine, isGeomInt);
734 myIsDone = myIntersector.IsDone();
738 myTangentFaces=myIntersector.TangentFaces();
739 if (myTangentFaces) {
744 myListOfPnts.Clear(); // to use LineConstructor
747 const Standard_Integer aNbLin = myIntersector.NbLines();
748 for (Standard_Integer i=1; i <= aNbLin; ++i) {
749 MakeCurve(i, dom1, dom2);
752 ComputeTolReached3d();
755 Handle(Geom2d_Curve) aC2D1, aC2D2;
757 const Standard_Integer aNbLin=mySeqOfCurve.Length();
758 for (Standard_Integer i=1; i<=aNbLin; ++i)
760 IntTools_Curve& aIC=mySeqOfCurve(i);
761 aC2D1=aIC.FirstCurve2d();
762 aC2D2=aIC.SecondCurve2d();
763 aIC.SetFirstCurve2d(aC2D2);
764 aIC.SetSecondCurve2d(aC2D1);
769 Standard_Real U1,V1,U2,V2;
770 IntTools_PntOnFace aPntOnF1, aPntOnF2;
771 IntTools_PntOn2Faces aPntOn2Faces;
773 const Standard_Integer aNbPnts = myIntersector.NbPnts();
774 for (Standard_Integer i=1; i <= aNbPnts; ++i)
776 const IntSurf_PntOn2S& aISPnt=myIntersector.Point(i).PntOn2S();
777 const gp_Pnt& aPnt=aISPnt.Value();
778 aISPnt.Parameters(U1,V1,U2,V2);
779 aPntOnF1.Init(myFace1, aPnt, U1, V1);
780 aPntOnF2.Init(myFace2, aPnt, U2, V2);
784 aPntOn2Faces.SetP1(aPntOnF1);
785 aPntOn2Faces.SetP2(aPntOnF2);
789 aPntOn2Faces.SetP2(aPntOnF1);
790 aPntOn2Faces.SetP1(aPntOnF2);
793 myPnts.Append(aPntOn2Faces);
798 //=======================================================================
799 //function : ComputeTolerance
801 //=======================================================================
802 Standard_Real IntTools_FaceFace::ComputeTolerance()
804 Standard_Integer i, j, aNbLin;
805 Standard_Real aFirst, aLast, aD, aDMax, aT;
806 Handle(Geom_Surface) aS1, aS2;
809 aNbLin = mySeqOfCurve.Length();
811 aS1 = myHS1->ChangeSurface().Surface();
812 aS2 = myHS2->ChangeSurface().Surface();
814 for (i = 1; i <= aNbLin; ++i) {
815 const IntTools_Curve& aIC = mySeqOfCurve(i);
816 const Handle(Geom_Curve)& aC3D = aIC.Curve();
821 aFirst = aC3D->FirstParameter();
822 aLast = aC3D->LastParameter();
824 const Handle(Geom2d_Curve)& aC2D1 = aIC.FirstCurve2d();
825 const Handle(Geom2d_Curve)& aC2D2 = aIC.SecondCurve2d();
827 for (j = 0; j < 2; ++j) {
828 const Handle(Geom2d_Curve)& aC2D = !j ? aC2D1 : aC2D2;
829 const Handle(Geom_Surface)& aS = !j ? aS1 : aS2;
831 if (!aC2D.IsNull()) {
832 if (IntTools_Tools::ComputeTolerance
833 (aC3D, aC2D, aS, aFirst, aLast, aD, aT)) {
840 const TopoDS_Face& aF = !i ? myFace1 : myFace2;
841 aD = FindMaxDistance(aC3D, aFirst, aLast, aF, myContext);
851 //=======================================================================
852 //function :ComputeTolReached3d
854 //=======================================================================
855 void IntTools_FaceFace::ComputeTolReached3d()
857 Standard_Integer aNbLin, i;
858 GeomAbs_SurfaceType aType1, aType2;
860 aNbLin=myIntersector.NbLines();
865 aType1=myHS1->Surface().GetType();
866 aType2=myHS2->Surface().GetType();
868 if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
870 Handle(IntPatch_Line) aIL1, aIL2;
871 IntPatch_IType aTL1, aTL2;
873 aIL1=myIntersector.Line(1);
874 aIL2=myIntersector.Line(2);
875 aTL1=aIL1->ArcType();
876 aTL2=aIL2->ArcType();
877 if (aTL1==IntPatch_Lin && aTL2==IntPatch_Lin) {
878 Standard_Real aD, aDTresh, dTol;
884 aL1=Handle(IntPatch_GLine)::DownCast(aIL1)->Line();
885 aL2=Handle(IntPatch_GLine)::DownCast(aIL2)->Line();
886 aD=aL1.Distance(aL2);
889 myTolReached3d=aD+dTol;
895 if (aNbLin) {// Check the distances
898 aDMax = ComputeTolerance();
900 myTolReached3d = aDMax;
903 }// if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
906 else if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
907 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
911 aTolF1 = BRep_Tool::Tolerance(myFace1);
912 aTolF2 = BRep_Tool::Tolerance(myFace2);
913 aTolFMax=Max(aTolF1, aTolF2);
915 if (aTolFMax>aTolTresh) {
916 myTolReached3d=aTolFMax;
918 }//if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
921 else if((aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) ||
922 (aType2 == GeomAbs_Cylinder && aType1 == GeomAbs_Plane)) {
924 const Handle(IntPatch_Line)& aIL1 = myIntersector.Line(1);
925 if(aIL1->ArcType() == IntPatch_Circle) {
926 gp_Circ aCir = Handle(IntPatch_GLine)::DownCast(aIL1)->Circle();
927 gp_XYZ aCirDir = aCir.Axis().Direction().XYZ();
930 if(aType1 == GeomAbs_Plane) {
931 aPln = myHS1->Surface().Plane();
934 aPln = myHS2->Surface().Plane();
936 aPlDir = aPln.Axis().Direction().XYZ();
937 Standard_Real cs = aCirDir*aPlDir;
938 if(cs < 0.) aPlDir.Reverse();
939 Standard_Real eps = 1.e-14;
940 if(!aPlDir.IsEqual(aCirDir, eps)) {
941 Standard_Integer aNbP = 11;
942 Standard_Real dt = 2.*M_PI / (aNbP - 1), t;
943 for(t = 0.; t < 2.*M_PI; t += dt) {
944 Standard_Real d = aPln.Distance(ElCLib::Value(t, aCir));
945 if(myTolReached3d < d) myTolReached3d = d;
947 myTolReached3d *= 1.1;
949 } //aIL1->ArcType() == IntPatch_Circle
951 } // aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane)
952 //End IFV Bug OCC20297
954 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
955 (aType2==GeomAbs_Plane && aType1==GeomAbs_Torus)) {
956 aNbLin=mySeqOfCurve.Length();
961 Standard_Integer aNbP;
962 Standard_Real aT, aT1, aT2, dT, aUT, aVT, aUP, aVP;
963 Standard_Real aDP, aDT, aDmax;
968 const IntTools_Curve& aIC=mySeqOfCurve(1);
969 const Handle(Geom_Curve)& aC3D=aIC.Curve();
970 const Handle(Geom_BSplineCurve)& aBS=
971 Handle(Geom_BSplineCurve)::DownCast(aC3D);
976 aT1=aBS->FirstParameter();
977 aT2=aBS->LastParameter();
979 aPln =(aType1==GeomAbs_Plane) ? myHS1->Plane() : myHS2->Plane();
980 aTorus=(aType1==GeomAbs_Plane) ? myHS2->Torus() : myHS1->Torus();
984 dT=(aT2-aT1)/(aNbP-1);
985 for (i=0; i<aNbP; ++i) {
993 ElSLib::Parameters(aPln, aP, aUP, aVP);
994 aPP=ElSLib::Value(aUP, aVP, aPln);
995 aDP=aP.SquareDistance(aPP);
1000 ElSLib::Parameters(aTorus, aP, aUT, aVT);
1001 aPT=ElSLib::Value(aUT, aVT, aTorus);
1002 aDT=aP.SquareDistance(aPT);
1008 if (aDmax > myTolReached3d*myTolReached3d) {
1009 myTolReached3d=sqrt(aDmax);
1010 myTolReached3d=1.1*myTolReached3d;
1012 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
1014 else if ((aType1==GeomAbs_SurfaceOfRevolution && aType2==GeomAbs_Cylinder) ||
1015 (aType2==GeomAbs_SurfaceOfRevolution && aType1==GeomAbs_Cylinder) ||
1016 (aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ||
1017 (aType2==GeomAbs_Plane && aType1==GeomAbs_Sphere) ||
1018 (aType1==GeomAbs_Plane && aType2==GeomAbs_SurfaceOfExtrusion) ||
1019 (aType2==GeomAbs_Plane && aType1==GeomAbs_SurfaceOfExtrusion) ||
1020 (aType1==GeomAbs_Plane && aType2==GeomAbs_BSplineSurface) ||
1021 (aType2==GeomAbs_Plane && aType1==GeomAbs_BSplineSurface) ||
1024 Standard_Real aDMax;
1026 aDMax = ComputeTolerance();
1027 if (aDMax > myTolReached3d) {
1028 myTolReached3d = aDMax;
1033 //=======================================================================
1034 //function : MakeCurve
1036 //=======================================================================
1037 void IntTools_FaceFace::MakeCurve(const Standard_Integer Index,
1038 const Handle(Adaptor3d_TopolTool)& dom1,
1039 const Handle(Adaptor3d_TopolTool)& dom2)
1041 Standard_Boolean bDone, rejectSurface, reApprox, bAvoidLineConstructor;
1042 Standard_Boolean ok, bPCurvesOk;
1043 Standard_Integer i, j, aNbParts;
1044 Standard_Real fprm, lprm;
1045 Standard_Real Tolpc;
1046 Handle(IntPatch_Line) L;
1047 IntPatch_IType typl;
1048 Handle(Geom_Curve) newc;
1050 const Standard_Real TOLCHECK =0.0000001;
1051 const Standard_Real TOLANGCHECK=0.1;
1053 rejectSurface = Standard_False;
1054 reApprox = Standard_False;
1056 bPCurvesOk = Standard_True;
1060 Tolpc = myTolApprox;
1061 bAvoidLineConstructor = Standard_False;
1062 L = myIntersector.Line(Index);
1063 typl = L->ArcType();
1065 if(typl==IntPatch_Walking) {
1066 Handle(IntPatch_Line) anewL;
1068 const Handle(IntPatch_WLine)& aWLine=
1069 Handle(IntPatch_WLine)::DownCast(L);
1070 //DumpWLine(aWLine);
1072 anewL = ComputePurgedWLine(aWLine);
1073 if(anewL.IsNull()) {
1078 //const Handle(IntPatch_WLine)& aWLineX = Handle(IntPatch_WLine)::DownCast(L);
1079 //DumpWLine(aWLineX);
1082 if(!myListOfPnts.IsEmpty()) {
1083 bAvoidLineConstructor = Standard_True;
1086 Standard_Integer nbp = aWLine->NbPnts();
1087 const IntSurf_PntOn2S& p1 = aWLine->Point(1);
1088 const IntSurf_PntOn2S& p2 = aWLine->Point(nbp);
1090 const gp_Pnt& P1 = p1.Value();
1091 const gp_Pnt& P2 = p2.Value();
1093 if(P1.SquareDistance(P2) < 1.e-14) {
1094 bAvoidLineConstructor = Standard_False;
1099 if(!bAvoidLineConstructor) {
1100 myLConstruct.Perform(L);
1102 bDone=myLConstruct.IsDone();
1103 aNbParts=myLConstruct.NbParts();
1104 if (!bDone|| !aNbParts) {
1112 //########################################
1113 // Line, Parabola, Hyperbola
1114 //########################################
1116 case IntPatch_Parabola:
1117 case IntPatch_Hyperbola: {
1118 if (typl == IntPatch_Lin) {
1120 new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line());
1123 else if (typl == IntPatch_Parabola) {
1125 new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola());
1128 else if (typl == IntPatch_Hyperbola) {
1130 new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola());
1134 if (typl == IntPatch_Lin) {
1135 TolR3d (myFace1, myFace2, myTolReached3d);
1138 aNbParts=myLConstruct.NbParts();
1139 for (i=1; i<=aNbParts; i++) {
1140 Standard_Boolean bFNIt, bLPIt;
1142 myLConstruct.Part(i, fprm, lprm);
1144 bFNIt=Precision::IsNegativeInfinite(fprm);
1145 bLPIt=Precision::IsPositiveInfinite(lprm);
1147 if (!bFNIt && !bLPIt) {
1149 IntTools_Curve aCurve;
1151 Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm);
1152 aCurve.SetCurve(aCT3D);
1153 if (typl == IntPatch_Parabola) {
1154 Standard_Real aTolF1, aTolF2, aTolBase;
1156 aTolF1 = BRep_Tool::Tolerance(myFace1);
1157 aTolF2 = BRep_Tool::Tolerance(myFace2);
1158 aTolBase=aTolF1+aTolF2;
1159 myTolReached3d=IntTools_Tools::CurveTolerance(aCT3D, aTolBase);
1162 aCurve.SetCurve(new Geom_TrimmedCurve(newc, fprm, lprm));
1164 Handle (Geom2d_Curve) C2d;
1165 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1166 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1167 myTolReached2d=Tolpc;
1170 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1173 Handle(Geom2d_BSplineCurve) H1;
1175 aCurve.SetFirstCurve2d(H1);
1179 Handle (Geom2d_Curve) C2d;
1180 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1181 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1182 myTolReached2d=Tolpc;
1185 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1188 Handle(Geom2d_BSplineCurve) H1;
1190 aCurve.SetSecondCurve2d(H1);
1192 mySeqOfCurve.Append(aCurve);
1193 } //if (!bFNIt && !bLPIt) {
1195 // on regarde si on garde
1197 Standard_Real aTestPrm, dT=100.;
1200 if (bFNIt && !bLPIt) {
1203 else if (!bFNIt && bLPIt) {
1207 // i.e, if (bFNIt && bLPIt)
1208 aTestPrm=IntTools_Tools::IntermediatePoint(-dT, dT);
1211 gp_Pnt ptref(newc->Value(aTestPrm));
1213 GeomAbs_SurfaceType typS1 = myHS1->GetType();
1214 GeomAbs_SurfaceType typS2 = myHS2->GetType();
1215 if( typS1 == GeomAbs_SurfaceOfExtrusion ||
1216 typS1 == GeomAbs_OffsetSurface ||
1217 typS1 == GeomAbs_SurfaceOfRevolution ||
1218 typS2 == GeomAbs_SurfaceOfExtrusion ||
1219 typS2 == GeomAbs_OffsetSurface ||
1220 typS2 == GeomAbs_SurfaceOfRevolution) {
1221 Handle(Geom2d_BSplineCurve) H1;
1222 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1226 Standard_Real u1, v1, u2, v2, Tol;
1228 Tol = Precision::Confusion();
1229 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1230 ok = (dom1->Classify(gp_Pnt2d(u1, v1), Tol) != TopAbs_OUT);
1232 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1235 Handle(Geom2d_BSplineCurve) H1;
1236 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1239 }// for (i=1; i<=aNbParts; i++) {
1240 }// case IntPatch_Lin: case IntPatch_Parabola: case IntPatch_Hyperbola:
1243 //########################################
1244 // Circle and Ellipse
1245 //########################################
1246 case IntPatch_Circle:
1247 case IntPatch_Ellipse: {
1249 if (typl == IntPatch_Circle) {
1250 newc = new Geom_Circle
1251 (Handle(IntPatch_GLine)::DownCast(L)->Circle());
1253 else { //IntPatch_Ellipse
1254 newc = new Geom_Ellipse
1255 (Handle(IntPatch_GLine)::DownCast(L)->Ellipse());
1259 TolR3d (myFace1, myFace2, myTolReached3d);
1261 aNbParts=myLConstruct.NbParts();
1263 Standard_Real aPeriod, aNul;
1264 TColStd_SequenceOfReal aSeqFprm, aSeqLprm;
1269 for (i=1; i<=aNbParts; i++) {
1270 myLConstruct.Part(i, fprm, lprm);
1272 if (fprm < aNul && lprm > aNul) {
1273 // interval that goes through 0. is divided on two intervals;
1274 while (fprm<aNul || fprm>aPeriod) fprm=fprm+aPeriod;
1275 while (lprm<aNul || lprm>aPeriod) lprm=lprm+aPeriod;
1277 if((aPeriod - fprm) > Tolpc) {
1278 aSeqFprm.Append(fprm);
1279 aSeqLprm.Append(aPeriod);
1282 gp_Pnt P1 = newc->Value(fprm);
1283 gp_Pnt P2 = newc->Value(aPeriod);
1284 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1285 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1287 if(P1.Distance(P2) > aTolDist) {
1288 Standard_Real anewpar = fprm;
1290 if(ParameterOutOfBoundary(fprm, newc, myFace1, myFace2,
1291 lprm, Standard_False, anewpar, myContext)) {
1294 aSeqFprm.Append(fprm);
1295 aSeqLprm.Append(aPeriod);
1300 if((lprm - aNul) > Tolpc) {
1301 aSeqFprm.Append(aNul);
1302 aSeqLprm.Append(lprm);
1305 gp_Pnt P1 = newc->Value(aNul);
1306 gp_Pnt P2 = newc->Value(lprm);
1307 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1308 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1310 if(P1.Distance(P2) > aTolDist) {
1311 Standard_Real anewpar = lprm;
1313 if(ParameterOutOfBoundary(lprm, newc, myFace1, myFace2,
1314 fprm, Standard_True, anewpar, myContext)) {
1317 aSeqFprm.Append(aNul);
1318 aSeqLprm.Append(lprm);
1324 aSeqFprm.Append(fprm);
1325 aSeqLprm.Append(lprm);
1330 aNbParts=aSeqFprm.Length();
1331 for (i=1; i<=aNbParts; i++) {
1335 Standard_Real aRealEpsilon=RealEpsilon();
1336 if (Abs(fprm) > aRealEpsilon || Abs(lprm-2.*M_PI) > aRealEpsilon) {
1337 //==============================================
1339 IntTools_Curve aCurve;
1340 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1341 aCurve.SetCurve(aTC3D);
1342 fprm=aTC3D->FirstParameter();
1343 lprm=aTC3D->LastParameter ();
1345 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {////
1347 Handle (Geom2d_Curve) C2d;
1348 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1349 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1350 myTolReached2d=Tolpc;
1353 aCurve.SetFirstCurve2d(C2d);
1356 Handle(Geom2d_BSplineCurve) H1;
1357 aCurve.SetFirstCurve2d(H1);
1362 Handle (Geom2d_Curve) C2d;
1363 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1364 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1365 myTolReached2d=Tolpc;
1368 aCurve.SetSecondCurve2d(C2d);
1371 Handle(Geom2d_BSplineCurve) H1;
1372 aCurve.SetSecondCurve2d(H1);
1377 Handle(Geom2d_BSplineCurve) H1;
1378 aCurve.SetFirstCurve2d(H1);
1379 aCurve.SetSecondCurve2d(H1);
1381 mySeqOfCurve.Append(aCurve);
1382 //==============================================
1383 } //if (Abs(fprm) > RealEpsilon() || Abs(lprm-2.*M_PI) > RealEpsilon())
1386 // on regarde si on garde
1389 // if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*M_PI) < RealEpsilon()) {
1390 if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*M_PI) <= aRealEpsilon) {
1391 IntTools_Curve aCurve;
1392 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1393 aCurve.SetCurve(aTC3D);
1394 fprm=aTC3D->FirstParameter();
1395 lprm=aTC3D->LastParameter ();
1398 Handle (Geom2d_Curve) C2d;
1399 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1400 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1401 myTolReached2d=Tolpc;
1404 aCurve.SetFirstCurve2d(C2d);
1407 Handle(Geom2d_BSplineCurve) H1;
1408 aCurve.SetFirstCurve2d(H1);
1412 Handle (Geom2d_Curve) C2d;
1413 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1414 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1415 myTolReached2d=Tolpc;
1418 aCurve.SetSecondCurve2d(C2d);
1421 Handle(Geom2d_BSplineCurve) H1;
1422 aCurve.SetSecondCurve2d(H1);
1424 mySeqOfCurve.Append(aCurve);
1429 Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol;
1431 aTwoPIdiv17=2.*M_PI/17.;
1433 for (j=0; j<=17; j++) {
1434 gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
1435 Tol = Precision::Confusion();
1437 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1438 ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT);
1440 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1443 IntTools_Curve aCurve;
1444 aCurve.SetCurve(newc);
1445 //==============================================
1446 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {
1449 Handle (Geom2d_Curve) C2d;
1450 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1451 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1452 myTolReached2d=Tolpc;
1455 aCurve.SetFirstCurve2d(C2d);
1458 Handle(Geom2d_BSplineCurve) H1;
1459 aCurve.SetFirstCurve2d(H1);
1463 Handle (Geom2d_Curve) C2d;
1464 BuildPCurves(fprm, lprm, Tolpc,myHS2->ChangeSurface().Surface(), newc, C2d);
1465 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1466 myTolReached2d=Tolpc;
1469 aCurve.SetSecondCurve2d(C2d);
1473 Handle(Geom2d_BSplineCurve) H1;
1474 aCurve.SetSecondCurve2d(H1);
1476 }// end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse)
1479 Handle(Geom2d_BSplineCurve) H1;
1481 aCurve.SetFirstCurve2d(H1);
1482 aCurve.SetSecondCurve2d(H1);
1484 //==============================================
1486 mySeqOfCurve.Append(aCurve);
1489 }// end of if (ok) {
1490 }// end of for (Standard_Integer j=0; j<=17; j++)
1491 }// end of else { on regarde si on garde
1492 }// for (i=1; i<=myLConstruct.NbParts(); i++)
1493 }// IntPatch_Circle: IntPatch_Ellipse:
1496 case IntPatch_Analytic: {
1497 IntSurf_Quadric quad1,quad2;
1498 GeomAbs_SurfaceType typs = myHS1->Surface().GetType();
1502 quad1.SetValue(myHS1->Surface().Plane());
1504 case GeomAbs_Cylinder:
1505 quad1.SetValue(myHS1->Surface().Cylinder());
1508 quad1.SetValue(myHS1->Surface().Cone());
1510 case GeomAbs_Sphere:
1511 quad1.SetValue(myHS1->Surface().Sphere());
1514 quad1.SetValue(myHS1->Surface().Torus());
1517 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 1");
1520 typs = myHS2->Surface().GetType();
1524 quad2.SetValue(myHS2->Surface().Plane());
1526 case GeomAbs_Cylinder:
1527 quad2.SetValue(myHS2->Surface().Cylinder());
1530 quad2.SetValue(myHS2->Surface().Cone());
1532 case GeomAbs_Sphere:
1533 quad2.SetValue(myHS2->Surface().Sphere());
1536 quad2.SetValue(myHS2->Surface().Torus());
1539 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 2");
1543 IntPatch_ALineToWLine convert (quad1, quad2);
1546 aNbParts=myLConstruct.NbParts();
1547 for (i=1; i<=aNbParts; i++) {
1548 myLConstruct.Part(i, fprm, lprm);
1549 Handle(IntPatch_WLine) WL =
1550 convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm);
1552 Handle(Geom2d_BSplineCurve) H1;
1553 Handle(Geom2d_BSplineCurve) H2;
1556 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1560 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1563 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1567 else { // myApprox=TRUE
1568 GeomInt_WLApprox theapp3d;
1570 Standard_Real tol2d = myTolApprox;
1572 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True);
1574 aNbParts=myLConstruct.NbParts();
1575 for (i=1; i<=aNbParts; i++) {
1576 myLConstruct.Part(i, fprm, lprm);
1577 Handle(IntPatch_WLine) WL =
1578 convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
1580 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
1582 if (!theapp3d.IsDone()) {
1584 Handle(Geom2d_BSplineCurve) H1;
1585 Handle(Geom2d_BSplineCurve) H2;
1588 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1592 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1595 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1599 if(myApprox1 || myApprox2) {
1600 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) {
1601 myTolReached2d = theapp3d.TolReached2d();
1605 if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) {
1606 myTolReached3d = theapp3d.TolReached3d();
1609 Standard_Integer aNbMultiCurves, nbpoles;
1610 aNbMultiCurves=theapp3d.NbMultiCurves();
1611 for (j=1; j<=aNbMultiCurves; j++) {
1612 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1613 nbpoles = mbspc.NbPoles();
1615 TColgp_Array1OfPnt tpoles(1, nbpoles);
1616 mbspc.Curve(1, tpoles);
1617 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1619 mbspc.Multiplicities(),
1622 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1623 Check.FixTangent(Standard_True,Standard_True);
1625 IntTools_Curve aCurve;
1626 aCurve.SetCurve(BS);
1629 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1630 mbspc.Curve(2,tpoles2d);
1631 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1633 mbspc.Multiplicities(),
1636 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1637 newCheck.FixTangent(Standard_True,Standard_True);
1639 aCurve.SetFirstCurve2d(BS2);
1642 Handle(Geom2d_BSplineCurve) H1;
1643 aCurve.SetFirstCurve2d(H1);
1647 TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
1648 Standard_Integer TwoOrThree;
1649 TwoOrThree=myApprox1 ? 3 : 2;
1650 mbspc.Curve(TwoOrThree, tpoles2d);
1651 Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
1653 mbspc.Multiplicities(),
1656 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1657 newCheck.FixTangent(Standard_True,Standard_True);
1659 aCurve.SetSecondCurve2d(BS2);
1662 Handle(Geom2d_BSplineCurve) H2;
1663 aCurve.SetSecondCurve2d(H2);
1666 mySeqOfCurve.Append(aCurve);
1668 }// for (j=1; j<=aNbMultiCurves; j++) {
1669 }// else from if (!theapp3d.IsDone())
1670 }// for (i=1; i<=aNbParts; i++) {
1671 }// else { // myApprox=TRUE
1672 }// case IntPatch_Analytic:
1675 case IntPatch_Walking:{
1676 Handle(IntPatch_WLine) WL =
1677 Handle(IntPatch_WLine)::DownCast(L);
1679 Standard_Integer ifprm, ilprm;
1683 if(!bAvoidLineConstructor){
1684 aNbParts=myLConstruct.NbParts();
1686 for (i=1; i<=aNbParts; ++i) {
1687 Handle(Geom2d_BSplineCurve) H1, H2;
1688 Handle(Geom_Curve) aBSp;
1690 if(bAvoidLineConstructor) {
1692 ilprm = WL->NbPnts();
1695 myLConstruct.Part(i, fprm, lprm);
1696 ifprm=(Standard_Integer)fprm;
1697 ilprm=(Standard_Integer)lprm;
1701 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1705 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1708 aBSp=MakeBSpline(WL, ifprm, ilprm);
1709 IntTools_Curve aIC(aBSp, H1, H2);
1710 mySeqOfCurve.Append(aIC);
1711 }// for (i=1; i<=aNbParts; ++i) {
1712 }// if (!myApprox) {
1715 Standard_Boolean bIsDecomposited;
1716 Standard_Integer nbiter, aNbSeqOfL;
1717 Standard_Real tol2d, aTolApproxImp;
1718 IntPatch_SequenceOfLine aSeqOfL;
1719 GeomInt_WLApprox theapp3d;
1720 Approx_ParametrizationType aParType = Approx_ChordLength;
1722 Standard_Boolean anApprox1 = myApprox1;
1723 Standard_Boolean anApprox2 = myApprox2;
1725 aTolApproxImp=1.e-5;
1726 tol2d = myTolApprox;
1728 GeomAbs_SurfaceType typs1, typs2;
1729 typs1 = myHS1->Surface().GetType();
1730 typs2 = myHS2->Surface().GetType();
1731 Standard_Boolean anWithPC = Standard_True;
1733 if(typs1 == GeomAbs_Cylinder && typs2 == GeomAbs_Sphere) {
1735 ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere());
1737 else if (typs1 == GeomAbs_Sphere && typs2 == GeomAbs_Cylinder) {
1739 ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere());
1743 myTolApprox = aTolApproxImp;//1.e-5;
1744 anApprox1 = Standard_False;
1745 anApprox2 = Standard_False;
1747 tol2d = myTolApprox;
1750 if(myHS1 == myHS2) {
1751 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1752 rejectSurface = Standard_True;
1755 if(reApprox && !rejectSurface)
1756 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1758 Standard_Integer iDegMax, iDegMin, iNbIter;
1760 ApproxParameters(myHS1, myHS2, iDegMin, iDegMax, iNbIter);
1761 theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, iNbIter, Standard_True, aParType);
1765 Standard_Real aReachedTol = Precision::Confusion();
1766 bIsDecomposited=DecompositionOfWLine(WL,
1772 bAvoidLineConstructor,
1776 if ( bIsDecomposited && ( myTolReached3d < aReachedTol ) ) {
1777 myTolReached3d = aReachedTol;
1780 aNbSeqOfL=aSeqOfL.Length();
1782 if (bIsDecomposited) {
1788 if (!bAvoidLineConstructor) {
1789 aNbParts=myLConstruct.NbParts();
1794 for(i = 1; i <= nbiter; ++i) {
1795 if(bIsDecomposited) {
1796 WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i));
1798 ilprm = WL->NbPnts();
1801 if(bAvoidLineConstructor) {
1803 ilprm = WL->NbPnts();
1806 myLConstruct.Part(i, fprm, lprm);
1807 ifprm = (Standard_Integer)fprm;
1808 ilprm = (Standard_Integer)lprm;
1812 //-- Si une des surfaces est un plan , on approxime en 2d
1813 //-- sur cette surface et on remonte les points 2d en 3d.
1814 if(typs1 == GeomAbs_Plane) {
1815 theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm);
1817 else if(typs2 == GeomAbs_Plane) {
1818 theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm);
1822 if (myHS1 != myHS2){
1823 if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) &&
1824 (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) {
1826 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType);
1828 Standard_Boolean bUseSurfaces;
1829 bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm, ilprm);
1832 rejectSurface = Standard_True;
1834 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1839 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm);
1842 if (!theapp3d.IsDone()) {
1843 Handle(Geom2d_BSplineCurve) H1;
1844 Handle(Geom2d_BSplineCurve) H2;
1846 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
1849 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1853 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1856 IntTools_Curve aIC(aBSp, H1, H2);
1857 mySeqOfCurve.Append(aIC);
1861 if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) {
1862 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) {
1863 myTolReached2d = theapp3d.TolReached2d();
1866 if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) {
1867 myTolReached3d = myTolReached2d;
1869 if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
1870 if (myTolReached3d<1.e-6) {
1871 myTolReached3d = theapp3d.TolReached3d();
1872 myTolReached3d=1.e-6;
1876 else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) {
1877 myTolReached3d = theapp3d.TolReached3d();
1880 Standard_Integer aNbMultiCurves, nbpoles;
1881 aNbMultiCurves=theapp3d.NbMultiCurves();
1882 for (j=1; j<=aNbMultiCurves; j++) {
1883 if(typs1 == GeomAbs_Plane) {
1884 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1885 nbpoles = mbspc.NbPoles();
1887 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1888 TColgp_Array1OfPnt tpoles(1,nbpoles);
1890 mbspc.Curve(1,tpoles2d);
1891 const gp_Pln& Pln = myHS1->Surface().Plane();
1893 Standard_Integer ik;
1894 for(ik = 1; ik<= nbpoles; ik++) {
1896 ElSLib::Value(tpoles2d.Value(ik).X(),
1897 tpoles2d.Value(ik).Y(),
1901 Handle(Geom_BSplineCurve) BS =
1902 new Geom_BSplineCurve(tpoles,
1904 mbspc.Multiplicities(),
1906 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1907 Check.FixTangent(Standard_True, Standard_True);
1909 IntTools_Curve aCurve;
1910 aCurve.SetCurve(BS);
1913 Handle(Geom2d_BSplineCurve) BS1 =
1914 new Geom2d_BSplineCurve(tpoles2d,
1916 mbspc.Multiplicities(),
1918 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
1919 Check1.FixTangent(Standard_True,Standard_True);
1921 // ############################################
1922 if(!rejectSurface && !reApprox) {
1923 Standard_Boolean isValid = IsCurveValid(BS1);
1925 reApprox = Standard_True;
1929 // ############################################
1930 aCurve.SetFirstCurve2d(BS1);
1933 Handle(Geom2d_BSplineCurve) H1;
1934 aCurve.SetFirstCurve2d(H1);
1938 mbspc.Curve(2, tpoles2d);
1940 Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
1942 mbspc.Multiplicities(),
1944 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1945 newCheck.FixTangent(Standard_True,Standard_True);
1947 // ###########################################
1948 if(!rejectSurface && !reApprox) {
1949 Standard_Boolean isValid = IsCurveValid(BS2);
1951 reApprox = Standard_True;
1955 // ###########################################
1957 aCurve.SetSecondCurve2d(BS2);
1960 Handle(Geom2d_BSplineCurve) H2;
1962 aCurve.SetSecondCurve2d(H2);
1965 mySeqOfCurve.Append(aCurve);
1966 }//if(typs1 == GeomAbs_Plane) {
1968 else if(typs2 == GeomAbs_Plane) {
1969 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1970 nbpoles = mbspc.NbPoles();
1972 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1973 TColgp_Array1OfPnt tpoles(1,nbpoles);
1974 mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d);
1975 const gp_Pln& Pln = myHS2->Surface().Plane();
1977 Standard_Integer ik;
1978 for(ik = 1; ik<= nbpoles; ik++) {
1980 ElSLib::Value(tpoles2d.Value(ik).X(),
1981 tpoles2d.Value(ik).Y(),
1986 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1988 mbspc.Multiplicities(),
1990 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1991 Check.FixTangent(Standard_True,Standard_True);
1993 IntTools_Curve aCurve;
1994 aCurve.SetCurve(BS);
1997 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
1999 mbspc.Multiplicities(),
2001 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
2002 Check1.FixTangent(Standard_True,Standard_True);
2004 // ###########################################
2005 if(!rejectSurface && !reApprox) {
2006 Standard_Boolean isValid = IsCurveValid(BS1);
2008 reApprox = Standard_True;
2012 // ###########################################
2013 bPCurvesOk = CheckPCurve(BS1, myFace2);
2014 aCurve.SetSecondCurve2d(BS1);
2017 Handle(Geom2d_BSplineCurve) H2;
2018 aCurve.SetSecondCurve2d(H2);
2022 mbspc.Curve(1,tpoles2d);
2023 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
2025 mbspc.Multiplicities(),
2027 GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK);
2028 Check2.FixTangent(Standard_True,Standard_True);
2030 // ###########################################
2031 if(!rejectSurface && !reApprox) {
2032 Standard_Boolean isValid = IsCurveValid(BS2);
2034 reApprox = Standard_True;
2038 // ###########################################
2039 bPCurvesOk = bPCurvesOk && CheckPCurve(BS2, myFace1);
2040 aCurve.SetFirstCurve2d(BS2);
2043 Handle(Geom2d_BSplineCurve) H1;
2045 aCurve.SetFirstCurve2d(H1);
2048 //if points of the pcurves are out of the faces bounds
2049 //create 3d and 2d curves without approximation
2051 Handle(Geom2d_BSplineCurve) H1, H2;
2052 bPCurvesOk = Standard_True;
2054 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
2057 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
2058 bPCurvesOk = CheckPCurve(H1, myFace1);
2062 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
2063 bPCurvesOk = bPCurvesOk && CheckPCurve(H2, myFace2);
2066 //if pcurves created without approximation are out of the
2067 //faces bounds, use approximated 3d and 2d curves
2069 IntTools_Curve aIC(aBSp, H1, H2);
2070 mySeqOfCurve.Append(aIC);
2072 mySeqOfCurve.Append(aCurve);
2075 mySeqOfCurve.Append(aCurve);
2077 }// else if(typs2 == GeomAbs_Plane)
2079 else { //typs2 != GeomAbs_Plane && typs1 != GeomAbs_Plane
2080 Standard_Boolean bIsValid1, bIsValid2;
2081 Handle(Geom_BSplineCurve) BS;
2082 Handle(Geom2d_BSplineCurve) aH2D;
2083 IntTools_Curve aCurve;
2085 bIsValid1=Standard_True;
2086 bIsValid2=Standard_True;
2088 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2089 nbpoles = mbspc.NbPoles();
2090 TColgp_Array1OfPnt tpoles(1,nbpoles);
2091 mbspc.Curve(1,tpoles);
2092 BS=new Geom_BSplineCurve(tpoles,
2094 mbspc.Multiplicities(),
2096 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2097 Check.FixTangent(Standard_True,Standard_True);
2099 aCurve.SetCurve(BS);
2100 aCurve.SetFirstCurve2d(aH2D);
2101 aCurve.SetSecondCurve2d(aH2D);
2105 Handle(Geom2d_BSplineCurve) BS1;
2106 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2107 mbspc.Curve(2,tpoles2d);
2109 BS1=new Geom2d_BSplineCurve(tpoles2d,
2111 mbspc.Multiplicities(),
2113 GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK);
2114 newCheck.FixTangent(Standard_True,Standard_True);
2117 bIsValid1=CheckPCurve(BS1, myFace1);
2120 aCurve.SetFirstCurve2d(BS1);
2123 Handle(Geom2d_BSplineCurve) BS1;
2124 fprm = BS->FirstParameter();
2125 lprm = BS->LastParameter();
2127 Handle(Geom2d_Curve) C2d;
2128 Standard_Real aTol = myTolApprox;
2129 BuildPCurves(fprm, lprm, aTol, myHS1->ChangeSurface().Surface(), BS, C2d);
2130 BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2131 aCurve.SetFirstCurve2d(BS1);
2133 } // if(myApprox1) {
2137 Handle(Geom2d_BSplineCurve) BS2;
2138 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2139 mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d);
2140 BS2=new Geom2d_BSplineCurve(tpoles2d,
2142 mbspc.Multiplicities(),
2144 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2145 newCheck.FixTangent(Standard_True,Standard_True);
2148 bIsValid2=CheckPCurve(BS2, myFace2);
2150 aCurve.SetSecondCurve2d(BS2);
2153 Handle(Geom2d_BSplineCurve) BS2;
2154 fprm = BS->FirstParameter();
2155 lprm = BS->LastParameter();
2157 Handle(Geom2d_Curve) C2d;
2158 Standard_Real aTol = myTolApprox;
2159 BuildPCurves(fprm, lprm, aTol, myHS2->ChangeSurface().Surface(), BS, C2d);
2160 BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2161 aCurve.SetSecondCurve2d(BS2);
2164 if (!bIsValid1 || !bIsValid2) {
2165 myTolApprox=aTolApproxImp;//1.e-5;
2166 tol2d = myTolApprox;
2167 reApprox = Standard_True;
2171 mySeqOfCurve.Append(aCurve);
2177 }// case IntPatch_Walking:{
2180 case IntPatch_Restriction:
2188 //=======================================================================
2189 //function : BuildPCurves
2191 //=======================================================================
2192 void BuildPCurves (Standard_Real f,
2195 const Handle (Geom_Surface)& S,
2196 const Handle (Geom_Curve)& C,
2197 Handle (Geom2d_Curve)& C2d)
2199 if (!C2d.IsNull()) {
2203 Standard_Real umin,umax,vmin,vmax;
2205 S->Bounds(umin, umax, vmin, vmax);
2206 // in class ProjLib_Function the range of parameters is shrank by 1.e-09
2207 if((l - f) > 2.e-09) {
2208 C2d = GeomProjLib::Curve2d(C,f,l,S,umin,umax,vmin,vmax,Tol);
2211 // proj. a circle that goes through the pole on a sphere to the sphere
2212 Tol += Precision::Confusion();
2213 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2217 if((l - f) > Epsilon(Abs(f))) {
2218 GeomAPI_ProjectPointOnSurf aProjector1, aProjector2;
2219 gp_Pnt P1 = C->Value(f);
2220 gp_Pnt P2 = C->Value(l);
2221 aProjector1.Init(P1, S);
2222 aProjector2.Init(P2, S);
2224 if(aProjector1.IsDone() && aProjector2.IsDone()) {
2225 Standard_Real U=0., V=0.;
2226 aProjector1.LowerDistanceParameters(U, V);
2229 aProjector2.LowerDistanceParameters(U, V);
2232 if(p1.Distance(p2) > gp::Resolution()) {
2233 TColgp_Array1OfPnt2d poles(1,2);
2234 TColStd_Array1OfReal knots(1,2);
2235 TColStd_Array1OfInteger mults(1,2);
2240 mults(1) = mults(2) = 2;
2242 C2d = new Geom2d_BSplineCurve(poles,knots,mults,1);
2244 // compute reached tolerance.begin
2245 gp_Pnt PMid = C->Value((f + l) * 0.5);
2246 aProjector1.Perform(PMid);
2248 if(aProjector1.IsDone()) {
2249 aProjector1.LowerDistanceParameters(U, V);
2250 gp_Pnt2d pmidproj(U, V);
2251 gp_Pnt2d pmidcurve2d = C2d->Value((f + l) * 0.5);
2252 Standard_Real adist = pmidcurve2d.Distance(pmidproj);
2253 Tol = (adist > Tol) ? adist : Tol;
2255 // compute reached tolerance.end
2261 if (S->IsUPeriodic() && !C2d.IsNull()) {
2262 // Recadre dans le domaine UV de la face
2263 Standard_Real aTm, U0, aEps, period, du, U0x;
2264 Standard_Boolean bAdjust;
2266 aEps = Precision::PConfusion();
2267 period = S->UPeriod();
2270 gp_Pnt2d pm = C2d->Value(aTm);
2274 GeomInt::AdjustPeriodic(U0, umin, umax, period, U0x, du, aEps);
2276 gp_Vec2d T1(du, 0.);
2282 //=======================================================================
2283 //function : Parameters
2285 //=======================================================================
2286 void Parameters(const Handle(GeomAdaptor_HSurface)& HS1,
2287 const Handle(GeomAdaptor_HSurface)& HS2,
2288 const gp_Pnt& Ptref,
2295 IntSurf_Quadric quad1,quad2;
2296 GeomAbs_SurfaceType typs = HS1->Surface().GetType();
2300 quad1.SetValue(HS1->Surface().Plane());
2302 case GeomAbs_Cylinder:
2303 quad1.SetValue(HS1->Surface().Cylinder());
2306 quad1.SetValue(HS1->Surface().Cone());
2308 case GeomAbs_Sphere:
2309 quad1.SetValue(HS1->Surface().Sphere());
2312 quad1.SetValue(HS1->Surface().Torus());
2315 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2318 typs = HS2->Surface().GetType();
2321 quad2.SetValue(HS2->Surface().Plane());
2323 case GeomAbs_Cylinder:
2324 quad2.SetValue(HS2->Surface().Cylinder());
2327 quad2.SetValue(HS2->Surface().Cone());
2329 case GeomAbs_Sphere:
2330 quad2.SetValue(HS2->Surface().Sphere());
2333 quad2.SetValue(HS2->Surface().Torus());
2336 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2339 quad1.Parameters(Ptref,U1,V1);
2340 quad2.Parameters(Ptref,U2,V2);
2343 //=======================================================================
2344 //function : MakeBSpline
2346 //=======================================================================
2347 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL,
2348 const Standard_Integer ideb,
2349 const Standard_Integer ifin)
2351 Standard_Integer i,nbpnt = ifin-ideb+1;
2352 TColgp_Array1OfPnt poles(1,nbpnt);
2353 TColStd_Array1OfReal knots(1,nbpnt);
2354 TColStd_Array1OfInteger mults(1,nbpnt);
2355 Standard_Integer ipidebm1;
2356 for(i=1,ipidebm1=i+ideb-1; i<=nbpnt;ipidebm1++, i++) {
2357 poles(i) = WL->Point(ipidebm1).Value();
2361 mults(1) = mults(nbpnt) = 2;
2363 new Geom_BSplineCurve(poles,knots,mults,1);
2367 //=======================================================================
2368 //function : MakeBSpline2d
2370 //=======================================================================
2371 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
2372 const Standard_Integer ideb,
2373 const Standard_Integer ifin,
2374 const Standard_Boolean onFirst)
2376 Standard_Integer i, nbpnt = ifin-ideb+1;
2377 TColgp_Array1OfPnt2d poles(1,nbpnt);
2378 TColStd_Array1OfReal knots(1,nbpnt);
2379 TColStd_Array1OfInteger mults(1,nbpnt);
2380 Standard_Integer ipidebm1;
2382 for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) {
2385 theWLine->Point(ipidebm1).ParametersOnS1(U, V);
2387 theWLine->Point(ipidebm1).ParametersOnS2(U, V);
2388 poles(i).SetCoord(U, V);
2392 mults(1) = mults(nbpnt) = 2;
2394 return new Geom2d_BSplineCurve(poles,knots,mults,1);
2396 //=======================================================================
2397 //function : PrepareLines3D
2399 //=======================================================================
2400 void IntTools_FaceFace::PrepareLines3D(const Standard_Boolean bToSplit)
2402 Standard_Integer i, aNbCurves;
2403 GeomAbs_SurfaceType aType1, aType2;
2404 IntTools_SequenceOfCurves aNewCvs;
2406 // 1. Treatment closed curves
2407 aNbCurves=mySeqOfCurve.Length();
2408 for (i=1; i<=aNbCurves; ++i) {
2409 const IntTools_Curve& aIC=mySeqOfCurve(i);
2412 Standard_Integer j, aNbC;
2413 IntTools_SequenceOfCurves aSeqCvs;
2415 aNbC=IntTools_Tools::SplitCurve(aIC, aSeqCvs);
2417 for (j=1; j<=aNbC; ++j) {
2418 const IntTools_Curve& aICNew=aSeqCvs(j);
2419 aNewCvs.Append(aICNew);
2423 aNewCvs.Append(aIC);
2427 aNewCvs.Append(aIC);
2431 // 2. Plane\Cone intersection when we had 4 curves
2432 aType1=myHS1->GetType();
2433 aType2=myHS2->GetType();
2434 aNbCurves=aNewCvs.Length();
2436 if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone) ||
2437 (aType2==GeomAbs_Plane && aType1==GeomAbs_Cone)) {
2439 GeomAbs_CurveType aCType1;
2441 aCType1=aNewCvs(1).Type();
2442 if (aCType1==GeomAbs_Line) {
2443 IntTools_SequenceOfCurves aSeqIn, aSeqOut;
2445 for (i=1; i<=aNbCurves; ++i) {
2446 const IntTools_Curve& aIC=aNewCvs(i);
2450 IntTools_Tools::RejectLines(aSeqIn, aSeqOut);
2453 aNbCurves=aSeqOut.Length();
2454 for (i=1; i<=aNbCurves; ++i) {
2455 const IntTools_Curve& aIC=aSeqOut(i);
2456 aNewCvs.Append(aIC);
2460 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone)...
2462 // 3. Fill mySeqOfCurve
2463 mySeqOfCurve.Clear();
2464 aNbCurves=aNewCvs.Length();
2465 for (i=1; i<=aNbCurves; ++i) {
2466 const IntTools_Curve& aIC=aNewCvs(i);
2467 mySeqOfCurve.Append(aIC);
2470 //=======================================================================
2471 //function : CorrectSurfaceBoundaries
2473 //=======================================================================
2474 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
2475 const Standard_Real theTolerance,
2476 Standard_Real& theumin,
2477 Standard_Real& theumax,
2478 Standard_Real& thevmin,
2479 Standard_Real& thevmax)
2481 Standard_Boolean enlarge, isuperiodic, isvperiodic;
2482 Standard_Real uinf, usup, vinf, vsup, delta;
2483 GeomAbs_SurfaceType aType;
2484 Handle(Geom_Surface) aSurface;
2486 aSurface = BRep_Tool::Surface(theFace);
2487 aSurface->Bounds(uinf, usup, vinf, vsup);
2488 delta = theTolerance;
2489 enlarge = Standard_False;
2491 GeomAdaptor_Surface anAdaptorSurface(aSurface);
2493 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
2494 Handle(Geom_Surface) aBasisSurface =
2495 (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface))->BasisSurface();
2497 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2498 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2503 if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2504 Handle(Geom_Surface) aBasisSurface =
2505 (Handle(Geom_OffsetSurface)::DownCast(aSurface))->BasisSurface();
2507 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2508 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2513 isuperiodic = anAdaptorSurface.IsUPeriodic();
2514 isvperiodic = anAdaptorSurface.IsVPeriodic();
2516 aType=anAdaptorSurface.GetType();
2517 if((aType==GeomAbs_BezierSurface) ||
2518 (aType==GeomAbs_BSplineSurface) ||
2519 (aType==GeomAbs_SurfaceOfExtrusion) ||
2520 (aType==GeomAbs_SurfaceOfRevolution) ||
2521 (aType==GeomAbs_Cylinder)) {
2522 enlarge=Standard_True;
2525 if(!isuperiodic && enlarge) {
2527 if((theumin - uinf) > delta )
2533 if((usup - theumax) > delta )
2539 if(!isvperiodic && enlarge) {
2540 if((thevmin - vinf) > delta ) {
2546 if((vsup - thevmax) > delta ) {
2555 Standard_Integer aNbP;
2556 Standard_Real aXP, dXfact, aXmid, aX1, aX2, aTolPA;
2558 aTolPA=Precision::Angular();
2561 aXP=anAdaptorSurface.UPeriod();
2562 dXfact=theumax-theumin;
2563 if (dXfact-aTolPA>aXP) {
2564 aXmid=0.5*(theumax+theumin);
2565 aNbP=RealToInt(aXmid/aXP);
2570 if (theumin>aTolPA) {
2571 aX1=theumin+aNbP*aXP;
2584 aXP=anAdaptorSurface.VPeriod();
2585 dXfact=thevmax-thevmin;
2586 if (dXfact-aTolPA>aXP) {
2587 aXmid=0.5*(thevmax+thevmin);
2588 aNbP=RealToInt(aXmid/aXP);
2593 if (thevmin>aTolPA) {
2594 aX1=thevmin+aNbP*aXP;
2607 if(isuperiodic || isvperiodic) {
2608 Standard_Boolean correct = Standard_False;
2609 Standard_Boolean correctU = Standard_False;
2610 Standard_Boolean correctV = Standard_False;
2612 TopExp_Explorer anExp;
2614 for(anExp.Init(theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
2615 if(BRep_Tool::IsClosed(TopoDS::Edge(anExp.Current()), theFace)) {
2616 correct = Standard_True;
2618 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
2620 for(Standard_Integer i = 0; i < 2; i++) {
2622 anEdge.Orientation(TopAbs_FORWARD);
2625 anEdge.Orientation(TopAbs_REVERSED);
2627 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l);
2629 if(aCurve.IsNull()) {
2630 correct = Standard_False;
2633 Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve);
2635 if(aLine.IsNull()) {
2636 correct = Standard_False;
2639 gp_Dir2d anUDir(1., 0.);
2640 gp_Dir2d aVDir(0., 1.);
2641 Standard_Real anAngularTolerance = Precision::Angular();
2643 correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance);
2644 correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance);
2646 gp_Pnt2d pp1 = aCurve->Value(f);
2648 gp_Pnt2d pp2 = aCurve->Value(l);
2657 Standard_Real umin, vmin, umax, vmax;
2658 aBox.Get(umin, vmin, umax, vmax);
2660 if(isuperiodic && correctU) {
2665 if(theumax > umax) {
2669 if(isvperiodic && correctV) {
2681 // The block is dedicated to determine whether WLine [ifprm, ilprm]
2682 // crosses the degenerated zone on each given surface or not.
2683 // If Yes -> We will not use info about surfaces during approximation
2684 // because inside degenerated zone of the surface the approx. algo.
2685 // uses wrong values of normal, etc., and resulting curve will have
2686 // oscillations that we would not like to have.
2691 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2692 const Handle(Geom_Surface)& aS,
2693 const Standard_Integer iDir);
2695 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2696 const TopoDS_Face& aF1,
2697 const TopoDS_Face& aF2);
2698 //=======================================================================
2699 //function : NotUseSurfacesForApprox
2701 //=======================================================================
2702 Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1,
2703 const TopoDS_Face& aF2,
2704 const Handle(IntPatch_WLine)& WL,
2705 const Standard_Integer ifprm,
2706 const Standard_Integer ilprm)
2708 Standard_Boolean bPInDZ;
2710 Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve();
2712 const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm);
2713 bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2);
2718 const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm);
2719 bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2);
2723 //=======================================================================
2724 //function : IsPointInDegeneratedZone
2726 //=======================================================================
2727 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2728 const TopoDS_Face& aF1,
2729 const TopoDS_Face& aF2)
2732 Standard_Boolean bFlag=Standard_True;
2733 Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22;
2734 Standard_Real U1, V1, U2, V2, aDelta, aD;
2737 Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1);
2738 aS1->Bounds(US11, US12, VS11, VS12);
2739 GeomAdaptor_Surface aGAS1(aS1);
2741 Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2);
2742 aS1->Bounds(US21, US22, VS21, VS22);
2743 GeomAdaptor_Surface aGAS2(aS2);
2745 //const gp_Pnt& aP=aP2S.Value();
2746 aP2S.Parameters(U1, V1, U2, V2);
2750 aD=aGAS1.UResolution(aDelta);
2751 aP2d.SetCoord(U1, V1);
2752 if (fabs(U1-US11) < aD) {
2753 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2758 if (fabs(U1-US12) < aD) {
2759 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2764 aD=aGAS1.VResolution(aDelta);
2765 if (fabs(V1-VS11) < aDelta) {
2766 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2771 if (fabs(V1-VS12) < aDelta) {
2772 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2778 aD=aGAS2.UResolution(aDelta);
2779 aP2d.SetCoord(U2, V2);
2780 if (fabs(U2-US21) < aDelta) {
2781 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2786 if (fabs(U2-US22) < aDelta) {
2787 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2792 aD=aGAS2.VResolution(aDelta);
2793 if (fabs(V2-VS21) < aDelta) {
2794 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2799 if (fabs(V2-VS22) < aDelta) {
2800 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2808 //=======================================================================
2809 //function : IsDegeneratedZone
2811 //=======================================================================
2812 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2813 const Handle(Geom_Surface)& aS,
2814 const Standard_Integer iDir)
2816 Standard_Boolean bFlag=Standard_True;
2817 Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD;
2818 Standard_Real aXm, aYm, aXb, aYb, aXe, aYe;
2819 aS->Bounds(US1, US2, VS1, VS2);
2821 gp_Pnt aPm, aPb, aPe;
2826 aS->D0(aXm, aYm, aPm);
2843 aS->D0(aXb, aYb, aPb);
2844 aS->D0(aXe, aYe, aPe);
2846 d1=aPm.Distance(aPb);
2847 d2=aPm.Distance(aPe);
2848 if (d1 < dD && d2 < dD) {
2865 aS->D0(aXb, aYb, aPb);
2866 aS->D0(aXe, aYe, aPe);
2868 d1=aPm.Distance(aPb);
2869 d2=aPm.Distance(aPe);
2870 if (d1 < dD && d2 < dD) {
2878 //=========================================================================
2879 // static function : ComputePurgedWLine
2880 // purpose : Removes equal points (leave one of equal points) from theWLine
2881 // and recompute vertex parameters.
2882 // Returns new WLine or null WLine if the number
2883 // of the points is less than 2.
2884 //=========================================================================
2885 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine) {
2887 Standard_Integer i, k, v, nb, nbvtx;
2888 Handle(IntPatch_WLine) aResult;
2889 nbvtx = theWLine->NbVertex();
2890 nb = theWLine->NbPnts();
2892 const IntSurf_PntOn2S& p1 = theWLine->Point(1);
2893 const IntSurf_PntOn2S& p2 = theWLine->Point(2);
2894 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
2899 Handle(IntPatch_WLine) aLocalWLine;
2900 Handle(IntPatch_WLine) aTmpWLine = theWLine;
2901 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
2902 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2903 for(i = 1; i <= nb; i++) {
2904 aLineOn2S->Add(theWLine->Point(i));
2907 for(v = 1; v <= nbvtx; v++) {
2908 aLocalWLine->AddVertex(theWLine->Vertex(v));
2911 for(i = 1; i <= aLineOn2S->NbPoints(); i++) {
2912 Standard_Integer aStartIndex = i + 1;
2913 Standard_Integer anEndIndex = i + 5;
2914 nb = aLineOn2S->NbPoints();
2915 anEndIndex = (anEndIndex > nb) ? nb : anEndIndex;
2917 if((aStartIndex > nb) || (anEndIndex <= 1)) {
2922 while(k <= anEndIndex) {
2925 IntSurf_PntOn2S p1 = aLineOn2S->Value(i);
2926 IntSurf_PntOn2S p2 = aLineOn2S->Value(k);
2928 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
2929 aTmpWLine = aLocalWLine;
2930 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2932 for(v = 1; v <= aTmpWLine->NbVertex(); v++) {
2933 IntPatch_Point aVertex = aTmpWLine->Vertex(v);
2934 Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine();
2936 if(avertexindex >= k) {
2937 aVertex.SetParameter(aVertex.ParameterOnLine() - 1.);
2939 aLocalWLine->AddVertex(aVertex);
2941 aLineOn2S->RemovePoint(k);
2950 if(aLineOn2S->NbPoints() > 1) {
2951 aResult = aLocalWLine;
2956 //=======================================================================
2959 //=======================================================================
2960 void TolR3d(const TopoDS_Face& aF1,
2961 const TopoDS_Face& aF2,
2962 Standard_Real& myTolReached3d)
2964 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
2966 aTolTresh=2.999999e-3;
2967 aTolF1 = BRep_Tool::Tolerance(aF1);
2968 aTolF2 = BRep_Tool::Tolerance(aF2);
2969 aTolFMax=Max(aTolF1, aTolF2);
2971 if (aTolFMax>aTolTresh) {
2972 myTolReached3d=aTolFMax;
2975 //=======================================================================
2976 //function : IsPointOnBoundary
2978 //=======================================================================
2979 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
2980 const Standard_Real theFirstBoundary,
2981 const Standard_Real theSecondBoundary,
2982 const Standard_Real theResolution,
2983 Standard_Boolean& IsOnFirstBoundary)
2985 Standard_Boolean bRet;
2987 Standard_Real adist;
2989 bRet=Standard_False;
2990 for(i = 0; i < 2; ++i) {
2991 IsOnFirstBoundary = (i == 0);
2992 if (IsOnFirstBoundary) {
2993 adist = fabs(theParameter - theFirstBoundary);
2996 adist = fabs(theParameter - theSecondBoundary);
2998 if(adist < theResolution) {
3004 // ------------------------------------------------------------------------------------------------
3005 // static function: FindPoint
3007 // ------------------------------------------------------------------------------------------------
3008 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3009 const gp_Pnt2d& theLastPoint,
3010 const Standard_Real theUmin,
3011 const Standard_Real theUmax,
3012 const Standard_Real theVmin,
3013 const Standard_Real theVmax,
3014 gp_Pnt2d& theNewPoint) {
3016 gp_Vec2d aVec(theFirstPoint, theLastPoint);
3017 Standard_Integer i = 0, j = 0;
3019 for(i = 0; i < 4; i++) {
3020 gp_Vec2d anOtherVec;
3021 gp_Vec2d anOtherVecNormal;
3022 gp_Pnt2d aprojpoint = theLastPoint;
3025 anOtherVec.SetX(0.);
3026 anOtherVec.SetY(1.);
3027 anOtherVecNormal.SetX(1.);
3028 anOtherVecNormal.SetY(0.);
3031 aprojpoint.SetX(theUmin);
3033 aprojpoint.SetX(theUmax);
3036 anOtherVec.SetX(1.);
3037 anOtherVec.SetY(0.);
3038 anOtherVecNormal.SetX(0.);
3039 anOtherVecNormal.SetY(1.);
3042 aprojpoint.SetY(theVmin);
3044 aprojpoint.SetY(theVmax);
3046 gp_Vec2d anormvec = aVec;
3047 anormvec.Normalize();
3048 RefineVector(anormvec);
3049 Standard_Real adot1 = anormvec.Dot(anOtherVecNormal);
3051 if(fabs(adot1) < Precision::Angular())
3053 Standard_Real adist = 0.;
3054 Standard_Boolean bIsOut = Standard_False;
3057 adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax);
3058 bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax);
3061 adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax);
3062 bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax);
3064 Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1;
3066 for(j = 0; j < 2; j++) {
3067 anoffset = (j == 0) ? anoffset : -anoffset;
3068 gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset));
3069 gp_Vec2d acurvec(theLastPoint, acurpoint);
3073 Standard_Real aDotX, anAngleX;
3075 aDotX = aVec.Dot(acurvec);
3076 anAngleX = aVec.Angle(acurvec);
3078 if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) {
3080 if((acurpoint.Y() >= theVmin) &&
3081 (acurpoint.Y() <= theVmax)) {
3082 theNewPoint = acurpoint;
3083 return Standard_True;
3087 if((acurpoint.X() >= theUmin) &&
3088 (acurpoint.X() <= theUmax)) {
3089 theNewPoint = acurpoint;
3090 return Standard_True;
3096 return Standard_False;
3100 // ------------------------------------------------------------------------------------------------
3101 // static function: FindPoint
3102 // purpose: Find point on the boundary of radial tangent zone
3103 // ------------------------------------------------------------------------------------------------
3104 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3105 const gp_Pnt2d& theLastPoint,
3106 const Standard_Real theUmin,
3107 const Standard_Real theUmax,
3108 const Standard_Real theVmin,
3109 const Standard_Real theVmax,
3110 const gp_Pnt2d& theTanZoneCenter,
3111 const Standard_Real theZoneRadius,
3112 Handle(GeomAdaptor_HSurface) theGASurface,
3113 gp_Pnt2d& theNewPoint) {
3114 theNewPoint = theLastPoint;
3116 if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) )
3117 return Standard_False;
3119 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3120 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3122 Standard_Real aRadius = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3123 gp_Ax22d anAxis( theTanZoneCenter, gp_Dir2d(1, 0), gp_Dir2d(0, 1) );
3124 gp_Circ2d aCircle( anAxis, aRadius );
3127 gp_Vec2d aDir( theLastPoint.XY() - theFirstPoint.XY() );
3128 Standard_Real aLength = aDir.Magnitude();
3129 if ( aLength <= gp::Resolution() )
3130 return Standard_False;
3131 gp_Lin2d aLine( theFirstPoint, aDir );
3134 Handle(Geom2d_Line) aCLine = new Geom2d_Line( aLine );
3135 Handle(Geom2d_TrimmedCurve) aC1 = new Geom2d_TrimmedCurve( aCLine, 0, aLength );
3136 Handle(Geom2d_Circle) aC2 = new Geom2d_Circle( aCircle );
3138 Standard_Real aTol = aRadius * 0.001;
3139 aTol = ( aTol < Precision::PConfusion() ) ? Precision::PConfusion() : aTol;
3141 Geom2dAPI_InterCurveCurve anIntersector;
3142 anIntersector.Init( aC1, aC2, aTol );
3144 if ( anIntersector.NbPoints() == 0 )
3145 return Standard_False;
3147 Standard_Boolean aFound = Standard_False;
3148 Standard_Real aMinDist = aLength * aLength;
3149 Standard_Integer i = 0;
3150 for ( i = 1; i <= anIntersector.NbPoints(); i++ ) {
3151 gp_Pnt2d aPInt = anIntersector.Point( i );
3152 if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) {
3153 if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) &&
3154 ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) {
3155 theNewPoint = aPInt;
3156 aFound = Standard_True;
3164 // ------------------------------------------------------------------------------------------------
3165 // static function: IsInsideTanZone
3166 // purpose: Check if point is inside a radial tangent zone
3167 // ------------------------------------------------------------------------------------------------
3168 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
3169 const gp_Pnt2d& theTanZoneCenter,
3170 const Standard_Real theZoneRadius,
3171 Handle(GeomAdaptor_HSurface) theGASurface) {
3173 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3174 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3175 Standard_Real aRadiusSQR = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3176 aRadiusSQR *= aRadiusSQR;
3177 if ( thePoint.SquareDistance( theTanZoneCenter ) <= aRadiusSQR )
3178 return Standard_True;
3179 return Standard_False;
3182 // ------------------------------------------------------------------------------------------------
3183 // static function: CheckTangentZonesExist
3184 // purpose: Check if tangent zone exists
3185 // ------------------------------------------------------------------------------------------------
3186 Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& theSurface1,
3187 const Handle(GeomAdaptor_HSurface)& theSurface2 )
3189 if ( ( theSurface1->GetType() != GeomAbs_Torus ) ||
3190 ( theSurface2->GetType() != GeomAbs_Torus ) )
3191 return Standard_False;
3193 gp_Torus aTor1 = theSurface1->Torus();
3194 gp_Torus aTor2 = theSurface2->Torus();
3196 if ( aTor1.Location().Distance( aTor2.Location() ) > Precision::Confusion() )
3197 return Standard_False;
3199 if ( ( fabs( aTor1.MajorRadius() - aTor2.MajorRadius() ) > Precision::Confusion() ) ||
3200 ( fabs( aTor1.MinorRadius() - aTor2.MinorRadius() ) > Precision::Confusion() ) )
3201 return Standard_False;
3203 if ( ( aTor1.MajorRadius() < aTor1.MinorRadius() ) ||
3204 ( aTor2.MajorRadius() < aTor2.MinorRadius() ) )
3205 return Standard_False;
3206 return Standard_True;
3209 // ------------------------------------------------------------------------------------------------
3210 // static function: ComputeTangentZones
3212 // ------------------------------------------------------------------------------------------------
3213 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
3214 const Handle(GeomAdaptor_HSurface)& theSurface2,
3215 const TopoDS_Face& theFace1,
3216 const TopoDS_Face& theFace2,
3217 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
3218 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
3219 Handle(TColStd_HArray1OfReal)& theResultRadius,
3220 const Handle(IntTools_Context)& aContext)
3222 Standard_Integer aResult = 0;
3223 if ( !CheckTangentZonesExist( theSurface1, theSurface2 ) )
3227 TColgp_SequenceOfPnt2d aSeqResultS1, aSeqResultS2;
3228 TColStd_SequenceOfReal aSeqResultRad;
3230 gp_Torus aTor1 = theSurface1->Torus();
3231 gp_Torus aTor2 = theSurface2->Torus();
3233 gp_Ax2 anax1( aTor1.Location(), aTor1.Axis().Direction() );
3234 gp_Ax2 anax2( aTor2.Location(), aTor2.Axis().Direction() );
3235 Standard_Integer j = 0;
3237 for ( j = 0; j < 2; j++ ) {
3238 Standard_Real aCoef = ( j == 0 ) ? -1 : 1;
3239 Standard_Real aRadius1 = fabs(aTor1.MajorRadius() + aCoef * aTor1.MinorRadius());
3240 Standard_Real aRadius2 = fabs(aTor2.MajorRadius() + aCoef * aTor2.MinorRadius());
3242 gp_Circ aCircle1( anax1, aRadius1 );
3243 gp_Circ aCircle2( anax2, aRadius2 );
3245 // roughly compute radius of tangent zone for perpendicular case
3246 Standard_Real aCriteria = Precision::Confusion() * 0.5;
3248 Standard_Real aT1 = aCriteria;
3249 Standard_Real aT2 = aCriteria;
3251 // internal tangency
3252 Standard_Real aR = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3253 //aT1 = aCriteria * aCriteria + aR * aR - ( aR - aCriteria ) * ( aR - aCriteria );
3254 aT1 = 2. * aR * aCriteria;
3258 // external tangency
3259 Standard_Real aRb = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3260 Standard_Real aRm = ( aRadius1 < aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3261 Standard_Real aDelta = aRb - aCriteria;
3263 aDelta -= aRm * aRm;
3264 aDelta /= 2. * (aRb - aRm);
3265 aDelta -= 0.5 * (aRb - aRm);
3267 aT1 = 2. * aRm * (aRm - aDelta);
3270 aCriteria = ( aT1 > aT2) ? aT1 : aT2;
3271 if ( aCriteria > 0 )
3272 aCriteria = sqrt( aCriteria );
3274 if ( aCriteria > 0.5 * aTor1.MinorRadius() ) {
3275 // too big zone -> drop to minimum
3276 aCriteria = Precision::Confusion();
3279 GeomAdaptor_Curve aC1( new Geom_Circle(aCircle1) );
3280 GeomAdaptor_Curve aC2( new Geom_Circle(aCircle2) );
3281 Extrema_ExtCC anExtrema(aC1, aC2, 0, 2. * M_PI, 0, 2. * M_PI,
3282 Precision::PConfusion(), Precision::PConfusion());
3284 if ( anExtrema.IsDone() ) {
3286 Standard_Integer i = 0;
3287 for ( i = 1; i <= anExtrema.NbExt(); i++ ) {
3288 if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria )
3291 Extrema_POnCurv P1, P2;
3292 anExtrema.Points( i, P1, P2 );
3294 Standard_Boolean bFoundResult = Standard_True;
3297 Standard_Integer surfit = 0;
3298 for ( surfit = 0; surfit < 2; surfit++ ) {
3299 GeomAPI_ProjectPointOnSurf& aProjector =
3300 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3302 gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value();
3303 aProjector.Perform(aP3d);
3305 if(!aProjector.IsDone())
3306 bFoundResult = Standard_False;
3308 if(aProjector.LowerDistance() > aCriteria) {
3309 bFoundResult = Standard_False;
3312 Standard_Real foundU = 0, foundV = 0;
3313 aProjector.LowerDistanceParameters(foundU, foundV);
3315 pr1 = gp_Pnt2d( foundU, foundV );
3317 pr2 = gp_Pnt2d( foundU, foundV );
3321 if ( bFoundResult ) {
3322 aSeqResultS1.Append( pr1 );
3323 aSeqResultS2.Append( pr2 );
3324 aSeqResultRad.Append( aCriteria );
3326 // torus is u and v periodic
3327 const Standard_Real twoPI = M_PI + M_PI;
3328 Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()};
3329 Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()};
3331 // iteration on period bounds
3332 for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) {
3333 Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI;
3334 Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI;
3336 // iteration on surfaces
3337 for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) {
3338 Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp;
3339 Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp;
3340 TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2;
3341 TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2;
3343 if (fabs(arr1[0] - aBound) < Precision::PConfusion()) {
3344 aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) );
3345 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3346 aSeqResultRad.Append( aCriteria );
3348 if (fabs(arr1[1] - aBound) < Precision::PConfusion()) {
3349 aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) );
3350 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3351 aSeqResultRad.Append( aCriteria );
3359 aResult = aSeqResultRad.Length();
3361 if ( aResult > 0 ) {
3362 theResultOnS1 = new TColgp_HArray1OfPnt2d( 1, aResult );
3363 theResultOnS2 = new TColgp_HArray1OfPnt2d( 1, aResult );
3364 theResultRadius = new TColStd_HArray1OfReal( 1, aResult );
3366 for ( Standard_Integer i = 1 ; i <= aResult; i++ ) {
3367 theResultOnS1->SetValue( i, aSeqResultS1.Value(i) );
3368 theResultOnS2->SetValue( i, aSeqResultS2.Value(i) );
3369 theResultRadius->SetValue( i, aSeqResultRad.Value(i) );
3375 // ------------------------------------------------------------------------------------------------
3376 // static function: AdjustByNeighbour
3378 // ------------------------------------------------------------------------------------------------
3379 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
3380 const gp_Pnt2d& theOriginalPoint,
3381 Handle(GeomAdaptor_HSurface) theGASurface) {
3383 gp_Pnt2d ap1 = theaNeighbourPoint;
3384 gp_Pnt2d ap2 = theOriginalPoint;
3386 if ( theGASurface->IsUPeriodic() ) {
3387 Standard_Real aPeriod = theGASurface->UPeriod();
3388 gp_Pnt2d aPTest = ap2;
3389 Standard_Real aSqDistMin = 1.e+100;
3391 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3392 aPTest.SetX( theOriginalPoint.X() + aPeriod * pIt );
3393 Standard_Real dd = ap1.SquareDistance( aPTest );
3395 if ( dd < aSqDistMin ) {
3401 if ( theGASurface->IsVPeriodic() ) {
3402 Standard_Real aPeriod = theGASurface->VPeriod();
3403 gp_Pnt2d aPTest = ap2;
3404 Standard_Real aSqDistMin = 1.e+100;
3406 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3407 aPTest.SetY( theOriginalPoint.Y() + aPeriod * pIt );
3408 Standard_Real dd = ap1.SquareDistance( aPTest );
3410 if ( dd < aSqDistMin ) {
3419 // ------------------------------------------------------------------------------------------------
3420 //function: DecompositionOfWLine
3422 // ------------------------------------------------------------------------------------------------
3423 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
3424 const Handle(GeomAdaptor_HSurface)& theSurface1,
3425 const Handle(GeomAdaptor_HSurface)& theSurface2,
3426 const TopoDS_Face& theFace1,
3427 const TopoDS_Face& theFace2,
3428 const GeomInt_LineConstructor& theLConstructor,
3429 const Standard_Boolean theAvoidLConstructor,
3430 IntPatch_SequenceOfLine& theNewLines,
3431 Standard_Real& theReachedTol3d,
3432 const Handle(IntTools_Context)& aContext)
3435 Standard_Boolean bRet, bAvoidLineConstructor;
3436 Standard_Integer aNbPnts, aNbParts;
3438 bRet=Standard_False;
3439 aNbPnts=theWLine->NbPnts();
3440 bAvoidLineConstructor=theAvoidLConstructor;
3445 if (!bAvoidLineConstructor) {
3446 aNbParts=theLConstructor.NbParts();
3452 Standard_Boolean bIsPrevPointOnBoundary, bIsPointOnBoundary, bIsCurrentPointOnBoundary;
3453 Standard_Integer nblines, pit, i, j;
3455 TColStd_Array1OfListOfInteger anArrayOfLines(1, aNbPnts);
3456 TColStd_Array1OfInteger anArrayOfLineType(1, aNbPnts);
3457 TColStd_ListOfInteger aListOfPointIndex;
3459 Handle(TColgp_HArray1OfPnt2d) aTanZoneS1;
3460 Handle(TColgp_HArray1OfPnt2d) aTanZoneS2;
3461 Handle(TColStd_HArray1OfReal) aTanZoneRadius;
3462 Standard_Integer aNbZone = ComputeTangentZones( theSurface1, theSurface2, theFace1, theFace2,
3463 aTanZoneS1, aTanZoneS2, aTanZoneRadius, aContext);
3467 aTol=Precision::Confusion();
3469 bIsPrevPointOnBoundary=Standard_False;
3470 bIsPointOnBoundary=Standard_False;
3475 for(pit = 1; pit <= aNbPnts; ++pit) {
3476 Standard_Boolean bIsOnFirstBoundary, isperiodic;
3477 Standard_Real aResolution, aPeriod, alowerboundary, aupperboundary, U, V;
3478 Standard_Real aParameter, anoffset, anAdjustPar;
3479 Standard_Real umin, umax, vmin, vmax;
3481 bIsCurrentPointOnBoundary = Standard_False;
3482 const IntSurf_PntOn2S& aPoint = theWLine->Point(pit);
3485 for(i = 0; i < 2; ++i) {
3486 Handle(GeomAdaptor_HSurface) aGASurface = (!i) ? theSurface1 : theSurface2;
3487 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3489 aPoint.ParametersOnS1(U, V);
3492 aPoint.ParametersOnS2(U, V);
3495 for(j = 0; j < 2; j++) {
3496 isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3502 aResolution=aGASurface->UResolution(aTol);
3503 aPeriod=aGASurface->UPeriod();
3504 alowerboundary=umin;
3505 aupperboundary=umax;
3509 aResolution=aGASurface->VResolution(aTol);
3510 aPeriod=aGASurface->VPeriod();
3511 alowerboundary=vmin;
3512 aupperboundary=vmax;
3516 GeomInt::AdjustPeriodic(aParameter,
3523 bIsOnFirstBoundary = Standard_True;// ?
3525 IsPointOnBoundary(anAdjustPar,
3529 bIsOnFirstBoundary);
3531 if(bIsPointOnBoundary) {
3532 bIsCurrentPointOnBoundary = Standard_True;
3536 // check if a point belong to a tangent zone. Begin
3537 Standard_Integer zIt = 0;
3538 for ( zIt = 1; zIt <= aNbZone; zIt++ ) {
3539 gp_Pnt2d aPZone = (i == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3540 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3542 if ( IsInsideTanZone(gp_Pnt2d( U, V ), aPZone, aZoneRadius, aGASurface ) ) {
3543 // set boundary flag to split the curve by a tangent zone
3544 bIsPointOnBoundary = Standard_True;
3545 bIsCurrentPointOnBoundary = Standard_True;
3546 if ( theReachedTol3d < aZoneRadius ) {
3547 theReachedTol3d = aZoneRadius;
3553 }//for(j = 0; j < 2; j++) {
3555 if(bIsCurrentPointOnBoundary){
3558 }//for(i = 0; i < 2; ++i) {
3560 if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) {
3561 if(!aListOfPointIndex.IsEmpty()) {
3563 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3564 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3565 aListOfPointIndex.Clear();
3567 bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary;
3569 aListOfPointIndex.Append(pit);
3570 } //for(pit = 1; pit <= aNbPnts; ++pit) {
3572 if(!aListOfPointIndex.IsEmpty()) {
3574 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3575 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3576 aListOfPointIndex.Clear();
3580 return bRet; //Standard_False;
3584 // 2. Correct wlines.begin
3585 TColStd_Array1OfListOfInteger anArrayOfLineEnds(1, nblines);
3586 Handle(IntSurf_LineOn2S) aSeqOfPntOn2S = new IntSurf_LineOn2S();
3588 for(i = 1; i <= nblines; i++) {
3589 if(anArrayOfLineType.Value(i) != 0) {
3592 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3593 TColStd_ListOfInteger aListOfFLIndex;
3595 for(j = 0; j < 2; j++) {
3596 Standard_Integer aneighbourindex = (j == 0) ? (i - 1) : (i + 1);
3598 if((aneighbourindex < 1) || (aneighbourindex > nblines))
3601 if(anArrayOfLineType.Value(aneighbourindex) == 0)
3603 const TColStd_ListOfInteger& aNeighbour = anArrayOfLines.Value(aneighbourindex);
3604 Standard_Integer anIndex = (j == 0) ? aNeighbour.Last() : aNeighbour.First();
3605 const IntSurf_PntOn2S& aPoint = theWLine->Point(anIndex);
3607 IntSurf_PntOn2S aNewP = aPoint;
3608 if(aListOfIndex.Extent() < 2) {
3609 aSeqOfPntOn2S->Add(aNewP);
3610 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
3614 Standard_Integer iFirst = aListOfIndex.First();
3615 Standard_Integer iLast = aListOfIndex.Last();
3617 for(Standard_Integer surfit = 0; surfit < 2; surfit++) {
3619 Handle(GeomAdaptor_HSurface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2;
3620 Standard_Real umin=0., umax=0., vmin=0., vmax=0.;
3621 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3622 Standard_Real U=0., V=0.;
3625 aNewP.ParametersOnS1(U, V);
3627 aNewP.ParametersOnS2(U, V);
3628 Standard_Integer nbboundaries = 0;
3630 Standard_Boolean bIsNearBoundary = Standard_False;
3631 Standard_Integer aZoneIndex = 0;
3632 Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1
3633 Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1
3636 for(Standard_Integer parit = 0; parit < 2; parit++) {
3637 Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3639 Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
3640 Standard_Real alowerboundary = (parit == 0) ? umin : vmin;
3641 Standard_Real aupperboundary = (parit == 0) ? umax : vmax;
3643 Standard_Real aParameter = (parit == 0) ? U : V;
3644 Standard_Boolean bIsOnFirstBoundary = Standard_True;
3648 IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3649 if(bIsPointOnBoundary) {
3650 bIsUBoundary = (parit == 0);
3651 bIsFirstBoundary = bIsOnFirstBoundary;
3656 Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3657 Standard_Real anoffset, anAdjustPar;
3658 GeomInt::AdjustPeriodic(aParameter, alowerboundary, aupperboundary,
3659 aPeriod, anAdjustPar, anoffset);
3662 IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3663 if(bIsPointOnBoundary) {
3664 bIsUBoundary = (parit == 0);
3665 bIsFirstBoundary = bIsOnFirstBoundary;
3669 //check neighbourhood of boundary
3670 Standard_Real anEpsilon = aResolution * 100.;
3671 Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
3672 anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
3674 bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary,
3675 anEpsilon, bIsOnFirstBoundary);
3681 // check if a point belong to a tangent zone. Begin
3682 for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) {
3683 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3684 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3686 Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast;
3687 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3688 Standard_Real nU1, nV1;
3691 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3693 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3694 gp_Pnt2d ap1(nU1, nV1);
3695 gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface );
3698 if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) {
3700 bIsNearBoundary = Standard_True;
3701 if ( theReachedTol3d < aZoneRadius ) {
3702 theReachedTol3d = aZoneRadius;
3706 // check if a point belong to a tangent zone. End
3707 Standard_Boolean bComputeLineEnd = Standard_False;
3709 if(nbboundaries == 2) {
3711 bComputeLineEnd = Standard_True;
3714 else if(nbboundaries == 1) {
3715 Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3718 Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
3719 Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
3720 Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3721 Standard_Real aParameter = (bIsUBoundary) ? U : V;
3722 Standard_Real anoffset, anAdjustPar;
3723 GeomInt::AdjustPeriodic(aParameter, alowerboundary, aupperboundary,
3724 aPeriod, anAdjustPar, anoffset);
3726 Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
3727 Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
3728 anotherPar += anoffset;
3729 Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3730 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
3731 Standard_Real nU1, nV1;
3734 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3736 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3738 Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
3739 Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
3740 bComputeLineEnd = Standard_True;
3741 Standard_Boolean bCheckAngle1 = Standard_False;
3742 Standard_Boolean bCheckAngle2 = Standard_False;
3744 Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
3745 Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
3747 if(((adist1 - adist2) > Precision::PConfusion()) &&
3748 (adist2 < (aPeriod / 4.))) {
3749 bCheckAngle1 = Standard_True;
3750 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
3752 if(aNewVec.SquareMagnitude() < gp::Resolution()) {
3753 aNewP.SetValue((surfit == 0), anewU, anewV);
3754 bCheckAngle1 = Standard_False;
3757 else if(adist1 < (aPeriod / 4.)) {
3758 bCheckAngle2 = Standard_True;
3759 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
3761 if(aNewVec.SquareMagnitude() < gp::Resolution()) {
3762 bCheckAngle2 = Standard_False;
3766 if(bCheckAngle1 || bCheckAngle2) {
3767 // assume there are at least two points in line (see "if" above)
3768 Standard_Integer anindexother = aneighbourpointindex;
3770 while((anindexother <= iLast) && (anindexother >= iFirst)) {
3771 anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
3772 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
3773 Standard_Real nU2, nV2;
3776 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3778 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3779 gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
3781 if(aVecOld.SquareMagnitude() <= gp::Resolution()) {
3785 Standard_Real anAngle = aNewVec.Angle(aVecOld);
3787 if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
3790 Standard_Real U1, U2, V1, V2;
3791 IntSurf_PntOn2S atmppoint = aNewP;
3792 atmppoint.SetValue((surfit == 0), anewU, anewV);
3793 atmppoint.Parameters(U1, V1, U2, V2);
3794 gp_Pnt P1 = theSurface1->Value(U1, V1);
3795 gp_Pnt P2 = theSurface2->Value(U2, V2);
3796 gp_Pnt P0 = aPoint.Value();
3798 if(P0.IsEqual(P1, aTol) &&
3799 P0.IsEqual(P2, aTol) &&
3800 P1.IsEqual(P2, aTol)) {
3801 bComputeLineEnd = Standard_False;
3802 aNewP.SetValue((surfit == 0), anewU, anewV);
3807 bComputeLineEnd = Standard_False;
3812 } // end while(anindexother...)
3816 else if ( bIsNearBoundary ) {
3817 bComputeLineEnd = Standard_True;
3820 if(bComputeLineEnd) {
3823 Standard_Boolean found = Standard_False;
3825 if ( bIsNearBoundary ) {
3826 // re-compute point near natural boundary or near tangent zone
3827 Standard_Real u1, v1, u2, v2;
3828 aNewP.Parameters( u1, v1, u2, v2 );
3830 anewpoint = gp_Pnt2d( u1, v1 );
3832 anewpoint = gp_Pnt2d( u2, v2 );
3834 Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast;
3835 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3836 Standard_Real nU1, nV1;
3839 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3841 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3842 gp_Pnt2d ap1(nU1, nV1);
3847 // exclude point from a tangent zone
3848 anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3849 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex);
3850 Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex);
3852 if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax,
3853 aPZone, aZoneRadius, aGASurface, ap2) ) {
3855 found = Standard_True;
3858 else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
3859 // re-compute point near boundary if shifted on a period
3860 ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3862 if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
3863 ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
3864 found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
3868 aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
3874 Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast;
3875 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3876 Standard_Real nU1, nV1;
3879 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3881 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3882 gp_Pnt2d ap1(nU1, nV1);
3883 gp_Pnt2d ap2(nU1, nV1);
3884 Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
3886 while((aneighbourpointindex2 <= iLast) && (aneighbourpointindex2 >= iFirst)) {
3887 aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
3888 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
3889 Standard_Real nU2, nV2;
3892 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3894 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3898 if(ap1.SquareDistance(ap2) > gp::Resolution()) {
3902 found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
3907 Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
3908 GeomAPI_ProjectPointOnSurf& aProjector =
3909 (surfit == 0) ? aContext->ProjPS(theFace2) : aContext->ProjPS(theFace1);
3910 Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
3912 Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
3914 gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
3915 aProjector.Perform(aP3d);
3917 if(aProjector.IsDone()) {
3918 if(aProjector.LowerDistance() < aCriteria) {
3919 Standard_Real foundU = U, foundV = V;
3920 aProjector.LowerDistanceParameters(foundU, foundV);
3922 //Correction of projected coordinates. Begin
3923 //Note, it may be shifted on a period
3924 Standard_Integer aneindex1 = (j == 0) ? iFirst : iLast;
3925 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
3926 Standard_Real nUn, nVn;
3929 aNeighbourPoint.ParametersOnS2(nUn, nVn);
3931 aNeighbourPoint.ParametersOnS1(nUn, nVn);
3932 gp_Pnt2d aNeighbour2d(nUn, nVn);
3933 gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
3934 foundU = anAdjustedPoint.X();
3935 foundV = anAdjustedPoint.Y();
3937 if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
3938 ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
3939 // attempt to roughly re-compute point
3940 foundU = ( foundU < umin ) ? umin : foundU;
3941 foundU = ( foundU > umax ) ? umax : foundU;
3942 foundV = ( foundV < vmin ) ? vmin : foundV;
3943 foundV = ( foundV > vmax ) ? vmax : foundV;
3945 GeomAPI_ProjectPointOnSurf& aProjector2 =
3946 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3948 aP3d = aSurfaceOther->Value(foundU, foundV);
3949 aProjector2.Perform(aP3d);
3951 if(aProjector2.IsDone()) {
3952 if(aProjector2.LowerDistance() < aCriteria) {
3953 Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
3954 aProjector2.LowerDistanceParameters(foundU2, foundV2);
3955 anewpoint.SetX(foundU2);
3956 anewpoint.SetY(foundV2);
3960 //Correction of projected coordinates. End
3963 aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
3965 aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
3971 aSeqOfPntOn2S->Add(aNewP);
3972 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
3974 anArrayOfLineEnds.SetValue(i, aListOfFLIndex);
3976 // Correct wlines.end
3978 // Split wlines.begin
3979 Standard_Integer nbiter;
3982 if (!bAvoidLineConstructor) {
3983 nbiter=theLConstructor.NbParts();
3986 for(j = 1; j <= nbiter; ++j) {
3987 Standard_Real fprm, lprm;
3988 Standard_Integer ifprm, ilprm;
3990 if(bAvoidLineConstructor) {
3992 ilprm = theWLine->NbPnts();
3995 theLConstructor.Part(j, fprm, lprm);
3996 ifprm = (Standard_Integer)fprm;
3997 ilprm = (Standard_Integer)lprm;
4000 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
4002 for(i = 1; i <= nblines; i++) {
4003 if(anArrayOfLineType.Value(i) != 0) {
4006 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
4007 const TColStd_ListOfInteger& aListOfFLIndex = anArrayOfLineEnds.Value(i);
4008 Standard_Boolean bhasfirstpoint = (aListOfFLIndex.Extent() == 2);
4009 Standard_Boolean bhaslastpoint = (aListOfFLIndex.Extent() == 2);
4011 if(!bhasfirstpoint && !aListOfFLIndex.IsEmpty()) {
4012 bhasfirstpoint = (i != 1);
4015 if(!bhaslastpoint && !aListOfFLIndex.IsEmpty()) {
4016 bhaslastpoint = (i != nblines);
4019 Standard_Integer iFirst = aListOfIndex.First();
4020 Standard_Integer iLast = aListOfIndex.Last();
4021 Standard_Boolean bIsFirstInside = ((ifprm >= iFirst) && (ifprm <= iLast));
4022 Standard_Boolean bIsLastInside = ((ilprm >= iFirst) && (ilprm <= iLast));
4024 if(!bIsFirstInside && !bIsLastInside) {
4025 if((ifprm < iFirst) && (ilprm > iLast)) {
4026 // append whole line, and boundaries if neccesary
4027 if(bhasfirstpoint) {
4028 pit = aListOfFLIndex.First();
4029 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4032 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4034 for(; anIt.More(); anIt.Next()) {
4036 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4041 pit = aListOfFLIndex.Last();
4042 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4046 // check end of split line (end is almost always)
4047 Standard_Integer aneighbour = i + 1;
4048 Standard_Boolean bIsEndOfLine = Standard_True;
4050 if(aneighbour <= nblines) {
4051 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4053 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4054 (aListOfNeighbourIndex.IsEmpty())) {
4055 bIsEndOfLine = Standard_False;
4060 if(aLineOn2S->NbPoints() > 1) {
4061 Handle(IntPatch_WLine) aNewWLine =
4062 new IntPatch_WLine(aLineOn2S, Standard_False);
4063 theNewLines.Append(aNewWLine);
4065 aLineOn2S = new IntSurf_LineOn2S();
4070 // end if(!bIsFirstInside && !bIsLastInside)
4072 if(bIsFirstInside && bIsLastInside) {
4073 // append inside points between ifprm and ilprm
4074 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4076 for(; anIt.More(); anIt.Next()) {
4078 if((pit < ifprm) || (pit > ilprm))
4080 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4086 if(bIsFirstInside) {
4087 // append points from ifprm to last point + boundary point
4088 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4090 for(; anIt.More(); anIt.Next()) {
4094 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4099 pit = aListOfFLIndex.Last();
4100 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4103 // check end of split line (end is almost always)
4104 Standard_Integer aneighbour = i + 1;
4105 Standard_Boolean bIsEndOfLine = Standard_True;
4107 if(aneighbour <= nblines) {
4108 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4110 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4111 (aListOfNeighbourIndex.IsEmpty())) {
4112 bIsEndOfLine = Standard_False;
4117 if(aLineOn2S->NbPoints() > 1) {
4118 Handle(IntPatch_WLine) aNewWLine =
4119 new IntPatch_WLine(aLineOn2S, Standard_False);
4120 theNewLines.Append(aNewWLine);
4122 aLineOn2S = new IntSurf_LineOn2S();
4125 // end if(bIsFirstInside)
4128 // append points from first boundary point to ilprm
4129 if(bhasfirstpoint) {
4130 pit = aListOfFLIndex.First();
4131 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4134 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4136 for(; anIt.More(); anIt.Next()) {
4140 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4144 //end if(bIsLastInside)
4148 if(aLineOn2S->NbPoints() > 1) {
4149 Handle(IntPatch_WLine) aNewWLine =
4150 new IntPatch_WLine(aLineOn2S, Standard_False);
4151 theNewLines.Append(aNewWLine);
4156 return Standard_True;
4159 // ------------------------------------------------------------------------------------------------
4160 // static function: ParameterOutOfBoundary
4161 // purpose: Computes a new parameter for given curve. The corresponding 2d points
4162 // does not lay on any boundary of given faces
4163 // ------------------------------------------------------------------------------------------------
4164 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
4165 const Handle(Geom_Curve)& theCurve,
4166 const TopoDS_Face& theFace1,
4167 const TopoDS_Face& theFace2,
4168 const Standard_Real theOtherParameter,
4169 const Standard_Boolean bIncreasePar,
4170 Standard_Real& theNewParameter,
4171 const Handle(IntTools_Context)& aContext)
4173 Standard_Boolean bIsComputed = Standard_False;
4174 theNewParameter = theParameter;
4176 Standard_Real acurpar = theParameter;
4177 TopAbs_State aState = TopAbs_ON;
4178 Standard_Integer iter = 0;
4179 Standard_Real asumtol = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4180 Standard_Real adelta = asumtol * 0.1;
4181 adelta = (adelta < Precision::Confusion()) ? Precision::Confusion() : adelta;
4182 Handle(Geom_Surface) aSurf1 = BRep_Tool::Surface(theFace1);
4183 Handle(Geom_Surface) aSurf2 = BRep_Tool::Surface(theFace2);
4185 Standard_Real u1, u2, v1, v2;
4187 GeomAPI_ProjectPointOnSurf aPrj1;
4188 aSurf1->Bounds(u1, u2, v1, v2);
4189 aPrj1.Init(aSurf1, u1, u2, v1, v2);
4191 GeomAPI_ProjectPointOnSurf aPrj2;
4192 aSurf2->Bounds(u1, u2, v1, v2);
4193 aPrj2.Init(aSurf2, u1, u2, v1, v2);
4195 while(aState == TopAbs_ON) {
4200 gp_Pnt aPCurrent = theCurve->Value(acurpar);
4201 aPrj1.Perform(aPCurrent);
4202 Standard_Real U=0., V=0.;
4204 if(aPrj1.IsDone()) {
4205 aPrj1.LowerDistanceParameters(U, V);
4206 aState = aContext->StatePointFace(theFace1, gp_Pnt2d(U, V));
4209 if(aState != TopAbs_ON) {
4210 aPrj2.Perform(aPCurrent);
4212 if(aPrj2.IsDone()) {
4213 aPrj2.LowerDistanceParameters(U, V);
4214 aState = aContext->StatePointFace(theFace2, gp_Pnt2d(U, V));
4225 theNewParameter = acurpar;
4226 bIsComputed = Standard_True;
4229 if(acurpar >= theOtherParameter)
4230 theNewParameter = theOtherParameter;
4233 if(acurpar <= theOtherParameter)
4234 theNewParameter = theOtherParameter;
4240 //=======================================================================
4241 //function : IsCurveValid
4243 //=======================================================================
4244 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve)
4246 if(thePCurve.IsNull())
4247 return Standard_False;
4249 Standard_Real tolint = 1.e-10;
4250 Geom2dAdaptor_Curve PCA;
4251 IntRes2d_Domain PCD;
4252 Geom2dInt_GInter PCI;
4254 Standard_Real pf = 0., pl = 0.;
4255 gp_Pnt2d pntf, pntl;
4257 if(!thePCurve->IsClosed() && !thePCurve->IsPeriodic()) {
4258 pf = thePCurve->FirstParameter();
4259 pl = thePCurve->LastParameter();
4260 pntf = thePCurve->Value(pf);
4261 pntl = thePCurve->Value(pl);
4262 PCA.Load(thePCurve);
4263 if(!PCA.IsPeriodic()) {
4264 if(PCA.FirstParameter() > pf) pf = PCA.FirstParameter();
4265 if(PCA.LastParameter() < pl) pl = PCA.LastParameter();
4267 PCD.SetValues(pntf,pf,tolint,pntl,pl,tolint);
4268 PCI.Perform(PCA,PCD,tolint,tolint);
4270 if(PCI.NbPoints() > 0) {
4271 return Standard_False;
4275 return Standard_True;
4278 //=======================================================================
4279 //static function : ApproxWithPCurves
4280 //purpose : for bug 20964 only
4281 //=======================================================================
4282 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
4283 const gp_Sphere& theSph)
4285 Standard_Boolean bRes = Standard_True;
4286 Standard_Real R1 = theCyl.Radius(), R2 = theSph.Radius();
4289 Standard_Real aD2, aRc2, aEps;
4295 const gp_Ax3& aAx3Sph=theSph.Position();
4296 const gp_Pnt& aLocSph=aAx3Sph.Location();
4297 const gp_Dir& aDirSph=aAx3Sph.Direction();
4299 const gp_Ax1& aAx1Cyl=theCyl.Axis();
4300 gp_Lin aLinCyl(aAx1Cyl);
4302 aApexSph.SetXYZ(aLocSph.XYZ()+R2*aDirSph.XYZ());
4303 aD2=aLinCyl.SquareDistance(aApexSph);
4304 if (fabs(aD2-aRc2)<aEps) {
4308 aApexSph.SetXYZ(aLocSph.XYZ()-R2*aDirSph.XYZ());
4309 aD2=aLinCyl.SquareDistance(aApexSph);
4310 if (fabs(aD2-aRc2)<aEps) {
4319 gp_Lin anCylAx(theCyl.Axis());
4321 Standard_Real aDist = anCylAx.Distance(theSph.Location());
4322 Standard_Real aDRel = Abs(aDist - R1)/R2;
4324 if(aDRel > .2) return bRes;
4326 Standard_Real par = ElCLib::Parameter(anCylAx, theSph.Location());
4327 gp_Pnt aP = ElCLib::Value(par, anCylAx);
4328 gp_Vec aV(aP, theSph.Location());
4330 Standard_Real dd = aV.Dot(theSph.Position().XDirection());
4332 if(aDist < R1 && dd > 0.) return Standard_False;
4333 if(aDist > R1 && dd < 0.) return Standard_False;
4338 //=======================================================================
4339 //function : PerformPlanes
4341 //=======================================================================
4342 void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
4343 const Handle(GeomAdaptor_HSurface)& theS2,
4344 const Standard_Real TolAng,
4345 const Standard_Real TolTang,
4346 const Standard_Boolean theApprox1,
4347 const Standard_Boolean theApprox2,
4348 IntTools_SequenceOfCurves& theSeqOfCurve,
4349 Standard_Boolean& theTangentFaces)
4352 gp_Pln aPln1 = theS1->Surface().Plane();
4353 gp_Pln aPln2 = theS2->Surface().Plane();
4355 IntAna_QuadQuadGeo aPlnInter(aPln1, aPln2, TolAng, TolTang);
4357 if(!aPlnInter.IsDone()) {
4358 theTangentFaces = Standard_False;
4362 IntAna_ResultType aResType = aPlnInter.TypeInter();
4364 if(aResType == IntAna_Same) {
4365 theTangentFaces = Standard_True;
4369 theTangentFaces = Standard_False;
4371 if(aResType == IntAna_Empty) {
4375 gp_Lin aLin = aPlnInter.Line(1);
4377 ProjLib_Plane aProj;
4380 aProj.Project(aLin);
4381 gp_Lin2d aLin2d1 = aProj.Line();
4384 aProj.Project(aLin);
4385 gp_Lin2d aLin2d2 = aProj.Line();
4387 //classify line2d1 relatively first plane
4388 Standard_Real P11, P12;
4389 Standard_Boolean IsCrossed = ClassifyLin2d(theS1, aLin2d1, TolTang, P11, P12);
4390 if(!IsCrossed) return;
4391 //classify line2d2 relatively second plane
4392 Standard_Real P21, P22;
4393 IsCrossed = ClassifyLin2d(theS2, aLin2d2, TolTang, P21, P22);
4394 if(!IsCrossed) return;
4396 //Analysis of parametric intervals: must have common part
4398 if(P21 >= P12) return;
4399 if(P22 <= P11) return;
4401 Standard_Real pmin, pmax;
4402 pmin = Max(P11, P21);
4403 pmax = Min(P12, P22);
4405 if(pmax - pmin <= TolTang) return;
4407 Handle(Geom_Line) aGLin = new Geom_Line(aLin);
4409 IntTools_Curve aCurve;
4410 Handle(Geom_TrimmedCurve) aGTLin = new Geom_TrimmedCurve(aGLin, pmin, pmax);
4412 aCurve.SetCurve(aGTLin);
4415 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d1);
4416 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4419 Handle(Geom2d_Curve) H1;
4420 aCurve.SetFirstCurve2d(H1);
4423 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d2);
4424 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4427 Handle(Geom2d_Curve) H1;
4428 aCurve.SetFirstCurve2d(H1);
4431 theSeqOfCurve.Append(aCurve);
4435 //=======================================================================
4436 //function : ClassifyLin2d
4438 //=======================================================================
4439 static inline Standard_Boolean INTER(const Standard_Real d1,
4440 const Standard_Real d2,
4441 const Standard_Real tol)
4443 return (d1 > tol && d2 < -tol) ||
4444 (d1 < -tol && d2 > tol) ||
4445 ((d1 <= tol && d1 >= -tol) && (d2 > tol || d2 < -tol)) ||
4446 ((d2 <= tol && d2 >= -tol) && (d1 > tol || d1 < -tol));
4448 static inline Standard_Boolean COINC(const Standard_Real d1,
4449 const Standard_Real d2,
4450 const Standard_Real tol)
4452 return (d1 <= tol && d1 >= -tol) && (d2 <= tol && d2 >= -tol);
4454 Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
4455 const gp_Lin2d& theLin2d,
4456 const Standard_Real theTol,
4457 Standard_Real& theP1,
4458 Standard_Real& theP2)
4461 Standard_Real xmin, xmax, ymin, ymax, d1, d2, A, B, C;
4462 Standard_Real par[2];
4463 Standard_Integer nbi = 0;
4465 xmin = theS->Surface().FirstUParameter();
4466 xmax = theS->Surface().LastUParameter();
4467 ymin = theS->Surface().FirstVParameter();
4468 ymax = theS->Surface().LastVParameter();
4470 theLin2d.Coefficients(A, B, C);
4472 //xmin, ymin <-> xmin, ymax
4473 d1 = A*xmin + B*ymin + C;
4474 d2 = A*xmin + B*ymax + C;
4476 if(INTER(d1, d2, theTol)) {
4477 //Intersection with boundary
4478 Standard_Real y = -(C + A*xmin)/B;
4479 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, y));
4482 else if (COINC(d1, d2, theTol)) {
4483 //Coincidence with boundary
4484 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4485 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4491 if(fabs(par[0]-par[1]) > theTol) {
4492 theP1 = Min(par[0], par[1]);
4493 theP2 = Max(par[0], par[1]);
4494 return Standard_True;
4496 else return Standard_False;
4500 //xmin, ymax <-> xmax, ymax
4502 d2 = A*xmax + B*ymax + C;
4504 if(d1 > theTol || d1 < -theTol) {//to avoid checking of
4505 //coincidence with the same point
4506 if(INTER(d1, d2, theTol)) {
4507 Standard_Real x = -(C + B*ymax)/A;
4508 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymax));
4511 else if (COINC(d1, d2, theTol)) {
4512 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4513 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4520 if(fabs(par[0]-par[1]) > theTol) {
4521 theP1 = Min(par[0], par[1]);
4522 theP2 = Max(par[0], par[1]);
4523 return Standard_True;
4525 else return Standard_False;
4529 //xmax, ymax <-> xmax, ymin
4531 d2 = A*xmax + B*ymin + C;
4533 if(d1 > theTol || d1 < -theTol) {
4534 if(INTER(d1, d2, theTol)) {
4535 Standard_Real y = -(C + A*xmax)/B;
4536 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, y));
4539 else if (COINC(d1, d2, theTol)) {
4540 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4541 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4547 if(fabs(par[0]-par[1]) > theTol) {
4548 theP1 = Min(par[0], par[1]);
4549 theP2 = Max(par[0], par[1]);
4550 return Standard_True;
4552 else return Standard_False;
4555 //xmax, ymin <-> xmin, ymin
4557 d2 = A*xmin + B*ymin + C;
4559 if(d1 > theTol || d1 < -theTol) {
4560 if(INTER(d1, d2, theTol)) {
4561 Standard_Real x = -(C + B*ymin)/A;
4562 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymin));
4565 else if (COINC(d1, d2, theTol)) {
4566 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4567 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4573 if(fabs(par[0]-par[1]) > theTol) {
4574 theP1 = Min(par[0], par[1]);
4575 theP2 = Max(par[0], par[1]);
4576 return Standard_True;
4578 else return Standard_False;
4581 return Standard_False;
4585 //=======================================================================
4586 //function : ApproxParameters
4588 //=======================================================================
4589 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
4590 const Handle(GeomAdaptor_HSurface)& aHS2,
4591 Standard_Integer& iDegMin,
4592 Standard_Integer& iDegMax,
4593 Standard_Integer& iNbIter)
4596 GeomAbs_SurfaceType aTS1, aTS2;
4603 aTS1=aHS1->Surface().GetType();
4604 aTS2=aHS2->Surface().GetType();
4607 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4608 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4609 Standard_Real aRC, aRT, dR, aPC;
4610 gp_Cylinder aCylinder;
4613 aPC=Precision::Confusion();
4615 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4616 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4618 aRC=aCylinder.Radius();
4619 aRT=aTorus.MinorRadius();
4629 if (aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Cylinder) {
4633 //=======================================================================
4634 //function : Tolerances
4636 //=======================================================================
4637 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
4638 const Handle(GeomAdaptor_HSurface)& aHS2,
4639 Standard_Real& aTolTang)
4641 GeomAbs_SurfaceType aTS1, aTS2;
4643 aTS1=aHS1->Surface().GetType();
4644 aTS2=aHS2->Surface().GetType();
4647 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4648 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4649 Standard_Real aRC, aRT, dR, aPC;
4650 gp_Cylinder aCylinder;
4653 aPC=Precision::Confusion();
4655 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4656 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4658 aRC=aCylinder.Radius();
4659 aRT=aTorus.MinorRadius();
4666 aTolTang=0.1*aTolTang;
4670 //=======================================================================
4671 //function : SortTypes
4673 //=======================================================================
4674 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
4675 const GeomAbs_SurfaceType aType2)
4677 Standard_Boolean bRet;
4678 Standard_Integer aI1, aI2;
4680 bRet=Standard_False;
4682 aI1=IndexType(aType1);
4683 aI2=IndexType(aType2);
4689 //=======================================================================
4690 //function : IndexType
4692 //=======================================================================
4693 Standard_Integer IndexType(const GeomAbs_SurfaceType aType)
4695 Standard_Integer aIndex;
4699 if (aType==GeomAbs_Plane) {
4702 else if (aType==GeomAbs_Cylinder) {
4705 else if (aType==GeomAbs_Cone) {
4708 else if (aType==GeomAbs_Sphere) {
4711 else if (aType==GeomAbs_Torus) {
4714 else if (aType==GeomAbs_BezierSurface) {
4717 else if (aType==GeomAbs_BSplineSurface) {
4720 else if (aType==GeomAbs_SurfaceOfRevolution) {
4723 else if (aType==GeomAbs_SurfaceOfExtrusion) {
4726 else if (aType==GeomAbs_OffsetSurface) {
4729 else if (aType==GeomAbs_OtherSurface) {
4734 #ifdef OCCT_DEBUG_DUMPWLINE
4735 //=======================================================================
4736 //function : DumpWLine
4738 //=======================================================================
4739 void DumpWLine(const Handle(IntPatch_WLine)& aWLine)
4741 Standard_Integer i, aNbPnts;
4742 Standard_Real aX, aY, aZ, aU1, aV1, aU2, aV2;
4744 printf(" *WLine\n");
4745 aNbPnts=aWLine->NbPnts();
4746 for (i=1; i<=aNbPnts; ++i) {
4747 const IntSurf_PntOn2S aPntOn2S=aWLine->Point(i);
4748 const gp_Pnt& aP3D=aPntOn2S.Value();
4749 aP3D.Coord(aX, aY, aZ);
4750 aPntOn2S.Parameters(aU1, aV1, aU2, aV2);
4752 printf("point p_%d %lf %lf %lf\n", i, aX, aY, aZ);
4753 //printf("point p_%d %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf\n",
4754 // i, aX, aY, aZ, aU1, aV1, aU2, aV2);
4758 //=======================================================================
4759 //function : RefineVector
4761 //=======================================================================
4762 void RefineVector(gp_Vec2d& aV2D)
4764 Standard_Integer k,m;
4765 Standard_Real aC[2], aEps, aR1, aR2, aNum;
4771 aV2D.Coord(aC[0], aC[1]);
4773 for (k=0; k<2; ++k) {
4776 if (aNum>aR1 && aNum<aR2) {
4787 aV2D.SetCoord(aC[0], aC[1]);
4789 //=======================================================================
4790 // Function : FindMaxDistance
4792 //=======================================================================
4793 Standard_Real FindMaxDistance(const Handle(Geom_Curve)& theCurve,
4794 const Standard_Real theFirst,
4795 const Standard_Real theLast,
4796 const TopoDS_Face& theFace,
4797 const Handle(IntTools_Context)& theContext)
4799 Standard_Integer aNbS;
4800 Standard_Real aT1, aT2, aDt, aD, aDMax, anEps;
4803 aDt = (theLast - theFirst) / aNbS;
4805 anEps = 1.e-4 * aDt;
4807 GeomAPI_ProjectPointOnSurf& aProjPS = theContext->ProjPS(theFace);
4813 if (aT2 > theLast) {
4817 aD = FindMaxDistance(theCurve, aT1, aT2, aProjPS, anEps);
4825 //=======================================================================
4826 // Function : FindMaxDistance
4828 //=======================================================================
4829 Standard_Real FindMaxDistance(const Handle(Geom_Curve)& theC,
4830 const Standard_Real theFirst,
4831 const Standard_Real theLast,
4832 GeomAPI_ProjectPointOnSurf& theProjPS,
4833 const Standard_Real theEps)
4835 Standard_Real aA, aB, aCf, aX, aX1, aX2, aF1, aF2, aF;
4837 aCf = 0.61803398874989484820458683436564;//(sqrt(5.)-1)/2.;
4841 aX1 = aB - aCf * (aB - aA);
4842 aF1 = MaxDistance(theC, aX1, theProjPS);
4843 aX2 = aA + aCf * (aB - aA);
4844 aF2 = MaxDistance(theC, aX2, theProjPS);
4847 if ((aB - aA) < theEps) {
4855 aX1 = aB - aCf * (aB - aA);
4856 aF1 = MaxDistance(theC, aX1, theProjPS);
4862 aX2 = aA + aCf * (aB - aA);
4863 aF2 = MaxDistance(theC, aX2, theProjPS);
4867 aX = 0.5 * (aA + aB);
4868 aF = MaxDistance(theC, aX, theProjPS);
4880 //=======================================================================
4881 // Function : MaxDistance
4883 //=======================================================================
4884 Standard_Real MaxDistance(const Handle(Geom_Curve)& theC,
4885 const Standard_Real aT,
4886 GeomAPI_ProjectPointOnSurf& theProjPS)
4892 theProjPS.Perform(aP);
4893 aD = theProjPS.NbPoints() ? theProjPS.LowerDistance() : 0.;
4898 //=======================================================================
4899 //function : CheckPCurve
4900 //purpose : Checks if points of the pcurve are out of the face bounds.
4901 //=======================================================================
4902 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
4903 const TopoDS_Face& aFace)
4905 const Standard_Integer NPoints = 23;
4907 Standard_Real umin,umax,vmin,vmax;
4909 BRepTools::UVBounds(aFace, umin, umax, vmin, vmax);
4910 Standard_Real tolU = Max ((umax-umin)*0.01, Precision::Confusion());
4911 Standard_Real tolV = Max ((vmax-vmin)*0.01, Precision::Confusion());
4912 Standard_Real fp = aPC->FirstParameter();
4913 Standard_Real lp = aPC->LastParameter();
4916 // adjust domain for periodic surfaces
4917 TopLoc_Location aLoc;
4918 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc);
4919 if (aSurf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
4920 aSurf = (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf))->BasisSurface();
4922 gp_Pnt2d pnt = aPC->Value((fp+lp)/2);
4926 if (aSurf->IsUPeriodic()) {
4927 Standard_Real aPer = aSurf->UPeriod();
4928 Standard_Integer nshift = (Standard_Integer) ((u-umin)/aPer);
4929 if (u < umin+aPer*nshift) nshift--;
4930 umin += aPer*nshift;
4931 umax += aPer*nshift;
4933 if (aSurf->IsVPeriodic()) {
4934 Standard_Real aPer = aSurf->VPeriod();
4935 Standard_Integer nshift = (Standard_Integer) ((v-vmin)/aPer);
4936 if (v < vmin+aPer*nshift) nshift--;
4937 vmin += aPer*nshift;
4938 vmax += aPer*nshift;
4941 //--------------------------------------------------------
4942 Standard_Boolean bRet;
4943 Standard_Integer j, aNbIntervals;
4944 Standard_Real aT, dT;
4947 Geom2dAdaptor_Curve aGAC(aPC);
4948 aNbIntervals=aGAC.NbIntervals(GeomAbs_CN);
4950 TColStd_Array1OfReal aTI(1, aNbIntervals+1);
4951 aGAC.Intervals(aTI,GeomAbs_CN);
4953 bRet=Standard_False;
4955 aT=aGAC.FirstParameter();
4956 for (j=1; j<=aNbIntervals; ++j) {
4957 dT=(aTI(j+1)-aTI(j))/NPoints;
4959 for (i=1; i<NPoints; i++) {
4963 if (umin-u > tolU || u-umax > tolU ||
4964 vmin-v > tolV || v-vmax > tolV) {
4971 //=======================================================================
4972 //function : CorrectPlaneBoundaries
4974 //=======================================================================
4975 void CorrectPlaneBoundaries(Standard_Real& aUmin,
4976 Standard_Real& aUmax,
4977 Standard_Real& aVmin,
4978 Standard_Real& aVmax)
4980 if (!(Precision::IsInfinite(aUmin) ||
4981 Precision::IsInfinite(aUmax))) {
4984 dU=0.1*(aUmax-aUmin);
4988 if (!(Precision::IsInfinite(aVmin) ||
4989 Precision::IsInfinite(aVmax))) {
4992 dV=0.1*(aVmax-aVmin);