aligner.cpp File Reference

#include "cmp.h"
#include "aligner.h"
#include "emdata.h"
#include "processor.h"
#include "util.h"
#include "symmetry.h"
#include <gsl/gsl_multimin.h>

Include dependency graph for aligner.cpp:

Go to the source code of this file.

Defines

#define EMAN2_ALIGNER_DEBUG   0
 
Id
aligner.cpp,v 1.151 2009/11/19 20:56:07 zyang Exp


Functions

static double refalifn (const gsl_vector *v, void *params)
static double refalifnfast (const gsl_vector *v, void *params)
static Transform refalin3d_perturb (const Transform *const t, const float &delta, const float &arc, const float &phi, const float &x, const float &y, const float &z)
static double refalifn3d (const gsl_vector *v, void *params)
void EMAN::dump_aligners ()
map< string, vector< string > > EMAN::dump_aligners_list ()


Define Documentation

#define EMAN2_ALIGNER_DEBUG   0

Id
aligner.cpp,v 1.151 2009/11/19 20:56:07 zyang Exp

Definition at line 48 of file aligner.cpp.


Function Documentation

static double refalifn ( const gsl_vector *  v,
void *  params 
) [static]

Definition at line 924 of file aligner.cpp.

References EMAN::Cmp::cmp(), EMAN::EMData::process(), EMAN::Transform::set_mirror(), EMAN::Transform::set_trans(), t, x, and y.

Referenced by EMAN::RefineAligner::align().

00925 {
00926         Dict *dict = (Dict *) params;
00927 
00928         double x = gsl_vector_get(v, 0);
00929         double y = gsl_vector_get(v, 1);
00930         double a = gsl_vector_get(v, 2);
00931 
00932         EMData *this_img = (*dict)["this"];
00933         EMData *with = (*dict)["with"];
00934         bool mirror = (*dict)["mirror"];
00935 
00936 //      float mean = (float)this_img->get_attr("mean");
00937 //      if ( Util::goodf(&mean) ) {
00938 //              //cout << "tmps mean is nan even before rotation" << endl;
00939 //      }
00940 
00941         Transform t(Dict("type","2d","alpha",static_cast<float>(a)));
00942 //      Transform3D t3d(Transform3D::EMAN, (float)a, 0.0f, 0.0f);
00943 //      t3d.set_posttrans( (float) x, (float) y);
00944 //      tmp->rotate_translate(t3d);
00945         t.set_trans((float)x,(float)y);
00946         t.set_mirror(mirror);
00947         EMData *tmp = this_img->process("math.transform",Dict("transform",&t));
00948 
00949         Cmp* c = (Cmp*) ((void*)(*dict)["cmp"]);
00950         double result = c->cmp(tmp,with);
00951 
00952         // DELETE AT SOME STAGE, USEFUL FOR PRERELEASE STUFF
00953         //      float test_result = (float)result;
00954 //      if ( Util::goodf(&test_result) ) {
00955 //              cout << "result " << result << " " << x << " " << y << " " << a << endl;
00956 //              cout << (float)this_img->get_attr("mean") << " " << (float)tmp->get_attr("mean") << " " << (float)with->get_attr("mean") << endl;
00957 //              tmp->write_image("tmp.hdf");
00958 //              with->write_image("with.hdf");
00959 //              this_img->write_image("this_img.hdf");
00960 //              EMData* t = this_img->copy();
00961 //              cout << (float)t->get_attr("mean") << endl;
00962 //              t->rotate_translate( t3d );
00963 //              cout << (float)t->get_attr("mean") << endl;
00964 //              cout << "exit" << endl;
00966 //              cout << (float)t->get_attr("mean") << endl;
00967 //              cout << "now exit" << endl;
00968 //              delete t;
00969 //      }
00970 
00971 
00972         if ( tmp != 0 ) delete tmp;
00973 
00974         return result;
00975 }

static double refalifn3d ( const gsl_vector *  v,
void *  params 
) [static]

Definition at line 1173 of file aligner.cpp.

References EMAN::Cmp::cmp(), phi, EMAN::EMData::process(), refalin3d_perturb(), t, x, and y.

Referenced by EMAN::Refine3DAligner::align().

