Intel® RealSense™ Cross Platform API
Intel Realsense Cross-platform API
|
Go to the documentation of this file.
9 #ifndef LIBREALSENSE_TYPES_H
10 #define LIBREALSENSE_TYPES_H
12 #include "../include/librealsense/rs.h"
13 #include "../include/librealsense/rscore.hpp"
20 #include <condition_variable>
46 std::ostringstream
ss;
48 operator std::string()
const {
return ss.str(); }
59 for (
unsigned int i = 0; i < sizeof(T); ++i) reinterpret_cast<char *>(&le_value)[i] = reinterpret_cast<const char *>(&be_value)[
sizeof(T) - i - 1];
76 #define LOG(SEVERITY, ...) do { if(static_cast<int>(SEVERITY) >= rsimpl::get_minimum_severity()) { std::ostringstream ss; ss << __VA_ARGS__; rsimpl::log(SEVERITY, ss.str()); } } while(false)
77 #define LOG_DEBUG(...) LOG(RS_LOG_SEVERITY_DEBUG, __VA_ARGS__)
78 #define LOG_INFO(...) LOG(RS_LOG_SEVERITY_INFO, __VA_ARGS__)
79 #define LOG_WARNING(...) LOG(RS_LOG_SEVERITY_WARN, __VA_ARGS__)
80 #define LOG_ERROR(...) LOG(RS_LOG_SEVERITY_ERROR, __VA_ARGS__)
81 #define LOG_FATAL(...) LOG(RS_LOG_SEVERITY_FATAL, __VA_ARGS__)
87 #define RS_ENUM_HELPERS(TYPE, PREFIX) const char * get_string(TYPE value); \
88 inline bool is_valid(TYPE value) { return value >= 0 && value < RS_##PREFIX##_COUNT; } \
89 inline std::ostream & operator << (std::ostream & out, TYPE value) { if(is_valid(value)) return out << get_string(value); else return out << (int)value; }
103 #undef RS_ENUM_HELPERS
133 std::vector<std::pair<rs_stream, rs_format>>
outputs;
202 int m_major, m_minor, m_patch, m_build;
204 std::string string_representation;
207 static std::vector<std::string> split(
const std::string& str);
208 static int parse_part(
const std::string& name,
int part);
214 : m_major(major), m_minor(minor), m_patch(patch), m_build(build), is_any(is_any), string_representation(
to_string()) {}
222 : m_major(parse_part(name, 0)), m_minor(parse_part(name, 1)), m_patch(parse_part(name, 2)), m_build(parse_part(name, 3)), is_any(false), string_representation(
to_string()) {}
226 if (is_any || other.is_any)
return true;
227 if (m_major > other.m_major)
return false;
228 if ((m_major == other.m_major) && (m_minor > other.m_minor))
return false;
229 if ((m_major == other.m_major) && (m_minor == other.m_minor) && (m_patch > other.m_patch))
return false;
230 if ((m_major == other.m_major) && (m_minor == other.m_minor) && (m_patch == other.m_patch) && (m_build > other.m_build))
return false;
235 return is_any || (other.m_major == m_major && other.m_minor == m_minor && other.m_patch == m_patch && other.m_build == m_build);
245 return (from <= *
this) && (*
this <= until);
248 operator const char*()
const
250 return string_representation.c_str();
306 throw std::runtime_error(
"failed to fetch an unpakcer, most likely because enable_stream was not called!");
319 void unpack(
byte *
const dest[],
const byte *
source)
const;
341 operator bool() {
return fptr !=
nullptr; }
345 try { fptr(dev, frame, user); }
catch (...)
347 LOG_ERROR(
"Received an execption from frame callback!");
363 operator bool() {
return fptr !=
nullptr; }
369 try { fptr(device, data, user); }
catch (...)
371 LOG_ERROR(
"Received an execption from motion events callback!");
388 operator bool() {
return fptr !=
nullptr; }
392 try { fptr(device, data, user); }
catch (...)
394 LOG_ERROR(
"Received an execption from timestamp events callback!");
409 operator bool() {
return fptr !=
nullptr; }
415 try { fptr(severity, message, user); }
418 LOG_ERROR(
"Received an execption from log callback!");
438 if (callback) callback->
release();
439 callback = other.callback;
440 other.callback =
nullptr;
479 return{ i.
width + pad_crop * 2, i.
height + pad_crop * 2, i.
ppx + pad_crop, i.
ppy + pad_crop, i.
fx, i.
fy, i.
model, {i.
coeffs[0], i.
coeffs[1], i.
coeffs[2], i.
coeffs[3], i.
coeffs[4]} };
484 const float sx = (float)width / i.
width, sy = (
float)height / i.
height;
485 return{ width, height, i.
ppx*sx, i.
ppy*sy, i.
fx*sx, i.
fy*sy, i.
model, {i.
coeffs[0], i.
coeffs[1], i.
coeffs[2], i.
coeffs[3], i.
coeffs[4]} };
490 inline uint32_t
pack(uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3)
492 return (c0 << 24) | (c1 << 16) | (c2 << 8) | c3;
495 template<
class T,
int C>
501 bool keep_allocating =
true;
502 std::condition_variable cv;
508 for (
auto i = 0; i < C; i++)
511 buffer[i] = std::move(T());
517 std::unique_lock<std::mutex> lock(mutex);
518 if (!keep_allocating)
return nullptr;
520 for (
auto i = 0; i < C; i++)
534 if (item < buffer || item >= buffer + C)
536 throw std::runtime_error(
"Trying to return item to a heap that didn't allocate it!");
538 auto i = item - buffer;
539 buffer[i] = std::move(T());
542 std::unique_lock<std::mutex> lock(mutex);
557 std::unique_lock<std::mutex> lock(mutex);
558 keep_allocating =
false;
563 std::unique_lock<std::mutex> lock(mutex);
565 const auto ready = [
this]()
569 if (!ready() && !cv.wait_for(lock, std::chrono::hours(1000), ready))
571 throw std::runtime_error(
"Could not flush one of the user controlled objects!");
578 std::function<void()> continuation;
579 const void* protected_data =
nullptr;
586 explicit frame_continuation(std::function<
void()> continuation,
const void* protected_data) : continuation(continuation), protected_data(protected_data) {}
591 other.continuation = []() {};
592 other.protected_data =
nullptr;
598 continuation = []() {};
599 protected_data =
nullptr;
604 protected_data =
nullptr;
605 continuation = [](){};
608 const void*
get_data()
const {
return protected_data; }
613 protected_data = other.protected_data;
614 continuation = other.continuation;
615 other.continuation = []() {};
616 other.protected_data =
nullptr;
632 std::function<
bool(
rs_stream)> intrinsic_validator);
645 return std::find_if(data.begin(), data.end(), [](
byte b){
return b!=0; }) != data.end();
float3x3 transpose(const float3x3 &a)
Definition: types.h:119
rs_camera_info firmware_type
Definition: types.h:259
float z
Definition: types.h:110
native_pixel_format pf
Definition: types.h:158
std::ostringstream ss
Definition: types.h:46
void reset()
Definition: types.h:602
rs_intrinsics native_intrinsics
Definition: types.h:160
rs_camera_info
Read-only strings that can be queried from the device.
Definition: rs.h:237
#define RS_ENUM_HELPERS(TYPE, PREFIX)
Definition: types.h:87
rs_stream
Streams are different types of data provided by RealSense devices.
Definition: rs.h:33
timestamp_callback_ptr timestamp_callback
Definition: types.h:455
rs_frame_metadata
Types of value provided from the device with each frame.
Definition: rs.h:203
stream
Streams are different types of data provided by RealSense devices.
Definition: rs.hpp:24
const static_device_info info
Definition: types.h:450
subdevice_mode_selection()
Definition: types.h:300
void get_all_possible_requestes(std::vector< stream_request >(&stream_requests)[RS_STREAM_NATIVE_COUNT]) const
stream_request requests[RS_STREAM_NATIVE_COUNT]
Definition: types.h:451
pose stream_poses[RS_STREAM_NATIVE_COUNT]
Definition: types.h:277
void release() override
Definition: types.h:351
std::vector< int > pad_crop_options
Definition: types.h:162
rs_intrinsics scale_intrinsics(const rs_intrinsics &i, int width, int height)
Definition: types.h:482
rs_log_severity
Severity of the librealsense logger.
Definition: rs.h:265
void on_event(rs_log_severity severity, const char *message) override
Definition: types.h:411
float depth_scale
Definition: types.h:456
bool divides2
Definition: types.h:183
subdevice_mode mode
Definition: types.h:295
bool validate_requests(stream_request(&requests)[RS_STREAM_NATIVE_COUNT], bool throw_exception=false) const
std::string name
Definition: types.h:270
rs_frame_callback * operator*()
Definition: types.h:445
bool validate_extrinsics(rs_stream from_stream, rs_stream to_stream) const
int stream_request::* field
Definition: types.h:180
float3 x
Definition: types.h:111
struct rs_motion_callback rs_motion_callback
Definition: rs.h:360
rs_option option
Definition: types.h:189
std::vector< supported_option > options
Definition: types.h:276
std::vector< supported_capability > capabilities_vector
Definition: types.h:282
bool find_good_requests_combination(stream_request(&output_requests)[RS_STREAM_NATIVE_COUNT], std::vector< stream_request > stream_requests[RS_STREAM_NATIVE_COUNT]) const
std::vector< subdevice_mode > subdevice_modes
Definition: types.h:273
int get_unpacked_width() const
bool operator>(const firmware_version &other) const
Definition: types.h:238
float3 operator+(const float3 &a, const float3 &b)
Definition: types.h:114
void log_to_file(rs_log_severity min_severity, const char *file_path)
rs_distortion model
Definition: rs.h:308
int height
Definition: types.h:168
void on_frame(rs_device *dev, rs_frame_ref *frame) override
Definition: types.h:342
std::string firmware_version
Definition: types.h:279
std::unique_ptr< rs_motion_callback, void(*)(rs_motion_callback *)> motion_callback_ptr
Definition: types.h:427
float3 y
Definition: types.h:111
to_string & operator<<(const T &val)
Definition: types.h:47
const int RS_MAX_EVENT_TIME_OUT
Definition: types.h:32
bool same_format
Definition: types.h:184
float fy
Definition: rs.h:307
frame_continuation()
Definition: types.h:584
bool validate_intrinsics(rs_stream stream) const
int pad_crop
Definition: types.h:296
float ppx
Definition: rs.h:304
std::string serial
Definition: types.h:280
rs_capabilities capability
Definition: types.h:256
float ppy
Definition: rs.h:305
bool divides
Definition: types.h:183
pose inverse(const pose &a)
Definition: types.h:123
int delta
Definition: types.h:181
double min
Definition: types.h:190
firmware_version from
Definition: types.h:257
rs_preset
Presets: general preferences that are translated by librealsense into concrete resolution and FPS.
Definition: rs.h:81
rs_distortion
Distortion model: defines how pixel coordinates should be mapped to sensor coordinates.
Definition: rs.h:99
Motion data from gyroscope and accelerometer from the microcontroller.
Definition: rs.h:347
void(* timestamp_callback_function_ptr)(rs_device *dev, rs_timestamp_data data, void *user)
Definition: types.h:329
T * allocate()
Definition: types.h:515
frame_callback_ptr callbacks[RS_STREAM_NATIVE_COUNT]
Definition: types.h:452
float fx
Definition: rs.h:306
float3x3 orientation
Definition: types.h:112
double step
Definition: types.h:190
firmware_version until
Definition: types.h:258
void set_output_buffer_format(const rs_output_buffer_format in_output_format)
int stream_subdevices[RS_STREAM_NATIVE_COUNT]
Definition: types.h:271
~frame_callback_ptr()
Definition: types.h:443
firmware_version(int major, int minor, int patch, int build, bool is_any=false)
Definition: types.h:213
void release() override
Definition: types.h:398
float3 position
Definition: types.h:112
bool operator<=(const firmware_version &other) const
Definition: types.h:224
~frame_continuation()
Definition: types.h:620
frame_continuation(frame_continuation &&other)
Definition: types.h:589
log_callback(log_callback_function_ptr fptr, void *user)
Definition: types.h:407
void deallocate(T *item)
Definition: types.h:532
void stop_allocation()
Definition: types.h:555
rs_output_buffer_format output_format
Definition: types.h:171
float & operator()(int i, int j)
Definition: types.h:111
void(* log_callback_function_ptr)(rs_log_severity severity, const char *message, void *user)
Definition: types.h:330
device_config(const rsimpl::static_device_info &info)
Definition: types.h:458
float x
Definition: types.h:110
rs_timestamp_domain
Specifies the clock in relation to which the frame timestamp was measured.
Definition: rs.h:292
stream_request presets[RS_STREAM_NATIVE_COUNT][RS_PRESET_COUNT]
Definition: types.h:275
const uint8_t RS_STREAM_NATIVE_COUNT
Definition: types.h:27
source
Allows the user to choose between available hardware subdevices.
Definition: rs.hpp:219
int fps
Definition: types.h:170
log_callback()
Definition: types.h:406
data_polling_request()
Definition: types.h:197
rs_intrinsics pad_crop_intrinsics(const rs_intrinsics &i, int pad_crop)
Definition: types.h:477
int subdevice
Definition: types.h:156
bool check_not_all_zeros(std::vector< byte > data)
Definition: types.h:643
subdevice_mode_selection(const subdevice_mode &mode, int pad_crop, int unpacker_index)
Definition: types.h:301
void log(rs_log_severity severity, const std::string &message)
struct rs_timestamp_callback rs_timestamp_callback
Definition: rs.h:362
float coeffs[5]
Definition: rs.h:309
void(* motion_callback_function_ptr)(rs_device *dev, rs_motion_data data, void *user)
Definition: types.h:328
bool operator==(const float3 &a, const float3 &b)
Definition: types.h:113
int width
Definition: types.h:168
const void * get_data() const
Definition: types.h:608
int get_width() const
Definition: types.h:309
rs_stream b
Definition: types.h:179
struct rs_log_callback rs_log_callback
Definition: rs.h:363
Definition: rscore.hpp:64
rs_stream a
Definition: types.h:179
firmware_version(const std::string &name)
Definition: types.h:221
motion_events_callback(rs_device *dev, motion_callback_function_ptr fptr, void *user)
Definition: types.h:361
rs_format
Formats: defines how each stream can be encoded.
Definition: rs.h:53
bool enabled
Definition: types.h:195
void release() override
Definition: types.h:423
void log_to_callback(rs_log_severity min_severity, rs_log_callback *callback)
int get_stride_x() const
Definition: types.h:312
int data_subdevices[RS_STREAM_NATIVE_COUNT]
Definition: types.h:272
void on_event(rs_motion_data data) override
Definition: types.h:365
void operator()()
Definition: types.h:595
bool enabled
Definition: types.h:167
const int RS_USER_QUEUE_SIZE
Definition: types.h:28
static firmware_version any()
Definition: types.h:216
rs_source
Source: allows you to choose between available hardware subdevices.
Definition: rs.h:90
std::unique_ptr< rs_timestamp_callback, void(*)(rs_timestamp_callback *)> timestamp_callback_ptr
Definition: types.h:428
void log_to_console(rs_log_severity min_severity)
std::vector< rs_frame_metadata > supported_metadata_vector
Definition: types.h:283
const pixel_format_unpacker & get_unpacker() const
Definition: types.h:303
int x
Definition: types.h:109
data_polling_request data_request
Definition: types.h:453
void release() override
Definition: types.h:376
frame_continuation(std::function< void()> continuation, const void *protected_data)
Definition: types.h:586
double max
Definition: types.h:190
bool contradict(stream_request req) const
firmware_version()
Definition: types.h:211
const std::vector< std::pair< rs_stream, rs_format > > & get_outputs() const
Definition: types.h:308
size_t get_image_size(rs_stream stream) const
supported_capability(rs_capabilities capability, firmware_version from, firmware_version until, rs_camera_info firmware_type=RS_CAMERA_INFO_CAMERA_FIRMWARE_VERSION)
Definition: types.h:261
std::vector< subdevice_mode_selection > select_modes() const
Definition: types.h:469
rs_capabilities
Specifies various capabilities of a RealSense device.
Definition: rs.h:213
timestamp_events_callback(rs_device *dev, timestamp_callback_function_ptr fptr, void *user)
Definition: types.h:386
rs_blob_type
Proprietary formats for direct communication with device firmware.
Definition: rs.h:228
Video stream intrinsics.
Definition: rs.h:300
void(* frame_callback_function_ptr)(rs_device *dev, rs_frame_ref *frame, void *user)
Definition: types.h:327
rs_option
Defines general configuration controls.
Definition: rs.h:128
Definition: rscore.hpp:139
void on_event(rs_timestamp_data data) override
Definition: types.h:389
float & operator[](int i)
Definition: types.h:110
bool all_requests_filled(const stream_request(&original_requests)[RS_STREAM_NATIVE_COUNT]) const
std::unique_ptr< rs_log_callback, void(*)(rs_log_callback *)> log_callback_ptr
Definition: types.h:426
rs_output_buffer_format output_format
Definition: types.h:298
int width
Definition: rs.h:302
std::vector< rs_intrinsics > rect_modes
Definition: types.h:161
float3 z
Definition: types.h:111
bool operator<(const firmware_version &other) const
Definition: types.h:240
Timestamp data from the motion microcontroller.
Definition: rs.h:339
std::map< rs_camera_info, std::string > camera_info
Definition: types.h:284
int get_stride_y() const
Definition: types.h:313
motion_callback_ptr motion_callback
Definition: types.h:454
int2 native_dims
Definition: types.h:157
frame_continuation & operator=(frame_continuation &&other)
Definition: types.h:610
float nominal_depth_scale
Definition: types.h:281
frame_callback()
Definition: types.h:338
Definition: rscore.hpp:125
bool fill_requests(stream_request(&requests)[RS_STREAM_NATIVE_COUNT]) const
motion_events_callback()
Definition: types.h:360
rs_stream bigger
Definition: types.h:182
int get_framerate() const
Definition: types.h:311
rs_format get_format(rs_stream stream) const
Definition: types.h:316
int height
Definition: rs.h:303
timestamp_events_callback()
Definition: types.h:385
uint8_t byte
Definition: types.h:42
int y
Definition: types.h:109
Definition: rscore.hpp:44
frame_callback_ptr & operator=(frame_callback_ptr &&other)
Definition: types.h:436
void unpack(byte *const dest[], const byte *source) const
frame_callback_ptr(rs_frame_callback *callback)
Definition: types.h:434
small_heap()
Definition: types.h:506
bool provides_stream(rs_stream stream) const
Definition: types.h:315
bool operator!=(const firmware_version &other) const
Definition: types.h:239
Definition: rscore.hpp:132
bool requires_processing() const
Definition: types.h:323
rs_format format
Definition: types.h:169
subdevice_mode_selection select_mode(const stream_request(&requests)[RS_STREAM_NATIVE_COUNT], int subdevice_index) const
frame_callback_ptr()
Definition: types.h:433
int get_unpacked_height() const
int num_libuvc_transfer_buffers
Definition: types.h:278
uint32_t pack(uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3)
Definition: types.h:490
rs_log_severity get_minimum_severity()
int delta2
Definition: types.h:181
float3 operator*(const float3 &a, float b)
Definition: types.h:115
Definition: rscore.hpp:146
bool operator==(const firmware_version &other) const
Definition: types.h:233
rs_event_source
Source device that triggered a specific timestamp event from the motion module.
Definition: rs.h:276
std::vector< interstream_rule > interstream_rules
Definition: types.h:274
const int RS_MAX_EVENT_QUEUE_SIZE
Definition: types.h:31
float y
Definition: types.h:110
void wait_until_empty()
Definition: types.h:561
int fps
Definition: types.h:159
frame_callback(rs_device *dev, frame_callback_function_ptr on_frame, void *user)
Definition: types.h:339
double def
Definition: types.h:190
rs_output_buffer_format
Output buffer format: sets how librealsense works with frame memory.
Definition: rs.h:73
size_t unpacker_index
Definition: types.h:297
#define LOG_ERROR(...)
Definition: types.h:80
int get_height() const
Definition: types.h:310
bool is_between(const firmware_version &from, const firmware_version &until)
Definition: types.h:243
bool operator>=(const firmware_version &other) const
Definition: types.h:241
supported_capability(rs_capabilities capability)
Definition: types.h:264