random_sample.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2009, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the copyright holder(s) nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  * $Id: extract_indices.h 1370 2011-06-19 01:06:01Z jspricke $
00035  *
00036  */
00037 
00038 #ifndef PCL_FILTERS_RANDOM_SUBSAMPLE_H_
00039 #define PCL_FILTERS_RANDOM_SUBSAMPLE_H_
00040 
00041 #include <pcl/filters/filter_indices.h>
00042 #include <time.h>
00043 #include <limits.h>
00044 
00045 namespace pcl
00046 {
00055   template<typename PointT>
00056   class RandomSample : public FilterIndices<PointT>
00057   {
00058     using FilterIndices<PointT>::filter_name_;
00059     using FilterIndices<PointT>::getClassName;
00060     using FilterIndices<PointT>::indices_;
00061     using FilterIndices<PointT>::input_;
00062     using FilterIndices<PointT>::negative_;
00063     using FilterIndices<PointT>::keep_organized_;
00064     using FilterIndices<PointT>::user_filter_value_;
00065     using FilterIndices<PointT>::extract_removed_indices_;
00066     using FilterIndices<PointT>::removed_indices_;
00067 
00068     typedef typename FilterIndices<PointT>::PointCloud PointCloud;
00069     typedef typename PointCloud::Ptr PointCloudPtr;
00070     typedef typename PointCloud::ConstPtr PointCloudConstPtr;
00071 
00072     public:
00073 
00074       typedef boost::shared_ptr< RandomSample<PointT> > Ptr;
00075       typedef boost::shared_ptr< const RandomSample<PointT> > ConstPtr;
00076 
00078       RandomSample (bool extract_removed_indices = false) : 
00079         FilterIndices<PointT> (extract_removed_indices),
00080         sample_ (UINT_MAX), 
00081         seed_ (static_cast<unsigned int> (time (NULL)))
00082       {
00083         filter_name_ = "RandomSample";
00084       }
00085 
00089       inline void
00090       setSample (unsigned int sample)
00091       {
00092         sample_ = sample;
00093       }
00094 
00097       inline unsigned int
00098       getSample ()
00099       {
00100         return (sample_);
00101       }
00102 
00106       inline void
00107       setSeed (unsigned int seed)
00108       {
00109         seed_ = seed;
00110       }
00111 
00114       inline unsigned int
00115       getSeed ()
00116       {
00117         return (seed_);
00118       }
00119 
00120     protected:
00121 
00123       unsigned int sample_;
00125       unsigned int seed_;
00126 
00130       void
00131       applyFilter (PointCloud &output);
00132 
00136       void
00137       applyFilter (std::vector<int> &indices);
00138 
00142       inline float
00143       unifRand ()
00144       {
00145         return (static_cast<float>(rand () / double (RAND_MAX)));
00146         //return (((214013 * seed_ + 2531011) >> 16) & 0x7FFF);
00147       }
00148   };
00149 
00154   template<>
00155   class PCL_EXPORTS RandomSample<pcl::PCLPointCloud2> : public FilterIndices<pcl::PCLPointCloud2>
00156   {
00157     using FilterIndices<pcl::PCLPointCloud2>::filter_name_;
00158     using FilterIndices<pcl::PCLPointCloud2>::getClassName;
00159 
00160     typedef pcl::PCLPointCloud2 PCLPointCloud2;
00161     typedef PCLPointCloud2::Ptr PCLPointCloud2Ptr;
00162     typedef PCLPointCloud2::ConstPtr PCLPointCloud2ConstPtr;
00163 
00164     public:
00165   
00166       typedef boost::shared_ptr<RandomSample<pcl::PCLPointCloud2> > Ptr;
00167       typedef boost::shared_ptr<const RandomSample<pcl::PCLPointCloud2> > ConstPtr;
00168   
00170       RandomSample () : sample_ (UINT_MAX), seed_ (static_cast<unsigned int> (time (NULL)))
00171       {
00172         filter_name_ = "RandomSample";
00173       }
00174 
00178       inline void
00179       setSample (unsigned int sample)
00180       {
00181         sample_ = sample;
00182       }
00183 
00186       inline unsigned int
00187       getSample ()
00188       {
00189         return (sample_);
00190       }
00191 
00195       inline void
00196       setSeed (unsigned int seed)
00197       {
00198         seed_ = seed;
00199       }
00200 
00203       inline unsigned int
00204       getSeed ()
00205       {
00206         return (seed_);
00207       }
00208 
00209     protected:
00210 
00212       unsigned int sample_;
00214       unsigned int seed_;
00215 
00219       void
00220       applyFilter (PCLPointCloud2 &output);
00221 
00225       void
00226       applyFilter (std::vector<int> &indices);
00227 
00231       inline float
00232       unifRand ()
00233       {
00234         return (static_cast<float> (rand () / double (RAND_MAX)));
00235         //return (((214013 * seed_ + 2531011) >> 16) & 0x7FFF);
00236       }
00237    };
00238 }
00239 
00240 #ifdef PCL_NO_PRECOMPILE
00241 #include <pcl/filters/impl/random_sample.hpp>
00242 #endif
00243 
00244 #endif  //#ifndef PCL_FILTERS_RANDOM_SUBSAMPLE_H_


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:32:00