1 // Created on: 1998-07-09
2 // Created by: Stephanie HUMEAU
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 <Adaptor3d_HCurve.hxx>
19 #include <Geom_BSplineCurve.hxx>
20 #include <Geom_Curve.hxx>
21 #include <Geom_Surface.hxx>
22 #include <Geom_SurfaceOfRevolution.hxx>
23 #include <Geom_TrimmedCurve.hxx>
24 #include <GeomAdaptor_HCurve.hxx>
25 #include <GeomFill_FunctionGuide.hxx>
26 #include <GeomFill_SectionLaw.hxx>
27 #include <GeomTools.hxx>
32 #include <gp_Trsf.hxx>
35 #include <math_Matrix.hxx>
36 #include <Precision.hxx>
37 #include <TColgp_HArray1OfPnt.hxx>
38 #include <TColStd_HArray1OfInteger.hxx>
39 #include <TColStd_HArray1OfReal.hxx>
41 //#include <Standard_NotImplemented.hxx>
42 //==============================================
43 // Calcul de la valeur de la fonction :
44 // G(w) - S(teta,v) = 0
45 // ou G : guide et S : surface de revolution
46 //==============================================
47 //==============================================
48 // Function : FunctionGuide
49 // Purpose : Initialisation de la section et de la surface d'arret
50 //==============================================
51 GeomFill_FunctionGuide::GeomFill_FunctionGuide
52 (const Handle(GeomFill_SectionLaw)& S,
53 const Handle(Adaptor3d_HCurve)& C,
54 const Standard_Real Param)
55 : TheGuide(C), TheLaw(S), TheUonS(Param)
57 Standard_Real Tol = Precision::Confusion();
58 if (TheLaw->IsConstant(Tol)) {
59 isconst = Standard_True;
60 TheConst = TheLaw->ConstantSection();
61 First = TheConst->FirstParameter();
62 Last = TheConst->LastParameter();
65 isconst = Standard_False;
71 //==============================================
72 // Function : SetParam
73 // Purpose : Initialisation de la surface de revolution
74 //==============================================
75 // void GeomFill_FunctionGuide::SetParam(const Standard_Real Param,
76 void GeomFill_FunctionGuide::SetParam(const Standard_Real ,
85 gp_Ax3 Rep (gp::Origin(), gp::DZ(), gp::DX());
88 // calculer transfo entre triedre et Oxyz
90 gp_Ax3 RepTriedre(C, D, B2);
92 Transfo.SetTransformation(RepTriedre, Rep);
96 TheCurve = new (Geom_TrimmedCurve)
97 (Handle(Geom_Curve)::DownCast(TheConst->Copy()),
101 Standard_Integer NbPoles, NbKnots, Deg;
102 TheLaw->SectionShape(NbPoles, NbKnots, Deg);
103 TColStd_Array1OfInteger Mult(1,NbKnots);
104 TheLaw->Mults( Mult);
105 TColStd_Array1OfReal Knots(1,NbKnots);
106 TheLaw->Knots(Knots);
107 TColgp_Array1OfPnt Poles(1, NbPoles);
108 TColStd_Array1OfReal Weights(1, NbPoles);
109 TheLaw->D0(TheUonS, Poles, Weights);
110 if (TheLaw->IsRational())
111 TheCurve = new (Geom_BSplineCurve)
112 (Poles, Weights, Knots, Mult ,
113 Deg, TheLaw->IsUPeriodic());
115 TheCurve = new (Geom_BSplineCurve)
117 Deg, TheLaw->IsUPeriodic());
121 TheCurve->Transform(Transfo);
122 TheSurface = new(Geom_SurfaceOfRevolution) (TheCurve, Axe);
125 //==============================================
126 // Function : NbVariables (w, u, v)
128 //==============================================
129 Standard_Integer GeomFill_FunctionGuide::NbVariables()const
134 //==============================================
135 // Function : NbEquations
137 //==============================================
138 Standard_Integer GeomFill_FunctionGuide::NbEquations()const
143 //==============================================
145 // Purpose : calcul of the value of the function at <X>
146 //==============================================
147 Standard_Boolean GeomFill_FunctionGuide::Value(const math_Vector& X,
153 TheGuide->D0(X(1), P);
154 TheSurface->D0(X(2), X(3), P1);
156 F(1) = P.Coord(1) - P1.Coord(1);
157 F(2) = P.Coord(2) - P1.Coord(2);
158 F(3) = P.Coord(3) - P1.Coord(3);
160 return Standard_True;
163 //==============================================
164 // Function : Derivatives
165 // Purpose :calcul of the derivative of the function
166 //==============================================
167 Standard_Boolean GeomFill_FunctionGuide::Derivatives(const math_Vector& X,
173 TheGuide->D1(X(1),P,DP);
174 TheSurface->D1(X(2),X(3),P1,DP1U,DP1V);
179 D(i,1) = DP.Coord(i);
180 D(i,2) = -DP1U.Coord(i);
181 D(i,3) = -DP1V.Coord(i);
184 return Standard_True;
187 //==============================================
189 // Purpose : calcul of the value and the derivative of the function
190 //==============================================
191 Standard_Boolean GeomFill_FunctionGuide::Values(const math_Vector& X,
198 TheGuide->D1(X(1),P,DP); //derivee de la generatrice
199 TheSurface->D1(X(2),X(3),P1,DP1U,DP1V); //derivee de la new surface
204 F(i) = P.Coord(i) - P1.Coord(i);
206 D(i,1) = DP.Coord(i);
207 D(i,2) = -DP1U.Coord(i);
208 D(i,3) = -DP1V.Coord(i);
211 return Standard_True;
214 //==============================================
216 // Purpose : calcul of the first derivative from t
217 //==============================================
218 Standard_Boolean GeomFill_FunctionGuide::DerivT(const math_Vector& X,
219 const gp_XYZ& DCentre,
225 DSDT(X(2),X(3), DCentre,DDir, DS);
227 TheCurve->D0(X(1), P);
229 F(1) = P.Coord(1) - DS.Coord(1);
230 F(2) = P.Coord(2) - DS.Coord(2);
231 F(3) = P.Coord(3) - DS.Coord(3);
233 return Standard_True;
236 //=========================================================
238 // Purpose : calcul de la derive de la surface /t en U, V
239 //=========================================================
240 void GeomFill_FunctionGuide::DSDT(const Standard_Real U,
241 const Standard_Real V,
246 // C origine sur l'axe de revolution
247 // Vdir vecteur unitaire definissant la direction de l'axe de revolution
248 // Q(v) point de parametre V sur la courbe de revolution
249 // OM (u,v) = OC + CQ * Cos(U) + (CQ.Vdir)(1-Cos(U)) * Vdir +
254 TheCurve->D0(V, Pc); //Q(v)
257 gp_XYZ& Q = Pc.ChangeCoord(), DQ(0, 0, 0); //Q
259 cout << "Not implemented" << endl;
263 Q.Subtract(Centre); //CQ
267 DVcrossCQ.SetLinearForm(DDir.Crossed (Q),
268 Dir.Crossed(DQ)); //Vdir^CQ
269 DVcrossCQ.Multiply (Sin(U)); //(Vdir^CQ)*Sin(U)
271 Standard_Real CosU = Cos(U);
273 DVdotCQ.SetLinearForm(DDir.Dot(Q) + Dir.Dot(DQ), Dir,
274 Dir.Dot(Q), DDir);//(CQ.Vdir)(1-Cos(U))Vdir
275 DVdotCQ.Add (DVcrossCQ); //addition des composantes
283 //=========================================================
284 // Function : Deriv2T
285 // Purpose : calcul of the second derivatice from t
286 //=========================================================
288 /* Standard_Boolean GeomFill_FunctionGuide::Deriv2T(const Standard_Real Param1,
289 const Standard_Real Param,
290 const Standard_Real Param0,
291 const math_Vector & R1,
292 const math_Vector & R,
293 const math_Vector & R0,
296 math_Vector F1(1,3,0);
297 math_Vector F2(1,3,0);
299 DerivT(Param1, Param, R1, R, F1);
300 DerivT(Param, Param0, R, R0, F2);
302 Standard_Real h1 = Param - Param1;
303 Standard_Real h2 = Param0 - Param;
307 F(i) = (F2(i) - F1(i)) / ((h2 + h1)/2);
309 return Standard_True;
312 //=========================================================
313 // Function : DerivTX
314 // Purpose : calcul of the second derivative from t and x
315 //=========================================================
316 Standard_Boolean GeomFill_FunctionGuide::DerivTX(const Standard_Real Param,
317 const Standard_Real Param0,
318 const math_Vector & R,
319 const math_Vector & X0,
323 gp_Vec DP1,DP2,DP2U,DP2V,DP1U,DP1V;
325 TheCurve->D1(R(1), P1, DP1); // guide
326 TheCurve->D1(X0(1), P2, DP2);
327 TheSurface->D1(R(2), R(3), P1, DP1U, DP1V); // surface
328 TheSurface->D1(X0(2), X0(3), P2, DP2U, DP2V); //derivee de la new surface
330 Standard_Real h = Param0 - Param;
335 D(i,1) = (DP2.Coord(i) - DP1.Coord(i)) / h;
336 //D(i,2) = - (DP2U.Coord(i) - DP1U.Coord(i)) / h;
337 D(i,2) = - DP1U.Coord(i) * (X0(2)-R(2)) / h;
338 //D(i,3) = - (DP2V.Coord(i) - DP1V.Coord(i)) / h;
339 D(i,3) = - DP1V.Coord(i) * (X0(3)-R(3)) / h;
342 return Standard_True;
345 //=========================================================
346 // Function : Deriv2X
347 // Purpose : calcul of the second derivative from x
348 //=========================================================
349 Standard_Boolean GeomFill_FunctionGuide::Deriv2X(const math_Vector & X,
353 gp_Vec DP,D2P,DPU,DPV;
354 gp_Vec D2PU, D2PV, D2PUV;
356 TheCurve->D2(X(1), P1, DP, D2P);
357 TheSurface->D2(X(2), X(3), P, DPU, DPV, D2PU, D2PV, D2PUV);
359 T.Init(0.); // tenseur
364 T(i,1,1) = D2P.Coord(i);
365 T(i,2,2) = -D2PU.Coord(i);
366 T(i,3,2) = T(i,2,3) = -D2PUV.Coord(i);
367 T(i,3,3) = -D2PV.Coord(i);
370 return Standard_True;