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

EMAN::FlipProcessor Class Reference

flip an image around an axis More...

#include <processor.h>

Inheritance diagram for EMAN::FlipProcessor:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

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

Static Public Member Functions

ProcessorNEW ()

Static Public Attributes

const string NAME = "xform.flip"

Detailed Description

flip an image around an axis

Parameters:
axis 'x', 'y', or 'z' axis. 'x' means horizonal flip; 'y' means vertical flip;

Definition at line 4324 of file processor.h.


Member Function Documentation

virtual string EMAN::FlipProcessor::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 4346 of file processor.h.

04347                 {
04348                         return "flip an image around an axis.";
04349                 }

virtual string EMAN::FlipProcessor::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 4329 of file processor.h.

04330                 {
04331                         return NAME;
04332                 }

virtual TypeDict EMAN::FlipProcessor::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 4339 of file processor.h.

References EMAN::TypeDict::put().

04340                 {
04341                         TypeDict d;
04342                         d.put("axis", EMObject::STRING, "'x', 'y', or 'z' axis. 'x' means horizonal flip; 'y' means vertical flip;");
04343                         return d;
04344                 }

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

Definition at line 4334 of file processor.h.

04335                 {
04336                         return new FlipProcessor();
04337                 }

void FlipProcessor::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:
image The image to be processed.

Implements EMAN::Processor.

Definition at line 4214 of file processor.cpp.

References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), LOGWARN, nx, ny, EMAN::Processor::params, EMAN::EMData::process_inplace(), t, EMAN::EMData::update(), x, and y.

04215 {
04216         ENTERFUNC;
04217         if (!image) {
04218                 LOGWARN("NULL Image");
04219                 return;
04220         }
04221         string axis = (const char*)params["axis"];
04222 #ifdef EMAN2_USING_CUDA
04223         if (image->gpu_operation_preferred()) {
04224                 float array[12] = {1.0, 0.0, 0.0, 0.0,
04225                                                    0.0, 1.0, 0.0, 0.0,
04226                                                    0.0, 0.0, 1.0, 0.0};
04227                 if (axis == "x" || axis == "X") {               // horizontal flip
04228                         array[0] = -1.0;
04229                 }else if (axis == "y" || axis == "Y") {         // vertical flip
04230                         array[5] = -1.0;
04231                 }
04232                 else if (axis == "z" || axis == "Z") {          // vertical flip
04233                         array[10] = -1.0;
04234                 }
04235                 Transform t(array);
04236                 Dict params("transform",(Transform*)&t);
04237                 image->process_inplace("xform",params);
04238                 EXITFUNC;
04239                 return;
04240         }
04241 #endif
04242 
04243 
04244         float *d = image->get_data();
04245         int nx = image->get_xsize();
04246         int ny = image->get_ysize();
04247         int nz = image->get_zsize();
04248 
04249         size_t nxy = nx * ny;
04250 
04251 
04252         // Note in all cases the origin is nx/2, ny/2 and nz/2
04253         // This means when flipping even sized dimensions that some pixels are redundant.
04254         // Here redundant pixels are set to zero, however, should this change to something
04255         // like the mean.
04256         if (axis == "x" || axis == "X") {               // Horizontal flip
04257                 int offset = (nx%2 == 0);
04258                 size_t idx1, idx2;
04259                 for(int z = 0; z < nz; ++z) {
04260                         for(int y = 0; y < ny; ++y) {
04261                                 if (offset != 0 ) {
04262                                         idx1 = z*nxy + y*nx;
04263                                         d[idx1] = 0; // Here's where you'd make it the mean
04264                                 }
04265                                 for(int x = offset; x < nx / 2; ++x) {
04266                                         idx1 = z*nxy + y*nx + x;
04267                                         idx2 = z*nxy + y*nx + (nx-x-1+offset);
04268                                         std::swap(d[idx1], d[idx2]);
04269                                 }
04270 
04271                         }
04272                 }
04273         }
04274 
04275         else if (axis == "y" || axis == "Y") {          // vertical flip
04276                 int offset = (ny%2 == 0);
04277                 for(int z=0; z<nz; ++z) {
04278                         if (offset != 0) {
04279                                 std::fill(d+z*nxy,d+z*nxy+nx,0); // So if we have change it to the mean it's easy to do so. (instead of using memset)
04280                         }
04281                         for(int y=offset; y<ny/2; ++y) {
04282                                 for(int x=0; x<nx; ++x) {
04283                                         std::swap(d[z*nxy + y*nx +x], d[z*nxy + (ny -y -1+offset)*nx +x]);
04284                                 }
04285                         }
04286                 }
04287         }
04288         else if (axis == "z" || axis == "Z") {          //z axis flip
04289                 int offset = (nz%2 == 0);
04290                 if (offset != 0) {
04291                         std::fill(d,d+nxy,0);// So if we have change it to the mean it's easy to do so. (instead of using memset)
04292                 }
04293                 size_t idx1, idx2;
04294                 for(int z=offset; z<nz/2; ++z) {
04295                         for(int y=0; y<ny; ++y) {
04296                                 for(int x=0; x<nx; ++x) {
04297                                         idx1 = z*nxy + y*nx + x;
04298                                         idx2 = (nz-z-1+offset)*nxy + y*nx + x;
04299                                         std::swap(d[idx1], d[idx2]);
04300                                 }
04301                         }
04302                 }
04303         }
04304 
04305         image->update();
04306         EXITFUNC;
04307 }


Member Data Documentation

const string FlipProcessor::NAME = "xform.flip" [static]
 

Definition at line 152 of file processor.cpp.


The documentation for this class was generated from the following files:
Generated on Thu Dec 9 13:48:08 2010 for EMAN2 by  doxygen 1.3.9.1