1 // File: Extrema_GenExtSS.cxx
2 // Created: Tue Jul 18 08:21:34 1995
3 // Author: Modelistation
6 #include <Extrema_GenExtSS.ixx>
7 #include <math_Vector.hxx>
8 #include <math_FunctionSetRoot.hxx>
10 //=======================================================================
11 //function : Extrema_GenExtSS
13 //=======================================================================
15 Extrema_GenExtSS::Extrema_GenExtSS()
17 myDone = Standard_False;
18 myInit = Standard_False;
21 //=======================================================================
22 //function : Extrema_GenExtSS
24 //=======================================================================
26 Extrema_GenExtSS::Extrema_GenExtSS(const Adaptor3d_Surface& S1,
27 const Adaptor3d_Surface& S2,
28 const Standard_Integer NbU,
29 const Standard_Integer NbV,
30 const Standard_Real Tol1,
31 const Standard_Real Tol2) : myF(S1,S2)
33 Initialize(S2, NbU, NbV, Tol2);
37 //=======================================================================
38 //function : Extrema_GenExtSS
40 //=======================================================================
42 Extrema_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 U1min,
47 const Standard_Real U1sup,
48 const Standard_Real V1min,
49 const Standard_Real V1sup,
50 const Standard_Real U2min,
51 const Standard_Real U2sup,
52 const Standard_Real V2min,
53 const Standard_Real V2sup,
54 const Standard_Real Tol1,
55 const Standard_Real Tol2): myF(S1, S2)
57 Initialize(S2, NbU, NbV, U2min,U2sup,V2min,V2sup,Tol2);
58 Perform(S1, U1min,U1sup,V1min,V1sup,Tol1);
61 //=======================================================================
62 //function : Initialize
64 //=======================================================================
66 void Extrema_GenExtSS::Initialize(const Adaptor3d_Surface& S2,
67 const Standard_Integer NbU,
68 const Standard_Integer NbV,
69 const Standard_Real Tol2)
71 myu2min = S2.FirstUParameter();
72 myu2sup = S2.LastUParameter();
73 myv2min = S2.FirstVParameter();
74 myv2sup = S2.LastVParameter();
75 Initialize(S2,NbU,NbV,myu2min,myu2sup,myv2min,myv2sup,Tol2);
78 //=======================================================================
79 //function : Initialize
81 //=======================================================================
83 void Extrema_GenExtSS::Initialize(const Adaptor3d_Surface& S2,
84 const Standard_Integer NbU,
85 const Standard_Integer NbV,
86 const Standard_Real U2min,
87 const Standard_Real U2sup,
88 const Standard_Real V2min,
89 const Standard_Real V2sup,
90 const Standard_Real Tol2)
92 myS2 = (Adaptor3d_SurfacePtr)&S2;
93 mypoints1 = new TColgp_HArray2OfPnt(0,NbU+1,0,NbV+1);
94 mypoints2 = new TColgp_HArray2OfPnt(0,NbU+1,0,NbV+1);
103 // Parametrage de l echantillon sur S2
105 Standard_Real PasU = myu2sup - myu2min;
106 Standard_Real PasV = myv2sup - myv2min;
107 Standard_Real U0 = PasU / myusample / 100.;
108 Standard_Real V0 = PasV / myvsample / 100.;
110 PasU = (PasU - U0) / (myusample - 1);
111 PasV = (PasV - V0) / (myvsample - 1);
112 U0 = myu2min + U0/2.;
113 V0 = myv2min + V0/2.;
115 // Calcul des distances
117 Standard_Integer NoU, NoV;
119 for ( NoU = 1, U = U0; NoU <= myusample; NoU++, U += PasU) {
120 for ( NoV = 1, V = V0; NoV <= myvsample; NoV++, V += PasV) {
121 P1 = myS2->Value(U, V);
122 mypoints2->SetValue(NoU,NoV,P1);
127 //=======================================================================
130 //=======================================================================
132 void Extrema_GenExtSS::Perform(const Adaptor3d_Surface& S1,
133 const Standard_Real Tol1)
135 myu1min = S1.FirstUParameter();
136 myu1sup = S1.LastUParameter();
137 myv1min = S1.FirstVParameter();
138 myv1sup = S1.LastVParameter();
139 Perform(S1, myu1min, myu1sup,myv1min,myv1sup,Tol1);
142 //=======================================================================
145 //=======================================================================
147 void Extrema_GenExtSS::Perform(const Adaptor3d_Surface& S1,
148 const Standard_Real U1min,
149 const Standard_Real U1sup,
150 const Standard_Real V1min,
151 const Standard_Real V1sup,
152 const Standard_Real Tol1)
154 myF.Initialize(S1,*myS2);
161 Standard_Real U1, V1, U2, V2;
162 Standard_Integer NoU1, NoV1, NoU2, NoV2;
165 // Parametrage de l echantillon sur S1
167 Standard_Real PasU1 = myu1sup - myu1min;
168 Standard_Real PasV1 = myv1sup - myv1min;
169 Standard_Real U10 = PasU1 / myusample / 100.;
170 Standard_Real V10 = PasV1 / myvsample / 100.;
171 PasU1 = (PasU1 - U10) / (myusample - 1);
172 PasV1 = (PasV1 - V10) / (myvsample - 1);
173 U10 = myu1min + U10/2.;
174 V10 = myv1min + V10/2.;
176 Standard_Real PasU2 = myu2sup - myu2min;
177 Standard_Real PasV2 = myv2sup - myv2min;
178 Standard_Real U20 = PasU2 / myusample / 100.;
179 Standard_Real V20 = PasV2 / myvsample / 100.;
180 PasU2 = (PasU2 - U20) / (myusample - 1);
181 PasV2 = (PasV2 - V20) / (myvsample - 1);
182 U20 = myu2min + U20/2.;
183 V20 = myv2min + V20/2.;
185 // Calcul des distances
187 for ( NoU1 = 1, U1 = U10; NoU1 <= myusample; NoU1++, U1 += PasU1) {
188 for ( NoV1 = 1, V1 = V10; NoV1 <= myvsample; NoV1++, V1 += PasV1) {
189 P1 = S1.Value(U1, V1);
190 mypoints1->SetValue(NoU1,NoV1,P1);
195 b- Calcul des minima:
197 b.a) Initialisations:
200 math_Vector Tol(1, 4);
205 math_Vector UV(1,4), UVinf(1,4), UVsup(1,4);
216 Standard_Real distmin = RealLast(), distmax = 0.0, TheDist;
218 Standard_Integer N1Umin=0,N1Vmin=0,N2Umin=0,N2Vmin=0;
219 gp_Pnt PP1min, PP2min;
220 Standard_Integer N1Umax=0,N1Vmax=0,N2Umax=0,N2Vmax=0;
221 gp_Pnt PP1max, PP2max;
223 for ( NoU1 = 1, U1 = U10; NoU1 <= myusample; NoU1++, U1 += PasU1) {
224 for ( NoV1 = 1, V1 = V10; NoV1 <= myvsample; NoV1++, V1 += PasV1) {
225 P1 = mypoints1->Value(NoU1, NoV1);
226 for ( NoU2 = 1, U2 = U20; NoU2 <= myusample; NoU2++, U2 += PasU2) {
227 for ( NoV2 = 1, V2 = V20; NoV2 <= myvsample; NoV2++, V2 += PasV2) {
228 P2 = mypoints2->Value(NoU2, NoV2);
229 TheDist = P1.SquareDistance(P2);
230 if (TheDist < distmin) {
239 if (TheDist > distmax) {
253 UV(1) = U10 + (N1Umin - 1) * PasU1;
254 UV(2) = V10 + (N1Vmin - 1) * PasV1;
255 UV(3) = U20 + (N2Umin - 1) * PasU2;
256 UV(4) = V20 + (N2Vmin - 1) * PasV2;
258 math_FunctionSetRoot SR1 (myF,UV,Tol,UVinf,UVsup);
260 UV(1) = U10 + (N1Umax - 1) * PasU1;
261 UV(2) = V10 + (N1Vmax - 1) * PasV1;
262 UV(3) = U20 + (N2Umax - 1) * PasU2;
263 UV(4) = V20 + (N2Vmax - 1) * PasV2;
265 math_FunctionSetRoot SR2 (myF,UV,Tol,UVinf,UVsup);
267 myDone = Standard_True;
270 //=======================================================================
273 //=======================================================================
275 Standard_Boolean Extrema_GenExtSS::IsDone() const
280 //=======================================================================
283 //=======================================================================
285 Standard_Integer Extrema_GenExtSS::NbExt() const
287 if (!IsDone()) { StdFail_NotDone::Raise(); }
292 //=======================================================================
295 //=======================================================================
297 Standard_Real Extrema_GenExtSS::SquareDistance(const Standard_Integer N) const
299 if (!IsDone()) { StdFail_NotDone::Raise(); }
300 return myF.SquareDistance(N);
303 //=======================================================================
304 //function : PointOnS1
306 //=======================================================================
308 Extrema_POnSurf Extrema_GenExtSS::PointOnS1(const Standard_Integer N) const
310 if (!IsDone()) { StdFail_NotDone::Raise(); }
311 return myF.PointOnS1(N);
314 //=======================================================================
315 //function : PointOnS2
317 //=======================================================================
319 Extrema_POnSurf Extrema_GenExtSS::PointOnS2(const Standard_Integer N) const
321 if (!IsDone()) { StdFail_NotDone::Raise(); }
322 return myF.PointOnS2(N);
325 //=======================================================================
328 //=======================================================================
330 Adaptor3d_SurfacePtr Extrema_GenExtSS::Bidon() const
332 return (Adaptor3d_SurfacePtr)0L;