1 // Created on: 2000-11-23
2 // Created by: Michael KLOKOV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <IntTools_FaceFace.ixx>
18 #include <Precision.hxx>
20 #include <TColStd_HArray1OfReal.hxx>
21 #include <TColStd_Array1OfReal.hxx>
22 #include <TColStd_Array1OfInteger.hxx>
23 #include <TColStd_SequenceOfReal.hxx>
24 #include <TColStd_ListOfInteger.hxx>
25 #include <TColStd_ListIteratorOfListOfInteger.hxx>
26 #include <TColStd_Array1OfListOfInteger.hxx>
28 #include <gp_Lin2d.hxx>
29 #include <gp_Ax22d.hxx>
30 #include <gp_Circ2d.hxx>
31 #include <gp_Torus.hxx>
32 #include <gp_Cylinder.hxx>
34 #include <Bnd_Box.hxx>
36 #include <TColgp_HArray1OfPnt2d.hxx>
37 #include <TColgp_SequenceOfPnt2d.hxx>
38 #include <TColgp_Array1OfPnt.hxx>
39 #include <TColgp_Array1OfPnt2d.hxx>
41 #include <IntAna_QuadQuadGeo.hxx>
43 #include <IntSurf_PntOn2S.hxx>
44 #include <IntSurf_LineOn2S.hxx>
45 #include <IntSurf_PntOn2S.hxx>
46 #include <IntSurf_ListOfPntOn2S.hxx>
47 #include <IntRes2d_Domain.hxx>
48 #include <ProjLib_Plane.hxx>
50 #include <IntPatch_GLine.hxx>
51 #include <IntPatch_RLine.hxx>
52 #include <IntPatch_WLine.hxx>
53 #include <IntPatch_ALine.hxx>
54 #include <IntPatch_ALineToWLine.hxx>
59 #include <Extrema_ExtCC.hxx>
60 #include <Extrema_POnCurv.hxx>
61 #include <BndLib_AddSurface.hxx>
63 #include <Adaptor3d_SurfacePtr.hxx>
64 #include <Adaptor2d_HLine2d.hxx>
66 #include <GeomAbs_SurfaceType.hxx>
67 #include <GeomAbs_CurveType.hxx>
69 #include <Geom_Surface.hxx>
70 #include <Geom_Line.hxx>
71 #include <Geom_Circle.hxx>
72 #include <Geom_Ellipse.hxx>
73 #include <Geom_Parabola.hxx>
74 #include <Geom_Hyperbola.hxx>
75 #include <Geom_TrimmedCurve.hxx>
76 #include <Geom_BSplineCurve.hxx>
77 #include <Geom_RectangularTrimmedSurface.hxx>
78 #include <Geom_OffsetSurface.hxx>
79 #include <Geom_Curve.hxx>
80 #include <Geom_Conic.hxx>
82 #include <Geom2d_TrimmedCurve.hxx>
83 #include <Geom2d_BSplineCurve.hxx>
84 #include <Geom2d_Line.hxx>
85 #include <Geom2d_Curve.hxx>
86 #include <Geom2d_Circle.hxx>
88 #include <Geom2dAPI_InterCurveCurve.hxx>
89 #include <Geom2dInt_GInter.hxx>
90 #include <GeomAdaptor_Curve.hxx>
91 #include <GeomAdaptor_HSurface.hxx>
92 #include <GeomAdaptor_Surface.hxx>
93 #include <GeomLib_CheckBSplineCurve.hxx>
94 #include <GeomLib_Check2dBSplineCurve.hxx>
96 #include <GeomInt_WLApprox.hxx>
97 #include <GeomProjLib.hxx>
98 #include <GeomAPI_ProjectPointOnSurf.hxx>
99 #include <Geom2dAdaptor_Curve.hxx>
100 #include <TopoDS.hxx>
101 #include <TopoDS_Edge.hxx>
102 #include <TopExp_Explorer.hxx>
104 #include <BRep_Tool.hxx>
105 #include <BRepTools.hxx>
106 #include <BRepAdaptor_Surface.hxx>
108 #include <IntTools_Curve.hxx>
109 #include <IntTools_Tools.hxx>
110 #include <IntTools_Tools.hxx>
111 #include <IntTools_TopolTool.hxx>
112 #include <IntTools_PntOnFace.hxx>
113 #include <IntTools_PntOn2Faces.hxx>
114 #include <BOPInt_Context.hxx>
115 #include <IntSurf_ListIteratorOfListOfPntOn2S.hxx>
118 void RefineVector(gp_Vec2d& aV2D);
121 void DumpWLine(const Handle(IntPatch_WLine)& aWLine);
125 void TolR3d(const TopoDS_Face& ,
129 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)&,
130 const Standard_Integer,
131 const Standard_Integer);
134 void Parameters(const Handle(GeomAdaptor_HSurface)&,
135 const Handle(GeomAdaptor_HSurface)&,
143 void BuildPCurves (Standard_Real f,Standard_Real l,Standard_Real& Tol,
144 const Handle (Geom_Surface)& S,
145 const Handle (Geom_Curve)& C,
146 Handle (Geom2d_Curve)& C2d);
149 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
150 const Standard_Real theTolerance,
151 Standard_Real& theumin,
152 Standard_Real& theumax,
153 Standard_Real& thevmin,
154 Standard_Real& thevmax);
156 Standard_Boolean NotUseSurfacesForApprox
157 (const TopoDS_Face& aF1,
158 const TopoDS_Face& aF2,
159 const Handle(IntPatch_WLine)& WL,
160 const Standard_Integer ifprm,
161 const Standard_Integer ilprm);
164 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine);
167 Standard_Real AdjustPeriodic(const Standard_Real theParameter,
168 const Standard_Real parmin,
169 const Standard_Real parmax,
170 const Standard_Real thePeriod,
171 Standard_Real& theOffset);
174 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
175 const Standard_Integer ideb,
176 const Standard_Integer ifin,
177 const Standard_Boolean onFirst);
180 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
181 const Handle(GeomAdaptor_HSurface)& theSurface1,
182 const Handle(GeomAdaptor_HSurface)& theSurface2,
183 const TopoDS_Face& theFace1,
184 const TopoDS_Face& theFace2,
185 const IntTools_LineConstructor& theLConstructor,
186 const Standard_Boolean theAvoidLConstructor,
187 IntPatch_SequenceOfLine& theNewLines,
188 Standard_Real& theReachedTol3d,
189 const Handle(BOPInt_Context)& );
192 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
193 const Handle(Geom_Curve)& theCurve,
194 const TopoDS_Face& theFace1,
195 const TopoDS_Face& theFace2,
196 const Standard_Real theOtherParameter,
197 const Standard_Boolean bIncreasePar,
198 Standard_Real& theNewParameter,
199 const Handle(BOPInt_Context)& );
202 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve);
205 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
206 const Standard_Real theFirstBoundary,
207 const Standard_Real theSecondBoundary,
208 const Standard_Real theResolution,
209 Standard_Boolean& IsOnFirstBoundary);
211 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
212 const gp_Pnt2d& theLastPoint,
213 const Standard_Real theUmin,
214 const Standard_Real theUmax,
215 const Standard_Real theVmin,
216 const Standard_Real theVmax,
217 gp_Pnt2d& theNewPoint);
221 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
222 const Handle(GeomAdaptor_HSurface)& theSurface2,
223 const TopoDS_Face& theFace1,
224 const TopoDS_Face& theFace2,
225 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
226 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
227 Handle(TColStd_HArray1OfReal)& theResultRadius,
228 const Handle(BOPInt_Context)& );
231 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
232 const gp_Pnt2d& theLastPoint,
233 const Standard_Real theUmin,
234 const Standard_Real theUmax,
235 const Standard_Real theVmin,
236 const Standard_Real theVmax,
237 const gp_Pnt2d& theTanZoneCenter,
238 const Standard_Real theZoneRadius,
239 Handle(GeomAdaptor_HSurface) theGASurface,
240 gp_Pnt2d& theNewPoint);
243 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
244 const gp_Pnt2d& theTanZoneCenter,
245 const Standard_Real theZoneRadius,
246 Handle(GeomAdaptor_HSurface) theGASurface);
249 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
250 const gp_Pnt2d& theOriginalPoint,
251 Handle(GeomAdaptor_HSurface) theGASurface);
253 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
254 const gp_Sphere& theSph);
256 static void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
257 const Handle(GeomAdaptor_HSurface)& theS2,
258 const Standard_Real TolAng,
259 const Standard_Real TolTang,
260 const Standard_Boolean theApprox1,
261 const Standard_Boolean theApprox2,
262 IntTools_SequenceOfCurves& theSeqOfCurve,
263 Standard_Boolean& theTangentFaces);
265 static Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
266 const gp_Lin2d& theLin2d,
267 const Standard_Real theTol,
268 Standard_Real& theP1,
269 Standard_Real& theP2);
272 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
273 const Handle(GeomAdaptor_HSurface)& aHS2,
274 Standard_Integer& iDegMin,
275 Standard_Integer& iNbIter,
276 Standard_Integer& iDegMax);
279 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
280 const Handle(GeomAdaptor_HSurface)& aHS2,
281 Standard_Real& aTolTang);
284 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
285 const GeomAbs_SurfaceType aType2);
287 Standard_Integer IndexType(const GeomAbs_SurfaceType aType);
291 Standard_Real MaxSquareDistance (const Standard_Real aT,
292 const Handle(Geom_Curve)& aC3D,
293 const Handle(Geom2d_Curve)& aC2D1,
294 const Handle(Geom2d_Curve)& aC2D2,
295 const Handle(GeomAdaptor_HSurface) myHS1,
296 const Handle(GeomAdaptor_HSurface) myHS2,
297 const TopoDS_Face& aF1,
298 const TopoDS_Face& aF2,
299 const Handle(BOPInt_Context)& aCtx);
302 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
303 const TopoDS_Face& aFace);
307 Standard_Real FindMaxSquareDistance (const Standard_Real aA,
308 const Standard_Real aB,
309 const Standard_Real aEps,
310 const Handle(Geom_Curve)& aC3D,
311 const Handle(Geom2d_Curve)& aC2D1,
312 const Handle(Geom2d_Curve)& aC2D2,
313 const Handle(GeomAdaptor_HSurface)& myHS1,
314 const Handle(GeomAdaptor_HSurface)& myHS2,
315 const TopoDS_Face& aF1,
316 const TopoDS_Face& aF2,
317 const Handle(BOPInt_Context)& aCtx);
319 //=======================================================================
322 //=======================================================================
323 IntTools_FaceFace::IntTools_FaceFace()
325 myIsDone=Standard_False;
326 myTangentFaces=Standard_False;
328 myHS1 = new GeomAdaptor_HSurface ();
329 myHS2 = new GeomAdaptor_HSurface ();
332 SetParameters(Standard_True, Standard_True, Standard_True, 1.e-07);
335 //=======================================================================
336 //function : SetContext
338 //=======================================================================
339 void IntTools_FaceFace::SetContext(const Handle(BOPInt_Context)& aContext)
343 //=======================================================================
346 //=======================================================================
347 const Handle(BOPInt_Context)& IntTools_FaceFace::Context()const
351 //=======================================================================
354 //=======================================================================
355 const TopoDS_Face& IntTools_FaceFace::Face1() const
359 //=======================================================================
362 //=======================================================================
363 const TopoDS_Face& IntTools_FaceFace::Face2() const
367 //=======================================================================
368 //function : TangentFaces
370 //=======================================================================
371 Standard_Boolean IntTools_FaceFace::TangentFaces() const
373 return myTangentFaces;
375 //=======================================================================
378 //=======================================================================
379 const IntTools_SequenceOfPntOn2Faces& IntTools_FaceFace::Points() const
383 //=======================================================================
386 //=======================================================================
387 Standard_Boolean IntTools_FaceFace::IsDone() const
391 //=======================================================================
392 //function : TolReached3d
394 //=======================================================================
395 Standard_Real IntTools_FaceFace::TolReached3d() const
397 return myTolReached3d;
399 //=======================================================================
401 //purpose : return lines of intersection
402 //=======================================================================
403 const IntTools_SequenceOfCurves& IntTools_FaceFace::Lines() const
405 StdFail_NotDone_Raise_if
407 "IntTools_FaceFace::Lines() => myIntersector NOT DONE");
410 //=======================================================================
411 //function : TolReached2d
413 //=======================================================================
414 Standard_Real IntTools_FaceFace::TolReached2d() const
416 return myTolReached2d;
418 // =======================================================================
419 // function: SetParameters
421 // =======================================================================
422 void IntTools_FaceFace::SetParameters(const Standard_Boolean ToApproxC3d,
423 const Standard_Boolean ToApproxC2dOnS1,
424 const Standard_Boolean ToApproxC2dOnS2,
425 const Standard_Real ApproximationTolerance)
427 myApprox = ToApproxC3d;
428 myApprox1 = ToApproxC2dOnS1;
429 myApprox2 = ToApproxC2dOnS2;
430 myTolApprox = ApproximationTolerance;
432 //=======================================================================
435 //=======================================================================
436 void IntTools_FaceFace::SetList(IntSurf_ListOfPntOn2S& aListOfPnts)
438 myListOfPnts = aListOfPnts;
442 static Standard_Boolean isTreatAnalityc(const TopoDS_Face& theF1,
443 const TopoDS_Face& theF2)
445 const Standard_Real Tolang = 1.e-8;
446 const Standard_Real aTolF1=BRep_Tool::Tolerance(theF1);
447 const Standard_Real aTolF2=BRep_Tool::Tolerance(theF2);
448 const Standard_Real aTolSum = aTolF1 + aTolF2;
449 Standard_Real aHigh = 0.0;
451 const BRepAdaptor_Surface aBAS1(theF1), aBAS2(theF2);
452 const GeomAbs_SurfaceType aType1=aBAS1.GetType();
453 const GeomAbs_SurfaceType aType2=aBAS2.GetType();
457 if(aType1 == GeomAbs_Plane)
461 else if(aType2 == GeomAbs_Plane)
467 return Standard_True;
470 if(aType1 == GeomAbs_Cylinder)
472 aS2=aBAS1.Cylinder();
473 const Standard_Real VMin = aBAS1.FirstVParameter();
474 const Standard_Real VMax = aBAS1.LastVParameter();
476 if( Precision::IsNegativeInfinite(VMin) ||
477 Precision::IsPositiveInfinite(VMax))
478 return Standard_True;
482 else if(aType2 == GeomAbs_Cylinder)
484 aS2=aBAS2.Cylinder();
486 const Standard_Real VMin = aBAS2.FirstVParameter();
487 const Standard_Real VMax = aBAS2.LastVParameter();
489 if( Precision::IsNegativeInfinite(VMin) ||
490 Precision::IsPositiveInfinite(VMax))
491 return Standard_True;
497 return Standard_True;
500 IntAna_QuadQuadGeo inter;
501 inter.Perform(aS1,aS2,Tolang,aTolSum, aHigh);
502 if(inter.TypeInter() == IntAna_Ellipse)
504 const gp_Elips anEl = inter.Ellipse(1);
505 const Standard_Real aMajorR = anEl.MajorRadius();
506 const Standard_Real aMinorR = anEl.MinorRadius();
508 return (aMajorR < 100000.0 * aMinorR);
512 return inter.IsDone();
518 //=======================================================================
520 //purpose : intersect surfaces of the faces
521 //=======================================================================
522 void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
523 const TopoDS_Face& aF2)
525 Standard_Boolean RestrictLine = Standard_False, hasCone = Standard_False;
527 if (myContext.IsNull()) {
528 myContext=new BOPInt_Context;
531 mySeqOfCurve.Clear();
534 myIsDone = Standard_False;
540 const BRepAdaptor_Surface aBAS1(myFace1, Standard_False);
541 const BRepAdaptor_Surface aBAS2(myFace2, Standard_False);
542 GeomAbs_SurfaceType aType1=aBAS1.GetType();
543 GeomAbs_SurfaceType aType2=aBAS2.GetType();
545 const Standard_Boolean bReverse=SortTypes(aType1, aType2);
550 aType1=aBAS2.GetType();
551 aType2=aBAS1.GetType();
553 if (myListOfPnts.Extent())
555 Standard_Real aU1,aV1,aU2,aV2;
556 IntSurf_ListIteratorOfListOfPntOn2S aItP2S;
558 aItP2S.Initialize(myListOfPnts);
559 for (; aItP2S.More(); aItP2S.Next())
561 IntSurf_PntOn2S& aP2S=aItP2S.Value();
562 aP2S.Parameters(aU1,aV1,aU2,aV2);
563 aP2S.SetValue(aU2,aV2,aU1,aV1);
569 const Handle(Geom_Surface) S1=BRep_Tool::Surface(myFace1);
570 const Handle(Geom_Surface) S2=BRep_Tool::Surface(myFace2);
572 const Standard_Real aTolF1=BRep_Tool::Tolerance(myFace1);
573 const Standard_Real aTolF2=BRep_Tool::Tolerance(myFace2);
575 Standard_Real TolArc = aTolF1 + aTolF2;
576 Standard_Real TolTang = TolArc;
578 const Standard_Boolean isFace1Quad = (aType1 == GeomAbs_Cylinder ||
579 aType1 == GeomAbs_Cone ||
580 aType1 == GeomAbs_Torus);
582 const Standard_Boolean isFace2Quad = (aType2 == GeomAbs_Cylinder ||
583 aType2 == GeomAbs_Cone ||
584 aType2 == GeomAbs_Torus);
586 if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane)
588 Standard_Real umin, umax, vmin, vmax;
589 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
590 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
592 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
593 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
594 Standard_Real TolAng = 1.e-8;
596 PerformPlanes(myHS1, myHS2, TolAng, TolTang, myApprox1, myApprox2,
597 mySeqOfCurve, myTangentFaces);
599 myIsDone = Standard_True;
603 const Standard_Integer NbLinPP = mySeqOfCurve.Length();
606 Standard_Real aTolFMax;
607 myTolReached3d = 1.e-7;
608 aTolFMax=Max(aTolF1, aTolF2);
609 if (aTolFMax>myTolReached3d)
611 myTolReached3d=aTolFMax;
614 myTolReached2d = myTolReached3d;
618 Handle(Geom2d_Curve) aC2D1, aC2D2;
619 const Standard_Integer aNbLin = mySeqOfCurve.Length();
620 for (Standard_Integer i = 1; i <= aNbLin; ++i)
622 IntTools_Curve& aIC=mySeqOfCurve(i);
623 aC2D1=aIC.FirstCurve2d();
624 aC2D2=aIC.SecondCurve2d();
625 aIC.SetFirstCurve2d(aC2D2);
626 aIC.SetSecondCurve2d(aC2D1);
633 }//if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
635 if ((aType1==GeomAbs_Plane) && isFace2Quad)
637 Standard_Real dU, dV;
640 Standard_Real umin, umax, vmin, vmax;
641 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
649 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
651 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
652 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
653 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
655 if( aType2==GeomAbs_Cone ) {
657 hasCone = Standard_True;
660 else if ((aType2==GeomAbs_Plane) && isFace1Quad)
662 Standard_Real dU, dV;
665 Standard_Real umin, umax, vmin, vmax;
666 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
667 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
668 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
670 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
677 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
679 if( aType1==GeomAbs_Cone ) {
681 hasCone = Standard_True;
686 Standard_Real umin, umax, vmin, vmax;
687 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
688 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
689 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
690 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
691 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
692 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
695 const Handle(IntTools_TopolTool) dom1 = new IntTools_TopolTool(myHS1);
696 const Handle(IntTools_TopolTool) dom2 = new IntTools_TopolTool(myHS2);
698 myLConstruct.Load(dom1, dom2, myHS1, myHS2);
701 Tolerances(myHS1, myHS2, TolTang);
704 const Standard_Real UVMaxStep = 0.001;
705 const Standard_Real Deflection = (hasCone) ? 0.085 : 0.1;
706 myIntersector.SetTolerances(TolArc, TolTang, UVMaxStep, Deflection);
709 if((myHS1->IsUClosed() && !myHS1->IsUPeriodic()) ||
710 (myHS1->IsVClosed() && !myHS1->IsVPeriodic()) ||
711 (myHS2->IsUClosed() && !myHS2->IsUPeriodic()) ||
712 (myHS2->IsVClosed() && !myHS2->IsVPeriodic()))
714 RestrictLine = Standard_True;
717 if((aType1 != GeomAbs_BSplineSurface) &&
718 (aType1 != GeomAbs_BezierSurface) &&
719 (aType1 != GeomAbs_OtherSurface) &&
720 (aType2 != GeomAbs_BSplineSurface) &&
721 (aType2 != GeomAbs_BezierSurface) &&
722 (aType2 != GeomAbs_OtherSurface))
724 RestrictLine = Standard_True;
726 if ((aType1 == GeomAbs_Torus) ||
727 (aType2 == GeomAbs_Torus))
729 myListOfPnts.Clear();
736 TopExp_Explorer aExp;
737 for(Standard_Integer i = 0; (!RestrictLine) && (i < 2); i++)
739 const TopoDS_Face& aF=(!i) ? myFace1 : myFace2;
740 aExp.Init(aF, TopAbs_EDGE);
741 for(; aExp.More(); aExp.Next())
743 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
745 if(BRep_Tool::Degenerated(aE))
747 RestrictLine = Standard_True;
754 const Standard_Boolean isGeomInt = isTreatAnalityc(aF1, aF2);
755 myIntersector.Perform(myHS1, dom1, myHS2, dom2, TolArc, TolTang,
756 myListOfPnts, RestrictLine, isGeomInt);
758 myIsDone = myIntersector.IsDone();
762 myTangentFaces=myIntersector.TangentFaces();
763 if (myTangentFaces) {
768 myListOfPnts.Clear(); // to use LineConstructor
771 const Standard_Integer aNbLin = myIntersector.NbLines();
772 for (Standard_Integer i=1; i <= aNbLin; ++i) {
773 MakeCurve(i, dom1, dom2);
776 ComputeTolReached3d();
779 Handle(Geom2d_Curve) aC2D1, aC2D2;
781 const Standard_Integer aNbLin=mySeqOfCurve.Length();
782 for (Standard_Integer i=1; i<=aNbLin; ++i)
784 IntTools_Curve& aIC=mySeqOfCurve(i);
785 aC2D1=aIC.FirstCurve2d();
786 aC2D2=aIC.SecondCurve2d();
787 aIC.SetFirstCurve2d(aC2D2);
788 aIC.SetSecondCurve2d(aC2D1);
793 Standard_Real U1,V1,U2,V2;
794 IntTools_PntOnFace aPntOnF1, aPntOnF2;
795 IntTools_PntOn2Faces aPntOn2Faces;
797 const Standard_Integer aNbPnts = myIntersector.NbPnts();
798 for (Standard_Integer i=1; i <= aNbPnts; ++i)
800 const IntSurf_PntOn2S& aISPnt=myIntersector.Point(i).PntOn2S();
801 const gp_Pnt& aPnt=aISPnt.Value();
802 aISPnt.Parameters(U1,V1,U2,V2);
803 aPntOnF1.Init(myFace1, aPnt, U1, V1);
804 aPntOnF2.Init(myFace2, aPnt, U2, V2);
808 aPntOn2Faces.SetP1(aPntOnF1);
809 aPntOn2Faces.SetP2(aPntOnF2);
813 aPntOn2Faces.SetP2(aPntOnF1);
814 aPntOn2Faces.SetP1(aPntOnF2);
817 myPnts.Append(aPntOn2Faces);
822 //=======================================================================
823 //function :ComputeTolReached3d
825 //=======================================================================
826 void IntTools_FaceFace::ComputeTolReached3d()
828 Standard_Boolean bCase1;
829 Standard_Integer aNbLin, i;
830 GeomAbs_SurfaceType aType1, aType2;
832 aNbLin=myIntersector.NbLines();
837 aType1=myHS1->Surface().GetType();
838 aType2=myHS2->Surface().GetType();
840 bCase1=((aType1==GeomAbs_Plane && aType2==GeomAbs_SurfaceOfExtrusion) ||
841 (aType2==GeomAbs_Plane && aType1==GeomAbs_SurfaceOfExtrusion));
843 if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
845 Handle(IntPatch_Line) aIL1, aIL2;
846 IntPatch_IType aTL1, aTL2;
848 aIL1=myIntersector.Line(1);
849 aIL2=myIntersector.Line(2);
850 aTL1=aIL1->ArcType();
851 aTL2=aIL2->ArcType();
852 if (aTL1==IntPatch_Lin && aTL2==IntPatch_Lin) {
853 Standard_Real aD, aDTresh, dTol;
859 aL1=Handle(IntPatch_GLine)::DownCast(aIL1)->Line();
860 aL2=Handle(IntPatch_GLine)::DownCast(aIL2)->Line();
861 aD=aL1.Distance(aL2);
864 myTolReached3d=aD+dTol;
870 if (aNbLin) {// Check the distances
871 Standard_Integer aNbP, j ;
872 Standard_Real aT1, aT2, dT, aD2, aD2Max, aEps, aT11, aT12;
876 aNbLin=mySeqOfCurve.Length();
878 for (i=1; i<=aNbLin; ++i) {
879 const IntTools_Curve& aIC=mySeqOfCurve(i);
880 const Handle(Geom_Curve)& aC3D=aIC.Curve();
881 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
882 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
887 const Handle(Geom_BSplineCurve)& aBC=
888 Handle(Geom_BSplineCurve)::DownCast(aC3D);
893 aT1=aBC->FirstParameter();
894 aT2=aBC->LastParameter();
898 for (j=1; j<aNbP; ++j) {
901 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
902 myHS1, myHS2, myFace1, myFace2, myContext);
907 }//for (i=1; i<=aNbLin; ++i) {
909 myTolReached3d=sqrt(aD2Max);
911 }// if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
914 else if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
915 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
919 aTolF1 = BRep_Tool::Tolerance(myFace1);
920 aTolF2 = BRep_Tool::Tolerance(myFace2);
921 aTolFMax=Max(aTolF1, aTolF2);
923 if (aTolFMax>aTolTresh) {
924 myTolReached3d=aTolFMax;
926 }//if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
929 else if((aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) ||
930 (aType2 == GeomAbs_Cylinder && aType1 == GeomAbs_Plane)) {
932 const Handle(IntPatch_Line)& aIL1 = myIntersector.Line(1);
933 if(aIL1->ArcType() == IntPatch_Circle) {
934 gp_Circ aCir = Handle(IntPatch_GLine)::DownCast(aIL1)->Circle();
935 gp_XYZ aCirDir = aCir.Axis().Direction().XYZ();
938 if(aType1 == GeomAbs_Plane) {
939 aPln = myHS1->Surface().Plane();
942 aPln = myHS2->Surface().Plane();
944 aPlDir = aPln.Axis().Direction().XYZ();
945 Standard_Real cs = aCirDir*aPlDir;
946 if(cs < 0.) aPlDir.Reverse();
947 Standard_Real eps = 1.e-14;
948 if(!aPlDir.IsEqual(aCirDir, eps)) {
949 Standard_Integer aNbP = 11;
950 Standard_Real dt = 2.*M_PI / (aNbP - 1), t;
951 for(t = 0.; t < 2.*M_PI; t += dt) {
952 Standard_Real d = aPln.Distance(ElCLib::Value(t, aCir));
953 if(myTolReached3d < d) myTolReached3d = d;
955 myTolReached3d *= 1.1;
957 } //aIL1->ArcType() == IntPatch_Circle
959 } // aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane)
960 //End IFV Bug OCC20297
962 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
963 (aType2==GeomAbs_Plane && aType1==GeomAbs_Torus)) {
964 aNbLin=mySeqOfCurve.Length();
969 Standard_Integer aNbP;
970 Standard_Real aT, aT1, aT2, dT, aUT, aVT, aUP, aVP;
971 Standard_Real aDP, aDT, aDmax;
976 const IntTools_Curve& aIC=mySeqOfCurve(1);
977 const Handle(Geom_Curve)& aC3D=aIC.Curve();
978 const Handle(Geom_BSplineCurve)& aBS=
979 Handle(Geom_BSplineCurve)::DownCast(aC3D);
984 aT1=aBS->FirstParameter();
985 aT2=aBS->LastParameter();
987 aPln =(aType1==GeomAbs_Plane) ? myHS1->Plane() : myHS2->Plane();
988 aTorus=(aType1==GeomAbs_Plane) ? myHS2->Torus() : myHS1->Torus();
992 dT=(aT2-aT1)/(aNbP-1);
993 for (i=0; i<aNbP; ++i) {
1001 ElSLib::Parameters(aPln, aP, aUP, aVP);
1002 aPP=ElSLib::Value(aUP, aVP, aPln);
1003 aDP=aP.SquareDistance(aPP);
1008 ElSLib::Parameters(aTorus, aP, aUT, aVT);
1009 aPT=ElSLib::Value(aUT, aVT, aTorus);
1010 aDT=aP.SquareDistance(aPT);
1016 if (aDmax > myTolReached3d*myTolReached3d) {
1017 myTolReached3d=sqrt(aDmax);
1018 myTolReached3d=1.1*myTolReached3d;
1020 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
1022 else if ((aType1==GeomAbs_SurfaceOfRevolution && aType2==GeomAbs_Cylinder) ||
1023 (aType2==GeomAbs_SurfaceOfRevolution && aType1==GeomAbs_Cylinder)) {
1024 Standard_Integer j, aNbP;
1025 Standard_Real aT, aT1, aT2, dT, aD2max, aD2;
1027 aNbLin=mySeqOfCurve.Length();
1031 for (i=1; i<=aNbLin; ++i) {
1032 const IntTools_Curve& aIC=mySeqOfCurve(i);
1033 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1034 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
1035 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1037 if (aC3D.IsNull()) {
1040 const Handle(Geom_BSplineCurve)& aBC=
1041 Handle(Geom_BSplineCurve)::DownCast(aC3D);
1046 aT1=aBC->FirstParameter();
1047 aT2=aBC->LastParameter();
1049 dT=(aT2-aT1)/(aNbP-1);
1050 for (j=0; j<aNbP; ++j) {
1056 aD2=MaxSquareDistance(aT, aC3D, aC2D1, aC2D2,
1057 myHS1, myHS2, myFace1, myFace2, myContext);
1061 }//for (j=0; j<aNbP; ++j) {
1063 }//for (i=1; i<=aNbLin; ++i) {
1065 aD2=myTolReached3d*myTolReached3d;
1067 myTolReached3d=sqrt(aD2max);
1069 }//if((aType1==GeomAbs_SurfaceOfRevolution ...
1070 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ||
1071 (aType2==GeomAbs_Plane && aType1==GeomAbs_Sphere)) {
1072 Standard_Integer j, aNbP;
1073 Standard_Real aT1, aT2, dT, aD2max, aD2, aEps, aT11, aT12;
1075 aNbLin=mySeqOfCurve.Length();
1079 for (i=1; i<=aNbLin; ++i) {
1080 const IntTools_Curve& aIC=mySeqOfCurve(i);
1081 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1082 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
1083 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1085 const Handle(Geom2d_BSplineCurve)& aBC2D1=
1086 Handle(Geom2d_BSplineCurve)::DownCast(aC2D1);
1087 const Handle(Geom2d_BSplineCurve)& aBC2D2=
1088 Handle(Geom2d_BSplineCurve)::DownCast(aC2D2);
1090 if (aBC2D1.IsNull() && aBC2D2.IsNull()) {
1094 if (!aBC2D1.IsNull()) {
1095 aT1=aBC2D1->FirstParameter();
1096 aT2=aBC2D1->LastParameter();
1099 aT1=aBC2D2->FirstParameter();
1100 aT2=aBC2D2->LastParameter();
1103 aEps=0.01*(aT2-aT1);
1105 for (j=0; j<aNbP; ++j) {
1112 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
1113 myHS1, myHS2, myFace1, myFace2, myContext);
1117 }//for (j=0; j<aNbP; ++j) {
1119 }//for (i=1; i<=aNbLin; ++i) {
1121 aD2=myTolReached3d*myTolReached3d;
1123 myTolReached3d=sqrt(aD2max);
1125 }//else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ...
1126 else if (!myApprox || bCase1) {
1127 //else if (!myApprox) {
1128 Standard_Integer aNbP, j;
1129 Standard_Real aT1, aT2, dT, aD2, aD2Max, aEps, aT11, aT12;
1132 aNbLin=mySeqOfCurve.Length();
1134 for (i=1; i<=aNbLin; ++i) {
1135 const IntTools_Curve& aIC=mySeqOfCurve(i);
1136 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1137 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
1138 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1140 if (aC3D.IsNull()) {
1143 const Handle(Geom_BSplineCurve)& aBC=
1144 Handle(Geom_BSplineCurve)::DownCast(aC3D);
1149 aT1=aBC->FirstParameter();
1150 aT2=aBC->LastParameter();
1152 aEps=0.0001*(aT2-aT1);
1155 for (j=1; j<aNbP-1; ++j) {
1158 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
1159 myHS1, myHS2, myFace1, myFace2, myContext);
1164 }//for (i=1; i<=aNbLin; ++i) {
1165 myTolReached3d=sqrt(aD2Max);
1168 //=======================================================================
1169 //function : MakeCurve
1171 //=======================================================================
1172 void IntTools_FaceFace::MakeCurve(const Standard_Integer Index,
1173 const Handle(Adaptor3d_TopolTool)& dom1,
1174 const Handle(Adaptor3d_TopolTool)& dom2)
1176 Standard_Boolean bDone, rejectSurface, reApprox, bAvoidLineConstructor;
1177 Standard_Boolean ok, bPCurvesOk;
1178 Standard_Integer i, j, aNbParts;
1179 Standard_Real fprm, lprm;
1180 Standard_Real Tolpc;
1181 Handle(IntPatch_Line) L;
1182 IntPatch_IType typl;
1183 Handle(Geom_Curve) newc;
1185 const Standard_Real TOLCHECK =0.0000001;
1186 const Standard_Real TOLANGCHECK=0.1;
1188 rejectSurface = Standard_False;
1189 reApprox = Standard_False;
1191 bPCurvesOk = Standard_True;
1195 Tolpc = myTolApprox;
1196 bAvoidLineConstructor = Standard_False;
1197 L = myIntersector.Line(Index);
1198 typl = L->ArcType();
1200 if(typl==IntPatch_Walking) {
1201 Handle(IntPatch_Line) anewL;
1203 const Handle(IntPatch_WLine)& aWLine=
1204 Handle(IntPatch_WLine)::DownCast(L);
1205 //DumpWLine(aWLine);
1207 anewL = ComputePurgedWLine(aWLine);
1208 if(anewL.IsNull()) {
1213 //const Handle(IntPatch_WLine)& aWLineX = Handle(IntPatch_WLine)::DownCast(L);
1214 //DumpWLine(aWLineX);
1217 if(!myListOfPnts.IsEmpty()) {
1218 bAvoidLineConstructor = Standard_True;
1221 Standard_Integer nbp = aWLine->NbPnts();
1222 const IntSurf_PntOn2S& p1 = aWLine->Point(1);
1223 const IntSurf_PntOn2S& p2 = aWLine->Point(nbp);
1225 const gp_Pnt& P1 = p1.Value();
1226 const gp_Pnt& P2 = p2.Value();
1228 if(P1.SquareDistance(P2) < 1.e-14) {
1229 bAvoidLineConstructor = Standard_False;
1234 if(!bAvoidLineConstructor) {
1235 myLConstruct.Perform(L);
1237 bDone=myLConstruct.IsDone();
1238 aNbParts=myLConstruct.NbParts();
1239 if (!bDone|| !aNbParts) {
1248 //########################################
1249 // Line, Parabola, Hyperbola
1250 //########################################
1252 case IntPatch_Parabola:
1253 case IntPatch_Hyperbola: {
1254 if (typl == IntPatch_Lin) {
1256 new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line());
1259 else if (typl == IntPatch_Parabola) {
1261 new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola());
1264 else if (typl == IntPatch_Hyperbola) {
1266 new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola());
1270 if (typl == IntPatch_Lin) {
1271 TolR3d (myFace1, myFace2, myTolReached3d);
1274 aNbParts=myLConstruct.NbParts();
1275 for (i=1; i<=aNbParts; i++) {
1276 myLConstruct.Part(i, fprm, lprm);
1278 if (!Precision::IsNegativeInfinite(fprm) &&
1279 !Precision::IsPositiveInfinite(lprm)) {
1281 IntTools_Curve aCurve;
1283 Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm);
1284 aCurve.SetCurve(aCT3D);
1285 if (typl == IntPatch_Parabola) {
1286 Standard_Real aTolF1, aTolF2, aTolBase;
1288 aTolF1 = BRep_Tool::Tolerance(myFace1);
1289 aTolF2 = BRep_Tool::Tolerance(myFace2);
1290 aTolBase=aTolF1+aTolF2;
1291 myTolReached3d=IntTools_Tools::CurveTolerance(aCT3D, aTolBase);
1294 aCurve.SetCurve(new Geom_TrimmedCurve(newc, fprm, lprm));
1296 Handle (Geom2d_Curve) C2d;
1297 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1298 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1299 myTolReached2d=Tolpc;
1302 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1305 Handle(Geom2d_BSplineCurve) H1;
1307 aCurve.SetFirstCurve2d(H1);
1311 Handle (Geom2d_Curve) C2d;
1312 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1313 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1314 myTolReached2d=Tolpc;
1317 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1320 Handle(Geom2d_BSplineCurve) H1;
1322 aCurve.SetSecondCurve2d(H1);
1324 mySeqOfCurve.Append(aCurve);
1325 } // end of if (!Precision::IsNegativeInfinite(fprm) && !Precision::IsPositiveInfinite(lprm))
1327 // on regarde si on garde
1329 Standard_Boolean bFNIt, bLPIt;
1330 Standard_Real aTestPrm, dT=100.;
1332 bFNIt=Precision::IsNegativeInfinite(fprm);
1333 bLPIt=Precision::IsPositiveInfinite(lprm);
1337 if (bFNIt && !bLPIt) {
1340 else if (!bFNIt && bLPIt) {
1344 gp_Pnt ptref(newc->Value(aTestPrm));
1346 GeomAbs_SurfaceType typS1 = myHS1->GetType();
1347 GeomAbs_SurfaceType typS2 = myHS2->GetType();
1348 if( typS1 == GeomAbs_SurfaceOfExtrusion ||
1349 typS1 == GeomAbs_OffsetSurface ||
1350 typS1 == GeomAbs_SurfaceOfRevolution ||
1351 typS2 == GeomAbs_SurfaceOfExtrusion ||
1352 typS2 == GeomAbs_OffsetSurface ||
1353 typS2 == GeomAbs_SurfaceOfRevolution)
1355 Handle(Geom2d_BSplineCurve) H1;
1356 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1360 Standard_Real u1, v1, u2, v2, Tol;
1362 Tol = Precision::Confusion();
1363 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1364 ok = (dom1->Classify(gp_Pnt2d(u1, v1), Tol) != TopAbs_OUT);
1366 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1369 Handle(Geom2d_BSplineCurve) H1;
1370 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1373 }// end of for (i=1; i<=myLConstruct.NbParts(); i++)
1374 }// case IntPatch_Lin: case IntPatch_Parabola: case IntPatch_Hyperbola:
1377 //########################################
1378 // Circle and Ellipse
1379 //########################################
1380 case IntPatch_Circle:
1381 case IntPatch_Ellipse: {
1383 if (typl == IntPatch_Circle) {
1384 newc = new Geom_Circle
1385 (Handle(IntPatch_GLine)::DownCast(L)->Circle());
1387 else { //IntPatch_Ellipse
1388 newc = new Geom_Ellipse
1389 (Handle(IntPatch_GLine)::DownCast(L)->Ellipse());
1393 TolR3d (myFace1, myFace2, myTolReached3d);
1395 aNbParts=myLConstruct.NbParts();
1397 Standard_Real aPeriod, aNul;
1398 TColStd_SequenceOfReal aSeqFprm, aSeqLprm;
1403 for (i=1; i<=aNbParts; i++) {
1404 myLConstruct.Part(i, fprm, lprm);
1406 if (fprm < aNul && lprm > aNul) {
1407 // interval that goes through 0. is divided on two intervals;
1408 while (fprm<aNul || fprm>aPeriod) fprm=fprm+aPeriod;
1409 while (lprm<aNul || lprm>aPeriod) lprm=lprm+aPeriod;
1411 if((aPeriod - fprm) > Tolpc) {
1412 aSeqFprm.Append(fprm);
1413 aSeqLprm.Append(aPeriod);
1416 gp_Pnt P1 = newc->Value(fprm);
1417 gp_Pnt P2 = newc->Value(aPeriod);
1418 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1419 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1421 if(P1.Distance(P2) > aTolDist) {
1422 Standard_Real anewpar = fprm;
1424 if(ParameterOutOfBoundary(fprm, newc, myFace1, myFace2,
1425 lprm, Standard_False, anewpar, myContext)) {
1428 aSeqFprm.Append(fprm);
1429 aSeqLprm.Append(aPeriod);
1434 if((lprm - aNul) > Tolpc) {
1435 aSeqFprm.Append(aNul);
1436 aSeqLprm.Append(lprm);
1439 gp_Pnt P1 = newc->Value(aNul);
1440 gp_Pnt P2 = newc->Value(lprm);
1441 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1442 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1444 if(P1.Distance(P2) > aTolDist) {
1445 Standard_Real anewpar = lprm;
1447 if(ParameterOutOfBoundary(lprm, newc, myFace1, myFace2,
1448 fprm, Standard_True, anewpar, myContext)) {
1451 aSeqFprm.Append(aNul);
1452 aSeqLprm.Append(lprm);
1458 aSeqFprm.Append(fprm);
1459 aSeqLprm.Append(lprm);
1464 aNbParts=aSeqFprm.Length();
1465 for (i=1; i<=aNbParts; i++) {
1469 Standard_Real aRealEpsilon=RealEpsilon();
1470 if (Abs(fprm) > aRealEpsilon || Abs(lprm-2.*M_PI) > aRealEpsilon) {
1471 //==============================================
1473 IntTools_Curve aCurve;
1474 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1475 aCurve.SetCurve(aTC3D);
1476 fprm=aTC3D->FirstParameter();
1477 lprm=aTC3D->LastParameter ();
1479 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {////
1481 Handle (Geom2d_Curve) C2d;
1482 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1483 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1484 myTolReached2d=Tolpc;
1487 aCurve.SetFirstCurve2d(C2d);
1490 Handle(Geom2d_BSplineCurve) H1;
1491 aCurve.SetFirstCurve2d(H1);
1496 Handle (Geom2d_Curve) C2d;
1497 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1498 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1499 myTolReached2d=Tolpc;
1502 aCurve.SetSecondCurve2d(C2d);
1505 Handle(Geom2d_BSplineCurve) H1;
1506 aCurve.SetSecondCurve2d(H1);
1511 Handle(Geom2d_BSplineCurve) H1;
1512 aCurve.SetFirstCurve2d(H1);
1513 aCurve.SetSecondCurve2d(H1);
1515 mySeqOfCurve.Append(aCurve);
1516 //==============================================
1517 } //if (Abs(fprm) > RealEpsilon() || Abs(lprm-2.*M_PI) > RealEpsilon())
1520 // on regarde si on garde
1523 // if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*M_PI) < RealEpsilon()) {
1524 if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*M_PI) <= aRealEpsilon) {
1525 IntTools_Curve aCurve;
1526 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1527 aCurve.SetCurve(aTC3D);
1528 fprm=aTC3D->FirstParameter();
1529 lprm=aTC3D->LastParameter ();
1532 Handle (Geom2d_Curve) C2d;
1533 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1534 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1535 myTolReached2d=Tolpc;
1538 aCurve.SetFirstCurve2d(C2d);
1541 Handle(Geom2d_BSplineCurve) H1;
1542 aCurve.SetFirstCurve2d(H1);
1546 Handle (Geom2d_Curve) C2d;
1547 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1548 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1549 myTolReached2d=Tolpc;
1552 aCurve.SetSecondCurve2d(C2d);
1555 Handle(Geom2d_BSplineCurve) H1;
1556 aCurve.SetSecondCurve2d(H1);
1558 mySeqOfCurve.Append(aCurve);
1563 Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol;
1565 aTwoPIdiv17=2.*M_PI/17.;
1567 for (j=0; j<=17; j++) {
1568 gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
1569 Tol = Precision::Confusion();
1571 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1572 ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT);
1574 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1577 IntTools_Curve aCurve;
1578 aCurve.SetCurve(newc);
1579 //==============================================
1580 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {
1583 Handle (Geom2d_Curve) C2d;
1584 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1585 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1586 myTolReached2d=Tolpc;
1589 aCurve.SetFirstCurve2d(C2d);
1592 Handle(Geom2d_BSplineCurve) H1;
1593 aCurve.SetFirstCurve2d(H1);
1597 Handle (Geom2d_Curve) C2d;
1598 BuildPCurves(fprm, lprm, Tolpc,myHS2->ChangeSurface().Surface(), newc, C2d);
1599 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1600 myTolReached2d=Tolpc;
1603 aCurve.SetSecondCurve2d(C2d);
1607 Handle(Geom2d_BSplineCurve) H1;
1608 aCurve.SetSecondCurve2d(H1);
1610 }// end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse)
1613 Handle(Geom2d_BSplineCurve) H1;
1615 aCurve.SetFirstCurve2d(H1);
1616 aCurve.SetSecondCurve2d(H1);
1618 //==============================================
1620 mySeqOfCurve.Append(aCurve);
1623 }// end of if (ok) {
1624 }// end of for (Standard_Integer j=0; j<=17; j++)
1625 }// end of else { on regarde si on garde
1626 }// for (i=1; i<=myLConstruct.NbParts(); i++)
1627 }// IntPatch_Circle: IntPatch_Ellipse:
1630 case IntPatch_Analytic: {
1631 IntSurf_Quadric quad1,quad2;
1632 GeomAbs_SurfaceType typs = myHS1->Surface().GetType();
1636 quad1.SetValue(myHS1->Surface().Plane());
1638 case GeomAbs_Cylinder:
1639 quad1.SetValue(myHS1->Surface().Cylinder());
1642 quad1.SetValue(myHS1->Surface().Cone());
1644 case GeomAbs_Sphere:
1645 quad1.SetValue(myHS1->Surface().Sphere());
1648 quad1.SetValue(myHS1->Surface().Torus());
1651 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 1");
1654 typs = myHS2->Surface().GetType();
1658 quad2.SetValue(myHS2->Surface().Plane());
1660 case GeomAbs_Cylinder:
1661 quad2.SetValue(myHS2->Surface().Cylinder());
1664 quad2.SetValue(myHS2->Surface().Cone());
1666 case GeomAbs_Sphere:
1667 quad2.SetValue(myHS2->Surface().Sphere());
1670 quad2.SetValue(myHS2->Surface().Torus());
1673 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 2");
1677 IntPatch_ALineToWLine convert (quad1, quad2);
1680 aNbParts=myLConstruct.NbParts();
1681 for (i=1; i<=aNbParts; i++) {
1682 myLConstruct.Part(i, fprm, lprm);
1683 Handle(IntPatch_WLine) WL =
1684 convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm);
1686 Handle(Geom2d_BSplineCurve) H1;
1687 Handle(Geom2d_BSplineCurve) H2;
1690 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1694 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1697 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1701 else { // myApprox=TRUE
1702 GeomInt_WLApprox theapp3d;
1704 Standard_Real tol2d = myTolApprox;
1706 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True);
1708 aNbParts=myLConstruct.NbParts();
1709 for (i=1; i<=aNbParts; i++) {
1710 myLConstruct.Part(i, fprm, lprm);
1711 Handle(IntPatch_WLine) WL =
1712 convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
1714 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
1716 if (!theapp3d.IsDone()) {
1718 Handle(Geom2d_BSplineCurve) H1;
1719 Handle(Geom2d_BSplineCurve) H2;
1722 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1726 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1729 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1733 if(myApprox1 || myApprox2) {
1734 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) {
1735 myTolReached2d = theapp3d.TolReached2d();
1739 if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) {
1740 myTolReached3d = theapp3d.TolReached3d();
1743 Standard_Integer aNbMultiCurves, nbpoles;
1744 aNbMultiCurves=theapp3d.NbMultiCurves();
1745 for (j=1; j<=aNbMultiCurves; j++) {
1746 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1747 nbpoles = mbspc.NbPoles();
1749 TColgp_Array1OfPnt tpoles(1, nbpoles);
1750 mbspc.Curve(1, tpoles);
1751 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1753 mbspc.Multiplicities(),
1756 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1757 Check.FixTangent(Standard_True,Standard_True);
1759 IntTools_Curve aCurve;
1760 aCurve.SetCurve(BS);
1763 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1764 mbspc.Curve(2,tpoles2d);
1765 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1767 mbspc.Multiplicities(),
1770 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1771 newCheck.FixTangent(Standard_True,Standard_True);
1773 aCurve.SetFirstCurve2d(BS2);
1776 Handle(Geom2d_BSplineCurve) H1;
1777 aCurve.SetFirstCurve2d(H1);
1781 TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
1782 Standard_Integer TwoOrThree;
1783 TwoOrThree=myApprox1 ? 3 : 2;
1784 mbspc.Curve(TwoOrThree, tpoles2d);
1785 Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
1787 mbspc.Multiplicities(),
1790 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1791 newCheck.FixTangent(Standard_True,Standard_True);
1793 aCurve.SetSecondCurve2d(BS2);
1796 Handle(Geom2d_BSplineCurve) H2;
1797 aCurve.SetSecondCurve2d(H2);
1800 mySeqOfCurve.Append(aCurve);
1802 }// for (j=1; j<=aNbMultiCurves; j++) {
1803 }// else from if (!theapp3d.IsDone())
1804 }// for (i=1; i<=aNbParts; i++) {
1805 }// else { // myApprox=TRUE
1806 }// case IntPatch_Analytic:
1809 case IntPatch_Walking: {
1810 Handle(IntPatch_WLine) WL =
1811 Handle(IntPatch_WLine)::DownCast(L);
1813 Standard_Integer ifprm, ilprm;
1817 if(!bAvoidLineConstructor){
1818 aNbParts=myLConstruct.NbParts();
1820 for (i=1; i<=aNbParts; ++i) {
1821 Handle(Geom2d_BSplineCurve) H1, H2;
1822 Handle(Geom_Curve) aBSp;
1824 if(bAvoidLineConstructor) {
1826 ilprm = WL->NbPnts();
1829 myLConstruct.Part(i, fprm, lprm);
1830 ifprm=(Standard_Integer)fprm;
1831 ilprm=(Standard_Integer)lprm;
1835 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1839 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1842 aBSp=MakeBSpline(WL, ifprm, ilprm);
1843 IntTools_Curve aIC(aBSp, H1, H2);
1844 mySeqOfCurve.Append(aIC);
1845 }// for (i=1; i<=aNbParts; ++i) {
1846 }// if (!myApprox) {
1849 Standard_Boolean bIsDecomposited;
1850 Standard_Integer nbiter, aNbSeqOfL;
1851 Standard_Real tol2d, aTolApproxImp;
1852 IntPatch_SequenceOfLine aSeqOfL;
1853 GeomInt_WLApprox theapp3d;
1854 Approx_ParametrizationType aParType = Approx_ChordLength;
1856 Standard_Boolean anApprox1 = myApprox1;
1857 Standard_Boolean anApprox2 = myApprox2;
1859 aTolApproxImp=1.e-5;
1860 tol2d = myTolApprox;
1862 GeomAbs_SurfaceType typs1, typs2;
1863 typs1 = myHS1->Surface().GetType();
1864 typs2 = myHS2->Surface().GetType();
1865 Standard_Boolean anWithPC = Standard_True;
1867 if(typs1 == GeomAbs_Cylinder && typs2 == GeomAbs_Sphere) {
1869 ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere());
1871 else if (typs1 == GeomAbs_Sphere && typs2 == GeomAbs_Cylinder) {
1873 ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere());
1877 myTolApprox = aTolApproxImp;//1.e-5;
1878 anApprox1 = Standard_False;
1879 anApprox2 = Standard_False;
1881 tol2d = myTolApprox;
1884 if(myHS1 == myHS2) {
1885 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1886 rejectSurface = Standard_True;
1889 if(reApprox && !rejectSurface)
1890 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1892 Standard_Integer iDegMax, iDegMin, iNbIter;
1894 ApproxParameters(myHS1, myHS2, iDegMin, iDegMax, iNbIter);
1895 theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, iNbIter, Standard_True, aParType);
1899 Standard_Real aReachedTol = Precision::Confusion();
1900 bIsDecomposited=DecompositionOfWLine(WL,
1906 bAvoidLineConstructor,
1910 if ( bIsDecomposited && ( myTolReached3d < aReachedTol ) ) {
1911 myTolReached3d = aReachedTol;
1914 aNbSeqOfL=aSeqOfL.Length();
1916 if (bIsDecomposited) {
1922 if (!bAvoidLineConstructor) {
1923 aNbParts=myLConstruct.NbParts();
1928 for(i = 1; i <= nbiter; ++i) {
1929 if(bIsDecomposited) {
1930 WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i));
1932 ilprm = WL->NbPnts();
1935 if(bAvoidLineConstructor) {
1937 ilprm = WL->NbPnts();
1940 myLConstruct.Part(i, fprm, lprm);
1941 ifprm = (Standard_Integer)fprm;
1942 ilprm = (Standard_Integer)lprm;
1946 //-- Si une des surfaces est un plan , on approxime en 2d
1947 //-- sur cette surface et on remonte les points 2d en 3d.
1948 if(typs1 == GeomAbs_Plane) {
1949 theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm);
1951 else if(typs2 == GeomAbs_Plane) {
1952 theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm);
1956 if (myHS1 != myHS2){
1957 if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) &&
1958 (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) {
1960 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType);
1962 Standard_Boolean bUseSurfaces;
1963 bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm, ilprm);
1966 rejectSurface = Standard_True;
1968 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1973 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm);
1976 if (!theapp3d.IsDone()) {
1977 Handle(Geom2d_BSplineCurve) H1;
1978 Handle(Geom2d_BSplineCurve) H2;
1980 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
1983 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1987 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1990 IntTools_Curve aIC(aBSp, H1, H2);
1991 mySeqOfCurve.Append(aIC);
1995 if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) {
1996 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) {
1997 myTolReached2d = theapp3d.TolReached2d();
2000 if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) {
2001 myTolReached3d = myTolReached2d;
2003 if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
2004 if (myTolReached3d<1.e-6) {
2005 myTolReached3d = theapp3d.TolReached3d();
2006 myTolReached3d=1.e-6;
2010 else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) {
2011 myTolReached3d = theapp3d.TolReached3d();
2014 Standard_Integer aNbMultiCurves, nbpoles;
2015 aNbMultiCurves=theapp3d.NbMultiCurves();
2016 for (j=1; j<=aNbMultiCurves; j++) {
2017 if(typs1 == GeomAbs_Plane) {
2018 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2019 nbpoles = mbspc.NbPoles();
2021 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2022 TColgp_Array1OfPnt tpoles(1,nbpoles);
2024 mbspc.Curve(1,tpoles2d);
2025 const gp_Pln& Pln = myHS1->Surface().Plane();
2027 Standard_Integer ik;
2028 for(ik = 1; ik<= nbpoles; ik++) {
2030 ElSLib::Value(tpoles2d.Value(ik).X(),
2031 tpoles2d.Value(ik).Y(),
2035 Handle(Geom_BSplineCurve) BS =
2036 new Geom_BSplineCurve(tpoles,
2038 mbspc.Multiplicities(),
2040 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2041 Check.FixTangent(Standard_True, Standard_True);
2043 IntTools_Curve aCurve;
2044 aCurve.SetCurve(BS);
2047 Handle(Geom2d_BSplineCurve) BS1 =
2048 new Geom2d_BSplineCurve(tpoles2d,
2050 mbspc.Multiplicities(),
2052 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
2053 Check1.FixTangent(Standard_True,Standard_True);
2055 // ############################################
2056 if(!rejectSurface && !reApprox) {
2057 Standard_Boolean isValid = IsCurveValid(BS1);
2059 reApprox = Standard_True;
2063 // ############################################
2064 aCurve.SetFirstCurve2d(BS1);
2067 Handle(Geom2d_BSplineCurve) H1;
2068 aCurve.SetFirstCurve2d(H1);
2072 mbspc.Curve(2, tpoles2d);
2074 Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
2076 mbspc.Multiplicities(),
2078 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2079 newCheck.FixTangent(Standard_True,Standard_True);
2081 // ###########################################
2082 if(!rejectSurface && !reApprox) {
2083 Standard_Boolean isValid = IsCurveValid(BS2);
2085 reApprox = Standard_True;
2089 // ###########################################
2091 aCurve.SetSecondCurve2d(BS2);
2094 Handle(Geom2d_BSplineCurve) H2;
2096 aCurve.SetSecondCurve2d(H2);
2099 mySeqOfCurve.Append(aCurve);
2100 }//if(typs1 == GeomAbs_Plane) {
2102 else if(typs2 == GeomAbs_Plane) {
2103 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2104 nbpoles = mbspc.NbPoles();
2106 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2107 TColgp_Array1OfPnt tpoles(1,nbpoles);
2108 mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d);
2109 const gp_Pln& Pln = myHS2->Surface().Plane();
2111 Standard_Integer ik;
2112 for(ik = 1; ik<= nbpoles; ik++) {
2114 ElSLib::Value(tpoles2d.Value(ik).X(),
2115 tpoles2d.Value(ik).Y(),
2120 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
2122 mbspc.Multiplicities(),
2124 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2125 Check.FixTangent(Standard_True,Standard_True);
2127 IntTools_Curve aCurve;
2128 aCurve.SetCurve(BS);
2131 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
2133 mbspc.Multiplicities(),
2135 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
2136 Check1.FixTangent(Standard_True,Standard_True);
2138 // ###########################################
2139 if(!rejectSurface && !reApprox) {
2140 Standard_Boolean isValid = IsCurveValid(BS1);
2142 reApprox = Standard_True;
2146 // ###########################################
2147 bPCurvesOk = CheckPCurve(BS1, myFace2);
2148 aCurve.SetSecondCurve2d(BS1);
2151 Handle(Geom2d_BSplineCurve) H2;
2152 aCurve.SetSecondCurve2d(H2);
2156 mbspc.Curve(1,tpoles2d);
2157 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
2159 mbspc.Multiplicities(),
2161 GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK);
2162 Check2.FixTangent(Standard_True,Standard_True);
2164 // ###########################################
2165 if(!rejectSurface && !reApprox) {
2166 Standard_Boolean isValid = IsCurveValid(BS2);
2168 reApprox = Standard_True;
2172 // ###########################################
2173 bPCurvesOk = bPCurvesOk && CheckPCurve(BS2, myFace1);
2174 aCurve.SetFirstCurve2d(BS2);
2177 Handle(Geom2d_BSplineCurve) H1;
2179 aCurve.SetFirstCurve2d(H1);
2182 //if points of the pcurves are out of the faces bounds
2183 //create 3d and 2d curves without approximation
2185 Handle(Geom2d_BSplineCurve) H1, H2;
2186 bPCurvesOk = Standard_True;
2188 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
2191 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
2192 bPCurvesOk = CheckPCurve(H1, myFace1);
2196 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
2197 bPCurvesOk = bPCurvesOk && CheckPCurve(H2, myFace2);
2200 //if pcurves created without approximation are out of the
2201 //faces bounds, use approximated 3d and 2d curves
2203 IntTools_Curve aIC(aBSp, H1, H2);
2204 mySeqOfCurve.Append(aIC);
2206 mySeqOfCurve.Append(aCurve);
2209 mySeqOfCurve.Append(aCurve);
2211 }// else if(typs2 == GeomAbs_Plane)
2213 else { //typs2 != GeomAbs_Plane && typs1 != GeomAbs_Plane
2214 Standard_Boolean bIsValid1, bIsValid2;
2215 Handle(Geom_BSplineCurve) BS;
2216 Handle(Geom2d_BSplineCurve) aH2D;
2217 IntTools_Curve aCurve;
2219 bIsValid1=Standard_True;
2220 bIsValid2=Standard_True;
2222 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2223 nbpoles = mbspc.NbPoles();
2224 TColgp_Array1OfPnt tpoles(1,nbpoles);
2225 mbspc.Curve(1,tpoles);
2226 BS=new Geom_BSplineCurve(tpoles,
2228 mbspc.Multiplicities(),
2230 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2231 Check.FixTangent(Standard_True,Standard_True);
2233 aCurve.SetCurve(BS);
2234 aCurve.SetFirstCurve2d(aH2D);
2235 aCurve.SetSecondCurve2d(aH2D);
2239 Handle(Geom2d_BSplineCurve) BS1;
2240 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2241 mbspc.Curve(2,tpoles2d);
2243 BS1=new Geom2d_BSplineCurve(tpoles2d,
2245 mbspc.Multiplicities(),
2247 GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK);
2248 newCheck.FixTangent(Standard_True,Standard_True);
2251 bIsValid1=CheckPCurve(BS1, myFace1);
2254 aCurve.SetFirstCurve2d(BS1);
2257 Handle(Geom2d_BSplineCurve) BS1;
2258 fprm = BS->FirstParameter();
2259 lprm = BS->LastParameter();
2261 Handle(Geom2d_Curve) C2d;
2262 Standard_Real aTol = myTolApprox;
2263 BuildPCurves(fprm, lprm, aTol, myHS1->ChangeSurface().Surface(), BS, C2d);
2264 BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2265 aCurve.SetFirstCurve2d(BS1);
2267 } // if(myApprox1) {
2271 Handle(Geom2d_BSplineCurve) BS2;
2272 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2273 mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d);
2274 BS2=new Geom2d_BSplineCurve(tpoles2d,
2276 mbspc.Multiplicities(),
2278 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2279 newCheck.FixTangent(Standard_True,Standard_True);
2282 bIsValid2=CheckPCurve(BS2, myFace2);
2284 aCurve.SetSecondCurve2d(BS2);
2287 Handle(Geom2d_BSplineCurve) BS2;
2288 fprm = BS->FirstParameter();
2289 lprm = BS->LastParameter();
2291 Handle(Geom2d_Curve) C2d;
2292 Standard_Real aTol = myTolApprox;
2293 BuildPCurves(fprm, lprm, aTol, myHS2->ChangeSurface().Surface(), BS, C2d);
2294 BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2295 aCurve.SetSecondCurve2d(BS2);
2298 if (!bIsValid1 || !bIsValid2) {
2299 myTolApprox=aTolApproxImp;//1.e-5;
2300 tol2d = myTolApprox;
2301 reApprox = Standard_True;
2305 mySeqOfCurve.Append(aCurve);
2311 }// case IntPatch_Walking:{
2314 case IntPatch_Restriction:
2322 //=======================================================================
2323 //function : BuildPCurves
2325 //=======================================================================
2326 void BuildPCurves (Standard_Real f,
2329 const Handle (Geom_Surface)& S,
2330 const Handle (Geom_Curve)& C,
2331 Handle (Geom2d_Curve)& C2d)
2334 Standard_Real umin,umax,vmin,vmax;
2339 // in class ProjLib_Function the range of parameters is shrank by 1.e-09
2340 if((l - f) > 2.e-09) {
2341 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2344 // proj. a circle that goes through the pole on a sphere to the sphere
2346 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2350 if((l - f) > Epsilon(Abs(f))) {
2351 GeomAPI_ProjectPointOnSurf aProjector1, aProjector2;
2352 gp_Pnt P1 = C->Value(f);
2353 gp_Pnt P2 = C->Value(l);
2354 aProjector1.Init(P1, S);
2355 aProjector2.Init(P2, S);
2357 if(aProjector1.IsDone() && aProjector2.IsDone()) {
2358 Standard_Real U=0., V=0.;
2359 aProjector1.LowerDistanceParameters(U, V);
2362 aProjector2.LowerDistanceParameters(U, V);
2365 if(p1.Distance(p2) > gp::Resolution()) {
2366 TColgp_Array1OfPnt2d poles(1,2);
2367 TColStd_Array1OfReal knots(1,2);
2368 TColStd_Array1OfInteger mults(1,2);
2373 mults(1) = mults(2) = 2;
2375 C2d = new Geom2d_BSplineCurve(poles,knots,mults,1);
2377 // compute reached tolerance.begin
2378 gp_Pnt PMid = C->Value((f + l) * 0.5);
2379 aProjector1.Perform(PMid);
2381 if(aProjector1.IsDone()) {
2382 aProjector1.LowerDistanceParameters(U, V);
2383 gp_Pnt2d pmidproj(U, V);
2384 gp_Pnt2d pmidcurve2d = C2d->Value((f + l) * 0.5);
2385 Standard_Real adist = pmidcurve2d.Distance(pmidproj);
2386 Tol = (adist > Tol) ? adist : Tol;
2388 // compute reached tolerance.end
2394 S->Bounds(umin, umax, vmin, vmax);
2396 if (S->IsUPeriodic() && !C2d.IsNull()) {
2397 // Recadre dans le domaine UV de la face
2398 Standard_Real period, U0, du, aEps;
2401 aEps=Precision::PConfusion();
2402 period = S->UPeriod();
2403 gp_Pnt2d Pf = C2d->Value(f);
2406 gp_Pnt2d Pl = C2d->Value(l);
2408 U0 = Min(Pl.X(), U0);
2409 // while(U0-umin<aEps) {
2410 while(U0-umin<-aEps) {
2415 while(U0-umax>aEps) {
2427 //=======================================================================
2428 //function : Parameters
2430 //=======================================================================
2431 void Parameters(const Handle(GeomAdaptor_HSurface)& HS1,
2432 const Handle(GeomAdaptor_HSurface)& HS2,
2433 const gp_Pnt& Ptref,
2440 IntSurf_Quadric quad1,quad2;
2441 GeomAbs_SurfaceType typs = HS1->Surface().GetType();
2445 quad1.SetValue(HS1->Surface().Plane());
2447 case GeomAbs_Cylinder:
2448 quad1.SetValue(HS1->Surface().Cylinder());
2451 quad1.SetValue(HS1->Surface().Cone());
2453 case GeomAbs_Sphere:
2454 quad1.SetValue(HS1->Surface().Sphere());
2457 quad1.SetValue(HS1->Surface().Torus());
2460 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2463 typs = HS2->Surface().GetType();
2466 quad2.SetValue(HS2->Surface().Plane());
2468 case GeomAbs_Cylinder:
2469 quad2.SetValue(HS2->Surface().Cylinder());
2472 quad2.SetValue(HS2->Surface().Cone());
2474 case GeomAbs_Sphere:
2475 quad2.SetValue(HS2->Surface().Sphere());
2478 quad2.SetValue(HS2->Surface().Torus());
2481 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2484 quad1.Parameters(Ptref,U1,V1);
2485 quad2.Parameters(Ptref,U2,V2);
2488 //=======================================================================
2489 //function : MakeBSpline
2491 //=======================================================================
2492 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL,
2493 const Standard_Integer ideb,
2494 const Standard_Integer ifin)
2496 Standard_Integer i,nbpnt = ifin-ideb+1;
2497 TColgp_Array1OfPnt poles(1,nbpnt);
2498 TColStd_Array1OfReal knots(1,nbpnt);
2499 TColStd_Array1OfInteger mults(1,nbpnt);
2500 Standard_Integer ipidebm1;
2501 for(i=1,ipidebm1=i+ideb-1; i<=nbpnt;ipidebm1++, i++) {
2502 poles(i) = WL->Point(ipidebm1).Value();
2506 mults(1) = mults(nbpnt) = 2;
2508 new Geom_BSplineCurve(poles,knots,mults,1);
2512 //=======================================================================
2513 //function : MakeBSpline2d
2515 //=======================================================================
2516 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
2517 const Standard_Integer ideb,
2518 const Standard_Integer ifin,
2519 const Standard_Boolean onFirst)
2521 Standard_Integer i, nbpnt = ifin-ideb+1;
2522 TColgp_Array1OfPnt2d poles(1,nbpnt);
2523 TColStd_Array1OfReal knots(1,nbpnt);
2524 TColStd_Array1OfInteger mults(1,nbpnt);
2525 Standard_Integer ipidebm1;
2527 for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) {
2530 theWLine->Point(ipidebm1).ParametersOnS1(U, V);
2532 theWLine->Point(ipidebm1).ParametersOnS2(U, V);
2533 poles(i).SetCoord(U, V);
2537 mults(1) = mults(nbpnt) = 2;
2539 return new Geom2d_BSplineCurve(poles,knots,mults,1);
2541 //=======================================================================
2542 //function : PrepareLines3D
2544 //=======================================================================
2545 void IntTools_FaceFace::PrepareLines3D(const Standard_Boolean bToSplit)
2547 Standard_Integer i, aNbCurves;
2548 GeomAbs_SurfaceType aType1, aType2;
2549 IntTools_SequenceOfCurves aNewCvs;
2551 // 1. Treatment closed curves
2552 aNbCurves=mySeqOfCurve.Length();
2553 for (i=1; i<=aNbCurves; ++i) {
2554 const IntTools_Curve& aIC=mySeqOfCurve(i);
2557 Standard_Integer j, aNbC;
2558 IntTools_SequenceOfCurves aSeqCvs;
2560 aNbC=IntTools_Tools::SplitCurve(aIC, aSeqCvs);
2562 for (j=1; j<=aNbC; ++j) {
2563 const IntTools_Curve& aICNew=aSeqCvs(j);
2564 aNewCvs.Append(aICNew);
2568 aNewCvs.Append(aIC);
2572 aNewCvs.Append(aIC);
2576 // 2. Plane\Cone intersection when we had 4 curves
2577 aType1=myHS1->GetType();
2578 aType2=myHS2->GetType();
2579 aNbCurves=aNewCvs.Length();
2581 if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone) ||
2582 (aType2==GeomAbs_Plane && aType1==GeomAbs_Cone)) {
2584 GeomAbs_CurveType aCType1;
2586 aCType1=aNewCvs(1).Type();
2587 if (aCType1==GeomAbs_Line) {
2588 IntTools_SequenceOfCurves aSeqIn, aSeqOut;
2590 for (i=1; i<=aNbCurves; ++i) {
2591 const IntTools_Curve& aIC=aNewCvs(i);
2595 IntTools_Tools::RejectLines(aSeqIn, aSeqOut);
2598 aNbCurves=aSeqOut.Length();
2599 for (i=1; i<=aNbCurves; ++i) {
2600 const IntTools_Curve& aIC=aSeqOut(i);
2601 aNewCvs.Append(aIC);
2605 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone)...
2607 // 3. Fill mySeqOfCurve
2608 mySeqOfCurve.Clear();
2609 aNbCurves=aNewCvs.Length();
2610 for (i=1; i<=aNbCurves; ++i) {
2611 const IntTools_Curve& aIC=aNewCvs(i);
2612 mySeqOfCurve.Append(aIC);
2615 //=======================================================================
2616 //function : CorrectSurfaceBoundaries
2618 //=======================================================================
2619 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
2620 const Standard_Real theTolerance,
2621 Standard_Real& theumin,
2622 Standard_Real& theumax,
2623 Standard_Real& thevmin,
2624 Standard_Real& thevmax)
2626 Standard_Boolean enlarge, isuperiodic, isvperiodic;
2627 Standard_Real uinf, usup, vinf, vsup, delta;
2628 GeomAbs_SurfaceType aType;
2629 Handle(Geom_Surface) aSurface;
2631 aSurface = BRep_Tool::Surface(theFace);
2632 aSurface->Bounds(uinf, usup, vinf, vsup);
2633 delta = theTolerance;
2634 enlarge = Standard_False;
2636 GeomAdaptor_Surface anAdaptorSurface(aSurface);
2638 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
2639 Handle(Geom_Surface) aBasisSurface =
2640 (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface))->BasisSurface();
2642 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2643 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2648 if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2649 Handle(Geom_Surface) aBasisSurface =
2650 (Handle(Geom_OffsetSurface)::DownCast(aSurface))->BasisSurface();
2652 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2653 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2658 isuperiodic = anAdaptorSurface.IsUPeriodic();
2659 isvperiodic = anAdaptorSurface.IsVPeriodic();
2661 aType=anAdaptorSurface.GetType();
2662 if((aType==GeomAbs_BezierSurface) ||
2663 (aType==GeomAbs_BSplineSurface) ||
2664 (aType==GeomAbs_SurfaceOfExtrusion) ||
2665 (aType==GeomAbs_SurfaceOfRevolution) ||
2666 (aType==GeomAbs_Cylinder)) {
2667 enlarge=Standard_True;
2670 if(!isuperiodic && enlarge) {
2672 if((theumin - uinf) > delta )
2678 if((usup - theumax) > delta )
2684 if(!isvperiodic && enlarge) {
2685 if((thevmin - vinf) > delta ) {
2691 if((vsup - thevmax) > delta ) {
2700 Standard_Integer aNbP;
2701 Standard_Real aXP, dXfact, aXmid, aX1, aX2, aTolPA;
2703 aTolPA=Precision::Angular();
2706 aXP=anAdaptorSurface.UPeriod();
2707 dXfact=theumax-theumin;
2708 if (dXfact-aTolPA>aXP) {
2709 aXmid=0.5*(theumax+theumin);
2710 aNbP=RealToInt(aXmid/aXP);
2715 if (theumin>aTolPA) {
2716 aX1=theumin+aNbP*aXP;
2729 aXP=anAdaptorSurface.VPeriod();
2730 dXfact=thevmax-thevmin;
2731 if (dXfact-aTolPA>aXP) {
2732 aXmid=0.5*(thevmax+thevmin);
2733 aNbP=RealToInt(aXmid/aXP);
2738 if (thevmin>aTolPA) {
2739 aX1=thevmin+aNbP*aXP;
2752 if(isuperiodic || isvperiodic) {
2753 Standard_Boolean correct = Standard_False;
2754 Standard_Boolean correctU = Standard_False;
2755 Standard_Boolean correctV = Standard_False;
2757 TopExp_Explorer anExp;
2759 for(anExp.Init(theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
2760 if(BRep_Tool::IsClosed(TopoDS::Edge(anExp.Current()), theFace)) {
2761 correct = Standard_True;
2763 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
2765 for(Standard_Integer i = 0; i < 2; i++) {
2767 anEdge.Orientation(TopAbs_FORWARD);
2770 anEdge.Orientation(TopAbs_REVERSED);
2772 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l);
2774 if(aCurve.IsNull()) {
2775 correct = Standard_False;
2778 Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve);
2780 if(aLine.IsNull()) {
2781 correct = Standard_False;
2784 gp_Dir2d anUDir(1., 0.);
2785 gp_Dir2d aVDir(0., 1.);
2786 Standard_Real anAngularTolerance = Precision::Angular();
2788 correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance);
2789 correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance);
2791 gp_Pnt2d pp1 = aCurve->Value(f);
2793 gp_Pnt2d pp2 = aCurve->Value(l);
2802 Standard_Real umin, vmin, umax, vmax;
2803 aBox.Get(umin, vmin, umax, vmax);
2805 if(isuperiodic && correctU) {
2810 if(theumax > umax) {
2814 if(isvperiodic && correctV) {
2826 // The block is dedicated to determine whether WLine [ifprm, ilprm]
2827 // crosses the degenerated zone on each given surface or not.
2828 // If Yes -> We will not use info about surfaces during approximation
2829 // because inside degenerated zone of the surface the approx. algo.
2830 // uses wrong values of normal, etc., and resulting curve will have
2831 // oscillations that we would not like to have.
2836 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2837 const Handle(Geom_Surface)& aS,
2838 const Standard_Integer iDir);
2840 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2841 const TopoDS_Face& aF1,
2842 const TopoDS_Face& aF2);
2843 //=======================================================================
2844 //function : NotUseSurfacesForApprox
2846 //=======================================================================
2847 Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1,
2848 const TopoDS_Face& aF2,
2849 const Handle(IntPatch_WLine)& WL,
2850 const Standard_Integer ifprm,
2851 const Standard_Integer ilprm)
2853 Standard_Boolean bPInDZ;
2855 Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve();
2857 const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm);
2858 bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2);
2863 const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm);
2864 bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2);
2868 //=======================================================================
2869 //function : IsPointInDegeneratedZone
2871 //=======================================================================
2872 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2873 const TopoDS_Face& aF1,
2874 const TopoDS_Face& aF2)
2877 Standard_Boolean bFlag=Standard_True;
2878 Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22;
2879 Standard_Real U1, V1, U2, V2, aDelta, aD;
2882 Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1);
2883 aS1->Bounds(US11, US12, VS11, VS12);
2884 GeomAdaptor_Surface aGAS1(aS1);
2886 Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2);
2887 aS1->Bounds(US21, US22, VS21, VS22);
2888 GeomAdaptor_Surface aGAS2(aS2);
2890 //const gp_Pnt& aP=aP2S.Value();
2891 aP2S.Parameters(U1, V1, U2, V2);
2895 aD=aGAS1.UResolution(aDelta);
2896 aP2d.SetCoord(U1, V1);
2897 if (fabs(U1-US11) < aD) {
2898 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2903 if (fabs(U1-US12) < aD) {
2904 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2909 aD=aGAS1.VResolution(aDelta);
2910 if (fabs(V1-VS11) < aDelta) {
2911 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2916 if (fabs(V1-VS12) < aDelta) {
2917 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2923 aD=aGAS2.UResolution(aDelta);
2924 aP2d.SetCoord(U2, V2);
2925 if (fabs(U2-US21) < aDelta) {
2926 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2931 if (fabs(U2-US22) < aDelta) {
2932 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2937 aD=aGAS2.VResolution(aDelta);
2938 if (fabs(V2-VS21) < aDelta) {
2939 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2944 if (fabs(V2-VS22) < aDelta) {
2945 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2953 //=======================================================================
2954 //function : IsDegeneratedZone
2956 //=======================================================================
2957 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2958 const Handle(Geom_Surface)& aS,
2959 const Standard_Integer iDir)
2961 Standard_Boolean bFlag=Standard_True;
2962 Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD;
2963 Standard_Real aXm, aYm, aXb, aYb, aXe, aYe;
2964 aS->Bounds(US1, US2, VS1, VS2);
2966 gp_Pnt aPm, aPb, aPe;
2971 aS->D0(aXm, aYm, aPm);
2988 aS->D0(aXb, aYb, aPb);
2989 aS->D0(aXe, aYe, aPe);
2991 d1=aPm.Distance(aPb);
2992 d2=aPm.Distance(aPe);
2993 if (d1 < dD && d2 < dD) {
3010 aS->D0(aXb, aYb, aPb);
3011 aS->D0(aXe, aYe, aPe);
3013 d1=aPm.Distance(aPb);
3014 d2=aPm.Distance(aPe);
3015 if (d1 < dD && d2 < dD) {
3023 //=========================================================================
3024 // static function : ComputePurgedWLine
3025 // purpose : Removes equal points (leave one of equal points) from theWLine
3026 // and recompute vertex parameters.
3027 // Returns new WLine or null WLine if the number
3028 // of the points is less than 2.
3029 //=========================================================================
3030 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine) {
3032 Standard_Integer i, k, v, nb, nbvtx;
3033 Handle(IntPatch_WLine) aResult;
3034 nbvtx = theWLine->NbVertex();
3035 nb = theWLine->NbPnts();
3037 const IntSurf_PntOn2S& p1 = theWLine->Point(1);
3038 const IntSurf_PntOn2S& p2 = theWLine->Point(2);
3039 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
3044 Handle(IntPatch_WLine) aLocalWLine;
3045 Handle(IntPatch_WLine) aTmpWLine = theWLine;
3046 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
3047 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
3048 for(i = 1; i <= nb; i++) {
3049 aLineOn2S->Add(theWLine->Point(i));
3052 for(v = 1; v <= nbvtx; v++) {
3053 aLocalWLine->AddVertex(theWLine->Vertex(v));
3056 for(i = 1; i <= aLineOn2S->NbPoints(); i++) {
3057 Standard_Integer aStartIndex = i + 1;
3058 Standard_Integer anEndIndex = i + 5;
3059 nb = aLineOn2S->NbPoints();
3060 anEndIndex = (anEndIndex > nb) ? nb : anEndIndex;
3062 if((aStartIndex > nb) || (anEndIndex <= 1)) {
3067 while(k <= anEndIndex) {
3070 IntSurf_PntOn2S p1 = aLineOn2S->Value(i);
3071 IntSurf_PntOn2S p2 = aLineOn2S->Value(k);
3073 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
3074 aTmpWLine = aLocalWLine;
3075 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
3077 for(v = 1; v <= aTmpWLine->NbVertex(); v++) {
3078 IntPatch_Point aVertex = aTmpWLine->Vertex(v);
3079 Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine();
3081 if(avertexindex >= k) {
3082 aVertex.SetParameter(aVertex.ParameterOnLine() - 1.);
3084 aLocalWLine->AddVertex(aVertex);
3086 aLineOn2S->RemovePoint(k);
3095 if(aLineOn2S->NbPoints() > 1) {
3096 aResult = aLocalWLine;
3101 //=======================================================================
3104 //=======================================================================
3105 void TolR3d(const TopoDS_Face& aF1,
3106 const TopoDS_Face& aF2,
3107 Standard_Real& myTolReached3d)
3109 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
3111 aTolTresh=2.999999e-3;
3112 aTolF1 = BRep_Tool::Tolerance(aF1);
3113 aTolF2 = BRep_Tool::Tolerance(aF2);
3114 aTolFMax=Max(aTolF1, aTolF2);
3116 if (aTolFMax>aTolTresh) {
3117 myTolReached3d=aTolFMax;
3120 //=======================================================================
3121 //function : AdjustPeriodic
3123 //=======================================================================
3124 Standard_Real AdjustPeriodic(const Standard_Real theParameter,
3125 const Standard_Real parmin,
3126 const Standard_Real parmax,
3127 const Standard_Real thePeriod,
3128 Standard_Real& theOffset)
3130 Standard_Real aresult;
3133 aresult = theParameter;
3134 while(aresult < parmin) {
3135 aresult += thePeriod;
3136 theOffset += thePeriod;
3139 while(aresult > parmax) {
3140 aresult -= thePeriod;
3141 theOffset -= thePeriod;
3145 //=======================================================================
3146 //function : IsPointOnBoundary
3148 //=======================================================================
3149 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
3150 const Standard_Real theFirstBoundary,
3151 const Standard_Real theSecondBoundary,
3152 const Standard_Real theResolution,
3153 Standard_Boolean& IsOnFirstBoundary)
3155 Standard_Boolean bRet;
3157 Standard_Real adist;
3159 bRet=Standard_False;
3160 for(i = 0; i < 2; ++i) {
3161 IsOnFirstBoundary = (i == 0);
3162 if (IsOnFirstBoundary) {
3163 adist = fabs(theParameter - theFirstBoundary);
3166 adist = fabs(theParameter - theSecondBoundary);
3168 if(adist < theResolution) {
3174 // ------------------------------------------------------------------------------------------------
3175 // static function: FindPoint
3177 // ------------------------------------------------------------------------------------------------
3178 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3179 const gp_Pnt2d& theLastPoint,
3180 const Standard_Real theUmin,
3181 const Standard_Real theUmax,
3182 const Standard_Real theVmin,
3183 const Standard_Real theVmax,
3184 gp_Pnt2d& theNewPoint) {
3186 gp_Vec2d aVec(theFirstPoint, theLastPoint);
3187 Standard_Integer i = 0, j = 0;
3189 for(i = 0; i < 4; i++) {
3190 gp_Vec2d anOtherVec;
3191 gp_Vec2d anOtherVecNormal;
3192 gp_Pnt2d aprojpoint = theLastPoint;
3195 anOtherVec.SetX(0.);
3196 anOtherVec.SetY(1.);
3197 anOtherVecNormal.SetX(1.);
3198 anOtherVecNormal.SetY(0.);
3201 aprojpoint.SetX(theUmin);
3203 aprojpoint.SetX(theUmax);
3206 anOtherVec.SetX(1.);
3207 anOtherVec.SetY(0.);
3208 anOtherVecNormal.SetX(0.);
3209 anOtherVecNormal.SetY(1.);
3212 aprojpoint.SetY(theVmin);
3214 aprojpoint.SetY(theVmax);
3216 gp_Vec2d anormvec = aVec;
3217 anormvec.Normalize();
3218 RefineVector(anormvec);
3219 Standard_Real adot1 = anormvec.Dot(anOtherVecNormal);
3221 if(fabs(adot1) < Precision::Angular())
3223 Standard_Real adist = 0.;
3224 Standard_Boolean bIsOut = Standard_False;
3227 adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax);
3228 bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax);
3231 adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax);
3232 bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax);
3234 Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1;
3236 for(j = 0; j < 2; j++) {
3237 anoffset = (j == 0) ? anoffset : -anoffset;
3238 gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset));
3239 gp_Vec2d acurvec(theLastPoint, acurpoint);
3243 Standard_Real aDotX, anAngleX;
3245 aDotX = aVec.Dot(acurvec);
3246 anAngleX = aVec.Angle(acurvec);
3248 if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) {
3250 if((acurpoint.Y() >= theVmin) &&
3251 (acurpoint.Y() <= theVmax)) {
3252 theNewPoint = acurpoint;
3253 return Standard_True;
3257 if((acurpoint.X() >= theUmin) &&
3258 (acurpoint.X() <= theUmax)) {
3259 theNewPoint = acurpoint;
3260 return Standard_True;
3266 return Standard_False;
3270 // ------------------------------------------------------------------------------------------------
3271 // static function: FindPoint
3272 // purpose: Find point on the boundary of radial tangent zone
3273 // ------------------------------------------------------------------------------------------------
3274 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3275 const gp_Pnt2d& theLastPoint,
3276 const Standard_Real theUmin,
3277 const Standard_Real theUmax,
3278 const Standard_Real theVmin,
3279 const Standard_Real theVmax,
3280 const gp_Pnt2d& theTanZoneCenter,
3281 const Standard_Real theZoneRadius,
3282 Handle(GeomAdaptor_HSurface) theGASurface,
3283 gp_Pnt2d& theNewPoint) {
3284 theNewPoint = theLastPoint;
3286 if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) )
3287 return Standard_False;
3289 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3290 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3292 Standard_Real aRadius = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3293 gp_Ax22d anAxis( theTanZoneCenter, gp_Dir2d(1, 0), gp_Dir2d(0, 1) );
3294 gp_Circ2d aCircle( anAxis, aRadius );
3297 gp_Vec2d aDir( theLastPoint.XY() - theFirstPoint.XY() );
3298 Standard_Real aLength = aDir.Magnitude();
3299 if ( aLength <= gp::Resolution() )
3300 return Standard_False;
3301 gp_Lin2d aLine( theFirstPoint, aDir );
3304 Handle(Geom2d_Line) aCLine = new Geom2d_Line( aLine );
3305 Handle(Geom2d_TrimmedCurve) aC1 = new Geom2d_TrimmedCurve( aCLine, 0, aLength );
3306 Handle(Geom2d_Circle) aC2 = new Geom2d_Circle( aCircle );
3308 Standard_Real aTol = aRadius * 0.001;
3309 aTol = ( aTol < Precision::PConfusion() ) ? Precision::PConfusion() : aTol;
3311 Geom2dAPI_InterCurveCurve anIntersector;
3312 anIntersector.Init( aC1, aC2, aTol );
3314 if ( anIntersector.NbPoints() == 0 )
3315 return Standard_False;
3317 Standard_Boolean aFound = Standard_False;
3318 Standard_Real aMinDist = aLength * aLength;
3319 Standard_Integer i = 0;
3320 for ( i = 1; i <= anIntersector.NbPoints(); i++ ) {
3321 gp_Pnt2d aPInt = anIntersector.Point( i );
3322 if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) {
3323 if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) &&
3324 ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) {
3325 theNewPoint = aPInt;
3326 aFound = Standard_True;
3334 // ------------------------------------------------------------------------------------------------
3335 // static function: IsInsideTanZone
3336 // purpose: Check if point is inside a radial tangent zone
3337 // ------------------------------------------------------------------------------------------------
3338 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
3339 const gp_Pnt2d& theTanZoneCenter,
3340 const Standard_Real theZoneRadius,
3341 Handle(GeomAdaptor_HSurface) theGASurface) {
3343 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3344 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3345 Standard_Real aRadiusSQR = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3346 aRadiusSQR *= aRadiusSQR;
3347 if ( thePoint.SquareDistance( theTanZoneCenter ) <= aRadiusSQR )
3348 return Standard_True;
3349 return Standard_False;
3352 // ------------------------------------------------------------------------------------------------
3353 // static function: CheckTangentZonesExist
3354 // purpose: Check if tangent zone exists
3355 // ------------------------------------------------------------------------------------------------
3356 Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& theSurface1,
3357 const Handle(GeomAdaptor_HSurface)& theSurface2 )
3359 if ( ( theSurface1->GetType() != GeomAbs_Torus ) ||
3360 ( theSurface2->GetType() != GeomAbs_Torus ) )
3361 return Standard_False;
3363 gp_Torus aTor1 = theSurface1->Torus();
3364 gp_Torus aTor2 = theSurface2->Torus();
3366 if ( aTor1.Location().Distance( aTor2.Location() ) > Precision::Confusion() )
3367 return Standard_False;
3369 if ( ( fabs( aTor1.MajorRadius() - aTor2.MajorRadius() ) > Precision::Confusion() ) ||
3370 ( fabs( aTor1.MinorRadius() - aTor2.MinorRadius() ) > Precision::Confusion() ) )
3371 return Standard_False;
3373 if ( ( aTor1.MajorRadius() < aTor1.MinorRadius() ) ||
3374 ( aTor2.MajorRadius() < aTor2.MinorRadius() ) )
3375 return Standard_False;
3376 return Standard_True;
3379 // ------------------------------------------------------------------------------------------------
3380 // static function: ComputeTangentZones
3382 // ------------------------------------------------------------------------------------------------
3383 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
3384 const Handle(GeomAdaptor_HSurface)& theSurface2,
3385 const TopoDS_Face& theFace1,
3386 const TopoDS_Face& theFace2,
3387 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
3388 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
3389 Handle(TColStd_HArray1OfReal)& theResultRadius,
3390 const Handle(BOPInt_Context)& aContext)
3392 Standard_Integer aResult = 0;
3393 if ( !CheckTangentZonesExist( theSurface1, theSurface2 ) )
3397 TColgp_SequenceOfPnt2d aSeqResultS1, aSeqResultS2;
3398 TColStd_SequenceOfReal aSeqResultRad;
3400 gp_Torus aTor1 = theSurface1->Torus();
3401 gp_Torus aTor2 = theSurface2->Torus();
3403 gp_Ax2 anax1( aTor1.Location(), aTor1.Axis().Direction() );
3404 gp_Ax2 anax2( aTor2.Location(), aTor2.Axis().Direction() );
3405 Standard_Integer j = 0;
3407 for ( j = 0; j < 2; j++ ) {
3408 Standard_Real aCoef = ( j == 0 ) ? -1 : 1;
3409 Standard_Real aRadius1 = fabs(aTor1.MajorRadius() + aCoef * aTor1.MinorRadius());
3410 Standard_Real aRadius2 = fabs(aTor2.MajorRadius() + aCoef * aTor2.MinorRadius());
3412 gp_Circ aCircle1( anax1, aRadius1 );
3413 gp_Circ aCircle2( anax2, aRadius2 );
3415 // roughly compute radius of tangent zone for perpendicular case
3416 Standard_Real aCriteria = Precision::Confusion() * 0.5;
3418 Standard_Real aT1 = aCriteria;
3419 Standard_Real aT2 = aCriteria;
3421 // internal tangency
3422 Standard_Real aR = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3423 //aT1 = aCriteria * aCriteria + aR * aR - ( aR - aCriteria ) * ( aR - aCriteria );
3424 aT1 = 2. * aR * aCriteria;
3428 // external tangency
3429 Standard_Real aRb = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3430 Standard_Real aRm = ( aRadius1 < aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3431 Standard_Real aDelta = aRb - aCriteria;
3433 aDelta -= aRm * aRm;
3434 aDelta /= 2. * (aRb - aRm);
3435 aDelta -= 0.5 * (aRb - aRm);
3437 aT1 = 2. * aRm * (aRm - aDelta);
3440 aCriteria = ( aT1 > aT2) ? aT1 : aT2;
3441 if ( aCriteria > 0 )
3442 aCriteria = sqrt( aCriteria );
3444 if ( aCriteria > 0.5 * aTor1.MinorRadius() ) {
3445 // too big zone -> drop to minimum
3446 aCriteria = Precision::Confusion();
3449 GeomAdaptor_Curve aC1( new Geom_Circle(aCircle1) );
3450 GeomAdaptor_Curve aC2( new Geom_Circle(aCircle2) );
3451 Extrema_ExtCC anExtrema(aC1, aC2, 0, 2. * M_PI, 0, 2. * M_PI,
3452 Precision::PConfusion(), Precision::PConfusion());
3454 if ( anExtrema.IsDone() ) {
3456 Standard_Integer i = 0;
3457 for ( i = 1; i <= anExtrema.NbExt(); i++ ) {
3458 if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria )
3461 Extrema_POnCurv P1, P2;
3462 anExtrema.Points( i, P1, P2 );
3464 Standard_Boolean bFoundResult = Standard_True;
3467 Standard_Integer surfit = 0;
3468 for ( surfit = 0; surfit < 2; surfit++ ) {
3469 GeomAPI_ProjectPointOnSurf& aProjector =
3470 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3472 gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value();
3473 aProjector.Perform(aP3d);
3475 if(!aProjector.IsDone())
3476 bFoundResult = Standard_False;
3478 if(aProjector.LowerDistance() > aCriteria) {
3479 bFoundResult = Standard_False;
3482 Standard_Real foundU = 0, foundV = 0;
3483 aProjector.LowerDistanceParameters(foundU, foundV);
3485 pr1 = gp_Pnt2d( foundU, foundV );
3487 pr2 = gp_Pnt2d( foundU, foundV );
3491 if ( bFoundResult ) {
3492 aSeqResultS1.Append( pr1 );
3493 aSeqResultS2.Append( pr2 );
3494 aSeqResultRad.Append( aCriteria );
3496 // torus is u and v periodic
3497 const Standard_Real twoPI = M_PI + M_PI;
3498 Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()};
3499 Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()};
3501 // iteration on period bounds
3502 for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) {
3503 Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI;
3504 Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI;
3506 // iteration on surfaces
3507 for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) {
3508 Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp;
3509 Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp;
3510 TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2;
3511 TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2;
3513 if (fabs(arr1[0] - aBound) < Precision::PConfusion()) {
3514 aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) );
3515 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3516 aSeqResultRad.Append( aCriteria );
3518 if (fabs(arr1[1] - aBound) < Precision::PConfusion()) {
3519 aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) );
3520 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3521 aSeqResultRad.Append( aCriteria );
3529 aResult = aSeqResultRad.Length();
3531 if ( aResult > 0 ) {
3532 theResultOnS1 = new TColgp_HArray1OfPnt2d( 1, aResult );
3533 theResultOnS2 = new TColgp_HArray1OfPnt2d( 1, aResult );
3534 theResultRadius = new TColStd_HArray1OfReal( 1, aResult );
3536 for ( Standard_Integer i = 1 ; i <= aResult; i++ ) {
3537 theResultOnS1->SetValue( i, aSeqResultS1.Value(i) );
3538 theResultOnS2->SetValue( i, aSeqResultS2.Value(i) );
3539 theResultRadius->SetValue( i, aSeqResultRad.Value(i) );
3545 // ------------------------------------------------------------------------------------------------
3546 // static function: AdjustByNeighbour
3548 // ------------------------------------------------------------------------------------------------
3549 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
3550 const gp_Pnt2d& theOriginalPoint,
3551 Handle(GeomAdaptor_HSurface) theGASurface) {
3553 gp_Pnt2d ap1 = theaNeighbourPoint;
3554 gp_Pnt2d ap2 = theOriginalPoint;
3556 if ( theGASurface->IsUPeriodic() ) {
3557 Standard_Real aPeriod = theGASurface->UPeriod();
3558 gp_Pnt2d aPTest = ap2;
3559 Standard_Real aSqDistMin = 1.e+100;
3561 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3562 aPTest.SetX( theOriginalPoint.X() + aPeriod * pIt );
3563 Standard_Real dd = ap1.SquareDistance( aPTest );
3565 if ( dd < aSqDistMin ) {
3571 if ( theGASurface->IsVPeriodic() ) {
3572 Standard_Real aPeriod = theGASurface->VPeriod();
3573 gp_Pnt2d aPTest = ap2;
3574 Standard_Real aSqDistMin = 1.e+100;
3576 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3577 aPTest.SetY( theOriginalPoint.Y() + aPeriod * pIt );
3578 Standard_Real dd = ap1.SquareDistance( aPTest );
3580 if ( dd < aSqDistMin ) {
3589 // ------------------------------------------------------------------------------------------------
3590 //function: DecompositionOfWLine
3592 // ------------------------------------------------------------------------------------------------
3593 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
3594 const Handle(GeomAdaptor_HSurface)& theSurface1,
3595 const Handle(GeomAdaptor_HSurface)& theSurface2,
3596 const TopoDS_Face& theFace1,
3597 const TopoDS_Face& theFace2,
3598 const IntTools_LineConstructor& theLConstructor,
3599 const Standard_Boolean theAvoidLConstructor,
3600 IntPatch_SequenceOfLine& theNewLines,
3601 Standard_Real& theReachedTol3d,
3602 const Handle(BOPInt_Context)& aContext)
3605 Standard_Boolean bRet, bAvoidLineConstructor;
3606 Standard_Integer aNbPnts, aNbParts;
3608 bRet=Standard_False;
3609 aNbPnts=theWLine->NbPnts();
3610 bAvoidLineConstructor=theAvoidLConstructor;
3615 if (!bAvoidLineConstructor) {
3616 aNbParts=theLConstructor.NbParts();
3622 Standard_Boolean bIsPrevPointOnBoundary, bIsPointOnBoundary, bIsCurrentPointOnBoundary;
3623 Standard_Integer nblines, pit, i, j;
3625 TColStd_Array1OfListOfInteger anArrayOfLines(1, aNbPnts);
3626 TColStd_Array1OfInteger anArrayOfLineType(1, aNbPnts);
3627 TColStd_ListOfInteger aListOfPointIndex;
3629 Handle(TColgp_HArray1OfPnt2d) aTanZoneS1;
3630 Handle(TColgp_HArray1OfPnt2d) aTanZoneS2;
3631 Handle(TColStd_HArray1OfReal) aTanZoneRadius;
3632 Standard_Integer aNbZone = ComputeTangentZones( theSurface1, theSurface2, theFace1, theFace2,
3633 aTanZoneS1, aTanZoneS2, aTanZoneRadius, aContext);
3637 aTol=Precision::Confusion();
3639 bIsPrevPointOnBoundary=Standard_False;
3640 bIsPointOnBoundary=Standard_False;
3645 for(pit = 1; pit <= aNbPnts; ++pit) {
3646 Standard_Boolean bIsOnFirstBoundary, isperiodic;
3647 Standard_Real aResolution, aPeriod, alowerboundary, aupperboundary, U, V;
3648 Standard_Real aParameter, anoffset, anAdjustPar;
3649 Standard_Real umin, umax, vmin, vmax;
3651 bIsCurrentPointOnBoundary = Standard_False;
3652 const IntSurf_PntOn2S& aPoint = theWLine->Point(pit);
3655 for(i = 0; i < 2; ++i) {
3656 Handle(GeomAdaptor_HSurface) aGASurface = (!i) ? theSurface1 : theSurface2;
3657 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3659 aPoint.ParametersOnS1(U, V);
3662 aPoint.ParametersOnS2(U, V);
3665 for(j = 0; j < 2; j++) {
3666 isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3672 aResolution=aGASurface->UResolution(aTol);
3673 aPeriod=aGASurface->UPeriod();
3674 alowerboundary=umin;
3675 aupperboundary=umax;
3679 aResolution=aGASurface->VResolution(aTol);
3680 aPeriod=aGASurface->VPeriod();
3681 alowerboundary=vmin;
3682 aupperboundary=vmax;
3687 anAdjustPar = AdjustPeriodic(aParameter,
3693 bIsOnFirstBoundary = Standard_True;// ?
3695 IsPointOnBoundary(anAdjustPar,
3699 bIsOnFirstBoundary);
3701 if(bIsPointOnBoundary) {
3702 bIsCurrentPointOnBoundary = Standard_True;
3706 // check if a point belong to a tangent zone. Begin
3707 Standard_Integer zIt = 0;
3708 for ( zIt = 1; zIt <= aNbZone; zIt++ ) {
3709 gp_Pnt2d aPZone = (i == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3710 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3712 if ( IsInsideTanZone(gp_Pnt2d( U, V ), aPZone, aZoneRadius, aGASurface ) ) {
3713 // set boundary flag to split the curve by a tangent zone
3714 bIsPointOnBoundary = Standard_True;
3715 bIsCurrentPointOnBoundary = Standard_True;
3716 if ( theReachedTol3d < aZoneRadius ) {
3717 theReachedTol3d = aZoneRadius;
3723 }//for(j = 0; j < 2; j++) {
3725 if(bIsCurrentPointOnBoundary){
3728 }//for(i = 0; i < 2; ++i) {
3730 if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) {
3731 if(!aListOfPointIndex.IsEmpty()) {
3733 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3734 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3735 aListOfPointIndex.Clear();
3737 bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary;
3739 aListOfPointIndex.Append(pit);
3740 } //for(pit = 1; pit <= aNbPnts; ++pit) {
3742 if(!aListOfPointIndex.IsEmpty()) {
3744 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3745 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3746 aListOfPointIndex.Clear();
3750 return bRet; //Standard_False;
3754 // 2. Correct wlines.begin
3755 TColStd_Array1OfListOfInteger anArrayOfLineEnds(1, nblines);
3756 Handle(IntSurf_LineOn2S) aSeqOfPntOn2S = new IntSurf_LineOn2S();
3758 for(i = 1; i <= nblines; i++) {
3759 if(anArrayOfLineType.Value(i) != 0) {
3762 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3763 if(aListOfIndex.Extent() < 2) {
3766 TColStd_ListOfInteger aListOfFLIndex;
3768 for(j = 0; j < 2; j++) {
3769 Standard_Integer aneighbourindex = (j == 0) ? (i - 1) : (i + 1);
3771 if((aneighbourindex < 1) || (aneighbourindex > nblines))
3774 if(anArrayOfLineType.Value(aneighbourindex) == 0)
3776 const TColStd_ListOfInteger& aNeighbour = anArrayOfLines.Value(aneighbourindex);
3777 Standard_Integer anIndex = (j == 0) ? aNeighbour.Last() : aNeighbour.First();
3778 const IntSurf_PntOn2S& aPoint = theWLine->Point(anIndex);
3780 IntSurf_PntOn2S aNewP = aPoint;
3782 for(Standard_Integer surfit = 0; surfit < 2; surfit++) {
3784 Handle(GeomAdaptor_HSurface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2;
3785 Standard_Real umin=0., umax=0., vmin=0., vmax=0.;
3786 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3787 Standard_Real U=0., V=0.;
3790 aNewP.ParametersOnS1(U, V);
3792 aNewP.ParametersOnS2(U, V);
3793 Standard_Integer nbboundaries = 0;
3795 Standard_Boolean bIsNearBoundary = Standard_False;
3796 Standard_Integer aZoneIndex = 0;
3797 Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1
3798 Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1
3801 for(Standard_Integer parit = 0; parit < 2; parit++) {
3802 Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3804 Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
3805 Standard_Real alowerboundary = (parit == 0) ? umin : vmin;
3806 Standard_Real aupperboundary = (parit == 0) ? umax : vmax;
3808 Standard_Real aParameter = (parit == 0) ? U : V;
3809 Standard_Boolean bIsOnFirstBoundary = Standard_True;
3813 IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3814 if(bIsPointOnBoundary) {
3815 bIsUBoundary = (parit == 0);
3816 bIsFirstBoundary = bIsOnFirstBoundary;
3821 Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3822 Standard_Real anoffset = 0.;
3823 Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
3826 IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3827 if(bIsPointOnBoundary) {
3828 bIsUBoundary = (parit == 0);
3829 bIsFirstBoundary = bIsOnFirstBoundary;
3833 //check neighbourhood of boundary
3834 Standard_Real anEpsilon = aResolution * 100.;
3835 Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
3836 anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
3838 bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary,
3839 anEpsilon, bIsOnFirstBoundary);
3845 // check if a point belong to a tangent zone. Begin
3846 for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) {
3847 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3848 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3850 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3851 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3852 Standard_Real nU1, nV1;
3855 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3857 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3858 gp_Pnt2d ap1(nU1, nV1);
3859 gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface );
3862 if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) {
3864 bIsNearBoundary = Standard_True;
3865 if ( theReachedTol3d < aZoneRadius ) {
3866 theReachedTol3d = aZoneRadius;
3870 // check if a point belong to a tangent zone. End
3871 Standard_Boolean bComputeLineEnd = Standard_False;
3873 if(nbboundaries == 2) {
3875 bComputeLineEnd = Standard_True;
3878 else if(nbboundaries == 1) {
3879 Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3882 Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
3883 Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
3884 Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3885 Standard_Real aParameter = (bIsUBoundary) ? U : V;
3886 Standard_Real anoffset = 0.;
3887 Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
3889 Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
3890 Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
3891 anotherPar += anoffset;
3892 Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3893 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
3894 Standard_Real nU1, nV1;
3897 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3899 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3901 Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
3902 Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
3903 bComputeLineEnd = Standard_True;
3904 Standard_Boolean bCheckAngle1 = Standard_False;
3905 Standard_Boolean bCheckAngle2 = Standard_False;
3907 Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
3908 Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
3910 if(((adist1 - adist2) > Precision::PConfusion()) &&
3911 (adist2 < (aPeriod / 4.))) {
3912 bCheckAngle1 = Standard_True;
3913 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
3915 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3916 aNewP.SetValue((surfit == 0), anewU, anewV);
3917 bCheckAngle1 = Standard_False;
3920 else if(adist1 < (aPeriod / 4.)) {
3921 bCheckAngle2 = Standard_True;
3922 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
3924 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3925 bCheckAngle2 = Standard_False;
3929 if(bCheckAngle1 || bCheckAngle2) {
3930 // assume there are at least two points in line (see "if" above)
3931 Standard_Integer anindexother = aneighbourpointindex;
3933 while((anindexother <= aListOfIndex.Last()) && (anindexother >= aListOfIndex.First())) {
3934 anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
3935 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
3936 Standard_Real nU2, nV2;
3939 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3941 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3942 gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
3944 if(aVecOld.SquareMagnitude() <= (gp::Resolution() * gp::Resolution())) {
3948 Standard_Real anAngle = aNewVec.Angle(aVecOld);
3950 if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
3953 Standard_Real U1, U2, V1, V2;
3954 IntSurf_PntOn2S atmppoint = aNewP;
3955 atmppoint.SetValue((surfit == 0), anewU, anewV);
3956 atmppoint.Parameters(U1, V1, U2, V2);
3957 gp_Pnt P1 = theSurface1->Value(U1, V1);
3958 gp_Pnt P2 = theSurface2->Value(U2, V2);
3959 gp_Pnt P0 = aPoint.Value();
3961 if(P0.IsEqual(P1, aTol) &&
3962 P0.IsEqual(P2, aTol) &&
3963 P1.IsEqual(P2, aTol)) {
3964 bComputeLineEnd = Standard_False;
3965 aNewP.SetValue((surfit == 0), anewU, anewV);
3970 bComputeLineEnd = Standard_False;
3975 } // end while(anindexother...)
3979 else if ( bIsNearBoundary ) {
3980 bComputeLineEnd = Standard_True;
3983 if(bComputeLineEnd) {
3986 Standard_Boolean found = Standard_False;
3988 if ( bIsNearBoundary ) {
3989 // re-compute point near natural boundary or near tangent zone
3990 Standard_Real u1, v1, u2, v2;
3991 aNewP.Parameters( u1, v1, u2, v2 );
3993 anewpoint = gp_Pnt2d( u1, v1 );
3995 anewpoint = gp_Pnt2d( u2, v2 );
3997 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3998 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3999 Standard_Real nU1, nV1;
4002 aNeighbourPoint.ParametersOnS1(nU1, nV1);
4004 aNeighbourPoint.ParametersOnS2(nU1, nV1);
4005 gp_Pnt2d ap1(nU1, nV1);
4010 // exclude point from a tangent zone
4011 anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface );
4012 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex);
4013 Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex);
4015 if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax,
4016 aPZone, aZoneRadius, aGASurface, ap2) ) {
4018 found = Standard_True;
4021 else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
4022 // re-compute point near boundary if shifted on a period
4023 ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
4025 if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
4026 ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
4027 found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
4031 aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
4037 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
4038 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
4039 Standard_Real nU1, nV1;
4042 aNeighbourPoint.ParametersOnS1(nU1, nV1);
4044 aNeighbourPoint.ParametersOnS2(nU1, nV1);
4045 gp_Pnt2d ap1(nU1, nV1);
4046 gp_Pnt2d ap2(nU1, nV1);
4047 Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
4049 while((aneighbourpointindex2 <= aListOfIndex.Last()) && (aneighbourpointindex2 >= aListOfIndex.First())) {
4050 aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
4051 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
4052 Standard_Real nU2, nV2;
4055 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
4057 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
4061 if(ap1.SquareDistance(ap2) > (gp::Resolution() * gp::Resolution())) {
4065 found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
4070 Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4071 GeomAPI_ProjectPointOnSurf& aProjector =
4072 (surfit == 0) ? aContext->ProjPS(theFace2) : aContext->ProjPS(theFace1);
4073 Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
4075 Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
4077 gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
4078 aProjector.Perform(aP3d);
4080 if(aProjector.IsDone()) {
4081 if(aProjector.LowerDistance() < aCriteria) {
4082 Standard_Real foundU = U, foundV = V;
4083 aProjector.LowerDistanceParameters(foundU, foundV);
4085 //Correction of projected coordinates. Begin
4086 //Note, it may be shifted on a period
4087 Standard_Integer aneindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
4088 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
4089 Standard_Real nUn, nVn;
4092 aNeighbourPoint.ParametersOnS2(nUn, nVn);
4094 aNeighbourPoint.ParametersOnS1(nUn, nVn);
4095 gp_Pnt2d aNeighbour2d(nUn, nVn);
4096 gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
4097 foundU = anAdjustedPoint.X();
4098 foundV = anAdjustedPoint.Y();
4100 if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
4101 ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
4102 // attempt to roughly re-compute point
4103 foundU = ( foundU < umin ) ? umin : foundU;
4104 foundU = ( foundU > umax ) ? umax : foundU;
4105 foundV = ( foundV < vmin ) ? vmin : foundV;
4106 foundV = ( foundV > vmax ) ? vmax : foundV;
4108 GeomAPI_ProjectPointOnSurf& aProjector2 =
4109 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
4111 aP3d = aSurfaceOther->Value(foundU, foundV);
4112 aProjector2.Perform(aP3d);
4114 if(aProjector2.IsDone()) {
4115 if(aProjector2.LowerDistance() < aCriteria) {
4116 Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
4117 aProjector2.LowerDistanceParameters(foundU2, foundV2);
4118 anewpoint.SetX(foundU2);
4119 anewpoint.SetY(foundV2);
4123 //Correction of projected coordinates. End
4126 aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
4128 aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
4134 aSeqOfPntOn2S->Add(aNewP);
4135 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
4137 anArrayOfLineEnds.SetValue(i, aListOfFLIndex);
4139 // Correct wlines.end
4141 // Split wlines.begin
4142 Standard_Integer nbiter;
4145 if (!bAvoidLineConstructor) {
4146 nbiter=theLConstructor.NbParts();
4149 for(j = 1; j <= nbiter; ++j) {
4150 Standard_Real fprm, lprm;
4151 Standard_Integer ifprm, ilprm;
4153 if(bAvoidLineConstructor) {
4155 ilprm = theWLine->NbPnts();
4158 theLConstructor.Part(j, fprm, lprm);
4159 ifprm = (Standard_Integer)fprm;
4160 ilprm = (Standard_Integer)lprm;
4163 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
4165 for(i = 1; i <= nblines; i++) {
4166 if(anArrayOfLineType.Value(i) != 0) {
4169 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
4171 if(aListOfIndex.Extent() < 2) {
4174 const TColStd_ListOfInteger& aListOfFLIndex = anArrayOfLineEnds.Value(i);
4175 Standard_Boolean bhasfirstpoint = (aListOfFLIndex.Extent() == 2);
4176 Standard_Boolean bhaslastpoint = (aListOfFLIndex.Extent() == 2);
4178 if(!bhasfirstpoint && !aListOfFLIndex.IsEmpty()) {
4179 bhasfirstpoint = (i != 1);
4182 if(!bhaslastpoint && !aListOfFLIndex.IsEmpty()) {
4183 bhaslastpoint = (i != nblines);
4185 Standard_Boolean bIsFirstInside = ((ifprm >= aListOfIndex.First()) && (ifprm <= aListOfIndex.Last()));
4186 Standard_Boolean bIsLastInside = ((ilprm >= aListOfIndex.First()) && (ilprm <= aListOfIndex.Last()));
4188 if(!bIsFirstInside && !bIsLastInside) {
4189 if((ifprm < aListOfIndex.First()) && (ilprm > aListOfIndex.Last())) {
4190 // append whole line, and boundaries if neccesary
4191 if(bhasfirstpoint) {
4192 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
4195 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4197 for(; anIt.More(); anIt.Next()) {
4198 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4203 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
4207 // check end of split line (end is almost always)
4208 Standard_Integer aneighbour = i + 1;
4209 Standard_Boolean bIsEndOfLine = Standard_True;
4211 if(aneighbour <= nblines) {
4212 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4214 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4215 (aListOfNeighbourIndex.IsEmpty())) {
4216 bIsEndOfLine = Standard_False;
4221 if(aLineOn2S->NbPoints() > 1) {
4222 Handle(IntPatch_WLine) aNewWLine =
4223 new IntPatch_WLine(aLineOn2S, Standard_False);
4224 theNewLines.Append(aNewWLine);
4226 aLineOn2S = new IntSurf_LineOn2S();
4231 // end if(!bIsFirstInside && !bIsLastInside)
4233 if(bIsFirstInside && bIsLastInside) {
4234 // append inside points between ifprm and ilprm
4235 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4237 for(; anIt.More(); anIt.Next()) {
4238 if((anIt.Value() < ifprm) || (anIt.Value() > ilprm))
4240 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4246 if(bIsFirstInside) {
4247 // append points from ifprm to last point + boundary point
4248 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4250 for(; anIt.More(); anIt.Next()) {
4251 if(anIt.Value() < ifprm)
4253 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4258 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
4261 // check end of split line (end is almost always)
4262 Standard_Integer aneighbour = i + 1;
4263 Standard_Boolean bIsEndOfLine = Standard_True;
4265 if(aneighbour <= nblines) {
4266 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4268 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4269 (aListOfNeighbourIndex.IsEmpty())) {
4270 bIsEndOfLine = Standard_False;
4275 if(aLineOn2S->NbPoints() > 1) {
4276 Handle(IntPatch_WLine) aNewWLine =
4277 new IntPatch_WLine(aLineOn2S, Standard_False);
4278 theNewLines.Append(aNewWLine);
4280 aLineOn2S = new IntSurf_LineOn2S();
4283 // end if(bIsFirstInside)
4286 // append points from first boundary point to ilprm
4287 if(bhasfirstpoint) {
4288 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
4291 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4293 for(; anIt.More(); anIt.Next()) {
4294 if(anIt.Value() > ilprm)
4296 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4300 //end if(bIsLastInside)
4304 if(aLineOn2S->NbPoints() > 1) {
4305 Handle(IntPatch_WLine) aNewWLine =
4306 new IntPatch_WLine(aLineOn2S, Standard_False);
4307 theNewLines.Append(aNewWLine);
4312 return Standard_True;
4315 // ------------------------------------------------------------------------------------------------
4316 // static function: ParameterOutOfBoundary
4317 // purpose: Computes a new parameter for given curve. The corresponding 2d points
4318 // does not lay on any boundary of given faces
4319 // ------------------------------------------------------------------------------------------------
4320 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
4321 const Handle(Geom_Curve)& theCurve,
4322 const TopoDS_Face& theFace1,
4323 const TopoDS_Face& theFace2,
4324 const Standard_Real theOtherParameter,
4325 const Standard_Boolean bIncreasePar,
4326 Standard_Real& theNewParameter,
4327 const Handle(BOPInt_Context)& aContext)
4329 Standard_Boolean bIsComputed = Standard_False;
4330 theNewParameter = theParameter;
4332 Standard_Real acurpar = theParameter;
4333 TopAbs_State aState = TopAbs_ON;
4334 Standard_Integer iter = 0;
4335 Standard_Real asumtol = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4336 Standard_Real adelta = asumtol * 0.1;
4337 adelta = (adelta < Precision::Confusion()) ? Precision::Confusion() : adelta;
4338 Handle(Geom_Surface) aSurf1 = BRep_Tool::Surface(theFace1);
4339 Handle(Geom_Surface) aSurf2 = BRep_Tool::Surface(theFace2);
4341 Standard_Real u1, u2, v1, v2;
4343 GeomAPI_ProjectPointOnSurf aPrj1;
4344 aSurf1->Bounds(u1, u2, v1, v2);
4345 aPrj1.Init(aSurf1, u1, u2, v1, v2);
4347 GeomAPI_ProjectPointOnSurf aPrj2;
4348 aSurf2->Bounds(u1, u2, v1, v2);
4349 aPrj2.Init(aSurf2, u1, u2, v1, v2);
4351 while(aState == TopAbs_ON) {
4356 gp_Pnt aPCurrent = theCurve->Value(acurpar);
4357 aPrj1.Perform(aPCurrent);
4358 Standard_Real U=0., V=0.;
4360 if(aPrj1.IsDone()) {
4361 aPrj1.LowerDistanceParameters(U, V);
4362 aState = aContext->StatePointFace(theFace1, gp_Pnt2d(U, V));
4365 if(aState != TopAbs_ON) {
4366 aPrj2.Perform(aPCurrent);
4368 if(aPrj2.IsDone()) {
4369 aPrj2.LowerDistanceParameters(U, V);
4370 aState = aContext->StatePointFace(theFace2, gp_Pnt2d(U, V));
4381 theNewParameter = acurpar;
4382 bIsComputed = Standard_True;
4385 if(acurpar >= theOtherParameter)
4386 theNewParameter = theOtherParameter;
4389 if(acurpar <= theOtherParameter)
4390 theNewParameter = theOtherParameter;
4396 //=======================================================================
4397 //function : IsCurveValid
4399 //=======================================================================
4400 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve)
4402 if(thePCurve.IsNull())
4403 return Standard_False;
4405 Standard_Real tolint = 1.e-10;
4406 Geom2dAdaptor_Curve PCA;
4407 IntRes2d_Domain PCD;
4408 Geom2dInt_GInter PCI;
4410 Standard_Real pf = 0., pl = 0.;
4411 gp_Pnt2d pntf, pntl;
4413 if(!thePCurve->IsClosed() && !thePCurve->IsPeriodic()) {
4414 pf = thePCurve->FirstParameter();
4415 pl = thePCurve->LastParameter();
4416 pntf = thePCurve->Value(pf);
4417 pntl = thePCurve->Value(pl);
4418 PCA.Load(thePCurve);
4419 if(!PCA.IsPeriodic()) {
4420 if(PCA.FirstParameter() > pf) pf = PCA.FirstParameter();
4421 if(PCA.LastParameter() < pl) pl = PCA.LastParameter();
4423 PCD.SetValues(pntf,pf,tolint,pntl,pl,tolint);
4424 PCI.Perform(PCA,PCD,tolint,tolint);
4426 if(PCI.NbPoints() > 0) {
4427 return Standard_False;
4431 return Standard_True;
4434 //=======================================================================
4435 //static function : ApproxWithPCurves
4436 //purpose : for bug 20964 only
4437 //=======================================================================
4438 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
4439 const gp_Sphere& theSph)
4441 Standard_Boolean bRes = Standard_True;
4442 Standard_Real R1 = theCyl.Radius(), R2 = theSph.Radius();
4444 if(R1 < 2.*R2) return bRes;
4446 gp_Lin anCylAx(theCyl.Axis());
4448 Standard_Real aDist = anCylAx.Distance(theSph.Location());
4449 Standard_Real aDRel = Abs(aDist - R1)/R2;
4451 if(aDRel > .2) return bRes;
4453 Standard_Real par = ElCLib::Parameter(anCylAx, theSph.Location());
4454 gp_Pnt aP = ElCLib::Value(par, anCylAx);
4455 gp_Vec aV(aP, theSph.Location());
4457 Standard_Real dd = aV.Dot(theSph.Position().XDirection());
4459 if(aDist < R1 && dd > 0.) return Standard_False;
4460 if(aDist > R1 && dd < 0.) return Standard_False;
4465 //=======================================================================
4466 //function : PerformPlanes
4468 //=======================================================================
4469 void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
4470 const Handle(GeomAdaptor_HSurface)& theS2,
4471 const Standard_Real TolAng,
4472 const Standard_Real TolTang,
4473 const Standard_Boolean theApprox1,
4474 const Standard_Boolean theApprox2,
4475 IntTools_SequenceOfCurves& theSeqOfCurve,
4476 Standard_Boolean& theTangentFaces)
4479 gp_Pln aPln1 = theS1->Surface().Plane();
4480 gp_Pln aPln2 = theS2->Surface().Plane();
4482 IntAna_QuadQuadGeo aPlnInter(aPln1, aPln2, TolAng, TolTang);
4484 if(!aPlnInter.IsDone()) {
4485 theTangentFaces = Standard_False;
4489 IntAna_ResultType aResType = aPlnInter.TypeInter();
4491 if(aResType == IntAna_Same) {
4492 theTangentFaces = Standard_True;
4496 theTangentFaces = Standard_False;
4498 if(aResType == IntAna_Empty) {
4502 gp_Lin aLin = aPlnInter.Line(1);
4504 ProjLib_Plane aProj;
4507 aProj.Project(aLin);
4508 gp_Lin2d aLin2d1 = aProj.Line();
4511 aProj.Project(aLin);
4512 gp_Lin2d aLin2d2 = aProj.Line();
4514 //classify line2d1 relatively first plane
4515 Standard_Real P11, P12;
4516 Standard_Boolean IsCrossed = ClassifyLin2d(theS1, aLin2d1, TolTang, P11, P12);
4517 if(!IsCrossed) return;
4518 //classify line2d2 relatively second plane
4519 Standard_Real P21, P22;
4520 IsCrossed = ClassifyLin2d(theS2, aLin2d2, TolTang, P21, P22);
4521 if(!IsCrossed) return;
4523 //Analysis of parametric intervals: must have common part
4525 if(P21 >= P12) return;
4526 if(P22 <= P11) return;
4528 Standard_Real pmin, pmax;
4529 pmin = Max(P11, P21);
4530 pmax = Min(P12, P22);
4532 if(pmax - pmin <= TolTang) return;
4534 Handle(Geom_Line) aGLin = new Geom_Line(aLin);
4536 IntTools_Curve aCurve;
4537 Handle(Geom_TrimmedCurve) aGTLin = new Geom_TrimmedCurve(aGLin, pmin, pmax);
4539 aCurve.SetCurve(aGTLin);
4542 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d1);
4543 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4546 Handle(Geom2d_Curve) H1;
4547 aCurve.SetFirstCurve2d(H1);
4550 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d2);
4551 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4554 Handle(Geom2d_Curve) H1;
4555 aCurve.SetFirstCurve2d(H1);
4558 theSeqOfCurve.Append(aCurve);
4562 //=======================================================================
4563 //function : ClassifyLin2d
4565 //=======================================================================
4566 static inline Standard_Boolean INTER(const Standard_Real d1,
4567 const Standard_Real d2,
4568 const Standard_Real tol)
4570 return (d1 > tol && d2 < -tol) ||
4571 (d1 < -tol && d2 > tol) ||
4572 ((d1 <= tol && d1 >= -tol) && (d2 > tol || d2 < -tol)) ||
4573 ((d2 <= tol && d2 >= -tol) && (d1 > tol || d1 < -tol));
4575 static inline Standard_Boolean COINC(const Standard_Real d1,
4576 const Standard_Real d2,
4577 const Standard_Real tol)
4579 return (d1 <= tol && d1 >= -tol) && (d2 <= tol && d2 >= -tol);
4581 Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
4582 const gp_Lin2d& theLin2d,
4583 const Standard_Real theTol,
4584 Standard_Real& theP1,
4585 Standard_Real& theP2)
4588 Standard_Real xmin, xmax, ymin, ymax, d1, d2, A, B, C;
4589 Standard_Real par[2];
4590 Standard_Integer nbi = 0;
4592 xmin = theS->Surface().FirstUParameter();
4593 xmax = theS->Surface().LastUParameter();
4594 ymin = theS->Surface().FirstVParameter();
4595 ymax = theS->Surface().LastVParameter();
4597 theLin2d.Coefficients(A, B, C);
4599 //xmin, ymin <-> xmin, ymax
4600 d1 = A*xmin + B*ymin + C;
4601 d2 = A*xmin + B*ymax + C;
4603 if(INTER(d1, d2, theTol)) {
4604 //Intersection with boundary
4605 Standard_Real y = -(C + A*xmin)/B;
4606 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, y));
4609 else if (COINC(d1, d2, theTol)) {
4610 //Coincidence with boundary
4611 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4612 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4618 if(fabs(par[0]-par[1]) > theTol) {
4619 theP1 = Min(par[0], par[1]);
4620 theP2 = Max(par[0], par[1]);
4621 return Standard_True;
4623 else return Standard_False;
4627 //xmin, ymax <-> xmax, ymax
4629 d2 = A*xmax + B*ymax + C;
4631 if(d1 > theTol || d1 < -theTol) {//to avoid checking of
4632 //coincidence with the same point
4633 if(INTER(d1, d2, theTol)) {
4634 Standard_Real x = -(C + B*ymax)/A;
4635 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymax));
4638 else if (COINC(d1, d2, theTol)) {
4639 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4640 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4647 if(fabs(par[0]-par[1]) > theTol) {
4648 theP1 = Min(par[0], par[1]);
4649 theP2 = Max(par[0], par[1]);
4650 return Standard_True;
4652 else return Standard_False;
4656 //xmax, ymax <-> xmax, ymin
4658 d2 = A*xmax + B*ymin + C;
4660 if(d1 > theTol || d1 < -theTol) {
4661 if(INTER(d1, d2, theTol)) {
4662 Standard_Real y = -(C + A*xmax)/B;
4663 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, y));
4666 else if (COINC(d1, d2, theTol)) {
4667 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4668 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4674 if(fabs(par[0]-par[1]) > theTol) {
4675 theP1 = Min(par[0], par[1]);
4676 theP2 = Max(par[0], par[1]);
4677 return Standard_True;
4679 else return Standard_False;
4682 //xmax, ymin <-> xmin, ymin
4684 d2 = A*xmin + B*ymin + C;
4686 if(d1 > theTol || d1 < -theTol) {
4687 if(INTER(d1, d2, theTol)) {
4688 Standard_Real x = -(C + B*ymin)/A;
4689 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymin));
4692 else if (COINC(d1, d2, theTol)) {
4693 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4694 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4700 if(fabs(par[0]-par[1]) > theTol) {
4701 theP1 = Min(par[0], par[1]);
4702 theP2 = Max(par[0], par[1]);
4703 return Standard_True;
4705 else return Standard_False;
4708 return Standard_False;
4712 //=======================================================================
4713 //function : ApproxParameters
4715 //=======================================================================
4716 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
4717 const Handle(GeomAdaptor_HSurface)& aHS2,
4718 Standard_Integer& iDegMin,
4719 Standard_Integer& iDegMax,
4720 Standard_Integer& iNbIter)
4723 GeomAbs_SurfaceType aTS1, aTS2;
4730 aTS1=aHS1->Surface().GetType();
4731 aTS2=aHS2->Surface().GetType();
4734 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4735 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4736 Standard_Real aRC, aRT, dR, aPC;
4737 gp_Cylinder aCylinder;
4740 aPC=Precision::Confusion();
4742 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4743 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4745 aRC=aCylinder.Radius();
4746 aRT=aTorus.MinorRadius();
4756 if (aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Cylinder) {
4760 //=======================================================================
4761 //function : Tolerances
4763 //=======================================================================
4764 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
4765 const Handle(GeomAdaptor_HSurface)& aHS2,
4766 Standard_Real& aTolTang)
4768 GeomAbs_SurfaceType aTS1, aTS2;
4770 aTS1=aHS1->Surface().GetType();
4771 aTS2=aHS2->Surface().GetType();
4774 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4775 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4776 Standard_Real aRC, aRT, dR, aPC;
4777 gp_Cylinder aCylinder;
4780 aPC=Precision::Confusion();
4782 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4783 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4785 aRC=aCylinder.Radius();
4786 aRT=aTorus.MinorRadius();
4793 aTolTang=0.1*aTolTang;
4797 //=======================================================================
4798 //function : SortTypes
4800 //=======================================================================
4801 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
4802 const GeomAbs_SurfaceType aType2)
4804 Standard_Boolean bRet;
4805 Standard_Integer aI1, aI2;
4807 bRet=Standard_False;
4809 aI1=IndexType(aType1);
4810 aI2=IndexType(aType2);
4816 //=======================================================================
4817 //function : IndexType
4819 //=======================================================================
4820 Standard_Integer IndexType(const GeomAbs_SurfaceType aType)
4822 Standard_Integer aIndex;
4826 if (aType==GeomAbs_Plane) {
4829 else if (aType==GeomAbs_Cylinder) {
4832 else if (aType==GeomAbs_Cone) {
4835 else if (aType==GeomAbs_Sphere) {
4838 else if (aType==GeomAbs_Torus) {
4841 else if (aType==GeomAbs_BezierSurface) {
4844 else if (aType==GeomAbs_BSplineSurface) {
4847 else if (aType==GeomAbs_SurfaceOfRevolution) {
4850 else if (aType==GeomAbs_SurfaceOfExtrusion) {
4853 else if (aType==GeomAbs_OffsetSurface) {
4856 else if (aType==GeomAbs_OtherSurface) {
4861 #ifdef DEB_DUMPWLINE
4862 //=======================================================================
4863 //function : DumpWLine
4865 //=======================================================================
4866 void DumpWLine(const Handle(IntPatch_WLine)& aWLine)
4868 Standard_Integer i, aNbPnts;
4869 Standard_Real aX, aY, aZ, aU1, aV1, aU2, aV2;
4871 printf(" *WLine\n");
4872 aNbPnts=aWLine->NbPnts();
4873 for (i=1; i<=aNbPnts; ++i) {
4874 const IntSurf_PntOn2S aPntOn2S=aWLine->Point(i);
4875 const gp_Pnt& aP3D=aPntOn2S.Value();
4876 aP3D.Coord(aX, aY, aZ);
4877 aPntOn2S.Parameters(aU1, aV1, aU2, aV2);
4879 printf("point p_%d %lf %lf %lf\n", i, aX, aY, aZ);
4880 //printf("point p_%d %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf\n",
4881 // i, aX, aY, aZ, aU1, aV1, aU2, aV2);
4885 //=======================================================================
4886 //function : RefineVector
4888 //=======================================================================
4889 void RefineVector(gp_Vec2d& aV2D)
4891 Standard_Integer k,m;
4892 Standard_Real aC[2], aEps, aR1, aR2, aNum;
4898 aV2D.Coord(aC[0], aC[1]);
4900 for (k=0; k<2; ++k) {
4903 if (aNum>aR1 && aNum<aR2) {
4914 aV2D.SetCoord(aC[0], aC[1]);
4916 //=======================================================================
4917 //function : FindMaxSquareDistance
4919 //=======================================================================
4920 Standard_Real FindMaxSquareDistance (const Standard_Real aT1,
4921 const Standard_Real aT2,
4922 const Standard_Real aEps,
4923 const Handle(Geom_Curve)& aC3D,
4924 const Handle(Geom2d_Curve)& aC2D1,
4925 const Handle(Geom2d_Curve)& aC2D2,
4926 const Handle(GeomAdaptor_HSurface)& myHS1,
4927 const Handle(GeomAdaptor_HSurface)& myHS2,
4928 const TopoDS_Face& myFace1,
4929 const TopoDS_Face& myFace2,
4930 const Handle(BOPInt_Context)& myContext)
4932 Standard_Real aA, aB, aCf, aX1, aX2, aF1, aF2, aX, aF;
4934 aCf=1.6180339887498948482045868343656;// =0.5*(1.+sqrt(5.));
4938 aF1=MaxSquareDistance(aX1,
4939 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4941 aF2=MaxSquareDistance(aX2,
4942 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4946 if (fabs(aA-aB)<aEps) {
4948 aF=MaxSquareDistance(aX,
4949 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4957 aF2=MaxSquareDistance(aX2,
4958 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4966 aF1=MaxSquareDistance(aX1,
4967 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4972 //=======================================================================
4973 //function : MaxSquareDistance
4975 //=======================================================================
4976 Standard_Real MaxSquareDistance (const Standard_Real aT,
4977 const Handle(Geom_Curve)& aC3D,
4978 const Handle(Geom2d_Curve)& aC2D1,
4979 const Handle(Geom2d_Curve)& aC2D2,
4980 const Handle(GeomAdaptor_HSurface) myHS1,
4981 const Handle(GeomAdaptor_HSurface) myHS2,
4982 const TopoDS_Face& aF1,
4983 const TopoDS_Face& aF2,
4984 const Handle(BOPInt_Context)& aCtx)
4986 Standard_Boolean bIsDone;
4988 Standard_Real aU, aV, aD2Max, aD2;
4995 if (aC3D.IsNull()) {
4999 for (i=0; i<2; ++i) {
5000 const Handle(GeomAdaptor_HSurface)& aGHS=(!i) ? myHS1 : myHS2;
5001 const TopoDS_Face &aF=(!i) ? aF1 : aF2;
5002 const Handle(Geom2d_Curve)& aC2D=(!i) ? aC2D1 : aC2D2;
5004 if (!aC2D.IsNull()) {
5007 aGHS->D0(aU, aV, aPS);
5008 aD2=aP.SquareDistance(aPS);
5014 GeomAPI_ProjectPointOnSurf& aProjector=aCtx->ProjPS(aF);
5016 aProjector.Perform(aP);
5017 bIsDone=aProjector.IsDone();
5019 aProjector.LowerDistanceParameters(aU, aV);
5020 aGHS->D0(aU, aV, aPS);
5021 aD2=aP.SquareDistance(aPS);
5031 //=======================================================================
5032 //function : CheckPCurve
5033 //purpose : Checks if points of the pcurve are out of the face bounds.
5034 //=======================================================================
5035 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
5036 const TopoDS_Face& aFace)
5038 const Standard_Integer NPoints = 23;
5040 Standard_Real umin,umax,vmin,vmax;
5042 BRepTools::UVBounds(aFace, umin, umax, vmin, vmax);
5043 Standard_Real tolU = Max ((umax-umin)*0.01, Precision::Confusion());
5044 Standard_Real tolV = Max ((vmax-vmin)*0.01, Precision::Confusion());
5045 Standard_Real fp = aPC->FirstParameter();
5046 Standard_Real lp = aPC->LastParameter();
5049 // adjust domain for periodic surfaces
5050 TopLoc_Location aLoc;
5051 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc);
5052 if (aSurf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
5053 aSurf = (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf))->BasisSurface();
5055 gp_Pnt2d pnt = aPC->Value((fp+lp)/2);
5059 if (aSurf->IsUPeriodic()) {
5060 Standard_Real aPer = aSurf->UPeriod();
5061 Standard_Integer nshift = (Standard_Integer) ((u-umin)/aPer);
5062 if (u < umin+aPer*nshift) nshift--;
5063 umin += aPer*nshift;
5064 umax += aPer*nshift;
5066 if (aSurf->IsVPeriodic()) {
5067 Standard_Real aPer = aSurf->VPeriod();
5068 Standard_Integer nshift = (Standard_Integer) ((v-vmin)/aPer);
5069 if (v < vmin+aPer*nshift) nshift--;
5070 vmin += aPer*nshift;
5071 vmax += aPer*nshift;
5074 //--------------------------------------------------------
5075 Standard_Boolean bRet;
5076 Standard_Integer j, aNbIntervals;
5077 Standard_Real aT, dT;
5080 Geom2dAdaptor_Curve aGAC(aPC);
5081 aNbIntervals=aGAC.NbIntervals(GeomAbs_CN);
5083 TColStd_Array1OfReal aTI(1, aNbIntervals+1);
5084 aGAC.Intervals(aTI,GeomAbs_CN);
5086 bRet=Standard_False;
5088 aT=aGAC.FirstParameter();
5089 for (j=1; j<=aNbIntervals; ++j) {
5090 dT=(aTI(j+1)-aTI(j))/NPoints;
5092 for (i=1; i<NPoints; i++) {
5096 if (umin-u > tolU || u-umax > tolU ||
5097 vmin-v > tolV || v-vmax > tolV) {