gaze  0.1.0
Perform gaze tracking with common webcams.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
Public Member Functions | List of all members
gaze::gui::DebugWindow Class Referencefinal

A window to inspect computation results. More...

#include "gaze/gui/debug_window.h"

Inheritance diagram for gaze::gui::DebugWindow:

Public Member Functions

void process_data (int idx=-1)
 
 DebugWindow (Pipeline *pipeline)
 
void on_user_event (void *event_data, int event_type) override
 

Detailed Description

A window to inspect computation results.

Definition at line 22 of file debug_window.h.

Constructor & Destructor Documentation

gaze::gui::DebugWindow::DebugWindow ( Pipeline pipeline)
explicit

Creates a DebugWindow.

Parameters
pipelineThe pipeline to inspect.

Definition at line 22 of file debug_window.cpp.

References gaze::gui::EventManager::instance(), process_data(), std::vector< _Tp, _Alloc >::push_back(), and gaze::gui::EventManager::subscribe().

23  : dlib::drawable_window(false, false),
24  pause_button(*this),
25  paused(false),
26  pipeline(pipeline),
27  pipeline_steps(pipeline->get_steps()),
28  pipeline_tabs(*this),
29  statistics_widget(*this) {
30  this->set_size(this->w_width, this->w_height);
31  this->set_title("GazeTracker DebugWindow");
32 
33  this->pause_button.set_pos(this->w_margin, this->w_margin);
34  this->pause_button.set_name("Pause");
35  this->pause_button.set_click_handler([this]() {
36  this->paused ^= true;
37  });
38 
39  this->statistics_widget.set_pos(
40  this->w_margin,
41  this->pause_button.bottom() + this->w_margin);
42  this->statistics_widget.set_size(
43  this->stat_width,
44  this->w_height - 3 * this->w_margin - this->pause_button.height());
45  this->statistics_widget.set_grid_size(this->pipeline_steps.size() + 1, 2);
46  this->statistics_widget.set_text(0, 0, "Pipeline step");
47  this->statistics_widget.set_text(0, 1,
48  dlib::convert_utf8_to_utf32("Execution time (\u00B5s)"));
49  for (auto row = decltype(this->statistics_widget.number_of_rows()){0};
50  row < this->statistics_widget.number_of_rows();
51  ++row) {
52  for (auto col = decltype(this->statistics_widget.number_of_columns()){0};
53  col < this->statistics_widget.number_of_columns();
54  ++col) {
55  this->statistics_widget.set_editable(row, col, false);
56  }
57  }
58 
59  this->pipeline_tabs.set_pos(this->statistics_widget.right() + this->w_margin,
60  this->pause_button.bottom() + this->w_margin);
61  this->pipeline_tabs.set_size(this->w_width - 3 * this->w_margin
62  - this->stat_width,
63  this->w_height - 3 * this->w_margin
64  - this->pause_button.height());
65  this->pipeline_tabs.set_number_of_tabs(
66  this->pipeline_steps.size() > 0 ? this->pipeline_steps.size() : 1);
67  this->pipeline_tabs.set_click_handler([this](auto new_idx, auto)
68  -> void {
69  this->process_data(new_idx);
70  });
71 
72  int width = this->pipeline_tabs.width() - 3 * this->w_margin;
73  int height = this->pipeline_tabs.height() - 3 * this->w_margin
74  - this->pause_button.height();
75  for (auto i = decltype(this->pipeline_steps.size()){0};
76  i < this->pipeline_steps.size(); ++i) {
78  if (VisualizeableBase* step =
79  dynamic_cast<VisualizeableBase*>(this->pipeline_steps[i])) {
80  widget = step->init(*this, width, height);
81  } else {
82  std::shared_ptr<dlib::label> tmp(new dlib::label(*this));
83  tmp->set_text("No visualization.");
84  widget = tmp;
85  }
86 
87  // Create widget group, add widget to it
88  std::shared_ptr<dlib::widget_group> widget_group_ptr(
89  new dlib::widget_group(*this));
90  this->widgets.push_back(widget_group_ptr);
91  widget_group_ptr->add(*widget.get(), this->w_margin, this->w_margin);
92 
93  // Assign name and add widget group to tab
94  this->pipeline_tabs.set_tab_name(i, this->pipeline_steps[i]->get_name());
95  this->pipeline_tabs.set_tab_group(i, *widget_group_ptr.get());
96 
97  // Assign name to statistics widget
98  this->statistics_widget.set_text(i + 1, 0,
99  this->pipeline_steps[i]->get_name());
100  }
101 
102  this->show();
103  if (this->pipeline_steps.size() > 0) {
105  }
106 }
static EventManager & instance()
void process_data(int idx=-1)
std::vector< PipelineStep * > get_steps()
Definition: pipeline.cpp:74
void push_back(const value_type &__x)
void subscribe(dlib::base_window *subscriber)

Member Function Documentation

void gaze::gui::DebugWindow::on_user_event ( void *  event_data,
int  event_type 
)
override

Checks the event type (

See Also
Events) and handles events.
Parameters
event_datadata passed along with the event.
event_typethe event type (
See Also
Events).

Definition at line 140 of file debug_window.cpp.

References gaze::Pipeline::get_data(), and process_data().

140  {
141  switch (event_type) {
142  case Events::PIPELINE_DATA_UPDATED:
143  if (this->paused) {
144  break;
145  }
146  this->data = this->pipeline->get_data();
147  this->process_data();
148  break;
149  }
150 }
void process_data(int idx=-1)
util::Data get_data()
Definition: pipeline.cpp:69
void gaze::gui::DebugWindow::process_data ( int  idx = -1)

Processes the data to be visualized.

Calls the visualize function of the PipelineStep of the active tab.

Parameters
idx(Optional): If this is a value other than -1, the tab with this index is updated instead of the current tab.

Definition at line 120 of file debug_window.cpp.

References gaze::util::Data::execution_times, and std::basic_ostringstream< _CharT, _Traits, _Alloc >::str().

Referenced by DebugWindow(), and on_user_event().

120  {
121  idx = idx < 0 ? this->pipeline_tabs.selected_tab() : idx;
122 
123  if (this->pipeline_steps.size() == 0) {
124  return;
125  }
126 
127  if (VisualizeableBase* step =
128  dynamic_cast<VisualizeableBase*>(this->pipeline_steps[idx])) {
129  step->visualize(this->data);
130  }
131 
132  for (auto i = decltype(this->pipeline_steps.size()){1};
133  i <= this->pipeline_steps.size(); ++i) {
135  os << this->data.execution_times[this->pipeline_steps[i - 1]->get_name()];
136  this->statistics_widget.set_text(i, 1, os.str());
137  }
138 }
std::map< std::string, double > execution_times
Definition: data.h:111
__string_type str() const

The documentation for this class was generated from the following files: