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("quiet", EMObject::BOOL, "Optional. If false, print verbose information.");
00482 d.put("subvolume",EMObject::INTARRAY, "Optional. (xorigin,yorigin,zorigin,xsize,ysize,zsize) all in Fourier pixels. Useful for parallelism.");
00483 d.put("savenorm",EMObject::STRING, "Debug. Will cause the normalization volume to be written directly to the specified file when finish() is called.");
00484 return d;
00485 }
00486
00487 static const string NAME;
00488
00489 protected:
00492 virtual void load_default_settings();
00493
00497 virtual void free_memory();
00498
00501 virtual void load_inserter();
00502
00508 virtual void do_insert_slice_work(const EMData* const input_slice, const Transform & euler,const float weight);
00509
00514 virtual void do_compare_slice_work(EMData* input_slice, const Transform & euler,float weight);
00515
00520 virtual bool pixel_at(const float& xx, const float& yy, const float& zz, float *dt);
00521
00523 FourierPixelInserter3D* inserter;
00524
00525 private:
00528 FourierReconstructor( const FourierReconstructor& that );
00531 FourierReconstructor& operator=( const FourierReconstructor& );
00532
00533 };
00534
00535
00536
00547 class WienerFourierReconstructor : public FourierReconstructor
00548 {
00549 public:
00553 WienerFourierReconstructor() {};
00554
00558 virtual ~WienerFourierReconstructor() { }
00559
00560
00570 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
00571
00572
00589 virtual int determine_slice_agreement(EMData* slice, const Transform &euler, const float weight=1.0, bool sub=true );
00590
00597 virtual EMData *finish(bool doift=true);
00598
00601 virtual string get_name() const
00602 {
00603 return NAME;
00604 }
00605
00608 virtual string get_desc() const
00609 {
00610 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.";
00611 }
00612
00616 static Reconstructor *NEW()
00617 {
00618 return new WienerFourierReconstructor();
00619 }
00620
00621 static const string NAME;
00622
00623 protected:
00624
00625 virtual void do_insert_slice_work(const EMData* const input_slice, const Transform & euler,const float weight);
00626
00631 virtual void do_compare_slice_work(EMData* input_slice, const Transform & euler,float weight);
00632
00637 virtual bool pixel_at(const float& xx, const float& yy, const float& zz, float *dt);
00638
00640
00641
00642 private:
00645 WienerFourierReconstructor( const WienerFourierReconstructor& that );
00648 WienerFourierReconstructor& operator=( const WienerFourierReconstructor& );
00649
00650 };
00651
00702 class FourierPlaneReconstructor : public Reconstructor, public ReconstructorVolumeData
00703 {
00704 public:
00708 FourierPlaneReconstructor() { load_default_settings(); }
00709
00713 virtual ~FourierPlaneReconstructor() { free_memory(); }
00714
00718 virtual void setup();
00719
00728 virtual void setup_seed(EMData* seed,float seed_weight);
00729
00738 virtual EMData* preprocess_slice( const EMData* const slice, const Transform& t = Transform() );
00739
00749 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
00750
00751
00768 virtual int determine_slice_agreement(EMData* slice, const Transform &euler, const float weight=1.0, bool sub=true );
00769
00776 virtual EMData *finish(bool doift=true);
00777
00780 virtual void clear();
00781
00784 virtual string get_name() const
00785 {
00786 return NAME;
00787 }
00788
00791 virtual string get_desc() const
00792 {
00793 return "Reconstruction via direct Fourier methods using one of a variety of different kernels, most of which are Gaussian based";
00794 }
00795
00799 static Reconstructor *NEW()
00800 {
00801 return new FourierPlaneReconstructor();
00802 }
00803
00807 virtual TypeDict get_param_types() const
00808 {
00809 TypeDict d;
00810 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.");
00811 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");
00812 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.");
00813 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.");
00814 d.put("verbose", EMObject::BOOL, "Optional. Toggles writing useful information to standard out. Default is false.");
00815 d.put("quiet", EMObject::BOOL, "Optional. If false, print verbose information.");
00816 return d;
00817 }
00818
00819 static const string NAME;
00820
00821 protected:
00824 virtual void load_default_settings();
00825
00829 virtual void free_memory();
00830
00833 virtual void load_inserter();
00834
00840 virtual void do_insert_slice_work(const EMData* const input_slice, const Transform & euler,const float weight);
00841
00846 virtual void do_compare_slice_work(EMData* input_slice, const Transform & euler,float weight);
00847
00852 virtual bool pixel_at(const float& xx, const float& yy, const float& zz, float *dt);
00853
00855 FourierPixelInserter3D* inserter;
00856
00857 private:
00860 FourierPlaneReconstructor( const FourierPlaneReconstructor& that );
00863 FourierPlaneReconstructor& operator=( const FourierPlaneReconstructor& );
00864
00865 };
00866
00867
00875 class BackProjectionReconstructor:public Reconstructor, public ReconstructorVolumeData
00876 {
00877 public:
00878 BackProjectionReconstructor() { load_default_settings(); }
00879
00880 virtual ~BackProjectionReconstructor() {}
00881
00882 virtual void setup();
00883
00892 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
00893
00894 virtual EMData *finish(bool doift=true);
00895
00896 virtual string get_name() const
00897 {
00898 return NAME;
00899 }
00900
00901 virtual string get_desc() const
00902 {
00903 return "Simple (unfiltered) back-projection reconstruction. Weighting by contributing particles in the class average is optional and default behaviour";
00904 }
00905
00906 static Reconstructor *NEW()
00907 {
00908 return new BackProjectionReconstructor();
00909 }
00910
00911 virtual TypeDict get_param_types() const
00912 {
00913 TypeDict d;
00914 d.put("size", EMObject::INT, "Necessary. The x and y dimensions of the input images.");
00915 d.put("weight", EMObject::FLOAT, "Optional. A temporary value set prior to slice insertion, indicative of the inserted slice's weight. Default sis 1.");
00916 d.put("sym", EMObject::STRING, "Optional. The symmetry to impose on the final reconstruction. Default is c1");
00917 d.put("zsample", EMObject::INT, "Optional. The z dimensions of the reconstructed volume.");
00918 return d;
00919 }
00920
00921 static const string NAME;
00922
00923 private:
00924
00925 BackProjectionReconstructor( const BackProjectionReconstructor& that);
00926
00927 BackProjectionReconstructor& operator=( const BackProjectionReconstructor& );
00928
00929 void load_default_settings()
00930 {
00931 params["weight"] = 1.0;
00932 params["use_weights"] = true;
00933 params["size"] = 0;
00934 params["sym"] = "c1";
00935 params["zsample"] = 0;
00936 }
00937
00938 EMData* preprocess_slice(const EMData* const slice, const Transform& t);
00939 };
00940
00941
00945 EMData* padfft_slice( const EMData* const slice, const Transform& t, int npad );
00946
00947 class nn4Reconstructor:public Reconstructor
00948 {
00949 public:
00950 nn4Reconstructor();
00951
00952 nn4Reconstructor( const string& symmetry, int size, int npad );
00953
00954 virtual ~nn4Reconstructor();
00955
00956 virtual void setup();
00957
00966 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
00967
00968 virtual EMData *finish(bool doift=true);
00969
00970 virtual string get_name() const
00971 {
00972 return NAME;
00973 }
00974
00975 virtual string get_desc() const
00976 {
00977 return "Direct Fourier inversion routine";
00978 }
00979
00980 static Reconstructor *NEW()
00981 {
00982 return new nn4Reconstructor();
00983 }
00984
00985 virtual TypeDict get_param_types() const
00986 {
00987 TypeDict d;
00988 d.put("size", EMObject::INT);
00989 d.put("npad", EMObject::INT);
00990 d.put("sign", EMObject::INT);
00991 d.put("ndim", EMObject::INT);
00992 d.put("snr", EMObject::FLOAT);
00993 d.put("symmetry", EMObject::STRING);
00994 d.put("snr", EMObject::FLOAT);
00995 d.put("fftvol", EMObject::EMDATA);
00996 d.put("weight", EMObject::EMDATA);
00997 d.put("weighting", EMObject::INT);
00998 return d;
00999 }
01000
01001 void setup( const string& symmetry, int size, int npad );
01002
01003 int insert_padfft_slice( EMData* padded, const Transform& trans, int mult=1 );
01004
01005 static const string NAME;
01006
01007 private:
01008 EMData* m_volume;
01009 EMData* m_wptr;
01010 string m_symmetry;
01011 int m_weighting;
01012 int m_vnx, m_vny, m_vnz;
01013 int m_npad;
01014 int m_nsym;
01015 int m_ndim;
01016 int m_vnzp, m_vnyp, m_vnxp;
01017 int m_vnzc, m_vnyc, m_vnxc;
01018 void buildFFTVolume();
01019 void buildNormVolume();
01020 float m_wghta;
01021 float m_wghtb;
01022 float m_osnr;
01023 void load_default_settings()
01024 {
01025
01026 }
01027 };
01028
01029
01035 class nn4_rectReconstructor:public Reconstructor
01036 {
01037 public:
01038 nn4_rectReconstructor();
01039
01040 nn4_rectReconstructor( const string& symmetry, int size, int npad );
01041
01042 virtual ~nn4_rectReconstructor();
01043
01044 virtual void setup();
01045
01054 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
01055
01056 virtual EMData *finish(bool doift=true);
01057
01058 virtual string get_name() const
01059 {
01060 return NAME;
01061 }
01062
01063 virtual string get_desc() const
01064 {
01065 return "Direct Fourier inversion routine";
01066 }
01067
01068 static Reconstructor *NEW()
01069 {
01070 return new nn4_rectReconstructor();
01071 }
01072
01073 virtual TypeDict get_param_types() const
01074 {
01075 TypeDict d;
01076 d.put("sizeprojection", EMObject::INT);
01077 d.put("sizex", EMObject::INT);
01078 d.put("sizey", EMObject::INT);
01079 d.put("sizez", EMObject::INT);
01080 d.put("xratio", EMObject::FLOAT);
01081 d.put("yratio", EMObject::FLOAT);
01082 d.put("zratio", EMObject::FLOAT);
01083 d.put("npad", EMObject::INT);
01084 d.put("sign", EMObject::INT);
01085 d.put("ndim", EMObject::INT);
01086 d.put("snr", EMObject::FLOAT);
01087 d.put("symmetry", EMObject::STRING);
01088 d.put("snr", EMObject::FLOAT);
01089 d.put("fftvol", EMObject::EMDATA);
01090 d.put("weight", EMObject::EMDATA);
01091 d.put("weighting", EMObject::INT);
01092 return d;
01093 }
01094
01095 void setup( const string& symmetry, int size, int npad );
01096
01097 int insert_padfft_slice( EMData* padded, const Transform& trans, int mult=1 );
01098
01099 static const string NAME;
01100
01101 private:
01102 EMData* m_volume;
01103 EMData* m_wptr;
01104 string m_symmetry;
01105 int m_weighting;
01106 int m_vnx, m_vny, m_vnz;
01107 int m_npad;
01108 int m_nsym;
01109 int m_ndim;
01110 int m_vnzp, m_vnyp, m_vnxp;
01111 int m_vnzc, m_vnyc, m_vnxc;
01112 int m_count;
01113 float m_xratio,m_yratio,m_zratio;
01114 float m_xscale,m_yscale;
01115 int m_sizeofprojection;
01116 void buildFFTVolume();
01117 void buildNormVolume();
01118 float m_wghta;
01119 float m_wghtb;
01120 float m_osnr;
01121 void load_default_settings()
01122 {
01123
01124 }
01125 };
01126
01127
01128
01129
01130
01131
01132 class nnSSNR_Reconstructor:public Reconstructor
01133 {
01134
01135 public:
01136 nnSSNR_Reconstructor();
01137
01138 nnSSNR_Reconstructor( const string& symmetry, int size, int npad);
01139
01140 ~nnSSNR_Reconstructor();
01141
01142 virtual void setup();
01143
01152 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
01153
01154 virtual EMData *finish(bool doift=true);
01155
01156 virtual string get_name() const
01157 {
01158 return NAME;
01159 }
01160
01161 virtual string get_desc() const
01162 {
01163 return "Reconstruction by nearest neighbor with 3D SSNR";
01164 }
01165
01166 static Reconstructor *NEW()
01167 {
01168 return new nnSSNR_Reconstructor();
01169 }
01170
01171 virtual TypeDict get_param_types() const
01172 {
01173 TypeDict d;
01174 d.put("size", EMObject::INT);
01175 d.put("npad", EMObject::INT);
01176 d.put("symmetry", EMObject::STRING);
01177 d.put("fftvol", EMObject::EMDATA);
01178 d.put("weight", EMObject::EMDATA);
01179 d.put("weight2", EMObject::EMDATA);
01180 d.put("SSNR", EMObject::EMDATA);
01181 d.put("vol_ssnr", EMObject::EMDATA);
01182 d.put("w", EMObject::FLOAT);
01183 return d;
01184 }
01185
01186 void setup( const string& symmetry, int size, int npad);
01187
01188 int insert_padfft_slice( EMData* padded, const Transform& trans, int mult=1 );
01189
01190 static const string NAME;
01191
01192 private:
01193 EMData* m_volume;
01194 EMData* m_wptr;
01195 EMData* m_wptr2;
01196 string m_symmetry;
01197 int m_weighting;
01198 int m_vnx, m_vny, m_vnz;
01199 int m_npad;
01200 int m_nsym;
01201 int m_vnzp, m_vnyp, m_vnxp;
01202 int m_vnzc, m_vnyc, m_vnxc;
01203 void buildFFTVolume();
01204 void buildNormVolume();
01205 void buildNorm2Volume();
01206 float m_wghta;
01207 float m_wghtb;
01208 };
01209
01210
01214 class nn4_ctfReconstructor:public Reconstructor
01215 {
01216 public:
01217 nn4_ctfReconstructor();
01218
01219 nn4_ctfReconstructor( const string& symmetry, int size, int npad, float snr, int sign );
01220
01221 virtual ~nn4_ctfReconstructor();
01222
01223 virtual void setup();
01224
01234 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
01235
01236 virtual EMData *finish(bool doift=true);
01237
01238 virtual string get_name() const
01239 {
01240 return NAME;
01241 }
01242
01243 virtual string get_desc() const
01244 {
01245 return "Direct Fourier inversion reconstruction routine";
01246 }
01247
01248 static Reconstructor *NEW()
01249 {
01250 return new nn4_ctfReconstructor();
01251 }
01252
01253
01254 TypeDict get_param_types() const
01255 {
01256 TypeDict d;
01257 d.put("size", EMObject::INT);
01258 d.put("npad", EMObject::INT);
01259 d.put("sign", EMObject::INT);
01260 d.put("symmetry", EMObject::STRING);
01261 d.put("snr", EMObject::FLOAT);
01262 d.put("fftvol", EMObject::EMDATA);
01263 d.put("weight", EMObject::EMDATA);
01264 d.put("weighting", EMObject::INT);
01265 d.put("varsnr", EMObject::INT);
01266 return d;
01267 }
01268
01269 void setup( const string& symmetry, int size, int npad, float snr, int sign );
01270
01271 int insert_padfft_slice( EMData* padfft, const Transform& trans, int mult=1);
01272
01273 int insert_buffed_slice( const EMData* buffer, int mult );
01274
01275 static const string NAME;
01276
01277 private:
01278 EMData* m_volume;
01279 EMData* m_wptr;
01280 int m_vnx, m_vny, m_vnz;
01281 int m_vnzp, m_vnyp, m_vnxp;
01282 int m_vnxc, m_vnyc, m_vnzc;
01283 int m_npad;
01284 int m_sign;
01285 int m_varsnr;
01286 int m_weighting;
01287 float m_wghta, m_wghtb;
01288 float m_snr;
01289 string m_symmetry;
01290 int m_nsym;
01291
01292 void buildFFTVolume();
01293 void buildNormVolume();
01294
01295 };
01296
01297
01301 class nn4_ctf_rectReconstructor:public Reconstructor
01302 {
01303 public:
01304 nn4_ctf_rectReconstructor();
01305
01306 nn4_ctf_rectReconstructor( const string& symmetry, int size, int npad, float snr, int sign );
01307
01308 virtual ~nn4_ctf_rectReconstructor();
01309
01310 virtual void setup();
01311
01321 virtual int insert_slice(const EMData* const slice, const Transform & euler, const float weight=1.0);
01322
01323 virtual EMData *finish(bool doift=true);
01324
01325 virtual string get_name() const
01326 {
01327 return NAME;
01328 }
01329
01330 virtual string get_desc() const
01331 {
01332 return "Direct Fourier inversion reconstruction routine";
01333 }
01334
01335 static Reconstructor *NEW()
01336 {
01337 return new nn4_ctf_rectReconstructor();
01338 }
01339
01340
01341 TypeDict get_param_types() const
01342 {
01343 TypeDict d;
01344 d.put("sizeprojection", EMObject::INT);
01345 d.put("sizex", EMObject::INT);
01346 d.put("sizey", EMObject::INT);
01347 d.put("sizez", EMObject::INT);
01348 d.put("xratio", EMObject::FLOAT);
01349 d.put("yratio", EMObject::FLOAT);
01350 d.put("zratio", EMObject::FLOAT);
01351 d.put("size", EMObject::INT);
01352 d.put("npad", EMObject::INT);
01353 d.put("sign", EMObject::INT);
01354 d.put("symmetry", EMObject::STRING);
01355 d.put("snr", EMObject::FLOAT);
01356 d.put("fftvol", EMObject::EMDATA);
01357 d.put("weight", EMObject::EMDATA);
01358 d.put("weighting", EMObject::INT);
01359 d.put("varsnr", EMObject::INT);
01360 return d;
01361 }
01362
01363 void setup( const string& symmetry, int size, int npad, float snr, int sign );
01364
01365 int insert_padfft_slice( EMData* padfft, const Transform& trans, int mult=1);
01366
01367 int insert_buffed_slice( const EMData* buffer, int mult );
01368
01369 static const string NAME;
01370
01371 private:
01372 EMData* m_volume;
01373 EMData* m_wptr;
01374 int m_vnx, m_vny, m_vnz;
01375 int m_vnzp, m_vnyp, m_vnxp;
01376 int m_vnxc, m_vnyc, m_vnzc;
01377 int m_count;
01378 float m_xratio, m_yratio, m_zratio;
01379 int m_sizeofprojection;
01380 int m_npad;
01381 int m_sign;
01382 int m_varsnr;
01383 int m_weighting;
01384 float m_wghta, m_wghtb;
01385 float m_snr;
01386 string m_symmetry;
01387 int m_nsym;
01388
01389 void buildFFTVolume();
01390 void buildNormVolume();
01391 };
01392
01393
01394
01395
01396
01397
01398
01399 class nnSSNR_ctfReconstructor:public Reconstructor
01400 {
01401
01402 public:
01403 nnSSNR_ctfReconstructor();
01404
01405 nnSSNR_ctfReconstructor( const string& symmetry, int size, int npad, float snr, int sign);
01406
01407 ~nnSSNR_ctfReconstructor();
01408
01409 virtual void setup();
01410
01420 virtual int insert_slice(const EMData* const slice, const Transform & euler,const float weight=1.0);
01421
01422
01423 virtual EMData *finish(bool doift=true);
01424
01425 virtual string get_name() const
01426 {
01427 return NAME;
01428 }
01429
01430 virtual string get_desc() const
01431 {
01432 return "Reconstruction by nearest neighbor with 3D SSNR with CTF";
01433 }
01434
01435 static Reconstructor *NEW()
01436 {
01437 return new nnSSNR_ctfReconstructor();
01438 }
01439
01440 TypeDict get_param_types() const
01441 {
01442 TypeDict d;
01443 d.put("size", EMObject::INT);
01444 d.put("npad", EMObject::INT);
01445 d.put("symmetry", EMObject::STRING);
01446 d.put("fftvol", EMObject::EMDATA);
01447 d.put("fftwvol", EMObject::EMDATA);
01448 d.put("weight", EMObject::EMDATA);
01449 d.put("weight2", EMObject::EMDATA);
01450 d.put("weight3", EMObject::EMDATA);
01451 d.put("SSNR", EMObject::EMDATA);
01452 d.put("vol_ssnr", EMObject::EMDATA);
01453 d.put("w", EMObject::FLOAT);
01454 d.put("sign", EMObject::INT);
01455 d.put("snr", EMObject::FLOAT);
01456 return d;
01457 }
01458 void setup( const string& symmetry, int size, int npad, float snr, int sign);
01459
01460 int insert_padfft_slice( EMData* padded, const Transform& trans, int mult=1 );
01461
01462 static const string NAME;
01463
01464 private:
01465 EMData* m_volume;
01466 EMData* m_wptr;
01467 EMData* m_wptr2;
01468 EMData* m_wptr3;
01469 string m_symmetry;
01470 int m_weighting;
01471 int m_vnx, m_vny, m_vnz;
01472 int m_npad;
01473 int m_nsym;
01474 int m_vnzp, m_vnyp, m_vnxp;
01475 int m_vnzc, m_vnyc, m_vnxc;
01476 void buildFFTVolume();
01477 void buildNormVolume();
01478 void buildNorm2Volume();
01479 void buildNorm3Volume();
01480 float m_wghta;
01481 float m_wghtb;
01482 int m_sign;
01483 float m_snr;
01484 int wiener;
01485 };
01486
01487 template <> Factory < Reconstructor >::Factory();
01488
01489 void dump_reconstructors();
01490 map<string, vector<string> > dump_reconstructors_list();
01491
01492
01493 struct point_t
01494 {
01495 int pos2;
01496 float real;
01497 float imag;
01498 float ctf2;
01499 };
01500
01501
01502 class newfile_store
01503 {
01504 public:
01505 newfile_store( const string& prefix, int npad, bool ctf );
01506
01507 virtual ~newfile_store();
01508
01509 void add_image( EMData* data, const Transform& tf );
01510
01511 void add_tovol( EMData* fftvol, EMData* wgtvol, const vector<int>& mults, int pbegin, int pend );
01512
01513 void get_image( int id, EMData* buf );
01514
01515 void read( int nprj );
01516
01517 void restart( );
01518
01519 private:
01520 int m_npad;
01521
01522 bool m_ctf;
01523
01524 string m_bin_file;
01525 string m_txt_file;
01526
01527 shared_ptr<std::ofstream> m_bin_of;
01528 shared_ptr<std::ofstream> m_txt_of;
01529 shared_ptr<std::ifstream> m_bin_if;
01530 vector< std::istream::off_type > m_offsets;
01531
01532 vector< point_t > m_points;
01533 };
01534
01535 class file_store
01536 {
01537 public:
01538 file_store(const string& filename, int npad, int write, bool CTF);
01539
01540 virtual ~file_store();
01541
01542 void add_image(EMData* data, const Transform& tf);
01543
01544 void get_image(int id, EMData* padfft);
01545
01546 void restart();
01547 private:
01548 shared_ptr<std::ifstream> m_ihandle;
01549 shared_ptr<std::ofstream> m_bin_ohandle;
01550 shared_ptr<std::ofstream> m_txt_ohandle;
01551 string m_bin_file;
01552 string m_txt_file;
01553 int m_ctf;
01554 int m_npad;
01555 int m_prev;
01556 int m_x_out;
01557 int m_y_out;
01558 int m_z_out;
01559 int m_write;
01560 std::istream::off_type m_totsize;
01561 float m_Cs;
01562 float m_pixel;
01563 float m_voltage;
01564 float m_ctf_applied;
01565 float m_amp_contrast;
01566 vector< float > m_defocuses;
01567 vector< float > m_phis;
01568 vector< float > m_thetas;
01569 vector< float > m_psis;
01570 };
01571
01572 }
01573
01574 #endif
01575
01576