コード例 #1
0
ファイル: qt_viewer.py プロジェクト: constantinpape/napari
    def _update_camera(self):
        if np.sum(self.viewer.dims.display) == 3:
            # Set a 3D camera
            self.view.camera = ArcballCamera(name="ArcballCamera")
            # flip y-axis to have correct alignment
            self.view.camera.flip = (0, 1, 0)
            min_shape, max_shape = self.viewer._calc_bbox()
            centroid = np.add(max_shape, min_shape) / 2
            size = np.subtract(max_shape, min_shape)
            # Scale the camera to the contents in the scene
            if len(centroid) > 0:
                centroid = centroid[-3:]
                self.view.camera.center = centroid[::-1]
                self.view.camera.scale_factor = 1.5 * np.mean(size[-3:])
        elif np.sum(self.viewer.dims.display) == 2:
            # Set 2D camera
            self.view.camera = PanZoomCamera(aspect=1, name="PanZoomCamera")
            # flip y-axis to have correct alignment
            self.view.camera.flip = (0, 1, 0)
            # Scale the camera to the contents in the scene
            self.view.camera.set_range()
        else:
            raise ValueError(
                "Invalid display flags set in dimensions {}".format(
                    self.viewer.dims.display
                )
            )

        self.view.camera.viewbox_key_event = viewbox_key_event
        # TO DO: Remove
        self.viewer._view = self.view
コード例 #2
0
ファイル: ant_simulator.py プロジェクト: K1seki221/jrt
    def __init__(self, N, width=600, height=600, decay_rate=1.0, hormone_secretion=None):
        from PIL.Image import open as open_image
        # setup simulation
        self._N = N
        self._INITIAL_FIELD = np.array(open_image(path.join(ENV_MAP_PATH, 'envmap01.png'))).astype(np.float32) / 255.
        #self._INITIAL_FIELD = np.zeros(self._INITIAL_FIELD.shape)
        self._FIELD_WIDTH = self._INITIAL_FIELD.shape[1]
        self._FIELD_HEIGHT = self._INITIAL_FIELD.shape[0]
        self._FIELD_DECAY_RATE = decay_rate
        self._SECRATION = hormone_secretion
        sensor_th = np.linspace(0, 2*np.pi, self.SENSOR_NUM, endpoint=False)
        self._SENSOR_POSITION = self.AGENT_RADIUS * np.array([np.cos(sensor_th), np.sin(sensor_th)]).T
        self.reset()  # initialize all variables, position, velocity and field status

        # setup display
        self._canvas = SceneCanvas(size=(width, height), position=(0,0), keys='interactive', title="ALife book "+self.__class__.__name__)
        self._canvas.events.mouse_double_click.connect(self._on_mouse_double_click)
        self._view = self._canvas.central_widget.add_view()
        self._view.camera = PanZoomCamera((0, 0, self._FIELD_WIDTH, self._FIELD_HEIGHT), aspect=1)
        self._field_image = Image(self._field, interpolation='nearest', parent=self._view.scene, method='subdivide', clim=(0,1))
        self._agent_polygon = []
        for i in range(self._N):
            p = AntSimulator._generate_agent_visual_polygon(self.AGENT_RADIUS)
            p.parent = self._field_image
            self._agent_polygon.append(p)
        self._canvas.show()
コード例 #3
0
    def __init__(self, viewer):
        super().__init__()

        QCoreApplication.setAttribute(
            Qt.AA_UseStyleSheetPropagationInWidgetStyles, True)
        self.setStyleSheet(self.themed_stylesheet)

        self.viewer = viewer
        self.viewer._qtviewer = self

        self.canvas = SceneCanvas(keys=None, vsync=True)
        self.canvas.native.setMinimumSize(QSize(100, 100))

        self.canvas.connect(self.on_mouse_move)
        self.canvas.connect(self.on_mouse_press)
        self.canvas.connect(self.on_mouse_release)
        self.canvas.connect(self.on_key_press)
        self.canvas.connect(self.on_key_release)

        self.view = self.canvas.central_widget.add_view()
        # Set 2D camera (the camera will scale to the contents in the scene)
        self.view.camera = PanZoomCamera(aspect=1)
        # flip y-axis to have correct aligment
        self.view.camera.flip = (0, 1, 0)
        self.view.camera.set_range()

        self.view.camera.viewbox_key_event = viewbox_key_event

        center = QWidget()
        layout = QVBoxLayout()
        layout.setContentsMargins(15, 20, 15, 10)
        layout.addWidget(self.canvas.native)
        dimsview = QtDims(self.viewer.dims)
        layout.addWidget(dimsview)
        center.setLayout(layout)

        # Add controls, center, and layerlist
        self.control_panel = QtControls(viewer)
        self.addWidget(self.control_panel)
        self.addWidget(center)
        self.addWidget(self.viewer.layers._qt)

        self._cursors = {
            'disabled':
            QCursor(
                QPixmap(':/icons/cursor/cursor_disabled.png').scaled(20, 20)),
            'cross':
            Qt.CrossCursor,
            'forbidden':
            Qt.ForbiddenCursor,
            'pointing':
            Qt.PointingHandCursor,
            'standard':
            QCursor()
        }
