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
00108 class Reconstructor : public FactoryBase
00109 {
00110 public:
00111 Reconstructor() {}
00112 virtual ~Reconstructor() {}
00115 virtual void setup() = 0;
00116
00124 virtual int insert_slice(const EMData* const slice, const Transform3D & euler) {throw;};
00125
00126
00127 virtual int insert_slice(const EMData* const slice, const Transform & euler) {throw;};
00128
00136 virtual int determine_slice_agreement(const EMData* const, const Transform3D &, const unsigned int)
00137 {
00138 cout << "You called determine slice agreement but nothing happened - there is no functionality for determing slice agreement using this " << get_name() << " reconstructor" << endl;
00139 return 0;
00140 }
00141
00142 virtual int determine_slice_agreement(const EMData* const, const Transform &, const unsigned int)
00143 {
00144 throw;
00145 }
00146
00150 virtual EMData *finish() = 0;
00151
00154 void print_params() const
00155 {
00156 std::cout << "Printing reconstructor params" << std::endl;
00157 for ( Dict::const_iterator it = params.begin(); it != params.end(); ++it )
00158 {
00159 std::cout << (it->first) << " " << (it->second).to_str() << std::endl;
00160 }
00161 std::cout << "Done printing reconstructor params" << std::endl;
00162 }
00163
00164
00165 EMObject& operator[]( const string& key ) { return params[key]; }
00166
00167
00168 virtual float get_score(const unsigned int) { return 0; }
00169
00170 virtual float get_norm(const unsigned int) { return 0; }
00171
00172
00173 virtual int insert_slice_weights(const Transform&) {return 0;}
00174
00175 private:
00176
00177 Reconstructor(const Reconstructor& that);
00178 Reconstructor& operator=(const Reconstructor& );
00179
00180 };
00181
00193 class ReconstructorVolumeData
00194 {
00195 public:
00199 inline ReconstructorVolumeData() : image(0), tmp_data(0), nx(0), ny(0), nz(0) {}
00200
00203 virtual ~ReconstructorVolumeData() { free_memory(); }
00204
00207 const EMData* const get_emdata() { return image; }
00208 protected:
00209
00211 EMData* image;
00213 EMData* tmp_data;
00214
00215
00216 int nx;
00217 int ny;
00218 int nz;
00219
00220 protected:
00226 void free_memory()
00227 {
00228 if (image != 0) {delete image; image = 0;}
00229 if ( tmp_data != 0 ) { delete tmp_data; tmp_data = 0; }
00230 }
00231
00237 virtual void normalize_threed();
00238
00242 virtual void zero_memory()
00243 {
00244 if (tmp_data != 0 ) tmp_data->to_zero();
00245 if (image != 0 ) image->to_zero();
00246 }
00247
00248 private:
00250 ReconstructorVolumeData(const ReconstructorVolumeData& that);
00252 ReconstructorVolumeData& operator=(const ReconstructorVolumeData& );
00253
00254 };
00255
00261 class FourierReconstructorSimple2D : public Reconstructor, public ReconstructorVolumeData
00262 {
00263 public:
00264 FourierReconstructorSimple2D() {}
00265
00266 virtual ~FourierReconstructorSimple2D() { }
00267
00268 virtual void setup();
00269
00270 virtual int insert_slice(const EMData* const slice, const Transform3D & euler) {
00271 throw UnexpectedBehaviorException("Transform3D interface is redundant");
00272 }
00273
00274 virtual int insert_slice(const EMData* const slice, const Transform & euler);
00275
00276 virtual EMData *finish();
00277
00278 virtual string get_name() const { return "fouriersimple2D"; }
00279
00280 virtual string get_desc() const { return "performs 2D reconstruction"; }
00281
00282 static Reconstructor *NEW()
00283 {
00284 return new FourierReconstructorSimple2D();
00285 }
00286
00287
00288 virtual TypeDict get_param_types() const
00289 {
00290 TypeDict d;
00291 d.put("nx", EMObject::INT, "Necessary. The x dimension of the input images.");
00292
00293 return d;
00294 }
00295 };
00296
00297
00298
00348 class FourierReconstructor : public Reconstructor, public ReconstructorVolumeData
00349 {
00350 public:
00354 FourierReconstructor() : image_idx(0), inserter(0), interp_FRC_calculator(0), slice_insertion_flag(true),
00355 slice_agreement_flag(false), x_scale_factor(0.0), y_scale_factor(0.0), z_scale_factor(0.0),
00356 max_input_dim(0), output_x(0), output_y(0), output_z(0) { load_default_settings(); }
00357
00361 virtual ~FourierReconstructor() { free_memory(); }
00362
00375 virtual void setup();
00376
00384 virtual int insert_slice(const EMData* const slice, const Transform & t3d = Transform());
00385
00386
00395 virtual int determine_slice_agreement(const EMData* const input_slice, const Transform & t3d, const unsigned int num_particles_in_slice = 1);
00396
00397
00398 virtual int insert_slice(const EMData* const slice, const Transform3D & t3d) {
00399 throw UnexpectedBehaviorException("No support for Transform3D in insert_slice, use Transform instead");
00400 };
00401
00402 virtual int determine_slice_agreement(const EMData* const input_slice, const Transform3D & t3d, const unsigned int num_particles_in_slice = 1) {
00403 throw UnexpectedBehaviorException("No support for Transform3D in determine_slice_agreement, use Transform instead");
00404 };
00405
00411 virtual EMData *finish();
00412
00415 virtual string get_name() const
00416 {
00417 return "fourier";
00418 }
00419
00422 virtual string get_desc() const
00423 {
00424 return "Reconstruction via direct Fourier methods using a combination of nearest neighbour and Gaussian kernels";
00425 }
00426
00430 static Reconstructor *NEW()
00431 {
00432 return new FourierReconstructor();
00433 }
00434
00438 virtual TypeDict get_param_types() const
00439 {
00440 TypeDict d;
00441 d.put("x_in", EMObject::INT, "Necessary. The x dimension of the input images.");
00442 d.put("y_in", EMObject::INT, "Necessary. The y dimension of the input images.");
00443 d.put("zsample", EMObject::INT, "Optional. The z dimension (Fourier sampling) of the reconstructed volume, very useful for tomographic reconstruction. Works for general volumes.");
00444 d.put("ysample", EMObject::INT, "Optional. The y dimension (Fourier sampling) of the reconstructed volume, works for general volumes. Not commonly specified.");
00445 d.put("xsample", EMObject::INT, "Optional. The x dimension (Fourier sampling) of the reconstructed volume, works for general volumes. Not commonly specified.");
00446 d.put("mode", EMObject::INT, "Optional. Fourier pixel insertion mode [1-8] - mode 2 is default.");
00447 d.put("hard", EMObject::FLOAT, "Optional. The quality metric threshold. Default is 0 (off).");
00448 d.put("sym", EMObject::STRING, "Optional. The symmetry of the reconstructed volume, c?, d?, oct, tet, icos, h?. Default is c1");
00449 d.put("quiet", EMObject::BOOL, "Optional. Toggles writing useful information to standard out. Default is false.");
00450 d.put("3damp", EMObject::BOOL, "Optional. Toggles writing the 3D FFT amplitude image. Default is false.");
00451 d.put("weight", EMObject::FLOAT, "Weight of the slice that is being inserted. Default is 1.0.");
00452 d.put("start_model", EMObject::EMDATA, "Start model");
00453 d.put("start_model_weight", EMObject::FLOAT, "start_model_weight");
00454 return d;
00455 }
00456
00463 virtual float get_score(const unsigned int idx) { if ( quality_scores.size() > idx ) return quality_scores[idx].get_snr_normed_frc_integral(); else throw UnexpectedBehaviorException("The requested index was beyond the length of the quality scores vector."); }
00464
00471 virtual float get_norm(const unsigned int idx) { if ( quality_scores.size() > idx ) return quality_scores[idx].get_norm(); else throw UnexpectedBehaviorException("The requested index was beyond the length of the quality scores vector."); }
00472
00473 virtual void zero_memory();
00474
00475 protected:
00483 EMData* preprocess_slice( const EMData* const slice, const Transform& t = Transform() );
00484
00487 void load_default_settings()
00488 {
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499 }
00500
00504 void free_memory();
00505
00508 void load_inserter();
00509
00512 void load_interp_FRC_calculator();
00513
00518 void do_insert_slice_work(const EMData* const input_slice, const Transform & euler);
00519
00522 void print_stats(const vector<InterpolatedFRC::QualityScores>& scores);
00523
00525 vector<InterpolatedFRC::QualityScores> quality_scores, prev_quality_scores;
00526
00528 unsigned int image_idx;
00529
00531 FourierPixelInserter3D* inserter;
00532
00534 InterpolatedFRC* interp_FRC_calculator;
00535
00537 bool slice_insertion_flag;
00538 bool slice_agreement_flag;
00539
00541 float x_scale_factor, y_scale_factor, z_scale_factor;
00542
00544 int max_input_dim;
00545
00547 int output_x, output_y, output_z;
00548 private:
00551 FourierReconstructor( const FourierReconstructor& that );
00554 FourierReconstructor& operator=( const FourierReconstructor& );
00555
00556 };
00557
00563 class BaldwinWoolfordReconstructor : public FourierReconstructor
00564 {
00565 public:
00566 BaldwinWoolfordReconstructor() : W(0) {}
00567
00570 virtual ~BaldwinWoolfordReconstructor() {
00571 if ( W != 0 )
00572 delete [] W;
00573 }
00574
00577 virtual string get_name() const
00578 {
00579 return "baldwinwoolford";
00580 }
00581
00584 virtual string get_desc() const
00585 {
00586 return "Reconstruction via direct Fourier inversion using gridding and delta function based weights";
00587 }
00588
00592 static Reconstructor *NEW()
00593 {
00594 return new BaldwinWoolfordReconstructor();
00595 }
00596
00597 virtual TypeDict get_param_types() const
00598 {
00599 TypeDict d;
00600 d.put("mode", EMObject::INT, "Optional. Fourier pixel insertion mode [1-8] - mode 2 is default.");
00601 d.put("x_in", EMObject::INT, "Necessary. The x dimension of the input images.");
00602 d.put("y_in", EMObject::INT, "Necessary. The y dimension of the input images.");
00603 d.put("zsample", EMObject::INT, "Optional. The z dimension (Fourier sampling) of the reconstructed volume, very useful for tomographic reconstruction. Works for general volumes.");
00604 d.put("ysample", EMObject::INT, "Optional. The y dimension (Fourier sampling) of the reconstructed volume, works for general volumes. Not commonly specified.");
00605 d.put("xsample", EMObject::INT, "Optional. The x dimension (Fourier sampling) of the reconstructed volume, works for general volumes. Not commonly specified.");
00606 d.put("sym", EMObject::STRING, "Optional. The symmetry of the reconstructed volume, c?, d?, oct, tet, icos, h?. Default is c1");
00607 d.put("maskwidth", EMObject::INT, "The width of the Fourier space kernel used to interpolate data to grid points" );
00608 d.put("postmultiply", EMObject::BOOL, "A flag that controls whether or not the reconstructed volume is post multiplied in real space by the IFT of the weighting function. Default is on");
00609
00610 d.put("3damp", EMObject::BOOL, "this doesn't work, fixme dsaw");
00611 d.put("hard", EMObject::FLOAT, "Optional. The quality metric threshold. Default is 0 (off).");
00612 d.put("quiet", EMObject::BOOL, "Optional. Toggles writing useful information to standard out. Default is false.");
00613 return d;
00614 }
00618 virtual EMData *finish();
00619
00620 virtual int insert_slice_weights(const Transform& t3d);
00621
00622 virtual int insert_slice(const EMData* const image, const Transform3D& t3d) {
00623 throw UnexpectedBehaviorException("Transform3D interface is redundant");
00624 }
00625 virtual int insert_slice(const EMData* const image, const Transform& t3d);
00626 void insert_pixel(const float& x, const float& y, const float& z, const float dt[2]);
00627
00628 void insert_density_at(const float& x, const float& y, const float& z);
00629
00630 virtual void setup();
00631
00632 protected:
00635 void load_default_settings()
00636 {
00637 params["mode"] = 1;
00638 params["x_in"] = 0;
00639 params["y_in"] = 0;
00640 params["zsample"] = 0;
00641 params["ysample"] = 0;
00642 params["xsample"] = 0;
00643 params["sym"] = "c1";
00644 params["maskwidth"] = 3;
00645
00646
00647 params["3damp"] = false;
00648 params["hard"] = 0.05;
00649 params["quiet"] = false;
00650 }
00651
00652 private:
00655 BaldwinWoolfordReconstructor( const BaldwinWoolfordReconstructor& that );
00658 BaldwinWoolfordReconstructor& operator=( const BaldwinWoolfordReconstructor& );
00659
00660 float* W;
00661 float dfreq;
00662
00663 };
00664
00667 class WienerFourierReconstructor:public Reconstructor, public ReconstructorVolumeData
00668 {
00669 public:
00670 WienerFourierReconstructor() { load_default_settings(); };
00671 virtual ~WienerFourierReconstructor() {};
00672
00673 virtual void setup();
00674
00675 virtual int insert_slice(const EMData* const slice, const Transform3D & euler);
00676
00677 virtual EMData *finish();
00678
00679 virtual string get_name() const
00680 {
00681 return "wiener_fourier";
00682 }
00683
00684 virtual string get_desc() const
00685 {
00686 return "Experimental - Direct Fourier reconstruction taking into account the Wiener filtration of the individual images.";
00687 }
00688
00689 static Reconstructor *NEW()
00690 {
00691 return new WienerFourierReconstructor();
00692 }
00693
00694 virtual TypeDict get_param_types() const
00695 {
00696 TypeDict d;
00697
00698 d.put("size", EMObject::INT);
00699 d.put("mode", EMObject::INT);
00700 d.put("weight", EMObject::FLOAT);
00701 d.put("use_weights", EMObject::BOOL);
00702 d.put("dlog", EMObject::BOOL);
00703 d.put("padratio", EMObject::FLOAT);
00704 d.put("snr", EMObject::FLOATARRAY);
00705 return d;
00706 }
00707 private:
00708
00709 WienerFourierReconstructor( const WienerFourierReconstructor& that);
00710
00711 WienerFourierReconstructor& operator=( const WienerFourierReconstructor& );
00712
00713 void load_default_settings()
00714 {
00715 params["size"] = 0;
00716 params["mode"] = 2;
00717 params["weight"] = 1.0;
00718 params["use_weights"] = true;
00719 params["dlog"] = false;
00720 params["padratio"] = 1.0;
00721 }
00722 };
00723
00731 class BackProjectionReconstructor:public Reconstructor, public ReconstructorVolumeData
00732 {
00733 public:
00734 BackProjectionReconstructor() { load_default_settings(); }
00735
00736 virtual ~BackProjectionReconstructor() {}
00737
00738 virtual void setup();
00739
00740 virtual int insert_slice(const EMData* const slice, const Transform3D & euler) {
00741 throw UnexpectedBehaviorException("Use of Tranform3D with BackProjection is deprecated"); }
00742
00743 virtual int insert_slice(const EMData* const slice, const Transform & euler);
00744
00745 virtual EMData *finish();
00746
00747 virtual string get_name() const
00748 {
00749 return "back_projection";
00750 }
00751
00752 virtual string get_desc() const
00753 {
00754 return "Simple (unfiltered) back-projection reconstruction. Weighting by contributing particles in the class average is optional and default behaviour";
00755 }
00756
00757 static Reconstructor *NEW()
00758 {
00759 return new BackProjectionReconstructor();
00760 }
00761
00762 virtual TypeDict get_param_types() const
00763 {
00764 TypeDict d;
00765 d.put("size", EMObject::INT, "Necessary. The x and y dimensions of the input images.");
00766 d.put("weight", EMObject::FLOAT, "Optional. A temporary value set prior to slice insertion, indicative of the inserted slice's weight. Default sis 1.");
00767 d.put("sym", EMObject::STRING, "Optional. The symmetry to impose on the final reconstruction. Default is c1");
00768 d.put("zsample", EMObject::INT, "Optional. The z dimensions of the reconstructed volume.");
00769 return d;
00770 }
00771 private:
00772
00773 BackProjectionReconstructor( const BackProjectionReconstructor& that);
00774
00775 BackProjectionReconstructor& operator=( const BackProjectionReconstructor& );
00776
00777 void load_default_settings()
00778 {
00779 params["weight"] = 1.0;
00780 params["use_weights"] = true;
00781 params["size"] = 0;
00782 params["sym"] = "c1";
00783 params["zsample"] = 0;
00784 }
00785
00786 EMData* preprocess_slice(const EMData* const slice, const Transform& t);
00787 };
00788
00789
00793 EMData* padfft_slice( const EMData* const slice, const Transform& t, int npad );
00794
00795 class nn4Reconstructor:public Reconstructor
00796 {
00797 public:
00798 nn4Reconstructor();
00799
00800 nn4Reconstructor( const string& symmetry, int size, int npad );
00801
00802 virtual ~nn4Reconstructor();
00803
00804 virtual void setup();
00805
00806 virtual int insert_slice(const EMData* const slice, const Transform & euler);
00807
00808 virtual EMData *finish();
00809
00810 virtual string get_name() const
00811 {
00812 return "nn4";
00813 }
00814
00815 virtual string get_desc() const
00816 {
00817 return "Direct Fourier inversion routine";
00818 }
00819
00820 static Reconstructor *NEW()
00821 {
00822 return new nn4Reconstructor();
00823 }
00824
00825 virtual TypeDict get_param_types() const
00826 {
00827 TypeDict d;
00828 d.put("size", EMObject::INT);
00829 d.put("npad", EMObject::INT);
00830 d.put("sign", EMObject::INT);
00831 d.put("ndim", EMObject::INT);
00832 d.put("snr", EMObject::FLOAT);
00833 d.put("symmetry", EMObject::STRING);
00834 d.put("snr", EMObject::FLOAT);
00835 d.put("fftvol", EMObject::EMDATA);
00836 d.put("weight", EMObject::EMDATA);
00837 d.put("weighting", EMObject::INT);
00838 return d;
00839 }
00840
00841 void setup( const string& symmetry, int size, int npad );
00842
00843 int insert_padfft_slice( EMData* padded, const Transform& trans, int mult=1 );
00844
00845
00846 private:
00847 EMData* m_volume;
00848 EMData* m_wptr;
00849 EMData* m_result;
00850 bool m_delete_volume;
00851 bool m_delete_weight;
00852 string m_symmetry;
00853 int m_weighting;
00854 int m_vnx, m_vny, m_vnz;
00855 int m_npad;
00856 int m_nsym;
00857 int m_ndim;
00858 int m_vnzp, m_vnyp, m_vnxp;
00859 int m_vnzc, m_vnyc, m_vnxc;
00860 void buildFFTVolume();
00861 void buildNormVolume();
00862 float m_wghta;
00863 float m_wghtb;
00864 float m_osnr;
00865 void load_default_settings()
00866 {
00867
00868 }
00869 };
00870
00871
00872
00873
00874
00875
00876 class nnSSNR_Reconstructor:public Reconstructor
00877 {
00878
00879 public:
00880 nnSSNR_Reconstructor();
00881
00882 nnSSNR_Reconstructor( const string& symmetry, int size, int npad);
00883
00884 ~nnSSNR_Reconstructor();
00885
00886 virtual void setup();
00887
00888 virtual int insert_slice(const EMData* const slice, const Transform & euler);
00889
00890 virtual EMData* finish();
00891
00892 virtual string get_name() const
00893 {
00894 return "nnSSNR";
00895 }
00896
00897 virtual string get_desc() const
00898 {
00899 return "Reconstruction by nearest neighbor with 3D SSNR";
00900 }
00901
00902 static Reconstructor *NEW()
00903 {
00904 return new nnSSNR_Reconstructor();
00905 }
00906
00907 virtual TypeDict get_param_types() const
00908 {
00909 TypeDict d;
00910 d.put("size", EMObject::INT);
00911 d.put("npad", EMObject::INT);
00912 d.put("symmetry", EMObject::STRING);
00913 d.put("fftvol", EMObject::EMDATA);
00914 d.put("weight", EMObject::EMDATA);
00915 d.put("weight2", EMObject::EMDATA);
00916 d.put("SSNR", EMObject::EMDATA);
00917 d.put("w", EMObject::FLOAT);
00918 return d;
00919 }
00920
00921 void setup( const string& symmetry, int size, int npad);
00922
00923 int insert_padfft_slice( EMData* padded, const Transform& trans, int mult=1 );
00924
00925 private:
00926 EMData* m_volume;
00927 EMData* m_wptr;
00928 EMData* m_wptr2;
00929 EMData* m_result;
00930 bool m_delete_volume;
00931 bool m_delete_weight;
00932 bool m_delete_weight2;
00933 string m_symmetry;
00934 int m_weighting;
00935 int m_vnx, m_vny, m_vnz;
00936 int m_npad;
00937 int m_nsym;
00938 int m_vnzp, m_vnyp, m_vnxp;
00939 int m_vnzc, m_vnyc, m_vnxc;
00940 void buildFFTVolume();
00941 void buildNormVolume();
00942 void buildNorm2Volume();
00943 float m_wghta;
00944 float m_wghtb;
00945 };
00946
00947
00951 class nn4_ctfReconstructor:public Reconstructor
00952 {
00953 public:
00954 nn4_ctfReconstructor();
00955
00956 nn4_ctfReconstructor( const string& symmetry, int size, int npad, float snr, int sign );
00957
00958 virtual ~nn4_ctfReconstructor();
00959
00960 virtual void setup();
00961
00962 virtual int insert_slice(const EMData* const slice, const Transform& euler);
00963
00964 virtual EMData *finish();
00965
00966 virtual string get_name() const
00967 {
00968 return "nn4_ctf";
00969 }
00970
00971 virtual string get_desc() const
00972 {
00973 return "Direct Fourier inversion reconstruction routine";
00974 }
00975
00976 static Reconstructor *NEW()
00977 {
00978 return new nn4_ctfReconstructor();
00979 }
00980
00981
00982 TypeDict get_param_types() const
00983 {
00984 TypeDict d;
00985 d.put("size", EMObject::INT);
00986 d.put("npad", EMObject::INT);
00987 d.put("sign", EMObject::INT);
00988 d.put("symmetry", EMObject::STRING);
00989 d.put("snr", EMObject::FLOAT);
00990 d.put("fftvol", EMObject::EMDATA);
00991 d.put("weight", EMObject::EMDATA);
00992 d.put("weighting", EMObject::INT);
00993 d.put("varsnr", EMObject::INT);
00994 return d;
00995 }
00996
00997 void setup( const string& symmetry, int size, int npad, float snr, int sign );
00998
00999 int insert_padfft_slice( EMData* padfft, const Transform& trans, int mult=1);
01000
01001 int insert_buffed_slice( const EMData* buffer, int mult );
01002 private:
01003 EMData* m_volume;
01004 EMData* m_result;
01005 EMData* m_wptr;
01006 bool m_delete_volume;
01007 bool m_delete_weight;
01008 int m_vnx, m_vny, m_vnz;
01009 int m_vnzp, m_vnyp, m_vnxp;
01010 int m_vnxc, m_vnyc, m_vnzc;
01011 int m_npad;
01012 int m_sign;
01013 int m_varsnr;
01014 int m_weighting;
01015 float m_wghta, m_wghtb;
01016 float m_snr;
01017 string m_symmetry;
01018 int m_nsym;
01019
01020 void buildFFTVolume();
01021 void buildNormVolume();
01022
01023 };
01024
01025
01026
01027
01028
01029
01030 class nnSSNR_ctfReconstructor:public Reconstructor
01031 {
01032
01033 public:
01034 nnSSNR_ctfReconstructor();
01035
01036 nnSSNR_ctfReconstructor( const string& symmetry, int size, int npad, float snr, int sign);
01037
01038 ~nnSSNR_ctfReconstructor();
01039
01040 virtual void setup();
01041
01042 virtual int insert_slice(const EMData *const slice, const Transform& euler);
01043
01044
01045 virtual EMData* finish();
01046
01047 virtual string get_name() const
01048 {
01049 return "nnSSNR_ctf";
01050 }
01051
01052 virtual string get_desc() const
01053 {
01054 return "Reconstruction by nearest neighbor with 3D SSNR with CTF";
01055 }
01056
01057 static Reconstructor *NEW()
01058 {
01059 return new nnSSNR_ctfReconstructor();
01060 }
01061
01062 TypeDict get_param_types() const
01063 {
01064 TypeDict d;
01065 d.put("size", EMObject::INT);
01066 d.put("npad", EMObject::INT);
01067 d.put("symmetry", EMObject::STRING);
01068 d.put("fftvol", EMObject::EMDATA);
01069 d.put("fftwvol", EMObject::EMDATA);
01070 d.put("weight", EMObject::EMDATA);
01071 d.put("weight2", EMObject::EMDATA);
01072 d.put("weight3", EMObject::EMDATA);
01073 d.put("SSNR", EMObject::EMDATA);
01074 d.put("w", EMObject::FLOAT);
01075 d.put("sign", EMObject::INT);
01076 d.put("snr", EMObject::FLOAT);
01077 return d;
01078 }
01079 void setup( const string& symmetry, int size, int npad, float snr, int sign);
01080
01081 int insert_padfft_slice( EMData* padded, const Transform& trans, int mult=1 );
01082
01083 private:
01084 EMData* m_volume;
01085 EMData* m_wptr;
01086 EMData* m_wptr2;
01087 EMData* m_wptr3;
01088 EMData* m_result;
01089 bool m_delete_volume;
01090 bool m_delete_weight;
01091 bool m_delete_weight2;
01092 bool m_delete_weight3;
01093 string m_symmetry;
01094 int m_weighting;
01095 int m_vnx, m_vny, m_vnz;
01096 int m_npad;
01097 int m_nsym;
01098 int m_vnzp, m_vnyp, m_vnxp;
01099 int m_vnzc, m_vnyc, m_vnxc;
01100 void buildFFTVolume();
01101 void buildNormVolume();
01102 void buildNorm2Volume();
01103 void buildNorm3Volume();
01104 float m_wghta;
01105 float m_wghtb;
01106 int m_sign;
01107 float m_snr;
01108 int wiener;
01109 };
01110
01111 template <> Factory < Reconstructor >::Factory();
01112
01113 void dump_reconstructors();
01114 map<string, vector<string> > dump_reconstructors_list();
01115
01116
01117 struct point_t
01118 {
01119 int pos2;
01120 float real;
01121 float imag;
01122 float ctf2;
01123 };
01124
01125
01126 class newfile_store
01127 {
01128 public:
01129 newfile_store( const string& prefix, int npad, bool ctf );
01130
01131 virtual ~newfile_store();
01132
01133 void add_image( EMData* data, const Transform& tf );
01134
01135 void add_tovol( EMData* fftvol, EMData* wgtvol, const vector<int>& mults, int pbegin, int pend );
01136
01137 void get_image( int id, EMData* buf );
01138
01139 void read( int nprj );
01140
01141 void restart( );
01142
01143 private:
01144 int m_npad;
01145
01146 bool m_ctf;
01147
01148 string m_bin_file;
01149 string m_txt_file;
01150
01151 shared_ptr<std::ofstream> m_bin_of;
01152 shared_ptr<std::ofstream> m_txt_of;
01153 shared_ptr<std::ifstream> m_bin_if;
01154 vector< std::istream::off_type > m_offsets;
01155
01156 vector< point_t > m_points;
01157 };
01158
01159 class file_store
01160 {
01161 public:
01162 file_store(const string& filename, int npad, int write, bool CTF);
01163
01164 virtual ~file_store();
01165
01166 void add_image(EMData* data, const Transform& tf);
01167
01168 void get_image(int id, EMData* padfft);
01169
01170 void restart();
01171 private:
01172 shared_ptr<std::ifstream> m_ihandle;
01173 shared_ptr<std::ofstream> m_bin_ohandle;
01174 shared_ptr<std::ofstream> m_txt_ohandle;
01175 string m_bin_file;
01176 string m_txt_file;
01177 int m_ctf;
01178 int m_npad;
01179 int m_prev;
01180 int m_x_out;
01181 int m_y_out;
01182 int m_z_out;
01183 int m_write;
01184 std::istream::off_type m_totsize;
01185 float m_Cs;
01186 float m_pixel;
01187 float m_voltage;
01188 float m_ctf_applied;
01189 float m_amp_contrast;
01190 vector< float > m_defocuses;
01191 vector< float > m_phis;
01192 vector< float > m_thetas;
01193 vector< float > m_psis;
01194 };
01195
01196 }
01197
01198 #endif
01199
01200