b311480e |
1 | // Created on: 1999-04-27 |
2 | // Created by: Pavel DURANDIN |
3 | // Copyright (c) 1999-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <ShapeExtend_CompositeSurface.ixx> |
18 | #include <Precision.hxx> |
19 | |
20 | //======================================================================= |
21 | //function : ShapeExtend_CompositeSurface |
22 | //purpose : |
23 | //======================================================================= |
24 | |
25 | ShapeExtend_CompositeSurface::ShapeExtend_CompositeSurface() |
26 | { |
27 | } |
28 | |
29 | //======================================================================= |
30 | //function : Constructor |
31 | //purpose : |
32 | //======================================================================= |
33 | |
34 | ShapeExtend_CompositeSurface::ShapeExtend_CompositeSurface(const Handle(TColGeom_HArray2OfSurface)& GridSurf, |
35 | const ShapeExtend_Parametrisation param) |
36 | { |
37 | Init ( GridSurf, param ); |
38 | } |
39 | |
40 | //======================================================================= |
41 | //function : Constructor |
42 | //purpose : |
43 | //======================================================================= |
44 | |
45 | ShapeExtend_CompositeSurface::ShapeExtend_CompositeSurface(const Handle(TColGeom_HArray2OfSurface)& GridSurf, |
46 | const TColStd_Array1OfReal &UJoints, |
47 | const TColStd_Array1OfReal &VJoints) |
48 | { |
49 | Init ( GridSurf, UJoints, VJoints ); |
50 | } |
51 | |
52 | //======================================================================= |
53 | //function : Init |
54 | //purpose : |
55 | //======================================================================= |
56 | |
57 | Standard_Boolean ShapeExtend_CompositeSurface::Init (const Handle(TColGeom_HArray2OfSurface)& GridSurf, |
58 | const ShapeExtend_Parametrisation param) |
59 | { |
60 | if ( GridSurf.IsNull() ) return Standard_False; |
61 | myPatches = GridSurf; |
62 | ComputeJointValues ( param ); |
63 | return CheckConnectivity ( Precision::Confusion() ); |
64 | } |
65 | |
66 | //======================================================================= |
67 | //function : Init |
68 | //purpose : |
69 | //======================================================================= |
70 | |
71 | Standard_Boolean ShapeExtend_CompositeSurface::Init (const Handle(TColGeom_HArray2OfSurface)& GridSurf, |
72 | const TColStd_Array1OfReal &UJoints, |
73 | const TColStd_Array1OfReal &VJoints) |
74 | { |
75 | if ( GridSurf.IsNull() ) return Standard_False; |
76 | myPatches = GridSurf; |
77 | |
78 | Standard_Boolean ok = Standard_True; |
79 | if ( ! SetUJointValues ( UJoints ) || ! SetVJointValues ( VJoints ) ) { |
80 | ok = Standard_False; |
81 | ComputeJointValues ( ShapeExtend_Natural ); |
63c629aa |
82 | #ifdef SHAPEEXTEND_DEB |
7fd59977 |
83 | cout << "Warning: ShapeExtend_CompositeSurface::Init: bad joint values" << endl; |
84 | #endif |
85 | } |
86 | |
87 | return ( CheckConnectivity ( Precision::Confusion() ) ? ok : Standard_False ); |
88 | } |
89 | |
90 | //======================================================================= |
91 | //function : NbUPatches |
92 | //purpose : |
93 | //======================================================================= |
94 | |
95 | Standard_Integer ShapeExtend_CompositeSurface::NbUPatches() const |
96 | { |
97 | return myPatches->ColLength(); |
98 | } |
99 | |
100 | //======================================================================= |
101 | //function : NbVPatches |
102 | //purpose : |
103 | //======================================================================= |
104 | |
105 | Standard_Integer ShapeExtend_CompositeSurface::NbVPatches() const |
106 | { |
107 | return myPatches->RowLength(); |
108 | } |
109 | |
110 | //======================================================================= |
111 | //function : Patch |
112 | //purpose : |
113 | //======================================================================= |
114 | |
115 | const Handle(Geom_Surface)& ShapeExtend_CompositeSurface::Patch(const Standard_Integer i, |
116 | const Standard_Integer j) const |
117 | { |
118 | return myPatches->Value(i,j); |
119 | } |
120 | |
121 | //======================================================================= |
122 | //function : Patches |
123 | //purpose : |
124 | //======================================================================= |
125 | |
126 | const Handle(TColGeom_HArray2OfSurface)& ShapeExtend_CompositeSurface::Patches() const |
127 | { |
128 | return myPatches; |
129 | } |
130 | |
131 | //======================================================================= |
132 | //function : UJointValues |
133 | //purpose : |
134 | //======================================================================= |
135 | |
136 | Handle(TColStd_HArray1OfReal) ShapeExtend_CompositeSurface::UJointValues() const |
137 | { |
138 | return myUJointValues; |
139 | } |
140 | |
141 | //======================================================================= |
142 | //function : VJointValues |
143 | //purpose : |
144 | //======================================================================= |
145 | |
146 | Handle(TColStd_HArray1OfReal) ShapeExtend_CompositeSurface::VJointValues() const |
147 | { |
148 | return myVJointValues; |
149 | } |
150 | |
151 | //======================================================================= |
152 | //function : UJointValue |
153 | //purpose : |
154 | //======================================================================= |
155 | |
156 | Standard_Real ShapeExtend_CompositeSurface::UJointValue(const Standard_Integer i) const |
157 | { |
158 | return myUJointValues->Value(i); |
159 | } |
160 | |
161 | //======================================================================= |
162 | //function : VJointValue |
163 | //purpose : |
164 | //======================================================================= |
165 | |
166 | Standard_Real ShapeExtend_CompositeSurface::VJointValue(const Standard_Integer i) const |
167 | { |
168 | return myVJointValues->Value(i); |
169 | } |
170 | |
171 | //======================================================================= |
172 | //function : SetUJointValues |
173 | //purpose : |
174 | //======================================================================= |
175 | |
176 | Standard_Boolean ShapeExtend_CompositeSurface::SetUJointValues (const TColStd_Array1OfReal &UJoints) |
177 | { |
178 | Standard_Integer NbU = NbUPatches(); |
179 | if ( UJoints.Length() != NbU+1 ) return Standard_False; |
180 | |
181 | Handle(TColStd_HArray1OfReal) UJointValues = new TColStd_HArray1OfReal(1,NbU+1); |
182 | for ( Standard_Integer i=1, j=UJoints.Lower(); i <= NbU+1; i++, j++ ) { |
183 | UJointValues->SetValue ( i, UJoints(j) ); |
184 | if ( i >1 && UJoints(j) - UJoints(j-1) < Precision::PConfusion() ) |
185 | return Standard_False; |
186 | } |
187 | myUJointValues = UJointValues; |
188 | return Standard_True; |
189 | } |
190 | |
191 | //======================================================================= |
192 | //function : SetVJointValues |
193 | //purpose : |
194 | //======================================================================= |
195 | |
196 | Standard_Boolean ShapeExtend_CompositeSurface::SetVJointValues (const TColStd_Array1OfReal &VJoints) |
197 | { |
198 | Standard_Integer NbV = NbVPatches(); |
199 | if ( VJoints.Length() != NbV+1 ) return Standard_False; |
200 | |
201 | Handle(TColStd_HArray1OfReal) VJointValues = new TColStd_HArray1OfReal(1,NbV+1); |
202 | for ( Standard_Integer i=1, j=VJoints.Lower(); i <= NbV+1; i++, j++ ) { |
203 | VJointValues->SetValue ( i, VJoints(j) ); |
204 | if ( i >1 && VJoints(j) - VJoints(j-1) < Precision::PConfusion() ) |
205 | return Standard_False; |
206 | } |
207 | myVJointValues = VJointValues; |
208 | return Standard_True; |
209 | } |
210 | |
211 | //======================================================================= |
212 | //function : SetUFirstValue |
213 | //purpose : |
214 | //======================================================================= |
215 | |
216 | void ShapeExtend_CompositeSurface::SetUFirstValue (const Standard_Real UFirst) |
217 | { |
218 | if ( myUJointValues.IsNull() ) return; |
219 | |
220 | Standard_Real shift = UFirst - myUJointValues->Value(1); |
221 | Standard_Integer NbU = myUJointValues->Length(); |
222 | for ( Standard_Integer i=1; i <= NbU; i++ ) { |
223 | myUJointValues->SetValue ( i, myUJointValues->Value(i) + shift ); |
224 | } |
225 | } |
226 | |
227 | //======================================================================= |
228 | //function : SetVFirstValue |
229 | //purpose : |
230 | //======================================================================= |
231 | |
232 | void ShapeExtend_CompositeSurface::SetVFirstValue (const Standard_Real VFirst) |
233 | { |
234 | if ( myVJointValues.IsNull() ) return; |
235 | |
236 | Standard_Real shift = VFirst - myVJointValues->Value(1); |
237 | Standard_Integer NbV = myVJointValues->Length(); |
238 | for ( Standard_Integer i=1; i <= NbV; i++ ) { |
239 | myVJointValues->SetValue ( i, myVJointValues->Value(i) + shift ); |
240 | } |
241 | } |
242 | |
243 | //======================================================================= |
244 | //function : LocateUParameter |
245 | //purpose : |
246 | //======================================================================= |
247 | |
248 | Standard_Integer ShapeExtend_CompositeSurface::LocateUParameter(const Standard_Real U) const |
249 | { |
250 | Standard_Integer nbPatch = NbUPatches(); |
251 | for(Standard_Integer i = 2; i <= nbPatch; i++) |
252 | if (U < myUJointValues->Value(i)) return i-1; |
253 | return nbPatch; |
254 | } |
255 | |
256 | //======================================================================= |
257 | //function : LocateVParameter |
258 | //purpose : |
259 | //======================================================================= |
260 | |
261 | Standard_Integer ShapeExtend_CompositeSurface::LocateVParameter(const Standard_Real V) const |
262 | { |
263 | Standard_Integer nbPatch = NbVPatches(); |
264 | for(Standard_Integer i = 2; i <= nbPatch; i++) |
265 | if (V < myVJointValues->Value(i)) return i-1; |
266 | return nbPatch; |
267 | } |
268 | |
269 | //======================================================================= |
270 | //function : LocateUVPoint |
271 | //purpose : |
272 | //======================================================================= |
273 | |
274 | void ShapeExtend_CompositeSurface::LocateUVPoint(const gp_Pnt2d& pnt, |
275 | Standard_Integer& i, |
276 | Standard_Integer& j) const |
277 | { |
278 | i = LocateUParameter(pnt.X()); |
279 | j = LocateVParameter(pnt.Y()); |
280 | } |
281 | |
282 | //======================================================================= |
283 | //function : Patch |
284 | //purpose : |
285 | //======================================================================= |
286 | |
287 | const Handle(Geom_Surface)& ShapeExtend_CompositeSurface::Patch(const Standard_Real U, |
288 | const Standard_Real V) const |
289 | { |
290 | return myPatches->Value ( LocateUParameter(U), LocateVParameter(V) ); |
291 | } |
292 | |
293 | //======================================================================= |
294 | //function : Patch |
295 | //purpose : |
296 | //======================================================================= |
297 | |
298 | const Handle(Geom_Surface)& ShapeExtend_CompositeSurface::Patch(const gp_Pnt2d& pnt) const |
299 | { |
300 | return myPatches->Value ( LocateUParameter(pnt.X()), LocateVParameter(pnt.Y()) ); |
301 | } |
302 | |
303 | //======================================================================= |
304 | //function : ULocalToGlobal |
305 | //purpose : |
306 | //======================================================================= |
307 | |
308 | Standard_Real ShapeExtend_CompositeSurface::ULocalToGlobal (const Standard_Integer i, |
309 | const Standard_Integer j, |
310 | const Standard_Real u) const |
311 | { |
312 | Standard_Real u1, u2, v1, v2; |
313 | myPatches->Value(i,j)->Bounds ( u1, u2, v1, v2 ); |
314 | Standard_Real scale = ( myUJointValues->Value(i+1) - myUJointValues->Value(i) ) / ( u2 - u1 ); |
315 | return u * scale + ( myUJointValues->Value(i) - u1 * scale ); // ! this formula is stable if u1 is infinite |
316 | } |
317 | |
318 | //======================================================================= |
319 | //function : VLocalToGlobal |
320 | //purpose : |
321 | //======================================================================= |
322 | |
323 | Standard_Real ShapeExtend_CompositeSurface::VLocalToGlobal (const Standard_Integer i, |
324 | const Standard_Integer j, |
325 | const Standard_Real v) const |
326 | { |
327 | Standard_Real u1, u2, v1, v2; |
328 | myPatches->Value(i,j)->Bounds ( u1, u2, v1, v2 ); |
329 | Standard_Real scale = ( myVJointValues->Value(j+1) - myVJointValues->Value(j) ) / ( v2 - v1 ); |
330 | return v * scale + ( myVJointValues->Value(j) - v1 * scale ); // ! this formula is stable if v1 is infinite |
331 | } |
332 | |
333 | //======================================================================= |
334 | //function : LocalToGlobal |
335 | //purpose : |
336 | //======================================================================= |
337 | |
338 | gp_Pnt2d ShapeExtend_CompositeSurface::LocalToGlobal (const Standard_Integer i, |
339 | const Standard_Integer j, |
340 | const gp_Pnt2d &uv) const |
341 | { |
342 | Standard_Real u1, u2, v1, v2; |
343 | myPatches->Value(i,j)->Bounds ( u1, u2, v1, v2 ); |
344 | Standard_Real scaleu = ( myUJointValues->Value(i+1) - myUJointValues->Value(i) ) / ( u2 - u1 ); |
345 | Standard_Real scalev = ( myVJointValues->Value(j+1) - myVJointValues->Value(j) ) / ( v2 - v1 ); |
346 | return gp_Pnt2d ( uv.X() * scaleu + ( myUJointValues->Value(i) - u1 * scaleu ), // ! this formula is stable if u1 or v1 is infinite |
347 | uv.Y() * scalev + ( myVJointValues->Value(j) - v1 * scalev ) ); |
348 | } |
349 | |
350 | //======================================================================= |
351 | //function : UGlobalToLocal |
352 | //purpose : |
353 | //======================================================================= |
354 | |
355 | Standard_Real ShapeExtend_CompositeSurface::UGlobalToLocal (const Standard_Integer i, |
356 | const Standard_Integer j, |
357 | const Standard_Real U) const |
358 | { |
359 | Standard_Real u1, u2, v1, v2; |
360 | myPatches->Value(i,j)->Bounds ( u1, u2, v1, v2 ); |
361 | Standard_Real scale = ( u2 - u1 ) / ( myUJointValues->Value(i+1) - myUJointValues->Value(i) ); |
362 | return U * scale + ( u1 - myUJointValues->Value(i) * scale ); // ! this formula is stable if u1 is infinite |
363 | } |
364 | |
365 | //======================================================================= |
366 | //function : VGlobalToLocal |
367 | //purpose : |
368 | //======================================================================= |
369 | |
370 | Standard_Real ShapeExtend_CompositeSurface::VGlobalToLocal (const Standard_Integer i, |
371 | const Standard_Integer j, |
372 | const Standard_Real V) const |
373 | { |
374 | Standard_Real u1, u2, v1, v2; |
375 | myPatches->Value(i,j)->Bounds ( u1, u2, v1, v2 ); |
376 | Standard_Real scale = ( v2 - v1 ) / ( myVJointValues->Value(j+1) - myVJointValues->Value(j) ); |
377 | return V * scale + ( v1 - myVJointValues->Value(j) * scale ); // ! this formula is stable if v1 is infinite |
378 | } |
379 | |
380 | //======================================================================= |
381 | //function : GlobalToLocal |
382 | //purpose : |
383 | //======================================================================= |
384 | |
385 | gp_Pnt2d ShapeExtend_CompositeSurface::GlobalToLocal (const Standard_Integer i, |
386 | const Standard_Integer j, |
387 | const gp_Pnt2d &UV) const |
388 | { |
389 | Standard_Real u1, u2, v1, v2; |
390 | myPatches->Value(i,j)->Bounds ( u1, u2, v1, v2 ); |
391 | Standard_Real scaleu = ( u2 - u1 ) / ( myUJointValues->Value(i+1) - myUJointValues->Value(i) ); |
392 | Standard_Real scalev = ( v2 - v1 ) / ( myVJointValues->Value(j+1) - myVJointValues->Value(j) ); |
393 | return gp_Pnt2d ( UV.X() * scaleu + ( u1 - myUJointValues->Value(i) * scaleu ), // ! this formula is stable if u1 or v1 is infinite |
394 | UV.Y() * scalev + ( v1 - myVJointValues->Value(j) * scalev ) ); |
395 | } |
396 | |
397 | //======================================================================= |
398 | //function : GlobalToLocalTransformation |
399 | //purpose : |
400 | //======================================================================= |
401 | |
402 | Standard_Boolean ShapeExtend_CompositeSurface::GlobalToLocalTransformation (const Standard_Integer i, |
403 | const Standard_Integer j, |
404 | Standard_Real &uFact, |
405 | gp_Trsf2d &Trsf) const |
406 | { |
407 | Standard_Real u1, u2, v1, v2; |
408 | myPatches->Value(i,j)->Bounds ( u1, u2, v1, v2 ); |
409 | |
410 | Standard_Real scaleu = ( u2 - u1 ) / ( myUJointValues->Value(i+1) - myUJointValues->Value(i) ); |
411 | Standard_Real scalev = ( v2 - v1 ) / ( myVJointValues->Value(j+1) - myVJointValues->Value(j) ); |
412 | gp_Vec2d shift ( u1 / scaleu - myUJointValues->Value(i), |
413 | v1 / scalev - myVJointValues->Value(j) ); |
414 | |
415 | uFact = scaleu / scalev; |
416 | gp_Trsf2d Shift, Scale; |
417 | if ( shift.X() != 0. || shift.Y() != 0. ) Shift.SetTranslation ( shift ); |
418 | if ( scalev != 1. ) Scale.SetScale ( gp_Pnt2d(0,0), scalev ); |
419 | Trsf = Scale * Shift; |
420 | return uFact != 1. || Trsf.Form() != gp_Identity; |
421 | } |
422 | |
423 | //======================================================================= |
424 | // Inherited methods (from Geom_Geometry and Geom_Surface) |
425 | //======================================================================= |
426 | |
427 | //======================================================================= |
428 | //function : Transform |
429 | //purpose : |
430 | //======================================================================= |
431 | |
432 | void ShapeExtend_CompositeSurface::Transform (const gp_Trsf &T) |
433 | { |
434 | if ( myPatches.IsNull() ) return; |
435 | for ( Standard_Integer i=1; i <= NbUPatches(); i++ ) |
436 | for ( Standard_Integer j=1; j <= NbVPatches(); j++ ) |
437 | Patch(i,j)->Transform ( T ); |
438 | } |
439 | |
440 | //======================================================================= |
441 | //function : Copy |
442 | //purpose : |
443 | //======================================================================= |
444 | |
445 | Handle(Geom_Geometry) ShapeExtend_CompositeSurface::Copy () const |
446 | { |
447 | Handle(ShapeExtend_CompositeSurface) surf = new ShapeExtend_CompositeSurface; |
448 | if ( myPatches.IsNull() ) return surf; |
449 | |
450 | Handle(TColGeom_HArray2OfSurface) patches = |
451 | new TColGeom_HArray2OfSurface ( 1, NbUPatches(), 1, NbVPatches() ); |
452 | for ( Standard_Integer i=1; i <= NbUPatches(); i++ ) |
453 | for ( Standard_Integer j=1; j <= NbVPatches(); j++ ) |
454 | patches->SetValue ( i, j, Handle(Geom_Surface)::DownCast ( Patch(i,j)->Copy() ) ); |
455 | surf->Init ( patches ); |
456 | return surf; |
457 | } |
458 | |
459 | //======================================================================= |
460 | //function : UReverse |
461 | //purpose : |
462 | //======================================================================= |
463 | |
464 | void ShapeExtend_CompositeSurface::UReverse () |
465 | { |
466 | } |
467 | |
468 | //======================================================================= |
469 | //function : UReversedParameter |
470 | //purpose : |
471 | //======================================================================= |
472 | |
473 | Standard_Real ShapeExtend_CompositeSurface::UReversedParameter (const Standard_Real U) const |
474 | { |
475 | return U; |
476 | } |
477 | |
478 | //======================================================================= |
479 | //function : VReverse |
480 | //purpose : |
481 | //======================================================================= |
482 | |
483 | void ShapeExtend_CompositeSurface::VReverse () |
484 | { |
485 | } |
486 | |
487 | //======================================================================= |
488 | //function : VReversedParameter |
489 | //purpose : |
490 | //======================================================================= |
491 | |
492 | Standard_Real ShapeExtend_CompositeSurface::VReversedParameter (const Standard_Real V) const |
493 | { |
494 | return V; |
495 | } |
496 | |
497 | //======================================================================= |
498 | //function : Bounds |
499 | //purpose : |
500 | //======================================================================= |
501 | |
502 | void ShapeExtend_CompositeSurface::Bounds(Standard_Real& U1, |
503 | Standard_Real& U2, |
504 | Standard_Real& V1, |
505 | Standard_Real& V2) const |
506 | { |
507 | U1 = UJointValue(1); |
508 | V1 = VJointValue(1); |
509 | U2 = UJointValue(NbUPatches()+1); |
510 | V2 = VJointValue(NbVPatches()+1); |
511 | } |
512 | |
513 | //======================================================================= |
514 | //function : IsUPeriodic |
515 | //purpose : |
516 | //======================================================================= |
517 | |
518 | Standard_Boolean ShapeExtend_CompositeSurface::IsUPeriodic () const |
519 | { |
520 | return Standard_False; |
521 | } |
522 | |
523 | //======================================================================= |
524 | //function : IsVPeriodic |
525 | //purpose : |
526 | //======================================================================= |
527 | |
528 | Standard_Boolean ShapeExtend_CompositeSurface::IsVPeriodic () const |
529 | { |
530 | return Standard_False; |
531 | } |
532 | |
533 | //======================================================================= |
534 | //function : UIso |
535 | //purpose : |
536 | //======================================================================= |
537 | |
538 | Handle(Geom_Curve) ShapeExtend_CompositeSurface::UIso (const Standard_Real ) const |
539 | { |
540 | Handle(Geom_Curve) dummy; |
541 | return dummy; |
542 | } |
543 | |
544 | //======================================================================= |
545 | //function : VIso |
546 | //purpose : |
547 | //======================================================================= |
548 | |
549 | Handle(Geom_Curve) ShapeExtend_CompositeSurface::VIso (const Standard_Real ) const |
550 | { |
551 | Handle(Geom_Curve) dummy; |
552 | return dummy; |
553 | } |
554 | |
555 | //======================================================================= |
556 | //function : Continuity |
557 | //purpose : |
558 | //======================================================================= |
559 | |
560 | GeomAbs_Shape ShapeExtend_CompositeSurface::Continuity () const |
561 | { |
562 | return GeomAbs_C0; |
563 | } |
564 | |
565 | //======================================================================= |
566 | //function : IsCNu |
567 | //purpose : |
568 | //======================================================================= |
569 | |
570 | Standard_Boolean ShapeExtend_CompositeSurface::IsCNu (const Standard_Integer N) const |
571 | { |
572 | return N <=0; |
573 | } |
574 | |
575 | //======================================================================= |
576 | //function : IsCNv |
577 | //purpose : |
578 | //======================================================================= |
579 | |
580 | Standard_Boolean ShapeExtend_CompositeSurface::IsCNv (const Standard_Integer N) const |
581 | { |
582 | return N <=0; |
583 | } |
584 | |
585 | //======================================================================= |
586 | //function : IsUClosed |
587 | //purpose : |
588 | //======================================================================= |
589 | |
590 | Standard_Boolean ShapeExtend_CompositeSurface::IsUClosed () const |
591 | { |
592 | return myUClosed; |
593 | } |
594 | |
595 | //======================================================================= |
596 | //function : IsVClosed |
597 | //purpose : |
598 | //======================================================================= |
599 | |
600 | Standard_Boolean ShapeExtend_CompositeSurface::IsVClosed () const |
601 | { |
602 | return myVClosed; |
603 | } |
604 | |
605 | //======================================================================= |
606 | //function : D0 |
607 | //purpose : |
608 | //======================================================================= |
609 | |
610 | void ShapeExtend_CompositeSurface::D0 (const Standard_Real U, |
611 | const Standard_Real V, |
612 | gp_Pnt& P) const |
613 | { |
614 | Standard_Integer i = LocateUParameter ( U ); |
615 | Standard_Integer j = LocateVParameter ( V ); |
616 | gp_Pnt2d uv = GlobalToLocal ( i, j, gp_Pnt2d ( U, V ) ); |
617 | myPatches->Value(i,j)->D0 ( uv.X(), uv.Y(), P ); |
618 | } |
619 | |
620 | //======================================================================= |
621 | //function : D1 |
622 | //purpose : |
623 | //======================================================================= |
624 | |
625 | void ShapeExtend_CompositeSurface::D1 (const Standard_Real U, |
626 | const Standard_Real V, |
627 | gp_Pnt& P, |
628 | gp_Vec& D1U, |
629 | gp_Vec& D1V) const |
630 | { |
631 | Standard_Integer i = LocateUParameter ( U ); |
632 | Standard_Integer j = LocateVParameter ( V ); |
633 | gp_Pnt2d uv = GlobalToLocal ( i, j, gp_Pnt2d ( U, V ) ); |
634 | myPatches->Value(i,j)->D1 ( uv.X(), uv.Y(), P, D1U, D1V ); |
635 | } |
636 | |
637 | //======================================================================= |
638 | //function : D2 |
639 | //purpose : |
640 | //======================================================================= |
641 | |
642 | void ShapeExtend_CompositeSurface::D2 (const Standard_Real U, |
643 | const Standard_Real V, |
644 | gp_Pnt& P, |
645 | gp_Vec& D1U, |
646 | gp_Vec& D1V, |
647 | gp_Vec& D2U, |
648 | gp_Vec& D2V, |
649 | gp_Vec& D2UV) const |
650 | { |
651 | Standard_Integer i = LocateUParameter ( U ); |
652 | Standard_Integer j = LocateVParameter ( V ); |
653 | gp_Pnt2d uv = GlobalToLocal ( i, j, gp_Pnt2d ( U, V ) ); |
654 | myPatches->Value(i,j)->D2 ( uv.X(), uv.Y(), P, D1U, D1V, D2U, D2V, D2UV ); |
655 | } |
656 | |
657 | //======================================================================= |
658 | //function : D3 |
659 | //purpose : |
660 | //======================================================================= |
661 | |
662 | void ShapeExtend_CompositeSurface::D3 (const Standard_Real U, |
663 | const Standard_Real V, |
664 | gp_Pnt& P, |
665 | gp_Vec& D1U, |
666 | gp_Vec& D1V, |
667 | gp_Vec& D2U, |
668 | gp_Vec& D2V, |
669 | gp_Vec& D2UV, |
670 | gp_Vec& D3U, |
671 | gp_Vec& D3V, |
672 | gp_Vec& D3UUV, |
673 | gp_Vec& D3UVV) const |
674 | { |
675 | Standard_Integer i = LocateUParameter ( U ); |
676 | Standard_Integer j = LocateVParameter ( V ); |
677 | gp_Pnt2d uv = GlobalToLocal ( i, j, gp_Pnt2d ( U, V ) ); |
678 | myPatches->Value(i,j)->D3 ( uv.X(), uv.Y(), P, D1U, D1V, D2U, D2V, D2UV, D3U, D3V, D3UUV, D3UVV ); |
679 | } |
680 | |
681 | //======================================================================= |
682 | //function : DN |
683 | //purpose : |
684 | //======================================================================= |
685 | |
686 | gp_Vec ShapeExtend_CompositeSurface::DN (const Standard_Real U, |
687 | const Standard_Real V, |
688 | const Standard_Integer Nu, |
689 | const Standard_Integer Nv) const |
690 | { |
691 | Standard_Integer i = LocateUParameter ( U ); |
692 | Standard_Integer j = LocateVParameter ( V ); |
693 | gp_Pnt2d uv = GlobalToLocal ( i, j, gp_Pnt2d ( U, V ) ); |
694 | return myPatches->Value(i,j)->DN ( uv.X(), uv.Y(), Nu, Nv ); |
695 | } |
696 | |
697 | //======================================================================= |
698 | //function : Value |
699 | //purpose : |
700 | //======================================================================= |
701 | |
702 | gp_Pnt ShapeExtend_CompositeSurface::Value (const gp_Pnt2d& pnt) const |
703 | { |
704 | Standard_Integer i = LocateUParameter ( pnt.X() ); |
705 | Standard_Integer j = LocateVParameter ( pnt.Y() ); |
706 | gp_Pnt2d uv = GlobalToLocal ( i, j, pnt ); |
707 | gp_Pnt point; |
708 | myPatches->Value(i,j)->D0 ( uv.X(), uv.Y(), point ); |
709 | return point; |
710 | } |
711 | |
712 | //======================================================================= |
713 | //function : ComputeJointValues |
714 | //purpose : |
715 | //======================================================================= |
716 | |
717 | void ShapeExtend_CompositeSurface::ComputeJointValues (const ShapeExtend_Parametrisation param) |
718 | { |
719 | Standard_Integer NbU = NbUPatches(); |
720 | Standard_Integer NbV = NbVPatches(); |
721 | myUJointValues = new TColStd_HArray1OfReal(1,NbU+1); |
722 | myVJointValues = new TColStd_HArray1OfReal(1,NbV+1); |
723 | |
724 | if ( param == ShapeExtend_Natural ) { |
725 | Standard_Real U1, U2, V1, V2, U=0, V=0; |
726 | Standard_Integer i; // svv Jan 10 2000 : porting on DEC |
727 | for ( i = 1; i <= NbU; i++ ) { |
728 | myPatches->Value(i,1)->Bounds(U1,U2,V1,V2); |
729 | if ( i ==1 ) myUJointValues->SetValue ( 1, U = U1 ); |
730 | U += ( U2 - U1 ); |
731 | myUJointValues->SetValue ( i+1, U ); |
732 | } |
733 | for ( i = 1; i <= NbV; i++ ) { |
734 | myPatches->Value(1,i)->Bounds(U1,U2,V1,V2); |
735 | if ( i ==1 ) myVJointValues->SetValue ( 1, V = V1 ); |
736 | V += ( V2 - V1 ); |
737 | myVJointValues->SetValue ( i+1, V ); |
738 | } |
739 | } |
740 | else { |
741 | Standard_Real stepu = 1., stepv = 1.; // suppose param == ShapeExtend_Uniform |
742 | if ( param == ShapeExtend_Unitary ) { |
743 | stepu /= NbU; |
744 | stepv /= NbV; |
745 | } |
746 | Standard_Integer i; // svv Jan 10 2000 : porting on DEC |
747 | for ( i=0; i <= NbU; i++ ) |
748 | myUJointValues->SetValue ( i+1, i * stepu ); |
749 | for ( i=0; i <= NbV; i++ ) |
750 | myVJointValues->SetValue ( i+1, i * stepv ); |
751 | } |
752 | } |
753 | |
754 | //======================================================================= |
755 | //function : CheckConnectivity |
756 | //purpose : |
757 | //======================================================================= |
758 | |
759 | static inline Standard_Real LimitValue (const Standard_Real &par) |
760 | { |
761 | return Precision::IsInfinite(par) ? ( par <0 ? -10000. : 10000. ) : par; |
762 | } |
763 | |
764 | static void GetLimitedBounds (const Handle(Geom_Surface) &surf, |
765 | Standard_Real &U1, Standard_Real &U2, |
766 | Standard_Real &V1, Standard_Real &V2) |
767 | { |
768 | surf->Bounds ( U1, U2, V1, V2 ); |
769 | U1 = LimitValue ( U1 ); |
770 | U2 = LimitValue ( U2 ); |
771 | V1 = LimitValue ( V1 ); |
772 | V2 = LimitValue ( V2 ); |
773 | } |
774 | |
775 | Standard_Boolean ShapeExtend_CompositeSurface::CheckConnectivity (const Standard_Real Prec) |
776 | { |
777 | const Standard_Integer NPOINTS = 23; |
778 | Standard_Boolean ok = Standard_True; |
779 | Standard_Integer NbU = NbUPatches(); |
780 | Standard_Integer NbV = NbVPatches(); |
781 | |
782 | // check in u direction |
783 | Standard_Integer i,j; // svv Jan 10 2000 : porting on DEC |
784 | for ( i=1, j = NbU; i <= NbU; j = i++ ) { |
785 | Standard_Real maxdist2 = 0.; |
786 | for ( Standard_Integer k=1; k <= NbV; k++ ) { |
787 | Handle(Geom_Surface) sj = myPatches->Value(j,k); |
788 | Handle(Geom_Surface) si = myPatches->Value(i,k); |
789 | Standard_Real Uj1, Uj2, Vj1, Vj2; |
790 | GetLimitedBounds ( sj, Uj1, Uj2, Vj1, Vj2 ); |
791 | Standard_Real Ui1, Ui2, Vi1, Vi2; |
792 | GetLimitedBounds ( si, Ui1, Ui2, Vi1, Vi2 ); |
793 | Standard_Real stepj = ( Vj2 - Vj1 ) / ( NPOINTS - 1 ); |
794 | Standard_Real stepi = ( Vi2 - Vi1 ) / ( NPOINTS - 1 ); |
795 | for ( Standard_Integer isample=0; isample < NPOINTS; isample++ ) { |
796 | Standard_Real parj = Vj1 + stepj * isample; |
797 | Standard_Real pari = Vi1 + stepi * isample; |
798 | Standard_Real dist2 = sj->Value ( Uj2, parj ).SquareDistance ( si->Value ( Ui1, pari ) ); |
799 | if ( maxdist2 < dist2 ) maxdist2 = dist2; |
800 | } |
801 | } |
802 | if ( i==1 ) myUClosed = ( maxdist2 <= Prec*Prec ); |
803 | else if ( maxdist2 > Prec*Prec ) ok = Standard_False; |
804 | } |
805 | |
806 | // check in v direction |
807 | for ( i=1, j = NbV; i <= NbV; j = i++ ) { |
808 | Standard_Real maxdist2 = 0.; |
809 | for ( Standard_Integer k=1; k <= NbU; k++ ) { |
810 | Handle(Geom_Surface) sj = myPatches->Value(k,j); |
811 | Handle(Geom_Surface) si = myPatches->Value(k,i); |
812 | Standard_Real Uj1, Uj2, Vj1, Vj2; |
813 | GetLimitedBounds ( sj, Uj1, Uj2, Vj1, Vj2 ); |
814 | Standard_Real Ui1, Ui2, Vi1, Vi2; |
815 | GetLimitedBounds ( si, Ui1, Ui2, Vi1, Vi2 ); |
816 | Standard_Real stepj = ( Uj2 - Uj1 ) / ( NPOINTS - 1 ); |
817 | Standard_Real stepi = ( Ui2 - Ui1 ) / ( NPOINTS - 1 ); |
818 | for ( Standard_Integer isample=0; isample < NPOINTS; isample++ ) { |
819 | Standard_Real parj = Uj1 + stepj * isample; |
820 | Standard_Real pari = Ui1 + stepi * isample; |
821 | Standard_Real dist2 = sj->Value ( parj, Vj2 ).SquareDistance ( si->Value ( pari, Vi1 ) ); |
822 | if ( maxdist2 < dist2 ) maxdist2 = dist2; |
823 | } |
824 | } |
825 | if ( i==1 ) myVClosed = ( maxdist2 <= Prec*Prec ); |
826 | else if ( maxdist2 > Prec*Prec ) ok = Standard_False; |
827 | } |
828 | |
63c629aa |
829 | #ifdef SHAPEEXTEND_DEB |
7fd59977 |
830 | if ( ! ok ) cout << "Warning: ShapeExtend_CompositeSurface: not connected in 3d" << endl; |
831 | #endif |
832 | return ok; |
833 | } |