def test_draco_two_layers(): n_points = 12 img = sphere_tissue_image(size=100, n_points=n_points) draco = DracoMesh(img) draco.construct_adjacency_complex() triangular = ['star', 'remeshed', 'projected', 'regular', 'flat'] image_dual_topomesh = draco.dual_reconstruction( reconstruction_triangulation=triangular, adjacency_complex_degree=3)
def test_draco(): n_points = 12 img = sphere_tissue_image(size=100, n_points=n_points) draco = DracoMesh(img) assert draco.point_topomesh.nb_wisps(0) == n_points + 1 draco.delaunay_adjacency_complex(surface_cleaning_criteria=[]) image_tetrahedra = np.sort(draco.image_cell_vertex.keys()) image_tetrahedra = image_tetrahedra[image_tetrahedra[:, 0] != 1] draco_tetrahedra = np.sort([ list(draco.triangulation_topomesh.borders(3, t, 3)) for t in draco.triangulation_topomesh.wisps(3) ]) delaunay_consistency = jaccard_index(image_tetrahedra, draco_tetrahedra) draco.adjacency_complex_optimization(n_iterations=2) assert draco.triangulation_topomesh.nb_region_neighbors(0, 2) == n_points image_tetrahedra = np.sort(draco.image_cell_vertex.keys()) image_tetrahedra = image_tetrahedra[image_tetrahedra[:, 0] != 1] draco_tetrahedra = np.sort([ list(draco.triangulation_topomesh.borders(3, t, 3)) for t in draco.triangulation_topomesh.wisps(3) ]) draco_consistency = jaccard_index(image_tetrahedra, draco_tetrahedra) # print delaunay_consistency,' -> ',draco_consistency assert draco_consistency == 1 or (draco_consistency >= 0.9 and draco_consistency > delaunay_consistency) triangular = ['star', 'remeshed', 'projected', 'regular', 'flat'] image_dual_topomesh = draco.dual_reconstruction( reconstruction_triangulation=triangular, adjacency_complex_degree=3) image_volumes = array_dict( nd.sum(np.ones_like(img), img, index=np.unique(img)[1:]) * np.prod(img.voxelsize), np.unique(img)[1:]) compute_topomesh_property(image_dual_topomesh, 'volume', 3) draco_volumes = image_dual_topomesh.wisp_property('volume', 3) for c in image_dual_topomesh.wisps(3): assert np.isclose(image_volumes[c], draco_volumes[c], 0.33)
def test_draco(): n_points = 12 img = sphere_tissue_image(size=100,n_points=n_points) draco = DracoMesh(img) assert draco.point_topomesh.nb_wisps(0) == n_points+1 draco.delaunay_adjacency_complex(surface_cleaning_criteria = []) image_tetrahedra = np.sort(draco.image_cell_vertex.keys()) image_tetrahedra = image_tetrahedra[image_tetrahedra[:,0] != 1] draco_tetrahedra = np.sort([list(draco.triangulation_topomesh.borders(3,t,3)) for t in draco.triangulation_topomesh.wisps(3)]) delaunay_consistency = jaccard_index(image_tetrahedra, draco_tetrahedra) draco.adjacency_complex_optimization(n_iterations=2) assert draco.triangulation_topomesh.nb_region_neighbors(0,2) == n_points image_tetrahedra = np.sort(draco.image_cell_vertex.keys()) image_tetrahedra = image_tetrahedra[image_tetrahedra[:,0] != 1] draco_tetrahedra = np.sort([list(draco.triangulation_topomesh.borders(3,t,3)) for t in draco.triangulation_topomesh.wisps(3)]) draco_consistency = jaccard_index(image_tetrahedra, draco_tetrahedra) # print delaunay_consistency,' -> ',draco_consistency assert draco_consistency == 1 or (draco_consistency >= 0.9 and draco_consistency > delaunay_consistency) triangular = ['star','remeshed','projected','regular','flat'] image_dual_topomesh = draco.dual_reconstruction(reconstruction_triangulation = triangular, adjacency_complex_degree=3) image_volumes = array_dict(nd.sum(np.ones_like(img),img,index=np.unique(img)[1:])*np.prod(img.resolution),np.unique(img)[1:]) compute_topomesh_property(image_dual_topomesh,'volume',3) draco_volumes = image_dual_topomesh.wisp_property('volume',3) for c in image_dual_topomesh.wisps(3): assert np.isclose(image_volumes[c],draco_volumes[c],0.33)
from openalea.draco_stem.draco.draco import DracoMesh from openalea.draco_stem.example_image import sphere_tissue_image from openalea.oalab.colormap.colormap_def import load_colormaps world.clear() size = 100. n_points = 11 n_layers = 2 img = sphere_tissue_image(size=size, n_points=n_points, n_layers=n_layers) world.add(img,"segmented_image",colormap='glasbey',alphamap='constant',bg_id=1,alpha=0.25) draco = DracoMesh(image=img) draco.delaunay_adjacency_complex(surface_cleaning_criteria=[]) world.add(draco.triangulation_topomesh,'adjacency_complex') world['adjacency_complex']['display_3'] = False world['adjacency_complex']['display_0'] = True world['adjacency_complex_vertices']['display_colorbar'] = False world['adjacency_complex_vertices']['polydata_colormap'] = load_colormaps()['glasbey'] world['adjacency_complex_vertices']['point_radius'] = 1.5 draco.adjacency_complex_optimization(n_iterations=3) world['adjacency_complex']['coef_3'] = 0.9 world['adjacency_complex']['display_3'] = True world['adjacency_complex_cells']['display_colorbar'] = False world['adjacency_complex_cells']['polydata_colormap'] = load_colormaps()['grey']
img = imread(inputfile) #img[img==0]=1 #img = SpatialImage(np.concatenate([img[:,:,35:],np.ones((img.shape[0],img.shape[1],5))],axis=2).astype(np.uint16),resolution=img.resolution) cell_vertex_file = dirname+"/output_meshes/"+filename+"/image_cell_vertex.dict" triangulation_file = dirname+"/output_meshes/"+filename+"/"+filename+"_draco_adjacency_complex.pkl" from openalea.container import array_dict world.add(img,"segmented_image",colormap='glasbey',alphamap='constant',bg_id=1,alpha=1.0) #draco = DracoMesh(image=img, image_cell_vertex_file=cell_vertex_file, triangulation_file=triangulation_file) #draco = DracoMesh(image_file=inputfile, image_cell_vertex_file=cell_vertex_file) draco = DracoMesh(image=img) #world.add(draco.segmented_image-(draco.segmented_image==1),'segmented_image',colormap='glasbey',alphamap='constant',bg_id=0) world.add(draco.point_topomesh,'image_cells') world['image_cells_vertices'].set_attribute('point_radius',img.max()) world.add(draco.layer_edge_topomesh['L1'],'L1_adjacency') #world.add(draco.image_cell_vertex_topomesh,'image_cell_vertex') draco.delaunay_adjacency_complex(surface_cleaning_criteria = []) #draco.delaunay_adjacency_complex(surface_cleaning_criteria = ['surface','sliver','distance']) draco.adjacency_complex_optimization(n_iterations=2) from copy import deepcopy triangulation_topomesh = deepcopy(draco.triangulation_topomesh) world.add(triangulation_topomesh,'cell_adjacency_complex')
alphamap='constant', bg_id=1, alpha=1.0) #from openalea.cgal_meshing.idra import IdraMesh #topomesh = IdraMesh(img,mesh_fineness=1.0).idra_topomesh() #world.add(topomesh,'IDRA_mesh') #idra_file = dirname+"/output_meshes/"+filename+"/"+filename+"_IDRA_mesh.ply" #save_ply_property_topomesh(topomesh,idra_file,color_faces=True,colormap=load_colormaps()['glasbey']) #from openalea.draco_stem.stem.tissue_mesh_optimization import optimize_topomesh #draco = DracoMesh(image=img, image_cell_vertex_file=cell_vertex_file, triangulation_file=triangulation_file) draco = DracoMesh(image_file=inputfile, image_cell_vertex_file=cell_vertex_file, triangulation_file=triangulation_file) #draco = DracoMesh(image=img) image_cell_vertex = draco.image_cell_vertex #optimized_topomesh = optimize_topomesh(topomesh,omega_forces={'regularization':0.00,'neighborhood':0.0,'laplacian':1.0,'planarization':0.27,'epidermis_planarization':0.07,'convexity':0.02},omega_regularization_max=0.01,edge_flip=True,cell_vertex_motion=True,image_cell_vertex=image_cell_vertex) #optimized_topomesh = optimize_topomesh(optimized_topomesh,omega_forces={'taubin_smoothing':0.65},cell_vertex_motion=True,image_cell_vertex=image_cell_vertex) #world.add(optimized_topomesh,'IDRA_STEM_mesh') #idra_stem_file = dirname+"/output_meshes/"+filename+"/"+filename+"_IDRA_STEM_mesh.ply" #save_ply_property_topomesh(optimized_topomesh,idra_stem_file,color_faces=True,colormap=load_colormaps()['glasbey']) #world.add(draco.segmented_image-(draco.segmented_image==1),'segmented_image',colormap='glasbey',alphamap='constant',bg_id=0) #world.add(draco.point_topomesh,'image_cells') #world['image_cells_vertices'].set_attribute('point_radius',img.max()) #world.add(draco.layer_edge_topomesh['L1'],'L1_adjacency')