vcglib/apps/nexus/patch.h

170 lines
5.2 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 $
2005-02-22 11:38:17 +01:00
Revision 1.13 2005/02/19 12:06:55 ponchio
Debug...
2005-02-19 13:06:55 +01:00
Revision 1.12 2005/02/19 10:45:05 ponchio
Patch generalized and small fixes.
2005-02-19 11:45:05 +01:00
Revision 1.11 2005/02/08 12:43:03 ponchio
Added copyright
2005-02-08 13:43:03 +01:00
****************************************************************************/
2004-07-02 15:00:02 +02:00
#ifndef NXS_PATCH_H
#define NXS_PATCH_H
#include <vcg/space/point3.h>
2004-10-08 17:12:04 +02:00
#include <vcg/space/sphere3.h>
2004-07-02 15:00:02 +02:00
namespace nxs {
2005-02-19 11:45:05 +01:00
struct Signature {
enum Face { TRIANGLES = 1, STRIPS = 2, TETRAS = 3, SLICE = 4 };
enum Vert { POINT2F = 1, POINT2D = 2,
POINT3F = 2, POINT3D = 3,
POINT4F = 4, POINT4D = 5 };
enum Compr { LZO = 1 };
unsigned char face;
unsigned char vert;
unsigned char compr;
unsigned char future; //who knows...
unsigned char fcolor;
unsigned char fnorm;
unsigned char ftext;
unsigned char fdata;
unsigned char vcolor;
unsigned char vnorm;
unsigned char vtext;
unsigned char vdata;
Signature(): face(1), vert(2), compr(0), future(0),
fcolor(0), fnorm(0), ftext(0), fdata(0),
vcolor(0), vnorm(0), vtext(0), vdata(0) {}
};
struct Encoding {
unsigned char bytes; //size per element
unsigned char comps; //number of components
void (*pack)(char *start, unsigned int nelem);
void (*unpack)(char *start, unsigned int nelem);
unsigned int size(unsigned short n) {
unsigned int s = (int)n * (int)bytes * (int)comps;
2005-02-22 11:38:17 +01:00
//padding a 8 bytes
if((s & 0x0000007) != 0) {
s>>=3; s++; s<<=3;
2005-02-19 11:45:05 +01:00
}
return s;
}
};
struct Encodings {
enum Name { EMPTY = 0,
BYTE1 = 1, SHORT1 = 2, FLOAT1 = 3, DOUBLE1 = 4,
BYTE2 = 5, SHORT2 = 6, FLOAT2 = 7, DOUBLE2 = 8,
BYTE3 = 9, SHORT3 = 10, FLOAT3 = 11, DOUBLE3 = 12,
BYTE4 = 13, SHORT4 = 14, FLOAT4 = 15, DOUBLE4 = 16 };
Encodings();
Encoding &operator[](int n) { return e[n]; }
protected:
Encoding e[17];
};
2004-09-17 17:25:59 +02:00
2004-07-02 15:00:02 +02:00
class Patch {
public:
2004-09-16 16:25:16 +02:00
2005-02-19 11:45:05 +01:00
static Encodings encodings;
Patch(Signature &signature, char *s,
2004-09-17 17:25:59 +02:00
unsigned short nv, unsigned short nf);
2004-07-02 19:42:43 +02:00
2005-02-19 11:45:05 +01:00
void Init(Signature &signature, unsigned short nv, unsigned short nf);
2004-07-02 15:00:02 +02:00
2005-02-19 11:45:05 +01:00
vcg::Point3f *Vert3fBegin() { return (vcg::Point3f *)vstart; }
vcg::Point3f &Vert3f(int n) { return Vert3fBegin()[n]; }
unsigned short *FaceBegin() { return (unsigned short *)fstart; }
unsigned short *Face(int n) { return FaceBegin() + 3 * n; }
2004-09-17 17:25:59 +02:00
2005-02-19 11:45:05 +01:00
//vcg::Point3f &Vert(unsigned short v) { return VertBegin()[v]; }
// unsigned short *Face(unsigned short f) { return FaceBegin() + f * 3; }
2004-09-30 02:27:42 +02:00
2005-02-22 11:38:17 +01:00
char *VColorBegin() { return vstartc; }
char *VNormBegin() { return vstartn; }
char *VTextBegin() { return vstartt; }
char *VDataBegin() { return vstartd; }
2005-02-19 11:45:05 +01:00
2005-02-22 11:38:17 +01:00
char *FColorBegin() { return fstartc; }
char *FNormBegin() { return fstartn; }
char *FTextBegin() { return fstartt; }
char *FDataBegin() { return fstartd; }
2005-02-19 11:45:05 +01:00
static unsigned int ChunkSize(Signature &signature,
2004-09-17 17:25:59 +02:00
unsigned short nvert,
2004-10-08 17:12:04 +02:00
unsigned short nface,
unsigned int chunk_size);
2004-07-02 15:00:02 +02:00
2005-02-19 11:45:05 +01:00
static unsigned int ByteSize(Signature &signature,
2004-09-17 17:25:59 +02:00
unsigned short nvert,
unsigned short nface);
2004-10-10 19:19:42 +02:00
char *Compress(unsigned int ram_size, unsigned int &size);
void Decompress(unsigned int ram_size, void *src, unsigned int src_sz);
2004-07-02 15:00:02 +02:00
2005-02-19 11:45:05 +01:00
char *fstart;
char *vstart;
2004-09-17 17:25:59 +02:00
unsigned short nf;
2005-02-19 11:45:05 +01:00
unsigned short nv;
2004-09-17 17:25:59 +02:00
2005-02-22 11:38:17 +01:00
char *fstartc;
char *fstartn;
char *fstartt;
char *fstartd;
char *vstartc;
char *vstartn;
char *vstartt;
char *vstartd;
2004-07-02 15:00:02 +02:00
};
2004-09-17 17:25:59 +02:00
} //namespace
2004-07-02 15:00:02 +02:00
#endif