Integration of OCCT 6.5.0 from SVN
[occt.git] / src / Approx / Approx_CurvilinearParameter.cxx
CommitLineData
7fd59977 1// File: Approx_CurvilinearParameter.cxx
2// Created: Fri Aug 22 09:11:03 1997
3// Author: Sergey SOKOLOV
4// <ssv@nonox.nnov.matra-dtv.fr>
5
6#include <Approx_CurvilinearParameter.ixx>
7
8#include <Adaptor3d_Curve.hxx>
9#include <GCPnts_AbscissaPoint.hxx>
10#include <gp_Pnt.hxx>
11#include <gp_Pnt2d.hxx>
12#include <gp_Vec.hxx>
13#include <gp_Vec2d.hxx>
14#include <GeomAbs_Shape.hxx>
15#include <AdvApprox_ApproxAFunction.hxx>
16#include <Geom_BSplineCurve.hxx>
17#include <TColStd_HArray1OfReal.hxx>
18#include <TColStd_HArray1OfInteger.hxx>
19#include <TColgp_Array1OfPnt.hxx>
20#include <GeomAdaptor_HCurve.hxx>
21#include <GeomAdaptor_HSurface.hxx>
22#include <TColStd_Array1OfReal.hxx>
23#include <AdvApprox_PrefAndRec.hxx>
24#include <Adaptor3d_CurveOnSurface.hxx>
25#include <Precision.hxx>
26#include <Geom2d_BSplineCurve.hxx>
27#include <TColgp_Array1OfPnt2d.hxx>
28#include <math_Vector.hxx>
29#include <CPnts_AbscissaPoint.hxx>
30#include <Approx_CurvlinFunc.hxx>
31
32#ifdef DEB
33#include <OSD_Timer.hxx>
34static OSD_Chronometer chr_total, chr_init, chr_approx;
35
36Standard_Real t_total, t_init, t_approx;
37void InitChron(OSD_Chronometer& ch)
38{
39 ch.Reset();
40 ch.Start();
41}
42
43void ResultChron( OSD_Chronometer & ch, Standard_Real & time)
44{
45 Standard_Real tch ;
46 ch.Stop();
47 ch.Show(tch);
48 time=time +tch;
49}
50
51Standard_IMPORT Standard_Integer uparam_count;
52Standard_IMPORT Standard_Real t_uparam;
53#endif
54
55//=======================================================================
56//class : Approx_CurvilinearParameter_EvalCurv
57//purpose : case of a free 3D curve
58//=======================================================================
59
60class Approx_CurvilinearParameter_EvalCurv : public AdvApprox_EvaluatorFunction
61{
62 public:
63 Approx_CurvilinearParameter_EvalCurv (const Handle(Approx_CurvlinFunc)& theFunc,
64 Standard_Real First, Standard_Real Last)
65 : fonct(theFunc) { StartEndSav[0] = First; StartEndSav[1] = Last; }
66
67 virtual void Evaluate (Standard_Integer *Dimension,
68 Standard_Real StartEnd[2],
69 Standard_Real *Parameter,
70 Standard_Integer *DerivativeRequest,
71 Standard_Real *Result, // [Dimension]
72 Standard_Integer *ErrorCode);
73
74 private:
75 Handle(Approx_CurvlinFunc) fonct;
76 Standard_Real StartEndSav[2];
77};
78
79void Approx_CurvilinearParameter_EvalCurv::Evaluate (Standard_Integer * Dimension,
80 Standard_Real * StartEnd,
81 Standard_Real * Param,
82 Standard_Integer * Order,
83 Standard_Real * Result,
84 Standard_Integer * ErrorCode)
85{
86 *ErrorCode = 0;
87 Standard_Real S = *Param;
88 TColStd_Array1OfReal Res(0, 2);
89 Standard_Integer i;
90
91// Dimension is incorrect
92 if (*Dimension != 3) {
93 *ErrorCode = 1;
94 }
95// Parameter is incorrect
96 if ( S < StartEnd[0] || S > StartEnd[1] ) {
97 *ErrorCode = 2;
98 }
99
100 if(StartEnd[0] != StartEndSav[0] || StartEnd[1]!= StartEndSav[1])
101 {
102 fonct->Trim(StartEnd[0],StartEnd[1], Precision::Confusion());
103 StartEndSav[0]=StartEnd[0];
104 StartEndSav[1]=StartEnd[1];
105 }
106
107 if(!fonct->EvalCase1(S, *Order, Res)) {
108 *ErrorCode = 3;
109 }
110
111 for(i = 0; i <= 2; i++)
112 Result[i] = Res(i);
113}
114
115Approx_CurvilinearParameter::Approx_CurvilinearParameter(const Handle(Adaptor3d_HCurve)& C3D,
116 const Standard_Real Tol,
117 const GeomAbs_Shape Order,
118 const Standard_Integer MaxDegree,
119 const Standard_Integer MaxSegments)
120{
121#ifdef DEB
122 t_total = t_init = t_approx = t_uparam = 0;
123 uparam_count = 0;
124 InitChron(chr_total);
125#endif
126 myCase = 1;
127// Initialisation of input parameters of AdvApprox
128
129 Standard_Integer Num1DSS=0, Num2DSS=0, Num3DSS=1;
130 Handle(TColStd_HArray1OfReal) OneDTolNul, TwoDTolNul;
131 Handle(TColStd_HArray1OfReal) ThreeDTol = new TColStd_HArray1OfReal(1,Num3DSS);
132 ThreeDTol->Init(Tol);
133
134#ifdef DEB
135 InitChron(chr_init);
136#endif
137 Handle(Approx_CurvlinFunc) fonct = new Approx_CurvlinFunc(C3D, Tol/10);
138#ifdef DEB
139 ResultChron(chr_init, t_init);
140#endif
141
142 Standard_Real FirstS = fonct->FirstParameter();
143 Standard_Real LastS = fonct->LastParameter();
144
145 Standard_Integer NbInterv_C2 = fonct->NbIntervals(GeomAbs_C2);
146 TColStd_Array1OfReal CutPnts_C2(1, NbInterv_C2+1);
147 fonct->Intervals(CutPnts_C2,GeomAbs_C2);
148 Standard_Integer NbInterv_C3 = fonct->NbIntervals(GeomAbs_C3);
149 TColStd_Array1OfReal CutPnts_C3(1, NbInterv_C3+1);
150 fonct->Intervals(CutPnts_C3,GeomAbs_C3);
151 AdvApprox_PrefAndRec CutTool(CutPnts_C2,CutPnts_C3);
152
153#ifdef DEB
154 InitChron(chr_approx);
155#endif
156
157 Approx_CurvilinearParameter_EvalCurv evC (fonct, FirstS, LastS);
158 AdvApprox_ApproxAFunction aApprox (Num1DSS, Num2DSS, Num3DSS,
159 OneDTolNul, TwoDTolNul, ThreeDTol,
160 FirstS, LastS, Order,
161 MaxDegree, MaxSegments,
162 evC, CutTool);
163
164#ifdef DEB
165 ResultChron(chr_approx, t_approx);
166#endif
167
168 myDone = aApprox.IsDone();
169 myHasResult = aApprox.HasResult();
170
171 if (myHasResult) {
172 TColgp_Array1OfPnt Poles(1,aApprox.NbPoles());
173 aApprox.Poles(1,Poles);
174 Handle(TColStd_HArray1OfReal) Knots = aApprox.Knots();
175 Handle(TColStd_HArray1OfInteger) Mults = aApprox.Multiplicities();
176 Standard_Integer Degree = aApprox.Degree();
177 myCurve3d = new Geom_BSplineCurve(Poles, Knots->Array1(), Mults->Array1(), Degree);
178 }
179 myMaxError3d = aApprox.MaxError(3,1);
180
181#ifdef DEB
182 ResultChron(chr_total, t_total);
183
184 cout<<" total reparametrization time = "<<t_total<<endl;
185 cout<<"initialization time = "<<t_init<<endl;
186 cout<<"approximation time = "<<t_approx<<endl;
187 cout<<"total time for uparam computation = "<<t_uparam<<endl;
188 cout<<"number uparam calles = "<<uparam_count<<endl;
189#endif
190}
191
192//=======================================================================
193//class : Approx_CurvilinearParameter_EvalCurvOnSurf
194//purpose : case of a curve on one surface
195//=======================================================================
196
197class Approx_CurvilinearParameter_EvalCurvOnSurf : public AdvApprox_EvaluatorFunction
198{
199 public:
200 Approx_CurvilinearParameter_EvalCurvOnSurf (const Handle(Approx_CurvlinFunc)& theFunc,
201 Standard_Real First, Standard_Real Last)
202 : fonct(theFunc) { StartEndSav[0] = First; StartEndSav[1] = Last; }
203
204 virtual void Evaluate (Standard_Integer *Dimension,
205 Standard_Real StartEnd[2],
206 Standard_Real *Parameter,
207 Standard_Integer *DerivativeRequest,
208 Standard_Real *Result, // [Dimension]
209 Standard_Integer *ErrorCode);
210
211 private:
212 Handle(Approx_CurvlinFunc) fonct;
213 Standard_Real StartEndSav[2];
214};
215
216void Approx_CurvilinearParameter_EvalCurvOnSurf::Evaluate (Standard_Integer * Dimension,
217 Standard_Real * StartEnd,
218 Standard_Real * Param,
219 Standard_Integer * Order,
220 Standard_Real * Result,
221 Standard_Integer * ErrorCode)
222{
223 *ErrorCode = 0;
224 Standard_Real S = *Param;
225 TColStd_Array1OfReal Res(0, 4);
226 Standard_Integer i;
227
228// Dimension is incorrect
229 if (*Dimension != 5) {
230 *ErrorCode = 1;
231 }
232// Parameter is incorrect
233 if ( S < StartEnd[0] || S > StartEnd[1] ) {
234 *ErrorCode = 2;
235 }
236
237 if(StartEnd[0] != StartEndSav[0] || StartEnd[1]!= StartEndSav[1])
238 {
239 fonct->Trim(StartEnd[0],StartEnd[1], Precision::Confusion());
240 StartEndSav[0]=StartEnd[0];
241 StartEndSav[1]=StartEnd[1];
242 }
243
244 if(!fonct->EvalCase2(S, *Order, Res)) {
245 *ErrorCode = 3;
246 }
247
248 for(i = 0; i <= 4; i++)
249 Result[i] = Res(i);
250}
251
252Approx_CurvilinearParameter::Approx_CurvilinearParameter(const Handle(Adaptor2d_HCurve2d)& C2D,
253 const Handle(Adaptor3d_HSurface)& Surf,
254 const Standard_Real Tol,
255 const GeomAbs_Shape Order,
256 const Standard_Integer MaxDegree,
257 const Standard_Integer MaxSegments)
258{
259#ifdef DEB
260 t_total = t_init = t_approx = t_uparam = 0;
261 uparam_count = 0;
262 InitChron(chr_total);
263#endif
264 myCase = 2;
265
266 // Initialisation of input parameters of AdvApprox
267
268 Standard_Integer Num1DSS=2, Num2DSS=0, Num3DSS=1, i;
269
270 Handle(TColStd_HArray1OfReal) OneDTol = new TColStd_HArray1OfReal(1,Num1DSS);
271 Standard_Real TolV,TolW;
272
273 ToleranceComputation(C2D,Surf,10,Tol,TolV,TolW);
274 OneDTol->SetValue(1,TolV);
275 OneDTol->SetValue(2,TolW);
276
277 OneDTol->SetValue(1,Tol);
278 OneDTol->SetValue(2,Tol);
279
280 Handle(TColStd_HArray1OfReal) TwoDTolNul;
281 Handle(TColStd_HArray1OfReal) ThreeDTol = new TColStd_HArray1OfReal(1,Num3DSS);
282 ThreeDTol->Init(Tol/2.);
283
284#ifdef DEB
285 InitChron(chr_init);
286#endif
287 Handle(Approx_CurvlinFunc) fonct = new Approx_CurvlinFunc(C2D, Surf, Tol/20);
288#ifdef DEB
289 ResultChron(chr_init, t_init);
290#endif
291
292 Standard_Real FirstS = fonct->FirstParameter();
293 Standard_Real LastS = fonct->LastParameter();
294
295 Standard_Integer NbInterv_C2 = fonct->NbIntervals(GeomAbs_C2);
296 TColStd_Array1OfReal CutPnts_C2(1, NbInterv_C2+1);
297 fonct->Intervals(CutPnts_C2,GeomAbs_C2);
298 Standard_Integer NbInterv_C3 = fonct->NbIntervals(GeomAbs_C3);
299 TColStd_Array1OfReal CutPnts_C3(1, NbInterv_C3+1);
300 fonct->Intervals(CutPnts_C3,GeomAbs_C3);
301 AdvApprox_PrefAndRec CutTool(CutPnts_C2,CutPnts_C3);
302
303#ifdef DEB
304 InitChron(chr_approx);
305#endif
306
307 Approx_CurvilinearParameter_EvalCurvOnSurf evCOnS (fonct, FirstS, LastS);
308 AdvApprox_ApproxAFunction aApprox (Num1DSS, Num2DSS, Num3DSS,
309 OneDTol, TwoDTolNul, ThreeDTol,
310 FirstS, LastS, Order,
311 MaxDegree, MaxSegments,
312 evCOnS, CutTool);
313
314#ifdef DEB
315 ResultChron(chr_approx, t_approx);
316#endif
317
318 myDone = aApprox.IsDone();
319 myHasResult = aApprox.HasResult();
320
321 if (myHasResult) {
322 Standard_Integer NbPoles = aApprox.NbPoles();
323 TColgp_Array1OfPnt Poles (1,NbPoles);
324 TColgp_Array1OfPnt2d Poles2d(1,NbPoles);
325 TColStd_Array1OfReal Poles1d(1,NbPoles);
326 aApprox.Poles(1,Poles);
327 aApprox.Poles1d(1,Poles1d);
328 for (i=1; i<=NbPoles; i++)
329 Poles2d(i).SetX(Poles1d(i));
330 aApprox.Poles1d(2,Poles1d);
331 for (i=1; i<=NbPoles; i++)
332 Poles2d(i).SetY(Poles1d(i));
333 Handle(TColStd_HArray1OfReal) Knots = aApprox.Knots();
334 Handle(TColStd_HArray1OfInteger) Mults = aApprox.Multiplicities();
335 Standard_Integer Degree = aApprox.Degree();
336 myCurve3d = new Geom_BSplineCurve(Poles, Knots->Array1(), Mults->Array1(), Degree);
337 myCurve2d1 = new Geom2d_BSplineCurve(Poles2d, Knots->Array1(), Mults->Array1(), Degree);
338 }
339 myMaxError2d1 = Max (aApprox.MaxError(1,1),aApprox.MaxError(1,2));
340 myMaxError3d = aApprox.MaxError(3,1);
341
342#ifdef DEB
343 ResultChron(chr_total, t_total);
344
345 cout<<" total reparametrization time = "<<t_total<<endl;
346 cout<<"initialization time = "<<t_init<<endl;
347 cout<<"approximation time = "<<t_approx<<endl;
348 cout<<"total time for uparam computation = "<<t_uparam<<endl;
349 cout<<"number uparam calles = "<<uparam_count<<endl;
350#endif
351}
352
353//=======================================================================
354//function : Approx_CurvilinearParameter_EvalCurvOn2Surf
355//purpose : case of a curve on two surfaces
356//=======================================================================
357
358class Approx_CurvilinearParameter_EvalCurvOn2Surf : public AdvApprox_EvaluatorFunction
359{
360 public:
361 Approx_CurvilinearParameter_EvalCurvOn2Surf (const Handle(Approx_CurvlinFunc)& theFunc,
362 Standard_Real First, Standard_Real Last)
363 : fonct(theFunc) { StartEndSav[0] = First; StartEndSav[1] = Last; }
364
365 virtual void Evaluate (Standard_Integer *Dimension,
366 Standard_Real StartEnd[2],
367 Standard_Real *Parameter,
368 Standard_Integer *DerivativeRequest,
369 Standard_Real *Result, // [Dimension]
370 Standard_Integer *ErrorCode);
371
372 private:
373 Handle(Approx_CurvlinFunc) fonct;
374 Standard_Real StartEndSav[2];
375};
376
377void Approx_CurvilinearParameter_EvalCurvOn2Surf::Evaluate (Standard_Integer * Dimension,
378 Standard_Real * StartEnd,
379 Standard_Real * Param,
380 Standard_Integer * Order,
381 Standard_Real * Result,
382 Standard_Integer * ErrorCode)
383{
384 *ErrorCode = 0;
385 Standard_Real S = *Param;
386 TColStd_Array1OfReal Res(0, 6);
387 Standard_Integer i;
388
389// Dimension is incorrect
390 if (*Dimension != 7) {
391 *ErrorCode = 1;
392 }
393// Parameter is incorrect
394 if ( S < StartEnd[0] || S > StartEnd[1] ) {
395 *ErrorCode = 2;
396 }
397
398/* if(StartEnd[0] != StartEndSav[0] || StartEnd[1]!= StartEndSav[1])
399 {
400 fonct->Trim(StartEnd[0],StartEnd[1], Precision::Confusion());
401 StartEndSav[0]=StartEnd[0];
402 StartEndSav[1]=StartEnd[1];
403 }
404*/
405 if(!fonct->EvalCase3(S, *Order, Res)) {
406 *ErrorCode = 3;
407 }
408
409 for(i = 0; i <= 6; i++)
410 Result[i] = Res(i);
411}
412
413Approx_CurvilinearParameter::Approx_CurvilinearParameter(const Handle(Adaptor2d_HCurve2d)& C2D1,
414 const Handle(Adaptor3d_HSurface)& Surf1,
415 const Handle(Adaptor2d_HCurve2d)& C2D2,
416 const Handle(Adaptor3d_HSurface)& Surf2,
417 const Standard_Real Tol,
418 const GeomAbs_Shape Order,
419 const Standard_Integer MaxDegree,
420 const Standard_Integer MaxSegments)
421{
422 Standard_Integer i;
423
424#ifdef DEB
425 t_total = t_init = t_approx = t_uparam = 0;
426 uparam_count = 0;
427 InitChron(chr_total);
428#endif
429 myCase = 3;
430
431 // Initialisation of input parameters of AdvApprox
432
433 Standard_Integer Num1DSS=4, Num2DSS=0, Num3DSS=1;
434 Handle(TColStd_HArray1OfReal) OneDTol = new TColStd_HArray1OfReal(1,Num1DSS);
435
436 Standard_Real TolV,TolW;
437 ToleranceComputation(C2D1,Surf1,10,Tol,TolV,TolW);
438 OneDTol->SetValue(1,TolV);
439 OneDTol->SetValue(2,TolW);
440
441 ToleranceComputation(C2D2,Surf2,10,Tol,TolV,TolW);
442 OneDTol->SetValue(3,TolV);
443 OneDTol->SetValue(4,TolW);
444
445 Handle(TColStd_HArray1OfReal) TwoDTolNul;
446 Handle(TColStd_HArray1OfReal) ThreeDTol = new TColStd_HArray1OfReal(1,Num3DSS);
447 ThreeDTol->Init(Tol/2);
448
449#ifdef DEB
450 InitChron(chr_init);
451#endif
452 Handle(Approx_CurvlinFunc) fonct = new Approx_CurvlinFunc(C2D1, C2D2, Surf1, Surf2, Tol/20);
453#ifdef DEB
454 ResultChron(chr_init, t_init);
455#endif
456
457 Standard_Real FirstS = fonct->FirstParameter();
458 Standard_Real LastS = fonct->LastParameter();
459
460 Standard_Integer NbInterv_C2 = fonct->NbIntervals(GeomAbs_C2);
461 TColStd_Array1OfReal CutPnts_C2(1, NbInterv_C2+1);
462 fonct->Intervals(CutPnts_C2,GeomAbs_C2);
463 Standard_Integer NbInterv_C3 = fonct->NbIntervals(GeomAbs_C3);
464 TColStd_Array1OfReal CutPnts_C3(1, NbInterv_C3+1);
465 fonct->Intervals(CutPnts_C3,GeomAbs_C3);
466 AdvApprox_PrefAndRec CutTool(CutPnts_C2,CutPnts_C3);
467
468#ifdef DEB
469 InitChron(chr_approx);
470#endif
471
472 Approx_CurvilinearParameter_EvalCurvOn2Surf evCOn2S (fonct, FirstS, LastS);
473 AdvApprox_ApproxAFunction aApprox (Num1DSS, Num2DSS, Num3DSS,
474 OneDTol, TwoDTolNul, ThreeDTol,
475 FirstS, LastS, Order,
476 MaxDegree, MaxSegments,
477 evCOn2S, CutTool);
478
479#ifdef DEB
480 ResultChron(chr_approx, t_approx);
481#endif
482
483 myDone = aApprox.IsDone();
484 myHasResult = aApprox.HasResult();
485
486 if (myHasResult) {
487 Standard_Integer NbPoles = aApprox.NbPoles();
488 TColgp_Array1OfPnt Poles (1,NbPoles);
489 TColgp_Array1OfPnt2d Poles2d(1,NbPoles);
490 TColStd_Array1OfReal Poles1d(1,NbPoles);
491 aApprox.Poles(1,Poles);
492 aApprox.Poles1d(1,Poles1d);
493 for (i=1; i<=NbPoles; i++)
494 Poles2d(i).SetX(Poles1d(i));
495 aApprox.Poles1d(2,Poles1d);
496 for (i=1; i<=NbPoles; i++)
497 Poles2d(i).SetY(Poles1d(i));
498 Handle(TColStd_HArray1OfReal) Knots = aApprox.Knots();
499 Handle(TColStd_HArray1OfInteger) Mults = aApprox.Multiplicities();
500 Standard_Integer Degree = aApprox.Degree();
501 myCurve3d = new Geom_BSplineCurve(Poles, Knots->Array1(), Mults->Array1(), Degree);
502 myCurve2d1 = new Geom2d_BSplineCurve(Poles2d, Knots->Array1(), Mults->Array1(), Degree);
503 aApprox.Poles1d(3,Poles1d);
504 for (i=1; i<=NbPoles; i++)
505 Poles2d(i).SetX(Poles1d(i));
506 aApprox.Poles1d(4,Poles1d);
507 for (i=1; i<=NbPoles; i++)
508 Poles2d(i).SetY(Poles1d(i));
509 myCurve2d2 = new Geom2d_BSplineCurve(Poles2d, Knots->Array1(), Mults->Array1(), Degree);
510 }
511 myMaxError2d1 = Max (aApprox.MaxError(1,1),aApprox.MaxError(1,2));
512 myMaxError2d2 = Max (aApprox.MaxError(1,3),aApprox.MaxError(1,4));
513 myMaxError3d = aApprox.MaxError(3,1);
514
515#ifdef DEB
516 ResultChron(chr_total, t_total);
517
518 cout<<" total reparametrization time = "<<t_total<<endl;
519 cout<<"initialization time = "<<t_init<<endl;
520 cout<<"approximation time = "<<t_approx<<endl;
521 cout<<"total time for uparam computation = "<<t_uparam<<endl;
522 cout<<"number uparam calles = "<<uparam_count<<endl;
523#endif
524}
525
526//=======================================================================
527//function : IsDone
528//purpose :
529//=======================================================================
530
531 Standard_Boolean Approx_CurvilinearParameter::IsDone() const
532{
533 return myDone;
534}
535
536//=======================================================================
537//function : HasResult
538//purpose :
539//=======================================================================
540
541 Standard_Boolean Approx_CurvilinearParameter::HasResult() const
542{
543 return myHasResult;
544}
545
546//=======================================================================
547//function : Curve3d
548//purpose : returns the Bspline curve corresponding to the reparametrized 3D curve
549//=======================================================================
550
551 Handle(Geom_BSplineCurve) Approx_CurvilinearParameter::Curve3d() const
552{
553 return myCurve3d;
554}
555
556//=======================================================================
557//function : MaxError3d
558//purpose : returns the maximum error on the reparametrized 3D curve
559//=======================================================================
560
561 Standard_Real Approx_CurvilinearParameter::MaxError3d() const
562{
563 return myMaxError3d;
564}
565
566//=======================================================================
567//function : Curve2d1
568//purpose : returns the BsplineCurve representing the reparametrized 2D curve on the
569// first surface (case of a curve on one or two surfaces)
570//=======================================================================
571
572 Handle(Geom2d_BSplineCurve) Approx_CurvilinearParameter::Curve2d1() const
573{
574 return myCurve2d1;
575}
576
577//=======================================================================
578//function : MaxError2d1
579//purpose : returns the maximum error on the first reparametrized 2D curve
580//=======================================================================
581
582 Standard_Real Approx_CurvilinearParameter::MaxError2d1() const
583{
584 return myMaxError2d1;
585}
586
587//=======================================================================
588//function : Curve2d2
589//purpose : returns the BsplineCurve representing the reparametrized 2D curve on the
590// second surface (case of a curve on two surfaces)
591//=======================================================================
592
593 Handle(Geom2d_BSplineCurve) Approx_CurvilinearParameter::Curve2d2() const
594{
595 return myCurve2d2;
596}
597
598//=======================================================================
599//function : MaxError2d2
600//purpose : returns the maximum error on the second reparametrized 2D curve
601//=======================================================================
602
603 Standard_Real Approx_CurvilinearParameter::MaxError2d2() const
604{
605 return myMaxError2d2;
606}
607
608//=======================================================================
609//function : Dump
610//purpose : print the maximum errors(s)
611//=======================================================================
612
613void Approx_CurvilinearParameter::Dump(Standard_OStream& o) const
614{
615 o << "Dump of Approx_CurvilinearParameter" << endl;
616 if (myCase==2 || myCase==3)
617 o << "myMaxError2d1 = " << myMaxError2d1 << endl;
618 if (myCase==3)
619 o << "myMaxError2d2 = " << myMaxError2d2 << endl;
620 o << "myMaxError3d = " << myMaxError3d << endl;
621}
622
623//=======================================================================
624//function : ToleranceComputation
625//purpose :
626//=======================================================================
627
628void Approx_CurvilinearParameter::ToleranceComputation(const Handle(Adaptor2d_HCurve2d) &C2D,
629 const Handle(Adaptor3d_HSurface) &S,
630 const Standard_Integer MaxNumber,
631 const Standard_Real Tol,
632 Standard_Real &TolV, Standard_Real &TolW)
633{
634 Standard_Real FirstU = C2D->FirstParameter(),
635 LastU = C2D->LastParameter();
636// Standard_Real parU, Max_dS_dv=1.,Max_dS_dw=1.;
637 Standard_Real Max_dS_dv=1.,Max_dS_dw=1.;
638 gp_Pnt P;
639 gp_Pnt2d pntVW;
640 gp_Vec dS_dv,dS_dw;
641
642 for (Standard_Integer i=1; i<=MaxNumber; i++) {
643 pntVW = C2D->Value(FirstU + (i-1)*(LastU-FirstU)/(MaxNumber-1));
644 S->D1(pntVW.X(),pntVW.Y(),P,dS_dv,dS_dw);
645 Max_dS_dv = Max (Max_dS_dv, dS_dv.Magnitude());
646 Max_dS_dw = Max (Max_dS_dw, dS_dw.Magnitude());
647 }
648 TolV = Tol / (4.*Max_dS_dv);
649 TolW = Tol / (4.*Max_dS_dw);
650
651#ifdef DEB
652 cout << "TolV = " << TolV << endl;
653 cout << "TolW = " << TolW << endl;
654#endif
655}