1 // Created on: 1998-08-17
2 // Created by: Philippe MANGIN
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
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_EvolvedSection.hxx>
29 #include <Law_Function.hxx>
30 #include <Precision.hxx>
31 #include <Standard_OutOfRange.hxx>
32 #include <Standard_Type.hxx>
33 #include <TColgp_Array2OfPnt.hxx>
34 #include <TColStd_Array1OfInteger.hxx>
35 #include <TColStd_Array1OfReal.hxx>
38 IMPLEMENT_STANDARD_RTTIEXT(GeomFill_EvolvedSection,GeomFill_SectionLaw)
41 #include <DrawTrSurf.hxx>
42 #include <Geom_Curve.hxx>
43 #include <Geom_BSplineCurve.hxx>
44 static Standard_Integer NumSec = 0;
45 static Standard_Boolean Affich = 0;
48 GeomFill_EvolvedSection::GeomFill_EvolvedSection(const Handle(Geom_Curve)& C,
49 const Handle(Law_Function)& L)
51 L->Bounds(First, Last);
52 mySection = Handle(Geom_Curve)::DownCast(C->Copy());
53 myLaw = L->Trim(First, Last, 1.e-20);
55 myCurve = Handle(Geom_BSplineCurve)::DownCast(C);
56 if (myCurve.IsNull()) {
57 myCurve = GeomConvert::CurveToBSplineCurve(C, Convert_QuasiAngular);
58 if (myCurve->IsPeriodic()) {
59 Standard_Integer M = myCurve->Degree()/2+1;
60 myCurve->RemoveKnot(1, M, Precision::Confusion());
67 sprintf(name,"UnifSect_%d",++NumSec);
68 DrawTrSurf::Set(name, myCurve);
73 //=======================================================
75 //=======================================================
76 Standard_Boolean GeomFill_EvolvedSection::D0(const Standard_Real U,
77 TColgp_Array1OfPnt& Poles,
78 TColStd_Array1OfReal& Weights)
81 Standard_Integer ii, L = Poles.Length();
83 myCurve->Poles(Poles);
84 for (ii=1; ii<=L; ii++) {
85 Poles(ii).ChangeCoord() *= val;
87 myCurve->Weights(Weights);
92 //=======================================================
94 //=======================================================
95 Standard_Boolean GeomFill_EvolvedSection::D1(const Standard_Real U,
96 TColgp_Array1OfPnt& Poles,
97 TColgp_Array1OfVec& DPoles,
98 TColStd_Array1OfReal& Weights,
99 TColStd_Array1OfReal& DWeights)
101 Standard_Real val, dval;
102 Standard_Integer ii, L = Poles.Length();
103 TLaw->D1(U, val, dval);
105 myCurve->Poles(Poles);
106 myCurve->Weights(Weights);
107 for (ii=1; ii<=L; ii++) {
108 DPoles(ii).SetXYZ(Poles(ii).XYZ());
110 Poles(ii).ChangeCoord() *= val;
114 return Standard_True;
117 //=======================================================
119 //=======================================================
120 Standard_Boolean GeomFill_EvolvedSection::D2(const Standard_Real U,
121 TColgp_Array1OfPnt& Poles,
122 TColgp_Array1OfVec& DPoles,
123 TColgp_Array1OfVec& D2Poles,
124 TColStd_Array1OfReal& Weights,
125 TColStd_Array1OfReal& DWeights,
126 TColStd_Array1OfReal& D2Weights)
128 Standard_Real val, dval, d2val;
129 Standard_Integer ii, L = Poles.Length();
130 TLaw->D2(U, val, dval, d2val);
131 myCurve->Poles(Poles);
132 myCurve->Weights(Weights);
134 for (ii=1; ii<=L; ii++) {
135 DPoles(ii).SetXYZ(Poles(ii).XYZ());
136 D2Poles(ii) = DPoles(ii);
137 D2Poles(ii) *= d2val;
139 Poles(ii).ChangeCoord() *= val;
145 return Standard_True;
148 //=======================================================
149 // Purpose :BSplineSurface()
150 //=======================================================
151 Handle(Geom_BSplineSurface) GeomFill_EvolvedSection::BSplineSurface() const
153 /* Standard_Integer ii, NbPoles = myCurve->NbPoles();
154 TColgp_Array2OfPnt Poles( 1, NbPoles, 1, 2);
155 TColStd_Array1OfReal UKnots(1,myCurve->NbKnots()), VKnots(1,2);
156 TColStd_Array1OfInteger UMults(1,myCurve->NbKnots()), VMults(1,2);
158 for (ii=1; ii <= NbPoles; ii++) {
159 Poles(ii, 1) = Poles(ii, 2) = myCurve->Pole(ii);
162 myCurve->Knots(UKnots);
166 myCurve->Multiplicities(UMults);
170 Handle(Geom_BSplineSurface) BS =
171 new (Geom_BSplineSurface) ( Poles,
174 myCurve->Degree(), 1,
175 myCurve->IsPeriodic());*/
176 Handle(Geom_BSplineSurface) BS;
181 //=======================================================
182 // Purpose :SectionShape
183 //=======================================================
184 void GeomFill_EvolvedSection::SectionShape(Standard_Integer& NbPoles,
185 Standard_Integer& NbKnots,
186 Standard_Integer& Degree) const
188 NbPoles = myCurve->NbPoles();
189 NbKnots = myCurve->NbKnots();
190 Degree = myCurve->Degree();
193 void GeomFill_EvolvedSection::Knots(TColStd_Array1OfReal& TKnots) const
195 myCurve->Knots(TKnots);
197 //=======================================================
199 //=======================================================
200 void GeomFill_EvolvedSection::Mults(TColStd_Array1OfInteger& TMults) const
202 myCurve->Multiplicities(TMults);
206 //=======================================================
207 // Purpose :IsRational
208 //=======================================================
209 Standard_Boolean GeomFill_EvolvedSection::IsRational() const
211 return myCurve->IsRational();
214 //=======================================================
215 // Purpose :IsUPeriodic
216 //=======================================================
217 Standard_Boolean GeomFill_EvolvedSection::IsUPeriodic() const
219 return myCurve->IsPeriodic();
222 //=======================================================
223 // Purpose :IsVPeriodic
224 //=======================================================
225 Standard_Boolean GeomFill_EvolvedSection::IsVPeriodic() const
228 (Abs(myLaw->Value(First) - myLaw->Value(Last)) < Precision::Confusion());
231 //=======================================================
232 // Purpose :NbIntervals
233 //=======================================================
234 Standard_Integer GeomFill_EvolvedSection::NbIntervals(const GeomAbs_Shape S) const
236 return myLaw->NbIntervals(S) ;
240 //=======================================================
241 // Purpose :Intervals
242 //=======================================================
243 void GeomFill_EvolvedSection::Intervals(TColStd_Array1OfReal& T,
244 const GeomAbs_Shape S) const
246 myLaw->Intervals(T, S) ;
250 //=======================================================
251 // Purpose : SetInterval
252 //=======================================================
253 void GeomFill_EvolvedSection::SetInterval(const Standard_Real F,
254 const Standard_Real L)
256 TLaw = myLaw->Trim(F, L, Precision::PConfusion());
259 //=======================================================
260 // Purpose : GetInterval
261 //=======================================================
262 void GeomFill_EvolvedSection::GetInterval(Standard_Real& F,
263 Standard_Real& L) const
268 //=======================================================
269 // Purpose : GetDomain
270 //=======================================================
271 void GeomFill_EvolvedSection::GetDomain(Standard_Real& F,
272 Standard_Real& L) const
278 //=======================================================
279 // Purpose : GetTolerance
280 //=======================================================
281 void GeomFill_EvolvedSection::GetTolerance(const Standard_Real BoundTol,
282 const Standard_Real SurfTol,
283 // const Standard_Real AngleTol,
284 const Standard_Real ,
285 TColStd_Array1OfReal& Tol3d) const
288 if (BoundTol<SurfTol) {
289 Tol3d(Tol3d.Lower()) = BoundTol;
290 Tol3d(Tol3d.Upper()) = BoundTol;
294 //=======================================================
296 //=======================================================
297 gp_Pnt GeomFill_EvolvedSection::BarycentreOfSurf() const
299 Standard_Real U = mySection->FirstParameter(), Delta, b;
303 Delta = ( myCurve->LastParameter() - U ) / 20;
304 Bary.SetCoord(0., 0., 0.);
305 for (ii=0 ; ii <=20; ii++, U+=Delta) {
306 P = myCurve->Value(U);
307 Bary.ChangeCoord() += P.XYZ();
311 Delta = ( Last - First) / 20;
312 for (ii=0, b=0.0; ii <=20; ii++, U+=Delta) {
313 b += myLaw->Value(U);
315 Bary.ChangeCoord() *= b/(21*21);
319 Standard_Real GeomFill_EvolvedSection::MaximalSection() const
321 Standard_Real L, val, max, U, Delta;
323 GeomAdaptor_Curve AC (mySection);
324 L = GCPnts_AbscissaPoint::Length(AC);
326 Delta = ( Last - First) / 20;
327 for (ii=0, max=0.0, U = First; ii <=20; ii++, U+=Delta) {
328 val = myLaw->Value(U);
329 if (val>max) max = val;
334 void GeomFill_EvolvedSection::GetMinimalWeight(TColStd_Array1OfReal& Weights) const
336 if (myCurve->IsRational()) {
337 myCurve->Weights(Weights);
344 Standard_Boolean GeomFill_EvolvedSection::IsConstant(Standard_Real& Error) const
346 // Standard_Real isconst = Standard_False;
347 Standard_Boolean isconst = Standard_False;
352 Handle(Geom_Curve) GeomFill_EvolvedSection::ConstantSection() const
354 Standard_Real Err, scale;
355 if (!IsConstant(Err)) throw StdFail_NotDone("The Law is not Constant!");
358 scale = myLaw->Value(First) +
359 myLaw->Value((First+Last)/2) +
361 T.SetScale(P, scale/3);
363 Handle(Geom_Curve) C;
364 C = Handle(Geom_Curve)::DownCast( mySection->Copy());