if args.mask is not None: mask = np.load(args.mask) step_size = args.step_size * mask else: step_size = args.step_size mesh = TriMesh_Vtk(surface_file_in, None) smooth_vertices = mesh.laplacian_smooth( nb_iter=args.nb_step, diffusion_step=step_size, l2_dist_weighted=args.dist_weighted, area_weighted=args.area_weighted, backward_step=not(args.forward_step), flow_file=None) smoothed_mesh = TriMesh_Vtk(mesh.get_triangles(), smooth_vertices) # Save smoothed_mesh.save(surface_file_out) # Display if args.vi: mesh.display('input surface') if args.vo: smoothed_mesh.display('output surface') #print "\n!!! Smooth surface Saved !!!\n"
#!/usr/bin/env python import argparse import numpy as np from trimeshpy.trimesh_vtk import TriMesh_Vtk parser = argparse.ArgumentParser(description='Surface transformation from RAS to LPS') parser.add_argument('input', type=str, default=None, help='input RAS surface file name') parser.add_argument('output', type=str, default=None, help='output LPS surface file name') #args = parser.parse_args("brain_mesh/rhwhiteRAS.vtk brain_mesh/t1_PA000002.nii.gz".split()) args = parser.parse_args() surface_file_in = args.input surface_file_out = args.output mesh = TriMesh_Vtk(surface_file_in, None) mesh.update_polydata() mesh.save(surface_file_out)
#filter if args.index is not None: print args.index mask = np.zeros([len(vts_label)], dtype=np.bool ) for index in args.index: if index == -1: print "selected region :", index, "None" else: print "selected region :", index, label_name[index] mask = np.logical_or(mask, (vts_label == index)) if args.inverse_mask: mask = ~mask vts_color[~mask] = [0,0,0] if args.white: vts_color[mask] = [255,255,255] mesh.update_polydata() mesh.set_colors(vts_color) if args.v: mesh.display() if args.out_surface is not None: mesh.save(args.o) if args.out_vts_mask is not None: np.save(args.out_vts_mask, mask)
from trimeshpy.trimesh_vtk import TriMesh_Vtk file_name = "../data/brain_mesh/100307.obj" save_file = "../data/brain_mesh/100307.vtk" mesh1 = TriMesh_Vtk(file_name, None) mesh1.save(save_file)
if voxel_space[1] != 'P': new_vertice[:,1] = -new_vertice[:,1] if voxel_space[2] != 'S': new_vertice[:,2] = -new_vertice[:,2] mesh.set_vertices(new_vertice) if args.fx or args.fy or args.fz: flip = [-1 if args.fx else 1, -1 if args.fy else 1, -1 if args.fz else 1] print "flip:", flip f_triangles, f_vertices = mesh.flip_triangle_and_vertices(flip) mesh.set_vertices(f_vertices) mesh.set_triangles(f_triangles) # smooth if args.smooth is not None: new_vertice = mesh.laplacian_smooth(1, args.smooth, l2_dist_weighted=False, area_weighted=False, backward_step=True) mesh.set_vertices(new_vertice) if args.out_surface is not None: mesh.save(args.out_surface) # view if args.v: mesh.update_polydata() mesh.update_normals() mesh.display()
if args.mask is not None: np.save(args.end_points, end_vertices[mask]) else: np.save(args.end_points, end_vertices) if args.end_normal is not None: end_normal = end_mesh.vertices_normal(args.ed_not_normed, args.ed_not_weighted) # save only not masked points if args.mask is not None: np.save(args.end_normal, end_normal[mask]) else: np.save(args.end_normal, end_normal) if args.end_surf is not None: end_mesh.save(args.end_surf) if args.info is not None: info = np.array([args.nb_step, args.step_size], np.object) np.save(args.info, info) # display if args.vi: mesh.display('input surface') if args.vo: end_mesh.display('output surface') if args.vf: lines = np.swapaxes(flow, 0, 1) actor = fvtk.line(lines, colors=[0.5,0,0.1])