0032951: Coding - get rid of unused headers [GeomConvert to IGESBasic]
[occt.git] / src / GeomFill / GeomFill_FunctionGuide.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <GeomFill_FunctionGuide.hxx>
18
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>
25 #include <gp_Ax1.hxx>
26 #include <gp_Ax3.hxx>
27 #include <gp_Dir.hxx>
28 #include <gp_Pnt.hxx>
29 #include <gp_Trsf.hxx>
30 #include <gp_Vec.hxx>
31 #include <gp_XYZ.hxx>
32 #include <math_Matrix.hxx>
33 #include <Precision.hxx>
34
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)
49 : TheGuide(C),
50   TheLaw(S),
51   isconst(Standard_False),
52   First(0.0),
53   Last(0.0),
54   TheUonS(Param)  
55 {
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();
62   }
63   else {
64    isconst = Standard_False;
65    TheConst.Nullify(); 
66   }
67   TheCurve.Nullify();
68 }
69
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 ,
76                                        const gp_Pnt& C,
77                                        const gp_XYZ& D,
78                                        const gp_XYZ& DX)
79 {
80   Centre = C.XYZ();
81   Dir = D;
82
83   //repere fixe
84   gp_Ax3 Rep (gp::Origin(), gp::DZ(), gp::DX());
85  
86
87   // calculer transfo entre triedre et Oxyz
88   gp_Dir B2 = DX;
89   gp_Ax3 RepTriedre(C, D, B2);
90   gp_Trsf Transfo;
91   Transfo.SetTransformation(RepTriedre, Rep);
92    
93
94   if (isconst) {
95     TheCurve = new (Geom_TrimmedCurve) 
96       (Handle(Geom_Curve)::DownCast(TheConst->Copy()),
97         First, Last);
98   }
99   else {
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());
113    else 
114      TheCurve = new (Geom_BSplineCurve)
115         (Poles, Knots, Mult,
116          Deg, TheLaw->IsUPeriodic()); 
117   }
118
119   gp_Ax1 Axe(C, Dir);
120   TheCurve->Transform(Transfo);
121   TheSurface = new(Geom_SurfaceOfRevolution) (TheCurve, Axe);
122 }
123
124 //==============================================
125 // Function : NbVariables (w, u, v)
126 // Purpose :
127 //==============================================
128  Standard_Integer GeomFill_FunctionGuide::NbVariables()const 
129
130   return 3;
131 }
132
133 //==============================================
134 // Function : NbEquations
135 // Purpose :
136 //==============================================
137  Standard_Integer GeomFill_FunctionGuide::NbEquations()const
138 {
139   return 3;
140 }
141
142 //==============================================
143 // Function : Value
144 // Purpose : calcul of the value of the function at <X>
145 //==============================================
146  Standard_Boolean GeomFill_FunctionGuide::Value(const math_Vector& X,
147                                                 math_Vector& F) 
148 {
149   gp_Pnt P,P1;
150  
151
152   TheGuide->D0(X(1), P);
153   TheSurface->D0(X(2), X(3), P1);
154   
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);
158
159   return Standard_True;
160 }
161
162 //==============================================
163 // Function : Derivatives
164 // Purpose :calcul of the derivative of the function
165 //==============================================
166  Standard_Boolean GeomFill_FunctionGuide::Derivatives(const math_Vector& X,
167                                                       math_Matrix& D) 
168 {
169   gp_Pnt P,P1;
170   gp_Vec DP,DP1U,DP1V;
171
172   TheGuide->D1(X(1),P,DP);
173   TheSurface->D1(X(2),X(3),P1,DP1U,DP1V);
174
175   Standard_Integer i;
176   for (i=1;i<=3;i++)
177     {
178       D(i,1) = DP.Coord(i);  
179       D(i,2) = -DP1U.Coord(i);
180       D(i,3) = -DP1V.Coord(i);
181     }// for
182
183   return Standard_True;
184 }
185
186 //==============================================
187 // Function : Values
188 // Purpose : calcul of the value and the derivative of the function
189 //==============================================
190  Standard_Boolean GeomFill_FunctionGuide::Values(const math_Vector& X,
191                                                  math_Vector& F,
192                                                  math_Matrix& D)
193
194   gp_Pnt P,P1;
195   gp_Vec DP,DP1U,DP1V;
196
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
199
200   Standard_Integer i;
201   for (i=1;i<=3;i++)
202     { 
203       F(i) = P.Coord(i) - P1.Coord(i);
204
205       D(i,1) = DP.Coord(i);  
206       D(i,2) = -DP1U.Coord(i);
207       D(i,3) = -DP1V.Coord(i);
208     }// for
209
210   return Standard_True;
211 }
212
213 //==============================================
214 // Function : DerivT
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,
219                                                  const gp_XYZ& DDir,
220                                                  math_Vector& F) 
221
222   gp_Pnt P;
223   gp_Vec DS;
224   DSDT(X(2),X(3), DCentre,DDir, DS);
225
226   TheCurve->D0(X(1), P);
227
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);  
231
232   return Standard_True;
233 }
234
235 //=========================================================
236 // Function : DSDT
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,
241                                    const gp_XYZ& DC,
242                                    const gp_XYZ& DDir,
243                                    gp_Vec& DS) const
244
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 +
249    //            (Vdir^CQ)* Sin(U)
250
251
252    gp_Pnt Pc;
253    TheCurve->D0(V, Pc);                  //Q(v)
254 //   if (!isconst) 
255
256    gp_XYZ& Q  = Pc.ChangeCoord(), DQ(0, 0, 0); //Q
257    if (!isconst) {
258      std::cout << "Not implemented" << std::endl;
259    }
260
261
262    Q.Subtract(Centre);  //CQ
263    DQ -= DC;
264
265    gp_XYZ DVcrossCQ;
266    DVcrossCQ.SetLinearForm(DDir.Crossed (Q), 
267                            Dir.Crossed(DQ));   //Vdir^CQ
268    DVcrossCQ.Multiply (Sin(U)); //(Vdir^CQ)*Sin(U)
269
270    Standard_Real CosU =  Cos(U);
271    gp_XYZ DVdotCQ;
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
275
276    DQ.Multiply (CosU);
277    DQ.Add (DVdotCQ);
278    DQ.Add (DC);
279    DS.SetXYZ(DQ);
280 }
281
282 //=========================================================
283 // Function : Deriv2T
284 // Purpose : calcul of the second derivatice from t
285 //=========================================================
286
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,
293                                                   math_Vector& F) 
294 {
295   math_Vector F1(1,3,0);
296   math_Vector F2(1,3,0);
297  
298   DerivT(Param1, Param, R1, R, F1);
299   DerivT(Param, Param0, R, R0, F2);
300   
301   Standard_Real h1 = Param - Param1;
302   Standard_Real h2 = Param0 - Param;
303   
304   Standard_Integer i;  
305   for (i=1;i<=3;i++)  
306     F(i) = (F2(i) - F1(i))  / ((h2 + h1)/2);
307  
308   return Standard_True; 
309 }
310
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,
319                                                   math_Matrix& D) 
320
321   gp_Pnt P1,P2;
322   gp_Vec DP1,DP2,DP2U,DP2V,DP1U,DP1V;
323
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
328  
329   Standard_Real h = Param0 - Param;
330
331   Standard_Integer i;
332   for (i=1;i<=3;i++)
333     {
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;  
339     }// for
340
341   return Standard_True;
342 }
343
344 //=========================================================
345 // Function : Deriv2X
346 // Purpose : calcul of the second derivative from x
347 //=========================================================
348  Standard_Boolean GeomFill_FunctionGuide::Deriv2X(const math_Vector & X,
349                                                   GeomFill_Tensor& T) 
350
351   gp_Pnt P,P1;
352   gp_Vec DP,D2P,DPU,DPV;
353   gp_Vec D2PU, D2PV, D2PUV;
354
355   TheCurve->D2(X(1), P1, DP, D2P);
356   TheSurface->D2(X(2), X(3), P, DPU, DPV, D2PU, D2PV, D2PUV);
357  
358   T.Init(0.); // tenseur
359
360   Standard_Integer i;
361   for (i=1;i<=3;i++)
362     {
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);
367     }// for
368
369   return Standard_True;
370 }*/
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412