예제 #1
0
def test_roi3d(dataxyz):
    roi_2d = PolygonalROI(vx=[0.5, 2.5, 2.5, 0.5], vy=[1, 1, 3.5, 3.5])
    roi = Projected3dROI(roi_2d, projection_matrix=np.eye(4))
    assert roi.contains(dataxyz['x'], dataxyz['y']).tolist() == [True, True, False]

    roi_2d = PolygonalROI(vx=[1.5, 3.5, 3.5, 1.5], vy=[4, 4, 6.5, 6.5])
    roi = Projected3dROI(roi_2d, projection_matrix=xyzw2yxzw)
    assert roi.contains3d(dataxyz['x'], dataxyz['y'], dataxyz['z']).tolist() == [True, True, False]
예제 #2
0
파일: view.py 프로젝트: eteq/glue-jupyter
 def on_selection(self, data, other=None):
     with self.output_widget:
         W = np.matrix(self.figure.matrix_world).reshape((4, 4)).T
         P = np.matrix(self.figure.matrix_projection).reshape((4, 4)).T
         M = np.dot(P, W)
         if data['device']:
             if data['type'] == 'lasso':
                 region = data['device']
                 vx, vy = zip(*region)
                 roi_2d = PolygonalROI(vx=vx, vy=vy)
             elif data['type'] == 'circle':
                 x1, y1 = data['device']['begin']
                 x2, y2 = data['device']['end']
                 dx = x2 - x1
                 dy = y2 - y1
                 r = (dx**2 + dy**2)**0.5
                 roi_2d = CircularROI(xc=x1, yc=y1, radius=r)
             elif data['type'] == 'rectangle':
                 x1, y1 = data['device']['begin']
                 x2, y2 = data['device']['end']
                 x = [x1, x2]
                 y = [y1, y2]
                 roi_2d = RectangularROI(xmin=min(x),
                                         xmax=max(x),
                                         ymin=min(y),
                                         ymax=max(y))
             roi = Projected3dROI(roi_2d, M)
             self.apply_roi(roi)
예제 #3
0
    def release(self, event):

        if event.button == 1:

            if self.corner2 is not None:
                roi = Projected3dROI(roi_2d=RectangularROI(*self.bounds),
                                     projection_matrix=self.projection_matrix)
                self.apply_roi(roi)

            self.reset()

            self.viewer.toolbar.active_tool = None
예제 #4
0
    def on_selection(self, data, other=None):

        if data['type'] != self.selector:
            return

        if data['device']:
            with self.viewer.output_widget:
                region = data['device']
                vx, vy = zip(*region)
                roi_2d = PolygonalROI(vx=vx, vy=vy)
                roi = Projected3dROI(roi_2d, self.projection_matrix)
                self.viewer.apply_roi(roi)
예제 #5
0
    def release(self, event):

        if event.button == 1:

            if self.radius > 0:
                roi = Projected3dROI(roi_2d=CircularROI(
                    self.center[0], self.center[1], self.radius),
                                     projection_matrix=self.projection_matrix)
                self.apply_roi(roi)

            self.reset()

            self.viewer.toolbar.active_tool = None
예제 #6
0
    def release(self, event):

        if event.button == 1:

            if len(self.line_pos) > 0:
                vx, vy = np.array(self.line_pos).transpose()
                roi = Projected3dROI(roi_2d=PolygonalROI(vx, vy),
                                     projection_matrix=self.projection_matrix)
                self.apply_roi(roi)

            self.reset()

            self.viewer.toolbar.active_tool = None
예제 #7
0
    def on_selection(self, data, other=None):

        if data['type'] != self.selector:
            return

        if data['device']:
            with self.viewer.output_widget:
                x1, y1 = data['device']['begin']
                x2, y2 = data['device']['end']
                dx = x2 - x1
                dy = y2 - y1
                r = (dx**2 + dy**2)**0.5
                roi_2d = CircularROI(xc=x1, yc=y1, radius=r)
                roi = Projected3dROI(roi_2d, self.projection_matrix)
                self.viewer.apply_roi(roi)
예제 #8
0
    def on_selection(self, data, other=None):

        if data['type'] != self.selector:
            return

        if data['device']:
            with self.viewer.output_widget:
                x1, y1 = data['device']['begin']
                x2, y2 = data['device']['end']
                x = [x1, x2]
                y = [y1, y2]
                roi_2d = RectangularROI(xmin=min(x),
                                        xmax=max(x),
                                        ymin=min(y),
                                        ymax=max(y))
                roi = Projected3dROI(roi_2d, self.projection_matrix)
                self.viewer.apply_roi(roi)
 def press(self, event):
     if event.button == 1:
         roi = Projected3dROI(roi_2d=NearestNeighborROI(event.pos[0], event.pos[1],
                                                        max_radius=5),
                              projection_matrix=self.projection_matrix)
         self.apply_roi(roi)