Skip to content

Commit

Permalink
Make sure data is contiguous, add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminum committed Dec 12, 2023
1 parent 4928a5a commit 0050f0d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cpp/open3d/t/geometry/TriangleMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
19 changes: 19 additions & 0 deletions python/test/t/geometry/test_trianglemesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 0050f0d

Please sign in to comment.