From 3ca1082ace1c19201f2c282be3468b52147e4ffd Mon Sep 17 00:00:00 2001 From: ponchio Date: Mon, 5 Jul 2004 15:49:39 +0000 Subject: [PATCH] Windows (DevCpp, mingw) port. --- apps/nexus/crude.h | 7 +- apps/nexus/crude2nexus.cpp | 11 ++- apps/nexus/crudeview.cpp | 26 ++++-- apps/nexus/mfhash.cpp | 7 +- apps/nexus/nexus.cpp | 10 +-- apps/nexus/nexus.h | 3 +- apps/nexus/nexusview.cpp | 5 +- apps/nexus/ply2crude.cpp | 7 +- apps/nexus/stopwatch.cpp | 7 +- apps/nexus/stopwatch.h | 14 +++- apps/nexus/vert_remap.cpp | 4 + apps/nexus/vfile.h | 163 +++++++++++++++++++++++++----------- apps/nexus/voronoiremap.cpp | 15 ++-- 13 files changed, 195 insertions(+), 84 deletions(-) diff --git a/apps/nexus/crude.h b/apps/nexus/crude.h index 8119459a..033f7fa5 100644 --- a/apps/nexus/crude.h +++ b/apps/nexus/crude.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.3 2004/07/04 15:25:33 ponchio +Backup (work in progress) + Revision 1.2 2004/06/25 16:47:13 ponchio Various debug @@ -86,7 +89,7 @@ public: vcg::Box3f &GetBox(); - template void Export(MESH &mesh) { + /*template void Export(MESH &mesh) { MESH::VertexType v; v.ClearFlags(); for(unsigned int i = 0; i < //DEBUG #include -#include "../nexus.h" -#include "../crude.h" -#include "../vert_remap.h" -#include "../vfile.h" +#include "nexus.h" +#include "crude.h" +#include "vert_remap.h" +#include "vfile.h" using namespace std; using namespace vcg; diff --git a/apps/nexus/crudeview.cpp b/apps/nexus/crudeview.cpp index 78834a55..379f844e 100644 --- a/apps/nexus/crudeview.cpp +++ b/apps/nexus/crudeview.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.1 2004/07/04 15:30:00 ponchio +Changed directory structure. + Revision 1.3 2004/07/02 13:03:34 ponchio *** empty log message *** @@ -41,6 +44,10 @@ using namespace std; #include +#ifdef WIN32 +#include +#endif + #include #include @@ -96,8 +103,8 @@ bool init() { -int main(int argc, char *argv[]) { - char file[64]; +int main(int argc, char *argv[]) { + if(argc < 2) { cerr << "Usage: " << argv[0] << " \n"; return -1; @@ -112,16 +119,21 @@ int main(int argc, char *argv[]) { bool vremap = false; bool fremap = false; + + VFile face_remap; + if(face_remap.Load(argv[1] + string(".rmf"))) { + cerr << "Found face remap.\n"; + fremap = true; + } else { + cerr << "Face remap not found.\n"; + } + VertRemap vert_remap; if(vert_remap.Load(argv[1])) { cerr << "Found vert remap.\n"; vremap = true; } - VFile face_remap; - if(face_remap.Load(argv[1] + string(".rmf"))) { - cerr << "Found face remap.\n"; - fremap = true; - } + if(!init()) { cerr << "Could not init SDL window\n"; diff --git a/apps/nexus/mfhash.cpp b/apps/nexus/mfhash.cpp index 13ca6370..e9d08de5 100644 --- a/apps/nexus/mfhash.cpp +++ b/apps/nexus/mfhash.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.4 2004/07/04 14:23:14 ponchio +*** empty log message *** + Revision 1.3 2004/07/02 17:40:30 ponchio Debug. @@ -39,8 +42,10 @@ Created ****************************************************************************/ -#include "mfhash.h" +#include #include +#include "mfhash.h" + using namespace std; using namespace nxs; diff --git a/apps/nexus/nexus.cpp b/apps/nexus/nexus.cpp index 000c16ec..80abd8ad 100644 --- a/apps/nexus/nexus.cpp +++ b/apps/nexus/nexus.cpp @@ -112,9 +112,9 @@ unsigned int Nexus::AddPatch(unsigned int nvert, unsigned int nface, } void Nexus::Join(std::vector &patches, - std::vector &newvert, std::vector &newface, - std::vector &newlinks) { + std::vector &newbord) { map > remap; @@ -181,7 +181,7 @@ void Nexus::Join(std::vector &patches, newbord[bcount++] = newlink; } } - unsigned int newentry = AddPatch(vcount, fcount, bcount); + /* unsigned int newentry = AddPatch(vcount, fcount, bcount); Patch newpatch = GetPatch(newentry); Border newborder = GetBorder(newentry); @@ -192,6 +192,6 @@ void Nexus::Join(std::vector &patches, newface.size() * sizeof(unsigned short)); memcpy(&(newborder[0]), &(newbord[0]), - newbord.size() * sizeof(Link)); - return newentry; + newbord.size() * sizeof(Link));*/ + return; } diff --git a/apps/nexus/nexus.h b/apps/nexus/nexus.h index 495d81c9..9109af8a 100644 --- a/apps/nexus/nexus.h +++ b/apps/nexus/nexus.h @@ -3,6 +3,7 @@ #include #include +#include #include #include "vfile.h" #include "patch.h" @@ -44,7 +45,7 @@ class Nexus { // unsigned int Join(std::vector &patches); void Join(std::vector &patches, - std::vector &vert, std::vector &faces, std::vector &links); diff --git a/apps/nexus/nexusview.cpp b/apps/nexus/nexusview.cpp index 8ebf1dbe..9a54db2b 100644 --- a/apps/nexus/nexusview.cpp +++ b/apps/nexus/nexusview.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.1 2004/07/04 15:30:00 ponchio +Changed directory structure. + Revision 1.2 2004/07/04 15:16:01 ponchio *** empty log message *** @@ -180,7 +183,7 @@ int main(int argc, char *argv[]) { - for(unsigned int i = 7; i < nexus.index.size(); i++) { + for(unsigned int i = 0; i < nexus.index.size(); i++) { Patch patch = nexus.GetPatch(i); unsigned int val = i + 1; diff --git a/apps/nexus/ply2crude.cpp b/apps/nexus/ply2crude.cpp index e7fb015d..75dea430 100644 --- a/apps/nexus/ply2crude.cpp +++ b/apps/nexus/ply2crude.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.1 2004/07/04 15:30:00 ponchio +Changed directory structure. + Revision 1.2 2004/07/02 13:09:57 ponchio *** empty log message *** @@ -38,7 +41,7 @@ Created #include #include #include -#include "../crude.h" +#include "crude.h" using namespace std; using namespace vcg; @@ -65,7 +68,7 @@ PropDescriptor plyprop2[1]= { 1,0,T_UCHAR,T_UCHAR,offsetof(PlyFace,flags) } }; -int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) { if(argc <= 2) { cerr << "Usage: " << argv[0] << " <...> \n"; return 0; diff --git a/apps/nexus/stopwatch.cpp b/apps/nexus/stopwatch.cpp index b5b0c7bf..cf0a4bfc 100644 --- a/apps/nexus/stopwatch.cpp +++ b/apps/nexus/stopwatch.cpp @@ -24,13 +24,16 @@ History $Log: not supported by cvs2svn $ +Revision 1.1 2004/07/01 21:38:30 ponchio +First draft created. + ****************************************************************************/ #include "stopwatch.h" StopWatch::StopWatch(): elapsed(0) {} -#ifdef _WIN32 +#ifdef WIN32 void StopWatch::Start(void) { static int first = 1; if(first) { @@ -78,7 +81,7 @@ double StopWatch::Elapsed() { } int StopWatch::Usec() { -#ifdef _WIN32 +#ifdef WIN32 return 0; #else struct timeval ttime; diff --git a/apps/nexus/stopwatch.h b/apps/nexus/stopwatch.h index 685cc7b6..d68688b0 100644 --- a/apps/nexus/stopwatch.h +++ b/apps/nexus/stopwatch.h @@ -24,10 +24,18 @@ History $Log: not supported by cvs2svn $ +Revision 1.1 2004/07/01 21:38:30 ponchio +First draft created. + ****************************************************************************/ + +#ifdef WIN32 +#include +#else #include #include +#endif class StopWatch { public: @@ -40,9 +48,9 @@ public: private: double Diff(); -#ifdef _WIN32 - static LARGE_INTEGER _tstart, _tend; - static LARGE_INTEGER freq; +#ifdef WIN32 + LARGE_INTEGER tstart, tend; + LARGE_INTEGER freq; #else struct timeval tstart, tend; struct timezone tz; diff --git a/apps/nexus/vert_remap.cpp b/apps/nexus/vert_remap.cpp index 1375986c..60512152 100644 --- a/apps/nexus/vert_remap.cpp +++ b/apps/nexus/vert_remap.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.4 2004/07/02 17:41:37 ponchio +Debug. + Revision 1.3 2004/07/02 13:01:28 ponchio Changed file extensions to .rmv, .rmb @@ -39,6 +42,7 @@ Created ****************************************************************************/ +#include #include #include "vert_remap.h" diff --git a/apps/nexus/vfile.h b/apps/nexus/vfile.h index 77124c80..800118ae 100644 --- a/apps/nexus/vfile.h +++ b/apps/nexus/vfile.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.6 2004/07/04 15:23:48 ponchio +Debug + Revision 1.5 2004/07/02 17:41:37 ponchio Debug. @@ -54,7 +57,12 @@ Created #ifndef VFILE_H #define VFILE_H +#ifndef WIN32 #include +#else +#include +#endif + #include //#include #include @@ -80,8 +88,12 @@ template class VFile { }; private: - +#ifdef WIN32 + HANDLE fp; +#else FILE *fp; +#endif + std::list buffers; typedef typename std::list::iterator list_iterator; @@ -114,8 +126,15 @@ template class VFile { queue_size = _queue_size; n_elements = 0; +#ifdef WIN32 + fp = CreateFile(filename.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, + 0, NULL); + if(fp == INVALID_HANDLE_VALUE) return false; +#else fp = fopen(filename.c_str(), "wb+"); if(!fp) return false; +#endif + return true; } @@ -127,19 +146,33 @@ template class VFile { assert(_chunk_size > 0); chunk_size = _chunk_size; queue_size = _queue_size; - +#ifdef WIN32 + fp = CreateFile(filename.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, + 0, NULL); + if(fp == INVALID_HANDLE_VALUE) return false; +#else fp = fopen(filename.c_str(), "rb+"); if(!fp) return false; +#endif + +#ifdef WIN32 + n_elements = GetFileSize(fp, NULL)/ sizeof(T); +#else fseek(fp, 0, SEEK_END); n_elements = ftell(fp)/ sizeof(T); +#endif return true; } void Close() { if(fp) { Flush(); +#ifdef WIN32 + CloseHandle(fp); +#else fclose(fp); +#endif fp = NULL; } } @@ -153,10 +186,19 @@ template class VFile { } void FlushBuffer(Buffer buffer) { + SetPosition(buffer.key); + WriteBuffer(buffer.data, buffer.size); +/*#ifdef WIN32 + SetFilePointer(fp, buffer.key * chunk_size * sizeof(T), FILE_BEGIN); + unsigned int tmp; + WriteFile(fp, buffer.data, sizeof(T) * buffer.size, &tmp, NULL); + if(tmp != sizeof(T) * buffer.size) + assert(0 && "Could not write"); +#else fseek(fp, buffer.key * chunk_size * sizeof(T), SEEK_SET); - if(buffer.size != fwrite(buffer.data, sizeof(T), buffer.size, fp)) { - assert(0 && "Could not write"); - } + if(buffer.size != fwrite(buffer.data, sizeof(T), buffer.size, fp)) + assert(0 && "Could not write"); +#endif*/ delete []buffer.data; } @@ -164,15 +206,30 @@ template class VFile { assert(fp); Flush(); if(elem > n_elements) { - if(-1 == fseek(fp, elem*sizeof(T) -1, SEEK_SET)) { - assert(0 && "Could not resize"); - } +#ifdef WIN32 + if(INVALID_SET_FILE_POINTER == SetFilePointer(fp, elem*sizeof(T)-1, 0, FILE_BEGIN)) +#else + if(-1 == fseek(fp, elem*sizeof(T) -1, SEEK_SET)) +#endif + assert(0 && "Could not resize"); + unsigned char a; +#ifdef WIN32 + DWORD tmp; + WriteFile(fp, &a, 1, &tmp, NULL); +#else fwrite(&a, sizeof(unsigned char), 1, fp); +#endif } else { //TODO optimize: we do not need flush for buffers over elem. + +#ifndef WIN32 int fd = fileno(fp); ftruncate(fd, elem*sizeof(T)); +#else + SetFilePointer(fp, elem*sizeof(T), 0, FILE_BEGIN); + SetEndOfFile(fp); +#endif } n_elements = elem; } @@ -208,20 +265,33 @@ template class VFile { buffers.push_front(buffer); index[buffer.key] = buffers.begin(); - + SetPosition(chunk); + ReadBuffer(buffer.data, buffer.size); +/*#ifdef WIN32 + if(INVALID_SET_FILE_POINTER == SetFilePointer(fp, chunk * chunk_size * sizeof(T), 0, FILE_BEGIN)) { +#else if(fseek(fp, chunk * chunk_size * sizeof(T), SEEK_SET)) { +#endif assert(0 && "failed to fseek"); return *(buffer.data); } - +#ifdef WIN32 + unsigned int tmp; + tmp = ReadFile(fp, buffer.data, sizeof(T) * buffer.size, &tmp, NULL); + if(tmp != sizeof(T) * buffer.size) + assert(0 && "failed reading."); + return (*buffer.data); +#else if(buffer.size != fread(buffer.data, sizeof(T), buffer.size, fp)) { if(feof(fp)) { - assert(0 && "end of file"); + assert(0 && "end of file"); } else { - assert(0 && "failed reading!"); + assert(0 && "failed reading!"); } return (*buffer.data); } +#endif + */ return *(buffer.data + offset); } @@ -262,7 +332,9 @@ template class VFile { buffers.push_front(buffer); index[chunk] = buffers.begin(); - if(fseek(fp, chunk * chunk_size * sizeof(T), SEEK_SET)) { + SetPosition(chunk); + ReadBuffer(buffer.data, buffer.size); + /*if(fseek(fp, chunk * chunk_size * sizeof(T), SEEK_SET)) { assert(0 && "failed to fseek"); return buffer.data; } @@ -274,44 +346,9 @@ template class VFile { assert(0 && "failed reading!"); } return buffer.data; - } + } */ return buffer.data; - } - - /** Allocate copy and return (remember to delete it) memory. - size is number of elements. **/ - T *Read(unsigned int begin, unsigned int size) { - //to make its simple we flush and read. - Flush(); - T *buf = new T[size]; - if(fseek(fp, begin * sizeof(T), SEEK_SET)) { - assert(0 && "failed to fseek"); - return buf; - } - if(size != fread(buf, sizeof(T), size, fp)) { - if(feof(fp)) { - assert(0 && "end of file"); - } else { - assert(0 && "failed reading!"); - } - } - return buf; - } - - void Write(T *buf, unsigned int begin, unsigned int size) { - //to make its simple we flush and read. - Flush(); - if(fseek(fp, begin * sizeof(T), SEEK_SET)) { - assert(0 && "failed to fseek"); - } - if(size != fwrite(buf, sizeof(T), size, fp)) { - if(feof(fp)) { - assert(0 && "end of file"); - } else { - assert(0 && "failed reading!"); - } - } - } + } unsigned int Size() { return n_elements; } unsigned int ChunkSize() { return chunk_size; } @@ -321,7 +358,33 @@ template class VFile { protected: void SetPosition(unsigned int chunk) { +#ifdef WIN32 + SetFilePointer(fp, chunk * chunk_size * sizeof(T), 0, FILE_BEGIN); +#else fseek(fp, chunk * chunk_size * sizeof(T), SEEK_SET); +#endif + } + void ReadBuffer(T *data, unsigned int size) { +#ifdef WIN32 + DWORD tmp; + ReadFile(fp, data, sizeof(T) * size, &tmp, NULL); + if(tmp != sizeof(T) * size) + assert(0 && "Could not read"); +#else + if(size != fread(data, sizeof(T), size, fp)) + assert(0 && "Could not read"); +#endif + } + void WriteBuffer(T *data, unsigned int size) { +#ifdef WIN32 + DWORD tmp; + WriteFile(fp, data, sizeof(T) * size, &tmp, NULL); + if(tmp != sizeof(T) * size) + assert(0 && "Could not write"); +#else + if(size != fwrite(data, sizeof(T), size, fp)) + assert(0 && "Could not write"); +#endif } }; diff --git a/apps/nexus/voronoiremap.cpp b/apps/nexus/voronoiremap.cpp index d4c5cd73..d6db50e7 100644 --- a/apps/nexus/voronoiremap.cpp +++ b/apps/nexus/voronoiremap.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.1 2004/07/04 15:30:00 ponchio +Changed directory structure. + Revision 1.3 2004/07/02 17:42:43 ponchio Debug. @@ -37,12 +40,12 @@ Created ****************************************************************************/ #include -#include "../pchain.h" -#include "../pvoronoi.h" -#include "../vert_remap.h" -#include "../crude.h" -#include "../stopwatch.h" -#include "../pintersect.h" +#include "pchain.h" +#include "pvoronoi.h" +#include "vert_remap.h" +#include "crude.h" +#include "stopwatch.h" +#include "pintersect.h" using namespace std; using namespace nxs;