xmsinterp  1.0
xms::InterpNatNeighImpl Class Reference

Performs natural neighbor interpolation to a location. More...

Inheritance diagram for xms::InterpNatNeighImpl:
xms::InterpNatNeigh

Public Member Functions

 InterpNatNeighImpl (const std::vector< xms::Pt3d > &a_pts, const std::vector< int > &a_tris, const std::vector< float > &a_scalar, GmTriSearch *a_triSearch)
 Consructor. More...
 
virtual float InterpToPt (const xms::Pt3d &a_pt) override
 Interpolates to a_pt. More...
 
virtual void GetNeighbors (int a_ptIdx, std::vector< int > &a_neigh) override
 Finds neighboring triangles for the pt at a_ptIdx index in m_pts. More...
 
virtual void SetNodalFunc (BSHP< NodalFunc > a_) override
 Set the precomputed nodal function. More...
 
virtual void RecalcNodalFunc () override
 Recalculates the nodal function. This happens when the scalars change.
 
virtual void SetBlendWeights (bool a_) override
 Turns on a flag for using a blending function when calculating weights. More...
 
virtual std::string ToString () override
 serializes the class to a string More...
 
void FillEdgeMap ()
 Creates a map of edges for natural neighbor calculations.
 
void FillCenterVec ()
 calculate the circumcircle centers for all triangles
 
void EdgesFromTri (int a_triIdx, std::pair< int, int > a_edges[3])
 fill an array of edges from a triangle index More...
 
void NeighTriFromTriIdx (int a_triIdx, std::vector< int > &a_tris)
 Gets the adjacent triangles to a_triIdx. More...
 
void GetNatNeighTriangles (const xms::Pt3d &a_pt, std::vector< int > &a_tris)
 Given a pt this will find the "natural neighbor" triangles. First, we find the triangle that the pt is in. Then we visit the neighbor triangles to see if the point is inside of its circumcircle. If it is then we will also visit the neighbors of that triangle and so on. More...
 
double BlendFunc (double a_x)
 Blending function to smooth interpolation weights refactored from GMS. More...
 
double ScalarFromNodalFunc (int a_ptIdx, const xms::Pt3d &a_loc)
 calculates the scalar using the nodal function More...
 
double HaleNnInterp (const xms::Pt3d &a_pt)
 Implementation of natural neighbor interpolation taken from this paper A stable and fast implementation of natural neighbor interpolation Luming Liang & Dave Hale Center for Wave Phenomena, Colorado School of Mines,Golden, CO 80401, USA April 20, 2010. More...
 
void HaleNnVisitNeighbors (int a_tIdx, const xms::Pt3d &a_pt, std::vector< nnOuterEdgeStruct > &a_outerEdges, std::map< int, double > &a_weights)
 Visit the neighbors to a_pt and calculate the interpolation weight for the natural neighbors. More...
 
int AdjacentTriangle (std::pair< int, int > &a_edge, int a_triIdx)
 Gets the triangle adjacent to a_edge. More...
 
bool PtInTriCircumCircle (const xms::Pt3d &a_pt, int a_tri)
 Determines if a point is inside of a triangle circumcircle. More...
 
void HaleNnAddOuterEdge (std::vector< nnOuterEdgeStruct > &a_, int a_tIdx, int a_ptIdx0, int a_ptIdx1, const xms::Pt3d &a_pt)
 Adds a nnOuterEdgeStruct to a vector. More...
 
void HaleNnSortOuterEdges (std::vector< nnOuterEdgeStruct > &a_)
 Sorts the outer edges. More...
 
void HaleNnOuterEdgesToWeights (std::vector< nnOuterEdgeStruct > &a_outerEdges, std::map< int, double > &a_weights)
 Calculates weights from the outer edges. More...
 
void NormalizeWeights (std::map< int, double > &a_weights)
 Normalizes the weights so that they sum to 1.0. More...
 
void BlendWeights (std::map< int, double > &a_weights)
 Blends the weights using BlendFunc. Smooths the interpolation. More...
 
double ScalarFromWeights (std::map< int, double > &a_weights, const xms::Pt3d &a_pt)
 Computes a scalar at a_pt based on the interpolation weights. More...
 
