vcglib/apps/nexus/nexus.h

147 lines
4.7 KiB
C++

/****************************************************************************
* 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 $
Revision 1.21 2005/02/19 10:45:04 ponchio
Patch generalized and small fixes.
Revision 1.20 2005/02/08 12:43:03 ponchio
Added copyright
****************************************************************************/
#ifndef NXS_NEXUS_H
#define NXS_NEXUS_H
#include <string>
#include <vector>
#include <list>
#include <map>
#include <vcg/space/sphere3.h>
#include "normalscone.h"
#include "patch.h"
#include "index_file.h"
#include "history.h"
#include "borderserver.h"
namespace nxs {
/* Header fo nexus:
1Kb riservato per dati globali:
Magic: 'n' 'x' 's' 0x00
Signature: unsigned int (maschera di bit)
Chunk size: unsigned int
Index offset: unsigned int (offset to the index begin,
must be a multiple of chunk size)
History offset: unsigned int: multiple of chunk_size
Tot vert: unsigned int
Tot face: unsigned int
Bound sphere: Sphere3f (4 float: Point3f center (x, y, z), (radius))
11 * 4 = 44 bytes -> 4k per alignment purpoouses and reserving space. */
struct Entry {
unsigned int patch_start; //granularita' Chunk
unsigned short ram_size; //in chunks
unsigned short disk_size; // in chunks (used when compressed)
unsigned short nvert;
unsigned short nface;
vcg::Sphere3f sphere;
float error;
NCone3s cone;
Patch *patch;
unsigned int vbo_array;
unsigned int vbo_element;
};
class Nexus: public IndexFile<Entry> {
public:
enum Version { NXS_CURRENT_VERSION = 1 };
//HEader data:
Signature signature;
unsigned int chunk_size;
//unsigned int .IndexFile::offset;
int64 history_offset;
unsigned int totvert;
unsigned int totface;
vcg::Sphere3f sphere;
History history;
BorderServer borders;
Nexus() {}
~Nexus();
bool Create(const std::string &filename, Signature &signature,
unsigned int chunk_size = 1024);
bool Load(const std::string &filename, bool readonly = false);
void Close();
void Flush(bool all = true);
unsigned int AddPatch(unsigned int nv, unsigned int nf, unsigned int nb);
Patch &GetPatch(unsigned int patch, bool flush = true);
Border &GetBorder(unsigned int patch, bool flush = true);
unsigned int &MaxRam() { return ram_max; }
// void AddBorder(unsigned int patch, Link &link);
//move to nxsalgo!
void Unify(float threshold = 0.0f);
bool IsCompressed() { return signature.compr != 0; }
bool HasStrips() { return signature.face == Signature::STRIPS; }
bool HasColors() { return signature.vcolor != 0; }
bool HasNormals() { return signature.vnorm != 0; }
bool HasTextures() { return signature.vtext != 0; }
unsigned int ram_max;
unsigned int ram_used;
protected:
std::list<unsigned int> pqueue;
std::map<unsigned int, std::list<unsigned int>::iterator> index;
Patch *LoadPatch(unsigned int id);
virtual void FlushPatch(unsigned int id);
bool LoadHeader();
void SaveHeader();
};
}
#endif