Get rid of unnecessary double storage of processed input polygons in the multi-material segmentation as ExPolygons and also as Polygons. All processed input polygons are now stored as ExPolygons.

This commit is contained in:
Lukáš Hejl 2021-07-25 22:29:48 +02:00
parent 38866b65b0
commit 216589fdb1
2 changed files with 57 additions and 38 deletions

View file

@ -20,10 +20,13 @@ public:
Contour(const Slic3r::Point *data, size_t size, bool open) : Contour(data, data + size, open) {}
Contour(const std::vector<Slic3r::Point> &pts, bool open) : Contour(pts.data(), pts.size(), open) {}
const Slic3r::Point *begin() const { return m_begin; }
const Slic3r::Point *end() const { return m_end; }
bool open() const { return m_open; }
bool closed() const { return ! m_open; }
const Slic3r::Point *begin() const { return m_begin; }
const Slic3r::Point *end() const { return m_end; }
bool open() const { return m_open; }
bool closed() const { return !m_open; }
const Slic3r::Point &front() const { return *m_begin; }
const Slic3r::Point &back() const { return *(m_end - 1); }
// Start point of a segment idx.
const Slic3r::Point& segment_start(size_t idx) const {
@ -61,6 +64,23 @@ public:
size_t num_segments() const { return this->size() - (m_open ? 1 : 0); }
Line get_segment(size_t idx) const
{
assert(idx < this->num_segments());
return Line(this->segment_start(idx), this->segment_end(idx));
}
Lines get_segments() const
{
Lines lines;
lines.reserve(this->num_segments());
if (this->num_segments() > 2) {
for (auto it = this->begin(); it != this->end() - 1; ++it) lines.push_back(Line(*it, *(it + 1)));
if (!m_open) lines.push_back(Line(this->back(), this->front()));
}
return lines;
}
private:
size_t size() const { return m_end - m_begin; }