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         this->visitCounter += featureNNS->knn(filteredReading.features, matches.ids, matches.dists, knn, epsilon, NNS::ALLOW_SELF_MATCH, maxDist);
00097 
00098         return matches;
00099 }
00100 
00101 template struct MatchersImpl<float>::KDTreeMatcher;
00102 template struct MatchersImpl<double>::KDTreeMatcher;
00103 
00104 // KDTreeVarDistMatcher
00105 template<typename T>
00106 MatchersImpl<T>::KDTreeVarDistMatcher::KDTreeVarDistMatcher(const Parameters& params):
00107         Matcher("KDTreeVarDistMatcher", KDTreeVarDistMatcher::availableParameters(), params),
00108         knn(Parametrizable::get<int>("knn")),
00109         epsilon(Parametrizable::get<T>("epsilon")),
00110         searchType(NNSearchType(Parametrizable::get<int>("searchType"))),
00111         maxDistField(Parametrizable::getParamValueString("maxDistField"))
00112 {
00113         LOG_INFO_STREAM("* KDTreeVarDsitMatcher: initialized with knn=" << knn << ", epsilon=" << epsilon << ", searchType=" << searchType << " and maxDistField=" << maxDistField);
00114 }
00115 
00116 template<typename T>
00117 MatchersImpl<T>::KDTreeVarDistMatcher::~KDTreeVarDistMatcher()
00118 {
00119 
00120 }
00121 
00122 template<typename T>
00123 void MatchersImpl<T>::KDTreeVarDistMatcher::init(
00124         const DataPoints& filteredReference)
00125 {
00126         // build and populate NNS
00127         featureNNS.reset( NNS::create(filteredReference.features, filteredReference.features.rows() - 1, searchType, NNS::TOUCH_STATISTICS));
00128 }
00129 
00130 template<typename T>
00131 typename PointMatcher<T>::Matches MatchersImpl<T>::KDTreeVarDistMatcher::findClosests(
00132         const DataPoints& filteredReading)
00133 {
00134         
00135         const int pointsCount(filteredReading.features.cols());
00136         Matches matches(
00137                 typename Matches::Dists(knn, pointsCount),
00138                 typename Matches::Ids(knn, pointsCount)
00139         );
00140         
00141         const BOOST_AUTO(maxDists, filteredReading.getDescriptorViewByName(maxDistField));
00142         
00143         this->visitCounter += featureNNS->knn(filteredReading.features, matches.ids, matches.dists, maxDists.transpose(), knn, epsilon, NNS::ALLOW_SELF_MATCH);
00144 
00145         return matches;
00146 }
00147 
00148 template struct MatchersImpl<float>::KDTreeVarDistMatcher;
00149 template struct MatchersImpl<double>::KDTreeVarDistMatcher;


upstream_src
Author(s):
autogenerated on Mon Oct 6 2014 10:27:42