EMAN::PhaseToCenterProcessor Class Reference
[unit test in Python]

Translates a cornered image to the center Undoes the PhaseToCornerProcessor. More...

#include <processor.h>

Inheritance diagram for EMAN::PhaseToCenterProcessor:

Inheritance graph
[legend]
Collaboration diagram for EMAN::PhaseToCenterProcessor:

Collaboration graph
[legend]
List of all members.

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 ProcessorNEW ()

Static Public Attributes

static const string NAME = "xform.phaseorigin.tocenter"

Detailed Description

Translates a cornered image to the center Undoes the PhaseToCornerProcessor.

works for 1D, 2D and 3D images, for all combinations of even and oddness

Author:
David Woolford <woolford@bcm.edu>
Date:
October 2007

Definition at line 4765 of file processor.h.


Member Function Documentation

virtual string EMAN::PhaseToCenterProcessor::get_desc (  )  const [inline, virtual]

Get the descrition of this specific processor.

This function must be overwritten by a subclass.

Returns:
The description of this processor.

Implements EMAN::Processor.

Definition at line 4780 of file processor.h.

04781                         {
04782                                 return "Undoes the effect of the xform.phaseorigin.tocorner processor";
04783                         }

virtual string EMAN::PhaseToCenterProcessor::get_name (  )  const [inline, virtual]

Get the processor's name.

Each processor is identified by a unique name.

Returns:
The processor's name.

Implements EMAN::Processor.

Definition at line 4770 of file processor.h.

References NAME.

04771                         {
04772                                 return NAME;
04773                         }

static Processor* EMAN::PhaseToCenterProcessor::NEW (  )  [inline, static]

Definition at line 4775 of file processor.h.

04776                         {
04777                                 return new PhaseToCenterProcessor();
04778                         }

void PhaseToCenterProcessor::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.

Parameters:
image The image to be processed.

Implements EMAN::Processor.

Definition at line 5074 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(), and EMAN::Phase180Processor::swap_corners_180().

