Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::MutablePolygon Class Reference

#include <src/libslic3r/MutablePolygon.hpp>

+ Collaboration diagram for Slic3r::MutablePolygon:

Classes

class  const_iterator
 
class  iterator
 
struct  LinkedPoint
 
class  range
 

Public Types

using IndexType = int32_t
 
using PointType = Point
 

Public Member Functions

 MutablePolygon ()=default
 
 MutablePolygon (const Polygon &rhs, size_t reserve=0)
 
 MutablePolygon (std::initializer_list< Point > rhs, size_t reserve=0)
 
template<typename IT >
 MutablePolygon (IT begin, IT end, size_t reserve=0)
 
template<typename IT >
void assign (IT begin, IT end, size_t reserve=0)
 
void assign (const Polygon &rhs, size_t reserve=0)
 
void polygon (Polygon &out) const
 
Polygon polygon () const
 
bool empty () const
 
size_t size () const
 
size_t capacity () const
 
bool valid () const
 
void clear ()
 
iterator begin ()
 
const_iterator cbegin () const
 
const_iterator begin () const
 
iterator end ()
 
const_iterator cend () const
 
const_iterator end () const
 
iterator remove (const iterator it)
 
iterator insert (const iterator it, const PointType pt)
 

Private Member Functions

LinkedPointat (IndexType i)
 
const LinkedPointat (IndexType i) const
 
template<typename IT >
void assign_inner (IT begin, IT end, size_t reserve)
 
IndexType remove (const IndexType i)
 
IndexType insert (const IndexType i, const Point pt)
 

Private Attributes

std::vector< LinkedPointm_data
 
IndexType m_size { 0 }
 
IndexType m_head { IndexType(-1) }
 
IndexType m_head_free { IndexType(-1) }
 

Detailed Description


Class Documentation

◆ Slic3r::MutablePolygon::LinkedPoint

struct Slic3r::MutablePolygon::LinkedPoint
+ Collaboration diagram for Slic3r::MutablePolygon::LinkedPoint:
Class Members
IndexType next
PointType point
IndexType prev

Member Typedef Documentation

◆ IndexType

◆ PointType

Constructor & Destructor Documentation

◆ MutablePolygon() [1/4]

Slic3r::MutablePolygon::MutablePolygon ( )
default

◆ MutablePolygon() [2/4]

Slic3r::MutablePolygon::MutablePolygon ( const Polygon rhs,
size_t  reserve = 0 
)
inline
129: MutablePolygon(rhs.points.begin(), rhs.points.end(), reserve) {}

◆ MutablePolygon() [3/4]

Slic3r::MutablePolygon::MutablePolygon ( std::initializer_list< Point rhs,
size_t  reserve = 0 
)
inline
130: MutablePolygon(rhs.begin(), rhs.end(), reserve) {}

◆ MutablePolygon() [4/4]

template<typename IT >
Slic3r::MutablePolygon::MutablePolygon ( IT  begin,
IT  end,
size_t  reserve = 0 
)
inline
133 {
134 this->assign_inner(begin, end, reserve);
135 };
void assign_inner(IT begin, IT end, size_t reserve)
Definition MutablePolygon.hpp:207
iterator end()
Definition MutablePolygon.hpp:176
iterator begin()
Definition MutablePolygon.hpp:172

References assign_inner(), and end().

+ Here is the call graph for this function:

Member Function Documentation

◆ assign() [1/2]

void Slic3r::MutablePolygon::assign ( const Polygon rhs,
size_t  reserve = 0 
)
inline
145 {
146 assign(rhs.points.begin(), rhs.points.end(), reserve);
147 }
void assign(IT begin, IT end, size_t reserve=0)
Definition MutablePolygon.hpp:138

References assign(), and Slic3r::MultiPoint::points.

+ Here is the call graph for this function:

◆ assign() [2/2]

template<typename IT >
void Slic3r::MutablePolygon::assign ( IT  begin,
IT  end,
size_t  reserve = 0 
)
inline
138 {
139 m_data.clear();
140 m_head = IndexType(-1);
141 m_head_free = { IndexType(-1) };
142 this->assign_inner(begin, end, reserve);
143 };
IndexType m_head
Definition MutablePolygon.hpp:199
int32_t IndexType
Definition MutablePolygon.hpp:17
std::vector< LinkedPoint > m_data
Definition MutablePolygon.hpp:196
IndexType m_head_free
Definition MutablePolygon.hpp:201

References assign_inner(), end(), m_data, m_head, and m_head_free.

