1 // Created on: 2000-11-23
2 // Created by: Michael KLOKOV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <IntTools_FaceFace.ixx>
18 #include <Precision.hxx>
20 #include <TColStd_HArray1OfReal.hxx>
21 #include <TColStd_Array1OfReal.hxx>
22 #include <TColStd_Array1OfInteger.hxx>
23 #include <TColStd_SequenceOfReal.hxx>
24 #include <TColStd_ListOfInteger.hxx>
25 #include <TColStd_ListIteratorOfListOfInteger.hxx>
26 #include <TColStd_Array1OfListOfInteger.hxx>
28 #include <gp_Lin2d.hxx>
29 #include <gp_Ax22d.hxx>
30 #include <gp_Circ2d.hxx>
31 #include <gp_Torus.hxx>
32 #include <gp_Cylinder.hxx>
34 #include <Bnd_Box.hxx>
36 #include <TColgp_HArray1OfPnt2d.hxx>
37 #include <TColgp_SequenceOfPnt2d.hxx>
38 #include <TColgp_Array1OfPnt.hxx>
39 #include <TColgp_Array1OfPnt2d.hxx>
41 #include <IntAna_QuadQuadGeo.hxx>
43 #include <IntSurf_PntOn2S.hxx>
44 #include <IntSurf_LineOn2S.hxx>
45 #include <IntSurf_PntOn2S.hxx>
46 #include <IntSurf_ListOfPntOn2S.hxx>
47 #include <IntRes2d_Domain.hxx>
48 #include <ProjLib_Plane.hxx>
50 #include <IntPatch_GLine.hxx>
51 #include <IntPatch_RLine.hxx>
52 #include <IntPatch_WLine.hxx>
53 #include <IntPatch_ALine.hxx>
54 #include <IntPatch_ALineToWLine.hxx>
59 #include <Extrema_ExtCC.hxx>
60 #include <Extrema_POnCurv.hxx>
61 #include <BndLib_AddSurface.hxx>
63 #include <Adaptor3d_SurfacePtr.hxx>
64 #include <Adaptor2d_HLine2d.hxx>
66 #include <GeomAbs_SurfaceType.hxx>
67 #include <GeomAbs_CurveType.hxx>
69 #include <Geom_Surface.hxx>
70 #include <Geom_Line.hxx>
71 #include <Geom_Circle.hxx>
72 #include <Geom_Ellipse.hxx>
73 #include <Geom_Parabola.hxx>
74 #include <Geom_Hyperbola.hxx>
75 #include <Geom_TrimmedCurve.hxx>
76 #include <Geom_BSplineCurve.hxx>
77 #include <Geom_RectangularTrimmedSurface.hxx>
78 #include <Geom_OffsetSurface.hxx>
79 #include <Geom_Curve.hxx>
80 #include <Geom_Conic.hxx>
82 #include <Geom2d_TrimmedCurve.hxx>
83 #include <Geom2d_BSplineCurve.hxx>
84 #include <Geom2d_Line.hxx>
85 #include <Geom2d_Curve.hxx>
86 #include <Geom2d_Circle.hxx>
88 #include <Geom2dAPI_InterCurveCurve.hxx>
89 #include <Geom2dInt_GInter.hxx>
90 #include <Geom2dAdaptor.hxx>
91 #include <GeomAdaptor_Curve.hxx>
92 #include <GeomAdaptor_HSurface.hxx>
93 #include <GeomAdaptor_Surface.hxx>
94 #include <GeomLib_CheckBSplineCurve.hxx>
95 #include <GeomLib_Check2dBSplineCurve.hxx>
97 #include <GeomInt_WLApprox.hxx>
98 #include <GeomProjLib.hxx>
99 #include <GeomAPI_ProjectPointOnSurf.hxx>
100 #include <Geom2dAdaptor_Curve.hxx>
101 #include <TopoDS.hxx>
102 #include <TopoDS_Edge.hxx>
103 #include <TopExp_Explorer.hxx>
105 #include <BRep_Tool.hxx>
106 #include <BRepTools.hxx>
107 #include <BRepAdaptor_Surface.hxx>
109 #include <IntTools_Curve.hxx>
110 #include <IntTools_Tools.hxx>
111 #include <IntTools_Tools.hxx>
112 #include <IntTools_TopolTool.hxx>
113 #include <IntTools_PntOnFace.hxx>
114 #include <IntTools_PntOn2Faces.hxx>
115 #include <IntTools_Context.hxx>
116 #include <IntSurf_ListIteratorOfListOfPntOn2S.hxx>
117 #include <GeomInt.hxx>
119 #include <Approx_CurveOnSurface.hxx>
120 #include <GeomAdaptor.hxx>
121 #include <GeomInt_IntSS.hxx>
124 void RefineVector(gp_Vec2d& aV2D);
125 #ifdef OCCT_DEBUG_DUMPWLINE
127 void DumpWLine(const Handle(IntPatch_WLine)& aWLine);
131 void TolR3d(const TopoDS_Face& ,
135 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)&,
136 const Standard_Integer,
137 const Standard_Integer);
140 void Parameters(const Handle(GeomAdaptor_HSurface)&,
141 const Handle(GeomAdaptor_HSurface)&,
149 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
150 const Standard_Real theTolerance,
151 Standard_Real& theumin,
152 Standard_Real& theumax,
153 Standard_Real& thevmin,
154 Standard_Real& thevmax);
157 Standard_Boolean NotUseSurfacesForApprox
158 (const TopoDS_Face& aF1,
159 const TopoDS_Face& aF2,
160 const Handle(IntPatch_WLine)& WL,
161 const Standard_Integer ifprm,
162 const Standard_Integer ilprm);
165 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine);
168 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
169 const Standard_Integer ideb,
170 const Standard_Integer ifin,
171 const Standard_Boolean onFirst);
174 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
175 const Handle(GeomAdaptor_HSurface)& theSurface1,
176 const Handle(GeomAdaptor_HSurface)& theSurface2,
177 const TopoDS_Face& theFace1,
178 const TopoDS_Face& theFace2,
179 const GeomInt_LineConstructor& theLConstructor,
180 const Standard_Boolean theAvoidLConstructor,
181 IntPatch_SequenceOfLine& theNewLines,
182 Standard_Real& theReachedTol3d,
183 const Handle(IntTools_Context)& );
186 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
187 const Handle(Geom_Curve)& theCurve,
188 const TopoDS_Face& theFace1,
189 const TopoDS_Face& theFace2,
190 const Standard_Real theOtherParameter,
191 const Standard_Boolean bIncreasePar,
192 Standard_Real& theNewParameter,
193 const Handle(IntTools_Context)& );
196 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve);
199 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
200 const Standard_Real theFirstBoundary,
201 const Standard_Real theSecondBoundary,
202 const Standard_Real theResolution,
203 Standard_Boolean& IsOnFirstBoundary);
205 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
206 const gp_Pnt2d& theLastPoint,
207 const Standard_Real theUmin,
208 const Standard_Real theUmax,
209 const Standard_Real theVmin,
210 const Standard_Real theVmax,
211 gp_Pnt2d& theNewPoint);
215 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
216 const Handle(GeomAdaptor_HSurface)& theSurface2,
217 const TopoDS_Face& theFace1,
218 const TopoDS_Face& theFace2,
219 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
220 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
221 Handle(TColStd_HArray1OfReal)& theResultRadius,
222 const Handle(IntTools_Context)& );
225 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
226 const gp_Pnt2d& theLastPoint,
227 const Standard_Real theUmin,
228 const Standard_Real theUmax,
229 const Standard_Real theVmin,
230 const Standard_Real theVmax,
231 const gp_Pnt2d& theTanZoneCenter,
232 const Standard_Real theZoneRadius,
233 Handle(GeomAdaptor_HSurface) theGASurface,
234 gp_Pnt2d& theNewPoint);
237 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
238 const gp_Pnt2d& theTanZoneCenter,
239 const Standard_Real theZoneRadius,
240 Handle(GeomAdaptor_HSurface) theGASurface);
243 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
244 const gp_Pnt2d& theOriginalPoint,
245 Handle(GeomAdaptor_HSurface) theGASurface);
247 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
248 const gp_Sphere& theSph);
250 static void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
251 const Handle(GeomAdaptor_HSurface)& theS2,
252 const Standard_Real TolAng,
253 const Standard_Real TolTang,
254 const Standard_Boolean theApprox1,
255 const Standard_Boolean theApprox2,
256 IntTools_SequenceOfCurves& theSeqOfCurve,
257 Standard_Boolean& theTangentFaces);
259 static Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
260 const gp_Lin2d& theLin2d,
261 const Standard_Real theTol,
262 Standard_Real& theP1,
263 Standard_Real& theP2);
266 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
267 const Handle(GeomAdaptor_HSurface)& aHS2,
268 Standard_Integer& iDegMin,
269 Standard_Integer& iNbIter,
270 Standard_Integer& iDegMax);
273 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
274 const Handle(GeomAdaptor_HSurface)& aHS2,
275 Standard_Real& aTolTang);
278 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
279 const GeomAbs_SurfaceType aType2);
281 Standard_Integer IndexType(const GeomAbs_SurfaceType aType);
285 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
286 const TopoDS_Face& aFace);
289 void CorrectPlaneBoundaries(Standard_Real& aUmin,
290 Standard_Real& aUmax,
291 Standard_Real& aVmin,
292 Standard_Real& aVmax);
294 //=======================================================================
297 //=======================================================================
298 IntTools_FaceFace::IntTools_FaceFace()
300 myIsDone=Standard_False;
301 myTangentFaces=Standard_False;
303 myHS1 = new GeomAdaptor_HSurface ();
304 myHS2 = new GeomAdaptor_HSurface ();
307 SetParameters(Standard_True, Standard_True, Standard_True, 1.e-07);
310 //=======================================================================
311 //function : SetContext
313 //=======================================================================
314 void IntTools_FaceFace::SetContext(const Handle(IntTools_Context)& aContext)
318 //=======================================================================
321 //=======================================================================
322 const Handle(IntTools_Context)& IntTools_FaceFace::Context()const
326 //=======================================================================
329 //=======================================================================
330 const TopoDS_Face& IntTools_FaceFace::Face1() const
334 //=======================================================================
337 //=======================================================================
338 const TopoDS_Face& IntTools_FaceFace::Face2() const
342 //=======================================================================
343 //function : TangentFaces
345 //=======================================================================
346 Standard_Boolean IntTools_FaceFace::TangentFaces() const
348 return myTangentFaces;
350 //=======================================================================
353 //=======================================================================
354 const IntTools_SequenceOfPntOn2Faces& IntTools_FaceFace::Points() const
358 //=======================================================================
361 //=======================================================================
362 Standard_Boolean IntTools_FaceFace::IsDone() const
366 //=======================================================================
367 //function : TolReached3d
369 //=======================================================================
370 Standard_Real IntTools_FaceFace::TolReached3d() const
372 return myTolReached3d;
374 //=======================================================================
376 //purpose : return lines of intersection
377 //=======================================================================
378 const IntTools_SequenceOfCurves& IntTools_FaceFace::Lines() const
380 StdFail_NotDone_Raise_if
382 "IntTools_FaceFace::Lines() => myIntersector NOT DONE");
385 //=======================================================================
386 //function : TolReached2d
388 //=======================================================================
389 Standard_Real IntTools_FaceFace::TolReached2d() const
391 return myTolReached2d;
393 // =======================================================================
394 // function: SetParameters
396 // =======================================================================
397 void IntTools_FaceFace::SetParameters(const Standard_Boolean ToApproxC3d,
398 const Standard_Boolean ToApproxC2dOnS1,
399 const Standard_Boolean ToApproxC2dOnS2,
400 const Standard_Real ApproximationTolerance)
402 myApprox = ToApproxC3d;
403 myApprox1 = ToApproxC2dOnS1;
404 myApprox2 = ToApproxC2dOnS2;
405 myTolApprox = ApproximationTolerance;
407 //=======================================================================
410 //=======================================================================
411 void IntTools_FaceFace::SetList(IntSurf_ListOfPntOn2S& aListOfPnts)
413 myListOfPnts = aListOfPnts;
417 static Standard_Boolean isTreatAnalityc(const TopoDS_Face& theF1,
418 const TopoDS_Face& theF2)
420 const Standard_Real Tolang = 1.e-8;
421 const Standard_Real aTolF1=BRep_Tool::Tolerance(theF1);
422 const Standard_Real aTolF2=BRep_Tool::Tolerance(theF2);
423 const Standard_Real aTolSum = aTolF1 + aTolF2;
424 Standard_Real aHigh = 0.0;
426 const BRepAdaptor_Surface aBAS1(theF1), aBAS2(theF2);
427 const GeomAbs_SurfaceType aType1=aBAS1.GetType();
428 const GeomAbs_SurfaceType aType2=aBAS2.GetType();
432 if(aType1 == GeomAbs_Plane)
436 else if(aType2 == GeomAbs_Plane)
442 return Standard_True;
445 if(aType1 == GeomAbs_Cylinder)
447 aS2=aBAS1.Cylinder();
448 const Standard_Real VMin = aBAS1.FirstVParameter();
449 const Standard_Real VMax = aBAS1.LastVParameter();
451 if( Precision::IsNegativeInfinite(VMin) ||
452 Precision::IsPositiveInfinite(VMax))
453 return Standard_True;
457 else if(aType2 == GeomAbs_Cylinder)
459 aS2=aBAS2.Cylinder();
461 const Standard_Real VMin = aBAS2.FirstVParameter();
462 const Standard_Real VMax = aBAS2.LastVParameter();
464 if( Precision::IsNegativeInfinite(VMin) ||
465 Precision::IsPositiveInfinite(VMax))
466 return Standard_True;
472 return Standard_True;
475 IntAna_QuadQuadGeo inter;
476 inter.Perform(aS1,aS2,Tolang,aTolSum, aHigh);
477 if(inter.TypeInter() == IntAna_Ellipse)
479 const gp_Elips anEl = inter.Ellipse(1);
480 const Standard_Real aMajorR = anEl.MajorRadius();
481 const Standard_Real aMinorR = anEl.MinorRadius();
483 return (aMajorR < 100000.0 * aMinorR);
487 return inter.IsDone();
490 //=======================================================================
492 //purpose : intersect surfaces of the faces
493 //=======================================================================
494 void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
495 const TopoDS_Face& aF2)
497 Standard_Boolean RestrictLine = Standard_False, hasCone = Standard_False;
499 if (myContext.IsNull()) {
500 myContext=new IntTools_Context;
503 mySeqOfCurve.Clear();
506 myIsDone = Standard_False;
512 const BRepAdaptor_Surface aBAS1(myFace1, Standard_False);
513 const BRepAdaptor_Surface aBAS2(myFace2, Standard_False);
514 GeomAbs_SurfaceType aType1=aBAS1.GetType();
515 GeomAbs_SurfaceType aType2=aBAS2.GetType();
517 const Standard_Boolean bReverse=SortTypes(aType1, aType2);
522 aType1=aBAS2.GetType();
523 aType2=aBAS1.GetType();
525 if (myListOfPnts.Extent())
527 Standard_Real aU1,aV1,aU2,aV2;
528 IntSurf_ListIteratorOfListOfPntOn2S aItP2S;
530 aItP2S.Initialize(myListOfPnts);
531 for (; aItP2S.More(); aItP2S.Next())
533 IntSurf_PntOn2S& aP2S=aItP2S.Value();
534 aP2S.Parameters(aU1,aV1,aU2,aV2);
535 aP2S.SetValue(aU2,aV2,aU1,aV1);
539 Standard_Boolean anAproxTmp = myApprox1;
540 myApprox1 = myApprox2;
541 myApprox2 = anAproxTmp;
545 const Handle(Geom_Surface) S1=BRep_Tool::Surface(myFace1);
546 const Handle(Geom_Surface) S2=BRep_Tool::Surface(myFace2);
548 const Standard_Real aTolF1=BRep_Tool::Tolerance(myFace1);
549 const Standard_Real aTolF2=BRep_Tool::Tolerance(myFace2);
551 Standard_Real TolArc = aTolF1 + aTolF2;
552 Standard_Real TolTang = TolArc;
554 const Standard_Boolean isFace1Quad = (aType1 == GeomAbs_Cylinder ||
555 aType1 == GeomAbs_Cone ||
556 aType1 == GeomAbs_Torus);
558 const Standard_Boolean isFace2Quad = (aType2 == GeomAbs_Cylinder ||
559 aType2 == GeomAbs_Cone ||
560 aType2 == GeomAbs_Torus);
562 if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
563 Standard_Real umin, umax, vmin, vmax;
565 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
566 CorrectPlaneBoundaries(umin, umax, vmin, vmax);
567 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
569 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
570 CorrectPlaneBoundaries(umin, umax, vmin, vmax);
571 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
573 Standard_Real TolAng = 1.e-8;
575 PerformPlanes(myHS1, myHS2, TolAng, TolTang, myApprox1, myApprox2,
576 mySeqOfCurve, myTangentFaces);
578 myIsDone = Standard_True;
580 if(!myTangentFaces) {
581 const Standard_Integer NbLinPP = mySeqOfCurve.Length();
583 Standard_Real aTolFMax;
584 myTolReached3d = 1.e-7;
585 aTolFMax=Max(aTolF1, aTolF2);
586 if (aTolFMax>myTolReached3d) {
587 myTolReached3d=aTolFMax;
590 myTolReached2d = myTolReached3d;
593 Handle(Geom2d_Curve) aC2D1, aC2D2;
594 const Standard_Integer aNbLin = mySeqOfCurve.Length();
595 for (Standard_Integer i = 1; i <= aNbLin; ++i) {
596 IntTools_Curve& aIC=mySeqOfCurve(i);
597 aC2D1=aIC.FirstCurve2d();
598 aC2D2=aIC.SecondCurve2d();
599 aIC.SetFirstCurve2d(aC2D2);
600 aIC.SetSecondCurve2d(aC2D1);
606 }//if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
608 if ((aType1==GeomAbs_Plane) && isFace2Quad)
610 Standard_Real umin, umax, vmin, vmax;
612 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
613 CorrectPlaneBoundaries(umin, umax, vmin, vmax);
614 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
616 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
617 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
618 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
620 if( aType2==GeomAbs_Cone ) {
622 hasCone = Standard_True;
625 else if ((aType2==GeomAbs_Plane) && isFace1Quad)
627 Standard_Real umin, umax, vmin, vmax;
629 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
630 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
631 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
633 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
634 CorrectPlaneBoundaries(umin, umax, vmin, vmax);
635 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
637 if( aType1==GeomAbs_Cone ) {
639 hasCone = Standard_True;
644 Standard_Real umin, umax, vmin, vmax;
645 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
646 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
647 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
648 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
649 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
650 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
653 const Handle(IntTools_TopolTool) dom1 = new IntTools_TopolTool(myHS1);
654 const Handle(IntTools_TopolTool) dom2 = new IntTools_TopolTool(myHS2);
656 myLConstruct.Load(dom1, dom2, myHS1, myHS2);
659 Tolerances(myHS1, myHS2, TolTang);
662 const Standard_Real UVMaxStep = 0.001;
663 const Standard_Real Deflection = (hasCone) ? 0.085 : 0.1;
664 myIntersector.SetTolerances(TolArc, TolTang, UVMaxStep, Deflection);
667 if((myHS1->IsUClosed() && !myHS1->IsUPeriodic()) ||
668 (myHS1->IsVClosed() && !myHS1->IsVPeriodic()) ||
669 (myHS2->IsUClosed() && !myHS2->IsUPeriodic()) ||
670 (myHS2->IsVClosed() && !myHS2->IsVPeriodic()))
672 RestrictLine = Standard_True;
675 if((aType1 != GeomAbs_BSplineSurface) &&
676 (aType1 != GeomAbs_BezierSurface) &&
677 (aType1 != GeomAbs_OtherSurface) &&
678 (aType2 != GeomAbs_BSplineSurface) &&
679 (aType2 != GeomAbs_BezierSurface) &&
680 (aType2 != GeomAbs_OtherSurface))
682 RestrictLine = Standard_True;
684 if ((aType1 == GeomAbs_Torus) ||
685 (aType2 == GeomAbs_Torus))
687 myListOfPnts.Clear();
694 TopExp_Explorer aExp;
695 for(Standard_Integer i = 0; (!RestrictLine) && (i < 2); i++)
697 const TopoDS_Face& aF=(!i) ? myFace1 : myFace2;
698 aExp.Init(aF, TopAbs_EDGE);
699 for(; aExp.More(); aExp.Next())
701 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
703 if(BRep_Tool::Degenerated(aE))
705 RestrictLine = Standard_True;
712 const Standard_Boolean isGeomInt = isTreatAnalityc(aF1, aF2);
713 myIntersector.Perform(myHS1, dom1, myHS2, dom2, TolArc, TolTang,
714 myListOfPnts, RestrictLine, isGeomInt);
716 myIsDone = myIntersector.IsDone();
720 myTangentFaces=myIntersector.TangentFaces();
721 if (myTangentFaces) {
726 myListOfPnts.Clear(); // to use LineConstructor
729 const Standard_Integer aNbLin = myIntersector.NbLines();
730 for (Standard_Integer i=1; i <= aNbLin; ++i) {
731 MakeCurve(i, dom1, dom2);
734 ComputeTolReached3d();
737 Handle(Geom2d_Curve) aC2D1, aC2D2;
739 const Standard_Integer aNbLin=mySeqOfCurve.Length();
740 for (Standard_Integer i=1; i<=aNbLin; ++i)
742 IntTools_Curve& aIC=mySeqOfCurve(i);
743 aC2D1=aIC.FirstCurve2d();
744 aC2D2=aIC.SecondCurve2d();
745 aIC.SetFirstCurve2d(aC2D2);
746 aIC.SetSecondCurve2d(aC2D1);
751 Standard_Boolean bValid2D1, bValid2D2;
752 Standard_Real U1,V1,U2,V2;
753 IntTools_PntOnFace aPntOnF1, aPntOnF2;
754 IntTools_PntOn2Faces aPntOn2Faces;
756 const Standard_Integer aNbPnts = myIntersector.NbPnts();
757 for (Standard_Integer i=1; i <= aNbPnts; ++i)
759 const IntSurf_PntOn2S& aISPnt=myIntersector.Point(i).PntOn2S();
760 const gp_Pnt& aPnt=aISPnt.Value();
761 aISPnt.Parameters(U1,V1,U2,V2);
763 // check the validity of the intersection point for the faces
764 bValid2D1 = myContext->IsPointInOnFace(myFace1, gp_Pnt2d(U1, V1));
769 bValid2D2 = myContext->IsPointInOnFace(myFace2, gp_Pnt2d(U2, V2));
774 // add the intersection point
775 aPntOnF1.Init(myFace1, aPnt, U1, V1);
776 aPntOnF2.Init(myFace2, aPnt, U2, V2);
780 aPntOn2Faces.SetP1(aPntOnF1);
781 aPntOn2Faces.SetP2(aPntOnF2);
785 aPntOn2Faces.SetP2(aPntOnF1);
786 aPntOn2Faces.SetP1(aPntOnF2);
789 myPnts.Append(aPntOn2Faces);
794 //=======================================================================
795 //function : ComputeTolerance
797 //=======================================================================
798 Standard_Real IntTools_FaceFace::ComputeTolerance()
800 Standard_Integer i, j, aNbLin;
801 Standard_Real aFirst, aLast, aD, aDMax, aT;
802 Handle(Geom_Surface) aS1, aS2;
805 aNbLin = mySeqOfCurve.Length();
807 aS1 = myHS1->ChangeSurface().Surface();
808 aS2 = myHS2->ChangeSurface().Surface();
810 for (i = 1; i <= aNbLin; ++i)
812 const IntTools_Curve& aIC = mySeqOfCurve(i);
813 const Handle(Geom_Curve)& aC3D = aIC.Curve();
819 aFirst = aC3D->FirstParameter();
820 aLast = aC3D->LastParameter();
822 const Handle(Geom2d_Curve)& aC2D1 = aIC.FirstCurve2d();
823 const Handle(Geom2d_Curve)& aC2D2 = aIC.SecondCurve2d();
825 for (j = 0; j < 2; ++j)
827 const Handle(Geom2d_Curve)& aC2D = !j ? aC2D1 : aC2D2;
828 const Handle(Geom_Surface)& aS = !j ? aS1 : aS2;
832 if (IntTools_Tools::ComputeTolerance
833 (aC3D, aC2D, aS, aFirst, aLast, aD, aT))
847 //=======================================================================
848 //function :ComputeTolReached3d
850 //=======================================================================
851 void IntTools_FaceFace::ComputeTolReached3d()
853 Standard_Integer aNbLin, i;
854 GeomAbs_SurfaceType aType1, aType2;
856 aNbLin=myIntersector.NbLines();
861 aType1=myHS1->Surface().GetType();
862 aType2=myHS2->Surface().GetType();
864 if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
866 Handle(IntPatch_Line) aIL1, aIL2;
867 IntPatch_IType aTL1, aTL2;
869 aIL1=myIntersector.Line(1);
870 aIL2=myIntersector.Line(2);
871 aTL1=aIL1->ArcType();
872 aTL2=aIL2->ArcType();
873 if (aTL1==IntPatch_Lin && aTL2==IntPatch_Lin) {
874 Standard_Real aD, aDTresh, dTol;
880 aL1=Handle(IntPatch_GLine)::DownCast(aIL1)->Line();
881 aL2=Handle(IntPatch_GLine)::DownCast(aIL2)->Line();
882 aD=aL1.Distance(aL2);
885 myTolReached3d=aD+dTol;
891 if (aNbLin) {// Check the distances
894 aDMax = ComputeTolerance();
896 myTolReached3d = aDMax;
899 }// if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
902 else if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
903 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
907 aTolF1 = BRep_Tool::Tolerance(myFace1);
908 aTolF2 = BRep_Tool::Tolerance(myFace2);
909 aTolFMax=Max(aTolF1, aTolF2);
911 if (aTolFMax>aTolTresh) {
912 myTolReached3d=aTolFMax;
914 }//if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
917 else if((aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) ||
918 (aType2 == GeomAbs_Cylinder && aType1 == GeomAbs_Plane)) {
920 const Handle(IntPatch_Line)& aIL1 = myIntersector.Line(1);
921 if(aIL1->ArcType() == IntPatch_Circle) {
922 gp_Circ aCir = Handle(IntPatch_GLine)::DownCast(aIL1)->Circle();
923 gp_XYZ aCirDir = aCir.Axis().Direction().XYZ();
926 if(aType1 == GeomAbs_Plane) {
927 aPln = myHS1->Surface().Plane();
930 aPln = myHS2->Surface().Plane();
932 aPlDir = aPln.Axis().Direction().XYZ();
933 Standard_Real cs = aCirDir*aPlDir;
934 if(cs < 0.) aPlDir.Reverse();
935 Standard_Real eps = 1.e-14;
936 if(!aPlDir.IsEqual(aCirDir, eps)) {
937 Standard_Integer aNbP = 11;
938 Standard_Real dt = 2.*M_PI / (aNbP - 1), t;
939 for(t = 0.; t < 2.*M_PI; t += dt) {
940 Standard_Real d = aPln.Distance(ElCLib::Value(t, aCir));
941 if(myTolReached3d < d) myTolReached3d = d;
943 myTolReached3d *= 1.1;
945 } //aIL1->ArcType() == IntPatch_Circle
947 } // aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane)
948 //End IFV Bug OCC20297
950 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
951 (aType2==GeomAbs_Plane && aType1==GeomAbs_Torus)) {
952 aNbLin=mySeqOfCurve.Length();
957 Standard_Integer aNbP;
958 Standard_Real aT, aT1, aT2, dT, aUT, aVT, aUP, aVP;
959 Standard_Real aDP, aDT, aDmax;
964 const IntTools_Curve& aIC=mySeqOfCurve(1);
965 const Handle(Geom_Curve)& aC3D=aIC.Curve();
966 Handle(Geom_BSplineCurve) aBS (Handle(Geom_BSplineCurve)::DownCast(aC3D));
971 aT1=aBS->FirstParameter();
972 aT2=aBS->LastParameter();
974 aPln =(aType1==GeomAbs_Plane) ? myHS1->Plane() : myHS2->Plane();
975 aTorus=(aType1==GeomAbs_Plane) ? myHS2->Torus() : myHS1->Torus();
979 dT=(aT2-aT1)/(aNbP-1);
980 for (i=0; i<aNbP; ++i) {
988 ElSLib::Parameters(aPln, aP, aUP, aVP);
989 aPP=ElSLib::Value(aUP, aVP, aPln);
990 aDP=aP.SquareDistance(aPP);
995 ElSLib::Parameters(aTorus, aP, aUT, aVT);
996 aPT=ElSLib::Value(aUT, aVT, aTorus);
997 aDT=aP.SquareDistance(aPT);
1003 if (aDmax > myTolReached3d*myTolReached3d) {
1004 myTolReached3d=sqrt(aDmax);
1005 myTolReached3d=1.1*myTolReached3d;
1007 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
1009 else if ((aType1==GeomAbs_SurfaceOfRevolution && aType2==GeomAbs_Cylinder) ||
1010 (aType2==GeomAbs_SurfaceOfRevolution && aType1==GeomAbs_Cylinder) ||
1011 (aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ||
1012 (aType2==GeomAbs_Plane && aType1==GeomAbs_Sphere) ||
1013 (aType1==GeomAbs_Plane && aType2==GeomAbs_SurfaceOfExtrusion) ||
1014 (aType2==GeomAbs_Plane && aType1==GeomAbs_SurfaceOfExtrusion) ||
1015 (aType1==GeomAbs_Plane && aType2==GeomAbs_BSplineSurface) ||
1016 (aType2==GeomAbs_Plane && aType1==GeomAbs_BSplineSurface) ||
1019 Standard_Real aDMax;
1021 aDMax = ComputeTolerance();
1022 if (aDMax > myTolReached3d) {
1023 myTolReached3d = aDMax;
1028 //=======================================================================
1029 //function : MakeCurve
1031 //=======================================================================
1032 void IntTools_FaceFace::MakeCurve(const Standard_Integer Index,
1033 const Handle(Adaptor3d_TopolTool)& dom1,
1034 const Handle(Adaptor3d_TopolTool)& dom2)
1036 Standard_Boolean bDone, rejectSurface, reApprox, bAvoidLineConstructor;
1037 Standard_Boolean ok, bPCurvesOk;
1038 Standard_Integer i, j, aNbParts;
1039 Standard_Real fprm, lprm;
1040 Standard_Real Tolpc;
1041 Handle(IntPatch_Line) L;
1042 IntPatch_IType typl;
1043 Handle(Geom_Curve) newc;
1045 const Standard_Real TOLCHECK =0.0000001;
1046 const Standard_Real TOLANGCHECK=0.1;
1048 rejectSurface = Standard_False;
1049 reApprox = Standard_False;
1051 bPCurvesOk = Standard_True;
1055 Tolpc = myTolApprox;
1056 bAvoidLineConstructor = Standard_False;
1057 L = myIntersector.Line(Index);
1058 typl = L->ArcType();
1060 if(typl==IntPatch_Walking) {
1061 Handle(IntPatch_Line) anewL;
1063 Handle(IntPatch_WLine) aWLine (Handle(IntPatch_WLine)::DownCast(L));
1064 //DumpWLine(aWLine);
1066 anewL = ComputePurgedWLine(aWLine);
1067 if(anewL.IsNull()) {
1072 //Handle(IntPatch_WLine) aWLineX (Handle(IntPatch_WLine)::DownCast(L));
1073 //DumpWLine(aWLineX);
1076 if(!myListOfPnts.IsEmpty()) {
1077 bAvoidLineConstructor = Standard_True;
1080 Standard_Integer nbp = aWLine->NbPnts();
1081 const IntSurf_PntOn2S& p1 = aWLine->Point(1);
1082 const IntSurf_PntOn2S& p2 = aWLine->Point(nbp);
1084 const gp_Pnt& P1 = p1.Value();
1085 const gp_Pnt& P2 = p2.Value();
1087 if(P1.SquareDistance(P2) < 1.e-14) {
1088 bAvoidLineConstructor = Standard_False;
1096 if(!bAvoidLineConstructor) {
1097 myLConstruct.Perform(L);
1099 bDone=myLConstruct.IsDone();
1105 if(typl != IntPatch_Restriction)
1107 aNbParts=myLConstruct.NbParts();
1118 //########################################
1119 // Line, Parabola, Hyperbola
1120 //########################################
1122 case IntPatch_Parabola:
1123 case IntPatch_Hyperbola: {
1124 if (typl == IntPatch_Lin) {
1126 new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line());
1129 else if (typl == IntPatch_Parabola) {
1131 new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola());
1134 else if (typl == IntPatch_Hyperbola) {
1136 new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola());
1140 if (typl == IntPatch_Lin) {
1141 TolR3d (myFace1, myFace2, myTolReached3d);
1144 aNbParts=myLConstruct.NbParts();
1145 for (i=1; i<=aNbParts; i++) {
1146 Standard_Boolean bFNIt, bLPIt;
1148 myLConstruct.Part(i, fprm, lprm);
1150 bFNIt=Precision::IsNegativeInfinite(fprm);
1151 bLPIt=Precision::IsPositiveInfinite(lprm);
1153 if (!bFNIt && !bLPIt) {
1155 IntTools_Curve aCurve;
1157 Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm);
1158 aCurve.SetCurve(aCT3D);
1159 if (typl == IntPatch_Parabola) {
1160 Standard_Real aTolF1, aTolF2, aTolBase;
1162 aTolF1 = BRep_Tool::Tolerance(myFace1);
1163 aTolF2 = BRep_Tool::Tolerance(myFace2);
1164 aTolBase=aTolF1+aTolF2;
1165 myTolReached3d=IntTools_Tools::CurveTolerance(aCT3D, aTolBase);
1168 aCurve.SetCurve(new Geom_TrimmedCurve(newc, fprm, lprm));
1170 Handle (Geom2d_Curve) C2d;
1171 GeomInt_IntSS::BuildPCurves(fprm, lprm, Tolpc,
1172 myHS1->ChangeSurface().Surface(), newc, C2d);
1173 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1174 myTolReached2d=Tolpc;
1177 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1180 Handle(Geom2d_BSplineCurve) H1;
1182 aCurve.SetFirstCurve2d(H1);
1186 Handle (Geom2d_Curve) C2d;
1187 GeomInt_IntSS::BuildPCurves(fprm, lprm, Tolpc,
1188 myHS2->ChangeSurface().Surface(), newc, C2d);
1189 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1190 myTolReached2d=Tolpc;
1193 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1196 Handle(Geom2d_BSplineCurve) H1;
1198 aCurve.SetSecondCurve2d(H1);
1200 mySeqOfCurve.Append(aCurve);
1201 } //if (!bFNIt && !bLPIt) {
1203 // on regarde si on garde
1205 Standard_Real aTestPrm, dT=100.;
1208 if (bFNIt && !bLPIt) {
1211 else if (!bFNIt && bLPIt) {
1215 // i.e, if (bFNIt && bLPIt)
1216 aTestPrm=IntTools_Tools::IntermediatePoint(-dT, dT);
1219 gp_Pnt ptref(newc->Value(aTestPrm));
1221 GeomAbs_SurfaceType typS1 = myHS1->GetType();
1222 GeomAbs_SurfaceType typS2 = myHS2->GetType();
1223 if( typS1 == GeomAbs_SurfaceOfExtrusion ||
1224 typS1 == GeomAbs_OffsetSurface ||
1225 typS1 == GeomAbs_SurfaceOfRevolution ||
1226 typS2 == GeomAbs_SurfaceOfExtrusion ||
1227 typS2 == GeomAbs_OffsetSurface ||
1228 typS2 == GeomAbs_SurfaceOfRevolution) {
1229 Handle(Geom2d_BSplineCurve) H1;
1230 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1234 Standard_Real u1, v1, u2, v2, Tol;
1236 Tol = Precision::Confusion();
1237 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1238 ok = (dom1->Classify(gp_Pnt2d(u1, v1), Tol) != TopAbs_OUT);
1240 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1243 Handle(Geom2d_BSplineCurve) H1;
1244 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1247 }// for (i=1; i<=aNbParts; i++) {
1248 }// case IntPatch_Lin: case IntPatch_Parabola: case IntPatch_Hyperbola:
1251 //########################################
1252 // Circle and Ellipse
1253 //########################################
1254 case IntPatch_Circle:
1255 case IntPatch_Ellipse: {
1257 if (typl == IntPatch_Circle) {
1258 newc = new Geom_Circle
1259 (Handle(IntPatch_GLine)::DownCast(L)->Circle());
1261 else { //IntPatch_Ellipse
1262 newc = new Geom_Ellipse
1263 (Handle(IntPatch_GLine)::DownCast(L)->Ellipse());
1267 TolR3d (myFace1, myFace2, myTolReached3d);
1269 aNbParts=myLConstruct.NbParts();
1271 Standard_Real aPeriod, aNul;
1272 TColStd_SequenceOfReal aSeqFprm, aSeqLprm;
1277 for (i=1; i<=aNbParts; i++) {
1278 myLConstruct.Part(i, fprm, lprm);
1280 if (fprm < aNul && lprm > aNul) {
1281 // interval that goes through 0. is divided on two intervals;
1282 while (fprm<aNul || fprm>aPeriod) fprm=fprm+aPeriod;
1283 while (lprm<aNul || lprm>aPeriod) lprm=lprm+aPeriod;
1285 if((aPeriod - fprm) > Tolpc) {
1286 aSeqFprm.Append(fprm);
1287 aSeqLprm.Append(aPeriod);
1290 gp_Pnt P1 = newc->Value(fprm);
1291 gp_Pnt P2 = newc->Value(aPeriod);
1292 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1293 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1295 if(P1.Distance(P2) > aTolDist) {
1296 Standard_Real anewpar = fprm;
1298 if(ParameterOutOfBoundary(fprm, newc, myFace1, myFace2,
1299 lprm, Standard_False, anewpar, myContext)) {
1302 aSeqFprm.Append(fprm);
1303 aSeqLprm.Append(aPeriod);
1308 if((lprm - aNul) > Tolpc) {
1309 aSeqFprm.Append(aNul);
1310 aSeqLprm.Append(lprm);
1313 gp_Pnt P1 = newc->Value(aNul);
1314 gp_Pnt P2 = newc->Value(lprm);
1315 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1316 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1318 if(P1.Distance(P2) > aTolDist) {
1319 Standard_Real anewpar = lprm;
1321 if(ParameterOutOfBoundary(lprm, newc, myFace1, myFace2,
1322 fprm, Standard_True, anewpar, myContext)) {
1325 aSeqFprm.Append(aNul);
1326 aSeqLprm.Append(lprm);
1332 aSeqFprm.Append(fprm);
1333 aSeqLprm.Append(lprm);
1338 aNbParts=aSeqFprm.Length();
1339 for (i=1; i<=aNbParts; i++) {
1343 Standard_Real aRealEpsilon=RealEpsilon();
1344 if (Abs(fprm) > aRealEpsilon || Abs(lprm-2.*M_PI) > aRealEpsilon) {
1345 //==============================================
1347 IntTools_Curve aCurve;
1348 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1349 aCurve.SetCurve(aTC3D);
1350 fprm=aTC3D->FirstParameter();
1351 lprm=aTC3D->LastParameter ();
1353 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {////
1355 Handle (Geom2d_Curve) C2d;
1356 GeomInt_IntSS::BuildPCurves(fprm, lprm, Tolpc,
1357 myHS1->ChangeSurface().Surface(), newc, C2d);
1358 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1359 myTolReached2d=Tolpc;
1362 aCurve.SetFirstCurve2d(C2d);
1365 Handle(Geom2d_BSplineCurve) H1;
1366 aCurve.SetFirstCurve2d(H1);
1371 Handle (Geom2d_Curve) C2d;
1372 GeomInt_IntSS::BuildPCurves(fprm,lprm,Tolpc,
1373 myHS2->ChangeSurface().Surface(),newc,C2d);
1374 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1375 myTolReached2d=Tolpc;
1378 aCurve.SetSecondCurve2d(C2d);
1381 Handle(Geom2d_BSplineCurve) H1;
1382 aCurve.SetSecondCurve2d(H1);
1387 Handle(Geom2d_BSplineCurve) H1;
1388 aCurve.SetFirstCurve2d(H1);
1389 aCurve.SetSecondCurve2d(H1);
1391 mySeqOfCurve.Append(aCurve);
1392 //==============================================
1393 } //if (Abs(fprm) > RealEpsilon() || Abs(lprm-2.*M_PI) > RealEpsilon())
1396 // on regarde si on garde
1399 // if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*M_PI) < RealEpsilon()) {
1400 if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*M_PI) <= aRealEpsilon) {
1401 IntTools_Curve aCurve;
1402 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1403 aCurve.SetCurve(aTC3D);
1404 fprm=aTC3D->FirstParameter();
1405 lprm=aTC3D->LastParameter ();
1408 Handle (Geom2d_Curve) C2d;
1409 GeomInt_IntSS::BuildPCurves(fprm,lprm,Tolpc,
1410 myHS1->ChangeSurface().Surface(),newc,C2d);
1411 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1412 myTolReached2d=Tolpc;
1415 aCurve.SetFirstCurve2d(C2d);
1418 Handle(Geom2d_BSplineCurve) H1;
1419 aCurve.SetFirstCurve2d(H1);
1423 Handle (Geom2d_Curve) C2d;
1424 GeomInt_IntSS::BuildPCurves(fprm,lprm,Tolpc,
1425 myHS2->ChangeSurface().Surface(),newc,C2d);
1426 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1427 myTolReached2d=Tolpc;
1430 aCurve.SetSecondCurve2d(C2d);
1433 Handle(Geom2d_BSplineCurve) H1;
1434 aCurve.SetSecondCurve2d(H1);
1436 mySeqOfCurve.Append(aCurve);
1441 Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol;
1443 aTwoPIdiv17=2.*M_PI/17.;
1445 for (j=0; j<=17; j++) {
1446 gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
1447 Tol = Precision::Confusion();
1449 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1450 ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT);
1452 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1455 IntTools_Curve aCurve;
1456 aCurve.SetCurve(newc);
1457 //==============================================
1458 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {
1461 Handle (Geom2d_Curve) C2d;
1462 GeomInt_IntSS::BuildPCurves(fprm, lprm, Tolpc,
1463 myHS1->ChangeSurface().Surface(), newc, C2d);
1464 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1465 myTolReached2d=Tolpc;
1468 aCurve.SetFirstCurve2d(C2d);
1471 Handle(Geom2d_BSplineCurve) H1;
1472 aCurve.SetFirstCurve2d(H1);
1476 Handle (Geom2d_Curve) C2d;
1477 GeomInt_IntSS::BuildPCurves(fprm, lprm, Tolpc,
1478 myHS2->ChangeSurface().Surface(), newc, C2d);
1479 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1480 myTolReached2d=Tolpc;
1483 aCurve.SetSecondCurve2d(C2d);
1487 Handle(Geom2d_BSplineCurve) H1;
1488 aCurve.SetSecondCurve2d(H1);
1490 }// end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse)
1493 Handle(Geom2d_BSplineCurve) H1;
1495 aCurve.SetFirstCurve2d(H1);
1496 aCurve.SetSecondCurve2d(H1);
1498 //==============================================
1500 mySeqOfCurve.Append(aCurve);
1503 }// end of if (ok) {
1504 }// end of for (Standard_Integer j=0; j<=17; j++)
1505 }// end of else { on regarde si on garde
1506 }// for (i=1; i<=myLConstruct.NbParts(); i++)
1507 }// IntPatch_Circle: IntPatch_Ellipse:
1510 case IntPatch_Analytic: {
1511 IntSurf_Quadric quad1,quad2;
1512 GeomAbs_SurfaceType typs = myHS1->Surface().GetType();
1516 quad1.SetValue(myHS1->Surface().Plane());
1518 case GeomAbs_Cylinder:
1519 quad1.SetValue(myHS1->Surface().Cylinder());
1522 quad1.SetValue(myHS1->Surface().Cone());
1524 case GeomAbs_Sphere:
1525 quad1.SetValue(myHS1->Surface().Sphere());
1528 quad1.SetValue(myHS1->Surface().Torus());
1531 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 1");
1534 typs = myHS2->Surface().GetType();
1538 quad2.SetValue(myHS2->Surface().Plane());
1540 case GeomAbs_Cylinder:
1541 quad2.SetValue(myHS2->Surface().Cylinder());
1544 quad2.SetValue(myHS2->Surface().Cone());
1546 case GeomAbs_Sphere:
1547 quad2.SetValue(myHS2->Surface().Sphere());
1550 quad2.SetValue(myHS2->Surface().Torus());
1553 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 2");
1557 IntPatch_ALineToWLine convert (quad1, quad2);
1560 aNbParts=myLConstruct.NbParts();
1561 for (i=1; i<=aNbParts; i++) {
1562 myLConstruct.Part(i, fprm, lprm);
1563 Handle(IntPatch_WLine) WL =
1564 convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm);
1566 Handle(Geom2d_BSplineCurve) H1;
1567 Handle(Geom2d_BSplineCurve) H2;
1570 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1574 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1577 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1581 else { // myApprox=TRUE
1582 GeomInt_WLApprox theapp3d;
1584 Standard_Real tol2d = myTolApprox;
1586 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True);
1588 aNbParts=myLConstruct.NbParts();
1589 for (i=1; i<=aNbParts; i++) {
1590 myLConstruct.Part(i, fprm, lprm);
1591 Handle(IntPatch_WLine) WL =
1592 convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
1594 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
1596 if (!theapp3d.IsDone()) {
1598 Handle(Geom2d_BSplineCurve) H1;
1599 Handle(Geom2d_BSplineCurve) H2;
1602 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1606 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1609 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1613 if(myApprox1 || myApprox2) {
1614 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) {
1615 myTolReached2d = theapp3d.TolReached2d();
1619 if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) {
1620 myTolReached3d = theapp3d.TolReached3d();
1623 Standard_Integer aNbMultiCurves, nbpoles;
1624 aNbMultiCurves=theapp3d.NbMultiCurves();
1625 for (j=1; j<=aNbMultiCurves; j++) {
1626 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1627 nbpoles = mbspc.NbPoles();
1629 TColgp_Array1OfPnt tpoles(1, nbpoles);
1630 mbspc.Curve(1, tpoles);
1631 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1633 mbspc.Multiplicities(),
1636 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1637 Check.FixTangent(Standard_True,Standard_True);
1639 IntTools_Curve aCurve;
1640 aCurve.SetCurve(BS);
1643 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1644 mbspc.Curve(2,tpoles2d);
1645 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1647 mbspc.Multiplicities(),
1650 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1651 newCheck.FixTangent(Standard_True,Standard_True);
1653 aCurve.SetFirstCurve2d(BS2);
1656 Handle(Geom2d_BSplineCurve) H1;
1657 aCurve.SetFirstCurve2d(H1);
1661 TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
1662 Standard_Integer TwoOrThree;
1663 TwoOrThree=myApprox1 ? 3 : 2;
1664 mbspc.Curve(TwoOrThree, tpoles2d);
1665 Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
1667 mbspc.Multiplicities(),
1670 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1671 newCheck.FixTangent(Standard_True,Standard_True);
1673 aCurve.SetSecondCurve2d(BS2);
1676 Handle(Geom2d_BSplineCurve) H2;
1677 aCurve.SetSecondCurve2d(H2);
1680 mySeqOfCurve.Append(aCurve);
1682 }// for (j=1; j<=aNbMultiCurves; j++) {
1683 }// else from if (!theapp3d.IsDone())
1684 }// for (i=1; i<=aNbParts; i++) {
1685 }// else { // myApprox=TRUE
1686 }// case IntPatch_Analytic:
1689 case IntPatch_Walking:{
1690 Handle(IntPatch_WLine) WL =
1691 Handle(IntPatch_WLine)::DownCast(L);
1693 Standard_Integer ifprm, ilprm;
1697 if(!bAvoidLineConstructor){
1698 aNbParts=myLConstruct.NbParts();
1700 for (i=1; i<=aNbParts; ++i) {
1701 Handle(Geom2d_BSplineCurve) H1, H2;
1702 Handle(Geom_Curve) aBSp;
1704 if(bAvoidLineConstructor) {
1706 ilprm = WL->NbPnts();
1709 myLConstruct.Part(i, fprm, lprm);
1710 ifprm=(Standard_Integer)fprm;
1711 ilprm=(Standard_Integer)lprm;
1715 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1719 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1722 aBSp=MakeBSpline(WL, ifprm, ilprm);
1723 IntTools_Curve aIC(aBSp, H1, H2);
1724 mySeqOfCurve.Append(aIC);
1725 }// for (i=1; i<=aNbParts; ++i) {
1726 }// if (!myApprox) {
1729 Standard_Boolean bIsDecomposited;
1730 Standard_Integer nbiter, aNbSeqOfL;
1731 Standard_Real tol2d, aTolApproxImp;
1732 IntPatch_SequenceOfLine aSeqOfL;
1733 GeomInt_WLApprox theapp3d;
1734 Approx_ParametrizationType aParType = Approx_ChordLength;
1736 Standard_Boolean anApprox1 = myApprox1;
1737 Standard_Boolean anApprox2 = myApprox2;
1739 aTolApproxImp=1.e-5;
1740 tol2d = myTolApprox;
1742 GeomAbs_SurfaceType typs1, typs2;
1743 typs1 = myHS1->Surface().GetType();
1744 typs2 = myHS2->Surface().GetType();
1745 Standard_Boolean anWithPC = Standard_True;
1747 if(typs1 == GeomAbs_Cylinder && typs2 == GeomAbs_Sphere) {
1749 ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere());
1751 else if (typs1 == GeomAbs_Sphere && typs2 == GeomAbs_Cylinder) {
1753 ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere());
1757 myTolApprox = aTolApproxImp;//1.e-5;
1758 anApprox1 = Standard_False;
1759 anApprox2 = Standard_False;
1761 tol2d = myTolApprox;
1764 if(myHS1 == myHS2) {
1765 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1766 rejectSurface = Standard_True;
1769 if(reApprox && !rejectSurface)
1770 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1772 Standard_Integer iDegMax, iDegMin, iNbIter;
1774 ApproxParameters(myHS1, myHS2, iDegMin, iDegMax, iNbIter);
1775 theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, iNbIter, Standard_True, aParType);
1779 Standard_Real aReachedTol = Precision::Confusion();
1780 bIsDecomposited=DecompositionOfWLine(WL,
1786 bAvoidLineConstructor,
1790 if ( bIsDecomposited && ( myTolReached3d < aReachedTol ) ) {
1791 myTolReached3d = aReachedTol;
1794 aNbSeqOfL=aSeqOfL.Length();
1796 if (bIsDecomposited) {
1802 if (!bAvoidLineConstructor) {
1803 aNbParts=myLConstruct.NbParts();
1808 for(i = 1; i <= nbiter; ++i) {
1809 if(bIsDecomposited) {
1810 WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i));
1812 ilprm = WL->NbPnts();
1815 if(bAvoidLineConstructor) {
1817 ilprm = WL->NbPnts();
1820 myLConstruct.Part(i, fprm, lprm);
1821 ifprm = (Standard_Integer)fprm;
1822 ilprm = (Standard_Integer)lprm;
1826 //-- Si une des surfaces est un plan , on approxime en 2d
1827 //-- sur cette surface et on remonte les points 2d en 3d.
1828 if(typs1 == GeomAbs_Plane) {
1829 theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm);
1831 else if(typs2 == GeomAbs_Plane) {
1832 theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm);
1836 if (myHS1 != myHS2){
1837 if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) &&
1838 (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) {
1840 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType);
1842 Standard_Boolean bUseSurfaces;
1843 bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm, ilprm);
1846 rejectSurface = Standard_True;
1848 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1853 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm);
1856 if (!theapp3d.IsDone()) {
1857 Handle(Geom2d_BSplineCurve) H1;
1858 Handle(Geom2d_BSplineCurve) H2;
1860 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
1863 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1867 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1870 IntTools_Curve aIC(aBSp, H1, H2);
1871 mySeqOfCurve.Append(aIC);
1875 if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) {
1876 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) {
1877 myTolReached2d = theapp3d.TolReached2d();
1880 if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) {
1881 myTolReached3d = myTolReached2d;
1883 if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
1884 if (myTolReached3d<1.e-6) {
1885 myTolReached3d = theapp3d.TolReached3d();
1886 myTolReached3d=1.e-6;
1890 else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) {
1891 myTolReached3d = theapp3d.TolReached3d();
1894 Standard_Integer aNbMultiCurves, nbpoles;
1895 aNbMultiCurves=theapp3d.NbMultiCurves();
1896 for (j=1; j<=aNbMultiCurves; j++) {
1897 if(typs1 == GeomAbs_Plane) {
1898 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1899 nbpoles = mbspc.NbPoles();
1901 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1902 TColgp_Array1OfPnt tpoles(1,nbpoles);
1904 mbspc.Curve(1,tpoles2d);
1905 const gp_Pln& Pln = myHS1->Surface().Plane();
1907 Standard_Integer ik;
1908 for(ik = 1; ik<= nbpoles; ik++) {
1910 ElSLib::Value(tpoles2d.Value(ik).X(),
1911 tpoles2d.Value(ik).Y(),
1915 Handle(Geom_BSplineCurve) BS =
1916 new Geom_BSplineCurve(tpoles,
1918 mbspc.Multiplicities(),
1920 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1921 Check.FixTangent(Standard_True, Standard_True);
1923 IntTools_Curve aCurve;
1924 aCurve.SetCurve(BS);
1927 Handle(Geom2d_BSplineCurve) BS1 =
1928 new Geom2d_BSplineCurve(tpoles2d,
1930 mbspc.Multiplicities(),
1932 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
1933 Check1.FixTangent(Standard_True,Standard_True);
1935 // ############################################
1936 if(!rejectSurface && !reApprox) {
1937 Standard_Boolean isValid = IsCurveValid(BS1);
1939 reApprox = Standard_True;
1943 // ############################################
1944 aCurve.SetFirstCurve2d(BS1);
1947 Handle(Geom2d_BSplineCurve) H1;
1948 aCurve.SetFirstCurve2d(H1);
1952 mbspc.Curve(2, tpoles2d);
1954 Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
1956 mbspc.Multiplicities(),
1958 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1959 newCheck.FixTangent(Standard_True,Standard_True);
1961 // ###########################################
1962 if(!rejectSurface && !reApprox) {
1963 Standard_Boolean isValid = IsCurveValid(BS2);
1965 reApprox = Standard_True;
1969 // ###########################################
1971 aCurve.SetSecondCurve2d(BS2);
1974 Handle(Geom2d_BSplineCurve) H2;
1976 aCurve.SetSecondCurve2d(H2);
1979 mySeqOfCurve.Append(aCurve);
1980 }//if(typs1 == GeomAbs_Plane) {
1982 else if(typs2 == GeomAbs_Plane) {
1983 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1984 nbpoles = mbspc.NbPoles();
1986 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1987 TColgp_Array1OfPnt tpoles(1,nbpoles);
1988 mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d);
1989 const gp_Pln& Pln = myHS2->Surface().Plane();
1991 Standard_Integer ik;
1992 for(ik = 1; ik<= nbpoles; ik++) {
1994 ElSLib::Value(tpoles2d.Value(ik).X(),
1995 tpoles2d.Value(ik).Y(),
2000 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
2002 mbspc.Multiplicities(),
2004 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2005 Check.FixTangent(Standard_True,Standard_True);
2007 IntTools_Curve aCurve;
2008 aCurve.SetCurve(BS);
2011 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
2013 mbspc.Multiplicities(),
2015 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
2016 Check1.FixTangent(Standard_True,Standard_True);
2018 // ###########################################
2019 if(!rejectSurface && !reApprox) {
2020 Standard_Boolean isValid = IsCurveValid(BS1);
2022 reApprox = Standard_True;
2026 // ###########################################
2027 bPCurvesOk = CheckPCurve(BS1, myFace2);
2028 aCurve.SetSecondCurve2d(BS1);
2031 Handle(Geom2d_BSplineCurve) H2;
2032 aCurve.SetSecondCurve2d(H2);
2036 mbspc.Curve(1,tpoles2d);
2037 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
2039 mbspc.Multiplicities(),
2041 GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK);
2042 Check2.FixTangent(Standard_True,Standard_True);
2044 // ###########################################
2045 if(!rejectSurface && !reApprox) {
2046 Standard_Boolean isValid = IsCurveValid(BS2);
2048 reApprox = Standard_True;
2052 // ###########################################
2053 bPCurvesOk = bPCurvesOk && CheckPCurve(BS2, myFace1);
2054 aCurve.SetFirstCurve2d(BS2);
2057 Handle(Geom2d_BSplineCurve) H1;
2059 aCurve.SetFirstCurve2d(H1);
2062 //if points of the pcurves are out of the faces bounds
2063 //create 3d and 2d curves without approximation
2065 Handle(Geom2d_BSplineCurve) H1, H2;
2066 bPCurvesOk = Standard_True;
2068 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
2071 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
2072 bPCurvesOk = CheckPCurve(H1, myFace1);
2076 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
2077 bPCurvesOk = bPCurvesOk && CheckPCurve(H2, myFace2);
2080 //if pcurves created without approximation are out of the
2081 //faces bounds, use approximated 3d and 2d curves
2083 IntTools_Curve aIC(aBSp, H1, H2);
2084 mySeqOfCurve.Append(aIC);
2086 mySeqOfCurve.Append(aCurve);
2089 mySeqOfCurve.Append(aCurve);
2091 }// else if(typs2 == GeomAbs_Plane)
2093 else { //typs2 != GeomAbs_Plane && typs1 != GeomAbs_Plane
2094 Standard_Boolean bIsValid1, bIsValid2;
2095 Handle(Geom_BSplineCurve) BS;
2096 Handle(Geom2d_BSplineCurve) aH2D;
2097 IntTools_Curve aCurve;
2099 bIsValid1=Standard_True;
2100 bIsValid2=Standard_True;
2102 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2103 nbpoles = mbspc.NbPoles();
2104 TColgp_Array1OfPnt tpoles(1,nbpoles);
2105 mbspc.Curve(1,tpoles);
2106 BS=new Geom_BSplineCurve(tpoles,
2108 mbspc.Multiplicities(),
2110 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2111 Check.FixTangent(Standard_True,Standard_True);
2113 aCurve.SetCurve(BS);
2114 aCurve.SetFirstCurve2d(aH2D);
2115 aCurve.SetSecondCurve2d(aH2D);
2119 Handle(Geom2d_BSplineCurve) BS1;
2120 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2121 mbspc.Curve(2,tpoles2d);
2123 BS1=new Geom2d_BSplineCurve(tpoles2d,
2125 mbspc.Multiplicities(),
2127 GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK);
2128 newCheck.FixTangent(Standard_True,Standard_True);
2131 bIsValid1=CheckPCurve(BS1, myFace1);
2134 aCurve.SetFirstCurve2d(BS1);
2137 Handle(Geom2d_BSplineCurve) BS1;
2138 fprm = BS->FirstParameter();
2139 lprm = BS->LastParameter();
2141 Handle(Geom2d_Curve) C2d;
2142 Standard_Real aTol = myTolApprox;
2143 GeomInt_IntSS::BuildPCurves(fprm, lprm, aTol,
2144 myHS1->ChangeSurface().Surface(), BS, C2d);
2145 BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2146 aCurve.SetFirstCurve2d(BS1);
2148 } // if(myApprox1) {
2152 Handle(Geom2d_BSplineCurve) BS2;
2153 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2154 mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d);
2155 BS2=new Geom2d_BSplineCurve(tpoles2d,
2157 mbspc.Multiplicities(),
2159 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2160 newCheck.FixTangent(Standard_True,Standard_True);
2163 bIsValid2=CheckPCurve(BS2, myFace2);
2165 aCurve.SetSecondCurve2d(BS2);
2168 Handle(Geom2d_BSplineCurve) BS2;
2169 fprm = BS->FirstParameter();
2170 lprm = BS->LastParameter();
2172 Handle(Geom2d_Curve) C2d;
2173 Standard_Real aTol = myTolApprox;
2174 GeomInt_IntSS::BuildPCurves(fprm, lprm, aTol,
2175 myHS2->ChangeSurface().Surface(), BS, C2d);
2176 BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2177 aCurve.SetSecondCurve2d(BS2);
2180 if (!bIsValid1 || !bIsValid2) {
2181 myTolApprox=aTolApproxImp;//1.e-5;
2182 tol2d = myTolApprox;
2183 reApprox = Standard_True;
2187 mySeqOfCurve.Append(aCurve);
2193 }// case IntPatch_Walking:{
2196 case IntPatch_Restriction:
2198 GeomAbs_SurfaceType typS1 = myHS1->Surface().GetType();
2199 GeomAbs_SurfaceType typS2 = myHS2->Surface().GetType();
2200 Standard_Boolean isAnalS1 = Standard_False;
2204 case GeomAbs_Cylinder:
2205 case GeomAbs_Sphere:
2207 case GeomAbs_Torus: isAnalS1 = Standard_True; break;
2211 Standard_Integer isAnalS2 = Standard_False;
2215 case GeomAbs_Cylinder:
2216 case GeomAbs_Sphere:
2218 case GeomAbs_Torus: isAnalS2 = Standard_True; break;
2222 Handle(IntPatch_RLine) RL =
2223 Handle(IntPatch_RLine)::DownCast(L);
2224 Handle(Geom_Curve) aC3d;
2225 Handle(Geom2d_Curve) aC2d1, aC2d2;
2226 Standard_Real aTolReached;
2227 GeomInt_IntSS::TreatRLine(RL, myHS1, myHS2, aC3d,
2228 aC2d1, aC2d2, aTolReached);
2233 Bnd_Box2d aBox1, aBox2;
2235 const Standard_Real aU1f = myHS1->FirstUParameter(),
2236 aV1f = myHS1->FirstVParameter(),
2237 aU1l = myHS1->LastUParameter(),
2238 aV1l = myHS1->LastVParameter();
2239 const Standard_Real aU2f = myHS2->FirstUParameter(),
2240 aV2f = myHS2->FirstVParameter(),
2241 aU2l = myHS2->LastUParameter(),
2242 aV2l = myHS2->LastVParameter();
2244 aBox1.Add(gp_Pnt2d(aU1f, aV1f));
2245 aBox1.Add(gp_Pnt2d(aU1l, aV1l));
2246 aBox2.Add(gp_Pnt2d(aU2f, aV2f));
2247 aBox2.Add(gp_Pnt2d(aU2l, aV2l));
2249 GeomInt_VectorOfReal anArrayOfParameters;
2251 //We consider here that the intersection line is same-parameter-line
2252 anArrayOfParameters.Append(aC3d->FirstParameter());
2253 anArrayOfParameters.Append(aC3d->LastParameter());
2256 TrimILineOnSurfBoundaries(aC2d1, aC2d2, aBox1, aBox2, anArrayOfParameters);
2258 const Standard_Integer aNbIntersSolutionsm1 = anArrayOfParameters.Length() - 1;
2261 for(Standard_Integer anInd = 0; anInd < aNbIntersSolutionsm1; anInd++)
2263 const Standard_Real aParF = anArrayOfParameters(anInd),
2264 aParL = anArrayOfParameters(anInd+1);
2266 if((aParL - aParF) <= Precision::PConfusion())
2269 const Standard_Real aPar = 0.5*(aParF + aParL);
2272 Handle(Geom2d_Curve) aCurv2d1, aCurv2d2;
2275 aC2d1->D0(aPar, aPt);
2277 if(aBox1.IsOut(aPt))
2281 aCurv2d1 = new Geom2d_TrimmedCurve(aC2d1, aParF, aParL);
2286 aC2d2->D0(aPar, aPt);
2288 if(aBox2.IsOut(aPt))
2292 aCurv2d2 = new Geom2d_TrimmedCurve(aC2d2, aParF, aParL);
2295 Handle(Geom_Curve) aCurv3d = new Geom_TrimmedCurve(aC3d, aParF, aParL);
2297 IntTools_Curve aIC(aCurv3d, aCurv2d1, aCurv2d2);
2298 mySeqOfCurve.Append(aIC);
2308 //=======================================================================
2309 //function : Parameters
2311 //=======================================================================
2312 void Parameters(const Handle(GeomAdaptor_HSurface)& HS1,
2313 const Handle(GeomAdaptor_HSurface)& HS2,
2314 const gp_Pnt& Ptref,
2321 IntSurf_Quadric quad1,quad2;
2322 GeomAbs_SurfaceType typs = HS1->Surface().GetType();
2326 quad1.SetValue(HS1->Surface().Plane());
2328 case GeomAbs_Cylinder:
2329 quad1.SetValue(HS1->Surface().Cylinder());
2332 quad1.SetValue(HS1->Surface().Cone());
2334 case GeomAbs_Sphere:
2335 quad1.SetValue(HS1->Surface().Sphere());
2338 quad1.SetValue(HS1->Surface().Torus());
2341 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2344 typs = HS2->Surface().GetType();
2347 quad2.SetValue(HS2->Surface().Plane());
2349 case GeomAbs_Cylinder:
2350 quad2.SetValue(HS2->Surface().Cylinder());
2353 quad2.SetValue(HS2->Surface().Cone());
2355 case GeomAbs_Sphere:
2356 quad2.SetValue(HS2->Surface().Sphere());
2359 quad2.SetValue(HS2->Surface().Torus());
2362 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2365 quad1.Parameters(Ptref,U1,V1);
2366 quad2.Parameters(Ptref,U2,V2);
2369 //=======================================================================
2370 //function : MakeBSpline
2372 //=======================================================================
2373 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL,
2374 const Standard_Integer ideb,
2375 const Standard_Integer ifin)
2377 Standard_Integer i,nbpnt = ifin-ideb+1;
2378 TColgp_Array1OfPnt poles(1,nbpnt);
2379 TColStd_Array1OfReal knots(1,nbpnt);
2380 TColStd_Array1OfInteger mults(1,nbpnt);
2381 Standard_Integer ipidebm1;
2382 for(i=1,ipidebm1=i+ideb-1; i<=nbpnt;ipidebm1++, i++) {
2383 poles(i) = WL->Point(ipidebm1).Value();
2387 mults(1) = mults(nbpnt) = 2;
2389 new Geom_BSplineCurve(poles,knots,mults,1);
2393 //=======================================================================
2394 //function : MakeBSpline2d
2396 //=======================================================================
2397 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
2398 const Standard_Integer ideb,
2399 const Standard_Integer ifin,
2400 const Standard_Boolean onFirst)
2402 Standard_Integer i, nbpnt = ifin-ideb+1;
2403 TColgp_Array1OfPnt2d poles(1,nbpnt);
2404 TColStd_Array1OfReal knots(1,nbpnt);
2405 TColStd_Array1OfInteger mults(1,nbpnt);
2406 Standard_Integer ipidebm1;
2408 for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) {
2411 theWLine->Point(ipidebm1).ParametersOnS1(U, V);
2413 theWLine->Point(ipidebm1).ParametersOnS2(U, V);
2414 poles(i).SetCoord(U, V);
2418 mults(1) = mults(nbpnt) = 2;
2420 return new Geom2d_BSplineCurve(poles,knots,mults,1);
2422 //=======================================================================
2423 //function : PrepareLines3D
2425 //=======================================================================
2426 void IntTools_FaceFace::PrepareLines3D(const Standard_Boolean bToSplit)
2428 Standard_Integer i, aNbCurves;
2429 GeomAbs_SurfaceType aType1, aType2;
2430 IntTools_SequenceOfCurves aNewCvs;
2432 // 1. Treatment closed curves
2433 aNbCurves=mySeqOfCurve.Length();
2434 for (i=1; i<=aNbCurves; ++i) {
2435 const IntTools_Curve& aIC=mySeqOfCurve(i);
2438 Standard_Integer j, aNbC;
2439 IntTools_SequenceOfCurves aSeqCvs;
2441 aNbC=IntTools_Tools::SplitCurve(aIC, aSeqCvs);
2443 for (j=1; j<=aNbC; ++j) {
2444 const IntTools_Curve& aICNew=aSeqCvs(j);
2445 aNewCvs.Append(aICNew);
2449 aNewCvs.Append(aIC);
2453 aNewCvs.Append(aIC);
2457 // 2. Plane\Cone intersection when we had 4 curves
2458 aType1=myHS1->GetType();
2459 aType2=myHS2->GetType();
2460 aNbCurves=aNewCvs.Length();
2462 if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone) ||
2463 (aType2==GeomAbs_Plane && aType1==GeomAbs_Cone)) {
2465 GeomAbs_CurveType aCType1;
2467 aCType1=aNewCvs(1).Type();
2468 if (aCType1==GeomAbs_Line) {
2469 IntTools_SequenceOfCurves aSeqIn, aSeqOut;
2471 for (i=1; i<=aNbCurves; ++i) {
2472 const IntTools_Curve& aIC=aNewCvs(i);
2476 IntTools_Tools::RejectLines(aSeqIn, aSeqOut);
2479 aNbCurves=aSeqOut.Length();
2480 for (i=1; i<=aNbCurves; ++i) {
2481 const IntTools_Curve& aIC=aSeqOut(i);
2482 aNewCvs.Append(aIC);
2486 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone)...
2488 // 3. Fill mySeqOfCurve
2489 mySeqOfCurve.Clear();
2490 aNbCurves=aNewCvs.Length();
2491 for (i=1; i<=aNbCurves; ++i) {
2492 const IntTools_Curve& aIC=aNewCvs(i);
2493 mySeqOfCurve.Append(aIC);
2496 //=======================================================================
2497 //function : CorrectSurfaceBoundaries
2499 //=======================================================================
2500 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
2501 const Standard_Real theTolerance,
2502 Standard_Real& theumin,
2503 Standard_Real& theumax,
2504 Standard_Real& thevmin,
2505 Standard_Real& thevmax)
2507 Standard_Boolean enlarge, isuperiodic, isvperiodic;
2508 Standard_Real uinf, usup, vinf, vsup, delta;
2509 GeomAbs_SurfaceType aType;
2510 Handle(Geom_Surface) aSurface;
2512 aSurface = BRep_Tool::Surface(theFace);
2513 aSurface->Bounds(uinf, usup, vinf, vsup);
2514 delta = theTolerance;
2515 enlarge = Standard_False;
2517 GeomAdaptor_Surface anAdaptorSurface(aSurface);
2519 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
2520 Handle(Geom_Surface) aBasisSurface =
2521 (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface))->BasisSurface();
2523 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2524 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2529 if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2530 Handle(Geom_Surface) aBasisSurface =
2531 (Handle(Geom_OffsetSurface)::DownCast(aSurface))->BasisSurface();
2533 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2534 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2539 isuperiodic = anAdaptorSurface.IsUPeriodic();
2540 isvperiodic = anAdaptorSurface.IsVPeriodic();
2542 aType=anAdaptorSurface.GetType();
2543 if((aType==GeomAbs_BezierSurface) ||
2544 (aType==GeomAbs_BSplineSurface) ||
2545 (aType==GeomAbs_SurfaceOfExtrusion) ||
2546 (aType==GeomAbs_SurfaceOfRevolution) ||
2547 (aType==GeomAbs_Cylinder)) {
2548 enlarge=Standard_True;
2551 if(!isuperiodic && enlarge) {
2553 if(!Precision::IsInfinite(theumin) &&
2554 ((theumin - uinf) > delta))
2560 if(!Precision::IsInfinite(theumax) &&
2561 ((usup - theumax) > delta))
2567 if(!isvperiodic && enlarge) {
2568 if(!Precision::IsInfinite(thevmin) &&
2569 ((thevmin - vinf) > delta)) {
2575 if(!Precision::IsInfinite(thevmax) &&
2576 ((vsup - thevmax) > delta)) {
2585 Standard_Integer aNbP;
2586 Standard_Real aXP, dXfact, aXmid, aX1, aX2, aTolPA;
2588 aTolPA=Precision::Angular();
2591 aXP=anAdaptorSurface.UPeriod();
2592 dXfact=theumax-theumin;
2593 if (dXfact-aTolPA>aXP) {
2594 aXmid=0.5*(theumax+theumin);
2595 aNbP=RealToInt(aXmid/aXP);
2600 if (theumin>aTolPA) {
2601 aX1=theumin+aNbP*aXP;
2614 aXP=anAdaptorSurface.VPeriod();
2615 dXfact=thevmax-thevmin;
2616 if (dXfact-aTolPA>aXP) {
2617 aXmid=0.5*(thevmax+thevmin);
2618 aNbP=RealToInt(aXmid/aXP);
2623 if (thevmin>aTolPA) {
2624 aX1=thevmin+aNbP*aXP;
2637 if(isuperiodic || isvperiodic) {
2638 Standard_Boolean correct = Standard_False;
2639 Standard_Boolean correctU = Standard_False;
2640 Standard_Boolean correctV = Standard_False;
2642 TopExp_Explorer anExp;
2644 for(anExp.Init(theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
2645 if(BRep_Tool::IsClosed(TopoDS::Edge(anExp.Current()), theFace)) {
2646 correct = Standard_True;
2648 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
2650 for(Standard_Integer i = 0; i < 2; i++) {
2652 anEdge.Orientation(TopAbs_FORWARD);
2655 anEdge.Orientation(TopAbs_REVERSED);
2657 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l);
2659 if(aCurve.IsNull()) {
2660 correct = Standard_False;
2663 Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve);
2665 if(aLine.IsNull()) {
2666 correct = Standard_False;
2669 gp_Dir2d anUDir(1., 0.);
2670 gp_Dir2d aVDir(0., 1.);
2671 Standard_Real anAngularTolerance = Precision::Angular();
2673 correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance);
2674 correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance);
2676 gp_Pnt2d pp1 = aCurve->Value(f);
2678 gp_Pnt2d pp2 = aCurve->Value(l);
2687 Standard_Real umin, vmin, umax, vmax;
2688 aBox.Get(umin, vmin, umax, vmax);
2690 if(isuperiodic && correctU) {
2695 if(theumax > umax) {
2699 if(isvperiodic && correctV) {
2711 // The block is dedicated to determine whether WLine [ifprm, ilprm]
2712 // crosses the degenerated zone on each given surface or not.
2713 // If Yes -> We will not use info about surfaces during approximation
2714 // because inside degenerated zone of the surface the approx. algo.
2715 // uses wrong values of normal, etc., and resulting curve will have
2716 // oscillations that we would not like to have.
2721 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2722 const Handle(Geom_Surface)& aS,
2723 const Standard_Integer iDir);
2725 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2726 const TopoDS_Face& aF1,
2727 const TopoDS_Face& aF2);
2728 //=======================================================================
2729 //function : NotUseSurfacesForApprox
2731 //=======================================================================
2732 Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1,
2733 const TopoDS_Face& aF2,
2734 const Handle(IntPatch_WLine)& WL,
2735 const Standard_Integer ifprm,
2736 const Standard_Integer ilprm)
2738 Standard_Boolean bPInDZ;
2740 Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve();
2742 const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm);
2743 bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2);
2748 const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm);
2749 bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2);
2753 //=======================================================================
2754 //function : IsPointInDegeneratedZone
2756 //=======================================================================
2757 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2758 const TopoDS_Face& aF1,
2759 const TopoDS_Face& aF2)
2762 Standard_Boolean bFlag=Standard_True;
2763 Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22;
2764 Standard_Real U1, V1, U2, V2, aDelta, aD;
2767 Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1);
2768 aS1->Bounds(US11, US12, VS11, VS12);
2769 GeomAdaptor_Surface aGAS1(aS1);
2771 Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2);
2772 aS1->Bounds(US21, US22, VS21, VS22);
2773 GeomAdaptor_Surface aGAS2(aS2);
2775 //const gp_Pnt& aP=aP2S.Value();
2776 aP2S.Parameters(U1, V1, U2, V2);
2780 aD=aGAS1.UResolution(aDelta);
2781 aP2d.SetCoord(U1, V1);
2782 if (fabs(U1-US11) < aD) {
2783 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2788 if (fabs(U1-US12) < aD) {
2789 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2794 aD=aGAS1.VResolution(aDelta);
2795 if (fabs(V1-VS11) < aDelta) {
2796 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2801 if (fabs(V1-VS12) < aDelta) {
2802 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2808 aD=aGAS2.UResolution(aDelta);
2809 aP2d.SetCoord(U2, V2);
2810 if (fabs(U2-US21) < aDelta) {
2811 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2816 if (fabs(U2-US22) < aDelta) {
2817 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2822 aD=aGAS2.VResolution(aDelta);
2823 if (fabs(V2-VS21) < aDelta) {
2824 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2829 if (fabs(V2-VS22) < aDelta) {
2830 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2838 //=======================================================================
2839 //function : IsDegeneratedZone
2841 //=======================================================================
2842 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2843 const Handle(Geom_Surface)& aS,
2844 const Standard_Integer iDir)
2846 Standard_Boolean bFlag=Standard_True;
2847 Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD;
2848 Standard_Real aXm, aYm, aXb, aYb, aXe, aYe;
2849 aS->Bounds(US1, US2, VS1, VS2);
2851 gp_Pnt aPm, aPb, aPe;
2856 aS->D0(aXm, aYm, aPm);
2873 aS->D0(aXb, aYb, aPb);
2874 aS->D0(aXe, aYe, aPe);
2876 d1=aPm.Distance(aPb);
2877 d2=aPm.Distance(aPe);
2878 if (d1 < dD && d2 < dD) {
2895 aS->D0(aXb, aYb, aPb);
2896 aS->D0(aXe, aYe, aPe);
2898 d1=aPm.Distance(aPb);
2899 d2=aPm.Distance(aPe);
2900 if (d1 < dD && d2 < dD) {
2908 //=========================================================================
2909 // static function : ComputePurgedWLine
2910 // purpose : Removes equal points (leave one of equal points) from theWLine
2911 // and recompute vertex parameters.
2912 // Returns new WLine or null WLine if the number
2913 // of the points is less than 2.
2914 //=========================================================================
2915 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine) {
2917 Standard_Integer i, k, v, nb, nbvtx;
2918 Handle(IntPatch_WLine) aResult;
2919 nbvtx = theWLine->NbVertex();
2920 nb = theWLine->NbPnts();
2922 const IntSurf_PntOn2S& p1 = theWLine->Point(1);
2923 const IntSurf_PntOn2S& p2 = theWLine->Point(2);
2924 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
2929 Handle(IntPatch_WLine) aLocalWLine;
2930 Handle(IntPatch_WLine) aTmpWLine = theWLine;
2931 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
2932 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2933 for(i = 1; i <= nb; i++) {
2934 aLineOn2S->Add(theWLine->Point(i));
2937 for(v = 1; v <= nbvtx; v++) {
2938 aLocalWLine->AddVertex(theWLine->Vertex(v));
2941 for(i = 1; i <= aLineOn2S->NbPoints(); i++) {
2942 Standard_Integer aStartIndex = i + 1;
2943 Standard_Integer anEndIndex = i + 5;
2944 nb = aLineOn2S->NbPoints();
2945 anEndIndex = (anEndIndex > nb) ? nb : anEndIndex;
2947 if((aStartIndex > nb) || (anEndIndex <= 1)) {
2952 while(k <= anEndIndex) {
2955 IntSurf_PntOn2S p1 = aLineOn2S->Value(i);
2956 IntSurf_PntOn2S p2 = aLineOn2S->Value(k);
2958 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
2959 aTmpWLine = aLocalWLine;
2960 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2962 for(v = 1; v <= aTmpWLine->NbVertex(); v++) {
2963 IntPatch_Point aVertex = aTmpWLine->Vertex(v);
2964 Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine();
2966 if(avertexindex >= k) {
2967 aVertex.SetParameter(aVertex.ParameterOnLine() - 1.);
2969 aLocalWLine->AddVertex(aVertex);
2971 aLineOn2S->RemovePoint(k);
2980 if(aLineOn2S->NbPoints() > 1) {
2981 aResult = aLocalWLine;
2986 //=======================================================================
2989 //=======================================================================
2990 void TolR3d(const TopoDS_Face& aF1,
2991 const TopoDS_Face& aF2,
2992 Standard_Real& myTolReached3d)
2994 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
2996 aTolTresh=2.999999e-3;
2997 aTolF1 = BRep_Tool::Tolerance(aF1);
2998 aTolF2 = BRep_Tool::Tolerance(aF2);
2999 aTolFMax=Max(aTolF1, aTolF2);
3001 if (aTolFMax>aTolTresh) {
3002 myTolReached3d=aTolFMax;
3005 //=======================================================================
3006 //function : IsPointOnBoundary
3008 //=======================================================================
3009 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
3010 const Standard_Real theFirstBoundary,
3011 const Standard_Real theSecondBoundary,
3012 const Standard_Real theResolution,
3013 Standard_Boolean& IsOnFirstBoundary)
3015 Standard_Boolean bRet;
3017 Standard_Real adist;
3019 bRet=Standard_False;
3020 for(i = 0; i < 2; ++i) {
3021 IsOnFirstBoundary = (i == 0);
3022 if (IsOnFirstBoundary) {
3023 adist = fabs(theParameter - theFirstBoundary);
3026 adist = fabs(theParameter - theSecondBoundary);
3028 if(adist < theResolution) {
3034 // ------------------------------------------------------------------------------------------------
3035 // static function: FindPoint
3037 // ------------------------------------------------------------------------------------------------
3038 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3039 const gp_Pnt2d& theLastPoint,
3040 const Standard_Real theUmin,
3041 const Standard_Real theUmax,
3042 const Standard_Real theVmin,
3043 const Standard_Real theVmax,
3044 gp_Pnt2d& theNewPoint) {
3046 gp_Vec2d aVec(theFirstPoint, theLastPoint);
3047 Standard_Integer i = 0, j = 0;
3049 for(i = 0; i < 4; i++) {
3050 gp_Vec2d anOtherVec;
3051 gp_Vec2d anOtherVecNormal;
3052 gp_Pnt2d aprojpoint = theLastPoint;
3055 anOtherVec.SetX(0.);
3056 anOtherVec.SetY(1.);
3057 anOtherVecNormal.SetX(1.);
3058 anOtherVecNormal.SetY(0.);
3061 aprojpoint.SetX(theUmin);
3063 aprojpoint.SetX(theUmax);
3066 anOtherVec.SetX(1.);
3067 anOtherVec.SetY(0.);
3068 anOtherVecNormal.SetX(0.);
3069 anOtherVecNormal.SetY(1.);
3072 aprojpoint.SetY(theVmin);
3074 aprojpoint.SetY(theVmax);
3076 gp_Vec2d anormvec = aVec;
3077 anormvec.Normalize();
3078 RefineVector(anormvec);
3079 Standard_Real adot1 = anormvec.Dot(anOtherVecNormal);
3081 if(fabs(adot1) < Precision::Angular())
3083 Standard_Real adist = 0.;
3084 Standard_Boolean bIsOut = Standard_False;
3087 adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax);
3088 bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax);
3091 adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax);
3092 bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax);
3094 Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1;
3096 for(j = 0; j < 2; j++) {
3097 anoffset = (j == 0) ? anoffset : -anoffset;
3098 gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset));
3099 gp_Vec2d acurvec(theLastPoint, acurpoint);
3103 Standard_Real aDotX, anAngleX;
3105 aDotX = aVec.Dot(acurvec);
3106 anAngleX = aVec.Angle(acurvec);
3108 if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) {
3110 if((acurpoint.Y() >= theVmin) &&
3111 (acurpoint.Y() <= theVmax)) {
3112 theNewPoint = acurpoint;
3113 return Standard_True;
3117 if((acurpoint.X() >= theUmin) &&
3118 (acurpoint.X() <= theUmax)) {
3119 theNewPoint = acurpoint;
3120 return Standard_True;
3126 return Standard_False;
3130 // ------------------------------------------------------------------------------------------------
3131 // static function: FindPoint
3132 // purpose: Find point on the boundary of radial tangent zone
3133 // ------------------------------------------------------------------------------------------------
3134 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3135 const gp_Pnt2d& theLastPoint,
3136 const Standard_Real theUmin,
3137 const Standard_Real theUmax,
3138 const Standard_Real theVmin,
3139 const Standard_Real theVmax,
3140 const gp_Pnt2d& theTanZoneCenter,
3141 const Standard_Real theZoneRadius,
3142 Handle(GeomAdaptor_HSurface) theGASurface,
3143 gp_Pnt2d& theNewPoint) {
3144 theNewPoint = theLastPoint;
3146 if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) )
3147 return Standard_False;
3149 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3150 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3152 Standard_Real aRadius = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3153 gp_Ax22d anAxis( theTanZoneCenter, gp_Dir2d(1, 0), gp_Dir2d(0, 1) );
3154 gp_Circ2d aCircle( anAxis, aRadius );
3157 gp_Vec2d aDir( theLastPoint.XY() - theFirstPoint.XY() );
3158 Standard_Real aLength = aDir.Magnitude();
3159 if ( aLength <= gp::Resolution() )
3160 return Standard_False;
3161 gp_Lin2d aLine( theFirstPoint, aDir );
3164 Handle(Geom2d_Line) aCLine = new Geom2d_Line( aLine );
3165 Handle(Geom2d_TrimmedCurve) aC1 = new Geom2d_TrimmedCurve( aCLine, 0, aLength );
3166 Handle(Geom2d_Circle) aC2 = new Geom2d_Circle( aCircle );
3168 Standard_Real aTol = aRadius * 0.001;
3169 aTol = ( aTol < Precision::PConfusion() ) ? Precision::PConfusion() : aTol;
3171 Geom2dAPI_InterCurveCurve anIntersector;
3172 anIntersector.Init( aC1, aC2, aTol );
3174 if ( anIntersector.NbPoints() == 0 )
3175 return Standard_False;
3177 Standard_Boolean aFound = Standard_False;
3178 Standard_Real aMinDist = aLength * aLength;
3179 Standard_Integer i = 0;
3180 for ( i = 1; i <= anIntersector.NbPoints(); i++ ) {
3181 gp_Pnt2d aPInt = anIntersector.Point( i );
3182 if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) {
3183 if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) &&
3184 ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) {
3185 theNewPoint = aPInt;
3186 aFound = Standard_True;
3194 // ------------------------------------------------------------------------------------------------
3195 // static function: IsInsideTanZone
3196 // purpose: Check if point is inside a radial tangent zone
3197 // ------------------------------------------------------------------------------------------------
3198 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
3199 const gp_Pnt2d& theTanZoneCenter,
3200 const Standard_Real theZoneRadius,
3201 Handle(GeomAdaptor_HSurface) theGASurface) {
3203 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3204 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3205 Standard_Real aRadiusSQR = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3206 aRadiusSQR *= aRadiusSQR;
3207 if ( thePoint.SquareDistance( theTanZoneCenter ) <= aRadiusSQR )
3208 return Standard_True;
3209 return Standard_False;
3212 // ------------------------------------------------------------------------------------------------
3213 // static function: CheckTangentZonesExist
3214 // purpose: Check if tangent zone exists
3215 // ------------------------------------------------------------------------------------------------
3216 Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& theSurface1,
3217 const Handle(GeomAdaptor_HSurface)& theSurface2 )
3219 if ( ( theSurface1->GetType() != GeomAbs_Torus ) ||
3220 ( theSurface2->GetType() != GeomAbs_Torus ) )
3221 return Standard_False;
3223 gp_Torus aTor1 = theSurface1->Torus();
3224 gp_Torus aTor2 = theSurface2->Torus();
3226 if ( aTor1.Location().Distance( aTor2.Location() ) > Precision::Confusion() )
3227 return Standard_False;
3229 if ( ( fabs( aTor1.MajorRadius() - aTor2.MajorRadius() ) > Precision::Confusion() ) ||
3230 ( fabs( aTor1.MinorRadius() - aTor2.MinorRadius() ) > Precision::Confusion() ) )
3231 return Standard_False;
3233 if ( ( aTor1.MajorRadius() < aTor1.MinorRadius() ) ||
3234 ( aTor2.MajorRadius() < aTor2.MinorRadius() ) )
3235 return Standard_False;
3236 return Standard_True;
3239 // ------------------------------------------------------------------------------------------------
3240 // static function: ComputeTangentZones
3242 // ------------------------------------------------------------------------------------------------
3243 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
3244 const Handle(GeomAdaptor_HSurface)& theSurface2,
3245 const TopoDS_Face& theFace1,
3246 const TopoDS_Face& theFace2,
3247 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
3248 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
3249 Handle(TColStd_HArray1OfReal)& theResultRadius,
3250 const Handle(IntTools_Context)& aContext)
3252 Standard_Integer aResult = 0;
3253 if ( !CheckTangentZonesExist( theSurface1, theSurface2 ) )
3257 TColgp_SequenceOfPnt2d aSeqResultS1, aSeqResultS2;
3258 TColStd_SequenceOfReal aSeqResultRad;
3260 gp_Torus aTor1 = theSurface1->Torus();
3261 gp_Torus aTor2 = theSurface2->Torus();
3263 gp_Ax2 anax1( aTor1.Location(), aTor1.Axis().Direction() );
3264 gp_Ax2 anax2( aTor2.Location(), aTor2.Axis().Direction() );
3265 Standard_Integer j = 0;
3267 for ( j = 0; j < 2; j++ ) {
3268 Standard_Real aCoef = ( j == 0 ) ? -1 : 1;
3269 Standard_Real aRadius1 = fabs(aTor1.MajorRadius() + aCoef * aTor1.MinorRadius());
3270 Standard_Real aRadius2 = fabs(aTor2.MajorRadius() + aCoef * aTor2.MinorRadius());
3272 gp_Circ aCircle1( anax1, aRadius1 );
3273 gp_Circ aCircle2( anax2, aRadius2 );
3275 // roughly compute radius of tangent zone for perpendicular case
3276 Standard_Real aCriteria = Precision::Confusion() * 0.5;
3278 Standard_Real aT1 = aCriteria;
3279 Standard_Real aT2 = aCriteria;
3281 // internal tangency
3282 Standard_Real aR = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3283 //aT1 = aCriteria * aCriteria + aR * aR - ( aR - aCriteria ) * ( aR - aCriteria );
3284 aT1 = 2. * aR * aCriteria;
3288 // external tangency
3289 Standard_Real aRb = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3290 Standard_Real aRm = ( aRadius1 < aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3291 Standard_Real aDelta = aRb - aCriteria;
3293 aDelta -= aRm * aRm;
3294 aDelta /= 2. * (aRb - aRm);
3295 aDelta -= 0.5 * (aRb - aRm);
3297 aT1 = 2. * aRm * (aRm - aDelta);
3300 aCriteria = ( aT1 > aT2) ? aT1 : aT2;
3301 if ( aCriteria > 0 )
3302 aCriteria = sqrt( aCriteria );
3304 if ( aCriteria > 0.5 * aTor1.MinorRadius() ) {
3305 // too big zone -> drop to minimum
3306 aCriteria = Precision::Confusion();
3309 GeomAdaptor_Curve aC1( new Geom_Circle(aCircle1) );
3310 GeomAdaptor_Curve aC2( new Geom_Circle(aCircle2) );
3311 Extrema_ExtCC anExtrema(aC1, aC2, 0, 2. * M_PI, 0, 2. * M_PI,
3312 Precision::PConfusion(), Precision::PConfusion());
3314 if ( anExtrema.IsDone() ) {
3316 Standard_Integer i = 0;
3317 for ( i = 1; i <= anExtrema.NbExt(); i++ ) {
3318 if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria )
3321 Extrema_POnCurv P1, P2;
3322 anExtrema.Points( i, P1, P2 );
3324 Standard_Boolean bFoundResult = Standard_True;
3327 Standard_Integer surfit = 0;
3328 for ( surfit = 0; surfit < 2; surfit++ ) {
3329 GeomAPI_ProjectPointOnSurf& aProjector =
3330 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3332 gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value();
3333 aProjector.Perform(aP3d);
3335 if(!aProjector.IsDone())
3336 bFoundResult = Standard_False;
3338 if(aProjector.LowerDistance() > aCriteria) {
3339 bFoundResult = Standard_False;
3342 Standard_Real foundU = 0, foundV = 0;
3343 aProjector.LowerDistanceParameters(foundU, foundV);
3345 pr1 = gp_Pnt2d( foundU, foundV );
3347 pr2 = gp_Pnt2d( foundU, foundV );
3351 if ( bFoundResult ) {
3352 aSeqResultS1.Append( pr1 );
3353 aSeqResultS2.Append( pr2 );
3354 aSeqResultRad.Append( aCriteria );
3356 // torus is u and v periodic
3357 const Standard_Real twoPI = M_PI + M_PI;
3358 Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()};
3359 Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()};
3361 // iteration on period bounds
3362 for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) {
3363 Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI;
3364 Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI;
3366 // iteration on surfaces
3367 for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) {
3368 Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp;
3369 Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp;
3370 TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2;
3371 TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2;
3373 if (fabs(arr1[0] - aBound) < Precision::PConfusion()) {
3374 aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) );
3375 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3376 aSeqResultRad.Append( aCriteria );
3378 if (fabs(arr1[1] - aBound) < Precision::PConfusion()) {
3379 aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) );
3380 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3381 aSeqResultRad.Append( aCriteria );
3389 aResult = aSeqResultRad.Length();
3391 if ( aResult > 0 ) {
3392 theResultOnS1 = new TColgp_HArray1OfPnt2d( 1, aResult );
3393 theResultOnS2 = new TColgp_HArray1OfPnt2d( 1, aResult );
3394 theResultRadius = new TColStd_HArray1OfReal( 1, aResult );
3396 for ( Standard_Integer i = 1 ; i <= aResult; i++ ) {
3397 theResultOnS1->SetValue( i, aSeqResultS1.Value(i) );
3398 theResultOnS2->SetValue( i, aSeqResultS2.Value(i) );
3399 theResultRadius->SetValue( i, aSeqResultRad.Value(i) );
3405 // ------------------------------------------------------------------------------------------------
3406 // static function: AdjustByNeighbour
3408 // ------------------------------------------------------------------------------------------------
3409 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
3410 const gp_Pnt2d& theOriginalPoint,
3411 Handle(GeomAdaptor_HSurface) theGASurface) {
3413 gp_Pnt2d ap1 = theaNeighbourPoint;
3414 gp_Pnt2d ap2 = theOriginalPoint;
3416 if ( theGASurface->IsUPeriodic() ) {
3417 Standard_Real aPeriod = theGASurface->UPeriod();
3418 gp_Pnt2d aPTest = ap2;
3419 Standard_Real aSqDistMin = 1.e+100;
3421 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3422 aPTest.SetX( theOriginalPoint.X() + aPeriod * pIt );
3423 Standard_Real dd = ap1.SquareDistance( aPTest );
3425 if ( dd < aSqDistMin ) {
3431 if ( theGASurface->IsVPeriodic() ) {
3432 Standard_Real aPeriod = theGASurface->VPeriod();
3433 gp_Pnt2d aPTest = ap2;
3434 Standard_Real aSqDistMin = 1.e+100;
3436 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3437 aPTest.SetY( theOriginalPoint.Y() + aPeriod * pIt );
3438 Standard_Real dd = ap1.SquareDistance( aPTest );
3440 if ( dd < aSqDistMin ) {
3449 // ------------------------------------------------------------------------------------------------
3450 //function: DecompositionOfWLine
3452 // ------------------------------------------------------------------------------------------------
3453 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
3454 const Handle(GeomAdaptor_HSurface)& theSurface1,
3455 const Handle(GeomAdaptor_HSurface)& theSurface2,
3456 const TopoDS_Face& theFace1,
3457 const TopoDS_Face& theFace2,
3458 const GeomInt_LineConstructor& theLConstructor,
3459 const Standard_Boolean theAvoidLConstructor,
3460 IntPatch_SequenceOfLine& theNewLines,
3461 Standard_Real& theReachedTol3d,
3462 const Handle(IntTools_Context)& aContext)
3465 Standard_Boolean bRet, bAvoidLineConstructor;
3466 Standard_Integer aNbPnts, aNbParts;
3468 bRet=Standard_False;
3469 aNbPnts=theWLine->NbPnts();
3470 bAvoidLineConstructor=theAvoidLConstructor;
3475 if (!bAvoidLineConstructor) {
3476 aNbParts=theLConstructor.NbParts();
3482 Standard_Boolean bIsPrevPointOnBoundary, bIsPointOnBoundary, bIsCurrentPointOnBoundary;
3483 Standard_Integer nblines, pit, i, j;
3485 TColStd_Array1OfListOfInteger anArrayOfLines(1, aNbPnts);
3486 TColStd_Array1OfInteger anArrayOfLineType(1, aNbPnts);
3487 TColStd_ListOfInteger aListOfPointIndex;
3489 Handle(TColgp_HArray1OfPnt2d) aTanZoneS1;
3490 Handle(TColgp_HArray1OfPnt2d) aTanZoneS2;
3491 Handle(TColStd_HArray1OfReal) aTanZoneRadius;
3492 Standard_Integer aNbZone = ComputeTangentZones( theSurface1, theSurface2, theFace1, theFace2,
3493 aTanZoneS1, aTanZoneS2, aTanZoneRadius, aContext);
3497 aTol=Precision::Confusion();
3499 bIsPrevPointOnBoundary=Standard_False;
3500 bIsPointOnBoundary=Standard_False;
3505 for(pit = 1; pit <= aNbPnts; ++pit) {
3506 Standard_Boolean bIsOnFirstBoundary, isperiodic;
3507 Standard_Real aResolution, aPeriod, alowerboundary, aupperboundary, U, V;
3508 Standard_Real aParameter, anoffset, anAdjustPar;
3509 Standard_Real umin, umax, vmin, vmax;
3511 bIsCurrentPointOnBoundary = Standard_False;
3512 const IntSurf_PntOn2S& aPoint = theWLine->Point(pit);
3515 for(i = 0; i < 2; ++i) {
3516 Handle(GeomAdaptor_HSurface) aGASurface = (!i) ? theSurface1 : theSurface2;
3517 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3519 aPoint.ParametersOnS1(U, V);
3522 aPoint.ParametersOnS2(U, V);
3525 for(j = 0; j < 2; j++) {
3526 isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3532 aResolution=aGASurface->UResolution(aTol);
3533 aPeriod=aGASurface->UPeriod();
3534 alowerboundary=umin;
3535 aupperboundary=umax;
3539 aResolution=aGASurface->VResolution(aTol);
3540 aPeriod=aGASurface->VPeriod();
3541 alowerboundary=vmin;
3542 aupperboundary=vmax;
3546 GeomInt::AdjustPeriodic(aParameter,
3553 bIsOnFirstBoundary = Standard_True;// ?
3555 IsPointOnBoundary(anAdjustPar,
3559 bIsOnFirstBoundary);
3561 if(bIsPointOnBoundary) {
3562 bIsCurrentPointOnBoundary = Standard_True;
3566 // check if a point belong to a tangent zone. Begin
3567 Standard_Integer zIt = 0;
3568 for ( zIt = 1; zIt <= aNbZone; zIt++ ) {
3569 gp_Pnt2d aPZone = (i == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3570 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3572 if ( IsInsideTanZone(gp_Pnt2d( U, V ), aPZone, aZoneRadius, aGASurface ) ) {
3573 // set boundary flag to split the curve by a tangent zone
3574 bIsPointOnBoundary = Standard_True;
3575 bIsCurrentPointOnBoundary = Standard_True;
3576 if ( theReachedTol3d < aZoneRadius ) {
3577 theReachedTol3d = aZoneRadius;
3583 }//for(j = 0; j < 2; j++) {
3585 if(bIsCurrentPointOnBoundary){
3588 }//for(i = 0; i < 2; ++i) {
3590 if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) {
3591 if(!aListOfPointIndex.IsEmpty()) {
3593 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3594 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3595 aListOfPointIndex.Clear();
3597 bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary;
3599 aListOfPointIndex.Append(pit);
3600 } //for(pit = 1; pit <= aNbPnts; ++pit) {
3602 if(!aListOfPointIndex.IsEmpty()) {
3604 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3605 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3606 aListOfPointIndex.Clear();
3610 return bRet; //Standard_False;
3614 // 2. Correct wlines.begin
3615 TColStd_Array1OfListOfInteger anArrayOfLineEnds(1, nblines);
3616 Handle(IntSurf_LineOn2S) aSeqOfPntOn2S = new IntSurf_LineOn2S();
3618 for(i = 1; i <= nblines; i++) {
3619 if(anArrayOfLineType.Value(i) != 0) {
3622 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3623 TColStd_ListOfInteger aListOfFLIndex;
3625 for(j = 0; j < 2; j++) {
3626 Standard_Integer aneighbourindex = (j == 0) ? (i - 1) : (i + 1);
3628 if((aneighbourindex < 1) || (aneighbourindex > nblines))
3631 if(anArrayOfLineType.Value(aneighbourindex) == 0)
3633 const TColStd_ListOfInteger& aNeighbour = anArrayOfLines.Value(aneighbourindex);
3634 Standard_Integer anIndex = (j == 0) ? aNeighbour.Last() : aNeighbour.First();
3635 const IntSurf_PntOn2S& aPoint = theWLine->Point(anIndex);
3637 IntSurf_PntOn2S aNewP = aPoint;
3638 if(aListOfIndex.Extent() < 2) {
3639 aSeqOfPntOn2S->Add(aNewP);
3640 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
3644 Standard_Integer iFirst = aListOfIndex.First();
3645 Standard_Integer iLast = aListOfIndex.Last();
3647 for(Standard_Integer surfit = 0; surfit < 2; surfit++) {
3649 Handle(GeomAdaptor_HSurface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2;
3650 Standard_Real umin=0., umax=0., vmin=0., vmax=0.;
3651 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3652 Standard_Real U=0., V=0.;
3655 aNewP.ParametersOnS1(U, V);
3657 aNewP.ParametersOnS2(U, V);
3658 Standard_Integer nbboundaries = 0;
3660 Standard_Boolean bIsNearBoundary = Standard_False;
3661 Standard_Integer aZoneIndex = 0;
3662 Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1
3663 Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1
3666 for(Standard_Integer parit = 0; parit < 2; parit++) {
3667 Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3669 Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
3670 Standard_Real alowerboundary = (parit == 0) ? umin : vmin;
3671 Standard_Real aupperboundary = (parit == 0) ? umax : vmax;
3673 Standard_Real aParameter = (parit == 0) ? U : V;
3674 Standard_Boolean bIsOnFirstBoundary = Standard_True;
3678 IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3679 if(bIsPointOnBoundary) {
3680 bIsUBoundary = (parit == 0);
3681 bIsFirstBoundary = bIsOnFirstBoundary;
3686 Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3687 Standard_Real anoffset, anAdjustPar;
3688 GeomInt::AdjustPeriodic(aParameter, alowerboundary, aupperboundary,
3689 aPeriod, anAdjustPar, anoffset);
3692 IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3693 if(bIsPointOnBoundary) {
3694 bIsUBoundary = (parit == 0);
3695 bIsFirstBoundary = bIsOnFirstBoundary;
3699 //check neighbourhood of boundary
3700 Standard_Real anEpsilon = aResolution * 100.;
3701 Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
3702 anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
3704 bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary,
3705 anEpsilon, bIsOnFirstBoundary);
3711 // check if a point belong to a tangent zone. Begin
3712 for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) {
3713 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3714 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3716 Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast;
3717 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3718 Standard_Real nU1, nV1;
3721 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3723 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3724 gp_Pnt2d ap1(nU1, nV1);
3725 gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface );
3728 if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) {
3730 bIsNearBoundary = Standard_True;
3731 if ( theReachedTol3d < aZoneRadius ) {
3732 theReachedTol3d = aZoneRadius;
3736 // check if a point belong to a tangent zone. End
3737 Standard_Boolean bComputeLineEnd = Standard_False;
3739 if(nbboundaries == 2) {
3741 bComputeLineEnd = Standard_True;
3744 else if(nbboundaries == 1) {
3745 Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3748 Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
3749 Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
3750 Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3751 Standard_Real aParameter = (bIsUBoundary) ? U : V;
3752 Standard_Real anoffset, anAdjustPar;
3753 GeomInt::AdjustPeriodic(aParameter, alowerboundary, aupperboundary,
3754 aPeriod, anAdjustPar, anoffset);
3756 Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
3757 Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
3758 anotherPar += anoffset;
3759 Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3760 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
3761 Standard_Real nU1, nV1;
3764 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3766 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3768 Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
3769 Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
3770 bComputeLineEnd = Standard_True;
3771 Standard_Boolean bCheckAngle1 = Standard_False;
3772 Standard_Boolean bCheckAngle2 = Standard_False;
3774 Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
3775 Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
3777 if(((adist1 - adist2) > Precision::PConfusion()) &&
3778 (adist2 < (aPeriod / 4.))) {
3779 bCheckAngle1 = Standard_True;
3780 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
3782 if(aNewVec.SquareMagnitude() < gp::Resolution()) {
3783 aNewP.SetValue((surfit == 0), anewU, anewV);
3784 bCheckAngle1 = Standard_False;
3787 else if(adist1 < (aPeriod / 4.)) {
3788 bCheckAngle2 = Standard_True;
3789 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
3791 if(aNewVec.SquareMagnitude() < gp::Resolution()) {
3792 bCheckAngle2 = Standard_False;
3796 if(bCheckAngle1 || bCheckAngle2) {
3797 // assume there are at least two points in line (see "if" above)
3798 Standard_Integer anindexother = aneighbourpointindex;
3800 while((anindexother <= iLast) && (anindexother >= iFirst)) {
3801 anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
3802 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
3803 Standard_Real nU2, nV2;
3806 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3808 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3809 gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
3811 if(aVecOld.SquareMagnitude() <= gp::Resolution()) {
3815 Standard_Real anAngle = aNewVec.Angle(aVecOld);
3817 if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
3820 Standard_Real U1, U2, V1, V2;
3821 IntSurf_PntOn2S atmppoint = aNewP;
3822 atmppoint.SetValue((surfit == 0), anewU, anewV);
3823 atmppoint.Parameters(U1, V1, U2, V2);
3824 gp_Pnt P1 = theSurface1->Value(U1, V1);
3825 gp_Pnt P2 = theSurface2->Value(U2, V2);
3826 gp_Pnt P0 = aPoint.Value();
3828 if(P0.IsEqual(P1, aTol) &&
3829 P0.IsEqual(P2, aTol) &&
3830 P1.IsEqual(P2, aTol)) {
3831 bComputeLineEnd = Standard_False;
3832 aNewP.SetValue((surfit == 0), anewU, anewV);
3837 bComputeLineEnd = Standard_False;
3842 } // end while(anindexother...)
3846 else if ( bIsNearBoundary ) {
3847 bComputeLineEnd = Standard_True;
3850 if(bComputeLineEnd) {
3853 Standard_Boolean found = Standard_False;
3855 if ( bIsNearBoundary ) {
3856 // re-compute point near natural boundary or near tangent zone
3857 Standard_Real u1, v1, u2, v2;
3858 aNewP.Parameters( u1, v1, u2, v2 );
3860 anewpoint = gp_Pnt2d( u1, v1 );
3862 anewpoint = gp_Pnt2d( u2, v2 );
3864 Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast;
3865 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3866 Standard_Real nU1, nV1;
3869 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3871 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3872 gp_Pnt2d ap1(nU1, nV1);
3877 // exclude point from a tangent zone
3878 anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3879 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex);
3880 Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex);
3882 if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax,
3883 aPZone, aZoneRadius, aGASurface, ap2) ) {
3885 found = Standard_True;
3888 else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
3889 // re-compute point near boundary if shifted on a period
3890 ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3892 if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
3893 ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
3894 found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
3898 aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
3904 Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast;
3905 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3906 Standard_Real nU1, nV1;
3909 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3911 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3912 gp_Pnt2d ap1(nU1, nV1);
3913 gp_Pnt2d ap2(nU1, nV1);
3914 Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
3916 while((aneighbourpointindex2 <= iLast) && (aneighbourpointindex2 >= iFirst)) {
3917 aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
3918 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
3919 Standard_Real nU2, nV2;
3922 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3924 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3928 if(ap1.SquareDistance(ap2) > gp::Resolution()) {
3932 found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
3937 Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
3938 GeomAPI_ProjectPointOnSurf& aProjector =
3939 (surfit == 0) ? aContext->ProjPS(theFace2) : aContext->ProjPS(theFace1);
3940 Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
3942 Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
3944 gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
3945 aProjector.Perform(aP3d);
3947 if(aProjector.IsDone()) {
3948 if(aProjector.LowerDistance() < aCriteria) {
3949 Standard_Real foundU = U, foundV = V;
3950 aProjector.LowerDistanceParameters(foundU, foundV);
3952 //Correction of projected coordinates. Begin
3953 //Note, it may be shifted on a period
3954 Standard_Integer aneindex1 = (j == 0) ? iFirst : iLast;
3955 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
3956 Standard_Real nUn, nVn;
3959 aNeighbourPoint.ParametersOnS2(nUn, nVn);
3961 aNeighbourPoint.ParametersOnS1(nUn, nVn);
3962 gp_Pnt2d aNeighbour2d(nUn, nVn);
3963 gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
3964 foundU = anAdjustedPoint.X();
3965 foundV = anAdjustedPoint.Y();
3967 if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
3968 ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
3969 // attempt to roughly re-compute point
3970 foundU = ( foundU < umin ) ? umin : foundU;
3971 foundU = ( foundU > umax ) ? umax : foundU;
3972 foundV = ( foundV < vmin ) ? vmin : foundV;
3973 foundV = ( foundV > vmax ) ? vmax : foundV;
3975 GeomAPI_ProjectPointOnSurf& aProjector2 =
3976 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3978 aP3d = aSurfaceOther->Value(foundU, foundV);
3979 aProjector2.Perform(aP3d);
3981 if(aProjector2.IsDone()) {
3982 if(aProjector2.LowerDistance() < aCriteria) {
3983 Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
3984 aProjector2.LowerDistanceParameters(foundU2, foundV2);
3985 anewpoint.SetX(foundU2);
3986 anewpoint.SetY(foundV2);
3990 //Correction of projected coordinates. End
3993 aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
3995 aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
4001 aSeqOfPntOn2S->Add(aNewP);
4002 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
4004 anArrayOfLineEnds.SetValue(i, aListOfFLIndex);
4006 // Correct wlines.end
4008 // Split wlines.begin
4009 Standard_Integer nbiter;
4012 if (!bAvoidLineConstructor) {
4013 nbiter=theLConstructor.NbParts();
4016 for(j = 1; j <= nbiter; ++j) {
4017 Standard_Real fprm, lprm;
4018 Standard_Integer ifprm, ilprm;
4020 if(bAvoidLineConstructor) {
4022 ilprm = theWLine->NbPnts();
4025 theLConstructor.Part(j, fprm, lprm);
4026 ifprm = (Standard_Integer)fprm;
4027 ilprm = (Standard_Integer)lprm;
4030 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
4032 for(i = 1; i <= nblines; i++) {
4033 if(anArrayOfLineType.Value(i) != 0) {
4036 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
4037 const TColStd_ListOfInteger& aListOfFLIndex = anArrayOfLineEnds.Value(i);
4038 Standard_Boolean bhasfirstpoint = (aListOfFLIndex.Extent() == 2);
4039 Standard_Boolean bhaslastpoint = (aListOfFLIndex.Extent() == 2);
4041 if(!bhasfirstpoint && !aListOfFLIndex.IsEmpty()) {
4042 bhasfirstpoint = (i != 1);
4045 if(!bhaslastpoint && !aListOfFLIndex.IsEmpty()) {
4046 bhaslastpoint = (i != nblines);
4049 Standard_Integer iFirst = aListOfIndex.First();
4050 Standard_Integer iLast = aListOfIndex.Last();
4051 Standard_Boolean bIsFirstInside = ((ifprm >= iFirst) && (ifprm <= iLast));
4052 Standard_Boolean bIsLastInside = ((ilprm >= iFirst) && (ilprm <= iLast));
4054 if(!bIsFirstInside && !bIsLastInside) {
4055 if((ifprm < iFirst) && (ilprm > iLast)) {
4056 // append whole line, and boundaries if neccesary
4057 if(bhasfirstpoint) {
4058 pit = aListOfFLIndex.First();
4059 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4062 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4064 for(; anIt.More(); anIt.Next()) {
4066 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4071 pit = aListOfFLIndex.Last();
4072 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4076 // check end of split line (end is almost always)
4077 Standard_Integer aneighbour = i + 1;
4078 Standard_Boolean bIsEndOfLine = Standard_True;
4080 if(aneighbour <= nblines) {
4081 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4083 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4084 (aListOfNeighbourIndex.IsEmpty())) {
4085 bIsEndOfLine = Standard_False;
4090 if(aLineOn2S->NbPoints() > 1) {
4091 Handle(IntPatch_WLine) aNewWLine =
4092 new IntPatch_WLine(aLineOn2S, Standard_False);
4093 theNewLines.Append(aNewWLine);
4095 aLineOn2S = new IntSurf_LineOn2S();
4100 // end if(!bIsFirstInside && !bIsLastInside)
4102 if(bIsFirstInside && bIsLastInside) {
4103 // append inside points between ifprm and ilprm
4104 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4106 for(; anIt.More(); anIt.Next()) {
4108 if((pit < ifprm) || (pit > ilprm))
4110 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4116 if(bIsFirstInside) {
4117 // append points from ifprm to last point + boundary point
4118 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4120 for(; anIt.More(); anIt.Next()) {
4124 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4129 pit = aListOfFLIndex.Last();
4130 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4133 // check end of split line (end is almost always)
4134 Standard_Integer aneighbour = i + 1;
4135 Standard_Boolean bIsEndOfLine = Standard_True;
4137 if(aneighbour <= nblines) {
4138 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4140 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4141 (aListOfNeighbourIndex.IsEmpty())) {
4142 bIsEndOfLine = Standard_False;
4147 if(aLineOn2S->NbPoints() > 1) {
4148 Handle(IntPatch_WLine) aNewWLine =
4149 new IntPatch_WLine(aLineOn2S, Standard_False);
4150 theNewLines.Append(aNewWLine);
4152 aLineOn2S = new IntSurf_LineOn2S();
4155 // end if(bIsFirstInside)
4158 // append points from first boundary point to ilprm
4159 if(bhasfirstpoint) {
4160 pit = aListOfFLIndex.First();
4161 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit);
4164 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4166 for(; anIt.More(); anIt.Next()) {
4170 const IntSurf_PntOn2S& aP = theWLine->Point(pit);
4174 //end if(bIsLastInside)
4178 if(aLineOn2S->NbPoints() > 1) {
4179 Handle(IntPatch_WLine) aNewWLine =
4180 new IntPatch_WLine(aLineOn2S, Standard_False);
4181 theNewLines.Append(aNewWLine);
4186 return Standard_True;
4189 // ------------------------------------------------------------------------------------------------
4190 // static function: ParameterOutOfBoundary
4191 // purpose: Computes a new parameter for given curve. The corresponding 2d points
4192 // does not lay on any boundary of given faces
4193 // ------------------------------------------------------------------------------------------------
4194 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
4195 const Handle(Geom_Curve)& theCurve,
4196 const TopoDS_Face& theFace1,
4197 const TopoDS_Face& theFace2,
4198 const Standard_Real theOtherParameter,
4199 const Standard_Boolean bIncreasePar,
4200 Standard_Real& theNewParameter,
4201 const Handle(IntTools_Context)& aContext)
4203 Standard_Boolean bIsComputed = Standard_False;
4204 theNewParameter = theParameter;
4206 Standard_Real acurpar = theParameter;
4207 TopAbs_State aState = TopAbs_ON;
4208 Standard_Integer iter = 0;
4209 Standard_Real asumtol = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4210 Standard_Real adelta = asumtol * 0.1;
4211 adelta = (adelta < Precision::Confusion()) ? Precision::Confusion() : adelta;
4212 Handle(Geom_Surface) aSurf1 = BRep_Tool::Surface(theFace1);
4213 Handle(Geom_Surface) aSurf2 = BRep_Tool::Surface(theFace2);
4215 Standard_Real u1, u2, v1, v2;
4217 GeomAPI_ProjectPointOnSurf aPrj1;
4218 aSurf1->Bounds(u1, u2, v1, v2);
4219 aPrj1.Init(aSurf1, u1, u2, v1, v2);
4221 GeomAPI_ProjectPointOnSurf aPrj2;
4222 aSurf2->Bounds(u1, u2, v1, v2);
4223 aPrj2.Init(aSurf2, u1, u2, v1, v2);
4225 while(aState == TopAbs_ON) {
4230 gp_Pnt aPCurrent = theCurve->Value(acurpar);
4231 aPrj1.Perform(aPCurrent);
4232 Standard_Real U=0., V=0.;
4234 if(aPrj1.IsDone()) {
4235 aPrj1.LowerDistanceParameters(U, V);
4236 aState = aContext->StatePointFace(theFace1, gp_Pnt2d(U, V));
4239 if(aState != TopAbs_ON) {
4240 aPrj2.Perform(aPCurrent);
4242 if(aPrj2.IsDone()) {
4243 aPrj2.LowerDistanceParameters(U, V);
4244 aState = aContext->StatePointFace(theFace2, gp_Pnt2d(U, V));
4255 theNewParameter = acurpar;
4256 bIsComputed = Standard_True;
4259 if(acurpar >= theOtherParameter)
4260 theNewParameter = theOtherParameter;
4263 if(acurpar <= theOtherParameter)
4264 theNewParameter = theOtherParameter;
4270 //=======================================================================
4271 //function : IsCurveValid
4273 //=======================================================================
4274 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve)
4276 if(thePCurve.IsNull())
4277 return Standard_False;
4279 Standard_Real tolint = 1.e-10;
4280 Geom2dAdaptor_Curve PCA;
4281 IntRes2d_Domain PCD;
4282 Geom2dInt_GInter PCI;
4284 Standard_Real pf = 0., pl = 0.;
4285 gp_Pnt2d pntf, pntl;
4287 if(!thePCurve->IsClosed() && !thePCurve->IsPeriodic()) {
4288 pf = thePCurve->FirstParameter();
4289 pl = thePCurve->LastParameter();
4290 pntf = thePCurve->Value(pf);
4291 pntl = thePCurve->Value(pl);
4292 PCA.Load(thePCurve);
4293 if(!PCA.IsPeriodic()) {
4294 if(PCA.FirstParameter() > pf) pf = PCA.FirstParameter();
4295 if(PCA.LastParameter() < pl) pl = PCA.LastParameter();
4297 PCD.SetValues(pntf,pf,tolint,pntl,pl,tolint);
4298 PCI.Perform(PCA,PCD,tolint,tolint);
4300 if(PCI.NbPoints() > 0) {
4301 return Standard_False;
4305 return Standard_True;
4308 //=======================================================================
4309 //static function : ApproxWithPCurves
4310 //purpose : for bug 20964 only
4311 //=======================================================================
4312 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
4313 const gp_Sphere& theSph)
4315 Standard_Boolean bRes = Standard_True;
4316 Standard_Real R1 = theCyl.Radius(), R2 = theSph.Radius();
4319 Standard_Real aD2, aRc2, aEps;
4325 const gp_Ax3& aAx3Sph=theSph.Position();
4326 const gp_Pnt& aLocSph=aAx3Sph.Location();
4327 const gp_Dir& aDirSph=aAx3Sph.Direction();
4329 const gp_Ax1& aAx1Cyl=theCyl.Axis();
4330 gp_Lin aLinCyl(aAx1Cyl);
4332 aApexSph.SetXYZ(aLocSph.XYZ()+R2*aDirSph.XYZ());
4333 aD2=aLinCyl.SquareDistance(aApexSph);
4334 if (fabs(aD2-aRc2)<aEps) {
4338 aApexSph.SetXYZ(aLocSph.XYZ()-R2*aDirSph.XYZ());
4339 aD2=aLinCyl.SquareDistance(aApexSph);
4340 if (fabs(aD2-aRc2)<aEps) {
4349 gp_Lin anCylAx(theCyl.Axis());
4351 Standard_Real aDist = anCylAx.Distance(theSph.Location());
4352 Standard_Real aDRel = Abs(aDist - R1)/R2;
4354 if(aDRel > .2) return bRes;
4356 Standard_Real par = ElCLib::Parameter(anCylAx, theSph.Location());
4357 gp_Pnt aP = ElCLib::Value(par, anCylAx);
4358 gp_Vec aV(aP, theSph.Location());
4360 Standard_Real dd = aV.Dot(theSph.Position().XDirection());
4362 if(aDist < R1 && dd > 0.) return Standard_False;
4363 if(aDist > R1 && dd < 0.) return Standard_False;
4368 //=======================================================================
4369 //function : PerformPlanes
4371 //=======================================================================
4372 void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
4373 const Handle(GeomAdaptor_HSurface)& theS2,
4374 const Standard_Real TolAng,
4375 const Standard_Real TolTang,
4376 const Standard_Boolean theApprox1,
4377 const Standard_Boolean theApprox2,
4378 IntTools_SequenceOfCurves& theSeqOfCurve,
4379 Standard_Boolean& theTangentFaces)
4382 gp_Pln aPln1 = theS1->Surface().Plane();
4383 gp_Pln aPln2 = theS2->Surface().Plane();
4385 IntAna_QuadQuadGeo aPlnInter(aPln1, aPln2, TolAng, TolTang);
4387 if(!aPlnInter.IsDone()) {
4388 theTangentFaces = Standard_False;
4392 IntAna_ResultType aResType = aPlnInter.TypeInter();
4394 if(aResType == IntAna_Same) {
4395 theTangentFaces = Standard_True;
4399 theTangentFaces = Standard_False;
4401 if(aResType == IntAna_Empty) {
4405 gp_Lin aLin = aPlnInter.Line(1);
4407 ProjLib_Plane aProj;
4410 aProj.Project(aLin);
4411 gp_Lin2d aLin2d1 = aProj.Line();
4414 aProj.Project(aLin);
4415 gp_Lin2d aLin2d2 = aProj.Line();
4417 //classify line2d1 relatively first plane
4418 Standard_Real P11, P12;
4419 Standard_Boolean IsCrossed = ClassifyLin2d(theS1, aLin2d1, TolTang, P11, P12);
4420 if(!IsCrossed) return;
4421 //classify line2d2 relatively second plane
4422 Standard_Real P21, P22;
4423 IsCrossed = ClassifyLin2d(theS2, aLin2d2, TolTang, P21, P22);
4424 if(!IsCrossed) return;
4426 //Analysis of parametric intervals: must have common part
4428 if(P21 >= P12) return;
4429 if(P22 <= P11) return;
4431 Standard_Real pmin, pmax;
4432 pmin = Max(P11, P21);
4433 pmax = Min(P12, P22);
4435 if(pmax - pmin <= TolTang) return;
4437 Handle(Geom_Line) aGLin = new Geom_Line(aLin);
4439 IntTools_Curve aCurve;
4440 Handle(Geom_TrimmedCurve) aGTLin = new Geom_TrimmedCurve(aGLin, pmin, pmax);
4442 aCurve.SetCurve(aGTLin);
4445 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d1);
4446 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4449 Handle(Geom2d_Curve) H1;
4450 aCurve.SetFirstCurve2d(H1);
4453 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d2);
4454 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4457 Handle(Geom2d_Curve) H1;
4458 aCurve.SetFirstCurve2d(H1);
4461 theSeqOfCurve.Append(aCurve);
4465 //=======================================================================
4466 //function : ClassifyLin2d
4468 //=======================================================================
4469 static inline Standard_Boolean INTER(const Standard_Real d1,
4470 const Standard_Real d2,
4471 const Standard_Real tol)
4473 return (d1 > tol && d2 < -tol) ||
4474 (d1 < -tol && d2 > tol) ||
4475 ((d1 <= tol && d1 >= -tol) && (d2 > tol || d2 < -tol)) ||
4476 ((d2 <= tol && d2 >= -tol) && (d1 > tol || d1 < -tol));
4478 static inline Standard_Boolean COINC(const Standard_Real d1,
4479 const Standard_Real d2,
4480 const Standard_Real tol)
4482 return (d1 <= tol && d1 >= -tol) && (d2 <= tol && d2 >= -tol);
4484 Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
4485 const gp_Lin2d& theLin2d,
4486 const Standard_Real theTol,
4487 Standard_Real& theP1,
4488 Standard_Real& theP2)
4491 Standard_Real xmin, xmax, ymin, ymax, d1, d2, A, B, C;
4492 Standard_Real par[2];
4493 Standard_Integer nbi = 0;
4495 xmin = theS->Surface().FirstUParameter();
4496 xmax = theS->Surface().LastUParameter();
4497 ymin = theS->Surface().FirstVParameter();
4498 ymax = theS->Surface().LastVParameter();
4500 theLin2d.Coefficients(A, B, C);
4502 //xmin, ymin <-> xmin, ymax
4503 d1 = A*xmin + B*ymin + C;
4504 d2 = A*xmin + B*ymax + C;
4506 if(INTER(d1, d2, theTol)) {
4507 //Intersection with boundary
4508 Standard_Real y = -(C + A*xmin)/B;
4509 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, y));
4512 else if (COINC(d1, d2, theTol)) {
4513 //Coincidence with boundary
4514 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4515 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4521 if(fabs(par[0]-par[1]) > theTol) {
4522 theP1 = Min(par[0], par[1]);
4523 theP2 = Max(par[0], par[1]);
4524 return Standard_True;
4526 else return Standard_False;
4530 //xmin, ymax <-> xmax, ymax
4532 d2 = A*xmax + B*ymax + C;
4534 if(d1 > theTol || d1 < -theTol) {//to avoid checking of
4535 //coincidence with the same point
4536 if(INTER(d1, d2, theTol)) {
4537 Standard_Real x = -(C + B*ymax)/A;
4538 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymax));
4541 else if (COINC(d1, d2, theTol)) {
4542 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4543 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4550 if(fabs(par[0]-par[1]) > theTol) {
4551 theP1 = Min(par[0], par[1]);
4552 theP2 = Max(par[0], par[1]);
4553 return Standard_True;
4555 else return Standard_False;
4559 //xmax, ymax <-> xmax, ymin
4561 d2 = A*xmax + B*ymin + C;
4563 if(d1 > theTol || d1 < -theTol) {
4564 if(INTER(d1, d2, theTol)) {
4565 Standard_Real y = -(C + A*xmax)/B;
4566 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, y));
4569 else if (COINC(d1, d2, theTol)) {
4570 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4571 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4577 if(fabs(par[0]-par[1]) > theTol) {
4578 theP1 = Min(par[0], par[1]);
4579 theP2 = Max(par[0], par[1]);
4580 return Standard_True;
4582 else return Standard_False;
4585 //xmax, ymin <-> xmin, ymin
4587 d2 = A*xmin + B*ymin + C;
4589 if(d1 > theTol || d1 < -theTol) {
4590 if(INTER(d1, d2, theTol)) {
4591 Standard_Real x = -(C + B*ymin)/A;
4592 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymin));
4595 else if (COINC(d1, d2, theTol)) {
4596 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4597 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4603 if(fabs(par[0]-par[1]) > theTol) {
4604 theP1 = Min(par[0], par[1]);
4605 theP2 = Max(par[0], par[1]);
4606 return Standard_True;
4608 else return Standard_False;
4611 return Standard_False;
4615 //=======================================================================
4616 //function : ApproxParameters
4618 //=======================================================================
4619 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
4620 const Handle(GeomAdaptor_HSurface)& aHS2,
4621 Standard_Integer& iDegMin,
4622 Standard_Integer& iDegMax,
4623 Standard_Integer& iNbIter)
4626 GeomAbs_SurfaceType aTS1, aTS2;
4633 aTS1=aHS1->Surface().GetType();
4634 aTS2=aHS2->Surface().GetType();
4637 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4638 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4639 Standard_Real aRC, aRT, dR, aPC;
4640 gp_Cylinder aCylinder;
4643 aPC=Precision::Confusion();
4645 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4646 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4648 aRC=aCylinder.Radius();
4649 aRT=aTorus.MinorRadius();
4659 if (aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Cylinder) {
4663 //=======================================================================
4664 //function : Tolerances
4666 //=======================================================================
4667 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
4668 const Handle(GeomAdaptor_HSurface)& aHS2,
4669 Standard_Real& aTolTang)
4671 GeomAbs_SurfaceType aTS1, aTS2;
4673 aTS1=aHS1->Surface().GetType();
4674 aTS2=aHS2->Surface().GetType();
4677 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4678 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4679 Standard_Real aRC, aRT, dR, aPC;
4680 gp_Cylinder aCylinder;
4683 aPC=Precision::Confusion();
4685 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4686 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4688 aRC=aCylinder.Radius();
4689 aRT=aTorus.MinorRadius();
4696 aTolTang=0.1*aTolTang;
4700 //=======================================================================
4701 //function : SortTypes
4703 //=======================================================================
4704 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
4705 const GeomAbs_SurfaceType aType2)
4707 Standard_Boolean bRet;
4708 Standard_Integer aI1, aI2;
4710 bRet=Standard_False;
4712 aI1=IndexType(aType1);
4713 aI2=IndexType(aType2);
4719 //=======================================================================
4720 //function : IndexType
4722 //=======================================================================
4723 Standard_Integer IndexType(const GeomAbs_SurfaceType aType)
4725 Standard_Integer aIndex;
4729 if (aType==GeomAbs_Plane) {
4732 else if (aType==GeomAbs_Cylinder) {
4735 else if (aType==GeomAbs_Cone) {
4738 else if (aType==GeomAbs_Sphere) {
4741 else if (aType==GeomAbs_Torus) {
4744 else if (aType==GeomAbs_BezierSurface) {
4747 else if (aType==GeomAbs_BSplineSurface) {
4750 else if (aType==GeomAbs_SurfaceOfRevolution) {
4753 else if (aType==GeomAbs_SurfaceOfExtrusion) {
4756 else if (aType==GeomAbs_OffsetSurface) {
4759 else if (aType==GeomAbs_OtherSurface) {
4764 #ifdef OCCT_DEBUG_DUMPWLINE
4765 //=======================================================================
4766 //function : DumpWLine
4768 //=======================================================================
4769 void DumpWLine(const Handle(IntPatch_WLine)& aWLine)
4771 Standard_Integer i, aNbPnts;
4772 Standard_Real aX, aY, aZ, aU1, aV1, aU2, aV2;
4774 printf(" *WLine\n");
4775 aNbPnts=aWLine->NbPnts();
4776 for (i=1; i<=aNbPnts; ++i) {
4777 const IntSurf_PntOn2S aPntOn2S=aWLine->Point(i);
4778 const gp_Pnt& aP3D=aPntOn2S.Value();
4779 aP3D.Coord(aX, aY, aZ);
4780 aPntOn2S.Parameters(aU1, aV1, aU2, aV2);
4782 printf("point p_%d %lf %lf %lf\n", i, aX, aY, aZ);
4783 //printf("point p_%d %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf\n",
4784 // i, aX, aY, aZ, aU1, aV1, aU2, aV2);
4788 //=======================================================================
4789 //function : RefineVector
4791 //=======================================================================
4792 void RefineVector(gp_Vec2d& aV2D)
4794 Standard_Integer k,m;
4795 Standard_Real aC[2], aEps, aR1, aR2, aNum;
4801 aV2D.Coord(aC[0], aC[1]);
4803 for (k=0; k<2; ++k) {
4806 if (aNum>aR1 && aNum<aR2) {
4817 aV2D.SetCoord(aC[0], aC[1]);
4820 //=======================================================================
4821 // Function : MaxDistance
4823 //=======================================================================
4824 Standard_Real MaxDistance(const Handle(Geom_Curve)& theC,
4825 const Standard_Real aT,
4826 GeomAPI_ProjectPointOnSurf& theProjPS)
4832 theProjPS.Perform(aP);
4833 aD = theProjPS.NbPoints() ? theProjPS.LowerDistance() : 0.;
4838 //=======================================================================
4839 //function : CheckPCurve
4840 //purpose : Checks if points of the pcurve are out of the face bounds.
4841 //=======================================================================
4842 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
4843 const TopoDS_Face& aFace)
4845 const Standard_Integer NPoints = 23;
4847 Standard_Real umin,umax,vmin,vmax;
4849 BRepTools::UVBounds(aFace, umin, umax, vmin, vmax);
4850 Standard_Real tolU = Max ((umax-umin)*0.01, Precision::Confusion());
4851 Standard_Real tolV = Max ((vmax-vmin)*0.01, Precision::Confusion());
4852 Standard_Real fp = aPC->FirstParameter();
4853 Standard_Real lp = aPC->LastParameter();
4856 // adjust domain for periodic surfaces
4857 TopLoc_Location aLoc;
4858 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc);
4859 if (aSurf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
4860 aSurf = (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf))->BasisSurface();
4862 gp_Pnt2d pnt = aPC->Value((fp+lp)/2);
4866 if (aSurf->IsUPeriodic()) {
4867 Standard_Real aPer = aSurf->UPeriod();
4868 Standard_Integer nshift = (Standard_Integer) ((u-umin)/aPer);
4869 if (u < umin+aPer*nshift) nshift--;
4870 umin += aPer*nshift;
4871 umax += aPer*nshift;
4873 if (aSurf->IsVPeriodic()) {
4874 Standard_Real aPer = aSurf->VPeriod();
4875 Standard_Integer nshift = (Standard_Integer) ((v-vmin)/aPer);
4876 if (v < vmin+aPer*nshift) nshift--;
4877 vmin += aPer*nshift;
4878 vmax += aPer*nshift;
4881 //--------------------------------------------------------
4882 Standard_Boolean bRet;
4883 Standard_Integer j, aNbIntervals;
4884 Standard_Real aT, dT;
4887 Geom2dAdaptor_Curve aGAC(aPC);
4888 aNbIntervals=aGAC.NbIntervals(GeomAbs_CN);
4890 TColStd_Array1OfReal aTI(1, aNbIntervals+1);
4891 aGAC.Intervals(aTI,GeomAbs_CN);
4893 bRet=Standard_False;
4895 aT=aGAC.FirstParameter();
4896 for (j=1; j<=aNbIntervals; ++j) {
4897 dT=(aTI(j+1)-aTI(j))/NPoints;
4899 for (i=1; i<NPoints; i++) {
4903 if (umin-u > tolU || u-umax > tolU ||
4904 vmin-v > tolV || v-vmax > tolV) {
4911 //=======================================================================
4912 //function : CorrectPlaneBoundaries
4914 //=======================================================================
4915 void CorrectPlaneBoundaries(Standard_Real& aUmin,
4916 Standard_Real& aUmax,
4917 Standard_Real& aVmin,
4918 Standard_Real& aVmax)
4920 if (!(Precision::IsInfinite(aUmin) ||
4921 Precision::IsInfinite(aUmax))) {
4924 dU=0.1*(aUmax-aUmin);
4928 if (!(Precision::IsInfinite(aVmin) ||
4929 Precision::IsInfinite(aVmax))) {
4932 dV=0.1*(aVmax-aVmin);