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);
311 //=======================================================================
314 //=======================================================================
315 IntTools_FaceFace::IntTools_FaceFace()
317 myTangentFaces=Standard_False;
319 myHS1 = new GeomAdaptor_HSurface ();
320 myHS2 = new GeomAdaptor_HSurface ();
323 SetParameters(Standard_True, Standard_True, Standard_True, 1.e-07);
326 //=======================================================================
327 //function : SetContext
329 //=======================================================================
330 void IntTools_FaceFace::SetContext(const Handle(IntTools_Context)& aContext)
334 //=======================================================================
337 //=======================================================================
338 const Handle(IntTools_Context)& IntTools_FaceFace::Context()const
342 //=======================================================================
345 //=======================================================================
346 const TopoDS_Face& IntTools_FaceFace::Face1() const
350 //=======================================================================
353 //=======================================================================
354 const TopoDS_Face& IntTools_FaceFace::Face2() const
358 //=======================================================================
359 //function : TangentFaces
361 //=======================================================================
362 Standard_Boolean IntTools_FaceFace::TangentFaces() const
364 return myTangentFaces;
366 //=======================================================================
369 //=======================================================================
370 const IntTools_SequenceOfPntOn2Faces& IntTools_FaceFace::Points() const
374 //=======================================================================
377 //=======================================================================
378 Standard_Boolean IntTools_FaceFace::IsDone() const
382 //=======================================================================
383 //function : TolReached3d
385 //=======================================================================
386 Standard_Real IntTools_FaceFace::TolReached3d() const
388 return myTolReached3d;
390 //=======================================================================
392 //purpose : return lines of intersection
393 //=======================================================================
394 const IntTools_SequenceOfCurves& IntTools_FaceFace::Lines() const
396 StdFail_NotDone_Raise_if
398 "IntTools_FaceFace::Lines() => !myIntersector.IsDone()");
401 //=======================================================================
402 //function : TolReached2d
404 //=======================================================================
405 Standard_Real IntTools_FaceFace::TolReached2d() const
407 return myTolReached2d;
409 // =======================================================================
410 // function: SetParameters
412 // =======================================================================
413 void IntTools_FaceFace::SetParameters(const Standard_Boolean ToApproxC3d,
414 const Standard_Boolean ToApproxC2dOnS1,
415 const Standard_Boolean ToApproxC2dOnS2,
416 const Standard_Real ApproximationTolerance)
418 myApprox = ToApproxC3d;
419 myApprox1 = ToApproxC2dOnS1;
420 myApprox2 = ToApproxC2dOnS2;
421 myTolApprox = ApproximationTolerance;
423 //=======================================================================
426 //=======================================================================
427 void IntTools_FaceFace::SetList(IntSurf_ListOfPntOn2S& aListOfPnts)
429 myListOfPnts = aListOfPnts;
431 //=======================================================================
433 //purpose : intersect surfaces of the faces
434 //=======================================================================
435 void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
436 const TopoDS_Face& aF2)
438 Standard_Boolean hasCone, RestrictLine, bTwoPlanes, bReverse;
439 Standard_Integer aNbLin, aNbPnts, i, NbLinPP;
440 Standard_Real TolArc, TolTang, Deflection, UVMaxStep;
441 Standard_Real umin, umax, vmin, vmax;
442 Standard_Real aTolF1, aTolF2;
443 GeomAbs_SurfaceType aType1, aType2;
444 Handle(Geom_Surface) S1, S2;
445 Handle(IntTools_TopolTool) dom1, dom2;
446 BRepAdaptor_Surface aBAS1, aBAS2;
448 if (myContext.IsNull()) {
449 myContext=new IntTools_Context;
452 mySeqOfCurve.Clear();
455 myIsDone = Standard_False;
457 hasCone = Standard_False;
458 bTwoPlanes = Standard_False;
463 aBAS1.Initialize(myFace1, Standard_False);
464 aBAS2.Initialize(myFace2, Standard_False);
465 aType1=aBAS1.GetType();
466 aType2=aBAS2.GetType();
468 bReverse=SortTypes(aType1, aType2);
472 aType1=aBAS2.GetType();
473 aType2=aBAS1.GetType();
475 if (myListOfPnts.Extent()) {
476 Standard_Real aU1,aV1,aU2,aV2;
477 IntSurf_ListIteratorOfListOfPntOn2S aItP2S;
479 aItP2S.Initialize(myListOfPnts);
480 for (; aItP2S.More(); aItP2S.Next()){
481 IntSurf_PntOn2S& aP2S=aItP2S.Value();
482 aP2S.Parameters(aU1,aV1,aU2,aV2);
483 aP2S.SetValue(aU2,aV2,aU1,aV1);
488 S1=BRep_Tool::Surface(myFace1);
489 S2=BRep_Tool::Surface(myFace2);
491 aTolF1=BRep_Tool::Tolerance(myFace1);
492 aTolF2=BRep_Tool::Tolerance(myFace2);
494 TolArc= aTolF1 + aTolF2;
498 if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
499 bTwoPlanes = Standard_True;
501 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
502 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
504 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
505 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
506 Standard_Real TolAng = 1.e-8;
507 PerformPlanes(myHS1, myHS2, TolAng, TolTang, myApprox1, myApprox2,
508 mySeqOfCurve, myTangentFaces);
510 myIsDone = Standard_True;
512 if(!myTangentFaces) {
514 NbLinPP = mySeqOfCurve.Length();
516 Standard_Real aTolFMax;
518 myTolReached3d = 1.e-7;
520 aTolFMax=Max(aTolF1, aTolF2);
522 if (aTolFMax>myTolReached3d) {
523 myTolReached3d=aTolFMax;
525 myTolReached2d = myTolReached3d;
528 Handle(Geom2d_Curve) aC2D1, aC2D2;
530 aNbLin=mySeqOfCurve.Length();
531 for (i=1; i<=aNbLin; ++i) {
532 IntTools_Curve& aIC=mySeqOfCurve(i);
533 aC2D1=aIC.FirstCurve2d();
534 aC2D2=aIC.SecondCurve2d();
536 aIC.SetFirstCurve2d(aC2D2);
537 aIC.SetSecondCurve2d(aC2D1);
543 }//if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
545 if (aType1==GeomAbs_Plane &&
546 (aType2==GeomAbs_Cylinder ||
547 aType2==GeomAbs_Cone ||
548 aType2==GeomAbs_Torus)) {
549 Standard_Real dU, dV;
551 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
558 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
560 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
561 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
562 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
564 if( aType2==GeomAbs_Cone ) {
566 hasCone = Standard_True;
570 else if ((aType1==GeomAbs_Cylinder||
571 aType1==GeomAbs_Cone ||
572 aType1==GeomAbs_Torus) &&
573 aType2==GeomAbs_Plane) {
574 Standard_Real dU, dV;
576 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
577 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
578 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
580 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
587 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
589 if( aType1==GeomAbs_Cone ) {
591 hasCone = Standard_True;
597 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
599 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
601 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
603 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
605 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
607 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
610 dom1 = new IntTools_TopolTool(myHS1);
611 dom2 = new IntTools_TopolTool(myHS2);
613 myLConstruct.Load(dom1, dom2, myHS1, myHS2);
615 Deflection = (hasCone) ? 0.085 : 0.1;
618 Tolerances(myHS1, myHS2, TolArc, TolTang, UVMaxStep, Deflection);
620 myIntersector.SetTolerances(TolArc, TolTang, UVMaxStep, Deflection);
622 RestrictLine = Standard_False;
624 if((myHS1->IsUClosed() && !myHS1->IsUPeriodic()) ||
625 (myHS1->IsVClosed() && !myHS1->IsVPeriodic()) ||
626 (myHS2->IsUClosed() && !myHS2->IsUPeriodic()) ||
627 (myHS2->IsVClosed() && !myHS2->IsVPeriodic())) {
628 RestrictLine = Standard_True;
631 if(((aType1 != GeomAbs_BSplineSurface) &&
632 (aType1 != GeomAbs_BezierSurface) &&
633 (aType1 != GeomAbs_OtherSurface)) &&
634 ((aType2 != GeomAbs_BSplineSurface) &&
635 (aType2 != GeomAbs_BezierSurface) &&
636 (aType2 != GeomAbs_OtherSurface))) {
637 RestrictLine = Standard_True;
639 if ((aType1 == GeomAbs_Torus) ||
640 (aType2 == GeomAbs_Torus) ) {
641 myListOfPnts.Clear();
646 TopExp_Explorer aExp;
648 for(i = 0; (!RestrictLine) && (i < 2); i++) {
649 const TopoDS_Face& aF=(!i) ? myFace1 : myFace2;
650 aExp.Init(aF, TopAbs_EDGE);
651 for(; aExp.More(); aExp.Next()) {
652 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
654 if(BRep_Tool::Degenerated(aE)) {
655 RestrictLine = Standard_True;
662 myIntersector.Perform(myHS1, dom1, myHS2, dom2,
664 myListOfPnts, RestrictLine);
666 myIsDone = myIntersector.IsDone();
668 myTangentFaces=myIntersector.TangentFaces();
669 if (myTangentFaces) {
674 myListOfPnts.Clear(); // to use LineConstructor
677 aNbLin = myIntersector.NbLines();
678 for (i=1; i<=aNbLin; ++i) {
679 MakeCurve(i, dom1, dom2);
682 ComputeTolReached3d();
685 Handle(Geom2d_Curve) aC2D1, aC2D2;
687 aNbLin=mySeqOfCurve.Length();
688 for (i=1; i<=aNbLin; ++i) {
689 IntTools_Curve& aIC=mySeqOfCurve(i);
690 aC2D1=aIC.FirstCurve2d();
691 aC2D2=aIC.SecondCurve2d();
693 aIC.SetFirstCurve2d(aC2D2);
694 aIC.SetSecondCurve2d(aC2D1);
699 Standard_Real U1,V1,U2,V2;
700 IntTools_PntOnFace aPntOnF1, aPntOnF2;
701 IntTools_PntOn2Faces aPntOn2Faces;
703 aNbPnts=myIntersector.NbPnts();
704 for (i=1; i<=aNbPnts; ++i) {
705 const IntSurf_PntOn2S& aISPnt=myIntersector.Point(i).PntOn2S();
706 const gp_Pnt& aPnt=aISPnt.Value();
707 aISPnt.Parameters(U1,V1,U2,V2);
708 aPntOnF1.Init(myFace1, aPnt, U1, V1);
709 aPntOnF2.Init(myFace2, aPnt, U2, V2);
712 aPntOn2Faces.SetP1(aPntOnF1);
713 aPntOn2Faces.SetP2(aPntOnF2);
716 aPntOn2Faces.SetP2(aPntOnF1);
717 aPntOn2Faces.SetP1(aPntOnF2);
719 myPnts.Append(aPntOn2Faces);
724 //=======================================================================
725 //function :ComputeTolReached3d
727 //=======================================================================
728 void IntTools_FaceFace::ComputeTolReached3d()
730 Standard_Integer aNbLin;
731 GeomAbs_SurfaceType aType1, aType2;
733 aNbLin=myIntersector.NbLines();
734 aType1=myHS1->Surface().GetType();
735 aType2=myHS2->Surface().GetType();
737 if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
739 Handle(IntPatch_Line) aIL1, aIL2;
740 IntPatch_IType aTL1, aTL2;
742 aIL1=myIntersector.Line(1);
743 aIL2=myIntersector.Line(2);
744 aTL1=aIL1->ArcType();
745 aTL2=aIL2->ArcType();
746 if (aTL1==IntPatch_Lin && aTL2==IntPatch_Lin) {
747 Standard_Real aD, aDTresh, dTol;
753 aL1=Handle(IntPatch_GLine)::DownCast(aIL1)->Line();
754 aL2=Handle(IntPatch_GLine)::DownCast(aIL2)->Line();
755 aD=aL1.Distance(aL2);
758 myTolReached3d=aD+dTol;
765 {// Check the distances
766 Standard_Integer i, j, aNbP;
767 Standard_Real aT, aT1, aT2, dT, aD2, aD2Max;
771 aNbLin=mySeqOfCurve.Length();
773 for (i=1; i<=aNbLin; ++i) {
774 const IntTools_Curve& aIC=mySeqOfCurve(i);
775 const Handle(Geom_Curve)& aC3D=aIC.Curve();
776 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
777 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
782 const Handle(Geom_BSplineCurve)& aBC=
783 Handle(Geom_BSplineCurve)::DownCast(aC3D);
788 aT1=aBC->FirstParameter();
789 aT2=aBC->LastParameter();
793 //modified by NIZNHY-PKV Tue Apr 17 14:36:33 2012f
794 for (j=1; j<aNbP; ++j) {
796 aD2=MaxSquareDistance(aT, aC3D, aC2D1, aC2D2,
797 myHS1, myHS2, myFace1, myFace2, myContext);
801 }//for (j=0; j<aNbP; ++j) {
802 }//for (i=1; i<=aNbLin; ++i) {
804 myTolReached3d=sqrt(aD2Max);
807 }// if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
810 else if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
811 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
815 aTolF1 = BRep_Tool::Tolerance(myFace1);
816 aTolF2 = BRep_Tool::Tolerance(myFace2);
817 aTolFMax=Max(aTolF1, aTolF2);
819 if (aTolFMax>aTolTresh) {
820 myTolReached3d=aTolFMax;
822 }//if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
825 else if((aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) ||
826 (aType2 == GeomAbs_Cylinder && aType1 == GeomAbs_Plane)) {
828 const Handle(IntPatch_Line)& aIL1 = myIntersector.Line(1);
829 if(aIL1->ArcType() == IntPatch_Circle) {
830 gp_Circ aCir = Handle(IntPatch_GLine)::DownCast(aIL1)->Circle();
831 gp_XYZ aCirDir = aCir.Axis().Direction().XYZ();
834 if(aType1 == GeomAbs_Plane) {
835 aPln = myHS1->Surface().Plane();
838 aPln = myHS2->Surface().Plane();
840 aPlDir = aPln.Axis().Direction().XYZ();
841 Standard_Real cs = aCirDir*aPlDir;
842 if(cs < 0.) aPlDir.Reverse();
843 Standard_Real eps = 1.e-14;
844 if(!aPlDir.IsEqual(aCirDir, eps)) {
845 Standard_Integer aNbP = 11;
846 Standard_Real dt = 2.*M_PI / (aNbP - 1), t;
847 for(t = 0.; t < 2.*M_PI; t += dt) {
848 Standard_Real d = aPln.Distance(ElCLib::Value(t, aCir));
849 if(myTolReached3d < d) myTolReached3d = d;
851 myTolReached3d *= 1.1;
853 } //aIL1->ArcType() == IntPatch_Circle
855 } // aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane)
856 //End IFV Bug OCC20297
858 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
859 (aType2==GeomAbs_Plane && aType1==GeomAbs_Torus)) {
860 aNbLin=mySeqOfCurve.Length();
865 Standard_Integer i, aNbP;
866 Standard_Real aT, aT1, aT2, dT, aUT, aVT, aUP, aVP;
867 Standard_Real aDP, aDT, aDmax;
872 const IntTools_Curve& aIC=mySeqOfCurve(1);
873 const Handle(Geom_Curve)& aC3D=aIC.Curve();
874 const Handle(Geom_BSplineCurve)& aBS=
875 Handle(Geom_BSplineCurve)::DownCast(aC3D);
880 aT1=aBS->FirstParameter();
881 aT2=aBS->LastParameter();
883 aPln =(aType1==GeomAbs_Plane) ? myHS1->Plane() : myHS2->Plane();
884 aTorus=(aType1==GeomAbs_Plane) ? myHS2->Torus() : myHS1->Torus();
888 dT=(aT2-aT1)/(aNbP-1);
889 for (i=0; i<aNbP; ++i) {
897 ElSLib::Parameters(aPln, aP, aUP, aVP);
898 aPP=ElSLib::Value(aUP, aVP, aPln);
899 aDP=aP.SquareDistance(aPP);
904 ElSLib::Parameters(aTorus, aP, aUT, aVT);
905 aPT=ElSLib::Value(aUT, aVT, aTorus);
906 aDT=aP.SquareDistance(aPT);
912 if (aDmax > myTolReached3d*myTolReached3d) {
913 myTolReached3d=sqrt(aDmax);
914 myTolReached3d=1.1*myTolReached3d;
916 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
918 else if ((aType1==GeomAbs_SurfaceOfRevolution && aType2==GeomAbs_Cylinder) ||
919 (aType2==GeomAbs_SurfaceOfRevolution && aType1==GeomAbs_Cylinder)) {
920 Standard_Integer i, j, aNbP;
921 Standard_Real aT, aT1, aT2, dT, aD2max, aD2;
923 aNbLin=mySeqOfCurve.Length();
927 for (i=1; i<=aNbLin; ++i) {
928 const IntTools_Curve& aIC=mySeqOfCurve(i);
929 const Handle(Geom_Curve)& aC3D=aIC.Curve();
930 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
931 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
936 const Handle(Geom_BSplineCurve)& aBC=
937 Handle(Geom_BSplineCurve)::DownCast(aC3D);
942 aT1=aBC->FirstParameter();
943 aT2=aBC->LastParameter();
945 dT=(aT2-aT1)/(aNbP-1);
946 for (j=0; j<aNbP; ++j) {
952 aD2=MaxSquareDistance(aT, aC3D, aC2D1, aC2D2,
953 myHS1, myHS2, myFace1, myFace2, myContext);
957 }//for (j=0; j<aNbP; ++j) {
958 }//for (i=1; i<=aNbLin; ++i) {
960 aD2=myTolReached3d*myTolReached3d;
962 myTolReached3d=sqrt(aD2max);
964 }//if((aType1==GeomAbs_SurfaceOfRevolution ...
966 //=======================================================================
967 //function : MakeCurve
969 //=======================================================================
970 void IntTools_FaceFace::MakeCurve(const Standard_Integer Index,
971 const Handle(Adaptor3d_TopolTool)& dom1,
972 const Handle(Adaptor3d_TopolTool)& dom2)
974 Standard_Boolean bDone, rejectSurface, reApprox, bAvoidLineConstructor;
976 Standard_Integer i, j, aNbParts;
977 Standard_Real fprm, lprm;
979 Handle(IntPatch_Line) L;
981 Handle(Geom_Curve) newc;
983 const Standard_Real TOLCHECK =0.0000001;
984 const Standard_Real TOLANGCHECK=0.1;
986 rejectSurface = Standard_False;
987 reApprox = Standard_False;
992 bAvoidLineConstructor = Standard_False;
993 L = myIntersector.Line(Index);
996 if(typl==IntPatch_Walking) {
997 Handle(IntPatch_Line) anewL;
999 const Handle(IntPatch_WLine)& aWLine=
1000 Handle(IntPatch_WLine)::DownCast(L);
1002 //DumpWLine(aWLine);
1004 anewL = ComputePurgedWLine(aWLine);
1005 if(anewL.IsNull()) {
1011 { const Handle(IntPatch_WLine)& aWLineX=
1012 Handle(IntPatch_WLine)::DownCast(L);
1018 if(!myListOfPnts.IsEmpty()) {
1019 bAvoidLineConstructor = Standard_True;
1022 Standard_Integer nbp = aWLine->NbPnts();
1023 const IntSurf_PntOn2S& p1 = aWLine->Point(1);
1024 const IntSurf_PntOn2S& p2 = aWLine->Point(nbp);
1026 const gp_Pnt& P1 = p1.Value();
1027 const gp_Pnt& P2 = p2.Value();
1029 if(P1.SquareDistance(P2) < 1.e-14) {
1030 bAvoidLineConstructor = Standard_False;
1036 if(!bAvoidLineConstructor) {
1037 myLConstruct.Perform(L);
1039 bDone=myLConstruct.IsDone();
1040 aNbParts=myLConstruct.NbParts();
1041 if (!bDone|| !aNbParts) {
1050 //########################################
1051 // Line, Parabola, Hyperbola
1052 //########################################
1054 case IntPatch_Parabola:
1055 case IntPatch_Hyperbola: {
1056 if (typl == IntPatch_Lin) {
1058 new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line());
1061 else if (typl == IntPatch_Parabola) {
1063 new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola());
1066 else if (typl == IntPatch_Hyperbola) {
1068 new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola());
1072 if (typl == IntPatch_Lin) {
1073 TolR3d (myFace1, myFace2, myTolReached3d);
1076 aNbParts=myLConstruct.NbParts();
1077 for (i=1; i<=aNbParts; i++) {
1078 myLConstruct.Part(i, fprm, lprm);
1080 if (!Precision::IsNegativeInfinite(fprm) &&
1081 !Precision::IsPositiveInfinite(lprm)) {
1083 IntTools_Curve aCurve;
1085 Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm);
1086 aCurve.SetCurve(aCT3D);
1087 if (typl == IntPatch_Parabola) {
1088 Standard_Real aTolF1, aTolF2, aTolBase;
1090 aTolF1 = BRep_Tool::Tolerance(myFace1);
1091 aTolF2 = BRep_Tool::Tolerance(myFace2);
1092 aTolBase=aTolF1+aTolF2;
1093 myTolReached3d=IntTools_Tools::CurveTolerance(aCT3D, aTolBase);
1096 aCurve.SetCurve(new Geom_TrimmedCurve(newc, fprm, lprm));
1098 Handle (Geom2d_Curve) C2d;
1099 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1100 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1101 myTolReached2d=Tolpc;
1104 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1107 Handle(Geom2d_BSplineCurve) H1;
1109 aCurve.SetFirstCurve2d(H1);
1113 Handle (Geom2d_Curve) C2d;
1114 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1115 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1116 myTolReached2d=Tolpc;
1119 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1122 Handle(Geom2d_BSplineCurve) H1;
1124 aCurve.SetSecondCurve2d(H1);
1126 mySeqOfCurve.Append(aCurve);
1127 } // end of if (!Precision::IsNegativeInfinite(fprm) && !Precision::IsPositiveInfinite(lprm))
1130 // on regarde si on garde
1132 Standard_Boolean bFNIt, bLPIt;
1133 Standard_Real aTestPrm, dT=100.;
1135 bFNIt=Precision::IsNegativeInfinite(fprm);
1136 bLPIt=Precision::IsPositiveInfinite(lprm);
1140 if (bFNIt && !bLPIt) {
1143 else if (!bFNIt && bLPIt) {
1147 gp_Pnt ptref(newc->Value(aTestPrm));
1150 Standard_Real u1, v1, u2, v2, Tol;
1152 Tol = Precision::Confusion();
1153 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1154 ok = (dom1->Classify(gp_Pnt2d(u1, v1), Tol) != TopAbs_OUT);
1156 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1159 Handle(Geom2d_BSplineCurve) H1;
1160 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1163 }// end of for (i=1; i<=myLConstruct.NbParts(); i++)
1164 }// case IntPatch_Lin: case IntPatch_Parabola: case IntPatch_Hyperbola:
1167 //########################################
1168 // Circle and Ellipse
1169 //########################################
1170 case IntPatch_Circle:
1171 case IntPatch_Ellipse: {
1173 if (typl == IntPatch_Circle) {
1174 newc = new Geom_Circle
1175 (Handle(IntPatch_GLine)::DownCast(L)->Circle());
1177 else { //IntPatch_Ellipse
1178 newc = new Geom_Ellipse
1179 (Handle(IntPatch_GLine)::DownCast(L)->Ellipse());
1183 TolR3d (myFace1, myFace2, myTolReached3d);
1185 aNbParts=myLConstruct.NbParts();
1187 Standard_Real aPeriod, aNul;
1188 TColStd_SequenceOfReal aSeqFprm, aSeqLprm;
1193 for (i=1; i<=aNbParts; i++) {
1194 myLConstruct.Part(i, fprm, lprm);
1196 if (fprm < aNul && lprm > aNul) {
1197 // interval that goes through 0. is divided on two intervals;
1198 while (fprm<aNul || fprm>aPeriod) fprm=fprm+aPeriod;
1199 while (lprm<aNul || lprm>aPeriod) lprm=lprm+aPeriod;
1201 if((aPeriod - fprm) > Tolpc) {
1202 aSeqFprm.Append(fprm);
1203 aSeqLprm.Append(aPeriod);
1206 gp_Pnt P1 = newc->Value(fprm);
1207 gp_Pnt P2 = newc->Value(aPeriod);
1208 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1209 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1211 if(P1.Distance(P2) > aTolDist) {
1212 Standard_Real anewpar = fprm;
1214 if(ParameterOutOfBoundary(fprm, newc, myFace1, myFace2, lprm, Standard_False, anewpar, myContext)) {
1217 aSeqFprm.Append(fprm);
1218 aSeqLprm.Append(aPeriod);
1223 if((lprm - aNul) > Tolpc) {
1224 aSeqFprm.Append(aNul);
1225 aSeqLprm.Append(lprm);
1228 gp_Pnt P1 = newc->Value(aNul);
1229 gp_Pnt P2 = newc->Value(lprm);
1230 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1231 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1233 if(P1.Distance(P2) > aTolDist) {
1234 Standard_Real anewpar = lprm;
1236 if(ParameterOutOfBoundary(lprm, newc, myFace1, myFace2, fprm, Standard_True, anewpar, myContext)) {
1239 aSeqFprm.Append(aNul);
1240 aSeqLprm.Append(lprm);
1246 aSeqFprm.Append(fprm);
1247 aSeqLprm.Append(lprm);
1252 aNbParts=aSeqFprm.Length();
1253 for (i=1; i<=aNbParts; i++) {
1257 Standard_Real aRealEpsilon=RealEpsilon();
1258 if (Abs(fprm) > aRealEpsilon || Abs(lprm-2.*M_PI) > aRealEpsilon) {
1259 //==============================================
1261 IntTools_Curve aCurve;
1262 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1263 aCurve.SetCurve(aTC3D);
1264 fprm=aTC3D->FirstParameter();
1265 lprm=aTC3D->LastParameter ();
1267 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {////
1269 Handle (Geom2d_Curve) C2d;
1270 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1271 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1272 myTolReached2d=Tolpc;
1275 aCurve.SetFirstCurve2d(C2d);
1278 Handle(Geom2d_BSplineCurve) H1;
1279 aCurve.SetFirstCurve2d(H1);
1284 Handle (Geom2d_Curve) C2d;
1285 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1286 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1287 myTolReached2d=Tolpc;
1290 aCurve.SetSecondCurve2d(C2d);
1293 Handle(Geom2d_BSplineCurve) H1;
1294 aCurve.SetSecondCurve2d(H1);
1299 Handle(Geom2d_BSplineCurve) H1;
1300 aCurve.SetFirstCurve2d(H1);
1301 aCurve.SetSecondCurve2d(H1);
1303 mySeqOfCurve.Append(aCurve);
1304 //==============================================
1305 } //if (Abs(fprm) > RealEpsilon() || Abs(lprm-2.*M_PI) > RealEpsilon())
1308 // on regarde si on garde
1311 // if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*M_PI) < RealEpsilon()) {
1312 if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*M_PI) <= aRealEpsilon) {
1313 IntTools_Curve aCurve;
1314 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1315 aCurve.SetCurve(aTC3D);
1316 fprm=aTC3D->FirstParameter();
1317 lprm=aTC3D->LastParameter ();
1320 Handle (Geom2d_Curve) C2d;
1321 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1322 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1323 myTolReached2d=Tolpc;
1326 aCurve.SetFirstCurve2d(C2d);
1329 Handle(Geom2d_BSplineCurve) H1;
1330 aCurve.SetFirstCurve2d(H1);
1334 Handle (Geom2d_Curve) C2d;
1335 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1336 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1337 myTolReached2d=Tolpc;
1340 aCurve.SetSecondCurve2d(C2d);
1343 Handle(Geom2d_BSplineCurve) H1;
1344 aCurve.SetSecondCurve2d(H1);
1346 mySeqOfCurve.Append(aCurve);
1351 Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol;
1353 aTwoPIdiv17=2.*M_PI/17.;
1355 for (j=0; j<=17; j++) {
1356 gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
1357 Tol = Precision::Confusion();
1359 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1360 ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT);
1362 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1365 IntTools_Curve aCurve;
1366 aCurve.SetCurve(newc);
1367 //==============================================
1368 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {
1371 Handle (Geom2d_Curve) C2d;
1372 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1373 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1374 myTolReached2d=Tolpc;
1377 aCurve.SetFirstCurve2d(C2d);
1380 Handle(Geom2d_BSplineCurve) H1;
1381 aCurve.SetFirstCurve2d(H1);
1385 Handle (Geom2d_Curve) C2d;
1386 BuildPCurves(fprm, lprm, Tolpc,myHS2->ChangeSurface().Surface(), newc, C2d);
1387 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1388 myTolReached2d=Tolpc;
1391 aCurve.SetSecondCurve2d(C2d);
1395 Handle(Geom2d_BSplineCurve) H1;
1396 aCurve.SetSecondCurve2d(H1);
1398 }// end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse)
1401 Handle(Geom2d_BSplineCurve) H1;
1403 aCurve.SetFirstCurve2d(H1);
1404 aCurve.SetSecondCurve2d(H1);
1406 //==============================================
1408 mySeqOfCurve.Append(aCurve);
1411 }// end of if (ok) {
1412 }// end of for (Standard_Integer j=0; j<=17; j++)
1413 }// end of else { on regarde si on garde
1414 }// for (i=1; i<=myLConstruct.NbParts(); i++)
1415 }// IntPatch_Circle: IntPatch_Ellipse:
1418 case IntPatch_Analytic: {
1419 IntSurf_Quadric quad1,quad2;
1420 GeomAbs_SurfaceType typs = myHS1->Surface().GetType();
1424 quad1.SetValue(myHS1->Surface().Plane());
1426 case GeomAbs_Cylinder:
1427 quad1.SetValue(myHS1->Surface().Cylinder());
1430 quad1.SetValue(myHS1->Surface().Cone());
1432 case GeomAbs_Sphere:
1433 quad1.SetValue(myHS1->Surface().Sphere());
1436 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 1");
1439 typs = myHS2->Surface().GetType();
1443 quad2.SetValue(myHS2->Surface().Plane());
1445 case GeomAbs_Cylinder:
1446 quad2.SetValue(myHS2->Surface().Cylinder());
1449 quad2.SetValue(myHS2->Surface().Cone());
1451 case GeomAbs_Sphere:
1452 quad2.SetValue(myHS2->Surface().Sphere());
1455 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 2");
1459 IntPatch_ALineToWLine convert (quad1, quad2);
1462 aNbParts=myLConstruct.NbParts();
1463 for (i=1; i<=aNbParts; i++) {
1464 myLConstruct.Part(i, fprm, lprm);
1465 Handle(IntPatch_WLine) WL =
1466 convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm);
1468 Handle(Geom2d_BSplineCurve) H1;
1469 Handle(Geom2d_BSplineCurve) H2;
1472 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1476 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1479 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1483 else { // myApprox=TRUE
1484 GeomInt_WLApprox theapp3d;
1486 Standard_Real tol2d = myTolApprox;
1488 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True);
1490 aNbParts=myLConstruct.NbParts();
1491 for (i=1; i<=aNbParts; i++) {
1492 myLConstruct.Part(i, fprm, lprm);
1493 Handle(IntPatch_WLine) WL =
1494 convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
1496 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
1498 if (!theapp3d.IsDone()) {
1500 Handle(Geom2d_BSplineCurve) H1;
1501 Handle(Geom2d_BSplineCurve) H2;
1504 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1508 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1511 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1515 if(myApprox1 || myApprox2) {
1516 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) {
1517 myTolReached2d = theapp3d.TolReached2d();
1521 if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) {
1522 myTolReached3d = theapp3d.TolReached3d();
1525 Standard_Integer aNbMultiCurves, nbpoles;
1526 aNbMultiCurves=theapp3d.NbMultiCurves();
1527 for (j=1; j<=aNbMultiCurves; j++) {
1528 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1529 nbpoles = mbspc.NbPoles();
1531 TColgp_Array1OfPnt tpoles(1, nbpoles);
1532 mbspc.Curve(1, tpoles);
1533 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1535 mbspc.Multiplicities(),
1538 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1539 Check.FixTangent(Standard_True,Standard_True);
1541 IntTools_Curve aCurve;
1542 aCurve.SetCurve(BS);
1545 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1546 mbspc.Curve(2,tpoles2d);
1547 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1549 mbspc.Multiplicities(),
1552 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1553 newCheck.FixTangent(Standard_True,Standard_True);
1555 aCurve.SetFirstCurve2d(BS2);
1558 Handle(Geom2d_BSplineCurve) H1;
1559 aCurve.SetFirstCurve2d(H1);
1563 TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
1564 Standard_Integer TwoOrThree;
1565 TwoOrThree=myApprox1 ? 3 : 2;
1566 mbspc.Curve(TwoOrThree, tpoles2d);
1567 Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
1569 mbspc.Multiplicities(),
1572 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1573 newCheck.FixTangent(Standard_True,Standard_True);
1575 aCurve.SetSecondCurve2d(BS2);
1578 Handle(Geom2d_BSplineCurve) H2;
1579 aCurve.SetSecondCurve2d(H2);
1582 mySeqOfCurve.Append(aCurve);
1584 }// for (j=1; j<=aNbMultiCurves; j++) {
1585 }// else from if (!theapp3d.IsDone())
1586 }// for (i=1; i<=aNbParts; i++) {
1587 }// else { // myApprox=TRUE
1588 }// case IntPatch_Analytic:
1591 case IntPatch_Walking:{
1592 Handle(IntPatch_WLine) WL =
1593 Handle(IntPatch_WLine)::DownCast(L);
1595 Standard_Integer ifprm, ilprm;
1599 if(!bAvoidLineConstructor){
1600 aNbParts=myLConstruct.NbParts();
1602 for (i=1; i<=aNbParts; ++i) {
1603 Handle(Geom2d_BSplineCurve) H1, H2;
1604 Handle(Geom_Curve) aBSp;
1606 if(bAvoidLineConstructor) {
1608 ilprm = WL->NbPnts();
1611 myLConstruct.Part(i, fprm, lprm);
1612 ifprm=(Standard_Integer)fprm;
1613 ilprm=(Standard_Integer)lprm;
1617 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1621 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1624 aBSp=MakeBSpline(WL, ifprm, ilprm);
1625 IntTools_Curve aIC(aBSp, H1, H2);
1626 mySeqOfCurve.Append(aIC);
1627 }// for (i=1; i<=aNbParts; ++i) {
1628 }// if (!myApprox) {
1631 Standard_Boolean bIsDecomposited;
1632 Standard_Integer nbiter, aNbSeqOfL;
1633 Standard_Real tol2d;
1634 IntPatch_SequenceOfLine aSeqOfL;
1635 GeomInt_WLApprox theapp3d;
1636 Approx_ParametrizationType aParType = Approx_ChordLength;
1638 Standard_Boolean anApprox1 = myApprox1;
1639 Standard_Boolean anApprox2 = myApprox2;
1641 tol2d = myTolApprox;
1643 GeomAbs_SurfaceType typs1, typs2;
1644 typs1 = myHS1->Surface().GetType();
1645 typs2 = myHS2->Surface().GetType();
1646 Standard_Boolean anWithPC = Standard_True;
1648 if(typs1 == GeomAbs_Cylinder && typs2 == GeomAbs_Sphere) {
1650 ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere());
1652 else if (typs1 == GeomAbs_Sphere && typs2 == GeomAbs_Cylinder) {
1654 ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere());
1657 //aParType = Approx_Centripetal;
1658 myTolApprox = 1.e-5;
1659 anApprox1 = Standard_False;
1660 anApprox2 = Standard_False;
1662 tol2d = myTolApprox;
1665 if(myHS1 == myHS2) {
1667 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1668 rejectSurface = Standard_True;
1671 if(reApprox && !rejectSurface)
1672 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1674 Standard_Integer iDegMax, iDegMin, iNbIter;
1676 ApproxParameters(myHS1, myHS2, iDegMin, iDegMax, iNbIter);
1677 theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, iNbIter, Standard_True, aParType);
1682 Standard_Real aReachedTol = Precision::Confusion();
1683 bIsDecomposited=DecompositionOfWLine(WL,
1689 bAvoidLineConstructor,
1693 if ( bIsDecomposited && ( myTolReached3d < aReachedTol ) )
1694 myTolReached3d = aReachedTol;
1697 aNbSeqOfL=aSeqOfL.Length();
1699 if (bIsDecomposited) {
1705 if (!bAvoidLineConstructor) {
1706 aNbParts=myLConstruct.NbParts();
1711 // nbiter=(bIsDecomposited) ? aSeqOfL.Length() :
1712 // ((bAvoidLineConstructor) ? 1 :aNbParts);
1714 for(i = 1; i <= nbiter; ++i) {
1715 if(bIsDecomposited) {
1716 WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i));
1718 ilprm = WL->NbPnts();
1721 if(bAvoidLineConstructor) {
1723 ilprm = WL->NbPnts();
1726 myLConstruct.Part(i, fprm, lprm);
1727 ifprm = (Standard_Integer)fprm;
1728 ilprm = (Standard_Integer)lprm;
1732 //-- Si une des surfaces est un plan , on approxime en 2d
1733 //-- sur cette surface et on remonte les points 2d en 3d.
1734 if(typs1 == GeomAbs_Plane) {
1735 theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm);
1737 else if(typs2 == GeomAbs_Plane) {
1738 theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm);
1742 if (myHS1 != myHS2){
1743 if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) &&
1744 (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) {
1746 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType);
1748 Standard_Boolean bUseSurfaces;
1749 bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm, ilprm);
1752 rejectSurface = Standard_True;
1754 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1759 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm);
1762 if (!theapp3d.IsDone()) {
1764 Handle(Geom2d_BSplineCurve) H1;
1766 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
1767 Handle(Geom2d_BSplineCurve) H2;
1770 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1774 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1777 IntTools_Curve aIC(aBSp, H1, H2);
1778 mySeqOfCurve.Append(aIC);
1782 if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) {
1783 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) {
1784 myTolReached2d = theapp3d.TolReached2d();
1787 if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) {
1788 myTolReached3d = myTolReached2d;
1790 if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
1791 if (myTolReached3d<1.e-6) {
1792 myTolReached3d = theapp3d.TolReached3d();
1793 myTolReached3d=1.e-6;
1798 else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) {
1799 myTolReached3d = theapp3d.TolReached3d();
1802 Standard_Integer aNbMultiCurves, nbpoles;
1803 aNbMultiCurves=theapp3d.NbMultiCurves();
1804 for (j=1; j<=aNbMultiCurves; j++) {
1805 if(typs1 == GeomAbs_Plane) {
1806 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1807 nbpoles = mbspc.NbPoles();
1809 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1810 TColgp_Array1OfPnt tpoles(1,nbpoles);
1812 mbspc.Curve(1,tpoles2d);
1813 const gp_Pln& Pln = myHS1->Surface().Plane();
1815 Standard_Integer ik;
1816 for(ik = 1; ik<= nbpoles; ik++) {
1818 ElSLib::Value(tpoles2d.Value(ik).X(),
1819 tpoles2d.Value(ik).Y(),
1823 Handle(Geom_BSplineCurve) BS =
1824 new Geom_BSplineCurve(tpoles,
1826 mbspc.Multiplicities(),
1828 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1829 Check.FixTangent(Standard_True, Standard_True);
1831 IntTools_Curve aCurve;
1832 aCurve.SetCurve(BS);
1835 Handle(Geom2d_BSplineCurve) BS1 =
1836 new Geom2d_BSplineCurve(tpoles2d,
1838 mbspc.Multiplicities(),
1840 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
1841 Check1.FixTangent(Standard_True,Standard_True);
1843 // ############################################
1844 if(!rejectSurface && !reApprox) {
1845 Standard_Boolean isValid = IsCurveValid(BS1);
1847 reApprox = Standard_True;
1851 // ############################################
1852 aCurve.SetFirstCurve2d(BS1);
1855 Handle(Geom2d_BSplineCurve) H1;
1856 aCurve.SetFirstCurve2d(H1);
1860 mbspc.Curve(2, tpoles2d);
1862 Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
1864 mbspc.Multiplicities(),
1866 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1867 newCheck.FixTangent(Standard_True,Standard_True);
1869 // ###########################################
1870 if(!rejectSurface && !reApprox) {
1871 Standard_Boolean isValid = IsCurveValid(BS2);
1873 reApprox = Standard_True;
1877 // ###########################################
1879 aCurve.SetSecondCurve2d(BS2);
1882 Handle(Geom2d_BSplineCurve) H2;
1884 aCurve.SetSecondCurve2d(H2);
1887 mySeqOfCurve.Append(aCurve);
1890 else if(typs2 == GeomAbs_Plane) {
1891 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1892 nbpoles = mbspc.NbPoles();
1894 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1895 TColgp_Array1OfPnt tpoles(1,nbpoles);
1896 mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d);
1897 const gp_Pln& Pln = myHS2->Surface().Plane();
1899 Standard_Integer ik;
1900 for(ik = 1; ik<= nbpoles; ik++) {
1902 ElSLib::Value(tpoles2d.Value(ik).X(),
1903 tpoles2d.Value(ik).Y(),
1908 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1910 mbspc.Multiplicities(),
1912 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1913 Check.FixTangent(Standard_True,Standard_True);
1915 IntTools_Curve aCurve;
1916 aCurve.SetCurve(BS);
1919 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
1921 mbspc.Multiplicities(),
1923 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
1924 Check1.FixTangent(Standard_True,Standard_True);
1926 // ###########################################
1927 if(!rejectSurface && !reApprox) {
1928 Standard_Boolean isValid = IsCurveValid(BS1);
1930 reApprox = Standard_True;
1934 // ###########################################
1935 aCurve.SetSecondCurve2d(BS1);
1938 Handle(Geom2d_BSplineCurve) H2;
1939 aCurve.SetSecondCurve2d(H2);
1943 mbspc.Curve(1,tpoles2d);
1944 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1946 mbspc.Multiplicities(),
1948 GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK);
1949 Check2.FixTangent(Standard_True,Standard_True);
1951 // ###########################################
1952 if(!rejectSurface && !reApprox) {
1953 Standard_Boolean isValid = IsCurveValid(BS2);
1955 reApprox = Standard_True;
1959 // ###########################################
1960 aCurve.SetFirstCurve2d(BS2);
1963 Handle(Geom2d_BSplineCurve) H1;
1965 aCurve.SetFirstCurve2d(H1);
1968 mySeqOfCurve.Append(aCurve);
1971 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1972 nbpoles = mbspc.NbPoles();
1973 TColgp_Array1OfPnt tpoles(1,nbpoles);
1974 mbspc.Curve(1,tpoles);
1975 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1977 mbspc.Multiplicities(),
1979 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1980 Check.FixTangent(Standard_True,Standard_True);
1982 IntTools_Curve aCurve;
1983 aCurve.SetCurve(BS);
1987 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1988 mbspc.Curve(2,tpoles2d);
1989 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
1991 mbspc.Multiplicities(),
1993 GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK);
1994 newCheck.FixTangent(Standard_True,Standard_True);
1996 aCurve.SetFirstCurve2d(BS1);
1999 Handle(Geom2d_BSplineCurve) BS1;
2000 fprm = BS->FirstParameter();
2001 lprm = BS->LastParameter();
2003 Handle(Geom2d_Curve) C2d;
2004 Standard_Real aTol = myTolApprox;
2005 BuildPCurves(fprm, lprm, aTol, myHS1->ChangeSurface().Surface(), BS, C2d);
2006 BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2007 aCurve.SetFirstCurve2d(BS1);
2012 Handle(Geom2d_BSplineCurve) H1;
2014 aCurve.SetFirstCurve2d(H1);
2018 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2019 mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d);
2020 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
2022 mbspc.Multiplicities(),
2024 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2025 newCheck.FixTangent(Standard_True,Standard_True);
2027 aCurve.SetSecondCurve2d(BS2);
2030 Handle(Geom2d_BSplineCurve) BS2;
2031 fprm = BS->FirstParameter();
2032 lprm = BS->LastParameter();
2034 Handle(Geom2d_Curve) C2d;
2035 Standard_Real aTol = myTolApprox;
2036 BuildPCurves(fprm, lprm, aTol, myHS2->ChangeSurface().Surface(), BS, C2d);
2037 BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2038 aCurve.SetSecondCurve2d(BS2);
2043 Handle(Geom2d_BSplineCurve) H2;
2045 aCurve.SetSecondCurve2d(H2);
2048 mySeqOfCurve.Append(aCurve);
2054 }// case IntPatch_Walking:{
2057 case IntPatch_Restriction:
2063 //=======================================================================
2064 //function : BuildPCurves
2066 //=======================================================================
2067 void BuildPCurves (Standard_Real f,
2070 const Handle (Geom_Surface)& S,
2071 const Handle (Geom_Curve)& C,
2072 Handle (Geom2d_Curve)& C2d)
2075 Standard_Real umin,umax,vmin,vmax;
2080 // in class ProjLib_Function the range of parameters is shrank by 1.e-09
2081 if((l - f) > 2.e-09) {
2082 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2085 // proj. a circle that goes through the pole on a sphere to the sphere
2087 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2091 if((l - f) > Epsilon(Abs(f))) {
2092 GeomAPI_ProjectPointOnSurf aProjector1, aProjector2;
2093 gp_Pnt P1 = C->Value(f);
2094 gp_Pnt P2 = C->Value(l);
2095 aProjector1.Init(P1, S);
2096 aProjector2.Init(P2, S);
2098 if(aProjector1.IsDone() && aProjector2.IsDone()) {
2099 Standard_Real U=0., V=0.;
2100 aProjector1.LowerDistanceParameters(U, V);
2103 aProjector2.LowerDistanceParameters(U, V);
2106 if(p1.Distance(p2) > gp::Resolution()) {
2107 TColgp_Array1OfPnt2d poles(1,2);
2108 TColStd_Array1OfReal knots(1,2);
2109 TColStd_Array1OfInteger mults(1,2);
2114 mults(1) = mults(2) = 2;
2116 C2d = new Geom2d_BSplineCurve(poles,knots,mults,1);
2118 // compute reached tolerance.begin
2119 gp_Pnt PMid = C->Value((f + l) * 0.5);
2120 aProjector1.Perform(PMid);
2122 if(aProjector1.IsDone()) {
2123 aProjector1.LowerDistanceParameters(U, V);
2124 gp_Pnt2d pmidproj(U, V);
2125 gp_Pnt2d pmidcurve2d = C2d->Value((f + l) * 0.5);
2126 Standard_Real adist = pmidcurve2d.Distance(pmidproj);
2127 Tol = (adist > Tol) ? adist : Tol;
2129 // compute reached tolerance.end
2135 S->Bounds(umin, umax, vmin, vmax);
2137 if (S->IsUPeriodic() && !C2d.IsNull()) {
2138 // Recadre dans le domaine UV de la face
2139 Standard_Real period, U0, du, aEps;
2142 aEps=Precision::PConfusion();
2143 period = S->UPeriod();
2144 gp_Pnt2d Pf = C2d->Value(f);
2147 gp_Pnt2d Pl = C2d->Value(l);
2149 U0 = Min(Pl.X(), U0);
2150 // while(U0-umin<aEps) {
2151 while(U0-umin<-aEps) {
2156 while(U0-umax>aEps) {
2167 BOPTColStd_Dump::PrintMessage("BuildPCurves()=> Echec ProjLib\n");
2171 //=======================================================================
2172 //function : Parameters
2174 //=======================================================================
2175 void Parameters(const Handle(GeomAdaptor_HSurface)& HS1,
2176 const Handle(GeomAdaptor_HSurface)& HS2,
2177 const gp_Pnt& Ptref,
2184 IntSurf_Quadric quad1,quad2;
2185 GeomAbs_SurfaceType typs = HS1->Surface().GetType();
2189 quad1.SetValue(HS1->Surface().Plane());
2191 case GeomAbs_Cylinder:
2192 quad1.SetValue(HS1->Surface().Cylinder());
2195 quad1.SetValue(HS1->Surface().Cone());
2197 case GeomAbs_Sphere:
2198 quad1.SetValue(HS1->Surface().Sphere());
2201 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2204 typs = HS2->Surface().GetType();
2207 quad2.SetValue(HS2->Surface().Plane());
2209 case GeomAbs_Cylinder:
2210 quad2.SetValue(HS2->Surface().Cylinder());
2213 quad2.SetValue(HS2->Surface().Cone());
2215 case GeomAbs_Sphere:
2216 quad2.SetValue(HS2->Surface().Sphere());
2219 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2222 quad1.Parameters(Ptref,U1,V1);
2223 quad2.Parameters(Ptref,U2,V2);
2226 //=======================================================================
2227 //function : MakeBSpline
2229 //=======================================================================
2230 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL,
2231 const Standard_Integer ideb,
2232 const Standard_Integer ifin)
2234 Standard_Integer i,nbpnt = ifin-ideb+1;
2235 TColgp_Array1OfPnt poles(1,nbpnt);
2236 TColStd_Array1OfReal knots(1,nbpnt);
2237 TColStd_Array1OfInteger mults(1,nbpnt);
2238 Standard_Integer ipidebm1;
2239 for(i=1,ipidebm1=i+ideb-1; i<=nbpnt;ipidebm1++, i++) {
2240 poles(i) = WL->Point(ipidebm1).Value();
2244 mults(1) = mults(nbpnt) = 2;
2246 new Geom_BSplineCurve(poles,knots,mults,1);
2250 //=======================================================================
2251 //function : MakeBSpline2d
2253 //=======================================================================
2254 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
2255 const Standard_Integer ideb,
2256 const Standard_Integer ifin,
2257 const Standard_Boolean onFirst)
2259 Standard_Integer i, nbpnt = ifin-ideb+1;
2260 TColgp_Array1OfPnt2d poles(1,nbpnt);
2261 TColStd_Array1OfReal knots(1,nbpnt);
2262 TColStd_Array1OfInteger mults(1,nbpnt);
2263 Standard_Integer ipidebm1;
2265 for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) {
2268 theWLine->Point(ipidebm1).ParametersOnS1(U, V);
2270 theWLine->Point(ipidebm1).ParametersOnS2(U, V);
2271 poles(i).SetCoord(U, V);
2275 mults(1) = mults(nbpnt) = 2;
2277 return new Geom2d_BSplineCurve(poles,knots,mults,1);
2279 //=======================================================================
2280 //function : PrepareLines3D
2282 //=======================================================================
2283 void IntTools_FaceFace::PrepareLines3D(const Standard_Boolean bToSplit)
2285 Standard_Integer i, aNbCurves;
2286 GeomAbs_SurfaceType aType1, aType2;
2287 IntTools_SequenceOfCurves aNewCvs;
2289 // 1. Treatment closed curves
2290 aNbCurves=mySeqOfCurve.Length();
2291 for (i=1; i<=aNbCurves; ++i) {
2292 const IntTools_Curve& aIC=mySeqOfCurve(i);
2295 Standard_Integer j, aNbC;
2296 IntTools_SequenceOfCurves aSeqCvs;
2298 aNbC=IntTools_Tools::SplitCurve(aIC, aSeqCvs);
2300 for (j=1; j<=aNbC; ++j) {
2301 const IntTools_Curve& aICNew=aSeqCvs(j);
2302 aNewCvs.Append(aICNew);
2306 aNewCvs.Append(aIC);
2310 aNewCvs.Append(aIC);
2314 // 2. Plane\Cone intersection when we had 4 curves
2315 aType1=myHS1->GetType();
2316 aType2=myHS2->GetType();
2317 aNbCurves=aNewCvs.Length();
2319 if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone) ||
2320 (aType2==GeomAbs_Plane && aType1==GeomAbs_Cone)) {
2322 GeomAbs_CurveType aCType1;
2324 aCType1=aNewCvs(1).Type();
2325 if (aCType1==GeomAbs_Line) {
2326 IntTools_SequenceOfCurves aSeqIn, aSeqOut;
2328 for (i=1; i<=aNbCurves; ++i) {
2329 const IntTools_Curve& aIC=aNewCvs(i);
2333 IntTools_Tools::RejectLines(aSeqIn, aSeqOut);
2336 aNbCurves=aSeqOut.Length();
2337 for (i=1; i<=aNbCurves; ++i) {
2338 const IntTools_Curve& aIC=aSeqOut(i);
2339 aNewCvs.Append(aIC);
2343 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone)...
2345 // 3. Fill mySeqOfCurve
2346 mySeqOfCurve.Clear();
2347 aNbCurves=aNewCvs.Length();
2348 for (i=1; i<=aNbCurves; ++i) {
2349 const IntTools_Curve& aIC=aNewCvs(i);
2350 mySeqOfCurve.Append(aIC);
2353 //=======================================================================
2354 //function : CorrectSurfaceBoundaries
2356 //=======================================================================
2357 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
2358 const Standard_Real theTolerance,
2359 Standard_Real& theumin,
2360 Standard_Real& theumax,
2361 Standard_Real& thevmin,
2362 Standard_Real& thevmax)
2364 Standard_Boolean enlarge, isuperiodic, isvperiodic;
2365 Standard_Real uinf, usup, vinf, vsup, delta;
2366 GeomAbs_SurfaceType aType;
2367 Handle(Geom_Surface) aSurface;
2369 aSurface = BRep_Tool::Surface(theFace);
2370 aSurface->Bounds(uinf, usup, vinf, vsup);
2371 delta = theTolerance;
2372 enlarge = Standard_False;
2374 GeomAdaptor_Surface anAdaptorSurface(aSurface);
2376 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
2377 Handle(Geom_Surface) aBasisSurface =
2378 (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface))->BasisSurface();
2380 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2381 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2386 if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2387 Handle(Geom_Surface) aBasisSurface =
2388 (Handle(Geom_OffsetSurface)::DownCast(aSurface))->BasisSurface();
2390 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2391 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2396 isuperiodic = anAdaptorSurface.IsUPeriodic();
2397 isvperiodic = anAdaptorSurface.IsVPeriodic();
2399 aType=anAdaptorSurface.GetType();
2400 if((aType==GeomAbs_BezierSurface) ||
2401 (aType==GeomAbs_BSplineSurface) ||
2402 (aType==GeomAbs_SurfaceOfExtrusion) ||
2403 (aType==GeomAbs_SurfaceOfRevolution)) {
2404 enlarge=Standard_True;
2407 if(!isuperiodic && enlarge) {
2409 if((theumin - uinf) > delta )
2415 if((usup - theumax) > delta )
2421 if(!isvperiodic && enlarge) {
2422 if((thevmin - vinf) > delta ) {
2428 if((vsup - thevmax) > delta ) {
2437 Standard_Integer aNbP;
2438 Standard_Real aXP, dXfact, aXmid, aX1, aX2, aTolPA;
2440 aTolPA=Precision::Angular();
2443 aXP=anAdaptorSurface.UPeriod();
2444 dXfact=theumax-theumin;
2445 if (dXfact-aTolPA>aXP) {
2446 aXmid=0.5*(theumax+theumin);
2447 aNbP=RealToInt(aXmid/aXP);
2452 if (theumin>aTolPA) {
2453 aX1=theumin+aNbP*aXP;
2466 aXP=anAdaptorSurface.VPeriod();
2467 dXfact=thevmax-thevmin;
2468 if (dXfact-aTolPA>aXP) {
2469 aXmid=0.5*(thevmax+thevmin);
2470 aNbP=RealToInt(aXmid/aXP);
2475 if (thevmin>aTolPA) {
2476 aX1=thevmin+aNbP*aXP;
2489 if(isuperiodic || isvperiodic) {
2490 Standard_Boolean correct = Standard_False;
2491 Standard_Boolean correctU = Standard_False;
2492 Standard_Boolean correctV = Standard_False;
2494 TopExp_Explorer anExp;
2496 for(anExp.Init(theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
2497 if(BRep_Tool::IsClosed(TopoDS::Edge(anExp.Current()), theFace)) {
2498 correct = Standard_True;
2500 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
2502 for(Standard_Integer i = 0; i < 2; i++) {
2504 anEdge.Orientation(TopAbs_FORWARD);
2507 anEdge.Orientation(TopAbs_REVERSED);
2509 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l);
2511 if(aCurve.IsNull()) {
2512 correct = Standard_False;
2515 Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve);
2517 if(aLine.IsNull()) {
2518 correct = Standard_False;
2521 gp_Dir2d anUDir(1., 0.);
2522 gp_Dir2d aVDir(0., 1.);
2523 Standard_Real anAngularTolerance = Precision::Angular();
2525 correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance);
2526 correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance);
2528 gp_Pnt2d pp1 = aCurve->Value(f);
2530 gp_Pnt2d pp2 = aCurve->Value(l);
2539 Standard_Real umin, vmin, umax, vmax;
2540 aBox.Get(umin, vmin, umax, vmax);
2542 if(isuperiodic && correctU) {
2547 if(theumax > umax) {
2551 if(isvperiodic && correctV) {
2563 // The block is dedicated to determine whether WLine [ifprm, ilprm]
2564 // crosses the degenerated zone on each given surface or not.
2565 // If Yes -> We will not use info about surfaces during approximation
2566 // because inside degenerated zone of the surface the approx. algo.
2567 // uses wrong values of normal, etc., and resulting curve will have
2568 // oscillations that we would not like to have.
2569 // PKV Tue Feb 12 2002
2573 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2574 const Handle(Geom_Surface)& aS,
2575 const Standard_Integer iDir);
2577 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2578 const TopoDS_Face& aF1,
2579 const TopoDS_Face& aF2);
2580 //=======================================================================
2581 //function : NotUseSurfacesForApprox
2583 //=======================================================================
2584 Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1,
2585 const TopoDS_Face& aF2,
2586 const Handle(IntPatch_WLine)& WL,
2587 const Standard_Integer ifprm,
2588 const Standard_Integer ilprm)
2590 Standard_Boolean bPInDZ;
2592 Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve();
2594 const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm);
2595 bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2);
2600 const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm);
2601 bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2);
2605 //=======================================================================
2606 //function : IsPointInDegeneratedZone
2608 //=======================================================================
2609 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2610 const TopoDS_Face& aF1,
2611 const TopoDS_Face& aF2)
2614 Standard_Boolean bFlag=Standard_True;
2615 Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22;
2616 Standard_Real U1, V1, U2, V2, aDelta, aD;
2619 Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1);
2620 aS1->Bounds(US11, US12, VS11, VS12);
2621 GeomAdaptor_Surface aGAS1(aS1);
2623 Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2);
2624 aS1->Bounds(US21, US22, VS21, VS22);
2625 GeomAdaptor_Surface aGAS2(aS2);
2627 //const gp_Pnt& aP=aP2S.Value();
2628 aP2S.Parameters(U1, V1, U2, V2);
2632 aD=aGAS1.UResolution(aDelta);
2633 aP2d.SetCoord(U1, V1);
2634 if (fabs(U1-US11) < aD) {
2635 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2640 if (fabs(U1-US12) < aD) {
2641 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2646 aD=aGAS1.VResolution(aDelta);
2647 if (fabs(V1-VS11) < aDelta) {
2648 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2653 if (fabs(V1-VS12) < aDelta) {
2654 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2660 aD=aGAS2.UResolution(aDelta);
2661 aP2d.SetCoord(U2, V2);
2662 if (fabs(U2-US21) < aDelta) {
2663 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2668 if (fabs(U2-US22) < aDelta) {
2669 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2674 aD=aGAS2.VResolution(aDelta);
2675 if (fabs(V2-VS21) < aDelta) {
2676 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2681 if (fabs(V2-VS22) < aDelta) {
2682 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2690 //=======================================================================
2691 //function : IsDegeneratedZone
2693 //=======================================================================
2694 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2695 const Handle(Geom_Surface)& aS,
2696 const Standard_Integer iDir)
2698 Standard_Boolean bFlag=Standard_True;
2699 Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD;
2700 Standard_Real aXm, aYm, aXb, aYb, aXe, aYe;
2701 aS->Bounds(US1, US2, VS1, VS2);
2703 gp_Pnt aPm, aPb, aPe;
2708 aS->D0(aXm, aYm, aPm);
2725 aS->D0(aXb, aYb, aPb);
2726 aS->D0(aXe, aYe, aPe);
2728 d1=aPm.Distance(aPb);
2729 d2=aPm.Distance(aPe);
2730 if (d1 < dD && d2 < dD) {
2747 aS->D0(aXb, aYb, aPb);
2748 aS->D0(aXe, aYe, aPe);
2750 d1=aPm.Distance(aPb);
2751 d2=aPm.Distance(aPe);
2752 if (d1 < dD && d2 < dD) {
2760 //=========================================================================
2761 // static function : ComputePurgedWLine
2762 // purpose : Removes equal points (leave one of equal points) from theWLine
2763 // and recompute vertex parameters.
2764 // Returns new WLine or null WLine if the number
2765 // of the points is less than 2.
2766 //=========================================================================
2767 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine) {
2769 Standard_Integer i, k, v, nb, nbvtx;
2770 Handle(IntPatch_WLine) aResult;
2771 nbvtx = theWLine->NbVertex();
2772 nb = theWLine->NbPnts();
2774 const IntSurf_PntOn2S& p1 = theWLine->Point(1);
2775 const IntSurf_PntOn2S& p2 = theWLine->Point(2);
2776 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
2781 Handle(IntPatch_WLine) aLocalWLine;
2782 Handle(IntPatch_WLine) aTmpWLine = theWLine;
2783 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
2784 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2785 for(i = 1; i <= nb; i++) {
2786 aLineOn2S->Add(theWLine->Point(i));
2789 for(v = 1; v <= nbvtx; v++) {
2790 aLocalWLine->AddVertex(theWLine->Vertex(v));
2793 for(i = 1; i <= aLineOn2S->NbPoints(); i++) {
2794 Standard_Integer aStartIndex = i + 1;
2795 Standard_Integer anEndIndex = i + 5;
2796 nb = aLineOn2S->NbPoints();
2797 anEndIndex = (anEndIndex > nb) ? nb : anEndIndex;
2799 if((aStartIndex > nb) || (anEndIndex <= 1)) {
2804 while(k <= anEndIndex) {
2807 IntSurf_PntOn2S p1 = aLineOn2S->Value(i);
2808 IntSurf_PntOn2S p2 = aLineOn2S->Value(k);
2810 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
2811 aTmpWLine = aLocalWLine;
2812 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2814 for(v = 1; v <= aTmpWLine->NbVertex(); v++) {
2815 IntPatch_Point aVertex = aTmpWLine->Vertex(v);
2816 Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine();
2818 if(avertexindex >= k) {
2819 aVertex.SetParameter(aVertex.ParameterOnLine() - 1.);
2821 aLocalWLine->AddVertex(aVertex);
2823 aLineOn2S->RemovePoint(k);
2832 if(aLineOn2S->NbPoints() > 1) {
2833 aResult = aLocalWLine;
2838 //=======================================================================
2841 //=======================================================================
2842 void TolR3d(const TopoDS_Face& aF1,
2843 const TopoDS_Face& aF2,
2844 Standard_Real& myTolReached3d)
2846 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
2848 aTolTresh=2.999999e-3;
2849 aTolF1 = BRep_Tool::Tolerance(aF1);
2850 aTolF2 = BRep_Tool::Tolerance(aF2);
2851 aTolFMax=Max(aTolF1, aTolF2);
2853 if (aTolFMax>aTolTresh) {
2854 myTolReached3d=aTolFMax;
2857 //=======================================================================
2858 //function : AdjustPeriodic
2860 //=======================================================================
2861 Standard_Real AdjustPeriodic(const Standard_Real theParameter,
2862 const Standard_Real parmin,
2863 const Standard_Real parmax,
2864 const Standard_Real thePeriod,
2865 Standard_Real& theOffset)
2867 Standard_Real aresult;
2870 aresult = theParameter;
2871 while(aresult < parmin) {
2872 aresult += thePeriod;
2873 theOffset += thePeriod;
2876 while(aresult > parmax) {
2877 aresult -= thePeriod;
2878 theOffset -= thePeriod;
2882 //=======================================================================
2883 //function : IsPointOnBoundary
2885 //=======================================================================
2886 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
2887 const Standard_Real theFirstBoundary,
2888 const Standard_Real theSecondBoundary,
2889 const Standard_Real theResolution,
2890 Standard_Boolean& IsOnFirstBoundary)
2892 Standard_Boolean bRet;
2894 Standard_Real adist;
2896 bRet=Standard_False;
2897 for(i = 0; i < 2; ++i) {
2898 IsOnFirstBoundary = (i == 0);
2899 if (IsOnFirstBoundary) {
2900 adist = fabs(theParameter - theFirstBoundary);
2903 adist = fabs(theParameter - theSecondBoundary);
2905 if(adist < theResolution) {
2911 // ------------------------------------------------------------------------------------------------
2912 // static function: FindPoint
2914 // ------------------------------------------------------------------------------------------------
2915 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
2916 const gp_Pnt2d& theLastPoint,
2917 const Standard_Real theUmin,
2918 const Standard_Real theUmax,
2919 const Standard_Real theVmin,
2920 const Standard_Real theVmax,
2921 gp_Pnt2d& theNewPoint) {
2923 gp_Vec2d aVec(theFirstPoint, theLastPoint);
2924 Standard_Integer i = 0, j = 0;
2926 for(i = 0; i < 4; i++) {
2927 gp_Vec2d anOtherVec;
2928 gp_Vec2d anOtherVecNormal;
2929 gp_Pnt2d aprojpoint = theLastPoint;
2932 anOtherVec.SetX(0.);
2933 anOtherVec.SetY(1.);
2934 anOtherVecNormal.SetX(1.);
2935 anOtherVecNormal.SetY(0.);
2938 aprojpoint.SetX(theUmin);
2940 aprojpoint.SetX(theUmax);
2943 anOtherVec.SetX(1.);
2944 anOtherVec.SetY(0.);
2945 anOtherVecNormal.SetX(0.);
2946 anOtherVecNormal.SetY(1.);
2949 aprojpoint.SetY(theVmin);
2951 aprojpoint.SetY(theVmax);
2953 gp_Vec2d anormvec = aVec;
2954 anormvec.Normalize();
2955 RefineVector(anormvec);
2956 Standard_Real adot1 = anormvec.Dot(anOtherVecNormal);
2958 if(fabs(adot1) < Precision::Angular())
2960 Standard_Real adist = 0.;
2961 Standard_Boolean bIsOut = Standard_False;
2964 adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax);
2965 bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax);
2968 adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax);
2969 bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax);
2971 Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1;
2973 for(j = 0; j < 2; j++) {
2974 anoffset = (j == 0) ? anoffset : -anoffset;
2975 gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset));
2976 gp_Vec2d acurvec(theLastPoint, acurpoint);
2980 Standard_Real aDotX, anAngleX;
2982 aDotX = aVec.Dot(acurvec);
2983 anAngleX = aVec.Angle(acurvec);
2985 if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) {
2987 if((acurpoint.Y() >= theVmin) &&
2988 (acurpoint.Y() <= theVmax)) {
2989 theNewPoint = acurpoint;
2990 return Standard_True;
2994 if((acurpoint.X() >= theUmin) &&
2995 (acurpoint.X() <= theUmax)) {
2996 theNewPoint = acurpoint;
2997 return Standard_True;
3003 return Standard_False;
3007 // ------------------------------------------------------------------------------------------------
3008 // static function: FindPoint
3009 // purpose: Find point on the boundary of radial tangent zone
3010 // ------------------------------------------------------------------------------------------------
3011 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3012 const gp_Pnt2d& theLastPoint,
3013 const Standard_Real theUmin,
3014 const Standard_Real theUmax,
3015 const Standard_Real theVmin,
3016 const Standard_Real theVmax,
3017 const gp_Pnt2d& theTanZoneCenter,
3018 const Standard_Real theZoneRadius,
3019 Handle(GeomAdaptor_HSurface) theGASurface,
3020 gp_Pnt2d& theNewPoint) {
3021 theNewPoint = theLastPoint;
3023 if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) )
3024 return Standard_False;
3026 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3027 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3029 Standard_Real aRadius = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3030 gp_Ax22d anAxis( theTanZoneCenter, gp_Dir2d(1, 0), gp_Dir2d(0, 1) );
3031 gp_Circ2d aCircle( anAxis, aRadius );
3034 gp_Vec2d aDir( theLastPoint.XY() - theFirstPoint.XY() );
3035 Standard_Real aLength = aDir.Magnitude();
3036 if ( aLength <= gp::Resolution() )
3037 return Standard_False;
3038 gp_Lin2d aLine( theFirstPoint, aDir );
3041 Handle(Geom2d_Line) aCLine = new Geom2d_Line( aLine );
3042 Handle(Geom2d_TrimmedCurve) aC1 = new Geom2d_TrimmedCurve( aCLine, 0, aLength );
3043 Handle(Geom2d_Circle) aC2 = new Geom2d_Circle( aCircle );
3045 Standard_Real aTol = aRadius * 0.001;
3046 aTol = ( aTol < Precision::PConfusion() ) ? Precision::PConfusion() : aTol;
3048 Geom2dAPI_InterCurveCurve anIntersector;
3049 anIntersector.Init( aC1, aC2, aTol );
3051 if ( anIntersector.NbPoints() == 0 )
3052 return Standard_False;
3054 Standard_Boolean aFound = Standard_False;
3055 Standard_Real aMinDist = aLength * aLength;
3056 Standard_Integer i = 0;
3057 for ( i = 1; i <= anIntersector.NbPoints(); i++ ) {
3058 gp_Pnt2d aPInt = anIntersector.Point( i );
3059 if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) {
3060 if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) &&
3061 ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) {
3062 theNewPoint = aPInt;
3063 aFound = Standard_True;
3071 // ------------------------------------------------------------------------------------------------
3072 // static function: IsInsideTanZone
3073 // purpose: Check if point is inside a radial tangent zone
3074 // ------------------------------------------------------------------------------------------------
3075 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
3076 const gp_Pnt2d& theTanZoneCenter,
3077 const Standard_Real theZoneRadius,
3078 Handle(GeomAdaptor_HSurface) theGASurface) {
3080 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3081 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3082 Standard_Real aRadiusSQR = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3083 aRadiusSQR *= aRadiusSQR;
3084 if ( thePoint.SquareDistance( theTanZoneCenter ) <= aRadiusSQR )
3085 return Standard_True;
3086 return Standard_False;
3089 // ------------------------------------------------------------------------------------------------
3090 // static function: CheckTangentZonesExist
3091 // purpose: Check if tangent zone exists
3092 // ------------------------------------------------------------------------------------------------
3093 Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& theSurface1,
3094 const Handle(GeomAdaptor_HSurface)& theSurface2 )
3096 if ( ( theSurface1->GetType() != GeomAbs_Torus ) ||
3097 ( theSurface2->GetType() != GeomAbs_Torus ) )
3098 return Standard_False;
3100 gp_Torus aTor1 = theSurface1->Torus();
3101 gp_Torus aTor2 = theSurface2->Torus();
3103 if ( aTor1.Location().Distance( aTor2.Location() ) > Precision::Confusion() )
3104 return Standard_False;
3106 if ( ( fabs( aTor1.MajorRadius() - aTor2.MajorRadius() ) > Precision::Confusion() ) ||
3107 ( fabs( aTor1.MinorRadius() - aTor2.MinorRadius() ) > Precision::Confusion() ) )
3108 return Standard_False;
3110 if ( ( aTor1.MajorRadius() < aTor1.MinorRadius() ) ||
3111 ( aTor2.MajorRadius() < aTor2.MinorRadius() ) )
3112 return Standard_False;
3113 return Standard_True;
3116 // ------------------------------------------------------------------------------------------------
3117 // static function: ComputeTangentZones
3119 // ------------------------------------------------------------------------------------------------
3120 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
3121 const Handle(GeomAdaptor_HSurface)& theSurface2,
3122 const TopoDS_Face& theFace1,
3123 const TopoDS_Face& theFace2,
3124 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
3125 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
3126 Handle(TColStd_HArray1OfReal)& theResultRadius,
3127 const Handle(IntTools_Context)& aContext)
3129 Standard_Integer aResult = 0;
3130 if ( !CheckTangentZonesExist( theSurface1, theSurface2 ) )
3134 TColgp_SequenceOfPnt2d aSeqResultS1, aSeqResultS2;
3135 TColStd_SequenceOfReal aSeqResultRad;
3137 gp_Torus aTor1 = theSurface1->Torus();
3138 gp_Torus aTor2 = theSurface2->Torus();
3140 gp_Ax2 anax1( aTor1.Location(), aTor1.Axis().Direction() );
3141 gp_Ax2 anax2( aTor2.Location(), aTor2.Axis().Direction() );
3142 Standard_Integer j = 0;
3144 for ( j = 0; j < 2; j++ ) {
3145 Standard_Real aCoef = ( j == 0 ) ? -1 : 1;
3146 Standard_Real aRadius1 = fabs(aTor1.MajorRadius() + aCoef * aTor1.MinorRadius());
3147 Standard_Real aRadius2 = fabs(aTor2.MajorRadius() + aCoef * aTor2.MinorRadius());
3149 gp_Circ aCircle1( anax1, aRadius1 );
3150 gp_Circ aCircle2( anax2, aRadius2 );
3152 // roughly compute radius of tangent zone for perpendicular case
3153 Standard_Real aCriteria = Precision::Confusion() * 0.5;
3155 Standard_Real aT1 = aCriteria;
3156 Standard_Real aT2 = aCriteria;
3158 // internal tangency
3159 Standard_Real aR = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3160 //aT1 = aCriteria * aCriteria + aR * aR - ( aR - aCriteria ) * ( aR - aCriteria );
3161 aT1 = 2. * aR * aCriteria;
3165 // external tangency
3166 Standard_Real aRb = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3167 Standard_Real aRm = ( aRadius1 < aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3168 Standard_Real aDelta = aRb - aCriteria;
3170 aDelta -= aRm * aRm;
3171 aDelta /= 2. * (aRb - aRm);
3172 aDelta -= 0.5 * (aRb - aRm);
3174 aT1 = 2. * aRm * (aRm - aDelta);
3177 aCriteria = ( aT1 > aT2) ? aT1 : aT2;
3178 if ( aCriteria > 0 )
3179 aCriteria = sqrt( aCriteria );
3181 if ( aCriteria > 0.5 * aTor1.MinorRadius() ) {
3182 // too big zone -> drop to minimum
3183 aCriteria = Precision::Confusion();
3186 GeomAdaptor_Curve aC1( new Geom_Circle(aCircle1) );
3187 GeomAdaptor_Curve aC2( new Geom_Circle(aCircle2) );
3188 Extrema_ExtCC anExtrema(aC1, aC2, 0, 2. * M_PI, 0, 2. * M_PI,
3189 Precision::PConfusion(), Precision::PConfusion());
3191 if ( anExtrema.IsDone() ) {
3193 Standard_Integer i = 0;
3194 for ( i = 1; i <= anExtrema.NbExt(); i++ ) {
3195 if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria )
3198 Extrema_POnCurv P1, P2;
3199 anExtrema.Points( i, P1, P2 );
3201 Standard_Boolean bFoundResult = Standard_True;
3204 Standard_Integer surfit = 0;
3205 for ( surfit = 0; surfit < 2; surfit++ ) {
3206 GeomAPI_ProjectPointOnSurf& aProjector =
3207 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3209 gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value();
3210 aProjector.Perform(aP3d);
3212 if(!aProjector.IsDone())
3213 bFoundResult = Standard_False;
3215 if(aProjector.LowerDistance() > aCriteria) {
3216 bFoundResult = Standard_False;
3219 Standard_Real foundU = 0, foundV = 0;
3220 aProjector.LowerDistanceParameters(foundU, foundV);
3222 pr1 = gp_Pnt2d( foundU, foundV );
3224 pr2 = gp_Pnt2d( foundU, foundV );
3228 if ( bFoundResult ) {
3229 aSeqResultS1.Append( pr1 );
3230 aSeqResultS2.Append( pr2 );
3231 aSeqResultRad.Append( aCriteria );
3233 // torus is u and v periodic
3234 const Standard_Real twoPI = M_PI + M_PI;
3235 Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()};
3236 Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()};
3238 // iteration on period bounds
3239 for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) {
3240 Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI;
3241 Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI;
3243 // iteration on surfaces
3244 for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) {
3245 Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp;
3246 Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp;
3247 TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2;
3248 TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2;
3250 if (fabs(arr1[0] - aBound) < Precision::PConfusion()) {
3251 aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) );
3252 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3253 aSeqResultRad.Append( aCriteria );
3255 if (fabs(arr1[1] - aBound) < Precision::PConfusion()) {
3256 aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) );
3257 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3258 aSeqResultRad.Append( aCriteria );
3266 aResult = aSeqResultRad.Length();
3268 if ( aResult > 0 ) {
3269 theResultOnS1 = new TColgp_HArray1OfPnt2d( 1, aResult );
3270 theResultOnS2 = new TColgp_HArray1OfPnt2d( 1, aResult );
3271 theResultRadius = new TColStd_HArray1OfReal( 1, aResult );
3273 for ( Standard_Integer i = 1 ; i <= aResult; i++ ) {
3274 theResultOnS1->SetValue( i, aSeqResultS1.Value(i) );
3275 theResultOnS2->SetValue( i, aSeqResultS2.Value(i) );
3276 theResultRadius->SetValue( i, aSeqResultRad.Value(i) );
3282 // ------------------------------------------------------------------------------------------------
3283 // static function: AdjustByNeighbour
3285 // ------------------------------------------------------------------------------------------------
3286 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
3287 const gp_Pnt2d& theOriginalPoint,
3288 Handle(GeomAdaptor_HSurface) theGASurface) {
3290 gp_Pnt2d ap1 = theaNeighbourPoint;
3291 gp_Pnt2d ap2 = theOriginalPoint;
3293 if ( theGASurface->IsUPeriodic() ) {
3294 Standard_Real aPeriod = theGASurface->UPeriod();
3295 gp_Pnt2d aPTest = ap2;
3296 Standard_Real aSqDistMin = 1.e+100;
3298 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3299 aPTest.SetX( theOriginalPoint.X() + aPeriod * pIt );
3300 Standard_Real dd = ap1.SquareDistance( aPTest );
3302 if ( dd < aSqDistMin ) {
3308 if ( theGASurface->IsVPeriodic() ) {
3309 Standard_Real aPeriod = theGASurface->VPeriod();
3310 gp_Pnt2d aPTest = ap2;
3311 Standard_Real aSqDistMin = 1.e+100;
3313 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3314 aPTest.SetY( theOriginalPoint.Y() + aPeriod * pIt );
3315 Standard_Real dd = ap1.SquareDistance( aPTest );
3317 if ( dd < aSqDistMin ) {
3326 // ------------------------------------------------------------------------------------------------
3327 //function: DecompositionOfWLine
3329 // ------------------------------------------------------------------------------------------------
3330 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
3331 const Handle(GeomAdaptor_HSurface)& theSurface1,
3332 const Handle(GeomAdaptor_HSurface)& theSurface2,
3333 const TopoDS_Face& theFace1,
3334 const TopoDS_Face& theFace2,
3335 const IntTools_LineConstructor& theLConstructor,
3336 const Standard_Boolean theAvoidLConstructor,
3337 IntPatch_SequenceOfLine& theNewLines,
3338 Standard_Real& theReachedTol3d,
3339 const Handle(IntTools_Context)& aContext)
3342 Standard_Boolean bRet, bAvoidLineConstructor;
3343 Standard_Integer aNbPnts, aNbParts;
3345 bRet=Standard_False;
3346 aNbPnts=theWLine->NbPnts();
3347 bAvoidLineConstructor=theAvoidLConstructor;
3352 if (!bAvoidLineConstructor) {
3353 aNbParts=theLConstructor.NbParts();
3359 Standard_Boolean bIsPrevPointOnBoundary, bIsPointOnBoundary, bIsCurrentPointOnBoundary;
3360 Standard_Integer nblines, pit, i, j;
3362 TColStd_Array1OfListOfInteger anArrayOfLines(1, aNbPnts);
3363 TColStd_Array1OfInteger anArrayOfLineType(1, aNbPnts);
3364 TColStd_ListOfInteger aListOfPointIndex;
3366 Handle(TColgp_HArray1OfPnt2d) aTanZoneS1;
3367 Handle(TColgp_HArray1OfPnt2d) aTanZoneS2;
3368 Handle(TColStd_HArray1OfReal) aTanZoneRadius;
3369 Standard_Integer aNbZone = ComputeTangentZones( theSurface1, theSurface2, theFace1, theFace2,
3370 aTanZoneS1, aTanZoneS2, aTanZoneRadius, aContext);
3374 aTol=Precision::Confusion();
3376 bIsPrevPointOnBoundary=Standard_False;
3377 bIsPointOnBoundary=Standard_False;
3382 for(pit = 1; pit <= aNbPnts; ++pit) {
3383 Standard_Boolean bIsOnFirstBoundary, isperiodic;
3384 Standard_Real aResolution, aPeriod, alowerboundary, aupperboundary, U, V;
3385 Standard_Real aParameter, anoffset, anAdjustPar;
3386 Standard_Real umin, umax, vmin, vmax;
3388 bIsCurrentPointOnBoundary = Standard_False;
3389 const IntSurf_PntOn2S& aPoint = theWLine->Point(pit);
3392 for(i = 0; i < 2; ++i) {
3393 Handle(GeomAdaptor_HSurface) aGASurface = (!i) ? theSurface1 : theSurface2;
3394 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3396 aPoint.ParametersOnS1(U, V);
3399 aPoint.ParametersOnS2(U, V);
3402 for(j = 0; j < 2; j++) {
3403 isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3409 aResolution=aGASurface->UResolution(aTol);
3410 aPeriod=aGASurface->UPeriod();
3411 alowerboundary=umin;
3412 aupperboundary=umax;
3416 aResolution=aGASurface->VResolution(aTol);
3417 aPeriod=aGASurface->VPeriod();
3418 alowerboundary=vmin;
3419 aupperboundary=vmax;
3424 anAdjustPar = AdjustPeriodic(aParameter,
3430 bIsOnFirstBoundary = Standard_True;// ?
3432 IsPointOnBoundary(anAdjustPar,
3436 bIsOnFirstBoundary);
3438 if(bIsPointOnBoundary) {
3439 bIsCurrentPointOnBoundary = Standard_True;
3443 // check if a point belong to a tangent zone. Begin
3444 Standard_Integer zIt = 0;
3445 for ( zIt = 1; zIt <= aNbZone; zIt++ ) {
3446 gp_Pnt2d aPZone = (i == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3447 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3449 if ( IsInsideTanZone(gp_Pnt2d( U, V ), aPZone, aZoneRadius, aGASurface ) ) {
3450 // set boundary flag to split the curve by a tangent zone
3451 bIsPointOnBoundary = Standard_True;
3452 bIsCurrentPointOnBoundary = Standard_True;
3453 if ( theReachedTol3d < aZoneRadius ) {
3454 theReachedTol3d = aZoneRadius;
3460 }//for(j = 0; j < 2; j++) {
3462 if(bIsCurrentPointOnBoundary){
3465 }//for(i = 0; i < 2; ++i) {
3467 if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) {
3468 if(!aListOfPointIndex.IsEmpty()) {
3470 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3471 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3472 aListOfPointIndex.Clear();
3474 bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary;
3476 aListOfPointIndex.Append(pit);
3477 } //for(pit = 1; pit <= aNbPnts; ++pit) {
3479 if(!aListOfPointIndex.IsEmpty()) {
3481 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3482 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3483 aListOfPointIndex.Clear();
3487 return bRet; //Standard_False;
3491 // 2. Correct wlines.begin
3492 TColStd_Array1OfListOfInteger anArrayOfLineEnds(1, nblines);
3493 Handle(IntSurf_LineOn2S) aSeqOfPntOn2S = new IntSurf_LineOn2S();
3495 for(i = 1; i <= nblines; i++) {
3496 if(anArrayOfLineType.Value(i) != 0) {
3499 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3500 if(aListOfIndex.Extent() < 2) {
3503 TColStd_ListOfInteger aListOfFLIndex;
3505 for(j = 0; j < 2; j++) {
3506 Standard_Integer aneighbourindex = (j == 0) ? (i - 1) : (i + 1);
3508 if((aneighbourindex < 1) || (aneighbourindex > nblines))
3511 if(anArrayOfLineType.Value(aneighbourindex) == 0)
3513 const TColStd_ListOfInteger& aNeighbour = anArrayOfLines.Value(aneighbourindex);
3514 Standard_Integer anIndex = (j == 0) ? aNeighbour.Last() : aNeighbour.First();
3515 const IntSurf_PntOn2S& aPoint = theWLine->Point(anIndex);
3517 IntSurf_PntOn2S aNewP = aPoint;
3519 for(Standard_Integer surfit = 0; surfit < 2; surfit++) {
3521 Handle(GeomAdaptor_HSurface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2;
3522 Standard_Real umin=0., umax=0., vmin=0., vmax=0.;
3523 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3524 Standard_Real U=0., V=0.;
3527 aNewP.ParametersOnS1(U, V);
3529 aNewP.ParametersOnS2(U, V);
3530 Standard_Integer nbboundaries = 0;
3532 Standard_Boolean bIsNearBoundary = Standard_False;
3533 Standard_Integer aZoneIndex = 0;
3534 Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1
3535 Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1
3538 for(Standard_Integer parit = 0; parit < 2; parit++) {
3539 Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3541 Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
3542 Standard_Real alowerboundary = (parit == 0) ? umin : vmin;
3543 Standard_Real aupperboundary = (parit == 0) ? umax : vmax;
3545 Standard_Real aParameter = (parit == 0) ? U : V;
3546 Standard_Boolean bIsOnFirstBoundary = Standard_True;
3550 IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3551 if(bIsPointOnBoundary) {
3552 bIsUBoundary = (parit == 0);
3553 bIsFirstBoundary = bIsOnFirstBoundary;
3558 Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3559 Standard_Real anoffset = 0.;
3560 Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
3563 IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3564 if(bIsPointOnBoundary) {
3565 bIsUBoundary = (parit == 0);
3566 bIsFirstBoundary = bIsOnFirstBoundary;
3570 //check neighbourhood of boundary
3571 Standard_Real anEpsilon = aResolution * 100.;
3572 Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
3573 anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
3575 bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary,
3576 anEpsilon, bIsOnFirstBoundary);
3582 // check if a point belong to a tangent zone. Begin
3583 for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) {
3584 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3585 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3587 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3588 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3589 Standard_Real nU1, nV1;
3592 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3594 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3595 gp_Pnt2d ap1(nU1, nV1);
3596 gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface );
3599 if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) {
3601 bIsNearBoundary = Standard_True;
3602 if ( theReachedTol3d < aZoneRadius ) {
3603 theReachedTol3d = aZoneRadius;
3607 // check if a point belong to a tangent zone. End
3608 Standard_Boolean bComputeLineEnd = Standard_False;
3610 if(nbboundaries == 2) {
3612 bComputeLineEnd = Standard_True;
3615 else if(nbboundaries == 1) {
3616 Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3619 Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
3620 Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
3621 Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3622 Standard_Real aParameter = (bIsUBoundary) ? U : V;
3623 Standard_Real anoffset = 0.;
3624 Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
3626 Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
3627 Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
3628 anotherPar += anoffset;
3629 Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3630 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
3631 Standard_Real nU1, nV1;
3634 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3636 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3638 Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
3639 Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
3640 bComputeLineEnd = Standard_True;
3641 Standard_Boolean bCheckAngle1 = Standard_False;
3642 Standard_Boolean bCheckAngle2 = Standard_False;
3644 Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
3645 Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
3647 if(((adist1 - adist2) > Precision::PConfusion()) &&
3648 (adist2 < (aPeriod / 4.))) {
3649 bCheckAngle1 = Standard_True;
3650 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
3652 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3653 aNewP.SetValue((surfit == 0), anewU, anewV);
3654 bCheckAngle1 = Standard_False;
3657 else if(adist1 < (aPeriod / 4.)) {
3658 bCheckAngle2 = Standard_True;
3659 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
3661 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3662 bCheckAngle2 = Standard_False;
3666 if(bCheckAngle1 || bCheckAngle2) {
3667 // assume there are at least two points in line (see "if" above)
3668 Standard_Integer anindexother = aneighbourpointindex;
3670 while((anindexother <= aListOfIndex.Last()) && (anindexother >= aListOfIndex.First())) {
3671 anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
3672 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
3673 Standard_Real nU2, nV2;
3676 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3678 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3679 gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
3681 if(aVecOld.SquareMagnitude() <= (gp::Resolution() * gp::Resolution())) {
3685 Standard_Real anAngle = aNewVec.Angle(aVecOld);
3687 if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
3690 Standard_Real U1, U2, V1, V2;
3691 IntSurf_PntOn2S atmppoint = aNewP;
3692 atmppoint.SetValue((surfit == 0), anewU, anewV);
3693 atmppoint.Parameters(U1, V1, U2, V2);
3694 gp_Pnt P1 = theSurface1->Value(U1, V1);
3695 gp_Pnt P2 = theSurface2->Value(U2, V2);
3696 gp_Pnt P0 = aPoint.Value();
3698 if(P0.IsEqual(P1, aTol) &&
3699 P0.IsEqual(P2, aTol) &&
3700 P1.IsEqual(P2, aTol)) {
3701 bComputeLineEnd = Standard_False;
3702 aNewP.SetValue((surfit == 0), anewU, anewV);
3707 bComputeLineEnd = Standard_False;
3712 } // end while(anindexother...)
3716 else if ( bIsNearBoundary ) {
3717 bComputeLineEnd = Standard_True;
3720 if(bComputeLineEnd) {
3723 Standard_Boolean found = Standard_False;
3725 if ( bIsNearBoundary ) {
3726 // re-compute point near natural boundary or near tangent zone
3727 Standard_Real u1, v1, u2, v2;
3728 aNewP.Parameters( u1, v1, u2, v2 );
3730 anewpoint = gp_Pnt2d( u1, v1 );
3732 anewpoint = gp_Pnt2d( u2, v2 );
3734 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3735 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3736 Standard_Real nU1, nV1;
3739 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3741 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3742 gp_Pnt2d ap1(nU1, nV1);
3747 // exclude point from a tangent zone
3748 anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3749 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex);
3750 Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex);
3752 if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax,
3753 aPZone, aZoneRadius, aGASurface, ap2) ) {
3755 found = Standard_True;
3758 else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
3759 // re-compute point near boundary if shifted on a period
3760 ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3762 if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
3763 ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
3764 found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
3768 aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
3774 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3775 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3776 Standard_Real nU1, nV1;
3779 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3781 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3782 gp_Pnt2d ap1(nU1, nV1);
3783 gp_Pnt2d ap2(nU1, nV1);
3784 Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
3786 while((aneighbourpointindex2 <= aListOfIndex.Last()) && (aneighbourpointindex2 >= aListOfIndex.First())) {
3787 aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
3788 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
3789 Standard_Real nU2, nV2;
3792 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3794 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3798 if(ap1.SquareDistance(ap2) > (gp::Resolution() * gp::Resolution())) {
3802 found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
3807 Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
3808 GeomAPI_ProjectPointOnSurf& aProjector =
3809 (surfit == 0) ? aContext->ProjPS(theFace2) : aContext->ProjPS(theFace1);
3810 Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
3812 Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
3814 gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
3815 aProjector.Perform(aP3d);
3817 if(aProjector.IsDone()) {
3818 if(aProjector.LowerDistance() < aCriteria) {
3819 Standard_Real foundU = U, foundV = V;
3820 aProjector.LowerDistanceParameters(foundU, foundV);
3822 //Correction of projected coordinates. Begin
3823 //Note, it may be shifted on a period
3824 Standard_Integer aneindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3825 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
3826 Standard_Real nUn, nVn;
3829 aNeighbourPoint.ParametersOnS2(nUn, nVn);
3831 aNeighbourPoint.ParametersOnS1(nUn, nVn);
3832 gp_Pnt2d aNeighbour2d(nUn, nVn);
3833 gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
3834 foundU = anAdjustedPoint.X();
3835 foundV = anAdjustedPoint.Y();
3837 if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
3838 ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
3839 // attempt to roughly re-compute point
3840 foundU = ( foundU < umin ) ? umin : foundU;
3841 foundU = ( foundU > umax ) ? umax : foundU;
3842 foundV = ( foundV < vmin ) ? vmin : foundV;
3843 foundV = ( foundV > vmax ) ? vmax : foundV;
3845 GeomAPI_ProjectPointOnSurf& aProjector2 =
3846 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3848 aP3d = aSurfaceOther->Value(foundU, foundV);
3849 aProjector2.Perform(aP3d);
3851 if(aProjector2.IsDone()) {
3852 if(aProjector2.LowerDistance() < aCriteria) {
3853 Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
3854 aProjector2.LowerDistanceParameters(foundU2, foundV2);
3855 anewpoint.SetX(foundU2);
3856 anewpoint.SetY(foundV2);
3860 //Correction of projected coordinates. End
3863 aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
3865 aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
3871 aSeqOfPntOn2S->Add(aNewP);
3872 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
3874 anArrayOfLineEnds.SetValue(i, aListOfFLIndex);
3876 // Correct wlines.end
3878 // Split wlines.begin
3879 Standard_Integer nbiter;
3882 if (!bAvoidLineConstructor) {
3883 nbiter=theLConstructor.NbParts();
3886 for(j = 1; j <= nbiter; ++j) {
3887 Standard_Real fprm, lprm;
3888 Standard_Integer ifprm, ilprm;
3890 if(bAvoidLineConstructor) {
3892 ilprm = theWLine->NbPnts();
3895 theLConstructor.Part(j, fprm, lprm);
3896 ifprm = (Standard_Integer)fprm;
3897 ilprm = (Standard_Integer)lprm;
3900 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
3902 for(i = 1; i <= nblines; i++) {
3903 if(anArrayOfLineType.Value(i) != 0) {
3906 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3908 if(aListOfIndex.Extent() < 2) {
3911 const TColStd_ListOfInteger& aListOfFLIndex = anArrayOfLineEnds.Value(i);
3912 Standard_Boolean bhasfirstpoint = (aListOfFLIndex.Extent() == 2);
3913 Standard_Boolean bhaslastpoint = (aListOfFLIndex.Extent() == 2);
3915 if(!bhasfirstpoint && !aListOfFLIndex.IsEmpty()) {
3916 bhasfirstpoint = (i != 1);
3919 if(!bhaslastpoint && !aListOfFLIndex.IsEmpty()) {
3920 bhaslastpoint = (i != nblines);
3922 Standard_Boolean bIsFirstInside = ((ifprm >= aListOfIndex.First()) && (ifprm <= aListOfIndex.Last()));
3923 Standard_Boolean bIsLastInside = ((ilprm >= aListOfIndex.First()) && (ilprm <= aListOfIndex.Last()));
3925 if(!bIsFirstInside && !bIsLastInside) {
3926 if((ifprm < aListOfIndex.First()) && (ilprm > aListOfIndex.Last())) {
3927 // append whole line, and boundaries if neccesary
3928 if(bhasfirstpoint) {
3929 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
3932 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
3934 for(; anIt.More(); anIt.Next()) {
3935 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
3940 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
3944 // check end of split line (end is almost always)
3945 Standard_Integer aneighbour = i + 1;
3946 Standard_Boolean bIsEndOfLine = Standard_True;
3948 if(aneighbour <= nblines) {
3949 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
3951 if((anArrayOfLineType.Value(aneighbour) != 0) &&
3952 (aListOfNeighbourIndex.IsEmpty())) {
3953 bIsEndOfLine = Standard_False;
3958 if(aLineOn2S->NbPoints() > 1) {
3959 Handle(IntPatch_WLine) aNewWLine =
3960 new IntPatch_WLine(aLineOn2S, Standard_False);
3961 theNewLines.Append(aNewWLine);
3963 aLineOn2S = new IntSurf_LineOn2S();
3968 // end if(!bIsFirstInside && !bIsLastInside)
3970 if(bIsFirstInside && bIsLastInside) {
3971 // append inside points between ifprm and ilprm
3972 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
3974 for(; anIt.More(); anIt.Next()) {
3975 if((anIt.Value() < ifprm) || (anIt.Value() > ilprm))
3977 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
3983 if(bIsFirstInside) {
3984 // append points from ifprm to last point + boundary point
3985 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
3987 for(; anIt.More(); anIt.Next()) {
3988 if(anIt.Value() < ifprm)
3990 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
3995 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
3998 // check end of split line (end is almost always)
3999 Standard_Integer aneighbour = i + 1;
4000 Standard_Boolean bIsEndOfLine = Standard_True;
4002 if(aneighbour <= nblines) {
4003 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4005 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4006 (aListOfNeighbourIndex.IsEmpty())) {
4007 bIsEndOfLine = Standard_False;
4012 if(aLineOn2S->NbPoints() > 1) {
4013 Handle(IntPatch_WLine) aNewWLine =
4014 new IntPatch_WLine(aLineOn2S, Standard_False);
4015 theNewLines.Append(aNewWLine);
4017 aLineOn2S = new IntSurf_LineOn2S();
4020 // end if(bIsFirstInside)
4023 // append points from first boundary point to ilprm
4024 if(bhasfirstpoint) {
4025 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
4028 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4030 for(; anIt.More(); anIt.Next()) {
4031 if(anIt.Value() > ilprm)
4033 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4037 //end if(bIsLastInside)
4041 if(aLineOn2S->NbPoints() > 1) {
4042 Handle(IntPatch_WLine) aNewWLine =
4043 new IntPatch_WLine(aLineOn2S, Standard_False);
4044 theNewLines.Append(aNewWLine);
4049 return Standard_True;
4052 // ------------------------------------------------------------------------------------------------
4053 // static function: ParameterOutOfBoundary
4054 // purpose: Computes a new parameter for given curve. The corresponding 2d points
4055 // does not lay on any boundary of given faces
4056 // ------------------------------------------------------------------------------------------------
4057 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
4058 const Handle(Geom_Curve)& theCurve,
4059 const TopoDS_Face& theFace1,
4060 const TopoDS_Face& theFace2,
4061 const Standard_Real theOtherParameter,
4062 const Standard_Boolean bIncreasePar,
4063 Standard_Real& theNewParameter,
4064 const Handle(IntTools_Context)& aContext)
4066 Standard_Boolean bIsComputed = Standard_False;
4067 theNewParameter = theParameter;
4069 Standard_Real acurpar = theParameter;
4070 TopAbs_State aState = TopAbs_ON;
4071 Standard_Integer iter = 0;
4072 Standard_Real asumtol = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4073 Standard_Real adelta = asumtol * 0.1;
4074 adelta = (adelta < Precision::Confusion()) ? Precision::Confusion() : adelta;
4075 Handle(Geom_Surface) aSurf1 = BRep_Tool::Surface(theFace1);
4076 Handle(Geom_Surface) aSurf2 = BRep_Tool::Surface(theFace2);
4078 Standard_Real u1, u2, v1, v2;
4080 GeomAPI_ProjectPointOnSurf aPrj1;
4081 aSurf1->Bounds(u1, u2, v1, v2);
4082 aPrj1.Init(aSurf1, u1, u2, v1, v2);
4084 GeomAPI_ProjectPointOnSurf aPrj2;
4085 aSurf2->Bounds(u1, u2, v1, v2);
4086 aPrj2.Init(aSurf2, u1, u2, v1, v2);
4088 while(aState == TopAbs_ON) {
4093 gp_Pnt aPCurrent = theCurve->Value(acurpar);
4094 aPrj1.Perform(aPCurrent);
4095 Standard_Real U=0., V=0.;
4097 if(aPrj1.IsDone()) {
4098 aPrj1.LowerDistanceParameters(U, V);
4099 aState = aContext->StatePointFace(theFace1, gp_Pnt2d(U, V));
4102 if(aState != TopAbs_ON) {
4103 aPrj2.Perform(aPCurrent);
4105 if(aPrj2.IsDone()) {
4106 aPrj2.LowerDistanceParameters(U, V);
4107 aState = aContext->StatePointFace(theFace2, gp_Pnt2d(U, V));
4118 theNewParameter = acurpar;
4119 bIsComputed = Standard_True;
4122 if(acurpar >= theOtherParameter)
4123 theNewParameter = theOtherParameter;
4126 if(acurpar <= theOtherParameter)
4127 theNewParameter = theOtherParameter;
4133 //=======================================================================
4134 //function : IsCurveValid
4136 //=======================================================================
4137 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve)
4139 if(thePCurve.IsNull())
4140 return Standard_False;
4142 Standard_Real tolint = 1.e-10;
4143 Geom2dAdaptor_Curve PCA;
4144 IntRes2d_Domain PCD;
4145 Geom2dInt_GInter PCI;
4147 Standard_Real pf = 0., pl = 0.;
4148 gp_Pnt2d pntf, pntl;
4150 if(!thePCurve->IsClosed() && !thePCurve->IsPeriodic()) {
4151 pf = thePCurve->FirstParameter();
4152 pl = thePCurve->LastParameter();
4153 pntf = thePCurve->Value(pf);
4154 pntl = thePCurve->Value(pl);
4155 PCA.Load(thePCurve);
4156 if(!PCA.IsPeriodic()) {
4157 if(PCA.FirstParameter() > pf) pf = PCA.FirstParameter();
4158 if(PCA.LastParameter() < pl) pl = PCA.LastParameter();
4160 PCD.SetValues(pntf,pf,tolint,pntl,pl,tolint);
4161 PCI.Perform(PCA,PCD,tolint,tolint);
4163 if(PCI.NbPoints() > 0) {
4164 return Standard_False;
4168 return Standard_True;
4171 //=======================================================================
4172 //static function : ApproxWithPCurves
4173 //purpose : for bug 20964 only
4174 //=======================================================================
4175 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
4176 const gp_Sphere& theSph)
4178 Standard_Boolean bRes = Standard_True;
4179 Standard_Real R1 = theCyl.Radius(), R2 = theSph.Radius();
4181 if(R1 < 2.*R2) return bRes;
4183 gp_Lin anCylAx(theCyl.Axis());
4185 Standard_Real aDist = anCylAx.Distance(theSph.Location());
4186 Standard_Real aDRel = Abs(aDist - R1)/R2;
4188 if(aDRel > .2) return bRes;
4190 Standard_Real par = ElCLib::Parameter(anCylAx, theSph.Location());
4191 gp_Pnt aP = ElCLib::Value(par, anCylAx);
4192 gp_Vec aV(aP, theSph.Location());
4194 Standard_Real dd = aV.Dot(theSph.Position().XDirection());
4196 if(aDist < R1 && dd > 0.) return Standard_False;
4197 if(aDist > R1 && dd < 0.) return Standard_False;
4202 //=======================================================================
4203 //function : PerformPlanes
4205 //=======================================================================
4206 void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
4207 const Handle(GeomAdaptor_HSurface)& theS2,
4208 const Standard_Real TolAng,
4209 const Standard_Real TolTang,
4210 const Standard_Boolean theApprox1,
4211 const Standard_Boolean theApprox2,
4212 IntTools_SequenceOfCurves& theSeqOfCurve,
4213 Standard_Boolean& theTangentFaces)
4216 gp_Pln aPln1 = theS1->Surface().Plane();
4217 gp_Pln aPln2 = theS2->Surface().Plane();
4219 IntAna_QuadQuadGeo aPlnInter(aPln1, aPln2, TolAng, TolTang);
4221 if(!aPlnInter.IsDone()) {
4222 theTangentFaces = Standard_False;
4226 IntAna_ResultType aResType = aPlnInter.TypeInter();
4228 if(aResType == IntAna_Same) {
4229 theTangentFaces = Standard_True;
4233 theTangentFaces = Standard_False;
4235 if(aResType == IntAna_Empty) {
4239 gp_Lin aLin = aPlnInter.Line(1);
4241 ProjLib_Plane aProj;
4244 aProj.Project(aLin);
4245 gp_Lin2d aLin2d1 = aProj.Line();
4248 aProj.Project(aLin);
4249 gp_Lin2d aLin2d2 = aProj.Line();
4251 //classify line2d1 relatively first plane
4252 Standard_Real P11, P12;
4253 Standard_Boolean IsCrossed = ClassifyLin2d(theS1, aLin2d1, TolTang, P11, P12);
4254 if(!IsCrossed) return;
4255 //classify line2d2 relatively second plane
4256 Standard_Real P21, P22;
4257 IsCrossed = ClassifyLin2d(theS2, aLin2d2, TolTang, P21, P22);
4258 if(!IsCrossed) return;
4260 //Analysis of parametric intervals: must have common part
4262 if(P21 >= P12) return;
4263 if(P22 <= P11) return;
4265 Standard_Real pmin, pmax;
4266 pmin = Max(P11, P21);
4267 pmax = Min(P12, P22);
4269 if(pmax - pmin <= TolTang) return;
4271 Handle(Geom_Line) aGLin = new Geom_Line(aLin);
4273 IntTools_Curve aCurve;
4274 Handle(Geom_TrimmedCurve) aGTLin = new Geom_TrimmedCurve(aGLin, pmin, pmax);
4276 aCurve.SetCurve(aGTLin);
4279 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d1);
4280 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4283 Handle(Geom2d_Curve) H1;
4284 aCurve.SetFirstCurve2d(H1);
4287 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d2);
4288 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4291 Handle(Geom2d_Curve) H1;
4292 aCurve.SetFirstCurve2d(H1);
4295 theSeqOfCurve.Append(aCurve);
4299 //=======================================================================
4300 //function : ClassifyLin2d
4302 //=======================================================================
4303 static inline Standard_Boolean INTER(const Standard_Real d1,
4304 const Standard_Real d2,
4305 const Standard_Real tol)
4307 return (d1 > tol && d2 < -tol) ||
4308 (d1 < -tol && d2 > tol) ||
4309 ((d1 <= tol && d1 >= -tol) && (d2 > tol || d2 < -tol)) ||
4310 ((d2 <= tol && d2 >= -tol) && (d1 > tol || d1 < -tol));
4312 static inline Standard_Boolean COINC(const Standard_Real d1,
4313 const Standard_Real d2,
4314 const Standard_Real tol)
4316 return (d1 <= tol && d1 >= -tol) && (d2 <= tol && d2 >= -tol);
4318 Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
4319 const gp_Lin2d& theLin2d,
4320 const Standard_Real theTol,
4321 Standard_Real& theP1,
4322 Standard_Real& theP2)
4325 Standard_Real xmin, xmax, ymin, ymax, d1, d2, A, B, C;
4326 Standard_Real par[2];
4327 Standard_Integer nbi = 0;
4329 xmin = theS->Surface().FirstUParameter();
4330 xmax = theS->Surface().LastUParameter();
4331 ymin = theS->Surface().FirstVParameter();
4332 ymax = theS->Surface().LastVParameter();
4334 theLin2d.Coefficients(A, B, C);
4336 //xmin, ymin <-> xmin, ymax
4337 d1 = A*xmin + B*ymin + C;
4338 d2 = A*xmin + B*ymax + C;
4340 if(INTER(d1, d2, theTol)) {
4341 //Intersection with boundary
4342 Standard_Real y = -(C + A*xmin)/B;
4343 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, y));
4346 else if (COINC(d1, d2, theTol)) {
4347 //Coincidence with boundary
4348 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4349 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4355 if(fabs(par[0]-par[1]) > theTol) {
4356 theP1 = Min(par[0], par[1]);
4357 theP2 = Max(par[0], par[1]);
4358 return Standard_True;
4360 else return Standard_False;
4364 //xmin, ymax <-> xmax, ymax
4366 d2 = A*xmax + B*ymax + C;
4368 if(d1 > theTol || d1 < -theTol) {//to avoid checking of
4369 //coincidence with the same point
4370 if(INTER(d1, d2, theTol)) {
4371 Standard_Real x = -(C + B*ymax)/A;
4372 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymax));
4375 else if (COINC(d1, d2, theTol)) {
4376 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4377 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4384 if(fabs(par[0]-par[1]) > theTol) {
4385 theP1 = Min(par[0], par[1]);
4386 theP2 = Max(par[0], par[1]);
4387 return Standard_True;
4389 else return Standard_False;
4393 //xmax, ymax <-> xmax, ymin
4395 d2 = A*xmax + B*ymin + C;
4397 if(d1 > theTol || d1 < -theTol) {
4398 if(INTER(d1, d2, theTol)) {
4399 Standard_Real y = -(C + A*xmax)/B;
4400 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, y));
4403 else if (COINC(d1, d2, theTol)) {
4404 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4405 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4411 if(fabs(par[0]-par[1]) > theTol) {
4412 theP1 = Min(par[0], par[1]);
4413 theP2 = Max(par[0], par[1]);
4414 return Standard_True;
4416 else return Standard_False;
4419 //xmax, ymin <-> xmin, ymin
4421 d2 = A*xmin + B*ymin + C;
4423 if(d1 > theTol || d1 < -theTol) {
4424 if(INTER(d1, d2, theTol)) {
4425 Standard_Real x = -(C + B*ymin)/A;
4426 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymin));
4429 else if (COINC(d1, d2, theTol)) {
4430 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4431 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4437 if(fabs(par[0]-par[1]) > theTol) {
4438 theP1 = Min(par[0], par[1]);
4439 theP2 = Max(par[0], par[1]);
4440 return Standard_True;
4442 else return Standard_False;
4445 return Standard_False;
4449 //=======================================================================
4450 //function : ApproxParameters
4452 //=======================================================================
4453 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
4454 const Handle(GeomAdaptor_HSurface)& aHS2,
4455 Standard_Integer& iDegMin,
4456 Standard_Integer& iDegMax,
4457 Standard_Integer& iNbIter)
4460 GeomAbs_SurfaceType aTS1, aTS2;
4467 aTS1=aHS1->Surface().GetType();
4468 aTS2=aHS2->Surface().GetType();
4471 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4472 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4473 Standard_Real aRC, aRT, dR, aPC;
4474 gp_Cylinder aCylinder;
4477 aPC=Precision::Confusion();
4479 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4480 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4482 aRC=aCylinder.Radius();
4483 aRT=aTorus.MinorRadius();
4493 if (aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Cylinder) {
4497 //=======================================================================
4498 //function : Tolerances
4500 //=======================================================================
4501 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
4502 const Handle(GeomAdaptor_HSurface)& aHS2,
4503 Standard_Real& ,//aTolArc,
4504 Standard_Real& aTolTang,
4505 Standard_Real& ,//aUVMaxStep,
4506 Standard_Real& )//aDeflection)
4508 GeomAbs_SurfaceType aTS1, aTS2;
4510 aTS1=aHS1->Surface().GetType();
4511 aTS2=aHS2->Surface().GetType();
4514 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4515 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4516 Standard_Real aRC, aRT, dR, aPC;
4517 gp_Cylinder aCylinder;
4520 aPC=Precision::Confusion();
4522 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4523 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4525 aRC=aCylinder.Radius();
4526 aRT=aTorus.MinorRadius();
4533 aTolTang=0.1*aTolTang;
4537 //=======================================================================
4538 //function : SortTypes
4540 //=======================================================================
4541 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
4542 const GeomAbs_SurfaceType aType2)
4544 Standard_Boolean bRet;
4545 Standard_Integer aI1, aI2;
4547 bRet=Standard_False;
4549 aI1=IndexType(aType1);
4550 aI2=IndexType(aType2);
4556 //=======================================================================
4557 //function : IndexType
4559 //=======================================================================
4560 Standard_Integer IndexType(const GeomAbs_SurfaceType aType)
4562 Standard_Integer aIndex;
4566 if (aType==GeomAbs_Plane) {
4569 else if (aType==GeomAbs_Cylinder) {
4572 else if (aType==GeomAbs_Cone) {
4575 else if (aType==GeomAbs_Sphere) {
4578 else if (aType==GeomAbs_Torus) {
4581 else if (aType==GeomAbs_BezierSurface) {
4584 else if (aType==GeomAbs_BSplineSurface) {
4587 else if (aType==GeomAbs_SurfaceOfRevolution) {
4590 else if (aType==GeomAbs_SurfaceOfExtrusion) {
4593 else if (aType==GeomAbs_OffsetSurface) {
4596 else if (aType==GeomAbs_OtherSurface) {
4601 //=======================================================================
4602 //function : DumpWLine
4604 //=======================================================================
4605 void DumpWLine(const Handle(IntPatch_WLine)& aWLine)
4607 Standard_Integer i, aNbPnts;
4608 Standard_Real aX, aY, aZ, aU1, aV1, aU2, aV2;
4610 printf(" *WLine\n");
4611 aNbPnts=aWLine->NbPnts();
4612 for (i=1; i<=aNbPnts; ++i) {
4613 const IntSurf_PntOn2S aPntOn2S=aWLine->Point(i);
4614 const gp_Pnt& aP3D=aPntOn2S.Value();
4615 aP3D.Coord(aX, aY, aZ);
4616 aPntOn2S.Parameters(aU1, aV1, aU2, aV2);
4618 printf("point p_%d %lf %lf %lf\n", i, aX, aY, aZ);
4619 //printf("point p_%d %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf\n",
4620 // i, aX, aY, aZ, aU1, aV1, aU2, aV2);
4623 //=======================================================================
4624 //function : RefineVector
4626 //=======================================================================
4627 void RefineVector(gp_Vec2d& aV2D)
4629 Standard_Integer k,m;
4630 Standard_Real aC[2], aEps, aR1, aR2, aNum;
4636 aV2D.Coord(aC[0], aC[1]);
4638 for (k=0; k<2; ++k) {
4641 if (aNum>aR1 && aNum<aR2) {
4652 aV2D.SetCoord(aC[0], aC[1]);
4654 //=======================================================================
4655 //function : MaxSquareDistance
4657 //=======================================================================
4658 Standard_Real MaxSquareDistance (const Standard_Real aT,
4659 const Handle(Geom_Curve)& aC3D,
4660 const Handle(Geom2d_Curve)& aC2D1,
4661 const Handle(Geom2d_Curve)& aC2D2,
4662 const Handle(GeomAdaptor_HSurface) myHS1,
4663 const Handle(GeomAdaptor_HSurface) myHS2,
4664 const TopoDS_Face& aF1,
4665 const TopoDS_Face& aF2,
4666 const Handle(IntTools_Context)& aCtx)
4668 Standard_Boolean bIsDone;
4670 Standard_Real aU, aV, aD2Max, aD2;
4677 if (aC3D.IsNull()) {
4681 for (i=0; i<2; ++i) {
4682 const Handle(GeomAdaptor_HSurface)& aGHS=(!i) ? myHS1 : myHS2;
4683 const TopoDS_Face &aF=(!i) ? aF1 : aF2;
4684 const Handle(Geom2d_Curve)& aC2D=(!i) ? aC2D1 : aC2D2;
4686 if (!aC2D.IsNull()) {
4689 aGHS->D0(aU, aV, aPS);
4690 aD2=aP.SquareDistance(aPS);
4696 GeomAPI_ProjectPointOnSurf& aProjector=aCtx->ProjPS(aF);
4698 aProjector.Perform(aP);
4699 bIsDone=aProjector.IsDone();
4701 aProjector.LowerDistanceParameters(aU, aV);
4702 aGHS->D0(aU, aV, aPS);
4703 aD2=aP.SquareDistance(aPS);