vcglib/apps/nexus/nexus.h

137 lines
4.5 KiB
C
Raw Normal View History

2005-02-08 13:43:03 +01:00
/****************************************************************************
* 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 $
****************************************************************************/
2004-07-02 15:00:02 +02:00
#ifndef NXS_NEXUS_H
#define NXS_NEXUS_H
#include <string>
#include <vector>
2005-01-14 16:25:29 +01:00
#include <list>
#include <map>
2004-10-08 16:46:26 +02:00
2005-01-14 16:25:29 +01:00
#include <vcg/space/sphere3.h>
#include "patch.h"
#include "index_file.h"
#include "history.h"
2004-10-08 16:46:26 +02:00
#include "borderserver.h"
2004-07-02 15:00:02 +02:00
namespace nxs {
2005-01-14 16:25:29 +01:00
/* 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;
Patch *patch;
unsigned int vbo_array;
unsigned int vbo_element;
};
class Nexus: public IndexFile<Entry> {
2004-07-02 15:00:02 +02:00
public:
2005-01-14 16:25:29 +01:00
//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;
2004-07-02 15:00:02 +02:00
2004-12-13 01:44:48 +01:00
Nexus() {}
~Nexus();
2004-10-08 16:46:26 +02:00
2004-10-10 19:19:42 +02:00
bool Create(const std::string &filename, Signature signature,
unsigned int chunk_size = 1024);
2004-12-13 01:44:48 +01:00
bool Load(const std::string &filename, bool readonly = false);
void Close();
2005-01-14 16:25:29 +01:00
void Flush(bool all = true);
2004-10-08 16:46:26 +02:00
unsigned int AddPatch(unsigned int nv, unsigned int nf, unsigned int nb);
Patch &GetPatch(unsigned int patch, bool flush = true);
2005-01-21 18:09:13 +01:00
Border &GetBorder(unsigned int patch, bool flush = true);
2004-07-04 16:26:46 +02:00
2005-01-14 16:25:29 +01:00
unsigned int &MaxRam() { return ram_max; }
// void AddBorder(unsigned int patch, Link &link);
//move to nxsalgo!
void Unify(float threshold = 0.0f);
2004-11-18 19:30:15 +01:00
2004-10-09 16:46:47 +02:00
bool IsCompressed() { return (signature & NXS_COMPRESSED) != 0; }
bool HasStrips() { return (signature & NXS_STRIP) != 0; }
bool HasColors() { return (signature & NXS_COLORS) != 0; }
bool HasNormalsShort() { return (signature & NXS_NORMALS_SHORT) != 0; }
bool HasNormalsFloat() { return (signature & NXS_NORMALS_FLOAT) != 0; }
2004-10-15 18:45:27 +02:00
2005-01-14 16:25:29 +01:00
unsigned int ram_max;
unsigned int ram_used;
protected:
2004-10-08 16:46:26 +02:00
2005-01-14 16:25:29 +01:00
std::list<unsigned int> pqueue;
std::map<unsigned int, std::list<unsigned int>::iterator> index;
2004-10-08 16:46:26 +02:00
2005-01-14 16:25:29 +01:00
Patch *LoadPatch(unsigned int id);
virtual void FlushPatch(unsigned int id);
2004-10-08 16:46:26 +02:00
2005-01-14 16:25:29 +01:00
bool LoadHeader();
void SaveHeader();
2004-07-02 15:00:02 +02:00
};
}
#endif