Exemplo n.º 1
0
T = img.affine[:3,3]
z = img.header.get_zooms()
mid_point = np.array(img.shape, dtype=np.float)/2.0

# Input assert
assert not(args.ir and args.r), "--ir or --r option"
assert not(args.it and args.t), "--it or --t option"
assert not(args.im and args.m and args.imz and args.mz ), "--m,im,mz or imz option"
assert not(args.tr and args.itr and args.tir and args.itir), "--tr,itr,tir or itir option"


mesh = TriMesh_Vtk(surface_file_in, None)
    
if args.test :
    tranfo = [-2,33,12]
    mesh.set_vertices(mesh.vertices_translation(tranfo))
    print "test : " + str(tranfo)
    
#todo nii rotation before or after translation?!?!?!
if args.r :
    tranfo = R
    mesh.set_vertices(mesh.vertices_rotation(tranfo))
    print "r : " + str(tranfo)
elif args.ir :
    tranfo = R.T
    mesh.set_vertices(mesh.vertices_rotation(R))
    print "ir : " + str(tranfo)
    
# nii translation
if args.t:
    tranfo = T
Exemplo n.º 2
0
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

# Test functions
start = time.time()
#points = tri_mesh_flow.laplacian_smooth(nb_step, diffusion_step, l2_dist_weighted=False, area_weighted=False, backward_step=False, flow_file=saved_flow)
#points = tri_mesh_flow.curvature_normal_smooth(nb_step, diffusion_step, area_weighted=True, backward_step=True, flow_file=saved_flow)
#points = tri_mesh_flow.positive_curvature_normal_smooth(nb_step, diffusion_step, area_weighted=True, backward_step=True, flow_file=saved_flow)
Exemplo n.º 3
0
if args.json is not None:
    json_file = args.json
else:
    json_file = "se_script_config.json"
    
with open(json_file) as data_file:    
    config = json.load(data_file)

rh_mesh = TriMesh_Vtk(args.rh_surface, None)
lh_mesh = TriMesh_Vtk(args.lh_surface, None)

run = config["run"]
if run["translate"]:
    t = fsf.get_xras_translation(args.mask)
    rh_mesh.set_vertices(rh_mesh.vertices_translation(t))
    lh_mesh.set_vertices(lh_mesh.vertices_translation(t))
    print "xras translation", t

if run["space"]:
    if config["space"]["auto"]:
        vox = fsf.get_nifti_voxel_space(args.mask)
        world = fsf.get_nifti_voxel_space(args.mask)
    else: 
        vox = config["space"]["vox"]
        world = config["space"]["world"]
        
    rh_mesh = fsf.vox_to_world(rh_mesh, vox, world)
    lh_mesh = fsf.vox_to_world(lh_mesh, vox, world)
    
    
Exemplo n.º 4
0
if args.world_lps:
    rotation = volume_nib.get_affine()[:3,:3]
    translation = volume_nib.get_affine()[:3,3]
    voxel_space = nib.aff2axcodes(volume_nib.get_affine())
    
    new_vertice = vertices.dot(rotation)
    new_vertice = new_vertice + translation
    # 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.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)
Exemplo n.º 5
0
    
    # Find freesurfer transformation
    transform_command_line = "mri_info --cras " + nii_name + " --o " +  temp_file_dir
    print "run :", transform_command_line
    os.system(transform_command_line)
    
    print "read :", temp_file_dir
    open_file = open(temp_file_dir, 'r')
    center_ras = open_file.read()
    open_file.close()
    os.remove(temp_file_dir)
    os.rmdir(temp_dir)
    
    print center_ras
    translate = np.array([float(x) for x in center_ras.split()])# temp HACK
    mesh.set_vertices(mesh.vertices_translation(translate))
    print "cras", translate
    
    
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:
Exemplo n.º 6
0
mesh.display()

"""
from scipy.spatial import Delaunay

# Triangulate parameter space to determine the triangles
#tri = mtri.Triangulation(u, v)
tri = Delaunay(vertices)
 

delaunay_triangles = np.vstack((tri.simplices[:,0:3], np.roll(tri.simplices,2,axis=1)[:,0:3]))
mesh.set_triangles(tri.simplices[:,0:3]) 
mesh.display()
"""

"""
#pre-smooth
vertices = mesh.laplacian_smooth(2, 5.0, l2_dist_weighted=False, area_weighted=False, backward_step=True, flow_file=None)
mesh.set_vertices(vertices)
#mesh.display()

# test colors curvature
test_curv = mesh.vertices_cotan_curvature(False)
color_curv = np.zeros([len(test_curv),3])
max_curv_color = 10000
color_curv[:,0] = np.maximum(-test_curv,0) * max_curv_color / np.abs(test_curv).max()
color_curv[:,2] = np.maximum(test_curv,0) * max_curv_color / np.abs(test_curv).max()
mesh.set_colors(color_curv)
mesh.display()
exit()
"""