Volume Class Reference

#include <Volume.hpp>

Collaboration diagram for Volume:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Volume ()
 empty constructor
 ~Volume ()
 destructor
void resize (const unsigned int &Nx, const unsigned int &Ny, const unsigned int &Nz)
 resize (fill with zero)
unsigned int size_x () const
 get size_x
unsigned int size_y () const
 get size_y
unsigned int size_z () const
 get size_z
double get_data (const unsigned int &kx, const unsigned int &ky, const unsigned int &kz) const
 get the value at position (kx,ky,kz)
void set_data (const unsigned int &kx, const unsigned int &ky, const unsigned int &kz, const double &value)
 set the value at position (kx,ky,kz)
double operator() (const double &x, const double &y, const double &z) const
 get the value at any position (x,y,z) using intepolation
Volume resampled_square (const unsigned int &N) const
 resample data to fit into a cube of a given size
Volume rotated_z (const double &angle) const
 apply rotation to the data by a fiven angle (radian) around the z direction
Volume smoothed () const
 smoothing
std::vector< float > slice_x (const unsigned &kx) const
 extract a slice of data in plane x=kx. Return a texture of size Ny*Nz (access using slice_x(kx)[ky+Ny*kz])
std::vector< float > slice_y (const unsigned &ky) const
 extract a slice of data in plane y=ky. Return a texture of size Nx*Nz (access using slice_x(ky)[kx+Nx*kz])
std::vector< float > slice_z (const unsigned &kz) const
 extract a slice of data in plane z=kz. Return a texture of size Nx*Ny (access using slice_x(kz)[kx+Nx*ky])
std::vector< float > mip () const
 Apply MIP projection along the x direction (return b&w texture of size Ny*Nz).
std::vector< std::vector< float > > ray_cast () const
 Apply classical ray-casting projection along the x direction (return color texture of size 3*Ny*Nz: access using ray_cast[r=0/g=1/b=2][ky+Ny*kz]).

Static Public Member Functions

static Volume load_v4d (const std::string &filename)
 load a .4d volume file

Private Member Functions

double linear_interpolation (const double &x, const double &y, const double &z) const
 internal tri-linear interpolation of the value at position (x,y,z). Return 0 if out-of-bounds

Private Attributes

unsigned int Nx
 size in x direction
unsigned int Ny
 size in y direction
unsigned int Nz
 size in x direction
std::vector< float > data
 internal data as concatenated vector of float

Detailed Description

Definition at line 9 of file Volume.hpp.


Constructor & Destructor Documentation

Volume::Volume (  ) 

empty constructor

Definition at line 7 of file Volume.cpp.

00007 :Nx(0),Ny(0),Nz(0),data(){}

Volume::~Volume (  ) 

destructor

Definition at line 8 of file Volume.cpp.

00008 {}


Member Function Documentation

double Volume::get_data ( const unsigned int &  kx,
const unsigned int &  ky,
const unsigned int &  kz 
) const

get the value at position (kx,ky,kz)

Definition at line 15 of file Volume.cpp.

References data, Nx, Ny, and Nz.

Referenced by linear_interpolation(), mip(), ray_cast(), slice_x(), slice_y(), slice_z(), and smoothed().

00016 {
00017     if(kx*ky*kz<Nx*Ny*Nz)
00018         return data[kx+Nx*(ky+Ny*kz)];
00019     else
00020         throw(std::string("Volume::get_data() outside bounds"));
00021 }

Here is the caller graph for this function:

double Volume::linear_interpolation ( const double &  x,
const double &  y,
const double &  z 
) const [private]

internal tri-linear interpolation of the value at position (x,y,z). Return 0 if out-of-bounds

Definition at line 113 of file Volume.cpp.

References get_data(), size_x(), size_y(), and size_z().

Referenced by operator()().

00114 {
00115     double epsilon=1e-6;
00116     if(x<0 || y<0 || z<0 || x+epsilon>=size_x() || y+epsilon>=size_y() || z+epsilon>=size_z())
00117     {
00118         //outside bounds
00119         return 0.0;
00120     }
00121 
00122     int x0=static_cast<int>(x);
00123     int y0=static_cast<int>(y);
00124     int z0=static_cast<int>(z);
00125 
00126     double ux;ux=(x-x0);
00127     double uy;uy=(y-y0);
00128     double uz;uz=(z-z0);
00129 
00130     double f=0.0;
00131 
00132     //******************************************************//
00133     //******************************************************//
00134     //**********  TO DO : Tri-linear interpolation *********//
00135     //******************************************************//
00136     //******************************************************//
00137     f=get_data(x0,y0,z0);
00138     //******************************************************//
00139     //******************************************************//
00140     //**********  /TO DO :                         *********//
00141     //******************************************************//
00142     //******************************************************//
00143 
00144     return f;
00145 }

