Skip to content

Commit

Permalink
Merge pull request #39 from pshriwise/rf-dist-limit
Browse files Browse the repository at this point in the history
Adding distance limit to ray_fire signature
  • Loading branch information
pshriwise authored Dec 24, 2024
2 parents 40f2106 + b8e9f74 commit 056007f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/xdg/ray_tracing_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class RayTracer {
std::pair<double, MeshID> ray_fire(TreeID scene,
const Position& origin,
const Direction& direction,
const double dist_limit = INFTY,
std::vector<MeshID>* const exclude_primitives = nullptr);

void closest(TreeID scene,
Expand Down
1 change: 1 addition & 0 deletions include/xdg/xdg.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ bool point_in_volume(MeshID volume,
std::pair<double, MeshID> ray_fire(MeshID volume,
const Position& origin,
const Direction& direction,
const double dist_limit = INFTY,
std::vector<MeshID>* const exclude_primitives = nullptr) const;

void closest(MeshID volume,
Expand Down
3 changes: 2 additions & 1 deletion src/ray_tracing_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,14 @@ std::pair<double, MeshID>
RayTracer::ray_fire(TreeID scene,
const Position& origin,
const Direction& direction,
const double dist_limit,
std::vector<MeshID>* const exclude_primitves)
{
RTCDRayHit rayhit;
// set ray data
rayhit.ray.set_org(origin);
rayhit.ray.set_dir(direction);
rayhit.ray.set_tfar(INFTY);
rayhit.ray.set_tfar(dist_limit);
rayhit.ray.set_tnear(0.0);
rayhit.ray.rf_type = RayFireType::VOLUME;
rayhit.ray.orientation = HitOrientation::EXITING;
Expand Down
3 changes: 2 additions & 1 deletion src/xdg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ std::pair<double, MeshID>
XDG::ray_fire(MeshID volume,
const Position& origin,
const Direction& direction,
const double dist_limit,
std::vector<MeshID>* const exclude_primitives) const
{
TreeID scene = volume_to_scene_map_.at(volume);
return ray_tracing_interface()->ray_fire(scene, origin, direction, exclude_primitives);
return ray_tracing_interface()->ray_fire(scene, origin, direction, dist_limit, exclude_primitives);
}

void XDG::closest(MeshID volume,
Expand Down
16 changes: 15 additions & 1 deletion tests/test_ray_fire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,18 @@ TEST_CASE("Test Ray Fire Mesh Mock")
direction = {-1.0, 0.0, 0.0};
intersection = rti->ray_fire(volume_tree, origin, direction);
REQUIRE_THAT(intersection.first, Catch::Matchers::WithinAbs(12.0, 1e-6));
}

// limit distance of the ray, shouldn't get a hit
origin = {0.0, 0.0, 0.0};
direction = {1.0, 0.0, 0.0};
intersection = rti->ray_fire(volume_tree, origin, direction, 4.5);
REQUIRE(intersection.second == ID_NONE);

// if the distance is just enough, we should still get a hit
// limit distance of the ray, shouldn't get a hit
origin = {0.0, 0.0, 0.0};
direction = {1.0, 0.0, 0.0};
intersection = rti->ray_fire(volume_tree, origin, direction, 5.1);
REQUIRE(intersection.second != ID_NONE);
REQUIRE_THAT(intersection.first, Catch::Matchers::WithinAbs(5.0, 1e-6));
}
2 changes: 1 addition & 1 deletion tools/particle_sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void initialize() {
}

void surf_dist() {
surface_intersection_ = xdg_->ray_fire(volume_, r_, u_, &history_);
surface_intersection_ = xdg_->ray_fire(volume_, r_, u_, INFTY, &history_);
if (surface_intersection_.first == 0.0) {
fatal_error("Particle {} stuck at position ({}, {}, {}) on surfacce {}", id_, r_.x, r_.y, r_.z, surface_intersection_.second);
alive_ = false;
Expand Down

0 comments on commit 056007f

Please sign in to comment.