def picking_virtuals(self, symbol, modifiers, min_dist=1e-3): """Compute the id of the closest track to the mouse pointer. """ x, y = self.mouse_x, self.mouse_y # Define two points in model space from mouse+screen(=0) position and mouse+horizon(=1) position near = screen_to_model(x, y, 0) far = screen_to_model(x, y, 1) #print 'peak virtuals ', near, far, x, y # Compute distance of virtuals from screen and from the line defined by the two points above tmp = np.array([cll.mindistance_segment2track_info(near, far, xyz) \ for xyz in self.virtuals]) line_distance, screen_distance = tmp[:, 0], tmp[:, 1] if False: # basic algoritm: # Among the virtuals within a range to the line (i.e. < min_dist) return the closest to the screen: closest_to_line_idx = np.argsort(line_distance) closest_to_line_thresholded_bool = line_distance[ closest_to_line_idx] < min_dist if (closest_to_line_thresholded_bool).any(): return closest_to_line_idx[np.argmin( screen_distance[closest_to_line_thresholded_bool])] else: return closest_to_line_idx[0] else: # simpler and apparently more effective algorithm: return np.argmin(line_distance + screen_distance)
def get_pointed_representative(self, min_dist=1e-3): """Compute the id of the closest streamline to the mouse pointer. """ x, y = self.mouse_x, self.mouse_y # Define two points in model space from mouse+screen(=0) position and mouse+horizon(=1) position near = screen_to_model(x, y, 0) far = screen_to_model(x, y, 1) # Compute distance of representatives from screen and from the line defined by the two points above tmp = np.array([cll.mindistance_segment2track_info(near, far, apply_transformation(xyz, self.glaff)) \ for xyz in self.representatives]) line_distance, screen_distance = tmp[:,0], tmp[:,1] return self.representative_ids_ordered[np.argmin(line_distance + screen_distance)]
def picking_virtuals(self, symbol, modifiers, min_dist=1e-3): """Compute the id of the closest track to the mouse pointer. """ x, y = self.mouse_x, self.mouse_y # Define two points in model space from mouse+screen(=0) position and mouse+horizon(=1) position near = screen_to_model(x, y, 0) far = screen_to_model(x, y, 1) # print 'peak virtuals ', near, far, x, y # Compute distance of virtuals from screen and from the line defined by the two points above tmp = np.array([cll.mindistance_segment2track_info(near, far, xyz) for xyz in self.virtuals]) line_distance, screen_distance = tmp[:, 0], tmp[:, 1] if False: # basic algoritm: # Among the virtuals within a range to the line (i.e. < min_dist) return the closest to the screen: closest_to_line_idx = np.argsort(line_distance) closest_to_line_thresholded_bool = line_distance[closest_to_line_idx] < min_dist if (closest_to_line_thresholded_bool).any(): return closest_to_line_idx[np.argmin(screen_distance[closest_to_line_thresholded_bool])] else: return closest_to_line_idx[0] else: # simpler and apparently more effective algorithm: return np.argmin(line_distance + screen_distance)