Allow conditioned walking

This commit is contained in:
Guilhem Lavaux 2009-11-06 22:05:00 -06:00
parent b8a67a50eb
commit 145b298730

View File

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