Referenced by assign(), Slic3r::remove_duplicates(), Slic3r::smooth_outward(), and Slic3r::smooth_outward().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ assign_inner()

template<typename IT >
void Slic3r::MutablePolygon::assign_inner ( IT  begin,
IT  end,
size_t  reserve 
)
inlineprivate
207 {
209 if (m_size > 0) {
210 m_head = 0;
211 m_data.reserve(std::max<size_t>(m_size, reserve));
212 auto i = IndexType(-1);
213 auto j = IndexType(1);
214 for (auto it = begin; it != end; ++ it)
215 m_data.push_back({ *it, i ++, j ++ });
216 m_data.front().prev = m_size - 1;
217 m_data.back ().next = 0;
218 }
219 };
IndexType m_size
Definition MutablePolygon.hpp:198

References begin(), end(), m_data, m_head, and m_size.

Referenced by MutablePolygon(), and assign().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ at() [1/2]

◆ at() [2/2]

const LinkedPoint & Slic3r::MutablePolygon::at ( IndexType  i) const
inlineprivate
204{ return m_data[i]; }

References m_data.

◆ begin() [1/2]

iterator Slic3r::MutablePolygon::begin ( )
inline
172{ return { this, m_head }; }

References m_head.

Referenced by assign_inner(), Slic3r::remove_duplicates(), Slic3r::remove_duplicates(), Slic3r::remove_duplicates(), and Slic3r::smooth_outward().

+ Here is the caller graph for this function:

◆ begin() [2/2]

const_iterator Slic3r::MutablePolygon::begin ( ) const
inline
174{ return this->cbegin(); }
const_iterator cbegin() const
Definition MutablePolygon.hpp:173

References cbegin().

+ Here is the call graph for this function:

◆ capacity()

size_t Slic3r::MutablePolygon::capacity ( ) const
inline
168{ return m_data.capacity(); }

References m_data.

◆ cbegin()

const_iterator Slic3r::MutablePolygon::cbegin ( ) const
inline
173{ return { this, m_head }; }

References m_head.

Referenced by begin(), Slic3r::operator==(), and polygon().

+ Here is the caller graph for this function:

◆ cend()

const_iterator Slic3r::MutablePolygon::cend ( ) const
inline
177{ return { this, this->empty() ? -1 : this->at(m_head).prev }; }
IndexType prev
Definition MutablePolygon.hpp:192
bool empty() const
Definition MutablePolygon.hpp:166
LinkedPoint & at(IndexType i)
Definition MutablePolygon.hpp:203

References at(), empty(), m_head, and Slic3r::MutablePolygon::LinkedPoint::prev.

Referenced by end().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clear()

void Slic3r::MutablePolygon::clear ( )
inline
170{ m_data.clear(); m_size = 0; m_head = IndexType(-1); m_head_free = IndexType(-1); }

References m_data, m_head, m_head_free, and m_size.

Referenced by Slic3r::clip_narrow_corner(), Slic3r::remove_duplicates(), and Slic3r::smooth_outward().

+ Here is the caller graph for this function:

◆ empty()

bool Slic3r::MutablePolygon::empty ( ) const
inline
166{ return m_size == 0; }

References m_size.

Referenced by cend(), end(), Slic3r::operator==(), remove(), Slic3r::remove_duplicates(), and Slic3r::remove_duplicates().

+ Here is the caller graph for this function:

◆ end() [1/2]

iterator Slic3r::MutablePolygon::end ( )
inline
176{ return { this, this->empty() ? -1 : this->at(m_head).prev }; }

References at(), empty(), m_head, and Slic3r::MutablePolygon::LinkedPoint::prev.

Referenced by MutablePolygon(), assign(), and assign_inner().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ end() [2/2]

const_iterator Slic3r::MutablePolygon::end ( ) const
inline
178{ return this->cend(); }
const_iterator cend() const
Definition MutablePolygon.hpp:177

References cend().

+ Here is the call graph for this function:

◆ insert() [1/2]

IndexType Slic3r::MutablePolygon::insert ( const IndexType  i,
const Point  pt 
)
inlineprivate
242 {
243 assert(i >= 0);
244 IndexType n;
245 IndexType j = this->at(i).prev;
246 if (m_head_free == -1) {
247 // Allocate a new item.
248 n = IndexType(m_data.size());
249 m_data.push_back({ pt, j, i });
250 } else {
251 n = m_head_free;
252 LinkedPoint &nlp = this->at(n);
253 m_head_free = nlp.next;
254 nlp = { pt, j, i };
255 }
256 this->at(j).next = n;
257 this->at(i).prev = n;
258 ++ m_size;
259 return n;
260 }
IndexType next
Definition MutablePolygon.hpp:194