Here is the call graph for this function:

Here is the caller graph for this function:

Volume Volume::load_v4d ( const std::string &  filename  )  [static]

load a .4d volume file

Definition at line 31 of file Volume.cpp.

References Nx, Ny, Nz, resize(), and set_data().

Referenced by main().

00032 {
00033 
00034     Volume v;
00035 
00036 
00037     std::ifstream stream(filename.c_str(),std::ifstream::in);
00038 
00039     if(!stream.good())
00040     {throw std::string("Error in Volume::load_v4d("+filename+") : cannot open file \n");}
00041 
00042     std::string buffer;
00043     unsigned int Nx=0,Ny=0,Nz=0;
00044     stream>>Nx; stream>>Ny; stream>>Nz;
00045 
00046     std::cout<<" find file "<<filename<<" size=("<<Nx<<","<<Ny<<","<<Nz<<")"<<std::endl;
00047     v.resize(Nx,Ny,Nz);
00048 
00049     double f;
00050 
00051     for(unsigned int kx=0;stream.good() && kx<Nx;++kx)
00052     {
00053         for(unsigned int ky=0;stream.good() && ky<Ny;++ky)
00054         {
00055             for(unsigned int kz=0;stream.good() && kz<Nz;++kz)
00056             {
00057                 stream>>f;
00058                 if(stream.good())
00059                     v.set_data(kx,ky,kz,f);
00060             }
00061         }
00062     }
00063     stream.close();
00064     return v;
00065 }

Here is the call graph for this function:

Here is the caller graph for this function:

std::vector< float > Volume::mip (  )  const

Apply MIP projection along the x direction (return b&w texture of size Ny*Nz).

Definition at line 215 of file Volume.cpp.

References get_data(), size_x(), size_y(), and size_z().

Referenced by main().

00216 {
00217     std::vector<float> proj(size_y()*size_z());
00218     for(unsigned int ky=0;ky<size_y();++ky)
00219     {
00220         for(unsigned int kz=0;kz<size_z();++kz)
00221         {
00222             //******************************************************//
00223             //******************************************************//
00224             //**********  TO DO : MIP                      *********//
00225             //******************************************************//
00226             //******************************************************//
00227             proj[ky+size_y()*kz]=get_data(size_x()/2.0,ky,kz);
00228             //******************************************************//
00229             //******************************************************//
00230             //**********  /TO DO :                         *********//
00231             //******************************************************//
00232             //******************************************************//
00233         }
00234     }
00235     return proj;
00236 }

Here is the call graph for this function:

Here is the caller graph for this function:

double Volume::operator() ( const double &  x,
const double &  y,
const double &  z 
) const

get the value at any position (x,y,z) using intepolation

Definition at line 108 of file Volume.cpp.

References linear_interpolation().

00109 {
00110     return linear_interpolation(x,y,z);
00111 }

Here is the call graph for this function:

std::vector< std::vector< float > > Volume::ray_cast (  )  const

Apply classical ray-casting projection along the x direction (return color texture of size 3*Ny*Nz: access using ray_cast[r=0/g=1/b=2][ky+Ny*kz]).

Definition at line 238 of file Volume.cpp.

References get_data(), size_x(), size_y(), and size_z().

Referenced by main().

00239 {
00240     std::vector<std::vector<float> >proj;
00241 
00242     proj.resize(3);
00243     proj[0].resize(size_y()*size_z());
00244     proj[1].resize(size_y()*size_z());
00245     proj[2].resize(size_y()*size_z());
00246 
00247     //******************************************************//
00248     //******************************************************//
00249     //**********  TO DO : Ray Casting              *********//
00250     //******************************************************//
00251     //******************************************************//
00252     for(unsigned int ky=0;ky<size_y();++ky)
00253     {
00254         for(unsigned int kz=0;kz<size_z();++kz)
00255         {
00256             proj[0][ky+size_y()*kz]=get_data(size_x()/2.0-2,ky,kz);
00257             proj[1][ky+size_y()*kz]=get_data(size_x()/2.0,ky,kz);
00258             proj[2][ky+size_y()*kz]=get_data(size_x()/2.0+2,ky,kz);
00259         }
00260     }
00261     //******************************************************//
00262     //******************************************************//
00263     //**********  /TO DO :                         *********//
00264     //******************************************************//
00265     //******************************************************//
00266 
00267     return proj;
00268 }

