3 #include "controller.h"
6 static const char* deapodize_post_str=
"deapodize";
13 deapo_shift.set_description(
"Shift deapodization function for correct offset");
14 append_arg(deapo_shift,
"deapo_shift");
16 kernel.set_funcpars(
"Gauss");
17 kernel.set_cmdline_option(
"kg"+postfix()).set_description(
"Kernel function for "+postfix()+
" k-space gridding");
18 append_arg(kernel,
"kernel");
20 kernelwidth=sqrt(
float(3-NDim))*3.0;
21 kernelwidth.set_cmdline_option(
"kw"+postfix()).set_unit(
"Pixel").set_description(
"Kernel width for "+postfix()+
" k-space gridding");
22 append_arg(kernelwidth,
"kernelwidth");
25 gridScale.set_cmdline_option(
"gs").set_description(
"Scale Factor for the grid used for gridding");
26 append_arg(gridScale,
"gridScale");
33 Log<Reco> odinlog(
"RecoGrid",
"gridshape");
35 TinyVector<int,3> imagesize=controller.
image_size();
36 TinyVector<int,NDim> result;
37 for(
int i=0; i<NDim; i++) result(i)=imagesize(3-NDim+i);
43 ODINLOG(odinlog,normalDebug) <<
"result=" << result << STD_endl;
52 Log<Reco> odinlog(c_label(),
"get_gridder");
58 typename GridderMap::const_iterator it=gridmap.find(traj);
59 if(it==gridmap.end()) {
62 float appGridScale = gridScale;
63 if (NDim == 1) appGridScale = 1.0;
65 TinyVector<int,NDim> dstshape=gridshape(coord, controller);
67 int nseg=traj->extent(0);
68 int npts=traj->extent(1);
70 STD_vector<GriddingPoint<NDim> > srccoords(nseg*npts);
72 for(
int iseg=0; iseg<nseg; iseg++) {
73 for(
int ipt=0; ipt<npts; ipt++) {
75 const TinyVector<float,3>& kpoint=gridpoint.coord;
77 TinyVector<float,NDim>& srcpoint=srccoord.coord;
78 for(
int i=0; i<NDim; i++) {
79 float k=kpoint(3-NDim+i);
80 srcpoint(i)=k * appGridScale;
82 ODINLOG(odinlog,normalDebug) <<
"srcpoint=" << srcpoint << STD_endl;
83 ODINLOG(odinlog,normalDebug) <<
"kpoint=" << kpoint << STD_endl;
84 srccoord.weight=gridpoint.weight;
89 ODINLOG(odinlog,normalDebug) <<
"kmax=" << kmax << STD_endl;
91 TinyVector<float,NDim> dstextent;
92 for(
int i=0; i<NDim; i++) dstextent(i)=kmax(3-NDim+i);
94 for (
int i=0; i<NDim; i++) {
95 dstshape(i) *= appGridScale;
96 dstextent(i) *= appGridScale;
99 float dk=max(dstextent/dstshape);
100 float kwidth=kernelwidth*dk*appGridScale;
101 ODINLOG(odinlog,normalDebug) <<
"dstshape/dstextent/dk/kwidth=" << dstshape <<
"/" << dstextent <<
"/" << dk <<
"/" << kwidth << STD_endl;
104 sampldens=gridder.
init(dstshape, dstextent, srccoords, kernel, kwidth);
110 int deapo_os_factor=4;
111 TinyVector<int,NDim> shape_os(deapo_os_factor*dstshape);
113 kspace_kernel_os=STD_complex(0.0);
116 for(
unsigned int i=0; i<kspace_kernel_os.size(); i++) {
117 TinyVector<int,NDim> index=kspace_kernel_os.create_index(i);
118 TinyVector<int,NDim> dist=index-shape_os/2;
119 float radius=
secureDivision( sqrt(
double(sum(dist*dist))), 0.5*deapo_os_factor*kernelwidth*appGridScale);
120 if(radius<=1.0) kspace_kernel_os(index)=STD_complex(kernel.calculate(radius));
124 ODINLOG(odinlog,normalDebug) <<
"deapo_shift=" << deapo_shift << STD_endl;
128 TinyVector<float,3> reloffset=controller.
reloffset();
129 TinyVector<float,NDim> reloffset_os;
130 for(
int i=0; i<NDim; i++) reloffset_os(i)=reloffset(3-NDim+i)/deapo_os_factor/appGridScale;
131 if(max(abs(reloffset))>0.0) kspace_kernel_os.modulate_offset(reloffset_os);
135 kspace_kernel_os.fft();
137 apodize=cabs(kspace_kernel_os(RectDomain<NDim>((shape_os-dstshape)/2, (shape_os-dstshape)/2+dstshape-1)));
140 if(min(apodize)>0.0) {
147 rdposted.
data(
Rank<NDim>()).reference(float2real(mean(apodize)/apodize));
148 controller.
post_data(deapodize_post_str+postfix(), rdposted);
150 ODINLOG(odinlog,warningLog) <<
"FT of gridding kernel contains zero, not applying de-apodize correction" << STD_endl;
166 ODINLOG(odinlog,errorLog) <<
"No kspaceTraj available for coord=" << rd.
coord().
print() << STD_endl;
174 TinyVector<int,NDim> outshape=gridshape(rd.
coord(), controller);
176 for (
int i=0; i<NDim; i++) outshape(i) *= gridScale;
183 int adcSize=adc.extent(0);
184 ODINLOG(odinlog,normalDebug) <<
"adcSize=" << adcSize << STD_endl;
186 unsigned int offset=0;
189 outdata=gridder(adc, offset);
193 return execute_next_step(rd,controller);
199 if(context.mode==RecoQueryContext::prep) {
212 if(!controller.
inquire_data(*
this, deapodize_post_str+postfix(), rddeapo))
return false;
217 for(
unsigned int i=0; i<data.size(); i++) {
220 TinyVector<int,NDim> deapoindex;
221 for(
int i=0; i<NDim; i++) deapoindex(i)=index(3-NDim+i);
223 data(index)*=deapo(deapoindex);
230 return execute_next_step(rd,controller);
240 if (scaleFactor != 1.0) {
242 Range all=Range::all();
245 TinyVector<int,3> inshape(indata.shape());
246 TinyVector<int,3> outshape(inshape(0), inshape(1) / scaleFactor, inshape(2) / scaleFactor);
248 TinyVector<int,2> phasebounds((inshape(1) - outshape(1)) / 2, (inshape(1) + outshape(1)) / 2);
249 TinyVector<int,2> readbounds((inshape(1) - outshape(1)) / 2, (inshape(1) + outshape(1)) / 2);
252 outdata = indata(all,Range(phasebounds(0),phasebounds(1)),Range(readbounds(0),readbounds(1)));
TinyVector< int, N_rank > create_index(unsigned long index) const
void announce_data(const STD_string &label)
TinyVector< float, 3 > kspace_extent() const
bool inquire_data(const RecoStep &caller, const STD_string &label, RecoData &data)
void post_data(const STD_string &label, const RecoData &data)
TinyVector< float, 3 > reloffset() const
TinyVector< int, 3 > image_size() const
ComplexData< 1 > & data(Rank< 1 >) const
deapodize1d, deapodize2d: De-apodize gridded data in 2 dimensions
grid1d, grid2d: Grid signal data with arbitrary k-space trajectory in 2 dimensions
RecoIndex & set_mode(indexMode m)
virtual bool query(RecoQueryContext &context)
bool execute_next_step(RecoData &rd, RecoController &controller)
Array< float, N_rank > init(const TinyVector< int, N_rank > &dst_shape, const TinyVector< float, N_rank > &dst_extent, const STD_vector< GriddingPoint< N_rank > > &src_coords, const LDRfilter &kernel, float kernel_diameter)
double secureDivision(double numerator, double denominator)
RecoIndex index[n_recoDims]
const ReadoutShape * readoutShape
STD_string print(RecoIndex::printMode printmode=RecoIndex::brief) const
const KspaceTraj * kspaceTraj
RecoController & controller