diff --git a/apps/nexus/nexusview.cpp b/apps/nexus/nexusview.cpp index 3eda7a59..b647e72f 100644 --- a/apps/nexus/nexusview.cpp +++ b/apps/nexus/nexusview.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.16 2004/10/19 01:23:02 ponchio +Daily backup (fragment...) + Revision 1.15 2004/10/15 16:45:27 ponchio Vbo added. @@ -102,7 +105,7 @@ using namespace std; #include #include -#include "stopwatch.h" +#include "watch.h" using namespace vcg; @@ -199,7 +202,7 @@ int main(int argc, char *argv[]) { " -: decrease error\n" " +: increase error (= too)\n"; - StopWatch watch; + Watch watch; bool rotate = false; bool show_borders = true; @@ -361,7 +364,7 @@ int main(int argc, char *argv[]) { nexus.SetComponent(NexusMt::COLOR, show_colors); nexus.SetComponent(NexusMt::NORMAL, show_normals); - watch.Restart(); + watch.Start(); nexus.Render(); @@ -416,7 +419,7 @@ int main(int argc, char *argv[]) { } SDL_GL_SwapBuffers(); - tframe = watch.Elapsed(); + tframe = watch.Time(); } diff --git a/apps/nexus/nxsedit.cpp b/apps/nexus/nxsedit.cpp index f10a089c..fef43f27 100644 --- a/apps/nexus/nxsedit.cpp +++ b/apps/nexus/nxsedit.cpp @@ -3,6 +3,7 @@ using namespace std; #include "nxsalgo.h" #include "nexus.h" +#include "watch.h" using namespace nxs; using namespace vcg; @@ -195,7 +196,7 @@ int main(int argc, char *argv[]) { Nexus nexus; nexus.patches.SetRamBufferSize(ram_size); if(!nexus.Load(input, true)) { - cerr << "Could not open nexus file: " << input << ".mt\n"; + cerr << "Could not open nexus file: " << input << "\n"; return -1; } @@ -269,7 +270,7 @@ int main(int argc, char *argv[]) { if(!output.size()) output = input + getSuffix(signature); - cerr << "Writing to nexus: " << output << endl; + cout << "Writing to nexus: " << output << endl; Nexus out; out.patches.SetRamBufferSize(ram_size); @@ -281,8 +282,12 @@ int main(int argc, char *argv[]) { return -1; } - + //TODO set rambuffer low (or even direct access!) + + Report report(nexus.index.size()); + cout << "Copying and allocating...\n"; for(unsigned int patch = 0; patch < nexus.index.size(); patch++) { + report.Step(patch); Nexus::PatchInfo &src_entry = nexus.index[patch]; Patch src_patch = nexus.GetPatch(patch); Border src_border = nexus.GetBorder(patch); @@ -300,8 +305,6 @@ int main(int argc, char *argv[]) { Nexus::PatchInfo &dst_entry = out.index[patch]; Patch dst_patch = out.GetPatch(patch); - - //copy vertices: memcpy(dst_patch.VertBegin(), src_patch.VertBegin(), src_patch.nv * sizeof(Point3f)); @@ -346,24 +349,21 @@ int main(int argc, char *argv[]) { dst_entry.error = src_entry.error; //adding borders. - //Check border is ok: for(unsigned int i = 0; i < src_border.Size(); i++) { Link &link = src_border[i]; if(link.IsNull()) continue; - if(link.end_patch > nexus.index.size()) { - cerr << "Link endp: " << link.end_patch << endl; - } + assert(link.end_patch < nexus.index.size()); } Border dst_border = out.GetBorder(patch); out.borders.ResizeBorder(patch, src_border.Size()); - // dst_entry.border_used = src_entry.border_used; memcpy(dst_border.Start(), src_border.Start(), src_border.Size() * sizeof(Link)); } + report.Finish(); //TODO this is ok only if we have faces still! if(add_normals) { - cerr << "Computing normals" << endl; + cout << "Computing normals" << endl; ComputeNormals(out); } @@ -372,6 +372,19 @@ int main(int argc, char *argv[]) { cerr << "Unsupported color\n"; return -1; } + if(qvertex) { + report.Init(nexus.index.size()); + cout << "Quantizing vertices\n"; + for(unsigned int patch = 0; patch < nexus.index.size(); patch++) { + report.Step(patch); + Patch src_patch = nexus.GetPatch(patch); + + float *ptr = (float *)src_patch.VertBegin(); + for(unsigned int i = 0; i < src_patch.nv*3; i++) + ptr[i] = qvertex * nearbyintf(ptr[i]/qvertex); + } + report.Finish(); + } //fixing sphere. out.sphere = nexus.sphere; diff --git a/apps/nexus/voronoichain.cpp b/apps/nexus/voronoichain.cpp index 830c471d..2aaf6773 100644 --- a/apps/nexus/voronoichain.cpp +++ b/apps/nexus/voronoichain.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.14 2004/10/19 04:23:29 ponchio +*** empty log message *** + Revision 1.13 2004/10/15 16:45:27 ponchio Vbo added. @@ -69,6 +72,7 @@ First draft. #include #include "voronoichain.h" +#include "watch.h" using namespace std; using namespace vcg; @@ -114,16 +118,19 @@ void VoronoiChain::Init(Crude &crude, float scaling, int steps) { //here goes some optimization pass. //Fine optimization. + Report report; vector fcentroids; vector fcount; for(int i = 0; i < steps; i++) { - cerr << "Optimization step 0: " << i << "/" << steps << endl; + cerr << "Optimization step: " << i+1 << "/" << steps << endl; fcentroids.clear(); fcount.clear(); fcentroids.resize(fine.size(), Point3f(0, 0, 0)); fcount.resize(fine.size(), 0); + report.Init(crude.Vertices()); for(unsigned int v = 0; v < crude.Vertices(); v++) { + if(v & 0xffff) report.Step(v); unsigned int ftarget; float dist = fine.Closest(crude.vert[v], ftarget); assert(ftarget != -1); @@ -157,14 +164,16 @@ void VoronoiChain::Init(Crude &crude, float scaling, int steps) { vector ccount; vector radius; for(int i = 0; i < steps; i++) { - cerr << "Optimization step 0: " << i << "/" << steps << endl; + cerr << "Optimization step: " << i+1 << "/" << steps << endl; ccentroids.clear(); ccount.clear(); ccentroids.resize(coarse.size(), Point3f(0, 0, 0)); ccount.resize(coarse.size(), 0); radius.resize(coarse.size(), 0); + report.Init(crude.Vertices()); for(unsigned int v = 0; v < crude.Vertices(); v++) { + if(v & 0xffff) report.Step(v); unsigned int ctarget = 0xffffffff; float dist = coarse.Closest(crude.vert[v], ctarget); assert(ctarget != 0xffffffff); @@ -372,6 +381,7 @@ void VoronoiChain::BuildLevel(Nexus &nexus, unsigned int offset, unsigned int tot_coarse = (unsigned int)(fine.size() * scaling); + //TODO this method for selecting the seeds is ugly! float ratio = tot_coarse/(float)(nexus.index.size() - offset); float cratio = 0; for(unsigned int idx = offset; idx < nexus.index.size(); idx++) { @@ -394,20 +404,24 @@ void VoronoiChain::BuildLevel(Nexus &nexus, unsigned int offset, coarse.Init(); cerr << "Coarse size: " << coarse.size() << endl; cerr << "Coarse mean: " << coarse_vmean << " mean_size: " << mean_size << endl; + + Report report; //here goes some optimization pass. //Coarse optimization. vector ccentroids; vector ccount; vector radius; for(int i = 0; i < steps; i++) { - cerr << "Optimization step 0: " << i << "/" << steps << endl; + cerr << "Optimization step: " << i+1 << "/" << steps << endl; ccentroids.clear(); ccount.clear(); ccentroids.resize(coarse.size(), Point3f(0, 0, 0)); ccount.resize(coarse.size(), 0); radius.resize(coarse.size(), 0); + report.Init(nexus.index.size()); for(unsigned int idx = offset; idx < nexus.index.size(); idx++) { + report.Step(idx); Patch patch = nexus.GetPatch(idx); for(unsigned int i = 0; i < patch.nv; i++) { diff --git a/apps/nexus/voronoinxs.cpp b/apps/nexus/voronoinxs.cpp index 1315b98a..3a26b67d 100644 --- a/apps/nexus/voronoinxs.cpp +++ b/apps/nexus/voronoinxs.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.16 2004/10/19 01:23:02 ponchio +Daily backup (fragment...) + Revision 1.15 2004/10/15 11:41:03 ponchio Tests and small changes. @@ -90,28 +93,10 @@ using namespace std; #include "decimate.h" #include "fragment.h" #include "nxsbuild.h" +#include "watch.h" using namespace vcg; using namespace nxs; -/*void RemapVertices(Crude &crude, - VertRemap &vert_remap, - VFile &face_remap, - vector &patch_verts); - -void NexusAllocate(Crude &crude, - Nexus &nexus, - VFile &face_remap, - vector &patch_faces, - vector &patch_verts); - -void NexusFill(Crude &crude, - Nexus &nexus, - VertRemap &vert_remap, - VFile &border_remap); - -void NexusFixBorder(Nexus &nexus, -VFile &border_remap);*/ - void NexusSplit(Nexus &nexus, VoronoiChain &vchain, unsigned int level, vector &newvert, @@ -124,12 +109,6 @@ void BuildFragment(Nexus &nexus, VoronoiPartition &part, set &patches, Fragment &fragment); -/*float Decimate(unsigned int target_faces, - vector &newvert, - vector &newface, - vector &newbord, - vector &vert_remap);*/ - void ReverseHistory(vector &history); void TestBorders(Nexus &nexus); @@ -214,6 +193,7 @@ int main(int argc, char *argv[]) { cerr << " -o N: nomber of optimization steps\n"; cerr << " -d : decimation method: quadric, cluster. (default quadric)\n"; cerr << " -b N: ram buffer size (in bytes)\n"; + cerr << " -r : stop after remapping fase\n"; return -1; } @@ -248,19 +228,18 @@ int main(int argc, char *argv[]) { VFile face_remap; if(!face_remap.Create(output + ".rmf")) { - cerr << "Could not create remap files: " << output << ".frm\n"; + cerr << "Could not create remap files: " << output << ".rmf\n"; return -1; } face_remap.Resize(crude.Faces()); - VertRemap vert_remap; if(!vert_remap.Create(output)) { - cerr << "Could not create remap files: " << output << ".rmv and .rmb\n"; + cerr << "Could not create remap file: " << output << ".rmv and .rmb\n"; return -1; } vert_remap.Resize(crude.Vertices()); - + VFile border_remap; if(!border_remap.Create(output + string(".tmp"))) { cerr << "Could not create temporary border remap file\n"; @@ -272,13 +251,15 @@ int main(int argc, char *argv[]) { //Remapping faces and vertices using level 0 and 1 of the chain cerr << "Remapping faces.\n"; vector patch_faces; - vchain.RemapFaces(crude, face_remap, patch_faces, scaling, optimization_steps); + vchain.RemapFaces(crude, face_remap, patch_faces, + scaling, optimization_steps); + cerr << "Remapping vertices.\n"; vector patch_verts; patch_verts.resize(patch_faces.size(), 0); RemapVertices(crude, vert_remap, face_remap, patch_verts); - + if(stop_after_remap) return 0; cerr << "Allocating space\n"; @@ -302,32 +283,32 @@ int main(int argc, char *argv[]) { nexus.patches.FlushAll(); /* BUILDING OTHER LEVELS */ - unsigned int oldoffset = 0; + Report report; + + unsigned int oldoffset = 0; for(unsigned int level = 1; level < max_level; level++) { cerr << "Level: " << level << endl; unsigned int newoffset = nexus.index.size(); vchain.BuildLevel(nexus, oldoffset, scaling, optimization_steps); - cerr << "Level built\n"; + report.Init(vchain.oldfragments.size(), 1); + unsigned int fcount = 0; vector level_history; map >::iterator fragment; for(fragment = vchain.oldfragments.begin(); fragment != vchain.oldfragments.end(); fragment++) { - + report.Step(fcount++); update.created.clear(); update.erased.clear(); - cerr << "Join "; set &fcells = (*fragment).second; set::iterator s; for(s = fcells.begin(); s != fcells.end(); s++) { update.erased.push_back(*s); - cerr << *s << " "; } - cerr << endl; vector newvert; vector newface; @@ -349,6 +330,7 @@ int main(int argc, char *argv[]) { level_history.push_back(update); } + report.Finish(); for(unsigned int i = 0; i < level_history.size(); i++) nexus.history.push_back(level_history[i]); @@ -389,8 +371,6 @@ void NexusSplit(Nexus &nexus, VoronoiChain &vchain, Nexus::Update &update, float error) { - cerr << "Counting nearby cells" << endl; - map centroids; map counts;