def refresh_calibration_file_list(self):

        # read in saved calibration files
        try:
            cal_path = os.path.expanduser(global_settings['calibration_path'])
        except KeyError:
            logging.warning(
                'A calibration_path was not found in the config file')
            logging.warning('Loaded global settings: %s' % global_settings)

        if not os.path.exists(cal_path):
            os.makedirs(cal_path)

        cal_files = os.listdir(cal_path)
        cal_files = filter(lambda x: re.match(r'.*\.pkl', x), cal_files)

        cal_names = [x.split('.')[0] for x in cal_files]
        cal_names.insert(0, 'None')

        # add back in the rest of the path
        cal_files = [os.path.join(cal_path, x) for x in cal_files]
        cal_files.insert(0, '<none>')

        cal_ids = range(0, len(cal_names))
        self.cal_enum_dict = OrderedDict(zip(cal_names, cal_ids))
        self.cal_lookup_dict = OrderedDict(zip(cal_ids, cal_names))

        logging.debug('Calibration files: %s' % self.cal_enum_dict)
        logging.debug('Calibration lookup: %s' % self.cal_lookup_dict)

        self.cal_enum = atb.enum('CalibrationFile', self.cal_enum_dict)
Exemple #2
0
    def refresh_calibration_file_list(self):

        # read in saved calibration files
        try:
            cal_path = os.path.expanduser(global_settings['calibration_path'])
        except KeyError:
            logging.warning('A calibration_path was not found in the config file')
            logging.warning('Loaded global settings: %s' % global_settings)

        if not os.path.exists(cal_path):
            os.makedirs(cal_path)

        cal_files = os.listdir(cal_path)
        cal_files = filter(lambda x: re.match(r'.*\.pkl', x), cal_files)

        cal_names = [x.split('.')[0] for x in cal_files]
        cal_names.insert(0, 'None')

        # add back in the rest of the path
        cal_files = [os.path.join(cal_path, x) for x in cal_files]
        cal_files.insert(0, '<none>')

        cal_ids = range(0, len(cal_names))
        self.cal_enum_dict = OrderedDict(zip(cal_names, cal_ids))
        self.cal_lookup_dict = OrderedDict(zip(cal_ids, cal_names))

        logging.debug('Calibration files: %s' % self.cal_enum_dict)
        logging.debug('Calibration lookup: %s' % self.cal_lookup_dict)

        self.cal_enum = atb.enum('CalibrationFile', self.cal_enum_dict)
Exemple #3
0
    def refresh_calibration_file_list(self):

        # read in saved calibration files
        try:
            cal_path = os.path.expanduser(global_settings["calibration_path"])
        except KeyError:
            log.warning("A calibration_path was not found in the config file")
            log.warning("Loaded global settings: %s" % global_settings)

        if not os.path.exists(cal_path):
            os.makedirs(cal_path)

        cal_files = os.listdir(cal_path)
        cal_files = filter(lambda x: re.match(r".*\.pkl", x), cal_files)

        cal_names = [x.split(".")[0] for x in cal_files]
        cal_names.insert(0, "None")

        # add back in the rest of the path
        cal_files = [os.path.join(cal_path, x) for x in cal_files]
        cal_files.insert(0, "<none>")

        cal_ids = range(0, len(cal_names))
        self.cal_enum_dict = OrderedDict(zip(cal_names, cal_ids))
        self.cal_lookup_dict = OrderedDict(zip(cal_ids, cal_names))

        log.debug("cal_enum_dict: %s" % (self.cal_enum_dict,))
        log.debug("cal_lookup_dict: %s" % (self.cal_lookup_dict,))

        self.cal_enum = atb.enum("CalibrationFile", self.cal_enum_dict)
Exemple #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()
Exemple #5
0
    fill = c_int(1)
    color = (c_float * 3)(1.0, 1.0, 0.3)
    shape = c_int()
    bar.add_var("Trackball/Phi",
                step=0.5,
                getter=trackball._get_phi,
                setter=trackball._set_phi)
    bar.add_var("Trackball/Theta",
                step=0.5,
                getter=trackball._get_theta,
                setter=trackball._set_theta)
    bar.add_var("Trackball/Zoom",
                step=0.01,
                getter=trackball._get_zoom,
                setter=trackball._set_zoom)
    Shape = atb.enum("Shape", {'Cube': 0, 'Torus': 1, 'Teapot': 2})
    bar.add_var("Object/Shape", shape, vtype=Shape)
    bar.add_var("Object/Fill", fill)
    bar.add_var("Object/Color", color, open=True)
    bar.add_separator("")
    bar.add_button("Quit", quit, key="ESCAPE", help="Quit application")

    def draw_background():
        viewport = gl.glGetIntegerv(gl.GL_VIEWPORT)
        gl.glDisable(gl.GL_LIGHTING)
        gl.glDisable(gl.GL_DEPTH_TEST)
        gl.glBegin(gl.GL_QUADS)
        gl.glColor(1.0, 1.0, 1.0)
        gl.glVertex(0, 0, -1)
        gl.glVertex(viewport[2], 0, -1)
        gl.glColor(0.0, 0.0, 1.0)
