Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 10 additions & 45 deletions io/include/pcl/io/png_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,66 +82,39 @@ namespace pcl
* \ingroup io
*/
PCL_EXPORTS void
saveRgbPNGFile (const std::string& file_name, const unsigned char *rgb_image, int width, int height)
{
saveCharPNGFile(file_name, rgb_image, width, height, 3);
}
saveRgbPNGFile (const std::string& file_name, const unsigned char *rgb_image, int width, int height);

/** \brief Saves 8-bit grayscale cloud as image to PNG file.
* \param[in] file_name the name of the file to write to disk
* \param[in] cloud point cloud to save
* \ingroup io
*/
void
savePNGFile (const std::string& file_name, const pcl::PointCloud<unsigned char>& cloud)
{
saveCharPNGFile(file_name, &cloud.points[0], cloud.width, cloud.height, 1);
}
PCL_EXPORTS void
savePNGFile (const std::string& file_name, const pcl::PointCloud<unsigned char>& cloud);

/** \brief Saves 16-bit grayscale cloud as image to PNG file.
* \param[in] file_name the name of the file to write to disk
* \param[in] cloud point cloud to save
* \ingroup io
*/
void
savePNGFile (const std::string& file_name, const pcl::PointCloud<unsigned short>& cloud)
{
saveShortPNGFile(file_name, &cloud.points[0], cloud.width, cloud.height, 1);
}
PCL_EXPORTS void
savePNGFile (const std::string& file_name, const pcl::PointCloud<unsigned short>& cloud);

/** \brief Saves a PCLImage (formely ROS sensor_msgs::Image) to PNG file.
* \param[in] file_name the name of the file to write to disk
* \param[in] image image to save
* \ingroup io
* \note Currently only "rgb8", "mono8", and "mono16" image encodings are supported.
*/
void
savePNGFile (const std::string& file_name, const pcl::PCLImage& image)
{
if (image.encoding == "rgb8")
{
saveRgbPNGFile(file_name, &image.data[0], image.width, image.height);
}
else if (image.encoding == "mono8")
{
saveCharPNGFile(file_name, &image.data[0], image.width, image.height, 1);
}
else if (image.encoding == "mono16")
{
saveShortPNGFile(file_name, reinterpret_cast<const unsigned short*>(&image.data[0]), image.width, image.height, 1);
}
else
{
PCL_ERROR ("[pcl::io::savePNGFile] Unsupported image encoding \"%s\".\n", image.encoding.c_str ());
}
}
PCL_EXPORTS void
savePNGFile (const std::string& file_name, const pcl::PCLImage& image);

/** \brief Saves RGB fields of cloud as image to PNG file.
* \param[in] file_name the name of the file to write to disk
* \param[in] cloud point cloud to save
* \ingroup io
*/
template <typename T>
template <typename T>
PCL_DEPRECATED (void savePNGFile (const std::string& file_name, const pcl::PointCloud<T>& cloud),
"pcl::io::savePNGFile<typename T> (file_name, cloud) is deprecated, please use a new generic "
"function pcl::io::savePNGFile (file_name, cloud, field_name) with \"rgb\" as the field name."
Expand Down Expand Up @@ -170,16 +143,8 @@ namespace pcl
"pcl::io::savePNGFile (file_name, cloud) is deprecated, please use a new generic function "
"pcl::io::savePNGFile (file_name, cloud, field_name) with \"label\" as the field name."
);
void
savePNGFile (const std::string& file_name, const pcl::PointCloud<pcl::PointXYZL>& cloud)
{
std::vector<unsigned short> data(cloud.width * cloud.height);
for (size_t i = 0; i < cloud.points.size (); ++i)
{
data[i] = static_cast<unsigned short> (cloud.points[i].label);
}
saveShortPNGFile(file_name, &data[0], cloud.width, cloud.height,1);
}
PCL_EXPORTS void
savePNGFile (const std::string& file_name, const pcl::PointCloud<pcl::PointXYZL>& cloud);

/** \brief Saves the data from the specified field of the point cloud as image to PNG file.
* \param[in] file_name the name of the file to write to disk
Expand Down
51 changes: 51 additions & 0 deletions io/src/png_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,54 @@ pcl::io::saveShortPNGFile (const std::string &file_name, const unsigned short *s

flipAndWritePng(file_name, importer);
}

void
pcl::io::saveRgbPNGFile (const std::string& file_name, const unsigned char *rgb_image, int width, int height)
{
saveCharPNGFile(file_name, rgb_image, width, height, 3);
}

void
pcl::io::savePNGFile (const std::string& file_name, const pcl::PointCloud<unsigned char>& cloud)
{
saveCharPNGFile(file_name, &cloud.points[0], cloud.width, cloud.height, 1);
}

void
pcl::io::savePNGFile (const std::string& file_name, const pcl::PointCloud<unsigned short>& cloud)
{
saveShortPNGFile(file_name, &cloud.points[0], cloud.width, cloud.height, 1);
}

void
pcl::io::savePNGFile (const std::string& file_name, const pcl::PCLImage& image)
{
if (image.encoding == "rgb8")
{
saveRgbPNGFile(file_name, &image.data[0], image.width, image.height);
}
else if (image.encoding == "mono8")
{
saveCharPNGFile(file_name, &image.data[0], image.width, image.height, 1);
}
else if (image.encoding == "mono16")
{
saveShortPNGFile(file_name, reinterpret_cast<const unsigned short*>(&image.data[0]), image.width, image.height, 1);
}
else
{
PCL_ERROR ("[pcl::io::savePNGFile] Unsupported image encoding \"%s\".\n", image.encoding.c_str ());
}
}

void
pcl::io::savePNGFile (const std::string& file_name, const pcl::PointCloud<pcl::PointXYZL>& cloud)
{
std::vector<unsigned short> data(cloud.width * cloud.height);
for (size_t i = 0; i < cloud.points.size (); ++i)
{
data[i] = static_cast<unsigned short> (cloud.points[i].label);
}
saveShortPNGFile(file_name, &data[0], cloud.width, cloud.height,1);
}