summaryrefslogtreecommitdiff
path: root/src/Extrema/Extrema_GenExtSS.cxx
blob: 16dc26e3fc750695945683ad1f1a878c138c184c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
// File:	Extrema_GenExtSS.cxx
// Created:	Tue Jul 18 08:21:34 1995
// Author:	Modelistation
//		<model@metrox>

#include <Extrema_GenExtSS.ixx>
#include <math_Vector.hxx>
#include <math_FunctionSetRoot.hxx>

//=======================================================================
//function : Extrema_GenExtSS
//purpose  : 
//=======================================================================

 Extrema_GenExtSS::Extrema_GenExtSS()
{
  myDone = Standard_False;
  myInit = Standard_False;
}

//=======================================================================
//function : Extrema_GenExtSS
//purpose  : 
//=======================================================================

Extrema_GenExtSS::Extrema_GenExtSS(const Adaptor3d_Surface& S1, 
				   const Adaptor3d_Surface& S2, 
				   const Standard_Integer NbU, 
				   const Standard_Integer NbV, 
				   const Standard_Real    Tol1, 
				   const Standard_Real    Tol2) : myF(S1,S2)
{
  Initialize(S2, NbU, NbV, Tol2);
  Perform(S1, Tol1);
}

//=======================================================================
//function : Extrema_GenExtSS
//purpose  : 
//=======================================================================

Extrema_GenExtSS::Extrema_GenExtSS(const Adaptor3d_Surface& S1, 
				   const Adaptor3d_Surface& S2, 
				   const Standard_Integer NbU, 
				   const Standard_Integer NbV, 
				   const Standard_Real U1min, 
				   const Standard_Real U1sup, 
				   const Standard_Real V1min, 
				   const Standard_Real V1sup, 
				   const Standard_Real U2min, 
				   const Standard_Real U2sup, 
				   const Standard_Real V2min, 
				   const Standard_Real V2sup, 
				   const Standard_Real Tol1, 
				   const Standard_Real Tol2): myF(S1, S2)
{
  Initialize(S2, NbU, NbV, U2min,U2sup,V2min,V2sup,Tol2);
  Perform(S1, U1min,U1sup,V1min,V1sup,Tol1);
}

//=======================================================================
//function : Initialize
//purpose  : 
//=======================================================================

void Extrema_GenExtSS::Initialize(const Adaptor3d_Surface& S2, 
				  const Standard_Integer NbU, 
				  const Standard_Integer NbV, 
				  const Standard_Real Tol2)
{
  myu2min = S2.FirstUParameter();
  myu2sup = S2.LastUParameter();
  myv2min = S2.FirstVParameter();
  myv2sup = S2.LastVParameter();
  Initialize(S2,NbU,NbV,myu2min,myu2sup,myv2min,myv2sup,Tol2);
}

//=======================================================================
//function : Initialize
//purpose  : 
//=======================================================================

void Extrema_GenExtSS::Initialize(const Adaptor3d_Surface& S2, 
				  const Standard_Integer NbU, 
				  const Standard_Integer NbV, 
				  const Standard_Real U2min, 
				  const Standard_Real U2sup, 
				  const Standard_Real V2min, 
				  const Standard_Real V2sup, 
				  const Standard_Real Tol2)
{
  myS2 = (Adaptor3d_SurfacePtr)&S2;
  mypoints1 = new TColgp_HArray2OfPnt(0,NbU+1,0,NbV+1);
  mypoints2 = new TColgp_HArray2OfPnt(0,NbU+1,0,NbV+1);
  myusample = NbU;
  myvsample = NbV;
  myu2min = U2min;
  myu2sup = U2sup;
  myv2min = V2min;
  myv2sup = V2sup;
  mytol2 = Tol2;

// Parametrage de l echantillon sur S2

  Standard_Real PasU = myu2sup - myu2min;
  Standard_Real PasV = myv2sup - myv2min;
  Standard_Real U0 = PasU / myusample / 100.;
  Standard_Real V0 = PasV / myvsample / 100.;
  gp_Pnt P1;
  PasU = (PasU - U0) / (myusample - 1);
  PasV = (PasV - V0) / (myvsample - 1);
  U0 = myu2min + U0/2.;
  V0 = myv2min + V0/2.;

// Calcul des distances

  Standard_Integer NoU, NoV;
  Standard_Real U, V;
  for ( NoU = 1, U = U0; NoU <= myusample; NoU++, U += PasU) {
    for ( NoV = 1, V = V0; NoV <= myvsample; NoV++, V += PasV) {
      P1 = myS2->Value(U, V);
      mypoints2->SetValue(NoU,NoV,P1);
    }
  }
}

