0032402: Coding Rules - eliminate msvc warning C4668 (symbol is not defined as a...
[occt.git] / src / GeomFill / GeomFill_UniformSection.cxx
1 // Created on: 1997-12-05
2 // Created by: Philippe MANGIN
3 // Copyright (c) 1997-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 <Convert_ParameterisationType.hxx>
19 #include <GCPnts_AbscissaPoint.hxx>
20 #include <Geom_BSplineCurve.hxx>
21 #include <Geom_BSplineSurface.hxx>
22 #include <Geom_Curve.hxx>
23 #include <Geom_Geometry.hxx>
24 #include <Geom_Surface.hxx>
25 #include <GeomAdaptor_Curve.hxx>
26 #include <GeomConvert.hxx>
27 #include <GeomFill_UniformSection.hxx>
28 #include <gp_Pnt.hxx>
29 #include <Precision.hxx>
30 #include <Standard_OutOfRange.hxx>
31 #include <Standard_Type.hxx>
32 #include <TColgp_Array2OfPnt.hxx>
33 #include <TColStd_Array1OfInteger.hxx>
34 #include <TColStd_Array1OfReal.hxx>
35
36 #include <stdio.h>
37 IMPLEMENT_STANDARD_RTTIEXT(GeomFill_UniformSection,GeomFill_SectionLaw)
38
39 #ifdef DRAW
40 #include <DrawTrSurf.hxx>
41 #include <Geom_Curve.hxx>
42 #include <Geom_BSplineCurve.hxx>
43 static Standard_Integer NumSec = 0;
44 static Standard_Boolean Affich = 0;
45 #endif
46
47 GeomFill_UniformSection::GeomFill_UniformSection(const Handle(Geom_Curve)& C,
48                                                  const Standard_Real FirstParameter,
49                                                  const Standard_Real LastParameter)
50                                                  : First(FirstParameter),
51                                                    Last(LastParameter)
52 {
53  mySection = Handle(Geom_Curve)::DownCast(C->Copy());
54  myCurve =  Handle(Geom_BSplineCurve)::DownCast(C);
55  if (myCurve.IsNull()) {
56    myCurve = GeomConvert::CurveToBSplineCurve(C, Convert_QuasiAngular);
57    if (myCurve->IsPeriodic()) {
58      Standard_Integer M = myCurve->Degree()/2+1;
59      myCurve->RemoveKnot(1, M, Precision::Confusion());
60    }
61  }
62
63 #ifdef DRAW
64  if (Affich) {
65    char name[256];
66    sprintf(name,"UnifSect_%d",++NumSec);
67    DrawTrSurf::Set(name, myCurve);
68  }
69 #endif
70 }
71
72 //=======================================================
73 // Purpose :D0
74 //=======================================================
75  Standard_Boolean GeomFill_UniformSection::D0(const Standard_Real,
76                                               TColgp_Array1OfPnt& Poles,
77                                               TColStd_Array1OfReal& Weights) 
78 {
79   myCurve->Poles(Poles);
80   myCurve->Weights(Weights);
81
82   return Standard_True;
83 }
84
85 //=======================================================
86 // Purpose :D1
87 //=======================================================
88  Standard_Boolean GeomFill_UniformSection::D1(const Standard_Real,
89                                               TColgp_Array1OfPnt& Poles,
90                                               TColgp_Array1OfVec& DPoles,
91                                               TColStd_Array1OfReal& Weights,
92                                               TColStd_Array1OfReal& DWeights) 
93 {
94   myCurve->Poles(Poles);
95   myCurve->Weights(Weights);
96   gp_Vec V0(0, 0, 0);
97   DPoles.Init(V0);
98   DWeights.Init(0);
99
100   return Standard_True;
101 }
102
103 //=======================================================
104 // Purpose :D2
105 //=======================================================
106  Standard_Boolean GeomFill_UniformSection::D2(const Standard_Real,
107                                               TColgp_Array1OfPnt& Poles,
108                                               TColgp_Array1OfVec& DPoles,
109                                               TColgp_Array1OfVec& D2Poles,
110                                               TColStd_Array1OfReal& Weights,
111                                               TColStd_Array1OfReal& DWeights,
112                                               TColStd_Array1OfReal& D2Weights) 
113 {
114   myCurve->Poles(Poles);
115   myCurve->Weights(Weights);
116   gp_Vec V0(0, 0, 0);
117   DPoles.Init(V0);
118   DWeights.Init(0);
119   D2Poles.Init(V0);
120   D2Weights.Init(0);
121
122   return Standard_True;
123 }
124
125 //=======================================================
126 // Purpose :BSplineSurface()
127 //=======================================================
128  Handle(Geom_BSplineSurface) GeomFill_UniformSection::BSplineSurface() const
129 {
130   Standard_Integer ii, NbPoles = myCurve->NbPoles();
131   TColgp_Array2OfPnt Poles( 1, NbPoles, 1, 2);
132   TColStd_Array1OfReal UKnots(1,myCurve->NbKnots()), VKnots(1,2); 
133   TColStd_Array1OfInteger UMults(1,myCurve->NbKnots()), VMults(1,2);
134   
135   for (ii=1; ii <= NbPoles; ii++) {
136     Poles(ii, 1) =  Poles(ii, 2) = myCurve->Pole(ii);
137   }
138
139   myCurve->Knots(UKnots);
140   VKnots(1) = First;
141   VKnots(2) = Last;
142
143   myCurve->Multiplicities(UMults);
144   VMults.Init(2);
145
146
147   Handle(Geom_BSplineSurface) BS = 
148     new (Geom_BSplineSurface) ( Poles,
149                                UKnots, VKnots,
150                                UMults, VMults,
151                                myCurve->Degree(), 1,
152                                myCurve->IsPeriodic());
153
154   return BS;
155 }
156 //=======================================================
157 // Purpose :SectionShape
158 //=======================================================
159  void GeomFill_UniformSection::SectionShape(Standard_Integer& NbPoles,
160                                             Standard_Integer& NbKnots,
161                                             Standard_Integer& Degree) const
162 {
163    NbPoles = myCurve->NbPoles();
164    NbKnots = myCurve->NbKnots();
165    Degree  = myCurve->Degree();
166 }
167
168  void GeomFill_UniformSection::Knots(TColStd_Array1OfReal& TKnots) const
169 {
170  myCurve->Knots(TKnots);
171 }
172 //=======================================================
173 // Purpose :Mults
174 //=======================================================
175  void GeomFill_UniformSection::Mults(TColStd_Array1OfInteger& TMults) const
176 {
177    myCurve->Multiplicities(TMults);
178 }
179
180
181 //=======================================================
182 // Purpose :IsRational
183 //=======================================================
184  Standard_Boolean GeomFill_UniformSection::IsRational() const
185 {
186   return myCurve->IsRational();
187 }
188
189 //=======================================================
190 // Purpose :IsUPeriodic
191 //=======================================================
192  Standard_Boolean GeomFill_UniformSection::IsUPeriodic() const
193 {
194   return myCurve->IsPeriodic();
195 }
196
197 //=======================================================
198 // Purpose :IsVPeriodic
199 //=======================================================
200  Standard_Boolean GeomFill_UniformSection::IsVPeriodic() const
201 {
202   return Standard_True;
203 }
204
205 //=======================================================
206 // Purpose :NbIntervals
207 //=======================================================
208 // Standard_Integer GeomFill_UniformSection::NbIntervals(const GeomAbs_Shape S) const
209  Standard_Integer GeomFill_UniformSection::NbIntervals(const GeomAbs_Shape ) const
210 {
211   return 1;
212 }
213
214
215 //=======================================================
216 // Purpose :Intervals
217 //=======================================================
218  void GeomFill_UniformSection::Intervals(TColStd_Array1OfReal& T,
219 //                                       const GeomAbs_Shape S) const
220                                          const GeomAbs_Shape ) const
221 {
222   T(T.Lower()) = First;
223   T(T.Upper()) = Last;
224 }
225
226
227 //=======================================================
228 // Purpose : SetInterval
229 //=======================================================
230  void GeomFill_UniformSection::SetInterval(const Standard_Real,
231                                            const Standard_Real) 
232 {
233  // Ne fait Rien
234 }
235
236 //=======================================================
237 // Purpose : GetInterval
238 //=======================================================
239  void GeomFill_UniformSection::GetInterval(Standard_Real& F,
240                                            Standard_Real& L) const
241 {
242   F = First;
243   L = Last;
244 }
245
246 //=======================================================
247 // Purpose : GetDomain
248 //=======================================================
249  void GeomFill_UniformSection::GetDomain(Standard_Real& F,
250                                          Standard_Real& L) const
251 {
252   F = First;
253   L = Last;
254 }
255
256 //=======================================================
257 // Purpose : GetTolerance
258 //=======================================================
259  void GeomFill_UniformSection::GetTolerance(const Standard_Real BoundTol,
260                                             const Standard_Real SurfTol,
261 //                                          const Standard_Real AngleTol,
262                                             const Standard_Real ,
263                                             TColStd_Array1OfReal& Tol3d) const
264 {
265   Tol3d.Init(SurfTol);
266   if (BoundTol<SurfTol) {
267     Tol3d(Tol3d.Lower()) = BoundTol;
268     Tol3d(Tol3d.Upper()) = BoundTol;
269   }
270 }
271
272 //=======================================================
273 // Purpose :
274 //=======================================================
275  gp_Pnt GeomFill_UniformSection::BarycentreOfSurf() const
276 {
277   Standard_Real U = mySection->FirstParameter(), Delta;
278   gp_Pnt P, Bary;
279
280   Delta = ( myCurve->LastParameter() - U ) / 20;
281   Bary.SetCoord(0., 0., 0.);
282   for (Standard_Integer ii=0; ii <=20; ii++, U+=Delta) {
283     P = myCurve->Value(U);
284     Bary.ChangeCoord() += P.XYZ();
285   } 
286   Bary.ChangeCoord() /= 21.;
287
288   return Bary;
289 }
290
291  Standard_Real GeomFill_UniformSection::MaximalSection() const
292 {
293   GeomAdaptor_Curve AC (mySection);
294   return GCPnts_AbscissaPoint::Length(AC);
295 }
296
297 void GeomFill_UniformSection::GetMinimalWeight(TColStd_Array1OfReal& Weights) const
298 {
299   if (myCurve->IsRational()) {
300     myCurve->Weights(Weights);
301   }
302   else {
303     Weights.Init(1);
304   }
305 }
306
307  Standard_Boolean GeomFill_UniformSection::IsConstant(Standard_Real& Error) const
308 {
309   Error = 0.;
310   return Standard_True;
311 }
312
313  Handle(Geom_Curve) GeomFill_UniformSection::ConstantSection() const
314 {
315   Handle(Geom_Curve) C;
316   C = Handle(Geom_Curve)::DownCast( mySection->Copy());
317   return C;
318 }
319