13 #include <msgpack.hpp>
25 auto IsLittleEndian = []() ->
bool {
30 std::memcpy(&b, &a,
sizeof(uint8_t));
34 return IsLittleEndian() ?
"<" :
">";
105 static std::string
MsgId() {
return "array"; }
111 const std::vector<int64_t>&
shape) {
113 arr.
type = TypeStr<T>();
115 arr.
data.ptr = (
const char*)ptr;
117 for (int64_t n :
shape) num *= n;
129 auto arr = messages::Array::FromPtr(
130 (scalar_t*)t.GetDataPtr(),
131 static_cast<std::vector<int64_t>>(t.GetShape()));
153 std::string& errstr)
const {
154 for (
auto rank : expected_ranks) {
155 if (
shape.size() ==
size_t(rank))
return true;
157 errstr +=
" expected rank to be in (";
158 for (
auto rank : expected_ranks) {
159 errstr += std::to_string(rank) +
", ";
161 errstr += std::string(
")") +
" but got shape [";
162 for (
auto d :
shape) {
163 errstr += std::to_string(d) +
", ";
168 bool CheckRank(
const std::vector<int>& expected_ranks)
const {
177 std::string& errstr)
const {
182 for (
size_t i = 0; i < expected_shape.size(); ++i) {
183 int64_t d_expected = expected_shape[i];
184 int64_t d =
shape[i];
185 if ((d_expected != -1 && d_expected != d) || d < 0) {
186 errstr +=
" expected shape [";
187 for (
auto d : expected_shape) {
191 errstr += std::to_string(d) +
", ";
194 errstr +=
"] but got [";
195 for (
auto d :
shape) {
196 errstr += std::to_string(d) +
", ";
204 bool CheckShape(
const std::vector<int64_t>& expected_shape)
const {
214 for (
auto d :
shape) n *= d;
215 if (0 == n ||
shape.empty()) {
216 errstr +=
" expected non empty array but got array with shape [";
217 for (
auto d :
shape) {
218 errstr += std::to_string(d) +
", ";
233 bool CheckType(
const std::vector<std::string>& expected_types,
234 std::string& errstr)
const {
235 for (
const auto& t : expected_types) {
236 if (t ==
type)
return true;
238 errstr +=
" expected array type to be one of (";
239 for (
const auto& t : expected_types) {
242 errstr +=
") but got " +
type;
245 bool CheckType(
const std::vector<std::string>& expected_types)
const {
256 static std::string
MsgId() {
return "mesh_data"; }
310 std::string tmp =
"invalid vertices array:";
313 if (!status) errstr += tmp;
320 std::string tmp =
"invalid faces array:";
344 tmp +=
" expected shape [?, >2] but got [" +
361 " invalid o3d_type. Expected 'PointCloud', 'TriangleMesh', "
362 "or 'LineSet' but got '" +
369 std::string tmp =
"invalid mesh_data message:";
372 if (!status) errstr += tmp;
392 static std::string
MsgId() {
return "set_mesh_data"; }
411 static std::string
MsgId() {
return "get_mesh_data"; }
427 static std::string
MsgId() {
return "camera_data"; }
435 std::array<double, 4>
R;
437 std::array<double, 3>
t;
459 static std::string
MsgId() {
return "set_camera_data"; }
479 static std::string
MsgId() {
return "set_time"; }
489 static std::string
MsgId() {
return "set_active_camera"; }
498 static std::string
MsgId() {
return "set_properties"; }
523 static std::string
MsgId() {
return "status"; }
529 return Status(1,
"unsupported msg_id");
532 return Status(2,
"error during unpacking");
535 return Status(3,
"error while processing message");
#define DISPATCH_DTYPE_TO_TEMPLATE(DTYPE,...)
Definition: Dispatch.h:30
Tensor Contiguous() const
Definition: Tensor.cpp:740
Tensor To(Dtype dtype, bool copy=false) const
Definition: Tensor.cpp:707
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 timeout_in_ms capture_handle capture_handle capture_handle image_handle temperature_c k4a_image_t image_handle uint8_t image_handle image_handle image_handle image_handle uint32_t
Definition: K4aPlugin.cpp:548
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 timeout_in_ms capture_handle capture_handle capture_handle image_handle temperature_c int
Definition: K4aPlugin.cpp:474
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
std::string TypeStr()
Definition: Messages.h:40
std::string TypeStr< int8_t >()
Definition: Messages.h:52
std::string TypeStr< uint64_t >()
Definition: Messages.h:80
std::string TypeStr< int16_t >()
Definition: Messages.h:56
std::string EndiannessStr()
Definition: Messages.h:24
std::string TypeStr< float >()
Definition: Messages.h:44
std::string TypeStr< double >()
Definition: Messages.h:48
std::string TypeStr< uint8_t >()
Definition: Messages.h:68
std::string TypeStr< int32_t >()
Definition: Messages.h:60
std::string TypeStr< int64_t >()
Definition: Messages.h:64
std::string TypeStr< uint32_t >()
Definition: Messages.h:76
std::string TypeStr< uint16_t >()
Definition: Messages.h:72
Definition: PinholeCameraIntrinsic.cpp:16
Definition: Messages.h:104
bool CheckNonEmpty() const
Definition: Messages.h:225
bool CheckRank(const std::vector< int > &expected_ranks, std::string &errstr) const
Definition: Messages.h:152
const T * Ptr() const
Definition: Messages.h:146
MSGPACK_DEFINE_MAP(type, shape, data)
static Array FromTensor(const core::Tensor &tensor)
Definition: Messages.h:125
bool CheckNonEmpty(std::string &errstr) const
Definition: Messages.h:212
bool CheckType(const std::vector< std::string > &expected_types) const
Definition: Messages.h:245
std::string type
Definition: Messages.h:141
static Array FromPtr(const T *const ptr, const std::vector< int64_t > &shape)
Definition: Messages.h:110
bool CheckShape(const std::vector< int64_t > &expected_shape, std::string &errstr) const
Definition: Messages.h:176
static std::string MsgId()
Definition: Messages.h:105
bool CheckRank(const std::vector< int > &expected_ranks) const
Definition: Messages.h:168
msgpack::type::raw_ref data
Definition: Messages.h:143
bool CheckType(const std::vector< std::string > &expected_types, std::string &errstr) const
Definition: Messages.h:233
bool CheckShape(const std::vector< int64_t > &expected_shape) const
Definition: Messages.h:204
core::Tensor tensor_
Definition: Messages.h:139
std::vector< int64_t > shape
Definition: Messages.h:142
struct for storing camera data
Definition: Messages.h:426
std::array< double, 4 > R
rotation R as quaternion [x,y,z,w]
Definition: Messages.h:435
std::vector< double > intrinsic_parameters
Definition: Messages.h:443
int height
Definition: Messages.h:447
MSGPACK_DEFINE_MAP(R, t, intrinsic_model, intrinsic_parameters, width, height, images)
static std::string MsgId()
Definition: Messages.h:427
std::array< double, 3 > t
translation
Definition: Messages.h:437
int width
image dimensions in pixels
Definition: Messages.h:446
std::map< std::string, Array > images
map of arrays that can be interpreted as camera images
Definition: Messages.h:450
std::string intrinsic_model
Definition: Messages.h:442
CameraData()
Definition: Messages.h:429
struct for defining a "get_mesh_data" message, which requests mesh data.
Definition: Messages.h:410
MSGPACK_DEFINE_MAP(path, time, layer)
std::string path
Path defining the location in the scene tree.
Definition: Messages.h:416
static std::string MsgId()
Definition: Messages.h:411
int32_t time
The time for which to return the data.
Definition: Messages.h:418
GetMeshData()
Definition: Messages.h:413
std::string layer
The layer for which to return the data.
Definition: Messages.h:420
struct for storing MeshData, e.g., PointClouds, TriangleMesh, ..
Definition: Messages.h:255
std::map< std::string, Array > face_attributes
stores arbitrary attributes for each face
Definition: Messages.h:278
std::map< std::string, Array > line_attributes
stores arbitrary attributes for each line
Definition: Messages.h:289
std::string material
Material for DrawableGeometry.
Definition: Messages.h:292
void SetO3DTypeToLineSet()
Definition: Messages.h:301
std::string o3d_type
Definition: Messages.h:262
Array faces
Definition: Messages.h:276
bool CheckO3DType(std::string &errstr) const
Definition: Messages.h:355
Array lines
Definition: Messages.h:287
bool CheckMessage(std::string &errstr) const
Definition: Messages.h:368
void SetO3DTypeToTriangleMesh()
Definition: Messages.h:302
std::map< std::string, Array > texture_maps
map of arrays that can be interpreted as textures
Definition: Messages.h:298
std::map< std::string, float > material_scalar_attributes
Material scalar properties.
Definition: Messages.h:294
bool CheckVertices(std::string &errstr) const
Definition: Messages.h:308
Array vertices
shape must be [num_verts,3]
Definition: Messages.h:265
MSGPACK_DEFINE_MAP(o3d_type, vertices, vertex_attributes, faces, face_attributes, lines, line_attributes, material, material_scalar_attributes, material_vector_attributes, texture_maps)
static std::string MsgId()
Definition: Messages.h:256
std::map< std::string, Array > vertex_attributes
Definition: Messages.h:268
bool O3DTypeIsPointCloud() const
Definition: Messages.h:304
std::map< std::string, std::array< float, 4 > > material_vector_attributes
Material vector[4] properties.
Definition: Messages.h:296
void SetO3DTypeToPointCloud()
Definition: Messages.h:300
bool CheckFaces(std::string &errstr) const
Definition: Messages.h:317
bool O3DTypeIsTriangleMesh() const
Definition: Messages.h:306
bool O3DTypeIsLineSet() const
Definition: Messages.h:305
Definition: Messages.h:515
std::string msg_id
Definition: Messages.h:516
MSGPACK_DEFINE_MAP(msg_id)
Definition: Messages.h:508
MSGPACK_DEFINE_MAP(msg_id)
std::string msg_id
Definition: Messages.h:509
Definition: Messages.h:488
static std::string MsgId()
Definition: Messages.h:489
std::string path
Definition: Messages.h:490
Definition: Messages.h:458
int32_t time
The time for which to return the data.
Definition: Messages.h:466
static std::string MsgId()
Definition: Messages.h:459
CameraData data
The data to be set.
Definition: Messages.h:471
std::string layer
The layer for which to return the data.
Definition: Messages.h:468
MSGPACK_DEFINE_MAP(path, time, layer, data)
SetCameraData()
Definition: Messages.h:461
std::string path
Path defining the location in the scene tree.
Definition: Messages.h:464
Definition: Messages.h:391
SetMeshData()
Definition: Messages.h:394
std::string layer
The layer for this data.
Definition: Messages.h:401
MSGPACK_DEFINE_MAP(path, time, layer, data)
std::string path
Path defining the location in the scene tree.
Definition: Messages.h:397
int32_t time
The time associated with this data.
Definition: Messages.h:399
static std::string MsgId()
Definition: Messages.h:392
MeshData data
The data to be set.
Definition: Messages.h:404
Definition: Messages.h:497
static std::string MsgId()
Definition: Messages.h:498
std::string path
Definition: Messages.h:499
Definition: Messages.h:478
int32_t time
Definition: Messages.h:481
SetTime()
Definition: Messages.h:480
static std::string MsgId()
Definition: Messages.h:479
Definition: Messages.h:522
Status()
Definition: Messages.h:525
static Status ErrorUnsupportedMsgId()
Definition: Messages.h:528
static Status ErrorProcessingMessage()
Definition: Messages.h:534
MSGPACK_DEFINE_MAP(code, str)
std::string str
string representation of the code
Definition: Messages.h:541
static std::string MsgId()
Definition: Messages.h:523
static Status ErrorUnpackingFailed()
Definition: Messages.h:531
int32_t code
return code. 0 means everything is OK.
Definition: Messages.h:539
static Status OK()
Definition: Messages.h:527
Status(int code, const std::string &str)
Definition: Messages.h:526