Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

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

ProcessorNEW ()

Static Public Attributes

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

04897                         {
04898                                 return "Undoes the effect of the xform.phaseorigin.tocorner processor";
04899                         }

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

04887                         {
04888                                 return NAME;
04889                         }

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

Definition at line 4891 of file processor.h.

04892                         {
04893                                 return new PhaseToCenterProcessor();
04894                         }

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 5195 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, nx, ny, rdata, EMAN::Phase180Processor::swap_central_slices_180(), and EMAN::Phase180Processor::swap_corners_180().

05196 {
05197         if (!image)     throw NullPointerException("Error: attempt to phase shift a null image");
05198 
05199 #ifdef EMAN2_USING_CUDA
05200         if (EMData::usecuda == 1 && image->getcudarwdata() && image->get_ndim() == 2) { // Because CUDA phase origin to center only works for 2D atm
05201                 //cout << "CUDA tocenter" << endl;
05202                 emdata_phaseorigin_to_center(image->getcudarwdata(), image->get_xsize(), image->get_ysize(), image->get_zsize());
05203                 return;
05204         }
05205 #endif // EMAN2_USING_CUDA
05206 
05207         if (image->is_complex()) {
05208                 fourier_phaseshift180(image);
05209                 return;
05210         }
05211 
05212         int nx = image->get_xsize();
05213         int ny = image->get_ysize();
05214         int nz = image->get_zsize();
05215 
05216         if ( ny == 1 && nz == 1 && nx == 1) return;
05217 
05218         int nxy = nx * ny;
05219 
05220         float *rdata = image->get_data();
05221 
05222         bool xodd = (nx % 2) == 1;
05223         bool yodd = (ny % 2) == 1;
05224         bool zodd = (nz % 2) == 1;
05225 
05226         if ( ny == 1 && nz == 1 ){
05227                 if (xodd) {
05228                         // Put the center pixel at the end, shifting the contents
05229                         // to right of the center one step to the left
05230                         float in_x = rdata[nx/2];
05231                         float tmp;
05232                         for ( int i = nx-1; i >= nx/2; --i ) {
05233                                 tmp = rdata[i];
05234                                 rdata[i] = in_x;
05235                                 in_x = tmp;
05236                         }
05237                 }
05238                 // now the operation is straight forward
05239                 for ( int i = 0; i < nx/2; ++i ) {
05240                         int idx = i + nx/2;
05241                         float tmp = rdata[i];
05242                         rdata[i] = rdata[idx];
05243                         rdata[idx] = tmp;
05244                 }
05245         }
05246         else if ( nz == 1 ){
05247                 // The order in which these operations occur literally undoes what the
05248                 // PhaseToCornerProcessor did to the image.
05249                 // First, the corners sections of the image are swapped appropriately
05250                 swap_corners_180(image);
05251                 // Second, central pixel lines are swapped
05252                 swap_central_slices_180(image);
05253 
05254                 float tmp;
05255                 // Third, appropriate sections of the image are cyclically shifted by one pixel
05256                 if (xodd) {
05257                         // Transfer the middle column to the far right
05258                         // Shift all from the far right to (but not including the) middle one to the left
05259                         for ( int r  = 0; r < ny; ++r ) {
05260                                 float last_val = rdata[r*nx+nx/2];
05261                                 for ( int c = nx-1; c >=  nx/2; --c ){
05262                                         int idx = r*nx+c;
05263                                         tmp = rdata[idx];
05264                                         rdata[idx] = last_val;
05265                                         last_val = tmp;
05266                                 }
05267                         }
05268                 }
05269                 if (yodd) {
05270                         // Tranfer the middle row to the top,
05271                         // shifting all pixels from the top row down one, until  but not including the) middle
05272                         for ( int c = 0; c < nx; ++c ) {
05273                                 // Get the value in the top row
05274                                 float last_val = rdata[ny/2*nx + c];
05275                                 for ( int r = ny-1; r >= ny/2; --r ){
05276                                         int idx = r*nx+c;
05277                                         tmp = rdata[idx];
05278                                         rdata[idx] = last_val;
05279                                         last_val = tmp;
05280                                 }
05281                         }
05282                 }
05283         }
05284         else
05285         {
05286                 // The order in which these operations occur literally undoes the
05287                 // PhaseToCornerProcessor operation - in 3D.
05288                 // First, the corner quadrants of the voxel volume are swapped
05289                 swap_corners_180(image);
05290                 // Second, appropriate parts of the central slices are swapped
05291                 swap_central_slices_180(image);
05292 
05293                 float tmp;
05294                 // Third, appropriate sections of the image are cyclically shifted by one voxel
05295                 if (xodd) {
05296                         // Transfer the central slice in the x direction to the far right
05297                         // moving all slices on the far right toward the center one pixel, until
05298                         // the center x slice is ecountered
05299                         size_t idx = 0;
05300                         for (int s = 0; s < nz; ++s) {
05301                                 for (int r = 0; r < ny; ++r) {
05302                                         float last_val = rdata[s*nxy+r*nx+nx/2];
05303                                         for (int c = nx-1; c >= nx/2; --c){
05304                                                 idx = (size_t)s*nxy+r*nx+c;
05305                                                 tmp = rdata[idx];
05306                                                 rdata[idx] = last_val;
05307                                                 last_val = tmp;
05308                                         }
05309                                 }
05310                         }
05311                 }
05312                 if (yodd) {
05313                         // Tranfer the central slice in the y direction to the top
05314                         // shifting all pixels below it down on, until the center y slice is encountered.
05315                         size_t idx = 0;
05316                         for (int s = 0; s < nz; ++s) {
05317                                 for (int c = 0; c < nx; ++c) {
05318                                         float last_val = rdata[s*nxy+ny/2*nx+c];
05319                                         for (int r = ny-1; r >= ny/2; --r){
05320                                                 idx = (size_t)s*nxy+r*nx+c;
05321                                                 tmp = rdata[idx];
05322                                                 rdata[idx] = last_val;
05323                                                 last_val = tmp;
05324                                         }
05325                                 }
05326                         }
05327                 }
05328                 if (zodd) {
05329                         // Tranfer the central slice in the z direction to the back
05330                         // shifting all pixels beyond and including the middle slice back one.
05331                         size_t idx = 0;
05332                         for (int r = 0; r < ny; ++r){
05333                                 for (int c = 0; c < nx; ++c) {
05334                                         float last_val = rdata[nz/2*nxy+r*nx+c];
05335                                         for (int s = nz-1; s >= nz/2; --s) {
05336                                                 idx = (size_t)s*nxy+r*nx+c;
05337                                                 tmp = rdata[idx];
05338                                                 rdata[idx] = last_val;
05339                                                 last_val = tmp;
05340                                         }
05341                                 }
05342                         }
05343                 }
05344 
05345 
05346         }
05347 }


Member Data Documentation

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

Definition at line 164 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Tue Jun 11 13:48:57 2013 for EMAN2 by  doxygen 1.3.9.1