0028966: Coding Rules - remove Adaptor2d_HCurve2d, Adaptor3d_HCurve and Adaptor3d_HSu...
[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 <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>
28 #include <gp_Ax1.hxx>
29 #include <gp_Ax3.hxx>
30 #include <gp_Dir.hxx>
31 #include <gp_Pnt.hxx>
32 #include <gp_Trsf.hxx>
33 #include <gp_Vec.hxx>
34 #include <gp_XYZ.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>
40
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)
55 : TheGuide(C),
56   TheLaw(S),
57   isconst(Standard_False),
58   First(0.0),
59   Last(0.0),
60   TheUonS(Param)  
61 {
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();
68   }
69   else {
70    isconst = Standard_False;
71    TheConst.Nullify(); 
72   }
73   TheCurve.Nullify();
74 }
75
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 ,
82                                        const gp_Pnt& C,
83                                        const gp_XYZ& D,
84                                        const gp_XYZ& DX)
85 {
86   Centre = C.XYZ();
87   Dir = D;
88
89   //repere fixe
90   gp_Ax3 Rep (gp::Origin(), gp::DZ(), gp::DX());
91  
92
93   // calculer transfo entre triedre et Oxyz
94   gp_Dir B2 = DX;
95   gp_Ax3 RepTriedre(C, D, B2);
96   gp_Trsf Transfo;
97   Transfo.SetTransformation(RepTriedre, Rep);
98    
99
100   if (isconst) {
101     TheCurve = new (Geom_TrimmedCurve) 
102       (Handle(Geom_Curve)::DownCast(TheConst->Copy()),
103         First, Last);
104   }
105   else {
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());
119    else 
120      TheCurve = new (Geom_BSplineCurve)
121         (Poles, Knots, Mult,
122          Deg, TheLaw->IsUPeriodic()); 
123   }
124
125   gp_Ax1 Axe(C, Dir);
126   TheCurve->Transform(Transfo);
127   TheSurface = new(Geom_SurfaceOfRevolution) (TheCurve, Axe);
128 }
129
130 //==============================================
131 // Function : NbVariables (w, u, v)
132 // Purpose :
133 //==============================================
134  Standard_Integer GeomFill_FunctionGuide::NbVariables()const 
135
136   return 3;
137 }
138
139 //==============================================
140 // Function : NbEquations
141 // Purpose :
142 //==============================================
143  Standard_Integer GeomFill_FunctionGuide::NbEquations()const
144 {
145   return 3;
146 }
147
148 //==============================================
149 // Function : Value
150 // Purpose : calcul of the value of the function at <X>
151 //==============================================
152  Standard_Boolean GeomFill_FunctionGuide::Value(const math_Vector& X,
153                                                 math_Vector& F) 
154 {
155   gp_Pnt P,P1;
156  
157
158   TheGuide->D0(X(1), P);
159   TheSurface->D0(X(2), X(3), P1);
160   
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);
164
165   return Standard_True;
166 }
167
168 //==============================================
169 // Function : Derivatives
170 // Purpose :calcul of the derivative of the function
171 //==============================================
172  Standard_Boolean GeomFill_FunctionGuide::Derivatives(const math_Vector& X,
173                                                       math_Matrix& D) 
174 {
175   gp_Pnt P,P1;
176   gp_Vec DP,DP1U,DP1V;
177
178   TheGuide->D1(X(1),P,DP);
179   TheSurface->D1(X(2),X(3),P1,DP1U,DP1V);
180
181   Standard_Integer i;
182   for (i=1;i<=3;i++)
183     {
184       D(i,1) = DP.Coord(i);  
185       D(i,2) = -DP1U.Coord(i);
186       D(i,3) = -DP1V.Coord(i);
187     }// for
188
189   return Standard_True;
190 }
191
192 //==============================================
193 // Function : Values
194 // Purpose : calcul of the value and the derivative of the function
195 //==============================================
196  Standard_Boolean GeomFill_FunctionGuide::Values(const math_Vector& X,
197                                                  math_Vector& F,
198                                                  math_Matrix& D)
199
200   gp_Pnt P,P1;
201   gp_Vec DP,DP1U,DP1V;
202
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
205
206   Standard_Integer i;
207   for (i=1;i<=3;i++)
208     { 
209       F(i) = P.Coord(i) - P1.Coord(i);
210
211       D(i,1) = DP.Coord(i);  
212       D(i,2) = -DP1U.Coord(i);
213       D(i,3) = -DP1V.Coord(i);
214     }// for
215
216   return Standard_True;
217 }
218
219 //==============================================
220 // Function : DerivT
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,
225                                                  const gp_XYZ& DDir,
226                                                  math_Vector& F) 
227
228   gp_Pnt P;
229   gp_Vec DS;
230   DSDT(X(2),X(3), DCentre,DDir, DS);
231
232   TheCurve->D0(X(1), P);
233
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);  
237
238   return Standard_True;
239 }
240
241 //=========================================================
242 // Function : DSDT
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,
247                                    const gp_XYZ& DC,
248                                    const gp_XYZ& DDir,
249                                    gp_Vec& DS) const
250
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 +
255    //            (Vdir^CQ)* Sin(U)
256
257
258    gp_Pnt Pc;
259    TheCurve->D0(V, Pc);                  //Q(v)
260 //   if (!isconst) 
261
262    gp_XYZ& Q  = Pc.ChangeCoord(), DQ(0, 0, 0); //Q
263    if (!isconst) {
264      std::cout << "Not implemented" << std::endl;
265    }
266
267
268    Q.Subtract(Centre);  //CQ
269    DQ -= DC;
270
271    gp_XYZ DVcrossCQ;
272    DVcrossCQ.SetLinearForm(DDir.Crossed (Q), 
273                            Dir.Crossed(DQ));   //Vdir^CQ
274    DVcrossCQ.Multiply (Sin(U)); //(Vdir^CQ)*Sin(U)
275
276    Standard_Real CosU =  Cos(U);
277    gp_XYZ DVdotCQ;
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
281
282    DQ.Multiply (CosU);
283    DQ.Add (DVdotCQ);
284    DQ.Add (DC);
285    DS.SetXYZ(DQ);
286 }
287
288 //=========================================================
289 // Function : Deriv2T
290 // Purpose : calcul of the second derivatice from t
291 //=========================================================
292
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,
299                                                   math_Vector& F) 
300 {
301   math_Vector F1(1,3,0);
302   math_Vector F2(1,3,0);
303  
304   DerivT(Param1, Param, R1, R, F1);
305   DerivT(Param, Param0, R, R0, F2);
306   
307   Standard_Real h1 = Param - Param1;
308   Standard_Real h2 = Param0 - Param;
309   
310   Standard_Integer i;  
311   for (i=1;i<=3;i++)  
312     F(i) = (F2(i) - F1(i))  / ((h2 + h1)/2);
313  
314   return Standard_True; 
315 }
316
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,
325                                                   math_Matrix& D) 
326
327   gp_Pnt P1,P2;
328   gp_Vec DP1,DP2,DP2U,DP2V,DP1U,DP1V;
329
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
334  
335   Standard_Real h = Param0 - Param;
336
337   Standard_Integer i;
338   for (i=1;i<=3;i++)
339     {
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;  
345     }// for
346
347   return Standard_True;
348 }
349
350 //=========================================================
351 // Function : Deriv2X
352 // Purpose : calcul of the second derivative from x
353 //=========================================================
354  Standard_Boolean GeomFill_FunctionGuide::Deriv2X(const math_Vector & X,
355                                                   GeomFill_Tensor& T) 
356
357   gp_Pnt P,P1;
358   gp_Vec DP,D2P,DPU,DPV;
359   gp_Vec D2PU, D2PV, D2PUV;
360
361   TheCurve->D2(X(1), P1, DP, D2P);
362   TheSurface->D2(X(2), X(3), P, DPU, DPV, D2PU, D2PV, D2PUV);
363  
364   T.Init(0.); // tenseur
365
366   Standard_Integer i;
367   for (i=1;i<=3;i++)
368     {
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);
373     }// for
374
375   return Standard_True;
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
413
414
415
416
417
418