Esempio n. 1
0
	def setup_atb(self):
		atb.init()
		self.bar = atb.Bar(name="Controls", label="Controls",
				help="Scene controls", color=(50,50,50), alpha=50,
				text='light', position=(10, 10), size=(200, 440))

		self.bar.add_var("World/Zoom", step=0.01, min=0.01, max=1.0,
					getter=self.trackball._get_zoom, setter=self.trackball._set_zoom)

		self.bar.add_var("World/Distance", step=1, min=1, max=300, 
				getter=self.trackball._get_distance, setter=self.trackball._set_distance)
		self.bar.add_var("World/Show_World", self.tb_show, help="Show/Hide Trackball Camera")
		
		self.bar.add_separator("")
		self.bar.add_var("Eye/Show_Eye", self.eye_show, help="Show/Hide Eye Camera")
		self.bar.add_var("Eye/Camera", step=1, min=0, max=self.camera_manager.get_num_cams()-1, 
				getter=self.eye._get_current, 
				setter=self._set_current_camera,
				key="SPACE")

		self.bar.add_separator("")
		self.bar.add_var("Image/Scale", step=0.00001, min=0.00001, getter=self.camera_manager.get_img_scale, 
					setter=self.camera_manager.set_img_scale )
		self.bar.add_button("Show_Images", self.camera_manager.pyramid_show, key="1", help="Show All Images")
		self.bar.add_button("Hide_Images", self.camera_manager.pyramid_hide, key="2", help="Hide All Images")
		self.bar.add_button("Show_Cones", self.camera_manager.cone_show, key="3", help="Show All Fixation Cones")
		self.bar.add_button("Hide_Cones", self.camera_manager.cone_hide, key="4", help="Hide All Images")

		self.bar.add_separator("")
		self.bar.add_var("Points/Show_Points", self.points_show, key="RETURN", help="Show/Hide Points")
		self.bar.add_var("Points/Size", step=0.5, min=1.0, max=20.0, getter=self.point_manager._get_scale, 
					setter=self.point_manager._set_scale )
		self.bar.add_button("Square Point", self.point_manager._make_square, key="9", help="Render square points")
		self.bar.add_button("Circular Point", self.point_manager._make_smooth, key="0", help="Render smooth points")

		self.bar.add_separator("")
		self.bar.add_var("Background/Color", self.color, open=False)
		self.bar.add_separator("")
		self.bar.add_var("Background/Fullscreen", self.full, help="Fullscreen mode for presentation")
		self.bar.add_button("Quit", self.quit, key="ESCAPE", help="Quit application")
Esempio n. 2
0
            stimI = i
            stim = stimSpikeSyncer.stimList[i]
            get_spikes()

    def set_stim_size(s):
        global stim, stimI, stimSpikeSyncer
        newStim = copy.deepcopy(stim)
        newStim.size_x = s
        newStim.size_y = s
        i = stimSpikeSyncer.find_stim(newStim)
        if i != -1:
            stimI = i
            stim = stimSpikeSyncer.stimList[i]
            get_spikes()

    atb.init()
    # global bar
    bar = atb.Bar(name="Controls",
                  label="Controls",
                  help="Scene controls",
                  position=(10, 10),
                  size=(200, 320))
    # channel = ct.c_int(1)
    # stim_id = ct.c_int(1)
    # stim_x = ct.c_float(1)
    # stim_y = ct.c_float(1)
    # stim_size = ct.c_int(1)
    bar.add_var("Channel",
                getter=get_channel,
                setter=set_channel,
                vtype=ct.c_int)
Esempio n. 3
0
    def setup_atb(self):
        atb.init()
        self.bar = atb.Bar(name="Controls",
                           label="Controls",
                           help="Scene controls",
                           color=(50, 50, 50),
                           alpha=50,
                           text='light',
                           position=(10, 10),
                           size=(200, 440))

        self.bar.add_var("World/Zoom",
                         step=0.01,
                         min=0.01,
                         max=1.0,
                         getter=self.trackball._get_zoom,
                         setter=self.trackball._set_zoom)

        self.bar.add_var("World/Distance",
                         step=1,
                         min=1,
                         max=300,
                         getter=self.trackball._get_distance,
                         setter=self.trackball._set_distance)
        self.bar.add_var("World/Show_World",
                         self.tb_show,
                         help="Show/Hide Trackball Camera")

        self.bar.add_separator("")
        self.bar.add_var("Eye/Show_Eye",
                         self.eye_show,
                         help="Show/Hide Eye Camera")
        self.bar.add_var("Eye/Camera",
                         step=1,
                         min=0,
                         max=self.camera_manager.get_num_cams() - 1,
                         getter=self.eye._get_current,
                         setter=self._set_current_camera,
                         key="SPACE")

        self.bar.add_separator("")
        self.bar.add_var("Image/Scale",
                         step=0.00001,
                         min=0.00001,
                         getter=self.camera_manager.get_img_scale,
                         setter=self.camera_manager.set_img_scale)
        self.bar.add_button("Show_Images",
                            self.camera_manager.pyramid_show,
                            key="1",
                            help="Show All Images")
        self.bar.add_button("Hide_Images",
                            self.camera_manager.pyramid_hide,
                            key="2",
                            help="Hide All Images")
        self.bar.add_button("Show_Cones",
                            self.camera_manager.cone_show,
                            key="3",
                            help="Show All Fixation Cones")
        self.bar.add_button("Hide_Cones",
                            self.camera_manager.cone_hide,
                            key="4",
                            help="Hide All Images")

        self.bar.add_separator("")
        self.bar.add_var("Points/Show_Points",
                         self.points_show,
                         key="RETURN",
                         help="Show/Hide Points")
        self.bar.add_var("Points/Size",
                         step=0.5,
                         min=1.0,
                         max=20.0,
                         getter=self.point_manager._get_scale,
                         setter=self.point_manager._set_scale)
        self.bar.add_button("Square Point",
                            self.point_manager._make_square,
                            key="9",
                            help="Render square points")
        self.bar.add_button("Circular Point",
                            self.point_manager._make_smooth,
                            key="0",
                            help="Render smooth points")

        self.bar.add_separator("")
        self.bar.add_var("Background/Color", self.color, open=False)
        self.bar.add_separator("")
        self.bar.add_var("Background/Fullscreen",
                         self.full,
                         help="Fullscreen mode for presentation")
        self.bar.add_button("Quit",
                            self.quit,
                            key="ESCAPE",
                            help="Quit application")
