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;
94 
95  //Build map of (old index to new index),
96  // in case we sample pts at the beginning of the point cloud
97  std::unordered_map<std::size_t, std::size_t> mapidx;
98 
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 
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 
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 
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
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 };
OctreeGridDataPointsFilter::buildParallel
bool buildParallel
Definition: OctreeGrid.h:156
OctreeGridDataPointsFilter::MedoidSampler
Definition: OctreeGrid.h:138
OctreeGridDataPointsFilter::DataPoints
PM::DataPoints DataPoints
Definition: OctreeGrid.h:58
OctreeGridDataPointsFilter::CentroidSampler
Definition: OctreeGrid.h:124
OctreeGridDataPointsFilter::maxPointByNode
std::size_t maxPointByNode
Definition: OctreeGrid.h:158
OctreeGridDataPointsFilter::FirstPtsSampler::idx
std::size_t idx
Definition: OctreeGrid.h:92
OctreeGridDataPointsFilter::FirstPtsSampler::FirstPtsSampler
FirstPtsSampler(DataPoints &dp)
Definition: OctreeGrid.cpp:41
OctreeGridDataPointsFilter::Parametrizable
PointMatcherSupport::Parametrizable Parametrizable
Definition: OctreeGrid.h:61
OctreeGridDataPointsFilter::InvalidField
PointMatcher< T >::DataPoints::InvalidField InvalidField
Definition: OctreeGrid.h:70
OctreeGridDataPointsFilter::samplingMethod
SamplingMethod samplingMethod
Definition: OctreeGrid.h:161
OctreeGridDataPointsFilter::FirstPtsSampler::finalize
virtual bool finalize()
Definition: OctreeGrid.cpp:75
OctreeGridDataPointsFilter::MEDOID
@ MEDOID
Definition: OctreeGrid.h:153
OctreeGridDataPointsFilter::RandomPtsSampler::seed
const std::size_t seed
Definition: OctreeGrid.h:113
build_map.T
T
Definition: build_map.py:34
OctreeGridDataPointsFilter::RandomPtsSampler::RandomPtsSampler
RandomPtsSampler(DataPoints &dp)
Definition: OctreeGrid.cpp:86
OctreeGridDataPointsFilter::DataPointsFilter
PM::DataPointsFilter DataPointsFilter
Definition: OctreeGrid.h:59
OctreeGridDataPointsFilter::RandomPtsSampler::operator()
bool operator()(Octree_< T, dim > &oc)
Definition: OctreeGrid.cpp:100
PointMatcher
Functions and classes that are dependant on scalar type are defined in this templatized class.
Definition: PointMatcher.h:130
OctreeGridDataPointsFilter::CentroidSampler::CentroidSampler
CentroidSampler(DataPoints &dp)
Definition: OctreeGrid.cpp:141
PointMatcher::DataPoints
A point cloud.
Definition: PointMatcher.h:207
OctreeGridDataPointsFilter::MedoidSampler::~MedoidSampler
virtual ~MedoidSampler()
Definition: OctreeGrid.h:146
OctreeGridDataPointsFilter::OctreeGridDataPointsFilter
OctreeGridDataPointsFilter()
OctreeGridDataPointsFilter::RAND_PTS
@ RAND_PTS
Definition: OctreeGrid.h:153
OctreeGridDataPointsFilter::MedoidSampler::operator()
bool operator()(Octree_< T, dim > &oc)
Definition: OctreeGrid.cpp:222
testing::internal::string
::std::string string
Definition: gtest.h:1979
OctreeGridDataPointsFilter::ParametersDoc
Parametrizable::ParametersDoc ParametersDoc
Definition: OctreeGrid.h:65
PointMatcher::DataPoints::InvalidField
An exception thrown when one tries to access features or descriptors unexisting or of wrong dimension...
Definition: PointMatcher.h:250
OctreeGridDataPointsFilter::ParameterDoc
Parametrizable::ParameterDoc ParameterDoc
Definition: OctreeGrid.h:64
OctreeGridDataPointsFilter::CENTROID
@ CENTROID
Definition: OctreeGrid.h:153
OctreeGridDataPointsFilter::CentroidSampler::operator()
bool operator()(Octree_< T, dim > &oc)
Definition: OctreeGrid.cpp:148
OctreeGridDataPointsFilter
Data Filter based on Octree representation.
Definition: OctreeGrid.h:54
OctreeGridDataPointsFilter::RandomPtsSampler::finalize
virtual bool finalize()
Definition: OctreeGrid.cpp:131
PointMatcherSupport::Parametrizable::ParametersDoc
std::vector< ParameterDoc > ParametersDoc
The documentation of all parameters.
Definition: Parametrizable.h:187
align_sequence.params
params
Definition: align_sequence.py:13
OctreeGridDataPointsFilter::SamplingMethod
SamplingMethod
Definition: OctreeGrid.h:153
OctreeGridDataPointsFilter::FirstPtsSampler::operator()
bool operator()(Octree_< T, dim > &oc)
Definition: OctreeGrid.cpp:48
OctreeGridDataPointsFilter::FirstPtsSampler::pts
DataPoints & pts
Definition: OctreeGrid.h:93
OctreeGridDataPointsFilter::FirstPtsSampler::mapidx
std::unordered_map< std::size_t, std::size_t > mapidx
Definition: OctreeGrid.h:97
PointMatcher::DataPointsFilter
A data filter takes a point cloud as input, transforms it, and produces another point cloud as output...
Definition: PointMatcher.h:440
OctreeGridDataPointsFilter::availableParameters
static const ParametersDoc availableParameters()
Definition: OctreeGrid.h:77
PointMatcherSupport::Parametrizable::InvalidParameter
An exception thrown when one tries to fetch the value of an unexisting parameter.
Definition: Parametrizable.h:144
OctreeGridDataPointsFilter::FIRST_PTS
@ FIRST_PTS
Definition: OctreeGrid.h:153
OctreeGridDataPointsFilter::sample
void sample(DataPoints &cloud)
Definition: OctreeGrid.cpp:333
PointMatcher::DataPoints::Index
Matrix::Index Index
An index to a row or a column.
Definition: PointMatcher.h:218
OctreeGridDataPointsFilter::FirstPtsSampler
Definition: OctreeGrid.h:90
OctreeGridDataPointsFilter::InvalidParameter
Parametrizable::InvalidParameter InvalidParameter
Definition: OctreeGrid.h:66
OctreeGridDataPointsFilter::RandomPtsSampler::~RandomPtsSampler
virtual ~RandomPtsSampler()
Definition: OctreeGrid.h:117
PointMatcherSupport::Parametrizable
The superclass of classes that are constructed using generic parameters. This class provides the para...
Definition: Parametrizable.h:141
OctreeGridDataPointsFilter::Index
DataPoints::Index Index
Definition: OctreeGrid.h:68
OctreeGridDataPointsFilter::Parameters
Parametrizable::Parameters Parameters
Definition: OctreeGrid.h:63
OctreeGridDataPointsFilter::RandomPtsSampler
Definition: OctreeGrid.h:107
PointMatcherSupport::Parametrizable::ParameterDoc
The documentation of a parameter.
Definition: Parametrizable.h:160
Octree_
Definition: octree.h:78
OctreeGridDataPointsFilter::P
PointMatcherSupport::Parametrizable P
Definition: OctreeGrid.h:62
OctreeGridDataPointsFilter::maxSizeByNode
T maxSizeByNode
Definition: OctreeGrid.h:159
OctreeGridDataPointsFilter::~OctreeGridDataPointsFilter
virtual ~OctreeGridDataPointsFilter()
Definition: OctreeGrid.h:169
OctreeGridDataPointsFilter::CentroidSampler::~CentroidSampler
virtual ~CentroidSampler()
Definition: OctreeGrid.h:132
OctreeGridDataPointsFilter::FirstPtsSampler::~FirstPtsSampler
virtual ~FirstPtsSampler()
Definition: OctreeGrid.h:100
OctreeGridDataPointsFilter::inPlaceFilter
virtual void inPlaceFilter(DataPoints &cloud)
Apply these filters to a point cloud without copying.
Definition: OctreeGrid.cpp:318
PointMatcher.h
public interface
octree.h
OctreeGridDataPointsFilter::filter
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:310
OctreeGridDataPointsFilter::description
static const std::string description()
Definition: OctreeGrid.h:72
OctreeGridDataPointsFilter::PM
PointMatcher< T > PM
Definition: OctreeGrid.h:57
PointMatcherSupport::Parametrizable::Parameters
std::map< std::string, Parameter > Parameters
Parameters stored as a map of string->string.
Definition: Parametrizable.h:199
OctreeGridDataPointsFilter::MedoidSampler::MedoidSampler
MedoidSampler(DataPoints &dp)
Definition: OctreeGrid.cpp:215


libpointmatcher
Author(s):
autogenerated on Mon Jan 1 2024 03:24:43