From f33b962262eaaf5f68270cc8caba29d72fc5342d Mon Sep 17 00:00:00 2001 From: ponchio Date: Tue, 22 Jun 2004 15:31:54 +0000 Subject: [PATCH] Created --- wrap/nexus/crude.cpp | 120 +++++++++++++++++++++++++++++++++++++++++++ wrap/nexus/crude.h | 89 ++++++++++++++++++++++++++++++++ 2 files changed, 209 insertions(+) create mode 100644 wrap/nexus/crude.cpp create mode 100644 wrap/nexus/crude.h diff --git a/wrap/nexus/crude.cpp b/wrap/nexus/crude.cpp new file mode 100644 index 00000000..b078b1bc --- /dev/null +++ b/wrap/nexus/crude.cpp @@ -0,0 +1,120 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/**************************************************************************** + History + +$Log: not supported by cvs2svn $ + +****************************************************************************/ + +#include "crude.h" + +using namespace std; +using namespace vcg; +using namespace nxs; + + +Crude::~Crude() { + if(fp) + Close(); +} + +bool Crude::Create(const std::string &file, unsigned int nv, unsigned int nf) { + if(!vert.Create(file + ".vrt")) return false; + if(!face.Create(file + ".frt")) return false; + + fp = fopen(file.c_str(), "wb+"); + if(!fp) return false; + Resize(nv, nf); + return true; +} +bool Crude::Load(const std::string &file) { + if(!vert.Load(file + ".vrt")) return false; + if(!face.Load(file + ".frt")) return false; + + fp = fopen(file.c_str(), "rb+"); + if(!fp) return false; + fread(&nvert, sizeof(unsigned int), 1, fp); + fread(&nface, sizeof(unsigned int), 1, fp); + fread(&box, sizeof(Box3f), 1, fp); + return true; +} +void Crude::Close() { + vert.Close(); + face.Close(); + rewind(fp); + fwrite(&nvert, sizeof(unsigned int), 1, fp); + fwrite(&nface, sizeof(unsigned int), 1, fp); + fwrite(&box, sizeof(Box3f), 1, fp); + fclose(fp); + fp = NULL; +} + +void Crude::Resize(unsigned int nv, unsigned int nf) { + nvert = nv; + nface = nf; + vert.Resize(nv); + face.Resize(nf); +} + +unsigned int Crude::Vertices() { + return nvert; +} +unsigned int Crude::Faces() { + return nface; +} + +void Crude::SetVertex(unsigned int i, float *f) { + Point3f &p = vert[i]; + p[0] = f[0]; + p[1] = f[1]; + p[2] = f[2]; +} + +Point3f &Crude::GetVertex(unsigned int i) { + return vert[i]; +} +Crude::Face &Crude::GetFace(unsigned int i) { + return face[i]; +} + void Crude::SetFace(unsigned int i, unsigned int *f) { + Face &ff = face[i]; + ff[0] = f[0]; + ff[1] = f[1]; + ff[2] = f[2]; + } + +vcg::Point3f Crude::GetBari(unsigned int i) { + Point3f bari(0, 0, 0); + Face &f = face[i]; + for(int k = 0; k < 3; k++) + bari += vert[f[k]]; + bari /= 3; + return bari; +} + +vcg::Box3f &Crude::GetBox() { + return box; +} + + diff --git a/wrap/nexus/crude.h b/wrap/nexus/crude.h new file mode 100644 index 00000000..80b1d47a --- /dev/null +++ b/wrap/nexus/crude.h @@ -0,0 +1,89 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/**************************************************************************** + History + +$Log: not supported by cvs2svn $ + +****************************************************************************/ + +#ifndef NXS_CRUDE_H +#define NXS_CRUDE_H + +#include +#include +#include +#include + +#include "vfile.h" + +namespace nxs { + +class Crude { +public: + + struct Face { + Face() {} + Face(unsigned int a, unsigned int b, unsigned int c) { + v[0] = a; v[1] = b; v[2] = c; + } + unsigned int v[3]; + unsigned int &operator[](int k) { return v[k]; } + unsigned int *ptr() { return v; } + }; + + Crude(): fp(NULL), nvert(0), nface(0) {} + ~Crude(); + + bool Create(const std::string &file, unsigned int nvert = 0, + unsigned int nface = 0); + bool Load(const std::string &file); + void Close(); + void Resize(unsigned int nvert, unsigned int nface); + + unsigned int Vertices(); + unsigned int Faces(); + + vcg::Point3f &GetVertex(unsigned int i); + void SetVertex(unsigned int i, float *p); + + Face &GetFace(unsigned int i); + void SetFace(unsigned int i, unsigned int *f); + + vcg::Point3f GetBari(unsigned int i); + + vcg::Box3f &GetBox(); + + protected: + VFile vert; + VFile face; + + FILE *fp; + unsigned int nvert; + unsigned int nface; + vcg::Box3f box; +}; + +} //namespace + +#endif