Introduced proper conditioning of walking the tree

This commit is contained in:
Guilhem Lavaux 2009-11-27 18:06:04 +01:00
parent a4ffa66b8d
commit a194f1f00b

View File

@ -47,12 +47,25 @@ namespace CosmoTool
return cells[0].numberLeaves;
}
static bool unconditioned(const FCoordinates&, octPtr, float, bool)
{
return true;
}
template<typename FunT>
void walkTree(FunT f)
{
OctCoords rootCenter = { octCoordCenter, octCoordCenter, octCoordCenter };
walkTreeElements(f, 0, rootCenter, octCoordCenter);
walkTreeElements(f, unconditioned, 0, rootCenter, octCoordCenter);
}
template<typename FunT, typename CondT>
void walkTree(FunT f, CondT condition)
{
OctCoords rootCenter = { octCoordCenter, octCoordCenter, octCoordCenter };
walkTreeElements(f, condition, 0, rootCenter, octCoordCenter);
}
protected:
@ -66,8 +79,8 @@ namespace CosmoTool
float xMin[3];
template<typename FunT>
void walkTreeElements(FunT f, octPtr node,
template<typename FunT,typename CondT>
void walkTreeElements(FunT f, CondT condition, octPtr node,
const OctCoords& icoord,
octCoordType halfNodeLength)
{
@ -79,11 +92,16 @@ namespace CosmoTool
center[j] = icoord[j]/(2.*octCoordCenter);
realCenter[j] = xMin[j] + center[j]*lenNorm;
}
f(realCenter, cells[node].numberLeaves, lenNorm*halfNodeLength/(float)octCoordCenter,
cells[node].children[0] == invalidOctCell, // True if this is a meta-node
false);
if (!condition(realCenter, cells[node].numberLeaves,
lenNorm*halfNodeLength/(float)octCoordCenter,
cells[node].children[0] == invalidOctCell))
return;
for (int i = 0; i < 8; i++)
{
octPtr newNode = cells[node].children[i];
@ -108,7 +126,7 @@ namespace CosmoTool
false, true);
continue;
}
walkTreeElements(f, cells[node].children[i], newCoord, halfNodeLength/2);
walkTreeElements(f, condition, cells[node].children[i], newCoord, halfNodeLength/2);
}
}