Less memory x extraction. (removed frags)

This commit is contained in:
Federico Ponchio 2005-02-20 00:43:24 +00:00
parent e9932cfb95
commit a99a702c9c
9 changed files with 164 additions and 97 deletions

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.8 2005/02/19 16:22:45 ponchio
Minor changes (visited and Cell)
Revision 1.7 2005/02/10 09:18:20 ponchio
Statistics.
@ -105,7 +108,8 @@ void Extraction::Init() {
Link &link = *n;
for(Link::iterator k = link.begin(); k != link.end(); k++) {
unsigned int patch = *k;
// unsigned int patch = *k;
unsigned int patch = k;
Entry &entry = (*mt)[patch];
bool visible;
@ -240,8 +244,10 @@ void Extraction::Update(NexusMt *_mt) {
for(l = node->out_begin(); l != node->out_end(); l++) {
Link &link = (*l);
for(Link::iterator k = link.begin(); k != link.end(); k++) {
selected.push_back(Item(*k, i));
errors[*k] = i;
// selected.push_back(Item(*k, i));
// errors[*k] = i;
selected.push_back(Item(k, i));
errors[k] = i;
}
}
} else if(back.size()) {
@ -253,8 +259,10 @@ void Extraction::Update(NexusMt *_mt) {
for(l = node->in_begin(); l != node->in_end(); l++) {
Link &link = (*l);
for(Link::iterator k = link.begin(); k != link.end(); k++) {
selected.push_back(Item(*k, i));
errors[*k] = i;
// selected.push_back(Item(*k, i));
// errors[*k] = i;
selected.push_back(Item(k, i));
errors[k] = i;
}
}
}
@ -266,8 +274,8 @@ float Extraction::GetRefineError(Node *node) {
Node::iterator i;
for(i = node->in_begin(); i != node->in_end(); i++) {
Link &link = *i;
for(Link::iterator k = link.begin(); k != link.end(); k++) {
Entry &entry = (*mt)[*k];
for(Link::iterator p = link.begin(); p != link.end(); p++) {
Entry &entry = (*mt)[p];
bool visible;
float error = metric->GetError(entry, visible);
if(error > maxerror) maxerror = error;
@ -391,10 +399,14 @@ void Extraction::Select() {
unsigned int n_out = (*n).node - root;
if(!visited[n_out]) {
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;
selected.push_back(Item(patch,0));
errors[patch] = 0.0f;
}*/
for(Link::iterator p= link.begin(); p != link.end(); p++) {
selected.push_back(Item(p, 0));
errors[p] = 0.0f;
}
}
}
@ -421,8 +433,8 @@ void Extraction::Visit(Node *node) {
for(i = node->out_begin(); i != node->out_end(); i++) {
float maxerror = -1;
Link &link = *i;
for(Link::iterator k = link.begin(); k != link.end(); k++) {
Entry &entry = (*mt)[*k];
for(Link::iterator p = link.begin(); p != link.end(); p++) {
Entry &entry = (*mt)[p];
bool visible;
float error = metric->GetError(entry, visible);
if(error > maxerror) maxerror = error;
@ -447,9 +459,8 @@ void Extraction::Diff(Node *node, Cost &cost) {
Node::iterator i;
for(i = node->in_begin(); i != node->in_end(); i++) {
Link &link = *i;
for(Link::iterator k = link.begin(); k != link.end(); k++) {
unsigned int patch = *k;
Entry &entry = (*mt)[patch];
for(Link::iterator p = link.begin(); p != link.end(); p++) {
Entry &entry = (*mt)[p];
cost.extr -= entry.ram_size;
vcg::Sphere3f &sphere = entry.sphere;
if(!frustum.IsOutside(sphere.Center(), sphere.Radius()))
@ -461,9 +472,8 @@ void Extraction::Diff(Node *node, Cost &cost) {
for(i = node->out_begin(); i != node->out_end(); i++) {
Link &link = *i;
for(Link::iterator k = link.begin(); k != link.end(); k++) {
unsigned int patch = *k;
Entry &entry = (*mt)[patch];
for(Link::iterator p = link.begin(); p != link.end(); p++) {
Entry &entry = (*mt)[p];
cost.extr += entry.ram_size;
vcg::Sphere3f &sphere = entry.sphere;
if(!frustum.IsOutside(sphere.Center(), sphere.Radius()))

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.8 2005/02/19 17:14:02 ponchio
History quick by default.
Revision 1.7 2005/02/19 16:22:45 ponchio
Minor changes (visited and Cell)
@ -41,6 +44,7 @@ Added copyright
#include <iostream>
#include "history.h"
#include "nexus.h"
using namespace std;
@ -51,7 +55,6 @@ History::~History() {
nodes = NULL;
in_links= NULL;
out_links = NULL;
frags = NULL;
}
void History::Clear() {
@ -74,10 +77,8 @@ bool History::Load(unsigned int _size, char *mem) {
unsigned int is_quick = *(unsigned int *)mem;
bool success;
if(is_quick == 53) {
// cerr << "Load quick!\n";
success = LoadQuick(_size, mem);
} else if(is_quick == 32) {
// cerr << "Load updates\n";
success = LoadUpdates(_size, mem);
} else {
cerr << "Invalid history: " << is_quick << "\n";
@ -88,16 +89,14 @@ bool History::Load(unsigned int _size, char *mem) {
bool History::LoadQuick(unsigned int _size, char *mem) {
buffer = mem;
nodes = (Node *)(buffer + 5 * sizeof(int));
nodes = (Node *)(buffer + 4 * sizeof(int));
in_links = (Link *)(nodes + n_nodes());
out_links = in_links + n_in_links();
frags = (unsigned int *)(out_links + n_out_links());
//check size is ok;
assert(n_nodes() * sizeof(Node) +
(n_in_links() + n_out_links()) * sizeof(Link) +
n_frags() * sizeof(unsigned int) +
5 * sizeof(int) == _size);
4 * sizeof(int) == _size);
size = _size;
return LoadPointers();
}
@ -135,29 +134,22 @@ bool History::LoadPointers() {
for(unsigned int i = 0; i < n_in_links(); i++) {
Link &link = in_links[i];
assert(((unsigned int)link.node) <= n_nodes());
assert(((unsigned int)link.frag_begin) <= n_frags());
link.node = nodes + (unsigned int)(link.node);
link.frag_begin = frags + (unsigned int)(link.frag_begin);
}
for(unsigned int i = 0; i < n_out_links(); i++) {
Link &link = out_links[i];
assert(((unsigned int)link.node) <= n_nodes());
assert(((unsigned int)link.frag_begin) <= n_frags());
link.node = nodes + (unsigned int)(link.node);
link.frag_begin = frags + (unsigned int)(link.frag_begin);
}
return true;
}
char *History::Save(unsigned int &_size) {
if(buffer) {
// cerr << "SaveQuick!\n";
if(buffer)
return SaveQuick(_size);
} else {
// cerr << "Save updates\n";
else
return SaveUpdates(_size);
}
}
char *History::SaveQuick(unsigned int &_size) {
@ -171,19 +163,16 @@ char *History::SaveQuick(unsigned int &_size) {
for(unsigned int i = 0; i < n_in_links(); i++) {
Link &link = in_links[i];
link.node = (Node *)(link.node - nodes);
link.frag_begin = (unsigned int *)(link.frag_begin - frags);
}
for(unsigned int i = 0; i < n_out_links(); i++) {
Link &link = out_links[i];
link.node = (Node *)(link.node - nodes);
link.frag_begin = (unsigned int *)(link.frag_begin - frags);
}
assert(n_nodes() * sizeof(Node) +
(n_in_links() + n_out_links()) * sizeof(Link) +
n_frags() * sizeof(unsigned int) +
5 * sizeof(int) == size);
4 * sizeof(int) == size);
_size = size;
char *tmp = buffer;
@ -211,7 +200,7 @@ char *History::SaveUpdates(unsigned int &_size) {
return mem;
}
bool History::UpdatesToQuick() {
bool History::UpdatesToQuick(Nexus &nexus) {
//maps cell -> node containing it
map<unsigned int, unsigned int> cell_node;
//maps node -> Links
@ -229,7 +218,6 @@ bool History::UpdatesToQuick() {
vector<Update>::iterator u;
for(u = updates.begin(); u != updates.end(); u++) {
Node &node = tmp_nodes[current_node];
//created cells belong to this node,
@ -238,8 +226,7 @@ bool History::UpdatesToQuick() {
cell_node[cell] = current_node;
}
//Every erased cell already belonged to a node.
//node -> its cells
//Every erased cell already belonged to a node //node -> its cells
map<unsigned int, vector<unsigned int> > node_erased;
for(unsigned int i = 0; i < (*u).erased.size(); i++) {
@ -248,14 +235,11 @@ bool History::UpdatesToQuick() {
node_erased[cell_node[cell]].push_back(cell);
}
//for every node with erased cells we build a fragment and
//put the corresponding cells in it.
map<unsigned int, vector<unsigned int> >::iterator e;
for(e = node_erased.begin(); e != node_erased.end(); e++) {
//node.in.push_back(innodes.size());
unsigned int floor_node = (*e).first;
vector<unsigned int> &cells = (*e).second;
@ -263,27 +247,22 @@ bool History::UpdatesToQuick() {
Link inlink;
inlink.node = (Node *)floor_node;
inlink.frag_begin = (unsigned int *)(tmp_frags.size());
inlink.frag_begin = tmp_frags.size();
inlink.frag_size = cells.size();
Link outlink;
outlink.node = (Node *)current_node;
outlink.frag_begin = (unsigned int *)(tmp_frags.size());
outlink.frag_begin = tmp_frags.size();
outlink.frag_size = cells.size();
//Fill it with erased cells.
vector<unsigned int>::iterator k;
for(k = cells.begin(); k != cells.end(); k++) {
for(k = cells.begin(); k != cells.end(); k++)
tmp_frags.push_back(*k);
}
//Add the new Frag to the node.
//Add the new Frag to the nodes (in and out)
node_outlinks[floor_node].push_back(outlink);
node_inlinks[current_node].push_back(inlink);
//Update in and out of the nodes.
}
current_node++;
}
@ -308,11 +287,47 @@ bool History::UpdatesToQuick() {
for(unsigned int i = 0; i < links.size(); i++)
tmp_in_links.push_back(links[i]);
}
//Here we reorder entries in nexus...
nexus.Flush();
vector<Entry> entries;
entries.resize(nexus.size());
for(unsigned int i = 0; i < nexus.size(); i++) {
assert(!nexus[i].patch);
entries[i] = nexus[i];
}
assert(tmp_frags.size() == nexus.size());
for(unsigned int i = 0; i < tmp_frags.size(); i++) {
nexus[i] = entries[tmp_frags[i]];
}
//WARNING CRITICAL TODOHey we should do the same on the borders!
vector<unsigned int> backward;
backward.resize(tmp_frags.size());
for(unsigned int i = 0; i < backward.size(); i++)
backward[tmp_frags[i]] = i;
for(unsigned int i = 0; i < nexus.borders.size(); i++) {
Border &border = nexus.borders.GetBorder(i);
for(unsigned int k = 0; k < border.Size(); k++)
border[k].end_patch = backward[border[k].end_patch];
}
nexus.borders.Flush();
vector<Border> borders;
borders.resize(nexus.borders.size());
for(unsigned int i = 0; i < nexus.borders.size(); i++) {
borders[i] = nexus.borders[i];
}
assert(tmp_frags.size() == nexus.borders.size());
for(unsigned int i = 0; i < tmp_frags.size(); i++) {
nexus.borders[i] = borders[tmp_frags[i]];
}
size = tmp_nodes.size() * sizeof(Node) +
tmp_in_links.size() * sizeof(Link) +
tmp_out_links.size() * sizeof(Link) +
tmp_frags.size() * sizeof(unsigned int) +
5 * sizeof(int);
4 * sizeof(int);
if(buffer) delete []buffer;
buffer = new char[size];
@ -321,18 +336,15 @@ bool History::UpdatesToQuick() {
n_nodes() = tmp_nodes.size();
n_in_links() = tmp_in_links.size();
n_out_links() = tmp_out_links.size();
n_frags() = tmp_frags.size();
nodes = (Node *)(buffer + 5 * sizeof(int));
nodes = (Node *)(buffer + 4 * sizeof(int));
in_links = (Link *)(nodes + n_nodes());
out_links = in_links + n_in_links();
frags = (unsigned int *)(out_links + n_out_links());
memcpy(nodes, &*tmp_nodes.begin(), tmp_nodes.size()*sizeof(Node));
memcpy(in_links, &*tmp_in_links.begin(), tmp_in_links.size()*sizeof(Link));
memcpy(out_links, &*tmp_out_links.begin(),
tmp_out_links.size()*sizeof(Link));
memcpy(frags, &*tmp_frags.begin(), tmp_frags.size() * sizeof(unsigned int));
return LoadPointers();
}
@ -347,7 +359,7 @@ void History::BuildLevels(vector<int> &levels) {
unsigned int current = 0;
if(node != nodes) { //not root
Link *inlink = node->in_begin();
unsigned int p = *(inlink->begin());
unsigned int p = (inlink->begin());
assert(p < levels.size());
assert(p >= 0);
current = levels[p]+1;
@ -356,7 +368,7 @@ void History::BuildLevels(vector<int> &levels) {
Link &link = *l;
Link::iterator c;
for(c = link.begin(); c != link.end(); c++) {
unsigned int p = *c;
unsigned int p = c;
while(p >= levels.size()) levels.push_back(-1);
levels[p] = current;
}

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.5 2005/02/19 16:22:45 ponchio
Minor changes (visited and Cell)
Revision 1.4 2005/02/17 16:40:35 ponchio
Optimized BuildLevels.
@ -43,6 +46,7 @@ Added copyright
namespace nxs {
class Nexus;
class History {
public:
@ -63,12 +67,14 @@ namespace nxs {
struct Link {
Node *node;
typedef unsigned int *iterator;
//TODO move to frag_begin frag_end (instead of frag_size)
//and test speed... before so maybe also for node
typedef unsigned int iterator;
iterator begin() { return frag_begin; }
iterator end() { return frag_begin + frag_size; }
unsigned int size() { return frag_size; }
unsigned int *frag_begin;
unsigned int frag_begin;
unsigned int frag_size;
};
@ -93,11 +99,11 @@ namespace nxs {
Link *in_links;
Link *out_links;
//TODO this list is really not necessary if we order our cells
unsigned int *frags;
// unsigned int *frags;
std::vector<Update> updates;
History(): nodes(NULL), in_links(NULL), out_links(NULL), frags(NULL),
History(): nodes(NULL), in_links(NULL), out_links(NULL),// frags(NULL),
buffer(NULL) {}
~History();
@ -117,7 +123,7 @@ namespace nxs {
char *SaveUpdates(unsigned int &size);
bool QuickToUpdates();
bool UpdatesToQuick();
bool UpdatesToQuick(Nexus &nexus);
bool IsQuick() { return buffer != NULL; }
void BuildLevels(std::vector<int> &levels);
@ -126,7 +132,7 @@ namespace nxs {
int &n_nodes() { return ((int *)buffer)[1]; }
int &n_in_links() { return ((int *)buffer)[2]; }
int &n_out_links() { return ((int *)buffer)[3]; }
int &n_frags() { return ((int *)buffer)[4]; }
// int &n_frags() { return ((int *)buffer)[4]; }
typedef Node *iterator;
iterator begin() { return nodes; }

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.29 2005/02/19 10:45:04 ponchio
Patch generalized and small fixes.
Revision 1.28 2005/02/08 12:43:03 ponchio
Added copyright
@ -102,11 +105,18 @@ void Nexus::Close() {
if(!IsReadOnly()) {
//set history_offset
if(!size()) history_offset = 0;
else
history_offset = (back().patch_start + back().disk_size);
history_offset = 0;
if(size()) {
//we need to discover where is the last patch
for(unsigned int i = 0; i < size(); i++) {
Entry &e = operator[](i);
if(e.patch_start + e.disk_size > history_offset)
history_offset = e.patch_start + e.disk_size;
}
// history_offset = (back().patch_start + back().disk_size);
}
history_offset *= chunk_size;
unsigned int history_size;
char *mem = history.Save(history_size);
Redim(history_offset + history_size + sizeof(unsigned int));

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.32 2005/02/19 12:06:53 ponchio
Debug...
Revision 1.31 2005/02/19 10:45:04 ponchio
Patch generalized and small fixes.
@ -98,7 +101,7 @@ void NexusMt::SetPreload(bool on) {
bool NexusMt::Load(const string &filename) {
if(!Nexus::Load(filename, true)) return false;
if(!history.IsQuick() && !history.UpdatesToQuick())
if(!history.IsQuick() && !history.UpdatesToQuick(*this))
return false;
#ifndef WIN32

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.41 2005/02/19 12:06:55 ponchio
Debug...
Revision 1.40 2005/02/17 15:39:44 ponchio
Reorderes statistics a bit.
@ -276,9 +279,7 @@ int main(int argc, char *argv[]) {
bool rotate = false;
bool show_borders = false;
bool show_colors = true;
bool do_render = true;
bool show_normals = true;
bool show_statistics = true;
bool extract = true;
bool realtime = true;
@ -384,8 +385,18 @@ int main(int argc, char *argv[]) {
case SDLK_q: exit(0); break;
case SDLK_k: keepdrawing = !keepdrawing; break;
case SDLK_e: extract = !extract; break;
case SDLK_c: show_colors = !show_colors; break;
case SDLK_n: show_normals = !show_normals; break;
case SDLK_c:
if(contest.attrs & DrawContest::COLOR)
contest.attrs &= ~DrawContest::COLOR;
else
contest.attrs |= DrawContest::COLOR; break;
case SDLK_n:
if(contest.attrs & DrawContest::NORMAL)
contest.attrs &= ~DrawContest::NORMAL;
else
contest.attrs |= DrawContest::NORMAL; break;
case SDLK_w: do_render = !do_render; break;
case SDLK_LEFT: nexus.MaxRam() *= 0.8; break;

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.17 2005/02/19 17:14:02 ponchio
History quick by default.
Revision 1.16 2005/02/19 10:45:04 ponchio
Patch generalized and small fixes.
@ -614,8 +617,9 @@ void FifthStep(const string &crudefile, const string &output,
nexus.history.updates.push_back(update);
ReverseHistory(nexus.history.updates);
nexus.borders.Flush();
if(!nexus.history.IsQuick())
nexus.history.UpdatesToQuick();
nexus.history.UpdatesToQuick(nexus);
// TestBorders(nexus);
nexus.Close();

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.21 2005/02/19 17:14:02 ponchio
History quick by default.
Revision 1.20 2005/02/19 10:45:04 ponchio
Patch generalized and small fixes.
@ -342,41 +345,41 @@ int main(int argc, char *argv[]) {
if(dump_history) {
if(nexus.history.IsQuick()) {
cerr << "Quick format\n";
cout << "Quick format\n";
for(unsigned int i = 0; i < nexus.history.n_nodes(); i++) {
cerr << "Node: " << i << " out: ";
cout << "Node: " << i << " out: ";
History::History::Node node = nexus.history.nodes[i];
for(History::Node::iterator l = node.out_begin(); l != node.out_end(); l++) {
cerr << ".";
cout << ".";
History::Link &link = *l;
for(History::Link::iterator p = link.begin(); p != link.end(); p++) {
cerr << *p << " ";
cout << p << " ";
}
}
cerr << " in: ";
cout << " in: ";
for(History::Node::iterator j = node.in_begin(); j != node.in_end(); j++) {
cerr << ".";
cout << ".";
History::Link &link = *j;
for(History::Link::iterator p = link.begin(); p != link.end(); p++) {
cerr << *p << " ";
cout << p << " ";
}
}
cerr << endl;
cout << endl;
}
} else {
cerr << "Update format\n";
cout << "Update format\n";
for(unsigned int i = 0; i < nexus.history.updates.size(); i++) {
History::Update &update = nexus.history.updates[i];
cerr << "Created: ";
cout << "Created: ";
for(unsigned int k = 0; k < update.created.size(); k++) {
cerr << update.created[k] << " ";
cout << update.created[k] << " ";
}
cerr << "\nErased: ";
cout << "\nErased: ";
for(unsigned int k = 0; k < update.erased.size(); k++) {
cerr << update.erased[k] << " ";
cout << update.erased[k] << " ";
}
cerr << "\n\n";
cout << "\n\n";
}
}
}
@ -386,7 +389,8 @@ int main(int argc, char *argv[]) {
Entry &entry = nexus[i];
cout << i << " -> nv: " << entry.nvert << " nf: " << entry.nface
<< " error: " << entry.error
<< " disk_size: " << entry.disk_size << endl;
<< " disk_size: " << entry.disk_size
<< " start: " << entry.patch_start << endl;
}
cout << endl;
}
@ -464,8 +468,7 @@ int main(int argc, char *argv[]) {
ZSort(nexus, forward, backward);
//Fixing history
if(!nexus.history.IsQuick())
nexus.history.UpdatesToQuick();
assert(nexus.history.IsQuick());
unsigned int hsize;
char *buffer = nexus.history.Save(hsize);
@ -474,7 +477,9 @@ int main(int argc, char *argv[]) {
if(zsort) {
if(out.history.IsQuick()) {
assert(0);
//TODO FIX THIS...
/* if(out.history.IsQuick()) {
for(unsigned int i = 0; i < out.history.n_frags(); i++)
out.history.frags[i] = backward[out.history.frags[i]];
} else {
@ -486,7 +491,7 @@ int main(int argc, char *argv[]) {
for(unsigned int k = 0; k < update.erased.size(); k++)
update.erased[k] = backward[update.erased[k]];
}
}
}*/
}
Report report(nexus.size());

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.5 2005/02/08 12:43:03 ponchio
Added copyright
****************************************************************************/
@ -55,15 +58,18 @@ int main(int argc, char *argv[]) {
unsigned short *face = patch.Face(f);
for(int k = 0; k < 3; k++) {
if(face[k] > patch.nv) {
cerr << "Invalid face number: " << face[k] << " > " << patch.nv << endl;
cerr << "Invalid face number: " << face[k] << " > "
<< patch.nv << endl;
cerr << "At patch: " << patchid << endl;
cerr << "start: " << info.patch_start << endl;
cerr << "nf: " << info.nface << " nv: " << info.nvert << endl;
//exit(0);
}
}
}
Sphere3f &sphere = info.sphere;
for(int v = 0; v < patch.nv; v++) {
Point3f &p = patch.Vert(v);
Point3f &p = patch.Vert3f(v);
float dist = Distance(sphere, p);
if(dist > 0.001) {
//if(!info.sphere.IsIn(p)) {