Go to the documentation of this file.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 #pragma once
00029
00030 #include "rtabmap/core/RtabmapExp.h"
00031
00032 #include <opencv2/highgui/highgui.hpp>
00033 #include <opencv2/core/core.hpp>
00034 #include <opencv2/features2d/features2d.hpp>
00035 #include <list>
00036 #include <set>
00037 #include "rtabmap/core/Parameters.h"
00038
00039 namespace rtabmap
00040 {
00041
00042 class DBDriver;
00043 class VisualWord;
00044 class FlannIndex;
00045
00046 class RTABMAP_EXP VWDictionary
00047 {
00048 public:
00049 enum NNStrategy{
00050 kNNFlannNaive,
00051 kNNFlannKdTree,
00052 kNNFlannLSH,
00053 kNNBruteForce,
00054 kNNBruteForceGPU,
00055 kNNUndef};
00056 static const int ID_START;
00057 static const int ID_INVALID;
00058
00059 public:
00060 VWDictionary(const ParametersMap & parameters = ParametersMap());
00061 virtual ~VWDictionary();
00062
00063 virtual void parseParameters(const ParametersMap & parameters);
00064
00065 virtual void update();
00066
00067 virtual std::list<int> addNewWords(
00068 const cv::Mat & descriptors,
00069 int signatureId);
00070 virtual void addWord(VisualWord * vw);
00071
00072 std::vector<int> findNN(const std::list<VisualWord *> & vws) const;
00073 std::vector<int> findNN(const cv::Mat & descriptors) const;
00074
00075 void addWordRef(int wordId, int signatureId);
00076 void removeAllWordRef(int wordId, int signatureId);
00077 const VisualWord * getWord(int id) const;
00078 VisualWord * getUnusedWord(int id) const;
00079 void setLastWordId(int id) {_lastWordId = id;}
00080 const std::map<int, VisualWord *> & getVisualWords() const {return _visualWords;}
00081 float getNndrRatio() const {return _nndrRatio;}
00082 unsigned int getNotIndexedWordsCount() const {return (int)_notIndexedWords.size();}
00083 int getLastIndexedWordId() const;
00084 int getTotalActiveReferences() const {return _totalActiveReferences;}
00085 unsigned int getIndexedWordsCount() const;
00086 unsigned int getIndexMemoryUsed() const;
00087 void setNNStrategy(NNStrategy strategy);
00088 bool isIncremental() const {return _incrementalDictionary;}
00089 bool isIncrementalFlann() const {return _incrementalFlann;}
00090 void setIncrementalDictionary();
00091 void setFixedDictionary(const std::string & dictionaryPath);
00092
00093 void exportDictionary(const char * fileNameReferences, const char * fileNameDescriptors) const;
00094
00095 void clear(bool printWarningsIfNotEmpty = true);
00096 std::vector<VisualWord *> getUnusedWords() const;
00097 std::vector<int> getUnusedWordIds() const;
00098 unsigned int getUnusedWordsSize() const {return (int)_unusedWords.size();}
00099 void removeWords(const std::vector<VisualWord*> & words);
00100 void deleteUnusedWords();
00101
00102 protected:
00103 int getNextId();
00104
00105 protected:
00106 std::map<int, VisualWord *> _visualWords;
00107 int _totalActiveReferences;
00108
00109 private:
00110 bool _incrementalDictionary;
00111 bool _incrementalFlann;
00112 float _rebalancingFactor;
00113 float _nndrRatio;
00114 std::string _dictionaryPath;
00115 bool _newWordsComparedTogether;
00116 int _lastWordId;
00117 bool useDistanceL1_;
00118 FlannIndex * _flannIndex;
00119 cv::Mat _dataTree;
00120 NNStrategy _strategy;
00121 std::map<int ,int> _mapIndexId;
00122 std::map<int ,int> _mapIdIndex;
00123 std::map<int, VisualWord*> _unusedWords;
00124 std::set<int> _notIndexedWords;
00125 std::set<int> _removedIndexedWords;
00126 };
00127
00128 }