2004-07-02 15:00:02 +02:00
|
|
|
#ifndef NXS_PATCH_H
|
|
|
|
#define NXS_PATCH_H
|
|
|
|
|
|
|
|
#include <vcg/space/point3.h>
|
2004-07-02 19:42:43 +02:00
|
|
|
#include <iostream>
|
2004-07-02 15:00:02 +02:00
|
|
|
namespace nxs {
|
|
|
|
|
|
|
|
struct Chunk {
|
|
|
|
unsigned char p[4096];
|
|
|
|
};
|
|
|
|
|
|
|
|
class Patch {
|
|
|
|
public:
|
|
|
|
|
|
|
|
Patch(Chunk *s = NULL): start(s) {}
|
|
|
|
|
|
|
|
unsigned short &VertSize() { return *(unsigned short *)start; }
|
|
|
|
|
|
|
|
vcg::Point3f *VertBegin() {
|
2004-07-02 19:42:43 +02:00
|
|
|
return (vcg::Point3f *)(((char *)start) + 2*sizeof(short)); }
|
2004-07-02 15:00:02 +02:00
|
|
|
|
|
|
|
unsigned short &FaceSize() { return *(((unsigned short *)start) + 1); }
|
|
|
|
|
|
|
|
unsigned short *FaceBegin() {
|
2004-07-02 19:42:43 +02:00
|
|
|
return (unsigned short *)(((char *)start) + 2*sizeof(short) +
|
2004-07-02 15:00:02 +02:00
|
|
|
VertSize() * sizeof(vcg::Point3f)); }
|
|
|
|
|
2004-07-02 19:42:43 +02:00
|
|
|
vcg::Point3f &Vert(unsigned int v) {
|
|
|
|
return VertBegin()[v];
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned short *Face(unsigned int f) {
|
|
|
|
return FaceBegin() + f * 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-02 15:00:02 +02:00
|
|
|
unsigned int ChunkSize() {
|
|
|
|
return ChunkSize(VertSize(), FaceSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int ByteSize() {
|
|
|
|
return ByteSize(VertSize(), FaceSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int ChunkSize(unsigned short nvert, unsigned short nface) {
|
|
|
|
unsigned int size = ByteSize(nvert, nface);
|
|
|
|
size = (size/sizeof(Chunk) + 1);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int ByteSize(unsigned short nvert, unsigned short nface) {
|
|
|
|
unsigned int size = nvert * sizeof(vcg::Point3f);
|
|
|
|
size += nface * 3 * sizeof(unsigned short);
|
|
|
|
|
|
|
|
//this condition should really rarely happen but helps save space
|
|
|
|
//during construction
|
|
|
|
if(size < nface * 3 * sizeof(unsigned int))
|
|
|
|
size = nface * 3 * sizeof(unsigned int);
|
|
|
|
|
2004-07-02 19:42:43 +02:00
|
|
|
size += 2 * sizeof(unsigned short);
|
2004-07-02 15:00:02 +02:00
|
|
|
return size;
|
|
|
|
}
|
2004-07-02 19:42:43 +02:00
|
|
|
// private:
|
2004-07-02 15:00:02 +02:00
|
|
|
Chunk *start;
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|