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.
17 #include <Adaptor2d_HLine2d.hxx>
18 #include <Adaptor3d_SurfacePtr.hxx>
19 #include <Adaptor3d_TopolTool.hxx>
20 #include <Approx_CurveOnSurface.hxx>
21 #include <Bnd_Box.hxx>
22 #include <BndLib_AddSurface.hxx>
23 #include <BRep_Tool.hxx>
24 #include <BRepAdaptor_Surface.hxx>
25 #include <BRepTools.hxx>
28 #include <Extrema_ExtCC.hxx>
29 #include <Extrema_POnCurv.hxx>
30 #include <Geom2d_BSplineCurve.hxx>
31 #include <Geom2d_Circle.hxx>
32 #include <Geom2d_Curve.hxx>
33 #include <Geom2d_Line.hxx>
34 #include <Geom2d_TrimmedCurve.hxx>
35 #include <Geom2dAdaptor.hxx>
36 #include <Geom2dAdaptor_Curve.hxx>
37 #include <Geom2dAPI_InterCurveCurve.hxx>
38 #include <Geom2dInt_GInter.hxx>
39 #include <Geom_BSplineCurve.hxx>
40 #include <Geom_Circle.hxx>
41 #include <Geom_Conic.hxx>
42 #include <Geom_Curve.hxx>
43 #include <Geom_Ellipse.hxx>
44 #include <Geom_Hyperbola.hxx>
45 #include <Geom_Line.hxx>
46 #include <Geom_OffsetSurface.hxx>
47 #include <Geom_Parabola.hxx>
48 #include <Geom_RectangularTrimmedSurface.hxx>
49 #include <Geom_Surface.hxx>
50 #include <Geom_TrimmedCurve.hxx>
51 #include <GeomAbs_CurveType.hxx>
52 #include <GeomAbs_SurfaceType.hxx>
53 #include <GeomAdaptor.hxx>
54 #include <GeomAdaptor_Curve.hxx>
55 #include <GeomAdaptor_HSurface.hxx>
56 #include <GeomAdaptor_Surface.hxx>
57 #include <GeomAPI_ProjectPointOnSurf.hxx>
58 #include <GeomInt.hxx>
59 #include <GeomInt_IntSS.hxx>
60 #include <GeomInt_WLApprox.hxx>
61 #include <GeomLib_Check2dBSplineCurve.hxx>
62 #include <GeomLib_CheckBSplineCurve.hxx>
63 #include <GeomProjLib.hxx>
64 #include <gp_Ax22d.hxx>
65 #include <gp_Circ2d.hxx>
66 #include <gp_Cylinder.hxx>
67 #include <gp_Lin2d.hxx>
68 #include <gp_Torus.hxx>
69 #include <IntAna_QuadQuadGeo.hxx>
70 #include <IntPatch_ALine.hxx>
71 #include <IntPatch_ALineToWLine.hxx>
72 #include <IntPatch_GLine.hxx>
73 #include <IntPatch_RLine.hxx>
74 #include <IntPatch_WLine.hxx>
75 #include <IntRes2d_Domain.hxx>
76 #include <IntSurf_LineOn2S.hxx>
77 #include <IntSurf_ListIteratorOfListOfPntOn2S.hxx>
78 #include <IntSurf_ListOfPntOn2S.hxx>
79 #include <IntSurf_PntOn2S.hxx>
80 #include <IntTools_Context.hxx>
81 #include <IntTools_Curve.hxx>
82 #include <IntTools_FaceFace.hxx>
83 #include <IntTools_PntOn2Faces.hxx>
84 #include <IntTools_PntOnFace.hxx>
85 #include <IntTools_Tools.hxx>
86 #include <IntTools_TopolTool.hxx>
87 #include <Precision.hxx>
88 #include <ProjLib_Plane.hxx>
89 #include <StdFail_NotDone.hxx>
90 #include <TColgp_Array1OfPnt.hxx>
91 #include <TColgp_Array1OfPnt2d.hxx>
92 #include <TColgp_HArray1OfPnt2d.hxx>
93 #include <TColgp_SequenceOfPnt2d.hxx>
94 #include <TColStd_Array1OfInteger.hxx>
95 #include <TColStd_Array1OfListOfInteger.hxx>
96 #include <TColStd_Array1OfReal.hxx>
97 #include <TColStd_HArray1OfReal.hxx>
98 #include <TColStd_ListIteratorOfListOfInteger.hxx>
99 #include <TColStd_ListOfInteger.hxx>
100 #include <TColStd_SequenceOfReal.hxx>
101 #include <TopExp_Explorer.hxx>
102 #include <TopoDS.hxx>
103 #include <TopoDS_Edge.hxx>
104 #include <TopoDS_Face.hxx>
107 void RefineVector(gp_Vec2d& aV2D);
108 #ifdef OCCT_DEBUG_DUMPWLINE
110 void DumpWLine(const Handle(IntPatch_WLine)& aWLine);
114 void TolR3d(const TopoDS_Face& ,
118 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)&,
119 const Standard_Integer,
120 const Standard_Integer);
123 void Parameters(const Handle(GeomAdaptor_HSurface)&,
124 const Handle(GeomAdaptor_HSurface)&,
132 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
133 const Standard_Real theTolerance,
134 Standard_Real& theumin,
135 Standard_Real& theumax,
136 Standard_Real& thevmin,
137 Standard_Real& thevmax);
140 Standard_Boolean NotUseSurfacesForApprox
141 (const TopoDS_Face& aF1,
142 const TopoDS_Face& aF2,
143 const Handle(IntPatch_WLine)& WL,
144 const Standard_Integer ifprm,
145 const Standard_Integer ilprm);
148 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine);
151 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
152 const Standard_Integer ideb,
153 const Standard_Integer ifin,
154 const Standard_Boolean onFirst);
157 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
158 const Handle(GeomAdaptor_HSurface)& theSurface1,
159 const Handle(GeomAdaptor_HSurface)& theSurface2,
160 const TopoDS_Face& theFace1,
161 const TopoDS_Face& theFace2,
162 const GeomInt_LineConstructor& theLConstructor,
163 const Standard_Boolean theAvoidLConstructor,
164 IntPatch_SequenceOfLine& theNewLines,
165 Standard_Real& theReachedTol3d,
166 const Handle(IntTools_Context)& );
169 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
170 const Handle(Geom_Curve)& theCurve,
171 const TopoDS_Face& theFace1,
172 const TopoDS_Face& theFace2,
173 const Standard_Real theOtherParameter,
174 const Standard_Boolean bIncreasePar,
175 Standard_Real& theNewParameter,
176 const Handle(IntTools_Context)& );
179 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve);
182 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
183 const Standard_Real theFirstBoundary,
184 const Standard_Real theSecondBoundary,
185 const Standard_Real theResolution,
186 Standard_Boolean& IsOnFirstBoundary);
188 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
189 const gp_Pnt2d& theLastPoint,
190 const Standard_Real theUmin,
191 const Standard_Real theUmax,
192 const Standard_Real theVmin,
193 const Standard_Real theVmax,
194 gp_Pnt2d& theNewPoint);
198 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
199 const Handle(GeomAdaptor_HSurface)& theSurface2,
200 const TopoDS_Face& theFace1,
201 const TopoDS_Face& theFace2,
202 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
203 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
204 Handle(TColStd_HArray1OfReal)& theResultRadius,
205 const Handle(IntTools_Context)& );
208 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
209 const gp_Pnt2d& theLastPoint,
210 const Standard_Real theUmin,
211 const Standard_Real theUmax,
212 const Standard_Real theVmin,
213 const Standard_Real theVmax,
214 const gp_Pnt2d& theTanZoneCenter,
215 const Standard_Real theZoneRadius,
216 Handle(GeomAdaptor_HSurface) theGASurface,
217 gp_Pnt2d& theNewPoint);
220 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
221 const gp_Pnt2d& theTanZoneCenter,
222 const Standard_Real theZoneRadius,
223 Handle(GeomAdaptor_HSurface) theGASurface);
226 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
227 const gp_Pnt2d& theOriginalPoint,
228 Handle(GeomAdaptor_HSurface) theGASurface);
230 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
231 const gp_Sphere& theSph);
233 static void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
234 const Handle(GeomAdaptor_HSurface)& theS2,
235 const Standard_Real TolAng,
236 const Standard_Real TolTang,
237 const Standard_Boolean theApprox1,
238 const Standard_Boolean theApprox2,
239 IntTools_SequenceOfCurves& theSeqOfCurve,
240 Standard_Boolean& theTangentFaces);
242 static Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
243 const gp_Lin2d& theLin2d,
244 const Standard_Real theTol,
245 Standard_Real& theP1,
246 Standard_Real& theP2);
249 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
250 const Handle(GeomAdaptor_HSurface)& aHS2,
251 Standard_Integer& iDegMin,
252 Standard_Integer& iNbIter,
253 Standard_Integer& iDegMax);
256 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
257 const Handle(GeomAdaptor_HSurface)& aHS2,
258 Standard_Real& aTolTang);
261 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
262 const GeomAbs_SurfaceType aType2);
264 Standard_Integer IndexType(const GeomAbs_SurfaceType aType);
268 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
269 const TopoDS_Face& aFace);
272 void CorrectPlaneBoundaries(Standard_Real& aUmin,
273 Standard_Real& aUmax,
274 Standard_Real& aVmin,
275 Standard_Real& aVmax);
277 //=======================================================================
280 //=======================================================================
281 IntTools_FaceFace::IntTools_FaceFace()
283 myIsDone=Standard_False;
284 myTangentFaces=Standard_False;
286 myHS1 = new GeomAdaptor_HSurface ();
287 myHS2 = new GeomAdaptor_HSurface ();
290 SetParameters(Standard_True, Standard_True, Standard_True, 1.e-07);
293 //=======================================================================
294 //function : SetContext
296 //=======================================================================
297 void IntTools_FaceFace::SetContext(const Handle(IntTools_Context)& aContext)
301 //=======================================================================
304 //=======================================================================
305 const Handle(IntTools_Context)& IntTools_FaceFace::Context()const
309 //=======================================================================
312 //=======================================================================
313 const TopoDS_Face& IntTools_FaceFace::Face1() const
317 //=======================================================================
320 //=======================================================================
321 const TopoDS_Face& IntTools_FaceFace::Face2() const
325 //=======================================================================
326 //function : TangentFaces
328 //=======================================================================
329 Standard_Boolean IntTools_FaceFace::TangentFaces() const
331 return myTangentFaces;
333 //=======================================================================
336 //=======================================================================
337 const IntTools_SequenceOfPntOn2Faces& IntTools_FaceFace::Points() const
341 //=======================================================================
344 //=======================================================================
345 Standard_Boolean IntTools_FaceFace::IsDone() const
349 //=======================================================================
350 //function : TolReached3d
352 //=======================================================================
353 Standard_Real IntTools_FaceFace::TolReached3d() const
355 return myTolReached3d;
357 //=======================================================================
359 //purpose : return lines of intersection
360 //=======================================================================
361 const IntTools_SequenceOfCurves& IntTools_FaceFace::Lines() const
363 StdFail_NotDone_Raise_if
365 "IntTools_FaceFace::Lines() => myIntersector NOT DONE");
368 //=======================================================================
369 //function : TolReached2d
371 //=======================================================================
372 Standard_Real IntTools_FaceFace::TolReached2d() const
374 return myTolReached2d;
376 // =======================================================================
377 // function: SetParameters
379 // =======================================================================
380 void IntTools_FaceFace::SetParameters(const Standard_Boolean ToApproxC3d,
381 const Standard_Boolean ToApproxC2dOnS1,
382 const Standard_Boolean ToApproxC2dOnS2,
383 const Standard_Real ApproximationTolerance)
385 myApprox = ToApproxC3d;
386 myApprox1 = ToApproxC2dOnS1;
387 myApprox2 = ToApproxC2dOnS2;
388 myTolApprox = ApproximationTolerance;
390 //=======================================================================
393 //=======================================================================
394 void IntTools_FaceFace::SetList(IntSurf_ListOfPntOn2S& aListOfPnts)
396 myListOfPnts = aListOfPnts;
400 static Standard_Boolean isTreatAnalityc(const TopoDS_Face& theF1,
401 const TopoDS_Face& theF2)
403 const Standard_Real Tolang = 1.e-8;
404 const Standard_Real aTolF1=BRep_Tool::Tolerance(theF1);
405 const Standard_Real aTolF2=BRep_Tool::Tolerance(theF2);
406 const Standard_Real aTolSum = aTolF1 + aTolF2;
407 Standard_Real aHigh = 0.0;
409 const BRepAdaptor_Surface aBAS1(theF1), aBAS2(theF2);
410 const GeomAbs_SurfaceType aType1=aBAS1.GetType();
411 const GeomAbs_SurfaceType aType2=aBAS2.GetType();
415 if(aType1 == GeomAbs_Plane)
419 else if(aType2 == GeomAbs_Plane)
425 return Standard_True;
428 if(aType1 == GeomAbs_Cylinder)
430 aS2=aBAS1.Cylinder();
431 const Standard_Real VMin = aBAS1.FirstVParameter();
432 const Standard_Real VMax = aBAS1.LastVParameter();
434 if( Precision::IsNegativeInfinite(VMin) ||
435 Precision::IsPositiveInfinite(VMax))
436 return Standard_True;
440 else if(aType2 == GeomAbs_Cylinder)
442 aS2=aBAS2.Cylinder();
444 const Standard_Real VMin = aBAS2.FirstVParameter();
445 const Standard_Real VMax = aBAS2.LastVParameter();
447 if( Precision::IsNegativeInfinite(VMin) ||
448 Precision::IsPositiveInfinite(VMax))
449 return Standard_True;
455 return Standard_True;
458 IntAna_QuadQuadGeo inter;
459 inter.Perform(aS1,aS2,Tolang,aTolSum, aHigh);
460 if(inter.TypeInter() == IntAna_Ellipse)
462 const gp_Elips anEl = inter.Ellipse(1);
463 const Standard_Real aMajorR = anEl.MajorRadius();
464 const Standard_Real aMinorR = anEl.MinorRadius();
466 return (aMajorR < 100000.0 * aMinorR);
470 return inter.IsDone();
473 //=======================================================================
475 //purpose : intersect surfaces of the faces
476 //=======================================================================
477 void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
478 const TopoDS_Face& aF2)
480 Standard_Boolean RestrictLine = Standard_False, hasCone = Standard_False;
482 if (myContext.IsNull()) {
483 myContext=new IntTools_Context;
486 mySeqOfCurve.Clear();
489 myIsDone = Standard_False;
495 const BRepAdaptor_Surface aBAS1(myFace1, Standard_False);
496 const BRepAdaptor_Surface aBAS2(myFace2, Standard_False);
497 GeomAbs_SurfaceType aType1=aBAS1.GetType();
498 GeomAbs_SurfaceType aType2=aBAS2.GetType();
500 const Standard_Boolean bReverse=SortTypes(aType1, aType2);
505 aType1=aBAS2.GetType();
506 aType2=aBAS1.GetType();
508 if (myListOfPnts.Extent())
510 Standard_Real aU1,aV1,aU2,aV2;
511 IntSurf_ListIteratorOfListOfPntOn2S aItP2S;
513 aItP2S.Initialize(myListOfPnts);
514 for (; aItP2S.More(); aItP2S.Next())
516 IntSurf_PntOn2S& aP2S=aItP2S.Value();
517 aP2S.Parameters(aU1,aV1,aU2,aV2);
518 aP2S.SetValue(aU2,aV2,aU1,aV1);
522 Standard_Boolean anAproxTmp = myApprox1;
523 myApprox1 = myApprox2;
524 myApprox2 = anAproxTmp;
528 const Handle(Geom_Surface) S1=BRep_Tool::Surface(myFace1);
529 const Handle(Geom_Surface) S2=BRep_Tool::Surface(myFace2);
531 const Standard_Real aTolF1=BRep_Tool::Tolerance(myFace1);
532 const Standard_Real aTolF2=BRep_Tool::Tolerance(myFace2);
534 Standard_Real TolArc = aTolF1 + aTolF2;
535 Standard_Real TolTang = TolArc;
537 const Standard_Boolean isFace1Quad = (aType1 == GeomAbs_Cylinder ||
538 aType1 == GeomAbs_Cone ||
539 aType1 == GeomAbs_Torus);
541 const Standard_Boolean isFace2Quad = (aType2 == GeomAbs_Cylinder ||
542 aType2 == GeomAbs_Cone ||
543 aType2 == GeomAbs_Torus);
545 if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
546 Standard_Real umin, umax, vmin, vmax;
548 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
549 CorrectPlaneBoundaries(umin, umax, vmin, vmax);
550 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
552 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
553 CorrectPlaneBoundaries(umin, umax, vmin, vmax);
554 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
556 Standard_Real TolAng = 1.e-8;
558 PerformPlanes(myHS1, myHS2, TolAng, TolTang, myApprox1, myApprox2,
559 mySeqOfCurve, myTangentFaces);
561 myIsDone = Standard_True;
563 if(!myTangentFaces) {
564 const Standard_Integer NbLinPP = mySeqOfCurve.Length();
566 Standard_Real aTolFMax;
567 myTolReached3d = 1.e-7;
568 aTolFMax=Max(aTolF1, aTolF2);
569 if (aTolFMax>myTolReached3d) {
570 myTolReached3d=aTolFMax;
573 myTolReached2d = myTolReached3d;
576 Handle(Geom2d_Curve) aC2D1, aC2D2;
577 const Standard_Integer aNbLin = mySeqOfCurve.Length();
578 for (Standard_Integer i = 1; i <= aNbLin; ++i) {
579 IntTools_Curve& aIC=mySeqOfCurve(i);
580 aC2D1=aIC.FirstCurve2d();
581 aC2D2=aIC.SecondCurve2d();
582 aIC.SetFirstCurve2d(aC2D2);
583 aIC.SetSecondCurve2d(aC2D1);
589 }//if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
591 if ((aType1==GeomAbs_Plane) && isFace2Quad)
593 Standard_Real umin, umax, vmin, vmax;
595 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
596 CorrectPlaneBoundaries(umin, umax, vmin, vmax);
597 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
599 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
600 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
601 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
603 if( aType2==GeomAbs_Cone ) {
605 hasCone = Standard_True;
608 else if ((aType2==GeomAbs_Plane) && isFace1Quad)
610 Standard_Real umin, umax, vmin, vmax;
612 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
613 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
614 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
616 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
617 CorrectPlaneBoundaries(umin, umax, vmin, vmax);
618 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
620 if( aType1==GeomAbs_Cone ) {
622 hasCone = Standard_True;
627 Standard_Real umin, umax, vmin, vmax;
628 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
629 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
630 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
631 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
632 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
633 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
636 const Handle(IntTools_TopolTool) dom1 = new IntTools_TopolTool(myHS1);
637 const Handle(IntTools_TopolTool) dom2 = new IntTools_TopolTool(myHS2);
639 myLConstruct.Load(dom1, dom2, myHS1, myHS2);
642 Tolerances(myHS1, myHS2, TolTang);
645 const Standard_Real UVMaxStep = 0.001;
646 const Standard_Real Deflection = (hasCone) ? 0.085 : 0.1;
647 myIntersector.SetTolerances(TolArc, TolTang, UVMaxStep, Deflection);
650 if((myHS1->IsUClosed() && !myHS1->IsUPeriodic()) ||
651 (myHS1->IsVClosed() && !myHS1->IsVPeriodic()) ||
652 (myHS2->IsUClosed() && !myHS2->IsUPeriodic()) ||
653 (myHS2->IsVClosed() && !myHS2->IsVPeriodic()))
655 RestrictLine = Standard_True;
658 if((aType1 != GeomAbs_BSplineSurface) &&
659 (aType1 != GeomAbs_BezierSurface) &&
660 (aType1 != GeomAbs_OtherSurface) &&
661 (aType2 != GeomAbs_BSplineSurface) &&
662 (aType2 != GeomAbs_BezierSurface) &&
663 (aType2 != GeomAbs_OtherSurface))
665 RestrictLine = Standard_True;
667 if ((aType1 == GeomAbs_Torus) ||
668 (aType2 == GeomAbs_Torus))
670 myListOfPnts.Clear();
677 TopExp_Explorer aExp;
678 for(Standard_Integer i = 0; (!RestrictLine) && (i < 2); i++)
680 const TopoDS_Face& aF=(!i) ? myFace1 : myFace2;
681 aExp.Init(aF, TopAbs_EDGE);
682 for(; aExp.More(); aExp.Next())
684 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
686 if(BRep_Tool::Degenerated(aE))
688 RestrictLine = Standard_True;
695 const Standard_Boolean isGeomInt = isTreatAnalityc(aF1, aF2);
696 myIntersector.Perform(myHS1, dom1, myHS2, dom2, TolArc, TolTang,
697 myListOfPnts, RestrictLine, isGeomInt);
699 myIsDone = myIntersector.IsDone();
703 myTangentFaces=myIntersector.TangentFaces();
704 if (myTangentFaces) {
709 myListOfPnts.Clear(); // to use LineConstructor
712 const Standard_Integer aNbLin = myIntersector.NbLines();
713 for (Standard_Integer i=1; i <= aNbLin; ++i) {
714 MakeCurve(i, dom1, dom2);
717 ComputeTolReached3d();
720 Handle(Geom2d_Curve) aC2D1, aC2D2;
722 const Standard_Integer aNbLin=mySeqOfCurve.Length();
723 for (Standard_Integer i=1; i<=aNbLin; ++i)
725 IntTools_Curve& aIC=mySeqOfCurve(i);
726 aC2D1=aIC.FirstCurve2d();
727 aC2D2=aIC.SecondCurve2d();
728 aIC.SetFirstCurve2d(aC2D2);
729 aIC.SetSecondCurve2d(aC2D1);
734 Standard_Boolean bValid2D1, bValid2D2;
735 Standard_Real U1,V1,U2,V2;
736 IntTools_PntOnFace aPntOnF1, aPntOnF2;
737 IntTools_PntOn2Faces aPntOn2Faces;
739 const Standard_Integer aNbPnts = myIntersector.NbPnts();
740 for (Standard_Integer i=1; i <= aNbPnts; ++i)
742 const IntSurf_PntOn2S& aISPnt=myIntersector.Point(i).PntOn2S();
743 const gp_Pnt& aPnt=aISPnt.Value();
744 aISPnt.Parameters(U1,V1,U2,V2);
746 // check the validity of the intersection point for the faces
747 bValid2D1 = myContext->IsPointInOnFace(myFace1, gp_Pnt2d(U1, V1));
752 bValid2D2 = myContext->IsPointInOnFace(myFace2, gp_Pnt2d(U2, V2));
757 // add the intersection point
758 aPntOnF1.Init(myFace1, aPnt, U1, V1);
759 aPntOnF2.Init(myFace2, aPnt, U2, V2);
763 aPntOn2Faces.SetP1(aPntOnF1);
764 aPntOn2Faces.SetP2(aPntOnF2);
768 aPntOn2Faces.SetP2(aPntOnF1);
769 aPntOn2Faces.SetP1(aPntOnF2);
772 myPnts.Append(aPntOn2Faces);
777 //=======================================================================
778 //function : ComputeTolerance
780 //=======================================================================
781 Standard_Real IntTools_FaceFace::ComputeTolerance()
783 Standard_Integer i, j, aNbLin;
784 Standard_Real aFirst, aLast, aD, aDMax, aT;
785 Handle(Geom_Surface) aS1, aS2;
788 aNbLin = mySeqOfCurve.Length();
790 aS1 = myHS1->ChangeSurface().Surface();
791 aS2 = myHS2->ChangeSurface().Surface();
793 for (i = 1; i <= aNbLin; ++i)
795 const IntTools_Curve& aIC = mySeqOfCurve(i);
796 const Handle(Geom_Curve)& aC3D = aIC.Curve();
802 aFirst = aC3D->FirstParameter();
803 aLast = aC3D->LastParameter();
805 const Handle(Geom2d_Curve)& aC2D1 = aIC.FirstCurve2d();
806 const Handle(Geom2d_Curve)& aC2D2 = aIC.SecondCurve2d();
808 for (j = 0; j < 2; ++j)
810 const Handle(Geom2d_Curve)& aC2D = !j ? aC2D1 : aC2D2;
811 const Handle(Geom_Surface)& aS = !j ? aS1 : aS2;
815 if (IntTools_Tools::ComputeTolerance
816 (aC3D, aC2D, aS, aFirst, aLast, aD, aT))
830 //=======================================================================
831 //function :ComputeTolReached3d
833 //=======================================================================
834 void IntTools_FaceFace::ComputeTolReached3d()
836 Standard_Integer aNbLin, i;
837 GeomAbs_SurfaceType aType1, aType2;
839 aNbLin=myIntersector.NbLines();
844 aType1=myHS1->Surface().GetType();
845 aType2=myHS2->Surface().GetType();
847 if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
849 Handle(IntPatch_Line) aIL1, aIL2;
850 IntPatch_IType aTL1, aTL2;
852 aIL1=myIntersector.Line(1);
853 aIL2=myIntersector.Line(2);
854 aTL1=aIL1->ArcType();
855 aTL2=aIL2->ArcType();
856 if (aTL1==IntPatch_Lin && aTL2==IntPatch_Lin) {
857 Standard_Real aD, aDTresh, dTol;
863 aL1=Handle(IntPatch_GLine)::DownCast(aIL1)->Line();
864 aL2=Handle(IntPatch_GLine)::DownCast(aIL2)->Line();
865 aD=aL1.Distance(aL2);
868 myTolReached3d=aD+dTol;
874 if (aNbLin) {// Check the distances
877 aDMax = ComputeTolerance();
879 myTolReached3d = aDMax;
882 }// if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
885 else if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
886 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
890 aTolF1 = BRep_Tool::Tolerance(myFace1);
891 aTolF2 = BRep_Tool::Tolerance(myFace2);
892 aTolFMax=Max(aTolF1, aTolF2);
894 if (aTolFMax>aTolTresh) {
895 myTolReached3d=aTolFMax;
897 }//if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
900 else if((aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) ||
901 (aType2 == GeomAbs_Cylinder && aType1 == GeomAbs_Plane)) {
903 const Handle(IntPatch_Line)& aIL1 = myIntersector.Line(1);
904 if(aIL1->ArcType() == IntPatch_Circle) {
905 gp_Circ aCir = Handle(IntPatch_GLine)::DownCast(aIL1)->Circle();
906 gp_XYZ aCirDir = aCir.Axis().Direction().XYZ();
909 if(aType1 == GeomAbs_Plane) {
910 aPln = myHS1->Surface().Plane();
913 aPln = myHS2->Surface().Plane();
915 aPlDir = aPln.Axis().Direction().XYZ();
916 Standard_Real cs = aCirDir*aPlDir;
917 if(cs < 0.) aPlDir.Reverse();
918 Standard_Real eps = 1.e-14;
919 if(!aPlDir.IsEqual(aCirDir, eps)) {
920 Standard_Integer aNbP = 11;
921 Standard_Real dt = 2.*M_PI / (aNbP - 1), t;
922 for(t = 0.; t < 2.*M_PI; t += dt) {
923 Standard_Real d = aPln.Distance(ElCLib::Value(t, aCir));
924 if(myTolReached3d < d) myTolReached3d = d;
926 myTolReached3d *= 1.1;
928 } //aIL1->ArcType() == IntPatch_Circle
930 } // aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane)
931 //End IFV Bug OCC20297
933 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
934 (aType2==GeomAbs_Plane && aType1==GeomAbs_Torus)) {
935 aNbLin=mySeqOfCurve.Length();
940 Standard_Integer aNbP;
941 Standard_Real aT, aT1, aT2, dT, aUT, aVT, aUP, aVP;
942 Standard_Real aDP, aDT, aDmax;
947 const IntTools_Curve& aIC=mySeqOfCurve(1);
948 const Handle(Geom_Curve)& aC3D=aIC.Curve();
949 Handle(Geom_BSplineCurve) aBS (Handle(Geom_BSplineCurve)::DownCast(aC3D));
954 aT1=aBS->FirstParameter();
955 aT2=aBS->LastParameter();
957 aPln =(aType1==GeomAbs_Plane) ? myHS1->Plane() : myHS2->Plane();
958 aTorus=(aType1==GeomAbs_Plane) ? myHS2->Torus() : myHS1->Torus();
962 dT=(aT2-aT1)/(aNbP-1);
963 for (i=0; i<aNbP; ++i) {
971 ElSLib::Parameters(aPln, aP, aUP, aVP);
972 aPP=ElSLib::Value(aUP, aVP, aPln);
973 aDP=aP.SquareDistance(aPP);
978 ElSLib::Parameters(aTorus, aP, aUT, aVT);
979 aPT=ElSLib::Value(aUT, aVT, aTorus);
980 aDT=aP.SquareDistance(aPT);
986 if (aDmax > myTolReached3d*myTolReached3d) {
987 myTolReached3d=sqrt(aDmax);
988 myTolReached3d=1.1*myTolReached3d;
990 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
992 else if ((aType1==GeomAbs_SurfaceOfRevolution && aType2==GeomAbs_Cylinder) ||
993 (aType2==GeomAbs_SurfaceOfRevolution && aType1==GeomAbs_Cylinder) ||
994 (aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ||
995 (aType2==GeomAbs_Plane && aType1==GeomAbs_Sphere) ||
996 (aType1==GeomAbs_Plane && aType2==GeomAbs_SurfaceOfExtrusion) ||
997 (aType2==GeomAbs_Plane && aType1==GeomAbs_SurfaceOfExtrusion) ||
998 (aType1==GeomAbs_Plane && aType2==GeomAbs_BSplineSurface) ||
999 (aType2==GeomAbs_Plane && aType1==GeomAbs_BSplineSurface) ||
1002 Standard_Real aDMax;
1004 aDMax = ComputeTolerance();
1005 if (aDMax > myTolReached3d) {
1006 myTolReached3d = aDMax;
1011 //=======================================================================
1012 //function : MakeCurve
1014 //=======================================================================
1015 void IntTools_FaceFace::MakeCurve(const Standard_Integer Index,
1016 const Handle(Adaptor3d_TopolTool)& dom1,
1017 const Handle(Adaptor3d_TopolTool)& dom2)
1019 Standard_Boolean bDone, rejectSurface, reApprox, bAvoidLineConstructor;
1020 Standard_Boolean ok, bPCurvesOk;
1021 Standard_Integer i, j, aNbParts;
1022 Standard_Real fprm, lprm;
1023 Standard_Real Tolpc;
1024 Handle(IntPatch_Line) L;
1025 IntPatch_IType typl;
1026 Handle(Geom_Curve) newc;
1028 const Standard_Real TOLCHECK =0.0000001;
1029 const Standard_Real TOLANGCHECK=0.1;
1031 rejectSurface = Standard_False;
1032 reApprox = Standard_False;
1034 bPCurvesOk = Standard_True;
1038 Tolpc = myTolApprox;
1039 bAvoidLineConstructor = Standard_False;
1040 L = myIntersector.Line(Index);
1041 typl = L->ArcType();
1043 if(typl==IntPatch_Walking) {
1044 Handle(IntPatch_Line) anewL;
1046 Handle(IntPatch_WLine) aWLine (Handle(IntPatch_WLine)::DownCast(L));
1047 //DumpWLine(aWLine);
1049 anewL = ComputePurgedWLine(aWLine);
1050 if(anewL.IsNull()) {
1055 //Handle(IntPatch_WLine) aWLineX (Handle(IntPatch_WLine)::DownCast(L));
1056 //DumpWLine(aWLineX);
1059 if(!myListOfPnts.IsEmpty()) {
1060 bAvoidLineConstructor = Standard_True;
1063 Standard_Integer nbp = aWLine->NbPnts();
1064 const IntSurf_PntOn2S& p1 = aWLine->Point(1);
1065 const IntSurf_PntOn2S& p2 = aWLine->Point(nbp);
1067 const gp_Pnt& P1 = p1.Value();
1068 const gp_Pnt& P2 = p2.Value();
1070 if(P1.SquareDistance(P2) < 1.e-14) {
1071 bAvoidLineConstructor = Standard_False;
1079 if(!bAvoidLineConstructor) {
1080 myLConstruct.Perform(L);
1082 bDone=myLConstruct.IsDone();
1088 if(typl != IntPatch_Restriction)
1090 aNbParts=myLConstruct.NbParts();
1101 //########################################
1102 // Line, Parabola, Hyperbola
1103 //########################################
1105 case IntPatch_Parabola:
1106 case IntPatch_Hyperbola: {
1107 if (typl == IntPatch_Lin) {
1109 new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line());
1112 else if (typl == IntPatch_Parabola) {
1114 new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola());
1117 else if (typl == IntPatch_Hyperbola) {
1119 new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola());
1123 if (typl == IntPatch_Lin) {
1124 TolR3d (myFace1, myFace2, myTolReached3d);
1127 aNbParts=myLConstruct.NbParts();
1128 for (i=1; i<=aNbParts; i++) {
1129 Standard_Boolean bFNIt, bLPIt;
1131 myLConstruct.Part(i, fprm, lprm);
1133 bFNIt=Precision::IsNegativeInfinite(fprm);
1134 bLPIt=Precision::IsPositiveInfinite(lprm);
1136 if (!bFNIt && !bLPIt) {
1138 IntTools_Curve aCurve;
1140 Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm);
1141 aCurve.SetCurve(aCT3D);
1142 if (typl == IntPatch_Parabola) {
1143 Standard_Real aTolF1, aTolF2, aTolBase;
1145 aTolF1 = BRep_Tool::Tolerance(myFace1);
1146 aTolF2 = BRep_Tool::Tolerance(myFace2);
1147 aTolBase=aTolF1+aTolF2;
1148 myTolReached3d=IntTools_Tools::CurveTolerance(aCT3D, aTolBase);
1151 aCurve.SetCurve(new Geom_TrimmedCurve(newc, fprm, lprm));
1153 Handle (Geom2d_Curve) C2d;
1154 GeomInt_IntSS::BuildPCurves(fprm, lprm, Tolpc,
1155 myHS1->ChangeSurface().Surface(), newc, C2d);
1156 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1157 myTolReached2d=Tolpc;
1160 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1163 Handle(Geom2d_BSplineCurve) H1;
1165 aCurve.SetFirstCurve2d(H1);
1169 Handle (Geom2d_Curve) C2d;
1170 GeomInt_IntSS::BuildPCurves(fprm, lprm, Tolpc,
1171 myHS2->ChangeSurface().Surface(), newc, C2d);
1172 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1173 myTolReached2d=Tolpc;
1176 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1179 Handle(Geom2d_BSplineCurve) H1;
1181 aCurve.SetSecondCurve2d(H1);
1183 mySeqOfCurve.Append(aCurve);
1184 } //if (!bFNIt && !bLPIt) {
1186 // on regarde si on garde
1188 Standard_Real aTestPrm, dT=100.;
1191 if (bFNIt && !bLPIt) {
1194 else if (!bFNIt && bLPIt) {
1198 // i.e, if (bFNIt && bLPIt)
1199 aTestPrm=IntTools_Tools::IntermediatePoint(-dT, dT);
1202 gp_Pnt ptref(newc->Value(aTestPrm));
1204 GeomAbs_SurfaceType typS1 = myHS1->GetType();
1205 GeomAbs_SurfaceType typS2 = myHS2->GetType();
1206 if( typS1 == GeomAbs_SurfaceOfExtrusion ||
1207 typS1 == GeomAbs_OffsetSurface ||
1208 typS1 == GeomAbs_SurfaceOfRevolution ||
1209 typS2 == GeomAbs_SurfaceOfExtrusion ||
1210 typS2 == GeomAbs_OffsetSurface ||
1211 typS2 == GeomAbs_SurfaceOfRevolution) {
1212 Handle(Geom2d_BSplineCurve) H1;
1213 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1217 Standard_Real u1, v1, u2, v2, Tol;
1219 Tol = Precision::Confusion();
1220 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1221 ok = (dom1->Classify(gp_Pnt2d(u1, v1), Tol) != TopAbs_OUT);
1223 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1226 Handle(Geom2d_BSplineCurve) H1;
1227 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1230 }// for (i=1; i<=aNbParts; i++) {
1231 }// case IntPatch_Lin: case IntPatch_Parabola: case IntPatch_Hyperbola:
1234 //########################################
1235 // Circle and Ellipse
1236 //########################################
1237 case IntPatch_Circle:
1238 case IntPatch_Ellipse: {
1240 if (typl == IntPatch_Circle) {
1241 newc = new Geom_Circle
1242 (Handle(IntPatch_GLine)::DownCast(L)->Circle());
1244 else { //IntPatch_Ellipse
1245 newc = new Geom_Ellipse
1246 (Handle(IntPatch_GLine)::DownCast(L)->Ellipse());
1250 TolR3d (myFace1, myFace2, myTolReached3d);
1252 aNbParts=myLConstruct.NbParts();
1254 Standard_Real aPeriod, aNul;
1255 TColStd_SequenceOfReal aSeqFprm, aSeqLprm;
1260 for (i=1; i<=aNbParts; i++) {
1261 myLConstruct.Part(i, fprm, lprm);
1263 if (fprm < aNul && lprm > aNul) {
1264 // interval that goes through 0. is divided on two intervals;
1265 while (fprm<aNul || fprm>aPeriod) fprm=fprm+aPeriod;
1266 while (lprm<aNul || lprm>aPeriod) lprm=lprm+aPeriod;
1268 if((aPeriod - fprm) > Tolpc) {
1269 aSeqFprm.Append(fprm);
1270 aSeqLprm.Append(aPeriod);
1273 gp_Pnt P1 = newc->Value(fprm);
1274 gp_Pnt P2 = newc->Value(aPeriod);
1275 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1276 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1278 if(P1.Distance(P2) > aTolDist) {
1279 Standard_Real anewpar = fprm;
1281 if(ParameterOutOfBoundary(fprm, newc, myFace1, myFace2,
1282 lprm, Standard_False, anewpar, myContext)) {
1285 aSeqFprm.Append(fprm);
1286 aSeqLprm.Append(aPeriod);
1291 if((lprm - aNul) > Tolpc) {
1292 aSeqFprm.Append(aNul);
1293 aSeqLprm.Append(lprm);
1296 gp_Pnt P1 = newc->Value(aNul);
1297 gp_Pnt P2 = newc->Value(lprm);
1298 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1299 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1301 if(P1.Distance(P2) > aTolDist) {
1302 Standard_Real anewpar = lprm;
1304 if(ParameterOutOfBoundary(lprm, newc, myFace1, myFace2,
1305 fprm, Standard_True, anewpar, myContext)) {
1308 aSeqFprm.Append(aNul);
1309 aSeqLprm.Append(lprm);
1315 aSeqFprm.Append(fprm);
1316 aSeqLprm.Append(lprm);
1321 aNbParts=aSeqFprm.Length();
1322 for (i=1; i<=aNbParts; i++) {
1326 Standard_Real aRealEpsilon=RealEpsilon();
1327 if (Abs(fprm) > aRealEpsilon || Abs(lprm-2.*M_PI) > aRealEpsilon) {
1328 //==============================================
1330 IntTools_Curve aCurve;
1331 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1332 aCurve.SetCurve(aTC3D);
1333 fprm=aTC3D->FirstParameter();
1334 lprm=aTC3D->LastParameter ();
1336 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {////
1338 Handle (Geom2d_Curve) C2d;
1339 GeomInt_IntSS::BuildPCurves(fprm, lprm, Tolpc,
1340 myHS1->ChangeSurface().Surface(), newc, C2d);
1341 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1342 myTolReached2d=Tolpc;
1345 aCurve.SetFirstCurve2d(C2d);
1348 Handle(Geom2d_BSplineCurve) H1;
1349 aCurve.SetFirstCurve2d(H1);
1354 Handle (Geom2d_Curve) C2d;
1355 GeomInt_IntSS::BuildPCurves(fprm,lprm,Tolpc,
1356 myHS2->ChangeSurface().Surface(),newc,C2d);
1357 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1358 myTolReached2d=Tolpc;
1361 aCurve.SetSecondCurve2d(C2d);
1364 Handle(Geom2d_BSplineCurve) H1;
1365 aCurve.SetSecondCurve2d(H1);
1370 Handle(Geom2d_BSplineCurve) H1;
1371 aCurve.SetFirstCurve2d(H1);
1372 aCurve.SetSecondCurve2d(H1);
1374 mySeqOfCurve.Append(aCurve);
1375 //==============================================
1376 } //if (Abs(fprm) > RealEpsilon() || Abs(lprm-2.*M_PI) > RealEpsilon())
1379 // on regarde si on garde
1382 // if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*M_PI) < RealEpsilon()) {
1383 if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*M_PI) <= aRealEpsilon) {
1384 IntTools_Curve aCurve;
1385 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1386 aCurve.SetCurve(aTC3D);
1387 fprm=aTC3D->FirstParameter();
1388 lprm=aTC3D->LastParameter ();
1391 Handle (Geom2d_Curve) C2d;
1392 GeomInt_IntSS::BuildPCurves(fprm,lprm,Tolpc,
1393 myHS1->ChangeSurface().Surface(),newc,C2d);
1394 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1395 myTolReached2d=Tolpc;
1398 aCurve.SetFirstCurve2d(C2d);
1401 Handle(Geom2d_BSplineCurve) H1;
1402 aCurve.SetFirstCurve2d(H1);
1406 Handle (Geom2d_Curve) C2d;
1407 GeomInt_IntSS::BuildPCurves(fprm,lprm,Tolpc,
1408 myHS2->ChangeSurface().Surface(),newc,C2d);
1409 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1410 myTolReached2d=Tolpc;
1413 aCurve.SetSecondCurve2d(C2d);
1416 Handle(Geom2d_BSplineCurve) H1;
1417 aCurve.SetSecondCurve2d(H1);
1419 mySeqOfCurve.Append(aCurve);
1424 Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol;
1426 aTwoPIdiv17=2.*M_PI/17.;
1428 for (j=0; j<=17; j++) {
1429 gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
1430 Tol = Precision::Confusion();
1432 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1433 ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT);
1435 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1438 IntTools_Curve aCurve;
1439 aCurve.SetCurve(newc);
1440 //==============================================
1441 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {
1444 Handle (Geom2d_Curve) C2d;
1445 GeomInt_IntSS::BuildPCurves(fprm, lprm, Tolpc,
1446 myHS1->ChangeSurface().Surface(), newc, C2d);
1447 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1448 myTolReached2d=Tolpc;
1451 aCurve.SetFirstCurve2d(C2d);
1454 Handle(Geom2d_BSplineCurve) H1;
1455 aCurve.SetFirstCurve2d(H1);
1459 Handle (Geom2d_Curve) C2d;
1460 GeomInt_IntSS::BuildPCurves(fprm, lprm, Tolpc,
1461 myHS2->ChangeSurface().Surface(), newc, C2d);
1462 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1463 myTolReached2d=Tolpc;
1466 aCurve.SetSecondCurve2d(C2d);
1470 Handle(Geom2d_BSplineCurve) H1;
1471 aCurve.SetSecondCurve2d(H1);
1473 }// end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse)
1476 Handle(Geom2d_BSplineCurve) H1;
1478 aCurve.SetFirstCurve2d(H1);
1479 aCurve.SetSecondCurve2d(H1);
1481 //==============================================
1483 mySeqOfCurve.Append(aCurve);
1486 }// end of if (ok) {
1487 }// end of for (Standard_Integer j=0; j<=17; j++)
1488 }// end of else { on regarde si on garde
1489 }// for (i=1; i<=myLConstruct.NbParts(); i++)
1490 }// IntPatch_Circle: IntPatch_Ellipse:
1493 case IntPatch_Analytic: {
1494 IntSurf_Quadric quad1,quad2;
1495 GeomAbs_SurfaceType typs = myHS1->Surface().GetType();
1499 quad1.SetValue(myHS1->Surface().Plane());
1501 case GeomAbs_Cylinder:
1502 quad1.SetValue(myHS1->Surface().Cylinder());
1505 quad1.SetValue(myHS1->Surface().Cone());
1507 case GeomAbs_Sphere:
1508 quad1.SetValue(myHS1->Surface().Sphere());
1511 quad1.SetValue(myHS1->Surface().Torus());
1514 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 1");
1517 typs = myHS2->Surface().GetType();
1521 quad2.SetValue(myHS2->Surface().Plane());
1523 case GeomAbs_Cylinder:
1524 quad2.SetValue(myHS2->Surface().Cylinder());
1527 quad2.SetValue(myHS2->Surface().Cone());
1529 case GeomAbs_Sphere:
1530 quad2.SetValue(myHS2->Surface().Sphere());
1533 quad2.SetValue(myHS2->Surface().Torus());
1536 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 2");
1540 IntPatch_ALineToWLine convert (quad1, quad2);
1543 aNbParts=myLConstruct.NbParts();
1544 for (i=1; i<=aNbParts; i++) {
1545 myLConstruct.Part(i, fprm, lprm);
1546 Handle(IntPatch_WLine) WL =
1547 convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm);
1549 Handle(Geom2d_BSplineCurve) H1;
1550 Handle(Geom2d_BSplineCurve) H2;
1553 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1557 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1560 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1564 else { // myApprox=TRUE
1565 GeomInt_WLApprox theapp3d;
1567 Standard_Real tol2d = myTolApprox;
1569 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True);
1571 aNbParts=myLConstruct.NbParts();
1572 for (i=1; i<=aNbParts; i++) {
1573 myLConstruct.Part(i, fprm, lprm);
1574 Handle(IntPatch_WLine) WL =
1575 convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
1577 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
1579 if (!theapp3d.IsDone()) {
1581 Handle(Geom2d_BSplineCurve) H1;
1582 Handle(Geom2d_BSplineCurve) H2;
1585 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1589 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1592 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1596 if(myApprox1 || myApprox2) {
1597 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) {
1598 myTolReached2d = theapp3d.TolReached2d();
1602 if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) {
1603 myTolReached3d = theapp3d.TolReached3d();
1606 Standard_Integer aNbMultiCurves, nbpoles;
1607 aNbMultiCurves=theapp3d.NbMultiCurves();
1608 for (j=1; j<=aNbMultiCurves; j++) {
1609 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1610 nbpoles = mbspc.NbPoles();
1612 TColgp_Array1OfPnt tpoles(1, nbpoles);
1613 mbspc.Curve(1, tpoles);
1614 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1616 mbspc.Multiplicities(),
1619 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1620 Check.FixTangent(Standard_True,Standard_True);
1622 IntTools_Curve aCurve;
1623 aCurve.SetCurve(BS);
1626 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1627 mbspc.Curve(2,tpoles2d);
1628 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1630 mbspc.Multiplicities(),
1633 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1634 newCheck.FixTangent(Standard_True,Standard_True);
1636 aCurve.SetFirstCurve2d(BS2);
1639 Handle(Geom2d_BSplineCurve) H1;
1640 aCurve.SetFirstCurve2d(H1);
1644 TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
1645 Standard_Integer TwoOrThree;
1646 TwoOrThree=myApprox1 ? 3 : 2;
1647 mbspc.Curve(TwoOrThree, tpoles2d);
1648 Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
1650 mbspc.Multiplicities(),
1653 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1654 newCheck.FixTangent(Standard_True,Standard_True);
1656 aCurve.SetSecondCurve2d(BS2);
1659 Handle(Geom2d_BSplineCurve) H2;
1660 aCurve.SetSecondCurve2d(H2);
1663 mySeqOfCurve.Append(aCurve);
1665 }// for (j=1; j<=aNbMultiCurves; j++) {
1666 }// else from if (!theapp3d.IsDone())
1667 }// for (i=1; i<=aNbParts; i++) {
1668 }// else { // myApprox=TRUE
1669 }// case IntPatch_Analytic:
1672 case IntPatch_Walking:{
1673 Handle(IntPatch_WLine) WL =
1674 Handle(IntPatch_WLine)::DownCast(L);
1676 Standard_Integer ifprm, ilprm;
1680 if(!bAvoidLineConstructor){
1681 aNbParts=myLConstruct.NbParts();
1683 for (i=1; i<=aNbParts; ++i) {
1684 Handle(Geom2d_BSplineCurve) H1, H2;
1685 Handle(Geom_Curve) aBSp;
1687 if(bAvoidLineConstructor) {
1689 ilprm = WL->NbPnts();
1692 myLConstruct.Part(i, fprm, lprm);
1693 ifprm=(Standard_Integer)fprm;
1694 ilprm=(Standard_Integer)lprm;
1698 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1702 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1705 aBSp=MakeBSpline(WL, ifprm, ilprm);
1706 IntTools_Curve aIC(aBSp, H1, H2);
1707 mySeqOfCurve.Append(aIC);
1708 }// for (i=1; i<=aNbParts; ++i) {
1709 }// if (!myApprox) {
1712 Standard_Boolean bIsDecomposited;
1713 Standard_Integer nbiter, aNbSeqOfL;
1714 Standard_Real tol2d, aTolApproxImp;
1715 IntPatch_SequenceOfLine aSeqOfL;
1716 GeomInt_WLApprox theapp3d;
1717 Approx_ParametrizationType aParType = Approx_ChordLength;
1719 Standard_Boolean anApprox1 = myApprox1;
1720 Standard_Boolean anApprox2 = myApprox2;
1722 aTolApproxImp=1.e-5;
1723 tol2d = myTolApprox;
1725 GeomAbs_SurfaceType typs1, typs2;
1726 typs1 = myHS1->Surface().GetType();
1727 typs2 = myHS2->Surface().GetType();
1728 Standard_Boolean anWithPC = Standard_True;
1730 if(typs1 == GeomAbs_Cylinder && typs2 == GeomAbs_Sphere) {
1732 ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere());
1734 else if (typs1 == GeomAbs_Sphere && typs2 == GeomAbs_Cylinder) {
1736 ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere());
1740 myTolApprox = aTolApproxImp;//1.e-5;
1741 anApprox1 = Standard_False;
1742 anApprox2 = Standard_False;
1744 tol2d = myTolApprox;
1747 if(myHS1 == myHS2) {
1748 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1749 rejectSurface = Standard_True;
1752 if(reApprox && !rejectSurface)
1753 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1755 Standard_Integer iDegMax, iDegMin, iNbIter;
1757 ApproxParameters(myHS1, myHS2, iDegMin, iDegMax, iNbIter);
1758 theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, iNbIter, Standard_True, aParType);
1762 Standard_Real aReachedTol = Precision::Confusion();
1763 bIsDecomposited=DecompositionOfWLine(WL,
1769 bAvoidLineConstructor,
1773 if ( bIsDecomposited && ( myTolReached3d < aReachedTol ) ) {
1774 myTolReached3d = aReachedTol;
1777 aNbSeqOfL=aSeqOfL.Length();
1779 if (bIsDecomposited) {
1785 if (!bAvoidLineConstructor) {
1786 aNbParts=myLConstruct.NbParts();
1791 for(i = 1; i <= nbiter; ++i) {
1792 if(bIsDecomposited) {
1793 WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i));
1795 ilprm = WL->NbPnts();
1798 if(bAvoidLineConstructor) {
1800 ilprm = WL->NbPnts();
1803 myLConstruct.Part(i, fprm, lprm);
1804 ifprm = (Standard_Integer)fprm;
1805 ilprm = (Standard_Integer)lprm;
1809 //-- Si une des surfaces est un plan , on approxime en 2d
1810 //-- sur cette surface et on remonte les points 2d en 3d.
1811 if(typs1 == GeomAbs_Plane) {
1812 theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm);
1814 else if(typs2 == GeomAbs_Plane) {
1815 theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm);
1819 if (myHS1 != myHS2){
1820 if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) &&
1821 (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) {
1823 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType);
1825 Standard_Boolean bUseSurfaces;
1826 bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm, ilprm);
1829 rejectSurface = Standard_True;
1831 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1836 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm);
1839 if (!theapp3d.IsDone()) {
1840 Handle(Geom2d_BSplineCurve) H1;
1841 Handle(Geom2d_BSplineCurve) H2;
1843 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
1846 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1850 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1853 IntTools_Curve aIC(aBSp, H1, H2);
1854 mySeqOfCurve.Append(aIC);
1858 if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) {
1859 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) {
1860 myTolReached2d = theapp3d.TolReached2d();
1863 if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) {
1864 myTolReached3d = myTolReached2d;
1866 if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
1867 if (myTolReached3d<1.e-6) {
1868 myTolReached3d = theapp3d.TolReached3d();
1869 myTolReached3d=1.e-6;
1873 else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) {
1874 myTolReached3d = theapp3d.TolReached3d();
1877 Standard_Integer aNbMultiCurves, nbpoles;
1878 aNbMultiCurves=theapp3d.NbMultiCurves();
1879 for (j=1; j<=aNbMultiCurves; j++) {
1880 if(typs1 == GeomAbs_Plane) {
1881 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1882 nbpoles = mbspc.NbPoles();
1884 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1885 TColgp_Array1OfPnt tpoles(1,nbpoles);
1887 mbspc.Curve(1,tpoles2d);
1888 const gp_Pln& Pln = myHS1->Surface().Plane();
1890 Standard_Integer ik;
1891 for(ik = 1; ik<= nbpoles; ik++) {
1893 ElSLib::Value(tpoles2d.Value(ik).X(),
1894 tpoles2d.Value(ik).Y(),
1898 Handle(Geom_BSplineCurve) BS =
1899 new Geom_BSplineCurve(tpoles,
1901 mbspc.Multiplicities(),
1903 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1904 Check.FixTangent(Standard_True, Standard_True);
1906 IntTools_Curve aCurve;
1907 aCurve.SetCurve(BS);
1910 Handle(Geom2d_BSplineCurve) BS1 =
1911 new Geom2d_BSplineCurve(tpoles2d,
1913 mbspc.Multiplicities(),
1915 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
1916 Check1.FixTangent(Standard_True,Standard_True);
1918 // ############################################
1919 if(!rejectSurface && !reApprox) {
1920 Standard_Boolean isValid = IsCurveValid(BS1);
1922 reApprox = Standard_True;
1926 // ############################################
1927 aCurve.SetFirstCurve2d(BS1);
1930 Handle(Geom2d_BSplineCurve) H1;
1931 aCurve.SetFirstCurve2d(H1);
1935 mbspc.Curve(2, tpoles2d);
1937 Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
1939 mbspc.Multiplicities(),
1941 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1942 newCheck.FixTangent(Standard_True,Standard_True);
1944 // ###########################################
1945 if(!rejectSurface && !reApprox) {
1946 Standard_Boolean isValid = IsCurveValid(BS2);
1948 reApprox = Standard_True;
1952 // ###########################################
1954 aCurve.SetSecondCurve2d(BS2);
1957 Handle(Geom2d_BSplineCurve) H2;
1959 aCurve.SetSecondCurve2d(H2);
1962 mySeqOfCurve.Append(aCurve);
1963 }//if(typs1 == GeomAbs_Plane) {
1965 else if(typs2 == GeomAbs_Plane) {
1966 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1967 nbpoles = mbspc.NbPoles();
1969 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1970 TColgp_Array1OfPnt tpoles(1,nbpoles);
1971 mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d);
1972 const gp_Pln& Pln = myHS2->Surface().Plane();
1974 Standard_Integer ik;
1975 for(ik = 1; ik<= nbpoles; ik++) {
1977 ElSLib::Value(tpoles2d.Value(ik).X(),
1978 tpoles2d.Value(ik).Y(),
1983 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1985 mbspc.Multiplicities(),
1987 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1988 Check.FixTangent(Standard_True,Standard_True);
1990 IntTools_Curve aCurve;
1991 aCurve.SetCurve(BS);
1994 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
1996 mbspc.Multiplicities(),
1998 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
1999 Check1.FixTangent(Standard_True,Standard_True);
2001 // ###########################################
2002 if(!rejectSurface && !reApprox) {
2003 Standard_Boolean isValid = IsCurveValid(BS1);
2005 reApprox = Standard_True;
2009 // ###########################################
2010 bPCurvesOk = CheckPCurve(BS1, myFace2);
2011 aCurve.SetSecondCurve2d(BS1);
2014 Handle(Geom2d_BSplineCurve) H2;
2015 aCurve.SetSecondCurve2d(H2);
2019 mbspc.Curve(1,tpoles2d);
2020 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
2022 mbspc.Multiplicities(),
2024 GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK);
2025 Check2.FixTangent(Standard_True,Standard_True);
2027 // ###########################################
2028 if(!rejectSurface && !reApprox) {
2029 Standard_Boolean isValid = IsCurveValid(BS2);
2031 reApprox = Standard_True;
2035 // ###########################################
2036 bPCurvesOk = bPCurvesOk && CheckPCurve(BS2, myFace1);
2037 aCurve.SetFirstCurve2d(BS2);
2040 Handle(Geom2d_BSplineCurve) H1;
2042 aCurve.SetFirstCurve2d(H1);
2045 //if points of the pcurves are out of the faces bounds
2046 //create 3d and 2d curves without approximation
2048 Handle(Geom2d_BSplineCurve) H1, H2;
2049 bPCurvesOk = Standard_True;
2051 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
2054 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
2055 bPCurvesOk = CheckPCurve(H1, myFace1);
2059 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
2060 bPCurvesOk = bPCurvesOk && CheckPCurve(H2, myFace2);
2063 //if pcurves created without approximation are out of the
2064 //faces bounds, use approximated 3d and 2d curves
2066 IntTools_Curve aIC(aBSp, H1, H2);
2067 mySeqOfCurve.Append(aIC);
2069 mySeqOfCurve.Append(aCurve);
2072 mySeqOfCurve.Append(aCurve);
2074 }// else if(typs2 == GeomAbs_Plane)
2076 else { //typs2 != GeomAbs_Plane && typs1 != GeomAbs_Plane
2077 Standard_Boolean bIsValid1, bIsValid2;
2078 Handle(Geom_BSplineCurve) BS;
2079 Handle(Geom2d_BSplineCurve) aH2D;
2080 IntTools_Curve aCurve;
2082 bIsValid1=Standard_True;
2083 bIsValid2=Standard_True;
2085 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2086 nbpoles = mbspc.NbPoles();
2087 TColgp_Array1OfPnt tpoles(1,nbpoles);
2088 mbspc.Curve(1,tpoles);
2089 BS=new Geom_BSplineCurve(tpoles,
2091 mbspc.Multiplicities(),
2093 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2094 Check.FixTangent(Standard_True,Standard_True);
2096 aCurve.SetCurve(BS);
2097 aCurve.SetFirstCurve2d(aH2D);
2098 aCurve.SetSecondCurve2d(aH2D);
2102 Handle(Geom2d_BSplineCurve) BS1;
2103 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2104 mbspc.Curve(2,tpoles2d);
2106 BS1=new Geom2d_BSplineCurve(tpoles2d,
2108 mbspc.Multiplicities(),
2110 GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK);
2111 newCheck.FixTangent(Standard_True,Standard_True);
2114 bIsValid1=CheckPCurve(BS1, myFace1);
2117 aCurve.SetFirstCurve2d(BS1);
2120 Handle(Geom2d_BSplineCurve) BS1;
2121 fprm = BS->FirstParameter();
2122 lprm = BS->LastParameter();
2124 Handle(Geom2d_Curve) C2d;
2125 Standard_Real aTol = myTolApprox;
2126 GeomInt_IntSS::BuildPCurves(fprm, lprm, aTol,
2127 myHS1->ChangeSurface().Surface(), BS, C2d);
2128 BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2129 aCurve.SetFirstCurve2d(BS1);
2131 } // if(myApprox1) {
2135 Handle(Geom2d_BSplineCurve) BS2;
2136 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2137 mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d);
2138 BS2=new Geom2d_BSplineCurve(tpoles2d,
2140 mbspc.Multiplicities(),
2142 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2143 newCheck.FixTangent(Standard_True,Standard_True);
2146 bIsValid2=CheckPCurve(BS2, myFace2);
2148 aCurve.SetSecondCurve2d(BS2);
2151 Handle(Geom2d_BSplineCurve) BS2;
2152 fprm = BS->FirstParameter();
2153 lprm = BS->LastParameter();
2155 Handle(Geom2d_Curve) C2d;
2156 Standard_Real aTol = myTolApprox;
2157 GeomInt_IntSS::BuildPCurves(fprm, lprm, aTol,
2158 myHS2->ChangeSurface().Surface(), BS, C2d);
2159 BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2160 aCurve.SetSecondCurve2d(BS2);
2163 if (!bIsValid1 || !bIsValid2) {
2164 myTolApprox=aTolApproxImp;//1.e-5;
2165 tol2d = myTolApprox;
2166 reApprox = Standard_True;
2170 mySeqOfCurve.Append(aCurve);
2176 }// case IntPatch_Walking:{
2179 case IntPatch_Restriction:
2181 Handle(IntPatch_RLine) RL =
2182 Handle(IntPatch_RLine)::DownCast(L);
2183 Handle(Geom_Curve) aC3d;
2184 Handle(Geom2d_Curve) aC2d1, aC2d2;
2185 Standard_Real aTolReached;
2186 GeomInt_IntSS::TreatRLine(RL, myHS1, myHS2, aC3d,
2187 aC2d1, aC2d2, aTolReached);
2192 Bnd_Box2d aBox1, aBox2;
2194 const Standard_Real aU1f = myHS1->FirstUParameter(),
2195 aV1f = myHS1->FirstVParameter(),
2196 aU1l = myHS1->LastUParameter(),
2197 aV1l = myHS1->LastVParameter();
2198 const Standard_Real aU2f = myHS2->FirstUParameter(),
2199 aV2f = myHS2->FirstVParameter(),
2200 aU2l = myHS2->LastUParameter(),
2201 aV2l = myHS2->LastVParameter();
2203 aBox1.Add(gp_Pnt2d(aU1f, aV1f));
2204 aBox1.Add(gp_Pnt2d(aU1l, aV1l));
2205 aBox2.Add(gp_Pnt2d(aU2f, aV2f));
2206 aBox2.Add(gp_Pnt2d(aU2l, aV2l));
2208 GeomInt_VectorOfReal anArrayOfParameters;
2210 //We consider here that the intersection line is same-parameter-line
2211 anArrayOfParameters.Append(aC3d->FirstParameter());
2212 anArrayOfParameters.Append(aC3d->LastParameter());
2215 TrimILineOnSurfBoundaries(aC2d1, aC2d2, aBox1, aBox2, anArrayOfParameters);
2217 const Standard_Integer aNbIntersSolutionsm1 = anArrayOfParameters.Length() - 1;
2220 for(Standard_Integer anInd = 0; anInd < aNbIntersSolutionsm1; anInd++)
2222 const Standard_Real aParF = anArrayOfParameters(anInd),
2223 aParL = anArrayOfParameters(anInd+1);
2225 if((aParL - aParF) <= Precision::PConfusion())
2228 const Standard_Real aPar = 0.5*(aParF + aParL);
2231 Handle(Geom2d_Curve) aCurv2d1, aCurv2d2;
2234 aC2d1->D0(aPar, aPt);
2236 if(aBox1.IsOut(aPt))
2240 aCurv2d1 = new Geom2d_TrimmedCurve(aC2d1, aParF, aParL);
2245 aC2d2->D0(aPar, aPt);
2247 if(aBox2.IsOut(aPt))
2251 aCurv2d2 = new Geom2d_TrimmedCurve(aC2d2, aParF, aParL);
2254 Handle(Geom_Curve) aCurv3d = new Geom_TrimmedCurve(aC3d, aParF, aParL);
2256 IntTools_Curve aIC(aCurv3d, aCurv2d1, aCurv2d2);
2257 mySeqOfCurve.Append(aIC);
2267 //=======================================================================
2268 //function : Parameters
2270 //=======================================================================
2271 void Parameters(const Handle(GeomAdaptor_HSurface)& HS1,
2272 const Handle(GeomAdaptor_HSurface)& HS2,
2273 const gp_Pnt& Ptref,
2280 IntSurf_Quadric quad1,quad2;
2281 GeomAbs_SurfaceType typs = HS1->Surface().GetType();
2285 quad1.SetValue(HS1->Surface().Plane());
2287 case GeomAbs_Cylinder:
2288 quad1.SetValue(HS1->Surface().Cylinder());
2291 quad1.SetValue(HS1->Surface().Cone());
2293 case GeomAbs_Sphere:
2294 quad1.SetValue(HS1->Surface().Sphere());
2297 quad1.SetValue(HS1->Surface().Torus());
2300 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2303 typs = HS2->Surface().GetType();
2306 quad2.SetValue(HS2->Surface().Plane());
2308 case GeomAbs_Cylinder:
2309 quad2.SetValue(HS2->Surface().Cylinder());
2312 quad2.SetValue(HS2->Surface().Cone());
2314 case GeomAbs_Sphere:
2315 quad2.SetValue(HS2->Surface().Sphere());
2318 quad2.SetValue(HS2->Surface().Torus());
2321 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2324 quad1.Parameters(Ptref,U1,V1);
2325 quad2.Parameters(Ptref,U2,V2);
2328 //=======================================================================
2329 //function : MakeBSpline
2331 //=======================================================================
2332 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL,
2333 const Standard_Integer ideb,
2334 const Standard_Integer ifin)
2336 Standard_Integer i,nbpnt = ifin-ideb+1;
2337 TColgp_Array1OfPnt poles(1,nbpnt);
2338 TColStd_Array1OfReal knots(1,nbpnt);
2339 TColStd_Array1OfInteger mults(1,nbpnt);
2340 Standard_Integer ipidebm1;
2341 for(i=1,ipidebm1=i+ideb-1; i<=nbpnt;ipidebm1++, i++) {
2342 poles(i) = WL->Point(ipidebm1).Value();
2346 mults(1) = mults(nbpnt) = 2;
2348 new Geom_BSplineCurve(poles,knots,mults,1);
2352 //=======================================================================
2353 //function : MakeBSpline2d
2355 //=======================================================================
2356 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
2357 const Standard_Integer ideb,
2358 const Standard_Integer ifin,
2359 const Standard_Boolean onFirst)
2361 Standard_Integer i, nbpnt = ifin-ideb+1;
2362 TColgp_Array1OfPnt2d poles(1,nbpnt);
2363 TColStd_Array1OfReal knots(1,nbpnt);
2364 TColStd_Array1OfInteger mults(1,nbpnt);
2365 Standard_Integer ipidebm1;
2367 for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) {
2370 theWLine->Point(ipidebm1).ParametersOnS1(U, V);
2372 theWLine->Point(ipidebm1).ParametersOnS2(U, V);
2373 poles(i).SetCoord(U, V);
2377 mults(1) = mults(nbpnt) = 2;
2379 return new Geom2d_BSplineCurve(poles,knots,mults,1);
2381 //=======================================================================
2382 //function : PrepareLines3D
2384 //=======================================================================
2385 void IntTools_FaceFace::PrepareLines3D(const Standard_Boolean bToSplit)
2387 Standard_Integer i, aNbCurves;
2388 GeomAbs_SurfaceType aType1, aType2;
2389 IntTools_SequenceOfCurves aNewCvs;
2391 // 1. Treatment closed curves
2392 aNbCurves=mySeqOfCurve.Length();
2393 for (i=1; i<=aNbCurves; ++i) {
2394 const IntTools_Curve& aIC=mySeqOfCurve(i);
2397 Standard_Integer j, aNbC;
2398 IntTools_SequenceOfCurves aSeqCvs;
2400 aNbC=IntTools_Tools::SplitCurve(aIC, aSeqCvs);
2402 for (j=1; j<=aNbC; ++j) {
2403 const IntTools_Curve& aICNew=aSeqCvs(j);
2404 aNewCvs.Append(aICNew);
2408 aNewCvs.Append(aIC);
2412 aNewCvs.Append(aIC);
2416 // 2. Plane\Cone intersection when we had 4 curves
2417 aType1=myHS1->GetType();
2418 aType2=myHS2->GetType();
2419 aNbCurves=aNewCvs.Length();
2421 if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone) ||
2422 (aType2==GeomAbs_Plane && aType1==GeomAbs_Cone)) {
2424 GeomAbs_CurveType aCType1;
2426 aCType1=aNewCvs(1).Type();
2427 if (aCType1==GeomAbs_Line) {
2428 IntTools_SequenceOfCurves aSeqIn, aSeqOut;
2430 for (i=1; i<=aNbCurves; ++i) {
2431 const IntTools_Curve& aIC=aNewCvs(i);
2435 IntTools_Tools::RejectLines(aSeqIn, aSeqOut);
2438 aNbCurves=aSeqOut.Length();
2439 for (i=1; i<=aNbCurves; ++i) {
2440 const IntTools_Curve& aIC=aSeqOut(i);
2441 aNewCvs.Append(aIC);
2445 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone)...
2447 // 3. Fill mySeqOfCurve
2448 mySeqOfCurve.Clear();
2449 aNbCurves=aNewCvs.Length();
2450 for (i=1; i<=aNbCurves; ++i) {
2451 const IntTools_Curve& aIC=aNewCvs(i);
2452 mySeqOfCurve.Append(aIC);
2455 //=======================================================================
2456 //function : CorrectSurfaceBoundaries
2458 //=======================================================================
2459 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
2460 const Standard_Real theTolerance,
2461 Standard_Real& theumin,
2462 Standard_Real& theumax,
2463 Standard_Real& thevmin,
2464 Standard_Real& thevmax)
2466 Standard_Boolean enlarge, isuperiodic, isvperiodic;
2467 Standard_Real uinf, usup, vinf, vsup, delta;
2468 GeomAbs_SurfaceType aType;
2469 Handle(Geom_Surface) aSurface;
2471 aSurface = BRep_Tool::Surface(theFace);
2472 aSurface->Bounds(uinf, usup, vinf, vsup);
2473 delta = theTolerance;
2474 enlarge = Standard_False;
2476 GeomAdaptor_Surface anAdaptorSurface(aSurface);
2478 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
2479 Handle(Geom_Surface) aBasisSurface =
2480 (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface))->BasisSurface();
2482 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2483 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2488 if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2489 Handle(Geom_Surface) aBasisSurface =
2490 (Handle(Geom_OffsetSurface)::DownCast(aSurface))->BasisSurface();
2492 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2493 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2498 isuperiodic = anAdaptorSurface.IsUPeriodic();
2499 isvperiodic = anAdaptorSurface.IsVPeriodic();
2501 aType=anAdaptorSurface.GetType();
2502 if((aType==GeomAbs_BezierSurface) ||
2503 (aType==GeomAbs_BSplineSurface) ||
2504 (aType==GeomAbs_SurfaceOfExtrusion) ||
2505 (aType==GeomAbs_SurfaceOfRevolution) ||
2506 (aType==GeomAbs_Cylinder)) {
2507 enlarge=Standard_True;
2510 if(!isuperiodic && enlarge) {
2512 if(!Precision::IsInfinite(theumin) &&
2513 ((theumin - uinf) > delta))
2519 if(!Precision::IsInfinite(theumax) &&
2520 ((usup - theumax) > delta))
2526 if(!isvperiodic && enlarge) {
2527 if(!Precision::IsInfinite(thevmin) &&
2528 ((thevmin - vinf) > delta)) {
2534 if(!Precision::IsInfinite(thevmax) &&
2535 ((vsup - thevmax) > delta)) {
2544 Standard_Integer aNbP;
2545 Standard_Real aXP, dXfact, aXmid, aX1, aX2, aTolPA;
2547 aTolPA=Precision::Angular();
2550 aXP=anAdaptorSurface.UPeriod();
2551 dXfact=theumax-theumin;
2552 if (dXfact-aTolPA>aXP) {
2553 aXmid=0.5*(theumax+theumin);
2554 aNbP=RealToInt(aXmid/aXP);
2559 if (theumin>aTolPA) {
2560 aX1=theumin+aNbP*aXP;
2573 aXP=anAdaptorSurface.VPeriod();
2574 dXfact=thevmax-thevmin;
2575 if (dXfact-aTolPA>aXP) {
2576 aXmid=0.5*(thevmax+thevmin);
2577 aNbP=RealToInt(aXmid/aXP);
2582 if (thevmin>aTolPA) {
2583 aX1=thevmin+aNbP*aXP;
2596 if(isuperiodic || isvperiodic) {
2597 Standard_Boolean correct = Standard_False;
2598 Standard_Boolean correctU = Standard_False;
2599 Standard_Boolean correctV = Standard_False;
2601 TopExp_Explorer anExp;
2603 for(anExp.Init(theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
2604 if(BRep_Tool::IsClosed(TopoDS::Edge(anExp.Current()), theFace)) {
2605 correct = Standard_True;
2607 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
2609 for(Standard_Integer i = 0; i < 2; i++) {
2611 anEdge.Orientation(TopAbs_FORWARD);
2614 anEdge.Orientation(TopAbs_REVERSED);
2616 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l);
2618 if(aCurve.IsNull()) {
2619 correct = Standard_False;
2622 Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve);
2624 if(aLine.IsNull()) {
2625 correct = Standard_False;
2628 gp_Dir2d anUDir(1., 0.);
2629 gp_Dir2d aVDir(0., 1.);
2630 Standard_Real anAngularTolerance = Precision::Angular();
2632 correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance);
2633 correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance);
2635 gp_Pnt2d pp1 = aCurve->Value(f);
2637 gp_Pnt2d pp2 = aCurve->Value(l);
2646 Standard_Real umin, vmin, umax, vmax;
2647 aBox.Get(umin, vmin, umax, vmax);
2649 if(isuperiodic && correctU) {
2654 if(theumax > umax) {
2658 if(isvperiodic && correctV) {
2670 // The block is dedicated to determine whether WLine [ifprm, ilprm]
2671 // crosses the degenerated zone on each given surface or not.
2672 // If Yes -> We will not use info about surfaces during approximation
2673 // because inside degenerated zone of the surface the approx. algo.
2674 // uses wrong values of normal, etc., and resulting curve will have
2675 // oscillations that we would not like to have.
2680 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2681 const Handle(Geom_Surface)& aS,
2682 const Standard_Integer iDir);
2684 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2685 const TopoDS_Face& aF1,
2686 const TopoDS_Face& aF2);
2687 //=======================================================================
2688 //function : NotUseSurfacesForApprox
2690 //=======================================================================
2691 Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1,
2692 const TopoDS_Face& aF2,
2693 const Handle(IntPatch_WLine)& WL,
2694 const Standard_Integer ifprm,
2695 const Standard_Integer ilprm)
2697 Standard_Boolean bPInDZ;
2699 Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve();
2701 const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm);
2702 bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2);
2707 const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm);
2708 bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2);
2712 //=======================================================================
2713 //function : IsPointInDegeneratedZone
2715 //=======================================================================
2716 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2717 const TopoDS_Face& aF1,
2718 const TopoDS_Face& aF2)
2721 Standard_Boolean bFlag=Standard_True;
2722 Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22;
2723 Standard_Real U1, V1, U2, V2, aDelta, aD;
2726 Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1);
2727 aS1->Bounds(US11, US12, VS11, VS12);
2728 GeomAdaptor_Surface aGAS1(aS1);
2730 Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2);
2731 aS1->Bounds(US21, US22, VS21, VS22);
2732 GeomAdaptor_Surface aGAS2(aS2);
2734 //const gp_Pnt& aP=aP2S.Value();
2735 aP2S.Parameters(U1, V1, U2, V2);
2739 aD=aGAS1.UResolution(aDelta);
2740 aP2d.SetCoord(U1, V1);
2741 if (fabs(U1-US11) < aD) {
2742 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2747 if (fabs(U1-US12) < aD) {
2748 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2753 aD=aGAS1.VResolution(aDelta);
2754 if (fabs(V1-VS11) < aDelta) {
2755 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2760 if (fabs(V1-VS12) < aDelta) {
2761 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2767 aD=aGAS2.UResolution(aDelta);
2768 aP2d.SetCoord(U2, V2);
2769 if (fabs(U2-US21) < aDelta) {
2770 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2775 if (fabs(U2-US22) < aDelta) {
2776 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2781 aD=aGAS2.VResolution(aDelta);
2782 if (fabs(V2-VS21) < aDelta) {
2783 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2788 if (fabs(V2-VS22) < aDelta) {
2789 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2797 //=======================================================================
2798 //function : IsDegeneratedZone
2800 //=======================================================================
2801 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2802 const Handle(Geom_Surface)& aS,
2803 const Standard_Integer iDir)
2805 Standard_Boolean bFlag=Standard_True;
2806 Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD;
2807 Standard_Real aXm, aYm, aXb, aYb, aXe, aYe;
2808 aS->Bounds(US1, US2, VS1, VS2);
2810 gp_Pnt aPm, aPb, aPe;
2815 aS->D0(aXm, aYm, aPm);
2832 aS->D0(aXb, aYb, aPb);
2833 aS->D0(aXe, aYe, aPe);
2835 d1=aPm.Distance(aPb);
2836 d2=aPm.Distance(aPe);
2837 if (d1 < dD && d2 < dD) {
2854 aS->D0(aXb, aYb, aPb);
2855 aS->D0(aXe, aYe, aPe);
2857 d1=aPm.Distance(aPb);
2858 d2=aPm.Distance(aPe);
2859 if (d1 < dD && d2 < dD) {
2867 //=========================================================================
2868 // static function : ComputePurgedWLine
2869 // purpose : Removes equal points (leave one of equal points) from theWLine
2870 // and recompute vertex parameters.
2871 // Returns new WLine or null WLine if the number
2872 // of the points is less than 2.
2873 //=========================================================================
2874 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine) {
2876 Standard_Integer i, k, v, nb, nbvtx;
2877 Handle(IntPatch_WLine) aResult;
2878 nbvtx = theWLine->NbVertex();
2879 nb = theWLine->NbPnts();
2881 const IntSurf_PntOn2S& p1 = theWLine->Point(1);
2882 const IntSurf_PntOn2S& p2 = theWLine->Point(2);
2883 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
2888 Handle(IntPatch_WLine) aLocalWLine;
2889 Handle(IntPatch_WLine) aTmpWLine = theWLine;
2890 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
2891 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2892 for(i = 1; i <= nb; i++) {
2893 aLineOn2S->Add(theWLine->Point(i));
2896 for(v = 1; v <= nbvtx; v++) {
2897 aLocalWLine->AddVertex(theWLine->Vertex(v));
2900 for(i = 1; i <= aLineOn2S->NbPoints(); i++) {
2901 Standard_Integer aStartIndex = i + 1;
2902 Standard_Integer anEndIndex = i + 5;
2903 nb = aLineOn2S->NbPoints();
2904 anEndIndex = (anEndIndex > nb) ? nb : anEndIndex;
2906 if((aStartIndex > nb) || (anEndIndex <= 1)) {
2911 while(k <= anEndIndex) {
2914 IntSurf_PntOn2S p1 = aLineOn2S->Value(i);
2915 IntSurf_PntOn2S p2 = aLineOn2S->Value(k);
2917 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
2918 aTmpWLine = aLocalWLine;
2919 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2921 for(v = 1; v <= aTmpWLine->NbVertex(); v++) {
2922 IntPatch_Point aVertex = aTmpWLine->Vertex(v);
2923 Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine();
2925 if(avertexindex >= k) {
2926 aVertex.SetParameter(aVertex.ParameterOnLine() - 1.);
2928 aLocalWLine->AddVertex(aVertex);
2930 aLineOn2S->RemovePoint(k);
2939 if(aLineOn2S->NbPoints() > 1) {
2940 aResult = aLocalWLine;
2945 //=======================================================================
2948 //=======================================================================
2949 void TolR3d(const TopoDS_Face& aF1,
2950 const TopoDS_Face& aF2,
2951 Standard_Real& myTolReached3d)
2953 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
2955 aTolTresh=2.999999e-3;
2956 aTolF1 = BRep_Tool::Tolerance(aF1);
2957 aTolF2 = BRep_Tool::Tolerance(aF2);
2958 aTolFMax=Max(aTolF1, aTolF2);
2960 if (aTolFMax>aTolTresh) {
2961 myTolReached3d=aTolFMax;
2964 //=======================================================================
2965 //function : IsPointOnBoundary
2967 //=======================================================================
2968 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
2969 const Standard_Real theFirstBoundary,
2970 const Standard_Real theSecondBoundary,
2971 const Standard_Real theResolution,
2972 Standard_Boolean& IsOnFirstBoundary)
2974 Standard_Boolean bRet;
2976 Standard_Real adist;
2978 bRet=Standard_False;
2979 for(i = 0; i < 2; ++i) {
2980 IsOnFirstBoundary = (i == 0);
2981 if (IsOnFirstBoundary) {
2982 adist = fabs(theParameter - theFirstBoundary);
2985 adist = fabs(theParameter - theSecondBoundary);
2987 if(adist < theResolution) {
2993 // ------------------------------------------------------------------------------------------------
2994 // static function: FindPoint
2996 // ------------------------------------------------------------------------------------------------
2997 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
2998 const gp_Pnt2d& theLastPoint,
2999 const Standard_Real theUmin,
3000 const Standard_Real theUmax,
3001 const Standard_Real theVmin,
3002 const Standard_Real theVmax,
3003 gp_Pnt2d& theNewPoint) {
3005 gp_Vec2d aVec(theFirstPoint, theLastPoint);
3006 Standard_Integer i = 0, j = 0;
3008 for(i = 0; i < 4; i++) {
3009 gp_Vec2d anOtherVec;
3010 gp_Vec2d anOtherVecNormal;
3011 gp_Pnt2d aprojpoint = theLastPoint;
3014 anOtherVec.SetX(0.);
3015 anOtherVec.SetY(1.);
3016 anOtherVecNormal.SetX(1.);
3017 anOtherVecNormal.SetY(0.);
3020 aprojpoint.SetX(theUmin);
3022 aprojpoint.SetX(theUmax);
3025 anOtherVec.SetX(1.);
3026 anOtherVec.SetY(0.);
3027 anOtherVecNormal.SetX(0.);
3028 anOtherVecNormal.SetY(1.);
3031 aprojpoint.SetY(theVmin);
3033 aprojpoint.SetY(theVmax);
3035 gp_Vec2d anormvec = aVec;
3036 anormvec.Normalize();
3037 RefineVector(anormvec);
3038 Standard_Real adot1 = anormvec.Dot(anOtherVecNormal);
3040 if(fabs(adot1) < Precision::Angular())
3042 Standard_Real adist = 0.;
3043 Standard_Boolean bIsOut = Standard_False;
3046 adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax);
3047 bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax);
3050 adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax);
3051 bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax);
3053 Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1;
3055 for(j = 0; j < 2; j++) {
3056 anoffset = (j == 0) ? anoffset : -anoffset;
3057 gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset));
3058 gp_Vec2d acurvec(theLastPoint, acurpoint);
3062 Standard_Real aDotX, anAngleX;
3064 aDotX = aVec.Dot(acurvec);
3065 anAngleX = aVec.Angle(acurvec);
3067 if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) {
3069 if((acurpoint.Y() >= theVmin) &&
3070 (acurpoint.Y() <= theVmax)) {
3071 theNewPoint = acurpoint;
3072 return Standard_True;
3076 if((acurpoint.X() >= theUmin) &&
3077 (acurpoint.X() <= theUmax)) {
3078 theNewPoint = acurpoint;
3079 return Standard_True;
3085 return Standard_False;
3089 // ------------------------------------------------------------------------------------------------
3090 // static function: FindPoint
3091 // purpose: Find point on the boundary of radial tangent zone
3092 // ------------------------------------------------------------------------------------------------
3093 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3094 const gp_Pnt2d& theLastPoint,
3095 const Standard_Real theUmin,
3096 const Standard_Real theUmax,
3097 const Standard_Real theVmin,
3098 const Standard_Real theVmax,
3099 const gp_Pnt2d& theTanZoneCenter,
3100 const Standard_Real theZoneRadius,
3101 Handle(GeomAdaptor_HSurface) theGASurface,
3102 gp_Pnt2d& theNewPoint) {
3103 theNewPoint = theLastPoint;
3105 if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) )
3106 return Standard_False;
3108 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3109 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3111 Standard_Real aRadius = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3112 gp_Ax22d anAxis( theTanZoneCenter, gp_Dir2d(1, 0), gp_Dir2d(0, 1) );
3113 gp_Circ2d aCircle( anAxis, aRadius );
3116 gp_Vec2d aDir( theLastPoint.XY() - theFirstPoint.XY() );
3117 Standard_Real aLength = aDir.Magnitude();
3118 if ( aLength <= gp::Resolution() )
3119 return Standard_False;
3120 gp_Lin2d aLine( theFirstPoint, aDir );
3123 Handle(Geom2d_Line) aCLine = new Geom2d_Line( aLine );
3124 Handle(Geom2d_TrimmedCurve) aC1 = new Geom2d_TrimmedCurve( aCLine, 0, aLength );
3125 Handle(Geom2d_Circle) aC2 = new Geom2d_Circle( aCircle );
3127 Standard_Real aTol = aRadius * 0.001;
3128 aTol = ( aTol < Precision::PConfusion() ) ? Precision::PConfusion() : aTol;
3130 Geom2dAPI_InterCurveCurve anIntersector;
3131 anIntersector.Init( aC1, aC2, aTol );
3133 if ( anIntersector.NbPoints() == 0 )
3134 return Standard_False;
3136 Standard_Boolean aFound = Standard_False;
3137 Standard_Real aMinDist = aLength * aLength;
3138 Standard_Integer i = 0;
3139 for ( i = 1; i <= anIntersector.NbPoints(); i++ ) {
3140 gp_Pnt2d aPInt = anIntersector.Point( i );
3141 if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) {
3142 if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) &&
3143 ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) {
3144 theNewPoint = aPInt;
3145 aFound = Standard_True;
3153 // ------------------------------------------------------------------------------------------------
3154 // static function: IsInsideTanZone
3155 // purpose: Check if point is inside a radial tangent zone
3156 // ------------------------------------------------------------------------------------------------
3157 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
3158 const gp_Pnt2d& theTanZoneCenter,
3159 const Standard_Real theZoneRadius,
3160 Handle(GeomAdaptor_HSurface) theGASurface) {
3162 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3163 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3164 Standard_Real aRadiusSQR = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3165 aRadiusSQR *= aRadiusSQR;
3166 if ( thePoint.SquareDistance( theTanZoneCenter ) <= aRadiusSQR )
3167 return Standard_True;
3168 return Standard_False;
3171 // ------------------------------------------------------------------------------------------------
3172 // static function: CheckTangentZonesExist
3173 // purpose: Check if tangent zone exists
3174 // ------------------------------------------------------------------------------------------------
3175 Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& theSurface1,
3176 const Handle(GeomAdaptor_HSurface)& theSurface2 )
3178 if ( ( theSurface1->GetType() != GeomAbs_Torus ) ||
3179 ( theSurface2->GetType() != GeomAbs_Torus ) )
3180 return Standard_False;
3182 gp_Torus aTor1 = theSurface1->Torus();
3183 gp_Torus aTor2 = theSurface2->Torus();
3185 if ( aTor1.Location().Distance( aTor2.Location() ) > Precision::Confusion() )
3186 return Standard_False;
3188 if ( ( fabs( aTor1.MajorRadius() - aTor2.MajorRadius() ) > Precision::Confusion() ) ||
3189 ( fabs( aTor1.MinorRadius() - aTor2.MinorRadius() ) > Precision::Confusion() ) )
3190 return Standard_False;
3192 if ( ( aTor1.MajorRadius() < aTor1.MinorRadius() ) ||
3193 ( aTor2.MajorRadius() < aTor2.MinorRadius() ) )
3194 return Standard_False;
3195 return Standard_True;
3198 // ------------------------------------------------------------------------------------------------
3199 // static function: ComputeTangentZones
3201 // ------------------------------------------------------------------------------------------------
3202 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
3203 const Handle(GeomAdaptor_HSurface)& theSurface2,
3204 const TopoDS_Face& theFace1,
3205 const TopoDS_Face& theFace2,
3206 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
3207 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
3208 Handle(TColStd_HArray1OfReal)& theResultRadius,
3209 const Handle(IntTools_Context)& aContext)
3211 Standard_Integer aResult = 0;
3212 if ( !CheckTangentZonesExist( theSurface1, theSurface2 ) )
3216 TColgp_SequenceOfPnt2d aSeqResultS1, aSeqResultS2;
3217 TColStd_SequenceOfReal aSeqResultRad;
3219 gp_Torus aTor1 = theSurface1->Torus();
3220 gp_Torus aTor2 = theSurface2->Torus();
3222 gp_Ax2 anax1( aTor1.Location(), aTor1.Axis().Direction() );
3223 gp_Ax2 anax2( aTor2.Location(), aTor2.Axis().Direction() );
3224 Standard_Integer j = 0;
3226 for ( j = 0; j < 2; j++ ) {
3227 Standard_Real aCoef = ( j == 0 ) ? -1 : 1;
3228 Standard_Real aRadius1 = fabs(aTor1.MajorRadius() + aCoef * aTor1.MinorRadius());
3229 Standard_Real aRadius2 = fabs(aTor2.MajorRadius() + aCoef * aTor2.MinorRadius());
3231 gp_Circ aCircle1( anax1, aRadius1 );
3232 gp_Circ aCircle2( anax2, aRadius2 );
3234 // roughly compute radius of tangent zone for perpendicular case
3235 Standard_Real aCriteria = Precision::Confusion() * 0.5;
3237 Standard_Real aT1 = aCriteria;
3238 Standard_Real aT2 = aCriteria;
3240 // internal tangency
3241 Standard_Real aR = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3242 //aT1 = aCriteria * aCriteria + aR * aR - ( aR - aCriteria ) * ( aR - aCriteria );
3243 aT1 = 2. * aR * aCriteria;
3247 // external tangency
3248 Standard_Real aRb = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3249 Standard_Real aRm = ( aRadius1 < aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3250 Standard_Real aDelta = aRb - aCriteria;
3252 aDelta -= aRm * aRm;
3253 aDelta /= 2. * (aRb - aRm);
3254 aDelta -= 0.5 * (aRb - aRm);
3256 aT1 = 2. * aRm * (aRm - aDelta);
3259 aCriteria = ( aT1 > aT2) ? aT1 : aT2;
3260 if ( aCriteria > 0 )
3261 aCriteria = sqrt( aCriteria );
3263 if ( aCriteria > 0.5 * aTor1.MinorRadius() ) {
3264 // too big zone -> drop to minimum
3265 aCriteria = Precision::Confusion();
3268 GeomAdaptor_Curve aC1( new Geom_Circle(aCircle1) );
3269 GeomAdaptor_Curve aC2( new Geom_Circle(aCircle2) );
3270 Extrema_ExtCC anExtrema(aC1, aC2, 0, 2. * M_PI, 0, 2. * M_PI,
3271 Precision::PConfusion(), Precision::PConfusion());
3273 if ( anExtrema.IsDone() ) {
3275 Standard_Integer i = 0;
3276 for ( i = 1; i <= anExtrema.NbExt(); i++ ) {
3277 if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria )
3280 Extrema_POnCurv P1, P2;
3281 anExtrema.Points( i, P1, P2 );
3283 Standard_Boolean bFoundResult = Standard_True;
3286 Standard_Integer surfit = 0;
3287 for ( surfit = 0; surfit < 2; surfit++ ) {
3288 GeomAPI_ProjectPointOnSurf& aProjector =
3289 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3291 gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value();
3292 aProjector.Perform(aP3d);
3294 if(!aProjector.IsDone())
3295 bFoundResult = Standard_False;
3297 if(aProjector.LowerDistance() > aCriteria) {
3298 bFoundResult = Standard_False;
3301 Standard_Real foundU = 0, foundV = 0;
3302 aProjector.LowerDistanceParameters(foundU, foundV);
3304 pr1 = gp_Pnt2d( foundU, foundV );
3306 pr2 = gp_Pnt2d( foundU, foundV );
3310 if ( bFoundResult ) {
3311 aSeqResultS1.Append( pr1 );
3312 aSeqResultS2.Append( pr2 );
3313 aSeqResultRad.Append( aCriteria );
3315 // torus is u and v periodic
3316 const Standard_Real twoPI = M_PI + M_PI;
3317 Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()};
3318 Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()};
3320 // iteration on period bounds
3321 for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) {
3322 Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI;
3323 Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI;
3325 // iteration on surfaces
3326 for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) {
3327 Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp;
3328 Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp;
3329 TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2;
3330 TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2;
3332 if (fabs(arr1[0] - aBound) < Precision::PConfusion()) {
3333 aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) );
3334 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3335 aSeqResultRad.Append( aCriteria );
3337 if (fabs(arr1[1] - aBound) < Precision::PConfusion()) {
3338 aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) );
3339 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3340 aSeqResultRad.Append( aCriteria );
3348 aResult = aSeqResultRad.Length();
3350 if ( aResult > 0 ) {
3351 theResultOnS1 = new TColgp_HArray1OfPnt2d( 1, aResult );
3352 theResultOnS2 = new TColgp_HArray1OfPnt2d( 1, aResult );
3353 theResultRadius = new TColStd_HArray1OfReal( 1, aResult );
3355 for ( Standard_Integer i = 1 ; i <= aResult; i++ ) {
3356 theResultOnS1->SetValue( i, aSeqResultS1.Value(i) );
3357 theResultOnS2->SetValue( i, aSeqResultS2.Value(i) );
3358 theResultRadius->SetValue( i, aSeqResultRad.Value(i) );
3364 // ------------------------------------------------------------------------------------------------
3365 // static function: AdjustByNeighbour
3367 // ------------------------------------------------------------------------------------------------
3368 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
3369 const gp_Pnt2d& theOriginalPoint,
3370 Handle(GeomAdaptor_HSurface) theGASurface) {
3372 gp_Pnt2d ap1 = theaNeighbourPoint;
3373 gp_Pnt2d ap2 = theOriginalPoint;
3375 if ( theGASurface->IsUPeriodic() ) {
3376 Standard_Real aPeriod = theGASurface->UPeriod();
3377 gp_Pnt2d aPTest = ap2;
3378 Standard_Real aSqDistMin = 1.e+100;
3380 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3381 aPTest.SetX( theOriginalPoint.X() + aPeriod * pIt );
3382 Standard_Real dd = ap1.SquareDistance( aPTest );
3384 if ( dd < aSqDistMin ) {
3390 if ( theGASurface->IsVPeriodic() ) {
3391 Standard_Real aPeriod = theGASurface->VPeriod();
3392 gp_Pnt2d aPTest = ap2;
3393 Standard_Real aSqDistMin = 1.e+100;
3395 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3396 aPTest.SetY( theOriginalPoint.Y() + aPeriod * pIt );
3397 Standard_Real dd = ap1.SquareDistance( aPTest );
3399 if ( dd < aSqDistMin ) {
3408 // ------------------------------------------------------------------------------------------------
3409 //function: DecompositionOfWLine
3411 // ------------------------------------------------------------------------------------------------
3412 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
3413 const Handle(GeomAdaptor_HSurface)& theSurface1,
3414 const Handle(GeomAdaptor_HSurface)& theSurface2,
3415 const TopoDS_Face& theFace1,
3416 const TopoDS_Face& theFace2,
3417 const GeomInt_LineConstructor& theLConstructor,
3418 const Standard_Boolean theAvoidLConstructor,
3419 IntPatch_SequenceOfLine& theNewLines,
3420 Standard_Real& theReachedTol3d,
3421 const Handle(IntTools_Context)& aContext)
3424 Standard_Boolean bRet, bAvoidLineConstructor;
3425 Standard_Integer aNbPnts, aNbParts;
3427 bRet=Standard_False;
3428 aNbPnts=theWLine->NbPnts();
3429 bAvoidLineConstructor=theAvoidLConstructor;
3434 if (!bAvoidLineConstructor) {
3435 aNbParts=theLConstructor.NbParts();
3441 Standard_Boolean bIsPrevPointOnBoundary, bIsPointOnBoundary, bIsCurrentPointOnBoundary;
3442 Standard_Integer nblines, pit, i, j;
3444 TColStd_Array1OfListOfInteger anArrayOfLines(1, aNbPnts);
3445 TColStd_Array1OfInteger anArrayOfLineType(1, aNbPnts);
3446 TColStd_ListOfInteger aListOfPointIndex;
3448 Handle(TColgp_HArray1OfPnt2d) aTanZoneS1;
3449 Handle(TColgp_HArray1OfPnt2d) aTanZoneS2;
3450 Handle(TColStd_HArray1OfReal) aTanZoneRadius;
3451 Standard_Integer aNbZone = ComputeTangentZones( theSurface1, theSurface2, theFace1, theFace2,
3452 aTanZoneS1, aTanZoneS2, aTanZoneRadius, aContext);
3456 aTol=Precision::Confusion();
3458 bIsPrevPointOnBoundary=Standard_False;
3459 bIsPointOnBoundary=Standard_False;
3464 for(pit = 1; pit <= aNbPnts; ++pit) {
3465 Standard_Boolean bIsOnFirstBoundary, isperiodic;
3466 Standard_Real aResolution, aPeriod, alowerboundary, aupperboundary, U, V;
3467 Standard_Real aParameter, anoffset, anAdjustPar;
3468 Standard_Real umin, umax, vmin, vmax;
3470 bIsCurrentPointOnBoundary = Standard_False;
3471 const IntSurf_PntOn2S& aPoint = theWLine->Point(pit);
3474 for(i = 0; i < 2; ++i) {
3475 Handle(GeomAdaptor_HSurface) aGASurface = (!i) ? theSurface1 : theSurface2;
3476 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3478 aPoint.ParametersOnS1(U, V);
3481 aPoint.ParametersOnS2(U, V);
3484 for(j = 0; j < 2; j++) {
3485 isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3491 aResolution=aGASurface->UResolution(aTol);
3492 aPeriod=aGASurface->UPeriod();
3493 alowerboundary=umin;
3494 aupperboundary=umax;
3498 aResolution=aGASurface->VResolution(aTol);
3499 aPeriod=aGASurface->VPeriod();
3500 alowerboundary=vmin;
3501 aupperboundary=vmax;
3505 GeomInt::AdjustPeriodic(aParameter,
3512 bIsOnFirstBoundary = Standard_True;// ?
3514 IsPointOnBoundary(anAdjustPar,
3518 bIsOnFirstBoundary);
3520 if(bIsPointOnBoundary) {
3521 bIsCurrentPointOnBoundary = Standard_True;
3525 // check if a point belong to a tangent zone. Begin
3526 Standard_Integer zIt = 0;
3527 for ( zIt = 1; zIt <= aNbZone; zIt++ ) {
3528 gp_Pnt2d aPZone = (i == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3529 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3531 if ( IsInsideTanZone(gp_Pnt2d( U, V ), aPZone, aZoneRadius, aGASurface ) ) {
3532 // set boundary flag to split the curve by a tangent zone
3533 bIsPointOnBoundary = Standard_True;
3534 bIsCurrentPointOnBoundary = Standard_True;
3535 if ( theReachedTol3d < aZoneRadius ) {
3536 theReachedTol3d = aZoneRadius;
3542 }//for(j = 0; j < 2; j++) {
3544 if(bIsCurrentPointOnBoundary){
3547 }//for(i = 0; i < 2; ++i) {
3549 if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) {
3550 if(!aListOfPointIndex.IsEmpty()) {
3552 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3553 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3554 aListOfPointIndex.Clear();
3556 bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary;
3558 aListOfPointIndex.Append(pit);
3559 } //for(pit = 1; pit <= aNbPnts; ++pit) {
3561 if(!aListOfPointIndex.IsEmpty()) {
3563 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3564 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3565 aListOfPointIndex.Clear();
3569 return bRet; //Standard_False;
3573 // 2. Correct wlines.begin
3574 TColStd_Array1OfListOfInteger anArrayOfLineEnds(1, nblines);
3575 Handle(IntSurf_LineOn2S) aSeqOfPntOn2S = new IntSurf_LineOn2S();
3577 for(i = 1; i <= nblines; i++) {
3578 if(anArrayOfLineType.Value(i) != 0) {
3581 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3582 TColStd_ListOfInteger aListOfFLIndex;
3584 for(j = 0; j < 2; j++) {
3585 Standard_Integer aneighbourindex = (j == 0) ? (i - 1) : (i + 1);
3587 if((aneighbourindex < 1) || (aneighbourindex > nblines))
3590 if(anArrayOfLineType.Value(aneighbourindex) == 0)
3592 const TColStd_ListOfInteger& aNeighbour = anArrayOfLines.Value(aneighbourindex);
3593 Standard_Integer anIndex = (j == 0) ? aNeighbour.Last() : aNeighbour.First();
3594 const IntSurf_PntOn2S& aPoint = theWLine->Point(anIndex);
3596 IntSurf_PntOn2S aNewP = aPoint;
3597 if(aListOfIndex.Extent() < 2) {
3598 aSeqOfPntOn2S->Add(aNewP);
3599 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
3603 Standard_Integer iFirst = aListOfIndex.First();
3604 Standard_Integer iLast = aListOfIndex.Last();
3606 for(Standard_Integer surfit = 0; surfit < 2; surfit++) {
3608 Handle(GeomAdaptor_HSurface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2;
3609 Standard_Real umin=0., umax=0., vmin=0., vmax=0.;
3610 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3611 Standard_Real U=0., V=0.;
3614 aNewP.ParametersOnS1(U, V);
3616 aNewP.ParametersOnS2(U, V);
3617 Standard_Integer nbboundaries = 0;
3619 Standard_Boolean bIsNearBoundary = Standard_False;
3620 Standard_Integer aZoneIndex = 0;
3621 Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1
3622 Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1
3625 for(Standard_Integer parit = 0; parit < 2; parit++) {
3626 Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3628 Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
3629 Standard_Real alowerboundary = (parit == 0) ? umin : vmin;
3630 Standard_Real aupperboundary = (parit == 0) ? umax : vmax;
3632 Standard_Real aParameter = (parit == 0) ? U : V;
3633 Standard_Boolean bIsOnFirstBoundary = Standard_True;
3637 IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3638 if(bIsPointOnBoundary) {
3639 bIsUBoundary = (parit == 0);
3640 bIsFirstBoundary = bIsOnFirstBoundary;
3645 Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3646 Standard_Real anoffset, anAdjustPar;
3647 GeomInt::AdjustPeriodic(aParameter, alowerboundary, aupperboundary,
3648 aPeriod, anAdjustPar, anoffset);
3651 IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3652 if(bIsPointOnBoundary) {
3653 bIsUBoundary = (parit == 0);
3654 bIsFirstBoundary = bIsOnFirstBoundary;
3658 //check neighbourhood of boundary
3659 Standard_Real anEpsilon = aResolution * 100.;
3660 Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
3661 anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
3663 bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary,
3664 anEpsilon, bIsOnFirstBoundary);
3670 // check if a point belong to a tangent zone. Begin
3671 for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) {
3672 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3673 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3675 Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast;
3676 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3677 Standard_Real nU1, nV1;
3680 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3682 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3683 gp_Pnt2d ap1(nU1, nV1);
3684 gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface );
3687 if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) {
3689 bIsNearBoundary = Standard_True;
3690 if ( theReachedTol3d < aZoneRadius ) {
3691 theReachedTol3d = aZoneRadius;
3695 // check if a point belong to a tangent zone. End
3696 Standard_Boolean bComputeLineEnd = Standard_False;
3698 if(nbboundaries == 2) {
3700 bComputeLineEnd = Standard_True;
3703 else if(nbboundaries == 1) {
3704 Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3707 Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
3708 Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
3709 Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3710 Standard_Real aParameter = (bIsUBoundary) ? U : V;
3711 Standard_Real anoffset, anAdjustPar;
3712 GeomInt::AdjustPeriodic(aParameter, alowerboundary, aupperboundary,
3713 aPeriod, anAdjustPar, anoffset);
3715 Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
3716 Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
3717 anotherPar += anoffset;
3718 Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3719 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
3720 Standard_Real nU1, nV1;
3723 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3725 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3727 Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
3728 Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
3729 bComputeLineEnd = Standard_True;
3730 Standard_Boolean bCheckAngle1 = Standard_False;
3731 Standard_Boolean bCheckAngle2 = Standard_False;
3733 Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
3734 Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
3736 if(((adist1 - adist2) > Precision::PConfusion()) &&
3737 (adist2 < (aPeriod / 4.))) {
3738 bCheckAngle1 = Standard_True;
3739 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
3741 if(aNewVec.SquareMagnitude() < gp::Resolution()) {
3742 aNewP.SetValue((surfit == 0), anewU, anewV);
3743 bCheckAngle1 = Standard_False;
3746 else if(adist1 < (aPeriod / 4.)) {
3747 bCheckAngle2 = Standard_True;
3748 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
3750 if(aNewVec.SquareMagnitude() < gp::Resolution()) {
3751 bCheckAngle2 = Standard_False;
3755 if(bCheckAngle1 || bCheckAngle2) {
3756 // assume there are at least two points in line (see "if" above)
3757 Standard_Integer anindexother = aneighbourpointindex;
3759 while((anindexother <= iLast) && (anindexother >= iFirst)) {
3760 anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
3761 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
3762 Standard_Real nU2, nV2;
3765 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3767 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3768 gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
3770 if(aVecOld.SquareMagnitude() <= gp::Resolution()) {
3774 Standard_Real anAngle = aNewVec.Angle(aVecOld);
3776 if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
3779 Standard_Real U1, U2, V1, V2;
3780 IntSurf_PntOn2S atmppoint = aNewP;
3781 atmppoint.SetValue((surfit == 0), anewU, anewV);
3782 atmppoint.Parameters(U1, V1, U2, V2);
3783 gp_Pnt P1 = theSurface1->Value(U1, V1);
3784 gp_Pnt P2 = theSurface2->Value(U2, V2);
3785 gp_Pnt P0 = aPoint.Value();
3787 if(P0.IsEqual(P1, aTol) &&
3788 P0.IsEqual(P2, aTol) &&
3789 P1.IsEqual(P2, aTol)) {
3790 bComputeLineEnd = Standard_False;
3791 aNewP.SetValue((surfit == 0), anewU, anewV);
3796 bComputeLineEnd = Standard_False;
3801 } // end while(anindexother...)
3805 else if ( bIsNearBoundary ) {
3806 bComputeLineEnd = Standard_True;
3809 if(bComputeLineEnd) {
3812 Standard_Boolean found = Standard_False;
3814 if ( bIsNearBoundary ) {
3815 // re-compute point near natural boundary or near tangent zone
3816 Standard_Real u1, v1, u2, v2;
3817 aNewP.Parameters( u1, v1, u2, v2 );
3819 anewpoint = gp_Pnt2d( u1, v1 );
3821 anewpoint = gp_Pnt2d( u2, v2 );
3823 Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast;
3824 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3825 Standard_Real nU1, nV1;
3828 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3830 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3831 gp_Pnt2d ap1(nU1, nV1);
3836 // exclude point from a tangent zone
3837 anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3838 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex);
3839 Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex);
3841 if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax,
3842 aPZone, aZoneRadius, aGASurface, ap2) ) {
3844 found = Standard_True;
3847 else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
3848 // re-compute point near boundary if shifted on a period
3849 ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3851 if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
3852 ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
3853 found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
3857 aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
3863 Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast;
3864 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3865 Standard_Real nU1, nV1;
3868 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3870 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3871 gp_Pnt2d ap1(nU1, nV1);
3872 gp_Pnt2d ap2(nU1, nV1);
3873 Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
3875 while((aneighbourpointindex2 <= iLast) && (aneighbourpointindex2 >= iFirst)) {
3876 aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
3877 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
3878 Standard_Real nU2, nV2;
3881 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3883 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3887 if(ap1.SquareDistance(ap2) > gp::Resolution()) {
3891 found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
3896 Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
3897 GeomAPI_ProjectPointOnSurf& aProjector =
3898 (surfit == 0) ? aContext->ProjPS(theFace2) : aContext->ProjPS(theFace1);
3899 Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
3901 Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
3903 gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
3904 aProjector.Perform(aP3d);
3906 if(aProjector.IsDone()) {
3907 if(aProjector.LowerDistance() < aCriteria) {
3908 Standard_Real foundU = U, foundV = V;
3909 aProjector.LowerDistanceParameters(foundU, foundV);
3911 //Correction of projected coordinates. Begin
3912 //Note, it may be shifted on a period
3913 Standard_Integer aneindex1 = (j == 0) ? iFirst : iLast;
3914 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
3915 Standard_Real nUn, nVn;
3918 aNeighbourPoint.ParametersOnS2(nUn, nVn);
3920 aNeighbourPoint.ParametersOnS1(nUn, nVn);
3921 gp_Pnt2d aNeighbour2d(nUn, nVn);
3922 gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
3923 foundU = anAdjustedPoint.X();
3924 foundV = anAdjustedPoint.Y();
3926 if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
3927 ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
3928 // attempt to roughly re-compute point
3929 foundU = ( foundU < umin ) ? umin : foundU;
3930 foundU = ( foundU > umax ) ? umax : foundU;
3931 foundV = ( foundV < vmin ) ? vmin : foundV;
3932 foundV = ( foundV > vmax ) ? vmax : foundV;
3934 GeomAPI_ProjectPointOnSurf& aProjector2 =
3935 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3937 aP3d = aSurfaceOther->Value(foundU, foundV);
3938 aProjector2.Perform(aP3d);
3940 if(aProjector2.IsDone()) {
3941 if(aProjector2.LowerDistance() < aCriteria) {
3942 Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
3943 aProjector2.LowerDistanceParameters(foundU2, foundV2);
3944 anewpoint.SetX(foundU2);
3945 anewpoint.SetY(foundV2);
3949 //Correction of projected coordinates. End
3952 aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
3954 aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
3960 aSeqOfPntOn2S->Add(aNewP);
3961 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
3963 anArrayOfLineEnds.SetValue(i, aListOfFLIndex);
3965 // Correct wlines.end
3967 // Split wlines.begin
3968 Standard_Integer nbiter;
3971 if (!bAvoidLineConstructor) {
3972 nbiter=theLConstructor.NbParts();
3975 for(j = 1; j <= nbiter; ++j) {
3976 Standard_Real fprm, lprm;
3977 Standard_Integer ifprm, ilprm;
3979 if(bAvoidLineConstructor) {
3981 ilprm = theWLine->NbPnts();
3984 theLConstructor.Part(j, fprm, lprm);
3985 ifprm = (Standard_Integer)fprm;
3986 ilprm = (Standard_Integer)lprm;
3989 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
3991 for(i = 1; i <= nblines; i++) {
3992 if(anArrayOfLineType.Value(i) != 0) {
3995 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3996 const TColStd_ListOfInteger& aListOfFLIndex = anArrayOfLineEnds.Value(i);
3997 Standard_Boolean bhasfirstpoint = (aListOfFLIndex.Extent() == 2);
3998 Standard_Boolean bhaslastpoint = (aListOfFLIndex.Extent() == 2);
4000 if(!bhasfirstpoint && !aListOfFLIndex.IsEmpty()) {
4001 bhasfirstpoint = (i != 1);
4004 if(!bhaslastpoint && !aListOfFLIndex.IsEmpty()) {
4005 bhaslastpoint = (i != nblines);
4008 Standard_Integer iFirst = aListOfIndex.First();
4009 Standard_Integer iLast = aListOfIndex.Last();
4010 Standard_Boolean bIsFirstInside = ((ifprm >= iFirst) && (ifprm <= iLast));
4011 Standard_Boolean bIsLastInside = ((ilprm >= iFirst) && (ilprm <= iLast));
4013 if(!bIsFirstInside && !bIsLastInside) {
4014 if((ifprm < iFirst) && (ilprm > iLast)) {
4015 // append whole line, and boundaries if neccesary
4016 if(bhasfirstpoint) {
4017 pit = aListOfFLIndex.First();
4018 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4021 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4023 for(; anIt.More(); anIt.Next()) {
4025 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4030 pit = aListOfFLIndex.Last();
4031 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4035 // check end of split line (end is almost always)
4036 Standard_Integer aneighbour = i + 1;
4037 Standard_Boolean bIsEndOfLine = Standard_True;
4039 if(aneighbour <= nblines) {
4040 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4042 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4043 (aListOfNeighbourIndex.IsEmpty())) {
4044 bIsEndOfLine = Standard_False;
4049 if(aLineOn2S->NbPoints() > 1) {
4050 Handle(IntPatch_WLine) aNewWLine =
4051 new IntPatch_WLine(aLineOn2S, Standard_False);
4052 theNewLines.Append(aNewWLine);
4054 aLineOn2S = new IntSurf_LineOn2S();
4059 // end if(!bIsFirstInside && !bIsLastInside)
4061 if(bIsFirstInside && bIsLastInside) {
4062 // append inside points between ifprm and ilprm
4063 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4065 for(; anIt.More(); anIt.Next()) {
4067 if((pit < ifprm) || (pit > ilprm))
4069 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4075 if(bIsFirstInside) {
4076 // append points from ifprm to last point + boundary point
4077 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4079 for(; anIt.More(); anIt.Next()) {
4083 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4088 pit = aListOfFLIndex.Last();
4089 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4092 // check end of split line (end is almost always)
4093 Standard_Integer aneighbour = i + 1;
4094 Standard_Boolean bIsEndOfLine = Standard_True;
4096 if(aneighbour <= nblines) {
4097 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4099 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4100 (aListOfNeighbourIndex.IsEmpty())) {
4101 bIsEndOfLine = Standard_False;
4106 if(aLineOn2S->NbPoints() > 1) {
4107 Handle(IntPatch_WLine) aNewWLine =
4108 new IntPatch_WLine(aLineOn2S, Standard_False);
4109 theNewLines.Append(aNewWLine);
4111 aLineOn2S = new IntSurf_LineOn2S();
4114 // end if(bIsFirstInside)
4117 // append points from first boundary point to ilprm
4118 if(bhasfirstpoint) {
4119 pit = aListOfFLIndex.First();
4120 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4123 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4125 for(; anIt.More(); anIt.Next()) {
4129 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4133 //end if(bIsLastInside)
4137 if(aLineOn2S->NbPoints() > 1) {
4138 Handle(IntPatch_WLine) aNewWLine =
4139 new IntPatch_WLine(aLineOn2S, Standard_False);
4140 theNewLines.Append(aNewWLine);
4145 return Standard_True;
4148 // ------------------------------------------------------------------------------------------------
4149 // static function: ParameterOutOfBoundary
4150 // purpose: Computes a new parameter for given curve. The corresponding 2d points
4151 // does not lay on any boundary of given faces
4152 // ------------------------------------------------------------------------------------------------
4153 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
4154 const Handle(Geom_Curve)& theCurve,
4155 const TopoDS_Face& theFace1,
4156 const TopoDS_Face& theFace2,
4157 const Standard_Real theOtherParameter,
4158 const Standard_Boolean bIncreasePar,
4159 Standard_Real& theNewParameter,
4160 const Handle(IntTools_Context)& aContext)
4162 Standard_Boolean bIsComputed = Standard_False;
4163 theNewParameter = theParameter;
4165 Standard_Real acurpar = theParameter;
4166 TopAbs_State aState = TopAbs_ON;
4167 Standard_Integer iter = 0;
4168 Standard_Real asumtol = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4169 Standard_Real adelta = asumtol * 0.1;
4170 adelta = (adelta < Precision::Confusion()) ? Precision::Confusion() : adelta;
4171 Handle(Geom_Surface) aSurf1 = BRep_Tool::Surface(theFace1);
4172 Handle(Geom_Surface) aSurf2 = BRep_Tool::Surface(theFace2);
4174 Standard_Real u1, u2, v1, v2;
4176 GeomAPI_ProjectPointOnSurf aPrj1;
4177 aSurf1->Bounds(u1, u2, v1, v2);
4178 aPrj1.Init(aSurf1, u1, u2, v1, v2);
4180 GeomAPI_ProjectPointOnSurf aPrj2;
4181 aSurf2->Bounds(u1, u2, v1, v2);
4182 aPrj2.Init(aSurf2, u1, u2, v1, v2);
4184 while(aState == TopAbs_ON) {
4189 gp_Pnt aPCurrent = theCurve->Value(acurpar);
4190 aPrj1.Perform(aPCurrent);
4191 Standard_Real U=0., V=0.;
4193 if(aPrj1.IsDone()) {
4194 aPrj1.LowerDistanceParameters(U, V);
4195 aState = aContext->StatePointFace(theFace1, gp_Pnt2d(U, V));
4198 if(aState != TopAbs_ON) {
4199 aPrj2.Perform(aPCurrent);
4201 if(aPrj2.IsDone()) {
4202 aPrj2.LowerDistanceParameters(U, V);
4203 aState = aContext->StatePointFace(theFace2, gp_Pnt2d(U, V));
4214 theNewParameter = acurpar;
4215 bIsComputed = Standard_True;
4218 if(acurpar >= theOtherParameter)
4219 theNewParameter = theOtherParameter;
4222 if(acurpar <= theOtherParameter)
4223 theNewParameter = theOtherParameter;
4229 //=======================================================================
4230 //function : IsCurveValid
4232 //=======================================================================
4233 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve)
4235 if(thePCurve.IsNull())
4236 return Standard_False;
4238 Standard_Real tolint = 1.e-10;
4239 Geom2dAdaptor_Curve PCA;
4240 IntRes2d_Domain PCD;
4241 Geom2dInt_GInter PCI;
4243 Standard_Real pf = 0., pl = 0.;
4244 gp_Pnt2d pntf, pntl;
4246 if(!thePCurve->IsClosed() && !thePCurve->IsPeriodic()) {
4247 pf = thePCurve->FirstParameter();
4248 pl = thePCurve->LastParameter();
4249 pntf = thePCurve->Value(pf);
4250 pntl = thePCurve->Value(pl);
4251 PCA.Load(thePCurve);
4252 if(!PCA.IsPeriodic()) {
4253 if(PCA.FirstParameter() > pf) pf = PCA.FirstParameter();
4254 if(PCA.LastParameter() < pl) pl = PCA.LastParameter();
4256 PCD.SetValues(pntf,pf,tolint,pntl,pl,tolint);
4257 PCI.Perform(PCA,PCD,tolint,tolint);
4259 if(PCI.NbPoints() > 0) {
4260 return Standard_False;
4264 return Standard_True;
4267 //=======================================================================
4268 //static function : ApproxWithPCurves
4269 //purpose : for bug 20964 only
4270 //=======================================================================
4271 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
4272 const gp_Sphere& theSph)
4274 Standard_Boolean bRes = Standard_True;
4275 Standard_Real R1 = theCyl.Radius(), R2 = theSph.Radius();
4278 Standard_Real aD2, aRc2, aEps;
4284 const gp_Ax3& aAx3Sph=theSph.Position();
4285 const gp_Pnt& aLocSph=aAx3Sph.Location();
4286 const gp_Dir& aDirSph=aAx3Sph.Direction();
4288 const gp_Ax1& aAx1Cyl=theCyl.Axis();
4289 gp_Lin aLinCyl(aAx1Cyl);
4291 aApexSph.SetXYZ(aLocSph.XYZ()+R2*aDirSph.XYZ());
4292 aD2=aLinCyl.SquareDistance(aApexSph);
4293 if (fabs(aD2-aRc2)<aEps) {
4297 aApexSph.SetXYZ(aLocSph.XYZ()-R2*aDirSph.XYZ());
4298 aD2=aLinCyl.SquareDistance(aApexSph);
4299 if (fabs(aD2-aRc2)<aEps) {
4308 gp_Lin anCylAx(theCyl.Axis());
4310 Standard_Real aDist = anCylAx.Distance(theSph.Location());
4311 Standard_Real aDRel = Abs(aDist - R1)/R2;
4313 if(aDRel > .2) return bRes;
4315 Standard_Real par = ElCLib::Parameter(anCylAx, theSph.Location());
4316 gp_Pnt aP = ElCLib::Value(par, anCylAx);
4317 gp_Vec aV(aP, theSph.Location());
4319 Standard_Real dd = aV.Dot(theSph.Position().XDirection());
4321 if(aDist < R1 && dd > 0.) return Standard_False;
4322 if(aDist > R1 && dd < 0.) return Standard_False;
4327 //=======================================================================
4328 //function : PerformPlanes
4330 //=======================================================================
4331 void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
4332 const Handle(GeomAdaptor_HSurface)& theS2,
4333 const Standard_Real TolAng,
4334 const Standard_Real TolTang,
4335 const Standard_Boolean theApprox1,
4336 const Standard_Boolean theApprox2,
4337 IntTools_SequenceOfCurves& theSeqOfCurve,
4338 Standard_Boolean& theTangentFaces)
4341 gp_Pln aPln1 = theS1->Surface().Plane();
4342 gp_Pln aPln2 = theS2->Surface().Plane();
4344 IntAna_QuadQuadGeo aPlnInter(aPln1, aPln2, TolAng, TolTang);
4346 if(!aPlnInter.IsDone()) {
4347 theTangentFaces = Standard_False;
4351 IntAna_ResultType aResType = aPlnInter.TypeInter();
4353 if(aResType == IntAna_Same) {
4354 theTangentFaces = Standard_True;
4358 theTangentFaces = Standard_False;
4360 if(aResType == IntAna_Empty) {
4364 gp_Lin aLin = aPlnInter.Line(1);
4366 ProjLib_Plane aProj;
4369 aProj.Project(aLin);
4370 gp_Lin2d aLin2d1 = aProj.Line();
4373 aProj.Project(aLin);
4374 gp_Lin2d aLin2d2 = aProj.Line();
4376 //classify line2d1 relatively first plane
4377 Standard_Real P11, P12;
4378 Standard_Boolean IsCrossed = ClassifyLin2d(theS1, aLin2d1, TolTang, P11, P12);
4379 if(!IsCrossed) return;
4380 //classify line2d2 relatively second plane
4381 Standard_Real P21, P22;
4382 IsCrossed = ClassifyLin2d(theS2, aLin2d2, TolTang, P21, P22);
4383 if(!IsCrossed) return;
4385 //Analysis of parametric intervals: must have common part
4387 if(P21 >= P12) return;
4388 if(P22 <= P11) return;
4390 Standard_Real pmin, pmax;
4391 pmin = Max(P11, P21);
4392 pmax = Min(P12, P22);
4394 if(pmax - pmin <= TolTang) return;
4396 Handle(Geom_Line) aGLin = new Geom_Line(aLin);
4398 IntTools_Curve aCurve;
4399 Handle(Geom_TrimmedCurve) aGTLin = new Geom_TrimmedCurve(aGLin, pmin, pmax);
4401 aCurve.SetCurve(aGTLin);
4404 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d1);
4405 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4408 Handle(Geom2d_Curve) H1;
4409 aCurve.SetFirstCurve2d(H1);
4412 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d2);
4413 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4416 Handle(Geom2d_Curve) H1;
4417 aCurve.SetFirstCurve2d(H1);
4420 theSeqOfCurve.Append(aCurve);
4424 //=======================================================================
4425 //function : ClassifyLin2d
4427 //=======================================================================
4428 static inline Standard_Boolean INTER(const Standard_Real d1,
4429 const Standard_Real d2,
4430 const Standard_Real tol)
4432 return (d1 > tol && d2 < -tol) ||
4433 (d1 < -tol && d2 > tol) ||
4434 ((d1 <= tol && d1 >= -tol) && (d2 > tol || d2 < -tol)) ||
4435 ((d2 <= tol && d2 >= -tol) && (d1 > tol || d1 < -tol));
4437 static inline Standard_Boolean COINC(const Standard_Real d1,
4438 const Standard_Real d2,
4439 const Standard_Real tol)
4441 return (d1 <= tol && d1 >= -tol) && (d2 <= tol && d2 >= -tol);
4443 Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
4444 const gp_Lin2d& theLin2d,
4445 const Standard_Real theTol,
4446 Standard_Real& theP1,
4447 Standard_Real& theP2)
4450 Standard_Real xmin, xmax, ymin, ymax, d1, d2, A, B, C;
4451 Standard_Real par[2];
4452 Standard_Integer nbi = 0;
4454 xmin = theS->Surface().FirstUParameter();
4455 xmax = theS->Surface().LastUParameter();
4456 ymin = theS->Surface().FirstVParameter();
4457 ymax = theS->Surface().LastVParameter();
4459 theLin2d.Coefficients(A, B, C);
4461 //xmin, ymin <-> xmin, ymax
4462 d1 = A*xmin + B*ymin + C;
4463 d2 = A*xmin + B*ymax + C;
4465 if(INTER(d1, d2, theTol)) {
4466 //Intersection with boundary
4467 Standard_Real y = -(C + A*xmin)/B;
4468 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, y));
4471 else if (COINC(d1, d2, theTol)) {
4472 //Coincidence with boundary
4473 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4474 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4480 if(fabs(par[0]-par[1]) > theTol) {
4481 theP1 = Min(par[0], par[1]);
4482 theP2 = Max(par[0], par[1]);
4483 return Standard_True;
4485 else return Standard_False;
4489 //xmin, ymax <-> xmax, ymax
4491 d2 = A*xmax + B*ymax + C;
4493 if(d1 > theTol || d1 < -theTol) {//to avoid checking of
4494 //coincidence with the same point
4495 if(INTER(d1, d2, theTol)) {
4496 Standard_Real x = -(C + B*ymax)/A;
4497 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymax));
4500 else if (COINC(d1, d2, theTol)) {
4501 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4502 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4509 if(fabs(par[0]-par[1]) > theTol) {
4510 theP1 = Min(par[0], par[1]);
4511 theP2 = Max(par[0], par[1]);
4512 return Standard_True;
4514 else return Standard_False;
4518 //xmax, ymax <-> xmax, ymin
4520 d2 = A*xmax + B*ymin + C;
4522 if(d1 > theTol || d1 < -theTol) {
4523 if(INTER(d1, d2, theTol)) {
4524 Standard_Real y = -(C + A*xmax)/B;
4525 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, y));
4528 else if (COINC(d1, d2, theTol)) {
4529 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4530 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4536 if(fabs(par[0]-par[1]) > theTol) {
4537 theP1 = Min(par[0], par[1]);
4538 theP2 = Max(par[0], par[1]);
4539 return Standard_True;
4541 else return Standard_False;
4544 //xmax, ymin <-> xmin, ymin
4546 d2 = A*xmin + B*ymin + C;
4548 if(d1 > theTol || d1 < -theTol) {
4549 if(INTER(d1, d2, theTol)) {
4550 Standard_Real x = -(C + B*ymin)/A;
4551 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymin));
4554 else if (COINC(d1, d2, theTol)) {
4555 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4556 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4562 if(fabs(par[0]-par[1]) > theTol) {
4563 theP1 = Min(par[0], par[1]);
4564 theP2 = Max(par[0], par[1]);
4565 return Standard_True;
4567 else return Standard_False;
4570 return Standard_False;
4574 //=======================================================================
4575 //function : ApproxParameters
4577 //=======================================================================
4578 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
4579 const Handle(GeomAdaptor_HSurface)& aHS2,
4580 Standard_Integer& iDegMin,
4581 Standard_Integer& iDegMax,
4582 Standard_Integer& iNbIter)
4585 GeomAbs_SurfaceType aTS1, aTS2;
4592 aTS1=aHS1->Surface().GetType();
4593 aTS2=aHS2->Surface().GetType();
4596 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4597 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4598 Standard_Real aRC, aRT, dR, aPC;
4599 gp_Cylinder aCylinder;
4602 aPC=Precision::Confusion();
4604 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4605 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4607 aRC=aCylinder.Radius();
4608 aRT=aTorus.MinorRadius();
4618 if (aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Cylinder) {
4622 //=======================================================================
4623 //function : Tolerances
4625 //=======================================================================
4626 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
4627 const Handle(GeomAdaptor_HSurface)& aHS2,
4628 Standard_Real& aTolTang)
4630 GeomAbs_SurfaceType aTS1, aTS2;
4632 aTS1=aHS1->Surface().GetType();
4633 aTS2=aHS2->Surface().GetType();
4636 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4637 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4638 Standard_Real aRC, aRT, dR, aPC;
4639 gp_Cylinder aCylinder;
4642 aPC=Precision::Confusion();
4644 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4645 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4647 aRC=aCylinder.Radius();
4648 aRT=aTorus.MinorRadius();
4655 aTolTang=0.1*aTolTang;
4659 //=======================================================================
4660 //function : SortTypes
4662 //=======================================================================
4663 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
4664 const GeomAbs_SurfaceType aType2)
4666 Standard_Boolean bRet;
4667 Standard_Integer aI1, aI2;
4669 bRet=Standard_False;
4671 aI1=IndexType(aType1);
4672 aI2=IndexType(aType2);
4678 //=======================================================================
4679 //function : IndexType
4681 //=======================================================================
4682 Standard_Integer IndexType(const GeomAbs_SurfaceType aType)
4684 Standard_Integer aIndex;
4688 if (aType==GeomAbs_Plane) {
4691 else if (aType==GeomAbs_Cylinder) {
4694 else if (aType==GeomAbs_Cone) {
4697 else if (aType==GeomAbs_Sphere) {
4700 else if (aType==GeomAbs_Torus) {
4703 else if (aType==GeomAbs_BezierSurface) {
4706 else if (aType==GeomAbs_BSplineSurface) {
4709 else if (aType==GeomAbs_SurfaceOfRevolution) {
4712 else if (aType==GeomAbs_SurfaceOfExtrusion) {
4715 else if (aType==GeomAbs_OffsetSurface) {
4718 else if (aType==GeomAbs_OtherSurface) {
4723 #ifdef OCCT_DEBUG_DUMPWLINE
4724 //=======================================================================
4725 //function : DumpWLine
4727 //=======================================================================
4728 void DumpWLine(const Handle(IntPatch_WLine)& aWLine)
4730 Standard_Integer i, aNbPnts;
4731 Standard_Real aX, aY, aZ, aU1, aV1, aU2, aV2;
4733 printf(" *WLine\n");
4734 aNbPnts=aWLine->NbPnts();
4735 for (i=1; i<=aNbPnts; ++i) {
4736 const IntSurf_PntOn2S aPntOn2S=aWLine->Point(i);
4737 const gp_Pnt& aP3D=aPntOn2S.Value();
4738 aP3D.Coord(aX, aY, aZ);
4739 aPntOn2S.Parameters(aU1, aV1, aU2, aV2);
4741 printf("point p_%d %lf %lf %lf\n", i, aX, aY, aZ);
4742 //printf("point p_%d %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf\n",
4743 // i, aX, aY, aZ, aU1, aV1, aU2, aV2);
4747 //=======================================================================
4748 //function : RefineVector
4750 //=======================================================================
4751 void RefineVector(gp_Vec2d& aV2D)
4753 Standard_Integer k,m;
4754 Standard_Real aC[2], aEps, aR1, aR2, aNum;
4760 aV2D.Coord(aC[0], aC[1]);
4762 for (k=0; k<2; ++k) {
4765 if (aNum>aR1 && aNum<aR2) {
4776 aV2D.SetCoord(aC[0], aC[1]);
4779 //=======================================================================
4780 // Function : MaxDistance
4782 //=======================================================================
4783 Standard_Real MaxDistance(const Handle(Geom_Curve)& theC,
4784 const Standard_Real aT,
4785 GeomAPI_ProjectPointOnSurf& theProjPS)
4791 theProjPS.Perform(aP);
4792 aD = theProjPS.NbPoints() ? theProjPS.LowerDistance() : 0.;
4797 //=======================================================================
4798 //function : CheckPCurve
4799 //purpose : Checks if points of the pcurve are out of the face bounds.
4800 //=======================================================================
4801 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
4802 const TopoDS_Face& aFace)
4804 const Standard_Integer NPoints = 23;
4806 Standard_Real umin,umax,vmin,vmax;
4808 BRepTools::UVBounds(aFace, umin, umax, vmin, vmax);
4809 Standard_Real tolU = Max ((umax-umin)*0.01, Precision::Confusion());
4810 Standard_Real tolV = Max ((vmax-vmin)*0.01, Precision::Confusion());
4811 Standard_Real fp = aPC->FirstParameter();
4812 Standard_Real lp = aPC->LastParameter();
4815 // adjust domain for periodic surfaces
4816 TopLoc_Location aLoc;
4817 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc);
4818 if (aSurf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
4819 aSurf = (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf))->BasisSurface();
4821 gp_Pnt2d pnt = aPC->Value((fp+lp)/2);
4825 if (aSurf->IsUPeriodic()) {
4826 Standard_Real aPer = aSurf->UPeriod();
4827 Standard_Integer nshift = (Standard_Integer) ((u-umin)/aPer);
4828 if (u < umin+aPer*nshift) nshift--;
4829 umin += aPer*nshift;
4830 umax += aPer*nshift;
4832 if (aSurf->IsVPeriodic()) {
4833 Standard_Real aPer = aSurf->VPeriod();
4834 Standard_Integer nshift = (Standard_Integer) ((v-vmin)/aPer);
4835 if (v < vmin+aPer*nshift) nshift--;
4836 vmin += aPer*nshift;
4837 vmax += aPer*nshift;
4840 //--------------------------------------------------------
4841 Standard_Boolean bRet;
4842 Standard_Integer j, aNbIntervals;
4843 Standard_Real aT, dT;
4846 Geom2dAdaptor_Curve aGAC(aPC);
4847 aNbIntervals=aGAC.NbIntervals(GeomAbs_CN);
4849 TColStd_Array1OfReal aTI(1, aNbIntervals+1);
4850 aGAC.Intervals(aTI,GeomAbs_CN);
4852 bRet=Standard_False;
4854 aT=aGAC.FirstParameter();
4855 for (j=1; j<=aNbIntervals; ++j) {
4856 dT=(aTI(j+1)-aTI(j))/NPoints;
4858 for (i=1; i<NPoints; i++) {
4862 if (umin-u > tolU || u-umax > tolU ||
4863 vmin-v > tolV || v-vmax > tolV) {
4870 //=======================================================================
4871 //function : CorrectPlaneBoundaries
4873 //=======================================================================
4874 void CorrectPlaneBoundaries(Standard_Real& aUmin,
4875 Standard_Real& aUmax,
4876 Standard_Real& aVmin,
4877 Standard_Real& aVmax)
4879 if (!(Precision::IsInfinite(aUmin) ||
4880 Precision::IsInfinite(aUmax))) {
4883 dU=0.1*(aUmax-aUmin);
4887 if (!(Precision::IsInfinite(aVmin) ||
4888 Precision::IsInfinite(aVmax))) {
4891 dV=0.1*(aVmax-aVmin);