NFFT Logo 3.0 API Reference
Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals

reconstruct_data_inh_3d.c

00001 #include <stdlib.h>
00002 #include <math.h>
00003 #include <limits.h>
00004 #include "nfft3.h"
00005 #include "util.h"
00006 
00013 void reconstruct(char* filename,int N,int M,int iteration , int weight)
00014 {
00015   int j,k,l;
00016   double time,min_time,max_time,min_inh,max_inh;
00017   double t,real,imag;
00018   double w,epsilon=0.0000003;     /* epsilon is a the break criterium for
00019                                    the iteration */;
00020   mri_inh_3d_plan my_plan;
00021   imri_inh_3d_plan my_iplan;
00022   FILE* fp,*fw,*fout_real,*fout_imag,*finh,*ftime;
00023   int my_N[3],my_n[3];
00024   int flags = PRE_PHI_HUT| PRE_PSI |MALLOC_X| MALLOC_F_HAT|
00025                       MALLOC_F| FFTW_INIT| FFT_OUT_OF_PLACE;
00026   unsigned infft_flags = CGNR | PRECOMPUTE_DAMP;
00027 
00028   double Ts;
00029   double W;
00030   int N3;
00031   int m=2;
00032   double sigma = 1.25;
00033 
00034   ftime=fopen("readout_time.dat","r");
00035   finh=fopen("inh.dat","r");
00036 
00037   min_time=INT_MAX; max_time=INT_MIN;
00038   for(j=0;j<M;j++)
00039   {
00040     fscanf(ftime,"%le ",&time);
00041     if(time<min_time)
00042       min_time = time;
00043     if(time>max_time)
00044       max_time = time;
00045   }
00046 
00047   fclose(ftime);
00048   
00049   Ts=(min_time+max_time)/2.0;
00050 
00051 
00052   min_inh=INT_MAX; max_inh=INT_MIN;
00053   for(j=0;j<N*N;j++)
00054   {
00055     fscanf(finh,"%le ",&w);
00056     if(w<min_inh)
00057       min_inh = w;
00058     if(w>max_inh)
00059       max_inh = w;
00060   }
00061   fclose(finh);
00062 
00063   N3=ceil((NFFT_MAX(fabs(min_inh),fabs(max_inh))*(max_time-min_time)/2.0+m/(2*sigma))*4*sigma);
00064   /* N3 has to be even */
00065   if(N3%2!=0)
00066     N3++;
00067   
00068   W= NFFT_MAX(fabs(min_inh),fabs(max_inh))/(0.5-((double) m)/N3);
00069 
00070   my_N[0]=N;my_n[0]=ceil(N*sigma);
00071   my_N[1]=N; my_n[1]=ceil(N*sigma);
00072   my_N[2]=N3; my_n[2]=ceil(N3*sigma);
00073   
00074   /* initialise nfft */ 
00075   mri_inh_3d_init_guru(&my_plan, my_N, M, my_n, m, sigma, flags,
00076                       FFTW_MEASURE| FFTW_DESTROY_INPUT);
00077 
00078   if (weight)
00079     infft_flags = infft_flags | PRECOMPUTE_WEIGHT;
00080 
00081   /* initialise my_iplan, advanced */
00082   imri_inh_3d_init_advanced(&my_iplan,&my_plan, infft_flags );
00083 
00084   /* get the weights */
00085   if(my_iplan.flags & PRECOMPUTE_WEIGHT)
00086   {
00087     fw=fopen("weights.dat","r");
00088     for(j=0;j<my_plan.M_total;j++)
00089     {
00090         fscanf(fw,"%le ",&my_iplan.w[j]);
00091     }
00092     fclose(fw);
00093   }
00094                       
00095   /* get the damping factors */
00096   if(my_iplan.flags & PRECOMPUTE_DAMP)
00097   {
00098     for(j=0;j<N;j++){
00099       for(k=0;k<N;k++) {
00100         int j2= j-N/2;
00101         int k2= k-N/2;
00102         double r=sqrt(j2*j2+k2*k2);
00103         if(r>(double) N/2) 
00104           my_iplan.w_hat[j*N+k]=0.0;
00105         else
00106           my_iplan.w_hat[j*N+k]=1.0;
00107       }   
00108     }
00109   }
00110   
00111   fp=fopen(filename,"r");
00112   ftime=fopen("readout_time.dat","r");
00113 
00114   for(j=0;j<my_plan.M_total;j++)
00115   {
00116     fscanf(fp,"%le %le %le %le",&my_plan.plan.x[3*j+0],&my_plan.plan.x[3*j+1],&real,&imag);
00117     my_iplan.y[j]=real+I*imag;
00118     fscanf(ftime,"%le ",&my_plan.plan.x[3*j+2]);
00119 
00120     my_plan.plan.x[3*j+2] = (my_plan.plan.x[3*j+2]-Ts)*W/N3;
00121   }
00122   fclose(fp);
00123   fclose(ftime);
00124 
00125 
00126   finh=fopen("inh.dat","r");
00127   for(j=0;j<N*N;j++)
00128   {
00129     fscanf(finh,"%le ",&my_plan.w[j]);
00130     my_plan.w[j]/=W;
00131   }
00132   fclose(finh);  
00133 
00134     
00135   if(my_plan.plan.nfft_flags & PRE_PSI) {
00136     nfft_precompute_psi(&my_plan.plan);
00137   }
00138   if(my_plan.plan.nfft_flags & PRE_FULL_PSI) {
00139       nfft_precompute_full_psi(&my_plan.plan);
00140   } 
00141 
00142   /* init some guess */
00143   for(j=0;j<my_plan.N_total;j++)
00144   {
00145     my_iplan.f_hat_iter[j]=0.0;
00146   }
00147  
00148   t=nfft_second();
00149   
00150   /* inverse trafo */
00151   imri_inh_3d_before_loop(&my_iplan);
00152   for(l=0;l<iteration;l++)
00153   {
00154     /* break if dot_r_iter is smaller than epsilon*/
00155     if(my_iplan.dot_r_iter<epsilon)
00156     break;
00157     fprintf(stderr,"%e,  %i of %i\n",sqrt(my_iplan.dot_r_iter),
00158     l+1,iteration);
00159     imri_inh_3d_loop_one_step(&my_iplan);
00160   }
00161 
00162   
00163   t=nfft_second()-t;
00164 #ifdef HAVE_TOTAL_USED_MEMORY
00165   fprintf(stderr,"time: %e seconds mem: %i \n",t,nfft_total_used_memory());
00166 #else
00167   fprintf(stderr,"time: %e seconds mem: mallinfo not available\n",t);
00168 #endif
00169   
00170   fout_real=fopen("output_real.dat","w");
00171   fout_imag=fopen("output_imag.dat","w");
00172   
00173   for (j=0;j<N*N;j++) {
00174     /* Verschiebung wieder herausrechnen */
00175     my_iplan.f_hat_iter[j]*=cexp(-2.0*I*PI*Ts*my_plan.w[j]*W);
00176     
00177     fprintf(fout_real,"%le ",creal(my_iplan.f_hat_iter[j]));
00178     fprintf(fout_imag,"%le ",cimag(my_iplan.f_hat_iter[j]));
00179   }
00180 
00181   fclose(fout_real);
00182   fclose(fout_imag);
00183   imri_inh_3d_finalize(&my_iplan);
00184   mri_inh_3d_finalize(&my_plan);
00185 }
00186 
00187 
00188 int main(int argc, char **argv)
00189 {
00190   if (argc <= 5) {
00191 
00192     printf("usage: ./reconstruct_data_inh_3d FILENAME N M ITER WEIGHTS\n");
00193     return 1;
00194   }
00195   
00196   reconstruct(argv[1],atoi(argv[2]),atoi(argv[3]),atoi(argv[4]),atoi(argv[5]));
00197 
00198   return 1;
00199 }
00200 /* \} */

Generated on 1 Nov 2006 by Doxygen 1.4.4