MatchersImpl.cpp
Go to the documentation of this file.
00001 // kate: replace-tabs off; indent-width 4; indent-mode normal
00002 // vim: ts=4:sw=4:noexpandtab
00003 /*
00004 
00005 Copyright (c) 2010--2012,
00006 François Pomerleau and Stephane Magnenat, ASL, ETHZ, Switzerland
00007 You can contact the authors at <f dot pomerleau at gmail dot com> and
00008 <stephane at magnenat dot net>
00009 
00010 All rights reserved.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014     * Redistributions of source code must retain the above copyright
00015       notice, this list of conditions and the following disclaimer.
00016     * Redistributions in binary form must reproduce the above copyright
00017       notice, this list of conditions and the following disclaimer in the
00018       documentation and/or other materials provided with the distribution.
00019     * Neither the name of the <organization> nor the
00020       names of its contributors may be used to endorse or promote products
00021       derived from this software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00024 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00025 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00026 DISCLAIMED. IN NO EVENT SHALL ETH-ASL BE LIABLE FOR ANY
00027 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00028 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00030 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00031 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00032 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 
00036 #include "MatchersImpl.h"
00037 #include "PointMatcherPrivate.h"
00038 
00039 // NullMatcher
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 // KDTreeMatcher
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         // build and populate NNS
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 // KDTreeVarDistMatcher
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         // build and populate NNS
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;


libpointmatcher
Author(s):
autogenerated on Thu Jun 20 2019 19:51:31