Пример #1
0
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)
Пример #2
0
def test_tetrahedrization_optimization():

    topomesh = octahedron_tetrahedra()

    compute_tetrahedrization_topological_properties(topomesh)
    compute_tetrahedrization_geometrical_properties(topomesh)

    tetrahedrization_topomesh_add_exterior(topomesh)

    target_tetrahedra = []
    target_tetrahedra += [(2, 3, 5, 6)]
    target_tetrahedra += [(3, 4, 5, 6)]
    target_tetrahedra += [(2, 3, 5, 7)]
    target_tetrahedra += [(3, 4, 5, 7)]

    target_tetrahedra += [(1, 2, 3, 6)]
    target_tetrahedra += [(1, 3, 4, 6)]
    target_tetrahedra += [(1, 4, 5, 6)]
    target_tetrahedra += [(1, 2, 5, 6)]

    target_tetrahedra += [(1, 2, 3, 7)]
    target_tetrahedra += [(1, 3, 4, 7)]
    target_tetrahedra += [(1, 4, 5, 7)]
    target_tetrahedra += [(1, 2, 5, 7)]

    target_tetrahedra = dict(zip(target_tetrahedra, np.zeros((4, 3))))

    kwargs = {}
    kwargs['simulated_annealing_initial_temperature'] = 0.1
    kwargs['simulated_annealing_lambda'] = 0.9
    kwargs['simulated_annealing_minimal_temperature'] = 0.09
    kwargs['n_iterations'] = 1

    topomesh = tetrahedrization_topomesh_topological_optimization(
        topomesh,
        image_cell_vertex=target_tetrahedra,
        omega_energies=dict(image=1.0),
        **kwargs)
    tetrahedrization_topomesh_remove_exterior(topomesh)

    assert topomesh.nb_wisps(3) == 4

    for t in topomesh.wisps(3):
        print t, list(topomesh.borders(3, t, 3))

    optimized_tetras = np.sort(
        [list(topomesh.borders(3, t, 3)) for t in topomesh.wisps(3)])
    target_tetras = np.sort(target_tetrahedra.keys())
    target_tetras = target_tetras[target_tetras[:, 0] != 1]

    assert jaccard_index(optimized_tetras, target_tetras) == 1.0
Пример #3
0
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)
def test_tetrahedrization_optimization():

    topomesh = octahedron_tetrahedra()

    compute_tetrahedrization_topological_properties(topomesh)
    compute_tetrahedrization_geometrical_properties(topomesh)

    tetrahedrization_topomesh_add_exterior(topomesh)

    target_tetrahedra = []
    target_tetrahedra += [(2,3,5,6)]
    target_tetrahedra += [(3,4,5,6)]
    target_tetrahedra += [(2,3,5,7)]
    target_tetrahedra += [(3,4,5,7)]

    target_tetrahedra += [(1,2,3,6)]
    target_tetrahedra += [(1,3,4,6)]
    target_tetrahedra += [(1,4,5,6)]
    target_tetrahedra += [(1,2,5,6)]

    target_tetrahedra += [(1,2,3,7)]
    target_tetrahedra += [(1,3,4,7)]
    target_tetrahedra += [(1,4,5,7)]
    target_tetrahedra += [(1,2,5,7)]


    target_tetrahedra = dict(zip(target_tetrahedra,np.zeros((4,3))))

    kwargs = {}
    kwargs['simulated_annealing_initial_temperature'] = 0.1
    kwargs['simulated_annealing_lambda'] =  0.9
    kwargs['simulated_annealing_minimal_temperature'] = 0.09
    kwargs['n_iterations'] = 1

    topomesh = tetrahedrization_topomesh_topological_optimization(topomesh,image_cell_vertex=target_tetrahedra,omega_energies=dict(image=1.0),**kwargs)
    tetrahedrization_topomesh_remove_exterior(topomesh)

    assert topomesh.nb_wisps(3) == 4

    for t in topomesh.wisps(3):
        print t, list(topomesh.borders(3,t,3))

    optimized_tetras = np.sort([list(topomesh.borders(3,t,3)) for t in topomesh.wisps(3)])
    target_tetras = np.sort(target_tetrahedra.keys())
    target_tetras = target_tetras[target_tetras[:,0] != 1]

    assert jaccard_index(optimized_tetras,target_tetras) == 1.0