-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.py
31 lines (22 loc) · 825 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import numpy as np
import scipy.sparse as sp
import torch
def row(A):
return A.reshape((1, -1))
def col(A):
return A.reshape((-1, 1))
def get_vert_connectivity(mesh_v, mesh_f):
"""Returns a sparse matrix (of size #verts x #verts) where each nonzero
element indicates a neighborhood relation. For example, if there is a
nonzero element in position (15,12), that means vertex 15 is connected
by an edge to vertex 12."""
vpv = sp.csc_matrix((len(mesh_v), len(mesh_v)))
# for each column in the faces...
for i in range(3):
IS = mesh_f[:, i]
JS = mesh_f[:, (i + 1) % 3]
data = np.ones(len(IS))
ij = np.vstack((row(IS.flatten()), row(JS.flatten())))
mtx = sp.csc_matrix((data, ij), shape=vpv.shape)
vpv = vpv + mtx + mtx.T
return vpv