Esempio n. 1
0
    def draw_sections(self, width, height, scale):
        t0, t1 = self.g_pool.timestamps[0], self.g_pool.timestamps[-1]
        pixel_to_time_fac = height / (t1 - t0)
        with gl_utils.Coord_System(t0, t1, height, 0):
            gl.glTranslatef(0, 0.001 + scale * self.timeline_line_height / 2, 0)
            for s in self.sections:
                color = RGBA(1., 1., 1., .5)
                if s['calibration_method'] == "natural_features":
                    draw_x([(m['timestamp'], 0) for m in self.manual_ref_positions],
                           height=12, width=3 * pixel_to_time_fac, thickness=scale, color=color)
                else:
                    draw_bars([(m['timestamp'], 0) for m in self.circle_marker_positions],
                              height=12, thickness=scale, color=color)
                cal_slc = slice(*s['calibration_range'])
                map_slc = slice(*s['mapping_range'])
                cal_ts = self.g_pool.timestamps[cal_slc]
                map_ts = self.g_pool.timestamps[map_slc]


                color = RGBA(*s['color'])
                if len(cal_ts):
                    draw_polyline([(cal_ts[0], 0), (cal_ts[-1], 0)], color=color,
                                  line_type=gl.GL_LINES, thickness=8*scale)
                if len(map_ts):
                    draw_polyline([(map_ts[0], 0), (map_ts[-1], 0)], color=color,
                                  line_type=gl.GL_LINES, thickness=2*scale)
                gl.glTranslatef(0, scale * self.timeline_line_height, 0)
    def gl_display(self):
        # normalize coordinate system, no need this step in utility functions
        with gl_utils.Coord_System(0, 1, 0, 1):
            ref_point_norm = [r['norm_pos'] for r in self.circle_marker_positions
                              if self.g_pool.capture.get_frame_index() == r['index']]
            cygl_utils.draw_points(ref_point_norm, size=35, color=cygl_utils.RGBA(0, .5, 0.5, .7))
            cygl_utils.draw_points(ref_point_norm, size=5, color=cygl_utils.RGBA(.0, .9, 0.0, 1.0))

            manual_refs_in_frame = [r for r in self.manual_ref_positions
                                    if self.g_pool.capture.get_frame_index() in r['index_range']]
            current = self.g_pool.capture.get_frame_index()
            for mr in manual_refs_in_frame:
                if mr['index'] == current:
                    cygl_utils.draw_points([mr['norm_pos']], size=35, color=cygl_utils.RGBA(.0, .0, 0.9, .8))
                    cygl_utils.draw_points([mr['norm_pos']], size=5, color=cygl_utils.RGBA(.0, .9, 0.0, 1.0))
                else:
                    distance = abs(current - mr['index'])
                    range_radius = (mr['index_range'][-1] - mr['index_range'][0]) // 2
                    # scale alpha [.1, .9] depending on distance to current frame
                    alpha = distance / range_radius
                    alpha = 0.1 * alpha + 0.9 * (1. - alpha)
                    # Use draw_progress instead of draw_circle. draw_circle breaks
                    # because of the normalized coord-system.
                    cygl_utils.draw_progress(mr['norm_pos'], 0., 0.999,
                                             inner_radius=20.,
                                             outer_radius=35.,
                                             color=cygl_utils.RGBA(.0, .0, 0.9, alpha))
                    cygl_utils.draw_points([mr['norm_pos']], size=5, color=cygl_utils.RGBA(.0, .9, 0.0, alpha))

        # calculate correct timeline height. Triggers timeline redraw only if changed
        self.timeline.content_height = max(0.001, self.timeline_line_height * len(self.sections))
Esempio n. 3
0
    def draw_activation(self, width, height, scale):
        t0, t1 = self.g_pool.timestamps[0], self.g_pool.timestamps[-1]
        response_points = tuple(zip(self.timestamps, self.filter_response))
        if len(response_points) == 0:
            return

        class_points = deque([(t0, -.9)])
        for b in self.g_pool.blinks:
            class_points.append((b['start_timestamp'], -.9))
            class_points.append((b['start_timestamp'], .9))
            class_points.append((b['end_timestamp'], .9))
            class_points.append((b['end_timestamp'], -.9))
        class_points.append((t1, -.9))

        thresholds = [(t0, self.onset_confidence_threshold),
                      (t1, self.onset_confidence_threshold),
                      (t0, -self.offset_confidence_threshold),
                      (t1, -self.offset_confidence_threshold)]

        with gl_utils.Coord_System(t0, t1, -1, 1):
            draw_polyline(response_points,
                          color=RGBA(0.6602, 0.8594, 0.4609, 0.8),
                          line_type=gl.GL_LINE_STRIP,
                          thickness=1 * scale)
            draw_polyline(class_points,
                          color=RGBA(0.9961, 0.3789, 0.5313, 0.8),
                          line_type=gl.GL_LINE_STRIP,
                          thickness=1 * scale)
            draw_polyline(thresholds,
                          color=RGBA(0.9961, 0.8438, 0.3984, 0.8),
                          line_type=gl.GL_LINES,
                          thickness=1 * scale)
