if viewer.core.is_animating: anim_t += anim_t_dir return False def key_down(viewer, key, mods): if key == ord(' '): viewer.core.is_animating = not viewer.core.is_animating return True return False igl.readOFF("../../tutorial/shared/decimated-knight.off", V, F) U = igl.eigen.MatrixXd(V) igl.readDMAT("../../tutorial/shared/decimated-knight-selection.dmat", S) # Vertices in selection b = igl.eigen.MatrixXi([[ t[0] for t in [(i, S[i]) for i in range(0, V.rows())] if t[1] >= 0 ]]).transpose() # Centroid mid = 0.5 * (V.colwiseMaxCoeff() + V.colwiseMinCoeff()) # Precomputation arap_data.max_iter = 100 igl.arap_precomputation(V, F, V.cols(), b, arap_data) # Set color based on selection
# Add the igl library to the modules search path import sys, os sys.path.insert(0, os.getcwd() + "/../") import igl V = igl.eigen.MatrixXd() F = igl.eigen.MatrixXi() # Load a mesh in OFF format igl.readOFF("../../tutorial/shared/cheburashka.off", V, F) # Read scalar function values from a file, U: #V by 1 U = igl.eigen.MatrixXd() igl.readDMAT("../../tutorial/shared/cheburashka-scalar.dmat", U) U = U.col(0) # Compute gradient operator: #F*3 by #V G = igl.eigen.SparseMatrixd() igl.grad(V, F, G) # Compute gradient of U GU = (G * U).MapMatrix(F.rows(), 3) # Compute gradient magnitude GU_mag = GU.rowwiseNorm() viewer = igl.viewer.Viewer() viewer.data.set_mesh(V, F) # Compute pseudocolor for original function
if key == ord(' '): viewer.core.is_animating = not viewer.core.is_animating return True if key == ord('D') or key == ord('d'): deformation_field = not deformation_field; return True return False igl.readOBJ("../../tutorial/shared/decimated-max.obj",V,F) U = igl.eigen.MatrixXd(V) # S(i) = j: j<0 (vertex i not in handle), j >= 0 (vertex i in handle j) S = igl.eigen.MatrixXd() igl.readDMAT("../../tutorial/shared/decimated-max-selection.dmat",S) S = S.castint() b = igl.eigen.MatrixXi([[t[0] for t in [(i,S[i]) for i in range(0,V.rows())] if t[1] >= 0]]).transpose() # Boundary conditions directly on deformed positions U_bc.resize(b.rows(),V.cols()) V_bc.resize(b.rows(),V.cols()) for bi in range(0,b.rows()): V_bc.setRow(bi,V.row(b[bi])) if (S[b[bi]] == 0): # Don't move handle 0 U_bc.setRow(bi,V.row(b[bi]))
import igl V = igl.eigen.MatrixXd() F = igl.eigen.MatrixXi() # Load a mesh in OFF format igl.readOFF("../tutorial/shared/cheburashka.off", V, F) # Read scalar function values from a file, U: #V by 1 U = igl.eigen.MatrixXd() igl.readDMAT("../tutorial/shared/cheburashka-scalar.dmat",U) U = U.col(0) # Compute gradient operator: #F*3 by #V G = igl.eigen.SparseMatrixd() igl.grad(V,F,G) # Compute gradient of U GU = (G*U).MapMatrix(F.rows(),3) # Compute gradient magnitude GU_mag = GU.rowwiseNorm() viewer = igl.viewer.Viewer() viewer.data.set_mesh(V, F) # Compute pseudocolor for original function C = igl.eigen.MatrixXd() igl.jet(U,True,C)