xmsinterp  1.0
NodalFunc.cpp
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
6 //------------------------------------------------------------------------------
7 
8 //----- Included files ---------------------------------------------------------
9 
10 // 1. Precompiled header
11 
12 // 2. My own header
14 
15 // 3. Standard library headers
16 
17 // 4. External library headers
18 #include <boost/thread/mutex.hpp>
19 #include <boost/weak_ptr.hpp>
20 
21 // 5. Shared code headers
22 //#include <shared1/containers/ContinuousArrays.h>
23 #include <xmscore/misc/XmError.h>
24 #include <xmscore/misc/XmLog.h>
25 #include <xmscore/stl/vector.h>
26 #include <xmscore/stl/utility.h>
27 #include <xmsgrid/geometry/GmPtSearch.h>
28 #include <xmsgrid/matrices/matrix.h>
33 
34 // 6. Non-shared code headers
35 
36 //----- Forward declarations ---------------------------------------------------
37 
38 //----- External globals -------------------------------------------------------
39 
40 //----- Namespace declaration --------------------------------------------------
41 // using namespace xms;
42 namespace xms
43 {
44 //----- Constants / Enumerations -----------------------------------------------
45 
46 //----- Classes / Structs ------------------------------------------------------
48 class NodalFuncImpl : public NodalFunc
49 {
50 public:
52  enum { NF_CONSTANT, NF_GRAD_PLANE, NF_QUADRATIC };
53 
55  class NfThread : public ThreadLoop
56  {
57  public:
61  NfThread(NodalFuncImpl* a_nf, BSHP<GmPtSearch> a_ptSearch)
62  : m_nf(a_nf)
63  , m_ptSearch(a_ptSearch)
64  {
65  }
66 
69  BSHP<ThreadLoop> CreateForNewThread() override
70  {
71  BSHP<NfThread> r(new NfThread(m_nf, m_ptSearch));
72  BSHP<ThreadLoop> q = BDPC<ThreadLoop>(r);
73  return q;
74  }
75 
77  BSHP<GmPtSearch> m_ptSearch;
79  std::vector<InterpPtInfo>
83  private:
85  void Worker() override
86  {
87  if (m_nf->m_errorReport)
88  return;
90  }
91  };
92 
93  NodalFuncImpl(const std::vector<Pt3d>& a_pts, const std::vector<float>& a_scalar);
94  NodalFuncImpl(int a_type,
95  bool a_2d,
96  BSHP<GmPtSearch> a_ptSearch,
97  const std::vector<Pt3d>& a_pts,
98  const std::vector<float>& a_scalar,
99  int a_nNearest,
100  bool a_quad_oct,
101  double a_power,
102  bool a_modifiedShepardWeights,
103  BSHP<Observer> a_p,
104  InterpNatNeigh* a_natNeigh);
105 
106  virtual double ScalarFromPtIdx(int a_ptIdx, const Pt3d& a_loc) const override;
107  virtual void GradientFromPtIdx(int a_ptIdx, Pt3d& a_grad) const override;
108  virtual void ComputeNodalFuncs() override;
109  virtual std::string ToString() const override;
112  virtual int GetType() const override { return m_type; }
115  virtual int GetNearestPointsOption() const override
116  {
117  if (m_natNeigh)
118  return 0;
119  return 1;
120  }
123  virtual int GetNumNearestPoints() const override { return m_nNearest; };
126  virtual bool GetUseModifiedShepardWeights() const override { return m_modifiedShepardWeights; }
129  virtual bool GetUseQuadrantSearch() const override { return m_quadOct; }
130 
131  void NfForPt(int a_ptIdx,
132  BSHP<GmPtSearch> a_s,
133  std::vector<int>& nearestPts,
134  std::vector<InterpPtInfo>& matrixPts,
135  std::vector<double>& d2,
136  std::vector<double>& w);
137  void NodalFuncForPtFromMatrixPts(int a_ptIdx, const std::vector<InterpPtInfo>& a_pts);
138 
139  void NodalFunc2d(int a_ptIdx, const std::vector<InterpPtInfo>& a_pts, double* a_A);
140  void NodalFunc3d(int a_ptIdx, const std::vector<InterpPtInfo>& a_pts, double* a_A);
141  Pt3d ComputeGradientForPoint(int a_ptIdx, const std::vector<InterpPtInfo>& a_pts);
142 
143  bool m_2d;
144  int m_type;
146  bool m_quadOct;
147  const std::vector<Pt3d>& m_pts;
148  const std::vector<float>& m_scalar;
149  BSHP<GmPtSearch> m_ptSearch;
150  std::vector<Pt3d> m_gradient;
152  double m_power;
154  std::vector<int> m_nearestAll;
156  BSHP<Observer> m_prog;
158  bool m_debugTest;
162 };
163 
164 //----- Internal functions -----------------------------------------------------
165 
166 //----- Class / Function definitions -------------------------------------------
167 
168 //------------------------------------------------------------------------------
187 //------------------------------------------------------------------------------
188 BSHP<NodalFunc> NodalFunc::New(int a_type,
189  bool a_2d,
190  BSHP<GmPtSearch> a_ptSearch,
191  const std::vector<Pt3d>& a_pts,
192  const std::vector<float>& a_scalar,
193  int a_nNearest,
194  bool a_quad_oct,
195  double a_power,
196  bool a_modifiedShepardWeights,
197  BSHP<Observer> a_p,
198  InterpNatNeigh* a_natNeigh)
199 {
200  BSHP<NodalFunc> ptr(new NodalFuncImpl(a_type, a_2d, a_ptSearch, a_pts, a_scalar, a_nNearest,
201  a_quad_oct, a_power, a_modifiedShepardWeights, a_p,
202  a_natNeigh));
203  return ptr;
204 } // NodalFunc::New
205 //------------------------------------------------------------------------------
207 //------------------------------------------------------------------------------
209 {
210 } // NodalFunc::NodalFunc
211 //------------------------------------------------------------------------------
213 //------------------------------------------------------------------------------
215 {
216 } // NodalFunc::~NodalFunc
217 
221 //------------------------------------------------------------------------------
225 //------------------------------------------------------------------------------
226 NodalFuncImpl::NodalFuncImpl(const std::vector<Pt3d>& a_pts, const std::vector<float>& a_scalar)
227 : m_2d(true)
228 , m_type(0)
229 , m_nNearest(8)
230 , m_quadOct(false)
231 , m_pts(a_pts)
232 , m_scalar(a_scalar)
233 , m_ptSearch()
234 , m_gradient()
235 , m_quadratic()
236 , m_power(2.0)
237 , m_modifiedShepardWeights(true)
238 , m_prog()
239 , m_errorReport(false)
240 , m_debugTest(true)
241 , m_natNeigh(nullptr)
242 {
243 } // NodalFuncImpl::NodalFuncImpl
244 //------------------------------------------------------------------------------
262 //------------------------------------------------------------------------------
264  bool a_2d,
265  BSHP<GmPtSearch> a_ptSearch,
266  const std::vector<Pt3d>& a_pts,
267  const std::vector<float>& a_scalar,
268  int a_nNearest,
269  bool a_quad_oct,
270  double a_power,
271  bool a_modifiedShepardWeights,
272  BSHP<Observer> a_p,
273  InterpNatNeigh* a_natNeigh)
274 : m_2d(a_2d)
275 , m_type(a_type)
276 , m_nNearest(a_nNearest)
277 , m_quadOct(a_quad_oct)
278 , m_pts(a_pts)
279 , m_scalar(a_scalar)
280 , m_ptSearch(a_ptSearch)
281 , m_gradient()
282 , m_quadratic()
283 , m_power(a_power)
284 , m_modifiedShepardWeights(a_modifiedShepardWeights)
285 , m_prog(a_p)
286 , m_errorReport(false)
287 , m_debugTest(false)
288 , m_natNeigh(a_natNeigh)
289 {
290  if (NF_GRAD_PLANE == m_type)
291  m_gradient.assign(m_pts.size(), Pt3d());
292  else if (NF_QUADRATIC == m_type)
293  {
294  // m_quadratic.SetSize((int)m_scalar.size(), 9, 0);
295  m_quadratic.assign((int)m_scalar.size(), VecDbl(9, 0.0));
296  }
297  if (m_nNearest < 1)
298  {
299  for (size_t i = 0; i < m_pts.size(); ++i)
300  m_nearestAll.push_back((int)i);
301  }
303 } // NodalFuncImpl::NodalFuncImpl
304 //------------------------------------------------------------------------------
307 //------------------------------------------------------------------------------
309 {
310  if (m_pts.empty())
311  return;
312  BSHP<GmPtSearch> s = m_ptSearch;
313 
314  if (m_pts.size() > 500)
315  {
316  BSHP<ThreadMgr> mgr = ThreadMgr::New();
317  mgr->SetThreadLoopClass(NfThread(this, s).CreateForNewThread());
318  if (m_pts.size() < 10000)
319  mgr->ExplicitlySetNumThreads(2);
320  mgr->SetObserver(m_prog);
321  mgr->RunThreads((int)m_pts.size());
322  }
323  else
324  {
325  BSHP<GmPtSearch> ps = m_ptSearch;
326  std::vector<int> nearestPts;
327  std::vector<InterpPtInfo> matrixPts;
328  std::vector<double> d2, w;
329  for (size_t i = 0; i < m_pts.size(); ++i)
330  {
331  NfForPt((int)i, ps, nearestPts, matrixPts, d2, w);
332  }
333  }
334 } // NodalFuncImpl::ComputeNodalFuncs
335 //------------------------------------------------------------------------------
343 //------------------------------------------------------------------------------
344 void NodalFuncImpl::NfForPt(int a_ptIdx,
345  BSHP<GmPtSearch> s,
346  std::vector<int>& nearestPts,
347  std::vector<InterpPtInfo>& matrixPts,
348  std::vector<double>& d2,
349  std::vector<double>& w)
350 {
351  const Pt3d& p = m_pts[a_ptIdx];
352  // get the nNearest points to this point
353  if (m_nNearest < 1)
354  {
355  nearestPts = m_nearestAll;
356  // remove my index from nearest vector
357  nearestPts.erase(nearestPts.begin() + a_ptIdx);
358  }
359  else if (m_natNeigh)
360  m_natNeigh->GetNeighbors(a_ptIdx, nearestPts);
361  else
362  s->NearestPtsToPtInRtree(a_ptIdx, p, m_nNearest, m_quadOct, nearestPts);
363  // get the distance squared between our point and the other points
364  inDistanceSquared(p, nearestPts, m_pts, m_2d, d2);
366 
367  matrixPts.resize(nearestPts.size());
368  int idx;
369  for (size_t j = 0; j < nearestPts.size(); ++j)
370  {
371  idx = nearestPts[j];
372  matrixPts[j].m_loc = m_pts[idx];
373  matrixPts[j].m_weight = w[j];
374  matrixPts[j].m_scalar = m_scalar[idx];
375  }
376  NodalFuncForPtFromMatrixPts(a_ptIdx, matrixPts);
377 } // NodalFuncImpl::NfForPt
378 //------------------------------------------------------------------------------
382 //------------------------------------------------------------------------------
383 void NodalFuncImpl::NodalFuncForPtFromMatrixPts(int a_ptIdx, const std::vector<InterpPtInfo>& a_pts)
384 {
385  if (1 == m_type)
386  {
387  m_gradient[a_ptIdx] = ComputeGradientForPoint(a_ptIdx, a_pts);
388  }
389  else
390  {
391  double A[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
392  if (m_2d)
393  NodalFunc2d(a_ptIdx, a_pts, A);
394  else
395  NodalFunc3d(a_ptIdx, a_pts, A);
396  for (int i = 0; i < 9; ++i)
397  m_quadratic[a_ptIdx][i] = A[i];
398  }
399 } // NodalFuncImpl::ComputeNodalFuncForPt
400 //------------------------------------------------------------------------------
405 //------------------------------------------------------------------------------
406 void NodalFuncImpl::NodalFunc2d(int a_ptIdx, const std::vector<InterpPtInfo>& a_pts, double* a_A)
407 {
408  const Pt3d& p = m_pts[a_ptIdx];
409  double *M[9], VV[9], *A(a_A), m[9][9];
410  for (int i = 0; i < 9; ++i)
411  M[i] = &m[i][0];
412  // set up matrix for computing gradients
413  inNodalFuncSetUpMatrixAndVector(p.x, p.y, m_scalar[a_ptIdx], a_pts, M, VV);
414  if (!mxSolveBandedEquations(M, A, VV, 5, 5))
415  {
416  boost::mutex mtx;
417  mtx.lock();
418  m_errorReport = true;
419  std::string msg =
420  "Error computing nodal functions. Increase the number "
421  "of points used for nodal function calculation.";
422  XM_LOG(xmlog::error, msg);
423  mtx.unlock();
424  }
425 } // NodalFuncImpl::NodalFunc2d
426 //------------------------------------------------------------------------------
431 //------------------------------------------------------------------------------
432 void NodalFuncImpl::NodalFunc3d(int a_ptIdx, const std::vector<InterpPtInfo>& a_pts, double* a_A)
433 {
434  const Pt3d& p = m_pts[a_ptIdx];
435  double *M[10], VV[10], *A(a_A), m[10][10];
436  for (int i = 0; i < 10; ++i)
437  M[i] = &m[i][0];
438  // set up matrix for computing gradients
439  inNodalFuncSetUpMatrixAndVector3d(p.x, p.y, p.z, m_scalar[a_ptIdx], a_pts, M, VV);
440  if (!mxSolveBandedEquations(M, A, VV, 9, 9))
441  {
442  boost::mutex mtx;
443  mtx.lock();
444  m_errorReport = true;
445  std::string msg =
446  "Error computing nodal functions. Increase the number "
447  "of points used for nodal function calculation.";
448  XM_LOG(xmlog::error, msg);
449  mtx.unlock();
450  }
451 } // NodalFuncImpl::NodalFunc2d
452 //------------------------------------------------------------------------------
457 //------------------------------------------------------------------------------
458 Pt3d NodalFuncImpl::ComputeGradientForPoint(int a_ptIdx, const std::vector<InterpPtInfo>& a_pts)
459 {
460  Pt3d grad;
461  if (m_2d)
462  {
463  double A[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
464  NodalFunc2d(a_ptIdx, a_pts, A);
465  grad.x = A[0];
466  grad.y = A[1];
467  return grad;
468  }
469 
470  // 3D
471  double A[3][3], x[3], B[3], *Aptr[3];
472  for (int i = 0; i < 3; ++i)
473  {
474  Aptr[i] = &A[i][0];
475  x[i] = B[i] = 0;
476  for (int j = 0; j < 3; ++j)
477  A[i][j] = 0;
478  }
479 
480  const Pt3d& p = m_pts[a_ptIdx];
481  double dx, dy, dz(0), df, weight;
482  for (size_t i = 0; i < a_pts.size(); ++i)
483  {
484  weight = a_pts[i].m_weight;
485  dx = a_pts[i].m_loc.x - p.x;
486  dy = a_pts[i].m_loc.y - p.y;
487  if (!m_2d)
488  dz = a_pts[i].m_loc.z - p.z;
489  df = a_pts[i].m_scalar - m_scalar[a_ptIdx];
490 
491  A[0][0] += weight * dx * dx;
492  A[0][1] += weight * dx * dy;
493  A[0][2] += weight * dx * dz;
494  A[1][1] += weight * dy * dy;
495  A[1][2] += weight * dy * dz;
496  A[2][2] += weight * dz * dz;
497 
498  B[0] += weight * df * dx;
499  B[1] += weight * df * dy;
500  B[2] += weight * df * dz;
501  }
502  A[1][0] = A[0][1];
503  A[2][0] = A[0][2];
504  A[2][1] = A[1][2];
505 
506  bool err = false;
507  if (m_2d)
508  err = !mxSolveNxN(&Aptr[0], x, B, 2);
509  else
510  err = !mxSolve3x3(A, x, B);
511  if (err || m_debugTest)
512  {
513  if (B[0] == 0.0 && B[1] == 0.0 && B[2] == 0.0)
514  { // ds was probably zero which is OK. Apply the zero or trivial solution
515  x[0] = x[1] = x[2] = 0.0;
516  }
517  else if (!m_errorReport)
518  {
519  boost::mutex mtx;
520  mtx.lock();
521  m_errorReport = true;
522  std::string msg =
523  "Error computing nodal functions. Increase the number "
524  "of points used for nodal function calculation.";
525  XM_LOG(xmlog::error, msg);
526  mtx.unlock();
527  }
528  }
529  grad.x = x[0];
530  grad.y = x[1];
531  grad.z = x[2];
532  return grad;
533 } // NodalFuncImpl::ComputeGradientForPoint
534 //------------------------------------------------------------------------------
541 //------------------------------------------------------------------------------
542 double NodalFuncImpl::ScalarFromPtIdx(int a_ptIdx, const Pt3d& a_loc) const
543 {
544  if (1 == m_type)
545  {
546  if (m_2d)
547  {
548  double dc, qi;
549  dc = m_gradient[a_ptIdx].x * m_pts[a_ptIdx].x + m_gradient[a_ptIdx].y * m_pts[a_ptIdx].y -
550  m_scalar[a_ptIdx];
551  qi = m_gradient[a_ptIdx].x * a_loc.x + m_gradient[a_ptIdx].y * a_loc.y - dc;
552  return qi;
553  }
554 
555  double f;
556  f = m_scalar[a_ptIdx] + m_gradient[a_ptIdx].x * (a_loc.x - m_pts[a_ptIdx].x) +
557  m_gradient[a_ptIdx].y * (a_loc.y - m_pts[a_ptIdx].y) +
558  m_gradient[a_ptIdx].z * (a_loc.z - m_pts[a_ptIdx].z);
559  return f;
560  }
561  else
562  {
563  double fi = (double)m_scalar[a_ptIdx];
564  double qi, dx, dy, dz;
565  dx = a_loc.x - m_pts[a_ptIdx].x;
566  dy = a_loc.y - m_pts[a_ptIdx].y;
567  if (m_2d)
568  {
569  qi = fi + m_quadratic[a_ptIdx][0] * dx + m_quadratic[a_ptIdx][1] * dy +
570  m_quadratic[a_ptIdx][2] * dx * dx + m_quadratic[a_ptIdx][3] * dx * dy +
571  m_quadratic[a_ptIdx][4] * dy * dy;
572  return qi;
573  }
574 
575  dz = a_loc.z - m_pts[a_ptIdx].z;
576  qi = fi + m_quadratic[a_ptIdx][0] * dx + m_quadratic[a_ptIdx][1] * dy +
577  m_quadratic[a_ptIdx][2] * dz + m_quadratic[a_ptIdx][3] * dx * dy +
578  m_quadratic[a_ptIdx][4] * dx * dz + m_quadratic[a_ptIdx][5] * dy * dz +
579  m_quadratic[a_ptIdx][6] * dx * dx + m_quadratic[a_ptIdx][7] * dy * dy +
580  m_quadratic[a_ptIdx][8] * dz * dz;
581  return qi;
582  }
583 } // NodalFuncImpl::ScalarFromPtIdx
584 //------------------------------------------------------------------------------
588 //------------------------------------------------------------------------------
589 void NodalFuncImpl::GradientFromPtIdx(int a_ptIdx, Pt3d& a_grad) const
590 {
591  if (a_ptIdx > 0 && a_ptIdx < (int)m_gradient.size())
592  a_grad = m_gradient[a_ptIdx];
593 } // NodalFuncImpl::GradientFromPtIdx
594 //------------------------------------------------------------------------------
597 //------------------------------------------------------------------------------
598 std::string NodalFuncImpl::ToString() const
599 {
600  std::stringstream ss;
601  ss << m_2d << "=2d " << m_type << "=type " << m_nNearest << "=nNearest " << m_quadOct
602  << "=quadOct " << m_power << "=power " << m_modifiedShepardWeights
603  << "=modifiedShepardWeights " << m_errorReport << "=errorReport " << m_debugTest
604  << "=debugTest "
605  << "\n";
606 
607  VecToStream(ss, m_pts, "pts");
608  VecToStream(ss, m_scalar, "scalar");
609  VecToStream(ss, m_gradient, "gradient");
610  for (size_t j = 0; j < m_quadratic.size(); ++j)
611  {
612  VecToStream(ss, m_quadratic[j], "quadratic");
613  }
614  ss << "=quadratic "
615  << "\n";
616 
617  VecToStream(ss, m_nearestAll, "nearestAll");
618 
619  return ss.str();
620 } // NodalFuncImpl::ToString
621 
622 } // namespace xms
623 
624 #ifdef CXX_TEST
625 
629 
630 // namespace xms {
631 using namespace xms;
636 //------------------------------------------------------------------------------
638 //------------------------------------------------------------------------------
640 {
641  BSHP<GmPtSearch> pts;
642  std::vector<Pt3d> vPts;
643  std::vector<float> vScalar;
644  BSHP<NodalFunc> nf =
645  NodalFunc::New(0, true, pts, vPts, vScalar, -1, false, 2, true, nullptr, nullptr);
646  TS_ASSERT(nf);
647 } // NodalFuncUnitTests::testCreateClass
648 //------------------------------------------------------------------------------
650 //------------------------------------------------------------------------------
652 {
653  std::vector<Pt3d> p(1, Pt3d(0, 0, 0));
654  std::vector<float> s(1, 0);
655  NodalFuncImpl nf(p, s);
656  nf.m_2d = false;
657  std::vector<InterpPtInfo> pInfo(2);
658  pInfo[0].m_loc = Pt3d(1, 0, 0);
659  pInfo[0].m_scalar = 0;
660  pInfo[0].m_weight = .5;
661  pInfo[1].m_loc = Pt3d(2, 0, 0);
662  pInfo[1].m_scalar = 0;
663  pInfo[1].m_weight = .5;
664  Pt3d grad = nf.ComputeGradientForPoint(0, pInfo);
665  TS_ASSERT_EQUALS(Pt3d(0, 0, 0), grad);
666  pInfo[0].m_scalar = 1;
667  pInfo[1].m_scalar = 2;
669  grad = nf.ComputeGradientForPoint(0, pInfo);
670  TS_ASSERT_EQUALS(true, (XmLog::Instance().ErrCount() != 0));
672 } // NodalFuncUnitTests::testComputeGradientForPoint
673 
674 //} // namespace xms
675 #endif // CXX_TEST
NfThread(NodalFuncImpl *a_nf, BSHP< GmPtSearch > a_ptSearch)
constructor
Definition: NodalFunc.cpp:61
virtual int GetType() const override
get the nodal function type 1 = gradient plane, 2 = quadratic
Definition: NodalFunc.cpp:112
#define XM_LOG(A, B)
virtual int GetNearestPointsOption() const override
get the nearest points option 0 = nearest points, 1 = natural neighbors
Definition: NodalFunc.cpp:115
virtual void ComputeNodalFuncs() override
Computes gradients at each point for use in the interpolation process.
Definition: NodalFunc.cpp:308
std::vector< InterpPtInfo > m_matrixPts
information about each point for nodal function calculation
Definition: NodalFunc.cpp:80
VecDbl m_w
weight for each point
Definition: NodalFunc.cpp:82
Implementation of NodalFunc.
Definition: NodalFunc.cpp:48
std::vector< int > VecInt
NodalFunc()
Constructor.
Definition: NodalFunc.cpp:208
std::vector< Pt3d > m_gradient
Calculated gradient coefficients at each point.
Definition: NodalFunc.cpp:150
virtual double ScalarFromPtIdx(int a_ptIdx, const Pt3d &a_loc) const override
Computes gradients at each point for use in the interpolation process.
Definition: NodalFunc.cpp:542
int m_type
1 gradient plane, 2 quadratic
Definition: NodalFunc.cpp:144
void testCreateClass()
test class creation
Definition: NodalFunc.cpp:639
InterpNatNeigh * m_natNeigh
Definition: NodalFunc.cpp:161
Pt3d ComputeGradientForPoint(int a_ptIdx, const std::vector< InterpPtInfo > &a_pts)
Computes the gradient for this point.
Definition: NodalFunc.cpp:458
std::vector< double > VecDbl
virtual int GetNumNearestPoints() const override
get the number of nearest points used in the nodal function calculation
Definition: NodalFunc.cpp:123
virtual void GradientFromPtIdx(int a_ptIdx, Pt3d &a_grad) const override
Fills in the gradient.
Definition: NodalFunc.cpp:589
static BSHP< NodalFunc > New(int a_type, bool a_2d, boost::shared_ptr< GmPtSearch > a_ptSearch, const std::vector< Pt3d > &a_pts, const std::vector< float > &a_scalar, int a_nNearest, bool a_quad_oct, double a_power, bool a_modifiedShepardWeights, boost::shared_ptr< Observer > a_p, InterpNatNeigh *a_natNeigh)
Creates a NodalFunc class.
Definition: NodalFunc.cpp:188
void NodalFunc2d(int a_ptIdx, const std::vector< InterpPtInfo > &a_pts, double *a_A)
Computes the matrix for the passed in point.
Definition: NodalFunc.cpp:406
int CurrIdx()
Returns the current index of the thread.
Definition: ThreadLoop.cpp:89
VecDbl2d m_quadratic
Calculated quadratic coefficients at each point.
Definition: NodalFunc.cpp:151
BSHP< GmPtSearch > m_ptSearch
spatial index for searching points
Definition: NodalFunc.cpp:77
void NfForPt(int a_ptIdx, BSHP< GmPtSearch > a_s, std::vector< int > &nearestPts, std::vector< InterpPtInfo > &matrixPts, std::vector< double > &d2, std::vector< double > &w)
Computes the nodal function for this point.
Definition: NodalFunc.cpp:344
void VecToStream(std::stringstream &a_ss, const T &a_v, std::string a_label)
VecInt m_nearestPts
indexes of nearest points to location
Definition: NodalFunc.cpp:78
bool m_errorReport
flag for reporting errors
Definition: NodalFunc.cpp:157
std::vector< int > m_nearestAll
convenience variable when all points are used in calculation
Definition: NodalFunc.cpp:155
bool m_modifiedShepardWeights
Definition: NodalFunc.cpp:153
BSHP< Observer > m_prog
Observer that reports status of interpolation process.
Definition: NodalFunc.cpp:156
BSHP< GmPtSearch > m_ptSearch
Class used to find nearest points.
Definition: NodalFunc.cpp:149
void NodalFuncForPtFromMatrixPts(int a_ptIdx, const std::vector< InterpPtInfo > &a_pts)
Computes the nodal function for this point.
Definition: NodalFunc.cpp:383
std::string GetAndClearStackStr()
Thread worker class.
Definition: ThreadLoop.h:23
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.
Definition: InterpUtil.cpp:50
static BSHP< ThreadMgr > New()
Creates a ThreadMgr.
Definition: ThreadMgr.cpp:105
virtual bool GetUseModifiedShepardWeights() const override
get the option for using Modified Shepard Weights
Definition: NodalFunc.cpp:126
bool m_2d
flag for computing distances in xy instead of xyz
Definition: NodalFunc.cpp:143
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.
Definition: InterpUtil.cpp:126
virtual std::string ToString() const override
Write the internals to a string.
Definition: NodalFunc.cpp:598
void Worker() override
Calculates the nodal function in this thread.
Definition: NodalFunc.cpp:85
VecDbl m_d2
distance squared from location to each point
Definition: NodalFunc.cpp:81
const std::vector< float > & m_scalar
Scalars at the points used to interpolate.
Definition: NodalFunc.cpp:148
const std::vector< Pt3d > & m_pts
Points used to interpolate.
Definition: NodalFunc.cpp:147
void NodalFunc3d(int a_ptIdx, const std::vector< InterpPtInfo > &a_pts, double *a_A)
Computes the matrix for the passed in point.
Definition: NodalFunc.cpp:432
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...
Definition: InterpUtil.cpp:266
virtual bool GetUseQuadrantSearch() const override
get the option for using a quadrant (octant in 3d) search for the nearest points
Definition: NodalFunc.cpp:129
void testComputeGradientForPoint()
test computing a gradient
Definition: NodalFunc.cpp:651
double m_power
exponent used with inverse distance (1/d^m_power)
Definition: NodalFunc.cpp:152
std::vector< VecDbl > VecDbl2d
static XmLog & Instance(bool a_delete=false, XmLog *a_new=NULL)
int m_nNearest
number of nearest points to consider in calculations
Definition: NodalFunc.cpp:145
virtual ~NodalFunc()
Destructor.
Definition: NodalFunc.cpp:214
Class to compute gradient plane and quadratic nodal functions for interpolation.
Definition: NodalFunc.h:30
bool m_quadOct
flag for performing quadrant(2d) or octant (3d) searching for nearest pts
Definition: NodalFunc.cpp:146
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...
Definition: InterpUtil.cpp:305
NodalFuncImpl(const std::vector< Pt3d > &a_pts, const std::vector< float > &a_scalar)
this constructor is only used with testing
Definition: NodalFunc.cpp:226
BSHP< ThreadLoop > CreateForNewThread() override
Creates an instance of this class for the thread manager.
Definition: NodalFunc.cpp:69
Class that performs natural neighbor interpolation.
NodalFuncImpl * m_nf
pointer to parent class
Definition: NodalFunc.cpp:76
Threading class to compute nodal functions in parallel.
Definition: NodalFunc.cpp:55