Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::PaintedLineVisitor Struct Reference
+ Collaboration diagram for Slic3r::PaintedLineVisitor:

Public Member Functions

 PaintedLineVisitor (const EdgeGrid::Grid &grid, std::vector< PaintedLine > &painted_lines, std::mutex &painted_lines_mutex, size_t reserve)
 
void reset ()
 
bool operator() (coord_t iy, coord_t ix)
 

Public Attributes

const EdgeGrid::Gridgrid
 
std::vector< PaintedLine > & painted_lines
 
std::mutex & painted_lines_mutex
 
Line line_to_test
 
std::unordered_set< std::pair< size_t, size_t >, boost::hash< std::pair< size_t, size_t > > > painted_lines_set
 
int color = -1
 

Static Public Attributes

static const double cos_threshold2 = Slic3r::sqr(cos(M_PI * 30. / 180.))
 
static const double append_threshold = 50 * SCALED_EPSILON
 
static const double append_threshold2 = Slic3r::sqr(append_threshold)
 

Detailed Description

Constructor & Destructor Documentation

◆ PaintedLineVisitor()

Slic3r::PaintedLineVisitor::PaintedLineVisitor ( const EdgeGrid::Grid grid,
std::vector< PaintedLine > &  painted_lines,
std::mutex &  painted_lines_mutex,
size_t  reserve 
)
inline
87 {
88 painted_lines_set.reserve(reserve);
89 }
std::mutex & painted_lines_mutex
Definition MultiMaterialSegmentation.cpp:142
const EdgeGrid::Grid & grid
Definition MultiMaterialSegmentation.cpp:140
std::unordered_set< std::pair< size_t, size_t >, boost::hash< std::pair< size_t, size_t > > > painted_lines_set
Definition MultiMaterialSegmentation.cpp:144
std::vector< PaintedLine > & painted_lines
Definition MultiMaterialSegmentation.cpp:141

References painted_lines_set.

Member Function Documentation

◆ operator()()

bool Slic3r::PaintedLineVisitor::operator() ( coord_t  iy,
coord_t  ix 
)
inline
94 {
95 // Called with a row and column of the grid cell, which is intersected by a line.
96 auto cell_data_range = grid.cell_data_range(iy, ix);
97 const Vec2d v1 = line_to_test.vector().cast<double>();
98 const double v1_sqr_norm = v1.squaredNorm();
99 const double heuristic_thr_part = line_to_test.length() + append_threshold;
100 for (auto it_contour_and_segment = cell_data_range.first; it_contour_and_segment != cell_data_range.second; ++it_contour_and_segment) {
101 Line grid_line = grid.line(*it_contour_and_segment);
102 const Vec2d v2 = grid_line.vector().cast<double>();
103 double heuristic_thr_sqr = Slic3r::sqr(heuristic_thr_part + grid_line.length());
104
105 // An inexpensive heuristic to test whether line_to_test and grid_line can be somewhere close enough to each other.
106 // This helps filter out cases when the following expensive calculations are useless.
107 if ((grid_line.a - line_to_test.a).cast<double>().squaredNorm() > heuristic_thr_sqr ||
108 (grid_line.b - line_to_test.a).cast<double>().squaredNorm() > heuristic_thr_sqr ||
109 (grid_line.a - line_to_test.b).cast<double>().squaredNorm() > heuristic_thr_sqr ||
110 (grid_line.b - line_to_test.b).cast<double>().squaredNorm() > heuristic_thr_sqr)
111 continue;
112
113 // When lines have too different length, it is necessary to normalize them
114 if (Slic3r::sqr(v1.dot(v2)) > cos_threshold2 * v1_sqr_norm * v2.squaredNorm()) {
115 // The two vectors are nearly collinear (their mutual angle is lower than 30 degrees)
116 if (painted_lines_set.find(*it_contour_and_segment) == painted_lines_set.end()) {
117 if (grid_line.distance_to_squared(line_to_test.a) < append_threshold2 ||
118 grid_line.distance_to_squared(line_to_test.b) < append_threshold2 ||
121 Line line_to_test_projected;
122 project_line_on_line(grid_line, line_to_test, &line_to_test_projected);
123
124 if ((line_to_test_projected.a - grid_line.a).cast<double>().squaredNorm() > (line_to_test_projected.b - grid_line.a).cast<double>().squaredNorm())
125 line_to_test_projected.reverse();
126
127 painted_lines_set.insert(*it_contour_and_segment);
128 {
129 boost::lock_guard<std::mutex> lock(painted_lines_mutex);
130 painted_lines.push_back({it_contour_and_segment->first, it_contour_and_segment->second, line_to_test_projected, this->color});
131 }
132 }
133 }
134 }
135 }
136 // Continue traversing the grid along the edge.
137 return true;
138 }
std::pair< std::vector< std::pair< size_t, size_t > >::const_iterator, std::vector< std::pair< size_t, size_t > >::const_iterator > cell_data_range(coord_t row, coord_t col) const
Definition EdgeGrid.hpp:336
Line line(const std::pair< size_t, size_t > &contour_and_segment_idx) const
Definition EdgeGrid.hpp:351
Vector vector() const
Definition Line.hpp:181
double length() const
Definition Line.hpp:165
double distance_to_squared(const Point &point) const
Definition Line.hpp:169
Point b
Definition Line.hpp:198
Point a
Definition Line.hpp:197
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:51
static bool project_line_on_line(const Line &projection_l, const Line &projected_l, Line *new_projected)
Definition MultiMaterialSegmentation.cpp:53
constexpr T sqr(T x)
Definition libslic3r.h:258
static const double append_threshold2
Definition MultiMaterialSegmentation.cpp:149
static const double append_threshold
Definition MultiMaterialSegmentation.cpp:148
Line line_to_test
Definition MultiMaterialSegmentation.cpp:143
int color
Definition MultiMaterialSegmentation.cpp:145
static const double cos_threshold2
Definition MultiMaterialSegmentation.cpp:147