Esempio n. 4
0
 def draw_fps(self, width, height, scale):
     with gl_utils.Coord_System(*self.cache['xlim'], *self.cache['ylim']):
         if self.show_world_fps:
             draw_points(self.cache['world'], size=2*scale, color=world_color)
         if self.show_eye_fps:
             draw_points(self.cache['eye0'], size=2*scale, color=right_color)
             draw_points(self.cache['eye1'], size=2*scale, color=left_color)
Esempio n. 5
0
 def draw_sections(self, width, height, scale):
     max_ts = len(self.g_pool.timestamps)
     with gl_utils.Coord_System(0, max_ts, height, 0):
         gl.glTranslatef(0, 0.001 + scale * self.timeline_line_height / 2,
                         0)
         for s in self.sections:
             color = RGBA(1., 1., 1., .5)
             if s['calibration_method'] == "natural_features":
                 draw_x([(m['index'], 0)
                         for m in self.manual_ref_positions],
                        size=12,
                        thickness=2 * scale,
                        color=color)
             else:
                 draw_bars([(m['index'], 0)
                            for m in self.circle_marker_positions],
                           height=12,
                           thickness=scale,
                           color=color)
             cal_slc = slice(*s['calibration_range'])
             map_slc = slice(*s['mapping_range'])
             color = RGBA(*s['color'])
             draw_polyline([(cal_slc.start, 0), (cal_slc.stop, 0)],
                           color=color,
                           line_type=gl.GL_LINES,
                           thickness=8 * scale)
             draw_polyline([(map_slc.start, 0), (map_slc.stop, 0)],
                           color=color,
                           line_type=gl.GL_LINES,
                           thickness=2 * scale)
             gl.glTranslatef(0, scale * self.timeline_line_height, 0)
Esempio n. 6
0
    def gl_display_cache_bars(self, width, height, scale):
        """
        """
        with gl_utils.Coord_System(0, self.cache.length - 1, height, 0):
            # Lines for areas that have been cached
            cached_ranges = []
            for r in self.cache.visited_ranges:  # [[0,1],[3,4]]
                cached_ranges += (r[0], 0), (r[1], 0
                                             )  # [(0,0),(1,0),(3,0),(4,0)]

            glTranslatef(0, scale * self.timeline_line_height / 2, 0)
            color = RGBA(.8, .6, .2, .8)
            draw_polyline(cached_ranges,
                          color=color,
                          line_type=GL_LINES,
                          thickness=scale * 4)

            # Lines where surfaces have been found in video
            cached_surfaces = []
            for s in self.surfaces:
                found_at = []
                if s.cache is not None:
                    for r in s.cache.positive_ranges:  # [[0,1],[3,4]]
                        found_at += (r[0], 0), (r[1], 0
                                                )  # [(0,0),(1,0),(3,0),(4,0)]
                    cached_surfaces.append(found_at)

            color = RGBA(0, .7, .3, .8)

            for s in cached_surfaces:
                glTranslatef(0, scale * self.timeline_line_height, 0)
                draw_polyline(s,
                              color=color,
                              line_type=GL_LINES,
                              thickness=scale * 2)
    def draw_sections(self, width, height, scale):
        t0, t1 = self.g_pool.timestamps[0], self.g_pool.timestamps[-1]
        pixel_to_time_fac = height / (t1 - t0)
        with gl_utils.Coord_System(t0, t1, height, 0):
            gl.glTranslatef(0, 0.001 + scale * self.timeline_line_height / 2, 0)
            for s in self.sections:
                cal_slc = slice(*s['calibration_range'])
                map_slc = slice(*s['mapping_range'])
                cal_ts = self.g_pool.timestamps[cal_slc]
                map_ts = self.g_pool.timestamps[map_slc]

                color = cygl_utils.RGBA(*s['color'][:3], 1.)
                if len(cal_ts):
                    cygl_utils.draw_rounded_rect((cal_ts[0], -4 * scale),
                                      (cal_ts[-1] - cal_ts[0], 8 * scale),
                                      corner_radius=0,
                                      color=color,
                                      sharpness=1.)
                if len(map_ts):
                    cygl_utils.draw_rounded_rect((map_ts[0], -scale),
                                      (map_ts[-1] - map_ts[0], 2 * scale),
                                      corner_radius=0,
                                      color=color,
                                      sharpness=1.)

                color = cygl_utils.RGBA(1., 1., 1., .5)
                if s['calibration_method'] == "natural_features":
                    cygl_utils.draw_x([(m['timestamp'], 0) for m in self.manual_ref_positions],
                           height=12 * scale, width=3 * pixel_to_time_fac / scale, thickness=scale, color=color)
                else:
                    cygl_utils.draw_bars([(m['timestamp'], 0) for m in self.circle_marker_positions],
                              height=12 * scale, thickness=scale, color=color)

                gl.glTranslatef(0, scale * self.timeline_line_height, 0)
