diff --git a/pupil_src/launchables/world.py b/pupil_src/launchables/world.py index 31f9b8ebe2..8496e91034 100644 --- a/pupil_src/launchables/world.py +++ b/pupil_src/launchables/world.py @@ -114,6 +114,7 @@ def world(timebase, eyes_are_alive, ipc_pub_url, ipc_sub_url, from remote_recorder import Remote_Recorder from audio_capture import Audio_Capture from accuracy_visualizer import Accuracy_Visualizer + from dialation_history import Dialation_History # UI Platform tweaks if platform.system() == 'Linux': @@ -152,7 +153,7 @@ def get_timestamp(): manager_classes += [p for p in runtime_plugins if issubclass(p, Base_Manager)] runtime_plugins = [p for p in runtime_plugins if not issubclass(p, Base_Manager)] user_launchable_plugins = [Audio_Capture, Pupil_Groups, Frame_Publisher, Pupil_Remote, Time_Sync, Surface_Tracker, - Annotation_Capture, Log_History, Fixation_Detector, + Annotation_Capture, Log_History, Fixation_Detector, Dialation_History, Blink_Detection, Remote_Recorder, Accuracy_Visualizer] + runtime_plugins system_plugins = [Log_Display, Display_Recent_Gaze, Recorder, Pupil_Data_Relay] plugin_by_index = (system_plugins + user_launchable_plugins + calibration_plugins diff --git a/pupil_src/shared_modules/dialation_history.py b/pupil_src/shared_modules/dialation_history.py new file mode 100644 index 0000000000..2ec9d5d1e3 --- /dev/null +++ b/pupil_src/shared_modules/dialation_history.py @@ -0,0 +1,88 @@ +''' +(*)~--------------------------------------------------------------------------- +Pupil - eye tracking platform +Copyright (C) 2012-2017 Pupil Labs + +Distributed under the terms of the GNU +Lesser General Public License (LGPL v3.0). +See COPYING and COPYING.LESSER for license details. +---------------------------------------------------------------------------~(*) +''' + +import logging +import glfw +from collections import deque +from plugin import Plugin +from pyglui import ui, graph + +import gl_utils + +# logging +logger = logging.getLogger(__name__) +logger.setLevel(logging.DEBUG) + + +class Dialation_History(Plugin): + """Pupil dialation visualization + + This plugin uses the 3d model's pupil diameter + and displays it in a graph for each eye. + """ + order = .9 + + def __init__(self, g_pool): + super().__init__(g_pool) + self.graphs = () + self.menu = None + + def init_gui(self): + eye0_graph = graph.Bar_Graph(min_val=.0, max_val=5.) + eye0_graph.pos = (140, 230) + eye0_graph.update_rate = 5 + eye0_graph.label = "id0 dia: %0.2f" + + eye1_graph = graph.Bar_Graph(min_val=.0, max_val=5.) + eye1_graph.pos = (260, 230) + eye1_graph.update_rate = 5 + eye1_graph.label = "id0 dia: %0.2f" + + self.graphs = eye0_graph, eye1_graph + self.on_window_resize(self.g_pool.main_window, *glfw.glfwGetFramebufferSize(self.g_pool.main_window)) + + def close(): + self.alive = False + + self.menu = ui.Growing_Menu('Dialation History') + self.menu.collapsed = True + self.menu.append(ui.Button('Close', close)) + self.menu.append(ui.Info_Text('Displays the recent pupil dialation in millimeters for each eye.')) + self.g_pool.sidebar.append(self.menu) + + def recent_events(self, events): + for p in events['pupil_positions']: + diam = p.get('diameter_3d', 0.) + if diam > 0. and p['confidence'] > 0.6: + self.graphs[p['id']].add(diam) + + def gl_display(self): + for g in self.graphs: + g.draw() + + def on_window_resize(self, window, w, h): + if gl_utils.is_window_visible(window): + hdpi_factor = float(glfw.glfwGetFramebufferSize(window)[0] / glfw.glfwGetWindowSize(window)[0]) + for g in self.graphs: + g.scale = hdpi_factor + g.adjust_window_size(w, h) + + def get_init_dict(self): + return {} + + def deinit_ui(self): + self.graphs = () + self.g_pool.sidebar.remove(self.menu) + self.menu = None + + def cleanup(self): + if self.menu: + self.deinit_ui()