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
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 <GCPnts_AbscissaPoint.hxx>
19 #include <Geom_BSplineCurve.hxx>
20 #include <Geom_BSplineSurface.hxx>
21 #include <Geom_Curve.hxx>
22 #include <Geom_Geometry.hxx>
23 #include <GeomAdaptor_Curve.hxx>
24 #include <GeomConvert.hxx>
25 #include <GeomFill_UniformSection.hxx>
27 #include <Precision.hxx>
28 #include <Standard_Type.hxx>
29 #include <TColgp_Array2OfPnt.hxx>
30 #include <TColStd_Array1OfInteger.hxx>
31 #include <TColStd_Array1OfReal.hxx>
34 IMPLEMENT_STANDARD_RTTIEXT(GeomFill_UniformSection,GeomFill_SectionLaw)
37 #include <DrawTrSurf.hxx>
38 #include <Geom_Curve.hxx>
39 #include <Geom_BSplineCurve.hxx>
40 static Standard_Integer NumSec = 0;
41 static Standard_Boolean Affich = 0;
44 GeomFill_UniformSection::GeomFill_UniformSection(const Handle(Geom_Curve)& C,
45 const Standard_Real FirstParameter,
46 const Standard_Real LastParameter)
47 : First(FirstParameter),
50 mySection = Handle(Geom_Curve)::DownCast(C->Copy());
51 myCurve = Handle(Geom_BSplineCurve)::DownCast(C);
52 if (myCurve.IsNull()) {
53 myCurve = GeomConvert::CurveToBSplineCurve(C, Convert_QuasiAngular);
54 if (myCurve->IsPeriodic()) {
55 Standard_Integer M = myCurve->Degree()/2+1;
56 myCurve->RemoveKnot(1, M, Precision::Confusion());
63 sprintf(name,"UnifSect_%d",++NumSec);
64 DrawTrSurf::Set(name, myCurve);
69 //=======================================================
71 //=======================================================
72 Standard_Boolean GeomFill_UniformSection::D0(const Standard_Real,
73 TColgp_Array1OfPnt& Poles,
74 TColStd_Array1OfReal& Weights)
76 myCurve->Poles(Poles);
77 myCurve->Weights(Weights);
82 //=======================================================
84 //=======================================================
85 Standard_Boolean GeomFill_UniformSection::D1(const Standard_Real,
86 TColgp_Array1OfPnt& Poles,
87 TColgp_Array1OfVec& DPoles,
88 TColStd_Array1OfReal& Weights,
89 TColStd_Array1OfReal& DWeights)
91 myCurve->Poles(Poles);
92 myCurve->Weights(Weights);
100 //=======================================================
102 //=======================================================
103 Standard_Boolean GeomFill_UniformSection::D2(const Standard_Real,
104 TColgp_Array1OfPnt& Poles,
105 TColgp_Array1OfVec& DPoles,
106 TColgp_Array1OfVec& D2Poles,
107 TColStd_Array1OfReal& Weights,
108 TColStd_Array1OfReal& DWeights,
109 TColStd_Array1OfReal& D2Weights)
111 myCurve->Poles(Poles);
112 myCurve->Weights(Weights);
119 return Standard_True;
122 //=======================================================
123 // Purpose :BSplineSurface()
124 //=======================================================
125 Handle(Geom_BSplineSurface) GeomFill_UniformSection::BSplineSurface() const
127 Standard_Integer ii, NbPoles = myCurve->NbPoles();
128 TColgp_Array2OfPnt Poles( 1, NbPoles, 1, 2);
129 TColStd_Array1OfReal UKnots(1,myCurve->NbKnots()), VKnots(1,2);
130 TColStd_Array1OfInteger UMults(1,myCurve->NbKnots()), VMults(1,2);
132 for (ii=1; ii <= NbPoles; ii++) {
133 Poles(ii, 1) = Poles(ii, 2) = myCurve->Pole(ii);
136 myCurve->Knots(UKnots);
140 myCurve->Multiplicities(UMults);
144 Handle(Geom_BSplineSurface) BS =
145 new (Geom_BSplineSurface) ( Poles,
148 myCurve->Degree(), 1,
149 myCurve->IsPeriodic());
153 //=======================================================
154 // Purpose :SectionShape
155 //=======================================================
156 void GeomFill_UniformSection::SectionShape(Standard_Integer& NbPoles,
157 Standard_Integer& NbKnots,
158 Standard_Integer& Degree) const
160 NbPoles = myCurve->NbPoles();
161 NbKnots = myCurve->NbKnots();
162 Degree = myCurve->Degree();
165 void GeomFill_UniformSection::Knots(TColStd_Array1OfReal& TKnots) const
167 myCurve->Knots(TKnots);
169 //=======================================================
171 //=======================================================
172 void GeomFill_UniformSection::Mults(TColStd_Array1OfInteger& TMults) const
174 myCurve->Multiplicities(TMults);
178 //=======================================================
179 // Purpose :IsRational
180 //=======================================================
181 Standard_Boolean GeomFill_UniformSection::IsRational() const
183 return myCurve->IsRational();
186 //=======================================================
187 // Purpose :IsUPeriodic
188 //=======================================================
189 Standard_Boolean GeomFill_UniformSection::IsUPeriodic() const
191 return myCurve->IsPeriodic();
194 //=======================================================
195 // Purpose :IsVPeriodic
196 //=======================================================
197 Standard_Boolean GeomFill_UniformSection::IsVPeriodic() const
199 return Standard_True;
202 //=======================================================
203 // Purpose :NbIntervals
204 //=======================================================
205 // Standard_Integer GeomFill_UniformSection::NbIntervals(const GeomAbs_Shape S) const
206 Standard_Integer GeomFill_UniformSection::NbIntervals(const GeomAbs_Shape ) const
212 //=======================================================
213 // Purpose :Intervals
214 //=======================================================
215 void GeomFill_UniformSection::Intervals(TColStd_Array1OfReal& T,
216 // const GeomAbs_Shape S) const
217 const GeomAbs_Shape ) const
219 T(T.Lower()) = First;
224 //=======================================================
225 // Purpose : SetInterval
226 //=======================================================
227 void GeomFill_UniformSection::SetInterval(const Standard_Real,
233 //=======================================================
234 // Purpose : GetInterval
235 //=======================================================
236 void GeomFill_UniformSection::GetInterval(Standard_Real& F,
237 Standard_Real& L) const
243 //=======================================================
244 // Purpose : GetDomain
245 //=======================================================
246 void GeomFill_UniformSection::GetDomain(Standard_Real& F,
247 Standard_Real& L) const
253 //=======================================================
254 // Purpose : GetTolerance
255 //=======================================================
256 void GeomFill_UniformSection::GetTolerance(const Standard_Real BoundTol,
257 const Standard_Real SurfTol,
258 // const Standard_Real AngleTol,
259 const Standard_Real ,
260 TColStd_Array1OfReal& Tol3d) const
263 if (BoundTol<SurfTol) {
264 Tol3d(Tol3d.Lower()) = BoundTol;
265 Tol3d(Tol3d.Upper()) = BoundTol;
269 //=======================================================
271 //=======================================================
272 gp_Pnt GeomFill_UniformSection::BarycentreOfSurf() const
274 Standard_Real U = mySection->FirstParameter(), Delta;
277 Delta = ( myCurve->LastParameter() - U ) / 20;
278 Bary.SetCoord(0., 0., 0.);
279 for (Standard_Integer ii=0; ii <=20; ii++, U+=Delta) {
280 P = myCurve->Value(U);
281 Bary.ChangeCoord() += P.XYZ();
283 Bary.ChangeCoord() /= 21.;
288 Standard_Real GeomFill_UniformSection::MaximalSection() const
290 GeomAdaptor_Curve AC (mySection);
291 return GCPnts_AbscissaPoint::Length(AC);
294 void GeomFill_UniformSection::GetMinimalWeight(TColStd_Array1OfReal& Weights) const
296 if (myCurve->IsRational()) {
297 myCurve->Weights(Weights);
304 Standard_Boolean GeomFill_UniformSection::IsConstant(Standard_Real& Error) const
307 return Standard_True;
310 Handle(Geom_Curve) GeomFill_UniformSection::ConstantSection() const
312 Handle(Geom_Curve) C;
313 C = Handle(Geom_Curve)::DownCast( mySection->Copy());