VWDictionary.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3 All rights reserved.
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  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the Universite de Sherbrooke nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #pragma once
29 
30 #include "rtabmap/core/RtabmapExp.h" // DLL export/import defines
31 
32 #include <opencv2/highgui/highgui.hpp>
33 #include <opencv2/core/core.hpp>
34 #include <opencv2/features2d/features2d.hpp>
35 #include <list>
36 #include <set>
38 
39 namespace rtabmap
40 {
41 
42 class DBDriver;
43 class VisualWord;
44 class FlannIndex;
45 
47 {
48 public:
49  enum NNStrategy{
55  kNNUndef};
56  static const int ID_START;
57  static const int ID_INVALID;
58 
59 public:
60  VWDictionary(const ParametersMap & parameters = ParametersMap());
61  virtual ~VWDictionary();
62 
63  virtual void parseParameters(const ParametersMap & parameters);
64 
65  virtual void update();
66 
67  virtual std::list<int> addNewWords(
68  const cv::Mat & descriptors,
69  int signatureId);
70  virtual void addWord(VisualWord * vw);
71 
72  std::vector<int> findNN(const std::list<VisualWord *> & vws) const;
73  std::vector<int> findNN(const cv::Mat & descriptors) const;
74 
75  void addWordRef(int wordId, int signatureId);
76  void removeAllWordRef(int wordId, int signatureId);
77  const VisualWord * getWord(int id) const;
78  VisualWord * getUnusedWord(int id) const;
79  void setLastWordId(int id) {_lastWordId = id;}
80  const std::map<int, VisualWord *> & getVisualWords() const {return _visualWords;}
81  float getNndrRatio() const {return _nndrRatio;}
82  unsigned int getNotIndexedWordsCount() const {return (int)_notIndexedWords.size();}
83  int getLastIndexedWordId() const;
84  int getTotalActiveReferences() const {return _totalActiveReferences;}
85  unsigned int getIndexedWordsCount() const;
86  unsigned int getIndexMemoryUsed() const;
87  void setNNStrategy(NNStrategy strategy);
88  bool isIncremental() const {return _incrementalDictionary;}
89  bool isIncrementalFlann() const {return _incrementalFlann;}
90  void setIncrementalDictionary();
91  void setFixedDictionary(const std::string & dictionaryPath);
92 
93  void exportDictionary(const char * fileNameReferences, const char * fileNameDescriptors) const;
94 
95  void clear(bool printWarningsIfNotEmpty = true);
96  std::vector<VisualWord *> getUnusedWords() const;
97  std::vector<int> getUnusedWordIds() const;
98  unsigned int getUnusedWordsSize() const {return (int)_unusedWords.size();}
99  void removeWords(const std::vector<VisualWord*> & words); // caller must delete the words
100  void deleteUnusedWords();
101 
102 protected:
103  int getNextId();
104 
105 protected:
106  std::map<int, VisualWord *> _visualWords; //<id,VisualWord*>
107  int _totalActiveReferences; // keep track of all references for updating the common signature
108 
109 private:
113  float _nndrRatio;
114  std::string _dictionaryPath; // a pre-computed dictionary (.txt)
119  cv::Mat _dataTree;
121  std::map<int ,int> _mapIndexId;
122  std::map<int ,int> _mapIdIndex;
123  std::map<int, VisualWord*> _unusedWords; //<id,VisualWord*>, note that these words stay in _visualWords
124  std::set<int> _notIndexedWords; // Words that are not indexed in the dictionary
125  std::set<int> _removedIndexedWords; // Words not anymore in the dictionary but still indexed in the dictionary
126 };
127 
128 } // namespace rtabmap
std::map< std::string, std::string > ParametersMap
Definition: Parameters.h:41
std::map< int,int > _mapIdIndex
Definition: VWDictionary.h:122
#define RTABMAP_EXP
Definition: RtabmapExp.h:38
void setLastWordId(int id)
Definition: VWDictionary.h:79
float getNndrRatio() const
Definition: VWDictionary.h:81
bool isIncrementalFlann() const
Definition: VWDictionary.h:89
std::map< int,int > _mapIndexId
Definition: VWDictionary.h:121
std::set< int > _notIndexedWords
Definition: VWDictionary.h:124
std::map< int, VisualWord * > _unusedWords
Definition: VWDictionary.h:123
std::set< int > _removedIndexedWords
Definition: VWDictionary.h:125
static const int ID_START
Definition: VWDictionary.h:56
unsigned int getNotIndexedWordsCount() const
Definition: VWDictionary.h:82
unsigned int getUnusedWordsSize() const
Definition: VWDictionary.h:98
static const int ID_INVALID
Definition: VWDictionary.h:57
int getTotalActiveReferences() const
Definition: VWDictionary.h:84
bool isIncremental() const
Definition: VWDictionary.h:88
std::string _dictionaryPath
Definition: VWDictionary.h:114
const std::map< int, VisualWord * > & getVisualWords() const
Definition: VWDictionary.h:80
FlannIndex * _flannIndex
Definition: VWDictionary.h:118
std::map< int, VisualWord * > _visualWords
Definition: VWDictionary.h:106


rtabmap
Author(s): Mathieu Labbe
autogenerated on Wed Jun 5 2019 22:43:41