Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow 3d viewer with 2d data #26

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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