OrcaSlicer latest
OrcaSlicer
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::Grid & grid
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
558 {
559 painted_lines_set.reserve(reserve);
560 }
std::mutex & painted_lines_mutex
Definition MultiMaterialSegmentation.cpp:613
const EdgeGrid::Grid & grid
Definition MultiMaterialSegmentation.cpp:611
std::unordered_set< std::pair< size_t, size_t >, boost::hash< std::pair< size_t, size_t > > > painted_lines_set
Definition MultiMaterialSegmentation.cpp:615
std::vector< PaintedLine > & painted_lines
Definition MultiMaterialSegmentation.cpp:612

References grid, painted_lines, painted_lines_mutex, and painted_lines_set.

Member Function Documentation

◆ operator()()

bool Slic3r::PaintedLineVisitor::operator() ( coord_t iy,
coord_t ix )
inline
565 {
566 // Called with a row and column of the grid cell, which is intersected by a line.
567 auto cell_data_range = grid.cell_data_range(iy, ix);
568 const Vec2d v1 = line_to_test.vector().cast<double>();
569 const double v1_sqr_norm = v1.squaredNorm();
570 const double heuristic_thr_part = line_to_test.length() + append_threshold;
571 for (auto it_contour_and_segment = cell_data_range.first; it_contour_and_segment != cell_data_range.second; ++it_contour_and_segment) {
572 Line grid_line = grid.line(*it_contour_and_segment);
573 const Vec2d v2 = grid_line.vector().cast<double>();
574 double heuristic_thr_sqr = Slic3r::sqr(heuristic_thr_part + grid_line.length());
575
576 // An inexpensive heuristic to test whether line_to_test and grid_line can be somewhere close enough to each other.
577 // This helps filter out cases when the following expensive calculations are useless.
578 if ((grid_line.a - line_to_test.a).cast<double>().squaredNorm() > heuristic_thr_sqr ||
579 (grid_line.b - line_to_test.a).cast<double>().squaredNorm() > heuristic_thr_sqr ||
580 (grid_line.a - line_to_test.b).cast<double>().squaredNorm() > heuristic_thr_sqr ||
581 (grid_line.b - line_to_test.b).cast<double>().squaredNorm() > heuristic_thr_sqr)
582 continue;
583
584 // When lines have too different length, it is necessary to normalize them
585 if (Slic3r::sqr(v1.dot(v2)) > cos_threshold2 * v1_sqr_norm * v2.squaredNorm()) {
586 // The two vectors are nearly collinear (their mutual angle is lower than 30 degrees)
587 if (painted_lines_set.find(*it_contour_and_segment) == painted_lines_set.end()) {
588 if (grid_line.distance_to_squared(line_to_test.a) < append_threshold2 ||
589 grid_line.distance_to_squared(line_to_test.b) < append_threshold2 ||
590 line_to_test.distance_to_squared(grid_line.a) < append_threshold2 ||
591 line_to_test.distance_to_squared(grid_line.b) < append_threshold2) {
592 Line line_to_test_projected;
593 project_line_on_line(grid_line, line_to_test, &line_to_test_projected);
594
595 if ((line_to_test_projected.a - grid_line.a).cast<double>().squaredNorm() > (line_to_test_projected.b - grid_line.a).cast<double>().squaredNorm())
596 line_to_test_projected.reverse();
597
598 painted_lines_set.insert(*it_contour_and_segment);
599 {
600 boost::lock_guard<std::mutex> lock(painted_lines_mutex);
601 painted_lines.push_back({it_contour_and_segment->first, it_contour_and_segment->second, line_to_test_projected, this->color});
602 }
603 }
604 }
605 }
606 }
607 // Continue traversing the grid along the edge.
608 return true;
609 }
static bool project_line_on_line(const Line &projection_l, const Line &projected_l, Line *new_projected)
Definition MultiMaterialSegmentation.cpp:524
constexpr T sqr(T x)
Definition libslic3r.h:301
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:67
@ lock
Definition GLGizmoEmboss.cpp:209
static const double append_threshold2
Definition MultiMaterialSegmentation.cpp:620
static const double append_threshold
Definition MultiMaterialSegmentation.cpp:619
Line line_to_test
Definition MultiMaterialSegmentation.cpp:614
int color
Definition MultiMaterialSegmentation.cpp:616
static const double cos_threshold2
Definition MultiMaterialSegmentation.cpp:618

References Slic3r::Line::a, append_threshold, append_threshold2, Slic3r::Line::b, color, cos_threshold2, Slic3r::Line::distance_to_squared(), grid, Slic3r::Line::length(), 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
562{ 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 PaintedLineVisitor(), and operator()().

◆ line_to_test

Line Slic3r::PaintedLineVisitor::line_to_test

Referenced by operator()().

◆ painted_lines

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

Referenced by PaintedLineVisitor(), and operator()().

◆ painted_lines_mutex

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

Referenced by PaintedLineVisitor(), and 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: