def on_mouse_release(self, event):

        # Get the visible datasets
        if event.button == 1 and self.mode is not None:
            visible_data, visual = self.get_visible_data()
            data = self.get_map_data()

            if len(self.line_pos) == 0:
                self.lasso_reset()
                return

            elif self.mode is 'lasso':
                selection_path = path.Path(self.line_pos, closed=True)
                mask = selection_path.contains_points(data)

            elif self.mode is 'ellipse':
                xmin, ymin = np.min(self.line_pos[:, 0]), np.min(self.line_pos[:, 1])
                xmax, ymax = np.max(self.line_pos[:, 0]), np.max(self.line_pos[:, 1])
                c = CircularROI((xmax + xmin) / 2., (ymax + ymin) / 2., (xmax - xmin) / 2.)  # (xc, yc, radius)
                mask = c.contains(data[:, 0], data[:, 1])

            elif self.mode is 'rectangle':
                xmin, ymin = np.min(self.line_pos[:, 0]), np.min(self.line_pos[:, 1])
                xmax, ymax = np.max(self.line_pos[:, 0]), np.max(self.line_pos[:, 1])
                r = RectangularROI(xmin, xmax, ymin, ymax)
                mask = r.contains(data[:, 0], data[:, 1])

            else:
                raise ValueError("Unknown mode: {0}".format(self.mode))

            self.mark_selected(mask, visible_data)

            self.lasso_reset()
Beispiel #2
0
    def on_mouse_release(self, event):
        """
        Get the mask of selected data and get them highlighted.
        :param event:
        """
        # Get the visible datasets
        if event.button == 1 and self.mode and self.mode is not 'point':
            visible_data, visual = self.get_visible_data()
            data = self.get_map_data()
            if len(self.line_pos) == 0:
                self.lasso_reset()
                return

            elif self.mode is 'lasso':
                # Note, we use points_inside_poly here instead of calling e.g.
                # matplotlib directly, because we include some optimizations
                # in points_inside_poly
                vx, vy = np.array(self.line_pos).transpose()
                x, y = data.transpose()
                mask = points_inside_poly(x, y, vx, vy)

            elif self.mode is 'ellipse':
                xmin, ymin = np.min(self.line_pos[:, 0]), \
                             np.min(self.line_pos[:, 1])
                xmax, ymax = np.max(self.line_pos[:, 0]), \
                             np.max(self.line_pos[:, 1])

                # (xc, yc, radius)
                c = CircularROI((xmax+xmin)/2., (ymax+ymin)/2., (xmax-xmin)/2.)
                mask = c.contains(data[:, 0], data[:, 1])

            elif self.mode is 'rectangle':
                xmin, ymin = np.min(self.line_pos[:, 0]), \
                             np.min(self.line_pos[:, 1])
                xmax, ymax = np.max(self.line_pos[:, 0]), \
                             np.max(self.line_pos[:, 1])
                r = RectangularROI(xmin, xmax, ymin, ymax)
                mask = r.contains(data[:, 0], data[:, 1])

            else:
                raise ValueError("Unknown mode: {0}".format(self.mode))

            # Mask matches transposed volume data set rather than the original one.
            # The ravel here is to make mask compatible with ElementSubsetState input.
            new_mask = np.reshape(mask, self.trans_ones_data.shape)
            new_mask = np.ravel(np.transpose(new_mask))
            self.mark_selected(new_mask, self.visible_data)

            self.lasso_reset()
