From 3e6747cd4df65b1770b6be7ec7f3e8394400a1d3 Mon Sep 17 00:00:00 2001 From: yiztang Date: Tue, 23 Dec 2014 19:24:48 +0800 Subject: [PATCH] Save normal and curvature in savePLYFile --- io/src/ply_io.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/io/src/ply_io.cpp b/io/src/ply_io.cpp index 6844f85f261..0751b936d92 100644 --- a/io/src/ply_io.cpp +++ b/io/src/ply_io.cpp @@ -1497,6 +1497,22 @@ pcl::io::savePLYFile (const std::string &file_name, const pcl::PolygonMesh &mesh "\nproperty uchar green" "\nproperty uchar blue"; } + // Check if we have normal on vertices + int normal_x_index = getFieldIndex(mesh.cloud, "normal_x"); + int normal_y_index = getFieldIndex(mesh.cloud, "normal_y"); + int normal_z_index = getFieldIndex(mesh.cloud, "normal_z"); + if (normal_x_index != -1 && normal_y_index != -1 && normal_z_index != -1) + { + fs << "\nproperty float nx" + "\nproperty float ny" + "\nproperty float nz"; + } + // Check if we have curvature on vertices + int curvature_index = getFieldIndex(mesh.cloud, "curvature"); + if ( curvature_index != -1) + { + fs << "\nproperty float curvature"; + } // Faces fs << "\nelement face "<< nr_faces; fs << "\nproperty list uchar int vertex_indices"; @@ -1541,6 +1557,22 @@ pcl::io::savePLYFile (const std::string &file_name, const pcl::PolygonMesh &mesh memcpy (&color, &mesh.cloud.data[i * point_size + mesh.cloud.fields[rgba_index].offset + c * sizeof (uint32_t)], sizeof (RGB)); fs << int (color.r) << " " << int (color.g) << " " << int (color.b) << " " << int (color.a); } + else if ((mesh.cloud.fields[d].datatype == pcl::PCLPointField::FLOAT32) && ( + mesh.cloud.fields[d].name == "normal_x" || + mesh.cloud.fields[d].name == "normal_y" || + mesh.cloud.fields[d].name == "normal_z")) + { + float value; + memcpy (&value, &mesh.cloud.data[i * point_size + mesh.cloud.fields[d].offset + c * sizeof(float)], sizeof(float)); + fs << value; + } + else if ((mesh.cloud.fields[d].datatype == pcl::PCLPointField::FLOAT32) && ( + mesh.cloud.fields[d].name == "curvature")) + { + float value; + memcpy(&value, &mesh.cloud.data[i * point_size + mesh.cloud.fields[d].offset + c * sizeof(float)], sizeof(float)); + fs << value; + } fs << " "; } if (xyz != 3)