Beispiel #1
0
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)
stop = time.time()
print (stop - start)

lines = np.memmap(saved_flow, dtype=np.float64, mode='r', shape=(nb_step, vertices.shape[0], vertices.shape[1]))
tri_mesh_flow.set_vertices_flow(np.array(lines))
tri_mesh_flow.display(display_name="Trimeshpy: Flow resulting surface")
tri_mesh_flow.display_vertices_flow(display_name="Trimeshpy: Flow visualization")

"""
### save fibers in .fib normal
#line_to_save = streamline.compress_streamlines(np.swapaxes(lines, 0, 1))
line_to_save = np.swapaxes(lines, 0, 1)
lines_polydata = lines_to_vtk_polydata(line_to_save, None, np.float32)
# spot laplacian
spot_tmf.laplacian_smooth(100, 0.001, area_weighted=True, backward_step=True, flow_file=saved_flow)
spot_tmf.set_vertices_flow_from_memmap(saved_flow, 100, sp_mesh.get_nb_vertices())
spot_tmf.display()
spot_tmf.display_vertices_flow()

# spot curv_flow
spot_tmf.set_vertices_flow(sp_mesh.get_vertices())
spot_tmf.curvature_normal_smooth(20, 1000, area_weighted=True, backward_step=True, flow_file=saved_flow)
spot_tmf.set_vertices_flow_from_memmap(saved_flow, 20, sp_mesh.get_nb_vertices())
spot_tmf.display()
spot_tmf.display_vertices_flow()

# spot mass_stiffness
spot_tmf.set_vertices_flow(sp_mesh.get_vertices())
spot_tmf.mass_stiffness_smooth(30, 0.003, flow_file=saved_flow)
spot_tmf.set_vertices_flow_from_memmap(saved_flow, 30, sp_mesh.get_nb_vertices())
spot_tmf.display()
spot_tmf.display_vertices_flow()


# Init Brain
b_mesh = TriMesh_Vtk(brain_file_name, None)
brain_tmf = TriMeshFlow_Vtk(b_mesh.get_triangles(), b_mesh.get_vertices())
brain_tmf.display()

brain_tmf.mass_stiffness_smooth(10, 30, flow_file=saved_flow)
brain_tmf.set_vertices_flow_from_memmap(saved_flow, 10, b_mesh.get_nb_vertices())
brain_tmf.display()
brain_tmf.display_vertices_flow()
# spot curv_flow
spot_tmf.set_vertices_flow(sp_mesh.get_vertices())
spot_tmf.curvature_normal_smooth(20,
                                 1000,
                                 area_weighted=True,
                                 backward_step=True,
                                 flow_file=trimeshpy.data.output_test_flow)
spot_tmf.set_vertices_flow_from_memmap(trimeshpy.data.output_test_flow, 20,
                                       sp_mesh.get_nb_vertices())
spot_tmf.display()
spot_tmf.display_vertices_flow()

# spot mass_stiffness
spot_tmf.set_vertices_flow(sp_mesh.get_vertices())
spot_tmf.mass_stiffness_smooth(30,
                               0.003,
                               flow_file=trimeshpy.data.output_test_flow)
spot_tmf.set_vertices_flow_from_memmap(trimeshpy.data.output_test_flow, 30,
                                       sp_mesh.get_nb_vertices())
spot_tmf.display()
spot_tmf.display_vertices_flow()

# Init Brain
b_mesh = TriMesh_Vtk(trimeshpy.data.brain_lh, None)
brain_tmf = TriMeshFlow_Vtk(b_mesh.get_triangles(), b_mesh.get_vertices())
brain_tmf.display()

brain_tmf.mass_stiffness_smooth(10,
                                30,
                                flow_file=trimeshpy.data.output_test_flow)
brain_tmf.set_vertices_flow_from_memmap(trimeshpy.data.output_test_flow, 10,