0022922: Clean up warnings on uninitialized / unused variables
[occt.git] / src / IntCurveSurface / IntCurveSurface_Polygon.gxx
CommitLineData
7fd59977 1// File: IntCurveSurface_Polygon.gxx
2// Created: Mon Oct 12 17:17:30 1992
3// Author: Laurent BUCHARD
4// <lbr@sdsun2>
5
6
7
8#include <Standard_ConstructionError.hxx>
9#include <Bnd_Box.hxx>
10#include <TColgp_Array1OfPnt.hxx>
11#include <gp_Lin.hxx>
12#include <gp_Vec.hxx>
13#include <gp_Dir.hxx>
14
15
16//======================================================================
17//== On echantillonne sur le Domain de la Curve NbPts Points
18//== a parametres constants.
19//==
20//== On estime la fleche maximum en prenant la distance maxi entre la
21//== droite Curve.Value(X(i))-->Curve.Value(X(i+1))
22//== et le point Curve.Value(X(i+1/2))
23//======================================================================
24IntCurveSurface_Polygon::IntCurveSurface_Polygon(const TheCurve& C,
25 const Standard_Integer tNbPts):
26 ThePnts(1,(tNbPts<5)? 5 : tNbPts)
27{
28 Standard_Integer NbPts = (tNbPts<5)? 5 : tNbPts;
29 NbPntIn = NbPts;
30 Binf = TheCurveTool::FirstParameter(C);
31 Bsup = TheCurveTool::LastParameter(C);
32 Init(C);
33}
34
35
36
37IntCurveSurface_Polygon::IntCurveSurface_Polygon(const TheCurve& C,
38 const Standard_Real U1,
39 const Standard_Real U2,
40 const Standard_Integer tNbPts):
41 ThePnts(1,(tNbPts<5)? 5 : tNbPts) , Binf(U1) , Bsup(U2)
42{
43
44
45 Standard_Integer NbPts = (tNbPts<5)? 5 : tNbPts;
46 NbPntIn = NbPts;
47 Init(C);
48}
49
50//=======================================================================
51//function : IntCurveSurface_Polygon
52//purpose :
53//=======================================================================
54
55IntCurveSurface_Polygon::IntCurveSurface_Polygon(const TheCurve& C,
56 const TColStd_Array1OfReal& Upars):
57 ThePnts(1,Upars.Length()) , Binf(Upars(Upars.Lower())) , Bsup(Upars(Upars.Upper()))
58{
59
60 //ddout << "IntCurveSurface_Polygon::IntCurveSurface_Polygon" << endl;
61 Standard_Integer NbPts = Upars.Length();
62 //ddout << "NbPts :" << NbPts << endl;
63 NbPntIn = NbPts;
64 Init(C, Upars);
65}
66
67
68void IntCurveSurface_Polygon::Init(const TheCurve& C) {
69
70 Standard_Real u=Binf;
71 Standard_Real u1=Bsup;
72 Standard_Real du=(u1-u)/(Standard_Real)(NbPntIn-1);
73 Standard_Integer i=1;
74 gp_Pnt P;
75 do {
76 TheCurveTool::D0(C,u,P);
77 TheBnd.Add(P);
78 ThePnts.SetValue(i,P);
79 u+=du;
80 i++;
81 }
82 while(i<=NbPntIn);
83
84
85 //-----------------------------------------------------
86 //--- Calcul d un majorant de fleche approche
87 //---
88 TheDeflection = 0.0;
89
90 if(NbPntIn>3) {
91
92 i=1;
93 u=Binf;
94 u+=du * 0.5;
95
96 do {
97 gp_Pnt Pm=TheCurveTool::Value(C,u);
98 gp_Pnt P1=ThePnts.Value(i);
99 gp_Pnt P2=ThePnts.Value(i+1);
100 gp_Lin L(P1,gp_Dir(gp_Vec(P1,P2)));
101 Standard_Real t=L.Distance(Pm);
102
103 if(t>TheDeflection) {
104 TheDeflection = t;
105 }
106 u+=du;
107 i++;
108 }
109 while(i<NbPntIn);
110
111 TheBnd.Enlarge(1.5*TheDeflection);
112 }
113 else {
114 TheBnd.Enlarge(1e-10);
115 }
116 ClosedPolygon = Standard_False;
117}
118
119//=======================================================================
120//function : Init
121//purpose :
122//=======================================================================
123
124void IntCurveSurface_Polygon::Init(const TheCurve& C,
125 const TColStd_Array1OfReal& Upars) {
126
127 //ddout << "IntCurveSurface_Polygon::Init" << endl;
128 Standard_Real u=Binf;
7fd59977 129 Standard_Integer i=1, i0 = Upars.Lower()-1;
130 gp_Pnt P;
131
132 myParams = new TColStd_HArray1OfReal(1, Upars.Length());
133 do {
134 //ddout << "-------------Parameter : " << i << " " << Upars(i+i0) << endl;
135 myParams->SetValue(i, Upars(i+i0));
136 TheCurveTool::D0(C,Upars(i+i0),P);
137 //ddout << "P : " << P.X() << " " << P.Y() << " " << P.Z() << endl;
138 TheBnd.Add(P);
139 ThePnts.SetValue(i,P);
140 i++;
141 }
142 while(i<=NbPntIn);
143
144
145 //-----------------------------------------------------
146 //--- Calcul d un majorant de fleche approche
147 //---
148 TheDeflection = 0.0;
149
150 if(NbPntIn>3) {
151
152 i=1;
153 //ddout << "Deflection estimation" << endl;
154 do {
155 u = 0.5*(Upars(i0+i)+Upars(i0+i+1));
156 //ddout << "===========Parameter : " << i << " " << u << endl;
157 gp_Pnt Pm=TheCurveTool::Value(C,u);
158 //ddout << "Pm : " << Pm.X() << " " << Pm.Y() << " " << Pm.Z() << endl;
159 gp_Pnt P1=ThePnts.Value(i);
160 //ddout << "P1 : " << P1.X() << " " << P1.Y() << " " << P1.Z() << endl;
161 gp_Pnt P2=ThePnts.Value(i+1);
162 //ddout << "P2 : " << P2.X() << " " << P2.Y() << " " << P2.Z() << endl;
163 gp_Lin L(P1,gp_Dir(gp_Vec(P1,P2)));
164 Standard_Real t=L.Distance(Pm);
165 //ddout << "Distance " << t << endl;
166 if(t>TheDeflection) {
167 TheDeflection = t;
168 }
169 i++;
170 }
171 while(i<NbPntIn);
172 //ddout << " TheDeflection = " << TheDeflection << endl;
173 TheBnd.Enlarge(1.5*TheDeflection);
174 }
175 else {
176 TheBnd.Enlarge(1e-10);
177 }
178 ClosedPolygon = Standard_False;
179}
180
181
182//======================================================================
183Standard_Real IntCurveSurface_Polygon::ApproxParamOnCurve(const Standard_Integer TheIndex,
184 const Standard_Real TheParamOnLine) const
185{
186 //ddout << "IntCurveSurface_Polygon::ApproxParamOnCurve" << endl;
187 if(TheParamOnLine < 0.0 || TheParamOnLine >1.0) {
188 cout<<" ParamOnLine = "<<TheParamOnLine<<" avec Index = "
189 <<TheIndex<<" dans IntCurveSurface_Polygon::ApproxParamOnCurve"<<endl;
190 return(Binf+(TheParamOnLine*(Bsup-Binf))/(Standard_Real)(NbPntIn-1));
191 }
192
193 Standard_Integer Index = TheIndex;
194 Standard_Real ParamOnLine = TheParamOnLine;
195 if (Index > NbPntIn) {
196 cout << "OutOfRange Polygon::ApproxParamOnCurve " <<endl;
197 }
198 if((Index == NbPntIn) && (ParamOnLine == 0.0)) {
199 Index--; ParamOnLine=1.0;
200 }
201
202 Standard_Real du, u;
203 if (myParams.IsNull())
204 {
205 du = (Bsup-Binf)/(Standard_Real)(NbPntIn-1);
206 u = Binf + du * (Standard_Real)(Index-1);
207 }
208 else
209 {
210 du = myParams->Value(Index+1) - myParams->Value(Index);
211 u = myParams->Value(Index);
212 }
213
214 u += du * ParamOnLine;
215 return (u);
216}
217
218
219//======================================================================
220void IntCurveSurface_Polygon::Dump(void) const {
221#if 0
222 static Standard_Integer Compteur=0;
223 char tamp[100];
224 Compteur++;
225 sprintf(tamp,"Poly%d",Compteur);
226 cout<<" @@@@@@@@@@@ F i c h i e r : "<<tamp<<" @@@@@@@@@@"<<endl;
227 FILE *fp;
228 fp=fopen(tamp,"w");
229 if(fp==NULL) {
230 cout<<"PolyGonGen::Erreur en Ouverture Fichier"<<tamp<<endl;
231 return;
232 }
233 fprintf(fp,"\n#Discretisation de : %f ---> %f \n",Binf,Bsup);
234 fprintf(fp,"\npol %d %d %f",Compteur,NbPntIn,TheDeflection);
235 gp_Pnt p1,p2;
236 for (Standard_Integer iObje=1; iObje<=NbSegments(); iObje++) {
237 p1=BeginOfSeg(iObje);
238 fprintf(fp,"\npnt %d %f %f",Compteur,p1.X(),p1.Y());
239 }
240 p1=EndOfSeg(NbSegments());
241 fprintf(fp,"\npnt %d %f %f",Compteur,p1.X(),p1.Y());
242 fprintf(fp,"\ndispol %d\n#\n",Compteur);
243 fclose(fp);
244#endif
245}
246//======================================================================
247//======================================================================