Classes | Public Types | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
rtflann::LshIndex< Distance > Class Template Reference

#include <lsh_index.h>

Inheritance diagram for rtflann::LshIndex< Distance >:
Inheritance graph
[legend]

Classes

struct  SortScoreIndexPairOnSecond
 

Public Types

typedef NNIndex< Distance > BaseClass
 
typedef Distance::ResultType DistanceType
 
typedef Distance::ElementType ElementType
 
- Public Types inherited from rtflann::NNIndex< Distance >
typedef Distance::ResultType DistanceType
 
typedef Distance::ElementType ElementType
 

Public Member Functions

void addPoints (const Matrix< ElementType > &points, float rebuild_threshold=2)
 Incrementally add points to the index. More...
 
virtual void buildIndex ()
 
virtual void buildIndex (const Matrix< ElementType > &dataset)
 
BaseClassclone () const
 
void findNeighbors (ResultSet< DistanceType > &result, const ElementType *vec, const SearchParams &) const
 
flann_algorithm_t getType () const
 
int knnSearch (const Matrix< ElementType > &queries, Matrix< size_t > &indices, Matrix< DistanceType > &dists, size_t knn, const SearchParams &params) const
 Perform k-nearest neighbor search. More...
 
int knnSearch (const Matrix< ElementType > &queries, std::vector< std::vector< size_t > > &indices, std::vector< std::vector< DistanceType > > &dists, size_t knn, const SearchParams &params) const
 Perform k-nearest neighbor search. More...
 
void loadIndex (FILE *stream)
 
 LshIndex (const IndexParams &params=LshIndexParams(), Distance d=Distance())
 
 LshIndex (const LshIndex &other)
 
 LshIndex (const Matrix< ElementType > &input_data, const IndexParams &params=LshIndexParams(), Distance d=Distance())
 
LshIndexoperator= (LshIndex other)
 
void saveIndex (FILE *stream)
 
template<typename Archive >
void serialize (Archive &ar)
 
int usedMemory () const
 
virtual ~LshIndex ()
 
- Public Member Functions inherited from rtflann::NNIndex< Distance >
virtual void buildIndex ()
 
virtual void buildIndex (const Matrix< ElementType > &dataset)
 
IndexParams getParameters () const
 
virtual ElementTypegetPoint (size_t id)
 
int knnSearch (const Matrix< ElementType > &queries, std::vector< std::vector< int > > &indices, std::vector< std::vector< DistanceType > > &dists, size_t knn, const SearchParams &params) const
 
 NNIndex (const IndexParams &params, Distance d)
 
 NNIndex (const NNIndex &other)
 
 NNIndex (Distance d)
 
int radiusSearch (const Matrix< ElementType > &queries, Matrix< int > &indices, Matrix< DistanceType > &dists, float radius, const SearchParams &params) const
 
virtual int radiusSearch (const Matrix< ElementType > &queries, Matrix< size_t > &indices, Matrix< DistanceType > &dists, float radius, const SearchParams &params) const
 Perform radius search. More...
 
int radiusSearch (const Matrix< ElementType > &queries, std::vector< std::vector< int > > &indices, std::vector< std::vector< DistanceType > > &dists, float radius, const SearchParams &params) const
 
virtual int radiusSearch (const Matrix< ElementType > &queries, std::vector< std::vector< size_t > > &indices, std::vector< std::vector< DistanceType > > &dists, float radius, const SearchParams &params) const
 Perform radius search. More...
 
size_t removedCount () const
 
virtual void removePoint (size_t id)
 
template<typename Archive >
void serialize (Archive &ar)
 
size_t size () const
 
size_t sizeAtBuild () const
 
size_t veclen () const
 
virtual ~NNIndex ()
 
- Public Member Functions inherited from rtflann::IndexBase
virtual ~IndexBase ()
 

Protected Member Functions

void buildIndexImpl ()
 
void freeIndex ()
 
