53 const std::vector<InterpPtInfo>& closest,
59 double wi, xi, yi, fi;
61 n = (int)closest.size();
63 for (i = 1; i <= 5; i++)
68 for (j = 1; j <= 5; j++)
69 M[i - 1][j - 1] = 0.0;
72 for (i = 0; i < n; i++)
74 wi = closest[i].m_weight;
75 xi = closest[i].m_loc.x - xk;
76 yi = closest[i].m_loc.y - yk;
77 fi = closest[i].m_scalar;
80 M[0][0] = M[0][0] + wi * xi * xi;
81 M[0][1] = M[0][1] + wi * xi * yi;
82 M[0][2] = M[0][2] + wi * xi * xi * xi;
83 M[0][3] = M[0][3] + wi * xi * xi * yi;
84 M[0][4] = M[0][4] + wi * xi * yi * yi;
85 v1[1] = v1[1] + wi * xi * fi;
86 v2[1] = v2[1] + wi * xi;
88 M[1][0] = M[1][0] + wi * yi * yi;
89 M[1][1] = M[1][1] + wi * xi * xi * yi;
90 M[1][2] = M[1][2] + wi * xi * yi * yi;
91 M[1][3] = M[1][3] + wi * yi * yi * yi;
92 v1[2] = v1[2] + wi * yi * fi;
93 v2[2] = v2[2] + wi * yi;
95 M[2][0] = M[2][0] + wi * xi * xi * xi * xi;
96 M[2][1] = M[2][1] + wi * xi * xi * xi * yi;
97 M[2][2] = M[2][2] + wi * xi * xi * yi * yi;
98 v1[3] = v1[3] + wi * xi * xi * fi;
99 v2[3] = v2[3] + wi * xi * xi;
101 M[3][0] = M[3][0] + wi * xi * xi * yi * yi;
102 M[3][1] = M[3][1] + wi * xi * yi * yi * yi;
103 v1[4] = v1[4] + wi * xi * yi * fi;
104 v2[4] = v2[4] + wi * xi * yi;
106 M[4][0] = M[4][0] + wi * yi * yi * yi * yi;
107 v1[5] = v1[5] + wi * yi * yi * fi;
108 v2[5] = v2[5] + wi * yi * yi;
111 for (i = 1; i <= 5; i++)
112 VV[i - 1] = v1[i] - fk * v2[i];
130 const std::vector<InterpPtInfo>& closest,
135 double v1[10], v2[10];
136 double wi, xi, yi, zi, fi;
137 double xyi, xzi, yzi, x2i, y2i, z2i, wXi;
143 for (i = 1; i < 10; i++)
148 for (j = 1; j < 10; j++)
149 m[i - 1][j - 1] = 0.0;
152 for (i = 0; i < (int)closest.size(); ++i)
154 wi = closest[i].m_weight;
155 xi = closest[i].m_loc.x - xk;
156 yi = closest[i].m_loc.y - yk;
157 zi = closest[i].m_loc.z - zk;
158 fi = closest[i].m_scalar;
169 m[0][0] += (wXi * xi);
170 m[0][1] += (wXi * yi);
171 m[0][2] += (wXi * zi);
172 m[0][3] += (wXi * xyi);
173 m[0][4] += (wXi * xzi);
174 m[0][5] += (wXi * yzi);
175 m[0][6] += (wXi * x2i);
176 m[0][7] += (wXi * y2i);
177 m[0][8] += (wXi * z2i);
182 m[1][0] += (wXi * yi);
183 m[1][1] += (wXi * zi);
184 m[1][2] += (wXi * xyi);
185 m[1][3] += (wXi * xzi);
186 m[1][4] += (wXi * yzi);
187 m[1][5] += (wXi * x2i);
188 m[1][6] += (wXi * y2i);
189 m[1][7] += (wXi * z2i);
194 m[2][0] += (wXi * zi);
195 m[2][1] += (wXi * xyi);
196 m[2][2] += (wXi * xzi);
197 m[2][3] += (wXi * yzi);
198 m[2][4] += (wXi * x2i);
199 m[2][5] += (wXi * y2i);
200 m[2][6] += (wXi * z2i);
205 m[3][0] += (wXi * xyi);
206 m[3][1] += (wXi * xzi);
207 m[3][2] += (wXi * yzi);
208 m[3][3] += (wXi * x2i);
209 m[3][4] += (wXi * y2i);
210 m[3][5] += (wXi * z2i);
215 m[4][0] += (wXi * xzi);
216 m[4][1] += (wXi * yzi);
217 m[4][2] += (wXi * x2i);
218 m[4][3] += (wXi * y2i);
219 m[4][4] += (wXi * z2i);
224 m[5][0] += (wXi * yzi);
225 m[5][1] += (wXi * x2i);
226 m[5][2] += (wXi * y2i);
227 m[5][3] += (wXi * z2i);
232 m[6][0] += (wXi * x2i);
233 m[6][1] += (wXi * y2i);
234 m[6][2] += (wXi * z2i);
239 m[7][0] += (wXi * y2i);
240 m[7][1] += (wXi * z2i);
245 m[8][0] += (wXi * z2i);
250 for (i = 1; i <= 9; i++)
251 vv[i - 1] = v1[i] - fk * v2[i];
267 const std::vector<int>& a_ptIdxs,
268 const std::vector<Pt3d>& a_ptLoc,
270 std::vector<double>& a_d2)
272 bool useAll = a_ptIdxs.empty();
273 size_t nPtIdxs = useAll ? a_ptLoc.size() : a_ptIdxs.size();
275 a_d2.reserve(nPtIdxs);
278 for (
size_t i = 0; i < nPtIdxs; ++i)
280 j = useAll ? i : a_ptIdxs[i];
281 d2 = xms::sqr(a_pt.
x - a_ptLoc[j].x) + xms::sqr(a_pt.
y - a_ptLoc[j].y);
283 d2 += xms::sqr(a_pt.
z - a_ptLoc[j].z);
307 bool a_modifiedShepardWeights,
308 std::vector<double>& a_w)
310 std::vector<double> d2(a_distSquare);
311 double distSum(0), dExp(a_power / 2), r, d;
313 a_w.assign(d2.size(), 0);
314 r = sqrt(*std::max_element(d2.begin(), d2.end()));
315 for (
size_t i = 0; i < d2.size(); ++i)
320 for (
size_t i = 0; i < d2.size(); ++i)
322 if (a_modifiedShepardWeights)
330 d2[i] = xms::sqr((r - d) / (r * d));
340 d2[i] = 1 / pow(d2[i], dExp);
348 for (
size_t i = 0; i < d2.size(); ++i)
351 for (
size_t i = 0; i < d2.size(); ++i)
353 a_w[i] = d2[i] / distSum;
365 bool allScalarsSame(
true);
366 if (a_scalars.empty())
367 return allScalarsSame;
369 if (a_act.empty() || a_act.size() != a_scalars.size())
371 float f = a_scalars[0];
372 for (
size_t i = 1; allScalarsSame && i < a_scalars.size(); ++i)
374 if (f != a_scalars[i])
375 allScalarsSame =
false;
377 return allScalarsSame;
384 for (
size_t i = 1; idx == 0 && i < a_act.size(); ++i)
391 float f = a_scalars[idx];
392 for (
size_t i = idx + 1; allScalarsSame && i < a_scalars.size(); ++i)
394 if (a_act[i] && f != a_scalars[i])
395 allScalarsSame =
false;
397 return allScalarsSame;
boost::dynamic_bitset< size_t > DynBitset
void inNodalFuncSetUpMatrixAndVector(double xk, double yk, double fk, const std::vector< InterpPtInfo > &closest, double **M, double *VV)
Sets up matrices for nodal function calculations. Refactored out of GMS.
void inNodalFuncSetUpMatrixAndVector3d(double xk, double yk, double zk, double fk, const std::vector< InterpPtInfo > &closest, double **M, double *vv)
Sets up matrices for nodal function calculations. Refactored out of GMS.
Utility functions called by interpolation code.
void inDistanceSquared(const Pt3d &a_pt, const std::vector< int > &a_ptIdxs, const std::vector< Pt3d > &a_ptLoc, bool a_2d, std::vector< double > &a_d2)
Computes the distance squared between the point "a_pt" and the other points. The other points are def...
void inIdwWeights(const std::vector< double > &a_distSquare, double a_power, bool a_modifiedShepardWeights, std::vector< double > &a_w)
Computes the idw weights that would be assigned to points associated with the distance squared that i...
bool inAllScalarsEqual(const std::vector< float > &a_scalars, const DynBitset &a_act)
Check to see if the all of the values in the scalars array are the same. It will also take into accou...