fix subdivide_meshes with empty mesh #1788

Summary:
Simplify code

fixes https://github.com/facebookresearch/pytorch3d/issues/1788

Reviewed By: MichaelRamamonjisoa

Differential Revision: D61847675

fbshipit-source-id: 48400875d1d885bb3615bc9f4b3c7c3d822b67e7
This commit is contained in:
Jeremy Reizenstein
2024-11-06 11:40:26 -08:00
committed by Facebook GitHub Bot
parent c434957b2a
commit 8fe6934885
2 changed files with 21 additions and 77 deletions

View File

@@ -217,6 +217,15 @@ class TestSubdivideMeshes(TestCaseMixin, unittest.TestCase):
self.assertClose(new_feats, gt_feats)
self.assertTrue(new_feats.requires_grad == gt_feats.requires_grad)
def test_with_empty(self):
verts_list = [[[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]], []]
faces_list = [[[0, 1, 2], [0, 2, 3]], []]
verts_list = [torch.tensor(verts, dtype=torch.float64) for verts in verts_list]
face_list = [torch.tensor(faces, dtype=torch.long) for faces in faces_list]
meshes = Meshes(verts=verts_list, faces=face_list)
subdivided_meshes = SubdivideMeshes()(meshes)
self.assertEqual(len(subdivided_meshes), 2)
@staticmethod
def subdivide_meshes_with_init(num_meshes: int = 10, same_topo: bool = False):
device = torch.device("cuda:0")