Exemple #6
0
    bar = atb.Bar(name="Controls", label="Controls",
                  help="Scene controls", position=(10, 10), size=(200, 340))
    bar.add_var("Trackball/Phi", step=0.5,
                getter=trackball._get_phi, setter=trackball._set_phi)
    bar.add_var("Trackball/Theta", step=0.5,
                getter=trackball._get_theta, setter=trackball._set_theta)
    bar.add_var("Trackball/Zoom", step=0.01,
                getter=trackball._get_zoom, setter=trackball._set_zoom)
    bar.add_var("Light/State", getter=I._get_lighted, setter=I._set_lighted)
    bar.add_var("Light/Position", position, vtype=atb.TW_TYPE_QUAT4F)
    bar.add_var("Light/Diffuse", diffuse)
    bar.add_var("Light/Ambient", ambient)
    bar.add_var("Light/Specular", specular)
    bar.add_var("Object/Elevation", step=0.01,
                getter=I._get_elevation, setter=I._set_elevation)
    bar.add_var("Object/Interpolation", vtype=atb.enum("Interpolation",Interpolation),
                getter=get_interpolation, setter=set_interpolation)
    bar.add_var("Object/Colormap", vtype=atb.enum("Colormap",Colormap),
                getter=get_cmap, setter=set_cmap)
    bar.add_var("Object/Grid/X", vtype = atb.TW_TYPE_FLOAT,
                getter=I._get_gridsize_x, setter=I._set_gridsize_x, min=0)
    bar.add_var("Object/Grid/Y",  vtype = atb.TW_TYPE_FLOAT,
                getter=I._get_gridsize_y, setter=I._set_gridsize_y, min=0)
    bar.add_var("Object/Grid/Z",  vtype = atb.TW_TYPE_FLOAT,
                getter=I._get_gridsize_z, setter=I._set_gridsize_z, min=0)
    bar.add_separator("")
    bar.add_button("Quit", quit, key="ESCAPE", help="Quit application")


    def draw_background():
        viewport = gl.glGetIntegerv(gl.GL_VIEWPORT)
    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()
Exemple #8
0
    atb.init()
    window = glumpy.Window(600, 600)
    trackball = glumpy.Trackball(45,135,1.25,4)
    bar = atb.Bar(name="Controls", label="Controls",
                  help="Scene controls", position=(10, 10), size=(200, 320))

    fill = c_int(1)
    color = (c_float * 3)(1.0,1.0,0.3)
    shape = c_int()
    bar.add_var("Trackball/Phi", step=0.5,
                getter=trackball._get_phi, setter=trackball._set_phi)
    bar.add_var("Trackball/Theta", step=0.5,
                getter=trackball._get_theta, setter=trackball._set_theta)
    bar.add_var("Trackball/Zoom", step=0.01,
                getter=trackball._get_zoom, setter=trackball._set_zoom)
    Shape = atb.enum("Shape", {'Cube':0, 'Torus':1, 'Teapot':2})
    bar.add_var("Object/Shape", shape, vtype=Shape)
    bar.add_var("Object/Fill", fill)
    bar.add_var("Object/Color", color, open=True)
    bar.add_separator("")
    bar.add_button("Quit", quit, key="ESCAPE", help="Quit application")


    def draw_background():
        viewport = gl.glGetIntegerv(gl.GL_VIEWPORT)
        gl.glDisable (gl.GL_LIGHTING)
        gl.glDisable (gl.GL_DEPTH_TEST);
        gl.glBegin(gl.GL_QUADS)
        gl.glColor(1.0,1.0,1.0)
        gl.glVertex(0,0,-1)
        gl.glVertex(viewport[2],0,-1)
    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()
Exemple #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.,
            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()
Exemple #11
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()