Skip to content

Commit c292c71

Browse files
adaGrad1facebook-github-bot
authored andcommitted
c++ marching cubes fix
Summary: Fixes #1641. The bug was caused by the mistaken downcasting of an int64_t into int, causing issues only on inputs large enough to have hashes that escaped the bounds of an int32. Also added a test case for this issue. Reviewed By: bottler Differential Revision: D53505370 fbshipit-source-id: 0fdd0efc6d259cc3b0263e7ff3a4ab2c648ec521
1 parent d0d9cae commit c292c71

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pytorch3d/csrc/marching_cubes/marching_cubes_cpu.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ std::tuple<at::Tensor, at::Tensor, at::Tensor> MarchingCubesCpu(
7171
if ((j + 1) % 3 == 0 && ps[0] != ps[1] && ps[1] != ps[2] &&
7272
ps[2] != ps[0]) {
7373
for (int k = 0; k < 3; k++) {
74-
int v = tri[k];
75-
edge_id_to_v[tri.at(k)] = ps.at(k);
74+
int64_t v = tri.at(k);
75+
edge_id_to_v[v] = ps.at(k);
7676
if (!uniq_edge_id.count(v)) {
7777
uniq_edge_id[v] = verts.size();
7878
verts.push_back(edge_id_to_v[v]);

tests/test_marching_cubes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,18 @@ def test_double_ellipsoid(self):
854854
self.assertClose(verts2[0], expected_verts)
855855
self.assertClose(faces2[0], expected_faces)
856856

857+
def test_single_large_ellipsoid(self):
858+
if USE_SCIKIT:
859+
from skimage.draw import ellipsoid
860+
861+
ellip_base = ellipsoid(50, 60, 16, levelset=True)
862+
volume = torch.Tensor(ellip_base).unsqueeze(0).cpu()
863+
verts, faces = marching_cubes_naive(volume, 0)
864+
verts2, faces2 = marching_cubes(volume, 0)
865+
866+
self.assertClose(verts[0], verts2[0], atol=1e-6)
867+
self.assertClose(faces[0], faces2[0], atol=1e-6)
868+
857869
def test_cube_surface_area(self):
858870
if USE_SCIKIT:
859871
from skimage.measure import marching_cubes_classic, mesh_surface_area

0 commit comments

Comments
 (0)