def show(plane): P = meshcut.cross_section_mesh(mesh, plane) colors = [(0, 1, 1), (1, 0, 1), (0, 0, 1)] print("num contours : ", len(P)) if True: utils.trimesh3d(mesh.verts, mesh.tris, color=(1, 1, 1), opacity=0.5, representation='wireframe') utils.show_plane(plane.orig, plane.n, scale=1, color=(1, 0, 0), opacity=0.5) for p, color in zip(P, itertools.cycle(colors)): p = np.array(p) mlab.plot3d(p[:, 0], p[:, 1], p[:, 2], tube_radius=None, line_width=3.0, color=color) return P
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), opacity=0.5) utils.show_plane(plane.orig, plane.n, scale=1, color=(1, 0, 0), opacity=0.5) for p, color in zip(P, itertools.cycle(colors)): p = np.array(p) #utils.points3d(np.array(p), point_size=3, color=(1,1,1)) mlab.plot3d(p[:, 0], p[:, 1], p[:, 2], tube_radius=None, line_width=3.0, color=color) return P
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), opacity=0.5) utils.show_plane(plane.orig, plane.n, scale=1, color=(1, 0, 0), opacity=0.5) for p, color in zip(P, itertools.cycle(colors)): p = np.array(p) mlab.plot3d(p[:, 0], p[:, 1], p[:, 2], tube_radius=None, line_width=3.0, color=color) return P
## import numpy as np import ply import mayavi.mlab as mlab # noqa from utils import points3d, trimesh3d, show_plane # %matplotlib qt ## with open('data/mesh.ply') as f: verts, faces, _ = ply.load_ply(f) ## # plane defined by origin and normal plane_orig = (1.0, 0.0, 0.0) plane_norm = (1.0, 0.0, 0.0) trimesh3d(verts, faces, color=(1, 1, 1)) show_plane(plane_orig, plane_norm, scale=0.5, color=(1, 0, 0), opacity=0.5) ## def point_to_plane_dist(p, plane_orig, plane_norm): return np.dot((p - plane_orig), plane_norm) def classify_faces(verts, faces, plane_orig, plane_norm): faces_pos = [] faces_mid = [] faces_neg = [] for f in faces: sides = [
## import numpy as np import ply import mayavi.mlab as mlab # noqa from utils import points3d, trimesh3d, show_plane # %matplotlib qt ## with open('data/mesh.ply') as f: verts, faces, _ = ply.load_ply(f) ## # plane defined by origin and normal plane_orig = (1.0, 0.0, 0.0) plane_norm = (1.0, 0.0, 0.0) trimesh3d(verts, faces, color=(1, 1, 1)) show_plane(plane_orig, plane_norm, scale=0.5, color=(1, 0, 0), opacity=0.5) ## def point_to_plane_dist(p, plane_orig, plane_norm): return np.dot((p - plane_orig), plane_norm) def classify_faces(verts, faces, plane_orig, plane_norm): faces_pos = [] faces_mid = [] faces_neg = [] for f in faces: sides = [point_to_plane_dist(p, plane_orig, plane_norm)
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) pyplot.subplot(2, 5, n+1, sharex=initial_subplot, sharey=initial_subplot) newcut.plot_2D()