Point Cloud Library (PCL)  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
spring.hpp
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 Willow Garage, Inc. 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: spring.hpp 3631 2011-12-22 19:40:30Z nizar $
00037  *
00038  */
00039 
00040 #ifndef PCL_POINT_CLOUD_SPRING_IMPL_HPP_
00041 #define PCL_POINT_CLOUD_SPRING_IMPL_HPP_
00042 
00043 template <typename PointT> inline bool
00044 pcl::PointCloudSpring<PointT>::initCompute ()
00045 {
00046   if ((expand_policy_ != MIRROR) && (expand_policy_ != DUPLICATE))
00047   {
00048     PCL_THROW_EXCEPTION (InitFailedException,
00049                          "[pcl::PointCloudSpring::initCompute] init failed: " 
00050                          << "expansion policy is either MIRROR or DUPLICATE");
00051     return false;
00052   }
00053 
00054   if ((direction_ != HORIZONTAL) && (direction_ != VERTICAL) && (direction_ != BOTH))
00055   {
00056     PCL_THROW_EXCEPTION (InitFailedException,
00057                          "[pcl::PointCloudSpring::initCompute] init failed: "
00058                          << "border must be a HORIZONTAL, VERTICAL or BOTH");
00059     return false;
00060   }
00061 
00062   if (amount_ <= 0)
00063   {
00064     PCL_THROW_EXCEPTION (InitFailedException,
00065                          "[pcl::PointCloudSpring::initCompute] init failed: " 
00066                          << "expansion amount must be strict positive!");
00067     return false;
00068   }
00069         
00070   if (!input_->isOrganized () && (expand_policy_ == VERTICAL || expand_policy_ == BOTH))
00071   {
00072     PCL_THROW_EXCEPTION (InitFailedException,
00073                          "[pcl::PointCloudSpring::initCompute] init failed: " 
00074                          << "vertical expansion requires organised point cloud");
00075     return false;
00076   }
00077   return true;
00078 }
00079 
00080 template <typename PointT> void 
00081 pcl::PointCloudSpring<PointT>::expandHorizontal(const PointT& val)
00082 {
00083   uint32_t old_height = input_->height;
00084   uint32_t old_width = input_->width;
00085   uint32_t new_width = old_width + 2*amount_;
00086   for (int j = 0; j < input_->height; ++j)
00087   {
00088     iterator start = input_->begin() + (j * new_width);
00089     input_->insert (start, amount_, val);
00090     start = input_->begin() + (j * new_width) + old_width + amount_;
00091     input_->insert (start, amount_, val);
00092     input_->height = old_height;
00093   }
00094   input_->width = old_width + 2*amount_;
00095   input_->height = old_height;
00096 }
00097       
00098 template <typename PointT> void 
00099 pcl::PointCloudSpring<PointT>::expandVertical(const PointT& val)
00100 {
00101   uint32_t old_height = input_->height;
00102   uint32_t old_width = input_->width;
00103   input_->insert (input_->begin (), amount_ * old_width, val);
00104   iterator last = input_->end () -1;
00105   input_->insert (last, amount_ * old_width, val);
00106   input_->width = old_width;
00107   input_->height = old_height + 2*amount_;
00108 }
00109 
00110 template <typename PointT> void 
00111 pcl::PointCloudSpring<PointT>::expandHorizontalDuplicate()
00112 {
00113   int old_height = input_->height;
00114   int old_width = input_->width;
00115   int new_width = old_width + 2*amount_;
00116   for (int j = 0; j < old_height; ++j)
00117     for(int i = 0; i < amount_; ++i)
00118     {
00119       iterator start = input_->begin () + (j * new_width);
00120       input_->insert (start, *start);
00121       start = input_->begin () + (j * new_width) + old_width + i;
00122       input_->insert (start, *start);
00123     }
00124 
00125   input_->width = old_width + 2*amount_;
00126   input_->height = old_height;
00127 }
00128 
00129 template <typename PointT> void 
00130 pcl::PointCloudSpring<PointT>::expandVerticalDuplicate()
00131 {
00132   uint32_t old_height = input_->height;
00133   uint32_t old_width = input_->width;
00134   for(int i = 0; i < amount_; ++i)
00135   {
00136     input_->insert (input_->begin (), input_->begin (), input_->begin () + old_width);
00137     input_->insert (input_->end (), input_->end () - old_width, input_->end ());
00138   }
00139   input_->width = old_width;
00140   input_->height = old_height + 2*amount_;
00141 }
00142 
00143 template <typename PointT> void 
00144 pcl::PointCloudSpring<PointT>::expandHorizontalMirror()
00145 {
00146   int old_height = input_->height;
00147   int old_width = input_->width;
00148   int new_width = old_width + 2*amount_;
00149   for (int j = 0; j < old_height; ++j)
00150     for(int i = 0; i < amount_; ++i)
00151     {
00152       iterator start = input_->begin () + (j * new_width);
00153       input_->insert (start, *(start + 2*i));
00154       start = input_->begin () + (j * new_width) + old_width + 2*i;
00155       input_->insert (start+1, *(start - 2*i));
00156     }
00157   input_->width = old_width + 2*amount_;
00158   input_->height = old_height;
00159 }
00160 
00161 template <typename PointT> void 
00162 pcl::PointCloudSpring<PointT>::expandVerticalMirror()
00163 {
00164   uint32_t old_height = input_->height;
00165   uint32_t old_width = input_->width;
00166 
00167   iterator up = input_->begin (), low = input_->end ();
00168   for(int i = 0; i < amount_; ++i)
00169   {
00170     input_->insert (input_->begin (), up, up + old_width);
00171     up+= old_width;
00172     input_->insert (input_->end (), low - old_width, low);
00173     low-= old_width;
00174   }
00175   input_->width = old_width;
00176   input_->height = old_height + 2*amount_;
00177 }
00178 
00179 template <typename PointT> inline void 
00180 pcl::PointCloudSpring<PointT>::deleteRows ()
00181 {
00182   uint32_t old_height = input_->height;
00183   uint32_t old_width = input_->width;
00184   input_->erase (input_->begin (), input_->begin () + amount_ * old_width);
00185   input_->erase (input_->end () - amount_ * old_width, input_->end ());
00186   input_->height = old_height - 2*amount_;
00187   input_->width = old_width;
00188 }
00189 
00190 template <typename PointT> inline void 
00191 pcl::PointCloudSpring<PointT>::deleteCols ()
00192 {
00193   uint32_t old_height = input_->height;
00194   uint32_t old_width = input_->width;
00195   uint32_t new_width = old_width - 2 * amount_;
00196   for(uint32_t j = 0; j < old_height; j++)
00197   {
00198     iterator start = input_->begin () + j * new_width;
00199     input_->erase (start, start + amount_);
00200     start = input_->begin () + (j+1) * new_width;
00201     input_->erase (start, start + amount_);    
00202   }
00203   input_->height = old_height;
00204   input_->width = new_width;
00205 }
00206 
00207 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines