#include <processor.h>
Inheritance diagram for EMAN::FourierToCornerProcessor:
Public Member Functions | |
virtual void | process_inplace (EMData *image) |
Fourier origin shift the image in the backwards direction Should only be called after the application of FourierToCenterProcessor. | |
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 | |
static Processor * | NEW () |
Static Public Attributes | |
static const string | NAME = "xform.fourierorigin.tocorner" |
Definition at line 4755 of file processor.h.
virtual string EMAN::FourierToCornerProcessor::get_desc | ( | ) | const [inline, virtual] |
Get the descrition of this specific processor.
This function must be overwritten by a subclass.
Implements EMAN::Processor.
Definition at line 4775 of file processor.h.
virtual string EMAN::FourierToCornerProcessor::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 4765 of file processor.h.
References NAME.
04766 { 04767 return NAME; 04768 }
static Processor* EMAN::FourierToCornerProcessor::NEW | ( | ) | [inline, static] |
Definition at line 4770 of file processor.h.
04771 { 04772 return new FourierToCornerProcessor(); 04773 }
void FourierToCornerProcessor::process_inplace | ( | EMData * | image | ) | [virtual] |
Fourier origin shift the image in the backwards direction Should only be called after the application of FourierToCenterProcessor.
image | the image to operate on |
ImageFormatException | if the image is not complex |
Implements EMAN::Processor.
Definition at line 4523 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(), rdata, and EMAN::EMData::set_shuffled().
04524 { 04525 if ( !image->is_complex() ) throw ImageFormatException("Can not Fourier origin shift an image that is not complex"); 04526 04527 int nx=image->get_xsize(); 04528 int ny=image->get_ysize(); 04529 int nz=image->get_zsize(); 04530 04531 int nxy = nx*ny; 04532 04533 if ( ny == 1 && nz == 1 ){ 04534 cout << "Warning- attempted Fourier origin shift a 1D image - no action taken" << endl; 04535 return; 04536 } 04537 int yodd = (ny%2==1); 04538 int zodd = (nz%2==1); 04539 04540 float* rdata = image->get_data(); 04541 04542 float tmp[2]; 04543 float* p1; 04544 float* p2; 04545 04546 if (yodd){ 04547 // Swap the middle slice (with respect to the y direction) with the bottom slice 04548 // shifting all slices above the middles slice upwards by one pixel, stopping 04549 // at the middle slice, not if nz = 1 we are not talking about slices, we are 04550 // talking about rows 04551 float prev[2]; 04552 size_t idx; 04553 for( int s = 0; s < nz; s++ ) { 04554 for( int c =0; c < nx; c += 2 ) { 04555 idx = (size_t)s*nxy+ny/2*nx+c; 04556 prev[0] = rdata[idx]; 04557 prev[1] = rdata[idx+1]; 04558 for( int r = 0; r <= ny/2; ++r ) { 04559 idx = (size_t)s*nxy+r*nx+c; 04560 float* p1 = &rdata[idx]; 04561 tmp[0] = p1[0]; 04562 tmp[1] = p1[1]; 04563 04564 p1[0] = prev[0]; 04565 p1[1] = prev[1]; 04566 04567 prev[0] = tmp[0]; 04568 prev[1] = tmp[1]; 04569 } 04570 } 04571 } 04572 } 04573 04574 // Shift slices (3D) or rows (2D) correctly in the y direction 04575 size_t idx1, idx2; 04576 for( int s = 0; s < nz; ++s ) { 04577 for( int r = 0 + yodd; r < ny/2+yodd; ++r ) { 04578 for( int c =0; c < nx; c += 2 ) { 04579 idx1 = (size_t)s*nxy+r*nx+c; 04580 idx2 = (size_t)s*nxy+(r+ny/2)*nx+c; 04581 p1 = &rdata[idx1]; 04582 p2 = &rdata[idx2]; 04583 04584 tmp[0] = p1[0]; 04585 tmp[1] = p1[1]; 04586 04587 p1[0] = p2[0]; 04588 p1[1] = p2[1]; 04589 04590 p2[0] = tmp[0]; 04591 p2[1] = tmp[1]; 04592 } 04593 } 04594 } 04595 04596 if ( nz != 1 ) 04597 { 04598 04599 if (zodd){ 04600 // Swap the middle slice (with respect to the z direction) and the front slice 04601 // shifting all behind the front slice towards the middle a distance of 1 voxel, 04602 // stopping at the middle slice. 04603 float prev[2]; 04604 size_t idx; 04605 for( int r = 0; r < ny; ++r ) { 04606 for( int c =0; c < nx; c += 2 ) { 04607 idx = (size_t)nz/2*nxy+r*nx+c; 04608 prev[0] = rdata[idx]; 04609 prev[1] = rdata[idx+1]; 04610 for( int s = 0; s <= nz/2; ++s ) { 04611 idx = (size_t)s*nxy+r*nx+c; 04612 float* p1 = &rdata[idx]; 04613 tmp[0] = p1[0]; 04614 tmp[1] = p1[1]; 04615 04616 p1[0] = prev[0]; 04617 p1[1] = prev[1]; 04618 04619 prev[0] = tmp[0]; 04620 prev[1] = tmp[1]; 04621 } 04622 } 04623 } 04624 } 04625 04626 // Shift slices correctly in the z direction 04627 size_t idx1, idx2; 04628 for( int s = 0+zodd; s < nz/2 + zodd; ++s ) { 04629 for( int r = 0; r < ny; ++r ) { 04630 for( int c =0; c < nx; c += 2 ) { 04631 idx1 = (size_t)s*nxy+r*nx+c; 04632 idx2 = (size_t)(s+nz/2)*nxy+r*nx+c; 04633 p1 = &rdata[idx1]; 04634 p2 = &rdata[idx2]; 04635 04636 tmp[0] = p1[0]; 04637 tmp[1] = p1[1]; 04638 04639 p1[0] = p2[0]; 04640 p1[1] = p2[1]; 04641 04642 p2[0] = tmp[0]; 04643 p2[1] = tmp[1]; 04644 } 04645 } 04646 } 04647 } 04648 image->set_shuffled(false); 04649 }
const string FourierToCornerProcessor::NAME = "xform.fourierorigin.tocorner" [static] |