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