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

object-ki.c

Go to the documentation of this file.
00001 /************************************************************************* 00002 * $Id: object-ki.c,v 1.9 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 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-ki.h" 00036 00037 #include <idseq.h> 00038 #include <idacr.h> 00039 #include <string.h> 00040 #include <idvol.h> 00041 #include "display.h" 00042 00054 void SetObjectFieldDefault1D(OBJECT3D* object,int posy,int posz,PPPVOLUME_FLOAT dech,int dimx) 00055 { 00056 int i; 00057 00058 for(i=0;i<dimx;i++) 00059 object->fielddefault[0][0][i]=dech[i][posy][posz]; 00060 } 00061 00073 void SetObjectFieldDefault2D(OBJECT3D* object,int pos,PPPVOLUME_FLOAT dech,int dimx,int dimy) 00074 { 00075 int i,j; 00076 PPIMAGE_FLOAT slice_dech=NULL; 00077 PPIMAGE_UCHAR slice=NULL; 00078 00079 /* visualisation of the field default slice which has been chosen */ 00080 slice_dech= (PPIMAGE_FLOAT)IdImaAlloc(dimx,dimy,IMA_FLOAT); 00081 for (i=0;i<dimx;i++) for(j=0;j<dimy;j++) 00082 slice_dech[j][i] = dech[i][j][pos]; 00083 00084 slice= (PPIMAGE_UCHAR)IdImaAlloc(dimx,dimy,IMA_UCHAR); 00085 IdImaRecadTo8((PPIMAGE)slice_dech,slice,-1.0,-1.0); 00086 DisplayImage2D(slice); 00087 00088 for (i=0;i<dimx;i++) for(j=0;j<dimy;j++) 00089 object->fielddefault[0][j][i]= dech[i][j][pos]; 00090 00091 IdImaFree(slice_dech); 00092 IdImaFree(slice); 00093 } 00094 00106 void SetObjectFieldDefault3D(OBJECT3D * object,PPPVOLUME_FLOAT dech,int dimx, int dimy,int dimz) 00107 { 00108 int i,j,k; 00109 for (i=0;i<dimx;i++) for(j=0;j<dimy;j++) for(k=0;k<dimz;k++) 00110 object->fielddefault[k][j][i]= dech[i][j][k]; 00111 } 00112 00120 void SetObjectFieldDefault(OBJECT3D * object,PPPVOLUME_FLOAT dech) 00121 { 00122 int i,j,k; 00123 for (i=0;i<IdVolDimX(dech);i++) for(j=0;j<IdVolDimY(dech);j++) for(k=0;k<IdVolDimZ(dech);k++) 00124 object->fielddefault[k][j][i]= dech[k][j][i]; 00125 } 00126 00127 00128 /************************************************** 00129 * \ingroup Object 00130 * \brief Set the ro, t1, t2, and ki values for one point of an object 00131 * \param object Pointer on the object 00132 * \param x x coordinate of the point 00133 * \param y x coordinate of the point 00134 * \param z x coordinate of the point 00135 * \param ro ro value 00136 * \param t1 t1 value 00137 * \param t2 t2 value 00138 * \param ki susceptibility value 00139 **************************************************/ 00140 void SetObjectPointSusceptibility(OBJECT3D *object,int x,int y,int z, 00141 int ro,int t1,int t2,int ki) 00142 { 00143 object->values[0][z][y][x] = ro; 00144 object->values[1][z][y][x] = t1; 00145 object->values[2][z][y][x] = t2; 00146 object->values[3][z][y][x] = ki; 00147 } 00148 00157 PVECTOR_FLOAT AllocInitVectFloat(int x) 00158 { 00159 PVECTOR_FLOAT vect; 00160 int i; 00161 00162 /*Allocation*/ 00163 vect=(PVECTOR_FLOAT) IdVectAlloc(x,VECT_FLOAT); 00164 if (!vect) 00165 { 00166 printf("Allocation error in AllocInitVectFloat ! \n"); 00167 exit(1); 00168 } 00169 00170 /*Initialisation*/ 00171 for (i=0;i<x;i++) 00172 vect[i]=0.0; 00173 00174 return vect; 00175 } 00176 00188 PPPVOLUME_FLOAT GetParamFromDataFile(char *filein,PSIGNAL_FLOAT datatab) 00189 { 00190 PPPVOLUME_UCHAR label; 00191 PPPVOLUME_FLOAT data; 00192 int nx,ny,nz; 00193 int x,y,z; 00194 00195 label = (PPPVOLUME_UCHAR) IdAcrReadFile(filein,VOL_UCHAR); 00196 nx=IdVolDimX(label); 00197 ny=IdVolDimY(label); 00198 nz=IdVolDimZ(label); 00199 00200 data=(PPPVOLUME_FLOAT)IdVolAlloc(nx,ny,nz,VOL_FLOAT); 00201 for (x=0;x<nx;x++) for (y=0;y<ny;y++) for(z=0;z<nz;z++) 00202 data[z][y][x]=datatab[label[z][y][x]]; 00203 IdVolFree(label); 00204 return data; 00205 } 00206 00218 OBJECT3D * CreateObject3DSphereKi(int dimx, int dimy, int dimz) 00219 { 00220 OBJECT3D * objet; 00221 int nbcomp,nbparam; 00222 int i,j,k; 00223 PPPVOLUME_FLOAT ro,t1,t2,ki,dech; 00224 PVECTOR_FLOAT roval,t1val,t2val,kival; 00225 char filelabel[80],filedech[80]; 00226 filelabel[0]='\0'; 00227 filedech[0]='\0'; 00228 00229 strcpy(filelabel,"hightresolution.vol"); 00230 strcpy(filedech,"Defchamps.vol"); 00231 00232 nbcomp = 1; 00233 nbparam= 4; /* ro, t1, t2 ,db */ 00234 objet = AllocObject(dimx,dimy,dimz,nbcomp,nbparam); 00235 00236 roval=AllocInitVectFloat(2); 00237 roval[0]=100; /* region 0 */ 00238 roval[1]=90; /* region 1 */ 00239 ro=GetParamFromDataFile(filelabel,roval); 00240 00241 t1val=AllocInitVectFloat(2); 00242 t1val[0]=90 ; /* region 0 */ 00243 t1val[1]=400; /* region 1 */ 00244 t1=GetParamFromDataFile(filelabel,t1val); 00245 00246 t2val=AllocInitVectFloat(2); 00247 t2val[0]=40 ; /* region 0 */ 00248 t2val[1]=50; /* region 1 */ 00249 t2=GetParamFromDataFile(filelabel,t2val); 00250 00251 kival=AllocInitVectFloat(2); 00252 kival[0]=0; /* region 0 */ 00253 kival[1]=-9.05e-6; /* region 1 */ 00254 ki=GetParamFromDataFile(filelabel,kival); 00255 00256 for (i=0;i<dimx;i++) for(j=0;j<dimy;j++) for(k=0;k<dimz;k++) 00257 SetObjectPointSusceptibility(objet,i,j,k,(int)ro[k][j][i],(int)t1[k][j][i],(int)t2[k][j][i],(int)ki[k][j][i]); 00258 00259 /* Reading the field default values in a file 00260 * This file has been obtained with one of the 00261 * suceptibility default computation method */ 00262 if (!strcmp(filedech,NULL)) 00263 { 00264 dech = (PPPVOLUME_FLOAT) IdAcrReadFile(filedech,VOL_FLOAT); 00265 SetObjectFieldDefault3D(objet,dech,dimx,dimy,dimz); 00266 } 00267 else 00268 { 00269 printf("Unable to read the field default values %s \n",filedech); 00270 exit(1); 00271 } 00272 00273 IdVolFree(ro); 00274 IdVolFree(t1); 00275 IdVolFree(t2); 00276 IdVolFree(ki); 00277 IdVolFree(dech); 00278 return(objet); 00279 } 00280 00281 00293 OBJECT3D * CreateObject2DCircleKi(int dimx, int dimy) 00294 { 00295 OBJECT3D * objet; 00296 int nbcomp,nbparam; 00297 int i,j,k; 00298 int z; 00299 PPPVOLUME_FLOAT ro,t1,t2,ki,dech; 00300 PVECTOR_FLOAT roval,t1val,t2val,kival; 00301 char filelabel[80], filedech[80]; 00302 filelabel[0]='\0'; 00303 filedech[0]='\0'; 00304 00305 strcpy(filelabel,"../data/sphere_64_10.vol"); 00306 strcpy(filedech,"../data/Defchamps_sphere_64_10.vol"); 00307 00308 nbcomp = 1; 00309 nbparam= 4; /* ro, t1, t2 ,db */ 00310 00311 objet = AllocObject(dimx,dimy,1,nbcomp,nbparam); 00312 00313 roval=AllocInitVectFloat(2); 00314 roval[0]=1000; /* region 0 */ 00315 roval[1]=0; /* region 1 */ 00316 ro=GetParamFromDataFile(filelabel,roval); 00317 IdVectFree(roval); 00318 00319 t1val=AllocInitVectFloat(2); 00320 t1val[0]=2000 ; /* region 0 */ 00321 t1val[1]=400; /* region 1 */ 00322 t1=GetParamFromDataFile(filelabel,t1val); 00323 IdVectFree(t1val); 00324 00325 t2val=AllocInitVectFloat(2); 00326 t2val[0]=200 ; /* region 0 */ 00327 t2val[1]=50; /* region 1 */ 00328 t2=GetParamFromDataFile(filelabel,t2val); 00329 IdVectFree(t2val); 00330 00331 /* remplissage avec du ki */ 00332 kival=AllocInitVectFloat(2); 00333 kival[0]=-9.05e-6; /* region 0 */ 00334 kival[1]=0; /* region 1 */ 00335 ki=GetParamFromDataFile(filelabel,kival); 00336 IdVectFree(kival); 00337 00338 k=0; 00339 z=dimx/2; /* Chosen slice */ 00340 for (i=0;i<dimx;i++) for(j=0;j<dimy;j++) 00341 SetObjectPointSusceptibility(objet,i,j,k,(int)ro[z][j][i],(int)t1[z][j][i],(int)t2[z][j][i],(int)ki[z][j][i]); 00342 00343 00344 /* Reading the field default values in a file 00345 * This file has been obtained with one of the 00346 * suceptibility default computation method */ 00347 dech = (PPPVOLUME_FLOAT)IdAcrReadFile(filedech,VOL_FLOAT); 00348 if (!dech) 00349 { 00350 printf("Unable to read the field default values %s \n",filedech); 00351 exit(1); 00352 } 00353 SetObjectFieldDefault2D(objet,z,dech,dimx,dimy); 00354 00355 IdVolFree(ro); 00356 IdVolFree(t1); 00357 IdVolFree(t2); 00358 IdVolFree(ki); 00359 IdVolFree(dech); 00360 return(objet); 00361 } 00362 00372 OBJECT3D * CreateObject1DSectionKi(int dimx) 00373 { 00374 OBJECT3D * objet; 00375 int nbcomp,nbparam; 00376 int i,j,k; 00377 int y,z; 00378 PPPVOLUME_FLOAT ro,t1,t2,ki; 00379 PPPVOLUME_FLOAT dech; 00380 PVECTOR_FLOAT roval,t1val,t2val,kival; 00381 char filelabel[80],filedech[80]; 00382 filelabel[0]='\0'; 00383 filedech[0]='\0'; 00384 00385 strcpy(filelabel,"../data/hightresolution.vol"); 00386 strcpy(filedech,"../data/Defchamps.vol"); 00387 00388 nbcomp = 1; 00389 nbparam= 4; /* ro, t1, t2 ,db */ 00390 00391 objet = AllocObject(dimx,1,1,nbcomp,nbparam); 00392 00393 roval=AllocInitVectFloat(2); 00394 roval[0]=0; /* region 0 */ 00395 roval[1]=100; /* region 1 */ 00396 ro=GetParamFromDataFile(filelabel,roval); 00397 IdVectFree(roval); 00398 00399 t1val=AllocInitVectFloat(2); 00400 t1val[0]=400 ; /* region 0 */ 00401 t1val[1]=2000; /* region 1 */ 00402 t1=GetParamFromDataFile(filelabel,t1val); 00403 IdVectFree(t1val); 00404 00405 t2val=AllocInitVectFloat(2); 00406 t2val[0]=50 ; /* region 0 */ 00407 t2val[1]=200; /* region 1 */ 00408 t2=GetParamFromDataFile(filelabel,t2val); 00409 IdVectFree(t2val); 00410 00411 kival=AllocInitVectFloat(2); 00412 kival[0]=-9.05e-6; /* region 0 */ 00413 kival[1]=0; /* region 1 */ 00414 ki=GetParamFromDataFile(filelabel,kival); 00415 IdVectFree(kival); 00416 00417 y=dimx/2; /* chosen line */ 00418 z=dimx/2; /* chosen slice */ 00419 00420 j=0; 00421 k=0; 00422 for (i=0;i<dimx;i++) 00423 { 00424 SetObjectPointSusceptibility(objet,i,j,k,(int)ro[z][y][i],(int)t1[z][y][i],(int)t2[z][y][i],(int)ki[z][y][i]); 00425 } 00426 00427 /* Reading the field default values in a file 00428 * This file has been obtained with one of the 00429 * suceptibility default computation method */ 00430 if (strcmp(filedech,"NULL")) 00431 { 00432 dech = (PPPVOLUME_FLOAT) IdAcrReadFile(filedech,VOL_FLOAT); 00433 SetObjectFieldDefault1D(objet,y,z,dech,dimx); 00434 } 00435 else 00436 { 00437 printf("Unable to read the field default values %s \n",filedech); 00438 exit(1); 00439 } 00440 IdVolFree(ro); 00441 IdVolFree(t1); 00442 IdVolFree(t2); 00443 IdVolFree(ki); 00444 IdVolFree(dech); 00445 return(objet); 00446 } 00447 00459 OBJECT3D * CreateObject2DKi(float RoExt, float RoInt, float T1Ext,float T1Int, float T2Ext, float T2Int, float KiExt, float KiInt, int dimx, int dimy, char *filelabel, char *filedech) 00460 { 00461 OBJECT3D * objet; 00462 int nbcomp,nbparam; 00463 int i,j,k; 00464 int z; 00465 PPPVOLUME_FLOAT ro,t1,t2,ki,dech; 00466 PVECTOR_FLOAT roval,t1val,t2val,kival; 00467 00468 nbcomp = 1; 00469 nbparam= 4; /* ro, t1, t2 ,db */ 00470 00471 objet = AllocObject(dimx,dimy,1,nbcomp,nbparam); 00472 00473 roval=AllocInitVectFloat(2); 00474 roval[0]=RoExt; /* region 0 */ 00475 roval[1]=RoInt; /* region 1 */ 00476 ro=GetParamFromDataFile(filelabel,roval); 00477 IdVectFree(roval); 00478 00479 t1val=AllocInitVectFloat(2); 00480 t1val[0]=T1Ext; /* region 0 */ 00481 t1val[1]=T1Int; /* region 1 */ 00482 t1=GetParamFromDataFile(filelabel,t1val); 00483 IdVectFree(t1val); 00484 00485 t2val=AllocInitVectFloat(2); 00486 t2val[0]=T2Ext ; /* region 0 */ 00487 t2val[1]=T2Int; /* region 1 */ 00488 t2=GetParamFromDataFile(filelabel,t2val); 00489 IdVectFree(t2val); 00490 00491 kival=AllocInitVectFloat(2); 00492 kival[0]=KiExt; /* region 0 */ 00493 kival[1]=KiInt; /* region 1 */ 00494 ki=GetParamFromDataFile(filelabel,kival); 00495 IdVectFree(kival); 00496 00497 k=0; 00498 z=dimx/2; /*Slice selection*/ 00499 for (i=0;i<dimx;i++) for(j=0;j<dimy;j++) 00500 { 00501 SetObjectPointSusceptibility(objet,i,j,k,(int)ro[z][j][i],(int)t1[z][j][i],(int)t2[z][j][i],(int)ki[z][j][i]); 00502 } 00503 00504 /* Reading the field default values in a file 00505 * This file has been obtained with one of the 00506 * suceptibility default computation method */ 00507 dech = (PPPVOLUME_FLOAT)IdAcrReadFile(filedech,VOL_FLOAT); 00508 if (!dech) 00509 { 00510 printf("Unable to read the field default values %s \n",filedech); 00511 exit(1); 00512 } 00513 SetObjectFieldDefault2D(objet,z,dech,dimx,dimy); 00514 00515 IdVolFree(ro); 00516 IdVolFree(t1); 00517 IdVolFree(t2); 00518 IdVolFree(ki); 00519 IdVolFree(dech); 00520 return(objet); 00521 } 00522

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