Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::Phase180Processor Class Reference
[unit test in Python]

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 4751 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:
image the image to be operated upon
Exceptions:
ImageFormatException if the image is not in complex format

Definition at line 4647 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(), and rdata.

Referenced by EMAN::PhaseToCenterProcessor::process_inplace(), and EMAN::PhaseToCornerProcessor::process_inplace().

04648 {
04649         if ( !image->is_complex() ) throw ImageFormatException("Can not handle images that are not complex in fourier phase shift 180");
04650 
04651         int nx = image->get_xsize();
04652         int ny = image->get_ysize();
04653         int nz = image->get_zsize();
04654 
04655         int nxy = nx * ny;
04656 
04657         float *rdata = image->get_data();
04658 
04659         // Who uses this function? It doesn't work for odd images, and it will give incorrect results for some even images
04660         // d.woolford, March 15 2009
04661         int of=0;
04662         if (((ny/2)%2)+((nz/2)%2)==1) of=1;
04663 
04664         for (int k = 0; k < nz; k++) {
04665                 size_t k2 = k * nxy;
04666 
04667                 for (int j = 0; j < ny; j++) {
04668                         int i = ((k+j)%2==of?2:0);
04669                         size_t j2 = j * nx + k2;
04670 
04671                         for (; i < nx; i += 4) {
04672                                 rdata[i + j2] *= -1.0f;
04673                                 rdata[i + j2 + 1] *= -1.0f;
04674                         }
04675                 }
04676         }
04677 }

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:
image the image to be operated upon
Exceptions:
ImageDimensionException if the image is 1D
NullPointerException if the image is null

Definition at line 4776 of file processor.cpp.

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

Referenced by EMAN::PhaseToCenterProcessor::process_inplace(), and EMAN::PhaseToCornerProcessor::process_inplace().

