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
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.
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.
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.
22 #include <Extrema_GenExtSS.ixx>
23 #include <math_Vector.hxx>
24 #include <math_FunctionSetRoot.hxx>
26 //=======================================================================
27 //function : Extrema_GenExtSS
29 //=======================================================================
31 Extrema_GenExtSS::Extrema_GenExtSS()
33 myDone = Standard_False;
34 myInit = Standard_False;
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 Tol1,
47 const Standard_Real Tol2) : myF(S1,S2)
49 Initialize(S2, NbU, NbV, Tol2);
53 //=======================================================================
54 //function : Extrema_GenExtSS
56 //=======================================================================
58 Extrema_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)
73 Initialize(S2, NbU, NbV, U2min,U2sup,V2min,V2sup,Tol2);
74 Perform(S1, U1min,U1sup,V1min,V1sup,Tol1);
77 //=======================================================================
78 //function : Initialize
80 //=======================================================================
82 void Extrema_GenExtSS::Initialize(const Adaptor3d_Surface& S2,
83 const Standard_Integer NbU,
84 const Standard_Integer NbV,
85 const Standard_Real Tol2)
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);
94 //=======================================================================
95 //function : Initialize
97 //=======================================================================
99 void 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)
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);
119 // Parametrage de l echantillon sur S2
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.;
126 PasU = (PasU - U0) / (myusample - 1);
127 PasV = (PasV - V0) / (myvsample - 1);
128 U0 = myu2min + U0/2.;
129 V0 = myv2min + V0/2.;
131 // Calcul des distances
133 Standard_Integer NoU, NoV;
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);
143 //=======================================================================
146 //=======================================================================
148 void Extrema_GenExtSS::Perform(const Adaptor3d_Surface& S1,
149 const Standard_Real Tol1)
151 myu1min = S1.FirstUParameter();
152 myu1sup = S1.LastUParameter();
153 myv1min = S1.FirstVParameter();
154 myv1sup = S1.LastVParameter();
155 Perform(S1, myu1min, myu1sup,myv1min,myv1sup,Tol1);
158 //=======================================================================
161 //=======================================================================
163 void 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)
170 myF.Initialize(S1,*myS2);
177 Standard_Real U1, V1, U2, V2;
178 Standard_Integer NoU1, NoV1, NoU2, NoV2;
181 // Parametrage de l echantillon sur S1
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.;
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.;
201 // Calcul des distances
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);
211 b- Calcul des minima:
213 b.a) Initialisations:
216 math_Vector Tol(1, 4);
221 math_Vector UV(1,4), UVinf(1,4), UVsup(1,4);
232 Standard_Real distmin = RealLast(), distmax = 0.0, TheDist;
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;
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) {
255 if (TheDist > distmax) {
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;
274 math_FunctionSetRoot SR1 (myF,UV,Tol,UVinf,UVsup);
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;
281 math_FunctionSetRoot SR2 (myF,UV,Tol,UVinf,UVsup);
283 myDone = Standard_True;
286 //=======================================================================
289 //=======================================================================
291 Standard_Boolean Extrema_GenExtSS::IsDone() const
296 //=======================================================================
299 //=======================================================================
301 Standard_Integer Extrema_GenExtSS::NbExt() const
303 if (!IsDone()) { StdFail_NotDone::Raise(); }
308 //=======================================================================
311 //=======================================================================
313 Standard_Real Extrema_GenExtSS::SquareDistance(const Standard_Integer N) const
315 if (!IsDone()) { StdFail_NotDone::Raise(); }
316 return myF.SquareDistance(N);
319 //=======================================================================
320 //function : PointOnS1
322 //=======================================================================
324 Extrema_POnSurf Extrema_GenExtSS::PointOnS1(const Standard_Integer N) const
326 if (!IsDone()) { StdFail_NotDone::Raise(); }
327 return myF.PointOnS1(N);
330 //=======================================================================
331 //function : PointOnS2
333 //=======================================================================
335 Extrema_POnSurf Extrema_GenExtSS::PointOnS2(const Standard_Integer N) const
337 if (!IsDone()) { StdFail_NotDone::Raise(); }
338 return myF.PointOnS2(N);
341 //=======================================================================
344 //=======================================================================
346 Adaptor3d_SurfacePtr Extrema_GenExtSS::Bidon() const
348 return (Adaptor3d_SurfacePtr)0L;