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