Skip to content

Commit

Permalink
Adding test for occlusion rays
Browse files Browse the repository at this point in the history
  • Loading branch information
pshriwise committed Jan 5, 2024
1 parent 5bfbdf1 commit 0a47217
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 18 deletions.
2 changes: 1 addition & 1 deletion include/xdg/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static Property VOID_MATERIAL {PropertyType::MATERIAL, "void"};
enum class RayFireType { VOLUME, POINT_CONTAINMENT, ACCUMULATE_HITS, FIND_VOLUME };

//
enum class HitOrientation { NONE, EXITING, ENTERING };
enum class HitOrientation { ANY, EXITING, ENTERING };

} // namespace xdg

Expand Down
8 changes: 8 additions & 0 deletions include/xdg/embree3.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ inline void rtcIntersect1(RTCScene scene, RTCRayHit* rayhit) {
}
}

inline void rtcOccluded1(RTCScene scene, RTCRay* ray) {
{
RTCIntersectContext context;
rtcInitIntersectContext(&context);
rtcOccluded1(scene, &context, ray);
}
}

#endif // include guard
5 changes: 5 additions & 0 deletions include/xdg/ray_tracing_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class RayTracer {
const Position& origin,
double& dist);

bool occluded(MeshID volume,
const Position& origin,
const Direction& direction,
double& dist) const;

// Accessors
int num_registered_volumes() const { return volume_map_.size(); }

Expand Down
26 changes: 26 additions & 0 deletions src/ray_tracing_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,30 @@ void RayTracer::closest(MeshID volume,
distance = query.dradius;
}

bool RayTracer::occluded(MeshID volume,
const Position& origin,
const Direction& direction,
double& distance) const
{
RTCScene scene = volume_map_.at(volume);

RTCDRay ray;
ray.set_org(origin);
ray.set_dir(direction);
ray.set_tfar(INFTY);
ray.set_tnear(0.0);
ray.rf_type = RayFireType::FIND_VOLUME;
ray.orientation = HitOrientation::ANY;
ray.flags = 0;
ray.mask = -1; // no mask

// fire the ray
{
rtcOccluded1(scene, (RTCRay*)&ray);
}

distance = ray.dtfar;
return distance != INFTY;
}

} // namespace xdg
33 changes: 16 additions & 17 deletions src/triangle_ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,6 @@ void TriangleIntersectionFunc(RTCIntersectFunctionNArguments* args) {
rayhit->hit.dNg[2] = normal[2];
}


void TriangleOcclusionFunc(RTCOccludedFunctionNArguments* args) {
const GeometryUserData* user_data = (const GeometryUserData*) args->geometryUserPtr;
const MeshManager* mesh_manager = user_data->mesh_manager;
const TriangleRef& tri_ref = user_data->tri_ref_buffer[args->primID];

auto vertices = mesh_manager->triangle_vertices(tri_ref.triangle_id);

// get the double precision ray from the args
RTCDRay* ray = (RTCDRay*) args->ray;

double plucker_dist;
if (plucker_ray_tri_intersect(vertices, ray->dorg, ray->ddir, plucker_dist)) {
ray->set_tfar(-INFTY);
}
}

bool TriangleClosestFunc(RTCPointQueryFunctionArguments* args) {
RTCGeometry g = rtcGetGeometry(*(RTCScene*)args->userPtr, args->geomID);
// get the array of DblTri's stored on the geometry
Expand Down Expand Up @@ -140,6 +123,22 @@ bool TriangleClosestFunc(RTCPointQueryFunctionArguments* args) {
}
}

void TriangleOcclusionFunc(RTCOccludedFunctionNArguments* args) {
const GeometryUserData* user_data = (const GeometryUserData*) args->geometryUserPtr;
const MeshManager* mesh_manager = user_data->mesh_manager;
const TriangleRef& tri_ref = user_data->tri_ref_buffer[args->primID];

auto vertices = mesh_manager->triangle_vertices(tri_ref.triangle_id);

// get the double precision ray from the args
RTCDRay* ray = (RTCDRay*) args->ray;

double plucker_dist;
if (plucker_ray_tri_intersect(vertices, ray->dorg, ray->ddir, plucker_dist)) {
ray->set_tfar(-INFTY);
}
}

} // namespace xdg


1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ TEST_NAMES
test_bbox
test_bvh
test_closest
test_occluded
test_ray_fire
test_mesh_internal
test_xdg_interface
Expand Down
34 changes: 34 additions & 0 deletions tests/test_occluded.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

// for testing
#include <catch2/catch_test_macros.hpp>

// xdg includes
#include "xdg/mesh_manager_interface.h"
#include "xdg/ray_tracing_interface.h"

#include "mesh_mock.h"

using namespace xdg;

TEST_CASE("Test Occluded")
{
std::shared_ptr<MeshManager> mm = std::make_shared<MeshMock>();
mm->init(); // this should do nothing, just good practice to call it

std::shared_ptr<RayTracer> rti = std::make_shared<RayTracer>();
rti->register_all_volumes(mm);

// setup ray to fire that won't hit the mock model
Position r {-100.0, 0.0, 0.0};
Direction u {1.0, 0.0, 0.0};
double dist {0.0};

MeshID volume = mm->volumes()[0];

bool result = rti->occluded(volume, r, u, dist);
REQUIRE(result == true);

u = {-1.0, 0.0, 0.0};
result = rti->occluded(volume, r, u, dist);
REQUIRE(result == false);
}

0 comments on commit 0a47217

Please sign in to comment.