Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need for speed - Speed up loading map time #1267

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ SET(PROJECT_VERSION_PATCH ${RTABMAP_PATCH_VERSION})
SET(PROJECT_SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")

####### COMPILATION PARAMS #######
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# In case of Makefiles if the user does not setup CMAKE_BUILD_TYPE, assume it's Release:
IF(${CMAKE_GENERATOR} MATCHES ".*Makefiles")
IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
Expand Down
18 changes: 14 additions & 4 deletions corelib/include/rtabmap/core/FlannIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define CORELIB_SRC_FLANNINDEX_H_

#include "rtabmap/core/rtabmap_core_export.h" // DLL export/import defines
#include <filesystem>
#include <list>
#include <opencv2/opencv.hpp>
#include <fstream>

namespace rtabmap {

Expand All @@ -40,11 +42,19 @@ class RTABMAP_CORE_EXPORT FlannIndex
FlannIndex();
virtual ~FlannIndex();

// serialize and save methods
void save(const std::filesystem::path& path);
void serialize(const std::filesystem::path& filename);

// deserialize and load methods
void load(const std::filesystem::path& dir);
void deserialize(const std::filesystem::path& file);

void release();
size_t indexedFeatures() const;
[[nodiscard]] size_t indexedFeatures() const;

// return Bytes
size_t memoryUsed() const;
[[nodiscard]] size_t memoryUsed() const;

// Note that useDistanceL1 doesn't have any effect if LSH is used
void buildLinearIndex(
Expand All @@ -71,8 +81,8 @@ class RTABMAP_CORE_EXPORT FlannIndex

bool isBuilt();

int featuresType() const {return featuresType_;}
int featuresDim() const {return featuresDim_;}
[[nodiscard]] int featuresType() const {return featuresType_;}
[[nodiscard]] int featuresDim() const {return featuresDim_;}

std::vector<unsigned int> addPoints(const cv::Mat & features);

Expand Down
3 changes: 2 additions & 1 deletion corelib/include/rtabmap/core/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "rtabmap/core/SensorData.h"
#include "rtabmap/core/Link.h"
#include "rtabmap/core/Features2d.h"
#include <string_view>
#include <typeinfo>
#include <list>
#include <map>
Expand Down Expand Up @@ -226,7 +227,7 @@ class RTABMAP_CORE_EXPORT Memory
void dumpMemoryTree(const char * fileNameTree) const;
virtual void dumpMemory(std::string directory) const;
virtual void dumpSignatures(const char * fileNameSign, bool words3D) const;
void dumpDictionary(const char * fileNameRef, const char * fileNameDesc) const;
void dumpDictionary(std::string_view dir) const;
unsigned long getMemoryUsed() const; //Bytes

void generateGraph(const std::string & fileName, const std::set<int> & ids = std::set<int>());
Expand Down
51 changes: 30 additions & 21 deletions corelib/include/rtabmap/core/VWDictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "rtabmap/core/rtabmap_core_export.h" // DLL export/import defines

#include <filesystem>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <list>
#include <set>
#include <string_view>
#include "rtabmap/core/Parameters.h"
#include <fstream>

namespace rtabmap
{
Expand Down Expand Up @@ -74,7 +77,8 @@ class RTABMAP_CORE_EXPORT VWDictionary
}

public:
VWDictionary(const ParametersMap & parameters = ParametersMap());
explicit VWDictionary(const ParametersMap & parameters = ParametersMap());
void setSavedIndex(const std::filesystem::path& dir);
virtual ~VWDictionary();

virtual void parseParameters(const ParametersMap & parameters);
Expand All @@ -86,60 +90,65 @@ class RTABMAP_CORE_EXPORT VWDictionary
int signatureId);
virtual void addWord(VisualWord * vw);

std::vector<int> findNN(const std::list<VisualWord *> & vws) const;
std::vector<int> findNN(const cv::Mat & descriptors) const;
[[nodiscard]] std::vector<int> findNN(const std::list<VisualWord *> & vws) const;
[[nodiscard]] std::vector<int> findNN(const cv::Mat & queryIn) const;

void addWordRef(int wordId, int signatureId);
void removeAllWordRef(int wordId, int signatureId);
const VisualWord * getWord(int id) const;
VisualWord * getUnusedWord(int id) const;
[[nodiscard]] const VisualWord * getWord(int id) const;
[[nodiscard]] VisualWord * getUnusedWord(int id) const;
void setLastWordId(int id) {_lastWordId = id;}
const std::map<int, VisualWord *> & getVisualWords() const {return _visualWords;}
float getNndrRatio() const {return _nndrRatio;}
unsigned int getNotIndexedWordsCount() const {return (int)_notIndexedWords.size();}
int getLastIndexedWordId() const;
int getTotalActiveReferences() const {return _totalActiveReferences;}
unsigned int getIndexedWordsCount() const;
unsigned int getIndexMemoryUsed() const; // KB
unsigned long getMemoryUsed() const; //Bytes
[[nodiscard]] const std::map<int, VisualWord *> & getVisualWords() const {return _visualWords;}
[[nodiscard]] float getNndrRatio() const {return _nndrRatio;}
[[nodiscard]] unsigned int getNotIndexedWordsCount() const {return (int)_notIndexedWords.size();}
[[nodiscard]] int getLastIndexedWordId() const;
[[nodiscard]] int getTotalActiveReferences() const {return _totalActiveReferences;}
[[nodiscard]] unsigned int getIndexedWordsCount() const;
[[nodiscard]] unsigned int getIndexMemoryUsed() const; // KB
[[nodiscard]] unsigned long getMemoryUsed() const; //Bytes
bool setNNStrategy(NNStrategy strategy); // Return true if the search tree has been re-initialized
bool isIncremental() const {return _incrementalDictionary;}
bool isIncrementalFlann() const {return _incrementalFlann;}
[[nodiscard]] bool isIncremental() const {return _incrementalDictionary;}
[[nodiscard]] bool isIncrementalFlann() const {return _incrementalFlann;}
void setIncrementalDictionary();
void setFixedDictionary(const std::string & dictionaryPath);

void exportDictionary(const char * fileNameReferences, const char * fileNameDescriptors) const;

void clear(bool printWarningsIfNotEmpty = true);
std::vector<VisualWord *> getUnusedWords() const;
std::vector<int> getUnusedWordIds() const;
unsigned int getUnusedWordsSize() const {return (int)_unusedWords.size();}
[[nodiscard]] std::vector<VisualWord *> getUnusedWords() const;
[[nodiscard]] std::vector<int> getUnusedWordIds() const;
[[nodiscard]] unsigned int getUnusedWordsSize() const {return (int)_unusedWords.size();}
void removeWords(const std::vector<VisualWord*> & words); // caller must delete the words
void deleteUnusedWords();

void save(std::string_view dir) const;
void load(std::string_view dir);
void loadMapIndex(const std::filesystem::path& file);

public:
static cv::Mat convertBinTo32F(const cv::Mat & descriptorsIn, bool byteToFloat = true);
static cv::Mat convert32FToBin(const cv::Mat & descriptorsIn, bool byteToFloat = true);

protected:
int getNextId();

protected:
void saveVars(const std::filesystem::path& filename) const;
std::map<int, VisualWord *> _visualWords; //<id,VisualWord*>
int _totalActiveReferences; // keep track of all references for updating the common signature

private:
bool _useSavedFile{false};
bool _incrementalDictionary;
bool _incrementalFlann;
float _rebalancingFactor;
bool _byteToFloat;
float _nndrRatio;
std::string save_dir_;
std::string _dictionaryPath; // a pre-computed dictionary (.txt or .db)
std::string _newDictionaryPath; // a pre-computed dictionary (.txt or .db)
bool _newWordsComparedTogether;
int _lastWordId;
bool useDistanceL1_;
FlannIndex * _flannIndex;
FlannIndex * _flannIndex; // save
cv::Mat _dataTree;
NNStrategy _strategy;
std::map<int ,int> _mapIndexId;
Expand Down
Loading
Loading