Backup
This commit is contained in:
parent
b72f041136
commit
b09b54699c
|
@ -5,6 +5,31 @@
|
||||||
using namespace nxs;
|
using namespace nxs;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
void Policy::Visit(Node *node, std::queue<Node *> &qnode) {
|
||||||
|
std::vector<Node *>::iterator n;
|
||||||
|
for(n = node->in.begin(); n != node->in.end(); n++)
|
||||||
|
if(!(*n)->visited)
|
||||||
|
Visit(*n, qnode);
|
||||||
|
|
||||||
|
node->visited = true;
|
||||||
|
qnode.push(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FrustumPolicy::Expand(unsigned int patch, Nexus::Entry &entry) {
|
||||||
|
if(entry.error == 0) return false;
|
||||||
|
float dist = Distance(entry.sphere, frustum.ViewPoint());
|
||||||
|
/*Point3f line = frustum.viewPoint() - cell->sphere.center;
|
||||||
|
float dist = line.Norm() - cell->sphere.radius; */
|
||||||
|
if(dist < 0) return true;
|
||||||
|
// dist = pow(dist, 1.2);
|
||||||
|
/* cerr << "Dist: " << dist << endl;
|
||||||
|
cerr << "Entry error: " << entry.error << endl;
|
||||||
|
cerr << "error: " << error << endl;
|
||||||
|
cerr << "resolution at dist: " << frustum.Resolution(dist) << endl;*/
|
||||||
|
return entry.error > error * frustum.Resolution(dist);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void NexusMt::LoadHistory() {
|
void NexusMt::LoadHistory() {
|
||||||
//The last update erases everything.
|
//The last update erases everything.
|
||||||
assert(history[0].erased.size() == 0);
|
assert(history[0].erased.size() == 0);
|
||||||
|
@ -107,3 +132,53 @@ void NexusMt::ExtractFixed(vector<unsigned int> &selected, float error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NexusMt::Extract(std::vector<unsigned int> &selected, Policy *policy) {
|
||||||
|
std::vector<Node>::iterator n;
|
||||||
|
for(n = nodes.begin(); n != nodes.end(); n++)
|
||||||
|
(*n).visited = false;
|
||||||
|
|
||||||
|
std::queue<Node *> qnodo;
|
||||||
|
qnodo.push(&nodes[0]);
|
||||||
|
nodes[0].visited = true;
|
||||||
|
|
||||||
|
for( ; !qnodo.empty(); qnodo.pop()) {
|
||||||
|
Node &node = *qnodo.front();
|
||||||
|
|
||||||
|
std::vector<Frag>::iterator i;
|
||||||
|
std::vector<Node *>::iterator on;
|
||||||
|
for(i = node.frags.begin(), on = node.out.begin();
|
||||||
|
i != node.frags.end(); i++, on++) {
|
||||||
|
if((*on)->visited) continue;
|
||||||
|
Frag &frag = (*i);
|
||||||
|
std::vector<unsigned int>::iterator cell;
|
||||||
|
for(cell = frag.begin(); cell != frag.end(); cell++) {
|
||||||
|
if(policy->Expand(*cell, index[*cell]))
|
||||||
|
policy->Visit(*on, qnodo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Select(selected);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NexusMt::Select(vector<unsigned int> &selected) {
|
||||||
|
selected.clear();
|
||||||
|
std::vector<Node>::iterator i;
|
||||||
|
for(i = nodes.begin(); i != nodes.end(); i++) {
|
||||||
|
Node &node = *i;
|
||||||
|
if(!node.visited)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
std::vector<Node *>::iterator n;
|
||||||
|
std::vector<Frag>::iterator f;
|
||||||
|
for(n = node.out.begin(), f = node.frags.begin();
|
||||||
|
n != node.out.end(); n++, f++) {
|
||||||
|
if(!(*n)->visited || (*n)->error == 0) {
|
||||||
|
vector<unsigned int>::iterator c;
|
||||||
|
Frag &frag = (*f);
|
||||||
|
for(c = frag.begin(); c != frag.end(); c++)
|
||||||
|
selected.push_back(*c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,12 +3,14 @@
|
||||||
|
|
||||||
|
|
||||||
#include "nexus.h"
|
#include "nexus.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
|
#include <wrap/gui/frustum.h>
|
||||||
|
|
||||||
|
|
||||||
namespace nxs {
|
namespace nxs {
|
||||||
|
|
||||||
class NexusMt: public Nexus {
|
|
||||||
private:
|
|
||||||
|
|
||||||
class Frag:public std::vector<unsigned int> {};
|
class Frag:public std::vector<unsigned int> {};
|
||||||
|
|
||||||
struct Node {
|
struct Node {
|
||||||
|
@ -19,13 +21,33 @@ class NexusMt: public Nexus {
|
||||||
bool visited;
|
bool visited;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Policy {
|
||||||
|
public:
|
||||||
|
virtual bool Expand(unsigned int patch, Nexus::Entry &entry) = 0;
|
||||||
|
virtual void Visit(Node *node, std::queue<Node *> &qnode);
|
||||||
|
};
|
||||||
|
|
||||||
|
class FrustumPolicy: public Policy {
|
||||||
|
public:
|
||||||
|
vcg::Frustumf frustum;
|
||||||
|
float error;
|
||||||
|
void GetView() { frustum.GetView(); }
|
||||||
|
bool Expand(unsigned int patch, Nexus::Entry &entry);
|
||||||
|
};
|
||||||
|
|
||||||
|
class NexusMt: public Nexus {
|
||||||
|
private:
|
||||||
std::vector<Node> nodes;
|
std::vector<Node> nodes;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void LoadHistory();
|
void LoadHistory();
|
||||||
void ClearHistory();
|
void ClearHistory();
|
||||||
|
|
||||||
void ExtractFixed(std::vector<unsigned int> &selected, float error);
|
void ExtractFixed(std::vector<unsigned int> &selected, float error);
|
||||||
|
void Extract(std::vector<unsigned int> &selected, Policy *policy);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void Select(std::vector<unsigned int> &selected);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.6 2004/09/17 15:25:09 ponchio
|
||||||
|
First working (hopefully) release.
|
||||||
|
|
||||||
Revision 1.5 2004/09/16 14:25:16 ponchio
|
Revision 1.5 2004/09/16 14:25:16 ponchio
|
||||||
Backup. (lot of changes).
|
Backup. (lot of changes).
|
||||||
|
|
||||||
|
@ -72,6 +75,8 @@ using namespace std;
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
|
|
||||||
#include <apps/nexus/nexusmt.h>
|
#include <apps/nexus/nexusmt.h>
|
||||||
|
#include <wrap/gui/trackball.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace vcg;
|
using namespace vcg;
|
||||||
using namespace nxs;
|
using namespace nxs;
|
||||||
|
@ -124,18 +129,21 @@ bool init() {
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
enum Mode { SCREEN, GEO };
|
||||||
int level = 0;
|
int level = 0;
|
||||||
int apatch = -1;
|
int apatch = -1;
|
||||||
float geo_error = -1;
|
float error = 1;
|
||||||
float screen_error = -1;
|
Mode mode = SCREEN;
|
||||||
|
|
||||||
|
Trackball track;
|
||||||
int option;
|
int option;
|
||||||
|
|
||||||
while((option = getopt(argc, argv, "l:p:g:s:")) != EOF) {
|
while((option = getopt(argc, argv, "l:p:g:s:")) != EOF) {
|
||||||
switch(option) {
|
switch(option) {
|
||||||
case 'l': level = atoi(optarg); break;
|
case 'l': level = atoi(optarg); break;
|
||||||
case 'p': apatch = atoi(optarg); break;
|
case 'p': apatch = atoi(optarg); break;
|
||||||
case 'g': geo_error = (float)atof(optarg); break;
|
case 'g': mode = GEO; error = (float)atof(optarg); break;
|
||||||
case 's': screen_error = (float)atof(optarg); break;
|
case 's': mode = SCREEN; error = (float)atof(optarg); break;
|
||||||
default: cerr << "Unknown option: " << (char)option << endl;
|
default: cerr << "Unknown option: " << (char)option << endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -163,6 +171,9 @@ int main(int argc, char *argv[]) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FrustumPolicy frustum_policy;
|
||||||
|
|
||||||
|
|
||||||
bool rotate = true;
|
bool rotate = true;
|
||||||
bool show_borders = true;
|
bool show_borders = true;
|
||||||
glClearColor(0, 0, 0, 0);
|
glClearColor(0, 0, 0, 0);
|
||||||
|
@ -174,13 +185,23 @@ int main(int argc, char *argv[]) {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
int x, y;
|
int x, y;
|
||||||
float alpha = 0;
|
float alpha = 0;
|
||||||
while( !quit ) { while( SDL_PollEvent( &event ) ){
|
while( !quit ) {
|
||||||
|
while( SDL_PollEvent( &event ) ){
|
||||||
switch( event.type ) {
|
switch( event.type ) {
|
||||||
case SDL_QUIT: quit = 1; break;
|
case SDL_QUIT: quit = 1; break;
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
switch(event.key.keysym.sym) {
|
switch(event.key.keysym.sym) {
|
||||||
case SDLK_q: exit(0); break;
|
case SDLK_q: exit(0); break;
|
||||||
case SDLK_SPACE: rotate = !rotate;
|
case SDLK_b: show_borders = !show_borders;break;
|
||||||
|
case SDLK_r:
|
||||||
|
case SDLK_SPACE: rotate = !rotate; break;
|
||||||
|
|
||||||
|
case SDLK_MINUS: error *= 0.9;
|
||||||
|
cerr << "error: " << error << endl; break;
|
||||||
|
|
||||||
|
case SDLK_EQUALS:
|
||||||
|
case SDLK_PLUS: error *= 1.1;
|
||||||
|
cerr << "error: " << error << endl; break;
|
||||||
}
|
}
|
||||||
//quit = 1;
|
//quit = 1;
|
||||||
//error++;
|
//error++;
|
||||||
|
@ -189,46 +210,65 @@ int main(int argc, char *argv[]) {
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
x = event.button.x;
|
x = event.button.x;
|
||||||
y = event.button.y;
|
y = height - event.button.y;
|
||||||
|
if(event.button.button == SDL_BUTTON_WHEELUP) {
|
||||||
|
track.MouseWheel(1);
|
||||||
|
} else if(event.button.button == SDL_BUTTON_WHEELDOWN) {
|
||||||
|
track.MouseWheel(-1);
|
||||||
|
} else
|
||||||
|
track.MouseDown(x, y, 1);
|
||||||
// hand.buttonDown(x, y, 1);
|
// hand.buttonDown(x, y, 1);
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEBUTTONUP:
|
case SDL_MOUSEBUTTONUP:
|
||||||
x = event.button.x;
|
x = event.button.x;
|
||||||
y = event.button.y;
|
y = height - event.button.y;
|
||||||
|
track.MouseUp(x, y, 1);
|
||||||
// hand.buttonUp(x, y);
|
// hand.buttonUp(x, y);
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
while(SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_MOUSEMOTIONMASK));
|
while(SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_MOUSEMOTIONMASK));
|
||||||
x = event.motion.x;
|
x = event.motion.x;
|
||||||
y = event.motion.y;
|
y = height - event.motion.y;
|
||||||
|
track.MouseMove(x, y);
|
||||||
// hand.mouseMove(x, y);
|
// hand.mouseMove(x, y);
|
||||||
break;
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluPerspective(40, 1, 0.1, 100);
|
gluPerspective(40, 1, 0.1, 100);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluLookAt(0,0,6, 0,0,0, 0,1,0);
|
gluLookAt(0,0,5, 0,0,0, 0,1,0);
|
||||||
|
|
||||||
|
|
||||||
|
track.GetView();
|
||||||
|
track.Apply();
|
||||||
|
|
||||||
float scale = 2/sphere.Radius();
|
float scale = 2/sphere.Radius();
|
||||||
glRotatef(alpha, 0, 1, 0);
|
// glRotatef(alpha, 0, 1, 0);
|
||||||
if(rotate)
|
// if(rotate)
|
||||||
alpha++;
|
// alpha++;
|
||||||
if(alpha > 360) alpha = 0;
|
// if(alpha > 360) alpha = 0;
|
||||||
glScalef(scale, scale, scale);
|
glScalef(scale, scale, scale);
|
||||||
Point3f center = sphere.Center();
|
Point3f center = sphere.Center();
|
||||||
glTranslatef(-center[0], -center[1], -center[2]);
|
glTranslatef(-center[0], -center[1], -center[2]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
vector<unsigned int> cells;
|
vector<unsigned int> cells;
|
||||||
if(apatch != -1) {
|
if(apatch != -1) {
|
||||||
cells.push_back(apatch);
|
cells.push_back(apatch);
|
||||||
} else if(geo_error != -1) {
|
} else if(mode == GEO) {
|
||||||
nexus.ExtractFixed(cells, geo_error);
|
nexus.ExtractFixed(cells, error);
|
||||||
|
} else if(mode == SCREEN) {
|
||||||
|
frustum_policy.error = error;
|
||||||
|
frustum_policy.GetView();
|
||||||
|
nexus.Extract(cells, &frustum_policy);
|
||||||
} else {
|
} else {
|
||||||
for(int i = 0; i < nexus.index.size(); i++) {
|
for(int i = 0; i < nexus.index.size(); i++) {
|
||||||
if(nexus.index[i].error == 0)
|
if(nexus.index[i].error == 0)
|
||||||
|
@ -246,6 +286,11 @@ int main(int argc, char *argv[]) {
|
||||||
((val * 37)%128) + 128,
|
((val * 37)%128) + 128,
|
||||||
((val * 87)%128) + 128);
|
((val * 87)%128) + 128);
|
||||||
|
|
||||||
|
/* Nexus::Entry &entry = nexus.index[cell];
|
||||||
|
float error = entry.error;
|
||||||
|
if(error < 1) error = 0;
|
||||||
|
glColor3ub(log(error) * 50, 128, 128);*/
|
||||||
|
|
||||||
glBegin(GL_TRIANGLES);
|
glBegin(GL_TRIANGLES);
|
||||||
unsigned short *f = patch.FaceBegin();
|
unsigned short *f = patch.FaceBegin();
|
||||||
for(unsigned int j = 0; j < patch.nf*3; j+= 3) {
|
for(unsigned int j = 0; j < patch.nf*3; j+= 3) {
|
||||||
|
|
Loading…
Reference in New Issue