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