EMAN2
Protected Member Functions
EMAN::Phase180Processor Class Reference

This class is abstract. More...

#include <processor.h>

Inheritance diagram for EMAN::Phase180Processor:
Inheritance graph
[legend]
Collaboration diagram for EMAN::Phase180Processor:
Collaboration graph
[legend]

List of all members.

Protected Member Functions

void swap_corners_180 (EMData *image)
 swap_corners_180 - works on 2D and 3D images
void swap_central_slices_180 (EMData *image)
 swap_central_slices_180 - works on 2D and 3D images
void fourier_phaseshift180 (EMData *image)
 fourier_phaseshift180 - fourier phase shift by 180 this function is called internally if the argument to the process_inplace function is complex.

Detailed Description

This class is abstract.

It contains functionality common to the PhaseToCenterProcessor and PhaseToCornerProcessor processors

Author:
David Woolford <woolford@bcm.edu>
Date:
October 2007

though the testing of this processor is really implicit

Definition at line 5085 of file processor.h.


Member Function Documentation

void Phase180Processor::fourier_phaseshift180 ( EMData image) [protected]

fourier_phaseshift180 - fourier phase shift by 180 this function is called internally if the argument to the process_inplace function is complex.

Parameters:
imagethe image to be operated upon
Exceptions:
ImageFormatExceptionif the image is not in complex format

Definition at line 5011 of file processor.cpp.

References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageFormatException, EMAN::EMData::is_complex(), nx, ny, and rdata.

{
        if ( !image->is_complex() ) throw ImageFormatException("Can not handle images that are not complex in fourier phase shift 180");

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

        int nxy = nx * ny;

        float *rdata = image->get_data();

        // Who uses this function? It doesn't work for odd images, and it will give incorrect results for some even images
        // d.woolford, March 15 2009
        int of=0;
        if (((ny/2)%2)+((nz/2)%2)==1) of=1;

        for (int k = 0; k < nz; k++) {
                size_t k2 = (size_t)k * nxy;

                for (int j = 0; j < ny; j++) {
                        int i = ((k+j)%2==of?2:0);
                        size_t j2 = j * nx + k2;

                        for (; i < nx; i += 4) {
                                rdata[i + j2] *= -1.0f;
                                rdata[i + j2 + 1] *= -1.0f;
                        }
                }
        }
}
void Phase180Processor::swap_central_slices_180 ( EMData image) [protected]

swap_central_slices_180 - works on 2D and 3D images

swaps pixels values in central slices, only required if the image has one or more odd dimensions. Should be used striclty in conjunction with swap_central_slices_180 function and never called by anyone except for PhaseToCenterProcessor and PhaseToCornerProcessor classes. Highly specialised function to handle all cases of even and oddness

Parameters:
imagethe image to be operated upon
Exceptions:
ImageDimensionExceptionif the image is 1D
NullPointerExceptionif the image is null

Definition at line 5140 of file processor.cpp.

