Example #1
0
def flow_trajectories(vertices, triangles, flow_file, steps=10, timestep=5):
    """
    Compute the positive mass stiffness surface flow of a surface mesh.

    Parameters:
    - - - - -
    vertices: float array
        list of vertices in mesh
    triangles: int array
        list of faces in mesh
    flow_file: string
        file (memory map) in which to save flow lines
    steps: int
        number of diffusion steps
    timestep: int
        diffusion time
    """

    # initialize flow object
    tri_mesh_flow = TriMeshFlow_Vtk(triangles, vertices)
    # compute final flow surface
    points = tri_mesh_flow.positive_mass_stiffness_smooth(steps,
                                                          timestep,
                                                          flow_file=flow_file)
    # get flow trajectory for each mesh vertex
    flow_lines = tri_mesh_flow.get_vertices_flow()

    return flow_lines
vertices = surface.darrays[0].data
triangles = surface.darrays[1].data

# Get diffusion step parameters
nb_step = args.diffusion_steps
nb_size = args.diffusion_size

tri_mesh_flow = TriMeshFlow_Vtk(triangles, vertices)

saved_flow = trimeshpy.data.output_test_flow
saved_fib = trimeshpy.data.output_test_fib

out_base = args.output_base
dat_file = ''.join([out_base, '.lines.dat'])
points = tri_mesh_flow.positive_mass_stiffness_smooth(nb_step,
                                                      nb_size,
                                                      flow_file=dat_file)

lines = np.memmap(dat_file,
                  dtype=np.float64,
                  mode='r',
                  shape=(nb_step, vertices.shape[0], vertices.shape[1]))

lines = np.asarray(lines)
L = {'lines': lines}
mat_file = ''.join([out_base, '.lines.mat'])
sio.savemat(file_name=mat_file, mdict=L)

# Compute length of flow lines
flow_lengths = flow_lengths(lines)
    required=False, default='gifti', type=str, choices=['gifti','freesurfer'])
parser.add_argument('--nb', help='Number of smoothing iterations.',
    required=True, type=int)
parser.add_argument('--ds', help='Number of diffusion steps.',
    required=True, type=int)

args = parser.parse_args()

nb_step = args.nb
diffusion_step = args.ds

# Load surface file
if args.surface_type == 'gifti':
    surface = nb.load(args.surface)
    vertices = surface.darrays[0].data
    triangles = surface.darrays[1].data
else:
    vertices, triangles = nb.freesurfer.io.read_geometry(args.surface)

saved_flow = trimeshpy.data.output_test_flow
saved_fib = trimeshpy.data.output_test_fib

tri_mesh_flow = TriMeshFlow_Vtk(triangles, vertices)

start = time.time()
points = tri_mesh_flow.positive_mass_stiffness_smooth(
    nb_step, diffusion_step, flow_file=saved_flow)
stop = time.time()

print('Total time: {:}'.format(start-stop))