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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 //=======================================================================
18 //function : GCPnts_QuasiUniformAbscissa
20 //=======================================================================
22 GCPnts_QuasiUniformAbscissa::GCPnts_QuasiUniformAbscissa(const TheCurve& C,
23 const Standard_Integer NbPoints)
25 Initialize(C, NbPoints);
28 //=======================================================================
29 //function : GCPnts_QuasiUniformAbscissa
31 //=======================================================================
33 GCPnts_QuasiUniformAbscissa::GCPnts_QuasiUniformAbscissa(const TheCurve& C,
34 const Standard_Integer NbPoints,
35 const Standard_Real U1,
36 const Standard_Real U2)
38 Initialize(C, NbPoints, U1, U2);
41 //=======================================================================
42 //function : Initialize
44 //=======================================================================
46 void GCPnts_QuasiUniformAbscissa::Initialize(const TheCurve& C,
47 const Standard_Integer NbPoints)
49 Initialize(C, NbPoints, C.FirstParameter(),
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
59 //=======================================================================
60 void GCPnts_QuasiUniformAbscissa::Initialize(const TheCurve& C,
61 const Standard_Integer NbPoints,
62 const Standard_Real U1,
63 const Standard_Real U2)
66 if ((C.GetType() != GeomAbs_BezierCurve) && (C.GetType() != GeomAbs_BSplineCurve))
68 GCPnts_UniformAbscissa UA(C,NbPoints,U1,U2);
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));
77 // for( i = 1 ; i <= NbPoints ; i++ ) {
78 // sprintf(name,"%s_%d","pnt2d",i+(compteur++));
79 // DrawTrSurf::Set(name,C->Value(UA.Parameter(i)));
84 Standard_ConstructionError_Raise_if(NbPoints <= 1, "");
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);
91 TColgp_Array1OfPnt2d LP(1,2*NbPoints); // tableau Longueur <-> Param
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);
100 LP(i+1) = gp_Pnt2d( Length, U1 + (i*dU));
104 // On cherche a mettre NbPoints dans la curve.
105 // on met les points environ a Length/NbPoints.
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++)
114 myParams->SetValue(i, U1 + aStep*(i-1));
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++)
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);
135 myParams->SetValue(NbPoints,U2);
136 myDone = Standard_True;