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 
18 #include <Adaptor3d_Curve.hxx>
19 #include <GeomFill_SnglrFunc.hxx>
20 #include <gp_Pnt.hxx>
21 #include <gp_Vec.hxx>
22 #include <Precision.hxx>
23 #include <Standard_DomainError.hxx>
24 #include <Standard_NotImplemented.hxx>
25 #include <Standard_OutOfRange.hxx>
26 
GeomFill_SnglrFunc(const Handle (Adaptor3d_Curve)& HC)27 GeomFill_SnglrFunc::GeomFill_SnglrFunc(const Handle(Adaptor3d_Curve)& HC) :
28        myHCurve(HC), ratio(1)
29 {
30 }
31 
32 //=======================================================================
33 //function : ShallowCopy
34 //purpose  :
35 //=======================================================================
36 
Handle(Adaptor3d_Curve)37 Handle(Adaptor3d_Curve) GeomFill_SnglrFunc::ShallowCopy() const
38 {
39   Handle(GeomFill_SnglrFunc) aCopy = new GeomFill_SnglrFunc(myHCurve->ShallowCopy());
40   aCopy->ratio = ratio;
41   return aCopy;
42 }
43 
SetRatio(const Standard_Real Ratio)44 void GeomFill_SnglrFunc::SetRatio(const Standard_Real Ratio)
45 {
46   ratio = Ratio;
47 }
48 
FirstParameter() const49  Standard_Real GeomFill_SnglrFunc::FirstParameter() const
50 {
51   return myHCurve->FirstParameter();
52 }
53 
LastParameter() const54  Standard_Real GeomFill_SnglrFunc::LastParameter() const
55 {
56   return myHCurve->LastParameter();
57 }
58 
NbIntervals(const GeomAbs_Shape S) const59  Standard_Integer GeomFill_SnglrFunc::NbIntervals(const GeomAbs_Shape S) const
60 {
61   GeomAbs_Shape HCS=GeomAbs_C0;
62   if (S == GeomAbs_C0)
63   {
64     HCS = GeomAbs_C2;
65   }
66   else if (S == GeomAbs_C1)
67   {
68     HCS = GeomAbs_C3;
69   }
70   else if (S >= GeomAbs_C2)
71   {
72     HCS = GeomAbs_CN;
73   }
74   return myHCurve->NbIntervals(HCS);
75 }
76 
Intervals(TColStd_Array1OfReal & T,const GeomAbs_Shape S) const77  void GeomFill_SnglrFunc::Intervals(TColStd_Array1OfReal& T,const GeomAbs_Shape S) const
78 {
79   GeomAbs_Shape HCS=GeomAbs_C0;
80   if (S == GeomAbs_C0)
81   {
82     HCS = GeomAbs_C2;
83   }
84   else if (S == GeomAbs_C1)
85   {
86     HCS = GeomAbs_C3;
87   }
88   else if (S >= GeomAbs_C2)
89   {
90     HCS = GeomAbs_CN;
91   }
92   myHCurve->Intervals(T, HCS);
93 }
94 
IsPeriodic() const95  Standard_Boolean GeomFill_SnglrFunc::IsPeriodic() const
96 {
97   return myHCurve->IsPeriodic();
98 }
99 
Period() const100  Standard_Real GeomFill_SnglrFunc::Period() const
101 {
102   return myHCurve->Period();
103 }
104 
105 
Value(const Standard_Real U) const106  gp_Pnt GeomFill_SnglrFunc::Value(const Standard_Real U) const
107 {
108   gp_Pnt C;
109   gp_Vec DC, D2C;
110   myHCurve->D2(U, C, DC, D2C);
111   DC *= ratio;
112   return gp_Pnt(DC.Crossed(D2C).XYZ());
113 }
114 
D0(const Standard_Real U,gp_Pnt & P) const115  void GeomFill_SnglrFunc::D0(const Standard_Real U,gp_Pnt& P) const
116 {
117   gp_Pnt C;
118   gp_Vec DC, D2C;
119   myHCurve->D2(U, C, DC, D2C);
120   DC *= ratio;
121   P = gp_Pnt(DC.Crossed(D2C).XYZ());
122 }
123 
D1(const Standard_Real U,gp_Pnt & P,gp_Vec & V) const124  void GeomFill_SnglrFunc::D1(const Standard_Real U,gp_Pnt& P,gp_Vec& V) const
125 {
126   gp_Pnt C;
127   gp_Vec DC, D2C, D3C;
128   myHCurve->D3(U, C, DC, D2C, D3C);
129   DC *= ratio;
130   P = gp_Pnt(DC.Crossed(D2C).XYZ());
131   V = DC.Crossed(D3C);
132 }
133 
D2(const Standard_Real U,gp_Pnt & P,gp_Vec & V1,gp_Vec & V2) const134  void GeomFill_SnglrFunc::D2(const Standard_Real U,gp_Pnt& P,gp_Vec& V1,gp_Vec& V2) const
135 {
136   gp_Pnt C;
137   gp_Vec DC, D2C, D3C, D4C;
138   myHCurve->D3(U, C, DC, D2C, D3C);
139   P = gp_Pnt(DC.Crossed(D2C).XYZ());
140   V1 = DC.Crossed(D3C);
141   D4C = myHCurve->DN(U, 4);
142   V2 = D2C.Crossed(D3C) + DC.Crossed(D4C);
143 
144   P.ChangeCoord() *= ratio;
145   V1 *= ratio;
146   V2 *= ratio;
147 }
148 
D3(const Standard_Real U,gp_Pnt & P,gp_Vec & V1,gp_Vec & V2,gp_Vec & V3) const149 void GeomFill_SnglrFunc::D3(const Standard_Real U,gp_Pnt& P,gp_Vec& V1,gp_Vec& V2,gp_Vec& V3) const
150   {
151   gp_Vec DC, D2C, D3C, D4C, D5C;
152   myHCurve->D3(U, P, DC, D2C, D3C);
153   D4C = myHCurve->DN(U, 4);
154   D5C = myHCurve->DN(U, 5);
155   P = gp_Pnt(DC.Crossed(D2C).XYZ()).ChangeCoord()*ratio;
156   V1 = DC.Crossed(D3C)*ratio;
157   V2 = (D2C.Crossed(D3C) + DC.Crossed(D4C))*ratio;
158   V3 = (DC.Crossed(D5C) + D2C.Crossed(D4C)*2)*ratio;
159   }
160 
DN(const Standard_Real U,const Standard_Integer N) const161 gp_Vec GeomFill_SnglrFunc::DN(const Standard_Real U,const Standard_Integer N) const
162   {
163   Standard_RangeError_Raise_if (N < 1, "Exception: Geom2d_OffsetCurve::DN(). N<1.");
164 
165   gp_Vec D1C, D2C, D3C;
166   gp_Pnt C;
167 
168   switch(N)
169     {
170     case 1:
171       D1(U,C,D1C);
172       return D1C;
173     case 2:
174       D2(U,C,D1C,D2C);
175       return D2C;
176     case 3:
177       D3(U,C,D1C,D2C,D3C);
178       return D3C;
179     default:
180       throw Standard_NotImplemented("Exception: Derivative order is greater than 3. "
181         "Cannot compute of derivative.");
182     }
183   }
184 
Resolution(const Standard_Real R3D) const185  Standard_Real GeomFill_SnglrFunc::Resolution(const Standard_Real R3D) const
186 {
187   return Precision::Parametric(R3D);
188 }
189 
GetType() const190  GeomAbs_CurveType GeomFill_SnglrFunc::GetType() const
191 {
192   return GeomAbs_OtherCurve;
193 }
194 
195 
196