Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2000-11-23 |
2 | // Created by: Michael KLOKOV | |
973c2be1 | 3 | // Copyright (c) 2000-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
d5f74e42 | 7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
11 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
7fd59977 | 15 | |
16 | #include <IntTools_FaceFace.ixx> | |
17 | ||
18 | #include <Precision.hxx> | |
19 | ||
20 | #include <TColStd_HArray1OfReal.hxx> | |
21 | #include <TColStd_Array1OfReal.hxx> | |
22 | #include <TColStd_Array1OfInteger.hxx> | |
23 | #include <TColStd_SequenceOfReal.hxx> | |
24 | #include <TColStd_ListOfInteger.hxx> | |
25 | #include <TColStd_ListIteratorOfListOfInteger.hxx> | |
26 | #include <TColStd_Array1OfListOfInteger.hxx> | |
27 | ||
28 | #include <gp_Lin2d.hxx> | |
29 | #include <gp_Ax22d.hxx> | |
30 | #include <gp_Circ2d.hxx> | |
31 | #include <gp_Torus.hxx> | |
32 | #include <gp_Cylinder.hxx> | |
33 | ||
34 | #include <Bnd_Box.hxx> | |
35 | ||
36 | #include <TColgp_HArray1OfPnt2d.hxx> | |
37 | #include <TColgp_SequenceOfPnt2d.hxx> | |
38 | #include <TColgp_Array1OfPnt.hxx> | |
39 | #include <TColgp_Array1OfPnt2d.hxx> | |
40 | ||
41 | #include <IntAna_QuadQuadGeo.hxx> | |
42 | ||
43 | #include <IntSurf_PntOn2S.hxx> | |
44 | #include <IntSurf_LineOn2S.hxx> | |
45 | #include <IntSurf_PntOn2S.hxx> | |
46 | #include <IntSurf_ListOfPntOn2S.hxx> | |
47 | #include <IntRes2d_Domain.hxx> | |
48 | #include <ProjLib_Plane.hxx> | |
49 | ||
50 | #include <IntPatch_GLine.hxx> | |
51 | #include <IntPatch_RLine.hxx> | |
52 | #include <IntPatch_WLine.hxx> | |
53 | #include <IntPatch_ALine.hxx> | |
54 | #include <IntPatch_ALineToWLine.hxx> | |
55 | ||
56 | #include <ElSLib.hxx> | |
57 | #include <ElCLib.hxx> | |
58 | ||
59 | #include <Extrema_ExtCC.hxx> | |
60 | #include <Extrema_POnCurv.hxx> | |
61 | #include <BndLib_AddSurface.hxx> | |
62 | ||
63 | #include <Adaptor3d_SurfacePtr.hxx> | |
64 | #include <Adaptor2d_HLine2d.hxx> | |
65 | ||
66 | #include <GeomAbs_SurfaceType.hxx> | |
67 | #include <GeomAbs_CurveType.hxx> | |
68 | ||
69 | #include <Geom_Surface.hxx> | |
70 | #include <Geom_Line.hxx> | |
71 | #include <Geom_Circle.hxx> | |
72 | #include <Geom_Ellipse.hxx> | |
73 | #include <Geom_Parabola.hxx> | |
74 | #include <Geom_Hyperbola.hxx> | |
75 | #include <Geom_TrimmedCurve.hxx> | |
76 | #include <Geom_BSplineCurve.hxx> | |
77 | #include <Geom_RectangularTrimmedSurface.hxx> | |
78 | #include <Geom_OffsetSurface.hxx> | |
79 | #include <Geom_Curve.hxx> | |
80 | #include <Geom_Conic.hxx> | |
81 | ||
82 | #include <Geom2d_TrimmedCurve.hxx> | |
83 | #include <Geom2d_BSplineCurve.hxx> | |
84 | #include <Geom2d_Line.hxx> | |
85 | #include <Geom2d_Curve.hxx> | |
86 | #include <Geom2d_Circle.hxx> | |
87 | ||
88 | #include <Geom2dAPI_InterCurveCurve.hxx> | |
89 | #include <Geom2dInt_GInter.hxx> | |
90 | #include <GeomAdaptor_Curve.hxx> | |
91 | #include <GeomAdaptor_HSurface.hxx> | |
92 | #include <GeomAdaptor_Surface.hxx> | |
93 | #include <GeomLib_CheckBSplineCurve.hxx> | |
94 | #include <GeomLib_Check2dBSplineCurve.hxx> | |
95 | ||
96 | #include <GeomInt_WLApprox.hxx> | |
97 | #include <GeomProjLib.hxx> | |
98 | #include <GeomAPI_ProjectPointOnSurf.hxx> | |
99 | #include <Geom2dAdaptor_Curve.hxx> | |
7fd59977 | 100 | #include <TopoDS.hxx> |
101 | #include <TopoDS_Edge.hxx> | |
102 | #include <TopExp_Explorer.hxx> | |
103 | ||
104 | #include <BRep_Tool.hxx> | |
105 | #include <BRepTools.hxx> | |
106 | #include <BRepAdaptor_Surface.hxx> | |
107 | ||
7fd59977 | 108 | #include <IntTools_Curve.hxx> |
109 | #include <IntTools_Tools.hxx> | |
110 | #include <IntTools_Tools.hxx> | |
111 | #include <IntTools_TopolTool.hxx> | |
112 | #include <IntTools_PntOnFace.hxx> | |
113 | #include <IntTools_PntOn2Faces.hxx> | |
1e143abb | 114 | #include <IntTools_Context.hxx> |
0fc4f2e2 | 115 | #include <IntSurf_ListIteratorOfListOfPntOn2S.hxx> |
2a78ec6a | 116 | #include <GeomInt.hxx> |
a2eede02 | 117 | |
fa9681ca P |
118 | static |
119 | void RefineVector(gp_Vec2d& aV2D); | |
0797d9d3 | 120 | #ifdef OCCT_DEBUG_DUMPWLINE |
a2eede02 P |
121 | static |
122 | void DumpWLine(const Handle(IntPatch_WLine)& aWLine); | |
4e18e72a | 123 | #endif |
7fd59977 | 124 | // |
125 | static | |
126 | void TolR3d(const TopoDS_Face& , | |
655fddc8 | 127 | const TopoDS_Face& , |
128 | Standard_Real& ); | |
7fd59977 | 129 | static |
130 | Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)&, | |
655fddc8 | 131 | const Standard_Integer, |
132 | const Standard_Integer); | |
7fd59977 | 133 | |
134 | static | |
135 | void Parameters(const Handle(GeomAdaptor_HSurface)&, | |
655fddc8 | 136 | const Handle(GeomAdaptor_HSurface)&, |
137 | const gp_Pnt&, | |
138 | Standard_Real&, | |
139 | Standard_Real&, | |
140 | Standard_Real&, | |
141 | Standard_Real&); | |
7fd59977 | 142 | |
143 | static | |
144 | void BuildPCurves (Standard_Real f,Standard_Real l,Standard_Real& Tol, | |
655fddc8 | 145 | const Handle (Geom_Surface)& S, |
146 | const Handle (Geom_Curve)& C, | |
147 | Handle (Geom2d_Curve)& C2d); | |
7fd59977 | 148 | |
149 | static | |
150 | void CorrectSurfaceBoundaries(const TopoDS_Face& theFace, | |
655fddc8 | 151 | const Standard_Real theTolerance, |
152 | Standard_Real& theumin, | |
153 | Standard_Real& theumax, | |
154 | Standard_Real& thevmin, | |
155 | Standard_Real& thevmax); | |
7fd59977 | 156 | static |
157 | Standard_Boolean NotUseSurfacesForApprox | |
158 | (const TopoDS_Face& aF1, | |
655fddc8 | 159 | const TopoDS_Face& aF2, |
160 | const Handle(IntPatch_WLine)& WL, | |
161 | const Standard_Integer ifprm, | |
162 | const Standard_Integer ilprm); | |
7fd59977 | 163 | |
164 | static | |
165 | Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine); | |
166 | ||
167 | static | |
7fd59977 | 168 | Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine, |
655fddc8 | 169 | const Standard_Integer ideb, |
170 | const Standard_Integer ifin, | |
171 | const Standard_Boolean onFirst); | |
7fd59977 | 172 | |
173 | static | |
174 | Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine, | |
655fddc8 | 175 | const Handle(GeomAdaptor_HSurface)& theSurface1, |
176 | const Handle(GeomAdaptor_HSurface)& theSurface2, | |
177 | const TopoDS_Face& theFace1, | |
178 | const TopoDS_Face& theFace2, | |
2a78ec6a | 179 | const GeomInt_LineConstructor& theLConstructor, |
655fddc8 | 180 | const Standard_Boolean theAvoidLConstructor, |
181 | IntPatch_SequenceOfLine& theNewLines, | |
182 | Standard_Real& theReachedTol3d, | |
1e143abb | 183 | const Handle(IntTools_Context)& ); |
7fd59977 | 184 | |
185 | static | |
186 | Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter, | |
655fddc8 | 187 | const Handle(Geom_Curve)& theCurve, |
188 | const TopoDS_Face& theFace1, | |
189 | const TopoDS_Face& theFace2, | |
190 | const Standard_Real theOtherParameter, | |
191 | const Standard_Boolean bIncreasePar, | |
192 | Standard_Real& theNewParameter, | |
1e143abb | 193 | const Handle(IntTools_Context)& ); |
7fd59977 | 194 | |
195 | static | |
196 | Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve); | |
197 | ||
198 | static | |
199 | Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter, | |
655fddc8 | 200 | const Standard_Real theFirstBoundary, |
201 | const Standard_Real theSecondBoundary, | |
202 | const Standard_Real theResolution, | |
203 | Standard_Boolean& IsOnFirstBoundary); | |
7fd59977 | 204 | static |
205 | Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint, | |
655fddc8 | 206 | const gp_Pnt2d& theLastPoint, |
207 | const Standard_Real theUmin, | |
208 | const Standard_Real theUmax, | |
209 | const Standard_Real theVmin, | |
210 | const Standard_Real theVmax, | |
211 | gp_Pnt2d& theNewPoint); | |
7fd59977 | 212 | |
213 | ||
214 | static | |
215 | Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1, | |
655fddc8 | 216 | const Handle(GeomAdaptor_HSurface)& theSurface2, |
217 | const TopoDS_Face& theFace1, | |
218 | const TopoDS_Face& theFace2, | |
219 | Handle(TColgp_HArray1OfPnt2d)& theResultOnS1, | |
220 | Handle(TColgp_HArray1OfPnt2d)& theResultOnS2, | |
221 | Handle(TColStd_HArray1OfReal)& theResultRadius, | |
1e143abb | 222 | const Handle(IntTools_Context)& ); |
7fd59977 | 223 | |
224 | static | |
225 | Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint, | |
655fddc8 | 226 | const gp_Pnt2d& theLastPoint, |
227 | const Standard_Real theUmin, | |
228 | const Standard_Real theUmax, | |
229 | const Standard_Real theVmin, | |
230 | const Standard_Real theVmax, | |
231 | const gp_Pnt2d& theTanZoneCenter, | |
232 | const Standard_Real theZoneRadius, | |
233 | Handle(GeomAdaptor_HSurface) theGASurface, | |
234 | gp_Pnt2d& theNewPoint); | |
7fd59977 | 235 | |
236 | static | |
237 | Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint, | |
655fddc8 | 238 | const gp_Pnt2d& theTanZoneCenter, |
239 | const Standard_Real theZoneRadius, | |
240 | Handle(GeomAdaptor_HSurface) theGASurface); | |
7fd59977 | 241 | |
242 | static | |
4f189102 | 243 | gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint, |
655fddc8 | 244 | const gp_Pnt2d& theOriginalPoint, |
245 | Handle(GeomAdaptor_HSurface) theGASurface); | |
7fd59977 | 246 | static |
4f189102 | 247 | Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl, |
655fddc8 | 248 | const gp_Sphere& theSph); |
7fd59977 | 249 | |
250 | static void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1, | |
655fddc8 | 251 | const Handle(GeomAdaptor_HSurface)& theS2, |
252 | const Standard_Real TolAng, | |
253 | const Standard_Real TolTang, | |
254 | const Standard_Boolean theApprox1, | |
255 | const Standard_Boolean theApprox2, | |
7fd59977 | 256 | IntTools_SequenceOfCurves& theSeqOfCurve, |
655fddc8 | 257 | Standard_Boolean& theTangentFaces); |
7fd59977 | 258 | |
259 | static Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS, | |
655fddc8 | 260 | const gp_Lin2d& theLin2d, |
261 | const Standard_Real theTol, | |
262 | Standard_Real& theP1, | |
263 | Standard_Real& theP2); | |
0fc4f2e2 | 264 | // |
7fd59977 | 265 | static |
266 | void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1, | |
655fddc8 | 267 | const Handle(GeomAdaptor_HSurface)& aHS2, |
268 | Standard_Integer& iDegMin, | |
269 | Standard_Integer& iNbIter, | |
270 | Standard_Integer& iDegMax); | |
7fd59977 | 271 | |
0fc4f2e2 P |
272 | static |
273 | void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1, | |
655fddc8 | 274 | const Handle(GeomAdaptor_HSurface)& aHS2, |
788cbaf4 | 275 | Standard_Real& aTolTang); |
0fc4f2e2 | 276 | |
0fc4f2e2 P |
277 | static |
278 | Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1, | |
655fddc8 | 279 | const GeomAbs_SurfaceType aType2); |
0fc4f2e2 P |
280 | static |
281 | Standard_Integer IndexType(const GeomAbs_SurfaceType aType); | |
d10203e8 | 282 | |
7fd59977 | 283 | // |
4f189102 P |
284 | static |
285 | Standard_Real MaxSquareDistance (const Standard_Real aT, | |
655fddc8 | 286 | const Handle(Geom_Curve)& aC3D, |
287 | const Handle(Geom2d_Curve)& aC2D1, | |
288 | const Handle(Geom2d_Curve)& aC2D2, | |
289 | const Handle(GeomAdaptor_HSurface) myHS1, | |
290 | const Handle(GeomAdaptor_HSurface) myHS2, | |
291 | const TopoDS_Face& aF1, | |
292 | const TopoDS_Face& aF2, | |
1e143abb | 293 | const Handle(IntTools_Context)& aCtx); |
989341c5 | 294 | |
295 | static | |
296 | Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC, | |
297 | const TopoDS_Face& aFace); | |
298 | ||
4f189102 | 299 | // |
37b6f439 | 300 | static |
301 | Standard_Real FindMaxSquareDistance (const Standard_Real aA, | |
655fddc8 | 302 | const Standard_Real aB, |
303 | const Standard_Real aEps, | |
304 | const Handle(Geom_Curve)& aC3D, | |
305 | const Handle(Geom2d_Curve)& aC2D1, | |
306 | const Handle(Geom2d_Curve)& aC2D2, | |
307 | const Handle(GeomAdaptor_HSurface)& myHS1, | |
308 | const Handle(GeomAdaptor_HSurface)& myHS2, | |
309 | const TopoDS_Face& aF1, | |
310 | const TopoDS_Face& aF2, | |
1e143abb | 311 | const Handle(IntTools_Context)& aCtx); |
37b6f439 | 312 | |
7fd59977 | 313 | //======================================================================= |
314 | //function : | |
315 | //purpose : | |
316 | //======================================================================= | |
4f189102 | 317 | IntTools_FaceFace::IntTools_FaceFace() |
7fd59977 | 318 | { |
3f16d970 | 319 | myIsDone=Standard_False; |
7fd59977 | 320 | myTangentFaces=Standard_False; |
321 | // | |
322 | myHS1 = new GeomAdaptor_HSurface (); | |
323 | myHS2 = new GeomAdaptor_HSurface (); | |
324 | myTolReached2d=0.; | |
325 | myTolReached3d=0.; | |
326 | SetParameters(Standard_True, Standard_True, Standard_True, 1.e-07); | |
4f189102 P |
327 | |
328 | } | |
329 | //======================================================================= | |
330 | //function : SetContext | |
331 | //purpose : | |
332 | //======================================================================= | |
1e143abb | 333 | void IntTools_FaceFace::SetContext(const Handle(IntTools_Context)& aContext) |
4f189102 P |
334 | { |
335 | myContext=aContext; | |
336 | } | |
337 | //======================================================================= | |
338 | //function : Context | |
339 | //purpose : | |
340 | //======================================================================= | |
1e143abb | 341 | const Handle(IntTools_Context)& IntTools_FaceFace::Context()const |
4f189102 P |
342 | { |
343 | return myContext; | |
7fd59977 | 344 | } |
345 | //======================================================================= | |
346 | //function : Face1 | |
347 | //purpose : | |
348 | //======================================================================= | |
4f189102 | 349 | const TopoDS_Face& IntTools_FaceFace::Face1() const |
7fd59977 | 350 | { |
351 | return myFace1; | |
352 | } | |
7fd59977 | 353 | //======================================================================= |
354 | //function : Face2 | |
355 | //purpose : | |
356 | //======================================================================= | |
4f189102 | 357 | const TopoDS_Face& IntTools_FaceFace::Face2() const |
7fd59977 | 358 | { |
359 | return myFace2; | |
360 | } | |
7fd59977 | 361 | //======================================================================= |
362 | //function : TangentFaces | |
363 | //purpose : | |
364 | //======================================================================= | |
4f189102 | 365 | Standard_Boolean IntTools_FaceFace::TangentFaces() const |
7fd59977 | 366 | { |
367 | return myTangentFaces; | |
368 | } | |
369 | //======================================================================= | |
370 | //function : Points | |
371 | //purpose : | |
372 | //======================================================================= | |
4f189102 | 373 | const IntTools_SequenceOfPntOn2Faces& IntTools_FaceFace::Points() const |
7fd59977 | 374 | { |
375 | return myPnts; | |
376 | } | |
377 | //======================================================================= | |
378 | //function : IsDone | |
379 | //purpose : | |
380 | //======================================================================= | |
4f189102 | 381 | Standard_Boolean IntTools_FaceFace::IsDone() const |
7fd59977 | 382 | { |
383 | return myIsDone; | |
384 | } | |
385 | //======================================================================= | |
386 | //function : TolReached3d | |
387 | //purpose : | |
388 | //======================================================================= | |
4f189102 | 389 | Standard_Real IntTools_FaceFace::TolReached3d() const |
7fd59977 | 390 | { |
391 | return myTolReached3d; | |
392 | } | |
393 | //======================================================================= | |
394 | //function : Lines | |
395 | //purpose : return lines of intersection | |
396 | //======================================================================= | |
4f189102 | 397 | const IntTools_SequenceOfCurves& IntTools_FaceFace::Lines() const |
7fd59977 | 398 | { |
4f189102 P |
399 | StdFail_NotDone_Raise_if |
400 | (!myIsDone, | |
788cbaf4 | 401 | "IntTools_FaceFace::Lines() => myIntersector NOT DONE"); |
7fd59977 | 402 | return mySeqOfCurve; |
403 | } | |
7fd59977 | 404 | //======================================================================= |
405 | //function : TolReached2d | |
406 | //purpose : | |
407 | //======================================================================= | |
4f189102 | 408 | Standard_Real IntTools_FaceFace::TolReached2d() const |
7fd59977 | 409 | { |
410 | return myTolReached2d; | |
411 | } | |
412 | // ======================================================================= | |
413 | // function: SetParameters | |
414 | // | |
415 | // ======================================================================= | |
4f189102 | 416 | void IntTools_FaceFace::SetParameters(const Standard_Boolean ToApproxC3d, |
655fddc8 | 417 | const Standard_Boolean ToApproxC2dOnS1, |
418 | const Standard_Boolean ToApproxC2dOnS2, | |
419 | const Standard_Real ApproximationTolerance) | |
7fd59977 | 420 | { |
421 | myApprox = ToApproxC3d; | |
422 | myApprox1 = ToApproxC2dOnS1; | |
423 | myApprox2 = ToApproxC2dOnS2; | |
424 | myTolApprox = ApproximationTolerance; | |
425 | } | |
426 | //======================================================================= | |
427 | //function : SetList | |
428 | //purpose : | |
429 | //======================================================================= | |
7fd59977 | 430 | void IntTools_FaceFace::SetList(IntSurf_ListOfPntOn2S& aListOfPnts) |
431 | { | |
432 | myListOfPnts = aListOfPnts; | |
433 | } | |
788cbaf4 | 434 | |
435 | ||
436 | static Standard_Boolean isTreatAnalityc(const TopoDS_Face& theF1, | |
437 | const TopoDS_Face& theF2) | |
438 | { | |
439 | const Standard_Real Tolang = 1.e-8; | |
440 | const Standard_Real aTolF1=BRep_Tool::Tolerance(theF1); | |
441 | const Standard_Real aTolF2=BRep_Tool::Tolerance(theF2); | |
442 | const Standard_Real aTolSum = aTolF1 + aTolF2; | |
443 | Standard_Real aHigh = 0.0; | |
444 | ||
445 | const BRepAdaptor_Surface aBAS1(theF1), aBAS2(theF2); | |
446 | const GeomAbs_SurfaceType aType1=aBAS1.GetType(); | |
447 | const GeomAbs_SurfaceType aType2=aBAS2.GetType(); | |
448 | ||
449 | gp_Pln aS1; | |
450 | gp_Cylinder aS2; | |
451 | if(aType1 == GeomAbs_Plane) | |
452 | { | |
453 | aS1=aBAS1.Plane(); | |
454 | } | |
455 | else if(aType2 == GeomAbs_Plane) | |
456 | { | |
457 | aS1=aBAS2.Plane(); | |
458 | } | |
459 | else | |
460 | { | |
461 | return Standard_True; | |
462 | } | |
463 | ||
464 | if(aType1 == GeomAbs_Cylinder) | |
465 | { | |
466 | aS2=aBAS1.Cylinder(); | |
467 | const Standard_Real VMin = aBAS1.FirstVParameter(); | |
468 | const Standard_Real VMax = aBAS1.LastVParameter(); | |
469 | ||
470 | if( Precision::IsNegativeInfinite(VMin) || | |
471 | Precision::IsPositiveInfinite(VMax)) | |
472 | return Standard_True; | |
473 | else | |
474 | aHigh = VMax - VMin; | |
475 | } | |
476 | else if(aType2 == GeomAbs_Cylinder) | |
477 | { | |
478 | aS2=aBAS2.Cylinder(); | |
479 | ||
480 | const Standard_Real VMin = aBAS2.FirstVParameter(); | |
481 | const Standard_Real VMax = aBAS2.LastVParameter(); | |
482 | ||
483 | if( Precision::IsNegativeInfinite(VMin) || | |
484 | Precision::IsPositiveInfinite(VMax)) | |
485 | return Standard_True; | |
486 | else | |
487 | aHigh = VMax - VMin; | |
488 | } | |
489 | else | |
490 | { | |
491 | return Standard_True; | |
492 | } | |
493 | ||
494 | IntAna_QuadQuadGeo inter; | |
495 | inter.Perform(aS1,aS2,Tolang,aTolSum, aHigh); | |
496 | if(inter.TypeInter() == IntAna_Ellipse) | |
497 | { | |
498 | const gp_Elips anEl = inter.Ellipse(1); | |
499 | const Standard_Real aMajorR = anEl.MajorRadius(); | |
500 | const Standard_Real aMinorR = anEl.MinorRadius(); | |
501 | ||
502 | return (aMajorR < 100000.0 * aMinorR); | |
503 | } | |
504 | else | |
505 | { | |
506 | return inter.IsDone(); | |
507 | } | |
508 | } | |
7fd59977 | 509 | //======================================================================= |
510 | //function : Perform | |
511 | //purpose : intersect surfaces of the faces | |
512 | //======================================================================= | |
59495dbe | 513 | void IntTools_FaceFace::Perform(const TopoDS_Face& aF1, |
c002793b | 514 | const TopoDS_Face& aF2) |
7fd59977 | 515 | { |
788cbaf4 | 516 | Standard_Boolean RestrictLine = Standard_False, hasCone = Standard_False; |
517 | ||
4f189102 | 518 | if (myContext.IsNull()) { |
1e143abb | 519 | myContext=new IntTools_Context; |
4f189102 | 520 | } |
788cbaf4 | 521 | |
7fd59977 | 522 | mySeqOfCurve.Clear(); |
7fd59977 | 523 | myTolReached2d=0.; |
524 | myTolReached3d=0.; | |
7fd59977 | 525 | myIsDone = Standard_False; |
0fc4f2e2 | 526 | myNbrestr=0;//? |
788cbaf4 | 527 | |
0fc4f2e2 P |
528 | myFace1=aF1; |
529 | myFace2=aF2; | |
788cbaf4 | 530 | |
531 | const BRepAdaptor_Surface aBAS1(myFace1, Standard_False); | |
532 | const BRepAdaptor_Surface aBAS2(myFace2, Standard_False); | |
533 | GeomAbs_SurfaceType aType1=aBAS1.GetType(); | |
534 | GeomAbs_SurfaceType aType2=aBAS2.GetType(); | |
535 | ||
536 | const Standard_Boolean bReverse=SortTypes(aType1, aType2); | |
537 | if (bReverse) | |
538 | { | |
0fc4f2e2 P |
539 | myFace1=aF2; |
540 | myFace2=aF1; | |
541 | aType1=aBAS2.GetType(); | |
542 | aType2=aBAS1.GetType(); | |
788cbaf4 | 543 | |
544 | if (myListOfPnts.Extent()) | |
545 | { | |
0fc4f2e2 P |
546 | Standard_Real aU1,aV1,aU2,aV2; |
547 | IntSurf_ListIteratorOfListOfPntOn2S aItP2S; | |
548 | // | |
549 | aItP2S.Initialize(myListOfPnts); | |
788cbaf4 | 550 | for (; aItP2S.More(); aItP2S.Next()) |
551 | { | |
655fddc8 | 552 | IntSurf_PntOn2S& aP2S=aItP2S.Value(); |
553 | aP2S.Parameters(aU1,aV1,aU2,aV2); | |
554 | aP2S.SetValue(aU2,aV2,aU1,aV1); | |
0fc4f2e2 P |
555 | } |
556 | } | |
2d2aa6f1 | 557 | // |
558 | Standard_Boolean anAproxTmp = myApprox1; | |
559 | myApprox1 = myApprox2; | |
560 | myApprox2 = anAproxTmp; | |
0fc4f2e2 | 561 | } |
7fd59977 | 562 | |
788cbaf4 | 563 | |
564 | const Handle(Geom_Surface) S1=BRep_Tool::Surface(myFace1); | |
565 | const Handle(Geom_Surface) S2=BRep_Tool::Surface(myFace2); | |
566 | ||
567 | const Standard_Real aTolF1=BRep_Tool::Tolerance(myFace1); | |
568 | const Standard_Real aTolF2=BRep_Tool::Tolerance(myFace2); | |
569 | ||
570 | Standard_Real TolArc = aTolF1 + aTolF2; | |
571 | Standard_Real TolTang = TolArc; | |
572 | ||
573 | const Standard_Boolean isFace1Quad = (aType1 == GeomAbs_Cylinder || | |
574 | aType1 == GeomAbs_Cone || | |
575 | aType1 == GeomAbs_Torus); | |
576 | ||
577 | const Standard_Boolean isFace2Quad = (aType2 == GeomAbs_Cylinder || | |
578 | aType2 == GeomAbs_Cone || | |
579 | aType2 == GeomAbs_Torus); | |
580 | ||
a34f083b | 581 | if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) { |
788cbaf4 | 582 | Standard_Real umin, umax, vmin, vmax; |
a34f083b | 583 | Standard_Real dU, dV; |
584 | // | |
0fc4f2e2 | 585 | BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax); |
a34f083b | 586 | dU=0.1*(umax-umin); |
587 | dV=0.1*(vmax-vmin); | |
588 | umin=umin-dU; | |
589 | umax=umax+dU; | |
590 | vmin=vmin-dV; | |
591 | vmax=vmax+dV; | |
7fd59977 | 592 | myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax); |
593 | // | |
0fc4f2e2 | 594 | BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax); |
a34f083b | 595 | dU=0.1*(umax-umin); |
596 | dV=0.1*(vmax-vmin); | |
597 | umin=umin-dU; | |
598 | umax=umax+dU; | |
599 | vmin=vmin-dV; | |
600 | vmax=vmax+dV; | |
7fd59977 | 601 | myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax); |
a34f083b | 602 | // |
7fd59977 | 603 | Standard_Real TolAng = 1.e-8; |
a34f083b | 604 | // |
59495dbe | 605 | PerformPlanes(myHS1, myHS2, TolAng, TolTang, myApprox1, myApprox2, |
a34f083b | 606 | mySeqOfCurve, myTangentFaces); |
607 | // | |
7fd59977 | 608 | myIsDone = Standard_True; |
4f189102 | 609 | |
a34f083b | 610 | if(!myTangentFaces) { |
788cbaf4 | 611 | const Standard_Integer NbLinPP = mySeqOfCurve.Length(); |
a34f083b | 612 | if(NbLinPP) { |
655fddc8 | 613 | Standard_Real aTolFMax; |
614 | myTolReached3d = 1.e-7; | |
615 | aTolFMax=Max(aTolF1, aTolF2); | |
a34f083b | 616 | if (aTolFMax>myTolReached3d) { |
655fddc8 | 617 | myTolReached3d=aTolFMax; |
618 | } | |
a34f083b | 619 | // |
655fddc8 | 620 | myTolReached2d = myTolReached3d; |
788cbaf4 | 621 | |
a34f083b | 622 | if (bReverse) { |
655fddc8 | 623 | Handle(Geom2d_Curve) aC2D1, aC2D2; |
788cbaf4 | 624 | const Standard_Integer aNbLin = mySeqOfCurve.Length(); |
a34f083b | 625 | for (Standard_Integer i = 1; i <= aNbLin; ++i) { |
655fddc8 | 626 | IntTools_Curve& aIC=mySeqOfCurve(i); |
627 | aC2D1=aIC.FirstCurve2d(); | |
628 | aC2D2=aIC.SecondCurve2d(); | |
629 | aIC.SetFirstCurve2d(aC2D2); | |
630 | aIC.SetSecondCurve2d(aC2D1); | |
631 | } | |
632 | } | |
0fc4f2e2 P |
633 | } |
634 | } | |
7fd59977 | 635 | return; |
0fc4f2e2 | 636 | }//if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){ |
788cbaf4 | 637 | |
638 | if ((aType1==GeomAbs_Plane) && isFace2Quad) | |
639 | { | |
7fd59977 | 640 | Standard_Real dU, dV; |
788cbaf4 | 641 | |
7fd59977 | 642 | // F1 |
788cbaf4 | 643 | Standard_Real umin, umax, vmin, vmax; |
0fc4f2e2 | 644 | BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax); |
788cbaf4 | 645 | |
7fd59977 | 646 | dU=0.1*(umax-umin); |
647 | dV=0.1*(vmax-vmin); | |
648 | umin=umin-dU; | |
649 | umax=umax+dU; | |
650 | vmin=vmin-dV; | |
651 | vmax=vmax+dV; | |
652 | myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax); | |
653 | // F2 | |
0fc4f2e2 P |
654 | BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax); |
655 | CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax); | |
7fd59977 | 656 | myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax); |
657 | // | |
658 | if( aType2==GeomAbs_Cone ) { | |
659 | TolArc = 0.0001; | |
7fd59977 | 660 | hasCone = Standard_True; |
661 | } | |
662 | } | |
788cbaf4 | 663 | else if ((aType2==GeomAbs_Plane) && isFace1Quad) |
664 | { | |
7fd59977 | 665 | Standard_Real dU, dV; |
788cbaf4 | 666 | |
7fd59977 | 667 | //F1 |
788cbaf4 | 668 | Standard_Real umin, umax, vmin, vmax; |
0fc4f2e2 P |
669 | BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax); |
670 | CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax); | |
7fd59977 | 671 | myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax); |
672 | // F2 | |
0fc4f2e2 | 673 | BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax); |
7fd59977 | 674 | dU=0.1*(umax-umin); |
675 | dV=0.1*(vmax-vmin); | |
676 | umin=umin-dU; | |
677 | umax=umax+dU; | |
678 | vmin=vmin-dV; | |
679 | vmax=vmax+dV; | |
680 | myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax); | |
681 | // | |
682 | if( aType1==GeomAbs_Cone ) { | |
683 | TolArc = 0.0001; | |
7fd59977 | 684 | hasCone = Standard_True; |
685 | } | |
686 | } | |
788cbaf4 | 687 | else |
688 | { | |
689 | Standard_Real umin, umax, vmin, vmax; | |
0fc4f2e2 | 690 | BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax); |
0fc4f2e2 | 691 | CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax); |
7fd59977 | 692 | myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax); |
0fc4f2e2 | 693 | BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax); |
0fc4f2e2 | 694 | CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax); |
7fd59977 | 695 | myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax); |
696 | } | |
788cbaf4 | 697 | |
698 | const Handle(IntTools_TopolTool) dom1 = new IntTools_TopolTool(myHS1); | |
699 | const Handle(IntTools_TopolTool) dom2 = new IntTools_TopolTool(myHS2); | |
700 | ||
7fd59977 | 701 | myLConstruct.Load(dom1, dom2, myHS1, myHS2); |
788cbaf4 | 702 | |
703 | ||
704 | Tolerances(myHS1, myHS2, TolTang); | |
705 | ||
706 | { | |
707 | const Standard_Real UVMaxStep = 0.001; | |
708 | const Standard_Real Deflection = (hasCone) ? 0.085 : 0.1; | |
59495dbe | 709 | myIntersector.SetTolerances(TolArc, TolTang, UVMaxStep, Deflection); |
788cbaf4 | 710 | } |
711 | ||
7fd59977 | 712 | if((myHS1->IsUClosed() && !myHS1->IsUPeriodic()) || |
713 | (myHS1->IsVClosed() && !myHS1->IsVPeriodic()) || | |
714 | (myHS2->IsUClosed() && !myHS2->IsUPeriodic()) || | |
788cbaf4 | 715 | (myHS2->IsVClosed() && !myHS2->IsVPeriodic())) |
716 | { | |
7fd59977 | 717 | RestrictLine = Standard_True; |
718 | } | |
719 | // | |
788cbaf4 | 720 | if((aType1 != GeomAbs_BSplineSurface) && |
59495dbe | 721 | (aType1 != GeomAbs_BezierSurface) && |
788cbaf4 | 722 | (aType1 != GeomAbs_OtherSurface) && |
723 | (aType2 != GeomAbs_BSplineSurface) && | |
59495dbe | 724 | (aType2 != GeomAbs_BezierSurface) && |
788cbaf4 | 725 | (aType2 != GeomAbs_OtherSurface)) |
726 | { | |
7fd59977 | 727 | RestrictLine = Standard_True; |
788cbaf4 | 728 | |
7fd59977 | 729 | if ((aType1 == GeomAbs_Torus) || |
788cbaf4 | 730 | (aType2 == GeomAbs_Torus)) |
731 | { | |
7fd59977 | 732 | myListOfPnts.Clear(); |
733 | } | |
734 | } | |
788cbaf4 | 735 | |
7fd59977 | 736 | // |
788cbaf4 | 737 | if(!RestrictLine) |
738 | { | |
7fd59977 | 739 | TopExp_Explorer aExp; |
788cbaf4 | 740 | for(Standard_Integer i = 0; (!RestrictLine) && (i < 2); i++) |
741 | { | |
7fd59977 | 742 | const TopoDS_Face& aF=(!i) ? myFace1 : myFace2; |
743 | aExp.Init(aF, TopAbs_EDGE); | |
788cbaf4 | 744 | for(; aExp.More(); aExp.Next()) |
745 | { | |
655fddc8 | 746 | const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current()); |
788cbaf4 | 747 | |
748 | if(BRep_Tool::Degenerated(aE)) | |
749 | { | |
655fddc8 | 750 | RestrictLine = Standard_True; |
751 | break; | |
752 | } | |
7fd59977 | 753 | } |
754 | } | |
755 | } | |
788cbaf4 | 756 | |
757 | const Standard_Boolean isGeomInt = isTreatAnalityc(aF1, aF2); | |
758 | myIntersector.Perform(myHS1, dom1, myHS2, dom2, TolArc, TolTang, | |
759 | myListOfPnts, RestrictLine, isGeomInt); | |
760 | ||
7fd59977 | 761 | myIsDone = myIntersector.IsDone(); |
788cbaf4 | 762 | |
763 | if (myIsDone) | |
764 | { | |
7fd59977 | 765 | myTangentFaces=myIntersector.TangentFaces(); |
766 | if (myTangentFaces) { | |
767 | return; | |
768 | } | |
769 | // | |
770 | if(RestrictLine) { | |
771 | myListOfPnts.Clear(); // to use LineConstructor | |
772 | } | |
773 | // | |
788cbaf4 | 774 | const Standard_Integer aNbLin = myIntersector.NbLines(); |
775 | for (Standard_Integer i=1; i <= aNbLin; ++i) { | |
7fd59977 | 776 | MakeCurve(i, dom1, dom2); |
777 | } | |
778 | // | |
779 | ComputeTolReached3d(); | |
780 | // | |
0fc4f2e2 P |
781 | if (bReverse) { |
782 | Handle(Geom2d_Curve) aC2D1, aC2D2; | |
783 | // | |
788cbaf4 | 784 | const Standard_Integer aNbLin=mySeqOfCurve.Length(); |
785 | for (Standard_Integer i=1; i<=aNbLin; ++i) | |
786 | { | |
655fddc8 | 787 | IntTools_Curve& aIC=mySeqOfCurve(i); |
788 | aC2D1=aIC.FirstCurve2d(); | |
789 | aC2D2=aIC.SecondCurve2d(); | |
790 | aIC.SetFirstCurve2d(aC2D2); | |
791 | aIC.SetSecondCurve2d(aC2D1); | |
0fc4f2e2 P |
792 | } |
793 | } | |
788cbaf4 | 794 | |
0fc4f2e2 | 795 | // Points |
7fd59977 | 796 | Standard_Real U1,V1,U2,V2; |
797 | IntTools_PntOnFace aPntOnF1, aPntOnF2; | |
0fc4f2e2 | 798 | IntTools_PntOn2Faces aPntOn2Faces; |
7fd59977 | 799 | // |
788cbaf4 | 800 | const Standard_Integer aNbPnts = myIntersector.NbPnts(); |
801 | for (Standard_Integer i=1; i <= aNbPnts; ++i) | |
802 | { | |
7fd59977 | 803 | const IntSurf_PntOn2S& aISPnt=myIntersector.Point(i).PntOn2S(); |
804 | const gp_Pnt& aPnt=aISPnt.Value(); | |
805 | aISPnt.Parameters(U1,V1,U2,V2); | |
0fc4f2e2 P |
806 | aPntOnF1.Init(myFace1, aPnt, U1, V1); |
807 | aPntOnF2.Init(myFace2, aPnt, U2, V2); | |
d10203e8 | 808 | // |
788cbaf4 | 809 | if (!bReverse) |
810 | { | |
655fddc8 | 811 | aPntOn2Faces.SetP1(aPntOnF1); |
812 | aPntOn2Faces.SetP2(aPntOnF2); | |
0fc4f2e2 | 813 | } |
788cbaf4 | 814 | else |
815 | { | |
655fddc8 | 816 | aPntOn2Faces.SetP2(aPntOnF1); |
817 | aPntOn2Faces.SetP1(aPntOnF2); | |
0fc4f2e2 | 818 | } |
788cbaf4 | 819 | |
7fd59977 | 820 | myPnts.Append(aPntOn2Faces); |
821 | } | |
7fd59977 | 822 | } |
823 | } | |
788cbaf4 | 824 | |
7fd59977 | 825 | //======================================================================= |
826 | //function :ComputeTolReached3d | |
827 | //purpose : | |
828 | //======================================================================= | |
829 | void IntTools_FaceFace::ComputeTolReached3d() | |
830 | { | |
128dba6f | 831 | Standard_Boolean bCase1; |
832 | Standard_Integer aNbLin, i; | |
7fd59977 | 833 | GeomAbs_SurfaceType aType1, aType2; |
834 | // | |
835 | aNbLin=myIntersector.NbLines(); | |
37b6f439 | 836 | if (!aNbLin) { |
837 | return; | |
838 | } | |
839 | // | |
7fd59977 | 840 | aType1=myHS1->Surface().GetType(); |
841 | aType2=myHS2->Surface().GetType(); | |
842 | // | |
128dba6f | 843 | bCase1=((aType1==GeomAbs_Plane && aType2==GeomAbs_SurfaceOfExtrusion) || |
4abae870 | 844 | (aType2==GeomAbs_Plane && aType1==GeomAbs_SurfaceOfExtrusion)); |
128dba6f | 845 | // |
4f189102 P |
846 | if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) { |
847 | if (aNbLin==2){ | |
848 | Handle(IntPatch_Line) aIL1, aIL2; | |
849 | IntPatch_IType aTL1, aTL2; | |
7fd59977 | 850 | // |
4f189102 P |
851 | aIL1=myIntersector.Line(1); |
852 | aIL2=myIntersector.Line(2); | |
853 | aTL1=aIL1->ArcType(); | |
854 | aTL2=aIL2->ArcType(); | |
855 | if (aTL1==IntPatch_Lin && aTL2==IntPatch_Lin) { | |
655fddc8 | 856 | Standard_Real aD, aDTresh, dTol; |
857 | gp_Lin aL1, aL2; | |
858 | // | |
859 | dTol=1.e-8; | |
860 | aDTresh=1.5e-6; | |
861 | // | |
862 | aL1=Handle(IntPatch_GLine)::DownCast(aIL1)->Line(); | |
863 | aL2=Handle(IntPatch_GLine)::DownCast(aIL2)->Line(); | |
864 | aD=aL1.Distance(aL2); | |
865 | aD=0.5*aD; | |
866 | if (aD<aDTresh) { | |
867 | myTolReached3d=aD+dTol; | |
868 | } | |
869 | return; | |
7fd59977 | 870 | } |
871 | } | |
4f189102 | 872 | //ZZ |
37b6f439 | 873 | if (aNbLin) {// Check the distances |
128dba6f | 874 | Standard_Integer aNbP, j ; |
575aec54 | 875 | Standard_Real aT1, aT2, dT, aD2, aD2Max, aEps, aT11, aT12; |
4f189102 P |
876 | // |
877 | aD2Max=0.; | |
0c5acd27 | 878 | aNbP=10; |
4f189102 P |
879 | aNbLin=mySeqOfCurve.Length(); |
880 | // | |
881 | for (i=1; i<=aNbLin; ++i) { | |
655fddc8 | 882 | const IntTools_Curve& aIC=mySeqOfCurve(i); |
883 | const Handle(Geom_Curve)& aC3D=aIC.Curve(); | |
884 | const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d(); | |
885 | const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d(); | |
886 | // | |
887 | if (aC3D.IsNull()) { | |
888 | continue; | |
889 | } | |
890 | const Handle(Geom_BSplineCurve)& aBC= | |
891 | Handle(Geom_BSplineCurve)::DownCast(aC3D); | |
892 | if (aBC.IsNull()) { | |
893 | continue; | |
894 | } | |
895 | // | |
896 | aT1=aBC->FirstParameter(); | |
897 | aT2=aBC->LastParameter(); | |
898 | // | |
899 | aEps=0.01*(aT2-aT1); | |
900 | dT=(aT2-aT1)/aNbP; | |
901 | for (j=1; j<aNbP; ++j) { | |
902 | aT11=aT1+j*dT; | |
903 | aT12=aT11+dT; | |
904 | aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2, | |
905 | myHS1, myHS2, myFace1, myFace2, myContext); | |
906 | if (aD2>aD2Max) { | |
907 | aD2Max=aD2; | |
908 | } | |
909 | } | |
4f189102 P |
910 | }//for (i=1; i<=aNbLin; ++i) { |
911 | // | |
912 | myTolReached3d=sqrt(aD2Max); | |
37b6f439 | 913 | }// if (aNbLin) |
4f189102 P |
914 | }// if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) { |
915 | // | |
0fc4f2e2 | 916 | //904/G3 f |
4f189102 | 917 | else if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) { |
7fd59977 | 918 | Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh; |
919 | // | |
920 | aTolTresh=1.e-7; | |
921 | // | |
922 | aTolF1 = BRep_Tool::Tolerance(myFace1); | |
923 | aTolF2 = BRep_Tool::Tolerance(myFace2); | |
924 | aTolFMax=Max(aTolF1, aTolF2); | |
925 | // | |
926 | if (aTolFMax>aTolTresh) { | |
927 | myTolReached3d=aTolFMax; | |
928 | } | |
4f189102 | 929 | }//if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) { |
0fc4f2e2 | 930 | //t |
7fd59977 | 931 | //IFV Bug OCC20297 |
4f189102 | 932 | else if((aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) || |
655fddc8 | 933 | (aType2 == GeomAbs_Cylinder && aType1 == GeomAbs_Plane)) { |
7fd59977 | 934 | if(aNbLin == 1) { |
935 | const Handle(IntPatch_Line)& aIL1 = myIntersector.Line(1); | |
936 | if(aIL1->ArcType() == IntPatch_Circle) { | |
655fddc8 | 937 | gp_Circ aCir = Handle(IntPatch_GLine)::DownCast(aIL1)->Circle(); |
938 | gp_XYZ aCirDir = aCir.Axis().Direction().XYZ(); | |
939 | gp_XYZ aPlDir; | |
940 | gp_Pln aPln; | |
941 | if(aType1 == GeomAbs_Plane) { | |
942 | aPln = myHS1->Surface().Plane(); | |
943 | } | |
944 | else { | |
945 | aPln = myHS2->Surface().Plane(); | |
946 | } | |
947 | aPlDir = aPln.Axis().Direction().XYZ(); | |
948 | Standard_Real cs = aCirDir*aPlDir; | |
949 | if(cs < 0.) aPlDir.Reverse(); | |
950 | Standard_Real eps = 1.e-14; | |
951 | if(!aPlDir.IsEqual(aCirDir, eps)) { | |
952 | Standard_Integer aNbP = 11; | |
953 | Standard_Real dt = 2.*M_PI / (aNbP - 1), t; | |
954 | for(t = 0.; t < 2.*M_PI; t += dt) { | |
955 | Standard_Real d = aPln.Distance(ElCLib::Value(t, aCir)); | |
956 | if(myTolReached3d < d) myTolReached3d = d; | |
957 | } | |
958 | myTolReached3d *= 1.1; | |
959 | } | |
7fd59977 | 960 | } //aIL1->ArcType() == IntPatch_Circle |
961 | } //aNbLin == 1 | |
4f189102 | 962 | } // aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) |
7fd59977 | 963 | //End IFV Bug OCC20297 |
0fc4f2e2 | 964 | // |
4f189102 | 965 | else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) || |
655fddc8 | 966 | (aType2==GeomAbs_Plane && aType1==GeomAbs_Torus)) { |
0fc4f2e2 P |
967 | aNbLin=mySeqOfCurve.Length(); |
968 | if (aNbLin!=1) { | |
969 | return; | |
970 | } | |
971 | // | |
128dba6f | 972 | Standard_Integer aNbP; |
0fc4f2e2 P |
973 | Standard_Real aT, aT1, aT2, dT, aUT, aVT, aUP, aVP; |
974 | Standard_Real aDP, aDT, aDmax; | |
975 | gp_Pln aPln; | |
976 | gp_Torus aTorus; | |
977 | gp_Pnt aP, aPP, aPT; | |
978 | // | |
979 | const IntTools_Curve& aIC=mySeqOfCurve(1); | |
980 | const Handle(Geom_Curve)& aC3D=aIC.Curve(); | |
4f189102 P |
981 | const Handle(Geom_BSplineCurve)& aBS= |
982 | Handle(Geom_BSplineCurve)::DownCast(aC3D); | |
0fc4f2e2 P |
983 | if (aBS.IsNull()) { |
984 | return; | |
985 | } | |
986 | // | |
987 | aT1=aBS->FirstParameter(); | |
988 | aT2=aBS->LastParameter(); | |
989 | // | |
990 | aPln =(aType1==GeomAbs_Plane) ? myHS1->Plane() : myHS2->Plane(); | |
991 | aTorus=(aType1==GeomAbs_Plane) ? myHS2->Torus() : myHS1->Torus(); | |
992 | // | |
993 | aDmax=-1.; | |
994 | aNbP=11; | |
995 | dT=(aT2-aT1)/(aNbP-1); | |
996 | for (i=0; i<aNbP; ++i) { | |
997 | aT=aT1+i*dT; | |
998 | if (i==aNbP-1) { | |
655fddc8 | 999 | aT=aT2; |
0fc4f2e2 P |
1000 | } |
1001 | // | |
1002 | aC3D->D0(aT, aP); | |
1003 | // | |
1004 | ElSLib::Parameters(aPln, aP, aUP, aVP); | |
1005 | aPP=ElSLib::Value(aUP, aVP, aPln); | |
1006 | aDP=aP.SquareDistance(aPP); | |
1007 | if (aDP>aDmax) { | |
655fddc8 | 1008 | aDmax=aDP; |
0fc4f2e2 P |
1009 | } |
1010 | // | |
1011 | ElSLib::Parameters(aTorus, aP, aUT, aVT); | |
1012 | aPT=ElSLib::Value(aUT, aVT, aTorus); | |
1013 | aDT=aP.SquareDistance(aPT); | |
1014 | if (aDT>aDmax) { | |
655fddc8 | 1015 | aDmax=aDT; |
0fc4f2e2 P |
1016 | } |
1017 | } | |
1018 | // | |
1019 | if (aDmax > myTolReached3d*myTolReached3d) { | |
1020 | myTolReached3d=sqrt(aDmax); | |
1021 | myTolReached3d=1.1*myTolReached3d; | |
1022 | } | |
1023 | }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) || | |
a9f7b6b5 | 1024 | // |
4f189102 | 1025 | else if ((aType1==GeomAbs_SurfaceOfRevolution && aType2==GeomAbs_Cylinder) || |
655fddc8 | 1026 | (aType2==GeomAbs_SurfaceOfRevolution && aType1==GeomAbs_Cylinder)) { |
128dba6f | 1027 | Standard_Integer j, aNbP; |
4f189102 | 1028 | Standard_Real aT, aT1, aT2, dT, aD2max, aD2; |
d10203e8 P |
1029 | // |
1030 | aNbLin=mySeqOfCurve.Length(); | |
4f189102 | 1031 | aD2max=0.; |
d10203e8 P |
1032 | aNbP=11; |
1033 | // | |
1034 | for (i=1; i<=aNbLin; ++i) { | |
1035 | const IntTools_Curve& aIC=mySeqOfCurve(i); | |
1036 | const Handle(Geom_Curve)& aC3D=aIC.Curve(); | |
1037 | const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d(); | |
1038 | const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d(); | |
1039 | // | |
1040 | if (aC3D.IsNull()) { | |
655fddc8 | 1041 | continue; |
d10203e8 | 1042 | } |
4f189102 | 1043 | const Handle(Geom_BSplineCurve)& aBC= |
655fddc8 | 1044 | Handle(Geom_BSplineCurve)::DownCast(aC3D); |
d10203e8 | 1045 | if (aBC.IsNull()) { |
655fddc8 | 1046 | return; |
d10203e8 P |
1047 | } |
1048 | // | |
1049 | aT1=aBC->FirstParameter(); | |
1050 | aT2=aBC->LastParameter(); | |
1051 | // | |
1052 | dT=(aT2-aT1)/(aNbP-1); | |
1053 | for (j=0; j<aNbP; ++j) { | |
655fddc8 | 1054 | aT=aT1+j*dT; |
1055 | if (j==aNbP-1) { | |
1056 | aT=aT2; | |
1057 | } | |
1058 | // | |
1059 | aD2=MaxSquareDistance(aT, aC3D, aC2D1, aC2D2, | |
1060 | myHS1, myHS2, myFace1, myFace2, myContext); | |
1061 | if (aD2>aD2max) { | |
1062 | aD2max=aD2; | |
1063 | } | |
d10203e8 | 1064 | }//for (j=0; j<aNbP; ++j) { |
37b6f439 | 1065 | |
d10203e8 P |
1066 | }//for (i=1; i<=aNbLin; ++i) { |
1067 | // | |
4f189102 P |
1068 | aD2=myTolReached3d*myTolReached3d; |
1069 | if (aD2max > aD2) { | |
1070 | myTolReached3d=sqrt(aD2max); | |
d10203e8 | 1071 | } |
a9f7b6b5 | 1072 | }//if((aType1==GeomAbs_SurfaceOfRevolution ... |
0c5acd27 | 1073 | else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) || |
655fddc8 | 1074 | (aType2==GeomAbs_Plane && aType1==GeomAbs_Sphere)) { |
128dba6f | 1075 | Standard_Integer j, aNbP; |
9c9a29ea | 1076 | Standard_Real aT1, aT2, dT, aD2max, aD2, aEps, aT11, aT12; |
0c5acd27 | 1077 | // |
1078 | aNbLin=mySeqOfCurve.Length(); | |
1079 | aD2max=0.; | |
1080 | aNbP=10; | |
1081 | // | |
1082 | for (i=1; i<=aNbLin; ++i) { | |
1083 | const IntTools_Curve& aIC=mySeqOfCurve(i); | |
1084 | const Handle(Geom_Curve)& aC3D=aIC.Curve(); | |
1085 | const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d(); | |
1086 | const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d(); | |
1087 | // | |
1088 | const Handle(Geom2d_BSplineCurve)& aBC2D1= | |
655fddc8 | 1089 | Handle(Geom2d_BSplineCurve)::DownCast(aC2D1); |
0c5acd27 | 1090 | const Handle(Geom2d_BSplineCurve)& aBC2D2= |
655fddc8 | 1091 | Handle(Geom2d_BSplineCurve)::DownCast(aC2D2); |
0c5acd27 | 1092 | // |
1093 | if (aBC2D1.IsNull() && aBC2D2.IsNull()) { | |
655fddc8 | 1094 | return; |
0c5acd27 | 1095 | } |
1096 | // | |
1097 | if (!aBC2D1.IsNull()) { | |
655fddc8 | 1098 | aT1=aBC2D1->FirstParameter(); |
1099 | aT2=aBC2D1->LastParameter(); | |
0c5acd27 | 1100 | } |
1101 | else { | |
655fddc8 | 1102 | aT1=aBC2D2->FirstParameter(); |
1103 | aT2=aBC2D2->LastParameter(); | |
0c5acd27 | 1104 | } |
1105 | // | |
1106 | aEps=0.01*(aT2-aT1); | |
9c9a29ea | 1107 | dT=(aT2-aT1)/aNbP; |
0c5acd27 | 1108 | for (j=0; j<aNbP; ++j) { |
655fddc8 | 1109 | aT11=aT1+j*dT; |
1110 | aT12=aT11+dT; | |
1111 | if (j==aNbP-1) { | |
1112 | aT12=aT2; | |
1113 | } | |
1114 | // | |
1115 | aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2, | |
1116 | myHS1, myHS2, myFace1, myFace2, myContext); | |
1117 | if (aD2>aD2max) { | |
1118 | aD2max=aD2; | |
1119 | } | |
0c5acd27 | 1120 | }//for (j=0; j<aNbP; ++j) { |
1121 | ||
1122 | }//for (i=1; i<=aNbLin; ++i) { | |
1123 | // | |
1124 | aD2=myTolReached3d*myTolReached3d; | |
1125 | if (aD2max > aD2) { | |
1126 | myTolReached3d=sqrt(aD2max); | |
1127 | } | |
1128 | }//else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ... | |
128dba6f | 1129 | else if (!myApprox || bCase1) { |
1130 | //else if (!myApprox) { | |
1131 | Standard_Integer aNbP, j; | |
4e57c75e | 1132 | Standard_Real aT1, aT2, dT, aD2, aD2Max, aEps, aT11, aT12; |
1133 | // | |
1134 | aD2Max=0.; | |
1135 | aNbLin=mySeqOfCurve.Length(); | |
1136 | // | |
1137 | for (i=1; i<=aNbLin; ++i) { | |
1138 | const IntTools_Curve& aIC=mySeqOfCurve(i); | |
1139 | const Handle(Geom_Curve)& aC3D=aIC.Curve(); | |
1140 | const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d(); | |
1141 | const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d(); | |
1142 | // | |
1143 | if (aC3D.IsNull()) { | |
4abae870 | 1144 | continue; |
59495dbe | 1145 | } |
4e57c75e | 1146 | const Handle(Geom_BSplineCurve)& aBC= |
4abae870 | 1147 | Handle(Geom_BSplineCurve)::DownCast(aC3D); |
4e57c75e | 1148 | if (aBC.IsNull()) { |
4abae870 | 1149 | continue; |
4e57c75e | 1150 | } |
1151 | // | |
1152 | aT1=aBC->FirstParameter(); | |
1153 | aT2=aBC->LastParameter(); | |
1154 | // | |
1155 | aEps=0.0001*(aT2-aT1); | |
1156 | aNbP=11; | |
1157 | dT=(aT2-aT1)/aNbP; | |
1158 | for (j=1; j<aNbP-1; ++j) { | |
4abae870 | 1159 | aT11=aT1+j*dT; |
1160 | aT12=aT11+dT; | |
1161 | aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2, | |
1162 | myHS1, myHS2, myFace1, myFace2, myContext); | |
1163 | if (aD2>aD2Max) { | |
1164 | aD2Max=aD2; | |
1165 | } | |
4e57c75e | 1166 | } |
1167 | }//for (i=1; i<=aNbLin; ++i) { | |
1168 | myTolReached3d=sqrt(aD2Max); | |
1169 | } | |
7fd59977 | 1170 | } |
1171 | //======================================================================= | |
1172 | //function : MakeCurve | |
1173 | //purpose : | |
1174 | //======================================================================= | |
1175 | void IntTools_FaceFace::MakeCurve(const Standard_Integer Index, | |
655fddc8 | 1176 | const Handle(Adaptor3d_TopolTool)& dom1, |
1177 | const Handle(Adaptor3d_TopolTool)& dom2) | |
7fd59977 | 1178 | { |
4abae870 | 1179 | Standard_Boolean bDone, rejectSurface, reApprox, bAvoidLineConstructor; |
1180 | Standard_Boolean ok, bPCurvesOk; | |
7fd59977 | 1181 | Standard_Integer i, j, aNbParts; |
1182 | Standard_Real fprm, lprm; | |
1183 | Standard_Real Tolpc; | |
1184 | Handle(IntPatch_Line) L; | |
1185 | IntPatch_IType typl; | |
1186 | Handle(Geom_Curve) newc; | |
1187 | // | |
1188 | const Standard_Real TOLCHECK =0.0000001; | |
1189 | const Standard_Real TOLANGCHECK=0.1; | |
1190 | // | |
1191 | rejectSurface = Standard_False; | |
1192 | reApprox = Standard_False; | |
989341c5 | 1193 | // |
1194 | bPCurvesOk = Standard_True; | |
59495dbe | 1195 | |
1196 | reapprox:; | |
1197 | ||
7fd59977 | 1198 | Tolpc = myTolApprox; |
1199 | bAvoidLineConstructor = Standard_False; | |
1200 | L = myIntersector.Line(Index); | |
1201 | typl = L->ArcType(); | |
1202 | // | |
1203 | if(typl==IntPatch_Walking) { | |
1204 | Handle(IntPatch_Line) anewL; | |
1205 | // | |
1206 | const Handle(IntPatch_WLine)& aWLine= | |
1207 | Handle(IntPatch_WLine)::DownCast(L); | |
4abae870 | 1208 | //DumpWLine(aWLine); |
1209 | ||
7fd59977 | 1210 | anewL = ComputePurgedWLine(aWLine); |
1211 | if(anewL.IsNull()) { | |
1212 | return; | |
1213 | } | |
1214 | L = anewL; | |
4abae870 | 1215 | |
1216 | //const Handle(IntPatch_WLine)& aWLineX = Handle(IntPatch_WLine)::DownCast(L); | |
1217 | //DumpWLine(aWLineX); | |
1218 | ||
7fd59977 | 1219 | // |
1220 | if(!myListOfPnts.IsEmpty()) { | |
1221 | bAvoidLineConstructor = Standard_True; | |
1222 | } | |
1223 | ||
1224 | Standard_Integer nbp = aWLine->NbPnts(); | |
1225 | const IntSurf_PntOn2S& p1 = aWLine->Point(1); | |
1226 | const IntSurf_PntOn2S& p2 = aWLine->Point(nbp); | |
1227 | ||
1228 | const gp_Pnt& P1 = p1.Value(); | |
1229 | const gp_Pnt& P2 = p2.Value(); | |
1230 | ||
1231 | if(P1.SquareDistance(P2) < 1.e-14) { | |
1232 | bAvoidLineConstructor = Standard_False; | |
1233 | } | |
7fd59977 | 1234 | } |
1235 | // | |
1236 | // Line Constructor | |
1237 | if(!bAvoidLineConstructor) { | |
1238 | myLConstruct.Perform(L); | |
1239 | // | |
1240 | bDone=myLConstruct.IsDone(); | |
1241 | aNbParts=myLConstruct.NbParts(); | |
1242 | if (!bDone|| !aNbParts) { | |
1243 | return; | |
1244 | } | |
1245 | } | |
1246 | // Do the Curve | |
59495dbe | 1247 | |
1248 | ||
7fd59977 | 1249 | typl=L->ArcType(); |
1250 | switch (typl) { | |
59495dbe | 1251 | //######################################## |
1252 | // Line, Parabola, Hyperbola | |
1253 | //######################################## | |
7fd59977 | 1254 | case IntPatch_Lin: |
1255 | case IntPatch_Parabola: | |
1256 | case IntPatch_Hyperbola: { | |
1257 | if (typl == IntPatch_Lin) { | |
1258 | newc = | |
655fddc8 | 1259 | new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line()); |
7fd59977 | 1260 | } |
1261 | ||
1262 | else if (typl == IntPatch_Parabola) { | |
1263 | newc = | |
655fddc8 | 1264 | new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola()); |
7fd59977 | 1265 | } |
59495dbe | 1266 | |
7fd59977 | 1267 | else if (typl == IntPatch_Hyperbola) { |
1268 | newc = | |
655fddc8 | 1269 | new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola()); |
7fd59977 | 1270 | } |
1271 | // | |
1272 | // myTolReached3d | |
1273 | if (typl == IntPatch_Lin) { | |
1274 | TolR3d (myFace1, myFace2, myTolReached3d); | |
1275 | } | |
1276 | // | |
1277 | aNbParts=myLConstruct.NbParts(); | |
1278 | for (i=1; i<=aNbParts; i++) { | |
1279 | myLConstruct.Part(i, fprm, lprm); | |
59495dbe | 1280 | |
7fd59977 | 1281 | if (!Precision::IsNegativeInfinite(fprm) && |
655fddc8 | 1282 | !Precision::IsPositiveInfinite(lprm)) { |
1283 | // | |
1284 | IntTools_Curve aCurve; | |
1285 | // | |
1286 | Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm); | |
1287 | aCurve.SetCurve(aCT3D); | |
1288 | if (typl == IntPatch_Parabola) { | |
1289 | Standard_Real aTolF1, aTolF2, aTolBase; | |
1290 | ||
1291 | aTolF1 = BRep_Tool::Tolerance(myFace1); | |
1292 | aTolF2 = BRep_Tool::Tolerance(myFace2); | |
1293 | aTolBase=aTolF1+aTolF2; | |
1294 | myTolReached3d=IntTools_Tools::CurveTolerance(aCT3D, aTolBase); | |
1295 | } | |
1296 | // | |
1297 | aCurve.SetCurve(new Geom_TrimmedCurve(newc, fprm, lprm)); | |
1298 | if(myApprox1) { | |
1299 | Handle (Geom2d_Curve) C2d; | |
1300 | BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d); | |
1301 | if(Tolpc>myTolReached2d || myTolReached2d==0.) { | |
1302 | myTolReached2d=Tolpc; | |
1303 | } | |
1304 | // | |
1305 | aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm)); | |
1306 | } | |
1307 | else { | |
1308 | Handle(Geom2d_BSplineCurve) H1; | |
1309 | // | |
1310 | aCurve.SetFirstCurve2d(H1); | |
1311 | } | |
1312 | ||
1313 | if(myApprox2) { | |
1314 | Handle (Geom2d_Curve) C2d; | |
1315 | BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d); | |
1316 | if(Tolpc>myTolReached2d || myTolReached2d==0.) { | |
1317 | myTolReached2d=Tolpc; | |
1318 | } | |
1319 | // | |
1320 | aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm)); | |
1321 | } | |
1322 | else { | |
1323 | Handle(Geom2d_BSplineCurve) H1; | |
1324 | // | |
1325 | aCurve.SetSecondCurve2d(H1); | |
1326 | } | |
1327 | mySeqOfCurve.Append(aCurve); | |
94218044 | 1328 | } // end of if (!Precision::IsNegativeInfinite(fprm) && !Precision::IsPositiveInfinite(lprm)) |
7fd59977 | 1329 | else { |
655fddc8 | 1330 | // on regarde si on garde |
1331 | // | |
1332 | Standard_Boolean bFNIt, bLPIt; | |
1333 | Standard_Real aTestPrm, dT=100.; | |
1334 | ||
1335 | bFNIt=Precision::IsNegativeInfinite(fprm); | |
1336 | bLPIt=Precision::IsPositiveInfinite(lprm); | |
1337 | ||
1338 | aTestPrm=0.; | |
1339 | ||
1340 | if (bFNIt && !bLPIt) { | |
1341 | aTestPrm=lprm-dT; | |
1342 | } | |
1343 | else if (!bFNIt && bLPIt) { | |
1344 | aTestPrm=fprm+dT; | |
1345 | } | |
1346 | ||
1347 | gp_Pnt ptref(newc->Value(aTestPrm)); | |
1348 | // | |
94218044 | 1349 | GeomAbs_SurfaceType typS1 = myHS1->GetType(); |
1350 | GeomAbs_SurfaceType typS2 = myHS2->GetType(); | |
1351 | if( typS1 == GeomAbs_SurfaceOfExtrusion || | |
1352 | typS1 == GeomAbs_OffsetSurface || | |
1353 | typS1 == GeomAbs_SurfaceOfRevolution || | |
1354 | typS2 == GeomAbs_SurfaceOfExtrusion || | |
1355 | typS2 == GeomAbs_OffsetSurface || | |
1356 | typS2 == GeomAbs_SurfaceOfRevolution) | |
1357 | { | |
1358 | Handle(Geom2d_BSplineCurve) H1; | |
1359 | mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1)); | |
1360 | continue; | |
1361 | } | |
1362 | ||
655fddc8 | 1363 | Standard_Real u1, v1, u2, v2, Tol; |
1364 | ||
1365 | Tol = Precision::Confusion(); | |
1366 | Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2); | |
1367 | ok = (dom1->Classify(gp_Pnt2d(u1, v1), Tol) != TopAbs_OUT); | |
1368 | if(ok) { | |
1369 | ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT); | |
1370 | } | |
1371 | if (ok) { | |
1372 | Handle(Geom2d_BSplineCurve) H1; | |
1373 | mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1)); | |
1374 | } | |
7fd59977 | 1375 | } |
1376 | }// end of for (i=1; i<=myLConstruct.NbParts(); i++) | |
1377 | }// case IntPatch_Lin: case IntPatch_Parabola: case IntPatch_Hyperbola: | |
59495dbe | 1378 | break; |
7fd59977 | 1379 | |
59495dbe | 1380 | //######################################## |
1381 | // Circle and Ellipse | |
1382 | //######################################## | |
7fd59977 | 1383 | case IntPatch_Circle: |
1384 | case IntPatch_Ellipse: { | |
1385 | ||
1386 | if (typl == IntPatch_Circle) { | |
1387 | newc = new Geom_Circle | |
655fddc8 | 1388 | (Handle(IntPatch_GLine)::DownCast(L)->Circle()); |
7fd59977 | 1389 | } |
1390 | else { //IntPatch_Ellipse | |
1391 | newc = new Geom_Ellipse | |
655fddc8 | 1392 | (Handle(IntPatch_GLine)::DownCast(L)->Ellipse()); |
7fd59977 | 1393 | } |
1394 | // | |
1395 | // myTolReached3d | |
1396 | TolR3d (myFace1, myFace2, myTolReached3d); | |
1397 | // | |
1398 | aNbParts=myLConstruct.NbParts(); | |
1399 | // | |
1400 | Standard_Real aPeriod, aNul; | |
1401 | TColStd_SequenceOfReal aSeqFprm, aSeqLprm; | |
59495dbe | 1402 | |
7fd59977 | 1403 | aNul=0.; |
c6541a0c | 1404 | aPeriod=M_PI+M_PI; |
7fd59977 | 1405 | |
1406 | for (i=1; i<=aNbParts; i++) { | |
1407 | myLConstruct.Part(i, fprm, lprm); | |
1408 | ||
1409 | if (fprm < aNul && lprm > aNul) { | |
655fddc8 | 1410 | // interval that goes through 0. is divided on two intervals; |
1411 | while (fprm<aNul || fprm>aPeriod) fprm=fprm+aPeriod; | |
1412 | while (lprm<aNul || lprm>aPeriod) lprm=lprm+aPeriod; | |
1413 | // | |
1414 | if((aPeriod - fprm) > Tolpc) { | |
1415 | aSeqFprm.Append(fprm); | |
1416 | aSeqLprm.Append(aPeriod); | |
1417 | } | |
1418 | else { | |
1419 | gp_Pnt P1 = newc->Value(fprm); | |
1420 | gp_Pnt P2 = newc->Value(aPeriod); | |
1421 | Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2); | |
1422 | aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist; | |
1423 | ||
1424 | if(P1.Distance(P2) > aTolDist) { | |
1425 | Standard_Real anewpar = fprm; | |
94218044 | 1426 | |
4abae870 | 1427 | if(ParameterOutOfBoundary(fprm, newc, myFace1, myFace2, |
1428 | lprm, Standard_False, anewpar, myContext)) { | |
655fddc8 | 1429 | fprm = anewpar; |
1430 | } | |
1431 | aSeqFprm.Append(fprm); | |
1432 | aSeqLprm.Append(aPeriod); | |
1433 | } | |
1434 | } | |
1435 | ||
1436 | // | |
1437 | if((lprm - aNul) > Tolpc) { | |
1438 | aSeqFprm.Append(aNul); | |
1439 | aSeqLprm.Append(lprm); | |
1440 | } | |
1441 | else { | |
1442 | gp_Pnt P1 = newc->Value(aNul); | |
1443 | gp_Pnt P2 = newc->Value(lprm); | |
1444 | Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2); | |
1445 | aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist; | |
1446 | ||
1447 | if(P1.Distance(P2) > aTolDist) { | |
1448 | Standard_Real anewpar = lprm; | |
94218044 | 1449 | |
4abae870 | 1450 | if(ParameterOutOfBoundary(lprm, newc, myFace1, myFace2, |
1451 | fprm, Standard_True, anewpar, myContext)) { | |
655fddc8 | 1452 | lprm = anewpar; |
1453 | } | |
1454 | aSeqFprm.Append(aNul); | |
1455 | aSeqLprm.Append(lprm); | |
1456 | } | |
1457 | } | |
7fd59977 | 1458 | } |
1459 | else { | |
655fddc8 | 1460 | // usual interval |
1461 | aSeqFprm.Append(fprm); | |
1462 | aSeqLprm.Append(lprm); | |
7fd59977 | 1463 | } |
1464 | } | |
59495dbe | 1465 | |
7fd59977 | 1466 | // |
1467 | aNbParts=aSeqFprm.Length(); | |
1468 | for (i=1; i<=aNbParts; i++) { | |
1469 | fprm=aSeqFprm(i); | |
1470 | lprm=aSeqLprm(i); | |
1471 | // | |
1472 | Standard_Real aRealEpsilon=RealEpsilon(); | |
c6541a0c | 1473 | if (Abs(fprm) > aRealEpsilon || Abs(lprm-2.*M_PI) > aRealEpsilon) { |
655fddc8 | 1474 | //============================================== |
1475 | //// | |
1476 | IntTools_Curve aCurve; | |
1477 | Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm); | |
1478 | aCurve.SetCurve(aTC3D); | |
1479 | fprm=aTC3D->FirstParameter(); | |
1480 | lprm=aTC3D->LastParameter (); | |
1481 | //// | |
1482 | if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {//// | |
1483 | if(myApprox1) { | |
1484 | Handle (Geom2d_Curve) C2d; | |
1485 | BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d); | |
1486 | if(Tolpc>myTolReached2d || myTolReached2d==0) { | |
1487 | myTolReached2d=Tolpc; | |
1488 | } | |
1489 | // | |
1490 | aCurve.SetFirstCurve2d(C2d); | |
1491 | } | |
1492 | else { //// | |
1493 | Handle(Geom2d_BSplineCurve) H1; | |
1494 | aCurve.SetFirstCurve2d(H1); | |
1495 | } | |
1496 | ||
1497 | ||
1498 | if(myApprox2) { | |
1499 | Handle (Geom2d_Curve) C2d; | |
1500 | BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d); | |
1501 | if(Tolpc>myTolReached2d || myTolReached2d==0) { | |
1502 | myTolReached2d=Tolpc; | |
1503 | } | |
1504 | // | |
1505 | aCurve.SetSecondCurve2d(C2d); | |
1506 | } | |
1507 | else { | |
1508 | Handle(Geom2d_BSplineCurve) H1; | |
1509 | aCurve.SetSecondCurve2d(H1); | |
1510 | } | |
1511 | } | |
1512 | ||
1513 | else { | |
1514 | Handle(Geom2d_BSplineCurve) H1; | |
1515 | aCurve.SetFirstCurve2d(H1); | |
1516 | aCurve.SetSecondCurve2d(H1); | |
1517 | } | |
1518 | mySeqOfCurve.Append(aCurve); | |
1519 | //============================================== | |
c6541a0c | 1520 | } //if (Abs(fprm) > RealEpsilon() || Abs(lprm-2.*M_PI) > RealEpsilon()) |
7fd59977 | 1521 | |
1522 | else { | |
655fddc8 | 1523 | // on regarde si on garde |
1524 | // | |
1525 | if (aNbParts==1) { | |
1526 | // if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*M_PI) < RealEpsilon()) { | |
1527 | if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*M_PI) <= aRealEpsilon) { | |
1528 | IntTools_Curve aCurve; | |
1529 | Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm); | |
1530 | aCurve.SetCurve(aTC3D); | |
1531 | fprm=aTC3D->FirstParameter(); | |
1532 | lprm=aTC3D->LastParameter (); | |
1533 | ||
1534 | if(myApprox1) { | |
1535 | Handle (Geom2d_Curve) C2d; | |
1536 | BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d); | |
1537 | if(Tolpc>myTolReached2d || myTolReached2d==0) { | |
1538 | myTolReached2d=Tolpc; | |
1539 | } | |
1540 | // | |
1541 | aCurve.SetFirstCurve2d(C2d); | |
1542 | } | |
1543 | else { //// | |
1544 | Handle(Geom2d_BSplineCurve) H1; | |
1545 | aCurve.SetFirstCurve2d(H1); | |
1546 | } | |
1547 | ||
1548 | if(myApprox2) { | |
1549 | Handle (Geom2d_Curve) C2d; | |
1550 | BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d); | |
1551 | if(Tolpc>myTolReached2d || myTolReached2d==0) { | |
1552 | myTolReached2d=Tolpc; | |
1553 | } | |
1554 | // | |
1555 | aCurve.SetSecondCurve2d(C2d); | |
1556 | } | |
1557 | else { | |
1558 | Handle(Geom2d_BSplineCurve) H1; | |
1559 | aCurve.SetSecondCurve2d(H1); | |
1560 | } | |
1561 | mySeqOfCurve.Append(aCurve); | |
1562 | break; | |
1563 | } | |
1564 | } | |
1565 | // | |
1566 | Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol; | |
1567 | ||
1568 | aTwoPIdiv17=2.*M_PI/17.; | |
1569 | ||
1570 | for (j=0; j<=17; j++) { | |
1571 | gp_Pnt ptref (newc->Value (j*aTwoPIdiv17)); | |
1572 | Tol = Precision::Confusion(); | |
1573 | ||
1574 | Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2); | |
1575 | ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT); | |
1576 | if(ok) { | |
1577 | ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT); | |
1578 | } | |
1579 | if (ok) { | |
1580 | IntTools_Curve aCurve; | |
1581 | aCurve.SetCurve(newc); | |
1582 | //============================================== | |
1583 | if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) { | |
1584 | ||
1585 | if(myApprox1) { | |
1586 | Handle (Geom2d_Curve) C2d; | |
1587 | BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d); | |
1588 | if(Tolpc>myTolReached2d || myTolReached2d==0) { | |
1589 | myTolReached2d=Tolpc; | |
1590 | } | |
1591 | // | |
1592 | aCurve.SetFirstCurve2d(C2d); | |
1593 | } | |
1594 | else { | |
1595 | Handle(Geom2d_BSplineCurve) H1; | |
1596 | aCurve.SetFirstCurve2d(H1); | |
1597 | } | |
1598 | ||
1599 | if(myApprox2) { | |
1600 | Handle (Geom2d_Curve) C2d; | |
1601 | BuildPCurves(fprm, lprm, Tolpc,myHS2->ChangeSurface().Surface(), newc, C2d); | |
1602 | if(Tolpc>myTolReached2d || myTolReached2d==0) { | |
1603 | myTolReached2d=Tolpc; | |
1604 | } | |
1605 | // | |
1606 | aCurve.SetSecondCurve2d(C2d); | |
1607 | } | |
1608 | ||
1609 | else { | |
1610 | Handle(Geom2d_BSplineCurve) H1; | |
1611 | aCurve.SetSecondCurve2d(H1); | |
1612 | } | |
1613 | }// end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) | |
1614 | ||
1615 | else { | |
1616 | Handle(Geom2d_BSplineCurve) H1; | |
1617 | // | |
1618 | aCurve.SetFirstCurve2d(H1); | |
1619 | aCurve.SetSecondCurve2d(H1); | |
1620 | } | |
1621 | //============================================== | |
1622 | // | |
1623 | mySeqOfCurve.Append(aCurve); | |
1624 | break; | |
1625 | ||
1626 | }// end of if (ok) { | |
1627 | }// end of for (Standard_Integer j=0; j<=17; j++) | |
1628 | }// end of else { on regarde si on garde | |
59495dbe | 1629 | }// for (i=1; i<=myLConstruct.NbParts(); i++) |
1630 | }// IntPatch_Circle: IntPatch_Ellipse: | |
1631 | break; | |
1632 | ||
7fd59977 | 1633 | case IntPatch_Analytic: { |
1634 | IntSurf_Quadric quad1,quad2; | |
1635 | GeomAbs_SurfaceType typs = myHS1->Surface().GetType(); | |
59495dbe | 1636 | |
7fd59977 | 1637 | switch (typs) { |
59495dbe | 1638 | case GeomAbs_Plane: |
1639 | quad1.SetValue(myHS1->Surface().Plane()); | |
655fddc8 | 1640 | break; |
59495dbe | 1641 | case GeomAbs_Cylinder: |
655fddc8 | 1642 | quad1.SetValue(myHS1->Surface().Cylinder()); |
1643 | break; | |
59495dbe | 1644 | case GeomAbs_Cone: |
655fddc8 | 1645 | quad1.SetValue(myHS1->Surface().Cone()); |
1646 | break; | |
59495dbe | 1647 | case GeomAbs_Sphere: |
655fddc8 | 1648 | quad1.SetValue(myHS1->Surface().Sphere()); |
1649 | break; | |
7eed5d29 | 1650 | case GeomAbs_Torus: |
1651 | quad1.SetValue(myHS1->Surface().Torus()); | |
1652 | break; | |
59495dbe | 1653 | default: |
655fddc8 | 1654 | Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 1"); |
59495dbe | 1655 | } |
1656 | ||
7fd59977 | 1657 | typs = myHS2->Surface().GetType(); |
59495dbe | 1658 | |
7fd59977 | 1659 | switch (typs) { |
59495dbe | 1660 | case GeomAbs_Plane: |
1661 | quad2.SetValue(myHS2->Surface().Plane()); | |
655fddc8 | 1662 | break; |
59495dbe | 1663 | case GeomAbs_Cylinder: |
655fddc8 | 1664 | quad2.SetValue(myHS2->Surface().Cylinder()); |
1665 | break; | |
59495dbe | 1666 | case GeomAbs_Cone: |
655fddc8 | 1667 | quad2.SetValue(myHS2->Surface().Cone()); |
1668 | break; | |
59495dbe | 1669 | case GeomAbs_Sphere: |
655fddc8 | 1670 | quad2.SetValue(myHS2->Surface().Sphere()); |
1671 | break; | |
7eed5d29 | 1672 | case GeomAbs_Torus: |
1673 | quad2.SetValue(myHS2->Surface().Torus()); | |
1674 | break; | |
59495dbe | 1675 | default: |
655fddc8 | 1676 | Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 2"); |
59495dbe | 1677 | } |
7fd59977 | 1678 | // |
1679 | //========= | |
1680 | IntPatch_ALineToWLine convert (quad1, quad2); | |
59495dbe | 1681 | |
7fd59977 | 1682 | if (!myApprox) { |
1683 | aNbParts=myLConstruct.NbParts(); | |
1684 | for (i=1; i<=aNbParts; i++) { | |
655fddc8 | 1685 | myLConstruct.Part(i, fprm, lprm); |
1686 | Handle(IntPatch_WLine) WL = | |
1687 | convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm); | |
1688 | // | |
1689 | Handle(Geom2d_BSplineCurve) H1; | |
1690 | Handle(Geom2d_BSplineCurve) H2; | |
1691 | ||
1692 | if(myApprox1) { | |
1693 | H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True); | |
1694 | } | |
1695 | ||
1696 | if(myApprox2) { | |
1697 | H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False); | |
1698 | } | |
1699 | // | |
1700 | mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2)); | |
7fd59977 | 1701 | } |
1702 | } // if (!myApprox) | |
1703 | ||
1704 | else { // myApprox=TRUE | |
1705 | GeomInt_WLApprox theapp3d; | |
1706 | // | |
1707 | Standard_Real tol2d = myTolApprox; | |
655fddc8 | 1708 | // |
7fd59977 | 1709 | theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True); |
59495dbe | 1710 | |
7fd59977 | 1711 | aNbParts=myLConstruct.NbParts(); |
1712 | for (i=1; i<=aNbParts; i++) { | |
655fddc8 | 1713 | myLConstruct.Part(i, fprm, lprm); |
1714 | Handle(IntPatch_WLine) WL = | |
1715 | convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm); | |
1716 | ||
1717 | theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts()); | |
1718 | ||
1719 | if (!theapp3d.IsDone()) { | |
1720 | // | |
1721 | Handle(Geom2d_BSplineCurve) H1; | |
1722 | Handle(Geom2d_BSplineCurve) H2; | |
1723 | ||
1724 | if(myApprox1) { | |
1725 | H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True); | |
1726 | } | |
1727 | ||
1728 | if(myApprox2) { | |
1729 | H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False); | |
1730 | } | |
1731 | // | |
1732 | mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2)); | |
1733 | } | |
1734 | ||
1735 | else { | |
1736 | if(myApprox1 || myApprox2) { | |
1737 | if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) { | |
1738 | myTolReached2d = theapp3d.TolReached2d(); | |
1739 | } | |
1740 | } | |
1741 | ||
1742 | if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) { | |
1743 | myTolReached3d = theapp3d.TolReached3d(); | |
1744 | } | |
1745 | ||
1746 | Standard_Integer aNbMultiCurves, nbpoles; | |
1747 | aNbMultiCurves=theapp3d.NbMultiCurves(); | |
1748 | for (j=1; j<=aNbMultiCurves; j++) { | |
1749 | const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j); | |
1750 | nbpoles = mbspc.NbPoles(); | |
1751 | ||
1752 | TColgp_Array1OfPnt tpoles(1, nbpoles); | |
1753 | mbspc.Curve(1, tpoles); | |
1754 | Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles, | |
1755 | mbspc.Knots(), | |
1756 | mbspc.Multiplicities(), | |
1757 | mbspc.Degree()); | |
1758 | ||
1759 | GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK); | |
1760 | Check.FixTangent(Standard_True,Standard_True); | |
1761 | // | |
1762 | IntTools_Curve aCurve; | |
1763 | aCurve.SetCurve(BS); | |
1764 | ||
1765 | if(myApprox1) { | |
1766 | TColgp_Array1OfPnt2d tpoles2d(1,nbpoles); | |
1767 | mbspc.Curve(2,tpoles2d); | |
1768 | Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d, | |
1769 | mbspc.Knots(), | |
1770 | mbspc.Multiplicities(), | |
1771 | mbspc.Degree()); | |
1772 | ||
1773 | GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK); | |
1774 | newCheck.FixTangent(Standard_True,Standard_True); | |
1775 | // | |
1776 | aCurve.SetFirstCurve2d(BS2); | |
1777 | } | |
1778 | else { | |
1779 | Handle(Geom2d_BSplineCurve) H1; | |
1780 | aCurve.SetFirstCurve2d(H1); | |
1781 | } | |
1782 | ||
1783 | if(myApprox2) { | |
1784 | TColgp_Array1OfPnt2d tpoles2d(1, nbpoles); | |
1785 | Standard_Integer TwoOrThree; | |
1786 | TwoOrThree=myApprox1 ? 3 : 2; | |
1787 | mbspc.Curve(TwoOrThree, tpoles2d); | |
1788 | Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d, | |
1789 | mbspc.Knots(), | |
1790 | mbspc.Multiplicities(), | |
1791 | mbspc.Degree()); | |
1792 | ||
1793 | GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK); | |
1794 | newCheck.FixTangent(Standard_True,Standard_True); | |
1795 | // | |
1796 | aCurve.SetSecondCurve2d(BS2); | |
1797 | } | |
1798 | else { | |
1799 | Handle(Geom2d_BSplineCurve) H2; | |
1800 | aCurve.SetSecondCurve2d(H2); | |
1801 | } | |
1802 | // | |
1803 | mySeqOfCurve.Append(aCurve); | |
1804 | ||
1805 | }// for (j=1; j<=aNbMultiCurves; j++) { | |
1806 | }// else from if (!theapp3d.IsDone()) | |
7fd59977 | 1807 | }// for (i=1; i<=aNbParts; i++) { |
1808 | }// else { // myApprox=TRUE | |
1809 | }// case IntPatch_Analytic: | |
59495dbe | 1810 | break; |
7fd59977 | 1811 | |
59495dbe | 1812 | case IntPatch_Walking:{ |
7fd59977 | 1813 | Handle(IntPatch_WLine) WL = |
1814 | Handle(IntPatch_WLine)::DownCast(L); | |
1815 | // | |
1816 | Standard_Integer ifprm, ilprm; | |
1817 | // | |
1818 | if (!myApprox) { | |
1819 | aNbParts = 1; | |
1820 | if(!bAvoidLineConstructor){ | |
655fddc8 | 1821 | aNbParts=myLConstruct.NbParts(); |
7fd59977 | 1822 | } |
1823 | for (i=1; i<=aNbParts; ++i) { | |
655fddc8 | 1824 | Handle(Geom2d_BSplineCurve) H1, H2; |
1825 | Handle(Geom_Curve) aBSp; | |
1826 | // | |
1827 | if(bAvoidLineConstructor) { | |
1828 | ifprm = 1; | |
1829 | ilprm = WL->NbPnts(); | |
1830 | } | |
1831 | else { | |
1832 | myLConstruct.Part(i, fprm, lprm); | |
1833 | ifprm=(Standard_Integer)fprm; | |
1834 | ilprm=(Standard_Integer)lprm; | |
1835 | } | |
1836 | // | |
1837 | if(myApprox1) { | |
1838 | H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True); | |
1839 | } | |
1840 | // | |
1841 | if(myApprox2) { | |
1842 | H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False); | |
1843 | } | |
1844 | // | |
1845 | aBSp=MakeBSpline(WL, ifprm, ilprm); | |
1846 | IntTools_Curve aIC(aBSp, H1, H2); | |
1847 | mySeqOfCurve.Append(aIC); | |
7fd59977 | 1848 | }// for (i=1; i<=aNbParts; ++i) { |
1849 | }// if (!myApprox) { | |
1850 | // | |
1851 | else { // X | |
1852 | Standard_Boolean bIsDecomposited; | |
1853 | Standard_Integer nbiter, aNbSeqOfL; | |
4abae870 | 1854 | Standard_Real tol2d, aTolApproxImp; |
7fd59977 | 1855 | IntPatch_SequenceOfLine aSeqOfL; |
1856 | GeomInt_WLApprox theapp3d; | |
1857 | Approx_ParametrizationType aParType = Approx_ChordLength; | |
1858 | // | |
1859 | Standard_Boolean anApprox1 = myApprox1; | |
1860 | Standard_Boolean anApprox2 = myApprox2; | |
4abae870 | 1861 | // |
1862 | aTolApproxImp=1.e-5; | |
7fd59977 | 1863 | tol2d = myTolApprox; |
1864 | ||
1865 | GeomAbs_SurfaceType typs1, typs2; | |
1866 | typs1 = myHS1->Surface().GetType(); | |
1867 | typs2 = myHS2->Surface().GetType(); | |
1868 | Standard_Boolean anWithPC = Standard_True; | |
1869 | ||
1870 | if(typs1 == GeomAbs_Cylinder && typs2 == GeomAbs_Sphere) { | |
655fddc8 | 1871 | anWithPC = |
1872 | ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere()); | |
7fd59977 | 1873 | } |
1874 | else if (typs1 == GeomAbs_Sphere && typs2 == GeomAbs_Cylinder) { | |
655fddc8 | 1875 | anWithPC = |
1876 | ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere()); | |
7fd59977 | 1877 | } |
4abae870 | 1878 | // |
7fd59977 | 1879 | if(!anWithPC) { |
4abae870 | 1880 | myTolApprox = aTolApproxImp;//1.e-5; |
655fddc8 | 1881 | anApprox1 = Standard_False; |
1882 | anApprox2 = Standard_False; | |
1883 | // | |
1884 | tol2d = myTolApprox; | |
7fd59977 | 1885 | } |
655fddc8 | 1886 | |
7fd59977 | 1887 | if(myHS1 == myHS2) { |
655fddc8 | 1888 | theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType); |
1889 | rejectSurface = Standard_True; | |
7fd59977 | 1890 | } |
1891 | else { | |
655fddc8 | 1892 | if(reApprox && !rejectSurface) |
1893 | theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType); | |
1894 | else { | |
1895 | Standard_Integer iDegMax, iDegMin, iNbIter; | |
1896 | // | |
1897 | ApproxParameters(myHS1, myHS2, iDegMin, iDegMax, iNbIter); | |
1898 | theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, iNbIter, Standard_True, aParType); | |
1899 | } | |
7fd59977 | 1900 | } |
1901 | // | |
1902 | Standard_Real aReachedTol = Precision::Confusion(); | |
1903 | bIsDecomposited=DecompositionOfWLine(WL, | |
655fddc8 | 1904 | myHS1, |
1905 | myHS2, | |
1906 | myFace1, | |
1907 | myFace2, | |
1908 | myLConstruct, | |
1909 | bAvoidLineConstructor, | |
1910 | aSeqOfL, | |
1911 | aReachedTol, | |
1912 | myContext); | |
4abae870 | 1913 | if ( bIsDecomposited && ( myTolReached3d < aReachedTol ) ) { |
655fddc8 | 1914 | myTolReached3d = aReachedTol; |
4abae870 | 1915 | } |
7fd59977 | 1916 | // |
1917 | aNbSeqOfL=aSeqOfL.Length(); | |
1918 | // | |
1919 | if (bIsDecomposited) { | |
655fddc8 | 1920 | nbiter=aNbSeqOfL; |
7fd59977 | 1921 | } |
1922 | else { | |
655fddc8 | 1923 | nbiter=1; |
1924 | aNbParts=1; | |
1925 | if (!bAvoidLineConstructor) { | |
1926 | aNbParts=myLConstruct.NbParts(); | |
1927 | nbiter=aNbParts; | |
1928 | } | |
7fd59977 | 1929 | } |
1930 | // | |
7fd59977 | 1931 | for(i = 1; i <= nbiter; ++i) { |
655fddc8 | 1932 | if(bIsDecomposited) { |
1933 | WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i)); | |
1934 | ifprm = 1; | |
1935 | ilprm = WL->NbPnts(); | |
1936 | } | |
1937 | else { | |
1938 | if(bAvoidLineConstructor) { | |
1939 | ifprm = 1; | |
1940 | ilprm = WL->NbPnts(); | |
1941 | } | |
1942 | else { | |
1943 | myLConstruct.Part(i, fprm, lprm); | |
1944 | ifprm = (Standard_Integer)fprm; | |
1945 | ilprm = (Standard_Integer)lprm; | |
1946 | } | |
1947 | } | |
1948 | //-- lbr : | |
1949 | //-- Si une des surfaces est un plan , on approxime en 2d | |
1950 | //-- sur cette surface et on remonte les points 2d en 3d. | |
1951 | if(typs1 == GeomAbs_Plane) { | |
1952 | theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm); | |
1953 | } | |
1954 | else if(typs2 == GeomAbs_Plane) { | |
1955 | theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm); | |
1956 | } | |
1957 | else { | |
1958 | // | |
1959 | if (myHS1 != myHS2){ | |
1960 | if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) && | |
1961 | (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) { | |
1962 | ||
1963 | theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType); | |
1964 | ||
1965 | Standard_Boolean bUseSurfaces; | |
1966 | bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm, ilprm); | |
1967 | if (bUseSurfaces) { | |
1968 | // ###### | |
1969 | rejectSurface = Standard_True; | |
1970 | // ###### | |
1971 | theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType); | |
1972 | } | |
1973 | } | |
1974 | } | |
1975 | // | |
1976 | theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm); | |
1977 | } | |
1978 | // | |
94218044 | 1979 | if (!theapp3d.IsDone()) { |
655fddc8 | 1980 | Handle(Geom2d_BSplineCurve) H1; |
94218044 | 1981 | Handle(Geom2d_BSplineCurve) H2; |
655fddc8 | 1982 | // |
1983 | Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm); | |
4abae870 | 1984 | // |
655fddc8 | 1985 | if(myApprox1) { |
1986 | H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True); | |
1987 | } | |
4abae870 | 1988 | // |
655fddc8 | 1989 | if(myApprox2) { |
1990 | H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False); | |
1991 | } | |
1992 | // | |
1993 | IntTools_Curve aIC(aBSp, H1, H2); | |
1994 | mySeqOfCurve.Append(aIC); | |
1995 | } | |
1996 | ||
1997 | else { | |
1998 | if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) { | |
1999 | if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) { | |
2000 | myTolReached2d = theapp3d.TolReached2d(); | |
2001 | } | |
2002 | } | |
2003 | if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) { | |
2004 | myTolReached3d = myTolReached2d; | |
2005 | // | |
2006 | if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) { | |
2007 | if (myTolReached3d<1.e-6) { | |
2008 | myTolReached3d = theapp3d.TolReached3d(); | |
2009 | myTolReached3d=1.e-6; | |
2010 | } | |
2011 | } | |
2012 | } | |
2013 | else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) { | |
2014 | myTolReached3d = theapp3d.TolReached3d(); | |
2015 | } | |
2016 | ||
2017 | Standard_Integer aNbMultiCurves, nbpoles; | |
2018 | aNbMultiCurves=theapp3d.NbMultiCurves(); | |
2019 | for (j=1; j<=aNbMultiCurves; j++) { | |
2020 | if(typs1 == GeomAbs_Plane) { | |
2021 | const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j); | |
2022 | nbpoles = mbspc.NbPoles(); | |
2023 | ||
2024 | TColgp_Array1OfPnt2d tpoles2d(1,nbpoles); | |
2025 | TColgp_Array1OfPnt tpoles(1,nbpoles); | |
2026 | ||
2027 | mbspc.Curve(1,tpoles2d); | |
2028 | const gp_Pln& Pln = myHS1->Surface().Plane(); | |
2029 | // | |
2030 | Standard_Integer ik; | |
2031 | for(ik = 1; ik<= nbpoles; ik++) { | |
2032 | tpoles.SetValue(ik, | |
2033 | ElSLib::Value(tpoles2d.Value(ik).X(), | |
2034 | tpoles2d.Value(ik).Y(), | |
2035 | Pln)); | |
2036 | } | |
2037 | // | |
2038 | Handle(Geom_BSplineCurve) BS = | |
2039 | new Geom_BSplineCurve(tpoles, | |
2040 | mbspc.Knots(), | |
2041 | mbspc.Multiplicities(), | |
2042 | mbspc.Degree()); | |
2043 | GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK); | |
2044 | Check.FixTangent(Standard_True, Standard_True); | |
2045 | // | |
2046 | IntTools_Curve aCurve; | |
2047 | aCurve.SetCurve(BS); | |
2048 | ||
2049 | if(myApprox1) { | |
2050 | Handle(Geom2d_BSplineCurve) BS1 = | |
2051 | new Geom2d_BSplineCurve(tpoles2d, | |
2052 | mbspc.Knots(), | |
2053 | mbspc.Multiplicities(), | |
2054 | mbspc.Degree()); | |
2055 | GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK); | |
2056 | Check1.FixTangent(Standard_True,Standard_True); | |
2057 | // | |
2058 | // ############################################ | |
2059 | if(!rejectSurface && !reApprox) { | |
2060 | Standard_Boolean isValid = IsCurveValid(BS1); | |
2061 | if(!isValid) { | |
2062 | reApprox = Standard_True; | |
2063 | goto reapprox; | |
2064 | } | |
2065 | } | |
2066 | // ############################################ | |
2067 | aCurve.SetFirstCurve2d(BS1); | |
2068 | } | |
2069 | else { | |
2070 | Handle(Geom2d_BSplineCurve) H1; | |
2071 | aCurve.SetFirstCurve2d(H1); | |
2072 | } | |
2073 | ||
2074 | if(myApprox2) { | |
2075 | mbspc.Curve(2, tpoles2d); | |
2076 | ||
2077 | Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d, | |
2078 | mbspc.Knots(), | |
2079 | mbspc.Multiplicities(), | |
2080 | mbspc.Degree()); | |
2081 | GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK); | |
2082 | newCheck.FixTangent(Standard_True,Standard_True); | |
2083 | ||
2084 | // ########################################### | |
2085 | if(!rejectSurface && !reApprox) { | |
2086 | Standard_Boolean isValid = IsCurveValid(BS2); | |
2087 | if(!isValid) { | |
2088 | reApprox = Standard_True; | |
2089 | goto reapprox; | |
2090 | } | |
2091 | } | |
2092 | // ########################################### | |
2093 | // | |
2094 | aCurve.SetSecondCurve2d(BS2); | |
2095 | } | |
2096 | else { | |
2097 | Handle(Geom2d_BSplineCurve) H2; | |
2098 | // | |
2099 | aCurve.SetSecondCurve2d(H2); | |
2100 | } | |
2101 | // | |
2102 | mySeqOfCurve.Append(aCurve); | |
4abae870 | 2103 | }//if(typs1 == GeomAbs_Plane) { |
655fddc8 | 2104 | |
2105 | else if(typs2 == GeomAbs_Plane) { | |
2106 | const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j); | |
2107 | nbpoles = mbspc.NbPoles(); | |
2108 | ||
2109 | TColgp_Array1OfPnt2d tpoles2d(1,nbpoles); | |
2110 | TColgp_Array1OfPnt tpoles(1,nbpoles); | |
2111 | mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d); | |
2112 | const gp_Pln& Pln = myHS2->Surface().Plane(); | |
2113 | // | |
2114 | Standard_Integer ik; | |
2115 | for(ik = 1; ik<= nbpoles; ik++) { | |
2116 | tpoles.SetValue(ik, | |
2117 | ElSLib::Value(tpoles2d.Value(ik).X(), | |
2118 | tpoles2d.Value(ik).Y(), | |
2119 | Pln)); | |
2120 | ||
2121 | } | |
2122 | // | |
2123 | Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles, | |
2124 | mbspc.Knots(), | |
2125 | mbspc.Multiplicities(), | |
2126 | mbspc.Degree()); | |
2127 | GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK); | |
2128 | Check.FixTangent(Standard_True,Standard_True); | |
2129 | // | |
2130 | IntTools_Curve aCurve; | |
2131 | aCurve.SetCurve(BS); | |
2132 | ||
2133 | if(myApprox2) { | |
2134 | Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d, | |
2135 | mbspc.Knots(), | |
2136 | mbspc.Multiplicities(), | |
2137 | mbspc.Degree()); | |
2138 | GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK); | |
2139 | Check1.FixTangent(Standard_True,Standard_True); | |
2140 | // | |
2141 | // ########################################### | |
2142 | if(!rejectSurface && !reApprox) { | |
2143 | Standard_Boolean isValid = IsCurveValid(BS1); | |
2144 | if(!isValid) { | |
2145 | reApprox = Standard_True; | |
2146 | goto reapprox; | |
2147 | } | |
2148 | } | |
989341c5 | 2149 | // ########################################### |
2150 | bPCurvesOk = CheckPCurve(BS1, myFace2); | |
655fddc8 | 2151 | aCurve.SetSecondCurve2d(BS1); |
2152 | } | |
2153 | else { | |
2154 | Handle(Geom2d_BSplineCurve) H2; | |
2155 | aCurve.SetSecondCurve2d(H2); | |
2156 | } | |
2157 | ||
2158 | if(myApprox1) { | |
2159 | mbspc.Curve(1,tpoles2d); | |
2160 | Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d, | |
2161 | mbspc.Knots(), | |
2162 | mbspc.Multiplicities(), | |
2163 | mbspc.Degree()); | |
2164 | GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK); | |
2165 | Check2.FixTangent(Standard_True,Standard_True); | |
2166 | // | |
2167 | // ########################################### | |
2168 | if(!rejectSurface && !reApprox) { | |
2169 | Standard_Boolean isValid = IsCurveValid(BS2); | |
2170 | if(!isValid) { | |
2171 | reApprox = Standard_True; | |
2172 | goto reapprox; | |
2173 | } | |
2174 | } | |
989341c5 | 2175 | // ########################################### |
2176 | bPCurvesOk = bPCurvesOk && CheckPCurve(BS2, myFace1); | |
655fddc8 | 2177 | aCurve.SetFirstCurve2d(BS2); |
2178 | } | |
2179 | else { | |
2180 | Handle(Geom2d_BSplineCurve) H1; | |
2181 | // | |
2182 | aCurve.SetFirstCurve2d(H1); | |
2183 | } | |
2184 | // | |
989341c5 | 2185 | //if points of the pcurves are out of the faces bounds |
2186 | //create 3d and 2d curves without approximation | |
2187 | if (!bPCurvesOk) { | |
2188 | Handle(Geom2d_BSplineCurve) H1, H2; | |
655fddc8 | 2189 | bPCurvesOk = Standard_True; |
2190 | // | |
989341c5 | 2191 | Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm); |
59495dbe | 2192 | |
989341c5 | 2193 | if(myApprox1) { |
2194 | H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True); | |
655fddc8 | 2195 | bPCurvesOk = CheckPCurve(H1, myFace1); |
989341c5 | 2196 | } |
59495dbe | 2197 | |
989341c5 | 2198 | if(myApprox2) { |
2199 | H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False); | |
655fddc8 | 2200 | bPCurvesOk = bPCurvesOk && CheckPCurve(H2, myFace2); |
989341c5 | 2201 | } |
2202 | // | |
655fddc8 | 2203 | //if pcurves created without approximation are out of the |
2204 | //faces bounds, use approximated 3d and 2d curves | |
2205 | if (bPCurvesOk) { | |
2206 | IntTools_Curve aIC(aBSp, H1, H2); | |
2207 | mySeqOfCurve.Append(aIC); | |
2208 | } else { | |
2209 | mySeqOfCurve.Append(aCurve); | |
2210 | } | |
989341c5 | 2211 | } else { |
2212 | mySeqOfCurve.Append(aCurve); | |
2213 | } | |
4abae870 | 2214 | }// else if(typs2 == GeomAbs_Plane) |
2215 | // | |
2216 | else { //typs2 != GeomAbs_Plane && typs1 != GeomAbs_Plane | |
2217 | Standard_Boolean bIsValid1, bIsValid2; | |
2218 | Handle(Geom_BSplineCurve) BS; | |
2219 | Handle(Geom2d_BSplineCurve) aH2D; | |
2220 | IntTools_Curve aCurve; | |
2221 | // | |
2222 | bIsValid1=Standard_True; | |
2223 | bIsValid2=Standard_True; | |
2224 | // | |
655fddc8 | 2225 | const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j); |
2226 | nbpoles = mbspc.NbPoles(); | |
2227 | TColgp_Array1OfPnt tpoles(1,nbpoles); | |
2228 | mbspc.Curve(1,tpoles); | |
4abae870 | 2229 | BS=new Geom_BSplineCurve(tpoles, |
655fddc8 | 2230 | mbspc.Knots(), |
2231 | mbspc.Multiplicities(), | |
2232 | mbspc.Degree()); | |
2233 | GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK); | |
2234 | Check.FixTangent(Standard_True,Standard_True); | |
2235 | // | |
2236 | aCurve.SetCurve(BS); | |
4abae870 | 2237 | aCurve.SetFirstCurve2d(aH2D); |
2238 | aCurve.SetSecondCurve2d(aH2D); | |
2239 | // | |
655fddc8 | 2240 | if(myApprox1) { |
2241 | if(anApprox1) { | |
4abae870 | 2242 | Handle(Geom2d_BSplineCurve) BS1; |
655fddc8 | 2243 | TColgp_Array1OfPnt2d tpoles2d(1,nbpoles); |
2244 | mbspc.Curve(2,tpoles2d); | |
4abae870 | 2245 | // |
2246 | BS1=new Geom2d_BSplineCurve(tpoles2d, | |
655fddc8 | 2247 | mbspc.Knots(), |
2248 | mbspc.Multiplicities(), | |
2249 | mbspc.Degree()); | |
2250 | GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK); | |
2251 | newCheck.FixTangent(Standard_True,Standard_True); | |
2252 | // | |
4abae870 | 2253 | if (!reApprox) { |
2254 | bIsValid1=CheckPCurve(BS1, myFace1); | |
2255 | } | |
2256 | // | |
655fddc8 | 2257 | aCurve.SetFirstCurve2d(BS1); |
2258 | } | |
2259 | else { | |
2260 | Handle(Geom2d_BSplineCurve) BS1; | |
2261 | fprm = BS->FirstParameter(); | |
2262 | lprm = BS->LastParameter(); | |
2263 | ||
2264 | Handle(Geom2d_Curve) C2d; | |
2265 | Standard_Real aTol = myTolApprox; | |
2266 | BuildPCurves(fprm, lprm, aTol, myHS1->ChangeSurface().Surface(), BS, C2d); | |
2267 | BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d); | |
2268 | aCurve.SetFirstCurve2d(BS1); | |
2269 | } | |
4abae870 | 2270 | } // if(myApprox1) { |
655fddc8 | 2271 | // |
2272 | if(myApprox2) { | |
2273 | if(anApprox2) { | |
4abae870 | 2274 | Handle(Geom2d_BSplineCurve) BS2; |
655fddc8 | 2275 | TColgp_Array1OfPnt2d tpoles2d(1,nbpoles); |
2276 | mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d); | |
4abae870 | 2277 | BS2=new Geom2d_BSplineCurve(tpoles2d, |
655fddc8 | 2278 | mbspc.Knots(), |
2279 | mbspc.Multiplicities(), | |
2280 | mbspc.Degree()); | |
2281 | GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK); | |
2282 | newCheck.FixTangent(Standard_True,Standard_True); | |
2283 | // | |
4abae870 | 2284 | if (!reApprox) { |
2285 | bIsValid2=CheckPCurve(BS2, myFace2); | |
2286 | } | |
655fddc8 | 2287 | aCurve.SetSecondCurve2d(BS2); |
2288 | } | |
2289 | else { | |
2290 | Handle(Geom2d_BSplineCurve) BS2; | |
2291 | fprm = BS->FirstParameter(); | |
2292 | lprm = BS->LastParameter(); | |
2293 | ||
2294 | Handle(Geom2d_Curve) C2d; | |
2295 | Standard_Real aTol = myTolApprox; | |
2296 | BuildPCurves(fprm, lprm, aTol, myHS2->ChangeSurface().Surface(), BS, C2d); | |
2297 | BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d); | |
2298 | aCurve.SetSecondCurve2d(BS2); | |
2299 | } | |
4abae870 | 2300 | } //if(myApprox2) { |
2301 | if (!bIsValid1 || !bIsValid2) { | |
2302 | myTolApprox=aTolApproxImp;//1.e-5; | |
2303 | tol2d = myTolApprox; | |
2304 | reApprox = Standard_True; | |
2305 | goto reapprox; | |
655fddc8 | 2306 | } |
2307 | // | |
2308 | mySeqOfCurve.Append(aCurve); | |
2309 | } | |
2310 | } | |
2311 | } | |
7fd59977 | 2312 | } |
2313 | }// else { // X | |
2314 | }// case IntPatch_Walking:{ | |
59495dbe | 2315 | break; |
2316 | ||
7fd59977 | 2317 | case IntPatch_Restriction: |
2318 | break; | |
4abae870 | 2319 | default: |
2320 | break; | |
7fd59977 | 2321 | |
2322 | } | |
2323 | } | |
2324 | ||
2325 | //======================================================================= | |
2326 | //function : BuildPCurves | |
2327 | //purpose : | |
2328 | //======================================================================= | |
655fddc8 | 2329 | void BuildPCurves (Standard_Real f, |
2330 | Standard_Real l, | |
2331 | Standard_Real& Tol, | |
2332 | const Handle (Geom_Surface)& S, | |
2333 | const Handle (Geom_Curve)& C, | |
2334 | Handle (Geom2d_Curve)& C2d) | |
7fd59977 | 2335 | { |
655fddc8 | 2336 | if (!C2d.IsNull()) { |
2337 | return; | |
2338 | } | |
2339 | // | |
7fd59977 | 2340 | Standard_Real umin,umax,vmin,vmax; |
2341 | // | |
655fddc8 | 2342 | S->Bounds(umin, umax, vmin, vmax); |
2343 | // in class ProjLib_Function the range of parameters is shrank by 1.e-09 | |
2344 | if((l - f) > 2.e-09) { | |
2345 | C2d = GeomProjLib::Curve2d(C,f,l,S,umin,umax,vmin,vmax,Tol); | |
2346 | // | |
2347 | if (C2d.IsNull()) { | |
2348 | // proj. a circle that goes through the pole on a sphere to the sphere | |
2349 | Tol += Precision::Confusion(); | |
7fd59977 | 2350 | C2d = GeomProjLib::Curve2d(C,f,l,S,Tol); |
7fd59977 | 2351 | } |
655fddc8 | 2352 | } |
2353 | else { | |
2354 | if((l - f) > Epsilon(Abs(f))) { | |
2355 | GeomAPI_ProjectPointOnSurf aProjector1, aProjector2; | |
2356 | gp_Pnt P1 = C->Value(f); | |
2357 | gp_Pnt P2 = C->Value(l); | |
2358 | aProjector1.Init(P1, S); | |
2359 | aProjector2.Init(P2, S); | |
2360 | ||
2361 | if(aProjector1.IsDone() && aProjector2.IsDone()) { | |
2362 | Standard_Real U=0., V=0.; | |
2363 | aProjector1.LowerDistanceParameters(U, V); | |
2364 | gp_Pnt2d p1(U, V); | |
2365 | ||
2366 | aProjector2.LowerDistanceParameters(U, V); | |
2367 | gp_Pnt2d p2(U, V); | |
2368 | ||
2369 | if(p1.Distance(p2) > gp::Resolution()) { | |
2370 | TColgp_Array1OfPnt2d poles(1,2); | |
2371 | TColStd_Array1OfReal knots(1,2); | |
2372 | TColStd_Array1OfInteger mults(1,2); | |
2373 | poles(1) = p1; | |
2374 | poles(2) = p2; | |
2375 | knots(1) = f; | |
2376 | knots(2) = l; | |
2377 | mults(1) = mults(2) = 2; | |
2378 | ||
2379 | C2d = new Geom2d_BSplineCurve(poles,knots,mults,1); | |
2380 | ||
2381 | // compute reached tolerance.begin | |
2382 | gp_Pnt PMid = C->Value((f + l) * 0.5); | |
2383 | aProjector1.Perform(PMid); | |
2384 | ||
2385 | if(aProjector1.IsDone()) { | |
2386 | aProjector1.LowerDistanceParameters(U, V); | |
2387 | gp_Pnt2d pmidproj(U, V); | |
2388 | gp_Pnt2d pmidcurve2d = C2d->Value((f + l) * 0.5); | |
2389 | Standard_Real adist = pmidcurve2d.Distance(pmidproj); | |
2390 | Tol = (adist > Tol) ? adist : Tol; | |
4abae870 | 2391 | } |
655fddc8 | 2392 | // compute reached tolerance.end |
4abae870 | 2393 | } |
7fd59977 | 2394 | } |
2395 | } | |
655fddc8 | 2396 | } |
2397 | // | |
2398 | if (S->IsUPeriodic() && !C2d.IsNull()) { | |
2399 | // Recadre dans le domaine UV de la face | |
2400 | Standard_Real aTm, U0, aEps, period, du, U0x; | |
2401 | Standard_Boolean bAdjust; | |
7fd59977 | 2402 | // |
655fddc8 | 2403 | aEps = Precision::PConfusion(); |
2404 | period = S->UPeriod(); | |
2405 | // | |
2406 | aTm = .5*(f + l); | |
2407 | gp_Pnt2d pm = C2d->Value(aTm); | |
2408 | U0 = pm.X(); | |
2409 | // | |
2410 | bAdjust = | |
2a78ec6a | 2411 | GeomInt::AdjustPeriodic(U0, umin, umax, period, U0x, du, aEps); |
655fddc8 | 2412 | if (bAdjust) { |
2413 | gp_Vec2d T1(du, 0.); | |
2414 | C2d->Translate(T1); | |
7fd59977 | 2415 | } |
2416 | } | |
7fd59977 | 2417 | } |
2418 | ||
2419 | //======================================================================= | |
2420 | //function : Parameters | |
2421 | //purpose : | |
2422 | //======================================================================= | |
2423 | void Parameters(const Handle(GeomAdaptor_HSurface)& HS1, | |
655fddc8 | 2424 | const Handle(GeomAdaptor_HSurface)& HS2, |
2425 | const gp_Pnt& Ptref, | |
2426 | Standard_Real& U1, | |
2427 | Standard_Real& V1, | |
2428 | Standard_Real& U2, | |
2429 | Standard_Real& V2) | |
7fd59977 | 2430 | { |
2431 | ||
2432 | IntSurf_Quadric quad1,quad2; | |
2433 | GeomAbs_SurfaceType typs = HS1->Surface().GetType(); | |
2434 | ||
2435 | switch (typs) { | |
2436 | case GeomAbs_Plane: | |
2437 | quad1.SetValue(HS1->Surface().Plane()); | |
2438 | break; | |
2439 | case GeomAbs_Cylinder: | |
2440 | quad1.SetValue(HS1->Surface().Cylinder()); | |
2441 | break; | |
2442 | case GeomAbs_Cone: | |
2443 | quad1.SetValue(HS1->Surface().Cone()); | |
2444 | break; | |
2445 | case GeomAbs_Sphere: | |
2446 | quad1.SetValue(HS1->Surface().Sphere()); | |
2447 | break; | |
7eed5d29 | 2448 | case GeomAbs_Torus: |
2449 | quad1.SetValue(HS1->Surface().Torus()); | |
2450 | break; | |
7fd59977 | 2451 | default: |
2452 | Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve"); | |
2453 | } | |
2454 | ||
2455 | typs = HS2->Surface().GetType(); | |
2456 | switch (typs) { | |
2457 | case GeomAbs_Plane: | |
2458 | quad2.SetValue(HS2->Surface().Plane()); | |
2459 | break; | |
2460 | case GeomAbs_Cylinder: | |
2461 | quad2.SetValue(HS2->Surface().Cylinder()); | |
2462 | break; | |
2463 | case GeomAbs_Cone: | |
2464 | quad2.SetValue(HS2->Surface().Cone()); | |
2465 | break; | |
2466 | case GeomAbs_Sphere: | |
2467 | quad2.SetValue(HS2->Surface().Sphere()); | |
2468 | break; | |
7eed5d29 | 2469 | case GeomAbs_Torus: |
2470 | quad2.SetValue(HS2->Surface().Torus()); | |
2471 | break; | |
7fd59977 | 2472 | default: |
2473 | Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve"); | |
2474 | } | |
2475 | ||
2476 | quad1.Parameters(Ptref,U1,V1); | |
2477 | quad2.Parameters(Ptref,U2,V2); | |
2478 | } | |
2479 | ||
2480 | //======================================================================= | |
2481 | //function : MakeBSpline | |
2482 | //purpose : | |
2483 | //======================================================================= | |
2484 | Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL, | |
655fddc8 | 2485 | const Standard_Integer ideb, |
2486 | const Standard_Integer ifin) | |
7fd59977 | 2487 | { |
2488 | Standard_Integer i,nbpnt = ifin-ideb+1; | |
2489 | TColgp_Array1OfPnt poles(1,nbpnt); | |
2490 | TColStd_Array1OfReal knots(1,nbpnt); | |
2491 | TColStd_Array1OfInteger mults(1,nbpnt); | |
2492 | Standard_Integer ipidebm1; | |
2493 | for(i=1,ipidebm1=i+ideb-1; i<=nbpnt;ipidebm1++, i++) { | |
2494 | poles(i) = WL->Point(ipidebm1).Value(); | |
2495 | mults(i) = 1; | |
2496 | knots(i) = i-1; | |
2497 | } | |
2498 | mults(1) = mults(nbpnt) = 2; | |
2499 | return | |
2500 | new Geom_BSplineCurve(poles,knots,mults,1); | |
2501 | } | |
2502 | // | |
2503 | ||
2504 | //======================================================================= | |
2505 | //function : MakeBSpline2d | |
2506 | //purpose : | |
2507 | //======================================================================= | |
2508 | Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine, | |
655fddc8 | 2509 | const Standard_Integer ideb, |
2510 | const Standard_Integer ifin, | |
2511 | const Standard_Boolean onFirst) | |
7fd59977 | 2512 | { |
2513 | Standard_Integer i, nbpnt = ifin-ideb+1; | |
2514 | TColgp_Array1OfPnt2d poles(1,nbpnt); | |
2515 | TColStd_Array1OfReal knots(1,nbpnt); | |
2516 | TColStd_Array1OfInteger mults(1,nbpnt); | |
2517 | Standard_Integer ipidebm1; | |
2518 | ||
2519 | for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) { | |
2520 | Standard_Real U, V; | |
2521 | if(onFirst) | |
655fddc8 | 2522 | theWLine->Point(ipidebm1).ParametersOnS1(U, V); |
7fd59977 | 2523 | else |
655fddc8 | 2524 | theWLine->Point(ipidebm1).ParametersOnS2(U, V); |
7fd59977 | 2525 | poles(i).SetCoord(U, V); |
2526 | mults(i) = 1; | |
2527 | knots(i) = i-1; | |
2528 | } | |
2529 | mults(1) = mults(nbpnt) = 2; | |
2530 | ||
2531 | return new Geom2d_BSplineCurve(poles,knots,mults,1); | |
2532 | } | |
2533 | //======================================================================= | |
2534 | //function : PrepareLines3D | |
2535 | //purpose : | |
2536 | //======================================================================= | |
a9f7b6b5 | 2537 | void IntTools_FaceFace::PrepareLines3D(const Standard_Boolean bToSplit) |
7fd59977 | 2538 | { |
a9f7b6b5 P |
2539 | Standard_Integer i, aNbCurves; |
2540 | GeomAbs_SurfaceType aType1, aType2; | |
7fd59977 | 2541 | IntTools_SequenceOfCurves aNewCvs; |
7fd59977 | 2542 | // |
a9f7b6b5 | 2543 | // 1. Treatment closed curves |
7fd59977 | 2544 | aNbCurves=mySeqOfCurve.Length(); |
a9f7b6b5 | 2545 | for (i=1; i<=aNbCurves; ++i) { |
7fd59977 | 2546 | const IntTools_Curve& aIC=mySeqOfCurve(i); |
7fd59977 | 2547 | // |
a9f7b6b5 P |
2548 | if (bToSplit) { |
2549 | Standard_Integer j, aNbC; | |
2550 | IntTools_SequenceOfCurves aSeqCvs; | |
2551 | // | |
2552 | aNbC=IntTools_Tools::SplitCurve(aIC, aSeqCvs); | |
2553 | if (aNbC) { | |
655fddc8 | 2554 | for (j=1; j<=aNbC; ++j) { |
2555 | const IntTools_Curve& aICNew=aSeqCvs(j); | |
2556 | aNewCvs.Append(aICNew); | |
2557 | } | |
a9f7b6b5 P |
2558 | } |
2559 | else { | |
655fddc8 | 2560 | aNewCvs.Append(aIC); |
7fd59977 | 2561 | } |
2562 | } | |
7fd59977 | 2563 | else { |
2564 | aNewCvs.Append(aIC); | |
2565 | } | |
2566 | } | |
2567 | // | |
2568 | // 2. Plane\Cone intersection when we had 4 curves | |
a9f7b6b5 P |
2569 | aType1=myHS1->GetType(); |
2570 | aType2=myHS2->GetType(); | |
2571 | aNbCurves=aNewCvs.Length(); | |
2572 | // | |
7fd59977 | 2573 | if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone) || |
2574 | (aType2==GeomAbs_Plane && aType1==GeomAbs_Cone)) { | |
7fd59977 | 2575 | if (aNbCurves==4) { |
a9f7b6b5 P |
2576 | GeomAbs_CurveType aCType1; |
2577 | // | |
2578 | aCType1=aNewCvs(1).Type(); | |
7fd59977 | 2579 | if (aCType1==GeomAbs_Line) { |
655fddc8 | 2580 | IntTools_SequenceOfCurves aSeqIn, aSeqOut; |
2581 | // | |
2582 | for (i=1; i<=aNbCurves; ++i) { | |
2583 | const IntTools_Curve& aIC=aNewCvs(i); | |
2584 | aSeqIn.Append(aIC); | |
2585 | } | |
2586 | // | |
2587 | IntTools_Tools::RejectLines(aSeqIn, aSeqOut); | |
2588 | // | |
2589 | aNewCvs.Clear(); | |
2590 | aNbCurves=aSeqOut.Length(); | |
2591 | for (i=1; i<=aNbCurves; ++i) { | |
2592 | const IntTools_Curve& aIC=aSeqOut(i); | |
2593 | aNewCvs.Append(aIC); | |
2594 | } | |
7fd59977 | 2595 | } |
2596 | } | |
a9f7b6b5 | 2597 | }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone)... |
7fd59977 | 2598 | // |
2599 | // 3. Fill mySeqOfCurve | |
2600 | mySeqOfCurve.Clear(); | |
2601 | aNbCurves=aNewCvs.Length(); | |
a9f7b6b5 | 2602 | for (i=1; i<=aNbCurves; ++i) { |
7fd59977 | 2603 | const IntTools_Curve& aIC=aNewCvs(i); |
2604 | mySeqOfCurve.Append(aIC); | |
2605 | } | |
7fd59977 | 2606 | } |
7fd59977 | 2607 | //======================================================================= |
2608 | //function : CorrectSurfaceBoundaries | |
2609 | //purpose : | |
2610 | //======================================================================= | |
59495dbe | 2611 | void CorrectSurfaceBoundaries(const TopoDS_Face& theFace, |
c002793b | 2612 | const Standard_Real theTolerance, |
2613 | Standard_Real& theumin, | |
2614 | Standard_Real& theumax, | |
2615 | Standard_Real& thevmin, | |
2616 | Standard_Real& thevmax) | |
7fd59977 | 2617 | { |
2618 | Standard_Boolean enlarge, isuperiodic, isvperiodic; | |
2619 | Standard_Real uinf, usup, vinf, vsup, delta; | |
2620 | GeomAbs_SurfaceType aType; | |
2621 | Handle(Geom_Surface) aSurface; | |
2622 | // | |
2623 | aSurface = BRep_Tool::Surface(theFace); | |
2624 | aSurface->Bounds(uinf, usup, vinf, vsup); | |
2625 | delta = theTolerance; | |
2626 | enlarge = Standard_False; | |
2627 | // | |
2628 | GeomAdaptor_Surface anAdaptorSurface(aSurface); | |
2629 | // | |
2630 | if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) { | |
2631 | Handle(Geom_Surface) aBasisSurface = | |
2632 | (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface))->BasisSurface(); | |
2633 | ||
2634 | if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) || | |
2635 | aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) { | |
2636 | return; | |
2637 | } | |
2638 | } | |
2639 | // | |
2640 | if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) { | |
2641 | Handle(Geom_Surface) aBasisSurface = | |
2642 | (Handle(Geom_OffsetSurface)::DownCast(aSurface))->BasisSurface(); | |
2643 | ||
2644 | if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) || | |
2645 | aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) { | |
2646 | return; | |
2647 | } | |
2648 | } | |
2649 | // | |
2650 | isuperiodic = anAdaptorSurface.IsUPeriodic(); | |
2651 | isvperiodic = anAdaptorSurface.IsVPeriodic(); | |
2652 | // | |
2653 | aType=anAdaptorSurface.GetType(); | |
2654 | if((aType==GeomAbs_BezierSurface) || | |
2655 | (aType==GeomAbs_BSplineSurface) || | |
2656 | (aType==GeomAbs_SurfaceOfExtrusion) || | |
c002793b | 2657 | (aType==GeomAbs_SurfaceOfRevolution) || |
2658 | (aType==GeomAbs_Cylinder)) { | |
7fd59977 | 2659 | enlarge=Standard_True; |
2660 | } | |
2661 | // | |
2662 | if(!isuperiodic && enlarge) { | |
2663 | ||
2664 | if((theumin - uinf) > delta ) | |
2665 | theumin -= delta; | |
2666 | else { | |
2667 | theumin = uinf; | |
2668 | } | |
2669 | ||
2670 | if((usup - theumax) > delta ) | |
2671 | theumax += delta; | |
2672 | else | |
2673 | theumax = usup; | |
2674 | } | |
2675 | // | |
2676 | if(!isvperiodic && enlarge) { | |
2677 | if((thevmin - vinf) > delta ) { | |
2678 | thevmin -= delta; | |
2679 | } | |
2680 | else { | |
2681 | thevmin = vinf; | |
2682 | } | |
2683 | if((vsup - thevmax) > delta ) { | |
2684 | thevmax += delta; | |
2685 | } | |
2686 | else { | |
2687 | thevmax = vsup; | |
2688 | } | |
2689 | } | |
2690 | // | |
2691 | { | |
2692 | Standard_Integer aNbP; | |
2693 | Standard_Real aXP, dXfact, aXmid, aX1, aX2, aTolPA; | |
2694 | // | |
2695 | aTolPA=Precision::Angular(); | |
2696 | // U | |
2697 | if (isuperiodic) { | |
2698 | aXP=anAdaptorSurface.UPeriod(); | |
2699 | dXfact=theumax-theumin; | |
2700 | if (dXfact-aTolPA>aXP) { | |
655fddc8 | 2701 | aXmid=0.5*(theumax+theumin); |
2702 | aNbP=RealToInt(aXmid/aXP); | |
2703 | if (aXmid<0.) { | |
2704 | aNbP=aNbP-1; | |
2705 | } | |
2706 | aX1=aNbP*aXP; | |
2707 | if (theumin>aTolPA) { | |
2708 | aX1=theumin+aNbP*aXP; | |
2709 | } | |
2710 | aX2=aX1+aXP; | |
2711 | if (theumin<aX1) { | |
2712 | theumin=aX1; | |
2713 | } | |
2714 | if (theumax>aX2) { | |
2715 | theumax=aX2; | |
2716 | } | |
7fd59977 | 2717 | } |
2718 | } | |
2719 | // V | |
2720 | if (isvperiodic) { | |
2721 | aXP=anAdaptorSurface.VPeriod(); | |
2722 | dXfact=thevmax-thevmin; | |
2723 | if (dXfact-aTolPA>aXP) { | |
655fddc8 | 2724 | aXmid=0.5*(thevmax+thevmin); |
2725 | aNbP=RealToInt(aXmid/aXP); | |
2726 | if (aXmid<0.) { | |
2727 | aNbP=aNbP-1; | |
2728 | } | |
2729 | aX1=aNbP*aXP; | |
2730 | if (thevmin>aTolPA) { | |
2731 | aX1=thevmin+aNbP*aXP; | |
2732 | } | |
2733 | aX2=aX1+aXP; | |
2734 | if (thevmin<aX1) { | |
2735 | thevmin=aX1; | |
2736 | } | |
2737 | if (thevmax>aX2) { | |
2738 | thevmax=aX2; | |
2739 | } | |
7fd59977 | 2740 | } |
2741 | } | |
2742 | } | |
2743 | // | |
2744 | if(isuperiodic || isvperiodic) { | |
2745 | Standard_Boolean correct = Standard_False; | |
2746 | Standard_Boolean correctU = Standard_False; | |
2747 | Standard_Boolean correctV = Standard_False; | |
2748 | Bnd_Box2d aBox; | |
2749 | TopExp_Explorer anExp; | |
2750 | ||
2751 | for(anExp.Init(theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) { | |
2752 | if(BRep_Tool::IsClosed(TopoDS::Edge(anExp.Current()), theFace)) { | |
655fddc8 | 2753 | correct = Standard_True; |
2754 | Standard_Real f, l; | |
2755 | TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current()); | |
2756 | ||
2757 | for(Standard_Integer i = 0; i < 2; i++) { | |
2758 | if(i==0) { | |
2759 | anEdge.Orientation(TopAbs_FORWARD); | |
2760 | } | |
2761 | else { | |
2762 | anEdge.Orientation(TopAbs_REVERSED); | |
2763 | } | |
2764 | Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l); | |
2765 | ||
2766 | if(aCurve.IsNull()) { | |
2767 | correct = Standard_False; | |
2768 | break; | |
2769 | } | |
2770 | Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve); | |
2771 | ||
2772 | if(aLine.IsNull()) { | |
2773 | correct = Standard_False; | |
2774 | break; | |
2775 | } | |
2776 | gp_Dir2d anUDir(1., 0.); | |
2777 | gp_Dir2d aVDir(0., 1.); | |
2778 | Standard_Real anAngularTolerance = Precision::Angular(); | |
2779 | ||
2780 | correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance); | |
2781 | correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance); | |
2782 | ||
2783 | gp_Pnt2d pp1 = aCurve->Value(f); | |
2784 | aBox.Add(pp1); | |
2785 | gp_Pnt2d pp2 = aCurve->Value(l); | |
2786 | aBox.Add(pp2); | |
2787 | } | |
2788 | if(!correct) | |
2789 | break; | |
7fd59977 | 2790 | } |
2791 | } | |
2792 | ||
2793 | if(correct) { | |
2794 | Standard_Real umin, vmin, umax, vmax; | |
2795 | aBox.Get(umin, vmin, umax, vmax); | |
2796 | ||
2797 | if(isuperiodic && correctU) { | |
655fddc8 | 2798 | |
2799 | if(theumin < umin) | |
2800 | theumin = umin; | |
2801 | ||
2802 | if(theumax > umax) { | |
2803 | theumax = umax; | |
2804 | } | |
7fd59977 | 2805 | } |
2806 | if(isvperiodic && correctV) { | |
655fddc8 | 2807 | |
2808 | if(thevmin < vmin) | |
2809 | thevmin = vmin; | |
2810 | if(thevmax > vmax) | |
2811 | thevmax = vmax; | |
7fd59977 | 2812 | } |
2813 | } | |
2814 | } | |
2815 | } | |
2816 | // | |
2817 | // | |
2818 | // The block is dedicated to determine whether WLine [ifprm, ilprm] | |
2819 | // crosses the degenerated zone on each given surface or not. | |
2820 | // If Yes -> We will not use info about surfaces during approximation | |
8e0115e4 | 2821 | // because inside degenerated zone of the surface the approx. algo. |
7fd59977 | 2822 | // uses wrong values of normal, etc., and resulting curve will have |
2823 | // oscillations that we would not like to have. | |
7fd59977 | 2824 | |
2825 | ||
4e57c75e | 2826 | |
7fd59977 | 2827 | static |
2828 | Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d, | |
655fddc8 | 2829 | const Handle(Geom_Surface)& aS, |
2830 | const Standard_Integer iDir); | |
7fd59977 | 2831 | static |
2832 | Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S, | |
655fddc8 | 2833 | const TopoDS_Face& aF1, |
2834 | const TopoDS_Face& aF2); | |
7fd59977 | 2835 | //======================================================================= |
2836 | //function : NotUseSurfacesForApprox | |
2837 | //purpose : | |
2838 | //======================================================================= | |
2839 | Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1, | |
655fddc8 | 2840 | const TopoDS_Face& aF2, |
2841 | const Handle(IntPatch_WLine)& WL, | |
2842 | const Standard_Integer ifprm, | |
2843 | const Standard_Integer ilprm) | |
7fd59977 | 2844 | { |
2845 | Standard_Boolean bPInDZ; | |
2846 | ||
2847 | Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve(); | |
2848 | ||
2849 | const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm); | |
2850 | bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2); | |
2851 | if (bPInDZ) { | |
2852 | return bPInDZ; | |
2853 | } | |
2854 | ||
2855 | const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm); | |
2856 | bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2); | |
2857 | ||
2858 | return bPInDZ; | |
2859 | } | |
2860 | //======================================================================= | |
2861 | //function : IsPointInDegeneratedZone | |
2862 | //purpose : | |
2863 | //======================================================================= | |
2864 | Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S, | |
655fddc8 | 2865 | const TopoDS_Face& aF1, |
2866 | const TopoDS_Face& aF2) | |
2867 | ||
7fd59977 | 2868 | { |
2869 | Standard_Boolean bFlag=Standard_True; | |
2870 | Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22; | |
2871 | Standard_Real U1, V1, U2, V2, aDelta, aD; | |
2872 | gp_Pnt2d aP2d; | |
2873 | ||
2874 | Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1); | |
2875 | aS1->Bounds(US11, US12, VS11, VS12); | |
2876 | GeomAdaptor_Surface aGAS1(aS1); | |
2877 | ||
2878 | Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2); | |
2879 | aS1->Bounds(US21, US22, VS21, VS22); | |
2880 | GeomAdaptor_Surface aGAS2(aS2); | |
2881 | // | |
2882 | //const gp_Pnt& aP=aP2S.Value(); | |
2883 | aP2S.Parameters(U1, V1, U2, V2); | |
2884 | // | |
2885 | aDelta=1.e-7; | |
2886 | // Check on Surf 1 | |
2887 | aD=aGAS1.UResolution(aDelta); | |
2888 | aP2d.SetCoord(U1, V1); | |
2889 | if (fabs(U1-US11) < aD) { | |
2890 | bFlag=IsDegeneratedZone(aP2d, aS1, 1); | |
2891 | if (bFlag) { | |
2892 | return bFlag; | |
2893 | } | |
2894 | } | |
2895 | if (fabs(U1-US12) < aD) { | |
2896 | bFlag=IsDegeneratedZone(aP2d, aS1, 1); | |
2897 | if (bFlag) { | |
2898 | return bFlag; | |
2899 | } | |
2900 | } | |
2901 | aD=aGAS1.VResolution(aDelta); | |
2902 | if (fabs(V1-VS11) < aDelta) { | |
2903 | bFlag=IsDegeneratedZone(aP2d, aS1, 2); | |
2904 | if (bFlag) { | |
2905 | return bFlag; | |
2906 | } | |
2907 | } | |
2908 | if (fabs(V1-VS12) < aDelta) { | |
2909 | bFlag=IsDegeneratedZone(aP2d, aS1, 2); | |
2910 | if (bFlag) { | |
2911 | return bFlag; | |
2912 | } | |
2913 | } | |
2914 | // Check on Surf 2 | |
2915 | aD=aGAS2.UResolution(aDelta); | |
2916 | aP2d.SetCoord(U2, V2); | |
2917 | if (fabs(U2-US21) < aDelta) { | |
2918 | bFlag=IsDegeneratedZone(aP2d, aS2, 1); | |
2919 | if (bFlag) { | |
2920 | return bFlag; | |
2921 | } | |
2922 | } | |
2923 | if (fabs(U2-US22) < aDelta) { | |
2924 | bFlag=IsDegeneratedZone(aP2d, aS2, 1); | |
2925 | if (bFlag) { | |
2926 | return bFlag; | |
2927 | } | |
2928 | } | |
2929 | aD=aGAS2.VResolution(aDelta); | |
2930 | if (fabs(V2-VS21) < aDelta) { | |
2931 | bFlag=IsDegeneratedZone(aP2d, aS2, 2); | |
2932 | if (bFlag) { | |
2933 | return bFlag; | |
2934 | } | |
2935 | } | |
2936 | if (fabs(V2-VS22) < aDelta) { | |
2937 | bFlag=IsDegeneratedZone(aP2d, aS2, 2); | |
2938 | if (bFlag) { | |
2939 | return bFlag; | |
2940 | } | |
2941 | } | |
2942 | return !bFlag; | |
2943 | } | |
2944 | ||
2945 | //======================================================================= | |
2946 | //function : IsDegeneratedZone | |
2947 | //purpose : | |
2948 | //======================================================================= | |
2949 | Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d, | |
655fddc8 | 2950 | const Handle(Geom_Surface)& aS, |
2951 | const Standard_Integer iDir) | |
7fd59977 | 2952 | { |
2953 | Standard_Boolean bFlag=Standard_True; | |
2954 | Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD; | |
2955 | Standard_Real aXm, aYm, aXb, aYb, aXe, aYe; | |
2956 | aS->Bounds(US1, US2, VS1, VS2); | |
2957 | ||
2958 | gp_Pnt aPm, aPb, aPe; | |
2959 | ||
2960 | aXm=aP2d.X(); | |
2961 | aYm=aP2d.Y(); | |
2962 | ||
2963 | aS->D0(aXm, aYm, aPm); | |
2964 | ||
2965 | dX=1.e-5; | |
2966 | dY=1.e-5; | |
2967 | dD=1.e-12; | |
2968 | ||
2969 | if (iDir==1) { | |
2970 | aXb=aXm; | |
2971 | aXe=aXm; | |
2972 | aYb=aYm-dY; | |
2973 | if (aYb < VS1) { | |
2974 | aYb=VS1; | |
2975 | } | |
2976 | aYe=aYm+dY; | |
2977 | if (aYe > VS2) { | |
2978 | aYe=VS2; | |
2979 | } | |
2980 | aS->D0(aXb, aYb, aPb); | |
2981 | aS->D0(aXe, aYe, aPe); | |
2982 | ||
2983 | d1=aPm.Distance(aPb); | |
2984 | d2=aPm.Distance(aPe); | |
2985 | if (d1 < dD && d2 < dD) { | |
2986 | return bFlag; | |
2987 | } | |
2988 | return !bFlag; | |
2989 | } | |
2990 | // | |
2991 | else if (iDir==2) { | |
2992 | aYb=aYm; | |
2993 | aYe=aYm; | |
2994 | aXb=aXm-dX; | |
2995 | if (aXb < US1) { | |
2996 | aXb=US1; | |
2997 | } | |
2998 | aXe=aXm+dX; | |
2999 | if (aXe > US2) { | |
3000 | aXe=US2; | |
3001 | } | |
3002 | aS->D0(aXb, aYb, aPb); | |
3003 | aS->D0(aXe, aYe, aPe); | |
3004 | ||
3005 | d1=aPm.Distance(aPb); | |
3006 | d2=aPm.Distance(aPe); | |
3007 | if (d1 < dD && d2 < dD) { | |
3008 | return bFlag; | |
3009 | } | |
3010 | return !bFlag; | |
3011 | } | |
3012 | return !bFlag; | |
3013 | } | |
3014 | ||
3015 | //========================================================================= | |
3016 | // static function : ComputePurgedWLine | |
3017 | // purpose : Removes equal points (leave one of equal points) from theWLine | |
3018 | // and recompute vertex parameters. | |
3019 | // Returns new WLine or null WLine if the number | |
3020 | // of the points is less than 2. | |
3021 | //========================================================================= | |
3022 | Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine) { | |
3928aec6 | 3023 | |
3928aec6 | 3024 | Standard_Integer i, k, v, nb, nbvtx; |
7fd59977 | 3025 | Handle(IntPatch_WLine) aResult; |
3928aec6 P |
3026 | nbvtx = theWLine->NbVertex(); |
3027 | nb = theWLine->NbPnts(); | |
3028 | if (nb==2) { | |
3029 | const IntSurf_PntOn2S& p1 = theWLine->Point(1); | |
3030 | const IntSurf_PntOn2S& p2 = theWLine->Point(2); | |
3031 | if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) { | |
3032 | return aResult; | |
3033 | } | |
3034 | } | |
3035 | // | |
7fd59977 | 3036 | Handle(IntPatch_WLine) aLocalWLine; |
3037 | Handle(IntPatch_WLine) aTmpWLine = theWLine; | |
7fd59977 | 3038 | Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S(); |
3039 | aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False); | |
7fd59977 | 3040 | for(i = 1; i <= nb; i++) { |
3041 | aLineOn2S->Add(theWLine->Point(i)); | |
3042 | } | |
3043 | ||
3044 | for(v = 1; v <= nbvtx; v++) { | |
3045 | aLocalWLine->AddVertex(theWLine->Vertex(v)); | |
3046 | } | |
3047 | ||
3048 | for(i = 1; i <= aLineOn2S->NbPoints(); i++) { | |
3049 | Standard_Integer aStartIndex = i + 1; | |
3050 | Standard_Integer anEndIndex = i + 5; | |
3051 | nb = aLineOn2S->NbPoints(); | |
3052 | anEndIndex = (anEndIndex > nb) ? nb : anEndIndex; | |
3053 | ||
a2eede02 | 3054 | if((aStartIndex > nb) || (anEndIndex <= 1)) { |
7fd59977 | 3055 | continue; |
3056 | } | |
3057 | k = aStartIndex; | |
3058 | ||
3059 | while(k <= anEndIndex) { | |
3060 | ||
3061 | if(i != k) { | |
655fddc8 | 3062 | IntSurf_PntOn2S p1 = aLineOn2S->Value(i); |
3063 | IntSurf_PntOn2S p2 = aLineOn2S->Value(k); | |
3064 | ||
3065 | if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) { | |
3066 | aTmpWLine = aLocalWLine; | |
3067 | aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False); | |
3068 | ||
3069 | for(v = 1; v <= aTmpWLine->NbVertex(); v++) { | |
3070 | IntPatch_Point aVertex = aTmpWLine->Vertex(v); | |
3071 | Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine(); | |
3072 | ||
3073 | if(avertexindex >= k) { | |
3074 | aVertex.SetParameter(aVertex.ParameterOnLine() - 1.); | |
3075 | } | |
3076 | aLocalWLine->AddVertex(aVertex); | |
3077 | } | |
3078 | aLineOn2S->RemovePoint(k); | |
3079 | anEndIndex--; | |
3080 | continue; | |
3081 | } | |
7fd59977 | 3082 | } |
3083 | k++; | |
3084 | } | |
3085 | } | |
3086 | ||
3087 | if(aLineOn2S->NbPoints() > 1) { | |
3088 | aResult = aLocalWLine; | |
3089 | } | |
3090 | return aResult; | |
3091 | } | |
3092 | ||
3093 | //======================================================================= | |
3094 | //function : TolR3d | |
3095 | //purpose : | |
3096 | //======================================================================= | |
3097 | void TolR3d(const TopoDS_Face& aF1, | |
655fddc8 | 3098 | const TopoDS_Face& aF2, |
3099 | Standard_Real& myTolReached3d) | |
7fd59977 | 3100 | { |
3101 | Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh; | |
3102 | ||
3103 | aTolTresh=2.999999e-3; | |
3104 | aTolF1 = BRep_Tool::Tolerance(aF1); | |
3105 | aTolF2 = BRep_Tool::Tolerance(aF2); | |
3106 | aTolFMax=Max(aTolF1, aTolF2); | |
3107 | ||
3108 | if (aTolFMax>aTolTresh) { | |
3109 | myTolReached3d=aTolFMax; | |
3110 | } | |
3111 | } | |
3112 | //======================================================================= | |
7fd59977 | 3113 | //function : IsPointOnBoundary |
3114 | //purpose : | |
3115 | //======================================================================= | |
3116 | Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter, | |
655fddc8 | 3117 | const Standard_Real theFirstBoundary, |
3118 | const Standard_Real theSecondBoundary, | |
3119 | const Standard_Real theResolution, | |
3120 | Standard_Boolean& IsOnFirstBoundary) | |
7fd59977 | 3121 | { |
3122 | Standard_Boolean bRet; | |
3123 | Standard_Integer i; | |
3124 | Standard_Real adist; | |
3125 | // | |
3126 | bRet=Standard_False; | |
3127 | for(i = 0; i < 2; ++i) { | |
3128 | IsOnFirstBoundary = (i == 0); | |
3129 | if (IsOnFirstBoundary) { | |
3130 | adist = fabs(theParameter - theFirstBoundary); | |
3131 | } | |
3132 | else { | |
3133 | adist = fabs(theParameter - theSecondBoundary); | |
3134 | } | |
3135 | if(adist < theResolution) { | |
3136 | return !bRet; | |
3137 | } | |
3138 | } | |
3139 | return bRet; | |
3140 | } | |
3141 | // ------------------------------------------------------------------------------------------------ | |
3142 | // static function: FindPoint | |
3143 | // purpose: | |
3144 | // ------------------------------------------------------------------------------------------------ | |
3145 | Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint, | |
655fddc8 | 3146 | const gp_Pnt2d& theLastPoint, |
3147 | const Standard_Real theUmin, | |
3148 | const Standard_Real theUmax, | |
3149 | const Standard_Real theVmin, | |
3150 | const Standard_Real theVmax, | |
3151 | gp_Pnt2d& theNewPoint) { | |
7fd59977 | 3152 | |
3153 | gp_Vec2d aVec(theFirstPoint, theLastPoint); | |
3154 | Standard_Integer i = 0, j = 0; | |
3155 | ||
3156 | for(i = 0; i < 4; i++) { | |
3157 | gp_Vec2d anOtherVec; | |
3158 | gp_Vec2d anOtherVecNormal; | |
3159 | gp_Pnt2d aprojpoint = theLastPoint; | |
3160 | ||
3161 | if((i % 2) == 0) { | |
3162 | anOtherVec.SetX(0.); | |
3163 | anOtherVec.SetY(1.); | |
3164 | anOtherVecNormal.SetX(1.); | |
3165 | anOtherVecNormal.SetY(0.); | |
3166 | ||
3167 | if(i < 2) | |
655fddc8 | 3168 | aprojpoint.SetX(theUmin); |
7fd59977 | 3169 | else |
655fddc8 | 3170 | aprojpoint.SetX(theUmax); |
7fd59977 | 3171 | } |
3172 | else { | |
3173 | anOtherVec.SetX(1.); | |
3174 | anOtherVec.SetY(0.); | |
3175 | anOtherVecNormal.SetX(0.); | |
3176 | anOtherVecNormal.SetY(1.); | |
3177 | ||
3178 | if(i < 2) | |
655fddc8 | 3179 | aprojpoint.SetY(theVmin); |
7fd59977 | 3180 | else |
655fddc8 | 3181 | aprojpoint.SetY(theVmax); |
7fd59977 | 3182 | } |
3183 | gp_Vec2d anormvec = aVec; | |
3184 | anormvec.Normalize(); | |
fa9681ca | 3185 | RefineVector(anormvec); |
7fd59977 | 3186 | Standard_Real adot1 = anormvec.Dot(anOtherVecNormal); |
3187 | ||
3188 | if(fabs(adot1) < Precision::Angular()) | |
3189 | continue; | |
3190 | Standard_Real adist = 0.; | |
3191 | Standard_Boolean bIsOut = Standard_False; | |
3192 | ||
3193 | if((i % 2) == 0) { | |
3194 | adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax); | |
3195 | bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax); | |
3196 | } | |
3197 | else { | |
3198 | adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax); | |
3199 | bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax); | |
3200 | } | |
3201 | Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1; | |
3202 | ||
3203 | for(j = 0; j < 2; j++) { | |
3204 | anoffset = (j == 0) ? anoffset : -anoffset; | |
3205 | gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset)); | |
3206 | gp_Vec2d acurvec(theLastPoint, acurpoint); | |
3207 | if ( bIsOut ) | |
655fddc8 | 3208 | acurvec.Reverse(); |
7fd59977 | 3209 | |
9e9df9d9 P |
3210 | Standard_Real aDotX, anAngleX; |
3211 | // | |
3212 | aDotX = aVec.Dot(acurvec); | |
3213 | anAngleX = aVec.Angle(acurvec); | |
3214 | // | |
3215 | if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) { | |
655fddc8 | 3216 | if((i % 2) == 0) { |
3217 | if((acurpoint.Y() >= theVmin) && | |
3218 | (acurpoint.Y() <= theVmax)) { | |
3219 | theNewPoint = acurpoint; | |
3220 | return Standard_True; | |
3221 | } | |
3222 | } | |
3223 | else { | |
3224 | if((acurpoint.X() >= theUmin) && | |
3225 | (acurpoint.X() <= theUmax)) { | |
3226 | theNewPoint = acurpoint; | |
3227 | return Standard_True; | |
3228 | } | |
3229 | } | |
7fd59977 | 3230 | } |
3231 | } | |
3232 | } | |
3233 | return Standard_False; | |
3234 | } | |
3235 | ||
3236 | ||
3237 | // ------------------------------------------------------------------------------------------------ | |
3238 | // static function: FindPoint | |
3239 | // purpose: Find point on the boundary of radial tangent zone | |
3240 | // ------------------------------------------------------------------------------------------------ | |
3241 | Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint, | |
655fddc8 | 3242 | const gp_Pnt2d& theLastPoint, |
3243 | const Standard_Real theUmin, | |
3244 | const Standard_Real theUmax, | |
3245 | const Standard_Real theVmin, | |
3246 | const Standard_Real theVmax, | |
3247 | const gp_Pnt2d& theTanZoneCenter, | |
3248 | const Standard_Real theZoneRadius, | |
3249 | Handle(GeomAdaptor_HSurface) theGASurface, | |
3250 | gp_Pnt2d& theNewPoint) { | |
7fd59977 | 3251 | theNewPoint = theLastPoint; |
3252 | ||
3253 | if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) ) | |
3254 | return Standard_False; | |
3255 | ||
3256 | Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius ); | |
3257 | Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius ); | |
3258 | ||
3259 | Standard_Real aRadius = ( aUResolution < aVResolution ) ? aUResolution : aVResolution; | |
3260 | gp_Ax22d anAxis( theTanZoneCenter, gp_Dir2d(1, 0), gp_Dir2d(0, 1) ); | |
3261 | gp_Circ2d aCircle( anAxis, aRadius ); | |
3262 | ||
3263 | // | |
3264 | gp_Vec2d aDir( theLastPoint.XY() - theFirstPoint.XY() ); | |
3265 | Standard_Real aLength = aDir.Magnitude(); | |
3266 | if ( aLength <= gp::Resolution() ) | |
3267 | return Standard_False; | |
3268 | gp_Lin2d aLine( theFirstPoint, aDir ); | |
3269 | ||
3270 | // | |
3271 | Handle(Geom2d_Line) aCLine = new Geom2d_Line( aLine ); | |
3272 | Handle(Geom2d_TrimmedCurve) aC1 = new Geom2d_TrimmedCurve( aCLine, 0, aLength ); | |
3273 | Handle(Geom2d_Circle) aC2 = new Geom2d_Circle( aCircle ); | |
3274 | ||
3275 | Standard_Real aTol = aRadius * 0.001; | |
3276 | aTol = ( aTol < Precision::PConfusion() ) ? Precision::PConfusion() : aTol; | |
3277 | ||
3278 | Geom2dAPI_InterCurveCurve anIntersector; | |
3279 | anIntersector.Init( aC1, aC2, aTol ); | |
3280 | ||
3281 | if ( anIntersector.NbPoints() == 0 ) | |
3282 | return Standard_False; | |
3283 | ||
3284 | Standard_Boolean aFound = Standard_False; | |
3285 | Standard_Real aMinDist = aLength * aLength; | |
3286 | Standard_Integer i = 0; | |
3287 | for ( i = 1; i <= anIntersector.NbPoints(); i++ ) { | |
3288 | gp_Pnt2d aPInt = anIntersector.Point( i ); | |
3289 | if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) { | |
3290 | if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) && | |
655fddc8 | 3291 | ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) { |
3292 | theNewPoint = aPInt; | |
3293 | aFound = Standard_True; | |
7fd59977 | 3294 | } |
3295 | } | |
3296 | } | |
3297 | ||
3298 | return aFound; | |
3299 | } | |
3300 | ||
3301 | // ------------------------------------------------------------------------------------------------ | |
3302 | // static function: IsInsideTanZone | |
3303 | // purpose: Check if point is inside a radial tangent zone | |
3304 | // ------------------------------------------------------------------------------------------------ | |
3305 | Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint, | |
655fddc8 | 3306 | const gp_Pnt2d& theTanZoneCenter, |
3307 | const Standard_Real theZoneRadius, | |
3308 | Handle(GeomAdaptor_HSurface) theGASurface) { | |
7fd59977 | 3309 | |
3310 | Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius ); | |
3311 | Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius ); | |
3312 | Standard_Real aRadiusSQR = ( aUResolution < aVResolution ) ? aUResolution : aVResolution; | |
3313 | aRadiusSQR *= aRadiusSQR; | |
3314 | if ( thePoint.SquareDistance( theTanZoneCenter ) <= aRadiusSQR ) | |
3315 | return Standard_True; | |
3316 | return Standard_False; | |
3317 | } | |
3318 | ||
3319 | // ------------------------------------------------------------------------------------------------ | |
3320 | // static function: CheckTangentZonesExist | |
3321 | // purpose: Check if tangent zone exists | |
3322 | // ------------------------------------------------------------------------------------------------ | |
3323 | Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& theSurface1, | |
655fddc8 | 3324 | const Handle(GeomAdaptor_HSurface)& theSurface2 ) |
7fd59977 | 3325 | { |
3326 | if ( ( theSurface1->GetType() != GeomAbs_Torus ) || | |
3327 | ( theSurface2->GetType() != GeomAbs_Torus ) ) | |
3328 | return Standard_False; | |
3329 | ||
7fd59977 | 3330 | gp_Torus aTor1 = theSurface1->Torus(); |
3331 | gp_Torus aTor2 = theSurface2->Torus(); | |
3332 | ||
3333 | if ( aTor1.Location().Distance( aTor2.Location() ) > Precision::Confusion() ) | |
3334 | return Standard_False; | |
3335 | ||
3336 | if ( ( fabs( aTor1.MajorRadius() - aTor2.MajorRadius() ) > Precision::Confusion() ) || | |
3337 | ( fabs( aTor1.MinorRadius() - aTor2.MinorRadius() ) > Precision::Confusion() ) ) | |
3338 | return Standard_False; | |
3339 | ||
3340 | if ( ( aTor1.MajorRadius() < aTor1.MinorRadius() ) || | |
3341 | ( aTor2.MajorRadius() < aTor2.MinorRadius() ) ) | |
3342 | return Standard_False; | |
3343 | return Standard_True; | |
3344 | } | |
3345 | ||
3346 | // ------------------------------------------------------------------------------------------------ | |
3347 | // static function: ComputeTangentZones | |
3348 | // purpose: | |
3349 | // ------------------------------------------------------------------------------------------------ | |
3350 | Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1, | |
655fddc8 | 3351 | const Handle(GeomAdaptor_HSurface)& theSurface2, |
3352 | const TopoDS_Face& theFace1, | |
3353 | const TopoDS_Face& theFace2, | |
3354 | Handle(TColgp_HArray1OfPnt2d)& theResultOnS1, | |
3355 | Handle(TColgp_HArray1OfPnt2d)& theResultOnS2, | |
3356 | Handle(TColStd_HArray1OfReal)& theResultRadius, | |
1e143abb | 3357 | const Handle(IntTools_Context)& aContext) |
4f189102 | 3358 | { |
7fd59977 | 3359 | Standard_Integer aResult = 0; |
3360 | if ( !CheckTangentZonesExist( theSurface1, theSurface2 ) ) | |
3361 | return aResult; | |
3362 | ||
7fd59977 | 3363 | |
3364 | TColgp_SequenceOfPnt2d aSeqResultS1, aSeqResultS2; | |
3365 | TColStd_SequenceOfReal aSeqResultRad; | |
3366 | ||
3367 | gp_Torus aTor1 = theSurface1->Torus(); | |
3368 | gp_Torus aTor2 = theSurface2->Torus(); | |
3369 | ||
3370 | gp_Ax2 anax1( aTor1.Location(), aTor1.Axis().Direction() ); | |
3371 | gp_Ax2 anax2( aTor2.Location(), aTor2.Axis().Direction() ); | |
3372 | Standard_Integer j = 0; | |
3373 | ||
3374 | for ( j = 0; j < 2; j++ ) { | |