04777 {
04778         int nx = image->get_xsize();
04779         int ny = image->get_ysize();
04780         int nz = image->get_zsize();
04781 
04782         int xodd = (nx % 2) == 1;
04783         int yodd = (ny % 2) == 1;
04784         int zodd = (nz % 2) == 1;
04785 
04786         int nxy = nx * ny;
04787 
04788         float *rdata = image->get_data();
04789 
04790         if ( ny == 1 && nz == 1 ){
04791                 throw ImageDimensionException("Error, cannot handle 1D images. This function should not have been called");
04792         }
04793         else if ( nz == 1 ) {
04794                 float tmp;
04795                 if ( yodd ) {
04796                         // Iterate along middle row, swapping values where appropriate
04797                         int r = ny/2;
04798                         for ( int c = 0; c < nx/2; ++c ) {
04799                                 int idx1 = r*nx + c;
04800                                 int idx2 = r*nx + c + nx/2+ xodd;
04801                                 tmp = rdata[idx1];
04802                                 rdata[idx1] = rdata[idx2];
04803                                 rdata[idx2] = tmp;
04804                         }
04805                 }
04806 
04807                 if ( xodd )     {
04808                         // Iterate along the central column, swapping values where appropriate
04809                         int c = nx/2;
04810                         for (  int r = 0; r < ny/2; ++r ) {
04811                                 int idx1 = r*nx + c;
04812                                 int idx2 = (r+ny/2+yodd)*nx + c;
04813                                 tmp = rdata[idx1];
04814                                 rdata[idx1] = rdata[idx2];
04815                                 rdata[idx2] = tmp;
04816                         }
04817                 }
04818         }
04819         else // nx && ny && nz are greater than 1
04820         {
04821                 float tmp;
04822                 if ( xodd ) {
04823                         // Iterate along the x = nx/2 slice, swapping values where appropriate
04824                         int c = nx/2;
04825                         size_t idx1, idx2;
04826                         for( int s = 0; s < nz/2; ++s ) {
04827                                 for ( int r = 0; r < ny/2; ++r ) {
04828                                         idx1 = s*nxy+r*nx+c;
04829                                         idx2 = (s+nz/2+zodd)*nxy+(r+ny/2+yodd)*nx+c;
04830                                         tmp = rdata[idx1];
04831                                         rdata[idx1] = rdata[idx2];
04832                                         rdata[idx2] = tmp;
04833                                 }
04834                         }
04835 
04836                         for( int s = nz-1; s >= (nz/2+zodd); --s ) {
04837                                 for ( int r = 0; r < ny/2; ++r ) {
04838                                         idx1 = s*nxy+r*nx+c;
04839                                         idx2 = (s-nz/2-zodd)*nxy+(r+ny/2+yodd)*nx+c;
04840                                         tmp = rdata[idx1];
04841                                         rdata[idx1] = rdata[idx2];
04842                                         rdata[idx2] = tmp;
04843                                 }
04844                         }
04845                 }
04846                 if ( yodd ) {
04847                         // Iterate along the y = ny/2 slice, swapping values where appropriate
04848                         int r = ny/2;
04849                         size_t idx1, idx2;
04850                         for( int s = 0; s < nz/2; ++s ) {
04851                                 for ( int c = 0; c < nx/2; ++c ) {
04852                                         idx1 = s*nxy+r*nx+c;
04853                                         idx2 =(s+nz/2+zodd)*nxy+r*nx+c+nx/2+xodd;
04854                                         tmp = rdata[idx1];
04855                                         rdata[idx1] = rdata[idx2];
04856                                         rdata[idx2] = tmp;
04857                                 }
04858                         }
04859 
04860                         for( int s = nz-1; s >= (nz/2+zodd); --s ) {
04861                                 for ( int c = 0; c < nx/2; ++c ) {
04862                                         idx1 = s*nxy+r*nx+c;
04863                                         idx2 = (s-nz/2-zodd)*nxy+r*nx+c+nx/2+xodd;
04864                                         tmp = rdata[idx1];
04865                                         rdata[idx1] = rdata[idx2];
04866                                         rdata[idx2] = tmp;
04867                                 }
04868                         }
04869                 }
04870                 if ( zodd ) {
04871                         // Iterate along the z = nz/2 slice, swapping values where appropriate
04872                         int s = nz/2;
04873                         size_t idx1, idx2;
04874                         for( int r = 0; r < ny/2; ++r ) {
04875                                 for ( int c = 0; c < nx/2; ++c ) {
04876                                         idx1 = s*nxy+r*nx+c;
04877                                         idx2 = s*nxy+(r+ny/2+yodd)*nx+c+nx/2+xodd;
04878                                         tmp = rdata[idx1];
04879                                         rdata[idx1] = rdata[idx2];
04880                                         rdata[idx2] = tmp;
04881                                 }
04882                         }
04883 
04884                         for( int r = ny-1; r >= (ny/2+yodd); --r ) {
04885                                 for ( int c = 0; c < nx/2; ++c ) {
04886                                         idx1 = s*nxy+r*nx+c;
04887                                         idx2 = s*nxy+(r-ny/2-yodd)*nx+c+nx/2+xodd;
04888                                         tmp = rdata[idx1];
04889                                         rdata[idx1] = rdata[idx2];
04890                                         rdata[idx2] = tmp;
04891                                 }
04892                         }
04893                 }
04894         }
04895 }

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:
image the image to be operated upon
Exceptions:
ImageDimensionException if the image is 1D
NullPointerException if the image is null

Definition at line 4679 of file processor.cpp.

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

Referenced by EMAN::PhaseToCenterProcessor::process_inplace(), and EMAN::PhaseToCornerProcessor::process_inplace().

