From 6d82d738a379002c9b82ad7665a9739907091bca Mon Sep 17 00:00:00 2001 From: ponchio Date: Wed, 1 Dec 2004 16:00:35 +0000 Subject: [PATCH] Level 3 --- apps/nexus/borderserver.cpp | 9 ++-- apps/nexus/nexus.cpp | 2 +- apps/nexus/nxsbuilder.cpp | 88 ++++++++++++++++++++++++++++++++++--- apps/nexus/watch.h | 7 ++- 4 files changed, 93 insertions(+), 13 deletions(-) diff --git a/apps/nexus/borderserver.cpp b/apps/nexus/borderserver.cpp index a81b5826..2a3ac079 100644 --- a/apps/nexus/borderserver.cpp +++ b/apps/nexus/borderserver.cpp @@ -32,10 +32,11 @@ bool BorderServer::ResizeBorder(unsigned int border, unsigned int nbord) { capacity = 65500; unsigned int newstart = Size(); Resize(newstart + capacity); - - Link *src = GetRegion(entry.border_start, entry.border_size); - Link *dst = GetRegion(newstart, capacity, false); - memcpy(dst, src, entry.border_used * sizeof(Link)); + if(entry.border_used > 0) { + Link *src = GetRegion(entry.border_start, entry.border_size); + Link *dst = GetRegion(newstart, capacity, false); + memcpy(dst, src, entry.border_used * sizeof(Link)); + } entry.border_start = newstart; entry.border_size = capacity; entry.border_used = nbord; diff --git a/apps/nexus/nexus.cpp b/apps/nexus/nexus.cpp index f991c76a..cf6921e4 100644 --- a/apps/nexus/nexus.cpp +++ b/apps/nexus/nexus.cpp @@ -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", 1)) return false; + if(!borders.Load(file + ".nxb", readonly, 1)) return false; return true; } diff --git a/apps/nexus/nxsbuilder.cpp b/apps/nexus/nxsbuilder.cpp index b664c399..9e183d6b 100644 --- a/apps/nexus/nxsbuilder.cpp +++ b/apps/nexus/nxsbuilder.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.3 2004/12/01 03:32:46 ponchio +Level 2 (debug). + Revision 1.2 2004/12/01 03:24:32 ponchio Level 2. @@ -202,6 +205,7 @@ void SecondStep(const string &crudefile, const string &output) { sorted.Close(); /* TODO fix this (after debug!) + WARNING what if multiple files? if(0 != unlink((crudefile + ".crf").c_str())) { cerr << "Could not remove " << crudefile << ".crf\n"; @@ -228,7 +232,7 @@ void ThirdStep(const string &crudefile, const string &output, } VFile sorted; - if(!sorted.Load(output + ".faces", true)) { + if(!sorted.Load(crudefile + ".faces", true)) { cerr << "Could not load sorted faces\n"; exit(0); } @@ -239,8 +243,8 @@ void ThirdStep(const string &crudefile, const string &output, } VFile vert_remap; - if(!vert_remap.Create(crudefile + ".rvm")) { - cerr << "Could not create: " << crudefile << ".rvm\n"; + if(!vert_remap.Create(output + ".rvm")) { + cerr << "Could not create: " << output << ".rvm\n"; exit(0); } @@ -255,8 +259,7 @@ void ThirdStep(const string &crudefile, const string &output, exit(0); } - Report report; - report.Init(face_index.size()); + Report report(face_index.size()); for(unsigned int patch = 0; patch < face_index.size(); patch++) { report.Step(patch); @@ -326,7 +329,7 @@ void ThirdStep(const string &crudefile, const string &output, for(unsigned int i = 0; i < nexus.index.size(); i++) nexus.sphere.Add(nexus.index[i].sphere); - Nexus::Update update; + Nexus::Update update; for(unsigned int i = 1; i < nexus.index.size(); i++) { update.created.push_back(i); } @@ -338,6 +341,76 @@ void ThirdStep(const string &crudefile, const string &output, update.erased.push_back(i); } nexus.history.push_back(update); + + if(!vert_index.Save(output + ".rvi")) { + cerr << "Could not save: " << output << ".rvi\n"; + exit(0); + } +} + +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); + } + //TODO Clear borders in case of failure! + + VFile vert_remap; + if(!vert_remap.Load(crudefile + ".rvm", true)) { + cerr << "Could not load: " << crudefile << ".rvm\n"; + exit(0); + } + + BlockIndex vert_index; + if(!vert_index.Load(output + ".rvi")) { + cerr << "Could not load index\n"; + exit(0); + } + Report report(nexus.index.size()); + + for(int start = 0; start < nexus.index.size(); start++) { + report.Step(start); + Nexus::PatchInfo &s_entry = nexus.index[start]; + + vector links; + + map vremap; + for(unsigned int i = 0; i < vert_index[start].size; i++) { + unsigned int global = vert_remap[vert_index[start].offset + i]; + vremap[global] = i; + } + + for(int end = 0; end < nexus.index.size(); end++) { + if(start == end) continue; + + Nexus::PatchInfo &e_entry = nexus.index[end]; + float dist = Distance(s_entry.sphere, e_entry.sphere); + if(dist > 0.1) continue; + + for(unsigned int i = 0; i < vert_index[end].size; i++) { + unsigned int global = vert_remap[vert_index[end].offset + i]; + if(vremap.count(global)) { + Link link; + link.start_vert = vremap[global]; + link.end_vert = i; + link.end_patch = end; + links.push_back(link); + } + } + } + //TODO Horribili visu (interfaccia di cacca!) + nexus.borders.ResizeBorder(start, 3 * links.size()); + nexus.borders.borders[start].border_used = links.size(); + Border border = nexus.GetBorder(start); + memcpy(&(border[0]), &*links.begin(), links.size() * sizeof(Link)); + } +} + +void FifthStep() { } int main(int argc, char *argv[]) { @@ -426,6 +499,9 @@ int main(int argc, char *argv[]) { if(step < 0 || step == 2) ThirdStep(crudefile, output, chunk_size); + + if(step < 0 || step == 3) + FourthStep(crudefile, output, ram_buffer); return 0; } diff --git a/apps/nexus/watch.h b/apps/nexus/watch.h index 57331786..78a774fb 100644 --- a/apps/nexus/watch.h +++ b/apps/nexus/watch.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.4 2004/11/28 04:10:59 ponchio +winsockapi include problem + Revision 1.3 2004/10/21 13:40:16 ponchio Debugging. @@ -82,8 +85,8 @@ private: class Report { public: - Report(unsigned int tot = 1, float inter = 5.0f) { Init(tot, inter); } - void Init(unsigned int tot, float inter = 5.0f); + Report(unsigned int tot = 1, float inter = 30.0f) { Init(tot, inter); } + void Init(unsigned int tot, float inter = 30.0f); void Step(unsigned int count); void Finish(); private: