From 00d5475c81b58aef9e8b7795a049d86317a7ddc9 Mon Sep 17 00:00:00 2001 From: ponchio Date: Mon, 21 Feb 2005 17:55:49 +0000 Subject: [PATCH] debug debug debug --- apps/nexus/fragment.cpp | 29 +++++++++++++ apps/nexus/fragment.h | 12 ++++-- apps/nexus/nxsalgo.cpp | 88 ++++++++++++++++++++++++++------------- apps/nexus/nxsalgo.h | 5 ++- apps/nexus/nxsbuilder.cpp | 18 +++----- apps/nexus/nxsedit.cpp | 8 ++++ apps/nexus/vpartition.cpp | 17 +++++++- apps/nexus/vpartition.h | 8 +++- 8 files changed, 136 insertions(+), 49 deletions(-) diff --git a/apps/nexus/fragment.cpp b/apps/nexus/fragment.cpp index 81de48f9..ace2374f 100644 --- a/apps/nexus/fragment.cpp +++ b/apps/nexus/fragment.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.9 2005/02/08 12:43:03 ponchio +Added copyright + ****************************************************************************/ @@ -32,6 +35,7 @@ $Log: not supported by cvs2svn $ #include "fragment.h" #include "border.h" +#include "nxsalgo.h" //#include "pvoronoi.h" @@ -40,7 +44,11 @@ using namespace vcg; using namespace nxs; using namespace pt; + + void NxsPatch::Write(outstm *out) { + out->write(&sphere, sizeof(Sphere3f)); + out->write(&cone, sizeof(ANCone3f)); int vsize = vert.size(); int fsize = face.size(); int bsize = bord.size(); @@ -56,6 +64,8 @@ void NxsPatch::Write(outstm *out) { } void NxsPatch::Read(instm *in) { + in->read(&sphere, sizeof(Sphere3f)); + in->read(&cone, sizeof(ANCone3f)); int vsize; int fsize; int bsize; @@ -385,6 +395,25 @@ void nxs::Split(Fragment &out, } } } + //process Cone and sphere + for(unsigned int seed = 0; seed != nseeds; seed++) { + NxsPatch &patch = out.pieces[seed]; + Sphere3f &sphere = patch.sphere; + sphere.CreateTight(patch.vert.size(), &*patch.vert.begin()); + + //NORMALS CONE + vector normals; + for(unsigned int i = 0; i < patch.face.size(); i += 3) { + unsigned short *f = &(patch.face[i]); + Point3f &v0 = patch.vert[f[0]]; + Point3f &v1 = patch.vert[f[1]]; + Point3f &v2 = patch.vert[f[2]]; + + Point3f norm = (v1 - v0) ^ (v2 - v0); + normals.push_back(norm.Normalize()); + } + patch.cone.AddNormals(normals, 0.99f); + } } unsigned int Fragment::Locate(const Point3f &p) { diff --git a/apps/nexus/fragment.h b/apps/nexus/fragment.h index 00739f3f..a1dfae84 100644 --- a/apps/nexus/fragment.h +++ b/apps/nexus/fragment.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.6 2005/02/08 12:43:03 ponchio +Added copyright + ****************************************************************************/ @@ -59,15 +62,18 @@ class NxsPatch { //this fields is the patch number in the infragment //and the seeds id in the outfragment unsigned int patch; + vcg::Sphere3f sphere; + ANCone3f cone; + std::vector vert; std::vector face; - + std::vector bord; - + void Write(pt::outstm *out); void Read(pt::instm *in); }; - + class Fragment { public: unsigned int id; diff --git a/apps/nexus/nxsalgo.cpp b/apps/nexus/nxsalgo.cpp index 97f82d79..359aec9e 100644 --- a/apps/nexus/nxsalgo.cpp +++ b/apps/nexus/nxsalgo.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.21 2005/02/20 18:07:01 ponchio +cleaning. + Revision 1.20 2005/02/19 10:45:04 ponchio Patch generalized and small fixes. @@ -48,6 +51,7 @@ Added copyright //#include #include "nxsalgo.h" +#include "vpartition.h" #include "vfile.h" #include "nexus.h" #include "zcurve.h" @@ -61,7 +65,7 @@ using namespace vcg; using namespace triangle_stripper; -void nxs::TightSphere(vcg::Sphere3f &sphere, +/*void nxs::TightSphere(vcg::Sphere3f &sphere, std::vector &points) { //test: //assumes radius is ok.... and try to optimize moving center. @@ -107,7 +111,7 @@ void nxs::TightSphere(vcg::Sphere3f &sphere, sphere.Center() = sphere.Center() + pert[best]; sphere.Radius() = best_radius; } -} + }*/ @@ -184,10 +188,6 @@ void nxs::ComputeNormals(Nexus &nexus) { normals[f[2]] += norm; } - //compute normalscone (done in building... - // ANCone3f cone; - // cone.AddNormals(normals, cone_threshold); - // nexus[p].cone.Import(cone); if(nexus.signature.vnorm == Encodings::SHORT4) { short *n = (short *)patch.VNormBegin(); for(unsigned int i = 0; i < patch.nv; i++, n += 4) { @@ -198,8 +198,11 @@ void nxs::ComputeNormals(Nexus &nexus) { n[3] = 0; } } else if(nexus.signature.vnorm == Encodings::FLOAT3) { - memcpy(patch.VNormBegin(), &*normals.begin(), - normals.size() * sizeof(Point3f)); + Point3f *n = (Point3f *)patch.VNormBegin(); + for(unsigned int i = 0; i < patch.nv; i++) { + n[i] = normals[i]; + n[i].Normalize(); + } } @@ -373,6 +376,8 @@ void nxs::ComputeTriStrip(unsigned short nfaces, unsigned short *faces, } } +/* + //TODO why i created this function? wonder... void nxs::Reorder(Signature &signature, Patch &patch) { vector remap; remap.resize(patch.nv, 0xffff); @@ -407,10 +412,11 @@ void nxs::Reorder(Signature &signature, Patch &patch) { memcpy(&*vert.begin(), patch.Vert3fBegin(), patch.nv * sizeof(Point3f)); for(int i = 0; i < patch.nv; i++) patch.Vert3f(remap[i]) = vert[i]; -} + }*/ //TODO actually use threshold void nxs::Unify(Nexus &nexus, float threshold) { + threshold = 0.001; //TODO what if colors or normals or strips? unsigned int duplicated = 0; unsigned int degenerate = 0; @@ -419,44 +425,62 @@ void nxs::Unify(Nexus &nexus, float threshold) { Entry &entry = nexus[p]; Patch &patch = nexus.GetPatch(p); - unsigned int vcount = 0; - map vertices; + + VPartition part; + for(unsigned int i = 0; i < patch.nv; i++) { + Point3f &point = patch.Vert3f(i); + part.push_back(point); + } + part.Init(); + + unsigned int vcount = 0; vector remap; remap.resize(patch.nv); + int targets[8]; + double dists[8]; + + //TODO CRITICAL FIX this unifying routine. for(unsigned int i = 0; i < patch.nv; i++) { Point3f &point = patch.Vert3f(i); + part.Closest(point, 8, targets, dists); + int k = 0; + for(k = 0; k < 8; k++) { + if(dists[k] > threshold) { + remap[i] = vcount++; + break; + } + if(targets[k] < i) { + remap[i] = remap[targets[k]]; + duplicated++; + break; + } + } + if(k == 8) + remap[i] = vcount++; - if(!vertices.count(point)) - vertices[point] = vcount++; - else - duplicated++; - - remap[i] = vertices[point]; } - assert(vertices.size() <= patch.nv); - if(vertices.size() == patch.nv) //no need to unify + + if(vcount == patch.nv) //no need to unify continue; vector newvert; - newvert.resize(vertices.size()); - map::iterator k; - for(k = vertices.begin(); k != vertices.end(); k++) { - newvert[(*k).second] = (*k).first; - } + newvert.resize(vcount); + for(unsigned int i = 0; i < patch.nv; i++) + newvert[remap[i]] = patch.Vert3f(i); vector newface; //check no degenerate faces get created. for(unsigned int f = 0; f < entry.nface; f++) { unsigned short *face = patch.Face(f); if(face[0] != face[1] && face[1] != face[2] && face[0] != face[2] && - newvert[remap[face[0]]] != newvert[remap[face[1]]] && - newvert[remap[face[0]]] != newvert[remap[face[2]]] && - newvert[remap[face[1]]] != newvert[remap[face[2]]]) { - newface.push_back(remap[face[0]]); - newface.push_back(remap[face[1]]); - newface.push_back(remap[face[2]]); + newvert[remap[face[0]]] != newvert[remap[face[1]]] && + newvert[remap[face[0]]] != newvert[remap[face[2]]] && + newvert[remap[face[1]]] != newvert[remap[face[2]]]) { + newface.push_back(remap[face[0]]); + newface.push_back(remap[face[1]]); + newface.push_back(remap[face[2]]); } else { degenerate++; } @@ -471,6 +495,7 @@ void nxs::Unify(Nexus &nexus, float threshold) { memcpy(patch.FaceBegin(), &(newface[0]), entry.nface*3*sizeof(short)); //testiamo il tutto... TODO remove this of course +#ifdef NDEBUG for(unsigned int i =0; i < patch.nf; i++) { for(int k =0 ; k < 3; k++) if(patch.Face(i)[k] >= patch.nv) { @@ -478,6 +503,8 @@ void nxs::Unify(Nexus &nexus, float threshold) { exit(0); } } +#endif + //TODO CRITICAL FIX unify vertices across borders..... HOW?????? //fix patch borders now set close; //bordering pathes @@ -500,6 +527,7 @@ void nxs::Unify(Nexus &nexus, float threshold) { } } //better to compact directly borders than setting them null. + //finally: there may be duplicated borders for(unsigned int p = 0; p < nexus.size(); p++) { Border &border = nexus.GetBorder(p); diff --git a/apps/nexus/nxsalgo.h b/apps/nexus/nxsalgo.h index 8e7a501b..5775971d 100644 --- a/apps/nexus/nxsalgo.h +++ b/apps/nexus/nxsalgo.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.7 2005/02/20 18:07:01 ponchio +cleaning. + Revision 1.6 2005/02/19 10:45:04 ponchio Patch generalized and small fixes. @@ -62,7 +65,7 @@ namespace nxs { void Unify(Nexus &nexus, float threshold); void ZSort(Nexus &nexus, std::vector &forward, std::vector &backward); - void TightSphere(vcg::Sphere3f &sphere, std::vector &points); + // void TightSphere(vcg::Sphere3f &sphere, std::vector &points); } #endif diff --git a/apps/nexus/nxsbuilder.cpp b/apps/nexus/nxsbuilder.cpp index 75d9fa94..58331120 100644 --- a/apps/nexus/nxsbuilder.cpp +++ b/apps/nexus/nxsbuilder.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.19 2005/02/20 18:07:01 ponchio +cleaning. + Revision 1.18 2005/02/20 00:43:24 ponchio Less memory x extraction. (removed frags) @@ -359,11 +362,7 @@ void ThirdStep(const string &crudefile, const string &output, memcpy(patch.Vert3fBegin(), &*vertices.begin(), vcount * sizeof(Point3f)); Sphere3f &sphere = nexus[patch_idx].sphere; - for(int i = 0; i < vertices.size(); i++) - sphere.Add(vertices[i]); - sphere.Radius() *= 1.01; - - TightSphere(sphere, vertices); + sphere.CreateTight(vertices.size(), &*vertices.begin()); vector normals; for(unsigned int i = 0; i < patch.nf; i++) { @@ -378,7 +377,6 @@ void ThirdStep(const string &crudefile, const string &output, ANCone3f cone; cone.AddNormals(normals, 0.99f); nexus[patch_idx].cone.Import(cone); - #ifndef NDEBUG for(int i = 0; i < vertices.size(); i++) { @@ -825,6 +823,8 @@ void SaveFragment(Nexus &nexus, VChain &chain, patch_levels.push_back(current_level); Entry &entry = nexus[patch_idx]; entry.error = fragout.error; + entry.sphere = patch.sphere; + entry.cone.Import(patch.cone); patch_remap[i] = patch_idx; chain.newfragments[patch.patch].insert(patch_idx); @@ -852,12 +852,6 @@ void SaveFragment(Nexus &nexus, VChain &chain, outpatch.vert.size() * sizeof(Point3f)); Entry &entry = nexus[patch_idx]; - for(unsigned int v = 0; v < outpatch.vert.size(); v++) { - entry.sphere.Add(outpatch.vert[v]); - nexus.sphere.Add(outpatch.vert[v]); - } - entry.sphere.Radius() *= 1.01; - TightSphere(entry.sphere, outpatch.vert); //remap internal borders for(unsigned int k = 0; k < outpatch.bord.size(); k++) { diff --git a/apps/nexus/nxsedit.cpp b/apps/nexus/nxsedit.cpp index 3c9f9005..605879d0 100644 --- a/apps/nexus/nxsedit.cpp +++ b/apps/nexus/nxsedit.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.24 2005/02/20 19:49:44 ponchio +cleaning (a bit more). + Revision 1.23 2005/02/20 18:07:01 ponchio cleaning. @@ -648,6 +651,11 @@ void printInfo(Nexus &nexus, bool verbose, bool dump_history) { << " error: " << entry.error << " disk_size: " << entry.disk_size << " start: " << entry.patch_start << endl; + cout << " Cone: " << entry.cone.n[0] << " " + << entry.cone.n[1] << " " + << entry.cone.n[2] << " " + << entry.cone.n[3] << "\n"; + } cout << endl; } diff --git a/apps/nexus/vpartition.cpp b/apps/nexus/vpartition.cpp index 4668d4b3..d1976cce 100644 --- a/apps/nexus/vpartition.cpp +++ b/apps/nexus/vpartition.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.3 2005/01/21 17:09:13 ponchio +Porting and debug. + Revision 1.2 2004/12/04 13:24:27 ponchio Fixed a couple of memory leak... @@ -85,13 +88,23 @@ void VPartition::Closest(const vcg::Point3f &p, point[1] = p[1]; point[2] = p[2]; double dists; - bd->annkSearch(&point[0], 1, &target, &dists, 1); + bd->annkSearch(&point[0], 1, &target, &dists); assert(target >= 0); assert(target < size()); dist = (float)dists; } +void VPartition::Closest(const vcg::Point3f &p, unsigned int nsize, + int *targets, + double *dists) { + double point[3]; + point[0] = p[0]; + point[1] = p[1]; + point[2] = p[2]; + bd->annkSearch(&point[0], nsize, targets, dists); +} + int VPartition::Locate(const vcg::Point3f &p) { double point[3]; @@ -101,7 +114,7 @@ int VPartition::Locate(const vcg::Point3f &p) { int target = -1; double dists; - bd->annkSearch(&point[0], 1, &target, &dists, 1); + bd->annkSearch(&point[0], 1, &target, &dists); return target; } diff --git a/apps/nexus/vpartition.h b/apps/nexus/vpartition.h index 0471240c..74aa70f7 100644 --- a/apps/nexus/vpartition.h +++ b/apps/nexus/vpartition.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.3 2005/01/18 22:46:58 ponchio +Small changes. + Revision 1.2 2004/12/04 13:24:28 ponchio Fixed a couple of memory leak... @@ -72,7 +75,10 @@ class VPartition: public std::vector { std::vector &dist); void Closest(const vcg::Point3f &p, int &target, float &dist); - + //most efficient! + void Closest(const vcg::Point3f &p, unsigned int nsize, + int *targets, + double *dists); ANNkd_tree *bd;