Esempio n. 8
0
    def draw_pupil_data(self, key, width, height, scale):
        right = self.cache[key]['right']
        left = self.cache[key]['left']

        with gl_utils.Coord_System(*self.cache[key]['xlim'], *self.cache[key]['ylim']):
            draw_points(right, size=2.*scale, color=right_color)
            draw_points(left, size=2.*scale, color=left_color)
Esempio n. 9
0
 def draw_sections(self, width, height, scale):
     with gl_utils.Coord_System(
         left=self._time_start, right=self._time_end, bottom=height, top=0
     ):
         self._translate_to_vertical_center_of_row(scale)
         for row in self._rows:
             self._draw_row(row, height, scale)
             self._translate_to_next_row(scale)
Esempio n. 10
0
 def draw_activation(self, width, height, scale):
     t0, t1 = self.g_pool.timestamps[0], self.g_pool.timestamps[-1]
     with gl_utils.Coord_System(t0, t1, -1, 1):
         draw_polyline(self.cache['response_points'], color=activity_color,
                       line_type=gl.GL_LINE_STRIP, thickness=scale)
         draw_polyline(self.cache['class_points'], color=blink_color,
                       line_type=gl.GL_LINE_STRIP, thickness=scale)
         draw_polyline(self.cache['thresholds'], color=threshold_color,
                       line_type=gl.GL_LINES, thickness=scale)
Esempio n. 11
0
    def draw_pupil_data(self, key, width, height, scale):
        right = self.cache[key]["right"]
        left = self.cache[key]["left"]

        with gl_utils.Coord_System(*self.cache[key]["xlim"], *self.cache[key]["ylim"]):
            cygl_utils.draw_points(
                right, size=2.0 * scale, color=COLOR_LEGEND_EYE_RIGHT
            )
            cygl_utils.draw_points(left, size=2.0 * scale, color=COLOR_LEGEND_EYE_LEFT)
Esempio n. 12
0
 def draw_data(self, width, height, scale, channel):
     with gl_utils.Coord_System(*self.cache["xlim"], *self.cache["ylim"]):
         channels = np.shape(self.cache["data"])[1]
         for i in range(channels):
             channel_data =np.reshape(self.cache["data"][:,channel],(-1)).tolist()
             whole_data = tuple(zip(channel_data, self.timestamps))
             if len(channel_data) ==1:
                 return
             cygl_utils.draw_points(
                 whole_data, size=2 * scale, color=COLOR_LEGEND_WORLD
             )
    def draw_pupil_data(self, key, width, height, scale):
        right = self.cache[key]['right']
        left = self.cache[key]['left']

        with gl_utils.Coord_System(*self.cache[key]['xlim'],
                                   *self.cache[key]['ylim']):
            cygl_utils.draw_points(right,
                                   size=2. * scale,
                                   color=COLOR_LEGEND_EYE_RIGHT)
            cygl_utils.draw_points(left,
                                   size=2. * scale,
                                   color=COLOR_LEGEND_EYE_LEFT)
Esempio n. 14
0
 def draw_fps(self, width, height, scale):
     with gl_utils.Coord_System(*self.cache["xlim"], *self.cache["ylim"]):
         if self.show_world_fps:
             cygl_utils.draw_points(self.cache["world"],
                                    size=2 * scale,
                                    color=COLOR_LEGEND_WORLD)
         if self.show_eye_fps:
             cygl_utils.draw_points(self.cache["eye0"],
                                    size=2 * scale,
                                    color=COLOR_LEGEND_EYE_RIGHT)
             cygl_utils.draw_points(self.cache["eye1"],
                                    size=2 * scale,
                                    color=COLOR_LEGEND_EYE_LEFT)
