#ifndef KNNARRAY_H #define KNNARRAY_H /** * this wrapper class provides all methods needed for nanoflanns KNN-search. * in order for this wrapper class to work, your data-structure must provide * the following methods: * * PointList: * size() - return the number of contained points * operator [] - access points via their index * Point * operator [] - access each dimension via its index * * example: * std::vector points; * KNNArray> arr(points); * KNN>, 3> knn(arr); */ template class KNNArray { private: /** the underlying data structure */ const T& elem; public: /** ctor with the underlying data structure */ KNNArray(const T& elem) : elem(elem) { ; } /** get the number of elements to search throrugh */ inline int kdtree_get_point_count() const { return elem.size(); } /** use nanoflanns default bbox */ template inline bool kdtree_get_bbox(BBOX& bb) const { (void) bb; return false; } /** get the idx-th element's dim-th coordinate */ inline float kdtree_get_pt(const size_t idx, const int dim) const { return elem[idx][dim]; } /** get the SQUARED distance between the given coordinates and the provided element */ inline float kdtree_distance(const float* p1, const size_t idx_p2, size_t) const { const float d0 = p1[0] - elem[idx_p2][0]; const float d1 = p1[1] - elem[idx_p2][1]; const float d2 = p1[2] - elem[idx_p2][2]; return (d0*d0) + (d1*d1) + (d2*d2); } }; #endif // KNNARRAY_H