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