Small changes.

This commit is contained in:
Federico Ponchio 2004-10-21 12:22:21 +00:00
parent 4e77db8161
commit ff951fed19
4 changed files with 67 additions and 57 deletions

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $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 Revision 1.15 2004/10/15 16:45:27 ponchio
Vbo added. Vbo added.
@ -102,7 +105,7 @@ using namespace std;
#include <GL/glut.h> #include <GL/glut.h>
#include <wrap/gui/trackball.h> #include <wrap/gui/trackball.h>
#include "stopwatch.h" #include "watch.h"
using namespace vcg; using namespace vcg;
@ -199,7 +202,7 @@ int main(int argc, char *argv[]) {
" -: decrease error\n" " -: decrease error\n"
" +: increase error (= too)\n"; " +: increase error (= too)\n";
StopWatch watch; Watch watch;
bool rotate = false; bool rotate = false;
bool show_borders = true; bool show_borders = true;
@ -361,7 +364,7 @@ int main(int argc, char *argv[]) {
nexus.SetComponent(NexusMt::COLOR, show_colors); nexus.SetComponent(NexusMt::COLOR, show_colors);
nexus.SetComponent(NexusMt::NORMAL, show_normals); nexus.SetComponent(NexusMt::NORMAL, show_normals);
watch.Restart(); watch.Start();
nexus.Render(); nexus.Render();
@ -416,7 +419,7 @@ int main(int argc, char *argv[]) {
} }
SDL_GL_SwapBuffers(); SDL_GL_SwapBuffers();
tframe = watch.Elapsed(); tframe = watch.Time();
} }

View File

