summaryrefslogtreecommitdiff
path: root/src/GeomFill/GeomFill_GuideTrihedronAC.cxx
blob: 8384379ea49e2f6c85148cd56d427ec5c2b56bad (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
408
409
410
411
412
413
414
415
416
// File:	GeomFill_GuideTrihedronAC.cxx
// Creted:	Tue Jun 23 15:39:24 1998
// Author:	Stephanie HUMEAU
//		<shu@sun17>


#include <GeomFill_GuideTrihedronAC.ixx>

#include <gp_Pnt.hxx>
#include <gp_Dir.hxx>
#include <gp_Vec.hxx>
#include <Precision.hxx>
#include <TColStd_SequenceOfReal.hxx>

#include <Approx_CurvlinFunc.hxx>
#include <Adaptor3d_Curve.hxx>
#include <GeomAdaptor.hxx>
#include <GeomAdaptor_HCurve.hxx>

#include <GeomFill_Frenet.hxx>
#include <GeomLib.hxx>


//=======================================================================
//function : GuideTrihedron
//purpose  : Constructor
//=======================================================================
 GeomFill_GuideTrihedronAC::GeomFill_GuideTrihedronAC(const Handle(Adaptor3d_HCurve) & guide)
{
  myCurve.Nullify();
  myGuide =  guide;
  myTrimG =  guide;
  myGuideAC = new (Approx_CurvlinFunc) (myGuide,1.e-7);
  Lguide = myGuideAC->GetLength(); 
  UTol = STol = Precision::PConfusion();
  Orig1 = 0; // origines pour le cas path multi-edges
  Orig2 = 1;
}

//=======================================================================
//function : Guide
//purpose  : calculation of trihedron
//=======================================================================

 Handle(Adaptor3d_HCurve) GeomFill_GuideTrihedronAC::Guide()const
{
  return myGuide;
}

//=======================================================================
//function : D0
//purpose  : calculation of trihedron
//=======================================================================
 Standard_Boolean GeomFill_GuideTrihedronAC::D0(const Standard_Real Param,
						gp_Vec& Tangent,
						gp_Vec& Normal,
						gp_Vec& BiNormal) 
{ 
  Standard_Real s = myCurveAC->GetSParameter(Param); // abscisse curviligne <=> Param
  Standard_Real OrigG = Orig1 + s*(Orig2-Orig1); // abscisse curv sur le guide (cas multi-edges)
  Standard_Real tG = myGuideAC->GetUParameter(myGuide->GetCurve(), OrigG, 1); // param <=> s sur theGuide

  gp_Pnt P, PG;
  gp_Vec To, B;
  myTrimmed->D1(Param, P, To);//point et derivee au parametre Param sur myCurve
  myTrimG->D0(tG, PG);// point au parametre tG sur myGuide
 
  gp_Vec n (P, PG); // vecteur definissant la normale
  
  Normal = n.Normalized();
  B = To.Crossed(Normal);
  BiNormal = B/B.Magnitude();
  Tangent = Normal.Crossed(BiNormal);
  Tangent.Normalize();

  return Standard_True;
}

//=======================================================================
//function : D1
//purpose  : calculation of trihedron and first derivative
//=======================================================================
 Standard_Boolean GeomFill_GuideTrihedronAC::D1(const Standard_Real Param,
						gp_Vec& Tangent,
						gp_Vec& DTangent,
						gp_Vec& Normal,
						gp_Vec& DNormal,
						gp_Vec& BiNormal,	   
						gp_Vec& DBiNormal) 
{ 
//triedre
  Standard_Real s, OrigG, tG, dtg; 
 // abscisse curviligne <=> Param
  s = myCurveAC->GetSParameter(Param);
  // parametre <=> s sur theGuide
  OrigG = Orig1 + s*(Orig2-Orig1); 
  // parametre <=> s sur  theGuide
  tG = myGuideAC->GetUParameter(myGuide->GetCurve(), OrigG, 1); 

  gp_Pnt P, PG;
  gp_Vec To, DTo, TG, B, BPrim;
  
  myTrimmed->D2(Param, P, To, DTo);
  myTrimG->D1(tG, PG, TG);
  
  gp_Vec n (P, PG), dn; 
  Standard_Real Norm = n.Magnitude();
  if (Norm < 1.e-12) {
    Norm = 1;
#if DEB
    cout << "GuideTrihedronAC : Normal indefinie" << endl;
#endif
  }
  
  n /= Norm;
  //derivee de n par rapport a Param
  dtg = (Orig2-Orig1)*(To.Magnitude()/TG.Magnitude())*(Lguide/L);
  dn.SetLinearForm(dtg, TG, -1, To);
  dn /= Norm;

// triedre
  Normal = n;
  B = To.Crossed(Normal);
  Standard_Real NormB = B.Magnitude();
  B/= NormB;

  BiNormal = B; 

  Tangent = Normal.Crossed(BiNormal);
  Tangent.Normalize();

// derivee premiere
  DNormal.SetLinearForm(-(n.Dot(dn)), n, dn);  
 
  BPrim.SetLinearForm(DTo.Crossed(Normal), To.Crossed(DNormal));

  DBiNormal.SetLinearForm(-(B.Dot(BPrim)), B, BPrim);
  DBiNormal /= NormB;

  DTangent.SetLinearForm(Normal.Crossed(DBiNormal), DNormal.Crossed(BiNormal));

  return Standard_True;
}


//=======================================================================
//function : D2
//purpose  : calculation of trihedron and derivatives
//=======================================================================
 Standard_Boolean GeomFill_GuideTrihedronAC::D2(const Standard_Real Param,
						gp_Vec& Tangent,
						gp_Vec& DTangent,
						gp_Vec& D2Tangent,
						gp_Vec& Normal,
						gp_Vec& DNormal,
						gp_Vec& D2Normal,
						gp_Vec& BiNormal,			  
						gp_Vec& DBiNormal,		  
						gp_Vec& D2BiNormal) 
{ 
  // abscisse curviligne <=> Param
  Standard_Real s = myCurveAC->GetSParameter(Param); 
  // parametre <=> s sur theGuide
  Standard_Real OrigG = Orig1 + s*(Orig2-Orig1); 
  Standard_Real tG = myGuideAC->GetUParameter(myGuide->GetCurve(), 
					      OrigG, 1); 

  gp_Pnt P,PG;
  gp_Vec TG,DTG;
//  gp_Vec To,DTo,D2To,B;
  gp_Vec To,DTo,D2To;
  
  myTrimmed->D3(Param, P, To, DTo, D2To);
  myTrimG->D2(tG, PG, TG, DTG);

  Standard_Real NTo = To.Magnitude();
  Standard_Real N2To = To.SquareMagnitude();
  Standard_Real NTG = TG.Magnitude();
  Standard_Real N2Tp = TG.SquareMagnitude();
  Standard_Real d2tp_dt2, dtg_dt; 
  dtg_dt = (Orig2-Orig1)*(NTo/NTG)*(Lguide/L);

  gp_Vec n(P, PG); // vecteur definissant la normale
  Standard_Real Norm = n.Magnitude(), ndn;
  //derivee de n par rapport a Param
  gp_Vec dn, d2n;
  dn.SetLinearForm(dtg_dt, TG, -1, To);

  //derivee seconde de tG par rapport a Param
  d2tp_dt2 = (Orig2-Orig1)*(Lguide/L) * 
    ( DTo.Dot(To) / (NTo*NTG) - N2To*TG*DTG*(Lguide/L) / (N2Tp*N2Tp));
  //derivee seconde de n par rapport a Param
  d2n.SetLinearForm(dtg_dt*dtg_dt,DTG, d2tp_dt2, TG, -1, DTo);

  if (Norm > 1.e-9) {
    n /= Norm;
    dn /= Norm;
    d2n /= Norm;
  }
//triedre
  Normal = n;

  gp_Vec TN, DTN, D2TN;
  TN  = To.Crossed(Normal);


  Standard_Real Norma = TN.Magnitude();
  if (Norma > 1.e-9) TN /= Norma;

  BiNormal = TN; 

  Tangent = Normal.Crossed(BiNormal);
//  Tangent.Normalize();

// derivee premiere du triedre
//  gp_Vec DTN = DTo.Crossed(Normal);
//  gp_Vec TDN = To.Crossed(DNormal);
//  gp_Vec DT = DTN + TDN;

  ndn = n.Dot(dn);
  DNormal.SetLinearForm(-ndn, n, dn); 

  DTN.SetLinearForm(DTo.Crossed(Normal),  To.Crossed(DNormal));
  DTN /= Norma;
  Standard_Real TNDTN = TN.Dot(DTN);

  DBiNormal.SetLinearForm(-TNDTN, TN, DTN);

  DTangent.SetLinearForm(Normal.Crossed(DBiNormal),
			 DNormal.Crossed(BiNormal));


//derivee seconde du triedre
  DTo.Crossed(DNormal);
  Standard_Real TN2 = TN.SquareMagnitude();

  D2Normal.SetLinearForm(-2*ndn, dn, 
			 3*ndn*ndn - (dn.SquareMagnitude() + n.Dot(d2n)),n,
			 d2n);
			 

  D2TN.SetLinearForm(1, D2To.Crossed(Normal), 
		     2, DTo.Crossed(DNormal),
		     To.Crossed(D2Normal));
  D2TN /= Norma;

  D2BiNormal.SetLinearForm(-2*TNDTN, DTN, 
			   3*TNDTN*TNDTN - (TN2 + TN.Dot(D2TN)), TN,
			   D2TN);
    
  D2Tangent.SetLinearForm(1, D2Normal.Crossed(BiNormal),
			  2, DNormal.Crossed(DBiNormal), 
			  Normal.Crossed(D2BiNormal) );

//  return Standard_True;
  return Standard_False;

}


//=======================================================================
//function : Copy
//purpose  : 
//=======================================================================
 Handle(GeomFill_TrihedronLaw) GeomFill_GuideTrihedronAC::Copy() const
{
 Handle(GeomFill_GuideTrihedronAC) copy = 
   new (GeomFill_GuideTrihedronAC) (myGuide);
 copy->SetCurve(myCurve);
 copy->Origine(Orig1,Orig2);
 return copy;
} 

//=======================================================================
//function : SetCurve
//purpose  : 
//=======================================================================
 void GeomFill_GuideTrihedronAC::SetCurve(const Handle(Adaptor3d_HCurve)& C) 
{
  myCurve = C;
  myTrimmed = C;
  if (!myCurve.IsNull()) {
    myCurveAC = new (Approx_CurvlinFunc) (C,1.e-7);
    L = myCurveAC->GetLength();
//    CorrectOrient(myGuide);
  }
}


//=======================================================================
//function : NbIntervals
//purpose  : 
//=======================================================================
 Standard_Integer GeomFill_GuideTrihedronAC::NbIntervals(const GeomAbs_Shape S) const
{
  Standard_Integer Nb;
  Nb = myCurveAC->NbIntervals(S);
  TColStd_Array1OfReal DiscC(1, Nb+1);
  myCurveAC->Intervals(DiscC, S);
  Nb =  myGuideAC->NbIntervals(S);
  TColStd_Array1OfReal DiscG(1, Nb+1);
  myGuideAC->Intervals(DiscG, S);

  TColStd_SequenceOfReal Seq;
  GeomLib::FuseIntervals(DiscC, DiscG, Seq);
  
  return Seq.Length()-1;

}

//======================================================================
//function :Intervals
//purpose  : 
//=======================================================================
 void GeomFill_GuideTrihedronAC::Intervals(TColStd_Array1OfReal& TT,
					   const GeomAbs_Shape S) const
{
  Standard_Integer Nb, ii;
  Nb = myCurveAC->NbIntervals(S);
  TColStd_Array1OfReal DiscC(1, Nb+1);
  myCurveAC->Intervals(DiscC, S);
  Nb =  myGuideAC->NbIntervals(S);
  TColStd_Array1OfReal DiscG(1, Nb+1);
  myGuideAC->Intervals(DiscG, S);

  TColStd_SequenceOfReal Seq;
  GeomLib::FuseIntervals(DiscC, DiscG, Seq); 
  Nb = Seq.Length();

  for (ii=1; ii<=Nb; ii++) {
    TT(ii) =  myCurveAC->GetUParameter(myCurve->GetCurve(), Seq(ii), 1);
  }

}

//======================================================================
//function :SetInterval
//purpose  : 
//=======================================================================
void GeomFill_GuideTrihedronAC::SetInterval(const Standard_Real First,
					    const Standard_Real Last) 
{
  myTrimmed = myCurve->Trim(First, Last, UTol); 
  Standard_Real Sf, Sl, U;

  Sf = myCurveAC->GetSParameter(First);
  Sl = myCurveAC->GetSParameter(Last);
//  if (Sl>1) Sl=1;
//  myCurveAC->Trim(Sf, Sl, UTol);

  U = Orig1 + Sf*(Orig2-Orig1);
  Sf = myGuideAC->GetUParameter(myGuide->GetCurve(), U, 1);
  U = Orig1 + Sl*(Orig2-Orig1);
  Sl = myGuideAC->GetUParameter(myGuide->GetCurve(), U, 1);
  myTrimG = myGuide->Trim(Sf, Sl, UTol); 
}



//=======================================================================
//function : GetAverageLaw
//purpose  : 
//=======================================================================
 void GeomFill_GuideTrihedronAC::GetAverageLaw(gp_Vec& ATangent,
					       gp_Vec& ANormal,
					       gp_Vec& ABiNormal) 
{
  Standard_Integer ii;
  Standard_Real t, Delta = (myCurve->LastParameter() - 
			    myCurve->FirstParameter())/20.001;

  ATangent.SetCoord(0.,0.,0.);
  ANormal.SetCoord(0.,0.,0.);
  ABiNormal.SetCoord(0.,0.,0.);
  gp_Vec T, N, B;
  
  for (ii=1; ii<=20; ii++) {
    t = myCurve->FirstParameter() +(ii-1)*Delta;
    D0(t, T, N, B);
    ATangent +=T;
    ANormal  +=N;
    ABiNormal+=B;
  }
  ATangent  /= 20;
  ANormal   /= 20;
  ABiNormal /= 20; 
}

//=======================================================================
//function : IsConstant
//purpose  : 
//=======================================================================
 Standard_Boolean GeomFill_GuideTrihedronAC::IsConstant() const
{
  return  Standard_False;
}

//=======================================================================
//function : IsOnlyBy3dCurve
//purpose  : 
//=======================================================================
 Standard_Boolean GeomFill_GuideTrihedronAC::IsOnlyBy3dCurve() const
{
  return Standard_False;
}

//=======================================================================
//function : Origine
//purpose  : 
//=======================================================================
 void GeomFill_GuideTrihedronAC::Origine(const Standard_Real OrACR1,
					 const Standard_Real OrACR2)
{
  Orig1 = OrACR1;
  Orig2 = OrACR2;
}