- Protected Member Functions inherited from rtflann::NNIndex< Distance >
void cleanRemovedPoints ()
 
void extendDataset (const Matrix< ElementType > &new_points)
 
size_t id_to_index (size_t id)
 
void indices_to_ids (const size_t *in, size_t *out, size_t size) const
 
void setDataset (const Matrix< ElementType > &dataset)
 
void swap (NNIndex &other)
 

Private Types

typedef std::pair< float, unsigned intScoreIndexPair
 

Private Member Functions

void fill_xor_mask (lsh::BucketKey key, int lowest_index, unsigned int level, std::vector< lsh::BucketKey > &xor_masks)
 
void getNeighbors (const ElementType *vec, bool do_radius, float radius, bool do_k, unsigned int k_nn, float &checked_average)
 
void getNeighbors (const ElementType *vec, ResultSet< DistanceType > &result) const
 
void swap (LshIndex &other)
 

Private Attributes

unsigned int key_size_
 
unsigned int multi_probe_level_
 
unsigned int table_number_
 
std::vector< lsh::LshTable< ElementType > > tables_
 
std::vector< lsh::BucketKeyxor_masks_
 

Additional Inherited Members

- Protected Attributes inherited from rtflann::NNIndex< Distance >
ElementTypedata_ptr_
 
Distance distance_
 
std::vector< size_tids_
 
IndexParams index_params_
 
size_t last_id_
 
std::vector< ElementType * > points_
 
bool removed_
 
size_t removed_count_
 
DynamicBitset removed_points_
 
size_t size_
 
size_t size_at_build_
 
size_t veclen_
 

Detailed Description

template<typename Distance>
class rtflann::LshIndex< Distance >

Randomized kd-tree index

Contains the k-d trees and other information for indexing a set of points for nearest-neighbor matching.

Definition at line 108 of file lsh_index.h.

Member Typedef Documentation

◆ BaseClass

template<typename Distance >
typedef NNIndex<Distance> rtflann::LshIndex< Distance >::BaseClass

Definition at line 114 of file lsh_index.h.

◆ DistanceType

template<typename Distance >
typedef Distance::ResultType rtflann::LshIndex< Distance >::DistanceType

Definition at line 112 of file lsh_index.h.

◆ ElementType

template<typename Distance >
typedef Distance::ElementType rtflann::LshIndex< Distance >::ElementType

Definition at line 111 of file lsh_index.h.

◆ ScoreIndexPair

template<typename Distance >
typedef std::pair<float, unsigned int> rtflann::LshIndex< Distance >::ScoreIndexPair
private

Defines the comparator on score and index

Definition at line 407 of file lsh_index.h.

Constructor & Destructor Documentation

◆ LshIndex() [1/3]

template<typename Distance >
rtflann::LshIndex< Distance >::LshIndex ( const IndexParams params = LshIndexParams(),
Distance  d = Distance() 
)
inline

Constructor

Parameters
paramsparameters passed to the LSH algorithm
dthe distance used

Definition at line 120 of file lsh_index.h.

◆ LshIndex() [2/3]

template<typename Distance >
rtflann::LshIndex< Distance >::LshIndex ( const Matrix< ElementType > &  input_data,
const IndexParams params = LshIndexParams(),
Distance  d = Distance() 
)
inline

Constructor

Parameters
input_datadataset with the input features
paramsparameters passed to the LSH algorithm
dthe distance used

Definition at line 136 of file lsh_index.h.

◆ LshIndex() [3/3]

template<typename Distance >
rtflann::LshIndex< Distance >::LshIndex ( const LshIndex< Distance > &  other)
inline

Definition at line 148 of file lsh_index.h.

◆ ~LshIndex()

template<typename Distance >
virtual rtflann::LshIndex< Distance >::~LshIndex ( )
inlinevirtual

Definition at line 163 of file lsh_index.h.

Member Function Documentation

◆ addPoints()

