EMAN::RT3DGridAligner Class Reference
[a function or class that is CUDA enabled]

rotational and translational alignment using a square qrid of Altitude and Azimuth values (the phi range is specifiable) This aligner is ported from the original tomohunter.py - it is less efficient than searching on the sphere (RT3DSphereAligner). More...

#include <aligner.h>

Inheritance diagram for EMAN::RT3DGridAligner:

Inheritance graph
[legend]
Collaboration diagram for EMAN::RT3DGridAligner:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual EMDataalign (EMData *this_img, EMData *to_img, const string &cmp_name="ccc.tomo", const Dict &cmp_params=Dict()) const
 See Aligner comments for more details.
virtual EMDataalign (EMData *this_img, EMData *to_img) const
 See Aligner comments for more details.
virtual vector< Dictxform_align_nbest (EMData *this_img, EMData *to_img, const unsigned int nsoln, const string &cmp_name, const Dict &cmp_params) const
 See Aligner comments for more details.
virtual string get_name () const
 Get the Aligner's name.
virtual string get_desc () const
virtual TypeDict get_param_types () const

Static Public Member Functions

static AlignerNEW ()

Static Public Attributes

static const string NAME = "rotate_translate_3d_grid"

Detailed Description

rotational and translational alignment using a square qrid of Altitude and Azimuth values (the phi range is specifiable) This aligner is ported from the original tomohunter.py - it is less efficient than searching on the sphere (RT3DSphereAligner).

This is for use as a course aligner. For refineing alignments, use the refine_3d_grid aligner. In general this aligner is not used much and is mostly depreciated.

Parameters:
daz The angle increment in the azimuth direction
laz Lower bound for the azimuth direction
uaz Upper bound for the azimuth direction
dphi The angle increment in the phi direction
lphi Lower bound for the phi direction
uphi Upper bound for the phi direction
dalt The angle increment in the altitude direction
lalt Lower bound for the altitude direction
ualt Upper bound for the altitude direction
dotrans Do a translational search
search The maximum length of the detectable translational shift - if you supply this parameter you can not supply the maxshiftx, maxshifty or maxshiftz parameters. Each approach is mutually exclusive
searchx The maximum length of the detectable translational shift in the x direction- if you supply this parameter you can not supply the maxshift parameters
searchy The maximum length of the detectable translational shift in the y direction- if you supply this parameter you can not supply the maxshift parameters
searchz The maximum length of the detectable translational shift in the z direction- if you supply this parameter you can not supply the maxshift parameters
verbose Turn this on to have useful information printed to standard out
Author:
John Flanagan and David Woolford (ported from Mike Schmid's e2tomohuntThis is the increment applied to the inplane rotationer code - Mike Schmid is the intellectual author)
Date:
Feb 2011

Definition at line 1146 of file aligner.h.


Member Function Documentation

virtual EMData* EMAN::RT3DGridAligner::align ( EMData this_img,
EMData to_img 
) const [inline, virtual]

See Aligner comments for more details.

Implements EMAN::Aligner.

Definition at line 1155 of file aligner.h.

References align().

01156                         {
01157                                 return align(this_img, to_img, "ccc.tomo", Dict());
01158                         }

EMData * RT3DGridAligner::align ( EMData this_img,
EMData to_img,
const string &  cmp_name = "ccc.tomo",
const Dict cmp_params = Dict() 
) const [virtual]

See Aligner comments for more details.

Implements EMAN::Aligner.

Definition at line 2088 of file aligner.cpp.

References EMAN::EMData::process(), EMAN::EMData::set_attr(), t, and xform_align_nbest().

Referenced by align().

02089 {
02090 
02091         vector<Dict> alis = xform_align_nbest(this_img,to,1,cmp_name,cmp_params);
02092 
02093         Dict t;
02094         Transform* tr = (Transform*) alis[0]["xform.align3d"];
02095         t["transform"] = tr;
02096         EMData* soln = this_img->process("xform",t);
02097         soln->set_attr("xform.align3d",tr);
02098         delete tr; tr = 0;
02099 
02100         return soln;
02101 
02102 }

virtual string EMAN::RT3DGridAligner::get_desc (  )  const [inline, virtual]

Implements EMAN::Aligner.

Definition at line 1170 of file aligner.h.

01171                         {
01172                                 return "3D rotational and translational alignment using specified ranges and maximum shifts";
01173                         }

virtual string EMAN::RT3DGridAligner::get_name (  )  const [inline, virtual]

Get the Aligner's name.

Each Aligner is identified by a unique name.

Returns:
The Aligner's name.

Implements EMAN::Aligner.

Definition at line 1165 of file aligner.h.

References NAME.

01166                         {
01167                                 return NAME;
01168                         }

virtual TypeDict EMAN::RT3DGridAligner::get_param_types (  )  const [inline, virtual]

Implements EMAN::Aligner.

Definition at line 1180 of file aligner.h.

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

01181                         {
01182                                 TypeDict d;
01183                                 d.put("daz", EMObject::FLOAT,"The angle increment in the azimuth direction. Default is 10");
01184                                 d.put("az0", EMObject::FLOAT,"Lower bound for the azimuth direction. Default it 0");
01185                                 d.put("az1", EMObject::FLOAT,"Upper bound for the azimuth direction. Default it 180.0");
01186                                 d.put("dphi", EMObject::FLOAT,"The angle increment in the phi direction. Default is 10");
01187                                 d.put("phi0", EMObject::FLOAT,"Lower bound for the phi direction. Default it 0");
01188                                 d.put("phi1", EMObject::FLOAT,"Upper bound for the phi direction. Default it 360.0");
01189                                 d.put("dalt", EMObject::FLOAT,"The angle increment in the altitude direction. Default is 10");
01190                                 d.put("alt0", EMObject::FLOAT,"Lower bound for the altitude direction. Default it 0");
01191                                 d.put("alt1", EMObject::FLOAT,"Upper bound for the altitude direction. Default it 360.0");
01192                                 d.put("dotrans", EMObject::BOOL,"Do a translational search. Default is True(1)");
01193                                 d.put("search", EMObject::INT,"The maximum length of the detectable translational shift - if you supply this parameter you can not supply the maxshiftx, maxshifty or maxshiftz parameters. Each approach is mutually exclusive.");
01194                                 d.put("searchx", EMObject::INT,"The maximum length of the detectable translational shift in the x direction- if you supply this parameter you can not supply the maxshift parameters. Default is 3.");
01195                                 d.put("searchy", EMObject::INT,"The maximum length of the detectable translational shift in the y direction- if you supply this parameter you can not supply the maxshift parameters. Default is 3.");
01196                                 d.put("searchz", EMObject::INT,"The maximum length of the detectable translational shift in the z direction- if you supply this parameter you can not supply the maxshift parameters. Default is 3");
01197                                 d.put("verbose", EMObject::BOOL,"Turn this on to have useful information printed to standard out.");
01198                                 return d;
01199                         }

static Aligner* EMAN::RT3DGridAligner::NEW (  )  [inline, static]

Definition at line 1175 of file aligner.h.

01176                         {
01177                                 return new RT3DGridAligner();
01178                         }

vector< Dict > RT3DGridAligner::xform_align_nbest ( EMData this_img,
EMData to_img,
const unsigned int  nsoln,
const string &  cmp_name,
const Dict cmp_params 
) const [virtual]

See Aligner comments for more details.

Reimplemented from EMAN::Aligner.

Definition at line 2104 of file aligner.cpp.

References EMAN::EMData::calc_ccf(), EMAN::EMData::calc_max_location_wrap(), calc_max_location_wrap_cuda(), EMAN::Cmp::cmp(), copy(), data, EMAN::EMData::do_fft(), EMAN::EMData::get_ndim(), get_stats_cuda(), EMAN::EMData::get_value_at_wrap(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), ImageDimensionException, InvalidParameterException, EMAN::Aligner::params, phi, EMAN::EMData::process(), EMAN::EMData::process_inplace(), EMAN::Dict::set_default(), EMAN::Transform::set_trans(), sqrt(), and t.

Referenced by align().

02104                                                                                                                                                                {
02105 
02106         if ( this_img->get_ndim() != 3 || to->get_ndim() != 3 ) {
02107                 throw ImageDimensionException("This aligner only works for 3D images");
02108         }
02109 
02110         int searchx = 0;
02111         int searchy = 0;
02112         int searchz = 0;
02113         
02114         bool dotrans = params.set_default("dotrans",1);
02115         if (params.has_key("search")) {
02116                 vector<string> check;
02117                 check.push_back("searchx");
02118                 check.push_back("searchy");
02119                 check.push_back("searchz");
02120                 for(vector<string>::const_iterator cit = check.begin(); cit != check.end(); ++cit) {
02121                         if (params.has_key(*cit)) throw InvalidParameterException("The search parameter is mutually exclusive of the searchx, searchy, and searchz parameters");
02122                 }
02123                 int search  = params["search"];
02124                 searchx = search;
02125                 searchy = search;
02126                 searchz = search;
02127         } else {
02128                 searchx = params.set_default("searchx",3);
02129                 searchy = params.set_default("searchy",3);
02130                 searchz = params.set_default("searchz",3);
02131         }
02132 
02133         float lalt = params.set_default("alt0",0.0f);
02134         float laz = params.set_default("az0",0.0f);
02135         float lphi = params.set_default("phi0",0.0f);
02136         float ualt = params.set_default("alt1",180.0f); // I am using 179.9 rather than 180 to avoid resampling
02137         float uphi = params.set_default("phi1",360.0f); // I am using 359.9 rather than 180 to avoid resampling 0 = 360 (for perodic functions)
02138         float uaz = params.set_default("az1",360.0f);   // I am using 359.9 rather than 180 to avoid resampling 0 = 360 (for perodic functions)
02139         float dalt = params.set_default("dalt",10.f);
02140         float daz = params.set_default("daz",10.f);
02141         float dphi = params.set_default("dphi",10.f);
02142         bool verbose = params.set_default("verbose",false);
02143         
02144         //in case we arre aligning tomos
02145         Dict altered_cmp_params(cmp_params);
02146         if (cmp_name == "ccc.tomo") {
02147                 altered_cmp_params.set_default("searchx", searchx);
02148                 altered_cmp_params.set_default("searchy", searchy);
02149                 altered_cmp_params.set_default("searchz", searchz);
02150                 altered_cmp_params.set_default("norm", true);
02151         }
02152 
02153         vector<Dict> solns;
02154         if (nsoln == 0) return solns; // What was the user thinking?
02155         for (unsigned int i = 0; i < nsoln; ++i ) {
02156                 Dict d;
02157                 d["score"] = 1.e24;
02158                 Transform t; // identity by default
02159                 d["xform.align3d"] = &t; // deep copy is going on here
02160                 solns.push_back(d);
02161         }
02162         
02163         bool tomography = (cmp_name == "ccc.tomo") ? 1 : 0;
02164         EMData * tofft = 0;
02165         if(dotrans || tomography){
02166                 tofft = to->do_fft();
02167         }
02168         
02169 #ifdef EMAN2_USING_CUDA 
02170         if(EMData::usecuda == 1) {
02171                 if(!this_img->getcudarodata()) this_img->copy_to_cudaro();  // safer call
02172                 if(!to->getcudarwdata()) to->copy_to_cuda();
02173                 if(to->getcudarwdata()){if(tofft) tofft->copy_to_cuda();}
02174         }
02175 #endif
02176 
02177         Dict d;
02178         d["type"] = "eman"; // d is used in the loop below
02179         Transform trans = Transform();
02180         Cmp* c = Factory <Cmp>::get(cmp_name, cmp_params);
02181         bool use_cpu = true;
02182         for ( float alt = lalt; alt <= ualt; alt += dalt) {
02183                 // An optimization for the range of az is made at the top of the sphere
02184                 // If you think about it, this is just a coarse way of making this approach slightly more efficient
02185                 for ( float az = laz; az < uaz; az += daz ){
02186                         if (verbose) {
02187                                 cout << "Trying angle alt " << alt << " az " << az << endl;
02188                         }
02189                         for( float phi = lphi; phi < uphi; phi += dphi ) {
02190                                 d["alt"] = alt;
02191                                 d["phi"] = phi; 
02192                                 d["az"] = az;
02193                                 Transform t(d);
02194                                 EMData* transformed = this_img->process("xform",Dict("transform",&t));
02195                                 
02196                                 //need to do things a bit diffrent if we want to compare two tomos
02197                                 float best_score = 0.0f;
02198                                 if(dotrans || tomography){
02199                                         EMData* ccf = transformed->calc_ccf(tofft);
02200 #ifdef EMAN2_USING_CUDA 
02201                                         if(to->getcudarwdata()){
02202                                                 use_cpu = false;;
02203                                                 CudaPeakInfo* data = calc_max_location_wrap_cuda(ccf->getcudarwdata(), ccf->get_xsize(), ccf->get_ysize(), ccf->get_zsize(), searchx, searchy, searchz);
02204                                                 trans.set_trans((float)-data->px, (float)-data->py, (float)-data->pz);
02205                                                 t = trans*t;    //composite transfrom to reflect the fact that we have done a rotation first and THEN a transformation
02206                                                 if (tomography) {
02207                                                         float2 stats = get_stats_cuda(ccf->getcudarwdata(), ccf->get_xsize(), ccf->get_ysize(), ccf->get_zsize());
02208                                                         best_score = -(data->peak - stats.x)/sqrt(stats.y); // Normalize, this is better than calling the norm processor since we only need to normalize one point
02209                                                 } else {
02210                                                         best_score = -data->peak;
02211                                                 }
02212                                                 delete data;
02213                                         }
02214 #endif
02215                                         if(use_cpu){
02216                                                 if(tomography) ccf->process_inplace("normalize");       
02217                                                 IntPoint point = ccf->calc_max_location_wrap(searchx,searchy,searchz);
02218                                                 trans.set_trans((float)-point[0], (float)-point[1], (float)-point[2]);
02219                                                 t = trans*t;    //composite transfrom to reflect the fact that we have done a rotation first and THEN a transformation
02220                                                 best_score = -ccf->get_value_at_wrap(point[0], point[1], point[2]);
02221                                         }
02222                                         delete ccf; ccf =0;
02223                                         delete transformed; transformed = 0;
02224                                 }
02225 
02226                                 if(!tomography){
02227                                         if(!transformed) transformed = this_img->process("xform",Dict("transform",&t));
02228                                         best_score = c->cmp(to,transformed);
02229                                         delete transformed; transformed = 0;
02230                                 }
02231                                 
02232                                 unsigned int j = 0;
02233                                 for ( vector<Dict>::iterator it = solns.begin(); it != solns.end(); ++it, ++j ) {
02234                                         if ( (float)(*it)["score"] > best_score ) {  // Note greater than - EMAN2 preferes minimums as a matter of policy
02235                                                 vector<Dict>::reverse_iterator rit = solns.rbegin();
02236                                                 copy(rit+1,solns.rend()-j,rit);
02237                                                 Dict& d = (*it);
02238                                                 d["score"] = best_score;
02239                                                 d["xform.align3d"] = &t;
02240                                                 break;
02241                                         }
02242                                 }
02243                         }
02244                 }
02245         }
02246 
02247         //Free up resources (for an expensive opperation like this move data to and from device is a small % of time)
02248         #ifdef EMAN2_USING_CUDA
02249                 to->copy_from_device();
02250                 this_img->ro_free();
02251         #endif
02252         
02253         if(tofft) {delete tofft; tofft = 0;}
02254         return solns;
02255 
02256 }


Member Data Documentation

const string RT3DGridAligner::NAME = "rotate_translate_3d_grid" [static]

Definition at line 1201 of file aligner.h.

Referenced by get_name().


The documentation for this class was generated from the following files:
Generated on Thu Nov 17 12:45:12 2011 for EMAN2 by  doxygen 1.4.7