EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
EMAN::RT3DGridAligner Class Reference

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]

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. More...
 
virtual EMDataalign (EMData *this_img, EMData *to_img) const
 See Aligner comments for more details. More...
 
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. More...
 
virtual string get_name () const
 Get the Aligner's name. More...
 
virtual string get_desc () const
 
virtual TypeDict get_param_types () const
 
- Public Member Functions inherited from EMAN::Aligner
virtual ~Aligner ()
 
virtual Dict get_params () const
 Get the Aligner parameters in a key/value dictionary. More...
 
virtual void set_params (const Dict &new_params)
 Set the Aligner parameters using a key/value dictionary. More...
 

Static Public Member Functions

static AlignerNEW ()
 

Static Public Attributes

static const string NAME = "rotate_translate_3d_grid"
 

Additional Inherited Members

- Protected Attributes inherited from EMAN::Aligner
Dict params
 

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
dazThe angle increment in the azimuth direction
lazLower bound for the azimuth direction
uazUpper bound for the azimuth direction
dphiThe angle increment in the phi direction
lphiLower bound for the phi direction
uphiUpper bound for the phi direction
daltThe angle increment in the altitude direction
laltLower bound for the altitude direction
ualtUpper bound for the altitude direction
dotransDo a translational search
searchThe 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
searchxThe maximum length of the detectable translational shift in the x direction- if you supply this parameter you can not supply the maxshift parameters
searchyThe maximum length of the detectable translational shift in the y direction- if you supply this parameter you can not supply the maxshift parameters
searchzThe maximum length of the detectable translational shift in the z direction- if you supply this parameter you can not supply the maxshift parameters
verboseTurn 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 1615 of file aligner.h.

Member Function Documentation

◆ align() [1/2]

virtual EMData * EMAN::RT3DGridAligner::align ( EMData this_img,
EMData to_img 
) const
inlinevirtual

See Aligner comments for more details.

Implements EMAN::Aligner.

Definition at line 1624 of file aligner.h.

1625 {
1626 return align(this_img, to_img, "ccc.tomo", Dict());
1627 }
virtual EMData * align(EMData *this_img, EMData *to_img, const string &cmp_name="ccc.tomo", const Dict &cmp_params=Dict()) const
See Aligner comments for more details.

References align().

◆ align() [2/2]

virtual EMData * EMAN::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.

Referenced by align().

◆ get_desc()

virtual string EMAN::RT3DGridAligner::get_desc ( ) const
inlinevirtual

Implements EMAN::Aligner.

Definition at line 1639 of file aligner.h.

1640 {
1641 return "3D rotational and translational alignment using specified ranges and maximum shifts";
1642 }

◆ get_name()

virtual string EMAN::RT3DGridAligner::get_name ( ) const
inlinevirtual

Get the Aligner's name.

Each Aligner is identified by a unique name.

Returns
The Aligner's name.

Implements EMAN::Aligner.

Definition at line 1634 of file aligner.h.

1635 {
1636 return NAME;
1637 }
static const string NAME
Definition: aligner.h:1671

References NAME.

◆ get_param_types()

virtual TypeDict EMAN::RT3DGridAligner::get_param_types ( ) const
inlinevirtual

Implements EMAN::Aligner.

Definition at line 1649 of file aligner.h.

1650 {
1651 TypeDict d;
1652 d.put("daz", EMObject::FLOAT,"The angle increment in the azimuth direction. Default is 10");
1653 d.put("az0", EMObject::FLOAT,"Lower bound for the azimuth direction. Default it 0");
1654 d.put("az1", EMObject::FLOAT,"Upper bound for the azimuth direction. Default it 180.0");
1655 d.put("dphi", EMObject::FLOAT,"The angle increment in the phi direction. Default is 10");
1656 d.put("phi0", EMObject::FLOAT,"Lower bound for the phi direction. Default it 0");
1657 d.put("phi1", EMObject::FLOAT,"Upper bound for the phi direction. Default it 360.0");
1658 d.put("dalt", EMObject::FLOAT,"The angle increment in the altitude direction. Default is 10");
1659 d.put("alt0", EMObject::FLOAT,"Lower bound for the altitude direction. Default it 0");
1660 d.put("alt1", EMObject::FLOAT,"Upper bound for the altitude direction. Default it 360.0");
1661 d.put("dotrans", EMObject::BOOL,"Do a translational search. Default is True(1)");
1662 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.");
1663 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.");
1664 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.");
1665 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");
1666 d.put("initxform", EMObject::TRANSFORM,"The Transform storing the starting position. If unspecified the identity matrix is used");
1667 d.put("verbose", EMObject::BOOL,"Turn this on to have useful information printed to standard out.");
1668 return d;
1669 }

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

◆ NEW()

static Aligner * EMAN::RT3DGridAligner::NEW ( )
inlinestatic

Definition at line 1644 of file aligner.h.

1645 {
1646 return new RT3DGridAligner();
1647 }

◆ xform_align_nbest()

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

