NFFT Logo 3.1.1 API Reference

mri.c

00001 /*
00002  * Copyright (c) 2002, 2009 Jens Keiner, Stefan Kunis, Daniel Potts
00003  *
00004  * This program is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU General Public License as published by the Free Software
00006  * Foundation; either version 2 of the License, or (at your option) any later
00007  * version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but WITHOUT
00010  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00012  * details.
00013  *
00014  * You should have received a copy of the GNU General Public License along with
00015  * this program; if not, write to the Free Software Foundation, Inc., 51
00016  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 /* $Id: mri.c 3198 2009-05-27 14:16:50Z keiner $ */
00020 
00021 #include <string.h>
00022 #include <math.h>
00023 
00024 #include <complex.h>
00025 
00026 #include "nfft3util.h"
00027 #include "nfft3.h"
00028 
00034 typedef struct window_funct_plan_ {
00035   int d;
00036   int m;
00037   int n[1];
00038   double sigma[1];
00039   double *b;
00040   double *spline_coeffs;                
00042 } window_funct_plan;
00043 
00047 void window_funct_init(window_funct_plan* ths, int m, int n, double sigma) {
00048   ths->d=1;
00049   ths->m=m;
00050   ths->n[0]=n;
00051   ths->sigma[0]=sigma;
00052   WINDOW_HELP_INIT
00053 }
00054 
00055 /*
00056  * mri_inh_2d1d
00057  */
00058 
00059 void mri_inh_2d1d_trafo(mri_inh_2d1d_plan *that) {
00060   int l,j;
00061   double _Complex *f = (double _Complex*) nfft_malloc(that->M_total*sizeof(double _Complex));
00062   double _Complex *f_hat = (double _Complex*) nfft_malloc(that->N_total*sizeof(double _Complex));
00063 
00064   window_funct_plan *ths = (window_funct_plan*) nfft_malloc(sizeof(window_funct_plan));
00065   window_funct_init(ths,that->plan.m,that->N3,that->sigma3);
00066 
00067   /* the pointers that->f and that->f_hat have been modified by the solver */
00068   that->plan.f = that->f;
00069   that->plan.f_hat = that->f_hat;
00070 
00071 
00072   memset(f,0,that->M_total*sizeof(double _Complex));
00073   for(j=0;j<that->N_total;j++)
00074   {
00075     f_hat[j]=that->f_hat[j];
00076   }
00077 
00078   for(l=-ths->n[0]/2;l<=ths->n[0]/2;l++) {
00079     for(j=0;j<that->N_total;j++)
00080       that->f_hat[j]*=cexp(-2*PI*_Complex_I*that->w[j]*((double)l))/PHI_HUT(ths->n[0]*that->w[j],0);
00081     nfft_trafo(&that->plan);
00082     for(j=0;j<that->M_total;j++){
00083       /* PHI has compact support */
00084       if(fabs(that->t[j]-((double)l)/((double)ths->n[0]))<that->plan.m/((double)ths->n[0]))
00085         f[j]+=that->f[j]*PHI(that->t[j]-((double)l)/((double)ths->n[0]),0);
00086     }
00087     for(j=0;j<that->N_total;j++)
00088       that->f_hat[j]=f_hat[j];
00089   }
00090 
00091   nfft_free(that->plan.f);
00092   that->f=f;
00093   that->plan.f = that->f;
00094 
00095   nfft_free(f_hat);
00096 
00097   WINDOW_HELP_FINALIZE
00098   nfft_free(ths);
00099 }
00100 
00101 void mri_inh_2d1d_adjoint(mri_inh_2d1d_plan *that) {
00102   int l,j;
00103   double _Complex *f = (double _Complex*) nfft_malloc(that->M_total*sizeof(double _Complex));
00104   double _Complex *f_hat = (double _Complex*) nfft_malloc(that->N_total*sizeof(double _Complex));
00105 
00106   window_funct_plan *ths = (window_funct_plan*) nfft_malloc(sizeof(window_funct_plan));
00107   window_funct_init(ths,that->plan.m,that->N3,that->sigma3);
00108 
00109   memset(f_hat,0,that->N_total*sizeof(double _Complex));
00110 
00111   /* the pointers that->f and that->f_hat have been modified by the solver */
00112   that->plan.f = that->f;
00113   that->plan.f_hat = that->f_hat;
00114 
00115   for(j=0;j<that->M_total;j++)
00116   {
00117     f[j]=that->f[j];
00118   }
00119 
00120 
00121 
00122   for(l=-ths->n[0]/2;l<=ths->n[0]/2;l++) {
00123 
00124     for(j=0;j<that->M_total;j++) {
00125       /* PHI has compact support */
00126       if(fabs(that->t[j]-((double)l)/((double)ths->n[0]))<that->plan.m/((double)ths->n[0]))
00127         that->f[j]*=PHI(that->t[j]-((double)l)/((double)ths->n[0]),0);
00128       else
00129         that->f[j]=0.0;
00130     }
00131     nfft_adjoint(&that->plan);
00132     for(j=0;j<that->N_total;j++)
00133       f_hat[j]+=that->f_hat[j]*cexp(2*PI*_Complex_I*that->w[j]*((double)l));
00134     for(j=0;j<that->M_total;j++)
00135       that->f[j]=f[j];
00136   }
00137 
00138   for(j=0;j<that->N_total;j++)
00139   {
00140     f_hat[j] /= PHI_HUT(ths->n[0]*that->w[j],0);
00141   }
00142 
00143   nfft_free(that->plan.f_hat);
00144   that->f_hat=f_hat;
00145   that->plan.f_hat = that->f_hat;
00146 
00147   nfft_free(f);
00148 
00149   WINDOW_HELP_FINALIZE
00150   nfft_free(ths);
00151 }
00152 
00153 void mri_inh_2d1d_init_guru(mri_inh_2d1d_plan *ths, int *N, int M, int *n,
00154                     int m, double sigma, unsigned nfft_flags, unsigned fftw_flags) {
00155 
00156   nfft_init_guru(&ths->plan,2,N,M,n,m,nfft_flags,fftw_flags);
00157   ths->N3=N[2];
00158   ths->sigma3=sigma;
00159   ths->N_total = ths->plan.N_total;
00160   ths->M_total = ths->plan.M_total;
00161   ths->f = ths->plan.f;
00162   ths->f_hat = ths->plan.f_hat;
00163 
00164   ths->t = (double*) nfft_malloc(ths->M_total*sizeof(double));
00165   ths->w = (double*) nfft_malloc(ths->N_total*sizeof(double));
00166 
00167   ths->mv_trafo = (void (*) (void* ))mri_inh_2d1d_trafo;
00168   ths->mv_adjoint = (void (*) (void* ))mri_inh_2d1d_adjoint;
00169 }
00170 
00171 void mri_inh_2d1d_finalize(mri_inh_2d1d_plan *ths) {
00172   nfft_free(ths->t);
00173   nfft_free(ths->w);
00174 
00175   /* the pointers ths->f and ths->f_hat have been modified by the solver */
00176   ths->plan.f = ths->f;
00177   ths->plan.f_hat = ths->f_hat;
00178 
00179   nfft_finalize(&ths->plan);
00180 }
00181 
00182 /*
00183  * mri_inh_3d
00184  */
00185 
00186 void mri_inh_3d_trafo(mri_inh_3d_plan *that) {
00187   int l,j;
00188   window_funct_plan *ths = (window_funct_plan*) nfft_malloc(sizeof(window_funct_plan));
00189   window_funct_init(ths,that->plan.m,that->N3,that->sigma3);
00190 
00191   /* the pointers that->f has been modified by the solver */
00192   that->plan.f =that->f ;
00193 
00194 
00195 
00196   for(j=0;j<that->N_total;j++) {
00197     for(l=-ths->n[0]/2;l<ths->n[0]/2;l++)
00198     {
00199       /* PHI has compact support */
00200       if(fabs(that->w[j]-((double)l)/((double)ths->n[0]))<ths->m/((double)ths->n[0]))
00201         that->plan.f_hat[j*ths->n[0]+(l+ths->n[0]/2)]= that->f_hat[j]*PHI(that->w[j]-((double)l)/((double)ths->n[0]),0);
00202       else
00203         that->plan.f_hat[j*ths->n[0]+(l+ths->n[0]/2)]=0.0;
00204     }
00205   }
00206 
00207   nfft_trafo(&that->plan);
00208 
00209   for(j=0;j<that->M_total;j++)
00210   {
00211     that->f[j] /= PHI_HUT(ths->n[0]*that->plan.x[3*j+2],0);
00212   }
00213 
00214   WINDOW_HELP_FINALIZE
00215   nfft_free(ths);
00216 }
00217 
00218 void mri_inh_3d_adjoint(mri_inh_3d_plan *that) {
00219   int l,j;
00220   window_funct_plan *ths = (window_funct_plan*) nfft_malloc(sizeof(window_funct_plan));
00221   window_funct_init(ths,that->plan.m,that->N3,that->sigma3);
00222 
00223   /* the pointers that->f has been modified by the solver */
00224   that->plan.f =that->f ;
00225 
00226   for(j=0;j<that->M_total;j++)
00227   {
00228     that->f[j] /= PHI_HUT(ths->n[0]*that->plan.x[3*j+2],0);
00229   }
00230 
00231   nfft_adjoint(&that->plan);
00232 
00233   for(j=0;j<that->N_total;j++) {
00234     that->f_hat[j]=0.0;
00235     for(l=-ths->n[0]/2;l<ths->n[0]/2;l++)
00236     {
00237       /* PHI has compact support */
00238       if(fabs(that->w[j]-((double)l)/((double)ths->n[0]))<ths->m/((double)ths->n[0]))
00239         that->f_hat[j]+= that->plan.f_hat[j*ths->n[0]+(l+ths->n[0]/2)]*PHI(that->w[j]-((double)l)/((double)ths->n[0]),0);
00240     }
00241   }
00242 
00243 
00244   WINDOW_HELP_FINALIZE
00245   nfft_free(ths);
00246 }
00247 
00248 void mri_inh_3d_init_guru(mri_inh_3d_plan *ths, int *N, int M, int *n,
00249                     int m, double sigma, unsigned nfft_flags, unsigned fftw_flags) {
00250   ths->N3=N[2];
00251   ths->sigma3=sigma;
00252   nfft_init_guru(&ths->plan,3,N,M,n,m,nfft_flags,fftw_flags);
00253   ths->N_total = N[0]*N[1];
00254   ths->M_total = ths->plan.M_total;
00255   ths->f = ths->plan.f;
00256   ths->f_hat = (double _Complex*) nfft_malloc(ths->N_total*sizeof(double _Complex));
00257   ths->w = (double*) nfft_malloc(ths->N_total*sizeof(double));
00258 
00259   ths->mv_trafo = (void (*) (void* ))mri_inh_3d_trafo;
00260   ths->mv_adjoint = (void (*) (void* ))mri_inh_3d_adjoint;
00261 }
00262 
00263 void mri_inh_3d_finalize(mri_inh_3d_plan *ths) {
00264   nfft_free(ths->w);
00265   nfft_free(ths->f_hat);
00266   nfft_finalize(&ths->plan);
00267 }

Generated on 17 Aug 2009 by Doxygen 1.5.3