25 namespace visualization {
30 const msgpack::object_handle& obj) {
31 std::string errstr(
":");
34 status_err.str += errstr;
35 msgpack::sbuffer sbuf;
37 msgpack::pack(sbuf, reply);
38 msgpack::pack(sbuf, status_err);
39 return std::shared_ptr<zmq::message_t>(
40 new zmq::message_t(sbuf.data(), sbuf.size()));
50 auto mesh = std::make_shared<ccMesh>(baseVertices);
51 mesh->addChild(baseVertices);
55 {messages::TypeStr<float>(), messages::TypeStr<double>()},
57 errstr =
"Ignoring vertices. vertices have wrong data type:" +
85 errstr =
"Ignoring normals. normals have wrong data type:" +
88 }
else if (!attr_arr.CheckShape({-1, 3}, errstr)) {
89 errstr =
"Ignoring normals. normals have wrong shape:" + errstr;
95 "Ignoring normals. not enough memory:" + errstr;
101 const float* ptr = attr_arr.Ptr<
float>();
102 for (int64_t i = 0; i < attr_arr.shape[0]; ++i) {
108 const double* ptr = attr_arr.Ptr<
double>();
109 for (int64_t i = 0; i < attr_arr.shape[0]; ++i) {
123 errstr =
"Ignoring colors. colors have wrong data type:" +
126 }
else if (!attr_arr.CheckShape({-1, 3}, errstr)) {
127 errstr =
"Ignoring colors. colors have wrong shape:" + errstr;
130 if (!baseVertices->hasColors()) {
131 if (!baseVertices->reserveTheRGBTable()) {
132 errstr =
"Ignoring colors. not enough memory:" + errstr;
138 const float* ptr = attr_arr.Ptr<
float>();
139 for (int64_t i = 0; i < attr_arr.shape[0]; ++i) {
148 const double* ptr = attr_arr.Ptr<
double>();
149 for (int64_t i = 0; i < attr_arr.shape[0]; ++i) {
161 if (!msg.data.faces.CheckShape({-1, 3}, errstr)) {
162 errstr =
"Ignoring faces. Only triangular faces are supported:" +
165 }
else if (!msg.data.faces.CheckType({messages::TypeStr<int32_t>(),
166 messages::TypeStr<int64_t>()},
168 errstr =
"Ignoring faces. Triangles have wrong data type:" + errstr;
171 mesh->reserve(
static_cast<std::size_t
>(msg.data.faces.shape[0]));
173 const int32_t* ptr = msg.data.faces.Ptr<int32_t>();
174 for (int64_t i = 0; i < msg.data.faces.shape[0]; ++i) {
175 mesh->addTriangle(
static_cast<unsigned int>(ptr[0]),
176 static_cast<unsigned int>(ptr[1]),
177 static_cast<unsigned int>(ptr[2]));
182 const int64_t* ptr = msg.data.faces.Ptr<int64_t>();
183 for (int64_t i = 0; i < msg.data.faces.shape[0]; ++i) {
184 mesh->addTriangle(
static_cast<unsigned int>(ptr[0]),
185 static_cast<unsigned int>(ptr[1]),
186 static_cast<unsigned int>(ptr[2]));
192 SetGeometry(mesh, msg.path, msg.time, msg.layer);
195 auto pcd = std::make_shared<ccPointCloud>();
196 if (!msg.data.vertices.CheckType(
197 {messages::TypeStr<float>(), messages::TypeStr<double>()},
199 errstr =
"Ignoring vertices. vertices have wrong data type:" +
203 pcd->reserveThePointsTable(
204 static_cast<unsigned>(msg.data.vertices.shape[0]));
206 const float* ptr = msg.data.vertices.Ptr<
float>();
207 for (int64_t i = 0; i < msg.data.vertices.shape[0]; ++i) {
213 const double* ptr = msg.data.vertices.Ptr<
double>();
214 for (int64_t i = 0; i < msg.data.vertices.shape[0]; ++i) {
221 if (msg.data.vertex_attributes.count(
"normals")) {
222 const auto& attr_arr = msg.data.vertex_attributes.at(
"normals");
226 errstr =
"Ignoring normals. normals have wrong data type:" +
229 }
else if (!attr_arr.CheckShape({-1, 3}, errstr)) {
230 errstr =
"Ignoring normals. normals have wrong shape:" +
234 if (!pcd->hasNormals()) {
235 if (!pcd->reserveTheNormsTable()) {
236 errstr =
"Ignoring normals. not enough memory:" +
243 const float* ptr = attr_arr.Ptr<
float>();
244 for (int64_t i = 0; i < attr_arr.shape[0]; ++i) {
250 const double* ptr = attr_arr.Ptr<
double>();
251 for (int64_t i = 0; i < attr_arr.shape[0]; ++i) {
260 if (msg.data.vertex_attributes.count(
"colors")) {
261 const auto& attr_arr = msg.data.vertex_attributes.at(
"colors");
265 errstr =
"Ignoring colors. colors have wrong data type:" +
268 }
else if (!attr_arr.CheckShape({-1, 3}, errstr)) {
269 errstr =
"Ignoring colors. colors have wrong shape:" +
273 if (!pcd->hasColors()) {
274 if (!pcd->reserveTheRGBTable()) {
275 errstr =
"Ignoring colors. not enough memory:" +
282 const float* ptr = attr_arr.Ptr<
float>();
283 for (int64_t i = 0; i < attr_arr.shape[0]; ++i) {
292 const double* ptr = attr_arr.Ptr<
double>();
293 for (int64_t i = 0; i < attr_arr.shape[0]; ++i) {
304 SetGeometry(pcd, msg.path, msg.time, msg.layer);
310 void MessageProcessor::SetGeometry(std::shared_ptr<ccHObject> geom,
311 const std::string&
path,
313 const std::string& layer) {
315 window_, [
this, geom,
path, time, layer]() {
316 on_geometry_(geom,
path, time, layer);
static Vector3Tpl fromArray(const int a[3])
Constructor from an int array.
virtual void setLocked(bool state)
Sets the "enabled" property.
virtual void setEnabled(bool state)
Sets the "enabled" property.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
void addNorm(const CCVector3 &N)
Pushes a normal vector on stack (shortcut)
bool hasNormals() const override
Returns whether normals are enabled or not.
bool reserveTheNormsTable()
Reserves memory to store the compressed normals.
bool reserveThePointsTable(unsigned _numberOfPoints)
Reserves memory to store the points coordinates.
void addPoint(const CCVector3 &P)
Adds a 3D point to the database.
std::shared_ptr< zmq::message_t > ProcessMessage(const io::rpc::messages::Request &req, const io::rpc::messages::SetMeshData &msg, const msgpack::object_handle &obj) override
unsigned char ColorCompType
Default color components type (R,G and B)
ccGuiPythonInstance * GetInstance() noexcept
std::string TypeStr< float >()
std::string TypeStr< double >()
std::string TypeStr< int32_t >()
std::string TypeStr< int64_t >()
std::shared_ptr< zmq::message_t > CreateStatusOKMsg()
static const std::string path
Generic file read and write utility for python interface.
bool CheckNonEmpty(std::string &errstr) const
std::vector< int64_t > shape
bool CheckType(const std::vector< std::string > &expected_types, std::string &errstr) const
std::map< std::string, Array > vertex_attributes
bool CheckMessage(std::string &errstr) const
Array vertices
shape must be [num_verts,3]
MeshData data
The data to be set.
static Status ErrorProcessingMessage()