NFFT 3.5.3alpha
reconstruct_data_3d.c
1/*
2 * Copyright (c) 2002, 2017 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#include "config.h"
19
20#include <math.h>
21#include <stdlib.h>
22#ifdef HAVE_COMPLEX_H
23#include <complex.h>
24#endif
25
26#include "nfft3.h"
27
37static void reconstruct(char* filename,int N,int M,int Z,int iteration, int weight)
38{
39 int j,k,z,l; /* some variables */
40 double real,imag; /* to read the real and imag part of a complex number */
41 nfft_plan my_plan; /* plan for the two dimensional nfft */
42 solver_plan_complex my_iplan; /* plan for the two dimensional infft */
43 FILE* fin; /* input file */
44 FILE* fout_real; /* output file (real part) */
45 FILE* fout_imag; /* output file (imag part) */
46 int my_N[3],my_n[3]; /* to init the nfft */
47 double epsilon=0.0000003; /* tmp to read the obsolent z from 700.acs
48 epsilon is a the break criterion for
49 the iteration */
50 unsigned infft_flags = CGNR | PRECOMPUTE_DAMP; /* flags for the infft */
51
52 /* initialise my_plan, specific.
53 we don't precompute psi */
54 my_N[0]=Z; my_n[0]=ceil(Z*1.2);
55 my_N[1]=N; my_n[1]=ceil(N*1.2);
56 my_N[2]=N; my_n[2]=ceil(N*1.2);
57 nfft_init_guru(&my_plan, 3, my_N, M, my_n, 6,
60 FFTW_MEASURE);
61
62 /* precompute lin psi */
63 if(my_plan.flags & PRE_LIN_PSI)
64 nfft_precompute_lin_psi(&my_plan);
65
66 if (weight)
67 infft_flags = infft_flags | PRECOMPUTE_WEIGHT;
68
69 /* initialise my_iplan, advanced */
70 solver_init_advanced_complex(&my_iplan,(nfft_mv_plan_complex*)(&my_plan), infft_flags );
71
72 /* get the weights */
73 if(my_iplan.flags & PRECOMPUTE_WEIGHT)
74 {
75 fin=fopen("weights.dat","r");
76 for(j=0;j<M;j++)
77 {
78 fscanf(fin,"%le ",&my_iplan.w[j]);
79 }
80 fclose(fin);
81 }
82
83 /* get the damping factors */
84 if(my_iplan.flags & PRECOMPUTE_DAMP)
85 {
86 for(j=0;j<N;j++){
87 for(k=0;k<N;k++) {
88 for(z=0;z<N;z++) {
89 int j2= j-N/2;
90 int k2= k-N/2;
91 int z2= z-N/2;
92 double r=sqrt(j2*j2+k2*k2+z2*z2);
93 if(r>(double) N/2)
94 my_iplan.w_hat[z*N*N+j*N+k]=0.0;
95 else
96 my_iplan.w_hat[z*N*N+j*N+k]=1.0;
97 }
98 }
99 }
100 }
101
102 /* open the input file */
103 fin=fopen(filename,"r");
104
105 /* open the output files */
106 fout_real=fopen("output_real.dat","w");
107 fout_imag=fopen("output_imag.dat","w");
108
109 /* read x,y,freal and fimag from the knots */
110 for(j=0;j<M;j++)
111 {
112 fscanf(fin,"%le %le %le %le %le ",&my_plan.x[3*j+1],&my_plan.x[3*j+2], &my_plan.x[3*j+0],
113 &real,&imag);
114 my_iplan.y[j] = real + _Complex_I*imag;
115 }
116
117 /* precompute psi */
118 if(my_plan.flags & PRE_PSI)
119 nfft_precompute_psi(&my_plan);
120
121 /* precompute full psi */
122 if(my_plan.flags & PRE_FULL_PSI)
123 nfft_precompute_full_psi(&my_plan);
124
125 /* init some guess */
126 for(k=0;k<my_plan.N_total;k++)
127 my_iplan.f_hat_iter[k]=0.0;
128
129 /* inverse trafo */
130 solver_before_loop_complex(&my_iplan);
131 for(l=0;l<iteration;l++)
132 {
133 /* break if dot_r_iter is smaller than epsilon*/
134 if(my_iplan.dot_r_iter<epsilon)
135 break;
136 fprintf(stderr,"%e, %i of %i\n",sqrt(my_iplan.dot_r_iter),
137 l+1,iteration);
138 solver_loop_one_step_complex(&my_iplan);
139 }
140
141 for(l=0;l<Z;l++)
142 {
143 for(k=0;k<N*N;k++)
144 {
145 /* write every Layer in the files */
146 fprintf(fout_real,"%le ",creal(my_iplan.f_hat_iter[ k+N*N*l ]));
147 fprintf(fout_imag,"%le ",cimag(my_iplan.f_hat_iter[ k+N*N*l ]));
148 }
149 fprintf(fout_real,"\n");
150 fprintf(fout_imag,"\n");
151 }
152
153 fclose(fout_real);
154 fclose(fout_imag);
155
156 solver_finalize_complex(&my_iplan);
157 nfft_finalize(&my_plan);
158}
159
160int main(int argc, char **argv)
161{
162 if (argc <= 6) {
163 printf("usage: ./reconstruct3D FILENAME N M Z ITER WEIGHTS\n");
164 return 1;
165 }
166
167 reconstruct(argv[1],atoi(argv[2]),atoi(argv[3]),atoi(argv[4]),atoi(argv[5]),atoi(argv[6]));
168 return 1;
169}
170/* \} */
static void reconstruct(char *filename, int N, int M, int Z, int iteration, int weight)
reconstruct makes an inverse 3d-nfft
#define MALLOC_F_HAT
Definition nfft3.h:194
#define MALLOC_X
Definition nfft3.h:193
#define PRE_FULL_PSI
Definition nfft3.h:192
#define PRE_PSI
Definition nfft3.h:191
#define MALLOC_F
Definition nfft3.h:195
#define PRE_LIN_PSI
Definition nfft3.h:189
#define FFTW_INIT
Definition nfft3.h:197
#define PRE_PHI_HUT
Definition nfft3.h:187
#define CGNR
Definition nfft3.h:808
#define PRECOMPUTE_DAMP
Definition nfft3.h:812
#define PRECOMPUTE_WEIGHT
Definition nfft3.h:811
Header file for the nfft3 library.
data structure for an inverse NFFT plan with double precision
Definition nfft3.h:802
double * w
weighting factors
Definition nfft3.h:802
unsigned flags
iteration type
Definition nfft3.h:802
double * w_hat
damping factors
Definition nfft3.h:802
double dot_r_iter
weighted dotproduct of r_iter
Definition nfft3.h:802
fftw_complex * y
right hand side, samples
Definition nfft3.h:802
fftw_complex * f_hat_iter
iterative solution
Definition nfft3.h:802