summaryrefslogtreecommitdiff
path: root/src/GeomFill/GeomFill_FunctionGuide.cxx
blob: 2a554544fa444f0dc67e2666c1a989cb8899f3c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
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
// File:	GeomFill_FunctionGuide.cxx
// Created:	Thu Jul  9 09:30:26 1998
// Author:	Stephanie HUMEAU
//		<shu@sun17>


#include <GeomFill_FunctionGuide.ixx>

#include <GeomFill_SectionLaw.hxx>

#include <Geom_TrimmedCurve.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Geom_SurfaceOfRevolution.hxx>

#include <GeomAdaptor_HCurve.hxx>
#include <GeomTools.hxx>

#include <Precision.hxx>
#include <gp_Pnt.hxx>
#include <gp_Vec.hxx>
#include <gp_XYZ.hxx>
#include <gp_Dir.hxx>
#include <gp_Trsf.hxx>
#include <gp_Ax1.hxx>
#include <gp_Ax3.hxx>

#include <TColStd_HArray1OfInteger.hxx>
#include <TColStd_HArray1OfReal.hxx>
#include <TColgp_HArray1OfPnt.hxx>


//#include <Standard_NotImplemented.hxx>

//==============================================
//   Calcul de la valeur de la fonction :
//                      G(w) - S(teta,v) = 0
// ou G : guide   et   S : surface de revolution 
//==============================================


//==============================================
// Function : FunctionGuide
// Purpose : Initialisation de la section et de la surface d'arret
//==============================================
 GeomFill_FunctionGuide::GeomFill_FunctionGuide
     (const Handle(GeomFill_SectionLaw)& S, 
      const Handle(Adaptor3d_HCurve)& C,
      const Standard_Real Param)
: TheGuide(C), TheLaw(S), TheUonS(Param)
{
  Standard_Real Tol = Precision::Confusion();
  if (TheLaw->IsConstant(Tol)) {
    isconst = Standard_True;
    TheConst = TheLaw->ConstantSection();
    First = TheConst->FirstParameter();
    Last =  TheConst->LastParameter();
  }
  else {
   isconst = Standard_False;
   TheConst.Nullify(); 
  }
  TheCurve.Nullify();
}

//==============================================
// Function : SetParam
// Purpose : Initialisation de la surface de revolution
//==============================================
// void GeomFill_FunctionGuide::SetParam(const Standard_Real Param,
 void GeomFill_FunctionGuide::SetParam(const Standard_Real ,
				       const gp_Pnt& C,
				       const gp_XYZ& D,
				       const gp_XYZ& DX)
{
  Centre = C.XYZ();
  Dir = D;

  //repere fixe
  gp_Ax3 Rep (gp::Origin(), gp::DZ(), gp::DX());
 

  // calculer transfo entre triedre et Oxyz
  gp_Dir B2 = DX;
  gp_Ax3 RepTriedre(C, D, B2);
  gp_Trsf Transfo;
  Transfo.SetTransformation(RepTriedre, Rep);
   

  if (isconst) {
    TheCurve = new (Geom_TrimmedCurve) 
      (Handle(Geom_Curve)::DownCast(TheConst->Copy()),
	First, Last);
  }
  else {
    Standard_Integer NbPoles, NbKnots, Deg;
    TheLaw->SectionShape(NbPoles, NbKnots, Deg);
    TColStd_Array1OfInteger Mult(1,NbKnots);
    TheLaw->Mults( Mult);
    TColStd_Array1OfReal Knots(1,NbKnots);
    TheLaw->Knots(Knots);
    TColgp_Array1OfPnt Poles(1, NbPoles);
    TColStd_Array1OfReal Weights(1,  NbPoles);
    TheLaw->D0(TheUonS, Poles, Weights);
    if (TheLaw->IsRational()) 
      TheCurve = new (Geom_BSplineCurve)
	(Poles, Weights, Knots, Mult ,
	 Deg, TheLaw->IsUPeriodic());
   else 
     TheCurve = new (Geom_BSplineCurve)
	(Poles, Knots, Mult,
	 Deg, TheLaw->IsUPeriodic()); 
  }

  gp_Ax1 Axe(C, Dir);
  TheCurve->Transform(Transfo);
  TheSurface = new(Geom_SurfaceOfRevolution) (TheCurve, Axe);
}

