Performance improvements in raycaster

This commit is contained in:
tamasmeszaros 2020-01-08 17:12:06 +01:00
parent bb62f36df3
commit 578fcbc37c
2 changed files with 12 additions and 9 deletions

View file

@ -333,20 +333,23 @@ EigenMesh3D::hit_result EigenMesh3D::filter_hits(
bool entry; bool entry;
}; };
std::vector<HoleHit> hole_isects; std::vector<HoleHit> hole_isects;
hole_isects.reserve(m_holes.size());
auto sf = s.cast<float>();
auto dirf = dir.cast<float>();
// Collect hits on all holes, preserve information about entry/exit // Collect hits on all holes, preserve information about entry/exit
for (const sla::DrainHole& hole : m_holes) { for (const sla::DrainHole& hole : m_holes) {
std::array<std::pair<float, Vec3d>, 2> isects; std::array<std::pair<float, Vec3d>, 2> isects;
if (hole.get_intersections(s.cast<float>(), if (hole.get_intersections(sf, dirf, isects)) {
dir.cast<float>(), isects)) { if (isects[0].first > 0.f) hole_isects.emplace_back(isects[0].first, isects[0].second, true);
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);
hole_isects.emplace_back(isects[1].first, isects[1].second, false);
} }
} }
// Remove hole hits behind the source // // Remove hole hits behind the source
for (int i=0; i<int(hole_isects.size()); ++i) // for (int i=0; i<int(hole_isects.size()); ++i)
if (hole_isects[i].t < 0.f) // if (hole_isects[i].t < 0.f)
hole_isects.erase(hole_isects.begin() + (i--)); // hole_isects.erase(hole_isects.begin() + (i--));
// Holes can intersect each other, sort the hits by t // Holes can intersect each other, sort the hits by t
std::sort(hole_isects.begin(), hole_isects.end(), std::sort(hole_isects.begin(), hole_isects.end(),

View file

@ -68,7 +68,7 @@ public:
inline const Vec3d& source() const { return m_source; } inline const Vec3d& source() const { return m_source; }
inline Vec3d position() const { return m_source + m_dir * m_t; } inline Vec3d position() const { return m_source + m_dir * m_t; }
inline bool is_valid() const { return m_mesh != nullptr; } inline bool is_valid() const { return m_mesh != nullptr; }
inline bool is_hit() const { return m_t != infty(); } inline bool is_hit() const { return !std::isinf(m_t); }
// Hit_result can decay into a double as the hit distance. // Hit_result can decay into a double as the hit distance.
inline operator double() const { return distance(); } inline operator double() const { return distance(); }