0022627: Change OCCT memory management defaults
[occt.git] / src / GCPnts / GCPnts_QuasiUniformAbscissa.gxx
CommitLineData
7fd59977 1// File: GCPnts_QuasiUniformAbscissa.gxx
2// Created: Thu Aug 22 15:58:50 1996
3// Author: Stagiaire Mary FABIEN
4// <fbi@zozox.paris1.matra-dtv.fr>
5
6
7//=======================================================================
8//function : GCPnts_QuasiUniformAbscissa
9//purpose :
10//=======================================================================
11
12GCPnts_QuasiUniformAbscissa::GCPnts_QuasiUniformAbscissa(TheCurve& C,
13 const Standard_Integer NbPoints)
14{
15 Initialize(C, NbPoints);
16}
17
18//=======================================================================
19//function : GCPnts_QuasiUniformAbscissa
20//purpose :
21//=======================================================================
22
23GCPnts_QuasiUniformAbscissa::GCPnts_QuasiUniformAbscissa(TheCurve& C,
24 const Standard_Integer NbPoints,
25 const Standard_Real U1,
26 const Standard_Real U2)
27{
28 Initialize(C, NbPoints, U1, U2);
29}
30
31//=======================================================================
32//function : Initialize
33//purpose :
34//=======================================================================
35
36void GCPnts_QuasiUniformAbscissa::Initialize(TheCurve& C,
37 const Standard_Integer NbPoints)
38{
39 Initialize(C, NbPoints, C.FirstParameter(),
40 C.LastParameter());
41}
42
43
44//=======================================================================
45//function : Initialize
46//purpose :
47//=======================================================================
48
49void GCPnts_QuasiUniformAbscissa::Initialize(TheCurve& C,
50 const Standard_Integer NbPoints,
51 const Standard_Real U1,
52 const Standard_Real U2)
53{
54 Standard_Integer i;
55 if ((C.GetType() != GeomAbs_BezierCurve) && (C.GetType() != GeomAbs_BSplineCurve))
56 {
57 GCPnts_UniformAbscissa UA(C,NbPoints,U1,U2);
58 myDone = UA.IsDone();
59 myNbPoints = UA.NbPoints();
60 myParams = new TColStd_HArray1OfReal(1,myNbPoints);
61 for( i = 1 ; i <= myNbPoints ; i++ )
62 myParams->SetValue(i,UA.Parameter(i));
63#ifdef DEB
64
65// char name [100];
66// for( i = 1 ; i <= NbPoints ; i++ ) {
67// sprintf(name,"%s_%d","pnt2d",i+(compteur++));
68// DrawTrSurf::Set(name,C->Value(UA.Parameter(i)));
69// }
70#endif
71 }
72 else {
73 Standard_ConstructionError_Raise_if(NbPoints <= 1, "");
74
75// evaluate the approximative length of the 3dCurve
76 myNbPoints = NbPoints;
77 Standard_Real Length = 0.;
78 Standard_Real Dist, dU = (U2 - U1) / ( 2*NbPoints - 1);
79
80 TColgp_Array1OfPnt2d LP(1,2*NbPoints); // tableau Longueur <-> Param
81 ThePnt P1, P2;
82 P1 = C.Value(U1);
83
84// On additionne toutes les distances
85 for ( i = 0; i < 2*NbPoints ; i++) {
86 P2 = C.Value(U1 + i*dU);
87 Dist = P1.Distance(P2);
88 Length += Dist;
89 LP(i+1) = gp_Pnt2d( Length, U1 + (i*dU));
90 P1 = P2;
91 }
92
93// On cherche a mettre NbPoints dans la curve.
94// on met les points environ a Length/NbPoints.
95
96 Standard_Real DCorde = Length / ( NbPoints - 1);
97 Standard_Real Corde = DCorde;
98 Standard_Integer Index = 1;
99 Standard_Real U, Alpha;
100 myParams = new TColStd_HArray1OfReal(1,NbPoints);
101 myParams->SetValue(1,U1);
102 for ( i = 2; i < NbPoints; i++) {
103 while ( LP(Index).X() < Corde) Index ++;
104 Alpha = (Corde - LP(Index-1).X()) / (LP(Index).X() - LP(Index-1).X());
105 U = LP(Index-1).Y() + Alpha * ( LP(Index).Y() - LP(Index-1).Y());
106 myParams->SetValue(i,U);
107 Corde = i*DCorde;
108 }
109 myParams->SetValue(NbPoints,U2);
110 myDone = Standard_True;
111 }
112}
113