Esempio n. 15
0
    def draw_pupil_data(self, key, width, height, scale):
        if not self.g_pool.pupil_positions:
            return

        t0, t1 = self.g_pool.timestamps[0], self.g_pool.timestamps[-1]
        right = [(pp['timestamp'], pp[key]) for pp in self.g_pool.pupil_positions if pp['id'] == 0]
        left = [(pp['timestamp'], pp[key]) for pp in self.g_pool.pupil_positions if pp['id'] == 1]

        # max_val must not be 0, else gl will crash
        max_val = max(chain((pp[1] for pp in right), (pp[1] for pp in left))) or 1

        with gl_utils.Coord_System(t0, t1, 0, max_val):
            draw_points(right, size=2.*scale, color=right_color)
            draw_points(left, size=2.*scale, color=left_color)
Esempio n. 16
0
    def draw_data(self, width, height, scale):

        if len(self.x[self.channel]) == 0:
            return

        x = self.x[self.channel] - self.x[self.channel][0]
        xlim = [min(x), max(x) + 0.01]
        ylim = [min(self.y[self.channel]), max(self.y[self.channel]) + 0.00001]

        with gl_utils.Coord_System(*xlim, *ylim):
            whole_data = tuple(
                zip(self.x[self.channel] - self.x[self.channel][0],
                    self.y[self.channel]))
            cygl_utils.draw_points(whole_data,
                                   size=2 * scale,
                                   color=COLOR_LEGEND_WORLD)
Esempio n. 17
0
 def _draw_grouped(self, data, keys, y_limits, width, height, scale):
     ts_min = self.g_pool.timestamps[0]
     ts_max = self.g_pool.timestamps[-1]
     data_raw = data[keys]
     sub_samples = np.linspace(
         0,
         self.data_len - 1,
         min(self.NUMBER_SAMPLES_TIMELINE, self.data_len),
         dtype=int,
     )
     with gl_utils.Coord_System(ts_min, ts_max, *y_limits):
         for key in keys:
             data_keyed = data_raw[key]
             if data_keyed.shape[0] == 0:
                 continue
             points = list(zip(self.data_ts[sub_samples], data_keyed[sub_samples]))
             cygl_utils.draw_points(points, size=1.5 * scale, color=self.CMAP[key])
Esempio n. 18
0
    def _timeline_draw_data_cb(self, width, height, scale):
        ts = self.g_pool.timestamps
        with gl_utils.Coord_System(ts[0], ts[-1], height, 0):
            # Lines for areas that have been cached
            cached_ranges = []
            for r in self.marker_cache.visited_ranges:
                cached_ranges += ((ts[r[0]], 0), (ts[r[1]], 0))

            gl.glTranslatef(0, scale * self.TIMELINE_LINE_HEIGHT / 2, 0)
            color = pyglui_utils.RGBA(0.8, 0.2, 0.2, 0.8)
            pyglui_utils.draw_polyline(cached_ranges,
                                       color=color,
                                       line_type=gl.GL_LINES,
                                       thickness=scale * 4)
            cached_ranges = []
            for r in self.marker_cache.positive_ranges:
                cached_ranges += ((ts[r[0]], 0), (ts[r[1]], 0))

            color = pyglui_utils.RGBA(0, 0.7, 0.3, 0.8)
            pyglui_utils.draw_polyline(cached_ranges,
                                       color=color,
                                       line_type=gl.GL_LINES,
                                       thickness=scale * 4)

            # Lines where surfaces have been found in video
            cached_surfaces = []
            for surface in self.surfaces:
                found_at = []
                if surface.location_cache is not None:
                    for r in surface.location_cache.positive_ranges:  # [[0,1],[3,4]]
                        found_at += ((ts[r[0]], 0), (ts[r[1]], 0))
                cached_surfaces.append(found_at)

            color = pyglui_utils.RGBA(0, 0.7, 0.3, 0.8)

            for surface in cached_surfaces:
                gl.glTranslatef(0, scale * self.TIMELINE_LINE_HEIGHT, 0)
                pyglui_utils.draw_polyline(surface,
                                           color=color,
                                           line_type=gl.GL_LINES,
                                           thickness=scale * 2)
Esempio n. 19
0
 def draw_audio(self, width, height, scale):
     with gl_utils.Coord_System(*self.xlim, *self.ylim):
         draw_bars_buffer(self.audio_viz_data, color=viz_color)
Esempio n. 20
0
 def draw_audio(self, width, height, scale):
     if self.audio_viz_data is None:
         return
     with gl_utils.Coord_System(*self.xlim, *self.ylim):
         pyglui_utils.draw_bars_buffer(self.audio_viz_data, color=viz_color)
 def _frame_coordinate_system(self):
     return gl_utils.Coord_System(left=0,
                                  right=self._frame_size[0],
                                  bottom=self._frame_size[1],
                                  top=0)