EMAN2
reconstructor.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_reconstructor_h__
00037 #define eman_reconstructor_h__ 1
00038 #include <fstream>
00039 #include <boost/shared_ptr.hpp>
00040 #include "emdata.h"
00041 #include "exception.h"
00042 #include "emobject.h"
00043 #include "interp.h"
00044 
00045 using std::vector;
00046 using std::map;
00047 using std::string;
00048 using boost::shared_ptr;
00049 
00050 using std::cout;
00051 using std::cerr;
00052 using std::endl;
00053 
00054 #include <utility>
00055 using std::pair;
00056 
00057 #include "reconstructor_tools.h"
00058 
00059 namespace EMAN
00060 {
00061 
00062         class Transform;
00063         class EMData;
00064 
00110         class Reconstructor : public FactoryBase
00111         {
00112           public:
00113                 Reconstructor() {}
00114                 virtual ~Reconstructor() {}
00117                 virtual void setup() = 0;
00118                 
00126                 virtual void setup_seed(EMData* seed,float seed_weight) {throw;}
00127 
00136                 virtual EMData* preprocess_slice( const EMData* const slice, const Transform& t = Transform() ) { EMData *ret=slice->copy(); ret->set_attr("reconstruct_preproc",(int)1); return ret; }
00137 
00146                 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight) {throw;}
00147                 int insert_slice(const EMData* const slice, const Transform & euler) { return this->insert_slice(slice, euler, 1.0f); }
00148 
00162                 virtual int determine_slice_agreement(EMData* slice, const Transform &euler, const float weight=1.0, bool sub=true ) { throw; }
00163 
00168                 virtual EMData *finish(bool doift=true) { throw; }
00169                 
00172                 virtual void clear() {throw; }
00173 
00176                 void print_params() const
00177                 {
00178                         std::cout << "Printing reconstructor params" << std::endl;
00179                         for ( Dict::const_iterator it = params.begin(); it != params.end(); ++it )
00180                         {
00181                                 std::cout << (it->first) << " " << (it->second).to_str() << std::endl;
00182                         }
00183                         std::cout << "Done printing reconstructor params" << std::endl;
00184                 }
00185 
00186 
00187                 EMObject& operator[]( const string& key ) { return params[key]; }
00188 
00189           private:
00190                 // Disallow copy construction
00191                 Reconstructor(const Reconstructor& that);
00192                 Reconstructor& operator=(const Reconstructor& );
00193 
00194         };
00195 
00207         class ReconstructorVolumeData
00208         {
00209                 public:
00213                         inline ReconstructorVolumeData() : image(0), tmp_data(0), nx(0), ny(0), nz(0), subnx(0), subny(0), subnz(0), subx0(0), suby0(0), subz0(0) {}
00214                         
00217                         virtual ~ReconstructorVolumeData() { free_memory(); }
00218 
00221                         const EMData* get_emdata() { return image; }
00222                 protected:
00223                         //These EMData pointers will most probably be allocated in setup() and released in finish()
00225                         EMData* image;
00227                         EMData* tmp_data;
00228 
00229                         // nx,ny,nz generally will store the dimensions of image
00230                         int nx,nx2;
00231                         int ny,ny2;
00232                         int nz,nz2;
00233                         
00234                         int subnx;
00235                         int subny;
00236                         int subnz;
00237                         
00238                         int subx0;
00239                         int suby0;
00240                         int subz0;
00241 
00242                 protected:
00248                         void free_memory()
00249                         {
00250                                 if (image != 0)  {delete image; image = 0;}
00251                                 if ( tmp_data != 0 ) { delete tmp_data; tmp_data = 0; }
00252                         }
00253 
00259                         virtual void normalize_threed(const bool sqrt_damp=false,const bool wiener=false);
00260 
00264                         virtual void zero_memory()
00265                         {
00266                                 if (tmp_data != 0 ) tmp_data->to_zero();
00267                                 if (image != 0 ) image->to_zero();
00268                         }
00269 
00270                 private:
00272                 ReconstructorVolumeData(const ReconstructorVolumeData& that);
00274                 ReconstructorVolumeData& operator=(const ReconstructorVolumeData& );
00275 
00276         };
00277 
00283         class FourierReconstructorSimple2D : public Reconstructor, public ReconstructorVolumeData
00284         {
00285                 public:
00286                         FourierReconstructorSimple2D() {}
00287 
00288                         virtual ~FourierReconstructorSimple2D() { }
00289 
00290                         virtual void setup();
00291 
00292                         virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight);
00293 
00294                         virtual EMData *finish(bool doift=true);
00295 
00296                         virtual string get_name() const { return NAME; }
00297 
00298                         virtual string get_desc() const { return "performs 2D reconstruction"; }
00299 
00300                         static Reconstructor *NEW()
00301                         {
00302                                 return new FourierReconstructorSimple2D();
00303                         }
00304 
00305 
00306                         virtual TypeDict get_param_types() const
00307                         {
00308                                 TypeDict d;
00309                                 d.put("nx", EMObject::INT, "Necessary. The x dimension of the input images.");
00310 //                              d.put("sym", EMObject::STRING, "Symmetry - assumed to be C1 if not specified");
00311                                 return d;
00312                         }
00313                         
00314                         static const string NAME;
00315         };
00316 
00317 
00318 
00369         class FourierReconstructor : public Reconstructor, public ReconstructorVolumeData
00370         {
00371           public:
00375                 FourierReconstructor() { load_default_settings(); }
00376 
00380                 virtual ~FourierReconstructor() { free_memory(); }
00381 
00385                 virtual void setup();
00386 
00395                 virtual void setup_seed(EMData* seed,float seed_weight);
00396 
00405                 virtual EMData* preprocess_slice( const EMData* const slice, const Transform& t = Transform() );
00406 
00416                 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight);
00417 
00418 
00435                 virtual int determine_slice_agreement(EMData* slice, const Transform &euler, const float weight=1.0, bool sub=true );
00436 
00443                 virtual EMData *finish(bool doift=true);
00444                 
00447                 virtual void clear();
00448 
00451                 virtual string get_name() const
00452                 {
00453                         return NAME;
00454                 }
00455 
00458                 virtual string get_desc() const
00459                 {
00460                         return "Reconstruction via direct Fourier methods using one of a variety of different kernels, most of which are Gaussian based";
00461                 }
00462 
00466                 static Reconstructor *NEW()
00467                 {
00468                         return new FourierReconstructor();
00469                 }
00470 
00474                 virtual TypeDict get_param_types() const
00475                 {
00476                         TypeDict d;
00477                         d.put("size", EMObject::INTARRAY, "Required. The dimensions of the real-space output volume, including any padding (must be handled by the calling application). Assumed that apix x/y/z identical.");
00478                         d.put("sym", EMObject::STRING, "Optional. The symmetry of the reconstructed volume, c?, d?, oct, tet, icos, h?. Default is c1, ie - an asymmetric object");
00479                         d.put("mode", EMObject::STRING, "Optional. Fourier pixel insertion mode name (nearest_neighbor, gauss_2, gauss_3, gauss_5, gauss_5_slow, gypergeom_5, experimental) gauss_2 is the default.");
00480                         d.put("sqrtnorm", EMObject::BOOL, "Optional. When normalizing, additionally divides by the sqrt of the normalization factor to damp exaggerated features. Is this justifyable ? No idea (yet). Default is false.");
00481                         d.put("verbose", EMObject::BOOL, "Optional. Toggles writing useful information to standard out. Default is false.");
00482                         d.put("quiet", EMObject::BOOL, "Optional. If false, print verbose information.");
00483                         d.put("subvolume",EMObject::INTARRAY, "Optional. (xorigin,yorigin,zorigin,xsize,ysize,zsize) all in Fourier pixels. Useful for parallelism.");
00484                         d.put("savenorm",EMObject::STRING, "Debug. Will cause the normalization volume to be written directly to the specified file when finish() is called.");
00485                         return d;
00486                 }
00487                 
00488                 static const string NAME;
00489 
00490           protected:
00493                 virtual void load_default_settings();
00494 
00498                 virtual void free_memory();
00499 
00502                 virtual void load_inserter();
00503 
00509                 virtual void do_insert_slice_work(const EMData* const input_slice, const Transform & euler,const float weight);
00510 
00515                 virtual void do_compare_slice_work(EMData* input_slice, const Transform & euler,float weight);
00516 
00521                 virtual bool pixel_at(const float& xx, const float& yy, const float& zz, float *dt);
00522 
00524                 FourierPixelInserter3D* inserter;
00525 
00526           private:
00529                 FourierReconstructor( const FourierReconstructor& that );
00532                 FourierReconstructor& operator=( const FourierReconstructor& );
00533 
00534         };
00535 
00536 
00537 
00548         class WienerFourierReconstructor : public FourierReconstructor
00549         {
00550           public:
00554                 WienerFourierReconstructor() {};
00555 
00559                 virtual ~WienerFourierReconstructor() { }
00560 
00561 
00571                 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight);
00572 
00573 
00590                 virtual int determine_slice_agreement(EMData* slice, const Transform &euler, const float weight=1.0, bool sub=true );
00591 
00598                 virtual EMData *finish(bool doift=true);
00599 
00602                 virtual string get_name() const
00603                 {
00604                         return NAME;
00605                 }
00606 
00609                 virtual string get_desc() const
00610                 {
00611                         return "Reconstruction via direct Fourier methods using one of a variety of different kernels, most of which are Gaussian based. This version also incorporates a nonisotropic Wiener filter based on SNR estimates stored in the class-average headers by the ctf.auto averager.";
00612                 }
00613 
00617                 static Reconstructor *NEW()
00618                 {
00619                         return new WienerFourierReconstructor();
00620                 }
00621                 
00622                 static const string NAME;
00623 
00624           protected:
00625                 
00626                 virtual void do_insert_slice_work(const EMData* const input_slice, const Transform & euler,const float weight);
00627 
00632                 virtual void do_compare_slice_work(EMData* input_slice, const Transform & euler,float weight);
00633 
00638                 virtual bool pixel_at(const float& xx, const float& yy, const float& zz, float *dt);
00639 
00641 //              FourierPixelInserter3D* inserter;
00642 
00643           private:
00646                 WienerFourierReconstructor( const WienerFourierReconstructor& that );
00649                 WienerFourierReconstructor& operator=( const WienerFourierReconstructor& );
00650 
00651         };
00652 
00703         class FourierPlaneReconstructor : public Reconstructor, public ReconstructorVolumeData
00704         {
00705           public:
00709                 FourierPlaneReconstructor() { load_default_settings(); }
00710 
00714                 virtual ~FourierPlaneReconstructor() { free_memory(); }
00715 
00719                 virtual void setup();
00720 
00729                 virtual void setup_seed(EMData* seed,float seed_weight);
00730 
00739                 virtual EMData* preprocess_slice( const EMData* const slice, const Transform& t = Transform() );
00740 
00750                 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight);
00751 
00752 
00769                 virtual int determine_slice_agreement(EMData* slice, const Transform &euler, const float weight=1.0, bool sub=true );
00770 
00777                 virtual EMData *finish(bool doift=true);
00778                 
00781                 virtual void clear();
00782 
00785                 virtual string get_name() const
00786                 {
00787                         return NAME;
00788                 }
00789 
00792                 virtual string get_desc() const
00793                 {
00794                         return "Reconstruction via direct Fourier methods using one of a variety of different kernels, most of which are Gaussian based";
00795                 }
00796 
00800                 static Reconstructor *NEW()
00801                 {
00802                         return new FourierPlaneReconstructor();
00803                 }
00804 
00808                 virtual TypeDict get_param_types() const
00809                 {
00810                         TypeDict d;
00811                         d.put("size", EMObject::INTARRAY, "Required. The dimensions of the real-space output volume, including any padding (must be handled by the calling application). Assumed that apix x/y/z identical.");
00812                         d.put("sym", EMObject::STRING, "Optional. The symmetry of the reconstructed volume, c?, d?, oct, tet, icos, h?. Default is c1, ie - an asymmetric object");
00813                         d.put("mode", EMObject::STRING, "Optional. Fourier pixel insertion mode name (nearest_neighbor, gauss_2, gauss_3, gauss_5, gauss_5_slow, gypergeom_5, experimental) gauss_2 is the default.");
00814                         d.put("sqrtnorm", EMObject::BOOL, "Optional. When normalizing, additionally divides by the sqrt of the normalization factor to damp exaggerated features. Is this justifyable ? No idea (yet). Default is false.");
00815                         d.put("verbose", EMObject::BOOL, "Optional. Toggles writing useful information to standard out. Default is false.");
00816                         d.put("quiet", EMObject::BOOL, "Optional. If false, print verbose information.");
00817                         return d;
00818                 }
00819                 
00820                 static const string NAME;
00821 
00822           protected:
00825                 virtual void load_default_settings();
00826 
00830                 virtual void free_memory();
00831 
00834                 virtual void load_inserter();
00835 
00841                 virtual void do_insert_slice_work(const EMData* const input_slice, const Transform & euler,const float weight);
00842 
00847                 virtual void do_compare_slice_work(EMData* input_slice, const Transform & euler,float weight);
00848 
00853                 virtual bool pixel_at(const float& xx, const float& yy, const float& zz, float *dt);
00854 
00856                 FourierPixelInserter3D* inserter;
00857 
00858           private:
00861                 FourierPlaneReconstructor( const FourierPlaneReconstructor& that );
00864                 FourierPlaneReconstructor& operator=( const FourierPlaneReconstructor& );
00865 
00866         };
00867 
00868         
00876         class BackProjectionReconstructor:public Reconstructor, public ReconstructorVolumeData
00877         {
00878           public:
00879                 BackProjectionReconstructor() { load_default_settings();  }
00880 
00881                 virtual ~BackProjectionReconstructor() {}
00882 
00883                 virtual void setup();
00884 
00893                 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight);
00894 
00904                 virtual int determine_slice_agreement(EMData* slice, const Transform &euler, const float weight=1.0, bool sub=true );
00905 
00906                 virtual EMData *finish(bool doift=true);
00907 
00908                 virtual string get_name() const
00909                 {
00910                         return NAME;
00911                 }
00912 
00913                 virtual string get_desc() const
00914                 {
00915                         return "Simple (unfiltered) back-projection reconstruction. Weighting by contributing particles in the class average is optional and default behaviour";
00916                 }
00917 
00918                 static Reconstructor *NEW()
00919                 {
00920                         return new BackProjectionReconstructor();
00921                 }
00922 
00923                 virtual TypeDict get_param_types() const
00924                 {
00925                         TypeDict d;
00926                         d.put("size", EMObject::INTARRAY, "Required. The dimensions of the real-space output volume, including any padding (must be handled by the calling application). Assumed that apix x/y/z identical.");
00927                         d.put("weight", EMObject::FLOAT, "Optional. A temporary value set prior to slice insertion, indicative of the inserted slice's weight. Default sis 1.");
00928                         d.put("sym", EMObject::STRING, "Optional. The symmetry to impose on the final reconstruction. Default is c1");
00929                         d.put("verbose", EMObject::BOOL, "Optional. Toggles writing useful information to standard out. Default is false.");
00930                         return d;
00931                 }
00932                 
00933                 static const string NAME;
00934                 
00935           private:
00936                 // Disallow copy construction
00937                 BackProjectionReconstructor( const BackProjectionReconstructor& that);
00938                 // Disallow assignment
00939                 BackProjectionReconstructor& operator=( const BackProjectionReconstructor& );
00940 
00941                 void load_default_settings()
00942                 {
00943                         params["weight"] = 1.0;
00944                         params["use_weights"] = true;
00945                         params["sym"] = "c1";
00946                         params["verbose"] = false;
00947                 }
00948 
00949                 EMData* preprocess_slice(const EMData* const slice, const Transform& t);
00950         };
00951 
00952 
00956         EMData* padfft_slice( const EMData* const slice, const Transform& t, int npad );
00957 
00958         class nn4Reconstructor:public Reconstructor
00959         {
00960           public:
00961                 nn4Reconstructor();
00962 
00963                 nn4Reconstructor( const string& symmetry, int size, int npad );
00964 
00965                 virtual ~nn4Reconstructor();
00966 
00967                 virtual void setup();
00968 
00977                 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight);
00978 
00979                 virtual EMData *finish(bool doift=true);
00980 
00981                 virtual string get_name() const
00982                 {
00983                         return NAME;
00984                 }
00985 
00986                 virtual string get_desc() const
00987                 {
00988                         return "Direct Fourier inversion routine";
00989                 }
00990 
00991                 static Reconstructor *NEW()
00992                 {
00993                         return new nn4Reconstructor();
00994                 }
00995 
00996                 virtual TypeDict get_param_types() const
00997                 {
00998                         TypeDict d;
00999                         d.put("size",           EMObject::INT);
01000                         d.put("npad",           EMObject::INT);
01001                         d.put("sign",           EMObject::INT);
01002                         d.put("ndim",           EMObject::INT);
01003                         d.put("snr",            EMObject::FLOAT);
01004                         d.put("symmetry",       EMObject::STRING);
01005                         d.put("snr",            EMObject::FLOAT);
01006                         d.put("fftvol",         EMObject::EMDATA);
01007                         d.put("weight",         EMObject::EMDATA);
01008                         d.put("weighting",  EMObject::INT);
01009                         return d;
01010                 }
01011 
01012                 void setup( const string& symmetry, int size, int npad );
01013 
01014                 int insert_padfft_slice( EMData* padded, const Transform& trans, float mult=1 );
01015 
01016                 static const string NAME;
01017 
01018           private:
01019                 EMData* m_volume;
01020                 EMData* m_wptr;
01021                 string  m_symmetry;
01022                 int m_weighting;
01023                 int m_vnx, m_vny, m_vnz;
01024                 int m_npad;
01025                 int m_nsym;
01026                 int m_ndim;
01027                 int m_vnzp, m_vnyp, m_vnxp;
01028                 int m_vnzc, m_vnyc, m_vnxc;
01029                 void buildFFTVolume();
01030                 void buildNormVolume();
01031                 float m_wghta;
01032                 float m_wghtb;
01033                 float m_osnr;
01034                 void load_default_settings()
01035                 {
01036                         //params["use_weights"] = false;
01037                 }
01038         };
01039 
01040 
01046         class nn4_rectReconstructor:public Reconstructor
01047         {
01048           public:
01049                 nn4_rectReconstructor();
01050 
01051                 nn4_rectReconstructor( const string& symmetry, int size, int npad );
01052 
01053                 virtual ~nn4_rectReconstructor();
01054 
01055                 virtual void setup();
01056 
01065                 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight);
01066 
01067                 virtual EMData *finish(bool doift=true);
01068 
01069                 virtual string get_name() const
01070                 {
01071                         return NAME;
01072                 }
01073 
01074                 virtual string get_desc() const
01075                 {
01076                         return "Direct Fourier inversion routine";
01077                 }
01078 
01079                 static Reconstructor *NEW()
01080                 {
01081                         return new nn4_rectReconstructor();
01082                 }
01083 
01084                 virtual TypeDict get_param_types() const
01085                 {
01086                         TypeDict d;
01087                         d.put("sizeprojection", EMObject::INT);
01088                         d.put("sizex",          EMObject::INT);
01089                         d.put("sizey",          EMObject::INT);
01090                         d.put("sizez",          EMObject::INT);
01091                         d.put("xratio",         EMObject::FLOAT);
01092                         d.put("yratio",         EMObject::FLOAT);
01093                         d.put("zratio",         EMObject::FLOAT);
01094                         d.put("npad",           EMObject::INT);
01095                         d.put("sign",           EMObject::INT);
01096                         d.put("ndim",           EMObject::INT);
01097                         d.put("snr",            EMObject::FLOAT);
01098                         d.put("symmetry",       EMObject::STRING);
01099                         d.put("snr",            EMObject::FLOAT);
01100                         d.put("fftvol",         EMObject::EMDATA);
01101                         d.put("weight",         EMObject::EMDATA);
01102                         d.put("weighting",      EMObject::INT);
01103                         return d;
01104                 }
01105 
01106                 void setup( const string& symmetry, int size, int npad );
01107 
01108                 int insert_padfft_slice( EMData* padded, const Transform& trans, float mult=1 );
01109 
01110                 static const string NAME;
01111 
01112           private:
01113                 EMData* m_volume;
01114                 EMData* m_wptr;
01115                 string  m_symmetry;
01116                 int m_weighting;
01117                 int m_vnx, m_vny, m_vnz;
01118                 int m_npad;
01119                 int m_nsym;
01120                 int m_ndim;
01121                 int m_vnzp, m_vnyp, m_vnxp;
01122                 int m_vnzc, m_vnyc, m_vnxc;
01123                 int m_count;
01124                 float m_xratio,m_yratio,m_zratio;//ratio of x,y,z direction in the 3d volume comparing to the cubic case
01125                 float m_xscale,m_yscale;//ratio of x,y direction of 2D FFT after scaling and roatating operations
01126                 int m_sizeofprojection;
01127                 void buildFFTVolume();
01128                 void buildNormVolume();
01129                 float m_wghta;
01130                 float m_wghtb;
01131                 float m_osnr;
01132                 void load_default_settings()
01133                 {
01134                         //params["use_weights"] = false;
01135                 }
01136         };
01137 
01138 
01139      /* Fourier Reconstruction by nearest neighbor with 3D SSNR
01140         Added by Zhengfan Yang on 03/16/07
01141      */
01142 
01143         class nnSSNR_Reconstructor:public Reconstructor
01144         {
01145 
01146           public:
01147                 nnSSNR_Reconstructor();
01148 
01149                 nnSSNR_Reconstructor( const string& symmetry, int size, int npad);
01150 
01151                 ~nnSSNR_Reconstructor();
01152 
01153                 virtual void setup();
01154 
01163                 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight);
01164 
01165                 virtual EMData *finish(bool doift=true);
01166 
01167                 virtual string get_name() const
01168                 {
01169                         return NAME;
01170                 }
01171 
01172                 virtual string get_desc() const
01173                 {
01174                         return "Reconstruction by nearest neighbor with 3D SSNR";
01175                 }
01176 
01177                 static Reconstructor *NEW()
01178                 {
01179                         return new nnSSNR_Reconstructor();
01180                 }
01181 
01182                 virtual TypeDict get_param_types() const
01183                 {
01184                         TypeDict d;
01185                         d.put("size", EMObject::INT);
01186                         d.put("npad", EMObject::INT);
01187                         d.put("symmetry", EMObject::STRING);
01188                         d.put("fftvol", EMObject::EMDATA);
01189                         d.put("weight", EMObject::EMDATA);
01190                         d.put("weight2", EMObject::EMDATA);
01191                         d.put("SSNR", EMObject::EMDATA);
01192                         d.put("vol_ssnr", EMObject::EMDATA);
01193                         d.put("w", EMObject::FLOAT);
01194                         return d;
01195                 }
01196 
01197                 void setup( const string& symmetry, int size, int npad);
01198 
01199                 int insert_padfft_slice( EMData* padded, const Transform& trans, float mult=1 );
01200 
01201                 static const string NAME;
01202                 
01203           private:
01204                 EMData* m_volume;
01205                 EMData* m_wptr;
01206                 EMData* m_wptr2;
01207                 string  m_symmetry;
01208                 int m_weighting;
01209                 int m_vnx, m_vny, m_vnz;
01210                 int m_npad;
01211                 int m_nsym;
01212                 int m_vnzp, m_vnyp, m_vnxp;
01213                 int m_vnzc, m_vnyc, m_vnxc;
01214                 void buildFFTVolume();
01215                 void buildNormVolume();
01216                 void buildNorm2Volume();
01217                 float m_wghta;
01218                 float m_wghtb;
01219         };
01220 
01221 
01225         class nn4_ctfReconstructor:public Reconstructor
01226         {
01227           public:
01228                 nn4_ctfReconstructor();
01229 
01230                 nn4_ctfReconstructor( const string& symmetry, int size, int npad, float snr, int sign );
01231 
01232                 virtual ~nn4_ctfReconstructor();
01233 
01234                 virtual void setup();
01235 
01245                 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight);
01246 
01247                 virtual EMData *finish(bool doift=true);
01248 
01249                 virtual string get_name() const
01250                 {
01251                         return NAME;
01252                 }
01253 
01254                 virtual string get_desc() const
01255                 {
01256                         return "Direct Fourier inversion reconstruction routine";
01257                 }
01258 
01259                 static Reconstructor *NEW()
01260                 {
01261                         return new nn4_ctfReconstructor();
01262                 }
01263 
01264 
01265                 TypeDict get_param_types() const
01266                 {
01267                         TypeDict d;
01268                         d.put("size",           EMObject::INT);
01269                         d.put("npad",           EMObject::INT);
01270                         d.put("sign",           EMObject::INT);
01271                         d.put("symmetry",       EMObject::STRING);
01272                         d.put("snr",            EMObject::FLOAT);
01273                         d.put("fftvol",         EMObject::EMDATA);
01274                         d.put("weight",         EMObject::EMDATA);
01275                         d.put("weighting",  EMObject::INT);
01276                         d.put("varsnr",     EMObject::INT);
01277                         return d;
01278                 }
01279 
01280                 void setup( const string& symmetry, int size, int npad, float snr, int sign );
01281 
01282                 int insert_padfft_slice( EMData* padfft, const Transform& trans, float mult=1);
01283 
01284                 int insert_buffed_slice( const EMData* buffer, float mult );
01285 
01286                 static const string NAME;
01287                 
01288           private:
01289                 EMData* m_volume;
01290                 EMData* m_wptr;
01291                 int m_vnx, m_vny, m_vnz;
01292                 int m_vnzp, m_vnyp, m_vnxp;
01293                 int m_vnxc, m_vnyc, m_vnzc;
01294                 int m_npad;
01295                 int m_sign;
01296                 int m_varsnr;
01297                 int m_weighting;
01298                 float m_wghta, m_wghtb;
01299                 float m_snr;
01300                 string m_symmetry;
01301                 int m_nsym;
01302 
01303                 void buildFFTVolume();
01304                 void buildNormVolume();
01305 
01306         };
01307 
01308 
01309 
01313         class nn4_ctfwReconstructor:public Reconstructor
01314         {
01315           public:
01316                 nn4_ctfwReconstructor();
01317 
01318                 nn4_ctfwReconstructor( const string& symmetry, int size, int npad, float snr, int sign );
01319 
01320                 virtual ~nn4_ctfwReconstructor();
01321 
01322                 virtual void setup();
01323 
01333                 virtual int insert_slice(const EMData* const slice, const Transform & euler, const float weight);
01334 
01335                 virtual EMData *finish(bool doift=true);
01336 
01337                 virtual string get_name() const
01338                 {
01339                         return NAME;
01340                 }
01341 
01342                 virtual string get_desc() const
01343                 {
01344                         return "Direct Fourier inversion reconstruction routine";
01345                 }
01346 
01347                 static Reconstructor *NEW()
01348                 {
01349                         return new nn4_ctfwReconstructor();
01350                 }
01351 
01352 
01353                 TypeDict get_param_types() const
01354                 {
01355                         TypeDict d;
01356                         d.put("size",           EMObject::INT);
01357                         d.put("npad",           EMObject::INT);
01358                         d.put("sign",           EMObject::INT);
01359                         d.put("symmetry",       EMObject::STRING);
01360                         d.put("snr",            EMObject::FLOAT);
01361                         d.put("fftvol",         EMObject::EMDATA);
01362                         d.put("weight",         EMObject::EMDATA);
01363                         d.put("refvol",         EMObject::EMDATA);
01364                         d.put("weighting",  EMObject::INT);
01365                         d.put("varsnr",     EMObject::INT);
01366                         return d;
01367                 }
01368 
01369                 void setup( const string& symmetry, int size, int npad, float snr, int sign );
01370 
01371                 int insert_padfft_slice_weighted( EMData* padfft, EMData* sigmasq2, const Transform& trans, const float weight);
01372 
01373                 //  It appears here one could add extra functions  int insert_buffed_slice( const EMData* buffer, float mult );
01374 
01375                 static const string NAME;
01376 
01377           private:
01378                 EMData* m_volume;
01379                 EMData* m_wptr;
01380                 EMData* m_refvol;
01381                 int m_vnx, m_vny, m_vnz;
01382                 int m_vnzp, m_vnyp, m_vnxp;
01383                 int m_vnxc, m_vnyc, m_vnzc;
01384                 int m_npad;
01385                 int m_sign;
01386                 int m_varsnr;
01387                 int m_weighting;
01388                 float m_wghta, m_wghtb;
01389                 float m_snr;
01390                 string m_symmetry;
01391                 int m_nsym;
01392 
01393                 void buildFFTVolume();
01394                 void buildNormVolume();
01395 
01396         };
01397 
01398 
01402         class nn4_ctf_rectReconstructor:public Reconstructor
01403         {
01404           public:
01405                 nn4_ctf_rectReconstructor();
01406 
01407                 nn4_ctf_rectReconstructor( const string& symmetry, int size, int npad, float snr, int sign );
01408 
01409                 virtual ~nn4_ctf_rectReconstructor();
01410 
01411                 virtual void setup();
01412 
01422                 virtual int insert_slice(const EMData* const slice, const Transform & euler, const float weight);
01423 
01424                 virtual EMData *finish(bool doift=true);
01425 
01426                 virtual string get_name() const
01427                 {
01428                         return NAME;
01429                 }
01430 
01431                 virtual string get_desc() const
01432                 {
01433                         return "Direct Fourier inversion reconstruction routine";
01434                 }
01435 
01436                 static Reconstructor *NEW()
01437                 {
01438                         return new nn4_ctf_rectReconstructor();
01439                 }
01440 
01441 
01442                 TypeDict get_param_types() const
01443                 {
01444                         TypeDict d;
01445                         d.put("size",           EMObject::INT);
01446                         d.put("npad",           EMObject::INT);
01447                         d.put("sign",           EMObject::INT);
01448                         d.put("symmetry",       EMObject::STRING);
01449                         d.put("snr",            EMObject::FLOAT);
01450                         d.put("fftvol",         EMObject::EMDATA);
01451                         d.put("weight",         EMObject::EMDATA);
01452                         d.put("refvol",         EMObject::EMDATA);
01453                         d.put("weighting",  EMObject::INT);
01454                         d.put("varsnr",     EMObject::INT);
01455                         return d;
01456                 }
01457 
01458                 void setup( const string& symmetry, int size, int npad, float snr, int sign );
01459 
01460                 int insert_padfft_slice( EMData* padfft, const Transform& trans, float mult=1);
01461 
01462                 int insert_buffed_slice( const EMData* buffer, float mult );
01463                 
01464                 static const string NAME;
01465                 
01466           private:
01467                 EMData* m_volume;
01468                 EMData* m_wptr;
01469                 int m_vnx, m_vny, m_vnz;
01470                 int m_vnzp, m_vnyp, m_vnxp;
01471                 int m_vnxc, m_vnyc, m_vnzc;
01472                 int m_count;
01473                 float m_xratio, m_yratio, m_zratio;//ratio of x,y,z direction in the 3d volume comparing to the cubic case
01474                 int m_sizeofprojection;
01475                 int m_npad;
01476                 int m_sign;
01477             int m_varsnr;
01478                 int m_weighting;
01479                 float m_wghta, m_wghtb;
01480                 float m_snr;
01481                 string m_symmetry;
01482                 int m_nsym;
01483 
01484                 void buildFFTVolume();
01485                 void buildNormVolume();
01486         };
01487 
01488 
01489 
01490      /* Fourier Reconstruction by nearest neighbor with 3D SSNR and CTF
01491         Added by Zhengfan Yang on 04/11/07
01492      */
01493 
01494         class nnSSNR_ctfReconstructor:public Reconstructor
01495         {
01496 
01497           public:
01498                 nnSSNR_ctfReconstructor();
01499 
01500                 nnSSNR_ctfReconstructor( const string& symmetry, int size, int npad, float snr, int sign);
01501 
01502                 ~nnSSNR_ctfReconstructor();
01503 
01504                 virtual void setup();
01505 
01515                 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight);
01516 
01517 
01518                 virtual EMData *finish(bool doift=true);
01519 
01520                 virtual string get_name() const
01521                 {
01522                         return NAME;
01523                 }
01524 
01525                 virtual string get_desc() const
01526                 {
01527                         return "Reconstruction by nearest neighbor with 3D SSNR with CTF";
01528                 }
01529 
01530                 static Reconstructor *NEW()
01531                 {
01532                         return new nnSSNR_ctfReconstructor();
01533                 }
01534 
01535                 TypeDict get_param_types() const
01536                 {
01537                         TypeDict d;
01538                         d.put("size",     EMObject::INT);
01539                         d.put("npad",     EMObject::INT);
01540                         d.put("symmetry", EMObject::STRING);
01541                         d.put("fftvol",   EMObject::EMDATA);
01542                         d.put("fftwvol",  EMObject::EMDATA);
01543                         d.put("weight",   EMObject::EMDATA);
01544                         d.put("weight2",  EMObject::EMDATA);
01545                         d.put("weight3",  EMObject::EMDATA);
01546                         d.put("SSNR",     EMObject::EMDATA);
01547                         d.put("vol_ssnr", EMObject::EMDATA);
01548                         d.put("w",        EMObject::FLOAT);
01549                         d.put("sign",     EMObject::INT);
01550                         d.put("snr",      EMObject::FLOAT);
01551                         return d;
01552                 }
01553                 void setup( const string& symmetry, int size, int npad, float snr, int sign);
01554 
01555                 int insert_padfft_slice( EMData* padded, const Transform& trans, float mult=1 );
01556 
01557                 static const string NAME;     
01558                 
01559           private:
01560                 EMData* m_volume;
01561                 EMData* m_wptr;
01562                 EMData* m_wptr2;
01563                 EMData* m_wptr3;
01564                 string  m_symmetry;
01565                 int m_weighting;
01566                 int m_vnx, m_vny, m_vnz;
01567                 int m_npad;
01568                 int m_nsym;
01569                 int m_vnzp, m_vnyp, m_vnxp;
01570                 int m_vnzc, m_vnyc, m_vnxc;
01571                 void buildFFTVolume();
01572                 void buildNormVolume();
01573                 void buildNorm2Volume();
01574                 void buildNorm3Volume();
01575                 float m_wghta;
01576                 float m_wghtb;
01577                 int   m_sign;
01578                 float m_snr;
01579                 int wiener;
01580         };
01581 
01582         template <> Factory < Reconstructor >::Factory();
01583 
01584         void dump_reconstructors();
01585         map<string, vector<string> > dump_reconstructors_list();
01586 
01587 
01588     struct point_t
01589     {
01590         int pos2;
01591         float real;
01592         float imag;
01593         float ctf2;
01594     };
01595 
01596 
01597         class newfile_store
01598         {
01599         public:
01600                 newfile_store( const string& prefix, int npad, bool ctf );
01601 
01602                 virtual ~newfile_store();
01603 
01604                 void add_image( EMData* data, const Transform& tf );
01605 
01606                 void add_tovol( EMData* fftvol, EMData* wgtvol, const vector<int>& mults, int pbegin, int pend );
01607 
01608                 void get_image( int id, EMData* buf );
01609 
01610         void read( int nprj );
01611 
01612                 void restart( );
01613 
01614         private:
01615                 int m_npad;
01616 
01617                 bool m_ctf;
01618 
01619                 string m_bin_file;
01620                 string m_txt_file;
01621 
01622                 shared_ptr<std::ofstream> m_bin_of;
01623                 shared_ptr<std::ofstream> m_txt_of;
01624                 shared_ptr<std::ifstream> m_bin_if;
01625                 vector< std::istream::off_type > m_offsets;
01626 
01627         vector< point_t > m_points;
01628         };
01629 
01630         class file_store
01631         {
01632           public:
01633                 file_store(const string& filename, int npad, int write, bool CTF);
01634 
01635                 virtual ~file_store();
01636 
01637                 void add_image(EMData* data, const Transform& tf);
01638 
01639                 void get_image(int id, EMData* padfft);
01640 
01641                 void restart();
01642           private:
01643                 shared_ptr<std::ifstream> m_ihandle;
01644                 shared_ptr<std::ofstream> m_bin_ohandle;
01645                 shared_ptr<std::ofstream> m_txt_ohandle;
01646                 string m_bin_file;
01647                 string m_txt_file;
01648                 int m_ctf;
01649                 int m_npad;
01650                 int m_prev;
01651                 int m_x_out;
01652                 int m_y_out;
01653                 int m_z_out;
01654                 int m_write;
01655                 std::istream::off_type m_totsize;
01656                 float m_Cs;
01657                 float m_pixel;
01658                 float m_voltage;
01659                 float m_ctf_applied;
01660                 float m_amp_contrast;
01661                 vector< float > m_defocuses;
01662                 vector< float > m_phis;
01663                 vector< float > m_thetas;
01664                 vector< float > m_psis;
01665         };
01666 
01667 }
01668 
01669 #endif
01670 
01671 /* vim: set ts=4 noet: */