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

04725                         {
04726                                 return "Undoes the effect of the xform.phaseorigin.tocorner processor";
04727                         }

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

References NAME.

04715                         {
04716                                 return NAME;
04717                         }

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

Definition at line 4719 of file processor.h.

04720                         {
04721                                 return new PhaseToCenterProcessor();
04722                         }

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

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


Member Data Documentation

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

Definition at line 4729 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Mon Mar 7 18:03:02 2011 for EMAN2 by  doxygen 1.4.7