//==============================================
// Function : NbVariables (w, u, v)
// Purpose :
//==============================================
 Standard_Integer GeomFill_FunctionGuide::NbVariables()const 
{ 
  return 3;
}

//==============================================
// Function : NbEquations
// Purpose :
//==============================================
 Standard_Integer GeomFill_FunctionGuide::NbEquations()const
{
  return 3;
}

//==============================================
// Function : Value
// Purpose : calcul of the value of the function at <X>
//==============================================
 Standard_Boolean GeomFill_FunctionGuide::Value(const math_Vector& X,
					        math_Vector& F) 
{
  gp_Pnt P,P1;
 

  TheGuide->D0(X(1), P);
  TheSurface->D0(X(2), X(3), P1);
  
  F(1) = P.Coord(1) - P1.Coord(1);
  F(2) = P.Coord(2) - P1.Coord(2); 
  F(3) = P.Coord(3) - P1.Coord(3);

  return Standard_True;
}

//==============================================
// Function : Derivatives
// Purpose :calcul of the derivative of the function
//==============================================
 Standard_Boolean GeomFill_FunctionGuide::Derivatives(const math_Vector& X,
						      math_Matrix& D) 
{
  gp_Pnt P,P1;
  gp_Vec DP,DP1U,DP1V;

  TheGuide->D1(X(1),P,DP);
  TheSurface->D1(X(2),X(3),P1,DP1U,DP1V);

  Standard_Integer i;
  for (i=1;i<=3;i++)
    {
      D(i,1) = DP.Coord(i);  
      D(i,2) = -DP1U.Coord(i);
      D(i,3) = -DP1V.Coord(i);
    }// for

  return Standard_True;
}

//==============================================
// Function : Values
// Purpose : calcul of the value and the derivative of the function
//==============================================
 Standard_Boolean GeomFill_FunctionGuide::Values(const math_Vector& X,
						 math_Vector& F,
						 math_Matrix& D)
{ 
  gp_Pnt P,P1;
  gp_Vec DP,DP1U,DP1V;

  TheGuide->D1(X(1),P,DP); //derivee de la generatrice
  TheSurface->D1(X(2),X(3),P1,DP1U,DP1V); //derivee de la new surface

  Standard_Integer i;
  for (i=1;i<=3;i++)
    { 
      F(i) = P.Coord(i) - P1.Coord(i);

      D(i,1) = DP.Coord(i);  
      D(i,2) = -DP1U.Coord(i);
      D(i,3) = -DP1V.Coord(i);
    }// for

  return Standard_True;
}

//==============================================
// Function : DerivT
// Purpose : calcul of the first derivative from t 
//==============================================
 Standard_Boolean GeomFill_FunctionGuide::DerivT(const math_Vector& X,
						 const gp_XYZ& DCentre,
						 const gp_XYZ& DDir,
						 math_Vector& F) 
{ 
  gp_Pnt P;
  gp_Vec DS;
  DSDT(X(2),X(3), DCentre,DDir, DS);

  TheCurve->D0(X(1), P);

  F(1) = P.Coord(1) - DS.Coord(1);
  F(2) = P.Coord(2) - DS.Coord(2); 
  F(3) = P.Coord(3) - DS.Coord(3);  

  return Standard_True;
}

//=========================================================
// Function : DSDT
// Purpose : calcul de la derive de la surface /t en U, V
//=========================================================
 void GeomFill_FunctionGuide::DSDT(const Standard_Real U,
				   const Standard_Real V,
				   const gp_XYZ& DC,
				   const gp_XYZ& DDir,
				   gp_Vec& DS) const
{ 
   // C origine sur l'axe de revolution
   // Vdir vecteur unitaire definissant la direction de l'axe de revolution
   // Q(v) point de parametre V sur la courbe de revolution
   // OM (u,v) = OC + CQ * Cos(U) + (CQ.Vdir)(1-Cos(U)) * Vdir +
   //            (Vdir^CQ)* Sin(U)


   gp_Pnt Pc;
   TheCurve->D0(V, Pc);                  //Q(v)
//   if (!isconst) 

   gp_XYZ& Q  = Pc.ChangeCoord(), DQ(0, 0, 0); //Q
   if (!isconst) {
     cout << "Not implemented" << endl;
   }


   Q.Subtract(Centre);  //CQ
   DQ -= DC;

   gp_XYZ DVcrossCQ;
   DVcrossCQ.SetLinearForm(DDir.Crossed (Q), 
			   Dir.Crossed(DQ));   //Vdir^CQ
   DVcrossCQ.Multiply (Sin(U)); //(Vdir^CQ)*Sin(U)

   Standard_Real CosU =  Cos(U);
   gp_XYZ DVdotCQ;
   DVdotCQ.SetLinearForm(DDir.Dot(Q) + Dir.Dot(DQ), Dir,
			Dir.Dot(Q), DDir);//(CQ.Vdir)(1-Cos(U))Vdir
   DVdotCQ.Add (DVcrossCQ);    //addition des composantes

   DQ.Multiply (CosU);
   DQ.Add (DVdotCQ);
   DQ.Add (DC);
   DS.SetXYZ(DQ);
}

