#include <processor.h>
Inheritance diagram for EMAN::PhaseToCenterProcessor:
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.tocenter" |
works for 1D, 2D and 3D images, for all combinations of even and oddness
Definition at line 4800 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 4815 of file processor.h.
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 4805 of file processor.h. References NAME. 04806 { 04807 return NAME; 04808 }
|
|
Definition at line 4810 of file processor.h. 04811 { 04812 return new PhaseToCenterProcessor(); 04813 }
|
|
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 5037 of file processor.cpp. References emdata_phaseorigin_to_center(), 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(), EMAN::Phase180Processor::swap_corners_180(), and UnexpectedBehaviorException. 05038 { 05039 if (!image) throw NullPointerException("Error: attempt to phase shift a null image"); 05040 bool proceed = true; 05041 05042 #ifdef EMAN2_USING_CUDA 05043 bool cpu = image->cpu_rw_is_current(); 05044 bool gpu = image->gpu_rw_is_current(); 05045 if ( !cpu && !gpu ) 05046 throw UnexpectedBehaviorException("Both the CPU and GPU data are not current"); 05047 if (gpu && image->get_ndim() == 2) { // Because CUDA phase origin to center only works for 2D atm 05048 EMDataForCuda tmp = image->get_data_struct_for_cuda(); 05049 emdata_phaseorigin_to_center(&tmp); 05050 proceed = false; 05051 image->gpu_update(); 05052 } 05053 #endif // EMAN2_USING_CUDA 05054 if (!proceed) return; // GPU processing occurred 05055 05056 if (image->is_complex()) { 05057 fourier_phaseshift180(image); 05058 return; 05059 } 05060 05061 int nx = image->get_xsize(); 05062 int ny = image->get_ysize(); 05063 int nz = image->get_zsize(); 05064 05065 if ( ny == 1 && nz == 1 && nx == 1) return; 05066 05067 int nxy = nx * ny; 05068 05069 float *rdata = image->get_data(); 05070 05071 bool xodd = (nx % 2) == 1; 05072 bool yodd = (ny % 2) == 1; 05073 bool zodd = (nz % 2) == 1; 05074 05075 if ( ny == 1 && nz == 1 ){ 05076 if (xodd) { 05077 // Put the center pixel at the end, shifting the contents 05078 // to right of the center one step to the left 05079 float in_x = rdata[nx/2]; 05080 float tmp; 05081 for ( int i = nx-1; i >= nx/2; --i ) { 05082 tmp = rdata[i]; 05083 rdata[i] = in_x; 05084 in_x = tmp; 05085 } 05086 } 05087 // now the operation is straight forward 05088 for ( int i = 0; i < nx/2; ++i ) { 05089 int idx = i + nx/2; 05090 float tmp = rdata[i]; 05091 rdata[i] = rdata[idx]; 05092 rdata[idx] = tmp; 05093 } 05094 } 05095 else if ( nz == 1 ){ 05096 // The order in which these operations occur literally undoes what the 05097 // PhaseToCornerProcessor did to the image. 05098 // First, the corners sections of the image are swapped appropriately 05099 swap_corners_180(image); 05100 // Second, central pixel lines are swapped 05101 swap_central_slices_180(image); 05102 05103 float tmp; 05104 // Third, appropriate sections of the image are cyclically shifted by one pixel 05105 if (xodd) { 05106 // Transfer the middle column to the far right 05107 // Shift all from the far right to (but not including the) middle one to the left 05108 for ( int r = 0; r < ny; ++r ) { 05109 float last_val = rdata[r*nx+nx/2]; 05110 for ( int c = nx-1; c >= nx/2; --c ){ 05111 int idx = r*nx+c; 05112 tmp = rdata[idx]; 05113 rdata[idx] = last_val; 05114 last_val = tmp; 05115 } 05116 } 05117 } 05118 if (yodd) { 05119 // Tranfer the middle row to the top, 05120 // shifting all pixels from the top row down one, until but not including the) middle 05121 for ( int c = 0; c < nx; ++c ) { 05122 // Get the value in the top row 05123 float last_val = rdata[ny/2*nx + c]; 05124 for ( int r = ny-1; r >= ny/2; --r ){ 05125 int idx = r*nx+c; 05126 tmp = rdata[idx]; 05127 rdata[idx] = last_val; 05128 last_val = tmp; 05129 } 05130 } 05131 } 05132 } 05133 else 05134 { 05135 // The order in which these operations occur literally undoes the 05136 // PhaseToCornerProcessor operation - in 3D. 05137 // First, the corner quadrants of the voxel volume are swapped 05138 swap_corners_180(image); 05139 // Second, appropriate parts of the central slices are swapped 05140 swap_central_slices_180(image); 05141 05142 float tmp; 05143 // Third, appropriate sections of the image are cyclically shifted by one voxel 05144 if (xodd) { 05145 // Transfer the central slice in the x direction to the far right 05146 // moving all slices on the far right toward the center one pixel, until 05147 // the center x slice is ecountered 05148 size_t idx = 0; 05149 for (int s = 0; s < nz; ++s) { 05150 for (int r = 0; r < ny; ++r) { 05151 float last_val = rdata[s*nxy+r*nx+nx/2]; 05152 for (int c = nx-1; c >= nx/2; --c){ 05153 idx = s*nxy+r*nx+c; 05154 tmp = rdata[idx]; 05155 rdata[idx] = last_val; 05156 last_val = tmp; 05157 } 05158 } 05159 } 05160 } 05161 if (yodd) { 05162 // Tranfer the central slice in the y direction to the top 05163 // shifting all pixels below it down on, until the center y slice is encountered. 05164 size_t idx = 0; 05165 for (int s = 0; s < nz; ++s) { 05166 for (int c = 0; c < nx; ++c) { 05167 float last_val = rdata[s*nxy+ny/2*nx+c]; 05168 for (int r = ny-1; r >= ny/2; --r){ 05169 idx = s*nxy+r*nx+c; 05170 tmp = rdata[idx]; 05171 rdata[idx] = last_val; 05172 last_val = tmp; 05173 } 05174 } 05175 } 05176 } 05177 if (zodd) { 05178 // Tranfer the central slice in the z direction to the back 05179 // shifting all pixels beyond and including the middle slice back one. 05180 size_t idx = 0; 05181 for (int r = 0; r < ny; ++r){ 05182 for (int c = 0; c < nx; ++c) { 05183 float last_val = rdata[nz/2*nxy+r*nx+c]; 05184 for (int s = nz-1; s >= nz/2; --s) { 05185 idx = s*nxy+r*nx+c; 05186 tmp = rdata[idx]; 05187 rdata[idx] = last_val; 05188 last_val = tmp; 05189 } 05190 } 05191 } 05192 } 05193 05194 05195 } 05196 }
|
|
Definition at line 4820 of file processor.h. Referenced by get_name(). |