#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 1381 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 1398 of file processor.h. 01399 {
01400 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.";
01401 }
|
|
|
Get the processor's name. Each processor is identified by a unique name.
Implements EMAN::Processor. Definition at line 1384 of file processor.h. 01385 {
01386 return NAME;
01387 }
|
|
|
Definition at line 1388 of file processor.h. 01389 {
01390 return new Rotate180Processor();
01391 }
|
|
|
Implements EMAN::Processor. Definition at line 8668 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. 08668 {
08669 ENTERFUNC;
08670
08671
08672 if (image->get_ndim() != 2) {
08673 throw ImageDimensionException("2D only");
08674 }
08675
08676 #ifdef EMAN2_USING_CUDA
08677 if (EMData::usecuda == 1 && image->getcudarwdata()) {
08678 //cout << "CUDA rotate 180" << endl;
08679 emdata_rotate_180(image->getcudarwdata(), image->get_xsize(), image->get_ysize());
08680 EXITFUNC;
08681 return;
08682 }
08683 #endif
08684
08685 float *d = image->get_data();
08686 int nx = image->get_xsize();
08687 int ny = image->get_ysize();
08688
08689 // x and y offsets are used to handle even vs odd cases
08690 int x_offset = 0;
08691 if (nx % 2 == 1) x_offset=1;
08692 int y_offset = 0;
08693 if (ny % 2 == 1) y_offset=1;
08694
08695 bool stop = false;
08696 for (int x = 1; x <= (nx/2+x_offset); x++) {
08697 int y = 0;
08698 for (y = 1; y < (ny+y_offset); y++) {
08699 if (x == (nx / 2+x_offset) && y == (ny / 2+y_offset)) {
08700 stop = true;
08701 break;
08702 }
08703 int i = (x-x_offset) + (y-y_offset) * nx;
08704 int k = nx - x + (ny - y) * nx;
08705
08706 float t = d[i];
08707 d[i] = d[k];
08708 d[k] = t;
08709 }
08710 if (stop) break;
08711 }
08712
08713 /* Here we guard against irregularites that occur at the boundaries
08714 * of even dimensioned images. The basic policy is to replace the pixel
08715 * in row 0 and/or column 0 with those in row 1 and/or column 1, respectively.
08716 * The pixel at 0,0 is replaced with the pixel at 1,1 if both image dimensions
08717 * are even. FIXME - it may be better to use an average at the corner, in
08718 * this latter case, using pixels (1,1), (0,1) and (1,0). I am not sure. (dsawoolford)
08719 */
08720 if (x_offset == 0) {
08721 for (int y = 0; y < ny; y++) {
08722 image->set_value_at_fast(0,y,image->get_value_at(1,y));
08723 }
08724 }
08725
08726 if (y_offset == 0) {
08727 for (int x = 0; x < nx; x++) {
08728 image->set_value_at_fast(x,0,image->get_value_at(x,1));
08729 }
08730 }
08731
08732 if (y_offset == 0 && x_offset == 0) {
08733 image->set_value_at_fast(0,0,image->get_value_at(1,1));
08734 }
08735
08736 image->update();
08737 EXITFUNC;
08738 }
|
|
|
Definition at line 90 of file processor.cpp. |
1.3.9.1