Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef OPENCV_FLANN_LINEAR_INDEX_H_
00032 #define OPENCV_FLANN_LINEAR_INDEX_H_
00033
00034 #include "general.h"
00035 #include "nn_index.h"
00036
00037 namespace cvflann
00038 {
00039
00040 struct LinearIndexParams : public IndexParams
00041 {
00042 LinearIndexParams()
00043 {
00044 (* this)["algorithm"] = FLANN_INDEX_LINEAR;
00045 }
00046 };
00047
00048 template <typename Distance>
00049 class LinearIndex : public NNIndex<Distance>
00050 {
00051 public:
00052
00053 typedef typename Distance::ElementType ElementType;
00054 typedef typename Distance::ResultType DistanceType;
00055
00056
00057 LinearIndex(const Matrix<ElementType>& inputData, const IndexParams& params = LinearIndexParams(),
00058 Distance d = Distance()) :
00059 dataset_(inputData), index_params_(params), distance_(d)
00060 {
00061 }
00062
00063 LinearIndex(const LinearIndex&);
00064 LinearIndex& operator=(const LinearIndex&);
00065
00066 flann_algorithm_t getType() const
00067 {
00068 return FLANN_INDEX_LINEAR;
00069 }
00070
00071
00072 size_t size() const
00073 {
00074 return dataset_.rows;
00075 }
00076
00077 size_t veclen() const
00078 {
00079 return dataset_.cols;
00080 }
00081
00082
00083 int usedMemory() const
00084 {
00085 return 0;
00086 }
00087
00088 void buildIndex()
00089 {
00090
00091 }
00092
00093 void saveIndex(FILE*)
00094 {
00095
00096 }
00097
00098
00099 void loadIndex(FILE*)
00100 {
00101
00102
00103 index_params_["algorithm"] = getType();
00104 }
00105
00106 void findNeighbors(ResultSet<DistanceType>& resultSet, const ElementType* vec, const SearchParams& )
00107 {
00108 ElementType* data = dataset_.data;
00109 for (size_t i = 0; i < dataset_.rows; ++i, data += dataset_.cols) {
00110 DistanceType dist = distance_(data, vec, dataset_.cols);
00111 resultSet.addPoint(dist, (int)i);
00112 }
00113 }
00114
00115 IndexParams getParameters() const
00116 {
00117 return index_params_;
00118 }
00119
00120 private:
00122 const Matrix<ElementType> dataset_;
00124 IndexParams index_params_;
00126 Distance distance_;
00127
00128 };
00129
00130 }
00131
00132 #endif // OPENCV_FLANN_LINEAR_INDEX_H_