From c6a58807ee8a55c79d5cdfac4eae648b7b25b05d Mon Sep 17 00:00:00 2001 From: ponchio Date: Fri, 25 Jun 2004 16:47:13 +0000 Subject: [PATCH] Various debug --- apps/nexus/crude.h | 6 +++- apps/nexus/pchain.h | 6 +++- apps/nexus/pvoronoi.h | 70 +++++++++++++++++++++++++++++++++++++++++-- apps/nexus/vfile.h | 21 +++++++++++-- 4 files changed, 96 insertions(+), 7 deletions(-) diff --git a/apps/nexus/crude.h b/apps/nexus/crude.h index 6783c6bd..e494a7d9 100644 --- a/apps/nexus/crude.h +++ b/apps/nexus/crude.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.1 2004/06/24 14:32:45 ponchio +Moved from wrap/nexus + Revision 1.1 2004/06/22 15:31:40 ponchio Created @@ -77,10 +80,11 @@ public: vcg::Box3f &GetBox(); - protected: VFile vert; VFile face; + protected: + FILE *fp; unsigned int nvert; unsigned int nface; diff --git a/apps/nexus/pchain.h b/apps/nexus/pchain.h index f886978d..16321873 100644 --- a/apps/nexus/pchain.h +++ b/apps/nexus/pchain.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.1 2004/06/24 14:32:45 ponchio +Moved from wrap/nexus + Revision 1.2 2004/06/24 14:19:20 ponchio Debugged @@ -37,12 +40,13 @@ Created #define NXS_PCHAIN_H #include +#include #include /** Partition must be a class with a Key type, with Levels, Locate, Priority, Save(FILE *), Load(FILE *) as in pvoronoi.h */ -namespace { +namespace nxs { template class PChain { public: diff --git a/apps/nexus/pvoronoi.h b/apps/nexus/pvoronoi.h index c932bd1b..2a82b6b9 100644 --- a/apps/nexus/pvoronoi.h +++ b/apps/nexus/pvoronoi.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.1 2004/06/24 14:32:45 ponchio +Moved from wrap/nexus + Revision 1.2 2004/06/24 14:19:20 ponchio Debugged @@ -104,14 +107,77 @@ namespace nxs { bool Load(const std::string &file); unsigned int Save(FILE *fp); unsigned int Load(FILE *fp); - private: - vcg::Box3f bbox; + + /** Pass iterators to Point3f container and size + to estimate optimal radius. + At the moment strategy is to campion randomly the file. + */ + template + static std::vector OptimalRadii(unsigned int total, + T begin, T end, + vcg::Box3f &box, + std::vector target) { + + //number of samples + unsigned int n_points = 20; + std::vector samples; + + T i; + unsigned int h; + for(i = begin, h =0; i != end; ++i, h++) + if(!((h+1)%(total/n_points))) + samples.push_back(*i); + + + float step = box.Diag()/10000; + + //for every sample i need to record function distance -> number of points + std::vector< std::vector > scale; + scale.resize(samples.size()); + for(unsigned int i = 0; i < samples.size(); i++) + scale[i].resize(10001, 0); + + + //for every point we check distance from samples + for(i = begin; i != end; ++i) { + vcg::Point3f &vp = *i; + for(unsigned int k = 0; k < samples.size(); k++) { + float dist = (vp - samples[k]).Norm(); + unsigned int pos = (int)(dist/step); + if(pos < 10000) + scale[k][pos]++; + } + } + + + float count =0; + unsigned int tcount = 0; + std::vector counting; + for(int j = 0; j < 10000; j++) { + for(unsigned int k = 0; k < samples.size(); k++) + count += scale[k][j]; + if(count > samples.size() * target[tcount]) { + counting.push_back(j); + tcount ++; + if(tcount >= target.size()) + j = 10000; + } + } + std::vector radius; + for(unsigned int i = 0; i < counting.size(); i++) + radius.push_back(2 * step * (counting[i])); + return radius; + } + + private: + vcg::Box3f bbox; vcg::GridStaticPtr< std::vector > ug; std::vector all_seeds; std::vector ug_seeds; std::vector seedBuf; }; + } #endif diff --git a/apps/nexus/vfile.h b/apps/nexus/vfile.h index bb7da8a4..c1d52eb1 100644 --- a/apps/nexus/vfile.h +++ b/apps/nexus/vfile.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.1 2004/06/24 14:32:45 ponchio +Moved from wrap/nexus + Revision 1.3 2004/06/22 15:32:09 ponchio Tested @@ -67,15 +70,25 @@ template class VFile { FILE *fp; std::list buffers; - typedef typename std::list::iterator iterator; + typedef typename std::list::iterator list_iterator; - std::map index; //TODO move to hash_map + std::map index; //TODO move to hash_map unsigned int chunk_size; //default buffer size (expressed in number of T) unsigned int queue_size; unsigned int n_elements; //size of the vector public: + class iterator { + public: + iterator(unsigned int p = 0, VFile *b = 0): n(p), buffer(b) {} + T &operator*() { return (*buffer)[n]; } + void operator++() { n++; } + bool operator!=(const iterator &i) { return i.n != n; } + private: + unsigned int n; + VFile *buffer; + }; VFile(): fp(NULL) {} ~VFile() { if(fp) Close(); } @@ -117,7 +130,7 @@ template class VFile { } void Flush() { - iterator i; + list_iterator i; for(i = buffers.begin(); i != buffers.end(); i++) FlushBuffer(*i); buffers.clear(); @@ -201,6 +214,8 @@ template class VFile { unsigned int Size() { return n_elements; } unsigned int ChunkSize() { return chunk_size; } unsigned int QueueSize() { return queue_size; } + iterator Begin() { return iterator(0, this); } + iterator End() { return iterator(Size(), this); } protected: void SetPosition(unsigned int chunk) {