template<typename Distance >
void rtflann::LshIndex< Distance >::addPoints ( const Matrix< ElementType > &  points,
float  rebuild_threshold = 2 
)
inlinevirtual

Incrementally add points to the index.

Parameters
pointsMatrix with points to be added
rebuild_threshold

Reimplemented from rtflann::NNIndex< Distance >.

Definition at line 176 of file lsh_index.h.

◆ buildIndex() [1/2]

template<typename Distance >
virtual void rtflann::NNIndex< Distance >::buildIndex
inline

Builds the index

Definition at line 153 of file nn_index.h.

◆ buildIndex() [2/2]

template<typename Distance >
virtual void rtflann::NNIndex< Distance >::buildIndex
inline

Builds the index using the specified dataset

Parameters
datasetthe dataset to use

Definition at line 169 of file nn_index.h.

◆ buildIndexImpl()

template<typename Distance >
void rtflann::LshIndex< Distance >::buildIndexImpl ( )
inlineprotectedvirtual

Builds the index

Implements rtflann::NNIndex< Distance >.

Definition at line 381 of file lsh_index.h.

◆ clone()

template<typename Distance >
BaseClass* rtflann::LshIndex< Distance >::clone ( ) const
inlinevirtual

Implements rtflann::NNIndex< Distance >.

Definition at line 169 of file lsh_index.h.

◆ fill_xor_mask()

template<typename Distance >
void rtflann::LshIndex< Distance >::fill_xor_mask ( lsh::BucketKey  key,
int  lowest_index,
unsigned int  level,
std::vector< lsh::BucketKey > &  xor_masks 
)
inlineprivate

Fills the different xor masks to use when getting the neighbors in multi-probe LSH

Parameters
keythe key we build neighbors from
lowest_indexthe lowest index of the bit set
levelthe multi-probe level we are at
xor_masksall the xor mask

Definition at line 422 of file lsh_index.h.

◆ findNeighbors()

template<typename Distance >
void rtflann::LshIndex< Distance >::findNeighbors ( ResultSet< DistanceType > &  result,
const ElementType vec,
const SearchParams  
) const
inlinevirtual

Find set of nearest neighbors to vec. Their indices are stored inside the result object.

Params: result = the result object in which the indices of the nearest-neighbors are stored vec = the vector for which to search the nearest neighbors maxCheck = the maximum number of restarts (in a best-bin-first manner)

Implements rtflann::NNIndex< Distance >.

Definition at line 371 of file lsh_index.h.

◆ freeIndex()

template<typename Distance >
void rtflann::LshIndex< Distance >::freeIndex ( )
inlineprotectedvirtual

Implements rtflann::NNIndex< Distance >.

Definition at line 398 of file lsh_index.h.

◆ getNeighbors() [1/2]

template<typename Distance >
void rtflann::LshIndex< Distance >::getNeighbors ( const ElementType vec,
bool  do_radius,
float  radius,
bool  do_k,
unsigned int  k_nn,
float checked_average 
)
inlineprivate

Performs the approximate nearest-neighbor search.

Parameters
vecthe feature to analyze
do_radiusflag indicating if we check the radius too
radiusthe radius if it is a radius search
do_kflag indicating if we limit the number of nn
k_nnthe number of nearest neighbors
checked_averageused for debugging

Definition at line 442 of file lsh_index.h.

◆ getNeighbors() [2/2]

template<typename Distance >
void rtflann::LshIndex< Distance >::getNeighbors ( const ElementType vec,
ResultSet< DistanceType > &  result 
) const
inlineprivate

Performs the approximate nearest-neighbor search. This is a slower version than the above as it uses the ResultSet

Parameters
vecthe feature to analyze

Definition at line 520 of file lsh_index.h.

◆ getType()

template<typename Distance >
flann_algorithm_t rtflann::LshIndex< Distance >::getType ( ) const
inlinevirtual

Implements rtflann::IndexBase.

Definition at line 197 of file lsh_index.h.

