gaze  0.1.0
Perform gaze tracking with common webcams.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
visualizeable.h
1 #ifndef INCLUDE_GAZE_GUI_VISUALIZEABLE_H_
2 #define INCLUDE_GAZE_GUI_VISUALIZEABLE_H_
3 
4 #include <memory>
5 #include <string>
6 
7 #include "dlib/gui_widgets.h"
8 
9 #include "gaze/util/data.h"
10 
11 
12 namespace gaze {
13 
18 namespace gui {
19 
27 namespace traits {
28 
30 
34 struct sizeable {};
35 
40 struct textable {};
42 
44 
50 template<typename widget_type>
51 struct widget_trait;
52 
59 template<> struct widget_trait<dlib::label> {
63  typedef textable tag;
64 };
65 
72 template<> struct widget_trait<dlib::image_display> {
76  typedef sizeable tag;
77 };
78 
85 template<> struct widget_trait<dlib::perspective_display> {
89  typedef sizeable tag;
90 };
92 
93 } // namespace traits
94 
96 
107 template<typename widget_type>
108 void adjust_widget(std::shared_ptr<widget_type> widget,
109  int width, int height, std::string, traits::sizeable) {
110  widget->set_size(width, height);
111 }
112 
124 template<typename widget_type>
125 void adjust_widget(std::shared_ptr<widget_type> widget,
126  int, int, std::string text, traits::textable) {
127  widget->set_text(text);
128 }
129 
139 template<typename widget_type>
140 void adjust_widget(std::shared_ptr<widget_type> widget,
141  int width, int height, std::string text) {
142  adjust_widget(widget, width, height, text,
143  typename traits::widget_trait<widget_type>::tag());
144 }
146 
155 template<typename widget_type>
156 // NOLINTNEXTLINE
157 std::shared_ptr<widget_type> create_widget(dlib::drawable_window& parent) {
158  return std::shared_ptr<widget_type>(new widget_type(parent));
159 }
160 
171  public:
175  virtual ~VisualizeableBase() = default;
176 
191  dlib::drawable_window& parent, // NOLINT
192  int width, int height,
193  std::string text = "No visualization.") = 0;
194 
198  virtual void remove_widget() {}
199 
210  virtual void visualize(util::Data& data) = 0; // NOLINT
211 };
212 
222 template<typename widget_type = dlib::label>
224  protected:
229 
230  public:
231  virtual ~Visualizeable() = default;
232 
234  dlib::drawable_window& parent, // NOLINT
235  int width, int height,
236  std::string text = "No visualization.") final {
237  widget = create_widget<widget_type>(parent);
238  adjust_widget<widget_type>(widget, width, height, text);
239  return widget;
240  }
241 
245  void remove_widget() override {
246  if (this->widget && this->widget.get()) {
247  this->widget->disable();
248  }
249  this->widget = std::shared_ptr<widget_type>(nullptr);
250  }
251 };
252 
256 typedef Visualizeable<dlib::label> LabelVisualizeable;
257 
261 typedef Visualizeable<dlib::image_display> ImageVisualizeable;
262 
266 typedef Visualizeable<dlib::perspective_display> PerspectiveVisualizeable;
267 
268 } // namespace gui
269 
270 } // namespace gaze
271 
272 #endif // INCLUDE_GAZE_GUI_VISUALIZEABLE_H_
std::shared_ptr< widget_type > widget
A tag for resizeable widgets.
Definition: visualizeable.h:34
virtual std::shared_ptr< dlib::drawable > init(dlib::drawable_window &parent, int width, int height, std::string text="No visualization.")=0
Abstract base class for Visualizeable to allow generic pointers.
void remove_widget() override
Template to assign tags to widgets as a trait.
Definition: visualizeable.h:51
std::shared_ptr< dlib::drawable > init(dlib::drawable_window &parent, int width, int height, std::string text="No visualization.") final
Implements VisualizeableBase for several widget types.
A tag for widgets which contain text messages.
Definition: visualizeable.h:40
virtual void visualize(util::Data &data)=0
virtual ~VisualizeableBase()=default
Wraps the data acquired per frame into a single instance.
Definition: data.h:27