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

feat: Allow to set zoom factor from interface in Search Label napari plugin #538

Merged
merged 4 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .napari/DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ This widget is equivalent to the PartSeg ROI Mask Simple Measurement window.

Widget to find the layer with the given number By highlighting it or zooming on it. The highlight widget uses white color, so the highlight may not be visible if the label has a bright color.

https://user-images.githubusercontent.com/3826210/149330875-84939278-abfb-459a-bde6-e27b6186aa06.mp4
https://user-images.githubusercontent.com/3826210/154669409-cdac9be8-3dbf-4a0e-a66f-af8a44aed0fb.mp4

### Mask create

Expand Down
21 changes: 16 additions & 5 deletions package/PartSeg/plugins/napari_widgets/search_label_widget.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

import numpy as np
from magicgui.widgets import Container, HBox, PushButton, SpinBox, create_widget
from napari import Viewer
Expand All @@ -20,6 +22,8 @@ def __init__(self, napari_viewer: Viewer):
self.component_selector.changed.connect(self._component_num_changed)
self.labels_layer = create_widget(annotation=Labels, label="ROI", options={})
self.labels_layer.changed.connect(self._update_roi_info)
self.zoom_factor = create_widget(annotation=float, label="Zoom factor", value=1.2)
self.zoom_factor.changed.connect(self._component_num_changed)
self.stop = PushButton(name="Stop")
self.stop.clicked.connect(self._stop)
self.roi_info = None
Expand All @@ -33,11 +37,12 @@ def __init__(self, napari_viewer: Viewer):
layout2 = HBox(
widgets=(
self.labels_layer,
self.stop,
self.zoom_factor,
)
)
self.insert(0, layout)
self.insert(1, layout2)
self.insert(2, self.stop)

def _update_roi_info(self):
if self.labels_layer.value is None:
Expand Down Expand Up @@ -95,7 +100,9 @@ def _shift_if_need(self, labels, bound_info):
self._update_point(lower_bound, upper_bound)
l_bound = lower_bound[-2:][::-1]
u_bound = upper_bound[-2:][::-1]
rect = Rect(self.napari_viewer.window.qt_viewer.view.camera.get_state()["rect"])
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "Public access to Window.qt_viewer")
rect = Rect(self.napari_viewer.window.qt_viewer.view.camera.get_state()["rect"])
if rect.contains(*l_bound) and rect.contains(*u_bound):
return
size = u_bound - l_bound
Expand All @@ -110,7 +117,9 @@ def _shift_if_need(self, labels, bound_info):
if rect.top < u_bound[1]:
pos = pos[0], pos[1] + (u_bound[1] - rect.top)
rect.pos = pos
self.napari_viewer.window.qt_viewer.view.camera.set_state({"rect": rect})
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "Public access to Window.qt_viewer")
self.napari_viewer.window.qt_viewer.view.camera.set_state({"rect": rect})

@staticmethod
def _data_to_world(layer: Labels, cords):
Expand All @@ -128,10 +137,12 @@ def _zoom(self):
lower_bound = self._data_to_world(labels, bound_info.lower)
upper_bound = self._data_to_world(labels, bound_info.upper)
diff = upper_bound - lower_bound
frame = diff * 0.2
frame = diff * (self.zoom_factor.value - 1)
if self.napari_viewer.dims.ndisplay == 2:
rect = Rect(pos=(lower_bound - frame)[-2:][::-1], size=(diff + 2 * frame)[-2:][::-1])
self.napari_viewer.window.qt_viewer.view.camera.set_state({"rect": rect})
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "Public access to Window.qt_viewer")
self.napari_viewer.window.qt_viewer.view.camera.set_state({"rect": rect})
self._update_point(lower_bound, upper_bound)

def _update_point(self, lower_bound, upper_bound):
Expand Down