Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1992-05-07 |
2 | // Created by: Jacques GOUSSARD | |
3 | // Copyright (c) 1992-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 | // Modified by skv - Thu Jan 15 15:57:15 2004 OCC4455 | |
23 | ||
24 | static void PutPointsOnLine(const Handle(Adaptor3d_HSurface)& S1, | |
25 | const Handle(Adaptor3d_HSurface)& S2, | |
26 | const IntPatch_SequenceOfPathPointOfTheSOnBounds&, | |
27 | const IntPatch_SequenceOfLine&, | |
28 | const Standard_Boolean, | |
29 | const Handle(Adaptor3d_TopolTool)&, | |
30 | const IntSurf_Quadric&, | |
31 | const IntSurf_Quadric&, | |
32 | const Standard_Boolean, | |
33 | const Standard_Real); | |
34 | ||
35 | static Standard_Boolean MultiplePoint (const IntPatch_SequenceOfPathPointOfTheSOnBounds&, | |
36 | const Handle(Adaptor3d_TopolTool)&, | |
37 | const IntSurf_Quadric&, | |
38 | const gp_Vec&, | |
39 | const IntPatch_SequenceOfLine&, | |
40 | TColStd_Array1OfInteger&, | |
41 | TColStd_Array1OfInteger&, | |
42 | const Standard_Integer, | |
43 | const Standard_Boolean); | |
44 | ||
45 | static Standard_Boolean PointOnSecondDom (const IntPatch_SequenceOfPathPointOfTheSOnBounds&, | |
46 | const Handle(Adaptor3d_TopolTool)&, | |
47 | const IntSurf_Quadric&, | |
48 | const gp_Vec&, | |
49 | const gp_Vec&, | |
50 | const Handle(IntPatch_Line)&, | |
51 | TColStd_Array1OfInteger&, | |
52 | const Standard_Integer); | |
53 | ||
54 | static Standard_Boolean SingleLine (const gp_Pnt&, | |
55 | const Handle(IntPatch_Line)&, | |
56 | const Standard_Real, | |
57 | Standard_Real&, | |
58 | gp_Vec&); | |
59 | ||
60 | ||
61 | static Standard_Boolean FindLine (gp_Pnt&, | |
62 | const IntPatch_SequenceOfLine&, | |
63 | const Standard_Real, | |
64 | Standard_Real&, | |
65 | gp_Vec&, | |
66 | Standard_Integer&, | |
67 | Standard_Integer, | |
68 | const Handle(Adaptor2d_HCurve2d)&, | |
69 | Standard_Real&, | |
70 | gp_Pnt& pointonarc, | |
71 | const IntSurf_Quadric&); | |
72 | ||
73 | static void ProcessSegments (const IntPatch_SequenceOfSegmentOfTheSOnBounds&, | |
74 | IntPatch_SequenceOfLine&, | |
75 | const IntSurf_Quadric&, | |
76 | const IntSurf_Quadric&, | |
77 | const Standard_Boolean, | |
78 | const Standard_Real); | |
79 | ||
80 | static void ProcessRLine (IntPatch_SequenceOfLine&, | |
81 | #ifndef DEB | |
82 | const IntSurf_Quadric&, | |
83 | const IntSurf_Quadric&, | |
84 | #else | |
85 | const Handle(Adaptor3d_HSurface)&, | |
86 | const Handle(Adaptor3d_HSurface)&, | |
87 | #endif | |
88 | const Standard_Real); | |
89 | ||
90 | ||
91 | ||
92 | ||
93 | //-- le calcul de dist est completement faux ds la routine ci dessous a revoir (lbr le 18 nov 97) | |
94 | Standard_Boolean IntersectionWithAnArc(gp_Pnt& PSurf, | |
95 | const Handle(IntPatch_ALine)& alin, | |
96 | Standard_Real& para, | |
97 | const Handle(Adaptor2d_HCurve2d)& thearc, | |
98 | Standard_Real& _theparameteronarc, | |
99 | gp_Pnt& thepointonarc, | |
100 | const IntSurf_Quadric& QuadSurf, | |
101 | const Standard_Real u0alin, | |
102 | const Standard_Real u1alin, | |
103 | Standard_Real& actualdist) { | |
104 | Standard_Real dtheta,theta; | |
105 | #ifdef DEB | |
106 | //Standard_Real u,v,A,B,C,cost,sint,sign; | |
107 | #endif | |
108 | //-- recherche bete du point le plus proche de thearc->Value(...) | |
109 | dtheta = (u1alin-u0alin)*0.01; | |
110 | Standard_Real du=0.000000001; | |
111 | Standard_Real distmin = RealLast(); | |
1d47d8d0 | 112 | |
7fd59977 | 113 | Standard_Real thetamin = 0.; |
1d47d8d0 | 114 | |
7fd59977 | 115 | Standard_Real theparameteronarc = _theparameteronarc; |
116 | for(Standard_Real _theta=u0alin+dtheta; _theta<=u1alin-dtheta; _theta+=dtheta) { | |
117 | gp_Pnt P=alin->Value(_theta); | |
118 | Standard_Real d=P.Distance(PSurf); | |
119 | if(d<distmin) { | |
120 | thetamin=_theta; | |
121 | distmin=d; | |
122 | } | |
123 | } | |
1d47d8d0 | 124 | |
7fd59977 | 125 | Standard_Real bestpara =0., besttheta =0., bestdist =0., distinit =0. ; |
1d47d8d0 | 126 | |
7fd59977 | 127 | //-- Distance initiale |
128 | { | |
129 | gp_Pnt pp0 = alin->Value(thetamin); | |
130 | Standard_Real ua0,va0; | |
131 | QuadSurf.Parameters(pp0,ua0,va0); | |
132 | gp_Pnt2d p2d; | |
133 | gp_Vec2d d2d; | |
134 | thearc->D1(theparameteronarc,p2d,d2d); | |
135 | gp_Vec2d PaPr(gp_Pnt2d(ua0,va0),p2d); | |
136 | distinit=PaPr.Magnitude(); | |
137 | } | |
138 | theta = thetamin; | |
139 | //-- recherche a partir de theta et theparameteronarc | |
140 | Standard_Boolean cpasok=Standard_True; | |
141 | Standard_Integer nbiter=0; | |
142 | Standard_Real drmax = (thearc->LastParameter() - thearc->FirstParameter())*0.05; | |
143 | Standard_Real damax = (u1alin-u0alin)*0.05; | |
144 | ||
145 | ||
146 | ||
147 | bestdist = RealLast(); | |
148 | ||
149 | do { | |
150 | Standard_Real ua0,va0,ua1,va1; | |
151 | //-- alin->Curve().InternalUVValue(theta,ua0,va0,A,B,C,cost,sint,sign); | |
152 | //-- alin->Curve().InternalUVValue(theta+du,ua1,va1,A,B,C,cost,sint,sign); | |
153 | gp_Pnt pp0 = alin->Value(theta); | |
154 | gp_Pnt pp1 = alin->Value(theta+du); | |
155 | QuadSurf.Parameters(pp0,ua0,va0); | |
156 | QuadSurf.Parameters(pp1,ua1,va1); | |
157 | ||
158 | ||
159 | gp_Vec2d D1a((ua1-ua0)/du,(va1-va0)/du); | |
160 | gp_Pnt2d p2d; | |
161 | gp_Vec2d d2d; | |
162 | thearc->D1(theparameteronarc,p2d,d2d); | |
163 | gp_Vec2d PaPr(gp_Pnt2d(ua0,va0),p2d); | |
164 | ||
165 | Standard_Real pbd=PaPr.Magnitude(); | |
166 | if(bestdist>pbd) { | |
167 | bestdist = pbd; | |
168 | bestpara = theparameteronarc; | |
169 | besttheta = theta; | |
170 | } | |
171 | ||
172 | D1a.SetCoord(-D1a.X(),-D1a.Y()); | |
173 | ||
174 | Standard_Real d = D1a.X() * d2d.Y() - D1a.Y() * d2d.X(); | |
175 | ||
176 | Standard_Real da = (-PaPr.X())* d2d.Y() - (-PaPr.Y()) * d2d.X(); | |
177 | Standard_Real dr = D1a.X() * (-PaPr.Y()) - D1a.Y() * (-PaPr.X()); | |
178 | if(Abs(d)>1e-15) { | |
179 | da/=d; | |
180 | dr/=d; | |
181 | } | |
182 | else { | |
183 | if(Abs(PaPr.X())>Abs(PaPr.Y())) { | |
184 | Standard_Real xx=PaPr.X(); | |
185 | xx*=0.5; | |
186 | if(D1a.X()) { | |
187 | da = -xx/D1a.X(); | |
188 | } | |
189 | if(d2d.X()) { | |
190 | dr = -xx/d2d.X(); | |
191 | } | |
192 | } | |
193 | else { | |
194 | Standard_Real yy=PaPr.Y(); | |
195 | yy*=0.5; | |
196 | if(D1a.Y()) { | |
197 | da = -yy/D1a.Y(); | |
198 | } | |
199 | if(d2d.Y()) { | |
200 | dr = -yy/d2d.Y(); | |
201 | } | |
202 | } | |
203 | } | |
204 | //-- Standard_Real da = -PaPr.Dot(D1a); | |
205 | //-- Standard_Real dr = -PaPr.Dot(d2d); | |
206 | ||
207 | if(da<-damax) da=-damax; | |
208 | else if(da>damax) da=damax; | |
209 | if(dr<-drmax) dr=-drmax; | |
210 | else if(dr>drmax) dr=drmax; | |
211 | ||
212 | if(Abs(da)<1e-10 && Abs(dr)<1e-10) { | |
213 | para = theta; | |
214 | PSurf = alin->Value(para); | |
215 | _theparameteronarc=theparameteronarc; | |
216 | thepointonarc = alin->Value(para); | |
217 | cpasok=Standard_False; | |
218 | //-- printf("\nt:%d",nbiter); | |
219 | actualdist = bestdist; | |
220 | return(Standard_True); | |
221 | } | |
222 | else { | |
223 | theta+=da; | |
224 | theparameteronarc+=dr; | |
225 | if( theparameteronarc>thearc->LastParameter() ) { | |
226 | theparameteronarc = thearc->LastParameter(); | |
227 | } | |
228 | if( theparameteronarc<thearc->FirstParameter() ) { | |
229 | theparameteronarc = thearc->FirstParameter(); | |
230 | } | |
231 | if( theta < u0alin) { | |
232 | theta = u0alin; | |
233 | } | |
234 | if( theta > u1alin-du) { | |
235 | theta = u1alin-du-du; | |
236 | } | |
237 | } | |
238 | nbiter++; | |
239 | } | |
240 | while(cpasok && nbiter<20); | |
241 | if(bestdist < distinit) { | |
242 | para = besttheta; | |
243 | PSurf = alin->Value(para); | |
244 | _theparameteronarc=bestpara; | |
245 | thepointonarc = alin->Value(para); | |
246 | //-- printf("\nT:%d",nbiter); | |
247 | actualdist=bestdist; | |
248 | return(Standard_True); | |
249 | } | |
250 | //-- printf("\nF:%d",nbiter); | |
251 | return(Standard_False); | |
252 | } | |
253 | ||
254 | ||
255 | ||
256 | ||
257 | ||
258 | //-- ====================================================================== | |
259 | static void Recadre(const Handle(Adaptor3d_HSurface)& myHS1, | |
260 | const Handle(Adaptor3d_HSurface)& myHS2, | |
261 | Standard_Real& u1, | |
262 | Standard_Real& v1, | |
263 | Standard_Real& u2, | |
264 | Standard_Real& v2) { | |
265 | Standard_Real f,l,lmf,fpls2; | |
266 | GeomAbs_SurfaceType typs1 = myHS1->GetType(); | |
267 | GeomAbs_SurfaceType typs2 = myHS2->GetType(); | |
268 | ||
269 | Standard_Boolean myHS1IsUPeriodic,myHS1IsVPeriodic; | |
270 | switch (typs1) { | |
271 | case GeomAbs_Cylinder: | |
272 | case GeomAbs_Cone: | |
273 | case GeomAbs_Sphere: | |
274 | { | |
275 | myHS1IsUPeriodic = Standard_True; | |
276 | myHS1IsVPeriodic = Standard_False; | |
277 | break; | |
278 | } | |
279 | case GeomAbs_Torus: | |
280 | { | |
281 | myHS1IsUPeriodic = myHS1IsVPeriodic = Standard_True; | |
282 | break; | |
283 | } | |
284 | default: | |
285 | { | |
286 | //-- Le cas de biparametrees periodiques est gere en amont | |
287 | myHS1IsUPeriodic = myHS1IsVPeriodic = Standard_False; | |
288 | break; | |
289 | } | |
290 | } | |
291 | ||
292 | Standard_Boolean myHS2IsUPeriodic,myHS2IsVPeriodic; | |
293 | switch (typs2) { | |
294 | case GeomAbs_Cylinder: | |
295 | case GeomAbs_Cone: | |
296 | case GeomAbs_Sphere: | |
297 | { | |
298 | myHS2IsUPeriodic = Standard_True; | |
299 | myHS2IsVPeriodic = Standard_False; | |
300 | break; | |
301 | } | |
302 | case GeomAbs_Torus: | |
303 | { | |
304 | myHS2IsUPeriodic = myHS2IsVPeriodic = Standard_True; | |
305 | break; | |
306 | } | |
307 | default: | |
308 | { | |
309 | //-- Le cas de biparametrees periodiques est gere en amont | |
310 | myHS2IsUPeriodic = myHS2IsVPeriodic = Standard_False; | |
311 | break; | |
312 | } | |
313 | } | |
314 | if(myHS1IsUPeriodic) { | |
c6541a0c | 315 | lmf = M_PI+M_PI; //-- myHS1->UPeriod(); |
7fd59977 | 316 | f = myHS1->FirstUParameter(); |
317 | l = myHS1->LastUParameter(); | |
318 | fpls2=0.5*(f+l); | |
319 | while((u1 < f)&&((fpls2-u1) > (u1+lmf-fpls2) )) { u1+=lmf; } | |
320 | while((u1 > l)&&((u1-fpls2) > (fpls2-(u1-lmf)) )) { u1-=lmf; } | |
321 | ||
322 | } | |
323 | if(myHS1IsVPeriodic) { | |
c6541a0c | 324 | lmf = M_PI+M_PI; //-- myHS1->VPeriod(); |
7fd59977 | 325 | f = myHS1->FirstVParameter(); |
326 | l = myHS1->LastVParameter(); | |
327 | fpls2=0.5*(f+l); | |
328 | while((v1 < f)&&((fpls2-v1) > (v1+lmf-fpls2) )) { v1+=lmf; } | |
329 | while((v1 > l)&&((v1-fpls2) > (fpls2-(v1-lmf)) )) { v1-=lmf; } | |
330 | //-- while(v1 < f) { v1+=lmf; } | |
331 | //-- while(v1 > l) { v1-=lmf; } | |
332 | } | |
333 | if(myHS2IsUPeriodic) { | |
c6541a0c | 334 | lmf = M_PI+M_PI; //-- myHS2->UPeriod(); |
7fd59977 | 335 | f = myHS2->FirstUParameter(); |
336 | l = myHS2->LastUParameter(); | |
337 | fpls2=0.5*(f+l); | |
338 | while((u2 < f)&&((fpls2-u2) > (u2+lmf-fpls2) )) { u2+=lmf; } | |
339 | while((u2 > l)&&((u2-fpls2) > (fpls2-(u2-lmf)) )) { u2-=lmf; } | |
340 | //-- while(u2 < f) { u2+=lmf; } | |
341 | //-- while(u2 > l) { u2-=lmf; } | |
342 | } | |
343 | if(myHS2IsVPeriodic) { | |
c6541a0c | 344 | lmf = M_PI+M_PI; //-- myHS2->VPeriod(); |
7fd59977 | 345 | f = myHS2->FirstVParameter(); |
346 | l = myHS2->LastVParameter(); | |
347 | fpls2=0.5*(f+l); | |
348 | while((v2 < f)&&((fpls2-v2) > (v2+lmf-fpls2) )) { v2+=lmf; } | |
349 | while((v2 > l)&&((v2-fpls2) > (fpls2-(v2-lmf)) )) { v2-=lmf; } | |
350 | //-- while(v2 < f) { v2+=lmf; } | |
351 | //-- while(v2 > l) { v2-=lmf; } | |
352 | } | |
353 | } | |
354 | //======================================================================= | |
355 | //function : PutPointsOnLine | |
356 | //purpose : | |
357 | //======================================================================= | |
358 | void PutPointsOnLine(const Handle(Adaptor3d_HSurface)& S1, | |
359 | const Handle(Adaptor3d_HSurface)& S2, | |
360 | const IntPatch_SequenceOfPathPointOfTheSOnBounds& listpnt, | |
361 | const IntPatch_SequenceOfLine& slin, | |
362 | const Standard_Boolean OnFirst, | |
363 | const Handle(Adaptor3d_TopolTool)& Domain, | |
364 | const IntSurf_Quadric& QuadSurf, | |
365 | const IntSurf_Quadric& OtherQuad, | |
366 | const Standard_Boolean multpoint, | |
367 | const Standard_Real Tolarc) { | |
368 | ||
369 | // Traitement des point (de listpnt) de depart. On les replace sur | |
370 | // la ligne d intersection, en leur affectant la transition correcte sur | |
371 | // cette ligne. | |
372 | Standard_Integer nbpnt = listpnt.Length(); | |
373 | Standard_Integer nblin=slin.Length(); | |
374 | ||
375 | if (!slin.Length() || !nbpnt) { | |
376 | return; | |
377 | } | |
378 | // | |
379 | Standard_Integer i,k; | |
380 | Standard_Integer linenumber; | |
381 | Standard_Real paraint,currentparameter,tolerance; | |
382 | Standard_Real U1,V1,U2,V2; | |
383 | Standard_Boolean goon; | |
384 | ||
385 | ||
386 | gp_Pnt Psurf, ptbid; | |
387 | gp_Vec Normale, Vtgint, Vtgrst; | |
388 | ||
389 | gp_Vec d1u,d1v; | |
390 | gp_Pnt2d p2d; | |
391 | gp_Vec2d d2d; | |
392 | ||
393 | IntSurf_Transition Transline,Transarc; | |
394 | ||
395 | Handle(Adaptor2d_HCurve2d) currentarc; | |
396 | Handle(Adaptor3d_HVertex) vtx,vtxbis; | |
397 | ||
398 | IntPatch_Point solpnt; | |
399 | IntPatch_ThePathPointOfTheSOnBounds currentpointonrst; | |
400 | IntPatch_IType TheType; | |
401 | ||
402 | TColStd_Array1OfInteger UsedLine(1,nblin); | |
403 | TColStd_Array1OfInteger Done(1,nbpnt); | |
404 | for(i=1;i<=nbpnt;i++) Done(i) = 0; //-- Initialisation a la main | |
405 | ||
406 | for (i=1; i<=nbpnt; i++) { | |
407 | ||
408 | if (Done(i) != 1) { | |
409 | currentpointonrst = listpnt.Value(i); | |
410 | Psurf = currentpointonrst.Value(); // Point dans l espace | |
411 | tolerance = currentpointonrst.Tolerance(); | |
412 | ||
413 | // On recherche d abord si on a correspondance avec un "point multiple" | |
414 | UsedLine.Init(0); | |
415 | ||
416 | goon = Standard_True; | |
417 | if (multpoint) { | |
418 | #if 1 | |
419 | Normale = QuadSurf.Normale(Psurf); // Normale a la surface au point | |
420 | currentarc = currentpointonrst.Arc(); | |
421 | currentparameter = currentpointonrst.Parameter(); | |
422 | currentarc->D1(currentparameter,p2d,d2d); | |
423 | QuadSurf.D1(p2d.X(),p2d.Y(),ptbid,d1u,d1v); | |
424 | Vtgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
425 | #endif | |
426 | goon = MultiplePoint(listpnt,Domain,QuadSurf,Normale,slin,Done, UsedLine, | |
427 | i,OnFirst); | |
428 | } | |
429 | if (goon) { | |
430 | Standard_Boolean linefound; | |
431 | ||
432 | for(Standard_Integer indiceline = 1; indiceline <=slin.Length(); indiceline++) { | |
433 | if( UsedLine(indiceline) != 0 ) | |
434 | continue; | |
435 | linenumber = indiceline; | |
436 | ||
437 | //-- Attention , les points peuvent etre deplaces | |
438 | //-- il faut reprendre le point original | |
439 | currentpointonrst = listpnt.Value(i); | |
440 | currentarc = currentpointonrst.Arc(); | |
441 | currentparameter = currentpointonrst.Parameter(); | |
442 | Psurf = currentpointonrst.Value(); // Point dans l espace | |
443 | tolerance = currentpointonrst.Tolerance(); | |
444 | //-- | |
445 | ||
446 | ||
447 | // Modified by skv - Thu Jan 15 15:57:15 2004 OCC4455 Begin | |
448 | if (! currentpointonrst.IsNew()) { | |
449 | Handle(Adaptor3d_HVertex) aVtx = currentpointonrst.Vertex(); | |
450 | Standard_Real aVtxTol = aVtx->Resolution(currentarc); | |
451 | Standard_Real aTolAng = 0.01*tolerance; | |
452 | ||
453 | tolerance = Max(tolerance, aVtxTol); | |
454 | ||
455 | gp_Vec aNorm1 = QuadSurf.Normale(Psurf); | |
456 | gp_Vec aNorm2 = OtherQuad.Normale(Psurf); | |
457 | // | |
458 | if (aNorm1.Magnitude()>gp::Resolution() && | |
459 | aNorm2.Magnitude()>gp::Resolution()) { | |
460 | ||
461 | if (aNorm1.IsParallel(aNorm2, aTolAng)) | |
462 | tolerance = Sqrt(tolerance); | |
463 | }// | |
464 | } | |
465 | // Modified by skv - Thu Jan 15 15:57:15 2004 OCC4455 End | |
466 | gp_Pnt pointonarc; | |
467 | Vtgint.SetCoord(0,0,0); | |
468 | linefound = FindLine(Psurf,slin,tolerance,paraint,Vtgint,linenumber,indiceline, | |
469 | currentarc,currentparameter,pointonarc,QuadSurf); | |
470 | if (linefound) { | |
471 | ||
472 | #if 1 | |
473 | Normale = QuadSurf.Normale(Psurf); // Normale a la surface au point | |
474 | currentarc = currentpointonrst.Arc(); | |
475 | //-- currentparameter = currentpointonrst.Parameter(); | |
476 | currentarc->D1(currentparameter,p2d,d2d); | |
477 | QuadSurf.D1(p2d.X(),p2d.Y(),ptbid,d1u,d1v); | |
478 | Vtgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
479 | #endif | |
480 | ||
481 | ||
482 | ||
483 | const Handle(IntPatch_Line)& lin = slin.Value(linenumber); | |
484 | TheType = lin->ArcType(); | |
485 | ||
486 | if (!OnFirst) { // on cherche la correspondance entre point sur domaine | |
487 | // de la premiere surface et point sur domaine de la | |
488 | // deuxieme surface | |
489 | ||
490 | goon = PointOnSecondDom (listpnt, Domain, QuadSurf, Normale, | |
491 | Vtgint, lin, Done, i); | |
492 | } | |
493 | ||
494 | if (goon) { | |
495 | //-- Modification du 4 avril 97 tolerance->Tolarc | |
496 | //-- on replace sur le vertex la tolerance d entree et | |
497 | //-- non la tolerance qui a servi au FindLine | |
498 | solpnt.SetValue(Psurf,Tolarc,Standard_False); | |
499 | ||
500 | U1 = p2d.X(); V1 = p2d.Y(); | |
501 | OtherQuad.Parameters(Psurf,U2,V2); | |
502 | ||
503 | if (OnFirst) { | |
504 | Recadre(S1,S2,U1,V1,U2,V2); | |
505 | solpnt.SetParameters(U1,V1,U2,V2); | |
506 | } | |
507 | else { | |
508 | Recadre(S1,S2,U2,V2,U1,V1); | |
509 | solpnt.SetParameters(U2,V2,U1,V1); | |
510 | } | |
511 | solpnt.SetParameter(paraint); | |
512 | ||
513 | if (! currentpointonrst.IsNew()) { | |
514 | vtx = currentpointonrst.Vertex(); | |
515 | solpnt.SetVertex(OnFirst,vtx); | |
516 | } | |
517 | else { | |
518 | //-- goon = Standard_False; ???? | |
519 | } | |
520 | ||
521 | if(Normale.SquareMagnitude()<1e-16) { | |
522 | Transline.SetValue(Standard_True,IntSurf_Undecided); | |
523 | Transarc.SetValue(Standard_True,IntSurf_Undecided); | |
524 | } | |
525 | else { | |
526 | IntSurf::MakeTransition(Vtgint,Vtgrst,Normale,Transline,Transarc); | |
527 | } | |
528 | solpnt.SetArc(OnFirst,currentarc, currentparameter, | |
529 | Transline,Transarc); | |
530 | if (TheType == IntPatch_Analytic) { | |
531 | (*((Handle(IntPatch_ALine)*)&lin))->AddVertex(solpnt); | |
532 | } | |
533 | else { | |
534 | (*((Handle(IntPatch_GLine)*)&lin))->AddVertex(solpnt); | |
535 | } | |
536 | Done(i) = 1; | |
537 | ||
538 | if (goon) { | |
539 | for (k=i+1; k<= nbpnt; k++) { | |
540 | if (Done(k) != 1) { | |
541 | currentpointonrst = listpnt.Value(k); | |
542 | if (!currentpointonrst.IsNew()) { | |
543 | vtxbis = currentpointonrst.Vertex(); | |
544 | if(vtx.IsNull()) { | |
545 | } | |
546 | else if (Domain->Identical(vtx, vtxbis)) { | |
547 | solpnt.SetVertex(OnFirst,vtxbis); | |
548 | currentarc = currentpointonrst.Arc(); | |
549 | currentparameter = currentpointonrst.Parameter(); | |
550 | ||
551 | // currentarc->D1(currentparameter,ptbid,Vtgrst); | |
552 | currentarc->D1(currentparameter,p2d,d2d); | |
553 | Vtgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
554 | if(Normale.SquareMagnitude()<1e-16) { | |
555 | Transline.SetValue(Standard_True,IntSurf_Undecided); | |
556 | Transarc.SetValue(Standard_True,IntSurf_Undecided); | |
557 | } | |
558 | else { | |
559 | IntSurf::MakeTransition(Vtgint,Vtgrst,Normale, | |
560 | Transline,Transarc); | |
561 | } | |
562 | solpnt.SetArc(OnFirst,currentarc,currentparameter, | |
563 | Transline,Transarc); | |
564 | if (TheType == IntPatch_Analytic) { | |
565 | (*((Handle(IntPatch_ALine)*)&lin))->AddVertex(solpnt); | |
566 | } | |
567 | else { | |
568 | (*((Handle(IntPatch_GLine)*)&lin))->AddVertex(solpnt); | |
569 | } | |
570 | Done(k) = 1; | |
571 | } | |
572 | } | |
573 | } | |
574 | } | |
575 | } | |
576 | } | |
577 | } | |
578 | else { | |
579 | Done(i) = 1; // il faudra tester si IsNew ou pas | |
580 | // et traiter en consequence | |
581 | } | |
582 | } | |
583 | } | |
584 | } | |
585 | } | |
586 | } | |
587 | ||
588 | ||
589 | Standard_Boolean MultiplePoint (const IntPatch_SequenceOfPathPointOfTheSOnBounds& listpnt, | |
590 | const Handle(Adaptor3d_TopolTool)& Domain, | |
591 | const IntSurf_Quadric& QuadSurf, | |
592 | const gp_Vec& Normale, | |
593 | const IntPatch_SequenceOfLine& slin, | |
594 | TColStd_Array1OfInteger& Done, | |
595 | TColStd_Array1OfInteger& UsedLine, | |
596 | const Standard_Integer Index, | |
597 | const Standard_Boolean OnFirst) { | |
598 | ||
599 | // Traitement des points "multiples". | |
600 | ||
601 | ||
602 | Standard_Integer k,ii,jj,nbvtx; | |
603 | Standard_Integer nblin = slin.Length(); | |
604 | IntPatch_IType TheType; | |
605 | ||
606 | ||
607 | IntSurf_Transition Transline,Transarc; | |
608 | ||
609 | ||
610 | IntPatch_Point intpt; | |
611 | Handle(Adaptor2d_HCurve2d) currentarc; | |
612 | Handle(Adaptor3d_HVertex) vtx,vtxbis; | |
613 | ||
614 | Standard_Integer nbpnt = listpnt.Length(); | |
615 | IntPatch_ThePathPointOfTheSOnBounds currentpointonrst = listpnt.Value(Index); | |
616 | IntPatch_ThePathPointOfTheSOnBounds otherpt; | |
617 | gp_Pnt Point = currentpointonrst.Value(); | |
618 | TColStd_Array1OfInteger localdone(1,nbpnt); localdone.Init(0); | |
619 | for (ii=1; ii<=nbpnt; ii++) { | |
620 | localdone(ii)=Done(ii); | |
621 | } | |
622 | ||
623 | Standard_Real currentparameter; | |
624 | Standard_Real Paraint; | |
625 | gp_Vec Vtgint,Vtgrst; | |
626 | gp_Pnt ptbid; | |
627 | ||
628 | gp_Vec d1u,d1v; | |
629 | gp_Pnt2d p2d; | |
630 | gp_Vec2d d2d; | |
631 | ||
632 | Standard_Boolean goon; | |
633 | ||
634 | Standard_Boolean Retvalue = Standard_True; | |
635 | ||
636 | for (ii = 1; ii <= nblin; ii++) { | |
637 | const Handle(IntPatch_Line)& slinValueii = slin.Value(ii); | |
638 | TheType = slinValueii->ArcType(); | |
639 | if (TheType == IntPatch_Analytic) { | |
640 | nbvtx = (*((Handle(IntPatch_ALine)*)&slinValueii))->NbVertex(); | |
641 | } | |
642 | else { | |
643 | nbvtx = (*((Handle(IntPatch_GLine)*)&slinValueii))->NbVertex(); | |
644 | } | |
645 | jj = 1; | |
646 | while (jj <= nbvtx) { | |
647 | if (TheType == IntPatch_Analytic) { | |
648 | intpt = (*((Handle(IntPatch_ALine)*)&slinValueii))->Vertex(jj); | |
649 | } | |
650 | else { | |
651 | intpt = (*((Handle(IntPatch_GLine)*)&slinValueii))->Vertex(jj); | |
652 | } | |
653 | if (intpt.IsMultiple() && | |
654 | (( OnFirst && !intpt.IsOnDomS1()) || | |
655 | (!OnFirst && !intpt.IsOnDomS2()))) { | |
656 | if (Point.Distance(intpt.Value()) <= intpt.Tolerance()) { | |
657 | Retvalue = Standard_False; | |
658 | Standard_Boolean foo = SingleLine(Point,slinValueii, | |
659 | intpt.Tolerance(),Paraint,Vtgint); | |
660 | if (!foo) { | |
661 | return Standard_False; // ne doit pas se produire | |
662 | } | |
663 | ||
664 | if (!currentpointonrst.IsNew()) { | |
665 | goon = Standard_True; | |
666 | vtx = currentpointonrst.Vertex(); | |
667 | intpt.SetVertex(OnFirst,vtx); | |
668 | } | |
669 | else { | |
670 | goon = Standard_False; | |
671 | } | |
672 | currentarc = currentpointonrst.Arc(); | |
673 | currentparameter = currentpointonrst.Parameter(); | |
674 | currentarc->D1(currentparameter,p2d,d2d); | |
675 | QuadSurf.D1(p2d.X(),p2d.Y(),ptbid,d1u,d1v); | |
676 | Vtgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
677 | ||
678 | //-- Si la normale est nulle (apex d un cone) On simule une transition UNKNOWN | |
679 | if(Normale.SquareMagnitude()<1e-16) { | |
680 | Transline.SetValue(Standard_True,IntSurf_Undecided); | |
681 | Transarc.SetValue(Standard_True,IntSurf_Undecided); | |
682 | } | |
683 | else { | |
684 | IntSurf::MakeTransition(Vtgint,Vtgrst,Normale,Transline,Transarc); | |
685 | } | |
686 | ||
687 | //-- Avant, on ne mettait pas ce point (17 nov 97) | |
688 | //--printf("\n ImpImp_0 : Point(%g,%g,%g) intpt(%g,%g,%g) \n", | |
689 | //-- Point.X(),Point.Y(),Point.Z(),intpt.Value().X(),intpt.Value().Y(),intpt.Value().Z()); | |
690 | intpt.SetValue(Point); | |
691 | ||
692 | intpt.SetArc(OnFirst,currentarc,currentparameter, | |
693 | Transline,Transarc); | |
694 | ||
695 | ||
696 | if (TheType == IntPatch_Analytic) { | |
697 | (*((Handle(IntPatch_ALine)*)&slinValueii))->Replace(jj,intpt); | |
698 | } | |
699 | else { | |
700 | (*((Handle(IntPatch_GLine)*)&slinValueii))->Replace(jj,intpt); | |
701 | } | |
702 | localdone(Index) = 1; | |
703 | if (goon) { | |
704 | for (k=Index+1; k<= nbpnt; k++) { | |
705 | if (Done(k) != 1) { | |
706 | otherpt= listpnt.Value(k); | |
707 | if (!otherpt.IsNew()) { | |
708 | vtxbis = otherpt.Vertex(); | |
709 | if (Domain->Identical(vtx, vtxbis)) { | |
710 | intpt.SetVertex(OnFirst,vtxbis); | |
711 | currentarc = otherpt.Arc(); | |
712 | currentparameter = otherpt.Parameter(); | |
713 | ||
714 | currentarc->D1(currentparameter,p2d,d2d); | |
715 | Vtgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
716 | if(Normale.SquareMagnitude()<1e-16) { | |
717 | Transline.SetValue(Standard_True,IntSurf_Undecided); | |
718 | Transarc.SetValue(Standard_True,IntSurf_Undecided); | |
719 | } | |
720 | else { | |
721 | IntSurf::MakeTransition(Vtgint,Vtgrst,Normale, | |
722 | Transline,Transarc); | |
723 | } | |
724 | intpt.SetArc(OnFirst,currentarc,currentparameter, | |
725 | Transline,Transarc); | |
726 | if (TheType == IntPatch_Analytic) { | |
727 | (*((Handle(IntPatch_ALine)*)&slinValueii))->AddVertex(intpt); | |
728 | } | |
729 | else { | |
730 | (*((Handle(IntPatch_GLine)*)&slinValueii))->AddVertex(intpt); | |
731 | } | |
732 | UsedLine(ii) = 1; | |
733 | Retvalue = Standard_True; | |
734 | localdone(k) = 1; | |
735 | } | |
736 | } | |
737 | } | |
738 | } | |
739 | } | |
740 | //-- jj = nbvtx +1; | |
741 | } | |
742 | //-- else { | |
743 | jj = jj+1; | |
744 | //-- } | |
745 | } | |
746 | else { | |
747 | jj = jj+1; | |
748 | } | |
749 | } | |
750 | } | |
751 | ||
752 | for (ii=1; ii<=nbpnt;ii++) { | |
753 | Done(ii) = localdone(ii); | |
754 | } | |
755 | ||
756 | return Retvalue; | |
757 | } | |
758 | ||
759 | ||
760 | ||
761 | Standard_Boolean PointOnSecondDom (const IntPatch_SequenceOfPathPointOfTheSOnBounds& listpnt, | |
762 | const Handle(Adaptor3d_TopolTool)& Domain, | |
763 | const IntSurf_Quadric& QuadSurf, | |
764 | const gp_Vec& Normale, | |
765 | const gp_Vec& Vtgint, | |
766 | const Handle(IntPatch_Line)& lin, | |
767 | TColStd_Array1OfInteger& Done, | |
768 | const Standard_Integer Index) | |
769 | ||
770 | ||
771 | // Duplication des points sur domaine de l autre surface. | |
772 | // On sait que le vertex sous-jacent est PntRef | |
773 | ||
774 | ||
775 | { | |
776 | ||
777 | Standard_Integer k,jj,nbvtx; | |
778 | IntPatch_IType TheType; | |
779 | ||
780 | IntSurf_Transition Transline,Transarc; | |
781 | IntPatch_Point intpt; | |
782 | Handle(Adaptor2d_HCurve2d) currentarc; | |
783 | Handle(Adaptor3d_HVertex) vtx,vtxbis; | |
784 | gp_Pnt ptbid; | |
785 | gp_Vec Vtgrst; | |
786 | ||
787 | gp_Vec d1u,d1v; | |
788 | gp_Pnt2d p2d; | |
789 | gp_Vec2d d2d; | |
790 | ||
791 | Standard_Integer nbpnt = listpnt.Length(); | |
792 | IntPatch_ThePathPointOfTheSOnBounds currentpointonrst = listpnt.Value(Index); | |
793 | Standard_Real currentparameter; | |
794 | ||
795 | Standard_Boolean goon; | |
796 | Standard_Boolean Retvalue = Standard_True; | |
797 | ||
798 | TheType = lin->ArcType(); | |
799 | if (TheType == IntPatch_Analytic) { | |
800 | nbvtx = (*((Handle(IntPatch_ALine)*)&lin))->NbVertex(); | |
801 | } | |
802 | else { | |
803 | nbvtx = (*((Handle(IntPatch_GLine)*)&lin))->NbVertex(); | |
804 | } | |
805 | jj = 1; | |
806 | while (jj <= nbvtx) { | |
807 | if (TheType == IntPatch_Analytic) { | |
808 | intpt = (*((Handle(IntPatch_ALine)*)&lin))->Vertex(jj); | |
809 | } | |
810 | else { | |
811 | intpt = (*((Handle(IntPatch_GLine)*)&lin))->Vertex(jj); | |
812 | } | |
813 | if (!intpt.IsOnDomS2()) { | |
814 | if (currentpointonrst.Value().Distance(intpt.Value()) <= | |
815 | intpt.Tolerance()) { | |
816 | Retvalue = Standard_False; | |
817 | if (!currentpointonrst.IsNew()) { | |
818 | goon = Standard_True; | |
819 | vtx = currentpointonrst.Vertex(); | |
820 | intpt.SetVertex(Standard_False,vtx); | |
821 | } | |
822 | else { | |
823 | goon = Standard_False; | |
824 | } | |
825 | currentarc = currentpointonrst.Arc(); | |
826 | currentparameter = currentpointonrst.Parameter(); | |
827 | currentarc->D1(currentparameter,p2d,d2d); | |
828 | QuadSurf.D1(p2d.X(),p2d.Y(),ptbid,d1u,d1v); | |
829 | Vtgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
830 | if(Normale.SquareMagnitude()<1e-16) { | |
831 | Transline.SetValue(Standard_True,IntSurf_Undecided); | |
832 | Transarc.SetValue(Standard_True,IntSurf_Undecided); | |
833 | } | |
834 | else { | |
835 | IntSurf::MakeTransition(Vtgint,Vtgrst,Normale,Transline,Transarc); | |
836 | } | |
837 | intpt.SetArc(Standard_False,currentarc,currentparameter, | |
838 | Transline,Transarc); | |
839 | if (TheType == IntPatch_Analytic) { | |
840 | (*((Handle(IntPatch_ALine)*)&lin))->Replace(jj,intpt); | |
841 | } | |
842 | else { | |
843 | (*((Handle(IntPatch_GLine)*)&lin))->Replace(jj,intpt); | |
844 | } | |
845 | Done(Index) = 1; | |
846 | ||
847 | if (goon) { | |
848 | for (k=Index+1; k<= nbpnt; k++) { | |
849 | if (Done(k) != 1) { | |
850 | currentpointonrst = listpnt.Value(k); | |
851 | if (!currentpointonrst.IsNew()) { | |
852 | vtxbis = currentpointonrst.Vertex(); | |
853 | if (Domain->Identical(vtx, vtxbis)) { | |
854 | intpt.SetVertex(Standard_False,vtxbis); | |
855 | currentarc = currentpointonrst.Arc(); | |
856 | currentparameter = currentpointonrst.Parameter(); | |
857 | currentarc->D1(currentparameter,p2d,d2d); | |
858 | Vtgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
859 | if(Normale.SquareMagnitude()<1e-16) { | |
860 | Transline.SetValue(Standard_True,IntSurf_Undecided); | |
861 | Transarc.SetValue(Standard_True,IntSurf_Undecided); | |
862 | } | |
863 | else { | |
864 | IntSurf::MakeTransition(Vtgint,Vtgrst,Normale, | |
865 | Transline,Transarc); | |
866 | } | |
867 | intpt.SetArc(Standard_False,currentarc,currentparameter, | |
868 | Transline,Transarc); | |
869 | if (TheType == IntPatch_Analytic) { | |
870 | (*((Handle(IntPatch_ALine)*)&lin))->AddVertex(intpt); | |
871 | } | |
872 | else { | |
873 | (*((Handle(IntPatch_GLine)*)&lin))->AddVertex(intpt); | |
874 | } | |
875 | Done(k) = 1; | |
876 | } | |
877 | } | |
878 | } | |
879 | } | |
880 | } | |
881 | //-- jj = nbvtx + 1; | |
882 | jj++; | |
883 | } | |
884 | else { | |
885 | jj = jj+1; | |
886 | } | |
887 | } | |
888 | else { | |
889 | jj = jj+1; | |
890 | } | |
891 | if (TheType == IntPatch_Analytic) { | |
892 | nbvtx = (*((Handle(IntPatch_ALine)*)&lin))->NbVertex(); | |
893 | } | |
894 | else { | |
895 | nbvtx = (*((Handle(IntPatch_GLine)*)&lin))->NbVertex(); | |
896 | } | |
897 | } | |
898 | return Retvalue; | |
899 | } | |
900 | ||
901 | ||
902 | ||
903 | Standard_Boolean FindLine (gp_Pnt& Psurf, | |
904 | const IntPatch_SequenceOfLine& slin, | |
905 | const Standard_Real Tol, | |
906 | Standard_Real& Paraint, | |
907 | gp_Vec& Vtgtint, | |
908 | Standard_Integer& Range, | |
909 | Standard_Integer OnlyThisLine, | |
910 | const Handle(Adaptor2d_HCurve2d)& thearc, | |
911 | Standard_Real& theparameteronarc, | |
912 | gp_Pnt& thepointonarc, | |
913 | const IntSurf_Quadric& QuadSurf) | |
914 | { | |
915 | ||
916 | // Traitement du point de depart ayant pour representation Psurf | |
917 | // dans l espace. On recherche la ligne d intersection contenant ce point. | |
918 | // On a en sortie la ligne, et le parametre et sa tangente du point sur | |
919 | // la ligne d intersection. | |
920 | ||
921 | Standard_Real distmin = RealLast(); | |
922 | Standard_Real dist,para; | |
923 | Standard_Real lower,upper; | |
924 | gp_Pnt pt; | |
925 | Standard_Integer i; | |
926 | IntPatch_IType typarc; | |
927 | ||
928 | Standard_Integer nblin = slin.Length(); | |
929 | for (i=1; i<=nblin; i++) { | |
930 | if(OnlyThisLine) { i=OnlyThisLine; nblin=0; } | |
931 | const Handle(IntPatch_Line)& lin = slin.Value(i); | |
932 | typarc = lin->ArcType(); | |
933 | if (typarc == IntPatch_Analytic) { | |
934 | Standard_Boolean foo; | |
935 | lower = (*((Handle(IntPatch_ALine)*)&lin))->FirstParameter(foo); | |
936 | upper = (*((Handle(IntPatch_ALine)*)&lin))->LastParameter(foo); | |
937 | } | |
938 | else { | |
939 | if ((*((Handle(IntPatch_GLine)*)&lin))->HasFirstPoint()) { | |
940 | lower = (*((Handle(IntPatch_GLine)*)&lin))->FirstPoint().ParameterOnLine(); | |
941 | } | |
942 | else { | |
943 | lower = RealFirst(); | |
944 | } | |
945 | if ((*((Handle(IntPatch_GLine)*)&lin))->HasLastPoint()) { | |
946 | upper = (*((Handle(IntPatch_GLine)*)&lin))->LastPoint().ParameterOnLine(); | |
947 | } | |
948 | else { | |
949 | upper = RealLast(); | |
950 | } | |
951 | } | |
952 | ||
953 | switch (typarc) { | |
954 | case IntPatch_Lin : | |
955 | { | |
956 | para = ElCLib::Parameter((*((Handle(IntPatch_GLine)*)&lin))->Line(),Psurf); | |
957 | if (para <= upper && para >= lower) { | |
958 | pt = ElCLib::Value(para,(*((Handle(IntPatch_GLine)*)&lin))->Line()); | |
959 | dist = Psurf.Distance(pt); | |
960 | if (dist< distmin) { | |
961 | distmin = dist; | |
962 | Paraint = para; | |
963 | Range = i; | |
964 | } | |
965 | } | |
966 | } | |
967 | break; | |
968 | case IntPatch_Circle : | |
969 | { | |
970 | para = ElCLib::Parameter((*((Handle(IntPatch_GLine)*)&lin))->Circle(),Psurf); | |
971 | if ((para <= upper && para >= lower) || | |
c6541a0c D |
972 | (para + 2.*M_PI <=upper && para + 2.*M_PI >= lower) || |
973 | (para - 2.*M_PI <=upper && para - 2.*M_PI >= lower)) { | |
7fd59977 | 974 | pt = ElCLib::Value(para,(*((Handle(IntPatch_GLine)*)&lin))->Circle()); |
975 | dist = Psurf.Distance(pt); | |
976 | if (dist< distmin) { | |
977 | distmin = dist; | |
978 | Paraint = para; | |
979 | Range = i; | |
980 | } | |
981 | } | |
982 | } | |
983 | break; | |
984 | case IntPatch_Ellipse : | |
985 | { | |
986 | para = ElCLib::Parameter((*((Handle(IntPatch_GLine)*)&lin))->Ellipse(),Psurf); | |
987 | if ((para <= upper && para >= lower) || | |
c6541a0c D |
988 | (para + 2.*M_PI <=upper && para + 2.*M_PI >= lower) || |
989 | (para - 2.*M_PI <=upper && para - 2.*M_PI >= lower)) { | |
7fd59977 | 990 | pt = ElCLib::Value(para,(*((Handle(IntPatch_GLine)*)&lin))->Ellipse()); |
991 | dist = Psurf.Distance(pt); | |
992 | if (dist< distmin) { | |
993 | distmin = dist; | |
994 | Paraint = para; | |
995 | Range = i; | |
996 | } | |
997 | } | |
998 | } | |
999 | break; | |
1000 | case IntPatch_Parabola : | |
1001 | { | |
1002 | ||
1003 | #if 0 | |
1004 | para = ElCLib::Parameter((*((Handle(IntPatch_GLine)*)&lin))->Parabola(),Psurf); | |
1005 | if (para <= upper && para >= lower) { | |
1006 | pt = ElCLib::Value(para,(*((Handle(IntPatch_GLine)*)&lin))->Parabola()); | |
1007 | dist = Psurf.Distance(pt); | |
1008 | if (dist< distmin) { | |
1009 | distmin = dist; | |
1010 | Paraint = para; | |
1011 | Range = i; | |
1012 | } | |
1013 | } | |
1014 | #else | |
1015 | //-- Le calcul du parametre sur une parabole est mal fait ds ElCLib. Il ne tient pas compte | |
1016 | //-- de la meilleure facon de calculer (axe X ou axe Y). Bilan : Si la parabole est tres | |
1017 | //-- pointue (focal de l'ordre de 1e-2 et si le point est a un parametre grand, ca foire. ) | |
1018 | //-- On ne peut pas modifier faciolement ds ElCLib car on ne passe pas la focale. ... | |
1019 | const gp_Parab& Parab=(*((Handle(IntPatch_GLine)*)&lin))->Parabola(); | |
1020 | para = ElCLib::Parameter(Parab,Psurf); | |
1021 | if (para <= upper && para >= lower) { | |
1022 | Standard_Integer amelioration=0; | |
1023 | //-- cout<<"\n ****** \n"; | |
1024 | do { | |
1025 | Standard_Real parabis = para+0.0000001; | |
1026 | ||
1027 | pt = ElCLib::Value(para,Parab); | |
1028 | dist = Psurf.Distance(pt); | |
1029 | ||
1030 | gp_Pnt ptbis = ElCLib::Value(parabis,Parab); | |
1031 | Standard_Real distbis = Psurf.Distance(ptbis); | |
1032 | ||
1033 | Standard_Real ddist = distbis-dist; | |
1034 | ||
1035 | //--cout<<" para: "<<para<<" dist:"<<dist<<" ddist:"<<ddist<<endl; | |
1036 | ||
1037 | if (dist< distmin) { | |
1038 | distmin = dist; | |
1039 | Paraint = para; | |
1040 | Range = i; | |
1041 | } | |
1042 | if(dist<1.0e-9 && dist>-1.0e-9) { amelioration=100; } | |
1043 | ||
1044 | if(ddist>1.0e-9 || ddist<-1.0e-9 ) { | |
1045 | para=para-dist*(parabis-para)/ddist; | |
1046 | } | |
1047 | else { | |
1048 | amelioration=100; | |
1049 | } | |
1050 | } | |
1051 | while(++amelioration < 5); | |
1052 | } | |
1053 | ||
1054 | ||
1055 | #endif | |
1056 | } | |
1057 | break; | |
1058 | case IntPatch_Hyperbola : | |
1059 | { | |
1060 | para = ElCLib::Parameter((*((Handle(IntPatch_GLine)*)&lin))->Hyperbola(),Psurf); | |
1061 | if (para <= upper && para >= lower) { | |
1062 | pt = ElCLib::Value(para,(*((Handle(IntPatch_GLine)*)&lin))->Hyperbola()); | |
1063 | dist = Psurf.Distance(pt); | |
1064 | if (dist< distmin) { | |
1065 | distmin = dist; | |
1066 | Paraint = para; | |
1067 | Range = i; | |
1068 | } | |
1069 | } | |
1070 | } | |
1071 | break; | |
1072 | ||
1073 | case IntPatch_Analytic : | |
1074 | { | |
1075 | const Handle(IntPatch_ALine)& alin = (*((Handle(IntPatch_ALine)*)&lin)); | |
1076 | Standard_Boolean ok = alin->FindParameter(Psurf,para); | |
1077 | if (ok) { | |
1078 | pt = alin->Value(para); | |
1079 | dist = Psurf.Distance(pt); | |
1080 | if (dist< distmin) { | |
1081 | distmin = dist; | |
1082 | Paraint = para; | |
1083 | Range = i; | |
1084 | } | |
1085 | } | |
1086 | else { | |
1087 | //-- le point n a pas ete trouve par bete projection. | |
1088 | //-- on essaie l intersection avec la restriction en 2d | |
1089 | Standard_Real theparamonarc = theparameteronarc; | |
6e6cd5d9 | 1090 | //#ifdef DEB |
1091 | // Standard_Real anpara=para; | |
1092 | //#endif | |
7fd59977 | 1093 | gp_Pnt CopiePsurf=Psurf; |
1094 | Standard_Boolean ok=IntersectionWithAnArc(CopiePsurf,alin,para,thearc,theparamonarc,thepointonarc,QuadSurf,lower,upper,dist); | |
1095 | ||
1096 | //--printf("\nIntersectionWithAnArc %d \n Psurf(%g,%g,%g)->(%g,%g,%g) dist=%g\n para(%g)->(%g)\n paraonarc(%g)->(%g)", | |
1097 | //-- ok,Psurf.X(),Psurf.Y(),Psurf.Z(),thepointonarc.X(),thepointonarc.Y(),thepointonarc.Z(),dist, | |
1098 | //-- anpara,para,theparameteronarc,theparamonarc); | |
1099 | dist = CopiePsurf.Distance(Psurf); | |
1100 | if(ok) { | |
1101 | if(dist<Tol) { | |
1102 | theparameteronarc = theparamonarc; | |
1103 | Psurf = thepointonarc; | |
1104 | distmin = dist; | |
1105 | Paraint = para; | |
1106 | Range = i; | |
1107 | } | |
1108 | } | |
1109 | } | |
1110 | } | |
1111 | break; | |
1112 | ||
1113 | case IntPatch_Walking: // impossible . c est pour eviter les warnings | |
1114 | { | |
1115 | } | |
1116 | case IntPatch_Restriction: // impossible . c est pour eviter les warnings | |
1117 | { | |
1118 | } | |
1119 | } | |
1120 | } | |
1121 | ||
1122 | if (distmin > Tol) { | |
1123 | return Standard_False; | |
1124 | } | |
1125 | ||
1126 | typarc = slin.Value(Range)->ArcType(); | |
1127 | ||
1128 | // Calcul de la tangente. | |
1129 | switch (typarc) { | |
1130 | case IntPatch_Lin : | |
1131 | Vtgtint = (*((Handle(IntPatch_GLine)*)&slin(Range)))->Line().Direction(); | |
1132 | break; | |
1133 | case IntPatch_Circle : | |
1134 | Vtgtint = ElCLib::DN(Paraint,(*((Handle(IntPatch_GLine)*)&slin(Range)))->Circle(),1); | |
1135 | break; | |
1136 | case IntPatch_Ellipse : | |
1137 | Vtgtint = ElCLib::DN(Paraint,(*((Handle(IntPatch_GLine)*)&slin(Range)))->Ellipse(),1); | |
1138 | break; | |
1139 | case IntPatch_Parabola : | |
1140 | Vtgtint = ElCLib::DN(Paraint,(*((Handle(IntPatch_GLine)*)&slin(Range)))->Parabola(),1); | |
1141 | break; | |
1142 | case IntPatch_Hyperbola : | |
1143 | Vtgtint = ElCLib::DN(Paraint,(*((Handle(IntPatch_GLine)*)&slin(Range)))->Hyperbola(),1); | |
1144 | break; | |
1145 | ||
1146 | case IntPatch_Analytic: | |
1147 | { | |
1148 | const Handle(IntPatch_ALine)& alin = (*((Handle(IntPatch_ALine)*)&slin(Range))); | |
1149 | Standard_Boolean abid = alin->D1(Paraint,pt,Vtgtint); | |
1150 | if (!abid) { | |
1151 | Standard_Real domaininf,domainsup,paramproche; | |
1152 | Standard_Boolean boolbid; | |
1153 | domaininf = alin->FirstParameter(boolbid); | |
1154 | domainsup = alin->LastParameter(boolbid); | |
1155 | if(Paraint>=domaininf && Paraint<=domainsup) { | |
1156 | Standard_Real DeltaParam = 0.001 * (domainsup-domaininf); | |
1157 | if(Paraint-domaininf >= domainsup-Paraint) { | |
1158 | //-- On decale le point vers le parametre le plus eloigne. | |
1159 | DeltaParam = -DeltaParam; | |
1160 | } | |
1161 | Standard_Integer kountbid = 0; | |
1162 | Standard_Boolean bornok = Standard_True; | |
1163 | paramproche = Paraint; | |
1164 | do { | |
1165 | paramproche+=DeltaParam; | |
1166 | kountbid++; | |
1167 | gp_Pnt ptbid; | |
1168 | if(paramproche>=domaininf && paramproche<=domainsup) { | |
1169 | abid = alin->D1(paramproche,ptbid,Vtgtint); | |
1170 | } | |
1171 | else { | |
1172 | bornok = Standard_False; | |
1173 | } | |
1174 | } | |
1175 | while(abid==Standard_False && kountbid<5 && bornok); | |
1176 | //-- Attention aux points de tangence (croisement de 4 lignes ) | |
1177 | bornok = Standard_True; | |
1178 | kountbid = 0; | |
1179 | gp_Vec OVtgtint(0.0,0.0,0.0); | |
1180 | paramproche = Paraint; | |
1181 | do { | |
1182 | paramproche-=DeltaParam; | |
1183 | kountbid++; | |
1184 | gp_Pnt ptbid; | |
1185 | if(paramproche>=domaininf && paramproche<=domainsup) { | |
1186 | abid = alin->D1(paramproche,ptbid,OVtgtint); | |
1187 | } | |
1188 | else { | |
1189 | bornok = Standard_False; | |
1190 | } | |
1191 | } | |
1192 | while(abid==Standard_False && kountbid<5 && bornok); | |
1193 | if(bornok) { | |
1194 | paramproche = Vtgtint.Dot(OVtgtint); | |
1195 | if(paramproche<=0.0) abid = Standard_False; | |
1196 | } | |
1197 | } | |
1198 | if(!abid) { | |
1199 | //-- cout << "Pb sur Calcul de derivee 111 " << endl; | |
1200 | Vtgtint.SetCoord(0.,0.,0.); | |
1201 | } | |
1202 | } | |
1203 | } | |
1204 | break; | |
1205 | case IntPatch_Walking: // impossible . c est pour eviter les warnings | |
1206 | { | |
1207 | } | |
1208 | case IntPatch_Restriction: // impossible . c est pour eviter les warnings | |
1209 | { | |
1210 | } | |
1211 | ||
1212 | } | |
1213 | return Standard_True; | |
1214 | } | |
1215 | ||
1216 | ||
1217 | Standard_Boolean SingleLine (const gp_Pnt& Psurf, | |
1218 | const Handle(IntPatch_Line)& lin, | |
1219 | const Standard_Real Tol, | |
1220 | Standard_Real& Paraint, | |
1221 | gp_Vec& Vtgtint) { | |
1222 | ||
1223 | // Traitement du point de depart ayant pour representation Psurf | |
1224 | // dans l espace. On le replace sur la ligne d intersection; On a en sortie | |
1225 | // son parametre et sa tangente sur la ligne d intersection. | |
1226 | // La fonction renvoie False si le point projete est a une distance | |
1227 | // superieure a Tol du point a projeter. | |
1228 | ||
1229 | IntPatch_IType typarc = lin->ArcType(); | |
1230 | ||
1d47d8d0 | 1231 | Standard_Real parproj = 0.; |
7fd59977 | 1232 | gp_Vec tgint; |
1233 | gp_Pnt ptproj; | |
1234 | Standard_Boolean retvalue; | |
1235 | ||
1236 | ||
1237 | switch (typarc) { | |
1238 | case IntPatch_Lin : | |
1239 | parproj = ElCLib::Parameter((*((Handle(IntPatch_GLine)*)&lin))->Line(),Psurf); | |
1240 | ElCLib::D1(parproj,(*((Handle(IntPatch_GLine)*)&lin))->Line(),ptproj,tgint); | |
1241 | break; | |
1242 | case IntPatch_Circle : | |
1243 | parproj = ElCLib::Parameter((*((Handle(IntPatch_GLine)*)&lin))->Circle(),Psurf); | |
1244 | ElCLib::D1(parproj,(*((Handle(IntPatch_GLine)*)&lin))->Circle(),ptproj,tgint); | |
1245 | break; | |
1246 | case IntPatch_Ellipse : | |
1247 | parproj = ElCLib::Parameter((*((Handle(IntPatch_GLine)*)&lin))->Ellipse(),Psurf); | |
1248 | ElCLib::D1(parproj,(*((Handle(IntPatch_GLine)*)&lin))->Ellipse(),ptproj,tgint); | |
1249 | break; | |
1250 | case IntPatch_Parabola : | |
1251 | parproj = ElCLib::Parameter((*((Handle(IntPatch_GLine)*)&lin))->Parabola(),Psurf); | |
1252 | ElCLib::D1(parproj,(*((Handle(IntPatch_GLine)*)&lin))->Parabola(),ptproj,tgint); | |
1253 | break; | |
1254 | case IntPatch_Hyperbola : | |
1255 | parproj = ElCLib::Parameter((*((Handle(IntPatch_GLine)*)&lin))->Hyperbola(),Psurf); | |
1256 | ElCLib::D1(parproj,(*((Handle(IntPatch_GLine)*)&lin))->Hyperbola(),ptproj,tgint); | |
1257 | break; | |
1258 | case IntPatch_Analytic : | |
1259 | { | |
1260 | const Handle(IntPatch_ALine)& alin = (*((Handle(IntPatch_ALine)*)&lin)); | |
1261 | Standard_Boolean ok = alin->FindParameter(Psurf,parproj); | |
1262 | if (ok) { | |
1263 | gp_Pnt ptbid; | |
1264 | Standard_Boolean bid = alin->D1(parproj,ptbid,tgint); | |
1265 | if (!bid) { | |
1266 | Standard_Real domaininf,domainsup,paramproche; | |
1267 | Standard_Boolean boolbid; | |
1268 | domaininf = alin->FirstParameter(boolbid); | |
1269 | domainsup = alin->LastParameter(boolbid); | |
1270 | if(parproj>=domaininf && parproj<=domainsup) { | |
1271 | Standard_Real DeltaParam = 0.001 * (domainsup-domaininf); | |
1272 | if(parproj-domaininf >= domainsup-parproj) { | |
1273 | //-- On decale le point vers le parametre le plus eloigne. | |
1274 | DeltaParam = -DeltaParam; | |
1275 | } | |
1276 | Standard_Integer kountbid = 0; | |
1277 | paramproche = parproj; | |
1278 | do { | |
1279 | paramproche+=DeltaParam; | |
1280 | kountbid++; | |
1281 | bid = alin->D1(paramproche,ptbid,tgint); | |
1282 | } | |
1283 | while(bid==Standard_False && kountbid<5); | |
1284 | ptproj = Psurf; | |
1285 | } | |
1286 | if(!bid) { | |
1287 | //-- cout << "Pb sur Calcul de derivee ALine " << endl; | |
1288 | tgint.SetCoord(0.,0.,0.); | |
1289 | return(Standard_False); | |
1290 | } | |
1291 | } | |
1292 | else { | |
1293 | ptproj = Psurf; | |
1294 | } | |
1295 | } | |
1296 | else { | |
1297 | //-- cout << "---- Pb sur ligne analytique dans SingleLine" << endl; | |
1298 | //-- cout << " Find Parameter"<<endl; | |
1299 | return Standard_False; | |
1300 | } | |
1301 | } | |
1302 | break; | |
1303 | case IntPatch_Walking: // impossible . c est pour eviter les warnings | |
1304 | { | |
1305 | } | |
1306 | case IntPatch_Restriction: // impossible . c est pour eviter les warnings | |
1307 | { | |
1308 | } | |
1309 | } | |
1310 | ||
1311 | if (Psurf.Distance(ptproj) <= Tol) { | |
1312 | Paraint = parproj; | |
1313 | Vtgtint = tgint; | |
1314 | retvalue = Standard_True; | |
1315 | } | |
1316 | else { | |
1317 | retvalue = Standard_False; | |
1318 | } | |
1319 | return retvalue; | |
1320 | } | |
1321 | ||
1322 | ||
1323 | void ProcessSegments (const IntPatch_SequenceOfSegmentOfTheSOnBounds& listedg, | |
1324 | IntPatch_SequenceOfLine& slin, | |
1325 | const IntSurf_Quadric& Quad1, | |
1326 | const IntSurf_Quadric& Quad2, | |
1327 | const Standard_Boolean OnFirst, | |
1328 | const Standard_Real TolArc) { | |
1329 | ||
1330 | Standard_Integer i,j,k; | |
1331 | Standard_Integer nbedg = listedg.Length(); | |
1332 | Standard_Integer Nblines,Nbpts; | |
1333 | ||
1334 | Handle(Adaptor2d_HCurve2d) arcRef; | |
1335 | IntPatch_Point ptvtx, newptvtx; | |
1336 | ||
1337 | Handle(IntPatch_RLine) rline; //-- On fait rline = new ... par la suite | |
1338 | ||
1339 | IntPatch_TheSegmentOfTheSOnBounds thesegsol; | |
1340 | IntPatch_ThePathPointOfTheSOnBounds PStartf,PStartl; | |
1341 | Standard_Boolean dofirst,dolast,procf,procl; | |
1d47d8d0 | 1342 | |
7fd59977 | 1343 | Standard_Real paramf =0.,paraml =0.,U1 =0.,V1 =0.,U2 =0.,V2 =0.; |
1d47d8d0 | 1344 | |
7fd59977 | 1345 | IntPatch_IType typ; |
1346 | IntSurf_TypeTrans trans1,trans2; | |
1347 | IntSurf_Transition TRest,TArc; | |
1348 | gp_Vec tgline,norm1,norm2,tgarc; | |
1349 | gp_Pnt valpt; | |
1350 | ||
1351 | gp_Vec d1u,d1v; | |
1352 | gp_Pnt2d p2d; | |
1353 | gp_Vec2d d2d; | |
1354 | ||
1355 | ||
1356 | for (i = 1; i <= nbedg; i++) { | |
1357 | Standard_Boolean EdgeDegenere=Standard_False; | |
1358 | thesegsol = listedg.Value(i); | |
1359 | arcRef = thesegsol.Curve(); | |
1360 | ||
1361 | ||
1362 | rline = new IntPatch_RLine(Standard_False); | |
1363 | if(OnFirst) { | |
1364 | rline->SetArcOnS1(arcRef); | |
1365 | } | |
1366 | else { | |
1367 | rline->SetArcOnS2(arcRef); | |
1368 | } | |
1369 | ||
1370 | // Traitement des points debut/fin du segment solution. | |
1371 | ||
1372 | dofirst = Standard_False; | |
1373 | dolast = Standard_False; | |
1374 | procf = Standard_False; | |
1375 | procl = Standard_False; | |
1376 | ||
1377 | if (thesegsol.HasFirstPoint()) { | |
1378 | dofirst = Standard_True; | |
1379 | PStartf = thesegsol.FirstPoint(); | |
1380 | paramf = PStartf.Parameter(); | |
1381 | } | |
1382 | if (thesegsol.HasLastPoint()) { | |
1383 | dolast = Standard_True; | |
1384 | PStartl = thesegsol.LastPoint(); | |
1385 | paraml = PStartl.Parameter(); | |
1386 | } | |
1387 | ||
1388 | if (dofirst && dolast) { // determination de la transition de la ligne | |
1389 | arcRef->D1(0.5*(paramf+paraml),p2d,d2d); | |
1390 | if (OnFirst) { | |
1391 | Quad1.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v); | |
1392 | } | |
1393 | else { | |
1394 | Quad2.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v); | |
1395 | } | |
1396 | tgline.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
1397 | ||
1398 | if(d1u.Magnitude()<1e-7) { //-- edge degenere ? | |
1399 | EdgeDegenere=Standard_True; | |
1400 | for(Standard_Integer edg=0;edg<=10;edg++) { | |
1401 | arcRef->D1(paramf+(paraml-paramf)*edg*0.1,p2d,d2d); | |
1402 | if (OnFirst) { | |
1403 | Quad1.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v); | |
1404 | } | |
1405 | else { | |
1406 | Quad2.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v); | |
1407 | } | |
1408 | ||
1409 | if(d1u.Magnitude()>1e-7) { | |
1410 | EdgeDegenere=Standard_False; | |
1411 | } | |
1412 | } | |
1413 | rline = new IntPatch_RLine(Standard_False); | |
1414 | if(OnFirst) { | |
1415 | rline->SetArcOnS1(arcRef); | |
1416 | } | |
1417 | else { | |
1418 | rline->SetArcOnS2(arcRef); | |
1419 | } | |
1420 | } | |
1421 | else { | |
1422 | norm2 = Quad2.Normale(valpt); | |
1423 | norm1 = Quad1.Normale(valpt); | |
1424 | ||
1425 | if (tgline.DotCross(norm2,norm1) > 0.000000001) { | |
1426 | trans1 = IntSurf_Out; | |
1427 | trans2 = IntSurf_In; | |
1428 | } | |
1429 | else if (tgline.DotCross(norm2,norm1) < -0.000000001){ | |
1430 | trans1 = IntSurf_In; | |
1431 | trans2 = IntSurf_Out; | |
1432 | } | |
1433 | else { | |
1434 | trans1 = trans2 = IntSurf_Undecided; | |
1435 | } | |
1436 | rline = new IntPatch_RLine(Standard_False,trans1,trans2); | |
1437 | if(OnFirst) { | |
1438 | rline->SetArcOnS1(arcRef); | |
1439 | } | |
1440 | else { | |
1441 | rline->SetArcOnS2(arcRef); | |
1442 | } | |
1443 | } | |
1444 | } | |
1445 | else { | |
1446 | rline = new IntPatch_RLine(Standard_False); | |
1447 | if(OnFirst) { | |
1448 | rline->SetArcOnS1(arcRef); | |
1449 | } | |
1450 | else { | |
1451 | rline->SetArcOnS2(arcRef); | |
1452 | } | |
1453 | } | |
1454 | ||
1455 | if (dofirst || dolast) { | |
1456 | Nblines = slin.Length(); | |
1457 | for (j=1; j<=Nblines; j++) { | |
1458 | const Handle(IntPatch_Line)& slinj = slin(j); | |
1459 | typ = slinj->ArcType(); | |
1460 | if (typ == IntPatch_Analytic) { | |
1461 | Nbpts = (*((Handle(IntPatch_ALine)*)&slinj))->NbVertex(); | |
1462 | } | |
1463 | else if (typ == IntPatch_Restriction) { | |
1464 | Nbpts = (*((Handle(IntPatch_RLine)*)&slinj))->NbVertex(); | |
1465 | } | |
1466 | else { | |
1467 | Nbpts = (*((Handle(IntPatch_GLine)*)&slinj))->NbVertex(); | |
1468 | } | |
1469 | for (k=1; k<=Nbpts;k++) { | |
1470 | if (typ == IntPatch_Analytic) { | |
1471 | ptvtx = (*((Handle(IntPatch_ALine)*)&slinj))->Vertex(k); | |
1472 | } | |
1473 | else if (typ == IntPatch_Restriction) { | |
1474 | ptvtx = (*((Handle(IntPatch_RLine)*)&slinj))->Vertex(k); | |
1475 | } | |
1476 | else { | |
1477 | ptvtx = (*((Handle(IntPatch_GLine)*)&slinj))->Vertex(k); | |
1478 | } | |
1479 | ||
1480 | if (EdgeDegenere==Standard_False && dofirst) { | |
1481 | if (ptvtx.Value().Distance(PStartf.Value()) <=TolArc) { | |
1482 | ptvtx.SetMultiple(Standard_True); | |
1483 | if (typ == IntPatch_Analytic) { | |
1484 | (*((Handle(IntPatch_ALine)*)&slinj))->Replace(k,ptvtx); | |
1485 | } | |
1486 | else if (typ == IntPatch_Restriction) { | |
1487 | (*((Handle(IntPatch_RLine)*)&slinj))->Replace(k,ptvtx); | |
1488 | } | |
1489 | else { | |
1490 | (*((Handle(IntPatch_GLine)*)&slinj))->Replace(k,ptvtx); | |
1491 | } | |
1492 | newptvtx = ptvtx; | |
1493 | newptvtx.SetParameter(paramf); | |
1494 | //Recalcul des transitions si point sur restriction | |
1495 | ||
1496 | arcRef->D1(paramf,p2d,d2d); | |
1497 | if (OnFirst) { | |
1498 | Quad1.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v); | |
1499 | } | |
1500 | else { | |
1501 | Quad2.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v); | |
1502 | } | |
1503 | tgline.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
1504 | if (ptvtx.IsOnDomS1()) { | |
1505 | const Handle(Adaptor2d_HCurve2d)& thearc = ptvtx.ArcOnS1(); | |
1506 | thearc->D1(ptvtx.ParameterOnArc1(),p2d,d2d); | |
1507 | Quad1.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v); | |
1508 | tgarc.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
1509 | norm1 = d1u.Crossed(d1v); | |
1510 | if(norm1.SquareMagnitude()<1e-16) { | |
1511 | TRest.SetValue(Standard_True,IntSurf_Undecided); | |
1512 | TArc.SetValue(Standard_True,IntSurf_Undecided); | |
1513 | } | |
1514 | else { | |
1515 | IntSurf::MakeTransition(tgline,tgarc,norm1,TRest,TArc); | |
1516 | } | |
1517 | newptvtx.SetArc(Standard_True,thearc,ptvtx.ParameterOnArc1(), | |
1518 | TRest,TArc); | |
1519 | } | |
1520 | if (ptvtx.IsOnDomS2()) { | |
1521 | const Handle(Adaptor2d_HCurve2d)& thearc = ptvtx.ArcOnS2(); | |
1522 | thearc->D1(ptvtx.ParameterOnArc2(),p2d,d2d); | |
1523 | Quad2.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v); | |
1524 | tgarc.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
1525 | norm2 = d1u.Crossed(d1v); | |
1526 | if(norm2.SquareMagnitude()<1e-16) { | |
1527 | TRest.SetValue(Standard_True,IntSurf_Undecided); | |
1528 | TArc.SetValue(Standard_True,IntSurf_Undecided); | |
1529 | } | |
1530 | else { | |
1531 | IntSurf::MakeTransition(tgline,tgarc,norm2,TRest,TArc); | |
1532 | } | |
1533 | newptvtx.SetArc(Standard_False,thearc,ptvtx.ParameterOnArc2(), | |
1534 | TRest,TArc); | |
1535 | } | |
1536 | ||
1537 | rline->AddVertex(newptvtx); | |
1538 | if (!procf){ | |
1539 | procf=Standard_True; | |
1540 | rline->SetFirstPoint(rline->NbVertex()); | |
1541 | } | |
1542 | } | |
1543 | } | |
1544 | if (EdgeDegenere==Standard_False && dolast) { | |
1545 | if (ptvtx.Value().Distance(PStartl.Value()) <=TolArc) { | |
1546 | ptvtx.SetMultiple(Standard_True); | |
1547 | if (typ == IntPatch_Analytic) { | |
1548 | (*((Handle(IntPatch_ALine)*)&slinj))->Replace(k,ptvtx); | |
1549 | } | |
1550 | else if (typ == IntPatch_Restriction) { | |
1551 | (*((Handle(IntPatch_RLine)*)&slinj))->Replace(k,ptvtx); | |
1552 | } | |
1553 | else { | |
1554 | (*((Handle(IntPatch_GLine)*)&slinj))->Replace(k,ptvtx); | |
1555 | } | |
1556 | ||
1557 | newptvtx = ptvtx; | |
1558 | newptvtx.SetParameter(paraml); | |
1559 | //Recalcul des transitions si point sur restriction | |
1560 | ||
1561 | arcRef->D1(paraml,p2d,d2d); | |
1562 | if (OnFirst) { | |
1563 | Quad1.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v); | |
1564 | } | |
1565 | else { | |
1566 | Quad2.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v); | |
1567 | } | |
1568 | tgline.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
1569 | if (ptvtx.IsOnDomS1()) { | |
1570 | const Handle(Adaptor2d_HCurve2d)& thearc = ptvtx.ArcOnS1(); | |
1571 | thearc->D1(ptvtx.ParameterOnArc1(),p2d,d2d); | |
1572 | Quad1.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v); | |
1573 | tgarc.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
1574 | norm1 = d1u.Crossed(d1v); | |
1575 | if(norm1.SquareMagnitude()<1e-16) { | |
1576 | TRest.SetValue(Standard_True,IntSurf_Undecided); | |
1577 | TArc.SetValue(Standard_True,IntSurf_Undecided); | |
1578 | } | |
1579 | else { | |
1580 | IntSurf::MakeTransition(tgline,tgarc,norm1,TRest,TArc); | |
1581 | } | |
1582 | newptvtx.SetArc(Standard_True,thearc,ptvtx.ParameterOnArc1(), | |
1583 | TRest,TArc); | |
1584 | } | |
1585 | if (ptvtx.IsOnDomS2()) { | |
1586 | const Handle(Adaptor2d_HCurve2d)& thearc = ptvtx.ArcOnS2(); | |
1587 | thearc->D1(ptvtx.ParameterOnArc2(),p2d,d2d); | |
1588 | Quad2.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v); | |
1589 | tgarc.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
1590 | norm2 = d1u.Crossed(d1v); | |
1591 | if(norm2.SquareMagnitude()<1e-16) { | |
1592 | TRest.SetValue(Standard_True,IntSurf_Undecided); | |
1593 | TArc.SetValue(Standard_True,IntSurf_Undecided); | |
1594 | } | |
1595 | else { | |
1596 | IntSurf::MakeTransition(tgline,tgarc,norm2,TRest,TArc); | |
1597 | } | |
1598 | newptvtx.SetArc(Standard_False,thearc,ptvtx.ParameterOnArc2(), | |
1599 | TRest,TArc); | |
1600 | } | |
1601 | ||
1602 | rline->AddVertex(newptvtx); | |
1603 | if (!procl){ | |
1604 | procl=Standard_True; | |
1605 | rline->SetLastPoint(rline->NbVertex()); | |
1606 | } | |
1607 | } | |
1608 | } | |
1609 | } | |
1610 | // Si on a traite le pt debut et/ou fin, on ne doit pas recommencer si | |
1611 | // il (ils) correspond(ent) a un point multiple. | |
1612 | ||
1613 | if (procf) { | |
1614 | dofirst = Standard_False; | |
1615 | } | |
1616 | if (procl) { | |
1617 | dolast = Standard_False; | |
1618 | } | |
1619 | } | |
1620 | } | |
1621 | // Si on n a pas trouve le point debut et./ou fin sur une des lignes | |
1622 | // d intersection, il faut quand-meme le placer sur la restriction solution | |
1623 | ||
1624 | if (dofirst) { | |
1625 | ptvtx.SetValue(PStartf.Value(),PStartf.Tolerance(),Standard_False); | |
1626 | Quad1.Parameters(PStartf.Value(),U1,V1); | |
1627 | Quad2.Parameters(PStartf.Value(),U2,V2); | |
1628 | ptvtx.SetParameters(U1,V1,U2,V2); | |
1629 | ptvtx.SetParameter(paramf); | |
1630 | if (! PStartf.IsNew()) { | |
1631 | IntSurf_Transition Transline; | |
1632 | IntSurf_Transition Transarc; | |
1633 | ptvtx.SetVertex(OnFirst,PStartf.Vertex()); | |
1634 | ptvtx.SetArc(OnFirst,PStartf.Arc(),PStartf.Parameter(), | |
1635 | Transline,Transarc); | |
1636 | } | |
1637 | ||
1638 | rline->AddVertex(ptvtx); | |
1639 | rline->SetFirstPoint(rline->NbVertex()); | |
1640 | } | |
1641 | if (dolast) { | |
1642 | ptvtx.SetValue(PStartl.Value(),PStartl.Tolerance(),Standard_False); | |
1643 | Quad1.Parameters(PStartl.Value(),U1,V1); | |
1644 | Quad2.Parameters(PStartl.Value(),U2,V2); | |
1645 | ptvtx.SetParameters(U1,V1,U2,V2); | |
1646 | ptvtx.SetParameter(paraml); | |
1647 | if (! PStartl.IsNew()) { | |
1648 | IntSurf_Transition Transline; | |
1649 | IntSurf_Transition Transarc; | |
1650 | ||
1651 | ptvtx.SetVertex(OnFirst,PStartl.Vertex()); | |
1652 | ptvtx.SetArc(OnFirst,PStartl.Arc(),PStartl.Parameter(), | |
1653 | Transline,Transarc); | |
1654 | } | |
1655 | ||
1656 | rline->AddVertex(ptvtx); | |
1657 | rline->SetLastPoint(rline->NbVertex()); | |
1658 | } | |
1659 | slin.Append(rline); | |
1660 | } | |
1661 | } | |
1662 | ||
1663 | ||
1664 | void ProcessRLine (IntPatch_SequenceOfLine& slin, | |
1665 | // const Handle(Adaptor3d_HSurface)& Surf1, | |
1666 | // const Handle(Adaptor3d_HSurface)& Surf2, | |
1667 | const IntSurf_Quadric& Quad1, | |
1668 | const IntSurf_Quadric& Quad2, | |
1669 | const Standard_Real _TolArc) { | |
1670 | ||
1671 | // On cherche a placer sur les restrictions solutions les points "multiples" | |
1672 | // des autres lignes d intersection | |
1673 | // Pas forcemment le plus efficace : on rique de projeter plusieurs fois | |
1674 | // le meme point sur la meme restriction... | |
1675 | ||
1676 | Standard_Real TolArc=100.0*_TolArc; | |
1677 | if(TolArc>0.1) TolArc=0.1; | |
1678 | ||
1679 | Standard_Integer i,j,k; | |
1680 | Standard_Integer Nblin,Nbvtx, Nbpt; | |
1d47d8d0 | 1681 | |
7fd59977 | 1682 | Standard_Boolean OnFirst = Standard_False,project = Standard_False,keeppoint = Standard_False; |
1d47d8d0 | 1683 | |
7fd59977 | 1684 | Handle(Adaptor2d_HCurve2d) arcref; |
1685 | Standard_Real paramproj,paramf,paraml; | |
1686 | ||
1687 | TColgp_SequenceOfPnt seq_Pnt3d; | |
1688 | TColStd_SequenceOfReal seq_Real; | |
1689 | ||
1690 | gp_Pnt ptproj,toproj,valpt; | |
1691 | ||
1692 | gp_Pnt2d p2d; | |
1693 | gp_Vec2d d2d; | |
1694 | gp_Vec d1u,d1v,tgrest,tgarc,norm; | |
1695 | IntSurf_Transition TRest,TArc; | |
1696 | #ifndef DEB | |
1697 | Standard_Real U =0.,V =0.; | |
1698 | #else | |
1699 | Standard_Real U,V; | |
1700 | #endif | |
1701 | IntPatch_Point Ptvtx,newptvtx; | |
1702 | ||
1703 | IntPatch_IType typ1,typ2; | |
1704 | ||
1705 | ||
1706 | Nblin = slin.Length(); | |
1707 | for (i=1; i<=Nblin; i++) { | |
1708 | const Handle(IntPatch_Line)& slini = slin(i); | |
1709 | typ1 = slini->ArcType(); | |
1710 | if (typ1 == IntPatch_Restriction) { | |
1711 | seq_Pnt3d.Clear(); | |
1712 | seq_Real.Clear(); | |
1713 | for (j=1; j<=Nblin; j++) { | |
1714 | const Handle(IntPatch_Line)& slinj = slin(j); | |
1715 | Nbpt = seq_Pnt3d.Length(); // important que ce soit ici | |
1716 | typ2 = slinj->ArcType(); | |
1717 | if (typ2 != IntPatch_Restriction) { | |
1718 | ||
1719 | //-- arcref = (*((Handle(IntPatch_RLine)*)&slini))->Arc(); | |
1720 | //-- OnFirst = (*((Handle(IntPatch_RLine)*)&slini))->IsOnFirstSurface(); | |
1721 | ||
1722 | //-- DES CHOSES A FAIRE ICI | |
1723 | if((*((Handle(IntPatch_RLine)*)&slini))->IsArcOnS1()) { | |
1724 | OnFirst=Standard_True; | |
1725 | arcref= (*((Handle(IntPatch_RLine)*)&slini))->ArcOnS1(); | |
1726 | } | |
1727 | else if((*((Handle(IntPatch_RLine)*)&slini))->IsArcOnS2()) { | |
1728 | arcref= (*((Handle(IntPatch_RLine)*)&slini))->ArcOnS2(); | |
1729 | OnFirst=Standard_False; | |
1730 | } | |
1731 | if ((*((Handle(IntPatch_RLine)*)&slini))->HasFirstPoint()) { | |
1732 | paramf = (*((Handle(IntPatch_RLine)*)&slini))->FirstPoint().ParameterOnLine(); | |
1733 | } | |
1734 | else { | |
1735 | // cout << "Pas de param debut sur rst solution" << endl; | |
1736 | paramf = RealFirst(); | |
1737 | } | |
1738 | if ((*((Handle(IntPatch_RLine)*)&slini))->HasLastPoint()) { | |
1739 | paraml = (*((Handle(IntPatch_RLine)*)&slini))->LastPoint().ParameterOnLine(); | |
1740 | } | |
1741 | else { | |
1742 | // cout << "Pas de param debut sur rst solution" << endl; | |
1743 | paraml = RealLast(); | |
1744 | } | |
1745 | ||
1746 | if (typ2 == IntPatch_Analytic) { | |
1747 | Nbvtx = (*((Handle(IntPatch_ALine)*)&slinj))->NbVertex(); | |
1748 | } | |
1749 | else { | |
1750 | Nbvtx = (*((Handle(IntPatch_GLine)*)&slinj))->NbVertex(); | |
1751 | } | |
1752 | ||
1753 | ||
1754 | Standard_Boolean EdgeDegenere=Standard_True; | |
1755 | for(Standard_Integer edg=0;EdgeDegenere && edg<=10;edg++) { | |
1756 | arcref->D1(paramf+(paraml-paramf)*edg*0.1,p2d,d2d); | |
1757 | if (OnFirst) { | |
1758 | Quad1.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v); | |
1759 | } | |
1760 | else { | |
1761 | Quad2.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v); | |
1762 | } | |
1763 | if(d1u.Magnitude()>1e-7) { | |
1764 | EdgeDegenere=Standard_False; | |
1765 | } | |
1766 | } | |
1767 | ||
1768 | for (k=1; EdgeDegenere==Standard_False && k<=Nbvtx; k++) { | |
1769 | if (typ2 == IntPatch_Analytic) { | |
1770 | Ptvtx = (*((Handle(IntPatch_ALine)*)&slinj))->Vertex(k); | |
1771 | } | |
1772 | else { | |
1773 | Ptvtx = (*((Handle(IntPatch_GLine)*)&slinj))->Vertex(k); | |
1774 | } | |
1775 | if ((OnFirst && !Ptvtx.IsOnDomS1()) || | |
1776 | (!OnFirst && !Ptvtx.IsOnDomS2())) { | |
1777 | // Si OnFirst && OnDomS1, c est qu on est a une extremite | |
1778 | // ca doit etre traite par Process Segment... | |
1779 | project = Standard_True; | |
1780 | keeppoint = Standard_False; | |
1781 | toproj = Ptvtx.Value(); | |
1782 | ||
1783 | Standard_Integer jj; | |
1784 | for (jj = 1; jj <= Nbpt; jj++) { | |
1785 | //for (Standard_Integer jj = 1; jj <= Nbpt; jj++) { | |
1786 | if (toproj.Distance(seq_Pnt3d(jj)) < _TolArc) { | |
1787 | project = Standard_False; | |
1788 | break; | |
1789 | } | |
1790 | } | |
1791 | if (project) { //-- il faut projeter pour trouver le point sur la rline. | |
1792 | if (OnFirst) { | |
1793 | Ptvtx.ParametersOnS1(U,V); | |
1794 | } | |
1795 | else { | |
1796 | Ptvtx.ParametersOnS2(U,V); | |
1797 | } | |
1798 | ||
1799 | project = IntPatch_HInterTool::Project(arcref,gp_Pnt2d(U,V), | |
1800 | paramproj,p2d); | |
1801 | ||
1802 | if (project) { | |
1803 | if (OnFirst) { | |
1804 | ptproj = Quad1.Value(p2d.X(),p2d.Y()); | |
1805 | } | |
1806 | else { | |
1807 | ptproj = Quad2.Value(p2d.X(),p2d.Y()); | |
1808 | } | |
1809 | if ((toproj.Distance(ptproj) <=100*TolArc) && | |
1810 | (paramproj >= paramf) && (paramproj <= paraml)){ | |
1811 | newptvtx = Ptvtx; | |
1812 | newptvtx.SetParameter(paramproj); | |
1813 | keeppoint = Standard_True; | |
1814 | seq_Pnt3d.Append(toproj); | |
1815 | seq_Real.Append(paramproj); | |
1816 | ||
1817 | //-- verifier que si la restriction arcref est trouvee, elle porte ce vertex | |
1818 | for (int ri=1; ri<=Nblin; ri++) { | |
1819 | const Handle(IntPatch_Line)& slinri = slin(ri); | |
1820 | if (slinri->ArcType() == IntPatch_Restriction) { | |
1821 | if(OnFirst && (*((Handle(IntPatch_RLine)*)&slinri))->IsArcOnS1()) { | |
1822 | if(arcref == (*((Handle(IntPatch_RLine)*)&slinri))->ArcOnS1()) { | |
1823 | (*((Handle(IntPatch_RLine)*)&slinri))->AddVertex(newptvtx); | |
1824 | //printf("\n ImpImpIntersection_0.gxx CAS1 \n"); | |
1825 | } | |
1826 | } | |
1827 | else if(OnFirst==Standard_False && (*((Handle(IntPatch_RLine)*)&slinri))->IsArcOnS2()) { | |
1828 | if(arcref == (*((Handle(IntPatch_RLine)*)&slinri))->ArcOnS2()) { | |
1829 | (*((Handle(IntPatch_RLine)*)&slinri))->AddVertex(newptvtx); | |
1830 | //printf("\n ImpImpIntersection_0.gxx CAS2 \n"); | |
1831 | } | |
1832 | } | |
1833 | } | |
1834 | } | |
1835 | // -- -------------------------------------------------- | |
1836 | } | |
1837 | } | |
1838 | } | |
1839 | else { | |
1840 | keeppoint = Standard_True; | |
1841 | newptvtx = Ptvtx; | |
1842 | newptvtx.SetParameter(seq_Real(jj)); | |
1843 | } | |
1844 | if (keeppoint) { | |
1845 | Ptvtx.SetMultiple(Standard_True); | |
1846 | newptvtx.SetMultiple(Standard_True); | |
1847 | ||
1848 | if (typ2 == IntPatch_Analytic) { | |
1849 | (*((Handle(IntPatch_ALine)*)&slinj))->Replace(k,Ptvtx); | |
1850 | } | |
1851 | else { | |
1852 | (*((Handle(IntPatch_GLine)*)&slinj))->Replace(k,Ptvtx); | |
1853 | } | |
1854 | ||
1855 | if (Ptvtx.IsOnDomS1() || Ptvtx.IsOnDomS2()) { | |
1856 | ||
1857 | arcref->D1(newptvtx.ParameterOnLine(),p2d,d2d); | |
1858 | ||
1859 | if (OnFirst) { // donc OnDomS2 | |
1860 | Quad1.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v); | |
1861 | tgrest.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
1862 | ||
1863 | const Handle(Adaptor2d_HCurve2d)& thearc = Ptvtx.ArcOnS2(); | |
1864 | thearc->D1(Ptvtx.ParameterOnArc2(),p2d,d2d); | |
1865 | Quad2.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v); | |
1866 | tgarc.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
1867 | norm = d1u.Crossed(d1v); //Quad2.Normale(valpt); | |
1868 | if(norm.SquareMagnitude()<1e-16) { | |
1869 | TRest.SetValue(Standard_True,IntSurf_Undecided); | |
1870 | TArc.SetValue(Standard_True,IntSurf_Undecided); | |
1871 | } | |
1872 | else { | |
1873 | IntSurf::MakeTransition(tgrest,tgarc,norm,TRest,TArc); | |
1874 | } | |
1875 | newptvtx.SetArc(Standard_False,thearc, | |
1876 | Ptvtx.ParameterOnArc2(),TRest,TArc); | |
1877 | ||
1878 | } | |
1879 | else { // donc OnDomS1 | |
1880 | Quad2.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v); | |
1881 | tgrest.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
1882 | ||
1883 | const Handle(Adaptor2d_HCurve2d)& thearc = Ptvtx.ArcOnS1(); | |
1884 | thearc->D1(Ptvtx.ParameterOnArc1(),p2d,d2d); | |
1885 | Quad1.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v); | |
1886 | tgarc.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v); | |
1887 | norm = d1u.Crossed(d1v); //Quad1.Normale(valpt); | |
1888 | if(norm.SquareMagnitude()<1e-16) { | |
1889 | TRest.SetValue(Standard_True,IntSurf_Undecided); | |
1890 | TArc.SetValue(Standard_True,IntSurf_Undecided); | |
1891 | } | |
1892 | else { | |
1893 | IntSurf::MakeTransition(tgrest,tgarc,norm,TRest,TArc); | |
1894 | } | |
1895 | newptvtx.SetArc(Standard_True,thearc, | |
1896 | Ptvtx.ParameterOnArc1(),TRest,TArc); | |
1897 | } | |
1898 | } //-- if (Ptvtx.IsOnDomS1() || Ptvtx.IsOnDomS2()) | |
1899 | ||
1900 | (*((Handle(IntPatch_RLine)*)&slini))->AddVertex(newptvtx); | |
1901 | ||
1902 | } //-- if (keeppoint) | |
1903 | } //-- if ((OnFirst && !Ptvtx.IsOnDomS1())||(!OnFirst && !Ptvtx.IsOnDomS2())) | |
1904 | } //-- boucle sur les vertex | |
1905 | } //-- if (typ2 != IntPatch_Restriction) | |
1906 | } //-- for (j=1; j<=Nblin; j++) | |
1907 | } //-- if (typ1 == IntPatch_Restriction) | |
1908 | } //-- for (i=1; i<=Nblin; i++) | |
1909 | } |