Beispiel #3
0
    def on_mouse_release(self, event):

        visible_data, visual = self.get_visible_data()

        # Get the visible datasets
        if event.button == 1 and self.mode is not None:

            visible_data, visual = self.get_visible_data()
            data = self.get_map_data()
            if len(self.line_pos) == 0:
                self.lasso_reset()
                return

            elif self.mode is 'lasso':
                # Note, we use points_inside_poly here instead of calling e.g.
                # matplotlib directly, because we include some optimizations
                # in points_inside_poly
                vx, vy = np.array(self.line_pos).transpose()
                x, y = data.transpose()
                mask = points_inside_poly(x, y, vx, vy)

            elif self.mode is 'ellipse':
                xmin, ymin = np.min(self.line_pos[:, 0]), np.min(self.line_pos[:, 1])
                xmax, ymax = np.max(self.line_pos[:, 0]), np.max(self.line_pos[:, 1])
                c = CircularROI((xmax + xmin) / 2., (ymax + ymin) / 2., (xmax - xmin) / 2.)  # (xc, yc, radius)
                mask = c.contains(data[:, 0], data[:, 1])

            elif self.mode is 'rectangle':
                xmin, ymin = np.min(self.line_pos[:, 0]), np.min(self.line_pos[:, 1])
                xmax, ymax = np.max(self.line_pos[:, 0]), np.max(self.line_pos[:, 1])
                r = RectangularROI(xmin, xmax, ymin, ymax)
                mask = r.contains(data[:, 0], data[:, 1])

            else:
                raise ValueError("Unknown mode: {0}".format(self.mode))

            # Mask matches transposed volume data set rather than the original one.
            # The ravel here is to make mask compatible with ElementSubsetState input.
            new_mask = np.reshape(mask, self.trans_ones_data.shape)
            new_mask = np.ravel(np.transpose(new_mask))
            self.mark_selected(new_mask, visible_data)

            self.lasso_reset()
Beispiel #4
0
    def on_mouse_release(self, event):

        # Get the visible datasets
        if event.button == 1 and self.mode is not None:
            visible_data, visual = self.get_visible_data()
            data = self.get_map_data()

            if len(self.line_pos) == 0:
                self.lasso_reset()
                return

            elif self.mode is 'lasso':
                selection_path = path.Path(self.line_pos, closed=True)
                mask = selection_path.contains_points(data)

            elif self.mode is 'ellipse':
                xmin, ymin = np.min(self.line_pos[:,
                                                  0]), np.min(self.line_pos[:,
                                                                            1])
                xmax, ymax = np.max(self.line_pos[:,
                                                  0]), np.max(self.line_pos[:,
                                                                            1])
                c = CircularROI((xmax + xmin) / 2., (ymax + ymin) / 2.,
                                (xmax - xmin) / 2.)  # (xc, yc, radius)
                mask = c.contains(data[:, 0], data[:, 1])

            elif self.mode is 'rectangle':
                xmin, ymin = np.min(self.line_pos[:,
                                                  0]), np.min(self.line_pos[:,
                                                                            1])
                xmax, ymax = np.max(self.line_pos[:,
                                                  0]), np.max(self.line_pos[:,
                                                                            1])
                r = RectangularROI(xmin, xmax, ymin, ymax)
                mask = r.contains(data[:, 0], data[:, 1])

            else:
                raise ValueError("Unknown mode: {0}".format(self.mode))

            self.mark_selected(mask, visible_data)

            self.lasso_reset()
    def release(self, event):

        if event.button == 1:

            if self.corner2 is not None:

                r = RectangularROI(*self.bounds)

                indices_dict = {}

                for layer_artist in self.iter_data_layer_artists():

                    data = get_map_data(layer_artist, self.viewer)
                    mask = r.contains(data[:, 0], data[:, 1])

                    shape_mask = np.reshape(mask, layer_artist.layer.shape[::-1])
                    shape_mask = np.ravel(np.transpose(shape_mask))

                    indices_dict[layer_artist.layer] = np.where(shape_mask)[0]

                self.mark_selected_dict(indices_dict)

            self.reset()
Beispiel #6
0
    def release(self, event):

        if event.button == 1:

            if self.corner2 is not None:

                r = RectangularROI(*self.bounds)

                indices_dict = {}

                for layer_artist in self.iter_data_layer_artists():

                    data = get_map_data(layer_artist, self.viewer)
                    mask = r.contains(data[:, 0], data[:, 1])

                    shape_mask = np.reshape(mask,
                                            layer_artist.layer.shape[::-1])
                    shape_mask = np.ravel(np.transpose(shape_mask))

                    indices_dict[layer_artist.layer] = np.where(shape_mask)[0]

                self.mark_selected_dict(indices_dict)

            self.reset()