VCG Library
simple_volume.h
1 #ifndef __VCG_SIMPLE_VOLUME
2 #define __VCG_SIMPLE_VOLUME
3 #include<vector>
4 namespace vcg
5 {
6 
7 template <class VOX_TYPE>
8 class SimpleVolume
9 {
10 public:
11  typedef VOX_TYPE VoxelType;
12  std::vector<VoxelType> Vol;
13 
14  Point3i sz;
15 
16  const Point3i &ISize() {return sz;};
17 
18  void Init(Point3i _sz)
19  {
20  sz=_sz;
21  Vol.resize(sz[0]*sz[1]*sz[2]);
22  }
23 
24  float Val(const int &x,const int &y,const int &z) const {
25  return cV(x,y,z).V();
26  //else return numeric_limits<float>::quiet_NaN( );
27  }
28 
29  float &Val(const int &x,const int &y,const int &z) {
30  return V(x,y,z).V();
31  //else return numeric_limits<float>::quiet_NaN( );
32  }
33 
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]];
36  }
37 
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]];
40  }
41 
42 
43 typedef enum { XAxis=0,YAxis=1,ZAxis=2} VolumeAxis;
44 
45 template < class VertexPointerType, VolumeAxis AxisVal >
46  void GetIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointerType &v, const float thr)
47 {
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();
57 }
58 
59 template < class VertexPointerType >
60  void GetXIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointerType &v, const float thr)
61 { GetIntercept<VertexPointerType,XAxis>(p1,p2,v,thr); }
62 
63 template < class VertexPointerType >
64  void GetYIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointerType &v, const float thr)
65 { GetIntercept<VertexPointerType,YAxis>(p1,p2,v,thr); }
66 
67 template < class VertexPointerType >
68  void GetZIntercept(const vcg::Point3i &p1, const vcg::Point3i &p2, VertexPointerType &v, const float thr)
69 { GetIntercept<VertexPointerType,ZAxis>(p1,p2,v,thr); }
70 };
71 template <class VolumeType>
72 class RawVolumeImporter
73 {
74 public:
75  enum DataType
76 {
77  // Funzioni superiori
78  UNDEF=0,
79  BYTE=1,
80  SHORT=2,
81  FLOAT=3
82 };
83 
84 static bool Open(const char *filename, VolumeType &V, Point3i sz, DataType d)
85 {
86 return true;
87 }
88 };
89 
90 class SimpleVoxel
91 {
92 private:
93  float _v;
94 public:
95  float &V() {return _v;};
96  float V() const {return _v;};
97 };
98 } // end namespace
99 #endif // __VCG_SIMPLE_VOLUME