MatchersImpl.cpp
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--2012,
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 
36 #include "MatchersImpl.h"
37 #include "PointMatcherPrivate.h"
38 
39 // NullMatcher
40 template<typename T>
42  const DataPoints& filteredReference)
43 {
44 
45 }
46 
47 template<typename T>
49  const DataPoints& filteredReading)
50 {
51  return Matches();
52 }
53 
54 template struct MatchersImpl<float>::NullMatcher;
55 template struct MatchersImpl<double>::NullMatcher;
56 
57 
58 
59 // KDTreeMatcher
60 template<typename T>
62  Matcher("KDTreeMatcher", KDTreeMatcher::availableParameters(), params),
63  knn(Parametrizable::get<int>("knn")),
64  epsilon(Parametrizable::get<T>("epsilon")),
65  searchType(NNSearchType(Parametrizable::get<int>("searchType"))),
66  maxDist(Parametrizable::get<T>("maxDist"))
67 {
68  LOG_INFO_STREAM("* KDTreeMatcher: initialized with knn=" << knn << ", epsilon=" << epsilon << ", searchType=" << searchType << " and maxDist=" << maxDist);
69 }
70 
71 template<typename T>
73 {
74 
75 }
76 
77 template<typename T>
79  const DataPoints& filteredReference)
80 {
81  // build and populate NNS
82  featureNNS.reset( NNS::create(filteredReference.features, filteredReference.features.rows() - 1, searchType, NNS::TOUCH_STATISTICS));
83 }
84 
85 template<typename T>
87  const DataPoints& filteredReading)
88 {
89 
90  const int pointsCount(filteredReading.features.cols());
92  typename Matches::Dists(knn, pointsCount),
93  typename Matches::Ids(knn, pointsCount)
94  );
95 
96  static_assert(NNS::InvalidIndex == Matches::InvalidId, "");
97  static_assert(NNS::InvalidValue == Matches::InvalidDist, "");
98  this->visitCounter += featureNNS->knn(filteredReading.features, matches.ids, matches.dists, knn, epsilon, NNS::ALLOW_SELF_MATCH, maxDist);
99 
100  return matches;
101 }
102 
103 template struct MatchersImpl<float>::KDTreeMatcher;
105 
106 // KDTreeVarDistMatcher
107 template<typename T>
109  Matcher("KDTreeVarDistMatcher", KDTreeVarDistMatcher::availableParameters(), params),
110  knn(Parametrizable::get<int>("knn")),
111  epsilon(Parametrizable::get<T>("epsilon")),
112  searchType(NNSearchType(Parametrizable::get<int>("searchType"))),
113  maxDistField(Parametrizable::getParamValueString("maxDistField"))
114 {
115  LOG_INFO_STREAM("* KDTreeVarDsitMatcher: initialized with knn=" << knn << ", epsilon=" << epsilon << ", searchType=" << searchType << " and maxDistField=" << maxDistField);
116 }
117 
118 template<typename T>
120 {
121 
122 }
123 
124 template<typename T>
126  const DataPoints& filteredReference)
127 {
128  // build and populate NNS
129  featureNNS.reset( NNS::create(filteredReference.features, filteredReference.features.rows() - 1, searchType, NNS::TOUCH_STATISTICS));
130 }
131 
132 template<typename T>
134  const DataPoints& filteredReading)
135 {
136 
137  const int pointsCount(filteredReading.features.cols());
139  typename Matches::Dists(knn, pointsCount),
140  typename Matches::Ids(knn, pointsCount)
141  );
142 
143  const BOOST_AUTO(maxDists, filteredReading.getDescriptorViewByName(maxDistField));
144 
145  static_assert(NNS::InvalidIndex == Matches::InvalidId, "");
146  static_assert(NNS::InvalidValue == Matches::InvalidDist, "");
147  this->visitCounter += featureNNS->knn(filteredReading.features, matches.ids, matches.dists, maxDists.transpose(), knn, epsilon, NNS::ALLOW_SELF_MATCH);
148 
149  return matches;
150 }
151 
A matcher links points in the reading to points in the reference.
Definition: PointMatcher.h:473
#define LOG_INFO_STREAM(args)
static NearestNeighbourSearch * create(const CloudType &cloud, const Index dim=std::numeric_limits< Index >::max(), const SearchType preferedType=KDTREE_LINEAR_HEAP, const unsigned creationOptionFlags=0, const Parameters &additionalParameters=Parameters())
static constexpr T InvalidDist
In case of too few matches the ids are filled with InvalidId.
Definition: PointMatcher.h:378
virtual Matches findClosests(const DataPoints &filteredReading)
Find the closest neighbors of filteredReading in filteredReference passed to init() ...
ConstView getDescriptorViewByName(const std::string &name) const
Get a const view on a descriptor by name, throw an exception if it does not exist.
static const ParametersDoc availableParameters()
Definition: MatchersImpl.h:80
std::shared_ptr< NNS > featureNNS
Definition: MatchersImpl.h:127
std::shared_ptr< NNS > featureNNS
Definition: MatchersImpl.h:96
Matrix Dists
Squared distances to closest points, dense matrix of ScalarType.
Definition: PointMatcher.h:373
unsigned long visitCounter
number of points visited
Definition: PointMatcher.h:475
virtual void init(const DataPoints &filteredReference)
Init this matcher to find nearest neighbor in filteredReference.
std::map< std::string, Parameter > Parameters
Parameters stored as a map of string->string.
const NNSearchType searchType
Definition: MatchersImpl.h:92
virtual void init(const DataPoints &filteredReference)
Init this matcher to find nearest neighbor in filteredReference.
Result of the data-association step (Matcher::findClosests), before outlier rejection.
Definition: PointMatcher.h:371
virtual Matches findClosests(const DataPoints &filteredReading)
Find the closest neighbors of filteredReading in filteredReference passed to init() ...
static constexpr Index InvalidIndex
PointMatcher< T >::Matches Matches
Definition: MatchersImpl.h:60
KDTreeMatcher(const Parameters &params=Parameters())
The superclass of classes that are constructed using generic parameters. This class provides the para...
std::string getParamValueString(const std::string &paramName)
Get the value of a parameter, as a string.
virtual Matches findClosests(const DataPoints &filteredReading)
Find the closest neighbors of filteredReading in filteredReference passed to init() ...
KDTreeVarDistMatcher(const Parameters &params=Parameters())
IntMatrix Ids
Identifiers of closest points, dense matrix of integers.
Definition: PointMatcher.h:374
S get(const std::string &paramName)
Return the value of paramName, lexically-casted to S.
virtual void init(const DataPoints &filteredReference)
Init this matcher to find nearest neighbor in filteredReference.
static constexpr T InvalidValue
Matrix features
features of points in the cloud
Definition: PointMatcher.h:331
static constexpr int InvalidId
Definition: PointMatcher.h:377


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