pyrs_internal.cpp
Go to the documentation of this file.
1 /* License: Apache 2.0. See LICENSE file in root directory.
2 Copyright(c) 2017 Intel Corporation. All Rights Reserved. */
3 
4 #include "python.hpp"
5 #include "../include/librealsense2/hpp/rs_internal.hpp"
6 #include <cstring>
7 
8 void init_internal(py::module &m) {
10  py::class_<rs2_video_stream> video_stream(m, "video_stream", "All the parameters"
11  " required to define a video stream.");
12  video_stream.def(py::init<>())
13  .def_readwrite("type", &rs2_video_stream::type)
14  .def_readwrite("index", &rs2_video_stream::index)
15  .def_readwrite("uid", &rs2_video_stream::uid)
16  .def_readwrite("width", &rs2_video_stream::width)
17  .def_readwrite("height", &rs2_video_stream::height)
18  .def_readwrite("fps", &rs2_video_stream::fps)
19  .def_readwrite("bpp", &rs2_video_stream::bpp)
20  .def_readwrite("fmt", &rs2_video_stream::fmt)
21  .def_readwrite("intrinsics", &rs2_video_stream::intrinsics);
22 
23  py::class_<rs2_motion_stream> motion_stream(m, "motion_stream", "All the parameters"
24  " required to define a motion stream.");
25  motion_stream.def(py::init<>())
26  .def_readwrite("type", &rs2_motion_stream::type)
27  .def_readwrite("index", &rs2_motion_stream::index)
28  .def_readwrite("uid", &rs2_motion_stream::uid)
29  .def_readwrite("fps", &rs2_motion_stream::fps)
30  .def_readwrite("fmt", &rs2_motion_stream::fmt)
31  .def_readwrite("intrinsics", &rs2_motion_stream::intrinsics);
32 
33  py::class_<rs2_pose_stream> pose_stream(m, "pose_stream", "All the parameters"
34  " required to define a pose stream.");
35  pose_stream.def(py::init<>())
36  .def_readwrite("type", &rs2_pose_stream::type)
37  .def_readwrite("index", &rs2_pose_stream::index)
38  .def_readwrite("uid", &rs2_pose_stream::uid)
39  .def_readwrite("fps", &rs2_pose_stream::fps)
40  .def_readwrite("fmt", &rs2_pose_stream::fmt);
41 
42  py::class_<rs2_software_video_frame> software_video_frame(m, "software_video_frame", "All the parameters "
43  "required to define a video frame.");
44  software_video_frame.def(py::init([]() { rs2_software_video_frame f{}; f.deleter = nullptr; return f; })) // guarantee deleter is set to nullptr
45  .def_property("pixels", [](const rs2_software_video_frame& self) {
46  // TODO: Not all formats (e.g. RAW10) are properly handled (see struct FmtToType in python.hpp)
48  size_t size = fmt_to_value<itemsize>(vp.format());
49  size_t upp = self.bpp / size;
50  if (upp == 1)
51  return BufData(self.pixels, size, fmt_to_value<fmtstring>(vp.format()), 2,
52  { (size_t)vp.height(), (size_t)vp.width() }, { vp.width()*size, size });
53  else
54  return BufData(self.pixels, size, fmt_to_value<fmtstring>(vp.format()), 3,
55  { (size_t)vp.height(), (size_t)vp.width(), upp }, { vp.width()*upp*size, upp*size, size });
57  if (self.deleter) self.deleter(self.pixels);
58  auto data = buf.request();
59  self.pixels = new uint8_t[data.size*data.itemsize]; // fwiw, might be possible to convert data.format -> underlying data type
60  std::memcpy(self.pixels, data.ptr, data.size*data.itemsize);
61  self.deleter = [](void* ptr){ delete[] ptr; };
62  })
63  .def_readwrite("stride", &rs2_software_video_frame::stride)
64  .def_readwrite("bpp", &rs2_software_video_frame::bpp)
65  .def_readwrite("timestamp", &rs2_software_video_frame::timestamp)
66  .def_readwrite("domain", &rs2_software_video_frame::domain)
67  .def_readwrite("frame_number", &rs2_software_video_frame::frame_number)
68  .def_property("profile", [](const rs2_software_video_frame& self) { return rs2::stream_profile(self.profile).as<rs2::video_stream_profile>(); },
69  [](rs2_software_video_frame& self, rs2::video_stream_profile profile) { self.profile = profile.get(); });
70 
71  py::class_<rs2_software_motion_frame> software_motion_frame(m, "software_motion_frame", "All the parameters "
72  "required to define a motion frame.");
73  software_motion_frame.def(py::init([]() { rs2_software_motion_frame f{}; f.deleter = nullptr; return f; })) // guarantee deleter is set to nullptr
74  .def_property("data", [](const rs2_software_motion_frame& self) -> rs2_vector {
75  auto data = reinterpret_cast<const float*>(self.data);
76  return rs2_vector{ data[0], data[1], data[2] };
78  if (self.deleter) self.deleter(self.data);
79  self.data = new float[3];
80  float *dptr = reinterpret_cast<float*>(self.data);
81  dptr[0] = data.x;
82  dptr[1] = data.y;
83  dptr[2] = data.z;
84  self.deleter = [](void* ptr){ delete[] ptr; };
85  })
86  .def_readwrite("timestamp", &rs2_software_motion_frame::timestamp)
87  .def_readwrite("domain", &rs2_software_motion_frame::domain)
88  .def_readwrite("frame_number", &rs2_software_motion_frame::frame_number)
89  .def_property("profile", [](const rs2_software_motion_frame& self) { return rs2::stream_profile(self.profile).as<rs2::motion_stream_profile>(); },
90  [](rs2_software_motion_frame& self, rs2::motion_stream_profile profile) { self.profile = profile.get(); });
91 
92  py::class_<rs2_software_pose_frame> software_pose_frame(m, "software_pose_frame", "All the parameters "
93  "required to define a pose frame.");
94  software_pose_frame.def(py::init([]() { rs2_software_pose_frame f{}; f.deleter = nullptr; return f; })) // guarantee deleter is set to nullptr
95  .def_property("data", [](const rs2_software_pose_frame& self) -> rs2_pose {
96  return *reinterpret_cast<const rs2_pose*>(self.data);
97  }, [](rs2_software_pose_frame& self, rs2_pose data) {
98  if (self.deleter) self.deleter(self.data);
99  self.data = new rs2_pose(data);
100  self.deleter = [](void* ptr){ delete[] ptr; };
101  })
102  .def_readwrite("timestamp", &rs2_software_pose_frame::timestamp)
103  .def_readwrite("domain", &rs2_software_pose_frame::domain)
104  .def_readwrite("frame_number", &rs2_software_pose_frame::frame_number)
105  .def_property("profile", [](const rs2_software_pose_frame& self) { return rs2::stream_profile(self.profile).as<rs2::pose_stream_profile>(); },
106  [](rs2_software_pose_frame& self, rs2::pose_stream_profile profile) { self.profile = profile.get(); });
107 
108  py::class_<rs2_software_notification> software_notification(m, "software_notification", "All the parameters "
109  "required to define a sensor notification.");
110  software_notification.def(py::init<>())
111  .def_readwrite("category", &rs2_software_notification::category)
112  .def_readwrite("type", &rs2_software_notification::type)
113  .def_readwrite("severity", &rs2_software_notification::severity)
114  .def_readwrite("description", &rs2_software_notification::description)
115  .def_readwrite("serialized_data", &rs2_software_notification::serialized_data);
119  // rs2::software_sensor
120  py::class_<rs2::software_sensor> software_sensor(m, "software_sensor");
121  software_sensor.def("add_video_stream", &rs2::software_sensor::add_video_stream, "Add video stream to software sensor",
122  "video_stream"_a, "is_default"_a=false)
123  .def("add_motion_stream", &rs2::software_sensor::add_motion_stream, "Add motion stream to software sensor",
124  "motion_stream"_a, "is_default"_a = false)
125  .def("add_pose_stream", &rs2::software_sensor::add_pose_stream, "Add pose stream to software sensor",
126  "pose_stream"_a, "is_default"_a = false)
127  .def("on_video_frame", &rs2::software_sensor::on_video_frame, "Inject video frame into the sensor", "frame"_a)
128  .def("on_motion_frame", &rs2::software_sensor::on_motion_frame, "Inject motion frame into the sensor", "frame"_a)
129  .def("on_pose_frame", &rs2::software_sensor::on_pose_frame, "Inject pose frame into the sensor", "frame"_a)
130  .def("set_metadata", &rs2::software_sensor::set_metadata, "Set frame metadata for the upcoming frames", "value"_a, "type"_a)
131  .def("add_read_only_option", &rs2::software_sensor::add_read_only_option, "Register read-only option that "
132  "will be supported by the sensor", "option"_a, "val"_a)
133  .def("set_read_only_option", &rs2::software_sensor::set_read_only_option, "Update value of registered "
134  "read-only option", "option"_a, "val"_a)
135  .def("add_option", &rs2::software_sensor::add_option, "Register option that will be supported by the sensor",
136  "option"_a, "range"_a, "is_writable"_a=true)
137  .def("on_notification", &rs2::software_sensor::on_notification, "notif"_a);
138 
139  // rs2::software_device
140  py::class_<rs2::software_device> software_device(m, "software_device");
141  software_device.def(py::init<>())
142  .def("add_sensor", &rs2::software_device::add_sensor, "Add software sensor with given name "
143  "to the software device.", "name"_a)
144  .def("set_destruction_callback", &rs2::software_device::set_destruction_callback<std::function<void()>>,
145  "Register destruction callback", "callback"_a)
146  .def("add_to", &rs2::software_device::add_to, "Add software device to existing context.\n"
147  "Any future queries on the context will return this device.\n"
148  "This operation cannot be undone (except for destroying the context)", "ctx"_a)
149  .def("register_info", &rs2::software_device::register_info, "Add a new camera info value, like serial number",
150  "info"_a, "val"_a)
151  .def("update_info", &rs2::software_device::update_info, "Update an existing camera info value, like serial number",
152  "info"_a, "val"_a);
153  //.def("create_matcher", &rs2::software_device::create_matcher, "Set the wanted matcher type that will "
154  // "be used by the syncer", "matcher"_a) // TODO: bind rs2_matchers enum.
155 
156  // rs2::firmware_log_message
157  py::class_<rs2::firmware_log_message> firmware_log_message(m, "firmware_log_message");
158  firmware_log_message.def("get_severity", &rs2::firmware_log_message::get_severity, "Get severity ")
159  .def("get_severity_str", &rs2::firmware_log_message::get_severity_str, "Get severity string ")
160  .def("get_timestamp", &rs2::firmware_log_message::get_timestamp, "Get timestamp ")
161  .def("get_data", &rs2::firmware_log_message::data, "Get data ")
162  .def("get_size", &rs2::firmware_log_message::size, "Get size ");
163 
164  // rs2::firmware_log_parsed_message
165  py::class_<rs2::firmware_log_parsed_message> firmware_log_parsed_message(m, "firmware_log_parsed_message");
166  firmware_log_parsed_message.def("get_message", &rs2::firmware_log_parsed_message::message, "Get message ")
167  .def("get_file_name", &rs2::firmware_log_parsed_message::file_name, "Get file name ")
168  .def("get_thread_name", &rs2::firmware_log_parsed_message::thread_name, "Get thread name ")
169  .def("get_severity", &rs2::firmware_log_parsed_message::severity, "Get severity ")
170  .def("get_line", &rs2::firmware_log_parsed_message::line, "Get line ")
171  .def("get_timestamp", &rs2::firmware_log_parsed_message::timestamp, "Get timestamp ")
172  .def("get_sequence_id", &rs2::firmware_log_parsed_message::sequence_id, "Get sequence id");
173 
174  // rs2::firmware_logger
175  py::class_<rs2::firmware_logger, rs2::device> firmware_logger(m, "firmware_logger");
176  firmware_logger.def(py::init<rs2::device>(), "device"_a)
177  .def("create_message", &rs2::firmware_logger::create_message, "Create FW Log")
178  .def("create_parsed_message", &rs2::firmware_logger::create_parsed_message, "Create FW Parsed Log")
179  .def("get_number_of_fw_logs", &rs2::firmware_logger::get_number_of_fw_logs, "Get Number of Fw Logs Polled From Device")
180  .def("get_firmware_log", &rs2::firmware_logger::get_firmware_log, "Get FW Log", "msg"_a)
181  .def("get_flash_log", &rs2::firmware_logger::get_flash_log, "Get Flash Log", "msg"_a)
182  .def("init_parser", &rs2::firmware_logger::init_parser, "Initialize Parser with content of xml file",
183  "xml_content"_a)
184  .def("parse_log", &rs2::firmware_logger::parse_log, "Parse Fw Log ", "msg"_a, "parsed_msg"_a);
185 
186  // rs2::terminal_parser
187  py::class_<rs2::terminal_parser> terminal_parser(m, "terminal_parser");
188  terminal_parser.def(py::init<const std::string&>(), "xml_content"_a)
189  .def("parse_command", &rs2::terminal_parser::parse_command, "Parse Command ", "cmd"_a)
190  .def("parse_response", &rs2::terminal_parser::parse_response, "Parse Response ", "cmd"_a, "response"_a);
191 
193 }
unsigned int get_number_of_fw_logs() const
rs2_format fmt
Definition: rs_internal.h:50
rs2::firmware_log_message create_message()
stream_profile add_pose_stream(rs2_pose_stream pose_stream, bool is_default=false)
rs2_log_severity get_severity() const
rs2_stream type
Definition: rs_internal.h:57
rs2_stream type
Definition: rs_internal.h:68
const GLfloat * m
Definition: glext.h:6814
std::vector< uint8_t > parse_command(const std::string &command)
void register_info(rs2_camera_info info, const std::string &val)
bool get_firmware_log(rs2::firmware_log_message &msg) const
void on_video_frame(rs2_software_video_frame frame)
void set_metadata(rs2_frame_metadata_value value, rs2_metadata_type type)
All the parameters required to define a pose frame.
Definition: rs_internal.h:100
std::string parse_response(const std::string &command, const std::vector< uint8_t > &response)
rs2_stream type
Definition: rs_internal.h:43
void on_motion_frame(rs2_software_motion_frame frame)
software_sensor add_sensor(std::string name)
rs2_timestamp_domain domain
Definition: rs_internal.h:94
unsigned char uint8_t
Definition: stdint.h:78
uint32_t get_timestamp() const
const char * serialized_data
Definition: rs_internal.h:128
stream_profile add_motion_stream(rs2_motion_stream motion_stream, bool is_default=false)
GLenum GLfloat * buffer
rs2_timestamp_domain domain
Definition: rs_internal.h:116
void set_read_only_option(rs2_option option, float val)
std::string severity() const
bool parse_log(const rs2::firmware_log_message &msg, const rs2::firmware_log_parsed_message &parsed_msg)
GLenum GLuint GLenum GLsizei const GLchar * buf
rs2::firmware_log_parsed_message create_parsed_message()
GLdouble f
GLsizeiptr size
std::string thread_name() const
rs2_log_severity severity
Definition: rs_internal.h:126
void(* deleter)(void *)
Definition: rs_internal.h:114
rs2_notification_category category
Definition: rs_internal.h:124
void init(void)
Definition: boing.c:180
std::string message() const
void update_info(rs2_camera_info info, const std::string &val)
rs2_format fmt
Definition: rs_internal.h:72
GLint GLint GLsizei GLint GLenum GLenum const void * pixels
rs2_format fmt
Definition: rs_internal.h:61
std::string get_severity_str() const
bool get_flash_log(rs2::firmware_log_message &msg) const
void set_destruction_callback(T callback) const
void on_notification(rs2_software_notification notif)
void add_to(context &ctx)
3D vector in Euclidean coordinate space
Definition: rs_types.h:129
void(* deleter)(void *)
Definition: rs_internal.h:92
void on_pose_frame(rs2_software_pose_frame frame)
All the parameters required to define a motion frame.
Definition: rs_internal.h:89
rs2_timestamp_domain domain
Definition: rs_internal.h:83
rs2_motion_device_intrinsic intrinsics
Definition: rs_internal.h:62
void add_option(rs2_option option, const option_range &range, bool is_writable=true)
bool init_parser(const std::string &xml_content)
void add_read_only_option(rs2_option option, float val)
std::string file_name() const
rs2_intrinsics intrinsics
Definition: rs_internal.h:51
struct rs2_pose rs2_pose
All the parameters required to define a video frame.
Definition: rs_internal.h:76
void(* deleter)(void *)
Definition: rs_internal.h:79
GLboolean * data
stream_profile add_video_stream(rs2_video_stream video_stream, bool is_default=false)
Definition: rs_internal.hpp:96
Definition: parser.hpp:150
std::vector< uint8_t > data() const
void init_internal(py::module &m)


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:39