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

Replace a source image with a cylinder. More...

#include <processor.h>

Inheritance diagram for EMAN::TestImageCylinder:
Inheritance graph
[legend]
Collaboration diagram for EMAN::TestImageCylinder:
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 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 ProcessorNEW ()

Static Public Attributes

static const string NAME = "testimage.cylinder"

Detailed Description

Replace a source image with a cylinder.

Parameters:
radiusradius for the cylinder
heightheight for the cylinder, by default it's the nz

Definition at line 7017 of file processor.h.


Member Function Documentation

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

                {
                        return "Replace a source image as a cylinder";
                }
virtual string EMAN::TestImageCylinder::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 7022 of file processor.h.

References NAME.

                {
                        return NAME;
                }
virtual TypeDict EMAN::TestImageCylinder::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 7037 of file processor.h.

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

                {
                        TypeDict d;
                        d.put("radius", EMObject::FLOAT, "radius for the cylinder");
                        d.put("height", EMObject::FLOAT, "height for the cylinder, by default it's the nz");

                        return d;
                }
static Processor* EMAN::TestImageCylinder::NEW ( ) [inline, static]

Definition at line 7032 of file processor.h.

                {
                        return new TestImageCylinder();
                }
void TestImageCylinder::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 8479 of file processor.cpp.

References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), ImageDimensionException, InvalidValueException, min, nx, ny, EMAN::Processor::params, and EMAN::EMData::update().

{
        preprocess(image);

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

        if(nz == 1) {
                throw ImageDimensionException("This processor only apply to 3D image");
        }

        float radius = params["radius"];
#ifdef _WIN32
        if(radius > _cpp_min(nx, ny)/2.0) {
#else
        if(radius > std::min(nx, ny)/2.0) {
#endif
                throw InvalidValueException(radius, "radius must be <= min(nx, ny)/2");
        }

        float height;
        if(params.has_key("height")) {
                height = params["height"];
                if(height > nz) {
                        throw InvalidValueException(radius, "height must be <= nz");
                }
        }
        else {
                height = static_cast<float>(nz);
        }

        float *dat = image->get_data();
        float x2, y2; //this is coordinates of this pixel from center axle
        float r = 0.0f;
        for (int k = 0; k < nz; ++k) {
                for (int j = 0; j < ny; ++j) {
                        for (int i = 0; i < nx; ++i, ++dat) {
                                x2 = fabs((float)i - nx/2);
                                y2 = fabs((float)j - ny/2);
                                r = (x2*x2)/(radius*radius) + (y2*y2)/(radius*radius);

                                if(r<=1 && k>=(nz-height)/2 && k<=(nz+height)/2) {
                                        *dat = 1;
                                }
                                else {
                                        *dat = 0;
                                }
                        }
                }
        }

        image->update();
}

Member Data Documentation

const string TestImageCylinder::NAME = "testimage.cylinder" [static]

Definition at line 7046 of file processor.h.

Referenced by get_name().


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