Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members

HelperVolume.hh

00001 #ifndef HELPER_VOLUME_HH
00002 #define HELPER_VOLUME_HH
00003 
00004 //=============================================================================
00005 
00006 #include <float.h>
00007 #include <vector>
00008 #include <assert.h>
00009 
00010 // helper class for volume encoding
00011 template <class Voxel>
00012 class HelperVolumeT
00013 {
00014 public:
00015 
00016 
00018   HelperVolumeT()  { }
00019 
00020 
00021   HelperVolumeT(int _res) : resolution_(_res), xres_(_res),
00022                             yres_(_res) ,zres_(_res) 
00023   { 
00024     voxels_.resize(_res*_res*_res); 
00025   }
00026   
00027   HelperVolumeT(int _xres, int _yres, int _zres) : xres_(_xres),
00028                             yres_(_yres) ,zres_(_zres)  
00029   { 
00030     voxels_.resize(_xres *_yres * _zres); 
00031   }
00032 
00034   ~HelperVolumeT() { }
00035 
00036 
00038   void clear() 
00039   { 
00040     voxels_.clear(); 
00041     resize(resolution_);
00042   }
00043 
00044 
00045   void resize(int _res) 
00046   { 
00047     voxels_.clear(); 
00048     voxels_.resize(_res*_res*_res);
00049     resolution_ = _res;
00050     xres_ = _res;
00051     yres_ = _res;
00052     zres_ = _res;  
00053   }
00054 
00055   void resize(int _xres ,int _yres_,int _zres_) 
00056   { 
00057     voxels_.clear(); 
00058     voxels_.resize(_xres*_yres*_zres);
00059     xres_ = _xres;
00060     yres_ = _yres;
00061     zres_ = _zres;  
00062   }
00063 
00064   unsigned int resolution() 
00065   {
00066     return resolution_;
00067   }
00068 
00069   unsigned int xresolution() 
00070   {
00071     return xres_;
00072   }
00073 
00074   unsigned int yresolution() 
00075   {
00076     return yres_;
00077   }
00078   
00079   unsigned int zresolution() 
00080   {
00081     return zres_;
00082   }
00083 
00084 
00085 //=== VOXEL HANDLING =========================================================
00086 
00088   unsigned int number_of_voxels() const { return voxels_.size(); }
00089 
00090 //=== GENERIC ACCESS AND INIT ================================================
00091 
00093   inline Voxel& voxel(unsigned int _voxel)
00094   {
00095     assert(_voxel < voxels_.size());
00096     assert(_voxel >= 0);
00097     return voxels_[_voxel];
00098   }  
00099 
00100 
00102   inline Voxel& operator()(unsigned int i, unsigned int j, unsigned int k)
00103   {
00104     // first check that index is alright
00105     assert((i < xres_)&&(j < yres_)&&(k < zres_));
00106     return voxels_[k * xres_ * yres_ + j * xres_ + i]; 
00107   }
00108 
00109 
00111   bool is_ok(unsigned int _xdim, unsigned int _ydim, unsigned int _zdim)
00112   {
00113     if ((_xdim < xres_)&&(_ydim < yres_)&&(_zdim < zres_)) 
00114       return true;
00115     
00116     return false;
00117   }
00118 
00119 
00121   void init()
00122   {
00123     for (unsigned int i = 0; i < voxels_.size(); ++i)
00124       {
00125         voxels_[i].set_conquered(false);
00126       }
00127   }
00128 
00129 
00130 //=============================================================================
00131 
00133 private:
00134   
00136   unsigned int resolution_; 
00137   unsigned int xres_, yres_, zres_; 
00139   std::vector<Voxel> voxels_;
00140 
00141 };
00142 
00143 //=============================================================================
00144 
00145 
00146 class HelperVoxel
00147 {
00148 public:
00149  
00150   //-------------------------------------------------------
00151 
00153   HelperVoxel() : conquered_(false), position_(-1) { }
00154   
00155   // destructor
00156   ~HelperVoxel() { }
00157 
00158   //-------------------------------------------------------
00159 
00160 private:
00162   bool    conquered_; 
00163   int position_;
00164 
00165 
00166 public:
00167   //-------------------------------------------------------
00168 
00169   inline bool conquered() {return conquered_;}
00170 
00171   inline void set_conquered(bool _con) {conquered_ = _con;}
00172 
00173   // init the voxel
00174   inline void init()  { conquered_     = false; };
00175 
00176   inline int  position() {return position_;};
00177 
00178   inline void set_position(int pos) {position_ = pos;};
00179 
00180   //-------------------------------------------------------
00181 
00182 };
00183 
00184 typedef HelperVolumeT<HelperVoxel>          HelperVolume;
00185 
00186 
00187 //=============================================================================
00188 
00189 #endif // HELPER_VOLUME_HH
00190 
00191 //=============================================================================

Generated on Mon Jul 5 18:07:08 2004 for IsoEx by doxygen 1.3.6-20040222