| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #ifndef FLANN_KDTREE_CUDA_3D_INDEX_H_ |
| | #define FLANN_KDTREE_CUDA_3D_INDEX_H_ |
| |
|
| | #include <algorithm> |
| | #include <map> |
| | #include <cassert> |
| | #include <cstring> |
| | #include "FLANN/general.h" |
| | #include "FLANN/algorithms/nn_index.h" |
| | #include "FLANN/util/matrix.h" |
| | #include "FLANN/util/result_set.h" |
| | #include "FLANN/util/heap.h" |
| | #include "FLANN/util/allocator.h" |
| | #include "FLANN/util/random.h" |
| | #include "FLANN/util/saving.h" |
| | #include "FLANN/util/params.h" |
| |
|
| | namespace flann |
| | { |
| |
|
| | struct KDTreeCuda3dIndexParams : public IndexParams |
| | { |
| | KDTreeCuda3dIndexParams( int leaf_max_size = 64 ) |
| | { |
| | (*this)["algorithm"] = FLANN_INDEX_KDTREE_CUDA; |
| | (*this)["leaf_max_size"] = leaf_max_size; |
| | (*this)["dim"] = 3; |
| | } |
| | }; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | template <typename Distance> |
| | class KDTreeCuda3dIndex : public NNIndex<Distance> |
| | { |
| | public: |
| | typedef typename Distance::ElementType ElementType; |
| | typedef typename Distance::ResultType DistanceType; |
| |
|
| | typedef NNIndex<Distance> BaseClass; |
| |
|
| | int visited_leafs; |
| |
|
| | typedef bool needs_kdtree_distance; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | KDTreeCuda3dIndex(const Matrix<ElementType>& inputData, const IndexParams& params = KDTreeCuda3dIndexParams(), |
| | Distance d = Distance() ) : BaseClass(params,d), dataset_(inputData), leaf_count_(0), visited_leafs(0), node_count_(0), current_node_count_(0) |
| | { |
| | size_ = dataset_.rows; |
| | dim_ = dataset_.cols; |
| |
|
| | int dim_param = get_param(params,"dim",-1); |
| | if (dim_param>0) dim_ = dim_param; |
| | leaf_max_size_ = get_param(params,"leaf_max_size",10); |
| | assert( dim_ == 3 ); |
| | gpu_helper_=0; |
| | } |
| |
|
| | KDTreeCuda3dIndex(const KDTreeCuda3dIndex& other); |
| | KDTreeCuda3dIndex operator=(KDTreeCuda3dIndex other); |
| |
|
| | |
| | |
| | |
| | ~KDTreeCuda3dIndex() |
| | { |
| | delete[] data_.ptr(); |
| | clearGpuBuffers(); |
| | } |
| |
|
| | BaseClass* clone() const |
| | { |
| | throw FLANNException("KDTreeCuda3dIndex cloning is not implemented"); |
| | } |
| |
|
| | |
| | |
| | |
| | void buildIndex() |
| | { |
| | |
| | vind_.resize(size_); |
| | for (size_t i = 0; i < size_; i++) { |
| | vind_[i] = i; |
| | } |
| |
|
| | leaf_count_=0; |
| | node_count_=0; |
| | |
| | |
| | |
| |
|
| | delete[] data_.ptr(); |
| |
|
| | uploadTreeToGpu(); |
| | } |
| |
|
| | flann_algorithm_t getType() const |
| | { |
| | return FLANN_INDEX_KDTREE_SINGLE; |
| | } |
| |
|
| |
|
| | void removePoint(size_t index) |
| | { |
| | throw FLANNException( "removePoint not implemented for this index type!" ); |
| | } |
| |
|
| | ElementType* getPoint(size_t id) |
| | { |
| | return dataset_[id]; |
| | } |
| |
|
| | void saveIndex(FILE* stream) |
| | { |
| | throw FLANNException( "Index saving not implemented!" ); |
| |
|
| | } |
| |
|
| |
|
| | void loadIndex(FILE* stream) |
| | { |
| | throw FLANNException( "Index loading not implemented!" ); |
| | } |
| |
|
| | size_t veclen() const |
| | { |
| | return dim_; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | int usedMemory() const |
| | { |
| | |
| | return 0; |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | int knnSearch(const Matrix<ElementType>& queries, Matrix<int>& indices, Matrix<DistanceType>& dists, size_t knn, const SearchParams& params) const |
| | { |
| | knnSearchGpu(queries,indices, dists, knn, params); |
| | return knn*queries.rows; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | 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 |
| | { |
| | knnSearchGpu(queries,indices, dists, knn, params); |
| | return knn*queries.rows; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | void knnSearchGpu(const Matrix<ElementType>& queries, Matrix<int>& indices, Matrix<DistanceType>& dists, size_t knn, const SearchParams& params) const; |
| |
|
| | int knnSearchGpu(const Matrix<ElementType>& queries, |
| | std::vector< std::vector<int> >& indices, |
| | std::vector<std::vector<DistanceType> >& dists, |
| | size_t knn, |
| | const SearchParams& params) const |
| | { |
| | flann::Matrix<int> ind( new int[knn*queries.rows], queries.rows,knn); |
| | flann::Matrix<DistanceType> dist( new DistanceType[knn*queries.rows], queries.rows,knn); |
| | knnSearchGpu(queries,ind,dist,knn,params); |
| | for( size_t i = 0; i<queries.rows; i++ ) { |
| | indices[i].resize(knn); |
| | dists[i].resize(knn); |
| | for( size_t j=0; j<knn; j++ ) { |
| | indices[i][j]=ind[i][j]; |
| | dists[i][j]=dist[i][j]; |
| | } |
| | } |
| | delete [] ind.ptr(); |
| | delete [] dist.ptr(); |
| | return knn*queries.rows; |
| | } |
| |
|
| | int radiusSearch(const Matrix<ElementType>& queries, Matrix<int>& indices, Matrix<DistanceType>& dists, |
| | float radius, const SearchParams& params) const |
| | { |
| | return radiusSearchGpu(queries,indices, dists, radius, params); |
| | } |
| |
|
| | int radiusSearch(const Matrix<ElementType>& queries, std::vector< std::vector<int> >& indices, |
| | std::vector<std::vector<DistanceType> >& dists, float radius, const SearchParams& params) const |
| | { |
| | return radiusSearchGpu(queries,indices, dists, radius, params); |
| | } |
| |
|
| | int radiusSearchGpu(const Matrix<ElementType>& queries, Matrix<int>& indices, Matrix<DistanceType>& dists, |
| | float radius, const SearchParams& params) const; |
| |
|
| | int radiusSearchGpu(const Matrix<ElementType>& queries, std::vector< std::vector<int> >& indices, |
| | std::vector<std::vector<DistanceType> >& dists, float radius, const SearchParams& params) const; |
| |
|
| | |
| | |
| | |
| | |
| | void findNeighbors(ResultSet<DistanceType>& result, const ElementType* vec, const SearchParams& searchParams) const |
| | { |
| | } |
| |
|
| | protected: |
| | void buildIndexImpl() |
| | { |
| | |
| | } |
| |
|
| | void freeIndex() |
| | { |
| | |
| | } |
| |
|
| | private: |
| |
|
| | void uploadTreeToGpu( ); |
| |
|
| | void clearGpuBuffers( ); |
| |
|
| |
|
| |
|
| |
|
| | private: |
| |
|
| | struct GpuHelper; |
| |
|
| | GpuHelper* gpu_helper_; |
| |
|
| | const Matrix<ElementType> dataset_; |
| |
|
| | int leaf_max_size_; |
| |
|
| | int leaf_count_; |
| | int node_count_; |
| | |
| | int current_node_count_; |
| |
|
| |
|
| | |
| | |
| | |
| | std::vector<int> vind_; |
| |
|
| | Matrix<ElementType> data_; |
| |
|
| | size_t dim_; |
| |
|
| | USING_BASECLASS_SYMBOLS |
| | }; |
| |
|
| |
|
| | } |
| |
|
| | #endif |
| |
|