24 template <
typename Real>
27 public ApprQuery<Real, ApprPolynomialSpecial4<Real>, std::array<Real, 3>>
33 std::vector<int>
const& yDegrees, std::vector<int>
const& zDegrees);
40 bool Fit(std::vector<std::array<Real, 4>>
const& observations,
41 std::vector<int>
const&
indices);
46 Real
Error(std::array<Real, 4>
const& observation)
const;
60 void Transform(std::vector<std::array<Real, 4>>
const& observations,
61 std::vector<int>
const& indices,
62 std::vector<std::array<Real, 4>>& transformed);
65 bool DoLeastSquares(std::vector<std::array<Real, 4>>& transformed);
85 template <
typename Real>
87 std::vector<int>
const& xDegrees, std::vector<int>
const& yDegrees,
88 std::vector<int>
const& zDegrees)
95 #if !defined(GTE_NO_LOGGER) 98 "The input arrays must have the same size.");
104 LogAssert(degree > lastDegree,
"Degrees must be increasing.");
112 LogAssert(degree > lastDegree,
"Degrees must be increasing.");
120 LogAssert(degree > lastDegree,
"Degrees must be increasing.");
125 mXDomain[0] = std::numeric_limits<Real>::max();
127 mYDomain[0] = std::numeric_limits<Real>::max();
129 mZDomain[0] = std::numeric_limits<Real>::max();
131 mWDomain[0] = std::numeric_limits<Real>::max();
144 mXPowers.resize(2 * mXDegrees.back() + 1);
146 mYPowers.resize(2 * mYDegrees.back() + 1);
148 mZPowers.resize(2 * mZDegrees.back() + 1);
152 template <
typename Real>
158 template <
typename Real>
160 std::vector<std::array<Real, 4>>
const& observations,
161 std::vector<int>
const&
indices)
163 if (indices.size() > 0)
166 std::vector<std::array<Real, 4>> transformed;
167 Transform(observations, indices, transformed);
177 template <
typename Real>
179 std::array<Real, 4>
const& observation)
const 181 Real
w =
Evaluate(observation[0], observation[1], observation[2]);
182 Real error =
std::abs(w - observation[3]);
186 template <
typename Real>
192 template <
typename Real>
198 template <
typename Real>
204 template <
typename Real>
210 template <
typename Real>
220 for (
int j = 1; j <= jmax; ++j)
226 for (
int j = 1; j <= jmax; ++j)
232 for (
int j = 1; j <= jmax; ++j)
238 int isup =
static_cast<int>(
mXDegrees.size());
239 for (
int i = 0; i < isup; ++i)
252 template <
typename Real>
254 std::vector<std::array<Real, 4>>
const& observations,
255 std::vector<int>
const&
indices,
256 std::vector<std::array<Real, 4>>& transformed)
258 int numSamples =
static_cast<int>(indices.size());
259 transformed.resize(numSamples);
261 std::array<Real, 4> omin = observations[indices[0]];
262 std::array<Real, 4> omax = omin;
263 std::array<Real, 4> obs;
265 for (s = 1; s < numSamples; ++
s)
267 obs = observations[indices[
s]];
268 for (i = 0; i < 4; ++i)
270 if (obs[i] < omin[i])
274 else if (obs[i] > omax[i])
289 for (i = 0; i < 4; ++i)
291 mScale[i] = ((Real)1) / (omax[i] - omin[i]);
294 for (s = 0; s < numSamples; ++
s)
296 obs = observations[indices[
s]];
297 for (i = 0; i < 4; ++i)
299 transformed[
s][i] = (Real)-1 + ((Real)2) *
mScale[i] *
306 template <
typename Real>
308 std::vector<std::array<Real, 4>>& transformed)
318 int numSamples =
static_cast<int>(transformed.size());
319 int twoMaxXDegree = 2 *
mXDegrees.back();
320 int twoMaxYDegree = 2 *
mYDegrees.back();
321 int twoMaxZDegree = 2 *
mZDegrees.back();
323 for (
int i = 0; i < numSamples; ++i)
326 Real
x = transformed[i][0];
327 Real
y = transformed[i][1];
328 Real
z = transformed[i][2];
329 Real
w = transformed[i][3];
330 for (
int j = 1; j <= twoMaxXDegree; ++j)
334 for (
int j = 1; j <= twoMaxYDegree; ++j)
338 for (
int j = 1; j <= twoMaxZDegree; ++j)
343 for (row = 0; row <
size; ++
row)
347 for (col = row; col <
size; ++col)
352 A(row, col) += xp * yp * zp;
359 B[
row] += xp * yp * zp *
w;
365 for (row = 0; row <
size; ++
row)
367 for (col = 0; col <
row; ++col)
369 A(row, col) = A(col, row);
374 Real invNumSamples = ((Real)1) / (Real)numSamples;
380 bool hasNonzero =
false;
381 for (
int i = 0; i <
size; ++i)
384 if (coefficients[i] != (Real)0)
std::array< Real, 4 > mScale
std::vector< Real > mZPowers
std::vector< Real > mParameters
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
std::array< Real, 2 > const & GetYDomain() const
#define LogAssert(condition, message)
std::vector< int > mZDegrees
Real Error(std::array< Real, 4 > const &observation) const
std::array< Real, 2 > mWDomain
std::array< Real, 2 > const & GetXDomain() const
int GetMinimumRequired() const
std::array< Real, 2 > mZDomain
GLubyte GLubyte GLubyte GLubyte w
bool Fit(std::vector< std::array< Real, 4 >> const &observations, std::vector< int > const &indices)
std::vector< Real > const & GetParameters() const
GLenum GLenum GLsizei void * row
GLsizei GLenum const void * indices
Real Evaluate(Real x, Real y, Real z) const
std::vector< Real > mYPowers
bool DoLeastSquares(std::vector< std::array< Real, 4 >> &transformed)
std::array< Real, 2 > const & GetZDomain() const
void Transform(std::vector< std::array< Real, 4 >> const &observations, std::vector< int > const &indices, std::vector< std::array< Real, 4 >> &transformed)
std::array< Real, 2 > mYDomain
std::vector< int > mYDegrees
GLdouble GLdouble GLdouble z
std::array< Real, 2 > mXDomain
Quaternion< Real > Inverse(Quaternion< Real > const &d)
ApprPolynomialSpecial4(std::vector< int > const &xDegrees, std::vector< int > const &yDegrees, std::vector< int > const &zDegrees)
std::vector< int > mXDegrees
std::vector< Real > mXPowers