This commit is contained in:
Federico Ponchio 2004-12-03 01:20:56 +00:00
parent 2f18ab315f
commit 03863f15b8
7 changed files with 126 additions and 78 deletions

View File

@ -172,7 +172,11 @@ float Cluster(MyMesh &mesh, unsigned int target_faces) {
unsigned int starting = mesh.vn;
unsigned int nseeds = target_faces/2;
assert(nseeds < mesh.vert.size());
#ifndef NDEBUG
if(nseeds >= mesh.vert.size()) {
cerr << "Strange! nseeds > vert.size(): " << nseeds << " >= "<< mesh.vert.size() << endl;
}
#endif
vector<unsigned int> remap;

View File

@ -32,7 +32,7 @@ bool Nexus::Create(const string &file, Signature sig, unsigned int c_size) {
return false;
}
//Important: chunk_size must be 1 so that i can use Region in VFile.
if(!borders.Create(file + ".nxb", 1)) {
if(!borders.Create(file + ".nxb", 1, 100)) {
cerr << "Could not create file: " << file << ".nxb" << endl;
return false;
}
@ -91,7 +91,7 @@ bool Nexus::Load(const string &file, bool readonly) {
//TODO support readonly
if(!patches.Load(file + ".nxp", signature, chunk_size, readonly))
return false;
if(!borders.Load(file + ".nxb", readonly, 1)) return false;
if(!borders.Load(file + ".nxb", readonly, 1, 100)) return false;
return true;
}
@ -373,18 +373,22 @@ void Nexus::Unify(float threshold) {
}
}
}
//TODO: better to compact directly borders than setting them null.
//better to compact directly borders than setting them null.
//finally: there may be duplicated borders
for(unsigned int p = 0; p < index.size(); p++) {
Border border = GetBorder(p);
set<Link> links;
for(unsigned int b = 0; b < border.Size(); b++) {
if(border[b].IsNull()) continue;
if(links.count(border[b]))
border[b] = Link();
else
links.insert(border[b]);
Link &link = border[b];
assert(!link.IsNull());
//if(border[b].IsNull()) continue;
links.insert(link);
}
int count = 0;
for(set<Link>::iterator k = links.begin(); k != links.end(); k++)
border[count++] = *k;
borders.borders[p].border_used = links.size();
}
totvert -= duplicated;

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.6 2004/12/02 20:22:42 ponchio
Level 5;
Revision 1.5 2004/12/02 19:10:18 ponchio
Bounding sphere fix.
@ -306,17 +309,15 @@ void ThirdStep(const string &crudefile, const string &output,
assert(vcount == vertices.size());
assert(fcount == faces.size());
if(vcount > 65000) {
cerr << "Too many vertices in this patch: "
<< vcount << endl;
//TODO deal with this case adding another patch at the end... its not that difficult!
//This can happen on degenerate cases when we have a lot of detached faces....
if(vcount > 65000 && fcount > 65000) {
cerr << "Too many vertices or faces in patch: " << patch << " v: " << vcount
<< " f: " << fcount << endl;
exit(0);
}
if(fcount > 65000) {
cerr << "Too many faces in this patch: "
<< fcount << endl;
exit(0);
}
unsigned int patch_idx = nexus.AddPatch(vertices.size(),
faces.size()/3,
0); //no borders!
@ -329,6 +330,12 @@ void ThirdStep(const string &crudefile, const string &output,
sphere.Add(vertices[i]);
sphere.Radius() *= 1.01;
#ifndef NDEBUG
for(int i = 0; i < vertices.size(); i++) {
assert(sphere.IsIn(vertices[i]));
}
#endif
//saving vert_remap
int64 vroffset = vert_remap.Size();
@ -369,12 +376,11 @@ void ThirdStep(const string &crudefile, const string &output,
void FourthStep(const string &crudefile, const string &output,
unsigned int ram_buffer) {
Nexus nexus;
nexus.patches.SetRamBufferSize(ram_buffer);
if(!nexus.Load(output)) {
cerr << "Could not load nexus " << output << endl;
exit(0);
}
nexus.patches.SetRamBufferSize(ram_buffer);
//TODO Clear borders in case of failure!
VFile<unsigned int> vert_remap;
@ -390,6 +396,10 @@ void FourthStep(const string &crudefile, const string &output,
}
Report report(nexus.index.size());
#ifndef NDEBUG
map<unsigned int, set<unsigned int> > reciprocal;
#endif
for(int start = 0; start < nexus.index.size(); start++) {
report.Step(start);
Nexus::PatchInfo &s_entry = nexus.index[start];
@ -407,7 +417,20 @@ void FourthStep(const string &crudefile, const string &output,
Nexus::PatchInfo &e_entry = nexus.index[end];
float dist = Distance(s_entry.sphere, e_entry.sphere);
if(dist > 0.1) continue;
if(dist > (s_entry.sphere.Radius() + e_entry.sphere.Radius()) * 0.01) {
#ifndef NDEBUG
if(start > end)
assert(!reciprocal[end].count(start));
#endif
continue;
}
#ifndef NDEBUG
if(start > end)
assert(reciprocal[end].count(start));
else
reciprocal[start].insert(end);
#endif
for(unsigned int i = 0; i < vert_index[end].size; i++) {
unsigned int global = vert_remap[vert_index[end].offset + i];
@ -438,12 +461,11 @@ void FifthStep(const string &crudefile, const string &output,
unsigned int max_level) {
Nexus nexus;
nexus.patches.SetRamBufferSize(ram_buffer);
if(!nexus.Load(output)) {
cerr << "Could not load nexus " << output << endl;
exit(0);
}
nexus.patches.SetRamBufferSize(ram_buffer);
VChain vchain;
if(!vchain.Load(output + ".vchain")) {
@ -761,6 +783,7 @@ void SaveFragment(Nexus &nexus, VChain &chain,
entry.sphere.Add(outpatch.vert[v]);
nexus.sphere.Add(outpatch.vert[v]);
}
entry.sphere.Radius() *= 1.01;
//remap internal borders
for(unsigned int k = 0; k < outpatch.bord.size(); k++) {
@ -786,9 +809,11 @@ void SaveFragment(Nexus &nexus, VChain &chain,
Link up(link.end_vert, link.start_vert, patch_idx);
newlinks[link.end_patch].insert(up);
assert(link.end_patch != patch_idx);
Border cborder = nexus.GetBorder(link.end_patch);
for(unsigned int k = 0; k < cborder.Size(); k++) {
//cerr << "Cborder.size: " << cborder.Size() << endl;
//cerr << "K: " << k << endl;
Link &clink = cborder[k];
assert(!clink.IsNull());
@ -839,7 +864,11 @@ void SaveFragment(Nexus &nexus, VChain &chain,
}
void ReverseHistory(vector<Nexus::Update> &history) {
std::reverse(history.begin(), history.end());
vector<Nexus::Update> revert = history;
history.clear();
for(int i = revert.size()-1; i >= 0; i--)
history.push_back(revert[i]);
//std::reverse(history.begin(), history.end());
vector<Nexus::Update>::iterator i;
for(i = history.begin(); i != history.end(); i++)
swap((*i).erased, (*i).created);

View File

@ -15,15 +15,18 @@ void SaveFragment(Nexus &nexus, VChain &chain,
void Opener::execute() {
cerr << "Trying to connect to: " << server->get_host() << endl;
server->reading.lock();
server->writing.lock();
while(1) {
if(get_signaled())
return;
cerr << "Trying to connect to: " << server->get_host() << endl;
try {
server->open();
server->connected = true;
server->queue = 0;
cerr << "Connected to: " << server->get_host() << endl;
break;
} catch(...) {
}

View File

@ -205,7 +205,6 @@ void PatchServer::GetVbo(unsigned int p,
void PatchServer::Flush() {
if(ram_used < ram_size * 1.1) return;
// ramlock.wrlock();
make_heap(lru.begin(), lru.end());
@ -299,6 +298,5 @@ bool PatchServer::FlushVbo(PTime &ptime) {
}
void PatchServer::SetRamBufferSize(unsigned int r_buffer) {
cerr << "Chunk_size: " << chunk_size << endl;
ram_size = (unsigned int)(r_buffer/chunk_size) + 1;
}

View File

@ -158,6 +158,7 @@ void nxs::Remap(VChain &chain,
//Fixing offset
int64 offset = 0;
for(unsigned int i = 0; i < index.size(); i++) {
assert(index[i].size < 65000);
index[i].offset = offset;
offset += index[i].size;
}
@ -244,7 +245,8 @@ void nxs::BuildLevel(VChain &chain,
VPartition &fine = chain[chain.size()-2];
fine.Init();
unsigned int ncells = (unsigned int)(fine.size() * scaling);
//unsigned int ncells = (unsigned int)(fine.size() * scaling);
unsigned int ncells = (unsigned int)(scaling * totface/target_size);
//TODO this method for selecting the seeds is ugly!
float ratio = ncells/(float)(nexus.index.size() - offset);
@ -382,6 +384,8 @@ bool nxs::Optimize(VPartition &part,
mark[i];
}
}
if(failed > 0)
cerr << "Found " << failed << " patches too big.\n";
if(join) {
for(unsigned int i = 0; i < part.size(); i++) {

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.18 2004/12/01 03:24:32 ponchio
Level 2.
Revision 1.17 2004/11/30 22:49:39 ponchio
Level 0.
@ -100,6 +103,8 @@ Created
/**Vector structure on file with simulated mmapping.
* a priority queue of buffers is used
* TODO: port to over 4Gb usable space
* add interface for readonly reads even when file is readwrite...
* instead of queue size use ramsize!!!!
* some mechanism to report errors?
* use an Iterator?
*/
@ -194,6 +199,7 @@ template <class T> class VFile: public MFile {
}
void Resize(unsigned int elem) {
//TODO do i really need to flush?
Flush();
MFile::Redim((int64)elem * (int64)sizeof(T));
n_elements = elem;