Skip to content

Commit e42b0c4

Browse files
bottlerfacebook-github-bot
authored andcommitted
Mesh normal consistency when no faces intersect
Summary: Corner case where there's nothing to do in this function. Reviewed By: nikhilaravi Differential Revision: D26073476 fbshipit-source-id: eb061683ffe35c1ffa8384c422a1557a636d52cd
1 parent 7f62eac commit e42b0c4

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

pytorch3d/loss/mesh_normal_consistency.py

+5
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ def mesh_normal_consistency(meshes):
114114
vert_edge_pair_idx, device=meshes.device, dtype=torch.int64
115115
)
116116

117+
if vert_edge_pair_idx.shape[0] == 0:
118+
return torch.tensor(
119+
[0.0], dtype=torch.float32, device=meshes.device, requires_grad=True
120+
)
121+
117122
v0_idx = edges_packed[edge_idx, 0]
118123
v0 = verts_packed[v0_idx]
119124
v1_idx = edges_packed[edge_idx, 1]

tests/test_mesh_normal_consistency.py

+11
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,17 @@ def test_mesh_normal_consistency(self):
218218

219219
self.assertTrue(torch.allclose(out1, out2))
220220

221+
def test_no_intersection(self):
222+
"""
223+
Test Mesh Normal Consistency for a mesh known to have no
224+
intersecting faces.
225+
"""
226+
verts = torch.rand(1, 6, 2)
227+
faces = torch.arange(6).reshape(1, 2, 3)
228+
meshes = Meshes(verts=verts, faces=faces)
229+
out = mesh_normal_consistency(meshes)
230+
self.assertEqual(out.item(), 0)
231+
221232
@staticmethod
222233
def mesh_normal_consistency_with_ico(
223234
num_meshes: int, level: int = 3, device: str = "cpu"

0 commit comments

Comments
 (0)