00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2010-2011, Willow Garage, Inc. 00006 * 00007 * All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 00013 * * Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * * Redistributions in binary form must reproduce the above 00016 * copyright notice, this list of conditions and the following 00017 * disclaimer in the documentation and/or other materials provided 00018 * with the distribution. 00019 * * Neither the name of the copyright holder(s) nor the names of its 00020 * contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00029 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00032 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00033 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 * $Id$ 00037 * Authors: Anatoly Baksheev 00038 */ 00039 00040 #ifndef PCL_IO_PNG_IO_H_ 00041 #define PCL_IO_PNG_IO_H_ 00042 00043 #include <pcl/pcl_macros.h> 00044 #include <pcl/point_cloud.h> 00045 #include <pcl/point_types.h> 00046 #include <pcl/console/print.h> 00047 #include <string> 00048 #include <vector> 00049 #include <pcl/io/point_cloud_image_extractors.h> 00050 00051 namespace pcl 00052 { 00053 namespace io 00054 { 00055 /** \brief Saves 8-bit encoded image to PNG file. 00056 * \param[in] file_name the name of the file to write to disk 00057 * \param[in] mono_image image grayscale data 00058 * \param[in] width image width 00059 * \param[in] height image height 00060 * \param[in] channels number of channels 00061 * \ingroup io 00062 */ 00063 PCL_EXPORTS void 00064 saveCharPNGFile (const std::string& file_name, const unsigned char *mono_image, int width, int height, int channels); 00065 00066 /** \brief Saves 16-bit encoded image to PNG file. 00067 * \param[in] file_name the name of the file to write to disk 00068 * \param[in] short_image image short data 00069 * \param[in] width image width 00070 * \param[in] height image height 00071 * \param[in] channels number of channels 00072 * \ingroup io 00073 */ 00074 PCL_EXPORTS void 00075 saveShortPNGFile (const std::string& file_name, const unsigned short *short_image, int width, int height, int channels); 00076 00077 /** \brief Saves 8-bit encoded RGB image to PNG file. 00078 * \param[in] file_name the name of the file to write to disk 00079 * \param[in] rgb_image image rgb data 00080 * \param[in] width image width 00081 * \param[in] height image height 00082 * \ingroup io 00083 */ 00084 PCL_EXPORTS void 00085 saveRgbPNGFile (const std::string& file_name, const unsigned char *rgb_image, int width, int height) 00086 { 00087 saveCharPNGFile(file_name, rgb_image, width, height, 3); 00088 } 00089 00090 /** \brief Saves 8-bit grayscale cloud as image to PNG file. 00091 * \param[in] file_name the name of the file to write to disk 00092 * \param[in] cloud point cloud to save 00093 * \ingroup io 00094 */ 00095 void 00096 savePNGFile (const std::string& file_name, const pcl::PointCloud<unsigned char>& cloud) 00097 { 00098 saveCharPNGFile(file_name, &cloud.points[0], cloud.width, cloud.height, 1); 00099 } 00100 00101 /** \brief Saves 16-bit grayscale cloud as image to PNG file. 00102 * \param[in] file_name the name of the file to write to disk 00103 * \param[in] cloud point cloud to save 00104 * \ingroup io 00105 */ 00106 void 00107 savePNGFile (const std::string& file_name, const pcl::PointCloud<unsigned short>& cloud) 00108 { 00109 saveShortPNGFile(file_name, &cloud.points[0], cloud.width, cloud.height, 1); 00110 } 00111 00112 /** \brief Saves a PCLImage (formely ROS sensor_msgs::Image) to PNG file. 00113 * \param[in] file_name the name of the file to write to disk 00114 * \param[in] image image to save 00115 * \ingroup io 00116 * \note Currently only "rgb8", "mono8", and "mono16" image encodings are supported. 00117 */ 00118 void 00119 savePNGFile (const std::string& file_name, const pcl::PCLImage& image) 00120 { 00121 if (image.encoding == "rgb8") 00122 { 00123 saveRgbPNGFile(file_name, &image.data[0], image.width, image.height); 00124 } 00125 else if (image.encoding == "mono8") 00126 { 00127 saveCharPNGFile(file_name, &image.data[0], image.width, image.height, 1); 00128 } 00129 else if (image.encoding == "mono16") 00130 { 00131 saveShortPNGFile(file_name, reinterpret_cast<const unsigned short*>(&image.data[0]), image.width, image.height, 1); 00132 } 00133 else 00134 { 00135 PCL_ERROR ("[pcl::io::savePNGFile] Unsupported image encoding \"%s\".\n", image.encoding.c_str ()); 00136 } 00137 } 00138 00139 /** \brief Saves RGB fields of cloud as image to PNG file. 00140 * \param[in] file_name the name of the file to write to disk 00141 * \param[in] cloud point cloud to save 00142 * \ingroup io 00143 */ 00144 PCL_DEPRECATED (template <typename T> void savePNGFile (const std::string& file_name, const pcl::PointCloud<T>& cloud), 00145 "pcl::io::savePNGFile<typename T> (file_name, cloud) is deprecated, please use a new generic " 00146 "function pcl::io::savePNGFile (file_name, cloud, field_name) with \"rgb\" as the field name." 00147 ); 00148 template <typename T> void 00149 savePNGFile (const std::string& file_name, const pcl::PointCloud<T>& cloud) 00150 { 00151 std::vector<unsigned char> data(cloud.width * cloud.height * 3); 00152 00153 for (size_t i = 0; i < cloud.points.size (); ++i) 00154 { 00155 data[i*3 + 0] = cloud.points[i].r; 00156 data[i*3 + 1] = cloud.points[i].g; 00157 data[i*3 + 2] = cloud.points[i].b; 00158 } 00159 saveRgbPNGFile(file_name, &data[0], cloud.width, cloud.height); 00160 } 00161 00162 /** \brief Saves Labeled Point cloud as image to PNG file. 00163 * \param[in] file_name the name of the file to write to disk 00164 * \param[in] cloud point cloud to save 00165 * \ingroup io 00166 * Warning: Converts to 16 bit (for png), labels using more than 16 bits will cause problems 00167 */ 00168 PCL_DEPRECATED (void savePNGFile (const std::string& file_name, const pcl::PointCloud<pcl::PointXYZL>& cloud), 00169 "pcl::io::savePNGFile (file_name, cloud) is deprecated, please use a new generic function " 00170 "pcl::io::savePNGFile (file_name, cloud, field_name) with \"label\" as the field name." 00171 ); 00172 void 00173 savePNGFile (const std::string& file_name, const pcl::PointCloud<pcl::PointXYZL>& cloud) 00174 { 00175 std::vector<unsigned short> data(cloud.width * cloud.height); 00176 for (size_t i = 0; i < cloud.points.size (); ++i) 00177 { 00178 data[i] = static_cast<unsigned short> (cloud.points[i].label); 00179 } 00180 saveShortPNGFile(file_name, &data[0], cloud.width, cloud.height,1); 00181 } 00182 00183 /** \brief Saves the data from the specified field of the point cloud as image to PNG file. 00184 * \param[in] file_name the name of the file to write to disk 00185 * \param[in] cloud point cloud to save 00186 * \param[in] field_name the name of the field to extract data from 00187 * \ingroup io 00188 */ 00189 template <typename PointT> void 00190 savePNGFile (const std::string& file_name, const pcl::PointCloud<PointT>& cloud, const std::string& field_name) 00191 { 00192 typedef typename PointCloudImageExtractor<PointT>::Ptr PointCloudImageExtractorPtr; 00193 PointCloudImageExtractorPtr pcie; 00194 if (field_name == "normal") 00195 { 00196 pcie = PointCloudImageExtractorPtr (new PointCloudImageExtractorFromNormalField<PointT>); 00197 } 00198 else if (field_name == "rgb") 00199 { 00200 pcie = PointCloudImageExtractorPtr (new PointCloudImageExtractorFromRGBField<PointT>); 00201 } 00202 else if (field_name == "label") 00203 { 00204 pcie = PointCloudImageExtractorPtr (new PointCloudImageExtractorFromLabelField<PointT>); 00205 } 00206 else if (field_name == "z") 00207 { 00208 pcie = PointCloudImageExtractorPtr (new PointCloudImageExtractorFromZField<PointT>); 00209 } 00210 else if (field_name == "curvature") 00211 { 00212 pcie = PointCloudImageExtractorPtr (new PointCloudImageExtractorFromCurvatureField<PointT>); 00213 } 00214 else if (field_name == "intensity") 00215 { 00216 pcie = PointCloudImageExtractorPtr (new PointCloudImageExtractorFromIntensityField<PointT>); 00217 } 00218 else 00219 { 00220 PCL_ERROR ("[pcl::io::savePNGFile] Unsupported field \"%s\".\n", field_name.c_str ()); 00221 return; 00222 } 00223 pcl::PCLImage image; 00224 if (pcie->extract (cloud, image)) 00225 { 00226 savePNGFile(file_name, image); 00227 } 00228 else 00229 { 00230 PCL_ERROR ("[pcl::io::savePNGFile] Failed to extract an image from \"%s\" field.\n", field_name.c_str()); 00231 } 00232 } 00233 00234 } 00235 } 00236 00237 #endif //#ifndef PCL_IO_PNG_IO_H_
Except where otherwise noted, the PointClouds.org web pages are licensed under Creative Commons Attribution 3.0.
Pages generated on Wed Mar 25 00:24:30 2015