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 #pragma once
00036
00037 #include "PointMatcher.h"
00038 #include "utils/octree.h"
00039
00040 #include <unordered_map>
00041
00053 template<typename T>
00054 struct OctreeGridDataPointsFilter : public PointMatcher<T>::DataPointsFilter
00055 {
00056
00057 typedef PointMatcher<T> PM;
00058 typedef typename PM::DataPoints DataPoints;
00059 typedef typename PM::DataPointsFilter DataPointsFilter;
00060
00061 typedef PointMatcherSupport::Parametrizable Parametrizable;
00062 typedef PointMatcherSupport::Parametrizable P;
00063 typedef Parametrizable::Parameters Parameters;
00064 typedef Parametrizable::ParameterDoc ParameterDoc;
00065 typedef Parametrizable::ParametersDoc ParametersDoc;
00066 typedef Parametrizable::InvalidParameter InvalidParameter;
00067
00068 typedef typename DataPoints::Index Index;
00069
00070 typedef typename PointMatcher<T>::DataPoints::InvalidField InvalidField;
00071
00072 inline static const std::string description()
00073 {
00074 return "Construct an Octree grid representation of the point cloud. Constructed either by limiting the number of point in each octant or by limiting the size of the bounding box. Down-sample by taking either the first or a random point, or compute the centroid.";
00075 }
00076
00077 inline static const ParametersDoc availableParameters()
00078 {
00079 return {
00080 {"buildParallel", "If 1 (true), use threads to build the octree.", "1", "0", "1", P::Comp<bool>},
00081 {"maxPointByNode", "Number of point under which the octree stop dividing.", "1", "1", "4294967295", &P::Comp<std::size_t>},
00082 {"maxSizeByNode", "Size of the bounding box under which the octree stop dividing.", "0", "0", "+inf", &P::Comp<T>},
00083 {"samplingMethod", "Method to sample the Octree: First Point (0), Random (1), Centroid (2) (more accurate but costly), Medoid (3) (more accurate but costly)", "0", "0", "3", &P::Comp<int>}
00084
00085 };
00086 }
00087
00088 public:
00089
00090 struct FirstPtsSampler
00091 {
00092 std::size_t idx;
00093 DataPoints& pts;
00094
00095
00096
00097 std::unordered_map<std::size_t, std::size_t> mapidx;
00098
00099 FirstPtsSampler(DataPoints& dp);
00100 virtual ~FirstPtsSampler(){}
00101
00102 template<std::size_t dim>
00103 bool operator()(Octree_<T,dim>& oc);
00104
00105 virtual bool finalize();
00106 };
00107 struct RandomPtsSampler : public FirstPtsSampler
00108 {
00109 using FirstPtsSampler::idx;
00110 using FirstPtsSampler::pts;
00111 using FirstPtsSampler::mapidx;
00112
00113 const std::size_t seed;
00114
00115 RandomPtsSampler(DataPoints& dp);
00116 RandomPtsSampler(DataPoints& dp, const std::size_t seed_);
00117 virtual ~RandomPtsSampler(){}
00118
00119 template<std::size_t dim>
00120 bool operator()(Octree_<T,dim>& oc);
00121
00122 virtual bool finalize();
00123 };
00124 struct CentroidSampler : public FirstPtsSampler
00125 {
00126 using FirstPtsSampler::idx;
00127 using FirstPtsSampler::pts;
00128 using FirstPtsSampler::mapidx;
00129
00130 CentroidSampler(DataPoints& dp);
00131
00132 virtual ~CentroidSampler(){}
00133
00134 template<std::size_t dim>
00135 bool operator()(Octree_<T,dim>& oc);
00136 };
00137
00138 struct MedoidSampler : public FirstPtsSampler
00139 {
00140 using FirstPtsSampler::idx;
00141 using FirstPtsSampler::pts;
00142 using FirstPtsSampler::mapidx;
00143
00144 MedoidSampler(DataPoints& dp);
00145
00146 virtual ~MedoidSampler(){}
00147
00148 template<std::size_t dim>
00149 bool operator()(Octree_<T,dim>& oc);
00150 };
00151
00152
00153 enum SamplingMethod : int { FIRST_PTS=0, RAND_PTS=1, CENTROID=2, MEDOID=3 };
00154
00155
00156 bool buildParallel;
00157
00158 std::size_t maxPointByNode;
00159 T maxSizeByNode;
00160
00161 SamplingMethod samplingMethod;
00162
00163
00164
00165 OctreeGridDataPointsFilter(const Parameters& params = Parameters());
00166
00167 OctreeGridDataPointsFilter();
00168
00169 virtual ~OctreeGridDataPointsFilter() {};
00170
00171 virtual DataPoints filter(const DataPoints& input);
00172 virtual void inPlaceFilter(DataPoints& cloud);
00173
00174 private:
00175 template<std::size_t dim> void sample(DataPoints& cloud);
00176 };