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 Transform3D;
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 void print_params() const
00172 {
00173 std::cout << "Printing reconstructor params" << std::endl;
00174 for ( Dict::const_iterator it = params.begin(); it != params.end(); ++it )
00175 {
00176 std::cout << (it->first) << " " << (it->second).to_str() << std::endl;
00177 }
00178 std::cout << "Done printing reconstructor params" << std::endl;
00179 }
00180
00181
00182 EMObject& operator[]( const string& key ) { return params[key]; }
00183
00184 private:
00185
00186 Reconstructor(const Reconstructor& that);
00187 Reconstructor& operator=(const Reconstructor& );
00188
00189 };
00190
00202 class ReconstructorVolumeData
00203 {
00204 public:
00208 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) {}
00209
00212 virtual ~ReconstructorVolumeData() { free_memory(); }
00213
00216 const EMData* const get_emdata() { return image; }
00217 protected:
00218
00220 EMData* image;
00222 EMData* tmp_data;
00223
00224
00225 int nx,nx2;
00226 int ny,ny2;
00227 int nz,nz2;
00228
00229 int subnx;
00230 int subny;
00231 int subnz;
00232
00233 int subx0;
00234 int suby0;
00235 int subz0;
00236
00237 protected:
00243 void free_memory()
00244 {
00245 if (image != 0) {delete image; image = 0;}
00246 if ( tmp_data != 0 ) { delete tmp_data; tmp_data = 0; }
00247 }
00248
00254 virtual void normalize_threed(const bool sqrt_damp=false,const bool wiener=false);
00255
00259 virtual void zero_memory()
00260 {
00261 if (tmp_data != 0 ) tmp_data->to_zero();
00262 if (image != 0 ) image->to_zero();
00263 }
00264
00265 private:
00267 ReconstructorVolumeData(const ReconstructorVolumeData& that);
00269 ReconstructorVolumeData& operator=(const ReconstructorVolumeData& );
00270
00271 };
00272
00278 class FourierReconstructorSimple2D : public Reconstructor, public ReconstructorVolumeData
00279 {
00280 public:
00281 FourierReconstructorSimple2D() {}
00282
00283 virtual ~FourierReconstructorSimple2D() { }
00284
00285 virtual void setup();
00286
00287 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
00288
00289 virtual EMData *finish(bool doift=true);
00290
00291 virtual string get_name() const { return NAME; }
00292
00293 virtual string get_desc() const { return "performs 2D reconstruction"; }
00294
00295 static Reconstructor *NEW()
00296 {
00297 return new FourierReconstructorSimple2D();
00298 }
00299
00300
00301 virtual TypeDict get_param_types() const
00302 {
00303 TypeDict d;
00304 d.put("nx", EMObject::INT, "Necessary. The x dimension of the input images.");
00305
00306 return d;
00307 }
00308
00309 static const string NAME;
00310 };
00311
00312
00313
00363 class FourierReconstructor : public Reconstructor, public ReconstructorVolumeData
00364 {
00365 public:
00369 FourierReconstructor() { load_default_settings(); }
00370
00374 virtual ~FourierReconstructor() { free_memory(); }
00375
00379 virtual void setup();
00380
00389 virtual void setup_seed(EMData* seed,float seed_weight);
00390
00399 virtual EMData* preprocess_slice( const EMData* const slice, const Transform& t = Transform() );
00400
00410 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
00411
00412
00429 virtual int determine_slice_agreement(EMData* slice, const Transform &euler, const float weight=1.0, bool sub=true );
00430
00437 virtual EMData *finish(bool doift=true);
00438
00441 virtual string get_name() const
00442 {
00443 return NAME;
00444 }
00445
00448 virtual string get_desc() const
00449 {
00450 return "Reconstruction via direct Fourier methods using one of a variety of different kernels, most of which are Gaussian based";
00451 }
00452
00456 static Reconstructor *NEW()
00457 {
00458 return new FourierReconstructor();
00459 }
00460
00464 virtual TypeDict get_param_types() const
00465 {
00466 TypeDict d;
00467 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.");
00468 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");
00469 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.");
00470 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.");
00471 d.put("verbose", EMObject::BOOL, "Optional. Toggles writing useful information to standard out. Default is false.");
00472 d.put("subvolume",EMObject::INTARRAY, "Optional. (xorigin,yorigin,zorigin,xsize,ysize,zsize) all in Fourier pixels. Useful for parallelism.");
00473 d.put("savenorm",EMObject::STRING, "Debug. Will cause the normalization volume to be written directly to the specified file when finish() is called.");
00474 return d;
00475 }
00476
00477 static const string NAME;
00478
00479 protected:
00482 virtual void load_default_settings();
00483
00487 virtual void free_memory();
00488
00491 virtual void load_inserter();
00492
00498 virtual void do_insert_slice_work(const EMData* const input_slice, const Transform & euler,const float weight);
00499
00504 virtual void do_compare_slice_work(EMData* input_slice, const Transform & euler,float weight);
00505
00510 virtual bool pixel_at(const float& xx, const float& yy, const float& zz, float *dt);
00511
00513 FourierPixelInserter3D* inserter;
00514
00515 private:
00518 FourierReconstructor( const FourierReconstructor& that );
00521 FourierReconstructor& operator=( const FourierReconstructor& );
00522
00523 };
00524
00525
00526
00537 class WienerFourierReconstructor : public FourierReconstructor
00538 {
00539 public:
00543 WienerFourierReconstructor() {};
00544
00548 virtual ~WienerFourierReconstructor() { }
00549
00550
00560 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
00561
00562
00579 virtual int determine_slice_agreement(EMData* slice, const Transform &euler, const float weight=1.0, bool sub=true );
00580
00587 virtual EMData *finish(bool doift=true);
00588
00591 virtual string get_name() const
00592 {
00593 return NAME;
00594 }
00595
00598 virtual string get_desc() const
00599 {
00600 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.";
00601 }
00602
00606 static Reconstructor *NEW()
00607 {
00608 return new WienerFourierReconstructor();
00609 }
00610
00611 static const string NAME;
00612
00613 protected:
00614
00615 virtual void do_insert_slice_work(const EMData* const input_slice, const Transform & euler,const float weight);
00616
00621 virtual void do_compare_slice_work(EMData* input_slice, const Transform & euler,float weight);
00622
00627 virtual bool pixel_at(const float& xx, const float& yy, const float& zz, float *dt);
00628
00630
00631
00632 private:
00635 WienerFourierReconstructor( const WienerFourierReconstructor& that );
00638 WienerFourierReconstructor& operator=( const WienerFourierReconstructor& );
00639
00640 };
00641
00649 class BackProjectionReconstructor:public Reconstructor, public ReconstructorVolumeData
00650 {
00651 public:
00652 BackProjectionReconstructor() { load_default_settings(); }
00653
00654 virtual ~BackProjectionReconstructor() {}
00655
00656 virtual void setup();
00657
00666 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
00667
00668 virtual EMData *finish(bool doift=true);
00669
00670 virtual string get_name() const
00671 {
00672 return NAME;
00673 }
00674
00675 virtual string get_desc() const
00676 {
00677 return "Simple (unfiltered) back-projection reconstruction. Weighting by contributing particles in the class average is optional and default behaviour";
00678 }
00679
00680 static Reconstructor *NEW()
00681 {
00682 return new BackProjectionReconstructor();
00683 }
00684
00685 virtual TypeDict get_param_types() const
00686 {
00687 TypeDict d;
00688 d.put("size", EMObject::INT, "Necessary. The x and y dimensions of the input images.");
00689 d.put("weight", EMObject::FLOAT, "Optional. A temporary value set prior to slice insertion, indicative of the inserted slice's weight. Default sis 1.");
00690 d.put("sym", EMObject::STRING, "Optional. The symmetry to impose on the final reconstruction. Default is c1");
00691 d.put("zsample", EMObject::INT, "Optional. The z dimensions of the reconstructed volume.");
00692 return d;
00693 }
00694
00695 static const string NAME;
00696
00697 private:
00698
00699 BackProjectionReconstructor( const BackProjectionReconstructor& that);
00700
00701 BackProjectionReconstructor& operator=( const BackProjectionReconstructor& );
00702
00703 void load_default_settings()
00704 {
00705 params["weight"] = 1.0;
00706 params["use_weights"] = true;
00707 params["size"] = 0;
00708 params["sym"] = "c1";
00709 params["zsample"] = 0;
00710 }
00711
00712 EMData* preprocess_slice(const EMData* const slice, const Transform& t);
00713 };
00714
00715
00719 EMData* padfft_slice( const EMData* const slice, const Transform& t, int npad );
00720
00721 class nn4Reconstructor:public Reconstructor
00722 {
00723 public:
00724 nn4Reconstructor();
00725
00726 nn4Reconstructor( const string& symmetry, int size, int npad );
00727
00728 virtual ~nn4Reconstructor();
00729
00730 virtual void setup();
00731
00740 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
00741
00742 virtual EMData *finish(bool doift=true);
00743
00744 virtual string get_name() const
00745 {
00746 return NAME;
00747 }
00748
00749 virtual string get_desc() const
00750 {
00751 return "Direct Fourier inversion routine";
00752 }
00753
00754 static Reconstructor *NEW()
00755 {
00756 return new nn4Reconstructor();
00757 }
00758
00759 virtual TypeDict get_param_types() const
00760 {
00761 TypeDict d;
00762 d.put("size", EMObject::INT);
00763 d.put("npad", EMObject::INT);
00764 d.put("sign", EMObject::INT);
00765 d.put("ndim", EMObject::INT);
00766 d.put("snr", EMObject::FLOAT);
00767 d.put("symmetry", EMObject::STRING);
00768 d.put("snr", EMObject::FLOAT);
00769 d.put("fftvol", EMObject::EMDATA);
00770 d.put("weight", EMObject::EMDATA);
00771 d.put("weighting", EMObject::INT);
00772 return d;
00773 }
00774
00775 void setup( const string& symmetry, int size, int npad );
00776
00777 int insert_padfft_slice( EMData* padded, const Transform& trans, int mult=1 );
00778
00779 static const string NAME;
00780
00781 private:
00782 EMData* m_volume;
00783 EMData* m_wptr;
00784 EMData* m_result;
00785 bool m_delete_volume;
00786 bool m_delete_weight;
00787 string m_symmetry;
00788 int m_weighting;
00789 int m_vnx, m_vny, m_vnz;
00790 int m_npad;
00791 int m_nsym;
00792 int m_ndim;
00793 int m_vnzp, m_vnyp, m_vnxp;
00794 int m_vnzc, m_vnyc, m_vnxc;
00795 void buildFFTVolume();
00796 void buildNormVolume();
00797 float m_wghta;
00798 float m_wghtb;
00799 float m_osnr;
00800 void load_default_settings()
00801 {
00802
00803 }
00804 };
00805
00806
00812 class nn4_rectReconstructor:public Reconstructor
00813 {
00814 public:
00815 nn4_rectReconstructor();
00816
00817 nn4_rectReconstructor( const string& symmetry, int size, int npad );
00818
00819 virtual ~nn4_rectReconstructor();
00820
00821 virtual void setup();
00822
00831 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
00832
00833 virtual EMData *finish(bool doift=true);
00834
00835 virtual string get_name() const
00836 {
00837 return NAME;
00838 }
00839
00840 virtual string get_desc() const
00841 {
00842 return "Direct Fourier inversion routine";
00843 }
00844
00845 static Reconstructor *NEW()
00846 {
00847 return new nn4_rectReconstructor();
00848 }
00849
00850 virtual TypeDict get_param_types() const
00851 {
00852 TypeDict d;
00853 d.put("sizeprojection", EMObject::INT);
00854 d.put("sizex", EMObject::INT);
00855 d.put("sizey", EMObject::INT);
00856 d.put("sizez", EMObject::INT);
00857 d.put("xratio", EMObject::FLOAT);
00858 d.put("yratio", EMObject::FLOAT);
00859 d.put("npad", EMObject::INT);
00860 d.put("sign", EMObject::INT);
00861 d.put("ndim", EMObject::INT);
00862 d.put("snr", EMObject::FLOAT);
00863 d.put("symmetry", EMObject::STRING);
00864 d.put("snr", EMObject::FLOAT);
00865 d.put("fftvol", EMObject::EMDATA);
00866 d.put("weight", EMObject::EMDATA);
00867 d.put("weighting", EMObject::INT);
00868 return d;
00869 }
00870
00871 void setup( const string& symmetry, int size, int npad );
00872
00873 int insert_padfft_slice( EMData* padded, const Transform& trans, int mult=1 );
00874
00875 static const string NAME;
00876
00877 private:
00878 EMData* m_volume;
00879 EMData* m_wptr;
00880 EMData* m_result;
00881 bool m_delete_volume;
00882 bool m_delete_weight;
00883 string m_symmetry;
00884 int m_weighting;
00885 int m_vnx, m_vny, m_vnz;
00886 int m_npad;
00887 int m_nsym;
00888 int m_ndim;
00889 int m_vnzp, m_vnyp, m_vnxp;
00890 int m_vnzc, m_vnyc, m_vnxc;
00891 int m_count;
00892 float m_xratio,m_yratio,m_zratio;
00893 float m_xscale,m_yscale;
00894 int m_sizeofprojection;
00895 void buildFFTVolume();
00896 void buildNormVolume();
00897 float m_wghta;
00898 float m_wghtb;
00899 float m_osnr;
00900 void load_default_settings()
00901 {
00902
00903 }
00904 };
00905
00906
00907
00908
00909
00910
00911 class nnSSNR_Reconstructor:public Reconstructor
00912 {
00913
00914 public:
00915 nnSSNR_Reconstructor();
00916
00917 nnSSNR_Reconstructor( const string& symmetry, int size, int npad);
00918
00919 ~nnSSNR_Reconstructor();
00920
00921 virtual void setup();
00922
00931 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
00932
00933 virtual EMData *finish(bool doift=true);
00934
00935 virtual string get_name() const
00936 {
00937 return NAME;
00938 }
00939
00940 virtual string get_desc() const
00941 {
00942 return "Reconstruction by nearest neighbor with 3D SSNR";
00943 }
00944
00945 static Reconstructor *NEW()
00946 {
00947 return new nnSSNR_Reconstructor();
00948 }
00949
00950 virtual TypeDict get_param_types() const
00951 {
00952 TypeDict d;
00953 d.put("size", EMObject::INT);
00954 d.put("npad", EMObject::INT);
00955 d.put("symmetry", EMObject::STRING);
00956 d.put("fftvol", EMObject::EMDATA);
00957 d.put("weight", EMObject::EMDATA);
00958 d.put("weight2", EMObject::EMDATA);
00959 d.put("SSNR", EMObject::EMDATA);
00960 d.put("w", EMObject::FLOAT);
00961 return d;
00962 }
00963
00964 void setup( const string& symmetry, int size, int npad);
00965
00966 int insert_padfft_slice( EMData* padded, const Transform& trans, int mult=1 );
00967
00968 static const string NAME;
00969
00970 private:
00971 EMData* m_volume;
00972 EMData* m_wptr;
00973 EMData* m_wptr2;
00974 EMData* m_result;
00975 bool m_delete_volume;
00976 bool m_delete_weight;
00977 bool m_delete_weight2;
00978 string m_symmetry;
00979 int m_weighting;
00980 int m_vnx, m_vny, m_vnz;
00981 int m_npad;
00982 int m_nsym;
00983 int m_vnzp, m_vnyp, m_vnxp;
00984 int m_vnzc, m_vnyc, m_vnxc;
00985 void buildFFTVolume();
00986 void buildNormVolume();
00987 void buildNorm2Volume();
00988 float m_wghta;
00989 float m_wghtb;
00990 };
00991
00992
00996 class nn4_ctfReconstructor:public Reconstructor
00997 {
00998 public:
00999 nn4_ctfReconstructor();
01000
01001 nn4_ctfReconstructor( const string& symmetry, int size, int npad, float snr, int sign );
01002
01003 virtual ~nn4_ctfReconstructor();
01004
01005 virtual void setup();
01006
01016 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
01017
01018 virtual EMData *finish(bool doift=true);
01019
01020 virtual string get_name() const
01021 {
01022 return NAME;
01023 }
01024
01025 virtual string get_desc() const
01026 {
01027 return "Direct Fourier inversion reconstruction routine";
01028 }
01029
01030 static Reconstructor *NEW()
01031 {
01032 return new nn4_ctfReconstructor();
01033 }
01034
01035
01036 TypeDict get_param_types() const
01037 {
01038 TypeDict d;
01039 d.put("size", EMObject::INT);
01040 d.put("npad", EMObject::INT);
01041 d.put("sign", EMObject::INT);
01042 d.put("symmetry", EMObject::STRING);
01043 d.put("snr", EMObject::FLOAT);
01044 d.put("fftvol", EMObject::EMDATA);
01045 d.put("weight", EMObject::EMDATA);
01046 d.put("weighting", EMObject::INT);
01047 d.put("varsnr", EMObject::INT);
01048 return d;
01049 }
01050
01051 void setup( const string& symmetry, int size, int npad, float snr, int sign );
01052
01053 int insert_padfft_slice( EMData* padfft, const Transform& trans, int mult=1);
01054
01055 int insert_buffed_slice( const EMData* buffer, int mult );
01056
01057 static const string NAME;
01058
01059 private:
01060 EMData* m_volume;
01061 EMData* m_result;
01062 EMData* m_wptr;
01063 bool m_delete_volume;
01064 bool m_delete_weight;
01065 int m_vnx, m_vny, m_vnz;
01066 int m_vnzp, m_vnyp, m_vnxp;
01067 int m_vnxc, m_vnyc, m_vnzc;
01068 int m_npad;
01069 int m_sign;
01070 int m_varsnr;
01071 int m_weighting;
01072 float m_wghta, m_wghtb;
01073 float m_snr;
01074 string m_symmetry;
01075 int m_nsym;
01076
01077 void buildFFTVolume();
01078 void buildNormVolume();
01079
01080 };
01081
01082
01086 class nn4_ctf_rectReconstructor:public Reconstructor
01087 {
01088 public:
01089 nn4_ctf_rectReconstructor();
01090
01091 nn4_ctf_rectReconstructor( const string& symmetry, int size, int npad, float snr, int sign );
01092
01093 virtual ~nn4_ctf_rectReconstructor();
01094
01095 virtual void setup();
01096
01106 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
01107
01108 virtual EMData *finish(bool doift=true);
01109
01110 virtual string get_name() const
01111 {
01112 return NAME;
01113 }
01114
01115 virtual string get_desc() const
01116 {
01117 return "Direct Fourier inversion reconstruction routine";
01118 }
01119
01120 static Reconstructor *NEW()
01121 {
01122 return new nn4_ctf_rectReconstructor();
01123 }
01124
01125
01126 TypeDict get_param_types() const
01127 {
01128 TypeDict d;
01129 d.put("sizeprojection", EMObject::INT);
01130 d.put("sizex", EMObject::INT);
01131 d.put("sizey", EMObject::INT);
01132 d.put("sizez", EMObject::INT);
01133 d.put("xratio", EMObject::FLOAT);
01134 d.put("yratio", EMObject::FLOAT);
01135 d.put("size", EMObject::INT);
01136 d.put("npad", EMObject::INT);
01137 d.put("sign", EMObject::INT);
01138 d.put("symmetry", EMObject::STRING);
01139 d.put("snr", EMObject::FLOAT);
01140 d.put("fftvol", EMObject::EMDATA);
01141 d.put("weight", EMObject::EMDATA);
01142 d.put("weighting", EMObject::INT);
01143 d.put("varsnr", EMObject::INT);
01144 return d;
01145 }
01146
01147 void setup( const string& symmetry, int size, int npad, float snr, int sign );
01148
01149 int insert_padfft_slice( EMData* padfft, const Transform& trans, int mult=1);
01150
01151 int insert_buffed_slice( const EMData* buffer, int mult );
01152
01153 static const string NAME;
01154
01155 private:
01156 EMData* m_volume;
01157 EMData* m_result;
01158 EMData* m_wptr;
01159 bool m_delete_volume;
01160 bool m_delete_weight;
01161 int m_vnx, m_vny, m_vnz;
01162 int m_vnzp, m_vnyp, m_vnxp;
01163 int m_vnxc, m_vnyc, m_vnzc;
01164 int m_count;
01165 float m_xratio,m_yratio,m_zratio;
01166 float m_xscale,m_yscale;
01167 int m_sizeofprojection;
01168 int m_npad;
01169 int m_sign;
01170 int m_varsnr;
01171 int m_weighting;
01172 float m_wghta, m_wghtb;
01173 float m_snr;
01174 string m_symmetry;
01175 int m_nsym;
01176
01177 void buildFFTVolume();
01178 void buildNormVolume();
01179
01180 };
01181
01182
01183
01184
01185
01186
01187
01188 class nnSSNR_ctfReconstructor:public Reconstructor
01189 {
01190
01191 public:
01192 nnSSNR_ctfReconstructor();
01193
01194 nnSSNR_ctfReconstructor( const string& symmetry, int size, int npad, float snr, int sign);
01195
01196 ~nnSSNR_ctfReconstructor();
01197
01198 virtual void setup();
01199
01209 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
01210
01211
01212 virtual EMData *finish(bool doift=true);
01213
01214 virtual string get_name() const
01215 {
01216 return NAME;
01217 }
01218
01219 virtual string get_desc() const
01220 {
01221 return "Reconstruction by nearest neighbor with 3D SSNR with CTF";
01222 }
01223
01224 static Reconstructor *NEW()
01225 {
01226 return new nnSSNR_ctfReconstructor();
01227 }
01228
01229 TypeDict get_param_types() const
01230 {
01231 TypeDict d;
01232 d.put("size", EMObject::INT);
01233 d.put("npad", EMObject::INT);
01234 d.put("symmetry", EMObject::STRING);
01235 d.put("fftvol", EMObject::EMDATA);
01236 d.put("fftwvol", EMObject::EMDATA);
01237 d.put("weight", EMObject::EMDATA);
01238 d.put("weight2", EMObject::EMDATA);
01239 d.put("weight3", EMObject::EMDATA);
01240 d.put("SSNR", EMObject::EMDATA);
01241 d.put("w", EMObject::FLOAT);
01242 d.put("sign", EMObject::INT);
01243 d.put("snr", EMObject::FLOAT);
01244 return d;
01245 }
01246 void setup( const string& symmetry, int size, int npad, float snr, int sign);
01247
01248 int insert_padfft_slice( EMData* padded, const Transform& trans, int mult=1 );
01249
01250 static const string NAME;
01251
01252 private:
01253 EMData* m_volume;
01254 EMData* m_wptr;
01255 EMData* m_wptr2;
01256 EMData* m_wptr3;
01257 EMData* m_result;
01258 bool m_delete_volume;
01259 bool m_delete_weight;
01260 bool m_delete_weight2;
01261 bool m_delete_weight3;
01262 string m_symmetry;
01263 int m_weighting;
01264 int m_vnx, m_vny, m_vnz;
01265 int m_npad;
01266 int m_nsym;
01267 int m_vnzp, m_vnyp, m_vnxp;
01268 int m_vnzc, m_vnyc, m_vnxc;
01269 void buildFFTVolume();
01270 void buildNormVolume();
01271 void buildNorm2Volume();
01272 void buildNorm3Volume();
01273 float m_wghta;
01274 float m_wghtb;
01275 int m_sign;
01276 float m_snr;
01277 int wiener;
01278 };
01279
01280 template <> Factory < Reconstructor >::Factory();
01281
01282 void dump_reconstructors();
01283 map<string, vector<string> > dump_reconstructors_list();
01284
01285
01286 struct point_t
01287 {
01288 int pos2;
01289 float real;
01290 float imag;
01291 float ctf2;
01292 };
01293
01294
01295 class newfile_store
01296 {
01297 public:
01298 newfile_store( const string& prefix, int npad, bool ctf );
01299
01300 virtual ~newfile_store();
01301
01302 void add_image( EMData* data, const Transform& tf );
01303
01304 void add_tovol( EMData* fftvol, EMData* wgtvol, const vector<int>& mults, int pbegin, int pend );
01305
01306 void get_image( int id, EMData* buf );
01307
01308 void read( int nprj );
01309
01310 void restart( );
01311
01312 private:
01313 int m_npad;
01314
01315 bool m_ctf;
01316
01317 string m_bin_file;
01318 string m_txt_file;
01319
01320 shared_ptr<std::ofstream> m_bin_of;
01321 shared_ptr<std::ofstream> m_txt_of;
01322 shared_ptr<std::ifstream> m_bin_if;
01323 vector< std::istream::off_type > m_offsets;
01324
01325 vector< point_t > m_points;
01326 };
01327
01328 class file_store
01329 {
01330 public:
01331 file_store(const string& filename, int npad, int write, bool CTF);
01332
01333 virtual ~file_store();
01334
01335 void add_image(EMData* data, const Transform& tf);
01336
01337 void get_image(int id, EMData* padfft);
01338
01339 void restart();
01340 private:
01341 shared_ptr<std::ifstream> m_ihandle;
01342 shared_ptr<std::ofstream> m_bin_ohandle;
01343 shared_ptr<std::ofstream> m_txt_ohandle;
01344 string m_bin_file;
01345 string m_txt_file;
01346 int m_ctf;
01347 int m_npad;
01348 int m_prev;
01349 int m_x_out;
01350 int m_y_out;
01351 int m_z_out;
01352 int m_write;
01353 std::istream::off_type m_totsize;
01354 float m_Cs;
01355 float m_pixel;
01356 float m_voltage;
01357 float m_ctf_applied;
01358 float m_amp_contrast;
01359 vector< float > m_defocuses;
01360 vector< float > m_phis;
01361 vector< float > m_thetas;
01362 vector< float > m_psis;
01363 };
01364
01365 }
01366
01367 #endif
01368
01369