6fce846292c7d857e4270396ba7de4627c845bb5
[occt.git] / src / GeomFill / GeomFill_SnglrFunc.cxx
1 // Created on: 1998-02-26
2 // Created by: Roman BORISOV
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <GeomFill_SnglrFunc.ixx>
18 #include <Standard_NotImplemented.hxx>
19 #include <Precision.hxx>
20
21 GeomFill_SnglrFunc::GeomFill_SnglrFunc(const Handle(Adaptor3d_HCurve)& HC) : 
22        myHCurve(HC), ratio(1)
23 {
24 }
25
26 void GeomFill_SnglrFunc::SetRatio(const Standard_Real Ratio)
27 {
28   ratio = Ratio;
29 }
30
31  Standard_Real GeomFill_SnglrFunc::FirstParameter() const
32 {
33   return myHCurve->FirstParameter();
34 }
35
36  Standard_Real GeomFill_SnglrFunc::LastParameter() const
37 {
38   return myHCurve->LastParameter();
39 }
40
41  Standard_Integer GeomFill_SnglrFunc::NbIntervals(const GeomAbs_Shape S) 
42 {
43   GeomAbs_Shape HCS=GeomAbs_C0;
44   switch(S) {
45   case GeomAbs_C0: HCS = GeomAbs_C2; break;
46   case GeomAbs_C1: HCS = GeomAbs_C3; break;
47   case GeomAbs_C2: HCS = GeomAbs_CN; break;
48   default: Standard_DomainError::Raise();
49   }
50   return myHCurve->NbIntervals(HCS);
51 }
52
53  void GeomFill_SnglrFunc::Intervals(TColStd_Array1OfReal& T,const GeomAbs_Shape S) 
54 {
55   GeomAbs_Shape HCS=GeomAbs_C0;
56   switch(S) {
57   case GeomAbs_C0: HCS = GeomAbs_C2; break;
58   case GeomAbs_C1: HCS = GeomAbs_C3; break;
59   case GeomAbs_C2: HCS = GeomAbs_CN; break;
60   default: Standard_DomainError::Raise();
61   }
62   myHCurve->Intervals(T, HCS);
63 }
64
65  Standard_Boolean GeomFill_SnglrFunc::IsPeriodic() const
66 {
67   return myHCurve->IsPeriodic();
68 }
69
70  Standard_Real GeomFill_SnglrFunc::Period() const
71 {
72   return myHCurve->Period();
73 }
74
75
76  gp_Pnt GeomFill_SnglrFunc::Value(const Standard_Real U) const
77 {
78   gp_Pnt C;
79   gp_Vec DC, D2C;
80   myHCurve->D2(U, C, DC, D2C);
81   DC *= ratio;
82   return gp_Pnt(DC.Crossed(D2C).XYZ());
83 }
84
85  void GeomFill_SnglrFunc::D0(const Standard_Real U,gp_Pnt& P) const
86 {
87   gp_Pnt C;
88   gp_Vec DC, D2C;
89   myHCurve->D2(U, C, DC, D2C);
90   DC *= ratio;
91   P = gp_Pnt(DC.Crossed(D2C).XYZ());
92 }
93
94  void GeomFill_SnglrFunc::D1(const Standard_Real U,gp_Pnt& P,gp_Vec& V) const
95 {
96   gp_Pnt C;
97   gp_Vec DC, D2C, D3C;
98   myHCurve->D3(U, C, DC, D2C, D3C);
99   DC *= ratio;
100   P = gp_Pnt(DC.Crossed(D2C).XYZ());
101   V = DC.Crossed(D3C);
102 }
103
104  void GeomFill_SnglrFunc::D2(const Standard_Real U,gp_Pnt& P,gp_Vec& V1,gp_Vec& V2) const
105 {
106   gp_Pnt C;
107   gp_Vec DC, D2C, D3C, D4C;
108   myHCurve->D3(U, C, DC, D2C, D3C);
109   P = gp_Pnt(DC.Crossed(D2C).XYZ());
110   V1 = DC.Crossed(D3C);
111   D4C = myHCurve->DN(U, 4);
112   V2 = D2C.Crossed(D3C) + DC.Crossed(D4C);
113
114   P.ChangeCoord() *= ratio;
115   V1 *= ratio;
116   V2 *= ratio;
117 }
118
119 void GeomFill_SnglrFunc::D3(const Standard_Real U,gp_Pnt& P,gp_Vec& V1,gp_Vec& V2,gp_Vec& V3) const
120   {
121   gp_Vec DC, D2C, D3C, D4C, D5C;
122   myHCurve->D3(U, P, DC, D2C, D3C);
123   D4C = myHCurve->DN(U, 4);
124   D5C = myHCurve->DN(U, 5);
125   P = gp_Pnt(DC.Crossed(D2C).XYZ()).ChangeCoord()*ratio;
126   V1 = DC.Crossed(D3C)*ratio;
127   V2 = (D2C.Crossed(D3C) + DC.Crossed(D4C))*ratio;
128   V3 = (DC.Crossed(D5C) + D2C.Crossed(D4C)*2)*ratio;
129   }
130
131 gp_Vec GeomFill_SnglrFunc::DN(const Standard_Real U,const Standard_Integer N) const
132   {
133   Standard_RangeError_Raise_if (N < 1, "Exception: Geom2d_OffsetCurve::DN(). N<1.");
134
135   gp_Vec D1C, D2C, D3C;
136   gp_Pnt C;
137
138   switch(N)
139     {
140     case 1:
141       D1(U,C,D1C);
142       return D1C;
143     case 2:
144       D2(U,C,D1C,D2C);
145       return D2C;
146     case 3:
147       D3(U,C,D1C,D2C,D3C);
148       return D3C;
149     default:
150       Standard_NotImplemented::Raise("Exception: Derivative order is greater than 3. "
151         "Cannot compute of derivative.");
152     }
153    
154   return gp_Vec();
155
156   }
157
158  Standard_Real GeomFill_SnglrFunc::Resolution(const Standard_Real R3D) const
159 {
160   return Precision::Parametric(R3D);
161 }
162
163  GeomAbs_CurveType GeomFill_SnglrFunc::GetType() const
164 {
165   return GeomAbs_OtherCurve;
166 }
167
168