Skip to content

Commit

Permalink
Fixing Nan errors in Camera Frustum Mesh (#1397)
Browse files Browse the repository at this point in the history
* Issue was that when normalized, the look vector had a slight floating point imprecision that caused this to try and calculate a new up vector. Because the up vector was being rotated based on that floating point imprecision, it was trying to rotate around a (0,0,0) axis which caused nan values

* Adding a test with the look_at and position vectors very close to each other.

* Alternative to rounding the look vector values
  • Loading branch information
emily-howell authored Oct 30, 2024
1 parent 0894b26 commit 50c9589
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1922,8 +1922,8 @@ void generate_camera_meshes(conduit::Node &image_data){
vtkm::Vec<vtkm::Float64,3> forward(0,0,-1);
double angle_between = vtkm::ACos(vtkm::Dot(forward, vtkm_look)) / vtkm::Pi() * 180;

// If the look vector has been rotated by a certain angle, ajust the camera up vector to match
if (angle_between != 0.0) {
// If the look vector has been rotated by a certain angle, adjust the camera up vector to match
if (vtkm::Abs(angle_between) >= 0.001) {
vtkm::Vec<vtkm::Float64,3> axisOfRotation = vtkm::Cross(vtkm_look, forward);
vtkm_up =
vtkm::Transform3DVector(vtkm::Transform3DRotate(-angle_between, axisOfRotation), vtkm_up);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions src/tests/ascent/t_ascent_render_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3004,7 +3004,7 @@ TEST(ascent_render_3d, test_render_3d_camera_frustum_meshes)

EXPECT_TRUE(conduit::blueprint::mesh::verify(data,verify_info));

ASCENT_INFO("Testing 3D rendering of camera frustum meshes");
ASCENT_INFO("Testing 3D rendering of camera frustum meshes\n");

//
// Create the actions.
Expand Down Expand Up @@ -3048,6 +3048,13 @@ TEST(ascent_render_3d, test_render_3d_camera_frustum_meshes)
add_plots["scenes/s1/renders/r4/camera/azimuth"] = 20.0;
add_plots["scenes/s1/renders/r4/camera/elevation"] = -45.0;

// Test that if the look_at location and the position location are quite similar that the frustum
// is still generated without errors.
add_plots["scenes/s1/renders/r5/image_prefix"] =
conduit::utils::join_file_path(output_path, "tout_render_3d_frust_image_nan");
add_plots["scenes/s1/renders/r5/camera/position"] = {0.0, 0.0, 0.0581200011074543};
add_plots["scenes/s1/renders/r5/camera/look_at"] = {0.0, 0.0, 0.0};

//
// Run Ascent to generate images
//
Expand All @@ -3065,7 +3072,7 @@ TEST(ascent_render_3d, test_render_3d_camera_frustum_meshes)
//
// For each image that was generated, run ascent to visualize the camera frustum
//
for (int image_index = 0; image_index<4; image_index++) {
for (int image_index = 0; image_index<5; image_index++) {
conduit::Node &image_node = ascent_info["images"][image_index];
conduit::Node camera_data = image_node["camera/camera_frustum_mesh"];

Expand Down

0 comments on commit 50c9589

Please sign in to comment.