35 #ifndef SHARK_ALGORITHMS_NEARESTNEIGHBORS_KHCTREE_H 36 #define SHARK_ALGORITHMS_NEARESTNEIGHBORS_KHCTREE_H 41 #include <boost/array.hpp> 73 template <
class Container,
int CuttingAccuracy = 25>
78 typedef typename Container::value_type value_type;
89 : base_type(points.
size())
95 std::vector<const_iterator> elements(
m_size);
102 for(std::size_t i = 0; i !=
m_size; ++i){
117 double v = p->distanceFromPlane(reference);
118 if (t == p->mp_right)
123 p = (
KHCTree const*)p->mep_parent;
125 return (dist * dist);
138 : base_type(parent, list, size)
145 template<
class Range>
147 typedef typename Range::iterator range_iterator;
158 if (
m_size <= CuttingAccuracy){
162 boost::array<const_iterator,CuttingAccuracy> samples;
163 for(std::size_t i = 0; i != CuttingAccuracy; i++)
164 samples[i] = points[
m_size * (2*i+1) / (2*CuttingAccuracy)];
169 std::vector<double> distance(
m_size);
170 for(std::size_t i = 0; i !=
m_size; ++i){
171 distance[i] =
funct(*points[i]);
176 range_iterator split = this->
splitList(distance,points);
177 range_iterator begin = boost::begin(points);
178 range_iterator end = boost::end(points);
186 std::size_t leftSize = split-begin;
191 boost::iterator_range<range_iterator>
left(begin,split);
192 boost::iterator_range<range_iterator>
right(split,end);
198 template<
class Range>
200 std::size_t numSamples =
batchSize(samples);
201 double best_dist2 = -1.0;
202 for (std::size_t i=1; i != numSamples; i++){
203 for (std::size_t j = 0; j != i; j++){
205 if (dist2 > best_dist2){
220 double funct(value_type
const& reference)
const{