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

ToMassCenterProcessor centers image at center of mass, ignores old dx, dy. More...

#include <processor.h>

Inheritance diagram for EMAN::ToMassCenterProcessor:
Inheritance graph
[legend]
Collaboration diagram for EMAN::ToMassCenterProcessor:
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 = "xform.centerofmass"

Detailed Description

ToMassCenterProcessor centers image at center of mass, ignores old dx, dy.

Parameters:
int_shift_onlyset to 1 only shift by integer, no interpolation

Definition at line 5495 of file processor.h.


Member Function Documentation

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

                {
                        return "ToMassCenterProcessor centers image at center of mass, with a threshold. Only values higher than the threshold are considered.";
                }
virtual string EMAN::ToMassCenterProcessor::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 5500 of file processor.h.

References NAME.

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

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

                {
                        TypeDict d;
                        d.put("int_shift_only", EMObject::INT, "set to 1 only shift by integer, no interpolation");
                        d.put("threshold", EMObject::FLOAT, "Only values larger than the threshold are included in the center of mass computation. Default is 0.");
//                      d.put("positive", EMObject::INT, "uses only densities >0 for the calculatton");
                        return d;
                }
static Processor* EMAN::ToMassCenterProcessor::NEW ( ) [inline, static]

Definition at line 5505 of file processor.h.

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

References abs, EMAN::EMData::calc_center_of_mass(), EMAN::EMObject::f, EMAN::EMData::get_attr(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), LOGWARN, EMAN::Processor::params, EMAN::EMData::set_attr(), EMAN::Dict::set_default(), EMAN::Transform::set_trans(), t, and EMAN::EMData::translate().

{
        if (!image) {
                LOGWARN("NULL Image");
                return;
        }

        int int_shift_only = params.set_default("int_shift_only",1);
        float threshold = params.set_default("threshold",0.0f);
//      int positive = params.set_default("positive",0);

        if ((float)image->get_attr("sigma")==0.0f) return;              // Can't center a constant valued image
        if (threshold>(float)image->get_attr("maximum")) {
                printf("Warning, centering threshold %1.2f, but image max %1.2f. Adjusting.",threshold,(float)image->get_attr("maximum"));
                threshold=(float)image->get_attr("mean")+(float)image->get_attr("sigma");
        }

        FloatPoint com = image->calc_center_of_mass(threshold);

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

        if (int_shift_only) {
                int dx = -(int)(floor(com[0] + 0.5f) - nx / 2);
                int dy = -(int)(floor(com[1] + 0.5f) - ny / 2);
                int dz = 0;
                if (nz > 1) {
                        dz = -(int)(floor(com[2] + 0.5f) - nz / 2);
                }
                if (abs(dx)>=nx-1 || abs(dy)>=ny-1 || abs(dz)>=nz) {
                        printf("ERROR, center of mass outside image\n");
                }
                else {
                        image->translate(dx, dy, dz);

                        Transform t;
                        t.set_trans((float)dx,(float)dy,(float)dz);

                        if (nz > 1) {
                                image->set_attr("xform.align3d",&t);
                        } else {
                                image->set_attr("xform.align2d",&t);
                        }
                }
        }
        else {
                float dx = -(com[0] - nx / 2);
                float dy = -(com[1] - ny / 2);
                float dz = 0;
                if (nz > 1) {
                        dz = -(com[2] - nz / 2);
                }
                if (fabs(dx)>=nx-1 || fabs(dy)>=ny-2 || fabs(dz)>=nz) {
                        printf("ERROR, center of mass outside image\n");
                }
                else {
                        image->translate(dx, dy, dz);

                        Transform t;
                        t.set_trans(dx,dy,dz);

                        if (nz > 1) {
                                image->set_attr("xform.align3d",&t);
                        } else {
                                image->set_attr("xform.align2d",&t);
                        }
                }
        }
}

Member Data Documentation

const string ToMassCenterProcessor::NAME = "xform.centerofmass" [static]

Definition at line 5524 of file processor.h.

Referenced by get_name().


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