This commit is contained in:
Federico Ponchio 2004-07-02 17:42:43 +00:00
parent b5173291bb
commit d47430e87b
7 changed files with 130 additions and 43 deletions

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.2 2004/07/01 21:34:04 ponchio
Rehash bug.
Revision 1.1 2004/06/24 14:32:45 ponchio Revision 1.1 2004/06/24 14:32:45 ponchio
Moved from wrap/nexus Moved from wrap/nexus
@ -68,8 +71,9 @@ void MFHash::Resize(unsigned int n) {
FILE *fp = tmpfile(); FILE *fp = tmpfile();
unsigned int count = 0; unsigned int count = 0;
for(unsigned int i = 0; i < buffer.Size(); i++) { for(unsigned int i = 0; i < buffer.Size(); i++) {
if(!buffer[i].Empty()) { Bucket &bucket = buffer[i];
fwrite(&buffer[i], sizeof(Bucket), 1, fp); if(!bucket.Empty()) {
fwrite(&bucket, sizeof(Bucket), 1, fp);
++count; ++count;
} }
} }
@ -92,11 +96,13 @@ void MFHash::Insert(unsigned int key, unsigned int value, bool rehash) {
assert(space > 0); assert(space > 0);
unsigned int hash_size = buffer.Size(); unsigned int hash_size = buffer.Size();
unsigned int j = key % hash_size; unsigned int j = key % hash_size;
while(!buffer[j].Empty()) { Bucket bucket = buffer[j];
if(buffer[j].key == key && buffer[j].value == value) //already here while(!bucket.Empty()) {
if(bucket.key == key && bucket.value == value) //already here
return; return;
j++; j++;
if(j >= hash_size) j = 0; if(j >= hash_size) j = 0;
bucket = buffer[j];
} }
buffer[j] = Bucket(key, value); buffer[j] = Bucket(key, value);
space--; space--;

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.3 2004/07/02 13:08:43 ponchio
*** empty log message ***
Revision 1.2 2004/07/01 21:34:29 ponchio Revision 1.2 2004/07/01 21:34:29 ponchio
*** empty log message *** *** empty log message ***
@ -68,7 +71,8 @@ class MFHash {
unsigned int j = key % hash_size; unsigned int j = key % hash_size;
while(!buffer[j].Empty()) { while(!buffer[j].Empty()) {
if(buffer[j].key == key) { if(buffer[j].key == key) {
container.push_back(buffer[j].value); //container.push_back(buffer[j].value);
container.insert(buffer[j].value);
} }
j++; j++;
if(j >= hash_size) j = 0; if(j >= hash_size) j = 0;

View File

@ -2,7 +2,7 @@
#define NXS_PATCH_H #define NXS_PATCH_H
#include <vcg/space/point3.h> #include <vcg/space/point3.h>
#include <iostream>
namespace nxs { namespace nxs {
struct Chunk { struct Chunk {
@ -17,14 +17,23 @@ class Patch {
unsigned short &VertSize() { return *(unsigned short *)start; } unsigned short &VertSize() { return *(unsigned short *)start; }
vcg::Point3f *VertBegin() { vcg::Point3f *VertBegin() {
return (vcg::Point3f *)(start + 2*sizeof(short)); } return (vcg::Point3f *)(((char *)start) + 2*sizeof(short)); }
unsigned short &FaceSize() { return *(((unsigned short *)start) + 1); } unsigned short &FaceSize() { return *(((unsigned short *)start) + 1); }
unsigned short *FaceBegin() { unsigned short *FaceBegin() {
return (unsigned short *)(start + 2*sizeof(short) + return (unsigned short *)(((char *)start) + 2*sizeof(short) +
VertSize() * sizeof(vcg::Point3f)); } VertSize() * sizeof(vcg::Point3f)); }
vcg::Point3f &Vert(unsigned int v) {
return VertBegin()[v];
}
unsigned short *Face(unsigned int f) {
return FaceBegin() + f * 3;
}
unsigned int ChunkSize() { unsigned int ChunkSize() {
return ChunkSize(VertSize(), FaceSize()); return ChunkSize(VertSize(), FaceSize());
} }
@ -48,10 +57,10 @@ class Patch {
if(size < nface * 3 * sizeof(unsigned int)) if(size < nface * 3 * sizeof(unsigned int))
size = nface * 3 * sizeof(unsigned int); size = nface * 3 * sizeof(unsigned int);
size = 2 * sizeof(unsigned short); size += 2 * sizeof(unsigned short);
return size; return size;
} }
private: // private:
Chunk *start; Chunk *start;
}; };

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.3 2004/07/02 13:01:28 ponchio
Changed file extensions to .rmv, .rmb
Revision 1.2 2004/07/01 21:36:30 ponchio Revision 1.2 2004/07/01 21:36:30 ponchio
Various debug Various debug
@ -54,6 +57,11 @@ bool VertRemap::Load(const std::string &file) {
return true; return true;
} }
void VertRemap::Close() {
all.Close();
borders.Close();
}
void VertRemap::Resize(unsigned int n_vert) { void VertRemap::Resize(unsigned int n_vert) {
all.Resize(n_vert); all.Resize(n_vert);
for(unsigned int i = 0; i < n_vert; i++) for(unsigned int i = 0; i < n_vert; i++)

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.2 2004/07/02 13:02:00 ponchio
Backup.
Revision 1.1 2004/06/24 14:32:45 ponchio Revision 1.1 2004/06/24 14:32:45 ponchio
Moved from wrap/nexus Moved from wrap/nexus
@ -43,8 +46,10 @@ namespace nxs {
class VertRemap { class VertRemap {
public: public:
~VertRemap() { Close(); }
bool Create(const std::string &file); bool Create(const std::string &file);
bool Load(const std::string &file); bool Load(const std::string &file);
void Close();
void Resize(unsigned int n_vert); void Resize(unsigned int n_vert);
unsigned int Size(); unsigned int Size();
@ -56,8 +61,9 @@ class VertRemap {
assert(key < Size()); assert(key < Size());
container.clear(); container.clear();
if(all[key] == 0xffffffff) return; if(all[key] == 0xffffffff) return;
container.push_back(all[key]); // container.push_back(all[key]);
borders.GetValue(key, container); borders.GetValues(key, container);
container.insert(all[key]);
} }
VFile<unsigned int> all; VFile<unsigned int> all;

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.4 2004/07/02 13:02:39 ponchio
Added GetRegion, Read and Write
Revision 1.3 2004/07/01 21:36:54 ponchio Revision 1.3 2004/07/01 21:36:54 ponchio
*** empty log message *** *** empty log message ***
@ -69,6 +72,7 @@ template <class T> class VFile {
struct Buffer { struct Buffer {
unsigned int key; unsigned int key;
unsigned int size; //in number of elements
T *data; T *data;
}; };
@ -97,7 +101,7 @@ template <class T> class VFile {
}; };
VFile(): fp(NULL) {} VFile(): fp(NULL) {}
~VFile() { if(fp) Close(); } ~VFile() { Close(); }
bool Create(const std::string &filename, bool Create(const std::string &filename,
unsigned int _chunk_size = 4096/sizeof(T), unsigned int _chunk_size = 4096/sizeof(T),
unsigned int _queue_size = 1000) { unsigned int _queue_size = 1000) {
@ -130,9 +134,11 @@ template <class T> class VFile {
} }
void Close() { void Close() {
Flush(); if(fp) {
fclose(fp); Flush();
fp = 0; fclose(fp);
fp = NULL;
}
} }
void Flush() { void Flush() {
@ -145,7 +151,7 @@ template <class T> class VFile {
void FlushBuffer(Buffer buffer) { void FlushBuffer(Buffer buffer) {
fseek(fp, buffer.key * chunk_size * sizeof(T), SEEK_SET); fseek(fp, buffer.key * chunk_size * sizeof(T), SEEK_SET);
if(chunk_size != fwrite(buffer.data, sizeof(T), chunk_size, fp)) { if(buffer.size != fwrite(buffer.data, sizeof(T), buffer.size, fp)) {
assert(0 && "Could not write"); assert(0 && "Could not write");
} }
delete []buffer.data; delete []buffer.data;
@ -153,6 +159,7 @@ template <class T> class VFile {
void Resize(unsigned int elem) { void Resize(unsigned int elem) {
assert(fp); assert(fp);
Flush();
if(elem > n_elements) { if(elem > n_elements) {
if(-1 == fseek(fp, elem*sizeof(T) -1, SEEK_SET)) { if(-1 == fseek(fp, elem*sizeof(T) -1, SEEK_SET)) {
assert(0 && "Could not resize"); assert(0 && "Could not resize");
@ -161,7 +168,6 @@ template <class T> class VFile {
fwrite(&a, sizeof(unsigned char), 1, fp); fwrite(&a, sizeof(unsigned char), 1, fp);
} else { } else {
//TODO optimize: we do not need flush for buffers over elem. //TODO optimize: we do not need flush for buffers over elem.
Flush();
int fd = fileno(fp); int fd = fileno(fp);
ftruncate(fd, elem*sizeof(T)); ftruncate(fd, elem*sizeof(T));
} }
@ -177,13 +183,14 @@ template <class T> class VFile {
unsigned int chunk = n/chunk_size; unsigned int chunk = n/chunk_size;
unsigned int offset = n - chunk*chunk_size; unsigned int offset = n - chunk*chunk_size;
assert(offset < chunk_size*sizeof(T)); assert(offset < chunk_size * sizeof(T));
if(index.count(chunk)) if(index.count(chunk))
return *((*(index[chunk])).data + offset); return *((*(index[chunk])).data + offset);
if(buffers.size() > queue_size) { if(buffers.size() > queue_size) {
Buffer &buffer= buffers.back(); Buffer &buffer= buffers.back();
assert(buffer.key != chunk);
FlushBuffer(buffer); FlushBuffer(buffer);
index.erase(buffer.key); index.erase(buffer.key);
buffers.pop_back(); buffers.pop_back();
@ -191,17 +198,20 @@ template <class T> class VFile {
Buffer buffer; Buffer buffer;
buffer.key = chunk; buffer.key = chunk;
buffer.data = new T[chunk_size * sizeof(T)]; buffer.data = new T[chunk_size];
buffer.size = chunk_size;
if(buffer.size + chunk * chunk_size > n_elements)
buffer.size = n_elements -chunk * chunk_size;
buffers.push_front(buffer);
index[buffer.key] = buffers.begin();
if(fseek(fp, chunk * chunk_size * sizeof(T), SEEK_SET)) { if(fseek(fp, chunk * chunk_size * sizeof(T), SEEK_SET)) {
assert(0 && "failed to fseek"); assert(0 && "failed to fseek");
return *(buffer.data); return *(buffer.data);
} }
unsigned int data_size = chunk_size; if(buffer.size != fread(buffer.data, sizeof(T), buffer.size, fp)) {
if(data_size + chunk * chunk_size > n_elements)
data_size = -chunk * chunk_size + n_elements;
if(data_size != fread(buffer.data, sizeof(T), data_size, fp)) {
if(feof(fp)) { if(feof(fp)) {
assert(0 && "end of file"); assert(0 && "end of file");
} else { } else {
@ -210,8 +220,6 @@ template <class T> class VFile {
return (*buffer.data); return (*buffer.data);
} }
buffers.push_front(buffer);
index[chunk] = buffers.begin();
return *(buffer.data + offset); return *(buffer.data + offset);
} }
@ -238,17 +246,20 @@ template <class T> class VFile {
Buffer buffer; Buffer buffer;
buffer.key = chunk; buffer.key = chunk;
buffer.data = new T[chunk_size * sizeof(T)*size]; buffer.data = new T[chunk_size * size];
buffer.size = chunk_size * size;
if(buffer.size + chunk * chunk_size > n_elements)
buffer.size = -chunk * chunk_size + n_elements;
buffers.push_front(buffer);
index[chunk] = buffers.begin();
if(fseek(fp, chunk * chunk_size * sizeof(T), SEEK_SET)) { if(fseek(fp, chunk * chunk_size * sizeof(T), SEEK_SET)) {
assert(0 && "failed to fseek"); assert(0 && "failed to fseek");
return buffer.data; return buffer.data;
} }
unsigned int data_size = chunk_size*size; if(buffer.size != fread(buffer.data, sizeof(T), buffer.size, fp)) {
if(data_size + chunk * chunk_size > n_elements)
data_size = -chunk * chunk_size + n_elements;
if(data_size != fread(buffer.data, sizeof(T), data_size, fp)) {
if(feof(fp)) { if(feof(fp)) {
assert(0 && "end of file"); assert(0 && "end of file");
} else { } else {
@ -256,9 +267,6 @@ template <class T> class VFile {
} }
return buffer.data; return buffer.data;
} }
buffers.push_front(buffer);
index[chunk] = buffers.begin();
return buffer.data; return buffer.data;
} }

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.2 2004/07/02 13:09:31 ponchio
Extensions changed.
Revision 1.1 2004/07/01 21:32:18 ponchio Revision 1.1 2004/07/01 21:32:18 ponchio
Created Created
@ -80,6 +83,8 @@ int main(int argc, char *argv[]) {
return -1; return -1;
} }
cerr << "Verts: " << crude.Vertices() << endl;
cerr << "Faces: " << crude.Faces() << endl;
cerr << "Getting optimal radius...\n"; cerr << "Getting optimal radius...\n";
watch.Start(); watch.Start();
@ -95,8 +100,8 @@ int main(int argc, char *argv[]) {
crude.vert.End(), crude.vert.End(),
crude.GetBox(), crude.GetBox(),
target); target);
for(unsigned int i = 0; i < radius.size(); i++) // for(unsigned int i = 0; i < radius.size(); i++)
cerr << "Radius: " << radius[i] << endl; // cerr << "Radius: " << radius[i] << endl;
watch.Stop(); watch.Stop();
cerr << " ...done in " << watch.Elapsed() << " secs\n"; cerr << " ...done in " << watch.Elapsed() << " secs\n";
@ -134,7 +139,7 @@ int main(int argc, char *argv[]) {
cerr << "Could not create remap files: " << output << ".frm\n"; cerr << "Could not create remap files: " << output << ".frm\n";
return -1; return -1;
} }
face_remap.Resize(crude.face.Size()); face_remap.Resize(crude.Faces());
PIntersect<VoronoiPartition> inter(chain.levels[0], chain.levels[1]); PIntersect<VoronoiPartition> inter(chain.levels[0], chain.levels[1]);
@ -142,11 +147,9 @@ int main(int argc, char *argv[]) {
cerr << "Splitting faces... "; cerr << "Splitting faces... ";
Point3f bari; Point3f bari;
for(unsigned int i = 0; i < crude.face.Size(); i++) { for(unsigned int i = 0; i < crude.Faces(); i++) {
bari = crude.GetBari(i); bari = crude.GetBari(i);
unsigned int patch = inter.Locate(bari); unsigned int patch = inter.Locate(bari);
if(patch > 1000)
cerr << "Patch: " << patch << endl;
face_remap[i] = patch; face_remap[i] = patch;
} }
@ -166,18 +169,61 @@ int main(int argc, char *argv[]) {
cerr << "Splitting vertices... "; cerr << "Splitting vertices... ";
for(unsigned int i = 0; i < crude.face.Size(); i++) { unsigned int totvert = 0;
for(unsigned int i = 0; i < crude.Faces(); i++) {
Crude::Face &face = crude.GetFace(i); Crude::Face &face = crude.GetFace(i);
unsigned int patch = face_remap[i]; unsigned int patch = face_remap[i];
if((i % 10000) == 0) if((i % 10000) == 0)
cerr << "inserting: " << i << endl; cerr << "inserting: " << i << endl;
for(int k = 0; k < 3; k++) { for(int k = 0; k < 3; k++) {
//DEBUG:
set<unsigned int> pp;
vert_remap.GetValues(face[k], pp);
if(!pp.count(patch))
totvert++;
vert_remap.Insert(face[k], patch); vert_remap.Insert(face[k], patch);
} }
} }
watch.Stop(); watch.Stop();
cerr << "done in " << watch.Elapsed() << " secs\n"; cerr << "done in " << watch.Elapsed() << " secs\n";
cerr << "Tot vertices: " << totvert << endl;
chain.Save(output + ".chn"); chain.Save(output + ".chn");
for(unsigned int i = 0; i < vert_remap.all.Size(); i++) {
unsigned int patch = vert_remap.all[i];
if(patch == 0xffffffff) {
continue;
}
totvert--;
}
int totbord = 0;
VFile<MFHash::Bucket> &border = vert_remap.borders.buffer;
cerr << "Border space:" << border.Size() << endl;
for(unsigned int i = 0; i < border.Size(); i++) {
MFHash::Bucket &bucket = border[i];
if(bucket.key == 0xffffffff) continue;
totvert--;
totbord++;
}
cerr << "Borders: " << totbord << endl;
vert_remap.Close();
//DEBUG testing if vert_remap.borders works
/* for(unsigned int i = 0; i < crude.Faces(); i++) {
Crude::Face &face = crude.GetFace(i);
unsigned int patch = face_remap[i];
for(int k = 0; k < 3; k++) {
set<unsigned int> v;
vert_remap.GetValues(face[k], v);
assert(v.size() != 0);
if(!v.count(patch)) {
cerr << "count: " << v.size() << endl;
cerr << "patch " << patch << endl;
}
assert(v.count(patch));
}
}*/
return 0; return 0;
} }