Matches.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 "PointMatcher.h"
37 #include "PointMatcherPrivate.h"
38 
39 using namespace std;
40 
42 template<typename T>
44 
46 template<typename T>
47 PointMatcher<T>::Matches::Matches(const Dists& dists, const Ids ids):
48  dists(dists),
49  ids(ids)
50 {}
51 
53 template<typename T>
54 PointMatcher<T>::Matches::Matches(const int knn, const int pointsCount):
55  dists(Dists(knn, pointsCount)),
56  ids(Ids(knn, pointsCount))
57 {}
58 
60 template<typename T>
62 {
63  // build array
64  vector<T> values;
65  values.reserve(dists.rows() * dists.cols());
66  for (int x = 0; x < dists.cols(); ++x)
67  {
68  for (int y = 0; y < dists.rows(); ++y)
69  {
70  if (dists(y, x) != numeric_limits<T>::infinity())
71  {
72  values.push_back(dists(y, x));
73  }
74  }
75  }
76  if (values.size() == 0)
77  throw ConvergenceError("no outlier to filter");
78 
79  if (quantile < 0.0 || quantile > 1.0)
80  throw ConvergenceError("quantile must be between 0 and 1");
81 
82  // get quantile
83  if (quantile == 1.0)
84  return *max_element(values.begin(), values.end());
85  nth_element(values.begin(), values.begin() + (values.size() * quantile), values.end());
86  return values[values.size() * quantile];
87 }
88 
90 template<typename T>
92 {
93  vector<T> values;
94  values.reserve(dists.rows() * dists.cols());
95  const long cols = dists.cols();
96  const long rows = dists.rows();
97  for (int x = 0; x < cols; ++x)
98  {
99  for (int y = 0; y < rows; ++y)
100  {
101  if (dists(y, x) != numeric_limits<T>::infinity())
102  {
103  values.push_back(dists(y, x));
104  }
105  }
106  }
107  if (values.size() == 0)
108  throw ConvergenceError("no outlier to filter");
109 
110  nth_element(values.begin(), values.begin() + (values.size() / 2), values.end());
111  const T median = values[values.size() / 2];
112 
113  // Compute absolute deviation
114  const unsigned size = values.size();
115  for (unsigned i = 0; i < size; ++i)
116  {
117  values[i] = fabs(values[i] - median);
118  }
119  // Median of the absolute deviation
120  nth_element(values.begin(), values.begin() + (values.size() / 2), values.end());
121  return values[values.size() / 2];
122 }
123 
124 template<typename T>
126 {
127  auto d = dists.array();
128  return std::sqrt((d - d.mean()).square().sum()/(d.size()-1));
129 }
130 
131 
132 template struct PointMatcher<float>::Matches;
133 template struct PointMatcher<double>::Matches;
PointMatcher::Matches::Dists
Matrix Dists
Squared distances to closest points, dense matrix of ScalarType.
Definition: PointMatcher.h:373
PointMatcher::Matches::getMedianAbsDeviation
T getMedianAbsDeviation() const
Calculate the Median of Absolute Deviation(MAD), which is median(|x-median(x)|), a kind of robust sta...
Definition: Matches.cpp:91
PointMatcher
Functions and classes that are dependant on scalar type are defined in this templatized class.
Definition: PointMatcher.h:130
PointMatcherPrivate.h
PointMatcher::ConvergenceError
Point matcher did not converge.
Definition: PointMatcher.h:148
test.x
x
Definition: test.py:4
PointMatcher::Matches::Matches
Matches()
In case of too few matches the dists are filled with InvalidDist.
Definition: Matches.cpp:43
d
d
PointMatcher::Matches::Ids
IntMatrix Ids
Identifiers of closest points, dense matrix of integers.
Definition: PointMatcher.h:374
PointMatcher::Matches
Result of the data-association step (Matcher::findClosests), before outlier rejection.
Definition: PointMatcher.h:371
values
std::vector< double > values
std
PointMatcher::Matches::getStandardDeviation
T getStandardDeviation() const
Definition: Matches.cpp:125
PointMatcher::Matches::getDistsQuantile
T getDistsQuantile(const T quantile) const
Get the distance at the T-ratio closest point.
Definition: Matches.cpp:61
PointMatcher.h
public interface


mp2p_icp
Author(s):
autogenerated on Fri Dec 20 2024 03:45:59