EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes
EMAN::PhaseToCenterProcessor Class Reference

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

                        {
                                return "Undoes the effect of the xform.phaseorigin.tocorner processor";
                        }
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 5139 of file processor.h.

References NAME.

                        {
                                return NAME;
                        }
static Processor* EMAN::PhaseToCenterProcessor::NEW ( ) [inline, static]

Definition at line 5144 of file processor.h.

                        {
                                return new PhaseToCenterProcessor();
                        }
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:
imageThe image to be processed.

Implements EMAN::Processor.

Definition at line 5409 of file processor.cpp.

References emdata_phaseorigin_to_center(), 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, and rdata.

{
        if (!image)     throw NullPointerException("Error: attempt to phase shift a null image");

#ifdef EMAN2_USING_CUDA
        if (EMData::usecuda == 1 && image->getcudarwdata() && image->get_ndim() == 2) { // Because CUDA phase origin to center only works for 2D atm
                //cout << "CUDA tocenter" << endl;
                emdata_phaseorigin_to_center(image->getcudarwdata(), image->get_xsize(), image->get_ysize(), image->get_zsize());
                return;
        }
#endif // EMAN2_USING_CUDA

        if (image->is_complex()) {
                fourier_phaseshift180(image);
                return;
        }

        int nx = image->get_xsize();
        int ny = image->get_ysize();
        int nz = image->get_zsize();

        if ( ny == 1 && nz == 1 && nx == 1) return;

        int nxy = nx * ny;

        float *rdata = image->get_data();

        bool xodd = (nx % 2) == 1;
        bool yodd = (ny % 2) == 1;
        bool zodd = (nz % 2) == 1;

        if ( ny == 1 && nz == 1 ){
                if (xodd) {
                        // Put the center pixel at the end, shifting the contents
                        // to right of the center one step to the left
                        float in_x = rdata[nx/2];
                        float tmp;
                        for ( int i = nx-1; i >= nx/2; --i ) {
                                tmp = rdata[i];
                                rdata[i] = in_x;
                                in_x = tmp;
                        }
                }
                // now the operation is straight forward
                for ( int i = 0; i < nx/2; ++i ) {
                        int idx = i + nx/2;
                        float tmp = rdata[i];
                        rdata[i] = rdata[idx];
                        rdata[idx] = tmp;
                }
        }
        else if ( nz == 1 ){
                // The order in which these operations occur literally undoes what the
                // PhaseToCornerProcessor did to the image.
                // First, the corners sections of the image are swapped appropriately
                swap_corners_180(image);
                // Second, central pixel lines are swapped
                swap_central_slices_180(image);

                float tmp;
                // Third, appropriate sections of the image are cyclically shifted by one pixel
                if (xodd) {
                        // Transfer the middle column to the far right
                        // Shift all from the far right to (but not including the) middle one to the left
                        for ( int r  = 0; r < ny; ++r ) {
                                float last_val = rdata[r*nx+nx/2];
                                for ( int c = nx-1; c >=  nx/2; --c ){
                                        int idx = r*nx+c;
                                        tmp = rdata[idx];
                                        rdata[idx] = last_val;
                                        last_val = tmp;
                                }
                        }
                }
                if (yodd) {
                        // Tranfer the middle row to the top,
                        // shifting all pixels from the top row down one, until  but not including the) middle
                        for ( int c = 0; c < nx; ++c ) {
                                // Get the value in the top row
                                float last_val = rdata[ny/2*nx + c];
                                for ( int r = ny-1; r >= ny/2; --r ){
                                        int idx = r*nx+c;
                                        tmp = rdata[idx];
                                        rdata[idx] = last_val;
                                        last_val = tmp;
                                }
                        }
                }
        }
        else
        {
                // The order in which these operations occur literally undoes the
                // PhaseToCornerProcessor operation - in 3D.
                // First, the corner quadrants of the voxel volume are swapped
                swap_corners_180(image);
                // Second, appropriate parts of the central slices are swapped
                swap_central_slices_180(image);

                float tmp;
                // Third, appropriate sections of the image are cyclically shifted by one voxel
                if (xodd) {
                        // Transfer the central slice in the x direction to the far right
                        // moving all slices on the far right toward the center one pixel, until
                        // the center x slice is ecountered
                        size_t idx = 0;
                        for (int s = 0; s < nz; ++s) {
                                for (int r = 0; r < ny; ++r) {
                                        float last_val = rdata[s*nxy+r*nx+nx/2];
                                        for (int c = nx-1; c >= nx/2; --c){
                                                idx = (size_t)s*nxy+r*nx+c;
                                                tmp = rdata[idx];
                                                rdata[idx] = last_val;
                                                last_val = tmp;
                                        }
                                }
                        }
                }
                if (yodd) {
                        // Tranfer the central slice in the y direction to the top
                        // shifting all pixels below it down on, until the center y slice is encountered.
                        size_t idx = 0;
                        for (int s = 0; s < nz; ++s) {
                                for (int c = 0; c < nx; ++c) {
                                        float last_val = rdata[s*nxy+ny/2*nx+c];
                                        for (int r = ny-1; r >= ny/2; --r){
                                                idx = (size_t)s*nxy+r*nx+c;
                                                tmp = rdata[idx];
                                                rdata[idx] = last_val;
                                                last_val = tmp;
                                        }
                                }
                        }
                }
                if (zodd) {
                        // Tranfer the central slice in the z direction to the back
                        // shifting all pixels beyond and including the middle slice back one.
                        size_t idx = 0;
                        for (int r = 0; r < ny; ++r){
                                for (int c = 0; c < nx; ++c) {
                                        float last_val = rdata[nz/2*nxy+r*nx+c];
                                        for (int s = nz-1; s >= nz/2; --s) {
                                                idx = (size_t)s*nxy+r*nx+c;
                                                tmp = rdata[idx];
                                                rdata[idx] = last_val;
                                                last_val = tmp;
                                        }
                                }
                        }
                }


        }
}

Member Data Documentation

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

Definition at line 5154 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files: