From 0050f0d0b8c698c78324dbd8dd1ad6c982bac5b8 Mon Sep 17 00:00:00 2001 From: Benjamin Ummenhofer Date: Tue, 12 Dec 2023 15:49:54 +0100 Subject: [PATCH] Make sure data is contiguous, add unit tests --- cpp/open3d/t/geometry/TriangleMesh.cpp | 4 ++-- python/test/t/geometry/test_trianglemesh.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/cpp/open3d/t/geometry/TriangleMesh.cpp b/cpp/open3d/t/geometry/TriangleMesh.cpp index 9a05ae64924..3c1766e3b65 100644 --- a/cpp/open3d/t/geometry/TriangleMesh.cpp +++ b/cpp/open3d/t/geometry/TriangleMesh.cpp @@ -301,10 +301,10 @@ double TriangleMesh::GetSurfaceArea() const { if (IsCPU()) { kernel::trianglemesh::ComputeTriangleAreasCPU( - GetVertexPositions(), GetTriangleIndices(), triangle_areas); + GetVertexPositions().Contiguous(), GetTriangleIndices().Contiguous(), triangle_areas); } else if (IsCUDA()) { CUDA_CALL(kernel::trianglemesh::ComputeTriangleAreasCUDA, - GetVertexPositions(), GetTriangleIndices(), triangle_areas); + GetVertexPositions().Contiguous(), GetTriangleIndices().Contiguous(), triangle_areas); } else { utility::LogError("Unimplemented device"); } diff --git a/python/test/t/geometry/test_trianglemesh.py b/python/test/t/geometry/test_trianglemesh.py index 843184dd3e6..270bfb3dc9f 100644 --- a/python/test/t/geometry/test_trianglemesh.py +++ b/python/test/t/geometry/test_trianglemesh.py @@ -417,3 +417,22 @@ def test_pickle(device): mesh.vertex.positions.cpu().numpy()) np.testing.assert_equal(mesh_load.triangle.indices.cpu().numpy(), mesh.triangle.indices.cpu().numpy()) + +@pytest.mark.parametrize("device", list_devices()) +def test_get_surface_area(device): + # Test with custom parameters. + cube = o3d.t.geometry.TriangleMesh.create_box( + float_dtype=o3c.float64, int_dtype=o3c.int32, device=device) + np.testing.assert_equal(cube.get_surface_area(), 6) + + empty = o3d.t.geometry.TriangleMesh(device=device) + empty.get_surface_area() + np.testing.assert_equal(empty.get_surface_area(), 0) + + # test noncontiguous + sphere =o3d.t.geometry.TriangleMesh.create_sphere(device=device) + area1 = sphere.get_surface_area() + sphere.vertex.positions = sphere.vertex.positions.T().contiguous().T() + sphere.triangle.indices = sphere.triangle.indices.T().contiguous().T() + area2 = sphere.get_surface_area() + np.testing.assert_almost_equal(area1, area2) \ No newline at end of file