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
00040 #ifndef emdata__metadata_h__
00041 #define emdata__metadata_h__
00042
00043 public:
00049 EMData *get_fft_amplitude();
00050
00056 EMData *get_fft_amplitude2D();
00057
00063 EMData *get_fft_phase();
00064
00065
00069 #ifdef EMAN2_USING_CUDA
00070 float *get_data() const;
00071 #else
00072 inline float *get_data() const { return rdata; }
00073 #endif
00074
00078 inline const float * const get_const_data() const { return get_data(); }
00079
00087 inline void set_data(float* data, const int x, const int y, const int z) {
00088 if (rdata) { EMUtil::em_free(rdata); rdata = 0; }
00089 #ifdef EMAN2_USING_CUDA
00090 free_cuda_memory();
00091 #endif
00092 rdata = data;
00093 nx = x; ny = y; nz = z;
00094 nxy = nx*ny;
00095 nxyz = nx*ny*nz;
00096 update();
00097 }
00098
00099
00110 void write_data(string fsp,size_t loc,const Region* const area=0,const int file_nx=0, const int file_ny=0, const int file_nz=0);
00111
00123 void read_data(string fsp,size_t loc,const Region* area=0,const int file_nx=0, const int file_ny=0, const int file_nz=0);
00124
00125
00126
00128 inline void update()
00129 {
00130 flags |= EMDATA_NEEDUPD | EMDATA_GPU_NEEDS_UPDATE | EMDATA_GPU_RO_NEEDS_UPDATE;
00131 changecount++;
00132 }
00133
00134
00138 inline bool has_ctff() const
00139 {
00140 if (this->has_attr("ctf")) {
00141 return true;
00142 }
00143 else {
00144 return false;
00145 }
00146 }
00147
00148
00153 float calc_center_density();
00154
00155
00160 float calc_sigma_diff();
00161
00162
00166 IntPoint calc_min_location() const;
00167
00168
00172 IntPoint calc_max_location() const;
00173
00181 IntPoint calc_max_location_wrap(const int maxshiftx=-1, const int maxshifty=-1, const int maxshiftz=-1);
00182
00187 FloatPoint calc_center_of_mass();
00188
00193 int calc_min_index() const;
00194
00195
00200 int calc_max_index() const;
00201
00202
00212 vector<Pixel> calc_highest_locations(float threshold) const;
00213
00219 vector<Pixel> calc_n_highest_locations(int n);
00220
00221
00227 float get_edge_mean() const;
00228
00229
00234 float get_circle_mean();
00235
00236
00240 Ctf * get_ctf() const;
00241
00242
00246 void set_ctf(Ctf * ctf);
00247
00248
00254 inline Vec3f get_translation() const
00255 {
00256 return all_translation;
00257 }
00258
00259
00264 inline void set_translation(const Vec3f &t)
00265 {
00266 all_translation = t;
00267 }
00268
00269
00276 inline void set_translation(float dx, float dy, float dz)
00277 {
00278 all_translation = Vec3f(dx, dy, dz);
00279 }
00280
00281
00285 inline Transform get_transform() const
00286 {
00287 Dict rotation_dict;
00288 rotation_dict["type"] = "eman";
00289 rotation_dict["alt"] = attr_dict["euler_alt"];
00290 rotation_dict["az"] = attr_dict["euler_az"];
00291 rotation_dict["phi"] = attr_dict["euler_phi"];
00292
00293 Transform trans;
00294 trans.to_identity();
00295 trans.set_rotation(rotation_dict);
00296
00297 return trans;
00298 }
00299
00307 inline void set_rotation(float az, float alt, float phi)
00308 {
00309 attr_dict["orientation_convention"] = "EMAN";
00310 attr_dict["euler_alt"]=alt;
00311 attr_dict["euler_az"]=az;
00312 attr_dict["euler_phi"]=phi;
00313 }
00314
00315
00321 inline void set_rotation(const Transform3D& t3d)
00322 {
00323 Dict d = t3d.get_rotation(Transform3D::EMAN);
00324 attr_dict["orientation_convention"] = "EMAN";
00325 attr_dict["euler_alt"] = (float) d["alt"];
00326 attr_dict["euler_az"] = (float) d["az"];
00327 attr_dict["euler_phi"] = (float) d["phi"];;
00328 }
00329
00330
00338 void set_size(int nx, int ny=1, int nz=1);
00339
00340 #ifdef EMAN2_USING_CUDA
00341
00348 void set_size_cuda(int nx, int ny=1, int nz=1);
00349 #endif //#EMAN2_USING_CUDA
00350
00351
00358 void set_complex_size(int nx, int ny=1, int nz=1) {
00359 set_size(nx*2, ny, nz);
00360 }
00361
00362
00366 inline void set_path(const string & new_path)
00367 {
00368 path = new_path;
00369 }
00370
00371
00375 inline void set_pathnum(int n)
00376 {
00377 pathnum = n;
00378 }
00379
00380
00389 MArray2D get_2dview() const;
00390
00391
00400 MArray3D get_3dview() const;
00401
00402
00410 MCArray2D get_2dcview() const;
00411
00412
00420 MCArray3D get_3dcview() const;
00421
00422
00430 MCArray3D* get_3dcviewptr() const;
00431
00432
00445 MArray2D get_2dview(int x0, int y0) const;
00446
00447
00461 MArray3D get_3dview(int x0, int y0, int z0) const;
00462
00463
00476 MCArray2D get_2dcview(int x0, int y0) const;
00477
00478
00492 MCArray3D get_3dcview(int x0, int y0, int z0) const;
00493
00494
00503 EMObject get_attr(const string & attr_name) const;
00504
00514 EMObject get_attr_default(const string & attr_name, const EMObject & em_obj = EMObject()) const;
00515
00521 void set_attr(const string & key, EMObject val);
00522
00523
00529 void set_attr_python(const string & key, EMObject val);
00530
00535 inline bool has_attr(const string& key) const {
00536 return attr_dict.has_key(key);
00537 }
00538
00545 Dict get_attr_dict() const;
00546
00547
00552 void set_attr_dict(const Dict & new_dict);
00553
00554
00555
00560 void del_attr(const string & attr_name);
00561
00562
00567 void del_attr_dict(const vector<string> & del_keys);
00568
00569
00573 inline int get_xsize() const
00574 {
00575 return nx;
00576 }
00577
00578
00582 inline int get_ysize() const
00583 {
00584 return ny;
00585 }
00586
00587
00591 inline int get_zsize() const
00592 {
00593 return nz;
00594 }
00595
00596
00600 inline size_t get_size() const
00601 {
00602 return (size_t)nx*(size_t)ny*(size_t)nz;
00603 }
00604
00608 inline vector<float> get_data_as_vector() const {
00609 int size = get_size();
00610 vector<float> v(size);
00611 float* data = get_data();
00612 std::copy(data,data+size,v.begin());
00613 return v;
00614 }
00615
00619 inline int get_ndim() const
00620 {
00621 if (nz <= 1) {
00622 if (ny <= 1) {
00623 return 1;
00624 }
00625 else {
00626 return 2;
00627 }
00628 }
00629
00630 return 3;
00631 }
00632
00633
00637 inline bool is_shuffled() const
00638 {
00639 if (flags & EMDATA_SHUFFLE) {
00640 return true;
00641 }
00642
00643 if(has_attr("is_shuffled")) {
00644 return get_attr("is_shuffled");
00645 }
00646
00647 return false;
00648 }
00649
00650
00654 inline bool is_FH() const
00655 {
00656 if (flags & EMDATA_FH) {
00657 return true;
00658 }
00659
00660 if(has_attr("is_fh")) {
00661 return get_attr("is_fh");
00662 }
00663
00664 return false;
00665 }
00666
00667
00671 inline bool is_complex() const
00672 {
00673 if(attr_dict.has_key("is_complex")) {
00674 if (int(attr_dict["is_complex"])) {
00675 return true;
00676 }
00677 else {
00678 return false;
00679 }
00680 }
00681 else {
00682 return false;
00683 }
00684 }
00685
00686
00690 inline bool is_real() const
00691 {
00692 return !is_complex();
00693 }
00694
00695
00700 inline void set_shuffled(bool is_shuffled)
00701 {
00702 if (is_shuffled) {
00703
00704
00705 set_attr("is_shuffled", (int)1);
00706 }
00707 else {
00708
00709 set_attr("is_shuffled", (int)0);
00710 }
00711 }
00712
00713
00718 inline void set_FH(bool is_FH)
00719 {
00720 if (is_FH) {
00721
00722 set_attr("is_fh", (int)1);
00723 }
00724 else {
00725
00726 set_attr("is_fh", (int)0);
00727 }
00728 }
00729
00730
00735 inline void set_complex(bool is_complex)
00736 {
00737 if (is_complex) {
00738 attr_dict["is_complex"] = int(1);
00739 }
00740 else {
00741 attr_dict["is_complex"] = int(0);
00742 }
00743 }
00744
00745
00750 inline bool is_complex_x() const
00751 {
00752 if(attr_dict.has_key("is_complex_x")) {
00753 if (int(attr_dict["is_complex_x"])) {
00754 return true;
00755 }
00756 else {
00757 return false;
00758 }
00759 }
00760 else {
00761 return false;
00762 }
00763 }
00764
00765 ;
00770 inline void set_complex_x(bool is_complex_x)
00771 {
00772 if (is_complex_x) {
00773 attr_dict["is_complex_x"] = int(1);
00774 }
00775 else {
00776 attr_dict["is_complex_x"] = int(0);
00777 }
00778 }
00779
00780
00784 inline bool is_flipped() const
00785 {
00786 if (flags & EMDATA_FLIP) {
00787 return true;
00788 }
00789
00790 if(attr_dict.has_key("is_flipped")) {
00791 if(get_attr("is_flipped")) {
00792 return true;
00793 }
00794 }
00795
00796 return false;
00797
00798 }
00799
00800
00805 inline void set_flipped(bool is_flipped)
00806 {
00807 if (is_flipped) {
00808 set_attr("is_flipped", (int)1);
00809 }
00810 else {
00811 set_attr("is_flipped", (int)0);
00812 }
00813 }
00814
00815
00820 inline bool is_ri() const
00821 {
00822 if(attr_dict.has_key("is_complex_ri")) {
00823 if (int(attr_dict["is_complex_ri"])) {
00824 return true;
00825 }
00826 else {
00827 return false;
00828 }
00829 }
00830 else {
00831 return false;
00832 }
00833 }
00834
00835
00840 inline void set_ri(bool is_ri)
00841 {
00842 if (is_ri) {
00843 attr_dict["is_complex_ri"] = int(1);
00844 }
00845 else {
00846 attr_dict["is_complex_ri"] = int(0);
00847 }
00848 }
00849
00850
00854 inline bool is_fftpadded() const
00855 {
00856 if (flags & EMDATA_PAD) {
00857 return true;
00858 }
00859
00860 if(has_attr("is_fftpad")) {
00861 return get_attr("is_fftpad");
00862 }
00863
00864 return false;
00865
00866 }
00867
00868
00873 inline void set_fftpad(bool is_fftpadded)
00874 {
00875 if (is_fftpadded) {
00876 set_attr("is_fftpad", int(1));
00877 }
00878 else {
00879 set_attr("is_fftpad", int(0));
00880 }
00881 }
00882
00883
00887 inline bool is_fftodd() const
00888 {
00889 if(flags & EMDATA_FFTODD) {
00890 return true;
00891 }
00892 else if( attr_dict.has_key("is_fftodd") && (int)attr_dict["is_fftodd"] == 1 ) {
00893 return true;
00894 }
00895 else {
00896 return false;
00897 }
00898 }
00899
00900
00905 inline void set_fftodd(bool is_fftodd)
00906 {
00907 if (is_fftodd) {
00908 set_attr("is_fftodd", int(1));
00909 }
00910 else {
00911 set_attr("is_fftodd", int(0));
00912 }
00913 }
00914
00915
00919 inline void set_nxc(int nxc)
00920 {
00921 attr_dict["nxc"] = nxc;
00922 }
00923
00924
00925
00926
00927
00928 inline int get_flags() const
00929 {
00930 return flags;
00931 }
00932
00933 inline void set_flags(int f)
00934 {
00935 flags = f;
00936 }
00937
00938 inline int get_changecount() const
00939 {
00940 return changecount;
00941 }
00942
00943 inline void set_changecount(int c)
00944 {
00945 changecount = c;
00946 }
00947
00948 inline int get_xoff() const
00949 {
00950 return xoff;
00951 }
00952
00953 inline int get_yoff() const
00954 {
00955 return yoff;
00956 }
00957
00958 inline int get_zoff() const
00959 {
00960 return zoff;
00961 }
00962
00963 inline void set_xyzoff(int x, int y, int z)
00964 {
00965 xoff = x;
00966 yoff = y;
00967 zoff = z;
00968 }
00969
00975 void scale_pixel(float scale_factor) const;
00976
00977 inline string get_path() const
00978 {
00979 return path;
00980 }
00981
00982 inline int get_pathnum() const
00983 {
00984 return pathnum;
00985 }
00986
00987
00988 std::string get_data_pickle() const;
00989
00990
00991 void set_data_pickle(std::string vf);
00992
00993
00994 int get_supp_pickle() const;
00995
00996 void set_supp_pickle(int i);
00997
00998 vector<Vec3i> mask_contig_region(const float& val, const Vec3i& seed);
00999
01000
01001 private:
01007 void set_attr_dict_explicit(const Dict & new_dict);
01008
01009
01010
01011 #endif //emdata__metadata_h__