Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

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), but very useful if you want to search in a specific, small, local area. 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

AlignerNEW ()

Static Public Attributes

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), but very useful if you want to search in a specific, small, local area.

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:
David Woolford and John Flanagan (ported from Mike Schmid's e2tomohuntThis is the increment applied to the inplane rotationer code - Mike Schmid is the intellectual author)
Date:
June 23 2009

Definition at line 1036 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 1045 of file aligner.h.

References align().

01046                         {
01047                                 return align(this_img, to_img, "ccc.tomo", Dict());
01048                         }

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 1846 of file aligner.cpp.

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

01847 {
01848 
01849         vector<Dict> alis = xform_align_nbest(this_img,to,1,cmp_name,cmp_params);
01850 
01851         Dict t;
01852         Transform* tr = (Transform*) alis[0]["xform.align3d"];
01853         t["transform"] = tr;
01854         EMData* soln = this_img->process("xform",t);
01855         soln->set_attr("xform.align3d",tr);
01856         delete tr; tr = 0;
01857 
01858         return soln;
01859 
01860 }

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

Implements EMAN::Aligner.

Definition at line 1060 of file aligner.h.

01061                         {
01062                                 return "3D rotational and translational alignment using specified ranges and maximum shifts";
01063                         }

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 1055 of file aligner.h.

01056                         {
01057                                 return NAME;
01058                         }

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

Implements EMAN::Aligner.

Definition at line 1070 of file aligner.h.

References EMAN::TypeDict::put().

01071                         {
01072                                 TypeDict d;
01073                                 d.put("daz", EMObject::FLOAT,"The angle increment in the azimuth direction. Default is 10");
01074                                 d.put("az0", EMObject::FLOAT,"Lower bound for the azimuth direction. Default it 0");
01075                                 d.put("az1", EMObject::FLOAT,"Upper bound for the azimuth direction. Default it 180.0");
01076                                 d.put("dphi", EMObject::FLOAT,"The angle increment in the phi direction. Default is 10");
01077                                 d.put("phi0", EMObject::FLOAT,"Lower bound for the phi direction. Default it 0");
01078                                 d.put("phi1", EMObject::FLOAT,"Upper bound for the phi direction. Default it 360.0");
01079                                 d.put("dalt", EMObject::FLOAT,"The angle increment in the altitude direction. Default is 10");
01080                                 d.put("alt0", EMObject::FLOAT,"Lower bound for the altitude direction. Default it 0");
01081                                 d.put("alt1", EMObject::FLOAT,"Upper bound for the altitude direction. Default it 360.0");
01082                                 d.put("dotrans", EMObject::BOOL,"Do a translational search. Default is True(1)");
01083                                 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.");
01084                                 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.");
01085                                 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.");
01086                                 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");
01087                                 d.put("verbose", EMObject::BOOL,"Turn this on to have useful information printed to standard out.");
01088                                 return d;
01089                         }

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

Definition at line 1065 of file aligner.h.

01066                         {
01067                                 return new RT3DGridAligner();
01068                         }

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 1862 of file aligner.cpp.

References EMAN::EMData::calc_ccf(), EMAN::EMData::calc_max_location_wrap(), calc_max_location_wrap_cuda(), EMAN::EMData::cmp(), copy(), data, EMAN::EMData::do_fft(), EMAN::Dict::end(), 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, CudaPeakInfo::peak, phi, EMAN::EMData::process(), EMAN::EMData::process_inplace(), CudaPeakInfo::px, CudaPeakInfo::py, CudaPeakInfo::pz, EMAN::Dict::set_default(), EMAN::Transform::set_trans(), sqrt(), and t.

Referenced by align().

01862                                                                                                                                                                {
01863 
01864         if ( this_img->get_ndim() != 3 || to->get_ndim() != 3 ) {
01865                 throw ImageDimensionException("This aligner only works for 3D images");
01866         }
01867 
01868         int searchx = 0;
01869         int searchy = 0;
01870         int searchz = 0;
01871         
01872         bool dotrans = params.set_default("dotrans",1);
01873         if (params.has_key("search")) {
01874                 vector<string> check;
01875                 check.push_back("searchx");
01876                 check.push_back("searchy");
01877                 check.push_back("searchz");
01878                 for(vector<string>::const_iterator cit = check.begin(); cit != check.end(); ++cit) {
01879                         if (params.has_key(*cit)) throw InvalidParameterException("The search parameter is mutually exclusive of the searchx, searchy, and searchz parameters");
01880                 }
01881                 int search  = params["search"];
01882                 searchx = search;
01883                 searchy = search;
01884                 searchz = search;
01885         } else {
01886                 searchx = params.set_default("searchx",3);
01887                 searchy = params.set_default("searchy",3);
01888                 searchz = params.set_default("searchz",3);
01889         }
01890 
01891         float lalt = params.set_default("alt0",0.0f);
01892         float laz = params.set_default("az0",0.0f);
01893         float lphi = params.set_default("phi0",0.0f);
01894         float ualt = params.set_default("alt1",180.0f); // I am using 179.9 rather than 180 to avoid resampling
01895         float uphi = params.set_default("phi1",360.0f); // I am using 359.9 rather than 180 to avoid resampling 0 = 360 (for perodic functions)
01896         float uaz = params.set_default("az1",360.0f);   // I am using 359.9 rather than 180 to avoid resampling 0 = 360 (for perodic functions)
01897         float dalt = params.set_default("dalt",10.f);
01898         float daz = params.set_default("daz",10.f);
01899         float dphi = params.set_default("dphi",10.f);
01900         bool verbose = params.set_default("verbose",false);
01901         
01902         //in case we arre aligning tomos
01903         Dict altered_cmp_params(cmp_params);
01904         if (cmp_name == "ccc.tomo") {
01905                 altered_cmp_params.set_default("searchx", searchx);
01906                 altered_cmp_params.set_default("searchy", searchy);
01907                 altered_cmp_params.set_default("searchz", searchz);
01908                 altered_cmp_params.set_default("norm", true);
01909         }
01910 
01911         vector<Dict> solns;
01912         if (nsoln == 0) return solns; // What was the user thinking?
01913         for (unsigned int i = 0; i < nsoln; ++i ) {
01914                 Dict d;
01915                 d["score"] = 1.e24;
01916                 Transform t; // identity by default
01917                 d["xform.align3d"] = &t; // deep copy is going on here
01918                 solns.push_back(d);
01919         }
01920         
01921         bool tomography = (cmp_name == "ccc.tomo") ? 1 : 0;
01922         EMData * tofft = 0;
01923         if(dotrans || tomography){
01924                 tofft = to->do_fft();
01925         }
01926         
01927 #ifdef EMAN2_USING_CUDA 
01928         if(EMData::usecuda == 1) {
01929                 if(!this_img->isrodataongpu()) this_img->copy_to_cudaro();
01930                 if(!to->cudarwdata) to->copy_to_cuda();
01931                 if(to->cudarwdata){if(tofft) tofft->copy_to_cuda();}
01932         }
01933 #endif
01934 
01935         Dict d;
01936         d["type"] = "eman"; // d is used in the loop below
01937         bool use_cpu = true;
01938         for ( float alt = lalt; alt <= ualt; alt += dalt) {
01939                 // An optimization for the range of az is made at the top of the sphere
01940                 // If you think about it, this is just a coarse way of making this approach slightly more efficient
01941                 for ( float az = laz; az < uaz; az += daz ){
01942                         if (verbose) {
01943                                 cout << "Trying angle alt " << alt << " az " << az << endl;
01944                         }
01945                         for( float phi = lphi; phi < uphi; phi += dphi ) {
01946                                 d["alt"] = alt;
01947                                 d["phi"] = phi; 
01948                                 d["az"] = az;
01949                                 Transform t(d);
01950                                 EMData* transformed = this_img->process("xform",Dict("transform",&t));
01951                                 
01952                                 //need to do things a bit diffrent if we want to compare two tomos
01953                                 float best_score;
01954                                 if(dotrans || tomography){
01955                                         EMData* ccf = transformed->calc_ccf(tofft);
01956 #ifdef EMAN2_USING_CUDA 
01957                                         if(to->cudarwdata){
01958                                                 use_cpu = false;
01959                                                 float2 stats = get_stats_cuda(ccf->cudarwdata, ccf->get_xsize(), ccf->get_ysize(), ccf->get_zsize());
01960                                                 CudaPeakInfo* data = calc_max_location_wrap_cuda(ccf->cudarwdata, ccf->get_xsize(), ccf->get_ysize(), ccf->get_zsize(), searchx, searchy, searchz);
01961                                                 t.set_trans((float)-data->px, (float)-data->py, (float)-data->pz);
01962                                                 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
01963                                         }
01964 #endif
01965                                         if(use_cpu){
01966                                                 if(tomography) ccf->process_inplace("normalize");       
01967                                                 IntPoint point = ccf->calc_max_location_wrap(searchx,searchy,searchz);
01968                                                 t.set_trans((float)-point[0], (float)-point[1], (float)-point[2]);
01969                                                 best_score = -ccf->get_value_at_wrap(point[0], point[1], point[2]);
01970                                                 delete transformed; // this is to stop a mem leak
01971                                                 transformed = this_img->process("xform",Dict("transform",&t));
01972                                         }
01973                                         delete ccf; ccf =0;
01974                                 }
01975 
01976                                 if(!tomography){
01977                                         best_score = transformed->cmp(cmp_name,to,cmp_params); //this is not very efficient as it creates a new cmp object for each iteration
01978                                 
01979                                 }
01980                                 delete transformed; transformed = 0;
01981                                 
01982                                 unsigned int j = 0;
01983                                 for ( vector<Dict>::iterator it = solns.begin(); it != solns.end(); ++it, ++j ) {
01984                                         if ( (float)(*it)["score"] > best_score ) {  // Note greater than - EMAN2 preferes minimums as a matter of policy
01985                                                 vector<Dict>::reverse_iterator rit = solns.rbegin();
01986                                                 copy(rit+1,solns.rend()-j,rit);
01987                                                 Dict& d = (*it);
01988                                                 d["score"] = best_score;
01989                                                 d["xform.align3d"] = &t;
01990                                                 break;
01991                                         }
01992                                 }
01993                         }
01994                 }
01995         }
01996 
01997         if(tofft) {delete tofft; tofft = 0;}
01998         return solns;
01999 
02000 }


Member Data Documentation

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

Definition at line 76 of file aligner.cpp.


The documentation for this class was generated from the following files:
Generated on Mon Mar 7 18:20:02 2011 for EMAN2 by  doxygen 1.3.9.1