0024059: Eliminate compiler warning C4701 in MSVC++ with warning level 4
[occt.git] / src / Extrema / Extrema_GenExtSS.cxx
CommitLineData
b311480e 1// Created on: 1995-07-18
2// Created by: Modelistation
3// Copyright (c) 1995-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22#include <Extrema_GenExtSS.ixx>
23#include <math_Vector.hxx>
24#include <math_FunctionSetRoot.hxx>
25
26//=======================================================================
27//function : Extrema_GenExtSS
28//purpose :
29//=======================================================================
30
b311480e 31Extrema_GenExtSS::Extrema_GenExtSS()
7fd59977 32{
33 myDone = Standard_False;
34 myInit = Standard_False;
35}
36
37//=======================================================================
38//function : Extrema_GenExtSS
39//purpose :
40//=======================================================================
41
42Extrema_GenExtSS::Extrema_GenExtSS(const Adaptor3d_Surface& S1,
43 const Adaptor3d_Surface& S2,
44 const Standard_Integer NbU,
45 const Standard_Integer NbV,
46 const Standard_Real Tol1,
47 const Standard_Real Tol2) : myF(S1,S2)
48{
49 Initialize(S2, NbU, NbV, Tol2);
50 Perform(S1, Tol1);
51}
52
53//=======================================================================
54//function : Extrema_GenExtSS
55//purpose :
56//=======================================================================
57
58Extrema_GenExtSS::Extrema_GenExtSS(const Adaptor3d_Surface& S1,
59 const Adaptor3d_Surface& S2,
60 const Standard_Integer NbU,
61 const Standard_Integer NbV,
62 const Standard_Real U1min,
63 const Standard_Real U1sup,
64 const Standard_Real V1min,
65 const Standard_Real V1sup,
66 const Standard_Real U2min,
67 const Standard_Real U2sup,
68 const Standard_Real V2min,
69 const Standard_Real V2sup,
70 const Standard_Real Tol1,
71 const Standard_Real Tol2): myF(S1, S2)
72{
73 Initialize(S2, NbU, NbV, U2min,U2sup,V2min,V2sup,Tol2);
74 Perform(S1, U1min,U1sup,V1min,V1sup,Tol1);
75}
76
77//=======================================================================
78//function : Initialize
79//purpose :
80//=======================================================================
81
82void Extrema_GenExtSS::Initialize(const Adaptor3d_Surface& S2,
83 const Standard_Integer NbU,
84 const Standard_Integer NbV,
85 const Standard_Real Tol2)
86{
87 myu2min = S2.FirstUParameter();
88 myu2sup = S2.LastUParameter();
89 myv2min = S2.FirstVParameter();
90 myv2sup = S2.LastVParameter();
91 Initialize(S2,NbU,NbV,myu2min,myu2sup,myv2min,myv2sup,Tol2);
92}
93
94//=======================================================================
95//function : Initialize
96//purpose :
97//=======================================================================
98
99void Extrema_GenExtSS::Initialize(const Adaptor3d_Surface& S2,
100 const Standard_Integer NbU,
101 const Standard_Integer NbV,
102 const Standard_Real U2min,
103 const Standard_Real U2sup,
104 const Standard_Real V2min,
105 const Standard_Real V2sup,
106 const Standard_Real Tol2)
107{
108 myS2 = (Adaptor3d_SurfacePtr)&S2;
109 mypoints1 = new TColgp_HArray2OfPnt(0,NbU+1,0,NbV+1);
110 mypoints2 = new TColgp_HArray2OfPnt(0,NbU+1,0,NbV+1);
111 myusample = NbU;
112 myvsample = NbV;
113 myu2min = U2min;
114 myu2sup = U2sup;
115 myv2min = V2min;
116 myv2sup = V2sup;
117 mytol2 = Tol2;
118
119// Parametrage de l echantillon sur S2
120
121 Standard_Real PasU = myu2sup - myu2min;
122 Standard_Real PasV = myv2sup - myv2min;
123 Standard_Real U0 = PasU / myusample / 100.;
124 Standard_Real V0 = PasV / myvsample / 100.;
125 gp_Pnt P1;
126 PasU = (PasU - U0) / (myusample - 1);
127 PasV = (PasV - V0) / (myvsample - 1);
128 U0 = myu2min + U0/2.;
129 V0 = myv2min + V0/2.;
130
131// Calcul des distances
132
133 Standard_Integer NoU, NoV;
134 Standard_Real U, V;
135 for ( NoU = 1, U = U0; NoU <= myusample; NoU++, U += PasU) {
136 for ( NoV = 1, V = V0; NoV <= myvsample; NoV++, V += PasV) {
137 P1 = myS2->Value(U, V);
138 mypoints2->SetValue(NoU,NoV,P1);
139 }
140 }
141}
142
143//=======================================================================
144//function : Perform
145//purpose :
146//=======================================================================
147
148void Extrema_GenExtSS::Perform(const Adaptor3d_Surface& S1,
149 const Standard_Real Tol1)
150{
151 myu1min = S1.FirstUParameter();
152 myu1sup = S1.LastUParameter();
153 myv1min = S1.FirstVParameter();
154 myv1sup = S1.LastVParameter();
155 Perform(S1, myu1min, myu1sup,myv1min,myv1sup,Tol1);
156}
157
158//=======================================================================
159//function : Perform
160//purpose :
161//=======================================================================
162
163void Extrema_GenExtSS::Perform(const Adaptor3d_Surface& S1,
164 const Standard_Real U1min,
165 const Standard_Real U1sup,
166 const Standard_Real V1min,
167 const Standard_Real V1sup,
168 const Standard_Real Tol1)
169{
170 myF.Initialize(S1,*myS2);
171 myu1min = U1min;
172 myu1sup = U1sup;
173 myv1min = V1min;
174 myv1sup = V1sup;
175 mytol1 = Tol1;
176
177 Standard_Real U1, V1, U2, V2;
178 Standard_Integer NoU1, NoV1, NoU2, NoV2;
179 gp_Pnt P1, P2;
180
181// Parametrage de l echantillon sur S1
182
183 Standard_Real PasU1 = myu1sup - myu1min;
184 Standard_Real PasV1 = myv1sup - myv1min;
185 Standard_Real U10 = PasU1 / myusample / 100.;
186 Standard_Real V10 = PasV1 / myvsample / 100.;
187 PasU1 = (PasU1 - U10) / (myusample - 1);
188 PasV1 = (PasV1 - V10) / (myvsample - 1);
189 U10 = myu1min + U10/2.;
190 V10 = myv1min + V10/2.;
191
192 Standard_Real PasU2 = myu2sup - myu2min;
193 Standard_Real PasV2 = myv2sup - myv2min;
194 Standard_Real U20 = PasU2 / myusample / 100.;
195 Standard_Real V20 = PasV2 / myvsample / 100.;
196 PasU2 = (PasU2 - U20) / (myusample - 1);
197 PasV2 = (PasV2 - V20) / (myvsample - 1);
198 U20 = myu2min + U20/2.;
199 V20 = myv2min + V20/2.;
200
201// Calcul des distances
202
203 for ( NoU1 = 1, U1 = U10; NoU1 <= myusample; NoU1++, U1 += PasU1) {
204 for ( NoV1 = 1, V1 = V10; NoV1 <= myvsample; NoV1++, V1 += PasV1) {
205 P1 = S1.Value(U1, V1);
206 mypoints1->SetValue(NoU1,NoV1,P1);
207 }
208 }
209
210/*
211b- Calcul des minima:
212 -----------------
213 b.a) Initialisations:
214*/
215
216 math_Vector Tol(1, 4);
217 Tol(1) = mytol1;
218 Tol(2) = mytol1;
219 Tol(3) = mytol2;
220 Tol(4) = mytol2;
221 math_Vector UV(1,4), UVinf(1,4), UVsup(1,4);
222 UVinf(1) = myu1min;
223 UVinf(2) = myv1min;
224 UVinf(3) = myu2min;
225 UVinf(4) = myv2min;
226 UVsup(1) = myu1sup;
227 UVsup(2) = myv1sup;
228 UVsup(3) = myu2sup;
229 UVsup(4) = myv2sup;
230
231
232 Standard_Real distmin = RealLast(), distmax = 0.0, TheDist;
233
234 Standard_Integer N1Umin=0,N1Vmin=0,N2Umin=0,N2Vmin=0;
235 gp_Pnt PP1min, PP2min;
236 Standard_Integer N1Umax=0,N1Vmax=0,N2Umax=0,N2Vmax=0;
237 gp_Pnt PP1max, PP2max;
238
239 for ( NoU1 = 1, U1 = U10; NoU1 <= myusample; NoU1++, U1 += PasU1) {
240 for ( NoV1 = 1, V1 = V10; NoV1 <= myvsample; NoV1++, V1 += PasV1) {
241 P1 = mypoints1->Value(NoU1, NoV1);
242 for ( NoU2 = 1, U2 = U20; NoU2 <= myusample; NoU2++, U2 += PasU2) {
243 for ( NoV2 = 1, V2 = V20; NoV2 <= myvsample; NoV2++, V2 += PasV2) {
244 P2 = mypoints2->Value(NoU2, NoV2);
245 TheDist = P1.SquareDistance(P2);
246 if (TheDist < distmin) {
247 distmin = TheDist;
248 N1Umin = NoU1;
249 N1Vmin = NoV1;
250 N2Umin = NoU2;
251 N2Vmin = NoV2;
252 PP1min = P1;
253 PP2min = P2;
254 }
255 if (TheDist > distmax) {
256 distmax = TheDist;
257 N1Umax = NoU1;
258 N1Vmax = NoV1;
259 N2Umax = NoU2;
260 N2Vmax = NoV2;
261 PP1max = P1;
262 PP2max = P2;
263 }
264 }
265 }
266 }
267 }
268
269 UV(1) = U10 + (N1Umin - 1) * PasU1;
270 UV(2) = V10 + (N1Vmin - 1) * PasV1;
271 UV(3) = U20 + (N2Umin - 1) * PasU2;
272 UV(4) = V20 + (N2Vmin - 1) * PasV2;
273
274 math_FunctionSetRoot SR1 (myF,UV,Tol,UVinf,UVsup);
275
276 UV(1) = U10 + (N1Umax - 1) * PasU1;
277 UV(2) = V10 + (N1Vmax - 1) * PasV1;
278 UV(3) = U20 + (N2Umax - 1) * PasU2;
279 UV(4) = V20 + (N2Vmax - 1) * PasV2;
280
281 math_FunctionSetRoot SR2 (myF,UV,Tol,UVinf,UVsup);
282
283 myDone = Standard_True;
284}
285
286//=======================================================================
287//function : IsDone
288//purpose :
289//=======================================================================
290
291Standard_Boolean Extrema_GenExtSS::IsDone() const
292{
293 return myDone;
294}
295
296//=======================================================================
297//function : NbExt
298//purpose :
299//=======================================================================
300
301Standard_Integer Extrema_GenExtSS::NbExt() const
302{
303 if (!IsDone()) { StdFail_NotDone::Raise(); }
304 return myF.NbExt();
305
306}
307
308//=======================================================================
309//function : Value
310//purpose :
311//=======================================================================
312
313Standard_Real Extrema_GenExtSS::SquareDistance(const Standard_Integer N) const
314{
315 if (!IsDone()) { StdFail_NotDone::Raise(); }
316 return myF.SquareDistance(N);
317}
318
319//=======================================================================
320//function : PointOnS1
321//purpose :
322//=======================================================================
323
324Extrema_POnSurf Extrema_GenExtSS::PointOnS1(const Standard_Integer N) const
325{
326 if (!IsDone()) { StdFail_NotDone::Raise(); }
327 return myF.PointOnS1(N);
328}
329
330//=======================================================================
331//function : PointOnS2
332//purpose :
333//=======================================================================
334
335Extrema_POnSurf Extrema_GenExtSS::PointOnS2(const Standard_Integer N) const
336{
337 if (!IsDone()) { StdFail_NotDone::Raise(); }
338 return myF.PointOnS2(N);
339}
340
341//=======================================================================
342//function : Bidon
343//purpose :
344//=======================================================================
345
346Adaptor3d_SurfacePtr Extrema_GenExtSS::Bidon() const
347{
348 return (Adaptor3d_SurfacePtr)0L;
349}
350