10701 int nx = image->get_xsize();
10702 int ny = image->get_ysize();
10703 int nz = image->get_zsize();
10710 const float *
const src_data = image->get_const_data();
10713 if ((nz == 1)&&(image ->
is_real())) {
10714 Vec2f offset(nx/2,ny/2);
10715 for (
int j = 0; j < ny; j++) {
10716 for (
int i = 0; i < nx; i++) {
10717 Vec2f coord(i-nx/2,j-ny/2);
10718 Vec2f soln = inv*coord;
10721 float x2 = soln[0];
10722 float y2 = soln[1];
10724 if (x2 < 0 || x2 >= nx || y2 < 0 || y2 >= ny ) {
10725 des_data[i + j * nx] = 0;
10731 int k0 = ii + jj * nx;
10734 int k3 = k0 + nx + 1;
10736 if (ii == nx - 1) {
10740 if (jj == ny - 1) {
10753 if ((nz == 1)&&(image ->
is_complex())&&(nx%2==0)&&((2*(nx-ny)-3)*(2*(nx-ny)-3)==1)&&(zerocorners==0) ) {
10770 float xshift= transNow[0];
float yshift= transNow[1];
10771 float tempR;
float tempI;
float tempW;
10774 Vec2f offset(nx/2,ny/2);
10775 float Mid =(N+1.0)/2.0;
10776 for (
int kyN = 0; kyN < ny; kyN++) {
10778 if (kyN>=nx/2) kyNew=kyN-ny;
10779 float kxOldPre= - sin(theta)* kyNew;
10780 float kyOldPre= cos(theta)* kyNew;
10781 float phaseY = -2*pi*kyNew*yshift/ny;
10783 for (
int kxN = 0; kxN < (nx/2); kxN++) {
10785 if (kxN >= nx/2) kxNew=kxN-ny;
10787 float kxOld= kxOldPre + cos(theta)* kxNew ;
10788 float kyOld= kyOldPre + sin(theta)* kxNew ;
10790 int kxLower= floor(kxOld);
int kxUpper= kxLower+1;
10791 int kyLower= floor(kyOld);
int kyUpper= kyLower+1;
10792 float dkxLower= (kxUpper-kxOld);
float dkxUpper= (kxOld-kxLower);
10793 float dkyLower= (kyUpper-kyOld);
float dkyUpper= (kyOld-kyLower);
10795 int kxL= kxLower;
int kyL=kyLower;
10796 float dataLL_R= 0;
float dataLL_I=0;
int flag=1;
10797 if ((abs(kxL)<Mid) && (abs(kyL)<Mid)) {
10798 kxL = (N+kxL)%N; kyL = (N+kyL)%N;
10799 if (kxL> N/2){ kxL=(N-kxL)%N; kyL=(N-kyL)%N ;flag=-1;}
10800 dataLL_R= src_data[2*kxL+ kyL*nx];
10801 dataLL_I= flag*src_data[2*kxL+1+ kyL*nx];
10804 kxL=kxLower;
int kyU=kyUpper;
10805 float dataLU_R= 0;
float dataLU_I=0; flag=1;
10806 if ((abs(kxL)<Mid) && (abs(kyU)<Mid)){
10807 kxL = (N+kxL)%N; kyU = (N+kyU)%N;
10808 if (kxL> N/2){ kxL=(N-kxL)%N; kyU=(N-kyU)%N;flag=-1;}
10809 dataLU_R= src_data[2*kxL+ kyU*nx];
10810 dataLU_I= flag*src_data[2*kxL+1+ kyU*nx];
10813 int kxU= kxUpper; kyL=kyLower;
10814 float dataUL_R= 0;
float dataUL_I=0; flag=1;
10815 if ((abs(kxU)<Mid) && (abs(kyL)<Mid)) {
10816 kxU = (N+kxU)%N; kyL = (N+kyL)%N;
10817 if (kxU> N/2) { kxU=(N-kxU)%N; kyL=(N-kyL)%N;flag=-1;}
10818 dataUL_R= src_data[2*kxU + kyL*nx];
10819 dataUL_I= flag*src_data[2*kxU+1 + kyL*nx];
10822 kxU= kxUpper; kyU=kyUpper;
10823 float dataUU_R= 0;
float dataUU_I=0; flag=1;
10824 if ((abs(kxU)<Mid) & (abs(kyU)<Mid)){
10825 kxU = (N+kxU)%N; kyU = (N+kyU)%N;
10826 if (kxU> N/2) { kxU=(N-kxU)%N; kyU=(N-kyU)%N;flag=-1;}
10827 dataUU_R= src_data[2*kxU + kyU*nx];
10828 dataUU_I= flag*src_data[2*kxU+1 + kyU*nx];
10831 float WLL = dkxLower*dkyLower ;
10832 float WLU = dkxLower*dkyUpper ;
10833 float WUL = dkxUpper*dkyLower ;
10834 float WUU = dkxUpper*dkyUpper ;
10835 tempW = WLL + WLU + WUL + WUU ;
10838 tempR = WLL*dataLL_R + WLU*dataLU_R + WUL* dataUL_R + WUU * dataUU_R ;
10839 tempI = WLL*dataLL_I + WLU*dataLU_I + WUL* dataUL_I + WUU * dataUU_I ;
10841 float phase = phaseY -2*pi*kxNew*xshift/ny;
10842 float tempRb=tempR*cos(
phase) - tempI*sin(
phase);
10843 float tempIb=tempR*sin(
phase) + tempI*cos(
phase);
10845 des_data[2*kxN + nx* kyN] = tempRb/tempW;
10846 des_data[2*kxN+1 + nx* kyN] = tempIb/tempW;
10853 if ((nz == 1)&&(image ->
is_complex())&&(nx%2==0)&&((2*(nx-ny)-3)*(2*(nx-ny)-3)==1)&&(zerocorners==1) ) {
10869 float Ctheta= cos(theta);
10870 float Stheta= sin(theta);
10873 float xshift= transNow[0];
float yshift= transNow[1];
10875 float tempR;
float tempI;
10879 Vec2f offset(nx/2,ny/2);
10880 float phaseConstx = -2*pi*xshift/ny ;
10881 float k1= cos(phaseConstx);
float k2= sin(phaseConstx);
10882 float k3= 1.0/k1;
float k4= k2/k1;
10885 for (
int kyN = 0; kyN < ny; kyN++) {
10887 if (kyN>=nx/2) kyNew=kyN-ny;
10888 float kxOld= - Stheta* kyNew - Ctheta;
10889 float kyOld= Ctheta* kyNew - Stheta;
10890 float phase = -2*pi*kyNew*yshift/ny - phaseConstx ;
10891 float Cphase = cos(
phase);
10892 float Sphase = sin(
phase);
10895 if (mirror==-1.0) {
10896 if (kyN>0) IndexOut = -2 + nx * (ny-kyN);
10897 else IndexOut = -2+ nx* kyN;
10899 else IndexOut = -2+ nx* kyN;
10900 for (
int kxN = 0; kxN < (nx/2); kxN++) {
10907 phase += phaseConstx;
10908 Cphase = Cphase*k1 -Sphase*k2;
10909 Sphase = Sphase*k3+ Cphase*k4;
10913 des_data[IndexOut] = 0;
10914 des_data[IndexOut+1] = 0;
10918 int kxLower= floor(kxOld);
10919 int kyLower= floor(kyOld);
10921 float dkxUpper= (kxOld-kxLower);
10923 float dkyUpper= (kyOld-kyLower);
10925 kx= kxLower; ky =kyLower;
10929 if (kx> N/2){ kx=(N-kx) ; ky=(N-ky) ;flagLL=-1;}
10930 int kLL =2*kx+ky*nx;
10932 kx = kxLower; ky = kyLower+1;
10936 if (kx> N/2){ kx=(N-kx) ; ky=(N-ky) ;flagLU=-1;}
10937 int kLU =2*kx+ky*nx;
10939 kx = kxLower+1; ky=kyLower;
10943 if (kx> N/2){ kx=(N-kx) ; ky=(N-ky) ;flagUL=-1;}
10944 int kUL =2*kx+ky*nx;
10946 kx = kxLower+1; ky = kyLower+1;
10950 if (kx> N/2){ kx=(N-kx) ; ky=(N-ky) ;flagUU=-1;}
10951 int kUU =2*kx+ky*nx;
10961 if (kLL<0||kUL<0||kLU<0||kUU<0||kLL>=nxy||kUL>=nxy||kLU>=nxy||kUU>=nxy)
continue;
10968 flagLU*src_data[kLU+1], flagUU*src_data[kUU+1],dkxUpper,dkyUpper);
10972 float tempRb=tempR*Cphase - tempI*Sphase;
10973 float tempIb=tempR*Sphase + tempI*Cphase;
10975 des_data[IndexOut] = tempRb;
10977 des_data[IndexOut+1] = tempIb*mirror;
10984 if ((nz > 1)&&(image ->
is_complex())&&(zerocorners==3)) {
10990 float xshift= transNow[0];
float yshift= transNow[1];
float zshift= transNow[2];
10992 float phaseConstx = -2*pi*xshift/ny ;
10993 float k1= cos(phaseConstx);
float k2= sin(phaseConstx);
10994 float k3= 1.0/k1;
float k4= k2/k1;
10996 float MatXX = (cos(az)*cos(phi) - sin(az)*cos(alt)*sin(phi) );
10997 float MatXY = (- cos(az)*sin(phi) - sin(az)*cos(alt)*cos(phi) ) ;
10998 float MatXZ = sin(az)*sin(alt) ;
10999 float MatYX = (sin(az)*cos(phi) + cos(az)*cos(alt)*sin(phi) );
11000 float MatYY = (- sin(az)*sin(phi) + cos(az)*cos(alt)*cos(phi) ) ;
11001 float MatYZ = - cos(az)*sin(alt) ;
11002 float MatZX = sin(alt)*sin(phi);
11003 float MatZY = sin(alt)*cos(phi);
11004 float MatZZ = cos(alt) ;
11005 float tempR;
float tempI;
float tempW;
11006 float Mid =(N+1.0)/2.0;
11009 for (
int kzN = 0; kzN < ny; kzN++) {
11011 if (kzN >= nx/2) kzNew=kzN-N;
11012 for (
int kyN = 0; kyN < ny; kyN++) {
11014 if (kyN>=nx/2) kyNew=kyN-ny;
11015 float kxPre = MatXY * kyNew + MatXZ *kzNew;
11016 float kyPre = MatYY * kyNew + MatYZ*kzNew;
11017 float kzPre = MatZY * kyNew + MatZZ*kzNew;
11018 float phase = -2*pi*kzNew*zshift/ny-2*pi*kyNew*yshift/ny - phaseConstx ;
11019 float Cphase = cos(
phase);
11020 float Sphase = sin(
phase);
11022 float OutBounds2= (2*Mid*Mid- (kyNew*kyNew+kzNew*kzNew)) ;
11023 int kxNewMax= nx/2;
11024 if (OutBounds2< 0) kxNewMax=0;
11025 else if (OutBounds2<(nx*nx/4)) kxNewMax=
sqrt(OutBounds2);
11026 for (
int kxN = kxNewMax; kxN < nx/2 ; kxN++ ) {
11027 des_data[2*kxN + nx* kyN +nxny*kzN] = 0;
11028 des_data[2*kxN + nx* kyN +nxny*kzN+1] = 0;
11032 for (
int kxN = 0; kxN < kxNewMax; kxN++ ) {
11033 Cphase = Cphase*k1 -Sphase*k2;
11034 Sphase = Sphase*k3+ Cphase*k4;
11036 float kxOld= MatXX * kxN + kxPre;
11037 float kyOld= MatYX * kxN + kyPre;
11038 float kzOld= MatZX * kxN + kzPre;
11040 if ((abs(kxOld)>=Mid) || (abs(kyOld)>=Mid) || (abs(kzOld)>=Mid) ) {
11041 des_data[2*kxN + nx* kyN +nxny*kzN] = 0;
11042 des_data[2*kxN + nx* kyN +nxny*kzN+1] = 0;
11045 int kxLower= floor(kxOld);
int kxUpper= kxLower+1;
11046 int kyLower= floor(kyOld);
int kyUpper= kyLower+1;
11047 int kzLower= floor(kzOld);
int kzUpper= kzLower+1;
11049 float dkxLower= (kxUpper-kxOld);
float dkxUpper= (kxOld-kxLower);
11050 float dkyLower= (kyUpper-kyOld);
float dkyUpper= (kyOld-kyLower);
11051 float dkzLower= (kzUpper-kzOld);
float dkzUpper= (kzOld-kzLower);
11053 int kxL= kxLower;
int kyL=kyLower;
int kzL=kzLower;
11054 float dataLLL_R= 0;
float dataLLL_I=0;
int flag=1;
11055 if ( (abs(kxL)<Mid) && (abs(kyL)<Mid) && (abs(kzL)<Mid) ) {
11056 kxL = (N+kxL)%N; kyL = (N+kyL)%N; kzL = (N+kzL)%N;
11057 if (kxL> N/2){kxL=(N-kxL)%N; kyL=(N-kyL)%N ; kzL=(N-kzL)%N ;flag=-1;}
11058 dataLLL_R= src_data[ 2*kxL + nx*kyL+ nxny*kzL ];
11059 dataLLL_I=flag*src_data[ 2*kxL+1 + nx*kyL+ nxny*kzL ];
11062 kxL= kxLower; kyL=kyLower;
int kzU=kzUpper;
11063 float dataLLU_R= 0;
float dataLLU_I=0; flag=1;
11064 if ( (abs(kxL)<Mid) && (abs(kyL)<Mid) && (abs(kzU)<Mid) ) {
11065 kxL = (N+kxL)%N; kyL = (N+kyL)%N; kzU = (N+kzU)%N;
11066 if (kxL> N/2){kxL=(N-kxL)%N; kyL=(N-kyL)%N ; kzU=(N-kzU)%N ;flag=-1;}
11067 dataLLU_R= src_data[ 2*kxL + nx*kyL+ nxny*kzU ];
11068 dataLLU_I= flag*src_data[ 2*kxL+1 + nx*kyL+ nxny*kzU ];
11071 kxL= kxLower;
int kyU=kyUpper; kzL=kzLower;
11072 float dataLUL_R= 0;
float dataLUL_I=0; flag=1;
11073 if ( (abs(kxL)<Mid) && (abs(kyU)<Mid)&& (abs(kzL)<Mid) ) {
11074 kxL = (N+kxL)%N; kyU = (N+kyU)%N; kzL = (N+kzL)%N;
11075 if (kxL> N/2){ kxL=(N-kxL)%N; kyU=(N-kyU)%N; kzL=(N-kzL)%N ;flag=-1;}
11076 dataLUL_R= src_data[ 2*kxL + nx*kyU+ nxny*kzL ];
11077 dataLUL_I=flag*src_data[ 2*kxL+1 + nx*kyU+ nxny*kzL ];
11080 kxL= kxLower; kyU=kyUpper; kzL=kzUpper;
11081 float dataLUU_R= 0;
float dataLUU_I=0; flag=1;
11082 if ( (abs(kxL)<Mid) && (abs(kyU)<Mid)&& (abs(kzU)<Mid)) {
11083 kxL = (N+kxL)%N; kyU = (N+kyU)%N; kzU = (N+kzU)%N;
11084 if (kxL> N/2){kxL=(N-kxL)%N; kyU=(N-kyU)%N; kzL=(N-kzL)%N ;flag=-1;}
11085 dataLUU_R= src_data[ 2*kxL + nx*kyU+ nxny*kzU ];
11086 dataLUU_I=flag*src_data[ 2*kxL+1 + nx*kyU+ nxny*kzU ];
11089 int kxU= kxUpper; kyL=kyLower; kzL=kzLower;
11090 float dataULL_R= 0;
float dataULL_I=0; flag=1;
11091 if ( (abs(kxU)<Mid) && (abs(kyL)<Mid) && (abs(kzL)<Mid) ) {
11092 kxU = (N+kxU)%N; kyL = (N+kyL)%N; kzL = (N+kzL)%N;
11093 if (kxU> N/2){kxU=(N-kxU)%N; kyL=(N-kyL)%N; kzL=(N-kzL)%N ;flag=-1;}
11094 dataULL_R= src_data[ 2*kxU + nx*kyL+ nxny*kzL ];
11095 dataULL_I=flag*src_data[ 2*kxU+1 + nx*kyL+ nxny*kzL ];
11098 kxU= kxUpper; kyL=kyLower; kzU=kzUpper;
11099 float dataULU_R= 0;
float dataULU_I=0; flag=1;
11100 if ( (abs(kxU)<Mid) && (abs(kyL)<Mid)&& (abs(kzU)<Mid) ) {
11101 kxU = (N+kxU)%N; kyL = (N+kyL)%N; kzU = (N+kzU)%N;
11102 if (kxU> N/2){kxU=(N-kxU)%N; kyL=(N-kyL)%N; kzU=(N-kzU)%N ;flag=-1;}
11103 dataULU_R= src_data[ 2*kxU + nx*kyL+ nxny*kzU ];
11104 dataULU_I=flag*src_data[ 2*kxU+1 + nx*kyL+ nxny*kzU ];
11107 kxU= kxUpper; kyU=kyUpper; kzL=kzLower;
11108 float dataUUL_R= 0;
float dataUUL_I=0; flag=1;
11109 if ( (abs(kxU)<Mid) && (abs(kyU)<Mid) && (abs(kzL)<Mid) ) {
11110 kxU = (N+kxU)%N; kyU = (N+kyU)%N; kzL = (N+kzL)%N;
11111 if (kxU> N/2){kxU=(N-kxU)%N; kyU=(N-kyU)%N; kzL=(N-kzL)%N ;flag=-1;}
11112 dataUUL_R= src_data[ 2*kxU + nx*kyU+ nxny*kzL ];
11113 dataUUL_I=flag*src_data[ 2*kxU+1 + nx*kyU+ nxny*kzL ];
11116 kxU= kxUpper; kyU=kyUpper; kzU=kzUpper;
11117 float dataUUU_R= 0;
float dataUUU_I=0; flag=1;
11118 if ( (abs(kxU)<Mid) && (abs(kyU)<Mid) && (abs(kzU)<Mid) ) {
11119 kxU = (N+kxU)%N; kyU = (N+kyU)%N; kzU = (N+kzU)%N;
11120 if (kxU> N/2) {kxU=(N-kxU)%N; kyU=(N-kyU)%N; kzU=(N-kzU)%N ;flag=-1;}
11121 dataUUU_R= src_data[ 2*kxU + nx*kyU+ nxny*kzU ];
11122 dataUUU_I=flag*src_data[ 2*kxU+1 + nx*kyU+ nxny*kzU ];
11125 float WLLL = dkxLower*dkyLower*dkzLower ;
11128 float WLLU = dkxLower*dkyLower*dkzUpper ;
11129 float WLUL = dkxLower*dkyUpper*dkzLower ;
11130 float WLUU = dkxLower*dkyUpper*dkzUpper ;
11131 float WULL = dkxUpper*dkyLower*dkzLower ;
11132 float WULU = dkxUpper*dkyLower*dkzUpper ;
11133 float WUUL = dkxUpper*dkyUpper*dkzLower;
11134 float WUUU = dkxUpper*dkyUpper*dkzUpper;
11135 tempW = WLLL + WLLU + WLUL + WLUU + WULL + WULU + WUUL + WUUU ;
11137 tempR = WLLL*dataLLL_R + WLLU*dataLLU_R + WLUL*dataLUL_R + WLUU*dataLUU_R ;
11138 tempR += WULL*dataULL_R + WULU*dataULU_R + WUUL*dataUUL_R + WUUU*dataUUU_R ;
11140 tempI = WLLL*dataLLL_I + WLLU*dataLLU_I + WLUL*dataLUL_I + WLUU*dataLUU_I ;
11141 tempI += WULL*dataULL_I + WULU*dataULU_I + WUUL*dataUUL_I + WUUU*dataUUU_I ;
11144 float tempRb=tempR*Cphase - tempI*Sphase;
11145 float tempIb=tempR*Sphase + tempI*Cphase;
11147 des_data[2*kxN + nx* kyN +nxny*kzN] = tempRb/tempW;
11148 des_data[2*kxN+1 + nx* kyN +nxny*kzN] = tempIb/tempW;
11152 if ((nz > 1)&&(image ->
is_complex())&&(zerocorners==2)) {
11158 float xshift= transNow[0];
float yshift= transNow[1];
float zshift= transNow[2];
11160 float phaseConstx = -2*pi*xshift/ny ;
11161 float k1= cos(phaseConstx);
float k2= sin(phaseConstx);
11162 float k3= 1.0/k1;
float k4= k2/k1;
11164 float MatXX = (cos(az)*cos(phi) - sin(az)*cos(alt)*sin(phi) );
11165 float MatXY = (- cos(az)*sin(phi) - sin(az)*cos(alt)*cos(phi) ) ;
11166 float MatXZ = sin(az)*sin(alt) ;
11167 float MatYX = (sin(az)*cos(phi) + cos(az)*cos(alt)*sin(phi) );
11168 float MatYY = (- sin(az)*sin(phi) + cos(az)*cos(alt)*cos(phi) ) ;
11169 float MatYZ = - cos(az)*sin(alt) ;
11170 float MatZX = sin(alt)*sin(phi);
11171 float MatZY = sin(alt)*cos(phi);
11172 float MatZZ = cos(alt) ;
11174 float Mid =(N+1.0)/2.0;
11175 int lim=(N/2)*(N/2);
11178 for (
int kzN = 0; kzN < ny; kzN++) {
11180 if (kzN >= nx/2) kzNew=kzN-N;
11181 for (
int kyN = 0; kyN < ny; kyN++) {
11183 if (kyN>=nx/2) kyNew=kyN-ny;
11186 int kyz2=kyNew*kyNew+kzNew*kzNew;
11187 if (kyz2>lim)
continue;
11188 int kxNewMax=(int)floor(
sqrt((
float)(lim-kyz2)));
11189 float kxPre = MatXY * kyNew + MatXZ *kzNew;
11190 float kyPre = MatYY * kyNew + MatYZ*kzNew;
11191 float kzPre = MatZY * kyNew + MatZZ*kzNew;
11192 float phase = -2*pi*kzNew*zshift/ny-2*pi*kyNew*yshift/ny - phaseConstx ;
11193 float Cphase = cos(
phase);
11194 float Sphase = sin(
phase);
11202 for (
int kxN = 0; kxN < kxNewMax; kxN++ ) {
11203 Cphase = Cphase*k1 -Sphase*k2;
11204 Sphase = Sphase*k3+ Cphase*k4;
11206 float kxOld= MatXX * kxN + kxPre;
11207 float kyOld= MatYX * kxN + kyPre;
11208 float kzOld= MatZX * kxN + kzPre;
11216 int kx0= floor(kxOld);
11217 int ky0= floor(kyOld);
11218 int kz0= floor(kzOld);
11220 float dkx0= (kxOld-kx0);
11221 float dky0= (kyOld-ky0);
11222 float dkz0= (kzOld-kz0);
11224 std::complex<float> c0 = image->get_complex_at(kx0 ,ky0 ,kz0 );
11225 std::complex<float> c1 = image->get_complex_at(kx0+1,ky0 ,kz0 );
11226 std::complex<float> c2 = image->get_complex_at(kx0 ,ky0+1,kz0 );
11227 std::complex<float> c3 = image->get_complex_at(kx0+1,ky0+1,kz0 );
11228 std::complex<float> c4 = image->get_complex_at(kx0 ,ky0 ,kz0+1);
11229 std::complex<float> c5 = image->get_complex_at(kx0+1,ky0 ,kz0+1);
11230 std::complex<float> c6 = image->get_complex_at(kx0 ,ky0+1,kz0+1);
11231 std::complex<float> c7 = image->get_complex_at(kx0+1,ky0+1,kz0+1);
11233 std::complex<float> nwv =
Util::trilinear_interpolate_complex(c0,c1,c2,c3,c4,c5,c6,c7,dkx0,dky0,dkz0);
11235 des_data[2*kxN + nx* kyN +nxny*kzN] = nwv.real()*Cphase - nwv.imag()*Sphase;
11236 des_data[2*kxN+1 + nx* kyN +nxny*kzN] = nwv.real()*Sphase + nwv.imag()*Cphase;
11337 if ((nz > 1)&&(image ->
is_complex())&&(zerocorners<=1)) {
11343 float xshift= transNow[0];
float yshift= transNow[1];
float zshift= transNow[2];
11345 float MatXX = (cos(az)*cos(phi) - sin(az)*cos(alt)*sin(phi) );
11346 float MatXY = (- cos(az)*sin(phi) - sin(az)*cos(alt)*cos(phi) ) ;
11347 float MatXZ = sin(az)*sin(alt) ;
11348 float MatYX = (sin(az)*cos(phi) + cos(az)*cos(alt)*sin(phi) );
11349 float MatYY = (- sin(az)*sin(phi) + cos(az)*cos(alt)*cos(phi) ) ;
11350 float MatYZ = - cos(az)*sin(alt) ;
11351 float MatZX = sin(alt)*sin(phi);
11352 float MatZY = sin(alt)*cos(phi);
11353 float MatZZ = cos(alt) ;
11354 float tempR=0;
float tempI=0;
11355 float Mid =(N+1.0)/2.0;
11356 float phaseConstx = -2*pi*xshift/ny ;
11357 float k1= cos(phaseConstx);
float k2= sin(phaseConstx);
11358 float k3= 1.0/k1;
float k4= k2/k1;
11365 for (
int kzN = 0; kzN < ny; kzN++) {
11367 if (kzN >= nx/2) kzNew=kzN-N;
11368 for (
int kyN = 0; kyN < ny; kyN++) {
11370 if (kyN>=nx/2) kyNew=kyN-ny;
11372 float kxOld = MatXY * kyNew + MatXZ *kzNew - MatXX;
11373 float kyOld = MatYY * kyNew + MatYZ*kzNew - MatYX;
11374 float kzOld = MatZY * kyNew + MatZZ*kzNew - MatZX;
11375 float phase = -2*pi*kzNew*zshift/ny-2*pi*kyNew*yshift/ny - phaseConstx ;
11376 float Cphase = cos(
phase);
11377 float Sphase = sin(
phase);
11380 int IndexOut= -2+ nx* kyN +nxny*kzN;
11381 float OutBounds2 = (Mid*Mid- (kyOld*kyOld+kzOld*kzOld)) ;
11383 int kxNewMax= nx/2;
11384 if (OutBounds2< 0) kxNewMax=0;
11385 else if (OutBounds2<(nx*nx/4)) kxNewMax=
sqrt(OutBounds2);
11386 for (
int kxN = kxNewMax; kxN < nx/2 ; kxN++ ) {
11387 des_data[2*kxN + nx* kyN +nxny*kzN] = 0;
11388 des_data[2*kxN + nx* kyN +nxny*kzN+1] = 0;
11392 for (
int kxNew = 0; kxNew < kxNewMax; kxNew++ ) {
11401 phase += phaseConstx;
11402 Cphase = Cphase*k1 -Sphase*k2;
11403 Sphase = Sphase*k3+ Cphase*k4;
11406 if ((abs(kxOld)>=Mid) || (abs(kyOld)>=Mid) || (abs(kzOld)>=Mid) ) {
11407 des_data[IndexOut] = 0;
11408 des_data[IndexOut+1] = 0;
11415 int kxLower= floor(kxOld);
11416 int kyLower= floor(kyOld);
11417 int kzLower= floor(kzOld);
11419 float dkxUpper= (kxOld-kxLower);
11420 float dkyUpper= (kyOld-kyLower);
11421 float dkzUpper= (kzOld-kzLower);
11424 kx= kxLower; ky =kyLower; kz=kzLower;
11428 if (kx<0) kx += N;
if (ky<0) ky += N;
if (kz<0) kz += N;
11429 if (kx> N/2){kx=N-kx;ky=(N-ky)%N;kz=(N-kz)%N; flagLLL=-1;}
11430 int kLLL =2*kx + nx*ky+ nxny*kz ;
11436 kx= kxLower; ky =kyLower; kz=kzLower+1;
11440 if (kx<0) kx += N;
if (ky<0) ky += N;
if (kz<0) kz += N;
11441 if (kx> N/2){kx=N-kx;ky=(N-ky)%N;kz=(N-kz)%N; flagLLU=-1;}
11442 int kLLU =2*kx + nx*ky+ nxny*kz ;
11448 kx= kxLower; ky =kyLower+1; kz=kzLower;
11452 if (kx<0) kx += N;
if (ky<0) ky += N;
if (kz<0) kz += N;
11453 if (kx> N/2){kx=N-kx;ky=(N-ky)%N;kz=(N-kz)%N; flagLUL=-1;}
11454 int kLUL =2*kx + nx*ky+ nxny*kz ;
11460 kx= kxLower; ky =kyLower+1; kz=kzLower+1;
11464 if (kx<0) kx += N;
if (ky<0) ky += N;
if (kz<0) kz += N;
11465 if (kx> N/2){kx=N-kx;ky=(N-ky)%N;kz=(N-kz)%N; flagLUU=-1;}
11466 int kLUU =2*kx + nx*ky+ nxny*kz ;
11472 kx= kxLower+1; ky =kyLower; kz=kzLower;
11476 if (kx<0) kx += N;
if (ky<0) ky += N;
if (kz<0) kz += N;
11477 if (kx> N/2){kx=N-kx;ky=(N-ky)%N;kz=(N-kz)%N; flagULL=-1;}
11478 int kULL =2*kx + nx*ky+ nxny*kz ;
11484 kx= kxLower+1; ky =kyLower; kz=kzLower+1;
11488 if (kx<0) kx += N;
if (ky<0) ky += N;
if (kz<0) kz += N;
11489 if (kx> N/2){kx=N-kx;ky=(N-ky)%N;kz=(N-kz)%N; flagULU=-1;}
11490 int kULU =2*kx + nx*ky+ nxny*kz ;
11496 kx= kxLower+1; ky =kyLower+1; kz=kzLower;
11500 if (kx<0) kx += N;
if (ky<0) ky += N;
if (kz<0) kz += N;
11501 if (kx> N/2){kx=N-kx;ky=(N-ky)%N;kz=(N-kz)%N; flagUUL=-1;}
11502 int kUUL =2*kx + nx*ky+ nxny*kz ;
11508 kx= kxLower+1; ky =kyLower+1; kz=kzLower+1;
11512 if (kx<0) kx += N;
if (ky<0) ky += N;
if (kz<0) kz += N;
11513 if (kx> N/2){kx=N-kx;ky=(N-ky)%N;kz=(N-kz)%N; flagUUU=-1;}
11514 int kUUU =2*kx + nx*ky+ nxny*kz ;
11530 src_data[kLLL] , src_data[kULL],
11531 src_data[kLUL] , src_data[kUUL],
11532 src_data[kLLU] , src_data[kULU],
11533 src_data[kLUU] , src_data[kUUU],
11534 dkxUpper,dkyUpper,dkzUpper);
11537 flagLLL*src_data[kLLL+1], flagULL*src_data[kULL+1],
11538 flagLUL*src_data[kLUL+1], flagUUL*src_data[kUUL+1],
11539 flagLLU*src_data[kLLU+1], flagULU*src_data[kULU+1],
11540 flagLUU*src_data[kLUU+1], flagUUU*src_data[kUUU+1],
11541 dkxUpper,dkyUpper,dkzUpper);
11544 float tempRb=tempR*Cphase - tempI*Sphase;
11545 float tempIb=tempR*Sphase + tempI*Cphase;
11547 des_data[IndexOut] = tempRb;
11548 des_data[IndexOut+1] = tempIb;
11551 if ((nz > 1)&&(image ->
is_real())) {
11552 size_t l=0, ii, k0, k1, k2, k3, k4, k5, k6, k7;
11553 Vec3f offset(nx/2,ny/2,nz/2);
11554 float x2, y2, z2, tuvx, tuvy, tuvz;
11556 for (
int k = 0; k < nz; ++k) {
11557 for (
int j = 0; j < ny; ++j) {
11558 for (
int i = 0; i < nx; ++i,++l) {
11559 Vec3f coord(i-nx/2,j-ny/2,k-nz/2);
11560 Vec3f soln = inv*coord;
11567 if (x2 < 0 || y2 < 0 || z2 < 0 || x2 >= nx || y2 >= ny || z2>= nz ) {
11577 ii = ix + iy * nx + iz * nxy;
11588 if (ix == nx - 1) {
11594 if (iy == ny - 1) {
11600 if (iz == nz - 1) {
11608 src_data[k1], src_data[k2], src_data[k3], src_data[k4],
11609 src_data[k5], src_data[k6], src_data[k7], tuvx, tuvy, tuvz);
EMObject get(const string &key) const
Get the EMObject corresponding to the particular key Probably better to just use operator[].
static void * em_calloc(const size_t nmemb, const size_t size)
static std::complex< float > trilinear_interpolate_complex(std::complex< float > p1, std::complex< float > p2, std::complex< float > p3, std::complex< float > p4, std::complex< float > p5, std::complex< float > p6, std::complex< float > p7, std::complex< float > p8, float t, float u, float v)
Calculate trilinear interpolation.
static int fast_floor(float x)
A fast way to calculate a floor, which is largest integral value not greater than argument.
static float trilinear_interpolate(float p1, float p2, float p3, float p4, float p5, float p6, float p7, float p8, float t, float u, float v)
Calculate trilinear interpolation.
static float bilinear_interpolate(float p1, float p2, float p3, float p4, float t, float u)
Calculate bilinear interpolation.
static float square_sum(float x, float y)
Calcuate (x*x + y*y).
The Vec2 is precisely the same as Vec3 except it works exclusively in 2D Note there are convenient ty...
EMData * sqrt() const
return square root of current image
EMData * phase() const
return phase part of a complex image as a real image format