src/Volume.cpp

Go to the documentation of this file.
00001 #include "Volume.h"
00002 
00003 
00004 Volume::Volume()
00005 {
00006   release();
00007 }
00008 
00009 Volume::Volume( const std::string &strFilename ) 
00010 {
00011   release();
00012         load( strFilename );
00013 }
00014 
00015 Volume::~Volume(void)
00016 {
00017   release();
00018 }
00019 
00020 
00021 void Volume::load( const std::string &strFilename )
00022 {
00023         std::cout << "- Loading file '" << strFilename << "' ... " << std::endl;
00024         
00025   FILE *fp = NULL;
00026         fopen_s( &fp, strFilename.c_str(), "rb" );
00027 
00028         if (!fp)
00029                 std::cerr << "- Error loading file!" << std::endl << std::endl;
00030         else
00031         {
00032 
00033                 /* who needs this??
00034     char vcPath[1024];
00035                 char *pFileName = NULL;
00036                 GetFullPathName(strFilename.c_str(),1024,vcPath,&pFileName);
00037                 char vcDrive[1024], vcDirectory[1024], vcFilename[1024], vcExtension[1024];
00038                 _splitpath_s(vcPath,vcDrive,vcDirectory,vcFilename,vcExtension);
00039                 const std::string strAdditionalFilename =  std::string(vcDrive)+std::string(vcDirectory)+std::string(vcFilename)+std::string(".ini");
00040 
00041                 char vpSpacingX[1024],vpSpacingY[1024],vpSpacingZ[1024];
00042                 GetPrivateProfileString("DatFile","oldDat Spacing X","1.0",vpSpacingX,256,strAdditionalFilename.c_str());
00043                 GetPrivateProfileString("DatFile","oldDat Spacing Y","1.0",vpSpacingY,256,strAdditionalFilename.c_str());
00044                 GetPrivateProfileString("DatFile","oldDat Spacing Z","1.0",vpSpacingZ,256,strAdditionalFilename.c_str());
00045     */
00046 
00047                 //unsigned short uWidth, uHeight, uDepth;
00048 
00049                 unsigned short sizeX, sizeY, sizeZ;
00050                 fread( &sizeX, sizeof(unsigned short), 1, fp );
00051                 fread( &sizeY, sizeof(unsigned short), 1, fp );
00052                 fread( &sizeZ, sizeof(unsigned short), 1, fp );
00053 
00054                 m_sizeX = int(sizeX);
00055                 m_sizeY = int(sizeY);
00056                 m_sizeZ = int(sizeZ);
00057 
00058     std::cout << " - Volume-dimensions: (" << 
00059       m_sizeX << ", " <<
00060       m_sizeY << ", " <<
00061       m_sizeZ << ")" << std::endl;
00062 
00063                 const int slice      = sizeX * sizeY;
00064                 const int volumeSize = slice * sizeZ;
00065                 m_voxels.resize( volumeSize );
00066 
00067                 std::vector<unsigned short> data;
00068                 data.resize( volumeSize );
00069 
00070                 // read file into data-vector and close it
00071     fread( (void*) &(data.front()), sizeof(unsigned short), volumeSize, fp );
00072                 fclose( fp );
00073 
00074                 std::cout << "- File loaded." << std::endl;
00075 
00076     //** create density data for histogram
00077     memset(m_densityArray, 0, sizeof(m_densityArray));
00078     int densityIndex = 0;
00079 
00080                 // process data and store it in m_voxels
00081     for ( int z=0; z<m_sizeZ; z++ )
00082                 {
00083                         for ( int y=0; y<m_sizeY; y++ )
00084                         {
00085                                 for ( int x=0; x<m_sizeX; x++ )
00086                                 {
00087                                         //we convert the data to float values in an interval of [0..1]
00088           const float fValue = std::min( 1.0f, float( data[ x + y*m_sizeX + z*slice ] ) / 4095.0f );
00089           m_voxels[ x + y*m_sizeX + z*slice ] = Voxel( fValue );
00090 
00091           // Creating Histogram
00092           densityIndex = (int) ( Voxel(fValue).getValue() * DENSITY_COUNT );
00093           m_densityArray[densityIndex]++; //increment arrayIndexValue
00094 
00095                             if( m_densityArray[densityIndex] > m_maxDensityIndex )
00096                             {
00097                                     m_maxDensityIndex = m_densityArray[densityIndex];
00098                             }
00099         }
00100                         }
00101       std::cout << "\r- Preparing data (" << (z*100) / (m_sizeZ - 1) << "%) ...";
00102                 }
00103                 std::cout << std::endl << "- Data prepared." << std::endl;
00104         }
00105 }
00106 
00107 void Volume::release()
00108 {
00109   printf("Unload Volume data\n");
00110 
00111   memset(m_densityArray, 0, sizeof(m_densityArray));
00112   m_voxels.clear();
00113   m_sizeX = m_sizeY = m_sizeZ = 1;
00114 }

Generated on Mon Dec 10 18:18:11 2007 for VisLU by  doxygen 1.5.4