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

mirror an image More...

#include <processor_sparx.h>

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

List of all members.

Public Member Functions

void process_inplace (EMData *image)
 To process an image in-place.
string get_name () const
 Get the processor's name.
TypeDict get_param_types () const
 Get processor parameter information in a dictionary.
string get_desc () const
 Get the descrition of this specific processor.

Static Public Member Functions

static ProcessorNEW ()

Static Public Attributes

static const string NAME = "xform.mirror"

Detailed Description

mirror an image

Parameters:
axis''x', 'y', or 'z' axis, means mirror by changing the sign of the respective axis;

Definition at line 48 of file processor_sparx.h.


Member Function Documentation

string EMAN::MirrorProcessor::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 71 of file processor_sparx.h.

                {
                        return "Mirrors an image along the specified axis. This will shift the image center for even box sizes. Use the 'xform.flip' processor to preserve center.";
                }
string EMAN::MirrorProcessor::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 54 of file processor_sparx.h.

References NAME.

                {
                        return NAME;
                }
TypeDict EMAN::MirrorProcessor::get_param_types ( ) const [inline, virtual]

Get processor parameter information in a dictionary.

Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.

Returns:
A dictionary containing the parameter info.

Reimplemented from EMAN::Processor.

Definition at line 64 of file processor_sparx.h.

References EMAN::TypeDict::put(), and EMAN::EMObject::STRING.

                {
                        TypeDict d;
                        d.put("axis", EMObject::STRING, "'x', 'y', or 'z' axis");
                        return d;
                }
static Processor* EMAN::MirrorProcessor::NEW ( ) [inline, static]

Definition at line 59 of file processor_sparx.h.

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

To process an image in-place.

For those processors which can only be processed out-of-place, override this function to just print out some error message to remind user call the out-of-place version.

Parameters:
imageThe image to be processed.

Implements EMAN::Processor.

Definition at line 8851 of file processor.cpp.

References EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), LOGWARN, nx, ny, EMAN::Processor::params, and EMAN::EMData::update().

{
        if (!image) {
                LOGWARN("NULL Image");
                return;
        }

        string axis = (const char*)params["axis"];

        float* data = image->EMData::get_data();

        int nx = image->get_xsize();
        int ny = image->get_ysize();
        int nz = image->get_zsize();
        size_t nxy = nx*ny;

        int x_start = 1-nx%2;
        int y_start = 1-ny%2;
        int z_start = 1-nz%2;

        if (axis == "x" || axis == "X") {
                for (int iz = 0; iz < nz; iz++)
                        for (int iy = 0; iy < ny; iy++) {
                                int offset = nx*iy + nxy*iz;
                                reverse(&data[offset+x_start],&data[offset+nx]);
                        }
        } else if (axis == "y" || axis == "Y") {
                float *tmp = new float[nx];
                int nhalf   = ny/2;
                size_t beg     = 0;
                for (int iz = 0; iz < nz; iz++) {
                        beg = iz*nxy;
                        for (int iy = y_start; iy < nhalf; iy++) {
                                memcpy(tmp, &data[beg+iy*nx], nx*sizeof(float));
                                memcpy(&data[beg+iy*nx], &data[beg+(ny-iy-1+y_start)*nx], nx*sizeof(float));
                                memcpy(&data[beg+(ny-iy-1+y_start)*nx], tmp, nx*sizeof(float));
                        }
                }
                delete[] tmp;
        } else if (axis == "z" || axis == "Z") {
                if(1-z_start) {
                        int nhalf = nz/2;
                        float *tmp = new float[nxy];
                        for(int iz = 0;iz<nhalf;iz++){
                                memcpy(tmp,&data[iz*nxy],nxy*sizeof(float));
                                memcpy(&data[iz*nxy],&data[(nz-iz-1)*nxy],nxy*sizeof(float));
                                memcpy(&data[(nz-iz-1)*nxy],tmp,nxy*sizeof(float));
                        }
                        delete[] tmp;
                } else {
                        float *tmp = new float[nx];
                        int nhalf   = nz/2;
                        size_t beg     = 0;
                        for (int iy = 0; iy < ny; iy++) {
                                beg = iy*nx;
                                for (int iz = z_start; iz < nhalf; iz++) {
                                        memcpy(tmp, &data[beg+ iz*nxy], nx*sizeof(float));
                                        memcpy(&data[beg+iz*nxy], &data[beg+(nz-iz-1+z_start)*nxy], nx*sizeof(float));
                                        memcpy(&data[beg+(nz-iz-1+z_start)*nxy], tmp, nx*sizeof(float));
                                }
                        }
                        delete[] tmp;
                }
        }

        image->update();
}

Member Data Documentation

const string MirrorProcessor::NAME = "xform.mirror" [static]

Definition at line 76 of file processor_sparx.h.

Referenced by get_name().


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