png_io.h
Go to the documentation of this file.
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 <string>
00047 #include <vector>
00048 
00049 namespace pcl
00050 {
00051   namespace io
00052   {
00061     PCL_EXPORTS void
00062     saveCharPNGFile (const std::string& file_name, const unsigned char *mono_image, int width, int height, int channels);
00063 
00072     PCL_EXPORTS void
00073     saveShortPNGFile (const std::string& file_name, const unsigned short *short_image, int width, int height, int channels);
00074 
00082     PCL_EXPORTS void 
00083     saveRgbPNGFile (const std::string& file_name, const unsigned char *rgb_image, int width, int height)
00084     {
00085       saveCharPNGFile(file_name, rgb_image, width, height, 3);
00086     }
00087 
00093     void
00094     savePNGFile (const std::string& file_name, const pcl::PointCloud<unsigned char>& cloud)
00095     {
00096       saveCharPNGFile(file_name, &cloud.points[0], cloud.width, cloud.height, 1);
00097     }
00098 
00105     void
00106     savePNGFile (const std::string& file_name, const pcl::PointCloud<unsigned short>& cloud)
00107     {
00108       saveShortPNGFile(file_name, &cloud.points[0], cloud.width, cloud.height, 1);
00109     }
00110 
00116     template <typename T> void
00117     savePNGFile (const std::string& file_name, const pcl::PointCloud<T>& cloud)
00118     {
00119       std::vector<unsigned char> data(cloud.width * cloud.height * 3);
00120 
00121       for (size_t i = 0; i < cloud.points.size (); ++i)
00122       {
00123         data[i*3 + 0] = cloud.points[i].r;
00124         data[i*3 + 1] = cloud.points[i].g;
00125         data[i*3 + 2] = cloud.points[i].b;        
00126       }
00127       saveRgbPNGFile(file_name, &data[0], cloud.width, cloud.height);
00128     } 
00129     
00136     void
00137     savePNGFile (const std::string& file_name, const pcl::PointCloud<pcl::PointXYZL>& cloud)
00138     {
00139       std::vector<unsigned short> data(cloud.width * cloud.height);
00140       
00141       for (size_t i = 0; i < cloud.points.size (); ++i)
00142       {
00143         data[i] = static_cast<unsigned short> (cloud.points[i].label);      
00144       }
00145       saveShortPNGFile(file_name, &data[0], cloud.width, cloud.height,1);
00146     }  
00147   }
00148 }
00149 
00150 #endif  //#ifndef PCL_IO_PNG_IO_H_


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:28:18