コード例 #4
0
ファイル: spscinspector.py プロジェクト: stargaser/spscviz
 def __init__(self, image, img_data, sources, poslist, index=0, **kwargs):
     PanZoomCamera.__init__(self, **kwargs)
     self.index = index
     self.image = image
     self.img_data = img_data
     self.sources = sources
     self.poslist = poslist
     #self.smin = 0.9*np.nanmin(self.img_data)
     #self.smax = 1.02*np.nanmax(self.img_data)
     pcts = np.nanpercentile(self.img_data, [5.0, 99.0])
     if np.all(np.isfinite(pcts)):
         self.smin = pcts[0]
         self.smax = pcts[1]
     self.accelerator = 5.0
     self.nsrc = len(poslist)
     self._keymap = {
         keys.UP: +1,
         keys.DOWN: -1,
         keys.LEFT: -1,
         keys.RIGHT: +1,
         keys.SPACE: +1
     }
     self._timer = Timer(0.2, start=False, connect=self.on_timer)
コード例 #5
0
ファイル: qt_viewer.py プロジェクト: nzatsepin/napari
    def _update_camera(self):
        if self.viewer.dims.ndisplay == 3:
            # Set a 3D camera
            if not isinstance(self.view.camera, ArcballCamera):
                self.view.camera = ArcballCamera(name="ArcballCamera", fov=0)
                # flip y-axis to have correct alignment
                # self.view.camera.flip = (0, 1, 0)

                self.view.camera.viewbox_key_event = viewbox_key_event
                self.viewer.reset_view()
        else:
            # Set 2D camera
            if not isinstance(self.view.camera, PanZoomCamera):
                self.view.camera = PanZoomCamera(aspect=1,
                                                 name="PanZoomCamera")
                # flip y-axis to have correct alignment
                self.view.camera.flip = (0, 1, 0)

                self.view.camera.viewbox_key_event = viewbox_key_event
                self.viewer.reset_view()
コード例 #6
0
ファイル: vispy_camera.py プロジェクト: rowhit/napari
    def __init__(self, view, camera, dims):
        self._view = view
        self._camera = camera
        self._dims = dims

        # Create 2D camera
        self._2D_camera = PanZoomCamera(aspect=1)
        # flip y-axis to have correct alignment
        self._2D_camera.flip = (0, 1, 0)
        self._2D_camera.viewbox_key_event = viewbox_key_event

        # Create 3D camera
        self._3D_camera = ArcballCamera(fov=0)
        self._3D_camera.viewbox_key_event = viewbox_key_event

        self._dims.events.ndisplay.connect(self._on_ndisplay_change,
                                           position='first')

        self._camera.events.center.connect(self._on_center_change)
        self._camera.events.zoom.connect(self._on_zoom_change)
        self._camera.events.angles.connect(self._on_angles_change)

        self._on_ndisplay_change(None)
コード例 #7
0
ファイル: _viewer.py プロジェクト: pep8speaks/napari-gui
    def __init__(self, viewer):
        super().__init__()

        self.canvas = SceneCanvas(keys=None, vsync=True)
        self.canvas.native.setMinimumSize(QSize(100, 100))
        self.view = self.canvas.central_widget.add_view()
        # Set 2D camera (the camera will scale to the contents in the scene)
        self.view.camera = PanZoomCamera(aspect=1)
        # flip y-axis to have correct aligment
        self.view.camera.flip = (0, 1, 0)
        self.view.camera.set_range()

        center = QWidget()
        layout = QVBoxLayout()
        layout.addWidget(self.canvas.native)
        layout.addWidget(viewer.dimensions._qt)
        center.setLayout(layout)

        # Add vertical sliders, center, and layerlist
        self.addWidget(viewer.controlBars._qt)
        self.addWidget(center)
        self.addWidget(viewer.layers._qt)

        viewer.dimensions._qt.setFixedHeight(0)
コード例 #8
0
ファイル: _viewer.py プロジェクト: shenlab-ucsf/SMART-Q
    def __init__(self, viewer):
        super().__init__()
        self.viewer = viewer
        self.sliders = []

        self.canvas = SceneCanvas(keys=None, vsync=True)

        layout = QGridLayout()
        self.setLayout(layout)
        layout.setContentsMargins(0, 0, 0, 0)
        #layout.setColumnStretch(0, 4)

        row = 0
        layout.addWidget(self.canvas.native, row, 0)
        #layout.setRowStretch(row, 1)

        self.view = self.canvas.central_widget.add_view()

        # Set 2D camera (the camera will scale to the contents in the scene)
        self.view.camera = PanZoomCamera(aspect=1)

        # flip y-axis to have correct aligment
        self.view.camera.flip = (0, 1, 0)
        self.view.camera.set_range()