//=======================================================================
//function : Perform
//purpose  : 
//=======================================================================

void Extrema_GenExtSS::Perform(const Adaptor3d_Surface& S1,
			       const Standard_Real    Tol1)
{
  myu1min = S1.FirstUParameter();
  myu1sup = S1.LastUParameter();
  myv1min = S1.FirstVParameter();
  myv1sup = S1.LastVParameter();
  Perform(S1, myu1min, myu1sup,myv1min,myv1sup,Tol1);
}

//=======================================================================
//function : Perform
//purpose  : 
//=======================================================================

void Extrema_GenExtSS::Perform(const Adaptor3d_Surface& S1,
			       const Standard_Real U1min, 
			       const Standard_Real U1sup, 
			       const Standard_Real V1min, 
			       const Standard_Real V1sup, 
			       const Standard_Real Tol1)
{
  myF.Initialize(S1,*myS2);
  myu1min = U1min;
  myu1sup = U1sup;
  myv1min = V1min;
  myv1sup = V1sup;
  mytol1 = Tol1;

  Standard_Real U1, V1, U2, V2;
  Standard_Integer NoU1, NoV1, NoU2, NoV2;
  gp_Pnt P1, P2;

// Parametrage de l echantillon sur S1

  Standard_Real PasU1 = myu1sup - myu1min;
  Standard_Real PasV1 = myv1sup - myv1min;
  Standard_Real U10 = PasU1 / myusample / 100.;
  Standard_Real V10 = PasV1 / myvsample / 100.;
  PasU1 = (PasU1 - U10) / (myusample - 1);
  PasV1 = (PasV1 - V10) / (myvsample - 1);
  U10 = myu1min + U10/2.;
  V10 = myv1min + V10/2.;

  Standard_Real PasU2 = myu2sup - myu2min;
  Standard_Real PasV2 = myv2sup - myv2min;
  Standard_Real U20 = PasU2 / myusample / 100.;
  Standard_Real V20 = PasV2 / myvsample / 100.;
  PasU2 = (PasU2 - U20) / (myusample - 1);
  PasV2 = (PasV2 - V20) / (myvsample - 1);
  U20 = myu2min + U20/2.;
  V20 = myv2min + V20/2.;

// Calcul des distances

  for ( NoU1 = 1, U1 = U10; NoU1 <= myusample; NoU1++, U1 += PasU1) {
    for ( NoV1 = 1, V1 = V10; NoV1 <= myvsample; NoV1++, V1 += PasV1) {
      P1 = S1.Value(U1, V1);
      mypoints1->SetValue(NoU1,NoV1,P1);
    }
  }
  
/*
b- Calcul des minima:
   -----------------
   b.a) Initialisations:
*/

  math_Vector Tol(1, 4);
  Tol(1) = mytol1;
  Tol(2) = mytol1;
  Tol(3) = mytol2;
  Tol(4) = mytol2;
  math_Vector UV(1,4), UVinf(1,4), UVsup(1,4);
  UVinf(1) = myu1min;
  UVinf(2) = myv1min;
  UVinf(3) = myu2min;
  UVinf(4) = myv2min;
  UVsup(1) = myu1sup;
  UVsup(2) = myv1sup;
  UVsup(3) = myu2sup;
  UVsup(4) = myv2sup;
  

  Standard_Real distmin = RealLast(), distmax = 0.0, TheDist;

  Standard_Integer N1Umin=0,N1Vmin=0,N2Umin=0,N2Vmin=0;
  gp_Pnt PP1min, PP2min;
  Standard_Integer N1Umax=0,N1Vmax=0,N2Umax=0,N2Vmax=0;
  gp_Pnt PP1max, PP2max;

  for ( NoU1 = 1, U1 = U10; NoU1 <= myusample; NoU1++, U1 += PasU1) {
    for ( NoV1 = 1, V1 = V10; NoV1 <= myvsample; NoV1++, V1 += PasV1) {
      P1 = mypoints1->Value(NoU1, NoV1);
      for ( NoU2 = 1, U2 = U20; NoU2 <= myusample; NoU2++, U2 += PasU2) {
	for ( NoV2 = 1, V2 = V20; NoV2 <= myvsample; NoV2++, V2 += PasV2) {
	  P2 = mypoints2->Value(NoU2, NoV2);
	  TheDist = P1.SquareDistance(P2);
	  if (TheDist < distmin) {
	    distmin = TheDist;
	    N1Umin = NoU1;
	    N1Vmin = NoV1;
	    N2Umin = NoU2;
	    N2Vmin = NoV2;
	    PP1min = P1;
	    PP2min = P2;
	  }
	  if (TheDist > distmax) {
	    distmax = TheDist;
	    N1Umax = NoU1;
	    N1Vmax = NoV1;
	    N2Umax = NoU2;
	    N2Vmax = NoV2;
	    PP1max = P1;
	    PP2max = P2;
	  }
	}
      }
    }
  }
  
  UV(1) = U10 + (N1Umin - 1) * PasU1;
  UV(2) = V10 + (N1Vmin - 1) * PasV1;
  UV(3) = U20 + (N2Umin - 1) * PasU2;
  UV(4) = V20 + (N2Vmin - 1) * PasV2;

  math_FunctionSetRoot SR1 (myF,UV,Tol,UVinf,UVsup);

  UV(1) = U10 + (N1Umax - 1) * PasU1;
  UV(2) = V10 + (N1Vmax - 1) * PasV1;
  UV(3) = U20 + (N2Umax - 1) * PasU2;
  UV(4) = V20 + (N2Vmax - 1) * PasV2;

  math_FunctionSetRoot SR2 (myF,UV,Tol,UVinf,UVsup);

  myDone = Standard_True;
}