Esempio n. 4
0
    def __init__(self, c):

        self.controller = c
        self.tracker_view = TrackerView()

        self.gui_frame_rate = 0.0

        self.n_frames = 0
        self.frame_count = 0
        self.frame_rate_accum = 0.0
        self.frame_rates = []
        self.start_time = None
        self.last_time = 0
        self.last_update_time = time.time()
        self.update_interval = 1 / 10000.

        atb.init()

        # Try grabbing current Width x Height for window to draw:
        # W = self.controller.get_camera_attribute('Width')
        # H = self.controller.get_camera_attribute('Height')
        # print "DEFINING WINDOW!!!! " + str(W) + ", " + str(H)
        self.window = glumpy.Window(656, 492)  # (900, 700)

        # ---------------------------------------------------------------------
        #   STAGE CONTROLS
        # ---------------------------------------------------------------------

        self.stages_bar = atb.Bar(
            name='stages',
            label='Stage Controls',
            iconified='true',
            help='Controls for adjusting stages',
            position=(10, 10),
            size=(200, 300),
        )

        self.stages_bar.add_var('X/x_set',
                                label='set value',
                                target=c,
                                attr='x_set')
        self.stages_bar.add_button('go_rel_x',
                                   lambda: c.go_rel_x(),
                                   group='X',
                                   label='move relative')
        self.stages_bar.add_button('go_abs_x',
                                   lambda: c.go_x(),
                                   group='X',
                                   label='move absolute')

        self.stages_bar.add_var('Y/y_set',
                                label='set value',
                                target=c,
                                attr='y_set')
        self.stages_bar.add_button('go_rel_y',
                                   lambda: c.go_rel_y(),
                                   group='Y',
                                   label='move relative')
        self.stages_bar.add_button('go_abs_y',
                                   lambda: c.go_y(),
                                   group='Y',
                                   label='move absolute')

        self.stages_bar.add_var('R/r_set',
                                label='set value',
                                target=c,
                                attr='r_set')
        self.stages_bar.add_button('go_rel_r',
                                   lambda: c.go_rel_r(),
                                   group='R',
                                   label='move relative')
        self.stages_bar.add_button('go_abs_r',
                                   lambda: c.go_r(),
                                   group='R',
                                   label='move absolute')

        self.stages_bar.add_button('up',
                                   lambda: c.up(),
                                   group='Jog',
                                   label='up')
        self.stages_bar.add_button('down',
                                   lambda: c.down(),
                                   group='Jog',
                                   label='down')
        self.stages_bar.add_button('left',
                                   lambda: c.left(),
                                   group='Jog',
                                   label='left')

        self.stages_bar.add_button('right',
                                   lambda: c.right(),
                                   group='Jog',
                                   label='right')

        # ---------------------------------------------------------------------
        #   FOCUS AND ZOOM CONTROLS
        # ---------------------------------------------------------------------

        self.focus_zoom_bar = atb.Bar(
            name='focus_and_zoom',
            label='Focus/Zoom Controls',
            iconified='true',
            help='Controls for adjusting power focus and zoom',
            position=(10, 10),
            size=(200, 300),
        )

        self.focus_zoom_bar.add_var('Focus/focus_step',
                                    label='focus step',
                                    target=c,
                                    attr='focus_step')
        self.focus_zoom_bar.add_button('focus_plus',
                                       lambda: c.focus_plus(),
                                       group='Focus',
                                       label='focus plus')
        self.focus_zoom_bar.add_button('focus_minus',
                                       lambda: c.focus_minus(),
                                       group='Focus',
                                       label='focus minus')

        self.focus_zoom_bar.add_var('Zoom/zoom_step',
                                    label='zoom step',
                                    target=c,
                                    attr='zoom_step')
        self.focus_zoom_bar.add_button('zoom_plus',
                                       lambda: c.zoom_plus(),
                                       group='Zoom',
                                       label='zoom plus')
        self.focus_zoom_bar.add_button('zoom_minus',
                                       lambda: c.zoom_minus(),
                                       group='Zoom',
                                       label='zoom minus')

        # ---------------------------------------------------------------------
        #   LED CONTROLS
        # ---------------------------------------------------------------------

        self.led_bar = atb.Bar(
            name='leds',
            label='LED Controls',
            iconified='true',
            help='Controls for adjusting illumination',
            position=(20, 20),
            size=(200, 180),
        )

        self.led_bar.add_var(
            'Side/Ch1_mA',
            #target=c,
            #attr='IsetCh1',
            label='I Ch1 (mA)',
            vtype=atb.TW_TYPE_UINT32,
            setter=lambda x: c.led_set_current(1, x),
            getter=lambda: c.led_soft_current(1),
            min=0,
            max=1000,
        )

        self.led_bar.add_var('Side/Ch1_status',
                             label='Ch1 status',
                             vtype=atb.TW_TYPE_BOOL8,
                             getter=lambda: c.led_soft_status(1),
                             setter=lambda x: c.led_set_status(1, x))

        self.led_bar.add_var(
            'Top/Ch2_mA',
            #target=c,
            #attr='IsetCh2',
            label='I Ch2 (mA)',
            vtype=atb.TW_TYPE_UINT32,
            setter=lambda x: c.led_set_current(2, x),
            getter=lambda: c.led_soft_current(2),
            min=0,
            max=1000,
        )
        self.led_bar.add_var('Top/Ch2_status',
                             vtype=atb.TW_TYPE_BOOL8,
                             getter=lambda: c.led_soft_status(2),
                             setter=lambda x: c.led_set_status(2, x))

        # --------------------------------------------------------------------
        #   GUI
        # --------------------------------------------------------------------

        self.gui_bar = atb.Bar(
            name='GUI',
            label='GUI',
            iconified='true',
            help='GUI Status',
            position=(60, 60),
            size=(200, 180),
        )

        self.gui_bar.add_var('gui_framerate',
                             label='gui frame rate',
                             vtype=atb.TW_TYPE_FLOAT,
                             min=1,
                             max=200,
                             step=0.1,
                             readonly=True,
                             getter=lambda: float(self.gui_frame_rate))

        # --------------------------------------------------------------------
        #   CAMERA
        # --------------------------------------------------------------------

        self.cam_bar = atb.Bar(
            name='Camera',
            label='Camera',
            iconified='true',
            help='Camera acquisition parameters',
            position=(60, 60),
            size=(200, 180),
        )

        self.cam_bar.add_var(
            'Recording/status',
            label='REC',
            vtype=atb.TW_TYPE_UINT32,
            getter=lambda: c.get_recording_status('recording'),
            setter=lambda x: c.set_recording_status('recording', int(x)),
            #attr='recording',
        )

        self.cam_bar.add_var(
            'Recording/name',
            label='name',
            vtype=atb.TW_TYPE_CDSTRING,
            getter=lambda: c.get_recording_name('subname'),
            setter=lambda x: c.set_recording_name(str(x)),
            #attr='recording',
        )

        PixelFormat = atb.enum('PixelFormat', {
            'Mono8': 0,
            'Mono12Packed': 1,
            'Mono16': 2
        })

        self.cam_bar.add_var(
            'PixelFormat',
            label='pixel format',
            vtype=PixelFormat,
            getter=lambda: c.get_pixel_format('PixelFormat'),
            setter=lambda x: c.set_pixel_format('PixelFormat', int(x)),
        )

        self.cam_bar.add_var(
            'BytesPerFrame',
            label='total bytes per frame',
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=645504,
            step=1,
            getter=lambda: c.get_camera_attribute('TotalBytesPerFrame'),
            # setter=lambda x: c.set_camera_attribute('BinningX', int(x)),
        )

        self.cam_bar.add_var(
            'framerate',
            label='frame rate',
            vtype=atb.TW_TYPE_FLOAT,
            min=1,
            max=125,
            step=0.1,
            readonly=True,
            getter=lambda: float(c.get_frame_rate()),
        )

        self.cam_bar.add_var(
            'Binning/binningX',
            label='binning X',
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=4,
            step=1,
            getter=lambda: c.get_camera_attribute('BinningX'),
            setter=lambda x: c.set_camera_attribute('BinningX', int(x)),
        )

        self.cam_bar.add_var(
            'Binning/binningY',
            label='binning Y',
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=4,
            step=1,
            getter=lambda: c.get_camera_attribute('BinningY'),
            setter=lambda x: c.set_camera_attribute('BinningY', int(x)),
        )

        ExposureMode = atb.enum('ExposureMode', {
            'Manual': 0,
            'AutoOnce': 1,
            'Auto': 2
        })

        self.cam_bar.add_var(
            'Exposure/mode',
            label='mode',
            vtype=ExposureMode,
            getter=lambda: c.get_exposure_mode('ExposureMode'),
            setter=lambda x: c.set_exposure_mode('ExposureMode', int(x)),
        )

        self.cam_bar.add_var(
            'Exposure/value',
            label='time (us)',
            vtype=atb.TW_TYPE_UINT32,
            min=0,
            max=150000,
            step=1,
            getter=lambda: c.get_camera_attribute('ExposureValue'),
            setter=lambda x: c.set_camera_attribute('ExposureValue', int(x)),
        )

        self.cam_bar.add_var(
            'gain',
            label='Gain',
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=50,
            step=1,
            #target=c,
            getter=lambda: c.get_camera_attribute('GainValue'),
            setter=lambda x: c.set_camera_attribute('GainValue', int(x)),
            attr='gain',
        )

        # self.cam_bar.add_var(
        #     'exposure',
        #     label='exposure',
        #     vtype=atb.TW_TYPE_UINT32,
        #     min=5000,
        #     max=30000,
        #     step=1000,
        #     target=c,
        #     attr='exposure',
        #     )

        self.cam_bar.add_var(
            'ROI/roi_width',
            label='width',
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=656,  #656,
            step=1,
            #target=c,
            getter=lambda: c.get_camera_attribute('Width'),
            setter=lambda x: c.set_camera_attribute('Width', int(x)),
            attr='roi_width',
        )

        self.cam_bar.add_var(
            'ROI/roi_height',
            label='height',
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=492,  #492,
            step=1,
            #target=c,
            getter=lambda: c.get_camera_attribute('Height'),
            setter=lambda x: c.set_camera_attribute('Height', int(x)),
            attr='roi_height',
        )

        # self.cam_bar.add_var(
        #     'ROI/roi_offset_x',
        #     label='offset x',
        #     vtype=atb.TW_TYPE_UINT32,
        #     min=0,
        #     max=800,
        #     step=1,
        #     target=c,
        #     attr='roi_offset_x',
        #     )

        # self.cam_bar.add_var(
        #     'ROI/roi_offset_y',
        #     label='offset y',
        #     vtype=atb.TW_TYPE_UINT32,
        #     min=0,
        #     max=800,
        #     step=1,
        #     target=c,
        #     attr='roi_offset_y',
        #     )

        # Event Handlers
        def on_init():
            self.tracker_view.prepare_opengl()

        def on_draw():
            self.tracker_view.draw((self.window.width, self.window.height))

        def on_idle(dt):
            self.update_tracker_view()
            # time.sleep(0.05)

        def on_key_press(symbol, modifiers):
            if symbol == glumpy.key.ESCAPE:
                c.stop_continuous_acquisition()
                print "Controller has %i refs" % sys.getrefcount(c)
                c.release()
                self.controller = None
                print "Controller has %i refs" % sys.getrefcount(c)
                c.shutdown()
                #print "Shutting down controller..."
                #print "Shut down controller", c.shutdown()
                #c.continuously_acquiring = False
                #c.acq_thread.join()
                sys.exit()

        self.window.push_handlers(atb.glumpy.Handlers(self.window))
        self.window.push_handlers(on_init, on_draw, on_key_press, on_idle)
        self.window.draw()
