0026063: GeomAPI_ExtremaCurveSurface have inexact API
[occt.git] / src / GeomAdaptor / GeomAdaptor_Surface.cxx
CommitLineData
b311480e 1// Created on: 1993-05-14
2// Created by: Joelle CHAUVET
3// Copyright (c) 1993-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// Modified: Thu Nov 26 16:37:18 1998
7fd59977 18// correction in NbUIntervals for SurfaceOfLinearExtrusion
19// (PRO16346)
20
21#define No_Standard_RangeError
22#define No_Standard_OutOfRange
23#define PosTol (Precision::PConfusion()*0.5)
24
25#include <GeomAdaptor_Surface.ixx>
26
27#include <GeomAdaptor_HSurface.hxx>
28#include <GeomAdaptor_HCurve.hxx>
29#include <GeomAdaptor_Curve.hxx>
30#include <Adaptor3d_HSurface.hxx>
31#include <Standard_OutOfRange.hxx>
32#include <Geom_RectangularTrimmedSurface.hxx>
33#include <Geom_BSplineSurface.hxx>
34#include <Geom_BezierSurface.hxx>
35#include <Geom_OffsetSurface.hxx>
36//#include <GeomConvert_BSplineSurfaceKnotSplitting.hxx>
37#include <Standard_OutOfRange.hxx>
38#include <TColStd_HArray1OfInteger.hxx>
39#include <TColStd_Array1OfReal.hxx>
40#include <TColStd_Array1OfInteger.hxx>
41#include <Geom_Plane.hxx>
42#include <Geom_CylindricalSurface.hxx>
43#include <Geom_SphericalSurface.hxx>
44#include <Geom_ToroidalSurface.hxx>
45#include <Geom_ConicalSurface.hxx>
46#include <Geom_SurfaceOfRevolution.hxx>
47#include <Geom_SurfaceOfLinearExtrusion.hxx>
48#include <Geom_Curve.hxx>
49#include <Geom_Circle.hxx>
50#include <gp_Circ.hxx>
51#include <gp_Lin.hxx>
52#include <gp_Trsf.hxx>
53#include <BSplCLib.hxx>
54#include <Precision.hxx>
55#include <Standard_NoSuchObject.hxx>
041bfce9 56#include <Standard_NullObject.hxx>
7fd59977 57
58#define myBspl (*((Handle(Geom_BSplineSurface)*)&mySurface))
59#define myExtSurf (*((Handle(Geom_SurfaceOfLinearExtrusion)*)&mySurface))
60#define myRevSurf (*((Handle(Geom_SurfaceOfRevolution)*)&mySurface))
61#define myOffSurf (*((Handle(Geom_OffsetSurface)*)&mySurface))
62
63//=======================================================================
64//function : LocalContinuity
65//purpose :
66//=======================================================================
67
68GeomAbs_Shape LocalContinuity(Standard_Integer Degree,
69 Standard_Integer Nb,
70 TColStd_Array1OfReal& TK,
71 TColStd_Array1OfInteger& TM,
72 Standard_Real PFirst,
73 Standard_Real PLast,
74 Standard_Boolean IsPeriodic)
75{
76 Standard_DomainError_Raise_if( (TK.Length()!=Nb || TM.Length()!=Nb )," ");
77 Standard_Integer Index1 = 0;
78 Standard_Integer Index2 = 0;
79 Standard_Real newFirst, newLast;
80 BSplCLib::LocateParameter(Degree,TK,TM,PFirst,IsPeriodic,1,Nb,Index1,newFirst);
81 BSplCLib::LocateParameter(Degree,TK,TM,PLast, IsPeriodic,1,Nb,Index2,newLast );
82 const Standard_Real EpsKnot = Precision::PConfusion();
83 if (Abs(newFirst-TK(Index1+1))< EpsKnot) Index1++;
84 if (Abs(newLast -TK(Index2 ))< EpsKnot) Index2--;
85 // attention aux courbes peridiques.
86 if ( (IsPeriodic) && (Index1 == Nb) )
87 Index1 = 1;
88
89 if (Index2!=Index1)
90 {
91 Standard_Integer i, Multmax = TM(Index1+1);
92 for (i = Index1+1; i<=Index2; i++) {
93 if (TM(i)>Multmax) Multmax=TM(i);
94 }
95 Multmax = Degree - Multmax;
96 if (Multmax <= 0) return GeomAbs_C0;
97 switch (Multmax) {
98 case 1: return GeomAbs_C1;
99 case 2: return GeomAbs_C2;
100 case 3: return GeomAbs_C3;
101 }
102 }
103 return GeomAbs_CN;
104}
105
106//=======================================================================
107//function : Load
108//purpose :
109//=======================================================================
110
041bfce9 111void GeomAdaptor_Surface::load(const Handle(Geom_Surface)& S,
7fd59977 112 const Standard_Real UFirst,
113 const Standard_Real ULast,
114 const Standard_Real VFirst,
115 const Standard_Real VLast,
116 const Standard_Real TolU,
117 const Standard_Real TolV)
118{
7fd59977 119 myTolU = TolU;
120 myTolV = TolV;
121 myUFirst = UFirst;
122 myULast = ULast;
123 myVFirst = VFirst;
124 myVLast = VLast;
125
126 if ( mySurface != S) {
127 mySurface = S;
128
129 const Handle(Standard_Type)& TheType = S->DynamicType();
130 if ( TheType == STANDARD_TYPE(Geom_BezierSurface))
131 mySurfaceType = GeomAbs_BezierSurface;
132 else if (TheType == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
133 Load((*((Handle(Geom_RectangularTrimmedSurface)*)&S))->BasisSurface(),
134 UFirst,ULast,VFirst,VLast);
135 }
136 else if ( TheType == STANDARD_TYPE(Geom_Plane))
137 mySurfaceType = GeomAbs_Plane;
138 else if ( TheType == STANDARD_TYPE(Geom_CylindricalSurface))
139 mySurfaceType = GeomAbs_Cylinder;
140 else if ( TheType == STANDARD_TYPE(Geom_ConicalSurface))
141 mySurfaceType = GeomAbs_Cone;
142 else if ( TheType == STANDARD_TYPE(Geom_SphericalSurface))
143 mySurfaceType = GeomAbs_Sphere;
144 else if ( TheType == STANDARD_TYPE(Geom_ToroidalSurface))
145 mySurfaceType = GeomAbs_Torus;
146 else if ( TheType == STANDARD_TYPE(Geom_SurfaceOfRevolution))
147 mySurfaceType = GeomAbs_SurfaceOfRevolution;
148 else if ( TheType == STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))
149 mySurfaceType = GeomAbs_SurfaceOfExtrusion;
150 else if ( TheType == STANDARD_TYPE(Geom_BSplineSurface)) {
151 mySurfaceType = GeomAbs_BSplineSurface;
152 myBspl = *((Handle(Geom_BSplineSurface)*)&S);
153 }
154 else if ( TheType == STANDARD_TYPE(Geom_OffsetSurface))
155 mySurfaceType = GeomAbs_OffsetSurface;
156 else
157 mySurfaceType = GeomAbs_OtherSurface;
158 }
159}
160
161// --
162// -- Global methods - Apply to the whole Surface.
163// --
164
165
166//=======================================================================
167//function : UContinuity
168//purpose :
169//=======================================================================
170
171GeomAbs_Shape GeomAdaptor_Surface::UContinuity() const
172{
173 switch (mySurfaceType)
174 {
175 case GeomAbs_BSplineSurface:
176 {
177 const Standard_Integer N = myBspl->NbUKnots();
178 TColStd_Array1OfReal TK(1,N);
179 TColStd_Array1OfInteger TM(1,N);
180 myBspl->UKnots(TK);
181 myBspl->UMultiplicities(TM);
182 return LocalContinuity(myBspl->UDegree(), myBspl->NbUKnots(), TK, TM,
183 myUFirst, myULast, IsUPeriodic());
184 }
566f8441 185 case GeomAbs_OffsetSurface:
7fd59977 186 {
187 switch(BasisSurface()->UContinuity())
188 {
566f8441 189 case GeomAbs_CN :
190 case GeomAbs_C3 : return GeomAbs_CN;
191 case GeomAbs_G2 :
192 case GeomAbs_C2 : return GeomAbs_C1;
193 case GeomAbs_G1 :
194 case GeomAbs_C1 : return GeomAbs_C0;
195 case GeomAbs_C0 : break;
7fd59977 196 }
197 Standard_NoSuchObject::Raise("GeomAdaptor_Surface::UContinuity");
566f8441 198 break;
7fd59977 199 }
566f8441 200 case GeomAbs_SurfaceOfExtrusion:
7fd59977 201 {
202 GeomAdaptor_Curve GC
203 ((*((Handle(Geom_SurfaceOfLinearExtrusion)*)&mySurface))->BasisCurve(),myUFirst,myULast);
204 return GC.Continuity();
205 }
566f8441 206 case GeomAbs_OtherSurface:
207 Standard_NoSuchObject::Raise("GeomAdaptor_Surface::UContinuity");
208 case GeomAbs_Plane:
209 case GeomAbs_Cylinder:
210 case GeomAbs_Cone:
211 case GeomAbs_Sphere:
212 case GeomAbs_Torus:
213 case GeomAbs_BezierSurface:
214 case GeomAbs_SurfaceOfRevolution: break;
7fd59977 215 }
216 return GeomAbs_CN;
217}
218
219//=======================================================================
220//function : VContinuity
221//purpose :
222//=======================================================================
223
224GeomAbs_Shape GeomAdaptor_Surface::VContinuity() const
225{
226 switch (mySurfaceType)
227 {
228 case GeomAbs_BSplineSurface:
229 {
230 const Standard_Integer N = myBspl->NbVKnots();
231 TColStd_Array1OfReal TK(1,N);
232 TColStd_Array1OfInteger TM(1,N);
233 myBspl->VKnots(TK);
234 myBspl->VMultiplicities(TM);
235 return LocalContinuity(myBspl->VDegree(), myBspl->NbVKnots(), TK, TM,
236 myVFirst, myVLast, IsVPeriodic());
237 }
566f8441 238 case GeomAbs_OffsetSurface:
7fd59977 239 {
240 switch(BasisSurface()->VContinuity())
241 {
566f8441 242 case GeomAbs_CN :
243 case GeomAbs_C3 : return GeomAbs_CN;
244 case GeomAbs_G2 :
245 case GeomAbs_C2 : return GeomAbs_C1;
246 case GeomAbs_G1 :
247 case GeomAbs_C1 : return GeomAbs_C0;
248 case GeomAbs_C0 : break;
7fd59977 249 }
250 Standard_NoSuchObject::Raise("GeomAdaptor_Surface::VContinuity");
251 break;
252 }
566f8441 253 case GeomAbs_SurfaceOfRevolution:
7fd59977 254 {
255 GeomAdaptor_Curve GC
256 ((*((Handle(Geom_SurfaceOfRevolution)*)&mySurface))->BasisCurve(),myVFirst,myVLast);
257 return GC.Continuity();
258 }
566f8441 259 case GeomAbs_OtherSurface:
260 Standard_NoSuchObject::Raise("GeomAdaptor_Surface::VContinuity");
261 case GeomAbs_Plane:
262 case GeomAbs_Cylinder:
263 case GeomAbs_Cone:
264 case GeomAbs_Sphere:
265 case GeomAbs_Torus:
266 case GeomAbs_BezierSurface:
267 case GeomAbs_SurfaceOfExtrusion: break;
7fd59977 268 }
269 return GeomAbs_CN;
270}
271
272//=======================================================================
273//function : NbUIntervals
274//purpose :
275//=======================================================================
276
277Standard_Integer GeomAdaptor_Surface::NbUIntervals(const GeomAbs_Shape S) const
278{
279 switch (mySurfaceType)
280 {
281 case GeomAbs_BSplineSurface:
282 {
283 GeomAdaptor_Curve myBasisCurve
284 (myBspl->VIso(myBspl->VKnot(myBspl->FirstVKnotIndex())),myUFirst,myULast);
285 return myBasisCurve.NbIntervals(S);
286 }
566f8441 287 case GeomAbs_SurfaceOfExtrusion:
7fd59977 288 {
289 GeomAdaptor_Curve myBasisCurve
290 ((*((Handle(Geom_SurfaceOfLinearExtrusion)*)&mySurface))->BasisCurve(),myUFirst,myULast);
291 if (myBasisCurve.GetType() == GeomAbs_BSplineCurve)
292 return myBasisCurve.NbIntervals(S);
293 break;
294 }
566f8441 295 case GeomAbs_OffsetSurface:
7fd59977 296 {
297 GeomAbs_Shape BaseS = GeomAbs_CN;
298 switch(S)
299 {
300 case GeomAbs_G1:
301 case GeomAbs_G2: Standard_DomainError::Raise("GeomAdaptor_Curve::NbUIntervals");
302 case GeomAbs_C0: BaseS = GeomAbs_C1; break;
303 case GeomAbs_C1: BaseS = GeomAbs_C2; break;
304 case GeomAbs_C2: BaseS = GeomAbs_C3; break;
566f8441 305 case GeomAbs_C3:
306 case GeomAbs_CN: break;
7fd59977 307 }
308 GeomAdaptor_Surface Sur((*((Handle(Geom_OffsetSurface)*)&mySurface))->BasisSurface());
309 return Sur.NbUIntervals(BaseS);
310 }
566f8441 311 case GeomAbs_Plane:
312 case GeomAbs_Cylinder:
313 case GeomAbs_Cone:
314 case GeomAbs_Sphere:
315 case GeomAbs_Torus:
316 case GeomAbs_BezierSurface:
317 case GeomAbs_OtherSurface:
318 case GeomAbs_SurfaceOfRevolution: break;
7fd59977 319 }
320 return 1;
321}
322
323//=======================================================================
324//function : NbVIntervals
325//purpose :
326//=======================================================================
327
328Standard_Integer GeomAdaptor_Surface::NbVIntervals(const GeomAbs_Shape S) const
329{
330 switch (mySurfaceType)
331 {
332 case GeomAbs_BSplineSurface:
333 {
334 GeomAdaptor_Curve myBasisCurve
335 (myBspl->UIso(myBspl->UKnot(myBspl->FirstUKnotIndex())),myVFirst,myVLast);
336 return myBasisCurve.NbIntervals(S);
337 }
566f8441 338 case GeomAbs_SurfaceOfRevolution:
7fd59977 339 {
340 GeomAdaptor_Curve myBasisCurve
341 ((*((Handle(Geom_SurfaceOfRevolution)*)&mySurface))->BasisCurve(),myVFirst,myVLast);
342 if (myBasisCurve.GetType() == GeomAbs_BSplineCurve)
343 return myBasisCurve.NbIntervals(S);
344 break;
345 }
566f8441 346 case GeomAbs_OffsetSurface:
7fd59977 347 {
348 GeomAbs_Shape BaseS = GeomAbs_CN;
349 switch(S)
350 {
351 case GeomAbs_G1:
352 case GeomAbs_G2: Standard_DomainError::Raise("GeomAdaptor_Curve::NbVIntervals");
353 case GeomAbs_C0: BaseS = GeomAbs_C1; break;
354 case GeomAbs_C1: BaseS = GeomAbs_C2; break;
355 case GeomAbs_C2: BaseS = GeomAbs_C3; break;
566f8441 356 case GeomAbs_C3:
357 case GeomAbs_CN: break;
7fd59977 358 }
359 GeomAdaptor_Surface Sur((*((Handle(Geom_OffsetSurface)*)&mySurface))->BasisSurface());
360 return Sur.NbVIntervals(BaseS);
566f8441 361 }
362 case GeomAbs_Plane:
363 case GeomAbs_Cylinder:
364 case GeomAbs_Cone:
365 case GeomAbs_Sphere:
366 case GeomAbs_Torus:
367 case GeomAbs_BezierSurface:
368 case GeomAbs_OtherSurface:
369 case GeomAbs_SurfaceOfExtrusion: break;
7fd59977 370 }
371 return 1;
372}
373
374//=======================================================================
375//function : UIntervals
376//purpose :
377//=======================================================================
378
379void GeomAdaptor_Surface::UIntervals(TColStd_Array1OfReal& T, const GeomAbs_Shape S) const
380{
381 Standard_Integer myNbUIntervals = 1;
382
383 switch (mySurfaceType)
384 {
385 case GeomAbs_BSplineSurface:
386 {
387 GeomAdaptor_Curve myBasisCurve
388 (myBspl->VIso(myBspl->VKnot(myBspl->FirstVKnotIndex())),myUFirst,myULast);
389 myNbUIntervals = myBasisCurve.NbIntervals(S);
390 myBasisCurve.Intervals(T,S);
391 break;
392 }
566f8441 393 case GeomAbs_SurfaceOfExtrusion:
7fd59977 394 {
395 GeomAdaptor_Curve myBasisCurve
396 ((*((Handle(Geom_SurfaceOfLinearExtrusion)*)&mySurface))->BasisCurve(),myUFirst,myULast);
397 if (myBasisCurve.GetType() == GeomAbs_BSplineCurve)
398 {
399 myNbUIntervals = myBasisCurve.NbIntervals(S);
400 myBasisCurve.Intervals(T,S);
401 }
402 break;
403 }
566f8441 404 case GeomAbs_OffsetSurface:
7fd59977 405 {
406 GeomAbs_Shape BaseS = GeomAbs_CN;
407 switch(S)
408 {
409 case GeomAbs_G1:
410 case GeomAbs_G2: Standard_DomainError::Raise("GeomAdaptor_Curve::UIntervals");
411 case GeomAbs_C0: BaseS = GeomAbs_C1; break;
412 case GeomAbs_C1: BaseS = GeomAbs_C2; break;
413 case GeomAbs_C2: BaseS = GeomAbs_C3; break;
566f8441 414 case GeomAbs_C3:
415 case GeomAbs_CN: break;
7fd59977 416 }
417 GeomAdaptor_Surface Sur((*((Handle(Geom_OffsetSurface)*)&mySurface))->BasisSurface());
418 myNbUIntervals = Sur.NbUIntervals(BaseS);
419 Sur.UIntervals(T, BaseS);
420 }
566f8441 421 case GeomAbs_Plane:
422 case GeomAbs_Cylinder:
423 case GeomAbs_Cone:
424 case GeomAbs_Sphere:
425 case GeomAbs_Torus:
426 case GeomAbs_BezierSurface:
427 case GeomAbs_OtherSurface:
428 case GeomAbs_SurfaceOfRevolution: break;
7fd59977 429 }
430
431 T(T.Lower()) = myUFirst;
432 T(T.Lower() + myNbUIntervals) = myULast;
433}
434
435//=======================================================================
436//function : VIntervals
437//purpose :
438//=======================================================================
439
440void GeomAdaptor_Surface::VIntervals(TColStd_Array1OfReal& T, const GeomAbs_Shape S) const
441{
442 Standard_Integer myNbVIntervals = 1;
443
444 switch (mySurfaceType)
445 {
446 case GeomAbs_BSplineSurface:
447 {
448 GeomAdaptor_Curve myBasisCurve
449 (myBspl->UIso(myBspl->UKnot(myBspl->FirstUKnotIndex())),myVFirst,myVLast);
450 myNbVIntervals = myBasisCurve.NbIntervals(S);
451 myBasisCurve.Intervals(T,S);
452 break;
453 }
566f8441 454 case GeomAbs_SurfaceOfRevolution:
7fd59977 455 {
456 GeomAdaptor_Curve myBasisCurve
457 ((*((Handle(Geom_SurfaceOfRevolution)*)&mySurface))->BasisCurve(),myVFirst,myVLast);
458 if (myBasisCurve.GetType() == GeomAbs_BSplineCurve)
459 {
460 myNbVIntervals = myBasisCurve.NbIntervals(S);
461 myBasisCurve.Intervals(T,S);
462 }
463 break;
464 }
566f8441 465 case GeomAbs_OffsetSurface:
7fd59977 466 {
467 GeomAbs_Shape BaseS = GeomAbs_CN;
468 switch(S)
469 {
470 case GeomAbs_G1:
471 case GeomAbs_G2: Standard_DomainError::Raise("GeomAdaptor_Curve::VIntervals");
472 case GeomAbs_C0: BaseS = GeomAbs_C1; break;
473 case GeomAbs_C1: BaseS = GeomAbs_C2; break;
474 case GeomAbs_C2: BaseS = GeomAbs_C3; break;
566f8441 475 case GeomAbs_C3:
476 case GeomAbs_CN: break;
7fd59977 477 }
478 GeomAdaptor_Surface Sur((*((Handle(Geom_OffsetSurface)*)&mySurface))->BasisSurface());
479 myNbVIntervals = Sur.NbVIntervals(BaseS);
480 Sur.VIntervals(T, BaseS);
481 }
566f8441 482 case GeomAbs_Plane:
483 case GeomAbs_Cylinder:
484 case GeomAbs_Cone:
485 case GeomAbs_Sphere:
486 case GeomAbs_Torus:
487 case GeomAbs_BezierSurface:
488 case GeomAbs_OtherSurface:
489 case GeomAbs_SurfaceOfExtrusion: break;
7fd59977 490 }
491
492 T(T.Lower()) = myVFirst;
493 T(T.Lower() + myNbVIntervals) = myVLast;
494}
495
496//=======================================================================
497//function : UTrim
498//purpose :
499//=======================================================================
500
501Handle(Adaptor3d_HSurface) GeomAdaptor_Surface::UTrim(const Standard_Real First,
502 const Standard_Real Last ,
503 const Standard_Real Tol ) const
504{
505 return Handle(GeomAdaptor_HSurface)
506 (new GeomAdaptor_HSurface(mySurface,First,Last,myVFirst,myVLast,Tol,myTolV));
507}
508
509//=======================================================================
510//function : VTrim
511//purpose :
512//=======================================================================
513
514Handle(Adaptor3d_HSurface) GeomAdaptor_Surface::VTrim(const Standard_Real First,
515 const Standard_Real Last ,
516 const Standard_Real Tol ) const
517{
518 return Handle(GeomAdaptor_HSurface)
519 (new GeomAdaptor_HSurface(mySurface,myUFirst,myULast,First,Last,myTolU,Tol));
520}
521
522//=======================================================================
523//function : IsUClosed
524//purpose :
525//=======================================================================
526
527Standard_Boolean GeomAdaptor_Surface::IsUClosed() const
528{
529 if (!mySurface->IsUClosed())
530 return Standard_False;
531
532 Standard_Real U1,U2,V1,V2;
533 mySurface->Bounds(U1,U2,V1,V2);
534 if (mySurface->IsUPeriodic())
535 return (Abs(Abs(U1-U2)-Abs(myUFirst-myULast))<Precision::PConfusion());
536
537 return ( Abs(U1-myUFirst)<Precision::PConfusion()
538 && Abs(U2-myULast )<Precision::PConfusion() );
539}
540
541//=======================================================================
542//function : IsVClosed
543//purpose :
544//=======================================================================
545
546Standard_Boolean GeomAdaptor_Surface::IsVClosed() const
547{
548 if (!mySurface->IsVClosed())
549 return Standard_False;
550
551 Standard_Real U1,U2,V1,V2;
552 mySurface->Bounds(U1,U2,V1,V2);
553 if (mySurface->IsVPeriodic())
554 return (Abs(Abs(V1-V2)-Abs(myVFirst-myVLast))<Precision::PConfusion());
555
556 return ( Abs(V1-myVFirst)<Precision::PConfusion()
557 && Abs(V2-myVLast )<Precision::PConfusion() );
558}
559
560//=======================================================================
561//function : IsUPeriodic
562//purpose :
563//=======================================================================
564
565Standard_Boolean GeomAdaptor_Surface::IsUPeriodic() const
566{
567 return (mySurface->IsUPeriodic());
568}
569
570//=======================================================================
571//function : UPeriod
572//purpose :
573//=======================================================================
574
575Standard_Real GeomAdaptor_Surface::UPeriod() const
576{
577 Standard_NoSuchObject_Raise_if(!IsUPeriodic()," ");
578 return mySurface->UPeriod();
579}
580
581//=======================================================================
582//function : IsVPeriodic
583//purpose :
584//=======================================================================
585
586Standard_Boolean GeomAdaptor_Surface::IsVPeriodic() const
587{
588 return (mySurface->IsVPeriodic());
589}
590
591//=======================================================================
592//function : VPeriod
593//purpose :
594//=======================================================================
595
596Standard_Real GeomAdaptor_Surface::VPeriod() const
597{
598 Standard_NoSuchObject_Raise_if(!IsVPeriodic()," ");
599 return mySurface->VPeriod();
600}
601
602//=======================================================================
603//function : Value
604//purpose :
605//=======================================================================
606
607gp_Pnt GeomAdaptor_Surface::Value(const Standard_Real U,
608 const Standard_Real V) const
609{
610 return mySurface->Value(U,V);
611}
612
613//=======================================================================
614//function : D0
615//purpose :
616//=======================================================================
617
618void GeomAdaptor_Surface::D0(const Standard_Real U,
619 const Standard_Real V, gp_Pnt& P) const
620{
621 mySurface->D0(U,V,P);
622}
623
624
625//=======================================================================
626//function : D1
627//purpose :
628//=======================================================================
629
630void GeomAdaptor_Surface::D1(const Standard_Real U,
631 const Standard_Real V,
632 gp_Pnt& P,
633 gp_Vec& D1U,
634 gp_Vec& D1V ) const
635{
636 Standard_Integer Ideb,Ifin,IVdeb,IVfin,USide=0,VSide=0;
637 Standard_Real u = U, v = V;
638 if (Abs(U-myUFirst) <= myTolU) {USide= 1; u = myUFirst;}
639 else if (Abs(U-myULast) <= myTolU) {USide= -1; u = myULast;}
640 if (Abs(V-myVFirst) <= myTolV) {VSide= 1; v = myVFirst;}
641 else if (Abs(V-myVLast) <= myTolV) {VSide= -1; v = myVLast;}
642
643 switch(mySurfaceType) {
644 case GeomAbs_BSplineSurface:
645 {
646 if((USide==0)&&(VSide==0)){
647 myBspl->D1(u,v,P,D1U,D1V);
648 }
649 else {
650 if(IfUVBound(u,v,Ideb,Ifin,IVdeb,IVfin,USide,VSide))
651 myBspl->LocalD1 (u, v, Ideb, Ifin,IVdeb ,IVfin ,P ,D1U,D1V);
652 else myBspl->D1(u,v,P,D1U,D1V);
653 }
654 break;
655 }
656
657 case GeomAbs_SurfaceOfExtrusion :
658
659 if(USide==0) myExtSurf->D1(u,v,P,D1U,D1V);
660 else myExtSurf->LocalD1(u,v,USide,P,D1U,D1V);
661 break;
662
663 case GeomAbs_SurfaceOfRevolution :
664
665 if(VSide==0) myRevSurf->D1 (u, v, P,D1U,D1V );
666 else myRevSurf->LocalD1 (u, v, VSide, P,D1U,D1V );
667 break;
668
669 case GeomAbs_OffsetSurface :
670 {
671 if((USide==0)&&(VSide==0)) myOffSurf->D1 (u, v,P,D1U,D1V );
672 else myOffSurf->LocalD1 (u, v, USide, VSide ,P,D1U,D1V );
673 break;
674 }
675 default :
676 mySurface->D1(u,v,P,D1U,D1V);
677 }
678}
679
680//=======================================================================
681//function : D2
682//purpose :
683//=======================================================================
684
685void GeomAdaptor_Surface::D2(const Standard_Real U,
686 const Standard_Real V, gp_Pnt& P,
687 gp_Vec& D1U, gp_Vec& D1V, gp_Vec& D2U,
688 gp_Vec& D2V, gp_Vec& D2UV) const
689{
690 Standard_Integer Ideb,Ifin,IVdeb,IVfin,USide=0,VSide=0;
691 Standard_Real u = U, v = V;
692 if (Abs(U-myUFirst) <= myTolU) {USide= 1; u = myUFirst;}
693 else if (Abs(U-myULast) <= myTolU) {USide= -1; u = myULast;}
694 if (Abs(V-myVFirst) <= myTolV) {VSide= 1; v = myVFirst;}
695 else if (Abs(V-myVLast) <= myTolV) {VSide= -1; v = myVLast;}
696
697 switch(mySurfaceType)
698 {
699 case GeomAbs_BSplineSurface:
700
701 if((USide==0)&&(VSide==0)) myBspl->D2(u,v,P,D1U,D1V,D2U,D2V,D2UV);
702 else{
703 if(IfUVBound(u,v,Ideb,Ifin,IVdeb,IVfin,USide,VSide))
704 myBspl->LocalD2 (u, v, Ideb, Ifin,IVdeb ,IVfin ,P ,D1U,D1V,D2U,D2V,D2UV);
705 else myBspl->D2(u,v,P,D1U,D1V,D2U,D2V,D2UV);
706 }
707 break;
708
709 case GeomAbs_SurfaceOfExtrusion :
710
711 if(USide==0) myExtSurf->D2(u,v,P,D1U,D1V,D2U,D2V,D2UV);
712 else myExtSurf->LocalD2(u,v,USide,P,D1U,D1V,D2U,D2V,D2UV);
713 break;
714
715 case GeomAbs_SurfaceOfRevolution :
716
717 if(VSide==0) myRevSurf->D2 (u, v, P,D1U,D1V,D2U,D2V,D2UV );
718 else myRevSurf->LocalD2 (u, v, VSide, P,D1U,D1V,D2U,D2V,D2UV );
719 break;
720
721 case GeomAbs_OffsetSurface :
722 {
723 if((USide==0)&&(VSide==0)) myOffSurf->D2 (u, v,P,D1U,D1V,D2U,D2V,D2UV );
724 else myOffSurf->LocalD2 (u, v, USide, VSide ,P,D1U,D1V,D2U,D2V,D2UV );
725 break;
726 }
727 default : { mySurface->D2(u,v,P,D1U,D1V,D2U,D2V,D2UV);
728 break;}
729 }
730}
731
732
733//=======================================================================
734//function : D3
735//purpose :
736//=======================================================================
737
738void GeomAdaptor_Surface::D3(const Standard_Real U, const Standard_Real V,
739 gp_Pnt& P, gp_Vec& D1U, gp_Vec& D1V,
740 gp_Vec& D2U, gp_Vec& D2V, gp_Vec& D2UV,
741 gp_Vec& D3U, gp_Vec& D3V, gp_Vec& D3UUV,
742 gp_Vec& D3UVV) const
743{
744 Standard_Integer Ideb,Ifin,IVdeb,IVfin,USide=0,VSide=0;
745 Standard_Real u = U, v = V;
746 if (Abs(U-myUFirst) <= myTolU) {USide= 1; u = myUFirst;}
747 else if (Abs(U-myULast) <= myTolU) {USide= -1; u = myULast;}
748 if (Abs(V-myVFirst) <= myTolV) {VSide= 1; v = myVFirst;}
749 else if (Abs(V-myVLast) <= myTolV) {VSide= -1; v = myVLast;}
750
751 switch(mySurfaceType) {
752 case GeomAbs_BSplineSurface:
753
754 if((USide==0)&&(VSide==0))
755 myBspl->D3(u,v,P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
756 else {
757 if(IfUVBound(u,v,Ideb,Ifin,IVdeb,IVfin,USide,VSide))
758 myBspl-> LocalD3 (u, v, Ideb, Ifin,IVdeb ,IVfin ,
759 P ,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
760 else
761 myBspl->D3(u,v,P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
762 }
763 break;
764
765 case GeomAbs_SurfaceOfExtrusion :
766
767 if(USide==0) myExtSurf->D3(u,v,P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
768 else myExtSurf->LocalD3(u,v,USide,P,D1U,D1V,D2U,D2V,D2UV,
769 D3U,D3V,D3UUV,D3UVV);
770 break;
771
772 case GeomAbs_SurfaceOfRevolution :
773
774 if(VSide==0) myRevSurf->D3 (u, v, P ,D1U,D1V,D2U,D2V,D2UV,
775 D3U,D3V,D3UUV,D3UVV);
776 else myRevSurf->LocalD3 (u, v, VSide, P,D1U,D1V,D2U,D2V,D2UV,
777 D3U,D3V,D3UUV,D3UVV );
778 break;
779
780 case GeomAbs_OffsetSurface :
781 {
782 if((USide==0)&&(VSide==0)) myOffSurf->D3 (u, v,P ,D1U,D1V,D2U,D2V,D2UV,
783 D3U,D3V,D3UUV,D3UVV);
784 else myOffSurf->LocalD3 (u, v, USide, VSide ,P ,D1U,D1V,D2U,D2V,D2UV,
785 D3U,D3V,D3UUV,D3UVV);
786 break;
787 }
788 default : { mySurface->D3(u,v,P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);
789 break;}
790 }
791}
792
793//=======================================================================
794//function : DN
795//purpose :
796//=======================================================================
797
798gp_Vec GeomAdaptor_Surface::DN(const Standard_Real U,
799 const Standard_Real V,
800 const Standard_Integer Nu,
801 const Standard_Integer Nv) const
802{
803 Standard_Integer Ideb,Ifin,IVdeb,IVfin,USide=0,VSide=0;
804 Standard_Real u = U, v = V;
805 if (Abs(U-myUFirst) <= myTolU) {USide= 1; u = myUFirst;}
806 else if (Abs(U-myULast) <= myTolU) {USide= -1; u = myULast;}
807 if (Abs(V-myVFirst) <= myTolV) {VSide= 1; v = myVFirst;}
808 else if (Abs(V-myVLast) <= myTolV) {VSide= -1; v = myVLast;}
809
810 switch(mySurfaceType)
811 {
812 case GeomAbs_BSplineSurface:
813
814 if((USide==0)&&(VSide==0)) return myBspl->DN(u,v,Nu,Nv);
815 else {
816 if(IfUVBound(u,v,Ideb,Ifin,IVdeb,IVfin,USide,VSide))
817 return myBspl->LocalDN (u, v, Ideb, Ifin,IVdeb ,IVfin ,Nu,Nv );
818 else
819 return myBspl->DN(u,v,Nu,Nv);
820 }
821
822 case GeomAbs_SurfaceOfExtrusion:
823
824 if(USide==0) return myExtSurf-> DN (u, v,Nu,Nv );
825 else return myExtSurf->LocalDN (u, v, USide,Nu,Nv );
826
827 case GeomAbs_SurfaceOfRevolution:
828
829 if(VSide==0) return myRevSurf->DN (u, v, Nu, Nv );
830 else return myRevSurf->LocalDN (u, v,VSide, Nu, Nv );
831
832 case GeomAbs_OffsetSurface:
833
834 if((USide==0)&&(VSide==0)) return myOffSurf->DN (u, v, Nu, Nv );
835 else return myOffSurf->LocalDN (u, v, USide, VSide, Nu, Nv );
836
837 case GeomAbs_Plane:
838 case GeomAbs_Cylinder:
839 case GeomAbs_Cone:
840 case GeomAbs_Sphere:
841 case GeomAbs_Torus:
842 case GeomAbs_BezierSurface:
843 case GeomAbs_OtherSurface:
844 default:
845 break;
846 }
847
848 return mySurface->DN(u,v, Nu, Nv);
849}
850
851
852//=======================================================================
853//function : UResolution
854//purpose :
855//=======================================================================
856
857Standard_Real GeomAdaptor_Surface::UResolution(const Standard_Real R3d) const
858{
859 Standard_Real Res = 0.;
860
861 switch (mySurfaceType)
862 {
863 case GeomAbs_SurfaceOfExtrusion:
864 {
865 GeomAdaptor_Curve myBasisCurve
866 ((*((Handle(Geom_SurfaceOfLinearExtrusion)*)&mySurface))->BasisCurve(),myUFirst,myULast);
867 return myBasisCurve.Resolution(R3d);
868 }
869 case GeomAbs_Torus:
870 {
871 Handle(Geom_ToroidalSurface)& S = *((Handle(Geom_ToroidalSurface)*)&mySurface);
872 const Standard_Real R = S->MajorRadius() + S->MinorRadius();
873 if(R>Precision::Confusion())
874 Res = R3d/(2.*R);
875 break;
876 }
877 case GeomAbs_Sphere:
878 {
879 Handle(Geom_SphericalSurface)& S = *((Handle(Geom_SphericalSurface)*)&mySurface);
880 const Standard_Real R = S->Radius();
881 if(R>Precision::Confusion())
882 Res = R3d/(2.*R);
883 break;
884 }
885 case GeomAbs_Cylinder:
886 {
887 Handle(Geom_CylindricalSurface)& S = *((Handle(Geom_CylindricalSurface)*)&mySurface);
888 const Standard_Real R = S->Radius();
889 if(R>Precision::Confusion())
890 Res = R3d/(2.*R);
891 break;
892 }
893 case GeomAbs_Cone:
894 {
895 if (myVLast - myVFirst > 1.e10) {
896 // Pas vraiment borne => resolution inconnue
897 return Precision::Parametric(R3d);
898 }
899 Handle(Geom_ConicalSurface)& S = *((Handle(Geom_ConicalSurface)*)&mySurface);
900 Handle(Geom_Curve) C = S->VIso(myVLast);
901 const Standard_Real Rayon1 = (*((Handle(Geom_Circle)*)&C))->Radius();
902 C = S->VIso(myVFirst);
903 const Standard_Real Rayon2 = (*((Handle(Geom_Circle)*)&C))->Radius();
904 const Standard_Real R = (Rayon1 > Rayon2)? Rayon1 : Rayon2;
905 return (R>Precision::Confusion()? (R3d / R) : 0.);
906 }
907 case GeomAbs_Plane:
908 {
909 return R3d;
910 }
911 case GeomAbs_BezierSurface:
912 {
913 Standard_Real Ures,Vres;
914 (*((Handle(Geom_BezierSurface)*)&mySurface))->Resolution(R3d,Ures,Vres);
915 return Ures;
916 }
917 case GeomAbs_BSplineSurface:
918 {
919 Standard_Real Ures,Vres;
920 (*((Handle(Geom_BSplineSurface)*)&mySurface))->Resolution(R3d,Ures,Vres);
921 return Ures;
922 }
923 case GeomAbs_OffsetSurface:
924 {
925 Handle(Geom_Surface) base = (*((Handle(Geom_OffsetSurface)*)&mySurface))->BasisSurface();
926 GeomAdaptor_Surface gabase(base,myUFirst,myULast,myVFirst,myVLast);
927 return gabase.UResolution(R3d);
928 }
929 default: return Precision::Parametric(R3d);
930 }
931
932 if ( Res <= 1.)
933 return 2.*ASin(Res);
934
c6541a0c 935 return 2.*M_PI;
7fd59977 936}
937
938//=======================================================================
939//function : VResolution
940//purpose :
941//=======================================================================
942
943Standard_Real GeomAdaptor_Surface::VResolution(const Standard_Real R3d) const
944{
945 Standard_Real Res = 0.;
946
947 switch (mySurfaceType)
948 {
949 case GeomAbs_SurfaceOfRevolution:
950 {
951 GeomAdaptor_Curve myBasisCurve
952 ((*((Handle(Geom_SurfaceOfRevolution)*)&mySurface))->BasisCurve(),myUFirst,myULast);
953 return myBasisCurve.Resolution(R3d);
954 }
955 case GeomAbs_Torus:
956 {
957 Handle(Geom_ToroidalSurface)& S = *((Handle(Geom_ToroidalSurface)*)&mySurface);
958 const Standard_Real R = S->MinorRadius();
959 if(R>Precision::Confusion())
960 Res = R3d/(2.*R);
961 break;
962 }
963 case GeomAbs_Sphere:
964 {
965 Handle(Geom_SphericalSurface)& S = *((Handle(Geom_SphericalSurface)*)&mySurface);
966 const Standard_Real R = S->Radius();
967 if(R>Precision::Confusion())
968 Res = R3d/(2.*R);
969 break;
970 }
971 case GeomAbs_SurfaceOfExtrusion:
972 case GeomAbs_Cylinder:
973 case GeomAbs_Cone:
974 case GeomAbs_Plane:
975 {
976 return R3d;
977 }
978 case GeomAbs_BezierSurface:
979 {
980 Standard_Real Ures,Vres;
981 (*((Handle(Geom_BezierSurface)*)&mySurface))->Resolution(R3d,Ures,Vres);
982 return Vres;
983 }
984 case GeomAbs_BSplineSurface:
985 {
986 Standard_Real Ures,Vres;
987 (*((Handle(Geom_BSplineSurface)*)&mySurface))->Resolution(R3d,Ures,Vres);
988 return Vres;
989 }
990 case GeomAbs_OffsetSurface:
991 {
992 Handle(Geom_Surface) base = (*((Handle(Geom_OffsetSurface)*)&mySurface))->BasisSurface();
993 GeomAdaptor_Surface gabase(base,myUFirst,myULast,myVFirst,myVLast);
994 return gabase.VResolution(R3d);
995 }
996 default: return Precision::Parametric(R3d);
997 }
998
999 if ( Res <= 1.)
1000 return 2.*ASin(Res);
1001
c6541a0c 1002 return 2.*M_PI;
7fd59977 1003}
1004
1005//=======================================================================
1006//function : Plane
1007//purpose :
1008//=======================================================================
1009
1010gp_Pln GeomAdaptor_Surface::Plane() const
1011{
1012 if (mySurfaceType != GeomAbs_Plane)
1013 Standard_NoSuchObject::Raise("GeomAdaptor_Surface::Plane");
1014 return (*((Handle(Geom_Plane)*)&mySurface))->Pln();
1015}
1016
1017//=======================================================================
1018//function : Cylinder
1019//purpose :
1020//=======================================================================
1021
1022gp_Cylinder GeomAdaptor_Surface::Cylinder() const
1023{
1024 if (mySurfaceType != GeomAbs_Cylinder)
1025 Standard_NoSuchObject::Raise("GeomAdaptor_Surface::Cylinder");
1026 return (*((Handle(Geom_CylindricalSurface)*)&mySurface))->Cylinder();
1027}
1028
1029//=======================================================================
1030//function : Cone
1031//purpose :
1032//=======================================================================
1033
1034gp_Cone GeomAdaptor_Surface::Cone() const
1035{
1036 if (mySurfaceType != GeomAbs_Cone)
1037 Standard_NoSuchObject::Raise("GeomAdaptor_Surface::Cone");
1038 return (*((Handle(Geom_ConicalSurface)*)&mySurface))->Cone();
1039}
1040
1041//=======================================================================
1042//function : Sphere
1043//purpose :
1044//=======================================================================
1045
1046gp_Sphere GeomAdaptor_Surface::Sphere() const
1047{
1048 if (mySurfaceType != GeomAbs_Sphere)
1049 Standard_NoSuchObject::Raise("GeomAdaptor_Surface::Sphere");
1050 return (*((Handle(Geom_SphericalSurface)*)&mySurface))->Sphere();
1051}
1052
1053//=======================================================================
1054//function : Torus
1055//purpose :
1056//=======================================================================
1057
1058gp_Torus GeomAdaptor_Surface::Torus() const
1059{
1060 if (mySurfaceType != GeomAbs_Torus)
1061 Standard_NoSuchObject::Raise("GeomAdaptor_Surface::Torus");
1062 return (*((Handle(Geom_ToroidalSurface)*)&mySurface))->Torus();
1063}
1064
1065//=======================================================================
1066//function : UDegree
1067//purpose :
1068//=======================================================================
1069
1070Standard_Integer GeomAdaptor_Surface::UDegree() const
1071{
1072 if (mySurfaceType == GeomAbs_BSplineSurface)
1073 return (*((Handle(Geom_BSplineSurface)*)&mySurface))->UDegree();
1074 if ( mySurfaceType == GeomAbs_BezierSurface)
1075 return (*((Handle(Geom_BezierSurface)*)&mySurface))->UDegree();
1076 if ( mySurfaceType == GeomAbs_SurfaceOfExtrusion)
1077 {
1078 GeomAdaptor_Curve myBasisCurve
1079 ((*((Handle(Geom_SurfaceOfLinearExtrusion)*)&mySurface))->BasisCurve(),myUFirst,myULast);
1080 return myBasisCurve.Degree();
1081 }
1082 Standard_NoSuchObject::Raise("GeomAdaptor_Surface::UDegree");
1083 return 0;
1084}
1085
1086//=======================================================================
1087//function : NbUPoles
1088//purpose :
1089//=======================================================================
1090
1091Standard_Integer GeomAdaptor_Surface::NbUPoles() const
1092{
1093 if (mySurfaceType == GeomAbs_BSplineSurface)
1094 return (*((Handle(Geom_BSplineSurface)*)&mySurface))->NbUPoles();
1095 if ( mySurfaceType == GeomAbs_BezierSurface)
1096 return (*((Handle(Geom_BezierSurface)*)&mySurface))->NbUPoles();
1097 if ( mySurfaceType == GeomAbs_SurfaceOfExtrusion)
1098 {
1099 GeomAdaptor_Curve myBasisCurve
1100 ((*((Handle(Geom_SurfaceOfLinearExtrusion)*)&mySurface))->BasisCurve(),myUFirst,myULast);
1101 return myBasisCurve.NbPoles();
1102 }
1103 Standard_NoSuchObject::Raise("GeomAdaptor_Surface::NbUPoles");
1104 return 0;
1105}
1106
1107//=======================================================================
1108//function : VDegree
1109//purpose :
1110//=======================================================================
1111
1112Standard_Integer GeomAdaptor_Surface::VDegree() const
1113{
1114 if (mySurfaceType == GeomAbs_BSplineSurface)
1115 return (*((Handle(Geom_BSplineSurface)*)&mySurface))->VDegree();
1116 if ( mySurfaceType == GeomAbs_BezierSurface)
1117 return (*((Handle(Geom_BezierSurface)*)&mySurface))->VDegree();
1118 if ( mySurfaceType == GeomAbs_SurfaceOfRevolution)
1119 {
1120 GeomAdaptor_Curve myBasisCurve
1121 ((*((Handle(Geom_SurfaceOfRevolution)*)&mySurface))->BasisCurve(),myUFirst,myULast);
1122 return myBasisCurve.Degree();
1123 }
1124 Standard_NoSuchObject::Raise("GeomAdaptor_Surface::VDegree");
1125 return 0;
1126}
1127
1128//=======================================================================
1129//function : NbVPoles
1130//purpose :
1131//=======================================================================
1132
1133Standard_Integer GeomAdaptor_Surface::NbVPoles() const
1134{
1135 if (mySurfaceType == GeomAbs_BSplineSurface)
1136 return (*((Handle(Geom_BSplineSurface)*)&mySurface))->NbVPoles();
1137 if ( mySurfaceType == GeomAbs_BezierSurface)
1138 return (*((Handle(Geom_BezierSurface)*)&mySurface))->NbVPoles();
1139 if ( mySurfaceType == GeomAbs_SurfaceOfRevolution)
1140 {
1141 GeomAdaptor_Curve myBasisCurve
1142 ((*((Handle(Geom_SurfaceOfRevolution)*)&mySurface))->BasisCurve(),myUFirst,myULast);
1143 return myBasisCurve.NbPoles();
1144 }
1145 Standard_NoSuchObject::Raise("GeomAdaptor_Surface::NbVPoles");
1146 return 0;
1147}
1148
1149//=======================================================================
1150//function : NbUKnots
1151//purpose :
1152//=======================================================================
1153
1154Standard_Integer GeomAdaptor_Surface::NbUKnots() const
1155{
1156 if (mySurfaceType == GeomAbs_BSplineSurface)
1157 return (*((Handle(Geom_BSplineSurface)*)&mySurface))->NbUKnots();
1158 if ( mySurfaceType == GeomAbs_SurfaceOfExtrusion)
1159 {
1160 GeomAdaptor_Curve myBasisCurve
1161 ((*((Handle(Geom_SurfaceOfLinearExtrusion)*)&mySurface))->BasisCurve(),myUFirst,myULast);
1162 return myBasisCurve.NbKnots();
1163 }
1164 Standard_NoSuchObject::Raise("GeomAdaptor_Surface::NbUKnots");
1165 return 0;
1166}
1167
1168//=======================================================================
1169//function : NbVKnots
1170//purpose :
1171//=======================================================================
1172
1173Standard_Integer GeomAdaptor_Surface::NbVKnots() const
1174{
1175 if (mySurfaceType == GeomAbs_BSplineSurface)
1176 return (*((Handle(Geom_BSplineSurface)*)&mySurface))->NbVKnots();
1177 Standard_NoSuchObject::Raise("GeomAdaptor_Surface::NbVKnots");
1178 return 0;
1179}
1180//=======================================================================
1181//function : IsURational
1182//purpose :
1183//=======================================================================
1184
1185Standard_Boolean GeomAdaptor_Surface::IsURational() const
1186{
1187 if (mySurfaceType == GeomAbs_BSplineSurface)
1188 return (*((Handle(Geom_BSplineSurface)*)&mySurface))->IsURational();
1189 if (mySurfaceType == GeomAbs_BezierSurface)
1190 return (*((Handle(Geom_BezierSurface)*)&mySurface))->IsURational();
1191 return Standard_False;
1192}
1193
1194//=======================================================================
1195//function : IsVRational
1196//purpose :
1197//=======================================================================
1198
1199Standard_Boolean GeomAdaptor_Surface::IsVRational() const
1200{
1201 if (mySurfaceType == GeomAbs_BSplineSurface)
1202 return (*((Handle(Geom_BSplineSurface)*)&mySurface))->IsVRational();
1203 if (mySurfaceType == GeomAbs_BezierSurface)
1204 return (*((Handle(Geom_BezierSurface)*)&mySurface))->IsVRational();
1205 return Standard_False;
1206}
1207
1208//=======================================================================
1209//function : Bezier
1210//purpose :
1211//=======================================================================
1212
1213Handle(Geom_BezierSurface) GeomAdaptor_Surface::Bezier() const
1214{
1215 if (mySurfaceType != GeomAbs_BezierSurface)
1216 Standard_NoSuchObject::Raise("GeomAdaptor_Surface::Bezier");
1217 return *((Handle(Geom_BezierSurface)*)&mySurface);
1218}
1219
1220//=======================================================================
1221//function : BSpline
1222//purpose :
1223//=======================================================================
1224
1225Handle(Geom_BSplineSurface) GeomAdaptor_Surface::BSpline() const
1226{
1227 if (mySurfaceType != GeomAbs_BSplineSurface)
1228 Standard_NoSuchObject::Raise("GeomAdaptor_Surface::BSpline");
1229 return *((Handle(Geom_BSplineSurface)*)&mySurface);
1230}
1231
1232//=======================================================================
1233//function : AxeOfRevolution
1234//purpose :
1235//=======================================================================
1236
1237gp_Ax1 GeomAdaptor_Surface::AxeOfRevolution() const
1238{
1239 if (mySurfaceType != GeomAbs_SurfaceOfRevolution)
1240 Standard_NoSuchObject::Raise("GeomAdaptor_Surface::AxeOfRevolution");
1241 return (*((Handle(Geom_SurfaceOfRevolution)*)&mySurface))->Axis();
1242}
1243
1244//=======================================================================
1245//function : Direction
1246//purpose :
1247//=======================================================================
1248
1249gp_Dir GeomAdaptor_Surface::Direction() const
1250{
1251 if (mySurfaceType != GeomAbs_SurfaceOfExtrusion)
1252 Standard_NoSuchObject::Raise("GeomAdaptor_Surface::Direction");
1253 return (*((Handle(Geom_SurfaceOfLinearExtrusion)*)&mySurface))->Direction();
1254}
1255
1256//=======================================================================
1257//function : BasisCurve
1258//purpose :
1259//=======================================================================
1260
1261Handle(Adaptor3d_HCurve) GeomAdaptor_Surface::BasisCurve() const
1262{
1263 Handle(Geom_Curve) C;
1264 if (mySurfaceType == GeomAbs_SurfaceOfExtrusion)
1265 C = (*((Handle(Geom_SurfaceOfLinearExtrusion)*)&mySurface))->BasisCurve();
1266 else if (mySurfaceType == GeomAbs_SurfaceOfRevolution)
1267 C = (*((Handle(Geom_SurfaceOfRevolution)*)&mySurface))->BasisCurve();
1268 else
1269 Standard_NoSuchObject::Raise("GeomAdaptor_Surface::BasisCurve");
1270 return Handle(GeomAdaptor_HCurve)(new GeomAdaptor_HCurve(C));
1271}
1272
1273//=======================================================================
1274//function : BasisSurface
1275//purpose :
1276//=======================================================================
1277
1278Handle(Adaptor3d_HSurface) GeomAdaptor_Surface::BasisSurface() const
1279{
1280 if (mySurfaceType != GeomAbs_OffsetSurface)
1281 Standard_NoSuchObject::Raise("GeomAdaptor_Surface::BasisSurface");
1282 return new GeomAdaptor_HSurface
1283 ((*((Handle(Geom_OffsetSurface)*)&mySurface))->BasisSurface(),
1284 myUFirst,myULast,myVFirst,myVLast);
1285}
1286
1287//=======================================================================
1288//function : OffsetValue
1289//purpose :
1290//=======================================================================
1291
1292Standard_Real GeomAdaptor_Surface::OffsetValue() const
1293{
1294 if (mySurfaceType != GeomAbs_OffsetSurface)
1295 Standard_NoSuchObject::Raise("GeomAdaptor_Surface::BasisSurface");
1296 return (*((Handle(Geom_OffsetSurface)*)&mySurface))->Offset();
1297}
1298
1299//=======================================================================
1300//function : IfUVBound <private>
1301//purpose : locates U,V parameters if U,V =First, Last,
1302// processes the finding span and returns the
1303// parameters for LocalDi
1304//=======================================================================
1305
1306Standard_Boolean GeomAdaptor_Surface::IfUVBound(const Standard_Real U,
1307 const Standard_Real V,
1308 Standard_Integer& IOutDeb,
1309 Standard_Integer& IOutFin,
1310 Standard_Integer& IOutVDeb,
1311 Standard_Integer& IOutVFin,
1312 const Standard_Integer USide,
1313 const Standard_Integer VSide) const
1314{
1315 Standard_Integer Ideb,Ifin;
470ebb43 1316 Standard_Integer anUFKIndx = myBspl->FirstUKnotIndex(),
1317 anULKIndx = myBspl->LastUKnotIndex(),
1318 aVFKIndx = myBspl->FirstVKnotIndex(), aVLKIndx = myBspl->LastVKnotIndex();
7fd59977 1319 myBspl->LocateU(U, PosTol, Ideb, Ifin, Standard_False);
1320 Standard_Boolean Local = (Ideb == Ifin);
470ebb43 1321 Span(USide,Ideb,Ifin,Ideb,Ifin,anUFKIndx,anULKIndx);
7fd59977 1322 Standard_Integer IVdeb,IVfin;
1323 myBspl->LocateV(V, PosTol, IVdeb, IVfin, Standard_False);
1324 if(IVdeb == IVfin) Local = Standard_True;
470ebb43 1325 Span(VSide,IVdeb,IVfin,IVdeb,IVfin,aVFKIndx,aVLKIndx);
7fd59977 1326
1327 IOutDeb=Ideb; IOutFin=Ifin;
1328 IOutVDeb=IVdeb; IOutVFin=IVfin;
1329
1330 return Local;
1331}
7fd59977 1332//=======================================================================
1333//function : Span <private>
1334//purpose : locates U,V parameters if U=UFirst or U=ULast,
1335// processes the finding span and returns the
1336// parameters for LocalDi
1337//=======================================================================
1338
1339void GeomAdaptor_Surface::Span(const Standard_Integer Side,
1340 const Standard_Integer Ideb,
1341 const Standard_Integer Ifin,
1342 Standard_Integer& OutIdeb,
1343 Standard_Integer& OutIfin,
470ebb43 1344 const Standard_Integer theFKIndx,
1345 const Standard_Integer theLKIndx) const
7fd59977 1346{
1347 if(Ideb!=Ifin)//not a knot
1348 {
470ebb43 1349 if(Ideb<theFKIndx) { OutIdeb=theFKIndx; OutIfin=theFKIndx+1; }
1350 else if(Ifin>theLKIndx) { OutIdeb=theLKIndx-1; OutIfin=theLKIndx; }
1351 else if(Ideb>=(theLKIndx-1)) { OutIdeb=theLKIndx-1; OutIfin=theLKIndx; }
1352 else if(Ifin<=theFKIndx+1) { OutIdeb=theFKIndx; OutIfin=theFKIndx+1; }
7fd59977 1353 else if(Ideb>Ifin) { OutIdeb=Ifin-1; OutIfin=Ifin; }
1354 else { OutIdeb=Ideb; OutIfin=Ifin; }
1355 }
1356 else
1357 {
470ebb43 1358 if(Ideb<=theFKIndx){ OutIdeb=theFKIndx; OutIfin=theFKIndx+1;}//first knot
1359 else if(Ifin>=theLKIndx) { OutIdeb=theLKIndx-1;OutIfin=theLKIndx;}//last knot
7fd59977 1360 else
1361 {
1362 if(Side==-1){OutIdeb=Ideb-1; OutIfin=Ifin;}
1363 else {OutIdeb=Ideb; OutIfin=Ifin+1;}
1364 }
1365 }
1366}