1 #ifndef __GfxTL_NEARESTNEIGHBORS_HEADER__
2 #define __GfxTL_NEARESTNEIGHBORS_HEADER__
8 template<
class Scalar,
class HandleT =
size_t >
56 template<
class NN,
class NNs >
79 intptr_t low = 0, high = n->size() - 1,
index = 0, mid;
84 mid = (low + high) >> 1;
97 n->insert(n->begin() +
index, nn);
100 if ((*n)[k] > (*n)[k - 1])
116 template<
class NNs,
class ScalarType >
118 ScalarType* worstDist)
122 *worstDist = n[j].sqrDist;
124 for (; j < size; ++j)
126 if (n[j].sqrDist > *worstDist)
128 *worstDist = n[j].sqrDist;
134 template<
class Po
int,
class Po
ints >
136 const Points& points,
size_t size,
143 typedef typename Points::size_type size_type;
146 ScalarType worstDist = 0;
148 for (; i < size && i < k; ++i)
151 n->push_back(
NN(i, diff * diff));
152 if (n->back().sqrDist > worstDist)
154 worstDist = n->back().sqrDist;
155 worst = n->size() - 1;
159 for (i = k; i < size; ++i)
162 ScalarType dist = diff * diff;
163 if (dist < worstDist)
165 (*n)[worst] =
NN(i, dist);
171 template<
class Po
int,
class Po
ints,
template<
class >
class ContainerT,
174 const Points& points,
size_t size,
179 for (
size_t i = 0; i < size; ++i)
181 NN nn(p.SqrDistance(points[i]), i);
182 neighbors->PushHeap(nn);
186 template<
class Po
int,
class Po
ints,
template<
class >
class ContainerT,
189 const Points& points,
size_t size,
194 for (
size_t i = 0; i < size; ++i)
196 NN nn(p.L1Distance(points[i]), i);
197 neighbors->PushHeap(nn);