OKVIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MatchingAlgorithm.hpp
Go to the documentation of this file.
1 /*********************************************************************************
2  * OKVIS - Open Keyframe-based Visual-Inertial SLAM
3  * Copyright (c) 2015, Autonomous Systems Lab / ETH Zurich
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * * Neither the name of Autonomous Systems Lab / ETH Zurich nor the names of
14  * its contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Created on:
30  * Author: Simon Lynen
31  * Modified: Stefan Leutenegger (s.leutenegger@imperial.ac.uk)
32  *********************************************************************************/
33 
42 #ifndef INCLUDE_OKVIS_MATCHINGALGORITHM_HPP_
43 #define INCLUDE_OKVIS_MATCHINGALGORITHM_HPP_
44 
45 #include <vector>
46 #include <cstddef>
47 #include <okvis/assert_macros.hpp>
48 #include <limits>
49 #include <map>
50 #include <memory>
51 
53 namespace okvis {
54 
67  public:
68  OKVIS_DEFINE_EXCEPTION(Exception, std::runtime_error)
69 
70  typedef std::shared_ptr<MatchingAlgorithm> Ptr;
71 
73  virtual ~MatchingAlgorithm();
74 
76  virtual void doSetup() {
77  }
78 
80  virtual size_t sizeA() const = 0;
82  virtual size_t sizeB() const = 0;
83 
86  typedef std::multimap<size_t, size_t> listB_tree_structure_t;
87 
92  virtual listB_tree_structure_t::iterator getListBStartIterator(size_t indexA);
96  virtual listB_tree_structure_t::iterator getListBEndIterator(size_t indexA);
97 
99  virtual float distanceThreshold() const {
100  return std::numeric_limits<float>::max();
101  }
102 
104  virtual float distanceRatioThreshold() const {
105  return 0;
106  }
107 
109  virtual bool skipA(size_t /* indexA */) const {
110  return false;
111  }
112 
114  virtual bool skipB(size_t /* indexB */) const {
115  return false;
116  }
117 
120  virtual float distance(size_t indexA, size_t indexB) const = 0;
121 
123  virtual void reserveMatches(size_t numMatches) = 0;
124 
127  virtual void setBestMatch(size_t indexA, size_t indexB, double distance) = 0;
128 
130  float matchFailed() const {
131  return std::numeric_limits<float>::max();
132  }
133 
134  private:
136 
137 };
138 
139 } // namespace okvis
140 
141 #endif /* INCLUDE_OKVIS_MATCHINGALGORITHM_HPP_ */
virtual float distance(size_t indexA, size_t indexB) const =0
The "distance" between the two points. For points that absolutely don't match. Please use float max...
std::shared_ptr< MatchingAlgorithm > Ptr
Definition: MatchingAlgorithm.hpp:70
virtual listB_tree_structure_t::iterator getListBEndIterator(size_t indexA)
Get end iterator for elements of listB to be matched against the given element from list A (indexA) f...
Definition: MatchingAlgorithm.cpp:61
virtual listB_tree_structure_t::iterator getListBStartIterator(size_t indexA)
Get begin iterator for elements of listB to be matched against the given element from list A (indexA)...
Definition: MatchingAlgorithm.cpp:54
virtual void setBestMatch(size_t indexA, size_t indexB, double distance)=0
At the end of the matching step, this function is called once for each pair of matches discovered...
an interface for 1-1 matching between lists of things.
Definition: MatchingAlgorithm.hpp:66
virtual float distanceRatioThreshold() const
By which factor does the first best match has to be better than the second best one.
Definition: MatchingAlgorithm.hpp:104
std::multimap< size_t, size_t > listB_tree_structure_t
Tree data structure for image space restricted matching mapping from image row to list of features (i...
Definition: MatchingAlgorithm.hpp:86
#define OKVIS_DEFINE_EXCEPTION(exceptionName, exceptionParent)
Macro for defining an exception with a given parent.
Definition: assert_macros.hpp:52
This file contains some useful assert macros.
virtual float distanceThreshold() const
Distances above this threshold will not be returned as matches.
Definition: MatchingAlgorithm.hpp:99
virtual bool skipA(size_t) const
Should we skip the item in list A? This will be called once for each item in the list.
Definition: MatchingAlgorithm.hpp:109
virtual size_t sizeB() const =0
What is the size of list B?
virtual bool skipB(size_t) const
Should we skip the item in list B? This will be called many times.
Definition: MatchingAlgorithm.hpp:114
virtual size_t sizeA() const =0
What is the size of list A?
virtual void reserveMatches(size_t numMatches)=0
A function that tells you how many times setBestMatch() will be called.
listB_tree_structure_t dummy_
Definition: MatchingAlgorithm.hpp:135
float matchFailed() const
What to return if the match failed.
Definition: MatchingAlgorithm.hpp:130
virtual void doSetup()
This will be called exactly once for each call to DenseMatcher::match()
Definition: MatchingAlgorithm.hpp:76