Commit | Line | Data |
---|---|---|
973c2be1 | 1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 2 | // |
973c2be1 | 3 | // This file is part of Open CASCADE Technology software library. |
b311480e | 4 | // |
d5f74e42 | 5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
9 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 10 | // |
973c2be1 | 11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. | |
7fd59977 | 13 | |
7fd59977 | 14 | |
42cf5bc1 | 15 | #include <Adaptor2d_HCurve2d.hxx> |
16 | #include <Adaptor2d_HLine2d.hxx> | |
17 | #include <Adaptor3d_HSurface.hxx> | |
18 | #include <Adaptor3d_HVertex.hxx> | |
19 | #include <Adaptor3d_TopolTool.hxx> | |
20 | #include <GeomAdaptor_Surface.hxx> | |
7fd59977 | 21 | #include <gp_Cone.hxx> |
22 | #include <gp_Pnt.hxx> | |
42cf5bc1 | 23 | #include <gp_Pnt2d.hxx> |
7fd59977 | 24 | #include <gp_Trsf.hxx> |
42cf5bc1 | 25 | #include <Precision.hxx> |
26 | #include <Standard_DomainError.hxx> | |
27 | #include <Standard_NotImplemented.hxx> | |
28 | #include <Standard_Type.hxx> | |
7fd59977 | 29 | |
25e59720 | 30 | IMPLEMENT_STANDARD_RTTIEXT(Adaptor3d_TopolTool,Standard_Transient) |
92efcf78 | 31 | |
7c4e9501 | 32 | #define myInfinite Precision::Infinite() |
7fd59977 | 33 | |
34 | static void GetConeApexParam(const gp_Cone& C, Standard_Real& U, Standard_Real& V) | |
35 | { | |
36 | const gp_Ax3& Pos = C.Position(); | |
37 | Standard_Real Radius = C.RefRadius(); | |
38 | Standard_Real SAngle = C.SemiAngle(); | |
39 | const gp_Pnt& P = C.Apex(); | |
40 | ||
41 | gp_Trsf T; | |
42 | T.SetTransformation (Pos); | |
43 | gp_Pnt Ploc = P.Transformed (T); | |
44 | ||
45 | if(Ploc.X() ==0.0 && Ploc.Y()==0.0 ) { | |
46 | U = 0.0; | |
47 | } | |
48 | else if ( -Radius > Ploc.Z()* Tan(SAngle) ) { | |
0d969553 | 49 | // the point is at the `wrong` side of the apex |
7fd59977 | 50 | U = atan2(-Ploc.Y(), -Ploc.X()); |
51 | } | |
52 | else { | |
53 | U = atan2(Ploc.Y(),Ploc.X()); | |
54 | } | |
c6541a0c | 55 | if (U < -1.e-16) U += (M_PI+M_PI); |
7fd59977 | 56 | else if (U < 0) U = 0; |
57 | ||
58 | V = sin(SAngle) * ( Ploc.X() * cos(U) + Ploc.Y() * sin(U) - Radius) | |
59 | + cos(SAngle) * Ploc.Z(); | |
60 | } | |
61 | ||
62 | ||
566f8441 | 63 | Adaptor3d_TopolTool::Adaptor3d_TopolTool () : myNbSamplesU(-1),nbRestr(0),idRestr(0) |
7fd59977 | 64 | |
65 | { | |
66 | } | |
67 | ||
68 | Adaptor3d_TopolTool::Adaptor3d_TopolTool (const Handle(Adaptor3d_HSurface)& S) | |
69 | { | |
70 | Initialize(S); | |
71 | } | |
72 | ||
73 | ||
74 | void Adaptor3d_TopolTool::Initialize () | |
75 | { | |
9775fa61 | 76 | throw Standard_NotImplemented("Adaptor3d_TopolTool::Initialize ()"); |
7fd59977 | 77 | } |
78 | ||
79 | void Adaptor3d_TopolTool::Initialize (const Handle(Adaptor3d_HSurface)& S) | |
80 | { | |
81 | Standard_Real pinf,psup,deltap; | |
82 | //Adaptor2d_Line2d * Line2dPtr ; | |
83 | ||
84 | myNbSamplesU=-1; | |
0d969553 | 85 | Uinf = S->FirstUParameter(); // where UIntervalFirst ?? |
7fd59977 | 86 | Vinf = S->FirstVParameter(); |
87 | Usup = S->LastUParameter(); | |
88 | Vsup = S->LastVParameter(); | |
89 | nbRestr = 0; | |
90 | idRestr = 0; | |
91 | ||
92 | Standard_Boolean Uinfinfinite = Precision::IsNegativeInfinite(Uinf); | |
93 | Standard_Boolean Usupinfinite = Precision::IsPositiveInfinite(Usup); | |
94 | Standard_Boolean Vinfinfinite = Precision::IsNegativeInfinite(Vinf); | |
95 | Standard_Boolean Vsupinfinite = Precision::IsPositiveInfinite(Vsup); | |
96 | ||
97 | if (! Vinfinfinite) { | |
98 | deltap = Min(Usup-Uinf,2.*myInfinite); | |
99 | if (Uinf >= -myInfinite){ | |
100 | pinf = Uinf; | |
101 | psup = pinf + deltap; | |
102 | } | |
103 | else if (Usup <= myInfinite) { | |
104 | psup = Usup; | |
105 | pinf = psup - deltap; | |
106 | } | |
107 | else { | |
108 | pinf = -myInfinite; | |
109 | psup = myInfinite; | |
110 | } | |
111 | ||
112 | // Line2dPtr = new Adaptor2d_Line2d(gp_Pnt2d(0.,Vinf),gp_Dir2d(1.,0.),pinf,psup); | |
113 | //myRestr[nbRestr] = new Adaptor2d_HLine2d(*Line2dPtr); | |
114 | myRestr[nbRestr] = new Adaptor2d_HLine2d(Adaptor2d_Line2d(gp_Pnt2d(0.,Vinf),gp_Dir2d(1.,0.),pinf,psup)); | |
115 | nbRestr++; | |
116 | } | |
117 | ||
118 | if (!Usupinfinite) { | |
119 | deltap = Min(Vsup-Vinf,2.*myInfinite); | |
120 | if (Vinf >= -myInfinite){ | |
121 | pinf = Vinf; | |
122 | psup = pinf + deltap; | |
123 | } | |
124 | else if (Vsup <= myInfinite) { | |
125 | psup = Vsup; | |
126 | pinf = psup - deltap; | |
127 | } | |
128 | else { | |
129 | pinf = -myInfinite; | |
130 | psup = myInfinite; | |
131 | } | |
132 | ||
133 | ||
134 | ||
135 | //Line2dPtr = new Adaptor2d_Line2d(gp_Pnt2d(Usup,0.),gp_Dir2d(0.,1.),pinf,psup); | |
136 | //myRestr[nbRestr] = new Adaptor2d_HLine2d(*Line2dPtr); | |
137 | myRestr[nbRestr] = new Adaptor2d_HLine2d(Adaptor2d_Line2d(gp_Pnt2d(Usup,0.),gp_Dir2d(0.,1.),pinf,psup)); | |
138 | nbRestr++; | |
139 | } | |
140 | ||
141 | if (!Vsupinfinite) { | |
142 | deltap = Min(Usup-Uinf,2.*myInfinite); | |
143 | if (-Usup >= -myInfinite){ | |
144 | pinf = -Usup; | |
145 | psup = pinf + deltap; | |
146 | } | |
147 | else if (-Uinf <= myInfinite) { | |
148 | psup = -Uinf; | |
149 | pinf = psup - deltap; | |
150 | } | |
151 | else { | |
152 | pinf = -myInfinite; | |
153 | psup = myInfinite; | |
154 | } | |
155 | ||
156 | ||
157 | //Line2dPtr = new Adaptor2d_Line2d(gp_Pnt2d(0.,Vsup),gp_Dir2d(-1.,0.),pinf,psup); | |
158 | //myRestr[nbRestr] = new Adaptor2d_HLine2d(*Line2dPtr); | |
159 | myRestr[nbRestr] = new Adaptor2d_HLine2d(Adaptor2d_Line2d(gp_Pnt2d(0.,Vsup),gp_Dir2d(-1.,0.),pinf,psup)); | |
160 | nbRestr++; | |
161 | } | |
162 | ||
163 | if (!Uinfinfinite) { | |
164 | deltap = Min(Vsup-Vinf,2.*myInfinite); | |
165 | if (-Vsup >= -myInfinite){ | |
166 | pinf = -Vsup; | |
167 | psup = pinf + deltap; | |
168 | } | |
169 | else if (-Vinf <= myInfinite) { | |
170 | psup = -Vinf; | |
171 | pinf = psup - deltap; | |
172 | } | |
173 | else { | |
174 | pinf = -myInfinite; | |
175 | psup = myInfinite; | |
176 | } | |
177 | ||
178 | //Line2dPtr = new Adaptor2d_Line2d(gp_Pnt2d(Uinf,0.),gp_Dir2d(0.,-1),pinf,psup); | |
179 | //myRestr[nbRestr] = new Adaptor2d_HLine2d(*Line2dPtr); | |
180 | myRestr[nbRestr] = new Adaptor2d_HLine2d(Adaptor2d_Line2d(gp_Pnt2d(Uinf,0.),gp_Dir2d(0.,-1),pinf,psup)); | |
181 | nbRestr++; | |
182 | } | |
183 | ||
184 | myS = S; | |
185 | ||
186 | if(nbRestr == 2 && S->GetType() == GeomAbs_Cone ) { | |
187 | Standard_Real U = 0., V = 0.; | |
188 | GetConeApexParam(S->Cone(),U,V); | |
189 | ||
190 | deltap = Min(Usup-Uinf,2.*myInfinite); | |
191 | if (Uinf >= -myInfinite){ | |
192 | pinf = Uinf; | |
193 | psup = pinf + deltap; | |
194 | } | |
195 | else if (Usup <= myInfinite) { | |
196 | psup = Usup; | |
197 | pinf = psup - deltap; | |
198 | } | |
199 | else { | |
200 | pinf = -myInfinite; | |
201 | psup = myInfinite; | |
202 | } | |
203 | ||
204 | //Line2dPtr = new Adaptor2d_Line2d(gp_Pnt2d(U,V),gp_Dir2d(1.,0.),pinf,psup); | |
205 | //myRestr[nbRestr] = new Adaptor2d_HLine2d(*Line2dPtr); | |
206 | myRestr[nbRestr] = new Adaptor2d_HLine2d(Adaptor2d_Line2d(gp_Pnt2d(U,V),gp_Dir2d(1.,0.),pinf,psup)); | |
207 | nbRestr++; | |
208 | } | |
209 | } | |
210 | ||
211 | ||
212 | void Adaptor3d_TopolTool::Init () | |
213 | { | |
214 | idRestr = 0; | |
215 | } | |
216 | ||
217 | ||
218 | Standard_Boolean Adaptor3d_TopolTool::More () | |
219 | { | |
220 | return (idRestr < nbRestr); | |
221 | } | |
222 | ||
223 | Handle(Adaptor2d_HCurve2d) Adaptor3d_TopolTool::Value () | |
224 | { | |
9775fa61 | 225 | if (idRestr >= nbRestr) {throw Standard_DomainError();} |
7fd59977 | 226 | return myRestr[idRestr]; |
227 | } | |
228 | ||
229 | void Adaptor3d_TopolTool::Next () | |
230 | { | |
231 | idRestr++; | |
232 | } | |
233 | ||
234 | ||
235 | void Adaptor3d_TopolTool::Initialize(const Handle(Adaptor2d_HCurve2d)& C) | |
236 | { | |
237 | nbVtx = 0; | |
238 | idVtx = 0; | |
239 | Standard_Real theUinf,theUsup; | |
240 | theUinf = C->FirstParameter(); | |
241 | theUsup = C->LastParameter(); | |
242 | // if (!Precision::IsNegativeInfinite(theUinf)) { | |
243 | if (theUinf > -myInfinite) { | |
244 | myVtx[nbVtx] = new Adaptor3d_HVertex(C->Value(theUinf),TopAbs_FORWARD,1.e-8); | |
245 | nbVtx++; | |
246 | } | |
247 | // if (!Precision::IsPositiveInfinite(theUsup)) { | |
248 | if (theUsup < myInfinite) { | |
249 | myVtx[nbVtx] = new Adaptor3d_HVertex(C->Value(theUsup),TopAbs_REVERSED,1.e-8); | |
250 | nbVtx++; | |
251 | } | |
252 | } | |
253 | ||
254 | ||
255 | void Adaptor3d_TopolTool::InitVertexIterator () | |
256 | { | |
257 | idVtx = 0; | |
258 | } | |
259 | ||
260 | ||
261 | Standard_Boolean Adaptor3d_TopolTool::MoreVertex () | |
262 | { | |
263 | return (idVtx < nbVtx); | |
264 | } | |
265 | ||
266 | ||
267 | Handle(Adaptor3d_HVertex) Adaptor3d_TopolTool::Vertex () | |
268 | { | |
9775fa61 | 269 | if (idVtx >= nbVtx) {throw Standard_DomainError();} |
7fd59977 | 270 | return myVtx[idVtx]; |
271 | } | |
272 | ||
273 | void Adaptor3d_TopolTool::NextVertex () | |
274 | { | |
275 | idVtx++; | |
276 | } | |
277 | ||
278 | ||
279 | TopAbs_State Adaptor3d_TopolTool::Classify(const gp_Pnt2d& P, | |
280 | const Standard_Real Tol, | |
281 | const Standard_Boolean ) | |
282 | // const Standard_Boolean RecadreOnPeriodic) | |
283 | { | |
284 | ||
285 | Standard_Real U = P.X(); | |
286 | Standard_Real V = P.Y(); | |
287 | ||
288 | if (nbRestr == 4) { | |
289 | if ((U < Uinf - Tol) || (U > Usup + Tol) || | |
7c4e9501 | 290 | (V < Vinf - Tol) || (V > Vsup + Tol)) { |
291 | return TopAbs_OUT; | |
7fd59977 | 292 | } |
293 | if ((Abs(U - Uinf) <= Tol) || (Abs(U - Usup) <= Tol) || | |
7c4e9501 | 294 | (Abs(V - Vinf) <= Tol) || (Abs(V - Vsup) <= Tol)) { |
295 | return TopAbs_ON; | |
7fd59977 | 296 | } |
297 | return TopAbs_IN; | |
298 | } | |
299 | else if (nbRestr == 0) { | |
300 | return TopAbs_IN; | |
301 | } | |
302 | else { | |
303 | Standard_Boolean dansu,dansv,surumin,surumax,survmin,survmax; | |
304 | if (Precision::IsNegativeInfinite(Uinf) && | |
7c4e9501 | 305 | Precision::IsPositiveInfinite(Usup)) { |
7fd59977 | 306 | dansu = Standard_True; |
307 | surumin = surumax = Standard_False; | |
308 | } | |
309 | else if (Precision::IsNegativeInfinite(Uinf)) { | |
310 | surumin = Standard_False; | |
311 | if (U >= Usup+Tol) { | |
7c4e9501 | 312 | dansu = Standard_False; |
313 | surumax = Standard_False; | |
7fd59977 | 314 | } |
315 | else { | |
7c4e9501 | 316 | dansu = Standard_True; |
317 | surumax = Standard_False; | |
318 | if (Abs(U-Usup)<=Tol) { | |
319 | surumax = Standard_True; | |
320 | } | |
7fd59977 | 321 | } |
322 | } | |
323 | else if (Precision::IsPositiveInfinite(Usup)) { | |
324 | surumax = Standard_False; | |
325 | if (U < Uinf-Tol) { | |
7c4e9501 | 326 | dansu = Standard_False; |
327 | surumin = Standard_False; | |
7fd59977 | 328 | } |
329 | else { | |
7c4e9501 | 330 | dansu = Standard_True; |
331 | surumin = Standard_False; | |
332 | if (Abs(U-Uinf)<=Tol) { | |
333 | surumin = Standard_True; | |
334 | } | |
7fd59977 | 335 | } |
336 | } | |
337 | else { | |
338 | if ((U < Uinf - Tol) || (U > Usup + Tol)) { | |
7c4e9501 | 339 | surumin = surumax = dansu = Standard_False; |
7fd59977 | 340 | } |
341 | else { | |
7c4e9501 | 342 | dansu = Standard_True; |
343 | surumin = surumax = Standard_False; | |
344 | if (Abs(U-Uinf)<=Tol) { | |
345 | surumin = Standard_True; | |
346 | } | |
347 | else if (Abs(U-Usup)<=Tol) { | |
348 | surumax = Standard_True; | |
349 | } | |
7fd59977 | 350 | } |
351 | } | |
352 | ||
353 | if (Precision::IsNegativeInfinite(Vinf) && | |
7c4e9501 | 354 | Precision::IsPositiveInfinite(Vsup)) { |
7fd59977 | 355 | dansv = Standard_True; |
356 | survmin = survmax = Standard_False; | |
357 | } | |
358 | else if (Precision::IsNegativeInfinite(Vinf)) { | |
359 | survmin = Standard_False; | |
360 | if (V > Vsup+Tol) { | |
7c4e9501 | 361 | dansv = Standard_False; |
362 | survmax = Standard_False; | |
7fd59977 | 363 | } |
364 | else { | |
7c4e9501 | 365 | dansv = Standard_True; |
366 | survmax = Standard_False; | |
367 | if (Abs(V-Vsup)<=Tol) { | |
368 | survmax = Standard_True; | |
369 | } | |
7fd59977 | 370 | } |
371 | } | |
372 | else if (Precision::IsPositiveInfinite(Vsup)) { | |
373 | survmax = Standard_False; | |
374 | if (V < Vinf-Tol) { | |
7c4e9501 | 375 | dansv = Standard_False; |
376 | survmin = Standard_False; | |
7fd59977 | 377 | } |
378 | else { | |
7c4e9501 | 379 | dansv = Standard_True; |
380 | survmin = Standard_False; | |
381 | if (Abs(V-Vinf)<=Tol) { | |
382 | survmin = Standard_True; | |
383 | } | |
7fd59977 | 384 | } |
385 | } | |
386 | else { | |
387 | if ((V < Vinf - Tol) || (V > Vsup + Tol)) { | |
7c4e9501 | 388 | survmin = survmax = dansv = Standard_False; |
7fd59977 | 389 | } |
390 | else { | |
7c4e9501 | 391 | dansv = Standard_True; |
392 | survmin = survmax = Standard_False; | |
393 | if (Abs(V-Vinf)<=Tol) { | |
394 | survmin = Standard_True; | |
395 | } | |
396 | else if (Abs(V-Vsup)<=Tol) { | |
397 | survmax = Standard_True; | |
398 | } | |
7fd59977 | 399 | } |
400 | } | |
401 | ||
402 | if (!dansu || !dansv) { | |
403 | return TopAbs_OUT; | |
404 | } | |
405 | if (surumin || survmin || surumax || survmax) { | |
406 | return TopAbs_ON; | |
407 | } | |
408 | return TopAbs_IN; | |
409 | } | |
410 | } | |
411 | ||
412 | ||
413 | ||
414 | Standard_Boolean Adaptor3d_TopolTool::IsThePointOn(const gp_Pnt2d& P, | |
415 | const Standard_Real Tol, | |
416 | const Standard_Boolean ) | |
417 | // const Standard_Boolean RecadreOnPeriodic) | |
418 | { | |
419 | ||
420 | Standard_Real U = P.X(); | |
421 | Standard_Real V = P.Y(); | |
422 | ||
423 | if (nbRestr == 4) { | |
424 | if ((U < Uinf - Tol) || (U > Usup + Tol) || | |
425 | (V < Vinf - Tol) || (V > Vsup + Tol)) { | |
426 | return(Standard_False); | |
427 | } | |
428 | if ((Abs(U - Uinf) <= Tol) || (Abs(U - Usup) <= Tol) || | |
429 | (Abs(V - Vinf) <= Tol) || (Abs(V - Vsup) <= Tol)) { | |
430 | return(Standard_True); | |
431 | } | |
432 | return(Standard_False); | |
433 | } | |
434 | else if (nbRestr == 0) { | |
435 | return(Standard_False); | |
436 | } | |
437 | else { | |
438 | Standard_Boolean dansu,dansv,surumin,surumax,survmin,survmax; | |
439 | if (Precision::IsNegativeInfinite(Uinf) && | |
440 | Precision::IsPositiveInfinite(Usup)) { | |
441 | dansu = Standard_True; | |
442 | surumin = surumax = Standard_False; | |
443 | } | |
444 | else if (Precision::IsNegativeInfinite(Uinf)) { | |
445 | surumin = Standard_False; | |
446 | if (U >= Usup+Tol) { | |
447 | dansu = Standard_False; | |
448 | surumax = Standard_False; | |
449 | } | |
450 | else { | |
451 | dansu = Standard_True; | |
452 | surumax = Standard_False; | |
453 | if (Abs(U-Usup)<=Tol) { | |
454 | surumax = Standard_True; | |
455 | } | |
456 | } | |
457 | } | |
458 | else if (Precision::IsPositiveInfinite(Usup)) { | |
459 | surumax = Standard_False; | |
460 | if (U < Uinf-Tol) { | |
461 | dansu = Standard_False; | |
462 | surumin = Standard_False; | |
463 | } | |
464 | else { | |
465 | dansu = Standard_True; | |
466 | surumin = Standard_False; | |
467 | if (Abs(U-Uinf)<=Tol) { | |
468 | surumin = Standard_True; | |
469 | } | |
470 | } | |
471 | } | |
472 | else { | |
473 | if ((U < Uinf - Tol) || (U > Usup + Tol)) { | |
474 | surumin = surumax = dansu = Standard_False; | |
475 | } | |
476 | else { | |
477 | dansu = Standard_True; | |
478 | surumin = surumax = Standard_False; | |
479 | if (Abs(U-Uinf)<=Tol) { | |
480 | surumin = Standard_True; | |
481 | } | |
482 | else if (Abs(U-Usup)<=Tol) { | |
483 | surumax = Standard_True; | |
484 | } | |
485 | } | |
486 | } | |
487 | ||
488 | if (Precision::IsNegativeInfinite(Vinf) && | |
489 | Precision::IsPositiveInfinite(Vsup)) { | |
490 | dansv = Standard_True; | |
491 | survmin = survmax = Standard_False; | |
492 | } | |
493 | else if (Precision::IsNegativeInfinite(Vinf)) { | |
494 | survmin = Standard_False; | |
495 | if (V > Vsup+Tol) { | |
496 | dansv = Standard_False; | |
497 | survmax = Standard_False; | |
498 | } | |
499 | else { | |
500 | dansv = Standard_True; | |
501 | survmax = Standard_False; | |
502 | if (Abs(V-Vsup)<=Tol) { | |
503 | survmax = Standard_True; | |
504 | } | |
505 | } | |
506 | } | |
507 | else if (Precision::IsPositiveInfinite(Vsup)) { | |
508 | survmax = Standard_False; | |
509 | if (V < Vinf-Tol) { | |
510 | dansv = Standard_False; | |
511 | survmin = Standard_False; | |
512 | } | |
513 | else { | |
514 | dansv = Standard_True; | |
515 | survmin = Standard_False; | |
516 | if (Abs(V-Vinf)<=Tol) { | |
517 | survmin = Standard_True; | |
518 | } | |
519 | } | |
520 | } | |
521 | else { | |
522 | if ((V < Vinf - Tol) || (V > Vsup + Tol)) { | |
523 | survmin = survmax = dansv = Standard_False; | |
524 | } | |
525 | else { | |
526 | dansv = Standard_True; | |
527 | survmin = survmax = Standard_False; | |
528 | if (Abs(V-Vinf)<=Tol) { | |
529 | survmin = Standard_True; | |
530 | } | |
531 | else if (Abs(V-Vsup)<=Tol) { | |
532 | survmax = Standard_True; | |
533 | } | |
534 | } | |
535 | } | |
536 | ||
537 | if (!dansu || !dansv) { | |
538 | return(Standard_False); | |
539 | } | |
540 | if (surumin || survmin || surumax || survmax) { | |
541 | return(Standard_True); | |
542 | } | |
8c2d3314 | 543 | return Standard_False; |
7fd59977 | 544 | } |
545 | } | |
546 | ||
547 | ||
548 | TopAbs_Orientation Adaptor3d_TopolTool::Orientation | |
549 | (const Handle(Adaptor2d_HCurve2d)&) | |
550 | { | |
551 | return TopAbs_FORWARD; | |
552 | } | |
553 | ||
554 | TopAbs_Orientation Adaptor3d_TopolTool::Orientation | |
555 | (const Handle(Adaptor3d_HVertex)& V) | |
556 | { | |
557 | return V->Orientation(); | |
558 | } | |
559 | ||
560 | Standard_Boolean Adaptor3d_TopolTool::Identical | |
561 | (const Handle(Adaptor3d_HVertex)& V1, | |
562 | const Handle(Adaptor3d_HVertex)& V2) | |
563 | { | |
564 | return V1->IsSame(V2); | |
565 | } | |
566 | ||
567 | ||
568 | //-- ============================================================ | |
569 | //-- m e t h o d e s u t i l i s e e s p o u r l e s | |
570 | //-- s a m p l e s | |
571 | //-- ============================================================ | |
572 | #include <TColgp_Array2OfPnt.hxx> | |
573 | #include <Geom_BezierSurface.hxx> | |
574 | #include <Geom_BSplineSurface.hxx> | |
575 | #include <TColStd_Array1OfReal.hxx> | |
576 | #include <TColStd_Array1OfBoolean.hxx> | |
577 | //#include <gce_MakeLin.hxx> | |
578 | #include <gp_Lin.hxx> | |
579 | #include <gp_Dir.hxx> | |
580 | #include <gp_Vec.hxx> | |
581 | ||
582 | #define myMinPnts 4 //Absolut possible minimum of sample points | |
583 | //Restriction of IntPolyh | |
584 | ||
585 | ||
586 | static void Analyse(const TColgp_Array2OfPnt& array2, | |
587 | const Standard_Integer nbup, | |
588 | const Standard_Integer nbvp, | |
589 | Standard_Integer& myNbSamplesU, | |
590 | Standard_Integer& myNbSamplesV) { | |
591 | gp_Vec Vi,Vip1; | |
592 | Standard_Integer sh,nbch,i,j; | |
593 | ||
594 | sh = 1; | |
595 | nbch = 0; | |
596 | if(nbvp>2) { | |
597 | for(i=2;i<nbup;i++) { | |
598 | const gp_Pnt& A=array2.Value(i,1); | |
599 | const gp_Pnt& B=array2.Value(i,2); | |
600 | const gp_Pnt& C=array2.Value(i,3); | |
601 | Vi.SetCoord(C.X()-B.X()-B.X()+A.X(), | |
602 | C.Y()-B.Y()-B.Y()+A.Y(), | |
603 | C.Z()-B.Z()-B.Z()+A.Z()); | |
604 | Standard_Integer locnbch=0; | |
0d969553 | 605 | for(j=3; j<nbvp;j++) { //-- try |
7fd59977 | 606 | const gp_Pnt& A1=array2.Value(i,j-1); |
607 | const gp_Pnt& B1=array2.Value(i,j); | |
608 | const gp_Pnt& C1=array2.Value(i,j+1); | |
609 | Vip1.SetCoord(C1.X()-B1.X()-B1.X()+A1.X(), | |
610 | C1.Y()-B1.Y()-B1.Y()+A1.Y(), | |
611 | C1.Z()-B1.Z()-B1.Z()+A1.Z()); | |
612 | Standard_Real pd = Vi.Dot(Vip1); | |
613 | Vi=Vip1; | |
614 | if(pd>1.0e-7 || pd<-1.0e-7) { | |
615 | if(pd>0) { if(sh==-1) { sh=1; locnbch++; } } | |
616 | else { if(sh==1) { sh=-1; locnbch++; } } | |
617 | } | |
618 | } | |
619 | if(locnbch>nbch) { | |
620 | nbch=locnbch; | |
621 | } | |
622 | } | |
623 | } | |
624 | myNbSamplesV = nbch+5; | |
625 | ||
626 | nbch=0; | |
627 | if(nbup>2) { | |
628 | for(j=2;j<nbvp;j++) { | |
629 | const gp_Pnt& A=array2.Value(1,j); | |
630 | const gp_Pnt& B=array2.Value(2,j); | |
631 | const gp_Pnt& C=array2.Value(3,j); | |
632 | Vi.SetCoord(C.X()-B.X()-B.X()+A.X(), | |
633 | C.Y()-B.Y()-B.Y()+A.Y(), | |
634 | C.Z()-B.Z()-B.Z()+A.Z()); | |
635 | Standard_Integer locnbch=0; | |
0d969553 | 636 | for(i=3; i<nbup;i++) { //-- try |
7fd59977 | 637 | const gp_Pnt& A1=array2.Value(i-1,j); |
638 | const gp_Pnt& B1=array2.Value(i,j); | |
639 | const gp_Pnt& C1=array2.Value(i+1,j); | |
640 | Vip1.SetCoord(C1.X()-B1.X()-B1.X()+A1.X(), | |
641 | C1.Y()-B1.Y()-B1.Y()+A1.Y(), | |
642 | C1.Z()-B1.Z()-B1.Z()+A1.Z()); | |
643 | Standard_Real pd = Vi.Dot(Vip1); | |
644 | Vi=Vip1; | |
645 | if(pd>1.0e-7 || pd<-1.0e-7) { | |
646 | if(pd>0) { if(sh==-1) { sh=1; locnbch++; } } | |
647 | else { if(sh==1) { sh=-1; locnbch++; } } | |
648 | } | |
649 | } | |
650 | if(locnbch>nbch) nbch=locnbch; | |
651 | } | |
652 | } | |
653 | myNbSamplesU = nbch+5; | |
654 | } | |
655 | ||
656 | ||
657 | void Adaptor3d_TopolTool::ComputeSamplePoints() { | |
658 | Standard_Real uinf,usup,vinf,vsup; | |
659 | uinf = myS->FirstUParameter(); usup = myS->LastUParameter(); | |
660 | vinf = myS->FirstVParameter(); vsup = myS->LastVParameter(); | |
661 | if (usup < uinf) { Standard_Real temp=uinf; uinf=usup; usup=temp; } | |
662 | if (vsup < vinf) { Standard_Real temp=vinf; vinf=vsup; vsup=temp; } | |
663 | if (uinf == RealFirst() && usup == RealLast()) { uinf=-1.e5; usup=1.e5; } | |
664 | else if (uinf == RealFirst()) { uinf=usup-2.e5; } | |
665 | else if (usup == RealLast()) { usup=uinf+2.e5; } | |
666 | ||
667 | if (vinf == RealFirst() && vsup == RealLast()) { vinf=-1.e5; vsup=1.e5; } | |
668 | else if (vinf == RealFirst()) { vinf=vsup-2.e5; } | |
669 | else if (vsup == RealLast()) { vsup=vinf+2.e5; } | |
670 | ||
671 | Standard_Integer nbsu,nbsv; | |
672 | GeomAbs_SurfaceType typS = myS->GetType(); | |
673 | switch(typS) { | |
674 | case GeomAbs_Plane: { nbsv=2; nbsu=2; } break; | |
675 | case GeomAbs_BezierSurface: { nbsv=3+myS->NbVPoles(); nbsu=3+myS->NbUPoles(); } break; | |
676 | case GeomAbs_BSplineSurface: { | |
677 | nbsv = myS->NbVKnots(); nbsv*= myS->VDegree(); if(nbsv < 4) nbsv=4; | |
678 | nbsu = myS->NbUKnots(); nbsu*= myS->UDegree(); if(nbsu < 4) nbsu=4; | |
679 | } | |
680 | break; | |
681 | case GeomAbs_Cylinder: | |
682 | case GeomAbs_Cone: | |
683 | case GeomAbs_Sphere: | |
684 | case GeomAbs_Torus: | |
685 | case GeomAbs_SurfaceOfRevolution: | |
686 | case GeomAbs_SurfaceOfExtrusion: { nbsv = 15; nbsu=15; } break; | |
687 | default: { nbsu = 10; nbsv=10; } break; | |
688 | } | |
689 | ||
0d969553 | 690 | //-- If the number of points is too great... analyze |
7fd59977 | 691 | //-- |
692 | //-- | |
693 | ||
694 | if(nbsu<6) nbsu=6; | |
695 | if(nbsv<6) nbsv=6; | |
696 | ||
697 | myNbSamplesU = nbsu; | |
698 | myNbSamplesV = nbsv; | |
699 | ||
700 | if(nbsu>8 || nbsv>8) { | |
701 | if(typS == GeomAbs_BSplineSurface) { | |
702 | const Handle(Geom_BSplineSurface)& Bspl = myS->BSpline(); | |
703 | Standard_Integer nbup = Bspl->NbUPoles(); | |
704 | Standard_Integer nbvp = Bspl->NbVPoles(); | |
705 | TColgp_Array2OfPnt array2(1,nbup,1,nbvp); | |
706 | Bspl->Poles(array2); | |
707 | Analyse(array2,nbup,nbvp,myNbSamplesU,myNbSamplesV); | |
708 | } | |
709 | else if(typS == GeomAbs_BezierSurface) { | |
710 | const Handle(Geom_BezierSurface)& Bez = myS->Bezier(); | |
711 | Standard_Integer nbup = Bez->NbUPoles(); | |
712 | Standard_Integer nbvp = Bez->NbVPoles(); | |
713 | TColgp_Array2OfPnt array2(1,nbup,1,nbvp); | |
714 | Bez->Poles(array2); | |
715 | Analyse(array2,nbup,nbvp,myNbSamplesU,myNbSamplesV); | |
716 | } | |
717 | } | |
718 | } | |
719 | ||
720 | Standard_Integer Adaptor3d_TopolTool::NbSamplesU() | |
721 | { | |
722 | if(myNbSamplesU <0) { | |
723 | ComputeSamplePoints(); | |
724 | } | |
725 | return(myNbSamplesU); | |
726 | } | |
727 | ||
728 | Standard_Integer Adaptor3d_TopolTool::NbSamplesV() | |
729 | { | |
730 | if(myNbSamplesU <0) { | |
731 | ComputeSamplePoints(); | |
732 | } | |
733 | return(myNbSamplesV); | |
734 | } | |
735 | ||
736 | Standard_Integer Adaptor3d_TopolTool::NbSamples() | |
737 | { | |
738 | if(myNbSamplesU <0) { | |
739 | ComputeSamplePoints(); | |
740 | } | |
741 | return(myNbSamplesU*myNbSamplesV); | |
742 | } | |
743 | ||
744 | void Adaptor3d_TopolTool::UParameters(TColStd_Array1OfReal& theArray) const | |
745 | { | |
746 | theArray = myUPars->Array1(); | |
747 | } | |
748 | ||
749 | void Adaptor3d_TopolTool::VParameters(TColStd_Array1OfReal& theArray) const | |
750 | { | |
751 | theArray = myVPars->Array1(); | |
752 | } | |
753 | ||
754 | void Adaptor3d_TopolTool::SamplePoint(const Standard_Integer i, | |
755 | gp_Pnt2d& P2d, | |
756 | gp_Pnt& P3d) | |
757 | { | |
758 | Standard_Integer iu, iv; | |
759 | Standard_Real u, v; | |
760 | if (myUPars.IsNull()) | |
761 | { | |
762 | Standard_Real myDU=(Usup-Uinf)/(myNbSamplesU+1); | |
763 | Standard_Real myDV=(Vsup-Vinf)/(myNbSamplesV+1); | |
764 | iv = 1 + i/myNbSamplesU; | |
765 | iu = 1+ i-(iv-1)*myNbSamplesU; | |
766 | u=Uinf+iu*myDU; | |
767 | v=Vinf+iv*myDV; | |
768 | } | |
769 | else | |
770 | { | |
771 | iv = (i-1)/myNbSamplesU + 1; | |
772 | iu = (i-1)%myNbSamplesU + 1; | |
773 | u = myUPars->Value(iu); | |
774 | v = myVPars->Value(iv); | |
775 | } | |
776 | ||
777 | P2d.SetCoord(u,v); | |
778 | P3d = myS->Value(u,v); | |
779 | } | |
780 | ||
781 | ||
782 | ||
783 | Standard_Boolean Adaptor3d_TopolTool::DomainIsInfinite() { | |
784 | if(Precision::IsNegativeInfinite(Uinf)) return(Standard_True); | |
785 | if(Precision::IsPositiveInfinite(Usup)) return(Standard_True); | |
786 | if(Precision::IsNegativeInfinite(Vinf)) return(Standard_True); | |
787 | if(Precision::IsPositiveInfinite(Vsup)) return(Standard_True); | |
788 | return(Standard_False); | |
789 | } | |
7fd59977 | 790 | //======================================================================= |
791 | //function : Edge | |
792 | //purpose : | |
793 | //======================================================================= | |
794 | Standard_Address Adaptor3d_TopolTool::Edge() const | |
795 | { | |
796 | return NULL; | |
797 | } | |
7fd59977 | 798 | //======================================================================= |
799 | //function : Has3d | |
800 | //purpose : | |
801 | //======================================================================= | |
802 | ||
803 | Standard_Boolean Adaptor3d_TopolTool::Has3d() const | |
804 | { | |
805 | return Standard_False; | |
806 | } | |
807 | ||
808 | //======================================================================= | |
809 | //function : Tol3d | |
810 | //purpose : | |
811 | //======================================================================= | |
812 | ||
813 | Standard_Real Adaptor3d_TopolTool::Tol3d(const Handle(Adaptor2d_HCurve2d)&) const | |
814 | { | |
9775fa61 | 815 | throw Standard_DomainError("Adaptor3d_TopolTool: has no 3d representation"); |
7fd59977 | 816 | } |
817 | ||
818 | //======================================================================= | |
819 | //function : Tol3d | |
820 | //purpose : | |
821 | //======================================================================= | |
822 | ||
823 | Standard_Real Adaptor3d_TopolTool::Tol3d(const Handle(Adaptor3d_HVertex)&) const | |
824 | { | |
9775fa61 | 825 | throw Standard_DomainError("Adaptor3d_TopolTool: has no 3d representation"); |
7fd59977 | 826 | } |
827 | ||
828 | //======================================================================= | |
829 | //function : Pnt | |
830 | //purpose : | |
831 | //======================================================================= | |
832 | ||
833 | gp_Pnt Adaptor3d_TopolTool::Pnt(const Handle(Adaptor3d_HVertex)&) const | |
834 | { | |
9775fa61 | 835 | throw Standard_DomainError("Adaptor3d_TopolTool: has no 3d representation"); |
7fd59977 | 836 | } |
837 | ||
838 | ||
839 | //======================================================================= | |
840 | //function : SamplePnts | |
841 | //purpose : | |
842 | //======================================================================= | |
843 | ||
844 | void Adaptor3d_TopolTool::SamplePnts(const Standard_Real theDefl, | |
845 | const Standard_Integer theNUmin, | |
846 | const Standard_Integer theNVmin) | |
847 | { | |
848 | Standard_Real uinf,usup,vinf,vsup; | |
849 | uinf = myS->FirstUParameter(); usup = myS->LastUParameter(); | |
850 | vinf = myS->FirstVParameter(); vsup = myS->LastVParameter(); | |
851 | if (usup < uinf) { Standard_Real temp=uinf; uinf=usup; usup=temp; } | |
852 | if (vsup < vinf) { Standard_Real temp=vinf; vinf=vsup; vsup=temp; } | |
853 | if (uinf == RealFirst() && usup == RealLast()) { uinf=-1.e5; usup=1.e5; } | |
854 | else if (uinf == RealFirst()) { uinf=usup-2.e5; } | |
855 | else if (usup == RealLast()) { usup=uinf+2.e5; } | |
856 | ||
857 | if (vinf == RealFirst() && vsup == RealLast()) { vinf=-1.e5; vsup=1.e5; } | |
858 | else if (vinf == RealFirst()) { vinf=vsup-2.e5; } | |
859 | else if (vsup == RealLast()) { vsup=vinf+2.e5; } | |
860 | ||
861 | // Standard_Integer nbsu,nbsv; | |
862 | GeomAbs_SurfaceType typS = myS->GetType(); | |
863 | // switch(typS) { | |
864 | // case GeomAbs_Plane: { nbsv=2; nbsu=2; } break; | |
865 | // case GeomAbs_BezierSurface: { | |
866 | // nbsv=myS->NbVPoles(); | |
867 | // nbsu=myS->NbUPoles(); | |
868 | // nbsu = Max(nbsu, theNUmin); | |
869 | // nbsv = Max(nbsv, theNVmin); | |
870 | // if(nbsu>8 || nbsv>8) { | |
871 | // const Handle(Geom_BezierSurface)& Bez = myS->Bezier(); | |
872 | // Standard_Integer nbup = Bez->NbUPoles(); | |
873 | // Standard_Integer nbvp = Bez->NbVPoles(); | |
874 | // TColgp_Array2OfPnt array2(1,nbup,1,nbvp); | |
875 | // Bez->Poles(array2); | |
876 | // Analyse(array2,nbup,nbvp,myNbSamplesU,myNbSamplesV); | |
877 | // } | |
878 | // } | |
879 | // break; | |
880 | // case GeomAbs_BSplineSurface: { | |
881 | if(typS == GeomAbs_BSplineSurface) { | |
0d969553 | 882 | // Processing BSpline surface |
7fd59977 | 883 | BSplSamplePnts(theDefl, theNUmin, theNVmin); |
884 | return; | |
885 | } | |
886 | else { | |
887 | ComputeSamplePoints(); | |
888 | } | |
889 | // case GeomAbs_Cylinder: | |
890 | // case GeomAbs_Cone: | |
891 | // case GeomAbs_Sphere: | |
892 | // case GeomAbs_Torus: | |
893 | // case GeomAbs_SurfaceOfRevolution: | |
894 | // case GeomAbs_SurfaceOfExtrusion: { nbsv = Max(15,theNVmin); nbsu=Max(15,theNUmin); } break; | |
895 | // default: { nbsu = Max(10,theNUmin); nbsv=Max(10,theNVmin); } break; | |
896 | // } | |
897 | ||
898 | ||
899 | // if(nbsu<6) nbsu=6; | |
900 | // if(nbsv<6) nbsv=6; | |
901 | ||
902 | // myNbSamplesU = nbsu; | |
903 | // myNbSamplesV = nbsv; | |
904 | ||
905 | ||
906 | myUPars = new TColStd_HArray1OfReal(1, myNbSamplesU); | |
907 | myVPars = new TColStd_HArray1OfReal(1, myNbSamplesV); | |
908 | Standard_Integer i; | |
909 | Standard_Real t, dt = (usup - uinf)/(myNbSamplesU - 1); | |
910 | myUPars->SetValue(1, uinf); | |
911 | myUPars->SetValue(myNbSamplesU, usup); | |
912 | for(i = 2, t = uinf+dt; i < myNbSamplesU; ++i, t += dt) { | |
913 | myUPars->SetValue(i, t); | |
914 | } | |
915 | ||
916 | dt = (vsup - vinf)/(myNbSamplesV - 1); | |
917 | myVPars->SetValue(1, vinf); | |
918 | myVPars->SetValue(myNbSamplesV, vsup); | |
919 | for(i = 2, t = vinf+dt; i < myNbSamplesV; ++i, t += dt) { | |
920 | myVPars->SetValue(i, t); | |
921 | } | |
922 | ||
923 | return; | |
924 | ||
925 | } | |
926 | ||
927 | //======================================================================= | |
928 | //function : BSplSamplePnts | |
929 | //purpose : | |
930 | //======================================================================= | |
931 | ||
932 | void Adaptor3d_TopolTool::BSplSamplePnts(const Standard_Real theDefl, | |
933 | const Standard_Integer theNUmin, | |
934 | const Standard_Integer theNVmin) | |
935 | { | |
fffc249f | 936 | const Standard_Integer aMaxPnts = 1001; |
7fd59977 | 937 | const Handle(Geom_BSplineSurface)& aBS = myS->BSpline(); |
938 | Standard_Real uinf,usup,vinf,vsup; | |
939 | uinf = myS->FirstUParameter(); usup = myS->LastUParameter(); | |
940 | vinf = myS->FirstVParameter(); vsup = myS->LastVParameter(); | |
941 | ||
1d47d8d0 | 942 | Standard_Integer i, k, j = 1; |
7fd59977 | 943 | Standard_Real t1, t2, dt; |
944 | Standard_Integer ui1 = aBS->FirstUKnotIndex(); | |
945 | Standard_Integer ui2 = aBS->LastUKnotIndex(); | |
946 | Standard_Integer vi1 = aBS->FirstVKnotIndex(); | |
947 | Standard_Integer vi2 = aBS->LastVKnotIndex(); | |
948 | ||
949 | for(i = ui1; i < ui2; ++i) { | |
950 | if(uinf >= aBS->UKnot(i) && uinf < aBS->UKnot(i+1)) { | |
951 | ui1 = i; | |
952 | break; | |
953 | } | |
954 | } | |
955 | ||
956 | for(i = ui2; i > ui1; --i) { | |
957 | if(usup <= aBS->UKnot(i) && usup > aBS->UKnot(i-1)) { | |
958 | ui2 = i; | |
959 | break; | |
960 | } | |
961 | } | |
962 | ||
963 | for(i = vi1; i < vi2; ++i) { | |
964 | if(vinf >= aBS->VKnot(i) && vinf < aBS->VKnot(i+1)) { | |
965 | vi1 = i; | |
966 | break; | |
967 | } | |
968 | } | |
969 | ||
970 | for(i = vi2; i > vi1; --i) { | |
971 | if(vsup <= aBS->VKnot(i) && vsup > aBS->VKnot(i-1)) { | |
972 | vi2 = i; | |
973 | break; | |
974 | } | |
975 | } | |
976 | ||
977 | Standard_Integer nbsu = ui2-ui1+1; nbsu += (nbsu - 1) * (aBS->UDegree()-1); | |
978 | Standard_Integer nbsv = vi2-vi1+1; nbsv += (nbsv - 1) * (aBS->VDegree()-1); | |
979 | Standard_Boolean bUuniform = Standard_False; | |
980 | Standard_Boolean bVuniform = Standard_False; | |
981 | ||
97acf541 | 982 | //modified by NIZHNY-EMV Mon Jun 10 14:19:04 2013 |
983 | if (nbsu < theNUmin || nbsv < theNVmin) { | |
984 | Standard_Integer aNb; | |
985 | if (nbsu < nbsv) { | |
986 | aNb = (Standard_Integer)(nbsv * ((Standard_Real)theNUmin)/((Standard_Real)nbsu)); | |
987 | aNb = Min(aNb, 30); | |
988 | bVuniform = (aNb > nbsv) ? Standard_True : bVuniform; | |
989 | nbsv = bVuniform ? aNb : nbsv; | |
990 | } else { | |
991 | aNb = (Standard_Integer)(nbsu * ((Standard_Real)theNVmin)/((Standard_Real)nbsv)); | |
992 | aNb = Min(aNb, 30); | |
993 | bUuniform = (aNb > nbsu) ? Standard_True : bUuniform; | |
994 | nbsu = bUuniform ? aNb : nbsu; | |
995 | } | |
996 | } | |
997 | //modified by NIZHNY-EMV Mon Jun 10 14:19:05 2013 | |
998 | ||
7fd59977 | 999 | if(nbsu < theNUmin) { |
1000 | nbsu = theNUmin; | |
1001 | bUuniform = Standard_True; | |
1002 | } | |
fffc249f | 1003 | else if (nbsu > aMaxPnts) |
1004 | { | |
1005 | nbsu = aMaxPnts; | |
1006 | bUuniform = Standard_True; | |
1007 | } | |
7fd59977 | 1008 | if(nbsv < theNVmin) { |
1009 | nbsv = theNVmin; | |
1010 | bVuniform = Standard_True; | |
1011 | } | |
fffc249f | 1012 | else if (nbsv > aMaxPnts) |
1013 | { | |
1014 | nbsv = aMaxPnts; | |
1015 | bVuniform = Standard_True; | |
1016 | } | |
7fd59977 | 1017 | |
1018 | TColStd_Array1OfReal anUPars(1, nbsu); | |
1019 | TColStd_Array1OfBoolean anUFlg(1, nbsu); | |
1020 | TColStd_Array1OfReal aVPars(1, nbsv); | |
1021 | TColStd_Array1OfBoolean aVFlg(1, nbsv); | |
1022 | ||
1023 | //Filling of sample parameters | |
1024 | if(bUuniform) { | |
1025 | t1 = uinf; | |
1026 | t2 = usup; | |
1027 | dt = (t2 - t1)/(nbsu - 1); | |
1028 | anUPars(1) = t1; | |
1029 | anUFlg(1) = Standard_False; | |
1030 | anUPars(nbsu) = t2; | |
1031 | anUFlg(nbsu) = Standard_False; | |
1032 | for(i = 2, t1 += dt; i < nbsu; ++i, t1 += dt) { | |
1033 | anUPars(i) = t1; | |
1034 | anUFlg(i) = Standard_False; | |
1035 | } | |
1036 | } | |
1037 | else { | |
1d47d8d0 | 1038 | Standard_Integer nbi = aBS->UDegree(); |
7fd59977 | 1039 | k = 0; |
1040 | t1 = uinf; | |
1041 | for(i = ui1+1; i <= ui2; ++i) { | |
1042 | if(i == ui2) t2 = usup; | |
1043 | else t2 = aBS->UKnot(i); | |
1044 | dt = (t2 - t1)/nbi; | |
1045 | j = 1; | |
1046 | do { | |
1047 | ++k; | |
1048 | anUPars(k) = t1; | |
1049 | anUFlg(k) = Standard_False; | |
1050 | t1 += dt; | |
1051 | } | |
1052 | while (++j <= nbi); | |
1053 | t1 = t2; | |
1054 | } | |
1055 | ++k; | |
1056 | anUPars(k) = t1; | |
1057 | } | |
1058 | ||
1059 | if(bVuniform) { | |
1060 | t1 = vinf; | |
1061 | t2 = vsup; | |
1062 | dt = (t2 - t1)/(nbsv - 1); | |
1063 | aVPars(1) = t1; | |
1064 | aVFlg(1) = Standard_False; | |
1065 | aVPars(nbsv) = t2; | |
1066 | aVFlg(nbsv) = Standard_False; | |
1067 | for(i = 2, t1 += dt; i < nbsv; ++i, t1 += dt) { | |
1068 | aVPars(i) = t1; | |
1069 | aVFlg(i) = Standard_False; | |
1070 | } | |
1071 | } | |
1072 | else { | |
1d47d8d0 | 1073 | Standard_Integer nbi = aBS->VDegree(); |
7fd59977 | 1074 | k = 0; |
1075 | t1 = vinf; | |
1076 | for(i = vi1+1; i <= vi2; ++i) { | |
1077 | if(i == vi2) t2 = vsup; | |
1078 | else t2 = aBS->VKnot(i); | |
1079 | dt = (t2 - t1)/nbi; | |
1080 | j = 1; | |
1081 | do { | |
1082 | ++k; | |
1083 | aVPars(k) = t1; | |
1084 | aVFlg(k) = Standard_False; | |
1085 | t1 += dt; | |
1086 | } | |
1087 | while (++j <= nbi); | |
1088 | t1 = t2; | |
1089 | } | |
1090 | ++k; | |
1091 | aVPars(k) = t1; | |
1092 | } | |
1093 | ||
1094 | //Analysis of deflection | |
1095 | ||
1096 | Standard_Real aDefl2 = Max(theDefl*theDefl, 1.e-9); | |
1097 | Standard_Real tol = Max(0.01*aDefl2, 1.e-9); | |
1098 | Standard_Integer l; | |
1099 | ||
1100 | anUFlg(1) = Standard_True; | |
1101 | anUFlg(nbsu) = Standard_True; | |
07782e0c | 1102 | //myNbSamplesU = 2; |
7fd59977 | 1103 | for(i = 1; i <= nbsv; ++i) { |
1104 | t1 = aVPars(i); | |
1105 | j = 1; | |
1106 | Standard_Boolean bCont = Standard_True; | |
1107 | while (j < nbsu-1 && bCont) { | |
1108 | ||
1109 | if(anUFlg(j+1)) { | |
1110 | ++j; | |
1111 | continue; | |
1112 | } | |
1113 | ||
1114 | t2 = anUPars(j); | |
a061150b | 1115 | gp_Pnt p1 = myS->Value(t2, t1); |
7fd59977 | 1116 | for(k = j+2; k <= nbsu; ++k) { |
1117 | t2 = anUPars(k); | |
a061150b | 1118 | gp_Pnt p2 = myS->Value(t2, t1); |
7fd59977 | 1119 | //gce_MakeLin MkLin(p1, p2); |
1120 | //const gp_Lin& lin = MkLin.Value(); | |
1121 | ||
1122 | if(p1.SquareDistance(p2) <= tol) continue; | |
1123 | ||
1124 | gp_Lin lin(p1, gp_Dir(gp_Vec(p1, p2))); | |
1125 | Standard_Boolean ok = Standard_True; | |
1126 | for(l = j+1; l < k; ++l) { | |
1127 | ||
1128 | if(anUFlg(l)) { | |
1129 | ok = Standard_False; | |
1130 | break; | |
1131 | } | |
1132 | ||
a061150b | 1133 | gp_Pnt pp = myS->Value(anUPars(l), t1); |
7fd59977 | 1134 | Standard_Real d = lin.SquareDistance(pp); |
1135 | ||
1136 | if(d <= aDefl2) continue; | |
1137 | ||
1138 | ok = Standard_False; | |
1139 | break; | |
1140 | } | |
1141 | ||
1142 | if(!ok) { | |
1143 | j = k - 1; | |
1144 | anUFlg(j) = Standard_True; | |
07782e0c | 1145 | //++myNbSamplesU; |
7fd59977 | 1146 | break; |
1147 | } | |
1148 | ||
1149 | if(anUFlg(k)) { | |
1150 | j = k; | |
1151 | break; | |
1152 | } | |
1153 | ||
1154 | ||
1155 | } | |
1156 | ||
1157 | if(k >= nbsu) bCont = Standard_False; | |
1158 | ||
1159 | } | |
1160 | } | |
07782e0c | 1161 | |
1162 | myNbSamplesU = 0; | |
1163 | for (i = 1; i <= nbsu; i++) | |
1164 | if (anUFlg(i) == Standard_True) | |
1165 | myNbSamplesU++; | |
1166 | ||
7fd59977 | 1167 | if(myNbSamplesU < myMinPnts) { |
1168 | if(myNbSamplesU == 2) { | |
1169 | //"uniform" distribution; | |
1170 | Standard_Integer nn = nbsu/myMinPnts; | |
1171 | anUFlg(1+nn) = Standard_True; | |
1172 | anUFlg(nbsu-nn) = Standard_True; | |
1173 | } | |
1174 | else { //myNbSamplesU == 3 | |
1175 | //insert in bigger segment | |
1176 | i = 2; | |
1177 | while(!anUFlg(i++)); | |
1178 | if(i < nbsu/2) j = Min(i+(nbsu-i)/2, nbsu-1); | |
1179 | else j = Max(i/2, 2); | |
1180 | } | |
1181 | anUFlg(j) = Standard_True; | |
1182 | myNbSamplesU = myMinPnts; | |
1183 | } | |
1184 | ||
1185 | aVFlg(1) = Standard_True; | |
1186 | aVFlg(nbsv) = Standard_True; | |
07782e0c | 1187 | //myNbSamplesV = 2; |
7fd59977 | 1188 | for(i = 1; i <= nbsu; ++i) { |
1189 | t1 = anUPars(i); | |
1190 | j = 1; | |
1191 | Standard_Boolean bCont = Standard_True; | |
1192 | while (j < nbsv-1 && bCont) { | |
1193 | ||
1194 | if(aVFlg(j+1)) { | |
1195 | ++j; | |
1196 | continue; | |
1197 | } | |
1198 | ||
1199 | t2 = aVPars(j); | |
a061150b | 1200 | gp_Pnt p1 = myS->Value(t1, t2); |
7fd59977 | 1201 | for(k = j+2; k <= nbsv; ++k) { |
1202 | t2 = aVPars(k); | |
a061150b | 1203 | gp_Pnt p2 = myS->Value(t1, t2); |
7fd59977 | 1204 | |
1205 | if(p1.SquareDistance(p2) <= tol) continue; | |
1206 | //gce_MakeLin MkLin(p1, p2); | |
1207 | //const gp_Lin& lin = MkLin.Value(); | |
1208 | gp_Lin lin(p1, gp_Dir(gp_Vec(p1, p2))); | |
1209 | Standard_Boolean ok = Standard_True; | |
1210 | for(l = j+1; l < k; ++l) { | |
1211 | ||
1212 | if(aVFlg(l)) { | |
1213 | ok = Standard_False; | |
1214 | break; | |
1215 | } | |
1216 | ||
a061150b | 1217 | gp_Pnt pp = myS->Value(t1, aVPars(l)); |
7fd59977 | 1218 | Standard_Real d = lin.SquareDistance(pp); |
1219 | ||
1220 | if(d <= aDefl2) continue; | |
1221 | ||
1222 | ok = Standard_False; | |
1223 | break; | |
1224 | } | |
1225 | ||
1226 | if(!ok) { | |
1227 | j = k - 1; | |
1228 | aVFlg(j) = Standard_True; | |
07782e0c | 1229 | //++myNbSamplesV; |
7fd59977 | 1230 | break; |
1231 | } | |
1232 | ||
1233 | if(aVFlg(k)) { | |
1234 | j = k; | |
1235 | break; | |
1236 | } | |
1237 | ||
1238 | ||
1239 | } | |
1240 | ||
1241 | if(k >= nbsv) bCont = Standard_False; | |
1242 | ||
1243 | } | |
1244 | } | |
07782e0c | 1245 | |
1246 | myNbSamplesV = 0; | |
1247 | for (i = 1; i <= nbsv; i++) | |
1248 | if (aVFlg(i) == Standard_True) | |
1249 | myNbSamplesV++; | |
1250 | ||
7fd59977 | 1251 | if(myNbSamplesV < myMinPnts) { |
1252 | if(myNbSamplesV == 2) { | |
1253 | //"uniform" distribution; | |
1254 | Standard_Integer nn = nbsv/myMinPnts; | |
1255 | aVFlg(1+nn) = Standard_True; | |
1256 | aVFlg(nbsv-nn) = Standard_True; | |
1257 | myNbSamplesV = myMinPnts; | |
1258 | } | |
1259 | else { //myNbSamplesU == 3 | |
1260 | //insert in bigger segment | |
1261 | i = 2; | |
1262 | while(!aVFlg(i++)); | |
1263 | if(i < nbsv/2) j = Min(i+(nbsv-i)/2, nbsv-1); | |
1264 | else j = Max(i/2, 2); | |
1265 | } | |
1266 | myNbSamplesV = myMinPnts; | |
1267 | aVFlg(j) = Standard_True; | |
1268 | } | |
fa9681ca P |
1269 | // |
1270 | //modified by NIZNHY-PKV Fri Dec 16 10:05:01 2011f | |
1271 | // | |
1272 | Standard_Boolean bFlag; | |
1273 | // | |
1274 | // U | |
1275 | bFlag=(myNbSamplesU < theNUmin); | |
1276 | if (bFlag) { | |
1277 | myNbSamplesU=nbsu; | |
1278 | } | |
1279 | // | |
1280 | myUPars = new TColStd_HArray1OfReal(1, myNbSamplesU); | |
1281 | // | |
1282 | for(j = 0, i = 1; i <= nbsu; ++i) { | |
1283 | if (bFlag) { | |
7c4e9501 | 1284 | myUPars->SetValue(i,anUPars(i)); |
fa9681ca P |
1285 | } |
1286 | else { | |
1287 | if(anUFlg(i)) { | |
7c4e9501 | 1288 | ++j; |
1289 | myUPars->SetValue(j,anUPars(i)); | |
fa9681ca P |
1290 | } |
1291 | } | |
1292 | } | |
1293 | // | |
1294 | // V | |
1295 | bFlag=(myNbSamplesV < theNVmin); | |
1296 | if (bFlag) { | |
1297 | myNbSamplesV=nbsv; | |
1298 | } | |
1299 | // | |
1300 | myVPars = new TColStd_HArray1OfReal(1, myNbSamplesV); | |
1301 | // | |
1302 | for(j = 0, i = 1; i <= nbsv; ++i) { | |
1303 | if (bFlag) { | |
1304 | myVPars->SetValue(i,aVPars(i)); | |
1305 | } | |
1306 | else { | |
1307 | if(aVFlg(i)) { | |
7c4e9501 | 1308 | ++j; |
1309 | myVPars->SetValue(j,aVPars(i)); | |
fa9681ca P |
1310 | } |
1311 | } | |
1312 | } | |
1313 | // | |
1314 | /* | |
7fd59977 | 1315 | myUPars = new TColStd_HArray1OfReal(1, myNbSamplesU); |
1316 | myVPars = new TColStd_HArray1OfReal(1, myNbSamplesV); | |
1317 | ||
1318 | j = 0; | |
1319 | for(i = 1; i <= nbsu; ++i) { | |
1320 | if(anUFlg(i)) { | |
1321 | ++j; | |
1322 | myUPars->SetValue(j,anUPars(i)); | |
1323 | } | |
1324 | } | |
1325 | ||
1326 | j = 0; | |
1327 | for(i = 1; i <= nbsv; ++i) { | |
1328 | if(aVFlg(i)) { | |
1329 | ++j; | |
1330 | myVPars->SetValue(j,aVPars(i)); | |
1331 | } | |
1332 | } | |
fa9681ca P |
1333 | */ |
1334 | //modified by NIZNHY-PKV Mon Dec 26 12:25:35 2011t | |
7fd59977 | 1335 | |
1336 | } | |
1337 | ||
fa9681ca P |
1338 | //======================================================================= |
1339 | //function : IsUniformSampling | |
1340 | //purpose : | |
1341 | //======================================================================= | |
7fd59977 | 1342 | Standard_Boolean Adaptor3d_TopolTool::IsUniformSampling() const |
1343 | { | |
1344 | GeomAbs_SurfaceType typS = myS->GetType(); | |
1345 | ||
1346 | if(typS == GeomAbs_BSplineSurface) | |
1347 | return Standard_False; | |
1348 | return Standard_True; | |
1349 | } |