diff --git a/src/gnomon_package_tissueimagemesh/algorithm/meshFilter/surfaceCellMeshDecimation.py b/src/gnomon_package_tissueimagemesh/algorithm/meshFilter/surfaceCellMeshDecimation.py index 46d972aebdd3c25f778c50384690eaa189ff9f58..bd66fb353f7b550743a9eb6d16db8f109b45bdaa 100644 --- a/src/gnomon_package_tissueimagemesh/algorithm/meshFilter/surfaceCellMeshDecimation.py +++ b/src/gnomon_package_tissueimagemesh/algorithm/meshFilter/surfaceCellMeshDecimation.py @@ -9,20 +9,12 @@ from gnomon.utils.decorators import meshInput, meshOutput # #} # add your imports before the next gnomon tag -from copy import deepcopy +from timagetk_geometry.image_surface.tissue_image_mesh import surface_tissue_mesh_collapse_same_label_edges -import numpy as np -import scipy.ndimage as nd - -from cellcomplex.property_topomesh.analysis import compute_topomesh_property, compute_topomesh_vertex_property_from_faces -from cellcomplex.property_topomesh.topological_operations import topomesh_collapse_edge -from cellcomplex.property_topomesh.extraction import clean_topomesh_properties - -from cellcomplex.utils import array_dict # {# gnomon, plugin.class # do not modify, any code after the gnomon tag will be overwritten -@algorithmPlugin(version='0.1.0', coreversion='0.81.0', name="Surface Cell Projection") +@algorithmPlugin(version='0.1.0', coreversion='0.81.0', name="Surface cell mesh decimation") @meshInput(attr='in_surface_topomesh', data_plugin='gnomonMeshDataPropertyTopomesh') @meshOutput(attr='surface_topomesh', data_plugin='gnomonMeshDataPropertyTopomesh') class surfaceCellMeshDecimation(gnomon.core.gnomonAbstractMeshFilter): @@ -35,57 +27,21 @@ class surfaceCellMeshDecimation(gnomon.core.gnomonAbstractMeshFilter): self._parameters = {} - # self.seg_img = {} self.in_surface_topomesh = {} self.surface_topomesh = {} def run(self): self.surface_topomesh = {} for time in self.in_surface_topomesh.keys(): - surface_topomesh = deepcopy(self.in_surface_topomesh[time]) + in_surface_topomesh = self.in_surface_topomesh[time] # #} # implement the run method - edges = np.array(list(surface_topomesh.wisps(1))) - edge_vertices = surface_topomesh.wisp_property('vertices', 1).values(edges) - edge_vertex_cells = surface_topomesh.wisp_property('label', 0).values(edge_vertices) - - inner_edges = edges[edge_vertex_cells[:, 1] == edge_vertex_cells[:, 0]] - inner_edge_lengths = surface_topomesh.wisp_property('length', 1).values(inner_edges) - - inner_edges = inner_edges[np.argsort(inner_edge_lengths)] - collapsed_edges = inner_edges - - iteration = 0 - while len(collapsed_edges)>0: - collapsed_edges = [] - affected_edges = set() - for e in inner_edges: - if not e in affected_edges: - neighbor_edges = set(surface_topomesh.border_neighbors(1, e)) - collapsed = topomesh_collapse_edge(surface_topomesh, e) - if collapsed: - collapsed_edges += [e] - affected_edges |= set(neighbor_edges) - iteration += 1 - print(f"Collapsed {len(collapsed_edges)} edges") - - clean_topomesh_properties(surface_topomesh) - compute_topomesh_property(surface_topomesh, 'vertices', 1) - compute_topomesh_property(surface_topomesh, 'length', 1) - - edges = np.array(list(surface_topomesh.wisps(1))) - edge_vertices = surface_topomesh.wisp_property('vertices', 1).values(edges) - edge_vertex_cells = surface_topomesh.wisp_property('label', 0).values(edge_vertices) - - inner_edges = edges[edge_vertex_cells[:, 1] == edge_vertex_cells[:, 0]] - inner_edge_lengths = surface_topomesh.wisp_property('length', 1).values(inner_edges) - - inner_edges = inner_edges[np.argsort(inner_edge_lengths)] + surface_topomesh = surface_tissue_mesh_collapse_same_label_edges( + in_surface_topomesh + ) - compute_topomesh_property(surface_topomesh, 'borders', 2) - compute_topomesh_property(surface_topomesh, 'vertices', 2) - compute_topomesh_property(surface_topomesh, 'oriented_vertices', 2) - compute_topomesh_property(surface_topomesh, 'oriented_borders', 3) + print(surface_topomesh.nb_wisps(0)) + print(surface_topomesh.wisp_property('label', 0)) self.surface_topomesh[time] = surface_topomesh