References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, ny, and rdata.

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

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

        int nxy = nx * ny;

        float *rdata = image->get_data();

        if ( ny == 1 && nz == 1 ){
                throw ImageDimensionException("Error, cannot handle 1D images. This function should not have been called");
        }
        else if ( nz == 1 ) {
                float tmp;
                if ( yodd ) {
                        // Iterate along middle row, swapping values where appropriate
                        int r = ny/2;
                        for ( int c = 0; c < nx/2; ++c ) {
                                int idx1 = r*nx + c;
                                int idx2 = r*nx + c + nx/2+ xodd;
                                tmp = rdata[idx1];
                                rdata[idx1] = rdata[idx2];
                                rdata[idx2] = tmp;
                        }
                }

                if ( xodd )     {
                        // Iterate along the central column, swapping values where appropriate
                        int c = nx/2;
                        for (  int r = 0; r < ny/2; ++r ) {
                                int idx1 = r*nx + c;
                                int idx2 = (r+ny/2+yodd)*nx + c;
                                tmp = rdata[idx1];
                                rdata[idx1] = rdata[idx2];
                                rdata[idx2] = tmp;
                        }
                }
        }
        else // nx && ny && nz are greater than 1
        {
                float tmp;
                if ( xodd ) {
                        // Iterate along the x = nx/2 slice, swapping values where appropriate
                        int c = nx/2;
                        size_t idx1, idx2;
                        for( int s = 0; s < nz/2; ++s ) {
                                for ( int r = 0; r < ny/2; ++r ) {
                                        idx1 = (size_t)s*nxy+(size_t)r*nx+c;
                                        idx2 = (s+nz/2+zodd)*(size_t)nxy+(r+ny/2+yodd)*(size_t)nx+c;
                                        tmp = rdata[idx1];
                                        rdata[idx1] = rdata[idx2];
                                        rdata[idx2] = tmp;
                                }
                        }

                        for( int s = nz-1; s >= (nz/2+zodd); --s ) {
                                for ( int r = 0; r < ny/2; ++r ) {
                                        idx1 = (size_t)s*nxy+(size_t)r*nx+c;
                                        idx2 = (s-nz/2-zodd)*(size_t)nxy+(r+ny/2+yodd)*(size_t)nx+c;
                                        tmp = rdata[idx1];
                                        rdata[idx1] = rdata[idx2];
                                        rdata[idx2] = tmp;
                                }
                        }
                }
                if ( yodd ) {
                        // Iterate along the y = ny/2 slice, swapping values where appropriate
                        int r = ny/2;
                        size_t idx1, idx2;
                        for( int s = 0; s < nz/2; ++s ) {
                                for ( int c = 0; c < nx/2; ++c ) {
                                        idx1 = (size_t)s*nxy+(size_t)r*nx+c;
                                        idx2 =(s+nz/2+zodd)*(size_t)nxy+(size_t)r*nx+c+nx/2+xodd;
                                        tmp = rdata[idx1];
                                        rdata[idx1] = rdata[idx2];
                                        rdata[idx2] = tmp;
                                }
                        }

                        for( int s = nz-1; s >= (nz/2+zodd); --s ) {
                                for ( int c = 0; c < nx/2; ++c ) {
                                        idx1 = (size_t)s*nxy+(size_t)r*nx+c;
                                        idx2 = (s-nz/2-zodd)*(size_t)nxy+(size_t)r*nx+c+nx/2+xodd;
                                        tmp = rdata[idx1];
                                        rdata[idx1] = rdata[idx2];
                                        rdata[idx2] = tmp;
                                }
                        }
                }
                if ( zodd ) {
                        // Iterate along the z = nz/2 slice, swapping values where appropriate
                        int s = nz/2;
                        size_t idx1, idx2;
                        for( int r = 0; r < ny/2; ++r ) {
                                for ( int c = 0; c < nx/2; ++c ) {
                                        idx1 = (size_t)s*nxy+(size_t)r*nx+c;
                                        idx2 = (size_t)s*nxy+(r+ny/2+yodd)*(size_t)nx+c+nx/2+xodd;
                                        tmp = rdata[idx1];
                                        rdata[idx1] = rdata[idx2];
                                        rdata[idx2] = tmp;
                                }
                        }

                        for( int r = ny-1; r >= (ny/2+yodd); --r ) {
                                for ( int c = 0; c < nx/2; ++c ) {
                                        idx1 = (size_t)s*nxy+(size_t)r*nx+c;
                                        idx2 = (size_t)s*nxy+(r-ny/2-yodd)*(size_t)nx+c+nx/2+xodd;
                                        tmp = rdata[idx1];
                                        rdata[idx1] = rdata[idx2];
                                        rdata[idx2] = tmp;
                                }
                        }
                }
        }
}
void Phase180Processor::swap_corners_180 ( EMData image) [protected]

swap_corners_180 - works on 2D and 3D images

Implements the conventional 180 degree phase shift required to put the center of the image at the bottom left of the image - is used in conjunction with swap_central_slices_180 if any of the image dimensions are odd, but by itself will perform the entire operation on even images. This functions is never called by anyone except for the PhaseToCenterProcessor and PhaseToCornerProcessor classes. Highly specialised function to handle all cases of even and oddness

