Point Cloud Library (PCL)  1.14.1-dev
png_io.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of the copyright holder(s) nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id$
37  * Authors: Anatoly Baksheev
38  */
39 
40 #pragma once
41 
42 #include <pcl/pcl_macros.h>
43 #include <pcl/point_cloud.h>
44 #include <pcl/console/print.h>
45 #include <string>
46 #include <pcl/io/point_cloud_image_extractors.h>
47 
48 namespace pcl
49 {
50  namespace io
51  {
52  /** \brief Saves 8-bit encoded image to PNG file.
53  * \param[in] file_name the name of the file to write to disk
54  * \param[in] mono_image image grayscale data
55  * \param[in] width image width
56  * \param[in] height image height
57  * \param[in] channels number of channels
58  * \ingroup io
59  */
60  PCL_EXPORTS void
61  saveCharPNGFile (const std::string& file_name, const unsigned char *mono_image, int width, int height, int channels);
62 
63  /** \brief Saves 16-bit encoded image to PNG file.
64  * \param[in] file_name the name of the file to write to disk
65  * \param[in] short_image image short data
66  * \param[in] width image width
67  * \param[in] height image height
68  * \param[in] channels number of channels
69  * \ingroup io
70  */
71  PCL_EXPORTS void
72  saveShortPNGFile (const std::string& file_name, const unsigned short *short_image, int width, int height, int channels);
73 
74  /** \brief Saves 8-bit encoded RGB image to PNG file.
75  * \param[in] file_name the name of the file to write to disk
76  * \param[in] rgb_image image rgb data
77  * \param[in] width image width
78  * \param[in] height image height
79  * \ingroup io
80  */
81  PCL_EXPORTS void
82  saveRgbPNGFile (const std::string& file_name, const unsigned char *rgb_image, int width, int height);
83 
84  /** \brief Saves 8-bit grayscale cloud as image to PNG file.
85  * \param[in] file_name the name of the file to write to disk
86  * \param[in] cloud point cloud to save
87  * \ingroup io
88  */
89  PCL_EXPORTS void
90  savePNGFile (const std::string& file_name, const pcl::PointCloud<unsigned char>& cloud);
91 
92  /** \brief Saves 16-bit grayscale cloud as image to PNG file.
93  * \param[in] file_name the name of the file to write to disk
94  * \param[in] cloud point cloud to save
95  * \ingroup io
96  */
97  PCL_EXPORTS void
98  savePNGFile (const std::string& file_name, const pcl::PointCloud<unsigned short>& cloud);
99 
100  /** \brief Saves a PCLImage (formerly ROS sensor_msgs::Image) to PNG file.
101  * \param[in] file_name the name of the file to write to disk
102  * \param[in] image image to save
103  * \ingroup io
104  * \note Currently only "rgb8", "mono8", and "mono16" image encodings are supported.
105  */
106  PCL_EXPORTS void
107  savePNGFile (const std::string& file_name, const pcl::PCLImage& image);
108 
109  /** \brief Saves the data from the specified field of the point cloud as image to PNG file.
110  * \param[in] file_name the name of the file to write to disk
111  * \param[in] cloud point cloud to save
112  * \param[in] field_name the name of the field to extract data from
113  * \ingroup io
114  */
115  template <typename PointT> void
116  savePNGFile (const std::string& file_name, const pcl::PointCloud<PointT>& cloud, const std::string& field_name)
117  {
118  using PointCloudImageExtractorPtr = typename PointCloudImageExtractor<PointT>::Ptr;
119  PointCloudImageExtractorPtr pcie;
120  if (field_name == "normal")
121  {
122  pcie = PointCloudImageExtractorPtr (new PointCloudImageExtractorFromNormalField<PointT>);
123  }
124  else if (field_name == "rgb")
125  {
126  pcie = PointCloudImageExtractorPtr (new PointCloudImageExtractorFromRGBField<PointT>);
127  }
128  else if (field_name == "label")
129  {
130  pcie = PointCloudImageExtractorPtr (new PointCloudImageExtractorFromLabelField<PointT>);
131  }
132  else if (field_name == "z")
133  {
134  pcie = PointCloudImageExtractorPtr (new PointCloudImageExtractorFromZField<PointT>);
135  }
136  else if (field_name == "curvature")
137  {
138  pcie = PointCloudImageExtractorPtr (new PointCloudImageExtractorFromCurvatureField<PointT>);
139  }
140  else if (field_name == "intensity")
141  {
142  pcie = PointCloudImageExtractorPtr (new PointCloudImageExtractorFromIntensityField<PointT>);
143  }
144  else
145  {
146  PCL_ERROR ("[pcl::io::savePNGFile] Unsupported field \"%s\".\n", field_name.c_str ());
147  return;
148  }
149  pcl::PCLImage image;
150  if (pcie->extract (cloud, image))
151  {
152  savePNGFile(file_name, image);
153  }
154  else
155  {
156  PCL_ERROR ("[pcl::io::savePNGFile] Failed to extract an image from \"%s\" field.\n", field_name.c_str());
157  }
158  }
159 
160  }
161 }
Image Extractor which uses the data present in the "curvature" field to produce a curvature map (as a...
Image Extractor which uses the data present in the "intensity" field to produce a monochrome intensit...
Image Extractor which uses the data present in the "label" field to produce either monochrome or RGB ...
Image Extractor which uses the data present in the "normal" field.
Image Extractor which uses the data present in the "rgb" or "rgba" fields to produce a color image wi...
Image Extractor which uses the data present in the "z" field to produce a depth map (as a monochrome ...
shared_ptr< PointCloudImageExtractor< PointT > > Ptr
PCL_EXPORTS void saveShortPNGFile(const std::string &file_name, const unsigned short *short_image, int width, int height, int channels)
Saves 16-bit encoded image to PNG file.
PCL_EXPORTS void saveRgbPNGFile(const std::string &file_name, const unsigned char *rgb_image, int width, int height)
Saves 8-bit encoded RGB image to PNG file.
PCL_EXPORTS void saveCharPNGFile(const std::string &file_name, const unsigned char *mono_image, int width, int height, int channels)
Saves 8-bit encoded image to PNG file.
PCL_EXPORTS void savePNGFile(const std::string &file_name, const pcl::PointCloud< unsigned char > &cloud)
Saves 8-bit grayscale cloud as image to PNG file.
Defines all the PCL and non-PCL macros used.
#define PCL_EXPORTS
Definition: pcl_macros.h:325