@ -3,6 +3,7 @@ using namespace std;
#include "nxsalgo.h" #include "nxsalgo.h"
#include "nexus.h" #include "nexus.h"
#include "watch.h"
using namespace nxs; using namespace nxs;
using namespace vcg; using namespace vcg;
@ -195,7 +196,7 @@ int main(int argc, char *argv[]) {
Nexus nexus; Nexus nexus;
nexus.patches.SetRamBufferSize(ram_size); nexus.patches.SetRamBufferSize(ram_size);
if(!nexus.Load(input, true)) { if(!nexus.Load(input, true)) {
cerr << "Could not open nexus file: " << input << ".mt\n"; cerr << "Could not open nexus file: " << input << "\n";
return -1; return -1;
} }
@ -269,7 +270,7 @@ int main(int argc, char *argv[]) {
if(!output.size()) output = input + getSuffix(signature); if(!output.size()) output = input + getSuffix(signature);
cerr << "Writing to nexus: " << output << endl; cout << "Writing to nexus: " << output << endl;
Nexus out; Nexus out;
out.patches.SetRamBufferSize(ram_size); out.patches.SetRamBufferSize(ram_size);
@ -281,8 +282,12 @@ int main(int argc, char *argv[]) {
return -1; 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++) { for(unsigned int patch = 0; patch < nexus.index.size(); patch++) {
report.Step(patch);
Nexus::PatchInfo &src_entry = nexus.index[patch]; Nexus::PatchInfo &src_entry = nexus.index[patch];
Patch src_patch = nexus.GetPatch(patch); Patch src_patch = nexus.GetPatch(patch);
Border src_border = nexus.GetBorder(patch); Border src_border = nexus.GetBorder(patch);
@ -300,8 +305,6 @@ int main(int argc, char *argv[]) {
Nexus::PatchInfo &dst_entry = out.index[patch]; Nexus::PatchInfo &dst_entry = out.index[patch];
Patch dst_patch = out.GetPatch(patch); Patch dst_patch = out.GetPatch(patch);
//copy vertices: //copy vertices:
memcpy(dst_patch.VertBegin(), src_patch.VertBegin(), memcpy(dst_patch.VertBegin(), src_patch.VertBegin(),
src_patch.nv * sizeof(Point3f)); src_patch.nv * sizeof(Point3f));
@ -346,24 +349,21 @@ int main(int argc, char *argv[]) {
dst_entry.error = src_entry.error; dst_entry.error = src_entry.error;
//adding borders. //adding borders.
//Check border is ok:
for(unsigned int i = 0; i < src_border.Size(); i++) { for(unsigned int i = 0; i < src_border.Size(); i++) {
Link &link = src_border[i]; Link &link = src_border[i];
if(link.IsNull()) continue; if(link.IsNull()) continue;
if(link.end_patch > nexus.index.size()) { assert(link.end_patch < nexus.index.size());
cerr << "Link endp: " << link.end_patch << endl;
}
} }
Border dst_border = out.GetBorder(patch); Border dst_border = out.GetBorder(patch);
out.borders.ResizeBorder(patch, src_border.Size()); out.borders.ResizeBorder(patch, src_border.Size());
// dst_entry.border_used = src_entry.border_used;
memcpy(dst_border.Start(), src_border.Start(), memcpy(dst_border.Start(), src_border.Start(),
src_border.Size() * sizeof(Link)); src_border.Size() * sizeof(Link));
} }
report.Finish();
//TODO this is ok only if we have faces still! //TODO this is ok only if we have faces still!
if(add_normals) { if(add_normals) {
cerr << "Computing normals" << endl; cout << "Computing normals" << endl;
ComputeNormals(out); ComputeNormals(out);
} }
@ -372,6 +372,19 @@ int main(int argc, char *argv[]) {
cerr << "Unsupported color\n"; cerr << "Unsupported color\n";
return -1; 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. //fixing sphere.
out.sphere = nexus.sphere; out.sphere = nexus.sphere;

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $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 Revision 1.13 2004/10/15 16:45:27 ponchio
Vbo added. Vbo added.
@ -69,6 +72,7 @@ First draft.
#include <iostream> #include <iostream>
#include "voronoichain.h" #include "voronoichain.h"
#include "watch.h"
using namespace std; using namespace std;
using namespace vcg; using namespace vcg;
@ -114,16 +118,19 @@ void VoronoiChain::Init(Crude &crude, float scaling, int steps) {
//here goes some optimization pass. //here goes some optimization pass.
//Fine optimization. //Fine optimization.
Report report;
vector<Point3f> fcentroids; vector<Point3f> fcentroids;
vector<unsigned int> fcount; vector<unsigned int> fcount;
for(int i = 0; i < steps; i++) { for(int i = 0; i < steps; i++) {
cerr << "Optimization step 0: " << i << "/" << steps << endl; cerr << "Optimization step: " << i+1 << "/" << steps << endl;
fcentroids.clear(); fcentroids.clear();
fcount.clear(); fcount.clear();
fcentroids.resize(fine.size(), Point3f(0, 0, 0)); fcentroids.resize(fine.size(), Point3f(0, 0, 0));
fcount.resize(fine.size(), 0); fcount.resize(fine.size(), 0);
report.Init(crude.Vertices());
for(unsigned int v = 0; v < crude.Vertices(); v++) { for(unsigned int v = 0; v < crude.Vertices(); v++) {
if(v & 0xffff) report.Step(v);
unsigned int ftarget; unsigned int ftarget;
float dist = fine.Closest(crude.vert[v], ftarget); float dist = fine.Closest(crude.vert[v], ftarget);
assert(ftarget != -1); assert(ftarget != -1);
@ -157,14 +164,16 @@ void VoronoiChain::Init(Crude &crude, float scaling, int steps) {
vector<unsigned int> ccount; vector<unsigned int> ccount;
vector<float> radius; vector<float> radius;
for(int i = 0; i < steps; i++) { for(int i = 0; i < steps; i++) {
cerr << "Optimization step 0: " << i << "/" << steps << endl; cerr << "Optimization step: " << i+1 << "/" << steps << endl;
ccentroids.clear(); ccentroids.clear();
ccount.clear(); ccount.clear();
ccentroids.resize(coarse.size(), Point3f(0, 0, 0)); ccentroids.resize(coarse.size(), Point3f(0, 0, 0));
ccount.resize(coarse.size(), 0); ccount.resize(coarse.size(), 0);
radius.resize(coarse.size(), 0); radius.resize(coarse.size(), 0);
report.Init(crude.Vertices());
for(unsigned int v = 0; v < crude.Vertices(); v++) { for(unsigned int v = 0; v < crude.Vertices(); v++) {
if(v & 0xffff) report.Step(v);
unsigned int ctarget = 0xffffffff; unsigned int ctarget = 0xffffffff;
float dist = coarse.Closest(crude.vert[v], ctarget); float dist = coarse.Closest(crude.vert[v], ctarget);
assert(ctarget != 0xffffffff); assert(ctarget != 0xffffffff);
@ -372,6 +381,7 @@ void VoronoiChain::BuildLevel(Nexus &nexus, unsigned int offset,
unsigned int tot_coarse = (unsigned int)(fine.size() * scaling); 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 ratio = tot_coarse/(float)(nexus.index.size() - offset);
float cratio = 0; float cratio = 0;
for(unsigned int idx = offset; idx < nexus.index.size(); idx++) { for(unsigned int idx = offset; idx < nexus.index.size(); idx++) {
@ -394,20 +404,24 @@ void VoronoiChain::BuildLevel(Nexus &nexus, unsigned int offset,
coarse.Init(); coarse.Init();
cerr << "Coarse size: " << coarse.size() << endl; cerr << "Coarse size: " << coarse.size() << endl;
cerr << "Coarse mean: " << coarse_vmean << " mean_size: " << mean_size << endl; cerr << "Coarse mean: " << coarse_vmean << " mean_size: " << mean_size << endl;
Report report;
//here goes some optimization pass. //here goes some optimization pass.
//Coarse optimization. //Coarse optimization.
vector<Point3f> ccentroids; vector<Point3f> ccentroids;
vector<unsigned int> ccount; vector<unsigned int> ccount;
vector<float> radius; vector<float> radius;
for(int i = 0; i < steps; i++) { for(int i = 0; i < steps; i++) {
cerr << "Optimization step 0: " << i << "/" << steps << endl; cerr << "Optimization step: " << i+1 << "/" << steps << endl;
ccentroids.clear(); ccentroids.clear();
ccount.clear(); ccount.clear();
ccentroids.resize(coarse.size(), Point3f(0, 0, 0)); ccentroids.resize(coarse.size(), Point3f(0, 0, 0));
ccount.resize(coarse.size(), 0); ccount.resize(coarse.size(), 0);
radius.resize(coarse.size(), 0); radius.resize(coarse.size(), 0);
report.Init(nexus.index.size());
for(unsigned int idx = offset; idx < nexus.index.size(); idx++) { for(unsigned int idx = offset; idx < nexus.index.size(); idx++) {
report.Step(idx);
Patch patch = nexus.GetPatch(idx); Patch patch = nexus.GetPatch(idx);
for(unsigned int i = 0; i < patch.nv; i++) { for(unsigned int i = 0; i < patch.nv; i++) {

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $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 Revision 1.15 2004/10/15 11:41:03 ponchio
Tests and small changes. Tests and small changes.
@ -90,28 +93,10 @@ using namespace std;
#include "decimate.h" #include "decimate.h"
#include "fragment.h" #include "fragment.h"
#include "nxsbuild.h" #include "nxsbuild.h"
#include "watch.h"
using namespace vcg; using namespace vcg;
using namespace nxs; using namespace nxs;
/*void RemapVertices(Crude &crude,
VertRemap &vert_remap,
VFile<unsigned int> &face_remap,
vector<unsigned int> &patch_verts);
void NexusAllocate(Crude &crude,
Nexus &nexus,
VFile<unsigned int> &face_remap,
vector<unsigned int> &patch_faces,
vector<unsigned int> &patch_verts);
void NexusFill(Crude &crude,
Nexus &nexus,
VertRemap &vert_remap,
VFile<RemapLink> &border_remap);
void NexusFixBorder(Nexus &nexus,
VFile<RemapLink> &border_remap);*/
void NexusSplit(Nexus &nexus, VoronoiChain &vchain, void NexusSplit(Nexus &nexus, VoronoiChain &vchain,
unsigned int level, unsigned int level,
vector<Point3f> &newvert, vector<Point3f> &newvert,
@ -124,12 +109,6 @@ void BuildFragment(Nexus &nexus, VoronoiPartition &part,
set<unsigned int> &patches, set<unsigned int> &patches,
Fragment &fragment); Fragment &fragment);
/*float Decimate(unsigned int target_faces,
vector<Point3f> &newvert,
vector<unsigned int> &newface,
vector<Link> &newbord,
vector<int> &vert_remap);*/
void ReverseHistory(vector<Nexus::Update> &history); void ReverseHistory(vector<Nexus::Update> &history);
void TestBorders(Nexus &nexus); void TestBorders(Nexus &nexus);
@ -214,6 +193,7 @@ int main(int argc, char *argv[]) {
cerr << " -o N: nomber of optimization steps\n"; cerr << " -o N: nomber of optimization steps\n";
cerr << " -d <method>: decimation method: quadric, cluster. (default quadric)\n"; cerr << " -d <method>: decimation method: quadric, cluster. (default quadric)\n";
cerr << " -b N: ram buffer size (in bytes)\n"; cerr << " -b N: ram buffer size (in bytes)\n";
cerr << " -r : stop after remapping fase\n";
return -1; return -1;
} }
@ -248,15 +228,14 @@ int main(int argc, char *argv[]) {
VFile<unsigned int> face_remap; VFile<unsigned int> face_remap;
if(!face_remap.Create(output + ".rmf")) { 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; return -1;
} }
face_remap.Resize(crude.Faces()); face_remap.Resize(crude.Faces());
VertRemap vert_remap; VertRemap vert_remap;
if(!vert_remap.Create(output)) { 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; return -1;
} }
vert_remap.Resize(crude.Vertices()); vert_remap.Resize(crude.Vertices());
@ -272,7 +251,9 @@ int main(int argc, char *argv[]) {
//Remapping faces and vertices using level 0 and 1 of the chain //Remapping faces and vertices using level 0 and 1 of the chain
cerr << "Remapping faces.\n"; cerr << "Remapping faces.\n";
vector<unsigned int> patch_faces; vector<unsigned int> 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"; cerr << "Remapping vertices.\n";
vector<unsigned int> patch_verts; vector<unsigned int> patch_verts;
@ -302,32 +283,32 @@ int main(int argc, char *argv[]) {
nexus.patches.FlushAll(); nexus.patches.FlushAll();
/* BUILDING OTHER LEVELS */ /* BUILDING OTHER LEVELS */
unsigned int oldoffset = 0;
Report report;
unsigned int oldoffset = 0;
for(unsigned int level = 1; level < max_level; level++) { for(unsigned int level = 1; level < max_level; level++) {
cerr << "Level: " << level << endl; cerr << "Level: " << level << endl;
unsigned int newoffset = nexus.index.size(); unsigned int newoffset = nexus.index.size();
vchain.BuildLevel(nexus, oldoffset, scaling, optimization_steps); vchain.BuildLevel(nexus, oldoffset, scaling, optimization_steps);
cerr << "Level built\n"; report.Init(vchain.oldfragments.size(), 1);
unsigned int fcount = 0;
vector<Nexus::Update> level_history; vector<Nexus::Update> level_history;
map<unsigned int, set<unsigned int> >::iterator fragment; map<unsigned int, set<unsigned int> >::iterator fragment;
for(fragment = vchain.oldfragments.begin(); for(fragment = vchain.oldfragments.begin();
fragment != vchain.oldfragments.end(); fragment++) { fragment != vchain.oldfragments.end(); fragment++) {
report.Step(fcount++);
update.created.clear(); update.created.clear();
update.erased.clear(); update.erased.clear();
cerr << "Join ";
set<unsigned int> &fcells = (*fragment).second; set<unsigned int> &fcells = (*fragment).second;
set<unsigned int>::iterator s; set<unsigned int>::iterator s;
for(s = fcells.begin(); s != fcells.end(); s++) { for(s = fcells.begin(); s != fcells.end(); s++) {
update.erased.push_back(*s); update.erased.push_back(*s);
cerr << *s << " ";
} }
cerr << endl;
vector<Point3f> newvert; vector<Point3f> newvert;
vector<unsigned int> newface; vector<unsigned int> newface;
@ -349,6 +330,7 @@ int main(int argc, char *argv[]) {
level_history.push_back(update); level_history.push_back(update);
} }
report.Finish();
for(unsigned int i = 0; i < level_history.size(); i++) for(unsigned int i = 0; i < level_history.size(); i++)
nexus.history.push_back(level_history[i]); nexus.history.push_back(level_history[i]);
@ -389,8 +371,6 @@ void NexusSplit(Nexus &nexus, VoronoiChain &vchain,
Nexus::Update &update, Nexus::Update &update,
float error) { float error) {
cerr << "Counting nearby cells" << endl;
map<unsigned int, Point3f> centroids; map<unsigned int, Point3f> centroids;
map<unsigned int, unsigned int> counts; map<unsigned int, unsigned int> counts;