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

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

                        {
                                return "Translates a centered image to the corner in a forward fashion";
                        }
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 5169 of file processor.h.

References NAME.

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

Definition at line 5174 of file processor.h.

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

Implements EMAN::Processor.

Definition at line 5261 of file processor.cpp.

References emdata_phaseorigin_to_corner(), 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 tocorner " << image->getcudarwdata() << endl;
                emdata_phaseorigin_to_corner(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 last pixel in the center, shifting the contents
                        // to right of the center one step to the right
                        float in_x = rdata[nx-1];
                        float tmp;
                        for ( int i = nx/2; i < nx; ++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+xodd;
                        float tmp = rdata[i];
                        rdata[i] = rdata[idx];
                        rdata[idx] = tmp;
                }

        }
        else if ( nz == 1 ) {
                if (yodd) {
                        // Tranfer the top row into the middle row,
                        // shifting all pixels above and including the current middle up one.
                        for ( int c = 0; c < nx; ++c ) {
                                // Get the value in the top row
                                float last_val = rdata[(ny-1)*nx + c];
                                float tmp;
                                for ( int r = ny/2; r < ny; ++r ){
                                        int idx =r*nx+c;
                                        tmp = rdata[idx];
                                        rdata[idx] = last_val;
                                        last_val = tmp;
                                }
                        }
                }

                if (xodd) {
                        // Transfer the right most column into the center column
                        // Shift all columns right of and including center to the right one pixel
                        for ( int r  = 0; r < ny; ++r ) {
                                float last_val = rdata[(r+1)*nx -1];
                                float tmp;
                                for ( int c = nx/2; c < nx; ++c ){
                                        int idx =r*nx+c;
                                        tmp = rdata[idx];
                                        rdata[idx] = last_val;
                                        last_val = tmp;
                                }
                        }
                }
                // It is important central slice shifting come after the previous two operations
                swap_central_slices_180(image);
                // Now the corners of the image can be shifted...
                swap_corners_180(image);

        }
        else
        {
                float tmp;
                if (zodd) {
                        // Tranfer the back slice into the middle slice,
                        // 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-1)*nxy+r*nx+c];
                                        for (int s = nz/2; s < nz; ++s) {
                                                idx = (size_t)s*nxy+r*nx+c;
                                                tmp = rdata[idx];
                                                rdata[idx] = last_val;
                                                last_val = tmp;
                                        }
                                }
                        }
                }
                if (yodd) {
                        // Tranfer the top slice into the middle slice,
                        // shifting all pixels above and including the middle slice up one.
                        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-1)*nx+c];
                                        for (int r = ny/2; r < ny; ++r){
                                                idx = (size_t)s*nxy+r*nx+c;
                                                tmp = rdata[idx];
                                                rdata[idx] = last_val;
                                                last_val = tmp;
                                        }
                                }
                        }
                }
                if (xodd) {
                        // Transfer the right most slice into the central slice
                        // Shift all pixels to right of and including center slice to the right one pixel
                        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-1];
                                        for (int c = nx/2; c < nx; ++c){
                                                idx = (size_t)s*nxy+r*nx+c;
                                                tmp = rdata[idx];
                                                rdata[idx] = last_val;
                                                last_val = tmp;
                                        }
                                }
                        }
                }
                // Now swap the various parts in the central slices
                swap_central_slices_180(image);
                // Now shift the corners
                swap_corners_180(image);
        }
}

Member Data Documentation

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

Definition at line 5184 of file processor.h.

Referenced by get_name().


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