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 inline float *get_data() const
00071 {
00072 if(rdata == 0){
00073 rdata = (float*)malloc(num_bytes);
00074 cudaMemcpy(rdata,cudarwdata,num_bytes,cudaMemcpyDeviceToHost);
00075 }
00076 return rdata;
00077 }
00078 #else
00079 inline float *get_data() const { return rdata; }
00080 #endif
00081
00085 inline const float * get_const_data() const { return get_data(); }
00086
00094 inline void set_data(float* data, const int x, const int y, const int z) {
00095 if (rdata) { EMUtil::em_free(rdata); rdata = 0; }
00096
00097
00098
00099 rdata = data;
00100 nx = x; ny = y; nz = z;
00101 nxy = nx*ny;
00102 nxyz = (size_t)nx*ny*nz;
00103 update();
00104 }
00105
00106
00117 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);
00118
00130 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);
00131
00132
00133
00135 inline void update()
00136 {
00137 flags |= EMDATA_NEEDUPD;
00138 changecount++;
00139 }
00140
00142 inline void clearupdate()
00143 {
00144 flags &= ~EMDATA_NEEDUPD;
00145 changecount--;
00146 }
00147
00151 inline bool has_ctff() const
00152 {
00153 if (this->has_attr("ctf")) {
00154 return true;
00155 }
00156 else {
00157 return false;
00158 }
00159 }
00160
00161
00166 float calc_center_density();
00167
00168
00173 float calc_sigma_diff();
00174
00175
00179 IntPoint calc_min_location() const;
00180
00181
00185 IntPoint calc_max_location() const;
00186
00194 IntPoint calc_max_location_wrap(const int maxshiftx=-1, const int maxshifty=-1, const int maxshiftz=-1);
00195
00200 FloatPoint calc_center_of_mass(const float threshold=0);
00201
00206 size_t calc_min_index() const;
00207
00208
00213 size_t calc_max_index() const;
00214
00215
00225 vector<Pixel> calc_highest_locations(float threshold) const;
00226
00232 vector<Pixel> calc_n_highest_locations(int n);
00233
00238 vector<Pixel> find_pixels_with_value(float val);
00239
00245 float get_edge_mean() const;
00246
00247
00252 float get_circle_mean();
00253
00254
00258 Ctf * get_ctf() const;
00259
00260
00264 void set_ctf(Ctf * ctf);
00265
00266
00272 inline Vec3f get_translation() const
00273 {
00274 return all_translation;
00275 }
00276
00277
00282 inline void set_translation(const Vec3f &t)
00283 {
00284 all_translation = t;
00285 }
00286
00287
00294 inline void set_translation(float dx, float dy, float dz)
00295 {
00296 all_translation = Vec3f(dx, dy, dz);
00297 }
00298
00299
00303 inline Transform get_transform() const
00304 {
00305 Dict rotation_dict;
00306 rotation_dict["type"] = "eman";
00307 rotation_dict["alt"] = attr_dict["euler_alt"];
00308 rotation_dict["az"] = attr_dict["euler_az"];
00309 rotation_dict["phi"] = attr_dict["euler_phi"];
00310
00311 Transform trans;
00312 trans.to_identity();
00313 trans.set_rotation(rotation_dict);
00314
00315 return trans;
00316 }
00317
00325 inline void set_rotation(float az, float alt, float phi)
00326 {
00327 attr_dict["orientation_convention"] = "EMAN";
00328 attr_dict["euler_alt"]=alt;
00329 attr_dict["euler_az"]=az;
00330 attr_dict["euler_phi"]=phi;
00331 }
00332
00333
00339 inline void set_rotation(const Transform& t3d)
00340 {
00341 Dict d = t3d.get_rotation("eman");
00342 attr_dict["orientation_convention"] = "EMAN";
00343 attr_dict["euler_alt"] = (float) d["alt"];
00344 attr_dict["euler_az"] = (float) d["az"];
00345 attr_dict["euler_phi"] = (float) d["phi"];;
00346 }
00347
00348
00356 void set_size(int nx, int ny=1, int nz=1);
00357
00358 #ifdef EMAN2_USING_CUDA
00359
00366 void set_size_cuda(int nx, int ny=1, int nz=1);
00367 #endif //#EMAN2_USING_CUDA
00368
00369
00376 void set_complex_size(int nx, int ny=1, int nz=1) {
00377 set_size(nx*2, ny, nz);
00378 }
00379
00380
00384 inline void set_path(const string & new_path)
00385 {
00386 path = new_path;
00387 }
00388
00389
00393 inline void set_pathnum(int n)
00394 {
00395 pathnum = n;
00396 }
00397
00398
00407 MArray2D get_2dview() const;
00408
00409
00418 MArray3D get_3dview() const;
00419
00420
00428 MCArray2D get_2dcview() const;
00429
00430
00438 MCArray3D get_3dcview() const;
00439
00440
00448 MCArray3D* get_3dcviewptr() const;
00449
00450
00463 MArray2D get_2dview(int x0, int y0) const;
00464
00465
00479 MArray3D get_3dview(int x0, int y0, int z0) const;
00480
00481
00494 MCArray2D get_2dcview(int x0, int y0) const;
00495
00496
00510 MCArray3D get_3dcview(int x0, int y0, int z0) const;
00511
00512
00521 EMObject get_attr(const string & attr_name) const;
00522
00532 EMObject get_attr_default(const string & attr_name, const EMObject & em_obj = EMObject()) const;
00533
00539 void set_attr(const string & key, EMObject val);
00540
00541
00547 void set_attr_python(const string & key, EMObject val);
00548
00553 inline bool has_attr(const string& key) const {
00554 return attr_dict.has_key(key);
00555 }
00556
00563 Dict get_attr_dict() const;
00564
00565 #ifdef EMAN2_USING_CUDA
00566
00571 inline Dict get_attr_dict_cuda() const {return attr_dict;}
00572 #endif
00573
00578 void set_attr_dict(const Dict & new_dict);
00579
00580
00581
00586 void del_attr(const string & attr_name);
00587
00588
00593 void del_attr_dict(const vector<string> & del_keys);
00594
00595
00599 inline int get_xsize() const
00600 {
00601 return nx;
00602 }
00603
00604
00608 inline int get_ysize() const
00609 {
00610 return ny;
00611 }
00612
00613
00617 inline int get_zsize() const
00618 {
00619 return nz;
00620 }
00621
00622
00626 inline size_t get_size() const
00627 {
00628 return (size_t)nx*(size_t)ny*(size_t)nz;
00629 }
00630
00634 inline vector<float> get_data_as_vector() const {
00635 int size = get_size();
00636 vector<float> v(size);
00637 float* data = get_data();
00638 std::copy(data,data+size,v.begin());
00639 return v;
00640 }
00641
00645 inline int get_ndim() const
00646 {
00647 if (nz <= 1) {
00648 if (ny <= 1) {
00649 return 1;
00650 }
00651 else {
00652 return 2;
00653 }
00654 }
00655
00656 return 3;
00657 }
00658
00659
00663 inline bool is_shuffled() const
00664 {
00665 if (flags & EMDATA_SHUFFLE) {
00666 return true;
00667 }
00668
00669 if(has_attr("is_shuffled")) {
00670 return get_attr("is_shuffled");
00671 }
00672
00673 return false;
00674 }
00675
00676
00680 inline bool is_FH() const
00681 {
00682 if (flags & EMDATA_FH) {
00683 return true;
00684 }
00685
00686 if(has_attr("is_fh")) {
00687 return get_attr("is_fh");
00688 }
00689
00690 return false;
00691 }
00692
00693
00697 inline bool is_complex() const
00698 {
00699 if(attr_dict.has_key("is_complex")) {
00700 if (int(attr_dict["is_complex"])) {
00701 return true;
00702 }
00703 else {
00704 return false;
00705 }
00706 }
00707 else {
00708 return false;
00709 }
00710 }
00711
00712
00716 inline bool is_real() const
00717 {
00718 return !is_complex();
00719 }
00720
00721
00726 inline void set_shuffled(bool is_shuffled)
00727 {
00728 if (is_shuffled) {
00729
00730
00731 set_attr("is_shuffled", (int)1);
00732 }
00733 else {
00734
00735 set_attr("is_shuffled", (int)0);
00736 }
00737 }
00738
00739
00744 inline void set_FH(bool is_FH)
00745 {
00746 if (is_FH) {
00747
00748 set_attr("is_fh", (int)1);
00749 }
00750 else {
00751
00752 set_attr("is_fh", (int)0);
00753 }
00754 }
00755
00756
00761 inline void set_complex(bool is_complex)
00762 {
00763 if (is_complex) {
00764 attr_dict["is_complex"] = int(1);
00765 }
00766 else {
00767 attr_dict["is_complex"] = int(0);
00768 }
00769 }
00770
00771
00776 inline bool is_complex_x() const
00777 {
00778 if(attr_dict.has_key("is_complex_x")) {
00779 if (int(attr_dict["is_complex_x"])) {
00780 return true;
00781 }
00782 else {
00783 return false;
00784 }
00785 }
00786 else {
00787 return false;
00788 }
00789 }
00790
00791 ;
00796 inline void set_complex_x(bool is_complex_x)
00797 {
00798 if (is_complex_x) {
00799 attr_dict["is_complex_x"] = int(1);
00800 }
00801 else {
00802 attr_dict["is_complex_x"] = int(0);
00803 }
00804 }
00805
00806
00810 inline bool is_flipped() const
00811 {
00812 if (flags & EMDATA_FLIP) {
00813 return true;
00814 }
00815
00816 if(attr_dict.has_key("is_flipped")) {
00817 if(get_attr("is_flipped")) {
00818 return true;
00819 }
00820 }
00821
00822 return false;
00823
00824 }
00825
00826
00831 inline void set_flipped(bool is_flipped)
00832 {
00833 if (is_flipped) {
00834 set_attr("is_flipped", (int)1);
00835 }
00836 else {
00837 set_attr("is_flipped", (int)0);
00838 }
00839 }
00840
00841
00846 inline bool is_ri() const
00847 {
00848 if(attr_dict.has_key("is_complex_ri")) {
00849 if (int(attr_dict["is_complex_ri"])) {
00850 return true;
00851 }
00852 else {
00853 return false;
00854 }
00855 }
00856 else {
00857 return false;
00858 }
00859 }
00860
00861
00866 inline void set_ri(bool is_ri)
00867 {
00868 if (is_ri) {
00869 attr_dict["is_complex_ri"] = int(1);
00870 }
00871 else {
00872 attr_dict["is_complex_ri"] = int(0);
00873 }
00874 }
00875
00876
00880 inline bool is_fftpadded() const
00881 {
00882 if (flags & EMDATA_PAD) {
00883 return true;
00884 }
00885
00886 if(has_attr("is_fftpad")) {
00887 return get_attr("is_fftpad");
00888 }
00889
00890 return false;
00891
00892 }
00893
00894
00899 inline void set_fftpad(bool is_fftpadded)
00900 {
00901 if (is_fftpadded) {
00902 set_attr("is_fftpad", int(1));
00903 }
00904 else {
00905 set_attr("is_fftpad", int(0));
00906 }
00907 }
00908
00909
00913 inline bool is_fftodd() const
00914 {
00915 if(flags & EMDATA_FFTODD) {
00916 return true;
00917 }
00918 else if( attr_dict.has_key("is_fftodd") && (int)attr_dict["is_fftodd"] == 1 ) {
00919 return true;
00920 }
00921 else {
00922 return false;
00923 }
00924 }
00925
00926
00931 inline void set_fftodd(bool is_fftodd)
00932 {
00933 if (is_fftodd) {
00934 set_attr("is_fftodd", int(1));
00935 }
00936 else {
00937 set_attr("is_fftodd", int(0));
00938 }
00939 }
00940
00941
00945 inline void set_nxc(int nxc)
00946 {
00947 attr_dict["nxc"] = nxc;
00948 }
00949
00950
00951
00952
00953
00954 inline int get_flags() const
00955 {
00956 return flags;
00957 }
00958
00959 inline void set_flags(int f)
00960 {
00961 flags = f;
00962 }
00963
00964 inline int get_changecount() const
00965 {
00966 return changecount;
00967 }
00968
00969 inline void set_changecount(int c)
00970 {
00971 changecount = c;
00972 }
00973
00974 inline int get_xoff() const
00975 {
00976 return xoff;
00977 }
00978
00979 inline int get_yoff() const
00980 {
00981 return yoff;
00982 }
00983
00984 inline int get_zoff() const
00985 {
00986 return zoff;
00987 }
00988
00989 inline void set_xyzoff(int x, int y, int z)
00990 {
00991 xoff = x;
00992 yoff = y;
00993 zoff = z;
00994 }
00995
01001 void scale_pixel(float scale_factor) const;
01002
01003 inline string get_path() const
01004 {
01005 return path;
01006 }
01007
01008 inline int get_pathnum() const
01009 {
01010 return pathnum;
01011 }
01012
01013
01014 std::string get_data_pickle() const;
01015
01016
01017 void set_data_pickle(std::string vf);
01018
01019
01020 int get_supp_pickle() const;
01021
01022 void set_supp_pickle(int i);
01023
01024 vector<Vec3i> mask_contig_region(const float& val, const Vec3i& seed);
01025
01031 float get_amplitude_thres(float thres);
01032
01033 private:
01039 void set_attr_dict_explicit(const Dict & new_dict);
01040
01041
01042
01043 #endif //emdata__metadata_h__