python.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/rs.hpp"
6 #include "../include/librealsense2/hpp/rs_export.hpp"
7 #include "types.h"
8 
10  m.doc() = R"pbdoc(
11  LibrealsenseTM Python Bindings
12  ==============================
13  Library for accessing Intel RealSenseTM cameras
14  )pbdoc";
15  m.attr("__version__") = RS2_API_VERSION_STR;
16 
17  init_c_files(m);
18  init_types(m);
19  init_frame(m);
20  init_options(m);
22  init_sensor(m);
23  init_device(m);
25  init_context(m);
27  init_internal(m); // must be run after init_frame()
28  init_export(m);
31  init_util(m);
32 
34  py::class_<rs2::save_to_ply, rs2::filter>(m, "save_to_ply")
35  .def(py::init<std::string, rs2::pointcloud>(), "filename"_a = "RealSense Pointcloud ", "pc"_a = rs2::pointcloud())
36  .def_property_readonly_static("option_ignore_color", [](py::object) { return rs2::save_to_ply::OPTION_IGNORE_COLOR; })
37  .def_property_readonly_static("option_ply_mesh", [](py::object) { return rs2::save_to_ply::OPTION_PLY_MESH; })
38  .def_property_readonly_static("option_ply_binary", [](py::object) { return rs2::save_to_ply::OPTION_PLY_BINARY; })
39  .def_property_readonly_static("option_ply_normals", [](py::object) { return rs2::save_to_ply::OPTION_PLY_NORMALS; })
40  .def_property_readonly_static("option_ply_threshold", [](py::object) { return rs2::save_to_ply::OPTION_PLY_THRESHOLD; });
41 
42  m.def("log_to_console", &rs2::log_to_console, "min_severity"_a);
43  m.def("log_to_file", &rs2::log_to_file, "min_severity"_a, "file_path"_a);
44  m.def("reset_logger", &rs2::reset_logger);
45  m.def("enable_rolling_log_file", &rs2::enable_rolling_log_file, "max_size"_a);
46 
47  // Access to log_message is only from a callback (see log_to_callback below) and so already
48  // should have the GIL acquired
49  py::class_<rs2::log_message> log_message(m, "log_message");
50  log_message.def("line_number", &rs2::log_message::line_number)
51  .def("filename", &rs2::log_message::filename)
52  .def("raw", &rs2::log_message::raw)
53  .def("full", &rs2::log_message::full)
54  .def("__str__", &rs2::log_message::raw)
55  .def("__repr__", &rs2::log_message::full);
56 
57  m.def("log_to_callback",
58  [](rs2_log_severity min_severity, std::function<void(rs2_log_severity, rs2::log_message)> callback)
59  {
60  rs2::log_to_callback( min_severity,
61  [callback]( rs2_log_severity severity, rs2::log_message const & msg ) noexcept
62  {
63  try
64  {
65  // We're not being called from Python but instead are calling it,
66  // we need to acquire it to not have issues with other threads...
67  py::gil_scoped_acquire gil;
68  callback( severity, msg );
69  }
70  catch( ... )
71  {
72  std::cerr << "?!?!?!!? exception in python log_to_callback callback ?!?!?!?!?" << std::endl;
73  }
74  } );
75  }, "min_severity"_a, "callback"_a);
76  // A call to rs.log() will cause a callback to get called! We should already own the GIL, but
77  // release it just in case to let others do their thing...
78  m.def("log", &rs2::log, "severity"_a, "message"_a, py::call_guard<py::gil_scoped_release>());
79 }
static const auto OPTION_IGNORE_COLOR
Definition: rs_export.hpp:37
void init_processing(bool use_glsl=true)
GLenum GLuint GLenum severity
void init_pipeline(py::module &m)
void init_sensor(py::module &m)
Definition: pyrs_sensor.cpp:9
void reset_logger()
Definition: rs.hpp:33
void log_to_callback(rs2_log_severity min_severity, S callback)
Definition: rs.hpp:139
const GLfloat * m
Definition: glext.h:6814
static const auto OPTION_PLY_THRESHOLD
Definition: rs_export.hpp:41
void log(rs2_log_severity severity, const char *message)
Definition: rs.hpp:149
void init_types(py::module &m)
Definition: pyrs_types.cpp:7
void init_util(py::module &m)
Definition: pyrsutil.cpp:7
const char * filename() const
Definition: rs.hpp:74
std::array< point3d, 4 > object
void init_serializable_device(py::module &m)
static const auto OPTION_PLY_NORMALS
Definition: rs_export.hpp:40
size_t line_number() const
Definition: rs.hpp:66
void init_frame(py::module &m)
Definition: pyrs_frame.cpp:7
void init_device(py::module &m)
Definition: pyrs_device.cpp:9
const char * raw() const
Definition: rs.hpp:82
def pointcloud(out, verts, texcoords, color, painter=True)
void init_context(py::module &m)
Definition: pyrs_context.cpp:7
def callback(frame)
Definition: t265_stereo.py:91
void log_to_file(rs2_log_severity min_severity, const char *file_path=nullptr)
Definition: rs.hpp:26
#define NAME
Definition: pybackend.cpp:26
void log_to_console(rs2_log_severity min_severity)
Definition: rs.hpp:19
void init_record_playback(py::module &m)
const char * full() const
Definition: rs.hpp:93
#define RS2_API_VERSION_STR
Definition: rs.h:43
PYBIND11_MODULE(NAME, m)
Definition: python.cpp:9
void enable_rolling_log_file(unsigned max_size)
Definition: rs.hpp:47
std::ostream & cerr()
void init_export(py::module &m)
Definition: pyrs_export.cpp:7
void init_c_files(py::module &m)
Definition: c_files.cpp:21
static const auto OPTION_PLY_BINARY
Definition: rs_export.hpp:39
rs2_log_severity
Severity of the librealsense logger.
Definition: rs_types.h:153
static const auto OPTION_PLY_MESH
Definition: rs_export.hpp:38
void init_advanced_mode(py::module &m)
void init_options(py::module &m)
Definition: pyrs_options.cpp:7
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