Debugging.

This commit is contained in:
Federico Ponchio 2004-10-21 13:40:16 +00:00
parent ff951fed19
commit ac405521f2
9 changed files with 72 additions and 55 deletions

View File

@ -26,12 +26,6 @@ class File {
readonly = file.readonly; readonly = file.readonly;
((File &)file).fp = NULL; ((File &)file).fp = NULL;
} }
bool operator=(const File &file) {
fp = file.fp;
size = file.size;
readonly = file.readonly;
((File &)file).fp = NULL;
}
bool Create(const std::string &filename); bool Create(const std::string &filename);
bool Load(const std::string &filename, bool readonly = false); bool Load(const std::string &filename, bool readonly = false);
void Close(); void Close();

View File

@ -5,8 +5,6 @@
using namespace std; using namespace std;
using namespace nxs; using namespace nxs;
typedef unsigned long long u64;
bool MFile::Create(const string &fname, unsigned int mxs) { bool MFile::Create(const string &fname, unsigned int mxs) {
filename = fname; filename = fname;
files.clear(); files.clear();
@ -14,8 +12,7 @@ bool MFile::Create(const string &fname, unsigned int mxs) {
readonly = false; readonly = false;
assert(mxs <= (1<<30)); assert(mxs <= (1<<30));
max_size = mxs; max_size = mxs;
AddFile(); return AddFile();
return true;
} }
bool MFile::Load(const string &fname, bool ronly) { bool MFile::Load(const string &fname, bool ronly) {
@ -55,26 +52,30 @@ void MFile::Close() {
files.clear(); files.clear();
} }
void MFile::Redim(unsigned long long sz) { void MFile::Redim(int64 sz) {
assert(!readonly); assert(!readonly);
if(sz > size) { if(sz > size) {
while(sz - size >= max_size) { unsigned int totfile = (unsigned int)(sz/max_size);
//TODO test rhis!!!!
while(files.size() < totfile) {
RedimLast(max_size); RedimLast(max_size);
AddFile(); AddFile();
} }
RedimLast(sz - size); assert(size < sz);
assert(sz - size < max_size);
RedimLast(files.back().Length() + (unsigned int)(sz - size));
} else { } else {
while(size - files.back().Length() > sz) while(size - files.back().Length() > sz)
RemoveFile(); RemoveFile();
assert(sz <= size); assert(sz <= size);
RedimLast(files.back().Length() - (size - sz)); RedimLast(files.back().Length() - (unsigned int)(size - sz));
} }
} }
void MFile::SetPosition(unsigned long long pos) { void MFile::SetPosition(int64 pos) {
assert(pos < size); assert(pos < size);
curr_fp = pos/(u64)max_size; curr_fp = (unsigned int)(pos/(int64)max_size);
curr_pos = pos - (u64)max_size * (u64)curr_fp; curr_pos = (unsigned int)(pos - (int64)max_size * (int64)curr_fp);
assert(curr_fp < files.size()); assert(curr_fp < files.size());
files[curr_fp].SetPosition(curr_pos); files[curr_fp].SetPosition(curr_pos);
} }
@ -106,11 +107,11 @@ void MFile::WriteBuffer(void *data, unsigned int sz) {
files[curr_fp].WriteBuffer(data, sz); files[curr_fp].WriteBuffer(data, sz);
} }
void MFile::AddFile() { bool MFile::AddFile() {
string name = Name(files.size()); string name = Name(files.size());
files.push_back(File()); files.push_back(File());
File &file = files.back(); File &file = files.back();
file.Create(name); return file.Create(name);
} }
void MFile::RemoveFile() { void MFile::RemoveFile() {

View File

@ -8,6 +8,11 @@
namespace nxs { namespace nxs {
#ifdef WIN32
typedef __int64 int64;
#else
typedef unsigned long long int64;
#endif
class MFile { class MFile {
public: public:
@ -21,10 +26,10 @@ class MFile {
bool Load(const std::string &filename, bool readonly = false); bool Load(const std::string &filename, bool readonly = false);
void Close(); void Close();
unsigned long long Length() { return size; } int64 Length() { return size; }
void Redim(unsigned long long size); void Redim(int64 size);
void SetPosition(unsigned long long pos); void SetPosition(int64 pos);
void ReadBuffer(void *data, unsigned int size); void ReadBuffer(void *data, unsigned int size);
void WriteBuffer(void *data, unsigned int size); void WriteBuffer(void *data, unsigned int size);
@ -35,12 +40,12 @@ class MFile {
std::vector<File> files; std::vector<File> files;
unsigned int curr_pos; unsigned int curr_pos;
unsigned int curr_fp; unsigned int curr_fp;
unsigned long long size; int64 size;
unsigned int max_size; unsigned int max_size;
bool readonly; bool readonly;
private: private:
//all theese refer to the last in the fp. //all theese refer to the last in the fp.
void AddFile(); bool AddFile();
void RemoveFile(); void RemoveFile();
void RedimLast(unsigned int sz); void RedimLast(unsigned int sz);
unsigned int GetSize(); unsigned int GetSize();

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.17 2004/10/21 12:22:21 ponchio
Small changes.
Revision 1.16 2004/10/19 01:23:02 ponchio Revision 1.16 2004/10/19 01:23:02 ponchio
Daily backup (fragment...) Daily backup (fragment...)
@ -431,7 +434,7 @@ int main(int argc, char *argv[]) {
void gl_print(float x, float y, char *str) { void gl_print(float x, float y, char *str) {
glRasterPos2f(x, y); glRasterPos2f(x, y);
int len = strlen(str); int len = (int)strlen(str);
for(int i = 0; i < len; i++) for(int i = 0; i < len; i++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, str[i]); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, str[i]);
} }

View File

@ -129,25 +129,25 @@ int main(int argc, char *argv[]) {
case 'z': compress = true; break; case 'z': compress = true; break;
case 'x': uncompress = true; break; case 'x': uncompress = true; break;
case 'v': qvertex = atof(optarg); case 'v': qvertex = (float)atof(optarg);
if(qvertex == 0) { if(qvertex == 0) {
cerr << "Invalid value for quantization: " << optarg << endl; cerr << "Invalid value for quantization: " << optarg << endl;
return -1; return -1;
} }
break; break;
case 'n': qnormal = atof(optarg); case 'n': qnormal = (float)atof(optarg);
if(qnormal == 0) { if(qnormal == 0) {
cerr << "Invalid value for quantization: " << optarg << endl; cerr << "Invalid value for quantization: " << optarg << endl;
return -1; return -1;
} }
break; break;
case 'k': qcolor = atof(optarg); case 'k': qcolor = (float)atof(optarg);
if(qcolor == 0) { if(qcolor == 0) {
cerr << "Invalid value for quantization: " << optarg << endl; cerr << "Invalid value for quantization: " << optarg << endl;
return -1; return -1;
} }
break; break;
case 't': qtexture = atof(optarg); case 't': qtexture = (float)atof(optarg);
if(qtexture == 0) { if(qtexture == 0) {
cerr << "Invalid value for quantization: " << optarg << endl; cerr << "Invalid value for quantization: " << optarg << endl;
return -1; return -1;
@ -262,6 +262,10 @@ int main(int argc, char *argv[]) {
return 0; return 0;
} }
if((add & NXS_NORMALS_SHORT) && compress) {
cerr << "Its not possible to add normals and compress in the same step\n";
return -1;
}
unsigned int signature = nexus.signature; unsigned int signature = nexus.signature;
signature |= add; signature |= add;
signature &= ~remove; signature &= ~remove;
@ -303,16 +307,17 @@ int main(int argc, char *argv[]) {
Nexus::PatchInfo &dst_entry = out.index[patch]; Nexus::PatchInfo &dst_entry = out.index[patch];
Patch dst_patch = out.GetPatch(patch); Patch dst_patch = out.GetPatch(patch);
//copy vertices: //copy vertices:
memcpy(dst_patch.VertBegin(), src_patch.VertBegin(), memcpy(dst_patch.VertBegin(), src_patch.VertBegin(),
src_patch.nv * sizeof(Point3f)); src_patch.nv * sizeof(Point3f));
if(qvertex) { if(qvertex && !add_normals) {
float *ptr = (float *)dst_patch.VertBegin(); float *ptr = (float *)dst_patch.VertBegin();
for(unsigned int i = 0; i < dst_patch.nv*3; i++) { for(int i = 0; i < dst_patch.nv*3; i++) {
ptr[i] = qvertex * nearbyintf(ptr[i]/qvertex); ptr[i] = qvertex * (int)(ptr[i]/qvertex);
//ptr[i] = 0; //ptr[i] = 0;
} }
} }
@ -324,22 +329,22 @@ int main(int argc, char *argv[]) {
strip.size() * sizeof(short)); strip.size() * sizeof(short));
} else { } else {
if(nexus.signature & NXS_STRIP) { if(nexus.signature & NXS_STRIP) {
memcpy(dst_patch.FaceBegin(), src_patch.FaceBegin(), memcpy(dst_patch.FaceBegin(), src_patch.FaceBegin(),
src_patch.nf * sizeof(unsigned short)); src_patch.nf * sizeof(unsigned short));
} else { } else {
memcpy(dst_patch.FaceBegin(), src_patch.FaceBegin(), memcpy(dst_patch.FaceBegin(), src_patch.FaceBegin(),
src_patch.nf * sizeof(unsigned short) * 3); src_patch.nf * sizeof(unsigned short) * 3);
} }
} }
if((nexus.signature & NXS_COLORS) && (out.signature & NXS_COLORS)) if((nexus.signature & NXS_COLORS) && (out.signature & NXS_COLORS))
memcpy(dst_patch.ColorBegin(), src_patch.ColorBegin(), memcpy(dst_patch.ColorBegin(), src_patch.ColorBegin(),
src_patch.nv * sizeof(unsigned int)); src_patch.nv * sizeof(unsigned int));
if((nexus.signature & NXS_NORMALS_SHORT) && if((nexus.signature & NXS_NORMALS_SHORT) &&
(out.signature & NXS_NORMALS_SHORT)) (out.signature & NXS_NORMALS_SHORT))
memcpy(dst_patch.Norm16Begin(), src_patch.Norm16Begin(), memcpy(dst_patch.Norm16Begin(), src_patch.Norm16Begin(),
src_patch.nv * sizeof(short)*4); src_patch.nv * sizeof(short)*4);
//reordering //reordering
//WATCH OUT BORDERS! //WATCH OUT BORDERS!
@ -372,7 +377,7 @@ int main(int argc, char *argv[]) {
cerr << "Unsupported color\n"; cerr << "Unsupported color\n";
return -1; return -1;
} }
if(qvertex) { if(qvertex && add_normals) {
report.Init(nexus.index.size()); report.Init(nexus.index.size());
cout << "Quantizing vertices\n"; cout << "Quantizing vertices\n";
for(unsigned int patch = 0; patch < nexus.index.size(); patch++) { for(unsigned int patch = 0; patch < nexus.index.size(); patch++) {
@ -380,8 +385,8 @@ int main(int argc, char *argv[]) {
Patch src_patch = nexus.GetPatch(patch); Patch src_patch = nexus.GetPatch(patch);
float *ptr = (float *)src_patch.VertBegin(); float *ptr = (float *)src_patch.VertBegin();
for(unsigned int i = 0; i < src_patch.nv*3; i++) for(int i = 0; i < src_patch.nv*3; i++)
ptr[i] = qvertex * nearbyintf(ptr[i]/qvertex); ptr[i] = qvertex * (int)(ptr[i]/qvertex);
} }
report.Finish(); report.Finish();
} }

View File

@ -221,7 +221,7 @@ void PatchServer::Flush(PTime &ptime) {
if(entry.disk_size == 0xffff) {//allocate space if(entry.disk_size == 0xffff) {//allocate space
assert(entry.patch_start == 0xffffffff); assert(entry.patch_start == 0xffffffff);
entry.disk_size = (unsigned int)((compressed_size-1)/chunk_size) + 1; entry.disk_size = (unsigned int)((compressed_size-1)/chunk_size) + 1;
entry.patch_start = Length()/chunk_size; entry.patch_start = (unsigned int)(Length()/chunk_size);
Redim(Length() + entry.disk_size * chunk_size); Redim(Length() + entry.disk_size * chunk_size);
} else { } else {
cerr << "OOOOPSPPPS not supported!" << endl; cerr << "OOOOPSPPPS not supported!" << endl;
@ -233,7 +233,7 @@ void PatchServer::Flush(PTime &ptime) {
} else { } else {
if(entry.disk_size == 0xffff) { if(entry.disk_size == 0xffff) {
entry.disk_size = entry.ram_size; entry.disk_size = entry.ram_size;
entry.patch_start = Length()/chunk_size; entry.patch_start = (unsigned int)(Length()/chunk_size);
Redim(Length() + entry.disk_size * chunk_size); Redim(Length() + entry.disk_size * chunk_size);
} }
SetPosition(entry.patch_start * chunk_size); SetPosition(entry.patch_start * chunk_size);

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.17 2004/10/21 12:22:21 ponchio
Small changes.
Revision 1.16 2004/10/19 01:23:02 ponchio Revision 1.16 2004/10/19 01:23:02 ponchio
Daily backup (fragment...) Daily backup (fragment...)
@ -390,7 +393,7 @@ void NexusSplit(Nexus &nexus, VoronoiChain &vchain,
} }
centroid /= newface.size()/3; centroid /= newface.size()/3;
//prune small cells: //prune small cells:
float min_size = (newface.size()/3) / 20; float min_size = (newface.size()/3) / 20.0f;
vector<unsigned int> cellremap; vector<unsigned int> cellremap;
VoronoiPartition local; VoronoiPartition local;

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.2 2004/10/21 12:14:02 ponchio
Support for mfile (>4Gb)
Revision 1.1 2004/10/19 17:20:24 ponchio Revision 1.1 2004/10/19 17:20:24 ponchio
renamed renamed
@ -58,19 +61,19 @@ void Watch::Start(void) {
elapsed = 0; elapsed = 0;
} }
double Watch::Pause() { float Watch::Pause() {
QueryPerformanceCounter(&tend); QueryPerformanceCounter(&tend);
elapsed += Diff(); elapsed += Diff();
return elapsed; return (float)elapsed;
} }
void Watch::Continue() { void Watch::Continue() {
QueryPerformanceCounter(&tstart); QueryPerformanceCounter(&tstart);
} }
double Watch::Time() { float Watch::Time() {
QueryPerformanceCounter(&tend); QueryPerformanceCounter(&tend);
return elapsed + Diff(); return (float)(elapsed + Diff());
} }
double Watch::Diff() { double Watch::Diff() {
@ -88,19 +91,19 @@ void Watch::Start() {
elapsed = 0; elapsed = 0;
} }
double Watch::Pause() { float Watch::Pause() {
gettimeofday(&tend, &tz); gettimeofday(&tend, &tz);
elapsed += Diff(); elapsed += Diff();
return elapsed; return (float)elapsed;
} }
void Watch::Continue() { void Watch::Continue() {
gettimeofday(&tstart, &tz); gettimeofday(&tstart, &tz);
} }
double Watch::Time() { float Watch::Time() {
gettimeofday(&tend, &tz); gettimeofday(&tend, &tz);
return elapsed + Diff(); return (float)(elapsed + Diff());
} }
double Watch::Diff() { double Watch::Diff() {

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.2 2004/10/21 12:14:02 ponchio
Support for mfile (>4Gb)
Revision 1.1 2004/10/19 17:20:24 ponchio Revision 1.1 2004/10/19 17:20:24 ponchio
renamed renamed
@ -53,10 +56,10 @@ class Watch {
public: public:
Watch(); Watch();
void Start(); void Start();
double Pause(); float Pause();
void Continue(); void Continue();
void Reset(); void Reset();
double Time(); float Time();
int Usec(); int Usec();
private: private:
double Diff(); double Diff();