Esempio n. 5
0
    def __init__(self, c):

        self.controller = c
        self.tracker_view = TrackerView()

        self.gui_frame_rate = 0.0

        self.n_frames = 0
        self.frame_count = 0
        self.frame_rate_accum = 0.0
        self.frame_rates = []
        self.start_time = None
        self.last_time = 0
        self.last_update_time = time.time()
        self.update_interval = 1 / 10000.

        atb.init()
        self.window = glumpy.Window(900, 600)

        # ---------------------------------------------------------------------
        #   STAGE CONTROLS
        # ---------------------------------------------------------------------

        self.stages_bar = atb.Bar(
            name='stages',
            label='Stage Controls',
            iconified='true',
            help='Controls for adjusting stages',
            position=(10, 10),
            size=(200, 300),
            )

        self.stages_bar.add_var('X/x_set', label='set value', target=c,
                                attr='x_set')
        self.stages_bar.add_button('go_rel_x', lambda: c.go_rel_x(), group='X',
                                   label='move relative')
        self.stages_bar.add_button('go_abs_x', lambda: c.go_x(), group='X',
                                   label='move absolute')

        self.stages_bar.add_var('Y/y_set', label='set value', target=c,
                                attr='y_set')
        self.stages_bar.add_button('go_rel_y', lambda: c.go_rel_y(), group='Y',
                                   label='move relative')
        self.stages_bar.add_button('go_abs_y', lambda: c.go_y(), group='Y',
                                   label='move absolute')

        self.stages_bar.add_var('R/r_set', label='set value', target=c,
                                attr='r_set')
        self.stages_bar.add_button('go_rel_r', lambda: c.go_rel_r(), group='R',
                                   label='move relative')
        self.stages_bar.add_button('go_abs_r', lambda: c.go_r(), group='R',
                                   label='move absolute')

        self.stages_bar.add_button('up', lambda: c.up(), group='Jog',
                                   label='up')
        self.stages_bar.add_button('down', lambda: c.down(), group='Jog',
                                   label='down')
        self.stages_bar.add_button('left', lambda: c.left(), group='Jog',
                                   label='left')

        self.stages_bar.add_button('right', lambda: c.right(), group='Jog',
                                   label='right')

        # ---------------------------------------------------------------------
        #   FOCUS AND ZOOM CONTROLS
        # ---------------------------------------------------------------------

        self.focus_zoom_bar = atb.Bar(
            name='focus_and_zoom',
            label='Focus/Zoom Controls',
            iconified='true',
            help='Controls for adjusting power focus and zoom',
            position=(10, 10),
            size=(200, 300),
            )

        self.focus_zoom_bar.add_var('Focus/focus_step', label='focus step',
                                    target=c, attr='focus_step')
        self.focus_zoom_bar.add_button('focus_plus', lambda: c.focus_plus(),
                                       group='Focus', label='focus plus')
        self.focus_zoom_bar.add_button('focus_minus', lambda: c.focus_minus(),
                                       group='Focus', label='focus minus')

        self.focus_zoom_bar.add_var('Zoom/zoom_step', label='zoom step',
                                    target=c, attr='zoom_step')
        self.focus_zoom_bar.add_button('zoom_plus', lambda: c.zoom_plus(),
                                       group='Zoom', label='zoom plus')
        self.focus_zoom_bar.add_button('zoom_minus', lambda: c.zoom_minus(),
                                       group='Zoom', label='zoom minus')

        # ---------------------------------------------------------------------
        #   LED CONTROLS
        # ---------------------------------------------------------------------

        self.led_bar = atb.Bar(
            name='leds',
            label='LED Controls',
            iconified='true',
            help='Controls for adjusting illumination',
            position=(20, 20),
            size=(200, 180),
            )


        self.led_bar.add_var(
            'Side/Ch1_mA',
            #target=c,
            #attr='IsetCh1',
            label='I Ch1 (mA)',
            vtype=atb.TW_TYPE_UINT32,
            setter=lambda x: c.led_set_current(1, x),
            getter=lambda: c.led_soft_current(1),
            min=0,
            max=1000,
            )

        self.led_bar.add_var('Side/Ch1_status', label='Ch1 status',
                             vtype=atb.TW_TYPE_BOOL8,
                             getter=lambda: c.led_soft_status(1),
                             setter=lambda x: c.led_set_status(1, x))

        self.led_bar.add_var(
            'Top/Ch2_mA',
            #target=c,
            #attr='IsetCh2',
            label='I Ch2 (mA)',
            vtype=atb.TW_TYPE_UINT32,
            setter=lambda x: c.led_set_current(2, x),
            getter=lambda: c.led_soft_current(2),
            min=0,
            max=1000,
            )
        self.led_bar.add_var('Top/Ch2_status', vtype=atb.TW_TYPE_BOOL8,
                             getter=lambda: c.led_soft_status(2),
                             setter=lambda x: c.led_set_status(2, x))


        # --------------------------------------------------------------------
        #   GUI
        # --------------------------------------------------------------------

        self.gui_bar = atb.Bar(
            name='GUI',
            label='GUI',
            iconified='true',
            help='GUI Status',
            position=(60, 60),
            size=(200, 180),
            )


        self.gui_bar.add_var(
            'gui_framerate',
            label='gui frame rate',
            vtype=atb.TW_TYPE_FLOAT,
            min=1,
            max=200,
            step=0.1,
            readonly=True,
            getter=lambda: float(self.gui_frame_rate)
        )        


        # --------------------------------------------------------------------
        #   CAMERA
        # --------------------------------------------------------------------

        self.cam_bar = atb.Bar(
            name='Camera',
            label='Camera',
            iconified='true',
            help='Camera acquisition parameters',
            position=(60, 60),
            size=(200, 180),
            )


        self.cam_bar.add_var(
            'framerate',
            label='frame rate',
            vtype=atb.TW_TYPE_FLOAT,
            min=1,
            max=200,
            step=0.1,
            readonly=True,
            getter=lambda: float(c.get_frame_rate())
        )        

        self.cam_bar.add_var(
            'Binning/binningx',
            label='binning X',
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=16,
            step=1,
            getter=lambda: c.get_camera_attribute('BinningX'),
            setter=lambda x: c.set_camera_attribute('BinningX', int(x)),
            )

        self.cam_bar.add_var(
            'Binning/binningy',
            label='binning Y',
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=16,
            step=1,
            getter=lambda: c.get_camera_attribute('BinningY'),
            setter=lambda x: c.set_camera_attribute('BinningY', int(x)),
            )



        # ExposureMode = atb.enum('ExposureMode', {'manual': 0,
        #                             'auto_once': 1, 'auto': 2})
        # self.cam_bar.add_var('Exposure/mode', label='mode',
        #                        vtype=ExposureMode,
        #                        getter=lambda: c.get_camera_attribute('ExposureMode'),
        #                        setter=lambda x: c.set_camera_attribute('ExposureMode', int(x)))


        # self.cam_bar.add_var(
        #     'Exposure/value',
        #     label='time (ms)',
        #     vtype=atb.TW_TYPE_UINT32,
        #     min=1,
        #     max=1000,
        #     step=1,
        #     getter=lambda: c.get_camera_attribute('ExposureValue'),
        #     setter=lambda x: c.set_camera_attribute('ExposureValue', int(x)),
        #     )

        # self.cam_bar.add_var(
        #     'gain',
        #     label='gain',
        #     vtype=atb.TW_TYPE_UINT32,
        #     min=1,
        #     max=16,
        #     step=1,
        #     target=c,
        #     attr='gain',
        #     )

        # self.cam_bar.add_var(
        #     'exposure',
        #     label='exposure',
        #     vtype=atb.TW_TYPE_UINT32,
        #     min=5000,
        #     max=30000,
        #     step=1000,
        #     target=c,
        #     attr='exposure',
        #     )

        # self.cam_bar.add_var(
        #     'ROI/roi_width',
        #     label='width',
        #     vtype=atb.TW_TYPE_UINT32,
        #     min=1,
        #     max=800,
        #     step=1,
        #     target=c,
        #     attr='roi_width',
        #     )

        # self.cam_bar.add_var(
        #     'ROI/roi_height',
        #     label='height',
        #     vtype=atb.TW_TYPE_UINT32,
        #     min=1,
        #     max=800,
        #     step=1,
        #     target=c,
        #     attr='roi_height',
        #     )

        # self.cam_bar.add_var(
        #     'ROI/roi_offset_x',
        #     label='offset x',
        #     vtype=atb.TW_TYPE_UINT32,
        #     min=0,
        #     max=800,
        #     step=1,
        #     target=c,
        #     attr='roi_offset_x',
        #     )

        # self.cam_bar.add_var(
        #     'ROI/roi_offset_y',
        #     label='offset y',
        #     vtype=atb.TW_TYPE_UINT32,
        #     min=0,
        #     max=800,
        #     step=1,
        #     target=c,
        #     attr='roi_offset_y',
        #     )

        # Event Handlers
        def on_init():
            self.tracker_view.prepare_opengl()

        def on_draw():
            self.tracker_view.draw((self.window.width, self.window.height))

        def on_idle(dt):
            self.update_tracker_view()
            # time.sleep(0.05)

        def on_key_press(symbol, modifiers):
            if symbol == glumpy.key.ESCAPE:
                c.stop_continuous_acquisition()
                print "Controller has %i refs" % sys.getrefcount(c)
                c.release()
                self.controller = None
                print "Controller has %i refs" % sys.getrefcount(c)
                c.shutdown()
                #print "Shutting down controller..."
                #print "Shut down controller", c.shutdown()
                #c.continuously_acquiring = False
                #c.acq_thread.join()
                sys.exit()

        self.window.push_handlers(atb.glumpy.Handlers(self.window))
        self.window.push_handlers(on_init, on_draw, on_key_press, on_idle)
        self.window.draw()
Esempio n. 6
0
            for xi in range(n-1):
                i = yi*n + xi
                self.indices[xi,yi] = i,i+1,i+n+1,i+n
    def draw(self):
        gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
        gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY);
        gl.glVertexPointerf(self.vertices)
        gl.glTexCoordPointerf(self.texcoords)
        gl.glDrawElementsus(gl.GL_QUADS, self.indices)
        gl.glDisableClientState(gl.GL_VERTEX_ARRAY)
        gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY);



if __name__ == '__main__':
    atb.init()
    window = glumpy.Window(900,600)
    trackball = glumpy.Trackball(60,30,0.85)
    mesh = Mesh(64)
    def func3(x,y):
        return (1-x/2+x**5+y**3)*numpy.exp(-x**2-y**2)
    dx, dy = .05, .05
    x = numpy.arange(-3.0, 3.0, dx, dtype=numpy.float32)
    y = numpy.arange(-3.0, 3.0, dy, dtype=numpy.float32)
    Z = func3(*numpy.meshgrid(x, y))
    I = glumpy.Image(Z, interpolation='bilinear',
                     cmap=glumpy.colormap.Hot, lighted=True,
                     gridsize=(31.0,31.0,0.0), elevation = 0.5)

    diffuse = (c_float*4)(1.0, 1.0, 1.0, 1.0)
    ambient = (c_float*4)(0.3, 0.3, 0.3, 1.0)
Esempio n. 7
0
def browser(data_path, video_path, pts_path, cam_intrinsics_path):

	record = Temp()
	record.path = None
	record.writer = None

	c = Temp()

	c.captures = [cv2.VideoCapture(path) for path in video_path]
	total_frames = min([cap.get(7) for cap in c.captures])
	record.fps = min([cap.get(5) for cap in c.captures])

	r, img_arr = c.captures[0].read()
	if len(c.captures)==2:
		r, img_arr2 =c.captures[1].read()


	img_arr = cv2.cvtColor(img_arr, cv2.COLOR_BGR2RGB)
	fig = glumpy.figure((img_arr.shape[1], img_arr.shape[0]))
	image = glumpy.Image(img_arr)
	image.x, image.y = 0,0

	# gaze object
	gaze = Temp()
	gaze.list = np.load(pts_path)
	# gaze.x_pos = gaze.list[:,0]
	# gaze.y_pos = gaze.list[:,1]
	# gaze.dt = gaze.list[:,2]
	gaze_list = list(gaze.list)

	gaze_point = Point(color=(255,0,0,0.3), scale=40.0)
	positions_by_frame = [[] for frame in range(int(gaze_list[-1][-1]) + 1)]
	while gaze_list:
		s = gaze_list.pop(0)
		frame = int(s[-1])
		positions_by_frame[frame].append({'x': s[0], 'y': s[1], 'dt': s[2]})
	gaze.map = positions_by_frame

	# keyframe list object
	framelist = Temp()
	framelist.keyframes = []
	framelist.otherframes = []

	cam_intrinsics = Temp()
	cam_intrinsics.H_map = []

	g_pool = Temp()


	if cam_intrinsics_path is not None:
		cam_intrinsics.K = np.load(cam_intrinsics_path[0])
		cam_intrinsics.dist_coefs = np.load(cam_intrinsics_path[1])

	atb.init()
	bar = Bar("Browser", data_path, total_frames, framelist, dict(label="Controls",
			help="Scene controls", color=(50,50,50), alpha=50,
			text='light', position=(10, 10), size=(200, 440)))

	def draw():
		gaze_point.draw()


	def on_draw():
		fig.clear(0.0, 0.0, 0.0, 1.0)
		image.draw(x=image.x, y=image.y, z=0.0,
					width=fig.width, height=fig.height)
		draw()

	def on_close():
		pass


		print "Close event !"

	def on_idle(dt):
		bar.update_fps(dt)
		sleep(0.03)

		if bar.play or bar.get_single:
			# load new images
			r, img1 = c.captures[0].read()
			if len(c.captures)==2:
				r, img2 =c.captures[1].read()
				if r and img1.shape != img2.shape:
					img2 = cv2.resize(img2,(img1.shape[1],img1.shape[0]))

			if not r:
				bar.play.value = 0
				return
			bar.frame_num.value +=1
			#stop playback when at the end of file.

			if bar.frame_num.value == 0:
				bar.play.value = 0

			# Extract corresponing Pupil posistions.
			# Here we are taking only the first values of the frame for positions hence 0 index
			try:
				x_screen, y_screen = denormalize((gaze.map[bar.frame_num.value][0]['x'],
														gaze.map[bar.frame_num.value][0]['y']),
														fig.width, fig.height, flip_y=True)
				img1[int(y_screen), int(x_screen)] = [255,255,255]

				# update gaze.x_screen, gaze.y_screen /OPENGL COORIDANTE SYSTEM
				gaze.x_screen,gaze.y_screen = flip_horizontal((x_screen,y_screen), fig.height)
				gaze_point.update((	gaze.x_screen, gaze.y_screen))
				print x_screen, y_screen
			except:
				pass

			if cam_intrinsics_path is not None and bar.display.value is not 0:
				# undistor world image
				img1 = cv2.undistort(img1, cam_intrinsics.K, cam_intrinsics.dist_coefs)
				# Undistort the gaze point based on the distortion coefs
				x_screen, y_screen = undistort_point((x_screen, y_screen),
									cam_intrinsics.K, cam_intrinsics.dist_coefs)

				if bar.display.value in (2,3):
					# homography mapping
					overlay, H = homography_map(img2, img1) # map img1 onto img2 (the world onto the source video)
					# cam_intrinsics.H_map.append([bar.frame_num.value, H])
					if overlay is not None:

						pt_homog = np.array([x_screen, y_screen, 1])
						pt_homog = np.dot(H, pt_homog)
						pt_homog /= pt_homog[-1] # normalize the gaze.pts
						x_screen, y_screen, z = pt_homog

						img1=overlay #overwrite img with the overlay

				if bar.display.value == 3:
					# cv2.circle(img2, (int(x_screen), int(y_screen)), 10, (0,255,0,100), 1)
					img1=img2 #overwrite img1 with the source video


			# update the img array
			img_arr[...] = cv2.cvtColor(img1, cv2.COLOR_BGR2RGB)


			#recorder logic
			if bar.record_video.value and not bar.record_running.value:
				record.path = os.path.join(bar.data_path, "out.avi")
				record.writer = cv2.VideoWriter(record.path,cv2.cv.CV_FOURCC(*'DIVX'),record.fps, (img1.shape[1],img1.shape[0]) )
				bar.record_running.value = 1

			if bar.record_video.value and bar.record_running.value:
				# Save image frames to video writer
				try:
					cv2.circle(img1, (int(x_screen), int(y_screen)), 20, (0,255,0,100), 1)
				except:
					pass
				record.writer.write(img1)

			# Finish all recordings, clean up.
			if not bar.record_video.value and bar.record_running.value:
				record.writer = None
				bar.record_running.value = 0



			#just grab one image.
			bar.get_single = 0


		image.update()
		fig.redraw()
		if bar.exit:
			on_close()
			fig.window.stop()


	fig.window.push_handlers(on_idle)
	fig.window.push_handlers(atb.glumpy.Handlers(fig.window))
	fig.window.push_handlers(on_draw)
	fig.window.push_handlers(on_close)
	fig.window.set_title("Browser")
	fig.window.set_position(0,0)
	glumpy.show()
