cgv
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
vr_camera.cxx
1#include "vr_camera.h"
2
3#include <iostream>
4#include <string>
5
6namespace vr {
7
8 vr_camera::vr_camera() : num_cameras(0u), state(CS_UNINITIALIZED), frame_format(CFF_RGBA), frame_split(CFS_NONE), frame_flipped(false)
9 {
10 }
11
13 const std::string& vr_camera::get_last_error() const
14 {
15 return last_error;
16 }
17
19 {
20 if (state != CS_UNINITIALIZED) {
21 last_error = "attempt to initialize already initialized vr camera";
22 return false;
23 }
24 if (!initialize_impl())
25 return false;
26 state = CS_INITIALIZED;
27 last_error.clear();
28 return true;
29 }
30
32 if (state == CS_UNINITIALIZED) {
33 last_error = "attempt to start not initialized vr camera, please initialize first";
34 return false;
35 }
36 if (state == CS_STARTED) {
37 last_error = "attempt to start already started vr camera";
38 return false;
39 }
40 if (!start_impl())
41 return false;
42 state = CS_STARTED;
43 last_error.clear();
44 return true;
45 }
46
48 if (state != CS_STARTED) {
49 last_error = "attempt to stop camera that was not started, please start camera first";
50 return false;
51 }
52 if (!stop_impl())
53 return false;
54 state = CS_INITIALIZED;
55 last_error.clear();
56 return true;
57 }
58
60 bool vr_camera::get_frame(std::vector<uint8_t>& frame_data, uint32_t& width, uint32_t& height, bool undistorted, bool maximum_valid_rectangle)
61 {
62 if (state != CS_STARTED) {
63 last_error = "attempt to get frame from vr camera that was not started, please start camera first";
64 return false;
65 }
66 if (!get_frame_impl(frame_data, width, height, undistorted, maximum_valid_rectangle))
67 return false;
68 last_error.clear();
69 return true;
70 }
72 bool vr_camera::get_gl_texture_id(uint32_t& tex_id, uint32_t& width, uint32_t& height, bool undistorted, float max_valid_texcoord_range[4])
73 {
74 if (state != CS_STARTED) {
75 last_error = "attempt to get gl texture id from vr camera that was not started, please start camera first";
76 return false;
77 }
78 if (!get_gl_texture_id_impl(tex_id, width, height, undistorted, max_valid_texcoord_range))
79 return false;
80 last_error.clear();
81 return true;
82 }
83
85 {
86 return frame_format;
87 }
88
90 {
91 return frame_split;
92 }
93
95 {
96 return state;
97 }
98
100 {
101 return num_cameras;
102 }
103
105 {
106 return frame_flipped;
107 }
108
109} // namespace vr
bool start()
start streaming of frames
Definition vr_camera.cxx:31
const std::string & get_last_error() const
return last error, if no error has occured, the function returns an empty string
Definition vr_camera.cxx:13
CameraFrameFormat get_frame_format() const
query pixel format
Definition vr_camera.cxx:84
CameraState get_state() const
return the camera state
Definition vr_camera.cxx:94
bool is_frame_flipped() const
query whether frame row order is from top to bottom
vr_camera()
construct camera object
Definition vr_camera.cxx:8
bool stop()
stop streaming of frames
Definition vr_camera.cxx:47
bool initialize()
initialization is typically called the c
Definition vr_camera.cxx:18
std::string last_error
store last error as a string to be as flexible as possible
Definition vr_camera.h:52
bool get_gl_texture_id(uint32_t &tex_id, uint32_t &width, uint32_t &height, bool undistorted, float max_valid_texcoord_range[4])
query id of shared opengl texture id
Definition vr_camera.cxx:72
CameraFrameSplit get_frame_split() const
query stereo frame layout
Definition vr_camera.cxx:89
uint8_t get_nr_cameras() const
return number of cameras in the headset (1 for mono and 2 for stereo)
Definition vr_camera.cxx:99
bool get_frame(std::vector< uint8_t > &frame_data, uint32_t &width, uint32_t &height, bool undistorted, bool maximum_valid_rectangle)
check for a new frame, return false if not available. Otherwise copy frame to provided buffer that is...
Definition vr_camera.cxx:60
the vr namespace for virtual reality support
CameraFrameSplit
in case of stereo cameras a frame contains images of both eyes either split vertically (left right) o...
Definition vr_camera.h:31
CameraState
different status values for a vr camera
Definition vr_camera.h:19
CameraFrameFormat
currently only a single frame format supported
Definition vr_camera.h:26
defines camera class for camera provided by vr_kit