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