01174 {
01175         Dict *dict = (Dict *) params;
01176         double x = gsl_vector_get(v, 0);
01177         double y = gsl_vector_get(v, 1);
01178         double z = gsl_vector_get(v, 2);
01179         double arc = gsl_vector_get(v, 3);
01180         double delta = gsl_vector_get(v, 4);
01181         double phi = gsl_vector_get(v, 5);
01182         EMData *this_img = (*dict)["this"];
01183         EMData *with = (*dict)["with"];
01184 //      bool mirror = (*dict)["mirror"];
01185 
01186         Transform* t = (*dict)["transform"];
01187 
01188         Transform soln = refalin3d_perturb(t,(float)delta,(float)arc,(float)phi,(float)x,(float)y,(float)z);
01189 
01190         EMData *tmp = this_img->process("math.transform",Dict("transform",&soln));
01191         Cmp* c = (Cmp*) ((void*)(*dict)["cmp"]);
01192         double result = c->cmp(tmp,with);
01193         if ( tmp != 0 ) delete tmp;
01194         delete t; t = 0;
01195 //      cout << result << " " << az << " " << alt << " " << phi << " " << x << " " << y << " " << z << endl;
01196         return result;
01197 }

static double refalifnfast ( const gsl_vector *  v,
void *  params 
) [static]

Definition at line 977 of file aligner.cpp.

References EMAN::EMData::dot_rotate_translate(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), x, and y.

Referenced by EMAN::RefineAligner::align().

00978 {
00979         Dict *dict = (Dict *) params;
00980         EMData *this_img = (*dict)["this"];
00981         EMData *img_to = (*dict)["with"];
00982         bool mirror = (*dict)["mirror"];
00983 
00984         double x = gsl_vector_get(v, 0);
00985         double y = gsl_vector_get(v, 1);
00986         double a = gsl_vector_get(v, 2);
00987 
00988         double r = this_img->dot_rotate_translate(img_to, (float)x, (float)y, (float)a, mirror);
00989         int nsec = this_img->get_xsize() * this_img->get_ysize();
00990         double result = 1.0 - r / nsec;
00991 
00992 //      cout << result << " x " << x << " y " << y << " az " << a <<  endl;
00993         return result;
00994 }

static Transform refalin3d_perturb ( const Transform *const   t,
const float &  delta,
const float &  arc,
const float &  phi,
const float &  x,
const float &  y,
const float &  z 
) [static]

Definition at line 1118 of file aligner.cpp.

References EMAN::Transform::get_params(), EMAN::Vec3< Type >::normalize(), EMAN::Aligner::params, q, EMAN::Transform::set_trans(), and EMAN::Transform::transpose().

Referenced by EMAN::Refine3DAligner::align(), and refalifn3d().

01119 {
01120         Dict orig_params = t->get_params("eman");
01121         float orig_phi = orig_params["phi"];
01122         float orig_x = orig_params["tx"];
01123         float orig_y = orig_params["ty"];
01124         float orig_z = orig_params["tz"];
01125         orig_params["phi"] = 0;
01126         orig_params["tx"] = 0;
01127         orig_params["ty"] = 0;
01128         orig_params["tz"] = 0;
01129         Transform t_no_phi(orig_params);
01130 
01131         Vec3f zz(0,0,1);
01132 
01133         Vec3f vv  = t_no_phi.transpose()*zz;
01134         Vec3f normal = Vec3f(-vv[2],0,-vv[0]);
01135 
01136         normal.normalize();
01137 
01138         Dict d;
01139         d["type"] = "spin";
01140         d["Omega"] = arc;
01141         d["n1"] = vv[0];
01142         d["n2"] = vv[1];
01143         d["n3"] = vv[2];
01144 
01145         Transform q(d);
01146 
01147         Vec3f  rot_vec = q*normal;
01148         rot_vec.normalize();
01149 
01150         Dict e;
01151         e["type"] = "spin";
01152         e["Omega"] = delta;
01153         e["n1"] = rot_vec[0];
01154         e["n2"] = rot_vec[1];
01155         e["n3"] = rot_vec[2];
01156 
01157         Transform perturb(e);
01158 
01159         Dict g;
01160         g["type"] = "eman";
01161         g["alt"] = 0;
01162         g["az"] = 0;
01163         g["phi"] = 0*phi+orig_phi;
01164 
01165         Transform phi_rot(g);
01166         Transform soln = t_no_phi*perturb*phi_rot;
01167         soln.set_trans(x+orig_x,y+orig_y,z+orig_z);
01168 
01169         Dict params = soln.get_params("eman");
01170         return soln;
01171 }


Generated on Fri Nov 20 02:19:10 2009 for EMAN2 by  doxygen 1.5.6