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;
118 arr.
data.size = uint32_t(
sizeof(T) * num);
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) {
161 errstr += std::string(
")") +
" but got shape [";
162 for (
auto d :
shape) {
168 bool CheckRank(
const std::vector<int>& expected_ranks)
const {
177 std::string& errstr)
const {
178 if (!
CheckRank({int(expected_shape.size())}, errstr)) {
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) {
194 errstr +=
"] but got [";
195 for (
auto d :
shape) {
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) {
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,...)
Tensor Contiguous() const
Tensor To(Dtype dtype, bool copy=false) const
std::string TypeStr< float >()
std::string TypeStr< int16_t >()
std::string TypeStr< uint16_t >()
std::string TypeStr< double >()
std::string TypeStr< int32_t >()
std::string TypeStr< uint64_t >()
std::string TypeStr< uint32_t >()
std::string TypeStr< int8_t >()
std::string TypeStr< uint8_t >()
std::string TypeStr< int64_t >()
std::string EndiannessStr()
Generic file read and write utility for python interface.
std::string to_string(const T &n)
bool CheckRank(const std::vector< int > &expected_ranks, std::string &errstr) const
bool CheckType(const std::vector< std::string > &expected_types) const
bool CheckShape(const std::vector< int64_t > &expected_shape, std::string &errstr) const
static Array FromTensor(const core::Tensor &tensor)
static std::string MsgId()
bool CheckNonEmpty() const
bool CheckNonEmpty(std::string &errstr) const
msgpack::type::raw_ref data
std::vector< int64_t > shape
bool CheckType(const std::vector< std::string > &expected_types, std::string &errstr) const
static Array FromPtr(const T *const ptr, const std::vector< int64_t > &shape)
bool CheckShape(const std::vector< int64_t > &expected_shape) const
bool CheckRank(const std::vector< int > &expected_ranks) const
MSGPACK_DEFINE_MAP(type, shape, data)
struct for storing camera data
std::vector< double > intrinsic_parameters
std::array< double, 3 > t
translation
std::string intrinsic_model
int width
image dimensions in pixels
MSGPACK_DEFINE_MAP(R, t, intrinsic_model, intrinsic_parameters, width, height, images)
std::map< std::string, Array > images
map of arrays that can be interpreted as camera images
std::array< double, 4 > R
rotation R as quaternion [x,y,z,w]
static std::string MsgId()
struct for defining a "get_mesh_data" message, which requests mesh data.
static std::string MsgId()
std::string layer
The layer for which to return the data.
int32_t time
The time for which to return the data.
std::string path
Path defining the location in the scene tree.
MSGPACK_DEFINE_MAP(path, time, layer)
struct for storing MeshData, e.g., PointClouds, TriangleMesh, ..
std::map< std::string, float > material_scalar_attributes
Material scalar properties.
std::map< std::string, Array > vertex_attributes
void SetO3DTypeToPointCloud()
MSGPACK_DEFINE_MAP(o3d_type, vertices, vertex_attributes, faces, face_attributes, lines, line_attributes, material, material_scalar_attributes, material_vector_attributes, texture_maps)
bool CheckO3DType(std::string &errstr) const
bool O3DTypeIsTriangleMesh() const
std::map< std::string, Array > face_attributes
stores arbitrary attributes for each face
bool CheckMessage(std::string &errstr) const
void SetO3DTypeToTriangleMesh()
std::map< std::string, std::array< float, 4 > > material_vector_attributes
Material vector[4] properties.
std::string material
Material for DrawableGeometry.
std::map< std::string, Array > line_attributes
stores arbitrary attributes for each line
std::map< std::string, Array > texture_maps
map of arrays that can be interpreted as textures
static std::string MsgId()
bool CheckFaces(std::string &errstr) const
bool CheckVertices(std::string &errstr) const
void SetO3DTypeToLineSet()
bool O3DTypeIsLineSet() const
Array vertices
shape must be [num_verts,3]
bool O3DTypeIsPointCloud() const
MSGPACK_DEFINE_MAP(msg_id)
MSGPACK_DEFINE_MAP(msg_id)
static std::string MsgId()
CameraData data
The data to be set.
int32_t time
The time for which to return the data.
MSGPACK_DEFINE_MAP(path, time, layer, data)
std::string path
Path defining the location in the scene tree.
static std::string MsgId()
std::string layer
The layer for which to return the data.
MSGPACK_DEFINE_MAP(path, time, layer, data)
std::string path
Path defining the location in the scene tree.
int32_t time
The time associated with this data.
std::string layer
The layer for this data.
MeshData data
The data to be set.
static std::string MsgId()
static std::string MsgId()
static std::string MsgId()
static Status ErrorUnpackingFailed()
static std::string MsgId()
Status(int code, const std::string &str)
std::string str
string representation of the code
static Status ErrorProcessingMessage()
static Status ErrorUnsupportedMsgId()
int32_t code
return code. 0 means everything is OK.
MSGPACK_DEFINE_MAP(code, str)