#include <processor.h>
Inheritance diagram for EMAN::PhaseToCornerProcessor:
Public Member Functions | |
virtual void | process_inplace (EMData *image) |
To process an image in-place. | |
virtual string | get_name () const |
Get the processor's name. | |
virtual string | get_desc () const |
Get the descrition of this specific processor. | |
Static Public Member Functions | |
Processor * | NEW () |
Static Public Attributes | |
const string | NAME = "xform.phaseorigin.tocorner" |
Definition at line 4795 of file processor.h.
|
Get the descrition of this specific processor. This function must be overwritten by a subclass.
Implements EMAN::Processor. Definition at line 4810 of file processor.h. 04811 { 04812 return "Translates a centered image to the corner in a forward fashion"; 04813 }
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 4800 of file processor.h. 04801 {
04802 return NAME;
04803 }
|
|
Definition at line 4805 of file processor.h. 04806 { 04807 return new PhaseToCornerProcessor(); 04808 }
|
|
To process an image in-place. For those processors which can only be processed out-of-place, override this function to just print out some error message to remind user call the out-of-place version.
Implements EMAN::Processor. Definition at line 4926 of file processor.cpp. References emdata_phaseorigin_to_corner(), EMAN::Phase180Processor::fourier_phaseshift180(), EMAN::EMData::get_data(), EMAN::EMData::get_ndim(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::EMData::is_complex(), NullPointerException, nx, ny, rdata, EMAN::Phase180Processor::swap_central_slices_180(), and EMAN::Phase180Processor::swap_corners_180(). 04927 { 04928 if (!image) throw NullPointerException("Error: attempt to phase shift a null image"); 04929 04930 #ifdef EMAN2_USING_CUDA 04931 if (image->getcudarwdata() && image->get_ndim() == 2) { // Because CUDA phase origin to center only works for 2D atm 04932 //cout << "CUDA tocorner" << endl; 04933 emdata_phaseorigin_to_corner(image->getcudarwdata(), image->get_xsize(), image->get_ysize(), image->get_zsize()); 04934 return; 04935 } 04936 #endif // EMAN2_USING_CUDA 04937 04938 if (image->is_complex()) { 04939 fourier_phaseshift180(image); 04940 return; 04941 } 04942 04943 int nx = image->get_xsize(); 04944 int ny = image->get_ysize(); 04945 int nz = image->get_zsize(); 04946 04947 if ( ny == 1 && nz == 1 && nx == 1) return; 04948 04949 int nxy = nx * ny; 04950 04951 float *rdata = image->get_data(); 04952 04953 bool xodd = (nx % 2) == 1; 04954 bool yodd = (ny % 2) == 1; 04955 bool zodd = (nz % 2) == 1; 04956 04957 if ( ny == 1 && nz == 1 ){ 04958 if (xodd){ 04959 // Put the last pixel in the center, shifting the contents 04960 // to right of the center one step to the right 04961 float in_x = rdata[nx-1]; 04962 float tmp; 04963 for ( int i = nx/2; i < nx; ++i ) { 04964 tmp = rdata[i]; 04965 rdata[i] = in_x; 04966 in_x = tmp; 04967 } 04968 } 04969 // now the operation is straight forward 04970 for ( int i = 0; i < nx/2; ++i ) { 04971 int idx = i+nx/2+xodd; 04972 float tmp = rdata[i]; 04973 rdata[i] = rdata[idx]; 04974 rdata[idx] = tmp; 04975 } 04976 04977 } 04978 else if ( nz == 1 ) { 04979 if (yodd) { 04980 // Tranfer the top row into the middle row, 04981 // shifting all pixels above and including the current middle up one. 04982 for ( int c = 0; c < nx; ++c ) { 04983 // Get the value in the top row 04984 float last_val = rdata[(ny-1)*nx + c]; 04985 float tmp; 04986 for ( int r = ny/2; r < ny; ++r ){ 04987 int idx =r*nx+c; 04988 tmp = rdata[idx]; 04989 rdata[idx] = last_val; 04990 last_val = tmp; 04991 } 04992 } 04993 } 04994 04995 if (xodd) { 04996 // Transfer the right most column into the center column 04997 // Shift all columns right of and including center to the right one pixel 04998 for ( int r = 0; r < ny; ++r ) { 04999 float last_val = rdata[(r+1)*nx -1]; 05000 float tmp; 05001 for ( int c = nx/2; c < nx; ++c ){ 05002 int idx =r*nx+c; 05003 tmp = rdata[idx]; 05004 rdata[idx] = last_val; 05005 last_val = tmp; 05006 } 05007 } 05008 } 05009 // It is important central slice shifting come after the previous two operations 05010 swap_central_slices_180(image); 05011 // Now the corners of the image can be shifted... 05012 swap_corners_180(image); 05013 05014 } 05015 else 05016 { 05017 float tmp; 05018 if (zodd) { 05019 // Tranfer the back slice into the middle slice, 05020 // shifting all pixels beyond and including the middle slice back one. 05021 size_t idx = 0; 05022 for (int r = 0; r < ny; ++r){ 05023 for (int c = 0; c < nx; ++c) { 05024 float last_val = rdata[(nz-1)*nxy+r*nx+c]; 05025 for (int s = nz/2; s < nz; ++s) { 05026 idx = (size_t)s*nxy+r*nx+c; 05027 tmp = rdata[idx]; 05028 rdata[idx] = last_val; 05029 last_val = tmp; 05030 } 05031 } 05032 } 05033 } 05034 if (yodd) { 05035 // Tranfer the top slice into the middle slice, 05036 // shifting all pixels above and including the middle slice up one. 05037 size_t idx = 0; 05038 for (int s = 0; s < nz; ++s) { 05039 for (int c = 0; c < nx; ++c) { 05040 float last_val = rdata[s*nxy+(ny-1)*nx+c]; 05041 for (int r = ny/2; r < ny; ++r){ 05042 idx = (size_t)s*nxy+r*nx+c; 05043 tmp = rdata[idx]; 05044 rdata[idx] = last_val; 05045 last_val = tmp; 05046 } 05047 } 05048 } 05049 } 05050 if (xodd) { 05051 // Transfer the right most slice into the central slice 05052 // Shift all pixels to right of and including center slice to the right one pixel 05053 size_t idx = 0; 05054 for (int s = 0; s < nz; ++s) { 05055 for (int r = 0; r < ny; ++r) { 05056 float last_val = rdata[s*nxy+r*nx+nx-1]; 05057 for (int c = nx/2; c < nx; ++c){ 05058 idx = (size_t)s*nxy+r*nx+c; 05059 tmp = rdata[idx]; 05060 rdata[idx] = last_val; 05061 last_val = tmp; 05062 } 05063 } 05064 } 05065 } 05066 // Now swap the various parts in the central slices 05067 swap_central_slices_180(image); 05068 // Now shift the corners 05069 swap_corners_180(image); 05070 } 05071 }
|
|
Definition at line 164 of file processor.cpp. |