aligner.h

Go to the documentation of this file.
00001 
00005 /*
00006  * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
00007  * Copyright (c) 2000-2006 Baylor College of Medicine
00008  *
00009  * This software is issued under a joint BSD/GNU license. You may use the
00010  * source code in this file under either license. However, note that the
00011  * complete EMAN2 and SPARX software packages have some GPL dependencies,
00012  * so you are responsible for compliance with the licenses of these packages
00013  * if you opt to use BSD licensing. The warranty disclaimer below holds
00014  * in either instance.
00015  *
00016  * This complete copyright notice must be included in any revised version of the
00017  * source code. Additional authorship citations may be added, but existing
00018  * author citations must be preserved.
00019  *
00020  * This program is free software; you can redistribute it and/or modify
00021  * it under the terms of the GNU General Public License as published by
00022  * the Free Software Foundation; either version 2 of the License, or
00023  * (at your option) any later version.
00024  *
00025  * This program is distributed in the hope that it will be useful,
00026  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00028  * GNU General Public License for more details.
00029  *
00030  * You should have received a copy of the GNU General Public License
00031  * along with this program; if not, write to the Free Software
00032  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00033  *
00034  * */
00035 
00036 #ifndef eman__aligner_h__
00037 #define eman__aligner_h__ 1
00038 
00039 
00040 #include "emobject.h"
00041 
00042 
00043 namespace EMAN
00044 {
00045         class EMData;
00046         class Cmp;
00047 
00084         class Aligner
00085         {
00086           public:
00087                 virtual ~ Aligner()
00088                 {
00089                 }
00090 
00091                 virtual EMData *align(EMData * this_img, EMData * to_img) const = 0;
00092 
00104                 virtual EMData *align(EMData * this_img, EMData * to_img,
00105                                                           const string & cmp_name, const Dict& cmp_params) const = 0;
00106 
00110                 virtual string get_name() const = 0;
00111 
00112                 virtual string get_desc() const = 0;
00116                 virtual Dict get_params() const
00117                 {
00118                         return params;
00119                 }
00120 
00124                 virtual void set_params(const Dict & new_params)
00125                 {
00126                         params = new_params;
00127                 }
00128 
00129                 virtual TypeDict get_param_types() const = 0;
00130 
00144                 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;
00145 //              {
00146 //                      vector<Dict> solns;
00147 //                      return solns;
00148 //              }
00149 
00150           protected:
00151                 mutable Dict params;
00152 
00153 //              /** Get a Transform pointer that is currently stored in the image header corresponding to the given key.
00154 //               * If non existant then initialize a new Transform pointer, set it as the image attribute, and return it.
00155 //               * The point being that if you have to access the xform.align2d or the xform.align3d
00156 //               * attributes from multiple aligners then you always want to get the same one.
00157 //               * @param key the alignment key such as "xform.align2d" or "xform.align3d"
00158 //               * @param image the image from which the Transform pointer will be extracted (and potentially assigned to if non existant)
00159 //               * @return the Transform pointer that is currently stored in the image header corresponding to the given key.
00160 //               */
00161 //              static Transform* get_align_attr(const string& key, EMData* const image );
00162 //
00163 //              static Transform* get_set_align_attr(const string& key, EMData* const to_image, const EMData* const from_image  );
00164         };
00165 
00174         class TranslationalAligner:public Aligner
00175         {
00176           public:
00177                 virtual EMData * align(EMData * this_img, EMData * to_img,
00178                                                 const string & cmp_name="dot", const Dict& cmp_params = Dict()) const;
00179 
00180                 virtual EMData * align(EMData * this_img, EMData * to_img) const
00181                 {
00182                         return align(this_img, to_img, "dot", Dict());
00183                 }
00184 
00185                 virtual string get_name() const
00186                 {
00187                         return NAME;
00188                 }
00189 
00190                 virtual string get_desc() const
00191                 {
00192                         return "Translational 2D and 3D alignment by cross-correlation";
00193                 }
00194 
00195                 static Aligner *NEW()
00196                 {
00197                         return new TranslationalAligner();
00198                 }
00199 
00200                 virtual TypeDict get_param_types() const
00201                 {
00202                         TypeDict d;
00203                         d.put("intonly", EMObject::INT,"Integer pixel translations only");
00204                         d.put("useflcf", EMObject::INT,"Use Fast Local Correlation Function rather than CCF");
00205                         d.put("maxshift", EMObject::INT,"Maximum translation in pixels");
00206                         d.put("masked", EMObject::INT,"Treat zero pixels in 'this' as a mask for normalization (default false)");
00207                         d.put("nozero", EMObject::INT,"Zero translation not permitted (useful for CCD images)");
00208                         return d;
00209                 }
00210                 
00211                 static const string NAME;
00212         };
00213 
00218         class RotationalAligner:public Aligner
00219         {
00220           public:
00221                 virtual EMData * align(EMData * this_img, EMData * to_img,
00222                                                 const string & cmp_name = "dot", const Dict& cmp_params = Dict()) const;
00223 
00224                 virtual EMData * align(EMData * this_img, EMData * to_img) const
00225                 {
00226                         return align(this_img, to_img, "dot", Dict());
00227                 }
00228 
00229                 virtual string get_name() const
00230                 {
00231                         return NAME;
00232                 }
00233 
00234                 virtual string get_desc() const
00235                 {
00236                         return "Performs rotational alignment,works accurately if the image is precentered, normally called internally in combination with translational and flip alignment";
00237                 }
00238 
00239                 static Aligner *NEW()
00240                 {
00241                         return new RotationalAligner();
00242                 }
00243 
00244                 static EMData * align_180_ambiguous(EMData * this_img, EMData * to_img, int rfp_mode = 0);
00245 
00246                 virtual TypeDict get_param_types() const
00247                 {
00248                         TypeDict d;
00249                         d.put("rfp_mode", EMObject::INT,"Either 0,1 or 2. A temporary flag for testing the rotational foot print. O is the original eman1 way. 1 is just using calc_ccf without padding. 2 is using calc_mutual_correlation without padding.");
00250                         return d;
00251                 }
00252                 
00253                 static const string NAME;
00254         };
00255 
00263         class RotationalAlignerIterative:public Aligner
00264         {
00265           public:
00266                 virtual EMData * align(EMData * this_img, EMData * to_img,
00267                                                 const string & cmp_name = "dot", const Dict& cmp_params = Dict()) const;
00268 
00269                 virtual EMData * align(EMData * this_img, EMData * to_img) const
00270                 {
00271                         return align(this_img, to_img, "dot", Dict());
00272                 }
00273 
00274                 virtual string get_name() const
00275                 {
00276                         return NAME;
00277                 }
00278 
00279                 virtual string get_desc() const
00280                 {
00281                         return "Performs rotational alignment using the SPIDER method";
00282                 }
00283 
00284                 static Aligner *NEW()
00285                 {
00286                         return new RotationalAlignerIterative();
00287                 }
00288 
00289                 virtual TypeDict get_param_types() const
00290                 {
00291                         TypeDict d;
00292                         d.put("r1", EMObject::INT, "Inner ring, pixels");
00293                         d.put("r2", EMObject::INT, "Outer ring, pixels");
00294                         return d;
00295                 }
00296                 
00297                 static const string NAME;
00298         };
00299 
00302         class RotatePrecenterAligner:public Aligner
00303         {
00304           public:
00305                 virtual EMData * align(EMData * this_img, EMData * to_img,
00306                                                 const string & cmp_name = "dot", const Dict& cmp_params = Dict()) const;
00307 
00308                 virtual EMData * align(EMData * this_img, EMData * to_img) const
00309                 {
00310                         return align(this_img, to_img, "dot", Dict());
00311                 }
00312 
00313                 virtual string get_name() const
00314                 {
00315                         return NAME;
00316                 }
00317 
00318                 virtual string get_desc() const
00319                 {
00320                         return "Performs rotational alignment and works accurately if the image is precentered";
00321                 }
00322 
00323                 static Aligner *NEW()
00324                 {
00325                         return new RotatePrecenterAligner();
00326                 }
00327 
00328                 virtual TypeDict get_param_types() const
00329                 {
00330                         TypeDict d;
00331                         return d;
00332                 }
00333                 
00334                 static const string NAME;
00335         };
00336 
00343         class RotateTranslateAligner:public Aligner
00344         {
00345           public:
00346                   virtual EMData * align(EMData * this_img, EMData * to_img,
00347                                            const string & cmp_name="dot", const Dict& cmp_params = Dict()) const;
00348 
00349                 virtual EMData * align(EMData * this_img, EMData * to_img) const
00350                 {
00351                         return align(this_img, to_img, "sqeuclidean", Dict());
00352                 }
00353 
00354                 virtual string get_name() const
00355                 {
00356                         return NAME;
00357                 }
00358 
00359                 virtual string get_desc() const
00360                 {
00361                         return "Performs rotational alignment and follows this with translational alignment.";
00362                 }
00363 
00364                 static Aligner *NEW()
00365                 {
00366                         return new RotateTranslateAligner();
00367                 }
00368 
00369                 virtual TypeDict get_param_types() const
00370                 {
00371                         TypeDict d;
00372                         //d.put("usedot", EMObject::INT);
00373                         d.put("maxshift", EMObject::INT, "Maximum translation in pixels");
00374                         d.put("nozero", EMObject::INT,"Zero translation not permitted (useful for CCD images)");
00375                         d.put("rfp_mode", EMObject::INT,"Either 0,1 or 2. A temporary flag for testing the rotational foot print");
00376                         d.put("useflcf", EMObject::INT,"Use Fast Local Correlation Function rather than CCF for translational alignment");
00377                         return d;
00378                 }
00379                 
00380                 static const string NAME;
00381         };
00382         
00393         class RotateTranslateAlignerIterative:public Aligner
00394         {
00395           public:
00396                 virtual EMData * align(EMData * this_img, EMData * to_img,
00397                                            const string & cmp_name="dot", const Dict& cmp_params = Dict()) const;
00398 
00399                 virtual EMData * align(EMData * this_img, EMData * to_img) const
00400                 {
00401                         return align(this_img, to_img, "sqeuclidean", Dict());
00402                 }
00403 
00404                 virtual string get_name() const
00405                 {
00406                         return NAME;
00407                 }
00408 
00409                 virtual string get_desc() const
00410                 {
00411                         return "Performs rotational alignment and follows this with translational alignment using the iterative method.";
00412                 }
00413 
00414                 static Aligner *NEW()
00415                 {
00416                         return new RotateTranslateAlignerIterative();
00417                 }
00418 
00419                 virtual TypeDict get_param_types() const
00420                 {
00421                         TypeDict d;
00422                         //d.put("usedot", EMObject::INT);
00423                         d.put("maxshift", EMObject::INT, "Maximum translation in pixels");
00424                         d.put("r1", EMObject::INT, "Inner ring, pixels");
00425                         d.put("r2", EMObject::INT, "Outer ring, pixels");
00426                         d.put("maxiter", EMObject::INT, "Maximum number of iterations");
00427                         d.put("nozero", EMObject::INT,"Zero translation not permitted (useful for CCD images)");
00428                         d.put("useflcf", EMObject::INT,"Use Fast Local Correlation Function rather than CCF for translational alignment");
00429                         return d;
00430                 }
00431                 
00432                 static const string NAME;
00433         };
00434 
00444         class RotateTranslateAlignerPawel:public Aligner
00445         {
00446           public:
00447                 virtual EMData * align(EMData * this_img, EMData * to_img,
00448                                            const string & cmp_name="dot", const Dict& cmp_params = Dict()) const;
00449 
00450                 virtual EMData * align(EMData * this_img, EMData * to_img) const
00451                 {
00452                         return align(this_img, to_img, "sqeuclidean", Dict());
00453                 }
00454 
00455                 virtual string get_name() const
00456                 {
00457                         return NAME;
00458                 }
00459 
00460                 virtual string get_desc() const
00461                 {
00462                         return "Performs rotational alignment and translation align by resampling to polar coordinates in real space.";
00463                 }
00464 
00465                 static Aligner *NEW()
00466                 {
00467                         return new RotateTranslateAlignerPawel();
00468                 }
00469 
00470                 virtual TypeDict get_param_types() const
00471                 {
00472                         TypeDict d;
00473                         //d.put("usedot", EMObject::INT);
00474                         d.put("tx", EMObject::INT, "Maximum x translation in pixels, Default = 0");
00475                         d.put("ty", EMObject::INT, "Maximum x translation in pixels, Default = 0");
00476                         d.put("r1", EMObject::INT, "Inner ring, pixels");
00477                         d.put("r2", EMObject::INT, "Outer ring, pixels");
00478                         return d;
00479                 }
00480                 
00481                 static const string NAME;
00482         };
00483         
00488         class RotateTranslateBestAligner:public Aligner
00489         {
00490           public:
00491                 virtual EMData * align(EMData * this_img, EMData * to_img,
00492                                            const string & cmp_name="dot", const Dict& cmp_params = Dict()) const;
00493 
00494                 virtual EMData * align(EMData * this_img, EMData * to_img) const
00495                 {
00496                         return align(this_img, to_img, "frc", Dict());
00497                 }
00498 
00499                 virtual string get_name() const
00500                 {
00501                         return NAME;
00502                 }
00503 
00504                 virtual string get_desc() const
00505                 {
00506                         return "Full 2D alignment using 'Rotational' and 'Translational', also incorporates 2D 'Refine' alignments.";
00507                 }
00508 
00509                 static Aligner *NEW()
00510                 {
00511                         return new RotateTranslateBestAligner();
00512                 }
00513 
00514                 virtual TypeDict get_param_types() const
00515                 {
00516                         TypeDict d;
00517                         d.put("maxshift", EMObject::INT, "Maximum translation in pixels");
00518                         d.put("snr", EMObject::FLOATARRAY, "signal to noise ratio array");
00519                         return d;
00520                 }
00521 
00522                 static const string NAME;
00523         };
00524 
00530         class RotateFlipAligner:public Aligner
00531         {
00532           public:
00533                 virtual EMData * align(EMData * this_img, EMData * to_img,
00534                                            const string & cmp_name="dot", const Dict& cmp_params = Dict()) const;
00535                 virtual EMData * align(EMData * this_img, EMData * to_img) const
00536                 {
00537                         return align(this_img, to_img, "dot", Dict());
00538                 }
00539                 virtual string get_name() const
00540                 {
00541                         return NAME;
00542                 }
00543 
00544                 virtual string get_desc() const
00545                 {
00546                         return "Performs two rotational alignments, one using the original image and one using the hand-flipped image. Decides which alignment is better using a comparitor and returns it";
00547                 }
00548 
00549                 static Aligner *NEW()
00550                 {
00551                         return new RotateFlipAligner();
00552                 }
00553 
00554                 virtual TypeDict get_param_types() const
00555                 {
00556                         return static_get_param_types();
00557                 }
00558 
00559                 static TypeDict static_get_param_types() {
00560                         TypeDict d;
00561 
00562                         d.put("imask", EMObject::INT);
00563                         d.put("rfp_mode", EMObject::INT,"Either 0,1 or 2. A temporary flag for testing the rotational foot print");
00564                         return d;
00565                 }
00566 
00567                 static const string NAME;
00568         };
00569 
00576         class RotateFlipAlignerIterative:public Aligner
00577         {
00578           public:
00579                 virtual EMData * align(EMData * this_img, EMData * to_img,
00580                                            const string & cmp_name="dot", const Dict& cmp_params = Dict()) const;
00581                 virtual EMData * align(EMData * this_img, EMData * to_img) const
00582                 {
00583                         return align(this_img, to_img, "dot", Dict());
00584                 }
00585                 virtual string get_name() const
00586                 {
00587                         return NAME;
00588                 }
00589 
00590                 virtual string get_desc() const
00591                 {
00592                         return "Performs two rotational alignments, iterative style, one using the original image and one using the hand-flipped image. Decides which alignment is better using a comparitor and returns it";
00593                 }
00594 
00595                 static Aligner *NEW()
00596                 {
00597                         return new RotateFlipAlignerIterative();
00598                 }
00599 
00600                 virtual TypeDict get_param_types() const
00601                 {
00602                         return static_get_param_types();
00603                 }
00604 
00605                 static TypeDict static_get_param_types() {
00606                         TypeDict d;
00607                         d.put("r1", EMObject::INT, "Inner ring, pixels");
00608                         d.put("r2", EMObject::INT, "Outer ring, pixels");
00609                         return d;
00610                 }
00611 
00612                 static const string NAME;
00613         };
00614         
00621         class RotateTranslateFlipAligner:public Aligner
00622         {
00623           public:
00624                 virtual EMData * align(EMData * this_img, EMData * to_img,
00625                                            const string & cmp_name="dot", const Dict& cmp_params = Dict()) const;
00626                 virtual EMData * align(EMData * this_img, EMData * to_img) const
00627                 {
00628                         return align(this_img, to_img, "sqeuclidean", Dict());
00629                 }
00630 
00631                 virtual string get_name() const
00632                 {
00633                         return NAME;
00634                 }
00635 
00636                 virtual string get_desc() const
00637                 {
00638                         return " Does two 'rotate_translate' alignments, one to accommodate for possible handedness change. Decided which alignment is better using a comparitor and returns the aligned image as the solution";
00639                 }
00640 
00641                 static Aligner *NEW()
00642                 {
00643                         return new RotateTranslateFlipAligner();
00644                 }
00645 
00646                 virtual TypeDict get_param_types() const
00647                 {
00648                         return static_get_param_types();
00649                 }
00650 
00651                 static TypeDict static_get_param_types() {
00652                         TypeDict d;
00653 
00654                         d.put("flip", EMObject::EMDATA);
00655                         d.put("usedot", EMObject::INT);
00656                         d.put("maxshift", EMObject::INT, "Maximum translation in pixels");
00657                         d.put("rfp_mode", EMObject::INT,"Either 0,1 or 2. A temporary flag for testing the rotational foot print");
00658                         d.put("useflcf", EMObject::INT,"Use Fast Local Correlation Function rather than CCF for translational alignment");
00659                         return d;
00660                 }
00661                 
00662                 static const string NAME;
00663         };
00664 
00674         class RotateTranslateFlipAlignerIterative:public Aligner
00675         {
00676           public:
00677                 virtual EMData * align(EMData * this_img, EMData * to_img,
00678                                            const string & cmp_name="dot", const Dict& cmp_params = Dict()) const;
00679                 virtual EMData * align(EMData * this_img, EMData * to_img) const
00680                 {
00681                         return align(this_img, to_img, "sqeuclidean", Dict());
00682                 }
00683 
00684                 virtual string get_name() const
00685                 {
00686                         return NAME;
00687                 }
00688 
00689                 virtual string get_desc() const
00690                 {
00691                         return " Does two 'rotate_translate.iterative' alignments, one to accommodate for possible handedness change. Decided which alignment is better using a comparitor and returns the aligned image as the solution";
00692                 }
00693 
00694                 static Aligner *NEW()
00695                 {
00696                         return new RotateTranslateFlipAlignerIterative();
00697                 }
00698 
00699                 virtual TypeDict get_param_types() const
00700                 {
00701                         return static_get_param_types();
00702                 }
00703 
00704                 static TypeDict static_get_param_types() {
00705                         TypeDict d;
00706                         d.put("flip", EMObject::EMDATA);
00707                         d.put("r1", EMObject::INT, "Inner ring, pixels");
00708                         d.put("r2", EMObject::INT, "Outer ring, pixels");
00709                         d.put("maxiter", EMObject::INT, "Maximum number of iterations");
00710                         d.put("maxshift", EMObject::INT, "Maximum translation in pixels");
00711                         return d;
00712                 }
00713                 
00714                 static const string NAME;
00715         };
00716         
00726         class RotateTranslateFlipAlignerPawel:public Aligner
00727         {
00728           public:
00729                 virtual EMData * align(EMData * this_img, EMData * to_img,
00730                                            const string & cmp_name="dot", const Dict& cmp_params = Dict()) const;
00731 
00732                 virtual EMData * align(EMData * this_img, EMData * to_img) const
00733                 {
00734                         return align(this_img, to_img, "sqeuclidean", Dict());
00735                 }
00736 
00737                 virtual string get_name() const
00738                 {
00739                         return NAME;
00740                 }
00741 
00742                 virtual string get_desc() const
00743                 {
00744                         return "Performs rotational alignment, translation align, and flip by resampling to polar coordinates in real space.";
00745                 }
00746 
00747                 static Aligner *NEW()
00748                 {
00749                         return new RotateTranslateFlipAlignerPawel();
00750                 }
00751 
00752                 virtual TypeDict get_param_types() const
00753                 {
00754                         TypeDict d;
00755                         //d.put("usedot", EMObject::INT);
00756                         d.put("tx", EMObject::INT, "Maximum x translation in pixels, Default = 0");
00757                         d.put("ty", EMObject::INT, "Maximum x translation in pixels, Default = 0");
00758                         d.put("r1", EMObject::INT, "Inner ring, pixels");
00759                         d.put("r2", EMObject::INT, "Outer ring, pixels");
00760                         return d;
00761                 }
00762                 
00763                 static const string NAME;
00764         };
00765         
00770         class RTFExhaustiveAligner:public Aligner
00771         {
00772           public:
00773                 virtual EMData * align(EMData * this_img, EMData * to_img,
00774                                            const string & cmp_name="dot", const Dict& cmp_params = Dict()) const;
00775                 virtual EMData * align(EMData * this_img, EMData * to_img) const
00776                 {
00777                         return align(this_img, to_img, "sqeuclidean", Dict());
00778                 }
00779 
00780                 virtual string get_name() const
00781                 {
00782                         return NAME;
00783                 }
00784 
00785                 virtual string get_desc() const
00786                 {
00787                         return "Experimental full 2D alignment with handedness check using semi-exhaustive search (not necessarily better than RTFBest)";
00788                 }
00789 
00790                 static Aligner *NEW()
00791                 {
00792                         return new RTFExhaustiveAligner();
00793                 }
00794 
00795                 virtual TypeDict get_param_types() const
00796                 {
00797                         TypeDict d;
00798 
00799                         d.put("flip", EMObject::EMDATA);
00800                         d.put("maxshift", EMObject::INT, "Maximum translation in pixels");
00801                         return d;
00802                 }
00803                 
00804                 static const string NAME;
00805         };
00806 
00814         class RTFSlowExhaustiveAligner:public Aligner
00815         {
00816           public:
00817                 virtual EMData * align(EMData * this_img, EMData * to_img,
00818                                                 const string & cmp_name, const Dict& cmp_params) const;
00819                 virtual EMData * align(EMData * this_img, EMData * to_img) const
00820                 {
00821                         return align(this_img, to_img, "sqeuclidean", Dict());
00822                 }
00823                 virtual string get_name() const
00824                 {
00825                         return NAME;
00826                 }
00827 
00828                 virtual string get_desc() const
00829                 {
00830                         return "Experimental full 2D alignment with handedness check using more exhaustive search (not necessarily better than RTFBest)";
00831                 }
00832 
00833                 static Aligner *NEW()
00834                 {
00835                         return new RTFSlowExhaustiveAligner();
00836                 }
00837 
00838                 virtual TypeDict get_param_types() const
00839                 {
00840                         TypeDict d;
00841                         d.put("flip", EMObject::EMDATA,"Optional. This is the flipped version of the images that is being aligned. If specified it will be used for the handedness check, if not a flipped copy of the image will be made");
00842                         d.put("maxshift", EMObject::INT,"The maximum length of the detectable translational shift");
00843                         d.put("transtep", EMObject::FLOAT,"The translation step to take when honing the alignment, which occurs after coarse alignment");
00844                         d.put("angstep", EMObject::FLOAT,"The angular step (in degrees) to take in the exhaustive search for the solution angle. Typically very small i.e. 3 or smaller.");
00845                         return d;
00846                 }
00847                 
00848                 static const string NAME;
00849         };
00850 
00853         class RefineAligner:public Aligner
00854         {
00855           public:
00856                 virtual EMData * align(EMData * this_img, EMData * to_img,
00857                                            const string & cmp_name="dot", const Dict& cmp_params = Dict()) const;
00858 
00859                 virtual EMData * align(EMData * this_img, EMData * to_img) const
00860                 {
00861                         return align(this_img, to_img, "sqeuclidean", Dict());
00862                 }
00863 
00864                 virtual string get_name() const
00865                 {
00866                         return NAME;
00867                 }
00868 
00869                 virtual string get_desc() const
00870                 {
00871                         return "Refines a preliminary 2D alignment using a simplex algorithm. Subpixel precision.";
00872                 }
00873 
00874                 static Aligner *NEW()
00875                 {
00876                         return new RefineAligner();
00877                 }
00878 
00879                 virtual TypeDict get_param_types() const
00880                 {
00881                         TypeDict d;
00882 
00883                         d.put("mode", EMObject::INT, "Currently unused");
00884                         d.put("xform.align2d", EMObject::TRANSFORM, "The Transform storing the starting guess. If unspecified the identity matrix is used");
00885                         d.put("stepx", EMObject::FLOAT, "The x increment used to create the starting simplex. Default is 1");
00886                         d.put("stepy", EMObject::FLOAT, "The y increment used to create the starting simplex. Default is 1");
00887                         d.put("stepaz", EMObject::FLOAT, "The rotational increment used to create the starting simplex. Default is 5");
00888                         d.put("precision", EMObject::FLOAT, "The precision which, if achieved, can stop the iterative refinement before reaching the maximum iterations. Default is 0.04.");
00889                         d.put("maxiter", EMObject::INT,"The maximum number of iterations that can be performed by the Simplex minimizer");
00890                         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.");
00891                         d.put("stepscale", EMObject::FLOAT, "If set to any non-zero value, scale will be included in the alignment, and this will be the initial step. Images should be edgenormalized. If the scale goes beyond +-30% alignment will fail.");
00892                         return d;
00893                 }
00894                 
00895                 static const string NAME;
00896         };
00897 
00898         class Refine3DAlignerGridInefficient:public Aligner
00899         {
00900                 public:
00901                         virtual EMData * align(EMData * this_img, EMData * to_img,
00902                                                    const string & cmp_name="sqeuclidean", const Dict& cmp_params = Dict()) const;
00903 
00904                         virtual EMData * align(EMData * this_img, EMData * to_img) const
00905                         {
00906                                 return align(this_img, to_img, "sqeuclidean", Dict());
00907                         }
00908 
00909                         virtual string get_name() const
00910                         {
00911                                 return NAME;
00912                         }
00913 
00914                         virtual string get_desc() const
00915                         {
00916                                 return "Refines a preliminary 3D alignment using a simplex algorithm. Subpixel precision.";
00917                         }
00918 
00919                         static Aligner *NEW()
00920                         {
00921                                 return new Refine3DAlignerGridInefficient();
00922                         }
00923 
00924                         virtual TypeDict get_param_types() const
00925                         {
00926                                 TypeDict d;
00927                                 d.put("xform.align3d", EMObject::TRANSFORM,"The Transform storing the starting guess. If unspecified the identity matrix is used");
00928                                 d.put("saz", EMObject::FLOAT, "The angular step size for az. Default is 2." );
00929                                 d.put("salt", EMObject::FLOAT, "The The angular step size for alt. Default is 2." );
00930                                 d.put("sphi", EMObject::FLOAT, "The The angular step size for phi. Default is 2." );
00931                                 d.put("raz", EMObject::FLOAT, "The angular range(+- this amount) for az. Default is 180." );
00932                                 d.put("ralt", EMObject::FLOAT, "The The angular range(+- this amount) for alt. Default is 6." );
00933                                 d.put("rphi", EMObject::FLOAT, "The The angular range(+- this amount) for phi. Default is 6." );        
00934                                 d.put("dotrans", EMObject::BOOL,"Do a translational search. Default is True(1)");
00935                                 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.");
00936                                 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.");
00937                                 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.");
00938                                 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");
00939                                 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.");
00940                                 d.put("verbose", EMObject::BOOL,"Turn this on to have useful information printed to standard out.");
00941                                 return d;
00942                         }
00943                         
00944                         static const string NAME;
00945         };
00946         
00968         class Refine3DAlignerQuaternion:public Aligner
00969         {
00970                 public:
00971                         virtual EMData * align(EMData * this_img, EMData * to_img,
00972                                                    const string & cmp_name="sqeuclidean", const Dict& cmp_params = Dict()) const;
00973 
00974                         virtual EMData * align(EMData * this_img, EMData * to_img) const
00975                         {
00976                                 return align(this_img, to_img, "sqeuclidean", Dict());
00977                         }
00978 
00979                         virtual string get_name() const
00980                         {
00981                                 return NAME;
00982                         }
00983 
00984                         virtual string get_desc() const
00985                         {
00986                                 return "Refines a preliminary 3D alignment using a simplex algorithm. Subpixel precision.";
00987                         }
00988 
00989                         static Aligner *NEW()
00990                         {
00991                                 return new Refine3DAlignerQuaternion();
00992                         }
00993 
00994                         virtual TypeDict get_param_types() const
00995                         {
00996                                 TypeDict d;
00997                                 d.put("xform.align3d", EMObject::TRANSFORM,"The Transform storing the starting guess. If unspecified the identity matrix is used");
00998                                 d.put("stepx", EMObject::FLOAT, "The initial simplex step size in x. Default is 1");
00999                                 d.put("stepy", EMObject::FLOAT, "The initial simplex step size in y. Default is 1");
01000                                 d.put("stepz", EMObject::FLOAT, "The initial simplex step size in z. Default is 1." );
01001                                 d.put("stepn0", EMObject::FLOAT, "The initial simplex step size in the first quaternion vecotr component. Default is 1." );
01002                                 d.put("stepn1", EMObject::FLOAT, "The initial simplex step size in the second quaternion vecotr component. Default is 1." );
01003                                 d.put("stepn2", EMObject::FLOAT, "The initial simplex step size in the third quaternion vecotr component. Default is 1." );
01004                                 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.");
01005                                 d.put("precision", EMObject::FLOAT, "The precision which, if achieved, can stop the iterative refinement before reaching the maximum iterations. Default is 0.01." );
01006                                 d.put("maxiter", EMObject::INT, "The maximum number of iterations that can be performed by the Simplex minimizer. Default is 100.");
01007                                 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.");
01008                                 return d;
01009                         }
01010                         
01011                         static const string NAME;
01012         };
01013         
01036         class RT3DGridAligner:public Aligner
01037         {
01038                 public:
01041                         virtual EMData * align(EMData * this_img, EMData * to_img,
01042                                                    const string & cmp_name="ccc.tomo", const Dict& cmp_params = Dict()) const;
01045                         virtual EMData * align(EMData * this_img, EMData * to_img) const
01046                         {
01047                                 return align(this_img, to_img, "ccc.tomo", Dict());
01048                         }
01049 
01050 
01053                         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;
01054 
01055                         virtual string get_name() const
01056                         {
01057                                 return NAME;
01058                         }
01059 
01060                         virtual string get_desc() const
01061                         {
01062                                 return "3D rotational and translational alignment using specified ranges and maximum shifts";
01063                         }
01064 
01065                         static Aligner *NEW()
01066                         {
01067                                 return new RT3DGridAligner();
01068                         }
01069 
01070                         virtual TypeDict get_param_types() const
01071                         {
01072                                 TypeDict d;
01073                                 d.put("daz", EMObject::FLOAT,"The angle increment in the azimuth direction. Default is 10");
01074                                 d.put("az0", EMObject::FLOAT,"Lower bound for the azimuth direction. Default it 0");
01075                                 d.put("az1", EMObject::FLOAT,"Upper bound for the azimuth direction. Default it 180.0");
01076                                 d.put("dphi", EMObject::FLOAT,"The angle increment in the phi direction. Default is 10");
01077                                 d.put("phi0", EMObject::FLOAT,"Lower bound for the phi direction. Default it 0");
01078                                 d.put("phi1", EMObject::FLOAT,"Upper bound for the phi direction. Default it 360.0");
01079                                 d.put("dalt", EMObject::FLOAT,"The angle increment in the altitude direction. Default is 10");
01080                                 d.put("alt0", EMObject::FLOAT,"Lower bound for the altitude direction. Default it 0");
01081                                 d.put("alt1", EMObject::FLOAT,"Upper bound for the altitude direction. Default it 360.0");
01082                                 d.put("dotrans", EMObject::BOOL,"Do a translational search. Default is True(1)");
01083                                 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.");
01084                                 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.");
01085                                 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.");
01086                                 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");
01087                                 d.put("verbose", EMObject::BOOL,"Turn this on to have useful information printed to standard out.");
01088                                 return d;
01089                         }
01090                         
01091                         static const string NAME;
01092         };
01093 
01119         class RT3DSphereAligner:public Aligner
01120         {
01121                 public:
01124                         virtual EMData * align(EMData * this_img, EMData * to_img,
01125                                                                    const string & cmp_name= "sqeuclidean", const Dict& cmp_params = Dict()) const;
01128                         virtual EMData * align(EMData * this_img, EMData * to_img) const
01129                         {
01130                                 return align(this_img, to_img, "sqeuclidean", Dict());
01131                         }
01132 
01133 
01136                         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;
01137 
01138                         virtual string get_name() const
01139                         {
01140                                 return NAME;
01141                         }
01142 
01143                         virtual string get_desc() const
01144                         {
01145                                 return "3D rotational and translational alignment using spherical sampling. Can reduce the search space if symmetry is supplied";
01146                         }
01147 
01148                         static Aligner *NEW()
01149                         {
01150                                 return new RT3DSphereAligner();
01151                         }
01152 
01153                         virtual TypeDict get_param_types() const
01154                         {
01155                                 TypeDict d;
01156                                 d.put("sym", EMObject::STRING,"The symmtery to use as the basis of the spherical sampling. Default is c1 (asymmetry).");
01157                                 d.put("orientgen", EMObject::STRING,"Advanced. The orientation generation strategy. Default is eman");
01158                                 d.put("delta", EMObject::FLOAT,"Angle the separates points on the sphere. This is exclusive of the \'n\' paramater. Default is 10");
01159                                 d.put("n", EMObject::INT,"An alternative to the delta argument, this is the number of points you want generated on the sphere. Default is OFF");
01160                                 d.put("dphi", EMObject::FLOAT,"The angle increment in the phi direction. Default is 10");
01161                                 d.put("phi0", EMObject::FLOAT,"Lower bound for phi. Default it 0");
01162                                 d.put("phi1", EMObject::FLOAT,"Upper bound for phi. Default it 360");
01163                                 d.put("dotrans", EMObject::BOOL,"Do a translational search. Default is True(1)");
01164                                 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.");
01165                                 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.");
01166                                 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.");
01167                                 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");
01168                                 d.put("verbose", EMObject::BOOL,"Turn this on to have useful information printed to standard out.");
01169                                 return d;
01170                         }
01171                         
01172                         static const string NAME;
01173         };
01174         
01175 
01176         class FRM2DAligner:public Aligner
01177                         {
01178                                 public:
01179                                         virtual EMData * align(EMData * this_img, EMData * to_img,
01180                                                         const string& cmp_name, const Dict& cmp_params=Dict()) const; //ming add ="frc"
01181 
01182                                         virtual EMData * align(EMData * this_img, EMData * to_img) const
01183                                         {
01184                                                 return align(this_img, to_img, "frc", Dict());
01185                                         }
01186 
01187                                         string get_name() const
01188                                         {
01189                                                 return NAME;
01190                                         }
01191 
01192                                         string get_desc() const
01193                                         {
01194                                                 return "FRM2D uses two rotational parameters and one translational parameter";
01195                                         }
01196 
01197                                         static Aligner *NEW()
01198                                         {
01199                                                 return new FRM2DAligner();
01200                                         }
01201                                         virtual TypeDict get_param_types() const
01202                                         {
01203                                                         TypeDict d;
01204                                                         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.");
01205 
01206                                                         //d.put("p_max", EMObject::FLOAT,"p_max is");
01207                                                         return d;
01208                                         }
01209 
01210                                         static const string NAME;
01211                 };
01212 
01213         
01214         class CUDA_Aligner
01215         {
01216           public:
01217                 CUDA_Aligner(int id);
01218 
01219                 void finish();
01220 
01221                 void setup(int nima, int nx, int ny, int ring_length, int nring, int ou, float step, int kx, int ky, bool ctf);
01222 
01223                 void insert_image(EMData *image, int num);
01224 
01225                 void filter_stack(vector<float> ctf_params);
01226                 
01227                 void sum_oe(vector<float> ctf_params, vector<float> ali_params, EMData* ave1, EMData *ave2);
01228 
01229                 vector<float> alignment_2d(EMData *ref_image, vector<float> sx, vector<float> sy, int silent);
01230 
01231                 vector<float> ali2d_single_iter(EMData *ref_image, vector<float> ali_params, float csx, float csy, int silent, float delta);
01232 
01233           private:
01234                 float *image_stack, *image_stack_filtered;
01235                 float *ccf;
01236                 int NIMA, NX, NY, RING_LENGTH, NRING, OU, KX, KY;
01237                 bool CTF;
01238                 float STEP;
01239         };
01240 
01241         class CUDA_multiref_aligner
01242         {
01243           public:
01244                 CUDA_multiref_aligner(int id);
01245 
01246                 void finish();
01247 
01248                 void setup(int nima, int nref, int nx, int ny, int ring_length, int nring, int ou, float step, int kx, int ky, bool ctf);
01249                 
01250                 void setup_params(vector<float> all_ali_params, vector<float> all_ctf_params);
01251 
01252                 void insert_image(EMData *image, int num);
01253                 
01254                 void insert_ref_image(EMData *image, int num);
01255 
01256                 vector<float> multiref_ali2d(int silent);
01257 
01258           private:
01259                 float *image_stack, *ref_image_stack, *ref_image_stack_filtered;
01260                 float *ccf;
01261                 float *ali_params, *ctf_params;
01262                 int NIMA, NREF, NX, NY, RING_LENGTH, NRING, OU, KX, KY, MAX_IMAGE_BATCH;
01263                 bool CTF;
01264                 float STEP;
01265         };
01266 
01267         template <> Factory < Aligner >::Factory();
01268 
01269         void dump_aligners();
01270         map<string, vector<string> > dump_aligners_list();
01271 }
01272 
01273 #endif

Generated on Mon Mar 7 17:58:46 2011 for EMAN2 by  doxygen 1.4.7