Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

vpvolume.cpp

Go to the documentation of this file.
00001 //deprecated
00003 //
00004 //  PROJECT.....: vpat - Creating Virtual Patients
00005 //  RESPONSIBLE.: Carla Freitas e Luciana Nedel
00006 //
00007 //  FILE........: vpvolume.cpp
00008 //  DESCRIPTION.: Contain the VPVolume class implementation.
00009 //
00010 //  AUTHOR......: Isabel Harb Manssour
00011 //  DATE........: November/13/2000
00012 //  DESCRIPTION.: Implementation and changes of some methods.
00013 //
00014 //  AUTHOR......: Isabel Harb Manssour
00015 //  DATE........: January/16/2000
00016 //  DESCRIPTION.: Inclusion and changes of some methods for 
00017 //                dynamical image window allocation.
00018 //
00019 //  AUTHOR......: Isabel Harb Manssour
00020 //  DATE........: June/04/2001
00021 //  DESCRIPTION.: Inclusion and changes of some methods to 
00022 //                identify the active camera, which is 
00023 //                determined by the view, and to get/set
00024 //                some attributes.
00025 //
00026 //  AUTHOR......: Isabel Harb Manssour
00027 //  DATE........: October/28/2002
00028 //  DESCRIPTION.: Inclusion and changes of some methods to 
00029 //                implement Gouraud shading.Code "adjust".
00030 //
00032 
00033 
00034 #include <vpvolume.h>
00035 #include <iostream>
00036 #include <cmath>
00037 #include <string>   //STL include
00038 using namespace std;
00039 
00040 
00042 // Description: Class "VPVolume" constructor without parameter. 
00043 // Parameters.: -
00044 // Return.....: -
00045 
00046 VPVolume::VPVolume () {
00047         zDimension = maxVolumeColor = 0;
00048         fileType = NONE;
00049         visualizationType = DEFAULTVIS;
00050         opacityComputation = LINEAROPAC;
00051         topSlice = 1;
00052         sideSlice = 1;
00053         frontSlice = 1;
00054         maxVolumeColor = 255;
00055         minVolumeColor = 0;
00056         grayImage = NULL;
00057         colorImage = NULL;
00058         activeCamera = NULL;
00059         volumeMatrix = NULL;
00060         volumeLightedMatrix = NULL;
00061 }
00062 
00063 
00065 // Description: Class "VPVolume" constructor with parameters for
00066 //              monomodal visualization.
00067 // Parameters.: char *n (path and file name)
00068 //              int t (file type - constant MRI,CT...)
00069 //              int dh (horizontal slice dimension)
00070 //              int dv (vertical slice dimension)
00071 //              int s (slice number)
00072 //              int b (number of bits/pixel)
00073 // Return.....: -
00074 
00075 VPVolume::VPVolume (const char *n, int t, int dh, int dv, int s, int b) {
00076 
00077   // local variables
00078   int i=0, j=0, k=0, d=0; 
00079   float valTmp=0;
00080   const char *aux;
00081   char extension[4] = {'\0'},
00082        description[100] = {'\0'},
00083        file[20] = {'\0'}, 
00084        path[70] = {'\0'};
00085 
00086   // Initialize some atributes
00087   grayImage = NULL;
00088   colorImage = NULL;
00089   activeCamera = NULL;
00090   maxVolumeColor = 0;
00091   maxVolumeColor = 0;
00092   minVolumeColor = 4095;
00093 
00094   // Set other attributes in accordance with the parameters
00095   fileType = t;
00096   visualizationType = DEFAULTVIS;
00097   opacityComputation = LINEAROPAC;
00098   fileBits = b;
00099   xDimension = dh;
00100   yDimension = s; 
00101   zDimension = dv;
00102 
00103 
00104   // Check file format in accordance with the file extension
00105   int baka=0;
00106   aux = n;
00107   while ( (*aux != '.') && (*aux) ) {
00108             aux++;
00109             baka++;
00110   }
00111   if (aux != NULL) {
00112             aux++;
00113             baka++;
00114             strcat(extension, aux);
00115   }  // else TRATAMENTO DE ERRO/EXCEÇÃO
00116 
00117   // Set the file path 
00118   while ( (*aux != '\\') && (*aux) ) {
00119             aux--;
00120             baka--;
00121   }
00122   baka++;
00123   strncpy(path, n, baka);
00124 
00125   // set the superclass attribute "description"
00126   strcpy(description, n);
00127   switch (fileType) {
00128             case ARQCT: strcat(description, ", CT data.");
00129                         break;
00130             case ARQMRI:strcat(description, ", MRI data.");
00131                         break;
00132             case ARQPET:strcat(description, ", PET data.");
00133                         break;
00134             case ARQSPECT:strcat(description, ", SPECT data.");
00135                         break;
00136   }
00137 
00138   if ( !strcmp (extension,"raw") ) { 
00139               // finish to set the superclass attribute "description"
00140               strcat(description, ", raw file");
00141               vpSetDescription(description);
00142               // to read the file .raw
00143               vpReadRawFile(n);
00144   }
00145 
00146   else if ( !strcmp(extension,"i") ) { 
00147               // finish to set the superclass attribute "description"
00148               strcat(description, ", i file");
00149               vpSetDescription(description);
00150               // to read the files .i
00151               vpReadIFile(n, path);
00152   }
00153           
00154   else if ( !strcmp(extension,"vol") ) { 
00155               // finish to set the superclass attribute "description"
00156               strcat(description, ", vol file");
00157               vpSetDescription(description);
00158               // to read the file .vol
00159               vpReadVolFile(n);
00160   }
00161           
00162   else { 
00163   }
00164 
00165   topSlice = (int) yDimension/2;
00166   sideSlice = (int) xDimension/2;
00167   frontSlice = (int) zDimension/2;
00168 
00169   controlTables.vpSetMinVolumeDensity(minVolumeColor); 
00170   controlTables.vpSetMaxVolumeDensity(maxVolumeColor); 
00171   controlTables.vpProcessMaxGradient();
00172 
00173   vpProcessCenterFocalPoint();
00174   vpProcessHistogram();
00175 }
00176 
00177 
00179 // Description: Method used to read raw file.
00180 // Parameters.: -
00181 // Return.....: -
00182 
00183 void VPVolume::vpReadRawFile(const char *n) {
00184       int i=0, j=0, k=0;
00185       unsigned char aux1, aux2;
00186       FILE *fp;
00187 
00188       // Memory allocation for data loading
00189       allocMemory();
00190       allocMemory2();
00191  
00192       // File opening
00193       fp = fopen(n,"rb");
00194       if ( fp == NULL ) {
00195             perror ("Unable to read dataset file."); 
00196             return;
00197       }
00198 
00199       switch (fileBits) {
00200          case 8:
00201             for (k=0; k<yDimension; k++) {
00202                 for (i=0; i<zDimension; i++) {
00203                     // Density read
00204                     for (j=0; j<xDimension; j++) {
00205                         // Read the density
00206                         fread(&aux1, 1, 1, fp);
00207                         volumeMatrix2[j][k][i] = (unsigned int) aux1;
00208                         if (volumeMatrix2[j][k][i] > maxVolumeColor) maxVolumeColor=volumeMatrix2[j][k][i];
00209                         if (volumeMatrix2[j][k][i] < minVolumeColor) minVolumeColor=volumeMatrix2[j][k][i];
00210                     }
00211                 }
00212             }   
00213             break;
00214          case 16:
00215             for (k=0; k<yDimension; k++) {
00216                 for (i=0; i<zDimension; i++) {
00217                     // Density read
00218                     for (j=0; j<xDimension; j++) {
00219                         // Read the density
00220                         fread(&aux1, 1, 1, fp);
00221                         fread(&aux2, 1, 1, fp);
00222                         volumeMatrix2[j][k][i] = (unsigned int) (aux1*256) + aux2;
00223                         if (volumeMatrix2[j][k][i] > maxVolumeColor) maxVolumeColor=volumeMatrix2[j][k][i];
00224                         if (volumeMatrix2[j][k][i] < minVolumeColor) minVolumeColor=volumeMatrix2[j][k][i];
00225                     }
00226                 }
00227             }   
00228             break;
00229       } // switch
00230 
00231       fclose(fp);
00232 
00233       for (j=0; j<yDimension; j++)
00234         for (i=0; i<xDimension; i++)
00235             for (k=0; k<zDimension; k++)
00236                 volumeMatrix[i][j][k] = volumeMatrix2[i][yDimension-1-j][k];
00237 
00238       delete [] volumeMatrix2;
00239 
00240 
00241 }
00242 
00243 
00245 // Description: Method used to read .i files.
00246 // Parameters.: -
00247 // Return.....: -
00248 
00249 void VPVolume::vpReadIFile(const char *n, char *p) {
00250       int i=0, j=0, k=0;
00251       char file[20] = {'\0'}, 
00252            pathFile[70] = {'\0'};
00253       unsigned char aux1, aux2;
00254       FILE *fp, *filesNames;
00255 
00256       // Memory allocation for data loading
00257       allocMemory();
00258 
00259       // First open the file that has the name of all slices files
00260       filesNames = fopen(n,"r");
00261       if ( filesNames == NULL ) {
00262             perror ("Unable to read dataset file."); 
00263             return;
00264       }
00265 
00266       switch (fileBits) {
00267          case 8:
00268                   for (k=0; k<yDimension; k++) {
00269                     fscanf(filesNames,"%s\n", file); // slice file name
00270                     strcpy(pathFile,p);
00271                     strcat(pathFile, file);
00272                     fp = fopen (pathFile, "rb");
00273                     if ( fp == NULL ) {
00274                         perror ("Unable to read dataset file."); 
00275                         return;
00276                     }
00277                     fread(&aux1, 1, 1, fp);
00278                     fread(&aux2, 1, 1, fp); // image width
00279                     fread(&aux1, 1, 1, fp);
00280                     fread(&aux2, 1, 1, fp); // imagem height
00281                     for (i=0; i<zDimension; i++) {
00282                         // Density read - JUST FOR 8 BITS!!!
00283                         for (j=0; j<xDimension; j++) {
00284                             // Read the density
00285                             fread(&aux1, 1, 1, fp);
00286                             volumeMatrix[j][k][i] = (unsigned int) aux1;
00287                             if (volumeMatrix[j][k][i] > maxVolumeColor) maxVolumeColor=volumeMatrix[j][k][i];
00288                             if (volumeMatrix[j][k][i] < minVolumeColor) minVolumeColor=volumeMatrix[j][k][i];
00289                         }
00290                     }
00291                     fclose(fp);
00292                   } 
00293                     break;
00294          case 16:
00295                   for (k=0; k<yDimension; k++) {
00296                     fscanf(filesNames,"%s\n", file); // slice file name
00297                     strcpy(pathFile,p);
00298                     strcat(pathFile, file);
00299                     fp = fopen (pathFile, "rb");
00300                     if ( fp == NULL ) {
00301                         perror ("Unable to read dataset file."); 
00302                         return;
00303                     }
00304                     for (i=0; i<zDimension; i++) {
00305                         for (j=0; j<xDimension; j++) {
00306                             // Read the density
00307                             fread(&aux1, 1, 1, fp);
00308                             fread(&aux2, 1, 1, fp);
00309                             volumeMatrix[j][k][i] = (unsigned int) (aux1*256) + aux2; // para brain.i
00310                             // volumeMatrix[j][k][i] = (unsigned int) ( (aux2*256) + aux1 ) / 256; // para tooth.i
00311                             if (volumeMatrix[j][k][i] > maxVolumeColor) maxVolumeColor=volumeMatrix[j][k][i];
00312                             if (volumeMatrix[j][k][i] < minVolumeColor) minVolumeColor=volumeMatrix[j][k][i];
00313                         }
00314                     }
00315                     fclose(fp);
00316                   } 
00317                   break;
00318       }
00319 
00320       fclose(filesNames);
00321 
00322 }
00323 
00324 
00326 // Description: Method used to read .vol files.
00327 // Parameters.: -
00328 // Return.....: -
00329 
00330 void VPVolume::vpReadVolFile(const char *n) {
00331       #define SEEK_SET 0
00332       int i=0, j=0, k=0;
00333       FILE *fp;
00334       xyz VolumeDimensions, Size;
00335       int   N;
00336       int NBytes;
00337       unsigned char *V8;
00338       sword *V16, V, Ib; // tipo sword
00339       int x1, y1; //z1;
00340       int MagicNumber;
00341       int HeaderLength;
00342       int         PixelDepth;
00343       int         PixelType;         // type
00344       int         IndexBits;         // number of "object" index bits in each pixel                 */
00345       float       ScaleX;            // base scale factors
00346       float       ScaleY;
00347       float       ScaleZ;
00348       float       RotX;              // base rotation
00349       float       RotY;
00350       float       RotZ;
00351       int         totalDepth;
00352 
00353 
00354       // File opening
00355       fp = fopen(n,"rb");
00356       if ( fp == NULL ) {
00357             perror ("Unable to read dataset file."); 
00358             return;
00359       }
00360 
00361 
00362       fread((void *)&MagicNumber, sizeof(int), 1, fp);
00363       vpSwapBytes(&MagicNumber, sizeof(int));
00364 
00365       if ((MagicNumber != C_VR_MAGIC_NUMBER) &&
00366             (MagicNumber != C_VR_MAGIC_NUMBER_OLD)) {
00367         //  return -2;
00368       }
00369       fread((void *)&HeaderLength , sizeof(int), 1, fp);
00370       fread((void *)&VolumeDimensions , sizeof(xyz), 1, fp);
00371       fread((void *)&PixelDepth , sizeof(int), 1, fp);
00372       fread((void *)&IndexBits, sizeof(int), 1, fp);
00373 
00374       vpSwapBytes ((int *)&HeaderLength, sizeof(int));
00375       vpSwapBytes ((int *)&VolumeDimensions, sizeof(xyz));
00376       vpSwapBytes ((int *)&PixelDepth,sizeof(int));
00377       vpSwapBytes ((int *)&IndexBits, sizeof(int));
00378 
00379 
00380       // Set some volume attributes in accordance with the data read
00381       xDimension = VolumeDimensions.x;
00382       yDimension = VolumeDimensions.z; 
00383       zDimension = VolumeDimensions.y;
00384 
00385       // Memory allocation for data loading
00386       allocMemory();
00387 
00388 
00389       PixelDepth -= IndexBits;
00390       if(MagicNumber == C_VR_MAGIC_NUMBER) {
00391         fread((void *)&ScaleX , sizeof(float), 1, fp);
00392         fread((void *)&ScaleY , sizeof(float), 1, fp);
00393         fread((void *)&ScaleZ , sizeof(float), 1, fp);
00394         fread((void *)&RotX , sizeof(float), 1, fp);
00395         fread((void *)&RotY , sizeof(float), 1, fp);
00396         fread((void *)&RotZ , sizeof(float), 1, fp);
00397         vpSwapBytes ((int *)&ScaleX, sizeof(float));
00398         vpSwapBytes ((int *)&ScaleY, sizeof(float));
00399         vpSwapBytes ((int *)&ScaleZ, sizeof(float));
00400         vpSwapBytes ((int *)&RotX, sizeof(float));
00401         vpSwapBytes ((int *)&RotY, sizeof(float));
00402         vpSwapBytes ((int *)&RotZ, sizeof(float));
00403       } else {
00404         ScaleX = 1.0;
00405         ScaleY = 1.0;
00406         ScaleZ = 1.0;
00407         RotX = 0.0;
00408         RotY = 0.0;
00409         RotZ = 0.0;
00410       } // else
00411 
00412 
00413       fseek(fp, HeaderLength, SEEK_SET);
00414 
00415       totalDepth = PixelDepth + IndexBits;
00416 
00417       switch(totalDepth) {
00418         case 8:
00419             PixelType = C_UNSIGNED_BYTE;
00420             break;
00421         case 16:
00422             if(IndexBits == 0) {
00423                 PixelType = C_UNSIGNED_SHORT;
00424             } else if (IndexBits == 4) {
00425                 PixelType = C_UNSIGNED_SHORT;
00426             } else if (IndexBits == 8) {
00427                 PixelType = C_UNSIGNED_SHORT;
00428             } else {
00429              //   return -3;
00430             } // else
00431           break;
00432         //  default:
00433        //  return -3;
00434       } // switch
00435 
00436       // determine the size of the dataset 
00437       if (PixelType == C_UNSIGNED_BYTE) {
00438             NBytes = 1;
00439       } else {
00440             NBytes = 2;
00441       }
00442 
00443        if(NBytes == 1) {
00444           N = 1;
00445           if(RotY == 0.0 && RotZ == 0.0) {
00446              if(RotX == 0) {
00447                 Size.x = yDimension;
00448                 Size.y = zDimension;
00449                 Size.z = xDimension;
00450                 V8 = new unsigned char[Size.y];
00451                 for(j=0; j<Size.x; j++) {
00452                    for(k=0; k<Size.z; k++) {
00453                        fread(&V8[0], NBytes, Size.y, fp);
00454                        y1 = Size.y-1;
00455                     for(i=0; i<Size.y; i++) {
00456                          volumeMatrix[k][j][i] = V8[y1];
00457                          if(V8[y1] > maxVolumeColor) 
00458                             maxVolumeColor = V8[y1];
00459                          else if(V8[y1] < minVolumeColor)
00460                             minVolumeColor = V8[y1];
00461                          y1--;
00462                       } // for i
00463                    } // for k
00464                 } // for j
00465              } // if RotX == 0.0
00466              else if(RotX == -90.0) {
00467                 Size.x = VolumeDimensions.y;
00468                 Size.y = VolumeDimensions.x;
00469                 Size.z = VolumeDimensions.z;
00470                 V8 = new unsigned char[Size.x];
00471                 for(k = Size.z-1; k >= 0; k--) {
00472                    for(i = Size.y-1; i >= 0; i--) {
00473                        fread(&V8[0], NBytes, Size.x, fp);
00474                        x1 = Size.x-1;
00475                        for(j = 0; j < Size.x; j++) {
00476                          volumeMatrix[j][k][i] = V8[x1];
00477                          if(V8[x1] > maxVolumeColor) 
00478                             maxVolumeColor = V8[x1];
00479                          else if(V8[x1] < minVolumeColor)
00480                             minVolumeColor = V8[x1];
00481                          x1--;
00482                        } // for j
00483                    } // for i
00484                 } // for k
00485              } // else
00486           } // if
00487           delete[] V8;
00488        } else {
00489           N = 1; // DOESN´T WORK!?!?!?
00490                 //Size.X = VolumeDimensions.z;
00491                 //Size.Y = VolumeDimensions.y;
00492                 //Size.Z = VolumeDimensions.x;
00493                 //AdjustScale(XYZR(ScaleZ, ScaleY, ScaleX));
00494                 //Alloc();
00495                 V16 = new sword[yDimension+1];
00496                 for(j=0; j<xDimension; j++) {
00497                    for(k=0; k<yDimension; k++) {
00498                        fread(&V16[1], NBytes, yDimension, fp);
00499                       y1 = yDimension;
00500                     for(i=0; i<zDimension; i++) {
00501                          V = (sword)((V16[y1] & (sword)0xFF00) >> 8);
00502                          Ib = (sword)((V16[y1] & (sword)0x03) << 4);      
00503                          if(Ib != 0)
00504                              volumeMatrix[j][k][i] = (sword)(V | (Ib << 8));                   
00505                          else
00506                              volumeMatrix[j][k][i] = V;                   
00507                          y1--;
00508                          if(V > maxVolumeColor)
00509                             maxVolumeColor = V;
00510                          else if(V < minVolumeColor)
00511                             minVolumeColor = V;
00512                       } // for x
00513                    } // for y
00514                 } // for z
00515           delete[] V16;
00516        } // if
00517 
00518       fclose(fp);
00519 
00520       // Auxiliary memory allocation for data loading
00521       allocMemory2();
00522 
00523       for (j=0; j<yDimension; j++)
00524         for (i=0; i<xDimension; i++)
00525             for (k=0; k<zDimension; k++)
00526                 volumeMatrix2[i][j][k] = volumeMatrix[i][yDimension-1-j][k];
00527 
00528       delete [] volumeMatrix;
00529 
00530       volumeMatrix = volumeMatrix2;
00531 }
00532 
00533 
00535 // Description: Method used to allocate memory to put the volume 
00536 //              data set and to put the light voxel information.  
00537 //              The space is allocated acording to the xDimension, 
00538 //              yDimension and zDimension attributes.
00539 // Parameters.: -
00540 // Return.....: bool (false if it doesn't allocate the necessary
00541 //                    memory)
00542 
00543 bool VPVolume::allocMemory() {
00544 
00545  int i, j;
00546 //  Incluir tratamento de exceções!!!
00547 
00548 
00549  // Volume matrix allocation
00550  volumeMatrix = (unsigned int ***) new unsigned short int **[sizeof(unsigned short int **) * xDimension]; 
00551  if (volumeMatrix == NULL)
00552     return false;
00553 
00554  for (i=0; i<xDimension; i++) {
00555     volumeMatrix[i] = (unsigned int **) new unsigned short int *[sizeof(unsigned short int *) * yDimension];
00556     if (volumeMatrix[i] == NULL)
00557         return false;
00558 
00559     for (j=0; j<yDimension; j++) {
00560         volumeMatrix[i][j] = new unsigned int[sizeof(unsigned short int) * zDimension];
00561         if (volumeMatrix[i][j] == NULL)
00562             return false;
00563     }
00564  }
00565 
00566  // "Light" matrix allocation
00567  volumeLightedMatrix = (unsigned char ***) new unsigned char **[sizeof(unsigned char **) * xDimension]; 
00568  if (volumeLightedMatrix == NULL)
00569     return false;
00570 
00571  for (i=0; i<xDimension; i++) {
00572     volumeLightedMatrix[i] = (unsigned char **) new unsigned char *[sizeof(unsigned char *) * yDimension];
00573     if (volumeLightedMatrix[i] == NULL)
00574         return false;
00575 
00576     for (j=0; j<yDimension; j++) {
00577         volumeLightedMatrix[i][j] = new unsigned char[sizeof(unsigned char) * zDimension];
00578         if (volumeLightedMatrix[i][j] == NULL)
00579             return false;
00580     }
00581  }
00582 
00583  return true;
00584 
00585 }
00586 
00587 
00588 bool VPVolume::allocMemory2() {
00589 
00590  int i, j;
00591 //  Incluir tratamento de exceções!!!
00592 
00593 
00594  // Volume matrix allocation
00595  volumeMatrix2 = (unsigned int ***) new unsigned short int **[sizeof(unsigned short int **) * xDimension]; 
00596  if (volumeMatrix2 == NULL)
00597     return false;
00598 
00599  for (i=0; i<xDimension; i++) {
00600     volumeMatrix2[i] = (unsigned int **) new unsigned short int *[sizeof(unsigned short int *) * yDimension];
00601     if (volumeMatrix2[i] == NULL)
00602         return false;
00603 
00604     for (j=0; j<yDimension; j++) {
00605         volumeMatrix2[i][j] = new unsigned int[sizeof(unsigned short int) * zDimension];
00606         if (volumeMatrix2[i][j] == NULL)
00607             return false;
00608     }
00609  }
00610 
00611  // "Light" matrix allocation
00612  volumeLightedMatrix = (unsigned char ***) new unsigned char **[sizeof(unsigned char **) * xDimension]; 
00613  if (volumeLightedMatrix == NULL)
00614     return false;
00615 
00616  for (i=0; i<xDimension; i++) {
00617     volumeLightedMatrix[i] = (unsigned char **) new unsigned char *[sizeof(unsigned char *) * yDimension];
00618     if (volumeLightedMatrix[i] == NULL)
00619         return false;
00620 
00621     for (j=0; j<yDimension; j++) {
00622         volumeLightedMatrix[i][j] = new unsigned char[sizeof(unsigned char) * zDimension];
00623         if (volumeLightedMatrix[i][j] == NULL)
00624             return false;
00625     }
00626  }
00627 
00628  return true;
00629 
00630 }
00631 
00633 // Description: Class "VPVolume" destructor.
00634 // Parameters.: -
00635 // Return.....: -
00636 
00637 VPVolume::~VPVolume () {
00638     delete [] volumeMatrix;
00639     delete [] volumeLightedMatrix;
00640 }
00641 
00642 
00644 // Description: Method "vpProcessLightedVolume" do the volume
00645 //              gradients processing.
00646 //              .
00647 // Parameters.: VPVector3D ld - light direction
00648 //              float al - ambient light
00649 // Return.....: -
00650 
00651 void VPVolume::vpProcessLightedVolume(VPVector3D ld, float al) {
00652 
00653     int i, j, k, intLight;
00654     float dot=0, light=0;
00655     VPVector3D gradient, previousGradient, maxGradient;
00656 
00657     for (j=0; j<yDimension; j++) {
00658         for (k=0; k<zDimension; k++) {
00659             previousGradient.x=0; previousGradient.y=0; previousGradient.z=0;
00660             for (i=0; i<xDimension; i++) {
00661 
00662                 previousGradient = gradient;
00663                 
00664                 // Gradient calculation uses the Sobel three-dimensional operator 
00665                  gradient = vpGetSobelGradient(i, j, k);
00666 
00667                 gradient.vpNormalize();
00668 
00669                 // Next steps: lighting processing
00670 
00671                 // Dot product between the gradient and the light direction
00672                 dot = gradient.vpDotProduct(ld); 
00673           
00674                 if (dot < 0.0)
00675                     dot = (float) 0.0;  // no negative contributions
00676 
00677                 light = al + (0.9 * dot); // 0.9 = diffuse
00678 
00679                 if (light > 1) 
00680                     light = 1;
00681 
00682                 // One byte to load light value: 
00683                 //  7 bits for the color and 1 bit for the flag
00684 
00685                 // Color (light value): 0-100
00686                 intLight = floor ( (light * 100) + 0.5 ); // "+0.5" to round light value
00687 
00688                 // flag = 1 (true) if the 8 neighbor voxels have the same intensity
00689                 // flag = 0 (false) if the 8 neighbor voxels don't have the same intensity
00690                 // Set the bit flag if the 8 neighbor voxels have the same intensity
00691                 // if (8 neighbor have the same value)
00692                 // primeiro bit = 1
00693                 // "else" it's not necessary because the first bit is already 0
00694                 volumeLightedMatrix[i][j][k] = (unsigned char) intLight;
00695             }
00696         }
00697     }   
00698 
00699 }
00700 
00701 
00703 // Description: Method "vpGetSobelGradient" process and returns 
00704 //              Sobel gradient.
00705 // Parameters.: int i, int j, int k (matrix index)
00706 // Return.....: VPVector3D gradient
00707 
00708 VPVector3D VPVolume::vpGetSobelGradient(int i, int j, int k) 
00709 {
00710     int iMinus, jMinus, kMinus, iPlus, jPlus, kPlus, x, y, z;
00711     VPVector3D gradient;
00712 
00713     // For boundaries adjustment
00714     iPlus = ( (i+1) < xDimension ) ? i+1 : i;
00715     jPlus = ( (j+1) < yDimension ) ? j+1 : j;
00716     kPlus = ( (k+1) < zDimension ) ? k+1 : k;
00717     iMinus = ( (i-1) >= 0 ) ? i-1 : i;
00718     jMinus = ( (j-1) >= 0 ) ? j-1 : j;
00719     kMinus = ( (k-1) >= 0 ) ? k-1 : k;
00720 
00721     x = 6 * ( volumeMatrix[iMinus][j][k] - volumeMatrix[iPlus][j][k] ) +
00722         3 * ( volumeMatrix[iMinus][jMinus][k] + volumeMatrix[iMinus][jPlus][k] +
00723               volumeMatrix[iMinus][j][kPlus] + volumeMatrix[iMinus][j][kMinus] -
00724               volumeMatrix[iPlus][jMinus][k] - volumeMatrix[iPlus][jPlus][k] -
00725               volumeMatrix[iPlus][j][kPlus] - volumeMatrix[iPlus][j][kMinus]    ) +
00726         2 * ( volumeMatrix[iMinus][jMinus][kMinus] + volumeMatrix[iMinus][jMinus][kPlus] +
00727               volumeMatrix[iMinus][jPlus][kPlus] + volumeMatrix[iMinus][jPlus][kMinus] -
00728               volumeMatrix[iPlus][jMinus][kMinus] - volumeMatrix[iPlus][jMinus][kPlus] -
00729               volumeMatrix[iPlus][jPlus][kPlus] - volumeMatrix[iPlus][jPlus][kMinus]    );
00730 
00731     y = 6 * ( volumeMatrix[i][jMinus][k] - volumeMatrix[i][jPlus][k] ) +
00732         3 * ( volumeMatrix[i][jMinus][kMinus] + volumeMatrix[iMinus][jMinus][k] +
00733               volumeMatrix[iPlus][jMinus][k] + volumeMatrix[i][jMinus][kPlus] -
00734               volumeMatrix[i][jPlus][kMinus] - volumeMatrix[iMinus][jPlus][k] -
00735               volumeMatrix[iPlus][jPlus][k] - volumeMatrix[i][jPlus][kPlus]   ) +
00736         2 * ( volumeMatrix[iMinus][jMinus][kMinus] + volumeMatrix[iPlus][jMinus][kMinus] +
00737               volumeMatrix[iMinus][jMinus][kPlus] + volumeMatrix[iPlus][jMinus][kPlus] -
00738               volumeMatrix[iMinus][jPlus][kMinus] - volumeMatrix[iPlus][jPlus][kMinus] -
00739               volumeMatrix[iMinus][jPlus][kPlus] - volumeMatrix[iPlus][jPlus][kPlus] );
00740 
00741     z = 6 * (volumeMatrix[i][j][kMinus] - volumeMatrix[i][j][kPlus] ) +
00742         3 * (volumeMatrix[iMinus][j][kMinus] + volumeMatrix[iPlus][j][kMinus] +
00743              volumeMatrix[i][jPlus][kMinus] + volumeMatrix[i][jMinus][kMinus] -
00744              volumeMatrix[iMinus][j][kPlus] - volumeMatrix[iPlus][j][kPlus] -
00745              volumeMatrix[i][jPlus][kPlus] - volumeMatrix[i][jMinus][kPlus]    ) +
00746         2 * (volumeMatrix[iMinus][jMinus][kMinus] + volumeMatrix[iMinus][jPlus][kMinus] +
00747              volumeMatrix[iPlus][jPlus][kMinus] + volumeMatrix[iPlus][jMinus][kMinus] -
00748              volumeMatrix[iMinus][jMinus][kPlus] - volumeMatrix[iMinus][jPlus][kPlus] -
00749              volumeMatrix[iPlus][jPlus][kPlus] - volumeMatrix[iPlus][jMinus][kPlus] );
00750 
00751     gradient.x = (float) x / 26.0;
00752     gradient.y = (float) y / 26.0;
00753     gradient.z = (float) z / 26.0; 
00754 
00755     return gradient;
00756 }
00757 
00758 
00760 // Description: Method "vpGetLinearGradientEstimation" process and  
00761 //              returns the gradient estimation based on 4D linear
00762 //              regression.
00763 // Parameters.: int i, int j, int k (matrix index)
00764 // Return.....: VPVector3D gradient
00765 
00766 VPVector3D VPVolume::vpGetLinearGradientEstimation(int i, int j, int k) {
00767 
00768     int iMinus, jMinus, kMinus, iPlus, jPlus, kPlus;
00769     VPVector3D gradient;
00770 
00771     // For boundaries adjustment
00772     iPlus = ( (i+1) < xDimension ) ? i+1 : i;
00773     jPlus = ( (j+1) < yDimension ) ? j+1 : j;
00774     kPlus = ( (k+1) < zDimension ) ? k+1 : k;
00775     iMinus = ( (i-1) >= 0 ) ? i-1 : i;
00776     jMinus = ( (j-1) >= 0 ) ? j-1 : j;
00777     kMinus = ( (k-1) >= 0 ) ? k-1 : k;
00778 
00779     gradient.x = (float)
00780     - volumeMatrix[iMinus][j][k] //*  ( 1 / (sqrt( (i-iMinus)+(i-iMinus)  )) )
00781     - volumeMatrix[iMinus][j][kPlus] 
00782     - volumeMatrix[iMinus][j][kMinus]   
00783     - volumeMatrix[iMinus][jMinus][k]  
00784     - volumeMatrix[iMinus][jMinus][kPlus] 
00785     - volumeMatrix[iMinus][jMinus][kMinus] 
00786     - volumeMatrix[iMinus][jPlus][k] 
00787     - volumeMatrix[iMinus][jPlus][kPlus] 
00788     - volumeMatrix[iMinus][jPlus][kMinus]  
00789     + volumeMatrix[iPlus][j][k]  
00790     + volumeMatrix[iPlus][j][kPlus]  
00791     + volumeMatrix[iPlus][j][kMinus] 
00792     + volumeMatrix[iPlus][jMinus][k]  
00793     + volumeMatrix[iPlus][jMinus][kPlus]  
00794     + volumeMatrix[iPlus][jMinus][kMinus] 
00795     + volumeMatrix[iPlus][jPlus][k]  
00796     + volumeMatrix[iPlus][jPlus][kPlus] 
00797     + volumeMatrix[iPlus][jPlus][kMinus]  ;
00798 
00799     gradient.y = (float)
00800     - volumeMatrix[i][jMinus][k]  
00801     - volumeMatrix[i][jMinus][kPlus]   
00802     - volumeMatrix[i][jMinus][kMinus] 
00803     - volumeMatrix[iPlus][jMinus][k]  
00804     - volumeMatrix[iPlus][jMinus][kPlus]   
00805     - volumeMatrix[iPlus][jMinus][kMinus]  
00806     - volumeMatrix[iMinus][jMinus][k]  
00807     - volumeMatrix[iMinus][jMinus][kPlus]   
00808     - volumeMatrix[iMinus][jMinus][kMinus]   
00809     + volumeMatrix[i][jPlus][k] 
00810     + volumeMatrix[i][jPlus][kPlus] 
00811     + volumeMatrix[i][jPlus][kMinus] 
00812     + volumeMatrix[iMinus][jPlus][k] 
00813     + volumeMatrix[iMinus][jPlus][kPlus] 
00814     + volumeMatrix[iMinus][jPlus][kMinus] 
00815     + volumeMatrix[iPlus][jPlus][k] 
00816     + volumeMatrix[iPlus][jPlus][kPlus] 
00817     + volumeMatrix[iPlus][jPlus][kMinus] ;
00818 
00819     gradient.z = (float)
00820     - volumeMatrix[i][j][kMinus] 
00821     - volumeMatrix[i][jPlus][kMinus]  
00822     - volumeMatrix[i][jMinus][kMinus]  
00823     - volumeMatrix[iPlus][j][kMinus]  
00824     - volumeMatrix[iPlus][jPlus][kMinus]  
00825     - volumeMatrix[iPlus][jMinus][kMinus]  
00826     - volumeMatrix[iMinus][j][kMinus]  
00827     - volumeMatrix[iMinus][jMinus][kMinus] 
00828     - volumeMatrix[iMinus][jPlus][kMinus]  
00829     + volumeMatrix[i][j][kPlus]  
00830     + volumeMatrix[i][jPlus][kPlus]  
00831     + volumeMatrix[i][jMinus][kPlus]      
00832     + volumeMatrix[iPlus][j][kPlus] 
00833     + volumeMatrix[iPlus][jPlus][kPlus]  
00834     + volumeMatrix[iPlus][jMinus][kPlus] 
00835     + volumeMatrix[iMinus][j][kPlus]  
00836     + volumeMatrix[iMinus][jMinus][kPlus] 
00837     + volumeMatrix[iMinus][jPlus][kPlus] ;
00838 
00839     return gradient;
00840 }
00841 
00842 
00844 // Description: Method "vpGetCentralDifferenceGradient" process and  
00845 //              returns the gradient estimation based on central
00846 //              difference method.
00847 // Parameters.: int i, int j, int k (matrix index)
00848 // Return.....: VPVector3D gradient
00849 
00850 VPVector3D VPVolume::vpGetCentralDifferenceGradient(int i, int j, int k) {
00851 
00852     int iMinus, jMinus, kMinus, iPlus, jPlus, kPlus;
00853     VPVector3D gradient;
00854 
00855     // For boundaries adjustment
00856     iPlus = ( (i+1) < xDimension ) ? i+1 : i;
00857     jPlus = ( (j+1) < yDimension ) ? j+1 : j;
00858     kPlus = ( (k+1) < zDimension ) ? k+1 : k;
00859     iMinus = ( (i-1) >= 0 ) ? i-1 : i;
00860     jMinus = ( (j-1) >= 0 ) ? j-1 : j;
00861     kMinus = ( (k-1) >= 0 ) ? k-1 : k;
00862 
00863     // Technique: Central Difference Gradient Estimator
00864     // 
00865     //        5-----------------6       
00866     //       /|                /|       
00867     //      / |               / |       
00868     //     /  |              /  |       
00869     // V(i,j,k)-------------2   |       
00870     //    |   |             |   |       
00871     //    |   |             |   |       
00872     //    |   |             |   |       
00873     //    |   8-------------|---V(i+1,j+1,k+1)          
00874     //    |  /              |  /        
00875     //    | /               | /     
00876     //    |/                |/      
00877     //    4-----------------3       
00878     //                  
00879     // Gx = V(i+1,j,k) - V(i-1,j,k)
00880     // Gy = V(i,j+1,k) - V(i,j-1,k)
00881     // Gz = V(i,j,k+1) - V(i,j,k-1)
00882 
00883     gradient.x = volumeMatrix[iPlus][j][k] - volumeMatrix[iMinus][j][k]; 
00884     gradient.y = volumeMatrix[i][jPlus][k] - volumeMatrix[i][jMinus][k]; 
00885     gradient.z = volumeMatrix[i][j][kPlus] - volumeMatrix[i][j][kMinus]; 
00886 
00887     return gradient;
00888 }
00889 
00890 
00892 // Description: Method "vpGetValue" returns the value of a volume
00893 //              matrix position.
00894 // Parameters.: int i, int j, int k (matrix index)
00895 // Return.....: short int volumeMatrix[i][j][k]
00896 
00897 unsigned int VPVolume::vpGetValue(int i, int j, int k) {
00898     unsigned int color;
00899 
00900     switch (fileBits) {
00901         case 8: color = (unsigned int) ((float)volumeMatrix[i][j][k]);
00902                 break;
00903         case 16:float temp = (float) (maxVolumeColor/255);  
00904                 // Density mapping to a gray value
00905                 // "Three Rule" for the convertion to 8 bits (0-65536 to 0-256
00906                 // gray levels): (256 * ponto)/65536
00907                 color = (unsigned int) ((float)volumeMatrix[i][j][k]/temp);
00908                 break;
00909     }
00910 
00911     return (color);
00912 }
00913 
00914 
00916 // Description: Method "vpGetLightValue" returns the value of a 
00917 //              volume lighted matrix position.
00918 // Parameters.: int i, int j, int k (matrix index)
00919 // Return.....: float volumeMatrix[i][j][k]
00920 
00921 float VPVolume::vpGetLightValue(int i, int j, int k) {
00922     float light;
00923     // CUIDAR A QUESTÃO QUE O PRIMEIRO BIT É FLAG!!!!
00924     light = volumeLightedMatrix[i][j][k] & (unsigned char)0x7F; //( (int)volumeLightedMatrix[i][j][k])/100.0;char
00925     light /= 100.0;
00926     return (light);
00927 }
00928 
00929 
00931 // Description: Method for image rendering.
00932 // Parameters.: -
00933 // Return.....: -
00934 
00935 void VPVolume::vpRender() {
00936 
00937     int viewHeight, viewWidth;
00938     activeCamera->vpGetViewDimension(viewHeight, viewWidth);
00939 
00940     switch(visualizationType) {
00941         case MIPVIS: 
00942                         vpAllocateGrayImage(viewHeight, viewWidth);
00943                         rayCasting.vpRenderMIP(scene, activeCamera, grayImage);
00944                         vpDisplayGray();
00945                         break;
00946         case MONOCOLORVIS:
00947                         vpAllocateColorImage(viewHeight, viewWidth);
00948                         rayCasting.vpRenderLivroMonoColor(scene, activeCamera, opacityComputation, colorImage);
00949                         vpDisplayColor();
00950                         break;
00951         case NOLIGHTMONOGRAYVIS:
00952                         vpAllocateGrayImage(viewHeight, viewWidth);
00953                         rayCasting.vpRenderNoLightMonoGray(scene, activeCamera, grayImage);
00954                         vpDisplayGray();
00955                         break;
00956         case MONOGRAYVIS:
00957                         vpAllocateGrayImage(viewHeight, viewWidth);
00958                         rayCasting.vpRenderLivroMonoGray(scene, activeCamera, MONOGRAYVIS, opacityComputation, grayImage);
00959                         vpDisplayGray();
00960                         break;
00961         case MULTIMODALVIS:
00962                         vpAllocateColorImage(viewHeight, viewWidth);
00963                         rayCasting.vpRenderLivroMultiModal(scene, activeCamera, opacityComputation, colorImage);
00964                         vpDisplayColor();
00965                         break;
00966         case MULTINNERSTRUCTURES:
00967                         vpAllocateColorImage(viewHeight, viewWidth);
00968                         rayCasting.vpRenderLivroMultiInnerStructures(scene, activeCamera, opacityComputation, colorImage); 
00969                         vpDisplayColor();
00970                         break;
00971         case MONOINNERSTRUCTURES:
00972                         vpAllocateGrayImage(viewHeight, viewWidth);
00973                         rayCasting.vpRenderLivroInnerStructures(scene, activeCamera, opacityComputation, grayImage); 
00974                         vpDisplayGray();
00975                         break;
00976         case MONOCOLORINNERSTRUCTURES:
00977                         vpAllocateColorImage(viewHeight, viewWidth);
00978                         rayCasting.vpRenderLivroMonoColorInnerStructures(scene, activeCamera, opacityComputation, colorImage); 
00979                         vpDisplayColor();
00980                         break;
00981         case DEFAULTVIS:
00982                         vpAllocateGrayImage(viewHeight, viewWidth);
00983                         rayCasting.vpRenderLivroMonoGray(scene, activeCamera, DEFAULTVIS, opacityComputation, grayImage);
00984                         vpDisplayGray();
00985                         break;
00986 
00987         case INNERSTRTOPSLICE:
00988                         vpAllocateColorImage(viewHeight, viewWidth);
00989                         vpSetSliceTopCamera();
00990                         slice.vpTopInnerStructRender(activeCamera, this, topSlice, colorImage);
00991                         vpDisplayColor();
00992                         break;
00993 
00994         case SLICETOP:  
00995                         vpAllocateGrayImage(viewHeight, viewWidth);
00996                         vpSetSliceTopCamera();
00997                         slice.vpTopSliceRender(activeCamera, this, topSlice, grayImage);
00998                         vpDisplayGray();
00999                         break;
01000 
01001         case INNERSTRFRONTSLICE:
01002 
01003         case SLICEFRONT:
01004                         vpAllocateGrayImage(viewHeight, viewWidth);
01005                         vpSetSliceFrontCamera();
01006                         slice.vpFrontSliceRender(activeCamera, this, frontSlice, grayImage);
01007                         vpDisplayGray();
01008                         break;
01009 
01010         case INNERSTRSIDESLICE:
01011                         vpAllocateColorImage(viewHeight, viewWidth);
01012                         vpSetSliceSideCamera();
01013                         slice.vpSideInnerStructRender(activeCamera, this, sideSlice, colorImage);
01014                         vpDisplayColor();
01015                         break;
01016 
01017         case SLICESIDE: 
01018                         vpAllocateGrayImage(viewHeight, viewWidth);
01019                         vpSetSliceSideCamera();
01020                         slice.vpSideSliceRender(activeCamera, this, sideSlice, grayImage);
01021                         vpDisplayGray();
01022                         break;
01023 
01024         case LINETOPSLICE:  
01025                         vpAllocateGrayImage(viewHeight, viewWidth);
01026                         vpSetSliceTopCamera();
01027                         slice.vpLineTopSliceRender(activeCamera, this, topSlice, grayImage);
01028                         vpDisplayGray();
01029                         break;
01030         case LINEFRONTSLICE:
01031                         vpAllocateGrayImage(viewHeight, viewWidth);
01032                         vpSetSliceFrontCamera();
01033                         slice.vpLineFrontSliceRender(activeCamera, this, frontSlice, grayImage);
01034                         vpDisplayGray();
01035                         break;
01036         case LINESIDESLICE: 
01037                         vpAllocateGrayImage(viewHeight, viewWidth);
01038                         vpSetSliceSideCamera();
01039                         slice.vpLineSideSliceRender(activeCamera, this, sideSlice, grayImage);
01040                         vpDisplayGray();
01041                         break;
01042     }
01043     
01044 }
01045 
01046 
01048 // Description: Method "vpAllocateGrayImage" is used to allocate
01049 //              and initialize an array for gray image store.
01050 // Parameters.: -
01051 // Return.....: -
01052 
01053 void VPVolume::vpAllocateGrayImage(int h, int w) {
01054 
01055     grayImage = (unsigned int **) new unsigned int[h]; 
01056     for (int c=0; c<h; c++)
01057         grayImage[c] = new unsigned int[w];
01058 
01059     for (int i=0; i<h; i++)
01060         for (int j=0; j<w; j++)
01061             grayImage[i][j] = 0;
01062 
01063 }
01064 
01065 
01067 // Description: Method "vpAllocateColorImage" is used to allocate
01068 //              and initialize an array for color image store.
01069 // Parameters.: -
01070 // Return.....: -
01071 
01072 void VPVolume::vpAllocateColorImage(int h, int w) {
01073 
01074  int i=0, j=0;
01075 
01076  colorImage = (unsigned int ***) new unsigned short int **[sizeof(unsigned short int **) * h]; 
01077 
01078  for (i=0; i<h; i++) {
01079     colorImage[i] = (unsigned int **) new unsigned short int *[sizeof(unsigned short int *) * w];
01080 
01081     for (j=0; j<w; j++) {
01082         colorImage[i][j] = new unsigned int[sizeof(unsigned short int) * 3];
01083     }
01084  }
01085 
01086  for (i=0; i<h; i++)
01087     for (j=0; j<w; j++) {
01088         colorImage[i][j][red] = 0;
01089         colorImage[i][j][green] = 0;
01090         colorImage[i][j][blue] = 0;
01091     }
01092 }
01093 
01094 
01096 // Description: Method "vpSetSliceTopCamera" set the camera
01097 //              attributes values for a top slice visualization.
01098 // Parameters.: -
01099 // Return.....: -
01100 
01101 void VPVolume::vpSetSliceTopCamera() {
01102     list<VPCamera*>::const_iterator iter;
01103     list<VPCamera*> cameras = scene->vpGetCameras();
01104     iter=cameras.begin();
01105     while ( *iter != activeCamera ) 
01106         iter++;
01107 
01108     // Get a pointer to the right camera 
01109     VPCamera *camera = *iter;
01110     VPPoint3D p;
01111 
01112     if ( (p == camera->vpGetTarget()) && (p == camera->vpGetLocation()) ) {
01113         // set camera parameters
01114         VPPoint3D target((float) vpGetXDimension()/2, 
01115                          (float) vpGetYDimension()/2,
01116                          (float) vpGetZDimension()/2);
01117         VPPoint3D location ((float) vpGetXDimension()/2, 
01118                             (float) 0,
01119                             (float) vpGetZDimension()/2);
01120         VPVector3D up(0.0,0.0,-1.0);
01121 
01122         camera->vpSetLocation(location);
01123         camera->vpSetTarget(target);
01124         camera->vpSetProjectionType(ORTHOGRAPHIC);
01125         camera->vpSetUp(up);
01126         camera->vpSetWinTopRight(vpGetXDimension()-1, vpGetZDimension()-1);
01127  
01128         camera->vpSetFarPlane(vpGetYDimension()+1);
01129         camera->vpSetNearPlane(0);
01130     }
01131     
01132 }
01133 
01134 
01136 // Description: Method "vpSetSliceFrontCamera" set the camera
01137 //              attributes values for a front slice visualization.
01138 // Parameters.: -
01139 // Return.....: -
01140 
01141 void VPVolume::vpSetSliceFrontCamera() {
01142     int virtualYDimension=0;
01143     list<VPCamera*>::const_iterator iter;
01144     list<VPCamera*> cameras = scene->vpGetCameras();
01145     iter=cameras.begin();
01146     while ( *iter != activeCamera ) 
01147         iter++;
01148 
01149     // Get a pointer to the right camera 
01150     VPCamera *camera = *iter;
01151     VPPoint3D p;
01152 
01153     // To verify the smallest dimension and set the virtualVolumeDimension
01154     if ( vpGetXDimension() < vpGetZDimension() )
01155         virtualYDimension = vpGetZDimension();
01156     else 
01157         virtualYDimension = vpGetXDimension();  
01158 
01159     if ( (p == camera->vpGetTarget()) && (p == camera->vpGetLocation()) ) {
01160         // set camera parameters    
01161         VPPoint3D target((float) vpGetXDimension()/2, 
01162                          (float) virtualYDimension/2,
01163                          (float) vpGetZDimension()/2);
01164         VPPoint3D location ((float) vpGetXDimension()/2, 
01165                             (float) virtualYDimension/2,
01166                             (float) vpGetZDimension());
01167         VPVector3D up(0.0,1.0,0.0);
01168 
01169         camera->vpSetLocation(location);
01170         camera->vpSetTarget(target);
01171         camera->vpSetProjectionType(ORTHOGRAPHIC);
01172         camera->vpSetUp(up);
01173         camera->vpSetWinTopRight(vpGetXDimension()-1, virtualYDimension-1);
01174  
01175         camera->vpSetFarPlane(vpGetZDimension()+1);
01176         camera->vpSetNearPlane(0);
01177     }
01178     
01179 }
01180 
01181 
01183 // Description: Method "vpSetSliceSideCamera" set the camera
01184 //              attributes values for a front slice visualization.
01185 // Parameters.: -
01186 // Return.....: -
01187 
01188 void VPVolume::vpSetSliceSideCamera() {
01189     int virtualYDimension=0;
01190     list<VPCamera*>::const_iterator iter;
01191     list<VPCamera*> cameras = scene->vpGetCameras();
01192     iter=cameras.begin();
01193     while ( *iter != activeCamera ) 
01194         iter++;
01195 
01196     // Get a pointer to the right camera 
01197     VPCamera *camera = *iter;
01198     VPPoint3D p;
01199 
01200     // To verify the smallest dimension and set the virtualVolumeDimension
01201     if ( vpGetXDimension() < vpGetZDimension() )
01202         virtualYDimension = vpGetZDimension();
01203     else 
01204         virtualYDimension = vpGetXDimension();  
01205 
01206     if ( (p == camera->vpGetTarget()) && (p == camera->vpGetLocation()) ) {
01207         // set camera parameters    
01208         VPPoint3D target((float) vpGetXDimension()/2, 
01209                          (float) virtualYDimension/2,
01210                          (float) vpGetZDimension()/2);
01211         VPPoint3D location ((float) 0, 
01212                             (float) virtualYDimension/2,
01213                             (float) vpGetZDimension()/2);
01214         VPVector3D up(0.0,1.0,0.0);
01215 
01216         camera->vpSetLocation(location);
01217         camera->vpSetTarget(target);
01218         camera->vpSetProjectionType(ORTHOGRAPHIC);
01219         camera->vpSetUp(up);
01220         camera->vpSetWinTopRight(vpGetZDimension()-1, virtualYDimension-1);
01221     
01222         camera->vpSetFarPlane(vpGetXDimension()+1);
01223         camera->vpSetNearPlane(0);
01224     }
01225 }
01226 
01227 
01229 // Description: Method for gray level image display.
01230 // Parameters.: -
01231 // Return.....: -
01232 
01233 void VPVolume::vpDisplayGray(){
01234  int i,j,k=0;
01235  int color=0;
01236  int viewHeight, viewWidth;
01237  
01238  activeCamera->vpGetViewDimension(viewHeight, viewWidth);
01239 
01240   for (i=0; i<viewHeight; i++,k+=3) { 
01241      for (j=0; j<viewWidth; j++) { 
01242 
01243         glBegin(GL_POINTS);
01244             glColor3ub((GLubyte)grayImage[i][j],(GLubyte)grayImage[i][j],(GLubyte)grayImage[i][j]);
01245             glVertex3f(j+1, i+1, 1.0f); // j+1 because the first array of data position
01246                                         // is 0 and the first screen position is 1
01247         glEnd();
01248     }
01249  }                      
01250 
01251  delete [] grayImage; 
01252 }
01253 
01254 
01256 // Description: Method for color image display.
01257 // Parameters.: -
01258 // Return.....: -
01259 
01260 void VPVolume::vpDisplayColor(){
01261  int i,j;
01262  int color=0;
01263  int viewHeight, viewWidth;
01264  
01265  activeCamera->vpGetViewDimension(viewHeight, viewWidth);
01266 
01267   for (i=0; i<viewHeight; i++) { 
01268      for (j=0; j<viewWidth; j++) { 
01269 
01270         glBegin(GL_POINTS);
01271             glColor3ub((GLubyte)colorImage[i][j][red],(GLubyte)colorImage[i][j][green],(GLubyte)colorImage[i][j][blue]);
01272             glVertex3f(j+1, i+1, 1.0f); // j+1 because the first array of data position
01273                                         // is 0 and the first screen position is 1
01274         glEnd();
01275     }
01276  }  
01277   
01278  if (INNERSTRTOPSLICE == visualizationType) {
01279         VPPoint2D p1, p2;
01280 
01281         // Draw a rectangle at SBand and TBand position
01282         p1 = slice.vpGetViewSBandPoint();
01283         p2 = slice.vpGetViewTBandPoint();
01284         glColor3f(1.0f, 0.0f, 0.0f);
01285         glRectf(p1.y-2, p1.x-2, p1.y+2, p1.x+2);
01286         glColor3f(1.0f, 1.0f, 0.0f);
01287         glRectf(p2.y-2, p2.x-2, p2.y+2, p2.x+2);
01288 
01289         // Draw the line that join SBand and TBand
01290         glLineWidth(1);
01291         glBegin(GL_LINES); 
01292             glColor3f(1.0f, 0.0f, 0.0f);
01293             glVertex3f(p1.y, p1.x, 1.0f);
01294             glColor3f(1.0f, 1.0f, 0.0f);    
01295             glVertex3f(p2.y, p2.x, 1.0f);
01296         glEnd();
01297         
01298         glLineWidth(2);
01299 
01300         // Draw the SBand line
01301         VPPoint2D *line;
01302         int points;
01303         slice.vpGetLineSBand(&line, points);
01304         glColor3f(1.0f, 0.0f, 0.0f);
01305         for (i=0; i<points-1; i++) {
01306             glBegin(GL_LINES); 
01307                 glVertex3f(line[i].y, line[i].x, 1.0f);
01308                 glVertex3f(line[i+1].y, line[i+1].x, 1.0f);
01309             glEnd();
01310         }
01311         // Draw the TBand line
01312         slice.vpGetLineTBand(&line, points);
01313         glColor3f(1.0f, 1.0f, 0.0f);
01314         for (i=0; i<points-1; i++) {
01315             glBegin(GL_LINES); 
01316                 glVertex3f(line[i].y, line[i].x, 1.0f);
01317                 glVertex3f(line[i+1].y, line[i+1].x, 1.0f);
01318             glEnd();
01319         }
01320         
01321  }
01322  
01323  else if (INNERSTRSIDESLICE == visualizationType) {
01324         VPPoint2D p1, p2;
01325 
01326         // Draw a rectangle at SBand and TBand position
01327         p1 = slice.vpGetViewSBandPoint();
01328         p2 = slice.vpGetViewTBandPoint();
01329         glColor3f(1.0f, 0.0f, 0.0f);
01330         glRectf(p1.y-2, p1.x-2, p1.y+2, p1.x+2);
01331         glColor3f(1.0f, 1.0f, 0.0f);
01332         glRectf(p2.y-2, p2.x-2, p2.y+2, p2.x+2);
01333 
01334         // Draw the line that join SBand and TBand
01335         glLineWidth(1);
01336         glBegin(GL_LINES); 
01337             glColor3f(1.0f, 0.0f, 0.0f);
01338             glVertex3f(p1.y, p1.x, 1.0f);
01339             glColor3f(1.0f, 1.0f, 0.0f);    
01340             glVertex3f(p2.y, p2.x, 1.0f);
01341         glEnd();
01342         
01343         glLineWidth(2);
01344 
01345         // Draw the SBand line
01346         VPPoint2D *line;
01347         int points;
01348         slice.vpGetLineSBand(&line, points);
01349         glColor3f(1.0f, 0.0f, 0.0f);
01350         for (i=0; i<points-1; i++) {
01351             glBegin(GL_LINES); 
01352                 glVertex3f(line[i].y, line[i].x, 1.0f);
01353                 glVertex3f(line[i+1].y, line[i+1].x, 1.0f);
01354             glEnd();
01355         }
01356         // Draw the TBand line
01357         slice.vpGetLineTBand(&line, points);
01358         glColor3f(1.0f, 1.0f, 0.0f);
01359         for (i=0; i<points-1; i++) {
01360             glBegin(GL_LINES); 
01361                 glVertex3f(line[i].y, line[i].x, 1.0f);
01362                 glVertex3f(line[i+1].y, line[i+1].x, 1.0f);
01363             glEnd();
01364         }
01365         
01366  }
01367  else if (INNERSTRFRONTSLICE == visualizationType) {
01368         VPPoint2D p1, p2;
01369 
01370         // Draw a rectangle at SBand and TBand position
01371         p1 = slice.vpGetViewSBandPoint();
01372         p2 = slice.vpGetViewTBandPoint();
01373         glColor3f(1.0f, 0.0f, 0.0f);
01374         glRectf(p1.y-2, p1.x-2, p1.y+2, p1.x+2);
01375         glColor3f(1.0f, 1.0f, 0.0f);
01376         glRectf(p2.y-2, p2.x-2, p2.y+2, p2.x+2);
01377 
01378         // Draw the line that join SBand and TBand
01379         glLineWidth(1);
01380         glBegin(GL_LINES); 
01381             glColor3f(1.0f, 0.0f, 0.0f);
01382             glVertex3f(p1.y, p1.x, 1.0f);
01383             glColor3f(1.0f, 1.0f, 0.0f);    
01384             glVertex3f(p2.y, p2.x, 1.0f);
01385         glEnd();
01386         
01387         glLineWidth(2);
01388 
01389         // Draw the SBand line
01390         VPPoint2D *line;
01391         int points;
01392         slice.vpGetLineSBand(&line, points);
01393         glColor3f(1.0f, 0.0f, 0.0f);
01394         for (i=0; i<points-1; i++) {
01395             glBegin(GL_LINES); 
01396                 glVertex3f(line[i].y, line[i].x, 1.0f);
01397                 glVertex3f(line[i+1].y, line[i+1].x, 1.0f);
01398             glEnd();
01399         }
01400         // Draw the TBand line
01401         slice.vpGetLineTBand(&line, points);
01402         glColor3f(1.0f, 1.0f, 0.0f);
01403         for (i=0; i<points-1; i++) {
01404             glBegin(GL_LINES); 
01405                 glVertex3f(line[i].y, line[i].x, 1.0f);
01406                 glVertex3f(line[i+1].y, line[i+1].x, 1.0f);
01407             glEnd();
01408         }
01409         
01410  }
01411 
01412  delete [] colorImage; 
01413 }
01414 
01415 
01417 // Description: Method to rotate an object.
01418 // Parameters.: -
01419 // Return.....: -
01420 
01421 void VPVolume::vpRotate() {
01422 
01423 }
01424 
01425 
01427 // Description: Method to change an object scale.
01428 // Parameters.: -
01429 // Return.....: -
01430 
01431 void VPVolume::vpScale(VPPoint3D s) {
01432 
01433 }
01434 
01435 
01437 // Description: Method to translate an object
01438 // Parameters.: -
01439 // Return.....: -
01440 
01441 void VPVolume::vpTranslate(VPPoint3D t) {
01442 
01443 }
01444 
01445 
01447 // Description: Method "vpSetVisualizationType" sends a new value 
01448 //              to the "visualizationType" attribute.
01449 // Parameters.: int vp (new attribute value)
01450 // Return.....: -
01451 
01452 void VPVolume::vpSetVisualizationType(int vp) {
01453     visualizationType = vp;
01454 }
01455 
01456 
01458 // Description: Method "vpGetVisualizationType" returns the value  
01459 //              of visualizationType attribute.
01460 // Parameters.: -
01461 // Return.....: int visualizationType (attribute value)
01462 
01463 int VPVolume::vpGetVisualizationType() {
01464     return visualizationType;
01465 }
01466 
01467 
01469 // Description: Method "vpSetTopSlice" sends a new value 
01470 //              to the "topSlice" attribute.
01471 // Parameters.: int v (new attribute value)
01472 // Return.....: -
01473 
01474 void VPVolume::vpSetTopSlice(int v) {
01475     topSlice = v;
01476     scene->vpSetChanged(true, this);
01477     scene->vpSetTypeOfChange(NEWTOPSLICE);
01478 
01479 }
01480 
01481 
01483 // Description: Method "vpGetTopSlice" returns the value of 
01484 //              topSlice attribute.
01485 // Parameters.: -
01486 // Return.....: int topSlice (attribute value)
01487 
01488 int VPVolume::vpGetTopSlice() {
01489     return topSlice;
01490 }
01491 
01492 
01494 // Description: Method "vpSetSideSlice" sends a new value 
01495 //              to the "sideSlice" attribute.
01496 // Parameters.: int v (new attribute value)
01497 // Return.....: -
01498 
01499 void VPVolume::vpSetSideSlice(int v) {
01500     sideSlice = v;
01501     scene->vpSetChanged(true, this);
01502     scene->vpSetTypeOfChange(NEWSIDESLICE);
01503 
01504 }
01505 
01506 
01508 // Description: Method "vpGetSideSlice" returns the value of 
01509 //              sideSlice attribute.
01510 // Parameters.: -
01511 // Return.....: int sideSlice (attribute value)
01512 
01513 int VPVolume::vpGetSideSlice() {
01514     return sideSlice;
01515 }
01516 
01517 
01519 // Description: Method "vpSetFrontSlice" sends a new value 
01520 //              to the "frontSlice" attribute.
01521 // Parameters.: int v (new attribute value)
01522 // Return.....: -
01523 
01524 void VPVolume::vpSetFrontSlice(int v) {
01525     frontSlice = v;
01526     scene->vpSetChanged(true, this);
01527     scene->vpSetTypeOfChange(NEWFRONTSLICE);
01528 
01529 }
01530 
01531 
01533 // Description: Method "vpGetFrontSlice" returns the value of 
01534 //              frontSlice attribute.
01535 // Parameters.: -
01536 // Return.....: int frontSlice (attribute value)
01537 
01538 int VPVolume::vpGetFrontSlice() {
01539     return frontSlice;
01540 }
01541 
01542 
01544 // Description: Method "vpSetActiveCamera" sends a new value 
01545 //              to the activeCamera attribute.
01546 // Parameters.: -
01547 // Return.....: -
01548 
01549 void VPVolume::vpSetActiveCamera(VPCamera *c) {
01550     activeCamera = c;
01551 }
01552 
01553 
01555 // Description: Method "vpSetRayCastingSBand" sends a new value for the end
01556 //              of S-Band (used for inner structures visualization).
01557 // Parameters.: VPPoint3D sb, int vt(visualization type)
01558 // Return.....: -
01559 
01560 void VPVolume::vpSetRayCastingSBand(VPPoint3D sb, int vt) {
01561     rayCasting.vpSetEndSBand(sb, this, vt);
01562 }
01563 
01564 
01566 // Description: Method "vpGetRayCastingSBand" get the value of the end
01567 //              of S-Band (used for inner structures visualization).
01568 // Parameters.: -
01569 // Return.....: int
01570 
01571 int VPVolume::vpGetRayCastingSBand(){ 
01572     return rayCasting.vpGetEndSBand();
01573 }
01574 
01575 
01577 // Description: Method "vpSetRayCastingTBand" sends a new value for the end
01578 //              of T-Band (used for inner structures visualization).
01579 // Parameters.: VPPoint3D tb, int vt(visualization type)
01580 // Return.....: -
01581 
01582 void VPVolume::vpSetRayCastingTBand(VPPoint3D tb, int vt) {
01583     rayCasting.vpSetEndTBand(tb, this, vt);
01584 }
01585 
01586 
01588 // Description: Method "vpGetRayCastingTBand" get the value of the end
01589 //              of T-Band (used for inner structures visualization).
01590 // Parameters.: -
01591 // Return.....: int
01592 
01593 int VPVolume::vpGetRayCastingTBand() {
01594     return rayCasting.vpGetEndTBand();
01595 }
01596 
01597 
01599 // Description: Method "vpSetRayCastingSampleStep" sends a new value 
01600 //              to the object attribute (sampleStep).
01601 // Parameters.: float s
01602 // Return.....: -
01603 
01604 void VPVolume::vpSetRayCastingSampleStep(float s) {
01605     rayCasting.vpSetSampleStep(s);
01606 }
01607 
01608 
01610 // Description: Method "vpGetRayCastingSampleStep" get the 
01611 //              object attribute value (sampleStep).
01612 // Parameters.: -
01613 // Return.....: float sampleStep
01614 
01615 float VPVolume::vpGetRayCastingSampleStep() {
01616     return rayCasting.vpGetSampleStep();
01617 }
01618 
01619 
01621 // Description: Method "vpSetRayCastingAmbientLight" sends a new  
01622 //              value to the object attribute (ambientLight).
01623 // Parameters.: float a
01624 // Return.....: -
01625 
01626 void VPVolume::vpSetRayCastingAmbientLight(float a) {
01627     rayCasting.vpSetAmbientLight(a);
01628 }
01629 
01630 
01632 // Description: Method "vpGetRayCastingAmbientLight" get the 
01633 //              object attribute (ambientLight).
01634 // Parameters.: -
01635 // Return.....: float ambientLight
01636 
01637 float VPVolume::vpGetRayCastingAmbientLight() {
01638     return rayCasting.vpGetAmbientLight();
01639 }
01640 
01641 
01643 // Description: Method "vpSetRayCastingDiffuseLight" sends a new  
01644 //              value to the object attribute (diffuseLight).
01645 // Parameters.: float a
01646 // Return.....: -
01647 
01648 void VPVolume::vpSetRayCastingDiffuseLight(float d) {
01649     rayCasting.vpSetDiffuseLight(d);
01650 }
01651 
01652 
01654 // Description: Method "vpGetRayCastingDiffuseLight" get the 
01655 //              object attribute (diffuseLight).
01656 // Parameters.: -
01657 // Return.....: float diffuseLight
01658 
01659 float VPVolume::vpGetRayCastingDiffuseLight() {
01660     return rayCasting.vpGetDiffuseLight();
01661 }
01662 
01663 
01665 // Description: Method "vpSetRayCastingSpecularExponent" sends a   
01666 //              new value to the object attribute (specularExponent).
01667 // Parameters.: int s
01668 // Return.....: -
01669 
01670 void  VPVolume::vpSetRayCastingSpecularExponent(int s) {
01671     rayCasting.vpSetSpecularExponent(s);
01672 }
01673 
01674 
01676 // Description: Method "vpGetRayCastingSpecularExponent" get the 
01677 //              object attribute (specularExponent).
01678 // Parameters.: -
01679 // Return.....: int specularExponent
01680 
01681 int   VPVolume::vpGetRayCastingSpecularExponent() {
01682     return rayCasting.vpGetSpecularExponent();
01683 }
01684 
01685 
01687 // Description: Method "vpSetRayCastingSpecular" sends a new  
01688 //              value to the object attribute (specular).
01689 // Parameters.: bool s
01690 // Return.....: -
01691 
01692 void  VPVolume::vpSetRayCastingSpecular(bool s) {
01693     rayCasting.vpSetSpecular(s);
01694 }
01695 
01696 
01698 // Description: Method "vpGetRayCastingSpecular" get the 
01699 //              object attribute (specular).
01700 // Parameters.: -
01701 // Return.....: bool specular
01702 
01703 bool  VPVolume::vpGetRayCastingSpecular() {
01704     return rayCasting.vpGetSpecular();
01705 }
01706 
01707 
01709 // Description: Method "vpSetRayCastingShadingMethod" sends a new  
01710 //              value to the object attribute (shadingMethod).
01711 // Parameters.: int sm
01712 // Return.....: -
01713 
01714 void  VPVolume::vpSetRayCastingShadingMethod(int sm) {
01715         rayCasting.vpSetShadingMethod(sm);
01716 }
01717 
01718 
01720 // Description: Method "vpGetRayCastingShadingMethod" get the 
01721 //              object attribute (shadingMethod).
01722 // Parameters.: -
01723 // Return.....: int shadingMethod
01724 
01725 int VPVolume::vpGetRayCastingShadingMethod() {
01726     return rayCasting.vpGetShadingMethod();
01727 }
01728 
01729 
01731 // Description: Method "vpSetRayCastingTypeOfCuttingTool" sends a   
01732 //              new value to the object attribute (typeOfCuttingTool).
01733 // Parameters.: int sm
01734 // Return.....: -
01735 
01736 void VPVolume::vpSetRayCastingTypeOfCuttingTool(int t) {
01737         rayCasting.vpSetTypeOfCuttingTool(t);
01738 }
01739 
01740 
01742 // Description: Method "vpGetRayCastingTypeOfCuttingTool" get the 
01743 //              object attribute (typeOfCuttingTool).
01744 // Parameters.: -
01745 // Return.....: int typeOfCuttingTool
01746 
01747 int VPVolume::vpGetRayCastingTypeOfCuttingTool(){
01748     return rayCasting.vpGetTypeOfCuttingTool();
01749 }
01750 
01751 
01753 // Description: Method "vpSetOpacityComputation" sends a new  
01754 //              value to the object attribute (opacityComputation).         
01755 // Parameters.: float a
01756 // Return.....: -
01757 
01758 void VPVolume::vpSetOpacityComputation(int oc){
01759     opacityComputation = oc;
01760 }
01761 
01762 
01764 // Description: Method "vpGetOpacityComputation" get the object
01765 //              attribute (opacityComputation) that has the
01766 //              kind of opacity computation that will be used.
01767 // Parameters.: -
01768 // Return.....: int opacityComputation
01769 
01770 int VPVolume::vpGetOpacityComputation(){
01771     return opacityComputation;
01772 }
01773 
01774 
01776 // Description: Method "vpSetOpacityTable" sends a new  
01777 //              value for the opacity table.            
01778 // Parameters.: float t[]
01779 // Return.....: -
01780 
01781 void  VPVolume::vpSetOpacityTable(float t[]) {
01782     controlTables.vpSetOpacityTable(t); 
01783 }
01784 
01785 
01787 // Description: Method "vpGetOpacityTable" gets the 
01788 //              opacity table.
01789 // Parameters.: -
01790 // Return.....: float *
01791 
01792 float * VPVolume::vpGetOpacityTable() {
01793     return controlTables.vpGetOpacityTable();
01794 }
01795 
01796 
01798 // Description: Method "vpSetColorTable" sends a new  
01799 //              value for the color table.          
01800 // Parameters.: VPColor c[]
01801 // Return.....: -
01802 
01803 void  VPVolume::vpSetColorTable(VPColor c[]) {
01804     controlTables.vpSetColorTable(c); 
01805 }
01806 
01807 
01809 // Description: Method "vpGetColorTable" gets the 
01810 //              colot table.
01811 // Parameters.: -
01812 // Return.....: VPColor *
01813 
01814 VPColor * VPVolume::vpGetColorTable() {
01815     return controlTables.vpGetColorTable();
01816 }
01817 
01818 
01820 // Description: Method "vpSetControlPoints" sends a new  
01821 //              value for the tables control points.
01822 // Parameters.: int cp[], int n
01823 // Return.....: -
01824 
01825 void VPVolume::vpSetControlPoints (int cp[], int n) {
01826     controlTables.vpSetControlPoints(cp, n);
01827 }
01828 
01829 
01831 // Description: Method "vpGetControlPoints" return the 
01832 //              tables control points.
01833 // Parameters.: -
01834 // Return.....: int cp[], int &n
01835 
01836 void VPVolume::vpGetControlPoints(int cp[], int &n) {
01837     controlTables.vpGetControlPoints(cp, n);
01838 }
01839 
01840 
01842 // Description: Method "vpSetControlPoints" sends a new  
01843 //              value for the tables control points.
01844 // Parameters.: int cp[], VPColor c[], int n
01845 // Return.....: -
01846 
01847 void VPVolume::vpSetControlPoints (int cp[], VPColor c[], int n) {
01848     controlTables.vpSetControlPoints(cp, c, n);
01849 }
01850 
01851 
01853 // Description: Method "vpGetControlPoints" return the 
01854 //              tables control points.
01855 // Parameters.: -
01856 // Return.....: int cp[], VPColor c[], int &n
01857 
01858 void VPVolume::vpGetControlPoints(int cp[], VPColor c[], int &n) {
01859     controlTables.vpGetControlPoints(cp, c, n);
01860 }
01861 
01862 
01864 // Description: Method "vpProcessHistogram" process the histogram 
01865 //              and save it in a file.
01866 // Parameters.: -
01867 // Return.....: -
01868 
01869 void  VPVolume::vpProcessHistogram() {
01870     int i, j, k, histogram[256], maxSample=0;
01871     FILE *fp, *fp1;
01872 
01873     for (i=0; i<256; i++)
01874         histogram[i] = 0;
01875 
01876     for (k=0; k<yDimension; k++) 
01877         for (i=0; i<zDimension; i++) 
01878             for (j=0; j<xDimension; j++) 
01879                 if (volumeMatrix[j][k][i]<256)
01880                     histogram[volumeMatrix[j][k][i]]++;
01881 
01882     for (i=0; i<256; i++)
01883         if (histogram[i] > maxSample)
01884             maxSample = histogram[i];
01885 
01886     fp = fopen("histograma.txt", "w");
01887     fp1 = fopen("excel.txt", "w");
01888 
01889     for (i=0; i<256; i++)
01890     {
01891         fprintf(fp, "%d - ", i);
01892         fprintf(fp1, "%d \n", histogram[i]);
01893         k = ( 3500 * histogram[i] ) / maxSample; 
01894         for (j=0; j<k; j++)
01895             fprintf(fp, "*");
01896         fprintf(fp, "\n");
01897     }
01898 
01899     fclose(fp);
01900     fclose(fp1); 
01901 }
01902 
01903 
01905 // Description: Method "vpProcessCenterFocalPoint" calcules the 
01906 //              value of the centerFocalPoint attribute (CENTRO DO
01907 //              OBJETO/ÓRGÃO).
01908 // Parameters.: -
01909 // Return.....: -
01910 
01911 void VPVolume::vpProcessCenterFocalPoint() {
01912     int i=0, k=0, x=0, z=0, min=0, max=0, density=0, distance=0, sum=0, aux=0;
01913 
01914     // X processing
01915     while ( (density<50) && (min<(xDimension-1)) ) {
01916         density = volumeMatrix[min][yDimension/2][zDimension/2];
01917         min++;
01918     }
01919     max = xDimension-1;
01920     density = 0;
01921     while ( (density<50) && (max>0) ) {
01922         density = volumeMatrix[max][yDimension/2][zDimension/2];
01923         max--;
01924     }
01925     centerFocalPoint.x = ((float)max + (float)min) / 2.0;
01926 
01927     // Y processing
01928     x = xDimension/3;
01929     z = zDimension/3;
01930     for (i=x; i<x*2; i++) {
01931         for (k=z; k<z*2; k++) {
01932             min = density = 0;
01933             while ( (density<50) && (min<(yDimension-1)) ) {
01934                 density = volumeMatrix[i][min][k];
01935                 min++;
01936             }
01937             max = yDimension-1;
01938             density = 0;
01939             while ( (density<50) && (max>0) ) {
01940                 density = volumeMatrix[i][max][k];
01941                 max--;
01942             }
01943             aux = max - min;
01944             if (distance < aux) {
01945                 distance = aux;
01946                 sum = max + min;
01947             }
01948         }
01949     }
01950     centerFocalPoint.y = (float)sum / 2.0;
01951 
01952     // Z processing
01953     // OBS: POR ENQUANTO NÃO LEVAR EM CONTA O PROBLEMA DO NARIZ...
01954     density = min = 0;
01955     while ( (density<50) && (min<(zDimension-1)) ) {
01956         density = volumeMatrix[(int)centerFocalPoint.x][(int)centerFocalPoint.y][min];
01957         min++;
01958     }
01959     density = 0;
01960     max = zDimension-1;
01961     while (density<50) {
01962         density = volumeMatrix[(int)centerFocalPoint.x][(int)centerFocalPoint.y][max];
01963         max--;
01964     }
01965     centerFocalPoint.z = ((float)max + (float)min) / 2.0;
01966 
01967 }
01968 
01969 
01971 // Description: Method "vpGetCenterFocalPoint" returns the value 
01972 //              of the centerFocalPoint attribute.
01973 // Parameters.: -
01974 // Return.....: VPPoint3D
01975 
01976 VPPoint3D VPVolume::vpGetCenterFocalPoint() {
01977     return centerFocalPoint;
01978 }
01979 
01980 
01982 // Description: Method "vpGetMinVolumeColor" returns the value 
01983 //              of the minVolumeColor attribute.
01984 // Parameters.: -
01985 // Return.....: unsigned int
01986 
01987 unsigned int VPVolume::vpGetMinVolumeColor() {
01988     return minVolumeColor;
01989 }
01990 
01991 
01993 // Description: Method "vpGetMaxVolumeColor" returns the value 
01994 //              of the maxVolumeColor attribute.
01995 // Parameters.: -
01996 // Return.....: unsigned int
01997 
01998 unsigned int VPVolume::vpGetMaxVolumeColor() {
01999     return maxVolumeColor;
02000 }
02001 
02002 
02004 // Description: Method "vpGetControlTables" returns the value 
02005 //              of the controlTables attribute.
02006 // Parameters.: -
02007 // Return.....: VPTable controlTables
02008 
02009 VPTable VPVolume::vpGetControlTables() {
02010     return controlTables;
02011 }
02012 
02013 
02015 // Description: Method "vpvpSwapBytes" is used because the datasets
02016 //              from the "Introduction to Volume Rendering" cd-rom
02017 //              are all written on a unix system, which has reverse 
02018 //              endian.
02019 // Parameters.: GLint *intPtr, pointer of words requiring byte swapping
02020 //              int sizeBytes, number of bytes in array
02021 // Return.....: -
02022 
02023 GLvoid VPVolume::vpSwapBytes(GLint *intPtr, int sizeBytes) {
02024     GLint       sizeInts, i;
02025     GLubyte     *bytePtr;
02026 
02027     sizeInts = sizeBytes / 4;
02028     for (i = 0; i < sizeInts; i++)
02029     {
02030         bytePtr = (GLubyte *) intPtr;
02031         *intPtr++ = ((bytePtr[0]<<24) | (bytePtr[1]<<16) | (bytePtr[2]<<8) |
02032             bytePtr[3]);
02033     }
02034 }
02035 
02036 
02038 // Description: Method "vpAdjustScale" is used to set scale 
02039 //              attribute, which is used because the volume is
02040 //              no isotropic.
02041 // Parameters.: int x, int y, int z, virtual volume dimensions
02042 // Return.....: -
02043 
02044 void VPVolume::vpAdjustScale(int x, int y, int z) {
02045 
02046     if ( (xDimension>=yDimension) && (xDimension>=zDimension) ) 
02047     {
02048         scale.x = 1;
02049         scale.y = (float) yDimension/xDimension;
02050         scale.z = (float) zDimension/xDimension;
02051     }
02052     else if ( (yDimension>=xDimension) && (yDimension>=zDimension) )
02053     {
02054         scale.y = 1;
02055         scale.x = (float) xDimension/yDimension;
02056         scale.z = (float) zDimension/yDimension;
02057     }
02058     else 
02059     {
02060         scale.z = 1;
02061         scale.x = (float) xDimension/zDimension;
02062         scale.y = (float) yDimension/zDimension;
02063     }
02064 
02065 }
02066 
02067 
02069 // Description: Method "vpGetScale" returns the value of the
02070 //              scale attribute.
02071 // Parameters.: -
02072 // Return.....: VPPoint3D scale
02073 
02074 VPPoint3D VPVolume::vpGetScale() {
02075     return scale;
02076 }
02077 
02078 
02080 // Description: Method "vpGetSliceViewSBandPoint" returns the value  
02081 //              of enfOfSBand attribute.
02082 // Parameters.: -
02083 // Return.....: VPPoint2D enfOfSBand (attribute value)
02084 
02085 VPPoint2D VPVolume::vpGetSliceViewSBandPoint() {
02086     return slice.vpGetViewSBandPoint(); // enfOfSBand ("view coordinate")
02087 }
02088 
02089 
02091 // Description: Method "vpGetSliceViewTBandPoint" returns the value  
02092 //              of enfOfTBand attribute.
02093 // Parameters.: -
02094 // Return.....: VPPoint2D enfOfTBand (attribute value)
02095 
02096 VPPoint2D VPVolume::vpGetSliceViewTBandPoint() {
02097     return slice.vpGetViewTBandPoint(); // enfOfTBand ("view coordinate")
02098 }
02099 
02100 
02102 // Description: Method "vpGetFileType" returns the value of the
02103 //              fileType attribute.
02104 // Parameters.: -
02105 // Return.....: int fileType (attribute value)
02106 
02107 int VPVolume::vpGetFileType() {
02108     return fileType; 
02109 }
02110 
02111 
02113 // Description: Method "vpSetCameraLocationForInnerStructure" sends    
02114 //              a new value for the cameraLocationForInnerStructure 
02115 //              attribute.
02116 // Parameters.: -
02117 // Return.....: -
02118 
02119 void VPVolume::vpSetCameraLocationForInnerStructure(VPPoint3D c) {
02120     cameraLocationForInnerStructure = c;
02121 }
02122 
02123 
02125 // Description: Method "vpGetCameraLocationForInnerStructure" 
02126 //              returns the value of the
02127 //              cameraLocationForInnerStructure attribute.
02128 // Parameters.: -
02129 // Return.....: VPPoint3D cameraLocationForInnerStructure 
02130 //              (attribute value)
02131 
02132 VPPoint3D VPVolume::vpGetCameraLocationForInnerStructure(){
02133     return cameraLocationForInnerStructure;
02134 }

Generated on Tue Sep 6 10:00:08 2005 for VPAT by  doxygen 1.4.4