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:

[legend]
Collaboration diagram for EMAN::Phase180Processor:
[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 4750 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 4616 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().

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

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 4745 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().

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

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 4648 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().

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


The documentation for this class was generated from the following files:
Generated on Fri Apr 30 15:39:25 2010 for EMAN2 by  doxygen 1.3.9.1