28 py::module m_rpc = m_io.def_submodule(
"rpc");
30 auto atexit = py::module::import(
"atexit");
31 atexit.attr(
"register")(
34 py::class_<rpc::ConnectionBase, std::shared_ptr<rpc::ConnectionBase>>(
35 m_rpc,
"_ConnectionBase");
37 py::class_<rpc::Connection, std::shared_ptr<rpc::Connection>,
39 The default connection class which uses a ZeroMQ socket.
41 .def(py::init([](std::string address, int connect_timeout,
43 return std::shared_ptr<rpc::Connection>(
47 "Creates a connection object",
48 "address"_a =
"tcp://127.0.0.1:51454",
49 "connect_timeout"_a = 5000,
"timeout"_a = 10000);
51 py::class_<rpc::BufferConnection, std::shared_ptr<rpc::BufferConnection>,
53 A connection writing to a memory buffer.
61 "Returns a copy of the buffer.");
63 py::class_<rpc::DummyReceiver, std::shared_ptr<rpc::DummyReceiver>>(
64 m_rpc,
"_DummyReceiver",
65 "Dummy receiver for the server side receiving requests from a "
67 .def(py::init([](
const std::string& address,
int timeout) {
68 return std::shared_ptr<rpc::DummyReceiver>(
71 "Creates the receiver object which can be used for testing "
73 "address"_a =
"tcp://127.0.0.1:51454",
"timeout"_a = 10000)
75 "Starts the receiver mainloop in a new thread.")
77 "Stops the receiver mainloop and joins the thread. This "
78 "function blocks until the mainloop is done with processing "
79 "messages that have already been received.");
82 "Destroys the ZMQ context.");
85 "time"_a = 0,
"layer"_a =
"",
86 "connection"_a = std::shared_ptr<rpc::Connection>(),
87 "Sends a point cloud message to a viewer.");
89 m_rpc,
"set_point_cloud",
91 {
"pcd",
"Point cloud object."},
92 {
"path",
"A path descriptor, e.g., 'mygroup/points'."},
93 {
"time",
"The time associated with this data."},
94 {
"layer",
"The layer associated with this data."},
96 "A Connection object. Use None to automatically create "
100 m_rpc.def(
"set_triangle_mesh",
101 py::overload_cast<
const ccMesh&,
const std::string&,
int,
103 std::shared_ptr<rpc::ConnectionBase>>(
105 "mesh"_a,
"path"_a =
"",
"time"_a = 0,
"layer"_a =
"",
106 "connection"_a = std::shared_ptr<rpc::ConnectionBase>(),
107 R
"doc(Sends a triangle mesh to a viewer.
109 mesh (ccMesh): The triangle mesh.
110 path (str): The path in the scene graph.
111 time (int): The time associated with the data.
112 layer (str): A layer name that can be used by receivers that support layers.
113 connection (cv3d.io.rpc.Connection): A connection object that will be used for sending the data.
116 Returns True if the data was successfully received.
119 m_rpc.def("set_triangle_mesh",
121 const std::string&,
int,
const std::string&,
122 std::shared_ptr<rpc::ConnectionBase>>(
124 "mesh"_a,
"path"_a =
"",
"time"_a = 0,
"layer"_a =
"",
125 "connection"_a = std::shared_ptr<rpc::ConnectionBase>(),
126 R
"doc(Sends a triangle mesh to a viewer.
128 mesh (cv3d.t.geometry.TriangleMesh): The triangle mesh.
129 path (str): The path in the scene graph.
130 time (int): The time associated with the data.
131 layer (str): A layer name that can be used by receivers that support layers.
132 connection (cv3d.io.rpc.Connection): A connection object that will be used for sending the data.
135 Returns True if the data was successfully received.
140 "vertex_attributes"_a = std::map<std::string, core::Tensor>(),
142 "face_attributes"_a = std::map<std::string, core::Tensor>(),
144 "line_attributes"_a = std::map<std::string, core::Tensor>(),
146 "material_scalar_attributes"_a = std::map<std::string, float>(),
147 "material_vector_attributes"_a =
148 std::map<std::string, Eigen::Vector4f>(),
149 "texture_maps"_a = std::map<std::string, t::geometry::Image>(),
151 "connection"_a = std::shared_ptr<rpc::ConnectionBase>(),
152 "Sends a set_mesh_data message.");
154 m_rpc,
"set_mesh_data",
156 {
"path",
"A path descriptor, e.g., 'mygroup/points'."},
157 {
"time",
"The time associated with this data."},
158 {
"layer",
"The layer associated with this data."},
159 {
"vertices",
"Tensor defining the vertices."},
160 {
"vertex_attributes",
161 "dict of Tensors with vertex attributes."},
162 {
"faces",
"Tensor defining the faces with vertex indices."},
164 "dict of Tensors with face attributes."},
165 {
"lines",
"Tensor defining lines with vertex indices."},
167 "dict of Tensors with line attributes."},
169 "Basic Material for geometry drawing. Must be non-empty "
170 "if any material attributes or texture maps are "
172 {
"material_scalar_attributes",
173 "dict of material scalar attributes for geometry drawing "
174 "(e.g. ``point_size``, ``line_width`` or "
175 "``base_reflectance``)."},
176 {
"material_vector_attributes",
177 "dict of material Vector4f attributes for geometry "
178 "drawing (e.g. ``base_color`` or ``absorption_color``)"},
179 {
"texture_maps",
"dict of Images with textures."},
180 {
"o3d_type", R
"doc(The type of the geometry. This is one of
181 ``PointCloud``, ``LineSet``, ``TriangleMesh``. This argument should be
182 specified for partial data that has no primary key data, e.g., a
183 triangle mesh without vertices but with other attribute tensors.)doc"},
185 "A Connection object. Use None to automatically create "
190 "path"_a =
"",
"time"_a = 0,
"layer"_a =
"",
191 "connection"_a = std::shared_ptr<rpc::ConnectionBase>(),
192 "Sends a PinholeCameraParameters object.");
194 m_rpc,
"set_legacy_camera",
196 {
"path",
"A path descriptor, e.g., 'mygroup/camera'."},
197 {
"time",
"The time associated with this data."},
198 {
"layer",
"The layer associated with this data."},
200 "A Connection object. Use None to automatically create "
205 "connection"_a = std::shared_ptr<rpc::ConnectionBase>(),
206 "Sets the time in the external visualizer.");
210 {
"time",
"The time value to set."},
212 "A Connection object. Use None to automatically create "
217 "connection"_a = std::shared_ptr<rpc::ConnectionBase>(),
218 "Sets the object with the specified path as the active camera.");
220 m_rpc,
"set_active_camera",
222 {
"path",
"A path descriptor, e.g., 'mygroup/camera'."},
224 "A Connection object. Use None to automatically create "
230 This function returns the geometry, the path and the time stored in a
231 SetMeshData message. data must contain the Request header message followed
232 by the SetMeshData message. The function returns None for the geometry if not
Implements a connection writing to a buffer.
Base class for all connections.
void Start()
Starts the receiver mainloop in a new thread.
A triangle mesh contains vertices and triangles.
void FunctionDocInject(py::module &pybind_module, const std::string &function_name, const std::unordered_map< std::string, std::string > &map_parameter_body_docs)
bool SetTriangleMesh(const ccMesh &mesh, const std::string &path, int time, const std::string &layer, std::shared_ptr< ConnectionBase > connection)
std::tuple< std::string, double, std::shared_ptr< t::geometry::Geometry > > DataBufferToMetaGeometry(std::string &data)
bool SetPointCloud(const ccPointCloud &pcd, const std::string &path, int time, const std::string &layer, std::shared_ptr< ConnectionBase > connection)
bool SetActiveCamera(const std::string &path, std::shared_ptr< ConnectionBase > connection)
bool SetLegacyCamera(const camera::PinholeCameraParameters &camera, const std::string &path, int time, const std::string &layer, std::shared_ptr< ConnectionBase > connection)
bool SetMeshData(const std::string &path, int time, const std::string &layer, const core::Tensor &vertices, const std::map< std::string, core::Tensor > &vertex_attributes, const core::Tensor &faces, const std::map< std::string, core::Tensor > &face_attributes, const core::Tensor &lines, const std::map< std::string, core::Tensor > &line_attributes, const std::string &material, const std::map< std::string, float > &material_scalar_attributes, const std::map< std::string, std::array< float, 4 >> &material_vector_attributes, const std::map< std::string, t::geometry::Image > &texture_maps, const std::string &o3d_type, std::shared_ptr< ConnectionBase > connection)
bool SetTime(int time, std::shared_ptr< ConnectionBase > connection)
void pybind_rpc(py::module &m)
Generic file read and write utility for python interface.