From a6dfe4e74b0a19adbf2145fc57368264c22b1c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= <thomas94@gmx.net> Date: Wed, 4 Jan 2023 09:31:00 +0100 Subject: [PATCH] Add several useful helper functions to `Ray` --- include/neural-graphics-primitives/common.h | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/neural-graphics-primitives/common.h b/include/neural-graphics-primitives/common.h index cf2fcb1..fdf5a99 100644 --- a/include/neural-graphics-primitives/common.h +++ b/include/neural-graphics-primitives/common.h @@ -180,6 +180,28 @@ enum class ESDFGroundTruthMode : int { struct Ray { Eigen::Vector3f o; Eigen::Vector3f d; + + NGP_HOST_DEVICE Eigen::Vector3f operator()(float t) const { + return o + t * d; + } + + NGP_HOST_DEVICE void advance(float t) { + o += d * t; + } + + NGP_HOST_DEVICE float distance_to(const Eigen::Vector3f& p) const { + Eigen::Vector3f nearest = p - o; + nearest -= d * nearest.dot(d) / d.squaredNorm(); + return nearest.norm(); + } + + NGP_HOST_DEVICE bool is_valid() const { + return d != Eigen::Vector3f::Zero(); + } + + static NGP_HOST_DEVICE Ray invalid() { + return {{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}}; + } }; struct TrainingXForm { -- GitLab