Open3D (C++ API)  0.11.0
Messages.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2020 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 #include <boost/predef/other/endian.h>
29 
30 #include <map>
31 #include <msgpack.hpp>
32 #include <string>
33 #include <vector>
34 
35 #if BOOST_ENDIAN_LITTLE_BYTE
36 #define ENDIANNESS_STR "<"
37 #elif BOOST_ENDIAN_BIG_BYTE
38 #define ENDIANNESS_STR ">"
39 #else
40 #error Cannot determine endianness
41 #endif
42 
43 namespace open3d {
44 namespace io {
45 namespace rpc {
46 namespace messages {
47 
50 template <class T>
51 inline std::string TypeStr() {
52  return "";
53 }
54 template <>
55 inline std::string TypeStr<float>() {
56  return ENDIANNESS_STR "f4";
57 }
58 template <>
59 inline std::string TypeStr<double>() {
60  return ENDIANNESS_STR "f8";
61 }
62 template <>
63 inline std::string TypeStr<int8_t>() {
64  return "|i1";
65 }
66 template <>
67 inline std::string TypeStr<int16_t>() {
68  return ENDIANNESS_STR "i2";
69 }
70 template <>
71 inline std::string TypeStr<int32_t>() {
72  return ENDIANNESS_STR "i4";
73 }
74 template <>
75 inline std::string TypeStr<int64_t>() {
76  return ENDIANNESS_STR "i8";
77 }
78 template <>
79 inline std::string TypeStr<uint8_t>() {
80  return "|u1";
81 }
82 template <>
83 inline std::string TypeStr<uint16_t>() {
84  return ENDIANNESS_STR "u2";
85 }
86 template <>
87 inline std::string TypeStr<uint32_t>() {
88  return ENDIANNESS_STR "u4";
89 }
90 template <>
91 inline std::string TypeStr<uint64_t>() {
92  return ENDIANNESS_STR "u8";
93 }
94 
95 #undef ENDIANNESS_STR
96 
117 struct Array {
118  static std::string MsgId() { return "array"; }
119 
120  template <class T>
121  static Array FromPtr(const T* const ptr,
122  const std::vector<int64_t>& shape) {
123  Array arr;
124  arr.type = TypeStr<T>();
125  arr.shape = shape;
126  arr.data.ptr = (const char*)ptr;
127  int64_t num = 1;
128  for (int64_t n : shape) num *= n;
129  arr.data.size = sizeof(T) * num;
130  return arr;
131  }
132  std::string type;
133  std::vector<int64_t> shape;
134  msgpack::type::raw_ref data;
135 
136  template <class T>
137  const T* Ptr() {
138  return (T*)data.ptr;
139  }
140 
141  // macro for creating the serialization/deserialization code
142  MSGPACK_DEFINE_MAP(type, shape, data);
143 };
144 
146 struct MeshData {
147  static std::string MsgId() { return "mesh_data"; }
148 
153  std::map<std::string, Array> vertex_attributes;
154 
163  std::map<std::string, Array> face_attributes;
164 
174  std::map<std::string, Array> line_attributes;
175 
177  std::map<std::string, Array> textures;
178 
179  MSGPACK_DEFINE_MAP(vertices,
180  vertex_attributes,
181  faces,
182  face_attributes,
183  lines,
184  line_attributes,
185  textures);
186 };
187 
190 struct SetMeshData {
191  static std::string MsgId() { return "set_mesh_data"; }
192 
193  SetMeshData() : time(0) {}
194 
196  std::string path;
200  std::string layer;
201 
204 
205  MSGPACK_DEFINE_MAP(path, time, layer, data);
206 };
207 
209 struct GetMeshData {
210  static std::string MsgId() { return "get_mesh_data"; }
211 
212  GetMeshData() : time(0) {}
213 
215  std::string path;
219  std::string layer;
220 
221  MSGPACK_DEFINE_MAP(path, time, layer);
222 };
223 
225 struct CameraData {
226  static std::string MsgId() { return "camera_data"; }
227 
228  CameraData() : width(0), height(0) {}
229 
230  // extrinsic parameters defining the world to camera transform, i.e.,
231  // X_cam = X_world * R + t
232 
234  std::array<double, 4> R;
236  std::array<double, 3> t;
237 
241  std::string intrinsic_model;
242  std::vector<double> intrinsic_parameters;
243 
245  int width;
246  int height;
247 
249  std::map<std::string, Array> images;
250 
252  R, t, intrinsic_model, intrinsic_parameters, width, height, images);
253 };
254 
258  static std::string MsgId() { return "set_camera_data"; }
259 
260  SetCameraData() : time(0) {}
261 
263  std::string path;
267  std::string layer;
268 
271 
272  MSGPACK_DEFINE_MAP(path, time, layer, data);
273 };
274 
277 struct SetTime {
278  static std::string MsgId() { return "set_time"; }
279  SetTime() : time(0) {}
281 
282  MSGPACK_DEFINE_MAP(time);
283 };
284 
288  static std::string MsgId() { return "set_active_camera"; }
289  std::string path;
290 
291  MSGPACK_DEFINE_MAP(path);
292 };
293 
297  static std::string MsgId() { return "set_properties"; }
298  std::string path;
299 
300  // application specific members go here.
301 
302  MSGPACK_DEFINE_MAP(path);
303 };
304 
307 struct Request {
308  std::string msg_id;
309  MSGPACK_DEFINE_MAP(msg_id);
310 };
311 
314 struct Reply {
315  std::string msg_id;
316  MSGPACK_DEFINE_MAP(msg_id);
317 };
318 
321 struct Status {
322  static std::string MsgId() { return "status"; }
323 
324  Status() : code(0) {}
325  Status(int code, const std::string& str) : code(code), str(str) {}
326  static Status OK() { return Status(); }
328  return Status(1, "unsupported msg_id");
329  }
331  return Status(2, "error during unpacking");
332  }
333 
337  std::string str;
338 
339  MSGPACK_DEFINE_MAP(code, str);
340 };
341 
342 } // namespace messages
343 } // namespace rpc
344 } // namespace io
345 } // namespace open3d
std::string msg_id
Definition: Messages.h:308
std::string msg_id
Definition: Messages.h:315
std::string TypeStr< float >()
Definition: Messages.h:55
std::string TypeStr< uint8_t >()
Definition: Messages.h:79
std::string path
Definition: Messages.h:298
Definition: Messages.h:117
int32_t time
The time for which to return the data.
Definition: Messages.h:265
static std::string MsgId()
Definition: Messages.h:226
std::string path
Path defining the location in the scene tree.
Definition: Messages.h:196
std::string TypeStr()
Definition: Messages.h:51
Status(int code, const std::string &str)
Definition: Messages.h:325
CameraData data
The data to be set.
Definition: Messages.h:270
std::string TypeStr< int64_t >()
Definition: Messages.h:75
int32_t time
The time associated with this data.
Definition: Messages.h:198
struct for storing MeshData, e.g., PointClouds, TriangleMesh, ..
Definition: Messages.h:146
Definition: Messages.h:321
std::string TypeStr< int8_t >()
Definition: Messages.h:63
static std::string MsgId()
Definition: Messages.h:118
std::string path
Definition: Messages.h:289
static std::string MsgId()
Definition: Messages.h:147
Definition: Messages.h:190
struct for storing camera data
Definition: Messages.h:225
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t int32_t
Definition: K4aPlugin.cpp:395
msgpack::type::raw_ref data
Definition: Messages.h:134
Definition: Messages.h:307
std::string path
Path defining the location in the scene tree.
Definition: Messages.h:215
Definition: Messages.h:277
const T * Ptr()
Definition: Messages.h:137
std::string path
Path defining the location in the scene tree.
Definition: Messages.h:263
std::map< std::string, Array > textures
map of arrays that can be interpreted as textures
Definition: Messages.h:177
GetMeshData()
Definition: Messages.h:212
static Status OK()
Definition: Messages.h:326
MSGPACK_DEFINE_MAP(type, shape, data)
std::vector< int64_t > shape
Definition: Messages.h:133
Array vertices
shape must be [num_verts,3]
Definition: Messages.h:150
Status()
Definition: Messages.h:324
static Status ErrorUnsupportedMsgId()
Definition: Messages.h:327
static std::string MsgId()
Definition: Messages.h:191
int height
Definition: Messages.h:246
std::string TypeStr< uint16_t >()
Definition: Messages.h:83
std::map< std::string, Array > face_attributes
stores arbitrary attributes for each face
Definition: Messages.h:163
std::map< std::string, Array > line_attributes
stores arbitrary attributes for each line
Definition: Messages.h:174
std::string TypeStr< uint32_t >()
Definition: Messages.h:87
std::string layer
The layer for which to return the data.
Definition: Messages.h:267
std::string TypeStr< uint64_t >()
Definition: Messages.h:91
static std::string MsgId()
Definition: Messages.h:210
static std::string MsgId()
Definition: Messages.h:258
Array lines
Definition: Messages.h:172
std::vector< double > intrinsic_parameters
Definition: Messages.h:242
std::string TypeStr< int16_t >()
Definition: Messages.h:67
int32_t time
The time for which to return the data.
Definition: Messages.h:217
std::string intrinsic_model
Definition: Messages.h:241
static std::string MsgId()
Definition: Messages.h:297
static std::string MsgId()
Definition: Messages.h:288
std::string TypeStr< int32_t >()
Definition: Messages.h:71
static std::string MsgId()
Definition: Messages.h:278
SetTime()
Definition: Messages.h:279
std::string str
string representation of the code
Definition: Messages.h:337
CameraData()
Definition: Messages.h:228
std::map< std::string, Array > images
map of arrays that can be interpreted as camera images
Definition: Messages.h:249
SetMeshData()
Definition: Messages.h:193
int32_t time
Definition: Messages.h:280
Definition: PinholeCameraIntrinsic.cpp:35
std::string layer
The layer for this data.
Definition: Messages.h:200
int height
Definition: FilePCD.cpp:72
std::array< double, 3 > t
translation
Definition: Messages.h:236
struct for defining a "get_mesh_data" message, which requests mesh data.
Definition: Messages.h:209
std::string layer
The layer for which to return the data.
Definition: Messages.h:219
MeshData data
The data to be set.
Definition: Messages.h:203
SetCameraData()
Definition: Messages.h:260
static Array FromPtr(const T *const ptr, const std::vector< int64_t > &shape)
Definition: Messages.h:121
Definition: Messages.h:314
int width
image dimensions in pixels
Definition: Messages.h:245
Array faces
Definition: Messages.h:161
std::array< double, 4 > R
rotation R as quaternion [x,y,z,w]
Definition: Messages.h:234
static Status ErrorUnpackingFailed()
Definition: Messages.h:330
static std::string MsgId()
Definition: Messages.h:322
std::map< std::string, Array > vertex_attributes
Definition: Messages.h:153
int32_t code
return code. 0 means everything is OK.
Definition: Messages.h:335
int width
Definition: FilePCD.cpp:71
std::string type
Definition: Messages.h:132
std::string TypeStr< double >()
Definition: Messages.h:59