def on_key_press(self, symbol, modifiers): if symbol not in [key.R]: self.window._world.propagate_keys(symbol, modifiers) # how to propagate the events to the actors and camera? if symbol == key.R: self.window.current_camera.reset() #if symbol == key.H: # self.window.set_size(1000, 600) """ if modifiers & key.MOD_CTRL: # make window bigger if symbol == key.PLUS: neww = self.window.width + self.window.width / 10 newh = self.window.height + self.window.height / 10 self.window.set_size(neww, newh) # make window smaller elif symbol == key.MINUS: neww = self.window.width - self.window.width / 10 newh = self.window.height - self.window.height / 10 self.window.set_size(neww, newh) """ if symbol == key.P: x,y=self.window.mouse_x,self.window.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) self.window._world.propagate_pickray(near, far) # with s, select and actor and focus the camera, make the aabb glowing, # d to deselect, push new set of events for this actor """
def on_key_press(self, symbol, modifiers): # how to propagate the events to the actors and camera? if symbol == key.R: self.window.current_camera.reset() if symbol == key.H: self.window.set_size(1000, 600) if modifiers & key.MOD_CTRL: # make window bigger if symbol == key.PLUS: neww = self.window.width + self.window.width / 10 newh = self.window.height + self.window.height / 10 self.window.set_size(neww, newh) # make window smaller elif symbol == key.MINUS: neww = self.window.width - self.window.width / 10 newh = self.window.height - self.window.height / 10 self.window.set_size(neww, newh) if symbol == key.P: # generate pickray x,y=self.window.mouse_x,self.window.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) self.window._world.propagate_pickray(near, far) # with s, select and actor and focus the camera, make the aabb glowing, # d to deselect, push new set of events for this actor if symbol == key.S: # select aabb x,y=self.window.mouse_x,self.window.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) found_actor = self.window._world.find_selected_actor(near, far) if not found_actor is None: print "found an actor that was selected" found_actor.show_aabb = not found_actor.show_aabb # get the center of the aabb ax,ay,az = found_actor.aabb.get_center() print "ax,az", ax, ay, az self.window.current_camera.set_lookatposition(ax,ay,az) else: print "no actor found"
def on_key_press(self, symbol, modifiers): # how to propagate the events to the actors and camera? if symbol == key.R: self.window.current_camera.reset() if symbol == key.H: self.window.set_size(1000, 600) if modifiers & key.MOD_CTRL: # make window bigger if symbol == key.PLUS: neww = self.window.width + self.window.width / 10 newh = self.window.height + self.window.height / 10 self.window.set_size(neww, newh) # make window smaller elif symbol == key.MINUS: neww = self.window.width - self.window.width / 10 newh = self.window.height - self.window.height / 10 self.window.set_size(neww, newh) if symbol == key.P: # generate pickray x, y = self.window.mouse_x, self.window.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) self.window._world.propagate_pickray(near, far) # with s, select and actor and focus the camera, make the aabb glowing, # d to deselect, push new set of events for this actor if symbol == key.S: # select aabb x, y = self.window.mouse_x, self.window.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) found_actor = self.window._world.find_selected_actor(near, far) if not found_actor is None: print "found an actor that was selected" found_actor.show_aabb = not found_actor.show_aabb # get the center of the aabb ax, ay, az = found_actor.aabb.get_center() print "ax,az", ax, ay, az self.window.current_camera.set_lookatposition(ax, ay, az) else: print "no actor found"
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 on_key_press(symbol,modifiers): #print('key pressed') if symbol == key.R: cam_rot.reset() cam_trans.reset() if symbol == key.P: global mouse_x, mouse_y x,y=mouse_x,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) #print near,far #print'x',x,'y',y for a in actors: try: a.process_pickray(near,far) except: pass
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_keys(self,symbol,modifiers): if symbol == key.P: 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) print 'P' #print 'collision with plane' success,t,p= cll.intersect_segment_plane(near,far,self.p0,self.p1,self.p2) print success print p o0_low_left=(-self.spri.width-self.sprj.width/2.,-self.spri.height/2) o0_up_right= (-self.sprj.width/2.,self.spri.height/2) if tell_me_if(p,o0_low_left,o0_up_right): print 'Object 0' pix0=np.round(p[0]-o0_low_left[0]).astype(int) pix1=np.round(p[1]-o0_low_left[1]).astype(int) self.update_vox_coords(self.vxi,pix1,pix0) print 'Changed', self.vxi,pix0,pix1 o1_low_left=(-self.sprj.width/2.,-self.sprj.height/2) o1_up_right= (self.sprj.width/2.,self.sprj.height/2) if tell_me_if(p,o1_low_left,o1_up_right): print 'Object 1' pix0=np.round(p[0]-o1_low_left[0]).astype(int) pix1=np.round(p[1]-o1_low_left[1]).astype(int) self.update_vox_coords(pix1,self.vxj,pix0) o2_low_left=(self.sprj.width/2.,-self.sprk.height/2) o2_up_right= (self.sprj.width/2+self.sprk.width,self.spri.height/2) if tell_me_if(p,o2_low_left,o2_up_right): print 'Object 2' pix0=np.round(p[0]-o2_low_left[0]).astype(int) pix1=np.round(p[1]-o2_low_left[1]).astype(int) self.update_vox_coords(pix1,pix0,self.vxk)
def process_keys(self,symbol,modifiers): if modifiers & key.MOD_SHIFT: print 'Shift' self.step=5 if symbol == key.UP: print 'Up' if self.vxk<self.data.shape[-1]-self.step: self.vxk+=self.step self.z+=self.step self.slk=self.update_slice(2,self.vxk) self.step=1 if symbol == key.DOWN: print 'Down' if self.vxk>=self.step-1: self.vxk-=self.step self.z-=self.step self.slk=self.update_slice(2,self.vxk) self.step=1 if symbol == key.LEFT: print 'Left' if self.vxi>=self.step-1: self.vxi-=self.step self.x-=self.step self.sli=self.update_slice(0,self.vxi) self.step=1 if symbol == key.RIGHT: print 'Right' if self.vxi<self.data.shape[0]-self.step: self.vxi+=self.step self.x+=self.step self.sli=self.update_slice(0,self.vxi) self.step=1 if symbol == key.PAGEUP: print 'PgUp' if self.vxj<self.data.shape[1]-self.step: self.vxj+=self.step self.y+=self.step self.slj=self.update_slice(1,self.vxj) self.step=1 if symbol == key.PAGEDOWN: print 'PgDown' if self.vxj>=self.step-1: self.vxj-=self.step self.y-=self.step self.slj=self.update_slice(1,self.vxj) self.step=1 #HIDE SLICES if symbol == key._0: print('0') if np.sum(self.show_slices)==0: self.show_slices[:]=True else: self.show_slices[:]=False if symbol == key._1: print('1') self.show_slices[0]= not self.show_slices[0] if symbol == key._2: print('2') self.show_slices[1]= not self.show_slices[1] if symbol == key._3: print('3') self.show_slices[2]= not self.show_slices[2] if symbol == key._6: print('6') if self.cube_size<self.cube_size_max: #have to change to cubex,cubey,cubez self.cube_sizex+=1 self.cube_roi_element=np.array([self.cube_sizex,self.cube_sizey,self.cube_sizez])*cube_vertices+self.cube_center self.change_roi(self.cube_roi_element, [1,1,0,1]) self.cube_size=np.max(np.array([self.cube_sizex,self.cube_sizey,self.cube_sizez])) if symbol == key._7: print('7') if self.cube_size<self.cube_size_max: #have to change to cubex,cubey,cubez self.cube_sizey+=1 self.cube_roi_element=np.array([self.cube_sizex,self.cube_sizey,self.cube_sizez])*cube_vertices+self.cube_center self.change_roi(self.cube_roi_element, [1,1,0,1]) self.cube_size=np.max(np.array([self.cube_sizex,self.cube_sizey,self.cube_sizez])) if symbol == key._8: print('8') if self.cube_size<self.cube_size_max: #have to change to cubex,cubey,cubez self.cube_sizez+=1 self.cube_roi_element=np.array([self.cube_sizex,self.cube_sizey,self.cube_sizez])*cube_vertices+self.cube_center self.change_roi(self.cube_roi_element, [1,1,0,1]) self.cube_size=np.max(np.array([self.cube_sizex,self.cube_sizey,self.cube_sizez])) if symbol == key.M: print('M - Maximizing ROI') if self.cube_size<self.cube_size_max: self.cube_sizex+=1 self.cube_sizey+=1 self.cube_sizez+=1 self.cube_roi_element=np.array([self.cube_sizex,self.cube_sizey,self.cube_sizez])*cube_vertices+self.cube_center self.change_roi(self.cube_roi_element, [1,1,0,1]) self.cube_size=np.max(np.array([self.cube_sizex,self.cube_sizey,self.cube_sizez])) print('ROI magnification %d' % self.cube_size) if symbol == key.N: print('N - miNimizing ROI') if self.cube_size>self.cube_size_min: self.cube_sizex-=1 self.cube_sizey-=1 self.cube_sizez-=1 self.cube_roi_element=np.array([self.cube_sizex,self.cube_sizey,self.cube_sizez])*cube_vertices+self.cube_center self.change_roi(self.cube_roi_element, [1,1,0,1]) self.cube_size=np.max(np.array([self.cube_sizex,self.cube_sizey,self.cube_sizez])) print('ROI magnification %d' % self.cube_size) if symbol == key.SPACE: print('Space - Select ROI') 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) bx,by,bz=self.data.shape center=np.array([bx/2.,by/2.,bz/2.]) #find intersection point on the closest slice point=self.slices_ray_intersection(near, far, center) if point !=None: self.cube_center=point self.cube_roi_element=self.cube_size*cube_vertices+point self.volume_point=np.round(point+center).astype(np.int) self.add_roi(self.cube_roi_element,[1,1,0,1.]) else: print('no intersection point') if symbol == key.ENTER: print('Enter - Store ROI in mask') #self.masks_list.append(mask) if self.cube_size>1: v0,v1,v2=self.volume_point rx=self.cube_sizex/2 ry=self.cube_sizey/2 rz=self.cube_sizez/2 self.mask[v0-rx:v0+rx,v1-ry:v1+ry,v2-rz:v2+rz]=1 if self.cube_size==1: self.mask[tuple(self.volume_point)]=1 #self.cube_roi_colors=np.ascontiguousarray(np.tile(self.cube_roi_color_stored,(len(cube_vertices),1))) self.change_roi(vertices=None, color=[0,1,1,1]) if symbol == key.D: print('D - All ROIs deleted and mask reseted') self.mask[:,:,:]=0 self.cube_roi_vertices=None self.cube_roi_colors=None self.cube_first=None self.cube_count=None self.cube_no=0 if symbol == key.QUESTION: print """