mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2026-01-17 03:40:34 +08:00
refactor laplacian matrices
Summary: Refactor of all functions to compute laplacian matrices in one file. Support for: * Standard Laplacian * Cotangent Laplacian * Norm Laplacian Reviewed By: nikhilaravi Differential Revision: D29297466 fbshipit-source-id: b96b88915ce8ef0c2f5693ec9b179fd27b70abf9
This commit is contained in:
committed by
Facebook GitHub Bot
parent
da9974b416
commit
07a5a68d50
@@ -406,34 +406,6 @@ class TestMeshes(TestCaseMixin, unittest.TestCase):
|
||||
self.assertFalse(newv.requires_grad)
|
||||
self.assertClose(newv, v)
|
||||
|
||||
def test_laplacian_packed(self):
|
||||
def naive_laplacian_packed(meshes):
|
||||
verts_packed = meshes.verts_packed()
|
||||
edges_packed = meshes.edges_packed()
|
||||
V = verts_packed.shape[0]
|
||||
|
||||
L = torch.zeros((V, V), dtype=torch.float32, device=meshes.device)
|
||||
for e in edges_packed:
|
||||
L[e[0], e[1]] = 1
|
||||
# symetric
|
||||
L[e[1], e[0]] = 1
|
||||
|
||||
deg = L.sum(1).view(-1, 1)
|
||||
deg[deg > 0] = 1.0 / deg[deg > 0]
|
||||
L = L * deg
|
||||
diag = torch.eye(V, dtype=torch.float32, device=meshes.device)
|
||||
L.masked_fill_(diag > 0, -1)
|
||||
return L
|
||||
|
||||
# Note that we don't test with random meshes for this case, as the
|
||||
# definition of Laplacian is defined for simple graphs (aka valid meshes)
|
||||
meshes = init_simple_mesh("cuda:0")
|
||||
|
||||
lapl_naive = naive_laplacian_packed(meshes)
|
||||
lapl = meshes.laplacian_packed().to_dense()
|
||||
# check with naive
|
||||
self.assertClose(lapl, lapl_naive)
|
||||
|
||||
def test_offset_verts(self):
|
||||
def naive_offset_verts(mesh, vert_offsets_packed):
|
||||
# new Meshes class
|
||||
|
||||
Reference in New Issue
Block a user