#include <processor.h>
Inheritance diagram for EMAN::TestImageSquarecube:
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 string | get_desc () const |
Get the descrition of this specific processor. | |
virtual TypeDict | get_param_types () const |
Get processor parameter information in a dictionary. | |
Static Public Member Functions | |
static Processor * | NEW () |
Static Public Attributes | |
static const string | NAME = "testimage.squarecube" |
edge_length | edge length of the square or cube | |
axis | specify a major axis for asymmetric features | |
odd_edge | edge length for the asymmetric axis | |
fill | answer 'yes' or 'no' to specify if it's filled or hollow, default filled |
Definition at line 6363 of file processor.h.
virtual string EMAN::TestImageSquarecube::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 6373 of file processor.h.
06374 { 06375 return "Replace a source image as a square or cube depends on 2D or 3D of the source image"; 06376 }
virtual string EMAN::TestImageSquarecube::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 6368 of file processor.h.
References NAME.
06369 { 06370 return NAME; 06371 }
virtual TypeDict EMAN::TestImageSquarecube::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 6383 of file processor.h.
References EMAN::EMObject::FLOAT, EMAN::EMObject::INT, EMAN::TypeDict::put(), and EMAN::EMObject::STRING.
06384 { 06385 TypeDict d; 06386 d.put("edge_length", EMObject::FLOAT, "edge length of the square or cube, unit: pixel"); 06387 d.put("axis", EMObject::STRING, "specify a major axis for asymmetric features"); 06388 d.put("odd_edge", EMObject::FLOAT, "edge length for the asymmetric axis"); 06389 d.put("fill", EMObject::INT, "Flag indicating if image is filled, default filled, 1 for filled, 0 for blank"); 06390 return d; 06391 }
static Processor* EMAN::TestImageSquarecube::NEW | ( | ) | [inline, static] |
void TestImageSquarecube::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 7641 of file processor.cpp.
References EMAN::EMData::get_data(), EMAN::Dict::has_key(), InvalidValueException, EMAN::Processor::params, EMAN::TestImageProcessor::preprocess(), and EMAN::EMData::update().
07642 { 07643 preprocess(image); 07644 07645 float edge_length = params["edge_length"]; 07646 string axis = (const char*)params["axis"]; 07647 float odd_edge = params["odd_edge"]; 07648 int fill = 1; 07649 if(params.has_key("fill")) { 07650 fill = (int)params["fill"]; 07651 } 07652 07653 float *dat = image->get_data(); 07654 float x2, y2, z2; //this coordinates of this pixel from center 07655 float xEdge, yEdge, zEdge; //half of edge length for this cube 07656 if(axis == ""){ 07657 xEdge = edge_length/2.0f; 07658 yEdge = edge_length/2.0f; 07659 zEdge = edge_length/2.0f; 07660 } 07661 else if(axis == "x"){ 07662 xEdge = odd_edge/2.0f; 07663 yEdge = edge_length/2.0f; 07664 zEdge = edge_length/2.0f; 07665 } 07666 else if(axis == "y"){ 07667 xEdge = edge_length/2.0f; 07668 yEdge = odd_edge/2.0f; 07669 zEdge = edge_length/2.0f; 07670 } 07671 else if(axis == "z"){ 07672 if( nz == 1 ){ 07673 throw InvalidValueException(0, "This is a 2D image, no asymmetric feature for z axis"); 07674 } 07675 xEdge = edge_length/2.0f; 07676 yEdge = edge_length/2.0f; 07677 zEdge = odd_edge/2.0f; 07678 } 07679 else{ 07680 throw InvalidValueException(0, "please specify a valid axis for asymmetric features"); 07681 } 07682 for (int k = 0; k < nz; ++k) { 07683 for (int j = 0; j < ny; ++j) { 07684 for (int i = 0; i < nx; ++i, ++dat) { 07685 x2 = (float)fabs((float)i - nx/2); 07686 y2 = (float)fabs((float)j - ny/2); 07687 z2 = (float)fabs((float)k - nz/2); 07688 if( x2<=xEdge && y2<=yEdge && z2<=zEdge ) { 07689 if( !fill) { 07690 *dat = 0; 07691 } 07692 else { 07693 *dat = 1; 07694 } 07695 } 07696 else { 07697 if( !fill ) { 07698 *dat = 1; 07699 } 07700 else { 07701 *dat = 0; 07702 } 07703 } 07704 } 07705 } 07706 } 07707 07708 image->update(); 07709 }
const string TestImageSquarecube::NAME = "testimage.squarecube" [static] |