Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1993-11-26 |
2 | // Created by: Modelistation | |
3 | // Copyright (c) 1993-1999 Matra Datavision | |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS | |
5 | // | |
6 | // The content of this file is subject to the Open CASCADE Technology Public | |
7 | // License Version 6.5 (the "License"). You may not use the content of this file | |
8 | // except in compliance with the License. Please obtain a copy of the License | |
9 | // at http://www.opencascade.org and read it completely before using this file. | |
10 | // | |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
13 | // | |
14 | // The Original Code and all software distributed under the License is | |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
16 | // Initial Developer hereby disclaims all such warranties, including without | |
17 | // limitation, any warranties of merchantability, fitness for a particular | |
18 | // purpose or non-infringement. Please see the License for the specific terms | |
19 | // and conditions governing the rights and limitations under the License. | |
20 | ||
7fd59977 | 21 | |
22 | #include <IntPatch_ALineToWLine.ixx> | |
23 | ||
24 | #include <IntSurf_LineOn2S.hxx> | |
25 | #include <IntSurf_PntOn2S.hxx> | |
26 | #include <IntSurf_TypeTrans.hxx> | |
27 | #include <IntSurf_Situation.hxx> | |
28 | ||
29 | #include <TColStd_Array1OfReal.hxx> | |
30 | #include <TColStd_Array1OfInteger.hxx> | |
31 | ||
32 | #include <Precision.hxx> | |
33 | ||
34 | #include <gp_Pnt.hxx> | |
35 | #include <gp_Vec.hxx> | |
36 | ||
37 | #include <Adaptor2d_HCurve2d.hxx> | |
38 | #include <GeomAbs_SurfaceType.hxx> | |
39 | #include <gp_Pnt2d.hxx> | |
40 | #include <gp_Vec2d.hxx> | |
41 | #include <IntAna2d_AnaIntersection.hxx> | |
42 | #include <gp_Lin2d.hxx> | |
43 | #include <IntAna2d_IntPoint.hxx> | |
44 | #include <gp_Cone.hxx> | |
45 | ||
46 | ||
47 | static | |
48 | gp_Pnt DefineDU(const Handle(IntPatch_ALine)& aline, | |
49 | const Standard_Real U, | |
50 | Standard_Real& DU, | |
51 | const Standard_Real CurvDef, | |
52 | const Standard_Real AngDef); | |
53 | ||
54 | static | |
55 | Standard_Boolean SameCurve(const Handle_Adaptor2d_HCurve2d& C1, | |
56 | const Handle_Adaptor2d_HCurve2d& C2); | |
57 | ||
58 | static | |
59 | void RecadreMemePeriode(const IntSurf_Quadric aQuad1, | |
60 | const IntSurf_Quadric aQuad2, | |
61 | Standard_Real& u1, | |
62 | Standard_Real& u2, | |
63 | const Standard_Real anu1, | |
64 | const Standard_Real anu2); | |
65 | ||
66 | static | |
67 | void CorrectFirstPartOfLine(Handle(IntSurf_LineOn2S)& LinOn2S, | |
68 | const IntSurf_Quadric aQuad1, | |
69 | const IntSurf_Quadric aQuad2, | |
70 | const Standard_Real ref_u1, | |
71 | const Standard_Real ref_u2, | |
72 | Standard_Real& new_u1, | |
73 | Standard_Real& new_u2); | |
74 | ||
75 | // | |
76 | static | |
77 | void RefineParameters(const Handle(IntPatch_ALine)& aALine, | |
78 | const Standard_Real aTb, | |
79 | const Standard_Real aTe, | |
80 | const Standard_Real aTx, | |
81 | const Standard_Integer iDir, | |
82 | const IntSurf_Quadric& aQuadric, | |
83 | const Standard_Real aTol3D, | |
84 | Standard_Real& aUx, | |
85 | Standard_Real& aVx); | |
86 | static | |
87 | Standard_Boolean FindNearParameter(const Handle(IntPatch_ALine)& aALine, | |
88 | const Standard_Real aTx, | |
89 | const Standard_Integer iDir, | |
90 | const Standard_Real aTol3D, | |
91 | Standard_Real& aT1); | |
92 | static | |
93 | Standard_Boolean IsApex(const IntSurf_Quadric& aQuadric, | |
94 | const Standard_Real aVx, | |
95 | const Standard_Real aTol3D); | |
96 | // | |
97 | ||
98 | //-- Je ne sais pas faire mieux et ca m'ennerve. lbr. | |
99 | //======================================================================= | |
100 | //function : IntPatch_ALineToWLine | |
101 | //purpose : | |
102 | //======================================================================= | |
103 | IntPatch_ALineToWLine::IntPatch_ALineToWLine(const IntSurf_Quadric& Quad1, | |
104 | const IntSurf_Quadric& Quad2) | |
105 | : | |
106 | quad1(Quad1), | |
107 | quad2(Quad2), | |
108 | deflectionmax(0.01), | |
109 | pasuvmax(0.05), | |
110 | nbpointsmax(200), | |
111 | type(0), | |
112 | myTolParam(1.e-12), | |
113 | myTolOpenDomain(1.e-9), | |
114 | myTolTransition(1.e-8) | |
115 | { | |
116 | myTol3D=Precision::Confusion(); | |
117 | } | |
118 | //======================================================================= | |
119 | //function : IntPatch_ALineToWLine | |
120 | //purpose : | |
121 | //======================================================================= | |
122 | IntPatch_ALineToWLine::IntPatch_ALineToWLine(const IntSurf_Quadric& Quad1, | |
123 | const IntSurf_Quadric& Quad2, | |
124 | const Standard_Real Deflection, | |
125 | const Standard_Real PasUVMax, | |
126 | const Standard_Integer NbMaxPoints) | |
127 | : | |
128 | quad1(Quad1), | |
129 | quad2(Quad2), | |
130 | deflectionmax(Deflection), | |
131 | pasuvmax(PasUVMax), | |
132 | nbpointsmax(NbMaxPoints), | |
133 | myTolParam(1.e-12), | |
134 | myTolOpenDomain(1.e-9), | |
135 | myTolTransition(1.e-8) | |
136 | { | |
137 | myTol3D=Precision::Confusion(); | |
138 | type = 0; | |
139 | } | |
140 | //======================================================================= | |
141 | //function : SetTol3D | |
142 | //purpose : | |
143 | //======================================================================= | |
144 | void IntPatch_ALineToWLine::SetTol3D(const Standard_Real aTol) | |
145 | { | |
146 | myTol3D = aTol; | |
147 | } | |
148 | //======================================================================= | |
149 | //function : Tol3D | |
150 | //purpose : | |
151 | //======================================================================= | |
152 | Standard_Real IntPatch_ALineToWLine::Tol3D()const | |
153 | { | |
154 | return myTol3D; | |
155 | } | |
156 | //======================================================================= | |
157 | //function : SetTolTransition | |
158 | //purpose : | |
159 | //======================================================================= | |
160 | void IntPatch_ALineToWLine::SetTolTransition(const Standard_Real aTol) | |
161 | { | |
162 | myTolTransition = aTol; | |
163 | } | |
164 | //======================================================================= | |
165 | //function : TolTransition | |
166 | //purpose : | |
167 | //======================================================================= | |
168 | Standard_Real IntPatch_ALineToWLine::TolTransition()const | |
169 | { | |
170 | return myTolTransition; | |
171 | } | |
172 | //======================================================================= | |
173 | //function : SetTolParam | |
174 | //purpose : | |
175 | //======================================================================= | |
176 | void IntPatch_ALineToWLine::SetTolParam(const Standard_Real aTolParam) | |
177 | { | |
178 | myTolParam = aTolParam; | |
179 | } | |
180 | //======================================================================= | |
181 | //function : TolParam | |
182 | //purpose : | |
183 | //======================================================================= | |
184 | Standard_Real IntPatch_ALineToWLine::TolParam()const | |
185 | { | |
186 | return myTolParam; | |
187 | } | |
188 | //======================================================================= | |
189 | //function : SetTolOpenDomain | |
190 | //purpose : | |
191 | //======================================================================= | |
192 | void IntPatch_ALineToWLine::SetTolOpenDomain(const Standard_Real aTol) | |
193 | { | |
194 | myTolOpenDomain = aTol; | |
195 | } | |
196 | //======================================================================= | |
197 | //function : TolOpenDomain | |
198 | //purpose : | |
199 | //======================================================================= | |
200 | Standard_Real IntPatch_ALineToWLine::TolOpenDomain()const | |
201 | { | |
202 | return myTolOpenDomain; | |
203 | } | |
204 | //======================================================================= | |
205 | //function : SetConstantParameter | |
206 | //purpose : | |
207 | //======================================================================= | |
208 | void IntPatch_ALineToWLine::SetConstantParameter() const | |
209 | { | |
210 | } | |
211 | //======================================================================= | |
212 | //function : SetUniformAbscissa | |
213 | //purpose : | |
214 | //======================================================================= | |
215 | void IntPatch_ALineToWLine::SetUniformAbscissa() const | |
216 | { | |
217 | } | |
218 | //======================================================================= | |
219 | //function : SetUniformDeflection | |
220 | //purpose : | |
221 | //======================================================================= | |
222 | void IntPatch_ALineToWLine::SetUniformDeflection() const | |
223 | { | |
224 | } | |
225 | //======================================================================= | |
226 | //function : MakeWLine | |
227 | //purpose : | |
228 | //======================================================================= | |
229 | Handle(IntPatch_WLine) IntPatch_ALineToWLine::MakeWLine(const Handle(IntPatch_ALine)& aline) const | |
230 | { | |
231 | Standard_Boolean included; | |
232 | Standard_Real f = aline->FirstParameter(included); | |
233 | if(!included) { | |
234 | f+=myTolOpenDomain; | |
235 | } | |
236 | Standard_Real l = aline->LastParameter(included); | |
237 | if(!included) { | |
238 | l-=myTolOpenDomain; | |
239 | } | |
240 | return(MakeWLine(aline,f,l)); | |
241 | } | |
242 | ||
243 | //======================================================================= | |
244 | //function : MakeWLine | |
245 | //purpose : | |
246 | //======================================================================= | |
247 | Handle(IntPatch_WLine) IntPatch_ALineToWLine::MakeWLine(const Handle(IntPatch_ALine)& aline, | |
248 | const Standard_Real _firstparam, | |
249 | const Standard_Real _lastparam) const | |
250 | { | |
251 | // | |
252 | Standard_Real dl, dumin, dumax, U, pv, pu1, pv1, pu2, pv2; | |
253 | Standard_Real firstparam, lastparam; | |
254 | Standard_Integer v, nbvtx; | |
255 | Standard_Boolean TriOk; | |
256 | // | |
257 | firstparam = _firstparam; | |
258 | lastparam = _lastparam; | |
259 | // Pas Bon ... | |
260 | // nbpointsmax It is the field. ( =200. by default) | |
261 | dl = (lastparam - firstparam)/(Standard_Real)(nbpointsmax-1); | |
262 | dumin = 0.1*dl; | |
263 | dumax = 10 * dl; | |
264 | // | |
265 | nbvtx = aline->NbVertex(); | |
266 | // | |
267 | TColStd_Array1OfReal paramvertex(1,Max(nbvtx,1)), newparamvertex(1,Max(nbvtx,1)); | |
268 | // | |
269 | for(v = 1; v<=nbvtx; v++) { | |
270 | const IntPatch_Point& aVtx = aline->Vertex(v); | |
271 | pv=aVtx.ParameterOnLine(); | |
272 | paramvertex(v)=pv; | |
273 | newparamvertex(v)=-1.; | |
274 | } | |
275 | // | |
276 | //-- Tri et Confusion des vertex proches | |
277 | do { | |
278 | TriOk = Standard_True; | |
279 | for(v=2; v<=nbvtx;v++) { | |
280 | if(paramvertex(v) < paramvertex(v-1)) { | |
281 | pv=paramvertex(v); | |
282 | paramvertex(v-1)=paramvertex(v); | |
283 | paramvertex(v)=pv; | |
284 | TriOk = Standard_False; | |
285 | } | |
286 | } | |
287 | } | |
288 | while(!TriOk); | |
289 | // | |
290 | for(v=2; v<=nbvtx;v++) { | |
291 | pv=paramvertex(v); | |
292 | pv1=paramvertex(v-1); | |
293 | if(pv-pv1 < myTolParam) { | |
294 | paramvertex(v)=pv1; | |
295 | } | |
296 | } | |
297 | // | |
298 | Standard_Integer t, nbpwline; | |
299 | Standard_Real u1,v1,u2,v2, anu1, anv1, anu2, anv2; | |
300 | Standard_Real aL, dl_sur_2; | |
301 | gp_Pnt Pnt3d, aPnt3d1; | |
302 | IntSurf_PntOn2S POn2S; | |
303 | Handle(IntSurf_LineOn2S) LinOn2S; | |
304 | // | |
305 | LinOn2S = new IntSurf_LineOn2S; | |
306 | ||
307 | //// Modified by jgv, 17.09.09 for OCC21255 //// | |
308 | Standard_Real refpar = RealLast(), ref_u1, ref_u2; | |
309 | if (nbvtx) | |
310 | { | |
311 | const IntPatch_Point& FirstVertex = aline->Vertex(1); | |
312 | refpar = FirstVertex.ParameterOnLine(); | |
313 | FirstVertex.Parameters(ref_u1, v1, ref_u2, v2); | |
314 | } | |
315 | //////////////////////////////////////////////// | |
316 | ||
317 | //----------------------------------------------------- | |
318 | //-- Estimation Grossiere de la longueur de la courbe | |
319 | //-- | |
320 | aL=0.; | |
321 | dl_sur_2=0.5*dl; | |
322 | Pnt3d = aline->Value(firstparam); | |
323 | for(t=0, U=firstparam+dumin; U<lastparam; t++,U+=dl_sur_2) { | |
324 | aPnt3d1 = aline->Value(U); | |
325 | aL+=Pnt3d.Distance(aPnt3d1); | |
326 | Pnt3d=aPnt3d1; | |
327 | } | |
328 | //------------------------------------------------------ | |
329 | aL/=t; | |
330 | aL*=2; | |
331 | //------------------------------------------------------ | |
332 | //-- Calcul du premier point | |
333 | //-- | |
334 | //------------------------------------------------------ | |
335 | //-- On reajuste firstparam et lastparam au cas ou ces | |
336 | //-- valeurs sont tres proches des parametres de vertex | |
337 | if(nbvtx) { | |
338 | Standard_Real pvtxmin, pvtxmax; | |
339 | // | |
340 | pvtxmin = aline->Vertex(1).ParameterOnLine(); | |
341 | pvtxmax = pvtxmin; | |
342 | // | |
343 | for(v=2; v<=nbvtx; v++) { | |
344 | pv=aline->Vertex(v).ParameterOnLine(); | |
345 | if(pvtxmin>pv){ | |
346 | pvtxmin = pv; | |
347 | } | |
348 | if(pvtxmax<pv){ | |
349 | pvtxmax =pv; | |
350 | } | |
351 | } | |
352 | if(Abs(pvtxmin-firstparam)<myTolOpenDomain) { | |
353 | firstparam=pvtxmin; | |
354 | } | |
355 | if(Abs(pvtxmax-lastparam)<myTolOpenDomain) { | |
356 | lastparam=pvtxmax; | |
357 | } | |
358 | } | |
359 | // | |
360 | // First Point | |
361 | Pnt3d = aline->Value(firstparam); | |
362 | quad1.Parameters(Pnt3d,u1,v1); | |
363 | // | |
364 | RefineParameters(aline, firstparam, lastparam, firstparam, 1, quad1, 10.*myTol3D, u1,v1); | |
365 | // | |
366 | // | |
367 | quad2.Parameters(Pnt3d,u2,v2); | |
368 | // | |
369 | RefineParameters(aline, firstparam, lastparam, firstparam, 1, quad2, 10.*myTol3D, u2,v2); | |
370 | // | |
371 | ||
372 | POn2S.SetValue(Pnt3d,u1,v1,u2,v2); | |
373 | anu1 = u1; | |
374 | anu2 = u2; | |
375 | LinOn2S->Add(POn2S); | |
376 | nbpwline = 1; | |
377 | U = firstparam; | |
378 | //------------------------------------------------------- | |
379 | //-- On detecte le cas : Point de debut == vertex | |
380 | //-- On affecte un parametre bidon qui sera recadre | |
381 | //-- dans l insertion des vertex dans la ligne | |
382 | //-- | |
383 | for(v=1;v<=nbvtx;v++) { | |
384 | if(newparamvertex(v)<0.) { | |
385 | pv=paramvertex(v); | |
386 | if((pv>=U-2.0*myTolOpenDomain) && (pv<=U+2.0*myTolOpenDomain)) { | |
387 | if(pv-U > myTolParam) { | |
388 | newparamvertex(v) = 1.000001; | |
389 | } | |
390 | else if(U-pv>myTolParam) { | |
391 | newparamvertex(v) = 0.999999; | |
392 | } | |
393 | } | |
394 | } | |
395 | } | |
396 | // | |
397 | Standard_Real DeltaU; | |
398 | // | |
399 | // the loop | |
400 | DeltaU=0.; | |
401 | //// Modified by jgv, 17.09.09 for OCC21255 //// | |
402 | Standard_Boolean Corrected = Standard_False; | |
403 | //////////////////////////////////////////////// | |
404 | while(U<lastparam) { | |
405 | Standard_Integer NbCalculD1; | |
406 | Standard_Real UPourCalculD1, pvavant, pvapres; | |
407 | gp_Vec VPourCalculD1; | |
408 | gp_Pnt PPourCalculD1; | |
409 | // | |
410 | DeltaU=0.; | |
411 | NbCalculD1=0; | |
412 | UPourCalculD1=U; | |
413 | do { | |
414 | if(aline->D1(UPourCalculD1,PPourCalculD1,VPourCalculD1)) { | |
415 | Standard_Real NormV = VPourCalculD1.Magnitude(); | |
416 | if(NormV > 1.0e-16) { | |
417 | DeltaU = aL/NormV; | |
418 | } | |
419 | } | |
420 | if(DeltaU < dumin) | |
421 | DeltaU = dumin; | |
422 | else if (DeltaU > dumax) | |
423 | DeltaU = dumax; | |
424 | UPourCalculD1+=dumin; | |
425 | } | |
426 | while((++NbCalculD1<10)&&(DeltaU==0.)); | |
427 | // | |
428 | //OCC541(apo)-> | |
429 | // static //xft | |
430 | Standard_Real CurvDef = deflectionmax, AngDef = CurvDef; | |
431 | if(U+DeltaU < lastparam) { | |
432 | DefineDU(aline,U,DeltaU,CurvDef,AngDef); | |
433 | } | |
434 | //<-OCC451(apo) | |
435 | // | |
436 | if(DeltaU==0.){ | |
437 | DeltaU = (dumin+dumax)*0.5; | |
438 | } | |
439 | //-------------------------------------------------------- | |
440 | //-- On cherche a placer un minimum de ??? Points entre | |
441 | //-- 2 vertex | |
442 | //-------------------------------------------------------- | |
443 | pvavant = firstparam; | |
444 | pvapres = lastparam; | |
445 | for(v=1;v<=nbvtx;v++) { | |
446 | pv=paramvertex(v); | |
447 | if(pv-U > myTolParam) { | |
448 | if(pvapres>pv) { | |
449 | pvapres = pv; | |
450 | } | |
451 | } | |
452 | else { | |
453 | if(U-pv > myTolParam) { | |
454 | if(pvavant<pv) { | |
455 | pvavant = pv; | |
456 | } | |
457 | } | |
458 | } | |
459 | } | |
460 | pvapres-=pvavant; | |
461 | if(pvapres < (10.*DeltaU)) { | |
462 | if(pvapres > (10.*dumin)) { | |
463 | DeltaU = pvapres*0.1; | |
464 | } | |
465 | else { | |
466 | DeltaU = dumin; | |
467 | } | |
468 | } | |
469 | //xf | |
470 | if (nbpwline==1 && nbvtx) { | |
471 | Standard_Real aUnext; | |
472 | // | |
473 | aUnext=U+DeltaU; | |
474 | pv=paramvertex(1); | |
475 | if (aUnext>pv){ | |
476 | DeltaU=0.5*(pv-firstparam); | |
477 | } | |
478 | } | |
479 | //xt | |
480 | //-------------------------------------------------------- | |
481 | //-- Calcul des nouveaux parametres sur les vertex | |
482 | //-- | |
483 | for(v=1;v<=nbvtx;v++) { | |
484 | if(newparamvertex(v)<0.) { | |
485 | pv=paramvertex(v); | |
486 | if(pv>=U && pv<(U+DeltaU) && (U+DeltaU<lastparam) ) { | |
487 | newparamvertex(v) = (Standard_Real)nbpwline + (pv-U)/DeltaU; | |
488 | } | |
489 | } | |
490 | } | |
491 | ||
492 | //// Modified by jgv, 17.09.09 for OCC21255 //// | |
493 | if (!Corrected && U >= refpar) | |
494 | { | |
495 | CorrectFirstPartOfLine(LinOn2S, quad1, quad2, ref_u1, ref_u2, anu1, anu2); | |
496 | Corrected = Standard_True; | |
497 | } | |
498 | //////////////////////////////////////////////// | |
499 | U+=DeltaU; | |
500 | if(U < lastparam) { | |
501 | nbpwline++; | |
502 | Pnt3d = aline->Value(U); | |
503 | quad1.Parameters(Pnt3d,u1,v1); | |
504 | quad2.Parameters(Pnt3d,u2,v2); | |
505 | RecadreMemePeriode(quad1, quad2, u1,u2,anu1,anu2); | |
506 | anu1 = u1; | |
507 | anu2 = u2; | |
508 | POn2S.SetValue(Pnt3d,u1,v1,u2,v2); | |
509 | LinOn2S->Add(POn2S); | |
510 | } | |
511 | }//while(U<lastparam) | |
512 | ||
513 | U-=DeltaU; | |
514 | for(v=1;v<=nbvtx;v++) { | |
515 | if(newparamvertex(v)<0.) { | |
516 | pv=paramvertex(v); | |
517 | if(pv <= lastparam+myTolOpenDomain) { | |
518 | if(lastparam-U) { | |
519 | newparamvertex(v) = (Standard_Real)nbpwline+(pv-U)/(lastparam-U); | |
520 | } | |
521 | else { | |
522 | newparamvertex(v) = nbpwline+1; | |
523 | } | |
524 | } | |
525 | } | |
526 | } | |
527 | // | |
528 | Pnt3d = aline->Value(lastparam); | |
529 | quad1.Parameters(Pnt3d,u1,v1); | |
530 | // | |
531 | RefineParameters(aline, firstparam, lastparam, lastparam, -1, quad1, 10.*myTol3D, u1,v1); | |
532 | // | |
533 | quad2.Parameters(Pnt3d,u2,v2); | |
534 | // | |
535 | RefineParameters(aline, firstparam, lastparam, lastparam, -1, quad2, 10.*myTol3D, u2,v2); | |
536 | // | |
537 | RecadreMemePeriode(quad1, quad2, u1,u2,anu1,anu2); | |
538 | POn2S.SetValue(Pnt3d,u1,v1,u2,v2); | |
539 | LinOn2S->Add(POn2S); | |
540 | nbpwline++; | |
541 | ||
542 | //// Modified by jgv, 17.09.09 for OCC21255 //// | |
543 | if (!Corrected && | |
544 | (lastparam >= refpar || refpar-lastparam < Precision::Confusion())) | |
545 | CorrectFirstPartOfLine(LinOn2S, quad1, quad2, ref_u1, ref_u2, anu1, anu2); | |
546 | //////////////////////////////////////////////// | |
547 | ||
548 | // | |
549 | //----------------------------------------------------------------- | |
550 | //-- Calcul de la transition de la ligne sur les surfaces --- | |
551 | //----------------------------------------------------------------- | |
552 | IntSurf_TypeTrans trans1,trans2; | |
553 | Standard_Integer indice1; | |
554 | Standard_Real dotcross; | |
555 | gp_Pnt aPP0, aPP1; | |
556 | // | |
557 | trans1=IntSurf_Undecided; | |
558 | trans2=IntSurf_Undecided; | |
559 | // | |
560 | indice1 = nbpwline/3; | |
561 | if(indice1<=2) { | |
562 | indice1 = 2; | |
563 | } | |
564 | // | |
565 | aPP1=LinOn2S->Value(indice1).Value(); | |
566 | aPP0=LinOn2S->Value(indice1-1).Value(); | |
567 | // | |
568 | gp_Vec tgvalid(aPP0, aPP1); | |
569 | gp_Vec aNQ1=quad1.Normale(aPP0); | |
570 | gp_Vec aNQ2=quad2.Normale(aPP0); | |
571 | // | |
572 | dotcross = tgvalid.DotCross(aNQ2, aNQ1); | |
573 | if (dotcross > myTolTransition) { | |
574 | trans1 = IntSurf_Out; | |
575 | trans2 = IntSurf_In; | |
576 | } | |
577 | else if(dotcross < -myTolTransition) { | |
578 | trans1 = IntSurf_In; | |
579 | trans2 = IntSurf_Out; | |
580 | } | |
581 | //----------------------------------------------------------------- | |
582 | //-- C r e a t i o n d e la W L i n e --- | |
583 | //----------------------------------------------------------------- | |
584 | Handle(IntPatch_WLine) wline; | |
585 | // | |
586 | if(aline->TransitionOnS1() == IntSurf_Touch) { | |
587 | Handle(IntPatch_WLine) wlinetemp = new IntPatch_WLine(LinOn2S, | |
588 | aline->IsTangent(), | |
589 | aline->SituationS1(), | |
590 | aline->SituationS2()); | |
591 | wline = wlinetemp; | |
592 | } | |
593 | if(aline->TransitionOnS1() == IntSurf_Undecided) { | |
594 | Handle(IntPatch_WLine) wlinetemp = new IntPatch_WLine(LinOn2S, | |
595 | aline->IsTangent()); | |
596 | wline = wlinetemp; | |
597 | } | |
598 | else { | |
599 | Handle(IntPatch_WLine) wlinetemp = new IntPatch_WLine(LinOn2S, | |
600 | aline->IsTangent(), | |
601 | trans1, // aline->TransitionOnS1(), | |
602 | trans2); //aline->TransitionOnS2()); | |
603 | wline = wlinetemp; | |
604 | } | |
605 | ||
606 | //----------------------------------------------------------------- | |
607 | //-- I n s e r t i o n d e s v e r t e x --- | |
608 | //----------------------------------------------------------------- | |
609 | TColStd_Array1OfInteger Redir(1,Max(nbvtx,1)); | |
610 | // | |
611 | for(v=1;v<=nbvtx;v++) { | |
612 | Redir(v) = v; | |
613 | } | |
614 | // | |
615 | TriOk=Standard_True; | |
616 | Standard_Integer tamp; | |
617 | do { | |
618 | TriOk = Standard_True; | |
619 | for(v=2; v<=nbvtx;v++) { | |
620 | if(newparamvertex(Redir(v))<newparamvertex(Redir(v-1))) { | |
621 | tamp = Redir(v-1); | |
622 | Redir(v-1) = Redir(v); | |
623 | Redir(v) = tamp; | |
624 | TriOk = Standard_False; | |
625 | } | |
626 | } | |
627 | } | |
628 | while(!TriOk); | |
629 | ||
630 | //----------------------------------------------------------------- | |
631 | //-- On detecte le cas ou un Vtx de param 1 ou nbpwline OnArc est double | |
632 | //-- Dans ce cas on supprime le vertex qui reference un arc deja reference | |
633 | //-- par un autre vertex | |
634 | //nbvtx = aline->NbVertex(); | |
635 | Standard_Boolean APointHasBeenRemoved; | |
636 | // | |
637 | do { | |
638 | Standard_Boolean RemoveVtxo, RemoveVtx; | |
639 | Standard_Integer vo, voo; | |
640 | Standard_Real ponl, ponlo, ponloo, aDist13, aDist23; | |
641 | // | |
642 | APointHasBeenRemoved = Standard_False; | |
643 | RemoveVtxo = Standard_False; | |
644 | RemoveVtx = Standard_False; | |
645 | // | |
646 | for(v=1; v<=nbvtx && !APointHasBeenRemoved; v++) { | |
647 | // | |
648 | if(newparamvertex(v)>=0.) { | |
649 | const IntPatch_Point& Vtx = aline->Vertex(v); | |
650 | ponl = Vtx.ParameterOnLine(); | |
651 | const gp_Pnt& aP=Vtx.Value(); | |
652 | // | |
653 | for(vo=1; vo<=nbvtx && !APointHasBeenRemoved; vo++) { | |
654 | if(v!=vo) { | |
655 | if(newparamvertex(vo)>=0.) { | |
656 | const IntPatch_Point& Vtxo = aline->Vertex(vo); | |
657 | ponlo = Vtxo.ParameterOnLine(); | |
658 | const gp_Pnt& aPo=Vtxo.Value(); | |
659 | // | |
660 | if(ponl-ponlo<myTolParam && ponlo-ponl<myTolParam) { | |
661 | // | |
662 | for(voo=1; voo<=nbvtx && !APointHasBeenRemoved; voo++) { | |
663 | if(voo!=v && voo!=vo) { | |
664 | if(newparamvertex(voo)>=0.) { | |
665 | const IntPatch_Point& Vtxoo = aline->Vertex(voo); | |
666 | ponloo = Vtxoo.ParameterOnLine(); | |
667 | const gp_Pnt& aPoo=Vtxoo.Value(); | |
668 | // | |
669 | aDist13=aP.Distance(aPoo); | |
670 | // | |
671 | if(aDist13<=myTol3D) { | |
672 | //-- 2 vertex de meme param + un confondu geometriquement | |
673 | if((Vtx.IsOnDomS1() == Vtxoo.IsOnDomS1()) && | |
674 | (Vtx.IsOnDomS2() == Vtxoo.IsOnDomS2()) ) { | |
675 | ||
676 | if(Vtx.IsOnDomS1()) { | |
677 | if(Vtx.ParameterOnArc1()==Vtxoo.ParameterOnArc1()) { | |
678 | if(SameCurve(Vtxoo.ArcOnS1(),Vtx.ArcOnS1())) { //-- param on s1 ? | |
679 | RemoveVtx = Standard_True; | |
680 | } | |
681 | } | |
682 | } | |
683 | if(Vtx.IsOnDomS2()) { | |
684 | if(Vtx.ParameterOnArc2()==Vtxoo.ParameterOnArc2()) { | |
685 | if(SameCurve(Vtxoo.ArcOnS2(),Vtx.ArcOnS2())) { | |
686 | RemoveVtx = Standard_True; | |
687 | } | |
688 | } | |
689 | else { | |
690 | RemoveVtx = Standard_False; | |
691 | } | |
692 | } | |
693 | } | |
694 | // | |
695 | if(RemoveVtx==Standard_False) { | |
696 | // | |
697 | aDist23=aPo.Distance(aPoo); | |
698 | // | |
699 | if(aDist23<=myTol3D) { | |
700 | //-- 2 vertex de meme param + un confondu geometriquement | |
701 | if((Vtxo.IsOnDomS1() == Vtxoo.IsOnDomS1())&& | |
702 | (Vtxo.IsOnDomS2() == Vtxoo.IsOnDomS2()) ) { | |
703 | if(Vtxo.IsOnDomS1()) { | |
704 | if(Vtxo.ParameterOnArc1()==Vtxoo.ParameterOnArc1()) { | |
705 | if(SameCurve(Vtxoo.ArcOnS1(),Vtxo.ArcOnS1())) { //-- param on s1 ? | |
706 | RemoveVtxo = Standard_True; | |
707 | } | |
708 | } | |
709 | } | |
710 | if(Vtxo.IsOnDomS2()) { | |
711 | if(Vtxo.ParameterOnArc2()==Vtxoo.ParameterOnArc2()) { | |
712 | if(SameCurve(Vtxoo.ArcOnS2(),Vtxo.ArcOnS2())) { | |
713 | RemoveVtxo = Standard_True; | |
714 | } | |
715 | } | |
716 | else { | |
717 | RemoveVtxo = Standard_False; | |
718 | } | |
719 | } | |
720 | } | |
721 | } | |
722 | } //-- | |
723 | if(RemoveVtx) { | |
724 | newparamvertex(v) = -1.; | |
725 | APointHasBeenRemoved = Standard_True; | |
726 | } | |
727 | else if(RemoveVtxo) { | |
728 | newparamvertex(vo) = -1.; | |
729 | APointHasBeenRemoved = Standard_True; | |
730 | } | |
731 | } //-- Pnt = Pntoo | |
732 | } //-- voo!=v && voo!=vo | |
733 | } //-- Fin boucle sur voo | |
734 | } | |
735 | } | |
736 | } | |
737 | } | |
738 | } | |
739 | } | |
740 | }//for(v=1; v<=nbvtx && !APointHasBeenRemoved; v++) | |
741 | } | |
742 | while(APointHasBeenRemoved); | |
743 | // | |
744 | Standard_Integer ParamVtxPrecedent, refpointonwline, aIndV; | |
745 | Standard_Real pvtx, approxparamonwline, aDst; | |
746 | Standard_Boolean bIsApex1, bIsApex2; | |
747 | // | |
748 | ParamVtxPrecedent = 0; | |
749 | // | |
750 | for(v=1; v<=nbvtx; v++) { | |
751 | aIndV=Redir(v); | |
752 | pv=paramvertex(v);// parameter from ALine | |
753 | pvtx = newparamvertex(aIndV); | |
754 | if(pvtx>=0. && (pvtx <= nbpwline+1)) { | |
755 | approxparamonwline=newparamvertex(aIndV); | |
756 | refpointonwline=1; | |
757 | // | |
758 | IntPatch_Point NewPoint = aline->Vertex(aIndV); | |
759 | // | |
760 | Pnt3d = NewPoint.Value(); | |
761 | quad1.Parameters(Pnt3d, u1, v1); | |
762 | quad2.Parameters(Pnt3d, u2, v2); | |
763 | //------------------------------------------------------- | |
764 | //-- On recadre les parametres des vertex dans la bonne - | |
765 | //-- periode en recadrant avec le point le plus proche - | |
766 | //------------------------------------------------------- | |
767 | if(approxparamonwline > nbpwline) { | |
768 | refpointonwline = nbpwline-1; | |
769 | } | |
770 | else if(approxparamonwline < 1) { | |
771 | refpointonwline = 1; | |
772 | } | |
773 | else { | |
774 | refpointonwline = (Standard_Integer)approxparamonwline; | |
775 | } | |
776 | // | |
777 | // | |
778 | const IntSurf_PntOn2S& aP2Sx=LinOn2S->Value(refpointonwline); | |
779 | aP2Sx.ParametersOnS1(anu1, anv1); | |
780 | aP2Sx.ParametersOnS2(anu2, anv2); | |
781 | // | |
782 | bIsApex1=IsApex(quad1, v1, myTol3D); | |
783 | bIsApex2=IsApex(quad2, v2, myTol3D); | |
784 | // | |
785 | //if (refpointonwline==1 || refpointonwline==nbpwline) { | |
786 | if (bIsApex1 || bIsApex2) { | |
787 | if (fabs(pv-firstparam)<myTolParam || fabs(pv-lastparam)<myTolParam) { | |
788 | // aline starts(ends) on vertex | |
789 | const gp_Pnt& aP1x=aP2Sx.Value(); | |
790 | // | |
791 | aDst=aP1x.Distance(Pnt3d); | |
792 | if (aDst<10.*myTol3D) { | |
793 | u1=anu1; | |
794 | v1=anv1; | |
795 | u2=anu2; | |
796 | v2=anv2; | |
797 | } | |
798 | } | |
799 | // | |
800 | else { | |
801 | // aline goes through vertex | |
802 | if (bIsApex1) { | |
803 | u1=0.; | |
804 | } | |
805 | if (bIsApex2) { | |
806 | u2=0.; | |
807 | } | |
808 | } | |
809 | } | |
810 | // | |
811 | // | |
812 | if(v==1) { | |
813 | ParamVtxPrecedent=refpointonwline; | |
814 | RecadreMemePeriode(quad1, quad2, u1,u2,anu1,anu2); | |
815 | NewPoint.SetParameter(refpointonwline); | |
816 | // | |
817 | NewPoint.SetParameters(u1,v1,u2,v2); | |
818 | wline->AddVertex(NewPoint); | |
819 | } | |
820 | // | |
821 | else { | |
822 | if(ParamVtxPrecedent==refpointonwline) { | |
823 | //-- 2 vertex renseignent le meme point de la LineOn2S | |
824 | //-- On insere un nv point = vtx | |
825 | //-- On decale tous les vtx apres de 1 | |
826 | RecadreMemePeriode(quad1, quad2, u1,u2,anu1,anu2); | |
827 | POn2S.SetValue(Pnt3d,u1,v1,u2,v2); | |
828 | LinOn2S->InsertBefore(refpointonwline+1, POn2S); | |
829 | nbpwline++; | |
830 | NewPoint.SetParameter(refpointonwline+1); | |
831 | NewPoint.SetParameters(u1,v1,u2,v2); | |
832 | wline->AddVertex(NewPoint); | |
833 | ParamVtxPrecedent = refpointonwline+1; | |
834 | // | |
835 | Standard_Integer vv=v+1; | |
836 | for(; vv<=nbvtx; vv++) { | |
837 | if(newparamvertex(Redir(vv))!=-1.) { | |
838 | newparamvertex(Redir(vv))=newparamvertex(Redir(vv))+1.; | |
839 | } | |
840 | } | |
841 | } | |
842 | // | |
843 | else { | |
844 | RecadreMemePeriode(quad1, quad2, u1,u2, anu1, anu2); | |
845 | NewPoint.SetParameter(refpointonwline); | |
846 | // | |
847 | NewPoint.SetParameters(u1, v1, u2, v2); | |
848 | wline->AddVertex(NewPoint); | |
849 | ParamVtxPrecedent = refpointonwline; | |
850 | } | |
851 | } | |
852 | } | |
853 | } | |
854 | // | |
855 | pu1=0.; | |
856 | pv1=0.; | |
857 | pu2=0.; | |
858 | pv2=0.; | |
859 | // | |
860 | switch(quad1.TypeQuadric()) { | |
861 | case GeomAbs_Cylinder: | |
862 | case GeomAbs_Cone: | |
863 | case GeomAbs_Sphere: | |
c6541a0c | 864 | pu1=M_PI+M_PI; |
7fd59977 | 865 | break; |
866 | default: | |
867 | break; | |
868 | } | |
869 | switch(quad2.TypeQuadric()) { | |
870 | case GeomAbs_Cylinder: | |
871 | case GeomAbs_Cone: | |
872 | case GeomAbs_Sphere: | |
c6541a0c | 873 | pu2=M_PI+M_PI; |
7fd59977 | 874 | break; |
875 | default: | |
876 | break; | |
877 | } | |
878 | wline->SetPeriod(pu1,pv1,pu2,pv2); | |
879 | ||
880 | wline->ComputeVertexParameters(myTol3D); | |
881 | return(wline); | |
882 | } | |
883 | //======================================================================= | |
884 | //function : DefineDU | |
885 | //purpose : | |
886 | //======================================================================= | |
887 | gp_Pnt DefineDU(const Handle(IntPatch_ALine)& aline, | |
888 | const Standard_Real U, | |
889 | Standard_Real& DU, | |
890 | const Standard_Real CurvDef, | |
891 | const Standard_Real AngDef) | |
892 | { | |
893 | gp_Pnt P1 = aline->Value(U), P2, P3; | |
894 | gp_Vec V13, V12, V23; | |
895 | Standard_Real dU = DU/2.0, curvDef, angDef, m1, m2, m3; | |
302f96fb | 896 | for(;;) { //According to class TangentialDeflection from GCPnts |
7fd59977 | 897 | P2=aline->Value(U+dU); P3=aline->Value(U+DU); |
898 | V13 = P3.XYZ().Subtracted(P1.XYZ()); m1 = V13.Magnitude(); | |
899 | V12 = P2.XYZ().Subtracted(P1.XYZ()); m2 = V12.Magnitude(); | |
900 | V23 = P3.XYZ().Subtracted(P2.XYZ()); m3 = V23.Magnitude(); | |
901 | if(m1 < CurvDef || m2 < CurvDef || m3 < CurvDef) break; | |
902 | curvDef = Abs(V13.Angle(V12)); | |
903 | angDef = Abs(V13.Angle(V23)); | |
904 | if(curvDef < CurvDef && angDef < AngDef) break; | |
905 | DU = dU; dU /= 2.0; | |
302f96fb | 906 | } |
7fd59977 | 907 | return P3; |
908 | } | |
909 | //======================================================================= | |
910 | //function : SameCurve | |
911 | //purpose : | |
912 | //======================================================================= | |
913 | Standard_Boolean SameCurve(const Handle_Adaptor2d_HCurve2d& C1,const Handle_Adaptor2d_HCurve2d& C2) | |
914 | { | |
915 | Standard_Real C1f = C1->FirstParameter(); | |
916 | Standard_Real C2f = C2->FirstParameter(); | |
917 | if(C1f!=C2f) return(Standard_False); | |
918 | Standard_Real C1l = C1->LastParameter(); | |
919 | Standard_Real C2l = C2->LastParameter(); | |
920 | if(C1l!=C2l) return(Standard_False); | |
921 | Standard_Real u=0.3*C1f+0.7*C1l; | |
922 | gp_Pnt2d P1 = C1->Value(u); | |
923 | gp_Pnt2d P2 = C2->Value(u); | |
924 | if(P1.X()!=P2.X()) return(Standard_False); | |
925 | if(P1.Y()!=P2.Y()) return(Standard_False); | |
926 | return(Standard_True); | |
927 | } | |
928 | //======================================================================= | |
929 | //function : RecadreMemePeriode | |
930 | //purpose : | |
931 | //======================================================================= | |
932 | void RecadreMemePeriode(const IntSurf_Quadric aQuad1, | |
933 | const IntSurf_Quadric aQuad2, | |
934 | Standard_Real& u1, | |
935 | Standard_Real& u2, | |
936 | const Standard_Real anu1, | |
937 | const Standard_Real anu2) | |
938 | { | |
939 | Standard_Boolean bBothCylinders; | |
940 | GeomAbs_SurfaceType aType1, aType2; | |
941 | // | |
942 | aType1=aQuad1.TypeQuadric(); | |
943 | aType2=aQuad2.TypeQuadric(); | |
944 | bBothCylinders=(aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder); | |
945 | // | |
946 | while(anu1-u1 > 5.0) { | |
c6541a0c | 947 | u1+=M_PI+M_PI; |
7fd59977 | 948 | } |
949 | while(u1-anu1 > 5.0) { | |
950 | // | |
951 | /* | |
952 | if (!bBothCylinders) {//cfe900/H6 | |
953 | // this check on Cylinder/Cylinder intersection is probably | |
954 | // because of pbs with ALine on it. | |
955 | // For other Quadrics there was no pbs found during | |
956 | // grid tests. | |
957 | // (it is necessary to see ...IntCyCy(...) for details). | |
958 | // | |
959 | // In any case the pb does not deal with apex problem. | |
960 | // | |
c6541a0c | 961 | if (u1-M_PI-M_PI<0.) { |
7fd59977 | 962 | break; |
963 | } | |
964 | } | |
965 | */ | |
966 | // | |
c6541a0c | 967 | u1-=M_PI+M_PI; |
7fd59977 | 968 | } |
969 | while(anu2-u2 > 5.0) { | |
c6541a0c | 970 | u2+=M_PI+M_PI; |
7fd59977 | 971 | } |
972 | while(u2-anu2 > 5.0) { | |
973 | // | |
974 | /* | |
975 | if (!bBothCylinders) {//cfe900/H6 | |
c6541a0c | 976 | if (u2-M_PI-M_PI<0.) { |
7fd59977 | 977 | break; |
978 | } | |
979 | } | |
980 | */ | |
981 | // | |
c6541a0c | 982 | u2-=M_PI+M_PI; |
7fd59977 | 983 | } |
984 | } | |
985 | ||
986 | //======================================================================= | |
987 | //function : CorrectFirstPartOfLine | |
988 | //purpose : | |
989 | //======================================================================= | |
990 | void CorrectFirstPartOfLine(Handle(IntSurf_LineOn2S)& LinOn2S, | |
991 | const IntSurf_Quadric aQuad1, | |
992 | const IntSurf_Quadric aQuad2, | |
993 | const Standard_Real ref_u1, | |
994 | const Standard_Real ref_u2, | |
995 | Standard_Real& new_u1, | |
996 | Standard_Real& new_u2) | |
997 | { | |
998 | Standard_Integer nbp = LinOn2S->NbPoints(); | |
999 | Standard_Real u1, v1, u2, v2, OffsetOnS1, OffsetOnS2; | |
1000 | ||
1001 | IntSurf_PntOn2S aPoint = LinOn2S->Value(nbp); | |
1002 | aPoint.Parameters(u1, v1, u2, v2); | |
1003 | ||
1004 | new_u1 = u1; | |
1005 | new_u2 = u2; | |
1006 | RecadreMemePeriode(aQuad1, aQuad2, new_u1, new_u2, ref_u1, ref_u2); | |
1007 | OffsetOnS1 = new_u1 - u1; | |
1008 | OffsetOnS2 = new_u2 - u2; | |
1009 | if (Abs(OffsetOnS1) > 1. || Abs(OffsetOnS2) > 1.) //recadre on n*2*PI is done | |
1010 | { | |
1011 | Standard_Integer i; | |
1012 | for (i = 1; i <= nbp; i++) | |
1013 | { | |
1014 | aPoint = LinOn2S->Value(i); | |
1015 | aPoint.Parameters(u1, v1, u2, v2); | |
1016 | LinOn2S->SetUV( i, Standard_True, u1 + OffsetOnS1, v1 ); | |
1017 | LinOn2S->SetUV( i, Standard_False, u2 + OffsetOnS2, v2 ); | |
1018 | } | |
1019 | } | |
1020 | } | |
1021 | ||
1022 | // | |
1023 | //======================================================================= | |
1024 | //function : IsApex | |
1025 | //purpose : | |
1026 | //======================================================================= | |
1027 | Standard_Boolean IsApex(const IntSurf_Quadric& aQuadric, | |
1028 | const Standard_Real aVx, | |
1029 | const Standard_Real aTol3D) | |
1030 | ||
1031 | { | |
1032 | Standard_Boolean bFlag; | |
1033 | Standard_Real aHalfPi, aEpsilon; | |
1034 | GeomAbs_SurfaceType aType; | |
1035 | // | |
1036 | bFlag=Standard_False; | |
1037 | // | |
1038 | aType=aQuadric.TypeQuadric(); | |
1039 | if (!(aType==GeomAbs_Cone || aType==GeomAbs_Sphere)) { | |
1040 | return bFlag; | |
1041 | } | |
1042 | // | |
1043 | aEpsilon=Epsilon(10.);//1.77e-15 | |
1044 | // | |
1045 | // apex on the Sphere | |
1046 | if(aType==GeomAbs_Sphere) { | |
c6541a0c | 1047 | aHalfPi=0.5*M_PI; |
7fd59977 | 1048 | if (fabs(aVx-aHalfPi)<aEpsilon) { |
1049 | bFlag=!bFlag; | |
1050 | } | |
1051 | else if (fabs(aVx+aHalfPi)<aEpsilon){ | |
1052 | bFlag=!bFlag; | |
1053 | } | |
1054 | } | |
1055 | // | |
1056 | // apex on the Cone | |
1057 | else if(aType==GeomAbs_Cone) { | |
1058 | Standard_Real aDst; | |
1059 | gp_Pnt aPap, aPx; | |
1060 | gp_Cone aCone; | |
1061 | // | |
1062 | aCone=aQuadric.Cone(); | |
1063 | aPap=aCone.Apex(); | |
1064 | aPx=aQuadric.Value(0.,aVx); | |
1065 | // | |
1066 | aDst=aPx.Distance(aPap); | |
1067 | if(aDst<aTol3D) { | |
1068 | bFlag=!bFlag; | |
1069 | } | |
1070 | } | |
1071 | return bFlag; | |
1072 | } | |
1073 | //======================================================================= | |
1074 | //function : RefineParameters | |
1075 | //purpose : | |
1076 | //======================================================================= | |
1077 | void RefineParameters(const Handle(IntPatch_ALine)& aALine, | |
1078 | const Standard_Real aTb, | |
1079 | const Standard_Real aTe, | |
1080 | const Standard_Real aTx, | |
1081 | const Standard_Integer iDir, | |
1082 | const IntSurf_Quadric& aQuadric, | |
1083 | const Standard_Real aTol3D, | |
1084 | Standard_Real& aUx, | |
1085 | Standard_Real& aVx) | |
1086 | { | |
1087 | GeomAbs_SurfaceType aType; | |
1088 | // | |
1089 | aType=aQuadric.TypeQuadric(); | |
1090 | if (!(aType==GeomAbs_Cone || aType==GeomAbs_Sphere)) { | |
1091 | return; | |
1092 | } | |
1093 | // | |
1094 | Standard_Boolean bIsDone, bIsEmpty, bParallel, bFound; | |
1095 | Standard_Integer aNbPoints; | |
1096 | Standard_Real aHalfPi, aEpsilon, aLimV, dT, aT1, aT2, aEpsT; | |
1097 | Standard_Real aU1, aV1, aU2, aV2; | |
1098 | gp_Pnt aP1, aP2, aPx; | |
1099 | gp_Pnt2d aP2D1, aP2D2, aPLim(0., 0.); | |
1100 | gp_Vec2d aVLim(1., 0.); | |
1101 | gp_Lin2d aLLim; | |
1102 | IntAna2d_AnaIntersection aAI; | |
1103 | // | |
1104 | aEpsilon=Epsilon(10.);//1.77e-15 | |
1105 | aEpsT=0.0001; | |
1106 | aLLim.SetDirection(aVLim); | |
1107 | // | |
1108 | // apex on the Cone | |
1109 | if(aType==GeomAbs_Cone) { | |
1110 | Standard_Real aDst; | |
1111 | gp_Pnt aPap; | |
1112 | gp_Cone aCone; | |
1113 | // | |
1114 | aCone=aQuadric.Cone(); | |
1115 | aPap=aCone.Apex(); | |
1116 | //aPx=aQuadric.Value(0.,aVx); | |
1117 | aPx=aALine->Value(aTx); | |
1118 | // | |
1119 | aDst=aPx.Distance(aPap); | |
1120 | if(aDst>aTol3D) {// nothing to do | |
1121 | return; | |
1122 | } | |
1123 | // | |
1124 | aPLim.SetY(aVx); | |
1125 | aLLim.SetLocation(aPLim); | |
1126 | // | |
1127 | } | |
1128 | // | |
1129 | // apex on the Sphere | |
1130 | if(aType==GeomAbs_Sphere) { | |
c6541a0c | 1131 | aHalfPi=0.5*M_PI; |
7fd59977 | 1132 | // |
1133 | if (fabs(aVx-aHalfPi)<aEpsilon) { | |
1134 | aLimV=aHalfPi; | |
1135 | } | |
1136 | else if (fabs(aVx+aHalfPi)<aEpsilon){ | |
1137 | aLimV=-aHalfPi; | |
1138 | } | |
1139 | else { | |
1140 | //Check: aUx must be 0 or 2*pi | |
c6541a0c | 1141 | if(fabs(aUx) < aEpsilon || fabs(aUx - 2.*M_PI) < aEpsilon) { |
7fd59977 | 1142 | //aUx = 0 or 2*pi, but may be it must be 2*pi or 0? |
1143 | bFound=FindNearParameter(aALine, aTx, iDir, aTol3D, aT1); | |
1144 | if(!bFound) { | |
1145 | dT=aEpsT*(aTe-aTb); | |
1146 | if (iDir<0) { | |
1147 | dT=-dT; | |
1148 | } | |
1149 | aT1=aTx+dT; | |
1150 | } | |
1151 | ||
1152 | aP1=aALine->Value(aT1); | |
1153 | aQuadric.Parameters(aP1, aU1, aV1); | |
1154 | ||
c6541a0c D |
1155 | if(fabs(aU1) > fabs(aU1 - 2.*M_PI)) { |
1156 | aUx = 2.*M_PI; | |
7fd59977 | 1157 | } |
1158 | else { | |
1159 | aUx = 0.; | |
1160 | } | |
1161 | } | |
1162 | ||
1163 | return; | |
1164 | } | |
1165 | // | |
1166 | aPLim.SetY(aLimV); | |
1167 | aLLim.SetLocation(aPLim); | |
1168 | } | |
1169 | // | |
1170 | // aT1, aT2 | |
1171 | // | |
1172 | // Try to find aT1, aT2 taking into acc 3D Tolerance | |
1173 | bFound=FindNearParameter(aALine, aTx, iDir, aTol3D, aT1); | |
1174 | if (bFound) { | |
1175 | bFound=FindNearParameter(aALine, aT1, iDir, aTol3D, aT2); | |
1176 | } | |
1177 | if (!bFound) { | |
1178 | // Assign aT1, aT2 by some values | |
1179 | dT=aEpsT*(aTe-aTb); | |
1180 | if (iDir<0) { | |
1181 | dT=-dT; | |
1182 | } | |
1183 | aT1=aTx+dT; | |
1184 | aT2=aT1+dT; | |
1185 | } | |
1186 | // | |
1187 | aP1=aALine->Value(aT1); | |
1188 | aQuadric.Parameters(aP1, aU1, aV1); | |
1189 | aP2D1.SetCoord(aU1, aV1); | |
1190 | // | |
1191 | aP2=aALine->Value(aT2); | |
1192 | aQuadric.Parameters(aP2, aU2, aV2); | |
1193 | aP2D2.SetCoord(aU2, aV2); | |
1194 | // | |
1195 | gp_Vec2d aV12(aP2D1, aP2D2); | |
1196 | ||
1197 | if(aV12.SquareMagnitude() <= aEpsilon) { | |
1198 | return; | |
1199 | } | |
1200 | gp_Lin2d aL12(aP2D1, aV12); | |
1201 | // | |
1202 | aAI.Perform(aLLim, aL12); | |
1203 | bIsDone=aAI.IsDone(); | |
1204 | if (!bIsDone) { | |
1205 | return; | |
1206 | } | |
1207 | bIsEmpty=aAI.IsEmpty(); | |
1208 | if (bIsEmpty) { | |
1209 | return; | |
1210 | } | |
1211 | aNbPoints=aAI.NbPoints(); | |
1212 | if (!aNbPoints) { | |
1213 | return; | |
1214 | } | |
1215 | bParallel=aAI.ParallelElements(); | |
1216 | if (bParallel) { | |
1217 | return; | |
1218 | } | |
1219 | const IntAna2d_IntPoint& aIAPnt=aAI.Point(1); | |
1220 | const gp_Pnt2d& aP2D=aIAPnt.Value(); | |
1221 | aUx=aP2D.X(); | |
1222 | } | |
1223 | //======================================================================= | |
1224 | //function : FindNearParameter | |
1225 | //purpose : | |
1226 | //======================================================================= | |
1227 | Standard_Boolean FindNearParameter(const Handle(IntPatch_ALine)& aALine, | |
1228 | const Standard_Real aTx, | |
1229 | const Standard_Integer iDir, | |
1230 | const Standard_Real aTol3D, | |
1231 | Standard_Real& aT1) | |
1232 | { | |
1233 | Standard_Boolean bFound; | |
1234 | Standard_Real aX, aY, aZ; | |
1235 | gp_Pnt aPx, aP1; | |
1236 | gp_Vec aVx; | |
1237 | // | |
1238 | aT1=0.; | |
1239 | // | |
1240 | bFound=aALine->D1(aTx, aPx, aVx); | |
1241 | if(!bFound){ | |
1242 | return bFound; | |
1243 | } | |
1244 | gp_Dir aDx(aVx); | |
1245 | if (iDir<0) { | |
1246 | aDx.Reverse(); | |
1247 | } | |
1248 | aX=aPx.X()+aDx.X()*aTol3D; | |
1249 | aY=aPx.Y()+aDx.Y()*aTol3D; | |
1250 | aZ=aPx.Z()+aDx.Z()*aTol3D; | |
1251 | aP1.SetCoord(aX, aY, aZ); | |
1252 | // | |
1253 | bFound=aALine->FindParameter(aP1, aT1); | |
1254 | // | |
1255 | return bFound; | |
1256 | } | |
1257 |