#include <aligner.h>
Inheritance diagram for EMAN::SymAlignProcessorQuat:
Public Member Functions | |
virtual EMData * | align (EMData *this_img, EMData *to_img, const string &cmp_name="ccc", const Dict &cmp_params=Dict()) const |
To align 'this_img' with another image passed in through its parameters. | |
virtual EMData * | align (EMData *this_img, EMData *to_img) const |
virtual string | get_name () const |
Get the Aligner's name. | |
string | get_desc () const |
virtual TypeDict | get_param_types () const |
Static Public Member Functions | |
static Aligner * | NEW () |
Static Public Attributes | |
static const string | NAME = "symalignquat" |
sym | The symmetry of the particle in question | |
xform.align3d | The initial guess to align the paricle to its symmetry axis |
Definition at line 1329 of file aligner.h.
virtual EMData* EMAN::SymAlignProcessorQuat::align | ( | EMData * | this_img, | |
EMData * | to_img | |||
) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 1335 of file aligner.h.
References align().
01336 { 01337 return align(this_img, to_img, "ccc", Dict()); 01338 }
EMData * SymAlignProcessorQuat::align | ( | EMData * | this_img, | |
EMData * | to_img, | |||
const string & | cmp_name = "ccc" , |
|||
const Dict & | cmp_params = Dict() | |||
) | const [virtual] |
To align 'this_img' with another image passed in through its parameters.
The alignment uses a user-given comparison method to compare the two images. If none is given, a default one is used.
this_img | The image to be compared. | |
to_img | 'this_img" is aligned with 'to_img'. | |
cmp_name | The comparison method to compare the two images. | |
cmp_params | The parameter dictionary for comparison method. |
Implements EMAN::Aligner.
Definition at line 2024 of file aligner.cpp.
References EMAN::EMData::get_xsize(), EMAN::Dict::has_key(), EMAN::Aligner::params, EMAN::EMData::process(), refalin3d_perturbquat(), EMAN::EMData::set_attr(), EMAN::Dict::set_default(), status, symquat(), t, x, and y.
Referenced by align().
02025 { 02026 //Get pretransform 02027 Transform* t; 02028 if (params.has_key("xform.align3d") ) { 02029 t = params["xform.align3d"]; 02030 }else { 02031 t = new Transform(); // is the identity 02032 } 02033 02034 float sdi = 0.0; 02035 float sdj = 0.0; 02036 float sdk = 0.0; 02037 float sdx = 0.0; 02038 float sdy = 0.0; 02039 float sdz = 0.0; 02040 02041 float spincoeff = params.set_default("spin_coeff",10.0f); // spin coefficient, controls speed of convergence (sort of) 02042 02043 int np = 6; // the number of dimensions 02044 Dict gsl_params; 02045 gsl_params["volume"] = volume; 02046 gsl_params["transform"] = t; 02047 gsl_params["sym"] = params.set_default("sym","c1"); 02048 gsl_params["spincoeff"] = spincoeff; 02049 02050 const gsl_multimin_fminimizer_type *T = gsl_multimin_fminimizer_nmsimplex; 02051 gsl_vector *ss = gsl_vector_alloc(np); 02052 02053 float stepi = params.set_default("stepn0",1.0f); // doesn't really matter b/c the vecor part will be normalized anyway 02054 float stepj = params.set_default("stepn1",1.0f); // doesn't really matter b/c the vecor part will be normalized anyway 02055 float stepk = params.set_default("stepn2",1.0f); // doesn't really matter b/c the vecor part will be normalized anyway 02056 float stepx = params.set_default("stepx",1.0f); 02057 float stepy = params.set_default("stepy",1.0f); 02058 float stepz = params.set_default("stepz",1.0f); 02059 02060 gsl_vector_set(ss, 0, stepi); 02061 gsl_vector_set(ss, 1, stepj); 02062 gsl_vector_set(ss, 2, stepk); 02063 gsl_vector_set(ss, 3, stepx); 02064 gsl_vector_set(ss, 4, stepy); 02065 gsl_vector_set(ss, 5, stepz); 02066 02067 gsl_vector *x = gsl_vector_alloc(np); 02068 gsl_vector_set(x, 0, sdi); 02069 gsl_vector_set(x, 1, sdj); 02070 gsl_vector_set(x, 2, sdk); 02071 gsl_vector_set(x, 3, sdx); 02072 gsl_vector_set(x, 4, sdy); 02073 gsl_vector_set(x, 5, sdz); 02074 02075 gsl_multimin_function minex_func; 02076 Cmp *c = Factory < Cmp >::get(cmp_name, cmp_params); 02077 gsl_params["cmp"] = (void *) c; 02078 minex_func.f = &symquat; 02079 minex_func.n = np; 02080 minex_func.params = (void *) &gsl_params; 02081 gsl_multimin_fminimizer *s = gsl_multimin_fminimizer_alloc(T, np); 02082 gsl_multimin_fminimizer_set(s, &minex_func, x, ss); 02083 02084 int rval = GSL_CONTINUE; 02085 int status = GSL_SUCCESS; 02086 int iter = 1; 02087 02088 float precision = params.set_default("precision",0.01f); 02089 int maxiter = params.set_default("maxiter",100); 02090 while (rval == GSL_CONTINUE && iter < maxiter) { 02091 iter++; 02092 status = gsl_multimin_fminimizer_iterate(s); 02093 if (status) { 02094 break; 02095 } 02096 rval = gsl_multimin_test_size(gsl_multimin_fminimizer_size(s), precision); 02097 } 02098 02099 int maxshift = params.set_default("maxshift",-1); 02100 02101 if (maxshift <= 0) { 02102 maxshift = volume->get_xsize() / 4; 02103 } 02104 float fmaxshift = static_cast<float>(maxshift); 02105 02106 EMData *result; 02107 if ( fmaxshift >= (float)gsl_vector_get(s->x, 0) && fmaxshift >= (float)gsl_vector_get(s->x, 1) && fmaxshift >= (float)gsl_vector_get(s->x, 2)) 02108 { 02109 float n0 = (float)gsl_vector_get(s->x, 0); 02110 float n1 = (float)gsl_vector_get(s->x, 1); 02111 float n2 = (float)gsl_vector_get(s->x, 2); 02112 float x = (float)gsl_vector_get(s->x, 3); 02113 float y = (float)gsl_vector_get(s->x, 4); 02114 float z = (float)gsl_vector_get(s->x, 5); 02115 02116 Transform tsoln = refalin3d_perturbquat(t,spincoeff,n0,n1,n2,x,y,z); 02117 02118 result = volume->process("xform",Dict("transform",&tsoln)); 02119 result->set_attr("xform.align3d",&tsoln); 02120 EMData *tmpsym = result->process("xform.applysym",Dict("sym",gsl_params["sym"])); 02121 result->set_attr("score", result->cmp(cmp_name,tmpsym,cmp_params)); 02122 delete tmpsym; 02123 } else { // The refine aligner failed - this shift went beyond the max shift 02124 result = volume->process("xform",Dict("transform",t)); 02125 result->set_attr("xform.align3d",t); 02126 result->set_attr("score",0.0); 02127 } 02128 02129 gsl_vector_free(x); 02130 gsl_vector_free(ss); 02131 gsl_multimin_fminimizer_free(s); 02132 02133 if (c != 0) delete c; 02134 delete t; 02135 02136 return result; 02137 }
string EMAN::SymAlignProcessorQuat::get_desc | ( | ) | const [inline, virtual] |
virtual string EMAN::SymAlignProcessorQuat::get_name | ( | ) | const [inline, virtual] |
virtual TypeDict EMAN::SymAlignProcessorQuat::get_param_types | ( | ) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 1352 of file aligner.h.
References EMAN::EMObject::FLOAT, EMAN::EMObject::INT, EMAN::TypeDict::put(), EMAN::EMObject::STRING, and EMAN::EMObject::TRANSFORM.
01353 { 01354 TypeDict d; 01355 d.put("sym", EMObject::STRING, "The symmettry. Default is c1"); 01356 d.put("xform.align3d", EMObject::TRANSFORM, "The initial guess for to align the particel to sym axis"); 01357 d.put("stepx", EMObject::FLOAT, "The initial simplex step size in x. Default is 1"); 01358 d.put("stepy", EMObject::FLOAT, "The initial simplex step size in y. Default is 1"); 01359 d.put("stepz", EMObject::FLOAT, "The initial simplex step size in z. Default is 1." ); 01360 d.put("stepn0", EMObject::FLOAT, "The initial simplex step size in the first quaternion vecotr component. Default is 1." ); 01361 d.put("stepn1", EMObject::FLOAT, "The initial simplex step size in the second quaternion vecotr component. Default is 1." ); 01362 d.put("stepn2", EMObject::FLOAT, "The initial simplex step size in the third quaternion vecotr component. Default is 1." ); 01363 d.put("spin_coeff", EMObject::FLOAT,"The multiplier appied to the spin (if it is too small or too large the simplex will not converge). Default is 10."); 01364 d.put("precision", EMObject::FLOAT, "The precision which, if achieved, can stop the iterative refinement before reaching the maximum iterations. Default is 0.01." ); 01365 d.put("maxiter", EMObject::INT, "The maximum number of iterations that can be performed by the Simplex minimizer. Default is 100."); 01366 d.put("maxshift", EMObject::INT,"Maximum translation in pixels in any direction. If the solution yields a shift beyond this value in any direction, then the refinement is judged a failure and the original alignment is used as the solution."); 01367 return d; 01368 }
static Aligner* EMAN::SymAlignProcessorQuat::NEW | ( | ) | [inline, static] |
const string SymAlignProcessorQuat::NAME = "symalignquat" [static] |