Skip to content

Commit

Permalink
fix voronoi repair
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Jul 24, 2024
1 parent b7a74d4 commit 06779d3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
32 changes: 19 additions & 13 deletions src/libslic3r/Geometry/Voronoi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ VoronoiDiagram::construct_voronoi(const SegmentIterator segment_begin, const Seg
} else {
BOOST_LOG_TRIVIAL(error) << "Detected unknown Voronoi diagram issue, input polygons will be rotated back and forth.";
}

//note: warning, not error as there is a repair possible done by the caller.
if (m_issue_type = try_to_repair_degenerated_voronoi_diagram(segment_begin, segment_end); m_issue_type != IssueType::NO_ISSUE_DETECTED) {
if (m_issue_type == IssueType::MISSING_VORONOI_VERTEX) {
BOOST_LOG_TRIVIAL(error) << "Detected missing Voronoi vertex even after the rotation of input.";
BOOST_LOG_TRIVIAL(warning) << "Detected missing Voronoi vertex even after the rotation of input.";
} else if (m_issue_type == IssueType::NON_PLANAR_VORONOI_DIAGRAM) {
BOOST_LOG_TRIVIAL(error) << "Detected non-planar Voronoi diagram even after the rotation of input.";
BOOST_LOG_TRIVIAL(warning) << "Detected non-planar Voronoi diagram even after the rotation of input.";
} else if (m_issue_type == IssueType::VORONOI_EDGE_INTERSECTING_INPUT_SEGMENT) {
BOOST_LOG_TRIVIAL(error) << "Detected Voronoi edge intersecting input segment even after the rotation of input.";
BOOST_LOG_TRIVIAL(warning) << "Detected Voronoi edge intersecting input segment even after the rotation of input.";
} else if (m_issue_type == IssueType::FINITE_EDGE_WITH_NON_FINITE_VERTEX) {
BOOST_LOG_TRIVIAL(error) << "Detected finite Voronoi vertex with non finite vertex even after the rotation of input.";
BOOST_LOG_TRIVIAL(warning) << "Detected finite Voronoi vertex with non finite vertex even after the rotation of input.";
} else {
BOOST_LOG_TRIVIAL(error) << "Detected unknown Voronoi diagram issue even after the rotation of input.";
BOOST_LOG_TRIVIAL(warning) << "Detected unknown Voronoi diagram issue even after the rotation of input.";
}

m_state = State::REPAIR_UNSUCCESSFUL;
Expand Down Expand Up @@ -156,13 +156,19 @@ typename boost::polygon::enable_if<
VoronoiDiagram::IssueType>::type
VoronoiDiagram::detect_known_issues(const VoronoiDiagram &voronoi_diagram, SegmentIterator segment_begin, SegmentIterator segment_end)
{
if (has_finite_edge_with_non_finite_vertex(voronoi_diagram)) {
return IssueType::FINITE_EDGE_WITH_NON_FINITE_VERTEX;
} else if (const IssueType cell_issue_type = detect_known_voronoi_cell_issues(voronoi_diagram, segment_begin, segment_end); cell_issue_type != IssueType::NO_ISSUE_DETECTED) {
return cell_issue_type;
} else if (!VoronoiUtilsCgal::is_voronoi_diagram_planar_angle(voronoi_diagram, segment_begin, segment_end)) {
// Detection of non-planar Voronoi diagram detects at least GH issues #8474, #8514 and #8446.
return IssueType::NON_PLANAR_VORONOI_DIAGRAM;
try {
if (has_finite_edge_with_non_finite_vertex(voronoi_diagram)) {
return IssueType::FINITE_EDGE_WITH_NON_FINITE_VERTEX;
} else if (const IssueType cell_issue_type = detect_known_voronoi_cell_issues(voronoi_diagram, segment_begin,
segment_end);
cell_issue_type != IssueType::NO_ISSUE_DETECTED) {
return cell_issue_type;
} else if (!VoronoiUtilsCgal::is_voronoi_diagram_planar_angle(voronoi_diagram, segment_begin, segment_end)) {
// Detection of non-planar Voronoi diagram detects at least GH issues #8474, #8514 and #8446.
return IssueType::NON_PLANAR_VORONOI_DIAGRAM;
}
} catch (std::exception) {
return IssueType::UNKNOWN;
}

return IssueType::NO_ISSUE_DETECTED;
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/Geometry/VoronoiUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ typename boost::polygon::enable_if<
VoronoiUtils::get_source_point_index(const VD::cell_type &cell, const SegmentIterator segment_begin, const SegmentIterator segment_end)
{
if (!cell.contains_point())
throw Slic3r::InvalidArgument("Voronoi cell doesn't contain a source point!");
throw Slic3r::InvalidArgument("Voronoi cell doesn't contain a source point index!");

if (cell.source_category() == boost::polygon::SOURCE_CATEGORY_SEGMENT_START_POINT) {
assert(int(cell.source_index()) < std::distance(segment_begin, segment_end));
Expand Down

0 comments on commit 06779d3

Please sign in to comment.