//=======================================================================
//function : IsDone
//purpose  : 
//=======================================================================

Standard_Boolean Extrema_GenExtSS::IsDone() const 
{
  return myDone;
}

//=======================================================================
//function : NbExt
//purpose  : 
//=======================================================================

Standard_Integer Extrema_GenExtSS::NbExt() const 
{
  if (!IsDone()) { StdFail_NotDone::Raise(); }
  return myF.NbExt();

}

//=======================================================================
//function : Value
//purpose  : 
//=======================================================================

Standard_Real Extrema_GenExtSS::SquareDistance(const Standard_Integer N) const 
{  
  if (!IsDone()) { StdFail_NotDone::Raise(); }
  return myF.SquareDistance(N);
}

//=======================================================================
//function : PointOnS1
//purpose  : 
//=======================================================================

Extrema_POnSurf Extrema_GenExtSS::PointOnS1(const Standard_Integer N) const 
{
  if (!IsDone()) { StdFail_NotDone::Raise(); }
  return myF.PointOnS1(N);
}

//=======================================================================
//function : PointOnS2
//purpose  : 
//=======================================================================

Extrema_POnSurf Extrema_GenExtSS::PointOnS2(const Standard_Integer N) const 
{
  if (!IsDone()) { StdFail_NotDone::Raise(); }
  return myF.PointOnS2(N);
}

//=======================================================================
//function : Bidon
//purpose  : 
//=======================================================================

Adaptor3d_SurfacePtr Extrema_GenExtSS::Bidon() const 
{
  return (Adaptor3d_SurfacePtr)0L;
}