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

Translates a centered image to the corner works for 1D, 2D and 3D images, for all combinations of even and oddness. More...

#include <processor.h>

Inheritance diagram for EMAN::PhaseToCornerProcessor:

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

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.tocorner"

Detailed Description

Translates a centered image to the corner 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 4909 of file processor.h.


Member Function Documentation

virtual string EMAN::PhaseToCornerProcessor::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 4924 of file processor.h.

04925                         {
04926                                 return "Translates a centered image to the corner in a forward fashion";
04927                         }

virtual string EMAN::PhaseToCornerProcessor::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 4914 of file processor.h.

References NAME.

04915                         {
04916                                 return NAME;
04917                         }

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

Definition at line 4919 of file processor.h.

04920                         {
04921                                 return new PhaseToCornerProcessor();
04922                         }

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.

Parameters:
image The image to be processed.

Implements EMAN::Processor.

Definition at line 5041 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().

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


Member Data Documentation

const string PhaseToCornerProcessor::NAME = "xform.phaseorigin.tocorner" [static]

Definition at line 4929 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Thu May 3 10:10:34 2012 for EMAN2 by  doxygen 1.4.7