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