Skip to content

Commit

Permalink
Re-review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nebraszka committed Mar 5, 2024
1 parent cf763c2 commit ae8df93
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 23 deletions.
3 changes: 2 additions & 1 deletion include/rgl/api/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,8 @@ RGL_API rgl_status_t rgl_node_raytrace_configure_distortion(rgl_node_t node, boo

/**
* Modifies RaytraceNode to set non-hit values for distance.
* Sets and differentiates non-hit values for the RGL_FIELD_DISTANCE_F32 field, specifically:
* Default non-hit value for the RGL_FIELD_DISTANCE_F32 field is set to infinity.
* This function allows to set custom values:
* - for non-hits closer than a minimum range (`near`),
* - for non-hits beyond a maximum range (`far`).
* Concurrently, it computes the RGL_FIELD_XYZ_VEC3_F32 field for these non-hit scenarios based on these distances, along with ray origin and direction.
Expand Down
6 changes: 4 additions & 2 deletions src/gpu/optixPrograms.cu
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ __forceinline__ __device__ void saveNonHitRayResult(float nonHitDistance)
Mat3x4f ray = ctx.rays[optixGetLaunchIndex().x];
Vec3f origin = ray * Vec3f{0, 0, 0};
Vec3f dir = ray * Vec3f{0, 0, 1} - origin;
Vec3f xyz = origin + dir.normalized() * nonHitDistance;
xyz = {isnan(xyz.x()) ? 0 : xyz.x(), isnan(xyz.y()) ? 0 : xyz.y(), isnan(xyz.z()) ? 0 : xyz.z()};
Vec3f displacement = dir.normalized() * nonHitDistance;
displacement = {isnan(displacement.x()) ? 0 : displacement.x(), isnan(displacement.y()) ? 0 : displacement.y(),
isnan(displacement.z()) ? 0 : displacement.z()};
Vec3f xyz = origin + displacement;
saveRayResult<false>(xyz, nonHitDistance, 0, RGL_ENTITY_INVALID_ID, Vec3f{NAN}, Vec3f{NAN}, NAN, Vec3f{NAN}, NAN);
}

Expand Down
1 change: 0 additions & 1 deletion test/include/helpers/commonHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

static constexpr float EPSILON_F = 1e-6f;
static constexpr int maxGPUCoresTestCount = 20000;
static constexpr float INF = std::numeric_limits<float>::infinity();

#define EXPECT_RGL_SUCCESS(status) EXPECT_EQ(status, rgl_status_t::RGL_SUCCESS)
#define ASSERT_RGL_SUCCESS(status) ASSERT_EQ(status, rgl_status_t::RGL_SUCCESS)
Expand Down
11 changes: 5 additions & 6 deletions test/src/graph/DistanceFieldTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class DistanceFieldTest : public RGLTestWithParam<float>
ASSERT_RGL_SUCCESS(rgl_node_rays_from_mat3x4f(&useRaysNode, rayTf.data(), rayTf.size()));
ASSERT_RGL_SUCCESS(rgl_node_rays_set_range(&setRangeNode, &raytraceRange, 1));
ASSERT_RGL_SUCCESS(rgl_node_raytrace(&raytraceNode, nullptr));
EXPECT_RGL_SUCCESS(rgl_node_raytrace_configure_non_hits(raytraceNode, INF, INF));
ASSERT_RGL_SUCCESS(rgl_node_points_yield(&yieldPointsNode, fields.data(), fields.size()));
}

Expand Down Expand Up @@ -149,8 +148,8 @@ TEST_F(DistanceFieldTest, should_compute_nonhit_distance_for_object_off_ray_path
connectNodes(false);
getResults();

EXPECT_EQ(outDistances.at(0), INF);
EXPECT_EQ(outDistances.at(1), INF);
EXPECT_EQ(outDistances.at(0), std::numeric_limits<float>::infinity());
EXPECT_EQ(outDistances.at(1), std::numeric_limits<float>::infinity());
}

TEST_P(DistanceFieldTest, should_compute_nonhit_distance_for_object_out_of_max_range)
Expand All @@ -166,7 +165,7 @@ TEST_P(DistanceFieldTest, should_compute_nonhit_distance_for_object_out_of_max_r

getResults();

EXPECT_EQ(outDistances.at(0), INF);
EXPECT_EQ(outDistances.at(0), std::numeric_limits<float>::infinity());
}

TEST_P(DistanceFieldTest, should_compute_nonhit_distance_for_object_out_of_min_range)
Expand All @@ -182,7 +181,7 @@ TEST_P(DistanceFieldTest, should_compute_nonhit_distance_for_object_out_of_min_r

getResults();

EXPECT_EQ(outDistances.at(0), INF);
EXPECT_EQ(outDistances.at(0), std::numeric_limits<float>::infinity());
}

TEST_P(DistanceFieldTest, object_in_range_behind_object_out_of_min_range)
Expand All @@ -202,7 +201,7 @@ TEST_P(DistanceFieldTest, object_in_range_behind_object_out_of_min_range)

getResults();

EXPECT_EQ(outDistances.at(0), INF);
EXPECT_EQ(outDistances.at(0), std::numeric_limits<float>::infinity());
}

TEST_P(DistanceFieldTest, should_compute_correct_distances_for_various_ray_angles)
Expand Down
1 change: 0 additions & 1 deletion test/src/graph/VelocityDistortionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ TEST_F(VelocityDistortionTest, smoke_test)
EXPECT_RGL_SUCCESS(rgl_node_raytrace(&raytrace, nullptr));
EXPECT_RGL_SUCCESS(rgl_node_raytrace_configure_velocity(raytrace, &linearVelocity, &angularVelocity));
EXPECT_RGL_SUCCESS(rgl_node_raytrace_configure_distortion(raytrace, true));
EXPECT_RGL_SUCCESS(rgl_node_raytrace_configure_non_hits(raytrace, INF, INF));
EXPECT_RGL_SUCCESS(rgl_node_points_yield(&yield, outFields.data(), outFields.size()));

EXPECT_RGL_SUCCESS(rgl_graph_node_add_child(useRays, offsetsNode));
Expand Down
20 changes: 8 additions & 12 deletions test/src/graph/nodes/RaytraceNodeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ TEST_F(RaytraceNodeTest, config_non_hits_should_not_impact_hits)
float resolution = 30.0f;
std::vector<rgl_mat3x4f> rays = makeLidar3dRays(fovX, fovY, resolution, resolution);

rgl_node_t rangeRaysNode = nullptr;
std::vector<rgl_vec2f> ranges{
rgl_vec2f{0.0f, CUBE_HALF_EDGE + 1.0f} // Ray should hit the cube
};

std::vector<rgl_field_t> outFields{XYZ_VEC3_F32, IS_HIT_I32, DISTANCE_F32};

/**
Expand All @@ -125,10 +130,12 @@ TEST_F(RaytraceNodeTest, config_non_hits_should_not_impact_hits)
rgl_node_t yieldNode = nullptr;

ASSERT_RGL_SUCCESS(rgl_node_rays_from_mat3x4f(&raysNode, rays.data(), rays.size()));
ASSERT_RGL_SUCCESS(rgl_node_rays_set_range(&rangeRaysNode, ranges.data(), ranges.size()));
ASSERT_RGL_SUCCESS(rgl_node_raytrace(&raytraceNode, nullptr));
ASSERT_RGL_SUCCESS(rgl_node_points_yield(&yieldNode, outFields.data(), outFields.size()));

ASSERT_RGL_SUCCESS(rgl_graph_node_add_child(raysNode, raytraceNode));
ASSERT_RGL_SUCCESS(rgl_graph_node_add_child(raysNode, rangeRaysNode));
ASSERT_RGL_SUCCESS(rgl_graph_node_add_child(rangeRaysNode, raytraceNode));
ASSERT_RGL_SUCCESS(rgl_graph_node_add_child(raytraceNode, yieldNode));

ASSERT_RGL_SUCCESS(rgl_graph_run(raysNode));
Expand All @@ -143,22 +150,11 @@ TEST_F(RaytraceNodeTest, config_non_hits_should_not_impact_hits)
* Hits with raytrace non hits configuration scenario
*/

rgl_node_t rangeRaysNode = nullptr;
std::vector<rgl_vec2f> ranges{
rgl_vec2f{0.0f, CUBE_HALF_EDGE + 1.0f} // Ray should hit the cube
};

ASSERT_RGL_SUCCESS(rgl_node_rays_set_range(&rangeRaysNode, ranges.data(), ranges.size()));

const float nearNonHitDistance = 123.0f;
const float farNonHitDistance = 321.0f;

ASSERT_RGL_SUCCESS(rgl_node_raytrace_configure_non_hits(raytraceNode, nearNonHitDistance, farNonHitDistance));

ASSERT_RGL_SUCCESS(rgl_graph_node_remove_child(raysNode, raytraceNode));
ASSERT_RGL_SUCCESS(rgl_graph_node_add_child(raysNode, rangeRaysNode));
ASSERT_RGL_SUCCESS(rgl_graph_node_add_child(rangeRaysNode, raytraceNode));

ASSERT_RGL_SUCCESS(rgl_graph_run(raysNode));

TestPointCloud outPointCloud = TestPointCloud::createFromNode(yieldNode, outFields);
Expand Down

0 comments on commit ae8df93

Please sign in to comment.