Parameters:
imagethe image to be operated upon
Exceptions:
ImageDimensionExceptionif the image is 1D
NullPointerExceptionif the image is null

Definition at line 5043 of file processor.cpp.

References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, ny, and rdata.

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

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

        int nxy = nx * ny;

        float *rdata = image->get_data();

        if ( ny == 1 && nz == 1 ){
                throw ImageDimensionException("Error, cannot handle 1D images. This function should not have been called");
        }
        else if ( nz == 1 ) {

                // Swap the bottom left and top right corners
                for ( int r = 0; r < ny/2; ++r ) {
                        for ( int c = 0; c < nx/2; ++c) {
                                int idx1 = r*nx + c;
                                int idx2 = (r+ny/2+yodd)*nx + c + nx/2+xodd;
                                float tmp = rdata[idx1];
                                rdata[idx1] = rdata[idx2];
                                rdata[idx2] = tmp;
                        }
                }

                // Swap the top left and bottom right corners
                for ( int r = ny-1; r >= (ny/2+yodd); --r ) {
                        for ( int c = 0; c < nx/2; ++c) {
                                int idx1 = r*nx + c;
                                int idx2 = (r-ny/2-yodd)*nx + c + nx/2+xodd;
                                float tmp = rdata[idx1];
                                rdata[idx1] = rdata[idx2];
                                rdata[idx2] = tmp;
                        }
                }
        }
        else // nx && ny && nz are greater than 1
        {
                float tmp;
                // Swap the bottom left front and back right top quadrants
                size_t idx1, idx2;

                for ( int s = 0; s < nz/2; ++s ) {
                        for ( int r = 0; r < ny/2; ++r ) {
                                for ( int c = 0; c < nx/2; ++ c) {
                                        idx1 = (size_t)s*nxy+(size_t)r*nx+c;
                                        idx2 = (s+nz/2+zodd)*(size_t)nxy+(r+ny/2+yodd)*(size_t)nx+c+nx/2+xodd;
                                        tmp = rdata[idx1];
                                        rdata[idx1] = rdata[idx2];
                                        rdata[idx2] = tmp;
                                }
                        }
                }
                // Swap the bottom right front and back left top quadrants
                for ( int s = 0; s < nz/2; ++s ) {
                        for ( int r = 0; r < ny/2; ++r ) {
                                for ( int c = nx-1; c >= (nx/2+xodd); --c) {
                                        idx1 = (size_t)s*nxy+(size_t)r*nx+c;
                                        idx2 = (s+nz/2+zodd)*(size_t)nxy+(r+ny/2+yodd)*(size_t)nx+c-nx/2-xodd;
                                        tmp = rdata[idx1];
                                        rdata[idx1] = rdata[idx2];
                                        rdata[idx2] = tmp;
                                }
                        }
                }
                // Swap the top right front and back left bottom quadrants
                for ( int s = 0; s < nz/2; ++s ) {
                        for ( int r = ny-1; r >= (ny/2+yodd); --r ) {
                                for ( int c = nx-1; c >= (nx/2+xodd); --c) {
                                        idx1 = (size_t)s*nxy+(size_t)r*nx+c;
                                        idx2 = (s+nz/2+zodd)*(size_t)nxy+(r-ny/2-yodd)*(size_t)nx+c-nx/2-xodd;
                                        tmp = rdata[idx1];
                                        rdata[idx1] = rdata[idx2];
                                        rdata[idx2] = tmp;
                                }
                        }
                }
                // Swap the top left front and back right bottom quadrants
                for ( int s = 0; s < nz/2; ++s ) {
                        for ( int r = ny-1; r >= (ny/2+yodd); --r ) {
                                for ( int c = 0; c < nx/2; ++c) {
                                        idx1 = (size_t)s*nxy+(size_t)r*nx+c;
                                        idx2 = (s+nz/2+zodd)*(size_t)nxy+(r-ny/2-yodd)*(size_t)nx+c+nx/2+xodd;
                                        tmp = rdata[idx1];
                                        rdata[idx1] = rdata[idx2];
                                        rdata[idx2] = tmp;
                                }
                        }
                }
        }
}

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