Windows (DevCpp, mingw) port.

This commit is contained in:
Federico Ponchio 2004-07-05 15:49:39 +00:00
parent e7e9d70390
commit 3ca1082ace
13 changed files with 195 additions and 84 deletions

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $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 Revision 1.2 2004/06/25 16:47:13 ponchio
Various debug Various debug
@ -86,7 +89,7 @@ public:
vcg::Box3f &GetBox(); vcg::Box3f &GetBox();
template <class MESH> void Export(MESH &mesh) { /*template <class MESH> void Export(MESH &mesh) {
MESH::VertexType v; MESH::VertexType v;
v.ClearFlags(); v.ClearFlags();
for(unsigned int i = 0; i < <Vertices(); i++) { for(unsigned int i = 0; i < <Vertices(); i++) {
@ -102,7 +105,7 @@ public:
mesh.vert.push_back(GetVertex(i)); mesh.vert.push_back(GetVertex(i));
} }
} }
} }*/
protected: protected:

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.1 2004/07/04 15:30:00 ponchio
Changed directory structure.
Revision 1.3 2004/07/04 14:28:05 ponchio Revision 1.3 2004/07/04 14:28:05 ponchio
Finito e debuggato Finito e debuggato
@ -40,10 +43,10 @@ Created
#include <set> //DEBUG #include <set> //DEBUG
#include <map> #include <map>
#include "../nexus.h" #include "nexus.h"
#include "../crude.h" #include "crude.h"
#include "../vert_remap.h" #include "vert_remap.h"
#include "../vfile.h" #include "vfile.h"
using namespace std; using namespace std;
using namespace vcg; using namespace vcg;

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $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 Revision 1.3 2004/07/02 13:03:34 ponchio
*** empty log message *** *** empty log message ***
@ -41,6 +44,10 @@ using namespace std;
#include <SDL/SDL.h> #include <SDL/SDL.h>
#ifdef WIN32
#include <windows.h>
#endif
#include <GL/gl.h> #include <GL/gl.h>
#include <GL/glu.h> #include <GL/glu.h>
@ -96,8 +103,8 @@ bool init() {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
char file[64];
if(argc < 2) { if(argc < 2) {
cerr << "Usage: " << argv[0] << " <crude file>\n"; cerr << "Usage: " << argv[0] << " <crude file>\n";
return -1; return -1;
@ -112,16 +119,21 @@ int main(int argc, char *argv[]) {
bool vremap = false; bool vremap = false;
bool fremap = false; bool fremap = false;
VFile<unsigned int> 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; VertRemap vert_remap;
if(vert_remap.Load(argv[1])) { if(vert_remap.Load(argv[1])) {
cerr << "Found vert remap.\n"; cerr << "Found vert remap.\n";
vremap = true; vremap = true;
} }
VFile<unsigned int> face_remap;
if(face_remap.Load(argv[1] + string(".rmf"))) {
cerr << "Found face remap.\n";
fremap = true;
}
if(!init()) { if(!init()) {
cerr << "Could not init SDL window\n"; cerr << "Could not init SDL window\n";

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $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 Revision 1.3 2004/07/02 17:40:30 ponchio
Debug. Debug.
@ -39,8 +42,10 @@ Created
****************************************************************************/ ****************************************************************************/
#include "mfhash.h" #include <assert.h>
#include <iostream> #include <iostream>
#include "mfhash.h"
using namespace std; using namespace std;
using namespace nxs; using namespace nxs;

View File

@ -112,9 +112,9 @@ unsigned int Nexus::AddPatch(unsigned int nvert, unsigned int nface,
} }
void Nexus::Join(std::vector<unsigned int> &patches, void Nexus::Join(std::vector<unsigned int> &patches,
std::vector<Point3f &newvert, std::vector<Point3f> &newvert,
std::vector<unsigned int> &newface, std::vector<unsigned int> &newface,
std::vector<Link> &newlinks) { std::vector<Link> &newbord) {
map<unsigned int, vector<unsigned int> > remap; map<unsigned int, vector<unsigned int> > remap;
@ -181,7 +181,7 @@ void Nexus::Join(std::vector<unsigned int> &patches,
newbord[bcount++] = newlink; newbord[bcount++] = newlink;
} }
} }
unsigned int newentry = AddPatch(vcount, fcount, bcount); /* unsigned int newentry = AddPatch(vcount, fcount, bcount);
Patch newpatch = GetPatch(newentry); Patch newpatch = GetPatch(newentry);
Border newborder = GetBorder(newentry); Border newborder = GetBorder(newentry);
@ -192,6 +192,6 @@ void Nexus::Join(std::vector<unsigned int> &patches,
newface.size() * sizeof(unsigned short)); newface.size() * sizeof(unsigned short));
memcpy(&(newborder[0]), &(newbord[0]), memcpy(&(newborder[0]), &(newbord[0]),
newbord.size() * sizeof(Link)); newbord.size() * sizeof(Link));*/
return newentry; return;
} }

View File

@ -3,6 +3,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <vcg/space/point3.h>
#include <vcg/space/sphere3.h> #include <vcg/space/sphere3.h>
#include "vfile.h" #include "vfile.h"
#include "patch.h" #include "patch.h"
@ -44,7 +45,7 @@ class Nexus {
// unsigned int Join(std::vector<unsigned int> &patches); // unsigned int Join(std::vector<unsigned int> &patches);
void Join(std::vector<unsigned int> &patches, void Join(std::vector<unsigned int> &patches,
std::vector<Point3f &vert, std::vector<vcg::Point3f> &vert,
std::vector<unsigned int> &faces, std::vector<unsigned int> &faces,
std::vector<Link> &links); std::vector<Link> &links);

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $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 Revision 1.2 2004/07/04 15:16:01 ponchio
*** empty log message *** *** 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); Patch patch = nexus.GetPatch(i);
unsigned int val = i + 1; unsigned int val = i + 1;

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $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 Revision 1.2 2004/07/02 13:09:57 ponchio
*** empty log message *** *** empty log message ***
@ -38,7 +41,7 @@ Created
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <wrap/ply/plylib.h> #include <wrap/ply/plylib.h>
#include "../crude.h" #include "crude.h"
using namespace std; using namespace std;
using namespace vcg; using namespace vcg;
@ -65,7 +68,7 @@ PropDescriptor plyprop2[1]= {
1,0,T_UCHAR,T_UCHAR,offsetof(PlyFace,flags) } 1,0,T_UCHAR,T_UCHAR,offsetof(PlyFace,flags) }
}; };
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
if(argc <= 2) { if(argc <= 2) {
cerr << "Usage: " << argv[0] << " <input1.ply> <...> <inputN.ply> <output>\n"; cerr << "Usage: " << argv[0] << " <input1.ply> <...> <inputN.ply> <output>\n";
return 0; return 0;

View File

@ -24,13 +24,16 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.1 2004/07/01 21:38:30 ponchio
First draft created.
****************************************************************************/ ****************************************************************************/
#include "stopwatch.h" #include "stopwatch.h"
StopWatch::StopWatch(): elapsed(0) {} StopWatch::StopWatch(): elapsed(0) {}
#ifdef _WIN32 #ifdef WIN32
void StopWatch::Start(void) { void StopWatch::Start(void) {
static int first = 1; static int first = 1;
if(first) { if(first) {
@ -78,7 +81,7 @@ double StopWatch::Elapsed() {
} }
int StopWatch::Usec() { int StopWatch::Usec() {
#ifdef _WIN32 #ifdef WIN32
return 0; return 0;
#else #else
struct timeval ttime; struct timeval ttime;

View File

@ -24,10 +24,18 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.1 2004/07/01 21:38:30 ponchio
First draft created.
****************************************************************************/ ****************************************************************************/
#ifdef WIN32
#include <windows.h>
#else
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#endif
class StopWatch { class StopWatch {
public: public:
@ -40,9 +48,9 @@ public:
private: private:
double Diff(); double Diff();
#ifdef _WIN32 #ifdef WIN32
static LARGE_INTEGER _tstart, _tend; LARGE_INTEGER tstart, tend;
static LARGE_INTEGER freq; LARGE_INTEGER freq;
#else #else
struct timeval tstart, tend; struct timeval tstart, tend;
struct timezone tz; struct timezone tz;

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $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 Revision 1.3 2004/07/02 13:01:28 ponchio
Changed file extensions to .rmv, .rmb Changed file extensions to .rmv, .rmb
@ -39,6 +42,7 @@ Created
****************************************************************************/ ****************************************************************************/
#include <assert.h>
#include <iostream> #include <iostream>
#include "vert_remap.h" #include "vert_remap.h"

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $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 Revision 1.5 2004/07/02 17:41:37 ponchio
Debug. Debug.
@ -54,7 +57,12 @@ Created
#ifndef VFILE_H #ifndef VFILE_H
#define VFILE_H #define VFILE_H
#ifndef WIN32
#include <unistd.h> #include <unistd.h>
#else
#include <windows.h>
#endif
#include <errno.h> #include <errno.h>
//#include <hash_map> //#include <hash_map>
#include <map> #include <map>
@ -80,8 +88,12 @@ template <class T> class VFile {
}; };
private: private:
#ifdef WIN32
HANDLE fp;
#else
FILE *fp; FILE *fp;
#endif
std::list<Buffer> buffers; std::list<Buffer> buffers;
typedef typename std::list<Buffer>::iterator list_iterator; typedef typename std::list<Buffer>::iterator list_iterator;
@ -114,8 +126,15 @@ template <class T> class VFile {
queue_size = _queue_size; queue_size = _queue_size;
n_elements = 0; 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+"); fp = fopen(filename.c_str(), "wb+");
if(!fp) return false; if(!fp) return false;
#endif
return true; return true;
} }
@ -127,19 +146,33 @@ template <class T> class VFile {
assert(_chunk_size > 0); assert(_chunk_size > 0);
chunk_size = _chunk_size; chunk_size = _chunk_size;
queue_size = _queue_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+"); fp = fopen(filename.c_str(), "rb+");
if(!fp) return false; if(!fp) return false;
#endif
#ifdef WIN32
n_elements = GetFileSize(fp, NULL)/ sizeof(T);
#else
fseek(fp, 0, SEEK_END); fseek(fp, 0, SEEK_END);
n_elements = ftell(fp)/ sizeof(T); n_elements = ftell(fp)/ sizeof(T);
#endif
return true; return true;
} }
void Close() { void Close() {
if(fp) { if(fp) {
Flush(); Flush();
#ifdef WIN32
CloseHandle(fp);
#else
fclose(fp); fclose(fp);
#endif
fp = NULL; fp = NULL;
} }
} }
@ -153,10 +186,19 @@ template <class T> class VFile {
} }
void FlushBuffer(Buffer buffer) { 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); fseek(fp, buffer.key * chunk_size * sizeof(T), SEEK_SET);
if(buffer.size != fwrite(buffer.data, sizeof(T), buffer.size, fp)) { if(buffer.size != fwrite(buffer.data, sizeof(T), buffer.size, fp))
assert(0 && "Could not write"); assert(0 && "Could not write");
} #endif*/
delete []buffer.data; delete []buffer.data;
} }
@ -164,15 +206,30 @@ template <class T> class VFile {
assert(fp); assert(fp);
Flush(); Flush();
if(elem > n_elements) { if(elem > n_elements) {
if(-1 == fseek(fp, elem*sizeof(T) -1, SEEK_SET)) { #ifdef WIN32
assert(0 && "Could not resize"); 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; unsigned char a;
#ifdef WIN32
DWORD tmp;
WriteFile(fp, &a, 1, &tmp, NULL);
#else
fwrite(&a, sizeof(unsigned char), 1, fp); fwrite(&a, sizeof(unsigned char), 1, fp);
#endif
} else { } else {
//TODO optimize: we do not need flush for buffers over elem. //TODO optimize: we do not need flush for buffers over elem.
#ifndef WIN32
int fd = fileno(fp); int fd = fileno(fp);
ftruncate(fd, elem*sizeof(T)); ftruncate(fd, elem*sizeof(T));
#else
SetFilePointer(fp, elem*sizeof(T), 0, FILE_BEGIN);
SetEndOfFile(fp);
#endif
} }
n_elements = elem; n_elements = elem;
} }
@ -208,20 +265,33 @@ template <class T> class VFile {
buffers.push_front(buffer); buffers.push_front(buffer);
index[buffer.key] = buffers.begin(); 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)) { if(fseek(fp, chunk * chunk_size * sizeof(T), SEEK_SET)) {
#endif
assert(0 && "failed to fseek"); assert(0 && "failed to fseek");
return *(buffer.data); 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(buffer.size != fread(buffer.data, sizeof(T), buffer.size, fp)) {
if(feof(fp)) { if(feof(fp)) {
assert(0 && "end of file"); assert(0 && "end of file");
} else { } else {
assert(0 && "failed reading!"); assert(0 && "failed reading!");
} }
return (*buffer.data); return (*buffer.data);
} }
#endif
*/
return *(buffer.data + offset); return *(buffer.data + offset);
} }
@ -262,7 +332,9 @@ template <class T> class VFile {
buffers.push_front(buffer); buffers.push_front(buffer);
index[chunk] = buffers.begin(); 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"); assert(0 && "failed to fseek");
return buffer.data; return buffer.data;
} }
@ -274,44 +346,9 @@ template <class T> class VFile {
assert(0 && "failed reading!"); assert(0 && "failed reading!");
} }
return buffer.data; return buffer.data;
} } */
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 Size() { return n_elements; }
unsigned int ChunkSize() { return chunk_size; } unsigned int ChunkSize() { return chunk_size; }
@ -321,7 +358,33 @@ template <class T> class VFile {
protected: protected:
void SetPosition(unsigned int chunk) { 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); 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
} }
}; };

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $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 Revision 1.3 2004/07/02 17:42:43 ponchio
Debug. Debug.
@ -37,12 +40,12 @@ Created
****************************************************************************/ ****************************************************************************/
#include <iostream> #include <iostream>
#include "../pchain.h" #include "pchain.h"
#include "../pvoronoi.h" #include "pvoronoi.h"
#include "../vert_remap.h" #include "vert_remap.h"
#include "../crude.h" #include "crude.h"
#include "../stopwatch.h" #include "stopwatch.h"
#include "../pintersect.h" #include "pintersect.h"
using namespace std; using namespace std;
using namespace nxs; using namespace nxs;