Have a recursion that only count particles

This commit is contained in:
Guilhem Lavaux 2011-06-22 13:57:06 -05:00
parent 97dbc381e0
commit 1ae7233139
3 changed files with 37 additions and 12 deletions

View File

@ -97,6 +97,7 @@ namespace CosmoTool {
CoordType *distances,
uint32_t numCells)
throw (NotEnoughCells);
uint32_t countCells(const coords& x, CoordType r);
Cell *getNearestNeighbour(const coords& x);
@ -146,6 +147,7 @@ namespace CosmoTool {
coords minBound,
coords maxBound);
template<bool justCount>
void recursiveIntersectionCells(RecursionInfoCells<N,ValType, CType>& info,
Node *node,
int level)

View File

@ -92,7 +92,7 @@ namespace CosmoTool {
info.numCells = numCells;
info.distances = 0;
recursiveIntersectionCells(info, root, 0);
recursiveIntersectionCells<false>(info, root, 0);
return info.currentRank;
}
@ -113,11 +113,29 @@ namespace CosmoTool {
info.numCells = numCells;
info.distances = distances;
recursiveIntersectionCells(info, root, 0);
recursiveIntersectionCells<false>(info, root, 0);
return info.currentRank;
}
template<int N, typename ValType, typename CType>
uint32_t KDTree<N,ValType,CType>::countCells(const coords& x, CoordType r)
{
RecursionInfoCells<N,ValType> info;
memcpy(info.x, x, sizeof(x));
info.r = r;
info.r2 = r*r;
info.cells = 0;
info.currentRank = 0;
info.numCells = 0;
info.distances = 0;
recursiveIntersectionCells<true>(info, root, 0);
return info.currentRank;
}
template<int N, typename ValType, typename CType>
template<bool justCount>
void KDTree<N,ValType,CType>::recursiveIntersectionCells(RecursionInfoCells<N,ValType,CType>& info,
Node *node,
int level)
@ -135,11 +153,14 @@ namespace CosmoTool {
}
if (d2 < info.r2)
{
if (info.currentRank == info.numCells)
throw NotEnoughCells();
info.cells[info.currentRank] = node->value;
if (info.distances)
info.distances[info.currentRank] = d2;
if (!justCount)
{
if (info.currentRank == info.numCells)
throw NotEnoughCells();
info.cells[info.currentRank] = node->value;
if (info.distances)
info.distances[info.currentRank] = d2;
}
info.currentRank++;
}
}
@ -149,15 +170,15 @@ namespace CosmoTool {
((info.x[axis]-info.r) < node->value->coord[axis]))
{
if (node->children[0] != 0)
recursiveIntersectionCells(info, node->children[0],
recursiveIntersectionCells<justCount>(info, node->children[0],
level+1);
}
if (((info.x[axis]+info.r) > node->value->coord[axis]) &&
((info.x[axis]-info.r) < node->maxBound[axis]))
{
if (node->children[1] != 0)
recursiveIntersectionCells(info, node->children[1],
level+1);
recursiveIntersectionCells<justCount>(info, node->children[1],
level+1);
}
}

View File

@ -236,8 +236,10 @@ namespace CosmoTool {
dimList[i] = edge[i];
fullSize *= edge[i];
}
array = new T[fullSize];
v->get(array, edge);
if (fullSize != 0) {
array = new T[fullSize];
v->get(array, edge);
}
delete[] edge;
}