From ed2d3c823b247a5af42edb82df857a5e276e25c0 Mon Sep 17 00:00:00 2001 From: ponchio Date: Tue, 22 Feb 2005 10:38:17 +0000 Subject: [PATCH] Debug, cleaning and optimization. --- apps/nexus/border.h | 5 +- apps/nexus/borderserver.cpp | 8 + apps/nexus/borderserver.h | 18 +- apps/nexus/crude.cpp | 4 + apps/nexus/crude.h | 5 +- apps/nexus/metric.h | 5 +- apps/nexus/nexusmt.cpp | 11 +- apps/nexus/nxsalgo.cpp | 333 ++++++++++++++++++++++-------------- apps/nexus/nxsalgo.h | 13 +- apps/nexus/nxsbuilder.cpp | 75 +++----- apps/nexus/nxsedit.cpp | 8 +- apps/nexus/nxspatcher.cpp | 5 +- apps/nexus/patch.cpp | 34 ++-- apps/nexus/patch.h | 43 ++--- apps/nexus/vpartition.cpp | 29 ++++ apps/nexus/vpartition.h | 9 + 16 files changed, 362 insertions(+), 243 deletions(-) diff --git a/apps/nexus/border.h b/apps/nexus/border.h index df23329e..25e0fc77 100644 --- a/apps/nexus/border.h +++ b/apps/nexus/border.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.6 2005/01/21 17:09:12 ponchio +Porting and debug. + Revision 1.5 2004/10/08 14:46:26 ponchio Working version. @@ -77,7 +80,7 @@ class Border { links(l), used(_used), size(_size), start(0) {} unsigned int Size() { return used; } //TODO rename available to capacity. - unsigned int Available() { return size; } + unsigned int Capacity() { return size; } Link &operator[](unsigned int i) { return links[i]; } Link *Start() { return links; } diff --git a/apps/nexus/borderserver.cpp b/apps/nexus/borderserver.cpp index 53486c97..f5c726d8 100644 --- a/apps/nexus/borderserver.cpp +++ b/apps/nexus/borderserver.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.10 2005/02/08 12:43:03 ponchio +Added copyright + ****************************************************************************/ @@ -86,6 +89,9 @@ Border &BorderServer::GetBorder(unsigned int border, bool flush) { index[border] = pqueue.begin(); } else { while(flush && ram_used > ram_max) { + if(!pqueue.size()) { + cerr << "Ram used: " << ram_used << " ram max: " << ram_max << endl; + } assert(pqueue.size()); unsigned int to_flush = pqueue.back(); pqueue.pop_back(); @@ -115,6 +121,8 @@ void BorderServer::ResizeBorder(unsigned int border, unsigned int used) { unsigned int newstart = Length()/sizeof(Link); Redim((int64)(newstart + capacity) * (int64)sizeof(Link)); Link *newlinks = new Link[capacity]; + ram_used += (capacity - entry.size); + if(entry.used > 0) { assert(entry.links); memcpy(newlinks, entry.links, entry.used * sizeof(Link)); diff --git a/apps/nexus/borderserver.h b/apps/nexus/borderserver.h index 68c21bb3..c47b72b5 100644 --- a/apps/nexus/borderserver.h +++ b/apps/nexus/borderserver.h @@ -24,6 +24,8 @@ History $Log: not supported by cvs2svn $ +Revision 1.5 2005/02/08 12:43:03 ponchio +Added copyright ****************************************************************************/ @@ -44,14 +46,6 @@ $Log: not supported by cvs2svn $ namespace nxs { - //This should be Border class!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -/*struct BorderEntry { - unsigned int start; //granuralita' Link - unsigned short size; //in Links //TODO what are this? be clear! - unsigned short used; //in Links - Link *links; -};*/ - class BorderServer: public IndexFile { public: BorderServer(): ram_max(1000000), ram_used(0) {} @@ -65,15 +59,9 @@ class BorderServer: public IndexFile { Border &GetBorder(unsigned int border, bool flush = true); void ResizeBorder(unsigned int border, unsigned int size); - /*unsigned int BorderSize(unsigned int i) { - return operator[](i).used; - } - unsigned int BorderCapacity(unsigned int i) { - return operator[](i).size; - } */ - protected: unsigned int ram_max; unsigned int ram_used; + protected: std::list pqueue; std::map::iterator> index; diff --git a/apps/nexus/crude.cpp b/apps/nexus/crude.cpp index 9cf0b875..23814db2 100644 --- a/apps/nexus/crude.cpp +++ b/apps/nexus/crude.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.3 2004/11/30 22:50:30 ponchio +Level 0. + Revision 1.2 2004/07/02 13:08:11 ponchio Changed extension to .cri, crv, crf @@ -36,6 +39,7 @@ Created ****************************************************************************/ +#include #include "crude.h" using namespace std; diff --git a/apps/nexus/crude.h b/apps/nexus/crude.h index c0aeb88c..a286a492 100644 --- a/apps/nexus/crude.h +++ b/apps/nexus/crude.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.5 2004/11/30 22:50:30 ponchio +Level 0. + Revision 1.4 2004/07/05 15:49:38 ponchio Windows (DevCpp, mingw) port. @@ -45,7 +48,7 @@ Created #ifndef NXS_CRUDE_H #define NXS_CRUDE_H -#include + #include #include #include diff --git a/apps/nexus/metric.h b/apps/nexus/metric.h index 0116308c..3edd2802 100644 --- a/apps/nexus/metric.h +++ b/apps/nexus/metric.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.8 2005/02/21 20:49:30 ponchio +some culling bug. + Revision 1.7 2005/02/20 19:49:44 ponchio cleaning (a bit more). @@ -90,7 +93,7 @@ namespace nxs { visible = false; error /= remote; } else if(entry.cone.Backface(sph, frustum.ViewPoint())) { - //visible = false; + visible = false; } } return error; diff --git a/apps/nexus/nexusmt.cpp b/apps/nexus/nexusmt.cpp index bb37994b..1b9eabc8 100644 --- a/apps/nexus/nexusmt.cpp +++ b/apps/nexus/nexusmt.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.35 2005/02/20 19:49:44 ponchio +cleaning (a bit more). + Revision 1.34 2005/02/20 18:07:01 ponchio cleaning. @@ -241,8 +244,8 @@ void NexusMt::Draw(unsigned int cell, DrawContest &contest) { fstart = NULL; vstart = NULL; - cstart = (char *)(64 * (int)patch.vstartc); - nstart = (char *)(64 * (int)patch.vstartn); + cstart = (char *)(patch.vstartc - patch.vstart); + nstart = (char *)(patch.vstartn - patch.vstart); } else { fstart = (char *)patch.FaceBegin(); vstart = (char *)patch.Vert3fBegin(); @@ -388,7 +391,7 @@ void NexusMt::LoadVbo(Entry &entry) { vbo_used += size; //TODO fix this when we allow data :p - size = 64 * (int)patch.vstartd; + size = patch.vstartd - patch.vstart; glGenBuffersARB(1, &entry.vbo_array); assert(entry.vbo_array); @@ -410,7 +413,7 @@ void NexusMt::FlushVbo(Entry &entry) { Patch &patch = *entry.patch; vbo_used -= patch.nf * sizeof(unsigned short); - vbo_used -= sizeof(float) * patch.vstartd; + vbo_used -= sizeof(float) * (patch.vstart - patch.vstartd); } //Kept for historical reasons. diff --git a/apps/nexus/nxsalgo.cpp b/apps/nexus/nxsalgo.cpp index 359aec9e..f9736f17 100644 --- a/apps/nexus/nxsalgo.cpp +++ b/apps/nexus/nxsalgo.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.22 2005/02/21 17:55:36 ponchio +debug debug debug + Revision 1.21 2005/02/20 18:07:01 ponchio cleaning. @@ -61,61 +64,184 @@ using namespace std; using namespace nxs; using namespace vcg; -#include "tristripper/tri_stripper.h" -using namespace triangle_stripper; +void nxs::Connect(Nexus &nexus, std::vector< set > &close, + float threshold) { -/*void nxs::TightSphere(vcg::Sphere3f &sphere, - std::vector &points) { - //test: - //assumes radius is ok.... and try to optimize moving center. - //TODO using a gradiend descent? really a mess. - Point3f center; - float radius; - Point3f pert[14]; - while(1) { - radius = sphere.Radius(); - float step = radius/40; - pert[0] = Point3f(step, 0, 0); - pert[1] = -pert[0]; - pert[2] = Point3f(0, step, 0); - pert[3] = -pert[2]; - pert[4] = Point3f(0, 0, step); - pert[5] = -pert[4]; - pert[6] = Point3f(step, step, step); - pert[7] = Point3f(step, step, -step); - pert[8] = Point3f(step, -step, step); - pert[9] = Point3f(step, -step, -step); - pert[10] = Point3f(-step, step, step); - pert[11] = Point3f(-step, step, -step); - pert[12] = Point3f(-step, -step, step); - pert[13] = Point3f(-step, -step, -step); + VPartition grid; + float max_radius = 0; + + for(unsigned int patch = 0; patch < nexus.size(); patch++) { + Sphere3f &sphere = nexus[patch].sphere; + grid.push_back(sphere.Center()); + float r = sphere.Radius(); + if(r > max_radius) max_radius = r; + } + grid.Init(); + close.clear(); + close.resize(nexus.size()); - unsigned int best = 14; - float best_radius = sphere.Radius(); + vector targets; + vector dists; + for(unsigned int patch = 0; patch < nexus.size(); patch++) { + float radius = nexus[patch].sphere.Radius(); + float max_distance = radius + max_radius + threshold; + max_distance *= max_distance; + grid.Closest(grid[patch], targets, dists, max_distance); - for(unsigned int k = 0; k < 14; k++) { - center = sphere.Center() + pert[k]; - radius = 0; - for(unsigned int i = 0; i < points.size(); i++) { - float r = 1.01 * Distance(center, points[i]); - if(r > radius) - radius = r; - } - if(radius < best_radius) { - best = k; - best_radius = radius; + for(unsigned int i = 0; i < targets.size(); i++) { + unsigned int target = targets[i]; + if(target == patch) continue; + float dist = radius + nexus[target].sphere.Radius() + threshold; + dist *= dist; + if(dist >= dists[i]) { + close[patch].insert(target); } } - if(best == 14) break; - sphere.Center() = sphere.Center() + pert[best]; - sphere.Radius() = best_radius; } - }*/ + + //DOUBLECROSS CHECK + for(unsigned int patch = 0; patch < nexus.size(); patch++) { + set::iterator i; + for(i = close[patch].begin(); i != close[patch].end(); i++) { + if(!close[*i].count(patch)) { + cerr << "Some problem width sphere intersection. Have alook.\n"; + cerr << "Meanwhile i fix it.\n"; + close[*i].insert(patch); + } + } + } +} + +void nxs::ComputeNormals(Nexus &nexus) { + assert(nexus.signature.vnorm); + assert(!nexus.borders.IsReadOnly()); + + //first calculate level 0 normals + //I load all patches in a fragment + //calculate normals + //fix external borders getting from level below + + //first try naive approach just load neighborough get normals and + //fix border with lower level + + vector levels; + nexus.history.BuildLevels(levels); + Report report(nexus.size(), 15); + + //TODO check level 0 is the finer onr + + int current_level = 0; + while(1) { + int count = 0; + for(unsigned int p = 0; p < nexus.size(); p++) { + if(levels[p] != current_level) continue; + count++; + report.Step(p); + + Border &border = nexus.GetBorder(p); + + map > normals; + normals[p] = vector(); + + for(unsigned int i = 0; i < border.Size(); i++) { + Link &link = border[i]; + if(levels[link.end_patch] == current_level) + normals[link.end_patch] = vector(); + } + map >::iterator k; + for(k = normals.begin(); k != normals.end(); k++) { + Patch &patch = nexus.GetPatch((*k).first); + + vector &normal = (*k).second; + normal.resize(patch.nv, Point3f(0, 0, 0)); + + if(nexus.signature.face == Signature::TRIANGLES) { + for(unsigned int i = 0; i < patch.nf; i++) { + unsigned short *f = patch.Face(i); + Point3f &v0 = patch.Vert3f(f[0]); + Point3f &v1 = patch.Vert3f(f[1]); + Point3f &v2 = patch.Vert3f(f[2]); + Point3f norm = (v1 - v0) ^ (v2 - v0); + normal[f[0]] += norm; + normal[f[1]] += norm; + normal[f[2]] += norm; + } + } else if(nexus.signature.face == Signature::STRIPS) { + for(int i = 0; i < patch.nf - 2; i++) { + unsigned short *f = patch.FaceBegin() + i; + Point3f &v0 = patch.Vert3f(f[0]); + Point3f &v1 = patch.Vert3f(f[1]); + Point3f &v2 = patch.Vert3f(f[2]); + Point3f norm = (v1 - v0) ^ (v2 - v0); + if(i%2) norm = -norm; + normal[f[0]] += norm; + normal[f[1]] += norm; + normal[f[2]] += norm; + } + } else + assert(0); + } + + //now fix borders + map > lowers; + for(unsigned int i = 0; i < border.Size(); i++) { + Link &link = border[i]; + if(levels[link.end_patch] == current_level) { + //TODO remove these asserts + assert(normals[p].size() > link.start_vert); + assert(normals.count(link.end_patch)); + assert(normals[link.end_patch].size() > link.end_vert); + normals[p][link.start_vert] += normals[link.end_patch][link.end_vert]; + } else if (levels[link.end_patch] < current_level) { + lowers[link.end_patch].push_back(link); + } + } + + map >::iterator s; + for(s = lowers.begin(); s != lowers.end(); s++) { + Patch &patch = nexus.GetPatch((*s).first); + for(unsigned int i = 0; i < (*s).second.size(); i++) { + Link &link = (*s).second[i]; + if(nexus.signature.vnorm == Encodings::FLOAT3) + normals[p][link.start_vert] = + ((Point3f *)patch.VNormBegin())[link.end_vert]; + else if(nexus.signature.vnorm == Encodings::SHORT4) { + Point3f &nor = normals[p][link.start_vert]; + short *n = ((short *)patch.VNormBegin()) + 4*link.end_vert; + nor[0] = n[0]; + nor[1] = n[1]; + nor[2] = n[2]; + } + } + } + //copy and normalize + Patch &patch = nexus.GetPatch(p); + Entry &entry = nexus[p]; + Point3f *norm = (Point3f *)patch.VNormBegin(); + vector &newnormals = normals[p]; + assert(newnormals.size() == patch.nv); + for(unsigned int i = 0; i < patch.nv; i++) { + newnormals[i].Normalize(); + if(nexus.signature.vnorm == Encodings::SHORT4) { + newnormals[i] *= 32766; + short *np = ((short *)norm) + 4 * i; + np[0] = (short)newnormals[i][0]; + np[1] = (short)newnormals[i][1]; + np[2] = (short)newnormals[i][2]; + np[3] = 0; + } else if(nexus.signature.vnorm == Encodings::FLOAT3) + norm[i] = newnormals[i]; + } + } + if(count == 0) break; + current_level++; + } +} -void nxs::ComputeNormals(Nexus &nexus) { +/*void nxs::ComputeNormals(Nexus &nexus) { assert(nexus.signature.vnorm); //setting borders readonly: @@ -254,37 +380,7 @@ void nxs::ComputeNormals(Nexus &nexus) { } } } - - - - /* set close; - for(unsigned int i = 0; i < border.Size(); i++) { - Link &link = border[i]; - if(link.IsNull()) continue; - unsigned int off = tmpb_start[p]; - Point3f p = tmpb.read(off + i); - p += normals[link.start_vert]; - tmpb.write(off + i, p); - // tmpb[off + i] += normals[link.start_vert]; - close.insert(link.end_patch); - } - - set::iterator k; - for(k = close.begin(); k != close.end(); k++) { - Border &remote = nexus.GetBorder(*k); - unsigned int off = tmpb_start[*k]; - - for(unsigned int i = 0; i < remote.Size(); i++) { - Link &link = remote[i]; - if(link.IsNull()) continue; - if(link.end_patch != p) continue; - Point3f p = tmpb.read(off + i); - p += normals[link.end_vert]; - tmpb.write(off + i, p); - // tmpb[off + i] += normals[link.end_vert]; - } - }*/ - } + } //Second step unify normals across borders cerr << "Second step\n"; @@ -321,60 +417,9 @@ void nxs::ComputeNormals(Nexus &nexus) { tmpb.Delete(); //TODO remove temporary file. nexus.borders.SetReadOnly(false); -} + }*/ -void nxs::ComputeTriStrip(unsigned short nfaces, unsigned short *faces, - vector &strip) { - - vector index; - index.resize(nfaces*3); - for(int i = 0; i < nfaces*3; i++) { - index[i] = faces[i]; - } - int cache_size = 0; - tri_stripper stripper(index); - stripper.SetCacheSize(cache_size); - // = 0 will disable the cache optimizer - stripper.SetMinStripSize(0); - tri_stripper::primitives_vector primitives; - stripper.Strip(&primitives); - - if(primitives.back().m_Indices.size() < 3) { - primitives.pop_back(); - } - //TODO spostare questo dentro il ciclo che rimonta le strip. - if(primitives.back().m_Type == tri_stripper::PT_Triangles) { - tri_stripper::primitives p; - p = primitives.back(); - primitives.pop_back(); - for(unsigned int i = 0; i < p.m_Indices.size(); i += 3) { - tri_stripper::primitives s; - s.m_Type = tri_stripper::PT_Triangle_Strip; - s.m_Indices.push_back(p.m_Indices[i]); - s.m_Indices.push_back(p.m_Indices[i+1]); - s.m_Indices.push_back(p.m_Indices[i+2]); - primitives.push_back(s); - } - } - - for(unsigned int i = 0; i < primitives.size(); i++) { - tri_stripper::primitives &primitive = primitives[i]; - assert(primitive.m_Indices.size() != 0); - int len = primitive.m_Indices.size(); - for(int l = 0; l < len; l++) - strip.push_back(primitive.m_Indices[l]); - - - if(i < primitives.size()-1) { //not the last primitive. - strip.push_back(primitive.m_Indices[len-1]); - //TODO optimize this! - if((len%2) == 1) //do not change orientation.... - strip.push_back(primitive.m_Indices[len-1]); - strip.push_back(primitives[i+1].m_Indices[0]); - } - } -} /* //TODO why i created this function? wonder... @@ -415,6 +460,35 @@ void nxs::Reorder(Signature &signature, Patch &patch) { }*/ //TODO actually use threshold + +void nxs::Unify(Nexus &nexus, float threshold) { + /* threshold = 0.00001; + unsigned int duplicated = 0; + unsigned int degenerate = 0; + + for(unsigned int p = 0; p < nexus.size(); p++) { + if(levels[p] != current_level) continue; + count++; + report.Step(p); + + Border &border = nexus.GetBorder(p); + + map > normals; + normals[p] = vector(); + + for(unsigned int i = 0; i < border.Size(); i++) { + Link &link = border[i]; + if(levels[link.end_patch] == current_level) + normals[link.end_patch] = vector(); + } + map >::iterator k; + for(k = normals.begin(); k != normals.end(); k++) { + Patch &patch = nexus.GetPatch((*k).first); + } + }*/ +} + +/* void nxs::Unify(Nexus &nexus, float threshold) { threshold = 0.001; //TODO what if colors or normals or strips? @@ -551,7 +625,7 @@ void nxs::Unify(Nexus &nexus, float threshold) { if(degenerate) cerr << "Found " << degenerate << " degenerate face while unmifying\n"; } - +*/ void nxs::ZSort(Nexus &nexus, vector &forward, vector &backward) { //lets get a bounding box from the sphere: @@ -590,3 +664,4 @@ void nxs::ZSort(Nexus &nexus, vector &forward, for(unsigned int i = 0; i < backward.size(); i++) backward[forward[i]] = i; } + diff --git a/apps/nexus/nxsalgo.h b/apps/nexus/nxsalgo.h index 5775971d..993a618f 100644 --- a/apps/nexus/nxsalgo.h +++ b/apps/nexus/nxsalgo.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.8 2005/02/21 17:55:36 ponchio +debug debug debug + Revision 1.7 2005/02/20 18:07:01 ponchio cleaning. @@ -42,6 +45,7 @@ Added copyright #ifndef NXS_ALGO_H #define NXS_ALGO_H +#include #include #include "patch.h" #include @@ -58,10 +62,13 @@ namespace nxs { bool operator<(const ZEntry &e) const { return pos < e.pos; } }; + //for every patch return close by (sphere intersecting) + //threshold is added to the distance to make sure we do not miss anything + void Connect(Nexus &nexus, std::vector< std::set > &close, + float threshold); + void ComputeNormals(Nexus &nexus); - void ComputeTriStrip(unsigned short nfaces, unsigned short *faces, - std::vector &strip); - void Reorder(Signature &signature, nxs::Patch &patch); + void Unify(Nexus &nexus, float threshold); void ZSort(Nexus &nexus, std::vector &forward, std::vector &backward); diff --git a/apps/nexus/nxsbuilder.cpp b/apps/nexus/nxsbuilder.cpp index 58331120..b8b34d71 100644 --- a/apps/nexus/nxsbuilder.cpp +++ b/apps/nexus/nxsbuilder.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.20 2005/02/21 17:55:47 ponchio +debug debug debug + Revision 1.19 2005/02/20 18:07:01 ponchio cleaning. @@ -432,7 +435,6 @@ void FourthStep(const string &crudefile, const string &output, exit(0); } nexus.MaxRam() = ram_buffer / nexus.chunk_size; - //TODO Clear borders in case of failure! VFile vert_remap; if(!vert_remap.Load(output + ".rvm", true)) { @@ -446,71 +448,48 @@ void FourthStep(const string &crudefile, const string &output, exit(0); } - /*float max_radius = 0; - VPartition grid; - for(int start = 0; start < nexus.size(); start++) { - Entry &entry = nexus[start]; - Sphere3f &sphere = entry.sphere; - if(sphere.Radius() > max_radius) max_radius = sphere.Radius(); - grid.push_back(sphere.Center()); - } - grid.Init(); - max_radius *= max_radius * 4; - vector nears; - vector dists; */ - + vector > close; + Connect(nexus, close, 0.0001); Report report(nexus.size()); for(int start = 0; start < nexus.size(); start++) { report.Step(start); - Entry &s_entry = nexus[start]; - Sphere3f &sphere = s_entry.sphere; + // Entry &s_entry = nexus[start]; + // Sphere3f &sphere = s_entry.sphere; vector links; -#ifdef WIN32 - hash_map vremap; -#else map vremap; -#endif for(unsigned int i = 0; i < vert_index[start].size; i++) { unsigned int global = vert_remap[vert_index[start].offset + i]; vremap[global] = i; } - - /*unsigned int n_nears = 10; - while(1) { - if(n_nears > grid.size()) n_nears = grid.size(); - grid.Closest(sphere.Center(), n_nears, nears, dists); - if(dists.back() > max_radius) break; - if(n_nears == grid.size()) break; - n_nears *= 2; - } + + // for(int end = 0; end < nexus.size(); end++) { + // if(start == end) continue; + set::iterator t; + for(t = close[start].begin(); t != close[start].end(); t++) { + unsigned int end = (*t); - for(int n = 0; n < nears.size(); n++) { - unsigned int end = nears[n]; */ - for(int end = 0; end < nexus.size(); end++) { - if(start == end) continue; - - Entry &e_entry = nexus[end]; - float dist = Distance(s_entry.sphere, e_entry.sphere); + // Entry &e_entry = nexus[end]; + // float dist = Distance(s_entry.sphere.Center(), e_entry.sphere.Center()); - if(dist > s_entry.sphere.Radius() + e_entry.sphere.Radius()) { - continue; - } + // if(dist > s_entry.sphere.Radius() + e_entry.sphere.Radius()) { + // continue; + // } + // assert(close[start].count(end)); 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); - } + 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); + } } } - Border &border = nexus.GetBorder(start); nexus.borders.ResizeBorder(start, 3 * links.size()); border.used = links.size(); diff --git a/apps/nexus/nxsedit.cpp b/apps/nexus/nxsedit.cpp index 605879d0..43d02a5c 100644 --- a/apps/nexus/nxsedit.cpp +++ b/apps/nexus/nxsedit.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.25 2005/02/21 17:55:47 ponchio +debug debug debug + Revision 1.24 2005/02/20 19:49:44 ponchio cleaning (a bit more). @@ -68,6 +71,7 @@ Added copyright #include #include "nxsalgo.h" +#include "strip.h" #include "nexus.h" #include "watch.h" @@ -463,14 +467,14 @@ int main(int argc, char *argv[]) { if(add_strips) { ComputeTriStrip(src_patch.nf, src_patch.FaceBegin(), strip); assert(strip.size() < 32767); - out.AddPatch(src_entry.nvert, strip.size(), src_border.Available()); + out.AddPatch(src_entry.nvert, strip.size(), src_border.Capacity()); if(verbose) { cerr << "tri: " << src_patch.nf << " strip: " << strip.size() << " ratio: " << (float)strip.size()/(float)src_patch.nf << endl; } } else - out.AddPatch(src_entry.nvert, src_entry.nface, src_border.Available()); + out.AddPatch(src_entry.nvert, src_entry.nface, src_border.Capacity()); Entry &dst_entry = out[p]; diff --git a/apps/nexus/nxspatcher.cpp b/apps/nexus/nxspatcher.cpp index 48ca3466..43f543c3 100644 --- a/apps/nexus/nxspatcher.cpp +++ b/apps/nexus/nxspatcher.cpp @@ -26,8 +26,9 @@ int main(int argc, char *argv[]) { crude.Resize(side * side, (side-1) * (side-1) * 2); for(unsigned int x = 0; x < side; x++) for(unsigned int y = 0; y < side; y++) { - Point3f p(x*x*x/((float)side), - y*y*y/((float)side), x*y/((float)side)); + // Point3f p(x*x*x/((float)side), + // y*y*y/((float)side), x*y/((float)side)); + Point3f p(x, y, sqrt((float)x*x + y*y)); crude.SetVertex(x + side * y, p); crude.GetBox().Add(p); } diff --git a/apps/nexus/patch.cpp b/apps/nexus/patch.cpp index 6e98b7ec..27600838 100644 --- a/apps/nexus/patch.cpp +++ b/apps/nexus/patch.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.12 2005/02/21 19:05:58 ponchio +i already fixed this bug. I hate you cvs. + Revision 1.11 2005/02/19 12:06:55 ponchio Debug... @@ -85,9 +88,9 @@ Encodings::Encodings() { } -void pad64(unsigned int &s) { - if((s & 0x0000003f) != 0) { - s>>=6; s++; s<<=6; +void pad8(unsigned int &s) { + if((s & 0x00000007) != 0) { + s>>=3; s++; s<<=3; } } void pad(unsigned int &size) { @@ -165,34 +168,33 @@ void Patch::Init(Signature &signature, assert(0); //non lo so... } - pad64(offset); + pad8(offset); - fstartc = (unsigned short)(offset/64); + fstartc = fstart + offset; offset += encodings[signature.fcolor].size(nf); - fstartn = (unsigned short)(offset/64); + fstartn = fstart + offset; offset += encodings[signature.fnorm].size(nf); - fstartt = (unsigned short)(offset/64); + fstartt = fstart + offset; offset += encodings[signature.ftext].size(nf); - fstartd = (unsigned short)(offset/64); + fstartd = fstart + offset; offset += encodings[signature.fdata].size(nf); vstart = fstart + offset; - offset = 0; if(signature.vert == Signature::POINT3F) offset += nv * sizeof(float) * 3; else if(signature.vert == Signature::POINT4F) offset += nv * sizeof(float) * 4; else assert(0); - pad64(offset); + pad8(offset); - vstartc = (unsigned short)(offset/64); + vstartc = fstart + offset; offset += encodings[signature.vcolor].size(nv); - vstartn = (unsigned short)(offset/64); + vstartn = fstart + offset; offset += encodings[signature.vnorm].size(nv); - vstartt = (unsigned short)(offset/64); + vstartt = fstart + offset; offset += encodings[signature.vtext].size(nv); - vstartd = (unsigned short)(offset/64); + vstartd = fstart + offset; offset += encodings[signature.vdata].size(nv); @@ -251,7 +253,7 @@ unsigned int Patch::ByteSize(Signature &signature, assert(0); //non lo so... } - pad64(size); + pad8(size); size += encodings[signature.fcolor].size(nface); size += encodings[signature.fnorm].size(nface); @@ -264,7 +266,7 @@ unsigned int Patch::ByteSize(Signature &signature, size += nvert * sizeof(float) * 4; else assert(0); - pad64(size); + pad8(size); size += encodings[signature.vcolor].size(nvert); size += encodings[signature.vnorm].size(nvert); diff --git a/apps/nexus/patch.h b/apps/nexus/patch.h index bdda6c0b..da77b2b9 100644 --- a/apps/nexus/patch.h +++ b/apps/nexus/patch.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.13 2005/02/19 12:06:55 ponchio +Debug... + Revision 1.12 2005/02/19 10:45:05 ponchio Patch generalized and small fixes. @@ -81,9 +84,9 @@ namespace nxs { unsigned int size(unsigned short n) { unsigned int s = (int)n * (int)bytes * (int)comps; - //padding a 64 bytes - if((s & 0x0000003f) != 0) { - s>>=6; s++; s<<=6; + //padding a 8 bytes + if((s & 0x0000007) != 0) { + s>>=3; s++; s<<=3; } return s; } @@ -121,15 +124,15 @@ class Patch { //vcg::Point3f &Vert(unsigned short v) { return VertBegin()[v]; } // unsigned short *Face(unsigned short f) { return FaceBegin() + f * 3; } - char *VColorBegin() { return vstart + 64*(int)vstartc; } - char *VNormBegin() { return vstart + 64*(int)vstartn; } - char *VTextBegin() { return vstart + 64*(int)vstartt; } - char *VDataBegin() { return vstart + 64*(int)vstartd; } + char *VColorBegin() { return vstartc; } + char *VNormBegin() { return vstartn; } + char *VTextBegin() { return vstartt; } + char *VDataBegin() { return vstartd; } - char *FColorBegin() { return fstart + 64*(int)fstartc; } - char *FNormBegin() { return fstart + 64*(int)fstartn; } - char *FTextBegin() { return fstart + 64*(int)fstartt; } - char *FDataBegin() { return fstart + 64*(int)fstartd; } + char *FColorBegin() { return fstartc; } + char *FNormBegin() { return fstartn; } + char *FTextBegin() { return fstartt; } + char *FDataBegin() { return fstartd; } static unsigned int ChunkSize(Signature &signature, unsigned short nvert, @@ -150,17 +153,15 @@ class Patch { unsigned short nf; unsigned short nv; - //these offset are from fstart in 64 bytes - unsigned short fstartc; - unsigned short fstartn; - unsigned short fstartt; - unsigned short fstartd; + char *fstartc; + char *fstartn; + char *fstartt; + char *fstartd; - //these offset are from vstart in 64 bytes - unsigned short vstartc; - unsigned short vstartn; - unsigned short vstartt; - unsigned short vstartd; + char *vstartc; + char *vstartn; + char *vstartt; + char *vstartd; }; } //namespace diff --git a/apps/nexus/vpartition.cpp b/apps/nexus/vpartition.cpp index d1976cce..0cfc6e4b 100644 --- a/apps/nexus/vpartition.cpp +++ b/apps/nexus/vpartition.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.4 2005/02/21 17:55:48 ponchio +debug debug debug + Revision 1.3 2005/01/21 17:09:13 ponchio Porting and debug. @@ -95,6 +98,32 @@ void VPartition::Closest(const vcg::Point3f &p, dist = (float)dists; } +void VPartition::Closest(const vcg::Point3f &p, + vector &targets, + vector &dists, + float max_distance) { + + double point[3]; point[0] = p[0]; point[1] = p[1]; point[2] = p[2]; + + int seeds = 6; + while(1) { + if(seeds > size()) seeds = size(); + targets.resize(seeds); + dists.resize(seeds); + bd->annkSearch(&point[0], seeds, &(targets[0]), &(dists[0])); + for(int i = 0; i < seeds; i++) { + if(dists[i] > max_distance) { + targets.resize(i); + dists.resize(i); + break; + } + } + if(targets.size() < seeds) break; + if(seeds == size()) break; + seeds *= 2; + } +} + void VPartition::Closest(const vcg::Point3f &p, unsigned int nsize, int *targets, double *dists) { diff --git a/apps/nexus/vpartition.h b/apps/nexus/vpartition.h index 74aa70f7..0453a825 100644 --- a/apps/nexus/vpartition.h +++ b/apps/nexus/vpartition.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.4 2005/02/21 17:55:49 ponchio +debug debug debug + Revision 1.3 2005/01/18 22:46:58 ponchio Small changes. @@ -53,6 +56,7 @@ class ANNbruteForce; namespace nxs { + //WARNING: all distances returned are SQUARED!!!! class VPartition: public std::vector { public: VPartition(): bd(NULL) {} @@ -75,6 +79,11 @@ class VPartition: public std::vector { std::vector &dist); void Closest(const vcg::Point3f &p, int &target, float &dist); + + //return all targets widthin that distance (SQUARED!!!) + void Closest(const vcg::Point3f &p, std::vector &targets, + std::vector &dists, + float max_distance); //most efficient! void Closest(const vcg::Point3f &p, unsigned int nsize, int *targets,