コード例 #9
0
ファイル: spscinspector.py プロジェクト: stargaser/spscviz
    def viewbox_key_event(self, event):
        """ViewBox key event handler

        Parameters
        ----------
        event : instance of Event
            The event.
        """
        PanZoomCamera.viewbox_key_event(self, event)
        if event.handled or not self.interactive:
            return

        if event.type == 'key_press':
            if event.key in self._keymap:
                val = self._keymap[event.key]
                self.update_index(val)
                self.update_pan()
                self.view_changed()

            elif event.key == 'M':
                self._timer.start()

            elif event.key == 'S':
                self._timer.stop()

            #elif event.key == 'X':
            #    ind = np.argsort(self.poslist[:,0])
            #    self.poslist = self.poslist[ind]

            #elif event.key == 'Y':
            #    ind = np.argsort(self.poslist[:,1])
            #    self.poslist = self.poslist[ind]

            elif event.key == 'L':
                print(self.sources[self.sources.sourceid==self.sources['sourceid'][self.index]])
                
            elif event.key == 'T':
                sdiff = self.accelerator*(self.smax - self.smin)/255.0
                self.smax += sdiff
                self.smin += sdiff
                self.update_scale()
            
            elif event.key == 'B':
                sdiff = self.accelerator*(self.smax - self.smin)/255.0
                self.smax -= sdiff
                self.smin -= sdiff
                self.update_scale()
                
            elif event.key == 'N':
                sdiff = self.accelerator*(self.smax - self.smin)/255.0
                self.smax -= sdiff
                self.smin += sdiff
                self.update_scale()
                
            elif event.key == 'W':
                sdiff = self.accelerator*(self.smax - self.smin)/255.0
                self.smax += sdiff
                self.smin -= sdiff
                self.update_scale()
                
            elif event.key == 'U':
                print("Current stretch limits: %10.4g, %10.4g"%(self.smin, self.smax))
                self.smin = float(input("New lower value?"))
                self.smax = float(input("New upper value?"))
                self.update_scale()
コード例 #10
0
    def __init__(self, viewer):
        super().__init__()

        QCoreApplication.setAttribute(
            Qt.AA_UseStyleSheetPropagationInWidgetStyles, True
        )

        self.viewer = viewer

        self.canvas = SceneCanvas(keys=None, vsync=True)
        self.canvas.native.setMinimumSize(QSize(100, 100))

        self.canvas.connect(self.on_mouse_move)
        self.canvas.connect(self.on_mouse_press)
        self.canvas.connect(self.on_mouse_release)
        self.canvas.connect(self.on_key_press)
        self.canvas.connect(self.on_key_release)
        self.canvas.connect(self.on_draw)

        self.view = self.canvas.central_widget.add_view()

        # Set 2D camera (the camera will scale to the contents in the scene)
        self.view.camera = PanZoomCamera(aspect=1)
        # flip y-axis to have correct aligment
        self.view.camera.flip = (0, 1, 0)
        self.view.camera.set_range()
        self.view.camera.viewbox_key_event = viewbox_key_event

        # TO DO: Remove
        self.viewer._view = self.view

        center = QWidget()
        center_layout = QVBoxLayout()
        center_layout.setContentsMargins(15, 20, 15, 10)
        center_layout.addWidget(self.canvas.native)
        self.dims = QtDims(self.viewer.dims)
        center_layout.addWidget(self.dims)
        center.setLayout(center_layout)

        # Add controls, center, and layerlist
        self.control_panel = QtControls(viewer)
        self.addWidget(self.control_panel)
        self.addWidget(center)

        right = QWidget()
        right_layout = QVBoxLayout()
        self.layers = QtLayerList(self.viewer.layers)
        right_layout.addWidget(self.layers)
        self.buttons = QtLayersButtons(viewer)
        right_layout.addWidget(self.buttons)
        right.setLayout(right_layout)
        right.setMinimumSize(QSize(308, 250))

        self.addWidget(right)

        self._last_visited_dir = str(Path.home())

        self._cursors = {
            'disabled': QCursor(
                QPixmap(':/icons/cursor/cursor_disabled.png').scaled(20, 20)
            ),
            'cross': Qt.CrossCursor,
            'forbidden': Qt.ForbiddenCursor,
            'pointing': Qt.PointingHandCursor,
            'standard': QCursor(),
        }

        self._update_palette(viewer.palette)

        self._key_release_generators = {}

        self.viewer.events.interactive.connect(self._on_interactive)
        self.viewer.events.cursor.connect(self._on_cursor)
        self.viewer.events.reset_view.connect(self._on_reset_view)
        self.viewer.events.palette.connect(
            lambda event: self._update_palette(event.palette)
        )
        self.viewer.layers.events.reordered.connect(self._update_canvas)

        self.setAcceptDrops(True)