67 GmPolyLinePtRedistributer::GmPolyLinePtRedistributer()
73 GmPolyLinePtRedistributer::~GmPolyLinePtRedistributer()
91 int nSeg = (int)((length / a_size) + .5);
104 a_lengths.resize(a_pts.size());
105 for (
size_t i = 1; i < a_pts.size(); ++i)
107 const Pt3d &p0(a_pts[i - 1]), &p1(a_pts[i]);
108 a_lengths[i] =
Mdist(p0.x, p0.y, p1.
x, p1.
y);
123 double a_totalLength,
128 std::map<double, size_t> tVals;
129 double runningLen(0), t;
130 for (
size_t i = 0; i < a_lengths.size(); ++i)
132 runningLen += a_lengths[i];
133 t = runningLen / a_totalLength;
134 tVals.insert(std::make_pair(t, i));
136 VecDbl targetTvals(a_nSeg);
137 for (
size_t i = 0; i < targetTvals.size(); ++i)
139 targetTvals[i] = (i + 1) * (1.0 / a_nSeg);
142 ret.reserve(a_nSeg + 1);
143 ret.push_back(a_pts.front());
144 for (
size_t i = 0; i < targetTvals.size(); ++i)
146 auto it = tVals.lower_bound(targetTvals[i]);
147 if (it != tVals.end())
149 size_t seg1 = it->second, seg0(0);
150 double t1 = it->first, t0(0);
151 if (it != tVals.begin())
158 double t = (targetTvals[i] - t0) / (t1 - t0);
160 const Pt3d &p0(a_pts[seg0]), &p1(a_pts[seg1]);
162 pt.
x = p0.x + t * (p1.
x - p0.x);
163 pt.
y = p0.y + t * (p1.
y - p0.y);
168 ret.push_back(a_pts.back());
195 xms::VecPt3d pts{{0, 0, 0}, {10, 0, 0}};
197 xms::VecPt3d basePts{{0, 0, 0}, {2, 0, 0}, {4, 0, 0}, {6, 0, 0}, {8, 0, 0}, {10, 0, 0}};
207 xms::VecPt3d pts{{0, 0, 0}, {10, 0, 0}, {10, 10, 0}};
209 xms::VecPt3d basePts = {{0, 0, 0}, {5, 0, 0}, {10, 0, 0}, {10, 5, 0}, {10, 10, 0}};
215 basePts = {{0, 0, 0}, {2.85, 0, 0}, {5.71, 0, 0}, {8.57, 0, 0},
216 {10, 1.43, 0}, {10, 4.29, 0}, {10, 7.14, 0}, {10, 10, 0}};
220 basePts = {{0, 0, 0}, {10, 10, 0}};
void testRedistribute1()
tests redistributing 2 line segments
Implementation of GmPolyLinePtRedistributer.
Redistributes the point locations on a polyline based on a size.
std::vector< double > VecDbl
double PolyLineLengths(const VecPt3d &a_pts, VecDbl &a_lengths)
Calculates the total length (xy) of a polyline as well as the length of each segment.
static BSHP< GmPolyLinePtRedistributer > New()
Creates an instance of this class.
void testCreateClass()
tests creating the class
virtual VecPt3d Redistribute(const VecPt3d &a_input, double a_size) override
Redistributes the distance between points on a polyline based on the a_size value provided to the met...
Functions dealing with geometry.
#define XM_ENSURE_TRUE(...)
VecPt3d RedistPolyLineWithNumSeg(const VecPt3d &a_pts, double a_totalLength, const VecDbl &a_lengths, int a_nSeg)
Calculates the total length (xy) of a polyline as well as the length of each segment.
void testRedistribute()
tests redistributing 1 line segment
double Mdist(_T x1, _U y1, _V x2, _W y2)
std::vector< Pt3d > VecPt3d