EMAN2
Macros | Functions
aligner.cpp File Reference
#include <random>
#include "emfft.h"
#include "cmp.h"
#include "aligner.h"
#include "averager.h"
#include "emdata.h"
#include "processor.h"
#include "util.h"
#include "symmetry.h"
#include <gsl/gsl_multimin.h>
#include "plugins/aligner_template.h"
Include dependency graph for aligner.cpp:

Go to the source code of this file.

Macros

#define EMAN2_ALIGNER_DEBUG   0
 

Functions

static double refalifn (const gsl_vector *v, void *params)
 
static void refalidf (const gsl_vector *v, void *params, gsl_vector *df)
 
static void refalifdf (const gsl_vector *v, void *params, double *f, gsl_vector *df)
 
static double refalifnfast (const gsl_vector *v, void *params)
 
static Transform refalin3d_perturbquat (const Transform *const t, const float &spincoeff, const float &n0, const float &n1, const float &n2, const float &x, const float &y, const float &z)
 
static double symquat (const gsl_vector *v, void *params)
 
static double refalifn3dquat (const gsl_vector *v, void *params)
 

Macro Definition Documentation

◆ EMAN2_ALIGNER_DEBUG

#define EMAN2_ALIGNER_DEBUG   0

Definition at line 53 of file aligner.cpp.

Function Documentation

◆ refalidf()

static void refalidf ( const gsl_vector *  v,
void *  params,
gsl_vector *  df 
)
static

Definition at line 1720 of file aligner.cpp.

1720 {
1721 // we do this using a simple local difference estimate due to the expense of the calculation.
1722 // The step has to be large enough for the similarity metric
1723 // To provide an accurate change in value.
1724 static double lstep[4] = { 0.05, 0.05, 0.1, 0.01 };
1725
1726 gsl_vector *vc = gsl_vector_alloc(v->size);
1727 gsl_vector_memcpy(vc,v);
1728
1729 double f = refalifn(v,params);
1730 for (unsigned int i=0; i<v->size; i++) {
1731 // double *vp = gsl_vector_ptr(vc,i);
1732 double vp = gsl_vector_get(vc,i);
1733 // *vp+=lstep[i];
1734 gsl_vector_set(vc,i,vp+lstep[i]);
1735 double f2 = refalifn(vc,params);
1736 // *vp-=lstep[i];
1737 gsl_vector_set(vc,i,vp);
1738
1739 gsl_vector_set(df,i,(f2-f)/lstep[i]);
1740 }
1741
1742 gsl_vector_free(vc);
1743 return;
1744}
static double refalifn(const gsl_vector *v, void *params)
Definition: aligner.cpp:1688
vector< pair< float, int > > vp

References refalifn().

◆ refalifdf()

static void refalifdf ( const gsl_vector *  v,
void *  params,
double *  f,
gsl_vector *  df 
)
static

Definition at line 1746 of file aligner.cpp.

1746 {
1747 // we do this using a simple local difference estimate due to the expense of the calculation.
1748 // The step has to be large enough for the similarity metric
1749 // To provide an accurate change in value.
1750 static double lstep[4] = { 0.05, 0.05, 0.1, 0.01 };
1751
1752 gsl_vector *vc = gsl_vector_alloc(v->size);
1753 gsl_vector_memcpy(vc,v);
1754
1755 *f = refalifn(v,params);
1756 for (unsigned int i=0; i<v->size; i++) {
1757 // double *vp = gsl_vector_ptr(vc,i);
1758 double vp = gsl_vector_get(vc,i);
1759 // *vp+=lstep[i];
1760 gsl_vector_set(vc,i,vp+lstep[i]);
1761 double f2 = refalifn(vc,params);
1762 // *vp-=lstep[i];
1763 gsl_vector_set(vc,i,vp);
1764
1765 gsl_vector_set(df,i,(f2-*f)/lstep[i]);
1766 }
1767
1768 gsl_vector_free(vc);
1769 return;
1770}

References refalifn().

◆ refalifn()

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

Definition at line 1688 of file aligner.cpp.

1689{
1690 Dict *dict = (Dict *) params;
1691
1692 double x = gsl_vector_get(v, 0);
1693 double y = gsl_vector_get(v, 1);
1694 double a = gsl_vector_get(v, 2);
1695
1696 EMData *this_img = (*dict)["this"];
1697 EMData *with = (*dict)["with"];
1698 bool mirror = (*dict)["mirror"];
1699
1700 Transform t(Dict("type","2d","alpha",static_cast<float>(a)));
1701 t.set_trans((float)x,(float)y);
1702 t.set_mirror(mirror);
1703 if (v->size>3) {
1704 float sca=(float)gsl_vector_get(v, 3);
1705 if (sca<.7 || sca>1.3) return 1.0e20;
1706 t.set_scale((float)gsl_vector_get(v, 3));
1707 }
1708 EMData *tmp = this_img->process("xform",Dict("transform",&t));
1709 if (dict->has_key("mask")) tmp->mult(*(EMData *)((*dict)["mask"]));
1710
1711// printf("GSL %f %f %f %d %f\n",x,y,a,mirror,(float)gsl_vector_get(v, 3));
1712 Cmp* c = (Cmp*) ((void*)(*dict)["cmp"]);
1713 double result = c->cmp(tmp,with);
1714
1715 if (tmp != 0) delete tmp;
1716
1717 return result;
1718}
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
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
A Transform object is a somewhat specialized object designed specifically for EMAN2/Sparx storage of ...
Definition: transform.h:75
#define y(i, j)
Definition: projector.cpp:1516
#define x(i)
Definition: projector.cpp:1517

