18 static std::map<void*, vr_kit*> vr_kit_map;
24 return tracking_reference_states[serial_nummer];
30 tracking_reference_states.clear();
36 for (
auto& s : tracking_reference_states)
43 std::fill(&calibration_matrix[0], &calibration_matrix[0] + 12, 0.0f);
44 calibration_matrix[0] = calibration_matrix[4] = calibration_matrix[8] = 1.0f;
45 use_calibration_matrix =
false;
52 std::copy(&calibration_matrix[0], &calibration_matrix[0] + 12, &transformation_matrix[0]);
57 if (!use_calibration_matrix)
62 for (i = 0; i < 3; ++i) {
63 pos[i] = calibration_matrix[9 + i];
64 for (
int j = 0; j < 3; ++j) {
65 pos[i] += calibration_matrix[3 * j + i] * pose[9 + j];
66 ori[3 * j + i] = 0.0f;
67 for (
int k = 0; k < 3; ++k)
68 ori[3 * j + i] += calibration_matrix[3 * k + i] * pose[3 * j + k];
71 for (i = 0; i < 3; ++i) {
73 for (
int j = 0; j < 3; ++j)
74 pose[3 * j + i] = ori[3 * j + i];
81 std::copy(&new_transformation_matrix[0], &new_transformation_matrix[0] + 12, &calibration_matrix[0]);
86 use_calibration_matrix =
true;
91 use_calibration_matrix =
false;
96 return use_calibration_matrix;
102 return tracking_reference_states;
103 calibrated_tracking_reference_states = tracking_reference_states;
104 for (
auto& s : calibrated_tracking_reference_states)
107 return calibrated_tracking_reference_states;
125 x_dir[1] = x_dir[2] = 0;
131 auto iter = kit_map.find(handle);
132 if (iter != kit_map.end())
135 kit_map[handle] = kit;
141 auto iter = kit_map.find(handle);
142 if (iter != kit_map.end()) {
143 std::cerr <<
"WARNING: vr kit <" << kit->
get_name() <<
"> recreated. Deleted copy <"
144 << iter->second->get_name() <<
"> might be still in use." << std::endl;
149 kit_map[handle] = kit;
151 std::cout <<
"vr kit registered:\n" << kit->
get_device_info() << std::endl;
157 std::cerr <<
"WARNING: could not initialize camera if vr kit <" << kit->
get_name() <<
">" << std::endl;
168 static std::vector<vr_driver*> drivers;
187 std::vector<void*> kit_handles;
189 auto new_ids = driver_ptr->scan_vr_kits();
190 kit_handles.insert(kit_handles.end(), new_ids.begin(), new_ids.end());
199 if ((kit_ptr = driver_ptr->replace_by_index(vr_kit_index, new_kit_ptr)))
207 if (driver_ptr->replace_by_pointer(old_kit_ptr, new_kit_ptr))
225 if (iter->second != vr_kit_ptr)
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
vr_calibration_base()
nothing to be done in contructor
bool initialize()
initialization is typically called the c
interface class for vr drivers.
void set_index(unsigned _idx)
write access to driver index is restricted to the register_driver() function
void clear_tracking_reference_states()
remove all tracking reference states
void mark_tracking_references_as_untracked()
mark all tracking reference states as untracked
void set_calibration_transformation(const float new_transformation_matrix[12])
write access to calibration transformation is reserved to classes derived from vr_calibration_base
void calibrate_pose(float(&pose)[12]) const
in case calibration matrix is enabled, transform given pose in place
void put_calibration_transformation(float transformation_matrix[12]) const
read access to calibration transformation stored as 3x4-matrix
vr_tracking_system_info tracking_system_info
store tracking system info to be filled by driver implementations
virtual const std::map< std::string, vr_trackable_state > & get_tracking_reference_states() const
provide read only access to tracking reference states
bool is_calibration_transformation_enabled() const
check whether calibration transformation is enabled; false after construction and typically set to tr...
void replace_vr_kit(void *handle, vr_kit *kit)
call this method during replacement of vr kits. In case vr kit handle had been registered before it i...
void register_vr_kit(void *handle, vr_kit *kit)
call this method during scanning of vr kits. In case vr kit handle had been registered before,...
vr_trackable_state & ref_tracking_reference_state(const std::string &serial_nummer)
provide reference to tracking reference states
virtual const vr_tracking_system_info & get_tracking_system_info() const
provide information on tracking system
vr_driver()
protected constructor
virtual ~vr_driver()
declare destructor virtual to ensure it being called also for derived classes
void enable_calibration_transformation()
enable use of calibration transformation
void put_x_direction(float *x_dir) const
put a 3d x direction into passed array
friend class vr_kit
allow vr_kit access to ref_reference_state and tracking_system_info
void disable_calibration_transformation()
disable use of calibration transformation
a vr kit is composed of headset, two controllers, and two trackers, where all devices can be attached...
vr_camera * get_camera() const
return camera or nullptr if not available
const vr_kit_info & get_device_info() const
return information on the currently attached devices
const vr_driver * get_driver() const
return driver
const std::string & get_name() const
return name of vr_kit
the vr namespace for virtual reality support
std::vector< vr_driver * > & ref_drivers()
return registered drivers
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...
bool unregister_vr_kit(void *handle, vr_kit *vr_kit_ptr)
unregister a previously registered vr kit by handle and pointer
std::vector< vr_driver * > & get_vr_drivers()
return a vector with all registered vr drivers
void register_driver(vr_driver *vrd)
register a new driver
std::map< void *, vr_kit * > & ref_vr_kit_map()
access to vr_kit map singleton
std::vector< void * > scan_vr_kits()
iterate all registered vr drivers to scan for vr kits and return vector of vr kit handles
@ VRS_TRACKED
trackable is connected and tracked
@ VRS_DETACHED
trackable is not reachable via wireless
bool replace_by_pointer(vr_kit *old_kit_ptr, vr_kit *new_kit_ptr)
scan vr kits and if one with given pointer exists, replace it by passed kit; return whether replaceme...
vr_kit * replace_by_index(int vr_kit_index, vr_kit *new_kit_ptr)
scan vr kits and if one of given index exists replace it by passed kit and return index to replaced k...
a trackable knows whether it is tracked and its 6d pose stored as 3x4 matrix in column major format
VRStatus status
whether trackable is currently tracked, only in case of true, the pose member contains useful informa...
information provided for tracking system
defines the class vr::vr_driver class and gives access to the driver registry with the functions vr::...