13 #include <Eigen/Geometry>
28 const std::string&
path,
30 const std::string& layer,
31 std::shared_ptr<ConnectionBase> connection) {
34 LogInfo(
"SetMeshData: point cloud is empty");
45 {int64_t(pcd.size()), 3});
50 {int64_t(normals.size()), 3});
55 {int64_t(pcd.getPointColors().size()), 3});
58 msgpack::sbuffer sbuf;
60 msgpack::pack(sbuf, request);
61 msgpack::pack(sbuf, msg);
63 zmq::message_t send_msg(sbuf.data(), sbuf.size());
65 connection = std::shared_ptr<Connection>(
new Connection());
67 auto reply = connection->Send(send_msg);
72 const std::string&
path,
74 const std::string& layer,
75 std::shared_ptr<ConnectionBase> connection) {
78 LogInfo(
"SetMeshData: triangle mesh is empty");
88 LogInfo(
"SetMeshData: triangle vertices is empty");
97 {int64_t(associatedCloud.size()), 3});
99 msg.
data.
faces = messages::Array::FromPtr(
101 {int64_t((*mesh.getTrianglesPtr()).size()), 3});
106 {int64_t(normals.size()), 3});
111 {int64_t(associatedCloud.getPointColors().size()), 3});
117 {int64_t(triNormals.size()), 3});
122 {int64_t(mesh.triangle_uvs_.size()), 2});
127 if (!
image.IsEmpty()) {
128 std::vector<int64_t> shape(
130 if (
image.bytes_per_channel_ ==
sizeof(uint8_t)) {
132 messages::Array::FromPtr(
133 (uint8_t*)
image.data_.data(), shape);
134 }
else if (
image.bytes_per_channel_ ==
sizeof(
float)) {
136 messages::Array::FromPtr((
float*)
image.data_.data(),
138 }
else if (
image.bytes_per_channel_ ==
sizeof(
double)) {
140 messages::Array::FromPtr(
141 (
double*)
image.data_.data(), shape);
148 msgpack::sbuffer sbuf;
150 msgpack::pack(sbuf, request);
151 msgpack::pack(sbuf, msg);
153 zmq::message_t send_msg(sbuf.data(), sbuf.size());
155 connection = std::shared_ptr<Connection>(
new Connection());
157 auto reply = connection->Send(send_msg);
162 const std::string&
path,
164 const std::string& layer,
165 std::shared_ptr<ConnectionBase> connection) {
166 std::map<std::string, core::Tensor> vertex_attributes(
168 std::map<std::string, core::Tensor> face_attributes(
171 std::string material_name;
172 std::map<std::string, float> material_scalar_attributes;
173 std::map<std::string, std::array<float, 4>> material_vector_attributes;
174 std::map<std::string, t::geometry::Image> texture_maps;
178 material_scalar_attributes = std::map<std::string, float>(
179 material.GetScalarProperties().begin(),
180 material.GetScalarProperties().end());
181 for (
const auto& it : material.GetVectorProperties()) {
182 std::array<float, 4> vec = {it.second(0), it.second(1),
183 it.second(2), it.second(3)};
184 material_vector_attributes[it.first] = vec;
186 texture_maps = std::map<std::string, t::geometry::Image>(
187 material.GetTextureMaps().begin(),
188 material.GetTextureMaps().end());
197 std::map<std::string, core::Tensor>(), material_name,
198 material_scalar_attributes, material_vector_attributes,
199 texture_maps, o3d_type.
o3d_type, connection);
204 const std::string& layer,
206 const std::map<std::string, core::Tensor>& vertex_attributes,
208 const std::map<std::string, core::Tensor>& face_attributes,
210 const std::map<std::string, core::Tensor>& line_attributes,
211 const std::string& material,
212 const std::map<std::string, float>& material_scalar_attributes,
213 const std::map<std::string, std::array<float, 4>>&
214 material_vector_attributes,
215 const std::map<std::string, t::geometry::Image>& texture_maps,
216 const std::string& o3d_type,
217 std::shared_ptr<ConnectionBase> connection) {
226 LogError(
"SetMeshData: vertices ndim must be 2 but is {}",
232 "SetMeshData: vertices must have dtype Float32 or Float64 "
237 msg.
data.
vertices = messages::Array::FromTensor(vertices);
240 for (
const auto& item : vertex_attributes) {
241 if (item.second.NumDims() >= 1) {
243 messages::Array::FromTensor(item.second);
245 LogError(
"SetMeshData: Attribute {} has incompatible shape {}",
246 item.first, item.second.GetShape().ToString());
254 "SetMeshData: faces must have dtype Int32 or Int64 but "
257 }
else if (faces.
NumDims() != 2) {
258 LogError(
"SetMeshData: faces must have rank 2 but is {}",
260 }
else if (faces.
GetShape()[1] < 3) {
261 LogError(
"SetMeshData: last dim of faces must be >=3 but is {}",
264 msg.
data.
faces = messages::Array::FromTensor(faces);
268 for (
const auto& item : face_attributes) {
269 if (item.second.NumDims() >= 1) {
271 messages::Array::FromTensor(item.second);
274 "SetMeshData: Attribute {} has incompatible shape "
276 item.first, item.second.GetShape().ToString());
284 "SetMeshData: lines must have dtype Int32 or Int64 but "
287 }
else if (lines.
NumDims() != 2) {
288 LogError(
"SetMeshData: lines must have rank 2 but is {}",
290 }
else if (lines.
GetShape()[1] < 2) {
291 LogError(
"SetMeshData: last dim of lines must be >=2 but is {}",
294 msg.
data.
lines = messages::Array::FromTensor(lines);
298 for (
const auto& item : line_attributes) {
299 if (item.second.NumDims() >= 1) {
301 messages::Array::FromTensor(item.second);
304 "SetMeshData: Attribute {} has incompatible shape "
306 item.first, item.second.GetShape().ToString());
310 if (!material.empty()) {
313 for (
const auto& item : material_vector_attributes) {
316 for (
const auto& texture_map : texture_maps) {
317 if (texture_map.second.IsEmpty()) {
318 LogError(
"SetMeshData: Texture map {} is empty",
322 messages::Array::FromTensor(
323 texture_map.second.AsTensor());
327 }
else if (!material_scalar_attributes.empty() ||
328 !material_vector_attributes.empty() || !texture_maps.empty()) {
330 "SetMeshData: Please provide a material for the texture maps");
336 LogError(
"SetMeshData: {}", errstr);
340 msgpack::sbuffer sbuf;
342 msgpack::pack(sbuf, request);
343 msgpack::pack(sbuf, msg);
345 zmq::message_t send_msg(sbuf.data(), sbuf.size());
347 connection = std::shared_ptr<Connection>(
new Connection());
349 auto reply = connection->Send(send_msg);
354 const std::string&
path,
356 const std::string& layer,
357 std::shared_ptr<ConnectionBase> connection) {
364 Eigen::Matrix3d R = camera.
extrinsic_.block<3, 3>(0, 0);
365 Eigen::Vector3d t = camera.
extrinsic_.block<3, 1>(0, 3);
366 Eigen::Quaterniond q(R);
367 msg.
data.
R[0] = q.x();
368 msg.
data.
R[1] = q.y();
369 msg.
data.
R[2] = q.z();
370 msg.
data.
R[3] = q.w();
372 msg.
data.
t[0] = t[0];
373 msg.
data.
t[1] = t[1];
374 msg.
data.
t[2] = t[2];
392 "SetLegacyCamera: Nonzero skew parameteer in "
393 "PinholeCameraParameters will be ignored!");
397 msgpack::sbuffer sbuf;
399 msgpack::pack(sbuf, request);
400 msgpack::pack(sbuf, msg);
402 zmq::message_t send_msg(sbuf.data(), sbuf.size());
404 connection = std::shared_ptr<Connection>(
new Connection());
406 auto reply = connection->Send(send_msg);
410 bool SetTime(
int time, std::shared_ptr<ConnectionBase> connection) {
414 msgpack::sbuffer sbuf;
416 msgpack::pack(sbuf, request);
417 msgpack::pack(sbuf, msg);
419 zmq::message_t send_msg(sbuf.data(), sbuf.size());
421 connection = std::shared_ptr<Connection>(
new Connection());
423 auto reply = connection->Send(send_msg);
428 std::shared_ptr<ConnectionBase> connection) {
432 msgpack::sbuffer sbuf;
434 msgpack::pack(sbuf, request);
435 msgpack::pack(sbuf, msg);
437 zmq::message_t send_msg(sbuf.data(), sbuf.size());
439 connection = std::shared_ptr<Connection>(
new Connection());
441 auto reply = connection->Send(send_msg);
float PointCoordinateType
Type of the coordinates of a (N-D) point.
std::shared_ptr< core::Tensor > image
static ccPointCloud * ToPointCloud(ccHObject *obj, bool *isLockedVertices=nullptr)
Converts current object to 'equivalent' ccPointCloud.
triangleIndexesContainer * getTrianglesPtr() const
std::vector< Eigen::Vector2d > triangle_uvs_
List of uv coordinates per triangle.
bool hasColors() const override
Returns whether colors are enabled or not.
ccGenericPointCloud * getAssociatedCloud() const override
Returns the vertices cloud.
bool hasTextures() const override
Returns whether textures are available for this mesh.
std::vector< CCVector3 * > getTriangleNormalsPtr() const
bool hasNormals() const override
Returns whether normals are enabled or not.
std::vector< cloudViewer::geometry::Image > textures_
Textures of the image.
bool hasTriangleUvs() const
bool hasTriNormals() const override
Returns whether the mesh has per-triangle normals.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
bool hasNormals() const override
Returns whether normals are enabled or not.
const ColorsTableType & getPointColors() const
std::vector< CCVector3 * > getPointNormalsPtr() const
bool hasColors() const override
Returns whether colors are enabled or not.
virtual bool hasPoints() const
virtual bool hasTriangles() const
std::vector< CCVector3 > & getPoints()
int height_
Height of the image.
int width_
Width of the image.
bool IsValid() const
Returns true iff both the width and height are greater than 0.
double GetSkew() const
Returns the skew.
Eigen::Matrix3d intrinsic_matrix_
Contains both intrinsic and extrinsic pinhole camera parameters.
PinholeCameraIntrinsic intrinsic_
PinholeCameraIntrinsic object.
Eigen::Matrix4d_u extrinsic_
Camera extrinsic parameters.
std::string ToString() const
int64_t NumElements() const
SizeVector GetShape() const
bool HasMaterial() const
Check if a material has been applied to this Geometry with SetMaterial.
visualization::rendering::Material & GetMaterial()
Get material associated with this Geometry.
A triangle mesh contains vertices and triangles.
core::Tensor & GetTriangleIndices()
const TensorMap & GetVertexAttr() const
Getter for vertex_attr_ TensorMap. Used in Pybind.
core::Tensor & GetVertexPositions()
const TensorMap & GetTriangleAttr() const
Getter for triangle_attr_ TensorMap. Used in Pybind.
const std::string & GetMaterialName() const
Get the name of the material.
unsigned char ColorCompType
Default color components type (R,G and B)
bool SetTriangleMesh(const t::geometry::TriangleMesh &mesh, const std::string &path, int time, const std::string &layer, std::shared_ptr< ConnectionBase > connection)
bool SetPointCloud(const ccPointCloud &pcd, const std::string &path, int time, const std::string &layer, std::shared_ptr< ConnectionBase > connection)
bool SetActiveCamera(const std::string &path, std::shared_ptr< ConnectionBase > connection)
bool ReplyIsOKStatus(const zmq::message_t &msg)
Convenience function for checking if the message is an OK.
bool SetLegacyCamera(const camera::PinholeCameraParameters &camera, const std::string &path, int time, const std::string &layer, std::shared_ptr< ConnectionBase > connection)
bool SetMeshData(const std::string &path, int time, const std::string &layer, const core::Tensor &vertices, const std::map< std::string, core::Tensor > &vertex_attributes, const core::Tensor &faces, const std::map< std::string, core::Tensor > &face_attributes, const core::Tensor &lines, const std::map< std::string, core::Tensor > &line_attributes, const std::string &material, const std::map< std::string, float > &material_scalar_attributes, const std::map< std::string, std::array< float, 4 >> &material_vector_attributes, const std::map< std::string, t::geometry::Image > &texture_maps, const std::string &o3d_type, std::shared_ptr< ConnectionBase > connection)
bool SetTime(int time, std::shared_ptr< ConnectionBase > connection)
static const std::string path
Generic file read and write utility for python interface.
std::string to_string(const T &n)
std::vector< double > intrinsic_parameters
std::array< double, 3 > t
translation
std::string intrinsic_model
int width
image dimensions in pixels
std::array< double, 4 > R
rotation R as quaternion [x,y,z,w]
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
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
Array vertices
shape must be [num_verts,3]
static std::string MsgId()
CameraData data
The data to be set.
int32_t time
The time for which to return the 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.
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()