#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 | |
static Processor * | NEW () |
Static Public Attributes | |
static const string | NAME = "xform.phaseorigin.tocorner" |
Definition at line 4909 of file processor.h.
virtual string EMAN::PhaseToCornerProcessor::get_desc | ( | ) | const [inline, virtual] |
Get the descrition of this specific processor.
This function must be overwritten by a subclass.
Implements EMAN::Processor.
Definition at line 4924 of file processor.h.
virtual string EMAN::PhaseToCornerProcessor::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 4914 of file processor.h.
References NAME.
04915 { 04916 return NAME; 04917 }
static Processor* EMAN::PhaseToCornerProcessor::NEW | ( | ) | [inline, static] |
Definition at line 4919 of file processor.h.
04920 { 04921 return new PhaseToCornerProcessor(); 04922 }
void PhaseToCornerProcessor::process_inplace | ( | EMData * | image | ) | [virtual] |
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.
image | The image to be processed. |
Implements EMAN::Processor.
Definition at line 5045 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, rdata, EMAN::Phase180Processor::swap_central_slices_180(), and EMAN::Phase180Processor::swap_corners_180().
05046 { 05047 if (!image) throw NullPointerException("Error: attempt to phase shift a null image"); 05048 05049 #ifdef EMAN2_USING_CUDA 05050 if (EMData::usecuda == 1 && image->getcudarwdata() && image->get_ndim() == 2) { // Because CUDA phase origin to center only works for 2D atm 05051 //cout << "CUDA tocorner " << image->getcudarwdata() << endl; 05052 emdata_phaseorigin_to_corner(image->getcudarwdata(), image->get_xsize(), image->get_ysize(), image->get_zsize()); 05053 return; 05054 } 05055 #endif // EMAN2_USING_CUDA 05056 05057 if (image->is_complex()) { 05058 fourier_phaseshift180(image); 05059 return; 05060 } 05061 05062 int nx = image->get_xsize(); 05063 int ny = image->get_ysize(); 05064 int nz = image->get_zsize(); 05065 05066 if ( ny == 1 && nz == 1 && nx == 1) return; 05067 05068 int nxy = nx * ny; 05069 05070 float *rdata = image->get_data(); 05071 05072 bool xodd = (nx % 2) == 1; 05073 bool yodd = (ny % 2) == 1; 05074 bool zodd = (nz % 2) == 1; 05075 05076 if ( ny == 1 && nz == 1 ){ 05077 if (xodd){ 05078 // Put the last pixel in the center, shifting the contents 05079 // to right of the center one step to the right 05080 float in_x = rdata[nx-1]; 05081 float tmp; 05082 for ( int i = nx/2; i < nx; ++i ) { 05083 tmp = rdata[i]; 05084 rdata[i] = in_x; 05085 in_x = tmp; 05086 } 05087 } 05088 // now the operation is straight forward 05089 for ( int i = 0; i < nx/2; ++i ) { 05090 int idx = i+nx/2+xodd; 05091 float tmp = rdata[i]; 05092 rdata[i] = rdata[idx]; 05093 rdata[idx] = tmp; 05094 } 05095 05096 } 05097 else if ( nz == 1 ) { 05098 if (yodd) { 05099 // Tranfer the top row into the middle row, 05100 // shifting all pixels above and including the current middle up one. 05101 for ( int c = 0; c < nx; ++c ) { 05102 // Get the value in the top row 05103 float last_val = rdata[(ny-1)*nx + c]; 05104 float tmp; 05105 for ( int r = ny/2; r < ny; ++r ){ 05106 int idx =r*nx+c; 05107 tmp = rdata[idx]; 05108 rdata[idx] = last_val; 05109 last_val = tmp; 05110 } 05111 } 05112 } 05113 05114 if (xodd) { 05115 // Transfer the right most column into the center column 05116 // Shift all columns right of and including center to the right one pixel 05117 for ( int r = 0; r < ny; ++r ) { 05118 float last_val = rdata[(r+1)*nx -1]; 05119 float tmp; 05120 for ( int c = nx/2; c < nx; ++c ){ 05121 int idx =r*nx+c; 05122 tmp = rdata[idx]; 05123 rdata[idx] = last_val; 05124 last_val = tmp; 05125 } 05126 } 05127 } 05128 // It is important central slice shifting come after the previous two operations 05129 swap_central_slices_180(image); 05130 // Now the corners of the image can be shifted... 05131 swap_corners_180(image); 05132 05133 } 05134 else 05135 { 05136 float tmp; 05137 if (zodd) { 05138 // Tranfer the back slice into the middle slice, 05139 // shifting all pixels beyond and including the middle slice back one. 05140 size_t idx = 0; 05141 for (int r = 0; r < ny; ++r){ 05142 for (int c = 0; c < nx; ++c) { 05143 float last_val = rdata[(nz-1)*nxy+r*nx+c]; 05144 for (int s = nz/2; s < nz; ++s) { 05145 idx = (size_t)s*nxy+r*nx+c; 05146 tmp = rdata[idx]; 05147 rdata[idx] = last_val; 05148 last_val = tmp; 05149 } 05150 } 05151 } 05152 } 05153 if (yodd) { 05154 // Tranfer the top slice into the middle slice, 05155 // shifting all pixels above and including the middle slice up one. 05156 size_t idx = 0; 05157 for (int s = 0; s < nz; ++s) { 05158 for (int c = 0; c < nx; ++c) { 05159 float last_val = rdata[s*nxy+(ny-1)*nx+c]; 05160 for (int r = ny/2; r < ny; ++r){ 05161 idx = (size_t)s*nxy+r*nx+c; 05162 tmp = rdata[idx]; 05163 rdata[idx] = last_val; 05164 last_val = tmp; 05165 } 05166 } 05167 } 05168 } 05169 if (xodd) { 05170 // Transfer the right most slice into the central slice 05171 // Shift all pixels to right of and including center slice to the right one pixel 05172 size_t idx = 0; 05173 for (int s = 0; s < nz; ++s) { 05174 for (int r = 0; r < ny; ++r) { 05175 float last_val = rdata[s*nxy+r*nx+nx-1]; 05176 for (int c = nx/2; c < nx; ++c){ 05177 idx = (size_t)s*nxy+r*nx+c; 05178 tmp = rdata[idx]; 05179 rdata[idx] = last_val; 05180 last_val = tmp; 05181 } 05182 } 05183 } 05184 } 05185 // Now swap the various parts in the central slices 05186 swap_central_slices_180(image); 05187 // Now shift the corners 05188 swap_corners_180(image); 05189 } 05190 }
const string PhaseToCornerProcessor::NAME = "xform.phaseorigin.tocorner" [static] |