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

object-simple.c

Go to the documentation of this file.
00001 /************************************************************************* 00002 * $Id: object-simple.c,v 1.9 2005/09/09 11:41:16 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 00036 #include "object-simple.h" 00037 00038 #include <idseq.h> 00039 #include <idacr.h> 00040 #include <string.h> 00041 #include <idvol.h> 00042 #include "display.h" 00043 00056 OBJECT3D * CreateHomogeneousObject(int dimx,int dimy,int dimz,int t1,int t2,int ro) 00057 { 00058 OBJECT3D * object; 00059 int nbparam,nbcomp; 00060 int i,j,k; 00061 00062 nbcomp = 1; /* We only consider the water proton */ 00063 nbparam= 3; /* ro, t1, t2 */ 00064 object = AllocObject(dimx,dimy,dimz,nbcomp,nbparam); 00065 00066 for (i=0;i<dimx;i++) for(j=0;j<dimy;j++) for(k=0;k<dimz;k++) 00067 SetObjectPoint(object,i,j,k,ro,t1,t2,WATER); 00068 00069 return(object); 00070 } 00071 00091 void SetSphericalObject(OBJECT3D * object, 00092 int radius, 00093 int dimx, int dimy, int dimz, 00094 int ox, int oy, int oz, 00095 int t1s, int t2s, int ros, 00096 int t1b, int t2b, int rob, int fill_all) 00097 { 00098 int i,j,k; 00099 00100 /* Few verifications verifications */ 00101 if ((object->nbparam !=3)||(object->nbcomponent!=1)) 00102 { 00103 printf("The number of object values is not correct !\n"); 00104 exit(0); 00105 } 00106 if (!((object->x==dimx)&&(object->y==dimy)&&(object->z==dimz))) 00107 { 00108 printf("The object size is not correct !\n"); 00109 exit(0); 00110 } 00111 00112 /* filling the object */ 00113 for (i=0;i<dimx;i++) for(j=0;j<dimy;j++) for(k=0;k<dimz;k++) 00114 { 00115 if ((i - ox) * (i - ox) + (j - oy) * (j - oy) + 00116 (k - oz) * (k - oz) < radius * radius) { 00117 SetObjectPoint(object,i,j,k,ros,t1s,t2s,WATER); 00118 } else { 00119 if (fill_all) { 00120 SetObjectPoint(object,i,j,k,rob,t1b,t2b,WATER); 00121 } 00122 } 00123 } 00124 } 00125 00146 OBJECT3D * CreateSphericalObject( 00147 int radius, 00148 int dimx, int dimy, int dimz, 00149 int ox, int oy, int oz, 00150 int t1s, int t2s, int ros, 00151 int t1b, int t2b, int rob, int fill_all) 00152 { 00153 OBJECT3D * object; 00154 int nbparam,nbcomp; 00155 00156 nbcomp = 1; /* We only consider the water protons */ 00157 nbparam= 3; /* ro, t1, t2 */ 00158 object = AllocObject(dimx,dimy,dimz,nbcomp,nbparam); 00159 SetSphericalObject(object,radius,dimx,dimy,dimz,ox,oy,oz,t1s,t2s,ros,t1b,t2b,rob,fill_all); 00160 return(object); 00161 } 00162 00163 00184 void SetEllipticalObject(OBJECT3D *object, 00185 int rx, int ry, int rz, 00186 int dimx, int dimy, int dimz, 00187 int ox, int oy, int oz, 00188 int t1s, int t2s, int ros, 00189 int t1b, int t2b, int rob, int fill_all) 00190 { 00191 int i,j,k; 00192 00193 /* Few verifications */ 00194 if ((object->nbparam !=3)||(object->nbcomponent!=1)) 00195 { 00196 printf("The number of object values is not correct !\n"); 00197 exit(0); 00198 } 00199 if (!((object->x==dimx)&&(object->y==dimy)&&(object->z==dimz))) 00200 { 00201 printf("The object size is not correct !\n"); 00202 exit(0); 00203 } 00204 00205 /* Filling the object */ 00206 for (i=0;i<dimx;i++) for(j=0;j<dimy;j++) for(k=0;k<dimz;k++) 00207 { 00208 if ((i-ox)*(i-ox) / (1.0*rx*rx) + (j-oy)*(j-oy) / (1.0*ry*ry) 00209 + (k-oz)*(k-oz) / (1.0*rz*rz) < 1) { 00210 SetObjectPoint(object,i,j,k,ros,t1s,t2s,WATER); 00211 } else { 00212 if (fill_all) { 00213 SetObjectPoint(object,i,j,k,rob,t1b,t2b,WATER); 00214 } 00215 } 00216 } 00217 } 00218 00219 00242 OBJECT3D * CreateEllipticalObject( 00243 int rx, int ry, int rz, 00244 int dimx, int dimy, int dimz, 00245 int ox, int oy, int oz, 00246 int t1s, int t2s, int ros, 00247 int t1b, int t2b, int rob, int fill_all) 00248 { 00249 OBJECT3D * object; 00250 int nbparam,nbcomp; 00251 00252 nbcomp = 1; /* We only consider the water protons */ 00253 nbparam= 3; /* ro, t1, t2 */ 00254 object = AllocObject(dimx,dimy,dimz,nbcomp,nbparam); 00255 SetEllipticalObject(object,rx,ry,rz,dimx,dimy,dimz,ox,oy,oz,t1s,t2s,ros,t1b,t2b,rob,fill_all); 00256 00257 return(object); 00258 } 00259 00280 void SetSphericalCylindricObject(OBJECT3D * object, 00281 int radius, 00282 int dimx, int dimy, int dimz, 00283 int ox, int oy, 00284 int t1s, int t2s, int ros, 00285 int t1b, int t2b, int rob, int fill_all) 00286 { 00287 int i,j,k; 00288 00289 /* Few verifications */ 00290 if ((object->nbparam !=3)||(object->nbcomponent!=1)) 00291 { 00292 printf("The number of object values is not correct !\n"); 00293 exit(0); 00294 } 00295 if (!((object->x==dimx)&&(object->y==dimy)&&(object->z==dimz))) 00296 { 00297 printf("The object size is not correct !\n"); 00298 exit(0); 00299 } 00300 00301 /* Filling the object */ 00302 for (i=0;i<dimx;i++) for(j=0;j<dimy;j++) for(k=0;k<dimz;k++) 00303 { 00304 if ((i - ox) * (i - ox) + (j - oy) * (j - oy) < radius * radius) { 00305 SetObjectPoint(object,i,j,k,ros,t1s,t2s,WATER); 00306 } else { 00307 if (fill_all) { 00308 SetObjectPoint(object,i,j,k,rob,t1b,t2b,WATER); 00309 } 00310 } 00311 } 00312 } 00313 00334 void SetEllipticalCylindricObject(OBJECT3D *object, 00335 int rx, int ry, 00336 int dimx, int dimy, int dimz, 00337 int ox, int oy, 00338 int t1s, int t2s, int ros, 00339 int t1b, int t2b, int rob,int fill_all) 00340 { 00341 int i,j,k; 00342 00343 /* Few verifications */ 00344 if ((object->nbparam !=3)||(object->nbcomponent!=1)) 00345 { 00346 printf("The number of object values is not correct !\n"); 00347 exit(0); 00348 } 00349 if (!((object->x==dimx)&&(object->y==dimy)&&(object->z==dimz))) 00350 { 00351 printf("The object size is not correct !\n"); 00352 exit(0); 00353 } 00354 00355 /* Filling the object */ 00356 for (i=0;i<dimx;i++) for(j=0;j<dimy;j++) for(k=0;k<dimz;k++) 00357 { 00358 if ((i-ox)*(i-ox)/(1.0*rx*rx)+(j-oy)*(j-oy)/(1.0*ry*ry)<1) 00359 { 00360 SetObjectPoint(object,i,j,k,ros,t1s,t2s,WATER); 00361 } else 00362 { 00363 if (fill_all) { 00364 SetObjectPoint(object,i,j,k,rob,t1b,t2b,WATER); 00365 } 00366 } 00367 } 00368 } 00369 00381 void ClearZplane(OBJECT3D *object,int first, int last, 00382 int dimx, int dimy, int dimz) 00383 { 00384 int i,j,k; 00385 for (k=first;k<=last;k++) 00386 for (i=0;i<dimx;i++) for(j=0;j<dimy;j++) 00387 { 00388 SetObjectPoint(object,i,j,k,1,1,1,WATER); 00389 } 00390 } 00391 00408 void SetLinearObject1D(OBJECT3D* object,int rodeb,int rofin,int t1deb,int t1fin,int t2deb,int t2fin, 00409 int xdeb,int xfin,int component) 00410 { 00411 int roa,t1a,t2a; 00412 int rob,t1b,t2b; 00413 int i; 00414 int t1,t2,ro; 00415 00416 roa= (int)( (rofin-rodeb)/(xfin-xdeb) ); t1a=(int)( (t1fin-t1deb)/(xfin-xdeb) ); t2a=(int)( (t2fin-t2deb)/(xfin-xdeb) ); 00417 rob=rofin-roa*xfin; t1b=t1fin-t1a*xfin;t2b=t2fin-t2a*xfin; 00418 for (i=xdeb;i<xfin;i++) 00419 { 00420 ro=(int)(roa*i+rob) ; t1=(int)(t1a*i+t1b) ; t2=(int)(t2a*i+t2b); 00421 SetObjectPoint(object,i,0,0,ro,t1,t2,component); 00422 } 00423 } 00424 00435 OBJECT3D * Create2DTestObjectCircleEllipseSquare(int nx,int ny) 00436 { 00437 OBJECT3D * object; 00438 int nz=1; 00439 int ro,t1,t2; 00440 int rx,ry, ox, oy; 00441 int i,j,k; 00442 int radius; 00443 00444 object = (OBJECT3D *) AllocObject(nx,ny,nz,1,3); 00445 00446 /* Background filling */ 00447 //t1=100; t2=50; ro=0; 00448 t1=500; t2=70; ro=50; 00449 k=0; 00450 for (i=0;i<nx;i++) for(j=0;j<ny;j++) 00451 SetObjectPoint(object,i,j,k,ro,t1,t2,WATER); 00452 00453 /* Circle filling */ 00454 if (nx<ny) radius=nx/8; 00455 else radius=ny/8; 00456 ox=nx/4; oy=ny/8; 00457 k=0; 00458 //t1=400; t2=50; ro=100; 00459 t1=500; t2=70; ro=100; 00460 for (i=0;i<nx;i++) for(j=0;j<ny;j++) 00461 if ((i - ox) * (i - ox) + (j - oy) * (j - oy) < radius * radius) 00462 SetObjectPoint(object,i,j,k,ro,t1,t2,WATER); 00463 00464 /* Square filling */ 00465 t1=2500; t2=70; ro=100; 00466 for (i=4*nx/10;i<6*nx/10;i++) for(j=4*ny/10;j<6*ny/10;j++) 00467 SetObjectPoint(object,i,j,k,ro,t1,t2,WATER); 00468 00469 /* Ellipse filling */ 00470 rx=nx/4; ry=ny/8; 00471 ox=3*nx/4; oy=3*ny/4; 00472 k=0; 00473 //t1=200; t2=50; ro=100; 00474 t1=500; t2=150; ro=100; 00475 for (i=0;i<nx;i++) for(j=0;j<ny;j++) 00476 if ((i-ox)*(i-ox)/(1.0*rx*rx)+(j-oy)*(j-oy)/(1.0*ry*ry)<1) 00477 SetObjectPoint(object,i,j,k,ro,t1,t2,WATER); 00478 00479 return(object); 00480 } 00481 00482 00493 OBJECT3D * Create2DTestObjectRectangleRoGradient(int nx,int ny, int lx, int ly) 00494 { 00495 00496 OBJECT3D * object; 00497 int nz=1; 00498 int ro,t1,t2; 00499 int i,j,k; 00500 int slope; /* in ro/pixel*/ 00501 int x1,x2,y1,y2,ro_point; 00502 00503 00504 object = (OBJECT3D *) AllocObject(nx,ny,nz,1,3); 00505 00506 t1=100; t2=50; ro=0; slope= 10; 00507 k=0; 00508 x1=(int)(0.5*(nx-lx)); 00509 x2=(int)(0.5*(nx+lx)); 00510 y1=(int)(0.5*(ny-ly)); 00511 y2=(int)(0.5*(ny+ly)); 00512 00513 /* Background filling*/ 00514 for (i=0;i<nx;i++) for(j=0;j<ny;j++) 00515 SetObjectPoint(object,i,j,k,ro,t1,t2,WATER); 00516 00517 00518 /* Rectangle filling */ 00519 00520 for (i=x1;i<x2;i++) for(j=y1;j<y2;j++) 00521 { 00522 ro_point=(int)(ro+slope*(i-x1)); 00523 SetObjectPoint(object,i,j,k,ro_point,t1,t2,WATER); 00524 } 00525 return(object); 00526 } 00527 00528 00529 /************************************************** 00530 * \ingroup object 00531 * \brief Set a cone within an object 00532 * \param object Pointer on the object 00533 * \param dimx x object size in voxel 00534 * \param dimy y object size in voxel 00535 * \param dimz z object size in voxel 00536 * \param ox Cone centre position along x 00537 * \param oy Cone centre position along y 00538 * \param r Basis circle radius at z=0 00539 * \param h Cone high 00540 * \param t1s t1 value inside the cone 00541 * \param t2s t2 value inside the cone 00542 * \param ros ro value inside the cone 00543 * \param t1b t1 value outside the cone 00544 * \param t2b t2 value outside the cone 00545 * \param rob ro value outside the cone 00546 * \param fill_all Filling the outside (Yes=1, No=0) 00547 **************************************************/ 00548 void SetObjectCone(OBJECT3D * object, 00549 int dimx, int dimy, int dimz, 00550 int r, int h, 00551 int ox, int oy, 00552 int t1s, int t2s, int ros, 00553 int t1b, int t2b, int rob, int fill_all) 00554 { 00555 int i,j,k; 00556 float radius; 00557 00558 00559 /* Few verifications */ 00560 if ((object->nbparam !=3)||(object->nbcomponent!=1)) 00561 { 00562 printf("The number of object values is not correct !\n"); 00563 exit(0); 00564 } 00565 if (!((object->x==dimx)&&(object->y==dimy)&&(object->z==dimz))) 00566 { 00567 printf("The object size is not correct !\n"); 00568 exit(0); 00569 } 00570 00571 for(k=0;k<h;k++) 00572 { 00573 radius = -(float)k/(float)h*r+r; 00574 00575 for(i=0;i<dimx;i++) for(j=0;j<dimy;j++) 00576 00577 { 00578 if (((i-ox)*(i-ox) + (j-oy)*(j-oy))< (radius * radius)) 00579 { 00580 SetObjectPoint(object,i,j,k,ros,t1s,t2s,WATER); 00581 } 00582 else 00583 { 00584 if (fill_all) 00585 { 00586 SetObjectPoint(object,i,j,k,rob,t1b,t2b,WATER); 00587 } 00588 } 00589 } 00590 } 00591 00592 00593 }

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