00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2013-, Open Perception, 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 */ 00037 #ifndef PCL_POINT_CLOUD_IMAGE_EXTRACTORS_H_ 00038 #define PCL_POINT_CLOUD_IMAGE_EXTRACTORS_H_ 00039 00040 #include <pcl/point_cloud.h> 00041 #include <pcl/PCLImage.h> 00042 00043 namespace pcl 00044 { 00045 namespace io 00046 { 00047 ////////////////////////////////////////////////////////////////////////////////////// 00048 /** \brief Base Image Extractor class for organized point clouds. 00049 * 00050 * This is an abstract class that declares an interface for image extraction from 00051 * organized point clouds. The family of its subclasses provide functionality to 00052 * extract images from particular fields. 00053 * 00054 * The following piece of code demonstrates typical usage of a PointCloudImageExtractor 00055 * subclass. Here the data are extracted from the "label" field and are saved as a 00056 * PNG image file. 00057 * 00058 * \code 00059 * // Source point cloud (needs to be filled with data of course) 00060 * pcl::PointCloud<pcl::PointXYZLabel> cloud; 00061 * // Target image 00062 * pcl::PCLImage image; 00063 * // Create PointCloudImageExtractor subclass that can handle "label" field 00064 * pcl::io::PointCloudImageExtractorFromLabelField<pcl::XYZLabel> pcie; 00065 * // Set it up if not happy with the defaults 00066 * pcie.setColorMode(pcie.COLORS_RGB_RANDOM); 00067 * // Try to extract an image 00068 * bool success = pcie.extract(cloud, image); 00069 * // Save to file if succeeded 00070 * if (success) 00071 * pcl::io::saveImage ("filename.png", image); 00072 * \endcode 00073 * 00074 * \author Sergey Alexandrov 00075 * \ingroup io 00076 */ 00077 template <typename PointT> 00078 class PointCloudImageExtractor 00079 { 00080 public: 00081 typedef pcl::PointCloud<PointT> PointCloud; 00082 00083 typedef boost::shared_ptr<PointCloudImageExtractor<PointT> > Ptr; 00084 typedef boost::shared_ptr<const PointCloudImageExtractor<PointT> > ConstPtr; 00085 00086 /** \brief Constructor. */ 00087 PointCloudImageExtractor () {} 00088 00089 /** \brief Destructor. */ 00090 virtual ~PointCloudImageExtractor () {} 00091 00092 /** \brief Obtain the image from the given cloud. 00093 * \param[in] cloud organized point cloud to extract image from 00094 * \param[out] image the output image 00095 * \return true if the operation was successful, false otherwise 00096 */ 00097 virtual bool 00098 extract (const PointCloud& cloud, pcl::PCLImage& image) const = 0; 00099 }; 00100 00101 ////////////////////////////////////////////////////////////////////////////////////// 00102 /** \brief Image Extractor extension which provides functionality to apply scaling to 00103 * the values extracted from a field. 00104 * \author Sergey Alexandrov 00105 * \ingroup io 00106 */ 00107 template <typename PointT> 00108 class PointCloudImageExtractorWithScaling : public PointCloudImageExtractor<PointT> 00109 { 00110 typedef typename PointCloudImageExtractor<PointT>::PointCloud PointCloud; 00111 00112 public: 00113 typedef boost::shared_ptr<PointCloudImageExtractorWithScaling<PointT> > Ptr; 00114 typedef boost::shared_ptr<const PointCloudImageExtractorWithScaling<PointT> > ConstPtr; 00115 00116 /** \brief Different scaling methods. 00117 * <ul> 00118 * <li><b>SCALING_NO</b> - no scaling.</li> 00119 * <li><b>SCALING_FULL_RANGE</b> - scales to full range of the output value.</li> 00120 * <li><b>SCASING_FIXED_FACTOR</b> - scales by a given fixed factor.</li> 00121 * </ul> 00122 */ 00123 enum ScalingMethod 00124 { 00125 SCALING_NO, 00126 SCALING_FULL_RANGE, 00127 SCALING_FIXED_FACTOR 00128 }; 00129 00130 /** \brief Constructor. */ 00131 PointCloudImageExtractorWithScaling (const std::string& field_name, const ScalingMethod scaling_method) 00132 : field_name_ (field_name) 00133 , scaling_method_ (scaling_method) 00134 , scaling_factor_ (1.0f) 00135 { 00136 } 00137 00138 /** \brief Constructor. */ 00139 PointCloudImageExtractorWithScaling (const std::string& field_name, const float scaling_factor) 00140 : field_name_ (field_name) 00141 , scaling_method_ (SCALING_FIXED_FACTOR) 00142 , scaling_factor_ (scaling_factor) 00143 { 00144 } 00145 00146 /** \brief Destructor. */ 00147 virtual ~PointCloudImageExtractorWithScaling () {} 00148 00149 /** \brief Obtain the image from the given cloud. 00150 * \param[in] cloud organized point cloud to extract image from 00151 * \param[out] image the output image 00152 * \return true if the operation was successful, false otherwise 00153 */ 00154 virtual bool 00155 extract (const PointCloud& cloud, pcl::PCLImage& image) const; 00156 00157 /** \brief Set scaling method. */ 00158 inline void 00159 setScalingMethod (const ScalingMethod scaling_method) 00160 { 00161 scaling_method_ = scaling_method; 00162 } 00163 00164 /** \brief Set fixed scaling factor. */ 00165 inline void 00166 setScalingFactor (const float scaling_factor) 00167 { 00168 scaling_factor_ = scaling_factor; 00169 } 00170 00171 protected: 00172 00173 std::string field_name_; 00174 ScalingMethod scaling_method_; 00175 float scaling_factor_; 00176 }; 00177 00178 ////////////////////////////////////////////////////////////////////////////////////// 00179 /** \brief Image Extractor which uses the data present in the "normal" field. Normal 00180 * vector components (x, y, z) are mapped to color channels (r, g, b respectively). 00181 * \author Sergey Alexandrov 00182 * \ingroup io 00183 */ 00184 template <typename PointT> 00185 class PointCloudImageExtractorFromNormalField : public PointCloudImageExtractor<PointT> 00186 { 00187 typedef typename PointCloudImageExtractor<PointT>::PointCloud PointCloud; 00188 00189 public: 00190 typedef boost::shared_ptr<PointCloudImageExtractorFromNormalField<PointT> > Ptr; 00191 typedef boost::shared_ptr<const PointCloudImageExtractorFromNormalField<PointT> > ConstPtr; 00192 00193 /** \brief Constructor. */ 00194 PointCloudImageExtractorFromNormalField () {} 00195 00196 /** \brief Destructor. */ 00197 virtual ~PointCloudImageExtractorFromNormalField () {} 00198 00199 /** \brief Obtain the color image from the given cloud. 00200 * The cloud should contain "normal" field. 00201 * \param[in] cloud organized point cloud to extract image from 00202 * \param[out] image the output image 00203 * \return true if the operation was successful, false otherwise 00204 */ 00205 virtual bool 00206 extract (const PointCloud& cloud, pcl::PCLImage& img) const; 00207 }; 00208 00209 ////////////////////////////////////////////////////////////////////////////////////// 00210 /** \brief Image Extractor which uses the data present in the "rgb" or "rgba" fields 00211 * to produce a color image with rgb8 encoding. 00212 * \author Sergey Alexandrov 00213 * \ingroup io 00214 */ 00215 template <typename PointT> 00216 class PointCloudImageExtractorFromRGBField : public PointCloudImageExtractor<PointT> 00217 { 00218 typedef typename PointCloudImageExtractor<PointT>::PointCloud PointCloud; 00219 00220 public: 00221 typedef boost::shared_ptr<PointCloudImageExtractorFromRGBField<PointT> > Ptr; 00222 typedef boost::shared_ptr<const PointCloudImageExtractorFromRGBField<PointT> > ConstPtr; 00223 00224 /** \brief Constructor. */ 00225 PointCloudImageExtractorFromRGBField () {} 00226 00227 /** \brief Destructor. */ 00228 virtual ~PointCloudImageExtractorFromRGBField () {} 00229 00230 /** \brief Obtain the color image from the given cloud. 00231 * The cloud should contain either "rgb" or "rgba" field. 00232 * \param[in] cloud organized point cloud to extract image from 00233 * \param[out] image the output image 00234 * \return true if the operation was successful, false otherwise 00235 */ 00236 virtual bool 00237 extract (const PointCloud& cloud, pcl::PCLImage& img) const; 00238 }; 00239 00240 ////////////////////////////////////////////////////////////////////////////////////// 00241 /** \brief Image Extractor which uses the data present in the "label" field to produce 00242 * either monochrome or RGB image where different labels correspond to different 00243 * colors. In the monochrome case colors are shades of gray, in the RGB case the 00244 * colors are generated randomly. 00245 * \author Sergey Alexandrov 00246 * \ingroup io 00247 */ 00248 template <typename PointT> 00249 class PointCloudImageExtractorFromLabelField : public PointCloudImageExtractor<PointT> 00250 { 00251 typedef typename PointCloudImageExtractor<PointT>::PointCloud PointCloud; 00252 00253 public: 00254 typedef boost::shared_ptr<PointCloudImageExtractorFromLabelField<PointT> > Ptr; 00255 typedef boost::shared_ptr<const PointCloudImageExtractorFromLabelField<PointT> > ConstPtr; 00256 00257 /** \brief Different modes for color mapping. 00258 * <ul> 00259 * <li><b>COLORS_MONO</b> - shades of gray (according to label id).</li> 00260 * <li><b>COLORS_RGB_RANDOM</b> - randomly generated RGB colors.</li> 00261 * </ul> 00262 */ 00263 enum ColorMode 00264 { 00265 COLORS_MONO, 00266 COLORS_RGB_RANDOM, 00267 }; 00268 00269 /** \brief Constructor. */ 00270 PointCloudImageExtractorFromLabelField (const ColorMode color_mode = COLORS_MONO) 00271 : color_mode_ (color_mode) 00272 { 00273 } 00274 00275 /** \brief Destructor. */ 00276 virtual ~PointCloudImageExtractorFromLabelField () {} 00277 00278 /** \brief Obtain the label image from the given cloud. 00279 * The cloud should contain "label" field. 00280 * \note Labels using more than 16 bits will cause problems in COLORS_MONO mode. 00281 * \param[in] cloud organized point cloud to extract image from 00282 * \param[out] image the output image 00283 * \return true if the operation was successful, false otherwise 00284 */ 00285 virtual bool 00286 extract (const PointCloud& cloud, pcl::PCLImage& img) const; 00287 00288 /** \brief Set color mapping mode. */ 00289 inline void 00290 setColorMode (const ColorMode color_mode) 00291 { 00292 color_mode_ = color_mode; 00293 } 00294 00295 private: 00296 00297 ColorMode color_mode_; 00298 }; 00299 00300 ////////////////////////////////////////////////////////////////////////////////////// 00301 /** \brief Image Extractor which uses the data present in the "z" field to produce a 00302 * depth map (as a monochrome image with mono16 encoding). 00303 * \author Sergey Alexandrov 00304 * \ingroup io 00305 */ 00306 template <typename PointT> 00307 class PointCloudImageExtractorFromZField : public PointCloudImageExtractorWithScaling<PointT> 00308 { 00309 typedef typename PointCloudImageExtractor<PointT>::PointCloud PointCloud; 00310 typedef typename PointCloudImageExtractorWithScaling<PointT>::ScalingMethod ScalingMethod; 00311 00312 public: 00313 typedef boost::shared_ptr<PointCloudImageExtractorFromZField<PointT> > Ptr; 00314 typedef boost::shared_ptr<const PointCloudImageExtractorFromZField<PointT> > ConstPtr; 00315 00316 /** \brief Constructor. 00317 * \param[i] scaling_factor a scaling factor to apply to each depth value (default 10000) 00318 */ 00319 PointCloudImageExtractorFromZField (const float scaling_factor = 10000) 00320 : PointCloudImageExtractorWithScaling<PointT> ("z", scaling_factor) 00321 { 00322 } 00323 00324 /** \brief Constructor. 00325 * \param[i] scaling_method a scaling method to use 00326 */ 00327 PointCloudImageExtractorFromZField (const ScalingMethod scaling_method) 00328 : PointCloudImageExtractorWithScaling<PointT> ("z", scaling_method) 00329 { 00330 } 00331 00332 /** \brief Destructor. */ 00333 virtual ~PointCloudImageExtractorFromZField () {} 00334 00335 protected: 00336 // Members derived from the base class 00337 using PointCloudImageExtractorWithScaling<PointT>::field_name_; 00338 using PointCloudImageExtractorWithScaling<PointT>::scaling_method_; 00339 using PointCloudImageExtractorWithScaling<PointT>::scaling_factor_; 00340 }; 00341 00342 ////////////////////////////////////////////////////////////////////////////////////// 00343 /** \brief Image Extractor which uses the data present in the "curvature" field to 00344 * produce a curvature map (as a monochrome image with mono16 encoding). 00345 * \author Sergey Alexandrov 00346 * \ingroup io 00347 */ 00348 template <typename PointT> 00349 class PointCloudImageExtractorFromCurvatureField : public PointCloudImageExtractorWithScaling<PointT> 00350 { 00351 typedef typename PointCloudImageExtractor<PointT>::PointCloud PointCloud; 00352 typedef typename PointCloudImageExtractorWithScaling<PointT>::ScalingMethod ScalingMethod; 00353 00354 public: 00355 typedef boost::shared_ptr<PointCloudImageExtractorFromCurvatureField<PointT> > Ptr; 00356 typedef boost::shared_ptr<const PointCloudImageExtractorFromCurvatureField<PointT> > ConstPtr; 00357 00358 /** \brief Constructor. 00359 * \param[i] scaling_method a scaling method to use (default SCALING_FULL_RANGE) 00360 */ 00361 PointCloudImageExtractorFromCurvatureField (const ScalingMethod scaling_method = PointCloudImageExtractorWithScaling<PointT>::SCALING_FULL_RANGE) 00362 : PointCloudImageExtractorWithScaling<PointT> ("curvature", scaling_method) 00363 { 00364 } 00365 00366 /** \brief Constructor. 00367 * \param[i] scaling_factor a scaling factor to apply to each curvature value 00368 */ 00369 PointCloudImageExtractorFromCurvatureField (const float scaling_factor) 00370 : PointCloudImageExtractorWithScaling<PointT> ("curvature", scaling_factor) 00371 { 00372 } 00373 00374 /** \brief Destructor. */ 00375 virtual ~PointCloudImageExtractorFromCurvatureField () {} 00376 00377 protected: 00378 // Members derived from the base class 00379 using PointCloudImageExtractorWithScaling<PointT>::field_name_; 00380 using PointCloudImageExtractorWithScaling<PointT>::scaling_method_; 00381 using PointCloudImageExtractorWithScaling<PointT>::scaling_factor_; 00382 }; 00383 00384 ////////////////////////////////////////////////////////////////////////////////////// 00385 /** \brief Image Extractor which uses the data present in the "intensity" field to produce a 00386 * monochrome intensity image (with mono16 encoding). 00387 * \author Sergey Alexandrov 00388 * \ingroup io 00389 */ 00390 template <typename PointT> 00391 class PointCloudImageExtractorFromIntensityField : public PointCloudImageExtractorWithScaling<PointT> 00392 { 00393 typedef typename PointCloudImageExtractor<PointT>::PointCloud PointCloud; 00394 typedef typename PointCloudImageExtractorWithScaling<PointT>::ScalingMethod ScalingMethod; 00395 00396 public: 00397 typedef boost::shared_ptr<PointCloudImageExtractorFromIntensityField<PointT> > Ptr; 00398 typedef boost::shared_ptr<const PointCloudImageExtractorFromIntensityField<PointT> > ConstPtr; 00399 00400 /** \brief Constructor. 00401 * \param[i] scaling_method a scaling method to use (default SCALING_NO) 00402 */ 00403 PointCloudImageExtractorFromIntensityField (const ScalingMethod scaling_method = PointCloudImageExtractorWithScaling<PointT>::SCALING_NO) 00404 : PointCloudImageExtractorWithScaling<PointT> ("intensity", scaling_method) 00405 { 00406 } 00407 00408 /** \brief Constructor. 00409 * \param[i] scaling_factor a scaling factor to apply to each intensity value 00410 */ 00411 PointCloudImageExtractorFromIntensityField (const float scaling_factor) 00412 : PointCloudImageExtractorWithScaling<PointT> ("intensity", scaling_factor) 00413 { 00414 } 00415 00416 /** \brief Destructor. */ 00417 virtual ~PointCloudImageExtractorFromIntensityField () {} 00418 00419 protected: 00420 // Members derived from the base class 00421 using PointCloudImageExtractorWithScaling<PointT>::field_name_; 00422 using PointCloudImageExtractorWithScaling<PointT>::scaling_method_; 00423 using PointCloudImageExtractorWithScaling<PointT>::scaling_factor_; 00424 }; 00425 00426 } 00427 } 00428 00429 #include <pcl/io/impl/point_cloud_image_extractors.hpp> 00430 00431 #endif //#ifndef PCL_POINT_CLOUD_IMAGE_EXTRACTORS_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