template class cvflann::NNIndex

Overview

Nearest-neighbour index base class More…

#include <nn_index.h>

template <typename Distance>
class NNIndex
{
public:
    // methods

    virtual
    void
    buildIndex() = 0;

    virtual
    void
    findNeighbors(
        ResultSet<DistanceType>& result,
        const ElementType* vec,
        const SearchParams& searchParams
        ) = 0;

    virtual
    IndexParams
    getParameters() const = 0;

    virtual
    flann_algorithm_t
    getType() const = 0;

    virtual
    void
    knnSearch(
        const Matrix<ElementType>& queries,
        Matrix<int>& indices,
        Matrix<DistanceType>& dists,
        int knn,
        const SearchParams& params
        );

    virtual
    void
    loadIndex(FILE* stream) = 0;

    virtual
    int
    radiusSearch(
        const Matrix<ElementType>& query,
        Matrix<int>& indices,
        Matrix<DistanceType>& dists,
        float radius,
        const SearchParams& params
        );

    virtual
    void
    saveIndex(FILE* stream) = 0;

    virtual
    size_t
    size() const = 0;

    virtual
    int
    usedMemory() const = 0;

    virtual
    size_t
    veclen() const = 0;
};

// direct descendants

template <typename Distance>
class AutotunedIndex;

template <typename Distance>
class CompositeIndex;

template <typename Distance>
class HierarchicalClusteringIndex;

template <typename Distance>
class Index;

template <typename Distance>
class KDTreeIndex;

template <typename Distance>
class KDTreeSingleIndex;

template <typename Distance>
class KMeansIndex;

template <typename Distance>
class LinearIndex;

template <typename Distance>
class LshIndex;

Detailed Documentation

Nearest-neighbour index base class

Methods

virtual
void
buildIndex() = 0

Builds the index.

virtual
void
findNeighbors(
    ResultSet<DistanceType>& result,
    const ElementType* vec,
    const SearchParams& searchParams
    ) = 0

Method that searches for nearest-neighbours.

virtual
IndexParams
getParameters() const = 0

Returns:

The index parameters

virtual
flann_algorithm_t
getType() const = 0

Returns:

The index type (kdtree, kmeans,…)

virtual
void
knnSearch(
    const Matrix<ElementType>& queries,
    Matrix<int>& indices,
    Matrix<DistanceType>& dists,
    int knn,
    const SearchParams& params
    )

Perform k-nearest neighbor search.

Parameters:

queries The query points for which to find the nearest neighbors
indices The indices of the nearest neighbors found
dists Distances to the nearest neighbors found
knn Number of nearest neighbors to return
params Search parameters
virtual
void
loadIndex(FILE* stream) = 0

Loads the index from a stream.

Parameters:

stream The stream from which the index is loaded
virtual
int
radiusSearch(
    const Matrix<ElementType>& query,
    Matrix<int>& indices,
    Matrix<DistanceType>& dists,
    float radius,
    const SearchParams& params
    )

Perform radius search.

Parameters:

query The query point
indices The indinces of the neighbors found within the given radius
dists The distances to the nearest neighbors found
radius The radius used for search
params Search parameters

Returns:

Number of neighbors found

virtual
void
saveIndex(FILE* stream) = 0

Saves the index to a stream.

Parameters:

stream The stream to save the index to
virtual
size_t
size() const = 0

Returns:

number of features in this index.

virtual
int
usedMemory() const = 0

Returns:

The amount of memory (in bytes) used by the index.

virtual
size_t
veclen() const = 0

Returns:

The dimensionality of the features in this index.