random_sample.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
00063 typedef typename FilterIndices<PointT>::PointCloud PointCloud;
00064 typedef typename PointCloud::Ptr PointCloudPtr;
00065 typedef typename PointCloud::ConstPtr PointCloudConstPtr;
00066
00067 public:
00069 RandomSample () : sample_ (UINT_MAX), seed_ (static_cast<unsigned int> (time (NULL)))
00070 {
00071 filter_name_ = "RandomSample";
00072 }
00073
00077 inline void
00078 setSample (unsigned int sample)
00079 {
00080 sample_ = sample;
00081 }
00082
00085 inline unsigned int
00086 getSample ()
00087 {
00088 return (sample_);
00089 }
00090
00094 inline void
00095 setSeed (unsigned int seed)
00096 {
00097 seed_ = seed;
00098 }
00099
00102 inline unsigned int
00103 getSeed ()
00104 {
00105 return (seed_);
00106 }
00107
00108 protected:
00109
00111 unsigned int sample_;
00113 unsigned int seed_;
00114
00118 void
00119 applyFilter (PointCloud &output);
00120
00124 void
00125 applyFilter (std::vector<int> &indices);
00126
00130 inline float
00131 unifRand ()
00132 {
00133 return (static_cast<float>(rand () / double (RAND_MAX)));
00134
00135 }
00136 };
00137
00142 template<>
00143 class PCL_EXPORTS RandomSample<sensor_msgs::PointCloud2> : public FilterIndices<sensor_msgs::PointCloud2>
00144 {
00145 using FilterIndices<sensor_msgs::PointCloud2>::filter_name_;
00146 using FilterIndices<sensor_msgs::PointCloud2>::getClassName;
00147
00148 typedef sensor_msgs::PointCloud2 PointCloud2;
00149 typedef PointCloud2::Ptr PointCloud2Ptr;
00150 typedef PointCloud2::ConstPtr PointCloud2ConstPtr;
00151
00152 public:
00154 RandomSample () : sample_ (UINT_MAX), seed_ (static_cast<unsigned int> (time (NULL)))
00155 {
00156 filter_name_ = "RandomSample";
00157 }
00158
00162 inline void
00163 setSample (unsigned int sample)
00164 {
00165 sample_ = sample;
00166 }
00167
00170 inline unsigned int
00171 getSample ()
00172 {
00173 return (sample_);
00174 }
00175
00179 inline void
00180 setSeed (unsigned int seed)
00181 {
00182 seed_ = seed;
00183 }
00184
00187 inline unsigned int
00188 getSeed ()
00189 {
00190 return (seed_);
00191 }
00192
00193 protected:
00194
00196 unsigned int sample_;
00198 unsigned int seed_;
00199
00203 void
00204 applyFilter (PointCloud2 &output);
00205
00209 void
00210 applyFilter (std::vector<int> &indices);
00211
00215 inline float
00216 unifRand ()
00217 {
00218 return (static_cast<float> (rand () / double (RAND_MAX)));
00219
00220 }
00221 };
00222 }
00223
00224 #endif //#ifndef PCL_FILTERS_RANDOM_SUBSAMPLE_H_