Changed tab

This commit is contained in:
Guilhem Lavaux 2015-01-26 18:16:43 +01:00
parent e01d3d0331
commit 730185ff89

View File

@ -55,12 +55,20 @@ namespace CosmoTool
typedef octCoordType OctCoords[3]; typedef octCoordType OctCoords[3];
template<class T = void>
struct OctCell struct OctCell
{ {
octPtr numberLeaves; octPtr numberLeaves;
octPtr children[8]; octPtr children[8];
T data;
}; };
template<typename T>
struct OctTree_defaultUpdater {
void operator()(T& d) { }
};
template<typename T_dataUpdater = OctTree_defaultUpdater<void>, class T = void>
class OctTree class OctTree
{ {
public: public:
@ -103,9 +111,10 @@ namespace CosmoTool
protected: protected:
T_dataUpdater updater;
const FCoordinates *particles; const FCoordinates *particles;
octPtr numParticles; octPtr numParticles;
OctCell *cells; OctCell<T> *cells;
float Lbox; float Lbox;
octPtr lastNode; octPtr lastNode;
octPtr numCells; octPtr numCells;
@ -128,47 +137,47 @@ namespace CosmoTool
FCoordinates center, realCenter; FCoordinates center, realCenter;
for (int j = 0; j < 3; j++) for (int j = 0; j < 3; j++)
{ {
center[j] = icoord[j]/(2.*octCoordCenter); center[j] = icoord[j]/(2.*octCoordCenter);
realCenter[j] = xMin[j] + center[j]*lenNorm; realCenter[j] = xMin[j] + center[j]*lenNorm;
} }
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, if (!condition(realCenter, cells[node].numberLeaves,
lenNorm*halfNodeLength/(float)octCoordCenter, lenNorm*halfNodeLength/(float)octCoordCenter,
cells[node].children[0] == invalidOctCell)) cells[node].children[0] == invalidOctCell))
return; return;
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
octPtr newNode = cells[node].children[i]; octPtr newNode = cells[node].children[i];
int ipos[3] = { (i&1), (i&2)>>1, (i&4)>>2 }; int ipos[3] = { (i&1), (i&2)>>1, (i&4)>>2 };
if (newNode == emptyOctCell || newNode == invalidOctCell) if (newNode == emptyOctCell || newNode == invalidOctCell)
continue; continue;
for (int j = 0; j < 3; j++) for (int j = 0; j < 3; j++)
newCoord[j] = icoord[j]+(2*ipos[j]-1)*halfNodeLength/2; newCoord[j] = icoord[j]+(2*ipos[j]-1)*halfNodeLength/2;
if (newNode & octParticleMarker) if (newNode & octParticleMarker)
{ {
for (int j = 0; j < 3; j++) for (int j = 0; j < 3; j++)
{ {
center[j] = newCoord[j]/(2.*octCoordCenter); center[j] = newCoord[j]/(2.*octCoordCenter);
realCenter[j] = xMin[j] + lenNorm*center[j]; realCenter[j] = xMin[j] + lenNorm*center[j];
} }
f(realCenter, f(realCenter,
1, lenNorm*halfNodeLength/(2.*octCoordCenter), 1, lenNorm*halfNodeLength/(2.*octCoordCenter),
false, true); false, true);
continue; continue;
} }
walkTreeElements(f, condition, cells[node].children[i], newCoord, halfNodeLength/2); walkTreeElements(f, condition, cells[node].children[i], newCoord, halfNodeLength/2);
} }
} }