def _compute_bands(self, points, smartmode=False): """ Sorts self.data into a list of arrays of data points by color, filling in self._index_bands. If *smartmode* is True, then it first calls _calc_render_method() to see which rendering method is optimal for the number of points and the distribution of color indices; if the rendering method is 'bruteforce', then this method short-circuits and returns without doing anything. """ if len(points) == 0: return if self.color_mapper is None: return # map the V values in the (x,y,v) self.data array color_data = points[:, 2] color_indices = self.color_mapper.map_index(color_data) if smartmode and self.render_method == 'bruteforce': pass else: # shuffle_indices indicates how to sort the points in self.data # so that their color_indices are in order. We don't really care # about the sorting so much as the fact that once they are sorted, # points of the same color are grouped together into "bands". shuffle_indices = argsort(color_indices) # This pulls values from the color_indices array into # sorted_color_indices, using the results of the sort we just did. sorted_color_indices = take(color_indices, shuffle_indices) # Now we want to determine where the continuous bands are. We do # this by right-shifting the sorted_color_indices array, subtracting # it from the original, and looking for all the nonzero points. shifted = right_shift(sorted_color_indices, sorted_color_indices[0]) start_indices = concatenate([[0], nonzero(sorted_color_indices - shifted)[0]]) end_indices = left_shift(start_indices, len(sorted_color_indices)) # Store the shuffled indices in self._index_bands. We don't store the # actual data points because we need to allow the renderer to index into # the mapped XY screen positions. self._index_bands = {} for (start, end) in zip(start_indices, end_indices): color_index = sorted_color_indices[start] self._index_bands[color_index] = shuffle_indices[start:end] self._color_indices = color_indices self._cache_valid = True return
def _compute_bands(self, points, smartmode=False): """ Sorts self.data into a list of arrays of data points by color, filling in self._index_bands. If *smartmode* is True, then it first calls _calc_render_method() to see which rendering method is optimal for the number of points and the distribution of color indices; if the rendering method is 'bruteforce', then this method short-circuits and returns without doing anything. """ if len(points) == 0: return if self.color_mapper is None: return # map the V values in the (x,y,v) self.data array color_data = points[:,2] color_indices = self.color_mapper.map_index(color_data) if smartmode and self.render_method == 'bruteforce': pass else: # shuffle_indices indicates how to sort the points in self.data # so that their color_indices are in order. We don't really care # about the sorting so much as the fact that once they are sorted, # points of the same color are grouped together into "bands". shuffle_indices = argsort(color_indices) # This pulls values from the color_indices array into # sorted_color_indices, using the results of the sort we just did. sorted_color_indices = take(color_indices, shuffle_indices) # Now we want to determine where the continuous bands are. We do # this by right-shifting the sorted_color_indices array, subtracting # it from the original, and looking for all the nonzero points. shifted = right_shift(sorted_color_indices, sorted_color_indices[0]) start_indices = concatenate([[0], nonzero(sorted_color_indices - shifted)[0]]) end_indices = left_shift(start_indices, len(sorted_color_indices)) # Store the shuffled indices in self._index_bands. We don't store the # actual data points because we need to allow the renderer to index into # the mapped XY screen positions. self._index_bands = {} for (start, end) in zip(start_indices, end_indices): color_index = sorted_color_indices[start] self._index_bands[color_index] = shuffle_indices[start:end] self._color_indices = color_indices self._cache_valid = True return