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 cudadirtybit = 1;
00075 }
00076 if(cudadirtybit == 1){
00077 cudadirtybit = 0;
00078 cudaMemcpy(rdata,cudarwdata,num_bytes,cudaMemcpyDeviceToHost);
00079 }
00080 return rdata;
00081 }
00082 #else
00083 inline float *get_data() const { return rdata; }
00084 #endif
00085
00089 inline const float * get_const_data() const { return get_data(); }
00090
00098 inline void set_data(float* data, const int x, const int y, const int z) {
00099 if (rdata) { EMUtil::em_free(rdata); rdata = 0; }
00100 #ifdef EMAN2_USING_CUDA
00101
00102
00103 #endif
00104 rdata = data;
00105 nx = x; ny = y; nz = z;
00106 nxy = nx*ny;
00107 nxyz = (size_t)nx*ny*nz;
00108 update();
00109 }
00110
00111 inline void set_data(float* data) {
00112 rdata = data;
00113 }
00114
00125 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);
00126
00138 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);
00139
00140
00141
00143 inline void update()
00144 {
00145 flags |= EMDATA_NEEDUPD;
00146 changecount++;
00147 }
00148
00150 inline void clearupdate()
00151 {
00152 flags &= ~EMDATA_NEEDUPD;
00153 changecount--;
00154 }
00155
00159 inline bool has_ctff() const
00160 {
00161 if (this->has_attr("ctf")) {
00162 return true;
00163 }
00164 else {
00165 return false;
00166 }
00167 }
00168
00169
00174 float calc_center_density();
00175
00176
00181 float calc_sigma_diff();
00182
00183
00187 IntPoint calc_min_location() const;
00188
00189
00193 IntPoint calc_max_location() const;
00194
00202 IntPoint calc_max_location_wrap(const int maxshiftx=-1, const int maxshifty=-1, const int maxshiftz=-1);
00203
00211 vector<float> calc_max_location_wrap_intp(const int maxshiftx=-1, const int maxshifty=-1, const int maxshiftz=-1);
00212
00217 FloatPoint calc_center_of_mass(const float threshold=0);
00218
00223 size_t calc_min_index() const;
00224
00225
00230 size_t calc_max_index() const;
00231
00232
00242 vector<Pixel> calc_highest_locations(float threshold) const;
00243
00249 vector<Pixel> calc_n_highest_locations(int n);
00250
00255 vector<Pixel> find_pixels_with_value(float val);
00256
00262 float get_edge_mean() const;
00263
00264
00269 float get_circle_mean();
00270
00271
00275 Ctf * get_ctf() const;
00276
00277
00281 void set_ctf(Ctf * ctf);
00282
00283
00289 inline Vec3f get_translation() const
00290 {
00291 return all_translation;
00292 }
00293
00294
00299 inline void set_translation(const Vec3f &t)
00300 {
00301 all_translation = t;
00302 }
00303
00304
00311 inline void set_translation(float dx, float dy, float dz)
00312 {
00313 all_translation = Vec3f(dx, dy, dz);
00314 }
00315
00316
00320 inline Transform get_transform() const
00321 {
00322 Dict rotation_dict;
00323 rotation_dict["type"] = "eman";
00324 rotation_dict["alt"] = attr_dict["euler_alt"];
00325 rotation_dict["az"] = attr_dict["euler_az"];
00326 rotation_dict["phi"] = attr_dict["euler_phi"];
00327
00328 Transform trans;
00329 trans.to_identity();
00330 trans.set_rotation(rotation_dict);
00331
00332 return trans;
00333 }
00334
00342 inline void set_rotation(float az, float alt, float phi)
00343 {
00344 attr_dict["orientation_convention"] = "EMAN";
00345 attr_dict["euler_alt"]=alt;
00346 attr_dict["euler_az"]=az;
00347 attr_dict["euler_phi"]=phi;
00348 }
00349
00350
00356 inline void set_rotation(const Transform& t3d)
00357 {
00358 Dict d = t3d.get_rotation("eman");
00359 attr_dict["orientation_convention"] = "EMAN";
00360 attr_dict["euler_alt"] = (float) d["alt"];
00361 attr_dict["euler_az"] = (float) d["az"];
00362 attr_dict["euler_phi"] = (float) d["phi"];;
00363 }
00364
00365
00373 void set_size(int nx, int ny=1, int nz=1, bool noalloc=false);
00374
00375 #ifdef EMAN2_USING_CUDA
00376
00383 void set_size_cuda(int nx, int ny=1, int nz=1);
00384 #endif //#EMAN2_USING_CUDA
00385
00386
00393 void set_complex_size(int nx, int ny=1, int nz=1) {
00394 set_size(nx*2, ny, nz);
00395 }
00396
00397
00401 inline void set_path(const string & new_path)
00402 {
00403 path = new_path;
00404 }
00405
00406
00410 inline void set_pathnum(int n)
00411 {
00412 pathnum = n;
00413 }
00414
00415
00424 MArray2D get_2dview() const;
00425
00426
00435 MArray3D get_3dview() const;
00436
00437
00445 MCArray2D get_2dcview() const;
00446
00447
00455 MCArray3D get_3dcview() const;
00456
00457
00465 MCArray3D* get_3dcviewptr() const;
00466
00467
00480 MArray2D get_2dview(int x0, int y0) const;
00481
00482
00496 MArray3D get_3dview(int x0, int y0, int z0) const;
00497
00498
00511 MCArray2D get_2dcview(int x0, int y0) const;
00512
00513
00527 MCArray3D get_3dcview(int x0, int y0, int z0) const;
00528
00529
00538 EMObject get_attr(const string & attr_name) const;
00539
00549 EMObject get_attr_default(const string & attr_name, const EMObject & em_obj = EMObject()) const;
00550
00556 void set_attr(const string & key, EMObject val);
00557
00558
00564 void set_attr_python(const string & key, EMObject val);
00565
00570 inline bool has_attr(const string& key) const {
00571 return attr_dict.has_key(key);
00572 }
00573
00580 Dict get_attr_dict() const;
00581
00582 #ifdef EMAN2_USING_CUDA
00583
00588 inline Dict get_attr_dict_cuda() const {return attr_dict;}
00589 #endif
00590
00595 void set_attr_dict(const Dict & new_dict);
00596
00597
00598
00603 void del_attr(const string & attr_name);
00604
00605
00610 void del_attr_dict(const vector<string> & del_keys);
00611
00612
00616 inline int get_xsize() const
00617 {
00618 return nx;
00619 }
00620
00621
00625 inline int get_ysize() const
00626 {
00627 return ny;
00628 }
00629
00630
00634 inline int get_zsize() const
00635 {
00636 return nz;
00637 }
00638
00639
00643 inline size_t get_size() const
00644 {
00645 return (size_t)nx*(size_t)ny*(size_t)nz;
00646 }
00647
00651 inline vector<float> get_data_as_vector() const {
00652 int size = get_size();
00653 vector<float> v(size);
00654 float* data = get_data();
00655 std::copy(data,data+size,v.begin());
00656 return v;
00657 }
00658
00662 inline int get_ndim() const
00663 {
00664 if (nz <= 1) {
00665 if (ny <= 1) {
00666 return 1;
00667 }
00668 else {
00669 return 2;
00670 }
00671 }
00672
00673 return 3;
00674 }
00675
00676
00680 inline bool is_shuffled() const
00681 {
00682 if (flags & EMDATA_SHUFFLE) {
00683 return true;
00684 }
00685
00686 if(has_attr("is_shuffled")) {
00687 return get_attr("is_shuffled");
00688 }
00689
00690 return false;
00691 }
00692
00693
00697 inline bool is_FH() const
00698 {
00699 if (flags & EMDATA_FH) {
00700 return true;
00701 }
00702
00703 if(has_attr("is_fh")) {
00704 return get_attr("is_fh");
00705 }
00706
00707 return false;
00708 }
00709
00710
00714 inline bool is_complex() const
00715 {
00716 if(attr_dict.has_key("is_complex")) {
00717 if (int(attr_dict["is_complex"])) {
00718 return true;
00719 }
00720 else {
00721 return false;
00722 }
00723 }
00724 else {
00725 return false;
00726 }
00727 }
00728
00729
00733 inline bool is_real() const
00734 {
00735 return !is_complex();
00736 }
00737
00738
00743 inline void set_shuffled(bool is_shuffled)
00744 {
00745 if (is_shuffled) {
00746
00747
00748 set_attr("is_shuffled", (int)1);
00749 }
00750 else {
00751
00752 set_attr("is_shuffled", (int)0);
00753 }
00754 }
00755
00756
00761 inline void set_FH(bool is_FH)
00762 {
00763 if (is_FH) {
00764
00765 set_attr("is_fh", (int)1);
00766 }
00767 else {
00768
00769 set_attr("is_fh", (int)0);
00770 }
00771 }
00772
00773
00778 inline void set_complex(bool is_complex)
00779 {
00780 if (is_complex) {
00781 attr_dict["is_complex"] = int(1);
00782 }
00783 else {
00784 attr_dict["is_complex"] = int(0);
00785 }
00786 }
00787
00788
00793 inline bool is_complex_x() const
00794 {
00795 if(attr_dict.has_key("is_complex_x")) {
00796 if (int(attr_dict["is_complex_x"])) {
00797 return true;
00798 }
00799 else {
00800 return false;
00801 }
00802 }
00803 else {
00804 return false;
00805 }
00806 }
00807
00808 ;
00813 inline void set_complex_x(bool is_complex_x)
00814 {
00815 if (is_complex_x) {
00816 attr_dict["is_complex_x"] = int(1);
00817 }
00818 else {
00819 attr_dict["is_complex_x"] = int(0);
00820 }
00821 }
00822
00823
00827 inline bool is_flipped() const
00828 {
00829 if (flags & EMDATA_FLIP) {
00830 return true;
00831 }
00832
00833 if(attr_dict.has_key("is_flipped")) {
00834 if(get_attr("is_flipped")) {
00835 return true;
00836 }
00837 }
00838
00839 return false;
00840
00841 }
00842
00843
00848 inline void set_flipped(bool is_flipped)
00849 {
00850 if (is_flipped) {
00851 set_attr("is_flipped", (int)1);
00852 }
00853 else {
00854 set_attr("is_flipped", (int)0);
00855 }
00856 }
00857
00858
00863 inline bool is_ri() const
00864 {
00865 if(attr_dict.has_key("is_complex_ri")) {
00866 if (int(attr_dict["is_complex_ri"])) {
00867 return true;
00868 }
00869 else {
00870 return false;
00871 }
00872 }
00873 else {
00874 return false;
00875 }
00876 }
00877
00878
00883 inline void set_ri(bool is_ri)
00884 {
00885 if (is_ri) {
00886 attr_dict["is_complex_ri"] = int(1);
00887 }
00888 else {
00889 attr_dict["is_complex_ri"] = int(0);
00890 }
00891 }
00892
00893
00897 inline bool is_fftpadded() const
00898 {
00899 if (flags & EMDATA_PAD) {
00900 return true;
00901 }
00902
00903 if(has_attr("is_fftpad")) {
00904 return get_attr("is_fftpad");
00905 }
00906
00907 return false;
00908
00909 }
00910
00911
00916 inline void set_fftpad(bool is_fftpadded)
00917 {
00918 if (is_fftpadded) {
00919 set_attr("is_fftpad", int(1));
00920 }
00921 else {
00922 set_attr("is_fftpad", int(0));
00923 }
00924 }
00925
00926
00930 inline bool is_fftodd() const
00931 {
00932 if(flags & EMDATA_FFTODD) {
00933 return true;
00934 }
00935 else if( attr_dict.has_key("is_fftodd") && (int)attr_dict["is_fftodd"] == 1 ) {
00936 return true;
00937 }
00938 else {
00939 return false;
00940 }
00941 }
00942
00943
00948 inline void set_fftodd(bool is_fftodd)
00949 {
00950 if (is_fftodd) {
00951 set_attr("is_fftodd", int(1));
00952 }
00953 else {
00954 set_attr("is_fftodd", int(0));
00955 }
00956 }
00957
00958
00962 inline void set_nxc(int nxc)
00963 {
00964 attr_dict["nxc"] = nxc;
00965 }
00966
00967
00968
00969
00970
00971 inline int get_flags() const
00972 {
00973 return flags;
00974 }
00975
00976 inline void set_flags(int f)
00977 {
00978 flags = f;
00979 }
00980
00981 inline int get_changecount() const
00982 {
00983 return changecount;
00984 }
00985
00986 inline void set_changecount(int c)
00987 {
00988 changecount = c;
00989 }
00990
00991 inline int get_xoff() const
00992 {
00993 return xoff;
00994 }
00995
00996 inline int get_yoff() const
00997 {
00998 return yoff;
00999 }
01000
01001 inline int get_zoff() const
01002 {
01003 return zoff;
01004 }
01005
01006 inline void set_xyzoff(int x, int y, int z)
01007 {
01008 xoff = x;
01009 yoff = y;
01010 zoff = z;
01011 }
01012
01018 void scale_pixel(float scale_factor) const;
01019
01020 inline string get_path() const
01021 {
01022 return path;
01023 }
01024
01025 inline int get_pathnum() const
01026 {
01027 return pathnum;
01028 }
01029
01030
01031 std::string get_data_pickle() const;
01032
01033
01034 void set_data_pickle(std::string vf);
01035
01036
01037 int get_supp_pickle() const;
01038
01039 void set_supp_pickle(int i);
01040
01041 vector<Vec3i> mask_contig_region(const float& val, const Vec3i& seed);
01042
01048 float get_amplitude_thres(float thres);
01049
01050 private:
01056 void set_attr_dict_explicit(const Dict & new_dict);
01057
01058
01059
01060 #endif //emdata__metadata_h__