1 // Created on: 2000-11-23
2 // Created by: Michael KLOKOV
3 // Copyright (c) 2000-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
22 #include <IntTools_FaceFace.ixx>
24 #include <Precision.hxx>
26 #include <TColStd_HArray1OfReal.hxx>
27 #include <TColStd_Array1OfReal.hxx>
28 #include <TColStd_Array1OfInteger.hxx>
29 #include <TColStd_SequenceOfReal.hxx>
30 #include <TColStd_ListOfInteger.hxx>
31 #include <TColStd_ListIteratorOfListOfInteger.hxx>
32 #include <TColStd_Array1OfListOfInteger.hxx>
34 #include <gp_Lin2d.hxx>
35 #include <gp_Ax22d.hxx>
36 #include <gp_Circ2d.hxx>
37 #include <gp_Torus.hxx>
38 #include <gp_Cylinder.hxx>
40 #include <Bnd_Box.hxx>
42 #include <TColgp_HArray1OfPnt2d.hxx>
43 #include <TColgp_SequenceOfPnt2d.hxx>
44 #include <TColgp_Array1OfPnt.hxx>
45 #include <TColgp_Array1OfPnt2d.hxx>
47 #include <IntAna_QuadQuadGeo.hxx>
49 #include <IntSurf_PntOn2S.hxx>
50 #include <IntSurf_LineOn2S.hxx>
51 #include <IntSurf_PntOn2S.hxx>
52 #include <IntSurf_ListOfPntOn2S.hxx>
53 #include <IntRes2d_Domain.hxx>
54 #include <ProjLib_Plane.hxx>
56 #include <IntPatch_GLine.hxx>
57 #include <IntPatch_RLine.hxx>
58 #include <IntPatch_WLine.hxx>
59 #include <IntPatch_ALine.hxx>
60 #include <IntPatch_ALineToWLine.hxx>
65 #include <Extrema_ExtCC.hxx>
66 #include <Extrema_POnCurv.hxx>
67 #include <BndLib_AddSurface.hxx>
69 #include <Adaptor3d_SurfacePtr.hxx>
70 #include <Adaptor2d_HLine2d.hxx>
72 #include <GeomAbs_SurfaceType.hxx>
73 #include <GeomAbs_CurveType.hxx>
75 #include <Geom_Surface.hxx>
76 #include <Geom_Line.hxx>
77 #include <Geom_Circle.hxx>
78 #include <Geom_Ellipse.hxx>
79 #include <Geom_Parabola.hxx>
80 #include <Geom_Hyperbola.hxx>
81 #include <Geom_TrimmedCurve.hxx>
82 #include <Geom_BSplineCurve.hxx>
83 #include <Geom_RectangularTrimmedSurface.hxx>
84 #include <Geom_OffsetSurface.hxx>
85 #include <Geom_Curve.hxx>
86 #include <Geom_Conic.hxx>
88 #include <Geom2d_TrimmedCurve.hxx>
89 #include <Geom2d_BSplineCurve.hxx>
90 #include <Geom2d_Line.hxx>
91 #include <Geom2d_Curve.hxx>
92 #include <Geom2d_Circle.hxx>
94 #include <Geom2dAPI_InterCurveCurve.hxx>
95 #include <Geom2dInt_GInter.hxx>
96 #include <GeomAdaptor_Curve.hxx>
97 #include <GeomAdaptor_HSurface.hxx>
98 #include <GeomAdaptor_Surface.hxx>
99 #include <GeomLib_CheckBSplineCurve.hxx>
100 #include <GeomLib_Check2dBSplineCurve.hxx>
102 #include <GeomInt_WLApprox.hxx>
103 #include <GeomProjLib.hxx>
104 #include <GeomAPI_ProjectPointOnSurf.hxx>
105 #include <Geom2dAdaptor_Curve.hxx>
106 #include <TopoDS.hxx>
107 #include <TopoDS_Edge.hxx>
108 #include <TopExp_Explorer.hxx>
110 #include <BRep_Tool.hxx>
111 #include <BRepTools.hxx>
112 #include <BRepAdaptor_Surface.hxx>
114 #include <IntTools_Curve.hxx>
115 #include <IntTools_Tools.hxx>
116 #include <IntTools_Tools.hxx>
117 #include <IntTools_TopolTool.hxx>
118 #include <IntTools_PntOnFace.hxx>
119 #include <IntTools_PntOn2Faces.hxx>
120 #include <BOPInt_Context.hxx>
121 #include <IntSurf_ListIteratorOfListOfPntOn2S.hxx>
124 void RefineVector(gp_Vec2d& aV2D);
127 void DumpWLine(const Handle(IntPatch_WLine)& aWLine);
131 void TolR3d(const TopoDS_Face& ,
135 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)&,
136 const Standard_Integer,
137 const Standard_Integer);
140 void Parameters(const Handle(GeomAdaptor_HSurface)&,
141 const Handle(GeomAdaptor_HSurface)&,
149 void BuildPCurves (Standard_Real f,Standard_Real l,Standard_Real& Tol,
150 const Handle (Geom_Surface)& S,
151 const Handle (Geom_Curve)& C,
152 Handle (Geom2d_Curve)& C2d);
155 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
156 const Standard_Real theTolerance,
157 Standard_Real& theumin,
158 Standard_Real& theumax,
159 Standard_Real& thevmin,
160 Standard_Real& thevmax);
162 Standard_Boolean NotUseSurfacesForApprox
163 (const TopoDS_Face& aF1,
164 const TopoDS_Face& aF2,
165 const Handle(IntPatch_WLine)& WL,
166 const Standard_Integer ifprm,
167 const Standard_Integer ilprm);
170 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine);
173 Standard_Real AdjustPeriodic(const Standard_Real theParameter,
174 const Standard_Real parmin,
175 const Standard_Real parmax,
176 const Standard_Real thePeriod,
177 Standard_Real& theOffset);
180 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
181 const Standard_Integer ideb,
182 const Standard_Integer ifin,
183 const Standard_Boolean onFirst);
186 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
187 const Handle(GeomAdaptor_HSurface)& theSurface1,
188 const Handle(GeomAdaptor_HSurface)& theSurface2,
189 const TopoDS_Face& theFace1,
190 const TopoDS_Face& theFace2,
191 const IntTools_LineConstructor& theLConstructor,
192 const Standard_Boolean theAvoidLConstructor,
193 IntPatch_SequenceOfLine& theNewLines,
194 Standard_Real& theReachedTol3d,
195 const Handle(BOPInt_Context)& );
198 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
199 const Handle(Geom_Curve)& theCurve,
200 const TopoDS_Face& theFace1,
201 const TopoDS_Face& theFace2,
202 const Standard_Real theOtherParameter,
203 const Standard_Boolean bIncreasePar,
204 Standard_Real& theNewParameter,
205 const Handle(BOPInt_Context)& );
208 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve);
211 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
212 const Standard_Real theFirstBoundary,
213 const Standard_Real theSecondBoundary,
214 const Standard_Real theResolution,
215 Standard_Boolean& IsOnFirstBoundary);
217 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
218 const gp_Pnt2d& theLastPoint,
219 const Standard_Real theUmin,
220 const Standard_Real theUmax,
221 const Standard_Real theVmin,
222 const Standard_Real theVmax,
223 gp_Pnt2d& theNewPoint);
227 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
228 const Handle(GeomAdaptor_HSurface)& theSurface2,
229 const TopoDS_Face& theFace1,
230 const TopoDS_Face& theFace2,
231 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
232 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
233 Handle(TColStd_HArray1OfReal)& theResultRadius,
234 const Handle(BOPInt_Context)& );
237 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
238 const gp_Pnt2d& theLastPoint,
239 const Standard_Real theUmin,
240 const Standard_Real theUmax,
241 const Standard_Real theVmin,
242 const Standard_Real theVmax,
243 const gp_Pnt2d& theTanZoneCenter,
244 const Standard_Real theZoneRadius,
245 Handle(GeomAdaptor_HSurface) theGASurface,
246 gp_Pnt2d& theNewPoint);
249 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
250 const gp_Pnt2d& theTanZoneCenter,
251 const Standard_Real theZoneRadius,
252 Handle(GeomAdaptor_HSurface) theGASurface);
255 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
256 const gp_Pnt2d& theOriginalPoint,
257 Handle(GeomAdaptor_HSurface) theGASurface);
259 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
260 const gp_Sphere& theSph);
262 static void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
263 const Handle(GeomAdaptor_HSurface)& theS2,
264 const Standard_Real TolAng,
265 const Standard_Real TolTang,
266 const Standard_Boolean theApprox1,
267 const Standard_Boolean theApprox2,
268 IntTools_SequenceOfCurves& theSeqOfCurve,
269 Standard_Boolean& theTangentFaces);
271 static Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
272 const gp_Lin2d& theLin2d,
273 const Standard_Real theTol,
274 Standard_Real& theP1,
275 Standard_Real& theP2);
278 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
279 const Handle(GeomAdaptor_HSurface)& aHS2,
280 Standard_Integer& iDegMin,
281 Standard_Integer& iNbIter,
282 Standard_Integer& iDegMax);
285 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
286 const Handle(GeomAdaptor_HSurface)& aHS2,
287 Standard_Real& aTolTang);
290 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
291 const GeomAbs_SurfaceType aType2);
293 Standard_Integer IndexType(const GeomAbs_SurfaceType aType);
297 Standard_Real MaxSquareDistance (const Standard_Real aT,
298 const Handle(Geom_Curve)& aC3D,
299 const Handle(Geom2d_Curve)& aC2D1,
300 const Handle(Geom2d_Curve)& aC2D2,
301 const Handle(GeomAdaptor_HSurface) myHS1,
302 const Handle(GeomAdaptor_HSurface) myHS2,
303 const TopoDS_Face& aF1,
304 const TopoDS_Face& aF2,
305 const Handle(BOPInt_Context)& aCtx);
308 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
309 const TopoDS_Face& aFace);
313 Standard_Real FindMaxSquareDistance (const Standard_Real aA,
314 const Standard_Real aB,
315 const Standard_Real aEps,
316 const Handle(Geom_Curve)& aC3D,
317 const Handle(Geom2d_Curve)& aC2D1,
318 const Handle(Geom2d_Curve)& aC2D2,
319 const Handle(GeomAdaptor_HSurface)& myHS1,
320 const Handle(GeomAdaptor_HSurface)& myHS2,
321 const TopoDS_Face& aF1,
322 const TopoDS_Face& aF2,
323 const Handle(BOPInt_Context)& aCtx);
325 //=======================================================================
328 //=======================================================================
329 IntTools_FaceFace::IntTools_FaceFace()
331 myIsDone=Standard_False;
332 myTangentFaces=Standard_False;
334 myHS1 = new GeomAdaptor_HSurface ();
335 myHS2 = new GeomAdaptor_HSurface ();
338 SetParameters(Standard_True, Standard_True, Standard_True, 1.e-07);
341 //=======================================================================
342 //function : SetContext
344 //=======================================================================
345 void IntTools_FaceFace::SetContext(const Handle(BOPInt_Context)& aContext)
349 //=======================================================================
352 //=======================================================================
353 const Handle(BOPInt_Context)& IntTools_FaceFace::Context()const
357 //=======================================================================
360 //=======================================================================
361 const TopoDS_Face& IntTools_FaceFace::Face1() const
365 //=======================================================================
368 //=======================================================================
369 const TopoDS_Face& IntTools_FaceFace::Face2() const
373 //=======================================================================
374 //function : TangentFaces
376 //=======================================================================
377 Standard_Boolean IntTools_FaceFace::TangentFaces() const
379 return myTangentFaces;
381 //=======================================================================
384 //=======================================================================
385 const IntTools_SequenceOfPntOn2Faces& IntTools_FaceFace::Points() const
389 //=======================================================================
392 //=======================================================================
393 Standard_Boolean IntTools_FaceFace::IsDone() const
397 //=======================================================================
398 //function : TolReached3d
400 //=======================================================================
401 Standard_Real IntTools_FaceFace::TolReached3d() const
403 return myTolReached3d;
405 //=======================================================================
407 //purpose : return lines of intersection
408 //=======================================================================
409 const IntTools_SequenceOfCurves& IntTools_FaceFace::Lines() const
411 StdFail_NotDone_Raise_if
413 "IntTools_FaceFace::Lines() => myIntersector NOT DONE");
416 //=======================================================================
417 //function : TolReached2d
419 //=======================================================================
420 Standard_Real IntTools_FaceFace::TolReached2d() const
422 return myTolReached2d;
424 // =======================================================================
425 // function: SetParameters
427 // =======================================================================
428 void IntTools_FaceFace::SetParameters(const Standard_Boolean ToApproxC3d,
429 const Standard_Boolean ToApproxC2dOnS1,
430 const Standard_Boolean ToApproxC2dOnS2,
431 const Standard_Real ApproximationTolerance)
433 myApprox = ToApproxC3d;
434 myApprox1 = ToApproxC2dOnS1;
435 myApprox2 = ToApproxC2dOnS2;
436 myTolApprox = ApproximationTolerance;
438 //=======================================================================
441 //=======================================================================
442 void IntTools_FaceFace::SetList(IntSurf_ListOfPntOn2S& aListOfPnts)
444 myListOfPnts = aListOfPnts;
448 static Standard_Boolean isTreatAnalityc(const TopoDS_Face& theF1,
449 const TopoDS_Face& theF2)
451 const Standard_Real Tolang = 1.e-8;
452 const Standard_Real aTolF1=BRep_Tool::Tolerance(theF1);
453 const Standard_Real aTolF2=BRep_Tool::Tolerance(theF2);
454 const Standard_Real aTolSum = aTolF1 + aTolF2;
455 Standard_Real aHigh = 0.0;
457 const BRepAdaptor_Surface aBAS1(theF1), aBAS2(theF2);
458 const GeomAbs_SurfaceType aType1=aBAS1.GetType();
459 const GeomAbs_SurfaceType aType2=aBAS2.GetType();
463 if(aType1 == GeomAbs_Plane)
467 else if(aType2 == GeomAbs_Plane)
473 return Standard_True;
476 if(aType1 == GeomAbs_Cylinder)
478 aS2=aBAS1.Cylinder();
479 const Standard_Real VMin = aBAS1.FirstVParameter();
480 const Standard_Real VMax = aBAS1.LastVParameter();
482 if( Precision::IsNegativeInfinite(VMin) ||
483 Precision::IsPositiveInfinite(VMax))
484 return Standard_True;
488 else if(aType2 == GeomAbs_Cylinder)
490 aS2=aBAS2.Cylinder();
492 const Standard_Real VMin = aBAS2.FirstVParameter();
493 const Standard_Real VMax = aBAS2.LastVParameter();
495 if( Precision::IsNegativeInfinite(VMin) ||
496 Precision::IsPositiveInfinite(VMax))
497 return Standard_True;
503 return Standard_True;
506 IntAna_QuadQuadGeo inter;
507 inter.Perform(aS1,aS2,Tolang,aTolSum, aHigh);
508 if(inter.TypeInter() == IntAna_Ellipse)
510 const gp_Elips anEl = inter.Ellipse(1);
511 const Standard_Real aMajorR = anEl.MajorRadius();
512 const Standard_Real aMinorR = anEl.MinorRadius();
514 return (aMajorR < 100000.0 * aMinorR);
518 return inter.IsDone();
524 //=======================================================================
526 //purpose : intersect surfaces of the faces
527 //=======================================================================
528 void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
529 const TopoDS_Face& aF2)
531 Standard_Boolean RestrictLine = Standard_False, hasCone = Standard_False;
533 if (myContext.IsNull()) {
534 myContext=new BOPInt_Context;
537 mySeqOfCurve.Clear();
540 myIsDone = Standard_False;
546 const BRepAdaptor_Surface aBAS1(myFace1, Standard_False);
547 const BRepAdaptor_Surface aBAS2(myFace2, Standard_False);
548 GeomAbs_SurfaceType aType1=aBAS1.GetType();
549 GeomAbs_SurfaceType aType2=aBAS2.GetType();
551 const Standard_Boolean bReverse=SortTypes(aType1, aType2);
556 aType1=aBAS2.GetType();
557 aType2=aBAS1.GetType();
559 if (myListOfPnts.Extent())
561 Standard_Real aU1,aV1,aU2,aV2;
562 IntSurf_ListIteratorOfListOfPntOn2S aItP2S;
564 aItP2S.Initialize(myListOfPnts);
565 for (; aItP2S.More(); aItP2S.Next())
567 IntSurf_PntOn2S& aP2S=aItP2S.Value();
568 aP2S.Parameters(aU1,aV1,aU2,aV2);
569 aP2S.SetValue(aU2,aV2,aU1,aV1);
575 const Handle(Geom_Surface) S1=BRep_Tool::Surface(myFace1);
576 const Handle(Geom_Surface) S2=BRep_Tool::Surface(myFace2);
578 const Standard_Real aTolF1=BRep_Tool::Tolerance(myFace1);
579 const Standard_Real aTolF2=BRep_Tool::Tolerance(myFace2);
581 Standard_Real TolArc = aTolF1 + aTolF2;
582 Standard_Real TolTang = TolArc;
584 const Standard_Boolean isFace1Quad = (aType1 == GeomAbs_Cylinder ||
585 aType1 == GeomAbs_Cone ||
586 aType1 == GeomAbs_Torus);
588 const Standard_Boolean isFace2Quad = (aType2 == GeomAbs_Cylinder ||
589 aType2 == GeomAbs_Cone ||
590 aType2 == GeomAbs_Torus);
592 if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane)
594 Standard_Real umin, umax, vmin, vmax;
595 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
596 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
598 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
599 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
600 Standard_Real TolAng = 1.e-8;
602 PerformPlanes(myHS1, myHS2, TolAng, TolTang, myApprox1, myApprox2,
603 mySeqOfCurve, myTangentFaces);
605 myIsDone = Standard_True;
609 const Standard_Integer NbLinPP = mySeqOfCurve.Length();
612 Standard_Real aTolFMax;
613 myTolReached3d = 1.e-7;
614 aTolFMax=Max(aTolF1, aTolF2);
615 if (aTolFMax>myTolReached3d)
617 myTolReached3d=aTolFMax;
620 myTolReached2d = myTolReached3d;
624 Handle(Geom2d_Curve) aC2D1, aC2D2;
625 const Standard_Integer aNbLin = mySeqOfCurve.Length();
626 for (Standard_Integer i = 1; i <= aNbLin; ++i)
628 IntTools_Curve& aIC=mySeqOfCurve(i);
629 aC2D1=aIC.FirstCurve2d();
630 aC2D2=aIC.SecondCurve2d();
631 aIC.SetFirstCurve2d(aC2D2);
632 aIC.SetSecondCurve2d(aC2D1);
639 }//if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
641 if ((aType1==GeomAbs_Plane) && isFace2Quad)
643 Standard_Real dU, dV;
646 Standard_Real umin, umax, vmin, vmax;
647 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
655 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
657 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
658 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
659 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
661 if( aType2==GeomAbs_Cone ) {
663 hasCone = Standard_True;
666 else if ((aType2==GeomAbs_Plane) && isFace1Quad)
668 Standard_Real dU, dV;
671 Standard_Real umin, umax, vmin, vmax;
672 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
673 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
674 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
676 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
683 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
685 if( aType1==GeomAbs_Cone ) {
687 hasCone = Standard_True;
692 Standard_Real umin, umax, vmin, vmax;
693 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
694 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
695 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
696 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
697 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
698 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
701 const Handle(IntTools_TopolTool) dom1 = new IntTools_TopolTool(myHS1);
702 const Handle(IntTools_TopolTool) dom2 = new IntTools_TopolTool(myHS2);
704 myLConstruct.Load(dom1, dom2, myHS1, myHS2);
707 Tolerances(myHS1, myHS2, TolTang);
710 const Standard_Real UVMaxStep = 0.001;
711 const Standard_Real Deflection = (hasCone) ? 0.085 : 0.1;
712 myIntersector.SetTolerances(TolArc, TolTang, UVMaxStep, Deflection);
715 if((myHS1->IsUClosed() && !myHS1->IsUPeriodic()) ||
716 (myHS1->IsVClosed() && !myHS1->IsVPeriodic()) ||
717 (myHS2->IsUClosed() && !myHS2->IsUPeriodic()) ||
718 (myHS2->IsVClosed() && !myHS2->IsVPeriodic()))
720 RestrictLine = Standard_True;
723 if((aType1 != GeomAbs_BSplineSurface) &&
724 (aType1 != GeomAbs_BezierSurface) &&
725 (aType1 != GeomAbs_OtherSurface) &&
726 (aType2 != GeomAbs_BSplineSurface) &&
727 (aType2 != GeomAbs_BezierSurface) &&
728 (aType2 != GeomAbs_OtherSurface))
730 RestrictLine = Standard_True;
732 if ((aType1 == GeomAbs_Torus) ||
733 (aType2 == GeomAbs_Torus))
735 myListOfPnts.Clear();
742 TopExp_Explorer aExp;
743 for(Standard_Integer i = 0; (!RestrictLine) && (i < 2); i++)
745 const TopoDS_Face& aF=(!i) ? myFace1 : myFace2;
746 aExp.Init(aF, TopAbs_EDGE);
747 for(; aExp.More(); aExp.Next())
749 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
751 if(BRep_Tool::Degenerated(aE))
753 RestrictLine = Standard_True;
760 const Standard_Boolean isGeomInt = isTreatAnalityc(aF1, aF2);
761 myIntersector.Perform(myHS1, dom1, myHS2, dom2, TolArc, TolTang,
762 myListOfPnts, RestrictLine, isGeomInt);
764 myIsDone = myIntersector.IsDone();
768 myTangentFaces=myIntersector.TangentFaces();
769 if (myTangentFaces) {
774 myListOfPnts.Clear(); // to use LineConstructor
777 const Standard_Integer aNbLin = myIntersector.NbLines();
778 for (Standard_Integer i=1; i <= aNbLin; ++i) {
779 MakeCurve(i, dom1, dom2);
782 ComputeTolReached3d();
785 Handle(Geom2d_Curve) aC2D1, aC2D2;
787 const Standard_Integer aNbLin=mySeqOfCurve.Length();
788 for (Standard_Integer i=1; i<=aNbLin; ++i)
790 IntTools_Curve& aIC=mySeqOfCurve(i);
791 aC2D1=aIC.FirstCurve2d();
792 aC2D2=aIC.SecondCurve2d();
793 aIC.SetFirstCurve2d(aC2D2);
794 aIC.SetSecondCurve2d(aC2D1);
799 Standard_Real U1,V1,U2,V2;
800 IntTools_PntOnFace aPntOnF1, aPntOnF2;
801 IntTools_PntOn2Faces aPntOn2Faces;
803 const Standard_Integer aNbPnts = myIntersector.NbPnts();
804 for (Standard_Integer i=1; i <= aNbPnts; ++i)
806 const IntSurf_PntOn2S& aISPnt=myIntersector.Point(i).PntOn2S();
807 const gp_Pnt& aPnt=aISPnt.Value();
808 aISPnt.Parameters(U1,V1,U2,V2);
809 aPntOnF1.Init(myFace1, aPnt, U1, V1);
810 aPntOnF2.Init(myFace2, aPnt, U2, V2);
814 aPntOn2Faces.SetP1(aPntOnF1);
815 aPntOn2Faces.SetP2(aPntOnF2);
819 aPntOn2Faces.SetP2(aPntOnF1);
820 aPntOn2Faces.SetP1(aPntOnF2);
823 myPnts.Append(aPntOn2Faces);
828 //=======================================================================
829 //function :ComputeTolReached3d
831 //=======================================================================
832 void IntTools_FaceFace::ComputeTolReached3d()
834 Standard_Boolean bCase1;
835 Standard_Integer aNbLin, i;
836 GeomAbs_SurfaceType aType1, aType2;
838 aNbLin=myIntersector.NbLines();
843 aType1=myHS1->Surface().GetType();
844 aType2=myHS2->Surface().GetType();
846 bCase1=((aType1==GeomAbs_Plane && aType2==GeomAbs_SurfaceOfExtrusion) ||
847 (aType2==GeomAbs_Plane && aType1==GeomAbs_SurfaceOfExtrusion));
849 if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
851 Handle(IntPatch_Line) aIL1, aIL2;
852 IntPatch_IType aTL1, aTL2;
854 aIL1=myIntersector.Line(1);
855 aIL2=myIntersector.Line(2);
856 aTL1=aIL1->ArcType();
857 aTL2=aIL2->ArcType();
858 if (aTL1==IntPatch_Lin && aTL2==IntPatch_Lin) {
859 Standard_Real aD, aDTresh, dTol;
865 aL1=Handle(IntPatch_GLine)::DownCast(aIL1)->Line();
866 aL2=Handle(IntPatch_GLine)::DownCast(aIL2)->Line();
867 aD=aL1.Distance(aL2);
870 myTolReached3d=aD+dTol;
876 if (aNbLin) {// Check the distances
877 Standard_Integer aNbP, j ;
878 Standard_Real aT1, aT2, dT, aD2, aD2Max, aEps, aT11, aT12;
882 aNbLin=mySeqOfCurve.Length();
884 for (i=1; i<=aNbLin; ++i) {
885 const IntTools_Curve& aIC=mySeqOfCurve(i);
886 const Handle(Geom_Curve)& aC3D=aIC.Curve();
887 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
888 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
893 const Handle(Geom_BSplineCurve)& aBC=
894 Handle(Geom_BSplineCurve)::DownCast(aC3D);
899 aT1=aBC->FirstParameter();
900 aT2=aBC->LastParameter();
904 for (j=1; j<aNbP; ++j) {
907 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
908 myHS1, myHS2, myFace1, myFace2, myContext);
913 }//for (i=1; i<=aNbLin; ++i) {
915 myTolReached3d=sqrt(aD2Max);
917 }// if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
920 else if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
921 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
925 aTolF1 = BRep_Tool::Tolerance(myFace1);
926 aTolF2 = BRep_Tool::Tolerance(myFace2);
927 aTolFMax=Max(aTolF1, aTolF2);
929 if (aTolFMax>aTolTresh) {
930 myTolReached3d=aTolFMax;
932 }//if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
935 else if((aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) ||
936 (aType2 == GeomAbs_Cylinder && aType1 == GeomAbs_Plane)) {
938 const Handle(IntPatch_Line)& aIL1 = myIntersector.Line(1);
939 if(aIL1->ArcType() == IntPatch_Circle) {
940 gp_Circ aCir = Handle(IntPatch_GLine)::DownCast(aIL1)->Circle();
941 gp_XYZ aCirDir = aCir.Axis().Direction().XYZ();
944 if(aType1 == GeomAbs_Plane) {
945 aPln = myHS1->Surface().Plane();
948 aPln = myHS2->Surface().Plane();
950 aPlDir = aPln.Axis().Direction().XYZ();
951 Standard_Real cs = aCirDir*aPlDir;
952 if(cs < 0.) aPlDir.Reverse();
953 Standard_Real eps = 1.e-14;
954 if(!aPlDir.IsEqual(aCirDir, eps)) {
955 Standard_Integer aNbP = 11;
956 Standard_Real dt = 2.*M_PI / (aNbP - 1), t;
957 for(t = 0.; t < 2.*M_PI; t += dt) {
958 Standard_Real d = aPln.Distance(ElCLib::Value(t, aCir));
959 if(myTolReached3d < d) myTolReached3d = d;
961 myTolReached3d *= 1.1;
963 } //aIL1->ArcType() == IntPatch_Circle
965 } // aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane)
966 //End IFV Bug OCC20297
968 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
969 (aType2==GeomAbs_Plane && aType1==GeomAbs_Torus)) {
970 aNbLin=mySeqOfCurve.Length();
975 Standard_Integer aNbP;
976 Standard_Real aT, aT1, aT2, dT, aUT, aVT, aUP, aVP;
977 Standard_Real aDP, aDT, aDmax;
982 const IntTools_Curve& aIC=mySeqOfCurve(1);
983 const Handle(Geom_Curve)& aC3D=aIC.Curve();
984 const Handle(Geom_BSplineCurve)& aBS=
985 Handle(Geom_BSplineCurve)::DownCast(aC3D);
990 aT1=aBS->FirstParameter();
991 aT2=aBS->LastParameter();
993 aPln =(aType1==GeomAbs_Plane) ? myHS1->Plane() : myHS2->Plane();
994 aTorus=(aType1==GeomAbs_Plane) ? myHS2->Torus() : myHS1->Torus();
998 dT=(aT2-aT1)/(aNbP-1);
999 for (i=0; i<aNbP; ++i) {
1007 ElSLib::Parameters(aPln, aP, aUP, aVP);
1008 aPP=ElSLib::Value(aUP, aVP, aPln);
1009 aDP=aP.SquareDistance(aPP);
1014 ElSLib::Parameters(aTorus, aP, aUT, aVT);
1015 aPT=ElSLib::Value(aUT, aVT, aTorus);
1016 aDT=aP.SquareDistance(aPT);
1022 if (aDmax > myTolReached3d*myTolReached3d) {
1023 myTolReached3d=sqrt(aDmax);
1024 myTolReached3d=1.1*myTolReached3d;
1026 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
1028 else if ((aType1==GeomAbs_SurfaceOfRevolution && aType2==GeomAbs_Cylinder) ||
1029 (aType2==GeomAbs_SurfaceOfRevolution && aType1==GeomAbs_Cylinder)) {
1030 Standard_Integer j, aNbP;
1031 Standard_Real aT, aT1, aT2, dT, aD2max, aD2;
1033 aNbLin=mySeqOfCurve.Length();
1037 for (i=1; i<=aNbLin; ++i) {
1038 const IntTools_Curve& aIC=mySeqOfCurve(i);
1039 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1040 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
1041 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1043 if (aC3D.IsNull()) {
1046 const Handle(Geom_BSplineCurve)& aBC=
1047 Handle(Geom_BSplineCurve)::DownCast(aC3D);
1052 aT1=aBC->FirstParameter();
1053 aT2=aBC->LastParameter();
1055 dT=(aT2-aT1)/(aNbP-1);
1056 for (j=0; j<aNbP; ++j) {
1062 aD2=MaxSquareDistance(aT, aC3D, aC2D1, aC2D2,
1063 myHS1, myHS2, myFace1, myFace2, myContext);
1067 }//for (j=0; j<aNbP; ++j) {
1069 }//for (i=1; i<=aNbLin; ++i) {
1071 aD2=myTolReached3d*myTolReached3d;
1073 myTolReached3d=sqrt(aD2max);
1075 }//if((aType1==GeomAbs_SurfaceOfRevolution ...
1076 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ||
1077 (aType2==GeomAbs_Plane && aType1==GeomAbs_Sphere)) {
1078 Standard_Integer j, aNbP;
1079 Standard_Real aT1, aT2, dT, aD2max, aD2, aEps, aT11, aT12;
1081 aNbLin=mySeqOfCurve.Length();
1085 for (i=1; i<=aNbLin; ++i) {
1086 const IntTools_Curve& aIC=mySeqOfCurve(i);
1087 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1088 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
1089 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1091 const Handle(Geom2d_BSplineCurve)& aBC2D1=
1092 Handle(Geom2d_BSplineCurve)::DownCast(aC2D1);
1093 const Handle(Geom2d_BSplineCurve)& aBC2D2=
1094 Handle(Geom2d_BSplineCurve)::DownCast(aC2D2);
1096 if (aBC2D1.IsNull() && aBC2D2.IsNull()) {
1100 if (!aBC2D1.IsNull()) {
1101 aT1=aBC2D1->FirstParameter();
1102 aT2=aBC2D1->LastParameter();
1105 aT1=aBC2D2->FirstParameter();
1106 aT2=aBC2D2->LastParameter();
1109 aEps=0.01*(aT2-aT1);
1111 for (j=0; j<aNbP; ++j) {
1118 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
1119 myHS1, myHS2, myFace1, myFace2, myContext);
1123 }//for (j=0; j<aNbP; ++j) {
1125 }//for (i=1; i<=aNbLin; ++i) {
1127 aD2=myTolReached3d*myTolReached3d;
1129 myTolReached3d=sqrt(aD2max);
1131 }//else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ...
1132 else if (!myApprox || bCase1) {
1133 //else if (!myApprox) {
1134 Standard_Integer aNbP, j;
1135 Standard_Real aT1, aT2, dT, aD2, aD2Max, aEps, aT11, aT12;
1138 aNbLin=mySeqOfCurve.Length();
1140 for (i=1; i<=aNbLin; ++i) {
1141 const IntTools_Curve& aIC=mySeqOfCurve(i);
1142 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1143 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
1144 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1146 if (aC3D.IsNull()) {
1149 const Handle(Geom_BSplineCurve)& aBC=
1150 Handle(Geom_BSplineCurve)::DownCast(aC3D);
1155 aT1=aBC->FirstParameter();
1156 aT2=aBC->LastParameter();
1158 aEps=0.0001*(aT2-aT1);
1161 for (j=1; j<aNbP-1; ++j) {
1164 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
1165 myHS1, myHS2, myFace1, myFace2, myContext);
1170 }//for (i=1; i<=aNbLin; ++i) {
1171 myTolReached3d=sqrt(aD2Max);
1174 //=======================================================================
1175 //function : MakeCurve
1177 //=======================================================================
1178 void IntTools_FaceFace::MakeCurve(const Standard_Integer Index,
1179 const Handle(Adaptor3d_TopolTool)& dom1,
1180 const Handle(Adaptor3d_TopolTool)& dom2)
1182 Standard_Boolean bDone, rejectSurface, reApprox, bAvoidLineConstructor,
1184 Standard_Boolean ok;
1185 Standard_Integer i, j, aNbParts;
1186 Standard_Real fprm, lprm;
1187 Standard_Real Tolpc;
1188 Handle(IntPatch_Line) L;
1189 IntPatch_IType typl;
1190 Handle(Geom_Curve) newc;
1192 const Standard_Real TOLCHECK =0.0000001;
1193 const Standard_Real TOLANGCHECK=0.1;
1195 rejectSurface = Standard_False;
1196 reApprox = Standard_False;
1198 bPCurvesOk = Standard_True;
1202 Tolpc = myTolApprox;
1203 bAvoidLineConstructor = Standard_False;
1204 L = myIntersector.Line(Index);
1205 typl = L->ArcType();
1207 if(typl==IntPatch_Walking) {
1208 Handle(IntPatch_Line) anewL;
1210 const Handle(IntPatch_WLine)& aWLine=
1211 Handle(IntPatch_WLine)::DownCast(L);
1212 #ifdef DEB_DUMPWLINE
1215 anewL = ComputePurgedWLine(aWLine);
1216 if(anewL.IsNull()) {
1220 #ifdef DEB_DUMPWLINE
1221 const Handle(IntPatch_WLine)& aWLineX = Handle(IntPatch_WLine)::DownCast(L);
1225 if(!myListOfPnts.IsEmpty()) {
1226 bAvoidLineConstructor = Standard_True;
1229 Standard_Integer nbp = aWLine->NbPnts();
1230 const IntSurf_PntOn2S& p1 = aWLine->Point(1);
1231 const IntSurf_PntOn2S& p2 = aWLine->Point(nbp);
1233 const gp_Pnt& P1 = p1.Value();
1234 const gp_Pnt& P2 = p2.Value();
1236 if(P1.SquareDistance(P2) < 1.e-14) {
1237 bAvoidLineConstructor = Standard_False;
1243 if(!bAvoidLineConstructor) {
1244 myLConstruct.Perform(L);
1246 bDone=myLConstruct.IsDone();
1247 aNbParts=myLConstruct.NbParts();
1248 if (!bDone|| !aNbParts) {
1257 //########################################
1258 // Line, Parabola, Hyperbola
1259 //########################################
1261 case IntPatch_Parabola:
1262 case IntPatch_Hyperbola: {
1263 if (typl == IntPatch_Lin) {
1265 new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line());
1268 else if (typl == IntPatch_Parabola) {
1270 new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola());
1273 else if (typl == IntPatch_Hyperbola) {
1275 new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola());
1279 if (typl == IntPatch_Lin) {
1280 TolR3d (myFace1, myFace2, myTolReached3d);
1283 aNbParts=myLConstruct.NbParts();
1284 for (i=1; i<=aNbParts; i++) {
1285 myLConstruct.Part(i, fprm, lprm);
1287 if (!Precision::IsNegativeInfinite(fprm) &&
1288 !Precision::IsPositiveInfinite(lprm)) {
1290 IntTools_Curve aCurve;
1292 Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm);
1293 aCurve.SetCurve(aCT3D);
1294 if (typl == IntPatch_Parabola) {
1295 Standard_Real aTolF1, aTolF2, aTolBase;
1297 aTolF1 = BRep_Tool::Tolerance(myFace1);
1298 aTolF2 = BRep_Tool::Tolerance(myFace2);
1299 aTolBase=aTolF1+aTolF2;
1300 myTolReached3d=IntTools_Tools::CurveTolerance(aCT3D, aTolBase);
1303 aCurve.SetCurve(new Geom_TrimmedCurve(newc, fprm, lprm));
1305 Handle (Geom2d_Curve) C2d;
1306 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1307 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1308 myTolReached2d=Tolpc;
1311 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1314 Handle(Geom2d_BSplineCurve) H1;
1316 aCurve.SetFirstCurve2d(H1);
1320 Handle (Geom2d_Curve) C2d;
1321 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1322 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1323 myTolReached2d=Tolpc;
1326 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1329 Handle(Geom2d_BSplineCurve) H1;
1331 aCurve.SetSecondCurve2d(H1);
1333 mySeqOfCurve.Append(aCurve);
1334 } // end of if (!Precision::IsNegativeInfinite(fprm) && !Precision::IsPositiveInfinite(lprm))
1337 // on regarde si on garde
1339 Standard_Boolean bFNIt, bLPIt;
1340 Standard_Real aTestPrm, dT=100.;
1342 bFNIt=Precision::IsNegativeInfinite(fprm);
1343 bLPIt=Precision::IsPositiveInfinite(lprm);
1347 if (bFNIt && !bLPIt) {
1350 else if (!bFNIt && bLPIt) {
1354 gp_Pnt ptref(newc->Value(aTestPrm));
1357 Standard_Real u1, v1, u2, v2, Tol;
1359 Tol = Precision::Confusion();
1360 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1361 ok = (dom1->Classify(gp_Pnt2d(u1, v1), Tol) != TopAbs_OUT);
1363 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1366 Handle(Geom2d_BSplineCurve) H1;
1367 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1370 }// end of for (i=1; i<=myLConstruct.NbParts(); i++)
1371 }// case IntPatch_Lin: case IntPatch_Parabola: case IntPatch_Hyperbola:
1374 //########################################
1375 // Circle and Ellipse
1376 //########################################
1377 case IntPatch_Circle:
1378 case IntPatch_Ellipse: {
1380 if (typl == IntPatch_Circle) {
1381 newc = new Geom_Circle
1382 (Handle(IntPatch_GLine)::DownCast(L)->Circle());
1384 else { //IntPatch_Ellipse
1385 newc = new Geom_Ellipse
1386 (Handle(IntPatch_GLine)::DownCast(L)->Ellipse());
1390 TolR3d (myFace1, myFace2, myTolReached3d);
1392 aNbParts=myLConstruct.NbParts();
1394 Standard_Real aPeriod, aNul;
1395 TColStd_SequenceOfReal aSeqFprm, aSeqLprm;
1400 for (i=1; i<=aNbParts; i++) {
1401 myLConstruct.Part(i, fprm, lprm);
1403 if (fprm < aNul && lprm > aNul) {
1404 // interval that goes through 0. is divided on two intervals;
1405 while (fprm<aNul || fprm>aPeriod) fprm=fprm+aPeriod;
1406 while (lprm<aNul || lprm>aPeriod) lprm=lprm+aPeriod;
1408 if((aPeriod - fprm) > Tolpc) {
1409 aSeqFprm.Append(fprm);
1410 aSeqLprm.Append(aPeriod);
1413 gp_Pnt P1 = newc->Value(fprm);
1414 gp_Pnt P2 = newc->Value(aPeriod);
1415 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1416 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1418 if(P1.Distance(P2) > aTolDist) {
1419 Standard_Real anewpar = fprm;
1421 if(ParameterOutOfBoundary(fprm, newc, myFace1, myFace2, lprm, Standard_False, anewpar, myContext)) {
1424 aSeqFprm.Append(fprm);
1425 aSeqLprm.Append(aPeriod);
1430 if((lprm - aNul) > Tolpc) {
1431 aSeqFprm.Append(aNul);
1432 aSeqLprm.Append(lprm);
1435 gp_Pnt P1 = newc->Value(aNul);
1436 gp_Pnt P2 = newc->Value(lprm);
1437 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1438 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1440 if(P1.Distance(P2) > aTolDist) {
1441 Standard_Real anewpar = lprm;
1443 if(ParameterOutOfBoundary(lprm, newc, myFace1, myFace2, fprm, Standard_True, anewpar, myContext)) {
1446 aSeqFprm.Append(aNul);
1447 aSeqLprm.Append(lprm);
1453 aSeqFprm.Append(fprm);
1454 aSeqLprm.Append(lprm);
1459 aNbParts=aSeqFprm.Length();
1460 for (i=1; i<=aNbParts; i++) {
1464 Standard_Real aRealEpsilon=RealEpsilon();
1465 if (Abs(fprm) > aRealEpsilon || Abs(lprm-2.*M_PI) > aRealEpsilon) {
1466 //==============================================
1468 IntTools_Curve aCurve;
1469 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1470 aCurve.SetCurve(aTC3D);
1471 fprm=aTC3D->FirstParameter();
1472 lprm=aTC3D->LastParameter ();
1474 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {////
1476 Handle (Geom2d_Curve) C2d;
1477 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1478 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1479 myTolReached2d=Tolpc;
1482 aCurve.SetFirstCurve2d(C2d);
1485 Handle(Geom2d_BSplineCurve) H1;
1486 aCurve.SetFirstCurve2d(H1);
1491 Handle (Geom2d_Curve) C2d;
1492 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1493 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1494 myTolReached2d=Tolpc;
1497 aCurve.SetSecondCurve2d(C2d);
1500 Handle(Geom2d_BSplineCurve) H1;
1501 aCurve.SetSecondCurve2d(H1);
1506 Handle(Geom2d_BSplineCurve) H1;
1507 aCurve.SetFirstCurve2d(H1);
1508 aCurve.SetSecondCurve2d(H1);
1510 mySeqOfCurve.Append(aCurve);
1511 //==============================================
1512 } //if (Abs(fprm) > RealEpsilon() || Abs(lprm-2.*M_PI) > RealEpsilon())
1515 // on regarde si on garde
1518 // if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*M_PI) < RealEpsilon()) {
1519 if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*M_PI) <= aRealEpsilon) {
1520 IntTools_Curve aCurve;
1521 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1522 aCurve.SetCurve(aTC3D);
1523 fprm=aTC3D->FirstParameter();
1524 lprm=aTC3D->LastParameter ();
1527 Handle (Geom2d_Curve) C2d;
1528 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1529 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1530 myTolReached2d=Tolpc;
1533 aCurve.SetFirstCurve2d(C2d);
1536 Handle(Geom2d_BSplineCurve) H1;
1537 aCurve.SetFirstCurve2d(H1);
1541 Handle (Geom2d_Curve) C2d;
1542 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1543 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1544 myTolReached2d=Tolpc;
1547 aCurve.SetSecondCurve2d(C2d);
1550 Handle(Geom2d_BSplineCurve) H1;
1551 aCurve.SetSecondCurve2d(H1);
1553 mySeqOfCurve.Append(aCurve);
1558 Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol;
1560 aTwoPIdiv17=2.*M_PI/17.;
1562 for (j=0; j<=17; j++) {
1563 gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
1564 Tol = Precision::Confusion();
1566 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1567 ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT);
1569 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1572 IntTools_Curve aCurve;
1573 aCurve.SetCurve(newc);
1574 //==============================================
1575 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {
1578 Handle (Geom2d_Curve) C2d;
1579 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1580 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1581 myTolReached2d=Tolpc;
1584 aCurve.SetFirstCurve2d(C2d);
1587 Handle(Geom2d_BSplineCurve) H1;
1588 aCurve.SetFirstCurve2d(H1);
1592 Handle (Geom2d_Curve) C2d;
1593 BuildPCurves(fprm, lprm, Tolpc,myHS2->ChangeSurface().Surface(), newc, C2d);
1594 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1595 myTolReached2d=Tolpc;
1598 aCurve.SetSecondCurve2d(C2d);
1602 Handle(Geom2d_BSplineCurve) H1;
1603 aCurve.SetSecondCurve2d(H1);
1605 }// end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse)
1608 Handle(Geom2d_BSplineCurve) H1;
1610 aCurve.SetFirstCurve2d(H1);
1611 aCurve.SetSecondCurve2d(H1);
1613 //==============================================
1615 mySeqOfCurve.Append(aCurve);
1618 }// end of if (ok) {
1619 }// end of for (Standard_Integer j=0; j<=17; j++)
1620 }// end of else { on regarde si on garde
1621 }// for (i=1; i<=myLConstruct.NbParts(); i++)
1622 }// IntPatch_Circle: IntPatch_Ellipse:
1625 case IntPatch_Analytic: {
1626 IntSurf_Quadric quad1,quad2;
1627 GeomAbs_SurfaceType typs = myHS1->Surface().GetType();
1631 quad1.SetValue(myHS1->Surface().Plane());
1633 case GeomAbs_Cylinder:
1634 quad1.SetValue(myHS1->Surface().Cylinder());
1637 quad1.SetValue(myHS1->Surface().Cone());
1639 case GeomAbs_Sphere:
1640 quad1.SetValue(myHS1->Surface().Sphere());
1643 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 1");
1646 typs = myHS2->Surface().GetType();
1650 quad2.SetValue(myHS2->Surface().Plane());
1652 case GeomAbs_Cylinder:
1653 quad2.SetValue(myHS2->Surface().Cylinder());
1656 quad2.SetValue(myHS2->Surface().Cone());
1658 case GeomAbs_Sphere:
1659 quad2.SetValue(myHS2->Surface().Sphere());
1662 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 2");
1666 IntPatch_ALineToWLine convert (quad1, quad2);
1669 aNbParts=myLConstruct.NbParts();
1670 for (i=1; i<=aNbParts; i++) {
1671 myLConstruct.Part(i, fprm, lprm);
1672 Handle(IntPatch_WLine) WL =
1673 convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm);
1675 Handle(Geom2d_BSplineCurve) H1;
1676 Handle(Geom2d_BSplineCurve) H2;
1679 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1683 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1686 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1690 else { // myApprox=TRUE
1691 GeomInt_WLApprox theapp3d;
1693 Standard_Real tol2d = myTolApprox;
1695 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True);
1697 aNbParts=myLConstruct.NbParts();
1698 for (i=1; i<=aNbParts; i++) {
1699 myLConstruct.Part(i, fprm, lprm);
1700 Handle(IntPatch_WLine) WL =
1701 convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
1703 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
1705 if (!theapp3d.IsDone()) {
1707 Handle(Geom2d_BSplineCurve) H1;
1708 Handle(Geom2d_BSplineCurve) H2;
1711 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1715 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1718 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1722 if(myApprox1 || myApprox2) {
1723 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) {
1724 myTolReached2d = theapp3d.TolReached2d();
1728 if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) {
1729 myTolReached3d = theapp3d.TolReached3d();
1732 Standard_Integer aNbMultiCurves, nbpoles;
1733 aNbMultiCurves=theapp3d.NbMultiCurves();
1734 for (j=1; j<=aNbMultiCurves; j++) {
1735 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1736 nbpoles = mbspc.NbPoles();
1738 TColgp_Array1OfPnt tpoles(1, nbpoles);
1739 mbspc.Curve(1, tpoles);
1740 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1742 mbspc.Multiplicities(),
1745 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1746 Check.FixTangent(Standard_True,Standard_True);
1748 IntTools_Curve aCurve;
1749 aCurve.SetCurve(BS);
1752 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1753 mbspc.Curve(2,tpoles2d);
1754 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1756 mbspc.Multiplicities(),
1759 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1760 newCheck.FixTangent(Standard_True,Standard_True);
1762 aCurve.SetFirstCurve2d(BS2);
1765 Handle(Geom2d_BSplineCurve) H1;
1766 aCurve.SetFirstCurve2d(H1);
1770 TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
1771 Standard_Integer TwoOrThree;
1772 TwoOrThree=myApprox1 ? 3 : 2;
1773 mbspc.Curve(TwoOrThree, tpoles2d);
1774 Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
1776 mbspc.Multiplicities(),
1779 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1780 newCheck.FixTangent(Standard_True,Standard_True);
1782 aCurve.SetSecondCurve2d(BS2);
1785 Handle(Geom2d_BSplineCurve) H2;
1786 aCurve.SetSecondCurve2d(H2);
1789 mySeqOfCurve.Append(aCurve);
1791 }// for (j=1; j<=aNbMultiCurves; j++) {
1792 }// else from if (!theapp3d.IsDone())
1793 }// for (i=1; i<=aNbParts; i++) {
1794 }// else { // myApprox=TRUE
1795 }// case IntPatch_Analytic:
1798 case IntPatch_Walking:{
1799 Handle(IntPatch_WLine) WL =
1800 Handle(IntPatch_WLine)::DownCast(L);
1802 Standard_Integer ifprm, ilprm;
1806 if(!bAvoidLineConstructor){
1807 aNbParts=myLConstruct.NbParts();
1809 for (i=1; i<=aNbParts; ++i) {
1810 Handle(Geom2d_BSplineCurve) H1, H2;
1811 Handle(Geom_Curve) aBSp;
1813 if(bAvoidLineConstructor) {
1815 ilprm = WL->NbPnts();
1818 myLConstruct.Part(i, fprm, lprm);
1819 ifprm=(Standard_Integer)fprm;
1820 ilprm=(Standard_Integer)lprm;
1824 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1828 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1831 aBSp=MakeBSpline(WL, ifprm, ilprm);
1832 IntTools_Curve aIC(aBSp, H1, H2);
1833 mySeqOfCurve.Append(aIC);
1834 }// for (i=1; i<=aNbParts; ++i) {
1835 }// if (!myApprox) {
1838 Standard_Boolean bIsDecomposited;
1839 Standard_Integer nbiter, aNbSeqOfL;
1840 Standard_Real tol2d;
1841 IntPatch_SequenceOfLine aSeqOfL;
1842 GeomInt_WLApprox theapp3d;
1843 Approx_ParametrizationType aParType = Approx_ChordLength;
1845 Standard_Boolean anApprox1 = myApprox1;
1846 Standard_Boolean anApprox2 = myApprox2;
1848 tol2d = myTolApprox;
1850 GeomAbs_SurfaceType typs1, typs2;
1851 typs1 = myHS1->Surface().GetType();
1852 typs2 = myHS2->Surface().GetType();
1853 Standard_Boolean anWithPC = Standard_True;
1855 if(typs1 == GeomAbs_Cylinder && typs2 == GeomAbs_Sphere) {
1857 ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere());
1859 else if (typs1 == GeomAbs_Sphere && typs2 == GeomAbs_Cylinder) {
1861 ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere());
1864 //aParType = Approx_Centripetal;
1865 myTolApprox = 1.e-5;
1866 anApprox1 = Standard_False;
1867 anApprox2 = Standard_False;
1869 tol2d = myTolApprox;
1872 if(myHS1 == myHS2) {
1874 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1875 rejectSurface = Standard_True;
1878 if(reApprox && !rejectSurface)
1879 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1881 Standard_Integer iDegMax, iDegMin, iNbIter;
1883 ApproxParameters(myHS1, myHS2, iDegMin, iDegMax, iNbIter);
1884 theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, iNbIter, Standard_True, aParType);
1889 Standard_Real aReachedTol = Precision::Confusion();
1890 bIsDecomposited=DecompositionOfWLine(WL,
1896 bAvoidLineConstructor,
1900 if ( bIsDecomposited && ( myTolReached3d < aReachedTol ) )
1901 myTolReached3d = aReachedTol;
1904 aNbSeqOfL=aSeqOfL.Length();
1906 if (bIsDecomposited) {
1912 if (!bAvoidLineConstructor) {
1913 aNbParts=myLConstruct.NbParts();
1918 // nbiter=(bIsDecomposited) ? aSeqOfL.Length() :
1919 // ((bAvoidLineConstructor) ? 1 :aNbParts);
1921 for(i = 1; i <= nbiter; ++i) {
1922 if(bIsDecomposited) {
1923 WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i));
1925 ilprm = WL->NbPnts();
1928 if(bAvoidLineConstructor) {
1930 ilprm = WL->NbPnts();
1933 myLConstruct.Part(i, fprm, lprm);
1934 ifprm = (Standard_Integer)fprm;
1935 ilprm = (Standard_Integer)lprm;
1939 //-- Si une des surfaces est un plan , on approxime en 2d
1940 //-- sur cette surface et on remonte les points 2d en 3d.
1941 if(typs1 == GeomAbs_Plane) {
1942 theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm);
1944 else if(typs2 == GeomAbs_Plane) {
1945 theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm);
1949 if (myHS1 != myHS2){
1950 if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) &&
1951 (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) {
1953 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType);
1955 Standard_Boolean bUseSurfaces;
1956 bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm, ilprm);
1959 rejectSurface = Standard_True;
1961 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1966 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm);
1969 if (!theapp3d.IsDone()) {
1971 Handle(Geom2d_BSplineCurve) H1;
1973 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
1974 Handle(Geom2d_BSplineCurve) H2;
1977 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1981 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1984 IntTools_Curve aIC(aBSp, H1, H2);
1985 mySeqOfCurve.Append(aIC);
1989 if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) {
1990 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) {
1991 myTolReached2d = theapp3d.TolReached2d();
1994 if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) {
1995 myTolReached3d = myTolReached2d;
1997 if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
1998 if (myTolReached3d<1.e-6) {
1999 myTolReached3d = theapp3d.TolReached3d();
2000 myTolReached3d=1.e-6;
2005 else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) {
2006 myTolReached3d = theapp3d.TolReached3d();
2009 Standard_Integer aNbMultiCurves, nbpoles;
2010 aNbMultiCurves=theapp3d.NbMultiCurves();
2011 for (j=1; j<=aNbMultiCurves; j++) {
2012 if(typs1 == GeomAbs_Plane) {
2013 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2014 nbpoles = mbspc.NbPoles();
2016 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2017 TColgp_Array1OfPnt tpoles(1,nbpoles);
2019 mbspc.Curve(1,tpoles2d);
2020 const gp_Pln& Pln = myHS1->Surface().Plane();
2022 Standard_Integer ik;
2023 for(ik = 1; ik<= nbpoles; ik++) {
2025 ElSLib::Value(tpoles2d.Value(ik).X(),
2026 tpoles2d.Value(ik).Y(),
2030 Handle(Geom_BSplineCurve) BS =
2031 new Geom_BSplineCurve(tpoles,
2033 mbspc.Multiplicities(),
2035 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2036 Check.FixTangent(Standard_True, Standard_True);
2038 IntTools_Curve aCurve;
2039 aCurve.SetCurve(BS);
2042 Handle(Geom2d_BSplineCurve) BS1 =
2043 new Geom2d_BSplineCurve(tpoles2d,
2045 mbspc.Multiplicities(),
2047 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
2048 Check1.FixTangent(Standard_True,Standard_True);
2050 // ############################################
2051 if(!rejectSurface && !reApprox) {
2052 Standard_Boolean isValid = IsCurveValid(BS1);
2054 reApprox = Standard_True;
2058 // ############################################
2059 aCurve.SetFirstCurve2d(BS1);
2062 Handle(Geom2d_BSplineCurve) H1;
2063 aCurve.SetFirstCurve2d(H1);
2067 mbspc.Curve(2, tpoles2d);
2069 Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
2071 mbspc.Multiplicities(),
2073 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2074 newCheck.FixTangent(Standard_True,Standard_True);
2076 // ###########################################
2077 if(!rejectSurface && !reApprox) {
2078 Standard_Boolean isValid = IsCurveValid(BS2);
2080 reApprox = Standard_True;
2084 // ###########################################
2086 aCurve.SetSecondCurve2d(BS2);
2089 Handle(Geom2d_BSplineCurve) H2;
2091 aCurve.SetSecondCurve2d(H2);
2094 mySeqOfCurve.Append(aCurve);
2097 else if(typs2 == GeomAbs_Plane) {
2098 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2099 nbpoles = mbspc.NbPoles();
2101 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2102 TColgp_Array1OfPnt tpoles(1,nbpoles);
2103 mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d);
2104 const gp_Pln& Pln = myHS2->Surface().Plane();
2106 Standard_Integer ik;
2107 for(ik = 1; ik<= nbpoles; ik++) {
2109 ElSLib::Value(tpoles2d.Value(ik).X(),
2110 tpoles2d.Value(ik).Y(),
2115 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
2117 mbspc.Multiplicities(),
2119 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2120 Check.FixTangent(Standard_True,Standard_True);
2122 IntTools_Curve aCurve;
2123 aCurve.SetCurve(BS);
2126 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
2128 mbspc.Multiplicities(),
2130 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
2131 Check1.FixTangent(Standard_True,Standard_True);
2133 // ###########################################
2134 if(!rejectSurface && !reApprox) {
2135 Standard_Boolean isValid = IsCurveValid(BS1);
2137 reApprox = Standard_True;
2141 // ###########################################
2142 bPCurvesOk = CheckPCurve(BS1, myFace2);
2143 aCurve.SetSecondCurve2d(BS1);
2146 Handle(Geom2d_BSplineCurve) H2;
2147 aCurve.SetSecondCurve2d(H2);
2151 mbspc.Curve(1,tpoles2d);
2152 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
2154 mbspc.Multiplicities(),
2156 GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK);
2157 Check2.FixTangent(Standard_True,Standard_True);
2159 // ###########################################
2160 if(!rejectSurface && !reApprox) {
2161 Standard_Boolean isValid = IsCurveValid(BS2);
2163 reApprox = Standard_True;
2167 // ###########################################
2168 bPCurvesOk = bPCurvesOk && CheckPCurve(BS2, myFace1);
2169 aCurve.SetFirstCurve2d(BS2);
2172 Handle(Geom2d_BSplineCurve) H1;
2174 aCurve.SetFirstCurve2d(H1);
2177 //if points of the pcurves are out of the faces bounds
2178 //create 3d and 2d curves without approximation
2180 Handle(Geom2d_BSplineCurve) H1, H2;
2181 bPCurvesOk = Standard_True;
2183 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
2186 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
2187 bPCurvesOk = CheckPCurve(H1, myFace1);
2191 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
2192 bPCurvesOk = bPCurvesOk && CheckPCurve(H2, myFace2);
2195 //if pcurves created without approximation are out of the
2196 //faces bounds, use approximated 3d and 2d curves
2198 IntTools_Curve aIC(aBSp, H1, H2);
2199 mySeqOfCurve.Append(aIC);
2201 mySeqOfCurve.Append(aCurve);
2204 mySeqOfCurve.Append(aCurve);
2208 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2209 nbpoles = mbspc.NbPoles();
2210 TColgp_Array1OfPnt tpoles(1,nbpoles);
2211 mbspc.Curve(1,tpoles);
2212 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
2214 mbspc.Multiplicities(),
2216 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2217 Check.FixTangent(Standard_True,Standard_True);
2219 IntTools_Curve aCurve;
2220 aCurve.SetCurve(BS);
2224 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2225 mbspc.Curve(2,tpoles2d);
2226 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
2228 mbspc.Multiplicities(),
2230 GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK);
2231 newCheck.FixTangent(Standard_True,Standard_True);
2233 aCurve.SetFirstCurve2d(BS1);
2236 Handle(Geom2d_BSplineCurve) BS1;
2237 fprm = BS->FirstParameter();
2238 lprm = BS->LastParameter();
2240 Handle(Geom2d_Curve) C2d;
2241 Standard_Real aTol = myTolApprox;
2242 BuildPCurves(fprm, lprm, aTol, myHS1->ChangeSurface().Surface(), BS, C2d);
2243 BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2244 aCurve.SetFirstCurve2d(BS1);
2249 Handle(Geom2d_BSplineCurve) H1;
2251 aCurve.SetFirstCurve2d(H1);
2255 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2256 mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d);
2257 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
2259 mbspc.Multiplicities(),
2261 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2262 newCheck.FixTangent(Standard_True,Standard_True);
2264 aCurve.SetSecondCurve2d(BS2);
2267 Handle(Geom2d_BSplineCurve) BS2;
2268 fprm = BS->FirstParameter();
2269 lprm = BS->LastParameter();
2271 Handle(Geom2d_Curve) C2d;
2272 Standard_Real aTol = myTolApprox;
2273 BuildPCurves(fprm, lprm, aTol, myHS2->ChangeSurface().Surface(), BS, C2d);
2274 BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2275 aCurve.SetSecondCurve2d(BS2);
2280 Handle(Geom2d_BSplineCurve) H2;
2282 aCurve.SetSecondCurve2d(H2);
2285 mySeqOfCurve.Append(aCurve);
2291 }// case IntPatch_Walking:{
2294 case IntPatch_Restriction:
2300 //=======================================================================
2301 //function : BuildPCurves
2303 //=======================================================================
2304 void BuildPCurves (Standard_Real f,
2307 const Handle (Geom_Surface)& S,
2308 const Handle (Geom_Curve)& C,
2309 Handle (Geom2d_Curve)& C2d)
2312 Standard_Real umin,umax,vmin,vmax;
2317 // in class ProjLib_Function the range of parameters is shrank by 1.e-09
2318 if((l - f) > 2.e-09) {
2319 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2322 // proj. a circle that goes through the pole on a sphere to the sphere
2324 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2328 if((l - f) > Epsilon(Abs(f))) {
2329 GeomAPI_ProjectPointOnSurf aProjector1, aProjector2;
2330 gp_Pnt P1 = C->Value(f);
2331 gp_Pnt P2 = C->Value(l);
2332 aProjector1.Init(P1, S);
2333 aProjector2.Init(P2, S);
2335 if(aProjector1.IsDone() && aProjector2.IsDone()) {
2336 Standard_Real U=0., V=0.;
2337 aProjector1.LowerDistanceParameters(U, V);
2340 aProjector2.LowerDistanceParameters(U, V);
2343 if(p1.Distance(p2) > gp::Resolution()) {
2344 TColgp_Array1OfPnt2d poles(1,2);
2345 TColStd_Array1OfReal knots(1,2);
2346 TColStd_Array1OfInteger mults(1,2);
2351 mults(1) = mults(2) = 2;
2353 C2d = new Geom2d_BSplineCurve(poles,knots,mults,1);
2355 // compute reached tolerance.begin
2356 gp_Pnt PMid = C->Value((f + l) * 0.5);
2357 aProjector1.Perform(PMid);
2359 if(aProjector1.IsDone()) {
2360 aProjector1.LowerDistanceParameters(U, V);
2361 gp_Pnt2d pmidproj(U, V);
2362 gp_Pnt2d pmidcurve2d = C2d->Value((f + l) * 0.5);
2363 Standard_Real adist = pmidcurve2d.Distance(pmidproj);
2364 Tol = (adist > Tol) ? adist : Tol;
2366 // compute reached tolerance.end
2372 S->Bounds(umin, umax, vmin, vmax);
2374 if (S->IsUPeriodic() && !C2d.IsNull()) {
2375 // Recadre dans le domaine UV de la face
2376 Standard_Real period, U0, du, aEps;
2379 aEps=Precision::PConfusion();
2380 period = S->UPeriod();
2381 gp_Pnt2d Pf = C2d->Value(f);
2384 gp_Pnt2d Pl = C2d->Value(l);
2386 U0 = Min(Pl.X(), U0);
2387 // while(U0-umin<aEps) {
2388 while(U0-umin<-aEps) {
2393 while(U0-umax>aEps) {
2405 //=======================================================================
2406 //function : Parameters
2408 //=======================================================================
2409 void Parameters(const Handle(GeomAdaptor_HSurface)& HS1,
2410 const Handle(GeomAdaptor_HSurface)& HS2,
2411 const gp_Pnt& Ptref,
2418 IntSurf_Quadric quad1,quad2;
2419 GeomAbs_SurfaceType typs = HS1->Surface().GetType();
2423 quad1.SetValue(HS1->Surface().Plane());
2425 case GeomAbs_Cylinder:
2426 quad1.SetValue(HS1->Surface().Cylinder());
2429 quad1.SetValue(HS1->Surface().Cone());
2431 case GeomAbs_Sphere:
2432 quad1.SetValue(HS1->Surface().Sphere());
2435 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2438 typs = HS2->Surface().GetType();
2441 quad2.SetValue(HS2->Surface().Plane());
2443 case GeomAbs_Cylinder:
2444 quad2.SetValue(HS2->Surface().Cylinder());
2447 quad2.SetValue(HS2->Surface().Cone());
2449 case GeomAbs_Sphere:
2450 quad2.SetValue(HS2->Surface().Sphere());
2453 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2456 quad1.Parameters(Ptref,U1,V1);
2457 quad2.Parameters(Ptref,U2,V2);
2460 //=======================================================================
2461 //function : MakeBSpline
2463 //=======================================================================
2464 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL,
2465 const Standard_Integer ideb,
2466 const Standard_Integer ifin)
2468 Standard_Integer i,nbpnt = ifin-ideb+1;
2469 TColgp_Array1OfPnt poles(1,nbpnt);
2470 TColStd_Array1OfReal knots(1,nbpnt);
2471 TColStd_Array1OfInteger mults(1,nbpnt);
2472 Standard_Integer ipidebm1;
2473 for(i=1,ipidebm1=i+ideb-1; i<=nbpnt;ipidebm1++, i++) {
2474 poles(i) = WL->Point(ipidebm1).Value();
2478 mults(1) = mults(nbpnt) = 2;
2480 new Geom_BSplineCurve(poles,knots,mults,1);
2484 //=======================================================================
2485 //function : MakeBSpline2d
2487 //=======================================================================
2488 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
2489 const Standard_Integer ideb,
2490 const Standard_Integer ifin,
2491 const Standard_Boolean onFirst)
2493 Standard_Integer i, nbpnt = ifin-ideb+1;
2494 TColgp_Array1OfPnt2d poles(1,nbpnt);
2495 TColStd_Array1OfReal knots(1,nbpnt);
2496 TColStd_Array1OfInteger mults(1,nbpnt);
2497 Standard_Integer ipidebm1;
2499 for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) {
2502 theWLine->Point(ipidebm1).ParametersOnS1(U, V);
2504 theWLine->Point(ipidebm1).ParametersOnS2(U, V);
2505 poles(i).SetCoord(U, V);
2509 mults(1) = mults(nbpnt) = 2;
2511 return new Geom2d_BSplineCurve(poles,knots,mults,1);
2513 //=======================================================================
2514 //function : PrepareLines3D
2516 //=======================================================================
2517 void IntTools_FaceFace::PrepareLines3D(const Standard_Boolean bToSplit)
2519 Standard_Integer i, aNbCurves;
2520 GeomAbs_SurfaceType aType1, aType2;
2521 IntTools_SequenceOfCurves aNewCvs;
2523 // 1. Treatment closed curves
2524 aNbCurves=mySeqOfCurve.Length();
2525 for (i=1; i<=aNbCurves; ++i) {
2526 const IntTools_Curve& aIC=mySeqOfCurve(i);
2529 Standard_Integer j, aNbC;
2530 IntTools_SequenceOfCurves aSeqCvs;
2532 aNbC=IntTools_Tools::SplitCurve(aIC, aSeqCvs);
2534 for (j=1; j<=aNbC; ++j) {
2535 const IntTools_Curve& aICNew=aSeqCvs(j);
2536 aNewCvs.Append(aICNew);
2540 aNewCvs.Append(aIC);
2544 aNewCvs.Append(aIC);
2548 // 2. Plane\Cone intersection when we had 4 curves
2549 aType1=myHS1->GetType();
2550 aType2=myHS2->GetType();
2551 aNbCurves=aNewCvs.Length();
2553 if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone) ||
2554 (aType2==GeomAbs_Plane && aType1==GeomAbs_Cone)) {
2556 GeomAbs_CurveType aCType1;
2558 aCType1=aNewCvs(1).Type();
2559 if (aCType1==GeomAbs_Line) {
2560 IntTools_SequenceOfCurves aSeqIn, aSeqOut;
2562 for (i=1; i<=aNbCurves; ++i) {
2563 const IntTools_Curve& aIC=aNewCvs(i);
2567 IntTools_Tools::RejectLines(aSeqIn, aSeqOut);
2570 aNbCurves=aSeqOut.Length();
2571 for (i=1; i<=aNbCurves; ++i) {
2572 const IntTools_Curve& aIC=aSeqOut(i);
2573 aNewCvs.Append(aIC);
2577 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone)...
2579 // 3. Fill mySeqOfCurve
2580 mySeqOfCurve.Clear();
2581 aNbCurves=aNewCvs.Length();
2582 for (i=1; i<=aNbCurves; ++i) {
2583 const IntTools_Curve& aIC=aNewCvs(i);
2584 mySeqOfCurve.Append(aIC);
2587 //=======================================================================
2588 //function : CorrectSurfaceBoundaries
2590 //=======================================================================
2591 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
2592 const Standard_Real theTolerance,
2593 Standard_Real& theumin,
2594 Standard_Real& theumax,
2595 Standard_Real& thevmin,
2596 Standard_Real& thevmax)
2598 Standard_Boolean enlarge, isuperiodic, isvperiodic;
2599 Standard_Real uinf, usup, vinf, vsup, delta;
2600 GeomAbs_SurfaceType aType;
2601 Handle(Geom_Surface) aSurface;
2603 aSurface = BRep_Tool::Surface(theFace);
2604 aSurface->Bounds(uinf, usup, vinf, vsup);
2605 delta = theTolerance;
2606 enlarge = Standard_False;
2608 GeomAdaptor_Surface anAdaptorSurface(aSurface);
2610 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
2611 Handle(Geom_Surface) aBasisSurface =
2612 (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface))->BasisSurface();
2614 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2615 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2620 if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2621 Handle(Geom_Surface) aBasisSurface =
2622 (Handle(Geom_OffsetSurface)::DownCast(aSurface))->BasisSurface();
2624 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2625 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2630 isuperiodic = anAdaptorSurface.IsUPeriodic();
2631 isvperiodic = anAdaptorSurface.IsVPeriodic();
2633 aType=anAdaptorSurface.GetType();
2634 if((aType==GeomAbs_BezierSurface) ||
2635 (aType==GeomAbs_BSplineSurface) ||
2636 (aType==GeomAbs_SurfaceOfExtrusion) ||
2637 (aType==GeomAbs_SurfaceOfRevolution)) {
2638 enlarge=Standard_True;
2641 if (aType==GeomAbs_Sphere) {
2645 if (dV+delta<M_PI) {
2646 enlarge=Standard_True;
2650 if(!isuperiodic && enlarge) {
2652 if((theumin - uinf) > delta )
2658 if((usup - theumax) > delta )
2664 if(!isvperiodic && enlarge) {
2665 if((thevmin - vinf) > delta ) {
2671 if((vsup - thevmax) > delta ) {
2680 Standard_Integer aNbP;
2681 Standard_Real aXP, dXfact, aXmid, aX1, aX2, aTolPA;
2683 aTolPA=Precision::Angular();
2686 aXP=anAdaptorSurface.UPeriod();
2687 dXfact=theumax-theumin;
2688 if (dXfact-aTolPA>aXP) {
2689 aXmid=0.5*(theumax+theumin);
2690 aNbP=RealToInt(aXmid/aXP);
2695 if (theumin>aTolPA) {
2696 aX1=theumin+aNbP*aXP;
2709 aXP=anAdaptorSurface.VPeriod();
2710 dXfact=thevmax-thevmin;
2711 if (dXfact-aTolPA>aXP) {
2712 aXmid=0.5*(thevmax+thevmin);
2713 aNbP=RealToInt(aXmid/aXP);
2718 if (thevmin>aTolPA) {
2719 aX1=thevmin+aNbP*aXP;
2732 if(isuperiodic || isvperiodic) {
2733 Standard_Boolean correct = Standard_False;
2734 Standard_Boolean correctU = Standard_False;
2735 Standard_Boolean correctV = Standard_False;
2737 TopExp_Explorer anExp;
2739 for(anExp.Init(theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
2740 if(BRep_Tool::IsClosed(TopoDS::Edge(anExp.Current()), theFace)) {
2741 correct = Standard_True;
2743 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
2745 for(Standard_Integer i = 0; i < 2; i++) {
2747 anEdge.Orientation(TopAbs_FORWARD);
2750 anEdge.Orientation(TopAbs_REVERSED);
2752 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l);
2754 if(aCurve.IsNull()) {
2755 correct = Standard_False;
2758 Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve);
2760 if(aLine.IsNull()) {
2761 correct = Standard_False;
2764 gp_Dir2d anUDir(1., 0.);
2765 gp_Dir2d aVDir(0., 1.);
2766 Standard_Real anAngularTolerance = Precision::Angular();
2768 correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance);
2769 correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance);
2771 gp_Pnt2d pp1 = aCurve->Value(f);
2773 gp_Pnt2d pp2 = aCurve->Value(l);
2782 Standard_Real umin, vmin, umax, vmax;
2783 aBox.Get(umin, vmin, umax, vmax);
2785 if(isuperiodic && correctU) {
2790 if(theumax > umax) {
2794 if(isvperiodic && correctV) {
2806 // The block is dedicated to determine whether WLine [ifprm, ilprm]
2807 // crosses the degenerated zone on each given surface or not.
2808 // If Yes -> We will not use info about surfaces during approximation
2809 // because inside degenerated zone of the surface the approx. algo.
2810 // uses wrong values of normal, etc., and resulting curve will have
2811 // oscillations that we would not like to have.
2816 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2817 const Handle(Geom_Surface)& aS,
2818 const Standard_Integer iDir);
2820 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2821 const TopoDS_Face& aF1,
2822 const TopoDS_Face& aF2);
2823 //=======================================================================
2824 //function : NotUseSurfacesForApprox
2826 //=======================================================================
2827 Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1,
2828 const TopoDS_Face& aF2,
2829 const Handle(IntPatch_WLine)& WL,
2830 const Standard_Integer ifprm,
2831 const Standard_Integer ilprm)
2833 Standard_Boolean bPInDZ;
2835 Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve();
2837 const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm);
2838 bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2);
2843 const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm);
2844 bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2);
2848 //=======================================================================
2849 //function : IsPointInDegeneratedZone
2851 //=======================================================================
2852 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2853 const TopoDS_Face& aF1,
2854 const TopoDS_Face& aF2)
2857 Standard_Boolean bFlag=Standard_True;
2858 Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22;
2859 Standard_Real U1, V1, U2, V2, aDelta, aD;
2862 Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1);
2863 aS1->Bounds(US11, US12, VS11, VS12);
2864 GeomAdaptor_Surface aGAS1(aS1);
2866 Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2);
2867 aS1->Bounds(US21, US22, VS21, VS22);
2868 GeomAdaptor_Surface aGAS2(aS2);
2870 //const gp_Pnt& aP=aP2S.Value();
2871 aP2S.Parameters(U1, V1, U2, V2);
2875 aD=aGAS1.UResolution(aDelta);
2876 aP2d.SetCoord(U1, V1);
2877 if (fabs(U1-US11) < aD) {
2878 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2883 if (fabs(U1-US12) < aD) {
2884 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2889 aD=aGAS1.VResolution(aDelta);
2890 if (fabs(V1-VS11) < aDelta) {
2891 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2896 if (fabs(V1-VS12) < aDelta) {
2897 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2903 aD=aGAS2.UResolution(aDelta);
2904 aP2d.SetCoord(U2, V2);
2905 if (fabs(U2-US21) < aDelta) {
2906 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2911 if (fabs(U2-US22) < aDelta) {
2912 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2917 aD=aGAS2.VResolution(aDelta);
2918 if (fabs(V2-VS21) < aDelta) {
2919 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2924 if (fabs(V2-VS22) < aDelta) {
2925 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2933 //=======================================================================
2934 //function : IsDegeneratedZone
2936 //=======================================================================
2937 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2938 const Handle(Geom_Surface)& aS,
2939 const Standard_Integer iDir)
2941 Standard_Boolean bFlag=Standard_True;
2942 Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD;
2943 Standard_Real aXm, aYm, aXb, aYb, aXe, aYe;
2944 aS->Bounds(US1, US2, VS1, VS2);
2946 gp_Pnt aPm, aPb, aPe;
2951 aS->D0(aXm, aYm, aPm);
2968 aS->D0(aXb, aYb, aPb);
2969 aS->D0(aXe, aYe, aPe);
2971 d1=aPm.Distance(aPb);
2972 d2=aPm.Distance(aPe);
2973 if (d1 < dD && d2 < dD) {
2990 aS->D0(aXb, aYb, aPb);
2991 aS->D0(aXe, aYe, aPe);
2993 d1=aPm.Distance(aPb);
2994 d2=aPm.Distance(aPe);
2995 if (d1 < dD && d2 < dD) {
3003 //=========================================================================
3004 // static function : ComputePurgedWLine
3005 // purpose : Removes equal points (leave one of equal points) from theWLine
3006 // and recompute vertex parameters.
3007 // Returns new WLine or null WLine if the number
3008 // of the points is less than 2.
3009 //=========================================================================
3010 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine) {
3012 Standard_Integer i, k, v, nb, nbvtx;
3013 Handle(IntPatch_WLine) aResult;
3014 nbvtx = theWLine->NbVertex();
3015 nb = theWLine->NbPnts();
3017 const IntSurf_PntOn2S& p1 = theWLine->Point(1);
3018 const IntSurf_PntOn2S& p2 = theWLine->Point(2);
3019 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
3024 Handle(IntPatch_WLine) aLocalWLine;
3025 Handle(IntPatch_WLine) aTmpWLine = theWLine;
3026 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
3027 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
3028 for(i = 1; i <= nb; i++) {
3029 aLineOn2S->Add(theWLine->Point(i));
3032 for(v = 1; v <= nbvtx; v++) {
3033 aLocalWLine->AddVertex(theWLine->Vertex(v));
3036 for(i = 1; i <= aLineOn2S->NbPoints(); i++) {
3037 Standard_Integer aStartIndex = i + 1;
3038 Standard_Integer anEndIndex = i + 5;
3039 nb = aLineOn2S->NbPoints();
3040 anEndIndex = (anEndIndex > nb) ? nb : anEndIndex;
3042 if((aStartIndex > nb) || (anEndIndex <= 1)) {
3047 while(k <= anEndIndex) {
3050 IntSurf_PntOn2S p1 = aLineOn2S->Value(i);
3051 IntSurf_PntOn2S p2 = aLineOn2S->Value(k);
3053 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
3054 aTmpWLine = aLocalWLine;
3055 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
3057 for(v = 1; v <= aTmpWLine->NbVertex(); v++) {
3058 IntPatch_Point aVertex = aTmpWLine->Vertex(v);
3059 Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine();
3061 if(avertexindex >= k) {
3062 aVertex.SetParameter(aVertex.ParameterOnLine() - 1.);
3064 aLocalWLine->AddVertex(aVertex);
3066 aLineOn2S->RemovePoint(k);
3075 if(aLineOn2S->NbPoints() > 1) {
3076 aResult = aLocalWLine;
3081 //=======================================================================
3084 //=======================================================================
3085 void TolR3d(const TopoDS_Face& aF1,
3086 const TopoDS_Face& aF2,
3087 Standard_Real& myTolReached3d)
3089 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
3091 aTolTresh=2.999999e-3;
3092 aTolF1 = BRep_Tool::Tolerance(aF1);
3093 aTolF2 = BRep_Tool::Tolerance(aF2);
3094 aTolFMax=Max(aTolF1, aTolF2);
3096 if (aTolFMax>aTolTresh) {
3097 myTolReached3d=aTolFMax;
3100 //=======================================================================
3101 //function : AdjustPeriodic
3103 //=======================================================================
3104 Standard_Real AdjustPeriodic(const Standard_Real theParameter,
3105 const Standard_Real parmin,
3106 const Standard_Real parmax,
3107 const Standard_Real thePeriod,
3108 Standard_Real& theOffset)
3110 Standard_Real aresult;
3113 aresult = theParameter;
3114 while(aresult < parmin) {
3115 aresult += thePeriod;
3116 theOffset += thePeriod;
3119 while(aresult > parmax) {
3120 aresult -= thePeriod;
3121 theOffset -= thePeriod;
3125 //=======================================================================
3126 //function : IsPointOnBoundary
3128 //=======================================================================
3129 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
3130 const Standard_Real theFirstBoundary,
3131 const Standard_Real theSecondBoundary,
3132 const Standard_Real theResolution,
3133 Standard_Boolean& IsOnFirstBoundary)
3135 Standard_Boolean bRet;
3137 Standard_Real adist;
3139 bRet=Standard_False;
3140 for(i = 0; i < 2; ++i) {
3141 IsOnFirstBoundary = (i == 0);
3142 if (IsOnFirstBoundary) {
3143 adist = fabs(theParameter - theFirstBoundary);
3146 adist = fabs(theParameter - theSecondBoundary);
3148 if(adist < theResolution) {
3154 // ------------------------------------------------------------------------------------------------
3155 // static function: FindPoint
3157 // ------------------------------------------------------------------------------------------------
3158 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3159 const gp_Pnt2d& theLastPoint,
3160 const Standard_Real theUmin,
3161 const Standard_Real theUmax,
3162 const Standard_Real theVmin,
3163 const Standard_Real theVmax,
3164 gp_Pnt2d& theNewPoint) {
3166 gp_Vec2d aVec(theFirstPoint, theLastPoint);
3167 Standard_Integer i = 0, j = 0;
3169 for(i = 0; i < 4; i++) {
3170 gp_Vec2d anOtherVec;
3171 gp_Vec2d anOtherVecNormal;
3172 gp_Pnt2d aprojpoint = theLastPoint;
3175 anOtherVec.SetX(0.);
3176 anOtherVec.SetY(1.);
3177 anOtherVecNormal.SetX(1.);
3178 anOtherVecNormal.SetY(0.);
3181 aprojpoint.SetX(theUmin);
3183 aprojpoint.SetX(theUmax);
3186 anOtherVec.SetX(1.);
3187 anOtherVec.SetY(0.);
3188 anOtherVecNormal.SetX(0.);
3189 anOtherVecNormal.SetY(1.);
3192 aprojpoint.SetY(theVmin);
3194 aprojpoint.SetY(theVmax);
3196 gp_Vec2d anormvec = aVec;
3197 anormvec.Normalize();
3198 RefineVector(anormvec);
3199 Standard_Real adot1 = anormvec.Dot(anOtherVecNormal);
3201 if(fabs(adot1) < Precision::Angular())
3203 Standard_Real adist = 0.;
3204 Standard_Boolean bIsOut = Standard_False;
3207 adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax);
3208 bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax);
3211 adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax);
3212 bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax);
3214 Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1;
3216 for(j = 0; j < 2; j++) {
3217 anoffset = (j == 0) ? anoffset : -anoffset;
3218 gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset));
3219 gp_Vec2d acurvec(theLastPoint, acurpoint);
3223 Standard_Real aDotX, anAngleX;
3225 aDotX = aVec.Dot(acurvec);
3226 anAngleX = aVec.Angle(acurvec);
3228 if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) {
3230 if((acurpoint.Y() >= theVmin) &&
3231 (acurpoint.Y() <= theVmax)) {
3232 theNewPoint = acurpoint;
3233 return Standard_True;
3237 if((acurpoint.X() >= theUmin) &&
3238 (acurpoint.X() <= theUmax)) {
3239 theNewPoint = acurpoint;
3240 return Standard_True;
3246 return Standard_False;
3250 // ------------------------------------------------------------------------------------------------
3251 // static function: FindPoint
3252 // purpose: Find point on the boundary of radial tangent zone
3253 // ------------------------------------------------------------------------------------------------
3254 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3255 const gp_Pnt2d& theLastPoint,
3256 const Standard_Real theUmin,
3257 const Standard_Real theUmax,
3258 const Standard_Real theVmin,
3259 const Standard_Real theVmax,
3260 const gp_Pnt2d& theTanZoneCenter,
3261 const Standard_Real theZoneRadius,
3262 Handle(GeomAdaptor_HSurface) theGASurface,
3263 gp_Pnt2d& theNewPoint) {
3264 theNewPoint = theLastPoint;
3266 if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) )
3267 return Standard_False;
3269 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3270 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3272 Standard_Real aRadius = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3273 gp_Ax22d anAxis( theTanZoneCenter, gp_Dir2d(1, 0), gp_Dir2d(0, 1) );
3274 gp_Circ2d aCircle( anAxis, aRadius );
3277 gp_Vec2d aDir( theLastPoint.XY() - theFirstPoint.XY() );
3278 Standard_Real aLength = aDir.Magnitude();
3279 if ( aLength <= gp::Resolution() )
3280 return Standard_False;
3281 gp_Lin2d aLine( theFirstPoint, aDir );
3284 Handle(Geom2d_Line) aCLine = new Geom2d_Line( aLine );
3285 Handle(Geom2d_TrimmedCurve) aC1 = new Geom2d_TrimmedCurve( aCLine, 0, aLength );
3286 Handle(Geom2d_Circle) aC2 = new Geom2d_Circle( aCircle );
3288 Standard_Real aTol = aRadius * 0.001;
3289 aTol = ( aTol < Precision::PConfusion() ) ? Precision::PConfusion() : aTol;
3291 Geom2dAPI_InterCurveCurve anIntersector;
3292 anIntersector.Init( aC1, aC2, aTol );
3294 if ( anIntersector.NbPoints() == 0 )
3295 return Standard_False;
3297 Standard_Boolean aFound = Standard_False;
3298 Standard_Real aMinDist = aLength * aLength;
3299 Standard_Integer i = 0;
3300 for ( i = 1; i <= anIntersector.NbPoints(); i++ ) {
3301 gp_Pnt2d aPInt = anIntersector.Point( i );
3302 if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) {
3303 if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) &&
3304 ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) {
3305 theNewPoint = aPInt;
3306 aFound = Standard_True;
3314 // ------------------------------------------------------------------------------------------------
3315 // static function: IsInsideTanZone
3316 // purpose: Check if point is inside a radial tangent zone
3317 // ------------------------------------------------------------------------------------------------
3318 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
3319 const gp_Pnt2d& theTanZoneCenter,
3320 const Standard_Real theZoneRadius,
3321 Handle(GeomAdaptor_HSurface) theGASurface) {
3323 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3324 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3325 Standard_Real aRadiusSQR = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3326 aRadiusSQR *= aRadiusSQR;
3327 if ( thePoint.SquareDistance( theTanZoneCenter ) <= aRadiusSQR )
3328 return Standard_True;
3329 return Standard_False;
3332 // ------------------------------------------------------------------------------------------------
3333 // static function: CheckTangentZonesExist
3334 // purpose: Check if tangent zone exists
3335 // ------------------------------------------------------------------------------------------------
3336 Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& theSurface1,
3337 const Handle(GeomAdaptor_HSurface)& theSurface2 )
3339 if ( ( theSurface1->GetType() != GeomAbs_Torus ) ||
3340 ( theSurface2->GetType() != GeomAbs_Torus ) )
3341 return Standard_False;
3343 gp_Torus aTor1 = theSurface1->Torus();
3344 gp_Torus aTor2 = theSurface2->Torus();
3346 if ( aTor1.Location().Distance( aTor2.Location() ) > Precision::Confusion() )
3347 return Standard_False;
3349 if ( ( fabs( aTor1.MajorRadius() - aTor2.MajorRadius() ) > Precision::Confusion() ) ||
3350 ( fabs( aTor1.MinorRadius() - aTor2.MinorRadius() ) > Precision::Confusion() ) )
3351 return Standard_False;
3353 if ( ( aTor1.MajorRadius() < aTor1.MinorRadius() ) ||
3354 ( aTor2.MajorRadius() < aTor2.MinorRadius() ) )
3355 return Standard_False;
3356 return Standard_True;
3359 // ------------------------------------------------------------------------------------------------
3360 // static function: ComputeTangentZones
3362 // ------------------------------------------------------------------------------------------------
3363 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
3364 const Handle(GeomAdaptor_HSurface)& theSurface2,
3365 const TopoDS_Face& theFace1,
3366 const TopoDS_Face& theFace2,
3367 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
3368 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
3369 Handle(TColStd_HArray1OfReal)& theResultRadius,
3370 const Handle(BOPInt_Context)& aContext)
3372 Standard_Integer aResult = 0;
3373 if ( !CheckTangentZonesExist( theSurface1, theSurface2 ) )
3377 TColgp_SequenceOfPnt2d aSeqResultS1, aSeqResultS2;
3378 TColStd_SequenceOfReal aSeqResultRad;
3380 gp_Torus aTor1 = theSurface1->Torus();
3381 gp_Torus aTor2 = theSurface2->Torus();
3383 gp_Ax2 anax1( aTor1.Location(), aTor1.Axis().Direction() );
3384 gp_Ax2 anax2( aTor2.Location(), aTor2.Axis().Direction() );
3385 Standard_Integer j = 0;
3387 for ( j = 0; j < 2; j++ ) {
3388 Standard_Real aCoef = ( j == 0 ) ? -1 : 1;
3389 Standard_Real aRadius1 = fabs(aTor1.MajorRadius() + aCoef * aTor1.MinorRadius());
3390 Standard_Real aRadius2 = fabs(aTor2.MajorRadius() + aCoef * aTor2.MinorRadius());
3392 gp_Circ aCircle1( anax1, aRadius1 );
3393 gp_Circ aCircle2( anax2, aRadius2 );
3395 // roughly compute radius of tangent zone for perpendicular case
3396 Standard_Real aCriteria = Precision::Confusion() * 0.5;
3398 Standard_Real aT1 = aCriteria;
3399 Standard_Real aT2 = aCriteria;
3401 // internal tangency
3402 Standard_Real aR = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3403 //aT1 = aCriteria * aCriteria + aR * aR - ( aR - aCriteria ) * ( aR - aCriteria );
3404 aT1 = 2. * aR * aCriteria;
3408 // external tangency
3409 Standard_Real aRb = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3410 Standard_Real aRm = ( aRadius1 < aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3411 Standard_Real aDelta = aRb - aCriteria;
3413 aDelta -= aRm * aRm;
3414 aDelta /= 2. * (aRb - aRm);
3415 aDelta -= 0.5 * (aRb - aRm);
3417 aT1 = 2. * aRm * (aRm - aDelta);
3420 aCriteria = ( aT1 > aT2) ? aT1 : aT2;
3421 if ( aCriteria > 0 )
3422 aCriteria = sqrt( aCriteria );
3424 if ( aCriteria > 0.5 * aTor1.MinorRadius() ) {
3425 // too big zone -> drop to minimum
3426 aCriteria = Precision::Confusion();
3429 GeomAdaptor_Curve aC1( new Geom_Circle(aCircle1) );
3430 GeomAdaptor_Curve aC2( new Geom_Circle(aCircle2) );
3431 Extrema_ExtCC anExtrema(aC1, aC2, 0, 2. * M_PI, 0, 2. * M_PI,
3432 Precision::PConfusion(), Precision::PConfusion());
3434 if ( anExtrema.IsDone() ) {
3436 Standard_Integer i = 0;
3437 for ( i = 1; i <= anExtrema.NbExt(); i++ ) {
3438 if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria )
3441 Extrema_POnCurv P1, P2;
3442 anExtrema.Points( i, P1, P2 );
3444 Standard_Boolean bFoundResult = Standard_True;
3447 Standard_Integer surfit = 0;
3448 for ( surfit = 0; surfit < 2; surfit++ ) {
3449 GeomAPI_ProjectPointOnSurf& aProjector =
3450 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3452 gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value();
3453 aProjector.Perform(aP3d);
3455 if(!aProjector.IsDone())
3456 bFoundResult = Standard_False;
3458 if(aProjector.LowerDistance() > aCriteria) {
3459 bFoundResult = Standard_False;
3462 Standard_Real foundU = 0, foundV = 0;
3463 aProjector.LowerDistanceParameters(foundU, foundV);
3465 pr1 = gp_Pnt2d( foundU, foundV );
3467 pr2 = gp_Pnt2d( foundU, foundV );
3471 if ( bFoundResult ) {
3472 aSeqResultS1.Append( pr1 );
3473 aSeqResultS2.Append( pr2 );
3474 aSeqResultRad.Append( aCriteria );
3476 // torus is u and v periodic
3477 const Standard_Real twoPI = M_PI + M_PI;
3478 Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()};
3479 Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()};
3481 // iteration on period bounds
3482 for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) {
3483 Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI;
3484 Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI;
3486 // iteration on surfaces
3487 for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) {
3488 Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp;
3489 Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp;
3490 TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2;
3491 TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2;
3493 if (fabs(arr1[0] - aBound) < Precision::PConfusion()) {
3494 aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) );
3495 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3496 aSeqResultRad.Append( aCriteria );
3498 if (fabs(arr1[1] - aBound) < Precision::PConfusion()) {
3499 aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) );
3500 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3501 aSeqResultRad.Append( aCriteria );
3509 aResult = aSeqResultRad.Length();
3511 if ( aResult > 0 ) {
3512 theResultOnS1 = new TColgp_HArray1OfPnt2d( 1, aResult );
3513 theResultOnS2 = new TColgp_HArray1OfPnt2d( 1, aResult );
3514 theResultRadius = new TColStd_HArray1OfReal( 1, aResult );
3516 for ( Standard_Integer i = 1 ; i <= aResult; i++ ) {
3517 theResultOnS1->SetValue( i, aSeqResultS1.Value(i) );
3518 theResultOnS2->SetValue( i, aSeqResultS2.Value(i) );
3519 theResultRadius->SetValue( i, aSeqResultRad.Value(i) );
3525 // ------------------------------------------------------------------------------------------------
3526 // static function: AdjustByNeighbour
3528 // ------------------------------------------------------------------------------------------------
3529 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
3530 const gp_Pnt2d& theOriginalPoint,
3531 Handle(GeomAdaptor_HSurface) theGASurface) {
3533 gp_Pnt2d ap1 = theaNeighbourPoint;
3534 gp_Pnt2d ap2 = theOriginalPoint;
3536 if ( theGASurface->IsUPeriodic() ) {
3537 Standard_Real aPeriod = theGASurface->UPeriod();
3538 gp_Pnt2d aPTest = ap2;
3539 Standard_Real aSqDistMin = 1.e+100;
3541 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3542 aPTest.SetX( theOriginalPoint.X() + aPeriod * pIt );
3543 Standard_Real dd = ap1.SquareDistance( aPTest );
3545 if ( dd < aSqDistMin ) {
3551 if ( theGASurface->IsVPeriodic() ) {
3552 Standard_Real aPeriod = theGASurface->VPeriod();
3553 gp_Pnt2d aPTest = ap2;
3554 Standard_Real aSqDistMin = 1.e+100;
3556 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3557 aPTest.SetY( theOriginalPoint.Y() + aPeriod * pIt );
3558 Standard_Real dd = ap1.SquareDistance( aPTest );
3560 if ( dd < aSqDistMin ) {
3569 // ------------------------------------------------------------------------------------------------
3570 //function: DecompositionOfWLine
3572 // ------------------------------------------------------------------------------------------------
3573 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
3574 const Handle(GeomAdaptor_HSurface)& theSurface1,
3575 const Handle(GeomAdaptor_HSurface)& theSurface2,
3576 const TopoDS_Face& theFace1,
3577 const TopoDS_Face& theFace2,
3578 const IntTools_LineConstructor& theLConstructor,
3579 const Standard_Boolean theAvoidLConstructor,
3580 IntPatch_SequenceOfLine& theNewLines,
3581 Standard_Real& theReachedTol3d,
3582 const Handle(BOPInt_Context)& aContext)
3585 Standard_Boolean bRet, bAvoidLineConstructor;
3586 Standard_Integer aNbPnts, aNbParts;
3588 bRet=Standard_False;
3589 aNbPnts=theWLine->NbPnts();
3590 bAvoidLineConstructor=theAvoidLConstructor;
3595 if (!bAvoidLineConstructor) {
3596 aNbParts=theLConstructor.NbParts();
3602 Standard_Boolean bIsPrevPointOnBoundary, bIsPointOnBoundary, bIsCurrentPointOnBoundary;
3603 Standard_Integer nblines, pit, i, j;
3605 TColStd_Array1OfListOfInteger anArrayOfLines(1, aNbPnts);
3606 TColStd_Array1OfInteger anArrayOfLineType(1, aNbPnts);
3607 TColStd_ListOfInteger aListOfPointIndex;
3609 Handle(TColgp_HArray1OfPnt2d) aTanZoneS1;
3610 Handle(TColgp_HArray1OfPnt2d) aTanZoneS2;
3611 Handle(TColStd_HArray1OfReal) aTanZoneRadius;
3612 Standard_Integer aNbZone = ComputeTangentZones( theSurface1, theSurface2, theFace1, theFace2,
3613 aTanZoneS1, aTanZoneS2, aTanZoneRadius, aContext);
3617 aTol=Precision::Confusion();
3619 bIsPrevPointOnBoundary=Standard_False;
3620 bIsPointOnBoundary=Standard_False;
3625 for(pit = 1; pit <= aNbPnts; ++pit) {
3626 Standard_Boolean bIsOnFirstBoundary, isperiodic;
3627 Standard_Real aResolution, aPeriod, alowerboundary, aupperboundary, U, V;
3628 Standard_Real aParameter, anoffset, anAdjustPar;
3629 Standard_Real umin, umax, vmin, vmax;
3631 bIsCurrentPointOnBoundary = Standard_False;
3632 const IntSurf_PntOn2S& aPoint = theWLine->Point(pit);
3635 for(i = 0; i < 2; ++i) {
3636 Handle(GeomAdaptor_HSurface) aGASurface = (!i) ? theSurface1 : theSurface2;
3637 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3639 aPoint.ParametersOnS1(U, V);
3642 aPoint.ParametersOnS2(U, V);
3645 for(j = 0; j < 2; j++) {
3646 isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3652 aResolution=aGASurface->UResolution(aTol);
3653 aPeriod=aGASurface->UPeriod();
3654 alowerboundary=umin;
3655 aupperboundary=umax;
3659 aResolution=aGASurface->VResolution(aTol);
3660 aPeriod=aGASurface->VPeriod();
3661 alowerboundary=vmin;
3662 aupperboundary=vmax;
3667 anAdjustPar = AdjustPeriodic(aParameter,
3673 bIsOnFirstBoundary = Standard_True;// ?
3675 IsPointOnBoundary(anAdjustPar,
3679 bIsOnFirstBoundary);
3681 if(bIsPointOnBoundary) {
3682 bIsCurrentPointOnBoundary = Standard_True;
3686 // check if a point belong to a tangent zone. Begin
3687 Standard_Integer zIt = 0;
3688 for ( zIt = 1; zIt <= aNbZone; zIt++ ) {
3689 gp_Pnt2d aPZone = (i == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3690 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3692 if ( IsInsideTanZone(gp_Pnt2d( U, V ), aPZone, aZoneRadius, aGASurface ) ) {
3693 // set boundary flag to split the curve by a tangent zone
3694 bIsPointOnBoundary = Standard_True;
3695 bIsCurrentPointOnBoundary = Standard_True;
3696 if ( theReachedTol3d < aZoneRadius ) {
3697 theReachedTol3d = aZoneRadius;
3703 }//for(j = 0; j < 2; j++) {
3705 if(bIsCurrentPointOnBoundary){
3708 }//for(i = 0; i < 2; ++i) {
3710 if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) {
3711 if(!aListOfPointIndex.IsEmpty()) {
3713 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3714 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3715 aListOfPointIndex.Clear();
3717 bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary;
3719 aListOfPointIndex.Append(pit);
3720 } //for(pit = 1; pit <= aNbPnts; ++pit) {
3722 if(!aListOfPointIndex.IsEmpty()) {
3724 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3725 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3726 aListOfPointIndex.Clear();
3730 return bRet; //Standard_False;
3734 // 2. Correct wlines.begin
3735 TColStd_Array1OfListOfInteger anArrayOfLineEnds(1, nblines);
3736 Handle(IntSurf_LineOn2S) aSeqOfPntOn2S = new IntSurf_LineOn2S();
3738 for(i = 1; i <= nblines; i++) {
3739 if(anArrayOfLineType.Value(i) != 0) {
3742 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3743 if(aListOfIndex.Extent() < 2) {
3746 TColStd_ListOfInteger aListOfFLIndex;
3748 for(j = 0; j < 2; j++) {
3749 Standard_Integer aneighbourindex = (j == 0) ? (i - 1) : (i + 1);
3751 if((aneighbourindex < 1) || (aneighbourindex > nblines))
3754 if(anArrayOfLineType.Value(aneighbourindex) == 0)
3756 const TColStd_ListOfInteger& aNeighbour = anArrayOfLines.Value(aneighbourindex);
3757 Standard_Integer anIndex = (j == 0) ? aNeighbour.Last() : aNeighbour.First();
3758 const IntSurf_PntOn2S& aPoint = theWLine->Point(anIndex);
3760 IntSurf_PntOn2S aNewP = aPoint;
3762 for(Standard_Integer surfit = 0; surfit < 2; surfit++) {
3764 Handle(GeomAdaptor_HSurface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2;
3765 Standard_Real umin=0., umax=0., vmin=0., vmax=0.;
3766 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3767 Standard_Real U=0., V=0.;
3770 aNewP.ParametersOnS1(U, V);
3772 aNewP.ParametersOnS2(U, V);
3773 Standard_Integer nbboundaries = 0;
3775 Standard_Boolean bIsNearBoundary = Standard_False;
3776 Standard_Integer aZoneIndex = 0;
3777 Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1
3778 Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1
3781 for(Standard_Integer parit = 0; parit < 2; parit++) {
3782 Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3784 Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
3785 Standard_Real alowerboundary = (parit == 0) ? umin : vmin;
3786 Standard_Real aupperboundary = (parit == 0) ? umax : vmax;
3788 Standard_Real aParameter = (parit == 0) ? U : V;
3789 Standard_Boolean bIsOnFirstBoundary = Standard_True;
3793 IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3794 if(bIsPointOnBoundary) {
3795 bIsUBoundary = (parit == 0);
3796 bIsFirstBoundary = bIsOnFirstBoundary;
3801 Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3802 Standard_Real anoffset = 0.;
3803 Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
3806 IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3807 if(bIsPointOnBoundary) {
3808 bIsUBoundary = (parit == 0);
3809 bIsFirstBoundary = bIsOnFirstBoundary;
3813 //check neighbourhood of boundary
3814 Standard_Real anEpsilon = aResolution * 100.;
3815 Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
3816 anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
3818 bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary,
3819 anEpsilon, bIsOnFirstBoundary);
3825 // check if a point belong to a tangent zone. Begin
3826 for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) {
3827 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3828 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3830 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3831 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3832 Standard_Real nU1, nV1;
3835 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3837 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3838 gp_Pnt2d ap1(nU1, nV1);
3839 gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface );
3842 if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) {
3844 bIsNearBoundary = Standard_True;
3845 if ( theReachedTol3d < aZoneRadius ) {
3846 theReachedTol3d = aZoneRadius;
3850 // check if a point belong to a tangent zone. End
3851 Standard_Boolean bComputeLineEnd = Standard_False;
3853 if(nbboundaries == 2) {
3855 bComputeLineEnd = Standard_True;
3858 else if(nbboundaries == 1) {
3859 Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3862 Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
3863 Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
3864 Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3865 Standard_Real aParameter = (bIsUBoundary) ? U : V;
3866 Standard_Real anoffset = 0.;
3867 Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
3869 Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
3870 Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
3871 anotherPar += anoffset;
3872 Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3873 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
3874 Standard_Real nU1, nV1;
3877 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3879 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3881 Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
3882 Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
3883 bComputeLineEnd = Standard_True;
3884 Standard_Boolean bCheckAngle1 = Standard_False;
3885 Standard_Boolean bCheckAngle2 = Standard_False;
3887 Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
3888 Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
3890 if(((adist1 - adist2) > Precision::PConfusion()) &&
3891 (adist2 < (aPeriod / 4.))) {
3892 bCheckAngle1 = Standard_True;
3893 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
3895 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3896 aNewP.SetValue((surfit == 0), anewU, anewV);
3897 bCheckAngle1 = Standard_False;
3900 else if(adist1 < (aPeriod / 4.)) {
3901 bCheckAngle2 = Standard_True;
3902 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
3904 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3905 bCheckAngle2 = Standard_False;
3909 if(bCheckAngle1 || bCheckAngle2) {
3910 // assume there are at least two points in line (see "if" above)
3911 Standard_Integer anindexother = aneighbourpointindex;
3913 while((anindexother <= aListOfIndex.Last()) && (anindexother >= aListOfIndex.First())) {
3914 anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
3915 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
3916 Standard_Real nU2, nV2;
3919 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3921 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3922 gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
3924 if(aVecOld.SquareMagnitude() <= (gp::Resolution() * gp::Resolution())) {
3928 Standard_Real anAngle = aNewVec.Angle(aVecOld);
3930 if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
3933 Standard_Real U1, U2, V1, V2;
3934 IntSurf_PntOn2S atmppoint = aNewP;
3935 atmppoint.SetValue((surfit == 0), anewU, anewV);
3936 atmppoint.Parameters(U1, V1, U2, V2);
3937 gp_Pnt P1 = theSurface1->Value(U1, V1);
3938 gp_Pnt P2 = theSurface2->Value(U2, V2);
3939 gp_Pnt P0 = aPoint.Value();
3941 if(P0.IsEqual(P1, aTol) &&
3942 P0.IsEqual(P2, aTol) &&
3943 P1.IsEqual(P2, aTol)) {
3944 bComputeLineEnd = Standard_False;
3945 aNewP.SetValue((surfit == 0), anewU, anewV);
3950 bComputeLineEnd = Standard_False;
3955 } // end while(anindexother...)
3959 else if ( bIsNearBoundary ) {
3960 bComputeLineEnd = Standard_True;
3963 if(bComputeLineEnd) {
3966 Standard_Boolean found = Standard_False;
3968 if ( bIsNearBoundary ) {
3969 // re-compute point near natural boundary or near tangent zone
3970 Standard_Real u1, v1, u2, v2;
3971 aNewP.Parameters( u1, v1, u2, v2 );
3973 anewpoint = gp_Pnt2d( u1, v1 );
3975 anewpoint = gp_Pnt2d( u2, v2 );
3977 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3978 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3979 Standard_Real nU1, nV1;
3982 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3984 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3985 gp_Pnt2d ap1(nU1, nV1);
3990 // exclude point from a tangent zone
3991 anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3992 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex);
3993 Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex);
3995 if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax,
3996 aPZone, aZoneRadius, aGASurface, ap2) ) {
3998 found = Standard_True;
4001 else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
4002 // re-compute point near boundary if shifted on a period
4003 ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
4005 if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
4006 ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
4007 found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
4011 aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
4017 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
4018 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
4019 Standard_Real nU1, nV1;
4022 aNeighbourPoint.ParametersOnS1(nU1, nV1);
4024 aNeighbourPoint.ParametersOnS2(nU1, nV1);
4025 gp_Pnt2d ap1(nU1, nV1);
4026 gp_Pnt2d ap2(nU1, nV1);
4027 Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
4029 while((aneighbourpointindex2 <= aListOfIndex.Last()) && (aneighbourpointindex2 >= aListOfIndex.First())) {
4030 aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
4031 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
4032 Standard_Real nU2, nV2;
4035 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
4037 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
4041 if(ap1.SquareDistance(ap2) > (gp::Resolution() * gp::Resolution())) {
4045 found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
4050 Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4051 GeomAPI_ProjectPointOnSurf& aProjector =
4052 (surfit == 0) ? aContext->ProjPS(theFace2) : aContext->ProjPS(theFace1);
4053 Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
4055 Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
4057 gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
4058 aProjector.Perform(aP3d);
4060 if(aProjector.IsDone()) {
4061 if(aProjector.LowerDistance() < aCriteria) {
4062 Standard_Real foundU = U, foundV = V;
4063 aProjector.LowerDistanceParameters(foundU, foundV);
4065 //Correction of projected coordinates. Begin
4066 //Note, it may be shifted on a period
4067 Standard_Integer aneindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
4068 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
4069 Standard_Real nUn, nVn;
4072 aNeighbourPoint.ParametersOnS2(nUn, nVn);
4074 aNeighbourPoint.ParametersOnS1(nUn, nVn);
4075 gp_Pnt2d aNeighbour2d(nUn, nVn);
4076 gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
4077 foundU = anAdjustedPoint.X();
4078 foundV = anAdjustedPoint.Y();
4080 if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
4081 ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
4082 // attempt to roughly re-compute point
4083 foundU = ( foundU < umin ) ? umin : foundU;
4084 foundU = ( foundU > umax ) ? umax : foundU;
4085 foundV = ( foundV < vmin ) ? vmin : foundV;
4086 foundV = ( foundV > vmax ) ? vmax : foundV;
4088 GeomAPI_ProjectPointOnSurf& aProjector2 =
4089 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
4091 aP3d = aSurfaceOther->Value(foundU, foundV);
4092 aProjector2.Perform(aP3d);
4094 if(aProjector2.IsDone()) {
4095 if(aProjector2.LowerDistance() < aCriteria) {
4096 Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
4097 aProjector2.LowerDistanceParameters(foundU2, foundV2);
4098 anewpoint.SetX(foundU2);
4099 anewpoint.SetY(foundV2);
4103 //Correction of projected coordinates. End
4106 aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
4108 aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
4114 aSeqOfPntOn2S->Add(aNewP);
4115 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
4117 anArrayOfLineEnds.SetValue(i, aListOfFLIndex);
4119 // Correct wlines.end
4121 // Split wlines.begin
4122 Standard_Integer nbiter;
4125 if (!bAvoidLineConstructor) {
4126 nbiter=theLConstructor.NbParts();
4129 for(j = 1; j <= nbiter; ++j) {
4130 Standard_Real fprm, lprm;
4131 Standard_Integer ifprm, ilprm;
4133 if(bAvoidLineConstructor) {
4135 ilprm = theWLine->NbPnts();
4138 theLConstructor.Part(j, fprm, lprm);
4139 ifprm = (Standard_Integer)fprm;
4140 ilprm = (Standard_Integer)lprm;
4143 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
4145 for(i = 1; i <= nblines; i++) {
4146 if(anArrayOfLineType.Value(i) != 0) {
4149 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
4151 if(aListOfIndex.Extent() < 2) {
4154 const TColStd_ListOfInteger& aListOfFLIndex = anArrayOfLineEnds.Value(i);
4155 Standard_Boolean bhasfirstpoint = (aListOfFLIndex.Extent() == 2);
4156 Standard_Boolean bhaslastpoint = (aListOfFLIndex.Extent() == 2);
4158 if(!bhasfirstpoint && !aListOfFLIndex.IsEmpty()) {
4159 bhasfirstpoint = (i != 1);
4162 if(!bhaslastpoint && !aListOfFLIndex.IsEmpty()) {
4163 bhaslastpoint = (i != nblines);
4165 Standard_Boolean bIsFirstInside = ((ifprm >= aListOfIndex.First()) && (ifprm <= aListOfIndex.Last()));
4166 Standard_Boolean bIsLastInside = ((ilprm >= aListOfIndex.First()) && (ilprm <= aListOfIndex.Last()));
4168 if(!bIsFirstInside && !bIsLastInside) {
4169 if((ifprm < aListOfIndex.First()) && (ilprm > aListOfIndex.Last())) {
4170 // append whole line, and boundaries if neccesary
4171 if(bhasfirstpoint) {
4172 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
4175 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4177 for(; anIt.More(); anIt.Next()) {
4178 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4183 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
4187 // check end of split line (end is almost always)
4188 Standard_Integer aneighbour = i + 1;
4189 Standard_Boolean bIsEndOfLine = Standard_True;
4191 if(aneighbour <= nblines) {
4192 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4194 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4195 (aListOfNeighbourIndex.IsEmpty())) {
4196 bIsEndOfLine = Standard_False;
4201 if(aLineOn2S->NbPoints() > 1) {
4202 Handle(IntPatch_WLine) aNewWLine =
4203 new IntPatch_WLine(aLineOn2S, Standard_False);
4204 theNewLines.Append(aNewWLine);
4206 aLineOn2S = new IntSurf_LineOn2S();
4211 // end if(!bIsFirstInside && !bIsLastInside)
4213 if(bIsFirstInside && bIsLastInside) {
4214 // append inside points between ifprm and ilprm
4215 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4217 for(; anIt.More(); anIt.Next()) {
4218 if((anIt.Value() < ifprm) || (anIt.Value() > ilprm))
4220 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4226 if(bIsFirstInside) {
4227 // append points from ifprm to last point + boundary point
4228 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4230 for(; anIt.More(); anIt.Next()) {
4231 if(anIt.Value() < ifprm)
4233 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4238 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
4241 // check end of split line (end is almost always)
4242 Standard_Integer aneighbour = i + 1;
4243 Standard_Boolean bIsEndOfLine = Standard_True;
4245 if(aneighbour <= nblines) {
4246 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4248 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4249 (aListOfNeighbourIndex.IsEmpty())) {
4250 bIsEndOfLine = Standard_False;
4255 if(aLineOn2S->NbPoints() > 1) {
4256 Handle(IntPatch_WLine) aNewWLine =
4257 new IntPatch_WLine(aLineOn2S, Standard_False);
4258 theNewLines.Append(aNewWLine);
4260 aLineOn2S = new IntSurf_LineOn2S();
4263 // end if(bIsFirstInside)
4266 // append points from first boundary point to ilprm
4267 if(bhasfirstpoint) {
4268 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
4271 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4273 for(; anIt.More(); anIt.Next()) {
4274 if(anIt.Value() > ilprm)
4276 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4280 //end if(bIsLastInside)
4284 if(aLineOn2S->NbPoints() > 1) {
4285 Handle(IntPatch_WLine) aNewWLine =
4286 new IntPatch_WLine(aLineOn2S, Standard_False);
4287 theNewLines.Append(aNewWLine);
4292 return Standard_True;
4295 // ------------------------------------------------------------------------------------------------
4296 // static function: ParameterOutOfBoundary
4297 // purpose: Computes a new parameter for given curve. The corresponding 2d points
4298 // does not lay on any boundary of given faces
4299 // ------------------------------------------------------------------------------------------------
4300 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
4301 const Handle(Geom_Curve)& theCurve,
4302 const TopoDS_Face& theFace1,
4303 const TopoDS_Face& theFace2,
4304 const Standard_Real theOtherParameter,
4305 const Standard_Boolean bIncreasePar,
4306 Standard_Real& theNewParameter,
4307 const Handle(BOPInt_Context)& aContext)
4309 Standard_Boolean bIsComputed = Standard_False;
4310 theNewParameter = theParameter;
4312 Standard_Real acurpar = theParameter;
4313 TopAbs_State aState = TopAbs_ON;
4314 Standard_Integer iter = 0;
4315 Standard_Real asumtol = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4316 Standard_Real adelta = asumtol * 0.1;
4317 adelta = (adelta < Precision::Confusion()) ? Precision::Confusion() : adelta;
4318 Handle(Geom_Surface) aSurf1 = BRep_Tool::Surface(theFace1);
4319 Handle(Geom_Surface) aSurf2 = BRep_Tool::Surface(theFace2);
4321 Standard_Real u1, u2, v1, v2;
4323 GeomAPI_ProjectPointOnSurf aPrj1;
4324 aSurf1->Bounds(u1, u2, v1, v2);
4325 aPrj1.Init(aSurf1, u1, u2, v1, v2);
4327 GeomAPI_ProjectPointOnSurf aPrj2;
4328 aSurf2->Bounds(u1, u2, v1, v2);
4329 aPrj2.Init(aSurf2, u1, u2, v1, v2);
4331 while(aState == TopAbs_ON) {
4336 gp_Pnt aPCurrent = theCurve->Value(acurpar);
4337 aPrj1.Perform(aPCurrent);
4338 Standard_Real U=0., V=0.;
4340 if(aPrj1.IsDone()) {
4341 aPrj1.LowerDistanceParameters(U, V);
4342 aState = aContext->StatePointFace(theFace1, gp_Pnt2d(U, V));
4345 if(aState != TopAbs_ON) {
4346 aPrj2.Perform(aPCurrent);
4348 if(aPrj2.IsDone()) {
4349 aPrj2.LowerDistanceParameters(U, V);
4350 aState = aContext->StatePointFace(theFace2, gp_Pnt2d(U, V));
4361 theNewParameter = acurpar;
4362 bIsComputed = Standard_True;
4365 if(acurpar >= theOtherParameter)
4366 theNewParameter = theOtherParameter;
4369 if(acurpar <= theOtherParameter)
4370 theNewParameter = theOtherParameter;
4376 //=======================================================================
4377 //function : IsCurveValid
4379 //=======================================================================
4380 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve)
4382 if(thePCurve.IsNull())
4383 return Standard_False;
4385 Standard_Real tolint = 1.e-10;
4386 Geom2dAdaptor_Curve PCA;
4387 IntRes2d_Domain PCD;
4388 Geom2dInt_GInter PCI;
4390 Standard_Real pf = 0., pl = 0.;
4391 gp_Pnt2d pntf, pntl;
4393 if(!thePCurve->IsClosed() && !thePCurve->IsPeriodic()) {
4394 pf = thePCurve->FirstParameter();
4395 pl = thePCurve->LastParameter();
4396 pntf = thePCurve->Value(pf);
4397 pntl = thePCurve->Value(pl);
4398 PCA.Load(thePCurve);
4399 if(!PCA.IsPeriodic()) {
4400 if(PCA.FirstParameter() > pf) pf = PCA.FirstParameter();
4401 if(PCA.LastParameter() < pl) pl = PCA.LastParameter();
4403 PCD.SetValues(pntf,pf,tolint,pntl,pl,tolint);
4404 PCI.Perform(PCA,PCD,tolint,tolint);
4406 if(PCI.NbPoints() > 0) {
4407 return Standard_False;
4411 return Standard_True;
4414 //=======================================================================
4415 //static function : ApproxWithPCurves
4416 //purpose : for bug 20964 only
4417 //=======================================================================
4418 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
4419 const gp_Sphere& theSph)
4421 Standard_Boolean bRes = Standard_True;
4422 Standard_Real R1 = theCyl.Radius(), R2 = theSph.Radius();
4424 if(R1 < 2.*R2) return bRes;
4426 gp_Lin anCylAx(theCyl.Axis());
4428 Standard_Real aDist = anCylAx.Distance(theSph.Location());
4429 Standard_Real aDRel = Abs(aDist - R1)/R2;
4431 if(aDRel > .2) return bRes;
4433 Standard_Real par = ElCLib::Parameter(anCylAx, theSph.Location());
4434 gp_Pnt aP = ElCLib::Value(par, anCylAx);
4435 gp_Vec aV(aP, theSph.Location());
4437 Standard_Real dd = aV.Dot(theSph.Position().XDirection());
4439 if(aDist < R1 && dd > 0.) return Standard_False;
4440 if(aDist > R1 && dd < 0.) return Standard_False;
4445 //=======================================================================
4446 //function : PerformPlanes
4448 //=======================================================================
4449 void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
4450 const Handle(GeomAdaptor_HSurface)& theS2,
4451 const Standard_Real TolAng,
4452 const Standard_Real TolTang,
4453 const Standard_Boolean theApprox1,
4454 const Standard_Boolean theApprox2,
4455 IntTools_SequenceOfCurves& theSeqOfCurve,
4456 Standard_Boolean& theTangentFaces)
4459 gp_Pln aPln1 = theS1->Surface().Plane();
4460 gp_Pln aPln2 = theS2->Surface().Plane();
4462 IntAna_QuadQuadGeo aPlnInter(aPln1, aPln2, TolAng, TolTang);
4464 if(!aPlnInter.IsDone()) {
4465 theTangentFaces = Standard_False;
4469 IntAna_ResultType aResType = aPlnInter.TypeInter();
4471 if(aResType == IntAna_Same) {
4472 theTangentFaces = Standard_True;
4476 theTangentFaces = Standard_False;
4478 if(aResType == IntAna_Empty) {
4482 gp_Lin aLin = aPlnInter.Line(1);
4484 ProjLib_Plane aProj;
4487 aProj.Project(aLin);
4488 gp_Lin2d aLin2d1 = aProj.Line();
4491 aProj.Project(aLin);
4492 gp_Lin2d aLin2d2 = aProj.Line();
4494 //classify line2d1 relatively first plane
4495 Standard_Real P11, P12;
4496 Standard_Boolean IsCrossed = ClassifyLin2d(theS1, aLin2d1, TolTang, P11, P12);
4497 if(!IsCrossed) return;
4498 //classify line2d2 relatively second plane
4499 Standard_Real P21, P22;
4500 IsCrossed = ClassifyLin2d(theS2, aLin2d2, TolTang, P21, P22);
4501 if(!IsCrossed) return;
4503 //Analysis of parametric intervals: must have common part
4505 if(P21 >= P12) return;
4506 if(P22 <= P11) return;
4508 Standard_Real pmin, pmax;
4509 pmin = Max(P11, P21);
4510 pmax = Min(P12, P22);
4512 if(pmax - pmin <= TolTang) return;
4514 Handle(Geom_Line) aGLin = new Geom_Line(aLin);
4516 IntTools_Curve aCurve;
4517 Handle(Geom_TrimmedCurve) aGTLin = new Geom_TrimmedCurve(aGLin, pmin, pmax);
4519 aCurve.SetCurve(aGTLin);
4522 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d1);
4523 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4526 Handle(Geom2d_Curve) H1;
4527 aCurve.SetFirstCurve2d(H1);
4530 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d2);
4531 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4534 Handle(Geom2d_Curve) H1;
4535 aCurve.SetFirstCurve2d(H1);
4538 theSeqOfCurve.Append(aCurve);
4542 //=======================================================================
4543 //function : ClassifyLin2d
4545 //=======================================================================
4546 static inline Standard_Boolean INTER(const Standard_Real d1,
4547 const Standard_Real d2,
4548 const Standard_Real tol)
4550 return (d1 > tol && d2 < -tol) ||
4551 (d1 < -tol && d2 > tol) ||
4552 ((d1 <= tol && d1 >= -tol) && (d2 > tol || d2 < -tol)) ||
4553 ((d2 <= tol && d2 >= -tol) && (d1 > tol || d1 < -tol));
4555 static inline Standard_Boolean COINC(const Standard_Real d1,
4556 const Standard_Real d2,
4557 const Standard_Real tol)
4559 return (d1 <= tol && d1 >= -tol) && (d2 <= tol && d2 >= -tol);
4561 Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
4562 const gp_Lin2d& theLin2d,
4563 const Standard_Real theTol,
4564 Standard_Real& theP1,
4565 Standard_Real& theP2)
4568 Standard_Real xmin, xmax, ymin, ymax, d1, d2, A, B, C;
4569 Standard_Real par[2];
4570 Standard_Integer nbi = 0;
4572 xmin = theS->Surface().FirstUParameter();
4573 xmax = theS->Surface().LastUParameter();
4574 ymin = theS->Surface().FirstVParameter();
4575 ymax = theS->Surface().LastVParameter();
4577 theLin2d.Coefficients(A, B, C);
4579 //xmin, ymin <-> xmin, ymax
4580 d1 = A*xmin + B*ymin + C;
4581 d2 = A*xmin + B*ymax + C;
4583 if(INTER(d1, d2, theTol)) {
4584 //Intersection with boundary
4585 Standard_Real y = -(C + A*xmin)/B;
4586 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, y));
4589 else if (COINC(d1, d2, theTol)) {
4590 //Coincidence with boundary
4591 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4592 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4598 if(fabs(par[0]-par[1]) > theTol) {
4599 theP1 = Min(par[0], par[1]);
4600 theP2 = Max(par[0], par[1]);
4601 return Standard_True;
4603 else return Standard_False;
4607 //xmin, ymax <-> xmax, ymax
4609 d2 = A*xmax + B*ymax + C;
4611 if(d1 > theTol || d1 < -theTol) {//to avoid checking of
4612 //coincidence with the same point
4613 if(INTER(d1, d2, theTol)) {
4614 Standard_Real x = -(C + B*ymax)/A;
4615 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymax));
4618 else if (COINC(d1, d2, theTol)) {
4619 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4620 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4627 if(fabs(par[0]-par[1]) > theTol) {
4628 theP1 = Min(par[0], par[1]);
4629 theP2 = Max(par[0], par[1]);
4630 return Standard_True;
4632 else return Standard_False;
4636 //xmax, ymax <-> xmax, ymin
4638 d2 = A*xmax + B*ymin + C;
4640 if(d1 > theTol || d1 < -theTol) {
4641 if(INTER(d1, d2, theTol)) {
4642 Standard_Real y = -(C + A*xmax)/B;
4643 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, y));
4646 else if (COINC(d1, d2, theTol)) {
4647 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4648 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4654 if(fabs(par[0]-par[1]) > theTol) {
4655 theP1 = Min(par[0], par[1]);
4656 theP2 = Max(par[0], par[1]);
4657 return Standard_True;
4659 else return Standard_False;
4662 //xmax, ymin <-> xmin, ymin
4664 d2 = A*xmin + B*ymin + C;
4666 if(d1 > theTol || d1 < -theTol) {
4667 if(INTER(d1, d2, theTol)) {
4668 Standard_Real x = -(C + B*ymin)/A;
4669 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymin));
4672 else if (COINC(d1, d2, theTol)) {
4673 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4674 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4680 if(fabs(par[0]-par[1]) > theTol) {
4681 theP1 = Min(par[0], par[1]);
4682 theP2 = Max(par[0], par[1]);
4683 return Standard_True;
4685 else return Standard_False;
4688 return Standard_False;
4692 //=======================================================================
4693 //function : ApproxParameters
4695 //=======================================================================
4696 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
4697 const Handle(GeomAdaptor_HSurface)& aHS2,
4698 Standard_Integer& iDegMin,
4699 Standard_Integer& iDegMax,
4700 Standard_Integer& iNbIter)
4703 GeomAbs_SurfaceType aTS1, aTS2;
4710 aTS1=aHS1->Surface().GetType();
4711 aTS2=aHS2->Surface().GetType();
4714 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4715 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4716 Standard_Real aRC, aRT, dR, aPC;
4717 gp_Cylinder aCylinder;
4720 aPC=Precision::Confusion();
4722 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4723 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4725 aRC=aCylinder.Radius();
4726 aRT=aTorus.MinorRadius();
4736 if (aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Cylinder) {
4740 //=======================================================================
4741 //function : Tolerances
4743 //=======================================================================
4744 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
4745 const Handle(GeomAdaptor_HSurface)& aHS2,
4746 Standard_Real& aTolTang)
4748 GeomAbs_SurfaceType aTS1, aTS2;
4750 aTS1=aHS1->Surface().GetType();
4751 aTS2=aHS2->Surface().GetType();
4754 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4755 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4756 Standard_Real aRC, aRT, dR, aPC;
4757 gp_Cylinder aCylinder;
4760 aPC=Precision::Confusion();
4762 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4763 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4765 aRC=aCylinder.Radius();
4766 aRT=aTorus.MinorRadius();
4773 aTolTang=0.1*aTolTang;
4777 //=======================================================================
4778 //function : SortTypes
4780 //=======================================================================
4781 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
4782 const GeomAbs_SurfaceType aType2)
4784 Standard_Boolean bRet;
4785 Standard_Integer aI1, aI2;
4787 bRet=Standard_False;
4789 aI1=IndexType(aType1);
4790 aI2=IndexType(aType2);
4796 //=======================================================================
4797 //function : IndexType
4799 //=======================================================================
4800 Standard_Integer IndexType(const GeomAbs_SurfaceType aType)
4802 Standard_Integer aIndex;
4806 if (aType==GeomAbs_Plane) {
4809 else if (aType==GeomAbs_Cylinder) {
4812 else if (aType==GeomAbs_Cone) {
4815 else if (aType==GeomAbs_Sphere) {
4818 else if (aType==GeomAbs_Torus) {
4821 else if (aType==GeomAbs_BezierSurface) {
4824 else if (aType==GeomAbs_BSplineSurface) {
4827 else if (aType==GeomAbs_SurfaceOfRevolution) {
4830 else if (aType==GeomAbs_SurfaceOfExtrusion) {
4833 else if (aType==GeomAbs_OffsetSurface) {
4836 else if (aType==GeomAbs_OtherSurface) {
4841 #ifdef DEB_DUMPWLINE
4842 //=======================================================================
4843 //function : DumpWLine
4845 //=======================================================================
4846 void DumpWLine(const Handle(IntPatch_WLine)& aWLine)
4848 Standard_Integer i, aNbPnts;
4849 Standard_Real aX, aY, aZ, aU1, aV1, aU2, aV2;
4851 printf(" *WLine\n");
4852 aNbPnts=aWLine->NbPnts();
4853 for (i=1; i<=aNbPnts; ++i) {
4854 const IntSurf_PntOn2S aPntOn2S=aWLine->Point(i);
4855 const gp_Pnt& aP3D=aPntOn2S.Value();
4856 aP3D.Coord(aX, aY, aZ);
4857 aPntOn2S.Parameters(aU1, aV1, aU2, aV2);
4859 printf("point p_%d %lf %lf %lf\n", i, aX, aY, aZ);
4860 //printf("point p_%d %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf\n",
4861 // i, aX, aY, aZ, aU1, aV1, aU2, aV2);
4865 //=======================================================================
4866 //function : RefineVector
4868 //=======================================================================
4869 void RefineVector(gp_Vec2d& aV2D)
4871 Standard_Integer k,m;
4872 Standard_Real aC[2], aEps, aR1, aR2, aNum;
4878 aV2D.Coord(aC[0], aC[1]);
4880 for (k=0; k<2; ++k) {
4883 if (aNum>aR1 && aNum<aR2) {
4894 aV2D.SetCoord(aC[0], aC[1]);
4896 //=======================================================================
4897 //function : FindMaxSquareDistance
4899 //=======================================================================
4900 Standard_Real FindMaxSquareDistance (const Standard_Real aT1,
4901 const Standard_Real aT2,
4902 const Standard_Real aEps,
4903 const Handle(Geom_Curve)& aC3D,
4904 const Handle(Geom2d_Curve)& aC2D1,
4905 const Handle(Geom2d_Curve)& aC2D2,
4906 const Handle(GeomAdaptor_HSurface)& myHS1,
4907 const Handle(GeomAdaptor_HSurface)& myHS2,
4908 const TopoDS_Face& myFace1,
4909 const TopoDS_Face& myFace2,
4910 const Handle(BOPInt_Context)& myContext)
4912 Standard_Real aA, aB, aCf, aX1, aX2, aF1, aF2, aX, aF;
4914 aCf=1.6180339887498948482045868343656;// =0.5*(1.+sqrt(5.));
4918 aF1=MaxSquareDistance(aX1,
4919 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4921 aF2=MaxSquareDistance(aX2,
4922 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4926 if (fabs(aA-aB)<aEps) {
4928 aF=MaxSquareDistance(aX,
4929 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4937 aF2=MaxSquareDistance(aX2,
4938 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4946 aF1=MaxSquareDistance(aX1,
4947 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4952 //=======================================================================
4953 //function : MaxSquareDistance
4955 //=======================================================================
4956 Standard_Real MaxSquareDistance (const Standard_Real aT,
4957 const Handle(Geom_Curve)& aC3D,
4958 const Handle(Geom2d_Curve)& aC2D1,
4959 const Handle(Geom2d_Curve)& aC2D2,
4960 const Handle(GeomAdaptor_HSurface) myHS1,
4961 const Handle(GeomAdaptor_HSurface) myHS2,
4962 const TopoDS_Face& aF1,
4963 const TopoDS_Face& aF2,
4964 const Handle(BOPInt_Context)& aCtx)
4966 Standard_Boolean bIsDone;
4968 Standard_Real aU, aV, aD2Max, aD2;
4975 if (aC3D.IsNull()) {
4979 for (i=0; i<2; ++i) {
4980 const Handle(GeomAdaptor_HSurface)& aGHS=(!i) ? myHS1 : myHS2;
4981 const TopoDS_Face &aF=(!i) ? aF1 : aF2;
4982 const Handle(Geom2d_Curve)& aC2D=(!i) ? aC2D1 : aC2D2;
4984 if (!aC2D.IsNull()) {
4987 aGHS->D0(aU, aV, aPS);
4988 aD2=aP.SquareDistance(aPS);
4994 GeomAPI_ProjectPointOnSurf& aProjector=aCtx->ProjPS(aF);
4996 aProjector.Perform(aP);
4997 bIsDone=aProjector.IsDone();
4999 aProjector.LowerDistanceParameters(aU, aV);
5000 aGHS->D0(aU, aV, aPS);
5001 aD2=aP.SquareDistance(aPS);
5011 //=======================================================================
5012 //function : CheckPCurve
5013 //purpose : Checks if points of the pcurve are out of the face bounds.
5014 //=======================================================================
5015 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
5016 const TopoDS_Face& aFace)
5018 const Standard_Integer NPoints = 23;
5019 Standard_Real umin,umax,vmin,vmax;
5021 BRepTools::UVBounds(aFace, umin, umax, vmin, vmax);
5022 Standard_Real tolU = Max ((umax-umin)*0.01, Precision::Confusion());
5023 Standard_Real tolV = Max ((vmax-vmin)*0.01, Precision::Confusion());
5024 Standard_Real fp = aPC->FirstParameter();
5025 Standard_Real lp = aPC->LastParameter();
5026 Standard_Real step = (lp-fp)/(NPoints+1);
5028 // adjust domain for periodic surfaces
5029 TopLoc_Location aLoc;
5030 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc);
5031 if (aSurf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)))
5032 aSurf = (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf))->BasisSurface();
5034 gp_Pnt2d pnt = aPC->Value((fp+lp)/2);
5038 if (aSurf->IsUPeriodic()) {
5039 Standard_Real aPer = aSurf->UPeriod();
5040 Standard_Integer nshift = (Standard_Integer) ((u-umin)/aPer);
5041 if (u < umin+aPer*nshift) nshift--;
5042 umin += aPer*nshift;
5043 umax += aPer*nshift;
5045 if (aSurf->IsVPeriodic()) {
5046 Standard_Real aPer = aSurf->VPeriod();
5047 Standard_Integer nshift = (Standard_Integer) ((v-vmin)/aPer);
5048 if (v < vmin+aPer*nshift) nshift--;
5049 vmin += aPer*nshift;
5050 vmax += aPer*nshift;
5054 for (i=1; i <= NPoints; i++) {
5055 Standard_Real p = fp + i * step;
5056 pnt = aPC->Value(p);
5058 if (umin-u > tolU || u-umax > tolU ||
5059 vmin-v > tolV || v-vmax > tolV)
5060 return Standard_False;
5062 return Standard_True;