3#include <cgv/utils/file.h>
19 if (!dp->is_calibration_transformation_enabled())
21 calibration_info[dp->get_driver_name()] = dp->get_tracking_reference_states();
23 dp->put_calibration_transformation(trans);
24 std::cout << dp->get_driver_name() <<
":";
25 for (
int i = 0; i < 12; ++i)
26 std::cout <<
" " << trans[i];
27 std::cout << std::endl;
34 std::vector<cgv::math::quaternion<float> > relative_rotations;
35 std::vector<cgv::math::fvec<float, 3> > relative_translations;
39 if (!handles.empty()) {
46 float current_transform_array[12];
51 std::cout <<
"current :";
52 for (
int i = 0; i < 12; ++i)
53 std::cout <<
" " << current_transform_array[i];
54 std::cout << std::endl;
57 for (
const auto& target : target_reference_states) {
59 auto iter = refs.find(target.first);
60 if (iter == refs.end())
69 pose_append(relative_transformation, pose_inverse(pose));
71 relative_translations.push_back(pose_position(relative_transformation));
76 for (
const auto& rr : relative_rotations)
79 for (
const auto& rt : relative_translations)
81 avg_rel_tra *= 1.0f / float(relative_translations.size());
83 bool consistent =
true;
84 for (
unsigned i = 0; i < relative_rotations.size(); ++i) {
89 if (length(relative_translations[i] - avg_rel_tra) > 0.02f) {
96 pose_transform(relative_transformation, current_transform);
99 std::cout <<
"relative :" << relative_transformation << std::endl;
100 std::cout <<
"new :";
101 for (
int i = 0; i < 12; ++i)
102 std::cout <<
" " << current_transform_array[i];
103 std::cout << std::endl;
113 if (iter == calibration_info.end())
124 if (!cgv::utils::file::read(file_path, content,
true))
127 std::map<std::string, std::map<std::string, vr::vr_trackable_state> > read_calibration_info;
128 std::vector<cgv::utils::line> lines;
130 std::string driver_name;
131 for (
auto l : lines) {
138 driver_name = std::string(l.begin + 3, l.size() - 4);
144 std::stringstream ss(std::string(l.begin + 2, l.size() - 2));
145 ss >> orientation >> position;
146 char rest_of_line[500];
147 ss.getline(&rest_of_line[0], 500);
148 std::string serial = std::string(rest_of_line+1);
149 if (!serial.empty()) {
150 if (serial[0] ==
'"')
151 serial = serial.substr(1, serial.size() - 2);
152 if (!serial.empty()) {
155 orientation.
put_matrix(pose_orientation(pose));
156 pose_position(pose) = position;
163 for (
const auto& driver_info : read_calibration_info)
164 calibration_info[driver_info.first] = driver_info.second;
167 if (update_drivers) {
169 auto iter = read_calibration_info.find(dp->get_driver_name());
171 if (iter == read_calibration_info.end())
181 std::ofstream os(file_path);
184 for (
const auto& di : calibration_info) {
185 os <<
"d \"" << di.first <<
"\"\n";
186 for (
const auto& s : di.second) {
190 os << orientation <<
" " << pose_position(pose) <<
" \"" << s.first <<
"\"\n";
More advanced text processing for splitting text into lines or tokens.
vr key events use the key codes defined in vr::VRKeys
bool update_driver_calibration(vr::vr_driver *dp, const std::map< std::string, vr::vr_trackable_state > &target_reference_states) const
update the calibration of a driver from the given target reference states
bool read_calibration(const std::string &file_path, bool update_drivers=true)
read calibration from calibration file
vr_calibration()
constructor is protected to forbid construction of more than one singleton
void update_calibration_info()
iterate vr drivers and copy calibration information into map
bool write_calibration(const std::string &file_path) const
write calibration to calibration file
matrix of fixed size dimensions
A vector with zero based index.
T normalize()
normalize the vector using the L2-Norm and return the length
void put_matrix(mat_type &M) const
compute equivalent 3x3 rotation matrix
void set_driver_calibration_matrix(vr_driver *driver, const float calibration_matrix[12]) const
single point of write access to calibration transformation of vr drivers
interface class for vr drivers.
void put_calibration_transformation(float transformation_matrix[12]) const
read access to calibration transformation stored as 3x4-matrix
virtual const std::map< std::string, vr_trackable_state > & get_tracking_reference_states() const
provide read only access to tracking reference states
virtual std::string get_driver_name() const =0
return name of driver
void enable_calibration_transformation()
enable use of calibration transformation
virtual std::vector< void * > scan_vr_kits()=0
scan all connected vr kits and return a vector with their ids
bool query_state(vr_kit_state &state, int pose_query=2)
query current state of vr kit and return whether this was successful
vr_calibration & ref_vr_calibration()
access to singleton object of vr_calibration class
void split_to_lines(const char *global_begin, const char *global_end, std::vector< line > &lines, bool truncate_trailing_spaces)
this function splits a text range at the newline characters into single lines.
vr_kit * get_vr_kit(void *handle)
query a pointer to a vr kit by its device handle, function can return null pointer in case that no vr...
std::vector< vr_driver * > & get_vr_drivers()
return a vector with all registered vr drivers
@ VRS_TRACKED
trackable is connected and tracked
helper functions to work with poses that can be represented with 3x4 matrix or quaternion plus vector
structure that stores all information describing the state of a VR kit
defines the class vr::vr_driver class and gives access to the driver registry with the functions vr::...