Have a recursion that only count particles
This commit is contained in:
parent
97dbc381e0
commit
1ae7233139
@ -97,6 +97,7 @@ namespace CosmoTool {
|
|||||||
CoordType *distances,
|
CoordType *distances,
|
||||||
uint32_t numCells)
|
uint32_t numCells)
|
||||||
throw (NotEnoughCells);
|
throw (NotEnoughCells);
|
||||||
|
uint32_t countCells(const coords& x, CoordType r);
|
||||||
|
|
||||||
Cell *getNearestNeighbour(const coords& x);
|
Cell *getNearestNeighbour(const coords& x);
|
||||||
|
|
||||||
@ -146,6 +147,7 @@ namespace CosmoTool {
|
|||||||
coords minBound,
|
coords minBound,
|
||||||
coords maxBound);
|
coords maxBound);
|
||||||
|
|
||||||
|
template<bool justCount>
|
||||||
void recursiveIntersectionCells(RecursionInfoCells<N,ValType, CType>& info,
|
void recursiveIntersectionCells(RecursionInfoCells<N,ValType, CType>& info,
|
||||||
Node *node,
|
Node *node,
|
||||||
int level)
|
int level)
|
||||||
|
@ -92,7 +92,7 @@ namespace CosmoTool {
|
|||||||
info.numCells = numCells;
|
info.numCells = numCells;
|
||||||
info.distances = 0;
|
info.distances = 0;
|
||||||
|
|
||||||
recursiveIntersectionCells(info, root, 0);
|
recursiveIntersectionCells<false>(info, root, 0);
|
||||||
return info.currentRank;
|
return info.currentRank;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,11 +113,29 @@ namespace CosmoTool {
|
|||||||
info.numCells = numCells;
|
info.numCells = numCells;
|
||||||
info.distances = distances;
|
info.distances = distances;
|
||||||
|
|
||||||
recursiveIntersectionCells(info, root, 0);
|
recursiveIntersectionCells<false>(info, root, 0);
|
||||||
return info.currentRank;
|
return info.currentRank;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<int N, typename ValType, typename CType>
|
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,
|
void KDTree<N,ValType,CType>::recursiveIntersectionCells(RecursionInfoCells<N,ValType,CType>& info,
|
||||||
Node *node,
|
Node *node,
|
||||||
int level)
|
int level)
|
||||||
@ -135,11 +153,14 @@ namespace CosmoTool {
|
|||||||
}
|
}
|
||||||
if (d2 < info.r2)
|
if (d2 < info.r2)
|
||||||
{
|
{
|
||||||
if (info.currentRank == info.numCells)
|
if (!justCount)
|
||||||
throw NotEnoughCells();
|
{
|
||||||
info.cells[info.currentRank] = node->value;
|
if (info.currentRank == info.numCells)
|
||||||
if (info.distances)
|
throw NotEnoughCells();
|
||||||
info.distances[info.currentRank] = d2;
|
info.cells[info.currentRank] = node->value;
|
||||||
|
if (info.distances)
|
||||||
|
info.distances[info.currentRank] = d2;
|
||||||
|
}
|
||||||
info.currentRank++;
|
info.currentRank++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,15 +170,15 @@ namespace CosmoTool {
|
|||||||
((info.x[axis]-info.r) < node->value->coord[axis]))
|
((info.x[axis]-info.r) < node->value->coord[axis]))
|
||||||
{
|
{
|
||||||
if (node->children[0] != 0)
|
if (node->children[0] != 0)
|
||||||
recursiveIntersectionCells(info, node->children[0],
|
recursiveIntersectionCells<justCount>(info, node->children[0],
|
||||||
level+1);
|
level+1);
|
||||||
}
|
}
|
||||||
if (((info.x[axis]+info.r) > node->value->coord[axis]) &&
|
if (((info.x[axis]+info.r) > node->value->coord[axis]) &&
|
||||||
((info.x[axis]-info.r) < node->maxBound[axis]))
|
((info.x[axis]-info.r) < node->maxBound[axis]))
|
||||||
{
|
{
|
||||||
if (node->children[1] != 0)
|
if (node->children[1] != 0)
|
||||||
recursiveIntersectionCells(info, node->children[1],
|
recursiveIntersectionCells<justCount>(info, node->children[1],
|
||||||
level+1);
|
level+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,8 +236,10 @@ namespace CosmoTool {
|
|||||||
dimList[i] = edge[i];
|
dimList[i] = edge[i];
|
||||||
fullSize *= edge[i];
|
fullSize *= edge[i];
|
||||||
}
|
}
|
||||||
array = new T[fullSize];
|
if (fullSize != 0) {
|
||||||
v->get(array, edge);
|
array = new T[fullSize];
|
||||||
|
v->get(array, edge);
|
||||||
|
}
|
||||||
delete[] edge;
|
delete[] edge;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user