From 780e231536a54f5e28fbc6592cf3509b053b0483 Mon Sep 17 00:00:00 2001 From: Patrick Labatut Date: Mon, 14 Jun 2021 04:02:14 -0700 Subject: [PATCH] Increase code coverage of subdivide_meshes Summary: Increase code coverage of subdivide_meshes and re-include it in code coverage test Reviewed By: bottler Differential Revision: D29097476 fbshipit-source-id: 3403ae38a90c4b53f24188eed11faae202a235b5 --- pytorch3d/ops/subdivide_meshes.py | 4 ++-- tests/test_subdivide_meshes.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pytorch3d/ops/subdivide_meshes.py b/pytorch3d/ops/subdivide_meshes.py index f02c04c6..417a1447 100644 --- a/pytorch3d/ops/subdivide_meshes.py +++ b/pytorch3d/ops/subdivide_meshes.py @@ -6,7 +6,7 @@ import torch.nn as nn from pytorch3d.structures import Meshes -class SubdivideMeshes(nn.Module): # pragma: no cover +class SubdivideMeshes(nn.Module): """ Subdivide a triangle mesh by adding a new vertex at the center of each edge and dividing each face into four new faces. Vectors of vertex @@ -396,7 +396,7 @@ def create_verts_index(verts_per_mesh, edges_per_mesh, device=None): return verts_idx -def create_faces_index(faces_per_mesh, device=None): # pragma: no cover +def create_faces_index(faces_per_mesh, device=None): """ Helper function to group the faces indices for each mesh. New faces are stacked at the end of the original faces tensor, so in order to have diff --git a/tests/test_subdivide_meshes.py b/tests/test_subdivide_meshes.py index ba6da2a1..6b5d2f6f 100644 --- a/tests/test_subdivide_meshes.py +++ b/tests/test_subdivide_meshes.py @@ -11,7 +11,7 @@ from pytorch3d.utils.ico_sphere import ico_sphere class TestSubdivideMeshes(TestCaseMixin, unittest.TestCase): - def test_simple_subdivide(self): + def simple_subdivide(self, with_init=False): # Create a mesh with one face and check the subdivided mesh has # 4 faces with the correct vertex coordinates. device = torch.device("cuda:0") @@ -23,7 +23,8 @@ class TestSubdivideMeshes(TestCaseMixin, unittest.TestCase): ) faces = torch.tensor([[0, 1, 2]], dtype=torch.int64, device=device) mesh = Meshes(verts=[verts], faces=[faces]) - subdivide = SubdivideMeshes() + mesh_init = mesh.clone() if with_init else None + subdivide = SubdivideMeshes(meshes=mesh_init) new_mesh = subdivide(mesh) # Subdivided face: @@ -61,6 +62,12 @@ class TestSubdivideMeshes(TestCaseMixin, unittest.TestCase): self.assertClose(new_faces, gt_subdivide_faces) self.assertTrue(new_verts.requires_grad == verts.requires_grad) + def test_simple_subdivide(self): + self.simple_subdivide() + + def test_simple_subdivide_with_init(self): + self.simple_subdivide(with_init=True) + def test_heterogeneous_meshes(self): device = torch.device("cuda:0") verts1 = torch.tensor(