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_toosl_h__
00037 #define eman_reconstructor_tools_h__ 1
00038
00039 #include "emdata.h"
00040 #include "interp.h"
00041
00042 #include <string>
00043 using std::string;
00044
00045 #include <cstdlib>
00046
00047
00048 #include <iostream>
00049 using std::cout;
00050 using std::endl;
00051
00052
00053 namespace EMAN
00054 {
00055
00100 class FourierPixelInserter3D : public FactoryBase
00101 {
00102 public:
00105 FourierPixelInserter3D() : norm(0), rdata(0), nx(0), ny(0), nz(0), nxy(0)
00106 {}
00107
00110 virtual ~FourierPixelInserter3D()
00111 {
00112 free_memory();
00113 }
00114
00115 TypeDict get_param_types() const
00116 {
00117 TypeDict d;
00118 d.put("nx", EMObject::INT);
00119 d.put("ny", EMObject::INT);
00120 d.put("nz", EMObject::INT);
00121 d.put("rdata", EMObject::FLOAT_POINTER);
00122 d.put("norm", EMObject::FLOAT_POINTER);
00123 return d;
00124 }
00125
00134 virtual bool insert_pixel(const float& xx, const float& yy, const float& zz, const float dt[], const float& weight=1.0) = 0;
00135
00136
00137 virtual void init();
00138
00144 virtual bool effected_pixels_are_zero(const float& xx, const float& yy, const float& zz) = 0;
00145
00146 protected:
00148 float * norm;
00150 float * rdata;
00151
00153 int nx, ny, nz, nxy;
00154
00156 static float tolerance;
00157 private:
00158
00159 FourierPixelInserter3D( const FourierPixelInserter3D& );
00160 FourierPixelInserter3D& operator=( const FourierPixelInserter3D& );
00161
00162 void free_memory()
00163 {
00164 }
00165 };
00166
00170 class FourierInserter3DMode1 : public FourierPixelInserter3D
00171 {
00172 public:
00173 FourierInserter3DMode1() {}
00174 virtual ~FourierInserter3DMode1() {}
00175
00176 virtual bool insert_pixel(const float& xx, const float& yy, const float& zz, const float dt[], const float& weight=1.0);
00177
00178 static FourierPixelInserter3D *NEW()
00179 {
00180 return new FourierInserter3DMode1();
00181 }
00182
00183 virtual string get_name() const
00184 {
00185 return "1";
00186 }
00187
00188 virtual string get_desc() const
00189 {
00190 return "Fourier pixel insertion using nearest neighbor";
00191 }
00192
00193 virtual bool effected_pixels_are_zero(const float& xx, const float& yy, const float& zz);
00194
00195 private:
00196
00197 FourierInserter3DMode1( const FourierInserter3DMode1& );
00198 FourierInserter3DMode1& operator=( const FourierInserter3DMode1& );
00199 };
00200
00204 class FourierInserter3DMode2 : public FourierPixelInserter3D
00205 {
00206 public:
00207 FourierInserter3DMode2() {}
00208 virtual ~FourierInserter3DMode2() {}
00209
00210 virtual bool insert_pixel(const float& xx, const float& yy, const float& zz, const float dt[], const float& weight=1.0);
00211
00212 static FourierPixelInserter3D *NEW()
00213 {
00214 return new FourierInserter3DMode2();
00215 }
00216
00217 virtual string get_name() const
00218 {
00219 return "2";
00220 }
00221
00222 virtual string get_desc() const
00223 {
00224 return "Fourier pixel insertion using interpolation and the nearest 8 voxels";
00225 }
00226
00227 virtual bool effected_pixels_are_zero(const float& xx, const float& yy, const float& zz);
00228
00229 virtual void init();
00230 private:
00231 int off[8];
00232 float g[8];
00233
00234
00235 FourierInserter3DMode2( const FourierInserter3DMode2& );
00236 FourierInserter3DMode2& operator=( const FourierInserter3DMode2& );
00237 };
00238
00242 class FourierInserter3DMode3 : public FourierPixelInserter3D
00243 {
00244 public:
00245 FourierInserter3DMode3() {}
00246 virtual ~FourierInserter3DMode3() {}
00247
00248 virtual bool insert_pixel(const float& xx, const float& yy, const float& zz, const float dt[], const float& weight=1.0);
00249
00250 static FourierPixelInserter3D *NEW()
00251 {
00252 return new FourierInserter3DMode3();
00253 }
00254
00255 virtual string get_name() const
00256 {
00257 return "3";
00258 }
00259
00260 virtual string get_desc() const
00261 {
00262 return "Fourier pixel insertion mode 3";
00263 }
00264
00265 virtual bool effected_pixels_are_zero(const float& xx, const float& yy, const float& zz);
00266
00267 private:
00268
00269 FourierInserter3DMode3( const FourierInserter3DMode3& );
00270 FourierInserter3DMode3& operator=( const FourierInserter3DMode3& );
00271 };
00272
00276 class FourierInserter3DMode4 : public FourierPixelInserter3D
00277 {
00278 public:
00279 FourierInserter3DMode4() {}
00280 virtual ~FourierInserter3DMode4() {}
00281
00282 virtual bool insert_pixel(const float& xx, const float& yy, const float& zz, const float dt[], const float& weight=1.0);
00283
00284 static FourierPixelInserter3D *NEW()
00285 {
00286 return new FourierInserter3DMode4();
00287 }
00288
00289 virtual string get_name() const
00290 {
00291 return "4";
00292 }
00293
00294 virtual string get_desc() const
00295 {
00296 return "Fourier pixel insertion mode 4";
00297 }
00298
00299 virtual bool effected_pixels_are_zero(const float& xx, const float& yy, const float& zz);
00300
00301 private:
00302
00303 FourierInserter3DMode4( const FourierInserter3DMode4& );
00304 FourierInserter3DMode4& operator=( const FourierInserter3DMode4& );
00305 };
00306
00310 class FourierInserter3DMode5 : public FourierPixelInserter3D
00311 {
00312 public:
00313 FourierInserter3DMode5()
00314 {
00315 gimx = EMAN::Interp::get_gimx();
00316 }
00317
00318 virtual ~FourierInserter3DMode5()
00319 {
00320
00321
00322
00323
00324
00325
00326 }
00327
00328 virtual bool insert_pixel(const float& xx, const float& yy, const float& zz, const float dt[], const float& weight=1.0);
00329
00330 static FourierPixelInserter3D *NEW()
00331 {
00332 return new FourierInserter3DMode5();
00333 }
00334
00335 virtual string get_name() const
00336 {
00337 return "5";
00338 }
00339
00340 virtual string get_desc() const
00341 {
00342 return "Fourier pixel insertion mode 5";
00343 }
00344
00345 virtual bool effected_pixels_are_zero(const float& xx, const float& yy, const float& zz);
00346
00347 private:
00348
00349 FourierInserter3DMode5( const FourierInserter3DMode5& );
00350 FourierInserter3DMode5& operator=( const FourierInserter3DMode5& );
00351
00352 float * gimx;
00353 };
00354
00358 class FourierInserter3DMode6 : public FourierPixelInserter3D
00359 {
00360 public:
00361 FourierInserter3DMode6() {}
00362 virtual ~FourierInserter3DMode6() {}
00363
00364 virtual bool insert_pixel(const float& xx, const float& yy, const float& zz, const float dt[], const float& weight=1.0);
00365
00366 static FourierPixelInserter3D *NEW()
00367 {
00368 return new FourierInserter3DMode6();
00369 }
00370
00371 virtual string get_name() const
00372 {
00373 return "6";
00374 }
00375
00376 virtual string get_desc() const
00377 {
00378 return "Fourier pixel insertion mode 6";
00379 }
00380
00381 virtual bool effected_pixels_are_zero(const float& xx, const float& yy, const float& zz);
00382
00383 private:
00384
00385 FourierInserter3DMode6( const FourierInserter3DMode6& );
00386 FourierInserter3DMode6& operator=( const FourierInserter3DMode6& );
00387 };
00388
00392 class FourierInserter3DMode7 : public FourierPixelInserter3D
00393 {
00394 public:
00395 FourierInserter3DMode7() {}
00396 virtual ~FourierInserter3DMode7() {}
00397
00398 virtual bool insert_pixel(const float& xx, const float& yy, const float& zz, const float dt[], const float& weight=1.0);
00399
00400 static FourierPixelInserter3D *NEW()
00401 {
00402 return new FourierInserter3DMode7();
00403 }
00404
00405 virtual string get_name() const
00406 {
00407 return "7";
00408 }
00409
00410 virtual string get_desc() const
00411 {
00412 return "Fourier pixel insertion mode 7";
00413 }
00414
00415 virtual bool effected_pixels_are_zero(const float& xx, const float& yy, const float& zz);
00416
00417 private:
00418
00419 FourierInserter3DMode7( const FourierInserter3DMode7& );
00420 FourierInserter3DMode7& operator=( const FourierInserter3DMode7& );
00421 };
00422
00426 class FourierInserter3DMode8 : public FourierPixelInserter3D
00427 {
00428 public:
00429 FourierInserter3DMode8() : W(0)
00430 {
00431
00432 }
00433 virtual ~FourierInserter3DMode8()
00434 {
00435 if ( W != 0 )
00436 delete [] W;
00437 }
00438
00439 virtual bool insert_pixel(const float& xx, const float& yy, const float& zz, const float dt[], const float& weight=1.0);
00440
00441 static FourierPixelInserter3D *NEW()
00442 {
00443 return new FourierInserter3DMode8();
00444 }
00445
00446 virtual string get_name() const
00447 {
00448 return "8";
00449 }
00450
00451 virtual string get_desc() const
00452 {
00453 return "Fourier pixel insertion mode 8";
00454 }
00455
00456 virtual bool effected_pixels_are_zero(const float&, const float&, const float&) { throw; }
00457
00458 virtual void init();
00459 private:
00460 int mFreqCutoff;
00461 float mDFreq;
00462
00463 FourierInserter3DMode8( const FourierInserter3DMode8& );
00464 FourierInserter3DMode8& operator=( const FourierInserter3DMode8& );
00465
00466 float* W;
00467 };
00468
00469
00470
00478 class InterpolationFunctoid
00479 {
00480 public:
00481 InterpolationFunctoid() {}
00482 virtual ~InterpolationFunctoid() {}
00483
00484 virtual float operate( const float radius ) const = 0;
00485 };
00486
00490 class InterpolationFunctoidMode3 : public InterpolationFunctoid
00491 {
00492 public:
00493 InterpolationFunctoidMode3() {}
00494 virtual ~InterpolationFunctoidMode3() {}
00495
00496 virtual float operate( const float radius ) const
00497 {
00498 return exp(-radius / EMConsts::I3G);
00499 }
00500 };
00501
00505 class InterpolationFunctoidMode4 : public InterpolationFunctoid
00506 {
00507 public:
00508 InterpolationFunctoidMode4() {}
00509 virtual ~InterpolationFunctoidMode4() {}
00510
00511 virtual float operate( const float radius ) const
00512 {
00513 return exp(-radius / EMConsts::I4G);
00514 }
00515 };
00516
00520 class InterpolationFunctoidMode5
00521 {
00522 public:
00523 InterpolationFunctoidMode5() { gimx = EMAN::Interp::get_gimx(); }
00524 virtual ~InterpolationFunctoidMode5()
00525 {
00526 if ( gimx != 0 )
00527 {
00528
00529
00530 }
00531 }
00532
00533 virtual float operate( const int mmx, const int mmy, const int mmz ) const
00534 {
00535 return gimx[abs(mmx) + abs(mmy) * 100 + abs(mmz) * 10000];
00536 }
00537 private:
00538 float * gimx;
00539 };
00540
00544 class InterpolationFunctoidMode6 : public InterpolationFunctoid
00545 {
00546 public:
00547 InterpolationFunctoidMode6() {}
00548 virtual ~InterpolationFunctoidMode6() {}
00549
00550 virtual float operate( const float radius ) const
00551 {
00552 return exp(-radius / EMConsts::I5G);
00553 }
00554 };
00555
00559 class InterpolationFunctoidMode7 : public InterpolationFunctoid
00560 {
00561 public:
00562 InterpolationFunctoidMode7() {}
00563 virtual ~InterpolationFunctoidMode7() {}
00564
00565 virtual float operate( const float radius ) const
00566 {
00567 return EMAN::Interp::hyperg(radius);
00568 }
00569 };
00570
00571
00606 class InterpolatedFRC : public FactoryBase
00607 {
00608 public:
00612 InterpolatedFRC();
00613
00616 virtual ~InterpolatedFRC()
00617 {
00618 free_memory();
00619 }
00620
00621 void set_params(const Dict & new_params);
00622
00623 TypeDict get_param_types() const
00624 {
00625 TypeDict d;
00626 d.put("nx", EMObject::INT);
00627 d.put("ny", EMObject::INT);
00628 d.put("nz", EMObject::INT);
00629 d.put("rdata", EMObject::FLOAT_POINTER);
00630 d.put("norm", EMObject::FLOAT_POINTER);
00631 d.put("z_scale", EMObject::FLOAT_POINTER);
00632 d.put("y_scale", EMObject::FLOAT_POINTER);
00633 d.put("x_scale", EMObject::FLOAT_POINTER);
00634 d.put("sampling", EMObject::FLOAT_POINTER);
00635 return d;
00636 }
00637
00646 virtual bool continue_frc_calc(const float& xx, const float& yy, const float& zz, const float dt[], const float& weight = 1.0) = 0;
00647
00648 unsigned int get_size() { return size; }
00649
00650 float operator[](const unsigned int& idx) { return frc[idx]; }
00651
00652
00653
00654 void reset();
00655
00656 protected:
00657 mutable Dict params;
00658
00659 InterpolatedFRC( const InterpolatedFRC& that );
00660
00661 InterpolatedFRC& operator=( const InterpolatedFRC& that);
00662
00667 bool continue_frc_calc_functoid(const float& xx, const float& yy, const float& zz, const float dt[], const InterpolationFunctoid& functoid, const float& weight = 1.0 );
00668
00671 void free_memory();
00672
00676 void init();
00677
00678
00679 float* threed_rdata, *norm_data;
00680
00681
00682 int nx, ny, nz, nxy;
00683
00684
00685 float x_scale, y_scale, z_scale;
00686
00687 float bin;
00688
00689
00690 int size;
00691 int pixel_radius_max;
00692 int pixel_radius_max_square;
00693
00694
00695
00696 float r, rn;
00697
00698 float* frc;
00699 float* frc_norm_rdata;
00700 float* frc_norm_dt;
00701
00702 int off[8];
00703 float g[8];
00704 public:
00708 class QualityScores
00709 {
00710 public:
00713 QualityScores() : frc_integral(0), snr_normed_frc_intergral(0), normed_snr_integral(0), norm(0) {}
00714
00718 QualityScores( const QualityScores& that ) : frc_integral(that.frc_integral),
00719 snr_normed_frc_intergral(that.snr_normed_frc_intergral), normed_snr_integral(that.normed_snr_integral), norm(that.norm) {}
00720
00724 QualityScores& operator=( const QualityScores& that );
00728 ~QualityScores() {}
00729
00731
00732 float get_frc_integral() const { return frc_integral; }
00733 float get_snr_normed_frc_integral() const { return snr_normed_frc_intergral; }
00734 float get_normed_snr_integral() const { return normed_snr_integral; }
00735 float get_norm() const { return norm; }
00736
00737 void set_frc_integral( const float& score ) { frc_integral = score; }
00738 void set_snr_normed_frc_integral(const float& score) { snr_normed_frc_intergral = score; }
00739 void set_normed_snr_integral(const float& score) { normed_snr_integral = score; }
00740 void set_norm( const float& score ) { norm = score; }
00741
00742 void debug_print()
00743 {
00744 cout << "frc " << frc_integral << " nfrc " << snr_normed_frc_intergral << " nsnr " << normed_snr_integral << " norm " << norm << endl;
00745 }
00746 private:
00747
00748 float frc_integral, snr_normed_frc_intergral, normed_snr_integral, norm;
00749
00750 };
00751
00752 QualityScores finish(const unsigned int num_particles);
00753 };
00754
00755 class InterpolatedFRCMode1 : public InterpolatedFRC
00756 {
00757 public:
00758 InterpolatedFRCMode1() {};
00759
00762 virtual ~InterpolatedFRCMode1() {}
00763
00764 virtual string get_name() const
00765 {
00766 return "1";
00767 }
00768
00769 static InterpolatedFRC *NEW()
00770 {
00771 return new InterpolatedFRCMode1();
00772 }
00773
00774 virtual string get_desc() const
00775 {
00776 return "Corresponds to Fourier pixel inserter mode 1";
00777 }
00778
00779 virtual bool continue_frc_calc(const float& xx, const float& yy, const float& zz, const float dt[], const float& weight = 1.0);
00780
00781 private:
00782
00783 InterpolatedFRCMode1( const InterpolatedFRCMode1& that );
00784
00785 InterpolatedFRCMode1& operator=( const InterpolatedFRCMode1& that);
00786
00787 };
00788
00789
00790 class InterpolatedFRCMode2 : public InterpolatedFRC
00791 {
00792 public:
00793 InterpolatedFRCMode2() {};
00794
00797 virtual ~InterpolatedFRCMode2() {}
00798
00799 virtual string get_name() const
00800 {
00801 return "2";
00802 }
00803
00804 static InterpolatedFRC *NEW()
00805 {
00806 return new InterpolatedFRCMode2();
00807 }
00808
00809 virtual string get_desc() const
00810 {
00811 return "Corresponds to Fourier pixel inserter mode 2";
00812 }
00813
00814 virtual bool continue_frc_calc(const float& xx, const float& yy, const float& zz, const float dt[], const float& weight = 1.0);
00815
00816 private:
00817
00818 InterpolatedFRCMode2( const InterpolatedFRCMode2& that );
00819
00820 InterpolatedFRCMode2& operator=( const InterpolatedFRCMode2& that);
00821
00822 };
00823
00824 class InterpolatedFRCMode3 : public InterpolatedFRC
00825 {
00826 public:
00827 InterpolatedFRCMode3() {};
00828
00831 virtual ~InterpolatedFRCMode3() {}
00832
00833 virtual string get_name() const
00834 {
00835 return "3";
00836 }
00837
00838 static InterpolatedFRC *NEW()
00839 {
00840 return new InterpolatedFRCMode3();
00841 }
00842
00843 virtual string get_desc() const
00844 {
00845 return "Corresponds to Fourier pixel inserter mode 3";
00846 }
00847
00848 virtual bool continue_frc_calc(const float& xx, const float& yy, const float& zz, const float dt[], const float& weight = 1.0);
00849
00850 private:
00851
00852 InterpolatedFRCMode3( const InterpolatedFRCMode3& that );
00853
00854 InterpolatedFRCMode3& operator=( const InterpolatedFRCMode3& that);
00855
00856 };
00857
00858
00859 class InterpolatedFRCMode4 : public InterpolatedFRC
00860 {
00861 public:
00862 InterpolatedFRCMode4( ) {};
00863
00866 virtual ~InterpolatedFRCMode4() {}
00867
00868 virtual string get_name() const
00869 {
00870 return "4";
00871 }
00872
00873 static InterpolatedFRC *NEW()
00874 {
00875 return new InterpolatedFRCMode4();
00876 }
00877
00878 virtual string get_desc() const
00879 {
00880 return "Corresponds to Fourier pixel inserter mode 4";
00881 }
00882
00883 virtual bool continue_frc_calc(const float& xx, const float& yy, const float& zz, const float dt[], const float& weight = 1.0);
00884
00885 private:
00886
00887 InterpolatedFRCMode4( const InterpolatedFRCMode4& that );
00888
00889 InterpolatedFRCMode4& operator=( const InterpolatedFRCMode4& that);
00890
00891 };
00892
00893
00894 class InterpolatedFRCMode5 : public InterpolatedFRC
00895 {
00896 public:
00897 InterpolatedFRCMode5() {};
00898
00901 virtual ~InterpolatedFRCMode5() {}
00902
00903 virtual string get_name() const
00904 {
00905 return "5";
00906 }
00907
00908 static InterpolatedFRC *NEW()
00909 {
00910 return new InterpolatedFRCMode5();
00911 }
00912
00913 virtual string get_desc() const
00914 {
00915 return "Corresponds to Fourier pixel inserter mode 5";
00916 }
00917
00918 virtual bool continue_frc_calc(const float& xx, const float& yy, const float& zz, const float dt[], const float& weight = 1.0);
00919
00920 private:
00921
00922 InterpolatedFRCMode5( const InterpolatedFRCMode5& that );
00923
00924 InterpolatedFRCMode5& operator=( const InterpolatedFRCMode5& that);
00925
00926 };
00927
00928 class InterpolatedFRCMode6 : public InterpolatedFRC
00929 {
00930 public:
00931 InterpolatedFRCMode6() {};
00932
00935 virtual ~InterpolatedFRCMode6() {}
00936
00937 virtual string get_name() const
00938 {
00939 return "6";
00940 }
00941
00942 static InterpolatedFRC *NEW()
00943 {
00944 return new InterpolatedFRCMode6();
00945 }
00946
00947 virtual string get_desc() const
00948 {
00949 return "Corresponds to Fourier pixel inserter mode 6";
00950 }
00951
00952 virtual bool continue_frc_calc(const float& xx, const float& yy, const float& zz, const float dt[], const float& weight = 1.0);
00953
00954 private:
00955
00956 InterpolatedFRCMode6( const InterpolatedFRCMode6& that );
00957
00958 InterpolatedFRCMode6& operator=( const InterpolatedFRCMode6& that);
00959
00960 };
00961
00962 class InterpolatedFRCMode7 : public InterpolatedFRC
00963 {
00964 public:
00965 InterpolatedFRCMode7() {}
00966
00969 virtual ~InterpolatedFRCMode7() {}
00970
00971 virtual string get_name() const
00972 {
00973 return "7";
00974 }
00975
00976 static InterpolatedFRC *NEW()
00977 {
00978 return new InterpolatedFRCMode7();
00979 }
00980
00981 virtual string get_desc() const
00982 {
00983 return "Corresponds to Fourier pixel inserter mode 7";
00984 }
00985
00986 virtual bool continue_frc_calc(const float& xx, const float& yy, const float& zz, const float dt[], const float& weight = 1.0);
00987
00988 private:
00989
00990 InterpolatedFRCMode7( const InterpolatedFRCMode7& that );
00991
00992 InterpolatedFRCMode7& operator=( const InterpolatedFRCMode7& that);
00993
00994 };
00995
00996
00997 template <> Factory < FourierPixelInserter3D >::Factory();
00998 template <> Factory < InterpolatedFRC >::Factory();
00999
01000 }
01001
01002
01003 #endif // eman_reconstructor_tools_h__