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.
17 #include <GeomFill_FunctionGuide.hxx>
19 #include <Geom_BSplineCurve.hxx>
20 #include <Geom_Curve.hxx>
21 #include <Geom_SurfaceOfRevolution.hxx>
22 #include <Geom_TrimmedCurve.hxx>
23 #include <GeomAdaptor_Curve.hxx>
24 #include <GeomFill_SectionLaw.hxx>
29 #include <gp_Trsf.hxx>
32 #include <math_Matrix.hxx>
33 #include <Precision.hxx>
35 //#include <Standard_NotImplemented.hxx>
36 //==============================================
37 // Calcul de la valeur de la fonction :
38 // G(w) - S(teta,v) = 0
39 // ou G : guide et S : surface de revolution
40 //==============================================
41 //==============================================
42 // Function : FunctionGuide
43 // Purpose : Initialisation de la section et de la surface d'arret
44 //==============================================
45 GeomFill_FunctionGuide::GeomFill_FunctionGuide
46 (const Handle(GeomFill_SectionLaw)& S,
47 const Handle(Adaptor3d_Curve)& C,
48 const Standard_Real Param)
51 isconst(Standard_False),
56 Standard_Real Tol = Precision::Confusion();
57 if (TheLaw->IsConstant(Tol)) {
58 isconst = Standard_True;
59 TheConst = TheLaw->ConstantSection();
60 First = TheConst->FirstParameter();
61 Last = TheConst->LastParameter();
64 isconst = Standard_False;
70 //==============================================
71 // Function : SetParam
72 // Purpose : Initialisation de la surface de revolution
73 //==============================================
74 // void GeomFill_FunctionGuide::SetParam(const Standard_Real Param,
75 void GeomFill_FunctionGuide::SetParam(const Standard_Real ,
84 gp_Ax3 Rep (gp::Origin(), gp::DZ(), gp::DX());
87 // calculer transfo entre triedre et Oxyz
89 gp_Ax3 RepTriedre(C, D, B2);
91 Transfo.SetTransformation(RepTriedre, Rep);
95 TheCurve = new (Geom_TrimmedCurve)
96 (Handle(Geom_Curve)::DownCast(TheConst->Copy()),
100 Standard_Integer NbPoles, NbKnots, Deg;
101 TheLaw->SectionShape(NbPoles, NbKnots, Deg);
102 TColStd_Array1OfInteger Mult(1,NbKnots);
103 TheLaw->Mults( Mult);
104 TColStd_Array1OfReal Knots(1,NbKnots);
105 TheLaw->Knots(Knots);
106 TColgp_Array1OfPnt Poles(1, NbPoles);
107 TColStd_Array1OfReal Weights(1, NbPoles);
108 TheLaw->D0(TheUonS, Poles, Weights);
109 if (TheLaw->IsRational())
110 TheCurve = new (Geom_BSplineCurve)
111 (Poles, Weights, Knots, Mult ,
112 Deg, TheLaw->IsUPeriodic());
114 TheCurve = new (Geom_BSplineCurve)
116 Deg, TheLaw->IsUPeriodic());
120 TheCurve->Transform(Transfo);
121 TheSurface = new(Geom_SurfaceOfRevolution) (TheCurve, Axe);
124 //==============================================
125 // Function : NbVariables (w, u, v)
127 //==============================================
128 Standard_Integer GeomFill_FunctionGuide::NbVariables()const
133 //==============================================
134 // Function : NbEquations
136 //==============================================
137 Standard_Integer GeomFill_FunctionGuide::NbEquations()const
142 //==============================================
144 // Purpose : calcul of the value of the function at <X>
145 //==============================================
146 Standard_Boolean GeomFill_FunctionGuide::Value(const math_Vector& X,
152 TheGuide->D0(X(1), P);
153 TheSurface->D0(X(2), X(3), P1);
155 F(1) = P.Coord(1) - P1.Coord(1);
156 F(2) = P.Coord(2) - P1.Coord(2);
157 F(3) = P.Coord(3) - P1.Coord(3);
159 return Standard_True;
162 //==============================================
163 // Function : Derivatives
164 // Purpose :calcul of the derivative of the function
165 //==============================================
166 Standard_Boolean GeomFill_FunctionGuide::Derivatives(const math_Vector& X,
172 TheGuide->D1(X(1),P,DP);
173 TheSurface->D1(X(2),X(3),P1,DP1U,DP1V);
178 D(i,1) = DP.Coord(i);
179 D(i,2) = -DP1U.Coord(i);
180 D(i,3) = -DP1V.Coord(i);
183 return Standard_True;
186 //==============================================
188 // Purpose : calcul of the value and the derivative of the function
189 //==============================================
190 Standard_Boolean GeomFill_FunctionGuide::Values(const math_Vector& X,
197 TheGuide->D1(X(1),P,DP); //derivee de la generatrice
198 TheSurface->D1(X(2),X(3),P1,DP1U,DP1V); //derivee de la new surface
203 F(i) = P.Coord(i) - P1.Coord(i);
205 D(i,1) = DP.Coord(i);
206 D(i,2) = -DP1U.Coord(i);
207 D(i,3) = -DP1V.Coord(i);
210 return Standard_True;
213 //==============================================
215 // Purpose : calcul of the first derivative from t
216 //==============================================
217 Standard_Boolean GeomFill_FunctionGuide::DerivT(const math_Vector& X,
218 const gp_XYZ& DCentre,
224 DSDT(X(2),X(3), DCentre,DDir, DS);
226 TheCurve->D0(X(1), P);
228 F(1) = P.Coord(1) - DS.Coord(1);
229 F(2) = P.Coord(2) - DS.Coord(2);
230 F(3) = P.Coord(3) - DS.Coord(3);
232 return Standard_True;
235 //=========================================================
237 // Purpose : calcul de la derive de la surface /t en U, V
238 //=========================================================
239 void GeomFill_FunctionGuide::DSDT(const Standard_Real U,
240 const Standard_Real V,
245 // C origine sur l'axe de revolution
246 // Vdir vecteur unitaire definissant la direction de l'axe de revolution
247 // Q(v) point de parametre V sur la courbe de revolution
248 // OM (u,v) = OC + CQ * Cos(U) + (CQ.Vdir)(1-Cos(U)) * Vdir +
253 TheCurve->D0(V, Pc); //Q(v)
256 gp_XYZ& Q = Pc.ChangeCoord(), DQ(0, 0, 0); //Q
258 std::cout << "Not implemented" << std::endl;
262 Q.Subtract(Centre); //CQ
266 DVcrossCQ.SetLinearForm(DDir.Crossed (Q),
267 Dir.Crossed(DQ)); //Vdir^CQ
268 DVcrossCQ.Multiply (Sin(U)); //(Vdir^CQ)*Sin(U)
270 Standard_Real CosU = Cos(U);
272 DVdotCQ.SetLinearForm(DDir.Dot(Q) + Dir.Dot(DQ), Dir,
273 Dir.Dot(Q), DDir);//(CQ.Vdir)(1-Cos(U))Vdir
274 DVdotCQ.Add (DVcrossCQ); //addition des composantes
282 //=========================================================
283 // Function : Deriv2T
284 // Purpose : calcul of the second derivatice from t
285 //=========================================================
287 /* Standard_Boolean GeomFill_FunctionGuide::Deriv2T(const Standard_Real Param1,
288 const Standard_Real Param,
289 const Standard_Real Param0,
290 const math_Vector & R1,
291 const math_Vector & R,
292 const math_Vector & R0,
295 math_Vector F1(1,3,0);
296 math_Vector F2(1,3,0);
298 DerivT(Param1, Param, R1, R, F1);
299 DerivT(Param, Param0, R, R0, F2);
301 Standard_Real h1 = Param - Param1;
302 Standard_Real h2 = Param0 - Param;
306 F(i) = (F2(i) - F1(i)) / ((h2 + h1)/2);
308 return Standard_True;
311 //=========================================================
312 // Function : DerivTX
313 // Purpose : calcul of the second derivative from t and x
314 //=========================================================
315 Standard_Boolean GeomFill_FunctionGuide::DerivTX(const Standard_Real Param,
316 const Standard_Real Param0,
317 const math_Vector & R,
318 const math_Vector & X0,
322 gp_Vec DP1,DP2,DP2U,DP2V,DP1U,DP1V;
324 TheCurve->D1(R(1), P1, DP1); // guide
325 TheCurve->D1(X0(1), P2, DP2);
326 TheSurface->D1(R(2), R(3), P1, DP1U, DP1V); // surface
327 TheSurface->D1(X0(2), X0(3), P2, DP2U, DP2V); //derivee de la new surface
329 Standard_Real h = Param0 - Param;
334 D(i,1) = (DP2.Coord(i) - DP1.Coord(i)) / h;
335 //D(i,2) = - (DP2U.Coord(i) - DP1U.Coord(i)) / h;
336 D(i,2) = - DP1U.Coord(i) * (X0(2)-R(2)) / h;
337 //D(i,3) = - (DP2V.Coord(i) - DP1V.Coord(i)) / h;
338 D(i,3) = - DP1V.Coord(i) * (X0(3)-R(3)) / h;
341 return Standard_True;
344 //=========================================================
345 // Function : Deriv2X
346 // Purpose : calcul of the second derivative from x
347 //=========================================================
348 Standard_Boolean GeomFill_FunctionGuide::Deriv2X(const math_Vector & X,
352 gp_Vec DP,D2P,DPU,DPV;
353 gp_Vec D2PU, D2PV, D2PUV;
355 TheCurve->D2(X(1), P1, DP, D2P);
356 TheSurface->D2(X(2), X(3), P, DPU, DPV, D2PU, D2PV, D2PUV);
358 T.Init(0.); // tenseur
363 T(i,1,1) = D2P.Coord(i);
364 T(i,2,2) = -D2PU.Coord(i);
365 T(i,3,2) = T(i,2,3) = -D2PUV.Coord(i);
366 T(i,3,3) = -D2PV.Coord(i);
369 return Standard_True;