24 template <
typename Real>
27 public ApprQuery<Real, ApprPolynomialSpecial3<Real>, std::array<Real, 3>>
33 std::vector<int>
const& yDegrees);
40 bool Fit(std::vector<std::array<Real, 3>>
const& observations,
41 std::vector<int>
const&
indices);
46 Real
Error(std::array<Real, 3>
const& observation)
const;
59 void Transform(std::vector<std::array<Real, 3>>
const& observations,
60 std::vector<int>
const& indices,
61 std::vector<std::array<Real, 3>>& transformed);
64 bool DoLeastSquares(std::vector<std::array<Real, 3>>& transformed);
84 template <
typename Real>
86 std::vector<int>
const& xDegrees, std::vector<int>
const& yDegrees)
92 #if !defined(GTE_NO_LOGGER) 94 "The input arrays must have the same size.");
100 LogAssert(degree > lastDegree,
"Degrees must be increasing.");
108 LogAssert(degree > lastDegree,
"Degrees must be increasing.");
113 mXDomain[0] = std::numeric_limits<Real>::max();
115 mYDomain[0] = std::numeric_limits<Real>::max();
117 mWDomain[0] = std::numeric_limits<Real>::max();
129 mXPowers.resize(2 * mXDegrees.back() + 1);
131 mYPowers.resize(2 * mYDegrees.back() + 1);
135 template <
typename Real>
141 template <
typename Real>
143 std::vector<std::array<Real, 3>>
const& observations,
144 std::vector<int>
const&
indices)
146 if (indices.size() > 0)
149 std::vector<std::array<Real, 3>> transformed;
150 Transform(observations, indices, transformed);
160 template <
typename Real>
162 std::array<Real, 3>
const& observation)
const 164 Real
w =
Evaluate(observation[0], observation[1]);
165 Real error =
std::abs(w - observation[2]);
169 template <
typename Real>
175 template <
typename Real>
181 template <
typename Real>
187 template <
typename Real>
196 for (
int j = 1; j <= jmax; ++j)
202 for (
int j = 1; j <= jmax; ++j)
208 int isup =
static_cast<int>(
mXDegrees.size());
209 for (
int i = 0; i < isup; ++i)
221 template <
typename Real>
223 std::vector<std::array<Real, 3>>
const& observations,
224 std::vector<int>
const&
indices,
225 std::vector<std::array<Real, 3>>& transformed)
227 int numSamples =
static_cast<int>(indices.size());
228 transformed.resize(numSamples);
230 std::array<Real, 3> omin = observations[indices[0]];
231 std::array<Real, 3> omax = omin;
232 std::array<Real, 3> obs;
234 for (s = 1; s < numSamples; ++
s)
236 obs = observations[indices[
s]];
237 for (i = 0; i < 3; ++i)
239 if (obs[i] < omin[i])
243 else if (obs[i] > omax[i])
256 for (i = 0; i < 3; ++i)
258 mScale[i] = ((Real)1) / (omax[i] - omin[i]);
261 for (s = 0; s < numSamples; ++
s)
263 obs = observations[indices[
s]];
264 for (i = 0; i < 3; ++i)
266 transformed[
s][i] = (Real)-1 + ((Real)2) *
mScale[i] *
273 template <
typename Real>
275 std::vector<std::array<Real, 3>>& transformed)
285 int numSamples =
static_cast<int>(transformed.size());
286 int twoMaxXDegree = 2 *
mXDegrees.back();
287 int twoMaxYDegree = 2 *
mYDegrees.back();
289 for (
int i = 0; i < numSamples; ++i)
292 Real
x = transformed[i][0];
293 Real
y = transformed[i][1];
294 Real
w = transformed[i][2];
295 for (
int j = 1; j <= 2 * twoMaxXDegree; ++j)
299 for (
int j = 1; j <= 2 * twoMaxYDegree; ++j)
304 for (row = 0; row <
size; ++
row)
308 for (col = row; col <
size; ++col)
312 A(row, col) += xp * yp;
318 B[
row] += xp * yp *
w;
324 for (row = 0; row <
size; ++
row)
326 for (col = 0; col <
row; ++col)
328 A(row, col) = A(col, row);
333 Real invNumSamples = ((Real)1) / (Real)numSamples;
339 bool hasNonzero =
false;
340 for (
int i = 0; i <
size; ++i)
343 if (coefficients[i] != (Real)0)
std::array< Real, 2 > const & GetYDomain() const
std::vector< int > mYDegrees
std::vector< Real > mParameters
void Transform(std::vector< std::array< Real, 3 >> const &observations, std::vector< int > const &indices, std::vector< std::array< Real, 3 >> &transformed)
std::array< Real, 3 > mScale
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
#define LogAssert(condition, message)
GLubyte GLubyte GLubyte GLubyte w
Real Evaluate(Real x, Real y) const
std::vector< int > mXDegrees
std::array< Real, 2 > mXDomain
GLenum GLenum GLsizei void * row
GLsizei GLenum const void * indices
bool DoLeastSquares(std::vector< std::array< Real, 3 >> &transformed)
std::vector< Real > mYPowers
std::array< Real, 2 > const & GetXDomain() const
ApprPolynomialSpecial3(std::vector< int > const &xDegrees, std::vector< int > const &yDegrees)
std::array< Real, 2 > mWDomain
Real Error(std::array< Real, 3 > const &observation) const
std::vector< Real > const & GetParameters() const
int GetMinimumRequired() const
Quaternion< Real > Inverse(Quaternion< Real > const &d)
std::vector< Real > mXPowers
std::array< Real, 2 > mYDomain
bool Fit(std::vector< std::array< Real, 3 >> const &observations, std::vector< int > const &indices)