Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals

display.c

Go to the documentation of this file.
00001 /************************************************************************* 00002 * $Id: display.c,v 1.10 2005/09/09 20:44:21 yougz Exp $ 00003 ************************************************************************** 00004 This software is governed by the CeCILL license under French law and 00005 abiding by the rules of distribution of free software. You can use, 00006 modify and/ or redistribute the software under the terms of the CeCILL 00007 license as circulated by CEA, CNRS and INRIA at the following URL 00008 "http://www.cecill.info". 00009 00010 As a counterpart to the access to the source code and rights to copy, 00011 modify and redistribute granted by the license, users are provided only 00012 with a limited warranty and the software's author, the holder of the 00013 economic rights, and the successive licensors have only limited 00014 liability. 00015 00016 In this respect, the user's attention is drawn to the risks associated 00017 with loading, using, modifying and/or developing or reproducing the 00018 software by the user in light of is specific status of free software, 00019 that may mean that it is complicated to manipulate, and that also 00020 therefore means that it is reserved for developers and experienced 00021 professionals having in-depth computer knowledge. Users are therefore 00022 encouraged to load and test the software's suitability as regards their 00023 requirements in conditions enabling the security of their systems and/or 00024 data to be ensured and, more generally, to use and operate it in the 00025 same conditions as regards security. 00026 00027 The fact that you are presently reading this means that you have had 00028 knowledge of the CeCILL license and that you accept its terms. 00029 00030 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de 00031 l'Image). All rights reserved. See License.txt for details. 00032 00033 Version 1.0 05/09/2005 00034 *************************************************************************/ 00035 #include "display.h" 00036 #include <string.h> 00037 00048 void DisplayImage2D(PPIMAGE_UCHAR image) 00049 { 00050 00051 #if ! defined(BROKEN_IDIMADISPLAY) 00052 IdImaDisplay(image,0,0,0,IdImaDimX(image),IdImaDimY(image),0,0); 00053 #endif 00054 00055 } 00064 void DisplayObject3D(OBJECT3D* object,int deb,int nb,char *visuname) 00065 { 00066 PPPVOLUME_USHORT vol; 00067 int x,y,z,i,j,k; 00068 char txt[80]; 00069 00070 x=object->x; 00071 y=object->y; 00072 z=object->z; 00073 00074 vol =(PPPVOLUME_USHORT) IdVolAlloc(x,y,z,VOL_USHORT); 00075 if (!vol) 00076 { 00077 printf("Unable to allocate a ushort volume in DisplayOBJECT3D !\n"); 00078 exit(0); 00079 } 00080 00081 /* Display the first component considered to be water */ 00082 for (i=0;i<x;i++) for(j=0;j<y;j++) for(k=0;k<z;k++) /* T1 */ 00083 vol[k][j][i]=object->values[T1][k][j][i]; 00084 strcpy(txt,visuname); 00085 strcat(txt,"-T1 water"); 00086 DisplayVol((PPPVOLUME)vol,0,z,0,255,txt,0,"\0"); 00087 00088 for (i=0;i<x;i++) for(j=0;j<y;j++) for(k=0;k<z;k++) /* T2 */ 00089 vol[k][j][i]=object->values[T2][k][j][i]; 00090 strcpy(txt,visuname); 00091 strcat(txt,"-T2 water"); 00092 DisplayVol((PPPVOLUME)vol,0,z,0,255,txt,0,"\0"); 00093 00094 for (i=0;i<x;i++) for(j=0;j<y;j++) for(k=0;k<z;k++) /* RO */ 00095 vol[k][j][i]=object->values[RO][k][j][i]; 00096 strcpy(txt,visuname); 00097 strcat(txt,"-RO water"); 00098 DisplayVol((PPPVOLUME)vol,0,z,0,255,txt,0,"\0"); 00099 00100 /* Display the second component considered to be fat */ 00101 if (object->nbcomponent>1) 00102 { 00103 for (i=0;i<x;i++) for(j=0;j<y;j++) for(k=0;k<z;k++) /* T1 */ 00104 vol[k][j][i]=object->values[4][k][j][i]; 00105 strcpy(txt,visuname); 00106 strcat(txt,"-T1 Fat"); 00107 DisplayVol((PPPVOLUME)vol,0,z,0,255,txt,0,"\0"); 00108 00109 for (i=0;i<x;i++) for(j=0;j<y;j++) for(k=0;k<z;k++) /* T2 */ 00110 vol[k][j][i]=object->values[5][k][j][i]; 00111 strcpy(txt,visuname); 00112 strcat(txt,"-T2 Fat"); 00113 DisplayVol((PPPVOLUME)vol,0,z,0,255,txt,0,"\0"); 00114 00115 for (i=0;i<x;i++) for(j=0;j<y;j++) for(k=0;k<z;k++) /* RO */ 00116 vol[k][j][i]=object->values[3][k][j][i]; 00117 strcpy(txt,visuname); 00118 strcat(txt,"-RO Fat"); 00119 DisplayVol((PPPVOLUME)vol,0,z,0,255,txt,0,"\0"); 00120 } 00121 00122 IdVolFree(vol); 00123 } 00124 00125 00132 void DisplayObject2D (OBJECT3D* object,char * visuname) 00133 { 00134 register int i,j; 00135 int x,y,z; 00136 PPIMAGE_USHORT imashort; 00137 double min,max; 00138 PPIMAGE_UCHAR imauchar; 00139 char txt[80]; 00140 00141 txt[0]='\0'; 00142 00143 x=object->x; 00144 y=object->y; 00145 z=object->z; 00146 00147 if (z!=1) 00148 printf("Watchout, your object is not 2D \n!"); 00149 00150 imashort = (PPIMAGE_USHORT) IdImaAlloc(x,y,IMA_SHORT); 00151 if(!imashort) 00152 { 00153 printf("Impossible d'allouer imashort dans Displayobject2D !\n"); 00154 exit(0); 00155 } 00156 00157 imauchar = (PPIMAGE_UCHAR) IdImaAlloc(x,y,IMA_UCHAR); 00158 if(!imauchar) 00159 { 00160 printf("Impossible d'allouer imauchar dans Displayobject2D !\n"); 00161 exit(0); 00162 } 00163 00164 /* Display the first component considered to be water */ 00165 for (i=0;i<x;i++) for(j=0;j<y;j++) /* T1 */ 00166 imashort[j][i]=object->values[T1][0][j][i]; 00167 min = IdImaMinima((PPIMAGE)imashort); 00168 max = IdImaMaxima((PPIMAGE)imashort); 00169 if (max!=min) 00170 { 00171 for (i=0;i<x;i++) for(j=0;j<y;j++) 00172 imauchar[i][j]= (int)((imashort[i][j]-min)/(max-min)*255); 00173 } 00174 else 00175 { 00176 for (i=0;i<x;i++) for(j=0;j<y;j++) 00177 imauchar[i][j]= (int) min; 00178 } 00179 strcpy(txt,visuname); 00180 strcat(txt,"-T1 water"); 00181 IdSetFileName(imauchar,txt); 00182 DisplayImage2D(imauchar); 00183 for (i=0;i<x;i++) for(j=0;j<y;j++) /* T2 */ 00184 imashort[j][i]=object->values[T2][0][j][i]; 00185 min = IdImaMinima((PPIMAGE)imashort); 00186 max = IdImaMaxima((PPIMAGE)imashort); 00187 if (max!=min) 00188 { 00189 for (i=0;i<x;i++) for(j=0;j<y;j++) 00190 imauchar[i][j]= (int)((imashort[i][j]-min)/(max-min)*255); 00191 } 00192 else 00193 { 00194 for (i=0;i<x;i++) for(j=0;j<y;j++) 00195 imauchar[i][j]= (int) min; 00196 } 00197 strcpy(txt,visuname); 00198 strcat(txt,"-T2 water"); 00199 IdSetFileName(imauchar,txt); 00200 DisplayImage2D(imauchar); 00201 for (i=0;i<x;i++) for(j=0;j<y;j++) /* RO */ 00202 imashort[j][i]=object->values[RO][0][j][i]; 00203 min = IdImaMinima((PPIMAGE)imashort); 00204 max = IdImaMaxima((PPIMAGE)imashort); 00205 if (max!=min) 00206 { 00207 for (i=0;i<x;i++) for(j=0;j<y;j++) 00208 imauchar[i][j]= (int)((imashort[i][j]-min)/(max-min)*255); 00209 } 00210 else 00211 { 00212 for (i=0;i<x;i++) for(j=0;j<y;j++) 00213 imauchar[i][j]= (int) min; 00214 } 00215 strcpy(txt,visuname); 00216 strcat(txt,"-RO water"); 00217 IdSetFileName(imauchar,txt); 00218 DisplayImage2D(imauchar); 00219 00220 /* Display the second component considered to be fat */ 00221 if (object->nbcomponent>1) 00222 { 00223 for (i=0;i<x;i++) for(j=0;j<y;j++) /* Recopie de T1 */ 00224 imashort[j][i]=object->values[T1+3][0][j][i]; 00225 min = IdImaMinima((PPIMAGE)imashort); 00226 max = IdImaMaxima((PPIMAGE)imashort); 00227 if (max!=min) 00228 { 00229 for (i=0;i<x;i++) for(j=0;j<y;j++) 00230 imauchar[i][j]= (int)((imashort[i][j]-min)/(max-min)*255); 00231 } 00232 else 00233 { 00234 for (i=0;i<x;i++) for(j=0;j<y;j++) 00235 imauchar[i][j]= (int) min; 00236 } 00237 strcpy(txt,visuname); 00238 strcat(txt,"-T1 fat"); 00239 IdSetFileName(imauchar,txt); 00240 DisplayImage2D(imauchar); 00241 for (i=0;i<x;i++) for(j=0;j<y;j++) /* T2 */ 00242 imashort[j][i]=object->values[T2+3][0][j][i]; 00243 min = IdImaMinima((PPIMAGE)imashort); 00244 max = IdImaMaxima((PPIMAGE)imashort); 00245 if (max!=min) 00246 { 00247 for (i=0;i<x;i++) for(j=0;j<y;j++) 00248 imauchar[i][j]= (int)((imashort[i][j]-min)/(max-min)*255); 00249 } 00250 else 00251 { 00252 for (i=0;i<x;i++) for(j=0;j<y;j++) 00253 imauchar[i][j]= (int) min; 00254 } 00255 strcpy(txt,visuname); 00256 strcat(txt,"-T2 fat"); 00257 IdSetFileName(imauchar,txt); 00258 DisplayImage2D(imauchar); 00259 for (i=0;i<x;i++) for(j=0;j<y;j++) /* RO */ 00260 imashort[j][i]=object->values[RO+3][0][j][i]; 00261 min = IdImaMinima((PPIMAGE)imashort); 00262 max = IdImaMaxima((PPIMAGE)imashort); 00263 if (max!=min) 00264 { 00265 for (i=0;i<x;i++) for(j=0;j<y;j++) 00266 imauchar[i][j]= (int)((imashort[i][j]-min)/(max-min)*255); 00267 } 00268 else 00269 { 00270 for (i=0;i<x;i++) for(j=0;j<y;j++) 00271 imauchar[i][j]= (int) min; 00272 } 00273 strcpy(txt,visuname); 00274 strcat(txt,"-RO fat"); 00275 IdSetFileName(imauchar,txt); 00276 DisplayImage2D(imauchar); 00277 } 00278 IdImaFree(imauchar); 00279 IdImaFree(imashort); 00280 } 00281 00282 00289 void DisplayObject1D (OBJECT3D* object, char* visuname) 00290 { 00291 int i; 00292 int x,y,z; 00293 PSIGNAL_USHORT sig; 00294 PPIMAGE_UCHAR ima; 00295 char txt[80]; 00296 00297 txt[0]='\0'; 00298 00299 x=object->x; 00300 y=object->y; 00301 z=object->z; 00302 00303 if ((y!=1)||(z!=1)) 00304 printf("Watchout ! Your object is not 1D \n!"); 00305 00306 sig = (PSIGNAL_USHORT) IdSigAlloc(x,SIG_USHORT); 00307 if (!sig) 00308 { 00309 printf("Unable to allocate sig in DisplayObject1D !\n"); 00310 exit(0); 00311 } 00312 00313 /* Display the first component considered to be water */ 00314 for (i=0;i<x;i++) /* T1 */ 00315 sig[i]=object->values[1][0][0][i]; 00316 ima=IdImaSignalToImage(sig,0,x,0,-1,-1,x,128,255,0); 00317 strcpy(txt,visuname); 00318 strcat(txt,"-T1 Water"); 00319 IdSetFileName(ima,txt); 00320 DisplayImage2D(ima); 00321 IdImaFree(ima); 00322 for (i=0;i<x;i++) /* T2 */ 00323 sig[i]=object->values[2][0][0][i]; 00324 ima=IdImaSignalToImage(sig,0,x,0,-1,-1,x,128,255,0);; 00325 strcpy(txt,visuname); 00326 strcat(txt,"-T2 Water"); 00327 IdSetFileName(ima,txt); 00328 DisplayImage2D(ima); 00329 IdImaFree(ima); 00330 for (i=0;i<x;i++) /* RO */ 00331 sig[i]=object->values[0][0][0][i]; 00332 ima=IdImaSignalToImage(sig,0,x,0,-1,-1,x,128,255,0); 00333 strcpy(txt,visuname); 00334 strcat(txt,"-RO Water"); 00335 IdSetFileName(ima,txt); 00336 DisplayImage2D(ima); 00337 IdImaFree(ima); 00338 00339 /* Display the second component considered to be fat */ 00340 if (object->nbcomponent>1) 00341 { 00342 for (i=0;i<x;i++) /* T1 */ 00343 sig[i]=object->values[4][0][0][i]; 00344 ima=IdImaSignalToImage(sig,0,x,0,-1,-1,x,128,255,0); 00345 strcpy(txt,visuname); 00346 strcat(txt,"-T1 Fat"); 00347 IdSetFileName(ima,txt); 00348 DisplayImage2D(ima); 00349 IdImaFree(ima); 00350 for (i=0;i<x;i++) /* T2 */ 00351 sig[i]=object->values[5][0][0][i]; 00352 ima=IdImaSignalToImage(sig,0,x,0,-1,-1,x,128,255,0); 00353 strcpy(txt,visuname); 00354 strcat(txt,"-T2 Fat"); 00355 IdSetFileName(ima,txt); 00356 DisplayImage2D(ima); 00357 IdImaFree(ima); 00358 for (i=0;i<x;i++) /* RO */ 00359 sig[i]=object->values[3][0][0][i]; 00360 ima=IdImaSignalToImage(sig,0,x,0,-1,-1,x,128,255,0); 00361 strcpy(txt,visuname); 00362 strcat(txt,"-RO Fat"); 00363 IdSetFileName(ima,txt); 00364 DisplayImage2D(ima); 00365 IdImaFree(ima); 00366 } 00367 00368 IdSigFree(sig); 00369 } 00370 00385 void DisplayVol (PPPVOLUME vol,int deb, int nb, int recad, int N, char *visuname, int save, char *filename) 00386 { 00387 typedef unsigned char uchar; 00388 typedef unsigned short ushort; 00389 typedef unsigned long ulong; 00390 char blabla[400]; 00391 int X,Y,Z; 00392 PPPVOLUME_UCHAR voluchar; 00393 PPIMAGE_UCHAR ima; 00394 int i,j,k; 00395 int nbx,nby; 00396 int dimx,dimy; 00397 int x,y,compt; 00398 double mini,maxi; 00399 double val; 00400 00401 blabla[0]='\0'; 00402 00403 X=IdVolDimX(vol); Y=IdVolDimY(vol); Z=IdVolDimZ(vol); 00404 00405 voluchar = (PPPVOLUME_UCHAR) IdVolAlloc(X,Y,Z,VOL_UCHAR); 00406 if(!voluchar) 00407 { 00408 printf("Allocation failure of voluchar in DisplayVol !\n"); 00409 exit(0); 00410 } 00411 00412 #define ABSO 1 00413 #define LOG 2 00414 00415 #define RABS(type,tt) for(k=0;k<Z;k++) for(j=0;j<Y;j++) for(i=0;i<X;i++) \ 00416 ((type)vol)[k][j][i] = (tt) fabs((double)((type)vol)[k][j][i]); 00417 00418 #define RLOG(type,tt) for(k=0;k<Z;k++) for(j=0;j<Y;j++) for(i=0;i<X;i++) \ 00419 ((type)vol)[k][j][i] = (tt) log(1.0+fabs((double)((type)vol)[k][j][i])); 00420 00421 #define RECAD(type) for(k=0;k<Z;k++) for(j=0;j<Y;j++) for(i=0;i<X;i++) \ 00422 { \ 00423 val = (double) ((type)vol)[k][j][i]; \ 00424 val = (val-mini) / (maxi-mini) * N; \ 00425 if (val>255.0) val = 255.0; \ 00426 voluchar[k][j][i]=(unsigned char) val; \ 00427 } 00428 if (recad==ABSO) 00429 { 00430 switch(IdVolType(vol)) 00431 { 00432 case VOL_UCHAR: 00433 { 00434 RABS(PPPVOLUME_UCHAR,uchar); 00435 } 00436 break; 00437 case VOL_USHORT: 00438 { 00439 RABS(PPPVOLUME_USHORT,ushort); 00440 } 00441 break; 00442 case VOL_SHORT: 00443 { 00444 RABS(PPPVOLUME_SHORT,short); 00445 } 00446 break; 00447 case VOL_ULONG: 00448 { 00449 RABS(PPPVOLUME_ULONG,ulong); 00450 } 00451 break; 00452 case VOL_LONG: 00453 { 00454 RABS(PPPVOLUME_LONG,long); 00455 } 00456 break; 00457 case VOL_FLOAT: 00458 { 00459 RABS(PPPVOLUME_FLOAT,float); 00460 } 00461 break; 00462 case VOL_DOUBLE: 00463 { 00464 RABS(PPPVOLUME_DOUBLE,double); 00465 } 00466 break; 00467 default: 00468 { 00469 printf("This Volume type is not supported by DisplayVol !\n"); 00470 exit(0); 00471 } 00472 break; 00473 } 00474 } 00475 00476 if (recad==LOG) 00477 { 00478 switch(IdVolType(vol)) 00479 { 00480 case VOL_UCHAR: 00481 { 00482 RLOG(PPPVOLUME_UCHAR,uchar); 00483 } 00484 break; 00485 case VOL_USHORT: 00486 { 00487 RLOG(PPPVOLUME_USHORT,ushort); 00488 } 00489 break; 00490 case VOL_SHORT: 00491 { 00492 RLOG(PPPVOLUME_SHORT,short); 00493 } 00494 break; 00495 case VOL_ULONG: 00496 { 00497 RLOG(PPPVOLUME_ULONG,ulong); 00498 } 00499 break; 00500 case VOL_LONG: 00501 { 00502 RLOG(PPPVOLUME_LONG,long); 00503 } 00504 break; 00505 case VOL_FLOAT: 00506 { 00507 RLOG(PPPVOLUME_FLOAT,float); 00508 } 00509 break; 00510 case VOL_DOUBLE: 00511 { 00512 RLOG(PPPVOLUME_DOUBLE,double); 00513 } 00514 break; 00515 default: 00516 { 00517 printf("This Volume type is not supported by DisplayVol !\n"); 00518 exit(0); 00519 } 00520 break; 00521 } 00522 } 00523 00524 mini = IdVolMinima(vol); maxi = IdVolMaxima(vol); 00525 00526 switch(IdVolType(vol)) 00527 { 00528 case VOL_UCHAR: 00529 { 00530 RECAD(PPPVOLUME_UCHAR); 00531 } 00532 break; 00533 case VOL_USHORT: 00534 { 00535 RECAD(PPPVOLUME_USHORT); 00536 } 00537 break; 00538 case VOL_SHORT: 00539 { 00540 RECAD(PPPVOLUME_SHORT); 00541 } 00542 break; 00543 case VOL_ULONG: 00544 { 00545 RECAD(PPPVOLUME_ULONG); 00546 } 00547 break; 00548 case VOL_LONG: 00549 { 00550 RECAD(PPPVOLUME_LONG); 00551 } 00552 break; 00553 case VOL_FLOAT: 00554 { 00555 RECAD(PPPVOLUME_FLOAT); 00556 } 00557 break; 00558 case VOL_DOUBLE: 00559 { 00560 RECAD(PPPVOLUME_DOUBLE); 00561 } 00562 break; 00563 default: 00564 { 00565 printf("This Volume type is not supported by DisplayVol!\n"); 00566 exit(0); 00567 } 00568 break; 00569 } 00570 00571 if (nb+deb>Z) 00572 { 00573 printf("Nb > profondeur du volume !!! \n"); 00574 exit(0); 00575 } 00576 00577 nbx = (int) floor(sqrt((double)nb)); 00578 nby = nbx; 00579 dimx = nbx * X; 00580 dimy = nby * Y; 00581 00582 ima = (PPIMAGE_UCHAR) IdImaAlloc(dimx,dimy,IMA_UCHAR); 00583 if (!ima) 00584 { 00585 printf("Impossible d'allouer l'image de visu !\n"); 00586 exit(0); 00587 } 00588 for (i=0;i<dimy;i++) for(j=0;j<dimx;j++) 00589 ima[i][j]=0; 00590 compt = deb; 00591 for (y=0;y<nby;y++) for (x=0;x<nbx;x++) 00592 { 00593 if (compt<nb+deb) 00594 { 00595 for(i=0;i<Y;i++) for(j=0;j<X;j++) 00596 ima[i+y*Y][j+x*X] = voluchar[compt][i][j]; 00597 } 00598 compt++; 00599 } 00600 IdVolFree(voluchar); 00601 sprintf(blabla," %d -> %d",deb,deb+nb-1); 00602 strcat(blabla,visuname); 00603 IdSetFileName(ima,visuname); 00604 DisplayImage2D(ima); 00605 if (save==1) 00606 IdAcrWriteFile(filename,ima); 00607 IdImaFree(ima); 00608 } 00609 00618 void DisplayVolXY (PPPVOLUME vol,int z,char *visuname) 00619 { 00620 DisplayVol(vol,z,1,0,255,visuname,0,"\0"); 00621 } 00622 00634 void DisplayVolX (PPPVOLUME vol,int y,int z,char *visuname,int save,char *filename) 00635 { 00636 int i; 00637 int x; 00638 PSIGNAL_DOUBLE sig; 00639 PPIMAGE_UCHAR ima; 00640 char txt[80]; 00641 00642 txt[0]='\0'; 00643 sprintf(txt,"-Y:%d-Z:%d",y,z); 00644 strcat(txt,visuname); 00645 00646 x=IdVolDimX(vol); 00647 00648 sig = (PSIGNAL_DOUBLE) IdSigAlloc(x,SIG_DOUBLE); 00649 if (!sig) 00650 { 00651 printf("Impossible d'allouer sig !\n"); 00652 exit(0); 00653 } 00654 switch (IdVolType(vol)) 00655 { 00656 case VOL_DOUBLE: 00657 for (i=0;i<x;i++) sig[i]= (double) ((PPPVOLUME_DOUBLE)vol)[z][y][i]; 00658 break; 00659 case VOL_FLOAT: 00660 for (i=0;i<x;i++) 00661 { 00662 sig[i]= (double) ((PPPVOLUME_FLOAT)vol)[z][y][i]; 00663 } 00664 break; 00665 case VOL_UCHAR: 00666 for (i=0;i<x;i++) sig[i]= (double) ((PPPVOLUME_UCHAR)vol)[z][y][i]; 00667 break; 00668 default: 00669 { 00670 printf("Volume type not yet managed !\n"); 00671 exit(0); 00672 } 00673 break; 00674 } 00675 printf("sig[0]=%lf \n",sig[0]); 00676 printf("sig[%d]=%lf \n",x/4,sig[x/4]); 00677 printf("sig[%d]=%lf \n",x/2-1,sig[x/2-1]); 00678 printf("sig[%d]=%lf \n",x/2,sig[x/2]); 00679 printf("sig[%d]=%lf \n",x/2+1,sig[x/2+1]); 00680 printf("sig[%d]=%lf \n",x-1,sig[x-1]); 00681 00682 if (save==1) IdSigWriteRawFile(filename,(PSIGNAL) sig); 00683 00684 ima=IdImaSignalToImage(sig,0,x,0,-1,-1,x,128,255,0); 00685 IdSigFree(sig); 00686 IdSetFileName(ima,txt); 00687 DisplayImage2D(ima); 00688 IdImaFree(ima); 00689 }

Generated on Wed Oct 19 09:28:33 2005 for SIMRI3D by doxygen 1.3.7