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 4832 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 4797 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().

04798 {
04799         if ( !image->is_complex() ) throw ImageFormatException("Can not handle images that are not complex in fourier phase shift 180");
04800 
04801         int nx = image->get_xsize();
04802         int ny = image->get_ysize();
04803         int nz = image->get_zsize();
04804 
04805         int nxy = nx * ny;
04806 
04807         float *rdata = image->get_data();
04808 
04809         // Who uses this function? It doesn't work for odd images, and it will give incorrect results for some even images
04810         // d.woolford, March 15 2009
04811         int of=0;
04812         if (((ny/2)%2)+((nz/2)%2)==1) of=1;
04813 
04814         for (int k = 0; k < nz; k++) {
04815                 size_t k2 = (size_t)k * nxy;
04816 
04817                 for (int j = 0; j < ny; j++) {
04818                         int i = ((k+j)%2==of?2:0);
04819                         size_t j2 = j * nx + k2;
04820 
04821                         for (; i < nx; i += 4) {
04822                                 rdata[i + j2] *= -1.0f;
04823                                 rdata[i + j2 + 1] *= -1.0f;
04824                         }
04825                 }
04826         }
04827 }

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

04927 {
04928         int nx = image->get_xsize();
04929         int ny = image->get_ysize();
04930         int nz = image->get_zsize();
04931 
04932         int xodd = (nx % 2) == 1;
04933         int yodd = (ny % 2) == 1;
04934         int zodd = (nz % 2) == 1;
04935 
04936         int nxy = nx * ny;
04937 
04938         float *rdata = image->get_data();
04939 
04940         if ( ny == 1 && nz == 1 ){
04941                 throw ImageDimensionException("Error, cannot handle 1D images. This function should not have been called");
04942         }
04943         else if ( nz == 1 ) {
04944                 float tmp;
04945                 if ( yodd ) {
04946                         // Iterate along middle row, swapping values where appropriate
04947                         int r = ny/2;
04948                         for ( int c = 0; c < nx/2; ++c ) {
04949                                 int idx1 = r*nx + c;
04950                                 int idx2 = r*nx + c + nx/2+ xodd;
04951                                 tmp = rdata[idx1];
04952                                 rdata[idx1] = rdata[idx2];
04953                                 rdata[idx2] = tmp;
04954                         }
04955                 }
04956 
04957                 if ( xodd )     {
04958                         // Iterate along the central column, swapping values where appropriate
04959                         int c = nx/2;
04960                         for (  int r = 0; r < ny/2; ++r ) {
04961                                 int idx1 = r*nx + c;
04962                                 int idx2 = (r+ny/2+yodd)*nx + c;
04963                                 tmp = rdata[idx1];
04964                                 rdata[idx1] = rdata[idx2];
04965                                 rdata[idx2] = tmp;
04966                         }
04967                 }
04968         }
04969         else // nx && ny && nz are greater than 1
04970         {
04971                 float tmp;
04972                 if ( xodd ) {
04973                         // Iterate along the x = nx/2 slice, swapping values where appropriate
04974                         int c = nx/2;
04975                         size_t idx1, idx2;
04976                         for( int s = 0; s < nz/2; ++s ) {
04977                                 for ( int r = 0; r < ny/2; ++r ) {
04978                                         idx1 = (size_t)s*nxy+(size_t)r*nx+c;
04979                                         idx2 = (s+nz/2+zodd)*(size_t)nxy+(r+ny/2+yodd)*(size_t)nx+c;
04980                                         tmp = rdata[idx1];
04981                                         rdata[idx1] = rdata[idx2];
04982                                         rdata[idx2] = tmp;
04983                                 }
04984                         }
04985 
04986                         for( int s = nz-1; s >= (nz/2+zodd); --s ) {
04987                                 for ( int r = 0; r < ny/2; ++r ) {
04988                                         idx1 = (size_t)s*nxy+(size_t)r*nx+c;
04989                                         idx2 = (s-nz/2-zodd)*(size_t)nxy+(r+ny/2+yodd)*(size_t)nx+c;
04990                                         tmp = rdata[idx1];
04991                                         rdata[idx1] = rdata[idx2];
04992                                         rdata[idx2] = tmp;
04993                                 }
04994                         }
04995                 }
04996                 if ( yodd ) {
04997                         // Iterate along the y = ny/2 slice, swapping values where appropriate
04998                         int r = ny/2;
04999                         size_t idx1, idx2;
05000                         for( int s = 0; s < nz/2; ++s ) {
05001                                 for ( int c = 0; c < nx/2; ++c ) {
05002                                         idx1 = (size_t)s*nxy+(size_t)r*nx+c;
05003                                         idx2 =(s+nz/2+zodd)*(size_t)nxy+(size_t)r*nx+c+nx/2+xodd;
05004                                         tmp = rdata[idx1];
05005                                         rdata[idx1] = rdata[idx2];
05006                                         rdata[idx2] = tmp;
05007                                 }
05008                         }
05009 
05010                         for( int s = nz-1; s >= (nz/2+zodd); --s ) {
05011                                 for ( int c = 0; c < nx/2; ++c ) {
05012                                         idx1 = (size_t)s*nxy+(size_t)r*nx+c;
05013                                         idx2 = (s-nz/2-zodd)*(size_t)nxy+(size_t)r*nx+c+nx/2+xodd;
05014                                         tmp = rdata[idx1];
05015                                         rdata[idx1] = rdata[idx2];
05016                                         rdata[idx2] = tmp;
05017                                 }
05018                         }
05019                 }
05020                 if ( zodd ) {
05021                         // Iterate along the z = nz/2 slice, swapping values where appropriate
05022                         int s = nz/2;
05023                         size_t idx1, idx2;
05024                         for( int r = 0; r < ny/2; ++r ) {
05025                                 for ( int c = 0; c < nx/2; ++c ) {
05026                                         idx1 = (size_t)s*nxy+(size_t)r*nx+c;
05027                                         idx2 = (size_t)s*nxy+(r+ny/2+yodd)*(size_t)nx+c+nx/2+xodd;
05028                                         tmp = rdata[idx1];
05029                                         rdata[idx1] = rdata[idx2];
05030                                         rdata[idx2] = tmp;
05031                                 }
05032                         }
05033 
05034                         for( int r = ny-1; r >= (ny/2+yodd); --r ) {
05035                                 for ( int c = 0; c < nx/2; ++c ) {
05036                                         idx1 = (size_t)s*nxy+(size_t)r*nx+c;
05037                                         idx2 = (size_t)s*nxy+(r-ny/2-yodd)*(size_t)nx+c+nx/2+xodd;
05038                                         tmp = rdata[idx1];
05039                                         rdata[idx1] = rdata[idx2];
05040                                         rdata[idx2] = tmp;
05041                                 }
05042                         }
05043                 }
05044         }
05045 }

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

