cgv
vr_log.h
1 #pragma once
2 #include <cgv/render/render_types.h>
3 #include <vector>
4 #include <unordered_map>
5 #include <ostream>
6 #include <sstream>
7 #include <memory>
8 
9 #include <libs/vr/vr_state.h>
10 #include <cgv/data/ref_counted.h>
11 #include "vr_driver.h"
12 
13 #include "lib_begin.h"
14 
15 namespace vr {
17  class CGV_API vr_log :
18  public cgv::render::render_types,
19  public cgv::data::ref_counted {
20  public:
21  template<class T>
22  using container = std::vector<T, std::allocator<T>>;
24  enum StorageMode {
25  SM_IN_MEMORY = 1,
26  SM_OSTREAM = 2,
27  SM_IN_MEMORY_AND_OSTREAM = 3,
28  SM_NONE = 0
29  };
30 
31  enum Filter {
32  F_POSE = 1,
33  F_BUTTON = 2,
34  F_AXES = 4,
35  F_VIBRATION = 8,
36  F_HMD = 16,
37  F_ALL = 31,
38  F_NONE = 0
39  };
40 
41  container<double> time_stamp;
42 
43  container<mat34> hmd_pose;
44  container<uint8_t> hmd_status;
45 
46  container<vecn> controller_axes[max_nr_controllers];
47  container<mat34> controller_pose[max_nr_controllers];
48  container<vec2> controller_vibration[max_nr_controllers];
49  container<unsigned> controller_button_flags[max_nr_controllers];
50  container<uint8_t> controller_status[max_nr_controllers];
51  private:
52  bool setting_locked = false;
53  int log_storage_mode = SM_NONE;
54  int filters = 0;
55  size_t nr_vr_states = 0; //number of recorded vr states
56 
57  std::shared_ptr<std::ostream> log_stream;
58 
59  inline void unlock_settings() {
60  setting_locked = false;
61  }
62  protected:
64  void log_vr_state(const vr::vr_kit_state& state, const int mode, const int filter, const double time, std::ostream* log_stream);
65  public:
66  vr_log() = default;
67  //construct log from stream
68  vr_log(std::istringstream& is);
69 
71  inline void log_vr_state(const vr::vr_kit_state& state, const double& time) {
72  log_vr_state(state, log_storage_mode, filters, time, log_stream.get());
73  }
75  void disable_log();
77  void enable_in_memory_log();
78 
80  void enable_ostream_log(const std::shared_ptr<std::ostream>& stream);
81 
83  inline void set_filter(int f) {
84  if (setting_locked)
85  return;
86  filters = f;
87  }
88  inline int get_filter() const {
89  return filters;
90  }
91 
93  void lock_settings();
94 
95  inline const size_t recorded_vr_states() const {
96  return nr_vr_states;
97  }
98 
100  bool load_state(std::istringstream& is);
101  };
102 }
103 
104 #include <cgv/config/lib_end.h>
vr::vr_log::log_vr_state
void log_vr_state(const vr::vr_kit_state &state, const double &time)
write vr_kit_state to log , and stream serialized vr_kit_state to log_stream if ostream_log is enable...
Definition: vr_log.h:71
cgv::math::fvec
Definition: fvec.h:18
vr
the vr namespace for virtual reality support
Definition: gl_vr_display.cxx:5
vr_driver.h
vr::vr_log
helper struct for logging vr events
Definition: vr_log.h:19
cgv::data::ref_counted
Definition: ref_counted.h:11
vr::max_nr_controllers
const unsigned max_nr_controllers
maximum number of attachable controller and tracker devices
Definition: vr_state.h:19
vr::vr_kit_state
structure that stores all information describing the state of a VR kit
Definition: vr_state.h:139
vr_state.h
vr::vr_log::set_filter
void set_filter(int f)
define what data should be recorded.
Definition: vr_log.h:83