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)
import numpy as np from openalea.image.serial.all import imread, imsave from openalea.image.spatial_image import SpatialImage 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)
meshing_dirname = dirname.parent.parent import os if not os.path.exists(dirname+"/output_meshes/"+filename): os.makedirs(dirname+"/output_meshes/"+filename) inputfile = dirname+"/segmented_images/"+filename+".inr.gz" size = 100. #n_points = int((4.*np.power(size/4.,2.))/(np.power(15.,2))) n_points = 21 print size," -> ",n_points img = sphere_tissue_image(size=size, n_points=n_points) imsave(inputfile,img) #inputfile = "/Users/gcerutti/Developpement/openalea/openalea_marsalt/example/time_0_cut_seg_median.inr" 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