#include <processor.h>
Inheritance diagram for EMAN::FlipProcessor:
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 | |
static Processor * | NEW () |
Static Public Attributes | |
static const string | NAME = "xform.flip" |
axis | 'x', 'y', or 'z' axis. 'x' means horizonal flip; 'y' means vertical flip; |
Definition at line 4409 of file processor.h.
virtual string EMAN::FlipProcessor::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 4431 of file processor.h.
virtual string EMAN::FlipProcessor::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 4414 of file processor.h.
References NAME.
04415 { 04416 return NAME; 04417 }
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.
Reimplemented from EMAN::Processor.
Definition at line 4424 of file processor.h.
References EMAN::TypeDict::put(), and EMAN::EMObject::STRING.
04425 { 04426 TypeDict d; 04427 d.put("axis", EMObject::STRING, "'x', 'y', or 'z' axis. 'x' means horizonal flip; 'y' means vertical flip;"); 04428 return d; 04429 }
static Processor* EMAN::FlipProcessor::NEW | ( | ) | [inline, static] |
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.
image | The image to be processed. |
Implements EMAN::Processor.
Definition at line 4274 of file processor.cpp.
References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), LOGWARN, EMAN::Processor::params, EMAN::EMData::process_inplace(), t, EMAN::EMData::update(), and x.
04275 { 04276 ENTERFUNC; 04277 if (!image) { 04278 LOGWARN("NULL Image"); 04279 return; 04280 } 04281 string axis = (const char*)params["axis"]; 04282 04283 #ifdef EMAN2_USING_CUDA 04284 if (image->cudarwdata) { 04285 //cout << "flip processor" << endl; 04286 float array[12] = {1.0, 0.0, 0.0, 0.0, 04287 0.0, 1.0, 0.0, 0.0, 04288 0.0, 0.0, 1.0, 0.0}; 04289 if (axis == "x" || axis == "X") { // horizontal flip 04290 array[0] = -1.0; 04291 }else if (axis == "y" || axis == "Y") { // vertical flip 04292 array[5] = -1.0; 04293 } 04294 else if (axis == "z" || axis == "Z") { // vertical flip 04295 array[10] = -1.0; 04296 } 04297 Transform t(array); 04298 Dict params("transform",(Transform*)&t); 04299 image->process_inplace("xform",params); 04300 04301 EXITFUNC; 04302 return; 04303 } 04304 #endif 04305 04306 04307 float *d = image->get_data(); 04308 int nx = image->get_xsize(); 04309 int ny = image->get_ysize(); 04310 int nz = image->get_zsize(); 04311 04312 size_t nxy = nx * ny; 04313 04314 04315 // Note in all cases the origin is nx/2, ny/2 and nz/2 04316 // This means when flipping even sized dimensions that some pixels are redundant. 04317 // Here redundant pixels are set to zero, however, should this change to something 04318 // like the mean. 04319 if (axis == "x" || axis == "X") { // Horizontal flip 04320 int offset = (nx%2 == 0); 04321 size_t idx1, idx2; 04322 for(int z = 0; z < nz; ++z) { 04323 for(int y = 0; y < ny; ++y) { 04324 if (offset != 0 ) { 04325 idx1 = z*nxy + y*nx; 04326 d[idx1] = 0; // Here's where you'd make it the mean 04327 } 04328 for(int x = offset; x < nx / 2; ++x) { 04329 idx1 = z*nxy + y*nx + x; 04330 idx2 = z*nxy + y*nx + (nx-x-1+offset); 04331 std::swap(d[idx1], d[idx2]); 04332 } 04333 04334 } 04335 } 04336 } 04337 04338 else if (axis == "y" || axis == "Y") { // vertical flip 04339 int offset = (ny%2 == 0); 04340 for(int z=0; z<nz; ++z) { 04341 if (offset != 0) { 04342 std::fill(d+z*nxy,d+(size_t)z*nxy+nx,0); // So if we have change it to the mean it's easy to do so. (instead of using memset) 04343 } 04344 for(int y=offset; y<ny/2; ++y) { 04345 for(int x=0; x<nx; ++x) { 04346 std::swap(d[(size_t)z*nxy + y*nx +x], d[(size_t)z*nxy + (ny -y -1+offset)*nx +x]); 04347 } 04348 } 04349 } 04350 } 04351 else if (axis == "z" || axis == "Z") { //z axis flip 04352 int offset = (nz%2 == 0); 04353 if (offset != 0) { 04354 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) 04355 } 04356 size_t idx1, idx2; 04357 for(int z=offset; z<nz/2; ++z) { 04358 for(int y=0; y<ny; ++y) { 04359 for(int x=0; x<nx; ++x) { 04360 idx1 = (size_t)z*nxy + y*nx + x; 04361 idx2 = (size_t)(nz-z-1+offset)*nxy + y*nx + x; 04362 std::swap(d[idx1], d[idx2]); 04363 } 04364 } 04365 } 04366 } 04367 04368 image->update(); 04369 EXITFUNC; 04370 }
const string FlipProcessor::NAME = "xform.flip" [static] |