#include <processor.h>
Inheritance diagram for EMAN::Rotate180Processor:
Public Member Functions | |
string | get_name () const |
Get the processor's name. | |
void | process_inplace (EMData *image) |
string | get_desc () const |
Get the descrition of this specific processor. | |
Static Public Member Functions | |
Processor * | NEW () |
Static Public Attributes | |
const string | NAME = "math.rotate.180" |
Definition at line 1257 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 1274 of file processor.h. 01275 { 01276 return "The 2D image is rotated by 180 degree by carefully swapping image pixel values. No explicit matrix multiplication is performed. If image dimensions are even will change pixels along x=0 and y=0. Works for all combinations of even and oddness."; 01277 }
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 1260 of file processor.h. 01261 {
01262 return NAME;
01263 }
|
|
Definition at line 1264 of file processor.h. 01265 { 01266 return new Rotate180Processor(); 01267 }
|
|
Implements EMAN::Processor. Definition at line 8588 of file processor.cpp. References emdata_rotate_180(), EMAN::EMData::get_data(), EMAN::EMData::get_ndim(), EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), ImageDimensionException, nx, ny, EMAN::EMData::set_value_at_fast(), t, EMAN::EMData::update(), x, and y. 08588 { 08589 ENTERFUNC; 08590 08591 08592 if (image->get_ndim() != 2) { 08593 throw ImageDimensionException("2D only"); 08594 } 08595 08596 #ifdef EMAN2_USING_CUDA 08597 if (image->gpu_operation_preferred() ) { 08598 EMDataForCuda tmp = image->get_data_struct_for_cuda(); 08599 emdata_rotate_180(&tmp); 08600 image->gpu_update(); 08601 EXITFUNC; 08602 return; 08603 } 08604 #endif 08605 08606 float *d = image->get_data(); 08607 int nx = image->get_xsize(); 08608 int ny = image->get_ysize(); 08609 08610 // x and y offsets are used to handle even vs odd cases 08611 int x_offset = 0; 08612 if (nx % 2 == 1) x_offset=1; 08613 int y_offset = 0; 08614 if (ny % 2 == 1) y_offset=1; 08615 08616 bool stop = false; 08617 for (int x = 1; x <= (nx/2+x_offset); x++) { 08618 int y = 0; 08619 for (y = 1; y < (ny+y_offset); y++) { 08620 if (x == (nx / 2+x_offset) && y == (ny / 2+y_offset)) { 08621 stop = true; 08622 break; 08623 } 08624 int i = (x-x_offset) + (y-y_offset) * nx; 08625 int k = nx - x + (ny - y) * nx; 08626 08627 float t = d[i]; 08628 d[i] = d[k]; 08629 d[k] = t; 08630 } 08631 if (stop) break; 08632 } 08633 08634 /* Here we guard against irregularites that occur at the boundaries 08635 * of even dimensioned images. The basic policy is to replace the pixel 08636 * in row 0 and/or column 0 with those in row 1 and/or column 1, respectively. 08637 * The pixel at 0,0 is replaced with the pixel at 1,1 if both image dimensions 08638 * are even. FIXME - it may be better to use an average at the corner, in 08639 * this latter case, using pixels (1,1), (0,1) and (1,0). I am not sure. (dsawoolford) 08640 */ 08641 if (x_offset == 0) { 08642 for (int y = 0; y < ny; y++) { 08643 image->set_value_at_fast(0,y,image->get_value_at(1,y)); 08644 } 08645 } 08646 08647 if (y_offset == 0) { 08648 for (int x = 0; x < nx; x++) { 08649 image->set_value_at_fast(x,0,image->get_value_at(x,1)); 08650 } 08651 } 08652 08653 if (y_offset == 0 && x_offset == 0) { 08654 image->set_value_at_fast(0,0,image->get_value_at(1,1)); 08655 } 08656 08657 image->update(); 08658 EXITFUNC; 08659 }
|
|
Definition at line 81 of file processor.cpp. |