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 4575 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 4615 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.

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

04616 {
04617         if ( !image->is_complex() ) throw ImageFormatException("Can not handle images that are not complex in fourier phase shift 180");
04618 
04619         int nx = image->get_xsize();
04620         int ny = image->get_ysize();
04621         int nz = image->get_zsize();
04622 
04623         int nxy = nx * ny;
04624 
04625         float *rdata = image->get_data();
04626 
04627         // Who uses this function? It doesn't work for odd images, and it will give incorrect results for some even images
04628         // d.woolford, March 15 2009
04629         int of=0;
04630         if (((ny/2)%2)+((nz/2)%2)==1) of=1;
04631 
04632         for (int k = 0; k < nz; k++) {
04633                 size_t k2 = k * nxy;
04634 
04635                 for (int j = 0; j < ny; j++) {
04636                         int i = ((k+j)%2==of?2:0);
04637                         size_t j2 = j * nx + k2;
04638 
04639                         for (; i < nx; i += 4) {
04640                                 rdata[i + j2] *= -1.0f;
04641                                 rdata[i + j2 + 1] *= -1.0f;
04642                         }
04643                 }
04644         }
04645 }

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 4744 of file processor.cpp.

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

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

04745 {
04746         int nx = image->get_xsize();
04747         int ny = image->get_ysize();
04748         int nz = image->get_zsize();
04749 
04750         int xodd = (nx % 2) == 1;
04751         int yodd = (ny % 2) == 1;
04752         int zodd = (nz % 2) == 1;
04753 
04754         int nxy = nx * ny;
04755 
04756         float *rdata = image->get_data();
04757 
04758         if ( ny == 1 && nz == 1 ){
04759                 throw ImageDimensionException("Error, cannot handle 1D images. This function should not have been called");
04760         }
04761         else if ( nz == 1 ) {
04762                 float tmp;
04763                 if ( yodd ) {
04764                         // Iterate along middle row, swapping values where appropriate
04765                         int r = ny/2;
04766                         for ( int c = 0; c < nx/2; ++c ) {
04767                                 int idx1 = r*nx + c;
04768                                 int idx2 = r*nx + c + nx/2+ xodd;
04769                                 tmp = rdata[idx1];
04770                                 rdata[idx1] = rdata[idx2];
04771                                 rdata[idx2] = tmp;
04772                         }
04773                 }
04774 
04775                 if ( xodd )     {
04776                         // Iterate along the central column, swapping values where appropriate
04777                         int c = nx/2;
04778                         for (  int r = 0; r < ny/2; ++r ) {
04779                                 int idx1 = r*nx + c;
04780                                 int idx2 = (r+ny/2+yodd)*nx + c;
04781                                 tmp = rdata[idx1];
04782                                 rdata[idx1] = rdata[idx2];
04783                                 rdata[idx2] = tmp;
04784                         }
04785                 }
04786         }
04787         else // nx && ny && nz are greater than 1
04788         {
04789                 float tmp;
04790                 if ( xodd ) {
04791                         // Iterate along the x = nx/2 slice, swapping values where appropriate
04792                         int c = nx/2;
04793                         size_t idx1, idx2;
04794                         for( int s = 0; s < nz/2; ++s ) {
04795                                 for ( int r = 0; r < ny/2; ++r ) {
04796                                         idx1 = s*nxy+r*nx+c;
04797                                         idx2 = (s+nz/2+zodd)*nxy+(r+ny/2+yodd)*nx+c;
04798                                         tmp = rdata[idx1];
04799                                         rdata[idx1] = rdata[idx2];
04800                                         rdata[idx2] = tmp;
04801                                 }
04802                         }
04803 
04804                         for( int s = nz-1; s >= (nz/2+zodd); --s ) {
04805                                 for ( int r = 0; r < ny/2; ++r ) {
04806                                         idx1 = s*nxy+r*nx+c;
04807                                         idx2 = (s-nz/2-zodd)*nxy+(r+ny/2+yodd)*nx+c;
04808                                         tmp = rdata[idx1];
04809                                         rdata[idx1] = rdata[idx2];
04810                                         rdata[idx2] = tmp;
04811                                 }
04812                         }
04813                 }
04814                 if ( yodd ) {
04815                         // Iterate along the y = ny/2 slice, swapping values where appropriate
04816                         int r = ny/2;
04817                         size_t idx1, idx2;
04818                         for( int s = 0; s < nz/2; ++s ) {
04819                                 for ( int c = 0; c < nx/2; ++c ) {
04820                                         idx1 = s*nxy+r*nx+c;
04821                                         idx2 =(s+nz/2+zodd)*nxy+r*nx+c+nx/2+xodd;
04822                                         tmp = rdata[idx1];
04823                                         rdata[idx1] = rdata[idx2];
04824                                         rdata[idx2] = tmp;
04825                                 }
04826                         }
04827 
04828                         for( int s = nz-1; s >= (nz/2+zodd); --s ) {
04829                                 for ( int c = 0; c < nx/2; ++c ) {
04830                                         idx1 = s*nxy+r*nx+c;
04831                                         idx2 = (s-nz/2-zodd)*nxy+r*nx+c+nx/2+xodd;
04832                                         tmp = rdata[idx1];
04833                                         rdata[idx1] = rdata[idx2];
04834                                         rdata[idx2] = tmp;
04835                                 }
04836                         }
04837                 }
04838                 if ( zodd ) {
04839                         // Iterate along the z = nz/2 slice, swapping values where appropriate
04840                         int s = nz/2;
04841                         size_t idx1, idx2;
04842                         for( int r = 0; r < ny/2; ++r ) {
04843                                 for ( int c = 0; c < nx/2; ++c ) {
04844                                         idx1 = s*nxy+r*nx+c;
04845                                         idx2 = s*nxy+(r+ny/2+yodd)*nx+c+nx/2+xodd;
04846                                         tmp = rdata[idx1];
04847                                         rdata[idx1] = rdata[idx2];
04848                                         rdata[idx2] = tmp;
04849                                 }
04850                         }
04851 
04852                         for( int r = ny-1; r >= (ny/2+yodd); --r ) {
04853                                 for ( int c = 0; c < nx/2; ++c ) {
04854                                         idx1 = s*nxy+r*nx+c;
04855                                         idx2 = s*nxy+(r-ny/2-yodd)*nx+c+nx/2+xodd;
04856                                         tmp = rdata[idx1];
04857                                         rdata[idx1] = rdata[idx2];
04858                                         rdata[idx2] = tmp;
04859                                 }
04860                         }
04861                 }
04862         }
04863 }

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 4647 of file processor.cpp.

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

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

