1 // Created on: 2014-06-23
2 // Created by: Alexander Malyshev
3 // Copyright (c) 2014-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement
16 #include <Extrema_GlobOptFuncCS.hxx>
20 #include <math_Vector.hxx>
21 #include <Standard_Integer.hxx>
22 #include <Standard_OutOfRange.hxx>
24 //!F(cu, su, sv)=(C^{(x)}(cu)-S^{(x)}(su,sv))^{2}+
25 // (C^{(y)}(cu)-S^{(y)}(su,sv))^{2}+
26 // (C^{(z)}(cu)-S^{(z)}(su,sv))^{2}
29 //=======================================================================
32 //=======================================================================
33 void Extrema_GlobOptFuncCS::value(Standard_Real cu,
38 F = myC->Value(cu).SquareDistance(myS->Value(su, sv));
41 //=======================================================================
44 //=======================================================================
45 void Extrema_GlobOptFuncCS::gradient(Standard_Real cu,
51 gp_Vec CD1, SD1U, SD1V;
53 myC->D1(cu, CD0, CD1);
54 myS->D1(su, sv, SD0, SD1U, SD1V);
56 G(1) = + (CD0.X() - SD0.X()) * CD1.X()
57 + (CD0.Y() - SD0.Y()) * CD1.Y()
58 + (CD0.Z() - SD0.Z()) * CD1.Z();
59 G(2) = - (CD0.X() - SD0.X()) * SD1U.X()
60 - (CD0.Y() - SD0.Y()) * SD1U.Y()
61 - (CD0.Z() - SD0.Z()) * SD1U.Z();
62 G(3) = - (CD0.X() - SD0.X()) * SD1V.X()
63 - (CD0.Y() - SD0.Y()) * SD1V.Y()
64 - (CD0.Z() - SD0.Z()) * SD1V.Z();
67 //=======================================================================
70 //=======================================================================
71 void Extrema_GlobOptFuncCS::hessian(Standard_Real cu,
77 gp_Vec CD1, SD1U, SD1V, CD2, SD2UU, SD2UV, SD2VV;
79 myC->D2(cu, CD0, CD1, CD2);
80 myS->D2(su, sv, SD0, SD1U, SD1V, SD2UU, SD2VV, SD2UV);
82 H(1,1) = + CD1.X() * CD1.X()
85 + (CD0.X() - SD0.X()) * CD2.X()
86 + (CD0.Y() - SD0.Y()) * CD2.Y()
87 + (CD0.Z() - SD0.Z()) * CD2.Z();
89 H(1,2) = - CD1.X() * SD1U.X()
93 H(1,3) = - CD1.X() * SD1V.X()
99 H(2,2) = + SD1U.X() * SD1U.X()
100 + SD1U.Y() * SD1U.Y()
101 + SD1U.Z() * SD1U.Z()
102 - (CD0.X() - SD0.X()) * SD2UU.X()
103 - (CD0.Y() - SD0.Y()) * SD2UU.Y()
104 - (CD0.Z() - SD0.Z()) * SD2UU.Z();
106 H(2,3) = + SD1U.X() * SD1V.X()
107 + SD1U.Y() * SD1V.Y()
108 + SD1U.Z() * SD1V.Z()
109 - (CD0.X() - SD0.X()) * SD2UV.X()
110 - (CD0.Y() - SD0.Y()) * SD2UV.Y()
111 - (CD0.Z() - SD0.Z()) * SD2UV.Z();
117 H(3,3) = + SD1V.X() * SD1V.X()
118 + SD1V.Y() * SD1V.Y()
119 + SD1V.Z() * SD1V.Z()
120 - (CD0.X() - SD0.X()) * SD2VV.X()
121 - (CD0.Y() - SD0.Y()) * SD2VV.Y()
122 - (CD0.Z() - SD0.Z()) * SD2VV.Z();
125 //=======================================================================
126 //function : checkInputData
128 //=======================================================================
129 Standard_Boolean Extrema_GlobOptFuncCS::checkInputData(const math_Vector &X,
134 Standard_Integer aStartIndex = X.Lower();
136 su = X(aStartIndex + 1);
137 sv = X(aStartIndex + 2);
139 if (cu < myC->FirstParameter() ||
140 cu > myC->LastParameter() ||
141 su < myS->FirstUParameter() ||
142 su > myS->LastUParameter() ||
143 sv < myS->FirstVParameter() ||
144 sv > myS->LastVParameter())
146 return Standard_False;
148 return Standard_True;
151 //=======================================================================
152 //function : Extrema_GlobOptFuncCS
153 //purpose : Constructor
154 //=======================================================================
155 Extrema_GlobOptFuncCS::Extrema_GlobOptFuncCS(const Adaptor3d_Curve *C,
156 const Adaptor3d_Surface *S)
162 //=======================================================================
163 //function : NbVariables
165 //=======================================================================
166 Standard_Integer Extrema_GlobOptFuncCS::NbVariables() const
171 //=======================================================================
174 //=======================================================================
175 Standard_Boolean Extrema_GlobOptFuncCS::Value(const math_Vector &X,
178 Standard_Real cu, su, sv;
179 if (!checkInputData(X, cu, su, sv))
180 return Standard_False;
182 value(cu, su, sv, F);
183 return Standard_True;
186 //=======================================================================
187 //function : Gradient
189 //=======================================================================
190 Standard_Boolean Extrema_GlobOptFuncCS::Gradient(const math_Vector &X,
193 Standard_Real cu, su, sv;
194 if (!checkInputData(X, cu, su, sv))
195 return Standard_False;
197 gradient(cu, su, sv, G);
198 return Standard_True;
201 //=======================================================================
204 //=======================================================================
205 Standard_Boolean Extrema_GlobOptFuncCS::Values(const math_Vector &X,
209 Standard_Real cu, su, sv;
210 if (!checkInputData(X, cu, su, sv))
211 return Standard_False;
213 value(cu, su, sv, F);
214 gradient(cu, su, sv, G);
215 return Standard_True;
218 //=======================================================================
221 //=======================================================================
222 Standard_Boolean Extrema_GlobOptFuncCS::Values(const math_Vector &X,
227 Standard_Real cu, su, sv;
228 if (!checkInputData(X, cu, su, sv))
229 return Standard_False;
231 value(cu, su, sv, F);
232 gradient(cu, su, sv, G);
233 hessian(cu, su, sv, H);
234 return Standard_True;