1 #ifndef __VCG_SIMPLE_VOLUME
2 #define __VCG_SIMPLE_VOLUME
7 template <
class VOX_TYPE>
11 typedef VOX_TYPE VoxelType;
12 std::vector<VoxelType> Vol;
16 const Point3i &ISize() {
return sz;};
18 void Init(Point3i _sz)
21 Vol.resize(sz[0]*sz[1]*sz[2]);
24 float Val(
const int &x,
const int &y,
const int &z)
const {
29 float &Val(
const int &x,
const int &y,
const int &z) {
34 VOX_TYPE &V(
const int &x,
const int &y,
const int &z) {
35 return Vol[x+y*sz[0]+z*sz[0]*sz[1]];
38 const VOX_TYPE &cV(
const int &x,
const int &y,
const int &z)
const {
39 return Vol[x+y*sz[0]+z*sz[0]*sz[1]];
43 typedef enum { XAxis=0,YAxis=1,ZAxis=2} VolumeAxis;
45 template <
class VertexPo
interType, VolumeAxis AxisVal >
46 void GetIntercept(
const vcg::Point3i &p1,
const vcg::Point3i &p2, VertexPointerType &v,
const float thr)
48 float f1 = Val(p1.X(), p1.Y(), p1.Z())-thr;
49 float f2 = Val(p2.X(), p2.Y(), p2.Z())-thr;
50 float u = (float) f1/(f1-f2);
51 if(AxisVal==XAxis) v->P().X() = (float) p1.X()*(1-u) + u*p2.X();
52 else v->P().X() = (float) p1.X();
53 if(AxisVal==YAxis) v->P().Y() = (float) p1.Y()*(1-u) + u*p2.Y();
54 else v->P().Y() = (float) p1.Y();
55 if(AxisVal==ZAxis) v->P().Z() = (float) p1.Z()*(1-u) + u*p2.Z();
56 else v->P().Z() = (float) p1.Z();
59 template <
class VertexPo
interType >
60 void GetXIntercept(
const vcg::Point3i &p1,
const vcg::Point3i &p2, VertexPointerType &v,
const float thr)
61 { GetIntercept<VertexPointerType,XAxis>(p1,p2,v,thr); }
63 template <
class VertexPo
interType >
64 void GetYIntercept(
const vcg::Point3i &p1,
const vcg::Point3i &p2, VertexPointerType &v,
const float thr)
65 { GetIntercept<VertexPointerType,YAxis>(p1,p2,v,thr); }
67 template <
class VertexPo
interType >
68 void GetZIntercept(
const vcg::Point3i &p1,
const vcg::Point3i &p2, VertexPointerType &v,
const float thr)
69 { GetIntercept<VertexPointerType,ZAxis>(p1,p2,v,thr); }
71 template <
class VolumeType>
72 class RawVolumeImporter
84 static bool Open(
const char *filename, VolumeType &V, Point3i sz, DataType d)
95 float &V() {
return _v;};
96 float V()
const {
return _v;};
99 #endif // __VCG_SIMPLE_VOLUME