Eigene Dateien/uni/visualisierung/vislu/bsp1/VisLu/VObject.cpp

Go to the documentation of this file.
00001 #include "VObject.h"
00002 
00003 VObject::VObject(){
00004 }
00005 
00006 void VObject::load(string _filename){
00007 
00008         if (VolumeTex != 0){
00009                 glDeleteTextures(1,&VolumeTex);
00010         }
00011         
00012         direction = 0;
00013         sliceNo = -1;
00014         chSlice = new int(0.0f);
00015         
00016         unsigned short *volumeData;
00017         
00018         FILE * pFile;
00019         pFile = fopen(_filename.c_str(),"rb");
00020         
00021         if (pFile == NULL){
00022                 exit(1);
00023         }
00024         /*
00025         char charX [2], charY[2], charZ[2];
00026         
00027         fgets(charX,3,pFile);
00028         fgets(charY,3,pFile);
00029         fgets(charZ,3,pFile);
00030         
00031         unsigned short sizeX = *charX;
00032         unsigned short sizeY = *charY;
00033         unsigned short sizeZ = *charZ;
00034         */
00035         unsigned short sizeX = getc(pFile);
00036                                         sizeX |= getc(pFile) << 8;
00037         unsigned short sizeY = getc(pFile);
00038                                         sizeY |= getc(pFile) << 8;
00039         unsigned short sizeZ = getc(pFile);
00040                                         sizeZ |= getc(pFile) << 8;
00041         
00042         int twoSizeX = getPowerofTwo(sizeX);
00043         int twoSizeY = getPowerofTwo(sizeY);
00044         int twoSizeZ = getPowerofTwo(sizeZ);
00045         //      volumeData = new float[sizeX*sizeY*sizeZ*4];
00046         // volumeData = new float[twoSizeX*twoSizeY*twoSizeZ*4];
00047         volumeData = new unsigned short[twoSizeX*twoSizeY*twoSizeZ];
00048         histogram = new int[4096];
00049         
00050         int i = 0;
00051         
00052         for(int arrayCount = 0; arrayCount < 4096; arrayCount++){
00053                 histogram[arrayCount] = 0;
00054         }
00055         
00056         for(int z=0; z < twoSizeZ; z++) 
00057         {                
00058                 //iterate over the volume
00059                 for(int y=0; y < twoSizeY; y++)
00060                 {       
00061                         for(int x=0; x < twoSizeX; x++)
00062                         {       
00063                                 if ((x>=sizeX) || (y>=sizeY) || (z>=sizeZ)){
00064                                         volumeData[i] = 0;
00065                                         }
00066                                 else {                                  
00067                                         unsigned short integer = getc(pFile);
00068                                         integer |= getc(pFile) << 8;
00069                                         
00070                                         (histogram[integer])++;
00071                                         volumeData[i] = integer;
00072                                         }
00073                                 i++;
00074                         }       
00075                 }       
00076         }
00077         
00078         fclose(pFile);
00079         
00080         glGenTextures(1, &VolumeTex);
00081         glBindTexture(GL_TEXTURE_3D, VolumeTex);
00082         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP);
00083         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP);
00084         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP);
00085         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00086         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
00087         
00088         glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE, twoSizeX, twoSizeY, twoSizeZ, 0, GL_LUMINANCE, GL_UNSIGNED_SHORT, volumeData);
00089         
00090         //glTexImage3D(GL_TEXTURE_3D, 0, 4, twoSizeX, twoSizeY, twoSizeZ, 0, GL_RGBA, GL_FLOAT, volumeData);
00091                 
00092         delete[] volumeData;
00093 }
00094 
00095 void VObject::draw(){
00096 
00097         sliceNo += *chSlice;
00098         glEnable(GL_BLEND);
00099         glBlendFunc(GL_SRC_ALPHA,GL_DST_ALPHA);
00100         
00101         glEnable(GL_TEXTURE_3D);
00102         glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
00103         
00104         glBindTexture(GL_TEXTURE_3D, VolumeTex);
00105         float count = 64.0f;
00106         if (sliceNo >= count)
00107                         sliceNo = count;
00108         else if (sliceNo < 0)
00109                         sliceNo =-1;
00110         glRotatef(-90,1,0,0);
00111         /*
00112          glBegin(GL_QUADS);
00113          glTexCoord3d( 0.0, 0.0, 0.3);
00114          glVertex3d(0.0, 0.0,0.3);
00115          glTexCoord3d(0.0, 1.0,0.3);
00116          glVertex3d(0.0, 1.0,0.3);
00117          glTexCoord3d(1.0, 1.0, 0.3);
00118          glVertex3d(1.0, 1.0, 0.3);
00119          glTexCoord3d(1.0, 0.0, 0.3);
00120          glVertex3d(1.0, 0.0, 0.3);
00121          glEnd();
00122          */     
00123         if ((direction == 0) || (sliceNo == -1)){
00124                 for (int i = 0; i < count; i++){
00125                         glBegin(GL_QUADS);
00126                         glTexCoord3d( 0.0, 0.0, (float)i/count);
00127                         glVertex3d(0.0, 0.0,(float)i/count);
00128                         glTexCoord3d(0.0, 1.0, (float)i/count);
00129                         glVertex3d(0.0, 1.0, (float)i/count);
00130                         glTexCoord3d(1.0, 1.0, (float)i/count);
00131                         glVertex3d(1.0, 1.0, (float)i/count);
00132                         glTexCoord3d(1.0, 0.0, (float)i/count);
00133                         glVertex3d(1.0, 0.0, (float)i/count);
00134                         glEnd();
00135                 }
00136         }
00137         else if (direction == 1){
00138                 glBegin(GL_QUADS);
00139                 glTexCoord3d( (float)sliceNo/count,0.0, 0.0);
00140                 glVertex3d((float)sliceNo/count,0.0, 0.0);
00141                 glTexCoord3d((float)sliceNo/count, 1.0, 0.0);
00142                 glVertex3d((float)sliceNo/count,1.0, 0.0);
00143                 glTexCoord3d((float)sliceNo/count,1.0, 1.0);
00144                 glVertex3d((float)sliceNo/count,1.0, 1.0);
00145                 glTexCoord3d((float)sliceNo/count,0.0, 1.0);
00146                 glVertex3d((float)sliceNo/count,0.0, 1.0);
00147                 glEnd();                        
00148         }
00149         
00150         else if (direction == 2){
00151                 glBegin(GL_QUADS);
00152                 glTexCoord3d( 0.0,(float)sliceNo/count, 0.0);
00153                 glVertex3d(0.0, (float)sliceNo/count, 0.0);
00154                 glTexCoord3d(1.0, (float)sliceNo/count, 0.0);
00155                 glVertex3d(1.0, (float)sliceNo/count, 0.0);
00156                 glTexCoord3d(1.0, (float)sliceNo/count, 1.0);
00157                 glVertex3d(1.0, (float)sliceNo/count, 1.0);
00158                 glTexCoord3d(0.0, (float)sliceNo/count, 1.0);
00159                 glVertex3d(0.0, (float)sliceNo/count, 1.0);
00160                 glEnd();
00161         }
00162         else if (direction == 3){
00163                 glBegin(GL_QUADS);
00164                 glTexCoord3d( 0.0,0.0,(float)sliceNo/count);
00165                 glVertex3d(0.0, 0.0,(float)sliceNo/count);
00166                 glTexCoord3d(1.0, 0.0,(float)sliceNo/count);
00167                 glVertex3d(1.0, 0.0,(float)sliceNo/count);
00168                 glTexCoord3d(1.0, 1.0,(float)sliceNo/count);
00169                 glVertex3d(1.0, 1.0,(float)sliceNo/count);
00170                 glTexCoord3d(0.0, 1.0,(float)sliceNo/count);
00171                 glVertex3d(0.0, 1.0,(float)sliceNo/count);
00172                 glEnd();
00173         }
00174         glDisable(GL_TEXTURE_3D);
00175         /*
00176          int count1 = 0;
00177          int count2 = 0;
00178          int count3 = 0;
00179          
00180          for (int i = 0; i < points.size(); ++i){
00181                  //TODO: Transferfkt
00182                  if (points[i]->density <= 50000){
00183                          glColor4fv(Color1);
00184                          count2++;
00185                  }
00186                  else {
00187                          glColor4fv(Color3);
00188                          count3++;
00189                          glBegin(GL_POINTS);
00190                          glVertex3f((points[i]->x),(points[i]->y),(points[i]->z));
00191                          glEnd();
00192                  }
00193                  
00194          }
00195          */
00196 }
00197 
00198 int* VObject::getHistogram(void){
00199         return histogram;
00200 }
00201 
00202 void VObject::setDirection(int dir){
00203         direction = dir;
00204 }
00205 
00206 int VObject::getDirection(void){
00207         return direction;
00208 }
00209 
00210 void VObject::setsliceNo(int slice){
00211         sliceNo = slice;
00212 }
00213 
00214 int* VObject::getsliceNo(void){
00215         return this->chSlice;
00216 }
00217 
00218 void VObject::changesliceNo(int ch){
00219         sliceNo += ch;
00220 }
00221 
00222 int VObject::getPowerofTwo(int _n){
00223         int i = 0;
00224         while (pow(2.0f,i) < _n){
00225                 i++;
00226         }
00227         return pow(2.0f,i);
00228 }
00229 
00230 VObject::~VObject(){
00231 }

Generated on Wed Dec 6 11:07:59 2006 for VisLU by  doxygen 1.5.1-p1