Skip to content
Snippets Groups Projects
Commit e59b31d2 authored by Paul Heinzlreiter's avatar Paul Heinzlreiter
Browse files

* tree update

parent d7eb40e6
Branches
No related merge requests found
......@@ -59,5 +59,38 @@ namespace nbody {
}
current = current->next;
}
/*
//iterate for updating representatives
current = this->nodes->prev;
while (current != this->nodes) {
current->representative.mass = 0.0;
current->representative.position[0] = 0.0;
current->representative.position[1] = 0.0;
current->representative.position[2] = 0.0;
if (current->leaf) {
for (unsigned int i = 0; i < current->bodies.size(); i++) {
current->representative.mass += current->bodies[i].mass;
for (int j = 0; j < 3; j++) {
current->representative.position[j] += current->bodies[i].position[j];
}
}
} else {
Node* child = current->next;
do {
current->representative.mass += child->representative.mass;
for (int j = 0; j < 3; j++) {
current->representative.position[j] += child->representative.position[j];
}
child = child->nextSibling;
} while (child != NULL);
}
current->representative.mass /= current->bodies.size();
for (int j = 0; j < 3; j++) {
current->representative.position[j] /= current->bodies.size();
}
current = current->prev;
}
*/
}
}
......@@ -178,7 +178,24 @@ namespace nbody {
}
return sqrt(dist);
}
}
double Box::distanceToBox(Box box) {
double length = 0.0;
for (int i = 0; i < 3; i++) {
double elem;
if (box.min[i] < this->min[i] && box.max[i] < this->min[i]) {
elem = this->min[i] - box.max[i];
} else if (box.min[i] > this->max[i] && box.max[i] > this->max[i]) {
elem = box.min[i] - this->max[i];
} else {
elem = 0.0;
}
length += elem * elem;
}
return sqrt(length);
}
vector<Box> Box::octreeSplit() {
......
......@@ -32,6 +32,7 @@ namespace nbody {
virtual void print();
virtual bool overlapsSphere(double* sphereCenter, double sphereRadius);
virtual double distanceToPosition(double* position);
virtual double distanceToBox(Box box);
virtual vector<Box> octreeSplit();
virtual vector<Box> splitLongestSide();
};
......
......@@ -170,6 +170,10 @@ namespace nbody {
return sqrt(distance) > this->getL();
}
bool Node::sufficientForBox(Box box) {
return this->bb.distanceToBox(box) > this->getL();
}
void Node::setBodies(vector<Body> bodies) {
this->bodies = bodies;
}
......
......@@ -44,6 +44,7 @@ namespace nbody {
virtual bool isCorrect();
virtual void print();
virtual bool sufficientForBody(Body body);
virtual bool sufficientForBox(Box box);
virtual void setBodies(vector<Body> bodies);
};
}
......
......@@ -117,6 +117,28 @@ namespace nbody {
return result;
}
vector<Body> Tree::extractRefinements(Box domain) {
vector<Body> result;
Node* current = this->nodes->next;
while (current != this->nodes) {
bool sufficient = current->sufficientForBox(domain);
if (sufficient) {
//TODO: check for setting representative in build process
result.push_back(current->representative);
current = current->afterSubtree;
} else if (current->leaf) {
result.insert(result.end(), current->bodies.begin(), current->bodies.end());
current = current->next;
} else {
current = current->next;
}
}
return result;
}
Box Tree::getRootBB() {
return this->nodes->next->bb;
}
......
......@@ -29,6 +29,7 @@ namespace nbody {
virtual void computeForces();
virtual void moveBodies();
virtual vector<Body> extractBodies();
virtual vector<Body> extractRefinements(Box domain);
virtual void rebuild();
virtual Box getRootBB();
virtual void print();
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment