Go to the documentation of this file. 1 #ifndef __GfxTL_NEARESTNEIGHBORS_HEADER__
2 #define __GfxTL_NEARESTNEIGHBORS_HEADER__
9 template <
class Scalar,
class HandleT =
size_t>
61 template <
class NN,
class NNs>
85 intptr_t low = 0, high =
n->size() - 1,
index = 0, mid;
90 mid = (low + high) >> 1;
103 n->insert(
n->begin() +
index, nn);
106 if ((*
n)[k] > (*n)[k - 1])
122 template <
class NNs,
class ScalarType>
128 *worstDist =
n[j].sqrDist;
130 for (; j < size; ++j)
132 if (
n[j].sqrDist > *worstDist)
134 *worstDist =
n[j].sqrDist;
140 template <
class Po
int,
class Po
ints>
152 typedef typename Points::size_type size_type;
155 ScalarType worstDist = 0;
157 for (; i < size && i < k; ++i)
160 n->push_back(
NN(i, diff * diff));
161 if (
n->back().sqrDist > worstDist)
163 worstDist =
n->back().sqrDist;
164 worst =
n->size() - 1;
168 for (i = k; i < size; ++i)
171 ScalarType dist = diff * diff;
172 if (dist < worstDist)
174 (*n)[worst] =
NN(i, dist);
180 template <
class Po
int,
class Po
ints,
template <
class>
class ContainerT,
class NN>
190 for (
size_t i = 0; i < size; ++i)
192 NN nn(p.SqrDistance(points[i]), i);
193 neighbors->PushHeap(nn);
197 template <
class Po
int,
class Po
ints,
template <
class>
class ContainerT,
class NN>
207 for (
size_t i = 0; i < size; ++i)
209 NN nn(p.L1Distance(points[i]), i);
210 neighbors->PushHeap(nn);
std::vector< Point > Points
NearestNeighbor(HandleType i, ScalarType d)
bool operator>(const NearestNeighbor &nn) const
constexpr auto n() noexcept
bool operator>=(const NearestNeighbor &nn) const
void BruteForceNearestNeighbors(unsigned int k, const Point &p, const Points &points, size_t size, LimitedHeap< NN, std::less< NN >, ContainerT > *neighbors)
void SortedNearestNeighborInsert(const NN &nn, unsigned int k, NNs *n)
bool operator<(const NearestNeighbor &nn) const
void BruteForceL1NearestNeighbors(unsigned int k, const Point &p, const Points &points, size_t size, LimitedHeap< NN, std::less< NN >, ContainerT > *neighbors)
void FindFurthestNearestNeighbor(const NNs &n, size_t size, size_t *worst, ScalarType *worstDist)
bool operator<=(const NearestNeighbor &nn) const
void NearestNeighbors(unsigned int k, const Point &p, const Points &points, size_t size, std::vector< NearestNeighbor< typename Points::size_type, typename Point::ScalarType >> *n)