VWDictionary.h
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2010-2014, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of the Universite de Sherbrooke nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
00020 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 */
00027 
00028 #pragma once
00029 
00030 #include "rtabmap/core/RtabmapExp.h" // DLL export/import defines
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 
00045 class RTABMAP_EXP VWDictionary
00046 {
00047 public:
00048         enum NNStrategy{kNNFlannNaive, kNNFlannKdTree, kNNFlannLSH, kNNBruteForce, kNNBruteForceGPU, kNNUndef};
00049         static const int ID_START;
00050         static const int ID_INVALID;
00051 
00052 public:
00053         VWDictionary(const ParametersMap & parameters = ParametersMap());
00054         virtual ~VWDictionary();
00055 
00056         virtual void parseParameters(const ParametersMap & parameters);
00057 
00058         virtual void update();
00059 
00060         virtual std::list<int> addNewWords(
00061                         const cv::Mat & descriptors,
00062                         int signatureId);
00063         virtual void addWord(VisualWord * vw);
00064 
00065         virtual std::vector<int> findNN(const std::list<VisualWord *> & vws) const;
00066 
00067         void addWordRef(int wordId, int signatureId);
00068         void removeAllWordRef(int wordId, int signatureId);
00069         const VisualWord * getWord(int id) const;
00070         VisualWord * getUnusedWord(int id) const;
00071         void setLastWordId(int id) {_lastWordId = id;}
00072         const std::map<int, VisualWord *> & getVisualWords() const {return _visualWords;}
00073         float getNndrRatio() const {return _nndrRatio;}
00074         unsigned int getNotIndexedWordsCount() const {return (int)_notIndexedWords.size();}
00075         int getLastIndexedWordId() const;
00076         int getTotalActiveReferences() const {return _totalActiveReferences;}
00077         void setNNStrategy(NNStrategy strategy);
00078         bool isIncremental() const {return _incrementalDictionary;}
00079         void setIncrementalDictionary();
00080         void setFixedDictionary(const std::string & dictionaryPath);
00081 
00082         void exportDictionary(const char * fileNameReferences, const char * fileNameDescriptors) const;
00083 
00084         void clear();
00085         std::vector<VisualWord *> getUnusedWords() const;
00086         std::vector<int> getUnusedWordIds() const;
00087         unsigned int getUnusedWordsSize() const {return (int)_unusedWords.size();}
00088         void removeWords(const std::vector<VisualWord*> & words); // caller must delete the words
00089         void deleteUnusedWords();
00090 
00091 protected:
00092         int getNextId();
00093 
00094 protected:
00095         std::map<int, VisualWord *> _visualWords; //<id,VisualWord*>
00096         int _totalActiveReferences; // keep track of all references for updating the common signature
00097 
00098 private:
00099         bool _incrementalDictionary;
00100         float _nndrRatio;
00101         std::string _dictionaryPath; // a pre-computed dictionary (.txt)
00102         bool _newWordsComparedTogether;
00103         int _lastWordId;
00104         cv::flann::Index * _flannIndex;
00105         cv::Mat _dataTree;
00106         NNStrategy _strategy;
00107         std::map<int ,int> _mapIndexId;
00108         std::map<int, VisualWord*> _unusedWords; //<id,VisualWord*>, note that these words stay in _visualWords
00109         std::set<int> _notIndexedWords; // Words that are not indexed in the dictionary
00110         std::set<int> _removedIndexedWords; // Words not anymore in the dictionary but still indexed in the dictionary
00111 };
00112 
00113 } // namespace rtabmap


rtabmap
Author(s): Mathieu Labbe
autogenerated on Fri Aug 28 2015 12:51:42