mirror of
https://github.com/introlab/rtabmap.git
synced 2026-10-07 10:37:47 +08:00
Loading time optimization (#1569)
* On init, rebuild the dictionnary only once * Fixed first dictionary update to avoid rebuilding multiple times. Commented some very verbose debug logs (should create a new level: UVERBOSE or UTRACE) * bump version 0.23: added parameters "Mem/LoadVisualLocalFeaturesOnInit", "Mem/FlannIndexSaved", "Kp/SerializeWithChecksum". * Renamed Mem/FlannIndexSaved to Kp/FlannIndexSaved. Update UI Preferences with new parameters. * commented some very verbose debug logs * Warn flann index serialization not implemented on windows * Warn flann index deserialization not implemented on windows * Removing some verbose logs * missing header (win32) * Added GlobalMap::fullUpdateNeeded() function * Adding log * Save flann index even if links changed * log time to serialize flann index * Make dictionary modified only after we update --------- Co-authored-by: Mathieu Labbe <[email protected]>
This commit is contained in:
co-authored by
Mathieu Labbe
parent
349580299c
commit
4603f09389
@@ -103,7 +103,6 @@ public:
|
||||
{
|
||||
flann_algorithm_t index_type = get_param<flann_algorithm_t>(params,"algorithm");
|
||||
loaded_ = false;
|
||||
|
||||
if (index_type == FLANN_INDEX_SAVED) {
|
||||
nnIndex_ = load_saved_index(features, get_param<std::string>(params,"filename"), distance);
|
||||
loaded_ = true;
|
||||
@@ -180,10 +179,20 @@ public:
|
||||
if (fout == NULL) {
|
||||
throw FLANNException("Cannot open file");
|
||||
}
|
||||
nnIndex_->saveIndex(fout);
|
||||
save(fout);
|
||||
fclose(fout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save index to file stream.
|
||||
* Caller has to open file stream with "wb" and close it afterwards.
|
||||
* @param filename
|
||||
*/
|
||||
void save(FILE * stream)
|
||||
{
|
||||
nnIndex_->saveIndex(stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* \returns number of features in this index.
|
||||
*/
|
||||
@@ -377,6 +386,26 @@ public:
|
||||
return nnIndex_->radiusSearch(queries, indices, dists, radius, params);
|
||||
}
|
||||
|
||||
void load_saved_index(FILE* fin)
|
||||
{
|
||||
if(loaded_) {
|
||||
throw FLANNException("Index already loaded!");
|
||||
}
|
||||
if(nnIndex_->sizeAtBuild() != 0) {
|
||||
throw FLANNException("Index must not be already built to load data.");
|
||||
}
|
||||
if (fin == NULL) {
|
||||
throw FLANNException("File pointer must be valid!");
|
||||
}
|
||||
IndexHeader header = load_header(fin);
|
||||
if (header.h.data_type != flann_datatype_value<ElementType>::value) {
|
||||
throw FLANNException("Datatype of saved index is different than of the one to be loaded.");
|
||||
}
|
||||
rewind(fin);
|
||||
nnIndex_->loadIndex(fin);
|
||||
loaded_ = true;
|
||||
}
|
||||
|
||||
private:
|
||||
IndexType* load_saved_index(const Matrix<ElementType>& dataset, const std::string& filename, Distance distance)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user