0024275: Cppcheck warnings on uninitialized class members
[occt.git] / src / Adaptor3d / Adaptor3d_OffsetCurve.cxx
... / ...
CommitLineData
1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
18#include <Adaptor3d_OffsetCurve.ixx>
19
20#include <Adaptor3d_HOffsetCurve.hxx>
21#include <GeomAbs_SurfaceType.hxx>
22#include <Standard_NoSuchObject.hxx>
23#include <Standard_NotImplemented.hxx>
24#include <gp_VectorWithNullMagnitude.hxx>
25#include <Precision.hxx>
26#include <gp_Ax22d.hxx>
27#include <gp_Dir2d.hxx>
28#include <gp.hxx>
29
30//=======================================================================
31//function : Adaptor3d_OffsetCurve
32//purpose :
33//=======================================================================
34
35Adaptor3d_OffsetCurve::Adaptor3d_OffsetCurve() :
36 myOffset( 0.),
37 myFirst ( 0.),
38 myLast ( 0.)
39{}
40
41//=======================================================================
42//function : Adaptor3d_OffsetCurve
43//purpose :
44//=======================================================================
45
46Adaptor3d_OffsetCurve::Adaptor3d_OffsetCurve(const Handle(Adaptor2d_HCurve2d)& C) :
47 myFirst ( 0.),
48 myLast ( 0.)
49{
50 Load(C);
51}
52
53//=======================================================================
54//function : Adaptor3d_OffsetCurve
55//purpose :
56//=======================================================================
57
58Adaptor3d_OffsetCurve::Adaptor3d_OffsetCurve(const Handle(Adaptor2d_HCurve2d)& C,
59 const Standard_Real Offset) :
60 myFirst ( 0.),
61 myLast ( 0.)
62{
63 Load(C);
64 Load(Offset);
65}
66
67//=======================================================================
68//function : Adaptor3d_OffsetCurve
69//purpose :
70//=======================================================================
71
72Adaptor3d_OffsetCurve::Adaptor3d_OffsetCurve(const Handle(Adaptor2d_HCurve2d)& C,
73 const Standard_Real Offset,
74 const Standard_Real WFirst,
75 const Standard_Real WLast)
76{
77 Load(C);
78 Load(Offset,WFirst,WLast);
79}
80
81//=======================================================================
82//function : Load
83//purpose :
84//=======================================================================
85
86void Adaptor3d_OffsetCurve::Load(const Handle(Adaptor2d_HCurve2d)& C )
87{
88 myCurve = C;
89 myOffset = 0.;
90}
91
92//=======================================================================
93//function : Load
94//purpose :
95//=======================================================================
96
97void Adaptor3d_OffsetCurve::Load( const Standard_Real Offset)
98{
99 myOffset = Offset;
100 myFirst = myCurve->FirstParameter();
101 myLast = myCurve->LastParameter();
102
103}
104
105//=======================================================================
106//function : Load
107//purpose :
108//=======================================================================
109
110void Adaptor3d_OffsetCurve::Load(const Standard_Real Offset,
111 const Standard_Real WFirst,
112 const Standard_Real WLast)
113{
114 myOffset = Offset;
115 myFirst = WFirst;
116 myLast = WLast;
117}
118
119//=======================================================================
120//function : Continuity
121//purpose :
122//=======================================================================
123
124GeomAbs_Shape Adaptor3d_OffsetCurve::Continuity() const
125{
126 switch (myCurve->Continuity()) {
127 case GeomAbs_CN: return GeomAbs_CN;
128 case GeomAbs_C3: return GeomAbs_C2;
129 case GeomAbs_C2: return GeomAbs_G2;
130 case GeomAbs_G2: return GeomAbs_C1;
131 case GeomAbs_C1: return GeomAbs_G1;
132 case GeomAbs_G1: return GeomAbs_C0;
133 case GeomAbs_C0:
134// No Continuity !!
135 Standard_TypeMismatch::Raise("Adaptor3d_OffsetCurve::IntervalContinuity");
136 break;
137 }
138
139 //portage WNT
140 return GeomAbs_C0;
141}
142
143//=======================================================================
144//function : NbIntervals
145//purpose :
146//=======================================================================
147
148Standard_Integer Adaptor3d_OffsetCurve::NbIntervals(const GeomAbs_Shape S) const
149{
150 GeomAbs_Shape Sh;
151 if ( S >= GeomAbs_C2) Sh = GeomAbs_CN;
152 else
153 Sh = (GeomAbs_Shape)((Standard_Integer)S + 2);
154
155 Standard_Integer nbInter = myCurve->NbIntervals(Sh);
156
157 if(nbInter == 1) return nbInter;
158
159 TColStd_Array1OfReal T(1,nbInter+1);
160
161 myCurve->Intervals(T,Sh);
162
163 Standard_Integer first = 1;
164 while (T(first) <= myFirst) first++;
165 Standard_Integer last = nbInter+1;
166 while (T(last) >= myLast) last--;
167 return (last - first + 2);
168}
169
170//=======================================================================
171//function : Intervals
172//purpose :
173//=======================================================================
174
175void Adaptor3d_OffsetCurve::Intervals(TColStd_Array1OfReal& TI,
176 const GeomAbs_Shape S) const
177{
178 GeomAbs_Shape Sh;
179 if ( S >= GeomAbs_C2) Sh = GeomAbs_CN;
180 else
181 Sh = (GeomAbs_Shape)((Standard_Integer)S + 2);
182
183 Standard_Integer nbInter = myCurve->NbIntervals(Sh);
184
185
186 if(nbInter == 1) {
187 TI(TI.Lower()) = myFirst ;
188 TI(TI.Lower() + 1) = myLast ;
189 return;
190 }
191
192 TColStd_Array1OfReal T(1,nbInter+1);
193 myCurve->Intervals(T,Sh);
194
195 Standard_Integer first = 1;
196 while (T(first) <= myFirst) first++;
197 Standard_Integer last = nbInter+1;
198 while (T(last) >= myLast) last--;
199
200 Standard_Integer i = TI.Lower(), j;
201 for (j = first-1; j <= last+1; j++) {
202 TI(i) = T(j);
203 i++;
204 }
205
206 TI(TI.Lower()) = myFirst ;
207 TI(TI.Lower() + last-first + 2) = myLast ;
208
209}
210
211
212//=======================================================================
213//function : Trim
214//purpose :
215//=======================================================================
216
217Handle(Adaptor2d_HCurve2d) Adaptor3d_OffsetCurve::Trim
218(const Standard_Real First,
219 const Standard_Real Last,
220 const Standard_Real) const
221{
222 Handle(Adaptor3d_HOffsetCurve) HO = new Adaptor3d_HOffsetCurve(*this);
223 HO->ChangeCurve2d().Load(myOffset,First,Last);
224 return HO;
225}
226
227
228//=======================================================================
229//function : IsClosed
230//purpose :
231//=======================================================================
232
233Standard_Boolean Adaptor3d_OffsetCurve::IsClosed() const
234{
235 if ( myOffset == 0.) {
236 return myCurve->IsClosed();
237 }
238 else {
239 if (myCurve->Continuity() == GeomAbs_C0)
240 return Standard_False;
241 else {
242 if ( myCurve->IsClosed()) {
243 gp_Vec2d Dummy[2];
244 gp_Pnt2d P;
245 myCurve->D1
246 (myCurve->FirstParameter(),P,Dummy[0]);
247 myCurve->D1
248 (myCurve->LastParameter(),P,Dummy[1]);
249 if (Dummy[0].IsParallel(Dummy[1],Precision::Angular()) &&
250 !(Dummy[0].IsOpposite(Dummy[1],Precision::Angular())))
251 return Standard_True;
252 else
253 return Standard_False;
254 }
255 else
256 return Standard_False;
257 }
258 }
259}
260
261//=======================================================================
262//function : IsPeriodic
263//purpose :
264//=======================================================================
265
266Standard_Boolean Adaptor3d_OffsetCurve::IsPeriodic() const
267{
268 return myCurve->IsPeriodic();
269}
270
271//=======================================================================
272//function : Period
273//purpose :
274//=======================================================================
275
276Standard_Real Adaptor3d_OffsetCurve::Period() const
277{
278 return myCurve->Period();
279}
280
281//=======================================================================
282//function : Value
283//purpose :
284//=======================================================================
285
286gp_Pnt2d Adaptor3d_OffsetCurve::Value(const Standard_Real U) const
287{
288 if ( myOffset != 0.) {
289 gp_Pnt2d P;
290 gp_Vec2d V;
291 Standard_Real Norme;
292 myCurve->D1(U, P, V);
293 Norme = V.Magnitude();
294 V.SetCoord(-V.Y(),V.X());
295 if (Norme >= gp::Resolution()) {
296 return gp_Pnt2d(P.XY()+myOffset*V.XY()/Norme);
297 }
298 else {
299 gp_VectorWithNullMagnitude::Raise("Adaptor3d_OffsetCurve::Value");
300 return gp_Pnt2d();
301 }
302 }
303 else {
304 return myCurve->Value(U);
305 }
306}
307
308//=======================================================================
309//function : D0
310//purpose :
311//=======================================================================
312
313void Adaptor3d_OffsetCurve::D0(const Standard_Real U, gp_Pnt2d& P) const
314{
315 P = Value( U);
316}
317
318//=======================================================================
319//function : D1
320//purpose :
321//=======================================================================
322
323void Adaptor3d_OffsetCurve::D1
324 (const Standard_Real U, gp_Pnt2d& P, gp_Vec2d& V) const
325{
326 gp_Vec2d V1,V2,V3;
327 gp_Pnt2d PP;
328 Standard_Real Norme;
329 if ( myOffset != 0. ) {
330 myCurve->D2(U,PP,V1,V2);
331 Norme = V1.Magnitude();
332 V3.SetCoord( -V1.Y(),V1.X());
333 V2.SetCoord( -V2.Y(),V2.X());
334 if ( Norme >= gp::Resolution()) {
335 P = gp_Pnt2d( PP.XY()+myOffset*V3.XY()/Norme);
336 V = gp_Vec2d( V1.XY()+
337 (myOffset/Norme)*(V2.XY()-V3.XY()*
338 (V2.XY()*V3.XY())/(Norme*Norme)));
339 }
340 else {
341 gp_VectorWithNullMagnitude::Raise("Adaptor3d_OffsetCurve::D1");
342 }
343 }
344 else {
345 myCurve->D1(U,P,V);
346 }
347}
348
349//=======================================================================
350//function : D2
351//purpose :
352//=======================================================================
353
354void Adaptor3d_OffsetCurve::D2
355 (const Standard_Real U, gp_Pnt2d& P, gp_Vec2d& V1, gp_Vec2d& V2) const
356{
357 if ( myOffset != 0.) {
358 gp_Vec2d T1,T2,T3;
359 gp_Pnt2d PP;
360 Standard_Real Norme;
361 myCurve->D3(U,PP,T1,T2,T3);
362
363 Norme = T1.Magnitude();
364 if ( Norme >= gp::Resolution()) {
365 gp_Vec2d N1,N2,N3; // Ni = Z ^ Ti
366 N1.SetCoord( -T1.Y(), T1.X());
367 N2.SetCoord( -T2.Y(), T2.X());
368 N3.SetCoord( -T3.Y(), T3.X());
369 Standard_Real d12,d13,d22,Nor3,Nor11;
370 d12 = T1*T2;
371 d22 = T2*T2;
372 d13 = T1*T3;
373 Nor3 = Norme*Norme*Norme;
374 Nor11 = Nor3*Nor3*Nor3*Norme*Norme;
375 V2 = gp_Vec2d( -1 * ( (d22+d13)/Nor3 + 3*d12*d12/Nor11) * N1.XY());
376 V2 = gp_Vec2d( V2.XY() - (2*d12/Nor3)*N2.XY() + N3.XY()/Norme);
377 V2 = gp_Vec2d( myOffset*V2.XY() + T2.XY());
378
379 D1( U,P,V1);
380 }
381 else {
382 gp_VectorWithNullMagnitude::Raise("Adaptor3d_OffsetCurve::D2");
383 }
384 }
385 else {
386 myCurve->D2(U,P,V1,V2);
387 }
388}
389
390//=======================================================================
391//function : D3
392//purpose :
393//=======================================================================
394
395//void Adaptor3d_OffsetCurve::D3
396// (const Standard_Real T,
397// gp_Pnt2d& P, gp_Vec2d& V1, gp_Vec2d& V2, gp_Vec2d& V3) const
398void Adaptor3d_OffsetCurve::D3
399 (const Standard_Real ,
400 gp_Pnt2d& , gp_Vec2d& , gp_Vec2d& , gp_Vec2d& ) const
401{
402 Standard_NotImplemented::Raise("Adaptor3d_OffsetCurve::D3");
403}
404
405//=======================================================================
406//function : DN
407//purpose :
408//=======================================================================
409
410gp_Vec2d Adaptor3d_OffsetCurve::DN
411// (const Standard_Real T, const Standard_Integer N) const
412 (const Standard_Real , const Standard_Integer ) const
413{
414 Standard_NotImplemented::Raise("Adaptor3d_OffsetCurve::DN");
415 return gp_Vec2d();
416}
417
418
419//=======================================================================
420//function : Resolution
421//purpose :
422//=======================================================================
423
424Standard_Real Adaptor3d_OffsetCurve::Resolution(const Standard_Real R3d) const
425{
426 return Precision::PConfusion(R3d);
427}
428
429
430//=======================================================================
431//function : GetType
432//purpose :
433//=======================================================================
434
435GeomAbs_CurveType Adaptor3d_OffsetCurve::GetType() const {
436
437 if ( myOffset == 0.) {
438 return myCurve->GetType();
439 }
440 else {
441 switch (myCurve->GetType()) {
442
443 case GeomAbs_Line:
444 return GeomAbs_Line;
445
446 case GeomAbs_Circle:
447 return GeomAbs_Circle;
448
449 default:
450 return GeomAbs_OtherCurve;
451
452 }
453 }
454}
455
456//=======================================================================
457//function : Line
458//purpose :
459//=======================================================================
460
461gp_Lin2d Adaptor3d_OffsetCurve::Line() const
462{
463 if ( GetType() == GeomAbs_Line) {
464 gp_Pnt2d P;
465 gp_Vec2d V;
466 D1(0,P,V);
467 return gp_Lin2d(P,V);
468 }
469 else {
470 Standard_NoSuchObject::Raise("Adaptor3d_OffsetCurve::Line");
471 return gp_Lin2d();
472 }
473}
474
475
476//=======================================================================
477//function : Circle
478//purpose :
479//=======================================================================
480
481gp_Circ2d Adaptor3d_OffsetCurve::Circle() const
482{
483 if ( GetType() == GeomAbs_Circle) {
484 if (myOffset == 0.) {
485 return myCurve->Circle();
486 }
487 else {
488 gp_Circ2d C1( myCurve->Circle());
489 Standard_Real radius = C1.Radius();
490 gp_Ax22d axes( C1.Axis());
491 gp_Dir2d Xd = axes.XDirection();
492 gp_Dir2d Yd = axes.YDirection();
493 Standard_Real Crossed = Xd.X()*Yd.Y()-Xd.Y()*Yd.X();
494 Standard_Real Signe = ( Crossed > 0.) ? 1. : -1.;
495
496 radius += Signe*myOffset;
497 if ( radius > 0.) {
498 return gp_Circ2d( axes,radius);
499 }
500 else if ( radius < 0.) {
501 radius = - radius;
502 axes.SetXDirection( (axes.XDirection()).Reversed());
503 return gp_Circ2d( axes,radius);
504 }
505 else { // Cercle de rayon Nul
506 Standard_NoSuchObject::Raise("Adaptor3d_OffsetCurve::Circle");
507 }
508 }
509 }
510 else {
511 Standard_NoSuchObject::Raise("Adaptor3d_OffsetCurve::Circle");
512 }
513 // portage WNT
514 return gp_Circ2d();
515}
516
517//=======================================================================
518//function : Ellipse
519//purpose :
520//=======================================================================
521
522gp_Elips2d Adaptor3d_OffsetCurve::Ellipse() const
523{
524 if (myCurve->GetType() == GeomAbs_Ellipse && myOffset == 0.) {
525 return myCurve->Ellipse();;
526 }
527 else {
528 Standard_NoSuchObject::Raise("Adaptor3d_OffsetCurve:Ellipse");
529 }
530 // portage WNT
531 return gp_Elips2d();
532}
533
534//=======================================================================
535//function : Hyperbola
536//purpose :
537//=======================================================================
538
539gp_Hypr2d Adaptor3d_OffsetCurve::Hyperbola() const
540{
541 if (myCurve->GetType()==GeomAbs_Hyperbola && myOffset==0.) {
542 return myCurve->Hyperbola();
543 }
544 else {
545 Standard_NoSuchObject::Raise("Adaptor3d_OffsetCurve:Hyperbola");
546 }
547 // portage WNT
548 return gp_Hypr2d();
549}
550
551//=======================================================================
552//function : Parabola
553//purpose :
554//=======================================================================
555
556gp_Parab2d Adaptor3d_OffsetCurve::Parabola() const
557{
558 if (myCurve->GetType() == GeomAbs_Parabola && myOffset == 0.) {
559 return myCurve->Parabola();
560 }
561 else {
562 Standard_NoSuchObject::Raise("Adaptor3d_OffsetCurve:Parabola");
563 }
564 // portage WNT
565 return gp_Parab2d();
566}
567//=======================================================================
568//function : Degree
569//purpose :
570//=======================================================================
571
572Standard_Integer Adaptor3d_OffsetCurve::Degree() const
573{
574 GeomAbs_CurveType type = myCurve->GetType();
575 if ( (type==GeomAbs_BezierCurve || type==GeomAbs_BSplineCurve)
576 && myOffset == 0.) {
577 return myCurve->Degree();
578 }
579 else {
580 Standard_NoSuchObject::Raise("Adaptor3d_offsetCurve::Degree");
581 return 0;
582 }
583}
584//=======================================================================
585//function : IsRational
586//purpose :
587//=======================================================================
588
589Standard_Boolean Adaptor3d_OffsetCurve::IsRational() const
590{
591 if ( myOffset == 0.) {
592 return myCurve->IsRational();
593 }
594 return Standard_False;
595}
596//=======================================================================
597//function : NbPoles
598//purpose :
599//=======================================================================
600
601Standard_Integer Adaptor3d_OffsetCurve::NbPoles() const
602{
603 GeomAbs_CurveType type = myCurve->GetType();
604 if ( (type==GeomAbs_BezierCurve || type==GeomAbs_BSplineCurve)
605 && myOffset == 0.) {
606 return myCurve->NbPoles();
607 }
608 else {
609 Standard_NoSuchObject::Raise("Adaptor3d_OffsetCurve::NbPoles");
610 return 0;
611 }
612}
613
614//=======================================================================
615//function : NbKnots
616//purpose :
617//=======================================================================
618
619Standard_Integer Adaptor3d_OffsetCurve::NbKnots() const
620{
621 if( myOffset == 0.) {
622 return myCurve->NbKnots();
623 }
624 else {
625 Standard_NoSuchObject::Raise("Adaptor3d_OffsetCurve::NbKnots");
626 return 0;
627 }
628}
629
630//=======================================================================
631//function : Bezier
632//purpose :
633//=======================================================================
634
635Handle(Geom2d_BezierCurve) Adaptor3d_OffsetCurve::Bezier() const
636{
637 Standard_NoSuchObject_Raise_if
638 ( myOffset != 0.0e0 || GetType() != GeomAbs_BezierCurve, "");
639 return myCurve->Bezier();
640}
641
642
643//=======================================================================
644//function : BSpline
645//purpose :
646//=======================================================================
647
648Handle(Geom2d_BSplineCurve) Adaptor3d_OffsetCurve::BSpline() const
649{
650 Standard_NoSuchObject_Raise_if
651 ( myOffset != 0.0e0 || GetType() != GeomAbs_BSplineCurve, "");
652
653 return myCurve->BSpline();
654}
655
656