25 #include <xmsgrid/geometry/GmPtSearch.h> 26 #include <xmsgrid/geometry/GmTriSearch.h> 56 virtual void SetPtsTris(BSHP<VecPt3d> a_, BSHP<VecInt> a_tris)
override;
58 virtual void SetScalars(
const float* a_scalar,
size_t a_n)
override;
59 virtual void SetScalars(BSHP<VecFlt> a_scalar)
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;
84 virtual void SetTrunc(
double a_sMax,
double a_sMin)
override;
89 int a_ndFuncNumNearestPts,
91 BSHP<Observer> a_prog)
override;
126 return m_nodal->GetNearestPointsOption();
135 return m_nodal->GetNumNearestPoints();
143 return m_nodal->GetUseModifiedShepardWeights();
149 virtual std::string
ToString()
const override;
184 InterpLinear::InterpLinear()
190 InterpLinear::~InterpLinear()
202 InterpLinearImpl::InterpLinearImpl()
203 : m_triSearch(GmTriSearch::New())
211 , m_cloughTocher(false)
218 InterpLinearImpl::~InterpLinearImpl()
234 for (
size_t i = 0; i <
m_pts->size(); ++i)
246 m_scalar->assign(&a_scalar[0], &a_scalar[a_n]);
351 float* s = &(*m_scalar)[0];
352 rval = (float)((s[idxs[0]] * wts[0]) + (s[idxs[1]] * wts[1]) + (s[idxs[2]] * wts[2]));
355 if (
EQ_TOL(wts[0], 1, FLT_EPSILON) ||
EQ_TOL(wts[1], 1, FLT_EPSILON) ||
356 EQ_TOL(wts[2], 1, FLT_EPSILON))
392 a_scalars.assign(a_pts.size(), 0);
393 for (
size_t i = 0; i < a_pts.size(); i++)
415 m_triSearch->TriEnvelopsContainingPt(a_pt, a_tris);
427 return m_triSearch->InterpWeights(a_pt, a_idxs, a_wts);
438 m_ct->ComputeCtCoeff(&a_idxs[0]);
439 return (
float)(
m_ct->InterpToPt(a_pt));
449 return m_nn->InterpToPt(a_pt);
486 int nodalfunc(1), nearest(16);
487 bool twod(
true), quad_oct(
false), modifiedShepardWeights(
true);
493 modifiedShepardWeights, a_prog,
nullptr);
513 int a_ndFuncNumNearestPts,
515 BSHP<Observer> a_prog)
522 m_nn->SetBlendWeights(a_blendWeights);
526 int nearest(a_ndFuncNumNearestPts);
527 bool twod(
true), quad_oct(
false), modifiedShepardWeights(
true);
530 BSHP<GmPtSearch> pts;
531 if (0 != a_ndFuncOpt)
537 modifiedShepardWeights, a_prog, nnPtr);
547 BSHP<GmPtSearch> pts = GmPtSearch::New(
true);
548 pts->PtsToSearch(
m_pts);
559 m_nn->RecalcNodalFunc();
561 m_ct->RecalcNodalFunc();
569 std::stringstream ss;
593 ss <<
m_ct->ToString();
599 ss <<
m_nn->ToString();
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);
639 BSHP<VecPt3d> p(
new VecPt3d());
640 *p = {{0, 0, 1}, {1, 1, 1}, {1, 0, 1}};
641 BSHP<VecInt> t(
new VecInt());
644 const float EXTRAPVAL = (float)-3.12345678;
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);
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);
659 pt =
Pt3d(.5, .5, 0);
660 TS_ASSERT_DELTA(1, linear.
InterpToPt(pt), FLT_EPSILON);
662 TS_ASSERT_DELTA(1, linear.
InterpToPt(pt), FLT_EPSILON);
664 TS_ASSERT_DELTA(1, linear.
InterpToPt(pt), FLT_EPSILON);
667 TS_ASSERT_DELTA(1, linear.
InterpToPt(pt), FLT_EPSILON);
669 TS_ASSERT_DELTA(1, linear.
InterpToPt(pt), FLT_EPSILON);
671 TS_ASSERT_DELTA(1, linear.
InterpToPt(pt), FLT_EPSILON);
674 VecInt baseIdxes = { 0, 0 };
675 TS_ASSERT_EQUALS(baseIdxes, idxes);
677 VecPt3d vPts = {{ .5, .5, 0 }, { -1, 0, 0 }, { -.5, 0, 0 }};
681 baseIdxes = { 1, 2 };
682 TS_ASSERT_EQUALS(baseIdxes, idxes);
690 BSHP<VecPt3d> p(
new VecPt3d());
691 *p = {{0, 0, 0}, {1, 1, 1}, {1, 0, 2}};
692 BSHP<VecInt> t(
new VecInt());
698 TS_ASSERT_DELTA(.5, linear.
InterpToPt(pt), FLT_EPSILON);
700 TS_ASSERT_DELTA(1, linear.
InterpToPt(pt), FLT_EPSILON);
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);
712 BSHP<VecPt3d> p(
new VecPt3d());
713 *p = {{0, 0, 0}, {1, 1, 1}, {1, 0, 2}};
714 BSHP<VecInt> t(
new VecInt());
720 TS_ASSERT_DELTA(.5f, linear.
InterpToPt(pt), 1e-7);
722 TS_ASSERT_DELTA(-1.0f, linear.
InterpToPt(pt), FLT_EPSILON);
725 TS_ASSERT_DELTA(-1.0f, linear.
InterpToPt(pt), FLT_EPSILON);
728 TS_ASSERT_DELTA(-1.0f, linear.
InterpToPt(pt), FLT_EPSILON);
731 TS_ASSERT_DELTA(-1.0f, linear.
InterpToPt(pt), FLT_EPSILON);
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.
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.
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'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.
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.
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...
std::vector< Pt3d > VecPt3d
double m_truncMax
Maximum truncation value. All interpolated values will be <=.