Bugfix: custom seam did not work for triangles that were exactly vertical

The projection algorithm was originally made for custom supports, so vertical triangles
were not interesting. They are for seam. Instead of rewriting the algorithm and risking
more bugs, the edge case is detected and the triangle is tilted slightly.
This commit is contained in:
Lukas Matena 2021-02-19 10:57:18 +01:00
parent bd2cbea202
commit 1904b7b904
2 changed files with 32 additions and 26 deletions

View File

@ -750,35 +750,36 @@ void SeamPlacer::apply_custom_seam(const Polygon& polygon, size_t po_idx,
}
}
////////////////////////
// std::ostringstream os;
// os << std::setw(3) << std::setfill('0') << layer_id;
// int a = scale_(30.);
// SVG svg("custom_seam" + os.str() + ".svg", BoundingBox(Point(-a, -a), Point(a, a)));
// //if (! m_enforcers[po_idx].empty())
// // svg.draw(m_enforcers[po_idx][layer_id].polys, "blue");
// //if (! m_blockers[po_idx].empty())
// // svg.draw(m_blockers[po_idx][layer_id].polys, "red");
#if 0
std::ostringstream os;
os << std::setw(3) << std::setfill('0') << layer_id;
int a = scale_(30.);
SVG svg("custom_seam" + os.str() + ".svg", BoundingBox(Point(-a, -a), Point(a, a)));
if (! m_enforcers[po_idx].empty())
svg.draw(m_enforcers[po_idx][layer_id].polys, "blue");
if (! m_blockers[po_idx].empty())
svg.draw(m_blockers[po_idx][layer_id].polys, "red");
if (! blockers_idxs.empty()) {
;
}
size_t min_idx = std::min_element(penalties.begin(), penalties.end()) - penalties.begin();
// size_t min_idx = std::min_element(penalties.begin(), penalties.end()) - penalties.begin();
// //svg.draw(polygon.points[idx_min], "red", 6e5);
// for (size_t i=0; i<polygon.points.size(); ++i) {
// std::string fill;
// coord_t size = 0;
// if (min_idx == i) {
// fill = "yellow";
// size = 5e5;
// } else
// fill = (std::find(enforcers_idxs.begin(), enforcers_idxs.end(), i) != enforcers_idxs.end() ? "green" : "black");
// if (i != 0)
// svg.draw(polygon.points[i], fill, size);
// else
// svg.draw(polygon.points[i], "red", 5e5);
// }
//////////////////////
for (size_t i=0; i<polygon.points.size(); ++i) {
std::string fill;
coord_t size = 5e5;
if (min_idx == i)
fill = "yellow";
else
fill = (std::find(blockers_idxs.begin(), blockers_idxs.end(), i) != blockers_idxs.end() ? "green" : "black");
if (i != 0)
svg.draw(polygon.points[i], fill, size);
else
svg.draw(polygon.points[i], "red", 5e5);
}
#endif
}

View File

@ -2845,6 +2845,11 @@ void PrintObject::project_and_append_custom_facets(
if (! seam && tr_det_sign * z_comp > 0.)
continue;
// The algorithm does not process vertical triangles, but it should for seam.
// In that case, tilt the triangle a bit so the projection does not degenerate.
if (seam && z_comp == 0.f)
facet[0].x() += float(EPSILON);
// Sort the three vertices according to z-coordinate.
std::sort(facet.begin(), facet.end(),
[](const Vec3f& pt1, const Vec3f&pt2) {