Debug.
This commit is contained in:
parent
b5173291bb
commit
d47430e87b
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$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
|
||||
Moved from wrap/nexus
|
||||
|
||||
|
@ -68,8 +71,9 @@ void MFHash::Resize(unsigned int n) {
|
|||
FILE *fp = tmpfile();
|
||||
unsigned int count = 0;
|
||||
for(unsigned int i = 0; i < buffer.Size(); i++) {
|
||||
if(!buffer[i].Empty()) {
|
||||
fwrite(&buffer[i], sizeof(Bucket), 1, fp);
|
||||
Bucket &bucket = buffer[i];
|
||||
if(!bucket.Empty()) {
|
||||
fwrite(&bucket, sizeof(Bucket), 1, fp);
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
@ -92,11 +96,13 @@ void MFHash::Insert(unsigned int key, unsigned int value, bool rehash) {
|
|||
assert(space > 0);
|
||||
unsigned int hash_size = buffer.Size();
|
||||
unsigned int j = key % hash_size;
|
||||
while(!buffer[j].Empty()) {
|
||||
if(buffer[j].key == key && buffer[j].value == value) //already here
|
||||
Bucket bucket = buffer[j];
|
||||
while(!bucket.Empty()) {
|
||||
if(bucket.key == key && bucket.value == value) //already here
|
||||
return;
|
||||
j++;
|
||||
if(j >= hash_size) j = 0;
|
||||
bucket = buffer[j];
|
||||
}
|
||||
buffer[j] = Bucket(key, value);
|
||||
space--;
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$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
|
||||
*** empty log message ***
|
||||
|
||||
|
@ -68,7 +71,8 @@ class MFHash {
|
|||
unsigned int j = key % hash_size;
|
||||
while(!buffer[j].Empty()) {
|
||||
if(buffer[j].key == key) {
|
||||
container.push_back(buffer[j].value);
|
||||
//container.push_back(buffer[j].value);
|
||||
container.insert(buffer[j].value);
|
||||
}
|
||||
j++;
|
||||
if(j >= hash_size) j = 0;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define NXS_PATCH_H
|
||||
|
||||
#include <vcg/space/point3.h>
|
||||
|
||||
#include <iostream>
|
||||
namespace nxs {
|
||||
|
||||
struct Chunk {
|
||||
|
@ -17,14 +17,23 @@ class Patch {
|
|||
unsigned short &VertSize() { return *(unsigned short *)start; }
|
||||
|
||||
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 *FaceBegin() {
|
||||
return (unsigned short *)(start + 2*sizeof(short) +
|
||||
return (unsigned short *)(((char *)start) + 2*sizeof(short) +
|
||||
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() {
|
||||
return ChunkSize(VertSize(), FaceSize());
|
||||
}
|
||||
|
@ -48,10 +57,10 @@ class Patch {
|
|||
if(size < nface * 3 * sizeof(unsigned int))
|
||||
size = nface * 3 * sizeof(unsigned int);
|
||||
|
||||
size = 2 * sizeof(unsigned short);
|
||||
size += 2 * sizeof(unsigned short);
|
||||
return size;
|
||||
}
|
||||
private:
|
||||
// private:
|
||||
Chunk *start;
|
||||
};
|
||||
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$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
|
||||
Various debug
|
||||
|
||||
|
@ -54,6 +57,11 @@ bool VertRemap::Load(const std::string &file) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void VertRemap::Close() {
|
||||
all.Close();
|
||||
borders.Close();
|
||||
}
|
||||
|
||||
void VertRemap::Resize(unsigned int n_vert) {
|
||||
all.Resize(n_vert);
|
||||
for(unsigned int i = 0; i < n_vert; i++)
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$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
|
||||
Moved from wrap/nexus
|
||||
|
||||
|
@ -43,8 +46,10 @@ namespace nxs {
|
|||
|
||||
class VertRemap {
|
||||
public:
|
||||
~VertRemap() { Close(); }
|
||||
bool Create(const std::string &file);
|
||||
bool Load(const std::string &file);
|
||||
void Close();
|
||||
void Resize(unsigned int n_vert);
|
||||
|
||||
unsigned int Size();
|
||||
|
@ -56,8 +61,9 @@ class VertRemap {
|
|||
assert(key < Size());
|
||||
container.clear();
|
||||
if(all[key] == 0xffffffff) return;
|
||||
container.push_back(all[key]);
|
||||
borders.GetValue(key, container);
|
||||
// container.push_back(all[key]);
|
||||
borders.GetValues(key, container);
|
||||
container.insert(all[key]);
|
||||
}
|
||||
|
||||
VFile<unsigned int> all;
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$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
|
||||
*** empty log message ***
|
||||
|
||||
|
@ -69,6 +72,7 @@ template <class T> class VFile {
|
|||
|
||||
struct Buffer {
|
||||
unsigned int key;
|
||||
unsigned int size; //in number of elements
|
||||
T *data;
|
||||
};
|
||||
|
||||
|
@ -97,7 +101,7 @@ template <class T> class VFile {
|
|||
};
|
||||
|
||||
VFile(): fp(NULL) {}
|
||||
~VFile() { if(fp) Close(); }
|
||||
~VFile() { Close(); }
|
||||
bool Create(const std::string &filename,
|
||||
unsigned int _chunk_size = 4096/sizeof(T),
|
||||
unsigned int _queue_size = 1000) {
|
||||
|
@ -130,9 +134,11 @@ template <class T> class VFile {
|
|||
}
|
||||
|
||||
void Close() {
|
||||
if(fp) {
|
||||
Flush();
|
||||
fclose(fp);
|
||||
fp = 0;
|
||||
fp = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void Flush() {
|
||||
|
@ -145,7 +151,7 @@ template <class T> class VFile {
|
|||
|
||||
void FlushBuffer(Buffer buffer) {
|
||||
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");
|
||||
}
|
||||
delete []buffer.data;
|
||||
|
@ -153,6 +159,7 @@ template <class T> class VFile {
|
|||
|
||||
void Resize(unsigned int elem) {
|
||||
assert(fp);
|
||||
Flush();
|
||||
if(elem > n_elements) {
|
||||
if(-1 == fseek(fp, elem*sizeof(T) -1, SEEK_SET)) {
|
||||
assert(0 && "Could not resize");
|
||||
|
@ -161,7 +168,6 @@ template <class T> class VFile {
|
|||
fwrite(&a, sizeof(unsigned char), 1, fp);
|
||||
} else {
|
||||
//TODO optimize: we do not need flush for buffers over elem.
|
||||
Flush();
|
||||
int fd = fileno(fp);
|
||||
ftruncate(fd, elem*sizeof(T));
|
||||
}
|
||||
|
@ -184,6 +190,7 @@ template <class T> class VFile {
|
|||
|
||||
if(buffers.size() > queue_size) {
|
||||
Buffer &buffer= buffers.back();
|
||||
assert(buffer.key != chunk);
|
||||
FlushBuffer(buffer);
|
||||
index.erase(buffer.key);
|
||||
buffers.pop_back();
|
||||
|
@ -191,17 +198,20 @@ template <class T> class VFile {
|
|||
|
||||
Buffer buffer;
|
||||
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)) {
|
||||
assert(0 && "failed to fseek");
|
||||
return *(buffer.data);
|
||||
}
|
||||
|
||||
unsigned int data_size = chunk_size;
|
||||
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(buffer.size != fread(buffer.data, sizeof(T), buffer.size, fp)) {
|
||||
if(feof(fp)) {
|
||||
assert(0 && "end of file");
|
||||
} else {
|
||||
|
@ -210,8 +220,6 @@ template <class T> class VFile {
|
|||
return (*buffer.data);
|
||||
}
|
||||
|
||||
buffers.push_front(buffer);
|
||||
index[chunk] = buffers.begin();
|
||||
return *(buffer.data + offset);
|
||||
}
|
||||
|
||||
|
@ -238,17 +246,20 @@ template <class T> class VFile {
|
|||
|
||||
Buffer buffer;
|
||||
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)) {
|
||||
assert(0 && "failed to fseek");
|
||||
return buffer.data;
|
||||
}
|
||||
|
||||
unsigned int data_size = chunk_size*size;
|
||||
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(buffer.size != fread(buffer.data, sizeof(T), buffer.size, fp)) {
|
||||
if(feof(fp)) {
|
||||
assert(0 && "end of file");
|
||||
} else {
|
||||
|
@ -256,9 +267,6 @@ template <class T> class VFile {
|
|||
}
|
||||
return buffer.data;
|
||||
}
|
||||
|
||||
buffers.push_front(buffer);
|
||||
index[chunk] = buffers.begin();
|
||||
return buffer.data;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$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
|
||||
Created
|
||||
|
||||
|
@ -80,6 +83,8 @@ int main(int argc, char *argv[]) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
cerr << "Verts: " << crude.Vertices() << endl;
|
||||
cerr << "Faces: " << crude.Faces() << endl;
|
||||
cerr << "Getting optimal radius...\n";
|
||||
watch.Start();
|
||||
|
||||
|
@ -95,8 +100,8 @@ int main(int argc, char *argv[]) {
|
|||
crude.vert.End(),
|
||||
crude.GetBox(),
|
||||
target);
|
||||
for(unsigned int i = 0; i < radius.size(); i++)
|
||||
cerr << "Radius: " << radius[i] << endl;
|
||||
// for(unsigned int i = 0; i < radius.size(); i++)
|
||||
// cerr << "Radius: " << radius[i] << endl;
|
||||
|
||||
watch.Stop();
|
||||
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";
|
||||
return -1;
|
||||
}
|
||||
face_remap.Resize(crude.face.Size());
|
||||
face_remap.Resize(crude.Faces());
|
||||
|
||||
|
||||
PIntersect<VoronoiPartition> inter(chain.levels[0], chain.levels[1]);
|
||||
|
@ -142,11 +147,9 @@ int main(int argc, char *argv[]) {
|
|||
cerr << "Splitting faces... ";
|
||||
|
||||
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);
|
||||
unsigned int patch = inter.Locate(bari);
|
||||
if(patch > 1000)
|
||||
cerr << "Patch: " << patch << endl;
|
||||
face_remap[i] = patch;
|
||||
}
|
||||
|
||||
|
@ -166,18 +169,61 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
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);
|
||||
unsigned int patch = face_remap[i];
|
||||
if((i % 10000) == 0)
|
||||
cerr << "inserting: " << i << endl;
|
||||
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);
|
||||
}
|
||||
}
|
||||
watch.Stop();
|
||||
cerr << "done in " << watch.Elapsed() << " secs\n";
|
||||
cerr << "Tot vertices: " << totvert << endl;
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue