0027961: Visualization - remove unused and no more working OpenGl_AVIWriter
[occt.git] / src / Extrema / Extrema_FuncExtSS.cxx
1 // Created on: 1996-01-09
2 // Created by: Laurent PAINNOT
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Adaptor3d_Surface.hxx>
19 #include <Extrema_FuncExtSS.hxx>
20 #include <Extrema_POnSurf.hxx>
21 #include <gp_Vec.hxx>
22 #include <math_Matrix.hxx>
23 #include <Standard_OutOfRange.hxx>
24 #include <Standard_TypeMismatch.hxx>
25
26 /*----------------------------------------------------------------------------
27  Si on note Du1s et Dv1s, les derivees en u1 et v1, les 2 fonctions a annuler sont:
28  Si on note Du2s et Dv2s, les derivees en u2 et v2, les 2 fonctions a annuler sont:
29  { F1(u1,v1,u2,v2) = (S1(u1,v1)-S2(u2,v2)).Du1s1(u1,v1) }
30  { F2(u1,v1,u2,v2) = (S1(u1,v1)-S2(u2,v2)).Dv1s1(u1,v1) }
31  { F3(u1,v1,u2,v2) = (S1(u1,v1)-S2(u2,v2)).Du2s2(u2,v2) }
32  { F4(u1,v1,u2,v2) = (S1(u1,v1)-S2(u2,v2)).Dv2s2(u2,v2) }
33  { du1f1(u1,v1,u2,v2) = Du1s1(u1,v1).Du1s1(u1,v1)+(S1(u1,v1)-S2(u2,v2)).Du1u1s1(u1,v1) 
34                       = ||Du1s1(u1,v1)||**2      +(S1(u1,v1)-S2(u2,v2)).Du1u1s1(u1,v1) }
35  { dv1f1(u1,v1,u2,v2) = Dv1s1(u1,v1).Du1s1(u1,v1)+(S1(u1,v1)-S2(u2,v2)).Du1v1s1(u1,v1) }
36  { du2f1(u1,v1,u2,v2) = -Du2s2(u2,v2).Du1s1(u1,v1) }
37  { dv2f1(u1,v1,u2,v2) = -Dv2s2(u2,v2).Du1s1(u1,v1) }
38  { du1f2(u1,v1,u2,v2) = Du1s1(u1,v1).Dv1s1(u1,v1)+(S1(u1,v1)-S2(u2,v2)).Du1v1s1(u1,v1) }
39  { dv1f2(u1,v1,u2,v2) = Dv1s1(u1,v1).Dv1s1(u1,v1)+(S1(u1,v1)-S2(u2,v2)).Dv1v1s1(u1,v1) 
40                       = ||Dv1s1(u1,v1)||**2      +(S1(u1,v1)-S2(u2,v2)).Dv1v1s1(u1,v1) }
41  { du2f2(u1,v1,u2,v2) = -Du2s2(u2,v2).Dv1s1(u1,v1) }
42  { dv2f2(u1,v1,u2,v2) = -Dv2s2(u2,v2).Dv1s1(u1,v1) }
43  { du1f3(u1,v1,u2,v2) = Du1s1(u1,v1).Du2s2(u2,v2) }
44  { dv1f3(u1,v1,u2,v2) = Dv1s1(u1,v1).Du2s2(u2,v2) }
45  { du2f3(u1,v1,u2,v2) = -Du2s2(u2,v2).Du2s2(u2,v2)+(S1(u1,v1)-S2(u2,v2)).Du2u2s2(u2,v2) 
46                       = -||Du2s2(u2,v2)||**2      +(S1(u1,v1)-S2(u2,v2)).Du2u2s2(u2,v2) }
47  { dv2f3(u1,v1,u2,v2) = -Dv2s2(u2,v2).Du2s2(u2,v2)+(S1(u1,v1)-S2(u2,v2)).Dv2u2s2(u2,v2) }
48  { du1f4(u1,v1,u2,v2) = Du1s1(u1,v1).Dv2s2(u2,v2) }
49  { dv1f4(u1,v1,u2,v2) = Dv1s1(u1,v1).Dv2s2(u2,v2) }
50  { du2f4(u1,v1,u2,v2) = -Du2s2(u2,v2).Dv2s2(u2,v2)+(S1(u1,v1)-S2(u2,v2)).Du2v2s2(u2,v2) }
51  { dv2f4(u1,v1,u2,v2) = -Dv2s2(u2,v2).Dv2s2(u2,v2)+(S1(u1,v1)-S2(u2,v2)).Dv2v2s2(u2,v2) 
52                       = -||Dv2s2(u2,v2)||**2      +(S1(u1,v1)-S2(u2,v2)).Dv2v2s2(u2,v2) }
53 ----------------------------------------------------------------------------*/
54 //=======================================================================
55 //function : Extrema_FuncExtSS
56 //purpose  : 
57 //=======================================================================
58 Extrema_FuncExtSS::Extrema_FuncExtSS ()
59 {
60   myS1init = Standard_False;
61   myS2init = Standard_False;
62 }
63
64 //=======================================================================
65 //function : Extrema_FuncExtSS
66 //purpose  : 
67 //=======================================================================
68
69 Extrema_FuncExtSS::Extrema_FuncExtSS (const Adaptor3d_Surface& S1,
70                                       const Adaptor3d_Surface& S2)
71 {
72   myS1 = (Adaptor3d_SurfacePtr)&S1;
73   myS2 = (Adaptor3d_SurfacePtr)&S2;
74   myS1init = Standard_True;
75   myS2init = Standard_True;
76 }
77
78 //=======================================================================
79 //function : Initialize
80 //purpose  : 
81 //=======================================================================
82
83 void Extrema_FuncExtSS::Initialize(const Adaptor3d_Surface& S1,
84                                    const Adaptor3d_Surface& S2)
85 {
86   myS1 = (Adaptor3d_SurfacePtr)&S1;
87   myS2 = (Adaptor3d_SurfacePtr)&S2;
88   myS1init = Standard_True;
89   myS2init = Standard_True;
90   myPoint1.Clear();
91   myPoint2.Clear();
92   mySqDist.Clear();
93 }
94
95
96
97 //=======================================================================
98 //function : NbVariables
99 //purpose  : 
100 //=======================================================================
101
102 Standard_Integer Extrema_FuncExtSS::NbVariables () const { return 4;}
103
104
105 //=======================================================================
106 //function : NbEquations
107 //purpose  : 
108 //=======================================================================
109
110 Standard_Integer Extrema_FuncExtSS::NbEquations () const { return 4;}
111
112
113 //=======================================================================
114 //function : Value
115 //purpose  : 
116 //=======================================================================
117
118 Standard_Boolean Extrema_FuncExtSS::Value (const math_Vector& UV, 
119                                            math_Vector& F)
120 {
121   if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
122   myU1 = UV(1);
123   myV1 = UV(2);
124   myU2 = UV(3);
125   myV2 = UV(4);
126   gp_Vec Du1s1, Dv1s1;
127   gp_Vec Du2s2, Dv2s2;
128   myS1->D1(myU1,myV1,myP1,Du1s1,Dv1s1);
129   myS2->D1(myU2,myV2,myP2,Du2s2,Dv2s2);
130
131   gp_Vec P1P2 (myP2,myP1);
132
133   F(1) = P1P2.Dot(Du1s1);
134   F(2) = P1P2.Dot(Dv1s1);
135   F(3) = P1P2.Dot(Du2s2);
136   F(4) = P1P2.Dot(Dv2s2);
137
138   return Standard_True;  
139 }
140
141 //=======================================================================
142 //function : Derivatives
143 //purpose  : 
144 //=======================================================================
145
146 Standard_Boolean Extrema_FuncExtSS::Derivatives (const math_Vector& UV, 
147                                                  math_Matrix& Df)
148 {
149   math_Vector F(1,4);
150   return Values(UV,F,Df);
151 }
152
153 //=======================================================================
154 //function : Values
155 //purpose  : 
156 //=======================================================================
157
158 Standard_Boolean Extrema_FuncExtSS::Values (const math_Vector& UV, 
159                                             math_Vector& F,
160                                             math_Matrix& Df)
161 {
162   if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
163   myU1 = UV(1);
164   myV1 = UV(2);
165   myU2 = UV(3);
166   myV2 = UV(4);
167   gp_Vec Du1s1, Dv1s1, Du1u1s1, Dv1v1s1, Du1v1s1;
168   gp_Vec Du2s2, Dv2s2, Du2u2s2, Dv2v2s2, Du2v2s2;
169   myS1->D2(myU1,myV1,myP1,Du1s1,Dv1s1,Du1u1s1,Dv1v1s1,Du1v1s1);
170   myS2->D2(myU2,myV2,myP2,Du2s2,Dv2s2,Du2u2s2,Dv2v2s2,Du2v2s2);
171
172   gp_Vec P1P2 (myP2,myP1);
173
174   F(1) = P1P2.Dot(Du1s1);
175   F(2) = P1P2.Dot(Dv1s1);
176   F(3) = P1P2.Dot(Du2s2);
177   F(4) = P1P2.Dot(Dv2s2);
178
179   Df(1,1) = Du1s1.SquareMagnitude() + P1P2.Dot(Du1u1s1);
180   Df(1,2) = Dv1s1.Dot(Du1s1) + P1P2.Dot(Du1v1s1);
181   Df(1,3) = -Du2s2.Dot(Du1s1);
182   Df(1,4) = -Dv2s2.Dot(Du1s1);
183
184   Df(2,1) = Df(1, 2);   // Du1s1.Dot(Dv1s1) + P1P2.Dot(Du1v1s1);
185   Df(2,2) = Dv1s1.SquareMagnitude() + P1P2.Dot(Dv1v1s1);
186   Df(2,3) = -Du2s2.Dot(Dv1s1);
187   Df(2,4) = -Dv2s2.Dot(Dv1s1);
188
189   Df(3,1) = -Df(1,3);   // Du1s1.Dot(Du2s2);
190   Df(3,2) = -Df(2,3);   // Dv1s1.Dot(Du2s2);
191   Df(3,3) = -Du2s2.SquareMagnitude() + P1P2.Dot(Du2u2s2);
192   Df(3,4) = -Dv2s2.Dot(Du2s2) + P1P2.Dot(Du2v2s2);
193
194   Df(4,1) = -Df(1,4);   // Du1s1.Dot(Dv2s2);
195   Df(4,2) = -Df(2,4);   // Dv1s1.Dot(Dv2s2);
196   Df(4,3) = Df(3,4);    // -Du2s2.Dot(Dv2s2) + P1P2.Dot(Du2v2s2);
197   Df(4,4) = -Dv2s2.SquareMagnitude() + P1P2.Dot(Dv2v2s2);
198
199   return Standard_True;
200 }
201
202 //=======================================================================
203 //function : GetStateNumber
204 //purpose  : 
205 //=======================================================================
206
207 Standard_Integer Extrema_FuncExtSS::GetStateNumber ()
208 {
209   if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
210 #if 0
211   math_Vector Sol(1, 4), UVSol(1, 4);
212   UVSol(1) = myU1; UVSol(2) = myV1; UVSol(3) = myU2; UVSol(4) = myV2;
213   Value(UVSol, Sol);
214   cout <<"F(1)= "<<Sol(1)<<" F(2)= "<<Sol(2)<<" F(3)= "<<Sol(3)<<" F(4)= "<<Sol(4)<<endl;
215 #endif
216
217   mySqDist.Append(myP1.SquareDistance(myP2));
218   myPoint1.Append(Extrema_POnSurf(myU1,myV1,myP1));
219   myPoint2.Append(Extrema_POnSurf(myU2,myV2,myP2));
220   return 0;
221 }
222
223 //=======================================================================
224 //function : NbExt
225 //purpose  : 
226 //=======================================================================
227
228 Standard_Integer Extrema_FuncExtSS::NbExt () const
229 {
230   return mySqDist.Length();
231 }
232
233 //=======================================================================
234 //function : SquareDistance
235 //purpose  : 
236 //=======================================================================
237
238 Standard_Real Extrema_FuncExtSS::SquareDistance (const Standard_Integer N) const
239 {
240   if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
241   return mySqDist.Value(N);
242 }
243
244 //=======================================================================
245 //function : PointOnS1
246 //purpose  : 
247 //=======================================================================
248
249 const Extrema_POnSurf& Extrema_FuncExtSS::PointOnS1 (const Standard_Integer N) const
250 {
251   if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
252   return myPoint1.Value(N);
253 }
254 //=======================================================================
255 //function : PointOnS2
256 //purpose  : 
257 //=======================================================================
258
259 const Extrema_POnSurf& Extrema_FuncExtSS::PointOnS2 (const Standard_Integer N) const
260 {
261   if (!myS1init || !myS2init) Standard_TypeMismatch::Raise();
262   return myPoint2.Value(N);
263 }
264
265