def get_dk2(): for monitor in fw.get_monitors(): if monitor.physical_size == (71, 126): return monitor return None # If we're still here (no rift?), lets just return the primary display return fw.get_primary_monitor()
def print_all_monitors(): ''' note you can run xrandr in the command line to get the info as well rift will look like: DP-0 connected primary 1920x1080+0+0 left (normal left inverted right x axis y axis) 71mm x 126mm 1080x1920 75.0*+ 72.0 60.0 1080x948 120.0 ''' print for monitor in fw.get_monitors(): print monitor.name print monitor.physical_size print monitor.pos for mode in monitor.video_modes: print ' mode:' print ' %s' % mode.width print ' %s' % mode.height print ' %s' % mode.refresh_rate print
def get_rift(): ''' http://unix.stackexchange.com/questions/67983/get-monitor-make-and-model-and-other-info-in-human-readable-form http://superuser.com/questions/800572/interpret-edid-information-to-get-manufacturer-and-type-number-of-my-laptop-scre http://ubuntuforums.org/showthread.php?t=1946208 https://github.com/glfw/glfw/issues/212 If we could easily read the EDID that'd be much easier Vendor is OVR read-edid barfs w/ Nvida (maybe can use NV-CONTROL) xrandr --verbose works... ''' # For now, lets do the easiest thing and get it by physical size of DK2 for monitor in fw.get_monitors(): if monitor.physical_size == (71, 126): return monitor ### TODO: DK1 physical size # If we're still here (no rift?), lets just return the primary display return fw.get_primary_monitor()
def __init__(self, wavelength_nm, pixel_size_um, focal_mm, beam_radius_mm=None, screenID=None, active_area_coords=None, lut_edges=[0, 255]): print("""Thanks for using SLM-3dPointCloud. Library openly available for non-commercial use at https://github.com/ppozzi/SLM-3dPointCloud. If used for academic purposes, please consider citing the appropriate literature (https://doi.org/10.3389/fncel.2021.609505, https://doi.org/10.3390/mps2010002))""" ) self.screenID = screenID if self.screenID is not None: self.screenresolution = ( screeninfo.get_monitors()[self.screenID].height, screeninfo.get_monitors()[self.screenID].width) if active_area_coords is None: self.res = numpy.amin( numpy.asarray([ screeninfo.get_monitors()[self.screenID].height, screeninfo.get_monitors()[self.screenID].width ])) self.position = (screeninfo.get_monitors()[self.screenID].x, 0) self.aperture_position = (int( (self.screenresolution[0] - self.res) / 2), int((self.screenresolution[1] - self.res) / 2)) else: self.res = (active_area_coords[2]) self.position = (screeninfo.get_monitors()[self.screenID].x, 0) self.aperture_position = (active_area_coords[0], active_area_coords[1]) else: if active_area_coords is None: self.res = 512 self.position = (0, 0) else: self.res = active_area_coords[2] self.position = (active_area_coords[0], active_area_coords[1]) self.aperture_position = (0, 0) self.screenresolution = (self.res, self.res) glfw.init() glfw.Window.hint() if screenID != None: self.win = glfw.Window(self.screenresolution[1], self.screenresolution[0], "SLM", glfw.get_monitors()[self.screenID]) else: self.win = glfw.Window( self.screenresolution[1], self.screenresolution[0], "SLM", ) self.win.pos = self.position self.win.make_current() self.win.swap_interval(0) self.lut_edges = lut_edges glViewport(0, 0, self.screenresolution[1], self.screenresolution[0]) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(0, 1.0, 0, 1.0, -1.0, 1.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glEnable(GL_DEPTH_TEST) glClearColor(1.0, 1.0, 1.0, 1.5) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glEnable(GL_TEXTURE_2D) self.tex = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, self.tex) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, self.screenresolution[1], self.screenresolution[0], 0, GL_RGBA, GL_UNSIGNED_BYTE, None) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) import pycuda.gl.autoinit self.mod = SourceModule(cuda_code, options=DEFAULT_NVCC_FLAGS) self.project_to_slm = self.mod.get_function("project_to_slm") self.project_to_spots_setup = self.mod.get_function( "project_to_spots_setup") self.project_to_spots_end = self.mod.get_function( "project_to_spots_end") self.project_to_slm_comp = self.mod.get_function("project_to_slm_comp") self.project_to_spots_setup_comp = self.mod.get_function( "project_to_spots_setup_comp") self.project_to_spots_end_comp = self.mod.get_function( "project_to_spots_end_comp") self.update_weights = self.mod.get_function("update_weights") self.fill_screen_output = self.mod.get_function("fill_screen_output") self.pbo = glGenBuffers(1) glBindBuffer(GL_PIXEL_UNPACK_BUFFER, self.pbo) glBufferData(GL_PIXEL_UNPACK_BUFFER, self.screenresolution[1] * self.screenresolution[0] * 4, None, GL_DYNAMIC_COPY) self.cuda_pbo = pycuda.gl.RegisteredBuffer( int(self.pbo), cuda_gl.graphics_map_flags.WRITE_DISCARD) self.lam = wavelength_nm * 0.001 self.pix_size = pixel_size_um self.f = focal_mm * 1000.0 self.blocksize_forward = 512 XC, YC = numpy.meshgrid( numpy.linspace(-self.pix_size * self.res / 2, self.pix_size * self.res / 2, self.res), numpy.linspace(-self.pix_size * self.res / 2, self.pix_size * self.res / 2, self.res)) RC2 = XC**2 + YC**2 pupil_coords = numpy.where( numpy.sqrt(RC2) <= self.pix_size * self.res / 2) indexes = numpy.asarray(range(pupil_coords[0].shape[0])) numpy.random.shuffle(indexes) self.pupil_coords = (pupil_coords[0][indexes], pupil_coords[1][indexes]) self.PUP_NP = self.pupil_coords[0].shape[0] # XC_unit, YC_unit = numpy.meshgrid(numpy.linspace(-1.0, 1.0, self.res), # numpy.linspace(-1.0, 1.0, self.res)) # pupil_int = gauss((XC_unit, YC_unit), 1.0, 0.0, 0.00851336, -0.02336506, 0.48547321, 0.50274484)**2 if beam_radius_mm == None: pupil_int = numpy.ones((self.res, self.res)) else: pupil_int = numpy.exp(-(XC**2 + YC**2) / (1000.0 * beam_radius_mm)**2) pupil_int = pupil_int[self.pupil_coords] pupil_int = (pupil_int / numpy.sum(pupil_int)).astype("float32") self.PUP_INT_gpu = gpuarray.to_gpu(pupil_int) self.holo_real_gpu = gpuarray.to_gpu( numpy.zeros(self.PUP_NP, dtype="float32")) self.holo_imag_gpu = gpuarray.to_gpu( numpy.zeros(self.PUP_NP, dtype="float32")) self.XC_gpu = gpuarray.to_gpu(XC[self.pupil_coords].astype("float32")) self.YC_gpu = gpuarray.to_gpu(YC[self.pupil_coords].astype("float32")) self.float_pars_gpu = gpuarray.to_gpu( numpy.asarray([ 2.0 * numpy.pi / (self.lam * self.f), numpy.pi / (self.lam * self.f**2) * 10**3 ]).astype("float32")) self.screen_pup_coords_y_gpu = gpuarray.to_gpu( (self.pupil_coords[0] + self.aperture_position[0]).astype("int32")) self.screen_pup_coords_x_gpu = gpuarray.to_gpu( (self.pupil_coords[1] + self.aperture_position[1]).astype("int32")) self.screenpars_gpu = gpuarray.to_gpu( numpy.asarray([ self.PUP_NP, self.screenresolution[1], self.lut_edges[0], self.lut_edges[1] ]).astype("int32"))