2553 {
2554
2555 if ( this_img->get_ndim() != 3 || to->get_ndim() != 3 ) {
2556 throw ImageDimensionException("This aligner only works for 3D images");
2557 }
2558
2559 int searchx = 0;
2560 int searchy = 0;
2561 int searchz = 0;
2562
2563 bool dotrans = params.set_default("dotrans",1);
2564 if (params.has_key("search")) {
2565 vector<string> check;
2566 check.push_back("searchx");
2567 check.push_back("searchy");
2568 check.push_back("searchz");
2569 for(vector<string>::const_iterator cit = check.begin(); cit != check.end(); ++cit) {
2570 if (params.has_key(*cit)) throw InvalidParameterException("The search parameter is mutually exclusive of the searchx, searchy, and searchz parameters");
2571 }
2572 int search = params["search"];
2573 searchx = search;
2574 searchy = search;
2575 searchz = search;
2576 } else {
2577 searchx = params.set_default("searchx",3);
2578 searchy = params.set_default("searchy",3);
2579 searchz = params.set_default("searchz",3);
2580 }
2581
2582 Transform* initxform;
2583 if (params.has_key("initxform") ) {
2584 // Unlike the 2d refine aligner, this class doesn't require the starting transform's
2585 // parameters to form the starting guess. Instead the Transform itself
2586 // is perturbed carefully (using quaternion rotation) to overcome problems that arise
2587 // when you use orthogonally-based Euler angles
2588 initxform = params["initxform"];
2589 }else {
2590 initxform = new Transform(); // is the identity
2591 }
2592
2593 float lalt = params.set_default("alt0",0.0f);
2594 float laz = params.set_default("az0",0.0f);
2595 float lphi = params.set_default("phi0",0.0f);
2596 float ualt = params.set_default("alt1",180.0f); // I am using 179.9 rather than 180 to avoid resampling
2597 float uphi = params.set_default("phi1",360.0f); // I am using 359.9 rather than 180 to avoid resampling 0 = 360 (for perodic functions)
2598 float uaz = params.set_default("az1",360.0f); // I am using 359.9 rather than 180 to avoid resampling 0 = 360 (for perodic functions)
2599 float dalt = params.set_default("dalt",10.f);
2600 float daz = params.set_default("daz",10.f);
2601 float dphi = params.set_default("dphi",10.f);
2602 bool verbose = params.set_default("verbose",false);
2603
2604 //in case we arre aligning tomos
2605 Dict altered_cmp_params(cmp_params);
2606 if (cmp_name == "ccc.tomo") {
2607 altered_cmp_params.set_default("searchx", searchx);
2608 altered_cmp_params.set_default("searchy", searchy);
2609 altered_cmp_params.set_default("searchz", searchz);
2610 altered_cmp_params.set_default("norm", true);
2611 }
2612
2613 vector<Dict> solns;
2614 if (nsoln == 0) return solns; // What was the user thinking?
2615 for (unsigned int i = 0; i < nsoln; ++i ) {
2616 Dict d;
2617 d["score"] = 1.e24;
2618 Transform t; // identity by default
2619 d["xform.align3d"] = &t; // deep copy is going on here
2620 solns.push_back(d);
2621 }
2622
2623 bool tomography = (cmp_name == "ccc.tomo") ? 1 : 0;
2624 EMData * tofft = 0;
2625 if(dotrans || tomography){
2626 tofft = to->do_fft();
2627 }
2628
2629#ifdef EMAN2_USING_CUDA
2630 if(EMData::usecuda == 1) {
2631 if(!this_img->getcudarodata()) this_img->copy_to_cudaro(); // safer call
2632 if(!to->getcudarwdata()) to->copy_to_cuda();
2633 if(to->getcudarwdata()){if(tofft) tofft->copy_to_cuda();}
2634 }
2635#endif
2636
2637 Dict d;
2638 d["type"] = "eman"; // d is used in the loop below
2639 Transform trans = Transform();
2640 Cmp* c = Factory <Cmp>::get(cmp_name, cmp_params);
2641 bool use_cpu = true;
2642 for ( float alt = lalt; alt <= ualt; alt += dalt) {
2643 // An optimization for the range of az is made at the top of the sphere
2644 // If you think about it, this is just a coarse way of making this approach slightly more efficient
2645 for ( float az = laz; az < uaz; az += daz ){
2646 if (verbose) {
2647 cout << "Trying angle alt " << alt << " az " << az << endl;
2648 }
2649 for( float phi = lphi; phi < uphi; phi += dphi ) {
2650 d["alt"] = alt;
2651 d["phi"] = phi;
2652 d["az"] = az;
2653 Transform t(d);
2654 t = t*(*initxform);
2655 EMData* transformed = this_img->process("xform",Dict("transform",&t));
2656
2657 //need to do things a bit diffrent if we want to compare two tomos
2658 float best_score = 0.0f;
2659 if(dotrans || tomography){
2660 EMData* ccf = transformed->calc_ccf(tofft);
2661#ifdef EMAN2_USING_CUDA
2662 if(EMData::usecuda == 1){
2663 use_cpu = false;;
2664 CudaPeakInfo* data = calc_max_location_wrap_cuda(ccf->getcudarwdata(), ccf->get_xsize(), ccf->get_ysize(), ccf->get_zsize(), searchx, searchy, searchz);
2665 trans.set_trans((float)-data->px, (float)-data->py, (float)-data->pz);
2666 t = trans*t; //composite transfrom to reflect the fact that we have done a rotation first and THEN a transformation
2667 if (tomography) {
2668 float2 stats = get_stats_cuda(ccf->getcudarwdata(), ccf->get_xsize(), ccf->get_ysize(), ccf->get_zsize());
2669 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
2670 } else {
2671 best_score = -data->peak;
2672 }
2673 delete data;
2674 }
2675#endif
2676 if(use_cpu){
2677 if(tomography) ccf->process_inplace("normalize");
2678 IntPoint point = ccf->calc_max_location_wrap(searchx,searchy,searchz);
2679 trans.set_trans((float)-point[0], (float)-point[1], (float)-point[2]);
2680 t = trans*t; //composite transfrom to reflect the fact that we have done a rotation first and THEN a transformation
2681 best_score = -ccf->get_value_at_wrap(point[0], point[1], point[2]);
2682 }
2683 delete ccf; ccf =0;
2684 delete transformed; transformed = 0;
2685 }
2686
2687 if(!tomography){
2688 if(!transformed) transformed = this_img->process("xform",Dict("transform",&t));
2689 best_score = c->cmp(to,transformed);
2690 delete transformed; transformed = 0;
2691 }
2692
2693 unsigned int j = 0;
2694 for ( vector<Dict>::iterator it = solns.begin(); it != solns.end(); ++it, ++j ) {
2695 if ( (float)(*it)["score"] > best_score ) { // Note greater than - EMAN2 preferes minimums as a matter of policy
2696 vector<Dict>::reverse_iterator rit = solns.rbegin();
2697 copy(rit+1,solns.rend()-j,rit);
2698 Dict& d = (*it);
2699 d["score"] = best_score;
2700 d["xform.align3d"] = &t;
2701 break;
2702 }
2703 }
2704 }
2705 }
2706 }
2707
2708 if(tofft) {delete tofft; tofft = 0;}
2709 if (c != 0) delete c;
2710
2711 return solns;
2712
2713}
Dict params
Definition: aligner.h:147
Cmp class defines image comparison method.
Definition: cmp.h:82
virtual float cmp(EMData *image, EMData *with) const =0
To compare 'image' with another image passed in through its parameters.
Dict is a dictionary to store <string, EMObject> pair.
Definition: emobject.h:385
type set_default(const string &key, type val)
Default setting behavior This can be achieved using a template - d.woolford Jan 2008 (before there wa...
Definition: emobject.h:569
bool has_key(const string &key) const
Ask the Dictionary if it as a particular key.
Definition: emobject.h:511
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
Factory is used to store objects to create new instances.
Definition: emobject.h:725
IntPoint defines an integer-coordinate point in a 1D/2D/3D space.
Definition: geometry.h:192
A Transform object is a somewhat specialized object designed specifically for EMAN2/Sparx storage of ...
Definition: transform.h:75
void set_trans(const float &x, const float &y, const float &z=0)
Set the post translation component.
Definition: transform.cpp:1036
float2 get_stats_cuda(const float *data, const int nx, const int ny, const int nz)
CudaPeakInfo * calc_max_location_wrap_cuda(const float *in, const int nx, const int ny, const int nz, const int maxdx, const int maxdy, const int maxdz)
EMData * copy() const
This file is a part of "emdata.h", to use functions in this file, you should "#include "emdata....
EMData * sqrt() const
return square root of current image
#define InvalidParameterException(desc)
Definition: exception.h:361
#define ImageDimensionException(desc)
Definition: exception.h:166
EMData * calc_ccf(EMData *with=0, fp_flag fpflag=CIRCULANT, bool center=false)
Calculate Cross-Correlation Function (CCF).
Definition: emdata.cpp:1499
float peak
Definition: cuda_util.h:29

References EMAN::EMData::calc_ccf(), calc_max_location_wrap_cuda(), EMAN::Cmp::cmp(), copy(), get_stats_cuda(), EMAN::Dict::has_key(), ImageDimensionException, InvalidParameterException, EMAN::Aligner::params, CudaPeakInfo::peak, CudaPeakInfo::px, CudaPeakInfo::py, CudaPeakInfo::pz, EMAN::Dict::set_default(), EMAN::Transform::set_trans(), and sqrt().

Member Data Documentation

◆ NAME

const string RT3DGridAligner::NAME = "rotate_translate_3d_grid"
static

Definition at line 1671 of file aligner.h.

Referenced by get_name().


The documentation for this class was generated from the following files: