Le LOD marche 100% pour les split !

This commit is contained in:
Georges Dupéron 2011-12-22 18:13:12 +01:00
parent 3701b8e1d5
commit b333f10d0b
3 changed files with 14 additions and 42 deletions

View File

@ -6,14 +6,6 @@ Heap::Heap()
void Heap::init(int id, int factor) { this->id = id; this->factor = factor; } void Heap::init(int id, int factor) { this->id = id; this->factor = factor; }
void Heap::insert(float key, Chose* value) { void Heap::insert(float key, Chose* value) {
// { // DEBUG
// int _d_node = value->lod.heaps[id];
// if (_d_node <= lastNode && _d_node >= 0 &&
// buckets[getBucket(_d_node)][getIndex(_d_node)].value == value) {
// std::cout << "ERROR ! Trying to insert " << value;
// std::cout << " but it is already here." << std::endl;
// }
// }
++lastNode; ++lastNode;
if (getBucket(lastNode) > lastAllocatedBucket) { if (getBucket(lastNode) > lastAllocatedBucket) {
allocateBucket(); allocateBucket();
@ -21,26 +13,11 @@ void Heap::insert(float key, Chose* value) {
buckets[getBucket(lastNode)][getIndex(lastNode)].key = key; buckets[getBucket(lastNode)][getIndex(lastNode)].key = key;
buckets[getBucket(lastNode)][getIndex(lastNode)].value = value; buckets[getBucket(lastNode)][getIndex(lastNode)].value = value;
siftUp(lastNode); siftUp(lastNode);
for (int i = 0; i <= lastNode; i++) {
std::cout << id << " ";
std::cout << buckets[getBucket(lastNode)][getIndex(lastNode)].key << " ";
std::cout << buckets[getBucket(lastNode)][getIndex(lastNode)].value;
std::cout << typeid(*(buckets[getBucket(lastNode)][getIndex(lastNode)].value)).name();
std::cout << std::endl;
}
} }
void Heap::remove(Chose* value) { void Heap::remove(Chose* value) {
int node = value->lod.heaps[id]; int node = value->lod.heaps[id];
// { // DEBUG
// if (buckets[getBucket(node)][getIndex(node)].value != value) {
// std::cout << "ERROR ! Trying to remove " << value;
// std::cout << " but found " << buckets[getBucket(node)][getIndex(node)].value;
// std::cout << std::endl;
// }
// }
if (node == lastNode) { // On a supprimé le dernier noeud. if (node == lastNode) { // On a supprimé le dernier noeud.
--lastNode; --lastNode;
// + 1 pour garder au moins un bucket "en cache". // + 1 pour garder au moins un bucket "en cache".
@ -84,7 +61,7 @@ void Heap::siftUp(int node) {
break; break;
int p = parent(node); int p = parent(node);
np = &(buckets[getBucket(p)][getIndex(p)]); np = &(buckets[getBucket(p)][getIndex(p)]);
if (n->key * factor <= np->key * factor) if (n->key * factor >= np->key * factor) //!!!!!
break; break;
HeapNode temp = *n; HeapNode temp = *n;
*n = *np; *n = *np;
@ -111,9 +88,9 @@ void Heap::siftDown(int node) {
nrc = &(buckets[getBucket(rc)][getIndex(rc)]); nrc = &(buckets[getBucket(rc)][getIndex(rc)]);
// exchLeft et exchRight peuvent être tout deux true. Dans ce // exchLeft et exchRight peuvent être tout deux true. Dans ce
// cas, c'est exchRight qui gagne. // cas, c'est exchRight qui gagne.
bool exchLeft = (lc <= lastNode) && (n->key * factor < nlc->key * factor); bool exchLeft = (lc <= lastNode) && (n->key * factor > nlc->key * factor);
bool exchRight = (rc <= lastNode) && (n->key * factor < nrc->key * factor); bool exchRight = (rc <= lastNode) && (n->key * factor > nrc->key * factor);
exchRight = exchRight && (nlc->key * factor < nrc->key * factor); exchRight = exchRight && (nlc->key * factor > nrc->key * factor);
if ((!exchLeft) && (!exchRight)) if ((!exchLeft) && (!exchRight))
break; break;
HeapNode temp = *n; HeapNode temp = *n;

21
lod.cpp
View File

@ -33,7 +33,6 @@ void Lod::setCamera(Vertex newCamera) {
for(int i = 0; i < 6; i++) { for(int i = 0; i < 6; i++) {
Chose* c; Chose* c;
while((c = splitOut[i].popIfLessThan(camera[i>>1]))) { while((c = splitOut[i].popIfLessThan(camera[i>>1]))) {
std::cout<<"soi "<<c->lod.inCounter+1<<" "<<typeid(*c).name()<<" "<<c<<std::endl;
if(c->lod.inCounter == 5) { if(c->lod.inCounter == 5) {
for(int j = 0; j < 6; j++) { for(int j = 0; j < 6; j++) {
if(i == j) continue; if(i == j) continue;
@ -52,7 +51,6 @@ void Lod::setCamera(Vertex newCamera) {
for(int i = 0; i < 6; i++) { for(int i = 0; i < 6; i++) {
Chose* c; Chose* c;
while((c = splitIn[i].popIfLessThan(camera[i>>1]))) { while((c = splitIn[i].popIfLessThan(camera[i>>1]))) {
std::cout<<"SIO "<<c->lod.inCounter-1<<" "<<typeid(*c).name()<<" "<<c<<std::endl;
c->lod.inCounter--; c->lod.inCounter--;
splitOut[i].insert(c->lod.splitBox[i], c); splitOut[i].insert(c->lod.splitBox[i], c);
} }
@ -61,20 +59,21 @@ void Lod::setCamera(Vertex newCamera) {
void Lod::doSplit(Chose* c) { void Lod::doSplit(Chose* c) {
// TODO // TODO
if (c->split() && c->children.size() > 0) { if (c->split()) {
std::vector<Chose*>::iterator it; std::vector<Chose*>::iterator it;
for (it = c->children.begin(); it != c->children.end(); ++it) { for (it = c->children.begin(); it != c->children.end(); ++it) {
(*it)->triangulation(); (*it)->triangulation();
(*it)->updateAABB(); (*it)->updateAABB();
(*it)->drawAABB(); // (*it)->drawAABB();
addSplitCube((*it)); addSplitCube((*it));
} }
} else {
// Pour debug : quand on tente de split un objet qui ne peut
// pas l'être, on vire le dessin de sa splitBox.
c->triangles.clear();
c->triangulation();
} }
// else {
// // Pour debug : quand on tente de split un objet qui ne peut
// // pas l'être, on vire le dessin de sa splitBox.
// c->triangles.clear();
// c->triangulation();
// }
} }
void Lod::addMergeCube(Chose* chose) { void Lod::addMergeCube(Chose* chose) {
@ -85,9 +84,6 @@ void Lod::addMergeCube(Chose* chose) {
void Lod::addSplitCube(Chose* chose) { void Lod::addSplitCube(Chose* chose) {
chose->lod.inCounter = 0; chose->lod.inCounter = 0;
for(int i = 0; i < 6; i++) { for(int i = 0; i < 6; i++) {
// std::cout << chose->lod.splitBox[i] << " " << camera[i>>1] << " " << splitOut[i].factor;
// std::cout << " " << (splitOut[i].lessThan(chose->lod.splitBox[i], camera[i>>1]) ? "t" : "f");
// std::cout << std::endl;
if(splitOut[i].lessThan(chose->lod.splitBox[i], camera[i>>1])) { if(splitOut[i].lessThan(chose->lod.splitBox[i], camera[i>>1])) {
chose->lod.inCounter++; chose->lod.inCounter++;
splitIn[i].insert(chose->lod.splitBox[i], chose); splitIn[i].insert(chose->lod.splitBox[i], chose);
@ -101,5 +97,4 @@ void Lod::addSplitCube(Chose* chose) {
splitIn[i].remove(chose); splitIn[i].remove(chose);
doSplit(chose); doSplit(chose);
} }
std::cout<<"insert "<<chose->lod.inCounter<<" "<<typeid(*chose).name()<<" "<<chose<<std::endl;
} }

View File

@ -3,7 +3,7 @@
// camera(Camera(Vertex(9600,10000,15300),0,179,1000,0.6) // camera(Camera(Vertex(9600,10000,15300),0,179,1000,0.6)
View::View(Chose* root) View::View(Chose* root)
: root(root), : root(root),
camera(Camera(Vertex(-15000,-15000,3000),45,90,1000,0.6)), camera(Camera(Vertex(-9000,-15000,3000),45,90,1000,0.6)),
lod(camera.cameraCenter, root) { lod(camera.cameraCenter, root) {
initWindow(); initWindow();
mainLoop(); mainLoop();
@ -105,7 +105,7 @@ void View::mainLoop() {
short continuer = 1; short continuer = 1;
SDL_Event event; SDL_Event event;
SDL_EnableKeyRepeat(40,40); SDL_EnableKeyRepeat(40,40);
// SDL_WM_GrabInput(SDL_GRAB_ON); SDL_WM_GrabInput(SDL_GRAB_ON);
SDL_ShowCursor(SDL_DISABLE); SDL_ShowCursor(SDL_DISABLE);
while ( SDL_PollEvent(&event) ); // empty queue. while ( SDL_PollEvent(&event) ); // empty queue.