00001
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00032
00033
00034 #include <vpvolume.h>
00035 #include <iostream>
00036 #include <cmath>
00037 #include <string>
00038 using namespace std;
00039
00040
00042
00043
00044
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
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 VPVolume::VPVolume (const char *n, int t, int dh, int dv, int s, int b) {
00076
00077
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
00087 grayImage = NULL;
00088 colorImage = NULL;
00089 activeCamera = NULL;
00090 maxVolumeColor = 0;
00091 maxVolumeColor = 0;
00092 minVolumeColor = 4095;
00093
00094
00095 fileType = t;
00096 visualizationType = DEFAULTVIS;
00097 opacityComputation = LINEAROPAC;
00098 fileBits = b;
00099 xDimension = dh;
00100 yDimension = s;
00101 zDimension = dv;
00102
00103
00104
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 }
00116
00117
00118 while ( (*aux != '\\') && (*aux) ) {
00119 aux--;
00120 baka--;
00121 }
00122 baka++;
00123 strncpy(path, n, baka);
00124
00125
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
00140 strcat(description, ", raw file");
00141 vpSetDescription(description);
00142
00143 vpReadRawFile(n);
00144 }
00145
00146 else if ( !strcmp(extension,"i") ) {
00147
00148 strcat(description, ", i file");
00149 vpSetDescription(description);
00150
00151 vpReadIFile(n, path);
00152 }
00153
00154 else if ( !strcmp(extension,"vol") ) {
00155
00156 strcat(description, ", vol file");
00157 vpSetDescription(description);
00158
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
00180
00181
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
00189 allocMemory();
00190 allocMemory2();
00191
00192
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
00204 for (j=0; j<xDimension; j++) {
00205
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
00218 for (j=0; j<xDimension; j++) {
00219
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 }
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
00246
00247
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
00257 allocMemory();
00258
00259
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);
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);
00279 fread(&aux1, 1, 1, fp);
00280 fread(&aux2, 1, 1, fp);
00281 for (i=0; i<zDimension; i++) {
00282
00283 for (j=0; j<xDimension; j++) {
00284
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);
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
00307 fread(&aux1, 1, 1, fp);
00308 fread(&aux2, 1, 1, fp);
00309 volumeMatrix[j][k][i] = (unsigned int) (aux1*256) + aux2;
00310
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
00327
00328
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;
00339 int x1, y1;
00340 int MagicNumber;
00341 int HeaderLength;
00342 int PixelDepth;
00343 int PixelType;
00344 int IndexBits;
00345 float ScaleX;
00346 float ScaleY;
00347 float ScaleZ;
00348 float RotX;
00349 float RotY;
00350 float RotZ;
00351 int totalDepth;
00352
00353
00354
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
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
00381 xDimension = VolumeDimensions.x;
00382 yDimension = VolumeDimensions.z;
00383 zDimension = VolumeDimensions.y;
00384
00385
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 }
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
00430 }
00431 break;
00432
00433
00434 }
00435
00436
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 }
00463 }
00464 }
00465 }
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 }
00483 }
00484 }
00485 }
00486 }
00487 delete[] V8;
00488 } else {
00489 N = 1;
00490
00491
00492
00493
00494
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 }
00513 }
00514 }
00515 delete[] V16;
00516 }
00517
00518 fclose(fp);
00519
00520
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
00536
00537
00538
00539
00540
00541
00542
00543 bool VPVolume::allocMemory() {
00544
00545 int i, j;
00546
00547
00548
00549
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
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
00592
00593
00594
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
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
00634
00635
00636
00637 VPVolume::~VPVolume () {
00638 delete [] volumeMatrix;
00639 delete [] volumeLightedMatrix;
00640 }
00641
00642
00644
00645
00646
00647
00648
00649
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
00665 gradient = vpGetSobelGradient(i, j, k);
00666
00667 gradient.vpNormalize();
00668
00669
00670
00671
00672 dot = gradient.vpDotProduct(ld);
00673
00674 if (dot < 0.0)
00675 dot = (float) 0.0;
00676
00677 light = al + (0.9 * dot);
00678
00679 if (light > 1)
00680 light = 1;
00681
00682
00683
00684
00685
00686 intLight = floor ( (light * 100) + 0.5 );
00687
00688
00689
00690
00691
00692
00693
00694 volumeLightedMatrix[i][j][k] = (unsigned char) intLight;
00695 }
00696 }
00697 }
00698
00699 }
00700
00701
00703
00704
00705
00706
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
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
00761
00762
00763
00764
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
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]
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
00845
00846
00847
00848
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
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
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
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
00893
00894
00895
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
00905
00906
00907 color = (unsigned int) ((float)volumeMatrix[i][j][k]/temp);
00908 break;
00909 }
00910
00911 return (color);
00912 }
00913
00914
00916
00917
00918
00919
00920
00921 float VPVolume::vpGetLightValue(int i, int j, int k) {
00922 float light;
00923
00924 light = volumeLightedMatrix[i][j][k] & (unsigned char)0x7F;
00925 light /= 100.0;
00926 return (light);
00927 }
00928
00929
00931
00932
00933
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
01049
01050
01051
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
01068
01069
01070
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
01097
01098
01099
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
01109 VPCamera *camera = *iter;
01110 VPPoint3D p;
01111
01112 if ( (p == camera->vpGetTarget()) && (p == camera->vpGetLocation()) ) {
01113
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
01137
01138
01139
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
01150 VPCamera *camera = *iter;
01151 VPPoint3D p;
01152
01153
01154 if ( vpGetXDimension() < vpGetZDimension() )
01155 virtualYDimension = vpGetZDimension();
01156 else
01157 virtualYDimension = vpGetXDimension();
01158
01159 if ( (p == camera->vpGetTarget()) && (p == camera->vpGetLocation()) ) {
01160
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
01184
01185
01186
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
01197 VPCamera *camera = *iter;
01198 VPPoint3D p;
01199
01200
01201 if ( vpGetXDimension() < vpGetZDimension() )
01202 virtualYDimension = vpGetZDimension();
01203 else
01204 virtualYDimension = vpGetXDimension();
01205
01206 if ( (p == camera->vpGetTarget()) && (p == camera->vpGetLocation()) ) {
01207
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
01230
01231
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);
01246
01247 glEnd();
01248 }
01249 }
01250
01251 delete [] grayImage;
01252 }
01253
01254
01256
01257
01258
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);
01273
01274 glEnd();
01275 }
01276 }
01277
01278 if (INNERSTRTOPSLICE == visualizationType) {
01279 VPPoint2D p1, p2;
01280
01281
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
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
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
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
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
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
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
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
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
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
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
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
01418
01419
01420
01421 void VPVolume::vpRotate() {
01422
01423 }
01424
01425
01427
01428
01429
01430
01431 void VPVolume::vpScale(VPPoint3D s) {
01432
01433 }
01434
01435
01437
01438
01439
01440
01441 void VPVolume::vpTranslate(VPPoint3D t) {
01442
01443 }
01444
01445
01447
01448
01449
01450
01451
01452 void VPVolume::vpSetVisualizationType(int vp) {
01453 visualizationType = vp;
01454 }
01455
01456
01458
01459
01460
01461
01462
01463 int VPVolume::vpGetVisualizationType() {
01464 return visualizationType;
01465 }
01466
01467
01469
01470
01471
01472
01473
01474 void VPVolume::vpSetTopSlice(int v) {
01475 topSlice = v;
01476 scene->vpSetChanged(true, this);
01477 scene->vpSetTypeOfChange(NEWTOPSLICE);
01478
01479 }
01480
01481
01483
01484
01485
01486
01487
01488 int VPVolume::vpGetTopSlice() {
01489 return topSlice;
01490 }
01491
01492
01494
01495
01496
01497
01498
01499 void VPVolume::vpSetSideSlice(int v) {
01500 sideSlice = v;
01501 scene->vpSetChanged(true, this);
01502 scene->vpSetTypeOfChange(NEWSIDESLICE);
01503
01504 }
01505
01506
01508
01509
01510
01511
01512
01513 int VPVolume::vpGetSideSlice() {
01514 return sideSlice;
01515 }
01516
01517
01519
01520
01521
01522
01523
01524 void VPVolume::vpSetFrontSlice(int v) {
01525 frontSlice = v;
01526 scene->vpSetChanged(true, this);
01527 scene->vpSetTypeOfChange(NEWFRONTSLICE);
01528
01529 }
01530
01531
01533
01534
01535
01536
01537
01538 int VPVolume::vpGetFrontSlice() {
01539 return frontSlice;
01540 }
01541
01542
01544
01545
01546
01547
01548
01549 void VPVolume::vpSetActiveCamera(VPCamera *c) {
01550 activeCamera = c;
01551 }
01552
01553
01555
01556
01557
01558
01559
01560 void VPVolume::vpSetRayCastingSBand(VPPoint3D sb, int vt) {
01561 rayCasting.vpSetEndSBand(sb, this, vt);
01562 }
01563
01564
01566
01567
01568
01569
01570
01571 int VPVolume::vpGetRayCastingSBand(){
01572 return rayCasting.vpGetEndSBand();
01573 }
01574
01575
01577
01578
01579
01580
01581
01582 void VPVolume::vpSetRayCastingTBand(VPPoint3D tb, int vt) {
01583 rayCasting.vpSetEndTBand(tb, this, vt);
01584 }
01585
01586
01588
01589
01590
01591
01592
01593 int VPVolume::vpGetRayCastingTBand() {
01594 return rayCasting.vpGetEndTBand();
01595 }
01596
01597
01599
01600
01601
01602
01603
01604 void VPVolume::vpSetRayCastingSampleStep(float s) {
01605 rayCasting.vpSetSampleStep(s);
01606 }
01607
01608
01610
01611
01612
01613
01614
01615 float VPVolume::vpGetRayCastingSampleStep() {
01616 return rayCasting.vpGetSampleStep();
01617 }
01618
01619
01621
01622
01623
01624
01625
01626 void VPVolume::vpSetRayCastingAmbientLight(float a) {
01627 rayCasting.vpSetAmbientLight(a);
01628 }
01629
01630
01632
01633
01634
01635
01636
01637 float VPVolume::vpGetRayCastingAmbientLight() {
01638 return rayCasting.vpGetAmbientLight();
01639 }
01640
01641
01643
01644
01645
01646
01647
01648 void VPVolume::vpSetRayCastingDiffuseLight(float d) {
01649 rayCasting.vpSetDiffuseLight(d);
01650 }
01651
01652
01654
01655
01656
01657
01658
01659 float VPVolume::vpGetRayCastingDiffuseLight() {
01660 return rayCasting.vpGetDiffuseLight();
01661 }
01662
01663
01665
01666
01667
01668
01669
01670 void VPVolume::vpSetRayCastingSpecularExponent(int s) {
01671 rayCasting.vpSetSpecularExponent(s);
01672 }
01673
01674
01676
01677
01678
01679
01680
01681 int VPVolume::vpGetRayCastingSpecularExponent() {
01682 return rayCasting.vpGetSpecularExponent();
01683 }
01684
01685
01687
01688
01689
01690
01691
01692 void VPVolume::vpSetRayCastingSpecular(bool s) {
01693 rayCasting.vpSetSpecular(s);
01694 }
01695
01696
01698
01699
01700
01701
01702
01703 bool VPVolume::vpGetRayCastingSpecular() {
01704 return rayCasting.vpGetSpecular();
01705 }
01706
01707
01709
01710
01711
01712
01713
01714 void VPVolume::vpSetRayCastingShadingMethod(int sm) {
01715 rayCasting.vpSetShadingMethod(sm);
01716 }
01717
01718
01720
01721
01722
01723
01724
01725 int VPVolume::vpGetRayCastingShadingMethod() {
01726 return rayCasting.vpGetShadingMethod();
01727 }
01728
01729
01731
01732
01733
01734
01735
01736 void VPVolume::vpSetRayCastingTypeOfCuttingTool(int t) {
01737 rayCasting.vpSetTypeOfCuttingTool(t);
01738 }
01739
01740
01742
01743
01744
01745
01746
01747 int VPVolume::vpGetRayCastingTypeOfCuttingTool(){
01748 return rayCasting.vpGetTypeOfCuttingTool();
01749 }
01750
01751
01753
01754
01755
01756
01757
01758 void VPVolume::vpSetOpacityComputation(int oc){
01759 opacityComputation = oc;
01760 }
01761
01762
01764
01765
01766
01767
01768
01769
01770 int VPVolume::vpGetOpacityComputation(){
01771 return opacityComputation;
01772 }
01773
01774
01776
01777
01778
01779
01780
01781 void VPVolume::vpSetOpacityTable(float t[]) {
01782 controlTables.vpSetOpacityTable(t);
01783 }
01784
01785
01787
01788
01789
01790
01791
01792 float * VPVolume::vpGetOpacityTable() {
01793 return controlTables.vpGetOpacityTable();
01794 }
01795
01796
01798
01799
01800
01801
01802
01803 void VPVolume::vpSetColorTable(VPColor c[]) {
01804 controlTables.vpSetColorTable(c);
01805 }
01806
01807
01809
01810
01811
01812
01813
01814 VPColor * VPVolume::vpGetColorTable() {
01815 return controlTables.vpGetColorTable();
01816 }
01817
01818
01820
01821
01822
01823
01824
01825 void VPVolume::vpSetControlPoints (int cp[], int n) {
01826 controlTables.vpSetControlPoints(cp, n);
01827 }
01828
01829
01831
01832
01833
01834
01835
01836 void VPVolume::vpGetControlPoints(int cp[], int &n) {
01837 controlTables.vpGetControlPoints(cp, n);
01838 }
01839
01840
01842
01843
01844
01845
01846
01847 void VPVolume::vpSetControlPoints (int cp[], VPColor c[], int n) {
01848 controlTables.vpSetControlPoints(cp, c, n);
01849 }
01850
01851
01853
01854
01855
01856
01857
01858 void VPVolume::vpGetControlPoints(int cp[], VPColor c[], int &n) {
01859 controlTables.vpGetControlPoints(cp, c, n);
01860 }
01861
01862
01864
01865
01866
01867
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
01906
01907
01908
01909
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
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
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
01953
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
01972
01973
01974
01975
01976 VPPoint3D VPVolume::vpGetCenterFocalPoint() {
01977 return centerFocalPoint;
01978 }
01979
01980
01982
01983
01984
01985
01986
01987 unsigned int VPVolume::vpGetMinVolumeColor() {
01988 return minVolumeColor;
01989 }
01990
01991
01993
01994
01995
01996
01997
01998 unsigned int VPVolume::vpGetMaxVolumeColor() {
01999 return maxVolumeColor;
02000 }
02001
02002
02004
02005
02006
02007
02008
02009 VPTable VPVolume::vpGetControlTables() {
02010 return controlTables;
02011 }
02012
02013
02015
02016
02017
02018
02019
02020
02021
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
02039
02040
02041
02042
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
02070
02071
02072
02073
02074 VPPoint3D VPVolume::vpGetScale() {
02075 return scale;
02076 }
02077
02078
02080
02081
02082
02083
02084
02085 VPPoint2D VPVolume::vpGetSliceViewSBandPoint() {
02086 return slice.vpGetViewSBandPoint();
02087 }
02088
02089
02091
02092
02093
02094
02095
02096 VPPoint2D VPVolume::vpGetSliceViewTBandPoint() {
02097 return slice.vpGetViewTBandPoint();
02098 }
02099
02100
02102
02103
02104
02105
02106
02107 int VPVolume::vpGetFileType() {
02108 return fileType;
02109 }
02110
02111
02113
02114
02115
02116
02117
02118
02119 void VPVolume::vpSetCameraLocationForInnerStructure(VPPoint3D c) {
02120 cameraLocationForInnerStructure = c;
02121 }
02122
02123
02125
02126
02127
02128
02129
02130
02131
02132 VPPoint3D VPVolume::vpGetCameraLocationForInnerStructure(){
02133 return cameraLocationForInnerStructure;
02134 }