Skip to content

Commit

Permalink
revert to original python code test
Browse files Browse the repository at this point in the history
  • Loading branch information
yxlao committed Dec 28, 2024
1 parent 3c4b5af commit cf9e01e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 44 deletions.
3 changes: 1 addition & 2 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

def pytest_configure(config):
config.addinivalue_line(
"markers",
"skip_no_o3d_display: skip test when no display is available",
"markers", "skip_no_o3d_display: skip test when no display is available"
)


Expand Down
30 changes: 7 additions & 23 deletions test/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,7 @@ def gen_random_pose():
[-axis[1], axis[0], 0],
]
)
RT = (
np.eye(3)
+ np.sin(angle) * ss
+ (1 - np.cos(angle)) * np.dot(ss, ss)
)
RT = np.eye(3) + np.sin(angle) * ss + (1 - np.cos(angle)) * np.dot(ss, ss)
c = np.random.uniform(-10, 10, size=(3,))
pose = np.eye(4)
pose[:3, :3] = RT
Expand All @@ -142,12 +138,8 @@ def gen_random_pose():
pose_gl = ct.convert.pose_opencv_to_opengl(pose_cv)
pose_cv_recovered = ct.convert.pose_opengl_to_opencv(pose_gl)
pose_gl_recovered = ct.convert.pose_opencv_to_opengl(pose_cv_recovered)
np.testing.assert_allclose(
pose_cv, pose_cv_recovered, rtol=1e-5, atol=1e-5
)
np.testing.assert_allclose(
pose_gl, pose_gl_recovered, rtol=1e-5, atol=1e-5
)
np.testing.assert_allclose(pose_cv, pose_cv_recovered, rtol=1e-5, atol=1e-5)
np.testing.assert_allclose(pose_gl, pose_gl_recovered, rtol=1e-5, atol=1e-5)

# Test convert T bidirectionally
T_cv = np.copy(T)
Expand Down Expand Up @@ -216,12 +208,8 @@ def gen_random_T():
pose_gl = ct.convert.pose_opencv_to_opengl(pose_cv)
pose_cv_recovered = ct.convert.pose_opengl_to_opencv(pose_gl)
pose_gl_recovered = ct.convert.pose_opencv_to_opengl(pose_cv_recovered)
np.testing.assert_allclose(
pose_cv, pose_cv_recovered, rtol=1e-5, atol=1e-5
)
np.testing.assert_allclose(
pose_gl, pose_gl_recovered, rtol=1e-5, atol=1e-5
)
np.testing.assert_allclose(pose_cv, pose_cv_recovered, rtol=1e-5, atol=1e-5)
np.testing.assert_allclose(pose_gl, pose_gl_recovered, rtol=1e-5, atol=1e-5)

# Test T and pose are consistent across conversions
np.testing.assert_allclose(
Expand Down Expand Up @@ -304,9 +292,7 @@ def test_im_depth_im_distance_convert():
# Geometries
sphere = o3d.geometry.TriangleMesh.create_sphere(radius=1.0)
sphere = sphere.translate([0, 0, 4])
box = o3d.geometry.TriangleMesh.create_box(
width=1.5, height=1.5, depth=1.5
)
box = o3d.geometry.TriangleMesh.create_box(width=1.5, height=1.5, depth=1.5)
box = box.translate([0, 0, 4])
mesh = sphere + box

Expand All @@ -327,6 +313,4 @@ def test_im_depth_im_distance_convert():
im_depth_reconstructed = ct.convert.im_distance_to_im_depth(im_distance, K)

# Assert that the reconstructed depth is close to the original
np.testing.assert_allclose(
im_depth, im_depth_reconstructed, rtol=1e-5, atol=1e-5
)
np.testing.assert_allclose(im_depth, im_depth_reconstructed, rtol=1e-5, atol=1e-5)
4 changes: 1 addition & 3 deletions test/test_raycast.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ def test_mesh_to_depth(visualize: bool):
# Geometries
sphere = o3d.geometry.TriangleMesh.create_sphere(radius=1.0)
sphere = sphere.translate([0, 0, 4])
box = o3d.geometry.TriangleMesh.create_box(
width=1.5, height=1.5, depth=1.5
)
box = o3d.geometry.TriangleMesh.create_box(width=1.5, height=1.5, depth=1.5)
box = box.translate([0, 0, 4])
mesh = sphere + box
lineset = ct.convert.mesh_to_lineset(mesh)
Expand Down
21 changes: 5 additions & 16 deletions test/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@ def test_render_geometries(visualize: bool):
See conftest.py for more information on the visualize fixture.
"""
# Setup geometries: sphere (red), box (blue)
sphere = o3d.geometry.TriangleMesh.create_sphere(
radius=1.0, resolution=100
)
sphere = o3d.geometry.TriangleMesh.create_sphere(radius=1.0, resolution=100)
sphere = sphere.translate([0, 0, 4])
sphere = sphere.paint_uniform_color([0.2, 0.4, 0.8])
sphere.compute_vertex_normals()
box = o3d.geometry.TriangleMesh.create_box(
width=1.5, height=1.5, depth=1.5
)
box = o3d.geometry.TriangleMesh.create_box(width=1.5, height=1.5, depth=1.5)
box = box.translate([0, 0, 4])
box = box.paint_uniform_color([0.8, 0.2, 0.2])
box.compute_vertex_normals()
Expand Down Expand Up @@ -69,11 +65,7 @@ def test_render_geometries(visualize: bool):
im_raycast_depth[im_raycast_depth == np.inf] = 0

# Heuristic checks of RGB rendering
assert im_render_rgb.shape == (
height,
width,
3,
), "Image has incorrect dimensions"
assert im_render_rgb.shape == (height, width, 3), "Image has incorrect dimensions"
num_white_pixels = np.sum(
(im_render_rgb[:, :, 0] > 0.9)
& (im_render_rgb[:, :, 1] > 0.9)
Expand All @@ -89,9 +81,7 @@ def test_render_geometries(visualize: bool):
& (im_render_rgb[:, :, 1] < 0.3)
& (im_render_rgb[:, :, 2] < 0.5)
)
assert num_white_pixels > (
height * width * 0.5
), "Expected mostly white background"
assert num_white_pixels > (height * width * 0.5), "Expected mostly white background"
assert num_blue_pixels > 100, "Expected blue pixels (sphere) not found"
assert num_red_pixels > 100, "Expected red pixels (box) not found"

Expand All @@ -108,8 +98,7 @@ def test_render_geometries(visualize: bool):
im_render_rgb_mask.astype(float) - im_render_depth_mask.astype(float)
)
im_mask_diff_raycast_vs_render = np.abs(
im_raycast_depth_mask.astype(float)
- im_render_depth_mask.astype(float)
im_raycast_depth_mask.astype(float) - im_render_depth_mask.astype(float)
)
assert (
np.mean(im_mask_diff_rgb_vs_raycast) < 0.01
Expand Down

0 comments on commit cf9e01e

Please sign in to comment.