05075 {
05076         if (!image)     throw NullPointerException("Error: attempt to phase shift a null image");
05077 
05078 #ifdef EMAN2_USING_CUDA
05079         if (image->getcudarwdata() && image->get_ndim() == 2) { // Because CUDA phase origin to center only works for 2D atm
05080                 //cout << "CUDA tocenter" << endl;
05081                 emdata_phaseorigin_to_center(image->getcudarwdata(), image->get_xsize(), image->get_ysize(), image->get_zsize());
05082                 return;
05083         }
05084 #endif // EMAN2_USING_CUDA
05085 
05086         if (image->is_complex()) {
05087                 fourier_phaseshift180(image);
05088                 return;
05089         }
05090 
05091         int nx = image->get_xsize();
05092         int ny = image->get_ysize();
05093         int nz = image->get_zsize();
05094 
05095         if ( ny == 1 && nz == 1 && nx == 1) return;
05096 
05097         int nxy = nx * ny;
05098 
05099         float *rdata = image->get_data();
05100 
05101         bool xodd = (nx % 2) == 1;
05102         bool yodd = (ny % 2) == 1;
05103         bool zodd = (nz % 2) == 1;
05104 
05105         if ( ny == 1 && nz == 1 ){
05106                 if (xodd) {
05107                         // Put the center pixel at the end, shifting the contents
05108                         // to right of the center one step to the left
05109                         float in_x = rdata[nx/2];
05110                         float tmp;
05111                         for ( int i = nx-1; i >= nx/2; --i ) {
05112                                 tmp = rdata[i];
05113                                 rdata[i] = in_x;
05114                                 in_x = tmp;
05115                         }
05116                 }
05117                 // now the operation is straight forward
05118                 for ( int i = 0; i < nx/2; ++i ) {
05119                         int idx = i + nx/2;
05120                         float tmp = rdata[i];
05121                         rdata[i] = rdata[idx];
05122                         rdata[idx] = tmp;
05123                 }
05124         }
05125         else if ( nz == 1 ){
05126                 // The order in which these operations occur literally undoes what the
05127                 // PhaseToCornerProcessor did to the image.
05128                 // First, the corners sections of the image are swapped appropriately
05129                 swap_corners_180(image);
05130                 // Second, central pixel lines are swapped
05131                 swap_central_slices_180(image);
05132 
05133                 float tmp;
05134                 // Third, appropriate sections of the image are cyclically shifted by one pixel
05135                 if (xodd) {
05136                         // Transfer the middle column to the far right
05137                         // Shift all from the far right to (but not including the) middle one to the left
05138                         for ( int r  = 0; r < ny; ++r ) {
05139                                 float last_val = rdata[r*nx+nx/2];
05140                                 for ( int c = nx-1; c >=  nx/2; --c ){
05141                                         int idx = r*nx+c;
05142                                         tmp = rdata[idx];
05143                                         rdata[idx] = last_val;
05144                                         last_val = tmp;
05145                                 }
05146                         }
05147                 }
05148                 if (yodd) {
05149                         // Tranfer the middle row to the top,
05150                         // shifting all pixels from the top row down one, until  but not including the) middle
05151                         for ( int c = 0; c < nx; ++c ) {
05152                                 // Get the value in the top row
05153                                 float last_val = rdata[ny/2*nx + c];
05154                                 for ( int r = ny-1; r >= ny/2; --r ){
05155                                         int idx = r*nx+c;
05156                                         tmp = rdata[idx];
05157                                         rdata[idx] = last_val;
05158                                         last_val = tmp;
05159                                 }
05160                         }
05161                 }
05162         }
05163         else
05164         {
05165                 // The order in which these operations occur literally undoes the
05166                 // PhaseToCornerProcessor operation - in 3D.
05167                 // First, the corner quadrants of the voxel volume are swapped
05168                 swap_corners_180(image);
05169                 // Second, appropriate parts of the central slices are swapped
05170                 swap_central_slices_180(image);
05171 
05172                 float tmp;
05173                 // Third, appropriate sections of the image are cyclically shifted by one voxel
05174                 if (xodd) {
05175                         // Transfer the central slice in the x direction to the far right
05176                         // moving all slices on the far right toward the center one pixel, until
05177                         // the center x slice is ecountered
05178                         size_t idx = 0;
05179                         for (int s = 0; s < nz; ++s) {
05180                                 for (int r = 0; r < ny; ++r) {
05181                                         float last_val = rdata[s*nxy+r*nx+nx/2];
05182                                         for (int c = nx-1; c >= nx/2; --c){
05183                                                 idx = (size_t)s*nxy+r*nx+c;
05184                                                 tmp = rdata[idx];
05185                                                 rdata[idx] = last_val;
05186                                                 last_val = tmp;
05187                                         }
05188                                 }
05189                         }
05190                 }
05191                 if (yodd) {
05192                         // Tranfer the central slice in the y direction to the top
05193                         // shifting all pixels below it down on, until the center y slice is encountered.
05194                         size_t idx = 0;
05195                         for (int s = 0; s < nz; ++s) {
05196                                 for (int c = 0; c < nx; ++c) {
05197                                         float last_val = rdata[s*nxy+ny/2*nx+c];
05198                                         for (int r = ny-1; r >= ny/2; --r){
05199                                                 idx = (size_t)s*nxy+r*nx+c;
05200                                                 tmp = rdata[idx];
05201                                                 rdata[idx] = last_val;
05202                                                 last_val = tmp;
05203                                         }
05204                                 }
05205                         }
05206                 }
05207                 if (zodd) {
05208                         // Tranfer the central slice in the z direction to the back
05209                         // shifting all pixels beyond and including the middle slice back one.
05210                         size_t idx = 0;
05211                         for (int r = 0; r < ny; ++r){
05212                                 for (int c = 0; c < nx; ++c) {
05213                                         float last_val = rdata[nz/2*nxy+r*nx+c];
05214                                         for (int s = nz-1; s >= nz/2; --s) {
05215                                                 idx = (size_t)s*nxy+r*nx+c;
05216                                                 tmp = rdata[idx];
05217                                                 rdata[idx] = last_val;
05218                                                 last_val = tmp;
05219                                         }
05220                                 }
05221                         }
05222                 }
05223 
05224 
05225         }
05226 }


Member Data Documentation

const string PhaseToCenterProcessor::NAME = "xform.phaseorigin.tocenter" [static]

Definition at line 4785 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Mon May 2 13:30:47 2011 for EMAN2 by  doxygen 1.4.7