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

Replace a source image as a sine wave in specified wave length. More...

#include <processor.h>

Inheritance diagram for EMAN::TestImageSinewave:
Inheritance graph
[legend]
Collaboration diagram for EMAN::TestImageSinewave:
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.sinewave"

Detailed Description

Replace a source image as a sine wave in specified wave length.

Parameters:
wavelengthwavelength in equation sin(x*2*PI/wavelength - phase*180/PI)
axis(optional) specify a major axis for asymmetric features, default x axis
phase(optional) the phase in radians
az(optional) angle in degree. for 2D image, this is the rotated angle of the image, in 3D image, it's az for euler angle. default is zero
alt(optional) angle in degree. only in 3D case, alt for euler angle, default is zero
phi(optional) angle in degree. only in 3D case, phi for euler angle, default is zero

Definition at line 6693 of file processor.h.


Member Function Documentation

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

                {
                        return "Replace a source image as a sine wave in specified wave length";
                }
virtual string EMAN::TestImageSinewave::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 6698 of file processor.h.

References NAME.

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

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

                {
                        TypeDict d;
                        d.put("wavelength", EMObject::FLOAT, "wavelength in equation sin(x*2*PI/wavelength - phase*180/PI)");
                        d.put("axis", EMObject::STRING, "(optional) specify a major axis for asymmetric features, default x axis");
                        d.put("phase", EMObject::FLOAT, "(optional) the phase in radians");
                        d.put("az", EMObject::FLOAT, "(optional) angle in degree. for 2D image, this is the rotated angle of the image, \
                                                                                                in 3D image, it's az for euler angle. default is zero");
                        d.put("alt", EMObject::FLOAT, "(optional) angle in degree. only in 3D case, alt for euler angle, default is zero");
                        d.put("phi", EMObject::FLOAT, "(optional) angle in degree. only in 3D case, phi for euler angle, default is zero");
                        return d;
                }
static Processor* EMAN::TestImageSinewave::NEW ( ) [inline, static]

Definition at line 6708 of file processor.h.

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

References EMAN::EMData::get_data(), EMAN::CutoffBlockProcessor::get_name(), EMAN::EMData::get_ndim(), EMAN::Dict::has_key(), InvalidParameterException, LOGERR, nx, ny, EMAN::Processor::params, phase(), phi, EMAN::EMData::transform(), and EMAN::EMData::update().

{
        preprocess(image);

        if(!params.has_key("wavelength")) {
                LOGERR("%s wavelength is required parameter", get_name().c_str());
                throw InvalidParameterException("wavelength parameter is required.");
        }
        float wavelength = params["wavelength"];

        string axis = "";
        if(params.has_key("axis")) {
                axis = (const char*)params["axis"];
        }

        float phase = 0;
        if(params.has_key("phase")) {
                phase = params["phase"];
        }

        int ndim = image->get_ndim();
        float * dat = image->get_data();

        if(ndim==1) {   //1D
                for(int i=0; i<nx; ++i, ++dat) {
                        *dat = sin(i*(2.0f*M_PI/wavelength) + phase);
                }
        }
        else if(ndim==2) {      //2D
                float alpha = 0;
                if(params.has_key("az")) {
                        alpha = params["az"];
                }
                for(int j=0; j<ny; ++j) {
                        for(int i=0; i<nx; ++i, ++dat) {
                                if(alpha != 0) {
                                        *dat = sin((i*sin((180-alpha)*M_PI/180)+j*cos((180-alpha)*M_PI/180))*(2.0f*M_PI/wavelength) + phase);
                                }
                                else if(axis.compare("y")==0 || axis.compare("Y")==0) {
                                        *dat = sin(j*(2.0f*M_PI/wavelength) + phase);
                                }
                                else {
                                        *dat = sin(i*(2.0f*M_PI/wavelength) + phase);
                                }
                        }
                }
        }
        else {  //3D
                float az = 0;
                if(params.has_key("az")) {
                        az = params["az"];
                }
                float alt = 0;
                if(params.has_key("alt")) {
                        alt = params["alt"];
                }
                float phi = 0;
                if(params.has_key("phi")) {
                        phi = params["phi"];
                }

                for(int k=0; k<nz; ++k) {
                        for(int j=0; j<ny; ++j) {
                                for(int i=0; i<nx; ++i, ++dat) {
                                        if(axis.compare("z")==0 || axis.compare("Z")==0) {
                                                *dat = sin(k*(2.0f*M_PI/wavelength) + phase);
                                        }
                                        else if(axis.compare("y")==0 || axis.compare("Y")==0) {
                                                *dat = sin(j*(2.0f*M_PI/wavelength) + phase);
                                        }
                                        else {
                                                *dat = sin(i*(2.0f*M_PI/wavelength) + phase);
                                        }
                                }
                        }
                }

                if(az != 0 || alt != 0 || phi != 0) {
                        Dict d("type","eman");
                        d["az"] = az; d["phi"] = phi; d["alt"] = alt;
                        image->transform(Transform(d));
                }
        }

        image->update();
}

Member Data Documentation

const string TestImageSinewave::NAME = "testimage.sinewave" [static]

Definition at line 6726 of file processor.h.

Referenced by get_name().


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