00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "MatchersImpl.h"
00037 #include "PointMatcherPrivate.h"
00038
00039
00040 template<typename T>
00041 void MatchersImpl<T>::NullMatcher::init(
00042 const DataPoints& filteredReference)
00043 {
00044
00045 }
00046
00047 template<typename T>
00048 typename PointMatcher<T>::Matches MatchersImpl<T>::NullMatcher::findClosests(
00049 const DataPoints& filteredReading)
00050 {
00051 return Matches();
00052 }
00053
00054 template struct MatchersImpl<float>::NullMatcher;
00055 template struct MatchersImpl<double>::NullMatcher;
00056
00057
00058
00059
00060 template<typename T>
00061 MatchersImpl<T>::KDTreeMatcher::KDTreeMatcher(const Parameters& params):
00062 Matcher("KDTreeMatcher", KDTreeMatcher::availableParameters(), params),
00063 knn(Parametrizable::get<int>("knn")),
00064 epsilon(Parametrizable::get<T>("epsilon")),
00065 searchType(NNSearchType(Parametrizable::get<int>("searchType"))),
00066 maxDist(Parametrizable::get<T>("maxDist"))
00067 {
00068 LOG_INFO_STREAM("* KDTreeMatcher: initialized with knn=" << knn << ", epsilon=" << epsilon << ", searchType=" << searchType << " and maxDist=" << maxDist);
00069 }
00070
00071 template<typename T>
00072 MatchersImpl<T>::KDTreeMatcher::~KDTreeMatcher()
00073 {
00074
00075 }
00076
00077 template<typename T>
00078 void MatchersImpl<T>::KDTreeMatcher::init(
00079 const DataPoints& filteredReference)
00080 {
00081
00082 featureNNS.reset( NNS::create(filteredReference.features, filteredReference.features.rows() - 1, searchType, NNS::TOUCH_STATISTICS));
00083 }
00084
00085 template<typename T>
00086 typename PointMatcher<T>::Matches MatchersImpl<T>::KDTreeMatcher::findClosests(
00087 const DataPoints& filteredReading)
00088 {
00089
00090 const int pointsCount(filteredReading.features.cols());
00091 Matches matches(
00092 typename Matches::Dists(knn, pointsCount),
00093 typename Matches::Ids(knn, pointsCount)
00094 );
00095
00096 static_assert(NNS::InvalidIndex == Matches::InvalidId, "");
00097 static_assert(NNS::InvalidValue == Matches::InvalidDist, "");
00098 this->visitCounter += featureNNS->knn(filteredReading.features, matches.ids, matches.dists, knn, epsilon, NNS::ALLOW_SELF_MATCH, maxDist);
00099
00100 return matches;
00101 }
00102
00103 template struct MatchersImpl<float>::KDTreeMatcher;
00104 template struct MatchersImpl<double>::KDTreeMatcher;
00105
00106
00107 template<typename T>
00108 MatchersImpl<T>::KDTreeVarDistMatcher::KDTreeVarDistMatcher(const Parameters& params):
00109 Matcher("KDTreeVarDistMatcher", KDTreeVarDistMatcher::availableParameters(), params),
00110 knn(Parametrizable::get<int>("knn")),
00111 epsilon(Parametrizable::get<T>("epsilon")),
00112 searchType(NNSearchType(Parametrizable::get<int>("searchType"))),
00113 maxDistField(Parametrizable::getParamValueString("maxDistField"))
00114 {
00115 LOG_INFO_STREAM("* KDTreeVarDsitMatcher: initialized with knn=" << knn << ", epsilon=" << epsilon << ", searchType=" << searchType << " and maxDistField=" << maxDistField);
00116 }
00117
00118 template<typename T>
00119 MatchersImpl<T>::KDTreeVarDistMatcher::~KDTreeVarDistMatcher()
00120 {
00121
00122 }
00123
00124 template<typename T>
00125 void MatchersImpl<T>::KDTreeVarDistMatcher::init(
00126 const DataPoints& filteredReference)
00127 {
00128
00129 featureNNS.reset( NNS::create(filteredReference.features, filteredReference.features.rows() - 1, searchType, NNS::TOUCH_STATISTICS));
00130 }
00131
00132 template<typename T>
00133 typename PointMatcher<T>::Matches MatchersImpl<T>::KDTreeVarDistMatcher::findClosests(
00134 const DataPoints& filteredReading)
00135 {
00136
00137 const int pointsCount(filteredReading.features.cols());
00138 Matches matches(
00139 typename Matches::Dists(knn, pointsCount),
00140 typename Matches::Ids(knn, pointsCount)
00141 );
00142
00143 const BOOST_AUTO(maxDists, filteredReading.getDescriptorViewByName(maxDistField));
00144
00145 static_assert(NNS::InvalidIndex == Matches::InvalidId, "");
00146 static_assert(NNS::InvalidValue == Matches::InvalidDist, "");
00147 this->visitCounter += featureNNS->knn(filteredReading.features, matches.ids, matches.dists, maxDists.transpose(), knn, epsilon, NNS::ALLOW_SELF_MATCH);
00148
00149 return matches;
00150 }
00151
00152 template struct MatchersImpl<float>::KDTreeVarDistMatcher;
00153 template struct MatchersImpl<double>::KDTreeVarDistMatcher;