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 RTABMAP_FLANN_LINEAR_INDEX_H_
00032 #define RTABMAP_FLANN_LINEAR_INDEX_H_
00033
00034 #include "rtflann/general.h"
00035 #include "nn_index.h"
00036
00037 namespace rtflann
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 typedef NNIndex<Distance> BaseClass;
00057
00058 LinearIndex(const IndexParams& params = LinearIndexParams(), Distance d = Distance()) :
00059 BaseClass(params, d)
00060 {
00061 }
00062
00063 LinearIndex(const Matrix<ElementType>& input_data, const IndexParams& params = LinearIndexParams(), Distance d = Distance()) :
00064 BaseClass(params, d)
00065 {
00066 setDataset(input_data);
00067 }
00068
00069 LinearIndex(const LinearIndex& other) : BaseClass(other)
00070 {
00071 }
00072
00073 LinearIndex& operator=(LinearIndex other)
00074 {
00075 this->swap(other);
00076 return *this;
00077 }
00078
00079 virtual ~LinearIndex()
00080 {
00081 }
00082
00083 BaseClass* clone() const
00084 {
00085 return new LinearIndex(*this);
00086 }
00087
00088 void addPoints(const Matrix<ElementType>& points, float rebuild_threshold = 2)
00089 {
00090 assert(points.cols==veclen_);
00091 extendDataset(points);
00092 }
00093
00094 flann_algorithm_t getType() const
00095 {
00096 return FLANN_INDEX_LINEAR;
00097 }
00098
00099
00100 int usedMemory() const
00101 {
00102 return 0;
00103 }
00104
00105 template<typename Archive>
00106 void serialize(Archive& ar)
00107 {
00108 ar.setObject(this);
00109
00110 ar & *static_cast<NNIndex<Distance>*>(this);
00111
00112 if (Archive::is_loading::value) {
00113 index_params_["algorithm"] = getType();
00114 }
00115 }
00116
00117 void saveIndex(FILE* stream)
00118 {
00119 serialization::SaveArchive sa(stream);
00120 sa & *this;
00121 }
00122
00123 void loadIndex(FILE* stream)
00124 {
00125 serialization::LoadArchive la(stream);
00126 la & *this;
00127 }
00128
00129 void findNeighbors(ResultSet<DistanceType>& resultSet, const ElementType* vec, const SearchParams& ) const
00130 {
00131 if (removed_) {
00132 for (size_t i = 0; i < points_.size(); ++i) {
00133 if (removed_points_.test(i)) continue;
00134 DistanceType dist = distance_(points_[i], vec, veclen_);
00135 resultSet.addPoint(dist, i);
00136 }
00137 }
00138 else {
00139 for (size_t i = 0; i < points_.size(); ++i) {
00140 DistanceType dist = distance_(points_[i], vec, veclen_);
00141 resultSet.addPoint(dist, i);
00142 }
00143 }
00144 }
00145 protected:
00146 void buildIndexImpl()
00147 {
00148
00149 }
00150
00151 void freeIndex()
00152 {
00153
00154 }
00155
00156 private:
00157
00158 USING_BASECLASS_SYMBOLS
00159 };
00160
00161 }
00162
00163 #endif // FLANN_LINEAR_INDEX_H_