parser.add_argument('-lh_mask', type=str, default=None, help='input left surface mask array') # option parser.add_argument('-report', type=str, default=None, help='output intersection report') args = parser.parse_args() rh_lines = get_streamlines(load_streamlines_poyldata(args.rh_tracking)) lh_lines = get_streamlines(load_streamlines_poyldata(args.lh_tracking)) lines = [rh_lines, lh_lines] print "Read .vtk surface file" rh_mesh = TriMesh_Vtk(args.rh_surface, None) lh_mesh = TriMesh_Vtk(args.lh_surface, None) tris = [rh_mesh.get_triangles(), lh_mesh.get_triangles()] vts = [rh_mesh.get_vertices(), lh_mesh.get_vertices()] print "Generate OBB-Tree" #tree = vtk.vtkModifiedBSPTree() rh_tree = vtk.vtkOBBTree() rh_tree.SetDataSet(rh_mesh.get_polydata()) rh_tree.BuildLocator() lh_tree = vtk.vtkOBBTree() lh_tree.SetDataSet(lh_mesh.get_polydata()) lh_tree.BuildLocator() tree = [rh_tree, lh_tree] # report info [rh, lh] start_count = [len(rh_lines), len(lh_lines)]
saved_flow = "testflow.dat" #files names sphere_file_name = "../data/test_mesh/sphere.obj" cube_file_name = "../data/test_mesh/cube_simple.obj" torus_file_name = "../data/test_mesh/torus.obj" spot_file_name = "../data/test_mesh/spot.obj" brain_file_name = "../data/brain_mesh/100307_smooth_lh.vtk" # Init Sphere s_mesh = TriMesh_Vtk(sphere_file_name, None) s_vshape0 = s_mesh.get_nb_vertices() # Display sphere sphere_tmf = TriMeshFlow_Vtk(s_mesh.get_triangles(), s_mesh.get_vertices()) sphere_tmf.display() # Umbrella sphere sphere_tmf.laplacian_smooth(100, 1, l2_dist_weighted=False, area_weighted=False, backward_step=False, flow_file=saved_flow) sphere_tmf.set_vertices_flow_from_memmap(saved_flow, 100, s_vshape0) sphere_tmf.display() sphere_tmf.display_vertices_flow() # L2 weighted sphere_tmf.set_vertices_flow(s_mesh.get_vertices()) sphere_tmf.laplacian_smooth(100, 1, l2_dist_weighted=True, area_weighted=False, backward_step=False, flow_file=saved_flow) sphere_tmf.set_vertices_flow_from_memmap(saved_flow, 100, s_vshape0) sphere_tmf.display() sphere_tmf.display_vertices_flow()
# by Etienne St-Onge import numpy as np import time import trimeshpy from trimeshpy.trimesh_vtk import TriMesh_Vtk from trimeshpy.trimeshflow_vtk import TriMeshFlow_Vtk from trimeshpy.vtk_util import lines_to_vtk_polydata, save_polydata # Test files file_name = trimeshpy.data.brain_lh mesh = TriMesh_Vtk(file_name, None) triangles = mesh.get_triangles() vertices = mesh.get_vertices() mesh.display(display_name="Trimeshpy: Initial Mesh") # pre-smooth vertices = mesh.laplacian_smooth(2, 10.0, l2_dist_weighted=False, area_weighted=False, backward_step=True, flow_file=None) mesh.set_vertices(vertices) mesh.display(display_name="Trimeshpy: Smoothed Mesh") tri_mesh_flow = TriMeshFlow_Vtk(triangles, vertices) # Test parameters nb_step = 10 diffusion_step = 10 saved_flow = trimeshpy.data.output_test_flow saved_fib = trimeshpy.data.output_test_fib
# by [email protected] import numpy as np from trimeshpy.trimesh_class import TriMesh from trimeshpy.trimesh_vtk import TriMesh_Vtk file_name = "../data/test_mesh/cube_simple.obj" #file_name = "../data/test_mesh/sphere.obj" #file_name = "../data/test_mesh/torus.obj" mesh = TriMesh_Vtk(file_name, None) triangles = mesh.get_triangles() vertices = mesh.get_vertices() tri_mesh = TriMesh(triangles, vertices) print tri_mesh.get_nb_triangles(), tri_mesh.get_nb_vertices() bool_tests = True current_test = True """CONNECTIVITY MATRIX""" # test vertex connectivity vv_matrix = tri_mesh.edge_map(False) current_test = np.alltrue(vv_matrix.todense() == vv_matrix.T.todense()) print current_test, ": connectivity is symmetric" bool_tests = bool_tests and current_test # test triangles vertex connectivity tv_matrix = tri_mesh.triangle_vertex_map() nb_triangles_per_points = tri_mesh.nb_triangles_per_vertex() current_test = np.alltrue(tv_matrix.sum(1) == 3)
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) volume_nib = nib.load(nii_name) if not args.no_lps: voxel_space = nib.aff2axcodes(volume_nib.get_affine()) new_vertice = mesh.get_vertices() # voxel_space -> LPS print str(voxel_space), "-to-> LPS" if voxel_space[0] != 'L': new_vertice[:,0] = -new_vertice[:,0] 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.tx is not None or args.ty is not None or args.tz is not None : translate2 = [0.0, 0.0, 0.0] if args.tx is not None: translate2[0] = args.tx
parser.add_argument('-max_nb_step', type=int, default=100, help='nb step for surface tracking interpolation') parser.add_argument('-compression', type=float, default=None, help='compression toll (no-compression by default, but 0.01 is dipy default)') args = parser.parse_args() ### weight correctly the ending triangle ! print " loading files!" intersect = np.load(args.intersection) surf_id = np.load(args.surf_idx) tracto_polydata = load_streamlines_poyldata(args.tracto_cut) tracto = get_streamlines(tracto_polydata) rh_mesh = TriMesh_Vtk(args.rh_surface, None) rh_vts = rh_mesh.get_vertices() rh_tris = rh_mesh.get_triangles() lh_mesh = TriMesh_Vtk(args.lh_surface, None) lh_vts = lh_mesh.get_vertices() lh_tris = lh_mesh.get_triangles() rh_info = np.load(args.rh_flow_info) lh_info = np.load(args.lh_flow_info) rh_flow = np.memmap(args.rh_flow_file, dtype=np.float64, mode='r', shape=(rh_info[0], rh_vts.shape[0], rh_vts.shape[1])) lh_flow = np.memmap(args.lh_flow_file, dtype=np.float64, mode='r', shape=(rh_info[0], lh_vts.shape[0], lh_vts.shape[1]))
# by Etienne St-Onge import trimeshpy from trimeshpy.trimesh_vtk import TriMesh_Vtk from trimeshpy.trimeshflow_vtk import TriMeshFlow_Vtk # Init Sphere s_mesh = TriMesh_Vtk(trimeshpy.data.sphere, None) s_vshape0 = s_mesh.get_nb_vertices() # Display sphere sphere_tmf = TriMeshFlow_Vtk(s_mesh.get_triangles(), s_mesh.get_vertices()) sphere_tmf.display() NB_STEP_SPHERE = 100 # Umbrella sphere sphere_tmf.laplacian_smooth(NB_STEP_SPHERE, 1, l2_dist_weighted=False, area_weighted=False, backward_step=False, flow_file=trimeshpy.data.output_test_flow) sphere_tmf.set_vertices_flow_from_memmap(trimeshpy.data.output_test_flow, NB_STEP_SPHERE, s_vshape0) sphere_tmf.display() sphere_tmf.display_vertices_flow() # L2 weighted sphere_tmf.set_vertices_flow(s_mesh.get_vertices()) sphere_tmf.laplacian_smooth(NB_STEP_SPHERE, 1,