OctreeGrid.h
Go to the documentation of this file.
00001 // kate: replace-tabs off; indent-width 4; indent-mode normal
00002 // vim: ts=4:sw=4:noexpandtab
00003 /*
00004 
00005 Copyright (c) 2010--2018,
00006 François Pomerleau and Stephane Magnenat, ASL, ETHZ, Switzerland
00007 You can contact the authors at <f dot pomerleau at gmail dot com> and
00008 <stephane at magnenat dot net>
00009 
00010 All rights reserved.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014     * Redistributions of source code must retain the above copyright
00015       notice, this list of conditions and the following disclaimer.
00016     * Redistributions in binary form must reproduce the above copyright
00017       notice, this list of conditions and the following disclaimer in the
00018       documentation and/or other materials provided with the distribution.
00019     * Neither the name of the <organization> nor the
00020       names of its contributors may be used to endorse or promote products
00021       derived from this software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00024 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00025 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00026 DISCLAIMED. IN NO EVENT SHALL ETH-ASL BE LIABLE FOR ANY
00027 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00028 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00030 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00031 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00032 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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         // Type definitions
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                 //FIXME: add seed parameter for the random sampling
00085                 };
00086         }
00087 
00088 public:
00089 //Visitors class to apply processing
00090         struct FirstPtsSampler
00091         {
00092                 std::size_t idx;
00093                 DataPoints&     pts;
00094 
00095                 //Build map of (old index to new index), 
00096                 // in case we sample pts at the begining of the pointcloud
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         //Nearest point from the centroid (contained in the cloud)
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 //Atributes
00156         bool buildParallel;
00157         
00158         std::size_t maxPointByNode;
00159         T           maxSizeByNode;
00160         
00161         SamplingMethod samplingMethod;
00162 
00163 //Methods       
00164         //Constructor, uses parameter interface
00165         OctreeGridDataPointsFilter(const Parameters& params = Parameters());
00166 
00167         OctreeGridDataPointsFilter();
00168         // Destr
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 };


libpointmatcher
Author(s):
autogenerated on Thu Jun 20 2019 19:51:31