def _update_selection(self): """ Sets the selection datasource's 'selection' metadata element to a mask of all the points selected """ if self.selection_datasource is None: return selected_mask = zeros(self.selection_datasource._data.shape, dtype=numpy.int32) data = self._get_data() # Compose the selection mask from the cached selections first, then # the active selection, taking into account the selection mode only # for the active selection for selection in self._previous_selections: selected_mask |= (points_in_polygon(data, selection, False)) if self.selection_mode == 'exclude': selected_mask |= (points_in_polygon(data, self._active_selection, False)) selected_mask = 1 - selected_mask elif self.selection_mode == 'invert': selected_mask = -1 * (selected_mask -points_in_polygon(data, self._active_selection, False)) else: selected_mask |= (points_in_polygon(data, self._active_selection, False)) if sometrue(selected_mask != self.selection_datasource.metadata['selection']): self.selection_datasource.metadata['selection'] = selected_mask self.selection_changed = True return
def _selection_changed(self): data = np.logical_not(points_in_polygon(self.img_index, self.lasso.dataspace_points, False).astype(np.bool)) data = data.reshape((256, 256)) copy = self.img_data.copy() copy[data] = 0 self.plotdata["mask_data"] = copy self.plot2.request_redraw()
def is_in(self, point_x, point_y): """ Test if a point is within this polygonal region """ point_array = array(((point_x, point_y), )) vertices = array(self.points) winding = self.inside_rule == "winding" result = points_in_polygon(point_array, vertices, winding) return result[0]
def is_in(self, point_x, point_y): """ Test if a point is within this polygonal region """ point_array = array(((point_x, point_y),)) vertices = array(self.points) winding = self.inside_rule == "winding" result = points_in_polygon(point_array, vertices, winding) return result[0]
def _eval ( self, model ): """ Evaluates the result of the filter for the specified model. """ if len( self.points ) == 0: return None points = array( zip( getattr( model, self.x_value ), getattr( model, self.y_value ) ) ) result = None for items in self.points: pip = points_in_polygon( points, array( items ) ) if result is None: result = pip else: result = result | pip return result
def hittest(self, screen_pt, threshold=7.0, return_distance=False): """ Performs point-in-polygon testing or point/line proximity testing. If self.hittest_type is "line" or "point", then behaves like the parent class BaseXYPlot.hittest(). If self.hittest_type is "poly", then returns True if the given point is inside the polygon, and False otherwise. """ if self.hittest_type in ("line", "point"): return BaseXYPlot.hittest(self, screen_pt, threshold, return_distance) data_pt = self.map_data(screen_pt, all_values=True) index = self.index.get_data() value = self.value.get_data() poly = np.vstack((index,value)).T if points_in_polygon([data_pt], poly)[0] == 1: return True else: return False
def hittest(self, screen_pt, threshold=7.0, return_distance=False): """ Performs point-in-polygon testing or point/line proximity testing. If self.hittest_type is "line" or "point", then behaves like the parent class BaseXYPlot.hittest(). If self.hittest_type is "poly", then returns True if the given point is inside the polygon, and False otherwise. """ if self.hittest_type in ("line", "point"): return BaseXYPlot.hittest(self, screen_pt, threshold, return_distance) data_pt = self.map_data(screen_pt, all_values=True) index = self.index.get_data() value = self.value.get_data() poly = np.vstack((index,value)).T if points_in_polygon([data_pt], poly)[0] == 1: return True else: return False
def find_star(self, x, y): from enthought.kiva.agg import points_in_polygon for star in self.stars[::-1]: if points_in_polygon((x, y), star.polygon()): return star return None