コード例 #1
0
ファイル: draco.py プロジェクト: VirtualPlants/draco_stem
    def adjacency_complex_optimization(
        self, n_iterations=1, omega_energies={"image": 10.0, "geometry": 0.1, "adjacency": 0.01}
    ):
        """Optimize the adjacency complex to match better the actual cell adjacencies in the tissue.

        The optimization is performed as an iterative energy minimization process of local topological transformations 
        (edge flips and triangle swaps) following a simulated annealing heuristic.

        Args:
            n_iterations (int): number of iterations (cycles of simulated annealing) to perform
            omega_energies (dict): weights of the different terms of the energy functional :
                • 'image' : energy measuring the difference between the adjacency complex simplices and the ones extracted from the image
                • 'geometry' : energy penalizing irregular tetrahedra in the adjacency complex
                • 'adjacency' : energy pulling the number of neighbors of each cell to an empirical optimal value according to its layer

        Updates:
            triangulation_topomesh (PropertyTopomesh) : the DracoMesh adjacency complex is set to this optimized complex.

        Returns:
            None
        """

        self.optimized_delaunay_topomesh = deepcopy(self.delaunay_topomesh)
        compute_tetrahedrization_geometrical_properties(self.optimized_delaunay_topomesh)
        tetrahedrization_topomesh_add_exterior(self.optimized_delaunay_topomesh)
        self.optimized_delaunay_topomesh = tetrahedrization_topomesh_topological_optimization(
            self.optimized_delaunay_topomesh,
            image_cell_vertex=self.image_cell_vertex,
            omega_energies=omega_energies,
            image_graph=self.image_graph,
            n_iterations=n_iterations,
        )
        tetrahedrization_topomesh_remove_exterior(self.optimized_delaunay_topomesh)
        clean_tetrahedrization(self.optimized_delaunay_topomesh, min_cell_neighbors=2)
        self.triangulation_topomesh = deepcopy(self.optimized_delaunay_topomesh)
コード例 #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_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