0029915: Porting to VC 2017 : Regressions in Modeling Algorithms on VC 2017
[occt.git] / src / GCPnts / GCPnts_QuasiUniformAbscissa.pxx
CommitLineData
b311480e 1// Created on: 1996-08-22
2// Created by: Stagiaire Mary FABIEN
3// Copyright (c) 1996-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17//=======================================================================
18//function : GCPnts_QuasiUniformAbscissa
19//purpose :
20//=======================================================================
21
37782ec2 22GCPnts_QuasiUniformAbscissa::GCPnts_QuasiUniformAbscissa(const TheCurve& C,
7fd59977 23 const Standard_Integer NbPoints)
24{
25 Initialize(C, NbPoints);
26}
27
28//=======================================================================
29//function : GCPnts_QuasiUniformAbscissa
30//purpose :
31//=======================================================================
32
37782ec2 33GCPnts_QuasiUniformAbscissa::GCPnts_QuasiUniformAbscissa(const TheCurve& C,
7fd59977 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
37782ec2 46void GCPnts_QuasiUniformAbscissa::Initialize(const TheCurve& C,
7fd59977 47 const Standard_Integer NbPoints)
48{
49 Initialize(C, NbPoints, C.FirstParameter(),
50 C.LastParameter());
51}
52
53
54//=======================================================================
55//function : Initialize
f379643f 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.
7fd59977 59//=======================================================================
37782ec2 60void GCPnts_QuasiUniformAbscissa::Initialize(const TheCurve& C,
7fd59977 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));
0797d9d3 74#ifdef OCCT_DEBUG
7fd59977 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 }
2d2b3d53 83 else
84 {
85 Standard_ConstructionError_Raise_if (NbPoints <= 1,
86 "GCPnts_QuasiUniformAbscissa::Initialize() - number of points should be >= 2");
7fd59977 87
88// evaluate the approximative length of the 3dCurve
89 myNbPoints = NbPoints;
90 Standard_Real Length = 0.;
91 Standard_Real Dist, dU = (U2 - U1) / ( 2*NbPoints - 1);
92
93 TColgp_Array1OfPnt2d LP(1,2*NbPoints); // tableau Longueur <-> Param
94 ThePnt P1, P2;
95 P1 = C.Value(U1);
96
97// On additionne toutes les distances
98 for ( i = 0; i < 2*NbPoints ; i++) {
99 P2 = C.Value(U1 + i*dU);
100 Dist = P1.Distance(P2);
101 Length += Dist;
102 LP(i+1) = gp_Pnt2d( Length, U1 + (i*dU));
103 P1 = P2;
104 }
105
106// On cherche a mettre NbPoints dans la curve.
107// on met les points environ a Length/NbPoints.
108
f379643f 109 if(IsEqual(Length, 0.0))
110 {//use usual analytical grid
111 Standard_Real aStep = (U2 - U1) / (NbPoints - 1);
112 myParams = new TColStd_HArray1OfReal(1,NbPoints);
113 myParams->SetValue(1,U1);
114 for ( i = 2; i < NbPoints; i++)
115 {
116 myParams->SetValue(i, U1 + aStep*(i-1));
117 }
7fd59977 118 }
f379643f 119 else
120 {
121 Standard_Real DCorde = Length / ( NbPoints - 1);
122 Standard_Real Corde = DCorde;
123 Standard_Integer Index = 1;
124 Standard_Real U, Alpha;
125 myParams = new TColStd_HArray1OfReal(1,NbPoints);
126 myParams->SetValue(1,U1);
127 for ( i = 2; i < NbPoints; i++)
128 {
129 while ( LP(Index).X() < Corde) Index ++;
130 Alpha = (Corde - LP(Index-1).X()) / (LP(Index).X() - LP(Index-1).X());
131 U = LP(Index-1).Y() + Alpha * ( LP(Index).Y() - LP(Index-1).Y());
132 myParams->SetValue(i,U);
133 Corde = i*DCorde;
134 }
135 }
136
7fd59977 137 myParams->SetValue(NbPoints,U2);
138 myDone = Standard_True;
139 }
140}
141