cgv
vr_camera.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 
6 #include "lib_begin.h"
7 
10 
14 namespace vr {
16 
19  CS_UNINITIALIZED,
20  CS_INITIALIZED,
21  CS_STARTED
22 };
23 
26  CFF_RGBA = 0
27 };
28 
31  CFS_NONE = 0, // no split indicates mono camera
32  CFS_VERTICAL, // left right split
33  CFS_HORIZONTAL // top bottom split
34 };
35 
37 class CGV_API vr_camera
38 {
39 protected:
41  friend class vr_kit;
43  vr_camera();
45  friend class vr_driver;
47  bool initialize();
49  virtual ~vr_camera() = default;
51  mutable std::string last_error;
52 public:
55  uint8_t get_nr_cameras() const;
58  virtual bool put_camera_to_head_matrix(int camera_index, float* pose_matrix) const = 0;
60  virtual bool put_projection_matrix(int camera_index, bool undistorted, float z_near, float z_far, float* projection_matrix) const = 0;
62  virtual bool put_camera_intrinsics(int camera_index, bool undistorted, float* focal_length_2d_ptr, float* center_2d_ptr) const = 0;
64  bool start();
66  bool stop();
68  CameraState get_state() const;
70  bool has_error() const { return !last_error.empty(); }
72  const std::string& get_last_error() const;
74 
77  CameraFrameFormat get_frame_format() const;
80  CameraFrameSplit get_frame_split() const;
82  bool is_frame_flipped() const;
84  bool get_frame(std::vector<uint8_t>& frame_data, uint32_t& width, uint32_t& height, bool undistorted, bool maximum_valid_rectangle);
86  bool get_gl_texture_id(uint32_t& tex_id, uint32_t& width, uint32_t& height, bool undistorted, float max_valid_texcoord_range[4]);
88 protected:
89  uint8_t num_cameras;
90  CameraFrameFormat frame_format;
91  CameraFrameSplit frame_split;
92  bool frame_flipped;
93  CameraState state;
94 private:
95  virtual bool initialize_impl() = 0;
96  virtual bool start_impl() = 0;
97  virtual bool stop_impl() = 0;
98  virtual bool get_frame_impl(std::vector<uint8_t>& frame_data, uint32_t& width, uint32_t& height, bool undistorted, bool maximum_valid_rectangle) = 0;
99  virtual bool get_gl_texture_id_impl(uint32_t& tex_id, uint32_t& width, uint32_t& height, bool undistorted, float max_valid_texcoord_range[4]) = 0;
100 };
101 
102 } // namespace vr
104 
105 #include <cgv/config/lib_end.h>
vr::CameraFrameSplit
CameraFrameSplit
in case of stereo cameras a frame contains images of both eyes either split vertically (left right) o...
Definition: vr_camera.h:30
vr::vr_camera::put_camera_intrinsics
virtual bool put_camera_intrinsics(int camera_index, bool undistorted, float *focal_length_2d_ptr, float *center_2d_ptr) const =0
write the focal lengths in x- and y-direction to access to focal_length_2d_ptr[0|1] and the texture c...
vr
the vr namespace for virtual reality support
Definition: gl_vr_display.cxx:5
vr::vr_camera::has_error
bool has_error() const
check for error
Definition: vr_camera.h:70
vr::CameraFrameFormat
CameraFrameFormat
currently only a single frame format supported
Definition: vr_camera.h:25
vr::vr_camera::last_error
std::string last_error
store last error as a string to be as flexible as possible
Definition: vr_camera.h:51
vr::vr_kit
a vr kit is composed of headset, two controllers, and two trackers, where all devices can be attached...
Definition: vr_kit.h:69
vr::vr_driver
interface class for vr drivers.
Definition: vr_driver.h:57
vr::vr_camera
interface for mono or stereo cameras in VR headsets
Definition: vr_camera.h:38
vr::vr_camera::put_projection_matrix
virtual bool put_projection_matrix(int camera_index, bool undistorted, float z_near, float z_far, float *projection_matrix) const =0
access to 4x4 matrix in column major format for perspective transformation of camera (0....
vr::CameraState
CameraState
different status values for a vr camera
Definition: vr_camera.h:18
vr::vr_camera::~vr_camera
virtual ~vr_camera()=default
destruct camera
vr::vr_camera::put_camera_to_head_matrix
virtual bool put_camera_to_head_matrix(int camera_index, float *pose_matrix) const =0
access to 3x4 matrix in column major format for transformation from camera (0 .. left,...