31 #ifndef RTABMAP_FLANN_HPP_ 32 #define RTABMAP_FLANN_HPP_ 69 (*this)[
"filename"] = filename;
75 template<
typename Distance>
84 : index_params_(params)
91 nnIndex_ = load_saved_index(features, get_param<std::string>(params,
"filename"),
distance);
96 nnIndex_ = create_index_by_type<Distance>(index_type, features, params,
distance);
102 : index_params_(params)
108 nnIndex_ = load_saved_index(features, get_param<std::string>(params,
"filename"),
distance);
112 flann_algorithm_t index_type = get_param<flann_algorithm_t>(params,
"algorithm");
113 nnIndex_ = create_index_by_type<Distance>(index_type, features, params,
distance);
118 Index(
const Index& other) : loaded_(other.loaded_), index_params_(other.index_params_)
140 nnIndex_->buildIndex();
146 nnIndex_->buildIndex(points);
151 nnIndex_->addPoints(points, rebuild_threshold);
160 nnIndex_->removePoint(point_id);
170 return nnIndex_->getPoint(point_id);
177 void save(std::string filename)
179 FILE* fout = fopen(filename.c_str(),
"wb");
183 nnIndex_->saveIndex(fout);
192 return nnIndex_->veclen();
200 return nnIndex_->size();
205 return nnIndex_->removedCount();
210 return nnIndex_->sizeAtBuild();
218 return nnIndex_->getType();
226 return nnIndex_->usedMemory();
235 return nnIndex_->getParameters();
252 return nnIndex_->knnSearch(queries, indices, dists, knn, params);
270 return nnIndex_->knnSearch(queries, indices, dists, knn, params);
282 std::vector< std::vector<size_t> >& indices,
283 std::vector<std::vector<DistanceType> >& dists,
287 return nnIndex_->knnSearch(queries, indices, dists, knn, params);
300 std::vector< std::vector<int> >& indices,
301 std::vector<std::vector<DistanceType> >& dists,
305 return nnIndex_->knnSearch(queries, indices, dists, knn, params);
323 return nnIndex_->radiusSearch(queries, indices, dists, radius, params);
341 return nnIndex_->radiusSearch(queries, indices, dists, radius, params);
354 std::vector< std::vector<size_t> >& indices,
355 std::vector<std::vector<DistanceType> >& dists,
359 return nnIndex_->radiusSearch(queries, indices, dists, radius, params);
372 std::vector< std::vector<int> >& indices,
373 std::vector<std::vector<DistanceType> >& dists,
377 return nnIndex_->radiusSearch(queries, indices, dists, radius, params);
383 FILE* fin = fopen(filename.c_str(),
"rb");
389 throw FLANNException(
"Datatype of saved index is different than of the one to be loaded.");
394 IndexType* nnIndex = create_index_by_type<Distance>(header.
h.
index_type, dataset, params,
distance);
404 std::swap(nnIndex_, other.
nnIndex_);
405 std::swap(loaded_, other.
loaded_);
433 template <
typename Distance>
SavedIndexParams(std::string filename)
std::map< std::string, any > IndexParams
void log_verbosity(int level)
IndexType * load_saved_index(const Matrix< ElementType > &dataset, const std::string &filename, Distance distance)
IndexParams index_params_
void removePoint(size_t point_id)
ElementType * getPoint(size_t point_id)
int getClusterCenters(Matrix< DistanceType > ¢ers)
int knnSearch(const Matrix< ElementType > &queries, std::vector< std::vector< size_t > > &indices, std::vector< std::vector< DistanceType > > &dists, size_t knn, const SearchParams ¶ms) const
Perform k-nearest neighbor search.
GLM_FUNC_DECL genType::value_type distance(genType const &p0, genType const &p1)
IndexParams getParameters() const
std_msgs::Header * header(M &m)
int radiusSearch(const Matrix< ElementType > &queries, Matrix< int > &indices, Matrix< DistanceType > &dists, float radius, const SearchParams ¶ms) const
NNIndex< Distance > IndexType
size_t sizeAtBuild() const
int knnSearch(const Matrix< ElementType > &queries, Matrix< int > &indices, Matrix< DistanceType > &dists, size_t knn, const SearchParams ¶ms) const
Index(const IndexParams ¶ms, Distance distance=Distance())
int knnSearch(const Matrix< ElementType > &queries, Matrix< size_t > &indices, Matrix< DistanceType > &dists, size_t knn, const SearchParams ¶ms) const
Perform k-nearest neighbor search.
virtual void buildIndex()
int radiusSearch(const Matrix< ElementType > &queries, std::vector< std::vector< size_t > > &indices, std::vector< std::vector< DistanceType > > &dists, float radius, const SearchParams ¶ms) const
Perform radius search.
void addPoints(const Matrix< ElementType > &points, float rebuild_threshold=2)
Distance::ResultType DistanceType
int radiusSearch(const Matrix< ElementType > &queries, std::vector< std::vector< int > > &indices, std::vector< std::vector< DistanceType > > &dists, float radius, const SearchParams ¶ms) const
IndexHeader load_header(FILE *stream)
flann_algorithm_t getType() const
Index(const Matrix< ElementType > &features, const IndexParams ¶ms, Distance distance=Distance())
virtual void loadIndex(FILE *stream)=0
void buildIndex(const Matrix< ElementType > &points)
void save(std::string filename)
Index & operator=(Index other)
int knnSearch(const Matrix< ElementType > &queries, std::vector< std::vector< int > > &indices, std::vector< std::vector< DistanceType > > &dists, size_t knn, const SearchParams ¶ms) const
int hierarchicalClustering(const Matrix< typename Distance::ElementType > &points, Matrix< typename Distance::ResultType > ¢ers, const KMeansIndexParams ¶ms, Distance d=Distance())
size_t removedCount() const
int radiusSearch(const Matrix< ElementType > &queries, Matrix< size_t > &indices, Matrix< DistanceType > &dists, float radius, const SearchParams ¶ms) const
Perform radius search.
static void setLevel(int level)
virtual NNIndex * clone() const =0
Distance::ElementType ElementType
Index(const Index &other)