Warnings on vc14 were eliminated
[occt.git] / src / Extrema / Extrema_GlobOptFuncCS.cxx
CommitLineData
1d33d22b 1// Created on: 2014-06-23
2// Created by: Alexander Malyshev
3// Copyright (c) 2014-2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
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.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement
15
16#include <Extrema_GlobOptFuncCS.hxx>
17
18#include <gp_Pnt.hxx>
19#include <gp_Vec.hxx>
20#include <math_Vector.hxx>
21#include <Standard_Integer.hxx>
22#include <Standard_OutOfRange.hxx>
23
f82a9555 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}
1d33d22b 27
28
29//=======================================================================
30//function : value
31//purpose :
32//=======================================================================
33void Extrema_GlobOptFuncCS::value(Standard_Real cu,
34 Standard_Real su,
35 Standard_Real sv,
36 Standard_Real &F)
37{
f82a9555 38 F = myC->Value(cu).SquareDistance(myS->Value(su, sv));
1d33d22b 39}
40
41//=======================================================================
42//function : gradient
43//purpose :
44//=======================================================================
45void Extrema_GlobOptFuncCS::gradient(Standard_Real cu,
46 Standard_Real su,
47 Standard_Real sv,
48 math_Vector &G)
49{
50 gp_Pnt CD0, SD0;
51 gp_Vec CD1, SD1U, SD1V;
52
53 myC->D1(cu, CD0, CD1);
54 myS->D1(su, sv, SD0, SD1U, SD1V);
55
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();
65}
66
67//=======================================================================
68//function : hessian
69//purpose :
70//=======================================================================
71void Extrema_GlobOptFuncCS::hessian(Standard_Real cu,
72 Standard_Real su,
73 Standard_Real sv,
74 math_Matrix &H)
75{
76 gp_Pnt CD0, SD0;
77 gp_Vec CD1, SD1U, SD1V, CD2, SD2UU, SD2UV, SD2VV;
78
79 myC->D2(cu, CD0, CD1, CD2);
80 myS->D2(su, sv, SD0, SD1U, SD1V, SD2UU, SD2VV, SD2UV);
81
82 H(1,1) = + CD1.X() * CD1.X()
83 + CD1.Y() * CD1.Y()
84 + CD1.Z() * CD1.Z()
85 + (CD0.X() - SD0.X()) * CD2.X()
86 + (CD0.Y() - SD0.Y()) * CD2.Y()
87 + (CD0.Z() - SD0.Z()) * CD2.Z();
f82a9555 88
1d33d22b 89 H(1,2) = - CD1.X() * SD1U.X()
90 - CD1.Y() * SD1U.Y()
91 - CD1.Z() * SD1U.Z();
f82a9555 92
1d33d22b 93 H(1,3) = - CD1.X() * SD1V.X()
94 - CD1.Y() * SD1V.Y()
95 - CD1.Z() * SD1V.Z();
f82a9555 96
1d33d22b 97 H(2,1) = H(1,2);
f82a9555 98
1d33d22b 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()
f82a9555 103 - (CD0.Y() - SD0.Y()) * SD2UU.Y()
104 - (CD0.Z() - SD0.Z()) * SD2UU.Z();
105
1d33d22b 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()
f82a9555 110 - (CD0.Y() - SD0.Y()) * SD2UV.Y()
111 - (CD0.Z() - SD0.Z()) * SD2UV.Z();
112
1d33d22b 113 H(3,1) = H(1,3);
f82a9555 114
1d33d22b 115 H(3,2) = H(2,3);
f82a9555 116
1d33d22b 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()
f82a9555 121 - (CD0.Y() - SD0.Y()) * SD2VV.Y()
122 - (CD0.Z() - SD0.Z()) * SD2VV.Z();
1d33d22b 123}
124
125//=======================================================================
126//function : checkInputData
127//purpose :
128//=======================================================================
129Standard_Boolean Extrema_GlobOptFuncCS::checkInputData(const math_Vector &X,
130 Standard_Real &cu,
131 Standard_Real &su,
132 Standard_Real &sv)
133{
134 Standard_Integer aStartIndex = X.Lower();
135 cu = X(aStartIndex);
136 su = X(aStartIndex + 1);
137 sv = X(aStartIndex + 2);
138
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())
145 {
146 return Standard_False;
147 }
148 return Standard_True;
149}
150
151//=======================================================================
152//function : Extrema_GlobOptFuncCS
153//purpose : Constructor
154//=======================================================================
155Extrema_GlobOptFuncCS::Extrema_GlobOptFuncCS(const Adaptor3d_Curve *C,
156 const Adaptor3d_Surface *S)
157: myC(C),
158 myS(S)
159{
160}
161
162//=======================================================================
163//function : NbVariables
164//purpose :
165//=======================================================================
166Standard_Integer Extrema_GlobOptFuncCS::NbVariables() const
167{
168 return 3;
169}
170
171//=======================================================================
172//function : Value
173//purpose :
174//=======================================================================
175Standard_Boolean Extrema_GlobOptFuncCS::Value(const math_Vector &X,
176 Standard_Real &F)
177{
178 Standard_Real cu, su, sv;
179 if (!checkInputData(X, cu, su, sv))
180 return Standard_False;
181
182 value(cu, su, sv, F);
183 return Standard_True;
184}
185
186//=======================================================================
187//function : Gradient
188//purpose :
189//=======================================================================
190Standard_Boolean Extrema_GlobOptFuncCS::Gradient(const math_Vector &X,
191 math_Vector &G)
192{
193 Standard_Real cu, su, sv;
194 if (!checkInputData(X, cu, su, sv))
195 return Standard_False;
196
197 gradient(cu, su, sv, G);
198 return Standard_True;
199}
200
201//=======================================================================
202//function : Values
203//purpose :
204//=======================================================================
205Standard_Boolean Extrema_GlobOptFuncCS::Values(const math_Vector &X,
206 Standard_Real &F,
207 math_Vector &G)
208{
209 Standard_Real cu, su, sv;
210 if (!checkInputData(X, cu, su, sv))
211 return Standard_False;
212
213 value(cu, su, sv, F);
214 gradient(cu, su, sv, G);
215 return Standard_True;
216}
217
218//=======================================================================
219//function : Values
220//purpose :
221//=======================================================================
222Standard_Boolean Extrema_GlobOptFuncCS::Values(const math_Vector &X,
223 Standard_Real &F,
224 math_Vector &G,
225 math_Matrix &H)
226{
227 Standard_Real cu, su, sv;
228 if (!checkInputData(X, cu, su, sv))
229 return Standard_False;
230
231 value(cu, su, sv, F);
232 gradient(cu, su, sv, G);
233 hessian(cu, su, sv, H);
234 return Standard_True;
235}