Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1992-05-07 |
2 | // Created by: Jacques GOUSSARD | |
3 | // Copyright (c) 1992-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
d5f74e42 | 8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
12 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
7fd59977 | 16 | |
e2e0498b | 17 | #include <IntPatch_ImpPrmIntersection.hxx> |
7fd59977 | 18 | |
c22b52d6 | 19 | #include <Adaptor3d_Surface.hxx> |
42cf5bc1 | 20 | #include <Adaptor3d_TopolTool.hxx> |
e2e0498b | 21 | #include <ElCLib.hxx> |
3306fdd9 | 22 | #include <ElSLib.hxx> |
42cf5bc1 | 23 | #include <IntPatch_ArcFunction.hxx> |
42cf5bc1 | 24 | #include <IntPatch_RLine.hxx> |
25 | #include <IntPatch_RstInt.hxx> | |
e2e0498b | 26 | #include <IntPatch_SpecialPoints.hxx> |
e2e0498b | 27 | #include <IntPatch_TheIWalking.hxx> |
7fd59977 | 28 | #include <IntPatch_TheSurfFunction.hxx> |
7fd59977 | 29 | #include <IntPatch_WLine.hxx> |
42cf5bc1 | 30 | #include <IntSurf.hxx> |
e2e0498b | 31 | #include <IntSurf_Quadric.hxx> |
32 | #include <IntSurf_QuadricTool.hxx> | |
42cf5bc1 | 33 | #include <IntSurf_SequenceOfPathPoint.hxx> |
c22b52d6 | 34 | #include <TColStd_Array1OfInteger.hxx> |
e2e0498b | 35 | #include <TopAbs_Orientation.hxx> |
36 | #include <TopTrans_CurveTransition.hxx> | |
37 | #include <math_Matrix.hxx> | |
38 | #include <math_Vector.hxx> | |
42cf5bc1 | 39 | |
0797d9d3 | 40 | #ifndef OCCT_DEBUG |
191478a5 | 41 | #define No_Standard_RangeError |
42 | #define No_Standard_OutOfRange | |
43 | #endif | |
44 | ||
77dbd1f1 | 45 | static Standard_Boolean DecomposeResult(const Handle(IntPatch_PointLine)& theLine, |
4e14c88f | 46 | const Standard_Boolean IsReversed, |
47 | const IntSurf_Quadric& theQuad, | |
48 | const Handle(Adaptor3d_TopolTool)& thePDomain, | |
c22b52d6 | 49 | const Handle(Adaptor3d_Surface)& theQSurf, |
50 | const Handle(Adaptor3d_Surface)& theOtherSurf, | |
4e14c88f | 51 | const Standard_Real theArcTol, |
a09c8f3a | 52 | const Standard_Real theTolTang, |
4e14c88f | 53 | IntPatch_SequenceOfLine& theLines); |
191478a5 | 54 | static |
55 | void ComputeTangency (const IntPatch_TheSOnBounds& solrst, | |
56 | IntSurf_SequenceOfPathPoint& seqpdep, | |
57 | const Handle(Adaptor3d_TopolTool)& Domain, | |
58 | IntPatch_TheSurfFunction& Func, | |
c22b52d6 | 59 | const Handle(Adaptor3d_Surface)& PSurf, |
191478a5 | 60 | TColStd_Array1OfInteger& Destination); |
61 | static | |
62 | void Recadre(const Standard_Boolean , | |
63 | GeomAbs_SurfaceType typeS1, | |
64 | GeomAbs_SurfaceType typeS2, | |
65 | IntPatch_Point& pt, | |
66 | const Handle(IntPatch_TheIWLineOfTheIWalking)& iwline, | |
67 | Standard_Integer Param, | |
68 | Standard_Real U1, | |
69 | Standard_Real V1, | |
70 | Standard_Real U2, | |
71 | Standard_Real V2); | |
7fd59977 | 72 | |
77dbd1f1 | 73 | static |
74 | Standard_Boolean IsCoincide(IntPatch_TheSurfFunction& theFunc, | |
75 | const Handle(IntPatch_PointLine)& theLine, | |
c22b52d6 | 76 | const Handle(Adaptor2d_Curve2d)& theArc, |
77dbd1f1 | 77 | const Standard_Boolean isTheSurface1Using, |
78 | const Standard_Real theToler3D, | |
79 | const Standard_Real theToler2D, | |
80 | const Standard_Real thePeriod); | |
d4b867e6 | 81 | |
56b495d9 | 82 | static |
83 | Standard_Real GetLocalStep(const Handle(Adaptor3d_Surface)& theSurf, | |
84 | const Standard_Real theStep); | |
85 | ||
86 | ||
e2e0498b | 87 | //======================================================================= |
88 | //function : IsSeamOrPole | |
89 | //purpose : | |
90 | //======================================================================= | |
c22b52d6 | 91 | static IntPatch_SpecPntType IsSeamOrPole(const Handle(Adaptor3d_Surface)& theQSurf, |
e2e0498b | 92 | const Handle(IntSurf_LineOn2S)& theLine, |
93 | const Standard_Boolean IsReversed, | |
94 | const Standard_Integer theRefIndex, | |
3306fdd9 | 95 | const Standard_Real theTol3D, |
e2e0498b | 96 | const Standard_Real theDeltaMax) |
a09c8f3a | 97 | { |
98 | if((theRefIndex < 1) || (theRefIndex >= theLine->NbPoints())) | |
e2e0498b | 99 | return IntPatch_SPntNone; |
a09c8f3a | 100 | |
101 | //Parameters on Quadric and on parametric for reference point | |
102 | Standard_Real aUQRef, aVQRef, aUPRef, aVPRef; | |
103 | Standard_Real aUQNext, aVQNext, aUPNext, aVPNext; | |
104 | ||
3306fdd9 | 105 | const gp_Pnt &aP3d = theLine->Value(theRefIndex + 1).Value(); |
106 | ||
a09c8f3a | 107 | if(IsReversed) |
108 | { | |
109 | theLine->Value(theRefIndex).Parameters (aUPRef, aVPRef, aUQRef, aVQRef); | |
110 | theLine->Value(theRefIndex+1).Parameters(aUPNext, aVPNext, aUQNext, aVQNext); | |
111 | } | |
112 | else | |
113 | { | |
114 | theLine->Value(theRefIndex).Parameters (aUQRef, aVQRef, aUPRef, aVPRef); | |
115 | theLine->Value(theRefIndex+1).Parameters(aUQNext, aVQNext, aUPNext, aVPNext); | |
116 | } | |
117 | ||
118 | const GeomAbs_SurfaceType aType = theQSurf->GetType(); | |
119 | ||
3306fdd9 | 120 | if ((aType == GeomAbs_Cone) && |
121 | (theQSurf->Cone().Apex().SquareDistance(aP3d) < theTol3D*theTol3D)) | |
122 | { | |
123 | return IntPatch_SPntPoleSeamU; | |
124 | } | |
125 | else if (aType == GeomAbs_Sphere) | |
126 | { | |
127 | const Standard_Real aSqTol = theTol3D*theTol3D; | |
128 | gp_Pnt aP(ElSLib::Value(0.0, M_PI_2, theQSurf->Sphere())); | |
129 | if (aP.SquareDistance(aP3d) < aSqTol) | |
130 | { | |
131 | return IntPatch_SPntPoleSeamU; | |
132 | } | |
133 | ||
134 | aP = ElSLib::Value(0.0, -M_PI_2, theQSurf->Sphere()); | |
135 | if (aP.SquareDistance(aP3d) < aSqTol) | |
136 | { | |
137 | return IntPatch_SPntPoleSeamU; | |
138 | } | |
139 | } | |
140 | ||
141 | ||
a09c8f3a | 142 | const Standard_Real aDeltaU = Abs(aUQRef - aUQNext); |
143 | ||
144 | if((aType != GeomAbs_Torus) && (aDeltaU < theDeltaMax)) | |
e2e0498b | 145 | return IntPatch_SPntNone; |
a09c8f3a | 146 | |
147 | switch(aType) | |
148 | { | |
149 | case GeomAbs_Cylinder: | |
e2e0498b | 150 | return IntPatch_SPntSeamU; |
a09c8f3a | 151 | |
152 | case GeomAbs_Torus: | |
153 | { | |
154 | const Standard_Real aDeltaV = Abs(aVQRef - aVQNext); | |
155 | ||
156 | if((aDeltaU >= theDeltaMax) && (aDeltaV >= theDeltaMax)) | |
e2e0498b | 157 | return IntPatch_SPntSeamUV; |
a09c8f3a | 158 | |
159 | if(aDeltaU >= theDeltaMax) | |
e2e0498b | 160 | return IntPatch_SPntSeamU; |
a09c8f3a | 161 | |
162 | if(aDeltaV >= theDeltaMax) | |
e2e0498b | 163 | return IntPatch_SPntSeamV; |
a09c8f3a | 164 | } |
165 | ||
166 | break; | |
167 | case GeomAbs_Sphere: | |
168 | case GeomAbs_Cone: | |
e2e0498b | 169 | return IntPatch_SPntPoleSeamU; |
a09c8f3a | 170 | default: |
171 | break; | |
172 | } | |
173 | ||
e2e0498b | 174 | return IntPatch_SPntNone; |
a09c8f3a | 175 | } |
176 | ||
7fd59977 | 177 | //======================================================================= |
178 | //function : IntPatch_ImpPrmIntersection | |
179 | //purpose : | |
180 | //======================================================================= | |
7fd59977 | 181 | IntPatch_ImpPrmIntersection::IntPatch_ImpPrmIntersection () |
191478a5 | 182 | : done(Standard_False), |
183 | empt(Standard_False), | |
184 | myIsStartPnt(Standard_False), | |
185 | myUStart(0.0), | |
186 | myVStart(0.0) | |
7fd59977 | 187 | { } |
188 | ||
189 | ||
190 | //======================================================================= | |
191 | //function : IntPatch_ImpPrmIntersection | |
192 | //purpose : | |
193 | //======================================================================= | |
194 | ||
195 | IntPatch_ImpPrmIntersection::IntPatch_ImpPrmIntersection | |
c22b52d6 | 196 | (const Handle(Adaptor3d_Surface)& Surf1, |
191478a5 | 197 | const Handle(Adaptor3d_TopolTool)& D1, |
c22b52d6 | 198 | const Handle(Adaptor3d_Surface)& Surf2, |
191478a5 | 199 | const Handle(Adaptor3d_TopolTool)& D2, |
200 | const Standard_Real TolArc, | |
201 | const Standard_Real TolTang, | |
202 | const Standard_Real Fleche, | |
203 | const Standard_Real Pas) | |
204 | : done(Standard_False), | |
205 | empt(Standard_False), | |
206 | myIsStartPnt(Standard_False), | |
207 | myUStart(0.0), | |
208 | myVStart(0.0) | |
7fd59977 | 209 | { |
210 | Perform(Surf1,D1,Surf2,D2,TolArc,TolTang,Fleche,Pas); | |
211 | } | |
212 | ||
213 | ||
214 | //======================================================================= | |
215 | //function : SetStartPoint | |
216 | //purpose : | |
217 | //======================================================================= | |
218 | ||
219 | void IntPatch_ImpPrmIntersection::SetStartPoint(const Standard_Real U, | |
191478a5 | 220 | const Standard_Real V) |
7fd59977 | 221 | { |
222 | myIsStartPnt = Standard_True; | |
223 | myUStart = U; myVStart = V; | |
224 | } | |
225 | ||
7fd59977 | 226 | //======================================================================= |
227 | //function : ComputeTangency | |
228 | //purpose : | |
229 | //======================================================================= | |
230 | void ComputeTangency (const IntPatch_TheSOnBounds& solrst, | |
191478a5 | 231 | IntSurf_SequenceOfPathPoint& seqpdep, |
232 | const Handle(Adaptor3d_TopolTool)& Domain, | |
233 | IntPatch_TheSurfFunction& Func, | |
c22b52d6 | 234 | const Handle(Adaptor3d_Surface)& PSurf, |
191478a5 | 235 | TColStd_Array1OfInteger& Destination) |
7fd59977 | 236 | { |
237 | Standard_Integer i,k, NbPoints, seqlength; | |
238 | Standard_Real theparam,test; | |
239 | Standard_Boolean fairpt, ispassing; | |
240 | TopAbs_Orientation arcorien,vtxorien; | |
c22b52d6 | 241 | Handle(Adaptor2d_Curve2d) thearc; |
7fd59977 | 242 | Handle(Adaptor3d_HVertex) vtx,vtxbis; |
243 | //Standard_Boolean ispassing; | |
244 | IntPatch_ThePathPointOfTheSOnBounds PStart; | |
245 | IntSurf_PathPoint PPoint; | |
246 | gp_Vec vectg; | |
247 | gp_Dir2d dirtg; | |
248 | gp_Pnt ptbid; | |
249 | gp_Vec d1u,d1v,v1,v2; | |
250 | gp_Pnt2d p2d; | |
251 | gp_Vec2d d2d; | |
252 | // | |
1ef32e96 RL |
253 | double aX[2], aF[1], aD[1][2]; |
254 | math_Vector X(aX, 1, 2); | |
255 | math_Vector F(aF, 1, 1); | |
256 | math_Matrix D(aD, 1, 1, 1, 2); | |
7fd59977 | 257 | // |
258 | seqlength = 0; | |
259 | NbPoints = solrst.NbPoints(); | |
260 | for (i=1; i<= NbPoints; i++) { | |
261 | if (Destination(i) == 0) { | |
262 | PStart = solrst.Point(i); | |
263 | thearc = PStart.Arc(); | |
264 | theparam = PStart.Parameter(); | |
265 | arcorien = Domain->Orientation(thearc); | |
266 | ispassing = (arcorien == TopAbs_INTERNAL || | |
191478a5 | 267 | arcorien == TopAbs_EXTERNAL); |
268 | ||
7fd59977 | 269 | thearc->D0(theparam,p2d); |
270 | X(1) = p2d.X(); | |
271 | X(2) = p2d.Y(); | |
272 | PPoint.SetValue(PStart.Value(),X(1),X(2)); | |
191478a5 | 273 | |
7fd59977 | 274 | Func.Values(X,F,D); |
275 | if (Func.IsTangent()) { | |
191478a5 | 276 | PPoint.SetTangency(Standard_True); |
7fd59977 | 277 | Destination(i) = seqlength+1; |
191478a5 | 278 | if (!PStart.IsNew()) { |
279 | vtx = PStart.Vertex(); | |
280 | for (k=i+1; k<=NbPoints; k++) { | |
281 | if (Destination(k) ==0) { | |
282 | PStart = solrst.Point(k); | |
283 | if (!PStart.IsNew()) { | |
284 | vtxbis = PStart.Vertex(); | |
285 | if (Domain->Identical(vtx,vtxbis)) { | |
286 | thearc = PStart.Arc(); | |
287 | theparam = PStart.Parameter(); | |
288 | arcorien = Domain->Orientation(thearc); | |
289 | ispassing = ispassing && (arcorien == TopAbs_INTERNAL || | |
290 | arcorien == TopAbs_EXTERNAL); | |
291 | ||
292 | thearc->D0(theparam,p2d); | |
293 | PPoint.AddUV(p2d.X(),p2d.Y()); | |
294 | Destination(k) = seqlength+1; | |
295 | } | |
296 | } | |
297 | } | |
298 | } | |
299 | } | |
300 | PPoint.SetPassing(ispassing); | |
301 | seqpdep.Append(PPoint); | |
302 | seqlength++; | |
7fd59977 | 303 | } |
304 | else { // on a un point de depart potentiel | |
305 | ||
191478a5 | 306 | vectg = Func.Direction3d(); |
307 | dirtg = Func.Direction2d(); | |
308 | ||
309 | PSurf->D1(X(1),X(2),ptbid,d1u,d1v); | |
310 | thearc->D1(theparam,p2d,d2d); | |
311 | v2.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
312 | v1 = d1u.Crossed(d1v); | |
313 | ||
314 | test = vectg.Dot(v1.Crossed(v2)); | |
315 | if (PStart.IsNew()) { | |
316 | if ((test < 0. && arcorien == TopAbs_FORWARD) || | |
317 | (test > 0. && arcorien == TopAbs_REVERSED)) { | |
318 | vectg.Reverse(); | |
319 | dirtg.Reverse(); | |
320 | } | |
321 | PPoint.SetDirections(vectg,dirtg); | |
322 | PPoint.SetPassing(ispassing); | |
7fd59977 | 323 | Destination(i) = seqlength+1; |
191478a5 | 324 | seqpdep.Append(PPoint); |
325 | seqlength++; | |
326 | } | |
327 | else { // traiter la transition complexe | |
328 | gp_Dir bidnorm(1.,1.,1.); | |
329 | Standard_Real tole = 1.e-8; | |
330 | TopAbs_Orientation LocTrans; | |
331 | TopTrans_CurveTransition comptrans; | |
332 | comptrans.Reset(vectg,bidnorm,0.); | |
333 | if (arcorien == TopAbs_FORWARD || | |
334 | arcorien == TopAbs_REVERSED) { | |
335 | // pour essai | |
336 | ||
337 | vtx = PStart.Vertex(); | |
338 | vtxorien = Domain->Orientation(vtx); | |
339 | if (Abs(test) <= tole) { | |
340 | LocTrans = TopAbs_EXTERNAL; // et pourquoi pas INTERNAL | |
341 | } | |
342 | else { | |
343 | if (((test > 0.)&& arcorien == TopAbs_FORWARD) || | |
344 | ((test < 0.)&& arcorien == TopAbs_REVERSED)){ | |
345 | LocTrans = TopAbs_FORWARD; | |
346 | } | |
347 | else { | |
348 | LocTrans = TopAbs_REVERSED; | |
349 | } | |
350 | if (arcorien == TopAbs_REVERSED) {v2.Reverse();} | |
351 | } | |
352 | ||
353 | comptrans.Compare(tole,v2,bidnorm,0.,LocTrans,vtxorien); | |
354 | } | |
7fd59977 | 355 | Destination(i) = seqlength+1; |
191478a5 | 356 | for (k= i+1; k<=NbPoints; k++) { |
357 | if (Destination(k) == 0) { | |
358 | PStart = solrst.Point(k); | |
359 | if (!PStart.IsNew()) { | |
360 | vtxbis = PStart.Vertex(); | |
361 | if (Domain->Identical(vtx,vtxbis)) { | |
362 | thearc = PStart.Arc(); | |
363 | theparam = PStart.Parameter(); | |
364 | arcorien = Domain->Orientation(thearc); | |
365 | ||
366 | PPoint.AddUV(X(1),X(2)); | |
367 | ||
368 | thearc->D1(theparam,p2d,d2d); | |
369 | PPoint.AddUV(p2d.X(),p2d.Y()); | |
370 | ||
371 | if (arcorien == TopAbs_FORWARD || | |
372 | arcorien == TopAbs_REVERSED) { | |
373 | ispassing = Standard_False; | |
374 | v2.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
375 | ||
376 | test = vectg.Dot(v1.Crossed(v2)); | |
377 | vtxorien = Domain->Orientation(PStart.Vertex()); | |
378 | if (Abs(test) <= tole) { | |
379 | LocTrans = TopAbs_EXTERNAL; // et pourquoi pas INTERNAL | |
380 | } | |
381 | else { | |
382 | if (((test > 0.)&& arcorien == TopAbs_FORWARD) || | |
383 | ((test < 0.)&& arcorien == TopAbs_REVERSED)){ | |
384 | LocTrans = TopAbs_FORWARD; | |
385 | } | |
386 | else { | |
387 | LocTrans = TopAbs_REVERSED; | |
388 | } | |
389 | if (arcorien == TopAbs_REVERSED) {v2.Reverse();} | |
390 | } | |
391 | ||
392 | comptrans.Compare(tole,v2,bidnorm,0.,LocTrans,vtxorien); | |
393 | } | |
394 | Destination(k) = seqlength+1; | |
395 | } | |
396 | } | |
397 | } | |
398 | } | |
7fd59977 | 399 | fairpt = Standard_True; |
191478a5 | 400 | if (!ispassing) { |
401 | TopAbs_State Before = comptrans.StateBefore(); | |
402 | TopAbs_State After = comptrans.StateAfter(); | |
403 | if ((Before == TopAbs_UNKNOWN)||(After == TopAbs_UNKNOWN)) { | |
404 | fairpt = Standard_False; | |
405 | } | |
406 | else if (Before == TopAbs_IN) { | |
407 | if (After == TopAbs_IN) { | |
408 | ispassing = Standard_True; | |
409 | } | |
410 | else { | |
411 | vectg.Reverse(); | |
412 | dirtg.Reverse(); | |
413 | } | |
414 | } | |
415 | else { | |
416 | if (After !=TopAbs_IN) { | |
417 | fairpt = Standard_False; | |
418 | } | |
419 | } | |
420 | } | |
421 | if (fairpt) { | |
422 | PPoint.SetDirections(vectg,dirtg); | |
423 | PPoint.SetPassing(ispassing); | |
424 | seqpdep.Append(PPoint); | |
425 | seqlength++; | |
426 | } | |
427 | else { // il faut remettre en "ordre" si on ne garde pas le point. | |
428 | for (k=i; k <=NbPoints ; k++) { | |
429 | if (Destination(k)==seqlength + 1) { | |
430 | Destination(k) = -Destination(k); | |
431 | } | |
432 | } | |
433 | } | |
434 | } | |
7fd59977 | 435 | } |
436 | } | |
437 | } | |
438 | } | |
439 | //======================================================================= | |
440 | //function : Recadre | |
441 | //purpose : | |
442 | //======================================================================= | |
443 | void Recadre(const Standard_Boolean , | |
191478a5 | 444 | GeomAbs_SurfaceType typeS1, |
445 | GeomAbs_SurfaceType typeS2, | |
446 | IntPatch_Point& pt, | |
447 | const Handle(IntPatch_TheIWLineOfTheIWalking)& iwline, | |
448 | Standard_Integer Param, | |
449 | Standard_Real U1, | |
450 | Standard_Real V1, | |
451 | Standard_Real U2, | |
452 | Standard_Real V2) | |
7fd59977 | 453 | { |
454 | Standard_Real U1p,V1p,U2p,V2p; | |
455 | iwline->Line()->Value(Param).Parameters(U1p,V1p,U2p,V2p); | |
456 | switch(typeS1) | |
457 | { | |
191478a5 | 458 | case GeomAbs_Torus: |
459 | while(V1<(V1p-1.5*M_PI)) V1+=M_PI+M_PI; | |
460 | while(V1>(V1p+1.5*M_PI)) V1-=M_PI+M_PI; | |
b1811c1d | 461 | Standard_FALLTHROUGH |
191478a5 | 462 | case GeomAbs_Cylinder: |
463 | case GeomAbs_Cone: | |
464 | case GeomAbs_Sphere: | |
465 | while(U1<(U1p-1.5*M_PI)) U1+=M_PI+M_PI; | |
466 | while(U1>(U1p+1.5*M_PI)) U1-=M_PI+M_PI; | |
467 | default: | |
468 | break; | |
7fd59977 | 469 | } |
470 | switch(typeS2) | |
471 | { | |
191478a5 | 472 | case GeomAbs_Torus: |
473 | while(V2<(V2p-1.5*M_PI)) V2+=M_PI+M_PI; | |
474 | while(V2>(V2p+1.5*M_PI)) V2-=M_PI+M_PI; | |
b1811c1d | 475 | Standard_FALLTHROUGH |
191478a5 | 476 | case GeomAbs_Cylinder: |
477 | case GeomAbs_Cone: | |
478 | case GeomAbs_Sphere: | |
479 | while(U2<(U2p-1.5*M_PI)) U2+=M_PI+M_PI; | |
480 | while(U2>(U2p+1.5*M_PI)) U2-=M_PI+M_PI; | |
481 | default: | |
482 | break; | |
7fd59977 | 483 | } |
484 | pt.SetParameters(U1,V1,U2,V2); | |
485 | } | |
486 | ||
56b495d9 | 487 | //======================================================================= |
488 | //function : GetLocalStep | |
489 | //purpose : | |
490 | //======================================================================= | |
491 | Standard_Real GetLocalStep(const Handle(Adaptor3d_Surface)& theSurf, | |
492 | const Standard_Real theStep) | |
493 | { | |
494 | Standard_Real aLocalStep = theStep; | |
495 | if (theSurf->UContinuity() > GeomAbs_C0 && theSurf->VContinuity() > GeomAbs_C0) | |
496 | { | |
497 | GeomAbs_SurfaceType aSType = theSurf->GetType(); | |
498 | ||
499 | if (aSType == GeomAbs_BezierSurface || aSType == GeomAbs_BSplineSurface) | |
500 | { | |
501 | Standard_Real aMinRes = Precision::Infinite(); | |
502 | Standard_Integer aMaxDeg = 0; | |
503 | const Standard_Real aLimRes = 1.e-10; | |
504 | ||
505 | aMinRes = Min(theSurf->UResolution(Precision::Confusion()), | |
506 | theSurf->VResolution(Precision::Confusion())); | |
507 | aMaxDeg = Max(theSurf->UDegree(), theSurf->VDegree()); | |
508 | if (aMinRes < aLimRes && aMaxDeg > 3) | |
509 | { | |
510 | aLocalStep = 0.0001; | |
511 | } | |
512 | } | |
513 | } | |
514 | if (theSurf->UContinuity() == GeomAbs_C0) | |
515 | { | |
516 | Standard_Integer aNbInt = theSurf->NbUIntervals(GeomAbs_C1); | |
517 | if (aNbInt > 1) | |
518 | { | |
519 | TColStd_Array1OfReal anInts(1, aNbInt + 1); | |
520 | theSurf->UIntervals(anInts, GeomAbs_C1); | |
521 | Standard_Integer i; | |
522 | Standard_Real aMinInt = Precision::Infinite(); | |
523 | for (i = 1; i <= aNbInt; ++i) | |
524 | { | |
525 | aMinInt = Min(aMinInt, anInts(i + 1) - anInts(i)); | |
526 | } | |
527 | ||
528 | aMinInt /= theSurf->LastUParameter() - theSurf->FirstUParameter(); | |
529 | if (aMinInt < 0.002) | |
530 | { | |
531 | aLocalStep = 0.0001; | |
532 | } | |
533 | } | |
534 | ||
535 | } | |
536 | ||
537 | if (theSurf->VContinuity() == GeomAbs_C0) | |
538 | { | |
539 | Standard_Integer aNbInt = theSurf->NbVIntervals(GeomAbs_C1); | |
540 | if (aNbInt > 1) | |
541 | { | |
542 | TColStd_Array1OfReal anInts(1, aNbInt + 1); | |
543 | theSurf->VIntervals(anInts, GeomAbs_C1); | |
544 | Standard_Integer i; | |
545 | Standard_Real aMinInt = Precision::Infinite(); | |
546 | for (i = 1; i <= aNbInt; ++i) | |
547 | { | |
548 | aMinInt = Min(aMinInt, anInts(i + 1) - anInts(i)); | |
549 | } | |
550 | ||
551 | aMinInt /= theSurf->LastVParameter() - theSurf->FirstVParameter(); | |
552 | if (aMinInt < 0.002) | |
553 | { | |
554 | aLocalStep = 0.0001; | |
555 | } | |
556 | } | |
557 | } | |
558 | ||
559 | aLocalStep = Min(theStep, aLocalStep); | |
560 | return aLocalStep; | |
561 | } | |
7fd59977 | 562 | //======================================================================= |
563 | //function : Perform | |
564 | //purpose : | |
565 | //======================================================================= | |
c22b52d6 | 566 | void IntPatch_ImpPrmIntersection::Perform (const Handle(Adaptor3d_Surface)& Surf1, |
191478a5 | 567 | const Handle(Adaptor3d_TopolTool)& D1, |
c22b52d6 | 568 | const Handle(Adaptor3d_Surface)& Surf2, |
191478a5 | 569 | const Handle(Adaptor3d_TopolTool)& D2, |
570 | const Standard_Real TolArc, | |
571 | const Standard_Real TolTang, | |
572 | const Standard_Real Fleche, | |
573 | const Standard_Real Pas) | |
7fd59977 | 574 | { |
575 | Standard_Boolean reversed, procf, procl, dofirst, dolast; | |
d4b867e6 | 576 | Standard_Integer indfirst = 0, indlast = 0, ind2, NbSegm; |
7fd59977 | 577 | Standard_Integer NbPointIns, NbPointRst, Nblines, Nbpts, NbPointDep; |
578 | Standard_Real U1,V1,U2,V2,paramf,paraml,currentparam; | |
191478a5 | 579 | |
7fd59977 | 580 | IntPatch_TheSegmentOfTheSOnBounds thesegm; |
581 | IntSurf_PathPoint PPoint; | |
582 | ||
583 | Handle(IntPatch_RLine) rline; | |
584 | Handle(IntPatch_WLine) wline; | |
585 | IntPatch_ThePathPointOfTheSOnBounds PStart,PStartf,PStartl; | |
586 | IntPatch_Point ptdeb,ptfin,ptbis; | |
191478a5 | 587 | |
7fd59977 | 588 | IntPatch_IType typ; |
589 | IntSurf_Transition TLine,TArc; | |
590 | IntSurf_TypeTrans trans1,trans2; | |
591 | gp_Pnt valpt,ptbid; | |
592 | gp_Vec tgline,tgrst,norm1,norm2,d1u,d1v; | |
593 | gp_Dir DirNormale; | |
594 | gp_Vec VecNormale; | |
191478a5 | 595 | |
7fd59977 | 596 | gp_Pnt2d p2d; |
597 | gp_Vec2d d2d; | |
191478a5 | 598 | |
c22b52d6 | 599 | Handle(Adaptor2d_Curve2d) currentarc; |
7fd59977 | 600 | GeomAbs_SurfaceType typeS1, typeS2; |
601 | IntSurf_Quadric Quad; | |
602 | IntPatch_TheSurfFunction Func; | |
603 | IntPatch_ArcFunction AFunc; | |
604 | // | |
605 | typeS1 = Surf1->GetType(); | |
606 | typeS2 = Surf2->GetType(); | |
191478a5 | 607 | |
7fd59977 | 608 | paramf =0.; |
609 | paraml =0.; | |
610 | trans1 = IntSurf_Undecided; | |
611 | trans2 = IntSurf_Undecided; | |
612 | // | |
613 | done = Standard_False; | |
614 | empt = Standard_True; | |
615 | slin.Clear(); | |
616 | spnt.Clear(); | |
617 | // | |
618 | reversed = Standard_False; | |
191478a5 | 619 | switch (typeS1) |
620 | { | |
621 | case GeomAbs_Plane: | |
622 | Quad.SetValue(Surf1->Plane()); | |
623 | break; | |
7fd59977 | 624 | |
191478a5 | 625 | case GeomAbs_Cylinder: |
626 | Quad.SetValue(Surf1->Cylinder()); | |
627 | break; | |
7fd59977 | 628 | |
191478a5 | 629 | case GeomAbs_Sphere: |
630 | Quad.SetValue(Surf1->Sphere()); | |
631 | break; | |
7fd59977 | 632 | |
191478a5 | 633 | case GeomAbs_Cone: |
634 | Quad.SetValue(Surf1->Cone()); | |
635 | break; | |
7fd59977 | 636 | |
191478a5 | 637 | default: |
638 | { | |
7fd59977 | 639 | reversed = Standard_True; |
191478a5 | 640 | switch (typeS2) |
641 | { | |
642 | case GeomAbs_Plane: | |
643 | Quad.SetValue(Surf2->Plane()); | |
644 | break; | |
645 | ||
646 | case GeomAbs_Cylinder: | |
647 | Quad.SetValue(Surf2->Cylinder()); | |
648 | break; | |
649 | ||
650 | case GeomAbs_Sphere: | |
651 | Quad.SetValue(Surf2->Sphere()); | |
652 | break; | |
653 | ||
654 | case GeomAbs_Cone: | |
655 | Quad.SetValue(Surf2->Cone()); | |
656 | break; | |
657 | default: | |
658 | { | |
9775fa61 | 659 | throw Standard_ConstructionError(); |
191478a5 | 660 | break; |
661 | } | |
7fd59977 | 662 | } |
663 | } | |
664 | break; | |
665 | } | |
666 | // | |
9a640cbe | 667 | Standard_Real aLocalPas = Pas; |
56b495d9 | 668 | if (reversed) |
669 | aLocalPas = GetLocalStep(Surf1, Pas); | |
670 | else | |
671 | aLocalPas = GetLocalStep(Surf2, Pas); | |
9a640cbe | 672 | |
7fd59977 | 673 | Func.SetImplicitSurface(Quad); |
674 | Func.Set(IntSurf_QuadricTool::Tolerance(Quad)); | |
675 | AFunc.SetQuadric(Quad); | |
676 | // | |
677 | if (!reversed) { | |
678 | Func.Set(Surf2); | |
679 | AFunc.Set(Surf2); | |
680 | } | |
681 | else { | |
682 | Func.Set(Surf1); | |
683 | AFunc.Set(Surf1); | |
684 | } | |
685 | // | |
686 | if (!reversed) { | |
687 | solrst.Perform(AFunc,D2,TolArc,TolTang); | |
688 | } | |
689 | else { | |
690 | solrst.Perform(AFunc,D1,TolArc,TolTang); | |
691 | } | |
692 | if (!solrst.IsDone()) { | |
693 | return; | |
694 | } | |
695 | // | |
696 | IntSurf_SequenceOfPathPoint seqpdep; | |
697 | IntSurf_SequenceOfInteriorPoint seqpins; | |
698 | // | |
699 | NbPointRst = solrst.NbPoints(); | |
700 | TColStd_Array1OfInteger Destination(1,NbPointRst+1); Destination.Init(0); | |
701 | if (NbPointRst) { | |
702 | if (!reversed) { | |
703 | ComputeTangency(solrst,seqpdep,D2,Func,Surf2,Destination); | |
704 | } | |
705 | else { | |
706 | ComputeTangency(solrst,seqpdep,D1,Func,Surf1,Destination); | |
707 | } | |
708 | } | |
709 | // | |
e618b526 | 710 | Standard_Boolean SearchIns = Standard_True; |
711 | if(Quad.TypeQuadric() == GeomAbs_Plane && solrst.NbSegments() > 0) | |
712 | { | |
713 | //For such kind of cases it is possible that whole surface is on one side of plane, | |
714 | //plane only touches surface and does not cross it, | |
715 | //so no inner points exist. | |
716 | SearchIns = Standard_False; | |
717 | Handle(Adaptor3d_TopolTool) T; | |
718 | if(reversed) | |
719 | { | |
720 | T = D1; | |
721 | } | |
7fd59977 | 722 | else |
e618b526 | 723 | { |
724 | T = D2; | |
725 | } | |
726 | Standard_Integer aNbSamples = 0; | |
727 | aNbSamples = T->NbSamples(); | |
728 | gp_Pnt2d s2d; | |
729 | gp_Pnt s3d; | |
730 | Standard_Real aValf[1], aUVap[2]; | |
731 | math_Vector Valf(aValf,1,1), UVap(aUVap,1,2); | |
732 | T->SamplePoint(1,s2d, s3d); | |
733 | UVap(1)=s2d.X(); | |
734 | UVap(2)=s2d.Y(); | |
735 | Func.Value(UVap,Valf); | |
736 | Standard_Real rvalf = Sign(1.,Valf(1)); | |
d4b867e6 | 737 | for(Standard_Integer i = 2; i <= aNbSamples; ++i) |
e618b526 | 738 | { |
94f71cad | 739 | T->SamplePoint(i,s2d, s3d); |
e618b526 | 740 | UVap(1)=s2d.X(); |
741 | UVap(2)=s2d.Y(); | |
742 | Func.Value(UVap,Valf); | |
743 | if(rvalf * Valf(1) < 0.) | |
744 | { | |
745 | SearchIns = Standard_True; | |
746 | break; | |
747 | } | |
748 | } | |
7fd59977 | 749 | } |
e618b526 | 750 | // Recherche des points interieurs |
751 | NbPointIns = 0; | |
752 | if(SearchIns) { | |
753 | if (!reversed) { | |
754 | if (myIsStartPnt) | |
755 | solins.Perform(Func,Surf2,myUStart,myVStart); | |
756 | else | |
757 | solins.Perform(Func,Surf2,D2,TolTang); | |
758 | } | |
759 | else { | |
760 | if (myIsStartPnt) | |
761 | solins.Perform(Func,Surf1,myUStart,myVStart); | |
762 | else | |
763 | solins.Perform(Func,Surf1,D1,TolTang); | |
764 | } | |
765 | NbPointIns = solins.NbPoints(); | |
d4b867e6 | 766 | for (Standard_Integer i=1; i <= NbPointIns; i++) { |
e618b526 | 767 | seqpins.Append(solins.Value(i)); |
768 | } | |
7fd59977 | 769 | } |
770 | // | |
7fd59977 | 771 | NbPointDep=seqpdep.Length(); |
772 | // | |
773 | if (NbPointDep || NbPointIns) { | |
9a640cbe | 774 | IntPatch_TheIWalking iwalk(TolTang, Fleche, aLocalPas); |
92a55b01 | 775 | iwalk.Perform(seqpdep, seqpins, Func, reversed ? Surf1 : Surf2, reversed); |
776 | ||
7fd59977 | 777 | if(!iwalk.IsDone()) { |
778 | return; | |
779 | } | |
191478a5 | 780 | |
7fd59977 | 781 | Standard_Real Vmin, Vmax, TolV = 1.e-14; |
782 | if (!reversed) { //Surf1 is quadric | |
783 | Vmin = Surf1->FirstVParameter(); | |
784 | Vmax = Surf1->LastVParameter(); | |
785 | } | |
786 | else { //Surf2 is quadric | |
787 | Vmin = Surf2->FirstVParameter(); | |
788 | Vmax = Surf2->LastVParameter(); | |
789 | } | |
790 | // | |
791 | Nblines = iwalk.NbLines(); | |
d4b867e6 | 792 | for (Standard_Integer j=1; j<=Nblines; j++) { |
7fd59977 | 793 | const Handle(IntPatch_TheIWLineOfTheIWalking)& iwline = iwalk.Value(j); |
794 | const Handle(IntSurf_LineOn2S)& thelin = iwline->Line(); | |
191478a5 | 795 | |
7fd59977 | 796 | Nbpts = thelin->NbPoints(); |
797 | if(Nbpts>=2) { | |
d4b867e6 | 798 | Standard_Integer k = 0; |
191478a5 | 799 | tgline = iwline->TangentVector(k); |
800 | if(k>=1 && k<=Nbpts) { } else { k=Nbpts>>1; } | |
801 | valpt = thelin->Value(k).Value(); | |
802 | ||
803 | if (!reversed) { | |
804 | thelin->Value(k).ParametersOnS2(U2,V2); | |
805 | norm1 = Quad.Normale(valpt); | |
806 | Surf2->D1(U2,V2,ptbid,d1u,d1v); | |
807 | norm2 = d1u.Crossed(d1v); | |
808 | } | |
809 | else { | |
810 | thelin->Value(k).ParametersOnS1(U2,V2); | |
811 | norm2 = Quad.Normale(valpt); | |
812 | Surf1->D1(U2,V2,ptbid,d1u,d1v); | |
813 | norm1 = d1u.Crossed(d1v); | |
814 | } | |
815 | if (tgline.DotCross(norm2,norm1) > 0.) { | |
816 | trans1 = IntSurf_Out; | |
817 | trans2 = IntSurf_In; | |
818 | } | |
819 | else { | |
820 | trans1 = IntSurf_In; | |
821 | trans2 = IntSurf_Out; | |
822 | } | |
823 | ||
824 | // | |
825 | Standard_Real AnU1,AnU2,AnV2; | |
826 | ||
827 | GeomAbs_SurfaceType typQuad = Quad.TypeQuadric(); | |
828 | Standard_Boolean arecadr=Standard_False; | |
829 | valpt = thelin->Value(1).Value(); | |
830 | Quad.Parameters(valpt,AnU1,V1); | |
831 | ||
832 | if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin; | |
833 | if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax; | |
834 | ||
835 | if(reversed) { | |
836 | thelin->SetUV(1,Standard_False,AnU1,V1); //-- on va lire u2,v2 | |
837 | thelin->Value(1).ParametersOnS1(AnU2,AnV2); | |
838 | } | |
839 | else { | |
840 | thelin->SetUV(1,Standard_True,AnU1,V1); //-- on va lire u1,v1 | |
841 | thelin->Value(1).ParametersOnS2(AnU2,AnV2); | |
842 | } | |
843 | ||
844 | if(typQuad==GeomAbs_Cylinder || | |
845 | typQuad==GeomAbs_Cone || | |
846 | typQuad==GeomAbs_Sphere) { | |
847 | arecadr=Standard_True; | |
848 | } | |
849 | // | |
850 | for (k=2; k<=Nbpts; ++k) { | |
851 | valpt = thelin->Value(k).Value(); | |
852 | Quad.Parameters(valpt,U1,V1); | |
853 | // | |
854 | if((V1 < Vmin) && (Vmin-V1 < TolV)) { | |
855 | V1 = Vmin; | |
856 | } | |
857 | if((V1 > Vmax) && (V1-Vmax < TolV)) { | |
858 | V1 = Vmax; | |
859 | } | |
860 | // | |
861 | if(arecadr) { | |
862 | //modified by NIZNHY-PKV Fri Mar 28 15:06:01 2008f | |
863 | Standard_Real aCf, aTwoPI; | |
864 | // | |
865 | aCf=0.; | |
866 | aTwoPI=M_PI+M_PI; | |
867 | if ((U1-AnU1) > 1.5*M_PI) { | |
868 | while ((U1-AnU1) > (1.5*M_PI+aCf*aTwoPI)) { | |
869 | aCf=aCf+1.; | |
870 | } | |
871 | U1=U1-aCf*aTwoPI; | |
872 | } | |
873 | // | |
874 | else { | |
875 | while ((U1-AnU1) < (-1.5*M_PI-aCf*aTwoPI)) { | |
876 | aCf=aCf+1.; | |
877 | } | |
878 | U1=U1+aCf*aTwoPI; | |
879 | } | |
880 | // was: | |
881 | //if ((U1-AnU1) > 1.5*M_PI) { | |
882 | // U1-=M_PI+M_PI; | |
883 | //} | |
884 | //else if ((U1-AnU1) < -1.5*M_PI) { | |
885 | // U1+=M_PI+M_PI; | |
886 | //} | |
887 | //modified by NIZNHY-PKV Fri Mar 28 15:06:11 2008t | |
888 | } | |
889 | // | |
890 | if(reversed) { | |
891 | thelin->SetUV(k,Standard_False,U1,V1); | |
892 | ||
893 | thelin->Value(k).ParametersOnS1(U2,V2); | |
894 | switch(typeS1) { | |
895 | case GeomAbs_Cylinder: | |
896 | case GeomAbs_Cone: | |
897 | case GeomAbs_Sphere: | |
898 | case GeomAbs_Torus: | |
899 | while(U2<(AnU2-1.5*M_PI)) U2+=M_PI+M_PI; | |
900 | while(U2>(AnU2+1.5*M_PI)) U2-=M_PI+M_PI; | |
901 | break; | |
902 | default: | |
903 | break; | |
904 | } | |
905 | if(typeS2==GeomAbs_Torus) { | |
906 | while(V2<(AnV2-1.5*M_PI)) V2+=M_PI+M_PI; | |
907 | while(V2>(AnV2+1.5*M_PI)) V2-=M_PI+M_PI; | |
908 | } | |
909 | thelin->SetUV(k,Standard_True,U2,V2); | |
910 | } | |
911 | else { | |
912 | thelin->SetUV(k,Standard_True,U1,V1); | |
913 | ||
914 | thelin->Value(k).ParametersOnS2(U2,V2); | |
915 | switch(typeS2) { | |
916 | case GeomAbs_Cylinder: | |
917 | case GeomAbs_Cone: | |
918 | case GeomAbs_Sphere: | |
919 | case GeomAbs_Torus: | |
920 | while(U2<(AnU2-1.5*M_PI)) U2+=M_PI+M_PI; | |
921 | while(U2>(AnU2+1.5*M_PI)) U2-=M_PI+M_PI; | |
922 | break; | |
923 | default: | |
924 | break; | |
925 | } | |
926 | if(typeS2==GeomAbs_Torus) { | |
927 | while(V2<(AnV2-1.5*M_PI)) V2+=M_PI+M_PI; | |
928 | while(V2>(AnV2+1.5*M_PI)) V2-=M_PI+M_PI; | |
929 | } | |
930 | thelin->SetUV(k,Standard_False,U2,V2); | |
931 | ||
932 | } | |
933 | ||
934 | AnU1=U1; | |
935 | AnU2=U2; | |
936 | AnV2=V2; | |
937 | } | |
938 | // <-A | |
939 | wline = new IntPatch_WLine(thelin,Standard_False,trans1,trans2); | |
98974dcc | 940 | wline->SetCreatingWayInfo(IntPatch_WLine::IntPatch_WLImpPrm); |
191478a5 | 941 | |
77dbd1f1 | 942 | #ifdef INTPATCH_IMPPRMINTERSECTION_DEBUG |
943 | wline->Dump(0); | |
4e14c88f | 944 | #endif |
945 | ||
191478a5 | 946 | if ( iwline->HasFirstPoint() |
e618b526 | 947 | && iwline->IsTangentAtBegining() == Standard_False) |
948 | { | |
949 | indfirst = iwline->FirstPointIndex(); | |
950 | PPoint = seqpdep(indfirst); | |
951 | tgline = PPoint.Direction3d(); | |
952 | Standard_Integer themult = PPoint.Multiplicity(); | |
d4b867e6 | 953 | for (Standard_Integer i=NbPointRst; i>=1; i--) { |
e618b526 | 954 | if (Destination(i) == indfirst) { |
955 | if (!reversed) { //-- typeS1 = Pln || Cyl || Sph || Cone | |
956 | Quad.Parameters(PPoint.Value(),U1,V1); | |
957 | ||
958 | if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin; | |
959 | if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax; | |
960 | ||
961 | PPoint.Parameters(themult,U2,V2); | |
962 | Surf2->D1(U2,V2,ptbid,d1u,d1v); //-- @@@@ | |
963 | } | |
964 | else { //-- typeS1 != Pln && Cyl && Sph && Cone | |
965 | Quad.Parameters(PPoint.Value(),U2,V2); | |
191478a5 | 966 | |
e618b526 | 967 | if((V2 < Vmin) && (Vmin-V2 < TolV)) V2 = Vmin; |
968 | if((V2 > Vmax) && (V2-Vmax < TolV)) V2 = Vmax; | |
191478a5 | 969 | |
e618b526 | 970 | PPoint.Parameters(themult,U1,V1); |
971 | Surf1->D1(U1,V1,ptbid,d1u,d1v); //-- @@@@ | |
972 | } | |
191478a5 | 973 | |
e618b526 | 974 | VecNormale = d1u.Crossed(d1v); |
975 | //-- Modif du 27 Septembre 94 (Recadrage des pts U,V) | |
976 | ptdeb.SetValue(PPoint.Value(),TolArc,Standard_False); | |
977 | ptdeb.SetParameters(U1,V1,U2,V2); | |
978 | ptdeb.SetParameter(1.); | |
191478a5 | 979 | |
e618b526 | 980 | Recadre(reversed,typeS1,typeS2,ptdeb,iwline,1,U1,V1,U2,V2); |
191478a5 | 981 | |
e618b526 | 982 | currentarc = solrst.Point(i).Arc(); |
983 | currentparam = solrst.Point(i).Parameter(); | |
984 | currentarc->D1(currentparam,p2d,d2d); | |
985 | tgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
191478a5 | 986 | |
e618b526 | 987 | Standard_Real squaremagnitudeVecNormale = VecNormale.SquareMagnitude(); |
988 | if(squaremagnitudeVecNormale > 1e-13) { | |
989 | DirNormale=VecNormale; | |
990 | IntSurf::MakeTransition(tgline,tgrst,DirNormale,TLine,TArc); | |
991 | } | |
992 | else { | |
993 | TLine.SetValue(Standard_True,IntSurf_Undecided); | |
994 | TArc.SetValue(Standard_True,IntSurf_Undecided); | |
995 | } | |
191478a5 | 996 | |
e618b526 | 997 | ptdeb.SetArc(reversed,currentarc,currentparam,TLine,TArc); |
998 | if (!solrst.Point(i).IsNew()) { | |
999 | ptdeb.SetVertex(reversed,solrst.Point(i).Vertex()); | |
1000 | } | |
1001 | wline->AddVertex(ptdeb); | |
1002 | if (themult == 0) { | |
1003 | wline->SetFirstPoint(wline->NbVertex()); | |
191478a5 | 1004 | } |
e618b526 | 1005 | |
1006 | themult--; | |
191478a5 | 1007 | } |
e618b526 | 1008 | } |
191478a5 | 1009 | } |
e618b526 | 1010 | else if (iwline->IsTangentAtBegining()) |
1011 | { | |
191478a5 | 1012 | gp_Pnt psol = thelin->Value(1).Value(); |
1013 | thelin->Value(1).ParametersOnS1(U1,V1); | |
1014 | thelin->Value(1).ParametersOnS2(U2,V2); | |
1015 | ptdeb.SetValue(psol,TolArc,Standard_True); | |
1016 | ptdeb.SetParameters(U1,V1,U2,V2); | |
1017 | ptdeb.SetParameter(1.); | |
1018 | wline->AddVertex(ptdeb); | |
1019 | wline->SetFirstPoint(wline->NbVertex()); | |
1020 | } | |
e618b526 | 1021 | else |
1022 | { | |
191478a5 | 1023 | gp_Pnt psol = thelin->Value(1).Value(); |
1024 | thelin->Value(1).ParametersOnS1(U1,V1); | |
1025 | thelin->Value(1).ParametersOnS2(U2,V2); | |
1026 | ptdeb.SetValue(psol,TolArc,Standard_False); | |
1027 | ptdeb.SetParameters(U1,V1,U2,V2); | |
1028 | ptdeb.SetParameter(1.); | |
1029 | wline->AddVertex(ptdeb); | |
1030 | wline->SetFirstPoint(wline->NbVertex()); | |
1031 | } | |
1032 | ||
1033 | ||
1034 | if ( iwline->HasLastPoint() | |
e618b526 | 1035 | && iwline->IsTangentAtEnd() == Standard_False) |
1036 | { | |
1037 | indlast = iwline->LastPointIndex(); | |
1038 | PPoint = seqpdep(indlast); | |
1039 | tgline = PPoint.Direction3d().Reversed(); | |
1040 | Standard_Integer themult = PPoint.Multiplicity(); | |
d4b867e6 | 1041 | for (Standard_Integer i=NbPointRst; i >=1; i--) { |
e618b526 | 1042 | if (Destination(i) == indlast) { |
1043 | if (!reversed) { | |
1044 | Quad.Parameters(PPoint.Value(),U1,V1); | |
1045 | ||
1046 | if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin; | |
1047 | if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax; | |
1048 | ||
1049 | PPoint.Parameters(themult,U2,V2); | |
1050 | Surf2->D1(U2,V2,ptbid,d1u,d1v); //-- @@@@ | |
1051 | VecNormale = d1u.Crossed(d1v); //-- @@@@ | |
1052 | } | |
1053 | else { | |
1054 | Quad.Parameters(PPoint.Value(),U2,V2); | |
191478a5 | 1055 | |
e618b526 | 1056 | if((V2 < Vmin) && (Vmin-V2 < TolV)) V2 = Vmin; |
1057 | if((V2 > Vmax) && (V2-Vmax < TolV)) V2 = Vmax; | |
191478a5 | 1058 | |
e618b526 | 1059 | PPoint.Parameters(themult,U1,V1); |
1060 | Surf1->D1(U1,V1,ptbid,d1u,d1v); //-- @@@@ | |
1061 | VecNormale = d1u.Crossed(d1v); //-- @@@@ | |
1062 | } | |
191478a5 | 1063 | |
e618b526 | 1064 | ptfin.SetValue(PPoint.Value(),TolArc,Standard_False); |
1065 | ptfin.SetParameters(U1,V1,U2,V2); | |
1066 | ptfin.SetParameter(Nbpts); | |
191478a5 | 1067 | |
e618b526 | 1068 | Recadre(reversed,typeS1,typeS2,ptfin,iwline,Nbpts-1,U1,V1,U2,V2); |
191478a5 | 1069 | |
e618b526 | 1070 | currentarc = solrst.Point(i).Arc(); |
1071 | currentparam = solrst.Point(i).Parameter(); | |
1072 | currentarc->D1(currentparam,p2d,d2d); | |
1073 | tgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
191478a5 | 1074 | |
191478a5 | 1075 | |
e618b526 | 1076 | Standard_Real squaremagnitudeVecNormale = VecNormale.SquareMagnitude(); |
1077 | if(squaremagnitudeVecNormale > 1e-13) { | |
1078 | DirNormale=VecNormale; | |
1079 | IntSurf::MakeTransition(tgline,tgrst,DirNormale,TLine,TArc); | |
1080 | } | |
1081 | else { | |
1082 | TLine.SetValue(Standard_True,IntSurf_Undecided); | |
1083 | TArc.SetValue(Standard_True,IntSurf_Undecided); | |
1084 | } | |
191478a5 | 1085 | |
191478a5 | 1086 | |
e618b526 | 1087 | ptfin.SetArc(reversed,currentarc,currentparam,TLine,TArc); |
1088 | if (!solrst.Point(i).IsNew()) { | |
1089 | ptfin.SetVertex(reversed,solrst.Point(i).Vertex()); | |
191478a5 | 1090 | } |
e618b526 | 1091 | wline->AddVertex(ptfin); |
1092 | if (themult == 0) { | |
1093 | wline->SetLastPoint(wline->NbVertex()); | |
1094 | } | |
1095 | ||
1096 | themult--; | |
191478a5 | 1097 | } |
e618b526 | 1098 | } |
191478a5 | 1099 | } |
e618b526 | 1100 | else if (iwline->IsTangentAtEnd()) |
1101 | { | |
191478a5 | 1102 | gp_Pnt psol = thelin->Value(Nbpts).Value(); |
1103 | thelin->Value(Nbpts).ParametersOnS1(U1,V1); | |
1104 | thelin->Value(Nbpts).ParametersOnS2(U2,V2); | |
1105 | ptfin.SetValue(psol,TolArc,Standard_True); | |
1106 | ptfin.SetParameters(U1,V1,U2,V2); | |
1107 | ptfin.SetParameter(Nbpts); | |
1108 | wline->AddVertex(ptfin); | |
1109 | wline->SetLastPoint(wline->NbVertex()); | |
1110 | } | |
e618b526 | 1111 | else |
1112 | { | |
191478a5 | 1113 | gp_Pnt psol = thelin->Value(Nbpts).Value(); |
1114 | thelin->Value(Nbpts).ParametersOnS1(U1,V1); | |
1115 | thelin->Value(Nbpts).ParametersOnS2(U2,V2); | |
1116 | ptfin.SetValue(psol,TolArc,Standard_False); | |
1117 | ptfin.SetParameters(U1,V1,U2,V2); | |
1118 | ptfin.SetParameter(Nbpts); | |
1119 | wline->AddVertex(ptfin); | |
1120 | wline->SetLastPoint(wline->NbVertex()); | |
1121 | } | |
1122 | // | |
1123 | // Il faut traiter les points de passage. | |
1124 | slin.Append(wline); | |
7fd59977 | 1125 | }// if(Nbpts>=2) { |
1126 | }// for (j=1; j<=Nblines; j++) { | |
1127 | ||
1128 | // ON GERE LES RACCORDS ENTRE LIGNES. ELLE NE PEUVENT SE RACCORDER | |
1129 | // QUE SUR DES POINTS DE TANGENCE | |
1130 | ||
1131 | ||
1132 | Nblines = slin.Length(); | |
d4b867e6 | 1133 | for (Standard_Integer j=1; j<=Nblines-1; j++) { |
7fd59977 | 1134 | dofirst = dolast = Standard_False; |
1135 | const Handle(IntPatch_Line)& slinj = slin(j); | |
c5f3a425 | 1136 | Handle(IntPatch_WLine) wlin1 (Handle(IntPatch_WLine)::DownCast (slinj)); |
7fd59977 | 1137 | if (wlin1->HasFirstPoint()) { |
191478a5 | 1138 | ptdeb = wlin1->FirstPoint(indfirst); |
1139 | if (ptdeb.IsTangencyPoint()) { | |
1140 | dofirst = Standard_True; | |
1141 | } | |
7fd59977 | 1142 | } |
1143 | if (wlin1->HasLastPoint()) { | |
191478a5 | 1144 | ptfin = wlin1->LastPoint(indlast); |
1145 | if (ptfin.IsTangencyPoint()) { | |
1146 | dolast = Standard_True; | |
1147 | } | |
7fd59977 | 1148 | } |
191478a5 | 1149 | |
7fd59977 | 1150 | if (dofirst || dolast) { |
d4b867e6 | 1151 | for (Standard_Integer k=j+1; k<=Nblines;k++) { |
191478a5 | 1152 | const Handle(IntPatch_Line)& slink = slin(k); |
c5f3a425 | 1153 | Handle(IntPatch_WLine) wlin2 (Handle(IntPatch_WLine)::DownCast (slink)); |
191478a5 | 1154 | if (wlin2->HasFirstPoint()) { |
1155 | ptbis = wlin2->FirstPoint(ind2); | |
1156 | if (ptbis.IsTangencyPoint()) { | |
1157 | if (dofirst ) { | |
1158 | if (ptdeb.Value().Distance(ptbis.Value()) <= TolArc) { | |
1159 | ptdeb.SetMultiple(Standard_True); | |
1160 | if (!ptbis.IsMultiple()) { | |
1161 | ptbis.SetMultiple(Standard_True); | |
1162 | wlin2->Replace(ind2,ptbis); | |
1163 | } | |
1164 | } | |
1165 | } | |
1166 | if (dolast ) { | |
1167 | if (ptfin.Value().Distance(ptbis.Value()) <= TolArc) { | |
1168 | ptfin.SetMultiple(Standard_True); | |
1169 | if (!ptbis.IsMultiple()) { | |
1170 | ptbis.SetMultiple(Standard_True); | |
1171 | wlin2->Replace(ind2,ptbis); | |
1172 | } | |
1173 | } | |
1174 | } | |
1175 | } | |
1176 | } | |
1177 | if (wlin2->HasLastPoint()) { | |
1178 | ptbis = wlin2->LastPoint(ind2); | |
1179 | if (ptbis.IsTangencyPoint()) { | |
1180 | if (dofirst ) { | |
1181 | if (ptdeb.Value().Distance(ptbis.Value()) <= TolArc) { | |
1182 | ptdeb.SetMultiple(Standard_True); | |
1183 | if (!ptbis.IsMultiple()) { | |
1184 | ptbis.SetMultiple(Standard_True); | |
1185 | wlin2->Replace(ind2,ptbis); | |
1186 | } | |
1187 | } | |
1188 | } | |
1189 | if (dolast ) { | |
1190 | if (ptfin.Value().Distance(ptbis.Value()) <= TolArc) { | |
1191 | ptfin.SetMultiple(Standard_True); | |
1192 | if (!ptbis.IsMultiple()) { | |
1193 | ptbis.SetMultiple(Standard_True); | |
1194 | wlin2->Replace(ind2,ptbis); | |
1195 | } | |
1196 | } | |
1197 | } | |
1198 | } | |
1199 | } | |
1200 | } | |
1201 | if(dofirst) | |
1202 | wlin1->Replace(indfirst,ptdeb); | |
1203 | if(dolast) | |
1204 | wlin1->Replace(indlast,ptfin); | |
7fd59977 | 1205 | } |
1206 | } | |
1207 | }// if (seqpdep.Length() != 0 || seqpins.Length() != 0) { | |
1208 | // | |
1209 | // Treatment the segments | |
1210 | NbSegm = solrst.NbSegments(); | |
1211 | if (NbSegm) { | |
d4b867e6 | 1212 | for(Standard_Integer i=1; i<=NbSegm; i++) { |
7fd59977 | 1213 | thesegm = solrst.Segment(i); |
e618b526 | 1214 | //Check if segment is degenerated |
1215 | if(thesegm.HasFirstPoint() && thesegm.HasLastPoint()) | |
1216 | { | |
1217 | Standard_Real tol2 = Precision::Confusion(); | |
1218 | tol2 *= tol2; | |
1219 | const gp_Pnt& aPf = thesegm.FirstPoint().Value(); | |
1220 | const gp_Pnt& aPl = thesegm.LastPoint().Value(); | |
1221 | if(aPf.SquareDistance(aPl) <= tol2) | |
1222 | { | |
1223 | //segment can be degenerated - check inner point | |
1224 | paramf = thesegm.FirstPoint().Parameter(); | |
1225 | paraml = thesegm.LastPoint().Parameter(); | |
1226 | gp_Pnt2d _p2d = | |
1227 | thesegm.Curve()->Value(.57735 * paramf + 0.42265 * paraml); | |
1228 | gp_Pnt aPm; | |
1229 | if(reversed) | |
1230 | { | |
1231 | Surf1->D0(_p2d.X(), _p2d.Y(), aPm); | |
1232 | } | |
1233 | else | |
1234 | { | |
1235 | Surf2->D0(_p2d.X(), _p2d.Y(), aPm); | |
1236 | } | |
1237 | if(aPm.SquareDistance(aPf) <= tol2) | |
1238 | { | |
1239 | //Degenerated | |
1240 | continue; | |
1241 | } | |
1242 | } | |
1243 | } | |
1244 | ||
1245 | ||
7fd59977 | 1246 | //---------------------------------------------------------------------- |
1247 | // on cree une ligne d intersection contenant uniquement le segment. | |
1248 | // VOIR POUR LA TRANSITION DE LA LIGNE | |
1249 | // On ajoute aussi un polygone pour le traitement des intersections | |
1250 | // entre ligne et restrictions de la surface implicite (PutVertexOnLine) | |
1251 | //---------------------------------------------------------------------- | |
1252 | //-- Calcul de la transition sur la rline (12 fev 97) | |
1253 | //-- reversed a le sens de OnFirst | |
1254 | //-- | |
1255 | dofirst = dolast = Standard_False; | |
1256 | procf = Standard_False; | |
1257 | procl = Standard_False; | |
1258 | IntSurf_Transition TLineUnk,TArcUnk; | |
1259 | ||
1260 | IntPatch_Point _thepointAtBeg; | |
1261 | IntPatch_Point _thepointAtEnd; | |
191478a5 | 1262 | |
7fd59977 | 1263 | Standard_Boolean TransitionOK=Standard_False; |
1264 | ||
1265 | if(thesegm.HasFirstPoint()) { | |
191478a5 | 1266 | Standard_Real _u1,_v1,_u2,_v2; |
1267 | ||
1268 | dofirst = Standard_True; | |
1269 | PStartf = thesegm.FirstPoint(); | |
1270 | paramf = PStartf.Parameter(); | |
1271 | ||
1272 | gp_Pnt2d _p2d = thesegm.Curve()->Value(paramf); | |
1273 | Handle(Adaptor3d_HVertex) _vtx; | |
1274 | if(PStartf.IsNew()==Standard_False) | |
1275 | _vtx= PStartf.Vertex(); | |
1276 | const gp_Pnt& _Pp = PStartf.Value(); | |
1277 | _thepointAtBeg.SetValue(_Pp,PStartf.Tolerance(),Standard_False); | |
1278 | if (!reversed) { //-- typeS1 = Pln || Cyl || Sph || Cone | |
1279 | Quad.Parameters(_Pp,_u1,_v1); | |
1280 | _u2=_p2d.X(); _v2=_p2d.Y(); | |
1281 | } | |
1282 | else { //-- typeS1 != Pln && Cyl && Sph && Cone | |
1283 | Quad.Parameters(_Pp,_u2,_v2); | |
1284 | _u1=_p2d.X(); _v1=_p2d.Y(); | |
1285 | } | |
1286 | _thepointAtBeg.SetParameters(_u1,_v1,_u2,_v2); | |
1287 | _thepointAtBeg.SetParameter(paramf); | |
1288 | if(PStartf.IsNew()==Standard_False) | |
1289 | _thepointAtBeg.SetVertex(reversed,_vtx); | |
1290 | _thepointAtBeg.SetArc(reversed,thesegm.Curve(),paramf,TLineUnk,TArcUnk); | |
1291 | ||
1292 | ||
1293 | gp_Vec d1u1,d1v1,d1u2,d1v2; gp_Vec2d _d2d; | |
1294 | Surf1->D1(_u1,_v1,ptbid,d1u1,d1v1); | |
1295 | norm1 = d1u1.Crossed(d1v1); | |
1296 | Surf2->D1(_u2,_v2,ptbid,d1u2,d1v2); | |
1297 | norm2 = d1u2.Crossed(d1v2); | |
1298 | ||
1299 | thesegm.Curve()->D1(paramf,_p2d,_d2d); | |
1300 | if(reversed) { | |
1301 | tgline.SetLinearForm(_d2d.X(),d1u1,_d2d.Y(),d1v1); | |
1302 | } | |
1303 | else { | |
1304 | tgline.SetLinearForm(_d2d.X(),d1u2,_d2d.Y(),d1v2); | |
1305 | } | |
1306 | _u1=tgline.DotCross(norm2,norm1); | |
1307 | TransitionOK=Standard_True; | |
1308 | if (_u1 > 0.00000001) { | |
1309 | trans1 = IntSurf_Out; | |
1310 | trans2 = IntSurf_In; | |
1311 | } | |
1312 | else if(_u1 < -0.00000001) { | |
1313 | trans1 = IntSurf_In; | |
1314 | trans2 = IntSurf_Out; | |
1315 | } | |
1316 | else { | |
1317 | TransitionOK=Standard_False; | |
1318 | } | |
7fd59977 | 1319 | } |
1320 | if(thesegm.HasLastPoint()) { | |
191478a5 | 1321 | Standard_Real _u1,_v1,_u2,_v2; |
1322 | ||
1323 | dolast = Standard_True; | |
1324 | PStartl = thesegm.LastPoint(); | |
1325 | paraml = PStartl.Parameter(); | |
1326 | ||
1327 | gp_Pnt2d _p2d = thesegm.Curve()->Value(paraml); | |
1328 | Handle(Adaptor3d_HVertex) _vtx; | |
1329 | if(PStartl.IsNew()==Standard_False) | |
1330 | _vtx = PStartl.Vertex(); | |
1331 | const gp_Pnt& _Pp = PStartl.Value(); | |
1332 | IntPatch_Point _thepoint; | |
1333 | _thepointAtEnd.SetValue(_Pp,PStartl.Tolerance(),Standard_False); | |
1334 | if (!reversed) { //-- typeS1 = Pln || Cyl || Sph || Cone | |
1335 | Quad.Parameters(_Pp,_u1,_v1); | |
1336 | _u2=_p2d.X(); _v2=_p2d.Y(); | |
1337 | } | |
1338 | else { //-- typeS1 != Pln && Cyl && Sph && Cone | |
1339 | Quad.Parameters(_Pp,_u2,_v2); | |
1340 | _u1=_p2d.X(); _v1=_p2d.Y(); | |
1341 | } | |
1342 | _thepointAtEnd.SetParameters(_u1,_v1,_u2,_v2); | |
1343 | _thepointAtEnd.SetParameter(paraml); | |
1344 | if(PStartl.IsNew()==Standard_False) | |
1345 | _thepointAtEnd.SetVertex(reversed,_vtx); | |
1346 | _thepointAtEnd.SetArc(reversed,thesegm.Curve(),paraml,TLineUnk,TArcUnk); | |
1347 | ||
1348 | ||
1349 | ||
1350 | gp_Vec d1u1,d1v1,d1u2,d1v2; gp_Vec2d _d2d; | |
1351 | Surf1->D1(_u1,_v1,ptbid,d1u1,d1v1); | |
1352 | norm1 = d1u1.Crossed(d1v1); | |
1353 | Surf2->D1(_u2,_v2,ptbid,d1u2,d1v2); | |
1354 | norm2 = d1u2.Crossed(d1v2); | |
1355 | ||
1356 | thesegm.Curve()->D1(paraml,_p2d,_d2d); | |
1357 | if(reversed) { | |
1358 | tgline.SetLinearForm(_d2d.X(),d1u1,_d2d.Y(),d1v1); | |
1359 | } | |
1360 | else { | |
1361 | tgline.SetLinearForm(_d2d.X(),d1u2,_d2d.Y(),d1v2); | |
1362 | } | |
1363 | _u1=tgline.DotCross(norm2,norm1); | |
1364 | TransitionOK=Standard_True; | |
1365 | if (_u1 > 0.00000001) { | |
1366 | trans1 = IntSurf_Out; | |
1367 | trans2 = IntSurf_In; | |
1368 | } | |
1369 | else if(_u1 < -0.00000001) { | |
1370 | trans1 = IntSurf_In; | |
1371 | trans2 = IntSurf_Out; | |
1372 | } | |
1373 | else { | |
1374 | TransitionOK=Standard_False; | |
1375 | } | |
7fd59977 | 1376 | } |
1377 | if(TransitionOK==Standard_False) { | |
191478a5 | 1378 | //-- rline = new IntPatch_RLine (thesegm.Curve(),reversed,Standard_False); |
1379 | rline = new IntPatch_RLine (Standard_False); | |
1380 | if(reversed) { | |
1381 | rline->SetArcOnS1(thesegm.Curve()); | |
1382 | } | |
1383 | else { | |
1384 | rline->SetArcOnS2(thesegm.Curve()); | |
1385 | } | |
7fd59977 | 1386 | } |
1387 | else { | |
191478a5 | 1388 | //-- rline = new IntPatch_RLine (thesegm.Curve(),reversed,Standard_False,trans1,trans2); |
1389 | rline = new IntPatch_RLine (Standard_False,trans1,trans2); | |
1390 | if(reversed) { | |
1391 | rline->SetArcOnS1(thesegm.Curve()); | |
1392 | } | |
1393 | else { | |
1394 | rline->SetArcOnS2(thesegm.Curve()); | |
1395 | } | |
7fd59977 | 1396 | } |
1397 | ||
1398 | //------------------------------ | |
1399 | //-- Ajout des points | |
1400 | //-- | |
1401 | if (thesegm.HasFirstPoint()) { | |
191478a5 | 1402 | rline->AddVertex(_thepointAtBeg); |
1403 | rline->SetFirstPoint(rline->NbVertex()); | |
7fd59977 | 1404 | } |
191478a5 | 1405 | |
7fd59977 | 1406 | if (thesegm.HasLastPoint()) { |
191478a5 | 1407 | rline->AddVertex(_thepointAtEnd); |
1408 | rline->SetLastPoint(rline->NbVertex()); | |
7fd59977 | 1409 | } |
1410 | ||
1411 | // Polygone sur restriction solution | |
1412 | if (dofirst && dolast) { | |
191478a5 | 1413 | Standard_Real prm; |
1414 | gp_Pnt ptpoly; | |
1415 | IntSurf_PntOn2S p2s; | |
1416 | Handle(IntSurf_LineOn2S) Thelin = new IntSurf_LineOn2S (); | |
b2fedee6 | 1417 | const Handle(Adaptor2d_Curve2d)& arcsegm = thesegm.Curve(); |
191478a5 | 1418 | Standard_Integer nbsample = 100; |
1419 | ||
1420 | if (!reversed) { | |
d4b867e6 | 1421 | for (Standard_Integer j=1; j<=nbsample; j++) { |
191478a5 | 1422 | prm = paramf + (j-1)*(paraml-paramf)/(nbsample-1); |
1423 | arcsegm->D0(prm,p2d); | |
1424 | Surf2->D0(p2d.X(),p2d.Y(),ptpoly); | |
1425 | ||
1426 | Quad.Parameters(ptpoly,U1,V1); | |
1427 | p2s.SetValue(ptpoly,U1,V1,p2d.X(),p2d.Y()); | |
1428 | Thelin->Add(p2s); | |
1429 | } | |
1430 | } | |
1431 | else { | |
d4b867e6 | 1432 | for (Standard_Integer j=1; j<=nbsample; j++) { |
191478a5 | 1433 | prm = paramf + (j-1)*(paraml-paramf)/(nbsample-1); |
1434 | arcsegm->D0(prm,p2d); | |
1435 | Surf1->D0(p2d.X(),p2d.Y(),ptpoly); | |
1436 | ||
1437 | Quad.Parameters(ptpoly,U2,V2); | |
1438 | p2s.SetValue(ptpoly,p2d.X(),p2d.Y(),U2,V2); | |
1439 | Thelin->Add(p2s); | |
1440 | } | |
1441 | } | |
1442 | rline->Add(Thelin); | |
7fd59977 | 1443 | } |
1444 | ||
1445 | if (dofirst || dolast) { | |
191478a5 | 1446 | Nblines = slin.Length(); |
d4b867e6 | 1447 | for (Standard_Integer j=1; j<=Nblines; j++) { |
191478a5 | 1448 | const Handle(IntPatch_Line)& slinj = slin(j); |
1449 | typ = slinj->ArcType(); | |
1450 | if (typ == IntPatch_Walking) { | |
c5f3a425 | 1451 | Nbpts = Handle(IntPatch_WLine)::DownCast (slinj)->NbVertex(); |
191478a5 | 1452 | } |
1453 | else { | |
c5f3a425 | 1454 | Nbpts = Handle(IntPatch_RLine)::DownCast (slinj)->NbVertex(); |
191478a5 | 1455 | } |
d4b867e6 | 1456 | for (Standard_Integer k=1; k<=Nbpts;k++) { |
191478a5 | 1457 | if (typ == IntPatch_Walking) { |
c5f3a425 | 1458 | ptdeb = Handle(IntPatch_WLine)::DownCast (slinj)->Vertex(k); |
191478a5 | 1459 | } |
1460 | else { | |
c5f3a425 | 1461 | ptdeb = Handle(IntPatch_RLine)::DownCast (slinj)->Vertex(k); |
191478a5 | 1462 | } |
1463 | if (dofirst) { | |
1464 | ||
1465 | if (ptdeb.Value().Distance(PStartf.Value()) <=TolArc) { | |
1466 | ptdeb.SetMultiple(Standard_True); | |
1467 | if (typ == IntPatch_Walking) { | |
c5f3a425 | 1468 | Handle(IntPatch_WLine)::DownCast (slinj)->Replace(k,ptdeb); |
191478a5 | 1469 | } |
1470 | else { | |
c5f3a425 | 1471 | Handle(IntPatch_RLine)::DownCast (slinj)->Replace(k,ptdeb); |
191478a5 | 1472 | } |
1473 | ptdeb.SetParameter(paramf); | |
1474 | rline->AddVertex(ptdeb); | |
1475 | if (!procf){ | |
1476 | procf=Standard_True; | |
1477 | rline->SetFirstPoint(rline->NbVertex()); | |
1478 | } | |
1479 | } | |
1480 | } | |
1481 | if (dolast) { | |
1482 | if(dofirst) { //-- on recharge le ptdeb | |
1483 | if (typ == IntPatch_Walking) { | |
c5f3a425 | 1484 | ptdeb = Handle(IntPatch_WLine)::DownCast (slinj)->Vertex(k); |
191478a5 | 1485 | } |
1486 | else { | |
c5f3a425 | 1487 | ptdeb = Handle(IntPatch_RLine)::DownCast (slinj)->Vertex(k); |
191478a5 | 1488 | } |
1489 | } | |
1490 | if (ptdeb.Value().Distance(PStartl.Value()) <=TolArc) { | |
1491 | ptdeb.SetMultiple(Standard_True); | |
1492 | if (typ == IntPatch_Walking) { | |
c5f3a425 | 1493 | Handle(IntPatch_WLine)::DownCast (slinj)->Replace(k,ptdeb); |
191478a5 | 1494 | } |
1495 | else { | |
c5f3a425 | 1496 | Handle(IntPatch_RLine)::DownCast (slinj)->Replace(k,ptdeb); |
191478a5 | 1497 | } |
1498 | ptdeb.SetParameter(paraml); | |
1499 | rline->AddVertex(ptdeb); | |
1500 | if (!procl){ | |
1501 | procl=Standard_True; | |
1502 | rline->SetLastPoint(rline->NbVertex()); | |
1503 | } | |
1504 | } | |
1505 | } | |
1506 | } | |
1507 | } | |
7fd59977 | 1508 | } |
1509 | slin.Append(rline); | |
1510 | } | |
1511 | }// if (NbSegm) | |
1512 | // | |
1513 | // on traite les restrictions de la surface implicite | |
71958f7d | 1514 | |
1515 | for (Standard_Integer i=1, aNbLin = slin.Length(); i<=aNbLin; i++) | |
7fd59977 | 1516 | { |
f73c584c | 1517 | Handle(IntPatch_PointLine) aL = Handle(IntPatch_PointLine)::DownCast(slin(i)); |
d4b867e6 | 1518 | |
7fd59977 | 1519 | if (!reversed) |
d4b867e6 | 1520 | IntPatch_RstInt::PutVertexOnLine(aL,Surf1,D1,Surf2,Standard_True,TolTang); |
7fd59977 | 1521 | else |
d4b867e6 | 1522 | IntPatch_RstInt::PutVertexOnLine(aL,Surf2,D2,Surf1,Standard_False,TolTang); |
71958f7d | 1523 | |
f73c584c | 1524 | if (aL->NbPnts() <= 2) |
1525 | { | |
1526 | Standard_Boolean aCond = aL->NbPnts() < 2; | |
1527 | if (!aCond) | |
1528 | aCond = (aL->Point(1).IsSame(aL->Point(2), Precision::Confusion())); | |
1529 | ||
1530 | if (aCond) | |
1531 | { | |
1532 | slin.Remove(i); | |
1533 | i--; | |
1534 | aNbLin--; | |
1535 | continue; | |
1536 | } | |
1537 | } | |
1538 | ||
71958f7d | 1539 | if(aL->ArcType() == IntPatch_Walking) |
1540 | { | |
1541 | const Handle(IntPatch_WLine) aWL = Handle(IntPatch_WLine)::DownCast(aL); | |
1542 | slin.Append(aWL); | |
1543 | slin.Remove(i); | |
1544 | i--; | |
1545 | aNbLin--; | |
1546 | } | |
7fd59977 | 1547 | } |
d4b867e6 | 1548 | |
71958f7d | 1549 | // Now slin is filled as follows: lower indices correspond to Restriction line, |
1550 | // after (higher indices) - only Walking-line. | |
1551 | ||
1fbf69bb | 1552 | const Standard_Real aTol3d = Max(Func.Tolerance(), TolTang); |
c22b52d6 | 1553 | const Handle(Adaptor3d_Surface)& aQSurf = (reversed) ? Surf2 : Surf1; |
1554 | const Handle(Adaptor3d_Surface)& anOtherSurf = (reversed) ? Surf1 : Surf2; | |
d4b867e6 | 1555 | |
1556 | for (Standard_Integer i = 1; i <= slin.Length(); i++) | |
1557 | { | |
77dbd1f1 | 1558 | const Handle(IntPatch_PointLine)& aL1 = Handle(IntPatch_PointLine)::DownCast(slin(i)); |
1559 | const Handle(IntPatch_RLine)& aRL1 = Handle(IntPatch_RLine)::DownCast(aL1); | |
1560 | ||
1561 | if(aRL1.IsNull()) | |
1562 | { | |
1563 | //Walking-Walking cases are not supported | |
1564 | break; | |
1565 | } | |
1566 | ||
c22b52d6 | 1567 | const Handle(Adaptor2d_Curve2d)& anArc = aRL1->IsArcOnS1() ? |
77dbd1f1 | 1568 | aRL1->ArcOnS1() : |
1569 | aRL1->ArcOnS2(); | |
c22b52d6 | 1570 | if(anArc->GetType() != GeomAbs_Line) |
77dbd1f1 | 1571 | { |
1572 | //Restriction line must be isoline. | |
1573 | //Other cases are not supported by | |
1574 | //existing algorithms. | |
1575 | ||
1576 | break; | |
1577 | } | |
1578 | ||
1579 | Standard_Boolean isFirstDeleted = Standard_False; | |
1580 | ||
d4b867e6 | 1581 | for(Standard_Integer j = i + 1; j <= slin.Length(); j++) |
1582 | { | |
d4b867e6 | 1583 | Handle(IntPatch_PointLine) aL2 = Handle(IntPatch_PointLine)::DownCast(slin(j)); |
d4b867e6 | 1584 | Handle(IntPatch_RLine) aRL2 = Handle(IntPatch_RLine)::DownCast(aL2); |
1585 | ||
71958f7d | 1586 | //Here aL1 (i-th line) is Restriction-line and aL2 (j-th line) is |
1587 | //Restriction or Walking | |
d4b867e6 | 1588 | |
77dbd1f1 | 1589 | if(!aRL2.IsNull()) |
1590 | { | |
c22b52d6 | 1591 | const Handle(Adaptor2d_Curve2d)& anArc2 = aRL2->IsArcOnS1() ? |
d677b214 | 1592 | aRL2->ArcOnS1() : |
1593 | aRL2->ArcOnS2(); | |
c22b52d6 | 1594 | if(anArc2->GetType() != GeomAbs_Line) |
d4b867e6 | 1595 | { |
77dbd1f1 | 1596 | //Restriction line must be isoline. |
1597 | //Other cases are not supported by | |
1598 | //existing algorithms. | |
d4b867e6 | 1599 | |
77dbd1f1 | 1600 | continue; |
d4b867e6 | 1601 | } |
77dbd1f1 | 1602 | } |
d4b867e6 | 1603 | |
77dbd1f1 | 1604 | //aDir can be equal to one of following four values only |
1605 | //(because Reastriction line is boundary of rectangular surface): | |
1606 | //either {0, 1} or {0, -1} or {1, 0} or {-1, 0}. | |
c22b52d6 | 1607 | const gp_Dir2d aDir = anArc->Line().Direction(); |
d4b867e6 | 1608 | |
77dbd1f1 | 1609 | Standard_Real aTol2d = anOtherSurf->UResolution(aTol3d), |
1610 | aPeriod = anOtherSurf->IsVPeriodic() ? anOtherSurf->VPeriod() : 0.0; | |
d4b867e6 | 1611 | |
77dbd1f1 | 1612 | if(Abs(aDir.X()) < 0.5) |
1613 | {//Restriction directs along V-direction | |
1614 | aTol2d = anOtherSurf->VResolution(aTol3d); | |
1615 | aPeriod = anOtherSurf->IsUPeriodic() ? anOtherSurf->UPeriod() : 0.0; | |
d4b867e6 | 1616 | } |
1617 | ||
77dbd1f1 | 1618 | const Standard_Boolean isCoincide = IsCoincide(Func, aL2, anArc, aRL1->IsArcOnS1(), |
1619 | aTol3d, aTol2d, aPeriod); | |
d4b867e6 | 1620 | |
1621 | if(isCoincide) | |
77dbd1f1 | 1622 | { |
1623 | if(aRL2.IsNull()) | |
1624 | {//Delete Walking-line | |
1625 | slin.Remove(j); | |
1626 | j--; | |
1627 | } | |
1628 | else | |
1629 | {//Restriction-Restriction | |
c22b52d6 | 1630 | const Handle(Adaptor2d_Curve2d)& anArc2 = aRL2->IsArcOnS1() ? |
77dbd1f1 | 1631 | aRL2->ArcOnS1() : |
1632 | aRL2->ArcOnS2(); | |
1633 | ||
1634 | const Standard_Real aRange2 = anArc2->LastParameter() - | |
1635 | anArc2->FirstParameter(); | |
1636 | const Standard_Real aRange1 = anArc->LastParameter() - | |
1637 | anArc->FirstParameter(); | |
1638 | ||
1639 | if(aRange2 > aRange1) | |
1640 | { | |
1641 | isFirstDeleted = Standard_True; | |
1642 | break; | |
1643 | } | |
1644 | else | |
1645 | {//Delete j-th line | |
1646 | slin.Remove(j); | |
1647 | j--; | |
1648 | } | |
1649 | } | |
d4b867e6 | 1650 | } |
77dbd1f1 | 1651 | } //for(Standard_Integer j = i + 1; j <= slin.Length(); j++) |
1652 | ||
1653 | if(isFirstDeleted) | |
1654 | {//Delete i-th line | |
1655 | slin.Remove(i--); | |
d4b867e6 | 1656 | } |
77dbd1f1 | 1657 | }//for (Standard_Integer i = 1; i <= slin.Length(); i++) |
d4b867e6 | 1658 | |
7fd59977 | 1659 | empt = (slin.Length() == 0 && spnt.Length() == 0); |
1660 | done = Standard_True; | |
d4b867e6 | 1661 | |
7fd59977 | 1662 | |
191478a5 | 1663 | if(slin.Length() == 0) |
1664 | return; | |
7fd59977 | 1665 | |
191478a5 | 1666 | Standard_Boolean isDecomposeRequired = (Quad.TypeQuadric() == GeomAbs_Cone) || |
a09c8f3a | 1667 | (Quad.TypeQuadric() == GeomAbs_Sphere) || |
1668 | (Quad.TypeQuadric() == GeomAbs_Cylinder) || | |
1669 | (Quad.TypeQuadric() == GeomAbs_Torus); | |
7fd59977 | 1670 | |
191478a5 | 1671 | if(!isDecomposeRequired) |
1672 | return; | |
7fd59977 | 1673 | |
d4b867e6 | 1674 | // post processing for cones and spheres |
1675 | ||
191478a5 | 1676 | const Handle(Adaptor3d_TopolTool)& PDomain = (reversed) ? D1 : D2; |
7fd59977 | 1677 | |
191478a5 | 1678 | IntPatch_SequenceOfLine dslin; |
1679 | Standard_Boolean isDecompose = Standard_False; | |
d4b867e6 | 1680 | for(Standard_Integer i = 1; i <= slin.Length(); i++ ) |
191478a5 | 1681 | { |
77dbd1f1 | 1682 | if(DecomposeResult( Handle(IntPatch_PointLine)::DownCast(slin(i)), |
1683 | reversed, Quad, PDomain, aQSurf, | |
a09c8f3a | 1684 | anOtherSurf, TolArc, aTol3d, dslin)) |
191478a5 | 1685 | { |
1686 | isDecompose = Standard_True; | |
7fd59977 | 1687 | } |
7fd59977 | 1688 | } |
1689 | ||
191478a5 | 1690 | if(!isDecompose) |
1691 | return; | |
1692 | ||
1693 | slin.Clear(); | |
d4b867e6 | 1694 | for(Standard_Integer i = 1; i <= dslin.Length(); i++ ) |
191478a5 | 1695 | slin.Append(dslin(i)); |
7fd59977 | 1696 | } |
1697 | ||
1698 | // correct U parameter of the start point of line on Quadric | |
1699 | // (change 0->2PI or vs, if necessary) | |
1700 | static Standard_Real AdjustUFirst(Standard_Real U1,Standard_Real U2) | |
1701 | { | |
1702 | Standard_Real u = U1; | |
1703 | ||
1704 | // case: no adjustment | |
c6541a0c | 1705 | if( U1 > 0. && U1 < (2.*M_PI) ) |
7fd59977 | 1706 | return u; |
1707 | ||
1708 | // case: near '0' | |
1709 | if( U1 == 0. || fabs(U1) <= 1.e-9 ) { | |
c6541a0c D |
1710 | if( U2 > 0. && U2 < (2.*M_PI) ) |
1711 | u = ( U2 < ((2.*M_PI)-U2) ) ? 0. : (2.*M_PI); | |
7fd59977 | 1712 | else { |
1713 | Standard_Real uu = U2; | |
c6541a0c | 1714 | if( U2 > (2.*M_PI) ) |
191478a5 | 1715 | while( uu > (2.*M_PI) ) |
1716 | uu -= (2.*M_PI); | |
7fd59977 | 1717 | else |
191478a5 | 1718 | while( uu < 0.) |
1719 | uu += (2.*M_PI); | |
1720 | ||
c6541a0c | 1721 | u = ( uu < ((2.*M_PI)-uu) ) ? 0. : (2.*M_PI); |
7fd59977 | 1722 | } |
1723 | } | |
1724 | // case: near '2PI' | |
c6541a0c D |
1725 | else if( U1 == (2.*M_PI) || fabs((2.*M_PI)-fabs(U1)) <= 1.e-9 ) { |
1726 | if( U2 > 0. && U2 < (2.*M_PI) ) | |
1727 | u = ( U2 < ((2.*M_PI)-U2) ) ? 0. : (2.*M_PI); | |
7fd59977 | 1728 | else { |
1729 | Standard_Real uu = U2; | |
c6541a0c | 1730 | if( U2 > (2.*M_PI) ) |
191478a5 | 1731 | while( uu > (2.*M_PI) ) |
1732 | uu -= (2.*M_PI); | |
7fd59977 | 1733 | else |
191478a5 | 1734 | while( uu < 0.) |
1735 | uu += (2.*M_PI); | |
1736 | ||
c6541a0c | 1737 | u = ( uu < ((2.*M_PI)-uu) ) ? 0. : (2.*M_PI); |
7fd59977 | 1738 | } |
1739 | } | |
1740 | // case: '<0. || >2PI' | |
1741 | else { | |
1742 | if(U1 < 0.) | |
1743 | while(u < 0.) | |
191478a5 | 1744 | u += 2.*M_PI; |
c6541a0c D |
1745 | if(U1 > (2.*M_PI)) |
1746 | while(u > (2.*M_PI)) | |
191478a5 | 1747 | u -= (2.*M_PI); |
7fd59977 | 1748 | } |
1749 | ||
1750 | return u; | |
1751 | } | |
1752 | ||
7fd59977 | 1753 | // collect vertices, reject equals |
77dbd1f1 | 1754 | static Handle(IntSurf_LineOn2S) GetVertices(const Handle(IntPatch_PointLine)& thePLine, |
191478a5 | 1755 | const Standard_Real TOL3D, |
1756 | const Standard_Real TOL2D) | |
7fd59977 | 1757 | { |
191478a5 | 1758 | // Standard_Real TOL3D = 1.e-12, TOL2D = 1.e-8; |
7fd59977 | 1759 | |
1760 | Handle(IntSurf_LineOn2S) vertices = new IntSurf_LineOn2S(); | |
1761 | ||
1762 | Standard_Real U1 = 0., U2 = 0., V1 = 0., V2 = 0.; | |
1763 | Standard_Integer i = 0, k = 0; | |
77dbd1f1 | 1764 | Standard_Integer NbVrt = thePLine->NbVertex(); |
191478a5 | 1765 | |
7fd59977 | 1766 | TColStd_Array1OfInteger anVrts(1,NbVrt); |
1767 | anVrts.Init(0); | |
1768 | ||
1769 | // check equal vertices | |
1770 | for(i = 1; i <= NbVrt; i++) { | |
1771 | ||
1772 | if( anVrts(i) == -1 ) continue; | |
1773 | ||
77dbd1f1 | 1774 | const IntPatch_Point& Pi = thePLine->Vertex(i); |
7fd59977 | 1775 | |
1776 | for(k = (i+1); k <= NbVrt; k++) { | |
1777 | ||
1778 | if( anVrts(k) == -1 ) continue; | |
1779 | ||
77dbd1f1 | 1780 | const IntPatch_Point& Pk = thePLine->Vertex(k); |
7fd59977 | 1781 | |
1782 | if(Pi.Value().Distance(Pk.Value()) <= TOL3D) { | |
191478a5 | 1783 | // suggest the points are equal; |
1784 | // test 2d parameters on surface | |
1785 | Standard_Boolean sameU1 = Standard_False; | |
1786 | Standard_Boolean sameV1 = Standard_False; | |
1787 | Standard_Boolean sameU2 = Standard_False; | |
1788 | Standard_Boolean sameV2 = Standard_False; | |
1789 | ||
1790 | Pi.ParametersOnS1(U1,V1); | |
1791 | Pk.ParametersOnS1(U2,V2); | |
1792 | if(fabs(U1-U2) <= TOL2D) sameU1 = Standard_True; | |
1793 | if(fabs(V1-V2) <= TOL2D) sameV1 = Standard_True; | |
1794 | ||
1795 | Pi.ParametersOnS2(U1,V1); | |
1796 | Pk.ParametersOnS2(U2,V2); | |
1797 | if(fabs(U1-U2) <= TOL2D) sameU2 = Standard_True; | |
1798 | if(fabs(V1-V2) <= TOL2D) sameV2 = Standard_True; | |
1799 | ||
1800 | if((sameU1 && sameV1) && (sameU2 && sameV2)) | |
1801 | anVrts(k) = -1; | |
7fd59977 | 1802 | } |
1803 | } | |
1804 | } | |
1805 | ||
1806 | // copy further processed vertices | |
1807 | for(i = 1; i <= NbVrt; i++) { | |
1808 | if( anVrts(i) == -1 ) continue; | |
77dbd1f1 | 1809 | vertices->Add(thePLine->Vertex(i).PntOn2S()); |
7fd59977 | 1810 | } |
1811 | return vertices; | |
1812 | } | |
1813 | ||
7fd59977 | 1814 | static void SearchVertices(const Handle(IntSurf_LineOn2S)& Line, |
191478a5 | 1815 | const Handle(IntSurf_LineOn2S)& Vertices, |
1816 | TColStd_Array1OfInteger& PTypes) | |
7fd59977 | 1817 | { |
1818 | Standard_Integer nbp = Line->NbPoints(), nbv = Vertices->NbPoints(); | |
1819 | Standard_Integer ip = 0, iv = 0; | |
1820 | for(ip = 1; ip <= nbp; ip++) { | |
1821 | const IntSurf_PntOn2S& aP = Line->Value(ip); | |
1822 | Standard_Integer type = 0; | |
1823 | for(iv = 1; iv <= nbv; iv++) { | |
1824 | const IntSurf_PntOn2S& aV = Vertices->Value(iv); | |
16423f20 | 1825 | if(aP.IsSame(aV, Precision::Confusion(), Precision::PConfusion())) { |
191478a5 | 1826 | type = iv; |
1827 | break; | |
7fd59977 | 1828 | } |
1829 | } | |
1830 | PTypes(ip) = type; | |
1831 | } | |
1832 | } | |
1833 | ||
1834 | static inline Standard_Boolean IsSeamParameter(const Standard_Real U, | |
191478a5 | 1835 | const Standard_Real TOL2D) |
7fd59977 | 1836 | { |
c6541a0c | 1837 | return (fabs(U) <= TOL2D || fabs(2.*M_PI - U) <= TOL2D); |
7fd59977 | 1838 | } |
1839 | ||
1840 | static inline Standard_Real AdjustU(const Standard_Real U) | |
1841 | { | |
c6541a0c | 1842 | Standard_Real u = U, DBLPI = 2.*M_PI; |
7fd59977 | 1843 | if(u < 0. || u > DBLPI) { |
1844 | if(u < 0.) | |
1845 | while(u < 0.) | |
191478a5 | 1846 | u += DBLPI; |
7fd59977 | 1847 | else |
1848 | while(u > DBLPI) | |
191478a5 | 1849 | u -= DBLPI; |
7fd59977 | 1850 | } |
1851 | return u; | |
1852 | } | |
1853 | ||
1854 | static inline void Correct2DBounds(const Standard_Real UF, | |
191478a5 | 1855 | const Standard_Real UL, |
1856 | const Standard_Real VF, | |
1857 | const Standard_Real VL, | |
1858 | const Standard_Real TOL2D, | |
1859 | Standard_Real& U, | |
1860 | Standard_Real& V) | |
7fd59977 | 1861 | { |
1862 | Standard_Real Eps = 1.e-16; | |
1863 | Standard_Real dUF = fabs(U - UF); | |
1864 | Standard_Real dUL = fabs(U - UL); | |
1865 | Standard_Real dVF = fabs(V - VF); | |
1866 | Standard_Real dVL = fabs(V - VL); | |
1867 | if(dUF <= TOL2D && dUF > Eps) U = UF; | |
1868 | if(dUL <= TOL2D && dUL > Eps) U = UL; | |
1869 | if(dVF <= TOL2D && dVF > Eps) V = VF; | |
1870 | if(dVL <= TOL2D && dVL > Eps) V = VL; | |
1871 | } | |
1872 | ||
1873 | static void AdjustLine(Handle(IntSurf_LineOn2S)& Line, | |
191478a5 | 1874 | const Standard_Boolean IsReversed, |
c22b52d6 | 1875 | const Handle(Adaptor3d_Surface)& QSurf, |
191478a5 | 1876 | const Standard_Real TOL2D) |
7fd59977 | 1877 | { |
1878 | Standard_Real VF = QSurf->FirstVParameter(); | |
1879 | Standard_Real VL = QSurf->LastVParameter(); | |
1880 | Standard_Real UF = QSurf->FirstUParameter(); | |
1881 | Standard_Real UL = QSurf->LastUParameter(); | |
1882 | ||
1883 | Standard_Integer nbp = Line->NbPoints(), ip = 0; | |
1884 | Standard_Real U = 0., V = 0.; | |
1885 | for(ip = 1; ip <= nbp; ip++) { | |
1886 | if(IsReversed) { | |
1887 | Line->Value(ip).ParametersOnS2(U,V); | |
1888 | U = AdjustU(U); | |
1889 | Correct2DBounds(UF,UL,VF,VL,TOL2D,U,V); | |
1890 | Line->SetUV(ip,Standard_False,U,V); | |
1891 | } | |
1892 | else { | |
1893 | Line->Value(ip).ParametersOnS1(U,V); | |
1894 | U = AdjustU(U); | |
1895 | Correct2DBounds(UF,UL,VF,VL,TOL2D,U,V); | |
1896 | Line->SetUV(ip,Standard_True,U,V); | |
1897 | } | |
1898 | } | |
1899 | } | |
1900 | ||
1901 | static Standard_Boolean InsertSeamVertices(Handle(IntSurf_LineOn2S)& Line, | |
191478a5 | 1902 | const Standard_Boolean IsReversed, |
1903 | Handle(IntSurf_LineOn2S)& Vertices, | |
1904 | const TColStd_Array1OfInteger& PTypes, | |
1905 | const Standard_Real TOL2D) | |
7fd59977 | 1906 | { |
1907 | Standard_Boolean result = Standard_False; | |
1908 | Standard_Integer ip = 0, nbp = Line->NbPoints(); | |
1909 | Standard_Real U = 0., V = 0.; | |
1910 | for(ip = 1; ip <= nbp; ip++) { | |
1911 | Standard_Integer ipt = PTypes(ip); | |
1912 | if(ipt != 0) { | |
1913 | const IntSurf_PntOn2S& aP = Line->Value(ip); | |
1914 | if(IsReversed) | |
191478a5 | 1915 | aP.ParametersOnS2(U,V); // S2 - quadric |
7fd59977 | 1916 | else |
191478a5 | 1917 | aP.ParametersOnS1(U,V); // S1 - quadric |
7fd59977 | 1918 | U = AdjustU(U); |
1919 | if(IsSeamParameter(U,TOL2D)) { | |
191478a5 | 1920 | if(ip == 1 || ip == nbp) { |
1921 | Standard_Real U1 = 0., V1 = 0.; | |
1922 | Standard_Integer ipp = (ip == 1) ? (ip+1) : (ip-1); | |
1923 | if(IsReversed) | |
1924 | Line->Value(ipp).ParametersOnS2(U1,V1); // S2 - quadric | |
1925 | else | |
1926 | Line->Value(ipp).ParametersOnS1(U1,V1); // S1 - quadric | |
1927 | Standard_Real u = AdjustUFirst(U,U1); | |
1928 | if(fabs(u-U) >= 1.5*M_PI) { | |
1929 | Standard_Real U2 = 0., V2 = 0.; | |
1930 | if(IsReversed) { | |
1931 | Line->Value(ip).ParametersOnS1(U2,V2); // prm | |
1932 | Line->SetUV(ip,Standard_False,u,V); | |
1933 | Line->SetUV(ip,Standard_True,U2,V2); | |
1934 | } | |
1935 | else { | |
1936 | Line->Value(ip).ParametersOnS2(U2,V2); // prm | |
1937 | Line->SetUV(ip,Standard_True,u,V); | |
1938 | Line->SetUV(ip,Standard_False,U2,V2); | |
1939 | } | |
1940 | } | |
1941 | } | |
1942 | else { | |
1943 | Standard_Integer ipp = ip - 1; | |
1944 | Standard_Integer ipn = ip + 1; | |
1945 | Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.; | |
1946 | if(IsReversed) { | |
1947 | Line->Value(ipp).ParametersOnS2(U1,V1); // quad | |
1948 | Line->Value(ipn).ParametersOnS2(U2,V2); // quad | |
1949 | } | |
1950 | else { | |
1951 | Line->Value(ipp).ParametersOnS1(U1,V1); // quad | |
1952 | Line->Value(ipn).ParametersOnS1(U2,V2); // quad | |
1953 | } | |
1954 | U1 = AdjustU(U1); | |
1955 | U2 = AdjustU(U2); | |
1956 | Standard_Boolean pnearZero = (fabs(U1) < fabs(2.*M_PI-U1)) ? Standard_True : Standard_False; | |
1957 | Standard_Boolean cnearZero = (fabs(U) < fabs(2.*M_PI-U)) ? Standard_True : Standard_False; | |
1958 | if(pnearZero == cnearZero) { | |
1959 | if(!IsSeamParameter(U2,TOL2D) && !IsSeamParameter(U1,TOL2D)) { | |
1960 | Standard_Real nU = (cnearZero) ? (2.*M_PI) : 0.; | |
1961 | IntSurf_PntOn2S nP; | |
1962 | nP.SetValue(aP.Value()); | |
1963 | Standard_Real U3 = 0., V3 = 0.; | |
1964 | if(IsReversed) { | |
1965 | Line->Value(ip).ParametersOnS1(U3,V3); // prm | |
1966 | nP.SetValue(Standard_False,nU,V); | |
1967 | nP.SetValue(Standard_True,U3,V3); | |
1968 | } | |
1969 | else { | |
1970 | Line->Value(ip).ParametersOnS2(U3,V3); // prm | |
1971 | nP.SetValue(Standard_True,nU,V); | |
1972 | nP.SetValue(Standard_False,U3,V3); | |
1973 | } | |
1974 | Line->InsertBefore(ipn,nP); | |
1975 | Vertices->Add(nP); | |
1976 | result = Standard_True; | |
1977 | break; | |
1978 | } | |
1979 | } | |
1980 | else { | |
1981 | if(!IsSeamParameter(U2,TOL2D) && !IsSeamParameter(U1,TOL2D)) { | |
1982 | Standard_Real nU = (cnearZero) ? (2.*M_PI) : 0.; | |
1983 | IntSurf_PntOn2S nP; | |
1984 | nP.SetValue(aP.Value()); | |
1985 | Standard_Real U3 = 0., V3 = 0.; | |
1986 | if(IsReversed) { | |
1987 | Line->Value(ip).ParametersOnS1(U3,V3); // prm | |
1988 | nP.SetValue(Standard_False,nU,V); | |
1989 | nP.SetValue(Standard_True,U3,V3); | |
1990 | } | |
1991 | else { | |
1992 | Line->Value(ip).ParametersOnS2(U3,V3); // prm | |
1993 | nP.SetValue(Standard_True,nU,V); | |
1994 | nP.SetValue(Standard_False,U3,V3); | |
1995 | } | |
1996 | Line->InsertBefore(ip,nP); | |
1997 | Vertices->Add(nP); | |
1998 | result = Standard_True; | |
1999 | break; | |
2000 | } | |
2001 | else { | |
2002 | // Line->InsertBefore(ip,Line->Value(ipn)); | |
2003 | // Line->RemovePoint(ip+2); | |
2004 | // result = Standard_True; | |
04232180 | 2005 | // std::cout << "swap vertex " << std::endl; |
191478a5 | 2006 | // break; |
2007 | } | |
2008 | } | |
2009 | } | |
7fd59977 | 2010 | } |
2011 | } | |
2012 | } | |
2013 | return result; | |
2014 | } | |
2015 | ||
191478a5 | 2016 | static void ToSmooth( const Handle(IntSurf_LineOn2S)& Line, |
d4b867e6 | 2017 | const Standard_Boolean IsReversed, |
2018 | const IntSurf_Quadric& Quad, | |
2019 | const Standard_Boolean IsFirst, | |
2020 | Standard_Real& D3D) | |
7fd59977 | 2021 | { |
2022 | if(Line->NbPoints() <= 10) | |
2023 | return; | |
191478a5 | 2024 | |
7fd59977 | 2025 | D3D = 0.; |
2026 | Standard_Integer NbTestPnts = Line->NbPoints() / 5; | |
2027 | if(NbTestPnts < 5) NbTestPnts = 5; | |
2028 | ||
2029 | Standard_Integer startp = (IsFirst) ? 2 : (Line->NbPoints() - NbTestPnts - 2); | |
2030 | Standard_Integer ip = 0; | |
73dee811 | 2031 | Standard_Real Uc = 0., Vc = 0., Un = 0., Vn = 0., DDU = 0.; |
2032 | //Standard_Real DDV = 0.; | |
7fd59977 | 2033 | |
2034 | for(ip = startp; ip <= NbTestPnts; ip++) { | |
2035 | if(IsReversed) { | |
2036 | Line->Value(ip).ParametersOnS2(Uc,Vc); // S2 - quadric | |
2037 | Line->Value(ip+1).ParametersOnS2(Un,Vn); | |
2038 | } | |
2039 | else { | |
2040 | Line->Value(ip).ParametersOnS1(Uc,Vc); // S1 - quadric | |
2041 | Line->Value(ip+1).ParametersOnS1(Un,Vn); | |
2042 | } | |
2043 | DDU += fabs(fabs(Uc)-fabs(Un)); | |
73dee811 | 2044 | //DDV += fabs(fabs(Vc)-fabs(Vn)); |
191478a5 | 2045 | |
7fd59977 | 2046 | if(ip > startp) { |
2047 | Standard_Real DP = Line->Value(ip).Value().Distance(Line->Value(ip-1).Value()); | |
2048 | D3D += DP; | |
2049 | } | |
2050 | } | |
2051 | ||
2052 | DDU /= (Standard_Real) NbTestPnts + 1; | |
73dee811 | 2053 | //DDV /= (Standard_Real) NbTestPnts + 1; |
191478a5 | 2054 | |
7fd59977 | 2055 | D3D /= (Standard_Real) NbTestPnts + 1; |
2056 | ||
2057 | ||
2058 | Standard_Integer Index1 = (IsFirst) ? 1 : (Line->NbPoints()); | |
2059 | Standard_Integer Index2 = (IsFirst) ? 2 : (Line->NbPoints()-1); | |
2060 | Standard_Integer Index3 = (IsFirst) ? 3 : (Line->NbPoints()-2); | |
2061 | ||
2062 | Standard_Boolean doU = Standard_False; | |
7fd59977 | 2063 | |
2064 | Standard_Real U1 = 0., U2 = 0., V1 = 0., V2 = 0., U3 = 0., V3 = 0.; | |
2065 | ||
2066 | if(IsReversed) { | |
2067 | Line->Value(Index1).ParametersOnS2(U1,V1); // S2 - quadric | |
2068 | Line->Value(Index2).ParametersOnS2(U2,V2); | |
2069 | Line->Value(Index3).ParametersOnS2(U3,V3); | |
2070 | } | |
2071 | else { | |
2072 | Line->Value(Index1).ParametersOnS1(U1,V1); // S1 - quadric | |
2073 | Line->Value(Index2).ParametersOnS1(U2,V2); | |
2074 | Line->Value(Index3).ParametersOnS1(U3,V3); | |
2075 | } | |
2076 | ||
2077 | if(!doU && Quad.TypeQuadric() == GeomAbs_Sphere) { | |
c6541a0c | 2078 | if(fabs(fabs(U1)-fabs(U2)) > (M_PI/16.)) doU = Standard_True; |
191478a5 | 2079 | |
c6541a0c D |
2080 | if(doU && (fabs(U1) <= 1.e-9 || fabs(U1-2.*M_PI) <= 1.e-9)) { |
2081 | if(fabs(V1-M_PI/2.) <= 1.e-9 || fabs(V1+M_PI/2.) <= 1.e-9) {} | |
7fd59977 | 2082 | else { |
191478a5 | 2083 | doU = Standard_False; |
7fd59977 | 2084 | } |
2085 | } | |
2086 | } | |
191478a5 | 2087 | |
7fd59977 | 2088 | if(Quad.TypeQuadric() == GeomAbs_Cone) { |
2089 | Standard_Real Uapx = 0., Vapx = 0.; | |
2090 | Quad.Parameters(Quad.Cone().Apex(),Uapx,Vapx); | |
2091 | ||
c6541a0c | 2092 | if(fabs(fabs(U1)-fabs(U2)) > M_PI/32.) doU = Standard_True; |
7fd59977 | 2093 | |
c6541a0c | 2094 | if(doU && (fabs(U1) <= 1.e-9 || fabs(U1-2.*M_PI) <= 1.e-9)) { |
7fd59977 | 2095 | if(fabs(V1-Vapx) <= 1.e-9) {} |
2096 | else { | |
191478a5 | 2097 | doU = Standard_False; |
7fd59977 | 2098 | } |
2099 | } | |
2100 | } | |
2101 | ||
7fd59977 | 2102 | if(doU) { |
2103 | Standard_Real dU = Min((DDU/10.),5.e-8); | |
2104 | Standard_Real U = (U2 > U3) ? (U2 + dU) : (U2 - dU); | |
2105 | if(IsReversed) | |
2106 | Line->SetUV(Index1,Standard_False,U,V1); | |
2107 | else | |
2108 | Line->SetUV(Index1,Standard_True,U,V1); | |
2109 | U1 = U; | |
2110 | } | |
2111 | } | |
2112 | ||
2113 | static Standard_Boolean TestMiddleOnPrm(const IntSurf_PntOn2S& aP, | |
d4b867e6 | 2114 | const IntSurf_PntOn2S& aV, |
2115 | const Standard_Boolean IsReversed, | |
2116 | const Standard_Real ArcTol, | |
2117 | const Handle(Adaptor3d_TopolTool)& PDomain) | |
191478a5 | 2118 | |
7fd59977 | 2119 | { |
2120 | Standard_Boolean result = Standard_False; | |
2121 | Standard_Real Up = 0., Vp = 0., Uv = 0., Vv = 0.; | |
2122 | if(IsReversed) { | |
2123 | aP.ParametersOnS1(Up,Vp); //S1 - parametric | |
2124 | aV.ParametersOnS1(Uv,Vv); | |
2125 | } | |
2126 | else { | |
2127 | aP.ParametersOnS2(Up,Vp); // S2 - parametric | |
2128 | aV.ParametersOnS2(Uv,Vv); | |
2129 | } | |
2130 | Standard_Real Um = (Up + Uv)*0.5, Vm = (Vp + Vv)*0.5; | |
2131 | gp_Pnt2d a2DPntM(Um,Vm); | |
2132 | TopAbs_State PosM = PDomain->Classify(a2DPntM,ArcTol); | |
2133 | if(PosM == TopAbs_ON || PosM == TopAbs_IN ) | |
2134 | result = Standard_True; | |
2135 | return result; | |
2136 | } | |
2137 | ||
191478a5 | 2138 | static void VerifyVertices( const Handle(IntSurf_LineOn2S)& Line, |
d4b867e6 | 2139 | const Standard_Boolean IsReversed, |
2140 | const Handle(IntSurf_LineOn2S)& Vertices, | |
2141 | const Standard_Real TOL2D, | |
2142 | const Standard_Real ArcTol, | |
2143 | const Handle(Adaptor3d_TopolTool)& PDomain, | |
2144 | IntSurf_PntOn2S& VrtF, | |
2145 | Standard_Boolean& AddFirst, | |
2146 | IntSurf_PntOn2S& VrtL, | |
2147 | Standard_Boolean& AddLast) | |
7fd59977 | 2148 | { |
2149 | Standard_Integer nbp = Line->NbPoints(), nbv = Vertices->NbPoints(); | |
2150 | Standard_Integer FIndexSame = 0, FIndexNear = 0, LIndexSame = 0, LIndexNear = 0; | |
2151 | const IntSurf_PntOn2S& aPF = Line->Value(1); | |
2152 | const IntSurf_PntOn2S& aPL = Line->Value(nbp); | |
2153 | Standard_Real UF = 0., VF = 0., UL = 0., VL = 0.; | |
2154 | if(IsReversed) { | |
2155 | aPF.ParametersOnS2(UF,VF); | |
2156 | aPL.ParametersOnS2(UL,VL); | |
2157 | } | |
2158 | else { | |
2159 | aPF.ParametersOnS1(UF,VF); | |
2160 | aPL.ParametersOnS1(UL,VL); | |
2161 | } | |
2162 | gp_Pnt2d a2DPF(UF,VF); | |
2163 | gp_Pnt2d a2DPL(UL,VL); | |
2164 | Standard_Real DistMinF = 1.e+100, DistMinL = 1.e+100; | |
2165 | Standard_Integer FConjugated = 0, LConjugated = 0; | |
2166 | ||
2167 | Standard_Integer iv = 0; | |
2168 | ||
2169 | for(iv = 1; iv <= nbv; iv++) { | |
2170 | Standard_Real Uv = 0., Vv = 0.; | |
2171 | if(IsReversed) { | |
2172 | Vertices->Value(iv).ParametersOnS2(Uv,Vv); | |
2173 | Uv = AdjustU(Uv); | |
2174 | Vertices->SetUV(iv,Standard_False,Uv,Vv); | |
2175 | } | |
2176 | else { | |
2177 | Vertices->Value(iv).ParametersOnS1(Uv,Vv); | |
2178 | Uv = AdjustU(Uv); | |
2179 | Vertices->SetUV(iv,Standard_True,Uv,Vv); | |
2180 | } | |
2181 | } | |
2182 | ||
2183 | for(iv = 1; iv <= nbv; iv++) { | |
2184 | const IntSurf_PntOn2S& aV = Vertices->Value(iv); | |
16423f20 | 2185 | if(aPF.IsSame(aV, Precision::Confusion(), Precision::PConfusion())) { |
7fd59977 | 2186 | FIndexSame = iv; |
2187 | break; | |
2188 | } | |
2189 | else { | |
2190 | Standard_Real Uv = 0., Vv = 0.; | |
2191 | if(IsReversed) | |
2192 | aV.ParametersOnS2(Uv,Vv); | |
2193 | else | |
2194 | aV.ParametersOnS1(Uv,Vv); | |
2195 | gp_Pnt2d a2DV(Uv,Vv); | |
2196 | Standard_Real Dist = a2DV.Distance(a2DPF); | |
2197 | if(Dist < DistMinF) { | |
2198 | DistMinF = Dist; | |
2199 | FIndexNear = iv; | |
2200 | if(FConjugated != 0) | |
2201 | FConjugated = 0; | |
2202 | } | |
2203 | if(IsSeamParameter(Uv,TOL2D)) { | |
c6541a0c | 2204 | Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.; |
7fd59977 | 2205 | gp_Pnt2d a2DCV(Ucv,Vv); |
2206 | Standard_Real CDist = a2DCV.Distance(a2DPF); | |
2207 | if(CDist < DistMinF) { | |
2208 | DistMinF = CDist; | |
2209 | FConjugated = iv; | |
2210 | FIndexNear = iv; | |
2211 | } | |
2212 | } | |
2213 | } | |
2214 | } | |
2215 | ||
2216 | for(iv = 1; iv <= nbv; iv++) { | |
2217 | const IntSurf_PntOn2S& aV = Vertices->Value(iv); | |
16423f20 | 2218 | if(aPL.IsSame(aV, Precision::Confusion(), Precision::PConfusion())) { |
7fd59977 | 2219 | LIndexSame = iv; |
2220 | break; | |
2221 | } | |
2222 | else { | |
2223 | Standard_Real Uv = 0., Vv = 0.; | |
2224 | if(IsReversed) | |
2225 | aV.ParametersOnS2(Uv,Vv); | |
2226 | else | |
2227 | aV.ParametersOnS1(Uv,Vv); | |
2228 | gp_Pnt2d a2DV(Uv,Vv); | |
2229 | Standard_Real Dist = a2DV.Distance(a2DPL); | |
2230 | if(Dist < DistMinL) { | |
2231 | DistMinL = Dist; | |
2232 | LIndexNear = iv; | |
2233 | if(LConjugated != 0) | |
2234 | LConjugated = 0; | |
2235 | } | |
2236 | if(IsSeamParameter(Uv,TOL2D)) { | |
c6541a0c | 2237 | Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.; |
7fd59977 | 2238 | gp_Pnt2d a2DCV(Ucv,Vv); |
2239 | Standard_Real CDist = a2DCV.Distance(a2DPL); | |
2240 | if(CDist < DistMinL) { | |
2241 | DistMinL = CDist; | |
2242 | LConjugated = iv; | |
2243 | LIndexNear = iv; | |
2244 | } | |
2245 | } | |
2246 | } | |
2247 | } | |
2248 | ||
2249 | AddFirst = Standard_False; | |
2250 | AddLast = Standard_False; | |
2251 | ||
2252 | if(FIndexSame == 0) { | |
2253 | if(FIndexNear != 0) { | |
2254 | const IntSurf_PntOn2S& aV = Vertices->Value(FIndexNear); | |
2255 | Standard_Real Uv = 0., Vv = 0.; | |
2256 | if(IsReversed) | |
2257 | aV.ParametersOnS2(Uv,Vv); | |
2258 | else | |
2259 | aV.ParametersOnS1(Uv,Vv); | |
2260 | if(IsSeamParameter(Uv,TOL2D)) { | |
c6541a0c | 2261 | Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.; |
7fd59977 | 2262 | Standard_Boolean test = TestMiddleOnPrm(aPF,aV,IsReversed,ArcTol,PDomain); |
2263 | if(test) { | |
2264 | VrtF.SetValue(aV.Value()); | |
2265 | if(IsReversed) { | |
2266 | Standard_Real U2 = 0., V2 = 0.; | |
2267 | aV.ParametersOnS1(U2,V2); // S1 - prm | |
2268 | VrtF.SetValue(Standard_True,U2,V2); | |
2269 | if(FConjugated == 0) | |
2270 | VrtF.SetValue(Standard_False,Uv,Vv); | |
2271 | else | |
2272 | VrtF.SetValue(Standard_False,Ucv,Vv); | |
2273 | } | |
2274 | else { | |
2275 | Standard_Real U2 = 0., V2 = 0.; | |
2276 | aV.ParametersOnS2(U2,V2); // S2 - prm | |
2277 | VrtF.SetValue(Standard_False,U2,V2); | |
2278 | if(FConjugated == 0) | |
2279 | VrtF.SetValue(Standard_True,Uv,Vv); | |
2280 | else | |
2281 | VrtF.SetValue(Standard_True,Ucv,Vv); | |
2282 | } | |
2283 | Standard_Real Dist3D = VrtF.Value().Distance(aPF.Value()); | |
2284 | if(Dist3D > 1.5e-7 && DistMinF > TOL2D) { | |
2285 | AddFirst = Standard_True; | |
2286 | } | |
2287 | } | |
2288 | } | |
2289 | else { | |
2290 | // to do: analyze internal vertex | |
2291 | } | |
2292 | } | |
2293 | } | |
191478a5 | 2294 | |
7fd59977 | 2295 | if(LIndexSame == 0) { |
2296 | if(LIndexNear != 0) { | |
2297 | const IntSurf_PntOn2S& aV = Vertices->Value(LIndexNear); | |
2298 | Standard_Real Uv = 0., Vv = 0.; | |
2299 | if(IsReversed) | |
2300 | aV.ParametersOnS2(Uv,Vv); | |
2301 | else | |
2302 | aV.ParametersOnS1(Uv,Vv); | |
2303 | if(IsSeamParameter(Uv,TOL2D)) { | |
c6541a0c | 2304 | Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.; |
7fd59977 | 2305 | Standard_Boolean test = TestMiddleOnPrm(aPL,aV,IsReversed,ArcTol,PDomain); |
2306 | if(test) { | |
2307 | VrtL.SetValue(aV.Value()); | |
2308 | if(IsReversed) { | |
2309 | Standard_Real U2 = 0., V2 = 0.; | |
2310 | aV.ParametersOnS1(U2,V2); // S1 - prm | |
2311 | VrtL.SetValue(Standard_True,U2,V2); | |
2312 | if(LConjugated == 0) | |
2313 | VrtL.SetValue(Standard_False,Uv,Vv); | |
2314 | else | |
2315 | VrtL.SetValue(Standard_False,Ucv,Vv); | |
2316 | } | |
2317 | else { | |
2318 | Standard_Real U2 = 0., V2 = 0.; | |
2319 | aV.ParametersOnS2(U2,V2); // S2 - prm | |
2320 | VrtL.SetValue(Standard_False,U2,V2); | |
2321 | if(LConjugated == 0) | |
2322 | VrtL.SetValue(Standard_True,Uv,Vv); | |
2323 | else | |
2324 | VrtL.SetValue(Standard_True,Ucv,Vv); | |
2325 | } | |
2326 | Standard_Real Dist3D = VrtL.Value().Distance(aPL.Value()); | |
2327 | if(Dist3D > 1.5e-7 && DistMinL > TOL2D) { | |
2328 | AddLast = Standard_True; | |
2329 | } | |
2330 | } | |
2331 | } | |
2332 | else { | |
2333 | // to do: analyze internal vertex | |
2334 | } | |
2335 | } | |
2336 | } | |
2337 | } | |
2338 | ||
2339 | static Standard_Boolean AddVertices(Handle(IntSurf_LineOn2S)& Line, | |
191478a5 | 2340 | const IntSurf_PntOn2S& VrtF, |
2341 | const Standard_Boolean AddFirst, | |
2342 | const IntSurf_PntOn2S& VrtL, | |
2343 | const Standard_Boolean AddLast, | |
2344 | const Standard_Real D3DF, | |
2345 | const Standard_Real D3DL) | |
7fd59977 | 2346 | { |
2347 | Standard_Boolean result = Standard_False; | |
2348 | if(AddFirst) { | |
2349 | Standard_Real DF = Line->Value(1).Value().Distance(VrtF.Value()); | |
2350 | if((D3DF*2.) > DF && DF > 1.5e-7) { | |
2351 | Line->InsertBefore(1,VrtF); | |
2352 | result = Standard_True; | |
2353 | } | |
2354 | } | |
2355 | if(AddLast) { | |
2356 | Standard_Real DL = Line->Value(Line->NbPoints()).Value().Distance(VrtL.Value()); | |
2357 | if((D3DL*2.) > DL && DL > 1.5e-7) { | |
2358 | Line->Add(VrtL); | |
2359 | result = Standard_True; | |
2360 | } | |
2361 | } | |
2362 | return result; | |
2363 | } | |
191478a5 | 2364 | |
7fd59977 | 2365 | |
16423f20 | 2366 | static void PutIntVertices(const Handle(IntPatch_PointLine)& Line, |
191478a5 | 2367 | Handle(IntSurf_LineOn2S)& Result, |
16423f20 | 2368 | Standard_Boolean theIsReversed, |
191478a5 | 2369 | Handle(IntSurf_LineOn2S)& Vertices, |
2370 | const Standard_Real ArcTol) | |
7fd59977 | 2371 | { |
2372 | Standard_Integer nbp = Result->NbPoints(), nbv = Vertices->NbPoints(); | |
2373 | ||
2374 | if(nbp < 3) | |
2375 | return; | |
2376 | ||
16423f20 | 2377 | const Handle(IntPatch_RLine) aRLine = Handle(IntPatch_RLine)::DownCast(Line); |
2378 | ||
7fd59977 | 2379 | Standard_Integer ip = 0, iv = 0; |
2380 | gp_Pnt aPnt; | |
2381 | IntPatch_Point thePnt; | |
2382 | Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.; | |
191478a5 | 2383 | |
7fd59977 | 2384 | for(ip = 2; ip <= (nbp-1); ip++) { |
2385 | const IntSurf_PntOn2S& aP = Result->Value(ip); | |
2386 | for(iv = 1; iv <= nbv; iv++) { | |
2387 | const IntSurf_PntOn2S& aV = Vertices->Value(iv); | |
16423f20 | 2388 | if(aP.IsSame(aV, Precision::Confusion(), Precision::PConfusion())) { |
7fd59977 | 2389 | aPnt = Result->Value(ip).Value(); |
191478a5 | 2390 | Result->Value(ip).ParametersOnS1(U1,V1); |
2391 | Result->Value(ip).ParametersOnS2(U2,V2); | |
2392 | thePnt.SetValue(aPnt,ArcTol,Standard_False); | |
2393 | thePnt.SetParameters(U1,V1,U2,V2); | |
16423f20 | 2394 | |
2395 | Standard_Real aParam = (Standard_Real)ip; | |
2396 | ||
2397 | if(!aRLine.IsNull()) | |
2398 | { | |
2399 | //In fact, aRLine is always on the parametric surface. | |
2400 | //If (theIsReversed == TRUE) then (U1, V1) - point on | |
2401 | //parametric surface, otherwise - point on quadric. | |
c22b52d6 | 2402 | const Handle(Adaptor2d_Curve2d)& anArc = aRLine->IsArcOnS1() ? |
16423f20 | 2403 | aRLine->ArcOnS1() : |
2404 | aRLine->ArcOnS2(); | |
2405 | ||
c22b52d6 | 2406 | const gp_Lin2d aLin(anArc->Line()); |
16423f20 | 2407 | gp_Pnt2d aPSurf; |
2408 | ||
2409 | if(theIsReversed) | |
2410 | { | |
2411 | aPSurf.SetCoord(U1, V1); | |
2412 | } | |
2413 | else | |
2414 | { | |
2415 | aPSurf.SetCoord(U2, V2); | |
2416 | } | |
2417 | ||
2418 | aParam = ElCLib::Parameter(aLin, aPSurf); | |
2419 | } | |
2420 | ||
2421 | thePnt.SetParameter(aParam); | |
2422 | Line->AddVertex(thePnt); | |
7fd59977 | 2423 | } |
2424 | } | |
2425 | } | |
2426 | } | |
2427 | ||
2428 | static Standard_Boolean HasInternals(Handle(IntSurf_LineOn2S)& Line, | |
191478a5 | 2429 | Handle(IntSurf_LineOn2S)& Vertices) |
7fd59977 | 2430 | { |
2431 | Standard_Integer nbp = Line->NbPoints(), nbv = Vertices->NbPoints(); | |
2432 | Standard_Integer ip = 0, iv = 0; | |
2433 | Standard_Boolean result = Standard_False; | |
191478a5 | 2434 | |
7fd59977 | 2435 | if(nbp < 3) |
2436 | return result; | |
2437 | ||
2438 | for(ip = 2; ip <= (nbp-1); ip++) { | |
2439 | const IntSurf_PntOn2S& aP = Line->Value(ip); | |
2440 | for(iv = 1; iv <= nbv; iv++) { | |
2441 | const IntSurf_PntOn2S& aV = Vertices->Value(iv); | |
16423f20 | 2442 | if(aP.IsSame(aV, Precision::Confusion(), Precision::PConfusion())) { |
7fd59977 | 2443 | result = Standard_True; |
2444 | break; | |
2445 | } | |
2446 | } | |
2447 | if(result) | |
2448 | break; | |
2449 | } | |
191478a5 | 2450 | |
7fd59977 | 2451 | return result; |
2452 | } | |
2453 | static Handle(IntPatch_WLine) MakeSplitWLine (Handle(IntPatch_WLine)& WLine, | |
191478a5 | 2454 | Standard_Boolean Tang, |
2455 | IntSurf_TypeTrans Trans1, | |
2456 | IntSurf_TypeTrans Trans2, | |
2457 | Standard_Real ArcTol, | |
2458 | Standard_Integer ParFirst, | |
2459 | Standard_Integer ParLast) | |
7fd59977 | 2460 | { |
2461 | Handle(IntSurf_LineOn2S) SLine = WLine->Curve(); | |
2462 | Handle(IntSurf_LineOn2S) sline = new IntSurf_LineOn2S(); | |
191478a5 | 2463 | |
2464 | Standard_Integer ip = 0; | |
7fd59977 | 2465 | for(ip = ParFirst; ip <= ParLast; ip++) |
2466 | sline->Add(SLine->Value(ip)); | |
2467 | ||
2468 | Handle(IntPatch_WLine) wline = new IntPatch_WLine(sline,Tang,Trans1,Trans2); | |
98974dcc | 2469 | wline->SetCreatingWayInfo(IntPatch_WLine::IntPatch_WLImpPrm); |
7fd59977 | 2470 | |
2471 | gp_Pnt aSPnt; | |
2472 | IntPatch_Point TPntF,TPntL; | |
2473 | Standard_Real uu1 = 0., vv1 = 0., uu2 = 0., vv2 = 0.; | |
2474 | ||
2475 | aSPnt = sline->Value(1).Value(); | |
2476 | sline->Value(1).ParametersOnS1(uu1,vv1); | |
2477 | sline->Value(1).ParametersOnS2(uu2,vv2); | |
2478 | TPntF.SetValue(aSPnt,ArcTol,Standard_False); | |
2479 | TPntF.SetParameters(uu1,vv1,uu2,vv2); | |
2480 | TPntF.SetParameter(1.); | |
2481 | wline->AddVertex(TPntF); | |
2482 | wline->SetFirstPoint(1); | |
191478a5 | 2483 | |
7fd59977 | 2484 | aSPnt = sline->Value(sline->NbPoints()).Value(); |
2485 | sline->Value(sline->NbPoints()).ParametersOnS1(uu1,vv1); | |
2486 | sline->Value(sline->NbPoints()).ParametersOnS2(uu2,vv2); | |
2487 | TPntL.SetValue(aSPnt,ArcTol,Standard_False); | |
2488 | TPntL.SetParameters(uu1,vv1,uu2,vv2); | |
2489 | TPntL.SetParameter((Standard_Real)sline->NbPoints()); | |
2490 | wline->AddVertex(TPntL); | |
a09c8f3a | 2491 | wline->SetLastPoint(wline->NbVertex()); |
7fd59977 | 2492 | |
2493 | return wline; | |
2494 | } | |
2495 | ||
2496 | static Standard_Boolean SplitOnSegments(Handle(IntPatch_WLine)& WLine, | |
191478a5 | 2497 | Standard_Boolean Tang, |
2498 | IntSurf_TypeTrans Trans1, | |
2499 | IntSurf_TypeTrans Trans2, | |
2500 | Standard_Real ArcTol, | |
2501 | IntPatch_SequenceOfLine& Segments) | |
7fd59977 | 2502 | { |
2503 | Standard_Boolean result = Standard_False; | |
2504 | Segments.Clear(); | |
2505 | ||
2506 | Standard_Integer nbv = WLine->NbVertex(); | |
2507 | if(nbv > 3) { | |
2508 | Standard_Integer iv = 0; | |
2509 | for(iv = 1; iv < nbv; iv++) { | |
191478a5 | 2510 | Standard_Integer firstPar = |
2511 | (Standard_Integer) WLine->Vertex(iv).ParameterOnLine(); | |
2512 | Standard_Integer lastPar = | |
2513 | (Standard_Integer) WLine->Vertex(iv+1).ParameterOnLine(); | |
7fd59977 | 2514 | if((lastPar - firstPar) <= 1) |
2515 | continue; | |
2516 | else { | |
191478a5 | 2517 | Handle(IntPatch_WLine) splitwline = MakeSplitWLine(WLine,Tang,Trans1,Trans2, |
2518 | ArcTol,firstPar,lastPar); | |
7fd59977 | 2519 | Segments.Append(splitwline); |
2520 | if(!result) | |
2521 | result = Standard_True; | |
2522 | } | |
2523 | } | |
2524 | } | |
2525 | return result; | |
2526 | } | |
2527 | ||
779d6bc6 | 2528 | //======================================================================= |
2529 | //function : IsPointOnBoundary | |
2530 | //purpose : Returns TRUE if point <theParam> matches <theBoundary +/- thePeriod> | |
2531 | // with given tolerance criterion. | |
2532 | // For not-periodic case, thePeriod must be equal to 0.0. | |
2533 | //======================================================================= | |
2534 | static Standard_Boolean IsPointOnBoundary(const Standard_Real theToler2D, | |
2535 | const Standard_Real theBoundary, | |
2536 | const Standard_Real thePeriod, | |
2537 | const Standard_Real theParam) | |
2538 | { | |
2539 | Standard_Real aDelta = Abs(theParam - theBoundary); | |
2540 | if (thePeriod != 0.0) | |
2541 | { | |
2542 | aDelta = fmod(aDelta, thePeriod); | |
2543 | ||
2544 | // 0 <= aDelta < thePeriod | |
2545 | return ((aDelta < theToler2D) || ((thePeriod - aDelta) < theToler2D)); | |
2546 | } | |
2547 | ||
2548 | // Here, thePeriod == 0.0, aDelta > 0.0 | |
2549 | ||
2550 | return (aDelta < theToler2D); | |
2551 | } | |
2552 | ||
2553 | //======================================================================= | |
2554 | //function : DetectOfBoundaryAchievement | |
2555 | //purpose : Can change values of theNewLine (by adding the computed point on boundary, | |
2556 | // which parameter will be adjusted) and theIsOnBoundary variables. | |
2557 | //======================================================================= | |
c22b52d6 | 2558 | static void DetectOfBoundaryAchievement(const Handle(Adaptor3d_Surface)& theQSurf, // quadric |
779d6bc6 | 2559 | const Standard_Boolean theIsReversed, |
2560 | const Handle(IntSurf_LineOn2S)& theSourceLine, | |
2561 | const Standard_Integer thePointIndex, | |
2562 | const Standard_Real theToler2D, | |
2563 | Handle(IntSurf_LineOn2S)& theNewLine, | |
2564 | Standard_Boolean& theIsOnBoundary) | |
2565 | { | |
2566 | const Standard_Real aUPeriod = theQSurf->IsUPeriodic() ? theQSurf->UPeriod() : 0.0, | |
2567 | aVPeriod = theQSurf->IsVPeriodic() ? theQSurf->VPeriod() : 0.0; | |
2568 | const Standard_Real aUf = theQSurf->FirstUParameter(), | |
2569 | aUl = theQSurf->LastUParameter(), | |
2570 | aVf = theQSurf->FirstVParameter(), | |
2571 | aVl = theQSurf->LastVParameter(); | |
2572 | ||
2573 | const IntSurf_PntOn2S &aPPrev = theSourceLine->Value(thePointIndex - 1), | |
2574 | &aPCurr = theSourceLine->Value(thePointIndex); | |
2575 | Standard_Real aUPrev, aVPrev, aUCurr, aVCurr; | |
2576 | if (theIsReversed) | |
2577 | { | |
2578 | aPPrev.ParametersOnS2(aUPrev, aVPrev); // S2 - quadric, set U,V by Pnt3D | |
2579 | aPCurr.ParametersOnS2(aUCurr, aVCurr); // S2 - quadric, set U,V by Pnt3D | |
2580 | } | |
2581 | else | |
2582 | { | |
2583 | aPPrev.ParametersOnS1(aUPrev, aVPrev); // S1 - quadric, set U,V by Pnt3D | |
2584 | aPCurr.ParametersOnS1(aUCurr, aVCurr); // S1 - quadric, set U,V by Pnt3D | |
2585 | } | |
2586 | ||
2587 | // Ignore cases when the WLine goes along the surface boundary completely. | |
2588 | ||
2589 | if (IsPointOnBoundary(theToler2D, aUf, aUPeriod, aUCurr) && | |
2590 | !IsPointOnBoundary(theToler2D, aUf, aUPeriod, aUPrev)) | |
2591 | { | |
2592 | theIsOnBoundary = Standard_True; | |
2593 | } | |
2594 | else if (IsPointOnBoundary(theToler2D, aUl, aUPeriod, aUCurr) && | |
2595 | !IsPointOnBoundary(theToler2D, aUl, aUPeriod, aUPrev)) | |
2596 | { | |
2597 | theIsOnBoundary = Standard_True; | |
2598 | } | |
2599 | else if (IsPointOnBoundary(theToler2D, aVf, aVPeriod, aVCurr) && | |
2600 | !IsPointOnBoundary(theToler2D, aVf, aVPeriod, aVPrev)) | |
2601 | { | |
2602 | theIsOnBoundary = Standard_True; | |
2603 | } | |
2604 | else if (IsPointOnBoundary(theToler2D, aVl, aVPeriod, aVCurr) && | |
2605 | !IsPointOnBoundary(theToler2D, aVl, aVPeriod, aVPrev)) | |
2606 | { | |
2607 | theIsOnBoundary = Standard_True; | |
2608 | } | |
2609 | ||
2610 | if (theIsOnBoundary) | |
2611 | { | |
2612 | // Adjust, to avoid bad jumping of the WLine. | |
2613 | ||
2614 | const Standard_Real aDu = (aUPrev - aUCurr); | |
2615 | const Standard_Real aDv = (aVPrev - aVCurr); | |
2616 | if (aUPeriod > 0.0 && (2.0*Abs(aDu) > aUPeriod)) | |
2617 | { | |
2618 | aUCurr += Sign(aUPeriod, aDu); | |
2619 | } | |
2620 | ||
2621 | if (aVPeriod > 0.0 && (2.0*Abs(aDv) > aVPeriod)) | |
2622 | { | |
2623 | aVCurr += Sign(aVPeriod, aDv); | |
2624 | } | |
2625 | ||
2626 | IntSurf_PntOn2S aPoint = aPCurr; | |
2627 | aPoint.SetValue(!theIsReversed, aUCurr, aVCurr); | |
2628 | theNewLine->Add(aPoint); | |
2629 | } | |
2630 | } | |
4e14c88f | 2631 | //======================================================================= |
2632 | //function : DecomposeResult | |
2633 | //purpose : Split <theLine> in the places where it passes through seam edge | |
2634 | // or singularity (apex of cone or pole of sphere). | |
2635 | // This passage is detected by jump of U-parameter | |
2636 | // from point to point. | |
2637 | //======================================================================= | |
77dbd1f1 | 2638 | static Standard_Boolean DecomposeResult(const Handle(IntPatch_PointLine)& theLine, |
191478a5 | 2639 | const Standard_Boolean IsReversed, |
2640 | const IntSurf_Quadric& theQuad, | |
2641 | const Handle(Adaptor3d_TopolTool)& thePDomain, | |
c22b52d6 | 2642 | const Handle(Adaptor3d_Surface)& theQSurf, //quadric |
2643 | const Handle(Adaptor3d_Surface)& thePSurf, //parametric | |
191478a5 | 2644 | const Standard_Real theArcTol, |
a09c8f3a | 2645 | const Standard_Real theTolTang, |
191478a5 | 2646 | IntPatch_SequenceOfLine& theLines) |
7fd59977 | 2647 | { |
77dbd1f1 | 2648 | if(theLine->ArcType() == IntPatch_Restriction) |
2649 | { | |
2650 | const Handle(IntPatch_RLine)& aRL = Handle(IntPatch_RLine)::DownCast(theLine); | |
2651 | if(!aRL.IsNull()) | |
2652 | { | |
c22b52d6 | 2653 | const Handle(Adaptor2d_Curve2d)& anArc = aRL->IsArcOnS1() ? |
77dbd1f1 | 2654 | aRL->ArcOnS1() : |
2655 | aRL->ArcOnS2(); | |
c22b52d6 | 2656 | if(anArc->GetType() != GeomAbs_Line) |
77dbd1f1 | 2657 | { |
2658 | //Restriction line must be isoline. | |
2659 | //Other cases are not supported by | |
2660 | //existing algorithms. | |
2661 | ||
2662 | return Standard_False; | |
2663 | } | |
2664 | } | |
2665 | } | |
2666 | ||
4e14c88f | 2667 | const Standard_Real aDeltaUmax = M_PI_2; |
191478a5 | 2668 | const Standard_Real aTOL3D = 1.e-10, |
2669 | aTOL2D = Precision::PConfusion(), | |
2670 | aTOL2DS = Precision::PConfusion(); | |
7fd59977 | 2671 | |
77dbd1f1 | 2672 | const Handle(IntSurf_LineOn2S)& aSLine = theLine->Curve(); |
7fd59977 | 2673 | |
191478a5 | 2674 | if(aSLine->NbPoints() <= 2) |
2675 | { | |
2676 | return Standard_False; | |
2677 | } | |
2678 | ||
2679 | //Deletes repeated vertices | |
77dbd1f1 | 2680 | Handle(IntSurf_LineOn2S) aVLine = GetVertices(theLine,aTOL3D,aTOL2D); |
191478a5 | 2681 | |
2682 | Handle(IntSurf_LineOn2S) aSSLine(aSLine); | |
7fd59977 | 2683 | |
191478a5 | 2684 | if(aSSLine->NbPoints() <= 1) |
2685 | return Standard_False; | |
7fd59977 | 2686 | |
191478a5 | 2687 | AdjustLine(aSSLine,IsReversed,theQSurf,aTOL2D); |
7fd59977 | 2688 | |
77dbd1f1 | 2689 | if(theLine->ArcType() == IntPatch_Walking) |
191478a5 | 2690 | { |
2691 | Standard_Boolean isInserted = Standard_True; | |
2692 | while(isInserted) | |
2693 | { | |
2694 | const Standard_Integer aNbPnts = aSSLine->NbPoints(); | |
2695 | TColStd_Array1OfInteger aPTypes(1,aNbPnts); | |
2696 | SearchVertices(aSSLine,aVLine,aPTypes); | |
2697 | isInserted = InsertSeamVertices(aSSLine,IsReversed,aVLine,aPTypes,aTOL2D); | |
7fd59977 | 2698 | } |
7fd59977 | 2699 | } |
2700 | ||
191478a5 | 2701 | const Standard_Integer aLindex = aSSLine->NbPoints(); |
2702 | Standard_Integer aFindex = 1, aBindex = 0; | |
7fd59977 | 2703 | |
7fd59977 | 2704 | // build WLine parts (if any) |
191478a5 | 2705 | Standard_Boolean flNextLine = Standard_True; |
2706 | Standard_Boolean hasBeenDecomposed = Standard_False; | |
e2e0498b | 2707 | IntPatch_SpecPntType aPrePointExist = IntPatch_SPntNone; |
4e14c88f | 2708 | |
10ee9976 | 2709 | IntSurf_PntOn2S PrePoint; |
191478a5 | 2710 | while(flNextLine) |
2711 | { | |
2712 | // reset variables | |
2713 | flNextLine = Standard_False; | |
2714 | Standard_Boolean isDecomposited = Standard_False; | |
7fd59977 | 2715 | |
191478a5 | 2716 | Handle(IntSurf_LineOn2S) sline = new IntSurf_LineOn2S(); |
7fd59977 | 2717 | |
191478a5 | 2718 | //if((Lindex-Findex+1) <= 2 ) |
a09c8f3a | 2719 | if((aLindex <= aFindex) && !aPrePointExist) |
4e14c88f | 2720 | { |
2721 | //break of "while(flNextLine)" cycle | |
2722 | break; | |
2723 | } | |
10ee9976 | 2724 | |
a09c8f3a | 2725 | if(aPrePointExist) |
4e14c88f | 2726 | { |
4e14c88f | 2727 | const IntSurf_PntOn2S& aRefPt = aSSLine->Value(aFindex); |
2728 | ||
a09c8f3a | 2729 | const Standard_Real aURes = theQSurf->UResolution(theArcTol), |
e2e0498b | 2730 | aVRes = theQSurf->VResolution(theArcTol); |
4e14c88f | 2731 | |
e2e0498b | 2732 | const Standard_Real aTol2d = (aPrePointExist == IntPatch_SPntPole) ? -1.0 : |
2733 | (aPrePointExist == IntPatch_SPntSeamV)? aVRes : | |
2734 | (aPrePointExist == IntPatch_SPntSeamUV)? Max(aURes, aVRes) : aURes; | |
a09c8f3a | 2735 | |
e2e0498b | 2736 | if(IntPatch_SpecialPoints::ContinueAfterSpecialPoint(theQSurf, thePSurf, aRefPt, |
2737 | aPrePointExist, aTol2d, | |
2738 | PrePoint, IsReversed)) | |
4e14c88f | 2739 | { |
a09c8f3a | 2740 | sline->Add(PrePoint); |
3306fdd9 | 2741 | |
2742 | //Avoid adding duplicate points. | |
2743 | for (;aFindex <= aLindex; aFindex++) | |
2744 | { | |
2745 | if (!PrePoint.IsSame(aSSLine->Value(aFindex), theTolTang)) | |
2746 | { | |
2747 | break; | |
2748 | } | |
2749 | } | |
4e14c88f | 2750 | } |
2751 | else | |
2752 | { | |
2753 | //break of "while(flNextLine)" cycle | |
2754 | break; | |
2755 | } | |
2756 | } | |
2757 | ||
e2e0498b | 2758 | aPrePointExist = IntPatch_SPntNone; |
4e14c88f | 2759 | |
191478a5 | 2760 | // analyze other points |
2761 | for(Standard_Integer k = aFindex; k <= aLindex; k++) | |
2762 | { | |
2763 | if( k == aFindex ) | |
2764 | { | |
10ee9976 | 2765 | PrePoint = aSSLine->Value(k); |
a09c8f3a | 2766 | sline->Add(PrePoint); |
191478a5 | 2767 | continue; |
2768 | } | |
7fd59977 | 2769 | |
779d6bc6 | 2770 | //Check whether the current point is on the boundary of theQSurf. |
2771 | //If that is TRUE then the Walking-line will be decomposed in this point. | |
2772 | //However, this boundary is not singular-point (like seam or pole of sphere). | |
2773 | //Therefore, its processing will be simplified. | |
2774 | Standard_Boolean isOnBoundary = Standard_False; | |
2775 | ||
2776 | // Values of sline and isOnBoundary can be changed by this function | |
2777 | DetectOfBoundaryAchievement(theQSurf, IsReversed, aSSLine, | |
2778 | k, aTOL2D, sline, isOnBoundary); | |
2779 | ||
3306fdd9 | 2780 | aPrePointExist = IsSeamOrPole(theQSurf, aSSLine, IsReversed, |
2781 | k - 1, theTolTang, aDeltaUmax); | |
779d6bc6 | 2782 | |
2783 | if (isOnBoundary && (aPrePointExist != IntPatch_SPntPoleSeamU)) | |
191478a5 | 2784 | { |
779d6bc6 | 2785 | // If the considered point is on seam then its UV-parameters |
2786 | // are defined to within the surface period. Therefore, we can | |
2787 | // trust already computed parameters of this point. | |
2788 | // However, if this point (which is on the surface boundary) is | |
2789 | // a sphere pole or cone apex then its (point's) parameters | |
2790 | // have to be recomputed in the code below | |
2791 | // (see IntPatch_SpecialPoints::AddSingularPole() method). | |
2792 | // E.g. see "bugs modalg_6 bug26684_2" test case. | |
2793 | ||
2794 | aPrePointExist = IntPatch_SPntNone; | |
7fd59977 | 2795 | } |
7fd59977 | 2796 | |
779d6bc6 | 2797 | if (aPrePointExist != IntPatch_SPntNone) |
191478a5 | 2798 | { |
2799 | aBindex = k; | |
2800 | isDecomposited = Standard_True; | |
10ee9976 | 2801 | //// |
a09c8f3a | 2802 | const IntSurf_PntOn2S& aRefPt = aSSLine->Value(aBindex-1); |
2803 | ||
e2e0498b | 2804 | Standard_Real aCompareTol3D = Precision::Confusion(); |
2805 | Standard_Real aCompareTol2D = Precision::PConfusion(); | |
a09c8f3a | 2806 | |
e2e0498b | 2807 | IntSurf_PntOn2S aNewPoint = aRefPt; |
2808 | IntPatch_SpecPntType aLastType = IntPatch_SPntNone; | |
a09c8f3a | 2809 | |
e2e0498b | 2810 | if(aPrePointExist == IntPatch_SPntSeamUV) |
a09c8f3a | 2811 | { |
e2e0498b | 2812 | aPrePointExist = IntPatch_SPntNone; |
2813 | aLastType = IntPatch_SPntSeamUV; | |
2814 | IntPatch_SpecialPoints::AddCrossUVIsoPoint(theQSurf, thePSurf, | |
2815 | aRefPt, theTolTang, | |
2816 | aNewPoint, IsReversed); | |
2817 | } | |
2818 | else if(aPrePointExist == IntPatch_SPntSeamV) | |
2819 | {//WLine goes through seam | |
2820 | aPrePointExist = IntPatch_SPntNone; | |
2821 | aLastType = IntPatch_SPntSeamV; | |
a09c8f3a | 2822 | |
e2e0498b | 2823 | //Not quadric point |
2824 | Standard_Real aU0 = 0.0, aV0 = 0.0; | |
2825 | //Quadric point | |
2826 | Standard_Real aUQuadRef = 0.0, aVQuadRef = 0.0; | |
a09c8f3a | 2827 | |
e2e0498b | 2828 | if(IsReversed) |
10ee9976 | 2829 | { |
e2e0498b | 2830 | aRefPt.Parameters(aU0, aV0, aUQuadRef, aVQuadRef); |
10ee9976 | 2831 | } |
e2e0498b | 2832 | else |
10ee9976 | 2833 | { |
e2e0498b | 2834 | aRefPt.Parameters(aUQuadRef, aVQuadRef, aU0, aV0); |
10ee9976 | 2835 | } |
a09c8f3a | 2836 | |
bf714c84 | 2837 | math_Vector aTol(1, 3), aStartPoint(1,3), |
e2e0498b | 2838 | anInfBound(1, 3), aSupBound(1, 3); |
2839 | ||
a09c8f3a | 2840 | //Parameters on parametric surface |
779d6bc6 | 2841 | Standard_Real aUp = 0.0, aVp = 0.0, aUq = 0.0, aVq = 0.0; |
a09c8f3a | 2842 | if(IsReversed) |
10ee9976 | 2843 | { |
779d6bc6 | 2844 | aSSLine->Value(k).Parameters(aUp, aVp, aUq, aVq); |
10ee9976 | 2845 | } |
2846 | else | |
2847 | { | |
779d6bc6 | 2848 | aSSLine->Value(k).Parameters(aUq, aVq, aUp, aVp); |
10ee9976 | 2849 | } |
a09c8f3a | 2850 | |
2851 | aTol(1) = thePSurf->UResolution(theArcTol); | |
2852 | aTol(2) = thePSurf->VResolution(theArcTol); | |
2853 | aTol(3) = theQSurf->UResolution(theArcTol); | |
2854 | aStartPoint(1) = 0.5*(aU0 + aUp); | |
2855 | aStartPoint(2) = 0.5*(aV0 + aVp); | |
779d6bc6 | 2856 | aStartPoint(3) = 0.5*(aUQuadRef + aUq); |
bf714c84 | 2857 | anInfBound(1) = thePSurf->FirstUParameter(); |
2858 | anInfBound(2) = thePSurf->FirstVParameter(); | |
2859 | anInfBound(3) = theQSurf->FirstUParameter(); | |
2860 | aSupBound(1) = thePSurf->LastUParameter(); | |
2861 | aSupBound(2) = thePSurf->LastVParameter(); | |
2862 | aSupBound(3) = theQSurf->LastUParameter(); | |
a09c8f3a | 2863 | |
e2e0498b | 2864 | IntPatch_SpecialPoints:: |
3306fdd9 | 2865 | AddPointOnUorVIso(theQSurf, thePSurf, aRefPt, Standard_False, 0.0, |
e2e0498b | 2866 | aTol, aStartPoint, anInfBound, aSupBound, |
2867 | aNewPoint, IsReversed); | |
2868 | } | |
2869 | else if(aPrePointExist == IntPatch_SPntPoleSeamU) | |
2870 | { | |
779d6bc6 | 2871 | aPrePointExist = IntPatch_SPntNone; |
a09c8f3a | 2872 | |
e2e0498b | 2873 | IntPatch_Point aVert; |
2874 | aVert.SetValue(aRefPt); | |
3306fdd9 | 2875 | aVert.SetTolerance(theTolTang); |
a09c8f3a | 2876 | |
e2e0498b | 2877 | if(IntPatch_SpecialPoints:: |
3306fdd9 | 2878 | AddSingularPole(theQSurf, thePSurf, aRefPt, |
e2e0498b | 2879 | aVert, aNewPoint, IsReversed)) |
4e14c88f | 2880 | { |
e2e0498b | 2881 | aPrePointExist = IntPatch_SPntPole; |
2882 | aLastType = IntPatch_SPntPole; | |
779d6bc6 | 2883 | if (isOnBoundary) |
2884 | { | |
2885 | // It is necessary to replace earlier added point on | |
2886 | // the surface boundary with the pole. For that, | |
2887 | // here we delete excess point. New point will be added later. | |
2888 | isOnBoundary = Standard_False; | |
2889 | sline->RemovePoint(sline->NbPoints()); | |
2890 | } | |
2891 | ||
e2e0498b | 2892 | aCompareTol2D = -1.0; |
2893 | } //if(IntPatch_AddSpecialPoints::AddSingularPole(...)) | |
a09c8f3a | 2894 | else |
e2e0498b | 2895 | {//Pole is not an intersection point |
2896 | aPrePointExist = IntPatch_SPntSeamU; | |
a09c8f3a | 2897 | } |
2898 | } | |
4e14c88f | 2899 | |
e2e0498b | 2900 | if(aPrePointExist == IntPatch_SPntSeamU) |
2901 | {//WLine goes through seam | |
2902 | aPrePointExist = IntPatch_SPntNone; | |
2903 | aLastType = IntPatch_SPntSeamU; | |
4e14c88f | 2904 | |
e2e0498b | 2905 | //Not quadric point |
2906 | Standard_Real aU0 = 0.0, aV0 = 0.0; | |
2907 | //Quadric point | |
2908 | Standard_Real aUQuadRef = 0.0, aVQuadRef = 0.0; | |
4e14c88f | 2909 | |
e2e0498b | 2910 | if(IsReversed) |
a09c8f3a | 2911 | { |
e2e0498b | 2912 | aRefPt.Parameters(aU0, aV0, aUQuadRef, aVQuadRef); |
a09c8f3a | 2913 | } |
a09c8f3a | 2914 | else |
e2e0498b | 2915 | { |
2916 | aRefPt.Parameters(aUQuadRef, aVQuadRef, aU0, aV0); | |
a09c8f3a | 2917 | } |
a09c8f3a | 2918 | |
bf714c84 | 2919 | math_Vector aTol(1, 3), aStartPoint(1,3), |
2920 | anInfBound(1, 3), aSupBound(1, 3); | |
a09c8f3a | 2921 | |
2922 | //Parameters on parametric surface | |
779d6bc6 | 2923 | Standard_Real aUp = 0.0, aVp = 0.0, aUq = 0.0, aVq = 0.0; |
2924 | if (IsReversed) | |
a09c8f3a | 2925 | { |
779d6bc6 | 2926 | aSSLine->Value(k).Parameters(aUp, aVp, aUq, aVq); |
a09c8f3a | 2927 | } |
2928 | else | |
2929 | { | |
779d6bc6 | 2930 | aSSLine->Value(k).Parameters(aUq, aVq, aUp, aVp); |
a09c8f3a | 2931 | } |
2932 | ||
2933 | aTol(1) = thePSurf->UResolution(theArcTol); | |
2934 | aTol(2) = thePSurf->VResolution(theArcTol); | |
2935 | aTol(3) = theQSurf->VResolution(theArcTol); | |
2936 | aStartPoint(1) = 0.5*(aU0 + aUp); | |
2937 | aStartPoint(2) = 0.5*(aV0 + aVp); | |
779d6bc6 | 2938 | aStartPoint(3) = 0.5*(aVQuadRef + aVq); |
bf714c84 | 2939 | anInfBound(1) = thePSurf->FirstUParameter(); |
2940 | anInfBound(2) = thePSurf->FirstVParameter(); | |
2941 | anInfBound(3) = theQSurf->FirstVParameter(); | |
2942 | aSupBound(1) = thePSurf->LastUParameter(); | |
2943 | aSupBound(2) = thePSurf->LastVParameter(); | |
2944 | aSupBound(3) = theQSurf->LastVParameter(); | |
a09c8f3a | 2945 | |
e2e0498b | 2946 | IntPatch_SpecialPoints:: |
3306fdd9 | 2947 | AddPointOnUorVIso(theQSurf, thePSurf, aRefPt, Standard_True, 0.0, aTol, |
e2e0498b | 2948 | aStartPoint, anInfBound, aSupBound, aNewPoint, |
2949 | IsReversed); | |
2950 | } | |
a09c8f3a | 2951 | |
e2e0498b | 2952 | if(!aNewPoint.IsSame(aRefPt, aCompareTol3D, aCompareTol2D)) |
2953 | { | |
779d6bc6 | 2954 | if (isOnBoundary) |
2955 | break; | |
2956 | ||
e2e0498b | 2957 | sline->Add(aNewPoint); |
2958 | aPrePointExist = aLastType; | |
2959 | PrePoint = aNewPoint; | |
2960 | } | |
2961 | else | |
2962 | { | |
779d6bc6 | 2963 | if (isOnBoundary || (sline->NbPoints() == 1)) |
a09c8f3a | 2964 | { |
e2e0498b | 2965 | //FIRST point of the sline is the pole of the quadric. |
2966 | //Therefore, there is no point in decomposition. | |
a09c8f3a | 2967 | |
779d6bc6 | 2968 | // If the considered point is on surface boundary then |
2969 | // it is already marked as vertex. So, decomposition is | |
2970 | // not required, too. | |
2971 | ||
e2e0498b | 2972 | PrePoint = aRefPt; |
779d6bc6 | 2973 | aPrePointExist = isOnBoundary ? IntPatch_SPntNone : aLastType; |
a09c8f3a | 2974 | } |
4e14c88f | 2975 | } |
2976 | ||
10ee9976 | 2977 | //// |
191478a5 | 2978 | break; |
779d6bc6 | 2979 | } //if (aPrePointExist != IntPatch_SPntNone) cond. |
7fd59977 | 2980 | |
10ee9976 | 2981 | PrePoint = aSSLine->Value(k); |
779d6bc6 | 2982 | |
2983 | if (isOnBoundary) | |
2984 | { | |
2985 | aBindex = k; | |
2986 | isDecomposited = Standard_True; | |
2987 | aPrePointExist = IntPatch_SPntNone; | |
2988 | break; | |
2989 | } | |
2990 | else | |
2991 | { | |
2992 | sline->Add(aSSLine->Value(k)); | |
2993 | } | |
77dbd1f1 | 2994 | } //for(Standard_Integer k = aFindex; k <= aLindex; k++) |
2995 | ||
2996 | //Creation of new line as part of existing theLine. | |
2997 | //This part is defined by sline. | |
2998 | ||
2999 | if(sline->NbPoints() == 1) | |
3000 | { | |
3001 | flNextLine = Standard_True; | |
3306fdd9 | 3002 | |
3003 | if (aFindex < aBindex) | |
3004 | aFindex = aBindex; | |
77dbd1f1 | 3005 | |
3006 | //Go to the next part of aSSLine | |
3007 | //because we cannot create the line | |
3008 | //with single point. | |
3009 | ||
3010 | continue; | |
7fd59977 | 3011 | } |
7fd59977 | 3012 | |
191478a5 | 3013 | IntSurf_PntOn2S aVF, aVL; |
3014 | Standard_Boolean addVF = Standard_False, addVL = Standard_False; | |
3015 | VerifyVertices(sline,IsReversed,aVLine,aTOL2DS,theArcTol, | |
3016 | thePDomain,aVF,addVF,aVL,addVL); | |
3017 | ||
3018 | Standard_Boolean hasInternals = HasInternals(sline,aVLine); | |
3019 | ||
3020 | Standard_Real D3F = 0., D3L = 0.; | |
3021 | ToSmooth(sline,IsReversed,theQuad,Standard_True,D3F); | |
3022 | ToSmooth(sline,IsReversed,theQuad,Standard_False,D3L); | |
3023 | ||
3024 | //if(D3F <= 1.5e-7 && sline->NbPoints() >=3) { | |
3025 | // D3F = sline->Value(2).Value().Distance(sline->Value(3).Value()); | |
3026 | //} | |
3027 | //if(D3L <= 1.5e-7 && sline->NbPoints() >=3) { | |
3028 | // D3L = sline->Value(sline->NbPoints()-1).Value().Distance(sline-> | |
3029 | // Value(sline->NbPoints()-2).Value()); | |
3030 | //} | |
3031 | ||
3032 | if(addVF || addVL) | |
3033 | { | |
3034 | Standard_Boolean isAdded = AddVertices(sline,aVF,addVF,aVL,addVL,D3F,D3L); | |
3035 | if(isAdded) | |
3036 | { | |
3037 | ToSmooth(sline,IsReversed,theQuad,Standard_True,D3F); | |
3038 | ToSmooth(sline,IsReversed,theQuad,Standard_False,D3L); | |
3039 | } | |
7fd59977 | 3040 | } |
7fd59977 | 3041 | |
77dbd1f1 | 3042 | if(theLine->ArcType() == IntPatch_Walking) |
191478a5 | 3043 | { |
77dbd1f1 | 3044 | IntPatch_Point aTPntF, aTPntL; |
3045 | ||
3046 | Handle(IntPatch_WLine) wline = | |
3047 | new IntPatch_WLine(sline,Standard_False, | |
3048 | theLine->TransitionOnS1(),theLine->TransitionOnS2()); | |
98974dcc | 3049 | wline->SetCreatingWayInfo(IntPatch_WLine::IntPatch_WLImpPrm); |
77dbd1f1 | 3050 | |
779d6bc6 | 3051 | Standard_Real aU1 = 0.0, aV1 = 0.0, aU2 = 0.0, aV2 = 0.0; |
77dbd1f1 | 3052 | gp_Pnt aSPnt(sline->Value(1).Value()); |
779d6bc6 | 3053 | sline->Value(1).Parameters(aU1, aV1, aU2, aV2); |
77dbd1f1 | 3054 | aTPntF.SetValue(aSPnt,theArcTol,Standard_False); |
779d6bc6 | 3055 | aTPntF.SetParameters(aU1, aV1, aU2, aV2); |
3056 | aTPntF.SetParameter(1.0); | |
77dbd1f1 | 3057 | wline->AddVertex(aTPntF); |
3058 | wline->SetFirstPoint(1); | |
3059 | ||
3060 | if(hasInternals) | |
3061 | { | |
3062 | PutIntVertices(wline,sline,IsReversed,aVLine,theArcTol); | |
3063 | } | |
7fd59977 | 3064 | |
77dbd1f1 | 3065 | aSPnt = sline->Value(sline->NbPoints()).Value(); |
779d6bc6 | 3066 | sline->Value(sline->NbPoints()).Parameters(aU1, aV1, aU2, aV2); |
77dbd1f1 | 3067 | aTPntL.SetValue(aSPnt,theArcTol,Standard_False); |
779d6bc6 | 3068 | aTPntL.SetParameters(aU1, aV1, aU2, aV2); |
77dbd1f1 | 3069 | aTPntL.SetParameter(sline->NbPoints()); |
3070 | wline->AddVertex(aTPntL); | |
a09c8f3a | 3071 | wline->SetLastPoint(wline->NbVertex()); |
191478a5 | 3072 | |
77dbd1f1 | 3073 | IntPatch_SequenceOfLine segm; |
3074 | Standard_Boolean isSplited = SplitOnSegments(wline,Standard_False, | |
3075 | theLine->TransitionOnS1(),theLine->TransitionOnS2(),theArcTol,segm); | |
191478a5 | 3076 | |
77dbd1f1 | 3077 | if(!isSplited) |
3078 | { | |
3079 | theLines.Append(wline); | |
3080 | } | |
3081 | else | |
3082 | { | |
3083 | Standard_Integer nbsegms = segm.Length(); | |
3084 | Standard_Integer iseg = 0; | |
3085 | for(iseg = 1; iseg <= nbsegms; iseg++) | |
3086 | theLines.Append(segm(iseg)); | |
3087 | } | |
191478a5 | 3088 | } |
3089 | else | |
77dbd1f1 | 3090 | {//theLine->ArcType() == IntPatch_Restriction |
3091 | if(!isDecomposited && !hasBeenDecomposed) | |
3092 | { | |
3093 | //The line has not been changed | |
3094 | theLines.Append(Handle(IntPatch_RLine)::DownCast(theLine)); | |
3095 | return hasBeenDecomposed; | |
3096 | } | |
3097 | ||
3098 | IntPatch_Point aTPnt; | |
3099 | gp_Pnt2d aPSurf; | |
3100 | gp_Pnt aSPnt; | |
3101 | ||
3102 | Handle(IntPatch_RLine) aRLine = new IntPatch_RLine(*Handle(IntPatch_RLine)::DownCast(theLine)); | |
3103 | ||
3104 | aRLine->ClearVertexes(); | |
3105 | aRLine->SetCurve(sline); | |
3106 | ||
3107 | if(hasInternals) | |
3108 | { | |
3109 | PutIntVertices(aRLine,sline,IsReversed,aVLine,theArcTol); | |
3110 | } | |
3111 | ||
c22b52d6 | 3112 | const Handle(Adaptor2d_Curve2d)& anArc = aRLine->IsArcOnS1() ? |
77dbd1f1 | 3113 | aRLine->ArcOnS1() : |
3114 | aRLine->ArcOnS2(); | |
3115 | ||
3116 | Standard_Real aFPar = anArc->FirstParameter(), | |
3117 | aLPar = anArc->LastParameter(); | |
3118 | ||
3119 | const IntSurf_PntOn2S &aRFirst = sline->Value(1), | |
3120 | &aRLast = sline->Value(sline->NbPoints()); | |
3121 | ||
c22b52d6 | 3122 | const gp_Lin2d aLin(anArc->Line()); |
77dbd1f1 | 3123 | |
3124 | for(Standard_Integer aFLIndex = 0; aFLIndex < 2; aFLIndex++) | |
3125 | { | |
779d6bc6 | 3126 | Standard_Real aU1 = 0.0, aV1 = 0.0, aU2 = 0.0, aV2 = 0.0; |
77dbd1f1 | 3127 | if(aFLIndex == 0) |
3128 | { | |
779d6bc6 | 3129 | aRFirst.Parameters(aU1, aV1, aU2, aV2); |
77dbd1f1 | 3130 | aSPnt.SetXYZ(aRFirst.Value().XYZ()); |
3131 | } | |
3132 | else | |
3133 | { | |
779d6bc6 | 3134 | aRLast.Parameters(aU1, aV1, aU2, aV2); |
77dbd1f1 | 3135 | aSPnt.SetXYZ(aRLast.Value().XYZ()); |
3136 | } | |
3137 | ||
3138 | if(IsReversed) | |
3139 | { | |
779d6bc6 | 3140 | aPSurf.SetCoord(aU1, aV1); |
77dbd1f1 | 3141 | } |
3142 | else | |
3143 | { | |
779d6bc6 | 3144 | aPSurf.SetCoord(aU2, aV2); |
77dbd1f1 | 3145 | } |
3146 | ||
3147 | Standard_Real aPar = ElCLib::Parameter(aLin, aPSurf); | |
3148 | ||
3149 | if(aFLIndex == 0) | |
3150 | { | |
3151 | aFPar = Max(aFPar, aPar); | |
3152 | aPar = aFPar; | |
3153 | } | |
3154 | else | |
3155 | { | |
3156 | aLPar = Min(aLPar, aPar); | |
3157 | aPar = aLPar; | |
3158 | } | |
3159 | ||
3160 | aTPnt.SetParameter(aPar); | |
3161 | aTPnt.SetValue(aSPnt,theArcTol,Standard_False); | |
779d6bc6 | 3162 | aTPnt.SetParameters(aU1, aV1, aU2, aV2); |
77dbd1f1 | 3163 | |
3164 | aRLine->AddVertex(aTPnt); | |
3165 | } | |
3166 | ||
a09c8f3a | 3167 | if(aLPar - aFPar > Precision::PConfusion()) |
3168 | { | |
3169 | aRLine->SetFirstPoint(1); | |
3170 | aRLine->SetLastPoint(aRLine->NbVertex()); | |
77dbd1f1 | 3171 | |
a09c8f3a | 3172 | anArc->Trim(aFPar, aLPar, theArcTol); |
77dbd1f1 | 3173 | |
a09c8f3a | 3174 | theLines.Append(aRLine); |
3175 | } | |
191478a5 | 3176 | } |
7fd59977 | 3177 | |
191478a5 | 3178 | if(isDecomposited) |
3179 | { | |
3180 | aFindex = aBindex; | |
3181 | flNextLine = hasBeenDecomposed = Standard_True; | |
3182 | } | |
7fd59977 | 3183 | } |
3184 | ||
191478a5 | 3185 | return hasBeenDecomposed; |
7fd59977 | 3186 | } |
d4b867e6 | 3187 | |
77dbd1f1 | 3188 | //======================================================================= |
3189 | //function : CheckSegmSegm | |
3190 | //purpose : Returns TRUE if the segment [theParF, theParL] is included | |
3191 | // in the segment [theRefParF, theRefParL] segment. | |
3192 | //======================================================================= | |
3193 | static Standard_Boolean CheckSegmSegm(const Standard_Real theRefParF, | |
3194 | const Standard_Real theRefParL, | |
3195 | const Standard_Real theParF, | |
3196 | const Standard_Real theParL) | |
191478a5 | 3197 | { |
77dbd1f1 | 3198 | if((theParF < theRefParF) || (theParF > theRefParL)) |
3199 | { | |
3200 | return Standard_False; | |
3201 | } | |
d4b867e6 | 3202 | |
77dbd1f1 | 3203 | if((theParL < theRefParF) || (theParL > theRefParL)) |
3204 | { | |
3205 | return Standard_False; | |
3206 | } | |
d4b867e6 | 3207 | |
77dbd1f1 | 3208 | return Standard_True; |
3209 | } | |
3210 | ||
3211 | //======================================================================= | |
3212 | //function : IsCoincide | |
3213 | //purpose : Check, if theLine is coincided with theArc (in 2d-space). | |
3214 | // | |
3215 | // Attention!!! | |
0177fe26 | 3216 | // Cases when theArc is not 2d-line adaptor are supported by |
77dbd1f1 | 3217 | // TopOpeBRep classes only (i.e. are archaic). |
3218 | //======================================================================= | |
3219 | Standard_Boolean IsCoincide(IntPatch_TheSurfFunction& theFunc, | |
3220 | const Handle(IntPatch_PointLine)& theLine, | |
c22b52d6 | 3221 | const Handle(Adaptor2d_Curve2d)& theArc, |
77dbd1f1 | 3222 | const Standard_Boolean isTheSurface1Using, //Surf1 is parametric? |
3223 | const Standard_Real theToler3D, | |
3224 | const Standard_Real theToler2D, | |
3225 | const Standard_Real thePeriod) // Period of parametric surface in direction which is perpendicular to theArc direction. | |
3226 | { | |
9c4214b4 | 3227 | const Standard_Real aCoeffs[] = { 0.02447174185, 0.09549150281, 0.20610737385, 0.34549150281, /*Sin(x)*Sin(x)*/ |
3228 | 0.5, 0.65450849719, 0.79389262615 }; | |
77dbd1f1 | 3229 | if(theLine->ArcType() == IntPatch_Restriction) |
3230 | {//Restriction-restriction processing | |
3231 | const Handle(IntPatch_RLine)& aRL2 = Handle(IntPatch_RLine)::DownCast(theLine); | |
c22b52d6 | 3232 | const Handle(Adaptor2d_Curve2d)& anArc = aRL2->IsArcOnS1() ? aRL2->ArcOnS1() : aRL2->ArcOnS2(); |
77dbd1f1 | 3233 | |
c22b52d6 | 3234 | if(anArc->GetType() != GeomAbs_Line) |
77dbd1f1 | 3235 | { |
3236 | //Restriction line must be isoline. | |
3237 | //Other cases are not supported by | |
3238 | //existing algorithms. | |
3239 | ||
3240 | return Standard_False; | |
3241 | } | |
3242 | ||
c22b52d6 | 3243 | const gp_Lin2d aLin1(theArc->Line()), |
3244 | aLin2(anArc->Line()); | |
77dbd1f1 | 3245 | |
3246 | if(!aLin1.Direction().IsParallel(aLin2.Direction(), Precision::Angular())) | |
3247 | { | |
3248 | return Standard_False; | |
3249 | } | |
3250 | ||
3251 | const Standard_Real aDist = | |
c22b52d6 | 3252 | theArc->Line().Distance(anArc->Line()); |
77dbd1f1 | 3253 | if((aDist < theToler2D) || (Abs(aDist - thePeriod) < theToler2D)) |
3254 | { | |
3255 | const Standard_Real aRf = theArc->FirstParameter(), | |
3256 | aRl = theArc->LastParameter(); | |
3257 | const Standard_Real aParf = anArc->FirstParameter(), | |
3258 | aParl = anArc->LastParameter(); | |
3259 | const gp_Pnt2d aP1(ElCLib::Value(aParf, aLin2)), | |
3260 | aP2(ElCLib::Value(aParl, aLin2)); | |
3261 | ||
3262 | Standard_Real aParam1 = ElCLib::Parameter(aLin1, aP1), | |
3263 | aParam2 = ElCLib::Parameter(aLin1, aP2); | |
3264 | ||
3265 | if(CheckSegmSegm(aRf, aRl, aParam1, aParam2)) | |
3266 | return Standard_True; | |
3267 | ||
3268 | //Lines are parallel. Therefore, there is no point in | |
3269 | //projecting points to another line in order to check | |
3270 | //if segment second line is included in segment of first one. | |
3271 | ||
3272 | return CheckSegmSegm(aParam1, aParam2, aRf, aRl); | |
3273 | } | |
3274 | ||
3275 | return Standard_False; | |
3276 | } | |
3277 | ||
3278 | const Standard_Integer aNbPnts = theLine->NbPnts(); | |
3279 | const Standard_Real aUAf = theArc->FirstParameter(), | |
3280 | aUAl = theArc->LastParameter(); | |
c22b52d6 | 3281 | const gp_Lin2d anArcLin(theArc->Line()); |
77dbd1f1 | 3282 | |
3283 | math_Vector aX(1, 2), aVal(1, 1); | |
d4b867e6 | 3284 | |
3285 | for(Standard_Integer aPtID = 1; aPtID <= aNbPnts; aPtID++) | |
3286 | { | |
77dbd1f1 | 3287 | Standard_Real aUf = 0.0, aVf = 0.0; |
d4b867e6 | 3288 | if(isTheSurface1Using) |
77dbd1f1 | 3289 | theLine->Point(aPtID).ParametersOnS1(aUf, aVf); |
d4b867e6 | 3290 | else |
77dbd1f1 | 3291 | theLine->Point(aPtID).ParametersOnS2(aUf, aVf); |
3292 | ||
3293 | //Take 2d-point in parametric surface (because theArc is | |
3294 | //2d-line in parametric surface). | |
3295 | const gp_Pnt2d aPloc(aUf, aVf); | |
3296 | ||
3297 | const Standard_Real aRParam = ElCLib::Parameter(anArcLin, aPloc); | |
d4b867e6 | 3298 | |
77dbd1f1 | 3299 | if((aRParam < aUAf) || (aRParam > aUAl)) |
3300 | return Standard_False; | |
3301 | ||
3302 | const gp_Pnt2d aPmin(ElCLib::Value(aRParam, anArcLin)); | |
3303 | ||
3304 | const Standard_Real aDist = aPloc.Distance(aPmin); | |
3305 | if((aDist < theToler2D) || (Abs(aDist - thePeriod) < theToler2D)) | |
3306 | {//Considered point is in Restriction line. | |
3307 | //Go to the next point. | |
d4b867e6 | 3308 | continue; |
77dbd1f1 | 3309 | } |
3310 | ||
3311 | //Check if intermediate points between aPloc and theArc are | |
3312 | //intersection point (i.e. if aPloc is in tangent zone between | |
3313 | //two intersected surfaces). | |
3314 | ||
3315 | const Standard_Real aUl = aPmin.X(), aVl = aPmin.Y(); | |
d4b867e6 | 3316 | |
9c4214b4 | 3317 | Standard_Real aU, aV; |
3318 | Standard_Real dU = aUl - aUf, dV = aVl - aVf; | |
3319 | for(Standard_Integer i = 0; i < 7; i++) | |
d4b867e6 | 3320 | { |
9c4214b4 | 3321 | aU = aUf + aCoeffs[i] * dU; |
3322 | aV = aVf + aCoeffs[i] * dV; | |
3323 | ||
77dbd1f1 | 3324 | aX.Value(1) = aU; |
3325 | aX.Value(2) = aV; | |
3326 | ||
3327 | if(!theFunc.Value(aX, aVal)) | |
d4b867e6 | 3328 | { |
77dbd1f1 | 3329 | return Standard_False; |
d4b867e6 | 3330 | } |
3331 | ||
9c4214b4 | 3332 | if(Abs(theFunc.Root()) > theToler3D) |
d4b867e6 | 3333 | { |
77dbd1f1 | 3334 | return Standard_False; |
9c4214b4 | 3335 | } |
d4b867e6 | 3336 | } |
d4b867e6 | 3337 | } |
77dbd1f1 | 3338 | |
d4b867e6 | 3339 | return Standard_True; |
77dbd1f1 | 3340 | } |