xmsinterp  1.0
InterpLinear.cpp
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
8 //------------------------------------------------------------------------------
9 
10 //----- Included files ---------------------------------------------------------
11 
12 // 1. Precompiled header
13 
14 // 2. My header
16 
17 // 3. Standard Library Headers
18 #include <cfloat>
19 #include <sstream>
20 
21 // 4. External Library Headers
22 
23 // 5. Shared Headers
24 #include <xmscore/math/math.h>
25 #include <xmsgrid/geometry/GmPtSearch.h>
26 #include <xmsgrid/geometry/GmTriSearch.h>
31 #include <xmscore/stl/utility.h>
32 #include <xmscore/misc/XmError.h>
33 #include <xmscore/misc/xmstype.h>
34 
35 // 6. Non-shared Headers
36 
37 //----- Forward declarations ---------------------------------------------------
38 
39 //----- External globals -------------------------------------------------------
40 
41 //----- Namespace declaration --------------------------------------------------
42 namespace xms
43 {
44 //----- Constants / Enumerations -----------------------------------------------
45 
46 //----- Classes / Structs ------------------------------------------------------
47 
51 {
52 public:
54  virtual ~InterpLinearImpl();
55 
56  virtual void SetPtsTris(BSHP<VecPt3d> a_, BSHP<VecInt> a_tris) override;
57 
58  virtual void SetScalars(const float* a_scalar, size_t a_n) override;
59  virtual void SetScalars(BSHP<VecFlt> a_scalar) override;
60  virtual void SetPtActivity(DynBitset& a_activity) override;
61  // bitset is number of triangles in length not numtri*3 like the tris array
62  virtual void SetTriActivity(DynBitset& a_activity) override;
63  virtual const BSHP<VecPt3d> GetPts() const override;
64  virtual const BSHP<VecInt> GetTris() const override;
65  virtual const BSHP<VecFlt> GetScalars() const override;
66  virtual DynBitset GetPtActivity() const override;
67  virtual DynBitset GetTriActivity() const override;
68  virtual VecInt GetExtrapolationPointIndexes() const override;
69 
70  virtual float InterpToPt(const Pt3d& a_pt) override;
71  float InterpToPtImpl(const Pt3d& a_pt, int a_ptIdx);
72  virtual void InterpToPts(const VecPt3d& a_pts, VecFlt& a_scalars) override;
73 
74  // find triangle
75  virtual int TriContainingPt(const Pt3d& a_pt) override;
76  virtual void TriEnvelopsContainingPt(const Pt3d& a_pt, VecInt& a_tris) override;
77  // interpolation
78  virtual bool InterpWeights(const Pt3d& a_pt, VecInt& a_idxs, VecDbl& a_wts) override;
79 
80  float CloughTocherInterp(VecInt& a_idxs, const Pt3d& a_pt);
81  float NatNeighInterp(const Pt3d& a_pt);
82  // interpolation options
83  virtual void SetExtrapVal(double a_val) override;
84  virtual void SetTrunc(double a_sMax, double a_sMin) override;
85  virtual void SetUseCloughTocher(bool a_, BSHP<Observer> a_prog) override;
86  virtual void SetUseNatNeigh(bool a_,
87  int a_nodalFunc,
88  int a_ndFuncOpt,
89  int a_ndFuncNumNearestPts,
90  bool a_blendWeights,
91  BSHP<Observer> a_prog) override;
92 
95  virtual double GetExtrapVal() const override { return m_extrap; }
98  virtual bool GetTruncateInterpolatedValues() const override { return m_trunc; }
101  virtual double GetTruncMin() const override { return m_truncMin; }
104  virtual double GetTruncMax() const override { return m_truncMax; }
107  virtual bool GetUseCloughTocher() const override { return m_cloughTocher; }
110  virtual bool GetUseNatNeigh() const override { return m_natNeigh; }
113  virtual int GetNatNeighNodalFunc() const override
114  {
115  if (!m_nodal)
116  return 0;
117  return m_nodal->GetType();
118  }
122  virtual int GetNatNeighNodalFuncNearestPtsOption() const override
123  {
124  if (!m_nodal)
125  return 0;
126  return m_nodal->GetNearestPointsOption();
127  }
131  virtual int GetNatNeighNodalFuncNumNearestPts() const override
132  {
133  if (!m_nodal)
134  return 0;
135  return m_nodal->GetNumNearestPoints();
136  }
139  virtual bool GetNatNeighBlendWeights() const override
140  {
141  if (!m_nodal)
142  return false;
143  return m_nodal->GetUseModifiedShepardWeights();
144  }
145 
146 
147  BSHP<GmPtSearch> CreatePtSearch();
148  void RecalcNodalFunc();
149  virtual std::string ToString() const override;
150 
151 protected:
152  BSHP<GmTriSearch> m_triSearch;
153  BSHP<VecPt3d> m_pts;
154  BSHP<VecInt> m_tris;
155  BSHP<VecFlt> m_scalar;
156  double m_extrap;
157  bool m_trunc;
158  double m_truncMax;
159  double m_truncMin;
161  bool m_natNeigh;
162  BSHP<NodalFunc> m_nodal;
163  BSHP<InterpCt> m_ct;
164  BSHP<InterpNatNeigh> m_nn;
166 };
167 
168 //----- Internal functions -----------------------------------------------------
169 
170 //----- Class / Function definitions -------------------------------------------
171 
172 //------------------------------------------------------------------------------
175 //------------------------------------------------------------------------------
176 BSHP<InterpLinear> InterpLinear::New()
177 {
178  BSHP<InterpLinear> ptr(new InterpLinearImpl());
179  return ptr;
180 } // InterpLinear::New
181 //------------------------------------------------------------------------------
183 //------------------------------------------------------------------------------
184 InterpLinear::InterpLinear()
185 {
186 } // InterpLinear::InterpLinear
187 //------------------------------------------------------------------------------
189 //------------------------------------------------------------------------------
190 InterpLinear::~InterpLinear()
191 {
192 } // InterpLinear::~InterpLinear
193 
199 //------------------------------------------------------------------------------
201 //------------------------------------------------------------------------------
202 InterpLinearImpl::InterpLinearImpl()
203 : m_triSearch(GmTriSearch::New())
204 , m_pts(new VecPt3d())
205 , m_tris(new VecInt())
206 , m_scalar(new VecFlt())
207 , m_extrap(XM_NODATA)
208 , m_trunc(false)
209 , m_truncMax(0.0)
210 , m_truncMin(0.0)
211 , m_cloughTocher(false)
212 , m_natNeigh(false)
213 {
214 } // InterpLinearImpl::InterpLinearImpl
215 //------------------------------------------------------------------------------
217 //------------------------------------------------------------------------------
218 InterpLinearImpl::~InterpLinearImpl()
219 {
220 } // InterpLinearImpl::~InterpLinearImpl
221 //------------------------------------------------------------------------------
228 //------------------------------------------------------------------------------
229 void InterpLinearImpl::SetPtsTris(BSHP<VecPt3d> a_pts, BSHP<VecInt> a_tris)
230 {
231  m_pts = a_pts;
232  m_tris = a_tris;
233  m_scalar->assign(m_pts->size(), 0);
234  for (size_t i = 0; i < m_pts->size(); ++i)
235  (*m_scalar)[i] = (float)(*m_pts)[i].z;
236  m_triSearch->TrisToSearch(a_pts, a_tris);
237 } // InterpLinearImpl::SetPtsTris
238 //------------------------------------------------------------------------------
242 //------------------------------------------------------------------------------
243 void InterpLinearImpl::SetScalars(const float* a_scalar, size_t a_n)
244 {
245  XM_ENSURE_TRUE(a_n == m_pts->size());
246  m_scalar->assign(&a_scalar[0], &a_scalar[a_n]);
247  RecalcNodalFunc();
248 } // InterpLinearImpl::SetScalars
249 //------------------------------------------------------------------------------
252 //------------------------------------------------------------------------------
253 void InterpLinearImpl::SetScalars(BSHP<VecFlt> a_scalar)
254 {
255  XM_ENSURE_TRUE(a_scalar->size() == m_pts->size());
256  m_scalar = a_scalar;
257  RecalcNodalFunc();
258 } // InterpLinear::SetScalars
259 //------------------------------------------------------------------------------
262 //------------------------------------------------------------------------------
264 {
265  m_triSearch->SetPtActivity(a_activity);
266  RecalcNodalFunc();
267 } // InterpLinearImpl::SetPtActivity
268 //------------------------------------------------------------------------------
271 //------------------------------------------------------------------------------
273 {
274  m_triSearch->SetTriActivity(a_activity);
275  RecalcNodalFunc();
276 } // InterpLinearImpl::SetTriActivity
277 //------------------------------------------------------------------------------
280 //------------------------------------------------------------------------------
281 const BSHP<VecPt3d> InterpLinearImpl::GetPts() const
282 {
283  return m_pts;
284 } // InterpLinearImpl::GetPts
285 //------------------------------------------------------------------------------
288 //------------------------------------------------------------------------------
289 const BSHP<VecInt> InterpLinearImpl::GetTris() const
290 {
291  return m_tris;
292 } // InterpLinearImpl::GetTris
293 //------------------------------------------------------------------------------
296 //------------------------------------------------------------------------------
297 const BSHP<VecFlt> InterpLinearImpl::GetScalars() const
298 {
299  return m_scalar;
300 } // InterpLinearImpl::GetScalars
301 //------------------------------------------------------------------------------
304 //------------------------------------------------------------------------------
306 {
307  return m_triSearch->GetPtActivity();
308 } // InterpLinearImpl::GetPtActivity
309 //------------------------------------------------------------------------------
312 //------------------------------------------------------------------------------
314 {
315  return m_triSearch->GetTriActivity();
316 } // InterpLinearImpl::GetTriActivity
317 //------------------------------------------------------------------------------
321 //------------------------------------------------------------------------------
323 {
325 } // InterpLinearImpl::GetExtrapolationPointIndexes
326 //------------------------------------------------------------------------------
331 //------------------------------------------------------------------------------
333 {
334  return InterpToPtImpl(a_pt, 0);
335 } // InterpLinearImpl::InterpToPt
336 //------------------------------------------------------------------------------
342 //------------------------------------------------------------------------------
343 float InterpLinearImpl::InterpToPtImpl(const Pt3d& a_pt, int a_ptIdx)
344 {
345  // return m_triSearch->InterpToPt(a_pt);
346  float rval((float)m_extrap);
347  VecInt idxs(3, 0);
348  VecDbl wts(3, 0);
349  if (m_triSearch->InterpWeights(a_pt, idxs, wts))
350  {
351  float* s = &(*m_scalar)[0];
352  rval = (float)((s[idxs[0]] * wts[0]) + (s[idxs[1]] * wts[1]) + (s[idxs[2]] * wts[2]));
353  if (m_cloughTocher || m_natNeigh)
354  {
355  if (EQ_TOL(wts[0], 1, FLT_EPSILON) || EQ_TOL(wts[1], 1, FLT_EPSILON) ||
356  EQ_TOL(wts[2], 1, FLT_EPSILON))
357  {
358  }
359  else
360  {
361  if (m_cloughTocher)
362  {
363  rval = CloughTocherInterp(idxs, a_pt);
364  }
365  else
366  rval = NatNeighInterp(a_pt);
367  }
368  }
369  }
370  else
371  {
372  m_extrapolationPointIndexes.push_back(a_ptIdx);
373  }
374  if (m_trunc)
375  {
376  if (rval < m_truncMin)
377  rval = (float)m_truncMin;
378  if (rval > m_truncMax)
379  rval = (float)m_truncMax;
380  }
381  return rval;
382 } // InterpLinearImpl::InterpToPt
383 //-----------------------------------------------------------------------------
387 //-----------------------------------------------------------------------------
388 void InterpLinearImpl::InterpToPts(const VecPt3d& a_pts, VecFlt& a_scalars)
389 {
390  // m_triSearch->InterpToPts(a_pts, a_scalars);
392  a_scalars.assign(a_pts.size(), 0);
393  for (size_t i = 0; i < a_pts.size(); i++)
394  {
395  a_scalars[i] = InterpToPtImpl(a_pts[i], static_cast<int>(i));
396  }
397 } // InterpLinearImpl::InterpToPts
398 //------------------------------------------------------------------------------
403 //------------------------------------------------------------------------------
405 {
406  return m_triSearch->TriContainingPt(a_pt);
407 } // InterpLinearImpl::TriContainingPt
408 //------------------------------------------------------------------------------
412 //------------------------------------------------------------------------------
414 {
415  m_triSearch->TriEnvelopsContainingPt(a_pt, a_tris);
416 } // InterpLinearImpl::TriContainingPt
417 //------------------------------------------------------------------------------
424 //------------------------------------------------------------------------------
425 bool InterpLinearImpl::InterpWeights(const Pt3d& a_pt, VecInt& a_idxs, VecDbl& a_wts)
426 {
427  return m_triSearch->InterpWeights(a_pt, a_idxs, a_wts);
428 } // InterpLinearImpl::InterpWeights
429 //------------------------------------------------------------------------------
435 //------------------------------------------------------------------------------
437 {
438  m_ct->ComputeCtCoeff(&a_idxs[0]);
439  return (float)(m_ct->InterpToPt(a_pt));
440 } // InterpLinearImpl::CloughTocherInterp
441 //------------------------------------------------------------------------------
446 //------------------------------------------------------------------------------
448 {
449  return m_nn->InterpToPt(a_pt);
450 } // InterpLinearImpl::NatNeighInterp
451 //------------------------------------------------------------------------------
454 //------------------------------------------------------------------------------
456 {
457  m_extrap = a_val;
458 } // InterpLinearImpl::SetExtrapVal
459 //------------------------------------------------------------------------------
464 //------------------------------------------------------------------------------
465 void InterpLinearImpl::SetTrunc(double a_sMax, double a_sMin)
466 {
467  m_trunc = true;
468  m_truncMax = a_sMax;
469  m_truncMin = a_sMin;
470 } // InterpLinearImpl::SetTrunc
471 //------------------------------------------------------------------------------
477 //------------------------------------------------------------------------------
478 void InterpLinearImpl::SetUseCloughTocher(bool a_, BSHP<Observer> a_prog)
479 {
480  // m_triSearch->SetUseCloughTocher(a_, a_prog);
481  m_cloughTocher = a_;
482  if (!m_cloughTocher)
483  return;
484 
485  BSHP<GmPtSearch> pts = CreatePtSearch();
486  int nodalfunc(1), nearest(16);
487  bool twod(true), quad_oct(false), modifiedShepardWeights(true);
488  double dPower(2);
489  m_nodal.reset();
490  if (!inAllScalarsEqual(*m_scalar, m_triSearch->GetPtActivity()) && m_pts->size() > 6)
491  {
492  m_nodal = NodalFunc::New(nodalfunc, twod, pts, *m_pts, *m_scalar, nearest, quad_oct, dPower,
493  modifiedShepardWeights, a_prog, nullptr);
494  }
495  m_ct.reset(new InterpCt(*m_pts, m_nodal));
496 } // InterpLinearImpl::SetUseCloughTocher
497 //------------------------------------------------------------------------------
509 //------------------------------------------------------------------------------
511  int a_nodalFunc,
512  int a_ndFuncOpt,
513  int a_ndFuncNumNearestPts,
514  bool a_blendWeights,
515  BSHP<Observer> a_prog)
516 {
517  m_natNeigh = a_;
518  if (!m_natNeigh)
519  return;
520 
522  m_nn->SetBlendWeights(a_blendWeights);
523 
524  if (0 != a_nodalFunc && !inAllScalarsEqual(*m_scalar, m_triSearch->GetPtActivity()))
525  {
526  int nearest(a_ndFuncNumNearestPts);
527  bool twod(true), quad_oct(false), modifiedShepardWeights(true);
528  double dPower(2);
529  InterpNatNeigh* nnPtr(nullptr);
530  BSHP<GmPtSearch> pts;
531  if (0 != a_ndFuncOpt)
532  pts = CreatePtSearch();
533  else
534  nnPtr = m_nn.get();
535 
536  m_nodal = NodalFunc::New(a_nodalFunc, twod, pts, *m_pts, *m_scalar, nearest, quad_oct, dPower,
537  modifiedShepardWeights, a_prog, nnPtr);
538  m_nn->SetNodalFunc(m_nodal);
539  }
540 } // InterpLinearImpl::SetUseNatNeigh
541 //------------------------------------------------------------------------------
544 //------------------------------------------------------------------------------
546 {
547  BSHP<GmPtSearch> pts = GmPtSearch::New(true);
548  pts->PtsToSearch(m_pts);
549  DynBitset b = m_triSearch->GetPtActivity();
550  pts->SetActivity(b);
551  return pts;
552 } // InterpLinearImpl::CreatePtSearch
553 //------------------------------------------------------------------------------
555 //------------------------------------------------------------------------------
557 {
558  if (m_nn)
559  m_nn->RecalcNodalFunc();
560  else if (m_ct)
561  m_ct->RecalcNodalFunc();
562 } // InterpLinearImpl::RecalcNodalFunc
563 //------------------------------------------------------------------------------
566 //------------------------------------------------------------------------------
567 std::string InterpLinearImpl::ToString() const
568 {
569  std::stringstream ss;
570  ss << m_cloughTocher << "=cloughTocher " << m_natNeigh << "=natNeigh " << m_trunc << "=trunc "
571  << m_truncMax << "=truncMax " << m_truncMin << "=truncMin " << m_extrap << "=extrap "
572  << "\n";
573  if (m_triSearch)
574  {
575  ss << m_triSearch->ToString();
576  ss << "=triSearch "
577  << "\n";
578  }
579  if (m_pts)
580  VecToStream(ss, *m_pts, "pts");
581  if (m_tris)
582  VecToStream(ss, *m_tris, "tris");
583  if (m_scalar)
584  VecToStream(ss, *m_scalar, "scalar");
585  if (m_nodal)
586  {
587  ss << m_nodal->ToString();
588  ss << "=nodal "
589  << "\n";
590  }
591  if (m_ct)
592  {
593  ss << m_ct->ToString();
594  ss << "=ct "
595  << "\n";
596  }
597  if (m_nn)
598  {
599  ss << m_nn->ToString();
600  ss << "=nn "
601  << "\n";
602  }
603  ss << "\n";
604  return ss.str();
605 } // InterpLinearImpl::ToString
606 
607 } // namespace xms
608 
609 #ifdef CXX_TEST
610 
613 
614 // namespace xms {
615 using namespace xms;
616 
621 //------------------------------------------------------------------------------
623 //------------------------------------------------------------------------------
625 {
626 #if 0
627  BSHP<InterpLinear> interpolator = InterpLinear::New();
628  std::string s = interpolator->ToString();
629  std::string expected = "0=cloughTocher 0=natNeigh 0=trunc 0=truncMax 0=truncMin 3.40282e+038,3.40282e+038,3.40282e+038=min -3.40282e+038,-3.40282e+038,-3.40282e+038=max -1e+007=extrap ";
630  TS_ASSERT_EQUALS(expected, s);
631 #endif
632 } // InterpLinearUnitTests::testToString
633 //------------------------------------------------------------------------------
635 //------------------------------------------------------------------------------
637 {
638  InterpLinearImpl linear;
639  BSHP<VecPt3d> p(new VecPt3d());
640  *p = {{0, 0, 1}, {1, 1, 1}, {1, 0, 1}};
641  BSHP<VecInt> t(new VecInt());
642  *t = {0, 2, 1};
643  linear.SetPtsTris(p, t);
644  const float EXTRAPVAL = (float)-3.12345678;
645  linear.SetExtrapVal((double)EXTRAPVAL);
646 
647  Pt3d pt(-.1, 0, 0);
648  // double val(0);
649  // outside the triangle
650  TS_ASSERT_DELTA(EXTRAPVAL, linear.InterpToPt(pt), FLT_EPSILON);
651  pt = Pt3d(-1e-6, 0, 0);
652  TS_ASSERT_DELTA(EXTRAPVAL, linear.InterpToPt(pt), FLT_EPSILON);
653  // inside the triangle
654  pt = Pt3d(.5, .25, 0);
655  TS_ASSERT_DELTA(1, linear.InterpToPt(pt), FLT_EPSILON);
656  pt = Pt3d(-1e-13, 0, 0);
657  TS_ASSERT_DELTA(1, linear.InterpToPt(pt), FLT_EPSILON);
658  // on each edge of the triangle
659  pt = Pt3d(.5, .5, 0);
660  TS_ASSERT_DELTA(1, linear.InterpToPt(pt), FLT_EPSILON);
661  pt = Pt3d(.5, 0, 0);
662  TS_ASSERT_DELTA(1, linear.InterpToPt(pt), FLT_EPSILON);
663  pt = Pt3d(1, .5, 0);
664  TS_ASSERT_DELTA(1, linear.InterpToPt(pt), FLT_EPSILON);
665  // at the points of the triangle
666  pt = Pt3d();
667  TS_ASSERT_DELTA(1, linear.InterpToPt(pt), FLT_EPSILON);
668  pt = Pt3d(1, 1, 0);
669  TS_ASSERT_DELTA(1, linear.InterpToPt(pt), FLT_EPSILON);
670  pt = Pt3d(1, 0, 0);
671  TS_ASSERT_DELTA(1, linear.InterpToPt(pt), FLT_EPSILON);
672 
673  VecInt idxes = linear.GetExtrapolationPointIndexes();
674  VecInt baseIdxes = { 0, 0 };
675  TS_ASSERT_EQUALS(baseIdxes, idxes);
676 
677  VecPt3d vPts = {{ .5, .5, 0 }, { -1, 0, 0 }, { -.5, 0, 0 }};
678  VecFlt scalar;
679  linear.InterpToPts(vPts, scalar);
680  idxes = linear.GetExtrapolationPointIndexes();
681  baseIdxes = { 1, 2 };
682  TS_ASSERT_EQUALS(baseIdxes, idxes);
683 } // InterpLinearUnitTests::testOneTriangle
684 //------------------------------------------------------------------------------
686 //------------------------------------------------------------------------------
688 {
689  InterpLinearImpl linear;
690  BSHP<VecPt3d> p(new VecPt3d());
691  *p = {{0, 0, 0}, {1, 1, 1}, {1, 0, 2}};
692  BSHP<VecInt> t(new VecInt());
693  *t = {0, 2, 1};
694  linear.SetPtsTris(p, t);
695 
696  Pt3d pt(.5, .5, 0);
697  // double val(0);
698  TS_ASSERT_DELTA(.5, linear.InterpToPt(pt), FLT_EPSILON);
699  pt = Pt3d(.5, 0, 0);
700  TS_ASSERT_DELTA(1, linear.InterpToPt(pt), FLT_EPSILON);
701  pt = Pt3d(1, .5, 0);
702  TS_ASSERT_DELTA(1.5, linear.InterpToPt(pt), FLT_EPSILON);
703  pt = Pt3d(.66666666666666666, .3333333333333333333, 0);
704  TS_ASSERT_DELTA(1, linear.InterpToPt(pt), FLT_EPSILON);
705 } // InterpLinearUnitTests::testInterp
706 //------------------------------------------------------------------------------
708 //------------------------------------------------------------------------------
710 {
711  InterpLinearImpl linear;
712  BSHP<VecPt3d> p(new VecPt3d());
713  *p = {{0, 0, 0}, {1, 1, 1}, {1, 0, 2}};
714  BSHP<VecInt> t(new VecInt());
715  *t = {0, 2, 1};
716  linear.SetPtsTris(p, t);
717 
718  Pt3d pt(.5, .5, 0);
719  linear.SetUseCloughTocher(true, BSHP<Observer>());
720  TS_ASSERT_DELTA(.5f, linear.InterpToPt(pt), 1e-7);
721  linear.SetTrunc(-1, 0);
722  TS_ASSERT_DELTA(-1.0f, linear.InterpToPt(pt), FLT_EPSILON);
723  pt.x = .5;
724  pt.y = .1;
725  TS_ASSERT_DELTA(-1.0f, linear.InterpToPt(pt), FLT_EPSILON);
726  pt.x = .2;
727  pt.y = .15;
728  TS_ASSERT_DELTA(-1.0f, linear.InterpToPt(pt), FLT_EPSILON);
729  pt.x = .9;
730  pt.y = .5;
731  TS_ASSERT_DELTA(-1.0f, linear.InterpToPt(pt), FLT_EPSILON);
732 } // InterpLinearUnitTests::testCt
733 
734 //} // namespace xms
735 #endif // CXX_TEST
virtual void TriEnvelopsContainingPt(const Pt3d &a_pt, VecInt &a_tris) override
Find all triangles whose envelop contains the point.
std::vector< int > VecInt
virtual const BSHP< VecPt3d > GetPts() const override
Returns shared pointer to points vector.
virtual double GetTruncMax() const override
get the maximum truncation value
virtual bool GetNatNeighBlendWeights() const override
get the option for blending weights when using Natural Neighbor
BSHP< GmTriSearch > m_triSearch
spatial index for searching triangles
void testToString()
tests serializing class to a string
virtual void SetPtsTris(BSHP< VecPt3d > a_, BSHP< VecInt > a_tris) override
Adds the triangles to the class.
virtual bool GetUseNatNeigh() const override
get the option for using Natural Neighbor interpolation
Computes the Clough Tocher interpolation to a location.
Definition: InterpCt.h:25
virtual int GetNatNeighNodalFuncNearestPtsOption() const override
get the option for the Natural Neighbor nodal function nearest points. Nearest points or nearest natu...
double m_extrap
Extrapolation value.
virtual void SetPtActivity(DynBitset &a_activity) override
Modifies the activity bitset of the class.
std::vector< double > VecDbl
std::vector< float > VecFlt
virtual const BSHP< VecFlt > GetScalars() const override
Returns shared pointer to scalars vector.
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 testCt()
test clough tocher interpolation
virtual float InterpToPt(const Pt3d &a_pt) override
Use the stored triangles to interpolate to a point. Returns extrapolation value if the point is outsi...
virtual int TriContainingPt(const Pt3d &a_pt) override
Find the triangle containing the point.
virtual const BSHP< VecInt > GetTris() const override
Returns shared pointer to triangles vector.
float InterpToPtImpl(const Pt3d &a_pt, int a_ptIdx)
Use the stored triangles to interpolate to a point. Returns extrapolation value if the point is outsi...
void VecToStream(std::stringstream &a_ss, const T &a_v, std::string a_label)
virtual VecInt GetExtrapolationPointIndexes() const override
Returns vector of point indexes for points that were outside of all triangles.
virtual DynBitset GetTriActivity() const override
Returns bitset of triangle activity.
static boost::shared_ptr< InterpNatNeigh > New(const std::vector< Pt3d > &a_pts, const std::vector< int > &a_tris, const std::vector< float > &a_scalar, GmTriSearch *a_triSearch)
Creates a Natural Neighbor Interpolation class.
void testInterp()
test interpolating from 3 triangles
boost::dynamic_bitset< size_t > DynBitset
BSHP< InterpCt > m_ct
Clough Tocher interpolation class.
BSHP< VecFlt > m_scalar
Scalars we&#39;re interpolating from.
virtual bool InterpWeights(const Pt3d &a_pt, VecInt &a_idxs, VecDbl &a_wts) override
Use the stored triangles to get interpolation weights for a point. Returns false if the point is outs...
virtual double GetTruncMin() const override
get minimum truncation value
BSHP< NodalFunc > m_nodal
Nodal function (constant, gradient plane, quadratic)
virtual void SetUseNatNeigh(bool a_, int a_nodalFunc, int a_ndFuncOpt, int a_ndFuncNumNearestPts, bool a_blendWeights, BSHP< Observer > a_prog) override
Set the class to use natural neighbor (NN) interpolation.
virtual bool GetTruncateInterpolatedValues() const override
get the option to truncate interpolated values
Class that performs linear interpolation.
Definition: InterpLinear.h:37
virtual void SetTrunc(double a_sMax, double a_sMin) override
Set the truncation values for the interpolation and turn on truncation.
double m_truncMin
Minimum truncation value. All interpolated values will be >=.
float NatNeighInterp(const Pt3d &a_pt)
uses Natural Neighbor interpolation method to get the interpolated val
#define XM_ENSURE_TRUE(...)
bool m_trunc
flag to indicate if truncation is on
Implementation of InterpLinear.
virtual void SetScalars(const float *a_scalar, size_t a_n) override
Set the scalars that will be used to interpolate from.
virtual std::string ToString() const override
Write the internals to a string.
#define XM_NODATA
virtual int GetNatNeighNodalFuncNumNearestPts() const override
get the value for the number of nearest points to use when calculating the nodal function ...
bool EQ_TOL(const _T &A, const _U &B, const _V &tolerance)
bool m_natNeigh
flag indicating that natural neighbor interpolation will be used
BSHP< InterpNatNeigh > m_nn
Natural neighbor interpolation class.
BSHP< VecPt3d > m_pts
pt locations that make up triangles
void testOneTriangle()
tests interpolating from 1 triangle
virtual DynBitset GetPtActivity() const override
Returns bitset of point activity.
Utility functions called by interpolation code.
BSHP< GmPtSearch > CreatePtSearch()
Creates a GmPtSearch class to be used for nodal function generation.
static BSHP< InterpLinear > New()
Creates an TriSearch class.
virtual void InterpToPts(const VecPt3d &a_pts, VecFlt &a_scalars) override
Calls InterpToPt in a loop.
virtual void SetUseCloughTocher(bool a_, BSHP< Observer > a_prog) override
Set the class to use the Clough Tocher interpolation method. This is a legacy feature from GMS...
bool m_cloughTocher
flag indicating clough tocher interpolation will be used
virtual void SetTriActivity(DynBitset &a_activity) override
Modifies the activity bitset of the class.
VecInt m_extrapolationPointIndexes
indexes of points that are outside of all triangles
virtual bool GetUseCloughTocher() const override
get the option for using Clough Tocher interpolation
virtual int GetNatNeighNodalFunc() const override
get the value for the Natural Neighbor nodal function
virtual void SetExtrapVal(double a_val) override
Set the constant extrapolation value.
void RecalcNodalFunc()
Resets some members of the class.
virtual double GetExtrapVal() const override
get extrapolation value
float CloughTocherInterp(VecInt &a_idxs, const Pt3d &a_pt)
uses Clough Tocher interpolation method to get the interpolated val
Class that performs natural neighbor interpolation.
BSHP< VecInt > m_tris
triangles referencing indexes of pts
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...
Definition: InterpUtil.cpp:363
std::vector< Pt3d > VecPt3d
double m_truncMax
Maximum truncation value. All interpolated values will be <=.