Here is the call graph for this function:

Here is the caller graph for this function:

Volume Volume::resampled_square ( const unsigned int &  N  )  const

resample data to fit into a cube of a given size

Definition at line 147 of file Volume.cpp.

References resize(), set_data(), size_x(), size_y(), and size_z().

Referenced by main().

00148 {
00149     Volume vol2;vol2.resize(N,N,N);
00150 
00151 
00152     for(unsigned int k0=0;k0<N;++k0)
00153     {
00154         double ux=static_cast<double>(k0)/static_cast<double>(N-1);
00155         double x0=ux*(size_x()-1);
00156         for(unsigned int k1=0;k1<N;++k1)
00157         {
00158             double uy=static_cast<double>(k1)/static_cast<double>(N-1);
00159             double y0=uy*(size_y()-1);
00160             for(unsigned int k2=0;k2<N;++k2)
00161             {
00162                 double uz=static_cast<double>(k2)/static_cast<double>(N-1);
00163                 double z0=uz*(size_z()-1);
00164 
00165                 vol2.set_data(k0,k1,k2,(*this)(x0,y0,z0));
00166             }
00167         }
00168     }
00169 
00170     return vol2;
00171 
00172 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Volume::resize ( const unsigned int &  Nx,
const unsigned int &  Ny,
const unsigned int &  Nz 
)

resize (fill with zero)

Definition at line 10 of file Volume.cpp.

References data, Nx, Ny, and Nz.

Referenced by load_v4d(), resampled_square(), rotated_z(), and smoothed().

00011 {
00012     data.resize(_Nx*_Ny*_Nz);
00013     Nx=_Nx;Ny=_Ny;Nz=_Nz;
00014 }

Here is the caller graph for this function:

Volume Volume::rotated_z ( const double &  angle  )  const

apply rotation to the data by a fiven angle (radian) around the z direction

Definition at line 174 of file Volume.cpp.

References resize(), set_data(), size_x(), size_y(), and size_z().

Referenced by main().

00175 {
00176     unsigned int N=std::max(size_x(),size_y());
00177     Volume v2;v2.resize(N,N,size_z());
00178 
00179     double cos_a;cos_a=cos(angle);
00180     double sin_a;sin_a=sin(angle);
00181 
00182     for(unsigned int kx=0;kx<N;++kx)
00183     {
00184         for(unsigned int ky=0;ky<N;++ky)
00185         {
00186             for(unsigned int kz=0;kz<size_z();++kz)
00187             {
00188 
00189 
00190                 //******************************************************//
00191                 //******************************************************//
00192                 //**********  TO DO : Rotation                 *********//
00193                 //******************************************************//
00194                 //******************************************************//
00195                 double x0=kx;
00196                 double y0=ky;
00197                 double z0=kz;
00198                 //******************************************************//
00199                 //******************************************************//
00200                 //**********  /TO DO :                         *********//
00201                 //******************************************************//
00202                 //******************************************************//
00203 
00204                 double f=(*this)(x0,y0,z0);
00205                 v2.set_data(kx,ky,kz,f);
00206             }
00207         }
00208     }
00209 
00210     return v2;
00211 
00212 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Volume::set_data ( const unsigned int &  kx,
const unsigned int &  ky,
const unsigned int &  kz,
const double &  value 
)

set the value at position (kx,ky,kz)

Definition at line 22 of file Volume.cpp.

References data, Nx, Ny, and Nz.

Referenced by load_v4d(), resampled_square(), rotated_z(), and smoothed().

00023 {
00024     if(kx*ky*kz<Nx*Ny*Nz)
00025         data[kx+Nx*(ky+Ny*kz)]=value;
00026     else
00027         throw(std::string("Volume::set_data() outside bounds"));
00028 }

Here is the caller graph for this function:

unsigned int Volume::size_x (  )  const

get size_x

Definition at line 67 of file Volume.cpp.

References Nx.

Referenced by linear_interpolation(), main(), mip(), ray_cast(), resampled_square(), rotated_z(), and smoothed().

00067 {return Nx;}

Here is the caller graph for this function:

unsigned int Volume::size_y (  )  const

get size_y

Definition at line 68 of file Volume.cpp.

References Ny.

Referenced by linear_interpolation(), main(), mip(), ray_cast(), resampled_square(), rotated_z(), and smoothed().

00068 {return Ny;}

Here is the caller graph for this function:

unsigned int Volume::size_z (  )  const

get size_z

Definition at line 69 of file Volume.cpp.

References Nz.

Referenced by linear_interpolation(), main(), mip(), ray_cast(), resampled_square(), rotated_z(), and smoothed().

00069 {return Nz;}

Here is the caller graph for this function:

std::vector< float > Volume::slice_x ( const unsigned &  kx  )  const

extract a slice of data in plane x=kx. Return a texture of size Ny*Nz (access using slice_x(kx)[ky+Ny*kz])

Definition at line 71 of file Volume.cpp.

References get_data(), Ny, and Nz.

Referenced by main().

00072 {
00073     std::vector <float> slice(Ny*Nz);
00074     for(unsigned int ky=0;ky<Ny;++ky)
00075     {
00076         for(unsigned int kz=0;kz<Nz;++kz)
00077         {
00078             slice[ky+Ny*kz]=get_data(kx,ky,kz);
00079         }
00080     }
00081     return slice;
00082 }

Here is the call graph for this function:

Here is the caller graph for this function:

std::vector< float > Volume::slice_y ( const unsigned &  ky  )  const

extract a slice of data in plane y=ky. Return a texture of size Nx*Nz (access using slice_x(ky)[kx+Nx*kz])

Definition at line 83 of file Volume.cpp.

References get_data(), Nx, and Nz.

Referenced by main().

00084 {
00085     std::vector <float> slice(Nx*Nz);
00086     for(unsigned int kx=0;kx<Nx;++kx)
00087     {
00088         for(unsigned int kz=0;kz<Nz;++kz)
00089         {
00090             slice[kx+Nx*kz]=get_data(kx,ky,kz);
00091         }
00092     }
00093     return slice;
00094 }

Here is the call graph for this function:

Here is the caller graph for this function:

std::vector< float > Volume::slice_z ( const unsigned &  kz  )  const

extract a slice of data in plane z=kz. Return a texture of size Nx*Ny (access using slice_x(kz)[kx+Nx*ky])

Definition at line 95 of file Volume.cpp.

References get_data(), Nx, and Ny.

Referenced by main().

00096 {
00097     std::vector <float> slice(Nx*Ny);
00098     for(unsigned int kx=0;kx<Nx;++kx)
00099     {
00100         for(unsigned int ky=0;ky<Ny;++ky)
00101         {
00102             slice[kx+Nx*ky]=get_data(kx,ky,kz);
00103         }
00104     }
00105     return slice;
00106 }

Here is the call graph for this function:

Here is the caller graph for this function:

Volume Volume::smoothed (  )  const

smoothing

Definition at line 270 of file Volume.cpp.

References get_data(), resize(), set_data(), size_x(), size_y(), and size_z().

Referenced by main().

00271 {
00272     Volume v2;v2.resize(size_x(),size_y(),size_z());
00273 
00274     for(unsigned int kx=1;kx<size_x()-1;++kx)
00275     {
00276         for(unsigned int ky=1;ky<size_y()-1;++ky)
00277         {
00278             for(unsigned int kz=1;kz<size_z()-1;++kz)
00279             {
00280                 double f=get_data(kx  ,ky,kz);
00281 
00282                 double fx0=get_data(kx-1,ky,kz);
00283                 double fx2=get_data(kx+1,ky,kz);
00284 
00285                 double fy0=get_data(kx,ky-1,kz);
00286                 double fy2=get_data(kx,ky+1,kz);
00287 
00288                 double fz0=get_data(kx,ky,kz-1);
00289                 double fz2=get_data(kx,ky,kz+1);
00290 
00291                 double v=1/12.0*(6*f+fx0+fx2+fy0+fy2+fz0+fz2);
00292 
00293                 v2.set_data(kx,ky,kz,v);
00294             }
00295         }
00296     }
00297     return v2;
00298 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

std::vector<float> Volume::data [private]

internal data as concatenated vector of float

Definition at line 122 of file Volume.hpp.

Referenced by get_data(), resize(), and set_data().

unsigned int Volume::Nx [private]

size in x direction

Definition at line 116 of file Volume.hpp.

Referenced by get_data(), load_v4d(), resize(), set_data(), size_x(), slice_y(), and slice_z().

unsigned int Volume::Ny [private]

size in y direction

Definition at line 118 of file Volume.hpp.

Referenced by get_data(), load_v4d(), resize(), set_data(), size_y(), slice_x(), and slice_z().

unsigned int Volume::Nz [private]

size in x direction

Definition at line 120 of file Volume.hpp.

Referenced by get_data(), load_v4d(), resize(), set_data(), size_z(), slice_x(), and slice_y().


The documentation for this class was generated from the following files:

Generated on Sun Jan 24 21:30:27 2010 by  doxygen 1.6.1