cgv
Loading...
Searching...
No Matches
vr_log.h
1#pragma once
2#include <vector>
3#include <unordered_map>
4#include <ostream>
5#include <sstream>
6#include <memory>
7
8#include <libs/vr/vr_state.h>
9#include <cgv/data/ref_counted.h>
10//#include <cgv/math/fvec.h>
11//#include <cgv/math/vec.h>
12#include <cgv/math/fmat.h>
13#include "vr_driver.h"
14
15#include "lib_begin.h"
16
17namespace vr {
19 class CGV_API vr_log : public cgv::data::ref_counted {
20 public:
21 template<class T>
22 using container = std::vector<T, std::allocator<T>>;
23 enum StorageMode {
24 SM_IN_MEMORY = 1,
25 SM_OSTREAM = 2,
26 SM_IN_MEMORY_AND_OSTREAM = 3,
27 SM_NONE = 0
28 };
29
30 enum Filter {
31 F_POSE = 1,
32 F_BUTTON = 2,
33 F_AXES = 4,
34 F_VIBRATION = 8,
35 F_HMD = 16,
36 F_ALL = 31,
37 F_NONE = 0
38 };
39
40 container<double> time_stamp;
41
42 container<cgv::mat3x4> hmd_pose;
43 container<uint8_t> hmd_status;
44
45 container<cgv::vecn> controller_axes[max_nr_controllers];
46 container<cgv::mat3x4> controller_pose[max_nr_controllers];
47 container<cgv::vec2> controller_vibration[max_nr_controllers];
48 container<unsigned> controller_button_flags[max_nr_controllers];
49 container<uint8_t> controller_status[max_nr_controllers];
50 private:
51 bool setting_locked = false;
52 int log_storage_mode = SM_NONE;
53 int filters = 0;
54 size_t nr_vr_states = 0; //number of recorded vr states
55
56 std::shared_ptr<std::ostream> log_stream;
57
58 inline void unlock_settings() {
59 setting_locked = false;
60 }
61 protected:
63 void log_vr_state(const vr::vr_kit_state& state, const int mode, const int filter, const double time, std::ostream* log_stream);
64 public:
65 vr_log() = default;
66 //construct log from stream
67 vr_log(std::istringstream& is);
68
70 inline void log_vr_state(const vr::vr_kit_state& state, const double& time) {
71 log_vr_state(state, log_storage_mode, filters, time, log_stream.get());
72 }
74 void disable_log();
76 void enable_in_memory_log();
77
79 void enable_ostream_log(const std::shared_ptr<std::ostream>& stream);
80
82 inline void set_filter(int f) {
83 if (setting_locked)
84 return;
85 filters = f;
86 }
87 inline int get_filter() const {
88 return filters;
89 }
90
92 void lock_settings();
93
94 inline const size_t recorded_vr_states() const {
95 return nr_vr_states;
96 }
97
99 bool load_state(std::istringstream& is);
100 };
101}
102
103#include <cgv/config/lib_end.h>
if you derive your class from this class, a ref_ptr will do reference counting in the inhereted ref_c...
Definition ref_counted.h:11
helper struct for logging vr events
Definition vr_log.h:19
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:70
void set_filter(int f)
define what data should be recorded.
Definition vr_log.h:82
the vr namespace for virtual reality support
const unsigned max_nr_controllers
maximum number of attachable controller and tracker devices
Definition vr_state.h:19
structure that stores all information describing the state of a VR kit
Definition vr_state.h:139
defines the class vr::vr_driver class and gives access to the driver registry with the functions vr::...
defines types to store the state vr::vr_kit_state of a vr kit, which is split into sub states for the...