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). 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).

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

References align().

01061                         {
01062                                 return align(this_img, to_img, "ccc.tomo", Dict());
01063                         }

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

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

01865 {
01866 
01867         vector<Dict> alis = xform_align_nbest(this_img,to,1,cmp_name,cmp_params);
01868 
01869         Dict t;
01870         Transform* tr = (Transform*) alis[0]["xform.align3d"];
01871         t["transform"] = tr;
01872         EMData* soln = this_img->process("xform",t);
01873         soln->set_attr("xform.align3d",tr);
01874         delete tr; tr = 0;
01875 
01876         return soln;
01877 
01878 }

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

Implements EMAN::Aligner.

Definition at line 1075 of file aligner.h.

01076                         {
01077                                 return "3D rotational and translational alignment using specified ranges and maximum shifts";
01078                         }

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

01071                         {
01072                                 return NAME;
01073                         }

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

Implements EMAN::Aligner.

Definition at line 1085 of file aligner.h.

References EMAN::TypeDict::put().

01086                         {
01087                                 TypeDict d;
01088                                 d.put("daz", EMObject::FLOAT,"The angle increment in the azimuth direction. Default is 10");
01089                                 d.put("az0", EMObject::FLOAT,"Lower bound for the azimuth direction. Default it 0");
01090                                 d.put("az1", EMObject::FLOAT,"Upper bound for the azimuth direction. Default it 180.0");
01091                                 d.put("dphi", EMObject::FLOAT,"The angle increment in the phi direction. Default is 10");
01092                                 d.put("phi0", EMObject::FLOAT,"Lower bound for the phi direction. Default it 0");
01093                                 d.put("phi1", EMObject::FLOAT,"Upper bound for the phi direction. Default it 360.0");
01094                                 d.put("dalt", EMObject::FLOAT,"The angle increment in the altitude direction. Default is 10");
01095                                 d.put("alt0", EMObject::FLOAT,"Lower bound for the altitude direction. Default it 0");
01096                                 d.put("alt1", EMObject::FLOAT,"Upper bound for the altitude direction. Default it 360.0");
01097                                 d.put("dotrans", EMObject::BOOL,"Do a translational search. Default is True(1)");
01098                                 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.");
01099                                 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.");
01100                                 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.");
01101                                 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");
01102                                 d.put("verbose", EMObject::BOOL,"Turn this on to have useful information printed to standard out.");
01103                                 return d;
01104                         }

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

Definition at line 1080 of file aligner.h.

01081                         {
01082                                 return new RT3DGridAligner();
01083                         }

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 1880 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().

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


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 Thu Mar 10 22:59:50 2011 for EMAN2 by  doxygen 1.3.9.1