04680 {
04681         int nx = image->get_xsize();
04682         int ny = image->get_ysize();
04683         int nz = image->get_zsize();
04684 
04685         int xodd = (nx % 2) == 1;
04686         int yodd = (ny % 2) == 1;
04687         int zodd = (nz % 2) == 1;
04688 
04689         int nxy = nx * ny;
04690 
04691         float *rdata = image->get_data();
04692 
04693         if ( ny == 1 && nz == 1 ){
04694                 throw ImageDimensionException("Error, cannot handle 1D images. This function should not have been called");
04695         }
04696         else if ( nz == 1 ) {
04697 
04698                 // Swap the bottom left and top right corners
04699                 for ( int r = 0; r < ny/2; ++r ) {
04700                         for ( int c = 0; c < nx/2; ++c) {
04701                                 int idx1 = r*nx + c;
04702                                 int idx2 = (r+ny/2+yodd)*nx + c + nx/2+xodd;
04703                                 float tmp = rdata[idx1];
04704                                 rdata[idx1] = rdata[idx2];
04705                                 rdata[idx2] = tmp;
04706                         }
04707                 }
04708 
04709                 // Swap the top left and bottom right corners
04710                 for ( int r = ny-1; r >= (ny/2+yodd); --r ) {
04711                         for ( int c = 0; c < nx/2; ++c) {
04712                                 int idx1 = r*nx + c;
04713                                 int idx2 = (r-ny/2-yodd)*nx + c + nx/2+xodd;
04714                                 float tmp = rdata[idx1];
04715                                 rdata[idx1] = rdata[idx2];
04716                                 rdata[idx2] = tmp;
04717                         }
04718                 }
04719         }
04720         else // nx && ny && nz are greater than 1
04721         {
04722                 float tmp;
04723                 // Swap the bottom left front and back right top quadrants
04724                 size_t idx1, idx2;
04725 
04726                 for ( int s = 0; s < nz/2; ++s ) {
04727                         for ( int r = 0; r < ny/2; ++r ) {
04728                                 for ( int c = 0; c < nx/2; ++ c) {
04729                                         idx1 = s*nxy+r*nx+c;
04730                                         idx2 = (s+nz/2+zodd)*nxy+(r+ny/2+yodd)*nx+c+nx/2+xodd;
04731                                         tmp = rdata[idx1];
04732                                         rdata[idx1] = rdata[idx2];
04733                                         rdata[idx2] = tmp;
04734                                 }
04735                         }
04736                 }
04737                 // Swap the bottom right front and back left top quadrants
04738                 for ( int s = 0; s < nz/2; ++s ) {
04739                         for ( int r = 0; r < ny/2; ++r ) {
04740                                 for ( int c = nx-1; c >= (nx/2+xodd); --c) {
04741                                         idx1 = s*nxy+r*nx+c;
04742                                         idx2 = (s+nz/2+zodd)*nxy+(r+ny/2+yodd)*nx+c-nx/2-xodd;
04743                                         tmp = rdata[idx1];
04744                                         rdata[idx1] = rdata[idx2];
04745                                         rdata[idx2] = tmp;
04746                                 }
04747                         }
04748                 }
04749                 // Swap the top right front and back left bottom quadrants
04750                 for ( int s = 0; s < nz/2; ++s ) {
04751                         for ( int r = ny-1; r >= (ny/2+yodd); --r ) {
04752                                 for ( int c = nx-1; c >= (nx/2+xodd); --c) {
04753                                         idx1 = s*nxy+r*nx+c;
04754                                         idx2 = (s+nz/2+zodd)*nxy+(r-ny/2-yodd)*nx+c-nx/2-xodd;
04755                                         tmp = rdata[idx1];
04756                                         rdata[idx1] = rdata[idx2];
04757                                         rdata[idx2] = tmp;
04758                                 }
04759                         }
04760                 }
04761                 // Swap the top left front and back right bottom quadrants
04762                 for ( int s = 0; s < nz/2; ++s ) {
04763                         for ( int r = ny-1; r >= (ny/2+yodd); --r ) {
04764                                 for ( int c = 0; c < nx/2; ++c) {
04765                                         idx1 = s*nxy+r*nx+c;
04766                                         idx2 = (s+nz/2+zodd)*nxy+(r-ny/2-yodd)*nx+c+nx/2+xodd;
04767                                         tmp = rdata[idx1];
04768                                         rdata[idx1] = rdata[idx2];
04769                                         rdata[idx2] = tmp;
04770                                 }
04771                         }
04772                 }
04773         }
04774 }


The documentation for this class was generated from the following files:
Generated on Tue May 25 17:37:33 2010 for EMAN2 by  doxygen 1.4.4