#include <aligner.h>
Inheritance diagram for EMAN::RT3DGridAligner:
Public Member Functions | |
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. | |
virtual EMData * | align (EMData *this_img, EMData *to_img) const |
See Aligner comments for more details. | |
virtual vector< Dict > | xform_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. | |
virtual string | get_name () const |
Get the Aligner's name. | |
virtual string | get_desc () const |
virtual TypeDict | get_param_types () const |
Static Public Member Functions | |
static Aligner * | NEW () |
Static Public Attributes | |
static const string | NAME = "rotate_translate_3d_grid" |
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.
daz | The angle increment in the azimuth direction | |
laz | Lower bound for the azimuth direction | |
uaz | Upper bound for the azimuth direction | |
dphi | The angle increment in the phi direction | |
lphi | Lower bound for the phi direction | |
uphi | Upper bound for the phi direction | |
dalt | The angle increment in the altitude direction | |
lalt | Lower bound for the altitude direction | |
ualt | Upper bound for the altitude direction | |
dotrans | Do a translational search | |
search | 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 | |
searchx | The maximum length of the detectable translational shift in the x direction- if you supply this parameter you can not supply the maxshift parameters | |
searchy | The maximum length of the detectable translational shift in the y direction- if you supply this parameter you can not supply the maxshift parameters | |
searchz | The maximum length of the detectable translational shift in the z direction- if you supply this parameter you can not supply the maxshift parameters | |
verbose | Turn this on to have useful information printed to standard out |
Definition at line 1453 of file aligner.h.
EMData * 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.
Definition at line 2267 of file aligner.cpp.
References EMAN::EMData::process(), EMAN::EMData::set_attr(), t, and xform_align_nbest().
Referenced by align().
02268 { 02269 02270 vector<Dict> alis = xform_align_nbest(this_img,to,1,cmp_name,cmp_params); 02271 02272 Dict t; 02273 Transform* tr = (Transform*) alis[0]["xform.align3d"]; 02274 t["transform"] = tr; 02275 EMData* soln = this_img->process("xform",t); 02276 soln->set_attr("xform.align3d",tr); 02277 delete tr; tr = 0; 02278 02279 return soln; 02280 02281 }
virtual string EMAN::RT3DGridAligner::get_desc | ( | ) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 1477 of file aligner.h.
01478 { 01479 return "3D rotational and translational alignment using specified ranges and maximum shifts"; 01480 }
virtual string EMAN::RT3DGridAligner::get_name | ( | ) | const [inline, virtual] |
virtual TypeDict EMAN::RT3DGridAligner::get_param_types | ( | ) | const [inline, virtual] |
Implements EMAN::Aligner.
Definition at line 1487 of file aligner.h.
References EMAN::EMObject::BOOL, EMAN::EMObject::FLOAT, EMAN::EMObject::INT, and EMAN::TypeDict::put().
01488 { 01489 TypeDict d; 01490 d.put("daz", EMObject::FLOAT,"The angle increment in the azimuth direction. Default is 10"); 01491 d.put("az0", EMObject::FLOAT,"Lower bound for the azimuth direction. Default it 0"); 01492 d.put("az1", EMObject::FLOAT,"Upper bound for the azimuth direction. Default it 180.0"); 01493 d.put("dphi", EMObject::FLOAT,"The angle increment in the phi direction. Default is 10"); 01494 d.put("phi0", EMObject::FLOAT,"Lower bound for the phi direction. Default it 0"); 01495 d.put("phi1", EMObject::FLOAT,"Upper bound for the phi direction. Default it 360.0"); 01496 d.put("dalt", EMObject::FLOAT,"The angle increment in the altitude direction. Default is 10"); 01497 d.put("alt0", EMObject::FLOAT,"Lower bound for the altitude direction. Default it 0"); 01498 d.put("alt1", EMObject::FLOAT,"Upper bound for the altitude direction. Default it 360.0"); 01499 d.put("dotrans", EMObject::BOOL,"Do a translational search. Default is True(1)"); 01500 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."); 01501 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."); 01502 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."); 01503 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"); 01504 d.put("verbose", EMObject::BOOL,"Turn this on to have useful information printed to standard out."); 01505 return d; 01506 }
static Aligner* EMAN::RT3DGridAligner::NEW | ( | ) | [inline, static] |
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 2283 of file aligner.cpp.
References EMAN::EMData::calc_ccf(), EMAN::EMData::calc_max_location_wrap(), calc_max_location_wrap_cuda(), EMAN::Cmp::cmp(), copy(), data, EMAN::EMData::do_fft(), EMAN::EMData::get_ndim(), get_stats_cuda(), EMAN::EMData::get_value_at_wrap(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), ImageDimensionException, InvalidParameterException, EMAN::Aligner::params, phi, EMAN::EMData::process(), EMAN::EMData::process_inplace(), EMAN::Dict::set_default(), EMAN::Transform::set_trans(), sqrt(), and t.
Referenced by align().
02283 { 02284 02285 if ( this_img->get_ndim() != 3 || to->get_ndim() != 3 ) { 02286 throw ImageDimensionException("This aligner only works for 3D images"); 02287 } 02288 02289 int searchx = 0; 02290 int searchy = 0; 02291 int searchz = 0; 02292 02293 bool dotrans = params.set_default("dotrans",1); 02294 if (params.has_key("search")) { 02295 vector<string> check; 02296 check.push_back("searchx"); 02297 check.push_back("searchy"); 02298 check.push_back("searchz"); 02299 for(vector<string>::const_iterator cit = check.begin(); cit != check.end(); ++cit) { 02300 if (params.has_key(*cit)) throw InvalidParameterException("The search parameter is mutually exclusive of the searchx, searchy, and searchz parameters"); 02301 } 02302 int search = params["search"]; 02303 searchx = search; 02304 searchy = search; 02305 searchz = search; 02306 } else { 02307 searchx = params.set_default("searchx",3); 02308 searchy = params.set_default("searchy",3); 02309 searchz = params.set_default("searchz",3); 02310 } 02311 02312 float lalt = params.set_default("alt0",0.0f); 02313 float laz = params.set_default("az0",0.0f); 02314 float lphi = params.set_default("phi0",0.0f); 02315 float ualt = params.set_default("alt1",180.0f); // I am using 179.9 rather than 180 to avoid resampling 02316 float uphi = params.set_default("phi1",360.0f); // I am using 359.9 rather than 180 to avoid resampling 0 = 360 (for perodic functions) 02317 float uaz = params.set_default("az1",360.0f); // I am using 359.9 rather than 180 to avoid resampling 0 = 360 (for perodic functions) 02318 float dalt = params.set_default("dalt",10.f); 02319 float daz = params.set_default("daz",10.f); 02320 float dphi = params.set_default("dphi",10.f); 02321 bool verbose = params.set_default("verbose",false); 02322 02323 //in case we arre aligning tomos 02324 Dict altered_cmp_params(cmp_params); 02325 if (cmp_name == "ccc.tomo") { 02326 altered_cmp_params.set_default("searchx", searchx); 02327 altered_cmp_params.set_default("searchy", searchy); 02328 altered_cmp_params.set_default("searchz", searchz); 02329 altered_cmp_params.set_default("norm", true); 02330 } 02331 02332 vector<Dict> solns; 02333 if (nsoln == 0) return solns; // What was the user thinking? 02334 for (unsigned int i = 0; i < nsoln; ++i ) { 02335 Dict d; 02336 d["score"] = 1.e24; 02337 Transform t; // identity by default 02338 d["xform.align3d"] = &t; // deep copy is going on here 02339 solns.push_back(d); 02340 } 02341 02342 bool tomography = (cmp_name == "ccc.tomo") ? 1 : 0; 02343 EMData * tofft = 0; 02344 if(dotrans || tomography){ 02345 tofft = to->do_fft(); 02346 } 02347 02348 #ifdef EMAN2_USING_CUDA 02349 if(EMData::usecuda == 1) { 02350 if(!this_img->getcudarodata()) this_img->copy_to_cudaro(); // safer call 02351 if(!to->getcudarwdata()) to->copy_to_cuda(); 02352 if(to->getcudarwdata()){if(tofft) tofft->copy_to_cuda();} 02353 } 02354 #endif 02355 02356 Dict d; 02357 d["type"] = "eman"; // d is used in the loop below 02358 Transform trans = Transform(); 02359 Cmp* c = Factory <Cmp>::get(cmp_name, cmp_params); 02360 bool use_cpu = true; 02361 for ( float alt = lalt; alt <= ualt; alt += dalt) { 02362 // An optimization for the range of az is made at the top of the sphere 02363 // If you think about it, this is just a coarse way of making this approach slightly more efficient 02364 for ( float az = laz; az < uaz; az += daz ){ 02365 if (verbose) { 02366 cout << "Trying angle alt " << alt << " az " << az << endl; 02367 } 02368 for( float phi = lphi; phi < uphi; phi += dphi ) { 02369 d["alt"] = alt; 02370 d["phi"] = phi; 02371 d["az"] = az; 02372 Transform t(d); 02373 EMData* transformed = this_img->process("xform",Dict("transform",&t)); 02374 02375 //need to do things a bit diffrent if we want to compare two tomos 02376 float best_score = 0.0f; 02377 if(dotrans || tomography){ 02378 EMData* ccf = transformed->calc_ccf(tofft); 02379 #ifdef EMAN2_USING_CUDA 02380 if(EMData::usecuda == 1){ 02381 use_cpu = false;; 02382 CudaPeakInfo* data = calc_max_location_wrap_cuda(ccf->getcudarwdata(), ccf->get_xsize(), ccf->get_ysize(), ccf->get_zsize(), searchx, searchy, searchz); 02383 trans.set_trans((float)-data->px, (float)-data->py, (float)-data->pz); 02384 t = trans*t; //composite transfrom to reflect the fact that we have done a rotation first and THEN a transformation 02385 if (tomography) { 02386 float2 stats = get_stats_cuda(ccf->getcudarwdata(), ccf->get_xsize(), ccf->get_ysize(), ccf->get_zsize()); 02387 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 02388 } else { 02389 best_score = -data->peak; 02390 } 02391 delete data; 02392 } 02393 #endif 02394 if(use_cpu){ 02395 if(tomography) ccf->process_inplace("normalize"); 02396 IntPoint point = ccf->calc_max_location_wrap(searchx,searchy,searchz); 02397 trans.set_trans((float)-point[0], (float)-point[1], (float)-point[2]); 02398 t = trans*t; //composite transfrom to reflect the fact that we have done a rotation first and THEN a transformation 02399 best_score = -ccf->get_value_at_wrap(point[0], point[1], point[2]); 02400 } 02401 delete ccf; ccf =0; 02402 delete transformed; transformed = 0; 02403 } 02404 02405 if(!tomography){ 02406 if(!transformed) transformed = this_img->process("xform",Dict("transform",&t)); 02407 best_score = c->cmp(to,transformed); 02408 delete transformed; transformed = 0; 02409 } 02410 02411 unsigned int j = 0; 02412 for ( vector<Dict>::iterator it = solns.begin(); it != solns.end(); ++it, ++j ) { 02413 if ( (float)(*it)["score"] > best_score ) { // Note greater than - EMAN2 preferes minimums as a matter of policy 02414 vector<Dict>::reverse_iterator rit = solns.rbegin(); 02415 copy(rit+1,solns.rend()-j,rit); 02416 Dict& d = (*it); 02417 d["score"] = best_score; 02418 d["xform.align3d"] = &t; 02419 break; 02420 } 02421 } 02422 } 02423 } 02424 } 02425 02426 if(tofft) {delete tofft; tofft = 0;} 02427 if (c != 0) delete c; 02428 02429 return solns; 02430 02431 }
const string RT3DGridAligner::NAME = "rotate_translate_3d_grid" [static] |