#include <processor.h>
Inheritance diagram for EMAN::PhaseToCornerProcessor:
Public Member Functions | |
virtual void | process_inplace (EMData *image) |
To process an image in-place. | |
virtual string | get_name () const |
Get the processor's name. | |
virtual string | get_desc () const |
Get the descrition of this specific processor. | |
Static Public Member Functions | |
Processor * | NEW () |
Static Public Attributes | |
const string | NAME = "xform.phaseorigin.tocorner" |
Definition at line 4864 of file processor.h.
|
Get the descrition of this specific processor. This function must be overwritten by a subclass.
Implements EMAN::Processor. Definition at line 4879 of file processor.h. 04880 { 04881 return "Translates a centered image to the corner in a forward fashion"; 04882 }
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 4869 of file processor.h. 04870 {
04871 return NAME;
04872 }
|
|
Definition at line 4874 of file processor.h. 04875 { 04876 return new PhaseToCornerProcessor(); 04877 }
|
|
To process an image in-place. For those processors which can only be processed out-of-place, override this function to just print out some error message to remind user call the out-of-place version.
Implements EMAN::Processor. Definition at line 4969 of file processor.cpp. References emdata_phaseorigin_to_corner(), EMAN::Phase180Processor::fourier_phaseshift180(), EMAN::EMData::get_data(), EMAN::EMData::get_ndim(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::EMData::is_complex(), NullPointerException, nx, ny, rdata, EMAN::Phase180Processor::swap_central_slices_180(), and EMAN::Phase180Processor::swap_corners_180(). 04970 { 04971 if (!image) throw NullPointerException("Error: attempt to phase shift a null image"); 04972 04973 #ifdef EMAN2_USING_CUDA 04974 if (EMData::usecuda == 1 && image->getcudarwdata() && image->get_ndim() == 2) { // Because CUDA phase origin to center only works for 2D atm 04975 //cout << "CUDA tocorner " << image->getcudarwdata() << endl; 04976 emdata_phaseorigin_to_corner(image->getcudarwdata(), image->get_xsize(), image->get_ysize(), image->get_zsize()); 04977 return; 04978 } 04979 #endif // EMAN2_USING_CUDA 04980 04981 if (image->is_complex()) { 04982 fourier_phaseshift180(image); 04983 return; 04984 } 04985 04986 int nx = image->get_xsize(); 04987 int ny = image->get_ysize(); 04988 int nz = image->get_zsize(); 04989 04990 if ( ny == 1 && nz == 1 && nx == 1) return; 04991 04992 int nxy = nx * ny; 04993 04994 float *rdata = image->get_data(); 04995 04996 bool xodd = (nx % 2) == 1; 04997 bool yodd = (ny % 2) == 1; 04998 bool zodd = (nz % 2) == 1; 04999 05000 if ( ny == 1 && nz == 1 ){ 05001 if (xodd){ 05002 // Put the last pixel in the center, shifting the contents 05003 // to right of the center one step to the right 05004 float in_x = rdata[nx-1]; 05005 float tmp; 05006 for ( int i = nx/2; i < nx; ++i ) { 05007 tmp = rdata[i]; 05008 rdata[i] = in_x; 05009 in_x = tmp; 05010 } 05011 } 05012 // now the operation is straight forward 05013 for ( int i = 0; i < nx/2; ++i ) { 05014 int idx = i+nx/2+xodd; 05015 float tmp = rdata[i]; 05016 rdata[i] = rdata[idx]; 05017 rdata[idx] = tmp; 05018 } 05019 05020 } 05021 else if ( nz == 1 ) { 05022 if (yodd) { 05023 // Tranfer the top row into the middle row, 05024 // shifting all pixels above and including the current middle up one. 05025 for ( int c = 0; c < nx; ++c ) { 05026 // Get the value in the top row 05027 float last_val = rdata[(ny-1)*nx + c]; 05028 float tmp; 05029 for ( int r = ny/2; r < ny; ++r ){ 05030 int idx =r*nx+c; 05031 tmp = rdata[idx]; 05032 rdata[idx] = last_val; 05033 last_val = tmp; 05034 } 05035 } 05036 } 05037 05038 if (xodd) { 05039 // Transfer the right most column into the center column 05040 // Shift all columns right of and including center to the right one pixel 05041 for ( int r = 0; r < ny; ++r ) { 05042 float last_val = rdata[(r+1)*nx -1]; 05043 float tmp; 05044 for ( int c = nx/2; c < nx; ++c ){ 05045 int idx =r*nx+c; 05046 tmp = rdata[idx]; 05047 rdata[idx] = last_val; 05048 last_val = tmp; 05049 } 05050 } 05051 } 05052 // It is important central slice shifting come after the previous two operations 05053 swap_central_slices_180(image); 05054 // Now the corners of the image can be shifted... 05055 swap_corners_180(image); 05056 05057 } 05058 else 05059 { 05060 float tmp; 05061 if (zodd) { 05062 // Tranfer the back slice into the middle slice, 05063 // shifting all pixels beyond and including the middle slice back one. 05064 size_t idx = 0; 05065 for (int r = 0; r < ny; ++r){ 05066 for (int c = 0; c < nx; ++c) { 05067 float last_val = rdata[(nz-1)*nxy+r*nx+c]; 05068 for (int s = nz/2; s < nz; ++s) { 05069 idx = (size_t)s*nxy+r*nx+c; 05070 tmp = rdata[idx]; 05071 rdata[idx] = last_val; 05072 last_val = tmp; 05073 } 05074 } 05075 } 05076 } 05077 if (yodd) { 05078 // Tranfer the top slice into the middle slice, 05079 // shifting all pixels above and including the middle slice up one. 05080 size_t idx = 0; 05081 for (int s = 0; s < nz; ++s) { 05082 for (int c = 0; c < nx; ++c) { 05083 float last_val = rdata[s*nxy+(ny-1)*nx+c]; 05084 for (int r = ny/2; r < ny; ++r){ 05085 idx = (size_t)s*nxy+r*nx+c; 05086 tmp = rdata[idx]; 05087 rdata[idx] = last_val; 05088 last_val = tmp; 05089 } 05090 } 05091 } 05092 } 05093 if (xodd) { 05094 // Transfer the right most slice into the central slice 05095 // Shift all pixels to right of and including center slice to the right one pixel 05096 size_t idx = 0; 05097 for (int s = 0; s < nz; ++s) { 05098 for (int r = 0; r < ny; ++r) { 05099 float last_val = rdata[s*nxy+r*nx+nx-1]; 05100 for (int c = nx/2; c < nx; ++c){ 05101 idx = (size_t)s*nxy+r*nx+c; 05102 tmp = rdata[idx]; 05103 rdata[idx] = last_val; 05104 last_val = tmp; 05105 } 05106 } 05107 } 05108 } 05109 // Now swap the various parts in the central slices 05110 swap_central_slices_180(image); 05111 // Now shift the corners 05112 swap_corners_180(image); 05113 } 05114 }
|
|
Definition at line 165 of file processor.cpp. |