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;
((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 Load(const std::string &filename, bool readonly = false);
void Close();

View File

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

View File

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

View File

@ -24,6 +24,9 @@
History
$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
Daily backup (fragment...)
@ -431,7 +434,7 @@ int main(int argc, char *argv[]) {
void gl_print(float x, float y, char *str) {
glRasterPos2f(x, y);
int len = strlen(str);
int len = (int)strlen(str);
for(int i = 0; i < len; 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 'x': uncompress = true; break;
case 'v': qvertex = atof(optarg);
case 'v': qvertex = (float)atof(optarg);
if(qvertex == 0) {
cerr << "Invalid value for quantization: " << optarg << endl;
return -1;
}
break;
case 'n': qnormal = atof(optarg);
case 'n': qnormal = (float)atof(optarg);
if(qnormal == 0) {
cerr << "Invalid value for quantization: " << optarg << endl;
return -1;
}
break;
case 'k': qcolor = atof(optarg);
case 'k': qcolor = (float)atof(optarg);
if(qcolor == 0) {
cerr << "Invalid value for quantization: " << optarg << endl;
return -1;
}
break;
case 't': qtexture = atof(optarg);
case 't': qtexture = (float)atof(optarg);
if(qtexture == 0) {
cerr << "Invalid value for quantization: " << optarg << endl;
return -1;
@ -262,6 +262,10 @@ int main(int argc, char *argv[]) {
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;
signature |= add;
signature &= ~remove;
@ -303,16 +307,17 @@ int main(int argc, char *argv[]) {
Nexus::PatchInfo &dst_entry = out.index[patch];
Patch dst_patch = out.GetPatch(patch);
//copy vertices:
memcpy(dst_patch.VertBegin(), src_patch.VertBegin(),
src_patch.nv * sizeof(Point3f));
if(qvertex) {
if(qvertex && !add_normals) {
float *ptr = (float *)dst_patch.VertBegin();
for(unsigned int i = 0; i < dst_patch.nv*3; i++) {
ptr[i] = qvertex * nearbyintf(ptr[i]/qvertex);
for(int i = 0; i < dst_patch.nv*3; i++) {
ptr[i] = qvertex * (int)(ptr[i]/qvertex);
//ptr[i] = 0;
}
}
@ -372,7 +377,7 @@ int main(int argc, char *argv[]) {
cerr << "Unsupported color\n";
return -1;
}
if(qvertex) {
if(qvertex && add_normals) {
report.Init(nexus.index.size());
cout << "Quantizing vertices\n";
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);
float *ptr = (float *)src_patch.VertBegin();
for(unsigned int i = 0; i < src_patch.nv*3; i++)
ptr[i] = qvertex * nearbyintf(ptr[i]/qvertex);
for(int i = 0; i < src_patch.nv*3; i++)
ptr[i] = qvertex * (int)(ptr[i]/qvertex);
}
report.Finish();
}

View File

@ -221,7 +221,7 @@ void PatchServer::Flush(PTime &ptime) {
if(entry.disk_size == 0xffff) {//allocate space
assert(entry.patch_start == 0xffffffff);
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);
} else {
cerr << "OOOOPSPPPS not supported!" << endl;
@ -233,7 +233,7 @@ void PatchServer::Flush(PTime &ptime) {
} else {
if(entry.disk_size == 0xffff) {
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);
}
SetPosition(entry.patch_start * chunk_size);

View File

@ -24,6 +24,9 @@
History
$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
Daily backup (fragment...)
@ -390,7 +393,7 @@ void NexusSplit(Nexus &nexus, VoronoiChain &vchain,
}
centroid /= newface.size()/3;
//prune small cells:
float min_size = (newface.size()/3) / 20;
float min_size = (newface.size()/3) / 20.0f;
vector<unsigned int> cellremap;
VoronoiPartition local;

View File

@ -24,6 +24,9 @@
History
$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
renamed
@ -58,19 +61,19 @@ void Watch::Start(void) {
elapsed = 0;
}
double Watch::Pause() {
float Watch::Pause() {
QueryPerformanceCounter(&tend);
elapsed += Diff();
return elapsed;
return (float)elapsed;
}
void Watch::Continue() {
QueryPerformanceCounter(&tstart);
}
double Watch::Time() {
float Watch::Time() {
QueryPerformanceCounter(&tend);
return elapsed + Diff();
return (float)(elapsed + Diff());
}
double Watch::Diff() {
@ -88,19 +91,19 @@ void Watch::Start() {
elapsed = 0;
}
double Watch::Pause() {
float Watch::Pause() {
gettimeofday(&tend, &tz);
elapsed += Diff();
return elapsed;
return (float)elapsed;
}
void Watch::Continue() {
gettimeofday(&tstart, &tz);
}
double Watch::Time() {
float Watch::Time() {
gettimeofday(&tend, &tz);
return elapsed + Diff();
return (float)(elapsed + Diff());
}
double Watch::Diff() {

View File

@ -24,6 +24,9 @@
History
$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
renamed
@ -53,10 +56,10 @@ class Watch {
public:
Watch();
void Start();
double Pause();
float Pause();
void Continue();
void Reset();
double Time();
float Time();
int Usec();
private:
double Diff();