4 #ifndef LIBREALSENSE_PYTHON_HPP 5 #define LIBREALSENSE_PYTHON_HPP 7 #include <pybind11/pybind11.h> 10 #include <pybind11/operators.h> 13 #include <pybind11/stl.h> 16 #include <pybind11/chrono.h> 19 #include <pybind11/stl_bind.h> 22 #include <pybind11/functional.h> 24 #define NAME pyrealsense2 25 #define SNAME "pyrealsense2" 27 #include "../include/librealsense2/h/rs_sensor.h" 29 namespace py = pybind11;
33 #define BIND_DOWNCAST(class, downcast) "is_"#downcast, &rs2::class::is<rs2::downcast>).def("as_"#downcast, &rs2::class::as<rs2::downcast> 38 #define BIND_ENUM(module, rs2_enum_type, RS2_ENUM_COUNT, docstring) BIND_ENUM_CUSTOM( module, rs2_enum_type, 0, RS2_ENUM_COUNT-1, docstring) 39 #define BIND_ENUM_CUSTOM(module, rs2_enum_type, FIRST, LAST, docstring) \ 40 static std::string rs2_enum_type##pyclass_name = std::string(#rs2_enum_type).substr(rs2_prefix.length()); \ 42 py::enum_<rs2_enum_type> py_##rs2_enum_type(module, rs2_enum_type##pyclass_name.c_str(), docstring); \ 44 for (int i = FIRST; i <= LAST; i++) \ 46 rs2_enum_type v = static_cast<rs2_enum_type>(i); \ 47 const char* enum_name = rs2_enum_type##_to_string(v); \ 48 auto python_name = make_pythonic_str(enum_name); \ 49 py_##rs2_enum_type.value(python_name.c_str(), v); \ 54 template<
typename T,
size_t SIZE>
57 for (
size_t i = 0;
i < SIZE;
i++)
63 template<
typename T,
size_t NROWS,
size_t NCOLS>
66 for (
size_t i = 0;
i < NROWS;
i++)
68 for (
size_t j = 0;
j < NCOLS;
j++)
74 template <
typename T,
size_t N>
77 std::ostringstream oss;
79 for (
int i = 0;
i < N;
i++)
89 template <
typename T,
size_t N,
size_t M>
92 std::ostringstream oss;
94 for (
int i = 0;
i < N;
i++)
99 for (
int j = 0;
j <
M;
j++)
111 #define BIND_RAW_ARRAY_GETTER(T, member, valueT, SIZE) [](const T& self) -> const std::array<valueT, SIZE>& { return reinterpret_cast<const std::array<valueT, SIZE>&>(self.member); } 112 #define BIND_RAW_ARRAY_SETTER(T, member, valueT, SIZE) [](T& self, const std::array<valueT, SIZE>& src) { copy_raw_array(self.member, src); } 114 #define BIND_RAW_2D_ARRAY_GETTER(T, member, valueT, NROWS, NCOLS) [](const T& self) -> const std::array<std::array<valueT, NCOLS>, NROWS>& { return reinterpret_cast<const std::array<std::array<valueT, NCOLS>, NROWS>&>(self.member); } 115 #define BIND_RAW_2D_ARRAY_SETTER(T, member, valueT, NROWS, NCOLS) [](T& self, const std::array<std::array<valueT, NCOLS>, NROWS>& src) { copy_raw_2d_array(self.member, src); } 117 #define BIND_RAW_ARRAY_PROPERTY(T, member, valueT, SIZE) #member, BIND_RAW_ARRAY_GETTER(T, member, valueT, SIZE), BIND_RAW_ARRAY_SETTER(T, member, valueT, SIZE) 118 #define BIND_RAW_2D_ARRAY_PROPERTY(T, member, valueT, NROWS, NCOLS) #member, BIND_RAW_2D_ARRAY_GETTER(T, member, valueT, NROWS, NCOLS), BIND_RAW_2D_ARRAY_SETTER(T, member, valueT, NROWS, NCOLS) 123 #define MAP_FMT_TO_TYPE(F, T) template <> struct FmtToType<F> { using type = T; } 159 template<
template<rs2_format>
class F>
191 case RS2_FORMAT_COUNT:
throw std::runtime_error(
"format.count is not a valid value for arguments of type format!");
199 void *_ptr =
nullptr;
200 size_t _itemsize = 0;
207 : _ptr(ptr), _itemsize(itemsize), _format(format), _ndim(ndim), _shape(shape), _strides(strides) {}
237 #endif // LIBREALSENSE_PYTHON_HPP
auto fmt_to_value(rs2_format fmt) -> typename std::result_of< decltype(&F< RS2_FORMAT_ANY >::func)()>::type
void init_context(py::module &m)
std::string matrix_to_string(const T(&arr)[N][M])
std::string array_to_string(const T(&arr)[N])
static constexpr size_t func()
BufData(void *ptr, size_t itemsize, const std::string &format, size_t dim, size_t count)
GLsizei const GLchar *const * string
void copy_raw_array(T(&dst)[SIZE], const std::array< T, SIZE > &src)
void copy_raw_2d_array(T(&dst)[NROWS][NCOLS], const std::array< std::array< T, NCOLS >, NROWS > &src)
static const std::string func()
std::string make_pythonic_str(std::string str)
void init_device(py::module &m)
GLsizei const GLuint const GLintptr const GLsizei * strides
void init_internal(py::module &m)
void init_record_playback(py::module &m)
void init_export(py::module &m)
GLint GLint GLsizei GLint GLenum format
BufData(void *ptr, size_t itemsize, const std::string &format, size_t size)
rs2_format
A stream's format identifies how binary data is encoded within a frame.
void init_util(py::module &m)
BufData(void *ptr, size_t itemsize, const std::string &format, size_t ndim, const std::vector< size_t > &shape, const std::vector< size_t > &strides)
#define MAP_FMT_TO_TYPE(F, T)
const std::string rs2_prefix
std::vector< size_t > _shape
void init_pipeline(py::module &m)
void init_sensor(py::module &m)
void init_advanced_mode(py::module &m)
void init_frame(py::module &m)
void init_processing(py::module &m)
std::vector< size_t > _strides
void init_options(py::module &m)
void init_serializable_device(py::module &m)
void init_types(py::module &m)
void init_c_files(py::module &m)