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

object.c

Go to the documentation of this file.
00001 /************************************************************************* 00002 * $Id: object.c,v 1.10 2005/09/26 10:19:34 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 its 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 "object.h" 00036 #include "object-simple.h" 00037 #include "object-ki.h" 00038 #include "object-compound.h" 00039 #include "object-brain.h" 00040 00041 #include <idseq.h> 00042 #include <idacr.h> 00043 #include <string.h> 00044 #include <idvol.h> 00045 #include "display.h" 00046 00062 OBJECT3D* GetTestObject2D(int obj, int x,int y, double db0) 00063 { 00064 OBJECT3D *object; 00065 PPPVOLUME_UCHAR vol,label; 00066 PPIMAGE_FLOAT value; 00067 int z; 00068 00069 z=1; 00070 switch(obj) 00071 { 00072 case 1: 00073 { 00074 object=Create2DTestObjectCircleEllipseSquare(x,y); 00075 break; 00076 } 00077 case 2: 00078 { 00079 /* tacq=8, TE=20 TR=2500 gives a nice contrast with this object*/ 00080 object=CreateObjectBiComponent2DCircle(x,y); 00081 break; 00082 } 00083 case 3: 00084 { 00085 object=CreateObject2DCircleKi(x,y); 00086 break; 00087 } 00088 case 5: 00089 { 00090 object=CreateSphericalObject((int)(x/2.5),x,y,1,(int)x/2,(int)y/2,1,500,70,77,0,0,0,1); 00091 break; 00092 } 00093 case 4: /* Brain */ 00094 { 00095 // tacq=10.0; TE=25.0; TR=500.0; /* T1 contrast */ 00096 // tacq=10.0; TE=100.0; TR=2000.0; /* T2 contrast */ 00097 // tacq=10.0; TE=22.0; TR=2000.0; /* ro contrast */ 00098 vol = ReadLabelVolume("brainlabelz126.raw",256,256,1); 00099 switch(x) 00100 { 00101 case 256: 00102 { 00103 label= GetVolumeVOI(vol,0,0,0,x,y,z); 00104 } 00105 break; 00106 case 128: 00107 { 00108 label= GetVolumeVOI(vol,38,24,0,x,y,z); 00109 } 00110 break; 00111 case 64: 00112 { 00113 label= GetVolumeVOI(vol,38,24,0,x,y,z); 00114 } 00115 break; 00116 default: 00117 { 00118 x=32;y=32;z=1; 00119 label= GetVolumeVOI(vol,60,60,0,x,y,z); 00120 } 00121 break; 00122 } 00123 IdVolFree(vol); 00124 value = GetBrainPhysicalValues(1.0); 00125 object = LabelToObject(label,value); 00126 IdImaFree(value); 00127 break; 00128 } 00129 default: 00130 { 00131 printf("Unknown object number !!\n"); 00132 exit(0); 00133 break; 00134 } 00135 } 00136 SetObjectSize(object,(float)0.2,(float)0.2,(float)0.002); 00137 SetObjectDeltaB0(object,db0); 00138 00139 return(object); 00140 } 00141 00158 OBJECT3D* GetTestObject3D(int obj, int x, int y, int z, double db0) 00159 { 00160 OBJECT3D *object; 00161 00162 switch(obj) 00163 { 00164 case 1: 00165 { 00166 object=CreateObject3DSphereEllipse(x,y,z); 00167 break; 00168 } 00169 case 2: 00170 { 00171 object=CreateObjectBiComponent3DSphere(x,y,z); 00172 break; 00173 } 00174 default: 00175 { 00176 printf("Unknown object number !!\n"); 00177 exit(0); 00178 break; 00179 } 00180 } 00181 SetObjectSize(object,(float)0.2,(float)0.2,(float)0.2); 00182 SetObjectDeltaB0(object,db0); 00183 00184 return(object); 00185 } 00186 00187 00195 void SaveObjectAsVolFloat(OBJECT3D *object) 00196 { 00197 PPPVOLUME_FLOAT volfloat; 00198 int x,y,z; 00199 int i,j,k; 00200 char nom[80]; 00201 nom[0]='\0'; 00202 00203 x=object->x; 00204 y=object->y; 00205 z=object->z; 00206 00207 volfloat = (PPPVOLUME_FLOAT) IdVolAlloc(x,y,z,VOL_FLOAT); 00208 if (!volfloat) 00209 { 00210 printf("Impossible d'allouer volfloat ! \n"); 00211 exit(0); 00212 } 00213 00214 for(k=0;k<z;k++) for(j=0;j<y;j++) for (i=0;i<x;i++) 00215 volfloat[k][j][i] = (float) object->values[0][k][j][i]; 00216 strcpy(nom,"volWATERro.vol"); 00217 IdAcrWriteFile(nom,volfloat); 00218 00219 for(k=0;k<z;k++) for(j=0;j<y;j++) for (i=0;i<x;i++) 00220 volfloat[k][j][i] = (float) object->values[1][k][j][i]; 00221 strcpy(nom,"volWATERt1.vol"); 00222 IdAcrWriteFile(nom,volfloat); 00223 00224 for(k=0;k<z;k++) for(j=0;j<y;j++) for (i=0;i<x;i++) 00225 volfloat[k][j][i] = (float) object->values[2][k][j][i]; 00226 strcpy(nom,"volWATERt2.vol"); 00227 IdAcrWriteFile(nom,volfloat); 00228 00229 if (object->component ==2) 00230 { 00231 for(k=0;k<z;k++) for(j=0;j<y;j++) for (i=0;i<x;i++) 00232 volfloat[k][j][i] = (float) object->values[3][k][j][i]; 00233 strcpy(nom,"volFATro.vol"); 00234 IdAcrWriteFile(nom,volfloat); 00235 00236 00237 for(k=0;k<z;k++) for(j=0;j<y;j++) for (i=0;i<x;i++) 00238 volfloat[k][j][i] = (float) object->values[4][k][j][i]; 00239 strcpy(nom,"volFATt1.vol"); 00240 IdAcrWriteFile(nom,volfloat); 00241 00242 for(k=0;k<z;k++) for(j=0;j<y;j++) for (i=0;i<x;i++) 00243 volfloat[k][j][i] = (float) object->values[5][k][j][i]; 00244 strcpy(nom,"volFATt2.vol"); 00245 IdAcrWriteFile(nom,volfloat); 00246 IdVolFree(volfloat); 00247 } 00248 } 00249 00262 OBJECT3D* AllocObject(int x, int y, int z, int nbcomp, int nbparam) 00263 { 00264 OBJECT3D *object; 00265 int i,j,k,t; 00266 int nbvol; 00267 00268 nbvol = nbcomp*nbparam; 00269 00270 object = (OBJECT3D *) malloc(sizeof(OBJECT3D)); 00271 if (!object) 00272 { 00273 printf("Unable to allocate an OBJECT3D ! \n"); 00274 exit(0); 00275 } 00276 00277 object->values = (PPPPSEQUENCE_USHORT) IdSeqAlloc(x,y,z,nbvol,SEQ_USHORT); 00278 if (!object->values) 00279 { 00280 printf("Unable to allocate a SEQUENCE ! \n"); 00281 exit(0); 00282 } 00283 00284 for (t=0;t<nbvol;t++) 00285 for (i=0;i<x;i++) for (j=0;j<y;j++) for (k=0;k<z;k++) 00286 { 00287 object->values[t][k][j][i]=0; 00288 } 00289 00290 object->chemshift = (PSIGNAL_FLOAT)IdSigAlloc(nbcomp,SIG_FLOAT); 00291 if (!object->chemshift) 00292 { 00293 printf("Unable to allocate SIGNAL! \n"); 00294 exit(0); 00295 } 00296 for (t=0;t<nbcomp;t++) 00297 { 00298 object->chemshift[t]=0.0; 00299 } 00300 00301 object->deltaB0 = (PPPVOLUME_FLOAT)IdVolAlloc(x,y,z,VOL_FLOAT); 00302 if (!object->deltaB0) 00303 { 00304 printf("Unable to allocate VOLUME! \n"); 00305 exit(0); 00306 } 00307 00308 for (i=0;i<x;i++) for (j=0;j<y;j++) for (k=0;k<z;k++) 00309 { 00310 object->deltaB0[k][j][i]=0.0; 00311 } 00312 00313 object->fielddefault = (PPPVOLUME_FLOAT)IdVolAlloc(x,y,z,VOL_FLOAT); 00314 if (!object->fielddefault) 00315 { 00316 printf("Unable to allocate VOLUME! \n"); 00317 exit(0); 00318 } 00319 00320 for (i=0;i<x;i++) for (j=0;j<y;j++) for (k=0;k<z;k++) 00321 { 00322 object->fielddefault[k][j][i]=0.0; 00323 } 00324 00325 object->x=x; object->y=y;object->z=z; 00326 object->nbcomponent=nbcomp; 00327 object->nbparam=nbparam; 00328 object->component=0; /* Default active component = 0 */ 00329 00330 /* We give to the object a size of 1x1x1 meter */ 00331 object->lx=1.0; object->ly=1.0;object->lz=1.0; 00332 00333 return(object); 00334 } 00335 00342 void FreeObject(OBJECT3D * object) 00343 { 00344 IdSeqFree(object->values); 00345 IdVolFree(object->fielddefault); 00346 IdVolFree(object->deltaB0); 00347 if (object->chemshift!=NULL) IdSigFree(object->chemshift); 00348 free(object); 00349 } 00350 00361 void SetObjectSize(OBJECT3D *object, float lx, float ly, float lz) 00362 { 00363 object->lx = lx; 00364 object->ly = ly; 00365 object->lz = lz; 00366 } 00367 00375 void SetObjectActiveComponent(OBJECT3D *object, int component) 00376 { 00377 object->component = component; 00378 } 00379 00388 void SetObjectDeltaB0(OBJECT3D *object, double deltab0) 00389 { 00390 int i,j,k; 00391 for (i=0;i<object->x;i++) for (j=0;j<object->y;j++) for (k=0;k<object->z;k++) 00392 { 00393 object->deltaB0[k][j][i]=(float) deltab0; 00394 } 00395 } 00396 00405 void SetObjectChemicalShift(OBJECT3D * object,float edw,int component) 00406 { 00407 object->chemshift[component]=edw; 00408 } 00409 00410 00424 void SetObjectPoint(OBJECT3D *object,int x,int y,int z, 00425 int ro,int t1,int t2,int component 00426 ) 00427 { 00428 int i; 00429 i=component*object->nbparam; 00430 object->values[0+i][z][y][x] = ro; 00431 object->values[1+i][z][y][x] = t1; 00432 object->values[2+i][z][y][x] = t2; 00433 } 00434 00443 void WriteObject(OBJECT3D * object, char * name) 00444 { 00445 IdAcrWriteFile(name,(PPPPSEQUENCE)object->values); 00446 } 00447 00456 OBJECT3D* ReadObject(char * name) 00457 { 00458 PPPPSEQUENCE_USHORT seq; 00459 OBJECT3D * object; 00460 int x,y,z,nbparam,nbcomp,nbvol; 00461 int t,i,j,k; 00462 float lx,ly,lz; 00463 00464 seq = (PPPPSEQUENCE_USHORT) IdAcrReadFile(name,SEQ_USHORT); 00465 x = IdSeqDimX(seq); 00466 y = IdSeqDimY(seq); 00467 z = IdSeqDimZ(seq); 00468 nbvol = IdSeqDimT(seq); 00469 00470 if (nbvol>3) 00471 { 00472 nbparam=3; /* Default value : ro,t1,t2 */ 00473 nbcomp= 2; /* Default value : 2, WATER and FAT*/ 00474 } 00475 else 00476 { 00477 nbparam=3; /* Default value : ro,t1,t2 */ 00478 nbcomp= 1; /* Default value : 1, WATER */ 00479 } 00480 lx=1.0; ly=1.0; lz=1.0; 00481 00482 object = (OBJECT3D *) AllocObject(x,y,z,nbcomp,nbparam); 00483 for(t=0;t<nbvol;t++) 00484 for(i=0;i<x;i++) for(j=0;j<y;j++) for(k=0;k<z;k++) 00485 { 00486 /* Not very efficient, better possible using memcpy ! */ 00487 object->values[t][k][j][i]=seq[t][k][j][i]; 00488 } 00489 IdSeqFree(seq); 00490 00491 object->nbcomponent=nbcomp; 00492 object->nbparam=nbparam; 00493 object->lx=lx; object->ly=ly; object->lz=lz; 00494 object->x=x; object->y=y; object->z=z; 00495 00496 return(object); 00497 }

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