58 static_cast<std::runtime_error&
>(*this) = std::runtime_error(ss.str());
68 template<
typename T,
typename CloudType>
71 dim(min(dim, int(cloud.rows()))),
72 creationOptionFlags(creationOptionFlags),
73 minBound(
Vector::Constant(this->dim, numeric_limits<T>::max())),
74 maxBound(
Vector::Constant(this->dim, numeric_limits<T>::min()))
76 if (cloud.cols() == 0)
78 if (cloud.rows() == 0)
82 template<
typename T,
typename CloudType>
86 const Eigen::Map<const Matrix> queryMatrix(&query.coeff(0,0), dim, 1);
88 const Eigen::Map<Matrix> queryMatrix(&query.coeff(0,0), dim, 1);
96 const unsigned long stats =
knn(queryMatrix, indexMatrix, dists2Matrix, k, epsilon, optionFlags, maxRadius);
97 indices = indexMatrix.col(0);
98 dists2 = dists2Matrix.col(0);
102 template<
typename T,
typename CloudType>
108 if (k >
cloud.cols())
109 throw runtime_error() <<
"Requesting more points (" << k <<
") than available in cloud (" <<
cloud.cols() <<
")";
113 if (k >
cloud.cols()-1)
114 throw runtime_error() <<
"Requesting more points (" << k <<
") than available in cloud minus 1 (" <<
cloud.cols()-1 <<
") (as self match is forbidden)";
116 if (query.rows() < dim)
117 throw runtime_error() <<
"Query has less dimensions (" << query.rows() <<
") than requested for cloud (" << dim <<
")";
118 if (indices.rows() != k)
119 throw runtime_error() <<
"Index matrix has a different number of rows (" << indices.rows() <<
") than k (" << k <<
")";
120 if (indices.cols() != query.cols())
121 throw runtime_error() <<
"Index matrix has a different number of columns (" << indices.rows() <<
") than query (" << query.cols() <<
")";
122 if (dists2.rows() != k)
123 throw runtime_error() <<
"Distance matrix has a different number of rows (" << dists2.rows() <<
") than k (" << k <<
")";
124 if (dists2.cols() != query.cols())
125 throw runtime_error() <<
"Distance matrix has a different number of columns (" << dists2.rows() <<
") than query (" << query.cols() <<
")";
126 if (maxRadii && (maxRadii->size() != query.cols()))
127 throw runtime_error() <<
"Maximum radii vector has not the same length (" << maxRadii->size() <<
") than query has columns (" << k <<
")";
128 const unsigned maxOptionFlagsValue(ALLOW_SELF_MATCH|SORT_RESULTS);
129 if (optionFlags > maxOptionFlagsValue)
130 throw runtime_error() <<
"OR-ed value of option flags (" << optionFlags <<
") is larger than maximal valid value (" << maxOptionFlagsValue <<
")";
134 template<
typename T,
typename CloudType>
138 throw runtime_error() <<
"Your space must have at least one dimension";
139 switch (preferedType)
145 case KDTREE_CL_PT_IN_NODES:
return new KDTreeBalancedPtInNodesStackOpenCL<T, CloudType>(
cloud, dim, creationOptionFlags, CL_DEVICE_TYPE_GPU);
146 case KDTREE_CL_PT_IN_LEAVES:
return new KDTreeBalancedPtInLeavesStackOpenCL<T, CloudType>(
cloud, dim, creationOptionFlags, CL_DEVICE_TYPE_GPU);
147 case BRUTE_FORCE_CL:
return new BruteForceSearchOpenCL<T, CloudType>(
cloud, dim, creationOptionFlags, CL_DEVICE_TYPE_GPU);
149 case KDTREE_CL_PT_IN_NODES:
throw runtime_error() <<
"OpenCL not found during compilation";
150 case KDTREE_CL_PT_IN_LEAVES:
throw runtime_error() <<
"OpenCL not found during compilation";
151 case BRUTE_FORCE_CL:
throw runtime_error() <<
"OpenCL not found during compilation";
152 #endif // HAVE_OPENCL 157 template<
typename T,
typename CloudType>
161 throw runtime_error() <<
"Your space must have at least one dimension";
165 template<
typename T,
typename CloudType>
169 throw runtime_error() <<
"Your space must have at least one dimension";
173 template<
typename T,
typename CloudType>
177 throw runtime_error() <<
"Your space must have at least one dimension";
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 ...
KDTree, unbalanced, points in leaves, stack, implicit bounds, ANN_KD_SL_MIDPT, optimised implementati...
tuple knn(const object query, const Index k=1, const double epsilon=0, const unsigned optionFlags=0, const double maxRadius=infD)
implementation of index heaps
Nearest neighbour search interface, templatized on scalar type.
runtime_error(const runtime_error &re)
runtime_error & operator<<(const T &t)
NearestNeighbourSearch(const CloudType &cloud, const Index dim, const unsigned creationOptionFlags)
constructor
Eigen::Matrix< T, Eigen::Dynamic, 1 > Vector
an Eigen vector of type T, to hold the coordinates of a point
int Index
an index to a Vector or a Matrix, for refering to data points
Eigen::Matrix< Index, Eigen::Dynamic, Eigen::Dynamic > IndexMatrix
a matrix of indices to data points
Brute-force nearest neighbour.
Eigen::Matrix< Index, Eigen::Dynamic, 1 > IndexVector
a vector of indices to data points
CloudType CloudType
a column-major Eigen matrix in which each column is a point; this matrix has dim rows ...
header for implementation