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> | |
d4b867e6 | 90 | #include <Geom2dAdaptor.hxx> |
7fd59977 | 91 | #include <GeomAdaptor_Curve.hxx> |
92 | #include <GeomAdaptor_HSurface.hxx> | |
93 | #include <GeomAdaptor_Surface.hxx> | |
94 | #include <GeomLib_CheckBSplineCurve.hxx> | |
95 | #include <GeomLib_Check2dBSplineCurve.hxx> | |
96 | ||
97 | #include <GeomInt_WLApprox.hxx> | |
98 | #include <GeomProjLib.hxx> | |
99 | #include <GeomAPI_ProjectPointOnSurf.hxx> | |
100 | #include <Geom2dAdaptor_Curve.hxx> | |
7fd59977 | 101 | #include <TopoDS.hxx> |
102 | #include <TopoDS_Edge.hxx> | |
103 | #include <TopExp_Explorer.hxx> | |
104 | ||
105 | #include <BRep_Tool.hxx> | |
106 | #include <BRepTools.hxx> | |
107 | #include <BRepAdaptor_Surface.hxx> | |
108 | ||
7fd59977 | 109 | #include <IntTools_Curve.hxx> |
110 | #include <IntTools_Tools.hxx> | |
111 | #include <IntTools_Tools.hxx> | |
112 | #include <IntTools_TopolTool.hxx> | |
113 | #include <IntTools_PntOnFace.hxx> | |
114 | #include <IntTools_PntOn2Faces.hxx> | |
1e143abb | 115 | #include <IntTools_Context.hxx> |
0fc4f2e2 | 116 | #include <IntSurf_ListIteratorOfListOfPntOn2S.hxx> |
2a78ec6a | 117 | #include <GeomInt.hxx> |
a2eede02 | 118 | |
d4b867e6 | 119 | #include <Approx_CurveOnSurface.hxx> |
120 | #include <GeomAdaptor.hxx> | |
121 | #include <GeomInt_IntSS.hxx> | |
122 | ||
fa9681ca P |
123 | static |
124 | void RefineVector(gp_Vec2d& aV2D); | |
0797d9d3 | 125 | #ifdef OCCT_DEBUG_DUMPWLINE |
a2eede02 P |
126 | static |
127 | void DumpWLine(const Handle(IntPatch_WLine)& aWLine); | |
4e18e72a | 128 | #endif |
7fd59977 | 129 | // |
130 | static | |
131 | void TolR3d(const TopoDS_Face& , | |
655fddc8 | 132 | const TopoDS_Face& , |
133 | Standard_Real& ); | |
7fd59977 | 134 | static |
135 | Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)&, | |
655fddc8 | 136 | const Standard_Integer, |
137 | const Standard_Integer); | |
7fd59977 | 138 | |
139 | static | |
140 | void Parameters(const Handle(GeomAdaptor_HSurface)&, | |
655fddc8 | 141 | const Handle(GeomAdaptor_HSurface)&, |
142 | const gp_Pnt&, | |
143 | Standard_Real&, | |
144 | Standard_Real&, | |
145 | Standard_Real&, | |
146 | Standard_Real&); | |
7fd59977 | 147 | |
7fd59977 | 148 | static |
149 | void CorrectSurfaceBoundaries(const TopoDS_Face& theFace, | |
655fddc8 | 150 | const Standard_Real theTolerance, |
151 | Standard_Real& theumin, | |
152 | Standard_Real& theumax, | |
153 | Standard_Real& thevmin, | |
154 | Standard_Real& thevmax); | |
d4b867e6 | 155 | |
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 | ||
7fd59977 | 167 | static |
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 | |
4f189102 | 283 | // |
989341c5 | 284 | static |
285 | Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC, | |
286 | const TopoDS_Face& aFace); | |
287 | ||
7fd59977 | 288 | // |
37b6f439 | 289 | static |
1b7ae951 | 290 | Standard_Real MaxDistance(const Handle(Geom_Curve)& theC, |
291 | const Standard_Real aT, | |
292 | GeomAPI_ProjectPointOnSurf& theProjPS); | |
293 | static | |
294 | Standard_Real FindMaxDistance(const Handle(Geom_Curve)& theC, | |
295 | const Standard_Real theFirst, | |
296 | const Standard_Real theLast, | |
297 | GeomAPI_ProjectPointOnSurf& theProjPS, | |
298 | const Standard_Real theEps); | |
299 | static | |
300 | Standard_Real FindMaxDistance(const Handle(Geom_Curve)& theCurve, | |
301 | const Standard_Real theFirst, | |
302 | const Standard_Real theLast, | |
303 | const TopoDS_Face& theFace, | |
304 | const Handle(IntTools_Context)& theContext); | |
37b6f439 | 305 | |
9a5a19e9 | 306 | static |
307 | void CorrectPlaneBoundaries(Standard_Real& aUmin, | |
308 | Standard_Real& aUmax, | |
309 | Standard_Real& aVmin, | |
310 | Standard_Real& aVmax); | |
311 | ||
7fd59977 | 312 | //======================================================================= |
313 | //function : | |
314 | //purpose : | |
315 | //======================================================================= | |
4f189102 | 316 | IntTools_FaceFace::IntTools_FaceFace() |
7fd59977 | 317 | { |
3f16d970 | 318 | myIsDone=Standard_False; |
7fd59977 | 319 | myTangentFaces=Standard_False; |
320 | // | |
321 | myHS1 = new GeomAdaptor_HSurface (); | |
322 | myHS2 = new GeomAdaptor_HSurface (); | |
323 | myTolReached2d=0.; | |
324 | myTolReached3d=0.; | |
325 | SetParameters(Standard_True, Standard_True, Standard_True, 1.e-07); | |
4f189102 P |
326 | |
327 | } | |
328 | //======================================================================= | |
329 | //function : SetContext | |
330 | //purpose : | |
331 | //======================================================================= | |
1e143abb | 332 | void IntTools_FaceFace::SetContext(const Handle(IntTools_Context)& aContext) |
4f189102 P |
333 | { |
334 | myContext=aContext; | |
335 | } | |
336 | //======================================================================= | |
337 | //function : Context | |
338 | //purpose : | |
339 | //======================================================================= | |
1e143abb | 340 | const Handle(IntTools_Context)& IntTools_FaceFace::Context()const |
4f189102 P |
341 | { |
342 | return myContext; | |
7fd59977 | 343 | } |
344 | //======================================================================= | |
345 | //function : Face1 | |
346 | //purpose : | |
347 | //======================================================================= | |
4f189102 | 348 | const TopoDS_Face& IntTools_FaceFace::Face1() const |
7fd59977 | 349 | { |
350 | return myFace1; | |
351 | } | |
7fd59977 | 352 | //======================================================================= |
353 | //function : Face2 | |
354 | //purpose : | |
355 | //======================================================================= | |
4f189102 | 356 | const TopoDS_Face& IntTools_FaceFace::Face2() const |
7fd59977 | 357 | { |
358 | return myFace2; | |
359 | } | |
7fd59977 | 360 | //======================================================================= |
361 | //function : TangentFaces | |
362 | //purpose : | |
363 | //======================================================================= | |
4f189102 | 364 | Standard_Boolean IntTools_FaceFace::TangentFaces() const |
7fd59977 | 365 | { |
366 | return myTangentFaces; | |
367 | } | |
368 | //======================================================================= | |
369 | //function : Points | |
370 | //purpose : | |
371 | //======================================================================= | |
4f189102 | 372 | const IntTools_SequenceOfPntOn2Faces& IntTools_FaceFace::Points() const |
7fd59977 | 373 | { |
374 | return myPnts; | |
375 | } | |
376 | //======================================================================= | |
377 | //function : IsDone | |
378 | //purpose : | |
379 | //======================================================================= | |
4f189102 | 380 | Standard_Boolean IntTools_FaceFace::IsDone() const |
7fd59977 | 381 | { |
382 | return myIsDone; | |
383 | } | |
384 | //======================================================================= | |
385 | //function : TolReached3d | |
386 | //purpose : | |
387 | //======================================================================= | |
4f189102 | 388 | Standard_Real IntTools_FaceFace::TolReached3d() const |
7fd59977 | 389 | { |
390 | return myTolReached3d; | |
391 | } | |
392 | //======================================================================= | |
393 | //function : Lines | |
394 | //purpose : return lines of intersection | |
395 | //======================================================================= | |
4f189102 | 396 | const IntTools_SequenceOfCurves& IntTools_FaceFace::Lines() const |
7fd59977 | 397 | { |
4f189102 P |
398 | StdFail_NotDone_Raise_if |
399 | (!myIsDone, | |
788cbaf4 | 400 | "IntTools_FaceFace::Lines() => myIntersector NOT DONE"); |
7fd59977 | 401 | return mySeqOfCurve; |
402 | } | |
7fd59977 | 403 | //======================================================================= |
404 | //function : TolReached2d | |
405 | //purpose : | |
406 | //======================================================================= | |
4f189102 | 407 | Standard_Real IntTools_FaceFace::TolReached2d() const |
7fd59977 | 408 | { |
409 | return myTolReached2d; | |
410 | } | |
411 | // ======================================================================= | |
412 | // function: SetParameters | |
413 | // | |
414 | // ======================================================================= | |
4f189102 | 415 | void IntTools_FaceFace::SetParameters(const Standard_Boolean ToApproxC3d, |
655fddc8 | 416 | const Standard_Boolean ToApproxC2dOnS1, |
417 | const Standard_Boolean ToApproxC2dOnS2, | |
418 | const Standard_Real ApproximationTolerance) | |
7fd59977 | 419 | { |
420 | myApprox = ToApproxC3d; | |
421 | myApprox1 = ToApproxC2dOnS1; | |
422 | myApprox2 = ToApproxC2dOnS2; | |
423 | myTolApprox = ApproximationTolerance; | |
424 | } | |
425 | //======================================================================= | |
426 | //function : SetList | |
427 | //purpose : | |
428 | //======================================================================= | |
7fd59977 | 429 | void IntTools_FaceFace::SetList(IntSurf_ListOfPntOn2S& aListOfPnts) |
430 | { | |
431 | myListOfPnts = aListOfPnts; | |
432 | } | |
788cbaf4 | 433 | |
434 | ||
435 | static Standard_Boolean isTreatAnalityc(const TopoDS_Face& theF1, | |
436 | const TopoDS_Face& theF2) | |
437 | { | |
438 | const Standard_Real Tolang = 1.e-8; | |
439 | const Standard_Real aTolF1=BRep_Tool::Tolerance(theF1); | |
440 | const Standard_Real aTolF2=BRep_Tool::Tolerance(theF2); | |
441 | const Standard_Real aTolSum = aTolF1 + aTolF2; | |
442 | Standard_Real aHigh = 0.0; | |
443 | ||
444 | const BRepAdaptor_Surface aBAS1(theF1), aBAS2(theF2); | |
445 | const GeomAbs_SurfaceType aType1=aBAS1.GetType(); | |
446 | const GeomAbs_SurfaceType aType2=aBAS2.GetType(); | |
447 | ||
448 | gp_Pln aS1; | |
449 | gp_Cylinder aS2; | |
450 | if(aType1 == GeomAbs_Plane) | |
451 | { | |
452 | aS1=aBAS1.Plane(); | |
453 | } | |
454 | else if(aType2 == GeomAbs_Plane) | |
455 | { | |
456 | aS1=aBAS2.Plane(); | |
457 | } | |
458 | else | |
459 | { | |
460 | return Standard_True; | |
461 | } | |
462 | ||
463 | if(aType1 == GeomAbs_Cylinder) | |
464 | { | |
465 | aS2=aBAS1.Cylinder(); | |
466 | const Standard_Real VMin = aBAS1.FirstVParameter(); | |
467 | const Standard_Real VMax = aBAS1.LastVParameter(); | |
468 | ||
469 | if( Precision::IsNegativeInfinite(VMin) || | |
470 | Precision::IsPositiveInfinite(VMax)) | |
471 | return Standard_True; | |
472 | else | |
473 | aHigh = VMax - VMin; | |
474 | } | |
475 | else if(aType2 == GeomAbs_Cylinder) | |
476 | { | |
477 | aS2=aBAS2.Cylinder(); | |
478 | ||
479 | const Standard_Real VMin = aBAS2.FirstVParameter(); | |
480 | const Standard_Real VMax = aBAS2.LastVParameter(); | |
481 | ||
482 | if( Precision::IsNegativeInfinite(VMin) || | |
483 | Precision::IsPositiveInfinite(VMax)) | |
484 | return Standard_True; | |
485 | else | |
486 | aHigh = VMax - VMin; | |
487 | } | |
488 | else | |
489 | { | |
490 | return Standard_True; | |
491 | } | |
492 | ||
493 | IntAna_QuadQuadGeo inter; | |
494 | inter.Perform(aS1,aS2,Tolang,aTolSum, aHigh); | |
495 | if(inter.TypeInter() == IntAna_Ellipse) | |
496 | { | |
497 | const gp_Elips anEl = inter.Ellipse(1); | |
498 | const Standard_Real aMajorR = anEl.MajorRadius(); | |
499 | const Standard_Real aMinorR = anEl.MinorRadius(); | |
500 | ||
501 | return (aMajorR < 100000.0 * aMinorR); | |
502 | } | |
503 | else | |
504 | { | |
505 | return inter.IsDone(); | |
506 | } | |
507 | } | |
7fd59977 | 508 | //======================================================================= |
509 | //function : Perform | |
510 | //purpose : intersect surfaces of the faces | |
511 | //======================================================================= | |
9a5a19e9 | 512 | void IntTools_FaceFace::Perform(const TopoDS_Face& aF1, |
c002793b | 513 | const TopoDS_Face& aF2) |
7fd59977 | 514 | { |
788cbaf4 | 515 | Standard_Boolean RestrictLine = Standard_False, hasCone = Standard_False; |
516 | ||
4f189102 | 517 | if (myContext.IsNull()) { |
1e143abb | 518 | myContext=new IntTools_Context; |
4f189102 | 519 | } |
788cbaf4 | 520 | |
7fd59977 | 521 | mySeqOfCurve.Clear(); |
7fd59977 | 522 | myTolReached2d=0.; |
523 | myTolReached3d=0.; | |
7fd59977 | 524 | myIsDone = Standard_False; |
0fc4f2e2 | 525 | myNbrestr=0;//? |
788cbaf4 | 526 | |
0fc4f2e2 P |
527 | myFace1=aF1; |
528 | myFace2=aF2; | |
788cbaf4 | 529 | |
530 | const BRepAdaptor_Surface aBAS1(myFace1, Standard_False); | |
531 | const BRepAdaptor_Surface aBAS2(myFace2, Standard_False); | |
532 | GeomAbs_SurfaceType aType1=aBAS1.GetType(); | |
533 | GeomAbs_SurfaceType aType2=aBAS2.GetType(); | |
534 | ||
535 | const Standard_Boolean bReverse=SortTypes(aType1, aType2); | |
536 | if (bReverse) | |
537 | { | |
0fc4f2e2 P |
538 | myFace1=aF2; |
539 | myFace2=aF1; | |
540 | aType1=aBAS2.GetType(); | |
541 | aType2=aBAS1.GetType(); | |
788cbaf4 | 542 | |
543 | if (myListOfPnts.Extent()) | |
544 | { | |
0fc4f2e2 P |
545 | Standard_Real aU1,aV1,aU2,aV2; |
546 | IntSurf_ListIteratorOfListOfPntOn2S aItP2S; | |
547 | // | |
548 | aItP2S.Initialize(myListOfPnts); | |
788cbaf4 | 549 | for (; aItP2S.More(); aItP2S.Next()) |
550 | { | |
655fddc8 | 551 | IntSurf_PntOn2S& aP2S=aItP2S.Value(); |
552 | aP2S.Parameters(aU1,aV1,aU2,aV2); | |
553 | aP2S.SetValue(aU2,aV2,aU1,aV1); | |
0fc4f2e2 P |
554 | } |
555 | } | |
2d2aa6f1 | 556 | // |
557 | Standard_Boolean anAproxTmp = myApprox1; | |
558 | myApprox1 = myApprox2; | |
559 | myApprox2 = anAproxTmp; | |
0fc4f2e2 | 560 | } |
7fd59977 | 561 | |
788cbaf4 | 562 | |
563 | const Handle(Geom_Surface) S1=BRep_Tool::Surface(myFace1); | |
564 | const Handle(Geom_Surface) S2=BRep_Tool::Surface(myFace2); | |
565 | ||
566 | const Standard_Real aTolF1=BRep_Tool::Tolerance(myFace1); | |
567 | const Standard_Real aTolF2=BRep_Tool::Tolerance(myFace2); | |
568 | ||
569 | Standard_Real TolArc = aTolF1 + aTolF2; | |
570 | Standard_Real TolTang = TolArc; | |
571 | ||
572 | const Standard_Boolean isFace1Quad = (aType1 == GeomAbs_Cylinder || | |
573 | aType1 == GeomAbs_Cone || | |
574 | aType1 == GeomAbs_Torus); | |
575 | ||
576 | const Standard_Boolean isFace2Quad = (aType2 == GeomAbs_Cylinder || | |
577 | aType2 == GeomAbs_Cone || | |
578 | aType2 == GeomAbs_Torus); | |
579 | ||
a34f083b | 580 | if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) { |
788cbaf4 | 581 | Standard_Real umin, umax, vmin, vmax; |
a34f083b | 582 | // |
0fc4f2e2 | 583 | BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax); |
9a5a19e9 | 584 | CorrectPlaneBoundaries(umin, umax, vmin, vmax); |
7fd59977 | 585 | myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax); |
586 | // | |
0fc4f2e2 | 587 | BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax); |
9a5a19e9 | 588 | CorrectPlaneBoundaries(umin, umax, vmin, vmax); |
7fd59977 | 589 | myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax); |
a34f083b | 590 | // |
7fd59977 | 591 | Standard_Real TolAng = 1.e-8; |
a34f083b | 592 | // |
59495dbe | 593 | PerformPlanes(myHS1, myHS2, TolAng, TolTang, myApprox1, myApprox2, |
a34f083b | 594 | mySeqOfCurve, myTangentFaces); |
595 | // | |
7fd59977 | 596 | myIsDone = Standard_True; |
4f189102 | 597 | |
a34f083b | 598 | if(!myTangentFaces) { |
788cbaf4 | 599 | const Standard_Integer NbLinPP = mySeqOfCurve.Length(); |
a34f083b | 600 | if(NbLinPP) { |
655fddc8 | 601 | Standard_Real aTolFMax; |
602 | myTolReached3d = 1.e-7; | |
603 | aTolFMax=Max(aTolF1, aTolF2); | |
a34f083b | 604 | if (aTolFMax>myTolReached3d) { |
655fddc8 | 605 | myTolReached3d=aTolFMax; |
606 | } | |
a34f083b | 607 | // |
655fddc8 | 608 | myTolReached2d = myTolReached3d; |
788cbaf4 | 609 | |
a34f083b | 610 | if (bReverse) { |
655fddc8 | 611 | Handle(Geom2d_Curve) aC2D1, aC2D2; |
788cbaf4 | 612 | const Standard_Integer aNbLin = mySeqOfCurve.Length(); |
a34f083b | 613 | for (Standard_Integer i = 1; i <= aNbLin; ++i) { |
655fddc8 | 614 | IntTools_Curve& aIC=mySeqOfCurve(i); |
615 | aC2D1=aIC.FirstCurve2d(); | |
616 | aC2D2=aIC.SecondCurve2d(); | |
617 | aIC.SetFirstCurve2d(aC2D2); | |
618 | aIC.SetSecondCurve2d(aC2D1); | |
619 | } | |
620 | } | |
0fc4f2e2 P |
621 | } |
622 | } | |
7fd59977 | 623 | return; |
0fc4f2e2 | 624 | }//if(aType1==GeomAbs_Plane && aType2==GeomAbs_Plane){ |
788cbaf4 | 625 | |
626 | if ((aType1==GeomAbs_Plane) && isFace2Quad) | |
627 | { | |
788cbaf4 | 628 | Standard_Real umin, umax, vmin, vmax; |
9a5a19e9 | 629 | // F1 |
630 | BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax); | |
631 | CorrectPlaneBoundaries(umin, umax, vmin, vmax); | |
7fd59977 | 632 | myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax); |
633 | // F2 | |
0fc4f2e2 P |
634 | BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax); |
635 | CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax); | |
7fd59977 | 636 | myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax); |
637 | // | |
638 | if( aType2==GeomAbs_Cone ) { | |
639 | TolArc = 0.0001; | |
7fd59977 | 640 | hasCone = Standard_True; |
641 | } | |
642 | } | |
788cbaf4 | 643 | else if ((aType2==GeomAbs_Plane) && isFace1Quad) |
644 | { | |
788cbaf4 | 645 | Standard_Real umin, umax, vmin, vmax; |
9a5a19e9 | 646 | //F1 |
0fc4f2e2 P |
647 | BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax); |
648 | CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax); | |
7fd59977 | 649 | myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax); |
650 | // F2 | |
0fc4f2e2 | 651 | BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax); |
9a5a19e9 | 652 | CorrectPlaneBoundaries(umin, umax, vmin, vmax); |
7fd59977 | 653 | myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax); |
654 | // | |
655 | if( aType1==GeomAbs_Cone ) { | |
656 | TolArc = 0.0001; | |
7fd59977 | 657 | hasCone = Standard_True; |
658 | } | |
659 | } | |
788cbaf4 | 660 | else |
661 | { | |
662 | Standard_Real umin, umax, vmin, vmax; | |
0fc4f2e2 | 663 | BRepTools::UVBounds(myFace1, umin, umax, vmin, vmax); |
0fc4f2e2 | 664 | CorrectSurfaceBoundaries(myFace1, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax); |
7fd59977 | 665 | myHS1->ChangeSurface().Load(S1, umin, umax, vmin, vmax); |
0fc4f2e2 | 666 | BRepTools::UVBounds(myFace2, umin, umax, vmin, vmax); |
0fc4f2e2 | 667 | CorrectSurfaceBoundaries(myFace2, (aTolF1 + aTolF2) * 2., umin, umax, vmin, vmax); |
7fd59977 | 668 | myHS2->ChangeSurface().Load(S2, umin, umax, vmin, vmax); |
669 | } | |
788cbaf4 | 670 | |
671 | const Handle(IntTools_TopolTool) dom1 = new IntTools_TopolTool(myHS1); | |
672 | const Handle(IntTools_TopolTool) dom2 = new IntTools_TopolTool(myHS2); | |
673 | ||
7fd59977 | 674 | myLConstruct.Load(dom1, dom2, myHS1, myHS2); |
788cbaf4 | 675 | |
676 | ||
677 | Tolerances(myHS1, myHS2, TolTang); | |
678 | ||
679 | { | |
680 | const Standard_Real UVMaxStep = 0.001; | |
681 | const Standard_Real Deflection = (hasCone) ? 0.085 : 0.1; | |
59495dbe | 682 | myIntersector.SetTolerances(TolArc, TolTang, UVMaxStep, Deflection); |
788cbaf4 | 683 | } |
684 | ||
7fd59977 | 685 | if((myHS1->IsUClosed() && !myHS1->IsUPeriodic()) || |
686 | (myHS1->IsVClosed() && !myHS1->IsVPeriodic()) || | |
687 | (myHS2->IsUClosed() && !myHS2->IsUPeriodic()) || | |
788cbaf4 | 688 | (myHS2->IsVClosed() && !myHS2->IsVPeriodic())) |
689 | { | |
7fd59977 | 690 | RestrictLine = Standard_True; |
691 | } | |
692 | // | |
788cbaf4 | 693 | if((aType1 != GeomAbs_BSplineSurface) && |
59495dbe | 694 | (aType1 != GeomAbs_BezierSurface) && |
788cbaf4 | 695 | (aType1 != GeomAbs_OtherSurface) && |
696 | (aType2 != GeomAbs_BSplineSurface) && | |
59495dbe | 697 | (aType2 != GeomAbs_BezierSurface) && |
788cbaf4 | 698 | (aType2 != GeomAbs_OtherSurface)) |
699 | { | |
7fd59977 | 700 | RestrictLine = Standard_True; |
788cbaf4 | 701 | |
7fd59977 | 702 | if ((aType1 == GeomAbs_Torus) || |
788cbaf4 | 703 | (aType2 == GeomAbs_Torus)) |
704 | { | |
7fd59977 | 705 | myListOfPnts.Clear(); |
706 | } | |
707 | } | |
788cbaf4 | 708 | |
7fd59977 | 709 | // |
788cbaf4 | 710 | if(!RestrictLine) |
711 | { | |
7fd59977 | 712 | TopExp_Explorer aExp; |
788cbaf4 | 713 | for(Standard_Integer i = 0; (!RestrictLine) && (i < 2); i++) |
714 | { | |
7fd59977 | 715 | const TopoDS_Face& aF=(!i) ? myFace1 : myFace2; |
716 | aExp.Init(aF, TopAbs_EDGE); | |
788cbaf4 | 717 | for(; aExp.More(); aExp.Next()) |
718 | { | |
655fddc8 | 719 | const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current()); |
788cbaf4 | 720 | |
721 | if(BRep_Tool::Degenerated(aE)) | |
722 | { | |
655fddc8 | 723 | RestrictLine = Standard_True; |
724 | break; | |
725 | } | |
7fd59977 | 726 | } |
727 | } | |
728 | } | |
788cbaf4 | 729 | |
730 | const Standard_Boolean isGeomInt = isTreatAnalityc(aF1, aF2); | |
731 | myIntersector.Perform(myHS1, dom1, myHS2, dom2, TolArc, TolTang, | |
732 | myListOfPnts, RestrictLine, isGeomInt); | |
733 | ||
7fd59977 | 734 | myIsDone = myIntersector.IsDone(); |
788cbaf4 | 735 | |
736 | if (myIsDone) | |
737 | { | |
7fd59977 | 738 | myTangentFaces=myIntersector.TangentFaces(); |
739 | if (myTangentFaces) { | |
740 | return; | |
741 | } | |
742 | // | |
743 | if(RestrictLine) { | |
744 | myListOfPnts.Clear(); // to use LineConstructor | |
745 | } | |
746 | // | |
788cbaf4 | 747 | const Standard_Integer aNbLin = myIntersector.NbLines(); |
748 | for (Standard_Integer i=1; i <= aNbLin; ++i) { | |
7fd59977 | 749 | MakeCurve(i, dom1, dom2); |
750 | } | |
751 | // | |
752 | ComputeTolReached3d(); | |
753 | // | |
0fc4f2e2 P |
754 | if (bReverse) { |
755 | Handle(Geom2d_Curve) aC2D1, aC2D2; | |
756 | // | |
788cbaf4 | 757 | const Standard_Integer aNbLin=mySeqOfCurve.Length(); |
758 | for (Standard_Integer i=1; i<=aNbLin; ++i) | |
759 | { | |
655fddc8 | 760 | IntTools_Curve& aIC=mySeqOfCurve(i); |
761 | aC2D1=aIC.FirstCurve2d(); | |
762 | aC2D2=aIC.SecondCurve2d(); | |
763 | aIC.SetFirstCurve2d(aC2D2); | |
764 | aIC.SetSecondCurve2d(aC2D1); | |
0fc4f2e2 P |
765 | } |
766 | } | |
788cbaf4 | 767 | |
0fc4f2e2 | 768 | // Points |
e9e644ed | 769 | Standard_Boolean bValid2D1, bValid2D2; |
7fd59977 | 770 | Standard_Real U1,V1,U2,V2; |
771 | IntTools_PntOnFace aPntOnF1, aPntOnF2; | |
0fc4f2e2 | 772 | IntTools_PntOn2Faces aPntOn2Faces; |
7fd59977 | 773 | // |
788cbaf4 | 774 | const Standard_Integer aNbPnts = myIntersector.NbPnts(); |
775 | for (Standard_Integer i=1; i <= aNbPnts; ++i) | |
776 | { | |
7fd59977 | 777 | const IntSurf_PntOn2S& aISPnt=myIntersector.Point(i).PntOn2S(); |
778 | const gp_Pnt& aPnt=aISPnt.Value(); | |
779 | aISPnt.Parameters(U1,V1,U2,V2); | |
e9e644ed | 780 | // |
781 | // check the validity of the intersection point for the faces | |
782 | bValid2D1 = myContext->IsPointInOnFace(myFace1, gp_Pnt2d(U1, V1)); | |
783 | if (!bValid2D1) { | |
784 | continue; | |
785 | } | |
786 | // | |
787 | bValid2D2 = myContext->IsPointInOnFace(myFace2, gp_Pnt2d(U2, V2)); | |
788 | if (!bValid2D2) { | |
789 | continue; | |
790 | } | |
791 | // | |
792 | // add the intersection point | |
0fc4f2e2 P |
793 | aPntOnF1.Init(myFace1, aPnt, U1, V1); |
794 | aPntOnF2.Init(myFace2, aPnt, U2, V2); | |
d10203e8 | 795 | // |
788cbaf4 | 796 | if (!bReverse) |
797 | { | |
655fddc8 | 798 | aPntOn2Faces.SetP1(aPntOnF1); |
799 | aPntOn2Faces.SetP2(aPntOnF2); | |
0fc4f2e2 | 800 | } |
788cbaf4 | 801 | else |
802 | { | |
655fddc8 | 803 | aPntOn2Faces.SetP2(aPntOnF1); |
804 | aPntOn2Faces.SetP1(aPntOnF2); | |
0fc4f2e2 | 805 | } |
788cbaf4 | 806 | |
7fd59977 | 807 | myPnts.Append(aPntOn2Faces); |
808 | } | |
7fd59977 | 809 | } |
810 | } | |
788cbaf4 | 811 | |
1b7ae951 | 812 | //======================================================================= |
813 | //function : ComputeTolerance | |
814 | //purpose : | |
815 | //======================================================================= | |
816 | Standard_Real IntTools_FaceFace::ComputeTolerance() | |
817 | { | |
818 | Standard_Integer i, j, aNbLin; | |
bcf50875 | 819 | Standard_Real aFirst, aLast, aD, aDMax, aT; |
1b7ae951 | 820 | Handle(Geom_Surface) aS1, aS2; |
821 | // | |
822 | aDMax = 0; | |
1b7ae951 | 823 | aNbLin = mySeqOfCurve.Length(); |
824 | // | |
825 | aS1 = myHS1->ChangeSurface().Surface(); | |
826 | aS2 = myHS2->ChangeSurface().Surface(); | |
827 | // | |
828 | for (i = 1; i <= aNbLin; ++i) { | |
829 | const IntTools_Curve& aIC = mySeqOfCurve(i); | |
830 | const Handle(Geom_Curve)& aC3D = aIC.Curve(); | |
831 | if (aC3D.IsNull()) { | |
832 | continue; | |
833 | } | |
834 | // | |
835 | aFirst = aC3D->FirstParameter(); | |
836 | aLast = aC3D->LastParameter(); | |
837 | // | |
838 | const Handle(Geom2d_Curve)& aC2D1 = aIC.FirstCurve2d(); | |
839 | const Handle(Geom2d_Curve)& aC2D2 = aIC.SecondCurve2d(); | |
840 | // | |
841 | for (j = 0; j < 2; ++j) { | |
842 | const Handle(Geom2d_Curve)& aC2D = !j ? aC2D1 : aC2D2; | |
843 | const Handle(Geom_Surface)& aS = !j ? aS1 : aS2; | |
844 | // | |
845 | if (!aC2D.IsNull()) { | |
846 | if (IntTools_Tools::ComputeTolerance | |
847 | (aC3D, aC2D, aS, aFirst, aLast, aD, aT)) { | |
848 | if (aD > aDMax) { | |
849 | aDMax = aD; | |
850 | } | |
851 | } | |
852 | } | |
853 | // | |
854 | const TopoDS_Face& aF = !i ? myFace1 : myFace2; | |
855 | aD = FindMaxDistance(aC3D, aFirst, aLast, aF, myContext); | |
856 | if (aD > aDMax) { | |
857 | aDMax = aD; | |
858 | } | |
859 | } | |
860 | } | |
861 | // | |
862 | return aDMax; | |
863 | } | |
864 | ||
7fd59977 | 865 | //======================================================================= |
866 | //function :ComputeTolReached3d | |
867 | //purpose : | |
868 | //======================================================================= | |
869 | void IntTools_FaceFace::ComputeTolReached3d() | |
870 | { | |
128dba6f | 871 | Standard_Integer aNbLin, i; |
7fd59977 | 872 | GeomAbs_SurfaceType aType1, aType2; |
873 | // | |
874 | aNbLin=myIntersector.NbLines(); | |
37b6f439 | 875 | if (!aNbLin) { |
876 | return; | |
877 | } | |
878 | // | |
7fd59977 | 879 | aType1=myHS1->Surface().GetType(); |
880 | aType2=myHS2->Surface().GetType(); | |
881 | // | |
4f189102 P |
882 | if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) { |
883 | if (aNbLin==2){ | |
884 | Handle(IntPatch_Line) aIL1, aIL2; | |
885 | IntPatch_IType aTL1, aTL2; | |
7fd59977 | 886 | // |
4f189102 P |
887 | aIL1=myIntersector.Line(1); |
888 | aIL2=myIntersector.Line(2); | |
889 | aTL1=aIL1->ArcType(); | |
890 | aTL2=aIL2->ArcType(); | |
891 | if (aTL1==IntPatch_Lin && aTL2==IntPatch_Lin) { | |
655fddc8 | 892 | Standard_Real aD, aDTresh, dTol; |
893 | gp_Lin aL1, aL2; | |
894 | // | |
895 | dTol=1.e-8; | |
896 | aDTresh=1.5e-6; | |
897 | // | |
898 | aL1=Handle(IntPatch_GLine)::DownCast(aIL1)->Line(); | |
899 | aL2=Handle(IntPatch_GLine)::DownCast(aIL2)->Line(); | |
900 | aD=aL1.Distance(aL2); | |
901 | aD=0.5*aD; | |
902 | if (aD<aDTresh) { | |
903 | myTolReached3d=aD+dTol; | |
904 | } | |
905 | return; | |
7fd59977 | 906 | } |
907 | } | |
4f189102 | 908 | //ZZ |
37b6f439 | 909 | if (aNbLin) {// Check the distances |
1b7ae951 | 910 | Standard_Real aDMax; |
4f189102 | 911 | // |
1b7ae951 | 912 | aDMax = ComputeTolerance(); |
913 | if (aDMax > 0.) { | |
914 | myTolReached3d = aDMax; | |
915 | } | |
37b6f439 | 916 | }// if (aNbLin) |
4f189102 P |
917 | }// if (aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder) { |
918 | // | |
0fc4f2e2 | 919 | //904/G3 f |
4f189102 | 920 | else if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) { |
7fd59977 | 921 | Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh; |
922 | // | |
923 | aTolTresh=1.e-7; | |
924 | // | |
925 | aTolF1 = BRep_Tool::Tolerance(myFace1); | |
926 | aTolF2 = BRep_Tool::Tolerance(myFace2); | |
927 | aTolFMax=Max(aTolF1, aTolF2); | |
928 | // | |
929 | if (aTolFMax>aTolTresh) { | |
930 | myTolReached3d=aTolFMax; | |
931 | } | |
4f189102 | 932 | }//if (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane) { |
0fc4f2e2 | 933 | //t |
7fd59977 | 934 | //IFV Bug OCC20297 |
4f189102 | 935 | else if((aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) || |
655fddc8 | 936 | (aType2 == GeomAbs_Cylinder && aType1 == GeomAbs_Plane)) { |
7fd59977 | 937 | if(aNbLin == 1) { |
938 | const Handle(IntPatch_Line)& aIL1 = myIntersector.Line(1); | |
939 | if(aIL1->ArcType() == IntPatch_Circle) { | |
655fddc8 | 940 | gp_Circ aCir = Handle(IntPatch_GLine)::DownCast(aIL1)->Circle(); |
941 | gp_XYZ aCirDir = aCir.Axis().Direction().XYZ(); | |
942 | gp_XYZ aPlDir; | |
943 | gp_Pln aPln; | |
944 | if(aType1 == GeomAbs_Plane) { | |
945 | aPln = myHS1->Surface().Plane(); | |
946 | } | |
947 | else { | |
948 | aPln = myHS2->Surface().Plane(); | |
949 | } | |
950 | aPlDir = aPln.Axis().Direction().XYZ(); | |
951 | Standard_Real cs = aCirDir*aPlDir; | |
952 | if(cs < 0.) aPlDir.Reverse(); | |
953 | Standard_Real eps = 1.e-14; | |
954 | if(!aPlDir.IsEqual(aCirDir, eps)) { | |
955 | Standard_Integer aNbP = 11; | |
956 | Standard_Real dt = 2.*M_PI / (aNbP - 1), t; | |
957 | for(t = 0.; t < 2.*M_PI; t += dt) { | |
958 | Standard_Real d = aPln.Distance(ElCLib::Value(t, aCir)); | |
959 | if(myTolReached3d < d) myTolReached3d = d; | |
960 | } | |
961 | myTolReached3d *= 1.1; | |
962 | } | |
7fd59977 | 963 | } //aIL1->ArcType() == IntPatch_Circle |
964 | } //aNbLin == 1 | |
4f189102 | 965 | } // aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) |
7fd59977 | 966 | //End IFV Bug OCC20297 |
0fc4f2e2 | 967 | // |
4f189102 | 968 | else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) || |
655fddc8 | 969 | (aType2==GeomAbs_Plane && aType1==GeomAbs_Torus)) { |
0fc4f2e2 P |
970 | aNbLin=mySeqOfCurve.Length(); |
971 | if (aNbLin!=1) { | |
972 | return; | |
973 | } | |
974 | // | |
128dba6f | 975 | Standard_Integer aNbP; |
0fc4f2e2 P |
976 | Standard_Real aT, aT1, aT2, dT, aUT, aVT, aUP, aVP; |
977 | Standard_Real aDP, aDT, aDmax; | |
978 | gp_Pln aPln; | |
979 | gp_Torus aTorus; | |
980 | gp_Pnt aP, aPP, aPT; | |
981 | // | |
982 | const IntTools_Curve& aIC=mySeqOfCurve(1); | |
983 | const Handle(Geom_Curve)& aC3D=aIC.Curve(); | |
4f189102 P |
984 | const Handle(Geom_BSplineCurve)& aBS= |
985 | Handle(Geom_BSplineCurve)::DownCast(aC3D); | |
0fc4f2e2 P |
986 | if (aBS.IsNull()) { |
987 | return; | |
988 | } | |
989 | // | |
990 | aT1=aBS->FirstParameter(); | |
991 | aT2=aBS->LastParameter(); | |
992 | // | |
993 | aPln =(aType1==GeomAbs_Plane) ? myHS1->Plane() : myHS2->Plane(); | |
994 | aTorus=(aType1==GeomAbs_Plane) ? myHS2->Torus() : myHS1->Torus(); | |
995 | // | |
996 | aDmax=-1.; | |
997 | aNbP=11; | |
998 | dT=(aT2-aT1)/(aNbP-1); | |
999 | for (i=0; i<aNbP; ++i) { | |
1000 | aT=aT1+i*dT; | |
1001 | if (i==aNbP-1) { | |
655fddc8 | 1002 | aT=aT2; |
0fc4f2e2 P |
1003 | } |
1004 | // | |
1005 | aC3D->D0(aT, aP); | |
1006 | // | |
1007 | ElSLib::Parameters(aPln, aP, aUP, aVP); | |
1008 | aPP=ElSLib::Value(aUP, aVP, aPln); | |
1009 | aDP=aP.SquareDistance(aPP); | |
1010 | if (aDP>aDmax) { | |
655fddc8 | 1011 | aDmax=aDP; |
0fc4f2e2 P |
1012 | } |
1013 | // | |
1014 | ElSLib::Parameters(aTorus, aP, aUT, aVT); | |
1015 | aPT=ElSLib::Value(aUT, aVT, aTorus); | |
1016 | aDT=aP.SquareDistance(aPT); | |
1017 | if (aDT>aDmax) { | |
655fddc8 | 1018 | aDmax=aDT; |
0fc4f2e2 P |
1019 | } |
1020 | } | |
1021 | // | |
1022 | if (aDmax > myTolReached3d*myTolReached3d) { | |
1023 | myTolReached3d=sqrt(aDmax); | |
1024 | myTolReached3d=1.1*myTolReached3d; | |
1025 | } | |
1026 | }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) || | |
a9f7b6b5 | 1027 | // |
4f189102 | 1028 | else if ((aType1==GeomAbs_SurfaceOfRevolution && aType2==GeomAbs_Cylinder) || |
1b7ae951 | 1029 | (aType2==GeomAbs_SurfaceOfRevolution && aType1==GeomAbs_Cylinder) || |
1030 | (aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) || | |
1031 | (aType2==GeomAbs_Plane && aType1==GeomAbs_Sphere) || | |
1032 | (aType1==GeomAbs_Plane && aType2==GeomAbs_SurfaceOfExtrusion) || | |
1033 | (aType2==GeomAbs_Plane && aType1==GeomAbs_SurfaceOfExtrusion) || | |
1034 | (aType1==GeomAbs_Plane && aType2==GeomAbs_BSplineSurface) || | |
1035 | (aType2==GeomAbs_Plane && aType1==GeomAbs_BSplineSurface) || | |
1036 | !myApprox) { | |
0c5acd27 | 1037 | // |
1b7ae951 | 1038 | Standard_Real aDMax; |
0c5acd27 | 1039 | // |
1b7ae951 | 1040 | aDMax = ComputeTolerance(); |
1041 | if (aDMax > myTolReached3d) { | |
1042 | myTolReached3d = aDMax; | |
0c5acd27 | 1043 | } |
4e57c75e | 1044 | } |
7fd59977 | 1045 | } |
1b7ae951 | 1046 | |
7fd59977 | 1047 | //======================================================================= |
1048 | //function : MakeCurve | |
1049 | //purpose : | |
1050 | //======================================================================= | |
1051 | void IntTools_FaceFace::MakeCurve(const Standard_Integer Index, | |
655fddc8 | 1052 | const Handle(Adaptor3d_TopolTool)& dom1, |
1053 | const Handle(Adaptor3d_TopolTool)& dom2) | |
7fd59977 | 1054 | { |
4abae870 | 1055 | Standard_Boolean bDone, rejectSurface, reApprox, bAvoidLineConstructor; |
1056 | Standard_Boolean ok, bPCurvesOk; | |
7fd59977 | 1057 | Standard_Integer i, j, aNbParts; |
1058 | Standard_Real fprm, lprm; | |
1059 | Standard_Real Tolpc; | |
1060 | Handle(IntPatch_Line) L; | |
1061 | IntPatch_IType typl; | |
1062 | Handle(Geom_Curve) newc; | |
1063 | // | |
1064 | const Standard_Real TOLCHECK =0.0000001; | |
1065 | const Standard_Real TOLANGCHECK=0.1; | |
1066 | // | |
1067 | rejectSurface = Standard_False; | |
1068 | reApprox = Standard_False; | |
989341c5 | 1069 | // |
1070 | bPCurvesOk = Standard_True; | |
59495dbe | 1071 | |
1072 | reapprox:; | |
1073 | ||
7fd59977 | 1074 | Tolpc = myTolApprox; |
1075 | bAvoidLineConstructor = Standard_False; | |
1076 | L = myIntersector.Line(Index); | |
1077 | typl = L->ArcType(); | |
1078 | // | |
1079 | if(typl==IntPatch_Walking) { | |
1080 | Handle(IntPatch_Line) anewL; | |
1081 | // | |
1082 | const Handle(IntPatch_WLine)& aWLine= | |
1083 | Handle(IntPatch_WLine)::DownCast(L); | |
4abae870 | 1084 | //DumpWLine(aWLine); |
1085 | ||
7fd59977 | 1086 | anewL = ComputePurgedWLine(aWLine); |
1087 | if(anewL.IsNull()) { | |
1088 | return; | |
1089 | } | |
1090 | L = anewL; | |
4abae870 | 1091 | |
1092 | //const Handle(IntPatch_WLine)& aWLineX = Handle(IntPatch_WLine)::DownCast(L); | |
1093 | //DumpWLine(aWLineX); | |
1094 | ||
7fd59977 | 1095 | // |
1096 | if(!myListOfPnts.IsEmpty()) { | |
1097 | bAvoidLineConstructor = Standard_True; | |
1098 | } | |
1099 | ||
1100 | Standard_Integer nbp = aWLine->NbPnts(); | |
1101 | const IntSurf_PntOn2S& p1 = aWLine->Point(1); | |
1102 | const IntSurf_PntOn2S& p2 = aWLine->Point(nbp); | |
1103 | ||
1104 | const gp_Pnt& P1 = p1.Value(); | |
1105 | const gp_Pnt& P2 = p2.Value(); | |
1106 | ||
1107 | if(P1.SquareDistance(P2) < 1.e-14) { | |
1108 | bAvoidLineConstructor = Standard_False; | |
1109 | } | |
7fd59977 | 1110 | } |
d4b867e6 | 1111 | |
1112 | typl=L->ArcType(); | |
1113 | ||
7fd59977 | 1114 | // |
1115 | // Line Constructor | |
1116 | if(!bAvoidLineConstructor) { | |
1117 | myLConstruct.Perform(L); | |
1118 | // | |
1119 | bDone=myLConstruct.IsDone(); | |
d4b867e6 | 1120 | if(!bDone) |
1121 | { | |
7fd59977 | 1122 | return; |
1123 | } | |
d4b867e6 | 1124 | |
1125 | if(typl != IntPatch_Restriction) | |
1126 | { | |
1127 | aNbParts=myLConstruct.NbParts(); | |
1128 | if (aNbParts <= 0) | |
1129 | { | |
1130 | return; | |
1131 | } | |
1132 | } | |
7fd59977 | 1133 | } |
1134 | // Do the Curve | |
d4b867e6 | 1135 | |
1136 | ||
7fd59977 | 1137 | switch (typl) { |
59495dbe | 1138 | //######################################## |
1139 | // Line, Parabola, Hyperbola | |
1140 | //######################################## | |
7fd59977 | 1141 | case IntPatch_Lin: |
1142 | case IntPatch_Parabola: | |
1143 | case IntPatch_Hyperbola: { | |
1144 | if (typl == IntPatch_Lin) { | |
1145 | newc = | |
655fddc8 | 1146 | new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line()); |
7fd59977 | 1147 | } |
1148 | ||
1149 | else if (typl == IntPatch_Parabola) { | |
1150 | newc = | |
655fddc8 | 1151 | new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola()); |
7fd59977 | 1152 | } |
59495dbe | 1153 | |
7fd59977 | 1154 | else if (typl == IntPatch_Hyperbola) { |
1155 | newc = | |
655fddc8 | 1156 | new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola()); |
7fd59977 | 1157 | } |
1158 | // | |
1159 | // myTolReached3d | |
1160 | if (typl == IntPatch_Lin) { | |
1161 | TolR3d (myFace1, myFace2, myTolReached3d); | |
1162 | } | |
1163 | // | |
1164 | aNbParts=myLConstruct.NbParts(); | |
1165 | for (i=1; i<=aNbParts; i++) { | |
0da45792 | 1166 | Standard_Boolean bFNIt, bLPIt; |
1167 | // | |
7fd59977 | 1168 | myLConstruct.Part(i, fprm, lprm); |
d4b867e6 | 1169 | // |
0da45792 | 1170 | bFNIt=Precision::IsNegativeInfinite(fprm); |
1171 | bLPIt=Precision::IsPositiveInfinite(lprm); | |
1172 | // | |
1173 | if (!bFNIt && !bLPIt) { | |
655fddc8 | 1174 | // |
1175 | IntTools_Curve aCurve; | |
1176 | // | |
1177 | Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm); | |
1178 | aCurve.SetCurve(aCT3D); | |
1179 | if (typl == IntPatch_Parabola) { | |
1180 | Standard_Real aTolF1, aTolF2, aTolBase; | |
1181 | ||
1182 | aTolF1 = BRep_Tool::Tolerance(myFace1); | |
1183 | aTolF2 = BRep_Tool::Tolerance(myFace2); | |
1184 | aTolBase=aTolF1+aTolF2; | |
1185 | myTolReached3d=IntTools_Tools::CurveTolerance(aCT3D, aTolBase); | |
1186 | } | |
1187 | // | |
1188 | aCurve.SetCurve(new Geom_TrimmedCurve(newc, fprm, lprm)); | |
1189 | if(myApprox1) { | |
1190 | Handle (Geom2d_Curve) C2d; | |
d4b867e6 | 1191 | GeomInt_IntSS::BuildPCurves(fprm, lprm, Tolpc, |
1192 | myHS1->ChangeSurface().Surface(), newc, C2d); | |
655fddc8 | 1193 | if(Tolpc>myTolReached2d || myTolReached2d==0.) { |
1194 | myTolReached2d=Tolpc; | |
1195 | } | |
1196 | // | |
1197 | aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm)); | |
1198 | } | |
1199 | else { | |
1200 | Handle(Geom2d_BSplineCurve) H1; | |
1201 | // | |
1202 | aCurve.SetFirstCurve2d(H1); | |
1203 | } | |
0da45792 | 1204 | // |
655fddc8 | 1205 | if(myApprox2) { |
1206 | Handle (Geom2d_Curve) C2d; | |
d4b867e6 | 1207 | GeomInt_IntSS::BuildPCurves(fprm, lprm, Tolpc, |
1208 | myHS2->ChangeSurface().Surface(), newc, C2d); | |
655fddc8 | 1209 | if(Tolpc>myTolReached2d || myTolReached2d==0.) { |
1210 | myTolReached2d=Tolpc; | |
1211 | } | |
1212 | // | |
1213 | aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm)); | |
1214 | } | |
1215 | else { | |
1216 | Handle(Geom2d_BSplineCurve) H1; | |
1217 | // | |
1218 | aCurve.SetSecondCurve2d(H1); | |
1219 | } | |
1220 | mySeqOfCurve.Append(aCurve); | |
0da45792 | 1221 | } //if (!bFNIt && !bLPIt) { |
7fd59977 | 1222 | else { |
655fddc8 | 1223 | // on regarde si on garde |
1224 | // | |
655fddc8 | 1225 | Standard_Real aTestPrm, dT=100.; |
0da45792 | 1226 | // |
655fddc8 | 1227 | aTestPrm=0.; |
655fddc8 | 1228 | if (bFNIt && !bLPIt) { |
1229 | aTestPrm=lprm-dT; | |
1230 | } | |
1231 | else if (!bFNIt && bLPIt) { | |
1232 | aTestPrm=fprm+dT; | |
1233 | } | |
0da45792 | 1234 | else { |
1235 | // i.e, if (bFNIt && bLPIt) | |
1236 | aTestPrm=IntTools_Tools::IntermediatePoint(-dT, dT); | |
1237 | } | |
1238 | // | |
655fddc8 | 1239 | gp_Pnt ptref(newc->Value(aTestPrm)); |
1240 | // | |
94218044 | 1241 | GeomAbs_SurfaceType typS1 = myHS1->GetType(); |
1242 | GeomAbs_SurfaceType typS2 = myHS2->GetType(); | |
1243 | if( typS1 == GeomAbs_SurfaceOfExtrusion || | |
1244 | typS1 == GeomAbs_OffsetSurface || | |
1245 | typS1 == GeomAbs_SurfaceOfRevolution || | |
1246 | typS2 == GeomAbs_SurfaceOfExtrusion || | |
1247 | typS2 == GeomAbs_OffsetSurface || | |
0da45792 | 1248 | typS2 == GeomAbs_SurfaceOfRevolution) { |
94218044 | 1249 | Handle(Geom2d_BSplineCurve) H1; |
1250 | mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1)); | |
1251 | continue; | |
1252 | } | |
1253 | ||
655fddc8 | 1254 | Standard_Real u1, v1, u2, v2, Tol; |
1255 | ||
1256 | Tol = Precision::Confusion(); | |
1257 | Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2); | |
1258 | ok = (dom1->Classify(gp_Pnt2d(u1, v1), Tol) != TopAbs_OUT); | |
1259 | if(ok) { | |
1260 | ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT); | |
1261 | } | |
1262 | if (ok) { | |
1263 | Handle(Geom2d_BSplineCurve) H1; | |
1264 | mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1)); | |
1265 | } | |
7fd59977 | 1266 | } |
0da45792 | 1267 | }// for (i=1; i<=aNbParts; i++) { |
7fd59977 | 1268 | }// case IntPatch_Lin: case IntPatch_Parabola: case IntPatch_Hyperbola: |
59495dbe | 1269 | break; |
7fd59977 | 1270 | |
59495dbe | 1271 | //######################################## |
1272 | // Circle and Ellipse | |
1273 | //######################################## | |
7fd59977 | 1274 | case IntPatch_Circle: |
1275 | case IntPatch_Ellipse: { | |
1276 | ||
1277 | if (typl == IntPatch_Circle) { | |
1278 | newc = new Geom_Circle | |
655fddc8 | 1279 | (Handle(IntPatch_GLine)::DownCast(L)->Circle()); |
7fd59977 | 1280 | } |
1281 | else { //IntPatch_Ellipse | |
1282 | newc = new Geom_Ellipse | |
655fddc8 | 1283 | (Handle(IntPatch_GLine)::DownCast(L)->Ellipse()); |
7fd59977 | 1284 | } |
1285 | // | |
1286 | // myTolReached3d | |
1287 | TolR3d (myFace1, myFace2, myTolReached3d); | |
1288 | // | |
1289 | aNbParts=myLConstruct.NbParts(); | |
1290 | // | |
1291 | Standard_Real aPeriod, aNul; | |
1292 | TColStd_SequenceOfReal aSeqFprm, aSeqLprm; | |
59495dbe | 1293 | |
7fd59977 | 1294 | aNul=0.; |
c6541a0c | 1295 | aPeriod=M_PI+M_PI; |
7fd59977 | 1296 | |
1297 | for (i=1; i<=aNbParts; i++) { | |
1298 | myLConstruct.Part(i, fprm, lprm); | |
1299 | ||
1300 | if (fprm < aNul && lprm > aNul) { | |
655fddc8 | 1301 | // interval that goes through 0. is divided on two intervals; |
1302 | while (fprm<aNul || fprm>aPeriod) fprm=fprm+aPeriod; | |
1303 | while (lprm<aNul || lprm>aPeriod) lprm=lprm+aPeriod; | |
1304 | // | |
1305 | if((aPeriod - fprm) > Tolpc) { | |
1306 | aSeqFprm.Append(fprm); | |
1307 | aSeqLprm.Append(aPeriod); | |
1308 | } | |
1309 | else { | |
1310 | gp_Pnt P1 = newc->Value(fprm); | |
1311 | gp_Pnt P2 = newc->Value(aPeriod); | |
1312 | Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2); | |
1313 | aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist; | |
1314 | ||
1315 | if(P1.Distance(P2) > aTolDist) { | |
1316 | Standard_Real anewpar = fprm; | |
94218044 | 1317 | |
4abae870 | 1318 | if(ParameterOutOfBoundary(fprm, newc, myFace1, myFace2, |
1319 | lprm, Standard_False, anewpar, myContext)) { | |
655fddc8 | 1320 | fprm = anewpar; |
1321 | } | |
1322 | aSeqFprm.Append(fprm); | |
1323 | aSeqLprm.Append(aPeriod); | |
1324 | } | |
1325 | } | |
1326 | ||
1327 | // | |
1328 | if((lprm - aNul) > Tolpc) { | |
1329 | aSeqFprm.Append(aNul); | |
1330 | aSeqLprm.Append(lprm); | |
1331 | } | |
1332 | else { | |
1333 | gp_Pnt P1 = newc->Value(aNul); | |
1334 | gp_Pnt P2 = newc->Value(lprm); | |
1335 | Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2); | |
1336 | aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist; | |
1337 | ||
1338 | if(P1.Distance(P2) > aTolDist) { | |
1339 | Standard_Real anewpar = lprm; | |
94218044 | 1340 | |
4abae870 | 1341 | if(ParameterOutOfBoundary(lprm, newc, myFace1, myFace2, |
1342 | fprm, Standard_True, anewpar, myContext)) { | |
655fddc8 | 1343 | lprm = anewpar; |
1344 | } | |
1345 | aSeqFprm.Append(aNul); | |
1346 | aSeqLprm.Append(lprm); | |
1347 | } | |
1348 | } | |
7fd59977 | 1349 | } |
1350 | else { | |
655fddc8 | 1351 | // usual interval |
1352 | aSeqFprm.Append(fprm); | |
1353 | aSeqLprm.Append(lprm); | |
7fd59977 | 1354 | } |
1355 | } | |
59495dbe | 1356 | |
7fd59977 | 1357 | // |
1358 | aNbParts=aSeqFprm.Length(); | |
1359 | for (i=1; i<=aNbParts; i++) { | |
1360 | fprm=aSeqFprm(i); | |
1361 | lprm=aSeqLprm(i); | |
1362 | // | |
1363 | Standard_Real aRealEpsilon=RealEpsilon(); | |
c6541a0c | 1364 | if (Abs(fprm) > aRealEpsilon || Abs(lprm-2.*M_PI) > aRealEpsilon) { |
655fddc8 | 1365 | //============================================== |
1366 | //// | |
1367 | IntTools_Curve aCurve; | |
1368 | Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm); | |
1369 | aCurve.SetCurve(aTC3D); | |
1370 | fprm=aTC3D->FirstParameter(); | |
1371 | lprm=aTC3D->LastParameter (); | |
1372 | //// | |
1373 | if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {//// | |
1374 | if(myApprox1) { | |
1375 | Handle (Geom2d_Curve) C2d; | |
d4b867e6 | 1376 | GeomInt_IntSS::BuildPCurves(fprm, lprm, Tolpc, |
1377 | myHS1->ChangeSurface().Surface(), newc, C2d); | |
655fddc8 | 1378 | if(Tolpc>myTolReached2d || myTolReached2d==0) { |
1379 | myTolReached2d=Tolpc; | |
1380 | } | |
1381 | // | |
1382 | aCurve.SetFirstCurve2d(C2d); | |
1383 | } | |
1384 | else { //// | |
1385 | Handle(Geom2d_BSplineCurve) H1; | |
1386 | aCurve.SetFirstCurve2d(H1); | |
1387 | } | |
1388 | ||
1389 | ||
1390 | if(myApprox2) { | |
1391 | Handle (Geom2d_Curve) C2d; | |
d4b867e6 | 1392 | GeomInt_IntSS::BuildPCurves(fprm,lprm,Tolpc, |
1393 | myHS2->ChangeSurface().Surface(),newc,C2d); | |
655fddc8 | 1394 | if(Tolpc>myTolReached2d || myTolReached2d==0) { |
1395 | myTolReached2d=Tolpc; | |
1396 | } | |
1397 | // | |
1398 | aCurve.SetSecondCurve2d(C2d); | |
1399 | } | |
1400 | else { | |
1401 | Handle(Geom2d_BSplineCurve) H1; | |
1402 | aCurve.SetSecondCurve2d(H1); | |
1403 | } | |
1404 | } | |
1405 | ||
1406 | else { | |
1407 | Handle(Geom2d_BSplineCurve) H1; | |
1408 | aCurve.SetFirstCurve2d(H1); | |
1409 | aCurve.SetSecondCurve2d(H1); | |
1410 | } | |
1411 | mySeqOfCurve.Append(aCurve); | |
1412 | //============================================== | |
c6541a0c | 1413 | } //if (Abs(fprm) > RealEpsilon() || Abs(lprm-2.*M_PI) > RealEpsilon()) |
7fd59977 | 1414 | |
1415 | else { | |
655fddc8 | 1416 | // on regarde si on garde |
1417 | // | |
1418 | if (aNbParts==1) { | |
1419 | // if (Abs(fprm) < RealEpsilon() && Abs(lprm-2.*M_PI) < RealEpsilon()) { | |
1420 | if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*M_PI) <= aRealEpsilon) { | |
1421 | IntTools_Curve aCurve; | |
1422 | Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm); | |
1423 | aCurve.SetCurve(aTC3D); | |
1424 | fprm=aTC3D->FirstParameter(); | |
1425 | lprm=aTC3D->LastParameter (); | |
1426 | ||
1427 | if(myApprox1) { | |
1428 | Handle (Geom2d_Curve) C2d; | |
d4b867e6 | 1429 | GeomInt_IntSS::BuildPCurves(fprm,lprm,Tolpc, |
1430 | myHS1->ChangeSurface().Surface(),newc,C2d); | |
655fddc8 | 1431 | if(Tolpc>myTolReached2d || myTolReached2d==0) { |
1432 | myTolReached2d=Tolpc; | |
1433 | } | |
1434 | // | |
1435 | aCurve.SetFirstCurve2d(C2d); | |
1436 | } | |
1437 | else { //// | |
1438 | Handle(Geom2d_BSplineCurve) H1; | |
1439 | aCurve.SetFirstCurve2d(H1); | |
1440 | } | |
1441 | ||
1442 | if(myApprox2) { | |
1443 | Handle (Geom2d_Curve) C2d; | |
d4b867e6 | 1444 | GeomInt_IntSS::BuildPCurves(fprm,lprm,Tolpc, |
1445 | myHS2->ChangeSurface().Surface(),newc,C2d); | |
655fddc8 | 1446 | if(Tolpc>myTolReached2d || myTolReached2d==0) { |
1447 | myTolReached2d=Tolpc; | |
1448 | } | |
1449 | // | |
1450 | aCurve.SetSecondCurve2d(C2d); | |
1451 | } | |
1452 | else { | |
1453 | Handle(Geom2d_BSplineCurve) H1; | |
1454 | aCurve.SetSecondCurve2d(H1); | |
1455 | } | |
1456 | mySeqOfCurve.Append(aCurve); | |
1457 | break; | |
1458 | } | |
1459 | } | |
1460 | // | |
1461 | Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol; | |
1462 | ||
1463 | aTwoPIdiv17=2.*M_PI/17.; | |
1464 | ||
1465 | for (j=0; j<=17; j++) { | |
1466 | gp_Pnt ptref (newc->Value (j*aTwoPIdiv17)); | |
1467 | Tol = Precision::Confusion(); | |
1468 | ||
1469 | Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2); | |
1470 | ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT); | |
1471 | if(ok) { | |
1472 | ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT); | |
1473 | } | |
1474 | if (ok) { | |
1475 | IntTools_Curve aCurve; | |
1476 | aCurve.SetCurve(newc); | |
1477 | //============================================== | |
1478 | if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) { | |
1479 | ||
1480 | if(myApprox1) { | |
1481 | Handle (Geom2d_Curve) C2d; | |
d4b867e6 | 1482 | GeomInt_IntSS::BuildPCurves(fprm, lprm, Tolpc, |
1483 | myHS1->ChangeSurface().Surface(), newc, C2d); | |
655fddc8 | 1484 | if(Tolpc>myTolReached2d || myTolReached2d==0) { |
1485 | myTolReached2d=Tolpc; | |
1486 | } | |
1487 | // | |
1488 | aCurve.SetFirstCurve2d(C2d); | |
1489 | } | |
1490 | else { | |
1491 | Handle(Geom2d_BSplineCurve) H1; | |
1492 | aCurve.SetFirstCurve2d(H1); | |
1493 | } | |
1494 | ||
1495 | if(myApprox2) { | |
1496 | Handle (Geom2d_Curve) C2d; | |
d4b867e6 | 1497 | GeomInt_IntSS::BuildPCurves(fprm, lprm, Tolpc, |
1498 | myHS2->ChangeSurface().Surface(), newc, C2d); | |
655fddc8 | 1499 | if(Tolpc>myTolReached2d || myTolReached2d==0) { |
1500 | myTolReached2d=Tolpc; | |
1501 | } | |
1502 | // | |
1503 | aCurve.SetSecondCurve2d(C2d); | |
1504 | } | |
1505 | ||
1506 | else { | |
1507 | Handle(Geom2d_BSplineCurve) H1; | |
1508 | aCurve.SetSecondCurve2d(H1); | |
1509 | } | |
1510 | }// end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) | |
1511 | ||
1512 | else { | |
1513 | Handle(Geom2d_BSplineCurve) H1; | |
1514 | // | |
1515 | aCurve.SetFirstCurve2d(H1); | |
1516 | aCurve.SetSecondCurve2d(H1); | |
1517 | } | |
1518 | //============================================== | |
1519 | // | |
1520 | mySeqOfCurve.Append(aCurve); | |
1521 | break; | |
1522 | ||
1523 | }// end of if (ok) { | |
1524 | }// end of for (Standard_Integer j=0; j<=17; j++) | |
1525 | }// end of else { on regarde si on garde | |
59495dbe | 1526 | }// for (i=1; i<=myLConstruct.NbParts(); i++) |
1527 | }// IntPatch_Circle: IntPatch_Ellipse: | |
1528 | break; | |
1529 | ||
7fd59977 | 1530 | case IntPatch_Analytic: { |
1531 | IntSurf_Quadric quad1,quad2; | |
1532 | GeomAbs_SurfaceType typs = myHS1->Surface().GetType(); | |
59495dbe | 1533 | |
7fd59977 | 1534 | switch (typs) { |
59495dbe | 1535 | case GeomAbs_Plane: |
1536 | quad1.SetValue(myHS1->Surface().Plane()); | |
655fddc8 | 1537 | break; |
59495dbe | 1538 | case GeomAbs_Cylinder: |
655fddc8 | 1539 | quad1.SetValue(myHS1->Surface().Cylinder()); |
1540 | break; | |
59495dbe | 1541 | case GeomAbs_Cone: |
655fddc8 | 1542 | quad1.SetValue(myHS1->Surface().Cone()); |
1543 | break; | |
59495dbe | 1544 | case GeomAbs_Sphere: |
655fddc8 | 1545 | quad1.SetValue(myHS1->Surface().Sphere()); |
1546 | break; | |
7eed5d29 | 1547 | case GeomAbs_Torus: |
1548 | quad1.SetValue(myHS1->Surface().Torus()); | |
1549 | break; | |
59495dbe | 1550 | default: |
655fddc8 | 1551 | Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 1"); |
59495dbe | 1552 | } |
1553 | ||
7fd59977 | 1554 | typs = myHS2->Surface().GetType(); |
59495dbe | 1555 | |
7fd59977 | 1556 | switch (typs) { |
59495dbe | 1557 | case GeomAbs_Plane: |
1558 | quad2.SetValue(myHS2->Surface().Plane()); | |
655fddc8 | 1559 | break; |
59495dbe | 1560 | case GeomAbs_Cylinder: |
655fddc8 | 1561 | quad2.SetValue(myHS2->Surface().Cylinder()); |
1562 | break; | |
59495dbe | 1563 | case GeomAbs_Cone: |
655fddc8 | 1564 | quad2.SetValue(myHS2->Surface().Cone()); |
1565 | break; | |
59495dbe | 1566 | case GeomAbs_Sphere: |
655fddc8 | 1567 | quad2.SetValue(myHS2->Surface().Sphere()); |
1568 | break; | |
7eed5d29 | 1569 | case GeomAbs_Torus: |
1570 | quad2.SetValue(myHS2->Surface().Torus()); | |
1571 | break; | |
59495dbe | 1572 | default: |
655fddc8 | 1573 | Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 2"); |
59495dbe | 1574 | } |
7fd59977 | 1575 | // |
1576 | //========= | |
1577 | IntPatch_ALineToWLine convert (quad1, quad2); | |
59495dbe | 1578 | |
7fd59977 | 1579 | if (!myApprox) { |
1580 | aNbParts=myLConstruct.NbParts(); | |
1581 | for (i=1; i<=aNbParts; i++) { | |
655fddc8 | 1582 | myLConstruct.Part(i, fprm, lprm); |
1583 | Handle(IntPatch_WLine) WL = | |
1584 | convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm); | |
1585 | // | |
1586 | Handle(Geom2d_BSplineCurve) H1; | |
1587 | Handle(Geom2d_BSplineCurve) H2; | |
1588 | ||
1589 | if(myApprox1) { | |
1590 | H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True); | |
1591 | } | |
1592 | ||
1593 | if(myApprox2) { | |
1594 | H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False); | |
1595 | } | |
1596 | // | |
1597 | mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2)); | |
7fd59977 | 1598 | } |
1599 | } // if (!myApprox) | |
1600 | ||
1601 | else { // myApprox=TRUE | |
1602 | GeomInt_WLApprox theapp3d; | |
1603 | // | |
1604 | Standard_Real tol2d = myTolApprox; | |
655fddc8 | 1605 | // |
7fd59977 | 1606 | theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True); |
59495dbe | 1607 | |
7fd59977 | 1608 | aNbParts=myLConstruct.NbParts(); |
1609 | for (i=1; i<=aNbParts; i++) { | |
655fddc8 | 1610 | myLConstruct.Part(i, fprm, lprm); |
1611 | Handle(IntPatch_WLine) WL = | |
1612 | convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm); | |
1613 | ||
1614 | theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts()); | |
1615 | ||
1616 | if (!theapp3d.IsDone()) { | |
1617 | // | |
1618 | Handle(Geom2d_BSplineCurve) H1; | |
1619 | Handle(Geom2d_BSplineCurve) H2; | |
1620 | ||
1621 | if(myApprox1) { | |
1622 | H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True); | |
1623 | } | |
1624 | ||
1625 | if(myApprox2) { | |
1626 | H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False); | |
1627 | } | |
1628 | // | |
1629 | mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2)); | |
1630 | } | |
1631 | ||
1632 | else { | |
1633 | if(myApprox1 || myApprox2) { | |
1634 | if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) { | |
1635 | myTolReached2d = theapp3d.TolReached2d(); | |
1636 | } | |
1637 | } | |
1638 | ||
1639 | if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) { | |
1640 | myTolReached3d = theapp3d.TolReached3d(); | |
1641 | } | |
1642 | ||
1643 | Standard_Integer aNbMultiCurves, nbpoles; | |
1644 | aNbMultiCurves=theapp3d.NbMultiCurves(); | |
1645 | for (j=1; j<=aNbMultiCurves; j++) { | |
1646 | const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j); | |
1647 | nbpoles = mbspc.NbPoles(); | |
1648 | ||
1649 | TColgp_Array1OfPnt tpoles(1, nbpoles); | |
1650 | mbspc.Curve(1, tpoles); | |
1651 | Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles, | |
1652 | mbspc.Knots(), | |
1653 | mbspc.Multiplicities(), | |
1654 | mbspc.Degree()); | |
1655 | ||
1656 | GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK); | |
1657 | Check.FixTangent(Standard_True,Standard_True); | |
1658 | // | |
1659 | IntTools_Curve aCurve; | |
1660 | aCurve.SetCurve(BS); | |
1661 | ||
1662 | if(myApprox1) { | |
1663 | TColgp_Array1OfPnt2d tpoles2d(1,nbpoles); | |
1664 | mbspc.Curve(2,tpoles2d); | |
1665 | Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d, | |
1666 | mbspc.Knots(), | |
1667 | mbspc.Multiplicities(), | |
1668 | mbspc.Degree()); | |
1669 | ||
1670 | GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK); | |
1671 | newCheck.FixTangent(Standard_True,Standard_True); | |
1672 | // | |
1673 | aCurve.SetFirstCurve2d(BS2); | |
1674 | } | |
1675 | else { | |
1676 | Handle(Geom2d_BSplineCurve) H1; | |
1677 | aCurve.SetFirstCurve2d(H1); | |
1678 | } | |
1679 | ||
1680 | if(myApprox2) { | |
1681 | TColgp_Array1OfPnt2d tpoles2d(1, nbpoles); | |
1682 | Standard_Integer TwoOrThree; | |
1683 | TwoOrThree=myApprox1 ? 3 : 2; | |
1684 | mbspc.Curve(TwoOrThree, tpoles2d); | |
1685 | Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d, | |
1686 | mbspc.Knots(), | |
1687 | mbspc.Multiplicities(), | |
1688 | mbspc.Degree()); | |
1689 | ||
1690 | GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK); | |
1691 | newCheck.FixTangent(Standard_True,Standard_True); | |
1692 | // | |
1693 | aCurve.SetSecondCurve2d(BS2); | |
1694 | } | |
1695 | else { | |
1696 | Handle(Geom2d_BSplineCurve) H2; | |
1697 | aCurve.SetSecondCurve2d(H2); | |
1698 | } | |
1699 | // | |
1700 | mySeqOfCurve.Append(aCurve); | |
1701 | ||
1702 | }// for (j=1; j<=aNbMultiCurves; j++) { | |
1703 | }// else from if (!theapp3d.IsDone()) | |
7fd59977 | 1704 | }// for (i=1; i<=aNbParts; i++) { |
1705 | }// else { // myApprox=TRUE | |
1706 | }// case IntPatch_Analytic: | |
59495dbe | 1707 | break; |
7fd59977 | 1708 | |
59495dbe | 1709 | case IntPatch_Walking:{ |
7fd59977 | 1710 | Handle(IntPatch_WLine) WL = |
1711 | Handle(IntPatch_WLine)::DownCast(L); | |
1712 | // | |
1713 | Standard_Integer ifprm, ilprm; | |
1714 | // | |
1715 | if (!myApprox) { | |
1716 | aNbParts = 1; | |
1717 | if(!bAvoidLineConstructor){ | |
655fddc8 | 1718 | aNbParts=myLConstruct.NbParts(); |
7fd59977 | 1719 | } |
1720 | for (i=1; i<=aNbParts; ++i) { | |
655fddc8 | 1721 | Handle(Geom2d_BSplineCurve) H1, H2; |
1722 | Handle(Geom_Curve) aBSp; | |
1723 | // | |
1724 | if(bAvoidLineConstructor) { | |
1725 | ifprm = 1; | |
1726 | ilprm = WL->NbPnts(); | |
1727 | } | |
1728 | else { | |
1729 | myLConstruct.Part(i, fprm, lprm); | |
1730 | ifprm=(Standard_Integer)fprm; | |
1731 | ilprm=(Standard_Integer)lprm; | |
1732 | } | |
1733 | // | |
1734 | if(myApprox1) { | |
1735 | H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True); | |
1736 | } | |
1737 | // | |
1738 | if(myApprox2) { | |
1739 | H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False); | |
1740 | } | |
1741 | // | |
1742 | aBSp=MakeBSpline(WL, ifprm, ilprm); | |
1743 | IntTools_Curve aIC(aBSp, H1, H2); | |
1744 | mySeqOfCurve.Append(aIC); | |
7fd59977 | 1745 | }// for (i=1; i<=aNbParts; ++i) { |
1746 | }// if (!myApprox) { | |
1747 | // | |
1748 | else { // X | |
1749 | Standard_Boolean bIsDecomposited; | |
1750 | Standard_Integer nbiter, aNbSeqOfL; | |
4abae870 | 1751 | Standard_Real tol2d, aTolApproxImp; |
7fd59977 | 1752 | IntPatch_SequenceOfLine aSeqOfL; |
1753 | GeomInt_WLApprox theapp3d; | |
1754 | Approx_ParametrizationType aParType = Approx_ChordLength; | |
1755 | // | |
1756 | Standard_Boolean anApprox1 = myApprox1; | |
1757 | Standard_Boolean anApprox2 = myApprox2; | |
4abae870 | 1758 | // |
1759 | aTolApproxImp=1.e-5; | |
7fd59977 | 1760 | tol2d = myTolApprox; |
1761 | ||
1762 | GeomAbs_SurfaceType typs1, typs2; | |
1763 | typs1 = myHS1->Surface().GetType(); | |
1764 | typs2 = myHS2->Surface().GetType(); | |
1765 | Standard_Boolean anWithPC = Standard_True; | |
1766 | ||
1767 | if(typs1 == GeomAbs_Cylinder && typs2 == GeomAbs_Sphere) { | |
655fddc8 | 1768 | anWithPC = |
1769 | ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere()); | |
7fd59977 | 1770 | } |
1771 | else if (typs1 == GeomAbs_Sphere && typs2 == GeomAbs_Cylinder) { | |
655fddc8 | 1772 | anWithPC = |
1773 | ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere()); | |
7fd59977 | 1774 | } |
4abae870 | 1775 | // |
7fd59977 | 1776 | if(!anWithPC) { |
4abae870 | 1777 | myTolApprox = aTolApproxImp;//1.e-5; |
655fddc8 | 1778 | anApprox1 = Standard_False; |
1779 | anApprox2 = Standard_False; | |
1780 | // | |
1781 | tol2d = myTolApprox; | |
7fd59977 | 1782 | } |
655fddc8 | 1783 | |
7fd59977 | 1784 | if(myHS1 == myHS2) { |
655fddc8 | 1785 | theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType); |
1786 | rejectSurface = Standard_True; | |
7fd59977 | 1787 | } |
1788 | else { | |
655fddc8 | 1789 | if(reApprox && !rejectSurface) |
1790 | theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType); | |
1791 | else { | |
1792 | Standard_Integer iDegMax, iDegMin, iNbIter; | |
1793 | // | |
1794 | ApproxParameters(myHS1, myHS2, iDegMin, iDegMax, iNbIter); | |
1795 | theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, iNbIter, Standard_True, aParType); | |
1796 | } | |
7fd59977 | 1797 | } |
1798 | // | |
1799 | Standard_Real aReachedTol = Precision::Confusion(); | |
1800 | bIsDecomposited=DecompositionOfWLine(WL, | |
655fddc8 | 1801 | myHS1, |
1802 | myHS2, | |
1803 | myFace1, | |
1804 | myFace2, | |
1805 | myLConstruct, | |
1806 | bAvoidLineConstructor, | |
1807 | aSeqOfL, | |
1808 | aReachedTol, | |
1809 | myContext); | |
4abae870 | 1810 | if ( bIsDecomposited && ( myTolReached3d < aReachedTol ) ) { |
655fddc8 | 1811 | myTolReached3d = aReachedTol; |
4abae870 | 1812 | } |
7fd59977 | 1813 | // |
1814 | aNbSeqOfL=aSeqOfL.Length(); | |
1815 | // | |
1816 | if (bIsDecomposited) { | |
655fddc8 | 1817 | nbiter=aNbSeqOfL; |
7fd59977 | 1818 | } |
1819 | else { | |
655fddc8 | 1820 | nbiter=1; |
1821 | aNbParts=1; | |
1822 | if (!bAvoidLineConstructor) { | |
1823 | aNbParts=myLConstruct.NbParts(); | |
1824 | nbiter=aNbParts; | |
1825 | } | |
7fd59977 | 1826 | } |
1827 | // | |
7fd59977 | 1828 | for(i = 1; i <= nbiter; ++i) { |
655fddc8 | 1829 | if(bIsDecomposited) { |
1830 | WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i)); | |
1831 | ifprm = 1; | |
1832 | ilprm = WL->NbPnts(); | |
1833 | } | |
1834 | else { | |
1835 | if(bAvoidLineConstructor) { | |
1836 | ifprm = 1; | |
1837 | ilprm = WL->NbPnts(); | |
1838 | } | |
1839 | else { | |
1840 | myLConstruct.Part(i, fprm, lprm); | |
1841 | ifprm = (Standard_Integer)fprm; | |
1842 | ilprm = (Standard_Integer)lprm; | |
1843 | } | |
1844 | } | |
1845 | //-- lbr : | |
1846 | //-- Si une des surfaces est un plan , on approxime en 2d | |
1847 | //-- sur cette surface et on remonte les points 2d en 3d. | |
1848 | if(typs1 == GeomAbs_Plane) { | |
1849 | theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm); | |
1850 | } | |
1851 | else if(typs2 == GeomAbs_Plane) { | |
1852 | theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm); | |
1853 | } | |
1854 | else { | |
1855 | // | |
1856 | if (myHS1 != myHS2){ | |
1857 | if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) && | |
1858 | (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) { | |
1859 | ||
1860 | theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType); | |
1861 | ||
1862 | Standard_Boolean bUseSurfaces; | |
1863 | bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm, ilprm); | |
1864 | if (bUseSurfaces) { | |
1865 | // ###### | |
1866 | rejectSurface = Standard_True; | |
1867 | // ###### | |
1868 | theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType); | |
1869 | } | |
1870 | } | |
1871 | } | |
1872 | // | |
1873 | theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm); | |
1874 | } | |
1875 | // | |
94218044 | 1876 | if (!theapp3d.IsDone()) { |
655fddc8 | 1877 | Handle(Geom2d_BSplineCurve) H1; |
94218044 | 1878 | Handle(Geom2d_BSplineCurve) H2; |
655fddc8 | 1879 | // |
1880 | Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm); | |
4abae870 | 1881 | // |
655fddc8 | 1882 | if(myApprox1) { |
1883 | H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True); | |
1884 | } | |
4abae870 | 1885 | // |
655fddc8 | 1886 | if(myApprox2) { |
1887 | H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False); | |
1888 | } | |
1889 | // | |
1890 | IntTools_Curve aIC(aBSp, H1, H2); | |
1891 | mySeqOfCurve.Append(aIC); | |
1892 | } | |
1893 | ||
1894 | else { | |
1895 | if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) { | |
1896 | if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) { | |
1897 | myTolReached2d = theapp3d.TolReached2d(); | |
1898 | } | |
1899 | } | |
1900 | if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) { | |
1901 | myTolReached3d = myTolReached2d; | |
1902 | // | |
1903 | if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) { | |
1904 | if (myTolReached3d<1.e-6) { | |
1905 | myTolReached3d = theapp3d.TolReached3d(); | |
1906 | myTolReached3d=1.e-6; | |
1907 | } | |
1908 | } | |
1909 | } | |
1910 | else if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) { | |
1911 | myTolReached3d = theapp3d.TolReached3d(); | |
1912 | } | |
1913 | ||
1914 | Standard_Integer aNbMultiCurves, nbpoles; | |
1915 | aNbMultiCurves=theapp3d.NbMultiCurves(); | |
1916 | for (j=1; j<=aNbMultiCurves; j++) { | |
1917 | if(typs1 == GeomAbs_Plane) { | |
1918 | const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j); | |
1919 | nbpoles = mbspc.NbPoles(); | |
1920 | ||
1921 | TColgp_Array1OfPnt2d tpoles2d(1,nbpoles); | |
1922 | TColgp_Array1OfPnt tpoles(1,nbpoles); | |
1923 | ||
1924 | mbspc.Curve(1,tpoles2d); | |
1925 | const gp_Pln& Pln = myHS1->Surface().Plane(); | |
1926 | // | |
1927 | Standard_Integer ik; | |
1928 | for(ik = 1; ik<= nbpoles; ik++) { | |
1929 | tpoles.SetValue(ik, | |
1930 | ElSLib::Value(tpoles2d.Value(ik).X(), | |
1931 | tpoles2d.Value(ik).Y(), | |
1932 | Pln)); | |
1933 | } | |
1934 | // | |
1935 | Handle(Geom_BSplineCurve) BS = | |
1936 | new Geom_BSplineCurve(tpoles, | |
1937 | mbspc.Knots(), | |
1938 | mbspc.Multiplicities(), | |
1939 | mbspc.Degree()); | |
1940 | GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK); | |
1941 | Check.FixTangent(Standard_True, Standard_True); | |
1942 | // | |
1943 | IntTools_Curve aCurve; | |
1944 | aCurve.SetCurve(BS); | |
1945 | ||
1946 | if(myApprox1) { | |
1947 | Handle(Geom2d_BSplineCurve) BS1 = | |
1948 | new Geom2d_BSplineCurve(tpoles2d, | |
1949 | mbspc.Knots(), | |
1950 | mbspc.Multiplicities(), | |
1951 | mbspc.Degree()); | |
1952 | GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK); | |
1953 | Check1.FixTangent(Standard_True,Standard_True); | |
1954 | // | |
1955 | // ############################################ | |
1956 | if(!rejectSurface && !reApprox) { | |
1957 | Standard_Boolean isValid = IsCurveValid(BS1); | |
1958 | if(!isValid) { | |
1959 | reApprox = Standard_True; | |
1960 | goto reapprox; | |
1961 | } | |
1962 | } | |
1963 | // ############################################ | |
1964 | aCurve.SetFirstCurve2d(BS1); | |
1965 | } | |
1966 | else { | |
1967 | Handle(Geom2d_BSplineCurve) H1; | |
1968 | aCurve.SetFirstCurve2d(H1); | |
1969 | } | |
1970 | ||
1971 | if(myApprox2) { | |
1972 | mbspc.Curve(2, tpoles2d); | |
1973 | ||
1974 | Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d, | |
1975 | mbspc.Knots(), | |
1976 | mbspc.Multiplicities(), | |
1977 | mbspc.Degree()); | |
1978 | GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK); | |
1979 | newCheck.FixTangent(Standard_True,Standard_True); | |
1980 | ||
1981 | // ########################################### | |
1982 | if(!rejectSurface && !reApprox) { | |
1983 | Standard_Boolean isValid = IsCurveValid(BS2); | |
1984 | if(!isValid) { | |
1985 | reApprox = Standard_True; | |
1986 | goto reapprox; | |
1987 | } | |
1988 | } | |
1989 | // ########################################### | |
1990 | // | |
1991 | aCurve.SetSecondCurve2d(BS2); | |
1992 | } | |
1993 | else { | |
1994 | Handle(Geom2d_BSplineCurve) H2; | |
1995 | // | |
1996 | aCurve.SetSecondCurve2d(H2); | |
1997 | } | |
1998 | // | |
1999 | mySeqOfCurve.Append(aCurve); | |
4abae870 | 2000 | }//if(typs1 == GeomAbs_Plane) { |
655fddc8 | 2001 | |
2002 | else if(typs2 == GeomAbs_Plane) { | |
2003 | const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j); | |
2004 | nbpoles = mbspc.NbPoles(); | |
2005 | ||
2006 | TColgp_Array1OfPnt2d tpoles2d(1,nbpoles); | |
2007 | TColgp_Array1OfPnt tpoles(1,nbpoles); | |
2008 | mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d); | |
2009 | const gp_Pln& Pln = myHS2->Surface().Plane(); | |
2010 | // | |
2011 | Standard_Integer ik; | |
2012 | for(ik = 1; ik<= nbpoles; ik++) { | |
2013 | tpoles.SetValue(ik, | |
2014 | ElSLib::Value(tpoles2d.Value(ik).X(), | |
2015 | tpoles2d.Value(ik).Y(), | |
2016 | Pln)); | |
2017 | ||
2018 | } | |
2019 | // | |
2020 | Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles, | |
2021 | mbspc.Knots(), | |
2022 | mbspc.Multiplicities(), | |
2023 | mbspc.Degree()); | |
2024 | GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK); | |
2025 | Check.FixTangent(Standard_True,Standard_True); | |
2026 | // | |
2027 | IntTools_Curve aCurve; | |
2028 | aCurve.SetCurve(BS); | |
2029 | ||
2030 | if(myApprox2) { | |
2031 | Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d, | |
2032 | mbspc.Knots(), | |
2033 | mbspc.Multiplicities(), | |
2034 | mbspc.Degree()); | |
2035 | GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK); | |
2036 | Check1.FixTangent(Standard_True,Standard_True); | |
2037 | // | |
2038 | // ########################################### | |
2039 | if(!rejectSurface && !reApprox) { | |
2040 | Standard_Boolean isValid = IsCurveValid(BS1); | |
2041 | if(!isValid) { | |
2042 | reApprox = Standard_True; | |
2043 | goto reapprox; | |
2044 | } | |
2045 | } | |
989341c5 | 2046 | // ########################################### |
2047 | bPCurvesOk = CheckPCurve(BS1, myFace2); | |
655fddc8 | 2048 | aCurve.SetSecondCurve2d(BS1); |
2049 | } | |
2050 | else { | |
2051 | Handle(Geom2d_BSplineCurve) H2; | |
2052 | aCurve.SetSecondCurve2d(H2); | |
2053 | } | |
2054 | ||
2055 | if(myApprox1) { | |
2056 | mbspc.Curve(1,tpoles2d); | |
2057 | Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d, | |
2058 | mbspc.Knots(), | |
2059 | mbspc.Multiplicities(), | |
2060 | mbspc.Degree()); | |
2061 | GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK); | |
2062 | Check2.FixTangent(Standard_True,Standard_True); | |
2063 | // | |
2064 | // ########################################### | |
2065 | if(!rejectSurface && !reApprox) { | |
2066 | Standard_Boolean isValid = IsCurveValid(BS2); | |
2067 | if(!isValid) { | |
2068 | reApprox = Standard_True; | |
2069 | goto reapprox; | |
2070 | } | |
2071 | } | |
989341c5 | 2072 | // ########################################### |
2073 | bPCurvesOk = bPCurvesOk && CheckPCurve(BS2, myFace1); | |
655fddc8 | 2074 | aCurve.SetFirstCurve2d(BS2); |
2075 | } | |
2076 | else { | |
2077 | Handle(Geom2d_BSplineCurve) H1; | |
2078 | // | |
2079 | aCurve.SetFirstCurve2d(H1); | |
2080 | } | |
2081 | // | |
989341c5 | 2082 | //if points of the pcurves are out of the faces bounds |
2083 | //create 3d and 2d curves without approximation | |
2084 | if (!bPCurvesOk) { | |
2085 | Handle(Geom2d_BSplineCurve) H1, H2; | |
655fddc8 | 2086 | bPCurvesOk = Standard_True; |
2087 | // | |
989341c5 | 2088 | Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm); |
59495dbe | 2089 | |
989341c5 | 2090 | if(myApprox1) { |
2091 | H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True); | |
655fddc8 | 2092 | bPCurvesOk = CheckPCurve(H1, myFace1); |
989341c5 | 2093 | } |
59495dbe | 2094 | |
989341c5 | 2095 | if(myApprox2) { |
2096 | H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False); | |
655fddc8 | 2097 | bPCurvesOk = bPCurvesOk && CheckPCurve(H2, myFace2); |
989341c5 | 2098 | } |
2099 | // | |
655fddc8 | 2100 | //if pcurves created without approximation are out of the |
2101 | //faces bounds, use approximated 3d and 2d curves | |
2102 | if (bPCurvesOk) { | |
2103 | IntTools_Curve aIC(aBSp, H1, H2); | |
2104 | mySeqOfCurve.Append(aIC); | |
2105 | } else { | |
2106 | mySeqOfCurve.Append(aCurve); | |
2107 | } | |
989341c5 | 2108 | } else { |
2109 | mySeqOfCurve.Append(aCurve); | |
2110 | } | |
4abae870 | 2111 | }// else if(typs2 == GeomAbs_Plane) |
2112 | // | |
2113 | else { //typs2 != GeomAbs_Plane && typs1 != GeomAbs_Plane | |
2114 | Standard_Boolean bIsValid1, bIsValid2; | |
2115 | Handle(Geom_BSplineCurve) BS; | |
2116 | Handle(Geom2d_BSplineCurve) aH2D; | |
2117 | IntTools_Curve aCurve; | |
2118 | // | |
2119 | bIsValid1=Standard_True; | |
2120 | bIsValid2=Standard_True; | |
2121 | // | |
655fddc8 | 2122 | const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j); |
2123 | nbpoles = mbspc.NbPoles(); | |
2124 | TColgp_Array1OfPnt tpoles(1,nbpoles); | |
2125 | mbspc.Curve(1,tpoles); | |
4abae870 | 2126 | BS=new Geom_BSplineCurve(tpoles, |
655fddc8 | 2127 | mbspc.Knots(), |
2128 | mbspc.Multiplicities(), | |
2129 | mbspc.Degree()); | |
2130 | GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK); | |
2131 | Check.FixTangent(Standard_True,Standard_True); | |
2132 | // | |
2133 | aCurve.SetCurve(BS); | |
4abae870 | 2134 | aCurve.SetFirstCurve2d(aH2D); |
2135 | aCurve.SetSecondCurve2d(aH2D); | |
2136 | // | |
655fddc8 | 2137 | if(myApprox1) { |
2138 | if(anApprox1) { | |
4abae870 | 2139 | Handle(Geom2d_BSplineCurve) BS1; |
655fddc8 | 2140 | TColgp_Array1OfPnt2d tpoles2d(1,nbpoles); |
2141 | mbspc.Curve(2,tpoles2d); | |
4abae870 | 2142 | // |
2143 | BS1=new Geom2d_BSplineCurve(tpoles2d, | |
655fddc8 | 2144 | mbspc.Knots(), |
2145 | mbspc.Multiplicities(), | |
2146 | mbspc.Degree()); | |
2147 | GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK); | |
2148 | newCheck.FixTangent(Standard_True,Standard_True); | |
2149 | // | |
4abae870 | 2150 | if (!reApprox) { |
2151 | bIsValid1=CheckPCurve(BS1, myFace1); | |
2152 | } | |
2153 | // | |
655fddc8 | 2154 | aCurve.SetFirstCurve2d(BS1); |
2155 | } | |
2156 | else { | |
2157 | Handle(Geom2d_BSplineCurve) BS1; | |
2158 | fprm = BS->FirstParameter(); | |
2159 | lprm = BS->LastParameter(); | |
2160 | ||
2161 | Handle(Geom2d_Curve) C2d; | |
2162 | Standard_Real aTol = myTolApprox; | |
d4b867e6 | 2163 | GeomInt_IntSS::BuildPCurves(fprm, lprm, aTol, |
2164 | myHS1->ChangeSurface().Surface(), BS, C2d); | |
655fddc8 | 2165 | BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d); |
2166 | aCurve.SetFirstCurve2d(BS1); | |
2167 | } | |
4abae870 | 2168 | } // if(myApprox1) { |
655fddc8 | 2169 | // |
2170 | if(myApprox2) { | |
2171 | if(anApprox2) { | |
4abae870 | 2172 | Handle(Geom2d_BSplineCurve) BS2; |
655fddc8 | 2173 | TColgp_Array1OfPnt2d tpoles2d(1,nbpoles); |
2174 | mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d); | |
4abae870 | 2175 | BS2=new Geom2d_BSplineCurve(tpoles2d, |
655fddc8 | 2176 | mbspc.Knots(), |
2177 | mbspc.Multiplicities(), | |
2178 | mbspc.Degree()); | |
2179 | GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK); | |
2180 | newCheck.FixTangent(Standard_True,Standard_True); | |
2181 | // | |
4abae870 | 2182 | if (!reApprox) { |
2183 | bIsValid2=CheckPCurve(BS2, myFace2); | |
2184 | } | |
655fddc8 | 2185 | aCurve.SetSecondCurve2d(BS2); |
2186 | } | |
2187 | else { | |
2188 | Handle(Geom2d_BSplineCurve) BS2; | |
2189 | fprm = BS->FirstParameter(); | |
2190 | lprm = BS->LastParameter(); | |
2191 | ||
2192 | Handle(Geom2d_Curve) C2d; | |
2193 | Standard_Real aTol = myTolApprox; | |
d4b867e6 | 2194 | GeomInt_IntSS::BuildPCurves(fprm, lprm, aTol, |
2195 | myHS2->ChangeSurface().Surface(), BS, C2d); | |
655fddc8 | 2196 | BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d); |
2197 | aCurve.SetSecondCurve2d(BS2); | |
2198 | } | |
4abae870 | 2199 | } //if(myApprox2) { |
2200 | if (!bIsValid1 || !bIsValid2) { | |
2201 | myTolApprox=aTolApproxImp;//1.e-5; | |
2202 | tol2d = myTolApprox; | |
2203 | reApprox = Standard_True; | |
2204 | goto reapprox; | |
655fddc8 | 2205 | } |
2206 | // | |
2207 | mySeqOfCurve.Append(aCurve); | |
2208 | } | |
2209 | } | |
2210 | } | |
7fd59977 | 2211 | } |
2212 | }// else { // X | |
2213 | }// case IntPatch_Walking:{ | |
59495dbe | 2214 | break; |
2215 | ||
7fd59977 | 2216 | case IntPatch_Restriction: |
d4b867e6 | 2217 | { |
2218 | GeomAbs_SurfaceType typS1 = myHS1->Surface().GetType(); | |
2219 | GeomAbs_SurfaceType typS2 = myHS2->Surface().GetType(); | |
2220 | Standard_Boolean isAnalS1 = Standard_False; | |
2221 | switch (typS1) | |
2222 | { | |
2223 | case GeomAbs_Plane: | |
2224 | case GeomAbs_Cylinder: | |
2225 | case GeomAbs_Sphere: | |
2226 | case GeomAbs_Cone: | |
2227 | case GeomAbs_Torus: isAnalS1 = Standard_True; break; | |
2228 | default: break; | |
2229 | } | |
7fd59977 | 2230 | |
d4b867e6 | 2231 | Standard_Integer isAnalS2 = Standard_False; |
2232 | switch (typS2) | |
2233 | { | |
2234 | case GeomAbs_Plane: | |
2235 | case GeomAbs_Cylinder: | |
2236 | case GeomAbs_Sphere: | |
2237 | case GeomAbs_Cone: | |
2238 | case GeomAbs_Torus: isAnalS2 = Standard_True; break; | |
2239 | default: break; | |
2240 | } | |
7fd59977 | 2241 | |
d4b867e6 | 2242 | Handle(IntPatch_RLine) RL = |
2243 | Handle(IntPatch_RLine)::DownCast(L); | |
2244 | Handle(Geom_Curve) aC3d; | |
2245 | Handle(Geom2d_Curve) aC2d1, aC2d2; | |
2246 | Standard_Real aTolReached; | |
2247 | GeomInt_IntSS::TreatRLine(RL, myHS1, myHS2, aC3d, | |
2248 | aC2d1, aC2d2, aTolReached); | |
2249 | ||
2250 | if(aC3d.IsNull()) | |
2251 | break; | |
2252 | ||
2253 | Bnd_Box2d aBox1, aBox2; | |
2254 | ||
2255 | const Standard_Real aU1f = myHS1->FirstUParameter(), | |
2256 | aV1f = myHS1->FirstVParameter(), | |
2257 | aU1l = myHS1->LastUParameter(), | |
2258 | aV1l = myHS1->LastVParameter(); | |
2259 | const Standard_Real aU2f = myHS2->FirstUParameter(), | |
2260 | aV2f = myHS2->FirstVParameter(), | |
2261 | aU2l = myHS2->LastUParameter(), | |
2262 | aV2l = myHS2->LastVParameter(); | |
2263 | ||
2264 | aBox1.Add(gp_Pnt2d(aU1f, aV1f)); | |
2265 | aBox1.Add(gp_Pnt2d(aU1l, aV1l)); | |
2266 | aBox2.Add(gp_Pnt2d(aU2f, aV2f)); | |
2267 | aBox2.Add(gp_Pnt2d(aU2l, aV2l)); | |
2268 | ||
2269 | GeomInt_VectorOfReal anArrayOfParameters; | |
655fddc8 | 2270 | |
d4b867e6 | 2271 | //We consider here that the intersection line is same-parameter-line |
2272 | anArrayOfParameters.Append(aC3d->FirstParameter()); | |
2273 | anArrayOfParameters.Append(aC3d->LastParameter()); | |
2274 | ||
2275 | GeomInt_IntSS:: | |
2276 | TrimILineOnSurfBoundaries(aC2d1, aC2d2, aBox1, aBox2, anArrayOfParameters); | |
2277 | ||
2278 | const Standard_Integer aNbIntersSolutionsm1 = anArrayOfParameters.Length() - 1; | |
2279 | ||
2280 | //Trim RLine found. | |
2281 | for(Standard_Integer anInd = 0; anInd < aNbIntersSolutionsm1; anInd++) | |
2282 | { | |
2283 | const Standard_Real aParF = anArrayOfParameters(anInd), | |
2284 | aParL = anArrayOfParameters(anInd+1); | |
2285 | ||
2286 | if((aParL - aParF) <= Precision::PConfusion()) | |
2287 | continue; | |
2288 | ||
2289 | const Standard_Real aPar = 0.5*(aParF + aParL); | |
2290 | gp_Pnt2d aPt; | |
2291 | ||
2292 | Handle(Geom2d_Curve) aCurv2d1, aCurv2d2; | |
2293 | if(!aC2d1.IsNull()) | |
2294 | { | |
2295 | aC2d1->D0(aPar, aPt); | |
2296 | ||
2297 | if(aBox1.IsOut(aPt)) | |
2298 | continue; | |
2299 | ||
2300 | if(myApprox1) | |
2301 | aCurv2d1 = new Geom2d_TrimmedCurve(aC2d1, aParF, aParL); | |
4abae870 | 2302 | } |
d4b867e6 | 2303 | |
2304 | if(!aC2d2.IsNull()) | |
2305 | { | |
2306 | aC2d2->D0(aPar, aPt); | |
2307 | ||
2308 | if(aBox2.IsOut(aPt)) | |
2309 | continue; | |
2310 | ||
2311 | if(myApprox2) | |
2312 | aCurv2d2 = new Geom2d_TrimmedCurve(aC2d2, aParF, aParL); | |
2313 | } | |
2314 | ||
2315 | Handle(Geom_Curve) aCurv3d = new Geom_TrimmedCurve(aC3d, aParF, aParL); | |
2316 | ||
2317 | IntTools_Curve aIC(aCurv3d, aCurv2d1, aCurv2d2); | |
2318 | mySeqOfCurve.Append(aIC); | |
7fd59977 | 2319 | } |
2320 | } | |
d4b867e6 | 2321 | break; |
2322 | default: | |
2323 | break; | |
2324 | ||
7fd59977 | 2325 | } |
7fd59977 | 2326 | } |
2327 | ||
2328 | //======================================================================= | |
2329 | //function : Parameters | |
2330 | //purpose : | |
2331 | //======================================================================= | |
2332 | void Parameters(const Handle(GeomAdaptor_HSurface)& HS1, | |
655fddc8 | 2333 | const Handle(GeomAdaptor_HSurface)& HS2, |
2334 | const gp_Pnt& Ptref, | |
2335 | Standard_Real& U1, | |
2336 | Standard_Real& V1, | |
2337 | Standard_Real& U2, | |
2338 | Standard_Real& V2) | |
7fd59977 | 2339 | { |
2340 | ||
2341 | IntSurf_Quadric quad1,quad2; | |
2342 | GeomAbs_SurfaceType typs = HS1->Surface().GetType(); | |
2343 | ||
2344 | switch (typs) { | |
2345 | case GeomAbs_Plane: | |
2346 | quad1.SetValue(HS1->Surface().Plane()); | |
2347 | break; | |
2348 | case GeomAbs_Cylinder: | |
2349 | quad1.SetValue(HS1->Surface().Cylinder()); | |
2350 | break; | |
2351 | case GeomAbs_Cone: | |
2352 | quad1.SetValue(HS1->Surface().Cone()); | |
2353 | break; | |
2354 | case GeomAbs_Sphere: | |
2355 | quad1.SetValue(HS1->Surface().Sphere()); | |
2356 | break; | |
7eed5d29 | 2357 | case GeomAbs_Torus: |
2358 | quad1.SetValue(HS1->Surface().Torus()); | |
2359 | break; | |
7fd59977 | 2360 | default: |
2361 | Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve"); | |
2362 | } | |
2363 | ||
2364 | typs = HS2->Surface().GetType(); | |
2365 | switch (typs) { | |
2366 | case GeomAbs_Plane: | |
2367 | quad2.SetValue(HS2->Surface().Plane()); | |
2368 | break; | |
2369 | case GeomAbs_Cylinder: | |
2370 | quad2.SetValue(HS2->Surface().Cylinder()); | |
2371 | break; | |
2372 | case GeomAbs_Cone: | |
2373 | quad2.SetValue(HS2->Surface().Cone()); | |
2374 | break; | |
2375 | case GeomAbs_Sphere: | |
2376 | quad2.SetValue(HS2->Surface().Sphere()); | |
2377 | break; | |
7eed5d29 | 2378 | case GeomAbs_Torus: |
2379 | quad2.SetValue(HS2->Surface().Torus()); | |
2380 | break; | |
7fd59977 | 2381 | default: |
2382 | Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve"); | |
2383 | } | |
2384 | ||
2385 | quad1.Parameters(Ptref,U1,V1); | |
2386 | quad2.Parameters(Ptref,U2,V2); | |
2387 | } | |
2388 | ||
2389 | //======================================================================= | |
2390 | //function : MakeBSpline | |
2391 | //purpose : | |
2392 | //======================================================================= | |
2393 | Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)& WL, | |
655fddc8 | 2394 | const Standard_Integer ideb, |
2395 | const Standard_Integer ifin) | |
7fd59977 | 2396 | { |
2397 | Standard_Integer i,nbpnt = ifin-ideb+1; | |
2398 | TColgp_Array1OfPnt poles(1,nbpnt); | |
2399 | TColStd_Array1OfReal knots(1,nbpnt); | |
2400 | TColStd_Array1OfInteger mults(1,nbpnt); | |
2401 | Standard_Integer ipidebm1; | |
2402 | for(i=1,ipidebm1=i+ideb-1; i<=nbpnt;ipidebm1++, i++) { | |
2403 | poles(i) = WL->Point(ipidebm1).Value(); | |
2404 | mults(i) = 1; | |
2405 | knots(i) = i-1; | |
2406 | } | |
2407 | mults(1) = mults(nbpnt) = 2; | |
2408 | return | |
2409 | new Geom_BSplineCurve(poles,knots,mults,1); | |
2410 | } | |
2411 | // | |
2412 | ||
2413 | //======================================================================= | |
2414 | //function : MakeBSpline2d | |
2415 | //purpose : | |
2416 | //======================================================================= | |
2417 | Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine, | |
655fddc8 | 2418 | const Standard_Integer ideb, |
2419 | const Standard_Integer ifin, | |
2420 | const Standard_Boolean onFirst) | |
7fd59977 | 2421 | { |
2422 | Standard_Integer i, nbpnt = ifin-ideb+1; | |
2423 | TColgp_Array1OfPnt2d poles(1,nbpnt); | |
2424 | TColStd_Array1OfReal knots(1,nbpnt); | |
2425 | TColStd_Array1OfInteger mults(1,nbpnt); | |
2426 | Standard_Integer ipidebm1; | |
2427 | ||
2428 | for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) { | |
2429 | Standard_Real U, V; | |
2430 | if(onFirst) | |
655fddc8 | 2431 | theWLine->Point(ipidebm1).ParametersOnS1(U, V); |
7fd59977 | 2432 | else |
655fddc8 | 2433 | theWLine->Point(ipidebm1).ParametersOnS2(U, V); |
7fd59977 | 2434 | poles(i).SetCoord(U, V); |
2435 | mults(i) = 1; | |
2436 | knots(i) = i-1; | |
2437 | } | |
2438 | mults(1) = mults(nbpnt) = 2; | |
2439 | ||
2440 | return new Geom2d_BSplineCurve(poles,knots,mults,1); | |
2441 | } | |
2442 | //======================================================================= | |
2443 | //function : PrepareLines3D | |
2444 | //purpose : | |
2445 | //======================================================================= | |
a9f7b6b5 | 2446 | void IntTools_FaceFace::PrepareLines3D(const Standard_Boolean bToSplit) |
7fd59977 | 2447 | { |
a9f7b6b5 P |
2448 | Standard_Integer i, aNbCurves; |
2449 | GeomAbs_SurfaceType aType1, aType2; | |
7fd59977 | 2450 | IntTools_SequenceOfCurves aNewCvs; |
7fd59977 | 2451 | // |
a9f7b6b5 | 2452 | // 1. Treatment closed curves |
7fd59977 | 2453 | aNbCurves=mySeqOfCurve.Length(); |
a9f7b6b5 | 2454 | for (i=1; i<=aNbCurves; ++i) { |
7fd59977 | 2455 | const IntTools_Curve& aIC=mySeqOfCurve(i); |
7fd59977 | 2456 | // |
a9f7b6b5 P |
2457 | if (bToSplit) { |
2458 | Standard_Integer j, aNbC; | |
2459 | IntTools_SequenceOfCurves aSeqCvs; | |
2460 | // | |
2461 | aNbC=IntTools_Tools::SplitCurve(aIC, aSeqCvs); | |
2462 | if (aNbC) { | |
655fddc8 | 2463 | for (j=1; j<=aNbC; ++j) { |
2464 | const IntTools_Curve& aICNew=aSeqCvs(j); | |
2465 | aNewCvs.Append(aICNew); | |
2466 | } | |
a9f7b6b5 P |
2467 | } |
2468 | else { | |
655fddc8 | 2469 | aNewCvs.Append(aIC); |
7fd59977 | 2470 | } |
2471 | } | |
7fd59977 | 2472 | else { |
2473 | aNewCvs.Append(aIC); | |
2474 | } | |
2475 | } | |
2476 | // | |
2477 | // 2. Plane\Cone intersection when we had 4 curves | |
a9f7b6b5 P |
2478 | aType1=myHS1->GetType(); |
2479 | aType2=myHS2->GetType(); | |
2480 | aNbCurves=aNewCvs.Length(); | |
2481 | // | |
7fd59977 | 2482 | if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone) || |
2483 | (aType2==GeomAbs_Plane && aType1==GeomAbs_Cone)) { | |
7fd59977 | 2484 | if (aNbCurves==4) { |
a9f7b6b5 P |
2485 | GeomAbs_CurveType aCType1; |
2486 | // | |
2487 | aCType1=aNewCvs(1).Type(); | |
7fd59977 | 2488 | if (aCType1==GeomAbs_Line) { |
655fddc8 | 2489 | IntTools_SequenceOfCurves aSeqIn, aSeqOut; |
2490 | // | |
2491 | for (i=1; i<=aNbCurves; ++i) { | |
2492 | const IntTools_Curve& aIC=aNewCvs(i); | |
2493 | aSeqIn.Append(aIC); | |
2494 | } | |
2495 | // | |
2496 | IntTools_Tools::RejectLines(aSeqIn, aSeqOut); | |
2497 | // | |
2498 | aNewCvs.Clear(); | |
2499 | aNbCurves=aSeqOut.Length(); | |
2500 | for (i=1; i<=aNbCurves; ++i) { | |
2501 | const IntTools_Curve& aIC=aSeqOut(i); | |
2502 | aNewCvs.Append(aIC); | |
2503 | } | |
7fd59977 | 2504 | } |
2505 | } | |
a9f7b6b5 | 2506 | }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone)... |
7fd59977 | 2507 | // |
2508 | // 3. Fill mySeqOfCurve | |
2509 | mySeqOfCurve.Clear(); | |
2510 | aNbCurves=aNewCvs.Length(); | |
a9f7b6b5 | 2511 | for (i=1; i<=aNbCurves; ++i) { |
7fd59977 | 2512 | const IntTools_Curve& aIC=aNewCvs(i); |
2513 | mySeqOfCurve.Append(aIC); | |
2514 | } | |
7fd59977 | 2515 | } |
7fd59977 | 2516 | //======================================================================= |
2517 | //function : CorrectSurfaceBoundaries | |
2518 | //purpose : | |
2519 | //======================================================================= | |
59495dbe | 2520 | void CorrectSurfaceBoundaries(const TopoDS_Face& theFace, |
c002793b | 2521 | const Standard_Real theTolerance, |
2522 | Standard_Real& theumin, | |
2523 | Standard_Real& theumax, | |
2524 | Standard_Real& thevmin, | |
2525 | Standard_Real& thevmax) | |
7fd59977 | 2526 | { |
2527 | Standard_Boolean enlarge, isuperiodic, isvperiodic; | |
2528 | Standard_Real uinf, usup, vinf, vsup, delta; | |
2529 | GeomAbs_SurfaceType aType; | |
2530 | Handle(Geom_Surface) aSurface; | |
2531 | // | |
2532 | aSurface = BRep_Tool::Surface(theFace); | |
2533 | aSurface->Bounds(uinf, usup, vinf, vsup); | |
2534 | delta = theTolerance; | |
2535 | enlarge = Standard_False; | |
2536 | // | |
2537 | GeomAdaptor_Surface anAdaptorSurface(aSurface); | |
2538 | // | |
2539 | if(aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) { | |
2540 | Handle(Geom_Surface) aBasisSurface = | |
2541 | (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface))->BasisSurface(); | |
2542 | ||
2543 | if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) || | |
2544 | aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) { | |
2545 | return; | |
2546 | } | |
2547 | } | |
2548 | // | |
2549 | if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) { | |
2550 | Handle(Geom_Surface) aBasisSurface = | |
2551 | (Handle(Geom_OffsetSurface)::DownCast(aSurface))->BasisSurface(); | |
2552 | ||
2553 | if(aBasisSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)) || | |
2554 | aBasisSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) { | |
2555 | return; | |
2556 | } | |
2557 | } | |
2558 | // | |
2559 | isuperiodic = anAdaptorSurface.IsUPeriodic(); | |
2560 | isvperiodic = anAdaptorSurface.IsVPeriodic(); | |
2561 | // | |
2562 | aType=anAdaptorSurface.GetType(); | |
2563 | if((aType==GeomAbs_BezierSurface) || | |
2564 | (aType==GeomAbs_BSplineSurface) || | |
2565 | (aType==GeomAbs_SurfaceOfExtrusion) || | |
c002793b | 2566 | (aType==GeomAbs_SurfaceOfRevolution) || |
2567 | (aType==GeomAbs_Cylinder)) { | |
7fd59977 | 2568 | enlarge=Standard_True; |
2569 | } | |
2570 | // | |
2571 | if(!isuperiodic && enlarge) { | |
2572 | ||
d4b867e6 | 2573 | if(!Precision::IsInfinite(theumin) && |
2574 | ((theumin - uinf) > delta)) | |
7fd59977 | 2575 | theumin -= delta; |
2576 | else { | |
2577 | theumin = uinf; | |
2578 | } | |
2579 | ||
d4b867e6 | 2580 | if(!Precision::IsInfinite(theumax) && |
2581 | ((usup - theumax) > delta)) | |
7fd59977 | 2582 | theumax += delta; |
2583 | else | |
2584 | theumax = usup; | |
2585 | } | |
2586 | // | |
2587 | if(!isvperiodic && enlarge) { | |
d4b867e6 | 2588 | if(!Precision::IsInfinite(thevmin) && |
2589 | ((thevmin - vinf) > delta)) { | |
7fd59977 | 2590 | thevmin -= delta; |
2591 | } | |
2592 | else { | |
2593 | thevmin = vinf; | |
2594 | } | |
d4b867e6 | 2595 | if(!Precision::IsInfinite(thevmax) && |
2596 | ((vsup - thevmax) > delta)) { | |
7fd59977 | 2597 | thevmax += delta; |
2598 | } | |
2599 | else { | |
2600 | thevmax = vsup; | |
2601 | } | |
2602 | } | |
2603 | // | |
2604 | { | |
2605 | Standard_Integer aNbP; | |
2606 | Standard_Real aXP, dXfact, aXmid, aX1, aX2, aTolPA; | |
2607 | // | |
2608 | aTolPA=Precision::Angular(); | |
2609 | // U | |
2610 | if (isuperiodic) { | |
2611 | aXP=anAdaptorSurface.UPeriod(); | |
2612 | dXfact=theumax-theumin; | |
2613 | if (dXfact-aTolPA>aXP) { | |
655fddc8 | 2614 | aXmid=0.5*(theumax+theumin); |
2615 | aNbP=RealToInt(aXmid/aXP); | |
2616 | if (aXmid<0.) { | |
2617 | aNbP=aNbP-1; | |
2618 | } | |
2619 | aX1=aNbP*aXP; | |
2620 | if (theumin>aTolPA) { | |
2621 | aX1=theumin+aNbP*aXP; | |
2622 | } | |
2623 | aX2=aX1+aXP; | |
2624 | if (theumin<aX1) { | |
2625 | theumin=aX1; | |
2626 | } | |
2627 | if (theumax>aX2) { | |
2628 | theumax=aX2; | |
2629 | } | |
7fd59977 | 2630 | } |
2631 | } | |
2632 | // V | |
2633 | if (isvperiodic) { | |
2634 | aXP=anAdaptorSurface.VPeriod(); | |
2635 | dXfact=thevmax-thevmin; | |
2636 | if (dXfact-aTolPA>aXP) { | |
655fddc8 | 2637 | aXmid=0.5*(thevmax+thevmin); |
2638 | aNbP=RealToInt(aXmid/aXP); | |
2639 | if (aXmid<0.) { | |
2640 | aNbP=aNbP-1; | |
2641 | } | |
2642 | aX1=aNbP*aXP; | |
2643 | if (thevmin>aTolPA) { | |
2644 | aX1=thevmin+aNbP*aXP; | |
2645 | } | |
2646 | aX2=aX1+aXP; | |
2647 | if (thevmin<aX1) { | |
2648 | thevmin=aX1; | |
2649 | } | |
2650 | if (thevmax>aX2) { | |
2651 | thevmax=aX2; | |
2652 | } | |
7fd59977 | 2653 | } |
2654 | } | |
2655 | } | |
2656 | // | |
2657 | if(isuperiodic || isvperiodic) { | |
2658 | Standard_Boolean correct = Standard_False; | |
2659 | Standard_Boolean correctU = Standard_False; | |
2660 | Standard_Boolean correctV = Standard_False; | |
2661 | Bnd_Box2d aBox; | |
2662 | TopExp_Explorer anExp; | |
2663 | ||
2664 | for(anExp.Init(theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) { | |
2665 | if(BRep_Tool::IsClosed(TopoDS::Edge(anExp.Current()), theFace)) { | |
655fddc8 | 2666 | correct = Standard_True; |
2667 | Standard_Real f, l; | |
2668 | TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current()); | |
2669 | ||
2670 | for(Standard_Integer i = 0; i < 2; i++) { | |
2671 | if(i==0) { | |
2672 | anEdge.Orientation(TopAbs_FORWARD); | |
2673 | } | |
2674 | else { | |
2675 | anEdge.Orientation(TopAbs_REVERSED); | |
2676 | } | |
2677 | Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l); | |
2678 | ||
2679 | if(aCurve.IsNull()) { | |
2680 | correct = Standard_False; | |
2681 | break; | |
2682 | } | |
2683 | Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve); | |
2684 | ||
2685 | if(aLine.IsNull()) { | |
2686 | correct = Standard_False; | |
2687 | break; | |
2688 | } | |
2689 | gp_Dir2d anUDir(1., 0.); | |
2690 | gp_Dir2d aVDir(0., 1.); | |
2691 | Standard_Real anAngularTolerance = Precision::Angular(); | |
2692 | ||
2693 | correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance); | |
2694 | correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance); | |
2695 | ||
2696 | gp_Pnt2d pp1 = aCurve->Value(f); | |
2697 | aBox.Add(pp1); | |
2698 | gp_Pnt2d pp2 = aCurve->Value(l); | |
2699 | aBox.Add(pp2); | |
2700 | } | |
2701 | if(!correct) | |
2702 | break; | |
7fd59977 | 2703 | } |
2704 | } | |
2705 | ||
2706 | if(correct) { | |
2707 | Standard_Real umin, vmin, umax, vmax; | |
2708 | aBox.Get(umin, vmin, umax, vmax); | |
2709 | ||
2710 | if(isuperiodic && correctU) { | |
655fddc8 | 2711 | |
2712 | if(theumin < umin) | |
2713 | theumin = umin; | |
2714 | ||
2715 | if(theumax > umax) { | |
2716 | theumax = umax; | |
2717 | } | |
7fd59977 | 2718 | } |
2719 | if(isvperiodic && correctV) { | |
655fddc8 | 2720 | |
2721 | if(thevmin < vmin) | |
2722 | thevmin = vmin; | |
2723 | if(thevmax > vmax) | |
2724 | thevmax = vmax; | |
7fd59977 | 2725 | } |
2726 | } | |
2727 | } | |
2728 | } | |
2729 | // | |
2730 | // | |
2731 | // The block is dedicated to determine whether WLine [ifprm, ilprm] | |
2732 | // crosses the degenerated zone on each given surface or not. | |
2733 | // If Yes -> We will not use info about surfaces during approximation | |
8e0115e4 | 2734 | // because inside degenerated zone of the surface the approx. algo. |
7fd59977 | 2735 | // uses wrong values of normal, etc., and resulting curve will have |
2736 | // oscillations that we would not like to have. | |
7fd59977 | 2737 | |
2738 | ||
4e57c75e | 2739 | |
7fd59977 | 2740 | static |
2741 | Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d, | |
655fddc8 | 2742 | const Handle(Geom_Surface)& aS, |
2743 | const Standard_Integer iDir); | |
7fd59977 | 2744 | static |
2745 | Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S, | |
655fddc8 | 2746 | const TopoDS_Face& aF1, |
2747 | const TopoDS_Face& aF2); | |
7fd59977 | 2748 | //======================================================================= |
2749 | //function : NotUseSurfacesForApprox | |
2750 | //purpose : | |
2751 | //======================================================================= | |
2752 | Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1, | |
655fddc8 | 2753 | const TopoDS_Face& aF2, |
2754 | const Handle(IntPatch_WLine)& WL, | |
2755 | const Standard_Integer ifprm, | |
2756 | const Standard_Integer ilprm) | |
7fd59977 | 2757 | { |
2758 | Standard_Boolean bPInDZ; | |
2759 | ||
2760 | Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve(); | |
2761 | ||
2762 | const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm); | |
2763 | bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2); | |
2764 | if (bPInDZ) { | |
2765 | return bPInDZ; | |
2766 | } | |
2767 | ||
2768 | const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm); | |
2769 | bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2); | |
2770 | ||
2771 | return bPInDZ; | |
2772 | } | |
2773 | //======================================================================= | |
2774 | //function : IsPointInDegeneratedZone | |
2775 | //purpose : | |
2776 | //======================================================================= | |
2777 | Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S, | |
655fddc8 | 2778 | const TopoDS_Face& aF1, |
2779 | const TopoDS_Face& aF2) | |
2780 | ||
7fd59977 | 2781 | { |
2782 | Standard_Boolean bFlag=Standard_True; | |
2783 | Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22; | |
2784 | Standard_Real U1, V1, U2, V2, aDelta, aD; | |
2785 | gp_Pnt2d aP2d; | |
2786 | ||
2787 | Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1); | |
2788 | aS1->Bounds(US11, US12, VS11, VS12); | |
2789 | GeomAdaptor_Surface aGAS1(aS1); | |
2790 | ||
2791 | Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2); | |
2792 | aS1->Bounds(US21, US22, VS21, VS22); | |
2793 | GeomAdaptor_Surface aGAS2(aS2); | |
2794 | // | |
2795 | //const gp_Pnt& aP=aP2S.Value(); | |
2796 | aP2S.Parameters(U1, V1, U2, V2); | |
2797 | // | |
2798 | aDelta=1.e-7; | |
2799 | // Check on Surf 1 | |
2800 | aD=aGAS1.UResolution(aDelta); | |
2801 | aP2d.SetCoord(U1, V1); | |
2802 | if (fabs(U1-US11) < aD) { | |
2803 | bFlag=IsDegeneratedZone(aP2d, aS1, 1); | |
2804 | if (bFlag) { | |
2805 | return bFlag; | |
2806 | } | |
2807 | } | |
2808 | if (fabs(U1-US12) < aD) { | |
2809 | bFlag=IsDegeneratedZone(aP2d, aS1, 1); | |
2810 | if (bFlag) { | |
2811 | return bFlag; | |
2812 | } | |
2813 | } | |
2814 | aD=aGAS1.VResolution(aDelta); | |
2815 | if (fabs(V1-VS11) < aDelta) { | |
2816 | bFlag=IsDegeneratedZone(aP2d, aS1, 2); | |
2817 | if (bFlag) { | |
2818 | return bFlag; | |
2819 | } | |
2820 | } | |
2821 | if (fabs(V1-VS12) < aDelta) { | |
2822 | bFlag=IsDegeneratedZone(aP2d, aS1, 2); | |
2823 | if (bFlag) { | |
2824 | return bFlag; | |
2825 | } | |
2826 | } | |
2827 | // Check on Surf 2 | |
2828 | aD=aGAS2.UResolution(aDelta); | |
2829 | aP2d.SetCoord(U2, V2); | |
2830 | if (fabs(U2-US21) < aDelta) { | |
2831 | bFlag=IsDegeneratedZone(aP2d, aS2, 1); | |
2832 | if (bFlag) { | |
2833 | return bFlag; | |
2834 | } | |
2835 | } | |
2836 | if (fabs(U2-US22) < aDelta) { | |
2837 | bFlag=IsDegeneratedZone(aP2d, aS2, 1); | |
2838 | if (bFlag) { | |
2839 | return bFlag; | |
2840 | } | |
2841 | } | |
2842 | aD=aGAS2.VResolution(aDelta); | |
2843 | if (fabs(V2-VS21) < aDelta) { | |
2844 | bFlag=IsDegeneratedZone(aP2d, aS2, 2); | |
2845 | if (bFlag) { | |
2846 | return bFlag; | |
2847 | } | |
2848 | } | |
2849 | if (fabs(V2-VS22) < aDelta) { | |
2850 | bFlag=IsDegeneratedZone(aP2d, aS2, 2); | |
2851 | if (bFlag) { | |
2852 | return bFlag; | |
2853 | } | |
2854 | } | |
2855 | return !bFlag; | |
2856 | } | |
2857 | ||
2858 | //======================================================================= | |
2859 | //function : IsDegeneratedZone | |
2860 | //purpose : | |
2861 | //======================================================================= | |
2862 | Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d, | |
655fddc8 | 2863 | const Handle(Geom_Surface)& aS, |
2864 | const Standard_Integer iDir) | |
7fd59977 | 2865 | { |
2866 | Standard_Boolean bFlag=Standard_True; | |
2867 | Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD; | |
2868 | Standard_Real aXm, aYm, aXb, aYb, aXe, aYe; | |
2869 | aS->Bounds(US1, US2, VS1, VS2); | |
2870 | ||
2871 | gp_Pnt aPm, aPb, aPe; | |
2872 | ||
2873 | aXm=aP2d.X(); | |
2874 | aYm=aP2d.Y(); | |
2875 | ||
2876 | aS->D0(aXm, aYm, aPm); | |
2877 | ||
2878 | dX=1.e-5; | |
2879 | dY=1.e-5; | |
2880 | dD=1.e-12; | |
2881 | ||
2882 | if (iDir==1) { | |
2883 | aXb=aXm; | |
2884 | aXe=aXm; | |
2885 | aYb=aYm-dY; | |
2886 | if (aYb < VS1) { | |
2887 | aYb=VS1; | |
2888 | } | |
2889 | aYe=aYm+dY; | |
2890 | if (aYe > VS2) { | |
2891 | aYe=VS2; | |
2892 | } | |
2893 | aS->D0(aXb, aYb, aPb); | |
2894 | aS->D0(aXe, aYe, aPe); | |
2895 | ||
2896 | d1=aPm.Distance(aPb); | |
2897 | d2=aPm.Distance(aPe); | |
2898 | if (d1 < dD && d2 < dD) { | |
2899 | return bFlag; | |
2900 | } | |
2901 | return !bFlag; | |
2902 | } | |
2903 | // | |
2904 | else if (iDir==2) { | |
2905 | aYb=aYm; | |
2906 | aYe=aYm; | |
2907 | aXb=aXm-dX; | |
2908 | if (aXb < US1) { | |
2909 | aXb=US1; | |
2910 | } | |
2911 | aXe=aXm+dX; | |
2912 | if (aXe > US2) { | |
2913 | aXe=US2; | |
2914 | } | |
2915 | aS->D0(aXb, aYb, aPb); | |
2916 | aS->D0(aXe, aYe, aPe); | |
2917 | ||
2918 | d1=aPm.Distance(aPb); | |
2919 | d2=aPm.Distance(aPe); | |
2920 | if (d1 < dD && d2 < dD) { | |
2921 | return bFlag; | |
2922 | } | |
2923 | return !bFlag; | |
2924 | } | |
2925 | return !bFlag; | |
2926 | } | |
2927 | ||
2928 | //========================================================================= | |
2929 | // static function : ComputePurgedWLine | |
2930 | // purpose : Removes equal points (leave one of equal points) from theWLine | |
2931 | // and recompute vertex parameters. | |
2932 | // Returns new WLine or null WLine if the number | |
2933 | // of the points is less than 2. | |
2934 | //========================================================================= | |
2935 | Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine) { | |
3928aec6 | 2936 | |
3928aec6 | 2937 | Standard_Integer i, k, v, nb, nbvtx; |
7fd59977 | 2938 | Handle(IntPatch_WLine) aResult; |
3928aec6 P |
2939 | nbvtx = theWLine->NbVertex(); |
2940 | nb = theWLine->NbPnts(); | |
2941 | if (nb==2) { | |
2942 | const IntSurf_PntOn2S& p1 = theWLine->Point(1); | |
2943 | const IntSurf_PntOn2S& p2 = theWLine->Point(2); | |
2944 | if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) { | |
2945 | return aResult; | |
2946 | } | |
2947 | } | |
2948 | // | |
7fd59977 | 2949 | Handle(IntPatch_WLine) aLocalWLine; |
2950 | Handle(IntPatch_WLine) aTmpWLine = theWLine; | |
7fd59977 | 2951 | Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S(); |
2952 | aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False); | |
7fd59977 | 2953 | for(i = 1; i <= nb; i++) { |
2954 | aLineOn2S->Add(theWLine->Point(i)); | |
2955 | } | |
2956 | ||
2957 | for(v = 1; v <= nbvtx; v++) { | |
2958 | aLocalWLine->AddVertex(theWLine->Vertex(v)); | |
2959 | } | |
2960 | ||
2961 | for(i = 1; i <= aLineOn2S->NbPoints(); i++) { | |
2962 | Standard_Integer aStartIndex = i + 1; | |
2963 | Standard_Integer anEndIndex = i + 5; | |
2964 | nb = aLineOn2S->NbPoints(); | |
2965 | anEndIndex = (anEndIndex > nb) ? nb : anEndIndex; | |
2966 | ||
a2eede02 | 2967 | if((aStartIndex > nb) || (anEndIndex <= 1)) { |
7fd59977 | 2968 | continue; |
2969 | } | |
2970 | k = aStartIndex; | |
2971 | ||
2972 | while(k <= anEndIndex) { | |
2973 | ||
2974 | if(i != k) { | |
655fddc8 | 2975 | IntSurf_PntOn2S p1 = aLineOn2S->Value(i); |
2976 | IntSurf_PntOn2S p2 = aLineOn2S->Value(k); | |
2977 | ||
2978 | if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) { | |
2979 | aTmpWLine = aLocalWLine; | |
2980 | aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False); | |
2981 | ||
2982 | for(v = 1; v <= aTmpWLine->NbVertex(); v++) { | |
2983 | IntPatch_Point aVertex = aTmpWLine->Vertex(v); | |
2984 | Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine(); | |
2985 | ||
2986 | if(avertexindex >= k) { | |
2987 | aVertex.SetParameter(aVertex.ParameterOnLine() - 1.); | |
2988 | } | |
2989 | aLocalWLine->AddVertex(aVertex); | |
2990 | } | |
2991 | aLineOn2S->RemovePoint(k); | |
2992 | anEndIndex--; | |
2993 | continue; | |
2994 | } | |
7fd59977 | 2995 | } |
2996 | k++; | |
2997 | } | |
2998 | } | |
2999 | ||
3000 | if(aLineOn2S->NbPoints() > 1) { | |
3001 | aResult = aLocalWLine; | |
3002 | } | |
3003 | return aResult; | |
3004 | } | |
3005 | ||
3006 | //======================================================================= | |
3007 | //function : TolR3d | |
3008 | //purpose : | |
3009 | //======================================================================= | |
3010 | void TolR3d(const TopoDS_Face& aF1, | |
655fddc8 | 3011 | const TopoDS_Face& aF2, |
3012 | Standard_Real& myTolReached3d) | |
7fd59977 | 3013 | { |
3014 | Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh; | |
3015 | ||
3016 | aTolTresh=2.999999e-3; | |
3017 | aTolF1 = BRep_Tool::Tolerance(aF1); | |
3018 | aTolF2 = BRep_Tool::Tolerance(aF2); | |
3019 | aTolFMax=Max(aTolF1, aTolF2); | |
3020 | ||
3021 | if (aTolFMax>aTolTresh) { | |
3022 | myTolReached3d=aTolFMax; | |
3023 | } | |
3024 | } | |
3025 | //======================================================================= | |
7fd59977 | 3026 | //function : IsPointOnBoundary |
3027 | //purpose : | |
3028 | //======================================================================= | |
3029 | Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter, | |
655fddc8 | 3030 | const Standard_Real theFirstBoundary, |
3031 | const Standard_Real theSecondBoundary, | |
3032 | const Standard_Real theResolution, | |
3033 | Standard_Boolean& IsOnFirstBoundary) | |
7fd59977 | 3034 | { |
3035 | Standard_Boolean bRet; | |
3036 | Standard_Integer i; | |
3037 | Standard_Real adist; | |
3038 | // | |
3039 | bRet=Standard_False; | |
3040 | for(i = 0; i < 2; ++i) { | |
3041 | IsOnFirstBoundary = (i == 0); | |
3042 | if (IsOnFirstBoundary) { | |
3043 | adist = fabs(theParameter - theFirstBoundary); | |
3044 | } | |
3045 | else { | |
3046 | adist = fabs(theParameter - theSecondBoundary); | |
3047 | } | |
3048 | if(adist < theResolution) { | |
3049 | return !bRet; | |
3050 | } | |
3051 | } | |
3052 | return bRet; | |
3053 | } | |
3054 | // ------------------------------------------------------------------------------------------------ | |
3055 | // static function: FindPoint | |
3056 | // purpose: | |
3057 | // ------------------------------------------------------------------------------------------------ | |
3058 | Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint, | |
655fddc8 | 3059 | const gp_Pnt2d& theLastPoint, |
3060 | const Standard_Real theUmin, | |
3061 | const Standard_Real theUmax, | |
3062 | const Standard_Real theVmin, | |
3063 | const Standard_Real theVmax, | |
3064 | gp_Pnt2d& theNewPoint) { | |
7fd59977 | 3065 | |
3066 | gp_Vec2d aVec(theFirstPoint, theLastPoint); | |
3067 | Standard_Integer i = 0, j = 0; | |
3068 | ||
3069 | for(i = 0; i < 4; i++) { | |
3070 | gp_Vec2d anOtherVec; | |
3071 | gp_Vec2d anOtherVecNormal; | |
3072 | gp_Pnt2d aprojpoint = theLastPoint; | |
3073 | ||
3074 | if((i % 2) == 0) { | |
3075 | anOtherVec.SetX(0.); | |
3076 | anOtherVec.SetY(1.); | |
3077 | anOtherVecNormal.SetX(1.); | |
3078 | anOtherVecNormal.SetY(0.); | |
3079 | ||
3080 | if(i < 2) | |
655fddc8 | 3081 | aprojpoint.SetX(theUmin); |
7fd59977 | 3082 | else |
655fddc8 | 3083 | aprojpoint.SetX(theUmax); |
7fd59977 | 3084 | } |
3085 | else { | |
3086 | anOtherVec.SetX(1.); | |
3087 | anOtherVec.SetY(0.); | |
3088 | anOtherVecNormal.SetX(0.); | |
3089 | anOtherVecNormal.SetY(1.); | |
3090 | ||
3091 | if(i < 2) | |
655fddc8 | 3092 | aprojpoint.SetY(theVmin); |
7fd59977 | 3093 | else |
655fddc8 | 3094 | aprojpoint.SetY(theVmax); |
7fd59977 | 3095 | } |
3096 | gp_Vec2d anormvec = aVec; | |
3097 | anormvec.Normalize(); | |
fa9681ca | 3098 | RefineVector(anormvec); |
7fd59977 | 3099 | Standard_Real adot1 = anormvec.Dot(anOtherVecNormal); |
3100 | ||
3101 | if(fabs(adot1) < Precision::Angular()) | |
3102 | continue; | |
3103 | Standard_Real adist = 0.; | |
3104 | Standard_Boolean bIsOut = Standard_False; | |
3105 | ||
3106 | if((i % 2) == 0) { | |
3107 | adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax); | |
3108 | bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax); | |
3109 | } | |
3110 | else { | |
3111 | adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax); | |
3112 | bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax); | |
3113 | } | |
3114 | Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1; | |
3115 | ||
3116 | for(j = 0; j < 2; j++) { | |
3117 | anoffset = (j == 0) ? anoffset : -anoffset; | |
3118 | gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset)); | |
3119 | gp_Vec2d acurvec(theLastPoint, acurpoint); | |
3120 | if ( bIsOut ) | |
655fddc8 | 3121 | acurvec.Reverse(); |
7fd59977 | 3122 | |
9e9df9d9 P |
3123 | Standard_Real aDotX, anAngleX; |
3124 | // | |
3125 | aDotX = aVec.Dot(acurvec); | |
3126 | anAngleX = aVec.Angle(acurvec); | |
3127 | // | |
3128 | if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) { | |
655fddc8 | 3129 | if((i % 2) == 0) { |
3130 | if((acurpoint.Y() >= theVmin) && | |
3131 | (acurpoint.Y() <= theVmax)) { | |
3132 | theNewPoint = acurpoint; | |
3133 | return Standard_True; | |
3134 | } | |
3135 | } | |
3136 | else { | |
3137 | if((acurpoint.X() >= theUmin) && | |
3138 | (acurpoint.X() <= theUmax)) { | |
3139 | theNewPoint = acurpoint; | |
3140 | return Standard_True; | |
3141 | } | |
3142 | } | |
7fd59977 | 3143 | } |
3144 | } | |
3145 | } | |
3146 | return Standard_False; | |
3147 | } | |
3148 | ||
3149 | ||
3150 | // ------------------------------------------------------------------------------------------------ | |
3151 | // static function: FindPoint | |
3152 | // purpose: Find point on the boundary of radial tangent zone | |
3153 | // ------------------------------------------------------------------------------------------------ | |
3154 | Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint, | |
655fddc8 | 3155 | const gp_Pnt2d& theLastPoint, |
3156 | const Standard_Real theUmin, | |
3157 | const Standard_Real theUmax, | |
3158 | const Standard_Real theVmin, | |
3159 | const Standard_Real theVmax, | |
3160 | const gp_Pnt2d& theTanZoneCenter, | |
3161 | const Standard_Real theZoneRadius, | |
3162 | Handle(GeomAdaptor_HSurface) theGASurface, | |
3163 | gp_Pnt2d& theNewPoint) { | |
7fd59977 | 3164 | theNewPoint = theLastPoint; |
3165 | ||
3166 | if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) ) | |
3167 | return Standard_False; | |
3168 | ||
3169 | Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius ); | |
3170 | Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius ); | |
3171 | ||
3172 | Standard_Real aRadius = ( aUResolution < aVResolution ) ? aUResolution : aVResolution; | |
3173 | gp_Ax22d anAxis( theTanZoneCenter, gp_Dir2d(1, 0), gp_Dir2d(0, 1) ); | |
3174 | gp_Circ2d aCircle( anAxis, aRadius ); | |
3175 | ||
3176 | // | |
3177 | gp_Vec2d aDir( theLastPoint.XY() - theFirstPoint.XY() ); | |
3178 | Standard_Real aLength = aDir.Magnitude(); | |
3179 | if ( aLength <= gp::Resolution() ) | |
3180 | return Standard_False; | |
3181 | gp_Lin2d aLine( theFirstPoint, aDir ); | |
3182 | ||
3183 | // | |
3184 | Handle(Geom2d_Line) aCLine = new Geom2d_Line( aLine ); | |
3185 | Handle(Geom2d_TrimmedCurve) aC1 = new Geom2d_TrimmedCurve( aCLine, 0, aLength ); | |
3186 | Handle(Geom2d_Circle) aC2 = new Geom2d_Circle( aCircle ); | |
3187 | ||
3188 | Standard_Real aTol = aRadius * 0.001; | |
3189 | aTol = ( aTol < Precision::PConfusion() ) ? Precision::PConfusion() : aTol; | |
3190 | ||
3191 | Geom2dAPI_InterCurveCurve anIntersector; | |
3192 | anIntersector.Init( aC1, aC2, aTol ); | |
3193 | ||
3194 | if ( anIntersector.NbPoints() == 0 ) | |
3195 | return Standard_False; | |
3196 | ||
3197 | Standard_Boolean aFound = Standard_False; | |
3198 | Standard_Real aMinDist = aLength * aLength; | |
3199 | Standard_Integer i = 0; | |
3200 | for ( i = 1; i <= anIntersector.NbPoints(); i++ ) { | |
3201 | gp_Pnt2d aPInt = anIntersector.Point( i ); | |
3202 | if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) { | |
3203 | if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) && | |
655fddc8 | 3204 | ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) { |
3205 | theNewPoint = aPInt; | |
3206 | aFound = Standard_True; | |
7fd59977 | 3207 | } |
3208 | } | |
3209 | } | |
3210 | ||
3211 | return aFound; | |
3212 | } | |
3213 | ||
3214 | // ------------------------------------------------------------------------------------------------ | |
3215 | // static function: IsInsideTanZone | |
3216 | // purpose: Check if point is inside a radial tangent zone | |
3217 | // ------------------------------------------------------------------------------------------------ | |
3218 | Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint, | |
655fddc8 | 3219 | const gp_Pnt2d& theTanZoneCenter, |
3220 | const Standard_Real theZoneRadius, | |
3221 | Handle(GeomAdaptor_HSurface) theGASurface) { | |
7fd59977 | 3222 | |
3223 | Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius ); | |
3224 | Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius ); | |
3225 | Standard_Real aRadiusSQR = ( aUResolution < aVResolution ) ? aUResolution : aVResolution; | |
3226 | aRadiusSQR *= aRadiusSQR; | |
3227 | if ( thePoint.SquareDistance( theTanZoneCenter ) <= aRadiusSQR ) | |
3228 | return Standard_True; | |
3229 | return Standard_False; | |
3230 | } | |
3231 | ||
3232 | // ------------------------------------------------------------------------------------------------ | |
3233 | // static function: CheckTangentZonesExist | |
3234 | // purpose: Check if tangent zone exists | |
3235 | // ------------------------------------------------------------------------------------------------ | |
3236 | Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& theSurface1, | |
655fddc8 | 3237 | const Handle(GeomAdaptor_HSurface)& theSurface2 ) |
7fd59977 | 3238 | { |
3239 | if ( ( theSurface1->GetType() != GeomAbs_Torus ) || | |
3240 | ( theSurface2->GetType() != GeomAbs_Torus ) ) | |
3241 | return Standard_False; | |
3242 | ||
7fd59977 | 3243 | gp_Torus aTor1 = theSurface1->Torus(); |
3244 | gp_Torus aTor2 = theSurface2->Torus(); | |
3245 | ||
3246 | if ( aTor1.Location().Distance( aTor2.Location() ) > Precision::Confusion() ) | |
3247 | return Standard_False; | |
3248 | ||
3249 | if ( ( fabs( aTor1.MajorRadius() - aTor2.MajorRadius() ) > Precision::Confusion() ) || | |
3250 | ( fabs( aTor1.MinorRadius() - aTor2.MinorRadius() ) > Precision::Confusion() ) ) | |
3251 | return Standard_False; | |
3252 | ||
3253 | if ( ( aTor1.MajorRadius() < aTor1.MinorRadius() ) || | |
3254 | ( aTor2.MajorRadius() < aTor2.MinorRadius() ) ) | |
3255 | return Standard_False; | |
3256 | return Standard_True; | |
3257 | } | |
3258 | ||
3259 | // ------------------------------------------------------------------------------------------------ | |
3260 | // static function: ComputeTangentZones | |
3261 | // purpose: | |
3262 | // ------------------------------------------------------------------------------------------------ | |
3263 | Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1, | |
655fddc8 | 3264 | const Handle(GeomAdaptor_HSurface)& theSurface2, |
3265 | const TopoDS_Face& theFace1, | |
3266 | const TopoDS_Face& theFace2, | |
3267 | Handle(TColgp_HArray1OfPnt2d)& theResultOnS1, | |
3268 | Handle(TColgp_HArray1OfPnt2d)& theResultOnS2, | |
3269 | Handle(TColStd_HArray1OfReal)& theResultRadius, | |
1e143abb | 3270 | const Handle(IntTools_Context)& aContext) |
4f189102 | 3271 | { |
7fd59977 | 3272 | Standard_Integer aResult = 0; |
3273 | if ( !CheckTangentZonesExist( theSurface1, theSurface2 ) ) | |
3274 | return aResult; | |
3275 | ||
7fd59977 | 3276 | |
3277 | TColgp_SequenceOfPnt2d aSeqResultS1, aSeqResultS2; | |
3278 | TColStd_SequenceOfReal aSeqResultRad; | |
3279 | ||
3280 | gp_Torus aTor1 = theSurface1->Torus(); | |
3281 | gp_Torus aTor2 = theSurface2->Torus(); | |
3282 | ||
3283 | gp_Ax2 anax1( aTor1.Location(), aTor1.Axis().Direction() ); | |
3284 | gp_Ax2 anax2( aTor2.Location(), aTor2.Axis().Direction() ); | |
3285 | Standard_Integer j = 0; | |
3286 | ||
3287 | for ( j = 0; j < 2; j++ ) { | |
3288 | Standard_Real aCoef = ( j == 0 ) ? -1 : 1; | |
3289 | Standard_Real aRadius1 = fabs(aTor1.MajorRadius() + aCoef * aTor1.MinorRadius()); | |
3290 | Standard_Real aRadius2 = fabs(aTor2.MajorRadius() + aCoef * aTor2.MinorRadius()); | |
3291 | ||
3292 | gp_Circ aCircle1( anax1, aRadius1 ); | |
3293 | gp_Circ aCircle2( anax2, aRadius2 ); | |
3294 | ||
3295 | // roughly compute radius of tangent zone for perpendicular case | |
3296 | Standard_Real aCriteria = Precision::Confusion() * 0.5; | |
3297 | ||
3298 | Standard_Real aT1 = aCriteria; | |
3299 | Standard_Real aT2 = aCriteria; | |
3300 | if ( j == 0 ) { | |
3301 | // internal tangency | |
3302 | Standard_Real aR = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius(); | |
3303 | //aT1 = aCriteria * aCriteria + aR * aR - ( aR - aCriteria ) * ( aR - aCriteria ); | |
3304 | aT1 = 2. * aR * aCriteria; | |
3305 | aT2 = aT1; | |
3306 | } | |
3307 | else { | |
3308 | // external tangency | |
3309 | Standard_Real aRb = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius(); | |
3310 | Standard_Real aRm = ( aRadius1 < aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius(); | |
3311 | Standard_Real aDelta = aRb - aCriteria; | |
3312 | aDelta *= aDelta; | |
3313 | aDelta -= aRm * aRm; | |
3314 | aDelta /= 2. * (aRb - aRm); | |
3315 | aDelta -= 0.5 * (aRb - aRm); | |
3316 | ||
3317 | aT1 = 2. * aRm * (aRm - aDelta); | |
3318 | aT2 = aT1; | |
3319 | } | |
3320 | aCriteria = ( aT1 > aT2) ? aT1 : aT2; | |
3321 | if ( aCriteria > 0 ) | |
3322 | aCriteria = sqrt( aCriteria ); | |
3323 | ||
3324 | if ( aCriteria > 0.5 * aTor1.MinorRadius() ) { | |
3325 | // too big zone -> drop to minimum | |
3326 | aCriteria = Precision::Confusion(); | |
3327 | } | |
3328 | ||
3329 | GeomAdaptor_Curve aC1( new Geom_Circle(aCircle1) ); | |
3330 | GeomAdaptor_Curve aC2( new Geom_Circle(aCircle2) ); | |
c6541a0c | 3331 | Extrema_ExtCC anExtrema(aC1, aC2, 0, 2. * M_PI, 0, 2. * M_PI, |
655fddc8 | 3332 | Precision::PConfusion(), Precision::PConfusion()); |
3333 | ||
7fd59977 | 3334 | if ( anExtrema.IsDone() ) { |
3335 | ||
3336 | Standard_Integer i = 0; | |
3337 | for ( i = 1; i <= anExtrema.NbExt(); i++ ) { | |
655fddc8 | 3338 | if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria ) |
3339 | continue; | |
3340 | ||
3341 | Extrema_POnCurv P1, P2; | |
3342 | anExtrema.Points( i, P1, P2 ); | |
3343 | ||
3344 | Standard_Boolean bFoundResult = Standard_True; | |
3345 | gp_Pnt2d pr1, pr2; | |
3346 | ||
3347 | Standard_Integer surfit = 0; | |
3348 | for ( surfit = 0; surfit < 2; surfit++ ) { | |
3349 | GeomAPI_ProjectPointOnSurf& aProjector = | |
3350 | (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2); | |
3351 | ||
3352 | gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value(); | |
3353 | aProjector.Perform(aP3d); | |
3354 | ||
3355 | if(!aProjector.IsDone()) | |
3356 | bFoundResult = Standard_False; | |
3357 | else { | |
3358 | if(aProjector.LowerDistance() > aCriteria) { | |
3359 | bFoundResult = Standard_False; | |
3360 | } | |
3361 | else { | |
3362 | Standard_Real foundU = 0, foundV = 0; | |
3363 | aProjector.LowerDistanceParameters(foundU, foundV); | |
3364 | if ( surfit == 0 ) | |
3365 | pr1 = gp_Pnt2d( foundU, foundV ); | |
3366 | else | |
3367 | pr2 = gp_Pnt2d( foundU, foundV ); | |
3368 | } | |
3369 | } | |
3370 | } | |
3371 | if ( bFoundResult ) { | |
3372 | aSeqResultS1.Append( pr1 ); | |
3373 | aSeqResultS2.Append( pr2 ); | |
3374 | aSeqResultRad.Append( aCriteria ); | |
3375 | ||
3376 | // torus is u and v periodic | |
3377 | const Standard_Real twoPI = M_PI + M_PI; | |
3378 | Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()}; | |
3379 | Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()}; | |
3380 | ||
3381 | // iteration on period bounds | |
3382 | for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) { | |
3383 | Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI; | |
3384 | Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI; | |
3385 | ||
3386 | // iteration on surfaces | |
3387 | for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) { | |
3388 | Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp; | |
3389 | Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp; | |
3390 | TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2; | |
3391 | TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2; | |
3392 | ||
3393 | if (fabs(arr1[0] - aBound) < Precision::PConfusion()) { | |
3394 | aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) ); | |
3395 | aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) ); | |
3396 | aSeqResultRad.Append( aCriteria ); | |
3397 | } | |
3398 | if (fabs(arr1[1] - aBound) < Precision::PConfusion()) { | |
3399 | aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) ); | |
3400 | aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) ); | |
3401 | aSeqResultRad.Append( aCriteria ); | |
3402 | } | |
3403 | } | |
3404 | } // | |
3405 | } | |
7fd59977 | 3406 | } |
3407 | } | |
3408 | } | |
3409 | aResult = aSeqResultRad.Length(); | |
3410 | ||
3411 | if ( aResult > 0 ) { | |
3412 | theResultOnS1 = new TColgp_HArray1OfPnt2d( 1, aResult ); | |
3413 | theResultOnS2 = new TColgp_HArray1OfPnt2d( 1, aResult ); | |
3414 | theResultRadius = new TColStd_HArray1OfReal( 1, aResult ); | |
3415 | ||
3416 | for ( Standard_Integer i = 1 ; i <= aResult; i++ ) { | |
3417 | theResultOnS1->SetValue( i, aSeqResultS1.Value(i) ); | |
3418 | theResultOnS2->SetValue( i, aSeqResultS2.Value(i) ); | |
3419 | theResultRadius->SetValue( i, aSeqResultRad.Value(i) ); | |
3420 | } | |
3421 | } | |
3422 | return aResult; | |
3423 | } | |
3424 | ||
3425 | // ------------------------------------------------------------------------------------------------ | |
3426 | // static function: AdjustByNeighbour | |
3427 | // purpose: | |
3428 | // ------------------------------------------------------------------------------------------------ | |
3429 | gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint, | |
655fddc8 | 3430 | const gp_Pnt2d& theOriginalPoint, |
3431 | Handle(GeomAdaptor_HSurface) theGASurface) { | |
7fd59977 | 3432 | |
3433 | gp_Pnt2d ap1 = theaNeighbourPoint; | |
3434 | gp_Pnt2d ap2 = theOriginalPoint; | |
3435 | ||
3436 | if ( theGASurface->IsUPeriodic() ) { | |
3437 | Standard_Real aPeriod = theGASurface->UPeriod(); | |
3438 | gp_Pnt2d aPTest = ap2; | |
3439 | Standard_Real aSqDistMin = 1.e+100; | |
3440 | ||
3441 | for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) { | |
3442 | aPTest.SetX( theOriginalPoint.X() + aPeriod * pIt ); | |
3443 | Standard_Real dd = ap1.SquareDistance( aPTest ); | |
3444 | ||
3445 | if ( dd < aSqDistMin ) { | |
655fddc8 | 3446 | ap2 = aPTest; |
3447 | aSqDistMin = dd; | |
7fd59977 | 3448 | } |
3449 | } | |
3450 | } | |
3451 | if ( theGASurface->IsVPeriodic() ) { | |
3452 | Standard_Real aPeriod = theGASurface->VPeriod(); | |
3453 | gp_Pnt2d aPTest = ap2; | |
3454 | Standard_Real aSqDistMin = 1.e+100; | |
3455 | ||
3456 | for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) { | |
3457 | aPTest.SetY( theOriginalPoint.Y() + aPeriod * pIt ); | |
3458 | Standard_Real dd = ap1.SquareDistance( aPTest ); | |
3459 | ||
3460 | if ( dd < aSqDistMin ) { | |
655fddc8 | 3461 | ap2 = aPTest; |
3462 | aSqDistMin = dd; | |
7fd59977 | 3463 | } |
3464 | } | |
3465 | } | |
3466 | return ap2; | |
3467 | } | |
3468 | ||
3469 | // ------------------------------------------------------------------------------------------------ | |
3470 | //function: DecompositionOfWLine | |
3471 | // purpose: | |
3472 | // ------------------------------------------------------------------------------------------------ | |
3473 | Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine, | |
655fddc8 | 3474 | const Handle(GeomAdaptor_HSurface)& theSurface1, |
3475 | const Handle(GeomAdaptor_HSurface)& theSurface2, | |
3476 | const TopoDS_Face& theFace1, | |
3477 | const TopoDS_Face& theFace2, | |
2a78ec6a | 3478 | const GeomInt_LineConstructor& theLConstructor, |
655fddc8 | 3479 | const Standard_Boolean theAvoidLConstructor, |
3480 | IntPatch_SequenceOfLine& theNewLines, | |
3481 | Standard_Real& theReachedTol3d, | |
1e143abb | 3482 | const Handle(IntTools_Context)& aContext) |
4f189102 | 3483 | { |
7fd59977 | 3484 | |
3485 | Standard_Boolean bRet, bAvoidLineConstructor; | |
3486 | Standard_Integer aNbPnts, aNbParts; | |
3487 | // | |
3488 | bRet=Standard_False; | |
3489 | aNbPnts=theWLine->NbPnts(); | |
3490 | bAvoidLineConstructor=theAvoidLConstructor; | |
3491 | // | |
3492 | if(!aNbPnts){ | |
3493 | return bRet; | |
3494 | } | |
3495 | if (!bAvoidLineConstructor) { | |
3496 | aNbParts=theLConstructor.NbParts(); | |
3497 | if (!aNbParts) { | |
3498 | return bRet; | |
3499 | } | |
3500 | } | |
3501 | // | |
3502 | Standard_Boolean bIsPrevPointOnBoundary, bIsPointOnBoundary, bIsCurrentPointOnBoundary; | |
3503 | Standard_Integer nblines, pit, i, j; | |
3504 | Standard_Real aTol; | |
3505 | TColStd_Array1OfListOfInteger anArrayOfLines(1, aNbPnts); | |
3506 | TColStd_Array1OfInteger anArrayOfLineType(1, aNbPnts); | |
3507 | TColStd_ListOfInteger aListOfPointIndex; | |
7fd59977 | 3508 | |
3509 | Handle(TColgp_HArray1OfPnt2d) aTanZoneS1; | |
3510 | Handle(TColgp_HArray1OfPnt2d) aTanZoneS2; | |
3511 | Handle(TColStd_HArray1OfReal) aTanZoneRadius; | |
3512 | Standard_Integer aNbZone = ComputeTangentZones( theSurface1, theSurface2, theFace1, theFace2, | |
655fddc8 | 3513 | aTanZoneS1, aTanZoneS2, aTanZoneRadius, aContext); |
7fd59977 | 3514 | |
3515 | // | |
3516 | nblines=0; | |
3517 | aTol=Precision::Confusion(); | |
3518 | aTol=0.5*aTol; | |
3519 | bIsPrevPointOnBoundary=Standard_False; | |
3520 | bIsPointOnBoundary=Standard_False; | |
3521 | // | |
3522 | // 1. ... | |
3523 | // | |
3524 | // Points | |
3525 | for(pit = 1; pit <= aNbPnts; ++pit) { | |
3526 | Standard_Boolean bIsOnFirstBoundary, isperiodic; | |
3527 | Standard_Real aResolution, aPeriod, alowerboundary, aupperboundary, U, V; | |
3528 | Standard_Real aParameter, anoffset, anAdjustPar; | |
3529 | Standard_Real umin, umax, vmin, vmax; | |
3530 | // | |
3531 | bIsCurrentPointOnBoundary = Standard_False; | |
3532 | const IntSurf_PntOn2S& aPoint = theWLine->Point(pit); | |
3533 | // | |
3534 | // Surface | |
3535 | for(i = 0; i < 2; ++i) { | |
3536 | Handle(GeomAdaptor_HSurface) aGASurface = (!i) ? theSurface1 : theSurface2; | |
3537 | aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax); | |
3538 | if(!i) { | |
655fddc8 | 3539 | aPoint.ParametersOnS1(U, V); |
7fd59977 | 3540 | } |
3541 | else { | |
655fddc8 | 3542 | aPoint.ParametersOnS2(U, V); |
7fd59977 | 3543 | } |
3544 | // U, V | |
3545 | for(j = 0; j < 2; j++) { | |
655fddc8 | 3546 | isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic(); |
3547 | if(!isperiodic){ | |
3548 | continue; | |
3549 | } | |
3550 | // | |
3551 | if (!j) { | |
3552 | aResolution=aGASurface->UResolution(aTol); | |
3553 | aPeriod=aGASurface->UPeriod(); | |
3554 | alowerboundary=umin; | |
3555 | aupperboundary=umax; | |
3556 | aParameter=U; | |
3557 | } | |
3558 | else { | |
3559 | aResolution=aGASurface->VResolution(aTol); | |
3560 | aPeriod=aGASurface->VPeriod(); | |
3561 | alowerboundary=vmin; | |
3562 | aupperboundary=vmax; | |
3563 | aParameter=V; | |
3564 | } | |
3565 | ||
2a78ec6a | 3566 | GeomInt::AdjustPeriodic(aParameter, |
655fddc8 | 3567 | alowerboundary, |
3568 | aupperboundary, | |
3569 | aPeriod, | |
3570 | anAdjustPar, | |
3571 | anoffset); | |
3572 | // | |
3573 | bIsOnFirstBoundary = Standard_True;// ? | |
3574 | bIsPointOnBoundary= | |
3575 | IsPointOnBoundary(anAdjustPar, | |
3576 | alowerboundary, | |
3577 | aupperboundary, | |
3578 | aResolution, | |
3579 | bIsOnFirstBoundary); | |
3580 | // | |
3581 | if(bIsPointOnBoundary) { | |
3582 | bIsCurrentPointOnBoundary = Standard_True; | |
3583 | break; | |
3584 | } | |
3585 | else { | |
3586 | // check if a point belong to a tangent zone. Begin | |
3587 | Standard_Integer zIt = 0; | |
3588 | for ( zIt = 1; zIt <= aNbZone; zIt++ ) { | |
3589 | gp_Pnt2d aPZone = (i == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt); | |
3590 | Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt); | |
3591 | ||
3592 | if ( IsInsideTanZone(gp_Pnt2d( U, V ), aPZone, aZoneRadius, aGASurface ) ) { | |
3593 | // set boundary flag to split the curve by a tangent zone | |
3594 | bIsPointOnBoundary = Standard_True; | |
3595 | bIsCurrentPointOnBoundary = Standard_True; | |
3596 | if ( theReachedTol3d < aZoneRadius ) { | |
3597 | theReachedTol3d = aZoneRadius; | |
3598 | } | |
3599 | break; | |
3600 | } | |
3601 | } | |
3602 | } | |
7fd59977 | 3603 | }//for(j = 0; j < 2; j++) { |
3604 | ||
3605 | if(bIsCurrentPointOnBoundary){ | |
655fddc8 | 3606 | break; |
7fd59977 | 3607 | } |
3608 | }//for(i = 0; i < 2; ++i) { | |
3609 | // | |
3610 | if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) { | |
3611 | if(!aListOfPointIndex.IsEmpty()) { | |
655fddc8 | 3612 | nblines++; |
3613 | anArrayOfLines.SetValue(nblines, aListOfPointIndex); | |
3614 | anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary); | |
3615 | aListOfPointIndex.Clear(); | |
7fd59977 | 3616 | } |
3617 | bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary; | |
3618 | } | |
3619 | aListOfPointIndex.Append(pit); | |
3620 | } //for(pit = 1; pit <= aNbPnts; ++pit) { | |
3621 | // | |
3622 | if(!aListOfPointIndex.IsEmpty()) { | |
3623 | nblines++; | |
3624 | anArrayOfLines.SetValue(nblines, aListOfPointIndex); | |
3625 | anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary); | |
3626 | aListOfPointIndex.Clear(); | |
3627 | } | |
3628 | // | |
3629 | if(nblines<=1) { | |
3630 | return bRet; //Standard_False; | |
3631 | } | |
3632 | // | |
3633 | // | |
3634 | // 2. Correct wlines.begin | |
3635 | TColStd_Array1OfListOfInteger anArrayOfLineEnds(1, nblines); | |
3636 | Handle(IntSurf_LineOn2S) aSeqOfPntOn2S = new IntSurf_LineOn2S(); | |
3637 | // | |
3638 | for(i = 1; i <= nblines; i++) { | |
3639 | if(anArrayOfLineType.Value(i) != 0) { | |
3640 | continue; | |
3641 | } | |
3642 | const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i); | |
7fd59977 | 3643 | TColStd_ListOfInteger aListOfFLIndex; |
3644 | ||
3645 | for(j = 0; j < 2; j++) { | |
3646 | Standard_Integer aneighbourindex = (j == 0) ? (i - 1) : (i + 1); | |
3647 | ||
3648 | if((aneighbourindex < 1) || (aneighbourindex > nblines)) | |
655fddc8 | 3649 | continue; |
7fd59977 | 3650 | |
3651 | if(anArrayOfLineType.Value(aneighbourindex) == 0) | |
655fddc8 | 3652 | continue; |
7fd59977 | 3653 | const TColStd_ListOfInteger& aNeighbour = anArrayOfLines.Value(aneighbourindex); |
3654 | Standard_Integer anIndex = (j == 0) ? aNeighbour.Last() : aNeighbour.First(); | |
3655 | const IntSurf_PntOn2S& aPoint = theWLine->Point(anIndex); | |
3656 | ||
3657 | IntSurf_PntOn2S aNewP = aPoint; | |
b1574471 | 3658 | if(aListOfIndex.Extent() < 2) { |
3659 | aSeqOfPntOn2S->Add(aNewP); | |
3660 | aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints()); | |
3661 | continue; | |
3662 | } | |
3663 | // | |
3664 | Standard_Integer iFirst = aListOfIndex.First(); | |
3665 | Standard_Integer iLast = aListOfIndex.Last(); | |
3666 | // | |
7fd59977 | 3667 | for(Standard_Integer surfit = 0; surfit < 2; surfit++) { |
3668 | ||
655fddc8 | 3669 | Handle(GeomAdaptor_HSurface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2; |
3670 | Standard_Real umin=0., umax=0., vmin=0., vmax=0.; | |
3671 | aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax); | |
3672 | Standard_Real U=0., V=0.; | |
7fd59977 | 3673 | |
655fddc8 | 3674 | if(surfit == 0) |
3675 | aNewP.ParametersOnS1(U, V); | |
3676 | else | |
3677 | aNewP.ParametersOnS2(U, V); | |
3678 | Standard_Integer nbboundaries = 0; | |
7fd59977 | 3679 | |
655fddc8 | 3680 | Standard_Boolean bIsNearBoundary = Standard_False; |
3681 | Standard_Integer aZoneIndex = 0; | |
3682 | Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1 | |
3683 | Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1 | |
3684 | ||
7fd59977 | 3685 | |
655fddc8 | 3686 | for(Standard_Integer parit = 0; parit < 2; parit++) { |
3687 | Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic(); | |
7fd59977 | 3688 | |
655fddc8 | 3689 | Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol); |
3690 | Standard_Real alowerboundary = (parit == 0) ? umin : vmin; | |
3691 | Standard_Real aupperboundary = (parit == 0) ? umax : vmax; | |
7fd59977 | 3692 | |
655fddc8 | 3693 | Standard_Real aParameter = (parit == 0) ? U : V; |
3694 | Standard_Boolean bIsOnFirstBoundary = Standard_True; | |
7fd59977 | 3695 | |
655fddc8 | 3696 | if(!isperiodic) { |
3697 | bIsPointOnBoundary= | |
3698 | IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary); | |
3699 | if(bIsPointOnBoundary) { | |
3700 | bIsUBoundary = (parit == 0); | |
3701 | bIsFirstBoundary = bIsOnFirstBoundary; | |
3702 | nbboundaries++; | |
3703 | } | |
3704 | } | |
3705 | else { | |
3706 | Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod(); | |
3707 | Standard_Real anoffset, anAdjustPar; | |
2a78ec6a | 3708 | GeomInt::AdjustPeriodic(aParameter, alowerboundary, aupperboundary, |
655fddc8 | 3709 | aPeriod, anAdjustPar, anoffset); |
3710 | ||
3711 | bIsPointOnBoundary= | |
3712 | IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary); | |
3713 | if(bIsPointOnBoundary) { | |
3714 | bIsUBoundary = (parit == 0); | |
3715 | bIsFirstBoundary = bIsOnFirstBoundary; | |
3716 | nbboundaries++; | |
3717 | } | |
3718 | else { | |
b1574471 | 3719 | //check neighbourhood of boundary |
3720 | Standard_Real anEpsilon = aResolution * 100.; | |
3721 | Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1; | |
3722 | anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon; | |
3723 | ||
655fddc8 | 3724 | bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, |
3725 | anEpsilon, bIsOnFirstBoundary); | |
3726 | ||
3727 | } | |
3728 | } | |
3729 | } | |
3730 | ||
3731 | // check if a point belong to a tangent zone. Begin | |
3732 | for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) { | |
3733 | gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt); | |
3734 | Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt); | |
3735 | ||
b1574471 | 3736 | Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast; |
655fddc8 | 3737 | const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1); |
3738 | Standard_Real nU1, nV1; | |
3739 | ||
3740 | if(surfit == 0) | |
3741 | aNeighbourPoint.ParametersOnS1(nU1, nV1); | |
3742 | else | |
3743 | aNeighbourPoint.ParametersOnS2(nU1, nV1); | |
3744 | gp_Pnt2d ap1(nU1, nV1); | |
3745 | gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface ); | |
3746 | ||
3747 | ||
3748 | if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) { | |
3749 | aZoneIndex = zIt; | |
3750 | bIsNearBoundary = Standard_True; | |
3751 | if ( theReachedTol3d < aZoneRadius ) { | |
3752 | theReachedTol3d = aZoneRadius; | |
3753 | } | |
3754 | } | |
3755 | } | |
3756 | // check if a point belong to a tangent zone. End | |
3757 | Standard_Boolean bComputeLineEnd = Standard_False; | |
3758 | ||
3759 | if(nbboundaries == 2) { | |
3760 | //xf | |
3761 | bComputeLineEnd = Standard_True; | |
3762 | //xt | |
3763 | } | |
3764 | else if(nbboundaries == 1) { | |
3765 | Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic(); | |
3766 | ||
3767 | if(isperiodic) { | |
3768 | Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin; | |
3769 | Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax; | |
3770 | Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod(); | |
3771 | Standard_Real aParameter = (bIsUBoundary) ? U : V; | |
3772 | Standard_Real anoffset, anAdjustPar; | |
2a78ec6a | 3773 | GeomInt::AdjustPeriodic(aParameter, alowerboundary, aupperboundary, |
655fddc8 | 3774 | aPeriod, anAdjustPar, anoffset); |
3775 | ||
3776 | Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary); | |
3777 | Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist); | |
3778 | anotherPar += anoffset; | |
3779 | Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last(); | |
3780 | const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex); | |
3781 | Standard_Real nU1, nV1; | |
3782 | ||
3783 | if(surfit == 0) | |
3784 | aNeighbourPoint.ParametersOnS1(nU1, nV1); | |
3785 | else | |
3786 | aNeighbourPoint.ParametersOnS2(nU1, nV1); | |
3787 | ||
3788 | Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V); | |
3789 | Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar); | |
3790 | bComputeLineEnd = Standard_True; | |
3791 | Standard_Boolean bCheckAngle1 = Standard_False; | |
3792 | Standard_Boolean bCheckAngle2 = Standard_False; | |
3793 | gp_Vec2d aNewVec; | |
3794 | Standard_Real anewU = (bIsUBoundary) ? anotherPar : U; | |
3795 | Standard_Real anewV = (bIsUBoundary) ? V : anotherPar; | |
3796 | ||
3797 | if(((adist1 - adist2) > Precision::PConfusion()) && | |
3798 | (adist2 < (aPeriod / 4.))) { | |
3799 | bCheckAngle1 = Standard_True; | |
3800 | aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV)); | |
3801 | ||
b2af2f56 | 3802 | if(aNewVec.SquareMagnitude() < gp::Resolution()) { |
655fddc8 | 3803 | aNewP.SetValue((surfit == 0), anewU, anewV); |
3804 | bCheckAngle1 = Standard_False; | |
3805 | } | |
3806 | } | |
3807 | else if(adist1 < (aPeriod / 4.)) { | |
3808 | bCheckAngle2 = Standard_True; | |
3809 | aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V)); | |
3810 | ||
b2af2f56 | 3811 | if(aNewVec.SquareMagnitude() < gp::Resolution()) { |
655fddc8 | 3812 | bCheckAngle2 = Standard_False; |
3813 | } | |
3814 | } | |
3815 | ||
3816 | if(bCheckAngle1 || bCheckAngle2) { | |
3817 | // assume there are at least two points in line (see "if" above) | |
3818 | Standard_Integer anindexother = aneighbourpointindex; | |
3819 | ||
b1574471 | 3820 | while((anindexother <= iLast) && (anindexother >= iFirst)) { |
655fddc8 | 3821 | anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1); |
3822 | const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother); | |
3823 | Standard_Real nU2, nV2; | |
3824 | ||
3825 | if(surfit == 0) | |
3826 | aPrevNeighbourPoint.ParametersOnS1(nU2, nV2); | |
3827 | else | |
3828 | aPrevNeighbourPoint.ParametersOnS2(nU2, nV2); | |
3829 | gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1)); | |
3830 | ||
b2af2f56 | 3831 | if(aVecOld.SquareMagnitude() <= gp::Resolution()) { |
655fddc8 | 3832 | continue; |
3833 | } | |
3834 | else { | |
3835 | Standard_Real anAngle = aNewVec.Angle(aVecOld); | |
3836 | ||
3837 | if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) { | |
3838 | ||
3839 | if(bCheckAngle1) { | |
3840 | Standard_Real U1, U2, V1, V2; | |
3841 | IntSurf_PntOn2S atmppoint = aNewP; | |
3842 | atmppoint.SetValue((surfit == 0), anewU, anewV); | |
3843 | atmppoint.Parameters(U1, V1, U2, V2); | |
3844 | gp_Pnt P1 = theSurface1->Value(U1, V1); | |
3845 | gp_Pnt P2 = theSurface2->Value(U2, V2); | |
3846 | gp_Pnt P0 = aPoint.Value(); | |
3847 | ||
3848 | if(P0.IsEqual(P1, aTol) && | |
3849 | P0.IsEqual(P2, aTol) && | |
3850 | P1.IsEqual(P2, aTol)) { | |
3851 | bComputeLineEnd = Standard_False; | |
3852 | aNewP.SetValue((surfit == 0), anewU, anewV); | |
3853 | } | |
3854 | } | |
3855 | ||
3856 | if(bCheckAngle2) { | |
3857 | bComputeLineEnd = Standard_False; | |
3858 | } | |
3859 | } | |
3860 | break; | |
3861 | } | |
3862 | } // end while(anindexother...) | |
3863 | } | |
3864 | } | |
3865 | } | |
3866 | else if ( bIsNearBoundary ) { | |
3867 | bComputeLineEnd = Standard_True; | |
3868 | } | |
3869 | ||
3870 | if(bComputeLineEnd) { | |
3871 | ||
3872 | gp_Pnt2d anewpoint; | |
3873 | Standard_Boolean found = Standard_False; | |
3874 | ||
3875 | if ( bIsNearBoundary ) { | |
3876 | // re-compute point near natural boundary or near tangent zone | |
3877 | Standard_Real u1, v1, u2, v2; | |
3878 | aNewP.Parameters( u1, v1, u2, v2 ); | |
3879 | if(surfit == 0) | |
3880 | anewpoint = gp_Pnt2d( u1, v1 ); | |
3881 | else | |
3882 | anewpoint = gp_Pnt2d( u2, v2 ); | |
3883 | ||
b1574471 | 3884 | Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast; |
655fddc8 | 3885 | const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1); |
3886 | Standard_Real nU1, nV1; | |
3887 | ||
3888 | if(surfit == 0) | |
3889 | aNeighbourPoint.ParametersOnS1(nU1, nV1); | |
3890 | else | |
3891 | aNeighbourPoint.ParametersOnS2(nU1, nV1); | |
3892 | gp_Pnt2d ap1(nU1, nV1); | |
3893 | gp_Pnt2d ap2; | |
3894 | ||
3895 | ||
3896 | if ( aZoneIndex ) { | |
3897 | // exclude point from a tangent zone | |
3898 | anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface ); | |
3899 | gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex); | |
3900 | Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex); | |
3901 | ||
3902 | if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax, | |
3903 | aPZone, aZoneRadius, aGASurface, ap2) ) { | |
3904 | anewpoint = ap2; | |
3905 | found = Standard_True; | |
3906 | } | |
3907 | } | |
3908 | else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) { | |
3909 | // re-compute point near boundary if shifted on a period | |
3910 | ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface ); | |
3911 | ||
3912 | if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) || | |
3913 | ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) { | |
3914 | found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint); | |
3915 | } | |
3916 | else { | |
3917 | anewpoint = ap2; | |
3918 | aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() ); | |
3919 | } | |
3920 | } | |
3921 | } | |
3922 | else { | |
3923 | ||
b1574471 | 3924 | Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast; |
655fddc8 | 3925 | const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1); |
3926 | Standard_Real nU1, nV1; | |
3927 | ||
3928 | if(surfit == 0) | |
3929 | aNeighbourPoint.ParametersOnS1(nU1, nV1); | |
3930 | else | |
3931 | aNeighbourPoint.ParametersOnS2(nU1, nV1); | |
3932 | gp_Pnt2d ap1(nU1, nV1); | |
3933 | gp_Pnt2d ap2(nU1, nV1); | |
3934 | Standard_Integer aneighbourpointindex2 = aneighbourpointindex1; | |
3935 | ||
b1574471 | 3936 | while((aneighbourpointindex2 <= iLast) && (aneighbourpointindex2 >= iFirst)) { |
655fddc8 | 3937 | aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1); |
3938 | const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2); | |
3939 | Standard_Real nU2, nV2; | |
3940 | ||
3941 | if(surfit == 0) | |
3942 | aPrevNeighbourPoint.ParametersOnS1(nU2, nV2); | |
3943 | else | |
3944 | aPrevNeighbourPoint.ParametersOnS2(nU2, nV2); | |
3945 | ap2.SetX(nU2); | |
3946 | ap2.SetY(nV2); | |
3947 | ||
b2af2f56 | 3948 | if(ap1.SquareDistance(ap2) > gp::Resolution()) { |
655fddc8 | 3949 | break; |
3950 | } | |
3951 | } | |
3952 | found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint); | |
3953 | } | |
3954 | ||
3955 | if(found) { | |
3956 | // check point | |
3957 | Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2); | |
3958 | GeomAPI_ProjectPointOnSurf& aProjector = | |
3959 | (surfit == 0) ? aContext->ProjPS(theFace2) : aContext->ProjPS(theFace1); | |
3960 | Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2; | |
3961 | ||
3962 | Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1; | |
3963 | ||
3964 | gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y()); | |
3965 | aProjector.Perform(aP3d); | |
3966 | ||
3967 | if(aProjector.IsDone()) { | |
3968 | if(aProjector.LowerDistance() < aCriteria) { | |
3969 | Standard_Real foundU = U, foundV = V; | |
3970 | aProjector.LowerDistanceParameters(foundU, foundV); | |
3971 | ||
3972 | //Correction of projected coordinates. Begin | |
3973 | //Note, it may be shifted on a period | |
b1574471 | 3974 | Standard_Integer aneindex1 = (j == 0) ? iFirst : iLast; |
655fddc8 | 3975 | const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1); |
3976 | Standard_Real nUn, nVn; | |
3977 | ||
3978 | if(surfit == 0) | |
3979 | aNeighbourPoint.ParametersOnS2(nUn, nVn); | |
3980 | else | |
3981 | aNeighbourPoint.ParametersOnS1(nUn, nVn); | |
3982 | gp_Pnt2d aNeighbour2d(nUn, nVn); | |
3983 | gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther ); | |
3984 | foundU = anAdjustedPoint.X(); | |
3985 | foundV = anAdjustedPoint.Y(); | |
3986 | ||
3987 | if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) && | |
3988 | ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) { | |
3989 | // attempt to roughly re-compute point | |
3990 | foundU = ( foundU < umin ) ? umin : foundU; | |
3991 | foundU = ( foundU > umax ) ? umax : foundU; | |
3992 | foundV = ( foundV < vmin ) ? vmin : foundV; | |
3993 | foundV = ( foundV > vmax ) ? vmax : foundV; | |
3994 | ||
3995 | GeomAPI_ProjectPointOnSurf& aProjector2 = | |
3996 | (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2); | |
3997 | ||
3998 | aP3d = aSurfaceOther->Value(foundU, foundV); | |
3999 | aProjector2.Perform(aP3d); | |
4000 | ||
4001 | if(aProjector2.IsDone()) { | |
4002 | if(aProjector2.LowerDistance() < aCriteria) { | |
4003 | Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y(); | |
4004 | aProjector2.LowerDistanceParameters(foundU2, foundV2); | |
4005 | anewpoint.SetX(foundU2); | |
4006 | anewpoint.SetY(foundV2); | |
4007 | } | |
4008 | } | |
4009 | } | |
4010 | //Correction of projected coordinates. End | |
4011 | ||
4012 | if(surfit == 0) | |
4013 | aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV); | |
4014 | else | |
4015 | aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y()); | |
4016 | } | |
4017 | } | |
4018 | } | |
4019 | } | |
7fd59977 | 4020 | } |
4021 | aSeqOfPntOn2S->Add(aNewP); | |
4022 | aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints()); | |
4023 | } | |
4024 | anArrayOfLineEnds.SetValue(i, aListOfFLIndex); | |
4025 | } | |
4026 | // Correct wlines.end | |
4027 | ||
4028 | // Split wlines.begin | |
4029 | Standard_Integer nbiter; | |
4030 | // | |
4031 | nbiter=1; | |
4032 | if (!bAvoidLineConstructor) { | |
4033 | nbiter=theLConstructor.NbParts(); | |
4034 | } | |
4035 | // | |
4036 | for(j = 1; j <= nbiter; ++j) { | |
4037 | Standard_Real fprm, lprm; | |
4038 | Standard_Integer ifprm, ilprm; | |
4039 | // | |
4040 | if(bAvoidLineConstructor) { | |
4041 | ifprm = 1; | |
4042 | ilprm = theWLine->NbPnts(); | |
4043 | } | |
4044 | else { | |
4045 | theLConstructor.Part(j, fprm, lprm); | |
4046 | ifprm = (Standard_Integer)fprm; | |
4047 | ilprm = (Standard_Integer)lprm; | |
4048 | } | |
4049 | ||
4050 | Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S(); | |
4051 | // | |
4052 | for(i = 1; i <= nblines; i++) { | |
4053 | if(anArrayOfLineType.Value(i) != 0) { | |
655fddc8 | 4054 | continue; |
7fd59977 | 4055 | } |
4056 | const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i); | |
7fd59977 | 4057 | const TColStd_ListOfInteger& aListOfFLIndex = anArrayOfLineEnds.Value(i); |
4058 | Standard_Boolean bhasfirstpoint = (aListOfFLIndex.Extent() == 2); | |
4059 | Standard_Boolean bhaslastpoint = (aListOfFLIndex.Extent() == 2); | |
4060 | ||
4061 | if(!bhasfirstpoint && !aListOfFLIndex.IsEmpty()) { | |
655fddc8 | 4062 | bhasfirstpoint = (i != 1); |
7fd59977 | 4063 | } |
4064 | ||
4065 | if(!bhaslastpoint && !aListOfFLIndex.IsEmpty()) { | |
655fddc8 | 4066 | bhaslastpoint = (i != nblines); |
7fd59977 | 4067 | } |
b1574471 | 4068 | |
4069 | Standard_Integer iFirst = aListOfIndex.First(); | |
4070 | Standard_Integer iLast = aListOfIndex.Last(); | |
4071 | Standard_Boolean bIsFirstInside = ((ifprm >= iFirst) && (ifprm <= iLast)); | |
4072 | Standard_Boolean bIsLastInside = ((ilprm >= iFirst) && (ilprm <= iLast)); | |
7fd59977 | 4073 | |
4074 | if(!bIsFirstInside && !bIsLastInside) { | |
b1574471 | 4075 | if((ifprm < iFirst) && (ilprm > iLast)) { |
655fddc8 | 4076 | // append whole line, and boundaries if neccesary |
4077 | if(bhasfirstpoint) { | |
b1574471 | 4078 | pit = aListOfFLIndex.First(); |
4079 | const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit); | |
655fddc8 | 4080 | aLineOn2S->Add(aP); |
4081 | } | |
4082 | TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex); | |
4083 | ||
4084 | for(; anIt.More(); anIt.Next()) { | |
b1574471 | 4085 | pit = anIt.Value(); |
4086 | const IntSurf_PntOn2S& aP = theWLine->Point(pit); | |
655fddc8 | 4087 | aLineOn2S->Add(aP); |
4088 | } | |
4089 | ||
4090 | if(bhaslastpoint) { | |
b1574471 | 4091 | pit = aListOfFLIndex.Last(); |
4092 | const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit); | |
655fddc8 | 4093 | aLineOn2S->Add(aP); |
4094 | } | |
4095 | ||
4096 | // check end of split line (end is almost always) | |
4097 | Standard_Integer aneighbour = i + 1; | |
4098 | Standard_Boolean bIsEndOfLine = Standard_True; | |
4099 | ||
4100 | if(aneighbour <= nblines) { | |
4101 | const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour); | |
4102 | ||
4103 | if((anArrayOfLineType.Value(aneighbour) != 0) && | |
4104 | (aListOfNeighbourIndex.IsEmpty())) { | |
4105 | bIsEndOfLine = Standard_False; | |
4106 | } | |
4107 | } | |
4108 | ||
4109 | if(bIsEndOfLine) { | |
4110 | if(aLineOn2S->NbPoints() > 1) { | |
4111 | Handle(IntPatch_WLine) aNewWLine = | |
4112 | new IntPatch_WLine(aLineOn2S, Standard_False); | |
4113 | theNewLines.Append(aNewWLine); | |
4114 | } | |
4115 | aLineOn2S = new IntSurf_LineOn2S(); | |
4116 | } | |
4117 | } | |
4118 | continue; | |
7fd59977 | 4119 | } |
4120 | // end if(!bIsFirstInside && !bIsLastInside) | |
4121 | ||
4122 | if(bIsFirstInside && bIsLastInside) { | |
655fddc8 | 4123 | // append inside points between ifprm and ilprm |
4124 | TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex); | |
4125 | ||
4126 | for(; anIt.More(); anIt.Next()) { | |
b1574471 | 4127 | pit = anIt.Value(); |
4128 | if((pit < ifprm) || (pit > ilprm)) | |
655fddc8 | 4129 | continue; |
b1574471 | 4130 | const IntSurf_PntOn2S& aP = theWLine->Point(pit); |
655fddc8 | 4131 | aLineOn2S->Add(aP); |
4132 | } | |
7fd59977 | 4133 | } |
4134 | else { | |
4135 | ||
655fddc8 | 4136 | if(bIsFirstInside) { |
4137 | // append points from ifprm to last point + boundary point | |
4138 | TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex); | |
4139 | ||
4140 | for(; anIt.More(); anIt.Next()) { | |
b1574471 | 4141 | pit = anIt.Value(); |
4142 | if(pit < ifprm) | |
655fddc8 | 4143 | continue; |
b1574471 | 4144 | const IntSurf_PntOn2S& aP = theWLine->Point(pit); |
655fddc8 | 4145 | aLineOn2S->Add(aP); |
4146 | } | |
4147 | ||
4148 | if(bhaslastpoint) { | |
b1574471 | 4149 | pit = aListOfFLIndex.Last(); |
4150 | const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit); | |
655fddc8 | 4151 | aLineOn2S->Add(aP); |
4152 | } | |
4153 | // check end of split line (end is almost always) | |
4154 | Standard_Integer aneighbour = i + 1; | |
4155 | Standard_Boolean bIsEndOfLine = Standard_True; | |
4156 | ||
4157 | if(aneighbour <= nblines) { | |
4158 | const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour); | |
4159 | ||
4160 | if((anArrayOfLineType.Value(aneighbour) != 0) && | |
4161 | (aListOfNeighbourIndex.IsEmpty())) { | |
4162 | bIsEndOfLine = Standard_False; | |
4163 | } | |
4164 | } | |
4165 | ||
4166 | if(bIsEndOfLine) { | |
4167 | if(aLineOn2S->NbPoints() > 1) { | |
4168 | Handle(IntPatch_WLine) aNewWLine = | |
4169 | new IntPatch_WLine(aLineOn2S, Standard_False); | |
4170 | theNewLines.Append(aNewWLine); | |
4171 | } | |
4172 | aLineOn2S = new IntSurf_LineOn2S(); | |
4173 | } | |
4174 | } | |
4175 | // end if(bIsFirstInside) | |
4176 | ||
4177 | if(bIsLastInside) { | |
4178 | // append points from first boundary point to ilprm | |
4179 | if(bhasfirstpoint) { | |
b1574471 | 4180 | pit = aListOfFLIndex.First(); |
4181 | const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit); | |
655fddc8 | 4182 | aLineOn2S->Add(aP); |
4183 | } | |
4184 | TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex); | |
4185 | ||
4186 | for(; anIt.More(); anIt.Next()) { | |
b1574471 | 4187 | pit = anIt.Value(); |
4188 | if(pit > ilprm) | |
655fddc8 | 4189 | continue; |
b1574471 | 4190 | const IntSurf_PntOn2S& aP = theWLine->Point(pit); |
655fddc8 | 4191 | aLineOn2S->Add(aP); |
4192 | } | |
4193 | } | |
4194 | //end if(bIsLastInside) | |
7fd59977 | 4195 | } |
4196 | } | |
4197 | ||
4198 | if(aLineOn2S->NbPoints() > 1) { | |
4199 | Handle(IntPatch_WLine) aNewWLine = | |
655fddc8 | 4200 | new IntPatch_WLine(aLineOn2S, Standard_False); |
7fd59977 | 4201 | theNewLines.Append(aNewWLine); |
4202 | } | |
4203 | } | |
4204 | // Split wlines.end | |
4205 | ||
4206 | return Standard_True; | |
4207 | } | |
4208 | ||
4209 | // ------------------------------------------------------------------------------------------------ | |
4210 | // static function: ParameterOutOfBoundary | |
4211 | // purpose: Computes a new parameter for given curve. The corresponding 2d points | |
0fc4f2e2 | 4212 | // does not lay on any boundary of given faces |
7fd59977 | 4213 | // ------------------------------------------------------------------------------------------------ |
4214 | Standard_Boolean ParameterOutOfBoundary(const Standard_Real theParameter, | |
655fddc8 | 4215 | const Handle(Geom_Curve)& theCurve, |
4216 | const TopoDS_Face& theFace1, | |
4217 | const TopoDS_Face& theFace2, | |
4218 | const Standard_Real theOtherParameter, | |
4219 | const Standard_Boolean bIncreasePar, | |
4220 | Standard_Real& theNewParameter, | |
1e143abb | 4221 | const Handle(IntTools_Context)& aContext) |
4f189102 | 4222 | { |
7fd59977 | 4223 | Standard_Boolean bIsComputed = Standard_False; |
4224 | theNewParameter = theParameter; | |
4225 | ||
7fd59977 | 4226 | Standard_Real acurpar = theParameter; |
4227 | TopAbs_State aState = TopAbs_ON; | |
4228 | Standard_Integer iter = 0; | |
4229 | Standard_Real asumtol = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2); | |
4230 | Standard_Real adelta = asumtol * 0.1; | |
4231 | adelta = (adelta < Precision::Confusion()) ? Precision::Confusion() : adelta; | |
4232 | Handle(Geom_Surface) aSurf1 = BRep_Tool::Surface(theFace1); | |
4233 | Handle(Geom_Surface) aSurf2 = BRep_Tool::Surface(theFace2); | |
4234 | ||
4235 | Standard_Real u1, u2, v1, v2; | |
4236 | ||
4237 | GeomAPI_ProjectPointOnSurf aPrj1; | |
4238 | aSurf1->Bounds(u1, u2, v1, v2); | |
4239 | aPrj1.Init(aSurf1, u1, u2, v1, v2); | |
4240 | ||
4241 | GeomAPI_ProjectPointOnSurf aPrj2; | |
4242 | aSurf2->Bounds(u1, u2, v1, v2); | |
4243 | aPrj2.Init(aSurf2, u1, u2, v1, v2); | |
4244 | ||
4245 | while(aState == TopAbs_ON) { | |
4246 | if(bIncreasePar) | |
4247 | acurpar += adelta; | |
4248 | else | |
4249 | acurpar -= adelta; | |
4250 | gp_Pnt aPCurrent = theCurve->Value(acurpar); | |
4251 | aPrj1.Perform(aPCurrent); | |
4252 | Standard_Real U=0., V=0.; | |
4253 | ||
4254 | if(aPrj1.IsDone()) { | |
4255 | aPrj1.LowerDistanceParameters(U, V); | |
4f189102 | 4256 | aState = aContext->StatePointFace(theFace1, gp_Pnt2d(U, V)); |
7fd59977 | 4257 | } |
4258 | ||
4259 | if(aState != TopAbs_ON) { | |
4260 | aPrj2.Perform(aPCurrent); | |
655fddc8 | 4261 | |
7fd59977 | 4262 | if(aPrj2.IsDone()) { |
655fddc8 | 4263 | aPrj2.LowerDistanceParameters(U, V); |
4264 | aState = aContext->StatePointFace(theFace2, gp_Pnt2d(U, V)); | |
7fd59977 | 4265 | } |
4266 | } | |
4267 | ||
4268 | if(iter > 11) { | |
4269 | break; | |
4270 | } | |
4271 | iter++; | |
4272 | } | |
4273 | ||
4274 | if(iter <= 11) { | |
4275 | theNewParameter = acurpar; | |
4276 | bIsComputed = Standard_True; | |
4277 | ||
4278 | if(bIncreasePar) { | |
4279 | if(acurpar >= theOtherParameter) | |
655fddc8 | 4280 | theNewParameter = theOtherParameter; |
7fd59977 | 4281 | } |
4282 | else { | |
4283 | if(acurpar <= theOtherParameter) | |
655fddc8 | 4284 | theNewParameter = theOtherParameter; |
7fd59977 | 4285 | } |
4286 | } | |
4287 | return bIsComputed; | |
4288 | } | |
4289 | ||
0fc4f2e2 P |
4290 | //======================================================================= |
4291 | //function : IsCurveValid | |
4292 | //purpose : | |
4293 | //======================================================================= | |
7fd59977 | 4294 | Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve) |
4295 | { | |
4296 | if(thePCurve.IsNull()) | |
4297 | return Standard_False; | |
4298 | ||
4299 | Standard_Real tolint = 1.e-10; | |
4300 | Geom2dAdaptor_Curve PCA; | |
4301 | IntRes2d_Domain PCD; | |
4302 | Geom2dInt_GInter PCI; | |
4303 | ||
4304 | Standard_Real pf = 0., pl = 0.; | |
4305 | gp_Pnt2d pntf, pntl; | |
4306 | ||
4307 | if(!thePCurve->IsClosed() && !thePCurve->IsPeriodic()) { | |
4308 | pf = thePCurve->FirstParameter(); | |
4309 | pl = thePCurve->LastParameter(); | |
4310 | pntf = thePCurve->Value(pf); | |
4311 | pntl = thePCurve->Value(pl); | |
4312 | PCA.Load(thePCurve); | |
4313 | if(!PCA.IsPeriodic()) { | |
4314 | if(PCA.FirstParameter() > pf) pf = PCA.FirstParameter(); | |
4315 | if(PCA.LastParameter() < pl) pl = PCA.LastParameter(); | |
4316 | } | |
4317 | PCD.SetValues(pntf,pf,tolint,pntl,pl,tolint); | |
4318 | PCI.Perform(PCA,PCD,tolint,tolint); | |
4319 | if(PCI.IsDone()) | |
4320 | if(PCI.NbPoints() > 0) { | |
4321 | return Standard_False; | |
4322 | } | |
4323 | } | |
4324 | ||
4325 | return Standard_True; | |
4326 | } | |
4327 | ||
4328 | //======================================================================= | |
4329 | //static function : ApproxWithPCurves | |
4330 | //purpose : for bug 20964 only | |
4331 | //======================================================================= | |
7fd59977 | 4332 | Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl, |
655fddc8 | 4333 | const gp_Sphere& theSph) |
7fd59977 | 4334 | { |
4335 | Standard_Boolean bRes = Standard_True; | |
4336 | Standard_Real R1 = theCyl.Radius(), R2 = theSph.Radius(); | |
59495dbe | 4337 | // |
4338 | { | |
4339 | Standard_Real aD2, aRc2, aEps; | |
4340 | gp_Pnt aApexSph; | |
4341 | // | |
4342 | aEps=1.E-7; | |
4343 | aRc2=R1*R1; | |
4344 | // | |
4345 | const gp_Ax3& aAx3Sph=theSph.Position(); | |
4346 | const gp_Pnt& aLocSph=aAx3Sph.Location(); | |
4347 | const gp_Dir& aDirSph=aAx3Sph.Direction(); | |
4348 | // | |
4349 | const gp_Ax1& aAx1Cyl=theCyl.Axis(); | |
4350 | gp_Lin aLinCyl(aAx1Cyl); | |
4351 | // | |
4352 | aApexSph.SetXYZ(aLocSph.XYZ()+R2*aDirSph.XYZ()); | |
4353 | aD2=aLinCyl.SquareDistance(aApexSph); | |
4354 | if (fabs(aD2-aRc2)<aEps) { | |
4355 | return !bRes; | |
4356 | } | |
4357 | // | |
4358 | aApexSph.SetXYZ(aLocSph.XYZ()-R2*aDirSph.XYZ()); | |
4359 | aD2=aLinCyl.SquareDistance(aApexSph); | |
4360 | if (fabs(aD2-aRc2)<aEps) { | |
4361 | return !bRes; | |
4362 | } | |
4363 | } | |
4364 | // | |
4365 | ||
4366 | if(R1 < 2.*R2) { | |
4367 | return bRes; | |
4368 | } | |
7fd59977 | 4369 | gp_Lin anCylAx(theCyl.Axis()); |
4370 | ||
4371 | Standard_Real aDist = anCylAx.Distance(theSph.Location()); | |
4372 | Standard_Real aDRel = Abs(aDist - R1)/R2; | |
4373 | ||
4374 | if(aDRel > .2) return bRes; | |
4375 | ||
4376 | Standard_Real par = ElCLib::Parameter(anCylAx, theSph.Location()); | |
4377 | gp_Pnt aP = ElCLib::Value(par, anCylAx); | |
4378 | gp_Vec aV(aP, theSph.Location()); | |
4379 | ||
4380 | Standard_Real dd = aV.Dot(theSph.Position().XDirection()); | |
4381 | ||
4382 | if(aDist < R1 && dd > 0.) return Standard_False; | |
4383 | if(aDist > R1 && dd < 0.) return Standard_False; | |
4384 | ||
4385 | ||
4386 | return bRes; | |
4387 | } | |
7fd59977 | 4388 | //======================================================================= |
4389 | //function : PerformPlanes | |
4390 | //purpose : | |
4391 | //======================================================================= | |
7fd59977 | 4392 | void PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1, |
655fddc8 | 4393 | const Handle(GeomAdaptor_HSurface)& theS2, |
4394 | const Standard_Real TolAng, | |
4395 | const Standard_Real TolTang, | |
4396 | const Standard_Boolean theApprox1, | |
4397 | const Standard_Boolean theApprox2, | |
4398 | IntTools_SequenceOfCurves& theSeqOfCurve, | |
4399 | Standard_Boolean& theTangentFaces) | |
7fd59977 | 4400 | { |
4401 | ||
4402 | gp_Pln aPln1 = theS1->Surface().Plane(); | |
4403 | gp_Pln aPln2 = theS2->Surface().Plane(); | |
4404 | ||
4405 | IntAna_QuadQuadGeo aPlnInter(aPln1, aPln2, TolAng, TolTang); | |
4406 | ||
4407 | if(!aPlnInter.IsDone()) { | |
4408 | theTangentFaces = Standard_False; | |
4409 | return; | |
4410 | } | |
4411 | ||
4412 | IntAna_ResultType aResType = aPlnInter.TypeInter(); | |
4413 | ||
4414 | if(aResType == IntAna_Same) { | |
4415 | theTangentFaces = Standard_True; | |
4416 | return; | |
4417 | } | |
4418 | ||
4419 | theTangentFaces = Standard_False; | |
4420 | ||
4421 | if(aResType == IntAna_Empty) { | |
4422 | return; | |
4423 | } | |
4424 | ||
4425 | gp_Lin aLin = aPlnInter.Line(1); | |
4426 | ||
4427 | ProjLib_Plane aProj; | |
4428 | ||
4429 | aProj.Init(aPln1); | |
4430 | aProj.Project(aLin); | |
4431 | gp_Lin2d aLin2d1 = aProj.Line(); | |
4432 | // | |
4433 | aProj.Init(aPln2); | |
4434 | aProj.Project(aLin); | |
4435 | gp_Lin2d aLin2d2 = aProj.Line(); | |
4436 | // | |
4437 | //classify line2d1 relatively first plane | |
4438 | Standard_Real P11, P12; | |
4439 | Standard_Boolean IsCrossed = ClassifyLin2d(theS1, aLin2d1, TolTang, P11, P12); | |
4440 | if(!IsCrossed) return; | |
4441 | //classify line2d2 relatively second plane | |
4442 | Standard_Real P21, P22; | |
4443 | IsCrossed = ClassifyLin2d(theS2, aLin2d2, TolTang, P21, P22); | |
4444 | if(!IsCrossed) return; | |
4445 | ||
4446 | //Analysis of parametric intervals: must have common part | |
4447 | ||
4448 | if(P21 >= P12) return; | |
4449 | if(P22 <= P11) return; | |
4450 | ||
4451 | Standard_Real pmin, pmax; | |
4452 | pmin = Max(P11, P21); | |
4453 | pmax = Min(P12, P22); | |
4454 | ||
4455 | if(pmax - pmin <= TolTang) return; | |
4456 | ||
4457 | Handle(Geom_Line) aGLin = new Geom_Line(aLin); | |
4458 | ||
4459 | IntTools_Curve aCurve; | |
4460 | Handle(Geom_TrimmedCurve) aGTLin = new Geom_TrimmedCurve(aGLin, pmin, pmax); | |
4461 | ||
4462 | aCurve.SetCurve(aGTLin); | |
4463 | ||
4464 | if(theApprox1) { | |
4465 | Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d1); | |
4466 | aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax)); | |
4467 | } | |
4468 | else { | |
4469 | Handle(Geom2d_Curve) H1; | |
4470 | aCurve.SetFirstCurve2d(H1); | |
4471 | } | |
4472 | if(theApprox2) { | |
4473 | Handle(Geom2d_Line) C2d = new Geom2d_Line(aLin2d2); | |
4474 | aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d, pmin, pmax)); | |
4475 | } | |
4476 | else { | |
4477 | Handle(Geom2d_Curve) H1; | |
4478 | aCurve.SetFirstCurve2d(H1); | |
4479 | } | |
4480 | ||
4481 | theSeqOfCurve.Append(aCurve); | |
4482 | ||
4483 | } | |
4484 | ||
4485 | //======================================================================= | |
4486 | //function : ClassifyLin2d | |
4487 | //purpose : | |
4488 | //======================================================================= | |
4489 | static inline Standard_Boolean INTER(const Standard_Real d1, | |
655fddc8 | 4490 | const Standard_Real d2, |
4491 | const Standard_Real tol) | |
7fd59977 | 4492 | { |
4493 | return (d1 > tol && d2 < -tol) || | |
4494 | (d1 < -tol && d2 > tol) || | |
4495 | ((d1 <= tol && d1 >= -tol) && (d2 > tol || d2 < -tol)) || | |
4496 | ((d2 <= tol && d2 >= -tol) && (d1 > tol || d1 < -tol)); | |
4497 | } | |
4498 | static inline Standard_Boolean COINC(const Standard_Real d1, | |
655fddc8 | 4499 | const Standard_Real d2, |
4500 | const Standard_Real tol) | |
7fd59977 | 4501 | { |
4502 | return (d1 <= tol && d1 >= -tol) && (d2 <= tol && d2 >= -tol); | |
4503 | } | |
4504 | Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS, | |
655fddc8 | 4505 | const gp_Lin2d& theLin2d, |
4506 | const Standard_Real theTol, | |
4507 | Standard_Real& theP1, | |
4508 | Standard_Real& theP2) | |
7fd59977 | 4509 | |
4510 | { | |
4511 | Standard_Real xmin, xmax, ymin, ymax, d1, d2, A, B, C; | |
4512 | Standard_Real par[2]; | |
4513 | Standard_Integer nbi = 0; | |
4514 | ||
4515 | xmin = theS->Surface().FirstUParameter(); | |
4516 | xmax = theS->Surface().LastUParameter(); | |
4517 | ymin = theS->Surface().FirstVParameter(); | |
4518 | ymax = theS->Surface().LastVParameter(); | |
4519 | ||
4520 | theLin2d.Coefficients(A, B, C); | |
4521 | ||
4522 | //xmin, ymin <-> xmin, ymax | |
4523 | d1 = A*xmin + B*ymin + C; | |
4524 | d2 = A*xmin + B*ymax + C; | |
4525 | ||
4526 | if(INTER(d1, d2, theTol)) { | |
4527 | //Intersection with boundary | |
4528 | Standard_Real y = -(C + A*xmin)/B; | |
4529 | par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, y)); | |
4530 | nbi++; | |
4531 | } | |
4532 | else if (COINC(d1, d2, theTol)) { | |
4533 | //Coincidence with boundary | |
4534 | par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin)); | |
4535 | par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax)); | |
4536 | nbi = 2; | |
4537 | } | |
4538 | ||
4539 | if(nbi == 2) { | |
4540 | ||
4541 | if(fabs(par[0]-par[1]) > theTol) { | |
4542 | theP1 = Min(par[0], par[1]); | |
4543 | theP2 = Max(par[0], par[1]); | |
4544 | return Standard_True; | |
4545 | } | |
4546 | else return Standard_False; | |
4547 | ||
4548 | } | |
4549 | ||
4550 | //xmin, ymax <-> xmax, ymax | |
4551 | d1 = d2; | |
4552 | d2 = A*xmax + B*ymax + C; | |
4553 | ||
4554 | if(d1 > theTol || d1 < -theTol) {//to avoid checking of | |
4555 | //coincidence with the same point | |
4556 | if(INTER(d1, d2, theTol)) { | |
4557 | Standard_Real x = -(C + B*ymax)/A; | |
4558 | par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymax)); | |
4559 | nbi++; | |
4560 | } | |
4561 | else if (COINC(d1, d2, theTol)) { | |
4562 | par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymax)); | |
4563 | par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax)); | |
4564 | nbi = 2; | |
4565 | } | |
4566 | } | |
4567 | ||
4568 | if(nbi == 2) { | |
4569 | ||
4570 | if(fabs(par[0]-par[1]) > theTol) { | |
4571 | theP1 = Min(par[0], par[1]); | |
4572 | theP2 = Max(par[0], par[1]); | |
4573 | return Standard_True; | |
4574 | } | |
4575 | else return Standard_False; | |
4576 | ||
4577 | } | |
4578 | ||
4579 | //xmax, ymax <-> xmax, ymin | |
4580 | d1 = d2; | |
4581 | d2 = A*xmax + B*ymin + C; | |
4582 | ||
4583 | if(d1 > theTol || d1 < -theTol) { | |
4584 | if(INTER(d1, d2, theTol)) { | |
4585 | Standard_Real y = -(C + A*xmax)/B; | |
4586 | par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, y)); | |
4587 | nbi++; | |
4588 | } | |
4589 | else if (COINC(d1, d2, theTol)) { | |
4590 | par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymax)); | |
4591 | par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin)); | |
4592 | nbi = 2; | |
4593 | } | |
4594 | } | |
4595 | ||
4596 | if(nbi == 2) { | |
4597 | if(fabs(par[0]-par[1]) > theTol) { | |
4598 | theP1 = Min(par[0], par[1]); | |
4599 | theP2 = Max(par[0], par[1]); | |
4600 | return Standard_True; | |
4601 | } | |
4602 | else return Standard_False; | |
4603 | } | |
4604 | ||
4605 | //xmax, ymin <-> xmin, ymin | |
4606 | d1 = d2; | |
4607 | d2 = A*xmin + B*ymin + C; | |
4608 | ||
4609 | if(d1 > theTol || d1 < -theTol) { | |
4610 | if(INTER(d1, d2, theTol)) { | |
4611 | Standard_Real x = -(C + B*ymin)/A; | |
4612 | par[nbi] = ElCLib::Parameter(theLin2d, gp_Pnt2d(x, ymin)); | |
4613 | nbi++; | |
4614 | } | |
4615 | else if (COINC(d1, d2, theTol)) { | |
4616 | par[0] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmax, ymin)); | |
4617 | par[1] = ElCLib::Parameter(theLin2d, gp_Pnt2d(xmin, ymin)); | |
4618 | nbi = 2; | |
4619 | } | |
4620 | } | |
4621 | ||
4622 | if(nbi == 2) { | |
4623 | if(fabs(par[0]-par[1]) > theTol) { | |
4624 | theP1 = Min(par[0], par[1]); | |
4625 | theP2 = Max(par[0], par[1]); | |
4626 | return Standard_True; | |
4627 | } | |
4628 | else return Standard_False; | |
4629 | } | |
4630 | ||
4631 | return Standard_False; | |
4632 | ||
4633 | } | |
4634 | // | |
7fd59977 | 4635 | //======================================================================= |
4636 | //function : ApproxParameters | |
4637 | //purpose : | |
4638 | //======================================================================= | |
4639 | void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1, | |
655fddc8 | 4640 | const Handle(GeomAdaptor_HSurface)& aHS2, |
4641 | Standard_Integer& iDegMin, | |
4642 | Standard_Integer& iDegMax, | |
4643 | Standard_Integer& iNbIter) | |
4f189102 | 4644 | |
7fd59977 | 4645 | { |
4646 | GeomAbs_SurfaceType aTS1, aTS2; | |
0fc4f2e2 | 4647 | |
7fd59977 | 4648 | // |
4f189102 | 4649 | iNbIter=0; |
7fd59977 | 4650 | iDegMin=4; |
4651 | iDegMax=8; | |
7fd59977 | 4652 | // |
4653 | aTS1=aHS1->Surface().GetType(); | |
4654 | aTS2=aHS2->Surface().GetType(); | |
4655 | // | |
4656 | // Cylinder/Torus | |
4657 | if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) || | |
4658 | (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) { | |
0fc4f2e2 | 4659 | Standard_Real aRC, aRT, dR, aPC; |
7fd59977 | 4660 | gp_Cylinder aCylinder; |
4661 | gp_Torus aTorus; | |
4662 | // | |
4663 | aPC=Precision::Confusion(); | |
4664 | // | |
0fc4f2e2 P |
4665 | aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder(); |
4666 | aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus(); | |
7fd59977 | 4667 | // |
4668 | aRC=aCylinder.Radius(); | |
4669 | aRT=aTorus.MinorRadius(); | |
4670 | dR=aRC-aRT; | |
4671 | if (dR<0.) { | |
4672 | dR=-dR; | |
4673 | } | |
4674 | // | |
4675 | if (dR<aPC) { | |
0fc4f2e2 P |
4676 | iDegMax=6; |
4677 | } | |
4678 | } | |
4f189102 | 4679 | if (aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Cylinder) { |
8e0115e4 | 4680 | iNbIter=1; |
4f189102 | 4681 | } |
0fc4f2e2 P |
4682 | } |
4683 | //======================================================================= | |
4684 | //function : Tolerances | |
4685 | //purpose : | |
4686 | //======================================================================= | |
4687 | void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1, | |
655fddc8 | 4688 | const Handle(GeomAdaptor_HSurface)& aHS2, |
788cbaf4 | 4689 | Standard_Real& aTolTang) |
0fc4f2e2 P |
4690 | { |
4691 | GeomAbs_SurfaceType aTS1, aTS2; | |
4692 | // | |
4693 | aTS1=aHS1->Surface().GetType(); | |
4694 | aTS2=aHS2->Surface().GetType(); | |
4695 | // | |
4696 | // Cylinder/Torus | |
4697 | if ((aTS1==GeomAbs_Cylinder && aTS2==GeomAbs_Torus) || | |
4698 | (aTS2==GeomAbs_Cylinder && aTS1==GeomAbs_Torus)) { | |
4699 | Standard_Real aRC, aRT, dR, aPC; | |
4700 | gp_Cylinder aCylinder; | |
4701 | gp_Torus aTorus; | |
4702 | // | |
4703 | aPC=Precision::Confusion(); | |
4704 | // | |
4705 | aCylinder=(aTS1==GeomAbs_Cylinder)? aHS1->Surface().Cylinder() : aHS2->Surface().Cylinder(); | |
4706 | aTorus=(aTS1==GeomAbs_Torus)? aHS1->Surface().Torus() : aHS2->Surface().Torus(); | |
4707 | // | |
4708 | aRC=aCylinder.Radius(); | |
4709 | aRT=aTorus.MinorRadius(); | |
4710 | dR=aRC-aRT; | |
4711 | if (dR<0.) { | |
4712 | dR=-dR; | |
7fd59977 | 4713 | } |
0fc4f2e2 P |
4714 | // |
4715 | if (dR<aPC) { | |
4716 | aTolTang=0.1*aTolTang; | |
4717 | } | |
4718 | } | |
4719 | } | |
0fc4f2e2 P |
4720 | //======================================================================= |
4721 | //function : SortTypes | |
4722 | //purpose : | |
4723 | //======================================================================= | |
4724 | Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1, | |
655fddc8 | 4725 | const GeomAbs_SurfaceType aType2) |
0fc4f2e2 P |
4726 | { |
4727 | Standard_Boolean bRet; | |
4728 | Standard_Integer aI1, aI2; | |
4729 | // | |
4730 | bRet=Standard_False; | |
4731 | // | |
4732 | aI1=IndexType(aType1); | |
4733 | aI2=IndexType(aType2); | |
4734 | if (aI1<aI2){ | |
4735 | bRet=!bRet; | |
4736 | } | |
4737 | return bRet; | |
4738 | } | |
4739 | //======================================================================= | |
4740 | //function : IndexType | |
4741 | //purpose : | |
4742 | //======================================================================= | |
4743 | Standard_Integer IndexType(const GeomAbs_SurfaceType aType) | |
4744 | { | |
4745 | Standard_Integer aIndex; | |
4746 | // | |
4747 | aIndex=11; | |
4748 | // | |
4749 | if (aType==GeomAbs_Plane) { | |
4750 | aIndex=0; | |
7fd59977 | 4751 | } |
0fc4f2e2 P |
4752 | else if (aType==GeomAbs_Cylinder) { |
4753 | aIndex=1; | |
4754 | } | |
4755 | else if (aType==GeomAbs_Cone) { | |
4756 | aIndex=2; | |
4757 | } | |
4758 | else if (aType==GeomAbs_Sphere) { | |
4759 | aIndex=3; | |
4760 | } | |
4761 | else if (aType==GeomAbs_Torus) { | |
4762 | aIndex=4; | |
4763 | } | |
4764 | else if (aType==GeomAbs_BezierSurface) { | |
4765 | aIndex=5; | |
4766 | } | |
4767 | else if (aType==GeomAbs_BSplineSurface) { | |
4768 | aIndex=6; | |
4769 | } | |
4770 | else if (aType==GeomAbs_SurfaceOfRevolution) { | |
4771 | aIndex=7; | |
4772 | } | |
4773 | else if (aType==GeomAbs_SurfaceOfExtrusion) { | |
4774 | aIndex=8; | |
4775 | } | |
4776 | else if (aType==GeomAbs_OffsetSurface) { | |
4777 | aIndex=9; | |
4778 | } | |
4779 | else if (aType==GeomAbs_OtherSurface) { | |
4780 | aIndex=10; | |
4781 | } | |
4782 | return aIndex; | |
7fd59977 | 4783 | } |
0797d9d3 | 4784 | #ifdef OCCT_DEBUG_DUMPWLINE |
a2eede02 P |
4785 | //======================================================================= |
4786 | //function : DumpWLine | |
4787 | //purpose : | |
4788 | //======================================================================= | |
4789 | void DumpWLine(const Handle(IntPatch_WLine)& aWLine) | |
4790 | { | |
4791 | Standard_Integer i, aNbPnts; | |
4792 | Standard_Real aX, aY, aZ, aU1, aV1, aU2, aV2; | |
4793 | // | |
4f189102 | 4794 | printf(" *WLine\n"); |
a2eede02 P |
4795 | aNbPnts=aWLine->NbPnts(); |
4796 | for (i=1; i<=aNbPnts; ++i) { | |
4797 | const IntSurf_PntOn2S aPntOn2S=aWLine->Point(i); | |
4798 | const gp_Pnt& aP3D=aPntOn2S.Value(); | |
4799 | aP3D.Coord(aX, aY, aZ); | |
4800 | aPntOn2S.Parameters(aU1, aV1, aU2, aV2); | |
4801 | // | |
4f189102 P |
4802 | printf("point p_%d %lf %lf %lf\n", i, aX, aY, aZ); |
4803 | //printf("point p_%d %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf\n", | |
655fddc8 | 4804 | // i, aX, aY, aZ, aU1, aV1, aU2, aV2); |
a2eede02 P |
4805 | } |
4806 | } | |
4e18e72a | 4807 | #endif |
fa9681ca P |
4808 | //======================================================================= |
4809 | //function : RefineVector | |
4810 | //purpose : | |
4811 | //======================================================================= | |
4812 | void RefineVector(gp_Vec2d& aV2D) | |
4813 | { | |
4814 | Standard_Integer k,m; | |
4815 | Standard_Real aC[2], aEps, aR1, aR2, aNum; | |
4816 | // | |
4817 | aEps=RealEpsilon(); | |
4818 | aR1=1.-aEps; | |
4819 | aR2=1.+aEps; | |
4820 | // | |
4821 | aV2D.Coord(aC[0], aC[1]); | |
4822 | // | |
4823 | for (k=0; k<2; ++k) { | |
4824 | m=(k+1)%2; | |
4825 | aNum=fabs(aC[k]); | |
4826 | if (aNum>aR1 && aNum<aR2) { | |
4827 | if (aC[k]<0.) { | |
655fddc8 | 4828 | aC[k]=-1.; |
4829 | } | |
fa9681ca | 4830 | else { |
655fddc8 | 4831 | aC[k]=1.; |
fa9681ca P |
4832 | } |
4833 | aC[m]=0.; | |
4834 | break; | |
4835 | } | |
4836 | } | |
4837 | aV2D.SetCoord(aC[0], aC[1]); | |
37b6f439 | 4838 | } |
4839 | //======================================================================= | |
1b7ae951 | 4840 | // Function : FindMaxDistance |
4841 | // purpose : | |
37b6f439 | 4842 | //======================================================================= |
1b7ae951 | 4843 | Standard_Real FindMaxDistance(const Handle(Geom_Curve)& theCurve, |
4844 | const Standard_Real theFirst, | |
4845 | const Standard_Real theLast, | |
4846 | const TopoDS_Face& theFace, | |
4847 | const Handle(IntTools_Context)& theContext) | |
37b6f439 | 4848 | { |
1b7ae951 | 4849 | Standard_Integer aNbS; |
4850 | Standard_Real aT1, aT2, aDt, aD, aDMax, anEps; | |
37b6f439 | 4851 | // |
1b7ae951 | 4852 | aNbS = 11; |
4853 | aDt = (theLast - theFirst) / aNbS; | |
4854 | aDMax = 0.; | |
4855 | anEps = 1.e-4 * aDt; | |
37b6f439 | 4856 | // |
1b7ae951 | 4857 | GeomAPI_ProjectPointOnSurf& aProjPS = theContext->ProjPS(theFace); |
4858 | aT2 = theFirst; | |
4859 | for (;;) { | |
4860 | aT1 = aT2; | |
4861 | aT2 += aDt; | |
37b6f439 | 4862 | // |
1b7ae951 | 4863 | if (aT2 > theLast) { |
37b6f439 | 4864 | break; |
4865 | } | |
1b7ae951 | 4866 | // |
4867 | aD = FindMaxDistance(theCurve, aT1, aT2, aProjPS, anEps); | |
4868 | if (aD > aDMax) { | |
4869 | aDMax = aD; | |
37b6f439 | 4870 | } |
4871 | } | |
1b7ae951 | 4872 | // |
4873 | return aDMax; | |
37b6f439 | 4874 | } |
4f189102 | 4875 | //======================================================================= |
1b7ae951 | 4876 | // Function : FindMaxDistance |
4877 | // purpose : | |
4f189102 | 4878 | //======================================================================= |
1b7ae951 | 4879 | Standard_Real FindMaxDistance(const Handle(Geom_Curve)& theC, |
4880 | const Standard_Real theFirst, | |
4881 | const Standard_Real theLast, | |
4882 | GeomAPI_ProjectPointOnSurf& theProjPS, | |
4883 | const Standard_Real theEps) | |
4f189102 | 4884 | { |
1b7ae951 | 4885 | Standard_Real aA, aB, aCf, aX, aX1, aX2, aF1, aF2, aF; |
4f189102 | 4886 | // |
1b7ae951 | 4887 | aCf = 0.61803398874989484820458683436564;//(sqrt(5.)-1)/2.; |
4888 | aA = theFirst; | |
4889 | aB = theLast; | |
4f189102 | 4890 | // |
1b7ae951 | 4891 | aX1 = aB - aCf * (aB - aA); |
4892 | aF1 = MaxDistance(theC, aX1, theProjPS); | |
4893 | aX2 = aA + aCf * (aB - aA); | |
4894 | aF2 = MaxDistance(theC, aX2, theProjPS); | |
4f189102 | 4895 | // |
1b7ae951 | 4896 | for (;;) { |
4897 | if ((aB - aA) < theEps) { | |
4898 | break; | |
4f189102 P |
4899 | } |
4900 | // | |
1b7ae951 | 4901 | if (aF1 > aF2) { |
4902 | aB = aX2; | |
4903 | aX2 = aX1; | |
4904 | aF2 = aF1; | |
4905 | aX1 = aB - aCf * (aB - aA); | |
4906 | aF1 = MaxDistance(theC, aX1, theProjPS); | |
4f189102 | 4907 | } |
1b7ae951 | 4908 | else { |
4909 | aA = aX1; | |
4910 | aX1 = aX2; | |
4911 | aF1 = aF2; | |
4912 | aX2 = aA + aCf * (aB - aA); | |
4913 | aF2 = MaxDistance(theC, aX2, theProjPS); | |
4914 | } | |
4915 | } | |
4916 | // | |
4917 | aX = 0.5 * (aA + aB); | |
4918 | aF = MaxDistance(theC, aX, theProjPS); | |
4919 | // | |
4920 | if (aF1 > aF) { | |
4921 | aF = aF1; | |
4922 | } | |
4923 | // | |
4924 | if (aF2 > aF) { | |
4925 | aF = aF2; | |
4f189102 P |
4926 | } |
4927 | // | |
1b7ae951 | 4928 | return aF; |
4929 | } | |
4930 | //======================================================================= | |
4931 | // Function : MaxDistance | |
4932 | // purpose : | |
4933 | //======================================================================= | |
4934 | Standard_Real MaxDistance(const Handle(Geom_Curve)& theC, | |
4935 | const Standard_Real aT, | |
4936 | GeomAPI_ProjectPointOnSurf& theProjPS) | |
4937 | { | |
4938 | Standard_Real aD; | |
4939 | gp_Pnt aP; | |
4940 | // | |
4941 | theC->D0(aT, aP); | |
4942 | theProjPS.Perform(aP); | |
4943 | aD = theProjPS.NbPoints() ? theProjPS.LowerDistance() : 0.; | |
4944 | // | |
4945 | return aD; | |
4f189102 | 4946 | } |
989341c5 | 4947 | |
4948 | //======================================================================= | |
4949 | //function : CheckPCurve | |
4950 | //purpose : Checks if points of the pcurve are out of the face bounds. | |
4951 | //======================================================================= | |
59495dbe | 4952 | Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC, |
4953 | const TopoDS_Face& aFace) | |
989341c5 | 4954 | { |
4955 | const Standard_Integer NPoints = 23; | |
4abae870 | 4956 | Standard_Integer i; |
989341c5 | 4957 | Standard_Real umin,umax,vmin,vmax; |
4958 | ||
4959 | BRepTools::UVBounds(aFace, umin, umax, vmin, vmax); | |
4960 | Standard_Real tolU = Max ((umax-umin)*0.01, Precision::Confusion()); | |
4961 | Standard_Real tolV = Max ((vmax-vmin)*0.01, Precision::Confusion()); | |
4962 | Standard_Real fp = aPC->FirstParameter(); | |
4963 | Standard_Real lp = aPC->LastParameter(); | |
59495dbe | 4964 | |
989341c5 | 4965 | |
4966 | // adjust domain for periodic surfaces | |
4967 | TopLoc_Location aLoc; | |
4968 | Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc); | |
4abae870 | 4969 | if (aSurf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) { |
989341c5 | 4970 | aSurf = (Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf))->BasisSurface(); |
4abae870 | 4971 | } |
989341c5 | 4972 | gp_Pnt2d pnt = aPC->Value((fp+lp)/2); |
4973 | Standard_Real u,v; | |
4974 | pnt.Coord(u,v); | |
4abae870 | 4975 | // |
989341c5 | 4976 | if (aSurf->IsUPeriodic()) { |
4977 | Standard_Real aPer = aSurf->UPeriod(); | |
4978 | Standard_Integer nshift = (Standard_Integer) ((u-umin)/aPer); | |
4979 | if (u < umin+aPer*nshift) nshift--; | |
4980 | umin += aPer*nshift; | |
4981 | umax += aPer*nshift; | |
4982 | } | |
4983 | if (aSurf->IsVPeriodic()) { | |
4984 | Standard_Real aPer = aSurf->VPeriod(); | |
4985 | Standard_Integer nshift = (Standard_Integer) ((v-vmin)/aPer); | |
4986 | if (v < vmin+aPer*nshift) nshift--; | |
4987 | vmin += aPer*nshift; | |
4988 | vmax += aPer*nshift; | |
4989 | } | |
4abae870 | 4990 | // |
4991 | //-------------------------------------------------------- | |
4992 | Standard_Boolean bRet; | |
4993 | Standard_Integer j, aNbIntervals; | |
4994 | Standard_Real aT, dT; | |
4995 | gp_Pnt2d aP2D; | |
4996 | // | |
4997 | Geom2dAdaptor_Curve aGAC(aPC); | |
4998 | aNbIntervals=aGAC.NbIntervals(GeomAbs_CN); | |
4999 | // | |
5000 | TColStd_Array1OfReal aTI(1, aNbIntervals+1); | |
5001 | aGAC.Intervals(aTI,GeomAbs_CN); | |
5002 | // | |
5003 | bRet=Standard_False; | |
5004 | // | |
5005 | aT=aGAC.FirstParameter(); | |
5006 | for (j=1; j<=aNbIntervals; ++j) { | |
5007 | dT=(aTI(j+1)-aTI(j))/NPoints; | |
5008 | // | |
5009 | for (i=1; i<NPoints; i++) { | |
5010 | aT=aT+dT; | |
5011 | aGAC.D0(aT, aP2D); | |
5012 | aP2D.Coord(u,v); | |
59495dbe | 5013 | if (umin-u > tolU || u-umax > tolU || |
4abae870 | 5014 | vmin-v > tolV || v-vmax > tolV) { |
5015 | return bRet; | |
59495dbe | 5016 | } |
5017 | } | |
989341c5 | 5018 | } |
4abae870 | 5019 | return !bRet; |
989341c5 | 5020 | } |
9a5a19e9 | 5021 | //======================================================================= |
5022 | //function : CorrectPlaneBoundaries | |
5023 | //purpose : | |
5024 | //======================================================================= | |
5025 | void CorrectPlaneBoundaries(Standard_Real& aUmin, | |
5026 | Standard_Real& aUmax, | |
5027 | Standard_Real& aVmin, | |
5028 | Standard_Real& aVmax) | |
5029 | { | |
5030 | if (!(Precision::IsInfinite(aUmin) || | |
5031 | Precision::IsInfinite(aUmax))) { | |
5032 | Standard_Real dU; | |
5033 | // | |
5034 | dU=0.1*(aUmax-aUmin); | |
5035 | aUmin=aUmin-dU; | |
5036 | aUmax=aUmax+dU; | |
5037 | } | |
5038 | if (!(Precision::IsInfinite(aVmin) || | |
5039 | Precision::IsInfinite(aVmax))) { | |
5040 | Standard_Real dV; | |
5041 | // | |
5042 | dV=0.1*(aVmax-aVmin); | |
5043 | aVmin=aVmin-dV; | |
5044 | aVmax=aVmax+dV; | |
5045 | } | |
5046 | } |