NFFT  3.3.0
reconstruct_data_inh_2d1d.c
1 /*
2  * Copyright (c) 2002, 2015 Jens Keiner, Stefan Kunis, Daniel Potts
3  *
4  * This program is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU General Public License as published by the Free Software
6  * Foundation; either version 2 of the License, or (at your option) any later
7  * version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 51
16  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 /* $Id$ */
20 #include <stdlib.h>
21 #include <math.h>
22 #include <limits.h>
23 #include <complex.h>
24 
25 #include "nfft3.h"
26 
27 #ifndef MAX
28 #define MAX(a,b) (((a)>(b))?(a):(b))
29 #endif
30 
37 static void reconstruct(char* filename,int N,int M,int iteration , int weight)
38 {
39  int j,k,l;
40  double time,min_time,max_time,min_inh,max_inh;
41  double t0, t1;
42  double t,real,imag;
43  double w,epsilon=0.0000003; /* epsilon is a the break criterium for
44  the iteration */;
45  mri_inh_2d1d_plan my_plan;
46  solver_plan_complex my_iplan;
47  FILE* fp,*fw,*fout_real,*fout_imag,*finh,*ftime;
48  int my_N[3],my_n[3];
49  int flags = PRE_PHI_HUT| PRE_PSI |MALLOC_X| MALLOC_F_HAT|
50  MALLOC_F| FFTW_INIT| FFT_OUT_OF_PLACE;
51  unsigned infft_flags = CGNR | PRECOMPUTE_DAMP;
52 
53  double Ts;
54  double W,T;
55  int N3;
56  int m=2;
57  double sigma = 1.25;
58 
59  ftime=fopen("readout_time.dat","r");
60  finh=fopen("inh.dat","r");
61 
62  min_time=INT_MAX; max_time=INT_MIN;
63  for(j=0;j<M;j++)
64  {
65  fscanf(ftime,"%le ",&time);
66  if(time<min_time)
67  min_time = time;
68  if(time>max_time)
69  max_time = time;
70  }
71 
72  fclose(ftime);
73 
74  Ts=(min_time+max_time)/2.0;
75 
76 
77  min_inh=INT_MAX; max_inh=INT_MIN;
78  for(j=0;j<N*N;j++)
79  {
80  fscanf(finh,"%le ",&w);
81  if(w<min_inh)
82  min_inh = w;
83  if(w>max_inh)
84  max_inh = w;
85  }
86  fclose(finh);
87 
88  N3=ceil((MAX(fabs(min_inh),fabs(max_inh))*(max_time-min_time)/2.0+(m)/(2*sigma))*4*sigma);
89  /* N3 has to be even */
90  if(N3%2!=0)
91  N3++;
92 
93  T=((max_time-min_time)/2.0)/(0.5-((double) (m))/N3);
94  W=N3/T;
95 
96  my_N[0]=N; my_n[0]=ceil(N*sigma);
97  my_N[1]=N; my_n[1]=ceil(N*sigma);
98  my_N[2]=N3; my_n[2]=N3;
99 
100  /* initialise nfft */
101  mri_inh_2d1d_init_guru(&my_plan, my_N, M, my_n, m, sigma, flags,
102  FFTW_MEASURE| FFTW_DESTROY_INPUT);
103 
104 
105  /* precompute lin psi if set */
106  if(my_plan.plan.flags & PRE_LIN_PSI)
107  nfft_precompute_lin_psi(&my_plan.plan);
108 
109  if (weight)
110  infft_flags = infft_flags | PRECOMPUTE_WEIGHT;
111 
112  /* initialise my_iplan, advanced */
113  solver_init_advanced_complex(&my_iplan,(nfft_mv_plan_complex*)(&my_plan), infft_flags );
114 
115  /* get the weights */
116  if(my_iplan.flags & PRECOMPUTE_WEIGHT)
117  {
118  fw=fopen("weights.dat","r");
119  for(j=0;j<my_plan.M_total;j++)
120  {
121  fscanf(fw,"%le ",&my_iplan.w[j]);
122  }
123  fclose(fw);
124  }
125 
126  /* get the damping factors */
127  if(my_iplan.flags & PRECOMPUTE_DAMP)
128  {
129  for(j=0;j<N;j++){
130  for(k=0;k<N;k++) {
131  int j2= j-N/2;
132  int k2= k-N/2;
133  double r=sqrt(j2*j2+k2*k2);
134  if(r>(double) N/2)
135  my_iplan.w_hat[j*N+k]=0.0;
136  else
137  my_iplan.w_hat[j*N+k]=1.0;
138  }
139  }
140  }
141 
142  fp=fopen(filename,"r");
143  ftime=fopen("readout_time.dat","r");
144 
145  for(j=0;j<my_plan.M_total;j++)
146  {
147  fscanf(fp,"%le %le %le %le",&my_plan.plan.x[2*j+0],&my_plan.plan.x[2*j+1],&real,&imag);
148  my_iplan.y[j]=real+ _Complex_I*imag;
149  fscanf(ftime,"%le ",&my_plan.t[j]);
150 
151  my_plan.t[j] = (my_plan.t[j]-Ts)/T;
152  }
153  fclose(fp);
154  fclose(ftime);
155 
156 
157  finh=fopen("inh.dat","r");
158  for(j=0;j<N*N;j++)
159  {
160  fscanf(finh,"%le ",&my_plan.w[j]);
161  my_plan.w[j]/=W;
162  }
163  fclose(finh);
164 
165 
166  if(my_plan.plan.flags & PRE_PSI) {
167  nfft_precompute_psi(&my_plan.plan);
168  }
169  if(my_plan.plan.flags & PRE_FULL_PSI) {
170  nfft_precompute_full_psi(&my_plan.plan);
171  }
172 
173  /* init some guess */
174  for(j=0;j<my_plan.N_total;j++)
175  {
176  my_iplan.f_hat_iter[j]=0.0;
177  }
178 
179  t0 = nfft_clock_gettime_seconds();
180 
181  /* inverse trafo */
182  solver_before_loop_complex(&my_iplan);
183  for(l=0;l<iteration;l++)
184  {
185  /* break if dot_r_iter is smaller than epsilon*/
186  if(my_iplan.dot_r_iter<epsilon)
187  break;
188  fprintf(stderr,"%e, %i of %i\n",sqrt(my_iplan.dot_r_iter),
189  l+1,iteration);
190  solver_loop_one_step_complex(&my_iplan);
191  }
192 
193  t1 = nfft_clock_gettime_seconds();
194  t = t1-t0;
195 
196  fout_real=fopen("output_real.dat","w");
197  fout_imag=fopen("output_imag.dat","w");
198 
199  for (j=0;j<N*N;j++) {
200  /* Verschiebung wieder herausrechnen */
201  my_iplan.f_hat_iter[j]*=cexp(-2.0*_Complex_I*M_PI*Ts*my_plan.w[j]*W);
202 
203  fprintf(fout_real,"%le ",creal(my_iplan.f_hat_iter[j]));
204  fprintf(fout_imag,"%le ",cimag(my_iplan.f_hat_iter[j]));
205  }
206 
207  fclose(fout_real);
208  fclose(fout_imag);
209  solver_finalize_complex(&my_iplan);
210  mri_inh_2d1d_finalize(&my_plan);
211 }
212 
213 
214 int main(int argc, char **argv)
215 {
216  if (argc <= 5) {
217 
218  printf("usage: ./reconstruct_data_inh_2d1d FILENAME N M ITER WEIGHTS\n");
219  return 1;
220  }
221 
222  reconstruct(argv[1],atoi(argv[2]),atoi(argv[3]),atoi(argv[4]),atoi(argv[5]));
223 
224  return 1;
225 }
226 /* \} */
double * w
weighting factors
Definition: nfft3.h:786
unsigned flags
iteration type
Definition: nfft3.h:786
double dot_r_iter
weighted dotproduct of r_iter
Definition: nfft3.h:786
NFFT_INT M_total
Total number of samples.
Definition: nfft3.h:527
fftw_complex * y
right hand side, samples
Definition: nfft3.h:786
double * x
Nodes in time/spatial domain, size is doubles.
Definition: nfft3.h:194
NFFT_INT N_total
Total number of Fourier coefficients.
Definition: nfft3.h:527
unsigned flags
Flags for precomputation, (de)allocation, and FFTW usage, default setting is PRE_PHI_HUT | PRE_PSI | ...
Definition: nfft3.h:194
data structure for an inverse NFFT plan with double precision
Definition: nfft3.h:786
double * w_hat
damping factors
Definition: nfft3.h:786
fftw_complex * f_hat_iter
iterative solution
Definition: nfft3.h:786