Skip to content

Commit

Permalink
Merge pull request #26 from MPI-Dortmund/gix_issue_20
Browse files Browse the repository at this point in the history
Allow 3d viewer with 2d data
  • Loading branch information
thorstenwagner authored Jun 7, 2023
2 parents 90b0718 + aa68167 commit 02f5ca3
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/box_manager/_qt/SelectMetric.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,11 @@ def _handle_insert(self, event):
layer.editable = False

if len(np.unique(get_size(layer))) == 1:
set_size(layer, np.ones(len(layer.data), dtype=bool), np.atleast_1d(get_size(layer)[0])[0])
set_size(
layer,
np.ones(len(layer.data), dtype=bool),
np.atleast_1d(get_size(layer)[0])[0],
)
layer.refresh()
layer.events.set_data.connect(self._update_on_data)
layer.events.editable.connect(self._update_editable)
Expand Down Expand Up @@ -1072,20 +1076,27 @@ def _update_on_data(self, event):
return

if not check_equal(layer, self.prev_valid_layers[layer.name][1]):
"""
We need to identify which coordinates have actually changed.
For this we use two sets and identify the old and new indices.
New indices are getting their feaures filled.
"""
old_data = self.prev_valid_layers[layer.name][1]

if self.napari_viewer.dims.ndim == 3:
set_old = {tuple(row.ravel().tolist()) for row in old_data}
set_new = {
if self.napari_viewer.dims.ndim == 3 and layer.ndim == 3:
set_old_coordinates = {
tuple(row.ravel().tolist()) for row in old_data
}
set_new_coordinates = {
tuple(row.ravel().tolist()) for row in layer.data
}
indices_old = {
row[self.napari_viewer.dims.order[0]]
for row in set_old - set_new
for row in set_old_coordinates - set_new_coordinates
}
indices_new = {
row[self.napari_viewer.dims.order[0]]
for row in set_new - set_old
for row in set_new_coordinates - set_old_coordinates
}
current_slices = list(indices_new | indices_old)
if indices_new:
Expand All @@ -1095,6 +1106,8 @@ def _update_on_data(self, event):
.sort_values()
.iloc[layer.features.shape[0] // 2]
)
elif self.napari_viewer.dims.ndim == 3 and layer.ndim == 2:
current_slices = [0]
elif self.napari_viewer.dims.ndim == 2:
current_slices = [0]
else:
Expand Down

0 comments on commit 02f5ca3

Please sign in to comment.