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