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 <Adaptor3d_Curve.hxx>
20 #include <Geom_BSplineCurve.hxx>
21 #include <Geom_Curve.hxx>
22 #include <Geom_Surface.hxx>
23 #include <Geom_SurfaceOfRevolution.hxx>
24 #include <Geom_TrimmedCurve.hxx>
25 #include <GeomAdaptor_Curve.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_Curve)& C,
54 const Standard_Real Param)
57 isconst(Standard_False),
62 Standard_Real Tol = Precision::Confusion();
63 if (TheLaw->IsConstant(Tol)) {
64 isconst = Standard_True;
65 TheConst = TheLaw->ConstantSection();
66 First = TheConst->FirstParameter();
67 Last = TheConst->LastParameter();
70 isconst = Standard_False;
76 //==============================================
77 // Function : SetParam
78 // Purpose : Initialisation de la surface de revolution
79 //==============================================
80 // void GeomFill_FunctionGuide::SetParam(const Standard_Real Param,
81 void GeomFill_FunctionGuide::SetParam(const Standard_Real ,
90 gp_Ax3 Rep (gp::Origin(), gp::DZ(), gp::DX());
93 // calculer transfo entre triedre et Oxyz
95 gp_Ax3 RepTriedre(C, D, B2);
97 Transfo.SetTransformation(RepTriedre, Rep);
101 TheCurve = new (Geom_TrimmedCurve)
102 (Handle(Geom_Curve)::DownCast(TheConst->Copy()),
106 Standard_Integer NbPoles, NbKnots, Deg;
107 TheLaw->SectionShape(NbPoles, NbKnots, Deg);
108 TColStd_Array1OfInteger Mult(1,NbKnots);
109 TheLaw->Mults( Mult);
110 TColStd_Array1OfReal Knots(1,NbKnots);
111 TheLaw->Knots(Knots);
112 TColgp_Array1OfPnt Poles(1, NbPoles);
113 TColStd_Array1OfReal Weights(1, NbPoles);
114 TheLaw->D0(TheUonS, Poles, Weights);
115 if (TheLaw->IsRational())
116 TheCurve = new (Geom_BSplineCurve)
117 (Poles, Weights, Knots, Mult ,
118 Deg, TheLaw->IsUPeriodic());
120 TheCurve = new (Geom_BSplineCurve)
122 Deg, TheLaw->IsUPeriodic());
126 TheCurve->Transform(Transfo);
127 TheSurface = new(Geom_SurfaceOfRevolution) (TheCurve, Axe);
130 //==============================================
131 // Function : NbVariables (w, u, v)
133 //==============================================
134 Standard_Integer GeomFill_FunctionGuide::NbVariables()const
139 //==============================================
140 // Function : NbEquations
142 //==============================================
143 Standard_Integer GeomFill_FunctionGuide::NbEquations()const
148 //==============================================
150 // Purpose : calcul of the value of the function at <X>
151 //==============================================
152 Standard_Boolean GeomFill_FunctionGuide::Value(const math_Vector& X,
158 TheGuide->D0(X(1), P);
159 TheSurface->D0(X(2), X(3), P1);
161 F(1) = P.Coord(1) - P1.Coord(1);
162 F(2) = P.Coord(2) - P1.Coord(2);
163 F(3) = P.Coord(3) - P1.Coord(3);
165 return Standard_True;
168 //==============================================
169 // Function : Derivatives
170 // Purpose :calcul of the derivative of the function
171 //==============================================
172 Standard_Boolean GeomFill_FunctionGuide::Derivatives(const math_Vector& X,
178 TheGuide->D1(X(1),P,DP);
179 TheSurface->D1(X(2),X(3),P1,DP1U,DP1V);
184 D(i,1) = DP.Coord(i);
185 D(i,2) = -DP1U.Coord(i);
186 D(i,3) = -DP1V.Coord(i);
189 return Standard_True;
192 //==============================================
194 // Purpose : calcul of the value and the derivative of the function
195 //==============================================
196 Standard_Boolean GeomFill_FunctionGuide::Values(const math_Vector& X,
203 TheGuide->D1(X(1),P,DP); //derivee de la generatrice
204 TheSurface->D1(X(2),X(3),P1,DP1U,DP1V); //derivee de la new surface
209 F(i) = P.Coord(i) - P1.Coord(i);
211 D(i,1) = DP.Coord(i);
212 D(i,2) = -DP1U.Coord(i);
213 D(i,3) = -DP1V.Coord(i);
216 return Standard_True;
219 //==============================================
221 // Purpose : calcul of the first derivative from t
222 //==============================================
223 Standard_Boolean GeomFill_FunctionGuide::DerivT(const math_Vector& X,
224 const gp_XYZ& DCentre,
230 DSDT(X(2),X(3), DCentre,DDir, DS);
232 TheCurve->D0(X(1), P);
234 F(1) = P.Coord(1) - DS.Coord(1);
235 F(2) = P.Coord(2) - DS.Coord(2);
236 F(3) = P.Coord(3) - DS.Coord(3);
238 return Standard_True;
241 //=========================================================
243 // Purpose : calcul de la derive de la surface /t en U, V
244 //=========================================================
245 void GeomFill_FunctionGuide::DSDT(const Standard_Real U,
246 const Standard_Real V,
251 // C origine sur l'axe de revolution
252 // Vdir vecteur unitaire definissant la direction de l'axe de revolution
253 // Q(v) point de parametre V sur la courbe de revolution
254 // OM (u,v) = OC + CQ * Cos(U) + (CQ.Vdir)(1-Cos(U)) * Vdir +
259 TheCurve->D0(V, Pc); //Q(v)
262 gp_XYZ& Q = Pc.ChangeCoord(), DQ(0, 0, 0); //Q
264 std::cout << "Not implemented" << std::endl;
268 Q.Subtract(Centre); //CQ
272 DVcrossCQ.SetLinearForm(DDir.Crossed (Q),
273 Dir.Crossed(DQ)); //Vdir^CQ
274 DVcrossCQ.Multiply (Sin(U)); //(Vdir^CQ)*Sin(U)
276 Standard_Real CosU = Cos(U);
278 DVdotCQ.SetLinearForm(DDir.Dot(Q) + Dir.Dot(DQ), Dir,
279 Dir.Dot(Q), DDir);//(CQ.Vdir)(1-Cos(U))Vdir
280 DVdotCQ.Add (DVcrossCQ); //addition des composantes
288 //=========================================================
289 // Function : Deriv2T
290 // Purpose : calcul of the second derivatice from t
291 //=========================================================
293 /* Standard_Boolean GeomFill_FunctionGuide::Deriv2T(const Standard_Real Param1,
294 const Standard_Real Param,
295 const Standard_Real Param0,
296 const math_Vector & R1,
297 const math_Vector & R,
298 const math_Vector & R0,
301 math_Vector F1(1,3,0);
302 math_Vector F2(1,3,0);
304 DerivT(Param1, Param, R1, R, F1);
305 DerivT(Param, Param0, R, R0, F2);
307 Standard_Real h1 = Param - Param1;
308 Standard_Real h2 = Param0 - Param;
312 F(i) = (F2(i) - F1(i)) / ((h2 + h1)/2);
314 return Standard_True;
317 //=========================================================
318 // Function : DerivTX
319 // Purpose : calcul of the second derivative from t and x
320 //=========================================================
321 Standard_Boolean GeomFill_FunctionGuide::DerivTX(const Standard_Real Param,
322 const Standard_Real Param0,
323 const math_Vector & R,
324 const math_Vector & X0,
328 gp_Vec DP1,DP2,DP2U,DP2V,DP1U,DP1V;
330 TheCurve->D1(R(1), P1, DP1); // guide
331 TheCurve->D1(X0(1), P2, DP2);
332 TheSurface->D1(R(2), R(3), P1, DP1U, DP1V); // surface
333 TheSurface->D1(X0(2), X0(3), P2, DP2U, DP2V); //derivee de la new surface
335 Standard_Real h = Param0 - Param;
340 D(i,1) = (DP2.Coord(i) - DP1.Coord(i)) / h;
341 //D(i,2) = - (DP2U.Coord(i) - DP1U.Coord(i)) / h;
342 D(i,2) = - DP1U.Coord(i) * (X0(2)-R(2)) / h;
343 //D(i,3) = - (DP2V.Coord(i) - DP1V.Coord(i)) / h;
344 D(i,3) = - DP1V.Coord(i) * (X0(3)-R(3)) / h;
347 return Standard_True;
350 //=========================================================
351 // Function : Deriv2X
352 // Purpose : calcul of the second derivative from x
353 //=========================================================
354 Standard_Boolean GeomFill_FunctionGuide::Deriv2X(const math_Vector & X,
358 gp_Vec DP,D2P,DPU,DPV;
359 gp_Vec D2PU, D2PV, D2PUV;
361 TheCurve->D2(X(1), P1, DP, D2P);
362 TheSurface->D2(X(2), X(3), P, DPU, DPV, D2PU, D2PV, D2PUV);
364 T.Init(0.); // tenseur
369 T(i,1,1) = D2P.Coord(i);
370 T(i,2,2) = -D2PU.Coord(i);
371 T(i,3,2) = T(i,2,3) = -D2PUV.Coord(i);
372 T(i,3,3) = -D2PV.Coord(i);
375 return Standard_True;