References Slic3r::Line::a, append_threshold, append_threshold2, Slic3r::Line::b, Slic3r::EdgeGrid::Grid::cell_data_range(), color, cos_threshold2, Slic3r::Line::distance_to_squared(), grid, Slic3r::Line::length(), Slic3r::EdgeGrid::Grid::line(), line_to_test, painted_lines, painted_lines_mutex, painted_lines_set, Slic3r::project_line_on_line(), Slic3r::Line::reverse(), Slic3r::sqr(), and Slic3r::Line::vector().

+ Here is the call graph for this function:

◆ reset()

void Slic3r::PaintedLineVisitor::reset ( )
inline
91{ painted_lines_set.clear(); }

References painted_lines_set.

Member Data Documentation

◆ append_threshold

const double Slic3r::PaintedLineVisitor::append_threshold = 50 * SCALED_EPSILON
inlinestatic

Referenced by operator()().

◆ append_threshold2

const double Slic3r::PaintedLineVisitor::append_threshold2 = Slic3r::sqr(append_threshold)
inlinestatic

Referenced by operator()().

◆ color

int Slic3r::PaintedLineVisitor::color = -1

Referenced by operator()().

◆ cos_threshold2

const double Slic3r::PaintedLineVisitor::cos_threshold2 = Slic3r::sqr(cos(M_PI * 30. / 180.))
inlinestatic

Referenced by operator()().

◆ grid

const EdgeGrid::Grid& Slic3r::PaintedLineVisitor::grid

Referenced by operator()().

◆ line_to_test

Line Slic3r::PaintedLineVisitor::line_to_test

Referenced by operator()().

◆ painted_lines

std::vector<PaintedLine>& Slic3r::PaintedLineVisitor::painted_lines

Referenced by operator()().

◆ painted_lines_mutex

std::mutex& Slic3r::PaintedLineVisitor::painted_lines_mutex

Referenced by operator()().

◆ painted_lines_set

std::unordered_set<std::pair<size_t, size_t>, boost::hash<std::pair<size_t, size_t> > > Slic3r::PaintedLineVisitor::painted_lines_set

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