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 <IntTools_Curve.hxx>
115 #include <IntTools_Tools.hxx>
116 #include <IntTools_Tools.hxx>
117 #include <IntTools_TopolTool.hxx>
118 #include <IntTools_PntOnFace.hxx>
119 #include <IntTools_PntOn2Faces.hxx>
120 #include <BOPInt_Context.hxx>
121 #include <IntSurf_ListIteratorOfListOfPntOn2S.hxx>
124 void RefineVector(gp_Vec2d& aV2D);
127 void DumpWLine(const Handle(IntPatch_WLine)& aWLine);
130 void TolR3d(const TopoDS_Face& ,
134 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)&,
135 const Standard_Integer,
136 const Standard_Integer);
139 void Parameters(const Handle(GeomAdaptor_HSurface)&,
140 const Handle(GeomAdaptor_HSurface)&,
148 void BuildPCurves (Standard_Real f,Standard_Real l,Standard_Real& Tol,
149 const Handle (Geom_Surface)& S,
150 const Handle (Geom_Curve)& C,
151 Handle (Geom2d_Curve)& C2d);
154 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
155 const Standard_Real theTolerance,
156 Standard_Real& theumin,
157 Standard_Real& theumax,
158 Standard_Real& thevmin,
159 Standard_Real& thevmax);
161 Standard_Boolean NotUseSurfacesForApprox
162 (const TopoDS_Face& aF1,
163 const TopoDS_Face& aF2,
164 const Handle(IntPatch_WLine)& WL,
165 const Standard_Integer ifprm,
166 const Standard_Integer ilprm);
169 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine);
172 Standard_Real AdjustPeriodic(const Standard_Real theParameter,
173 const Standard_Real parmin,
174 const Standard_Real parmax,
175 const Standard_Real thePeriod,
176 Standard_Real& theOffset);
179 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
180 const Standard_Integer ideb,
181 const Standard_Integer ifin,
182 const Standard_Boolean onFirst);
185 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
186 const Handle(GeomAdaptor_HSurface)& theSurface1,
187 const Handle(GeomAdaptor_HSurface)& theSurface2,
188 const TopoDS_Face& theFace1,
189 const TopoDS_Face& theFace2,
190 const IntTools_LineConstructor& theLConstructor,
191 const Standard_Boolean theAvoidLConstructor,
192 IntPatch_SequenceOfLine& theNewLines,
193 Standard_Real& theReachedTol3d,
194 const Handle(BOPInt_Context)& );
197 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
198 const Handle(Geom_Curve)& theCurve,
199 const TopoDS_Face& theFace1,
200 const TopoDS_Face& theFace2,
201 const Standard_Real theOtherParameter,
202 const Standard_Boolean bIncreasePar,
203 Standard_Real& theNewParameter,
204 const Handle(BOPInt_Context)& );
207 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve);
210 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
211 const Standard_Real theFirstBoundary,
212 const Standard_Real theSecondBoundary,
213 const Standard_Real theResolution,
214 Standard_Boolean& IsOnFirstBoundary);
216 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
217 const gp_Pnt2d& theLastPoint,
218 const Standard_Real theUmin,
219 const Standard_Real theUmax,
220 const Standard_Real theVmin,
221 const Standard_Real theVmax,
222 gp_Pnt2d& theNewPoint);
226 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
227 const Handle(GeomAdaptor_HSurface)& theSurface2,
228 const TopoDS_Face& theFace1,
229 const TopoDS_Face& theFace2,
230 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
231 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
232 Handle(TColStd_HArray1OfReal)& theResultRadius,
233 const Handle(BOPInt_Context)& );
236 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
237 const gp_Pnt2d& theLastPoint,
238 const Standard_Real theUmin,
239 const Standard_Real theUmax,
240 const Standard_Real theVmin,
241 const Standard_Real theVmax,
242 const gp_Pnt2d& theTanZoneCenter,
243 const Standard_Real theZoneRadius,
244 Handle(GeomAdaptor_HSurface) theGASurface,
245 gp_Pnt2d& theNewPoint);
248 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
249 const gp_Pnt2d& theTanZoneCenter,
250 const Standard_Real theZoneRadius,
251 Handle(GeomAdaptor_HSurface) theGASurface);
254 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
255 const gp_Pnt2d& theOriginalPoint,
256 Handle(GeomAdaptor_HSurface) theGASurface);
258 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
259 const gp_Sphere& theSph);
261 static void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
262 const Handle(GeomAdaptor_HSurface)& theS2,
263 const Standard_Real TolAng,
264 const Standard_Real TolTang,
265 const Standard_Boolean theApprox1,
266 const Standard_Boolean theApprox2,
267 IntTools_SequenceOfCurves& theSeqOfCurve,
268 Standard_Boolean& theTangentFaces);
270 static Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
271 const gp_Lin2d& theLin2d,
272 const Standard_Real theTol,
273 Standard_Real& theP1,
274 Standard_Real& theP2);
277 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
278 const Handle(GeomAdaptor_HSurface)& aHS2,
279 Standard_Integer& iDegMin,
280 Standard_Integer& iNbIter,
281 Standard_Integer& iDegMax);
284 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
285 const Handle(GeomAdaptor_HSurface)& aHS2,
286 Standard_Real& aTolArc,
287 Standard_Real& aTolTang,
288 Standard_Real& aUVMaxStep,
289 Standard_Real& aDeflection);
292 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
293 const GeomAbs_SurfaceType aType2);
295 Standard_Integer IndexType(const GeomAbs_SurfaceType aType);
299 Standard_Real MaxSquareDistance (const Standard_Real aT,
300 const Handle(Geom_Curve)& aC3D,
301 const Handle(Geom2d_Curve)& aC2D1,
302 const Handle(Geom2d_Curve)& aC2D2,
303 const Handle(GeomAdaptor_HSurface) myHS1,
304 const Handle(GeomAdaptor_HSurface) myHS2,
305 const TopoDS_Face& aF1,
306 const TopoDS_Face& aF2,
307 const Handle(BOPInt_Context)& aCtx);
310 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
311 const TopoDS_Face& aFace);
315 Standard_Real FindMaxSquareDistance (const Standard_Real aA,
316 const Standard_Real aB,
317 const Standard_Real aEps,
318 const Handle(Geom_Curve)& aC3D,
319 const Handle(Geom2d_Curve)& aC2D1,
320 const Handle(Geom2d_Curve)& aC2D2,
321 const Handle(GeomAdaptor_HSurface)& myHS1,
322 const Handle(GeomAdaptor_HSurface)& myHS2,
323 const TopoDS_Face& aF1,
324 const TopoDS_Face& aF2,
325 const Handle(BOPInt_Context)& aCtx);
327 //=======================================================================
330 //=======================================================================
331 IntTools_FaceFace::IntTools_FaceFace()
333 myIsDone=Standard_False;
334 myTangentFaces=Standard_False;
336 myHS1 = new GeomAdaptor_HSurface ();
337 myHS2 = new GeomAdaptor_HSurface ();
340 SetParameters(Standard_True, Standard_True, Standard_True, 1.e-07);
343 //=======================================================================
344 //function : SetContext
346 //=======================================================================
347 void IntTools_FaceFace::SetContext(const Handle(BOPInt_Context)& aContext)
351 //=======================================================================
354 //=======================================================================
355 const Handle(BOPInt_Context)& IntTools_FaceFace::Context()const
359 //=======================================================================
362 //=======================================================================
363 const TopoDS_Face& IntTools_FaceFace::Face1() const
367 //=======================================================================
370 //=======================================================================
371 const TopoDS_Face& IntTools_FaceFace::Face2() const
375 //=======================================================================
376 //function : TangentFaces
378 //=======================================================================
379 Standard_Boolean IntTools_FaceFace::TangentFaces() const
381 return myTangentFaces;
383 //=======================================================================
386 //=======================================================================
387 const IntTools_SequenceOfPntOn2Faces& IntTools_FaceFace::Points() const
391 //=======================================================================
394 //=======================================================================
395 Standard_Boolean IntTools_FaceFace::IsDone() const
399 //=======================================================================
400 //function : TolReached3d
402 //=======================================================================
403 Standard_Real IntTools_FaceFace::TolReached3d() const
405 return myTolReached3d;
407 //=======================================================================
409 //purpose : return lines of intersection
410 //=======================================================================
411 const IntTools_SequenceOfCurves& IntTools_FaceFace::Lines() const
413 StdFail_NotDone_Raise_if
415 "IntTools_FaceFace::Lines() => !myIntersector.IsDone()");
418 //=======================================================================
419 //function : TolReached2d
421 //=======================================================================
422 Standard_Real IntTools_FaceFace::TolReached2d() const
424 return myTolReached2d;
426 // =======================================================================
427 // function: SetParameters
429 // =======================================================================
430 void IntTools_FaceFace::SetParameters(const Standard_Boolean ToApproxC3d,
431 const Standard_Boolean ToApproxC2dOnS1,
432 const Standard_Boolean ToApproxC2dOnS2,
433 const Standard_Real ApproximationTolerance)
435 myApprox = ToApproxC3d;
436 myApprox1 = ToApproxC2dOnS1;
437 myApprox2 = ToApproxC2dOnS2;
438 myTolApprox = ApproximationTolerance;
440 //=======================================================================
443 //=======================================================================
444 void IntTools_FaceFace::SetList(IntSurf_ListOfPntOn2S& aListOfPnts)
446 myListOfPnts = aListOfPnts;
448 //=======================================================================
450 //purpose : intersect surfaces of the faces
451 //=======================================================================
452 void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
453 const TopoDS_Face& aF2)
455 Standard_Boolean hasCone, RestrictLine, bTwoPlanes, bReverse;
456 Standard_Integer aNbLin, aNbPnts, i, NbLinPP;
457 Standard_Real TolArc, TolTang, Deflection, UVMaxStep;
458 Standard_Real umin, umax, vmin, vmax;
459 Standard_Real aTolF1, aTolF2;
460 GeomAbs_SurfaceType aType1, aType2;
461 Handle(Geom_Surface) S1, S2;
462 Handle(IntTools_TopolTool) dom1, dom2;
463 BRepAdaptor_Surface aBAS1, aBAS2;
465 if (myContext.IsNull()) {
466 myContext=new BOPInt_Context;
469 mySeqOfCurve.Clear();
472 myIsDone = Standard_False;
474 hasCone = Standard_False;
475 bTwoPlanes = Standard_False;
480 aBAS1.Initialize(myFace1, Standard_False);
481 aBAS2.Initialize(myFace2, Standard_False);
482 aType1=aBAS1.GetType();
483 aType2=aBAS2.GetType();
485 bReverse=SortTypes(aType1, aType2);
489 aType1=aBAS2.GetType();
490 aType2=aBAS1.GetType();
492 if (myListOfPnts.Extent()) {
493 Standard_Real aU1,aV1,aU2,aV2;
494 IntSurf_ListIteratorOfListOfPntOn2S aItP2S;
496 aItP2S.Initialize(myListOfPnts);
497 for (; aItP2S.More(); aItP2S.Next()){
498 IntSurf_PntOn2S& aP2S=aItP2S.Value();
499 aP2S.Parameters(aU1,aV1,aU2,aV2);
500 aP2S.SetValue(aU2,aV2,aU1,aV1);
505 S1=BRep_Tool::Surface(myFace1);
506 S2=BRep_Tool::Surface(myFace2);
508 aTolF1=BRep_Tool::Tolerance(myFace1);
509 aTolF2=BRep_Tool::Tolerance(myFace2);
511 TolArc= aTolF1 + aTolF2;
515 if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
516 bTwoPlanes = Standard_True;
518 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
519 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
521 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
522 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
523 Standard_Real TolAng = 1.e-8;
524 PerformPlanes(myHS1, myHS2, TolAng, TolTang, myApprox1, myApprox2,
525 mySeqOfCurve, myTangentFaces);
527 myIsDone = Standard_True;
529 if(!myTangentFaces) {
531 NbLinPP = mySeqOfCurve.Length();
533 Standard_Real aTolFMax;
535 myTolReached3d = 1.e-7;
537 aTolFMax=Max(aTolF1, aTolF2);
539 if (aTolFMax>myTolReached3d) {
540 myTolReached3d=aTolFMax;
542 myTolReached2d = myTolReached3d;
545 Handle(Geom2d_Curve) aC2D1, aC2D2;
547 aNbLin=mySeqOfCurve.Length();
548 for (i=1; i<=aNbLin; ++i) {
549 IntTools_Curve& aIC=mySeqOfCurve(i);
550 aC2D1=aIC.FirstCurve2d();
551 aC2D2=aIC.SecondCurve2d();
553 aIC.SetFirstCurve2d(aC2D2);
554 aIC.SetSecondCurve2d(aC2D1);
560 }//if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){
562 if (aType1==GeomAbs_Plane &&
563 (aType2==GeomAbs_Cylinder ||
564 aType2==GeomAbs_Cone ||
565 aType2==GeomAbs_Torus)) {
566 Standard_Real dU, dV;
568 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
575 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
577 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
578 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
579 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
581 if( aType2==GeomAbs_Cone ) {
583 hasCone = Standard_True;
587 else if ((aType1==GeomAbs_Cylinder||
588 aType1==GeomAbs_Cone ||
589 aType1==GeomAbs_Torus) &&
590 aType2==GeomAbs_Plane) {
591 Standard_Real dU, dV;
593 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
594 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
595 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
597 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
604 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
606 if( aType1==GeomAbs_Cone ) {
608 hasCone = Standard_True;
614 BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax);
616 CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
618 myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax);
620 BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax);
622 CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax);
624 myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax);
627 dom1 = new IntTools_TopolTool(myHS1);
628 dom2 = new IntTools_TopolTool(myHS2);
630 myLConstruct.Load(dom1, dom2, myHS1, myHS2);
632 Deflection = (hasCone) ? 0.085 : 0.1;
635 Tolerances(myHS1, myHS2, TolArc, TolTang, UVMaxStep, Deflection);
637 myIntersector.SetTolerances(TolArc, TolTang, UVMaxStep, Deflection);
639 RestrictLine = Standard_False;
641 if((myHS1->IsUClosed() && !myHS1->IsUPeriodic()) ||
642 (myHS1->IsVClosed() && !myHS1->IsVPeriodic()) ||
643 (myHS2->IsUClosed() && !myHS2->IsUPeriodic()) ||
644 (myHS2->IsVClosed() && !myHS2->IsVPeriodic())) {
645 RestrictLine = Standard_True;
648 if(((aType1 != GeomAbs_BSplineSurface) &&
649 (aType1 != GeomAbs_BezierSurface) &&
650 (aType1 != GeomAbs_OtherSurface)) &&
651 ((aType2 != GeomAbs_BSplineSurface) &&
652 (aType2 != GeomAbs_BezierSurface) &&
653 (aType2 != GeomAbs_OtherSurface))) {
654 RestrictLine = Standard_True;
656 if ((aType1 == GeomAbs_Torus) ||
657 (aType2 == GeomAbs_Torus) ) {
658 myListOfPnts.Clear();
663 TopExp_Explorer aExp;
665 for(i = 0; (!RestrictLine) && (i < 2); i++) {
666 const TopoDS_Face& aF=(!i) ? myFace1 : myFace2;
667 aExp.Init(aF, TopAbs_EDGE);
668 for(; aExp.More(); aExp.Next()) {
669 const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
671 if(BRep_Tool::Degenerated(aE)) {
672 RestrictLine = Standard_True;
679 myIntersector.Perform(myHS1, dom1, myHS2, dom2,
681 myListOfPnts, RestrictLine);
683 myIsDone = myIntersector.IsDone();
685 myTangentFaces=myIntersector.TangentFaces();
686 if (myTangentFaces) {
691 myListOfPnts.Clear(); // to use LineConstructor
694 aNbLin = myIntersector.NbLines();
695 for (i=1; i<=aNbLin; ++i) {
696 MakeCurve(i, dom1, dom2);
699 ComputeTolReached3d();
702 Handle(Geom2d_Curve) aC2D1, aC2D2;
704 aNbLin=mySeqOfCurve.Length();
705 for (i=1; i<=aNbLin; ++i) {
706 IntTools_Curve& aIC=mySeqOfCurve(i);
707 aC2D1=aIC.FirstCurve2d();
708 aC2D2=aIC.SecondCurve2d();
710 aIC.SetFirstCurve2d(aC2D2);
711 aIC.SetSecondCurve2d(aC2D1);
716 Standard_Real U1,V1,U2,V2;
717 IntTools_PntOnFace aPntOnF1, aPntOnF2;
718 IntTools_PntOn2Faces aPntOn2Faces;
720 aNbPnts=myIntersector.NbPnts();
721 for (i=1; i<=aNbPnts; ++i) {
722 const IntSurf_PntOn2S& aISPnt=myIntersector.Point(i).PntOn2S();
723 const gp_Pnt& aPnt=aISPnt.Value();
724 aISPnt.Parameters(U1,V1,U2,V2);
725 aPntOnF1.Init(myFace1, aPnt, U1, V1);
726 aPntOnF2.Init(myFace2, aPnt, U2, V2);
729 aPntOn2Faces.SetP1(aPntOnF1);
730 aPntOn2Faces.SetP2(aPntOnF2);
733 aPntOn2Faces.SetP2(aPntOnF1);
734 aPntOn2Faces.SetP1(aPntOnF2);
736 myPnts.Append(aPntOn2Faces);
741 //=======================================================================
742 //function :ComputeTolReached3d
744 //=======================================================================
745 void IntTools_FaceFace::ComputeTolReached3d()
747 Standard_Integer aNbLin;
748 GeomAbs_SurfaceType aType1, aType2;
750 aNbLin=myIntersector.NbLines();
755 aType1=myHS1->Surface().GetType();
756 aType2=myHS2->Surface().GetType();
758 if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
760 Handle(IntPatch_Line) aIL1, aIL2;
761 IntPatch_IType aTL1, aTL2;
763 aIL1=myIntersector.Line(1);
764 aIL2=myIntersector.Line(2);
765 aTL1=aIL1->ArcType();
766 aTL2=aIL2->ArcType();
767 if (aTL1==IntPatch_Lin && aTL2==IntPatch_Lin) {
768 Standard_Real aD, aDTresh, dTol;
774 aL1=Handle(IntPatch_GLine)::DownCast(aIL1)->Line();
775 aL2=Handle(IntPatch_GLine)::DownCast(aIL2)->Line();
776 aD=aL1.Distance(aL2);
779 myTolReached3d=aD+dTol;
785 if (aNbLin) {// Check the distances
786 Standard_Integer i, aNbP, j ;
787 Standard_Real aT1, aT2, dT, aD2, aD2Max, aEps, aT11, aT12;
791 aNbLin=mySeqOfCurve.Length();
793 for (i=1; i<=aNbLin; ++i) {
794 const IntTools_Curve& aIC=mySeqOfCurve(i);
795 const Handle(Geom_Curve)& aC3D=aIC.Curve();
796 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
797 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
802 const Handle(Geom_BSplineCurve)& aBC=
803 Handle(Geom_BSplineCurve)::DownCast(aC3D);
808 aT1=aBC->FirstParameter();
809 aT2=aBC->LastParameter();
813 for (j=1; j<aNbP; ++j) {
816 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
817 myHS1, myHS2, myFace1, myFace2, myContext);
822 }//for (i=1; i<=aNbLin; ++i) {
824 myTolReached3d=sqrt(aD2Max);
826 }// if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) {
829 else if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
830 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
834 aTolF1 = BRep_Tool::Tolerance(myFace1);
835 aTolF2 = BRep_Tool::Tolerance(myFace2);
836 aTolFMax=Max(aTolF1, aTolF2);
838 if (aTolFMax>aTolTresh) {
839 myTolReached3d=aTolFMax;
841 }//if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) {
844 else if((aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) ||
845 (aType2 == GeomAbs_Cylinder && aType1 == GeomAbs_Plane)) {
847 const Handle(IntPatch_Line)& aIL1 = myIntersector.Line(1);
848 if(aIL1->ArcType() == IntPatch_Circle) {
849 gp_Circ aCir = Handle(IntPatch_GLine)::DownCast(aIL1)->Circle();
850 gp_XYZ aCirDir = aCir.Axis().Direction().XYZ();
853 if(aType1 == GeomAbs_Plane) {
854 aPln = myHS1->Surface().Plane();
857 aPln = myHS2->Surface().Plane();
859 aPlDir = aPln.Axis().Direction().XYZ();
860 Standard_Real cs = aCirDir*aPlDir;
861 if(cs < 0.) aPlDir.Reverse();
862 Standard_Real eps = 1.e-14;
863 if(!aPlDir.IsEqual(aCirDir, eps)) {
864 Standard_Integer aNbP = 11;
865 Standard_Real dt = 2.*M_PI / (aNbP - 1), t;
866 for(t = 0.; t < 2.*M_PI; t += dt) {
867 Standard_Real d = aPln.Distance(ElCLib::Value(t, aCir));
868 if(myTolReached3d < d) myTolReached3d = d;
870 myTolReached3d *= 1.1;
872 } //aIL1->ArcType() == IntPatch_Circle
874 } // aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane)
875 //End IFV Bug OCC20297
877 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
878 (aType2==GeomAbs_Plane && aType1==GeomAbs_Torus)) {
879 aNbLin=mySeqOfCurve.Length();
884 Standard_Integer i, aNbP;
885 Standard_Real aT, aT1, aT2, dT, aUT, aVT, aUP, aVP;
886 Standard_Real aDP, aDT, aDmax;
891 const IntTools_Curve& aIC=mySeqOfCurve(1);
892 const Handle(Geom_Curve)& aC3D=aIC.Curve();
893 const Handle(Geom_BSplineCurve)& aBS=
894 Handle(Geom_BSplineCurve)::DownCast(aC3D);
899 aT1=aBS->FirstParameter();
900 aT2=aBS->LastParameter();
902 aPln =(aType1==GeomAbs_Plane) ? myHS1->Plane() : myHS2->Plane();
903 aTorus=(aType1==GeomAbs_Plane) ? myHS2->Torus() : myHS1->Torus();
907 dT=(aT2-aT1)/(aNbP-1);
908 for (i=0; i<aNbP; ++i) {
916 ElSLib::Parameters(aPln, aP, aUP, aVP);
917 aPP=ElSLib::Value(aUP, aVP, aPln);
918 aDP=aP.SquareDistance(aPP);
923 ElSLib::Parameters(aTorus, aP, aUT, aVT);
924 aPT=ElSLib::Value(aUT, aVT, aTorus);
925 aDT=aP.SquareDistance(aPT);
931 if (aDmax > myTolReached3d*myTolReached3d) {
932 myTolReached3d=sqrt(aDmax);
933 myTolReached3d=1.1*myTolReached3d;
935 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
937 else if ((aType1==GeomAbs_SurfaceOfRevolution && aType2==GeomAbs_Cylinder) ||
938 (aType2==GeomAbs_SurfaceOfRevolution && aType1==GeomAbs_Cylinder)) {
939 Standard_Integer i, j, aNbP;
940 Standard_Real aT, aT1, aT2, dT, aD2max, aD2;
942 aNbLin=mySeqOfCurve.Length();
946 for (i=1; i<=aNbLin; ++i) {
947 const IntTools_Curve& aIC=mySeqOfCurve(i);
948 const Handle(Geom_Curve)& aC3D=aIC.Curve();
949 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
950 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
955 const Handle(Geom_BSplineCurve)& aBC=
956 Handle(Geom_BSplineCurve)::DownCast(aC3D);
961 aT1=aBC->FirstParameter();
962 aT2=aBC->LastParameter();
964 dT=(aT2-aT1)/(aNbP-1);
965 for (j=0; j<aNbP; ++j) {
971 aD2=MaxSquareDistance(aT, aC3D, aC2D1, aC2D2,
972 myHS1, myHS2, myFace1, myFace2, myContext);
976 }//for (j=0; j<aNbP; ++j) {
978 }//for (i=1; i<=aNbLin; ++i) {
980 aD2=myTolReached3d*myTolReached3d;
982 myTolReached3d=sqrt(aD2max);
984 }//if((aType1==GeomAbs_SurfaceOfRevolution ...
985 else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ||
986 (aType2==GeomAbs_Plane && aType1==GeomAbs_Sphere)) {
987 Standard_Integer i, j, aNbP;
988 Standard_Real aT1, aT2, dT, aD2max, aD2, aEps, aT11, aT12;
990 aNbLin=mySeqOfCurve.Length();
994 for (i=1; i<=aNbLin; ++i) {
995 const IntTools_Curve& aIC=mySeqOfCurve(i);
996 const Handle(Geom_Curve)& aC3D=aIC.Curve();
997 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
998 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1000 const Handle(Geom2d_BSplineCurve)& aBC2D1=
1001 Handle(Geom2d_BSplineCurve)::DownCast(aC2D1);
1002 const Handle(Geom2d_BSplineCurve)& aBC2D2=
1003 Handle(Geom2d_BSplineCurve)::DownCast(aC2D2);
1005 if (aBC2D1.IsNull() && aBC2D2.IsNull()) {
1009 if (!aBC2D1.IsNull()) {
1010 aT1=aBC2D1->FirstParameter();
1011 aT2=aBC2D1->LastParameter();
1014 aT1=aBC2D2->FirstParameter();
1015 aT2=aBC2D2->LastParameter();
1018 aEps=0.01*(aT2-aT1);
1020 for (j=0; j<aNbP; ++j) {
1027 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
1028 myHS1, myHS2, myFace1, myFace2, myContext);
1032 }//for (j=0; j<aNbP; ++j) {
1034 }//for (i=1; i<=aNbLin; ++i) {
1036 aD2=myTolReached3d*myTolReached3d;
1038 myTolReached3d=sqrt(aD2max);
1040 }//else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ...
1041 else if (!myApprox) {
1042 Standard_Integer i, aNbP, j ;
1043 Standard_Real aT1, aT2, dT, aD2, aD2Max, aEps, aT11, aT12;
1046 aNbLin=mySeqOfCurve.Length();
1048 for (i=1; i<=aNbLin; ++i) {
1049 const IntTools_Curve& aIC=mySeqOfCurve(i);
1050 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1051 const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
1052 const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
1054 if (aC3D.IsNull()) {
1057 const Handle(Geom_BSplineCurve)& aBC=
1058 Handle(Geom_BSplineCurve)::DownCast(aC3D);
1063 aT1=aBC->FirstParameter();
1064 aT2=aBC->LastParameter();
1066 aEps=0.0001*(aT2-aT1);
1069 for (j=1; j<aNbP-1; ++j) {
1072 aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
1073 myHS1, myHS2, myFace1, myFace2, myContext);
1078 }//for (i=1; i<=aNbLin; ++i) {
1079 myTolReached3d=sqrt(aD2Max);
1081 //modified by NIZNHY-PKV Thu Aug 30 13:31:12 2012t
1083 //=======================================================================
1084 //function : MakeCurve
1086 //=======================================================================
1087 void IntTools_FaceFace::MakeCurve(const Standard_Integer Index,
1088 const Handle(Adaptor3d_TopolTool)& dom1,
1089 const Handle(Adaptor3d_TopolTool)& dom2)
1091 Standard_Boolean bDone, rejectSurface, reApprox, bAvoidLineConstructor,
1093 Standard_Boolean ok;
1094 Standard_Integer i, j, aNbParts;
1095 Standard_Real fprm, lprm;
1096 Standard_Real Tolpc;
1097 Handle(IntPatch_Line) L;
1098 IntPatch_IType typl;
1099 Handle(Geom_Curve) newc;
1101 const Standard_Real TOLCHECK =0.0000001;
1102 const Standard_Real TOLANGCHECK=0.1;
1104 rejectSurface = Standard_False;
1105 reApprox = Standard_False;
1107 bPCurvesOk = Standard_True;
1111 Tolpc = myTolApprox;
1112 bAvoidLineConstructor = Standard_False;
1113 L = myIntersector.Line(Index);
1114 typl = L->ArcType();
1116 if(typl==IntPatch_Walking) {
1117 Handle(IntPatch_Line) anewL;
1119 const Handle(IntPatch_WLine)& aWLine=
1120 Handle(IntPatch_WLine)::DownCast(L);
1122 //DumpWLine(aWLine);
1124 anewL = ComputePurgedWLine(aWLine);
1125 if(anewL.IsNull()) {
1131 { const Handle(IntPatch_WLine)& aWLineX=
1132 Handle(IntPatch_WLine)::DownCast(L);
1138 if(!myListOfPnts.IsEmpty()) {
1139 bAvoidLineConstructor = Standard_True;
1142 Standard_Integer nbp = aWLine->NbPnts();
1143 const IntSurf_PntOn2S& p1 = aWLine->Point(1);
1144 const IntSurf_PntOn2S& p2 = aWLine->Point(nbp);
1146 const gp_Pnt& P1 = p1.Value();
1147 const gp_Pnt& P2 = p2.Value();
1149 if(P1.SquareDistance(P2) < 1.e-14) {
1150 bAvoidLineConstructor = Standard_False;
1156 if(!bAvoidLineConstructor) {
1157 myLConstruct.Perform(L);
1159 bDone=myLConstruct.IsDone();
1160 aNbParts=myLConstruct.NbParts();
1161 if (!bDone|| !aNbParts) {
1170 //########################################
1171 // Line, Parabola, Hyperbola
1172 //########################################
1174 case IntPatch_Parabola:
1175 case IntPatch_Hyperbola: {
1176 if (typl == IntPatch_Lin) {
1178 new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line());
1181 else if (typl == IntPatch_Parabola) {
1183 new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola());
1186 else if (typl == IntPatch_Hyperbola) {
1188 new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola());
1192 if (typl == IntPatch_Lin) {
1193 TolR3d (myFace1, myFace2, myTolReached3d);
1196 aNbParts=myLConstruct.NbParts();
1197 for (i=1; i<=aNbParts; i++) {
1198 myLConstruct.Part(i, fprm, lprm);
1200 if (!Precision::IsNegativeInfinite(fprm) &&
1201 !Precision::IsPositiveInfinite(lprm)) {
1203 IntTools_Curve aCurve;
1205 Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm);
1206 aCurve.SetCurve(aCT3D);
1207 if (typl == IntPatch_Parabola) {
1208 Standard_Real aTolF1, aTolF2, aTolBase;
1210 aTolF1 = BRep_Tool::Tolerance(myFace1);
1211 aTolF2 = BRep_Tool::Tolerance(myFace2);
1212 aTolBase=aTolF1+aTolF2;
1213 myTolReached3d=IntTools_Tools::CurveTolerance(aCT3D, aTolBase);
1216 aCurve.SetCurve(new Geom_TrimmedCurve(newc, fprm, lprm));
1218 Handle (Geom2d_Curve) C2d;
1219 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1220 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1221 myTolReached2d=Tolpc;
1224 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1227 Handle(Geom2d_BSplineCurve) H1;
1229 aCurve.SetFirstCurve2d(H1);
1233 Handle (Geom2d_Curve) C2d;
1234 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1235 if(Tolpc>myTolReached2d || myTolReached2d==0.) {
1236 myTolReached2d=Tolpc;
1239 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
1242 Handle(Geom2d_BSplineCurve) H1;
1244 aCurve.SetSecondCurve2d(H1);
1246 mySeqOfCurve.Append(aCurve);
1247 } // end of if (!Precision::IsNegativeInfinite(fprm) && !Precision::IsPositiveInfinite(lprm))
1250 // on regarde si on garde
1252 Standard_Boolean bFNIt, bLPIt;
1253 Standard_Real aTestPrm, dT=100.;
1255 bFNIt=Precision::IsNegativeInfinite(fprm);
1256 bLPIt=Precision::IsPositiveInfinite(lprm);
1260 if (bFNIt && !bLPIt) {
1263 else if (!bFNIt && bLPIt) {
1267 gp_Pnt ptref(newc->Value(aTestPrm));
1270 Standard_Real u1, v1, u2, v2, Tol;
1272 Tol = Precision::Confusion();
1273 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1274 ok = (dom1->Classify(gp_Pnt2d(u1, v1), Tol) != TopAbs_OUT);
1276 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1279 Handle(Geom2d_BSplineCurve) H1;
1280 mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
1283 }// end of for (i=1; i<=myLConstruct.NbParts(); i++)
1284 }// case IntPatch_Lin: case IntPatch_Parabola: case IntPatch_Hyperbola:
1287 //########################################
1288 // Circle and Ellipse
1289 //########################################
1290 case IntPatch_Circle:
1291 case IntPatch_Ellipse: {
1293 if (typl == IntPatch_Circle) {
1294 newc = new Geom_Circle
1295 (Handle(IntPatch_GLine)::DownCast(L)->Circle());
1297 else { //IntPatch_Ellipse
1298 newc = new Geom_Ellipse
1299 (Handle(IntPatch_GLine)::DownCast(L)->Ellipse());
1303 TolR3d (myFace1, myFace2, myTolReached3d);
1305 aNbParts=myLConstruct.NbParts();
1307 Standard_Real aPeriod, aNul;
1308 TColStd_SequenceOfReal aSeqFprm, aSeqLprm;
1313 for (i=1; i<=aNbParts; i++) {
1314 myLConstruct.Part(i, fprm, lprm);
1316 if (fprm < aNul && lprm > aNul) {
1317 // interval that goes through 0. is divided on two intervals;
1318 while (fprm<aNul || fprm>aPeriod) fprm=fprm+aPeriod;
1319 while (lprm<aNul || lprm>aPeriod) lprm=lprm+aPeriod;
1321 if((aPeriod - fprm) > Tolpc) {
1322 aSeqFprm.Append(fprm);
1323 aSeqLprm.Append(aPeriod);
1326 gp_Pnt P1 = newc->Value(fprm);
1327 gp_Pnt P2 = newc->Value(aPeriod);
1328 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1329 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1331 if(P1.Distance(P2) > aTolDist) {
1332 Standard_Real anewpar = fprm;
1334 if(ParameterOutOfBoundary(fprm, newc, myFace1, myFace2, lprm, Standard_False, anewpar, myContext)) {
1337 aSeqFprm.Append(fprm);
1338 aSeqLprm.Append(aPeriod);
1343 if((lprm - aNul) > Tolpc) {
1344 aSeqFprm.Append(aNul);
1345 aSeqLprm.Append(lprm);
1348 gp_Pnt P1 = newc->Value(aNul);
1349 gp_Pnt P2 = newc->Value(lprm);
1350 Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
1351 aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
1353 if(P1.Distance(P2) > aTolDist) {
1354 Standard_Real anewpar = lprm;
1356 if(ParameterOutOfBoundary(lprm, newc, myFace1, myFace2, fprm, Standard_True, anewpar, myContext)) {
1359 aSeqFprm.Append(aNul);
1360 aSeqLprm.Append(lprm);
1366 aSeqFprm.Append(fprm);
1367 aSeqLprm.Append(lprm);
1372 aNbParts=aSeqFprm.Length();
1373 for (i=1; i<=aNbParts; i++) {
1377 Standard_Real aRealEpsilon=RealEpsilon();
1378 if (Abs(fprm) > aRealEpsilon || Abs(lprm-2.*M_PI) > aRealEpsilon) {
1379 //==============================================
1381 IntTools_Curve aCurve;
1382 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1383 aCurve.SetCurve(aTC3D);
1384 fprm=aTC3D->FirstParameter();
1385 lprm=aTC3D->LastParameter ();
1387 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {////
1389 Handle (Geom2d_Curve) C2d;
1390 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1391 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1392 myTolReached2d=Tolpc;
1395 aCurve.SetFirstCurve2d(C2d);
1398 Handle(Geom2d_BSplineCurve) H1;
1399 aCurve.SetFirstCurve2d(H1);
1404 Handle (Geom2d_Curve) C2d;
1405 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1406 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1407 myTolReached2d=Tolpc;
1410 aCurve.SetSecondCurve2d(C2d);
1413 Handle(Geom2d_BSplineCurve) H1;
1414 aCurve.SetSecondCurve2d(H1);
1419 Handle(Geom2d_BSplineCurve) H1;
1420 aCurve.SetFirstCurve2d(H1);
1421 aCurve.SetSecondCurve2d(H1);
1423 mySeqOfCurve.Append(aCurve);
1424 //==============================================
1425 } //if (Abs(fprm) > RealEpsilon() || Abs(lprm-2.*M_PI) > RealEpsilon())
1428 // on regarde si on garde
1431 // if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*M_PI) < RealEpsilon()) {
1432 if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*M_PI) <= aRealEpsilon) {
1433 IntTools_Curve aCurve;
1434 Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
1435 aCurve.SetCurve(aTC3D);
1436 fprm=aTC3D->FirstParameter();
1437 lprm=aTC3D->LastParameter ();
1440 Handle (Geom2d_Curve) C2d;
1441 BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
1442 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1443 myTolReached2d=Tolpc;
1446 aCurve.SetFirstCurve2d(C2d);
1449 Handle(Geom2d_BSplineCurve) H1;
1450 aCurve.SetFirstCurve2d(H1);
1454 Handle (Geom2d_Curve) C2d;
1455 BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
1456 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1457 myTolReached2d=Tolpc;
1460 aCurve.SetSecondCurve2d(C2d);
1463 Handle(Geom2d_BSplineCurve) H1;
1464 aCurve.SetSecondCurve2d(H1);
1466 mySeqOfCurve.Append(aCurve);
1471 Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol;
1473 aTwoPIdiv17=2.*M_PI/17.;
1475 for (j=0; j<=17; j++) {
1476 gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
1477 Tol = Precision::Confusion();
1479 Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
1480 ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT);
1482 ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
1485 IntTools_Curve aCurve;
1486 aCurve.SetCurve(newc);
1487 //==============================================
1488 if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {
1491 Handle (Geom2d_Curve) C2d;
1492 BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
1493 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1494 myTolReached2d=Tolpc;
1497 aCurve.SetFirstCurve2d(C2d);
1500 Handle(Geom2d_BSplineCurve) H1;
1501 aCurve.SetFirstCurve2d(H1);
1505 Handle (Geom2d_Curve) C2d;
1506 BuildPCurves(fprm, lprm, Tolpc,myHS2->ChangeSurface().Surface(), newc, C2d);
1507 if(Tolpc>myTolReached2d || myTolReached2d==0) {
1508 myTolReached2d=Tolpc;
1511 aCurve.SetSecondCurve2d(C2d);
1515 Handle(Geom2d_BSplineCurve) H1;
1516 aCurve.SetSecondCurve2d(H1);
1518 }// end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse)
1521 Handle(Geom2d_BSplineCurve) H1;
1523 aCurve.SetFirstCurve2d(H1);
1524 aCurve.SetSecondCurve2d(H1);
1526 //==============================================
1528 mySeqOfCurve.Append(aCurve);
1531 }// end of if (ok) {
1532 }// end of for (Standard_Integer j=0; j<=17; j++)
1533 }// end of else { on regarde si on garde
1534 }// for (i=1; i<=myLConstruct.NbParts(); i++)
1535 }// IntPatch_Circle: IntPatch_Ellipse:
1538 case IntPatch_Analytic: {
1539 IntSurf_Quadric quad1,quad2;
1540 GeomAbs_SurfaceType typs = myHS1->Surface().GetType();
1544 quad1.SetValue(myHS1->Surface().Plane());
1546 case GeomAbs_Cylinder:
1547 quad1.SetValue(myHS1->Surface().Cylinder());
1550 quad1.SetValue(myHS1->Surface().Cone());
1552 case GeomAbs_Sphere:
1553 quad1.SetValue(myHS1->Surface().Sphere());
1556 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 1");
1559 typs = myHS2->Surface().GetType();
1563 quad2.SetValue(myHS2->Surface().Plane());
1565 case GeomAbs_Cylinder:
1566 quad2.SetValue(myHS2->Surface().Cylinder());
1569 quad2.SetValue(myHS2->Surface().Cone());
1571 case GeomAbs_Sphere:
1572 quad2.SetValue(myHS2->Surface().Sphere());
1575 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 2");
1579 IntPatch_ALineToWLine convert (quad1, quad2);
1582 aNbParts=myLConstruct.NbParts();
1583 for (i=1; i<=aNbParts; i++) {
1584 myLConstruct.Part(i, fprm, lprm);
1585 Handle(IntPatch_WLine) WL =
1586 convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm);
1588 Handle(Geom2d_BSplineCurve) H1;
1589 Handle(Geom2d_BSplineCurve) H2;
1592 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1596 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1599 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1603 else { // myApprox=TRUE
1604 GeomInt_WLApprox theapp3d;
1606 Standard_Real tol2d = myTolApprox;
1608 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True);
1610 aNbParts=myLConstruct.NbParts();
1611 for (i=1; i<=aNbParts; i++) {
1612 myLConstruct.Part(i, fprm, lprm);
1613 Handle(IntPatch_WLine) WL =
1614 convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
1616 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
1618 if (!theapp3d.IsDone()) {
1620 Handle(Geom2d_BSplineCurve) H1;
1621 Handle(Geom2d_BSplineCurve) H2;
1624 H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
1628 H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
1631 mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
1635 if(myApprox1 || myApprox2) {
1636 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) {
1637 myTolReached2d = theapp3d.TolReached2d();
1641 if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) {
1642 myTolReached3d = theapp3d.TolReached3d();
1645 Standard_Integer aNbMultiCurves, nbpoles;
1646 aNbMultiCurves=theapp3d.NbMultiCurves();
1647 for (j=1; j<=aNbMultiCurves; j++) {
1648 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1649 nbpoles = mbspc.NbPoles();
1651 TColgp_Array1OfPnt tpoles(1, nbpoles);
1652 mbspc.Curve(1, tpoles);
1653 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
1655 mbspc.Multiplicities(),
1658 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1659 Check.FixTangent(Standard_True,Standard_True);
1661 IntTools_Curve aCurve;
1662 aCurve.SetCurve(BS);
1665 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1666 mbspc.Curve(2,tpoles2d);
1667 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
1669 mbspc.Multiplicities(),
1672 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1673 newCheck.FixTangent(Standard_True,Standard_True);
1675 aCurve.SetFirstCurve2d(BS2);
1678 Handle(Geom2d_BSplineCurve) H1;
1679 aCurve.SetFirstCurve2d(H1);
1683 TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
1684 Standard_Integer TwoOrThree;
1685 TwoOrThree=myApprox1 ? 3 : 2;
1686 mbspc.Curve(TwoOrThree, tpoles2d);
1687 Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
1689 mbspc.Multiplicities(),
1692 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1693 newCheck.FixTangent(Standard_True,Standard_True);
1695 aCurve.SetSecondCurve2d(BS2);
1698 Handle(Geom2d_BSplineCurve) H2;
1699 aCurve.SetSecondCurve2d(H2);
1702 mySeqOfCurve.Append(aCurve);
1704 }// for (j=1; j<=aNbMultiCurves; j++) {
1705 }// else from if (!theapp3d.IsDone())
1706 }// for (i=1; i<=aNbParts; i++) {
1707 }// else { // myApprox=TRUE
1708 }// case IntPatch_Analytic:
1711 case IntPatch_Walking:{
1712 Handle(IntPatch_WLine) WL =
1713 Handle(IntPatch_WLine)::DownCast(L);
1715 Standard_Integer ifprm, ilprm;
1719 if(!bAvoidLineConstructor){
1720 aNbParts=myLConstruct.NbParts();
1722 for (i=1; i<=aNbParts; ++i) {
1723 Handle(Geom2d_BSplineCurve) H1, H2;
1724 Handle(Geom_Curve) aBSp;
1726 if(bAvoidLineConstructor) {
1728 ilprm = WL->NbPnts();
1731 myLConstruct.Part(i, fprm, lprm);
1732 ifprm=(Standard_Integer)fprm;
1733 ilprm=(Standard_Integer)lprm;
1737 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1741 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1744 aBSp=MakeBSpline(WL, ifprm, ilprm);
1745 IntTools_Curve aIC(aBSp, H1, H2);
1746 mySeqOfCurve.Append(aIC);
1747 }// for (i=1; i<=aNbParts; ++i) {
1748 }// if (!myApprox) {
1751 Standard_Boolean bIsDecomposited;
1752 Standard_Integer nbiter, aNbSeqOfL;
1753 Standard_Real tol2d;
1754 IntPatch_SequenceOfLine aSeqOfL;
1755 GeomInt_WLApprox theapp3d;
1756 Approx_ParametrizationType aParType = Approx_ChordLength;
1758 Standard_Boolean anApprox1 = myApprox1;
1759 Standard_Boolean anApprox2 = myApprox2;
1761 tol2d = myTolApprox;
1763 GeomAbs_SurfaceType typs1, typs2;
1764 typs1 = myHS1->Surface().GetType();
1765 typs2 = myHS2->Surface().GetType();
1766 Standard_Boolean anWithPC = Standard_True;
1768 if(typs1 == GeomAbs_Cylinder && typs2 == GeomAbs_Sphere) {
1770 ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere());
1772 else if (typs1 == GeomAbs_Sphere && typs2 == GeomAbs_Cylinder) {
1774 ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere());
1777 //aParType = Approx_Centripetal;
1778 myTolApprox = 1.e-5;
1779 anApprox1 = Standard_False;
1780 anApprox2 = Standard_False;
1782 tol2d = myTolApprox;
1785 if(myHS1 == myHS2) {
1787 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1788 rejectSurface = Standard_True;
1791 if(reApprox && !rejectSurface)
1792 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1794 Standard_Integer iDegMax, iDegMin, iNbIter;
1796 ApproxParameters(myHS1, myHS2, iDegMin, iDegMax, iNbIter);
1797 theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, iNbIter, Standard_True, aParType);
1802 Standard_Real aReachedTol = Precision::Confusion();
1803 bIsDecomposited=DecompositionOfWLine(WL,
1809 bAvoidLineConstructor,
1813 if ( bIsDecomposited && ( myTolReached3d < aReachedTol ) )
1814 myTolReached3d = aReachedTol;
1817 aNbSeqOfL=aSeqOfL.Length();
1819 if (bIsDecomposited) {
1825 if (!bAvoidLineConstructor) {
1826 aNbParts=myLConstruct.NbParts();
1831 // nbiter=(bIsDecomposited) ? aSeqOfL.Length() :
1832 // ((bAvoidLineConstructor) ? 1 :aNbParts);
1834 for(i = 1; i <= nbiter; ++i) {
1835 if(bIsDecomposited) {
1836 WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i));
1838 ilprm = WL->NbPnts();
1841 if(bAvoidLineConstructor) {
1843 ilprm = WL->NbPnts();
1846 myLConstruct.Part(i, fprm, lprm);
1847 ifprm = (Standard_Integer)fprm;
1848 ilprm = (Standard_Integer)lprm;
1852 //-- Si une des surfaces est un plan , on approxime en 2d
1853 //-- sur cette surface et on remonte les points 2d en 3d.
1854 if(typs1 == GeomAbs_Plane) {
1855 theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm);
1857 else if(typs2 == GeomAbs_Plane) {
1858 theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm);
1862 if (myHS1 != myHS2){
1863 if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) &&
1864 (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) {
1866 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType);
1868 Standard_Boolean bUseSurfaces;
1869 bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm, ilprm);
1872 rejectSurface = Standard_True;
1874 theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
1879 theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm);
1882 if (!theapp3d.IsDone()) {
1884 Handle(Geom2d_BSplineCurve) H1;
1886 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
1887 Handle(Geom2d_BSplineCurve) H2;
1890 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
1894 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
1897 IntTools_Curve aIC(aBSp, H1, H2);
1898 mySeqOfCurve.Append(aIC);
1902 if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) {
1903 if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) {
1904 myTolReached2d = theapp3d.TolReached2d();
1907 if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) {
1908 myTolReached3d = myTolReached2d;
1910 if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
1911 if (myTolReached3d<1.e-6) {
1912 myTolReached3d = theapp3d.TolReached3d();
1913 myTolReached3d=1.e-6;
1918 else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) {
1919 myTolReached3d = theapp3d.TolReached3d();
1922 Standard_Integer aNbMultiCurves, nbpoles;
1923 aNbMultiCurves=theapp3d.NbMultiCurves();
1924 for (j=1; j<=aNbMultiCurves; j++) {
1925 if(typs1 == GeomAbs_Plane) {
1926 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
1927 nbpoles = mbspc.NbPoles();
1929 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
1930 TColgp_Array1OfPnt tpoles(1,nbpoles);
1932 mbspc.Curve(1,tpoles2d);
1933 const gp_Pln& Pln = myHS1->Surface().Plane();
1935 Standard_Integer ik;
1936 for(ik = 1; ik<= nbpoles; ik++) {
1938 ElSLib::Value(tpoles2d.Value(ik).X(),
1939 tpoles2d.Value(ik).Y(),
1943 Handle(Geom_BSplineCurve) BS =
1944 new Geom_BSplineCurve(tpoles,
1946 mbspc.Multiplicities(),
1948 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
1949 Check.FixTangent(Standard_True, Standard_True);
1951 IntTools_Curve aCurve;
1952 aCurve.SetCurve(BS);
1955 Handle(Geom2d_BSplineCurve) BS1 =
1956 new Geom2d_BSplineCurve(tpoles2d,
1958 mbspc.Multiplicities(),
1960 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
1961 Check1.FixTangent(Standard_True,Standard_True);
1963 // ############################################
1964 if(!rejectSurface && !reApprox) {
1965 Standard_Boolean isValid = IsCurveValid(BS1);
1967 reApprox = Standard_True;
1971 // ############################################
1972 aCurve.SetFirstCurve2d(BS1);
1975 Handle(Geom2d_BSplineCurve) H1;
1976 aCurve.SetFirstCurve2d(H1);
1980 mbspc.Curve(2, tpoles2d);
1982 Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
1984 mbspc.Multiplicities(),
1986 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
1987 newCheck.FixTangent(Standard_True,Standard_True);
1989 // ###########################################
1990 if(!rejectSurface && !reApprox) {
1991 Standard_Boolean isValid = IsCurveValid(BS2);
1993 reApprox = Standard_True;
1997 // ###########################################
1999 aCurve.SetSecondCurve2d(BS2);
2002 Handle(Geom2d_BSplineCurve) H2;
2004 aCurve.SetSecondCurve2d(H2);
2007 mySeqOfCurve.Append(aCurve);
2010 else if(typs2 == GeomAbs_Plane) {
2011 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2012 nbpoles = mbspc.NbPoles();
2014 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2015 TColgp_Array1OfPnt tpoles(1,nbpoles);
2016 mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d);
2017 const gp_Pln& Pln = myHS2->Surface().Plane();
2019 Standard_Integer ik;
2020 for(ik = 1; ik<= nbpoles; ik++) {
2022 ElSLib::Value(tpoles2d.Value(ik).X(),
2023 tpoles2d.Value(ik).Y(),
2028 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
2030 mbspc.Multiplicities(),
2032 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2033 Check.FixTangent(Standard_True,Standard_True);
2035 IntTools_Curve aCurve;
2036 aCurve.SetCurve(BS);
2039 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
2041 mbspc.Multiplicities(),
2043 GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
2044 Check1.FixTangent(Standard_True,Standard_True);
2046 // ###########################################
2047 if(!rejectSurface && !reApprox) {
2048 Standard_Boolean isValid = IsCurveValid(BS1);
2050 reApprox = Standard_True;
2054 // ###########################################
2055 bPCurvesOk = CheckPCurve(BS1, myFace2);
2056 aCurve.SetSecondCurve2d(BS1);
2059 Handle(Geom2d_BSplineCurve) H2;
2060 aCurve.SetSecondCurve2d(H2);
2064 mbspc.Curve(1,tpoles2d);
2065 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
2067 mbspc.Multiplicities(),
2069 GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK);
2070 Check2.FixTangent(Standard_True,Standard_True);
2072 // ###########################################
2073 if(!rejectSurface && !reApprox) {
2074 Standard_Boolean isValid = IsCurveValid(BS2);
2076 reApprox = Standard_True;
2080 // ###########################################
2081 bPCurvesOk = bPCurvesOk && CheckPCurve(BS2, myFace1);
2082 aCurve.SetFirstCurve2d(BS2);
2085 Handle(Geom2d_BSplineCurve) H1;
2087 aCurve.SetFirstCurve2d(H1);
2090 //if points of the pcurves are out of the faces bounds
2091 //create 3d and 2d curves without approximation
2093 Handle(Geom2d_BSplineCurve) H1, H2;
2094 bPCurvesOk = Standard_True;
2096 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
2099 H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
2100 bPCurvesOk = CheckPCurve(H1, myFace1);
2104 H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
2105 bPCurvesOk = bPCurvesOk && CheckPCurve(H2, myFace2);
2108 //if pcurves created without approximation are out of the
2109 //faces bounds, use approximated 3d and 2d curves
2111 IntTools_Curve aIC(aBSp, H1, H2);
2112 mySeqOfCurve.Append(aIC);
2114 mySeqOfCurve.Append(aCurve);
2117 mySeqOfCurve.Append(aCurve);
2121 const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
2122 nbpoles = mbspc.NbPoles();
2123 TColgp_Array1OfPnt tpoles(1,nbpoles);
2124 mbspc.Curve(1,tpoles);
2125 Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
2127 mbspc.Multiplicities(),
2129 GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
2130 Check.FixTangent(Standard_True,Standard_True);
2132 IntTools_Curve aCurve;
2133 aCurve.SetCurve(BS);
2137 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2138 mbspc.Curve(2,tpoles2d);
2139 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
2141 mbspc.Multiplicities(),
2143 GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK);
2144 newCheck.FixTangent(Standard_True,Standard_True);
2146 aCurve.SetFirstCurve2d(BS1);
2149 Handle(Geom2d_BSplineCurve) BS1;
2150 fprm = BS->FirstParameter();
2151 lprm = BS->LastParameter();
2153 Handle(Geom2d_Curve) C2d;
2154 Standard_Real aTol = myTolApprox;
2155 BuildPCurves(fprm, lprm, aTol, myHS1->ChangeSurface().Surface(), BS, C2d);
2156 BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2157 aCurve.SetFirstCurve2d(BS1);
2162 Handle(Geom2d_BSplineCurve) H1;
2164 aCurve.SetFirstCurve2d(H1);
2168 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
2169 mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d);
2170 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
2172 mbspc.Multiplicities(),
2174 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
2175 newCheck.FixTangent(Standard_True,Standard_True);
2177 aCurve.SetSecondCurve2d(BS2);
2180 Handle(Geom2d_BSplineCurve) BS2;
2181 fprm = BS->FirstParameter();
2182 lprm = BS->LastParameter();
2184 Handle(Geom2d_Curve) C2d;
2185 Standard_Real aTol = myTolApprox;
2186 BuildPCurves(fprm, lprm, aTol, myHS2->ChangeSurface().Surface(), BS, C2d);
2187 BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
2188 aCurve.SetSecondCurve2d(BS2);
2193 Handle(Geom2d_BSplineCurve) H2;
2195 aCurve.SetSecondCurve2d(H2);
2198 mySeqOfCurve.Append(aCurve);
2204 }// case IntPatch_Walking:{
2207 case IntPatch_Restriction:
2213 //=======================================================================
2214 //function : BuildPCurves
2216 //=======================================================================
2217 void BuildPCurves (Standard_Real f,
2220 const Handle (Geom_Surface)& S,
2221 const Handle (Geom_Curve)& C,
2222 Handle (Geom2d_Curve)& C2d)
2225 Standard_Real umin,umax,vmin,vmax;
2230 // in class ProjLib_Function the range of parameters is shrank by 1.e-09
2231 if((l - f) > 2.e-09) {
2232 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2235 // proj. a circle that goes through the pole on a sphere to the sphere
2237 C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
2241 if((l - f) > Epsilon(Abs(f))) {
2242 GeomAPI_ProjectPointOnSurf aProjector1, aProjector2;
2243 gp_Pnt P1 = C->Value(f);
2244 gp_Pnt P2 = C->Value(l);
2245 aProjector1.Init(P1, S);
2246 aProjector2.Init(P2, S);
2248 if(aProjector1.IsDone() && aProjector2.IsDone()) {
2249 Standard_Real U=0., V=0.;
2250 aProjector1.LowerDistanceParameters(U, V);
2253 aProjector2.LowerDistanceParameters(U, V);
2256 if(p1.Distance(p2) > gp::Resolution()) {
2257 TColgp_Array1OfPnt2d poles(1,2);
2258 TColStd_Array1OfReal knots(1,2);
2259 TColStd_Array1OfInteger mults(1,2);
2264 mults(1) = mults(2) = 2;
2266 C2d = new Geom2d_BSplineCurve(poles,knots,mults,1);
2268 // compute reached tolerance.begin
2269 gp_Pnt PMid = C->Value((f + l) * 0.5);
2270 aProjector1.Perform(PMid);
2272 if(aProjector1.IsDone()) {
2273 aProjector1.LowerDistanceParameters(U, V);
2274 gp_Pnt2d pmidproj(U, V);
2275 gp_Pnt2d pmidcurve2d = C2d->Value((f + l) * 0.5);
2276 Standard_Real adist = pmidcurve2d.Distance(pmidproj);
2277 Tol = (adist > Tol) ? adist : Tol;
2279 // compute reached tolerance.end
2285 S->Bounds(umin, umax, vmin, vmax);
2287 if (S->IsUPeriodic() && !C2d.IsNull()) {
2288 // Recadre dans le domaine UV de la face
2289 Standard_Real period, U0, du, aEps;
2292 aEps=Precision::PConfusion();
2293 period = S->UPeriod();
2294 gp_Pnt2d Pf = C2d->Value(f);
2297 gp_Pnt2d Pl = C2d->Value(l);
2299 U0 = Min(Pl.X(), U0);
2300 // while(U0-umin<aEps) {
2301 while(U0-umin<-aEps) {
2306 while(U0-umax>aEps) {
2318 //=======================================================================
2319 //function : Parameters
2321 //=======================================================================
2322 void Parameters(const Handle(GeomAdaptor_HSurface)& HS1,
2323 const Handle(GeomAdaptor_HSurface)& HS2,
2324 const gp_Pnt& Ptref,
2331 IntSurf_Quadric quad1,quad2;
2332 GeomAbs_SurfaceType typs = HS1->Surface().GetType();
2336 quad1.SetValue(HS1->Surface().Plane());
2338 case GeomAbs_Cylinder:
2339 quad1.SetValue(HS1->Surface().Cylinder());
2342 quad1.SetValue(HS1->Surface().Cone());
2344 case GeomAbs_Sphere:
2345 quad1.SetValue(HS1->Surface().Sphere());
2348 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2351 typs = HS2->Surface().GetType();
2354 quad2.SetValue(HS2->Surface().Plane());
2356 case GeomAbs_Cylinder:
2357 quad2.SetValue(HS2->Surface().Cylinder());
2360 quad2.SetValue(HS2->Surface().Cone());
2362 case GeomAbs_Sphere:
2363 quad2.SetValue(HS2->Surface().Sphere());
2366 Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve");
2369 quad1.Parameters(Ptref,U1,V1);
2370 quad2.Parameters(Ptref,U2,V2);
2373 //=======================================================================
2374 //function : MakeBSpline
2376 //=======================================================================
2377 Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL,
2378 const Standard_Integer ideb,
2379 const Standard_Integer ifin)
2381 Standard_Integer i,nbpnt = ifin-ideb+1;
2382 TColgp_Array1OfPnt poles(1,nbpnt);
2383 TColStd_Array1OfReal knots(1,nbpnt);
2384 TColStd_Array1OfInteger mults(1,nbpnt);
2385 Standard_Integer ipidebm1;
2386 for(i=1,ipidebm1=i+ideb-1; i<=nbpnt;ipidebm1++, i++) {
2387 poles(i) = WL->Point(ipidebm1).Value();
2391 mults(1) = mults(nbpnt) = 2;
2393 new Geom_BSplineCurve(poles,knots,mults,1);
2397 //=======================================================================
2398 //function : MakeBSpline2d
2400 //=======================================================================
2401 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
2402 const Standard_Integer ideb,
2403 const Standard_Integer ifin,
2404 const Standard_Boolean onFirst)
2406 Standard_Integer i, nbpnt = ifin-ideb+1;
2407 TColgp_Array1OfPnt2d poles(1,nbpnt);
2408 TColStd_Array1OfReal knots(1,nbpnt);
2409 TColStd_Array1OfInteger mults(1,nbpnt);
2410 Standard_Integer ipidebm1;
2412 for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) {
2415 theWLine->Point(ipidebm1).ParametersOnS1(U, V);
2417 theWLine->Point(ipidebm1).ParametersOnS2(U, V);
2418 poles(i).SetCoord(U, V);
2422 mults(1) = mults(nbpnt) = 2;
2424 return new Geom2d_BSplineCurve(poles,knots,mults,1);
2426 //=======================================================================
2427 //function : PrepareLines3D
2429 //=======================================================================
2430 void IntTools_FaceFace::PrepareLines3D(const Standard_Boolean bToSplit)
2432 Standard_Integer i, aNbCurves;
2433 GeomAbs_SurfaceType aType1, aType2;
2434 IntTools_SequenceOfCurves aNewCvs;
2436 // 1. Treatment closed curves
2437 aNbCurves=mySeqOfCurve.Length();
2438 for (i=1; i<=aNbCurves; ++i) {
2439 const IntTools_Curve& aIC=mySeqOfCurve(i);
2442 Standard_Integer j, aNbC;
2443 IntTools_SequenceOfCurves aSeqCvs;
2445 aNbC=IntTools_Tools::SplitCurve(aIC, aSeqCvs);
2447 for (j=1; j<=aNbC; ++j) {
2448 const IntTools_Curve& aICNew=aSeqCvs(j);
2449 aNewCvs.Append(aICNew);
2453 aNewCvs.Append(aIC);
2457 aNewCvs.Append(aIC);
2461 // 2. Plane\Cone intersection when we had 4 curves
2462 aType1=myHS1->GetType();
2463 aType2=myHS2->GetType();
2464 aNbCurves=aNewCvs.Length();
2466 if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone) ||
2467 (aType2==GeomAbs_Plane && aType1==GeomAbs_Cone)) {
2469 GeomAbs_CurveType aCType1;
2471 aCType1=aNewCvs(1).Type();
2472 if (aCType1==GeomAbs_Line) {
2473 IntTools_SequenceOfCurves aSeqIn, aSeqOut;
2475 for (i=1; i<=aNbCurves; ++i) {
2476 const IntTools_Curve& aIC=aNewCvs(i);
2480 IntTools_Tools::RejectLines(aSeqIn, aSeqOut);
2483 aNbCurves=aSeqOut.Length();
2484 for (i=1; i<=aNbCurves; ++i) {
2485 const IntTools_Curve& aIC=aSeqOut(i);
2486 aNewCvs.Append(aIC);
2490 }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone)...
2492 // 3. Fill mySeqOfCurve
2493 mySeqOfCurve.Clear();
2494 aNbCurves=aNewCvs.Length();
2495 for (i=1; i<=aNbCurves; ++i) {
2496 const IntTools_Curve& aIC=aNewCvs(i);
2497 mySeqOfCurve.Append(aIC);
2500 //=======================================================================
2501 //function : CorrectSurfaceBoundaries
2503 //=======================================================================
2504 void CorrectSurfaceBoundaries(const TopoDS_Face& theFace,
2505 const Standard_Real theTolerance,
2506 Standard_Real& theumin,
2507 Standard_Real& theumax,
2508 Standard_Real& thevmin,
2509 Standard_Real& thevmax)
2511 Standard_Boolean enlarge, isuperiodic, isvperiodic;
2512 Standard_Real uinf, usup, vinf, vsup, delta;
2513 GeomAbs_SurfaceType aType;
2514 Handle(Geom_Surface) aSurface;
2516 aSurface = BRep_Tool::Surface(theFace);
2517 aSurface->Bounds(uinf, usup, vinf, vsup);
2518 delta = theTolerance;
2519 enlarge = Standard_False;
2521 GeomAdaptor_Surface anAdaptorSurface(aSurface);
2523 if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
2524 Handle(Geom_Surface) aBasisSurface =
2525 (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface))->BasisSurface();
2527 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2528 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2533 if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2534 Handle(Geom_Surface) aBasisSurface =
2535 (Handle(Geom_OffsetSurface)::DownCast(aSurface))->BasisSurface();
2537 if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) ||
2538 aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) {
2543 isuperiodic = anAdaptorSurface.IsUPeriodic();
2544 isvperiodic = anAdaptorSurface.IsVPeriodic();
2546 aType=anAdaptorSurface.GetType();
2547 if((aType==GeomAbs_BezierSurface) ||
2548 (aType==GeomAbs_BSplineSurface) ||
2549 (aType==GeomAbs_SurfaceOfExtrusion) ||
2550 (aType==GeomAbs_SurfaceOfRevolution)) {
2551 enlarge=Standard_True;
2554 if (aType==GeomAbs_Sphere) {
2558 if (dV+delta<M_PI) {
2559 enlarge=Standard_True;
2563 if(!isuperiodic && enlarge) {
2565 if((theumin - uinf) > delta )
2571 if((usup - theumax) > delta )
2577 if(!isvperiodic && enlarge) {
2578 if((thevmin - vinf) > delta ) {
2584 if((vsup - thevmax) > delta ) {
2593 Standard_Integer aNbP;
2594 Standard_Real aXP, dXfact, aXmid, aX1, aX2, aTolPA;
2596 aTolPA=Precision::Angular();
2599 aXP=anAdaptorSurface.UPeriod();
2600 dXfact=theumax-theumin;
2601 if (dXfact-aTolPA>aXP) {
2602 aXmid=0.5*(theumax+theumin);
2603 aNbP=RealToInt(aXmid/aXP);
2608 if (theumin>aTolPA) {
2609 aX1=theumin+aNbP*aXP;
2622 aXP=anAdaptorSurface.VPeriod();
2623 dXfact=thevmax-thevmin;
2624 if (dXfact-aTolPA>aXP) {
2625 aXmid=0.5*(thevmax+thevmin);
2626 aNbP=RealToInt(aXmid/aXP);
2631 if (thevmin>aTolPA) {
2632 aX1=thevmin+aNbP*aXP;
2645 if(isuperiodic || isvperiodic) {
2646 Standard_Boolean correct = Standard_False;
2647 Standard_Boolean correctU = Standard_False;
2648 Standard_Boolean correctV = Standard_False;
2650 TopExp_Explorer anExp;
2652 for(anExp.Init(theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
2653 if(BRep_Tool::IsClosed(TopoDS::Edge(anExp.Current()), theFace)) {
2654 correct = Standard_True;
2656 TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
2658 for(Standard_Integer i = 0; i < 2; i++) {
2660 anEdge.Orientation(TopAbs_FORWARD);
2663 anEdge.Orientation(TopAbs_REVERSED);
2665 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l);
2667 if(aCurve.IsNull()) {
2668 correct = Standard_False;
2671 Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve);
2673 if(aLine.IsNull()) {
2674 correct = Standard_False;
2677 gp_Dir2d anUDir(1., 0.);
2678 gp_Dir2d aVDir(0., 1.);
2679 Standard_Real anAngularTolerance = Precision::Angular();
2681 correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance);
2682 correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance);
2684 gp_Pnt2d pp1 = aCurve->Value(f);
2686 gp_Pnt2d pp2 = aCurve->Value(l);
2695 Standard_Real umin, vmin, umax, vmax;
2696 aBox.Get(umin, vmin, umax, vmax);
2698 if(isuperiodic && correctU) {
2703 if(theumax > umax) {
2707 if(isvperiodic && correctV) {
2719 // The block is dedicated to determine whether WLine [ifprm, ilprm]
2720 // crosses the degenerated zone on each given surface or not.
2721 // If Yes -> We will not use info about surfaces during approximation
2722 // because inside degenerated zone of the surface the approx. algo.
2723 // uses wrong values of normal, etc., and resulting curve will have
2724 // oscillations that we would not like to have.
2729 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2730 const Handle(Geom_Surface)& aS,
2731 const Standard_Integer iDir);
2733 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2734 const TopoDS_Face& aF1,
2735 const TopoDS_Face& aF2);
2736 //=======================================================================
2737 //function : NotUseSurfacesForApprox
2739 //=======================================================================
2740 Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1,
2741 const TopoDS_Face& aF2,
2742 const Handle(IntPatch_WLine)& WL,
2743 const Standard_Integer ifprm,
2744 const Standard_Integer ilprm)
2746 Standard_Boolean bPInDZ;
2748 Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve();
2750 const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm);
2751 bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2);
2756 const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm);
2757 bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2);
2761 //=======================================================================
2762 //function : IsPointInDegeneratedZone
2764 //=======================================================================
2765 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
2766 const TopoDS_Face& aF1,
2767 const TopoDS_Face& aF2)
2770 Standard_Boolean bFlag=Standard_True;
2771 Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22;
2772 Standard_Real U1, V1, U2, V2, aDelta, aD;
2775 Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1);
2776 aS1->Bounds(US11, US12, VS11, VS12);
2777 GeomAdaptor_Surface aGAS1(aS1);
2779 Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2);
2780 aS1->Bounds(US21, US22, VS21, VS22);
2781 GeomAdaptor_Surface aGAS2(aS2);
2783 //const gp_Pnt& aP=aP2S.Value();
2784 aP2S.Parameters(U1, V1, U2, V2);
2788 aD=aGAS1.UResolution(aDelta);
2789 aP2d.SetCoord(U1, V1);
2790 if (fabs(U1-US11) < aD) {
2791 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2796 if (fabs(U1-US12) < aD) {
2797 bFlag=IsDegeneratedZone(aP2d, aS1, 1);
2802 aD=aGAS1.VResolution(aDelta);
2803 if (fabs(V1-VS11) < aDelta) {
2804 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2809 if (fabs(V1-VS12) < aDelta) {
2810 bFlag=IsDegeneratedZone(aP2d, aS1, 2);
2816 aD=aGAS2.UResolution(aDelta);
2817 aP2d.SetCoord(U2, V2);
2818 if (fabs(U2-US21) < aDelta) {
2819 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2824 if (fabs(U2-US22) < aDelta) {
2825 bFlag=IsDegeneratedZone(aP2d, aS2, 1);
2830 aD=aGAS2.VResolution(aDelta);
2831 if (fabs(V2-VS21) < aDelta) {
2832 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2837 if (fabs(V2-VS22) < aDelta) {
2838 bFlag=IsDegeneratedZone(aP2d, aS2, 2);
2846 //=======================================================================
2847 //function : IsDegeneratedZone
2849 //=======================================================================
2850 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
2851 const Handle(Geom_Surface)& aS,
2852 const Standard_Integer iDir)
2854 Standard_Boolean bFlag=Standard_True;
2855 Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD;
2856 Standard_Real aXm, aYm, aXb, aYb, aXe, aYe;
2857 aS->Bounds(US1, US2, VS1, VS2);
2859 gp_Pnt aPm, aPb, aPe;
2864 aS->D0(aXm, aYm, aPm);
2881 aS->D0(aXb, aYb, aPb);
2882 aS->D0(aXe, aYe, aPe);
2884 d1=aPm.Distance(aPb);
2885 d2=aPm.Distance(aPe);
2886 if (d1 < dD && d2 < dD) {
2903 aS->D0(aXb, aYb, aPb);
2904 aS->D0(aXe, aYe, aPe);
2906 d1=aPm.Distance(aPb);
2907 d2=aPm.Distance(aPe);
2908 if (d1 < dD && d2 < dD) {
2916 //=========================================================================
2917 // static function : ComputePurgedWLine
2918 // purpose : Removes equal points (leave one of equal points) from theWLine
2919 // and recompute vertex parameters.
2920 // Returns new WLine or null WLine if the number
2921 // of the points is less than 2.
2922 //=========================================================================
2923 Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine) {
2925 Standard_Integer i, k, v, nb, nbvtx;
2926 Handle(IntPatch_WLine) aResult;
2927 nbvtx = theWLine->NbVertex();
2928 nb = theWLine->NbPnts();
2930 const IntSurf_PntOn2S& p1 = theWLine->Point(1);
2931 const IntSurf_PntOn2S& p2 = theWLine->Point(2);
2932 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
2937 Handle(IntPatch_WLine) aLocalWLine;
2938 Handle(IntPatch_WLine) aTmpWLine = theWLine;
2939 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
2940 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2941 for(i = 1; i <= nb; i++) {
2942 aLineOn2S->Add(theWLine->Point(i));
2945 for(v = 1; v <= nbvtx; v++) {
2946 aLocalWLine->AddVertex(theWLine->Vertex(v));
2949 for(i = 1; i <= aLineOn2S->NbPoints(); i++) {
2950 Standard_Integer aStartIndex = i + 1;
2951 Standard_Integer anEndIndex = i + 5;
2952 nb = aLineOn2S->NbPoints();
2953 anEndIndex = (anEndIndex > nb) ? nb : anEndIndex;
2955 if((aStartIndex > nb) || (anEndIndex <= 1)) {
2960 while(k <= anEndIndex) {
2963 IntSurf_PntOn2S p1 = aLineOn2S->Value(i);
2964 IntSurf_PntOn2S p2 = aLineOn2S->Value(k);
2966 if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
2967 aTmpWLine = aLocalWLine;
2968 aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
2970 for(v = 1; v <= aTmpWLine->NbVertex(); v++) {
2971 IntPatch_Point aVertex = aTmpWLine->Vertex(v);
2972 Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine();
2974 if(avertexindex >= k) {
2975 aVertex.SetParameter(aVertex.ParameterOnLine() - 1.);
2977 aLocalWLine->AddVertex(aVertex);
2979 aLineOn2S->RemovePoint(k);
2988 if(aLineOn2S->NbPoints() > 1) {
2989 aResult = aLocalWLine;
2994 //=======================================================================
2997 //=======================================================================
2998 void TolR3d(const TopoDS_Face& aF1,
2999 const TopoDS_Face& aF2,
3000 Standard_Real& myTolReached3d)
3002 Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
3004 aTolTresh=2.999999e-3;
3005 aTolF1 = BRep_Tool::Tolerance(aF1);
3006 aTolF2 = BRep_Tool::Tolerance(aF2);
3007 aTolFMax=Max(aTolF1, aTolF2);
3009 if (aTolFMax>aTolTresh) {
3010 myTolReached3d=aTolFMax;
3013 //=======================================================================
3014 //function : AdjustPeriodic
3016 //=======================================================================
3017 Standard_Real AdjustPeriodic(const Standard_Real theParameter,
3018 const Standard_Real parmin,
3019 const Standard_Real parmax,
3020 const Standard_Real thePeriod,
3021 Standard_Real& theOffset)
3023 Standard_Real aresult;
3026 aresult = theParameter;
3027 while(aresult < parmin) {
3028 aresult += thePeriod;
3029 theOffset += thePeriod;
3032 while(aresult > parmax) {
3033 aresult -= thePeriod;
3034 theOffset -= thePeriod;
3038 //=======================================================================
3039 //function : IsPointOnBoundary
3041 //=======================================================================
3042 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
3043 const Standard_Real theFirstBoundary,
3044 const Standard_Real theSecondBoundary,
3045 const Standard_Real theResolution,
3046 Standard_Boolean& IsOnFirstBoundary)
3048 Standard_Boolean bRet;
3050 Standard_Real adist;
3052 bRet=Standard_False;
3053 for(i = 0; i < 2; ++i) {
3054 IsOnFirstBoundary = (i == 0);
3055 if (IsOnFirstBoundary) {
3056 adist = fabs(theParameter - theFirstBoundary);
3059 adist = fabs(theParameter - theSecondBoundary);
3061 if(adist < theResolution) {
3067 // ------------------------------------------------------------------------------------------------
3068 // static function: FindPoint
3070 // ------------------------------------------------------------------------------------------------
3071 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3072 const gp_Pnt2d& theLastPoint,
3073 const Standard_Real theUmin,
3074 const Standard_Real theUmax,
3075 const Standard_Real theVmin,
3076 const Standard_Real theVmax,
3077 gp_Pnt2d& theNewPoint) {
3079 gp_Vec2d aVec(theFirstPoint, theLastPoint);
3080 Standard_Integer i = 0, j = 0;
3082 for(i = 0; i < 4; i++) {
3083 gp_Vec2d anOtherVec;
3084 gp_Vec2d anOtherVecNormal;
3085 gp_Pnt2d aprojpoint = theLastPoint;
3088 anOtherVec.SetX(0.);
3089 anOtherVec.SetY(1.);
3090 anOtherVecNormal.SetX(1.);
3091 anOtherVecNormal.SetY(0.);
3094 aprojpoint.SetX(theUmin);
3096 aprojpoint.SetX(theUmax);
3099 anOtherVec.SetX(1.);
3100 anOtherVec.SetY(0.);
3101 anOtherVecNormal.SetX(0.);
3102 anOtherVecNormal.SetY(1.);
3105 aprojpoint.SetY(theVmin);
3107 aprojpoint.SetY(theVmax);
3109 gp_Vec2d anormvec = aVec;
3110 anormvec.Normalize();
3111 RefineVector(anormvec);
3112 Standard_Real adot1 = anormvec.Dot(anOtherVecNormal);
3114 if(fabs(adot1) < Precision::Angular())
3116 Standard_Real adist = 0.;
3117 Standard_Boolean bIsOut = Standard_False;
3120 adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax);
3121 bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax);
3124 adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax);
3125 bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax);
3127 Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1;
3129 for(j = 0; j < 2; j++) {
3130 anoffset = (j == 0) ? anoffset : -anoffset;
3131 gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset));
3132 gp_Vec2d acurvec(theLastPoint, acurpoint);
3136 Standard_Real aDotX, anAngleX;
3138 aDotX = aVec.Dot(acurvec);
3139 anAngleX = aVec.Angle(acurvec);
3141 if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) {
3143 if((acurpoint.Y() >= theVmin) &&
3144 (acurpoint.Y() <= theVmax)) {
3145 theNewPoint = acurpoint;
3146 return Standard_True;
3150 if((acurpoint.X() >= theUmin) &&
3151 (acurpoint.X() <= theUmax)) {
3152 theNewPoint = acurpoint;
3153 return Standard_True;
3159 return Standard_False;
3163 // ------------------------------------------------------------------------------------------------
3164 // static function: FindPoint
3165 // purpose: Find point on the boundary of radial tangent zone
3166 // ------------------------------------------------------------------------------------------------
3167 Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint,
3168 const gp_Pnt2d& theLastPoint,
3169 const Standard_Real theUmin,
3170 const Standard_Real theUmax,
3171 const Standard_Real theVmin,
3172 const Standard_Real theVmax,
3173 const gp_Pnt2d& theTanZoneCenter,
3174 const Standard_Real theZoneRadius,
3175 Handle(GeomAdaptor_HSurface) theGASurface,
3176 gp_Pnt2d& theNewPoint) {
3177 theNewPoint = theLastPoint;
3179 if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) )
3180 return Standard_False;
3182 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3183 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3185 Standard_Real aRadius = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3186 gp_Ax22d anAxis( theTanZoneCenter, gp_Dir2d(1, 0), gp_Dir2d(0, 1) );
3187 gp_Circ2d aCircle( anAxis, aRadius );
3190 gp_Vec2d aDir( theLastPoint.XY() - theFirstPoint.XY() );
3191 Standard_Real aLength = aDir.Magnitude();
3192 if ( aLength <= gp::Resolution() )
3193 return Standard_False;
3194 gp_Lin2d aLine( theFirstPoint, aDir );
3197 Handle(Geom2d_Line) aCLine = new Geom2d_Line( aLine );
3198 Handle(Geom2d_TrimmedCurve) aC1 = new Geom2d_TrimmedCurve( aCLine, 0, aLength );
3199 Handle(Geom2d_Circle) aC2 = new Geom2d_Circle( aCircle );
3201 Standard_Real aTol = aRadius * 0.001;
3202 aTol = ( aTol < Precision::PConfusion() ) ? Precision::PConfusion() : aTol;
3204 Geom2dAPI_InterCurveCurve anIntersector;
3205 anIntersector.Init( aC1, aC2, aTol );
3207 if ( anIntersector.NbPoints() == 0 )
3208 return Standard_False;
3210 Standard_Boolean aFound = Standard_False;
3211 Standard_Real aMinDist = aLength * aLength;
3212 Standard_Integer i = 0;
3213 for ( i = 1; i <= anIntersector.NbPoints(); i++ ) {
3214 gp_Pnt2d aPInt = anIntersector.Point( i );
3215 if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) {
3216 if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) &&
3217 ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) {
3218 theNewPoint = aPInt;
3219 aFound = Standard_True;
3227 // ------------------------------------------------------------------------------------------------
3228 // static function: IsInsideTanZone
3229 // purpose: Check if point is inside a radial tangent zone
3230 // ------------------------------------------------------------------------------------------------
3231 Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint,
3232 const gp_Pnt2d& theTanZoneCenter,
3233 const Standard_Real theZoneRadius,
3234 Handle(GeomAdaptor_HSurface) theGASurface) {
3236 Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
3237 Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
3238 Standard_Real aRadiusSQR = ( aUResolution < aVResolution ) ? aUResolution : aVResolution;
3239 aRadiusSQR *= aRadiusSQR;
3240 if ( thePoint.SquareDistance( theTanZoneCenter ) <= aRadiusSQR )
3241 return Standard_True;
3242 return Standard_False;
3245 // ------------------------------------------------------------------------------------------------
3246 // static function: CheckTangentZonesExist
3247 // purpose: Check if tangent zone exists
3248 // ------------------------------------------------------------------------------------------------
3249 Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& theSurface1,
3250 const Handle(GeomAdaptor_HSurface)& theSurface2 )
3252 if ( ( theSurface1->GetType() != GeomAbs_Torus ) ||
3253 ( theSurface2->GetType() != GeomAbs_Torus ) )
3254 return Standard_False;
3256 gp_Torus aTor1 = theSurface1->Torus();
3257 gp_Torus aTor2 = theSurface2->Torus();
3259 if ( aTor1.Location().Distance( aTor2.Location() ) > Precision::Confusion() )
3260 return Standard_False;
3262 if ( ( fabs( aTor1.MajorRadius() - aTor2.MajorRadius() ) > Precision::Confusion() ) ||
3263 ( fabs( aTor1.MinorRadius() - aTor2.MinorRadius() ) > Precision::Confusion() ) )
3264 return Standard_False;
3266 if ( ( aTor1.MajorRadius() < aTor1.MinorRadius() ) ||
3267 ( aTor2.MajorRadius() < aTor2.MinorRadius() ) )
3268 return Standard_False;
3269 return Standard_True;
3272 // ------------------------------------------------------------------------------------------------
3273 // static function: ComputeTangentZones
3275 // ------------------------------------------------------------------------------------------------
3276 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
3277 const Handle(GeomAdaptor_HSurface)& theSurface2,
3278 const TopoDS_Face& theFace1,
3279 const TopoDS_Face& theFace2,
3280 Handle(TColgp_HArray1OfPnt2d)& theResultOnS1,
3281 Handle(TColgp_HArray1OfPnt2d)& theResultOnS2,
3282 Handle(TColStd_HArray1OfReal)& theResultRadius,
3283 const Handle(BOPInt_Context)& aContext)
3285 Standard_Integer aResult = 0;
3286 if ( !CheckTangentZonesExist( theSurface1, theSurface2 ) )
3290 TColgp_SequenceOfPnt2d aSeqResultS1, aSeqResultS2;
3291 TColStd_SequenceOfReal aSeqResultRad;
3293 gp_Torus aTor1 = theSurface1->Torus();
3294 gp_Torus aTor2 = theSurface2->Torus();
3296 gp_Ax2 anax1( aTor1.Location(), aTor1.Axis().Direction() );
3297 gp_Ax2 anax2( aTor2.Location(), aTor2.Axis().Direction() );
3298 Standard_Integer j = 0;
3300 for ( j = 0; j < 2; j++ ) {
3301 Standard_Real aCoef = ( j == 0 ) ? -1 : 1;
3302 Standard_Real aRadius1 = fabs(aTor1.MajorRadius() + aCoef * aTor1.MinorRadius());
3303 Standard_Real aRadius2 = fabs(aTor2.MajorRadius() + aCoef * aTor2.MinorRadius());
3305 gp_Circ aCircle1( anax1, aRadius1 );
3306 gp_Circ aCircle2( anax2, aRadius2 );
3308 // roughly compute radius of tangent zone for perpendicular case
3309 Standard_Real aCriteria = Precision::Confusion() * 0.5;
3311 Standard_Real aT1 = aCriteria;
3312 Standard_Real aT2 = aCriteria;
3314 // internal tangency
3315 Standard_Real aR = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3316 //aT1 = aCriteria * aCriteria + aR * aR - ( aR - aCriteria ) * ( aR - aCriteria );
3317 aT1 = 2. * aR * aCriteria;
3321 // external tangency
3322 Standard_Real aRb = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3323 Standard_Real aRm = ( aRadius1 < aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius();
3324 Standard_Real aDelta = aRb - aCriteria;
3326 aDelta -= aRm * aRm;
3327 aDelta /= 2. * (aRb - aRm);
3328 aDelta -= 0.5 * (aRb - aRm);
3330 aT1 = 2. * aRm * (aRm - aDelta);
3333 aCriteria = ( aT1 > aT2) ? aT1 : aT2;
3334 if ( aCriteria > 0 )
3335 aCriteria = sqrt( aCriteria );
3337 if ( aCriteria > 0.5 * aTor1.MinorRadius() ) {
3338 // too big zone -> drop to minimum
3339 aCriteria = Precision::Confusion();
3342 GeomAdaptor_Curve aC1( new Geom_Circle(aCircle1) );
3343 GeomAdaptor_Curve aC2( new Geom_Circle(aCircle2) );
3344 Extrema_ExtCC anExtrema(aC1, aC2, 0, 2. * M_PI, 0, 2. * M_PI,
3345 Precision::PConfusion(), Precision::PConfusion());
3347 if ( anExtrema.IsDone() ) {
3349 Standard_Integer i = 0;
3350 for ( i = 1; i <= anExtrema.NbExt(); i++ ) {
3351 if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria )
3354 Extrema_POnCurv P1, P2;
3355 anExtrema.Points( i, P1, P2 );
3357 Standard_Boolean bFoundResult = Standard_True;
3360 Standard_Integer surfit = 0;
3361 for ( surfit = 0; surfit < 2; surfit++ ) {
3362 GeomAPI_ProjectPointOnSurf& aProjector =
3363 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
3365 gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value();
3366 aProjector.Perform(aP3d);
3368 if(!aProjector.IsDone())
3369 bFoundResult = Standard_False;
3371 if(aProjector.LowerDistance() > aCriteria) {
3372 bFoundResult = Standard_False;
3375 Standard_Real foundU = 0, foundV = 0;
3376 aProjector.LowerDistanceParameters(foundU, foundV);
3378 pr1 = gp_Pnt2d( foundU, foundV );
3380 pr2 = gp_Pnt2d( foundU, foundV );
3384 if ( bFoundResult ) {
3385 aSeqResultS1.Append( pr1 );
3386 aSeqResultS2.Append( pr2 );
3387 aSeqResultRad.Append( aCriteria );
3389 // torus is u and v periodic
3390 const Standard_Real twoPI = M_PI + M_PI;
3391 Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()};
3392 Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()};
3394 // iteration on period bounds
3395 for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) {
3396 Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI;
3397 Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI;
3399 // iteration on surfaces
3400 for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) {
3401 Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp;
3402 Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp;
3403 TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2;
3404 TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2;
3406 if (fabs(arr1[0] - aBound) < Precision::PConfusion()) {
3407 aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) );
3408 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3409 aSeqResultRad.Append( aCriteria );
3411 if (fabs(arr1[1] - aBound) < Precision::PConfusion()) {
3412 aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) );
3413 aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
3414 aSeqResultRad.Append( aCriteria );
3422 aResult = aSeqResultRad.Length();
3424 if ( aResult > 0 ) {
3425 theResultOnS1 = new TColgp_HArray1OfPnt2d( 1, aResult );
3426 theResultOnS2 = new TColgp_HArray1OfPnt2d( 1, aResult );
3427 theResultRadius = new TColStd_HArray1OfReal( 1, aResult );
3429 for ( Standard_Integer i = 1 ; i <= aResult; i++ ) {
3430 theResultOnS1->SetValue( i, aSeqResultS1.Value(i) );
3431 theResultOnS2->SetValue( i, aSeqResultS2.Value(i) );
3432 theResultRadius->SetValue( i, aSeqResultRad.Value(i) );
3438 // ------------------------------------------------------------------------------------------------
3439 // static function: AdjustByNeighbour
3441 // ------------------------------------------------------------------------------------------------
3442 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint,
3443 const gp_Pnt2d& theOriginalPoint,
3444 Handle(GeomAdaptor_HSurface) theGASurface) {
3446 gp_Pnt2d ap1 = theaNeighbourPoint;
3447 gp_Pnt2d ap2 = theOriginalPoint;
3449 if ( theGASurface->IsUPeriodic() ) {
3450 Standard_Real aPeriod = theGASurface->UPeriod();
3451 gp_Pnt2d aPTest = ap2;
3452 Standard_Real aSqDistMin = 1.e+100;
3454 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3455 aPTest.SetX( theOriginalPoint.X() + aPeriod * pIt );
3456 Standard_Real dd = ap1.SquareDistance( aPTest );
3458 if ( dd < aSqDistMin ) {
3464 if ( theGASurface->IsVPeriodic() ) {
3465 Standard_Real aPeriod = theGASurface->VPeriod();
3466 gp_Pnt2d aPTest = ap2;
3467 Standard_Real aSqDistMin = 1.e+100;
3469 for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) {
3470 aPTest.SetY( theOriginalPoint.Y() + aPeriod * pIt );
3471 Standard_Real dd = ap1.SquareDistance( aPTest );
3473 if ( dd < aSqDistMin ) {
3482 // ------------------------------------------------------------------------------------------------
3483 //function: DecompositionOfWLine
3485 // ------------------------------------------------------------------------------------------------
3486 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
3487 const Handle(GeomAdaptor_HSurface)& theSurface1,
3488 const Handle(GeomAdaptor_HSurface)& theSurface2,
3489 const TopoDS_Face& theFace1,
3490 const TopoDS_Face& theFace2,
3491 const IntTools_LineConstructor& theLConstructor,
3492 const Standard_Boolean theAvoidLConstructor,
3493 IntPatch_SequenceOfLine& theNewLines,
3494 Standard_Real& theReachedTol3d,
3495 const Handle(BOPInt_Context)& aContext)
3498 Standard_Boolean bRet, bAvoidLineConstructor;
3499 Standard_Integer aNbPnts, aNbParts;
3501 bRet=Standard_False;
3502 aNbPnts=theWLine->NbPnts();
3503 bAvoidLineConstructor=theAvoidLConstructor;
3508 if (!bAvoidLineConstructor) {
3509 aNbParts=theLConstructor.NbParts();
3515 Standard_Boolean bIsPrevPointOnBoundary, bIsPointOnBoundary, bIsCurrentPointOnBoundary;
3516 Standard_Integer nblines, pit, i, j;
3518 TColStd_Array1OfListOfInteger anArrayOfLines(1, aNbPnts);
3519 TColStd_Array1OfInteger anArrayOfLineType(1, aNbPnts);
3520 TColStd_ListOfInteger aListOfPointIndex;
3522 Handle(TColgp_HArray1OfPnt2d) aTanZoneS1;
3523 Handle(TColgp_HArray1OfPnt2d) aTanZoneS2;
3524 Handle(TColStd_HArray1OfReal) aTanZoneRadius;
3525 Standard_Integer aNbZone = ComputeTangentZones( theSurface1, theSurface2, theFace1, theFace2,
3526 aTanZoneS1, aTanZoneS2, aTanZoneRadius, aContext);
3530 aTol=Precision::Confusion();
3532 bIsPrevPointOnBoundary=Standard_False;
3533 bIsPointOnBoundary=Standard_False;
3538 for(pit = 1; pit <= aNbPnts; ++pit) {
3539 Standard_Boolean bIsOnFirstBoundary, isperiodic;
3540 Standard_Real aResolution, aPeriod, alowerboundary, aupperboundary, U, V;
3541 Standard_Real aParameter, anoffset, anAdjustPar;
3542 Standard_Real umin, umax, vmin, vmax;
3544 bIsCurrentPointOnBoundary = Standard_False;
3545 const IntSurf_PntOn2S& aPoint = theWLine->Point(pit);
3548 for(i = 0; i < 2; ++i) {
3549 Handle(GeomAdaptor_HSurface) aGASurface = (!i) ? theSurface1 : theSurface2;
3550 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3552 aPoint.ParametersOnS1(U, V);
3555 aPoint.ParametersOnS2(U, V);
3558 for(j = 0; j < 2; j++) {
3559 isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3565 aResolution=aGASurface->UResolution(aTol);
3566 aPeriod=aGASurface->UPeriod();
3567 alowerboundary=umin;
3568 aupperboundary=umax;
3572 aResolution=aGASurface->VResolution(aTol);
3573 aPeriod=aGASurface->VPeriod();
3574 alowerboundary=vmin;
3575 aupperboundary=vmax;
3580 anAdjustPar = AdjustPeriodic(aParameter,
3586 bIsOnFirstBoundary = Standard_True;// ?
3588 IsPointOnBoundary(anAdjustPar,
3592 bIsOnFirstBoundary);
3594 if(bIsPointOnBoundary) {
3595 bIsCurrentPointOnBoundary = Standard_True;
3599 // check if a point belong to a tangent zone. Begin
3600 Standard_Integer zIt = 0;
3601 for ( zIt = 1; zIt <= aNbZone; zIt++ ) {
3602 gp_Pnt2d aPZone = (i == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3603 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3605 if ( IsInsideTanZone(gp_Pnt2d( U, V ), aPZone, aZoneRadius, aGASurface ) ) {
3606 // set boundary flag to split the curve by a tangent zone
3607 bIsPointOnBoundary = Standard_True;
3608 bIsCurrentPointOnBoundary = Standard_True;
3609 if ( theReachedTol3d < aZoneRadius ) {
3610 theReachedTol3d = aZoneRadius;
3616 }//for(j = 0; j < 2; j++) {
3618 if(bIsCurrentPointOnBoundary){
3621 }//for(i = 0; i < 2; ++i) {
3623 if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) {
3624 if(!aListOfPointIndex.IsEmpty()) {
3626 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3627 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3628 aListOfPointIndex.Clear();
3630 bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary;
3632 aListOfPointIndex.Append(pit);
3633 } //for(pit = 1; pit <= aNbPnts; ++pit) {
3635 if(!aListOfPointIndex.IsEmpty()) {
3637 anArrayOfLines.SetValue(nblines, aListOfPointIndex);
3638 anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
3639 aListOfPointIndex.Clear();
3643 return bRet; //Standard_False;
3647 // 2. Correct wlines.begin
3648 TColStd_Array1OfListOfInteger anArrayOfLineEnds(1, nblines);
3649 Handle(IntSurf_LineOn2S) aSeqOfPntOn2S = new IntSurf_LineOn2S();
3651 for(i = 1; i <= nblines; i++) {
3652 if(anArrayOfLineType.Value(i) != 0) {
3655 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
3656 if(aListOfIndex.Extent() < 2) {
3659 TColStd_ListOfInteger aListOfFLIndex;
3661 for(j = 0; j < 2; j++) {
3662 Standard_Integer aneighbourindex = (j == 0) ? (i - 1) : (i + 1);
3664 if((aneighbourindex < 1) || (aneighbourindex > nblines))
3667 if(anArrayOfLineType.Value(aneighbourindex) == 0)
3669 const TColStd_ListOfInteger& aNeighbour = anArrayOfLines.Value(aneighbourindex);
3670 Standard_Integer anIndex = (j == 0) ? aNeighbour.Last() : aNeighbour.First();
3671 const IntSurf_PntOn2S& aPoint = theWLine->Point(anIndex);
3673 IntSurf_PntOn2S aNewP = aPoint;
3675 for(Standard_Integer surfit = 0; surfit < 2; surfit++) {
3677 Handle(GeomAdaptor_HSurface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2;
3678 Standard_Real umin=0., umax=0., vmin=0., vmax=0.;
3679 aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
3680 Standard_Real U=0., V=0.;
3683 aNewP.ParametersOnS1(U, V);
3685 aNewP.ParametersOnS2(U, V);
3686 Standard_Integer nbboundaries = 0;
3688 Standard_Boolean bIsNearBoundary = Standard_False;
3689 Standard_Integer aZoneIndex = 0;
3690 Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1
3691 Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1
3694 for(Standard_Integer parit = 0; parit < 2; parit++) {
3695 Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3697 Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
3698 Standard_Real alowerboundary = (parit == 0) ? umin : vmin;
3699 Standard_Real aupperboundary = (parit == 0) ? umax : vmax;
3701 Standard_Real aParameter = (parit == 0) ? U : V;
3702 Standard_Boolean bIsOnFirstBoundary = Standard_True;
3706 IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3707 if(bIsPointOnBoundary) {
3708 bIsUBoundary = (parit == 0);
3709 bIsFirstBoundary = bIsOnFirstBoundary;
3714 Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3715 Standard_Real anoffset = 0.;
3716 Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
3719 IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
3720 if(bIsPointOnBoundary) {
3721 bIsUBoundary = (parit == 0);
3722 bIsFirstBoundary = bIsOnFirstBoundary;
3726 //check neighbourhood of boundary
3727 Standard_Real anEpsilon = aResolution * 100.;
3728 Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
3729 anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
3731 bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary,
3732 anEpsilon, bIsOnFirstBoundary);
3738 // check if a point belong to a tangent zone. Begin
3739 for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) {
3740 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
3741 Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
3743 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3744 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3745 Standard_Real nU1, nV1;
3748 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3750 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3751 gp_Pnt2d ap1(nU1, nV1);
3752 gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface );
3755 if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) {
3757 bIsNearBoundary = Standard_True;
3758 if ( theReachedTol3d < aZoneRadius ) {
3759 theReachedTol3d = aZoneRadius;
3763 // check if a point belong to a tangent zone. End
3764 Standard_Boolean bComputeLineEnd = Standard_False;
3766 if(nbboundaries == 2) {
3768 bComputeLineEnd = Standard_True;
3771 else if(nbboundaries == 1) {
3772 Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
3775 Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
3776 Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
3777 Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
3778 Standard_Real aParameter = (bIsUBoundary) ? U : V;
3779 Standard_Real anoffset = 0.;
3780 Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
3782 Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
3783 Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
3784 anotherPar += anoffset;
3785 Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3786 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
3787 Standard_Real nU1, nV1;
3790 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3792 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3794 Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
3795 Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
3796 bComputeLineEnd = Standard_True;
3797 Standard_Boolean bCheckAngle1 = Standard_False;
3798 Standard_Boolean bCheckAngle2 = Standard_False;
3800 Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
3801 Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
3803 if(((adist1 - adist2) > Precision::PConfusion()) &&
3804 (adist2 < (aPeriod / 4.))) {
3805 bCheckAngle1 = Standard_True;
3806 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
3808 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3809 aNewP.SetValue((surfit == 0), anewU, anewV);
3810 bCheckAngle1 = Standard_False;
3813 else if(adist1 < (aPeriod / 4.)) {
3814 bCheckAngle2 = Standard_True;
3815 aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
3817 if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
3818 bCheckAngle2 = Standard_False;
3822 if(bCheckAngle1 || bCheckAngle2) {
3823 // assume there are at least two points in line (see "if" above)
3824 Standard_Integer anindexother = aneighbourpointindex;
3826 while((anindexother <= aListOfIndex.Last()) && (anindexother >= aListOfIndex.First())) {
3827 anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
3828 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
3829 Standard_Real nU2, nV2;
3832 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3834 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3835 gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
3837 if(aVecOld.SquareMagnitude() <= (gp::Resolution() * gp::Resolution())) {
3841 Standard_Real anAngle = aNewVec.Angle(aVecOld);
3843 if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
3846 Standard_Real U1, U2, V1, V2;
3847 IntSurf_PntOn2S atmppoint = aNewP;
3848 atmppoint.SetValue((surfit == 0), anewU, anewV);
3849 atmppoint.Parameters(U1, V1, U2, V2);
3850 gp_Pnt P1 = theSurface1->Value(U1, V1);
3851 gp_Pnt P2 = theSurface2->Value(U2, V2);
3852 gp_Pnt P0 = aPoint.Value();
3854 if(P0.IsEqual(P1, aTol) &&
3855 P0.IsEqual(P2, aTol) &&
3856 P1.IsEqual(P2, aTol)) {
3857 bComputeLineEnd = Standard_False;
3858 aNewP.SetValue((surfit == 0), anewU, anewV);
3863 bComputeLineEnd = Standard_False;
3868 } // end while(anindexother...)
3872 else if ( bIsNearBoundary ) {
3873 bComputeLineEnd = Standard_True;
3876 if(bComputeLineEnd) {
3879 Standard_Boolean found = Standard_False;
3881 if ( bIsNearBoundary ) {
3882 // re-compute point near natural boundary or near tangent zone
3883 Standard_Real u1, v1, u2, v2;
3884 aNewP.Parameters( u1, v1, u2, v2 );
3886 anewpoint = gp_Pnt2d( u1, v1 );
3888 anewpoint = gp_Pnt2d( u2, v2 );
3890 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3891 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3892 Standard_Real nU1, nV1;
3895 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3897 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3898 gp_Pnt2d ap1(nU1, nV1);
3903 // exclude point from a tangent zone
3904 anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3905 gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex);
3906 Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex);
3908 if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax,
3909 aPZone, aZoneRadius, aGASurface, ap2) ) {
3911 found = Standard_True;
3914 else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
3915 // re-compute point near boundary if shifted on a period
3916 ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
3918 if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
3919 ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
3920 found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
3924 aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
3930 Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3931 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
3932 Standard_Real nU1, nV1;
3935 aNeighbourPoint.ParametersOnS1(nU1, nV1);
3937 aNeighbourPoint.ParametersOnS2(nU1, nV1);
3938 gp_Pnt2d ap1(nU1, nV1);
3939 gp_Pnt2d ap2(nU1, nV1);
3940 Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
3942 while((aneighbourpointindex2 <= aListOfIndex.Last()) && (aneighbourpointindex2 >= aListOfIndex.First())) {
3943 aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
3944 const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
3945 Standard_Real nU2, nV2;
3948 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
3950 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
3954 if(ap1.SquareDistance(ap2) > (gp::Resolution() * gp::Resolution())) {
3958 found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
3963 Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
3964 GeomAPI_ProjectPointOnSurf& aProjector =
3965 (surfit == 0) ? aContext->ProjPS(theFace2) : aContext->ProjPS(theFace1);
3966 Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
3968 Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
3970 gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
3971 aProjector.Perform(aP3d);
3973 if(aProjector.IsDone()) {
3974 if(aProjector.LowerDistance() < aCriteria) {
3975 Standard_Real foundU = U, foundV = V;
3976 aProjector.LowerDistanceParameters(foundU, foundV);
3978 //Correction of projected coordinates. Begin
3979 //Note, it may be shifted on a period
3980 Standard_Integer aneindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
3981 const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
3982 Standard_Real nUn, nVn;
3985 aNeighbourPoint.ParametersOnS2(nUn, nVn);
3987 aNeighbourPoint.ParametersOnS1(nUn, nVn);
3988 gp_Pnt2d aNeighbour2d(nUn, nVn);
3989 gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
3990 foundU = anAdjustedPoint.X();
3991 foundV = anAdjustedPoint.Y();
3993 if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
3994 ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
3995 // attempt to roughly re-compute point
3996 foundU = ( foundU < umin ) ? umin : foundU;
3997 foundU = ( foundU > umax ) ? umax : foundU;
3998 foundV = ( foundV < vmin ) ? vmin : foundV;
3999 foundV = ( foundV > vmax ) ? vmax : foundV;
4001 GeomAPI_ProjectPointOnSurf& aProjector2 =
4002 (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
4004 aP3d = aSurfaceOther->Value(foundU, foundV);
4005 aProjector2.Perform(aP3d);
4007 if(aProjector2.IsDone()) {
4008 if(aProjector2.LowerDistance() < aCriteria) {
4009 Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
4010 aProjector2.LowerDistanceParameters(foundU2, foundV2);
4011 anewpoint.SetX(foundU2);
4012 anewpoint.SetY(foundV2);
4016 //Correction of projected coordinates. End
4019 aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
4021 aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
4027 aSeqOfPntOn2S->Add(aNewP);
4028 aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
4030 anArrayOfLineEnds.SetValue(i, aListOfFLIndex);
4032 // Correct wlines.end
4034 // Split wlines.begin
4035 Standard_Integer nbiter;
4038 if (!bAvoidLineConstructor) {
4039 nbiter=theLConstructor.NbParts();
4042 for(j = 1; j <= nbiter; ++j) {
4043 Standard_Real fprm, lprm;
4044 Standard_Integer ifprm, ilprm;
4046 if(bAvoidLineConstructor) {
4048 ilprm = theWLine->NbPnts();
4051 theLConstructor.Part(j, fprm, lprm);
4052 ifprm = (Standard_Integer)fprm;
4053 ilprm = (Standard_Integer)lprm;
4056 Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S();
4058 for(i = 1; i <= nblines; i++) {
4059 if(anArrayOfLineType.Value(i) != 0) {
4062 const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
4064 if(aListOfIndex.Extent() < 2) {
4067 const TColStd_ListOfInteger& aListOfFLIndex = anArrayOfLineEnds.Value(i);
4068 Standard_Boolean bhasfirstpoint = (aListOfFLIndex.Extent() == 2);
4069 Standard_Boolean bhaslastpoint = (aListOfFLIndex.Extent() == 2);
4071 if(!bhasfirstpoint && !aListOfFLIndex.IsEmpty()) {
4072 bhasfirstpoint = (i != 1);
4075 if(!bhaslastpoint && !aListOfFLIndex.IsEmpty()) {
4076 bhaslastpoint = (i != nblines);
4078 Standard_Boolean bIsFirstInside = ((ifprm >= aListOfIndex.First()) && (ifprm <= aListOfIndex.Last()));
4079 Standard_Boolean bIsLastInside = ((ilprm >= aListOfIndex.First()) && (ilprm <= aListOfIndex.Last()));
4081 if(!bIsFirstInside && !bIsLastInside) {
4082 if((ifprm < aListOfIndex.First()) && (ilprm > aListOfIndex.Last())) {
4083 // append whole line, and boundaries if neccesary
4084 if(bhasfirstpoint) {
4085 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
4088 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4090 for(; anIt.More(); anIt.Next()) {
4091 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4096 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
4100 // check end of split line (end is almost always)
4101 Standard_Integer aneighbour = i + 1;
4102 Standard_Boolean bIsEndOfLine = Standard_True;
4104 if(aneighbour <= nblines) {
4105 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4107 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4108 (aListOfNeighbourIndex.IsEmpty())) {
4109 bIsEndOfLine = Standard_False;
4114 if(aLineOn2S->NbPoints() > 1) {
4115 Handle(IntPatch_WLine) aNewWLine =
4116 new IntPatch_WLine(aLineOn2S, Standard_False);
4117 theNewLines.Append(aNewWLine);
4119 aLineOn2S = new IntSurf_LineOn2S();
4124 // end if(!bIsFirstInside && !bIsLastInside)
4126 if(bIsFirstInside && bIsLastInside) {
4127 // append inside points between ifprm and ilprm
4128 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4130 for(; anIt.More(); anIt.Next()) {
4131 if((anIt.Value() < ifprm) || (anIt.Value() > ilprm))
4133 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4139 if(bIsFirstInside) {
4140 // append points from ifprm to last point + boundary point
4141 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4143 for(; anIt.More(); anIt.Next()) {
4144 if(anIt.Value() < ifprm)
4146 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4151 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
4154 // check end of split line (end is almost always)
4155 Standard_Integer aneighbour = i + 1;
4156 Standard_Boolean bIsEndOfLine = Standard_True;
4158 if(aneighbour <= nblines) {
4159 const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
4161 if((anArrayOfLineType.Value(aneighbour) != 0) &&
4162 (aListOfNeighbourIndex.IsEmpty())) {
4163 bIsEndOfLine = Standard_False;
4168 if(aLineOn2S->NbPoints() > 1) {
4169 Handle(IntPatch_WLine) aNewWLine =
4170 new IntPatch_WLine(aLineOn2S, Standard_False);
4171 theNewLines.Append(aNewWLine);
4173 aLineOn2S = new IntSurf_LineOn2S();
4176 // end if(bIsFirstInside)
4179 // append points from first boundary point to ilprm
4180 if(bhasfirstpoint) {
4181 const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
4184 TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
4186 for(; anIt.More(); anIt.Next()) {
4187 if(anIt.Value() > ilprm)
4189 const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
4193 //end if(bIsLastInside)
4197 if(aLineOn2S->NbPoints() > 1) {
4198 Handle(IntPatch_WLine) aNewWLine =
4199 new IntPatch_WLine(aLineOn2S, Standard_False);
4200 theNewLines.Append(aNewWLine);
4205 return Standard_True;
4208 // ------------------------------------------------------------------------------------------------
4209 // static function: ParameterOutOfBoundary
4210 // purpose: Computes a new parameter for given curve. The corresponding 2d points
4211 // does not lay on any boundary of given faces
4212 // ------------------------------------------------------------------------------------------------
4213 Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter,
4214 const Handle(Geom_Curve)& theCurve,
4215 const TopoDS_Face& theFace1,
4216 const TopoDS_Face& theFace2,
4217 const Standard_Real theOtherParameter,
4218 const Standard_Boolean bIncreasePar,
4219 Standard_Real& theNewParameter,
4220 const Handle(BOPInt_Context)& aContext)
4222 Standard_Boolean bIsComputed = Standard_False;
4223 theNewParameter = theParameter;
4225 Standard_Real acurpar = theParameter;
4226 TopAbs_State aState = TopAbs_ON;
4227 Standard_Integer iter = 0;
4228 Standard_Real asumtol = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
4229 Standard_Real adelta = asumtol * 0.1;
4230 adelta = (adelta < Precision::Confusion()) ? Precision::Confusion() : adelta;
4231 Handle(Geom_Surface) aSurf1 = BRep_Tool::Surface(theFace1);
4232 Handle(Geom_Surface) aSurf2 = BRep_Tool::Surface(theFace2);
4234 Standard_Real u1, u2, v1, v2;
4236 GeomAPI_ProjectPointOnSurf aPrj1;
4237 aSurf1->Bounds(u1, u2, v1, v2);
4238 aPrj1.Init(aSurf1, u1, u2, v1, v2);
4240 GeomAPI_ProjectPointOnSurf aPrj2;
4241 aSurf2->Bounds(u1, u2, v1, v2);
4242 aPrj2.Init(aSurf2, u1, u2, v1, v2);
4244 while(aState == TopAbs_ON) {
4249 gp_Pnt aPCurrent = theCurve->Value(acurpar);
4250 aPrj1.Perform(aPCurrent);
4251 Standard_Real U=0., V=0.;
4253 if(aPrj1.IsDone()) {
4254 aPrj1.LowerDistanceParameters(U, V);
4255 aState = aContext->StatePointFace(theFace1, gp_Pnt2d(U, V));
4258 if(aState != TopAbs_ON) {
4259 aPrj2.Perform(aPCurrent);
4261 if(aPrj2.IsDone()) {
4262 aPrj2.LowerDistanceParameters(U, V);
4263 aState = aContext->StatePointFace(theFace2, gp_Pnt2d(U, V));
4274 theNewParameter = acurpar;
4275 bIsComputed = Standard_True;
4278 if(acurpar >= theOtherParameter)
4279 theNewParameter = theOtherParameter;
4282 if(acurpar <= theOtherParameter)
4283 theNewParameter = theOtherParameter;
4289 //=======================================================================
4290 //function : IsCurveValid
4292 //=======================================================================
4293 Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve)
4295 if(thePCurve.IsNull())
4296 return Standard_False;
4298 Standard_Real tolint = 1.e-10;
4299 Geom2dAdaptor_Curve PCA;
4300 IntRes2d_Domain PCD;
4301 Geom2dInt_GInter PCI;
4303 Standard_Real pf = 0., pl = 0.;
4304 gp_Pnt2d pntf, pntl;
4306 if(!thePCurve->IsClosed() && !thePCurve->IsPeriodic()) {
4307 pf = thePCurve->FirstParameter();
4308 pl = thePCurve->LastParameter();
4309 pntf = thePCurve->Value(pf);
4310 pntl = thePCurve->Value(pl);
4311 PCA.Load(thePCurve);
4312 if(!PCA.IsPeriodic()) {
4313 if(PCA.FirstParameter() > pf) pf = PCA.FirstParameter();
4314 if(PCA.LastParameter() < pl) pl = PCA.LastParameter();
4316 PCD.SetValues(pntf,pf,tolint,pntl,pl,tolint);
4317 PCI.Perform(PCA,PCD,tolint,tolint);
4319 if(PCI.NbPoints() > 0) {
4320 return Standard_False;
4324 return Standard_True;
4327 //=======================================================================
4328 //static function : ApproxWithPCurves
4329 //purpose : for bug 20964 only
4330 //=======================================================================
4331 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
4332 const gp_Sphere& theSph)
4334 Standard_Boolean bRes = Standard_True;
4335 Standard_Real R1 = theCyl.Radius(), R2 = theSph.Radius();
4337 if(R1 < 2.*R2) return bRes;
4339 gp_Lin anCylAx(theCyl.Axis());
4341 Standard_Real aDist = anCylAx.Distance(theSph.Location());
4342 Standard_Real aDRel = Abs(aDist - R1)/R2;
4344 if(aDRel > .2) return bRes;
4346 Standard_Real par = ElCLib::Parameter(anCylAx, theSph.Location());
4347 gp_Pnt aP = ElCLib::Value(par, anCylAx);
4348 gp_Vec aV(aP, theSph.Location());
4350 Standard_Real dd = aV.Dot(theSph.Position().XDirection());
4352 if(aDist < R1 && dd > 0.) return Standard_False;
4353 if(aDist > R1 && dd < 0.) return Standard_False;
4358 //=======================================================================
4359 //function : PerformPlanes
4361 //=======================================================================
4362 void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
4363 const Handle(GeomAdaptor_HSurface)& theS2,
4364 const Standard_Real TolAng,
4365 const Standard_Real TolTang,
4366 const Standard_Boolean theApprox1,
4367 const Standard_Boolean theApprox2,
4368 IntTools_SequenceOfCurves& theSeqOfCurve,
4369 Standard_Boolean& theTangentFaces)
4372 gp_Pln aPln1 = theS1->Surface().Plane();
4373 gp_Pln aPln2 = theS2->Surface().Plane();
4375 IntAna_QuadQuadGeo aPlnInter(aPln1, aPln2, TolAng, TolTang);
4377 if(!aPlnInter.IsDone()) {
4378 theTangentFaces = Standard_False;
4382 IntAna_ResultType aResType = aPlnInter.TypeInter();
4384 if(aResType == IntAna_Same) {
4385 theTangentFaces = Standard_True;
4389 theTangentFaces = Standard_False;
4391 if(aResType == IntAna_Empty) {
4395 gp_Lin aLin = aPlnInter.Line(1);
4397 ProjLib_Plane aProj;
4400 aProj.Project(aLin);
4401 gp_Lin2d aLin2d1 = aProj.Line();
4404 aProj.Project(aLin);
4405 gp_Lin2d aLin2d2 = aProj.Line();
4407 //classify line2d1 relatively first plane
4408 Standard_Real P11, P12;
4409 Standard_Boolean IsCrossed = ClassifyLin2d(theS1, aLin2d1, TolTang, P11, P12);
4410 if(!IsCrossed) return;
4411 //classify line2d2 relatively second plane
4412 Standard_Real P21, P22;
4413 IsCrossed = ClassifyLin2d(theS2, aLin2d2, TolTang, P21, P22);
4414 if(!IsCrossed) return;
4416 //Analysis of parametric intervals: must have common part
4418 if(P21 >= P12) return;
4419 if(P22 <= P11) return;
4421 Standard_Real pmin, pmax;
4422 pmin = Max(P11, P21);
4423 pmax = Min(P12, P22);
4425 if(pmax - pmin <= TolTang) return;
4427 Handle(Geom_Line) aGLin = new Geom_Line(aLin);
4429 IntTools_Curve aCurve;
4430 Handle(Geom_TrimmedCurve) aGTLin = new Geom_TrimmedCurve(aGLin, pmin, pmax);
4432 aCurve.SetCurve(aGTLin);
4435 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d1);
4436 aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4439 Handle(Geom2d_Curve) H1;
4440 aCurve.SetFirstCurve2d(H1);
4443 Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d2);
4444 aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax));
4447 Handle(Geom2d_Curve) H1;
4448 aCurve.SetFirstCurve2d(H1);
4451 theSeqOfCurve.Append(aCurve);
4455 //=======================================================================
4456 //function : ClassifyLin2d
4458 //=======================================================================
4459 static inline Standard_Boolean INTER(const Standard_Real d1,
4460 const Standard_Real d2,
4461 const Standard_Real tol)
4463 return (d1 > tol && d2 < -tol) ||
4464 (d1 < -tol && d2 > tol) ||
4465 ((d1 <= tol && d1 >= -tol) && (d2 > tol || d2 < -tol)) ||
4466 ((d2 <= tol && d2 >= -tol) && (d1 > tol || d1 < -tol));
4468 static inline Standard_Boolean COINC(const Standard_Real d1,
4469 const Standard_Real d2,
4470 const Standard_Real tol)
4472 return (d1 <= tol && d1 >= -tol) && (d2 <= tol && d2 >= -tol);
4474 Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
4475 const gp_Lin2d& theLin2d,
4476 const Standard_Real theTol,
4477 Standard_Real& theP1,
4478 Standard_Real& theP2)
4481 Standard_Real xmin, xmax, ymin, ymax, d1, d2, A, B, C;
4482 Standard_Real par[2];
4483 Standard_Integer nbi = 0;
4485 xmin = theS->Surface().FirstUParameter();
4486 xmax = theS->Surface().LastUParameter();
4487 ymin = theS->Surface().FirstVParameter();
4488 ymax = theS->Surface().LastVParameter();
4490 theLin2d.Coefficients(A, B, C);
4492 //xmin, ymin <-> xmin, ymax
4493 d1 = A*xmin + B*ymin + C;
4494 d2 = A*xmin + B*ymax + C;
4496 if(INTER(d1, d2, theTol)) {
4497 //Intersection with boundary
4498 Standard_Real y = -(C + A*xmin)/B;
4499 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, y));
4502 else if (COINC(d1, d2, theTol)) {
4503 //Coincidence with boundary
4504 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4505 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4511 if(fabs(par[0]-par[1]) > theTol) {
4512 theP1 = Min(par[0], par[1]);
4513 theP2 = Max(par[0], par[1]);
4514 return Standard_True;
4516 else return Standard_False;
4520 //xmin, ymax <-> xmax, ymax
4522 d2 = A*xmax + B*ymax + C;
4524 if(d1 > theTol || d1 < -theTol) {//to avoid checking of
4525 //coincidence with the same point
4526 if(INTER(d1, d2, theTol)) {
4527 Standard_Real x = -(C + B*ymax)/A;
4528 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymax));
4531 else if (COINC(d1, d2, theTol)) {
4532 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax));
4533 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4540 if(fabs(par[0]-par[1]) > theTol) {
4541 theP1 = Min(par[0], par[1]);
4542 theP2 = Max(par[0], par[1]);
4543 return Standard_True;
4545 else return Standard_False;
4549 //xmax, ymax <-> xmax, ymin
4551 d2 = A*xmax + B*ymin + C;
4553 if(d1 > theTol || d1 < -theTol) {
4554 if(INTER(d1, d2, theTol)) {
4555 Standard_Real y = -(C + A*xmax)/B;
4556 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, y));
4559 else if (COINC(d1, d2, theTol)) {
4560 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax));
4561 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4567 if(fabs(par[0]-par[1]) > theTol) {
4568 theP1 = Min(par[0], par[1]);
4569 theP2 = Max(par[0], par[1]);
4570 return Standard_True;
4572 else return Standard_False;
4575 //xmax, ymin <-> xmin, ymin
4577 d2 = A*xmin + B*ymin + C;
4579 if(d1 > theTol || d1 < -theTol) {
4580 if(INTER(d1, d2, theTol)) {
4581 Standard_Real x = -(C + B*ymin)/A;
4582 par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymin));
4585 else if (COINC(d1, d2, theTol)) {
4586 par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin));
4587 par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin));
4593 if(fabs(par[0]-par[1]) > theTol) {
4594 theP1 = Min(par[0], par[1]);
4595 theP2 = Max(par[0], par[1]);
4596 return Standard_True;
4598 else return Standard_False;
4601 return Standard_False;
4605 //=======================================================================
4606 //function : ApproxParameters
4608 //=======================================================================
4609 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
4610 const Handle(GeomAdaptor_HSurface)& aHS2,
4611 Standard_Integer& iDegMin,
4612 Standard_Integer& iDegMax,
4613 Standard_Integer& iNbIter)
4616 GeomAbs_SurfaceType aTS1, aTS2;
4623 aTS1=aHS1->Surface().GetType();
4624 aTS2=aHS2->Surface().GetType();
4627 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4628 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4629 Standard_Real aRC, aRT, dR, aPC;
4630 gp_Cylinder aCylinder;
4633 aPC=Precision::Confusion();
4635 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4636 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4638 aRC=aCylinder.Radius();
4639 aRT=aTorus.MinorRadius();
4649 if (aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Cylinder) {
4653 //=======================================================================
4654 //function : Tolerances
4656 //=======================================================================
4657 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
4658 const Handle(GeomAdaptor_HSurface)& aHS2,
4659 Standard_Real& ,//aTolArc,
4660 Standard_Real& aTolTang,
4661 Standard_Real& ,//aUVMaxStep,
4662 Standard_Real& )//aDeflection)
4664 GeomAbs_SurfaceType aTS1, aTS2;
4666 aTS1=aHS1->Surface().GetType();
4667 aTS2=aHS2->Surface().GetType();
4670 if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) ||
4671 (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) {
4672 Standard_Real aRC, aRT, dR, aPC;
4673 gp_Cylinder aCylinder;
4676 aPC=Precision::Confusion();
4678 aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder();
4679 aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus();
4681 aRC=aCylinder.Radius();
4682 aRT=aTorus.MinorRadius();
4689 aTolTang=0.1*aTolTang;
4693 //=======================================================================
4694 //function : SortTypes
4696 //=======================================================================
4697 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
4698 const GeomAbs_SurfaceType aType2)
4700 Standard_Boolean bRet;
4701 Standard_Integer aI1, aI2;
4703 bRet=Standard_False;
4705 aI1=IndexType(aType1);
4706 aI2=IndexType(aType2);
4712 //=======================================================================
4713 //function : IndexType
4715 //=======================================================================
4716 Standard_Integer IndexType(const GeomAbs_SurfaceType aType)
4718 Standard_Integer aIndex;
4722 if (aType==GeomAbs_Plane) {
4725 else if (aType==GeomAbs_Cylinder) {
4728 else if (aType==GeomAbs_Cone) {
4731 else if (aType==GeomAbs_Sphere) {
4734 else if (aType==GeomAbs_Torus) {
4737 else if (aType==GeomAbs_BezierSurface) {
4740 else if (aType==GeomAbs_BSplineSurface) {
4743 else if (aType==GeomAbs_SurfaceOfRevolution) {
4746 else if (aType==GeomAbs_SurfaceOfExtrusion) {
4749 else if (aType==GeomAbs_OffsetSurface) {
4752 else if (aType==GeomAbs_OtherSurface) {
4757 //=======================================================================
4758 //function : DumpWLine
4760 //=======================================================================
4761 void DumpWLine(const Handle(IntPatch_WLine)& aWLine)
4763 Standard_Integer i, aNbPnts;
4764 Standard_Real aX, aY, aZ, aU1, aV1, aU2, aV2;
4766 printf(" *WLine\n");
4767 aNbPnts=aWLine->NbPnts();
4768 for (i=1; i<=aNbPnts; ++i) {
4769 const IntSurf_PntOn2S aPntOn2S=aWLine->Point(i);
4770 const gp_Pnt& aP3D=aPntOn2S.Value();
4771 aP3D.Coord(aX, aY, aZ);
4772 aPntOn2S.Parameters(aU1, aV1, aU2, aV2);
4774 printf("point p_%d %lf %lf %lf\n", i, aX, aY, aZ);
4775 //printf("point p_%d %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf\n",
4776 // i, aX, aY, aZ, aU1, aV1, aU2, aV2);
4779 //=======================================================================
4780 //function : RefineVector
4782 //=======================================================================
4783 void RefineVector(gp_Vec2d& aV2D)
4785 Standard_Integer k,m;
4786 Standard_Real aC[2], aEps, aR1, aR2, aNum;
4792 aV2D.Coord(aC[0], aC[1]);
4794 for (k=0; k<2; ++k) {
4797 if (aNum>aR1 && aNum<aR2) {
4808 aV2D.SetCoord(aC[0], aC[1]);
4810 //=======================================================================
4811 //function : FindMaxSquareDistance
4813 //=======================================================================
4814 Standard_Real FindMaxSquareDistance (const Standard_Real aT1,
4815 const Standard_Real aT2,
4816 const Standard_Real aEps,
4817 const Handle(Geom_Curve)& aC3D,
4818 const Handle(Geom2d_Curve)& aC2D1,
4819 const Handle(Geom2d_Curve)& aC2D2,
4820 const Handle(GeomAdaptor_HSurface)& myHS1,
4821 const Handle(GeomAdaptor_HSurface)& myHS2,
4822 const TopoDS_Face& myFace1,
4823 const TopoDS_Face& myFace2,
4824 const Handle(BOPInt_Context)& myContext)
4826 Standard_Real aA, aB, aCf, aX1, aX2, aF1, aF2, aX, aF;
4828 aCf=1.6180339887498948482045868343656;// =0.5*(1.+sqrt(5.));
4832 aF1=MaxSquareDistance(aX1,
4833 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4835 aF2=MaxSquareDistance(aX2,
4836 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4840 if (fabs(aA-aB)<aEps) {
4842 aF=MaxSquareDistance(aX,
4843 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4851 aF2=MaxSquareDistance(aX2,
4852 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4860 aF1=MaxSquareDistance(aX1,
4861 aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
4866 //=======================================================================
4867 //function : MaxSquareDistance
4869 //=======================================================================
4870 Standard_Real MaxSquareDistance (const Standard_Real aT,
4871 const Handle(Geom_Curve)& aC3D,
4872 const Handle(Geom2d_Curve)& aC2D1,
4873 const Handle(Geom2d_Curve)& aC2D2,
4874 const Handle(GeomAdaptor_HSurface) myHS1,
4875 const Handle(GeomAdaptor_HSurface) myHS2,
4876 const TopoDS_Face& aF1,
4877 const TopoDS_Face& aF2,
4878 const Handle(BOPInt_Context)& aCtx)
4880 Standard_Boolean bIsDone;
4882 Standard_Real aU, aV, aD2Max, aD2;
4889 if (aC3D.IsNull()) {
4893 for (i=0; i<2; ++i) {
4894 const Handle(GeomAdaptor_HSurface)& aGHS=(!i) ? myHS1 : myHS2;
4895 const TopoDS_Face &aF=(!i) ? aF1 : aF2;
4896 const Handle(Geom2d_Curve)& aC2D=(!i) ? aC2D1 : aC2D2;
4898 if (!aC2D.IsNull()) {
4901 aGHS->D0(aU, aV, aPS);
4902 aD2=aP.SquareDistance(aPS);
4908 GeomAPI_ProjectPointOnSurf& aProjector=aCtx->ProjPS(aF);
4910 aProjector.Perform(aP);
4911 bIsDone=aProjector.IsDone();
4913 aProjector.LowerDistanceParameters(aU, aV);
4914 aGHS->D0(aU, aV, aPS);
4915 aD2=aP.SquareDistance(aPS);
4925 //=======================================================================
4926 //function : CheckPCurve
4927 //purpose : Checks if points of the pcurve are out of the face bounds.
4928 //=======================================================================
4929 Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
4930 const TopoDS_Face& aFace)
4932 const Standard_Integer NPoints = 23;
4933 Standard_Real umin,umax,vmin,vmax;
4935 BRepTools::UVBounds(aFace, umin, umax, vmin, vmax);
4936 Standard_Real tolU = Max ((umax-umin)*0.01, Precision::Confusion());
4937 Standard_Real tolV = Max ((vmax-vmin)*0.01, Precision::Confusion());
4938 Standard_Real fp = aPC->FirstParameter();
4939 Standard_Real lp = aPC->LastParameter();
4940 Standard_Real step = (lp-fp)/(NPoints+1);
4942 // adjust domain for periodic surfaces
4943 TopLoc_Location aLoc;
4944 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc);
4945 if (aSurf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)))
4946 aSurf = (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf))->BasisSurface();
4948 gp_Pnt2d pnt = aPC->Value((fp+lp)/2);
4952 if (aSurf->IsUPeriodic()) {
4953 Standard_Real aPer = aSurf->UPeriod();
4954 Standard_Integer nshift = (Standard_Integer) ((u-umin)/aPer);
4955 if (u < umin+aPer*nshift) nshift--;
4956 umin += aPer*nshift;
4957 umax += aPer*nshift;
4959 if (aSurf->IsVPeriodic()) {
4960 Standard_Real aPer = aSurf->VPeriod();
4961 Standard_Integer nshift = (Standard_Integer) ((v-vmin)/aPer);
4962 if (v < vmin+aPer*nshift) nshift--;
4963 vmin += aPer*nshift;
4964 vmax += aPer*nshift;
4968 for (i=1; i <= NPoints; i++) {
4969 Standard_Real p = fp + i * step;
4970 pnt = aPC->Value(p);
4972 if (umin-u > tolU || u-umax > tolU ||
4973 vmin-v > tolV || v-vmax > tolV)
4974 return Standard_False;
4976 return Standard_True;