- Public Member Functions inherited from xms::InterpNatNeigh
virtual ~InterpNatNeigh ()
 Destructor.
 

Private Types

typedef boost::unordered_map< std::pair< int, int >, std::pair< int, int > > MapEdges
 typedef for long template
 

Private Attributes

const std::vector< xms::Pt3d > & m_pts
 points interpolating from
 
const std::vector< int > & m_tris
 triangles interpolating from
 
const std::vector< float > & m_scalar
 scalar interpolating from
 
double m_tol
 tolerance for geometric floating point comparisons
 
MapEdges m_edges
 map of triangle edges
 
std::vector< xms::Pt3dm_centers
 circumcircle centers of triangles
 
BSHP< NodalFuncm_nf
 Nodal function (constant, gradient plane, quadratic)
 
GmTriSearch * m_triSearch
 Spatial index for searching triangles.
 
bool m_blendWeights
 flag for blending interpolation weights
 

Additional Inherited Members

- Static Public Member Functions inherited from xms::InterpNatNeigh
static boost::shared_ptr< InterpNatNeighNew (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. More...
 
- Protected Member Functions inherited from xms::InterpNatNeigh
 InterpNatNeigh ()
 Constructor.
 

Detailed Description

Performs natural neighbor interpolation to a location.

Definition at line 58 of file InterpNatNeigh.cpp.

Constructor & Destructor Documentation

◆ InterpNatNeighImpl()

xms::InterpNatNeighImpl::InterpNatNeighImpl ( const std::vector< xms::Pt3d > &  a_pts,
const std::vector< int > &  a_tris,
const std::vector< float > &  a_scalar,
GmTriSearch *  a_triSearch 
)

Consructor.

Parameters
[in]a_ptsLocations that are interpolated from
[in]a_trisTriangles connecting a_pts and defining neighbors
[in]a_scalarScalars that are interpolated from
[in]a_triSearchSpatial index for searching triangles

Definition at line 168 of file InterpNatNeigh.cpp.

References FillCenterVec(), and FillEdgeMap().

Member Function Documentation

◆ AdjacentTriangle()

int xms::InterpNatNeighImpl::AdjacentTriangle ( std::pair< int, int > &  a_edge,
int  a_triIdx 
)

Gets the triangle adjacent to a_edge.

Parameters
[in]a_edgeA triangle edge
[in]a_triIdxTriangle index
Returns
the index to the adjacent triangle. If there is no adjacent triangle then the return value is XM_NONE.

Definition at line 508 of file InterpNatNeigh.cpp.

References m_edges, and XM_NONE.

Referenced by HaleNnVisitNeighbors().

◆ BlendFunc()

double xms::InterpNatNeighImpl::BlendFunc ( double  x)

Blending function to smooth interpolation weights refactored from GMS.

Parameters
xinterpolation weight
Returns
The blended value.

Definition at line 399 of file InterpNatNeigh.cpp.

Referenced by BlendWeights().

◆ BlendWeights()

void xms::InterpNatNeighImpl::BlendWeights ( std::map< int, double > &  a_weights)

Blends the weights using BlendFunc. Smooths the interpolation.

Parameters
[out]a_weightsThe interpolation weights

Definition at line 622 of file InterpNatNeigh.cpp.

References BlendFunc().

Referenced by HaleNnInterp().

◆ EdgesFromTri()

void xms::InterpNatNeighImpl::EdgesFromTri ( int  a_triIdx,
std::pair< int, int >  a_edges[3] 
)

fill an array of edges from a triangle index

Parameters
[in]a_triIdxIndex of the triangle
[out]a_edgesArray of triangle edges filled by this method

Definition at line 325 of file InterpNatNeigh.cpp.

References m_tris.

Referenced by FillEdgeMap(), and NeighTriFromTriIdx().

◆ GetNatNeighTriangles()

void xms::InterpNatNeighImpl::GetNatNeighTriangles ( const xms::Pt3d a_pt,
std::vector< int > &  a_tris 
)

Given a pt this will find the "natural neighbor" triangles. First, we find the triangle that the pt is in. Then we visit the neighbor triangles to see if the point is inside of its circumcircle. If it is then we will also visit the neighbors of that triangle and so on.

Parameters
[in]a_ptThe location to find the natural neighbor triangles
[out]a_trisThe triangle indexes that are natural neighbors to a_pt

Definition at line 360 of file InterpNatNeigh.cpp.

References m_centers, m_tris, m_triSearch, NeighTriFromTriIdx(), and XM_NONE.

Referenced by GetNeighbors(), and InterpNatNeighUnitTests::testGetTris().

◆ GetNeighbors()

void xms::InterpNatNeighImpl::GetNeighbors ( int  a_ptIdx,
std::vector< int > &  a_neigh 
)
overridevirtual

Finds neighboring triangles for the pt at a_ptIdx index in m_pts.

Parameters
[in]a_ptIdxIndex to the point where we want to find its neighbor triangles
[out]a_neighVector of triangle indexes

Definition at line 199 of file InterpNatNeigh.cpp.

References GetNatNeighTriangles(), m_pts, and m_tris.

Referenced by InterpNatNeighUnitTests::testGetNeighbors().

◆ HaleNnAddOuterEdge()

void xms::InterpNatNeighImpl::HaleNnAddOuterEdge ( std::vector< nnOuterEdgeStruct > &  a_,
int  a_tIdx,
int  a_ptIdx0,
int  a_ptIdx1,
const xms::Pt3d a_pt 
)

Adds a nnOuterEdgeStruct to a vector.

Parameters
[out]a_Vector of outer edges
[in]a_tIdxTriangle index
[in]a_ptIdx0Point index for first point on edge of triangle a_tIdx
[in]a_ptIdx1Point index for second point on edge of triangle a_tIdx
[in]a_ptLocation used to find this outer edge

Definition at line 542 of file InterpNatNeigh.cpp.

References xms::nnOuterEdgeStruct::m_cc, xms::nnOuterEdgeStruct::m_edge, m_pts, m_tol, and xms::nnOuterEdgeStruct::m_triIdx.

Referenced by HaleNnVisitNeighbors().

◆ HaleNnInterp()

double xms::InterpNatNeighImpl::HaleNnInterp ( const xms::Pt3d a_pt)

Implementation of natural neighbor interpolation taken from this paper A stable and fast implementation of natural neighbor interpolation Luming Liang & Dave Hale Center for Wave Phenomena, Colorado School of Mines,Golden, CO 80401, USA April 20, 2010.

Parameters
[in]a_ptThe location being interpolated to
Returns
The interpolated value at a_pt

Definition at line 427 of file InterpNatNeigh.cpp.

References BlendWeights(), HaleNnOuterEdgesToWeights(), HaleNnSortOuterEdges(), HaleNnVisitNeighbors(), m_blendWeights, m_triSearch, NormalizeWeights(), ScalarFromWeights(), and XM_NONE.

Referenced by InterpToPt(), and InterpNatNeighUnitTests::testHaleNnInterp().

◆ HaleNnOuterEdgesToWeights()

void xms::InterpNatNeighImpl::HaleNnOuterEdgesToWeights ( std::vector< nnOuterEdgeStruct > &  a_outerEdges,
std::map< int, double > &  a_weights 
)

Calculates weights from the outer edges.

Parameters
[in]a_outerEdgesThe outer edges
[out]a_weightsWeight calculated for each outer edge

Definition at line 577 of file InterpNatNeigh.cpp.

References xms::nnOuterEdgeStruct::m_cc, m_centers, xms::nnOuterEdgeStruct::m_edge, and xms::nnOuterEdgeStruct::m_triIdx.

Referenced by HaleNnInterp().

◆ HaleNnSortOuterEdges()

void xms::InterpNatNeighImpl::HaleNnSortOuterEdges ( std::vector< nnOuterEdgeStruct > &  a_)

Sorts the outer edges.

Parameters
[out]a_Vector of outer edges

Definition at line 560 of file InterpNatNeigh.cpp.

Referenced by HaleNnInterp(), and InterpNatNeighUnitTests::testHaleNnSortOuterEdges().

◆ HaleNnVisitNeighbors()

void xms::InterpNatNeighImpl::HaleNnVisitNeighbors ( int  a_tIdx,
const xms::Pt3d a_pt,
std::vector< nnOuterEdgeStruct > &  a_outerEdges,
std::map< int, double > &  a_weights 
)

Visit the neighbors to a_pt and calculate the interpolation weight for the natural neighbors.

Parameters
[in]a_tIdxStarting triangle index
[in]a_ptLocation used to find natural neighbors
[out]a_outerEdgesOuter edges for a_pt
[out]a_weightsInterpolation weight for neighbor triangle

Definition at line 459 of file InterpNatNeigh.cpp.

References AdjacentTriangle(), HaleNnAddOuterEdge(), m_centers, m_tris, PtInTriCircumCircle(), and XM_NONE.

Referenced by HaleNnInterp().

◆ InterpToPt()

float xms::InterpNatNeighImpl::InterpToPt ( const xms::Pt3d a_pt)
overridevirtual

Interpolates to a_pt.

Parameters
[in]a_ptThe location to interpolate to
Returns
The interpolated value at a_pt

Definition at line 189 of file InterpNatNeigh.cpp.

References HaleNnInterp().

◆ NeighTriFromTriIdx()

void xms::InterpNatNeighImpl::NeighTriFromTriIdx ( int  a_triIdx,
std::vector< int > &  a_tris 
)

Gets the adjacent triangles to a_triIdx.

Parameters
[in]a_triIdxIndex of the triangle
[out]a_trisIndexes of adjacent triangles

Definition at line 336 of file InterpNatNeigh.cpp.

References EdgesFromTri(), m_edges, and XM_NONE.

Referenced by GetNatNeighTriangles().

◆ NormalizeWeights()

void xms::InterpNatNeighImpl::NormalizeWeights ( std::map< int, double > &  a_weights)

Normalizes the weights so that they sum to 1.0.

Parameters
[out]a_weightsThe interpolation weights

Definition at line 609 of file InterpNatNeigh.cpp.

Referenced by HaleNnInterp().

◆ PtInTriCircumCircle()

bool xms::InterpNatNeighImpl::PtInTriCircumCircle ( const xms::Pt3d a_pt,
int  a_tri 
)

Determines if a point is inside of a triangle circumcircle.

Parameters
[in]a_ptThe location to test
[in]a_triIndex to the triangle
Returns
true if the point is inside the circumcircle

Definition at line 526 of file InterpNatNeigh.cpp.

References m_centers.

Referenced by HaleNnVisitNeighbors().

◆ ScalarFromNodalFunc()

double xms::InterpNatNeighImpl::ScalarFromNodalFunc ( int  a_ptIdx,
const xms::Pt3d a_loc 
)

calculates the scalar using the nodal function

Parameters
[in]a_ptIdxIndex to point in m_pts
[in]a_locLocation being interpolated to
Returns
the scalar adjusted by the nodal function

Definition at line 409 of file InterpNatNeigh.cpp.

References m_nf, and m_scalar.

Referenced by ScalarFromWeights().

◆ ScalarFromWeights()

double xms::InterpNatNeighImpl::ScalarFromWeights ( std::map< int, double > &  a_weights,
const xms::Pt3d a_pt 
)

Computes a scalar at a_pt based on the interpolation weights.

Parameters
[in]a_weightsThe interpolation weights
[in]a_ptThe location interpolated to.
Returns
The interpolated value at a_pt.

Definition at line 640 of file InterpNatNeigh.cpp.

References ScalarFromNodalFunc().

Referenced by HaleNnInterp().

◆ SetBlendWeights()

void xms::InterpNatNeighImpl::SetBlendWeights ( bool  a_)
overridevirtual

Turns on a flag for using a blending function when calculating weights.

Parameters
[in]a_flag to turn on weight blending

Definition at line 236 of file InterpNatNeigh.cpp.

References m_blendWeights.

◆ SetNodalFunc()

void xms::InterpNatNeighImpl::SetNodalFunc ( BSHP< NodalFunc a_)
overridevirtual

Set the precomputed nodal function.

Parameters
a_The nodal function class.

Definition at line 220 of file InterpNatNeigh.cpp.

References m_nf.

◆ ToString()

std::string xms::InterpNatNeighImpl::ToString ( )
overridevirtual

serializes the class to a string

Returns
The string.

Definition at line 244 of file InterpNatNeigh.cpp.

References m_blendWeights, m_centers, m_edges, m_pts, m_scalar, m_tol, m_tris, and VecToStream().


The documentation for this class was generated from the following file: