def load_human(): # TODO: This is ugly, make ply a submodule of meshcut (requires # some refactoring) print('examples :', EXAMPLES_DIR) sys.path.append(EXAMPLES_DIR) import ply fname = os.path.join(DATA_DIR, 'mesh.ply') with open(fname) as f: verts, faces, _ = ply.load_ply(f) return meshcut.TriangleMesh(verts, faces)
def loadMesh(self, file): #Decide on filetype fn, fext = os.path.splitext(file) fext = fext.upper() if fext == '.STL': verts, faces = self.load_stl(file) elif fext == '.PLY': with open(file) as f: verts, faces, _ = ply.load_ply(f) else: print("unknown file extension", fext) return None return verts, faces
def loadMesh(self, file): #Decide on filetype fn, fext = os.path.splitext(file) fext = fext.upper() if fext=='.STL': verts, faces = self.load_stl(file) elif fext=='.PLY': with open(file) as f: verts, faces, _ = ply.load_ply(f) else: print("unknown file extension",fext) return None return verts, faces
reload(meshcut) # This will align the plane with some edges, so this is a good test # for vertices intersection handling plane_orig = (1.28380000591278076172, -0.12510000169277191162, 0) plane_norm = (1, 0, 0) plane = meshcut.Plane(plane_orig, plane_norm) show(plane, expected_n_contours=3) ## if __name__ == '__main__': ## example_dir = os.path.join(os.path.dirname(meshcut.__file__), 'examples') example_fname = os.path.join(example_dir, 'data', 'mesh.ply') with open(example_fname) as f: verts, faces, _ = ply.load_ply(f) mesh = meshcut.TriangleMesh(verts, faces) ## def show(plane, expected_n_contours): P = meshcut.cross_section_mesh(mesh, plane) colors = [(0, 1, 1), (1, 0, 1), (0, 0, 1)] print("num contours : ", len(P), ' expected : ', expected_n_contours) if True: utils.trimesh3d(mesh.verts, mesh.tris, color=(1, 1, 1),
import os import numpy as np import mayavi.mlab as mlab import itertools import utils import ply import meshcut ## if __name__ == '__main__': ## example_dir = os.path.join(os.path.dirname(meshcut.__file__), 'examples') example_fname = os.path.join(example_dir, 'data', 'mesh.ply') with open(example_fname) as f: verts, faces, _ = ply.load_ply(f) mesh = meshcut.TriangleMesh(verts, faces) ## def show(plane, expected_n_contours): P = meshcut.cross_section_mesh(mesh, plane) colors = [ (0, 1, 1), (1, 0, 1), (0, 0, 1) ] print("num contours : ", len(P), ' expected : ', expected_n_contours) if True: utils.trimesh3d(mesh.verts, mesh.tris, color=(1, 1, 1),
import numpy as np import numpy.linalg as la from vispy import scene from vispy.color import Color from vispy import gloo from vispy.scene.cameras import TurntableCamera import vispy.io import vispy.geometry import ply import depth import norm import pylab as pl np.set_printoptions(precision=5, suppress=True) ## verts, faces, _ = ply.load_ply('mesh2.ply') verts = verts.astype(np.float32) faces = np.array(faces, 'uint32') def rotx(angle): """Rotation matrix of angle (in radians) around the x-axis""" cosa = np.cos(angle) sina = np.sin(angle) return np.array([[1, 0, 0], [0, cosa, -sina], [0, sina, cosa]], dtype=float) def roty(angle): """Rotation matrix of angle around the y-axis""" cosa = np.cos(angle) sina = np.sin(angle) return np.array([[cosa, 0, sina], [0, 1, 0], [-sina, 0, cosa]], dtype=float)
import numpy as np import numpy.linalg as la from vispy import scene from vispy.color import Color from vispy import gloo from vispy.scene.cameras import TurntableCamera import vispy.io import vispy.geometry import ply import depth import norm import pylab as pl np.set_printoptions(precision=5, suppress=True) ## verts, faces, _ = ply.load_ply('mesh2.ply') verts = verts.astype(np.float32) faces = np.array(faces, 'uint32') def rotx(angle): """Rotation matrix of angle (in radians) around the x-axis""" cosa = np.cos(angle) sina = np.sin(angle) return np.array([[1, 0, 0], [0, cosa, -sina], [0, sina, cosa]], dtype=float) def roty(angle): """Rotation matrix of angle around the y-axis""" cosa = np.cos(angle)
def plot_3D(self, unrotated = False): for seg in self.sliced: if unrotated: seg = rotate(seg, [0, 0, 1], 2*np.pi - self.angle) mlab.plot3d(seg[:, 0], seg[:, 1], seg[:, 2], tube_radius=None, line_width=3.0, color=self.color) def plot_2D(self): for seg in self.sliced: unrotated_seg = rotate(seg, [0, 0, 1], 2*np.pi - self.angle) pyplot.plot(unrotated_seg[:, 1], unrotated_seg[:, 2]) #Load and plot the pretty mesh with open(r"C:\Users\aaron\sfm\tranquilitatis\cross-sections\MTP_V2.ply") as f: display_mesh = ply.load_ply(f) # Draw the mesh with Mayavi utils.trimesh3d(verts=display_mesh[0], faces=display_mesh[1]) #Load the mesh for calculations with open(r"C:\Users\aaron\sfm\tranquilitatis\cross-sections\MTP_V2_print.ply") as f: display_mesh = ply.load_ply(f) mesh = meshcut.TriangleMesh(verts=display_mesh[0], tris=display_mesh[1]) #create all the cut planes xs_angles = np.arange(0, 2*np.pi, (2.0*np.pi)/10) slices = [] initial_subplot = pyplot.subplot(2, 5, 1) for n, xs_angle in enumerate(xs_angles): newcut = cutplane(angle=xs_angle, mesh=mesh) slices.append(newcut)