Esempio n. 8
0
    def __init__(self, c):

        self.controller = c
        self.tracker_view = TrackerView()

        self.show_feature_map = c_bool(False)
        self.display_starburst = c_bool(False)
        self.n_frames = 0
        self.frame_count = 0
        self.frame_rate_accum = 0.0
        self.frame_rates = []
        self.start_time = None
        self.last_time = 0
        self.last_update_time = time.time()

        self.calibration_file = ''

        atb.init()
        self.window = glumpy.Window(900, 600)
        self.window.draw()

        self.gaze_bar = atb.Bar(name='gaze',
                                label='Gaze Info',
                                iconified='false',
                                help='Current Gaze',
                                position=(10, 10),
                                size=(100, 200))

        # self.gaze_bar.add_var('Gaze/Status', label='Calibration Status',
        #                     target=c, attr='calibration_status', readonly=True)
        self.gaze_bar.add_var('Gaze/H',
                              label='Horizontal Gaze',
                              target=c,
                              attr='gaze_azimuth',
                              readonly=True)
        self.gaze_bar.add_var('Gaze/V',
                              label='Vertical Gaze',
                              target=c,
                              attr='gaze_elevation',
                              readonly=True)
        # self.gaze_bar.add_var('FPS', label='FPS', target=c,
        #                     attr='conduit_fps', readonly=True)

        # ---------------------------------------------------------------------
        #   STAGE CONTROLS
        # ---------------------------------------------------------------------

        # self.stages_bar = atb.Bar(
        #     name='stages',
        #     label='Stage Controls',
        #     iconified='true',
        #     help='Controls for adjusting stages',
        #     position=(10, 10),
        #     size=(200, 300),
        #     )

        # self.stages_bar.add_var('X/x_set', label='set value', target=c,
        #                         attr='x_set')
        # self.stages_bar.add_button('go_rel_x', lambda: c.go_rel_x(), group='X',
        #                            label='move relative')
        # self.stages_bar.add_button('go_abs_x', lambda: c.go_x(), group='X',
        #                            label='move absolute')

        # self.stages_bar.add_var('Y/y_set', label='set value', target=c,
        #                         attr='y_set')
        # self.stages_bar.add_button('go_rel_y', lambda: c.go_rel_y(), group='Y',
        #                            label='move relative')
        # self.stages_bar.add_button('go_abs_y', lambda: c.go_y(), group='Y',
        #                            label='move absolute')

        # self.stages_bar.add_var('R/r_set', label='set value', target=c,
        #                         attr='r_set')
        # self.stages_bar.add_button('go_rel_r', lambda: c.go_rel_r(), group='R',
        #                            label='move relative')
        # self.stages_bar.add_button('go_abs_r', lambda: c.go_r(), group='R',
        #                            label='move absolute')

        # self.stages_bar.add_button('up', lambda: c.up(), group='Jog',
        #                            label='up')
        # self.stages_bar.add_button('down', lambda: c.down(), group='Jog',
        #                            label='down')
        # self.stages_bar.add_button('left', lambda: c.left(), group='Jog',
        #                            label='left')

        # self.stages_bar.add_button('right', lambda: c.right(), group='Jog',
        #                            label='right')

        # ---------------------------------------------------------------------
        #   FOCUS AND ZOOM CONTROLS
        # ---------------------------------------------------------------------

        # self.focus_zoom_bar = atb.Bar(
        #     name='focus_and_zoom',
        #     label='Focus/Zoom Controls',
        #     iconified='true',
        #     help='Controls for adjusting power focus and zoom',
        #     position=(10, 10),
        #     size=(200, 300),
        #     )

        # self.focus_zoom_bar.add_var('Focus/focus_step', label='focus step',
        #                             target=c, attr='focus_step')
        # self.focus_zoom_bar.add_button('focus_plus', lambda: c.focus_plus(),
        #                                group='Focus', label='focus plus')
        # self.focus_zoom_bar.add_button('focus_minus', lambda: c.focus_minus(),
        #                                group='Focus', label='focus minus')

        # self.focus_zoom_bar.add_var('Zoom/zoom_step', label='zoom step',
        #                             target=c, attr='zoom_step')
        # self.focus_zoom_bar.add_button('zoom_plus', lambda: c.zoom_plus(),
        #                                group='Zoom', label='zoom plus')
        # self.focus_zoom_bar.add_button('zoom_minus', lambda: c.zoom_minus(),
        #                                group='Zoom', label='zoom minus')

        # ---------------------------------------------------------------------
        #   LED CONTROLS
        # ---------------------------------------------------------------------

        # self.led_bar = atb.Bar(
        #     name='leds',
        #     label='LED Controls',
        #     iconified='true',
        #     help='Controls for adjusting illumination',
        #     position=(20, 20),
        #     size=(200, 180),
        #     )

        # self.led_bar.add_var(
        #     'Side/Ch1_mA',
        #     #target=c,
        #     #attr='IsetCh1',
        #     label='I Ch1 (mA)',
        #     vtype=atb.TW_TYPE_UINT32,
        #     setter=lambda x: c.leds.set_current(1, x),
        #     getter=lambda: c.leds.soft_current(1),
        #     min=0,
        #     max=1000,
        #     )

        # self.led_bar.add_var('Side/Ch1_status', label='Ch1 status',
        #                      vtype=atb.TW_TYPE_BOOL8,
        #                      getter=lambda: c.leds.soft_status(1),
        #                      setter=lambda x: c.leds.set_status(1, x))

        # self.led_bar.add_var(
        #     'Top/Ch2_mA',
        #     #target=c,
        #     #attr='IsetCh2',
        #     label='I Ch2 (mA)',
        #     vtype=atb.TW_TYPE_UINT32,
        #     setter=lambda x: c.leds.set_current(2, x),
        #     getter=lambda: c.leds.soft_current(2),
        #     min=0,
        #     max=1000,
        #     )
        # self.led_bar.add_var('Top/Ch2_status', vtype=atb.TW_TYPE_BOOL8,
        #                      getter=lambda: c.leds.soft_status(2),
        #                      setter=lambda x: c.leds.set_status(2, x))

        #self.led_bar.add_var(
        #    'Channel3/Ch3_mA',
        #    target=c,
        #    attr='IsetCh3',
        #    label='I Ch3 (mA)',
        #    setter=lambda x: c.leds.set_current(3,x),
        #    min=0,
        #    max=250,
        #    )
        # self.led_bar.add_var('Channel3/Ch3_status', label='Ch3 status',
        #                              vtype=atb.TW_TYPE_BOOL8,
        #                              getter=lambda: c.leds.soft_status(3),
        #                              setter=lambda x: c.leds.set_status(3, x))
        #
        #         self.led_bar.add_var(
        #             'Channel4/Ch4_mA',
        #             target=c,
        #             attr='IsetCh4',
        #             label='I Ch4 (mA)',
        #             setter=lambda x: c.leds.set_current(4,x),
        #             min=0,
        #             max=250,
        #             )
        #         self.led_bar.add_var('Channel4/Ch4_status', label='Ch4 status',
        #                              vtype=atb.TW_TYPE_BOOL8,
        #                              getter=lambda: c.leds.soft_status(4),
        #                              setter=lambda x: c.leds.set_status(4, x))

        # ---------------------------------------------------------------------
        #   RADIAL FEATURE FINDER
        # ---------------------------------------------------------------------
        if True:
            radial_ff = c.radial_ff

            self.radial_ff_bar = atb.Bar(
                name='RadialFF',
                label='Radial Symmetry',
                help='Parameters for initial (symmetry-based) image processing',
                iconified='true',
                position=(30, 30),
                size=(250, 180),
            )

            self.radial_ff_bar.add_var(
                'target_kpixels',
                label='Target kPixels',
                vtype=atb.TW_TYPE_FLOAT,
                min=50.,
                max=1000.,
                step=10.,
                target=radial_ff,
                attr='target_kpixels',
            )
            self.radial_ff_bar.add_var(
                'min_radius_fraction',
                label='Min. radius (fraction)',
                vtype=atb.TW_TYPE_FLOAT,
                min=0.01,
                max=0.5,
                step=0.01,
                target=radial_ff,
                attr='min_radius_fraction',
            )
            self.radial_ff_bar.add_var(
                'max_radius_fraction',
                label='Max. radius (fraction)',
                vtype=atb.TW_TYPE_FLOAT,
                min=0.1,
                max=0.8,
                step=0.01,
                target=radial_ff,
                attr='max_radius_fraction',
            )
            self.radial_ff_bar.add_var(
                'radius_steps',
                label='Radius steps',
                vtype=atb.TW_TYPE_UINT32,
                min=1,
                max=10,
                step=1,
                target=radial_ff,
                attr='radius_steps',
            )
            self.radial_ff_bar.add_var(
                'alpha',
                label='Alpha',
                vtype=atb.TW_TYPE_FLOAT,
                min=1.,
                max=50.,
                step=1.,
                target=radial_ff,
                attr='alpha',
            )

            self.radial_ff_bar.add_var('show_transform',
                                       label='Show Transform',
                                       vtype=atb.TW_TYPE_BOOL8,
                                       target=self,
                                       attr='show_feature_map')

            self.radial_ff_bar.add_var('Albino/albino_mode_enable',
                                       label='Mode Enabled',
                                       vtype=atb.TW_TYPE_BOOL8,
                                       target=radial_ff,
                                       attr='albino_mode')
            self.radial_ff_bar.add_var(
                'Albino/albino_threshold',
                label='Threshold',
                vtype=atb.TW_TYPE_FLOAT,
                min=0.1,
                max=50.,
                step=1.,
                target=radial_ff,
                attr='albino_threshold',
            )

            self.radial_ff_bar.add_var(
                'RestrictRegion/top',
                label='top',
                vtype=atb.TW_TYPE_UINT32,
                min=0,
                max=300,
                step=1,
                target=radial_ff,
                attr='restrict_top',
            )
            self.radial_ff_bar.add_var(
                'RestrictRegion/left',
                label='left',
                vtype=atb.TW_TYPE_UINT32,
                min=0,
                max=300,
                step=1,
                target=radial_ff,
                attr='restrict_left',
            )

            self.radial_ff_bar.add_var(
                'RestrictRegion/right',
                label='right',
                vtype=atb.TW_TYPE_UINT32,
                min=0,
                max=300,
                step=1,
                target=radial_ff,
                attr='restrict_right',
            )

            self.radial_ff_bar.add_var(
                'RestrictRegion/bottom',
                label='bottom',
                vtype=atb.TW_TYPE_UINT32,
                min=0,
                max=300,
                step=1,
                target=radial_ff,
                attr='restrict_bottom',
            )

            # ---------------------------------------------------------------------
            #   STARBURST FEATURE FINDER
            # ---------------------------------------------------------------------

            self.sb_ff_bar = atb.Bar(
                name='StarburstFF',
                label='Starburst',
                iconified='true',
                help=
                "Parameters for the refinement phase ('starburst') image processing",
                position=(40, 40),
                size=(200, 250),
            )

            sb_ff = c.starburst_ff

            self.sb_ff_bar.add_var(
                'Pupil/n_pupil_rays',
                label='n rays',
                vtype=atb.TW_TYPE_UINT32,
                min=1,
                max=100,
                step=1,
                target=sb_ff,
                attr='pupil_n_rays',
            )

            self.sb_ff_bar.add_var(
                'Pupil/pupil_min_radius',
                label='min radius',
                vtype=atb.TW_TYPE_UINT32,
                min=1,
                max=100,
                step=1,
                target=sb_ff,
                attr='pupil_min_radius',
            )

            self.sb_ff_bar.add_var(
                'Pupil/pupil_threshold',
                label='edge detect threshold',
                vtype=atb.TW_TYPE_FLOAT,
                min=0.1,
                max=5.0,
                step=0.1,
                target=sb_ff,
                attr='pupil_threshold',
            )

            self.sb_ff_bar.add_var(
                'CR/n_cr_rays',
                label='n rays',
                vtype=atb.TW_TYPE_UINT32,
                min=1,
                max=100,
                step=1,
                target=sb_ff,
                attr='cr_n_rays',
            )

            self.sb_ff_bar.add_var(
                'CR/cr_min_radius',
                label='min radius',
                vtype=atb.TW_TYPE_UINT32,
                min=1,
                max=100,
                step=1,
                target=sb_ff,
                attr='cr_min_radius',
            )

            self.sb_ff_bar.add_var(
                'CR/cr_threshold',
                label='edge detect threshold',
                vtype=atb.TW_TYPE_FLOAT,
                min=0.1,
                max=5.0,
                step=0.1,
                target=sb_ff,
                attr='cr_threshold',
            )

            fit_algos = {
                0: 'circle_least_squares',
                1: 'circle_least_squares_ransac',
                2: 'ellipse_least_squares'
            }

            fit_algos_rev = dict([(val, key)
                                  for (key, val) in fit_algos.items()])

            FittingAlgorithm = atb.enum('FittingAlgorithm', {
                'circle lst sq': 0,
                'circle ransac': 1,
                'ellipse lst sq': 2
            })
            self.sb_ff_bar.add_var('Fitting/circle_fit', label='circle fit method',
                                   vtype=FittingAlgorithm, getter=lambda: \
                                   fit_algos_rev[sb_ff.fitting_algorithm],
                                   setter=lambda x: \
                                   setattr(sb_ff, 'fitting_algorithm', fit_algos[x]))

            self.sb_ff_bar.add_var('Display/show_rays', self.display_starburst)

        # ---------------------------------------------------------------------
        #   CALIBRATION
        # ---------------------------------------------------------------------
        # self.cal_bar = atb.Bar(
        #     name='Calibration',
        #     label='Calibration',
        #     iconified='true',
        #     help='Auto-calibration steps',
        #     position=(50, 50),
        #     size=(250, 300),
        #     refresh=0.5
        #     )

        # self.cal_bar.add_button('calibrate', lambda: c.calibrate(),
        #                         label='Calibrate (full)')

        # self.cal_bar.add_separator('Sub-phases')
        # self.cal_bar.add_button('cal_center_h', lambda: \
        #                         c.calibrate_center_horizontal(),
        #                         label='Center Horizontal')
        # self.cal_bar.add_button('cal_center_v', lambda: \
        #                         c.calibrate_center_vertical(),
        #                         label='Center Vertical')
        # self.cal_bar.add_button('cal_center_d', lambda: \
        #                         c.calibrate_center_depth(), label='Center Depth'
        #                         )

        # self.cal_bar.add_button('cal_pupil_rad', lambda: \
        #                         c.calibrate_find_pupil_radius(),
        #                         label='Find Pupil Radius')

        # self.cal_bar.add_separator('Info')
        # self.cal_bar.add_var('d', label='Distance to CR curv. center',
        #                      vtype=atb.TW_TYPE_FLOAT, target=c.calibrator,
        #                      attr='d')  # readonly = True,
        # self.cal_bar.add_var('Rp', label='Pupil rotation radius (Rp)[mm]',
        #                      vtype=atb.TW_TYPE_FLOAT, target=c.calibrator,
        #                      attr='Rp_mm')  # readonly = True,

        # # Calibration Files
        # try:
        #     self.refresh_calibration_file_list()

        #     self.cal_bar.add_separator('Calibration Files')

        #     self.cal_bar.add_var('current_calibration_file',
        #                          vtype=self.cal_enum, label='Calibration File',
        #                          getter=lambda: \
        #                          self.get_calibration_file_atb(),
        #                          setter=lambda x: \
        #                          self.set_calibration_file_atb(x))
        #                           # setter = lambda x: sb_ff.__dict__.__setitem__('fitting_algorithm', fit_algos[x]))
        #                           # getter=lambda: self.get_calibration_file_atb,
        #                           # setter=lambda x: self.set_calibration_file_atb(x))

        #     self.cal_bar.add_separator('Calibration Save')
        #     self.cal_file_save_name = ctypes.c_char_p('')

        #     self.cal_bar.add_var('calibration_file_save_name',
        #                          vtype=atb.TW_TYPE_CDSTRING, target=self,
        #                          attr='cal_file_save_name')
        #     self.cal_bar.add_button('save_calibration', lambda: \
        #                             self.save_calibration_file_atb(self.cal_file_save_name))
        # except Exception as E:
        #     logging.warning("Error setting calibration file list: %s" % E)
        #     logging.warning("""Unable to use calibration-file saving
        #                        infrastructure.  A patched version of glumpy
        #                        is required to enable this feature.""")

        # --------------------------------------------------------------------
        #   CAMERA
        # --------------------------------------------------------------------

        self.cam_bar = atb.Bar(
            name='Camera',
            label='Camera',
            iconified='true',
            help='Camera acquisition parameters',
            position=(60, 60),
            size=(200, 180),
        )

        cam = c.camera

        # def saving(x=None):
        #     if not hasattr(c.feature_finder, 'save'):
        #         return False
        #     if x is None:
        #         return c.feature_finder.save
        #     c.feature_finder.save = x

        # self.cam_bar.add_var(
        #     'save',
        #     label='save',
        #     vtype=atb.TW_TYPE_BOOL8,
        #     getter=lambda: saving(),
        #     setter=lambda x: saving(x),
        # )

        # self.cam_bar.add_var(
        #     'binning',
        #     label='binning',
        #     vtype=atb.TW_TYPE_UINT32,
        #     min=1,
        #     max=16,
        #     step=1,
        #     target=cam,
        #     attr='binning',
        #     )

        # self.cam_bar.add_var(
        #     'gain',
        #     label='gain',
        #     vtype=atb.TW_TYPE_UINT32,
        #     min=1,
        #     max=16,
        #     step=1,
        #     target=cam,
        #     attr='gain',
        #     )

        # self.cam_bar.add_var(
        #     'exposure',
        #     label='exposure',
        #     vtype=atb.TW_TYPE_UINT32,
        #     min=5000,
        #     max=30000,
        #     step=1000,
        #     target=c,
        #     attr='exposure',
        #     )

        self.cam_bar.add_var(
            'ROI/roi_width',
            label='width',
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=800,
            step=1,
            target=cam,
            attr='roi_width',
        )

        self.cam_bar.add_var(
            'ROI/roi_height',
            label='height',
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=800,
            step=1,
            target=cam,
            attr='roi_height',
        )

        # Event Handlers
        def on_init():
            self.tracker_view.prepare_opengl()

        def on_draw():
            self.window.clear()
            self.tracker_view.draw((self.window.width, self.window.height))

        def on_idle(dt):
            # if dt < 0.02:
            #    return
            self.update_tracker_view()
            self.window.draw()

        def on_key_press(symbol, modifiers):
            if symbol == glumpy.key.ESCAPE:
                c.stop_continuous_acquisition()
                logging.debug("Controller has %i refs" % sys.getrefcount(c))
                c.release()
                self.controller = None
                logging.debug("Controller has %i refs" % sys.getrefcount(c))
                c.shutdown()
                sys.exit()

        self.window.push_handlers(atb.glumpy.Handlers(self.window))
        self.window.push_handlers(on_init, on_draw, on_key_press, on_idle)
        self.window.draw()