References at(), m_data, m_head_free, m_size, Slic3r::MutablePolygon::LinkedPoint::next, and Slic3r::MutablePolygon::LinkedPoint::prev.

+ Here is the call graph for this function:

◆ insert() [2/2]

iterator Slic3r::MutablePolygon::insert ( const iterator  it,
const PointType  pt 
)
inline
185{ assert(it.m_data == this); return { this, this->insert(it.m_idx, pt) }; }
iterator insert(const iterator it, const PointType pt)
Definition MutablePolygon.hpp:185

References insert(), Slic3r::MutablePolygon::iterator::m_data, and Slic3r::MutablePolygon::iterator::m_idx.

Referenced by insert(), and Slic3r::MutablePolygon::iterator::insert().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ polygon() [1/2]

Polygon Slic3r::MutablePolygon::polygon ( ) const
inline
160 {
161 Polygon out;
162 this->polygon(out);
163 return out;
164 };
Polygon polygon() const
Definition MutablePolygon.hpp:160
Slic3r::Polygon Polygon
Definition Emboss.cpp:34

References polygon().

Referenced by polygon().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ polygon() [2/2]

void Slic3r::MutablePolygon::polygon ( Polygon out) const
inline
149 {
150 out.points.clear();
151 if (this->valid()) {
152 out.points.reserve(this->size());
153 auto it = this->cbegin();
154 out.points.emplace_back(*it);
155 for (++ it; it != this->cbegin(); ++ it)
156 out.points.emplace_back(*it);
157 }
158 };
bool valid() const
Definition MutablePolygon.hpp:169
size_t size() const
Definition MutablePolygon.hpp:167

References cbegin(), Slic3r::MultiPoint::points, size(), and valid().

Referenced by Slic3r::remove_duplicates(), Slic3r::smooth_outward(), Slic3r::smooth_outward(), and Slic3r::smooth_outward().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ remove() [1/2]

IndexType Slic3r::MutablePolygon::remove ( const IndexType  i)
inlineprivate
221 {
222 assert(i >= 0);
223 assert(m_size > 0);
224 assert(m_head != -1);
225 LinkedPoint &lp = this->at(i);
226 IndexType prev = lp.prev;
227 IndexType next = lp.next;
228 lp.next = m_head_free;
229 m_head_free = i;
230 if (-- m_size == 0)
231 m_head = -1;
232 else if (m_head == i)
233 m_head = next;
234 assert(! this->empty() || (prev == i && next == i));
235 if (this->empty())
236 return IndexType(-1);
237 this->at(prev).next = next;
238 this->at(next).prev = prev;
239 return next;
240 }

References at(), empty(), m_head, m_head_free, m_size, Slic3r::MutablePolygon::LinkedPoint::next, and Slic3r::MutablePolygon::LinkedPoint::prev.

+ Here is the call graph for this function:

◆ remove() [2/2]

iterator Slic3r::MutablePolygon::remove ( const iterator  it)
inline
182{ assert(it.m_data == this); return { this, this->remove(it.m_idx) }; }
iterator remove(const iterator it)
Definition MutablePolygon.hpp:182

References Slic3r::MutablePolygon::iterator::m_data, Slic3r::MutablePolygon::iterator::m_idx, and remove().

Referenced by Slic3r::MutablePolygon::iterator::remove(), and remove().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ size()

size_t Slic3r::MutablePolygon::size ( ) const
inline
167{ return m_size; }

References m_size.

Referenced by Slic3r::clip_narrow_corner(), Slic3r::operator==(), polygon(), Slic3r::remove_duplicates(), Slic3r::MutablePolygon::const_iterator::size(), Slic3r::MutablePolygon::iterator::size(), and Slic3r::smooth_outward().

+ Here is the caller graph for this function:

◆ valid()

bool Slic3r::MutablePolygon::valid ( ) const
inline
169{ return m_size >= 3; }

References m_size.

Referenced by polygon().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_data

std::vector<LinkedPoint> Slic3r::MutablePolygon::m_data
private

◆ m_head

IndexType Slic3r::MutablePolygon::m_head { IndexType(-1) }
private

◆ m_head_free

IndexType Slic3r::MutablePolygon::m_head_free { IndexType(-1) }
private

Referenced by assign(), clear(), insert(), and remove().

◆ m_size

IndexType Slic3r::MutablePolygon::m_size { 0 }
private

The documentation for this class was generated from the following file: