Eigene Dateien/Vis/src/VVolume.cpp

Go to the documentation of this file.
00001 #include "VVolume.h"
00002 #include "glew.h"
00003 #include <fstream>
00004 #include <iostream>
00005 
00006 #define HISTOGRAM2D_RESOLUTION 1024*1024*4
00007 #define HISTOGRAM2D_RESOLUTION_X 1024
00008 #define HISTOGRAM2D_RESOLUTION_Y 1024
00009 
00010 
00011 VVolume::VVolume() : 
00012                                                 m_GLVolumeHandle(0), 
00013                                                 m_DimX(0), 
00014                                                 m_DimY(0), 
00015                                                 m_DimZ(0), 
00016                                                 m_maxdensity(0.0f),
00017                                                 m_VolumeFilePath(""),  
00018                                                 m_ModelMatrix(), 
00019                                                 m_NormalMatrix()
00020 {
00021         m_Histogram.resize(0);
00022         m_VolumeData.resize(0);
00023 
00024         m_histogram2d_texture.resize(HISTOGRAM2D_RESOLUTION);
00025         
00026 }
00027 
00028 VVolume::VVolume(std::string filepath) : 
00029                                                 m_GLVolumeHandle(0), 
00030                                                 m_DimX(0), 
00031                                                 m_DimY(0), 
00032                                                 m_DimZ(0), 
00033                                                 m_maxdensity(0.0f),
00034                                                 m_VolumeFilePath(filepath), 
00035                                                 m_ModelMatrix(), 
00036                                                 m_NormalMatrix()
00037 {
00038         m_Histogram.resize(0);
00039         m_VolumeData.resize(0);
00040         int size[3];
00041         this->loadVolume(m_VolumeFilePath, size);
00042 
00043         m_histogram2d_texture.resize(HISTOGRAM2D_RESOLUTION);
00044         
00045 }
00046 
00047 VVolume::~VVolume()
00048 {
00049         clear();
00050 
00051         m_histogram2d_texture.clear();
00052 }
00053 
00054 bool VVolume::loadVolume(std::string filepath, int *data)
00055 {
00056 
00057         std::string fileend = filepath.substr(filepath.size()-5, filepath.size()-1);
00058         if(fileend.compare(".gdat") == 0)
00059         {
00060                 return this->loadGDat(filepath, data);
00061         }
00062         
00063         fileend = filepath.substr(filepath.size()-4, filepath.size()-1);
00064         if(fileend.compare(".dat") == 0)
00065         {
00066                 return this->loadDat(filepath, data);
00067         }
00068         return false;
00069 }
00070 
00071 bool VVolume::saveVolume(std::string filepath)
00072 {
00073         if(filepath == "")
00074         {
00075                 return true;
00076         }
00077         FILE *fp = NULL;
00078 
00079         std::cout << "Saving Volume File: " << filepath << std::endl;
00080 
00081         fopen_s(&fp,filepath.c_str(),"wb");
00082 
00083         if(!fp)
00084         {
00085                 return false;
00086         }
00087 
00088         fwrite(reinterpret_cast<char*>(&m_DimX), sizeof(int), 1,fp);
00089         fwrite(reinterpret_cast<char*>(&m_DimY), sizeof(int), 1,fp);
00090         fwrite(reinterpret_cast<char*>(&m_DimZ), sizeof(int), 1,fp);
00091 
00092         for(int i = 0; i < m_DimZ; ++i)
00093         {
00094                 for(int j = 0; j < m_DimY; ++j)
00095                 {
00096                         for (int k = 0; k < m_DimX; ++k)
00097                         {
00098                                 fwrite(reinterpret_cast<char*>(m_VolumeData[k + j * m_DimX + i * m_DimX * m_DimY].getDataPtr()), sizeof(float), 1,fp);
00099                                 fwrite(reinterpret_cast<char*>(m_VolumeData[k + j * m_DimX + i * m_DimX * m_DimY].getGradientPtr()), sizeof(float), 3,fp);
00100                         }
00101                 }
00102                 std::cout << "\rSaving Data(" << (i*100)/(m_DimZ-1) << "%) ... ";
00103         }
00104 
00105         std::cout << "Saving Histograms" << std::endl;
00106 
00107         fwrite(reinterpret_cast<char*>(&m_Histogram[0]), sizeof(int), 4096,fp);
00108         
00109 
00110         unsigned int histsizex = HISTOGRAM2D_RESOLUTION_X;
00111         unsigned int histsizey = HISTOGRAM2D_RESOLUTION_Y;
00112         unsigned int numchannel = HISTOGRAM2D_RESOLUTION / (histsizey * histsizex);
00113 
00114 
00115         fwrite(reinterpret_cast<char*>(&histsizex), sizeof(unsigned int), 1,fp);
00116         fwrite(reinterpret_cast<char*>(&histsizey), sizeof(unsigned int), 1,fp);
00117         fwrite(reinterpret_cast<char*>(&numchannel), sizeof(unsigned int), 1,fp);
00118         fwrite(reinterpret_cast<char*>(&m_histogram2d_texture[0]), sizeof(unsigned char), HISTOGRAM2D_RESOLUTION, fp);
00119 
00120         fclose(fp);
00121         std::cout << std::endl << "Saving Volume Data Finished" << std::endl;
00122         return true;
00123 }
00124 
00125 int VVolume::getDimX()
00126 {
00127         if (!GLEW_ARB_texture_non_power_of_two)
00128         {
00129                 return getNextPowerOfTwo(m_DimX);
00130         }
00131         return m_DimX;
00132 }
00133 
00134 int VVolume::getDimY()
00135 {
00136         if (!GLEW_ARB_texture_non_power_of_two)
00137         {
00138                 return getNextPowerOfTwo(m_DimY);
00139         }
00140         return m_DimY;
00141 }
00142 
00143 int VVolume::getDimZ()
00144 {
00145         if (!GLEW_ARB_texture_non_power_of_two)
00146         {
00147                 return getNextPowerOfTwo(m_DimZ);
00148         }
00149         return m_DimZ;
00150 }
00151 
00152 bool VVolume::bindVolumeInOpenGL()
00153 {
00154         std::cout << "Binding Volume in OpenGl" << std::endl;
00155         
00156         GLenum glError = GL_NO_ERROR;
00157         glGenTextures(1, &m_GLVolumeHandle);
00158 
00159         if (glError != GL_NO_ERROR)
00160         {
00161                 std::cout << "Error generating texture " << gluErrorString(glError) << std::endl;
00162                 return false;
00163         }
00164 
00165         glEnable(GL_TEXTURE_3D);
00166         glBindTexture(GL_TEXTURE_3D, m_GLVolumeHandle);
00167 
00168         float vfBorderColor[4] = {0.0f, 0.0f, 0.0f, 0.0f};
00169         glTexParameterfv(GL_TEXTURE_3D_EXT, GL_TEXTURE_BORDER_COLOR, vfBorderColor);
00170 
00171         if (GLEW_ARB_texture_border_clamp)
00172         {
00173                 glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER_ARB);
00174                 glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER_ARB);
00175                 glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_WRAP_R_EXT, GL_CLAMP_TO_BORDER_ARB);
00176         }
00177         else
00178         {
00179                 glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_WRAP_S, GL_CLAMP);
00180                 glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_WRAP_T, GL_CLAMP);
00181                 glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_WRAP_R_EXT, GL_CLAMP);
00182         }
00183 
00184         glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
00185         glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
00186         
00187 
00188         int iInternalFormat = GL_RGBA;
00189 
00190         if (GLEW_ARB_texture_float)
00191                 iInternalFormat = GL_RGBA16F_ARB;
00192 
00193         int iTextureWidth = m_DimX;
00194         int iTextureHeight = m_DimY;
00195         int iTextureDepth = m_DimZ;
00196 
00197         if (!GLEW_ARB_texture_non_power_of_two)
00198         {
00199                 iTextureWidth = getNextPowerOfTwo(m_DimX);
00200                 iTextureHeight = getNextPowerOfTwo(m_DimY);
00201                 iTextureDepth = getNextPowerOfTwo(m_DimZ);                               
00202         }
00203 
00204         glTexImage3D(GL_TEXTURE_3D, 0, iInternalFormat, iTextureWidth, iTextureHeight, iTextureDepth, 0, GL_RGBA, GL_FLOAT, NULL);
00205 
00206         glError = glGetError();
00207         if (glError != GL_NO_ERROR )
00208         {
00209                 std::cout << "Error creating texture" << std::endl;
00210         }
00211 
00212         glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, m_DimX, m_DimY, m_DimZ, GL_RGBA, GL_FLOAT, &(m_VolumeData[0]));
00213 
00214 
00215         glError = glGetError();
00216         if (glError != GL_NO_ERROR )
00217         {
00218                 std::cout << "Error creating texture" << std::endl;
00219         }
00220 
00221         std::cout << "Binding Volume in OpenGL finished" << std::endl;
00222         glDisable(GL_TEXTURE_3D);
00223         return true;
00224 }
00225 
00226 bool VVolume::loadDat(std::string filename, int *data)
00227 {
00228         FILE *fp = NULL;
00229 
00230         fopen_s(&fp,filename.c_str(),"rb");
00231 
00232         if(!fp)
00233         {
00234                 return false;
00235         }
00236 
00237         std::cout << "Loading Volume File: " << filename << std::endl;
00238         unsigned short dimX, dimY, dimZ;
00239 
00240         fread(&dimX,sizeof(unsigned short),1,fp);
00241         fread(&dimY,sizeof(unsigned short),1,fp);
00242         fread(&dimZ,sizeof(unsigned short),1,fp);
00243 
00244         m_DimX = (int)dimX;
00245         m_DimY = (int)dimY;
00246         m_DimZ = (int)dimZ;
00247 
00248         data[0] = m_DimX;
00249         data[1] = m_DimY;
00250         data[2] = m_DimZ;
00251 
00252         std::cout << "File Header:" << std::endl;
00253         std::cout << "\t\tDimension X: " << m_DimX << std::endl;
00254         std::cout << "\t\tDimension Y: " << m_DimY << std::endl;
00255         std::cout << "\t\tDimension Z: " << m_DimZ << std::endl;
00256 
00257         if (!GLEW_ARB_texture_non_power_of_two)
00258         {
00259                 const int iPotWidth = getNextPowerOfTwo(m_DimX);
00260                 const int iPotHeight = getNextPowerOfTwo(m_DimY);
00261                 const int iPotDepth = getNextPowerOfTwo(m_DimZ);
00262 
00263                 const VVector vecScale = VVector(float(m_DimX)/float(iPotWidth),float(m_DimY)/float(iPotHeight),float(m_DimZ)/float(iPotDepth));
00264                 const VVector vecTranslation = VVector(-float(iPotWidth - m_DimX)/float(m_DimX),-float(iPotHeight - m_DimY)/float(m_DimY),-float(iPotDepth - m_DimZ)/float(m_DimZ));
00265 
00266                 m_ModelMatrix.scale(vecScale);
00267                 m_ModelMatrix.translate(vecTranslation);
00268         }
00269 
00270         int numVoxels = m_DimX * m_DimY * m_DimZ;
00271 
00272         std::vector<unsigned short> tmpData(numVoxels);
00273         m_VolumeData.resize(numVoxels);
00274 
00275         fread((void*)&(tmpData.front()),sizeof(unsigned short),numVoxels,fp);
00276         fclose(fp);
00277         
00278         m_Histogram.clear();
00279         m_Histogram.resize(4096);
00280         m_maxdensity = 0.0f;
00281 
00282         for (int i = 0; i< HISTOGRAM2D_RESOLUTION; i++)
00283         {
00284                 m_histogram2d_texture[i] = 0;
00285         }
00286 
00287         std::map<int, std::map<float, int>> m_Histogram2D;      
00288 
00289         const int iSlice = m_DimX * m_DimY;
00290 
00291         
00292         unsigned int max_probability = 0;
00293 
00294         for (int k=0;k<m_DimZ;k++)
00295         {
00296                 const int i1nz = max(k-1,0);
00297                 const int i0pz = k;
00298                 const int i1pz = min(k+1,m_DimZ-1);
00299 
00300                 for (int j=0;j<m_DimY;j++)
00301                 {
00302                         const int i1ny = max(j-1,0);
00303                         const int i0py = j;
00304                         const int i1py = min(j+1,m_DimY-1);
00305 
00306                         for (int i=0;i<m_DimX;i++)
00307                         {
00308                                 const int i1nx = max(i-1,0);
00309                                 const int i0px = i;
00310                                 const int i1px = min(i+1,m_DimX-1);
00311 
00312                                 float samplesNegZOffset[9];
00313                                 float samplesNoZOffset[9];
00314                                 float samplesPosZOffset[9];
00315 
00316                                 // Code taken from Stefan Bruckners Computational Aesthetics Framework
00317                                 // only rewritten for nicer(but not as readable as the original) constructor
00318 
00319                                 samplesNegZOffset[0] = min(1.0f,float(tmpData[i1nx + i1ny*m_DimX + i1nz*iSlice]) / 4095.0f);
00320                                 samplesNegZOffset[1] = min(1.0f,float(tmpData[i0px + i1ny*m_DimX + i1nz*iSlice]) / 4095.0f);
00321                                 samplesNegZOffset[2] = min(1.0f,float(tmpData[i1px + i1ny*m_DimX + i1nz*iSlice]) / 4095.0f);
00322                                 samplesNegZOffset[3] = min(1.0f,float(tmpData[i1nx + i0py*m_DimX + i1nz*iSlice]) / 4095.0f);
00323                                 samplesNegZOffset[4] = min(1.0f,float(tmpData[i0px + i0py*m_DimX + i1nz*iSlice]) / 4095.0f);
00324                                 samplesNegZOffset[5] = min(1.0f,float(tmpData[i1px + i0py*m_DimX + i1nz*iSlice]) / 4095.0f);
00325                                 samplesNegZOffset[6] = min(1.0f,float(tmpData[i1nx + i1py*m_DimX + i1nz*iSlice]) / 4095.0f);
00326                                 samplesNegZOffset[7] = min(1.0f,float(tmpData[i0px + i1py*m_DimX + i1nz*iSlice]) / 4095.0f);
00327                                 samplesNegZOffset[8] = min(1.0f,float(tmpData[i1px + i1py*m_DimX + i1nz*iSlice]) / 4095.0f);
00328 
00329                                 samplesNoZOffset[0] = min(1.0f,float(tmpData[i1nx + i1ny*m_DimX + i0pz*iSlice]) / 4095.0f);
00330                                 samplesNoZOffset[1] = min(1.0f,float(tmpData[i0px + i1ny*m_DimX + i0pz*iSlice]) / 4095.0f);
00331                                 samplesNoZOffset[2] = min(1.0f,float(tmpData[i1px + i1ny*m_DimX + i0pz*iSlice]) / 4095.0f);
00332                                 samplesNoZOffset[3] = min(1.0f,float(tmpData[i1nx + i0py*m_DimX + i0pz*iSlice]) / 4095.0f);
00333                                 samplesNoZOffset[4] = min(1.0f,float(tmpData[i0px + i0py*m_DimX + i0pz*iSlice]) / 4095.0f);
00334                                 samplesNoZOffset[5] = min(1.0f,float(tmpData[i1px + i0py*m_DimX + i0pz*iSlice]) / 4095.0f);
00335                                 samplesNoZOffset[6] = min(1.0f,float(tmpData[i1nx + i1py*m_DimX + i0pz*iSlice]) / 4095.0f);
00336                                 samplesNoZOffset[7] = min(1.0f,float(tmpData[i0px + i1py*m_DimX + i0pz*iSlice]) / 4095.0f);
00337                                 samplesNoZOffset[8] = min(1.0f,float(tmpData[i1px + i1py*m_DimX + i0pz*iSlice]) / 4095.0f);
00338 
00339                                 samplesPosZOffset[0] = min(1.0f,float(tmpData[i1nx + i1ny*m_DimX + i1pz*iSlice]) / 4095.0f);
00340                                 samplesPosZOffset[1] = min(1.0f,float(tmpData[i0px + i1ny*m_DimX + i1pz*iSlice]) / 4095.0f);
00341                                 samplesPosZOffset[2] = min(1.0f,float(tmpData[i1px + i1ny*m_DimX + i1pz*iSlice]) / 4095.0f);
00342                                 samplesPosZOffset[3] = min(1.0f,float(tmpData[i1nx + i0py*m_DimX + i1pz*iSlice]) / 4095.0f);
00343                                 samplesPosZOffset[4] = min(1.0f,float(tmpData[i0px + i0py*m_DimX + i1pz*iSlice]) / 4095.0f);
00344                                 samplesPosZOffset[5] = min(1.0f,float(tmpData[i1px + i0py*m_DimX + i1pz*iSlice]) / 4095.0f);
00345                                 samplesPosZOffset[6] = min(1.0f,float(tmpData[i1nx + i1py*m_DimX + i1pz*iSlice]) / 4095.0f);
00346                                 samplesPosZOffset[7] = min(1.0f,float(tmpData[i0px + i1py*m_DimX + i1pz*iSlice]) / 4095.0f);
00347                                 samplesPosZOffset[8] = min(1.0f,float(tmpData[i1px + i1py*m_DimX + i1pz*iSlice]) / 4095.0f);
00348 
00349                                 m_VolumeData[i+j*m_DimX+k*iSlice] = VVoxel( samplesNegZOffset, samplesNoZOffset, samplesPosZOffset);
00350                                 float fValue = m_VolumeData[i+j*m_DimX+k*iSlice].getData() * 4095.0f;
00351                                 float magValue = m_VolumeData[i+j*m_DimX+k*iSlice].getGradientMagnitude();
00352 
00353                                 int dens = (int)(m_VolumeData[i+j*m_DimX+k*iSlice].getData() * HISTOGRAM2D_RESOLUTION_X);
00354                                 int gmag = (int)(m_VolumeData[i+j*m_DimX+k*iSlice].getGradientMagnitude()*HISTOGRAM2D_RESOLUTION_Y);
00355 
00356                                 
00357 
00358                                 m_histogram2d_texture[dens*4 + gmag*HISTOGRAM2D_RESOLUTION_X*4] += 1;
00359                                 m_histogram2d_texture[dens*4 + gmag*HISTOGRAM2D_RESOLUTION_X*4 +1] += 1;
00360                                 m_histogram2d_texture[dens*4 + gmag*HISTOGRAM2D_RESOLUTION_X*4 +2] += 1;
00361                                 m_histogram2d_texture[dens*4 + gmag*HISTOGRAM2D_RESOLUTION_X*4 +3] += 1;
00362 
00363                                 if( gmag > 512 &&
00364                                         max_probability < m_histogram2d_texture[dens*4 + gmag*HISTOGRAM2D_RESOLUTION_X*4])
00365                                 {
00366                                         max_probability = m_histogram2d_texture[dens*4 + gmag*HISTOGRAM2D_RESOLUTION_X*4];
00367                                 }
00368 
00369 
00370                                 if(fValue != 0)
00371                                 {
00372                                         m_Histogram[(int)(fValue)]++;
00373                                         if (fValue > 255.0 && m_Histogram[(int)(fValue)] > m_maxdensity) 
00374                                                 m_maxdensity = m_Histogram[(int)(fValue)];
00375                                 }
00376                         }
00377                 }
00378 
00379                 std::cout << "\rPreparing data (" << (k*100) / (m_DimZ-1) << "%) ...";
00380         }
00381 
00382         for (int i = 0; i< HISTOGRAM2D_RESOLUTION; i++)
00383         {
00384 
00385                 if(m_histogram2d_texture[i]>0) 
00386                         
00387                 {
00388                         m_histogram2d_texture[i]= 128 + min(127, (unsigned int)(127.0f * ( (float)m_histogram2d_texture[i]/ max_probability )) );
00389                 }
00390                 //m_histogram2d_texture[i] = min(255, (unsigned int)(255.0f * ( (float)m_histogram2d_texture[i]/ max_probability )) );
00391                 
00392         }
00393 
00394         std::cout << std::endl << "Loading Volume Data Finished" << std::endl;
00395  
00396         data[3] = m_maxdensity;
00397 
00398         
00399 
00400         return (this->bindVolumeInOpenGL());
00401 }
00402 
00403 bool VVolume::loadGDat(std::string filename, int *data)
00404 {
00405         FILE *fp = NULL;
00406 
00407         fopen_s(&fp,filename.c_str(),"rb");
00408 
00409         if(!fp)
00410         {
00411                 return false;
00412         }
00413 
00414         std::cout << "Loading Volume File: " << filename << std::endl;
00415         int dimX, dimY, dimZ;
00416 
00417         fread(&dimX,sizeof(int),1,fp);
00418         fread(&dimY,sizeof(int),1,fp);
00419         fread(&dimZ,sizeof(int),1,fp);
00420 
00421 
00422         m_DimX = (int)dimX;
00423         m_DimY = (int)dimY;
00424         m_DimZ = (int)dimZ;
00425 
00426         data[0] = m_DimX;
00427         data[1] = m_DimY;
00428         data[2] = m_DimZ;
00429 
00430         std::cout << "File Header:" << std::endl;
00431         std::cout << "\t\tDimension X: " << m_DimX << std::endl;
00432         std::cout << "\t\tDimension Y: " << m_DimY << std::endl;
00433         std::cout << "\t\tDimension Z: " << m_DimZ << std::endl;
00434 
00435         if (!GLEW_ARB_texture_non_power_of_two)
00436         {
00437                 const int iPotWidth = getNextPowerOfTwo(m_DimX);
00438                 const int iPotHeight = getNextPowerOfTwo(m_DimY);
00439                 const int iPotDepth = getNextPowerOfTwo(m_DimZ);
00440 
00441                 const VVector vecScale = VVector(float(m_DimX)/float(iPotWidth),float(m_DimY)/float(iPotHeight),float(m_DimZ)/float(iPotDepth));
00442                 const VVector vecTranslation = VVector(-float(iPotWidth - m_DimX)/float(m_DimX),-float(iPotHeight - m_DimY)/float(m_DimY),-float(iPotDepth - m_DimZ)/float(m_DimZ));
00443 
00444                 m_ModelMatrix.scale(vecScale);
00445                 m_ModelMatrix.translate(vecTranslation);
00446         }
00447 
00448         int numVoxels = m_DimX * m_DimY * m_DimZ;
00449 
00450         std::vector<VVoxel> tmpData(numVoxels);
00451         m_VolumeData.resize(numVoxels);
00452 
00453         
00454         m_Histogram.clear();
00455         m_Histogram.resize(4096);
00456         m_maxdensity = 0.0f;
00457 
00458         for(int i = 0; i < m_DimZ; ++i)
00459         {
00460                 for(int j = 0; j < m_DimY; ++j)
00461                 {
00462                         for (int k = 0; k < m_DimX; ++k)
00463                         {
00464                                 float density;
00465                                 fread((void*)&density,sizeof(float),1,fp);
00466                                 float gradient[3];
00467                                 fread((void*)gradient,sizeof(float),3,fp);
00468                                 
00469                                 m_VolumeData[k + j * m_DimX + i * m_DimX * m_DimY] = VVoxel(density, VVector(gradient));
00470                         }
00471                 }
00472                 std::cout << "\rPreparing Data(" << (i*100)/(m_DimZ-1) << "%) ... ";
00473         }
00474 
00475         fread(reinterpret_cast<char*>(&m_Histogram[0]), sizeof(int), 4096,fp);
00476 
00477         m_maxdensity = 0.0f;
00478         for(int i = 256; i < 4096; ++i)
00479         {
00480                 if (m_Histogram[i] > m_maxdensity) 
00481                         m_maxdensity = m_Histogram[i];
00482         }
00483         
00484         unsigned int histsizex;
00485         unsigned int histsizey;
00486         unsigned int numchannel;
00487 
00488 
00489         fread(reinterpret_cast<char*>(&histsizex), sizeof(unsigned int), 1,fp);
00490         fread(reinterpret_cast<char*>(&histsizey), sizeof(unsigned int), 1,fp);
00491         fread(reinterpret_cast<char*>(&numchannel), sizeof(unsigned int), 1,fp);
00492 
00493         m_histogram2d_texture.clear();
00494         m_histogram2d_texture.resize(histsizex * histsizey * numchannel);
00495 
00496         fread(reinterpret_cast<char*>(&m_histogram2d_texture[0]), sizeof(unsigned char),histsizex * histsizey * numchannel, fp);
00497 
00498         fclose(fp);
00499         std::cout << std::endl << "Loading Volume Data Finished" << std::endl;
00500 
00501         data[3] = m_maxdensity;
00502 
00503         return (this->bindVolumeInOpenGL());
00504 }
00505 
00506 void VVolume::clear()
00507 {
00508         m_VolumeData.clear();
00509         m_Histogram.clear();
00510         if(m_GLVolumeHandle)
00511         {
00512                 glDeleteTextures(1,&m_GLVolumeHandle);
00513                 m_GLVolumeHandle = 0;
00514         }
00515 }
00516 
00517 void VVolume::flipVolumeX()
00518 {
00519         if(m_VolumeData.size() == 0)
00520         {
00521                 return;
00522         }
00523         std::vector<VVoxel> newVolume;
00524         newVolume.resize(m_VolumeData.size());
00525 
00526         for(int i = 0; i < m_DimZ; ++i)
00527         {
00528                 for(int j = 0; j < m_DimY; ++j)
00529                 {
00530                         for (int k = 0; k < m_DimX; ++k)
00531                         {
00532                                 newVolume[k + j * m_DimX + i * m_DimX * m_DimY] = m_VolumeData[(m_DimX - k - 1) + j * m_DimX + i * m_DimX * m_DimY];
00533                                 VVector gradient = newVolume[k + j * m_DimX + i * m_DimX * m_DimY].getGradient();
00534                                 gradient.setX(-gradient.getX());
00535                                 newVolume[k + j * m_DimX + i * m_DimX * m_DimY].setGradient(gradient);
00536                         }
00537                 }
00538                 std::cout << "\rPreparing Data(" << (i*100)/(m_DimZ-1) << "%) ... ";
00539         }
00540 
00541         m_VolumeData = newVolume;
00542         this->bindVolumeInOpenGL();
00543 }
00544 
00545 void VVolume::flipVolumeY()
00546 {
00547         if(m_VolumeData.size() == 0)
00548         {
00549                 return;
00550         }
00551         std::vector<VVoxel> newVolume;
00552         newVolume.resize(m_VolumeData.size());
00553 
00554         for(int i = 0; i < m_DimZ; ++i)
00555         {
00556                 for(int j = 0; j < m_DimY; ++j)
00557                 {
00558                         for (int k = 0; k < m_DimX; ++k)
00559                         {
00560                                 newVolume[k + j * m_DimX + i * m_DimX * m_DimY] = m_VolumeData[k + (m_DimY - j - 1) * m_DimX + i * m_DimX * m_DimY];
00561                                 VVector gradient = newVolume[k + j * m_DimX + i * m_DimX * m_DimY].getGradient();
00562                                 gradient.setY(-gradient.getY());
00563                                 newVolume[k + j * m_DimX + i * m_DimX * m_DimY].setGradient(gradient);
00564                         }
00565                 }
00566                 std::cout << "\rPreparing Data(" << (i*100)/(m_DimZ-1) << "%) ... ";
00567         }
00568 
00569         m_VolumeData = newVolume;
00570         this->bindVolumeInOpenGL();
00571 }
00572 
00573 void VVolume::flipVolumeZ()
00574 {
00575         if(m_VolumeData.size() == 0)
00576         {
00577                 return;
00578         }
00579         std::vector<VVoxel> newVolume;
00580         newVolume.resize(m_VolumeData.size());
00581 
00582         for(int i = 0; i < m_DimZ; ++i)
00583         {
00584                 for(int j = 0; j < m_DimY; ++j)
00585                 {
00586                         for (int k = 0; k < m_DimX; ++k)
00587                         {
00588                                 newVolume[k + j * m_DimX + i * m_DimX * m_DimY] = m_VolumeData[k + j * m_DimX + (m_DimZ - i - 1) * m_DimX * m_DimY];
00589                                 VVector gradient = newVolume[k + j * m_DimX + i * m_DimX * m_DimY].getGradient();
00590                                 gradient.setZ(-gradient.getZ());
00591                                 newVolume[k + j * m_DimX + i * m_DimX * m_DimY].setGradient(gradient);
00592                         }
00593                 }
00594                 std::cout << "\rPreparing Data(" << (i*100)/(m_DimZ-1) << "%) ... ";
00595         }
00596 
00597         m_VolumeData = newVolume;
00598         this->bindVolumeInOpenGL();
00599 }

Generated on Wed Dec 5 05:15:09 2007 for VolRendering by  doxygen 1.5.4