From f22961edaed244337f463fefad1634a0883c727f Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Thu, 9 Jan 2020 14:06:39 +0100 Subject: [PATCH] Fixed a raycaster problem with handling duplicate hits from igl The duplicate hits confused winding number calculations in the raycaster, which in turn returned incorrect hit. --- src/libslic3r/SLA/Common.cpp | 14 +++++++++----- tests/sla_print/sla_raycast_tests.cpp | 3 +-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/libslic3r/SLA/Common.cpp b/src/libslic3r/SLA/Common.cpp index a0fc2f3bb..3d31c5522 100644 --- a/src/libslic3r/SLA/Common.cpp +++ b/src/libslic3r/SLA/Common.cpp @@ -297,7 +297,14 @@ EigenMesh3D::query_ray_hits(const Vec3d &s, const Vec3d &dir) const // The sort is necessary, the hits are not always sorted. std::sort(hits.begin(), hits.end(), [](const igl::Hit& a, const igl::Hit& b) { return a.t < b.t; }); - + + // Remove duplicates. They sometimes appear, for example when the ray is cast + // along an axis of a cube due to floating-point approximations in igl (?) + hits.erase(std::unique(hits.begin(), hits.end(), + [](const igl::Hit& a, const igl::Hit& b) + { return a.t == b.t; }), + hits.end()); + // Convert the igl::Hit into hit_result outs.reserve(hits.size()); for (const igl::Hit& hit : hits) { @@ -342,14 +349,11 @@ EigenMesh3D::hit_result EigenMesh3D::filter_hits( for (const sla::DrainHole& hole : m_holes) { std::array, 2> isects; if (hole.get_intersections(sf, dirf, isects)) { + // Ignore hole hits behind the source if (isects[0].first > 0.f) hole_isects.emplace_back(isects[0].first, isects[0].second, true); if (isects[1].first > 0.f) hole_isects.emplace_back(isects[1].first, isects[1].second, false); } } -// // Remove hole hits behind the source -// for (int i=0; i