32 #ifndef __NABO_PRIVATE_H
33 #define __NABO_PRIVATE_H
38 #include <boost/cstdint.hpp>
39 using boost::uint32_t;
42 #endif // BOOST_STDINT
46 #define __CL_ENABLE_EXCEPTIONS
52 #define _UNUSED __attribute__ ((unused))
68 template<
typename T,
typename A,
typename B>
69 inline T
dist2(
const A& v0,
const B& v1)
71 return (v0 - v1).squaredNorm();
92 virtual unsigned long knn(
const Matrix& query,
IndexMatrix& indices,
Matrix& dists2,
const Index k,
const T epsilon,
const unsigned optionFlags,
const T maxRadius)
const;
93 virtual unsigned long knn(
const Matrix& query,
IndexMatrix& indices,
Matrix& dists2,
const Vector& maxRadii,
const Index k = 1,
const T epsilon = 0,
const unsigned optionFlags = 0)
const;
97 template<
typename T,
typename Heap>
133 inline uint32_t
getDim(
const uint32_t dimChildBucketSize)
const
134 {
return dimChildBucketSize &
dimMask; }
201 unsigned long onePointKnn(
const Matrix& query,
IndexMatrix& indices,
Matrix& dists2,
int i, Heap& heap, std::vector<T>& off,
const T maxError,
const T maxRadius2,
const bool allowSelfMatch,
const bool collectStatistics,
const bool sortResults)
const;
212 template<
bool allowSelfMatch,
bool collectStatistics>
213 unsigned long recurseKnn(
const T* query,
const unsigned n, T rd, Heap& heap, std::vector<T>& off,
const T maxError,
const T maxRadius2)
const;
218 virtual unsigned long knn(
const Matrix& query,
IndexMatrix& indices,
Matrix& dists2,
const Index k,
const T epsilon,
const unsigned optionFlags,
const T maxRadius)
const;
219 virtual unsigned long knn(
const Matrix& query,
IndexMatrix& indices,
Matrix& dists2,
const Vector& maxRadii,
const Index k = 1,
const T epsilon = 0,
const unsigned optionFlags = 0)
const;
253 void initOpenCL(
const char* clFileName,
const char* kernelName,
const std::string& additionalDefines =
"");
256 virtual unsigned long knn(
const Matrix& query,
IndexMatrix& indices,
Matrix& dists2,
const Index k,
const T epsilon,
const unsigned optionFlags,
const T maxRadius)
const;
335 inline size_t childLeft(
size_t pos)
const {
return 2*pos + 1; }
336 inline size_t childRight(
size_t pos)
const {
return 2*pos + 2; }
337 inline size_t parent(
size_t pos)
const {
return (pos-1)/2; }
406 inline size_t childLeft(
size_t pos)
const {
return 2*pos + 1; }
407 inline size_t childRight(
size_t pos)
const {
return 2*pos + 2; }
408 inline size_t parent(
size_t pos)
const {
return (pos-1)/2; }
420 #endif // HAVE_OPENCL
CompareDim(const size_t dim)
Build the functor for a specific dimension.
Definition: nabo_private.h:315
size_t childLeft(size_t pos) const
Return the left child of pos.
Definition: nabo_private.h:335
Eigen::Matrix< Index, Eigen::Dynamic, 1 > IndexVector
a vector of indices to data points
Definition: nabo.h:254
unsigned long recurseKnn(const T *query, const unsigned n, T rd, Heap &heap, std::vector< T > &off, const T maxError, const T maxRadius2) const
recursive search, strongly inspired by ANN and [Arya & Mount, Algorithms for fast vector quantization...
Definition: kdtree_cpu.cpp:354
uint32_t getChildBucketSize(const uint32_t dimChildBucketSize) const
get the child index or the bucket size out of the coumpount index
Definition: nabo_private.h:136
CompareDim(const Matrix &cloud, const size_t dim)
Build the functor for a specific dimension on a specific cloud.
Definition: nabo_private.h:386
OpenCL support for nearest neighbour search.
Definition: nabo_private.h:226
KDTree, unbalanced, points in leaves, stack, implicit bounds, ANN_KD_SL_MIDPT, optimised implementati...
Definition: nabo_private.h:98
size_t childRight(size_t pos) const
Return the right child of pos.
Definition: nabo_private.h:336
virtual unsigned long knn(const Matrix &query, IndexMatrix &indices, Matrix &dists2, const Index k, const T epsilon, const unsigned optionFlags, const T maxRadius) const
Find the k nearest neighbours for each point of query.
Definition: kdtree_cpu.cpp:274
const Index dim
the dimensionality of the data-point cloud
Definition: nabo.h:261
KDTreeBalancedPtInNodesStackOpenCL(const Matrix &cloud, const Index dim, const unsigned creationOptionFlags, const cl_device_type deviceType)
constructor, calls OpenCLSearch<T>(cloud, ...)
Definition: kdtree_opencl.cpp:622
std::vector< BucketEntry > Buckets
bucket data
Definition: nabo_private.h:175
KDTree, balanced, points in nodes, stack, implicit bounds, balance aspect ratio.
Definition: nabo_private.h:351
size_t dim
dimension on which to compare
Definition: nabo_private.h:313
virtual unsigned long knn(const Matrix &query, IndexMatrix &indices, Matrix &dists2, const Index k, const T epsilon, const unsigned optionFlags, const T maxRadius) const
Find the k nearest neighbours for each point of query.
Definition: brute_force_cpu.cpp:64
size_t parent(size_t pos) const
Return the parent of pos.
Definition: nabo_private.h:408
size_t childRight(size_t pos) const
Return the right child of pos.
Definition: nabo_private.h:407
BuildPoints::iterator BuildPointsIt
iterator to points during kd-tree construction
Definition: nabo_private.h:376
BuildPoints::iterator BuildPointsIt
iterator to points during kd-tree construction
Definition: nabo_private.h:306
Eigen::Matrix< Index, Eigen::Dynamic, Eigen::Dynamic > IndexMatrix
a matrix of indices to data points
Definition: nabo.h:256
Nodes nodes
search nodes
Definition: nabo_private.h:331
Nearest neighbour search interface, templatized on scalar type.
Definition: nabo.h:245
cl::Buffer nodesCL
CL buffer for search nodes.
Definition: nabo_private.h:332
cl::Context & context
the CL context
Definition: nabo_private.h:241
size_t getTreeSize(size_t size) const
Return the storage size of tree of a given size.
Definition: kdtree_opencl.cpp:542
cl::Buffer nodesCL
CL buffer for search nodes.
Definition: nabo_private.h:403
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > Matrix
a column-major Eigen matrix in which each column is a point; this matrix has dim rows ...
Definition: nabo.h:250
BuildPoints::const_iterator BuildPointsCstIt
const-iterator to indices of points during kd-tree construction
Definition: nabo_private.h:119
uint32_t createDimChildBucketSize(const uint32_t dim, const uint32_t childIndex) const
create the compound index containing the dimension and the index of the child or the bucket size ...
Definition: nabo_private.h:130
BucketEntry(const T *pt=0, const Index index=0)
create a new bucket entry for a point in the data
Definition: nabo_private.h:171
void buildNodes(const BuildPointsIt first, const BuildPointsIt last, const size_t pos, const Vector minValues, const Vector maxValues)
Recurse to build nodes.
Definition: kdtree_opencl.cpp:572
uint32_t dimChildBucketSize
cut dimension for split nodes (dimBitCount lsb), index of right node or number of bucket(rest)...
Definition: nabo_private.h:144
Node(const int dim=-2, const Index index=0)
Build a tree node, with a given index and a given dimension to cut on.
Definition: nabo_private.h:397
T cutVal
for split node, split value
Definition: nabo_private.h:147
const unsigned bucketSize
size of bucket
Definition: nabo_private.h:122
int dim
dimension of the cut, or, if negative, index of the point: -1 == invalid, <= -2 = index of pt ...
Definition: nabo_private.h:323
const unsigned creationOptionFlags
creation options
Definition: nabo.h:263
KDTreeBalancedPtInLeavesStackOpenCL(const Matrix &cloud, const Index dim, const unsigned creationOptionFlags, const cl_device_type deviceType)
constructor, calls OpenCLSearch<T>(cloud, ...)
Definition: kdtree_opencl.cpp:499
Node(const uint32_t dimChild, const T cutVal)
construct a split node
Definition: nabo_private.h:152
T cutVal
value of the cut
Definition: nabo_private.h:324
KDTree, balanced, points in leaves, stack, implicit bounds, balance aspect ratio. ...
Definition: nabo_private.h:261
int Index
an index to a Vector or a Matrix, for refering to data points
Definition: nabo.h:252
Nodes nodes
search nodes
Definition: nabo_private.h:402
const uint32_t dimBitCount
number of bits required to store dimension index + number of dimensions
Definition: nabo_private.h:125
bool operator()(const BuildPoint &p0, const BuildPoint &p1)
Compare the values of p0 and p1 on dim, and return whether p0[dim] < p1[dim].
Definition: nabo_private.h:388
Index index
index of point
Definition: nabo_private.h:165
BruteForceSearch(const Matrix &cloud, const Index dim, const unsigned creationOptionFlags)
constructor, calls NearestNeighbourSearch<T>(cloud)
Definition: brute_force_cpu.cpp:45
virtual unsigned long knn(const Matrix &query, IndexMatrix &indices, Matrix &dists2, const Index k, const T epsilon, const unsigned optionFlags, const T maxRadius) const
Find the k nearest neighbours for each point of query.
Definition: kdtree_opencl.cpp:323
std::vector< Node > Nodes
dense vector of search nodes, provides better memory performances than many small objects ...
Definition: nabo_private.h:159
Functor to compare point values on a given dimension.
Definition: nabo_private.h:311
KDTreeUnbalancedPtInLeavesImplicitBoundsStackOpt(const Matrix &cloud, const Index dim, const unsigned creationOptionFlags, const Parameters &additionalParameters)
constructor, calls NearestNeighbourSearch<T>(cloud)
Definition: kdtree_cpu.cpp:228
const Matrix & cloud
reference to data points used to compare
Definition: nabo_private.h:383
void initOpenCL(const char *clFileName, const char *kernelName, const std::string &additionalDefines="")
Initialize CL support.
Definition: kdtree_opencl.cpp:225
Brute-force nearest neighbour.
Definition: nabo_private.h:76
Nodes nodes
search nodes
Definition: nabo_private.h:178
int dim
dimension of the cut, or, if -1 == leaf, -2 == invalid
Definition: nabo_private.h:394
unsigned buildNodes(const BuildPointsIt first, const BuildPointsIt last, const Vector minValues, const Vector maxValues)
construct nodes for points [first..last[ inside the hyperrectangle [minValues..maxValues] ...
Definition: kdtree_cpu.cpp:110
const cl_device_type deviceType
the type of device to run CL code on (CL_DEVICE_TYPE_CPU or CL_DEVICE_TYPE_GPU)
Definition: nabo_private.h:240
size_t parent(size_t pos) const
Return the parent of pos.
Definition: nabo_private.h:337
uint32_t bucketIndex
for leaf node, pointer to bucket
Definition: nabo_private.h:148
Parameter vector.
Definition: nabo.h:218
const uint32_t dimMask
mask to access dim
Definition: nabo_private.h:127
BuildPoints::const_iterator BuildPointsCstIt
const-iterator to points during kd-tree construction
Definition: nabo_private.h:378
BuildPoint(const Vector &pos=Vector(), const size_t index=0)
Construct a build point, at a given pos with a specific index.
Definition: nabo_private.h:301
OpenCLSearch(const Matrix &cloud, const Index dim, const unsigned creationOptionFlags, const cl_device_type deviceType)
constructor, calls NearestNeighbourSearch<T>(cloud)
Definition: kdtree_opencl.cpp:217
std::vector< BuildPoint > BuildPoints
points during kd-tree construction
Definition: nabo_private.h:374
BuildPoints::const_iterator BuildPointsCstIt
const-iterator to points during kd-tree construction
Definition: nabo_private.h:308
bool operator()(const BuildPoint &p0, const BuildPoint &p1)
Compare the values of p0 and p1 on dim, and return whether p0[dim] < p1[dim].
Definition: nabo_private.h:317
std::vector< Index > BuildPoints
indices of points during kd-tree construction
Definition: nabo_private.h:115
unsigned long onePointKnn(const Matrix &query, IndexMatrix &indices, Matrix &dists2, int i, Heap &heap, std::vector< T > &off, const T maxError, const T maxRadius2, const bool allowSelfMatch, const bool collectStatistics, const bool sortResults) const
search one point, call recurseKnn with the correct template parameters
Definition: kdtree_cpu.cpp:325
Point during kd-tree construction.
Definition: nabo_private.h:296
BuildPoints::iterator BuildPointsIt
iterator to indices of points during kd-tree construction
Definition: nabo_private.h:117
cl::Kernel knnKernel
the kernel to perform knnSearch, mutable because it is stateful, but conceptually const ...
Definition: nabo_private.h:242
cl::CommandQueue queue
the command queue
Definition: nabo_private.h:243
size_t index
index of point in cloud
Definition: nabo_private.h:299
void buildNodes(const BuildPointsIt first, const BuildPointsIt last, const size_t pos, const Vector minValues, const Vector maxValues)
Recurse to build nodes.
Definition: kdtree_opencl.cpp:457
size_t childLeft(size_t pos) const
Return the left child of pos.
Definition: nabo_private.h:406
size_t getTreeSize(size_t size) const
Return the storage size of tree of a given size.
Definition: kdtree_opencl.cpp:422
size_t dim
dimension on which to compare
Definition: nabo_private.h:384
Functor to compare point values on a given dimension.
Definition: nabo_private.h:381
std::vector< Node > Nodes
dense vector of search nodes
Definition: nabo_private.h:400
KDTree, balanced, points in leaves, stack, implicit bounds, balance aspect ratio. ...
Definition: nabo_private.h:275
Node(const uint32_t bucketSize, const uint32_t bucketIndex)
construct a leaf node
Definition: nabo_private.h:155
Index BuildPoint
a point during kd-tree construction is just its index
Definition: nabo_private.h:372
Index index
index of the point to cut
Definition: nabo_private.h:395
BruteForceSearchOpenCL(const Matrix &cloud, const Index dim, const unsigned creationOptionFlags, const cl_device_type deviceType)
constructor, calls OpenCLSearch<T>(cloud, ...)
Definition: kdtree_opencl.cpp:397
Buckets buckets
buckets
Definition: nabo_private.h:181
Tree node for CL.
Definition: nabo_private.h:392
cl::Buffer cloudCL
the buffer for the input data
Definition: nabo_private.h:244
T dist2(const A &v0, const B &v1)
Euclidean distance.
Definition: nabo_private.h:69
entry in a bucket
Definition: nabo_private.h:162
Tree node for CL.
Definition: nabo_private.h:321
size_t getTreeDepth(size_t size) const
Return the max depth of a tree of a given size.
Definition: kdtree_opencl.cpp:442
Eigen::Matrix< T, Eigen::Dynamic, 1 > Vector
an Eigen vector of type T, to hold the coordinates of a point
Definition: nabo.h:248
const Matrix & cloud
the reference to the data-point cloud, which must remain valid during the lifetime of the NearestNeig...
Definition: nabo.h:259
Node(const int dim=-1, const T cutVal=0)
Build a tree node, with a given dimension and value to cut on, or, if leaf and dim <= -2...
Definition: nabo_private.h:326
uint32_t getDim(const uint32_t dimChildBucketSize) const
get the dimension out of the compound index
Definition: nabo_private.h:133
Vector pos
point
Definition: nabo_private.h:298
std::vector< BuildPoint > BuildPoints
points during kd-tree construction
Definition: nabo_private.h:304
size_t getTreeDepth(size_t size) const
Return the max depth of a tree of a given size.
Definition: kdtree_opencl.cpp:559
std::pair< T, T > getBounds(const BuildPointsIt first, const BuildPointsIt last, const unsigned dim)
return the bounds of points from [first..last[ on dimension dim
Definition: kdtree_cpu.cpp:94
search node
Definition: nabo_private.h:142
std::vector< Node > Nodes
dense vector of search nodes
Definition: nabo_private.h:329
const T * pt
pointer to first value of point data, 0 if end of bucket
Definition: nabo_private.h:164