From a194f1f00bf2981c9ad655b5882b4d44d80efebd Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Fri, 27 Nov 2009 18:06:04 +0100 Subject: [PATCH] Introduced proper conditioning of walking the tree --- src/octTree.hpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/octTree.hpp b/src/octTree.hpp index 6dd846d..14bf17d 100644 --- a/src/octTree.hpp +++ b/src/octTree.hpp @@ -47,12 +47,25 @@ namespace CosmoTool return cells[0].numberLeaves; } + static bool unconditioned(const FCoordinates&, octPtr, float, bool) + { + return true; + } + template void walkTree(FunT f) { OctCoords rootCenter = { octCoordCenter, octCoordCenter, octCoordCenter }; - walkTreeElements(f, 0, rootCenter, octCoordCenter); + walkTreeElements(f, unconditioned, 0, rootCenter, octCoordCenter); + } + + template + 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 - void walkTreeElements(FunT f, octPtr node, + template + 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); } }