#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 4833 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 4848 of file processor.h. 04849 { 04850 return "Translates a centered image to the corner in a forward fashion"; 04851 }
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 4838 of file processor.h. 04839 {
04840 return NAME;
04841 }
|
|
Definition at line 4843 of file processor.h. 04844 { 04845 return new PhaseToCornerProcessor(); 04846 }
|
|
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 4954 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(). 04955 { 04956 if (!image) throw NullPointerException("Error: attempt to phase shift a null image"); 04957 04958 #ifdef EMAN2_USING_CUDA 04959 if (EMData::usecuda == 1 && image->getcudarwdata() && image->get_ndim() == 2) { // Because CUDA phase origin to center only works for 2D atm 04960 //cout << "CUDA tocorner " << image->getcudarwdata() << endl; 04961 emdata_phaseorigin_to_corner(image->getcudarwdata(), image->get_xsize(), image->get_ysize(), image->get_zsize()); 04962 return; 04963 } 04964 #endif // EMAN2_USING_CUDA 04965 04966 if (image->is_complex()) { 04967 fourier_phaseshift180(image); 04968 return; 04969 } 04970 04971 int nx = image->get_xsize(); 04972 int ny = image->get_ysize(); 04973 int nz = image->get_zsize(); 04974 04975 if ( ny == 1 && nz == 1 && nx == 1) return; 04976 04977 int nxy = nx * ny; 04978 04979 float *rdata = image->get_data(); 04980 04981 bool xodd = (nx % 2) == 1; 04982 bool yodd = (ny % 2) == 1; 04983 bool zodd = (nz % 2) == 1; 04984 04985 if ( ny == 1 && nz == 1 ){ 04986 if (xodd){ 04987 // Put the last pixel in the center, shifting the contents 04988 // to right of the center one step to the right 04989 float in_x = rdata[nx-1]; 04990 float tmp; 04991 for ( int i = nx/2; i < nx; ++i ) { 04992 tmp = rdata[i]; 04993 rdata[i] = in_x; 04994 in_x = tmp; 04995 } 04996 } 04997 // now the operation is straight forward 04998 for ( int i = 0; i < nx/2; ++i ) { 04999 int idx = i+nx/2+xodd; 05000 float tmp = rdata[i]; 05001 rdata[i] = rdata[idx]; 05002 rdata[idx] = tmp; 05003 } 05004 05005 } 05006 else if ( nz == 1 ) { 05007 if (yodd) { 05008 // Tranfer the top row into the middle row, 05009 // shifting all pixels above and including the current middle up one. 05010 for ( int c = 0; c < nx; ++c ) { 05011 // Get the value in the top row 05012 float last_val = rdata[(ny-1)*nx + c]; 05013 float tmp; 05014 for ( int r = ny/2; r < ny; ++r ){ 05015 int idx =r*nx+c; 05016 tmp = rdata[idx]; 05017 rdata[idx] = last_val; 05018 last_val = tmp; 05019 } 05020 } 05021 } 05022 05023 if (xodd) { 05024 // Transfer the right most column into the center column 05025 // Shift all columns right of and including center to the right one pixel 05026 for ( int r = 0; r < ny; ++r ) { 05027 float last_val = rdata[(r+1)*nx -1]; 05028 float tmp; 05029 for ( int c = nx/2; c < nx; ++c ){ 05030 int idx =r*nx+c; 05031 tmp = rdata[idx]; 05032 rdata[idx] = last_val; 05033 last_val = tmp; 05034 } 05035 } 05036 } 05037 // It is important central slice shifting come after the previous two operations 05038 swap_central_slices_180(image); 05039 // Now the corners of the image can be shifted... 05040 swap_corners_180(image); 05041 05042 } 05043 else 05044 { 05045 float tmp; 05046 if (zodd) { 05047 // Tranfer the back slice into the middle slice, 05048 // shifting all pixels beyond and including the middle slice back one. 05049 size_t idx = 0; 05050 for (int r = 0; r < ny; ++r){ 05051 for (int c = 0; c < nx; ++c) { 05052 float last_val = rdata[(nz-1)*nxy+r*nx+c]; 05053 for (int s = nz/2; s < nz; ++s) { 05054 idx = (size_t)s*nxy+r*nx+c; 05055 tmp = rdata[idx]; 05056 rdata[idx] = last_val; 05057 last_val = tmp; 05058 } 05059 } 05060 } 05061 } 05062 if (yodd) { 05063 // Tranfer the top slice into the middle slice, 05064 // shifting all pixels above and including the middle slice up one. 05065 size_t idx = 0; 05066 for (int s = 0; s < nz; ++s) { 05067 for (int c = 0; c < nx; ++c) { 05068 float last_val = rdata[s*nxy+(ny-1)*nx+c]; 05069 for (int r = ny/2; r < ny; ++r){ 05070 idx = (size_t)s*nxy+r*nx+c; 05071 tmp = rdata[idx]; 05072 rdata[idx] = last_val; 05073 last_val = tmp; 05074 } 05075 } 05076 } 05077 } 05078 if (xodd) { 05079 // Transfer the right most slice into the central slice 05080 // Shift all pixels to right of and including center slice to the right one pixel 05081 size_t idx = 0; 05082 for (int s = 0; s < nz; ++s) { 05083 for (int r = 0; r < ny; ++r) { 05084 float last_val = rdata[s*nxy+r*nx+nx-1]; 05085 for (int c = nx/2; c < nx; ++c){ 05086 idx = (size_t)s*nxy+r*nx+c; 05087 tmp = rdata[idx]; 05088 rdata[idx] = last_val; 05089 last_val = tmp; 05090 } 05091 } 05092 } 05093 } 05094 // Now swap the various parts in the central slices 05095 swap_central_slices_180(image); 05096 // Now shift the corners 05097 swap_corners_180(image); 05098 } 05099 }
|
|
Definition at line 170 of file processor.cpp. |