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 4834 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 4849 of file processor.h.

04850                         {
04851                                 return "Undoes the effect of the xform.phaseorigin.tocorner processor";
04852                         }

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 4839 of file processor.h.

References NAME.

04840                         {
04841                                 return NAME;
04842                         }

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

Definition at line 4844 of file processor.h.

04845                         {
04846                                 return new PhaseToCenterProcessor();
04847                         }

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 5117 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().

05118 {
05119         if (!image)     throw NullPointerException("Error: attempt to phase shift a null image");
05120 
05121 #ifdef EMAN2_USING_CUDA
05122         if (EMData::usecuda == 1 && image->getcudarwdata() && image->get_ndim() == 2) { // Because CUDA phase origin to center only works for 2D atm
05123                 //cout << "CUDA tocenter" << endl;
05124                 emdata_phaseorigin_to_center(image->getcudarwdata(), image->get_xsize(), image->get_ysize(), image->get_zsize());
05125                 return;
05126         }
05127 #endif // EMAN2_USING_CUDA
05128 
05129         if (image->is_complex()) {
05130                 fourier_phaseshift180(image);
05131                 return;
05132         }
05133 
05134         int nx = image->get_xsize();
05135         int ny = image->get_ysize();
05136         int nz = image->get_zsize();
05137 
05138         if ( ny == 1 && nz == 1 && nx == 1) return;
05139 
05140         int nxy = nx * ny;
05141 
05142         float *rdata = image->get_data();
05143 
05144         bool xodd = (nx % 2) == 1;
05145         bool yodd = (ny % 2) == 1;
05146         bool zodd = (nz % 2) == 1;
05147 
05148         if ( ny == 1 && nz == 1 ){
05149                 if (xodd) {
05150                         // Put the center pixel at the end, shifting the contents
05151                         // to right of the center one step to the left
05152                         float in_x = rdata[nx/2];
05153                         float tmp;
05154                         for ( int i = nx-1; i >= nx/2; --i ) {
05155                                 tmp = rdata[i];
05156                                 rdata[i] = in_x;
05157                                 in_x = tmp;
05158                         }
05159                 }
05160                 // now the operation is straight forward
05161                 for ( int i = 0; i < nx/2; ++i ) {
05162                         int idx = i + nx/2;
05163                         float tmp = rdata[i];
05164                         rdata[i] = rdata[idx];
05165                         rdata[idx] = tmp;
05166                 }
05167         }
05168         else if ( nz == 1 ){
05169                 // The order in which these operations occur literally undoes what the
05170                 // PhaseToCornerProcessor did to the image.
05171                 // First, the corners sections of the image are swapped appropriately
05172                 swap_corners_180(image);
05173                 // Second, central pixel lines are swapped
05174                 swap_central_slices_180(image);
05175 
05176                 float tmp;
05177                 // Third, appropriate sections of the image are cyclically shifted by one pixel
05178                 if (xodd) {
05179                         // Transfer the middle column to the far right
05180                         // Shift all from the far right to (but not including the) middle one to the left
05181                         for ( int r  = 0; r < ny; ++r ) {
05182                                 float last_val = rdata[r*nx+nx/2];
05183                                 for ( int c = nx-1; c >=  nx/2; --c ){
05184                                         int idx = r*nx+c;
05185                                         tmp = rdata[idx];
05186                                         rdata[idx] = last_val;
05187                                         last_val = tmp;
05188                                 }
05189                         }
05190                 }
05191                 if (yodd) {
05192                         // Tranfer the middle row to the top,
05193                         // shifting all pixels from the top row down one, until  but not including the) middle
05194                         for ( int c = 0; c < nx; ++c ) {
05195                                 // Get the value in the top row
05196                                 float last_val = rdata[ny/2*nx + c];
05197                                 for ( int r = ny-1; r >= ny/2; --r ){
05198                                         int idx = r*nx+c;
05199                                         tmp = rdata[idx];
05200                                         rdata[idx] = last_val;
05201                                         last_val = tmp;
05202                                 }
05203                         }
05204                 }
05205         }
05206         else
05207         {
05208                 // The order in which these operations occur literally undoes the
05209                 // PhaseToCornerProcessor operation - in 3D.
05210                 // First, the corner quadrants of the voxel volume are swapped
05211                 swap_corners_180(image);
05212                 // Second, appropriate parts of the central slices are swapped
05213                 swap_central_slices_180(image);
05214 
05215                 float tmp;
05216                 // Third, appropriate sections of the image are cyclically shifted by one voxel
05217                 if (xodd) {
05218                         // Transfer the central slice in the x direction to the far right
05219                         // moving all slices on the far right toward the center one pixel, until
05220                         // the center x slice is ecountered
05221                         size_t idx = 0;
05222                         for (int s = 0; s < nz; ++s) {
05223                                 for (int r = 0; r < ny; ++r) {
05224                                         float last_val = rdata[s*nxy+r*nx+nx/2];
05225                                         for (int c = nx-1; c >= nx/2; --c){
05226                                                 idx = (size_t)s*nxy+r*nx+c;
05227                                                 tmp = rdata[idx];
05228                                                 rdata[idx] = last_val;
05229                                                 last_val = tmp;
05230                                         }
05231                                 }
05232                         }
05233                 }
05234                 if (yodd) {
05235                         // Tranfer the central slice in the y direction to the top
05236                         // shifting all pixels below it down on, until the center y slice is encountered.
05237                         size_t idx = 0;
05238                         for (int s = 0; s < nz; ++s) {
05239                                 for (int c = 0; c < nx; ++c) {
05240                                         float last_val = rdata[s*nxy+ny/2*nx+c];
05241                                         for (int r = ny-1; r >= ny/2; --r){
05242                                                 idx = (size_t)s*nxy+r*nx+c;
05243                                                 tmp = rdata[idx];
05244                                                 rdata[idx] = last_val;
05245                                                 last_val = tmp;
05246                                         }
05247                                 }
05248                         }
05249                 }
05250                 if (zodd) {
05251                         // Tranfer the central slice in the z direction to the back
05252                         // shifting all pixels beyond and including the middle slice back one.
05253                         size_t idx = 0;
05254                         for (int r = 0; r < ny; ++r){
05255                                 for (int c = 0; c < nx; ++c) {
05256                                         float last_val = rdata[nz/2*nxy+r*nx+c];
05257                                         for (int s = nz-1; s >= nz/2; --s) {
05258                                                 idx = (size_t)s*nxy+r*nx+c;
05259                                                 tmp = rdata[idx];
05260                                                 rdata[idx] = last_val;
05261                                                 last_val = tmp;
05262                                         }
05263                                 }
05264                         }
05265                 }
05266 
05267 
05268         }
05269 }


Member Data Documentation

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

Definition at line 4854 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Thu Nov 17 12:46:41 2011 for EMAN2 by  doxygen 1.4.7