gaze  0.1.0
Perform gaze tracking with common webcams.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
pipeline.cpp
1 #include "gaze/pipeline.h"
2 
3 #include <shared_mutex> // NOLINT
4 #include <string>
5 #include <thread> // NOLINT
6 #include <utility>
7 #include <vector>
8 
9 #include "gaze/gui/event_manager.h"
10 #include "gaze/pipeline_step.h"
11 #include "gaze/util/data.h"
12 
13 
14 namespace gaze {
15 
16 void Pipeline::operator()() {
17  while (!this->running) {
19  }
20  while (this->running) {
21  // Process
22  util::Data data;
23  for (PipelineStep* step : this->steps) {
24  std::chrono::high_resolution_clock::time_point start =
25  std::chrono::high_resolution_clock::now();
26 
27  step->process(data);
28 
29  std::chrono::high_resolution_clock::time_point end =
30  std::chrono::high_resolution_clock::now();
31  data.execution_times.insert(
33  step->get_name(),
35  end - start).count()));
36  }
37  { // Update data (locked)
38  std::unique_lock<std::shared_mutex> lock(this->data_access_mutex);
39  this->current_data = data;
40  }
41  // Notify EventManager that the data was updated.
43  gui::Events::PIPELINE_DATA_UPDATED);
44  }
45 }
46 
48  const bool start) : steps(steps) {
49  this->thread = new std::thread(&Pipeline::operator(), std::ref(*this));
50  if (start) {
51  this->start();
52  }
53 }
54 
56  this->stop();
57  this->thread->join();
58  delete this->thread;
59 }
60 
62  this->running = true;
63 }
64 
66  this->running = false;
67 }
68 
70  std::shared_lock<std::shared_mutex> lock(this->data_access_mutex);
71  return this->current_data;
72 }
73 
75  return this->steps;
76 }
77 
78 } // namespace gaze
static EventManager & instance()
iterator_traits< _InputIterator >::difference_type count(_InputIterator __first, _InputIterator __last, const _Tp &__value)
void publish(void *data, Events event)
void start()
Definition: pipeline.cpp:61
std::vector< PipelineStep * > get_steps()
Definition: pipeline.cpp:74
util::Data get_data()
Definition: pipeline.cpp:69
Pipeline(std::vector< PipelineStep * > steps, const bool start=true)
Definition: pipeline.cpp:47
void lock(_L1 &__l1, _L2 &__l2, _L3 &...__l3)
constexpr enable_if< __is_duration< _ToDur >::value, _ToDur >::type duration_cast(const duration< _Rep, _Period > &__d)
void sleep_for(const chrono::duration< _Rep, _Period > &__rtime)
reference_wrapper< _Tp > ref(_Tp &__t) noexcept
_Tp * end(valarray< _Tp > &__va)
Wraps the data acquired per frame into a single instance.
Definition: data.h:27