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

04640                         {
04641                                 return "Undoes the effect of the xform.phaseorigin.tocorner processor";
04642                         }

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

04630                         {
04631                                 return NAME;
04632                         }

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

Definition at line 4634 of file processor.h.

04635                         {
04636                                 return new PhaseToCenterProcessor();
04637                         }

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 5005 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(), EMAN::Phase180Processor::swap_corners_180(), and UnexpectedBehaviorException.

05006 {
05007         if (!image)     throw NullPointerException("Error: attempt to phase shift a null image");
05008         bool proceed = true;
05009 
05010 #ifdef EMAN2_USING_CUDA
05011         bool cpu = image->cpu_rw_is_current();
05012         bool gpu = image->gpu_rw_is_current();
05013         if ( !cpu && !gpu )
05014                 throw UnexpectedBehaviorException("Both the CPU and GPU data are not current");
05015         if (gpu && image->get_ndim() == 2) { // Because CUDA phase origin to center only works for 2D atm
05016                 EMDataForCuda tmp = image->get_data_struct_for_cuda();
05017                 emdata_phaseorigin_to_center(&tmp);
05018                 proceed = false;
05019                 image->gpu_update();
05020         }
05021 #endif // EMAN2_USING_CUDA
05022         if (!proceed) return; // GPU processing occurred
05023 
05024         if (image->is_complex()) {
05025                 fourier_phaseshift180(image);
05026                 return;
05027         }
05028 
05029         int nx = image->get_xsize();
05030         int ny = image->get_ysize();
05031         int nz = image->get_zsize();
05032 
05033         if ( ny == 1 && nz == 1 && nx == 1) return;
05034 
05035         int nxy = nx * ny;
05036 
05037         float *rdata = image->get_data();
05038 
05039         bool xodd = (nx % 2) == 1;
05040         bool yodd = (ny % 2) == 1;
05041         bool zodd = (nz % 2) == 1;
05042 
05043         if ( ny == 1 && nz == 1 ){
05044                 if (xodd) {
05045                         // Put the center pixel at the end, shifting the contents
05046                         // to right of the center one step to the left
05047                         float in_x = rdata[nx/2];
05048                         float tmp;
05049                         for ( int i = nx-1; i >= nx/2; --i ) {
05050                                 tmp = rdata[i];
05051                                 rdata[i] = in_x;
05052                                 in_x = tmp;
05053                         }
05054                 }
05055                 // now the operation is straight forward
05056                 for ( int i = 0; i < nx/2; ++i ) {
05057                         int idx = i + nx/2;
05058                         float tmp = rdata[i];
05059                         rdata[i] = rdata[idx];
05060                         rdata[idx] = tmp;
05061                 }
05062         }
05063         else if ( nz == 1 ){
05064                 // The order in which these operations occur literally undoes what the
05065                 // PhaseToCornerProcessor did to the image.
05066                 // First, the corners sections of the image are swapped appropriately
05067                 swap_corners_180(image);
05068                 // Second, central pixel lines are swapped
05069                 swap_central_slices_180(image);
05070 
05071                 float tmp;
05072                 // Third, appropriate sections of the image are cyclically shifted by one pixel
05073                 if (xodd) {
05074                         // Transfer the middle column to the far right
05075                         // Shift all from the far right to (but not including the) middle one to the left
05076                         for ( int r  = 0; r < ny; ++r ) {
05077                                 float last_val = rdata[r*nx+nx/2];
05078                                 for ( int c = nx-1; c >=  nx/2; --c ){
05079                                         int idx = r*nx+c;
05080                                         tmp = rdata[idx];
05081                                         rdata[idx] = last_val;
05082                                         last_val = tmp;
05083                                 }
05084                         }
05085                 }
05086                 if (yodd) {
05087                         // Tranfer the middle row to the top,
05088                         // shifting all pixels from the top row down one, until  but not including the) middle
05089                         for ( int c = 0; c < nx; ++c ) {
05090                                 // Get the value in the top row
05091                                 float last_val = rdata[ny/2*nx + c];
05092                                 for ( int r = ny-1; r >= ny/2; --r ){
05093                                         int idx = r*nx+c;
05094                                         tmp = rdata[idx];
05095                                         rdata[idx] = last_val;
05096                                         last_val = tmp;
05097                                 }
05098                         }
05099                 }
05100         }
05101         else
05102         {
05103                 // The order in which these operations occur literally undoes the
05104                 // PhaseToCornerProcessor operation - in 3D.
05105                 // First, the corner quadrants of the voxel volume are swapped
05106                 swap_corners_180(image);
05107                 // Second, appropriate parts of the central slices are swapped
05108                 swap_central_slices_180(image);
05109 
05110                 float tmp;
05111                 // Third, appropriate sections of the image are cyclically shifted by one voxel
05112                 if (xodd) {
05113                         // Transfer the central slice in the x direction to the far right
05114                         // moving all slices on the far right toward the center one pixel, until
05115                         // the center x slice is ecountered
05116                         size_t idx = 0;
05117                         for (int s = 0; s < nz; ++s) {
05118                                 for (int r = 0; r < ny; ++r) {
05119                                         float last_val = rdata[s*nxy+r*nx+nx/2];
05120                                         for (int c = nx-1; c >= nx/2; --c){
05121                                                 idx = s*nxy+r*nx+c;
05122                                                 tmp = rdata[idx];
05123                                                 rdata[idx] = last_val;
05124                                                 last_val = tmp;
05125                                         }
05126                                 }
05127                         }
05128                 }
05129                 if (yodd) {
05130                         // Tranfer the central slice in the y direction to the top
05131                         // shifting all pixels below it down on, until the center y slice is encountered.
05132                         size_t idx = 0;
05133                         for (int s = 0; s < nz; ++s) {
05134                                 for (int c = 0; c < nx; ++c) {
05135                                         float last_val = rdata[s*nxy+ny/2*nx+c];
05136                                         for (int r = ny-1; r >= ny/2; --r){
05137                                                 idx = s*nxy+r*nx+c;
05138                                                 tmp = rdata[idx];
05139                                                 rdata[idx] = last_val;
05140                                                 last_val = tmp;
05141                                         }
05142                                 }
05143                         }
05144                 }
05145                 if (zodd) {
05146                         // Tranfer the central slice in the z direction to the back
05147                         // shifting all pixels beyond and including the middle slice back one.
05148                         size_t idx = 0;
05149                         for (int r = 0; r < ny; ++r){
05150                                 for (int c = 0; c < nx; ++c) {
05151                                         float last_val = rdata[nz/2*nxy+r*nx+c];
05152                                         for (int s = nz-1; s >= nz/2; --s) {
05153                                                 idx = s*nxy+r*nx+c;
05154                                                 tmp = rdata[idx];
05155                                                 rdata[idx] = last_val;
05156                                                 last_val = tmp;
05157                                         }
05158                                 }
05159                         }
05160                 }
05161 
05162 
05163         }
05164 }


Member Data Documentation

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

Definition at line 158 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Thu Dec 9 13:48:10 2010 for EMAN2 by  doxygen 1.3.9.1