1 // Created on: 2000-11-23
2 // Created by: Michael KLOKOV
3 // Copyright (c) 2000-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
22 #include <IntTools_FaceFace.ixx>
24 #include <Precision.hxx>
26 #include <TColStd_HArray1OfReal.hxx>
27 #include <TColStd_Array1OfReal.hxx>
28 #include <TColStd_Array1OfInteger.hxx>
29 #include <TColStd_SequenceOfReal.hxx>
30 #include <TColStd_ListOfInteger.hxx>
31 #include <TColStd_ListIteratorOfListOfInteger.hxx>
32 #include <TColStd_Array1OfListOfInteger.hxx>
34 #include <gp_Lin2d.hxx>
35 #include <gp_Ax22d.hxx>
36 #include <gp_Circ2d.hxx>
37 #include <gp_Torus.hxx>
38 #include <gp_Cylinder.hxx>
40 #include <Bnd_Box.hxx>
42 #include <TColgp_HArray1OfPnt2d.hxx>
43 #include <TColgp_SequenceOfPnt2d.hxx>
44 #include <TColgp_Array1OfPnt.hxx>
45 #include <TColgp_Array1OfPnt2d.hxx>
47 #include <IntAna_QuadQuadGeo.hxx>
49 #include <IntSurf_PntOn2S.hxx>
50 #include <IntSurf_LineOn2S.hxx>
51 #include <IntSurf_PntOn2S.hxx>
52 #include <IntSurf_ListOfPntOn2S.hxx>
53 #include <IntRes2d_Domain.hxx>
54 #include <ProjLib_Plane.hxx>
56 #include <IntPatch_GLine.hxx>
57 #include <IntPatch_RLine.hxx>
58 #include <IntPatch_WLine.hxx>
59 #include <IntPatch_ALine.hxx>
60 #include <IntPatch_ALineToWLine.hxx>
65 #include <Extrema_ExtCC.hxx>
66 #include <Extrema_POnCurv.hxx>
67 #include <BndLib_AddSurface.hxx>
69 #include <Adaptor3d_SurfacePtr.hxx>
70 #include <Adaptor2d_HLine2d.hxx>
72 #include <GeomAbs_SurfaceType.hxx>
73 #include <GeomAbs_CurveType.hxx>
75 #include <Geom_Surface.hxx>
76 #include <Geom_Line.hxx>
77 #include <Geom_Circle.hxx>
78 #include <Geom_Ellipse.hxx>
79 #include <Geom_Parabola.hxx>
80 #include <Geom_Hyperbola.hxx>
81 #include <Geom_TrimmedCurve.hxx>
82 #include <Geom_BSplineCurve.hxx>
83 #include <Geom_RectangularTrimmedSurface.hxx>
84 #include <Geom_OffsetSurface.hxx>
85 #include <Geom_Curve.hxx>
86 #include <Geom_Conic.hxx>
88 #include <Geom2d_TrimmedCurve.hxx>
89 #include <Geom2d_BSplineCurve.hxx>
90 #include <Geom2d_Line.hxx>
91 #include <Geom2d_Curve.hxx>
92 #include <Geom2d_Circle.hxx>
94 #include <Geom2dAPI_InterCurveCurve.hxx>
95 #include <Geom2dInt_GInter.hxx>
96 #include <GeomAdaptor_Curve.hxx>
97 #include <GeomAdaptor_HSurface.hxx>
98 #include <GeomAdaptor_Surface.hxx>
99 #include <GeomLib_CheckBSplineCurve.hxx>
100 #include <GeomLib_Check2dBSplineCurve.hxx>
102 #include <GeomInt_WLApprox.hxx>
103 #include <GeomProjLib.hxx>
104 #include <GeomAPI_ProjectPointOnSurf.hxx>
105 #include <Geom2dAdaptor_Curve.hxx>
106 #include <TopoDS.hxx>
107 #include <TopoDS_Edge.hxx>
108 #include <TopExp_Explorer.hxx>
110 #include <BRep_Tool.hxx>
111 #include <BRepTools.hxx>
112 #include <BRepAdaptor_Surface.hxx>
114 #include <BOPTColStd_Dump.hxx>
116 #include <IntTools_Curve.hxx>
117 #include <IntTools_Tools.hxx>
118 #include <IntTools_Tools.hxx>
119 #include <IntTools_TopolTool.hxx>
120 #include <IntTools_PntOnFace.hxx>
121 #include <IntTools_PntOn2Faces.hxx>
122 #include <IntTools_Context.hxx>
123 #include <IntSurf_ListIteratorOfListOfPntOn2S.hxx>
126 void RefineVector(gp_Vec2d& aV2D);
129 void DumpWLine(const Handle(IntPatch_WLine)& aWLine);
132 void TolR3d(const TopoDS_Face& ,
136 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)&,
137 const Standard_Integer,
138 const Standard_Integer);
141 void Parameters(const Handle(GeomAdaptor_HSurface)&,
142 const Handle(GeomAdaptor_HSurface)&,
150 void BuildPCurves (Standard_Real f,Standard_Real l,Standard_Real& Tol,
151 const Handle (Geom_Surface)& S,
152 const Handle (Geom_Curve)& C,
153 Handle (Geom2d_Curve)& C2d);
156 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
157 const Standard_Real theTolerance,
158 Standard_Real& theumin,
159 Standard_Real& theumax,
160 Standard_Real& thevmin,
161 Standard_Real& thevmax);
163 Standard_Boolean NotUseSurfacesForApprox
164 (const TopoDS_Face& aF1,
165 const TopoDS_Face& aF2,
166 const Handle(IntPatch_WLine)& WL,
167 const Standard_Integer ifprm,
168 const Standard_Integer ilprm);
171 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine);
174 Standard_Real AdjustPeriodic(const Standard_Real theParameter,
175 const Standard_Real parmin,
176 const Standard_Real parmax,
177 const Standard_Real thePeriod,
178 Standard_Real& theOffset);
181 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
182 const Standard_Integer ideb,
183 const Standard_Integer ifin,
184 const Standard_Boolean onFirst);
187 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
188 const Handle(GeomAdaptor_HSurface)& theSurface1,
189 const Handle(GeomAdaptor_HSurface)& theSurface2,
190 const TopoDS_Face& theFace1,
191 const TopoDS_Face& theFace2,
192 const IntTools_LineConstructor& theLConstructor,
193 const Standard_Boolean theAvoidLConstructor,
194 IntPatch_SequenceOfLine& theNewLines,
195 Standard_Real& theReachedTol3d,
196 const Handle(IntTools_Context)& );
199 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
200 const Handle(Geom_Curve)& theCurve,
201 const TopoDS_Face& theFace1,
202 const TopoDS_Face& theFace2,
203 const Standard_Real theOtherParameter,
204 const Standard_Boolean bIncreasePar,
205 Standard_Real& theNewParameter,
206 const Handle(IntTools_Context)& );
209 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve);
212 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
213 const Standard_Real theFirstBoundary,
214 const Standard_Real theSecondBoundary,
215 const Standard_Real theResolution,
216 Standard_Boolean& IsOnFirstBoundary);
218 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
219 const gp_Pnt2d& theLastPoint,
220 const Standard_Real theUmin,
221 const Standard_Real theUmax,
222 const Standard_Real theVmin,
223 const Standard_Real theVmax,
224 gp_Pnt2d& theNewPoint);
228 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
229 const Handle(GeomAdaptor_HSurface)& theSurface2,
230 const TopoDS_Face& theFace1,
231 const TopoDS_Face& theFace2,
232 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
233 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
234 Handle(TColStd_HArray1OfReal)& theResultRadius,
235 const Handle(IntTools_Context)& );
238 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
239 const gp_Pnt2d& theLastPoint,
240 const Standard_Real theUmin,
241 const Standard_Real theUmax,
242 const Standard_Real theVmin,
243 const Standard_Real theVmax,
244 const gp_Pnt2d& theTanZoneCenter,
245 const Standard_Real theZoneRadius,
246 Handle(GeomAdaptor_HSurface) theGASurface,
247 gp_Pnt2d& theNewPoint);
250 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
251 const gp_Pnt2d& theTanZoneCenter,
252 const Standard_Real theZoneRadius,
253 Handle(GeomAdaptor_HSurface) theGASurface);
256 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
257 const gp_Pnt2d& theOriginalPoint,
258 Handle(GeomAdaptor_HSurface) theGASurface);
260 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
261 const gp_Sphere& theSph);
263 static void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
264 const Handle(GeomAdaptor_HSurface)& theS2,
265 const Standard_Real TolAng,
266 const Standard_Real TolTang,
267 const Standard_Boolean theApprox1,
268 const Standard_Boolean theApprox2,
269 IntTools_SequenceOfCurves& theSeqOfCurve,
270 Standard_Boolean& theTangentFaces);
272 static Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
273 const gp_Lin2d& theLin2d,
274 const Standard_Real theTol,
275 Standard_Real& theP1,
276 Standard_Real& theP2);
279 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
280 const Handle(GeomAdaptor_HSurface)& aHS2,
281 Standard_Integer& iDegMin,
282 Standard_Integer& iNbIter,
283 Standard_Integer& iDegMax);
286 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
287 const Handle(GeomAdaptor_HSurface)& aHS2,
288 Standard_Real& aTolArc,
289 Standard_Real& aTolTang,
290 Standard_Real& aUVMaxStep,
291 Standard_Real& aDeflection);
294 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
295 const GeomAbs_SurfaceType aType2);
297 Standard_Integer IndexType(const GeomAbs_SurfaceType aType);
301 Standard_Real MaxSquareDistance (const Standard_Real aT,
302 const Handle(Geom_Curve)& aC3D,
303 const Handle(Geom2d_Curve)& aC2D1,
304 const Handle(Geom2d_Curve)& aC2D2,
305 const Handle(GeomAdaptor_HSurface) myHS1,
306 const Handle(GeomAdaptor_HSurface) myHS2,
307 const TopoDS_Face& aF1,
308 const TopoDS_Face& aF2,
309 const Handle(IntTools_Context)& aCtx);
312 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
313 const TopoDS_Face& aFace);
317 Standard_Real FindMaxSquareDistance (const Standard_Real aA,
318 const Standard_Real aB,
319 const Standard_Real aEps,
320 const Handle(Geom_Curve)& aC3D,
321 const Handle(Geom2d_Curve)& aC2D1,
322 const Handle(Geom2d_Curve)& aC2D2,
323 const Handle(GeomAdaptor_HSurface)& myHS1,
324 const Handle(GeomAdaptor_HSurface)& myHS2,
325 const TopoDS_Face& aF1,
326 const TopoDS_Face& aF2,
327 const Handle(IntTools_Context)& aCtx);
329 //=======================================================================
332 //=======================================================================
333 IntTools_FaceFace::IntTools_FaceFace()
335 myTangentFaces=Standard_False;
337 myHS1 = new GeomAdaptor_HSurface ();
338 myHS2 = new GeomAdaptor_HSurface ();
341 SetParameters(Standard_True, Standard_True, Standard_True, 1.e-07);
344 //=======================================================================
345 //function : SetContext
347 //=======================================================================
348 void IntTools_FaceFace::SetContext(const Handle(IntTools_Context)& aContext)
352 //=======================================================================
355 //=======================================================================
356 const Handle(IntTools_Context)& IntTools_FaceFace::Context()const
360 //=======================================================================
363 //=======================================================================
364 const TopoDS_Face& IntTools_FaceFace::Face1() const
368 //=======================================================================
371 //=======================================================================
372 const TopoDS_Face& IntTools_FaceFace::Face2() const
376 //=======================================================================
377 //function : TangentFaces
379 //=======================================================================
380 Standard_Boolean IntTools_FaceFace::TangentFaces() const
382 return myTangentFaces;
384 //=======================================================================
387 //=======================================================================
388 const IntTools_SequenceOfPntOn2Faces& IntTools_FaceFace::Points() const
392 //=======================================================================
395 //=======================================================================
396 Standard_Boolean IntTools_FaceFace::IsDone() const
400 //=======================================================================
401 //function : TolReached3d
403 //=======================================================================
404 Standard_Real IntTools_FaceFace::TolReached3d() const
406 return myTolReached3d;
408 //=======================================================================
410 //purpose : return lines of intersection
411 //=======================================================================
412 const IntTools_SequenceOfCurves& IntTools_FaceFace::Lines() const
414 StdFail_NotDone_Raise_if
416 "IntTools_FaceFace::Lines() => !myIntersector.IsDone()");
419 //=======================================================================
420 //function : TolReached2d
422 //=======================================================================
423 Standard_Real IntTools_FaceFace::TolReached2d() const
425 return myTolReached2d;
427 // =======================================================================
428 // function: SetParameters
430 // =======================================================================
431 void IntTools_FaceFace::SetParameters(const Standard_Boolean ToApproxC3d,
432 const Standard_Boolean ToApproxC2dOnS1,
433 const Standard_Boolean ToApproxC2dOnS2,
434 const Standard_Real ApproximationTolerance)
436 myApprox = ToApproxC3d;
437 myApprox1 = ToApproxC2dOnS1;
438 myApprox2 = ToApproxC2dOnS2;
439 myTolApprox = ApproximationTolerance;
441 //=======================================================================
444 //=======================================================================
445 void IntTools_FaceFace::SetList(IntSurf_ListOfPntOn2S& aListOfPnts)
447 myListOfPnts = aListOfPnts;
449 //=======================================================================
451 //purpose : intersect surfaces of the faces
452 //=======================================================================
453 void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
454 const TopoDS_Face& aF2)
456 Standard_Boolean hasCone, RestrictLine, bTwoPlanes, bReverse;
457 Standard_Integer aNbLin, aNbPnts, i, NbLinPP;
458 Standard_Real TolArc, TolTang, Deflection, UVMaxStep;
459 Standard_Real umin, umax, vmin, vmax;
460 Standard_Real aTolF1, aTolF2;
461 GeomAbs_SurfaceType aType1, aType2;
462 Handle(Geom_Surface) S1, S2;
463 Handle(IntTools_TopolTool) dom1, dom2;
464 BRepAdaptor_Surface aBAS1, aBAS2;
466 if (myContext.IsNull()) {
467 myContext=new IntTools_Context;
470 mySeqOfCurve.Clear();
473 myIsDone = Standard_False;
475 hasCone = Standard_False;
476 bTwoPlanes = Standard_False;
481 aBAS1.Initialize(myFace1, Standard_False);
482 aBAS2.Initialize(myFace2, Standard_False);
483 aType1=aBAS1.GetType();
484 aType2=aBAS2.GetType();
486 bReverse=SortTypes(aType1, aType2);
490 aType1=aBAS2.GetType();
491 aType2=aBAS1.GetType();
493 if (myListOfPnts.Extent()) {
494 Standard_Real aU1,aV1,aU2,aV2;
495 IntSurf_ListIteratorOfListOfPntOn2S aItP2S;
497 aItP2S.Initialize(myListOfPnts);
498 for (; aItP2S.More(); aItP2S.Next()){
499 IntSurf_PntOn2S& aP2S=aItP2S.Value();
500 aP2S.Parameters(aU1,aV1,aU2,aV2);
501 aP2S.SetValue(aU2,aV2,aU1,aV1);
506 S1=BRep_Tool::Surface(myFace1);
507 S2=BRep_Tool::Surface(myFace2);
509 aTolF1=BRep_Tool::Tolerance(myFace1);
510 aTolF2=BRep_Tool::Tolerance(myFace2);
512 TolArc= aTolF1 + aTolF2;
516 if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
517 bTwoPlanes = Standard_True;
519 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
520 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
522 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
523 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
524 Standard_Real TolAng = 1.e-8;
525 PerformPlanes(myHS1, myHS2, TolAng, TolTang, myApprox1, myApprox2,
526 mySeqOfCurve, myTangentFaces);
528 myIsDone = Standard_True;
530 if(!myTangentFaces) {
532 NbLinPP = mySeqOfCurve.Length();
534 Standard_Real aTolFMax;
536 myTolReached3d = 1.e-7;
538 aTolFMax=Max(aTolF1, aTolF2);
540 if (aTolFMax>myTolReached3d) {
541 myTolReached3d=aTolFMax;
543 myTolReached2d = myTolReached3d;
546 Handle(Geom2d_Curve) aC2D1, aC2D2;
548 aNbLin=mySeqOfCurve.Length();
549 for (i=1; i<=aNbLin; ++i) {
550 IntTools_Curve& aIC=mySeqOfCurve(i);
551 aC2D1=aIC.FirstCurve2d();
552 aC2D2=aIC.SecondCurve2d();
554 aIC.SetFirstCurve2d(aC2D2);
555 aIC.SetSecondCurve2d(aC2D1);
561 }//if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
563 if (aType1==GeomAbs_Plane &&
564 (aType2==GeomAbs_Cylinder ||
565 aType2==GeomAbs_Cone ||
566 aType2==GeomAbs_Torus)) {
567 Standard_Real dU, dV;
569 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
576 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
578 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
579 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
580 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
582 if( aType2==GeomAbs_Cone ) {
584 hasCone = Standard_True;
588 else if ((aType1==GeomAbs_Cylinder||
589 aType1==GeomAbs_Cone ||
590 aType1==GeomAbs_Torus) &&
591 aType2==GeomAbs_Plane) {
592 Standard_Real dU, dV;
594 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
595 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
596 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
598 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
605 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
607 if( aType1==GeomAbs_Cone ) {
609 hasCone = Standard_True;
615 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
617 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
619 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
621 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
623 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
625 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
628 dom1 = new IntTools_TopolTool(myHS1);
629 dom2 = new IntTools_TopolTool(myHS2);
631 myLConstruct.Load(dom1, dom2, myHS1, myHS2);
633 Deflection = (hasCone) ? 0.085 : 0.1;
636 Tolerances(myHS1, myHS2, TolArc, TolTang, UVMaxStep, Deflection);
638 myIntersector.SetTolerances(TolArc, TolTang, UVMaxStep, Deflection);
640 RestrictLine = Standard_False;
642 if((myHS1->IsUClosed() && !myHS1->IsUPeriodic()) ||
643 (myHS1->IsVClosed() && !myHS1->IsVPeriodic()) ||
644 (myHS2->IsUClosed() && !myHS2->IsUPeriodic()) ||
645 (myHS2->IsVClosed() && !myHS2->IsVPeriodic())) {
646 RestrictLine = Standard_True;
649 if(((aType1 != GeomAbs_BSplineSurface) &&
650 (aType1 != GeomAbs_BezierSurface) &&
651 (aType1 != GeomAbs_OtherSurface)) &&
652 ((aType2 != GeomAbs_BSplineSurface) &&
653 (aType2 != GeomAbs_BezierSurface) &&
654 (aType2 != GeomAbs_OtherSurface))) {
655 RestrictLine = Standard_True;
657 if ((aType1 == GeomAbs_Torus) ||
658 (aType2 == GeomAbs_Torus) ) {
659 myListOfPnts.Clear();
664 TopExp_Explorer aExp;
666 for(i = 0; (!RestrictLine) && (i < 2); i++) {
667 const TopoDS_Face& aF=(!i) ? myFace1 : myFace2;
668 aExp.Init(aF, TopAbs_EDGE);
669 for(; aExp.More(); aExp.Next()) {
670 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
672 if(BRep_Tool::Degenerated(aE)) {
673 RestrictLine = Standard_True;
680 myIntersector.Perform(myHS1, dom1, myHS2, dom2,
682 myListOfPnts, RestrictLine);
684 myIsDone = myIntersector.IsDone();
686 myTangentFaces=myIntersector.TangentFaces();
687 if (myTangentFaces) {
692 myListOfPnts.Clear(); // to use LineConstructor
695 aNbLin = myIntersector.NbLines();
696 for (i=1; i<=aNbLin; ++i) {
697 MakeCurve(i, dom1, dom2);
700 ComputeTolReached3d();
703 Handle(Geom2d_Curve) aC2D1, aC2D2;
705 aNbLin=mySeqOfCurve.Length();
706 for (i=1; i<=aNbLin; ++i) {
707 IntTools_Curve& aIC=mySeqOfCurve(i);
708 aC2D1=aIC.FirstCurve2d();
709 aC2D2=aIC.SecondCurve2d();
711 aIC.SetFirstCurve2d(aC2D2);
712 aIC.SetSecondCurve2d(aC2D1);
717 Standard_Real U1,V1,U2,V2;
718 IntTools_PntOnFace aPntOnF1, aPntOnF2;
719 IntTools_PntOn2Faces aPntOn2Faces;
721 aNbPnts=myIntersector.NbPnts();
722 for (i=1; i<=aNbPnts; ++i) {
723 const IntSurf_PntOn2S& aISPnt=myIntersector.Point(i).PntOn2S();
724 const gp_Pnt& aPnt=aISPnt.Value();
725 aISPnt.Parameters(U1,V1,U2,V2);
726 aPntOnF1.Init(myFace1, aPnt, U1, V1);
727 aPntOnF2.Init(myFace2, aPnt, U2, V2);
730 aPntOn2Faces.SetP1(aPntOnF1);
731 aPntOn2Faces.SetP2(aPntOnF2);
734 aPntOn2Faces.SetP2(aPntOnF1);
735 aPntOn2Faces.SetP1(aPntOnF2);
737 myPnts.Append(aPntOn2Faces);
742 //=======================================================================
743 //function :ComputeTolReached3d
745 //=======================================================================
746 void IntTools_FaceFace::ComputeTolReached3d()
748 Standard_Integer aNbLin;
749 GeomAbs_SurfaceType aType1, aType2;
751 aNbLin=myIntersector.NbLines();
756 aType1=myHS1->Surface().GetType();
757 aType2=myHS2->Surface().GetType();
759 if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
761 Handle(IntPatch_Line) aIL1, aIL2;
762 IntPatch_IType aTL1, aTL2;
764 aIL1=myIntersector.Line(1);
765 aIL2=myIntersector.Line(2);
766 aTL1=aIL1->ArcType();
767 aTL2=aIL2->ArcType();
768 if (aTL1==IntPatch_Lin && aTL2==IntPatch_Lin) {
769 Standard_Real aD, aDTresh, dTol;
775 aL1=Handle(IntPatch_GLine)::DownCast(aIL1)->Line();
776 aL2=Handle(IntPatch_GLine)::DownCast(aIL2)->Line();
777 aD=aL1.Distance(aL2);
780 myTolReached3d=aD+dTol;
786 if (aNbLin) {// Check the distances
787 Standard_Integer i, aNbP, j ;
788 Standard_Real aT1, aT2, dT, aD2, aD2Max, aEps, aT11, aT12;
792 aNbLin=mySeqOfCurve.Length();
794 for (i=1; i<=aNbLin; ++i) {
795 const IntTools_Curve& aIC=mySeqOfCurve(i);
796 const Handle(Geom_Curve)& aC3D=aIC.Curve();
797 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
798 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
803 const Handle(Geom_BSplineCurve)& aBC=
804 Handle(Geom_BSplineCurve)::DownCast(aC3D);
809 aT1=aBC->FirstParameter();
810 aT2=aBC->LastParameter();
814 for (j=1; j<aNbP; ++j) {
817 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
818 myHS1, myHS2, myFace1, myFace2, myContext);
823 }//for (i=1; i<=aNbLin; ++i) {
825 myTolReached3d=sqrt(aD2Max);
827 }// if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
830 else if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
831 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
835 aTolF1 = BRep_Tool::Tolerance(myFace1);
836 aTolF2 = BRep_Tool::Tolerance(myFace2);
837 aTolFMax=Max(aTolF1, aTolF2);
839 if (aTolFMax>aTolTresh) {
840 myTolReached3d=aTolFMax;
842 }//if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
845 else if((aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) ||
846 (aType2 == GeomAbs_Cylinder && aType1 == GeomAbs_Plane)) {
848 const Handle(IntPatch_Line)& aIL1 = myIntersector.Line(1);
849 if(aIL1->ArcType() == IntPatch_Circle) {
850 gp_Circ aCir = Handle(IntPatch_GLine)::DownCast(aIL1)->Circle();
851 gp_XYZ aCirDir = aCir.Axis().Direction().XYZ();
854 if(aType1 == GeomAbs_Plane) {
855 aPln = myHS1->Surface().Plane();
858 aPln = myHS2->Surface().Plane();
860 aPlDir = aPln.Axis().Direction().XYZ();
861 Standard_Real cs = aCirDir*aPlDir;
862 if(cs < 0.) aPlDir.Reverse();
863 Standard_Real eps = 1.e-14;
864 if(!aPlDir.IsEqual(aCirDir, eps)) {
865 Standard_Integer aNbP = 11;
866 Standard_Real dt = 2.*M_PI / (aNbP - 1), t;
867 for(t = 0.; t < 2.*M_PI; t += dt) {
868 Standard_Real d = aPln.Distance(ElCLib::Value(t, aCir));
869 if(myTolReached3d < d) myTolReached3d = d;
871 myTolReached3d *= 1.1;
873 } //aIL1->ArcType() == IntPatch_Circle
875 } // aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane)
876 //End IFV Bug OCC20297
878 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
879 (aType2==GeomAbs_Plane && aType1==GeomAbs_Torus)) {
880 aNbLin=mySeqOfCurve.Length();
885 Standard_Integer i, aNbP;
886 Standard_Real aT, aT1, aT2, dT, aUT, aVT, aUP, aVP;
887 Standard_Real aDP, aDT, aDmax;
892 const IntTools_Curve& aIC=mySeqOfCurve(1);
893 const Handle(Geom_Curve)& aC3D=aIC.Curve();
894 const Handle(Geom_BSplineCurve)& aBS=
895 Handle(Geom_BSplineCurve)::DownCast(aC3D);
900 aT1=aBS->FirstParameter();
901 aT2=aBS->LastParameter();
903 aPln =(aType1==GeomAbs_Plane) ? myHS1->Plane() : myHS2->Plane();
904 aTorus=(aType1==GeomAbs_Plane) ? myHS2->Torus() : myHS1->Torus();
908 dT=(aT2-aT1)/(aNbP-1);
909 for (i=0; i<aNbP; ++i) {
917 ElSLib::Parameters(aPln, aP, aUP, aVP);
918 aPP=ElSLib::Value(aUP, aVP, aPln);
919 aDP=aP.SquareDistance(aPP);
924 ElSLib::Parameters(aTorus, aP, aUT, aVT);
925 aPT=ElSLib::Value(aUT, aVT, aTorus);
926 aDT=aP.SquareDistance(aPT);
932 if (aDmax > myTolReached3d*myTolReached3d) {
933 myTolReached3d=sqrt(aDmax);
934 myTolReached3d=1.1*myTolReached3d;
936 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
938 else if ((aType1==GeomAbs_SurfaceOfRevolution && aType2==GeomAbs_Cylinder) ||
939 (aType2==GeomAbs_SurfaceOfRevolution && aType1==GeomAbs_Cylinder)) {
940 Standard_Integer i, j, aNbP;
941 Standard_Real aT, aT1, aT2, dT, aD2max, aD2;
943 aNbLin=mySeqOfCurve.Length();
947 for (i=1; i<=aNbLin; ++i) {
948 const IntTools_Curve& aIC=mySeqOfCurve(i);
949 const Handle(Geom_Curve)& aC3D=aIC.Curve();
950 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
951 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
956 const Handle(Geom_BSplineCurve)& aBC=
957 Handle(Geom_BSplineCurve)::DownCast(aC3D);
962 aT1=aBC->FirstParameter();
963 aT2=aBC->LastParameter();
965 dT=(aT2-aT1)/(aNbP-1);
966 for (j=0; j<aNbP; ++j) {
972 aD2=MaxSquareDistance(aT, aC3D, aC2D1, aC2D2,
973 myHS1, myHS2, myFace1, myFace2, myContext);
977 }//for (j=0; j<aNbP; ++j) {
979 }//for (i=1; i<=aNbLin; ++i) {
981 aD2=myTolReached3d*myTolReached3d;
983 myTolReached3d=sqrt(aD2max);
985 }//if((aType1==GeomAbs_SurfaceOfRevolution ...
986 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ||
987 (aType2==GeomAbs_Plane && aType1==GeomAbs_Sphere)) {
988 Standard_Integer i, j, aNbP;
989 Standard_Real aT, aT1, aT2, dT, aD2max, aD2, aEps, aT11, aT12;
991 aNbLin=mySeqOfCurve.Length();
995 for (i=1; i<=aNbLin; ++i) {
996 const IntTools_Curve& aIC=mySeqOfCurve(i);
997 const Handle(Geom_Curve)& aC3D=aIC.Curve();
998 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
999 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1001 const Handle(Geom2d_BSplineCurve)& aBC2D1=
1002 Handle(Geom2d_BSplineCurve)::DownCast(aC2D1);
1003 const Handle(Geom2d_BSplineCurve)& aBC2D2=
1004 Handle(Geom2d_BSplineCurve)::DownCast(aC2D2);
1006 if (aBC2D1.IsNull() && aBC2D2.IsNull()) {
1010 if (!aBC2D1.IsNull()) {
1011 aT1=aBC2D1->FirstParameter();
1012 aT2=aBC2D1->LastParameter();
1015 aT1=aBC2D2->FirstParameter();
1016 aT2=aBC2D2->LastParameter();
1019 aEps=0.01*(aT2-aT1);
1020 dT=(aT2-aT1)/(aNbP-1);
1021 for (j=0; j<aNbP; ++j) {
1029 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
1030 myHS1, myHS2, myFace1, myFace2, myContext);
1034 }//for (j=0; j<aNbP; ++j) {
1036 }//for (i=1; i<=aNbLin; ++i) {
1038 aD2=myTolReached3d*myTolReached3d;
1040 myTolReached3d=sqrt(aD2max);
1042 }//else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ...
1044 //=======================================================================
1045 //function : MakeCurve
1047 //=======================================================================
1048 void IntTools_FaceFace::MakeCurve(const Standard_Integer Index,
1049 const Handle(Adaptor3d_TopolTool)& dom1,
1050 const Handle(Adaptor3d_TopolTool)& dom2)
1052 Standard_Boolean bDone, rejectSurface, reApprox, bAvoidLineConstructor,
1054 Standard_Boolean ok;
1055 Standard_Integer i, j, aNbParts;
1056 Standard_Real fprm, lprm;
1057 Standard_Real Tolpc;
1058 Handle(IntPatch_Line) L;
1059 IntPatch_IType typl;
1060 Handle(Geom_Curve) newc;
1062 const Standard_Real TOLCHECK =0.0000001;
1063 const Standard_Real TOLANGCHECK=0.1;
1065 rejectSurface = Standard_False;
1066 reApprox = Standard_False;
1068 bPCurvesOk = Standard_True;
1072 Tolpc = myTolApprox;
1073 bAvoidLineConstructor = Standard_False;
1074 L = myIntersector.Line(Index);
1075 typl = L->ArcType();
1077 if(typl==IntPatch_Walking) {
1078 Handle(IntPatch_Line) anewL;
1080 const Handle(IntPatch_WLine)& aWLine=
1081 Handle(IntPatch_WLine)::DownCast(L);
1083 //DumpWLine(aWLine);
1085 anewL = ComputePurgedWLine(aWLine);
1086 if(anewL.IsNull()) {
1092 { const Handle(IntPatch_WLine)& aWLineX=
1093 Handle(IntPatch_WLine)::DownCast(L);
1099 if(!myListOfPnts.IsEmpty()) {
1100 bAvoidLineConstructor = Standard_True;
1103 Standard_Integer nbp = aWLine->NbPnts();
1104 const IntSurf_PntOn2S& p1 = aWLine->Point(1);
1105 const IntSurf_PntOn2S& p2 = aWLine->Point(nbp);
1107 const gp_Pnt& P1 = p1.Value();
1108 const gp_Pnt& P2 = p2.Value();
1110 if(P1.SquareDistance(P2) < 1.e-14) {
1111 bAvoidLineConstructor = Standard_False;
1117 if(!bAvoidLineConstructor) {
1118 myLConstruct.Perform(L);
1120 bDone=myLConstruct.IsDone();
1121 aNbParts=myLConstruct.NbParts();
1122 if (!bDone|| !aNbParts) {
1131 //########################################
1132 // Line, Parabola, Hyperbola
1133 //########################################
1135 case IntPatch_Parabola:
1136 case IntPatch_Hyperbola: {
1137 if (typl == IntPatch_Lin) {
1139 new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line());
1142 else if (typl == IntPatch_Parabola) {
1144 new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola());
1147 else if (typl == IntPatch_Hyperbola) {
1149 new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola());
1153 if (typl == IntPatch_Lin) {
1154 TolR3d (myFace1, myFace2, myTolReached3d);
1157 aNbParts=myLConstruct.NbParts();
1158 for (i=1; i<=aNbParts; i++) {
1159 myLConstruct.Part(i, fprm, lprm);
1161 if (!Precision::IsNegativeInfinite(fprm) &&
1162 !Precision::IsPositiveInfinite(lprm)) {
1164 IntTools_Curve aCurve;
1166 Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm);
1167 aCurve.SetCurve(aCT3D);
1168 if (typl == IntPatch_Parabola) {
1169 Standard_Real aTolF1, aTolF2, aTolBase;
1171 aTolF1 = BRep_Tool::Tolerance(myFace1);
1172 aTolF2 = BRep_Tool::Tolerance(myFace2);
1173 aTolBase=aTolF1+aTolF2;
1174 myTolReached3d=IntTools_Tools::CurveTolerance(aCT3D, aTolBase);
1177 aCurve.SetCurve(new Geom_TrimmedCurve(newc, fprm, lprm));
1179 Handle (Geom2d_Curve) C2d;
1180 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1181 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1182 myTolReached2d=Tolpc;
1185 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1188 Handle(Geom2d_BSplineCurve) H1;
1190 aCurve.SetFirstCurve2d(H1);
1194 Handle (Geom2d_Curve) C2d;
1195 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1196 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1197 myTolReached2d=Tolpc;
1200 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1203 Handle(Geom2d_BSplineCurve) H1;
1205 aCurve.SetSecondCurve2d(H1);
1207 mySeqOfCurve.Append(aCurve);
1208 } // end of if (!Precision::IsNegativeInfinite(fprm) && !Precision::IsPositiveInfinite(lprm))
1211 // on regarde si on garde
1213 Standard_Boolean bFNIt, bLPIt;
1214 Standard_Real aTestPrm, dT=100.;
1216 bFNIt=Precision::IsNegativeInfinite(fprm);
1217 bLPIt=Precision::IsPositiveInfinite(lprm);
1221 if (bFNIt && !bLPIt) {
1224 else if (!bFNIt && bLPIt) {
1228 gp_Pnt ptref(newc->Value(aTestPrm));
1231 Standard_Real u1, v1, u2, v2, Tol;
1233 Tol = Precision::Confusion();
1234 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1235 ok = (dom1->Classify(gp_Pnt2d(u1, v1), Tol) != TopAbs_OUT);
1237 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1240 Handle(Geom2d_BSplineCurve) H1;
1241 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1244 }// end of for (i=1; i<=myLConstruct.NbParts(); i++)
1245 }// case IntPatch_Lin: case IntPatch_Parabola: case IntPatch_Hyperbola:
1248 //########################################
1249 // Circle and Ellipse
1250 //########################################
1251 case IntPatch_Circle:
1252 case IntPatch_Ellipse: {
1254 if (typl == IntPatch_Circle) {
1255 newc = new Geom_Circle
1256 (Handle(IntPatch_GLine)::DownCast(L)->Circle());
1258 else { //IntPatch_Ellipse
1259 newc = new Geom_Ellipse
1260 (Handle(IntPatch_GLine)::DownCast(L)->Ellipse());
1264 TolR3d (myFace1, myFace2, myTolReached3d);
1266 aNbParts=myLConstruct.NbParts();
1268 Standard_Real aPeriod, aNul;
1269 TColStd_SequenceOfReal aSeqFprm, aSeqLprm;
1274 for (i=1; i<=aNbParts; i++) {
1275 myLConstruct.Part(i, fprm, lprm);
1277 if (fprm < aNul && lprm > aNul) {
1278 // interval that goes through 0. is divided on two intervals;
1279 while (fprm<aNul || fprm>aPeriod) fprm=fprm+aPeriod;
1280 while (lprm<aNul || lprm>aPeriod) lprm=lprm+aPeriod;
1282 if((aPeriod - fprm) > Tolpc) {
1283 aSeqFprm.Append(fprm);
1284 aSeqLprm.Append(aPeriod);
1287 gp_Pnt P1 = newc->Value(fprm);
1288 gp_Pnt P2 = newc->Value(aPeriod);
1289 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1290 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1292 if(P1.Distance(P2) > aTolDist) {
1293 Standard_Real anewpar = fprm;
1295 if(ParameterOutOfBoundary(fprm, newc, myFace1, myFace2, lprm, Standard_False, anewpar, myContext)) {
1298 aSeqFprm.Append(fprm);
1299 aSeqLprm.Append(aPeriod);
1304 if((lprm - aNul) > Tolpc) {
1305 aSeqFprm.Append(aNul);
1306 aSeqLprm.Append(lprm);
1309 gp_Pnt P1 = newc->Value(aNul);
1310 gp_Pnt P2 = newc->Value(lprm);
1311 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1312 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1314 if(P1.Distance(P2) > aTolDist) {
1315 Standard_Real anewpar = lprm;
1317 if(ParameterOutOfBoundary(lprm, newc, myFace1, myFace2, fprm, Standard_True, anewpar, myContext)) {
1320 aSeqFprm.Append(aNul);
1321 aSeqLprm.Append(lprm);
1327 aSeqFprm.Append(fprm);
1328 aSeqLprm.Append(lprm);
1333 aNbParts=aSeqFprm.Length();
1334 for (i=1; i<=aNbParts; i++) {
1338 Standard_Real aRealEpsilon=RealEpsilon();
1339 if (Abs(fprm) > aRealEpsilon || Abs(lprm-2.*M_PI) > aRealEpsilon) {
1340 //==============================================
1342 IntTools_Curve aCurve;
1343 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1344 aCurve.SetCurve(aTC3D);
1345 fprm=aTC3D->FirstParameter();
1346 lprm=aTC3D->LastParameter ();
1348 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {////
1350 Handle (Geom2d_Curve) C2d;
1351 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1352 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1353 myTolReached2d=Tolpc;
1356 aCurve.SetFirstCurve2d(C2d);
1359 Handle(Geom2d_BSplineCurve) H1;
1360 aCurve.SetFirstCurve2d(H1);
1365 Handle (Geom2d_Curve) C2d;
1366 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1367 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1368 myTolReached2d=Tolpc;
1371 aCurve.SetSecondCurve2d(C2d);
1374 Handle(Geom2d_BSplineCurve) H1;
1375 aCurve.SetSecondCurve2d(H1);
1380 Handle(Geom2d_BSplineCurve) H1;
1381 aCurve.SetFirstCurve2d(H1);
1382 aCurve.SetSecondCurve2d(H1);
1384 mySeqOfCurve.Append(aCurve);
1385 //==============================================
1386 } //if (Abs(fprm) > RealEpsilon() || Abs(lprm-2.*M_PI) > RealEpsilon())
1389 // on regarde si on garde
1392 // if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*M_PI) < RealEpsilon()) {
1393 if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*M_PI) <= aRealEpsilon) {
1394 IntTools_Curve aCurve;
1395 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1396 aCurve.SetCurve(aTC3D);
1397 fprm=aTC3D->FirstParameter();
1398 lprm=aTC3D->LastParameter ();
1401 Handle (Geom2d_Curve) C2d;
1402 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1403 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1404 myTolReached2d=Tolpc;
1407 aCurve.SetFirstCurve2d(C2d);
1410 Handle(Geom2d_BSplineCurve) H1;
1411 aCurve.SetFirstCurve2d(H1);
1415 Handle (Geom2d_Curve) C2d;
1416 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1417 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1418 myTolReached2d=Tolpc;
1421 aCurve.SetSecondCurve2d(C2d);
1424 Handle(Geom2d_BSplineCurve) H1;
1425 aCurve.SetSecondCurve2d(H1);
1427 mySeqOfCurve.Append(aCurve);
1432 Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol;
1434 aTwoPIdiv17=2.*M_PI/17.;
1436 for (j=0; j<=17; j++) {
1437 gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
1438 Tol = Precision::Confusion();
1440 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1441 ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT);
1443 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1446 IntTools_Curve aCurve;
1447 aCurve.SetCurve(newc);
1448 //==============================================
1449 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {
1452 Handle (Geom2d_Curve) C2d;
1453 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1454 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1455 myTolReached2d=Tolpc;
1458 aCurve.SetFirstCurve2d(C2d);
1461 Handle(Geom2d_BSplineCurve) H1;
1462 aCurve.SetFirstCurve2d(H1);
1466 Handle (Geom2d_Curve) C2d;
1467 BuildPCurves(fprm, lprm, Tolpc,myHS2->ChangeSurface().Surface(), newc, C2d);
1468 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1469 myTolReached2d=Tolpc;
1472 aCurve.SetSecondCurve2d(C2d);
1476 Handle(Geom2d_BSplineCurve) H1;
1477 aCurve.SetSecondCurve2d(H1);
1479 }// end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse)
1482 Handle(Geom2d_BSplineCurve) H1;
1484 aCurve.SetFirstCurve2d(H1);
1485 aCurve.SetSecondCurve2d(H1);
1487 //==============================================
1489 mySeqOfCurve.Append(aCurve);
1492 }// end of if (ok) {
1493 }// end of for (Standard_Integer j=0; j<=17; j++)
1494 }// end of else { on regarde si on garde
1495 }// for (i=1; i<=myLConstruct.NbParts(); i++)
1496 }// IntPatch_Circle: IntPatch_Ellipse:
1499 case IntPatch_Analytic: {
1500 IntSurf_Quadric quad1,quad2;
1501 GeomAbs_SurfaceType typs = myHS1->Surface().GetType();
1505 quad1.SetValue(myHS1->Surface().Plane());
1507 case GeomAbs_Cylinder:
1508 quad1.SetValue(myHS1->Surface().Cylinder());
1511 quad1.SetValue(myHS1->Surface().Cone());
1513 case GeomAbs_Sphere:
1514 quad1.SetValue(myHS1->Surface().Sphere());
1517 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 1");
1520 typs = myHS2->Surface().GetType();
1524 quad2.SetValue(myHS2->Surface().Plane());
1526 case GeomAbs_Cylinder:
1527 quad2.SetValue(myHS2->Surface().Cylinder());
1530 quad2.SetValue(myHS2->Surface().Cone());
1532 case GeomAbs_Sphere:
1533 quad2.SetValue(myHS2->Surface().Sphere());
1536 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 2");
1540 IntPatch_ALineToWLine convert (quad1, quad2);
1543 aNbParts=myLConstruct.NbParts();
1544 for (i=1; i<=aNbParts; i++) {
1545 myLConstruct.Part(i, fprm, lprm);
1546 Handle(IntPatch_WLine) WL =
1547 convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm);
1549 Handle(Geom2d_BSplineCurve) H1;
1550 Handle(Geom2d_BSplineCurve) H2;
1553 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1557 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1560 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1564 else { // myApprox=TRUE
1565 GeomInt_WLApprox theapp3d;
1567 Standard_Real tol2d = myTolApprox;
1569 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True);
1571 aNbParts=myLConstruct.NbParts();
1572 for (i=1; i<=aNbParts; i++) {
1573 myLConstruct.Part(i, fprm, lprm);
1574 Handle(IntPatch_WLine) WL =
1575 convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
1577 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
1579 if (!theapp3d.IsDone()) {
1581 Handle(Geom2d_BSplineCurve) H1;
1582 Handle(Geom2d_BSplineCurve) H2;
1585 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1589 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1592 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1596 if(myApprox1 || myApprox2) {
1597 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) {
1598 myTolReached2d = theapp3d.TolReached2d();
1602 if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) {
1603 myTolReached3d = theapp3d.TolReached3d();
1606 Standard_Integer aNbMultiCurves, nbpoles;
1607 aNbMultiCurves=theapp3d.NbMultiCurves();
1608 for (j=1; j<=aNbMultiCurves; j++) {
1609 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1610 nbpoles = mbspc.NbPoles();
1612 TColgp_Array1OfPnt tpoles(1, nbpoles);
1613 mbspc.Curve(1, tpoles);
1614 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1616 mbspc.Multiplicities(),
1619 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1620 Check.FixTangent(Standard_True,Standard_True);
1622 IntTools_Curve aCurve;
1623 aCurve.SetCurve(BS);
1626 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1627 mbspc.Curve(2,tpoles2d);
1628 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1630 mbspc.Multiplicities(),
1633 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1634 newCheck.FixTangent(Standard_True,Standard_True);
1636 aCurve.SetFirstCurve2d(BS2);
1639 Handle(Geom2d_BSplineCurve) H1;
1640 aCurve.SetFirstCurve2d(H1);
1644 TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
1645 Standard_Integer TwoOrThree;
1646 TwoOrThree=myApprox1 ? 3 : 2;
1647 mbspc.Curve(TwoOrThree, tpoles2d);
1648 Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
1650 mbspc.Multiplicities(),
1653 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1654 newCheck.FixTangent(Standard_True,Standard_True);
1656 aCurve.SetSecondCurve2d(BS2);
1659 Handle(Geom2d_BSplineCurve) H2;
1660 aCurve.SetSecondCurve2d(H2);
1663 mySeqOfCurve.Append(aCurve);
1665 }// for (j=1; j<=aNbMultiCurves; j++) {
1666 }// else from if (!theapp3d.IsDone())
1667 }// for (i=1; i<=aNbParts; i++) {
1668 }// else { // myApprox=TRUE
1669 }// case IntPatch_Analytic:
1672 case IntPatch_Walking:{
1673 Handle(IntPatch_WLine) WL =
1674 Handle(IntPatch_WLine)::DownCast(L);
1676 Standard_Integer ifprm, ilprm;
1680 if(!bAvoidLineConstructor){
1681 aNbParts=myLConstruct.NbParts();
1683 for (i=1; i<=aNbParts; ++i) {
1684 Handle(Geom2d_BSplineCurve) H1, H2;
1685 Handle(Geom_Curve) aBSp;
1687 if(bAvoidLineConstructor) {
1689 ilprm = WL->NbPnts();
1692 myLConstruct.Part(i, fprm, lprm);
1693 ifprm=(Standard_Integer)fprm;
1694 ilprm=(Standard_Integer)lprm;
1698 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1702 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1705 aBSp=MakeBSpline(WL, ifprm, ilprm);
1706 IntTools_Curve aIC(aBSp, H1, H2);
1707 mySeqOfCurve.Append(aIC);
1708 }// for (i=1; i<=aNbParts; ++i) {
1709 }// if (!myApprox) {
1712 Standard_Boolean bIsDecomposited;
1713 Standard_Integer nbiter, aNbSeqOfL;
1714 Standard_Real tol2d;
1715 IntPatch_SequenceOfLine aSeqOfL;
1716 GeomInt_WLApprox theapp3d;
1717 Approx_ParametrizationType aParType = Approx_ChordLength;
1719 Standard_Boolean anApprox1 = myApprox1;
1720 Standard_Boolean anApprox2 = myApprox2;
1722 tol2d = myTolApprox;
1724 GeomAbs_SurfaceType typs1, typs2;
1725 typs1 = myHS1->Surface().GetType();
1726 typs2 = myHS2->Surface().GetType();
1727 Standard_Boolean anWithPC = Standard_True;
1729 if(typs1 == GeomAbs_Cylinder && typs2 == GeomAbs_Sphere) {
1731 ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere());
1733 else if (typs1 == GeomAbs_Sphere && typs2 == GeomAbs_Cylinder) {
1735 ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere());
1738 //aParType = Approx_Centripetal;
1739 myTolApprox = 1.e-5;
1740 anApprox1 = Standard_False;
1741 anApprox2 = Standard_False;
1743 tol2d = myTolApprox;
1746 if(myHS1 == myHS2) {
1748 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1749 rejectSurface = Standard_True;
1752 if(reApprox && !rejectSurface)
1753 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1755 Standard_Integer iDegMax, iDegMin, iNbIter;
1757 ApproxParameters(myHS1, myHS2, iDegMin, iDegMax, iNbIter);
1758 theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, iNbIter, Standard_True, aParType);
1763 Standard_Real aReachedTol = Precision::Confusion();
1764 bIsDecomposited=DecompositionOfWLine(WL,
1770 bAvoidLineConstructor,
1774 if ( bIsDecomposited && ( myTolReached3d < aReachedTol ) )
1775 myTolReached3d = aReachedTol;
1778 aNbSeqOfL=aSeqOfL.Length();
1780 if (bIsDecomposited) {
1786 if (!bAvoidLineConstructor) {
1787 aNbParts=myLConstruct.NbParts();
1792 // nbiter=(bIsDecomposited) ? aSeqOfL.Length() :
1793 // ((bAvoidLineConstructor) ? 1 :aNbParts);
1795 for(i = 1; i <= nbiter; ++i) {
1796 if(bIsDecomposited) {
1797 WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i));
1799 ilprm = WL->NbPnts();
1802 if(bAvoidLineConstructor) {
1804 ilprm = WL->NbPnts();
1807 myLConstruct.Part(i, fprm, lprm);
1808 ifprm = (Standard_Integer)fprm;
1809 ilprm = (Standard_Integer)lprm;
1813 //-- Si une des surfaces est un plan , on approxime en 2d
1814 //-- sur cette surface et on remonte les points 2d en 3d.
1815 if(typs1 == GeomAbs_Plane) {
1816 theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm);
1818 else if(typs2 == GeomAbs_Plane) {
1819 theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm);
1823 if (myHS1 != myHS2){
1824 if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) &&
1825 (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) {
1827 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType);
1829 Standard_Boolean bUseSurfaces;
1830 bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm, ilprm);
1833 rejectSurface = Standard_True;
1835 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1840 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm);
1843 if (!theapp3d.IsDone()) {
1845 Handle(Geom2d_BSplineCurve) H1;
1847 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
1848 Handle(Geom2d_BSplineCurve) H2;
1851 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1855 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1858 IntTools_Curve aIC(aBSp, H1, H2);
1859 mySeqOfCurve.Append(aIC);
1863 if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) {
1864 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) {
1865 myTolReached2d = theapp3d.TolReached2d();
1868 if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) {
1869 myTolReached3d = myTolReached2d;
1871 if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
1872 if (myTolReached3d<1.e-6) {
1873 myTolReached3d = theapp3d.TolReached3d();
1874 myTolReached3d=1.e-6;
1879 else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) {
1880 myTolReached3d = theapp3d.TolReached3d();
1883 Standard_Integer aNbMultiCurves, nbpoles;
1884 aNbMultiCurves=theapp3d.NbMultiCurves();
1885 for (j=1; j<=aNbMultiCurves; j++) {
1886 if(typs1 == GeomAbs_Plane) {
1887 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1888 nbpoles = mbspc.NbPoles();
1890 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1891 TColgp_Array1OfPnt tpoles(1,nbpoles);
1893 mbspc.Curve(1,tpoles2d);
1894 const gp_Pln& Pln = myHS1->Surface().Plane();
1896 Standard_Integer ik;
1897 for(ik = 1; ik<= nbpoles; ik++) {
1899 ElSLib::Value(tpoles2d.Value(ik).X(),
1900 tpoles2d.Value(ik).Y(),
1904 Handle(Geom_BSplineCurve) BS =
1905 new Geom_BSplineCurve(tpoles,
1907 mbspc.Multiplicities(),
1909 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1910 Check.FixTangent(Standard_True, Standard_True);
1912 IntTools_Curve aCurve;
1913 aCurve.SetCurve(BS);
1916 Handle(Geom2d_BSplineCurve) BS1 =
1917 new Geom2d_BSplineCurve(tpoles2d,
1919 mbspc.Multiplicities(),
1921 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
1922 Check1.FixTangent(Standard_True,Standard_True);
1924 // ############################################
1925 if(!rejectSurface && !reApprox) {
1926 Standard_Boolean isValid = IsCurveValid(BS1);
1928 reApprox = Standard_True;
1932 // ############################################
1933 aCurve.SetFirstCurve2d(BS1);
1936 Handle(Geom2d_BSplineCurve) H1;
1937 aCurve.SetFirstCurve2d(H1);
1941 mbspc.Curve(2, tpoles2d);
1943 Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
1945 mbspc.Multiplicities(),
1947 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1948 newCheck.FixTangent(Standard_True,Standard_True);
1950 // ###########################################
1951 if(!rejectSurface && !reApprox) {
1952 Standard_Boolean isValid = IsCurveValid(BS2);
1954 reApprox = Standard_True;
1958 // ###########################################
1960 aCurve.SetSecondCurve2d(BS2);
1963 Handle(Geom2d_BSplineCurve) H2;
1965 aCurve.SetSecondCurve2d(H2);
1968 mySeqOfCurve.Append(aCurve);
1971 else if(typs2 == GeomAbs_Plane) {
1972 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1973 nbpoles = mbspc.NbPoles();
1975 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1976 TColgp_Array1OfPnt tpoles(1,nbpoles);
1977 mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d);
1978 const gp_Pln& Pln = myHS2->Surface().Plane();
1980 Standard_Integer ik;
1981 for(ik = 1; ik<= nbpoles; ik++) {
1983 ElSLib::Value(tpoles2d.Value(ik).X(),
1984 tpoles2d.Value(ik).Y(),
1989 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1991 mbspc.Multiplicities(),
1993 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1994 Check.FixTangent(Standard_True,Standard_True);
1996 IntTools_Curve aCurve;
1997 aCurve.SetCurve(BS);
2000 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
2002 mbspc.Multiplicities(),
2004 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
2005 Check1.FixTangent(Standard_True,Standard_True);
2007 // ###########################################
2008 if(!rejectSurface && !reApprox) {
2009 Standard_Boolean isValid = IsCurveValid(BS1);
2011 reApprox = Standard_True;
2015 // ###########################################
2016 bPCurvesOk = CheckPCurve(BS1, myFace2);
2017 aCurve.SetSecondCurve2d(BS1);
2020 Handle(Geom2d_BSplineCurve) H2;
2021 aCurve.SetSecondCurve2d(H2);
2025 mbspc.Curve(1,tpoles2d);
2026 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
2028 mbspc.Multiplicities(),
2030 GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK);
2031 Check2.FixTangent(Standard_True,Standard_True);
2033 // ###########################################
2034 if(!rejectSurface && !reApprox) {
2035 Standard_Boolean isValid = IsCurveValid(BS2);
2037 reApprox = Standard_True;
2041 // ###########################################
2042 bPCurvesOk = bPCurvesOk && CheckPCurve(BS2, myFace1);
2043 aCurve.SetFirstCurve2d(BS2);
2046 Handle(Geom2d_BSplineCurve) H1;
2048 aCurve.SetFirstCurve2d(H1);
2051 //if points of the pcurves are out of the faces bounds
2052 //create 3d and 2d curves without approximation
2054 Handle(Geom2d_BSplineCurve) H1, H2;
2055 bPCurvesOk = Standard_True;
2057 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
2060 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
2061 bPCurvesOk = CheckPCurve(H1, myFace1);
2065 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
2066 bPCurvesOk = bPCurvesOk && CheckPCurve(H2, myFace2);
2069 //if pcurves created without approximation are out of the
2070 //faces bounds, use approximated 3d and 2d curves
2072 IntTools_Curve aIC(aBSp, H1, H2);
2073 mySeqOfCurve.Append(aIC);
2075 mySeqOfCurve.Append(aCurve);
2078 mySeqOfCurve.Append(aCurve);
2082 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2083 nbpoles = mbspc.NbPoles();
2084 TColgp_Array1OfPnt tpoles(1,nbpoles);
2085 mbspc.Curve(1,tpoles);
2086 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
2088 mbspc.Multiplicities(),
2090 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2091 Check.FixTangent(Standard_True,Standard_True);
2093 IntTools_Curve aCurve;
2094 aCurve.SetCurve(BS);
2098 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2099 mbspc.Curve(2,tpoles2d);
2100 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
2102 mbspc.Multiplicities(),
2104 GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK);
2105 newCheck.FixTangent(Standard_True,Standard_True);
2107 aCurve.SetFirstCurve2d(BS1);
2110 Handle(Geom2d_BSplineCurve) BS1;
2111 fprm = BS->FirstParameter();
2112 lprm = BS->LastParameter();
2114 Handle(Geom2d_Curve) C2d;
2115 Standard_Real aTol = myTolApprox;
2116 BuildPCurves(fprm, lprm, aTol, myHS1->ChangeSurface().Surface(), BS, C2d);
2117 BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2118 aCurve.SetFirstCurve2d(BS1);
2123 Handle(Geom2d_BSplineCurve) H1;
2125 aCurve.SetFirstCurve2d(H1);
2129 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2130 mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d);
2131 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
2133 mbspc.Multiplicities(),
2135 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2136 newCheck.FixTangent(Standard_True,Standard_True);
2138 aCurve.SetSecondCurve2d(BS2);
2141 Handle(Geom2d_BSplineCurve) BS2;
2142 fprm = BS->FirstParameter();
2143 lprm = BS->LastParameter();
2145 Handle(Geom2d_Curve) C2d;
2146 Standard_Real aTol = myTolApprox;
2147 BuildPCurves(fprm, lprm, aTol, myHS2->ChangeSurface().Surface(), BS, C2d);
2148 BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2149 aCurve.SetSecondCurve2d(BS2);
2154 Handle(Geom2d_BSplineCurve) H2;
2156 aCurve.SetSecondCurve2d(H2);
2159 mySeqOfCurve.Append(aCurve);
2165 }// case IntPatch_Walking:{
2168 case IntPatch_Restriction:
2174 //=======================================================================
2175 //function : BuildPCurves
2177 //=======================================================================
2178 void BuildPCurves (Standard_Real f,
2181 const Handle (Geom_Surface)& S,
2182 const Handle (Geom_Curve)& C,
2183 Handle (Geom2d_Curve)& C2d)
2186 Standard_Real umin,umax,vmin,vmax;
2191 // in class ProjLib_Function the range of parameters is shrank by 1.e-09
2192 if((l - f) > 2.e-09) {
2193 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2196 // proj. a circle that goes through the pole on a sphere to the sphere
2198 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2202 if((l - f) > Epsilon(Abs(f))) {
2203 GeomAPI_ProjectPointOnSurf aProjector1, aProjector2;
2204 gp_Pnt P1 = C->Value(f);
2205 gp_Pnt P2 = C->Value(l);
2206 aProjector1.Init(P1, S);
2207 aProjector2.Init(P2, S);
2209 if(aProjector1.IsDone() && aProjector2.IsDone()) {
2210 Standard_Real U=0., V=0.;
2211 aProjector1.LowerDistanceParameters(U, V);
2214 aProjector2.LowerDistanceParameters(U, V);
2217 if(p1.Distance(p2) > gp::Resolution()) {
2218 TColgp_Array1OfPnt2d poles(1,2);
2219 TColStd_Array1OfReal knots(1,2);
2220 TColStd_Array1OfInteger mults(1,2);
2225 mults(1) = mults(2) = 2;
2227 C2d = new Geom2d_BSplineCurve(poles,knots,mults,1);
2229 // compute reached tolerance.begin
2230 gp_Pnt PMid = C->Value((f + l) * 0.5);
2231 aProjector1.Perform(PMid);
2233 if(aProjector1.IsDone()) {
2234 aProjector1.LowerDistanceParameters(U, V);
2235 gp_Pnt2d pmidproj(U, V);
2236 gp_Pnt2d pmidcurve2d = C2d->Value((f + l) * 0.5);
2237 Standard_Real adist = pmidcurve2d.Distance(pmidproj);
2238 Tol = (adist > Tol) ? adist : Tol;
2240 // compute reached tolerance.end
2246 S->Bounds(umin, umax, vmin, vmax);
2248 if (S->IsUPeriodic() && !C2d.IsNull()) {
2249 // Recadre dans le domaine UV de la face
2250 Standard_Real period, U0, du, aEps;
2253 aEps=Precision::PConfusion();
2254 period = S->UPeriod();
2255 gp_Pnt2d Pf = C2d->Value(f);
2258 gp_Pnt2d Pl = C2d->Value(l);
2260 U0 = Min(Pl.X(), U0);
2261 // while(U0-umin<aEps) {
2262 while(U0-umin<-aEps) {
2267 while(U0-umax>aEps) {
2278 BOPTColStd_Dump::PrintMessage("BuildPCurves()=> Echec ProjLib\n");
2282 //=======================================================================
2283 //function : Parameters
2285 //=======================================================================
2286 void Parameters(const Handle(GeomAdaptor_HSurface)& HS1,
2287 const Handle(GeomAdaptor_HSurface)& HS2,
2288 const gp_Pnt& Ptref,
2295 IntSurf_Quadric quad1,quad2;
2296 GeomAbs_SurfaceType typs = HS1->Surface().GetType();
2300 quad1.SetValue(HS1->Surface().Plane());
2302 case GeomAbs_Cylinder:
2303 quad1.SetValue(HS1->Surface().Cylinder());
2306 quad1.SetValue(HS1->Surface().Cone());
2308 case GeomAbs_Sphere:
2309 quad1.SetValue(HS1->Surface().Sphere());
2312 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2315 typs = HS2->Surface().GetType();
2318 quad2.SetValue(HS2->Surface().Plane());
2320 case GeomAbs_Cylinder:
2321 quad2.SetValue(HS2->Surface().Cylinder());
2324 quad2.SetValue(HS2->Surface().Cone());
2326 case GeomAbs_Sphere:
2327 quad2.SetValue(HS2->Surface().Sphere());
2330 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2333 quad1.Parameters(Ptref,U1,V1);
2334 quad2.Parameters(Ptref,U2,V2);
2337 //=======================================================================
2338 //function : MakeBSpline
2340 //=======================================================================
2341 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL,
2342 const Standard_Integer ideb,
2343 const Standard_Integer ifin)
2345 Standard_Integer i,nbpnt = ifin-ideb+1;
2346 TColgp_Array1OfPnt poles(1,nbpnt);
2347 TColStd_Array1OfReal knots(1,nbpnt);
2348 TColStd_Array1OfInteger mults(1,nbpnt);
2349 Standard_Integer ipidebm1;
2350 for(i=1,ipidebm1=i+ideb-1; i<=nbpnt;ipidebm1++, i++) {
2351 poles(i) = WL->Point(ipidebm1).Value();
2355 mults(1) = mults(nbpnt) = 2;
2357 new Geom_BSplineCurve(poles,knots,mults,1);
2361 //=======================================================================
2362 //function : MakeBSpline2d
2364 //=======================================================================
2365 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
2366 const Standard_Integer ideb,
2367 const Standard_Integer ifin,
2368 const Standard_Boolean onFirst)
2370 Standard_Integer i, nbpnt = ifin-ideb+1;
2371 TColgp_Array1OfPnt2d poles(1,nbpnt);
2372 TColStd_Array1OfReal knots(1,nbpnt);
2373 TColStd_Array1OfInteger mults(1,nbpnt);
2374 Standard_Integer ipidebm1;
2376 for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) {
2379 theWLine->Point(ipidebm1).ParametersOnS1(U, V);
2381 theWLine->Point(ipidebm1).ParametersOnS2(U, V);
2382 poles(i).SetCoord(U, V);
2386 mults(1) = mults(nbpnt) = 2;
2388 return new Geom2d_BSplineCurve(poles,knots,mults,1);
2390 //=======================================================================
2391 //function : PrepareLines3D
2393 //=======================================================================
2394 void IntTools_FaceFace::PrepareLines3D(const Standard_Boolean bToSplit)
2396 Standard_Integer i, aNbCurves;
2397 GeomAbs_SurfaceType aType1, aType2;
2398 IntTools_SequenceOfCurves aNewCvs;
2400 // 1. Treatment closed curves
2401 aNbCurves=mySeqOfCurve.Length();
2402 for (i=1; i<=aNbCurves; ++i) {
2403 const IntTools_Curve& aIC=mySeqOfCurve(i);
2406 Standard_Integer j, aNbC;
2407 IntTools_SequenceOfCurves aSeqCvs;
2409 aNbC=IntTools_Tools::SplitCurve(aIC, aSeqCvs);
2411 for (j=1; j<=aNbC; ++j) {
2412 const IntTools_Curve& aICNew=aSeqCvs(j);
2413 aNewCvs.Append(aICNew);
2417 aNewCvs.Append(aIC);
2421 aNewCvs.Append(aIC);
2425 // 2. Plane\Cone intersection when we had 4 curves
2426 aType1=myHS1->GetType();
2427 aType2=myHS2->GetType();
2428 aNbCurves=aNewCvs.Length();
2430 if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone) ||
2431 (aType2==GeomAbs_Plane && aType1==GeomAbs_Cone)) {
2433 GeomAbs_CurveType aCType1;
2435 aCType1=aNewCvs(1).Type();
2436 if (aCType1==GeomAbs_Line) {
2437 IntTools_SequenceOfCurves aSeqIn, aSeqOut;
2439 for (i=1; i<=aNbCurves; ++i) {
2440 const IntTools_Curve& aIC=aNewCvs(i);
2444 IntTools_Tools::RejectLines(aSeqIn, aSeqOut);
2447 aNbCurves=aSeqOut.Length();
2448 for (i=1; i<=aNbCurves; ++i) {
2449 const IntTools_Curve& aIC=aSeqOut(i);
2450 aNewCvs.Append(aIC);
2454 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone)...
2456 // 3. Fill mySeqOfCurve
2457 mySeqOfCurve.Clear();
2458 aNbCurves=aNewCvs.Length();
2459 for (i=1; i<=aNbCurves; ++i) {
2460 const IntTools_Curve& aIC=aNewCvs(i);
2461 mySeqOfCurve.Append(aIC);
2464 //=======================================================================
2465 //function : CorrectSurfaceBoundaries
2467 //=======================================================================
2468 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
2469 const Standard_Real theTolerance,
2470 Standard_Real& theumin,
2471 Standard_Real& theumax,
2472 Standard_Real& thevmin,
2473 Standard_Real& thevmax)
2475 Standard_Boolean enlarge, isuperiodic, isvperiodic;
2476 Standard_Real uinf, usup, vinf, vsup, delta;
2477 GeomAbs_SurfaceType aType;
2478 Handle(Geom_Surface) aSurface;
2480 aSurface = BRep_Tool::Surface(theFace);
2481 aSurface->Bounds(uinf, usup, vinf, vsup);
2482 delta = theTolerance;
2483 enlarge = Standard_False;
2485 GeomAdaptor_Surface anAdaptorSurface(aSurface);
2487 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
2488 Handle(Geom_Surface) aBasisSurface =
2489 (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface))->BasisSurface();
2491 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2492 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2497 if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2498 Handle(Geom_Surface) aBasisSurface =
2499 (Handle(Geom_OffsetSurface)::DownCast(aSurface))->BasisSurface();
2501 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2502 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2507 isuperiodic = anAdaptorSurface.IsUPeriodic();
2508 isvperiodic = anAdaptorSurface.IsVPeriodic();
2510 aType=anAdaptorSurface.GetType();
2511 if((aType==GeomAbs_BezierSurface) ||
2512 (aType==GeomAbs_BSplineSurface) ||
2513 (aType==GeomAbs_SurfaceOfExtrusion) ||
2514 (aType==GeomAbs_SurfaceOfRevolution)) {
2515 enlarge=Standard_True;
2518 if (aType==GeomAbs_Sphere) {
2522 if (dV+delta<M_PI) {
2523 enlarge=Standard_True;
2527 if(!isuperiodic && enlarge) {
2529 if((theumin - uinf) > delta )
2535 if((usup - theumax) > delta )
2541 if(!isvperiodic && enlarge) {
2542 if((thevmin - vinf) > delta ) {
2548 if((vsup - thevmax) > delta ) {
2557 Standard_Integer aNbP;
2558 Standard_Real aXP, dXfact, aXmid, aX1, aX2, aTolPA;
2560 aTolPA=Precision::Angular();
2563 aXP=anAdaptorSurface.UPeriod();
2564 dXfact=theumax-theumin;
2565 if (dXfact-aTolPA>aXP) {
2566 aXmid=0.5*(theumax+theumin);
2567 aNbP=RealToInt(aXmid/aXP);
2572 if (theumin>aTolPA) {
2573 aX1=theumin+aNbP*aXP;
2586 aXP=anAdaptorSurface.VPeriod();
2587 dXfact=thevmax-thevmin;
2588 if (dXfact-aTolPA>aXP) {
2589 aXmid=0.5*(thevmax+thevmin);
2590 aNbP=RealToInt(aXmid/aXP);
2595 if (thevmin>aTolPA) {
2596 aX1=thevmin+aNbP*aXP;
2609 if(isuperiodic || isvperiodic) {
2610 Standard_Boolean correct = Standard_False;
2611 Standard_Boolean correctU = Standard_False;
2612 Standard_Boolean correctV = Standard_False;
2614 TopExp_Explorer anExp;
2616 for(anExp.Init(theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
2617 if(BRep_Tool::IsClosed(TopoDS::Edge(anExp.Current()), theFace)) {
2618 correct = Standard_True;
2620 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
2622 for(Standard_Integer i = 0; i < 2; i++) {
2624 anEdge.Orientation(TopAbs_FORWARD);
2627 anEdge.Orientation(TopAbs_REVERSED);
2629 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l);
2631 if(aCurve.IsNull()) {
2632 correct = Standard_False;
2635 Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve);
2637 if(aLine.IsNull()) {
2638 correct = Standard_False;
2641 gp_Dir2d anUDir(1., 0.);
2642 gp_Dir2d aVDir(0., 1.);
2643 Standard_Real anAngularTolerance = Precision::Angular();
2645 correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance);
2646 correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance);
2648 gp_Pnt2d pp1 = aCurve->Value(f);
2650 gp_Pnt2d pp2 = aCurve->Value(l);
2659 Standard_Real umin, vmin, umax, vmax;
2660 aBox.Get(umin, vmin, umax, vmax);
2662 if(isuperiodic && correctU) {
2667 if(theumax > umax) {
2671 if(isvperiodic && correctV) {
2683 // The block is dedicated to determine whether WLine [ifprm, ilprm]
2684 // crosses the degenerated zone on each given surface or not.
2685 // If Yes -> We will not use info about surfaces during approximation
2686 // because inside degenerated zone of the surface the approx. algo.
2687 // uses wrong values of normal, etc., and resulting curve will have
2688 // oscillations that we would not like to have.
2693 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2694 const Handle(Geom_Surface)& aS,
2695 const Standard_Integer iDir);
2697 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2698 const TopoDS_Face& aF1,
2699 const TopoDS_Face& aF2);
2700 //=======================================================================
2701 //function : NotUseSurfacesForApprox
2703 //=======================================================================
2704 Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1,
2705 const TopoDS_Face& aF2,
2706 const Handle(IntPatch_WLine)& WL,
2707 const Standard_Integer ifprm,
2708 const Standard_Integer ilprm)
2710 Standard_Boolean bPInDZ;
2712 Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve();
2714 const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm);
2715 bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2);
2720 const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm);
2721 bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2);
2725 //=======================================================================
2726 //function : IsPointInDegeneratedZone
2728 //=======================================================================
2729 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2730 const TopoDS_Face& aF1,
2731 const TopoDS_Face& aF2)
2734 Standard_Boolean bFlag=Standard_True;
2735 Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22;
2736 Standard_Real U1, V1, U2, V2, aDelta, aD;
2739 Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1);
2740 aS1->Bounds(US11, US12, VS11, VS12);
2741 GeomAdaptor_Surface aGAS1(aS1);
2743 Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2);
2744 aS1->Bounds(US21, US22, VS21, VS22);
2745 GeomAdaptor_Surface aGAS2(aS2);
2747 //const gp_Pnt& aP=aP2S.Value();
2748 aP2S.Parameters(U1, V1, U2, V2);
2752 aD=aGAS1.UResolution(aDelta);
2753 aP2d.SetCoord(U1, V1);
2754 if (fabs(U1-US11) < aD) {
2755 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2760 if (fabs(U1-US12) < aD) {
2761 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2766 aD=aGAS1.VResolution(aDelta);
2767 if (fabs(V1-VS11) < aDelta) {
2768 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2773 if (fabs(V1-VS12) < aDelta) {
2774 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2780 aD=aGAS2.UResolution(aDelta);
2781 aP2d.SetCoord(U2, V2);
2782 if (fabs(U2-US21) < aDelta) {
2783 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2788 if (fabs(U2-US22) < aDelta) {
2789 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2794 aD=aGAS2.VResolution(aDelta);
2795 if (fabs(V2-VS21) < aDelta) {
2796 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2801 if (fabs(V2-VS22) < aDelta) {
2802 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2810 //=======================================================================
2811 //function : IsDegeneratedZone
2813 //=======================================================================
2814 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2815 const Handle(Geom_Surface)& aS,
2816 const Standard_Integer iDir)
2818 Standard_Boolean bFlag=Standard_True;
2819 Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD;
2820 Standard_Real aXm, aYm, aXb, aYb, aXe, aYe;
2821 aS->Bounds(US1, US2, VS1, VS2);
2823 gp_Pnt aPm, aPb, aPe;
2828 aS->D0(aXm, aYm, aPm);
2845 aS->D0(aXb, aYb, aPb);
2846 aS->D0(aXe, aYe, aPe);
2848 d1=aPm.Distance(aPb);
2849 d2=aPm.Distance(aPe);
2850 if (d1 < dD && d2 < dD) {
2867 aS->D0(aXb, aYb, aPb);
2868 aS->D0(aXe, aYe, aPe);
2870 d1=aPm.Distance(aPb);
2871 d2=aPm.Distance(aPe);
2872 if (d1 < dD && d2 < dD) {
2880 //=========================================================================
2881 // static function : ComputePurgedWLine
2882 // purpose : Removes equal points (leave one of equal points) from theWLine
2883 // and recompute vertex parameters.
2884 // Returns new WLine or null WLine if the number
2885 // of the points is less than 2.
2886 //=========================================================================
2887 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine) {
2889 Standard_Integer i, k, v, nb, nbvtx;
2890 Handle(IntPatch_WLine) aResult;
2891 nbvtx = theWLine->NbVertex();
2892 nb = theWLine->NbPnts();
2894 const IntSurf_PntOn2S& p1 = theWLine->Point(1);
2895 const IntSurf_PntOn2S& p2 = theWLine->Point(2);
2896 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
2901 Handle(IntPatch_WLine) aLocalWLine;
2902 Handle(IntPatch_WLine) aTmpWLine = theWLine;
2903 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
2904 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2905 for(i = 1; i <= nb; i++) {
2906 aLineOn2S->Add(theWLine->Point(i));
2909 for(v = 1; v <= nbvtx; v++) {
2910 aLocalWLine->AddVertex(theWLine->Vertex(v));
2913 for(i = 1; i <= aLineOn2S->NbPoints(); i++) {
2914 Standard_Integer aStartIndex = i + 1;
2915 Standard_Integer anEndIndex = i + 5;
2916 nb = aLineOn2S->NbPoints();
2917 anEndIndex = (anEndIndex > nb) ? nb : anEndIndex;
2919 if((aStartIndex > nb) || (anEndIndex <= 1)) {
2924 while(k <= anEndIndex) {
2927 IntSurf_PntOn2S p1 = aLineOn2S->Value(i);
2928 IntSurf_PntOn2S p2 = aLineOn2S->Value(k);
2930 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
2931 aTmpWLine = aLocalWLine;
2932 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2934 for(v = 1; v <= aTmpWLine->NbVertex(); v++) {
2935 IntPatch_Point aVertex = aTmpWLine->Vertex(v);
2936 Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine();
2938 if(avertexindex >= k) {
2939 aVertex.SetParameter(aVertex.ParameterOnLine() - 1.);
2941 aLocalWLine->AddVertex(aVertex);
2943 aLineOn2S->RemovePoint(k);
2952 if(aLineOn2S->NbPoints() > 1) {
2953 aResult = aLocalWLine;
2958 //=======================================================================
2961 //=======================================================================
2962 void TolR3d(const TopoDS_Face& aF1,
2963 const TopoDS_Face& aF2,
2964 Standard_Real& myTolReached3d)
2966 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
2968 aTolTresh=2.999999e-3;
2969 aTolF1 = BRep_Tool::Tolerance(aF1);
2970 aTolF2 = BRep_Tool::Tolerance(aF2);
2971 aTolFMax=Max(aTolF1, aTolF2);
2973 if (aTolFMax>aTolTresh) {
2974 myTolReached3d=aTolFMax;
2977 //=======================================================================
2978 //function : AdjustPeriodic
2980 //=======================================================================
2981 Standard_Real AdjustPeriodic(const Standard_Real theParameter,
2982 const Standard_Real parmin,
2983 const Standard_Real parmax,
2984 const Standard_Real thePeriod,
2985 Standard_Real& theOffset)
2987 Standard_Real aresult;
2990 aresult = theParameter;
2991 while(aresult < parmin) {
2992 aresult += thePeriod;
2993 theOffset += thePeriod;
2996 while(aresult > parmax) {
2997 aresult -= thePeriod;
2998 theOffset -= thePeriod;
3002 //=======================================================================
3003 //function : IsPointOnBoundary
3005 //=======================================================================
3006 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
3007 const Standard_Real theFirstBoundary,
3008 const Standard_Real theSecondBoundary,
3009 const Standard_Real theResolution,
3010 Standard_Boolean& IsOnFirstBoundary)
3012 Standard_Boolean bRet;
3014 Standard_Real adist;
3016 bRet=Standard_False;
3017 for(i = 0; i < 2; ++i) {
3018 IsOnFirstBoundary = (i == 0);
3019 if (IsOnFirstBoundary) {
3020 adist = fabs(theParameter - theFirstBoundary);
3023 adist = fabs(theParameter - theSecondBoundary);
3025 if(adist < theResolution) {
3031 // ------------------------------------------------------------------------------------------------
3032 // static function: FindPoint
3034 // ------------------------------------------------------------------------------------------------
3035 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3036 const gp_Pnt2d& theLastPoint,
3037 const Standard_Real theUmin,
3038 const Standard_Real theUmax,
3039 const Standard_Real theVmin,
3040 const Standard_Real theVmax,
3041 gp_Pnt2d& theNewPoint) {
3043 gp_Vec2d aVec(theFirstPoint, theLastPoint);
3044 Standard_Integer i = 0, j = 0;
3046 for(i = 0; i < 4; i++) {
3047 gp_Vec2d anOtherVec;
3048 gp_Vec2d anOtherVecNormal;
3049 gp_Pnt2d aprojpoint = theLastPoint;
3052 anOtherVec.SetX(0.);
3053 anOtherVec.SetY(1.);
3054 anOtherVecNormal.SetX(1.);
3055 anOtherVecNormal.SetY(0.);
3058 aprojpoint.SetX(theUmin);
3060 aprojpoint.SetX(theUmax);
3063 anOtherVec.SetX(1.);
3064 anOtherVec.SetY(0.);
3065 anOtherVecNormal.SetX(0.);
3066 anOtherVecNormal.SetY(1.);
3069 aprojpoint.SetY(theVmin);
3071 aprojpoint.SetY(theVmax);
3073 gp_Vec2d anormvec = aVec;
3074 anormvec.Normalize();
3075 RefineVector(anormvec);
3076 Standard_Real adot1 = anormvec.Dot(anOtherVecNormal);
3078 if(fabs(adot1) < Precision::Angular())
3080 Standard_Real adist = 0.;
3081 Standard_Boolean bIsOut = Standard_False;
3084 adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax);
3085 bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax);
3088 adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax);
3089 bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax);
3091 Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1;
3093 for(j = 0; j < 2; j++) {
3094 anoffset = (j == 0) ? anoffset : -anoffset;
3095 gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset));
3096 gp_Vec2d acurvec(theLastPoint, acurpoint);
3100 Standard_Real aDotX, anAngleX;
3102 aDotX = aVec.Dot(acurvec);
3103 anAngleX = aVec.Angle(acurvec);
3105 if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) {
3107 if((acurpoint.Y() >= theVmin) &&
3108 (acurpoint.Y() <= theVmax)) {
3109 theNewPoint = acurpoint;
3110 return Standard_True;
3114 if((acurpoint.X() >= theUmin) &&
3115 (acurpoint.X() <= theUmax)) {
3116 theNewPoint = acurpoint;
3117 return Standard_True;
3123 return Standard_False;
3127 // ------------------------------------------------------------------------------------------------
3128 // static function: FindPoint
3129 // purpose: Find point on the boundary of radial tangent zone
3130 // ------------------------------------------------------------------------------------------------
3131 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3132 const gp_Pnt2d& theLastPoint,
3133 const Standard_Real theUmin,
3134 const Standard_Real theUmax,
3135 const Standard_Real theVmin,
3136 const Standard_Real theVmax,
3137 const gp_Pnt2d& theTanZoneCenter,
3138 const Standard_Real theZoneRadius,
3139 Handle(GeomAdaptor_HSurface) theGASurface,
3140 gp_Pnt2d& theNewPoint) {
3141 theNewPoint = theLastPoint;
3143 if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) )
3144 return Standard_False;
3146 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3147 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3149 Standard_Real aRadius = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3150 gp_Ax22d anAxis( theTanZoneCenter, gp_Dir2d(1, 0), gp_Dir2d(0, 1) );
3151 gp_Circ2d aCircle( anAxis, aRadius );
3154 gp_Vec2d aDir( theLastPoint.XY() - theFirstPoint.XY() );
3155 Standard_Real aLength = aDir.Magnitude();
3156 if ( aLength <= gp::Resolution() )
3157 return Standard_False;
3158 gp_Lin2d aLine( theFirstPoint, aDir );
3161 Handle(Geom2d_Line) aCLine = new Geom2d_Line( aLine );
3162 Handle(Geom2d_TrimmedCurve) aC1 = new Geom2d_TrimmedCurve( aCLine, 0, aLength );
3163 Handle(Geom2d_Circle) aC2 = new Geom2d_Circle( aCircle );
3165 Standard_Real aTol = aRadius * 0.001;
3166 aTol = ( aTol < Precision::PConfusion() ) ? Precision::PConfusion() : aTol;
3168 Geom2dAPI_InterCurveCurve anIntersector;
3169 anIntersector.Init( aC1, aC2, aTol );
3171 if ( anIntersector.NbPoints() == 0 )
3172 return Standard_False;
3174 Standard_Boolean aFound = Standard_False;
3175 Standard_Real aMinDist = aLength * aLength;
3176 Standard_Integer i = 0;
3177 for ( i = 1; i <= anIntersector.NbPoints(); i++ ) {
3178 gp_Pnt2d aPInt = anIntersector.Point( i );
3179 if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) {
3180 if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) &&
3181 ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) {
3182 theNewPoint = aPInt;
3183 aFound = Standard_True;
3191 // ------------------------------------------------------------------------------------------------
3192 // static function: IsInsideTanZone
3193 // purpose: Check if point is inside a radial tangent zone
3194 // ------------------------------------------------------------------------------------------------
3195 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
3196 const gp_Pnt2d& theTanZoneCenter,
3197 const Standard_Real theZoneRadius,
3198 Handle(GeomAdaptor_HSurface) theGASurface) {
3200 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3201 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3202 Standard_Real aRadiusSQR = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3203 aRadiusSQR *= aRadiusSQR;
3204 if ( thePoint.SquareDistance( theTanZoneCenter ) <= aRadiusSQR )
3205 return Standard_True;
3206 return Standard_False;
3209 // ------------------------------------------------------------------------------------------------
3210 // static function: CheckTangentZonesExist
3211 // purpose: Check if tangent zone exists
3212 // ------------------------------------------------------------------------------------------------
3213 Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& theSurface1,
3214 const Handle(GeomAdaptor_HSurface)& theSurface2 )
3216 if ( ( theSurface1->GetType() != GeomAbs_Torus ) ||
3217 ( theSurface2->GetType() != GeomAbs_Torus ) )
3218 return Standard_False;
3220 gp_Torus aTor1 = theSurface1->Torus();
3221 gp_Torus aTor2 = theSurface2->Torus();
3223 if ( aTor1.Location().Distance( aTor2.Location() ) > Precision::Confusion() )
3224 return Standard_False;
3226 if ( ( fabs( aTor1.MajorRadius() - aTor2.MajorRadius() ) > Precision::Confusion() ) ||
3227 ( fabs( aTor1.MinorRadius() - aTor2.MinorRadius() ) > Precision::Confusion() ) )
3228 return Standard_False;
3230 if ( ( aTor1.MajorRadius() < aTor1.MinorRadius() ) ||
3231 ( aTor2.MajorRadius() < aTor2.MinorRadius() ) )
3232 return Standard_False;
3233 return Standard_True;
3236 // ------------------------------------------------------------------------------------------------
3237 // static function: ComputeTangentZones
3239 // ------------------------------------------------------------------------------------------------
3240 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
3241 const Handle(GeomAdaptor_HSurface)& theSurface2,
3242 const TopoDS_Face& theFace1,
3243 const TopoDS_Face& theFace2,
3244 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
3245 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
3246 Handle(TColStd_HArray1OfReal)& theResultRadius,
3247 const Handle(IntTools_Context)& aContext)
3249 Standard_Integer aResult = 0;
3250 if ( !CheckTangentZonesExist( theSurface1, theSurface2 ) )
3254 TColgp_SequenceOfPnt2d aSeqResultS1, aSeqResultS2;
3255 TColStd_SequenceOfReal aSeqResultRad;
3257 gp_Torus aTor1 = theSurface1->Torus();
3258 gp_Torus aTor2 = theSurface2->Torus();
3260 gp_Ax2 anax1( aTor1.Location(), aTor1.Axis().Direction() );
3261 gp_Ax2 anax2( aTor2.Location(), aTor2.Axis().Direction() );
3262 Standard_Integer j = 0;
3264 for ( j = 0; j < 2; j++ ) {
3265 Standard_Real aCoef = ( j == 0 ) ? -1 : 1;
3266 Standard_Real aRadius1 = fabs(aTor1.MajorRadius() + aCoef * aTor1.MinorRadius());
3267 Standard_Real aRadius2 = fabs(aTor2.MajorRadius() + aCoef * aTor2.MinorRadius());
3269 gp_Circ aCircle1( anax1, aRadius1 );
3270 gp_Circ aCircle2( anax2, aRadius2 );
3272 // roughly compute radius of tangent zone for perpendicular case
3273 Standard_Real aCriteria = Precision::Confusion() * 0.5;
3275 Standard_Real aT1 = aCriteria;
3276 Standard_Real aT2 = aCriteria;
3278 // internal tangency
3279 Standard_Real aR = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3280 //aT1 = aCriteria * aCriteria + aR * aR - ( aR - aCriteria ) * ( aR - aCriteria );
3281 aT1 = 2. * aR * aCriteria;
3285 // external tangency
3286 Standard_Real aRb = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3287 Standard_Real aRm = ( aRadius1 < aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3288 Standard_Real aDelta = aRb - aCriteria;
3290 aDelta -= aRm * aRm;
3291 aDelta /= 2. * (aRb - aRm);
3292 aDelta -= 0.5 * (aRb - aRm);
3294 aT1 = 2. * aRm * (aRm - aDelta);
3297 aCriteria = ( aT1 > aT2) ? aT1 : aT2;
3298 if ( aCriteria > 0 )
3299 aCriteria = sqrt( aCriteria );
3301 if ( aCriteria > 0.5 * aTor1.MinorRadius() ) {
3302 // too big zone -> drop to minimum
3303 aCriteria = Precision::Confusion();
3306 GeomAdaptor_Curve aC1( new Geom_Circle(aCircle1) );
3307 GeomAdaptor_Curve aC2( new Geom_Circle(aCircle2) );
3308 Extrema_ExtCC anExtrema(aC1, aC2, 0, 2. * M_PI, 0, 2. * M_PI,
3309 Precision::PConfusion(), Precision::PConfusion());
3311 if ( anExtrema.IsDone() ) {
3313 Standard_Integer i = 0;
3314 for ( i = 1; i <= anExtrema.NbExt(); i++ ) {
3315 if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria )
3318 Extrema_POnCurv P1, P2;
3319 anExtrema.Points( i, P1, P2 );
3321 Standard_Boolean bFoundResult = Standard_True;
3324 Standard_Integer surfit = 0;
3325 for ( surfit = 0; surfit < 2; surfit++ ) {
3326 GeomAPI_ProjectPointOnSurf& aProjector =
3327 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3329 gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value();
3330 aProjector.Perform(aP3d);
3332 if(!aProjector.IsDone())
3333 bFoundResult = Standard_False;
3335 if(aProjector.LowerDistance() > aCriteria) {
3336 bFoundResult = Standard_False;
3339 Standard_Real foundU = 0, foundV = 0;
3340 aProjector.LowerDistanceParameters(foundU, foundV);
3342 pr1 = gp_Pnt2d( foundU, foundV );
3344 pr2 = gp_Pnt2d( foundU, foundV );
3348 if ( bFoundResult ) {
3349 aSeqResultS1.Append( pr1 );
3350 aSeqResultS2.Append( pr2 );
3351 aSeqResultRad.Append( aCriteria );
3353 // torus is u and v periodic
3354 const Standard_Real twoPI = M_PI + M_PI;
3355 Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()};
3356 Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()};
3358 // iteration on period bounds
3359 for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) {
3360 Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI;
3361 Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI;
3363 // iteration on surfaces
3364 for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) {
3365 Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp;
3366 Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp;
3367 TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2;
3368 TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2;
3370 if (fabs(arr1[0] - aBound) < Precision::PConfusion()) {
3371 aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) );
3372 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3373 aSeqResultRad.Append( aCriteria );
3375 if (fabs(arr1[1] - aBound) < Precision::PConfusion()) {
3376 aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) );
3377 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3378 aSeqResultRad.Append( aCriteria );
3386 aResult = aSeqResultRad.Length();
3388 if ( aResult > 0 ) {
3389 theResultOnS1 = new TColgp_HArray1OfPnt2d( 1, aResult );
3390 theResultOnS2 = new TColgp_HArray1OfPnt2d( 1, aResult );
3391 theResultRadius = new TColStd_HArray1OfReal( 1, aResult );
3393 for ( Standard_Integer i = 1 ; i <= aResult; i++ ) {
3394 theResultOnS1->SetValue( i, aSeqResultS1.Value(i) );
3395 theResultOnS2->SetValue( i, aSeqResultS2.Value(i) );
3396 theResultRadius->SetValue( i, aSeqResultRad.Value(i) );
3402 // ------------------------------------------------------------------------------------------------
3403 // static function: AdjustByNeighbour
3405 // ------------------------------------------------------------------------------------------------
3406 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
3407 const gp_Pnt2d& theOriginalPoint,
3408 Handle(GeomAdaptor_HSurface) theGASurface) {
3410 gp_Pnt2d ap1 = theaNeighbourPoint;
3411 gp_Pnt2d ap2 = theOriginalPoint;
3413 if ( theGASurface->IsUPeriodic() ) {
3414 Standard_Real aPeriod = theGASurface->UPeriod();
3415 gp_Pnt2d aPTest = ap2;
3416 Standard_Real aSqDistMin = 1.e+100;
3418 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3419 aPTest.SetX( theOriginalPoint.X() + aPeriod * pIt );
3420 Standard_Real dd = ap1.SquareDistance( aPTest );
3422 if ( dd < aSqDistMin ) {
3428 if ( theGASurface->IsVPeriodic() ) {
3429 Standard_Real aPeriod = theGASurface->VPeriod();
3430 gp_Pnt2d aPTest = ap2;
3431 Standard_Real aSqDistMin = 1.e+100;
3433 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3434 aPTest.SetY( theOriginalPoint.Y() + aPeriod * pIt );
3435 Standard_Real dd = ap1.SquareDistance( aPTest );
3437 if ( dd < aSqDistMin ) {
3446 // ------------------------------------------------------------------------------------------------
3447 //function: DecompositionOfWLine
3449 // ------------------------------------------------------------------------------------------------
3450 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
3451 const Handle(GeomAdaptor_HSurface)& theSurface1,
3452 const Handle(GeomAdaptor_HSurface)& theSurface2,
3453 const TopoDS_Face& theFace1,
3454 const TopoDS_Face& theFace2,
3455 const IntTools_LineConstructor& theLConstructor,
3456 const Standard_Boolean theAvoidLConstructor,
3457 IntPatch_SequenceOfLine& theNewLines,
3458 Standard_Real& theReachedTol3d,
3459 const Handle(IntTools_Context)& aContext)
3462 Standard_Boolean bRet, bAvoidLineConstructor;
3463 Standard_Integer aNbPnts, aNbParts;
3465 bRet=Standard_False;
3466 aNbPnts=theWLine->NbPnts();
3467 bAvoidLineConstructor=theAvoidLConstructor;
3472 if (!bAvoidLineConstructor) {
3473 aNbParts=theLConstructor.NbParts();
3479 Standard_Boolean bIsPrevPointOnBoundary, bIsPointOnBoundary, bIsCurrentPointOnBoundary;
3480 Standard_Integer nblines, pit, i, j;
3482 TColStd_Array1OfListOfInteger anArrayOfLines(1, aNbPnts);
3483 TColStd_Array1OfInteger anArrayOfLineType(1, aNbPnts);
3484 TColStd_ListOfInteger aListOfPointIndex;
3486 Handle(TColgp_HArray1OfPnt2d) aTanZoneS1;
3487 Handle(TColgp_HArray1OfPnt2d) aTanZoneS2;
3488 Handle(TColStd_HArray1OfReal) aTanZoneRadius;
3489 Standard_Integer aNbZone = ComputeTangentZones( theSurface1, theSurface2, theFace1, theFace2,
3490 aTanZoneS1, aTanZoneS2, aTanZoneRadius, aContext);
3494 aTol=Precision::Confusion();
3496 bIsPrevPointOnBoundary=Standard_False;
3497 bIsPointOnBoundary=Standard_False;
3502 for(pit = 1; pit <= aNbPnts; ++pit) {
3503 Standard_Boolean bIsOnFirstBoundary, isperiodic;
3504 Standard_Real aResolution, aPeriod, alowerboundary, aupperboundary, U, V;
3505 Standard_Real aParameter, anoffset, anAdjustPar;
3506 Standard_Real umin, umax, vmin, vmax;
3508 bIsCurrentPointOnBoundary = Standard_False;
3509 const IntSurf_PntOn2S& aPoint = theWLine->Point(pit);
3512 for(i = 0; i < 2; ++i) {
3513 Handle(GeomAdaptor_HSurface) aGASurface = (!i) ? theSurface1 : theSurface2;
3514 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3516 aPoint.ParametersOnS1(U, V);
3519 aPoint.ParametersOnS2(U, V);
3522 for(j = 0; j < 2; j++) {
3523 isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3529 aResolution=aGASurface->UResolution(aTol);
3530 aPeriod=aGASurface->UPeriod();
3531 alowerboundary=umin;
3532 aupperboundary=umax;
3536 aResolution=aGASurface->VResolution(aTol);
3537 aPeriod=aGASurface->VPeriod();
3538 alowerboundary=vmin;
3539 aupperboundary=vmax;
3544 anAdjustPar = AdjustPeriodic(aParameter,
3550 bIsOnFirstBoundary = Standard_True;// ?
3552 IsPointOnBoundary(anAdjustPar,
3556 bIsOnFirstBoundary);
3558 if(bIsPointOnBoundary) {
3559 bIsCurrentPointOnBoundary = Standard_True;
3563 // check if a point belong to a tangent zone. Begin
3564 Standard_Integer zIt = 0;
3565 for ( zIt = 1; zIt <= aNbZone; zIt++ ) {
3566 gp_Pnt2d aPZone = (i == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3567 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3569 if ( IsInsideTanZone(gp_Pnt2d( U, V ), aPZone, aZoneRadius, aGASurface ) ) {
3570 // set boundary flag to split the curve by a tangent zone
3571 bIsPointOnBoundary = Standard_True;
3572 bIsCurrentPointOnBoundary = Standard_True;
3573 if ( theReachedTol3d < aZoneRadius ) {
3574 theReachedTol3d = aZoneRadius;
3580 }//for(j = 0; j < 2; j++) {
3582 if(bIsCurrentPointOnBoundary){
3585 }//for(i = 0; i < 2; ++i) {
3587 if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) {
3588 if(!aListOfPointIndex.IsEmpty()) {
3590 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3591 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3592 aListOfPointIndex.Clear();
3594 bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary;
3596 aListOfPointIndex.Append(pit);
3597 } //for(pit = 1; pit <= aNbPnts; ++pit) {
3599 if(!aListOfPointIndex.IsEmpty()) {
3601 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3602 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3603 aListOfPointIndex.Clear();
3607 return bRet; //Standard_False;
3611 // 2. Correct wlines.begin
3612 TColStd_Array1OfListOfInteger anArrayOfLineEnds(1, nblines);
3613 Handle(IntSurf_LineOn2S) aSeqOfPntOn2S = new IntSurf_LineOn2S();
3615 for(i = 1; i <= nblines; i++) {
3616 if(anArrayOfLineType.Value(i) != 0) {
3619 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3620 if(aListOfIndex.Extent() < 2) {
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;
3639 for(Standard_Integer surfit = 0; surfit < 2; surfit++) {
3641 Handle(GeomAdaptor_HSurface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2;
3642 Standard_Real umin=0., umax=0., vmin=0., vmax=0.;
3643 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3644 Standard_Real U=0., V=0.;
3647 aNewP.ParametersOnS1(U, V);
3649 aNewP.ParametersOnS2(U, V);
3650 Standard_Integer nbboundaries = 0;
3652 Standard_Boolean bIsNearBoundary = Standard_False;
3653 Standard_Integer aZoneIndex = 0;
3654 Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1
3655 Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1
3658 for(Standard_Integer parit = 0; parit < 2; parit++) {
3659 Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3661 Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
3662 Standard_Real alowerboundary = (parit == 0) ? umin : vmin;
3663 Standard_Real aupperboundary = (parit == 0) ? umax : vmax;
3665 Standard_Real aParameter = (parit == 0) ? U : V;
3666 Standard_Boolean bIsOnFirstBoundary = Standard_True;
3670 IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3671 if(bIsPointOnBoundary) {
3672 bIsUBoundary = (parit == 0);
3673 bIsFirstBoundary = bIsOnFirstBoundary;
3678 Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3679 Standard_Real anoffset = 0.;
3680 Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
3683 IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3684 if(bIsPointOnBoundary) {
3685 bIsUBoundary = (parit == 0);
3686 bIsFirstBoundary = bIsOnFirstBoundary;
3690 //check neighbourhood of boundary
3691 Standard_Real anEpsilon = aResolution * 100.;
3692 Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
3693 anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
3695 bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary,
3696 anEpsilon, bIsOnFirstBoundary);
3702 // check if a point belong to a tangent zone. Begin
3703 for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) {
3704 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3705 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3707 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3708 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3709 Standard_Real nU1, nV1;
3712 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3714 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3715 gp_Pnt2d ap1(nU1, nV1);
3716 gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface );
3719 if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) {
3721 bIsNearBoundary = Standard_True;
3722 if ( theReachedTol3d < aZoneRadius ) {
3723 theReachedTol3d = aZoneRadius;
3727 // check if a point belong to a tangent zone. End
3728 Standard_Boolean bComputeLineEnd = Standard_False;
3730 if(nbboundaries == 2) {
3732 bComputeLineEnd = Standard_True;
3735 else if(nbboundaries == 1) {
3736 Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3739 Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
3740 Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
3741 Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3742 Standard_Real aParameter = (bIsUBoundary) ? U : V;
3743 Standard_Real anoffset = 0.;
3744 Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
3746 Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
3747 Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
3748 anotherPar += anoffset;
3749 Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3750 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
3751 Standard_Real nU1, nV1;
3754 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3756 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3758 Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
3759 Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
3760 bComputeLineEnd = Standard_True;
3761 Standard_Boolean bCheckAngle1 = Standard_False;
3762 Standard_Boolean bCheckAngle2 = Standard_False;
3764 Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
3765 Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
3767 if(((adist1 - adist2) > Precision::PConfusion()) &&
3768 (adist2 < (aPeriod / 4.))) {
3769 bCheckAngle1 = Standard_True;
3770 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
3772 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3773 aNewP.SetValue((surfit == 0), anewU, anewV);
3774 bCheckAngle1 = Standard_False;
3777 else if(adist1 < (aPeriod / 4.)) {
3778 bCheckAngle2 = Standard_True;
3779 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
3781 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3782 bCheckAngle2 = Standard_False;
3786 if(bCheckAngle1 || bCheckAngle2) {
3787 // assume there are at least two points in line (see "if" above)
3788 Standard_Integer anindexother = aneighbourpointindex;
3790 while((anindexother <= aListOfIndex.Last()) && (anindexother >= aListOfIndex.First())) {
3791 anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
3792 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
3793 Standard_Real nU2, nV2;
3796 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3798 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3799 gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
3801 if(aVecOld.SquareMagnitude() <= (gp::Resolution() * gp::Resolution())) {
3805 Standard_Real anAngle = aNewVec.Angle(aVecOld);
3807 if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
3810 Standard_Real U1, U2, V1, V2;
3811 IntSurf_PntOn2S atmppoint = aNewP;
3812 atmppoint.SetValue((surfit == 0), anewU, anewV);
3813 atmppoint.Parameters(U1, V1, U2, V2);
3814 gp_Pnt P1 = theSurface1->Value(U1, V1);
3815 gp_Pnt P2 = theSurface2->Value(U2, V2);
3816 gp_Pnt P0 = aPoint.Value();
3818 if(P0.IsEqual(P1, aTol) &&
3819 P0.IsEqual(P2, aTol) &&
3820 P1.IsEqual(P2, aTol)) {
3821 bComputeLineEnd = Standard_False;
3822 aNewP.SetValue((surfit == 0), anewU, anewV);
3827 bComputeLineEnd = Standard_False;
3832 } // end while(anindexother...)
3836 else if ( bIsNearBoundary ) {
3837 bComputeLineEnd = Standard_True;
3840 if(bComputeLineEnd) {
3843 Standard_Boolean found = Standard_False;
3845 if ( bIsNearBoundary ) {
3846 // re-compute point near natural boundary or near tangent zone
3847 Standard_Real u1, v1, u2, v2;
3848 aNewP.Parameters( u1, v1, u2, v2 );
3850 anewpoint = gp_Pnt2d( u1, v1 );
3852 anewpoint = gp_Pnt2d( u2, v2 );
3854 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3855 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3856 Standard_Real nU1, nV1;
3859 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3861 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3862 gp_Pnt2d ap1(nU1, nV1);
3867 // exclude point from a tangent zone
3868 anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3869 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex);
3870 Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex);
3872 if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax,
3873 aPZone, aZoneRadius, aGASurface, ap2) ) {
3875 found = Standard_True;
3878 else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
3879 // re-compute point near boundary if shifted on a period
3880 ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3882 if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
3883 ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
3884 found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
3888 aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
3894 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3895 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3896 Standard_Real nU1, nV1;
3899 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3901 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3902 gp_Pnt2d ap1(nU1, nV1);
3903 gp_Pnt2d ap2(nU1, nV1);
3904 Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
3906 while((aneighbourpointindex2 <= aListOfIndex.Last()) && (aneighbourpointindex2 >= aListOfIndex.First())) {
3907 aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
3908 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
3909 Standard_Real nU2, nV2;
3912 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3914 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3918 if(ap1.SquareDistance(ap2) > (gp::Resolution() * gp::Resolution())) {
3922 found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
3927 Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
3928 GeomAPI_ProjectPointOnSurf& aProjector =
3929 (surfit == 0) ? aContext->ProjPS(theFace2) : aContext->ProjPS(theFace1);
3930 Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
3932 Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
3934 gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
3935 aProjector.Perform(aP3d);
3937 if(aProjector.IsDone()) {
3938 if(aProjector.LowerDistance() < aCriteria) {
3939 Standard_Real foundU = U, foundV = V;
3940 aProjector.LowerDistanceParameters(foundU, foundV);
3942 //Correction of projected coordinates. Begin
3943 //Note, it may be shifted on a period
3944 Standard_Integer aneindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3945 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
3946 Standard_Real nUn, nVn;
3949 aNeighbourPoint.ParametersOnS2(nUn, nVn);
3951 aNeighbourPoint.ParametersOnS1(nUn, nVn);
3952 gp_Pnt2d aNeighbour2d(nUn, nVn);
3953 gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
3954 foundU = anAdjustedPoint.X();
3955 foundV = anAdjustedPoint.Y();
3957 if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
3958 ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
3959 // attempt to roughly re-compute point
3960 foundU = ( foundU < umin ) ? umin : foundU;
3961 foundU = ( foundU > umax ) ? umax : foundU;
3962 foundV = ( foundV < vmin ) ? vmin : foundV;
3963 foundV = ( foundV > vmax ) ? vmax : foundV;
3965 GeomAPI_ProjectPointOnSurf& aProjector2 =
3966 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3968 aP3d = aSurfaceOther->Value(foundU, foundV);
3969 aProjector2.Perform(aP3d);
3971 if(aProjector2.IsDone()) {
3972 if(aProjector2.LowerDistance() < aCriteria) {
3973 Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
3974 aProjector2.LowerDistanceParameters(foundU2, foundV2);
3975 anewpoint.SetX(foundU2);
3976 anewpoint.SetY(foundV2);
3980 //Correction of projected coordinates. End
3983 aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
3985 aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
3991 aSeqOfPntOn2S->Add(aNewP);
3992 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
3994 anArrayOfLineEnds.SetValue(i, aListOfFLIndex);
3996 // Correct wlines.end
3998 // Split wlines.begin
3999 Standard_Integer nbiter;
4002 if (!bAvoidLineConstructor) {
4003 nbiter=theLConstructor.NbParts();
4006 for(j = 1; j <= nbiter; ++j) {
4007 Standard_Real fprm, lprm;
4008 Standard_Integer ifprm, ilprm;
4010 if(bAvoidLineConstructor) {
4012 ilprm = theWLine->NbPnts();
4015 theLConstructor.Part(j, fprm, lprm);
4016 ifprm = (Standard_Integer)fprm;
4017 ilprm = (Standard_Integer)lprm;
4020 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
4022 for(i = 1; i <= nblines; i++) {
4023 if(anArrayOfLineType.Value(i) != 0) {
4026 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
4028 if(aListOfIndex.Extent() < 2) {
4031 const TColStd_ListOfInteger& aListOfFLIndex = anArrayOfLineEnds.Value(i);
4032 Standard_Boolean bhasfirstpoint = (aListOfFLIndex.Extent() == 2);
4033 Standard_Boolean bhaslastpoint = (aListOfFLIndex.Extent() == 2);
4035 if(!bhasfirstpoint && !aListOfFLIndex.IsEmpty()) {
4036 bhasfirstpoint = (i != 1);
4039 if(!bhaslastpoint && !aListOfFLIndex.IsEmpty()) {
4040 bhaslastpoint = (i != nblines);
4042 Standard_Boolean bIsFirstInside = ((ifprm >= aListOfIndex.First()) && (ifprm <= aListOfIndex.Last()));
4043 Standard_Boolean bIsLastInside = ((ilprm >= aListOfIndex.First()) && (ilprm <= aListOfIndex.Last()));
4045 if(!bIsFirstInside && !bIsLastInside) {
4046 if((ifprm < aListOfIndex.First()) && (ilprm > aListOfIndex.Last())) {
4047 // append whole line, and boundaries if neccesary
4048 if(bhasfirstpoint) {
4049 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
4052 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4054 for(; anIt.More(); anIt.Next()) {
4055 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4060 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
4064 // check end of split line (end is almost always)
4065 Standard_Integer aneighbour = i + 1;
4066 Standard_Boolean bIsEndOfLine = Standard_True;
4068 if(aneighbour <= nblines) {
4069 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4071 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4072 (aListOfNeighbourIndex.IsEmpty())) {
4073 bIsEndOfLine = Standard_False;
4078 if(aLineOn2S->NbPoints() > 1) {
4079 Handle(IntPatch_WLine) aNewWLine =
4080 new IntPatch_WLine(aLineOn2S, Standard_False);
4081 theNewLines.Append(aNewWLine);
4083 aLineOn2S = new IntSurf_LineOn2S();
4088 // end if(!bIsFirstInside && !bIsLastInside)
4090 if(bIsFirstInside && bIsLastInside) {
4091 // append inside points between ifprm and ilprm
4092 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4094 for(; anIt.More(); anIt.Next()) {
4095 if((anIt.Value() < ifprm) || (anIt.Value() > ilprm))
4097 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4103 if(bIsFirstInside) {
4104 // append points from ifprm to last point + boundary point
4105 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4107 for(; anIt.More(); anIt.Next()) {
4108 if(anIt.Value() < ifprm)
4110 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4115 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
4118 // check end of split line (end is almost always)
4119 Standard_Integer aneighbour = i + 1;
4120 Standard_Boolean bIsEndOfLine = Standard_True;
4122 if(aneighbour <= nblines) {
4123 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4125 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4126 (aListOfNeighbourIndex.IsEmpty())) {
4127 bIsEndOfLine = Standard_False;
4132 if(aLineOn2S->NbPoints() > 1) {
4133 Handle(IntPatch_WLine) aNewWLine =
4134 new IntPatch_WLine(aLineOn2S, Standard_False);
4135 theNewLines.Append(aNewWLine);
4137 aLineOn2S = new IntSurf_LineOn2S();
4140 // end if(bIsFirstInside)
4143 // append points from first boundary point to ilprm
4144 if(bhasfirstpoint) {
4145 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
4148 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4150 for(; anIt.More(); anIt.Next()) {
4151 if(anIt.Value() > ilprm)
4153 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4157 //end if(bIsLastInside)
4161 if(aLineOn2S->NbPoints() > 1) {
4162 Handle(IntPatch_WLine) aNewWLine =
4163 new IntPatch_WLine(aLineOn2S, Standard_False);
4164 theNewLines.Append(aNewWLine);
4169 return Standard_True;
4172 // ------------------------------------------------------------------------------------------------
4173 // static function: ParameterOutOfBoundary
4174 // purpose: Computes a new parameter for given curve. The corresponding 2d points
4175 // does not lay on any boundary of given faces
4176 // ------------------------------------------------------------------------------------------------
4177 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
4178 const Handle(Geom_Curve)& theCurve,
4179 const TopoDS_Face& theFace1,
4180 const TopoDS_Face& theFace2,
4181 const Standard_Real theOtherParameter,
4182 const Standard_Boolean bIncreasePar,
4183 Standard_Real& theNewParameter,
4184 const Handle(IntTools_Context)& aContext)
4186 Standard_Boolean bIsComputed = Standard_False;
4187 theNewParameter = theParameter;
4189 Standard_Real acurpar = theParameter;
4190 TopAbs_State aState = TopAbs_ON;
4191 Standard_Integer iter = 0;
4192 Standard_Real asumtol = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4193 Standard_Real adelta = asumtol * 0.1;
4194 adelta = (adelta < Precision::Confusion()) ? Precision::Confusion() : adelta;
4195 Handle(Geom_Surface) aSurf1 = BRep_Tool::Surface(theFace1);
4196 Handle(Geom_Surface) aSurf2 = BRep_Tool::Surface(theFace2);
4198 Standard_Real u1, u2, v1, v2;
4200 GeomAPI_ProjectPointOnSurf aPrj1;
4201 aSurf1->Bounds(u1, u2, v1, v2);
4202 aPrj1.Init(aSurf1, u1, u2, v1, v2);
4204 GeomAPI_ProjectPointOnSurf aPrj2;
4205 aSurf2->Bounds(u1, u2, v1, v2);
4206 aPrj2.Init(aSurf2, u1, u2, v1, v2);
4208 while(aState == TopAbs_ON) {
4213 gp_Pnt aPCurrent = theCurve->Value(acurpar);
4214 aPrj1.Perform(aPCurrent);
4215 Standard_Real U=0., V=0.;
4217 if(aPrj1.IsDone()) {
4218 aPrj1.LowerDistanceParameters(U, V);
4219 aState = aContext->StatePointFace(theFace1, gp_Pnt2d(U, V));
4222 if(aState != TopAbs_ON) {
4223 aPrj2.Perform(aPCurrent);
4225 if(aPrj2.IsDone()) {
4226 aPrj2.LowerDistanceParameters(U, V);
4227 aState = aContext->StatePointFace(theFace2, gp_Pnt2d(U, V));
4238 theNewParameter = acurpar;
4239 bIsComputed = Standard_True;
4242 if(acurpar >= theOtherParameter)
4243 theNewParameter = theOtherParameter;
4246 if(acurpar <= theOtherParameter)
4247 theNewParameter = theOtherParameter;
4253 //=======================================================================
4254 //function : IsCurveValid
4256 //=======================================================================
4257 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve)
4259 if(thePCurve.IsNull())
4260 return Standard_False;
4262 Standard_Real tolint = 1.e-10;
4263 Geom2dAdaptor_Curve PCA;
4264 IntRes2d_Domain PCD;
4265 Geom2dInt_GInter PCI;
4267 Standard_Real pf = 0., pl = 0.;
4268 gp_Pnt2d pntf, pntl;
4270 if(!thePCurve->IsClosed() && !thePCurve->IsPeriodic()) {
4271 pf = thePCurve->FirstParameter();
4272 pl = thePCurve->LastParameter();
4273 pntf = thePCurve->Value(pf);
4274 pntl = thePCurve->Value(pl);
4275 PCA.Load(thePCurve);
4276 if(!PCA.IsPeriodic()) {
4277 if(PCA.FirstParameter() > pf) pf = PCA.FirstParameter();
4278 if(PCA.LastParameter() < pl) pl = PCA.LastParameter();
4280 PCD.SetValues(pntf,pf,tolint,pntl,pl,tolint);
4281 PCI.Perform(PCA,PCD,tolint,tolint);
4283 if(PCI.NbPoints() > 0) {
4284 return Standard_False;
4288 return Standard_True;
4291 //=======================================================================
4292 //static function : ApproxWithPCurves
4293 //purpose : for bug 20964 only
4294 //=======================================================================
4295 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
4296 const gp_Sphere& theSph)
4298 Standard_Boolean bRes = Standard_True;
4299 Standard_Real R1 = theCyl.Radius(), R2 = theSph.Radius();
4301 if(R1 < 2.*R2) return bRes;
4303 gp_Lin anCylAx(theCyl.Axis());
4305 Standard_Real aDist = anCylAx.Distance(theSph.Location());
4306 Standard_Real aDRel = Abs(aDist - R1)/R2;
4308 if(aDRel > .2) return bRes;
4310 Standard_Real par = ElCLib::Parameter(anCylAx, theSph.Location());
4311 gp_Pnt aP = ElCLib::Value(par, anCylAx);
4312 gp_Vec aV(aP, theSph.Location());
4314 Standard_Real dd = aV.Dot(theSph.Position().XDirection());
4316 if(aDist < R1 && dd > 0.) return Standard_False;
4317 if(aDist > R1 && dd < 0.) return Standard_False;
4322 //=======================================================================
4323 //function : PerformPlanes
4325 //=======================================================================
4326 void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
4327 const Handle(GeomAdaptor_HSurface)& theS2,
4328 const Standard_Real TolAng,
4329 const Standard_Real TolTang,
4330 const Standard_Boolean theApprox1,
4331 const Standard_Boolean theApprox2,
4332 IntTools_SequenceOfCurves& theSeqOfCurve,
4333 Standard_Boolean& theTangentFaces)
4336 gp_Pln aPln1 = theS1->Surface().Plane();
4337 gp_Pln aPln2 = theS2->Surface().Plane();
4339 IntAna_QuadQuadGeo aPlnInter(aPln1, aPln2, TolAng, TolTang);
4341 if(!aPlnInter.IsDone()) {
4342 theTangentFaces = Standard_False;
4346 IntAna_ResultType aResType = aPlnInter.TypeInter();
4348 if(aResType == IntAna_Same) {
4349 theTangentFaces = Standard_True;
4353 theTangentFaces = Standard_False;
4355 if(aResType == IntAna_Empty) {
4359 gp_Lin aLin = aPlnInter.Line(1);
4361 ProjLib_Plane aProj;
4364 aProj.Project(aLin);
4365 gp_Lin2d aLin2d1 = aProj.Line();
4368 aProj.Project(aLin);
4369 gp_Lin2d aLin2d2 = aProj.Line();
4371 //classify line2d1 relatively first plane
4372 Standard_Real P11, P12;
4373 Standard_Boolean IsCrossed = ClassifyLin2d(theS1, aLin2d1, TolTang, P11, P12);
4374 if(!IsCrossed) return;
4375 //classify line2d2 relatively second plane
4376 Standard_Real P21, P22;
4377 IsCrossed = ClassifyLin2d(theS2, aLin2d2, TolTang, P21, P22);
4378 if(!IsCrossed) return;
4380 //Analysis of parametric intervals: must have common part
4382 if(P21 >= P12) return;
4383 if(P22 <= P11) return;
4385 Standard_Real pmin, pmax;
4386 pmin = Max(P11, P21);
4387 pmax = Min(P12, P22);
4389 if(pmax - pmin <= TolTang) return;
4391 Handle(Geom_Line) aGLin = new Geom_Line(aLin);
4393 IntTools_Curve aCurve;
4394 Handle(Geom_TrimmedCurve) aGTLin = new Geom_TrimmedCurve(aGLin, pmin, pmax);
4396 aCurve.SetCurve(aGTLin);
4399 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d1);
4400 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4403 Handle(Geom2d_Curve) H1;
4404 aCurve.SetFirstCurve2d(H1);
4407 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d2);
4408 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4411 Handle(Geom2d_Curve) H1;
4412 aCurve.SetFirstCurve2d(H1);
4415 theSeqOfCurve.Append(aCurve);
4419 //=======================================================================
4420 //function : ClassifyLin2d
4422 //=======================================================================
4423 static inline Standard_Boolean INTER(const Standard_Real d1,
4424 const Standard_Real d2,
4425 const Standard_Real tol)
4427 return (d1 > tol && d2 < -tol) ||
4428 (d1 < -tol && d2 > tol) ||
4429 ((d1 <= tol && d1 >= -tol) && (d2 > tol || d2 < -tol)) ||
4430 ((d2 <= tol && d2 >= -tol) && (d1 > tol || d1 < -tol));
4432 static inline Standard_Boolean COINC(const Standard_Real d1,
4433 const Standard_Real d2,
4434 const Standard_Real tol)
4436 return (d1 <= tol && d1 >= -tol) && (d2 <= tol && d2 >= -tol);
4438 Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
4439 const gp_Lin2d& theLin2d,
4440 const Standard_Real theTol,
4441 Standard_Real& theP1,
4442 Standard_Real& theP2)
4445 Standard_Real xmin, xmax, ymin, ymax, d1, d2, A, B, C;
4446 Standard_Real par[2];
4447 Standard_Integer nbi = 0;
4449 xmin = theS->Surface().FirstUParameter();
4450 xmax = theS->Surface().LastUParameter();
4451 ymin = theS->Surface().FirstVParameter();
4452 ymax = theS->Surface().LastVParameter();
4454 theLin2d.Coefficients(A, B, C);
4456 //xmin, ymin <-> xmin, ymax
4457 d1 = A*xmin + B*ymin + C;
4458 d2 = A*xmin + B*ymax + C;
4460 if(INTER(d1, d2, theTol)) {
4461 //Intersection with boundary
4462 Standard_Real y = -(C + A*xmin)/B;
4463 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, y));
4466 else if (COINC(d1, d2, theTol)) {
4467 //Coincidence with boundary
4468 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4469 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4475 if(fabs(par[0]-par[1]) > theTol) {
4476 theP1 = Min(par[0], par[1]);
4477 theP2 = Max(par[0], par[1]);
4478 return Standard_True;
4480 else return Standard_False;
4484 //xmin, ymax <-> xmax, ymax
4486 d2 = A*xmax + B*ymax + C;
4488 if(d1 > theTol || d1 < -theTol) {//to avoid checking of
4489 //coincidence with the same point
4490 if(INTER(d1, d2, theTol)) {
4491 Standard_Real x = -(C + B*ymax)/A;
4492 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymax));
4495 else if (COINC(d1, d2, theTol)) {
4496 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4497 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4504 if(fabs(par[0]-par[1]) > theTol) {
4505 theP1 = Min(par[0], par[1]);
4506 theP2 = Max(par[0], par[1]);
4507 return Standard_True;
4509 else return Standard_False;
4513 //xmax, ymax <-> xmax, ymin
4515 d2 = A*xmax + B*ymin + C;
4517 if(d1 > theTol || d1 < -theTol) {
4518 if(INTER(d1, d2, theTol)) {
4519 Standard_Real y = -(C + A*xmax)/B;
4520 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, y));
4523 else if (COINC(d1, d2, theTol)) {
4524 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4525 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4531 if(fabs(par[0]-par[1]) > theTol) {
4532 theP1 = Min(par[0], par[1]);
4533 theP2 = Max(par[0], par[1]);
4534 return Standard_True;
4536 else return Standard_False;
4539 //xmax, ymin <-> xmin, ymin
4541 d2 = A*xmin + B*ymin + C;
4543 if(d1 > theTol || d1 < -theTol) {
4544 if(INTER(d1, d2, theTol)) {
4545 Standard_Real x = -(C + B*ymin)/A;
4546 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymin));
4549 else if (COINC(d1, d2, theTol)) {
4550 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4551 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4557 if(fabs(par[0]-par[1]) > theTol) {
4558 theP1 = Min(par[0], par[1]);
4559 theP2 = Max(par[0], par[1]);
4560 return Standard_True;
4562 else return Standard_False;
4565 return Standard_False;
4569 //=======================================================================
4570 //function : ApproxParameters
4572 //=======================================================================
4573 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
4574 const Handle(GeomAdaptor_HSurface)& aHS2,
4575 Standard_Integer& iDegMin,
4576 Standard_Integer& iDegMax,
4577 Standard_Integer& iNbIter)
4580 GeomAbs_SurfaceType aTS1, aTS2;
4587 aTS1=aHS1->Surface().GetType();
4588 aTS2=aHS2->Surface().GetType();
4591 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4592 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4593 Standard_Real aRC, aRT, dR, aPC;
4594 gp_Cylinder aCylinder;
4597 aPC=Precision::Confusion();
4599 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4600 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4602 aRC=aCylinder.Radius();
4603 aRT=aTorus.MinorRadius();
4613 if (aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Cylinder) {
4617 //=======================================================================
4618 //function : Tolerances
4620 //=======================================================================
4621 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
4622 const Handle(GeomAdaptor_HSurface)& aHS2,
4623 Standard_Real& ,//aTolArc,
4624 Standard_Real& aTolTang,
4625 Standard_Real& ,//aUVMaxStep,
4626 Standard_Real& )//aDeflection)
4628 GeomAbs_SurfaceType aTS1, aTS2;
4630 aTS1=aHS1->Surface().GetType();
4631 aTS2=aHS2->Surface().GetType();
4634 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4635 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4636 Standard_Real aRC, aRT, dR, aPC;
4637 gp_Cylinder aCylinder;
4640 aPC=Precision::Confusion();
4642 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4643 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4645 aRC=aCylinder.Radius();
4646 aRT=aTorus.MinorRadius();
4653 aTolTang=0.1*aTolTang;
4657 //=======================================================================
4658 //function : SortTypes
4660 //=======================================================================
4661 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
4662 const GeomAbs_SurfaceType aType2)
4664 Standard_Boolean bRet;
4665 Standard_Integer aI1, aI2;
4667 bRet=Standard_False;
4669 aI1=IndexType(aType1);
4670 aI2=IndexType(aType2);
4676 //=======================================================================
4677 //function : IndexType
4679 //=======================================================================
4680 Standard_Integer IndexType(const GeomAbs_SurfaceType aType)
4682 Standard_Integer aIndex;
4686 if (aType==GeomAbs_Plane) {
4689 else if (aType==GeomAbs_Cylinder) {
4692 else if (aType==GeomAbs_Cone) {
4695 else if (aType==GeomAbs_Sphere) {
4698 else if (aType==GeomAbs_Torus) {
4701 else if (aType==GeomAbs_BezierSurface) {
4704 else if (aType==GeomAbs_BSplineSurface) {
4707 else if (aType==GeomAbs_SurfaceOfRevolution) {
4710 else if (aType==GeomAbs_SurfaceOfExtrusion) {
4713 else if (aType==GeomAbs_OffsetSurface) {
4716 else if (aType==GeomAbs_OtherSurface) {
4721 //=======================================================================
4722 //function : DumpWLine
4724 //=======================================================================
4725 void DumpWLine(const Handle(IntPatch_WLine)& aWLine)
4727 Standard_Integer i, aNbPnts;
4728 Standard_Real aX, aY, aZ, aU1, aV1, aU2, aV2;
4730 printf(" *WLine\n");
4731 aNbPnts=aWLine->NbPnts();
4732 for (i=1; i<=aNbPnts; ++i) {
4733 const IntSurf_PntOn2S aPntOn2S=aWLine->Point(i);
4734 const gp_Pnt& aP3D=aPntOn2S.Value();
4735 aP3D.Coord(aX, aY, aZ);
4736 aPntOn2S.Parameters(aU1, aV1, aU2, aV2);
4738 printf("point p_%d %lf %lf %lf\n", i, aX, aY, aZ);
4739 //printf("point p_%d %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf\n",
4740 // i, aX, aY, aZ, aU1, aV1, aU2, aV2);
4743 //=======================================================================
4744 //function : RefineVector
4746 //=======================================================================
4747 void RefineVector(gp_Vec2d& aV2D)
4749 Standard_Integer k,m;
4750 Standard_Real aC[2], aEps, aR1, aR2, aNum;
4756 aV2D.Coord(aC[0], aC[1]);
4758 for (k=0; k<2; ++k) {
4761 if (aNum>aR1 && aNum<aR2) {
4772 aV2D.SetCoord(aC[0], aC[1]);
4774 //=======================================================================
4775 //function : FindMaxSquareDistance
4777 //=======================================================================
4778 Standard_Real FindMaxSquareDistance (const Standard_Real aT1,
4779 const Standard_Real aT2,
4780 const Standard_Real aEps,
4781 const Handle(Geom_Curve)& aC3D,
4782 const Handle(Geom2d_Curve)& aC2D1,
4783 const Handle(Geom2d_Curve)& aC2D2,
4784 const Handle(GeomAdaptor_HSurface)& myHS1,
4785 const Handle(GeomAdaptor_HSurface)& myHS2,
4786 const TopoDS_Face& myFace1,
4787 const TopoDS_Face& myFace2,
4788 const Handle(IntTools_Context)& myContext)
4790 Standard_Real aA, aB, aCf, aX1, aX2, aF1, aF2, aX, aF;
4792 aCf=1.6180339887498948482045868343656;// =0.5*(1.+sqrt(5.));
4796 aF1=MaxSquareDistance(aX1,
4797 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4799 aF2=MaxSquareDistance(aX2,
4800 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4804 if (fabs(aA-aB)<aEps) {
4806 aF=MaxSquareDistance(aX,
4807 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4815 aF2=MaxSquareDistance(aX2,
4816 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4824 aF1=MaxSquareDistance(aX1,
4825 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4830 //=======================================================================
4831 //function : MaxSquareDistance
4833 //=======================================================================
4834 Standard_Real MaxSquareDistance (const Standard_Real aT,
4835 const Handle(Geom_Curve)& aC3D,
4836 const Handle(Geom2d_Curve)& aC2D1,
4837 const Handle(Geom2d_Curve)& aC2D2,
4838 const Handle(GeomAdaptor_HSurface) myHS1,
4839 const Handle(GeomAdaptor_HSurface) myHS2,
4840 const TopoDS_Face& aF1,
4841 const TopoDS_Face& aF2,
4842 const Handle(IntTools_Context)& aCtx)
4844 Standard_Boolean bIsDone;
4846 Standard_Real aU, aV, aD2Max, aD2;
4853 if (aC3D.IsNull()) {
4857 for (i=0; i<2; ++i) {
4858 const Handle(GeomAdaptor_HSurface)& aGHS=(!i) ? myHS1 : myHS2;
4859 const TopoDS_Face &aF=(!i) ? aF1 : aF2;
4860 const Handle(Geom2d_Curve)& aC2D=(!i) ? aC2D1 : aC2D2;
4862 if (!aC2D.IsNull()) {
4865 aGHS->D0(aU, aV, aPS);
4866 aD2=aP.SquareDistance(aPS);
4872 GeomAPI_ProjectPointOnSurf& aProjector=aCtx->ProjPS(aF);
4874 aProjector.Perform(aP);
4875 bIsDone=aProjector.IsDone();
4877 aProjector.LowerDistanceParameters(aU, aV);
4878 aGHS->D0(aU, aV, aPS);
4879 aD2=aP.SquareDistance(aPS);
4889 //=======================================================================
4890 //function : CheckPCurve
4891 //purpose : Checks if points of the pcurve are out of the face bounds.
4892 //=======================================================================
4893 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
4894 const TopoDS_Face& aFace)
4896 const Standard_Integer NPoints = 23;
4897 Standard_Real umin,umax,vmin,vmax;
4899 BRepTools::UVBounds(aFace, umin, umax, vmin, vmax);
4900 Standard_Real tolU = Max ((umax-umin)*0.01, Precision::Confusion());
4901 Standard_Real tolV = Max ((vmax-vmin)*0.01, Precision::Confusion());
4902 Standard_Real fp = aPC->FirstParameter();
4903 Standard_Real lp = aPC->LastParameter();
4904 Standard_Real step = (lp-fp)/(NPoints+1);
4906 // adjust domain for periodic surfaces
4907 TopLoc_Location aLoc;
4908 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc);
4909 if (aSurf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)))
4910 aSurf = (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf))->BasisSurface();
4912 gp_Pnt2d pnt = aPC->Value((fp+lp)/2);
4916 if (aSurf->IsUPeriodic()) {
4917 Standard_Real aPer = aSurf->UPeriod();
4918 Standard_Integer nshift = (Standard_Integer) ((u-umin)/aPer);
4919 if (u < umin+aPer*nshift) nshift--;
4920 umin += aPer*nshift;
4921 umax += aPer*nshift;
4923 if (aSurf->IsVPeriodic()) {
4924 Standard_Real aPer = aSurf->VPeriod();
4925 Standard_Integer nshift = (Standard_Integer) ((v-vmin)/aPer);
4926 if (v < vmin+aPer*nshift) nshift--;
4927 vmin += aPer*nshift;
4928 vmax += aPer*nshift;
4932 for (i=1; i <= NPoints; i++) {
4933 Standard_Real p = fp + i * step;
4934 pnt = aPC->Value(p);
4936 if (umin-u > tolU || u-umax > tolU ||
4937 vmin-v > tolV || v-vmax > tolV)
4938 return Standard_False;
4940 return Standard_True;