xmsinterp  1.0
AnisotropicInterpolator.h
Go to the documentation of this file.
1 #pragma once
2 //------------------------------------------------------------------------------
7 //------------------------------------------------------------------------------
8 
9 //----- Included files ---------------------------------------------------------
12 #include <xmscore/points/ptsfwd.h>
13 #include <xmscore/stl/vector.h>
14 
15 //----- Forward declarations ---------------------------------------------------
16 
17 //----- Namespace declaration --------------------------------------------------
18 namespace xms
19 {
20 //----- Constants / Enumerations -----------------------------------------------
21 
22 //----- Forward declarations ---------------------------------------------------
23 
24 //----- Structs / Classes ------------------------------------------------------
25 
28 struct SNResult
29 {
38  SNResult(size_t a_index, double a_param, double a_cross, const Pt3d& a_position)
39  : m_position(a_position)
40  , m_param(a_param)
41  , m_cross(a_cross)
42  , m_index(a_index)
43  {
44  }
45 
47  double m_param;
48  double m_cross;
49  size_t m_index;
50 };
51 
55 {
59  LineParameters(double a_slope, double a_intercept);
63  LineParameters NormalThrough(const Pt3d& a_p) const;
68  bool Intersection(const LineParameters& a_other, Pt3d& a_p) const;
69 
70  double m_slope;
71  double m_intercept;
72 };
73 
75 typedef std::vector<SNResult> VecSNResult;
76 
92 {
93 public:
95 
96  void SetPoints(const VecPt3d& a_centerlinePts,
97  const VecPt3d& a_interpolationPts,
98  bool a_pickClosest = false);
99  const VecPt3d& GetInterpolationPoints() const;
100 
101  double InterpolatePoint(const Pt3d& a_target,
102  const VecPt3d& a_interpolationPoints,
103  double a_xScale,
104  double a_IDWPower = 2,
105  double a_tol = 1.0e-5);
106 
107  // Implementation details - for testing only
108 
109  VecPt3d ComputeInterpolationPoints(const VecPt3d& a_interpolationPts, bool a_pickClosest);
110 
111  double Distance(const Pt3d& a_p0, const Pt3d& a_p1) const;
112 
113  double AnisotropicDistanceSquared(const Pt3d& a_p0, const Pt3d& a_p1, double a_xScale);
114 
115  double CalculateIDW(double a_xScale,
116  const VecPt3d& a_points,
117  const Pt3d& a_target,
118  double a_power,
119  double a_tol = 1.0e-5);
120 
121  double CrossProduct(size_t a_segmentIndex, const Pt3d& a_p) const;
122 
123  LineParameters GetLineParameters(const Pt3d& a_p0, const Pt3d& a_p1) const;
124 
125  double GetParameterInSegment(size_t a_segmentIndex, const Pt3d& a_p) const;
126 
127  bool GetIntersectionOfSegmentWithPoint(size_t a_segmentIndex,
128  const Pt3d& a_p,
129  Pt3d& a_intersection,
130  double& a_param) const;
131 
132  void GetNormalPointParameter(size_t a_segmentIndex,
133  const Pt3d& a_p,
134  double& a_lastParam,
135  VecSNResult& a_results) const;
136 
137  void GetAllNormalPointParameters(const Pt3d& a_p, VecSNResult& a_results);
138 
139  VecPt3d TransformPoint(const Pt3d& a_p, bool a_onlyClosest = false);
140 
142 private:
145 
146  // data members:
149  std::vector<LineParameters> m_lineParams;
152 };
153 
154 //----- Function prototypes ----------------------------------------------------
155 
156 } // namespace xms
VecDbl m_accLengths
The accumulated distance along the centerline of each point.
VecPt3d m_centerLinePts
The polyline representing the centerline.
double InterpolatePoint(const Pt3d &a_target, const VecPt3d &a_interpolationPoints, double a_xScale, double a_IDWPower=2, double a_tol=1.0e-5)
Interpolate the z coordinate of the interpolation points to point a_target.
LineParameters GetLineParameters(const Pt3d &a_p0, const Pt3d &a_p1) const
Compute the 2d slope and intercept for a line through two points.
std::vector< double > VecDbl
bool GetIntersectionOfSegmentWithPoint(size_t a_segmentIndex, const Pt3d &a_p, Pt3d &a_intersection, double &a_param) const
Get the intersecting point and its parameter of a line through point a_p normal to a segment of m_cen...
size_t m_index
index of the segment within the centerline polyline
bool Intersection(const LineParameters &a_other, Pt3d &a_p) const
Get the intersection point of this and another line.
VecPt3d TransformPoint(const Pt3d &a_p, bool a_onlyClosest=false)
Transforms a point from (x, y, z) to (s, n, z) coordinates. s is for station (distance along the cent...
double CalculateIDW(double a_xScale, const VecPt3d &a_points, const Pt3d &a_target, double a_power, double a_tol=1.0e-5)
Calculates the Inverse Distance Weighted interpolation of a set of points at a target point...
VecPt3d m_SNPoints
The interpolation points.
VecPt3d ComputeInterpolationPoints(const VecPt3d &a_interpolationPts, bool a_pickClosest)
Transforms a set of points from normal (x, y, z) coordinates to (s, n, z) coordinates. Note: The z coordinate is left unchanged.
LineParameters NormalThrough(const Pt3d &a_p) const
Get the LineParameters for a line normal to this through a point.
double CrossProduct(size_t a_segmentIndex, const Pt3d &a_p) const
Compute the 2d cross product of the vectors from a_p to the 1st and last points in a segment of m_cen...
Hold data of transforming from xyz to station,normal space.
double AnisotropicDistanceSquared(const Pt3d &a_p0, const Pt3d &a_p1, double a_xScale)
Compute the distance squared between two points, after a scale factor is applied to their x coordinat...
void SetPoints(const VecPt3d &a_centerlinePts, const VecPt3d &a_interpolationPts, bool a_pickClosest=false)
Set the centerline points to parameterize to.
const VecPt3d & GetInterpolationPoints() const
Get the transformed interpolation points in (s, n, z) space.
SNResult(size_t a_index, double a_param, double a_cross, const Pt3d &a_position)
Construct a station normal result.
std::vector< SNResult > VecSNResult
A Vector of station normal results (for a given point).
Class to transform points relative to a centerline polyline into a space where the centerline segment...
double Distance(const Pt3d &a_p0, const Pt3d &a_p1) const
Compute the distance between two points.
#define XM_DISALLOW_COPY_AND_ASSIGN(TypeName)
Pt3< double > Pt3d
double GetParameterInSegment(size_t a_segmentIndex, const Pt3d &a_p) const
Compute the parameter for a point in a segment of m_centerLinePts. The parameter will be between 0 an...
LineParameters(double a_slope, double a_intercept)
Constructor from slope and intercept.
void GetNormalPointParameter(size_t a_segmentIndex, const Pt3d &a_p, double &a_lastParam, VecSNResult &a_results) const
Append the transform (if any) of a point to a centerline segment.
Pt3d m_position
intersection of the normal through point in the segment
double m_param
parameter in the range [0..1] within the segment
double m_slope
Slope of the line. 0 is horizontal. Nan is vertical.
void GetAllNormalPointParameters(const Pt3d &a_p, VecSNResult &a_results)
Get the SNResults for a point.
double m_intercept
x intercept if vertical; else, the y intercept.
std::vector< LineParameters > m_lineParams
std::vector< Pt3d > VecPt3d
2D Line definition. If vertical m_slope is Nan.
double m_cross
cross product (>0 if on left of segment; <0 on right)