Last active
April 28, 2023 20:51
-
-
Save Chandler/4a8542baee98b66caca4d8329d3a6336 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import igl | |
import numpy as np | |
import polyscope as ps | |
import scipy | |
from sklearn.preprocessing import normalize | |
import robust_laplacian | |
from scipy.sparse import linalg as sla | |
path = "scan_007.obj" | |
# vertices and faces | |
V,F = igl.read_triangle_mesh(path) | |
max_eigenvectors = 500 | |
# cotan laplacian and mass matrix | |
laplacian = igl.cotmatrix(V,F) | |
massmatrix = igl.massmatrix(V,F) | |
# eigenvectors of the laplacian | |
_, eigenvectors = scipy.sparse.linalg.eigsh( | |
laplacian, max_eigenvectors, massmatrix, sigma=-1e-6 | |
) | |
# reverse to order by descending eigenvalues | |
spectral_basis = eigenvectors[:, ::-1] | |
# the spectral representation of mesh coordinate functions | |
# very important to scale by the mass matrix when projecting into the eigenfunctions | |
spectral_coefficients = spectral_basis.T @ massmatrix @ V | |
ps.init() | |
# visualize the original mesh | |
original_mesh = ps.register_surface_mesh("mesh", V, F) | |
for k in [500,300, 100,50,10,5]: | |
# reconstruct with basis truncated to k basis vectors | |
# representing different levels of compression | |
new_vertices = spectral_basis[:,:k] @ spectral_coefficients[:k,:] | |
# visualize the reconstruction | |
ps.register_surface_mesh(f"reconstructed_mesh_{k}", new_vertices.astype(np.float32), F) | |
ps.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment