#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 1662 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 1695 of file processor.h.
01696 { 01697 return "The image is scaled with the clip variable in mind, being sure to preserve as much pixel information as possible."; 01698 }
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 1665 of file processor.h.
References NAME.
01666 { 01667 return NAME; 01668 }
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 1685 of file processor.h.
References EMAN::EMObject::FLOAT, EMAN::EMObject::INT, and EMAN::TypeDict::put().
01686 { 01687 TypeDict d; 01688 d.put("scale", EMObject::FLOAT, "The amount by which to scale" ); 01689 d.put("clip", EMObject::INT, "The length of each output dimension. Non sophisticated, output dimensions can't be different" ); 01692 return d; 01693 }
static Processor* EMAN::ScaleTransformProcessor::NEW | ( | ) | [inline, static] |
Definition at line 1669 of file processor.h.
01670 { 01671 return new ScaleTransformProcessor(); 01672 }
ImageDimensionException | if the image is not 2D or 3D | |
InvalidParameterException | if the Transform parameter is not specified |
Reimplemented from EMAN::Processor.
Definition at line 8841 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.
08841 { 08842 int ndim = image->get_ndim(); 08843 if (ndim != 2 && ndim != 3) throw UnexpectedBehaviorException("The Scale Transform processors only works for 2D and 3D images"); 08844 08845 if ( image->get_xsize() != image->get_ysize()) { 08846 throw ImageDimensionException("x size and y size of image do not match. This processor only works for uniformly sized data"); 08847 } 08848 if ( ndim == 3 ) { 08849 if ( image->get_xsize() != image->get_zsize()) { 08850 throw ImageDimensionException("x size and z size of image do not match. This processor only works for uniformly sized data"); 08851 } 08852 } 08853 08854 float scale = params.set_default("scale",0.0f); 08855 if (scale <= 0.0f) throw InvalidParameterException("The scale parameter must be greater than 0"); 08856 08857 int clip = 0; 08858 08859 if(params.has_key("clip")) 08860 { 08861 clip = params["clip"]; 08862 if (clip < 0) throw InvalidParameterException("The clip parameter must be greater than 0"); // If it's zero it's not used 08863 } 08864 else 08865 { 08866 clip = (int)(scale*image->get_xsize()); 08867 } 08868 08869 Region r; 08870 if (ndim == 3) { 08871 r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2,clip, clip,clip); 08872 } else { // ndim == 2 guaranteed by check at beginning of function 08873 r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, clip, clip); 08874 } 08875 08876 EMData* ret = 0; 08877 if (scale > 1) { 08878 if ( clip != 0) { 08879 ret = image->get_clip(r); 08880 } 08881 Transform t; 08882 t.set_scale(scale); 08883 if (ret != 0) { 08884 ret->process_inplace("xform",Dict("transform",&t)); 08885 } else { 08886 ret = image->process("xform",Dict("transform",&t)); 08887 } 08888 } else if (scale < 1) { 08889 Transform t; 08890 t.set_scale(scale); 08891 ret = image->process("xform",Dict("transform",&t)); 08892 if ( clip != 0) { 08893 ret->clip_inplace(r); 08894 } 08895 } else { 08896 if ( clip != 0) { 08897 ret = image->get_clip(r); 08898 } else { 08899 ret = image->copy(); 08900 } 08901 } 08902 return ret; 08903 08904 }
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 8785 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.
08785 { 08786 int ndim = image->get_ndim(); 08787 if (ndim != 2 && ndim != 3) throw UnexpectedBehaviorException("The Scale Transform processors only works for 2D and 3D images"); 08788 08789 if ( image->get_xsize() != image->get_ysize()) { 08790 throw ImageDimensionException("x size and y size of image do not match. This processor only works for uniformly sized data"); 08791 } 08792 if ( ndim == 3 ) { 08793 if ( image->get_xsize() != image->get_zsize()) { 08794 throw ImageDimensionException("x size and z size of image do not match. This processor only works for uniformly sized data"); 08795 } 08796 } 08797 08798 float scale = params.set_default("scale",0.0f); 08799 if (scale <= 0.0f) throw InvalidParameterException("The scale parameter must be greater than 0"); 08800 08801 int clip = 0; 08802 08803 if(params.has_key("clip")) 08804 { 08805 clip = params["clip"]; 08806 if (clip < 0) throw InvalidParameterException("The clip parameter must be greater than 0"); // If it's zero it's not used 08807 } 08808 else 08809 { 08810 clip = (int)(scale*image->get_xsize()); 08811 } 08812 08813 Region r; 08814 if (ndim == 3) { 08815 r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2,clip, clip,clip); 08816 } else { // ndim == 2 guaranteed by check at beginning of function 08817 r = Region( (image->get_xsize()-clip)/2, (image->get_xsize()-clip)/2, clip, clip); 08818 } 08819 08820 if (scale > 1) { 08821 if ( clip != 0) { 08822 image->clip_inplace(r); 08823 } 08824 Transform t; 08825 t.set_scale(scale); 08826 image->process_inplace("xform",Dict("transform",&t)); 08827 } else if (scale < 1) { 08828 Transform t; 08829 t.set_scale(scale); 08830 image->process_inplace("xform",Dict("transform",&t)); 08831 if ( clip != 0) { 08832 image->clip_inplace(r); 08833 } 08834 } else { 08835 if ( clip != 0) { 08836 image->clip_inplace(r); 08837 } 08838 } 08839 }
const string ScaleTransformProcessor::NAME = "xform.scale" [static] |