04648 {
04649         int nx = image->get_xsize();
04650         int ny = image->get_ysize();
04651         int nz = image->get_zsize();
04652 
04653         int xodd = (nx % 2) == 1;
04654         int yodd = (ny % 2) == 1;
04655         int zodd = (nz % 2) == 1;
04656 
04657         int nxy = nx * ny;
04658 
04659         float *rdata = image->get_data();
04660 
04661         if ( ny == 1 && nz == 1 ){
04662                 throw ImageDimensionException("Error, cannot handle 1D images. This function should not have been called");
04663         }
04664         else if ( nz == 1 ) {
04665 
04666                 // Swap the bottom left and top right corners
04667                 for ( int r = 0; r < ny/2; ++r ) {
04668                         for ( int c = 0; c < nx/2; ++c) {
04669                                 int idx1 = r*nx + c;
04670                                 int idx2 = (r+ny/2+yodd)*nx + c + nx/2+xodd;
04671                                 float tmp = rdata[idx1];
04672                                 rdata[idx1] = rdata[idx2];
04673                                 rdata[idx2] = tmp;
04674                         }
04675                 }
04676 
04677                 // Swap the top left and bottom right corners
04678                 for ( int r = ny-1; r >= (ny/2+yodd); --r ) {
04679                         for ( int c = 0; c < nx/2; ++c) {
04680                                 int idx1 = r*nx + c;
04681                                 int idx2 = (r-ny/2-yodd)*nx + c + nx/2+xodd;
04682                                 float tmp = rdata[idx1];
04683                                 rdata[idx1] = rdata[idx2];
04684                                 rdata[idx2] = tmp;
04685                         }
04686                 }
04687         }
04688         else // nx && ny && nz are greater than 1
04689         {
04690                 float tmp;
04691                 // Swap the bottom left front and back right top quadrants
04692                 size_t idx1, idx2;
04693 
04694                 for ( int s = 0; s < nz/2; ++s ) {
04695                         for ( int r = 0; r < ny/2; ++r ) {
04696                                 for ( int c = 0; c < nx/2; ++ c) {
04697                                         idx1 = s*nxy+r*nx+c;
04698                                         idx2 = (s+nz/2+zodd)*nxy+(r+ny/2+yodd)*nx+c+nx/2+xodd;
04699                                         tmp = rdata[idx1];
04700                                         rdata[idx1] = rdata[idx2];
04701                                         rdata[idx2] = tmp;
04702                                 }
04703                         }
04704                 }
04705                 // Swap the bottom right front and back left top quadrants
04706                 for ( int s = 0; s < nz/2; ++s ) {
04707                         for ( int r = 0; r < ny/2; ++r ) {
04708                                 for ( int c = nx-1; c >= (nx/2+xodd); --c) {
04709                                         idx1 = s*nxy+r*nx+c;
04710                                         idx2 = (s+nz/2+zodd)*nxy+(r+ny/2+yodd)*nx+c-nx/2-xodd;
04711                                         tmp = rdata[idx1];
04712                                         rdata[idx1] = rdata[idx2];
04713                                         rdata[idx2] = tmp;
04714                                 }
04715                         }
04716                 }
04717                 // Swap the top right front and back left bottom quadrants
04718                 for ( int s = 0; s < nz/2; ++s ) {
04719                         for ( int r = ny-1; r >= (ny/2+yodd); --r ) {
04720                                 for ( int c = nx-1; c >= (nx/2+xodd); --c) {
04721                                         idx1 = s*nxy+r*nx+c;
04722                                         idx2 = (s+nz/2+zodd)*nxy+(r-ny/2-yodd)*nx+c-nx/2-xodd;
04723                                         tmp = rdata[idx1];
04724                                         rdata[idx1] = rdata[idx2];
04725                                         rdata[idx2] = tmp;
04726                                 }
04727                         }
04728                 }
04729                 // Swap the top left front and back right bottom quadrants
04730                 for ( int s = 0; s < nz/2; ++s ) {
04731                         for ( int r = ny-1; r >= (ny/2+yodd); --r ) {
04732                                 for ( int c = 0; c < nx/2; ++c) {
04733                                         idx1 = s*nxy+r*nx+c;
04734                                         idx2 = (s+nz/2+zodd)*nxy+(r-ny/2-yodd)*nx+c+nx/2+xodd;
04735                                         tmp = rdata[idx1];
04736                                         rdata[idx1] = rdata[idx2];
04737                                         rdata[idx2] = tmp;
04738                                 }
04739                         }
04740                 }
04741         }
04742 }


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