예제 #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
예제 #2
0
                    help='Output base name.',
                    required=True,
                    type=str)

args = parser.parse_args()

# Load surface file
surface = nb.load(args.surface)
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]))
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()
예제 #4
0
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)
points = tri_mesh_flow.mass_stiffness_smooth(nb_step, diffusion_step, flow_file=saved_flow)
#points = tri_mesh_flow.positive_mass_stiffness_smooth(nb_step, diffusion_step, flow_file=saved_flow)
#points = tri_mesh_flow.volume_mass_stiffness_smooth(nb_step, diffusion_step, flow_file=saved_flow)
예제 #5
0
    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))
예제 #6
0
# 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,
예제 #7
0
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()
"""

tri_mesh_flow = TriMeshFlow_Vtk(triangles, vertices)
print tri_mesh_flow.get_nb_vertices(), tri_mesh_flow.get_nb_triangles()

# Test parameters
nb_step = 10
diffusion_step = 1#
saved_flow = "testflow.dat"  # None
saved_fib = "testflow.fib"  # None

# 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)
#points = tri_mesh_flow.mass_stiffness_smooth(nb_step, diffusion_step, flow_file=saved_flow)
#points = tri_mesh_flow.positive_mass_stiffness_smooth(nb_step, diffusion_step, flow_file=saved_flow)