diff --git a/src/octTree.cpp b/src/octTree.cpp index 91648cf..5435b25 100644 --- a/src/octTree.cpp +++ b/src/octTree.cpp @@ -32,6 +32,17 @@ OctTree::OctTree(const FCoordinates *particles, octPtr numParticles, } } + lenNorm = 0; + for (octPtr i = 0; i < numParticles; i++) + { + for (int j = 0; j < 3; j++) + { + float delta = particles[i][j]-xMin[j]; + if (delta > lenNorm) + lenNorm = delta; + } + } + cout << xMin[0] << " " << xMin[1] << " " << xMin[2] << " lNorm=" << lenNorm << endl; cells = new OctCell[numCells]; Lbox = (float)(octCoordTypeNorm+1); @@ -94,11 +105,14 @@ void OctTree::insertParticle(octPtr node, } for (int j = 0; j < 3; j++) - if ((octPtr)(particles[particleId][j]*Lbox) > icoord[j]) - { - octPos |= (1 << j); - ipos[j] = 1; - } + { + float treePos = (particles[particleId][j]-xMin[j])*Lbox/lenNorm; + if ((octPtr)(treePos) > icoord[j]) + { + octPos |= (1 << j); + ipos[j] = 1; + } + } if (cells[node].children[octPos] == emptyOctCell) { diff --git a/src/octTree.hpp b/src/octTree.hpp index 2402a5e..6dd846d 100644 --- a/src/octTree.hpp +++ b/src/octTree.hpp @@ -77,10 +77,10 @@ namespace CosmoTool for (int j = 0; j < 3; j++) { center[j] = icoord[j]/(2.*octCoordCenter); - realCenter[j] = center[j]*lenNorm+xMin[j]; + realCenter[j] = xMin[j] + center[j]*lenNorm; } - f(realCenter, cells[node].numberLeaves, halfNodeLength/(float)octCoordCenter, + f(realCenter, cells[node].numberLeaves, lenNorm*halfNodeLength/(float)octCoordCenter, cells[node].children[0] == invalidOctCell, // True if this is a meta-node false); @@ -104,7 +104,7 @@ namespace CosmoTool } f(realCenter, - 1, halfNodeLength/(2.*octCoordCenter), + 1, lenNorm*halfNodeLength/(2.*octCoordCenter), false, true); continue; }