def read_ply(i): #filename = 'data-armadillo/verts%d.ply' % (i + 1) filename = base_path + '%d.ply' % i if (i % 13 == 0): print('.', end='', flush=True) verts = igl.eigen.MatrixXd() igl.readPLY(filename, verts, _i, _d, _d) return e2p(verts)
def get_initial_verts_and_faces(): initial_verts = igl.eigen.MatrixXd() initial_faces = igl.eigen.MatrixXi() #path = base_path + '_and_faces.ply' path = base_path + '0.ply' igl.readPLY(path, initial_verts, initial_faces, _d, _d) return initial_verts, initial_faces
def undeform(path_ref, path_mov, path_morph, outdir): global Vref, Sref, Fref, Smov, Fmov global vecs, k global UxLUx, Ux, UyLUy, Uy, UzLUz, Uz, L global it ''' Specific paths ''' path_vref = path_ref + "/surf.ply" path_vmov = path_mov + "/surf.ply" path_sref = path_ref + "/surf.sphere.ply" path_smov = path_mov + "/surf.sphere.ply" path_rotref = path_ref + "/rotation.txt" path_rotmov = path_mov + "/rotation.txt" ''' Load meshes ''' Vref = igl.eigen.MatrixXd() Vmov = igl.eigen.MatrixXd() Sref = igl.eigen.MatrixXd() Smov = igl.eigen.MatrixXd() Smor = igl.eigen.MatrixXd() Fref = igl.eigen.MatrixXi() Fmov = igl.eigen.MatrixXi() TMP1 = igl.eigen.MatrixXd() TMP2 = igl.eigen.MatrixXd() # load meshes igl.readPLY(path_vref, Vref, Fref, TMP1, TMP2) igl.readPLY(path_vmov, Vmov, Fmov, TMP1, TMP2) igl.readPLY(path_sref, Sref, Fref, TMP1, TMP2) igl.readPLY(path_smov, Smov, Fmov, TMP1, TMP2) igl.readPLY(path_morph, Smor, Fmov, TMP1, TMP2) # load and apply rotations rot = np.loadtxt(path_rotref) rot = p2e(rot).leftCols(3).topRows(3) Sref = (rot.transpose() * Sref.transpose()).transpose() rot = np.loadtxt(path_rotmov) rot = p2e(rot).leftCols(3).topRows(3) Smov = (rot.transpose() * Smov.transpose()).transpose() ''' Compute uniform Laplacian matrix ''' A = igl.eigen.SparseMatrixi() igl.adjacency_matrix(Fmov, A) pA = e2p(A).astype('float64') pL = scipy.sparse.csgraph.laplacian(pA).astype(float).tocsc() L = p2e(pL) ''' Eigenpairs of the uniform Laplacian ''' k = 25 print("Using " + str(k) + " eigenvectors") vals, vecs = eigsh(pL, k, sigma=0, which='LM') evecs = p2e(vecs) ''' Initial deformation field guess ''' delta = Smor - Smov a = delta.col(0).transpose() * evecs # 1 row, k columns b = delta.col(1).transpose() * evecs c = delta.col(2).transpose() * evecs abc = np.concatenate((a, b, c), axis=1).T[:, 0] ''' Constant part of the deformation energy function ''' Ux = Vmov.col(0) Uy = Vmov.col(1) Uz = Vmov.col(2) UxLUx = Ux.transpose() * L * Ux UyLUy = Uy.transpose() * L * Uy UzLUz = Uz.transpose() * L * Uz ''' Initialise AABB tree for finding closest vertices ''' tree = igl.AABB() tree.init(Sref, Fref) ''' Call the minimisation algorithm ''' it = 0 x, f, d = fmin_l_bfgs_b(energy, x0=abc, approx_grad=True, callback=iteration) ''' Save the resulting morph sphere and the resulting projected mesh ''' sph = sphere(x) igl.writePLY(outdir + "/surf.sphere.ply", sphere(x), Fmov) igl.writePLY(outdir + "/surf.ply", project(sph), Fmov)