28 template <
int N,
typename Real,
typename Site,
int MaxNeighbors>
45 std::array<int, MaxNeighbors>& neighbors)
const;
69 inline bool operator()(SortedPoint
const& sorted0,
70 SortedPoint
const& sorted1)
const;
82 template <
int N,
typename Real,
typename Site,
int MaxNeighbors>
84 std::vector<Site>
const& sites,
int maxLeafSize,
int maxLevel)
90 int const numSites =
static_cast<int>(sites.size());
91 for (
int i = 0; i < numSites; ++i)
97 Build(numSites, 0, 0, 0);
100 template <
int N,
typename Real,
typename Site,
int MaxNeighbors>
inline 106 template <
int N,
typename Real,
typename Site,
int MaxNeighbors>
inline 112 template <
int N,
typename Real,
typename Site,
int MaxNeighbors>
115 std::array<int, MaxNeighbors>& neighbors)
const 117 Real sqrRadius = radius * radius;
118 int numNeighbors = 0;
119 std::array<int, MaxNeighbors + 1> localNeighbors;
120 std::array<Real, MaxNeighbors + 1> neighborSqrLength;
121 for (
int i = 0; i <= MaxNeighbors; ++i)
123 localNeighbors[i] = -1;
124 neighborSqrLength[i] = std::numeric_limits<Real>::max();
130 std::array<int, 32> stack;
143 Real sqrLength =
Dot(diff, diff);
144 if (sqrLength <= sqrRadius)
148 for (k = 0; k < numNeighbors; ++k)
150 if (sqrLength <= neighborSqrLength[k])
152 for (
int n = numNeighbors;
n > k; --
n)
154 localNeighbors[
n] = localNeighbors[
n - 1];
155 neighborSqrLength[
n] = neighborSqrLength[
n - 1];
160 if (k < MaxNeighbors)
163 neighborSqrLength[k] = sqrLength;
165 if (numNeighbors < MaxNeighbors)
173 if (node.
left != -1 && point[node.
axis] - radius <= node.
split)
184 for (
int i = 0; i < numNeighbors; ++i)
186 neighbors[i] = localNeighbors[i];
192 template <
int N,
typename Real,
typename Site,
int MaxNeighbors>
194 int siteOffset,
int nodeIndex,
int level)
196 LogAssert(siteOffset != -1,
"Invalid site offset.");
197 LogAssert(nodeIndex != -1,
"Invalid node index.");
198 LogAssert(numSites > 0,
"Empty point list.");
205 int halfNumSites = numSites / 2;
211 int const axis = level % N;
214 auto mid =
mSortedPoints.begin() + siteOffset + halfNumSites;
216 std::nth_element(begin, mid,
end, sorter);
230 int nextLevel = level + 1;
231 Build(halfNumSites, siteOffset, left, nextLevel);
232 Build(numSites - halfNumSites, siteOffset + halfNumSites,
right,
238 node.
split = std::numeric_limits<Real>::max();
246 template <
int N,
typename Real,
typename Site,
int MaxNeighbors>
inline 254 template <
int N,
typename Real,
typename Site,
int MaxNeighbors>
inline 258 return sorted0.first[
mAxis] < sorted1.first[
mAxis];
int GetMaxLeafSize() const
std::pair< Vector< N, Real >, int > SortedPoint
#define LogAssert(condition, message)
void Build(int numSites, int siteOffset, int nodeIndex, int level)
std::vector< SortedPoint > mSortedPoints
bool operator()(SortedPoint const &sorted0, SortedPoint const &sorted1) const
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
int FindNeighbors(Vector< N, Real > const &point, Real radius, std::array< int, MaxNeighbors > &neighbors) const
NearestNeighborQuery(std::vector< Site > const &sites, int maxLeafSize, int maxLevel)
std::vector< Node > mNodes
GLdouble GLdouble GLdouble GLdouble top