EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes
EMAN::Rotate180Processor Class Reference

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

#include <processor.h>

Inheritance diagram for EMAN::Rotate180Processor:
Inheritance graph
[legend]
Collaboration diagram for EMAN::Rotate180Processor:
Collaboration graph
[legend]

List of all members.

Public Member Functions

string get_name () const
 Get the processor's name.
void process_inplace (EMData *image)
 
Exceptions:
ImageDimensionExceptionif the image dimensions are not 2D

string get_desc () const
 Get the descrition of this specific processor.

Static Public Member Functions

static ProcessorNEW ()

Static Public Attributes

static 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 1613 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 1630 of file processor.h.

                        {
                                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.";
                        }
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 1616 of file processor.h.

References NAME.

                        {
                                return NAME;
                        }
static Processor* EMAN::Rotate180Processor::NEW ( ) [inline, static]

Definition at line 1620 of file processor.h.

                        {
                                return new Rotate180Processor();
                        }
void Rotate180Processor::process_inplace ( EMData image) [virtual]

Exceptions:
ImageDimensionExceptionif the image dimensions are not 2D

Implements EMAN::Processor.

Definition at line 9540 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, nx, ny, EMAN::EMData::set_value_at_fast(), t, EMAN::EMData::update(), x, and y.

                                                      {
        ENTERFUNC;


        if (image->get_ndim() != 2) {
                throw ImageDimensionException("2D only");
        }

#ifdef EMAN2_USING_CUDA
        if (EMData::usecuda == 1 && image->getcudarwdata()) {
                //cout << "CUDA rotate 180" << endl;
                emdata_rotate_180(image->getcudarwdata(), image->get_xsize(), image->get_ysize());
                EXITFUNC;
                return;
        }
#endif

        float *d = image->get_data();
        int nx = image->get_xsize();
        int ny = image->get_ysize();

        // x and y offsets are used to handle even vs odd cases
        int x_offset = 0;
        if (nx % 2 == 1) x_offset=1;
        int y_offset = 0;
        if (ny % 2 == 1) y_offset=1;

        bool stop = false;
        for (int x = 1; x <= (nx/2+x_offset); x++) {
                int y = 0;
                for (y = 1; y < (ny+y_offset); y++) {
                        if (x == (nx / 2+x_offset) && y == (ny / 2+y_offset)) {
                                stop = true;
                                break;
                        }
                        int i = (x-x_offset) + (y-y_offset) * nx;
                        int k = nx - x + (ny - y) * nx;

                        float t = d[i];
                        d[i] = d[k];
                        d[k] = t;
                }
                if (stop) break;
        }

        /* Here we guard against irregularites that occur at the boundaries
         * of even dimensioned images. The basic policy is to replace the pixel
         * in row 0 and/or column 0 with those in row 1 and/or column 1, respectively.
         * The pixel at 0,0 is replaced with the pixel at 1,1 if both image dimensions
         * are even. FIXME - it may be better to use an average at the corner, in
         * this latter case, using pixels (1,1), (0,1) and (1,0). I am not sure. (dsawoolford)
        */
        if (x_offset == 0) {
                for (int y = 0; y < ny; y++) {
                        image->set_value_at_fast(0,y,image->get_value_at(1,y));
                }
        }

        if (y_offset == 0) {
                for (int x = 0; x < nx; x++) {
                        image->set_value_at_fast(x,0,image->get_value_at(x,1));
                }
        }

        if (y_offset == 0 && x_offset == 0) {
                image->set_value_at_fast(0,0,image->get_value_at(1,1));
        }

        image->update();
        EXITFUNC;
}

Member Data Documentation

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

Definition at line 1635 of file processor.h.

Referenced by get_name().


The documentation for this class was generated from the following files: