32 #include <msgpack.hpp> 44 auto IsLittleEndian = []() ->
bool {
49 std::memcpy(&b, &a,
sizeof(uint8_t));
53 return IsLittleEndian() ?
"<" :
">";
124 static std::string
MsgId() {
return "array"; }
130 const std::vector<int64_t>&
shape) {
132 arr.
type = TypeStr<T>();
134 arr.
data.ptr = (
const char*)ptr;
136 for (int64_t n : shape) num *= n;
149 (scalar_t*)t.GetDataPtr(),
150 static_cast<std::vector<int64_t>
>(t.GetShape()));
172 std::string& errstr)
const {
173 for (
auto rank : expected_ranks) {
174 if (shape.size() ==
size_t(rank))
return true;
176 errstr +=
" expected rank to be in (";
177 for (
auto rank : expected_ranks) {
178 errstr += std::to_string(rank) +
", ";
180 errstr += std::string(
")") +
" but got shape [";
181 for (
auto d : shape) {
182 errstr += std::to_string(d) +
", ";
187 bool CheckRank(
const std::vector<int>& expected_ranks)
const {
196 std::string& errstr)
const {
201 for (
size_t i = 0; i < expected_shape.size(); ++i) {
202 int64_t d_expected = expected_shape[i];
203 int64_t d = shape[i];
204 if ((d_expected != -1 && d_expected != d) || d < 0) {
205 errstr +=
" expected shape [";
206 for (
auto d : expected_shape) {
210 errstr += std::to_string(d) +
", ";
213 errstr +=
"] but got [";
214 for (
auto d : shape) {
215 errstr += std::to_string(d) +
", ";
223 bool CheckShape(
const std::vector<int64_t>& expected_shape)
const {
233 for (
auto d : shape) n *= d;
234 if (0 == n || shape.empty()) {
235 errstr +=
" expected non empty array but got array with shape [";
236 for (
auto d : shape) {
237 errstr += std::to_string(d) +
", ";
252 bool CheckType(
const std::vector<std::string>& expected_types,
253 std::string& errstr)
const {
254 for (
const auto& t : expected_types) {
255 if (t == type)
return true;
257 errstr +=
" expected array type to be one of (";
258 for (
const auto& t : expected_types) {
261 errstr +=
") but got " +
type;
264 bool CheckType(
const std::vector<std::string>& expected_types)
const {
275 static std::string
MsgId() {
return "mesh_data"; }
311 std::string material =
"";
328 if (vertices.
shape.empty())
return true;
329 std::string tmp =
"invalid vertices array:";
332 if (!status) errstr += tmp;
337 if (faces.
shape.empty())
return true;
339 std::string tmp =
"invalid faces array:";
341 bool status = faces.
CheckRank({1, 2}, tmp);
362 status = faces.
shape[1] > 2;
363 tmp +=
" expected shape [?, >2] but got [" +
364 std::to_string(faces.
shape[0]) +
", " +
365 std::to_string(faces.
shape[1]) +
"]";
375 if (o3d_type.empty() || O3DTypeIsPointCloud() || O3DTypeIsLineSet() ||
376 O3DTypeIsTriangleMesh()) {
380 " invalid o3d_type. Expected 'PointCloud', 'TriangleMesh', " 381 "or 'LineSet' but got '" +
388 std::string tmp =
"invalid mesh_data message:";
390 CheckO3DType(tmp) && CheckVertices(tmp) && CheckFaces(tmp);
391 if (!status) errstr += tmp;
403 material_scalar_attributes,
404 material_vector_attributes,
411 static std::string
MsgId() {
return "set_mesh_data"; }
430 static std::string
MsgId() {
return "get_mesh_data"; }
446 static std::string
MsgId() {
return "camera_data"; }
454 std::array<double, 4>
R;
456 std::array<double, 3>
t;
472 R, t, intrinsic_model, intrinsic_parameters, width, height, images);
478 static std::string
MsgId() {
return "set_camera_data"; }
498 static std::string
MsgId() {
return "set_time"; }
508 static std::string
MsgId() {
return "set_active_camera"; }
517 static std::string
MsgId() {
return "set_properties"; }
542 static std::string
MsgId() {
return "status"; }
545 Status(
int code,
const std::string& str) : code(code), str(str) {}
548 return Status(1,
"unsupported msg_id");
551 return Status(2,
"error during unpacking");
554 return Status(3,
"error while processing message");
std::string msg_id
Definition: Messages.h:528
std::string msg_id
Definition: Messages.h:535
bool CheckNonEmpty() const
Definition: Messages.h:244
bool CheckType(const std::vector< std::string > &expected_types, std::string &errstr) const
Definition: Messages.h:252
std::string TypeStr< float >()
Definition: Messages.h:63
std::string TypeStr< uint8_t >()
Definition: Messages.h:87
std::string path
Definition: Messages.h:518
Definition: Messages.h:123
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:557
int32_t time
The time for which to return the data.
Definition: Messages.h:485
const T * Ptr() const
Definition: Messages.h:165
static Array FromTensor(const core::Tensor &tensor)
Definition: Messages.h:144
static std::string MsgId()
Definition: Messages.h:446
std::string path
Path defining the location in the scene tree.
Definition: Messages.h:416
bool CheckMessage(std::string &errstr) const
Definition: Messages.h:387
std::string TypeStr()
Definition: Messages.h:59
Status(int code, const std::string &str)
Definition: Messages.h:545
CameraData data
The data to be set.
Definition: Messages.h:490
std::string TypeStr< int64_t >()
Definition: Messages.h:83
int32_t time
The time associated with this data.
Definition: Messages.h:418
struct for storing MeshData, e.g., PointClouds, TriangleMesh, ..
Definition: Messages.h:274
static Status ErrorProcessingMessage()
Definition: Messages.h:553
Definition: Messages.h:541
std::string TypeStr< int8_t >()
Definition: Messages.h:71
static std::string MsgId()
Definition: Messages.h:124
std::string path
Definition: Messages.h:509
void SetO3DTypeToTriangleMesh()
Definition: Messages.h:321
static std::string MsgId()
Definition: Messages.h:275
Definition: Messages.h:410
struct for storing camera data
Definition: Messages.h:445
Definition: Messages.h:477
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:398
Definition: Messages.h:516
void SetO3DTypeToPointCloud()
Definition: Messages.h:319
msgpack::type::raw_ref data
Definition: Messages.h:162
bool O3DTypeIsTriangleMesh() const
Definition: Messages.h:325
std::map< std::string, Array > texture_maps
map of arrays that can be interpreted as textures
Definition: Messages.h:317
Definition: Messages.h:527
std::string path
Path defining the location in the scene tree.
Definition: Messages.h:435
bool CheckVertices(std::string &errstr) const
Definition: Messages.h:327
Definition: Messages.h:497
bool CheckShape(const std::vector< int64_t > &expected_shape, std::string &errstr) const
Definition: Messages.h:195
std::string path
Path defining the location in the scene tree.
Definition: Messages.h:483
bool CheckNonEmpty(std::string &errstr) const
Definition: Messages.h:231
GetMeshData()
Definition: Messages.h:432
static Status OK()
Definition: Messages.h:546
MSGPACK_DEFINE_MAP(type, shape, data)
std::vector< int64_t > shape
Definition: Messages.h:161
Array vertices
shape must be [num_verts,3]
Definition: Messages.h:284
Status()
Definition: Messages.h:544
static Status ErrorUnsupportedMsgId()
Definition: Messages.h:547
static std::string MsgId()
Definition: Messages.h:411
int height
Definition: Messages.h:466
bool CheckFaces(std::string &errstr) const
Definition: Messages.h:336
std::string TypeStr< uint16_t >()
Definition: Messages.h:91
std::map< std::string, Array > face_attributes
stores arbitrary attributes for each face
Definition: Messages.h:297
std::map< std::string, Array > line_attributes
stores arbitrary attributes for each line
Definition: Messages.h:308
std::string TypeStr< uint32_t >()
Definition: Messages.h:95
std::string layer
The layer for which to return the data.
Definition: Messages.h:487
std::string TypeStr< uint64_t >()
Definition: Messages.h:99
bool O3DTypeIsPointCloud() const
Definition: Messages.h:323
Tensor To(Dtype dtype, bool copy=false) const
Definition: Tensor.cpp:713
Tensor Contiguous() const
Definition: Tensor.cpp:746
bool CheckRank(const std::vector< int > &expected_ranks) const
Definition: Messages.h:187
static std::string MsgId()
Definition: Messages.h:430
bool CheckType(const std::vector< std::string > &expected_types) const
Definition: Messages.h:264
std::map< std::string, std::array< float, 4 > > material_vector_attributes
Material vector[4] properties.
Definition: Messages.h:315
static std::string MsgId()
Definition: Messages.h:478
Array lines
Definition: Messages.h:306
std::vector< double > intrinsic_parameters
Definition: Messages.h:462
std::string TypeStr< int16_t >()
Definition: Messages.h:75
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:479
int32_t time
The time for which to return the data.
Definition: Messages.h:437
std::string intrinsic_model
Definition: Messages.h:461
static std::string MsgId()
Definition: Messages.h:517
static std::string MsgId()
Definition: Messages.h:508
std::string TypeStr< int32_t >()
Definition: Messages.h:79
static std::string MsgId()
Definition: Messages.h:498
std::string EndiannessStr()
Definition: Messages.h:43
SetTime()
Definition: Messages.h:499
bool CheckO3DType(std::string &errstr) const
Definition: Messages.h:374
std::string str
string representation of the code
Definition: Messages.h:560
CameraData()
Definition: Messages.h:448
std::map< std::string, Array > images
map of arrays that can be interpreted as camera images
Definition: Messages.h:469
SetMeshData()
Definition: Messages.h:413
#define DISPATCH_DTYPE_TO_TEMPLATE(DTYPE,...)
Definition: Dispatch.h:49
int32_t time
Definition: Messages.h:500
Definition: Messages.h:507
Definition: PinholeCameraIntrinsic.cpp:35
core::Tensor tensor_
Definition: Messages.h:158
std::string o3d_type
Definition: Messages.h:281
void SetO3DTypeToLineSet()
Definition: Messages.h:320
std::string layer
The layer for this data.
Definition: Messages.h:420
bool O3DTypeIsLineSet() const
Definition: Messages.h:324
std::array< double, 3 > t
translation
Definition: Messages.h:456
struct for defining a "get_mesh_data" message, which requests mesh data.
Definition: Messages.h:429
bool CheckShape(const std::vector< int64_t > &expected_shape) const
Definition: Messages.h:223
std::string layer
The layer for which to return the data.
Definition: Messages.h:439
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 image_handle timestamp_usec white_balance image_handle k4a_device_configuration_t config device_handle char size_t serial_number_size bool int32_t int32_t int32_t int32_t k4a_color_control_mode_t default_mode value const const k4a_calibration_t calibration char size_t
Definition: K4aPlugin.cpp:724
MeshData data
The data to be set.
Definition: Messages.h:423
bool CheckRank(const std::vector< int > &expected_ranks, std::string &errstr) const
Definition: Messages.h:171
SetCameraData()
Definition: Messages.h:480
static Array FromPtr(const T *const ptr, const std::vector< int64_t > &shape)
Definition: Messages.h:129
Definition: Messages.h:534
int width
image dimensions in pixels
Definition: Messages.h:465
std::map< std::string, float > material_scalar_attributes
Material scalar properties.
Definition: Messages.h:313
Array faces
Definition: Messages.h:295
std::array< double, 4 > R
rotation R as quaternion [x,y,z,w]
Definition: Messages.h:454
static Status ErrorUnpackingFailed()
Definition: Messages.h:550
static std::string MsgId()
Definition: Messages.h:542
std::map< std::string, Array > vertex_attributes
Definition: Messages.h:287
int32_t code
return code. 0 means everything is OK.
Definition: Messages.h:558
std::string type
Definition: Messages.h:160
std::string TypeStr< double >()
Definition: Messages.h:67