OctreeGrid.h
Go to the documentation of this file.
1 // kate: replace-tabs off; indent-width 4; indent-mode normal
2 // vim: ts=4:sw=4:noexpandtab
3 /*
4 
5 Copyright (c) 2010--2018,
6 François Pomerleau and Stephane Magnenat, ASL, ETHZ, Switzerland
7 You can contact the authors at <f dot pomerleau at gmail dot com> and
8 <stephane at magnenat dot net>
9 
10 All rights reserved.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright
15  notice, this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright
17  notice, this list of conditions and the following disclaimer in the
18  documentation and/or other materials provided with the distribution.
19  * Neither the name of the <organization> nor the
20  names of its contributors may be used to endorse or promote products
21  derived from this software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 DISCLAIMED. IN NO EVENT SHALL ETH-ASL BE LIABLE FOR ANY
27 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 #pragma once
36 
37 #include "PointMatcher.h"
38 #include "utils/octree.h"
39 
40 #include <unordered_map>
41 
53 template<typename T>
55 {
56  // Type definitions
58  typedef typename PM::DataPoints DataPoints;
60 
67 
68  typedef typename DataPoints::Index Index;
69 
71 
72  inline static const std::string description()
73  {
74  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.";
75  }
76 
77  inline static const ParametersDoc availableParameters()
78  {
79  return {
80  {"buildParallel", "If 1 (true), use threads to build the octree.", "1", "0", "1", P::Comp<bool>},
81  {"maxPointByNode", "Number of point under which the octree stop dividing.", "1", "1", "4294967295", &P::Comp<std::size_t>},
82  {"maxSizeByNode", "Size of the bounding box under which the octree stop dividing.", "0", "0", "+inf", &P::Comp<T>},
83  {"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>}
84  //FIXME: add seed parameter for the random sampling
85  };
86  }
87 
88 public:
89 //Visitors class to apply processing
91  {
92  std::size_t idx;
93  DataPoints& pts;
94 
95  //Build map of (old index to new index),
96  // in case we sample pts at the begining of the pointcloud
97  std::unordered_map<std::size_t, std::size_t> mapidx;
98 
99  FirstPtsSampler(DataPoints& dp);
100  virtual ~FirstPtsSampler(){}
101 
102  template<std::size_t dim>
103  bool operator()(Octree_<T,dim>& oc);
104 
105  virtual bool finalize();
106  };
108  {
109  using FirstPtsSampler::idx;
110  using FirstPtsSampler::pts;
112 
113  const std::size_t seed;
114 
115  RandomPtsSampler(DataPoints& dp);
116  RandomPtsSampler(DataPoints& dp, const std::size_t seed_);
117  virtual ~RandomPtsSampler(){}
118 
119  template<std::size_t dim>
120  bool operator()(Octree_<T,dim>& oc);
121 
122  virtual bool finalize();
123  };
125  {
126  using FirstPtsSampler::idx;
127  using FirstPtsSampler::pts;
129 
130  CentroidSampler(DataPoints& dp);
131 
132  virtual ~CentroidSampler(){}
133 
134  template<std::size_t dim>
135  bool operator()(Octree_<T,dim>& oc);
136  };
137  //Nearest point from the centroid (contained in the cloud)
139  {
140  using FirstPtsSampler::idx;
141  using FirstPtsSampler::pts;
143 
144  MedoidSampler(DataPoints& dp);
145 
146  virtual ~MedoidSampler(){}
147 
148  template<std::size_t dim>
149  bool operator()(Octree_<T,dim>& oc);
150  };
151 
152 //-------
153  enum SamplingMethod : int { FIRST_PTS=0, RAND_PTS=1, CENTROID=2, MEDOID=3 };
154 
155 //Atributes
157 
158  std::size_t maxPointByNode;
160 
162 
163 //Methods
164  //Constructor, uses parameter interface
165  OctreeGridDataPointsFilter(const Parameters& params = Parameters());
166 
168  // Destr
170 
171  virtual DataPoints filter(const DataPoints& input);
172  virtual void inPlaceFilter(DataPoints& cloud);
173 
174 private:
175  template<std::size_t dim> void sample(DataPoints& cloud);
176 };
PointMatcherSupport::Parametrizable P
Definition: OctreeGrid.h:62
DataPoints::Index Index
Definition: OctreeGrid.h:68
PointMatcherSupport::Parametrizable Parametrizable
Definition: OctreeGrid.h:61
public interface
Parametrizable::ParametersDoc ParametersDoc
Definition: OctreeGrid.h:65
virtual ~OctreeGridDataPointsFilter()
Definition: OctreeGrid.h:169
Matrix::Index Index
An index to a row or a column.
Definition: PointMatcher.h:218
::std::string string
Definition: gtest.h:1979
Parametrizable::ParameterDoc ParameterDoc
Definition: OctreeGrid.h:64
SamplingMethod samplingMethod
Definition: OctreeGrid.h:161
Definition: octree.h:78
virtual DataPoints filter(const DataPoints &input)
Apply filters to input point cloud. This is the non-destructive version and returns a copy...
Definition: OctreeGrid.cpp:306
PointMatcher< T >::DataPoints::InvalidField InvalidField
Definition: OctreeGrid.h:70
static const ParametersDoc availableParameters()
Definition: OctreeGrid.h:77
std::map< std::string, Parameter > Parameters
Parameters stored as a map of string->string.
PointMatcher< T > PM
Definition: OctreeGrid.h:57
Functions and classes that are dependant on scalar type are defined in this templatized class...
Definition: PointMatcher.h:130
static const std::string description()
Definition: OctreeGrid.h:72
A data filter takes a point cloud as input, transforms it, and produces another point cloud as output...
Definition: PointMatcher.h:440
Parametrizable::Parameters Parameters
Definition: OctreeGrid.h:63
PM::DataPoints DataPoints
Definition: OctreeGrid.h:58
The documentation of a parameter.
Data Filter based on Octree representation.
Definition: OctreeGrid.h:54
Parametrizable::InvalidParameter InvalidParameter
Definition: OctreeGrid.h:66
The superclass of classes that are constructed using generic parameters. This class provides the para...
An exception thrown when one tries to fetch the value of an unexisting parameter. ...
std::vector< ParameterDoc > ParametersDoc
The documentation of all parameters.
virtual void inPlaceFilter(DataPoints &cloud)
Apply these filters to a point cloud without copying.
Definition: OctreeGrid.cpp:314
An exception thrown when one tries to access features or descriptors unexisting or of wrong dimension...
Definition: PointMatcher.h:250
bool operator()(Octree_< T, dim > &oc)
Definition: OctreeGrid.cpp:48
std::unordered_map< std::size_t, std::size_t > mapidx
Definition: OctreeGrid.h:97
void sample(DataPoints &cloud)
Definition: OctreeGrid.cpp:329
PM::DataPointsFilter DataPointsFilter
Definition: OctreeGrid.h:59


libpointmatcher
Author(s):
autogenerated on Sat May 27 2023 02:38:02