25 const zmq::message_t& msg,
size_t&
offset,
bool& ok) {
27 if (msg.size() <=
offset) {
28 return std::shared_ptr<messages::Status>();
35 msgpack::unpack((
char*)msg.data(), msg.size(),
offset);
36 obj_handle.get().convert(reply);
38 LogDebug(
"Expected msg with id {} but got {}", status.
MsgId(),
41 auto status_obj_handle =
42 msgpack::unpack((
char*)msg.data(), msg.size(),
offset);
43 status_obj_handle.get().convert(status);
46 }
catch (std::exception& e) {
47 LogDebug(
"Failed to parse message: {}", e.what());
50 return std::make_shared<messages::Status>(status);
61 if (ok && status && 0 == status->code) {
69 msgpack::sbuffer sbuf;
70 msgpack::pack(sbuf, request);
71 return std::string(sbuf.data(), sbuf.size());
75 const zmq::message_t& msg) {
76 return std::make_tuple(msg.data(), msg.size());
81 return std::make_tuple(status.
code, status.
str);
85 auto OK = messages::Status::OK();
86 msgpack::sbuffer sbuf;
88 msgpack::pack(sbuf, reply);
89 msgpack::pack(sbuf, OK);
90 return std::shared_ptr<zmq::message_t>(
91 new zmq::message_t(sbuf.data(), sbuf.size()));
98 auto TypeStrToDtype = [](
const std::string& ts) {
101 }
else if (
"<f8" == ts) {
103 }
else if (
"|i1" == ts) {
105 }
else if (
"<i2" == ts) {
107 }
else if (
"<i4" == ts) {
109 }
else if (
"<i8" == ts) {
111 }
else if (
"|u1" == ts) {
113 }
else if (
"<u2" == ts) {
115 }
else if (
"<u4" == ts) {
117 }
else if (
"<u8" == ts) {
120 LogError(
"Unsupported type {}. Cannot convert to Tensor.", ts);
133 std::map<std::string, messages::Array>
result;
134 for (
auto item : tensor_map) {
135 result[item.first] = messages::Array::FromTensor(item.second);
141 std::string& errstr) {
143 if (mesh_data.
material.empty())
return material;
148 Eigen::Vector4f(vec.second.data()));
150 const std::vector<int64_t> expected_shapes[] = {{-1, -1}, {-1, -1, -1}};
152 std::string es(texture.first +
": ");
153 bool is_right_shape =
false;
154 for (
const auto& shape : expected_shapes) {
155 is_right_shape = texture.second.CheckShape(shape, es);
156 if (is_right_shape)
break;
158 if (!is_right_shape) {
159 errstr = errstr.empty() ? es : errstr +
'\n' + es;
175 auto mesh = std::make_shared<t::geometry::TriangleMesh>();
186 errstr =
"Invalid shape for faces, " + errstr;
190 mesh->SetTriangleAttr(item.first,
ArrayToTensor(item.second));
193 if (!errstr.empty()) {
199 auto ls = std::make_shared<t::geometry::LineSet>();
210 errstr =
"Invalid shape for lines, " + errstr;
217 if (!errstr.empty()) {
223 auto pcd = std::make_shared<t::geometry::PointCloud>();
231 if (!errstr.empty()) {
236 errstr +=
"MeshData has no triangles, lines, or vertices";
240 return std::shared_ptr<t::geometry::Geometry>();
245 if (!material.
IsValid())
return;
249 std::map<std::string, float>(scalars.begin(), scalars.end());
252 item.second[0], item.second[1], item.second[2], item.second[3]};
256 messages::Array::FromTensor(item.second.AsTensor());
271 LogError(
"GeometryToMeshData: TriangleMesh has no vertices!");
300 LogError(
"GeometryToMeshData: PointCloud has no points!");
321 LogError(
"GeometryToMeshData: LineSet has no points!");
340 std::tuple<std::string, double, std::shared_ptr<t::geometry::Geometry>>
342 const char* buffer = data.data();
343 size_t buffer_size = data.size();
345 auto limits = msgpack::unpack_limit(0xffffffff,
356 auto obj_handle = msgpack::unpack(buffer, buffer_size,
offset,
nullptr,
358 auto obj = obj_handle.get();
361 if (messages::SetMeshData::MsgId() == req.
msg_id) {
362 auto oh = msgpack::unpack(buffer, buffer_size,
offset,
nullptr,
364 auto mesh_obj = oh.get();
368 double time = msg.
time;
372 "DataBufferToMetaGeometry: Wrong message id. Expected "
373 "'{}' but got '{}'.",
374 messages::SetMeshData::MsgId(), req.
msg_id);
376 }
catch (std::exception& err) {
377 LogWarning(
"DataBufferToMetaGeometry: {}", err.what());
379 return std::forward_as_tuple(std::string(), 0.,
380 std::shared_ptr<t::geometry::Geometry>());
visualization::rendering::Material & GetMaterial()
Get material associated with this Geometry.
The Image class stores image with customizable rows, cols, channels, dtype and device.
A LineSet contains points and lines joining them and optionally attributes on the points and lines.
const TensorMap & GetLineAttr() const
Getter for line_attr_ TensorMap. Used in Pybind.
const TensorMap & GetPointAttr() const
Getter for point_attr_ TensorMap. Used in Pybind.
A point cloud contains a list of 3D points.
const TensorMap & GetPointAttr() const
Getter for point_attr_ TensorMap. Used in Pybind.
A triangle mesh contains vertices and triangles.
const TensorMap & GetVertexAttr() const
Getter for vertex_attr_ TensorMap. Used in Pybind.
const TensorMap & GetTriangleAttr() const
Getter for triangle_attr_ TensorMap. Used in Pybind.
const std::string & GetMaterialName() const
Get the name of the material.
const VectorPropertyMap & GetVectorProperties() const
Returns the map of vector properties.
const ScalarPropertyMap & GetScalarProperties() const
Returns the map of scalar properties.
void SetVectorProperty(const std::string &key, const Eigen::Vector4f &value)
void SetScalarProperty(const std::string &key, float value)
void SetTextureMap(const std::string &key, const t::geometry::Image &image)
const TextureMaps & GetTextureMaps() const
Returns the texture map map.
static Material GetMaterialFromMeshData(const messages::MeshData &mesh_data, std::string &errstr)
std::shared_ptr< t::geometry::Geometry > MeshDataToGeometry(const messages::MeshData &mesh_data)
static std::map< std::string, messages::Array > TensorMapToArrayMap(const t::geometry::TensorMap &tensor_map)
Converts a TensorMap to an Array map.
std::shared_ptr< zmq::message_t > CreateStatusOKMsg()
std::tuple< std::string, double, std::shared_ptr< t::geometry::Geometry > > DataBufferToMetaGeometry(std::string &data)
std::tuple< const void *, size_t > GetZMQMessageDataAndSize(const zmq::message_t &msg)
std::string CreateSerializedRequestMessage(const std::string &msg_id)
Creates a serialized Request message for testing purposes.
std::shared_ptr< messages::Status > UnpackStatusFromReply(const zmq::message_t &msg, size_t &offset, bool &ok)
static core::Tensor ArrayToTensor(const messages::Array &array)
messages::MeshData GeometryToMeshData(const t::geometry::LineSet &ls)
static void AddMaterialToMeshData(messages::MeshData &mesh_data, const Material &material)
std::tuple< int32_t, std::string > GetStatusCodeAndStr(const messages::Status &status)
bool ReplyIsOKStatus(const zmq::message_t &msg, size_t &offset)
Generic file read and write utility for python interface.
bool CheckShape(const std::vector< int64_t > &expected_shape, std::string &errstr) const
bool CheckNonEmpty(std::string &errstr) const
msgpack::type::raw_ref data
std::vector< int64_t > shape
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()
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
void SetO3DTypeToLineSet()
bool O3DTypeIsLineSet() const
Array vertices
shape must be [num_verts,3]
bool O3DTypeIsPointCloud() const
std::string path
Path defining the location in the scene tree.
int32_t time
The time associated with this data.
MeshData data
The data to be set.
static std::string MsgId()
std::string str
string representation of the code
int32_t code
return code. 0 means everything is OK.