Esempio n. 9
0
    def __init__(self, c):

        self.controller = c
        self.tracker_view = TrackerView()

        self.show_feature_map = c_bool(False)
        self.display_starburst = c_bool(False)
        self.n_frames = 0
        self.frame_count = 0
        self.frame_rate_accum = 0.0
        self.frame_rates = []
        self.start_time = None
        self.last_time = 0
        self.last_update_time = time.time()

        self.calibration_file = ''

        atb.init()
        self.window = glumpy.Window(900, 600)

        # ---------------------------------------------------------------------
        #   STAGE CONTROLS
        # ---------------------------------------------------------------------

        self.gaze_bar = atb.Bar(
            name='gaze',
            label='Gaze Info',
            iconified='false',
            help='Current Gaze',
            position=(10, 10),
            size=(100, 200))

        self.gaze_bar.add_var('Gaze/Status', label='Calibration Status',
                            target=c, attr='calibration_status', readonly=True)
        self.gaze_bar.add_var('Gaze/H', label='Horizontal Gaze', target=c,
                            attr='gaze_azimuth', readonly=True)
        self.gaze_bar.add_var('Gaze/V', label='Vertical Gaze', target=c,
                            attr='gaze_elevation', readonly=True)
        self.gaze_bar.add_var('FPS', label='FPS', target=c,
                            attr='conduit_fps', readonly=True)

        self.stages_bar = atb.Bar(
            name='stages',
            label='Stage Controls',
            iconified='true',
            help='Controls for adjusting stages',
            position=(10, 10),
            size=(200, 300),
            )

        self.stages_bar.add_var('X/x_set', label='set value', target=c,
                                attr='x_set')
        self.stages_bar.add_button('go_rel_x', lambda: c.go_rel_x(), group='X',
                                   label='move relative')
        self.stages_bar.add_button('go_abs_x', lambda: c.go_x(), group='X',
                                   label='move absolute')

        self.stages_bar.add_var('Y/y_set', label='set value', target=c,
                                attr='y_set')
        self.stages_bar.add_button('go_rel_y', lambda: c.go_rel_y(), group='Y',
                                   label='move relative')
        self.stages_bar.add_button('go_abs_y', lambda: c.go_y(), group='Y',
                                   label='move absolute')

        self.stages_bar.add_var('R/r_set', label='set value', target=c,
                                attr='r_set')
        self.stages_bar.add_button('go_rel_r', lambda: c.go_rel_r(), group='R',
                                   label='move relative')
        self.stages_bar.add_button('go_abs_r', lambda: c.go_r(), group='R',
                                   label='move absolute')

        self.stages_bar.add_button('up', lambda: c.up(), group='Jog',
                                   label='up')
        self.stages_bar.add_button('down', lambda: c.down(), group='Jog',
                                   label='down')
        self.stages_bar.add_button('left', lambda: c.left(), group='Jog',
                                   label='left')

        self.stages_bar.add_button('right', lambda: c.right(), group='Jog',
                                   label='right')

        # ---------------------------------------------------------------------
        #   FOCUS AND ZOOM CONTROLS
        # ---------------------------------------------------------------------

        self.focus_zoom_bar = atb.Bar(
            name='focus_and_zoom',
            label='Focus/Zoom Controls',
            iconified='true',
            help='Controls for adjusting power focus and zoom',
            position=(10, 10),
            size=(200, 300),
            )

        self.focus_zoom_bar.add_var('Focus/focus_step', label='focus step',
                                    target=c, attr='focus_step')
        self.focus_zoom_bar.add_button('focus_plus', lambda: c.focus_plus(),
                                       group='Focus', label='focus plus')
        self.focus_zoom_bar.add_button('focus_minus', lambda: c.focus_minus(),
                                       group='Focus', label='focus minus')

        self.focus_zoom_bar.add_var('Zoom/zoom_step', label='zoom step',
                                    target=c, attr='zoom_step')
        self.focus_zoom_bar.add_button('zoom_plus', lambda: c.zoom_plus(),
                                       group='Zoom', label='zoom plus')
        self.focus_zoom_bar.add_button('zoom_minus', lambda: c.zoom_minus(),
                                       group='Zoom', label='zoom minus')

        # ---------------------------------------------------------------------
        #   LED CONTROLS
        # ---------------------------------------------------------------------

        self.led_bar = atb.Bar(
            name='leds',
            label='LED Controls',
            iconified='true',
            help='Controls for adjusting illumination',
            position=(20, 20),
            size=(200, 180),
            )

        self.led_bar.add_var(
            'Side/Ch1_mA',
            #target=c,
            #attr='IsetCh1',
            label='I Ch1 (mA)',
            vtype=atb.TW_TYPE_UINT32,
            setter=lambda x: c.leds.set_current(1, x),
            getter=lambda: c.leds.soft_current(1),
            min=0,
            max=1000,
            )

        self.led_bar.add_var('Side/Ch1_status', label='Ch1 status',
                             vtype=atb.TW_TYPE_BOOL8,
                             getter=lambda: c.leds.soft_status(1),
                             setter=lambda x: c.leds.set_status(1, x))

        self.led_bar.add_var(
            'Top/Ch2_mA',
            #target=c,
            #attr='IsetCh2',
            label='I Ch2 (mA)',
            vtype=atb.TW_TYPE_UINT32,
            setter=lambda x: c.leds.set_current(2, x),
            getter=lambda: c.leds.soft_current(2),
            min=0,
            max=1000,
            )
        self.led_bar.add_var('Top/Ch2_status', vtype=atb.TW_TYPE_BOOL8,
                             getter=lambda: c.leds.soft_status(2),
                             setter=lambda x: c.leds.set_status(2, x))

        #self.led_bar.add_var(
        #    'Channel3/Ch3_mA',
        #    target=c,
        #    attr='IsetCh3',
        #    label='I Ch3 (mA)',
        #    setter=lambda x: c.leds.set_current(3,x),
        #    min=0,
        #    max=250,
        #    )
        # self.led_bar.add_var('Channel3/Ch3_status', label='Ch3 status',
        #                              vtype=atb.TW_TYPE_BOOL8,
        #                              getter=lambda: c.leds.soft_status(3),
        #                              setter=lambda x: c.leds.set_status(3, x))
        #
        #         self.led_bar.add_var(
        #             'Channel4/Ch4_mA',
        #             target=c,
        #             attr='IsetCh4',
        #             label='I Ch4 (mA)',
        #             setter=lambda x: c.leds.set_current(4,x),
        #             min=0,
        #             max=250,
        #             )
        #         self.led_bar.add_var('Channel4/Ch4_status', label='Ch4 status',
        #                              vtype=atb.TW_TYPE_BOOL8,
        #                              getter=lambda: c.leds.soft_status(4),
        #                              setter=lambda x: c.leds.set_status(4, x))

        # ---------------------------------------------------------------------
        #   RADIAL FEATURE FINDER
        # ---------------------------------------------------------------------
        radial_ff = c.radial_ff

        self.radial_ff_bar = atb.Bar(
            name='RadialFF',
            label='Radial Symmetry',
            help='Parameters for initial (symmetry-based) image processing',
            iconified='true',
            position=(30, 30),
            size=(250, 180),
            )

        self.radial_ff_bar.add_var(
            'target_kpixels',
            label='Target kPixels',
            vtype=atb.TW_TYPE_FLOAT,
            min=50.,
            max=1000.,
            step=10.,
            target=radial_ff,
            attr='target_kpixels',
            )
        self.radial_ff_bar.add_var(
            'min_radius_fraction',
            label='Min. radius (fraction)',
            vtype=atb.TW_TYPE_FLOAT,
            min=0.01,
            max=0.5,
            step=0.01,
            target=radial_ff,
            attr='min_radius_fraction',
            )
        self.radial_ff_bar.add_var(
            'max_radius_fraction',
            label='Max. radius (fraction)',
            vtype=atb.TW_TYPE_FLOAT,
            min=0.1,
            max=0.8,
            step=0.01,
            target=radial_ff,
            attr='max_radius_fraction',
            )
        self.radial_ff_bar.add_var(
            'radius_steps',
            label='Radius steps',
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=10,
            step=1,
            target=radial_ff,
            attr='radius_steps',
            )
        self.radial_ff_bar.add_var(
            'alpha',
            label='Alpha',
            vtype=atb.TW_TYPE_FLOAT,
            min=1.,
            max=50.,
            step=1.,
            target=radial_ff,
            attr='alpha',
            )

        self.radial_ff_bar.add_var('show_transform', label='Show Transform',
                                   vtype=atb.TW_TYPE_BOOL8, target=self,
                                   attr='show_feature_map')

        self.radial_ff_bar.add_var('Albino/albino_mode_enable',
                                   label='Mode Enabled',
                                   vtype=atb.TW_TYPE_BOOL8, target=radial_ff,
                                   attr='albino_mode')
        self.radial_ff_bar.add_var(
            'Albino/albino_threshold',
            label='Threshold',
            vtype=atb.TW_TYPE_FLOAT,
            min=0.1,
            max=50.,
            step=1.,
            target=radial_ff,
            attr='albino_threshold',
            )

        self.radial_ff_bar.add_var(
            'RestrictRegion/top',
            label='top',
            vtype=atb.TW_TYPE_UINT32,
            min=0,
            max=300,
            step=1,
            target=radial_ff,
            attr='restrict_top',
            )
        self.radial_ff_bar.add_var(
            'RestrictRegion/left',
            label='left',
            vtype=atb.TW_TYPE_UINT32,
            min=0,
            max=300,
            step=1,
            target=radial_ff,
            attr='restrict_left',
            )

        self.radial_ff_bar.add_var(
            'RestrictRegion/right',
            label='right',
            vtype=atb.TW_TYPE_UINT32,
            min=0,
            max=300,
            step=1,
            target=radial_ff,
            attr='restrict_right',
            )

        self.radial_ff_bar.add_var(
            'RestrictRegion/bottom',
            label='bottom',
            vtype=atb.TW_TYPE_UINT32,
            min=0,
            max=300,
            step=1,
            target=radial_ff,
            attr='restrict_bottom',
            )

        # ---------------------------------------------------------------------
        #   STARBURST FEATURE FINDER
        # ---------------------------------------------------------------------

        self.sb_ff_bar = atb.Bar(
            name='StarburstFF',
            label='Starburst',
            iconified='true',
            help="Parameters for the refinement phase ('starburst') image processing",
            position=(40, 40),
            size=(200, 250),
            )

        sb_ff = c.starburst_ff

        self.sb_ff_bar.add_var(
            'Pupil/n_pupil_rays',
            label='n rays',
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=100,
            step=1,
            target=sb_ff,
            attr='pupil_n_rays',
            )

        self.sb_ff_bar.add_var(
            'Pupil/pupil_min_radius',
            label='min radius',
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=100,
            step=1,
            target=sb_ff,
            attr='pupil_min_radius',
            )

        self.sb_ff_bar.add_var(
            'Pupil/pupil_threshold',
            label='edge detect threshold',
            vtype=atb.TW_TYPE_FLOAT,
            min=0.1,
            max=5.0,
            step=0.1,
            target=sb_ff,
            attr='pupil_threshold',
            )

        self.sb_ff_bar.add_var(
            'CR/n_cr_rays',
            label='n rays',
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=100,
            step=1,
            target=sb_ff,
            attr='cr_n_rays',
            )

        self.sb_ff_bar.add_var(
            'CR/cr_min_radius',
            label='min radius',
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=100,
            step=1,
            target=sb_ff,
            attr='cr_min_radius',
            )

        self.sb_ff_bar.add_var(
            'CR/cr_threshold',
            label='edge detect threshold',
            vtype=atb.TW_TYPE_FLOAT,
            min=0.1,
            max=5.0,
            step=0.1,
            target=sb_ff,
            attr='cr_threshold',
            )

        fit_algos = {0: 'circle_least_squares',
                     1: 'circle_least_squares_ransac',
                     2: 'ellipse_least_squares'}

        fit_algos_rev = dict([(val, key) for (key, val) in fit_algos.items()])

        FittingAlgorithm = atb.enum('FittingAlgorithm', {'circle lst sq': 0,
                                    'circle ransac': 1, 'ellipse lst sq': 2})
        self.sb_ff_bar.add_var('Fitting/circle_fit', label='circle fit method',
                               vtype=FittingAlgorithm, getter=lambda: \
                               fit_algos_rev[sb_ff.fitting_algorithm],
                               setter=lambda x: \
                               setattr(sb_ff, 'fitting_algorithm', fit_algos[x]))

        self.sb_ff_bar.add_var('Display/show_rays', self.display_starburst)

        # ---------------------------------------------------------------------
        #   CALIBRATION
        # ---------------------------------------------------------------------
        self.cal_bar = atb.Bar(
            name='Calibration',
            label='Calibration',
            iconified='true',
            help='Auto-calibration steps',
            position=(50, 50),
            size=(250, 300),
            refresh=0.5
            )

        self.cal_bar.add_button('calibrate', lambda: c.calibrate(),
                                label='Calibrate (full)')

        self.cal_bar.add_separator('Sub-phases')
        self.cal_bar.add_button('cal_center_h', lambda: \
                                c.calibrate_center_horizontal(),
                                label='Center Horizontal')
        self.cal_bar.add_button('cal_center_v', lambda: \
                                c.calibrate_center_vertical(),
                                label='Center Vertical')
        self.cal_bar.add_button('cal_center_d', lambda: \
                                c.calibrate_center_depth(), label='Center Depth'
                                )
        #self.cal_bar.add_button('align_pupil_cr', lambda: \
        #                        c.calibrate_align_pupil_and_cr(),
        #                        label='Align Pupil and CR')
        self.cal_bar.add_button('cal_pupil_rad', lambda: \
                                c.calibrate_find_pupil_radius(),
                                label='Find Pupil Radius')

        self.cal_bar.add_separator('Info')
        self.cal_bar.add_var('d', label='Distance to CR curv. center',
                             vtype=atb.TW_TYPE_FLOAT, target=c.calibrator,
                             attr='d')  # readonly = True,
        self.cal_bar.add_var('Rp', label='Pupil rotation radius (Rp)[mm]',
                             vtype=atb.TW_TYPE_FLOAT, target=c.calibrator,
                             attr='Rp_mm')  # readonly = True,

        # Calibration Files
        try:
            self.refresh_calibration_file_list()

            self.cal_bar.add_separator('Calibration Files')

            self.cal_bar.add_var('current_calibration_file',
                                 vtype=self.cal_enum, label='Calibration File',
                                 getter=lambda: \
                                 self.get_calibration_file_atb(),
                                 setter=lambda x: \
                                 self.set_calibration_file_atb(x))
                                  # setter = lambda x: sb_ff.__dict__.__setitem__('fitting_algorithm', fit_algos[x]))
                                  # getter=lambda: self.get_calibration_file_atb,
                                  # setter=lambda x: self.set_calibration_file_atb(x))

            self.cal_bar.add_separator('Calibration Save')
            self.cal_file_save_name = ctypes.c_char_p('')

            self.cal_bar.add_var('calibration_file_save_name',
                                 vtype=atb.TW_TYPE_CDSTRING, target=self,
                                 attr='cal_file_save_name')
            self.cal_bar.add_button('save_calibration', lambda: \
                                    self.save_calibration_file_atb(self.cal_file_save_name))
        except Exception as E:
            logging.warning("Error setting calibration file list: %s" % E)
            logging.warning("""Unable to use calibration-file saving
                               infrastructure.  A patched version of glumpy
                               is required to enable this feature.""")

        # --------------------------------------------------------------------
        #   CAMERA
        # --------------------------------------------------------------------

        self.cam_bar = atb.Bar(
            name='Camera',
            label='Camera',
            iconified='true',
            help='Camera acquisition parameters',
            position=(60, 60),
            size=(200, 180),
            )

        def saving(x=None):
            if not hasattr(c.feature_finder, 'save'):
                return False
            if x is None:
                return c.feature_finder.save
            c.feature_finder.save = x

        self.cam_bar.add_var(
            'save',
            label='save',
            vtype=atb.TW_TYPE_BOOL8,
            getter=lambda: saving(),
            setter=lambda x: saving(x),
        )

        self.cam_bar.add_var(
            'binning',
            label='binning',
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=16,
            step=1,
            target=c,
            attr='binning',
            )

        self.cam_bar.add_var(
            'gain',
            label='gain',
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=16,
            step=1,
            target=c,
            attr='gain',
            )

        self.cam_bar.add_var(
            'exposure',
            label='exposure',
            vtype=atb.TW_TYPE_UINT32,
            min=5000,
            max=30000,
            step=1000,
            target=c,
            attr='exposure',
            )

        self.cam_bar.add_var(
            'ROI/roi_width',
            label='width',
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=800,
            step=1,
            target=c,
            attr='roi_width',
            )

        self.cam_bar.add_var(
            'ROI/roi_height',
            label='height',
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=800,
            step=1,
            target=c,
            attr='roi_height',
            )

        self.cam_bar.add_var(
            'ROI/roi_offset_x',
            label='offset x',
            vtype=atb.TW_TYPE_UINT32,
            min=0,
            max=800,
            step=1,
            target=c,
            attr='roi_offset_x',
            )

        self.cam_bar.add_var(
            'ROI/roi_offset_y',
            label='offset y',
            vtype=atb.TW_TYPE_UINT32,
            min=0,
            max=800,
            step=1,
            target=c,
            attr='roi_offset_y',
            )

        # Event Handlers
        def on_init():
            self.tracker_view.prepare_opengl()

        def on_draw():
            self.window.clear()
            self.tracker_view.draw((self.window.width, self.window.height))

        def on_idle(dt):
            # if dt < 0.02:
            #    return
            self.update_tracker_view()
            self.window.draw()

        def on_key_press(symbol, modifiers):
            if symbol == glumpy.key.ESCAPE:
                c.stop_continuous_acquisition()
                logging.debug("Controller has %i refs" % sys.getrefcount(c))
                c.release()
                self.controller = None
                logging.debug("Controller has %i refs" % sys.getrefcount(c))
                c.shutdown()
                #print "Shutting down controller..."
                #print "Shut down controller", c.shutdown()
                #c.continuously_acquiring = False
                #c.acq_thread.join()
                sys.exit()

        self.window.push_handlers(atb.glumpy.Handlers(self.window))
        self.window.push_handlers(on_init, on_draw, on_key_press, on_idle)
        self.window.draw()
