Commit 780e2315 authored by Patrick Labatut's avatar Patrick Labatut Committed by Facebook GitHub Bot
Browse files

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
parent a0f79318
...@@ -6,7 +6,7 @@ import torch.nn as nn ...@@ -6,7 +6,7 @@ import torch.nn as nn
from pytorch3d.structures import Meshes 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 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 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): ...@@ -396,7 +396,7 @@ def create_verts_index(verts_per_mesh, edges_per_mesh, device=None):
return verts_idx 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 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 stacked at the end of the original faces tensor, so in order to have
......
...@@ -11,7 +11,7 @@ from pytorch3d.utils.ico_sphere import ico_sphere ...@@ -11,7 +11,7 @@ from pytorch3d.utils.ico_sphere import ico_sphere
class TestSubdivideMeshes(TestCaseMixin, unittest.TestCase): 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 # Create a mesh with one face and check the subdivided mesh has
# 4 faces with the correct vertex coordinates. # 4 faces with the correct vertex coordinates.
device = torch.device("cuda:0") device = torch.device("cuda:0")
...@@ -23,7 +23,8 @@ class TestSubdivideMeshes(TestCaseMixin, unittest.TestCase): ...@@ -23,7 +23,8 @@ class TestSubdivideMeshes(TestCaseMixin, unittest.TestCase):
) )
faces = torch.tensor([[0, 1, 2]], dtype=torch.int64, device=device) faces = torch.tensor([[0, 1, 2]], dtype=torch.int64, device=device)
mesh = Meshes(verts=[verts], faces=[faces]) 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) new_mesh = subdivide(mesh)
# Subdivided face: # Subdivided face:
...@@ -61,6 +62,12 @@ class TestSubdivideMeshes(TestCaseMixin, unittest.TestCase): ...@@ -61,6 +62,12 @@ class TestSubdivideMeshes(TestCaseMixin, unittest.TestCase):
self.assertClose(new_faces, gt_subdivide_faces) self.assertClose(new_faces, gt_subdivide_faces)
self.assertTrue(new_verts.requires_grad == verts.requires_grad) 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): def test_heterogeneous_meshes(self):
device = torch.device("cuda:0") device = torch.device("cuda:0")
verts1 = torch.tensor( verts1 = torch.tensor(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment