84 XmStampInterpCrossSectionImpl::XmStampInterpCrossSectionImpl()
92 XmStampInterpCrossSectionImpl::~XmStampInterpCrossSectionImpl()
105 for (
size_t i = 0; i <
m_io->
m_cs.size(); ++i)
108 if (cs.m_left.size() > 1 || cs.m_right.size() > 1)
110 if (cs.m_idxLeftShoulder < 1)
111 cs.m_idxLeftShoulder = 1;
112 if (cs.m_idxRightShoulder < 1)
113 cs.m_idxRightShoulder = 1;
119 for (
int i = 0; i < first; ++i)
125 for (
size_t i = (
size_t)(last + 1); last > 0 && i <
m_io->
m_cs.size(); ++i)
131 int prev = first, next;
132 double prevDist, nextDist, percent;
133 for (
int i = first + 1; i < last; ++i)
136 if (cs.m_left.size() > 1 || cs.m_right.size() > 1)
148 percent = prevDist / (prevDist + nextDist);
183 for (
size_t i =
m_io->
m_cs.size(); csIdx == -1 && i > 0; --i)
186 if (cs.m_left.size() > 1 || cs.m_right.size() > 1)
188 csIdx =
static_cast<int>(i - 1);
205 for (
size_t i = start; csIdx == -1 && i <
m_io->
m_cs.size(); ++i)
208 if (cs.m_left.size() > 1 || cs.m_right.size() > 1)
210 csIdx =
static_cast<int>(i);
230 InterpCs(pCs, nCs, a_percent, a_cs);
252 if (!pCs.m_left.empty())
254 else if (!pCs.m_right.empty())
260 pt.x = p1.x - (a_percent * (p1.x - p2.x));
261 pt.y = p1.y - (a_percent * (p1.y - p2.y));
262 a_cs.
m_left.assign(1, pt);
269 InterpPts(l1, 0, ls1, l2, 0, ls2, a_percent, l3);
272 int lend1((
int)pCs.m_left.size() - 1), lend2((
int)nCs.
m_left.size() - 1);
273 InterpPts(l1, ls1, lend1, l2, ls2, lend2, a_percent, l3);
281 InterpPts(r1, 0, rs1, r2, 0, rs2, a_percent, r3);
284 int rend1((
int)pCs.m_right.size() - 1), rend2((
int)nCs.
m_right.size() - 1);
285 InterpPts(r1, rs1, rend1, r2, rs2, rend2, a_percent, r3);
317 SetDbl tvals(t1.begin(), t1.end());
318 tvals.insert(t2.begin(), t2.end());
322 for (
const auto& t : tvals)
324 p1 =
PtFromT(a_v1, a_beg1, t1, t);
325 p2 =
PtFromT(a_v2, a_beg2, t2, t);
326 pt.
x = p1.
x - (a_percent * (p1.
x - p2.
x));
327 pt.
y = p1.
y - (a_percent * (p1.
y - p2.
y));
328 a_interpPts.push_back(pt);
345 double diff = a_v[a_end].x - a_v[a_beg].x;
346 for (
int i = a_beg + 1; i <= a_end; ++i)
348 double t = (a_v[i].x - a_v[a_beg].x) / diff;
364 if (a_t.size() == 1 && a_t[0] == 0.0)
368 double t1(-1), t2(-1);
371 for (
size_t i = 1; idx < 0 && i < a_t.size(); ++i)
375 idx =
static_cast<int>(i) - 1;
376 p1 = a_v[a_beg + idx];
377 p2 = a_v[a_beg + idx + 1];
381 else if (a_tval == a_t[i])
383 idx =
static_cast<int>(i);
384 p1 = a_v[a_beg + idx];
391 double localt = (a_tval - t1) / (t2 - t1);
392 r.
x = p1.
x + localt * (p2.
x - p1.
x);
393 r.
y = p1.
y + localt * (p2.
y - p1.
y);
409 XmStampInterpCrossSection::XmStampInterpCrossSection()
415 XmStampInterpCrossSection::~XmStampInterpCrossSection()
436 io.
m_centerLine = {{0, 0}, {5, 0}, {10, 0}, {15, 0}, {20, 0}, {25, 0}};
442 for (
auto& c : io.
m_cs)
444 TS_ASSERT(c.m_left.empty());
445 TS_ASSERT(c.m_right.empty());
446 TS_ASSERT(c.m_idxLeftShoulder == 0);
447 TS_ASSERT(c.m_idxRightShoulder == 0);
448 TS_ASSERT(c.m_leftMax == 0);
449 TS_ASSERT(c.m_rightMax == 0);
455 cs.
m_left = {{0, 10}, {1, 11}, {2, 12}, {4, 11}, {5, 10}, {10, 5}, {15, 0}};
463 cs1.
m_left = {{0, 20}, {4, 19}, {6, 18}, {8, 18}, {10, 20}, {15, 15}, {20, 10}};
474 TS_ASSERT_EQUALS(io.
m_cs[1].m_idxLeftShoulder, io.
m_cs[0].m_idxLeftShoulder);
475 TS_ASSERT_EQUALS(io.
m_cs[1].m_leftMax, io.
m_cs[0].m_leftMax);
476 TS_ASSERT_EQUALS(io.
m_cs[1].m_rightMax, io.
m_cs[0].m_rightMax);
478 TS_ASSERT_EQUALS(4, io.
m_cs[0].m_idxRightShoulder);
481 TS_ASSERT_EQUALS(io.
m_cs[4].m_idxLeftShoulder, io.
m_cs[5].m_idxLeftShoulder);
482 TS_ASSERT_EQUALS(io.
m_cs[4].m_leftMax, io.
m_cs[5].m_leftMax);
483 TS_ASSERT_EQUALS(io.
m_cs[4].m_rightMax, io.
m_cs[5].m_rightMax);
485 TS_ASSERT_EQUALS(io.
m_cs[4].m_idxRightShoulder, io.
m_cs[5].m_idxRightShoulder);
486 VecPt3d baseCs = {{0.00, 13.33}, {1.33, 13.83}, {2.67, 14.33}, {4.0, 13.67},
487 {5.33, 13.33}, {6.67, 13.33}, {11.67, 8.33}, {16.67, 3.33}};
489 TS_ASSERT_EQUALS(5, io.
m_cs[2].m_idxLeftShoulder);
491 TS_ASSERT_EQUALS(5, io.
m_cs[2].m_idxRightShoulder);
492 VecPt3d baseCs1 = {{0, 16.67}, {1.67, 16.67}, {3.33, 16.67}, {5.0, 15.83},
493 {6.67, 15.67}, {8.33, 16.67}, {13.33, 11.67}, {18.33, 6.67}};
495 TS_ASSERT_EQUALS(5, io.
m_cs[3].m_idxLeftShoulder);
497 TS_ASSERT_EQUALS(5, io.
m_cs[3].m_idxRightShoulder);
508 TS_ASSERT_EQUALS(5, io.
m_cs[2].m_idxRightShoulder);
509 baseCs = {{0, 13.33}, {1.33, 6.33}, {2, 6}, {2.67, 6}, {3.33, 6.67}, {5, 5}, {6.67, 3.33}};
511 TS_ASSERT_DELTA(6.33, io.
m_cs[2].m_leftMax, 1e-2);
514 TS_ASSERT_EQUALS(5, io.
m_cs[3].m_idxRightShoulder);
515 baseCs1 = {{0, 16.67}, {2.67, 12.67}, {4, 12}, {5.33, 12},
516 {6.67, 13.33}, {10, 10}, {13.33, 6.67}};
518 TS_ASSERT_DELTA(12.66, io.
m_cs[3].m_leftMax, 1e-2);
528 io.
m_centerLine = {{0, 0}, {5, 0}, {10, 0}, {15, 0}, {20, 0}, {25, 0}};
532 cs.
m_left = {{0, 10}, {1, 11}, {2, 12}, {4, 11}, {5, 10}, {10, 5}, {15, 0}};
537 cs.
m_left = {{0, 20}, {4, 19}, {6, 18}, {8, 18}, {10, 20}, {15, 15}, {20, 10}};
546 TS_ASSERT_EQUALS(1, io.
m_cs[0].m_idxLeftShoulder);
548 TS_ASSERT_EQUALS(1, io.
m_cs[0].m_idxRightShoulder);
550 TS_ASSERT_EQUALS(4, io.
m_cs[5].m_idxLeftShoulder);
552 TS_ASSERT_EQUALS(4, io.
m_cs[5].m_idxRightShoulder);
553 VecPt3d baseCs = {{0.00, 13.33}, {1.60, 13.27}, {2.40, 13.07}, {3.20, 13.20},
554 {4.00, 14.00}, {4.90, 14.43}, {6.71, 13.29}, {7.62, 12.38},
555 {10.33, 9.67}, {12.14, 7.86}, {16.67, 3.33}};
557 TS_ASSERT_EQUALS(4, io.
m_cs[2].m_idxLeftShoulder);
559 TS_ASSERT_EQUALS(4, io.
m_cs[2].m_idxRightShoulder);
560 baseCs = {{0.00, 16.67}, {2.80, 16.13}, {4.20, 15.53}, {5.60, 15.60},
561 {7.00, 17.00}, {7.81, 16.86}, {9.43, 15.57}, {10.24, 14.76},
562 {12.67, 12.33}, {14.29, 10.71}, {18.33, 6.67}};
564 TS_ASSERT_EQUALS(4, io.
m_cs[3].m_idxLeftShoulder);
566 TS_ASSERT_EQUALS(4, io.
m_cs[3].m_idxRightShoulder);
576 io.
m_centerLine = {{0, 0}, {5, 0}, {10, 0}, {15, 0}, {20, 0}, {25, 0}};
580 cs.
m_left = {{0, 10}, {1, 11}, {2, 12}, {4, 11}, {5, 10}, {10, 5}, {15, 0}};
585 cs.
m_left = {{0, 20}, {4, 19}, {6, 18}, {8, 18}, {10, 20}, {15, 15}, {20, 10}};
594 TS_ASSERT_EQUALS(2, io.
m_cs[0].m_idxLeftShoulder);
595 TS_ASSERT_EQUALS(2, io.
m_cs[1].m_idxLeftShoulder);
596 TS_ASSERT_EQUALS(3, io.
m_cs[2].m_idxLeftShoulder);
597 TS_ASSERT_EQUALS(3, io.
m_cs[3].m_idxLeftShoulder);
598 TS_ASSERT_EQUALS(3, io.
m_cs[4].m_idxLeftShoulder);
599 TS_ASSERT_EQUALS(3, io.
m_cs[5].m_idxLeftShoulder);
601 TS_ASSERT_EQUALS(2, io.
m_cs[0].m_idxRightShoulder);
602 TS_ASSERT_EQUALS(2, io.
m_cs[1].m_idxRightShoulder);
603 TS_ASSERT_EQUALS(3, io.
m_cs[2].m_idxRightShoulder);
604 TS_ASSERT_EQUALS(3, io.
m_cs[3].m_idxRightShoulder);
605 TS_ASSERT_EQUALS(3, io.
m_cs[4].m_idxRightShoulder);
606 TS_ASSERT_EQUALS(3, io.
m_cs[5].m_idxRightShoulder);
614 {0.00, 13.33}, {2.00, 13.66}, {3.00, 13.66}, {4.00, 14.00}, {5.94, 13.94},
615 {6.11, 13.88}, {6.92, 13.07}, {11.38, 8.61}, {11.79, 8.20}, {16.66, 3.33},
621 {0.00, 16.66}, {3.00, 16.33}, {4.50, 15.83}, {6.00, 16.00}, {7.89, 16.89},
622 {8.05, 16.94}, {8.84, 16.15}, {13.19, 11.80}, {13.58, 11.41}, {18.33, 6.66},
virtual bool ValidCrossSectionsExist(XmStamperIo &a_) override
Interpolates the missing cross sections. Modifys the m_cs member of the XmStamperIo class that is pas...
int FindLastValidCrossSection()
Finds the last valid cross section in the inputs.
int FindFirstValidCrossSection()
Finds the first valid cross section in the inputs.
static BSHP< XmStampInterpCrossSection > New()
Creates a XmStampInterpCrossSection class.
VecPt3d m_left
left side of the cross section
Implementaion of XmStampInterpCrossSection.
int m_idxRightShoulder
index to the shoulder point in the m_right vector
double gmXyDistance(double x1, double y1, double x2, double y2)
std::vector< double > VecDbl
Interpolate cross sections for stamping.
double m_leftMax
max x value for left side
XmStamperIo * m_io
pointer to the inputs to the stamp operation
void InterpPts(VecPt3d &a_v1, int a_beg1, int a_end1, VecPt3d &a_v2, int a_beg2, int a_end2, double a_percent, VecPt3d &a_interpPts)
Interpolates part of 2 cross sections to part of a new cross section. Separate interpolations are don...
std::set< double > SetDbl
void testCrossSectionTutorial()
[snip_test_Example_XmStamper_Test1]>
virtual void InterpCs(XmStampCrossSection &a_prev, XmStampCrossSection &a_next, double a_percent, XmStampCrossSection &a_cs) override
Interpolates a cross section from 2 other cross sections using a weight (a_percent) ...
void test0()
Tests symetric cross section interpolation.
#define XM_ENSURE_TRUE(...)
double m_rightMax
max x value for right side
VecPt3d m_right
right side of the cross section
void CalcTvals(VecPt3d &a_v, int a_beg, int a_end, VecDbl &a_t)
Calculates parametric t values from a vector of x,y coords based on x.
Stamping inputs/outputs class.
int FindNextValidCrossSection(int a_idx)
Finds the first valid cross section after a_idx in the inputs.
Pt3d PtFromT(VecPt3d &a_v, int a_beg, VecDbl &a_t, double a_tval)
Calculates the x,y location of the point at a_tval.
virtual void InterpMissingCrossSections(XmStamperIo &a_) override
Interpolates the missing cross sections. Modifys the m_cs member of the XmStamperIo class that is pas...
void test1()
[snip_test_Example_XmStamper_Test1]
Cross section definition for stamping.
std::vector< XmStampCrossSection > m_cs
cross sections along the polyLine
BSHP< Observer > m_observer
progress observer
int m_stampingType
Stamping type 0 - Cut, 1 - Fill, 2 - Both.
std::vector< Pt3d > VecPt3d