summaryrefslogtreecommitdiff
path: root/src/CPnts/CPnts_AbscissaPoint.cxx
blob: c912c82050009b0aef4393bb241162312d5e052e (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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
//------------------------------------------------------------------------
//                Calculer un point a abscisse donne a partir 
//                d un point donne
//
//  cas traites :segment de droite,arc de cercle courbe parametree
//               la courbe doit etre C1
//
//  pour une courbe parametree:
//
//   on calcule la longueur totale de la courbe
//   on calcule un point approche en assimilant la courbe a une droite
//   on calcule la longueur  de la courbe entre le point de depart et
//   le point approche
//   par iteration succsessive on trouve le point et son parametre associe
//   appel a FunctionRoot
//
// 

#include <CPnts_AbscissaPoint.ixx>

#include <math_GaussSingleIntegration.hxx>
#include <math_FunctionRoot.hxx>
#include <StdFail_NotDone.hxx>
#include <Standard_ConstructionError.hxx>

#include <gp_Vec.hxx>
#include <gp_Vec2d.hxx>
#include <Geom_BezierCurve.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Geom2d_BezierCurve.hxx>
#include <Geom2d_BSplineCurve.hxx>
#include <Precision.hxx>

// auxiliary functions to compute the length of the derivative

static Standard_Real f3d(const Standard_Real X, const Standard_Address C)
{
  gp_Vec V = ((Adaptor3d_Curve*)C)->DN(X,1);
  return V.Magnitude();
}

static Standard_Real f2d(const Standard_Real X, const Standard_Address C)
{
  gp_Vec2d V = ((Adaptor2d_Curve2d*)C)->DN(X,1);
  return V.Magnitude();
}

static Standard_Integer order(const Adaptor3d_Curve& C)
{
  switch (C.GetType()) {
    
  case GeomAbs_Line :
    return 2;

  case GeomAbs_Parabola :
    return 5;

  case GeomAbs_BezierCurve :
    return Min(24, 2*C.Bezier()->Degree());

  case GeomAbs_BSplineCurve :
    return Min(24, 2*C.BSpline()->NbPoles()-1);
    
    default :
      return 10;
  }
}

static Standard_Integer order(const Adaptor2d_Curve2d& C)
{
  switch (C.GetType()) {
    
  case GeomAbs_Line :
    return 2;

  case GeomAbs_Parabola :
    return 5;

  case GeomAbs_BezierCurve :
    return Min(24, 2*C.Bezier()->Degree());

  case GeomAbs_BSplineCurve :
    return Min(24, 2*C.BSpline()->NbPoles()-1);
    
    default :
      return 10;
  }
}


//=======================================================================
//function : Length
//purpose  : 3d
//=======================================================================

Standard_Real CPnts_AbscissaPoint::Length(const Adaptor3d_Curve& C) 
{
  return CPnts_AbscissaPoint::Length(C, C.FirstParameter(), 
				        C.LastParameter());
}

//=======================================================================
//function : Length
//purpose  : 2d
//=======================================================================

Standard_Real CPnts_AbscissaPoint::Length(const Adaptor2d_Curve2d& C) 
{
  return CPnts_AbscissaPoint::Length(C, C.FirstParameter(), 
				        C.LastParameter());
}

//=======================================================================
//function : Length
//purpose  : 3d with tolerance
//=======================================================================

Standard_Real CPnts_AbscissaPoint::Length(const Adaptor3d_Curve& C, const Standard_Real Tol) 
{
  return CPnts_AbscissaPoint::Length(C, C.FirstParameter(), 
				        C.LastParameter(), Tol);
}

//=======================================================================
//function : Length
//purpose  : 2d with tolerance
//=======================================================================

Standard_Real CPnts_AbscissaPoint::Length(const Adaptor2d_Curve2d& C, const Standard_Real Tol) 
{
  return CPnts_AbscissaPoint::Length(C, C.FirstParameter(), 
				        C.LastParameter(), Tol);
}


//=======================================================================
//function : Length
//purpose  : 3d with parameters
//=======================================================================

Standard_Real CPnts_AbscissaPoint::Length(const Adaptor3d_Curve& C,
					  const Standard_Real U1,
					  const Standard_Real U2) 
{
  CPnts_MyGaussFunction FG;
//POP pout WNT
  CPnts_RealFunction rf = f3d;
  FG.Init(rf,(Standard_Address)&C);
//  FG.Init(f3d,(Standard_Address)&C);
  math_GaussSingleIntegration TheLength(FG, U1, U2, order(C));
  if (!TheLength.IsDone()) {
    Standard_ConstructionError::Raise();
  }
  return Abs(TheLength.Value());
}

//=======================================================================
//function : Length
//purpose  : 2d with parameters
//=======================================================================

Standard_Real CPnts_AbscissaPoint::Length(const Adaptor2d_Curve2d& C,
					  const Standard_Real U1,
					  const Standard_Real U2) 
{
  CPnts_MyGaussFunction FG;
//POP pout WNT
  CPnts_RealFunction rf = f2d;
  FG.Init(rf,(Standard_Address)&C);
//  FG.Init(f2d,(Standard_Address)&C);
  math_GaussSingleIntegration TheLength(FG, U1, U2, order(C));
  if (!TheLength.IsDone()) {
    Standard_ConstructionError::Raise();
  }
  return Abs(TheLength.Value());
}

//=======================================================================
//function : Length
//purpose  : 3d with parameters and tolerance
//=======================================================================

Standard_Real CPnts_AbscissaPoint::Length(const Adaptor3d_Curve& C,
					  const Standard_Real U1,
					  const Standard_Real U2,
					  const Standard_Real Tol) 
{
  CPnts_MyGaussFunction FG;
//POP pout WNT
  CPnts_RealFunction rf = f3d;
  FG.Init(rf,(Standard_Address)&C);
//  FG.Init(f3d,(Standard_Address)&C);
  math_GaussSingleIntegration TheLength(FG, U1, U2, order(C), Tol);
  if (!TheLength.IsDone()) {
    Standard_ConstructionError::Raise();
  }
  return Abs(TheLength.Value());
}

//=======================================================================
//function : Length
//purpose  : 2d with parameters and tolerance
//=======================================================================

Standard_Real CPnts_AbscissaPoint::Length(const Adaptor2d_Curve2d& C,
					  const Standard_Real U1,
					  const Standard_Real U2,
					  const Standard_Real Tol) 
{
  CPnts_MyGaussFunction FG;
//POP pout WNT
  CPnts_RealFunction rf = f2d;
  FG.Init(rf,(Standard_Address)&C);
//  FG.Init(f2d,(Standard_Address)&C);
  math_GaussSingleIntegration TheLength(FG, U1, U2, order(C), Tol);
  if (!TheLength.IsDone()) {
    Standard_ConstructionError::Raise();
  }
  return Abs(TheLength.Value());
}

//=======================================================================
//function : CPnts_AbscissaPoint
//purpose  : 
//=======================================================================

CPnts_AbscissaPoint::CPnts_AbscissaPoint() : myDone(Standard_False)
{
}

//=======================================================================
//function : CPnts_AbscissaPoint
//purpose  : 
//=======================================================================

CPnts_AbscissaPoint::CPnts_AbscissaPoint(const Adaptor3d_Curve& C,
					 const Standard_Real   Abscissa,
					 const Standard_Real   U0,
					 const Standard_Real   Resolution)
{
//  Init(C);
  Init(C, Resolution); //rbv's modification
//
  Perform(Abscissa, U0, Resolution);
}

//=======================================================================
//function : CPnts_AbscissaPoint
//purpose  : 
//=======================================================================

CPnts_AbscissaPoint::CPnts_AbscissaPoint(const Adaptor2d_Curve2d& C,
					 const Standard_Real   Abscissa,
					 const Standard_Real   U0,
					 const Standard_Real   Resolution)
{
  Init(C);
  Perform(Abscissa, U0, Resolution);
}


//=======================================================================
//function : CPnts_AbscissaPoint
//purpose  : 
//=======================================================================

CPnts_AbscissaPoint::CPnts_AbscissaPoint(const Adaptor3d_Curve& C,
					 const Standard_Real   Abscissa,
					 const Standard_Real   U0,
					 const Standard_Real   Ui,
					 const Standard_Real   Resolution)
{
  Init(C);
  Perform(Abscissa, U0, Ui, Resolution);
}

//=======================================================================
//function : CPnts_AbscissaPoint
//purpose  : 
//=======================================================================

CPnts_AbscissaPoint::CPnts_AbscissaPoint(const Adaptor2d_Curve2d& C,
					 const Standard_Real   Abscissa,
					 const Standard_Real   U0,
					 const Standard_Real   Ui,
					 const Standard_Real   Resolution)
{
  Init(C);
  Perform(Abscissa, U0, Ui, Resolution);
}


//=======================================================================
//function : Init
//purpose  : 
//=======================================================================

void CPnts_AbscissaPoint::Init(const Adaptor3d_Curve& C)
{
  Init(C,C.FirstParameter(),C.LastParameter());
}

//=======================================================================
//function : Init
//purpose  : 
//=======================================================================

void CPnts_AbscissaPoint::Init(const Adaptor2d_Curve2d& C)
{
  Init(C,C.FirstParameter(),C.LastParameter());
}

//=======================================================================
//function : Init
//purpose  : introduced by rbv for curvilinear parametrization
//=======================================================================

void CPnts_AbscissaPoint::Init(const Adaptor3d_Curve& C, const Standard_Real Tol)
{
  Init(C,C.FirstParameter(),C.LastParameter(), Tol);
}

//=======================================================================
//function : Init
//purpose  : 
//=======================================================================

void CPnts_AbscissaPoint::Init(const Adaptor2d_Curve2d& C, const Standard_Real Tol)
{
  Init(C,C.FirstParameter(),C.LastParameter(), Tol);
}

//=======================================================================
//function : Init
//purpose  : 
//=======================================================================

void CPnts_AbscissaPoint::Init(const Adaptor3d_Curve& C,
			       const Standard_Real  U1,
			       const Standard_Real  U2)
{
//POP pout WNT
  CPnts_RealFunction rf = f3d;
  myF.Init(rf,(Standard_Address)&C,order(C));
//  myF.Init(f3d,(Standard_Address)&C,order(C));
  myL = CPnts_AbscissaPoint::Length(C, U1, U2);
  myUMin = Min(U1, U2);
  myUMax = Max(U1, U2);
  Standard_Real DU = myUMax - myUMin;
  myUMin = myUMin - DU;
  myUMax = myUMax + DU;
}

//=======================================================================
//function : Init
//purpose  : 
//=======================================================================

void CPnts_AbscissaPoint::Init(const Adaptor2d_Curve2d& C,
			       const Standard_Real    U1,
			       const Standard_Real    U2)
{
//POP pout WNT
  CPnts_RealFunction rf = f2d;
  myF.Init(rf,(Standard_Address)&C,order(C));
//  myF.Init(f2d,(Standard_Address)&C,order(C));
  myL = CPnts_AbscissaPoint::Length(C, U1, U2);
  myUMin = Min(U1, U2);
  myUMax = Max(U1, U2);
  Standard_Real DU = myUMax - myUMin;
  myUMin = myUMin - DU;
  myUMax = myUMax + DU;
}


//=======================================================================
//function : Init
//purpose  : introduced by rbv for curvilinear parametrization
//=======================================================================

void CPnts_AbscissaPoint::Init(const Adaptor3d_Curve& C,
			       const Standard_Real  U1,
			       const Standard_Real  U2,
			       const Standard_Real  Tol)
{
//POP pout WNT
  CPnts_RealFunction rf = f3d;
  myF.Init(rf,(Standard_Address)&C,order(C));
//  myF.Init(f3d,(Standard_Address)&C,order(C));
  myL = CPnts_AbscissaPoint::Length(C, U1, U2, Tol);
  myUMin = Min(U1, U2);
  myUMax = Max(U1, U2);
  Standard_Real DU = myUMax - myUMin;
  myUMin = myUMin - DU;
  myUMax = myUMax + DU;
}

//=======================================================================
//function : Init
//purpose  : 
//=======================================================================

void CPnts_AbscissaPoint::Init(const Adaptor2d_Curve2d& C,
			       const Standard_Real    U1,
			       const Standard_Real    U2,
			       const Standard_Real    Tol)
{
//POP pout WNT
  CPnts_RealFunction rf = f2d;
  myF.Init(rf,(Standard_Address)&C,order(C));
//  myF.Init(f2d,(Standard_Address)&C,order(C));
  myL = CPnts_AbscissaPoint::Length(C, U1, U2, Tol);
  myUMin = Min(U1, U2);
  myUMax = Max(U1, U2);
  Standard_Real DU = myUMax - myUMin;
  myUMin = myUMin - DU;
  myUMax = myUMax + DU;
}

//=======================================================================
//function : Perform
//purpose  : 
//=======================================================================

void CPnts_AbscissaPoint::Perform(const Standard_Real   Abscissa,
				  const Standard_Real   U0,
				  const Standard_Real   Resolution) 
{
  if (myL < Precision::Confusion()) {
    //
    //  on sort moins violemment : j'espere que l'on espere pas
    //  un increment notable au niveau de myParam
    //
    myDone = Standard_True ;
    myParam = U0 ;
  
  }
  else {
    Standard_Real Ui = U0 + (Abscissa / myL) * (myUMax - myUMin) / 3.;
    // exercice : why 3 ?
    Perform(Abscissa,U0,Ui,Resolution);
  }
}

//=======================================================================
//function : Perform
//purpose  : 
//=======================================================================

void CPnts_AbscissaPoint::Perform(const Standard_Real   Abscissa,
				  const Standard_Real   U0,
				  const Standard_Real   Ui,
				  const Standard_Real   Resolution) 
{
  if (myL < Precision::Confusion()) {
    //
    //  on sort moins violemment :
    //
    myDone = Standard_True ;
    myParam = U0 ;
  }
  else {
    myDone = Standard_False;
    myF.Init(U0, Abscissa);

    math_FunctionRoot Solution(myF, Ui, Resolution, myUMin, myUMax);
    
// Temporairement on vire le test de validite de la solution
// Il faudra des que l on pourra faire du cdl, rendre un tolreached
// lbo 21/03/97
//    if (Solution.IsDone()) {
//      Standard_Real D;
//      myF.Derivative(Solution.Root(),D);
//      if (Abs(Solution.Value()) < Resolution * D) {
//	myDone = Standard_True;
//	myParam = Solution.Root();
//      }
//    }
    if (Solution.IsDone()) {
      myDone = Standard_True;
      myParam = Solution.Root();
    }
  }
}

//=======================================================================
//function : AdvPerform
//purpose  : 
//=======================================================================

void CPnts_AbscissaPoint::AdvPerform(const Standard_Real   Abscissa,
				  const Standard_Real   U0,
				  const Standard_Real   Ui,
				  const Standard_Real   Resolution) 
{
  if (myL < Precision::Confusion()) {
    //
    //  on sort moins violemment :
    //
    myDone = Standard_True ;
    myParam = U0 ;
  }
  else {
    myDone = Standard_False;
//    myF.Init(U0, Abscissa);
    myF.Init(U0, Abscissa, Resolution/10); // rbv's modification

    math_FunctionRoot Solution(myF, Ui, Resolution, myUMin, myUMax);
    
// Temporairement on vire le test de validite de la solution
// Il faudra des que l on pourra faire du cdl, rendre un tolreached
// lbo 21/03/97
//    if (Solution.IsDone()) {
//      Standard_Real D;
//      myF.Derivative(Solution.Root(),D);
//      if (Abs(Solution.Value()) < Resolution * D) {
//	myDone = Standard_True;
//	myParam = Solution.Root();
//      }
//    }
    if (Solution.IsDone()) {
      myDone = Standard_True;
      myParam = Solution.Root();
    }
  }
}