//=========================================================
// Function : Deriv2T
// Purpose : calcul of the second derivatice from t
//=========================================================

/* Standard_Boolean GeomFill_FunctionGuide::Deriv2T(const Standard_Real Param1,
						  const Standard_Real Param,
						  const Standard_Real Param0,
						  const math_Vector & R1,
						  const math_Vector & R,
						  const math_Vector & R0,
						  math_Vector& F) 
{
  math_Vector F1(1,3,0);
  math_Vector F2(1,3,0);
 
  DerivT(Param1, Param, R1, R, F1);
  DerivT(Param, Param0, R, R0, F2);
  
  Standard_Real h1 = Param - Param1;
  Standard_Real h2 = Param0 - Param;
  
  Standard_Integer i;  
  for (i=1;i<=3;i++)  
    F(i) = (F2(i) - F1(i))  / ((h2 + h1)/2);
 
  return Standard_True; 
}

//=========================================================
// Function : DerivTX
// Purpose : calcul of the second derivative from t and x
//=========================================================
 Standard_Boolean GeomFill_FunctionGuide::DerivTX(const Standard_Real Param,
						  const Standard_Real Param0,
						  const math_Vector & R,
						  const math_Vector & X0,
						  math_Matrix& D) 
{ 
  gp_Pnt P1,P2;
  gp_Vec DP1,DP2,DP2U,DP2V,DP1U,DP1V;

  TheCurve->D1(R(1), P1, DP1); // guide
  TheCurve->D1(X0(1), P2, DP2); 
  TheSurface->D1(R(2), R(3), P1, DP1U, DP1V); // surface
  TheSurface->D1(X0(2), X0(3), P2, DP2U, DP2V); //derivee de la new surface
 
  Standard_Real h = Param0 - Param;

  Standard_Integer i;
  for (i=1;i<=3;i++)
    {
      D(i,1) = (DP2.Coord(i) - DP1.Coord(i)) / h;
      //D(i,2) = - (DP2U.Coord(i) - DP1U.Coord(i)) / h;  
      D(i,2) = - DP1U.Coord(i) * (X0(2)-R(2)) / h;  
      //D(i,3) = - (DP2V.Coord(i) - DP1V.Coord(i)) / h;   
      D(i,3) = - DP1V.Coord(i) * (X0(3)-R(3)) / h;  
    }// for

  return Standard_True;
}

//=========================================================
// Function : Deriv2X
// Purpose : calcul of the second derivative from x
//=========================================================
 Standard_Boolean GeomFill_FunctionGuide::Deriv2X(const math_Vector & X,
						  GeomFill_Tensor& T) 
{ 
  gp_Pnt P,P1;
  gp_Vec DP,D2P,DPU,DPV;
  gp_Vec D2PU, D2PV, D2PUV;

  TheCurve->D2(X(1), P1, DP, D2P);
  TheSurface->D2(X(2), X(3), P, DPU, DPV, D2PU, D2PV, D2PUV);
 
  T.Init(0.); // tenseur

  Standard_Integer i;
  for (i=1;i<=3;i++)
    {
      T(i,1,1) = D2P.Coord(i);  
      T(i,2,2) = -D2PU.Coord(i);
      T(i,3,2) = T(i,2,3) = -D2PUV.Coord(i);
      T(i,3,3) = -D2PV.Coord(i);
    }// for

  return Standard_True;
}*/