Beispiel #1
0
 def test_update_camera_position_component_marking(self, base_settings,
                                                   image_view, pos):
     roi = np.zeros(base_settings.image.get_channel(0).shape,
                    dtype=np.uint8)
     roi[..., 2:-2, 2:-2, 2:-2] = 1
     base_settings.roi = roi
     image_view.viewer.dims.set_point(1, 0)
     rect = Rect(image_view.viewer_widget.view.camera.get_state()["rect"])
     rect.pos = pos
     rect.size = (100, 100)
     image_view.viewer_widget.view.camera.set_state({"rect": rect})
     image_view.component_mark(1, False)
     assert image_view.viewer.dims.point[1] != 0
     assert image_view.viewer_widget.view.camera.get_state(
     )["rect"].pos != pos
 def _shift_if_need(self, labels, bound_info):
     if self.napari_viewer.dims.ndisplay != 2:
         return
     lower_bound = self._data_to_world(labels, bound_info.lower)
     upper_bound = self._data_to_world(labels, bound_info.upper)
     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"])
     if rect.contains(*l_bound) and rect.contains(*u_bound):
         return
     size = u_bound - l_bound
     rect.size = tuple(np.max([rect.size, size * 1.2], axis=0))
     pos = rect.pos
     if rect.left > l_bound[0]:
         pos = l_bound[0], pos[1]
     if rect.right < u_bound[0]:
         pos = pos[0] + u_bound[0] - rect.right, pos[1]
     if rect.bottom > l_bound[1]:
         pos = pos[0], l_bound[1]
     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})