0024553: Deleting obsolete/unused ".gxx" files from "GCPnts"
[occt.git] / src / GCPnts / GCPnts_QuasiUniformAbscissa.pxx
1 // Created on: 1996-08-22
2 // Created by: Stagiaire Mary FABIEN
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 //=======================================================================
18 //function : GCPnts_QuasiUniformAbscissa
19 //purpose  : 
20 //=======================================================================
21
22 GCPnts_QuasiUniformAbscissa::GCPnts_QuasiUniformAbscissa(const TheCurve& C,
23                                                const Standard_Integer NbPoints)
24 {
25   Initialize(C, NbPoints);
26 }
27
28 //=======================================================================
29 //function : GCPnts_QuasiUniformAbscissa
30 //purpose  : 
31 //=======================================================================
32
33 GCPnts_QuasiUniformAbscissa::GCPnts_QuasiUniformAbscissa(const TheCurve& C,
34                                                const Standard_Integer NbPoints,
35                                                const Standard_Real U1, 
36                                                const Standard_Real U2)
37 {
38   Initialize(C, NbPoints, U1, U2);
39 }
40
41 //=======================================================================
42 //function : Initialize
43 //purpose  : 
44 //=======================================================================
45
46 void GCPnts_QuasiUniformAbscissa::Initialize(const TheCurve& C,
47                                         const Standard_Integer NbPoints)
48 {
49   Initialize(C, NbPoints, C.FirstParameter(),
50              C.LastParameter());
51
52
53
54 //=======================================================================
55 //function : Initialize
56 //purpose  : This function divides given curve on the several parts with
57 //            equal length. It returns array of parameters in the
58 //            control points.
59 //=======================================================================
60 void GCPnts_QuasiUniformAbscissa::Initialize(const TheCurve& C,
61                                              const Standard_Integer NbPoints,
62                                              const Standard_Real U1, 
63                                              const Standard_Real U2)
64 {
65   Standard_Integer i;
66   if ((C.GetType() != GeomAbs_BezierCurve) && (C.GetType() != GeomAbs_BSplineCurve))
67     {
68       GCPnts_UniformAbscissa UA(C,NbPoints,U1,U2);
69       myDone = UA.IsDone();
70       myNbPoints = UA.NbPoints();
71       myParams = new TColStd_HArray1OfReal(1,myNbPoints);
72       for( i = 1 ; i <= myNbPoints ; i++ ) 
73         myParams->SetValue(i,UA.Parameter(i));
74 #ifdef OCCT_DEBUG
75
76 //      char name [100];
77 //      for( i = 1 ; i <= NbPoints ; i++ ) {
78 //      sprintf(name,"%s_%d","pnt2d",i+(compteur++));
79 //      DrawTrSurf::Set(name,C->Value(UA.Parameter(i)));
80 //      }
81 #endif
82     }
83   else {
84     Standard_ConstructionError_Raise_if(NbPoints <= 1, "");
85     
86 // evaluate the approximative length of the 3dCurve
87     myNbPoints = NbPoints;
88     Standard_Real Length = 0.;
89     Standard_Real Dist, dU = (U2 - U1) / ( 2*NbPoints - 1);
90     
91     TColgp_Array1OfPnt2d LP(1,2*NbPoints); // tableau Longueur <-> Param
92     ThePnt P1, P2;
93     P1 = C.Value(U1);
94     
95 // On additionne toutes les distances
96     for ( i = 0; i < 2*NbPoints ; i++) {
97       P2      = C.Value(U1 + i*dU);
98       Dist    = P1.Distance(P2);
99       Length += Dist;
100       LP(i+1) = gp_Pnt2d( Length, U1 + (i*dU));
101       P1      = P2;
102     }
103
104 // On cherche a mettre NbPoints dans la curve.
105 // on met les points environ a Length/NbPoints.
106
107     if(IsEqual(Length, 0.0))
108     {//use usual analytical grid
109       Standard_Real aStep = (U2 - U1) / (NbPoints - 1);
110       myParams = new TColStd_HArray1OfReal(1,NbPoints); 
111       myParams->SetValue(1,U1);
112       for ( i = 2; i < NbPoints; i++)
113       {
114         myParams->SetValue(i, U1 + aStep*(i-1));
115       }
116     }
117     else
118     {
119       Standard_Real DCorde = Length / ( NbPoints - 1); 
120       Standard_Real Corde  = DCorde;
121       Standard_Integer Index = 1;
122       Standard_Real U, Alpha;
123       myParams = new TColStd_HArray1OfReal(1,NbPoints); 
124       myParams->SetValue(1,U1); 
125       for ( i = 2; i < NbPoints; i++)
126       {
127         while ( LP(Index).X() < Corde) Index ++;
128         Alpha = (Corde - LP(Index-1).X()) / (LP(Index).X() - LP(Index-1).X());
129         U = LP(Index-1).Y() + Alpha * ( LP(Index).Y() - LP(Index-1).Y());
130         myParams->SetValue(i,U);
131         Corde = i*DCorde;
132       }
133     }
134
135     myParams->SetValue(NbPoints,U2);
136     myDone = Standard_True;
137   }
138 }
139