00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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=1.0) {throw;}
00147
00161 virtual int determine_slice_agreement(EMData* slice, const Transform &euler, const float weight=1.0, bool sub=true ) { throw; }
00162
00167 virtual EMData *finish(bool doift=true) { throw; }
00168
00171 virtual void clear() {throw; }
00172
00175 void print_params() const
00176 {
00177 std::cout << "Printing reconstructor params" << std::endl;
00178 for ( Dict::const_iterator it = params.begin(); it != params.end(); ++it )
00179 {
00180 std::cout << (it->first) << " " << (it->second).to_str() << std::endl;
00181 }
00182 std::cout << "Done printing reconstructor params" << std::endl;
00183 }
00184
00185
00186 EMObject& operator[]( const string& key ) { return params[key]; }
00187
00188 private:
00189
00190 Reconstructor(const Reconstructor& that);
00191 Reconstructor& operator=(const Reconstructor& );
00192
00193 };
00194
00206 class ReconstructorVolumeData
00207 {
00208 public:
00212 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) {}
00213
00216 virtual ~ReconstructorVolumeData() { free_memory(); }
00217
00220 const EMData* get_emdata() { return image; }
00221 protected:
00222
00224 EMData* image;
00226 EMData* tmp_data;
00227
00228
00229 int nx,nx2;
00230 int ny,ny2;
00231 int nz,nz2;
00232
00233 int subnx;
00234 int subny;
00235 int subnz;
00236
00237 int subx0;
00238 int suby0;
00239 int subz0;
00240
00241 protected:
00247 void free_memory()
00248 {
00249 if (image != 0) {delete image; image = 0;}
00250 if ( tmp_data != 0 ) { delete tmp_data; tmp_data = 0; }
00251 }
00252
00258 virtual void normalize_threed(const bool sqrt_damp=false,const bool wiener=false);
00259
00263 virtual void zero_memory()
00264 {
00265 if (tmp_data != 0 ) tmp_data->to_zero();
00266 if (image != 0 ) image->to_zero();
00267 }
00268
00269 private:
00271 ReconstructorVolumeData(const ReconstructorVolumeData& that);
00273 ReconstructorVolumeData& operator=(const ReconstructorVolumeData& );
00274
00275 };
00276
00282 class FourierReconstructorSimple2D : public Reconstructor, public ReconstructorVolumeData
00283 {
00284 public:
00285 FourierReconstructorSimple2D() {}
00286
00287 virtual ~FourierReconstructorSimple2D() { }
00288
00289 virtual void setup();
00290
00291 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
00292
00293 virtual EMData *finish(bool doift=true);
00294
00295 virtual string get_name() const { return NAME; }
00296
00297 virtual string get_desc() const { return "performs 2D reconstruction"; }
00298
00299 static Reconstructor *NEW()
00300 {
00301 return new FourierReconstructorSimple2D();
00302 }
00303
00304
00305 virtual TypeDict get_param_types() const
00306 {
00307 TypeDict d;
00308 d.put("nx", EMObject::INT, "Necessary. The x dimension of the input images.");
00309
00310 return d;
00311 }
00312
00313 static const string NAME;
00314 };
00315
00316
00317
00368 class FourierReconstructor : public Reconstructor, public ReconstructorVolumeData
00369 {
00370 public:
00374 FourierReconstructor() { load_default_settings(); }
00375
00379 virtual ~FourierReconstructor() { free_memory(); }
00380
00384 virtual void setup();
00385
00394 virtual void setup_seed(EMData* seed,float seed_weight);
00395
00404 virtual EMData* preprocess_slice( const EMData* const slice, const Transform& t = Transform() );
00405
00415 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
00416
00417
00434 virtual int determine_slice_agreement(EMData* slice, const Transform &euler, const float weight=1.0, bool sub=true );
00435
00442 virtual EMData *finish(bool doift=true);
00443
00446 virtual void clear();
00447
00450 virtual string get_name() const
00451 {
00452 return NAME;
00453 }
00454
00457 virtual string get_desc() const
00458 {
00459 return "Reconstruction via direct Fourier methods using one of a variety of different kernels, most of which are Gaussian based";
00460 }
00461
00465 static Reconstructor *NEW()
00466 {
00467 return new FourierReconstructor();
00468 }
00469
00473 virtual TypeDict get_param_types() const
00474 {
00475 TypeDict d;
00476 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.");
00477 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");
00478 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.");
00479 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.");
00480 d.put("verbose", EMObject::BOOL, "Optional. Toggles writing useful information to standard out. Default is false.");
00481 d.put("subvolume",EMObject::INTARRAY, "Optional. (xorigin,yorigin,zorigin,xsize,ysize,zsize) all in Fourier pixels. Useful for parallelism.");
00482 d.put("savenorm",EMObject::STRING, "Debug. Will cause the normalization volume to be written directly to the specified file when finish() is called.");
00483 return d;
00484 }
00485
00486 static const string NAME;
00487
00488 protected:
00491 virtual void load_default_settings();
00492
00496 virtual void free_memory();
00497
00500 virtual void load_inserter();
00501
00507 virtual void do_insert_slice_work(const EMData* const input_slice, const Transform & euler,const float weight);
00508
00513 virtual void do_compare_slice_work(EMData* input_slice, const Transform & euler,float weight);
00514
00519 virtual bool pixel_at(const float& xx, const float& yy, const float& zz, float *dt);
00520
00522 FourierPixelInserter3D* inserter;
00523
00524 private:
00527 FourierReconstructor( const FourierReconstructor& that );
00530 FourierReconstructor& operator=( const FourierReconstructor& );
00531
00532 };
00533
00534
00535
00546 class WienerFourierReconstructor : public FourierReconstructor
00547 {
00548 public:
00552 WienerFourierReconstructor() {};
00553
00557 virtual ~WienerFourierReconstructor() { }
00558
00559
00569 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
00570
00571
00588 virtual int determine_slice_agreement(EMData* slice, const Transform &euler, const float weight=1.0, bool sub=true );
00589
00596 virtual EMData *finish(bool doift=true);
00597
00600 virtual string get_name() const
00601 {
00602 return NAME;
00603 }
00604
00607 virtual string get_desc() const
00608 {
00609 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.";
00610 }
00611
00615 static Reconstructor *NEW()
00616 {
00617 return new WienerFourierReconstructor();
00618 }
00619
00620 static const string NAME;
00621
00622 protected:
00623
00624 virtual void do_insert_slice_work(const EMData* const input_slice, const Transform & euler,const float weight);
00625
00630 virtual void do_compare_slice_work(EMData* input_slice, const Transform & euler,float weight);
00631
00636 virtual bool pixel_at(const float& xx, const float& yy, const float& zz, float *dt);
00637
00639
00640
00641 private:
00644 WienerFourierReconstructor( const WienerFourierReconstructor& that );
00647 WienerFourierReconstructor& operator=( const WienerFourierReconstructor& );
00648
00649 };
00650
00658 class BackProjectionReconstructor:public Reconstructor, public ReconstructorVolumeData
00659 {
00660 public:
00661 BackProjectionReconstructor() { load_default_settings(); }
00662
00663 virtual ~BackProjectionReconstructor() {}
00664
00665 virtual void setup();
00666
00675 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
00676
00677 virtual EMData *finish(bool doift=true);
00678
00679 virtual string get_name() const
00680 {
00681 return NAME;
00682 }
00683
00684 virtual string get_desc() const
00685 {
00686 return "Simple (unfiltered) back-projection reconstruction. Weighting by contributing particles in the class average is optional and default behaviour";
00687 }
00688
00689 static Reconstructor *NEW()
00690 {
00691 return new BackProjectionReconstructor();
00692 }
00693
00694 virtual TypeDict get_param_types() const
00695 {
00696 TypeDict d;
00697 d.put("size", EMObject::INT, "Necessary. The x and y dimensions of the input images.");
00698 d.put("weight", EMObject::FLOAT, "Optional. A temporary value set prior to slice insertion, indicative of the inserted slice's weight. Default sis 1.");
00699 d.put("sym", EMObject::STRING, "Optional. The symmetry to impose on the final reconstruction. Default is c1");
00700 d.put("zsample", EMObject::INT, "Optional. The z dimensions of the reconstructed volume.");
00701 return d;
00702 }
00703
00704 static const string NAME;
00705
00706 private:
00707
00708 BackProjectionReconstructor( const BackProjectionReconstructor& that);
00709
00710 BackProjectionReconstructor& operator=( const BackProjectionReconstructor& );
00711
00712 void load_default_settings()
00713 {
00714 params["weight"] = 1.0;
00715 params["use_weights"] = true;
00716 params["size"] = 0;
00717 params["sym"] = "c1";
00718 params["zsample"] = 0;
00719 }
00720
00721 EMData* preprocess_slice(const EMData* const slice, const Transform& t);
00722 };
00723
00724
00728 EMData* padfft_slice( const EMData* const slice, const Transform& t, int npad );
00729
00730 class nn4Reconstructor:public Reconstructor
00731 {
00732 public:
00733 nn4Reconstructor();
00734
00735 nn4Reconstructor( const string& symmetry, int size, int npad );
00736
00737 virtual ~nn4Reconstructor();
00738
00739 virtual void setup();
00740
00749 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
00750
00751 virtual EMData *finish(bool doift=true);
00752
00753 virtual string get_name() const
00754 {
00755 return NAME;
00756 }
00757
00758 virtual string get_desc() const
00759 {
00760 return "Direct Fourier inversion routine";
00761 }
00762
00763 static Reconstructor *NEW()
00764 {
00765 return new nn4Reconstructor();
00766 }
00767
00768 virtual TypeDict get_param_types() const
00769 {
00770 TypeDict d;
00771 d.put("size", EMObject::INT);
00772 d.put("npad", EMObject::INT);
00773 d.put("sign", EMObject::INT);
00774 d.put("ndim", EMObject::INT);
00775 d.put("snr", EMObject::FLOAT);
00776 d.put("symmetry", EMObject::STRING);
00777 d.put("snr", EMObject::FLOAT);
00778 d.put("fftvol", EMObject::EMDATA);
00779 d.put("weight", EMObject::EMDATA);
00780 d.put("weighting", EMObject::INT);
00781 return d;
00782 }
00783
00784 void setup( const string& symmetry, int size, int npad );
00785
00786 int insert_padfft_slice( EMData* padded, const Transform& trans, int mult=1 );
00787
00788 static const string NAME;
00789
00790 private:
00791 EMData* m_volume;
00792 EMData* m_wptr;
00793 EMData* m_result;
00794 bool m_delete_volume;
00795 bool m_delete_weight;
00796 string m_symmetry;
00797 int m_weighting;
00798 int m_vnx, m_vny, m_vnz;
00799 int m_npad;
00800 int m_nsym;
00801 int m_ndim;
00802 int m_vnzp, m_vnyp, m_vnxp;
00803 int m_vnzc, m_vnyc, m_vnxc;
00804 void buildFFTVolume();
00805 void buildNormVolume();
00806 float m_wghta;
00807 float m_wghtb;
00808 float m_osnr;
00809 void load_default_settings()
00810 {
00811
00812 }
00813 };
00814
00815
00821 class nn4_rectReconstructor:public Reconstructor
00822 {
00823 public:
00824 nn4_rectReconstructor();
00825
00826 nn4_rectReconstructor( const string& symmetry, int size, int npad );
00827
00828 virtual ~nn4_rectReconstructor();
00829
00830 virtual void setup();
00831
00840 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
00841
00842 virtual EMData *finish(bool doift=true);
00843
00844 virtual string get_name() const
00845 {
00846 return NAME;
00847 }
00848
00849 virtual string get_desc() const
00850 {
00851 return "Direct Fourier inversion routine";
00852 }
00853
00854 static Reconstructor *NEW()
00855 {
00856 return new nn4_rectReconstructor();
00857 }
00858
00859 virtual TypeDict get_param_types() const
00860 {
00861 TypeDict d;
00862 d.put("sizeprojection", EMObject::INT);
00863 d.put("sizex", EMObject::INT);
00864 d.put("sizey", EMObject::INT);
00865 d.put("sizez", EMObject::INT);
00866 d.put("xratio", EMObject::FLOAT);
00867 d.put("yratio", EMObject::FLOAT);
00868 d.put("npad", EMObject::INT);
00869 d.put("sign", EMObject::INT);
00870 d.put("ndim", EMObject::INT);
00871 d.put("snr", EMObject::FLOAT);
00872 d.put("symmetry", EMObject::STRING);
00873 d.put("snr", EMObject::FLOAT);
00874 d.put("fftvol", EMObject::EMDATA);
00875 d.put("weight", EMObject::EMDATA);
00876 d.put("weighting", EMObject::INT);
00877 return d;
00878 }
00879
00880 void setup( const string& symmetry, int size, int npad );
00881
00882 int insert_padfft_slice( EMData* padded, const Transform& trans, int mult=1 );
00883
00884 static const string NAME;
00885
00886 private:
00887 EMData* m_volume;
00888 EMData* m_wptr;
00889 EMData* m_result;
00890 bool m_delete_volume;
00891 bool m_delete_weight;
00892 string m_symmetry;
00893 int m_weighting;
00894 int m_vnx, m_vny, m_vnz;
00895 int m_npad;
00896 int m_nsym;
00897 int m_ndim;
00898 int m_vnzp, m_vnyp, m_vnxp;
00899 int m_vnzc, m_vnyc, m_vnxc;
00900 int m_count;
00901 float m_xratio,m_yratio,m_zratio;
00902 float m_xscale,m_yscale;
00903 int m_sizeofprojection;
00904 void buildFFTVolume();
00905 void buildNormVolume();
00906 float m_wghta;
00907 float m_wghtb;
00908 float m_osnr;
00909 void load_default_settings()
00910 {
00911
00912 }
00913 };
00914
00915
00916
00917
00918
00919
00920 class nnSSNR_Reconstructor:public Reconstructor
00921 {
00922
00923 public:
00924 nnSSNR_Reconstructor();
00925
00926 nnSSNR_Reconstructor( const string& symmetry, int size, int npad);
00927
00928 ~nnSSNR_Reconstructor();
00929
00930 virtual void setup();
00931
00940 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
00941
00942 virtual EMData *finish(bool doift=true);
00943
00944 virtual string get_name() const
00945 {
00946 return NAME;
00947 }
00948
00949 virtual string get_desc() const
00950 {
00951 return "Reconstruction by nearest neighbor with 3D SSNR";
00952 }
00953
00954 static Reconstructor *NEW()
00955 {
00956 return new nnSSNR_Reconstructor();
00957 }
00958
00959 virtual TypeDict get_param_types() const
00960 {
00961 TypeDict d;
00962 d.put("size", EMObject::INT);
00963 d.put("npad", EMObject::INT);
00964 d.put("symmetry", EMObject::STRING);
00965 d.put("fftvol", EMObject::EMDATA);
00966 d.put("weight", EMObject::EMDATA);
00967 d.put("weight2", EMObject::EMDATA);
00968 d.put("SSNR", EMObject::EMDATA);
00969 d.put("w", EMObject::FLOAT);
00970 return d;
00971 }
00972
00973 void setup( const string& symmetry, int size, int npad);
00974
00975 int insert_padfft_slice( EMData* padded, const Transform& trans, int mult=1 );
00976
00977 static const string NAME;
00978
00979 private:
00980 EMData* m_volume;
00981 EMData* m_wptr;
00982 EMData* m_wptr2;
00983 EMData* m_result;
00984 bool m_delete_volume;
00985 bool m_delete_weight;
00986 bool m_delete_weight2;
00987 string m_symmetry;
00988 int m_weighting;
00989 int m_vnx, m_vny, m_vnz;
00990 int m_npad;
00991 int m_nsym;
00992 int m_vnzp, m_vnyp, m_vnxp;
00993 int m_vnzc, m_vnyc, m_vnxc;
00994 void buildFFTVolume();
00995 void buildNormVolume();
00996 void buildNorm2Volume();
00997 float m_wghta;
00998 float m_wghtb;
00999 };
01000
01001
01005 class nn4_ctfReconstructor:public Reconstructor
01006 {
01007 public:
01008 nn4_ctfReconstructor();
01009
01010 nn4_ctfReconstructor( const string& symmetry, int size, int npad, float snr, int sign );
01011
01012 virtual ~nn4_ctfReconstructor();
01013
01014 virtual void setup();
01015
01025 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
01026
01027 virtual EMData *finish(bool doift=true);
01028
01029 virtual string get_name() const
01030 {
01031 return NAME;
01032 }
01033
01034 virtual string get_desc() const
01035 {
01036 return "Direct Fourier inversion reconstruction routine";
01037 }
01038
01039 static Reconstructor *NEW()
01040 {
01041 return new nn4_ctfReconstructor();
01042 }
01043
01044
01045 TypeDict get_param_types() const
01046 {
01047 TypeDict d;
01048 d.put("size", EMObject::INT);
01049 d.put("npad", EMObject::INT);
01050 d.put("sign", EMObject::INT);
01051 d.put("symmetry", EMObject::STRING);
01052 d.put("snr", EMObject::FLOAT);
01053 d.put("fftvol", EMObject::EMDATA);
01054 d.put("weight", EMObject::EMDATA);
01055 d.put("weighting", EMObject::INT);
01056 d.put("varsnr", EMObject::INT);
01057 return d;
01058 }
01059
01060 void setup( const string& symmetry, int size, int npad, float snr, int sign );
01061
01062 int insert_padfft_slice( EMData* padfft, const Transform& trans, int mult=1);
01063
01064 int insert_buffed_slice( const EMData* buffer, int mult );
01065
01066 static const string NAME;
01067
01068 private:
01069 EMData* m_volume;
01070 EMData* m_result;
01071 EMData* m_wptr;
01072 bool m_delete_volume;
01073 bool m_delete_weight;
01074 int m_vnx, m_vny, m_vnz;
01075 int m_vnzp, m_vnyp, m_vnxp;
01076 int m_vnxc, m_vnyc, m_vnzc;
01077 int m_npad;
01078 int m_sign;
01079 int m_varsnr;
01080 int m_weighting;
01081 float m_wghta, m_wghtb;
01082 float m_snr;
01083 string m_symmetry;
01084 int m_nsym;
01085
01086 void buildFFTVolume();
01087 void buildNormVolume();
01088
01089 };
01090
01091
01095 class nn4_ctf_rectReconstructor:public Reconstructor
01096 {
01097 public:
01098 nn4_ctf_rectReconstructor();
01099
01100 nn4_ctf_rectReconstructor( const string& symmetry, int size, int npad, float snr, int sign );
01101
01102 virtual ~nn4_ctf_rectReconstructor();
01103
01104 virtual void setup();
01105
01115 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
01116
01117 virtual EMData *finish(bool doift=true);
01118
01119 virtual string get_name() const
01120 {
01121 return NAME;
01122 }
01123
01124 virtual string get_desc() const
01125 {
01126 return "Direct Fourier inversion reconstruction routine";
01127 }
01128
01129 static Reconstructor *NEW()
01130 {
01131 return new nn4_ctf_rectReconstructor();
01132 }
01133
01134
01135 TypeDict get_param_types() const
01136 {
01137 TypeDict d;
01138 d.put("sizeprojection", EMObject::INT);
01139 d.put("sizex", EMObject::INT);
01140 d.put("sizey", EMObject::INT);
01141 d.put("sizez", EMObject::INT);
01142 d.put("xratio", EMObject::FLOAT);
01143 d.put("yratio", EMObject::FLOAT);
01144 d.put("size", EMObject::INT);
01145 d.put("npad", EMObject::INT);
01146 d.put("sign", EMObject::INT);
01147 d.put("symmetry", EMObject::STRING);
01148 d.put("snr", EMObject::FLOAT);
01149 d.put("fftvol", EMObject::EMDATA);
01150 d.put("weight", EMObject::EMDATA);
01151 d.put("weighting", EMObject::INT);
01152 d.put("varsnr", EMObject::INT);
01153 return d;
01154 }
01155
01156 void setup( const string& symmetry, int size, int npad, float snr, int sign );
01157
01158 int insert_padfft_slice( EMData* padfft, const Transform& trans, int mult=1);
01159
01160 int insert_buffed_slice( const EMData* buffer, int mult );
01161
01162 static const string NAME;
01163
01164 private:
01165 EMData* m_volume;
01166 EMData* m_result;
01167 EMData* m_wptr;
01168 bool m_delete_volume;
01169 bool m_delete_weight;
01170 int m_vnx, m_vny, m_vnz;
01171 int m_vnzp, m_vnyp, m_vnxp;
01172 int m_vnxc, m_vnyc, m_vnzc;
01173 int m_count;
01174 float m_xratio,m_yratio,m_zratio;
01175 float m_xscale,m_yscale;
01176 int m_sizeofprojection;
01177 int m_npad;
01178 int m_sign;
01179 int m_varsnr;
01180 int m_weighting;
01181 float m_wghta, m_wghtb;
01182 float m_snr;
01183 string m_symmetry;
01184 int m_nsym;
01185
01186 void buildFFTVolume();
01187 void buildNormVolume();
01188
01189 };
01190
01191
01192
01193
01194
01195
01196
01197 class nnSSNR_ctfReconstructor:public Reconstructor
01198 {
01199
01200 public:
01201 nnSSNR_ctfReconstructor();
01202
01203 nnSSNR_ctfReconstructor( const string& symmetry, int size, int npad, float snr, int sign);
01204
01205 ~nnSSNR_ctfReconstructor();
01206
01207 virtual void setup();
01208
01218 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
01219
01220
01221 virtual EMData *finish(bool doift=true);
01222
01223 virtual string get_name() const
01224 {
01225 return NAME;
01226 }
01227
01228 virtual string get_desc() const
01229 {
01230 return "Reconstruction by nearest neighbor with 3D SSNR with CTF";
01231 }
01232
01233 static Reconstructor *NEW()
01234 {
01235 return new nnSSNR_ctfReconstructor();
01236 }
01237
01238 TypeDict get_param_types() const
01239 {
01240 TypeDict d;
01241 d.put("size", EMObject::INT);
01242 d.put("npad", EMObject::INT);
01243 d.put("symmetry", EMObject::STRING);
01244 d.put("fftvol", EMObject::EMDATA);
01245 d.put("fftwvol", EMObject::EMDATA);
01246 d.put("weight", EMObject::EMDATA);
01247 d.put("weight2", EMObject::EMDATA);
01248 d.put("weight3", EMObject::EMDATA);
01249 d.put("SSNR", EMObject::EMDATA);
01250 d.put("w", EMObject::FLOAT);
01251 d.put("sign", EMObject::INT);
01252 d.put("snr", EMObject::FLOAT);
01253 return d;
01254 }
01255 void setup( const string& symmetry, int size, int npad, float snr, int sign);
01256
01257 int insert_padfft_slice( EMData* padded, const Transform& trans, int mult=1 );
01258
01259 static const string NAME;
01260
01261 private:
01262 EMData* m_volume;
01263 EMData* m_wptr;
01264 EMData* m_wptr2;
01265 EMData* m_wptr3;
01266 EMData* m_result;
01267 bool m_delete_volume;
01268 bool m_delete_weight;
01269 bool m_delete_weight2;
01270 bool m_delete_weight3;
01271 string m_symmetry;
01272 int m_weighting;
01273 int m_vnx, m_vny, m_vnz;
01274 int m_npad;
01275 int m_nsym;
01276 int m_vnzp, m_vnyp, m_vnxp;
01277 int m_vnzc, m_vnyc, m_vnxc;
01278 void buildFFTVolume();
01279 void buildNormVolume();
01280 void buildNorm2Volume();
01281 void buildNorm3Volume();
01282 float m_wghta;
01283 float m_wghtb;
01284 int m_sign;
01285 float m_snr;
01286 int wiener;
01287 };
01288
01289 template <> Factory < Reconstructor >::Factory();
01290
01291 void dump_reconstructors();
01292 map<string, vector<string> > dump_reconstructors_list();
01293
01294
01295 struct point_t
01296 {
01297 int pos2;
01298 float real;
01299 float imag;
01300 float ctf2;
01301 };
01302
01303
01304 class newfile_store
01305 {
01306 public:
01307 newfile_store( const string& prefix, int npad, bool ctf );
01308
01309 virtual ~newfile_store();
01310
01311 void add_image( EMData* data, const Transform& tf );
01312
01313 void add_tovol( EMData* fftvol, EMData* wgtvol, const vector<int>& mults, int pbegin, int pend );
01314
01315 void get_image( int id, EMData* buf );
01316
01317 void read( int nprj );
01318
01319 void restart( );
01320
01321 private:
01322 int m_npad;
01323
01324 bool m_ctf;
01325
01326 string m_bin_file;
01327 string m_txt_file;
01328
01329 shared_ptr<std::ofstream> m_bin_of;
01330 shared_ptr<std::ofstream> m_txt_of;
01331 shared_ptr<std::ifstream> m_bin_if;
01332 vector< std::istream::off_type > m_offsets;
01333
01334 vector< point_t > m_points;
01335 };
01336
01337 class file_store
01338 {
01339 public:
01340 file_store(const string& filename, int npad, int write, bool CTF);
01341
01342 virtual ~file_store();
01343
01344 void add_image(EMData* data, const Transform& tf);
01345
01346 void get_image(int id, EMData* padfft);
01347
01348 void restart();
01349 private:
01350 shared_ptr<std::ifstream> m_ihandle;
01351 shared_ptr<std::ofstream> m_bin_ohandle;
01352 shared_ptr<std::ofstream> m_txt_ohandle;
01353 string m_bin_file;
01354 string m_txt_file;
01355 int m_ctf;
01356 int m_npad;
01357 int m_prev;
01358 int m_x_out;
01359 int m_y_out;
01360 int m_z_out;
01361 int m_write;
01362 std::istream::off_type m_totsize;
01363 float m_Cs;
01364 float m_pixel;
01365 float m_voltage;
01366 float m_ctf_applied;
01367 float m_amp_contrast;
01368 vector< float > m_defocuses;
01369 vector< float > m_phis;
01370 vector< float > m_thetas;
01371 vector< float > m_psis;
01372 };
01373
01374 }
01375
01376 #endif
01377
01378