Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::Rotate180Processor Class Reference
[a function or class that is CUDA enabled]

Rotate by 180 using pixel swapping, works for 2D only. More...

#include <processor.h>

Inheritance diagram for EMAN::Rotate180Processor:

[legend]
Collaboration diagram for EMAN::Rotate180Processor:
[legend]
List of all members.

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

ProcessorNEW ()

Static Public Attributes

const string NAME = "math.rotate.180"

Detailed Description

Rotate by 180 using pixel swapping, works for 2D only.

Author:
David Woolford
Date:
July 29th 2008

Definition at line 1467 of file processor.h.


Member Function Documentation

string EMAN::Rotate180Processor::get_desc  )  const [inline, virtual]
 

Get the descrition of this specific processor.

This function must be overwritten by a subclass.

Returns:
The description of this processor.

Implements EMAN::Processor.

Definition at line 1484 of file processor.h.

01485                         {
01486                                 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.";
01487                         }

string EMAN::Rotate180Processor::get_name  )  const [inline, virtual]
 

Get the processor's name.

Each processor is identified by a unique name.

Returns:
The processor's name.

Implements EMAN::Processor.

Definition at line 1470 of file processor.h.

01471                         {
01472                                 return NAME;
01473                         }

Processor* EMAN::Rotate180Processor::NEW  )  [inline, static]
 

Definition at line 1474 of file processor.h.

01475                         {
01476                                 return new Rotate180Processor();
01477                         }

void Rotate180Processor::process_inplace EMData image  )  [virtual]
 

Exceptions:
ImageDimensionException if the image dimensions are not 2D

Implements EMAN::Processor.

Definition at line 8542 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.

08542                                                       {
08543         ENTERFUNC;
08544 
08545 
08546         if (image->get_ndim() != 2) {
08547                 throw ImageDimensionException("2D only");
08548         }
08549 
08550 #ifdef EMAN2_USING_CUDA
08551         if (image->gpu_operation_preferred() ) {
08552                 EMDataForCuda tmp = image->get_data_struct_for_cuda();
08553                 emdata_rotate_180(&tmp);
08554                 image->gpu_update();
08555                 EXITFUNC;
08556                 return;
08557         }
08558 #endif
08559 
08560         float *d = image->get_data();
08561         int nx = image->get_xsize();
08562         int ny = image->get_ysize();
08563 
08564         // x and y offsets are used to handle even vs odd cases
08565         int x_offset = 0;
08566         if (nx % 2 == 1) x_offset=1;
08567         int y_offset = 0;
08568         if (ny % 2 == 1) y_offset=1;
08569 
08570         bool stop = false;
08571         for (int x = 1; x <= (nx/2+x_offset); x++) {
08572                 int y = 0;
08573                 for (y = 1; y < (ny+y_offset); y++) {
08574                         if (x == (nx / 2+x_offset) && y == (ny / 2+y_offset)) {
08575                                 stop = true;
08576                                 break;
08577                         }
08578                         int i = (x-x_offset) + (y-y_offset) * nx;
08579                         int k = nx - x + (ny - y) * nx;
08580 
08581                         float t = d[i];
08582                         d[i] = d[k];
08583                         d[k] = t;
08584                 }
08585                 if (stop) break;
08586         }
08587 
08588         /* Here we guard against irregularites that occur at the boundaries
08589          * of even dimensioned images. The basic policy is to replace the pixel
08590          * in row 0 and/or column 0 with those in row 1 and/or column 1, respectively.
08591          * The pixel at 0,0 is replaced with the pixel at 1,1 if both image dimensions
08592          * are even. FIXME - it may be better to use an average at the corner, in
08593          * this latter case, using pixels (1,1), (0,1) and (1,0). I am not sure. (dsawoolford)
08594         */
08595         if (x_offset == 0) {
08596                 for (int y = 0; y < ny; y++) {
08597                         image->set_value_at_fast(0,y,image->get_value_at(1,y));
08598                 }
08599         }
08600 
08601         if (y_offset == 0) {
08602                 for (int x = 0; x < nx; x++) {
08603                         image->set_value_at_fast(x,0,image->get_value_at(x,1));
08604                 }
08605         }
08606 
08607         if (y_offset == 0 && x_offset == 0) {
08608                 image->set_value_at_fast(0,0,image->get_value_at(1,1));
08609         }
08610 
08611         image->update();
08612         EXITFUNC;
08613 }


Member Data Documentation

const string Rotate180Processor::NAME = "math.rotate.180" [static]
 

Definition at line 87 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Fri Apr 30 15:39:20 2010 for EMAN2 by  doxygen 1.3.9.1