04830 {
04831         int nx = image->get_xsize();
04832         int ny = image->get_ysize();
04833         int nz = image->get_zsize();
04834 
04835         int xodd = (nx % 2) == 1;
04836         int yodd = (ny % 2) == 1;
04837         int zodd = (nz % 2) == 1;
04838 
04839         int nxy = nx * ny;
04840 
04841         float *rdata = image->get_data();
04842 
04843         if ( ny == 1 && nz == 1 ){
04844                 throw ImageDimensionException("Error, cannot handle 1D images. This function should not have been called");
04845         }
04846         else if ( nz == 1 ) {
04847 
04848                 // Swap the bottom left and top right corners
04849                 for ( int r = 0; r < ny/2; ++r ) {
04850                         for ( int c = 0; c < nx/2; ++c) {
04851                                 int idx1 = r*nx + c;
04852                                 int idx2 = (r+ny/2+yodd)*nx + c + nx/2+xodd;
04853                                 float tmp = rdata[idx1];
04854                                 rdata[idx1] = rdata[idx2];
04855                                 rdata[idx2] = tmp;
04856                         }
04857                 }
04858 
04859                 // Swap the top left and bottom right corners
04860                 for ( int r = ny-1; r >= (ny/2+yodd); --r ) {
04861                         for ( int c = 0; c < nx/2; ++c) {
04862                                 int idx1 = r*nx + c;
04863                                 int idx2 = (r-ny/2-yodd)*nx + c + nx/2+xodd;
04864                                 float tmp = rdata[idx1];
04865                                 rdata[idx1] = rdata[idx2];
04866                                 rdata[idx2] = tmp;
04867                         }
04868                 }
04869         }
04870         else // nx && ny && nz are greater than 1
04871         {
04872                 float tmp;
04873                 // Swap the bottom left front and back right top quadrants
04874                 size_t idx1, idx2;
04875 
04876                 for ( int s = 0; s < nz/2; ++s ) {
04877                         for ( int r = 0; r < ny/2; ++r ) {
04878                                 for ( int c = 0; c < nx/2; ++ c) {
04879                                         idx1 = (size_t)s*nxy+(size_t)r*nx+c;
04880                                         idx2 = (s+nz/2+zodd)*(size_t)nxy+(r+ny/2+yodd)*(size_t)nx+c+nx/2+xodd;
04881                                         tmp = rdata[idx1];
04882                                         rdata[idx1] = rdata[idx2];
04883                                         rdata[idx2] = tmp;
04884                                 }
04885                         }
04886                 }
04887                 // Swap the bottom right front and back left top quadrants
04888                 for ( int s = 0; s < nz/2; ++s ) {
04889                         for ( int r = 0; r < ny/2; ++r ) {
04890                                 for ( int c = nx-1; c >= (nx/2+xodd); --c) {
04891                                         idx1 = (size_t)s*nxy+(size_t)r*nx+c;
04892                                         idx2 = (s+nz/2+zodd)*(size_t)nxy+(r+ny/2+yodd)*(size_t)nx+c-nx/2-xodd;
04893                                         tmp = rdata[idx1];
04894                                         rdata[idx1] = rdata[idx2];
04895                                         rdata[idx2] = tmp;
04896                                 }
04897                         }
04898                 }
04899                 // Swap the top right front and back left bottom quadrants
04900                 for ( int s = 0; s < nz/2; ++s ) {
04901                         for ( int r = ny-1; r >= (ny/2+yodd); --r ) {
04902                                 for ( int c = nx-1; c >= (nx/2+xodd); --c) {
04903                                         idx1 = (size_t)s*nxy+(size_t)r*nx+c;
04904                                         idx2 = (s+nz/2+zodd)*(size_t)nxy+(r-ny/2-yodd)*(size_t)nx+c-nx/2-xodd;
04905                                         tmp = rdata[idx1];
04906                                         rdata[idx1] = rdata[idx2];
04907                                         rdata[idx2] = tmp;
04908                                 }
04909                         }
04910                 }
04911                 // Swap the top left front and back right bottom quadrants
04912                 for ( int s = 0; s < nz/2; ++s ) {
04913                         for ( int r = ny-1; r >= (ny/2+yodd); --r ) {
04914                                 for ( int c = 0; c < nx/2; ++c) {
04915                                         idx1 = (size_t)s*nxy+(size_t)r*nx+c;
04916                                         idx2 = (s+nz/2+zodd)*(size_t)nxy+(r-ny/2-yodd)*(size_t)nx+c+nx/2+xodd;
04917                                         tmp = rdata[idx1];
04918                                         rdata[idx1] = rdata[idx2];
04919                                         rdata[idx2] = tmp;
04920                                 }
04921                         }
04922                 }
04923         }
04924 }


The documentation for this class was generated from the following files:
Generated on Tue Jun 11 12:44:22 2013 for EMAN2 by  doxygen 1.4.7