def read_mesh_eigen(filename): V = igl.eigen.MatrixXd() F = igl.eigen.MatrixXi() igl.read_triangle_mesh(filename, V, F) stl = filename[-3:] == 'stl' if stl: # Remove duplicated vertices SV = igl.eigen.MatrixXd() SVI = igl.eigen.MatrixXi() SVJ = igl.eigen.MatrixXi() SF = igl.eigen.MatrixXi() igl.remove_duplicate_vertices(V, F, 1e-7, SV, SVI, SVJ, SF) V = SV F = SF return V, F
def initialize(self): self.vertices = igl.eigen.MatrixXd() self.faces = igl.eigen.MatrixXi() try: if not igl.read_triangle_mesh(self.mesh_path, self.vertices, self.faces): print("failed to read mesh\n") except: traceback.print_exc(file=sys.stdout) sys.exit(-1) self.face_normals = igl.eigen.MatrixXd() igl.per_face_normals(self.vertices, self.faces, self.face_normals) self.vertex_normals = igl.eigen.MatrixXd() igl.per_vertex_normals(self.vertices, self.faces, igl.PER_VERTEX_NORMALS_WEIGHTING_TYPE_AREA, self.vertex_normals) self.vertex_data = e2p(self.vertices).astype(dtype=np.float32, order='C') self.index_data = e2p(self.faces).astype(dtype=np.uint32, order='C') self.face_normal_data = e2p(self.face_normals).astype(dtype=np.float32, order='C') self.vertex_normal_data = e2p(self.vertex_normals).astype( dtype=np.float32, order='C') self.num_faces = self.index_data.shape[0] self.num_vertices = self.vertex_data.shape[0] self.center = np.mean(self.vertex_data, axis=0) self.max_vals = np.max(self.vertex_data, axis=0) self.min_vals = np.min(self.vertex_data, axis=0) self.extents = self.max_vals - self.min_vals print("min = %s, max = %s, extents = %s" % (self.min_vals, self.max_vals, self.extents)) self.vertex_data = (self.vertex_data - self.center) / self.extents self.vertex_byte_count = ArrayDatatype.arrayByteCount(self.vertex_data) self.vertex_normal_byte_count = ArrayDatatype.arrayByteCount( self.vertex_normal_data) self.index_byte_count = ArrayDatatype.arrayByteCount(self.index_data)
keys = { "space": "toggle between transforming original mesh and swept volume" } print_usage(keys) V = igl.eigen.MatrixXd() SV = igl.eigen.MatrixXd() VT = igl.eigen.MatrixXd() F = igl.eigen.MatrixXi() SF = igl.eigen.MatrixXi() show_swept_volume = False grid_size = 50 time_steps = 200 isolevel = 1 igl.read_triangle_mesh(TUTORIAL_SHARED_PATH + "bunny.off", V, F) print("Computing swept volume...") igl.copyleft.swept_volume(V, F, transform, time_steps, grid_size, isolevel, SV, SF) print("...finished.") # Plot the generated mesh viewer = igl.viewer.Viewer() viewer.data.set_mesh(V, F) viewer.data.set_face_based(True) viewer.core.is_animating = not show_swept_volume viewer.callback_pre_draw = pre_draw viewer.callback_key_down = key_down viewer.launch()
# obtain one at http://mozilla.org/MPL/2.0/. import sys, os # Add the igl library to the modules search path sys.path.insert(0, os.getcwd() + "/../") import pyigl as igl from shared import TUTORIAL_SHARED_PATH, check_dependencies dependencies = ["glfw"] check_dependencies(dependencies) V = igl.eigen.MatrixXd() F = igl.eigen.MatrixXi() igl.read_triangle_mesh(TUTORIAL_SHARED_PATH + "fertility.off", V, F) # Alternative discrete mean curvature HN = igl.eigen.MatrixXd() L = igl.eigen.SparseMatrixd() M = igl.eigen.SparseMatrixd() Minv = igl.eigen.SparseMatrixd() igl.cotmatrix(V, F, L) igl.massmatrix(V, F, igl.MASSMATRIX_TYPE_VORONOI, M) igl.invert_diag(M, Minv) # Laplace-Beltrami of position HN = -Minv * (L * V)
if __name__ == "__main__": keys = { "1": "show original mesh", "2": "show marching cubes contour of signed distance", "3": "show marching cubes contour of indicator function" } print_usage(keys) V = igl.eigen.MatrixXd() F = igl.eigen.MatrixXi() # Read in inputs as double precision floating point meshes igl.read_triangle_mesh(TUTORIAL_SHARED_PATH + "armadillo.obj", V, F) # number of vertices on the largest side s = 50 Vmin = V.colwiseMinCoeff() Vmax = V.colwiseMaxCoeff() h = (Vmax - Vmin).maxCoeff() / s res = (s * ((Vmax - Vmin) / (Vmax - Vmin).maxCoeff())).castint() def lerp(res, Vmin, Vmax, di, d): return Vmin[d] + float(di) / (res[d] - 1) * (Vmax[d] - Vmin[d]) # create grid print("Creating grid...") GV = igl.eigen.MatrixXd(res[0] * res[1] * res[2], 3) for zi in range(res[2]):
# Add the igl library to the modules search path import sys, os sys.path.insert(0, os.getcwd() + "/../") import pyigl as igl V = igl.eigen.MatrixXd() F = igl.eigen.MatrixXi() igl.read_triangle_mesh("../../tutorial/shared/fertility.off", V, F) # Alternative discrete mean curvature HN = igl.eigen.MatrixXd() L = igl.eigen.SparseMatrixd() M = igl.eigen.SparseMatrixd() Minv = igl.eigen.SparseMatrixd() igl.cotmatrix(V, F, L) igl.massmatrix(V, F, igl.MASSMATRIX_TYPE_VORONOI, M) igl.invert_diag(M, Minv) # Laplace-Beltrami of position HN = -Minv * (L * V) # Extract magnitude as mean curvature H = HN.rowwiseNorm() # Compute curvature directions via quadric fitting PD1 = igl.eigen.MatrixXd() PD2 = igl.eigen.MatrixXd()
def __init__(self, s=None): self.V = igl.eigen.MatrixXd() self.F = igl.eigen.MatrixXi() if s is not None: igl.read_triangle_mesh(s, self.V, self.F)
if __name__ == "__main__": keys = {"space": "toggle between transforming original mesh and swept volume"} print_usage(keys) V = igl.eigen.MatrixXd() SV = igl.eigen.MatrixXd() VT = igl.eigen.MatrixXd() F = igl.eigen.MatrixXi() SF = igl.eigen.MatrixXi() show_swept_volume = False grid_size = 50 time_steps = 200 isolevel = 1 igl.read_triangle_mesh(TUTORIAL_SHARED_PATH + "bunny.off", V, F) print("Computing swept volume...") igl.copyleft.swept_volume(V, F, transform, time_steps, grid_size, isolevel, SV, SF) print("...finished.") # Plot the generated mesh viewer = igl.glfw.Viewer() viewer.data().set_mesh(V, F) viewer.data().set_face_based(True) viewer.core.is_animating = not show_swept_volume viewer.callback_pre_draw = pre_draw viewer.callback_key_down = key_down viewer.launch()
# Add the igl library to the modules search path import sys, os sys.path.insert(0, os.getcwd() + "/../") import pyigl as igl V = igl.eigen.MatrixXd(); F = igl.eigen.MatrixXi(); igl.read_triangle_mesh("../../tutorial/shared/fertility.off", V, F); # Alternative discrete mean curvature HN = igl.eigen.MatrixXd() L = igl.eigen.SparseMatrixd() M = igl.eigen.SparseMatrixd() Minv = igl.eigen.SparseMatrixd() igl.cotmatrix(V,F,L) igl.massmatrix(V,F,igl.MASSMATRIX_TYPE_VORONOI,M) igl.invert_diag(M,Minv) # Laplace-Beltrami of position HN = -Minv*(L*V) # Extract magnitude as mean curvature H = HN.rowwiseNorm() # Compute curvature directions via quadric fitting PD1 = igl.eigen.MatrixXd() PD2 = igl.eigen.MatrixXd()
def _loadMesh(self, fp, doNormalize): #load mesh igl.read_triangle_mesh(fp, self._V, self._F) if doNormalize: self._normalizeMesh()
# def get_model() # model = ml_net_model(img_cols=shape_c, img_rows=shape_r, # downsampling_factor_product=10) # sgd = SGD(lr=1e-3, decay=0.0005, momentum=0.9, nesterov=True) # print("Compile ML-Net Model") # model.compile(sgd, loss) if __name__ == "__main__": mesh_path = sys.argv[1] print("mesh_path = %s\n" % mesh_path) vertices = igl.eigen.MatrixXd() faces = igl.eigen.MatrixXi() try: if not igl.read_triangle_mesh(mesh_path, vertices, faces): print("failed to read mesh\n") except: traceback.print_exc(file=sys.stdout) sys.exit(-1) face_normals = igl.eigen.MatrixXd() igl.per_face_normals(vertices, faces, face_normals) vertex_normals = igl.eigen.MatrixXd() igl.per_vertex_normals(vertices, faces, igl.PER_VERTEX_NORMALS_WEIGHTING_TYPE_AREA, vertex_normals) vertex_data = e2p(vertices).flatten('C').astype(dtype=np.float32, order='C') index_data = e2p(faces).flatten('C').astype(dtype=np.uint32, order='C')
keys = { "space": "toggle between original and reoriented faces", "F,f": "toggle between patchwise and facetwise reorientation", "S,s": "scramble colors" } print_usage(keys) V = igl.eigen.MatrixXd() F = igl.eigen.MatrixXi() C = [igl.eigen.MatrixXi(), igl.eigen.MatrixXi()] RGBcolors = [igl.eigen.MatrixXd(), igl.eigen.MatrixXd()] FF = [igl.eigen.MatrixXi(), igl.eigen.MatrixXi()] is_showing_reoriented = False facetwise = 0 igl.read_triangle_mesh(TUTORIAL_SHARED_PATH + "truck.obj", V, F) # Compute patches for p in range(2): I = igl.eigen.MatrixXi() igl.embree.reorient_facets_raycast(V, F, F.rows() * 100, 10, p == 1, False, False, I, C[p]) # apply reorientation FF[p].conservativeResize(F.rows(), F.cols()) for i in range(I.rows()): if I[i]: FF[p].setRow(i, F.row(i).rowwiseReverse()) else: FF[p].setRow(i, F.row(i))
if __name__ == "__main__": keys = {"space": "toggle between original and reoriented faces", "F,f": "toggle between patchwise and facetwise reorientation", "S,s": "scramble colors"} print_usage(keys) V = igl.eigen.MatrixXd() F = igl.eigen.MatrixXi() C = [igl.eigen.MatrixXi(), igl.eigen.MatrixXi()] RGBcolors = [igl.eigen.MatrixXd(), igl.eigen.MatrixXd()] FF = [igl.eigen.MatrixXi(), igl.eigen.MatrixXi()] is_showing_reoriented = False facetwise = 0 igl.read_triangle_mesh(TUTORIAL_SHARED_PATH + "truck.obj", V, F) # Compute patches for p in range(2): I = igl.eigen.MatrixXi() igl.embree.reorient_facets_raycast(V, F, F.rows() * 100, 10, p == 1, False, False, I, C[p]) # apply reorientation FF[p].conservativeResize(F.rows(), F.cols()) for i in range(I.rows()): if I[i]: FF[p].setRow(i, F.row(i).rowwiseReverse()) else: FF[p].setRow(i, F.row(i)) # Plot the generated mesh viewer = igl.glfw.Viewer()
# Add the igl library to the modules search path import sys, os sys.path.insert(0, os.getcwd() + "/../") import pyigl as igl V = igl.eigen.MatrixXd() U = igl.eigen.MatrixXd() F = igl.eigen.MatrixXi() c = 0 bbd = 1.0 twod = False if not igl.read_triangle_mesh("../../tutorial/shared/beetle.off",V,F): print("failed to load mesh") twod = V.col(2).minCoeff() == V.col(2).maxCoeff() bbd = (V.colwiseMaxCoeff() - V.colwiseMinCoeff()).norm() L = igl.eigen.SparseMatrixd() M = igl.eigen.SparseMatrixd() igl.cotmatrix(V,F,L) L = -L igl.massmatrix(V,F,igl.MASSMATRIX_TYPE_DEFAULT,M) k = 5 D = igl.eigen.MatrixXd() if not igl.eigs(L,M,k+1,igl.EIGS_TYPE_SM,U,D): print("Eigs failed.")
from shared import TUTORIAL_SHARED_PATH, check_dependencies dependencies = ["viewer"] check_dependencies(dependencies) V = igl.eigen.MatrixXd() U = igl.eigen.MatrixXd() F = igl.eigen.MatrixXi() c = 0 bbd = 1.0 twod = False if not igl.read_triangle_mesh(TUTORIAL_SHARED_PATH + "beetle.off", V, F): print("failed to load mesh") twod = V.col(2).minCoeff() == V.col(2).maxCoeff() bbd = (V.colwiseMaxCoeff() - V.colwiseMinCoeff()).norm() L = igl.eigen.SparseMatrixd() M = igl.eigen.SparseMatrixd() igl.cotmatrix(V, F, L) L = -L igl.massmatrix(V, F, igl.MASSMATRIX_TYPE_DEFAULT, M) k = 5 D = igl.eigen.MatrixXd() if not igl.eigs(L, M, k + 1, igl.EIGS_TYPE_SM, U, D):
return True if __name__ == "__main__": keys = {"1": "show original mesh", "2": "show marching cubes contour of signed distance", "3": "show marching cubes contour of indicator function"} print_usage(keys) V = igl.eigen.MatrixXd() F = igl.eigen.MatrixXi() # Read in inputs as double precision floating point meshes igl.read_triangle_mesh(TUTORIAL_SHARED_PATH + "armadillo.obj", V, F) # number of vertices on the largest side s = 50 Vmin = V.colwiseMinCoeff() Vmax = V.colwiseMaxCoeff() h = (Vmax - Vmin).maxCoeff() / s res = (s * ((Vmax - Vmin) / (Vmax - Vmin).maxCoeff())).castint() def lerp(res, Vmin, Vmax, di, d): return Vmin[d] + float(di) / (res[d] - 1) * (Vmax[d] - Vmin[d]) # create grid print("Creating grid...") GV = igl.eigen.MatrixXd(res[0] * res[1] * res[2], 3) for zi in range(res[2]):
import pymmgs import numpy as np import sys, os sys.path.insert(0, os.path.expanduser('~/Workspace/libigl/python')) import pyigl as igl import pyigl.eigen as Eigen from iglhelpers import p2e, e2p V = igl.eigen.MatrixXd() F = igl.eigen.MatrixXi() igl.read_triangle_mesh('/Users/zhongshi/1399_standing_clap_000010.obj', V, F) # SV, SVI, SVJ, SF = igl.eigen.MatrixXd(), igl.eigen.MatrixXi(), igl.eigen.MatrixXi(), igl.eigen.MatrixXi() # igl.remove_duplicate_vertices(V,F,1e-10, SV, SVI, SVJ, SF) M = igl.eigen.MatrixXd() igl.doublearea(V, F, M) M = e2p(M).flatten() # F0 = e2p(F)[np.where(M > 1e-9)[0],:] # npl = np.load('/Users/zhongshi/1006_jump_from_wall_000003.obj.npz') V0, F0 = e2p(V), e2p(F) # igl.writeOBJ('1399.obj',V, F) V, F = pymmgs.MMGS(V0, F0, 0.005) vw = igl.glfw.Viewer() vw.data().set_mesh(p2e(V), p2e(F)) vw.launch()