def process_picking(self,near,far): print('process picking') min_dist=[cll.mindistance_segment2track(near,far,xyz) for xyz in self.data] min_dist=np.array(min_dist) #print min_dist self.picked_track=min_dist.argmin() print 'min index',self.picked_track min_dist_info=[cll.mindistance_segment2track_info(near,far,xyz) for xyz in self.data] A = np.array(min_dist_info) dist=10**(-3) iA=np.where(A[:,0]<dist) minA=A[iA] print 'minA ', minA miniA=minA[:,1].argmin() print 'final min index ',iA[0][miniA] self.picked_track=iA[0][miniA]
def process_pickray(self,near,far): if self.centered: shift=np.array(self.position)-self.mean print shift else: shift=np.array([0,0,0]) min_dist_info=[ \ cll.mindistance_segment2track_info(near,far,xyz+shift) \ for xyz in self.curves] #print'Min distance info' #print min_dist_info A = np.array(min_dist_info) #print A dist=10**(-3) np.where(A[:,0]<dist) iA=np.where(A[:,0]<dist) minA=A[iA] if len(minA)==0: #print 'IN' iA=np.where(A[:,0]==A[:,0].min()) minA = A[iA] #print 'A','minA next',minA, iA miniA=minA[:,1].argmin() print 'track_center',self.position, 'selected',iA[0][miniA] self.current=iA[0][miniA]
def picking_virtuals(self,symbol,modifiers): x,y=self.mouse_x,self.mouse_y nx,ny,nz=screen_to_model(x,y,0) fx,fy,fz=screen_to_model(x,y,1) near=(nx,ny,nz) far=(fx,fy,fz) min_dist_info=[ cll.mindistance_segment2track_info(near,far,xyz) \ for xyz in self.virtuals] A = np.array(min_dist_info) dist=10**(-3) np.where(A[:,0]<dist) iA=np.where(A[:,0]<dist) minA=A[iA] if len(minA)==0: iA=np.where(A[:,0]==A[:,0].min()) minA = A[iA] miniA=minA[:,1].argmin() return iA[0][miniA]
def process_pickray(self,near,far): min_dist_info=[ cll.mindistance_segment2track_info(near,far,xyz) \ for xyz in self.curves] A = np.array(min_dist_info) dist=10**(-3) np.where(A[:,0]<dist) iA=np.where(A[:,0]<dist) minA=A[iA] if len(minA)==0: iA=np.where(A[:,0]==A[:,0].min()) minA = A[iA] miniA=minA[:,1].argmin() print 'track_id',iA[0][miniA] self.current=iA[0][miniA] if self.selected.count(self.current)==0: self.selected.append(self.current) if self.selected.count(self.current)>0: self.selected.remove(self.current)
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) # 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 process_picking(self, near, far): shift = np.array(self.position) - self.mean min_dist_info=[ \ cll.mindistance_segment2track_info(near,far,xyz+shift) \ for xyz in self.data] A = np.array(min_dist_info) dist = 10**(-3) np.where(A[:, 0] < dist) iA = np.where(A[:, 0] < dist) minA = A[iA] if len(minA) == 0: #print 'IN' iA = np.where(A[:, 0] == A[:, 0].min()) minA = A[iA] #print 'A','minA next',minA, iA miniA = minA[:, 1].argmin() print 'track_center', self.position, 'selected index ', iA[0][miniA] self.picked_track = iA[0][miniA] self.picked_tracks.append(self.picked_track)
def process_picking(self,near,far): shift=np.array(self.position)-self.mean min_dist_info=[ \ cll.mindistance_segment2track_info(near,far,xyz+shift) \ for xyz in self.data] A = np.array(min_dist_info) dist=10**(-3) np.where(A[:,0]<dist) iA=np.where(A[:,0]<dist) minA=A[iA] if len(minA)==0: #print 'IN' iA=np.where(A[:,0]==A[:,0].min()) minA = A[iA] #print 'A','minA next',minA, iA miniA=minA[:,1].argmin() print 'track_center',self.position, 'selected index ',iA[0][miniA] self.picked_track=iA[0][miniA] self.picked_tracks.append(self.picked_track)