3911 int nsoln = nrsoln*2;
3912 if (nrsoln<32) nsoln=64;
3921 if (this_img->is_complex()) {
3922 base_to=this_img->copy();
3923 EMData *tmp = base_to->do_ift();
3924 tmp->process_inplace(
"threshold.notzero");
3925 base_mask=tmp->do_fft();
3929 base_to=this_img->do_fft();
3930 base_to->process_inplace(
"xform.phaseorigin.tocorner");
3931 EMData *tmp = this_img->process(
"threshold.notzero");
3932 base_mask=tmp->do_fft();
3936 if (to->is_complex()) {
3937 base_this=to->copy();
3938 EMData *tmp = base_this->do_ift();
3939 tmp->process_inplace(
"math.squared");
3940 base_thissq = tmp->do_fft();
3944 base_this=to->do_fft();
3945 base_this->process_inplace(
"xform.phaseorigin.tocorner");
3946 EMData *tmp = base_this->process(
"math.squared");
3947 base_thissq = tmp->do_fft();
3956 if (base_this->get_xsize()!=base_this->get_ysize()+2 || base_this->get_ysize()!=base_this->get_zsize()
3957 || base_to->get_xsize()!=base_to->get_ysize()+2 || base_to->get_ysize()!=base_to->get_zsize())
throw InvalidCallException(
"ERROR (RT3DTreeAligner): requires cubic images with even numbered box sizes");
3963 base_this->process_inplace(
"xform.fourierorigin.tocenter");
3964 base_to->process_inplace(
"xform.fourierorigin.tocenter");
3965 base_thissq->process_inplace(
"xform.fourierorigin.tocenter");
3966 base_mask->process_inplace(
"xform.fourierorigin.tocenter");
3968 float apix=(float)this_img->get_attr(
"apix_x");
3969 int ny=this_img->get_ysize();
3975 maxny=4*int(ny*apix/maxres/2+1);
3977 printf(
"\n\n*******\nmax resolution %1.2f, box size %d\n", maxres, maxny);
3984 vector<float> s_score(nsoln,0.0f);
3985 vector<float> s_coverage(nsoln,0.0f);
3986 vector<float> s_step(nsoln*3,7.5f);
3987 vector<Transform> s_xform(nsoln);
3988 if (verbose>0) printf(
"%d solutions\n",nsoln);
3994 const vector< Transform > xfs=
params[
"initxform"];
3997 for (
unsigned int i=0; i<nsoln; i++){
3998 s_xform[i].set_params(xfs[i].
get_params(
"eman"));
4009 string axname[] = {
"az",
"alt",
"phi"};
4012 for (
int sexp=sexp_start; sexp<10; sexp++) {
4015 int ss=pow(2.0,sexp);
4016 if (ss>maxny) ss=maxny;
4018 else if (ss<48) ss=48;
4019 if (verbose>0) printf(
"\nSize %d\n",ss);
4021 int maxshift=maxshift00*ss/ny;
4022 if (maxshift00<0) maxshift=-1;
4026 EMData *small_to= base_to-> get_clip(
Region(0,(ny-ss)/2,(ny-ss)/2,ss+2,ss,ss));
4028 EMData *small_mask= base_mask-> get_clip(
Region(0,(ny-ss)/2,(ny-ss)/2,ss+2,ss,ss));
4029 small_this->process_inplace(
"xform.fourierorigin.tocorner");
4030 small_this->process_inplace(
"filter.highpass.gauss",
Dict(
"cutoff_pixels",4));
4031 small_to->process_inplace(
"xform.fourierorigin.tocorner");
4032 small_to->process_inplace(
"filter.highpass.gauss",
Dict(
"cutoff_pixels",4));
4033 small_mask->process_inplace(
"xform.fourierorigin.tocorner");
4034 small_mask->process_inplace(
"filter.highpass.gauss",
Dict(
"cutoff_pixels",4));
4035 small_thissq->process_inplace(
"xform.fourierorigin.tocorner");
4036 small_thissq->process_inplace(
"filter.highpass.gauss",
Dict(
"cutoff_pixels",4));
4040 small_this->process_inplace(
"filter.lowpass.gauss",
Dict(
"cutoff_abs",0.33f));
4041 small_to->process_inplace(
"filter.lowpass.gauss",
Dict(
"cutoff_abs",0.33f));
4047 for (
int i=0; i<ss/2; i++) {
4048 sigmathisv[i]*=sigmathisv[i]*sigmathis;
4049 sigmatov[i]*=sigmatov[i]*sigmato;
4055 float astep = 89.999/floor(pi/(1.5*2.0*atan(2.0/ss)));
4062 for (
int i=0; i<s_score.size(); i++) {
4064 if (fabs(s_step[i*3+0])<astep/4.0) s_step[i*3+0]*=2.0;
4065 if (fabs(s_step[i*3+1])<astep/4.0) s_step[i*3+1]*=2.0;
4066 if (fabs(s_step[i*3+2])<astep/4.0) s_step[i*3+2]*=2.0;
4072 if (verbose>1) printf(
"stage 1 - ang step %1.2f\n",astep);
4074 d[
"inc_mirror"] =
true;
4079 if (verbose>0) printf(
"%d orientations to test (%lu)\n",(
int)(transforms.size()*(360.0/astep)),transforms.size());
4080 if (transforms.size()<30)
continue;
4084 for (
unsigned int it=0; it<transforms.size(); it++) {
4087 printf(
" %d/%lu \r",it,transforms.size());
4090 for (
float phi=0; phi<360.0; phi+=astep) {
4102 EMData *stt=small_this->process(
"xform",
Dict(
"transform",
EMObject(&t),
"zerocorners",1));
4103 EMData *sttsq=small_thissq->process(
"xform",
Dict(
"transform",
EMObject(&t),
"zerocorners",1));
4106 IntPoint ml=ccf->calc_max_location_wrap();
4108 aap[
"tx"]=(int)ml[0];
4109 aap[
"ty"]=(int)ml[1];
4110 aap[
"tz"]=(int)ml[2];
4115 stt=small_this->process(
"xform",
Dict(
"transform",
EMObject(&t),
"zerocorners",1));
4118 float sim=stt->cmp(
"ccc.tomo.thresh",small_to);
4126 float worstv=1.0e20;
4127 for (
int i=0; i<nsoln; i++) {
4128 if (s_coverage[i]==0.0)
continue;
4132 if (adif<astep*2.5) {
4142 for (
int i=0; i<nsoln; i++) {
4143 if (s_coverage[i]==0.0) { worst=i;
break; }
4144 if (s_score[i]<worstv) {worst=i; worstv=s_score[i];}
4150 if (sim<s_score[worst]) {
4152 s_coverage[worst]=stt->get_attr(
"fft_overlap");
4159 if (verbose>2) printf(
"\n");
4169 float res=float(ny)/float(ss)*apix*2;
4170 if (verbose>1) printf(
"stage 2 - maxres %1.2f, astep %1.2f\n",res, astep);
4173 s_xform[nsoln]=initxf;
4177 for (
int i=0; i<nsoln; i++) {
4180 printf(
" %d\t%d\r",i,nsoln);
4186 testort(small_this,small_to,small_mask,small_thissq,sigmathisv,sigmatov,s_score,s_coverage,s_xform,i,upd, initxf, maxshift);
4189 for (
int axis=0; axis<3; axis++) {
4190 if (fabs(s_step[i*3+axis])<astep/4.0)
continue;
4191 upd[axname[axis]]=s_step[i*3+axis];
4194 if (axis==0) upd[axname[2]]=-s_step[i*3+axis];
4196 int r=
testort(small_this,small_to,small_mask,small_thissq,sigmathisv,sigmatov,s_score,s_coverage,s_xform,i,upd, initxf, maxshift);
4202 s_step[i*3+axis]*=-0.75;
4203 upd[axname[axis]]=s_step[i*3+axis];
4204 r=
testort(small_this,small_to,small_mask,small_thissq,sigmathisv,sigmatov,s_score,s_coverage,s_xform,i,upd, initxf, maxshift);
4207 if (verbose>4) printf(
"\nX %1.3f\t%1.3f\t%1.3f\t%d\t",s_step[i*3],s_step[i*3+1],s_step[i*3+2],changed);
4210 Dict aap=s_xform[i].get_params(
"eman");
4211 printf(
"\n%1.3f\t%1.3f\t%1.3f\t%1.3f\t%1.3f\t%1.3f\t(%1.3f)",s_step[i*3],s_step[i*3+1],s_step[i*3+2],
float(aap[
"az"]),
float(aap[
"alt"]),
float(aap[
"phi"]),s_score[i]);
4218 if (fabs(s_step[i*3])<astep/4 && fabs(s_step[i*3+1])<astep/4 && fabs(s_step[i*3+2])<astep/4) changed=0;
4238 for (
unsigned int i=0; i<nsoln-1; i++) {
4239 for (
unsigned int j=i+1; j<nsoln; j++) {
4240 if (s_score[i]>s_score[j]) {
4241 float t=s_score[i]; s_score[i]=s_score[j]; s_score[j]=t;
4242 t=s_coverage[i]; s_coverage[i]=s_coverage[j]; s_coverage[j]=t;
4243 Transform tt=s_xform[i]; s_xform[i]=s_xform[j]; s_xform[j]=tt;
4251 if (nsoln<nrsoln) nsoln=nrsoln;
4256 delete small_thissq;
4260 if (ss>=maxny && curiter>0)
break;
4270 for (
unsigned int i = 0; i < nrsoln; ++i ) {
4282 for (
unsigned int i = 0; i < nrsoln; ++i ) {
4284 d[
"score"] = s_score[i];
4285 d[
"coverage"] = s_coverage[i];
4286 s_xform[i].invert();
4287 d[
"xform.align3d"] = &s_xform[i];
virtual Dict get_params() const
Get the Aligner parameters in a key/value dictionary.
size_t size() const
Ask the Dictionary for its size.
EMData * get_clip(const Region &area, const float fill=0) const
Get an inclusive clip.
vector< float > calc_radial_dist(int n, float x0, float dx, int inten)
calculates radial distribution.
static T * get(const string &instance_name)
bool testort(EMData *small_this, EMData *small_to, EMData *small_mask, EMData *small_thissq, vector< float > &sigmathisv, vector< float > &sigmatov, vector< float > &s_score, vector< float > &s_coverage, vector< Transform > &s_xform, int i, Dict &upd, Transform initxf, int maxshift) const
Region defines a 2D or 3D rectangular region specified by its origin coordinates and all edges' sizes...
Symmetry3D - A base class for 3D Symmetry objects.
vector< Transform > gen_orientations(const string &generatorname="eman", const Dict &parms=Dict())
Ask the Symmetry3D object to generate a set of orientations in its asymmetric unit using an Orientati...
#define InvalidParameterException(desc)
#define InvalidCallException(desc)