Skip to content

Commit f6c3f9d

Browse files
authored
Merge pull request #104 from funkelab/70-replace-tracks-controller
70-replace-tracks-controller (funtracks)
2 parents 6d17332 + b4bdb2f commit f6c3f9d

File tree

3 files changed

+8
-50
lines changed

3 files changed

+8
-50
lines changed

finn/track_data_views/views/layers/track_labels.py

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import finn
99
from finn.utils import DirectLabelColormap
1010
from finn.utils.action_manager import action_manager
11-
from finn.utils.notifications import show_info, show_warning
11+
from finn.utils.notifications import show_info
1212

1313
if TYPE_CHECKING:
1414
from finn.track_data_views.views_coordinator.tracks_viewer import TracksViewer
@@ -229,53 +229,8 @@ def _on_paint(self, event):
229229
0
230230
] # also pass on the current time point to know which node to select later
231231
new_value, updated_pixels = self._parse_paint_event(event.value)
232-
# updated_pixels is a list of tuples. Each tuple is (indices, old_value)
233-
to_delete = [] # (node_ids, pixels)
234-
to_update_smaller = [] # (node_id, pixels)
235-
to_update_bigger = [] # (node_id, pixels)
236-
to_add = [] # (node_id, track_id, pixels)
237-
for pixels, old_value in updated_pixels:
238-
ndim = len(pixels)
239-
if old_value == 0:
240-
continue
241-
time = pixels[0][0]
242-
removed_node = old_value
243-
assert removed_node is not None, (
244-
f"Node with label {old_value} in time {time} was not found"
245-
)
246-
# check if all pixels of old_value are removed
247-
if np.sum(self.data[time] == old_value) == 0:
248-
to_delete.append((removed_node, pixels))
249-
else:
250-
to_update_smaller.append((removed_node, pixels))
251-
if new_value != 0:
252-
all_pixels = tuple(
253-
np.concatenate([pixels[dim] for pixels, _ in updated_pixels])
254-
for dim in range(ndim)
255-
)
256-
for _ in np.unique(all_pixels[0]):
257-
existing_node = self.tracks_viewer.tracks.graph.has_node(new_value)
258-
if existing_node:
259-
to_update_bigger.append((new_value, all_pixels))
260-
else:
261-
to_add.append((new_value, self.selected_track, all_pixels))
262-
263-
if len(to_delete) > 0 and len(to_add) > 0:
264-
show_warning(
265-
"This paint or fill operation completely replaced one label with a "
266-
"new label. This is currently not supported."
267-
" If you want to update the track id of the node, please edit the "
268-
"edges directly instead."
269-
)
270-
self._revert_paint(event)
271-
self.refresh()
272-
return
273232
self.tracks_viewer.tracks_controller.update_segmentations(
274-
to_delete,
275-
to_update_smaller,
276-
to_update_bigger,
277-
to_add,
278-
current_timepoint,
233+
new_value, updated_pixels, current_timepoint, self.selected_track
279234
)
280235

281236
def _refresh(self):

finn/track_import_export/load_tracks.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,11 @@ def tracks_from_df(
261261
):
262262
nodes = tracks.graph.nodes
263263
times = tracks.get_times(nodes)
264-
computed_attrs = tracks._compute_node_attrs(nodes, times)
265-
areas = computed_attrs[NodeAttr.AREA.value]
264+
computed_attrs = [
265+
tracks._compute_node_attrs(node, time)
266+
for node, time in zip(nodes, times, strict=False)
267+
]
268+
areas = [attrs[NodeAttr.AREA.value] for attrs in computed_attrs]
266269
tracks._set_nodes_attr(nodes, NodeAttr.AREA.value, areas)
267270

268271
return tracks

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ dependencies = [
7171
"typing_extensions>=4.2.0",
7272
"vispy>=0.14.1,<0.15",
7373
"wrapt>=1.11.1",
74-
"funtracks>=1.2.1",
74+
"funtracks>=1.3.0",
7575
"pyqtgraph",
7676
"fonticon-fontawesome6",
7777
"zarr<3",

0 commit comments

Comments
 (0)