References EMAN::Cmp::cmp(), EMAN::Dict::has_key(), EMAN::Transform::set_mirror(), EMAN::Transform::set_scale(), EMAN::Transform::set_trans(), x, and y.

Referenced by refalidf(), and refalifdf().

◆ refalifn3dquat()

static double refalifn3dquat ( const gsl_vector *  v,
void *  params 
)
static

Definition at line 2104 of file aligner.cpp.

2105{
2106 Dict *dict = (Dict *) params;
2107
2108 double n0 = gsl_vector_get(v, 0);
2109 double n1 = gsl_vector_get(v, 1);
2110 double n2 = gsl_vector_get(v, 2);
2111 double x = gsl_vector_get(v, 3);
2112 double y = gsl_vector_get(v, 4);
2113 double z = gsl_vector_get(v, 5);
2114
2115 EMData *this_img = (*dict)["this"];
2116 EMData *with = (*dict)["with"];
2117
2118 Transform* t = (*dict)["transform"];
2119 float spincoeff = (*dict)["spincoeff"];
2120
2121 Transform soln = refalin3d_perturbquat(t,spincoeff,(float)n0,(float)n1,(float)n2,(float)x,(float)y,(float)z);
2122
2123 EMData *tmp = this_img->process("xform",Dict("transform",&soln));
2124 Cmp* c = (Cmp*) ((void*)(*dict)["cmp"]);
2125 double result = c->cmp(tmp,with);
2126 if ( tmp != 0 ) delete tmp;
2127
2128 //cout << result << endl;
2129 return result;
2130}
static Transform refalin3d_perturbquat(const Transform *const t, const float &spincoeff, const float &n0, const float &n1, const float &n2, const float &x, const float &y, const float &z)
Definition: aligner.cpp:2054

References EMAN::Cmp::cmp(), refalin3d_perturbquat(), x, and y.

◆ refalifnfast()

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

Definition at line 1772 of file aligner.cpp.

1773{
1774 Dict *dict = (Dict *) params;
1775 EMData *this_img = (*dict)["this"];
1776 EMData *img_to = (*dict)["with"];
1777 bool mirror = (*dict)["mirror"];
1778
1779 double x = gsl_vector_get(v, 0);
1780 double y = gsl_vector_get(v, 1);
1781 double a = gsl_vector_get(v, 2);
1782
1783 double r = this_img->dot_rotate_translate(img_to, (float)x, (float)y, (float)a, mirror);
1784 int nsec = this_img->get_xsize() * this_img->get_ysize();
1785 double result = 1.0 - r / nsec;
1786
1787// cout << result << " x " << x << " y " << y << " az " << a << endl;
1788 return result;
1789}
double dot_rotate_translate(EMData *with, float dx, float dy, float da, const bool mirror=false)
dot product of 2 images.
Definition: emdata.cpp:1239

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

◆ refalin3d_perturbquat()

static Transform refalin3d_perturbquat ( const Transform *const  t,
const float &  spincoeff,
const float &  n0,
const float &  n1,
const float &  n2,
const float &  x,
const float &  y,
const float &  z 
)
static

Definition at line 2054 of file aligner.cpp.

2055{
2056 Vec3f normal(n0,n1,n2);
2057 normal.normalize();
2058
2059 float omega = spincoeff*sqrt(n0*n0 + n1*n1 + n2*n2); // Here we compute the spin by the rotation axis vector length
2060 Dict d;
2061 d["type"] = "spin";
2062 d["omega"] = omega;
2063 d["n1"] = normal[0];
2064 d["n2"] = normal[1];
2065 d["n3"] = normal[2];
2066 //cout << omega << " " << normal[0] << " " << normal[1] << " " << normal[2] << " " << n0 << " " << n1 << " " << n2 << endl;
2067
2068 Transform q(d);
2069 q.set_trans((float)x,(float)y,(float)z);
2070
2071 q = q*(*t); //compose transforms
2072
2073 return q;
2074}
EMData * sqrt() const
return square root of current image

References EMAN::Vec3< Type >::normalize(), EMAN::Transform::set_trans(), sqrt(), x, and y.

Referenced by refalifn3dquat(), and symquat().

◆ symquat()

static double symquat ( const gsl_vector *  v,
void *  params 
)
static

Definition at line 2076 of file aligner.cpp.

2077{
2078 Dict *dict = (Dict *) params;
2079
2080 double n0 = gsl_vector_get(v, 0);
2081 double n1 = gsl_vector_get(v, 1);
2082 double n2 = gsl_vector_get(v, 2);
2083 double x = gsl_vector_get(v, 3);
2084 double y = gsl_vector_get(v, 4);
2085 double z = gsl_vector_get(v, 5);
2086
2087 EMData* volume = (*dict)["volume"];
2088 float spincoeff = (*dict)["spincoeff"];
2089 Transform* t = (*dict)["transform"];
2090
2091 Transform soln = refalin3d_perturbquat(t,spincoeff,(float)n0,(float)n1,(float)n2,(float)x,(float)y,(float)z);
2092
2093 EMData *tmp = volume->process("xform",Dict("transform",&soln));
2094 EMData *symtmp = tmp->process("xform.applysym",Dict("sym",(*dict)["sym"]));
2095 Cmp* c = (Cmp*) ((void*)(*dict)["cmp"]);
2096 double result = c->cmp(symtmp,tmp);
2097 delete tmp;
2098 delete symtmp;
2099
2100 //cout << result << endl;
2101 return result;
2102}

References EMAN::Cmp::cmp(), refalin3d_perturbquat(), x, and y.