0025292: Face/Face intersection algorithm gives different results for different order...
[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
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#include <Extrema_GenExtSS.ixx>
18#include <math_Vector.hxx>
19#include <math_FunctionSetRoot.hxx>
20
21//=======================================================================
22//function : Extrema_GenExtSS
23//purpose :
24//=======================================================================
25
b311480e 26Extrema_GenExtSS::Extrema_GenExtSS()
7fd59977 27{
28 myDone = Standard_False;
29 myInit = Standard_False;
30}
31
32//=======================================================================
33//function : Extrema_GenExtSS
34//purpose :
35//=======================================================================
36
37Extrema_GenExtSS::Extrema_GenExtSS(const Adaptor3d_Surface& S1,
38 const Adaptor3d_Surface& S2,
39 const Standard_Integer NbU,
40 const Standard_Integer NbV,
41 const Standard_Real Tol1,
42 const Standard_Real Tol2) : myF(S1,S2)
43{
44 Initialize(S2, NbU, NbV, Tol2);
45 Perform(S1, Tol1);
46}
47
48//=======================================================================
49//function : Extrema_GenExtSS
50//purpose :
51//=======================================================================
52
53Extrema_GenExtSS::Extrema_GenExtSS(const Adaptor3d_Surface& S1,
54 const Adaptor3d_Surface& S2,
55 const Standard_Integer NbU,
56 const Standard_Integer NbV,
57 const Standard_Real U1min,
58 const Standard_Real U1sup,
59 const Standard_Real V1min,
60 const Standard_Real V1sup,
61 const Standard_Real U2min,
62 const Standard_Real U2sup,
63 const Standard_Real V2min,
64 const Standard_Real V2sup,
65 const Standard_Real Tol1,
66 const Standard_Real Tol2): myF(S1, S2)
67{
68 Initialize(S2, NbU, NbV, U2min,U2sup,V2min,V2sup,Tol2);
69 Perform(S1, U1min,U1sup,V1min,V1sup,Tol1);
70}
71
72//=======================================================================
73//function : Initialize
74//purpose :
75//=======================================================================
76
77void Extrema_GenExtSS::Initialize(const Adaptor3d_Surface& S2,
78 const Standard_Integer NbU,
79 const Standard_Integer NbV,
80 const Standard_Real Tol2)
81{
82 myu2min = S2.FirstUParameter();
83 myu2sup = S2.LastUParameter();
84 myv2min = S2.FirstVParameter();
85 myv2sup = S2.LastVParameter();
86 Initialize(S2,NbU,NbV,myu2min,myu2sup,myv2min,myv2sup,Tol2);
87}
88
89//=======================================================================
90//function : Initialize
91//purpose :
92//=======================================================================
93
94void Extrema_GenExtSS::Initialize(const Adaptor3d_Surface& S2,
95 const Standard_Integer NbU,
96 const Standard_Integer NbV,
97 const Standard_Real U2min,
98 const Standard_Real U2sup,
99 const Standard_Real V2min,
100 const Standard_Real V2sup,
101 const Standard_Real Tol2)
102{
103 myS2 = (Adaptor3d_SurfacePtr)&S2;
104 mypoints1 = new TColgp_HArray2OfPnt(0,NbU+1,0,NbV+1);
105 mypoints2 = new TColgp_HArray2OfPnt(0,NbU+1,0,NbV+1);
106 myusample = NbU;
107 myvsample = NbV;
108 myu2min = U2min;
109 myu2sup = U2sup;
110 myv2min = V2min;
111 myv2sup = V2sup;
112 mytol2 = Tol2;
113
114// Parametrage de l echantillon sur S2
115
116 Standard_Real PasU = myu2sup - myu2min;
117 Standard_Real PasV = myv2sup - myv2min;
118 Standard_Real U0 = PasU / myusample / 100.;
119 Standard_Real V0 = PasV / myvsample / 100.;
120 gp_Pnt P1;
121 PasU = (PasU - U0) / (myusample - 1);
122 PasV = (PasV - V0) / (myvsample - 1);
123 U0 = myu2min + U0/2.;
124 V0 = myv2min + V0/2.;
125
126// Calcul des distances
127
128 Standard_Integer NoU, NoV;
129 Standard_Real U, V;
130 for ( NoU = 1, U = U0; NoU <= myusample; NoU++, U += PasU) {
131 for ( NoV = 1, V = V0; NoV <= myvsample; NoV++, V += PasV) {
132 P1 = myS2->Value(U, V);
133 mypoints2->SetValue(NoU,NoV,P1);
134 }
135 }
136}
137
138//=======================================================================
139//function : Perform
140//purpose :
141//=======================================================================
142
143void Extrema_GenExtSS::Perform(const Adaptor3d_Surface& S1,
144 const Standard_Real Tol1)
145{
146 myu1min = S1.FirstUParameter();
147 myu1sup = S1.LastUParameter();
148 myv1min = S1.FirstVParameter();
149 myv1sup = S1.LastVParameter();
150 Perform(S1, myu1min, myu1sup,myv1min,myv1sup,Tol1);
151}
152
153//=======================================================================
154//function : Perform
155//purpose :
156//=======================================================================
157
158void Extrema_GenExtSS::Perform(const Adaptor3d_Surface& S1,
159 const Standard_Real U1min,
160 const Standard_Real U1sup,
161 const Standard_Real V1min,
162 const Standard_Real V1sup,
163 const Standard_Real Tol1)
164{
165 myF.Initialize(S1,*myS2);
166 myu1min = U1min;
167 myu1sup = U1sup;
168 myv1min = V1min;
169 myv1sup = V1sup;
170 mytol1 = Tol1;
171
172 Standard_Real U1, V1, U2, V2;
173 Standard_Integer NoU1, NoV1, NoU2, NoV2;
174 gp_Pnt P1, P2;
175
176// Parametrage de l echantillon sur S1
177
178 Standard_Real PasU1 = myu1sup - myu1min;
179 Standard_Real PasV1 = myv1sup - myv1min;
180 Standard_Real U10 = PasU1 / myusample / 100.;
181 Standard_Real V10 = PasV1 / myvsample / 100.;
182 PasU1 = (PasU1 - U10) / (myusample - 1);
183 PasV1 = (PasV1 - V10) / (myvsample - 1);
184 U10 = myu1min + U10/2.;
185 V10 = myv1min + V10/2.;
186
187 Standard_Real PasU2 = myu2sup - myu2min;
188 Standard_Real PasV2 = myv2sup - myv2min;
189 Standard_Real U20 = PasU2 / myusample / 100.;
190 Standard_Real V20 = PasV2 / myvsample / 100.;
191 PasU2 = (PasU2 - U20) / (myusample - 1);
192 PasV2 = (PasV2 - V20) / (myvsample - 1);
193 U20 = myu2min + U20/2.;
194 V20 = myv2min + V20/2.;
195
196// Calcul des distances
197
198 for ( NoU1 = 1, U1 = U10; NoU1 <= myusample; NoU1++, U1 += PasU1) {
199 for ( NoV1 = 1, V1 = V10; NoV1 <= myvsample; NoV1++, V1 += PasV1) {
200 P1 = S1.Value(U1, V1);
201 mypoints1->SetValue(NoU1,NoV1,P1);
202 }
203 }
204
205/*
206b- Calcul des minima:
207 -----------------
208 b.a) Initialisations:
209*/
210
211 math_Vector Tol(1, 4);
212 Tol(1) = mytol1;
213 Tol(2) = mytol1;
214 Tol(3) = mytol2;
215 Tol(4) = mytol2;
216 math_Vector UV(1,4), UVinf(1,4), UVsup(1,4);
217 UVinf(1) = myu1min;
218 UVinf(2) = myv1min;
219 UVinf(3) = myu2min;
220 UVinf(4) = myv2min;
221 UVsup(1) = myu1sup;
222 UVsup(2) = myv1sup;
223 UVsup(3) = myu2sup;
224 UVsup(4) = myv2sup;
225
226
227 Standard_Real distmin = RealLast(), distmax = 0.0, TheDist;
228
229 Standard_Integer N1Umin=0,N1Vmin=0,N2Umin=0,N2Vmin=0;
230 gp_Pnt PP1min, PP2min;
231 Standard_Integer N1Umax=0,N1Vmax=0,N2Umax=0,N2Vmax=0;
232 gp_Pnt PP1max, PP2max;
233
234 for ( NoU1 = 1, U1 = U10; NoU1 <= myusample; NoU1++, U1 += PasU1) {
235 for ( NoV1 = 1, V1 = V10; NoV1 <= myvsample; NoV1++, V1 += PasV1) {
236 P1 = mypoints1->Value(NoU1, NoV1);
237 for ( NoU2 = 1, U2 = U20; NoU2 <= myusample; NoU2++, U2 += PasU2) {
238 for ( NoV2 = 1, V2 = V20; NoV2 <= myvsample; NoV2++, V2 += PasV2) {
239 P2 = mypoints2->Value(NoU2, NoV2);
240 TheDist = P1.SquareDistance(P2);
241 if (TheDist < distmin) {
242 distmin = TheDist;
243 N1Umin = NoU1;
244 N1Vmin = NoV1;
245 N2Umin = NoU2;
246 N2Vmin = NoV2;
247 PP1min = P1;
248 PP2min = P2;
249 }
250 if (TheDist > distmax) {
251 distmax = TheDist;
252 N1Umax = NoU1;
253 N1Vmax = NoV1;
254 N2Umax = NoU2;
255 N2Vmax = NoV2;
256 PP1max = P1;
257 PP2max = P2;
258 }
259 }
260 }
261 }
262 }
263
264 UV(1) = U10 + (N1Umin - 1) * PasU1;
265 UV(2) = V10 + (N1Vmin - 1) * PasV1;
266 UV(3) = U20 + (N2Umin - 1) * PasU2;
267 UV(4) = V20 + (N2Vmin - 1) * PasV2;
268
269 math_FunctionSetRoot SR1 (myF,UV,Tol,UVinf,UVsup);
270
271 UV(1) = U10 + (N1Umax - 1) * PasU1;
272 UV(2) = V10 + (N1Vmax - 1) * PasV1;
273 UV(3) = U20 + (N2Umax - 1) * PasU2;
274 UV(4) = V20 + (N2Vmax - 1) * PasV2;
275
276 math_FunctionSetRoot SR2 (myF,UV,Tol,UVinf,UVsup);
277
278 myDone = Standard_True;
279}
280
281//=======================================================================
282//function : IsDone
283//purpose :
284//=======================================================================
285
286Standard_Boolean Extrema_GenExtSS::IsDone() const
287{
288 return myDone;
289}
290
291//=======================================================================
292//function : NbExt
293//purpose :
294//=======================================================================
295
296Standard_Integer Extrema_GenExtSS::NbExt() const
297{
298 if (!IsDone()) { StdFail_NotDone::Raise(); }
299 return myF.NbExt();
300
301}
302
303//=======================================================================
304//function : Value
305//purpose :
306//=======================================================================
307
308Standard_Real Extrema_GenExtSS::SquareDistance(const Standard_Integer N) const
309{
310 if (!IsDone()) { StdFail_NotDone::Raise(); }
311 return myF.SquareDistance(N);
312}
313
314//=======================================================================
315//function : PointOnS1
316//purpose :
317//=======================================================================
318
5d99f2c8 319const Extrema_POnSurf& Extrema_GenExtSS::PointOnS1(const Standard_Integer N) const
7fd59977 320{
321 if (!IsDone()) { StdFail_NotDone::Raise(); }
322 return myF.PointOnS1(N);
323}
324
325//=======================================================================
326//function : PointOnS2
327//purpose :
328//=======================================================================
329
5d99f2c8 330const Extrema_POnSurf& Extrema_GenExtSS::PointOnS2(const Standard_Integer N) const
7fd59977 331{
332 if (!IsDone()) { StdFail_NotDone::Raise(); }
333 return myF.PointOnS2(N);
334}
335
336//=======================================================================
337//function : Bidon
338//purpose :
339//=======================================================================
340
341Adaptor3d_SurfacePtr Extrema_GenExtSS::Bidon() const
342{
343 return (Adaptor3d_SurfacePtr)0L;
344}
345