Point Cloud Library (PCL)  1.9.1
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 #ifndef PCL_IO_PNG_IO_H_
41 #define PCL_IO_PNG_IO_H_
42 
43 #include <pcl/pcl_macros.h>
44 #include <pcl/point_cloud.h>
45 #include <pcl/point_types.h>
46 #include <pcl/console/print.h>
47 #include <string>
48 #include <vector>
49 #include <pcl/io/point_cloud_image_extractors.h>
50 
51 namespace pcl
52 {
53  namespace io
54  {
55  /** \brief Saves 8-bit encoded image to PNG file.
56  * \param[in] file_name the name of the file to write to disk
57  * \param[in] mono_image image grayscale data
58  * \param[in] width image width
59  * \param[in] height image height
60  * \param[in] channels number of channels
61  * \ingroup io
62  */
63  PCL_EXPORTS void
64  saveCharPNGFile (const std::string& file_name, const unsigned char *mono_image, int width, int height, int channels);
65 
66  /** \brief Saves 16-bit encoded image to PNG file.
67  * \param[in] file_name the name of the file to write to disk
68  * \param[in] short_image image short data
69  * \param[in] width image width
70  * \param[in] height image height
71  * \param[in] channels number of channels
72  * \ingroup io
73  */
74  PCL_EXPORTS void
75  saveShortPNGFile (const std::string& file_name, const unsigned short *short_image, int width, int height, int channels);
76 
77  /** \brief Saves 8-bit encoded RGB image to PNG file.
78  * \param[in] file_name the name of the file to write to disk
79  * \param[in] rgb_image image rgb data
80  * \param[in] width image width
81  * \param[in] height image height
82  * \ingroup io
83  */
84  PCL_EXPORTS void
85  saveRgbPNGFile (const std::string& file_name, const unsigned char *rgb_image, int width, int height);
86 
87  /** \brief Saves 8-bit grayscale cloud as image to PNG file.
88  * \param[in] file_name the name of the file to write to disk
89  * \param[in] cloud point cloud to save
90  * \ingroup io
91  */
92  PCL_EXPORTS void
93  savePNGFile (const std::string& file_name, const pcl::PointCloud<unsigned char>& cloud);
94 
95  /** \brief Saves 16-bit grayscale cloud as image to PNG file.
96  * \param[in] file_name the name of the file to write to disk
97  * \param[in] cloud point cloud to save
98  * \ingroup io
99  */
100  PCL_EXPORTS void
101  savePNGFile (const std::string& file_name, const pcl::PointCloud<unsigned short>& cloud);
102 
103  /** \brief Saves a PCLImage (formerly ROS sensor_msgs::Image) to PNG file.
104  * \param[in] file_name the name of the file to write to disk
105  * \param[in] image image to save
106  * \ingroup io
107  * \note Currently only "rgb8", "mono8", and "mono16" image encodings are supported.
108  */
109  PCL_EXPORTS void
110  savePNGFile (const std::string& file_name, const pcl::PCLImage& image);
111 
112  /** \brief Saves the data from the specified field of the point cloud as image to PNG file.
113  * \param[in] file_name the name of the file to write to disk
114  * \param[in] cloud point cloud to save
115  * \param[in] field_name the name of the field to extract data from
116  * \ingroup io
117  */
118  template <typename PointT> void
119  savePNGFile (const std::string& file_name, const pcl::PointCloud<PointT>& cloud, const std::string& field_name)
120  {
121  typedef typename PointCloudImageExtractor<PointT>::Ptr PointCloudImageExtractorPtr;
122  PointCloudImageExtractorPtr pcie;
123  if (field_name == "normal")
124  {
125  pcie = PointCloudImageExtractorPtr (new PointCloudImageExtractorFromNormalField<PointT>);
126  }
127  else if (field_name == "rgb")
128  {
129  pcie = PointCloudImageExtractorPtr (new PointCloudImageExtractorFromRGBField<PointT>);
130  }
131  else if (field_name == "label")
132  {
133  pcie = PointCloudImageExtractorPtr (new PointCloudImageExtractorFromLabelField<PointT>);
134  }
135  else if (field_name == "z")
136  {
137  pcie = PointCloudImageExtractorPtr (new PointCloudImageExtractorFromZField<PointT>);
138  }
139  else if (field_name == "curvature")
140  {
141  pcie = PointCloudImageExtractorPtr (new PointCloudImageExtractorFromCurvatureField<PointT>);
142  }
143  else if (field_name == "intensity")
144  {
145  pcie = PointCloudImageExtractorPtr (new PointCloudImageExtractorFromIntensityField<PointT>);
146  }
147  else
148  {
149  PCL_ERROR ("[pcl::io::savePNGFile] Unsupported field \"%s\".\n", field_name.c_str ());
150  return;
151  }
152  pcl::PCLImage image;
153  if (pcie->extract (cloud, image))
154  {
155  savePNGFile(file_name, image);
156  }
157  else
158  {
159  PCL_ERROR ("[pcl::io::savePNGFile] Failed to extract an image from \"%s\" field.\n", field_name.c_str());
160  }
161  }
162 
163  }
164 }
165 
166 #endif //#ifndef PCL_IO_PNG_IO_H_
Image Extractor which uses the data present in the "curvature" field to produce a curvature map (as a...
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.
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
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.
boost::shared_ptr< PointCloudImageExtractor< PointT > > Ptr
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 "normal" field.
Defines all the PCL implemented PointT point type structures.
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.
Image Extractor which uses the data present in the "intensity" field to produce a monochrome intensit...
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.
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 "z" field to produce a depth map (as a monochrome ...