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