#include <processor.h>


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 | ||||
| static Processor * | NEW () | |||
Static Public Attributes | ||||
| static const string | NAME = "math.rotate.180" | |||
Definition at line 1407 of file processor.h.
| string EMAN::Rotate180Processor::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 1410 of file processor.h.
References NAME.
01411 { 01412 return NAME; 01413 }
| static Processor* EMAN::Rotate180Processor::NEW | ( | ) | [inline, static] |
| void Rotate180Processor::process_inplace | ( | EMData * | image | ) | [virtual] |
| ImageDimensionException | if the image dimensions are not 2D |
Implements EMAN::Processor.
Definition at line 8531 of file processor.cpp.
References emdata_rotate_180(), ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_ndim(), EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), ImageDimensionException, EMAN::EMData::set_value_at_fast(), t, EMAN::EMData::update(), and x.
08531 { 08532 ENTERFUNC; 08533 08534 08535 if (image->get_ndim() != 2) { 08536 throw ImageDimensionException("2D only"); 08537 } 08538 08539 #ifdef EMAN2_USING_CUDA 08540 if (image->gpu_operation_preferred() ) { 08541 EMDataForCuda tmp = image->get_data_struct_for_cuda(); 08542 emdata_rotate_180(&tmp); 08543 image->gpu_update(); 08544 EXITFUNC; 08545 return; 08546 } 08547 #endif 08548 08549 float *d = image->get_data(); 08550 int nx = image->get_xsize(); 08551 int ny = image->get_ysize(); 08552 08553 // x and y offsets are used to handle even vs odd cases 08554 int x_offset = 0; 08555 if (nx % 2 == 1) x_offset=1; 08556 int y_offset = 0; 08557 if (ny % 2 == 1) y_offset=1; 08558 08559 bool stop = false; 08560 for (int x = 1; x <= (nx/2+x_offset); x++) { 08561 int y = 0; 08562 for (y = 1; y < (ny+y_offset); y++) { 08563 if (x == (nx / 2+x_offset) && y == (ny / 2+y_offset)) { 08564 stop = true; 08565 break; 08566 } 08567 int i = (x-x_offset) + (y-y_offset) * nx; 08568 int k = nx - x + (ny - y) * nx; 08569 08570 float t = d[i]; 08571 d[i] = d[k]; 08572 d[k] = t; 08573 } 08574 if (stop) break; 08575 } 08576 08577 /* Here we guard against irregularites that occur at the boundaries 08578 * of even dimensioned images. The basic policy is to replace the pixel 08579 * in row 0 and/or column 0 with those in row 1 and/or column 1, respectively. 08580 * The pixel at 0,0 is replaced with the pixel at 1,1 if both image dimensions 08581 * are even. FIXME - it may be better to use an average at the corner, in 08582 * this latter case, using pixels (1,1), (0,1) and (1,0). I am not sure. (dsawoolford) 08583 */ 08584 if (x_offset == 0) { 08585 for (int y = 0; y < ny; y++) { 08586 image->set_value_at_fast(0,y,image->get_value_at(1,y)); 08587 } 08588 } 08589 08590 if (y_offset == 0) { 08591 for (int x = 0; x < nx; x++) { 08592 image->set_value_at_fast(x,0,image->get_value_at(x,1)); 08593 } 08594 } 08595 08596 if (y_offset == 0 && x_offset == 0) { 08597 image->set_value_at_fast(0,0,image->get_value_at(1,1)); 08598 } 08599 08600 image->update(); 08601 EXITFUNC; 08602 }
| string EMAN::Rotate180Processor::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 1424 of file processor.h.
01425 { 01426 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."; 01427 }
const string Rotate180Processor::NAME = "math.rotate.180" [static] |
1.5.6