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

reconstruction.c

Go to the documentation of this file.
00001 /************************************************************************* 00002 * $Id: reconstruction.c,v 1.18 2005/09/07 07:13:32 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 "reconstruction.h" 00037 00038 #include <stdio.h> 00039 #include <math.h> 00040 #include <idsig.h> 00041 #include <idima.h> 00042 #include <idvol.h> 00043 #include <iderr.h> 00044 #include <idprint.h> 00053 void VolRFFiltering(PPPVOLUME_COMPLEX_DOUBLE volrf,int type) 00054 { 00055 int i,j,k; 00056 double x,y,z; 00057 double w,d; 00058 00059 x= (double) IdVolDimX(volrf); 00060 y= (double) IdVolDimY(volrf); 00061 z= (double) IdVolDimZ(volrf); 00062 00063 switch(type) 00064 { 00065 case 0: /* Hanning */ 00066 { 00067 if ((x!=1)&&(y!=1)&&(z!=1)) /*3D*/ 00068 { 00069 for(k=0;k<z;k++) for(j=0;j<y;j++) for(i=0;i<x;i++) 00070 { 00071 d=sqrt((i-x/2.)*(i-x/2.)/x/x*4+(j-y/2.)*(j-y/2.)/y/y*4+(k-z/2)*(k-z/2.)/z/z*4); 00072 if (d>1.0) d=1.0; 00073 w=0.5 + 0.5*cos(M_PI*d); 00074 volrf[k][j][i].re=volrf[k][j][i].re * w; 00075 volrf[k][j][i].im=volrf[k][j][i].im * w; 00076 } 00077 } 00078 if ((x!=1)&&(y!=1)&&(z==1)) /*2D*/ 00079 { 00080 for(k=0;k<z;k++) for(j=0;j<y;j++) for(i=0;i<x;i++) 00081 { 00082 d=sqrt((i-x/2.)*(i-x/2.)/x/x*4+(j-y/2.)*(j-y/2.)/y/y*4); 00083 if (d>1.0) d=1.0; 00084 w=0.5 + 0.5*cos(M_PI*d); 00085 volrf[k][j][i].re=volrf[k][j][i].re * w; 00086 volrf[k][j][i].im=volrf[k][j][i].im * w; 00087 } 00088 } 00089 if ((x!=1)&&(y==1)&&(z==1)) /*1D*/ 00090 { 00091 for(k=0;k<z;k++) for(j=0;j<y;j++) for(i=0;i<x;i++) 00092 { 00093 d=sqrt((i-x/2.)*(i-x/2.)/x/x*4); 00094 w=0.5 + 0.5*cos(M_PI*d); 00095 volrf[k][j][i].re=volrf[k][j][i].re * w; 00096 volrf[k][j][i].im=volrf[k][j][i].im * w; 00097 } 00098 } 00099 } /* End Hanning */ 00100 case 2: 00101 { 00102 } 00103 case 3: 00104 { 00105 } 00106 } /* End switch */ 00107 } 00108 00117 PPPVOLUME_COMPLEX_DOUBLE RecVolIFFTComplexeFromVol (PPPVOLUME_COMPLEX_DOUBLE volrf) 00118 { 00119 PPPVOLUME_COMPLEX_DOUBLE volrec; 00120 int i,j,k; 00121 int x,y,z; 00122 00123 volrf= (PPPVOLUME_COMPLEX_DOUBLE) IdVolIFFT((PPPVOLUME_COMPLEX) volrf); 00124 /* Careful : volrf output of IFFT is different from the volrf input. Thus it is desalloacted in this function */ 00125 00126 /* x permutation of the IFFT */ 00127 x=IdVolDimX(volrf); 00128 y=IdVolDimY(volrf); 00129 z=IdVolDimZ(volrf); 00130 volrec = (PPPVOLUME_COMPLEX_DOUBLE) IdVolAlloc(x,y,z,VOL_COMPLEX_DOUBLE); 00131 if(!volrec) 00132 { 00133 printf("Impossible d'allouer un volume dans RecVolIFFTComplexe !\n"); 00134 exit(0); 00135 } 00136 for(k=0;k<z;k++) for(j=0;j<y;j++) for(i=0;i<x;i++) 00137 { 00138 volrec[k][j][i].re=volrf[k][j][x-1-i].re; 00139 volrec[k][j][i].im=volrf[k][j][x-1-i].im; 00140 } 00141 00142 IdVolFree(volrf); 00143 return(volrec); 00144 } 00145 00154 PPPVOLUME_FLOAT RecVolIFFTModuleFromVol (PPPVOLUME_COMPLEX_DOUBLE volrf) 00155 { 00156 PPPVOLUME_COMPLEX_DOUBLE volrec; 00157 PPPVOLUME_FLOAT module; 00158 int i,j,k; 00159 int it,jt,kt; 00160 int x,y,z; 00161 double a,b; 00162 00163 volrec= (PPPVOLUME_COMPLEX_DOUBLE) RecVolIFFTComplexeFromVol(volrf); 00164 x = IdVolDimX(volrec); y=IdVolDimY(volrec); z=IdVolDimZ(volrec); 00165 00166 module = (PPPVOLUME_FLOAT) IdVolAlloc(x,y,z,VOL_FLOAT); 00167 00168 /* Module computation with dimx*dimy*dimz permutations */ 00169 for(k=0;k<z;k++) for(j=0;j<y;j++) for(i=0;i<x;i++) 00170 { 00171 it = (i + (x / 2)) % x; 00172 jt = (j + (y / 2)) % y; 00173 kt = (k + (z / 2)) % z; 00174 a = volrec[k][j][i].re; 00175 b = volrec[k][j][i].im; 00176 module[kt][jt][it] = (float) sqrt((a*a) + (b*b)); 00177 } 00178 00179 IdVolFree(volrec); 00180 00181 return(module); 00182 } 00183 00192 PPPVOLUME_FLOAT RecVolIFFTPhaseFromVol (PPPVOLUME_COMPLEX_DOUBLE volrf) 00193 { 00194 PPPVOLUME_COMPLEX_DOUBLE volrec; 00195 PPPVOLUME_FLOAT phase; 00196 int i,j,k; 00197 int it,jt,kt; 00198 int x,y,z; 00199 double a,b; 00200 00201 volrec= (PPPVOLUME_COMPLEX_DOUBLE) RecVolIFFTComplexeFromVol(volrf); 00202 x = IdVolDimX(volrec); y=IdVolDimY(volrec); z=IdVolDimZ(volrec); 00203 00204 phase = (PPPVOLUME_FLOAT) IdVolAlloc(x,y,z,VOL_FLOAT); 00205 00206 /* Phase computation with dimx*dimy*dimz permutations */ 00207 for(k=0;k<z;k++) for(j=0;j<y;j++) for(i=0;i<x;i++) 00208 { 00209 it = (i + (x / 2)) % x; 00210 jt = (j + (y / 2)) % y; 00211 kt = (k + (z / 2)) % z; 00212 a = volrec[k][j][i].re; 00213 b = volrec[k][j][i].im; 00214 phase[kt][jt][it] = (float) atan(b/a); 00215 } 00216 00217 IdVolFree(volrec); 00218 00219 return(phase); 00220 } 00221 00222 00231 PPPVOLUME_COMPLEX_DOUBLE RecVolIFFTComplexe (EXPERIENCE3D *expr) 00232 { 00233 PPPVOLUME_COMPLEX_DOUBLE vol; 00234 PPPVOLUME_COMPLEX_DOUBLE volrec; 00235 int i,j,k; 00236 int x,y,z; 00237 00238 vol= (PPPVOLUME_COMPLEX_DOUBLE) GetSignalRFComplexFromExperience(expr); 00239 vol= (PPPVOLUME_COMPLEX_DOUBLE) IdVolIFFT((PPPVOLUME_COMPLEX) vol); 00240 00241 /* X permutation */ 00242 x=IdVolDimX(vol); 00243 y=IdVolDimY(vol); 00244 z=IdVolDimZ(vol); 00245 volrec = (PPPVOLUME_COMPLEX_DOUBLE) IdVolAlloc(x,y,z,VOL_COMPLEX_DOUBLE); 00246 if(!volrec) 00247 { 00248 printf("Impossible d'allouer un volume dans RecVolIFFTComplexe !\n"); 00249 exit(0); 00250 } 00251 for(k=0;k<z;k++) for(j=0;j<y;j++) for(i=0;i<x;i++) 00252 { 00253 volrec[k][j][i].re=vol[k][j][x-1-i].re; 00254 volrec[k][j][i].im=vol[k][j][x-1-i].im; 00255 } 00256 IdVolFree(vol); 00257 return(volrec); 00258 } 00259 00260 00269 PPPVOLUME_FLOAT RecVolIFFTModule (EXPERIENCE3D *expr) 00270 { 00271 PPPVOLUME_COMPLEX_DOUBLE volrec; 00272 PPPVOLUME_FLOAT module; 00273 int i,j,k; 00274 int it,jt,kt; 00275 int x,y,z; 00276 double a,b; 00277 00278 volrec= (PPPVOLUME_COMPLEX_DOUBLE) RecVolIFFTComplexe(expr); 00279 x = IdVolDimX(volrec); y=IdVolDimY(volrec); z=IdVolDimZ(volrec); 00280 00281 module = (PPPVOLUME_FLOAT) IdVolAlloc(x,y,z,VOL_FLOAT); 00282 00283 /* Module computation with dimx*dimy*dimz permutations */ 00284 for(k=0;k<z;k++) for(j=0;j<y;j++) for(i=0;i<x;i++) 00285 { 00286 it = (i + (x / 2)) % x; 00287 jt = (j + (y / 2)) % y; 00288 kt = (k + (z / 2)) % z; 00289 a = volrec[k][j][i].re; 00290 b = volrec[k][j][i].im; 00291 module[kt][jt][it] = (float) sqrt((a*a) + (b*b)); 00292 } 00293 00294 IdVolFree(volrec); 00295 00296 return(module); 00297 } 00298 00307 PPPVOLUME_FLOAT RecVolIFFTPhase (EXPERIENCE3D *expr) 00308 { 00309 PPPVOLUME_COMPLEX_DOUBLE volrec; 00310 PPPVOLUME_FLOAT phase; 00311 int i,j,k; 00312 int it,jt,kt; 00313 int x,y,z; 00314 double a,b; 00315 00316 volrec= (PPPVOLUME_COMPLEX_DOUBLE) RecVolIFFTComplexe(expr); 00317 x = IdVolDimX(volrec); y=IdVolDimY(volrec); z=IdVolDimZ(volrec); 00318 00319 phase = (PPPVOLUME_FLOAT) IdVolAlloc(x,y,z,VOL_FLOAT); 00320 00321 /* Phase computation with dimx*dimy*dimz permutations */ 00322 for(k=0;k<z;k++) for(j=0;j<y;j++) for(i=0;i<x;i++) 00323 { 00324 it = (i + (x / 2)) % x; 00325 jt = (j + (y / 2)) % y; 00326 kt = (k + (z / 2)) % z; 00327 a = volrec[k][j][i].re; 00328 b = volrec[k][j][i].im; 00329 phase[kt][jt][it] = (float) atan(b/a); 00330 } 00331 00332 IdVolFree(volrec); 00333 00334 return(phase); 00335 } 00336

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