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);
1681 Standard_Integer ifprm, ilprm;
1685 if(!bAvoidLineConstructor){
1686 aNbParts=myLConstruct.NbParts();
1688 for (i=1; i<=aNbParts; ++i) {
1689 Handle(Geom2d_BSplineCurve) H1, H2;
1690 Handle(Geom_Curve) aBSp;
1692 if(bAvoidLineConstructor) {
1694 ilprm = WL->NbPnts();
1697 myLConstruct.Part(i, fprm, lprm);
1698 ifprm=(Standard_Integer)fprm;
1699 ilprm=(Standard_Integer)lprm;
1703 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1707 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1710 aBSp=MakeBSpline(WL, ifprm, ilprm);
1711 IntTools_Curve aIC(aBSp, H1, H2);
1712 mySeqOfCurve.Append(aIC);
1713 }// for (i=1; i<=aNbParts; ++i) {
1714 }// if (!myApprox) {
1717 Standard_Boolean bIsDecomposited;
1718 Standard_Integer nbiter, aNbSeqOfL;
1719 Standard_Real tol2d, aTolApproxImp;
1720 IntPatch_SequenceOfLine aSeqOfL;
1721 GeomInt_WLApprox theapp3d;
1722 Approx_ParametrizationType aParType = Approx_ChordLength;
1724 Standard_Boolean anApprox1 = myApprox1;
1725 Standard_Boolean anApprox2 = myApprox2;
1727 aTolApproxImp=1.e-5;
1728 tol2d = myTolApprox;
1730 GeomAbs_SurfaceType typs1, typs2;
1731 typs1 = myHS1->Surface().GetType();
1732 typs2 = myHS2->Surface().GetType();
1733 Standard_Boolean anWithPC = Standard_True;
1735 if(typs1 == GeomAbs_Cylinder && typs2 == GeomAbs_Sphere) {
1737 ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere());
1739 else if (typs1 == GeomAbs_Sphere && typs2 == GeomAbs_Cylinder) {
1741 ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere());
1745 myTolApprox = aTolApproxImp;//1.e-5;
1746 anApprox1 = Standard_False;
1747 anApprox2 = Standard_False;
1749 tol2d = myTolApprox;
1752 if(myHS1 == myHS2) {
1753 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1754 rejectSurface = Standard_True;
1757 if(reApprox && !rejectSurface)
1758 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1760 Standard_Integer iDegMax, iDegMin, iNbIter;
1762 ApproxParameters(myHS1, myHS2, iDegMin, iDegMax, iNbIter);
1763 theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, iNbIter, Standard_True, aParType);
1767 Standard_Real aReachedTol = Precision::Confusion();
1768 bIsDecomposited=DecompositionOfWLine(WL,
1774 bAvoidLineConstructor,
1778 if ( bIsDecomposited && ( myTolReached3d < aReachedTol ) ) {
1779 myTolReached3d = aReachedTol;
1782 aNbSeqOfL=aSeqOfL.Length();
1784 if (bIsDecomposited) {
1790 if (!bAvoidLineConstructor) {
1791 aNbParts=myLConstruct.NbParts();
1796 for(i = 1; i <= nbiter; ++i) {
1797 if(bIsDecomposited) {
1798 WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i));
1800 ilprm = WL->NbPnts();
1803 if(bAvoidLineConstructor) {
1805 ilprm = WL->NbPnts();
1808 myLConstruct.Part(i, fprm, lprm);
1809 ifprm = (Standard_Integer)fprm;
1810 ilprm = (Standard_Integer)lprm;
1814 //-- Si une des surfaces est un plan , on approxime en 2d
1815 //-- sur cette surface et on remonte les points 2d en 3d.
1816 if(typs1 == GeomAbs_Plane) {
1817 theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm);
1819 else if(typs2 == GeomAbs_Plane) {
1820 theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm);
1824 if (myHS1 != myHS2){
1825 if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) &&
1826 (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) {
1828 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType);
1830 Standard_Boolean bUseSurfaces;
1831 bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm, ilprm);
1834 rejectSurface = Standard_True;
1836 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1841 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm);
1844 if (!theapp3d.IsDone()) {
1845 Handle(Geom2d_BSplineCurve) H1;
1846 Handle(Geom2d_BSplineCurve) H2;
1848 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
1851 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1855 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1858 IntTools_Curve aIC(aBSp, H1, H2);
1859 mySeqOfCurve.Append(aIC);
1863 if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) {
1864 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) {
1865 myTolReached2d = theapp3d.TolReached2d();
1868 if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) {
1869 myTolReached3d = myTolReached2d;
1871 if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
1872 if (myTolReached3d<1.e-6) {
1873 myTolReached3d = theapp3d.TolReached3d();
1874 myTolReached3d=1.e-6;
1878 else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) {
1879 myTolReached3d = theapp3d.TolReached3d();
1882 Standard_Integer aNbMultiCurves, nbpoles;
1883 aNbMultiCurves=theapp3d.NbMultiCurves();
1884 for (j=1; j<=aNbMultiCurves; j++) {
1885 if(typs1 == GeomAbs_Plane) {
1886 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1887 nbpoles = mbspc.NbPoles();
1889 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1890 TColgp_Array1OfPnt tpoles(1,nbpoles);
1892 mbspc.Curve(1,tpoles2d);
1893 const gp_Pln& Pln = myHS1->Surface().Plane();
1895 Standard_Integer ik;
1896 for(ik = 1; ik<= nbpoles; ik++) {
1898 ElSLib::Value(tpoles2d.Value(ik).X(),
1899 tpoles2d.Value(ik).Y(),
1903 Handle(Geom_BSplineCurve) BS =
1904 new Geom_BSplineCurve(tpoles,
1906 mbspc.Multiplicities(),
1908 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1909 Check.FixTangent(Standard_True, Standard_True);
1911 IntTools_Curve aCurve;
1912 aCurve.SetCurve(BS);
1915 Handle(Geom2d_BSplineCurve) BS1 =
1916 new Geom2d_BSplineCurve(tpoles2d,
1918 mbspc.Multiplicities(),
1920 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
1921 Check1.FixTangent(Standard_True,Standard_True);
1923 // ############################################
1924 if(!rejectSurface && !reApprox) {
1925 Standard_Boolean isValid = IsCurveValid(BS1);
1927 reApprox = Standard_True;
1931 // ############################################
1932 aCurve.SetFirstCurve2d(BS1);
1935 Handle(Geom2d_BSplineCurve) H1;
1936 aCurve.SetFirstCurve2d(H1);
1940 mbspc.Curve(2, tpoles2d);
1942 Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
1944 mbspc.Multiplicities(),
1946 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1947 newCheck.FixTangent(Standard_True,Standard_True);
1949 // ###########################################
1950 if(!rejectSurface && !reApprox) {
1951 Standard_Boolean isValid = IsCurveValid(BS2);
1953 reApprox = Standard_True;
1957 // ###########################################
1959 aCurve.SetSecondCurve2d(BS2);
1962 Handle(Geom2d_BSplineCurve) H2;
1964 aCurve.SetSecondCurve2d(H2);
1967 mySeqOfCurve.Append(aCurve);
1968 }//if(typs1 == GeomAbs_Plane) {
1970 else if(typs2 == GeomAbs_Plane) {
1971 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1972 nbpoles = mbspc.NbPoles();
1974 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1975 TColgp_Array1OfPnt tpoles(1,nbpoles);
1976 mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d);
1977 const gp_Pln& Pln = myHS2->Surface().Plane();
1979 Standard_Integer ik;
1980 for(ik = 1; ik<= nbpoles; ik++) {
1982 ElSLib::Value(tpoles2d.Value(ik).X(),
1983 tpoles2d.Value(ik).Y(),
1988 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1990 mbspc.Multiplicities(),
1992 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1993 Check.FixTangent(Standard_True,Standard_True);
1995 IntTools_Curve aCurve;
1996 aCurve.SetCurve(BS);
1999 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
2001 mbspc.Multiplicities(),
2003 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
2004 Check1.FixTangent(Standard_True,Standard_True);
2006 // ###########################################
2007 if(!rejectSurface && !reApprox) {
2008 Standard_Boolean isValid = IsCurveValid(BS1);
2010 reApprox = Standard_True;
2014 // ###########################################
2015 bPCurvesOk = CheckPCurve(BS1, myFace2);
2016 aCurve.SetSecondCurve2d(BS1);
2019 Handle(Geom2d_BSplineCurve) H2;
2020 aCurve.SetSecondCurve2d(H2);
2024 mbspc.Curve(1,tpoles2d);
2025 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
2027 mbspc.Multiplicities(),
2029 GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK);
2030 Check2.FixTangent(Standard_True,Standard_True);
2032 // ###########################################
2033 if(!rejectSurface && !reApprox) {
2034 Standard_Boolean isValid = IsCurveValid(BS2);
2036 reApprox = Standard_True;
2040 // ###########################################
2041 bPCurvesOk = bPCurvesOk && CheckPCurve(BS2, myFace1);
2042 aCurve.SetFirstCurve2d(BS2);
2045 Handle(Geom2d_BSplineCurve) H1;
2047 aCurve.SetFirstCurve2d(H1);
2050 //if points of the pcurves are out of the faces bounds
2051 //create 3d and 2d curves without approximation
2053 Handle(Geom2d_BSplineCurve) H1, H2;
2054 bPCurvesOk = Standard_True;
2056 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
2059 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
2060 bPCurvesOk = CheckPCurve(H1, myFace1);
2064 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
2065 bPCurvesOk = bPCurvesOk && CheckPCurve(H2, myFace2);
2068 //if pcurves created without approximation are out of the
2069 //faces bounds, use approximated 3d and 2d curves
2071 IntTools_Curve aIC(aBSp, H1, H2);
2072 mySeqOfCurve.Append(aIC);
2074 mySeqOfCurve.Append(aCurve);
2077 mySeqOfCurve.Append(aCurve);
2079 }// else if(typs2 == GeomAbs_Plane)
2081 else { //typs2 != GeomAbs_Plane && typs1 != GeomAbs_Plane
2082 Standard_Boolean bIsValid1, bIsValid2;
2083 Handle(Geom_BSplineCurve) BS;
2084 Handle(Geom2d_BSplineCurve) aH2D;
2085 IntTools_Curve aCurve;
2087 bIsValid1=Standard_True;
2088 bIsValid2=Standard_True;
2090 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2091 nbpoles = mbspc.NbPoles();
2092 TColgp_Array1OfPnt tpoles(1,nbpoles);
2093 mbspc.Curve(1,tpoles);
2094 BS=new Geom_BSplineCurve(tpoles,
2096 mbspc.Multiplicities(),
2098 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2099 Check.FixTangent(Standard_True,Standard_True);
2101 aCurve.SetCurve(BS);
2102 aCurve.SetFirstCurve2d(aH2D);
2103 aCurve.SetSecondCurve2d(aH2D);
2107 Handle(Geom2d_BSplineCurve) BS1;
2108 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2109 mbspc.Curve(2,tpoles2d);
2111 BS1=new Geom2d_BSplineCurve(tpoles2d,
2113 mbspc.Multiplicities(),
2115 GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK);
2116 newCheck.FixTangent(Standard_True,Standard_True);
2119 bIsValid1=CheckPCurve(BS1, myFace1);
2122 aCurve.SetFirstCurve2d(BS1);
2125 Handle(Geom2d_BSplineCurve) BS1;
2126 fprm = BS->FirstParameter();
2127 lprm = BS->LastParameter();
2129 Handle(Geom2d_Curve) C2d;
2130 Standard_Real aTol = myTolApprox;
2131 GeomInt_IntSS::BuildPCurves(fprm, lprm, aTol,
2132 myHS1->ChangeSurface().Surface(), BS, C2d);
2133 BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2134 aCurve.SetFirstCurve2d(BS1);
2136 } // if(myApprox1) {
2140 Handle(Geom2d_BSplineCurve) BS2;
2141 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2142 mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d);
2143 BS2=new Geom2d_BSplineCurve(tpoles2d,
2145 mbspc.Multiplicities(),
2147 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2148 newCheck.FixTangent(Standard_True,Standard_True);
2151 bIsValid2=CheckPCurve(BS2, myFace2);
2153 aCurve.SetSecondCurve2d(BS2);
2156 Handle(Geom2d_BSplineCurve) BS2;
2157 fprm = BS->FirstParameter();
2158 lprm = BS->LastParameter();
2160 Handle(Geom2d_Curve) C2d;
2161 Standard_Real aTol = myTolApprox;
2162 GeomInt_IntSS::BuildPCurves(fprm, lprm, aTol,
2163 myHS2->ChangeSurface().Surface(), BS, C2d);
2164 BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2165 aCurve.SetSecondCurve2d(BS2);
2168 if (!bIsValid1 || !bIsValid2) {
2169 myTolApprox=aTolApproxImp;//1.e-5;
2170 tol2d = myTolApprox;
2171 reApprox = Standard_True;
2175 mySeqOfCurve.Append(aCurve);
2181 }// case IntPatch_Walking:{
2184 case IntPatch_Restriction:
2186 Handle(IntPatch_RLine) RL =
2187 Handle(IntPatch_RLine)::DownCast(L);
2188 Handle(Geom_Curve) aC3d;
2189 Handle(Geom2d_Curve) aC2d1, aC2d2;
2190 Standard_Real aTolReached;
2191 GeomInt_IntSS::TreatRLine(RL, myHS1, myHS2, aC3d,
2192 aC2d1, aC2d2, aTolReached);
2197 Bnd_Box2d aBox1, aBox2;
2199 const Standard_Real aU1f = myHS1->FirstUParameter(),
2200 aV1f = myHS1->FirstVParameter(),
2201 aU1l = myHS1->LastUParameter(),
2202 aV1l = myHS1->LastVParameter();
2203 const Standard_Real aU2f = myHS2->FirstUParameter(),
2204 aV2f = myHS2->FirstVParameter(),
2205 aU2l = myHS2->LastUParameter(),
2206 aV2l = myHS2->LastVParameter();
2208 aBox1.Add(gp_Pnt2d(aU1f, aV1f));
2209 aBox1.Add(gp_Pnt2d(aU1l, aV1l));
2210 aBox2.Add(gp_Pnt2d(aU2f, aV2f));
2211 aBox2.Add(gp_Pnt2d(aU2l, aV2l));
2213 GeomInt_VectorOfReal anArrayOfParameters;
2215 //We consider here that the intersection line is same-parameter-line
2216 anArrayOfParameters.Append(aC3d->FirstParameter());
2217 anArrayOfParameters.Append(aC3d->LastParameter());
2220 TrimILineOnSurfBoundaries(aC2d1, aC2d2, aBox1, aBox2, anArrayOfParameters);
2222 const Standard_Integer aNbIntersSolutionsm1 = anArrayOfParameters.Length() - 1;
2225 for(Standard_Integer anInd = 0; anInd < aNbIntersSolutionsm1; anInd++)
2227 const Standard_Real aParF = anArrayOfParameters(anInd),
2228 aParL = anArrayOfParameters(anInd+1);
2230 if((aParL - aParF) <= Precision::PConfusion())
2233 const Standard_Real aPar = 0.5*(aParF + aParL);
2236 Handle(Geom2d_Curve) aCurv2d1, aCurv2d2;
2239 aC2d1->D0(aPar, aPt);
2241 if(aBox1.IsOut(aPt))
2245 aCurv2d1 = new Geom2d_TrimmedCurve(aC2d1, aParF, aParL);
2250 aC2d2->D0(aPar, aPt);
2252 if(aBox2.IsOut(aPt))
2256 aCurv2d2 = new Geom2d_TrimmedCurve(aC2d2, aParF, aParL);
2259 Handle(Geom_Curve) aCurv3d = new Geom_TrimmedCurve(aC3d, aParF, aParL);
2261 IntTools_Curve aIC(aCurv3d, aCurv2d1, aCurv2d2);
2262 mySeqOfCurve.Append(aIC);
2272 //=======================================================================
2273 //function : Parameters
2275 //=======================================================================
2276 void Parameters(const Handle(GeomAdaptor_HSurface)& HS1,
2277 const Handle(GeomAdaptor_HSurface)& HS2,
2278 const gp_Pnt& Ptref,
2285 IntSurf_Quadric quad1,quad2;
2286 GeomAbs_SurfaceType typs = HS1->Surface().GetType();
2290 quad1.SetValue(HS1->Surface().Plane());
2292 case GeomAbs_Cylinder:
2293 quad1.SetValue(HS1->Surface().Cylinder());
2296 quad1.SetValue(HS1->Surface().Cone());
2298 case GeomAbs_Sphere:
2299 quad1.SetValue(HS1->Surface().Sphere());
2302 quad1.SetValue(HS1->Surface().Torus());
2305 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2308 typs = HS2->Surface().GetType();
2311 quad2.SetValue(HS2->Surface().Plane());
2313 case GeomAbs_Cylinder:
2314 quad2.SetValue(HS2->Surface().Cylinder());
2317 quad2.SetValue(HS2->Surface().Cone());
2319 case GeomAbs_Sphere:
2320 quad2.SetValue(HS2->Surface().Sphere());
2323 quad2.SetValue(HS2->Surface().Torus());
2326 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2329 quad1.Parameters(Ptref,U1,V1);
2330 quad2.Parameters(Ptref,U2,V2);
2333 //=======================================================================
2334 //function : MakeBSpline
2336 //=======================================================================
2337 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL,
2338 const Standard_Integer ideb,
2339 const Standard_Integer ifin)
2341 Standard_Integer i,nbpnt = ifin-ideb+1;
2342 TColgp_Array1OfPnt poles(1,nbpnt);
2343 TColStd_Array1OfReal knots(1,nbpnt);
2344 TColStd_Array1OfInteger mults(1,nbpnt);
2345 Standard_Integer ipidebm1;
2346 for(i=1,ipidebm1=i+ideb-1; i<=nbpnt;ipidebm1++, i++) {
2347 poles(i) = WL->Point(ipidebm1).Value();
2351 mults(1) = mults(nbpnt) = 2;
2353 new Geom_BSplineCurve(poles,knots,mults,1);
2357 //=======================================================================
2358 //function : MakeBSpline2d
2360 //=======================================================================
2361 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
2362 const Standard_Integer ideb,
2363 const Standard_Integer ifin,
2364 const Standard_Boolean onFirst)
2366 Standard_Integer i, nbpnt = ifin-ideb+1;
2367 TColgp_Array1OfPnt2d poles(1,nbpnt);
2368 TColStd_Array1OfReal knots(1,nbpnt);
2369 TColStd_Array1OfInteger mults(1,nbpnt);
2370 Standard_Integer ipidebm1;
2372 for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) {
2375 theWLine->Point(ipidebm1).ParametersOnS1(U, V);
2377 theWLine->Point(ipidebm1).ParametersOnS2(U, V);
2378 poles(i).SetCoord(U, V);
2382 mults(1) = mults(nbpnt) = 2;
2384 return new Geom2d_BSplineCurve(poles,knots,mults,1);
2386 //=======================================================================
2387 //function : PrepareLines3D
2389 //=======================================================================
2390 void IntTools_FaceFace::PrepareLines3D(const Standard_Boolean bToSplit)
2392 Standard_Integer i, aNbCurves;
2393 GeomAbs_SurfaceType aType1, aType2;
2394 IntTools_SequenceOfCurves aNewCvs;
2396 // 1. Treatment closed curves
2397 aNbCurves=mySeqOfCurve.Length();
2398 for (i=1; i<=aNbCurves; ++i) {
2399 const IntTools_Curve& aIC=mySeqOfCurve(i);
2402 Standard_Integer j, aNbC;
2403 IntTools_SequenceOfCurves aSeqCvs;
2405 aNbC=IntTools_Tools::SplitCurve(aIC, aSeqCvs);
2407 for (j=1; j<=aNbC; ++j) {
2408 const IntTools_Curve& aICNew=aSeqCvs(j);
2409 aNewCvs.Append(aICNew);
2413 aNewCvs.Append(aIC);
2417 aNewCvs.Append(aIC);
2421 // 2. Plane\Cone intersection when we had 4 curves
2422 aType1=myHS1->GetType();
2423 aType2=myHS2->GetType();
2424 aNbCurves=aNewCvs.Length();
2426 if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone) ||
2427 (aType2==GeomAbs_Plane && aType1==GeomAbs_Cone)) {
2429 GeomAbs_CurveType aCType1;
2431 aCType1=aNewCvs(1).Type();
2432 if (aCType1==GeomAbs_Line) {
2433 IntTools_SequenceOfCurves aSeqIn, aSeqOut;
2435 for (i=1; i<=aNbCurves; ++i) {
2436 const IntTools_Curve& aIC=aNewCvs(i);
2440 IntTools_Tools::RejectLines(aSeqIn, aSeqOut);
2443 aNbCurves=aSeqOut.Length();
2444 for (i=1; i<=aNbCurves; ++i) {
2445 const IntTools_Curve& aIC=aSeqOut(i);
2446 aNewCvs.Append(aIC);
2450 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone)...
2452 // 3. Fill mySeqOfCurve
2453 mySeqOfCurve.Clear();
2454 aNbCurves=aNewCvs.Length();
2455 for (i=1; i<=aNbCurves; ++i) {
2456 const IntTools_Curve& aIC=aNewCvs(i);
2457 mySeqOfCurve.Append(aIC);
2460 //=======================================================================
2461 //function : CorrectSurfaceBoundaries
2463 //=======================================================================
2464 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
2465 const Standard_Real theTolerance,
2466 Standard_Real& theumin,
2467 Standard_Real& theumax,
2468 Standard_Real& thevmin,
2469 Standard_Real& thevmax)
2471 Standard_Boolean enlarge, isuperiodic, isvperiodic;
2472 Standard_Real uinf, usup, vinf, vsup, delta;
2473 GeomAbs_SurfaceType aType;
2474 Handle(Geom_Surface) aSurface;
2476 aSurface = BRep_Tool::Surface(theFace);
2477 aSurface->Bounds(uinf, usup, vinf, vsup);
2478 delta = theTolerance;
2479 enlarge = Standard_False;
2481 GeomAdaptor_Surface anAdaptorSurface(aSurface);
2483 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
2484 Handle(Geom_Surface) aBasisSurface =
2485 (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface))->BasisSurface();
2487 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2488 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2493 if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2494 Handle(Geom_Surface) aBasisSurface =
2495 (Handle(Geom_OffsetSurface)::DownCast(aSurface))->BasisSurface();
2497 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2498 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2503 isuperiodic = anAdaptorSurface.IsUPeriodic();
2504 isvperiodic = anAdaptorSurface.IsVPeriodic();
2506 aType=anAdaptorSurface.GetType();
2507 if((aType==GeomAbs_BezierSurface) ||
2508 (aType==GeomAbs_BSplineSurface) ||
2509 (aType==GeomAbs_SurfaceOfExtrusion) ||
2510 (aType==GeomAbs_SurfaceOfRevolution) ||
2511 (aType==GeomAbs_Cylinder)) {
2512 enlarge=Standard_True;
2515 if(!isuperiodic && enlarge) {
2517 if(!Precision::IsInfinite(theumin) &&
2518 ((theumin - uinf) > delta))
2524 if(!Precision::IsInfinite(theumax) &&
2525 ((usup - theumax) > delta))
2531 if(!isvperiodic && enlarge) {
2532 if(!Precision::IsInfinite(thevmin) &&
2533 ((thevmin - vinf) > delta)) {
2539 if(!Precision::IsInfinite(thevmax) &&
2540 ((vsup - thevmax) > delta)) {
2549 Standard_Integer aNbP;
2550 Standard_Real aXP, dXfact, aXmid, aX1, aX2, aTolPA;
2552 aTolPA=Precision::Angular();
2555 aXP=anAdaptorSurface.UPeriod();
2556 dXfact=theumax-theumin;
2557 if (dXfact-aTolPA>aXP) {
2558 aXmid=0.5*(theumax+theumin);
2559 aNbP=RealToInt(aXmid/aXP);
2564 if (theumin>aTolPA) {
2565 aX1=theumin+aNbP*aXP;
2578 aXP=anAdaptorSurface.VPeriod();
2579 dXfact=thevmax-thevmin;
2580 if (dXfact-aTolPA>aXP) {
2581 aXmid=0.5*(thevmax+thevmin);
2582 aNbP=RealToInt(aXmid/aXP);
2587 if (thevmin>aTolPA) {
2588 aX1=thevmin+aNbP*aXP;
2601 if(isuperiodic || isvperiodic) {
2602 Standard_Boolean correct = Standard_False;
2603 Standard_Boolean correctU = Standard_False;
2604 Standard_Boolean correctV = Standard_False;
2606 TopExp_Explorer anExp;
2608 for(anExp.Init(theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
2609 if(BRep_Tool::IsClosed(TopoDS::Edge(anExp.Current()), theFace)) {
2610 correct = Standard_True;
2612 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
2614 for(Standard_Integer i = 0; i < 2; i++) {
2616 anEdge.Orientation(TopAbs_FORWARD);
2619 anEdge.Orientation(TopAbs_REVERSED);
2621 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l);
2623 if(aCurve.IsNull()) {
2624 correct = Standard_False;
2627 Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve);
2629 if(aLine.IsNull()) {
2630 correct = Standard_False;
2633 gp_Dir2d anUDir(1., 0.);
2634 gp_Dir2d aVDir(0., 1.);
2635 Standard_Real anAngularTolerance = Precision::Angular();
2637 correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance);
2638 correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance);
2640 gp_Pnt2d pp1 = aCurve->Value(f);
2642 gp_Pnt2d pp2 = aCurve->Value(l);
2651 Standard_Real umin, vmin, umax, vmax;
2652 aBox.Get(umin, vmin, umax, vmax);
2654 if(isuperiodic && correctU) {
2659 if(theumax > umax) {
2663 if(isvperiodic && correctV) {
2675 // The block is dedicated to determine whether WLine [ifprm, ilprm]
2676 // crosses the degenerated zone on each given surface or not.
2677 // If Yes -> We will not use info about surfaces during approximation
2678 // because inside degenerated zone of the surface the approx. algo.
2679 // uses wrong values of normal, etc., and resulting curve will have
2680 // oscillations that we would not like to have.
2685 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2686 const Handle(Geom_Surface)& aS,
2687 const Standard_Integer iDir);
2689 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2690 const TopoDS_Face& aF1,
2691 const TopoDS_Face& aF2);
2692 //=======================================================================
2693 //function : NotUseSurfacesForApprox
2695 //=======================================================================
2696 Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1,
2697 const TopoDS_Face& aF2,
2698 const Handle(IntPatch_WLine)& WL,
2699 const Standard_Integer ifprm,
2700 const Standard_Integer ilprm)
2702 Standard_Boolean bPInDZ;
2704 Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve();
2706 const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm);
2707 bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2);
2712 const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm);
2713 bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2);
2717 //=======================================================================
2718 //function : IsPointInDegeneratedZone
2720 //=======================================================================
2721 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2722 const TopoDS_Face& aF1,
2723 const TopoDS_Face& aF2)
2726 Standard_Boolean bFlag=Standard_True;
2727 Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22;
2728 Standard_Real U1, V1, U2, V2, aDelta, aD;
2731 Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1);
2732 aS1->Bounds(US11, US12, VS11, VS12);
2733 GeomAdaptor_Surface aGAS1(aS1);
2735 Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2);
2736 aS1->Bounds(US21, US22, VS21, VS22);
2737 GeomAdaptor_Surface aGAS2(aS2);
2739 //const gp_Pnt& aP=aP2S.Value();
2740 aP2S.Parameters(U1, V1, U2, V2);
2744 aD=aGAS1.UResolution(aDelta);
2745 aP2d.SetCoord(U1, V1);
2746 if (fabs(U1-US11) < aD) {
2747 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2752 if (fabs(U1-US12) < aD) {
2753 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2758 aD=aGAS1.VResolution(aDelta);
2759 if (fabs(V1-VS11) < aDelta) {
2760 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2765 if (fabs(V1-VS12) < aDelta) {
2766 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2772 aD=aGAS2.UResolution(aDelta);
2773 aP2d.SetCoord(U2, V2);
2774 if (fabs(U2-US21) < aDelta) {
2775 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2780 if (fabs(U2-US22) < aDelta) {
2781 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2786 aD=aGAS2.VResolution(aDelta);
2787 if (fabs(V2-VS21) < aDelta) {
2788 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2793 if (fabs(V2-VS22) < aDelta) {
2794 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2802 //=======================================================================
2803 //function : IsDegeneratedZone
2805 //=======================================================================
2806 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2807 const Handle(Geom_Surface)& aS,
2808 const Standard_Integer iDir)
2810 Standard_Boolean bFlag=Standard_True;
2811 Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD;
2812 Standard_Real aXm, aYm, aXb, aYb, aXe, aYe;
2813 aS->Bounds(US1, US2, VS1, VS2);
2815 gp_Pnt aPm, aPb, aPe;
2820 aS->D0(aXm, aYm, aPm);
2837 aS->D0(aXb, aYb, aPb);
2838 aS->D0(aXe, aYe, aPe);
2840 d1=aPm.Distance(aPb);
2841 d2=aPm.Distance(aPe);
2842 if (d1 < dD && d2 < dD) {
2859 aS->D0(aXb, aYb, aPb);
2860 aS->D0(aXe, aYe, aPe);
2862 d1=aPm.Distance(aPb);
2863 d2=aPm.Distance(aPe);
2864 if (d1 < dD && d2 < dD) {
2872 //=========================================================================
2873 // static function : ComputePurgedWLine
2874 // purpose : Removes equal points (leave one of equal points) from theWLine
2875 // and recompute vertex parameters.
2876 // Returns new WLine or null WLine if the number
2877 // of the points is less than 2.
2878 //=========================================================================
2879 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine) {
2881 Standard_Integer i, k, v, nb, nbvtx;
2882 Handle(IntPatch_WLine) aResult;
2883 nbvtx = theWLine->NbVertex();
2884 nb = theWLine->NbPnts();
2886 const IntSurf_PntOn2S& p1 = theWLine->Point(1);
2887 const IntSurf_PntOn2S& p2 = theWLine->Point(2);
2888 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
2893 Handle(IntPatch_WLine) aLocalWLine;
2894 Handle(IntPatch_WLine) aTmpWLine = theWLine;
2895 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
2896 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2897 for(i = 1; i <= nb; i++) {
2898 aLineOn2S->Add(theWLine->Point(i));
2901 for(v = 1; v <= nbvtx; v++) {
2902 aLocalWLine->AddVertex(theWLine->Vertex(v));
2905 for(i = 1; i <= aLineOn2S->NbPoints(); i++) {
2906 Standard_Integer aStartIndex = i + 1;
2907 Standard_Integer anEndIndex = i + 5;
2908 nb = aLineOn2S->NbPoints();
2909 anEndIndex = (anEndIndex > nb) ? nb : anEndIndex;
2911 if((aStartIndex > nb) || (anEndIndex <= 1)) {
2916 while(k <= anEndIndex) {
2919 IntSurf_PntOn2S p1 = aLineOn2S->Value(i);
2920 IntSurf_PntOn2S p2 = aLineOn2S->Value(k);
2922 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
2923 aTmpWLine = aLocalWLine;
2924 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2926 for(v = 1; v <= aTmpWLine->NbVertex(); v++) {
2927 IntPatch_Point aVertex = aTmpWLine->Vertex(v);
2928 Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine();
2930 if(avertexindex >= k) {
2931 aVertex.SetParameter(aVertex.ParameterOnLine() - 1.);
2933 aLocalWLine->AddVertex(aVertex);
2935 aLineOn2S->RemovePoint(k);
2944 if(aLineOn2S->NbPoints() > 1) {
2945 aResult = aLocalWLine;
2950 //=======================================================================
2953 //=======================================================================
2954 void TolR3d(const TopoDS_Face& aF1,
2955 const TopoDS_Face& aF2,
2956 Standard_Real& myTolReached3d)
2958 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
2960 aTolTresh=2.999999e-3;
2961 aTolF1 = BRep_Tool::Tolerance(aF1);
2962 aTolF2 = BRep_Tool::Tolerance(aF2);
2963 aTolFMax=Max(aTolF1, aTolF2);
2965 if (aTolFMax>aTolTresh) {
2966 myTolReached3d=aTolFMax;
2969 //=======================================================================
2970 //function : IsPointOnBoundary
2972 //=======================================================================
2973 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
2974 const Standard_Real theFirstBoundary,
2975 const Standard_Real theSecondBoundary,
2976 const Standard_Real theResolution,
2977 Standard_Boolean& IsOnFirstBoundary)
2979 Standard_Boolean bRet;
2981 Standard_Real adist;
2983 bRet=Standard_False;
2984 for(i = 0; i < 2; ++i) {
2985 IsOnFirstBoundary = (i == 0);
2986 if (IsOnFirstBoundary) {
2987 adist = fabs(theParameter - theFirstBoundary);
2990 adist = fabs(theParameter - theSecondBoundary);
2992 if(adist < theResolution) {
2998 // ------------------------------------------------------------------------------------------------
2999 // static function: FindPoint
3001 // ------------------------------------------------------------------------------------------------
3002 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3003 const gp_Pnt2d& theLastPoint,
3004 const Standard_Real theUmin,
3005 const Standard_Real theUmax,
3006 const Standard_Real theVmin,
3007 const Standard_Real theVmax,
3008 gp_Pnt2d& theNewPoint) {
3010 gp_Vec2d aVec(theFirstPoint, theLastPoint);
3011 Standard_Integer i = 0, j = 0;
3013 for(i = 0; i < 4; i++) {
3014 gp_Vec2d anOtherVec;
3015 gp_Vec2d anOtherVecNormal;
3016 gp_Pnt2d aprojpoint = theLastPoint;
3019 anOtherVec.SetX(0.);
3020 anOtherVec.SetY(1.);
3021 anOtherVecNormal.SetX(1.);
3022 anOtherVecNormal.SetY(0.);
3025 aprojpoint.SetX(theUmin);
3027 aprojpoint.SetX(theUmax);
3030 anOtherVec.SetX(1.);
3031 anOtherVec.SetY(0.);
3032 anOtherVecNormal.SetX(0.);
3033 anOtherVecNormal.SetY(1.);
3036 aprojpoint.SetY(theVmin);
3038 aprojpoint.SetY(theVmax);
3040 gp_Vec2d anormvec = aVec;
3041 anormvec.Normalize();
3042 RefineVector(anormvec);
3043 Standard_Real adot1 = anormvec.Dot(anOtherVecNormal);
3045 if(fabs(adot1) < Precision::Angular())
3047 Standard_Real adist = 0.;
3048 Standard_Boolean bIsOut = Standard_False;
3051 adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax);
3052 bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax);
3055 adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax);
3056 bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax);
3058 Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1;
3060 for(j = 0; j < 2; j++) {
3061 anoffset = (j == 0) ? anoffset : -anoffset;
3062 gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset));
3063 gp_Vec2d acurvec(theLastPoint, acurpoint);
3067 Standard_Real aDotX, anAngleX;
3069 aDotX = aVec.Dot(acurvec);
3070 anAngleX = aVec.Angle(acurvec);
3072 if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) {
3074 if((acurpoint.Y() >= theVmin) &&
3075 (acurpoint.Y() <= theVmax)) {
3076 theNewPoint = acurpoint;
3077 return Standard_True;
3081 if((acurpoint.X() >= theUmin) &&
3082 (acurpoint.X() <= theUmax)) {
3083 theNewPoint = acurpoint;
3084 return Standard_True;
3090 return Standard_False;
3094 // ------------------------------------------------------------------------------------------------
3095 // static function: FindPoint
3096 // purpose: Find point on the boundary of radial tangent zone
3097 // ------------------------------------------------------------------------------------------------
3098 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3099 const gp_Pnt2d& theLastPoint,
3100 const Standard_Real theUmin,
3101 const Standard_Real theUmax,
3102 const Standard_Real theVmin,
3103 const Standard_Real theVmax,
3104 const gp_Pnt2d& theTanZoneCenter,
3105 const Standard_Real theZoneRadius,
3106 Handle(GeomAdaptor_HSurface) theGASurface,
3107 gp_Pnt2d& theNewPoint) {
3108 theNewPoint = theLastPoint;
3110 if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) )
3111 return Standard_False;
3113 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3114 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3116 Standard_Real aRadius = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3117 gp_Ax22d anAxis( theTanZoneCenter, gp_Dir2d(1, 0), gp_Dir2d(0, 1) );
3118 gp_Circ2d aCircle( anAxis, aRadius );
3121 gp_Vec2d aDir( theLastPoint.XY() - theFirstPoint.XY() );
3122 Standard_Real aLength = aDir.Magnitude();
3123 if ( aLength <= gp::Resolution() )
3124 return Standard_False;
3125 gp_Lin2d aLine( theFirstPoint, aDir );
3128 Handle(Geom2d_Line) aCLine = new Geom2d_Line( aLine );
3129 Handle(Geom2d_TrimmedCurve) aC1 = new Geom2d_TrimmedCurve( aCLine, 0, aLength );
3130 Handle(Geom2d_Circle) aC2 = new Geom2d_Circle( aCircle );
3132 Standard_Real aTol = aRadius * 0.001;
3133 aTol = ( aTol < Precision::PConfusion() ) ? Precision::PConfusion() : aTol;
3135 Geom2dAPI_InterCurveCurve anIntersector;
3136 anIntersector.Init( aC1, aC2, aTol );
3138 if ( anIntersector.NbPoints() == 0 )
3139 return Standard_False;
3141 Standard_Boolean aFound = Standard_False;
3142 Standard_Real aMinDist = aLength * aLength;
3143 Standard_Integer i = 0;
3144 for ( i = 1; i <= anIntersector.NbPoints(); i++ ) {
3145 gp_Pnt2d aPInt = anIntersector.Point( i );
3146 if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) {
3147 if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) &&
3148 ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) {
3149 theNewPoint = aPInt;
3150 aFound = Standard_True;
3158 // ------------------------------------------------------------------------------------------------
3159 // static function: IsInsideTanZone
3160 // purpose: Check if point is inside a radial tangent zone
3161 // ------------------------------------------------------------------------------------------------
3162 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
3163 const gp_Pnt2d& theTanZoneCenter,
3164 const Standard_Real theZoneRadius,
3165 Handle(GeomAdaptor_HSurface) theGASurface) {
3167 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3168 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3169 Standard_Real aRadiusSQR = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3170 aRadiusSQR *= aRadiusSQR;
3171 if ( thePoint.SquareDistance( theTanZoneCenter ) <= aRadiusSQR )
3172 return Standard_True;
3173 return Standard_False;
3176 // ------------------------------------------------------------------------------------------------
3177 // static function: CheckTangentZonesExist
3178 // purpose: Check if tangent zone exists
3179 // ------------------------------------------------------------------------------------------------
3180 Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& theSurface1,
3181 const Handle(GeomAdaptor_HSurface)& theSurface2 )
3183 if ( ( theSurface1->GetType() != GeomAbs_Torus ) ||
3184 ( theSurface2->GetType() != GeomAbs_Torus ) )
3185 return Standard_False;
3187 gp_Torus aTor1 = theSurface1->Torus();
3188 gp_Torus aTor2 = theSurface2->Torus();
3190 if ( aTor1.Location().Distance( aTor2.Location() ) > Precision::Confusion() )
3191 return Standard_False;
3193 if ( ( fabs( aTor1.MajorRadius() - aTor2.MajorRadius() ) > Precision::Confusion() ) ||
3194 ( fabs( aTor1.MinorRadius() - aTor2.MinorRadius() ) > Precision::Confusion() ) )
3195 return Standard_False;
3197 if ( ( aTor1.MajorRadius() < aTor1.MinorRadius() ) ||
3198 ( aTor2.MajorRadius() < aTor2.MinorRadius() ) )
3199 return Standard_False;
3200 return Standard_True;
3203 // ------------------------------------------------------------------------------------------------
3204 // static function: ComputeTangentZones
3206 // ------------------------------------------------------------------------------------------------
3207 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
3208 const Handle(GeomAdaptor_HSurface)& theSurface2,
3209 const TopoDS_Face& theFace1,
3210 const TopoDS_Face& theFace2,
3211 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
3212 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
3213 Handle(TColStd_HArray1OfReal)& theResultRadius,
3214 const Handle(IntTools_Context)& aContext)
3216 Standard_Integer aResult = 0;
3217 if ( !CheckTangentZonesExist( theSurface1, theSurface2 ) )
3221 TColgp_SequenceOfPnt2d aSeqResultS1, aSeqResultS2;
3222 TColStd_SequenceOfReal aSeqResultRad;
3224 gp_Torus aTor1 = theSurface1->Torus();
3225 gp_Torus aTor2 = theSurface2->Torus();
3227 gp_Ax2 anax1( aTor1.Location(), aTor1.Axis().Direction() );
3228 gp_Ax2 anax2( aTor2.Location(), aTor2.Axis().Direction() );
3229 Standard_Integer j = 0;
3231 for ( j = 0; j < 2; j++ ) {
3232 Standard_Real aCoef = ( j == 0 ) ? -1 : 1;
3233 Standard_Real aRadius1 = fabs(aTor1.MajorRadius() + aCoef * aTor1.MinorRadius());
3234 Standard_Real aRadius2 = fabs(aTor2.MajorRadius() + aCoef * aTor2.MinorRadius());
3236 gp_Circ aCircle1( anax1, aRadius1 );
3237 gp_Circ aCircle2( anax2, aRadius2 );
3239 // roughly compute radius of tangent zone for perpendicular case
3240 Standard_Real aCriteria = Precision::Confusion() * 0.5;
3242 Standard_Real aT1 = aCriteria;
3243 Standard_Real aT2 = aCriteria;
3245 // internal tangency
3246 Standard_Real aR = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3247 //aT1 = aCriteria * aCriteria + aR * aR - ( aR - aCriteria ) * ( aR - aCriteria );
3248 aT1 = 2. * aR * aCriteria;
3252 // external tangency
3253 Standard_Real aRb = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3254 Standard_Real aRm = ( aRadius1 < aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3255 Standard_Real aDelta = aRb - aCriteria;
3257 aDelta -= aRm * aRm;
3258 aDelta /= 2. * (aRb - aRm);
3259 aDelta -= 0.5 * (aRb - aRm);
3261 aT1 = 2. * aRm * (aRm - aDelta);
3264 aCriteria = ( aT1 > aT2) ? aT1 : aT2;
3265 if ( aCriteria > 0 )
3266 aCriteria = sqrt( aCriteria );
3268 if ( aCriteria > 0.5 * aTor1.MinorRadius() ) {
3269 // too big zone -> drop to minimum
3270 aCriteria = Precision::Confusion();
3273 GeomAdaptor_Curve aC1( new Geom_Circle(aCircle1) );
3274 GeomAdaptor_Curve aC2( new Geom_Circle(aCircle2) );
3275 Extrema_ExtCC anExtrema(aC1, aC2, 0, 2. * M_PI, 0, 2. * M_PI,
3276 Precision::PConfusion(), Precision::PConfusion());
3278 if ( anExtrema.IsDone() ) {
3280 Standard_Integer i = 0;
3281 for ( i = 1; i <= anExtrema.NbExt(); i++ ) {
3282 if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria )
3285 Extrema_POnCurv P1, P2;
3286 anExtrema.Points( i, P1, P2 );
3288 Standard_Boolean bFoundResult = Standard_True;
3291 Standard_Integer surfit = 0;
3292 for ( surfit = 0; surfit < 2; surfit++ ) {
3293 GeomAPI_ProjectPointOnSurf& aProjector =
3294 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3296 gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value();
3297 aProjector.Perform(aP3d);
3299 if(!aProjector.IsDone())
3300 bFoundResult = Standard_False;
3302 if(aProjector.LowerDistance() > aCriteria) {
3303 bFoundResult = Standard_False;
3306 Standard_Real foundU = 0, foundV = 0;
3307 aProjector.LowerDistanceParameters(foundU, foundV);
3309 pr1 = gp_Pnt2d( foundU, foundV );
3311 pr2 = gp_Pnt2d( foundU, foundV );
3315 if ( bFoundResult ) {
3316 aSeqResultS1.Append( pr1 );
3317 aSeqResultS2.Append( pr2 );
3318 aSeqResultRad.Append( aCriteria );
3320 // torus is u and v periodic
3321 const Standard_Real twoPI = M_PI + M_PI;
3322 Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()};
3323 Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()};
3325 // iteration on period bounds
3326 for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) {
3327 Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI;
3328 Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI;
3330 // iteration on surfaces
3331 for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) {
3332 Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp;
3333 Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp;
3334 TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2;
3335 TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2;
3337 if (fabs(arr1[0] - aBound) < Precision::PConfusion()) {
3338 aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) );
3339 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3340 aSeqResultRad.Append( aCriteria );
3342 if (fabs(arr1[1] - aBound) < Precision::PConfusion()) {
3343 aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) );
3344 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3345 aSeqResultRad.Append( aCriteria );
3353 aResult = aSeqResultRad.Length();
3355 if ( aResult > 0 ) {
3356 theResultOnS1 = new TColgp_HArray1OfPnt2d( 1, aResult );
3357 theResultOnS2 = new TColgp_HArray1OfPnt2d( 1, aResult );
3358 theResultRadius = new TColStd_HArray1OfReal( 1, aResult );
3360 for ( Standard_Integer i = 1 ; i <= aResult; i++ ) {
3361 theResultOnS1->SetValue( i, aSeqResultS1.Value(i) );
3362 theResultOnS2->SetValue( i, aSeqResultS2.Value(i) );
3363 theResultRadius->SetValue( i, aSeqResultRad.Value(i) );
3369 // ------------------------------------------------------------------------------------------------
3370 // static function: AdjustByNeighbour
3372 // ------------------------------------------------------------------------------------------------
3373 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
3374 const gp_Pnt2d& theOriginalPoint,
3375 Handle(GeomAdaptor_HSurface) theGASurface) {
3377 gp_Pnt2d ap1 = theaNeighbourPoint;
3378 gp_Pnt2d ap2 = theOriginalPoint;
3380 if ( theGASurface->IsUPeriodic() ) {
3381 Standard_Real aPeriod = theGASurface->UPeriod();
3382 gp_Pnt2d aPTest = ap2;
3383 Standard_Real aSqDistMin = 1.e+100;
3385 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3386 aPTest.SetX( theOriginalPoint.X() + aPeriod * pIt );
3387 Standard_Real dd = ap1.SquareDistance( aPTest );
3389 if ( dd < aSqDistMin ) {
3395 if ( theGASurface->IsVPeriodic() ) {
3396 Standard_Real aPeriod = theGASurface->VPeriod();
3397 gp_Pnt2d aPTest = ap2;
3398 Standard_Real aSqDistMin = 1.e+100;
3400 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3401 aPTest.SetY( theOriginalPoint.Y() + aPeriod * pIt );
3402 Standard_Real dd = ap1.SquareDistance( aPTest );
3404 if ( dd < aSqDistMin ) {
3413 // ------------------------------------------------------------------------------------------------
3414 //function: DecompositionOfWLine
3416 // ------------------------------------------------------------------------------------------------
3417 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
3418 const Handle(GeomAdaptor_HSurface)& theSurface1,
3419 const Handle(GeomAdaptor_HSurface)& theSurface2,
3420 const TopoDS_Face& theFace1,
3421 const TopoDS_Face& theFace2,
3422 const GeomInt_LineConstructor& theLConstructor,
3423 const Standard_Boolean theAvoidLConstructor,
3424 IntPatch_SequenceOfLine& theNewLines,
3425 Standard_Real& theReachedTol3d,
3426 const Handle(IntTools_Context)& aContext)
3429 Standard_Boolean bRet, bAvoidLineConstructor;
3430 Standard_Integer aNbPnts, aNbParts;
3432 bRet=Standard_False;
3433 aNbPnts=theWLine->NbPnts();
3434 bAvoidLineConstructor=theAvoidLConstructor;
3439 if (!bAvoidLineConstructor) {
3440 aNbParts=theLConstructor.NbParts();
3446 Standard_Boolean bIsPrevPointOnBoundary, bIsPointOnBoundary, bIsCurrentPointOnBoundary;
3447 Standard_Integer nblines, pit, i, j;
3449 TColStd_Array1OfListOfInteger anArrayOfLines(1, aNbPnts);
3450 TColStd_Array1OfInteger anArrayOfLineType(1, aNbPnts);
3451 TColStd_ListOfInteger aListOfPointIndex;
3453 Handle(TColgp_HArray1OfPnt2d) aTanZoneS1;
3454 Handle(TColgp_HArray1OfPnt2d) aTanZoneS2;
3455 Handle(TColStd_HArray1OfReal) aTanZoneRadius;
3456 Standard_Integer aNbZone = ComputeTangentZones( theSurface1, theSurface2, theFace1, theFace2,
3457 aTanZoneS1, aTanZoneS2, aTanZoneRadius, aContext);
3461 aTol=Precision::Confusion();
3463 bIsPrevPointOnBoundary=Standard_False;
3464 bIsPointOnBoundary=Standard_False;
3469 for(pit = 1; pit <= aNbPnts; ++pit) {
3470 Standard_Boolean bIsOnFirstBoundary, isperiodic;
3471 Standard_Real aResolution, aPeriod, alowerboundary, aupperboundary, U, V;
3472 Standard_Real aParameter, anoffset, anAdjustPar;
3473 Standard_Real umin, umax, vmin, vmax;
3475 bIsCurrentPointOnBoundary = Standard_False;
3476 const IntSurf_PntOn2S& aPoint = theWLine->Point(pit);
3479 for(i = 0; i < 2; ++i) {
3480 Handle(GeomAdaptor_HSurface) aGASurface = (!i) ? theSurface1 : theSurface2;
3481 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3483 aPoint.ParametersOnS1(U, V);
3486 aPoint.ParametersOnS2(U, V);
3489 for(j = 0; j < 2; j++) {
3490 isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3496 aResolution=aGASurface->UResolution(aTol);
3497 aPeriod=aGASurface->UPeriod();
3498 alowerboundary=umin;
3499 aupperboundary=umax;
3503 aResolution=aGASurface->VResolution(aTol);
3504 aPeriod=aGASurface->VPeriod();
3505 alowerboundary=vmin;
3506 aupperboundary=vmax;
3510 GeomInt::AdjustPeriodic(aParameter,
3517 bIsOnFirstBoundary = Standard_True;// ?
3519 IsPointOnBoundary(anAdjustPar,
3523 bIsOnFirstBoundary);
3525 if(bIsPointOnBoundary) {
3526 bIsCurrentPointOnBoundary = Standard_True;
3530 // check if a point belong to a tangent zone. Begin
3531 Standard_Integer zIt = 0;
3532 for ( zIt = 1; zIt <= aNbZone; zIt++ ) {
3533 gp_Pnt2d aPZone = (i == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3534 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3536 if ( IsInsideTanZone(gp_Pnt2d( U, V ), aPZone, aZoneRadius, aGASurface ) ) {
3537 // set boundary flag to split the curve by a tangent zone
3538 bIsPointOnBoundary = Standard_True;
3539 bIsCurrentPointOnBoundary = Standard_True;
3540 if ( theReachedTol3d < aZoneRadius ) {
3541 theReachedTol3d = aZoneRadius;
3547 }//for(j = 0; j < 2; j++) {
3549 if(bIsCurrentPointOnBoundary){
3552 }//for(i = 0; i < 2; ++i) {
3554 if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) {
3555 if(!aListOfPointIndex.IsEmpty()) {
3557 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3558 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3559 aListOfPointIndex.Clear();
3561 bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary;
3563 aListOfPointIndex.Append(pit);
3564 } //for(pit = 1; pit <= aNbPnts; ++pit) {
3566 if(!aListOfPointIndex.IsEmpty()) {
3568 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3569 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3570 aListOfPointIndex.Clear();
3574 return bRet; //Standard_False;
3578 // 2. Correct wlines.begin
3579 TColStd_Array1OfListOfInteger anArrayOfLineEnds(1, nblines);
3580 Handle(IntSurf_LineOn2S) aSeqOfPntOn2S = new IntSurf_LineOn2S();
3582 for(i = 1; i <= nblines; i++) {
3583 if(anArrayOfLineType.Value(i) != 0) {
3586 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3587 TColStd_ListOfInteger aListOfFLIndex;
3589 for(j = 0; j < 2; j++) {
3590 Standard_Integer aneighbourindex = (j == 0) ? (i - 1) : (i + 1);
3592 if((aneighbourindex < 1) || (aneighbourindex > nblines))
3595 if(anArrayOfLineType.Value(aneighbourindex) == 0)
3597 const TColStd_ListOfInteger& aNeighbour = anArrayOfLines.Value(aneighbourindex);
3598 Standard_Integer anIndex = (j == 0) ? aNeighbour.Last() : aNeighbour.First();
3599 const IntSurf_PntOn2S& aPoint = theWLine->Point(anIndex);
3601 IntSurf_PntOn2S aNewP = aPoint;
3602 if(aListOfIndex.Extent() < 2) {
3603 aSeqOfPntOn2S->Add(aNewP);
3604 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
3608 Standard_Integer iFirst = aListOfIndex.First();
3609 Standard_Integer iLast = aListOfIndex.Last();
3611 for(Standard_Integer surfit = 0; surfit < 2; surfit++) {
3613 Handle(GeomAdaptor_HSurface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2;
3614 Standard_Real umin=0., umax=0., vmin=0., vmax=0.;
3615 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3616 Standard_Real U=0., V=0.;
3619 aNewP.ParametersOnS1(U, V);
3621 aNewP.ParametersOnS2(U, V);
3622 Standard_Integer nbboundaries = 0;
3624 Standard_Boolean bIsNearBoundary = Standard_False;
3625 Standard_Integer aZoneIndex = 0;
3626 Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1
3627 Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1
3630 for(Standard_Integer parit = 0; parit < 2; parit++) {
3631 Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3633 Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
3634 Standard_Real alowerboundary = (parit == 0) ? umin : vmin;
3635 Standard_Real aupperboundary = (parit == 0) ? umax : vmax;
3637 Standard_Real aParameter = (parit == 0) ? U : V;
3638 Standard_Boolean bIsOnFirstBoundary = Standard_True;
3642 IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3643 if(bIsPointOnBoundary) {
3644 bIsUBoundary = (parit == 0);
3645 bIsFirstBoundary = bIsOnFirstBoundary;
3650 Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3651 Standard_Real anoffset, anAdjustPar;
3652 GeomInt::AdjustPeriodic(aParameter, alowerboundary, aupperboundary,
3653 aPeriod, anAdjustPar, anoffset);
3656 IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3657 if(bIsPointOnBoundary) {
3658 bIsUBoundary = (parit == 0);
3659 bIsFirstBoundary = bIsOnFirstBoundary;
3663 //check neighbourhood of boundary
3664 Standard_Real anEpsilon = aResolution * 100.;
3665 Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
3666 anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
3668 bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary,
3669 anEpsilon, bIsOnFirstBoundary);
3675 // check if a point belong to a tangent zone. Begin
3676 for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) {
3677 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3678 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3680 Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast;
3681 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3682 Standard_Real nU1, nV1;
3685 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3687 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3688 gp_Pnt2d ap1(nU1, nV1);
3689 gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface );
3692 if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) {
3694 bIsNearBoundary = Standard_True;
3695 if ( theReachedTol3d < aZoneRadius ) {
3696 theReachedTol3d = aZoneRadius;
3700 // check if a point belong to a tangent zone. End
3701 Standard_Boolean bComputeLineEnd = Standard_False;
3703 if(nbboundaries == 2) {
3705 bComputeLineEnd = Standard_True;
3708 else if(nbboundaries == 1) {
3709 Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3712 Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
3713 Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
3714 Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3715 Standard_Real aParameter = (bIsUBoundary) ? U : V;
3716 Standard_Real anoffset, anAdjustPar;
3717 GeomInt::AdjustPeriodic(aParameter, alowerboundary, aupperboundary,
3718 aPeriod, anAdjustPar, anoffset);
3720 Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
3721 Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
3722 anotherPar += anoffset;
3723 Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3724 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
3725 Standard_Real nU1, nV1;
3728 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3730 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3732 Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
3733 Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
3734 bComputeLineEnd = Standard_True;
3735 Standard_Boolean bCheckAngle1 = Standard_False;
3736 Standard_Boolean bCheckAngle2 = Standard_False;
3738 Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
3739 Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
3741 if(((adist1 - adist2) > Precision::PConfusion()) &&
3742 (adist2 < (aPeriod / 4.))) {
3743 bCheckAngle1 = Standard_True;
3744 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
3746 if(aNewVec.SquareMagnitude() < gp::Resolution()) {
3747 aNewP.SetValue((surfit == 0), anewU, anewV);
3748 bCheckAngle1 = Standard_False;
3751 else if(adist1 < (aPeriod / 4.)) {
3752 bCheckAngle2 = Standard_True;
3753 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
3755 if(aNewVec.SquareMagnitude() < gp::Resolution()) {
3756 bCheckAngle2 = Standard_False;
3760 if(bCheckAngle1 || bCheckAngle2) {
3761 // assume there are at least two points in line (see "if" above)
3762 Standard_Integer anindexother = aneighbourpointindex;
3764 while((anindexother <= iLast) && (anindexother >= iFirst)) {
3765 anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
3766 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
3767 Standard_Real nU2, nV2;
3770 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3772 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3773 gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
3775 if(aVecOld.SquareMagnitude() <= gp::Resolution()) {
3779 Standard_Real anAngle = aNewVec.Angle(aVecOld);
3781 if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
3784 Standard_Real U1, U2, V1, V2;
3785 IntSurf_PntOn2S atmppoint = aNewP;
3786 atmppoint.SetValue((surfit == 0), anewU, anewV);
3787 atmppoint.Parameters(U1, V1, U2, V2);
3788 gp_Pnt P1 = theSurface1->Value(U1, V1);
3789 gp_Pnt P2 = theSurface2->Value(U2, V2);
3790 gp_Pnt P0 = aPoint.Value();
3792 if(P0.IsEqual(P1, aTol) &&
3793 P0.IsEqual(P2, aTol) &&
3794 P1.IsEqual(P2, aTol)) {
3795 bComputeLineEnd = Standard_False;
3796 aNewP.SetValue((surfit == 0), anewU, anewV);
3801 bComputeLineEnd = Standard_False;
3806 } // end while(anindexother...)
3810 else if ( bIsNearBoundary ) {
3811 bComputeLineEnd = Standard_True;
3814 if(bComputeLineEnd) {
3817 Standard_Boolean found = Standard_False;
3819 if ( bIsNearBoundary ) {
3820 // re-compute point near natural boundary or near tangent zone
3821 Standard_Real u1, v1, u2, v2;
3822 aNewP.Parameters( u1, v1, u2, v2 );
3824 anewpoint = gp_Pnt2d( u1, v1 );
3826 anewpoint = gp_Pnt2d( u2, v2 );
3828 Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast;
3829 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3830 Standard_Real nU1, nV1;
3833 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3835 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3836 gp_Pnt2d ap1(nU1, nV1);
3841 // exclude point from a tangent zone
3842 anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3843 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex);
3844 Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex);
3846 if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax,
3847 aPZone, aZoneRadius, aGASurface, ap2) ) {
3849 found = Standard_True;
3852 else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
3853 // re-compute point near boundary if shifted on a period
3854 ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3856 if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
3857 ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
3858 found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
3862 aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
3868 Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast;
3869 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3870 Standard_Real nU1, nV1;
3873 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3875 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3876 gp_Pnt2d ap1(nU1, nV1);
3877 gp_Pnt2d ap2(nU1, nV1);
3878 Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
3880 while((aneighbourpointindex2 <= iLast) && (aneighbourpointindex2 >= iFirst)) {
3881 aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
3882 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
3883 Standard_Real nU2, nV2;
3886 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3888 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3892 if(ap1.SquareDistance(ap2) > gp::Resolution()) {
3896 found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
3901 Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
3902 GeomAPI_ProjectPointOnSurf& aProjector =
3903 (surfit == 0) ? aContext->ProjPS(theFace2) : aContext->ProjPS(theFace1);
3904 Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
3906 Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
3908 gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
3909 aProjector.Perform(aP3d);
3911 if(aProjector.IsDone()) {
3912 if(aProjector.LowerDistance() < aCriteria) {
3913 Standard_Real foundU = U, foundV = V;
3914 aProjector.LowerDistanceParameters(foundU, foundV);
3916 //Correction of projected coordinates. Begin
3917 //Note, it may be shifted on a period
3918 Standard_Integer aneindex1 = (j == 0) ? iFirst : iLast;
3919 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
3920 Standard_Real nUn, nVn;
3923 aNeighbourPoint.ParametersOnS2(nUn, nVn);
3925 aNeighbourPoint.ParametersOnS1(nUn, nVn);
3926 gp_Pnt2d aNeighbour2d(nUn, nVn);
3927 gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
3928 foundU = anAdjustedPoint.X();
3929 foundV = anAdjustedPoint.Y();
3931 if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
3932 ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
3933 // attempt to roughly re-compute point
3934 foundU = ( foundU < umin ) ? umin : foundU;
3935 foundU = ( foundU > umax ) ? umax : foundU;
3936 foundV = ( foundV < vmin ) ? vmin : foundV;
3937 foundV = ( foundV > vmax ) ? vmax : foundV;
3939 GeomAPI_ProjectPointOnSurf& aProjector2 =
3940 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3942 aP3d = aSurfaceOther->Value(foundU, foundV);
3943 aProjector2.Perform(aP3d);
3945 if(aProjector2.IsDone()) {
3946 if(aProjector2.LowerDistance() < aCriteria) {
3947 Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
3948 aProjector2.LowerDistanceParameters(foundU2, foundV2);
3949 anewpoint.SetX(foundU2);
3950 anewpoint.SetY(foundV2);
3954 //Correction of projected coordinates. End
3957 aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
3959 aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
3965 aSeqOfPntOn2S->Add(aNewP);
3966 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
3968 anArrayOfLineEnds.SetValue(i, aListOfFLIndex);
3970 // Correct wlines.end
3972 // Split wlines.begin
3973 Standard_Integer nbiter;
3976 if (!bAvoidLineConstructor) {
3977 nbiter=theLConstructor.NbParts();
3980 for(j = 1; j <= nbiter; ++j) {
3981 Standard_Real fprm, lprm;
3982 Standard_Integer ifprm, ilprm;
3984 if(bAvoidLineConstructor) {
3986 ilprm = theWLine->NbPnts();
3989 theLConstructor.Part(j, fprm, lprm);
3990 ifprm = (Standard_Integer)fprm;
3991 ilprm = (Standard_Integer)lprm;
3994 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
3996 for(i = 1; i <= nblines; i++) {
3997 if(anArrayOfLineType.Value(i) != 0) {
4000 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
4001 const TColStd_ListOfInteger& aListOfFLIndex = anArrayOfLineEnds.Value(i);
4002 Standard_Boolean bhasfirstpoint = (aListOfFLIndex.Extent() == 2);
4003 Standard_Boolean bhaslastpoint = (aListOfFLIndex.Extent() == 2);
4005 if(!bhasfirstpoint && !aListOfFLIndex.IsEmpty()) {
4006 bhasfirstpoint = (i != 1);
4009 if(!bhaslastpoint && !aListOfFLIndex.IsEmpty()) {
4010 bhaslastpoint = (i != nblines);
4013 Standard_Integer iFirst = aListOfIndex.First();
4014 Standard_Integer iLast = aListOfIndex.Last();
4015 Standard_Boolean bIsFirstInside = ((ifprm >= iFirst) && (ifprm <= iLast));
4016 Standard_Boolean bIsLastInside = ((ilprm >= iFirst) && (ilprm <= iLast));
4018 if(!bIsFirstInside && !bIsLastInside) {
4019 if((ifprm < iFirst) && (ilprm > iLast)) {
4020 // append whole line, and boundaries if neccesary
4021 if(bhasfirstpoint) {
4022 pit = aListOfFLIndex.First();
4023 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4026 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4028 for(; anIt.More(); anIt.Next()) {
4030 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4035 pit = aListOfFLIndex.Last();
4036 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4040 // check end of split line (end is almost always)
4041 Standard_Integer aneighbour = i + 1;
4042 Standard_Boolean bIsEndOfLine = Standard_True;
4044 if(aneighbour <= nblines) {
4045 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4047 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4048 (aListOfNeighbourIndex.IsEmpty())) {
4049 bIsEndOfLine = Standard_False;
4054 if(aLineOn2S->NbPoints() > 1) {
4055 Handle(IntPatch_WLine) aNewWLine =
4056 new IntPatch_WLine(aLineOn2S, Standard_False);
4057 theNewLines.Append(aNewWLine);
4059 aLineOn2S = new IntSurf_LineOn2S();
4064 // end if(!bIsFirstInside && !bIsLastInside)
4066 if(bIsFirstInside && bIsLastInside) {
4067 // append inside points between ifprm and ilprm
4068 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4070 for(; anIt.More(); anIt.Next()) {
4072 if((pit < ifprm) || (pit > ilprm))
4074 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4080 if(bIsFirstInside) {
4081 // append points from ifprm to last point + boundary point
4082 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4084 for(; anIt.More(); anIt.Next()) {
4088 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4093 pit = aListOfFLIndex.Last();
4094 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4097 // check end of split line (end is almost always)
4098 Standard_Integer aneighbour = i + 1;
4099 Standard_Boolean bIsEndOfLine = Standard_True;
4101 if(aneighbour <= nblines) {
4102 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4104 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4105 (aListOfNeighbourIndex.IsEmpty())) {
4106 bIsEndOfLine = Standard_False;
4111 if(aLineOn2S->NbPoints() > 1) {
4112 Handle(IntPatch_WLine) aNewWLine =
4113 new IntPatch_WLine(aLineOn2S, Standard_False);
4114 theNewLines.Append(aNewWLine);
4116 aLineOn2S = new IntSurf_LineOn2S();
4119 // end if(bIsFirstInside)
4122 // append points from first boundary point to ilprm
4123 if(bhasfirstpoint) {
4124 pit = aListOfFLIndex.First();
4125 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4128 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4130 for(; anIt.More(); anIt.Next()) {
4134 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4138 //end if(bIsLastInside)
4142 if(aLineOn2S->NbPoints() > 1) {
4143 Handle(IntPatch_WLine) aNewWLine =
4144 new IntPatch_WLine(aLineOn2S, Standard_False);
4145 theNewLines.Append(aNewWLine);
4150 return Standard_True;
4153 // ------------------------------------------------------------------------------------------------
4154 // static function: ParameterOutOfBoundary
4155 // purpose: Computes a new parameter for given curve. The corresponding 2d points
4156 // does not lay on any boundary of given faces
4157 // ------------------------------------------------------------------------------------------------
4158 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
4159 const Handle(Geom_Curve)& theCurve,
4160 const TopoDS_Face& theFace1,
4161 const TopoDS_Face& theFace2,
4162 const Standard_Real theOtherParameter,
4163 const Standard_Boolean bIncreasePar,
4164 Standard_Real& theNewParameter,
4165 const Handle(IntTools_Context)& aContext)
4167 Standard_Boolean bIsComputed = Standard_False;
4168 theNewParameter = theParameter;
4170 Standard_Real acurpar = theParameter;
4171 TopAbs_State aState = TopAbs_ON;
4172 Standard_Integer iter = 0;
4173 Standard_Real asumtol = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4174 Standard_Real adelta = asumtol * 0.1;
4175 adelta = (adelta < Precision::Confusion()) ? Precision::Confusion() : adelta;
4176 Handle(Geom_Surface) aSurf1 = BRep_Tool::Surface(theFace1);
4177 Handle(Geom_Surface) aSurf2 = BRep_Tool::Surface(theFace2);
4179 Standard_Real u1, u2, v1, v2;
4181 GeomAPI_ProjectPointOnSurf aPrj1;
4182 aSurf1->Bounds(u1, u2, v1, v2);
4183 aPrj1.Init(aSurf1, u1, u2, v1, v2);
4185 GeomAPI_ProjectPointOnSurf aPrj2;
4186 aSurf2->Bounds(u1, u2, v1, v2);
4187 aPrj2.Init(aSurf2, u1, u2, v1, v2);
4189 while(aState == TopAbs_ON) {
4194 gp_Pnt aPCurrent = theCurve->Value(acurpar);
4195 aPrj1.Perform(aPCurrent);
4196 Standard_Real U=0., V=0.;
4198 if(aPrj1.IsDone()) {
4199 aPrj1.LowerDistanceParameters(U, V);
4200 aState = aContext->StatePointFace(theFace1, gp_Pnt2d(U, V));
4203 if(aState != TopAbs_ON) {
4204 aPrj2.Perform(aPCurrent);
4206 if(aPrj2.IsDone()) {
4207 aPrj2.LowerDistanceParameters(U, V);
4208 aState = aContext->StatePointFace(theFace2, gp_Pnt2d(U, V));
4219 theNewParameter = acurpar;
4220 bIsComputed = Standard_True;
4223 if(acurpar >= theOtherParameter)
4224 theNewParameter = theOtherParameter;
4227 if(acurpar <= theOtherParameter)
4228 theNewParameter = theOtherParameter;
4234 //=======================================================================
4235 //function : IsCurveValid
4237 //=======================================================================
4238 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve)
4240 if(thePCurve.IsNull())
4241 return Standard_False;
4243 Standard_Real tolint = 1.e-10;
4244 Geom2dAdaptor_Curve PCA;
4245 IntRes2d_Domain PCD;
4246 Geom2dInt_GInter PCI;
4248 Standard_Real pf = 0., pl = 0.;
4249 gp_Pnt2d pntf, pntl;
4251 if(!thePCurve->IsClosed() && !thePCurve->IsPeriodic()) {
4252 pf = thePCurve->FirstParameter();
4253 pl = thePCurve->LastParameter();
4254 pntf = thePCurve->Value(pf);
4255 pntl = thePCurve->Value(pl);
4256 PCA.Load(thePCurve);
4257 if(!PCA.IsPeriodic()) {
4258 if(PCA.FirstParameter() > pf) pf = PCA.FirstParameter();
4259 if(PCA.LastParameter() < pl) pl = PCA.LastParameter();
4261 PCD.SetValues(pntf,pf,tolint,pntl,pl,tolint);
4262 PCI.Perform(PCA,PCD,tolint,tolint);
4264 if(PCI.NbPoints() > 0) {
4265 return Standard_False;
4269 return Standard_True;
4272 //=======================================================================
4273 //static function : ApproxWithPCurves
4274 //purpose : for bug 20964 only
4275 //=======================================================================
4276 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
4277 const gp_Sphere& theSph)
4279 Standard_Boolean bRes = Standard_True;
4280 Standard_Real R1 = theCyl.Radius(), R2 = theSph.Radius();
4283 Standard_Real aD2, aRc2, aEps;
4289 const gp_Ax3& aAx3Sph=theSph.Position();
4290 const gp_Pnt& aLocSph=aAx3Sph.Location();
4291 const gp_Dir& aDirSph=aAx3Sph.Direction();
4293 const gp_Ax1& aAx1Cyl=theCyl.Axis();
4294 gp_Lin aLinCyl(aAx1Cyl);
4296 aApexSph.SetXYZ(aLocSph.XYZ()+R2*aDirSph.XYZ());
4297 aD2=aLinCyl.SquareDistance(aApexSph);
4298 if (fabs(aD2-aRc2)<aEps) {
4302 aApexSph.SetXYZ(aLocSph.XYZ()-R2*aDirSph.XYZ());
4303 aD2=aLinCyl.SquareDistance(aApexSph);
4304 if (fabs(aD2-aRc2)<aEps) {
4313 gp_Lin anCylAx(theCyl.Axis());
4315 Standard_Real aDist = anCylAx.Distance(theSph.Location());
4316 Standard_Real aDRel = Abs(aDist - R1)/R2;
4318 if(aDRel > .2) return bRes;
4320 Standard_Real par = ElCLib::Parameter(anCylAx, theSph.Location());
4321 gp_Pnt aP = ElCLib::Value(par, anCylAx);
4322 gp_Vec aV(aP, theSph.Location());
4324 Standard_Real dd = aV.Dot(theSph.Position().XDirection());
4326 if(aDist < R1 && dd > 0.) return Standard_False;
4327 if(aDist > R1 && dd < 0.) return Standard_False;
4332 //=======================================================================
4333 //function : PerformPlanes
4335 //=======================================================================
4336 void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
4337 const Handle(GeomAdaptor_HSurface)& theS2,
4338 const Standard_Real TolAng,
4339 const Standard_Real TolTang,
4340 const Standard_Boolean theApprox1,
4341 const Standard_Boolean theApprox2,
4342 IntTools_SequenceOfCurves& theSeqOfCurve,
4343 Standard_Boolean& theTangentFaces)
4346 gp_Pln aPln1 = theS1->Surface().Plane();
4347 gp_Pln aPln2 = theS2->Surface().Plane();
4349 IntAna_QuadQuadGeo aPlnInter(aPln1, aPln2, TolAng, TolTang);
4351 if(!aPlnInter.IsDone()) {
4352 theTangentFaces = Standard_False;
4356 IntAna_ResultType aResType = aPlnInter.TypeInter();
4358 if(aResType == IntAna_Same) {
4359 theTangentFaces = Standard_True;
4363 theTangentFaces = Standard_False;
4365 if(aResType == IntAna_Empty) {
4369 gp_Lin aLin = aPlnInter.Line(1);
4371 ProjLib_Plane aProj;
4374 aProj.Project(aLin);
4375 gp_Lin2d aLin2d1 = aProj.Line();
4378 aProj.Project(aLin);
4379 gp_Lin2d aLin2d2 = aProj.Line();
4381 //classify line2d1 relatively first plane
4382 Standard_Real P11, P12;
4383 Standard_Boolean IsCrossed = ClassifyLin2d(theS1, aLin2d1, TolTang, P11, P12);
4384 if(!IsCrossed) return;
4385 //classify line2d2 relatively second plane
4386 Standard_Real P21, P22;
4387 IsCrossed = ClassifyLin2d(theS2, aLin2d2, TolTang, P21, P22);
4388 if(!IsCrossed) return;
4390 //Analysis of parametric intervals: must have common part
4392 if(P21 >= P12) return;
4393 if(P22 <= P11) return;
4395 Standard_Real pmin, pmax;
4396 pmin = Max(P11, P21);
4397 pmax = Min(P12, P22);
4399 if(pmax - pmin <= TolTang) return;
4401 Handle(Geom_Line) aGLin = new Geom_Line(aLin);
4403 IntTools_Curve aCurve;
4404 Handle(Geom_TrimmedCurve) aGTLin = new Geom_TrimmedCurve(aGLin, pmin, pmax);
4406 aCurve.SetCurve(aGTLin);
4409 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d1);
4410 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4413 Handle(Geom2d_Curve) H1;
4414 aCurve.SetFirstCurve2d(H1);
4417 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d2);
4418 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4421 Handle(Geom2d_Curve) H1;
4422 aCurve.SetFirstCurve2d(H1);
4425 theSeqOfCurve.Append(aCurve);
4429 //=======================================================================
4430 //function : ClassifyLin2d
4432 //=======================================================================
4433 static inline Standard_Boolean INTER(const Standard_Real d1,
4434 const Standard_Real d2,
4435 const Standard_Real tol)
4437 return (d1 > tol && d2 < -tol) ||
4438 (d1 < -tol && d2 > tol) ||
4439 ((d1 <= tol && d1 >= -tol) && (d2 > tol || d2 < -tol)) ||
4440 ((d2 <= tol && d2 >= -tol) && (d1 > tol || d1 < -tol));
4442 static inline Standard_Boolean COINC(const Standard_Real d1,
4443 const Standard_Real d2,
4444 const Standard_Real tol)
4446 return (d1 <= tol && d1 >= -tol) && (d2 <= tol && d2 >= -tol);
4448 Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
4449 const gp_Lin2d& theLin2d,
4450 const Standard_Real theTol,
4451 Standard_Real& theP1,
4452 Standard_Real& theP2)
4455 Standard_Real xmin, xmax, ymin, ymax, d1, d2, A, B, C;
4456 Standard_Real par[2];
4457 Standard_Integer nbi = 0;
4459 xmin = theS->Surface().FirstUParameter();
4460 xmax = theS->Surface().LastUParameter();
4461 ymin = theS->Surface().FirstVParameter();
4462 ymax = theS->Surface().LastVParameter();
4464 theLin2d.Coefficients(A, B, C);
4466 //xmin, ymin <-> xmin, ymax
4467 d1 = A*xmin + B*ymin + C;
4468 d2 = A*xmin + B*ymax + C;
4470 if(INTER(d1, d2, theTol)) {
4471 //Intersection with boundary
4472 Standard_Real y = -(C + A*xmin)/B;
4473 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, y));
4476 else if (COINC(d1, d2, theTol)) {
4477 //Coincidence with boundary
4478 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4479 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4485 if(fabs(par[0]-par[1]) > theTol) {
4486 theP1 = Min(par[0], par[1]);
4487 theP2 = Max(par[0], par[1]);
4488 return Standard_True;
4490 else return Standard_False;
4494 //xmin, ymax <-> xmax, ymax
4496 d2 = A*xmax + B*ymax + C;
4498 if(d1 > theTol || d1 < -theTol) {//to avoid checking of
4499 //coincidence with the same point
4500 if(INTER(d1, d2, theTol)) {
4501 Standard_Real x = -(C + B*ymax)/A;
4502 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymax));
4505 else if (COINC(d1, d2, theTol)) {
4506 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4507 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4514 if(fabs(par[0]-par[1]) > theTol) {
4515 theP1 = Min(par[0], par[1]);
4516 theP2 = Max(par[0], par[1]);
4517 return Standard_True;
4519 else return Standard_False;
4523 //xmax, ymax <-> xmax, ymin
4525 d2 = A*xmax + B*ymin + C;
4527 if(d1 > theTol || d1 < -theTol) {
4528 if(INTER(d1, d2, theTol)) {
4529 Standard_Real y = -(C + A*xmax)/B;
4530 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, y));
4533 else if (COINC(d1, d2, theTol)) {
4534 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4535 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4541 if(fabs(par[0]-par[1]) > theTol) {
4542 theP1 = Min(par[0], par[1]);
4543 theP2 = Max(par[0], par[1]);
4544 return Standard_True;
4546 else return Standard_False;
4549 //xmax, ymin <-> xmin, ymin
4551 d2 = A*xmin + B*ymin + C;
4553 if(d1 > theTol || d1 < -theTol) {
4554 if(INTER(d1, d2, theTol)) {
4555 Standard_Real x = -(C + B*ymin)/A;
4556 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymin));
4559 else if (COINC(d1, d2, theTol)) {
4560 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4561 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4567 if(fabs(par[0]-par[1]) > theTol) {
4568 theP1 = Min(par[0], par[1]);
4569 theP2 = Max(par[0], par[1]);
4570 return Standard_True;
4572 else return Standard_False;
4575 return Standard_False;
4579 //=======================================================================
4580 //function : ApproxParameters
4582 //=======================================================================
4583 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
4584 const Handle(GeomAdaptor_HSurface)& aHS2,
4585 Standard_Integer& iDegMin,
4586 Standard_Integer& iDegMax,
4587 Standard_Integer& iNbIter)
4590 GeomAbs_SurfaceType aTS1, aTS2;
4597 aTS1=aHS1->Surface().GetType();
4598 aTS2=aHS2->Surface().GetType();
4601 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4602 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4603 Standard_Real aRC, aRT, dR, aPC;
4604 gp_Cylinder aCylinder;
4607 aPC=Precision::Confusion();
4609 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4610 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4612 aRC=aCylinder.Radius();
4613 aRT=aTorus.MinorRadius();
4623 if (aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Cylinder) {
4627 //=======================================================================
4628 //function : Tolerances
4630 //=======================================================================
4631 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
4632 const Handle(GeomAdaptor_HSurface)& aHS2,
4633 Standard_Real& aTolTang)
4635 GeomAbs_SurfaceType aTS1, aTS2;
4637 aTS1=aHS1->Surface().GetType();
4638 aTS2=aHS2->Surface().GetType();
4641 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4642 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4643 Standard_Real aRC, aRT, dR, aPC;
4644 gp_Cylinder aCylinder;
4647 aPC=Precision::Confusion();
4649 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4650 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4652 aRC=aCylinder.Radius();
4653 aRT=aTorus.MinorRadius();
4660 aTolTang=0.1*aTolTang;
4664 //=======================================================================
4665 //function : SortTypes
4667 //=======================================================================
4668 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
4669 const GeomAbs_SurfaceType aType2)
4671 Standard_Boolean bRet;
4672 Standard_Integer aI1, aI2;
4674 bRet=Standard_False;
4676 aI1=IndexType(aType1);
4677 aI2=IndexType(aType2);
4683 //=======================================================================
4684 //function : IndexType
4686 //=======================================================================
4687 Standard_Integer IndexType(const GeomAbs_SurfaceType aType)
4689 Standard_Integer aIndex;
4693 if (aType==GeomAbs_Plane) {
4696 else if (aType==GeomAbs_Cylinder) {
4699 else if (aType==GeomAbs_Cone) {
4702 else if (aType==GeomAbs_Sphere) {
4705 else if (aType==GeomAbs_Torus) {
4708 else if (aType==GeomAbs_BezierSurface) {
4711 else if (aType==GeomAbs_BSplineSurface) {
4714 else if (aType==GeomAbs_SurfaceOfRevolution) {
4717 else if (aType==GeomAbs_SurfaceOfExtrusion) {
4720 else if (aType==GeomAbs_OffsetSurface) {
4723 else if (aType==GeomAbs_OtherSurface) {
4728 #ifdef OCCT_DEBUG_DUMPWLINE
4729 //=======================================================================
4730 //function : DumpWLine
4732 //=======================================================================
4733 void DumpWLine(const Handle(IntPatch_WLine)& aWLine)
4735 Standard_Integer i, aNbPnts;
4736 Standard_Real aX, aY, aZ, aU1, aV1, aU2, aV2;
4738 printf(" *WLine\n");
4739 aNbPnts=aWLine->NbPnts();
4740 for (i=1; i<=aNbPnts; ++i) {
4741 const IntSurf_PntOn2S aPntOn2S=aWLine->Point(i);
4742 const gp_Pnt& aP3D=aPntOn2S.Value();
4743 aP3D.Coord(aX, aY, aZ);
4744 aPntOn2S.Parameters(aU1, aV1, aU2, aV2);
4746 printf("point p_%d %lf %lf %lf\n", i, aX, aY, aZ);
4747 //printf("point p_%d %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf\n",
4748 // i, aX, aY, aZ, aU1, aV1, aU2, aV2);
4752 //=======================================================================
4753 //function : RefineVector
4755 //=======================================================================
4756 void RefineVector(gp_Vec2d& aV2D)
4758 Standard_Integer k,m;
4759 Standard_Real aC[2], aEps, aR1, aR2, aNum;
4765 aV2D.Coord(aC[0], aC[1]);
4767 for (k=0; k<2; ++k) {
4770 if (aNum>aR1 && aNum<aR2) {
4781 aV2D.SetCoord(aC[0], aC[1]);
4784 //=======================================================================
4785 // Function : MaxDistance
4787 //=======================================================================
4788 Standard_Real MaxDistance(const Handle(Geom_Curve)& theC,
4789 const Standard_Real aT,
4790 GeomAPI_ProjectPointOnSurf& theProjPS)
4796 theProjPS.Perform(aP);
4797 aD = theProjPS.NbPoints() ? theProjPS.LowerDistance() : 0.;
4802 //=======================================================================
4803 //function : CheckPCurve
4804 //purpose : Checks if points of the pcurve are out of the face bounds.
4805 //=======================================================================
4806 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
4807 const TopoDS_Face& aFace)
4809 const Standard_Integer NPoints = 23;
4811 Standard_Real umin,umax,vmin,vmax;
4813 BRepTools::UVBounds(aFace, umin, umax, vmin, vmax);
4814 Standard_Real tolU = Max ((umax-umin)*0.01, Precision::Confusion());
4815 Standard_Real tolV = Max ((vmax-vmin)*0.01, Precision::Confusion());
4816 Standard_Real fp = aPC->FirstParameter();
4817 Standard_Real lp = aPC->LastParameter();
4820 // adjust domain for periodic surfaces
4821 TopLoc_Location aLoc;
4822 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc);
4823 if (aSurf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
4824 aSurf = (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf))->BasisSurface();
4826 gp_Pnt2d pnt = aPC->Value((fp+lp)/2);
4830 if (aSurf->IsUPeriodic()) {
4831 Standard_Real aPer = aSurf->UPeriod();
4832 Standard_Integer nshift = (Standard_Integer) ((u-umin)/aPer);
4833 if (u < umin+aPer*nshift) nshift--;
4834 umin += aPer*nshift;
4835 umax += aPer*nshift;
4837 if (aSurf->IsVPeriodic()) {
4838 Standard_Real aPer = aSurf->VPeriod();
4839 Standard_Integer nshift = (Standard_Integer) ((v-vmin)/aPer);
4840 if (v < vmin+aPer*nshift) nshift--;
4841 vmin += aPer*nshift;
4842 vmax += aPer*nshift;
4845 //--------------------------------------------------------
4846 Standard_Boolean bRet;
4847 Standard_Integer j, aNbIntervals;
4848 Standard_Real aT, dT;
4851 Geom2dAdaptor_Curve aGAC(aPC);
4852 aNbIntervals=aGAC.NbIntervals(GeomAbs_CN);
4854 TColStd_Array1OfReal aTI(1, aNbIntervals+1);
4855 aGAC.Intervals(aTI,GeomAbs_CN);
4857 bRet=Standard_False;
4859 aT=aGAC.FirstParameter();
4860 for (j=1; j<=aNbIntervals; ++j) {
4861 dT=(aTI(j+1)-aTI(j))/NPoints;
4863 for (i=1; i<NPoints; i++) {
4867 if (umin-u > tolU || u-umax > tolU ||
4868 vmin-v > tolV || v-vmax > tolV) {
4875 //=======================================================================
4876 //function : CorrectPlaneBoundaries
4878 //=======================================================================
4879 void CorrectPlaneBoundaries(Standard_Real& aUmin,
4880 Standard_Real& aUmax,
4881 Standard_Real& aVmin,
4882 Standard_Real& aVmax)
4884 if (!(Precision::IsInfinite(aUmin) ||
4885 Precision::IsInfinite(aUmax))) {
4888 dU=0.1*(aUmax-aUmin);
4892 if (!(Precision::IsInfinite(aVmin) ||
4893 Precision::IsInfinite(aVmax))) {
4896 dV=0.1*(aVmax-aVmin);