diff --git a/src/octTree.hpp b/src/octTree.hpp index 6dd846d..8f77bb1 100644 --- a/src/octTree.hpp +++ b/src/octTree.hpp @@ -49,10 +49,16 @@ namespace CosmoTool template void walkTree(FunT f) + { + walkTree(f, unconditioned); + } + + template + void walkTree(FunT f, CondT condition) { OctCoords rootCenter = { octCoordCenter, octCoordCenter, octCoordCenter }; - walkTreeElements(f, 0, rootCenter, octCoordCenter); + walkTreeElements(f, condition, 0, rootCenter, octCoordCenter); } protected: @@ -66,8 +72,14 @@ namespace CosmoTool float xMin[3]; - template - void walkTreeElements(FunT f, octPtr node, + static bool unconditioned() + { + return true; + } + + template + void walkTreeElements(FunT f, CondT condition, + octPtr node, const OctCoords& icoord, octCoordType halfNodeLength) { @@ -83,6 +95,11 @@ namespace CosmoTool 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++) { @@ -108,7 +125,8 @@ namespace CosmoTool false, true); continue; } - walkTreeElements(f, cells[node].children[i], newCoord, halfNodeLength/2); + walkTreeElements(f, condition, + cells[node].children[i], newCoord, halfNodeLength/2); } }