0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / GeomFill / GeomFill_EvolvedSection.cxx
CommitLineData
b311480e 1// Created on: 1998-08-17
2// Created by: Philippe MANGIN
3// Copyright (c) 1998-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
7fd59977 17
7fd59977 18#include <Convert_ParameterisationType.hxx>
42cf5bc1 19#include <GCPnts_AbscissaPoint.hxx>
20#include <Geom_BSplineCurve.hxx>
21#include <Geom_BSplineSurface.hxx>
22#include <Geom_Curve.hxx>
7fd59977 23#include <Geom_Geometry.hxx>
24#include <Geom_Surface.hxx>
7fd59977 25#include <GeomAdaptor_Curve.hxx>
42cf5bc1 26#include <GeomConvert.hxx>
27#include <GeomFill_EvolvedSection.hxx>
28#include <gp_Pnt.hxx>
29#include <Law_Function.hxx>
30#include <Precision.hxx>
31#include <Standard_OutOfRange.hxx>
32#include <Standard_Type.hxx>
7fd59977 33#include <TColgp_Array2OfPnt.hxx>
7fd59977 34#include <TColStd_Array1OfInteger.hxx>
42cf5bc1 35#include <TColStd_Array1OfReal.hxx>
7fd59977 36
42cf5bc1 37#include <stdio.h>
7fd59977 38#ifdef DRAW
39#include <DrawTrSurf.hxx>
ec357c5c 40#include <Geom_Curve.hxx>
41#include <Geom_BSplineCurve.hxx>
7fd59977 42static Standard_Integer NumSec = 0;
43static Standard_Boolean Affich = 0;
44#endif
45
46GeomFill_EvolvedSection::GeomFill_EvolvedSection(const Handle(Geom_Curve)& C,
47 const Handle(Law_Function)& L)
48{
7fd59977 49 L->Bounds(First, Last);
50 mySection = Handle(Geom_Curve)::DownCast(C->Copy());
51 myLaw = L->Trim(First, Last, 1.e-20);
52 TLaw = myLaw;
53 myCurve = Handle(Geom_BSplineCurve)::DownCast(C);
54 if (myCurve.IsNull()) {
55 myCurve = GeomConvert::CurveToBSplineCurve(C, Convert_QuasiAngular);
56 if (myCurve->IsPeriodic()) {
57 Standard_Integer M = myCurve->Degree()/2+1;
96a95605 58 myCurve->RemoveKnot(1, M, Precision::Confusion());
7fd59977 59 }
60 }
61
62#if DRAW
63 if (Affich) {
8b5567c7 64 char name[256];
7fd59977 65 sprintf(name,"UnifSect_%d",++NumSec);
66 DrawTrSurf::Set(name, myCurve);
7fd59977 67 }
68#endif
69}
70
71//=======================================================
72// Purpose :D0
73//=======================================================
74 Standard_Boolean GeomFill_EvolvedSection::D0(const Standard_Real U,
75 TColgp_Array1OfPnt& Poles,
76 TColStd_Array1OfReal& Weights)
77{
78 Standard_Real val;
79 Standard_Integer ii, L = Poles.Length();
80 val= TLaw->Value(U);
81 myCurve->Poles(Poles);
82 for (ii=1; ii<=L; ii++) {
83 Poles(ii).ChangeCoord() *= val;
84 }
85 myCurve->Weights(Weights);
86
87 return Standard_True;
88}
89
90//=======================================================
91// Purpose :D1
92//=======================================================
93 Standard_Boolean GeomFill_EvolvedSection::D1(const Standard_Real U,
94 TColgp_Array1OfPnt& Poles,
95 TColgp_Array1OfVec& DPoles,
96 TColStd_Array1OfReal& Weights,
97 TColStd_Array1OfReal& DWeights)
98{
99 Standard_Real val, dval;
100 Standard_Integer ii, L = Poles.Length();
101 TLaw->D1(U, val, dval);
102
103 myCurve->Poles(Poles);
104 myCurve->Weights(Weights);
105 for (ii=1; ii<=L; ii++) {
106 DPoles(ii).SetXYZ(Poles(ii).XYZ());
107 DPoles(ii) *= dval;
108 Poles(ii).ChangeCoord() *= val;
109 }
110 DWeights.Init(0);
111
112 return Standard_True;
113}
114
115//=======================================================
116// Purpose :D2
117//=======================================================
118 Standard_Boolean GeomFill_EvolvedSection::D2(const Standard_Real U,
119 TColgp_Array1OfPnt& Poles,
120 TColgp_Array1OfVec& DPoles,
121 TColgp_Array1OfVec& D2Poles,
122 TColStd_Array1OfReal& Weights,
123 TColStd_Array1OfReal& DWeights,
124 TColStd_Array1OfReal& D2Weights)
125{
126 Standard_Real val, dval, d2val;
127 Standard_Integer ii, L = Poles.Length();
128 TLaw->D2(U, val, dval, d2val);
129 myCurve->Poles(Poles);
130 myCurve->Weights(Weights);
131
132 for (ii=1; ii<=L; ii++) {
133 DPoles(ii).SetXYZ(Poles(ii).XYZ());
134 D2Poles(ii) = DPoles(ii);
135 D2Poles(ii) *= d2val;
136 DPoles(ii) *= dval;
137 Poles(ii).ChangeCoord() *= val;
138 }
139
140 DWeights.Init(0);
141 D2Weights.Init(0);
142
143 return Standard_True;
144}
145
146//=======================================================
147// Purpose :BSplineSurface()
148//=======================================================
149 Handle(Geom_BSplineSurface) GeomFill_EvolvedSection::BSplineSurface() const
150{
151/* Standard_Integer ii, NbPoles = myCurve->NbPoles();
152 TColgp_Array2OfPnt Poles( 1, NbPoles, 1, 2);
153 TColStd_Array1OfReal UKnots(1,myCurve->NbKnots()), VKnots(1,2);
154 TColStd_Array1OfInteger UMults(1,myCurve->NbKnots()), VMults(1,2);
155
156 for (ii=1; ii <= NbPoles; ii++) {
157 Poles(ii, 1) = Poles(ii, 2) = myCurve->Pole(ii);
158 }
159
160 myCurve->Knots(UKnots);
161 VKnots(1) = First;
162 VKnots(2) = Last;
163
164 myCurve->Multiplicities(UMults);
165 VMults.Init(2);
166
167
168 Handle(Geom_BSplineSurface) BS =
169 new (Geom_BSplineSurface) ( Poles,
170 UKnots, VKnots,
171 UMults, VMults,
172 myCurve->Degree(), 1,
173 myCurve->IsPeriodic());*/
174 Handle(Geom_BSplineSurface) BS;
175 BS.Nullify();
176 return BS;
177
178}
179//=======================================================
180// Purpose :SectionShape
181//=======================================================
182 void GeomFill_EvolvedSection::SectionShape(Standard_Integer& NbPoles,
183 Standard_Integer& NbKnots,
184 Standard_Integer& Degree) const
185{
186 NbPoles = myCurve->NbPoles();
187 NbKnots = myCurve->NbKnots();
188 Degree = myCurve->Degree();
189}
190
191 void GeomFill_EvolvedSection::Knots(TColStd_Array1OfReal& TKnots) const
192{
193 myCurve->Knots(TKnots);
194}
195//=======================================================
196// Purpose :Mults
197//=======================================================
198 void GeomFill_EvolvedSection::Mults(TColStd_Array1OfInteger& TMults) const
199{
200 myCurve->Multiplicities(TMults);
201}
202
203
204//=======================================================
205// Purpose :IsRational
206//=======================================================
207 Standard_Boolean GeomFill_EvolvedSection::IsRational() const
208{
209 return myCurve->IsRational();
210}
211
212//=======================================================
213// Purpose :IsUPeriodic
214//=======================================================
215 Standard_Boolean GeomFill_EvolvedSection::IsUPeriodic() const
216{
217 return myCurve->IsPeriodic();
218}
219
220//=======================================================
221// Purpose :IsVPeriodic
222//=======================================================
223 Standard_Boolean GeomFill_EvolvedSection::IsVPeriodic() const
224{
225 return
226 (Abs(myLaw->Value(First) - myLaw->Value(Last)) < Precision::Confusion());
227}
228
229//=======================================================
230// Purpose :NbIntervals
231//=======================================================
232 Standard_Integer GeomFill_EvolvedSection::NbIntervals(const GeomAbs_Shape S) const
233{
234 return myLaw->NbIntervals(S) ;
235}
236
237
238//=======================================================
239// Purpose :Intervals
240//=======================================================
241 void GeomFill_EvolvedSection::Intervals(TColStd_Array1OfReal& T,
242 const GeomAbs_Shape S) const
243{
244 myLaw->Intervals(T, S) ;
245}
246
247
248//=======================================================
249// Purpose : SetInterval
250//=======================================================
251 void GeomFill_EvolvedSection::SetInterval(const Standard_Real F,
252 const Standard_Real L)
253{
254 TLaw = myLaw->Trim(F, L, Precision::PConfusion());
255}
256
257//=======================================================
258// Purpose : GetInterval
259//=======================================================
260 void GeomFill_EvolvedSection::GetInterval(Standard_Real& F,
261 Standard_Real& L) const
262{
263 TLaw->Bounds(F, L);
264}
265
266//=======================================================
267// Purpose : GetDomain
268//=======================================================
269 void GeomFill_EvolvedSection::GetDomain(Standard_Real& F,
270 Standard_Real& L) const
271{
272 F = First;
273 L = Last;
274}
275
276//=======================================================
277// Purpose : GetTolerance
278//=======================================================
279 void GeomFill_EvolvedSection::GetTolerance(const Standard_Real BoundTol,
280 const Standard_Real SurfTol,
281// const Standard_Real AngleTol,
282 const Standard_Real ,
283 TColStd_Array1OfReal& Tol3d) const
284{
285 Tol3d.Init(SurfTol);
286 if (BoundTol<SurfTol) {
287 Tol3d(Tol3d.Lower()) = BoundTol;
288 Tol3d(Tol3d.Upper()) = BoundTol;
289 }
290}
291
292//=======================================================
293// Purpose :
294//=======================================================
295 gp_Pnt GeomFill_EvolvedSection::BarycentreOfSurf() const
296{
297 Standard_Real U = mySection->FirstParameter(), Delta, b;
298 Standard_Integer ii;
299 gp_Pnt P, Bary;
300
301 Delta = ( myCurve->LastParameter() - U ) / 20;
302 Bary.SetCoord(0., 0., 0.);
303 for (ii=0 ; ii <=20; ii++, U+=Delta) {
304 P = myCurve->Value(U);
305 Bary.ChangeCoord() += P.XYZ();
306 }
307
308 U = First;
309 Delta = ( Last - First) / 20;
310 for (ii=0, b=0.0; ii <=20; ii++, U+=Delta) {
311 b += myLaw->Value(U);
312 }
313 Bary.ChangeCoord() *= b/(21*21);
314 return Bary;
315}
316
317 Standard_Real GeomFill_EvolvedSection::MaximalSection() const
318{
319 Standard_Real L, val, max, U, Delta;
320 Standard_Integer ii;
321 GeomAdaptor_Curve AC (mySection);
322 L = GCPnts_AbscissaPoint::Length(AC);
323
324 Delta = ( Last - First) / 20;
325 for (ii=0, max=0.0, U = First; ii <=20; ii++, U+=Delta) {
326 val = myLaw->Value(U);
327 if (val>max) max = val;
328 }
329 return L*max;
330}
331
332void GeomFill_EvolvedSection::GetMinimalWeight(TColStd_Array1OfReal& Weights) const
333{
334 if (myCurve->IsRational()) {
335 myCurve->Weights(Weights);
336 }
337 else {
338 Weights.Init(1);
339 }
340}
341
342 Standard_Boolean GeomFill_EvolvedSection::IsConstant(Standard_Real& Error) const
343{
344// Standard_Real isconst = Standard_False;
345 Standard_Boolean isconst = Standard_False;
346 Error = 0.;
347 return isconst;
348}
349
350 Handle(Geom_Curve) GeomFill_EvolvedSection::ConstantSection() const
351{
352 Standard_Real Err, scale;
353 if (!IsConstant(Err)) StdFail_NotDone::Raise("The Law is not Constant!");
354 gp_Trsf T;
355 gp_Pnt P(0, 0, 0);
356 scale = myLaw->Value(First) +
357 myLaw->Value((First+Last)/2) +
358 myLaw->Value(Last);
359 T.SetScale(P, scale/3);
360
361 Handle(Geom_Curve) C;
362 C = Handle(Geom_Curve)::DownCast( mySection->Copy());
363 C->Transform(T);
364 return C;
365}
366
367
368