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

Keep conversion from ExPolygonsIndex to Index and vice versa ExPolygonsIndex .. contour(or hole) point from ExPolygons Index .. continous number. More...

#include <src/libslic3r/ExPolygonsIndex.hpp>

+ Collaboration diagram for Slic3r::ExPolygonsIndices:

Public Member Functions

 ExPolygonsIndices (const ExPolygons &shapes)
 
uint32_t cvt (const ExPolygonsIndex &id) const
 Convert to one index number.
 
ExPolygonsIndex cvt (uint32_t index) const
 Separate to multi index.
 
bool is_last_point (const ExPolygonsIndex &id) const
 Check whether id is last point in polygon.
 
uint32_t get_count () const
 Count of points in expolygons.
 

Private Attributes

std::vector< std::vector< uint32_t > > m_offsets
 
uint32_t m_count
 

Detailed Description

Keep conversion from ExPolygonsIndex to Index and vice versa ExPolygonsIndex .. contour(or hole) point from ExPolygons Index .. continous number.

index is used to address lines and points as result from function Slic3r::to_lines, Slic3r::to_points

Constructor & Destructor Documentation

◆ ExPolygonsIndices()

ExPolygonsIndices::ExPolygonsIndices ( const ExPolygons shapes)
6{
7 // prepare offsets
8 m_offsets.reserve(shapes.size());
10 for (const ExPolygon &shape : shapes) {
11 assert(!shape.contour.points.empty());
12 std::vector<uint32_t> shape_offsets;
13 shape_offsets.reserve(shape.holes.size() + 1);
14 shape_offsets.push_back(offset);
15 offset += shape.contour.points.size();
16 for (const Polygon &hole: shape.holes) {
17 shape_offsets.push_back(offset);
18 offset += hole.points.size();
19 }
20 m_offsets.push_back(std::move(shape_offsets));
21 }
23}
Definition ExPolygon.hpp:16
std::vector< std::vector< uint32_t > > m_offsets
Definition ExPolygonsIndex.hpp:39
uint32_t m_count
Definition ExPolygonsIndex.hpp:41
Points points
Definition MultiPoint.hpp:18
Definition Polygon.hpp:24
Slic3r::Polygons offset(const Slic3r::Polygon &polygon, const float delta, ClipperLib::JoinType joinType, double miterLimit)
Definition ClipperUtils.cpp:416
const Polygons & holes(const ExPolygon &p)
Definition AGGRaster.hpp:22
Slic3r::Polygon & hole(Slic3r::ExPolygon &sh, unsigned long idx)
Definition geometries.hpp:200
unsigned __int32 uint32_t
Definition unistd.h:79

References m_count, m_offsets, Slic3r::offset(), and Slic3r::MultiPoint::points.

+ Here is the call graph for this function:

Member Function Documentation

◆ cvt() [1/2]

uint32_t ExPolygonsIndices::cvt ( const ExPolygonsIndex id) const

Convert to one index number.

Parameters
idCompose of adress into expolygons
Returns
Index
26{
27 assert(id.expolygons_index < m_offsets.size());
28 const std::vector<uint32_t> &shape_offset = m_offsets[id.expolygons_index];
29 assert(id.polygon_index < shape_offset.size());
30 uint32_t res = shape_offset[id.polygon_index] + id.point_index;
31 assert(res < m_count);
32 return res;
33}

References m_count, and m_offsets.

Referenced by priv::choose_best_distance(), priv::collect_close_points(), Slic3r::cut_surface(), Slic3r::Emboss::divide_segments_for_close_point(), priv::fill_shape_distances(), priv::find_close_point(), priv::get_closest_point_index(), priv::is_face_inside(), and priv::select_patches().

+ Here is the caller graph for this function:

◆ cvt() [2/2]

ExPolygonsIndex ExPolygonsIndices::cvt ( uint32_t  index) const

Separate to multi index.

Parameters
indexadress into expolygons
Returns
36{
37 assert(index < m_count);
38 ExPolygonsIndex result{0, 0, 0};
39 // find expolygon index
40 auto fn = [](const std::vector<uint32_t> &offsets, uint32_t index) { return offsets[0] < index; };
41 auto it = std::lower_bound(m_offsets.begin() + 1, m_offsets.end(), index, fn);
42 result.expolygons_index = it - m_offsets.begin();
43 if (it == m_offsets.end() || it->at(0) != index) --result.expolygons_index;
44
45 // find polygon index
46 const std::vector<uint32_t> &shape_offset = m_offsets[result.expolygons_index];
47 auto it2 = std::lower_bound(shape_offset.begin() + 1, shape_offset.end(), index);
48 result.polygon_index = it2 - shape_offset.begin();
49 if (it2 == shape_offset.end() || *it2 != index) --result.polygon_index;
50
51 // calculate point index
52 uint32_t polygon_offset = shape_offset[result.polygon_index];
53 assert(index >= polygon_offset);
54 result.point_index = index - polygon_offset;
55 return result;
56}
Index into ExPolygons Identify expolygon, its contour (or hole) and point.
Definition ExPolygonsIndex.hpp:12

References m_count, and m_offsets.

◆ get_count()

uint32_t ExPolygonsIndices::get_count ( ) const

Count of points in expolygons.

Returns
Count of points in expolygons
82{ return m_count; }

References m_count.

Referenced by priv::choose_best_distance(), priv::collect_close_points(), Slic3r::cut_surface(), Slic3r::Emboss::divide_segments_for_close_point(), and priv::find_closest_point_pair().

+ Here is the caller graph for this function:

◆ is_last_point()

bool ExPolygonsIndices::is_last_point ( const ExPolygonsIndex id) const

Check whether id is last point in polygon.

Parameters
idIdentify point in expolygon
Returns
True when id is last point in polygon otherwise false
58 {
59 assert(id.expolygons_index < m_offsets.size());
60 const std::vector<uint32_t> &shape_offset = m_offsets[id.expolygons_index];
61 assert(id.polygon_index < shape_offset.size());
62 uint32_t index = shape_offset[id.polygon_index] + id.point_index;
63 assert(index < m_count);
64 // next index
65 uint32_t next_point_index = index + 1;
66 uint32_t next_poly_index = id.polygon_index + 1;
67 uint32_t next_expoly_index = id.expolygons_index + 1;
68 // is last expoly?
69 if (next_expoly_index == m_offsets.size()) {
70 // is last expoly last poly?
71 if (next_poly_index == shape_offset.size())
72 return next_point_index == m_count;
73 } else {
74 // (not last expoly) is expoly last poly?
75 if (next_poly_index == shape_offset.size())
76 return next_point_index == m_offsets[next_expoly_index][0];
77 }
78 // Not last polygon in expolygon
79 return next_point_index == shape_offset[next_poly_index];
80}

References m_count, and m_offsets.

Referenced by priv::collect_close_points(), and Slic3r::Emboss::divide_segments_for_close_point().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_count

uint32_t Slic3r::ExPolygonsIndices::m_count
private

◆ m_offsets

std::vector<std::vector<uint32_t> > Slic3r::ExPolygonsIndices::m_offsets
private

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