#include <processor.h>
Inheritance diagram for EMAN::ScaleTransformProcessor:
Public Member Functions | |||||||
virtual string | get_name () const | ||||||
Get the processor's name. | |||||||
virtual void | process_inplace (EMData *image) | ||||||
| |||||||
virtual EMData * | process (const EMData *const image) | ||||||
| |||||||
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.scale" |
scale | The amount by which to scale | |
cip | The length of each output dimension. Non sophisticated, output dimensions can't be different |
Definition at line 1651 of file processor.h.
virtual string EMAN::ScaleTransformProcessor::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 1685 of file processor.h.
01686 { 01687 return "The image is scaled with the clip variable in mind, being sure to preserve as much pixel information as possible."; 01688 }
virtual string EMAN::ScaleTransformProcessor::get_name | ( | ) | const [inline, virtual] |
Get the processor's name.
Each processor is identified by a unique name.
Implements EMAN::Processor.
Definition at line 1654 of file processor.h.
References NAME.
01655 { 01656 return NAME; 01657 }
virtual TypeDict EMAN::ScaleTransformProcessor::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 1675 of file processor.h.
References EMAN::EMObject::FLOAT, EMAN::EMObject::INT, and EMAN::TypeDict::put().
01676 { 01677 TypeDict d; 01678 d.put("scale", EMObject::FLOAT, "The amount by which to scale" ); 01679 d.put("clip", EMObject::INT, "The length of each output dimension. Non sophisticated, output dimensions can't be different" ); 01682 return d; 01683 }
static Processor* EMAN::ScaleTransformProcessor::NEW | ( | ) | [inline, static] |
Definition at line 1658 of file processor.h.
01659 { 01660 return new ScaleTransformProcessor(); 01661 }
ImageDimensionException | if the image is not 2D or 3D | |
InvalidParameterException | if the Transform parameter is not specified |
Reimplemented from EMAN::Processor.
Definition at line 8615 of file processor.cpp.
References EMAN::EMData::clip_inplace(), EMAN::EMData::copy(), EMAN::EMData::get_clip(), EMAN::EMData::get_ndim(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), ImageDimensionException, InvalidParameterException, EMAN::Processor::params, EMAN::EMData::process(), EMAN::EMData::process_inplace(), EMAN::Dict::set_default(), t, and UnexpectedBehaviorException.
08615 { 08616 int ndim = image->get_ndim(); 08617 if (ndim != 2 && ndim != 3) throw UnexpectedBehaviorException("The Scale Transform processors only works for 2D and 3D images"); 08618 08619 if ( image->get_xsize() != image->get_ysize()) { 08620 throw ImageDimensionException("x size and y size of image do not match. This processor only works for uniformly sized data"); 08621 } 08622 if ( ndim == 3 ) { 08623 if ( image->get_xsize() != image->get_zsize()) { 08624 throw ImageDimensionException("x size and z size of image do not match. This processor only works for uniformly sized data"); 08625 } 08626 } 08627 08628 float scale = params.set_default("scale",0.0f); 08629 if (scale <= 0.0f) throw InvalidParameterException("The scale parameter must be greater than 0"); 08630 08631 int clip = 0; 08632 08633 if(params.has_key("clip")) 08634 { 08635 clip = params["clip"]; 08636 if (clip < 0) throw InvalidParameterException("The clip parameter must be greater than 0"); // If it's zero it's not used 08637 } 08638 else 08639 { 08640 clip = (int)(scale*image->get_xsize()); 08641 } 08642 08643 Region r; 08644 if (ndim == 3) { 08645 r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2,clip, clip,clip); 08646 } else { // ndim == 2 guaranteed by check at beginning of function 08647 r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, clip, clip); 08648 } 08649 08650 EMData* ret = 0; 08651 if (scale > 1) { 08652 if ( clip != 0) { 08653 ret = image->get_clip(r); 08654 } 08655 Transform t; 08656 t.set_scale(scale); 08657 if (ret != 0) { 08658 ret->process_inplace("xform",Dict("transform",&t)); 08659 } else { 08660 ret = image->process("xform",Dict("transform",&t)); 08661 } 08662 } else if (scale < 1) { 08663 Transform t; 08664 t.set_scale(scale); 08665 ret = image->process("xform",Dict("transform",&t)); 08666 if ( clip != 0) { 08667 ret->clip_inplace(r); 08668 } 08669 } else { 08670 if ( clip != 0) { 08671 ret = image->get_clip(r); 08672 } else { 08673 ret = image->copy(); 08674 } 08675 } 08676 return ret; 08677 08678 }
void ScaleTransformProcessor::process_inplace | ( | EMData * | image | ) | [virtual] |
ImageDimensionException | if the image is not 2D or 3D | |
InvalidParameterException | if the Transform parameter is not specified |
Implements EMAN::Processor.
Definition at line 8559 of file processor.cpp.
References EMAN::EMData::clip_inplace(), EMAN::EMData::get_ndim(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), ImageDimensionException, InvalidParameterException, EMAN::Processor::params, EMAN::EMData::process_inplace(), EMAN::Dict::set_default(), t, and UnexpectedBehaviorException.
08559 { 08560 int ndim = image->get_ndim(); 08561 if (ndim != 2 && ndim != 3) throw UnexpectedBehaviorException("The Scale Transform processors only works for 2D and 3D images"); 08562 08563 if ( image->get_xsize() != image->get_ysize()) { 08564 throw ImageDimensionException("x size and y size of image do not match. This processor only works for uniformly sized data"); 08565 } 08566 if ( ndim == 3 ) { 08567 if ( image->get_xsize() != image->get_zsize()) { 08568 throw ImageDimensionException("x size and z size of image do not match. This processor only works for uniformly sized data"); 08569 } 08570 } 08571 08572 float scale = params.set_default("scale",0.0f); 08573 if (scale <= 0.0f) throw InvalidParameterException("The scale parameter must be greater than 0"); 08574 08575 int clip = 0; 08576 08577 if(params.has_key("clip")) 08578 { 08579 clip = params["clip"]; 08580 if (clip < 0) throw InvalidParameterException("The clip parameter must be greater than 0"); // If it's zero it's not used 08581 } 08582 else 08583 { 08584 clip = (int)(scale*image->get_xsize()); 08585 } 08586 08587 Region r; 08588 if (ndim == 3) { 08589 r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2,clip, clip,clip); 08590 } else { // ndim == 2 guaranteed by check at beginning of function 08591 r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, clip, clip); 08592 } 08593 08594 if (scale > 1) { 08595 if ( clip != 0) { 08596 image->clip_inplace(r); 08597 } 08598 Transform t; 08599 t.set_scale(scale); 08600 image->process_inplace("xform",Dict("transform",&t)); 08601 } else if (scale < 1) { 08602 Transform t; 08603 t.set_scale(scale); 08604 image->process_inplace("xform",Dict("transform",&t)); 08605 if ( clip != 0) { 08606 image->clip_inplace(r); 08607 } 08608 } else { 08609 if ( clip != 0) { 08610 image->clip_inplace(r); 08611 } 08612 } 08613 }
const string ScaleTransformProcessor::NAME = "xform.scale" [static] |