◆ knnSearch() [1/2]

template<typename Distance >
int rtflann::LshIndex< Distance >::knnSearch ( const Matrix< ElementType > &  queries,
Matrix< size_t > &  indices,
Matrix< DistanceType > &  dists,
size_t  knn,
const SearchParams params 
) const
inlinevirtual

Perform k-nearest neighbor search.

Parameters
[in]queriesThe query points for which to find the nearest neighbors
[out]indicesThe indices of the nearest neighbors found
[out]distsDistances to the nearest neighbors found
[in]knnNumber of nearest neighbors to return
[in]paramsSearch parameters

Reimplemented from rtflann::NNIndex< Distance >.

Definition at line 254 of file lsh_index.h.

◆ knnSearch() [2/2]

template<typename Distance >
int rtflann::LshIndex< Distance >::knnSearch ( const Matrix< ElementType > &  queries,
std::vector< std::vector< size_t > > &  indices,
std::vector< std::vector< DistanceType > > &  dists,
size_t  knn,
const SearchParams params 
) const
inlinevirtual

Perform k-nearest neighbor search.

Parameters
[in]queriesThe query points for which to find the nearest neighbors
[out]indicesThe indices of the nearest neighbors found
[out]distsDistances to the nearest neighbors found
[in]knnNumber of nearest neighbors to return
[in]paramsSearch parameters

Reimplemented from rtflann::NNIndex< Distance >.

Definition at line 309 of file lsh_index.h.

◆ loadIndex()

template<typename Distance >
void rtflann::LshIndex< Distance >::loadIndex ( FILE *  stream)
inlinevirtual

Implements rtflann::IndexBase.

Definition at line 231 of file lsh_index.h.

◆ operator=()

template<typename Distance >
LshIndex& rtflann::LshIndex< Distance >::operator= ( LshIndex< Distance >  other)
inline

Definition at line 157 of file lsh_index.h.

◆ saveIndex()

template<typename Distance >
void rtflann::LshIndex< Distance >::saveIndex ( FILE *  stream)
inlinevirtual

Implements rtflann::IndexBase.

Definition at line 225 of file lsh_index.h.

◆ serialize()

template<typename Distance >
template<typename Archive >
void rtflann::LshIndex< Distance >::serialize ( Archive &  ar)
inline

Definition at line 204 of file lsh_index.h.

◆ swap()

template<typename Distance >
void rtflann::LshIndex< Distance >::swap ( LshIndex< Distance > &  other)
inlineprivate

Definition at line 550 of file lsh_index.h.

◆ usedMemory()

template<typename Distance >
int rtflann::LshIndex< Distance >::usedMemory ( ) const
inlinevirtual

Computes the index memory usage Returns: memory used by the index

Implements rtflann::IndexBase.

Definition at line 241 of file lsh_index.h.

Member Data Documentation

◆ key_size_

template<typename Distance >
unsigned int rtflann::LshIndex< Distance >::key_size_
private

key size

Definition at line 567 of file lsh_index.h.

◆ multi_probe_level_

template<typename Distance >
unsigned int rtflann::LshIndex< Distance >::multi_probe_level_
private

How far should we look for neighbors in multi-probe LSH

Definition at line 569 of file lsh_index.h.

◆ table_number_

template<typename Distance >
unsigned int rtflann::LshIndex< Distance >::table_number_
private

table number

Definition at line 565 of file lsh_index.h.

◆ tables_

template<typename Distance >
std::vector<lsh::LshTable<ElementType> > rtflann::LshIndex< Distance >::tables_
private

The different hash tables

Definition at line 562 of file lsh_index.h.

◆ xor_masks_

template<typename Distance >
std::vector<lsh::BucketKey> rtflann::LshIndex< Distance >::xor_masks_
private

The XOR masks to apply to a key to get the neighboring buckets

Definition at line 572 of file lsh_index.h.


The documentation for this class was generated from the following file:


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:29