Point Cloud Library (PCL)  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
spring.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 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.h 3626 2011-12-22 01:51:20Z nizar $
00037  *
00038  */
00039 
00040 #ifndef PCL_POINT_CLOUD_EXPANDER_H_
00041 #define PCL_POINT_CLOUD_EXPANDER_H_
00042 
00043 #include <pcl/point_cloud.h>
00044 
00045 namespace pcl
00046 {
00047 
00057   template <typename PointT>
00058   class PointCloudSpring
00059   {
00060     public:
00061       typedef typename pcl::PointCloud<PointT> PointCloud;
00062       typedef typename PointCloud::Ptr PointCloudPtr;
00063       typedef typename PointCloud::ConstPtr PointCloudConstPtr;
00064       typedef typename PointCloud::iterator iterator;
00065 
00067       enum EXPAND_POLICY { MIRROR = 0, DUPLICATE };
00069       enum DIRECTION { HORIZONTAL = 0, VERTICAL, BOTH };
00071       PointCloudSpring () : expand_policy_(-1), direction_(-1) {}
00073       inline void
00074       setExpandPolicy (int policy) { expand_policy_ = policy; }
00076       inline int
00077       getExpandPolicy () { return (expand_policy_); } 
00079       inline void
00080       setDirection (int direction) { direction_ = direction; }
00082       inline int
00083       getDirection () { return (direction_); } 
00085       inline void
00086       setAmount (int amount) { amount_ = amount; }
00088       inline int
00089       getAmount () { return (amount_); }
00091       inline void
00092       setInputCloud (PointCloudPtr& input) { input_ = input; }
00094       inline PointCloudPtr
00095       getInputCloud () { return (input_); }
00096       
00097     private:
00098       inline bool
00099       initCompute ();
00100       
00101     public:
00109       inline void
00110       expand ()
00111       {
00112         if (!initCompute ())
00113           PCL_THROW_EXCEPTION (InitFailedException,
00114                                "[pcl::PointCloudSpring::initCompute] init failed");
00115         if (expand_policy_ == DUPLICATE)
00116         {
00117           if ((direction_ == VERTICAL) || (direction_ == BOTH))
00118             expandVerticalDuplicate ();
00119           if ((direction_ == HORIZONTAL) || (direction_ == BOTH))
00120             expandHorizontalDuplicate ();
00121         }
00122         else
00123         {
00124           if ((direction_ == VERTICAL) || (direction_ == BOTH))
00125             expandVerticalMirror ();
00126           if ((direction_ == HORIZONTAL) || (direction_ == BOTH))
00127             expandHorizontalMirror ();
00128         }
00129       }
00130 
00134       inline void
00135       expand (const PointT& val)
00136       {
00137         if (!initCompute ())
00138           PCL_THROW_EXCEPTION (InitFailedException,
00139                                "[pcl::PointCloudSpring::initCompute] init failed");
00140         if ((direction_ == VERTICAL) || (direction_ == BOTH))
00141         {
00142           expandVertical (val);
00143         }
00144         if ((direction_ == HORIZONTAL) || (direction_ == BOTH))
00145         {
00146           expandHorizontal (val);
00147         }
00148       }
00149 
00156       inline void
00157       shrink ()
00158       {
00159         if (!initCompute ())
00160           PCL_THROW_EXCEPTION (InitFailedException,
00161                                "[pcl::PointCloudShrinker::initCompute] init failed");
00162         if ((direction_ == VERTICAL) || (direction_ == BOTH))
00163           deleteRows ();
00164         if ((direction_ == HORIZONTAL) || (direction_ == BOTH))
00165           deleteCols ();
00166       }
00167 
00168     private:
00174       void 
00175       expandVertical(const PointT& val);
00181       void 
00182       expandHorizontal(const PointT& val);
00186       void 
00187       expandVerticalDuplicate();
00191       void 
00192       expandHorizontalDuplicate();
00196       void 
00197       expandVerticalMirror();
00201       void 
00202       expandHorizontalMirror();
00204       inline void
00205       deleteRows ();
00207       inline void
00208       deleteCols ();
00209       
00211       int expand_policy_;
00213       int direction_;
00215       int amount_;
00217       PointCloudPtr input_;
00218   };
00219 }
00220 
00221 #include <pcl/common/impl/spring.hpp>
00222 
00223 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines