import argparse import numpy as np import matplotlib.pyplot as plt import matplotlib.patches as mpatches from trimeshpy.trimesh_vtk import load_streamlines_poyldata, get_streamlines parser = argparse.ArgumentParser(description='lenghts stats') parser.add_argument('-lengths', type=str, nargs='+', default=None, help='tractography length (.npy)') parser.add_argument('-lengths', type=str, nargs='+', default=None, help='tractography surface connection idx (.npy)') args = parser.parse_args() streamlines_list = [] for filename in args.tracts: streamlines_list.append(get_streamlines(load_streamlines_poyldata(filename))) lines_length_list = [] for lines in streamlines_list: lines_length = np.zeros([len(lines)], dtype=np.float) for i in range(len(lines)): dist = lines[i][:-1] - lines[i][1:] lines_length[i] = np.sum(np.sqrt(np.sum(np.square(dist), axis=1))) lines_length_list.append(lines_length) #print np.average(lines_length) #print np.var(lines_length) histogram_list = [] color_list = ['lightcoral', 'darkred', 'lightgreen', 'darkgreen', 'skyblue', 'darkblue', 'khaki', 'y'] patches = [] fontsize=20
parser.add_argument('--fy1', action='store_true', default=False, help='flip x, from voxel_space') parser.add_argument('--fz1', action='store_true', default=False, help='flip x, from voxel_space') parser.add_argument('--fx2', action='store_true', default=False, help='flip x, from volume shape') parser.add_argument('--fy2', action='store_true', default=False, help='flip x, from volume shape') parser.add_argument('--fz2', action='store_true', default=False, help='flip x, from volume shape') parser.add_argument('-tx', type=float, default=None, help='x translation') parser.add_argument('-ty', type=float, default=None, help='y translation') parser.add_argument('-tz', type=float, default=None, help='z translation') args = parser.parse_args() # get transform nib_mask = nib.load(args.mask) lines = get_streamlines(load_streamlines_poyldata(args.tract)) rotation = nib_mask.get_affine()[:3,:3] inv_rotation = np.linalg.inv(rotation) translation = nib_mask.get_affine()[:3,3] scale = np.array(nib_mask.get_header().get_zooms()) voxel_space = nib.aff2axcodes(nib_mask.get_affine()) shape = nib_mask.get_data().shape print shape # transform if not args.no_transfo: if args.lps_ras: print "LPS -> RAS" print "Not implemented" raise NotImplementedError()
parser.add_argument('rh_surface', type=str, default=None, help='input right surface') parser.add_argument('lh_surface', type=str, default=None, help='input left surface') parser.add_argument('output', type=str, default=None, help='output right tracking result .fib (VTK FORMAT)') parser.add_argument('intersection', type=str, default=None, help='output points direction where flow stopped') parser.add_argument('surf_idx_inter', type=str, default=None, help='output surface index for intersection') parser.add_argument('-rh_mask', type=str, default=None, help='input right surface mask array') 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()
parser.add_argument('surf_idx', type=str, default=None, help='surface index intersection file') parser.add_argument('output', type=str, default=None, help='tracking result .fib format') 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]))