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

04895                         {
04896                                 return "Undoes the effect of the xform.phaseorigin.tocorner processor";
04897                         }

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

04885                         {
04886                                 return NAME;
04887                         }

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

Definition at line 4889 of file processor.h.

04890                         {
04891                                 return new PhaseToCenterProcessor();
04892                         }

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

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


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 Fri Aug 10 16:37:27 2012 for EMAN2 by  doxygen 1.3.9.1