Minor changes (visited and Cell)

This commit is contained in:
Federico Ponchio 2005-02-19 16:22:45 +00:00
parent 2bbfa50b0c
commit eed1577b2e
6 changed files with 121 additions and 90 deletions

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.7 2005/02/10 09:18:20 ponchio
Statistics.
Revision 1.6 2005/02/08 12:43:03 ponchio Revision 1.6 2005/02/08 12:43:03 ponchio
Added copyright Added copyright
@ -58,7 +61,7 @@ void Extraction::Extract(NexusMt *_mt) {
//first we clear the visited flags //first we clear the visited flags
visited.clear(); visited.clear();
visited.resize(mt->history.n_nodes(), false); visited.resize(mt->history.n_nodes(), 0);
heap.clear(); heap.clear();
@ -70,7 +73,7 @@ void Extraction::Extract(NexusMt *_mt) {
heap.pop_back(); heap.pop_back();
Node *node = hnode.node; Node *node = hnode.node;
if(visited[node - root]) continue; if(Visited(node)) continue;
if(Expand(hnode)) if(Expand(hnode))
Visit(node); Visit(node);
@ -90,35 +93,43 @@ void Extraction::Init() {
Node *nodes = mt->history.nodes; Node *nodes = mt->history.nodes;
for(unsigned int i = 0; i < visited.size(); i++) { for(unsigned int i = 0; i < visited.size(); i++) {
if(!visited[i]) continue; if(!visited[i]) continue;
// if(!visited[i]) continue;
Node &node = nodes[i]; Node &node = nodes[i];
bool cancoarse = true; bool cancoarse = true;
Node::iterator n; Node::iterator n;
for(n = node.out_begin(); n != node.out_end(); n++) { for(n = node.out_begin(); n != node.out_end(); n++) {
if(!Visited((*n).node)) {
// if(!visited[(*n).node - root]) {
float maxerror = -1;
Link &link = *n;
for(Link::iterator k = link.begin(); k != link.end(); k++) {
unsigned int patch = *k;
Entry &entry = (*mt)[patch];
bool visible;
float error = metric->GetError(entry, visible);
if(!visited[(*n).node - root]) { if(error > maxerror) maxerror = error;
float maxerror = -1;
cost.extr += entry.ram_size;
Link &link = *n; //TODO if(frustum) else
for(Link::iterator k = link.begin(); k != link.end(); k++) { //if(visible)
unsigned int patch = (*k).patch; // cost.draw += entry.ram_size;
Entry &entry = (*mt)[patch];
vcg::Sphere3f &sphere = entry.sphere;
float error = metric->GetError(entry); if(!frustum.IsOutside(sphere.Center(), sphere.Radius()))
if(error > maxerror) maxerror = error; cost.draw += entry.ram_size;
cost.extr += entry.ram_size; if(!entry.patch)
vcg::Sphere3f &sphere = entry.sphere; cost.disk += entry.disk_size;
if(!frustum.IsOutside(sphere.Center(), sphere.Radius())) }
cost.draw += entry.ram_size; if((*n).node != sink && maxerror > target_error)
if(!entry.patch) front.push_back(HeapNode((*n).node, maxerror));
cost.disk += entry.disk_size; if(maxerror > max_error) max_error = maxerror;
}
if((*n).node != sink && maxerror > target_error)
front.push_back(HeapNode((*n).node, maxerror));
if(maxerror > max_error) max_error = maxerror;
} else } else
cancoarse = false; cancoarse = false;
} }
if(cancoarse && &node != root) { if(cancoarse && &node != root) {
float error = GetRefineError(&node); float error = GetRefineError(&node);
@ -141,7 +152,7 @@ void Extraction::Update(NexusMt *_mt) {
if(!visited.size()) { if(!visited.size()) {
visited.resize(mt->history.n_nodes(), false); visited.resize(mt->history.n_nodes(), false);
visited[0] = true; SetVisited(root, true);
} }
Init(); Init();
@ -202,7 +213,7 @@ void Extraction::Update(NexusMt *_mt) {
Node::iterator i; Node::iterator i;
for(i = hnode.node->out_begin(); i != hnode.node->out_end(); i++) { for(i = hnode.node->out_begin(); i != hnode.node->out_end(); i++) {
Node *child = (*i).node; Node *child = (*i).node;
if(visited[child-root]) recursive = true; if(Visited(child)) recursive = true;
} }
if(!recursive && !Coarse(hnode)) { //no more disk so.. push back on heap the heapnode if(!recursive && !Coarse(hnode)) { //no more disk so.. push back on heap the heapnode
back.push_back(hnode); back.push_back(hnode);
@ -227,11 +238,11 @@ void Extraction::Update(NexusMt *_mt) {
front.pop_back(); front.pop_back();
Node::iterator l; Node::iterator l;
for(l = node->out_begin(); l != node->out_end(); l++) { for(l = node->out_begin(); l != node->out_end(); l++) {
Link &link = (*l); Link &link = (*l);
for(Link::iterator k = link.begin(); k != link.end(); k++) { for(Link::iterator k = link.begin(); k != link.end(); k++) {
selected.push_back(Item((*k).patch, i)); selected.push_back(Item(*k, i));
errors[(*k).patch] = i; errors[*k] = i;
} }
} }
} else if(back.size()) { } else if(back.size()) {
pop_heap(back.begin(), back.end(), greater<HeapNode>()); pop_heap(back.begin(), back.end(), greater<HeapNode>());
@ -240,11 +251,11 @@ void Extraction::Update(NexusMt *_mt) {
back.pop_back(); back.pop_back();
Node::iterator l; Node::iterator l;
for(l = node->in_begin(); l != node->in_end(); l++) { for(l = node->in_begin(); l != node->in_end(); l++) {
Link &link = (*l); Link &link = (*l);
for(Link::iterator k = link.begin(); k != link.end(); k++) { for(Link::iterator k = link.begin(); k != link.end(); k++) {
selected.push_back(Item((*k).patch, i)); selected.push_back(Item(*k, i));
errors[(*k).patch] = i; errors[*k] = i;
} }
} }
} }
} }
@ -256,8 +267,9 @@ float Extraction::GetRefineError(Node *node) {
for(i = node->in_begin(); i != node->in_end(); i++) { for(i = node->in_begin(); i != node->in_end(); i++) {
Link &link = *i; Link &link = *i;
for(Link::iterator k = link.begin(); k != link.end(); k++) { for(Link::iterator k = link.begin(); k != link.end(); k++) {
Entry &entry = (*mt)[(*k).patch]; Entry &entry = (*mt)[*k];
float error = metric->GetError(entry); bool visible;
float error = metric->GetError(entry, visible);
if(error > maxerror) maxerror = error; if(error > maxerror) maxerror = error;
} }
} }
@ -267,7 +279,6 @@ float Extraction::GetRefineError(Node *node) {
bool Extraction::Refine(HeapNode hnode) { bool Extraction::Refine(HeapNode hnode) {
Node *node = hnode.node; Node *node = hnode.node;
//cerr << "Refine node: " << (void *)hnode.node << " err: " << hnode.error << endl;
//recursively refine parent if applicable. //recursively refine parent if applicable.
Node::iterator i; Node::iterator i;
@ -305,7 +316,7 @@ bool Extraction::Refine(HeapNode hnode) {
draw_used += cost.draw; draw_used += cost.draw;
disk_used += cost.disk; disk_used += cost.disk;
visited[node - root] = true; SetVisited(node, true);
//now add to the front children (unless sink node) //now add to the front children (unless sink node)
@ -349,7 +360,7 @@ bool Extraction::Coarse(HeapNode hnode) {
if(disk_used > disk_max) return false; if(disk_used > disk_max) return false;
visited[node - root] = false; SetVisited(node, false);
//now add to the back parents (unless root node) //now add to the back parents (unless root node)
for(i = node->in_begin(); i != node->in_end(); i++) { for(i = node->in_begin(); i != node->in_end(); i++) {
@ -381,7 +392,7 @@ void Extraction::Select() {
if(!visited[n_out]) { if(!visited[n_out]) {
Link &link = *n; Link &link = *n;
for(Link::iterator k = link.begin(); k != link.end(); k++) { for(Link::iterator k = link.begin(); k != link.end(); k++) {
unsigned int patch = (*k).patch; unsigned int patch = *k;
selected.push_back(Item(patch,0)); selected.push_back(Item(patch,0));
errors[patch] = 0.0f; errors[patch] = 0.0f;
} }
@ -391,14 +402,13 @@ void Extraction::Select() {
} }
void Extraction::Visit(Node *node) { void Extraction::Visit(Node *node) {
if(visited[node - root]) return; assert(!Visited(node));
visited[node - root] = true; SetVisited(node, true);
Node::iterator i; Node::iterator i;
for(i = node->in_begin(); i != node->in_end(); i++) { for(i = node->in_begin(); i != node->in_end(); i++) {
unsigned int n_in = (*i).node - root; if(Visited((*i).node)) continue;
if(visited[n_in]) continue;
Visit((*i).node); Visit((*i).node);
} }
@ -412,8 +422,9 @@ void Extraction::Visit(Node *node) {
float maxerror = -1; float maxerror = -1;
Link &link = *i; Link &link = *i;
for(Link::iterator k = link.begin(); k != link.end(); k++) { for(Link::iterator k = link.begin(); k != link.end(); k++) {
Entry &entry = (*mt)[(*k).patch]; Entry &entry = (*mt)[*k];
float error = metric->GetError(entry); bool visible;
float error = metric->GetError(entry, visible);
if(error > maxerror) maxerror = error; if(error > maxerror) maxerror = error;
} }
//TODO this check may be dangerous for non saturating things... //TODO this check may be dangerous for non saturating things...
@ -437,7 +448,7 @@ void Extraction::Diff(Node *node, Cost &cost) {
for(i = node->in_begin(); i != node->in_end(); i++) { for(i = node->in_begin(); i != node->in_end(); i++) {
Link &link = *i; Link &link = *i;
for(Link::iterator k = link.begin(); k != link.end(); k++) { for(Link::iterator k = link.begin(); k != link.end(); k++) {
unsigned int patch = (*k).patch; unsigned int patch = *k;
Entry &entry = (*mt)[patch]; Entry &entry = (*mt)[patch];
cost.extr -= entry.ram_size; cost.extr -= entry.ram_size;
vcg::Sphere3f &sphere = entry.sphere; vcg::Sphere3f &sphere = entry.sphere;
@ -451,7 +462,7 @@ void Extraction::Diff(Node *node, Cost &cost) {
for(i = node->out_begin(); i != node->out_end(); i++) { for(i = node->out_begin(); i != node->out_end(); i++) {
Link &link = *i; Link &link = *i;
for(Link::iterator k = link.begin(); k != link.end(); k++) { for(Link::iterator k = link.begin(); k != link.end(); k++) {
unsigned int patch = (*k).patch; unsigned int patch = *k;
Entry &entry = (*mt)[patch]; Entry &entry = (*mt)[patch];
cost.extr += entry.ram_size; cost.extr += entry.ram_size;
vcg::Sphere3f &sphere = entry.sphere; vcg::Sphere3f &sphere = entry.sphere;

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.7 2005/02/10 09:18:20 ponchio
Statistics.
Revision 1.6 2005/02/08 12:43:03 ponchio Revision 1.6 2005/02/08 12:43:03 ponchio
Added copyright Added copyright
@ -79,6 +82,7 @@ class Extraction {
Metric *metric; Metric *metric;
//TODO make a pointer so no need to doubl check visibility...!
vcg::Frustumf frustum; vcg::Frustumf frustum;
float target_error; float target_error;
@ -88,6 +92,7 @@ class Extraction {
unsigned int disk_used, disk_max; unsigned int disk_used, disk_max;
std::vector<bool> visited; std::vector<bool> visited;
std::vector<bool> visible;
std::map<unsigned int, float> errors; std::map<unsigned int, float> errors;
std::vector<Item> selected; std::vector<Item> selected;
@ -126,9 +131,10 @@ class Extraction {
Node *root; Node *root;
Node *sink; Node *sink;
bool Visited(Node *node) { bool Visited(Node *node) { return visited[node - root]; }
return visited[node - root]; void SetVisited(Node *node, bool v) { visited[node - root] = v; }
} bool Visible(Node *node) { return visible[node - root]; }
void SetVisible(Node *node, bool v) { visible[node - root] = v; }
float GetRefineError(Node *node); float GetRefineError(Node *node);
}; };

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.6 2005/02/17 16:40:35 ponchio
Optimized BuildLevels.
Revision 1.5 2005/02/08 12:43:03 ponchio Revision 1.5 2005/02/08 12:43:03 ponchio
Added copyright Added copyright
@ -85,12 +88,12 @@ bool History::LoadQuick(unsigned int _size, char *mem) {
nodes = (Node *)(buffer + 5 * sizeof(int)); nodes = (Node *)(buffer + 5 * sizeof(int));
in_links = (Link *)(nodes + n_nodes()); in_links = (Link *)(nodes + n_nodes());
out_links = in_links + n_in_links(); out_links = in_links + n_in_links();
frags = (Cell *)(out_links + n_out_links()); frags = (unsigned int *)(out_links + n_out_links());
//check size is ok; //check size is ok;
assert(n_nodes() * sizeof(Node) + assert(n_nodes() * sizeof(Node) +
(n_in_links() + n_out_links()) * sizeof(Link) + (n_in_links() + n_out_links()) * sizeof(Link) +
n_frags() * sizeof(Cell) + n_frags() * sizeof(unsigned int) +
5 * sizeof(int) == size); 5 * sizeof(int) == size);
size = _size; size = _size;
return LoadPointers(); return LoadPointers();
@ -165,13 +168,13 @@ char *History::SaveQuick(unsigned int &_size) {
for(unsigned int i = 0; i < n_in_links(); i++) { for(unsigned int i = 0; i < n_in_links(); i++) {
Link &link = in_links[i]; Link &link = in_links[i];
link.node = (Node *)(link.node - nodes); link.node = (Node *)(link.node - nodes);
link.frag_begin = (Cell *)(link.frag_begin - frags); link.frag_begin = (unsigned int *)(link.frag_begin - frags);
} }
for(unsigned int i = 0; i < n_out_links(); i++) { for(unsigned int i = 0; i < n_out_links(); i++) {
Link &link = out_links[i]; Link &link = out_links[i];
link.node = (Node *)(link.node - nodes); link.node = (Node *)(link.node - nodes);
link.frag_begin = (Cell *)(link.frag_begin - frags); link.frag_begin = (unsigned int *)(link.frag_begin - frags);
} }
_size = size; _size = size;
@ -212,7 +215,7 @@ bool History::UpdatesToQuick() {
vector<Link> tmp_in_links; vector<Link> tmp_in_links;
vector<Link> tmp_out_links; vector<Link> tmp_out_links;
vector<Cell> tmp_frags; vector<unsigned int> tmp_frags;
unsigned int current_node = 0; unsigned int current_node = 0;
@ -252,21 +255,19 @@ bool History::UpdatesToQuick() {
Link inlink; Link inlink;
inlink.node = (Node *)floor_node; inlink.node = (Node *)floor_node;
inlink.frag_begin = (Cell *)(tmp_frags.size()); inlink.frag_begin = (unsigned int *)(tmp_frags.size());
inlink.frag_size = cells.size(); inlink.frag_size = cells.size();
Link outlink; Link outlink;
outlink.node = (Node *)current_node; outlink.node = (Node *)current_node;
outlink.frag_begin = (Cell *)(tmp_frags.size()); outlink.frag_begin = (unsigned int *)(tmp_frags.size());
outlink.frag_size = cells.size(); outlink.frag_size = cells.size();
//Fill it with erased cells. //Fill it with erased cells.
vector<unsigned int>::iterator k; vector<unsigned int>::iterator k;
for(k = cells.begin(); k != cells.end(); k++) { for(k = cells.begin(); k != cells.end(); k++) {
Cell cell; tmp_frags.push_back(*k);
cell.patch = (*k);
tmp_frags.push_back(cell);
} }
//Add the new Frag to the node. //Add the new Frag to the node.
@ -302,7 +303,7 @@ bool History::UpdatesToQuick() {
size = tmp_nodes.size() * sizeof(Node) + size = tmp_nodes.size() * sizeof(Node) +
tmp_in_links.size() * sizeof(Link) + tmp_in_links.size() * sizeof(Link) +
tmp_out_links.size() * sizeof(Link) + tmp_out_links.size() * sizeof(Link) +
tmp_frags.size() * sizeof(Cell) + tmp_frags.size() * sizeof(unsigned int) +
5 * sizeof(int); 5 * sizeof(int);
if(buffer) delete []buffer; if(buffer) delete []buffer;
@ -317,13 +318,13 @@ bool History::UpdatesToQuick() {
nodes = (Node *)(buffer + 5 * sizeof(int)); nodes = (Node *)(buffer + 5 * sizeof(int));
in_links = (Link *)(nodes + n_nodes()); in_links = (Link *)(nodes + n_nodes());
out_links = in_links + n_in_links(); out_links = in_links + n_in_links();
frags = (Cell *)(out_links + n_out_links()); frags = (unsigned int *)(out_links + n_out_links());
memcpy(nodes, &*tmp_nodes.begin(), tmp_nodes.size()*sizeof(Node)); memcpy(nodes, &*tmp_nodes.begin(), tmp_nodes.size()*sizeof(Node));
memcpy(in_links, &*tmp_in_links.begin(), tmp_in_links.size()*sizeof(Link)); memcpy(in_links, &*tmp_in_links.begin(), tmp_in_links.size()*sizeof(Link));
memcpy(out_links, &*tmp_out_links.begin(), memcpy(out_links, &*tmp_out_links.begin(),
tmp_out_links.size()*sizeof(Link)); tmp_out_links.size()*sizeof(Link));
memcpy(frags, &*tmp_frags.begin(), tmp_frags.size() * sizeof(Cell)); memcpy(frags, &*tmp_frags.begin(), tmp_frags.size() * sizeof(unsigned int));
return LoadPointers(); return LoadPointers();
} }
@ -338,7 +339,7 @@ void History::BuildLevels(vector<int> &levels) {
unsigned int current = 0; unsigned int current = 0;
if(node != nodes) { //not root if(node != nodes) { //not root
Link *inlink = node->in_begin(); Link *inlink = node->in_begin();
unsigned int p = inlink->begin()->patch; unsigned int p = *(inlink->begin());
assert(p < levels.size()); assert(p < levels.size());
assert(p >= 0); assert(p >= 0);
current = levels[p]+1; current = levels[p]+1;
@ -347,7 +348,7 @@ void History::BuildLevels(vector<int> &levels) {
Link &link = *l; Link &link = *l;
Link::iterator c; Link::iterator c;
for(c = link.begin(); c != link.end(); c++) { for(c = link.begin(); c != link.end(); c++) {
unsigned int p = (*c).patch; unsigned int p = *c;
while(p >= levels.size()) levels.push_back(-1); while(p >= levels.size()) levels.push_back(-1);
levels[p] = current; levels[p] = current;
} }

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.4 2005/02/17 16:40:35 ponchio
Optimized BuildLevels.
Revision 1.3 2005/02/08 12:43:03 ponchio Revision 1.3 2005/02/08 12:43:03 ponchio
Added copyright Added copyright
@ -50,22 +53,22 @@ namespace nxs {
std::vector<unsigned int> created; std::vector<unsigned int> created;
}; };
struct Cell { // struct Cell {
unsigned int patch; // unsigned int patch;
// float error; // float error;
}; // };
struct Node; struct Node;
struct Link { struct Link {
Node *node; Node *node;
typedef Cell *iterator; typedef unsigned int *iterator;
iterator begin() { return frag_begin; } iterator begin() { return frag_begin; }
iterator end() { return frag_begin + frag_size; } iterator end() { return frag_begin + frag_size; }
unsigned int size() { return frag_size; } unsigned int size() { return frag_size; }
Cell *frag_begin; unsigned int *frag_begin;
unsigned int frag_size; unsigned int frag_size;
}; };
@ -89,7 +92,8 @@ namespace nxs {
Node *nodes; Node *nodes;
Link *in_links; Link *in_links;
Link *out_links; Link *out_links;
Cell *frags; //TODO this list is really not necessary if we order our cells
unsigned int *frags;
std::vector<Update> updates; std::vector<Update> updates;

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.4 2005/02/08 12:43:03 ponchio
Added copyright
****************************************************************************/ ****************************************************************************/
@ -41,12 +44,14 @@ namespace nxs {
class Metric { class Metric {
public: public:
virtual void GetView() {} virtual void GetView() {}
virtual float GetError(Entry &entry) = 0; virtual float GetError(Entry &entry, bool &visible) = 0;
}; };
class FlatMetric: public Metric { class FlatMetric: public Metric {
public: public:
float GetError(Entry &entry) { return entry.error; } float GetError(Entry &entry, bool &visible) {
visible = true;
return entry.error; }
}; };
class FrustumMetric: public Metric { class FrustumMetric: public Metric {
@ -54,21 +59,20 @@ namespace nxs {
vcg::Frustumf frustum; vcg::Frustumf frustum;
virtual void GetView() { frustum.GetView(); } virtual void GetView() { frustum.GetView(); }
float GetError(Entry &entry) { float GetError(Entry &entry, bool &visible) {
vcg::Sphere3f &sphere = entry.sphere; visible = true;
float dist = (sphere.Center() - frustum.ViewPoint()).Norm() - sphere.Radius(); vcg::Sphere3f &sph = entry.sphere;
//float dist = Distance(sphere, frustum.ViewPoint()); float dist = (sph.Center() - frustum.ViewPoint()).Norm() - sph.Radius();
if(dist < 0)
return 1e20f;
float remote = frustum.Remoteness(sphere.Center(), sphere.Radius()); if(dist < 0) return 1e20f;
if(remote > 0)
return (entry.error/remote)/frustum.Resolution(dist);
//if(frustum.IsOutside(sphere.Center(), sphere.Radius())) float remote = frustum.Remoteness(sph.Center(), sph.Radius());
//return -1; float error = entry.error/frustum.Resolution(dist);
if(remote > 0) {
return entry.error/frustum.Resolution(dist); visible = false;
error /= remote;
}
return error;
} }
}; };
} }

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.21 2005/02/19 10:45:04 ponchio
Patch generalized and small fixes.
Revision 1.20 2005/02/08 12:43:03 ponchio Revision 1.20 2005/02/08 12:43:03 ponchio
Added copyright Added copyright
@ -40,6 +43,7 @@ Added copyright
#include <vcg/space/sphere3.h> #include <vcg/space/sphere3.h>
#include "normalscone.h"
#include "patch.h" #include "patch.h"
#include "index_file.h" #include "index_file.h"
#include "history.h" #include "history.h"
@ -72,6 +76,7 @@ struct Entry {
vcg::Sphere3f sphere; vcg::Sphere3f sphere;
float error; float error;
NCone3s cone;
Patch *patch; Patch *patch;
unsigned int vbo_array; unsigned int vbo_array;