68 GmPolyLinePtRedistributer::GmPolyLinePtRedistributer()
74 GmPolyLinePtRedistributer::~GmPolyLinePtRedistributer()
92 int nSeg = (int)((length / a_size) + .5);
105 a_lengths.resize(a_pts.size());
106 for (
size_t i = 1; i < a_pts.size(); ++i)
108 const Pt3d &p0(a_pts[i - 1]), &p1(a_pts[i]);
109 a_lengths[i] =
Mdist(p0.x, p0.y, p1.
x, p1.
y);
124 double a_totalLength,
129 std::map<double, size_t> tVals;
130 double runningLen(0), t;
131 for (
size_t i = 0; i < a_lengths.size(); ++i)
133 runningLen += a_lengths[i];
134 t = runningLen / a_totalLength;
135 tVals.insert(std::make_pair(t, i));
137 VecDbl targetTvals(a_nSeg);
138 for (
size_t i = 0; i < targetTvals.size(); ++i)
140 targetTvals[i] = (i + 1) * (1.0 / a_nSeg);
143 ret.reserve(a_nSeg + 1);
144 ret.push_back(a_pts.front());
145 for (
size_t i = 0; i < targetTvals.size(); ++i)
147 auto it = tVals.lower_bound(targetTvals[i]);
148 if (it != tVals.end())
150 size_t seg1 = it->second, seg0(0);
151 double t1 = it->first, t0(0);
152 if (it != tVals.begin())
159 double t = (targetTvals[i] - t0) / (t1 - t0);
161 const Pt3d &p0(a_pts[seg0]), &p1(a_pts[seg1]);
163 pt.
x = p0.x + t * (p1.
x - p0.x);
164 pt.
y = p0.y + t * (p1.
y - p0.y);
169 ret.push_back(a_pts.back());
198 xms::VecPt3d basePts{{0, 0, 0}, {2, 0, 0}, {4, 0, 0}, {6, 0, 0}, {8, 0, 0}, {10, 0, 0}};
210 xms::VecPt3d basePts = {{0, 0, 0}, {5, 0, 0}, {10, 0, 0}, {10, 5, 0}, {10, 10, 0}};
216 basePts = {{0, 0, 0}, {2.85, 0, 0}, {5.71, 0, 0}, {8.57, 0, 0},
217 {10, 1.43, 0}, {10, 4.29, 0}, {10, 7.14, 0}, {10, 10, 0}};
221 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.
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.
std::vector< double > VecDbl
#define XM_ENSURE_TRUE(...)
std::vector< Pt3d > VecPt3d
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)