Newer
Older
#include "BarnesHutTree.hpp"
BarnesHutTree::BarnesHutTree() {
}
BarnesHutTree::~BarnesHutTree() {
vector<Box> BarnesHutTree::splitBB(Node* node) {
int BarnesHutTree::numberOfChildren() {
return 8;
}
void BarnesHutTree::build(vector<Body> bodies) {
current->extendBBforBodies();
current->extendBBtoCube();
current->afterSubtree = current->next;
//iterate over existing boxes and split if it contains too much bodies
while (current != this->nodes) {
if (current->isSplitable()) {
vector<Box> subboxes = this->splitBB(current);
for (vector<Box>::iterator it = subboxes.begin(); it != subboxes.end(); it++) {
child->bodies = it->copyBodies(current->bodies);
if (it + 1 != subboxes.end()) {
child->nextSibling = current->next;
}
if (it != subboxes.begin()) {
current->next->prevSibling = child;
}
if (it != subboxes.begin()) {
child->afterSubtree = child->next;
} else {
child->afterSubtree = current->afterSubtree;
}
////
Node* child = current->next;
for (int i = 0; i < 8; i++) {
if (i == 0) {
if (child->prevSibling != NULL || child->nextSibling == NULL) {
cout << "WRONG BEG" << endl;
}
} else if (i == 7) {
if (child->prevSibling == NULL || child->nextSibling != NULL) {
cout << "WRONG END" << endl;
}
} else {
if (child->prevSibling == NULL || child->nextSibling == NULL) {
cout << "WRONG MID" << endl;
}
}
child = child->next;
}
////
current->bodies.clear();
}
current = current->next;
}
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
//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;
}
*/