Esempio n. 10
0
    def __init__(self, c):

        self.controller = c
        self.tracker_view = TrackerView()

        self.show_feature_map = c_bool(False)
        self.display_starburst = c_bool(False)
        self.n_frames = 0
        self.frame_count = 0
        self.frame_rate_accum = 0.0
        self.frame_rates = []
        self.start_time = None
        self.last_time = 0
        self.last_update_time = time.time()

        self.calibration_file = ""

        atb.init()
        self.window = glumpy.Window(900, 600)

        # ---------------------------------------------------------------------
        #   STAGE CONTROLS
        # ---------------------------------------------------------------------

        self.gaze_bar = atb.Bar(
            name="gaze", label="Gaze Info", iconified="false", help="Current Gaze", position=(10, 10), size=(100, 200)
        )

        self.gaze_bar.add_var(
            "Gaze/Status", label="Calibration Status", target=c, attr="calibration_status", readonly=True
        )
        self.gaze_bar.add_var("Gaze/H", label="Horizontal Gaze", target=c, attr="gaze_azimuth", readonly=True)
        self.gaze_bar.add_var("Gaze/V", label="Vertical Gaze", target=c, attr="gaze_elevation", readonly=True)
        self.gaze_bar.add_var("FPS", label="FPS", target=c, attr="conduit_fps", readonly=True)

        self.stages_bar = atb.Bar(
            name="stages",
            label="Stage Controls",
            iconified="true",
            help="Controls for adjusting stages",
            position=(10, 10),
            size=(200, 300),
        )

        self.stages_bar.add_var("X/x_set", label="set value", target=c, attr="x_set")
        self.stages_bar.add_button("go_rel_x", lambda: c.go_rel_x(), group="X", label="move relative")
        self.stages_bar.add_button("go_abs_x", lambda: c.go_x(), group="X", label="move absolute")

        self.stages_bar.add_var("Y/y_set", label="set value", target=c, attr="y_set")
        self.stages_bar.add_button("go_rel_y", lambda: c.go_rel_y(), group="Y", label="move relative")
        self.stages_bar.add_button("go_abs_y", lambda: c.go_y(), group="Y", label="move absolute")

        self.stages_bar.add_var("R/r_set", label="set value", target=c, attr="r_set")
        self.stages_bar.add_button("go_rel_r", lambda: c.go_rel_r(), group="R", label="move relative")
        self.stages_bar.add_button("go_abs_r", lambda: c.go_r(), group="R", label="move absolute")

        self.stages_bar.add_button("up", lambda: c.up(), group="Jog", label="up")
        self.stages_bar.add_button("down", lambda: c.down(), group="Jog", label="down")
        self.stages_bar.add_button("left", lambda: c.left(), group="Jog", label="left")

        self.stages_bar.add_button("right", lambda: c.right(), group="Jog", label="right")

        # ---------------------------------------------------------------------
        #   FOCUS AND ZOOM CONTROLS
        # ---------------------------------------------------------------------

        self.focus_zoom_bar = atb.Bar(
            name="focus_and_zoom",
            label="Focus/Zoom Controls",
            iconified="true",
            help="Controls for adjusting power focus and zoom",
            position=(10, 10),
            size=(200, 300),
        )

        self.focus_zoom_bar.add_var("Focus/focus_step", label="focus step", target=c, attr="focus_step")
        self.focus_zoom_bar.add_button("focus_plus", lambda: c.focus_plus(), group="Focus", label="focus plus")
        self.focus_zoom_bar.add_button("focus_minus", lambda: c.focus_minus(), group="Focus", label="focus minus")

        self.focus_zoom_bar.add_var("Zoom/zoom_step", label="zoom step", target=c, attr="zoom_step")
        self.focus_zoom_bar.add_button("zoom_plus", lambda: c.zoom_plus(), group="Zoom", label="zoom plus")
        self.focus_zoom_bar.add_button("zoom_minus", lambda: c.zoom_minus(), group="Zoom", label="zoom minus")

        # ---------------------------------------------------------------------
        #   LED CONTROLS
        # ---------------------------------------------------------------------

        self.led_bar = atb.Bar(
            name="leds",
            label="LED Controls",
            iconified="true",
            help="Controls for adjusting illumination",
            position=(20, 20),
            size=(200, 180),
        )

        self.led_bar.add_var(
            "Side/Ch1_mA",
            # target=c,
            # attr='IsetCh1',
            label="I Ch1 (mA)",
            vtype=atb.TW_TYPE_UINT32,
            setter=lambda x: c.leds.set_current(1, x),
            getter=lambda: c.leds.soft_current(1),
            min=0,
            max=1000,
        )

        self.led_bar.add_var(
            "Side/Ch1_status",
            label="Ch1 status",
            vtype=atb.TW_TYPE_BOOL8,
            getter=lambda: c.leds.soft_status(1),
            setter=lambda x: c.leds.set_status(1, x),
        )

        self.led_bar.add_var(
            "Top/Ch2_mA",
            # target=c,
            # attr='IsetCh2',
            label="I Ch2 (mA)",
            vtype=atb.TW_TYPE_UINT32,
            setter=lambda x: c.leds.set_current(2, x),
            getter=lambda: c.leds.soft_current(2),
            min=0,
            max=1000,
        )
        self.led_bar.add_var(
            "Top/Ch2_status",
            vtype=atb.TW_TYPE_BOOL8,
            getter=lambda: c.leds.soft_status(2),
            setter=lambda x: c.leds.set_status(2, x),
        )

        # self.led_bar.add_var(
        #    'Channel3/Ch3_mA',
        #    target=c,
        #    attr='IsetCh3',
        #    label='I Ch3 (mA)',
        #    setter=lambda x: c.leds.set_current(3,x),
        #    min=0,
        #    max=250,
        #    )
        # self.led_bar.add_var('Channel3/Ch3_status', label='Ch3 status',
        #                          vtype=atb.TW_TYPE_BOOL8,
        #                          getter=lambda: c.leds.soft_status(3),
        #                          setter=lambda x: c.leds.set_status(3, x))
        #
        #         self.led_bar.add_var(
        #             'Channel4/Ch4_mA',
        #             target=c,
        #             attr='IsetCh4',
        #             label='I Ch4 (mA)',
        #             setter=lambda x: c.leds.set_current(4,x),
        #             min=0,
        #             max=250,
        #             )
        #         self.led_bar.add_var('Channel4/Ch4_status',
        #                          label='Ch4 status',
        #                          vtype=atb.TW_TYPE_BOOL8,
        #                          getter=lambda: c.leds.soft_status(4),
        #                          setter=lambda x: c.leds.set_status(4, x))

        # ---------------------------------------------------------------------
        #   RADIAL FEATURE FINDER
        # ---------------------------------------------------------------------
        radial_ff = c.radial_ff

        self.radial_ff_bar = atb.Bar(
            name="RadialFF",
            label="Radial Symmetry",
            help="Parameters for initial (symmetry-based) image processing",
            iconified="true",
            position=(30, 30),
            size=(250, 180),
        )

        self.radial_ff_bar.add_var(
            "target_kpixels",
            label="Target kPixels",
            vtype=atb.TW_TYPE_FLOAT,
            min=50.0,
            max=1000.0,
            step=10.0,
            target=radial_ff,
            attr="target_kpixels",
        )
        self.radial_ff_bar.add_var(
            "min_radius_fraction",
            label="Min. radius (fraction)",
            vtype=atb.TW_TYPE_FLOAT,
            min=0.01,
            max=0.5,
            step=0.01,
            target=radial_ff,
            attr="min_radius_fraction",
        )
        self.radial_ff_bar.add_var(
            "max_radius_fraction",
            label="Max. radius (fraction)",
            vtype=atb.TW_TYPE_FLOAT,
            min=0.1,
            max=0.8,
            step=0.01,
            target=radial_ff,
            attr="max_radius_fraction",
        )
        self.radial_ff_bar.add_var(
            "radius_steps",
            label="Radius steps",
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=10,
            step=1,
            target=radial_ff,
            attr="radius_steps",
        )
        self.radial_ff_bar.add_var(
            "alpha", label="Alpha", vtype=atb.TW_TYPE_FLOAT, min=1.0, max=50.0, step=1.0, target=radial_ff, attr="alpha"
        )

        self.radial_ff_bar.add_var(
            "show_transform", label="Show Transform", vtype=atb.TW_TYPE_BOOL8, target=self, attr="show_feature_map"
        )

        self.radial_ff_bar.add_var(
            "Albino/albino_mode_enable",
            label="Mode Enabled",
            vtype=atb.TW_TYPE_BOOL8,
            target=radial_ff,
            attr="albino_mode",
        )
        self.radial_ff_bar.add_var(
            "Albino/albino_threshold",
            label="Threshold",
            vtype=atb.TW_TYPE_FLOAT,
            min=0.1,
            max=50.0,
            step=1.0,
            target=radial_ff,
            attr="albino_threshold",
        )

        self.radial_ff_bar.add_var(
            "RestrictRegion/top",
            label="top",
            vtype=atb.TW_TYPE_UINT32,
            min=0,
            max=300,
            step=1,
            target=radial_ff,
            attr="restrict_top",
        )
        self.radial_ff_bar.add_var(
            "RestrictRegion/left",
            label="left",
            vtype=atb.TW_TYPE_UINT32,
            min=0,
            max=300,
            step=1,
            target=radial_ff,
            attr="restrict_left",
        )

        self.radial_ff_bar.add_var(
            "RestrictRegion/right",
            label="right",
            vtype=atb.TW_TYPE_UINT32,
            min=0,
            max=300,
            step=1,
            target=radial_ff,
            attr="restrict_right",
        )

        self.radial_ff_bar.add_var(
            "RestrictRegion/bottom",
            label="bottom",
            vtype=atb.TW_TYPE_UINT32,
            min=0,
            max=300,
            step=1,
            target=radial_ff,
            attr="restrict_bottom",
        )

        # ---------------------------------------------------------------------
        #   STARBURST FEATURE FINDER
        # ---------------------------------------------------------------------

        self.sb_ff_bar = atb.Bar(
            name="StarburstFF",
            label="Starburst",
            iconified="true",
            help="Parameters for the refinement phase ('starburst') " "image processing",
            position=(40, 40),
            size=(200, 250),
        )

        sb_ff = c.starburst_ff

        self.sb_ff_bar.add_var(
            "Pupil/n_pupil_rays",
            label="n rays",
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=100,
            step=1,
            target=sb_ff,
            attr="pupil_n_rays",
        )

        self.sb_ff_bar.add_var(
            "Pupil/pupil_min_radius",
            label="min radius",
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=100,
            step=1,
            target=sb_ff,
            attr="pupil_min_radius",
        )

        self.sb_ff_bar.add_var(
            "Pupil/pupil_threshold",
            label="edge detect threshold",
            vtype=atb.TW_TYPE_FLOAT,
            min=0.1,
            max=5.0,
            step=0.1,
            target=sb_ff,
            attr="pupil_threshold",
        )

        self.sb_ff_bar.add_var(
            "CR/n_cr_rays",
            label="n rays",
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=100,
            step=1,
            target=sb_ff,
            attr="cr_n_rays",
        )

        self.sb_ff_bar.add_var(
            "CR/cr_min_radius",
            label="min radius",
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=100,
            step=1,
            target=sb_ff,
            attr="cr_min_radius",
        )

        self.sb_ff_bar.add_var(
            "CR/cr_threshold",
            label="edge detect threshold",
            vtype=atb.TW_TYPE_FLOAT,
            min=0.1,
            max=5.0,
            step=0.1,
            target=sb_ff,
            attr="cr_threshold",
        )

        fit_algos = {0: "circle_least_squares", 1: "circle_least_squares_ransac", 2: "ellipse_least_squares"}

        fit_algos_rev = dict([(val, key) for (key, val) in fit_algos.items()])

        FittingAlgorithm = atb.enum("FittingAlgorithm", {"circle lst sq": 0, "circle ransac": 1, "ellipse lst sq": 2})
        self.sb_ff_bar.add_var(
            "Fitting/circle_fit",
            label="circle fit method",
            vtype=FittingAlgorithm,
            getter=lambda: fit_algos_rev[sb_ff.fitting_algorithm],
            setter=lambda x: sb_ff.__dict__.__setitem__("fitting_algorithm", fit_algos[x]),
        )

        self.sb_ff_bar.add_var("Display/show_rays", self.display_starburst)

        # ---------------------------------------------------------------------
        #   CALIBRATION
        # ---------------------------------------------------------------------
        self.cal_bar = atb.Bar(
            name="Calibration",
            label="Calibration",
            iconified="true",
            help="Auto-calibration steps",
            position=(50, 50),
            size=(250, 300),
            refresh=0.5,
        )

        self.cal_bar.add_button("calibrate", lambda: c.calibrate(), label="Calibrate (full)")

        self.cal_bar.add_separator("Sub-phases")
        self.cal_bar.add_button("cal_center_h", lambda: c.calibrate_center_horizontal(), label="Center Horizontal")
        self.cal_bar.add_button("cal_center_v", lambda: c.calibrate_center_vertical(), label="Center Vertical")
        self.cal_bar.add_button("cal_center_d", lambda: c.calibrate_center_depth(), label="Center Depth")
        # self.cal_bar.add_button('align_pupil_cr', lambda: \
        #                        c.calibrate_align_pupil_and_cr(),
        #                        label='Align Pupil and CR')
        self.cal_bar.add_button("cal_pupil_rad", lambda: c.calibrate_find_pupil_radius(), label="Find Pupil Radius")

        self.cal_bar.add_separator("Info")
        self.cal_bar.add_var(
            "d", label="Distance to CR curv. center", vtype=atb.TW_TYPE_FLOAT, target=c.calibrator, attr="d"
        )  # readonly = True,
        self.cal_bar.add_var(
            "Rp", label="Pupil rotation radius (Rp)[mm]", vtype=atb.TW_TYPE_FLOAT, target=c.calibrator, attr="Rp_mm"
        )  # readonly = True,

        # Calibration Files
        try:
            self.refresh_calibration_file_list()

            self.cal_bar.add_separator("Calibration Files")

            self.cal_bar.add_var(
                "current_calibration_file",
                vtype=self.cal_enum,
                label="Calibration File",
                getter=lambda: self.get_calibration_file_atb(),
                setter=lambda x: self.set_calibration_file_atb(x),
            )
            # setter=lambda x: \
            #        sb_ff.__dict__.__setitem__( \
            #        'fitting_algorithm', fit_algos[x]))
            # getter=lambda: \
            #        self.get_calibration_file_atb,
            # setter=lambda x: \
            #        self.set_calibration_file_atb(x))

            self.cal_bar.add_separator("Calibration Save")
            self.cal_file_save_name = ctypes.c_char_p("")

            self.cal_bar.add_var(
                "calibration_file_save_name", vtype=atb.TW_TYPE_CDSTRING, target=self, attr="cal_file_save_name"
            )
            self.cal_bar.add_button("save_calibration", lambda: self.save_calibration_file_atb(self.cal_file_save_name))
        except Exception as E:
            log.warning("Error setting calibration file list: %s" % E)
            log.warning(
                """Unable to use calibration-file saving
                               infrastructure.  A patched version of glumpy
                               is required to enable this feature."""
            )

        # --------------------------------------------------------------------
        #   CAMERA
        # --------------------------------------------------------------------

        self.cam_bar = atb.Bar(
            name="Camera",
            label="Camera",
            iconified="true",
            help="Camera acquisition parameters",
            position=(60, 60),
            size=(200, 180),
        )

        self.cam_bar.add_var(
            "binning", label="binning", vtype=atb.TW_TYPE_UINT32, min=1, max=16, step=1, target=c, attr="binning"
        )

        self.cam_bar.add_var(
            "gain", label="gain", vtype=atb.TW_TYPE_UINT32, min=1, max=16, step=1, target=c, attr="gain"
        )

        self.cam_bar.add_var(
            "exposure",
            label="exposure",
            vtype=atb.TW_TYPE_UINT32,
            min=5000,
            max=30000,
            step=1000,
            target=c,
            attr="exposure",
        )

        self.cam_bar.add_var(
            "ROI/roi_width", label="width", vtype=atb.TW_TYPE_UINT32, min=1, max=800, step=1, target=c, attr="roi_width"
        )

        self.cam_bar.add_var(
            "ROI/roi_height",
            label="height",
            vtype=atb.TW_TYPE_UINT32,
            min=1,
            max=800,
            step=1,
            target=c,
            attr="roi_height",
        )

        self.cam_bar.add_var(
            "ROI/roi_offset_x",
            label="offset x",
            vtype=atb.TW_TYPE_UINT32,
            min=0,
            max=800,
            step=1,
            target=c,
            attr="roi_offset_x",
        )

        self.cam_bar.add_var(
            "ROI/roi_offset_y",
            label="offset y",
            vtype=atb.TW_TYPE_UINT32,
            min=0,
            max=800,
            step=1,
            target=c,
            attr="roi_offset_y",
        )

        # Event Handlers
        def on_init():
            self.tracker_view.prepare_opengl()

        def on_draw():
            self.window.clear()
            self.tracker_view.draw((self.window.width, self.window.height))

        def on_idle(dt):
            # if dt < 0.02:
            #    return
            self.update_tracker_view()
            self.window.draw()

        def on_key_press(symbol, modifiers):
            if symbol == glumpy.key.ESCAPE:
                c.stop_continuous_acquisition()
                log.debug("Controller has %i refs" % sys.getrefcount(c))
                c.release()
                self.controller = None
                log.debug("Controller has %i refs" % sys.getrefcount(c))
                c.shutdown()
                # print "Shutting down controller..."
                # print "Shut down controller", c.shutdown()
                # c.continuously_acquiring = False
                # c.acq_thread.join()
                sys.exit()

        self.window.push_handlers(atb.glumpy.Handlers(self.window))
        self.window.push_handlers(on_init, on_draw, on_key_press, on_idle)
        self.window.draw()