From bdb98252138733fc693129d7f0f3dbc4e2c7f40d Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Sun, 1 Nov 2009 18:56:10 -0600 Subject: [PATCH] Adapt for a more general octTree --- src/octTree.cpp | 13 +++++++++++++ src/octTree.hpp | 14 +++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/octTree.cpp b/src/octTree.cpp index 30e0175..91648cf 100644 --- a/src/octTree.cpp +++ b/src/octTree.cpp @@ -19,6 +19,19 @@ OctTree::OctTree(const FCoordinates *particles, octPtr numParticles, //#ifdef VERBOSE cerr << "Allocating " << numCells << " octtree cells" << endl; //#endif + + for (int j = 0; j < 3; j++) + xMin[j] = particles[0][j]; + + for (octPtr i = 1; i < numParticles; i++) + { + for (int j = 0; j < 3; j++) + { + if (particles[i][j] < xMin[j]) + xMin[j] = particles[i][j]; + } + } + cells = new OctCell[numCells]; Lbox = (float)(octCoordTypeNorm+1); diff --git a/src/octTree.hpp b/src/octTree.hpp index 3aee37c..2402a5e 100644 --- a/src/octTree.hpp +++ b/src/octTree.hpp @@ -62,6 +62,8 @@ namespace CosmoTool float Lbox; octPtr lastNode; octPtr numCells; + float lenNorm; + float xMin[3]; template @@ -70,10 +72,13 @@ namespace CosmoTool octCoordType halfNodeLength) { OctCoords newCoord; - FCoordinates realCenter; + FCoordinates center, realCenter; for (int j = 0; j < 3; j++) - realCenter[j] = icoord[j]/(2.*octCoordCenter); + { + center[j] = icoord[j]/(2.*octCoordCenter); + realCenter[j] = center[j]*lenNorm+xMin[j]; + } f(realCenter, cells[node].numberLeaves, halfNodeLength/(float)octCoordCenter, cells[node].children[0] == invalidOctCell, // True if this is a meta-node @@ -93,7 +98,10 @@ namespace CosmoTool if (newNode & octParticleMarker) { for (int j = 0; j < 3; j++) - realCenter[j] = newCoord[j]/(2.*octCoordCenter); + { + center[j] = newCoord[j]/(2.*octCoordCenter); + realCenter[j] = xMin[j] + lenNorm*center[j]; + } f(realCenter, 1, halfNodeLength/(2.*octCoordCenter),