EMAN2
emdata_metadata.h
Go to the documentation of this file.
00001 
00005 /*
00006  * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
00007  * Copyright (c) 2000-2006 Baylor College of Medicine
00008  *
00009  * This software is issued under a joint BSD/GNU license. You may use the
00010  * source code in this file under either license. However, note that the
00011  * complete EMAN2 and SPARX software packages have some GPL dependencies,
00012  * so you are responsible for compliance with the licenses of these packages
00013  * if you opt to use BSD licensing. The warranty disclaimer below holds
00014  * in either instance.
00015  *
00016  * This complete copyright notice must be included in any revised version of the
00017  * source code. Additional authorship citations may be added, but existing
00018  * author citations must be preserved.
00019  *
00020  * This program is free software; you can redistribute it and/or modify
00021  * it under the terms of the GNU General Public License as published by
00022  * the Free Software Foundation; either version 2 of the License, or
00023  * (at your option) any later version.
00024  *
00025  * This program is distributed in the hope that it will be useful,
00026  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00028  * GNU General Public License for more details.
00029  *
00030  * You should have received a copy of the GNU General Public License
00031  * along with this program; if not, write to the Free Software
00032  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 
00068 #ifdef EMAN2_USING_CUDA
00069 inline float *get_data() const
00070 {
00071         if(rdata == 0){
00072                 rdata = (float*)malloc(num_bytes);
00073                 cudadirtybit = 1;
00074         }
00075         if(cudadirtybit == 1){
00076                 cudadirtybit = 0;
00077                 cudaMemcpy(rdata,cudarwdata,num_bytes,cudaMemcpyDeviceToHost);
00078         }
00079         return rdata;
00080 }
00081 #else
00082 inline float *get_data() const { return rdata; }
00083 #endif
00084 
00088 inline const float * get_const_data() const { return get_data(); }
00089 
00097 inline void set_data(float* data, const int x, const int y, const int z) {
00098         if (rdata) { EMUtil::em_free(rdata); rdata = 0; }
00099 #ifdef EMAN2_USING_CUDA
00100         //cout << "set data" << endl;
00101 //      free_cuda_memory();
00102 #endif
00103         rdata = data;
00104         nx = x; ny = y; nz = z;
00105         nxy = nx*ny;
00106         nxyz = (size_t)nx*ny*nz;
00107         update();
00108 }
00109 
00110 inline void set_data(float* data) {
00111         rdata = data;
00112 }
00113 
00124 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);
00125 
00137 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);
00138 
00139 
00140 
00142 inline void update()
00143 {
00144         flags |= EMDATA_NEEDUPD;
00145         changecount++;
00146 #ifdef FFT_CACHING
00147         if (fftcache!=0) { delete fftcache; fftcache=0; }
00148 #endif //FFT_CACHING
00149 
00150 }
00151 
00153 inline void clearupdate()
00154 {
00155         flags &= ~EMDATA_NEEDUPD;
00156         changecount--;
00157 }
00158 
00162 inline bool has_ctff() const
00163 {
00164         if (this->has_attr("ctf")) {
00165                 return true;
00166         }
00167         else {
00168                 return false;
00169         }
00170 }
00171 
00172 
00177 float calc_center_density();
00178 
00179 
00184 float calc_sigma_diff();
00185 
00186 
00190 IntPoint calc_min_location() const;
00191 
00192 
00196 IntPoint calc_max_location() const;
00197 
00205 IntPoint calc_max_location_wrap(const int maxshiftx=-1, const int maxshifty=-1, const int maxshiftz=-1);
00206 
00214 vector<float> calc_max_location_wrap_intp(const int maxshiftx=-1, const int maxshifty=-1, const int maxshiftz=-1);
00215 
00220 FloatPoint calc_center_of_mass(const float threshold=0);
00221 
00226 size_t calc_min_index() const;
00227 
00228 
00233 size_t calc_max_index() const;
00234 
00235 
00245 vector<Pixel> calc_highest_locations(float threshold)  const;
00246 
00252 vector<Pixel> calc_n_highest_locations(int n);
00253 
00258 vector<Pixel> find_pixels_with_value(float val);
00259 
00265 float get_edge_mean() const;
00266 
00267 
00272 float get_circle_mean();
00273 
00274 
00278 Ctf * get_ctf() const;
00279 
00280 
00284 void set_ctf(Ctf * ctf);
00285 
00286 
00292 inline Vec3f get_translation() const
00293 {
00294         return all_translation;
00295 }
00296 
00297 
00302 inline void set_translation(const Vec3f &t)
00303 {
00304         all_translation = t;
00305 }
00306 
00307 
00314 inline void set_translation(float dx, float dy, float dz)
00315 {
00316         all_translation = Vec3f(dx, dy, dz);
00317 }
00318 
00319 
00323 inline Transform get_transform() const
00324 {
00325         Dict rotation_dict;
00326         rotation_dict["type"] = "eman";
00327         rotation_dict["alt"] = attr_dict["euler_alt"];
00328         rotation_dict["az"] = attr_dict["euler_az"];
00329         rotation_dict["phi"] = attr_dict["euler_phi"];
00330 
00331         Transform trans;
00332         trans.to_identity();
00333         trans.set_rotation(rotation_dict);
00334 
00335         return trans;
00336 }
00337 
00345 inline void set_rotation(float az, float alt, float phi)
00346 {
00347     attr_dict["orientation_convention"] = "EMAN";
00348         attr_dict["euler_alt"]=alt;
00349         attr_dict["euler_az"]=az;
00350         attr_dict["euler_phi"]=phi;
00351 }
00352 
00353 
00359 inline void set_rotation(const Transform& t3d)
00360 {
00361         Dict d = t3d.get_rotation("eman");
00362         attr_dict["orientation_convention"] = "EMAN";
00363         attr_dict["euler_alt"] = (float) d["alt"];
00364         attr_dict["euler_az"] = (float) d["az"];
00365         attr_dict["euler_phi"] = (float) d["phi"];;
00366 }
00367 
00368 
00376 void set_size(int nx, int ny=1, int nz=1, bool noalloc=false);
00377 
00378 #ifdef EMAN2_USING_CUDA
00379 
00386 void set_size_cuda(int nx, int ny=1, int nz=1);
00387 #endif //#EMAN2_USING_CUDA
00388 
00389 
00396 void set_complex_size(int nx, int ny=1, int nz=1) {
00397         set_size(nx*2, ny, nz);
00398 }
00399 
00400 
00404 inline void set_path(const string & new_path)
00405 {
00406         path = new_path;
00407 }
00408 
00409 
00413 inline void set_pathnum(int n)
00414 {
00415         pathnum = n;
00416 }
00417 
00418 
00427 MArray2D get_2dview() const;
00428 
00429 
00438 MArray3D get_3dview() const;
00439 
00440 
00448 MCArray2D get_2dcview() const;
00449 
00450 
00458 MCArray3D get_3dcview() const;
00459 
00460 
00468 MCArray3D* get_3dcviewptr() const;
00469 
00470 
00483 MArray2D get_2dview(int x0, int y0) const;
00484 
00485 
00499 MArray3D get_3dview(int x0, int y0, int z0) const;
00500 
00501 
00514 MCArray2D get_2dcview(int x0, int y0) const;
00515 
00516 
00530 MCArray3D get_3dcview(int x0, int y0, int z0) const;
00531 
00532 
00541 EMObject get_attr(const string & attr_name) const;
00542 
00552 EMObject get_attr_default(const string & attr_name, const EMObject & em_obj = EMObject()) const;
00553 
00559 void set_attr(const string & key, EMObject val);
00560 
00561 
00567 void set_attr_python(const string & key, EMObject val);
00568 
00573 inline bool has_attr(const string& key) const {
00574         return attr_dict.has_key(key);
00575 }
00576 
00583 Dict get_attr_dict() const;
00584 
00585 #ifdef EMAN2_USING_CUDA
00586 
00591 inline Dict get_attr_dict_cuda() const {return attr_dict;}
00592 #endif
00593 
00598 void set_attr_dict(const Dict & new_dict);
00599 
00600 
00601 
00606  void del_attr(const string & attr_name);
00607 
00608 
00613  void del_attr_dict(const vector<string> & del_keys);
00614 
00615 
00619 inline int get_xsize() const
00620 {
00621         return nx;
00622 }
00623 
00624 
00628 inline int get_ysize() const
00629 {
00630         return ny;
00631 }
00632 
00633 
00637 inline int get_zsize() const
00638 {
00639         return nz;
00640 }
00641 
00642 
00646 inline size_t get_size() const
00647 {
00648         return (size_t)nx*(size_t)ny*(size_t)nz;
00649 }
00650 
00654 inline vector<float> get_data_as_vector() const {
00655         int size = get_size();
00656         vector<float> v(size);
00657         float* data = get_data();
00658         std::copy(data,data+size,v.begin());
00659         return v;
00660 }
00661 
00665 inline int get_ndim() const
00666 {
00667         if (nz <= 1) {
00668                 if (ny <= 1) {
00669                         return 1;
00670                 }
00671                 else {
00672                         return 2;
00673                 }
00674         }
00675 
00676         return 3;
00677 }
00678 
00679 
00683 inline bool is_shuffled() const
00684 {  //     PRB
00685         if (flags & EMDATA_SHUFFLE) {
00686                 return true;
00687         }
00688 
00689         if(has_attr("is_shuffled")) {
00690                 return get_attr("is_shuffled");
00691         }
00692 
00693         return false;
00694 }
00695 
00696 
00700 inline bool is_FH() const
00701 {  //     PRB
00702         if (flags & EMDATA_FH) {
00703                 return true;
00704         }
00705 
00706         if(has_attr("is_fh")) {
00707                 return get_attr("is_fh");
00708         }
00709 
00710         return false;
00711 }
00712 
00713 
00717 inline bool is_complex() const
00718 {
00719         if(attr_dict.has_key("is_complex")) {
00720                 if (int(attr_dict["is_complex"])) {
00721                         return true;
00722                 }
00723                 else {
00724                         return false;
00725                 }
00726         }
00727         else {
00728                 return false;
00729         }
00730 }
00731 
00732 
00736 inline bool is_real() const
00737 {
00738         return !is_complex();
00739 }
00740 
00741 
00746 inline void set_shuffled(bool is_shuffled)
00747 { // PRB
00748         if (is_shuffled) {
00749 //              printf("entered correct part of set_shuffled \n");
00750 //              flags |=  EMDATA_SHUFFLE;
00751                 set_attr("is_shuffled", (int)1);
00752         }
00753         else {
00754 //              flags &= ~EMDATA_SHUFFLE;
00755                 set_attr("is_shuffled", (int)0);
00756         }
00757 }
00758 
00759 
00764 inline void set_FH(bool is_FH)
00765 { // PRB
00766         if (is_FH) {
00767 //              flags |=  EMDATA_FH;
00768                 set_attr("is_fh", (int)1);
00769         }
00770         else {
00771 //              flags &= ~EMDATA_FH;
00772                 set_attr("is_fh", (int)0);
00773         }
00774 }
00775 
00776 
00781 inline void set_complex(bool is_complex)
00782 {
00783         if (is_complex) {
00784                 attr_dict["is_complex"] = int(1);
00785         }
00786         else {
00787                 attr_dict["is_complex"] = int(0);
00788         }
00789 }
00790 
00791 
00796 inline bool is_complex_x() const
00797 {
00798         if(attr_dict.has_key("is_complex_x")) {
00799                 if (int(attr_dict["is_complex_x"])) {
00800                         return true;
00801                 }
00802                 else {
00803                         return false;
00804                 }
00805         }
00806         else {
00807                 return false;
00808         }
00809 }
00810 
00811 ;
00816 inline void set_complex_x(bool is_complex_x)
00817 {
00818         if (is_complex_x) {
00819                 attr_dict["is_complex_x"] = int(1);
00820         }
00821         else {
00822                 attr_dict["is_complex_x"] = int(0);
00823         }
00824 }
00825 
00826 
00830 inline bool is_flipped() const
00831 {
00832         if (flags & EMDATA_FLIP) { //keep here for back compatibility
00833                 return true;
00834         }
00835 
00836         if(attr_dict.has_key("is_flipped")) {
00837                 if(get_attr("is_flipped")) {
00838                         return true;
00839                 }
00840         }
00841 
00842         return false;
00843 
00844 }
00845 
00846 
00851 inline void set_flipped(bool is_flipped)
00852 {
00853         if (is_flipped) {
00854                 set_attr("is_flipped", (int)1);
00855         }
00856         else {
00857                 set_attr("is_flipped", (int)0);
00858         }
00859 }
00860 
00861 
00866 inline bool is_ri() const
00867 {
00868         if(attr_dict.has_key("is_complex_ri")) {
00869                 if (int(attr_dict["is_complex_ri"])) {
00870                         return true;
00871                 }
00872                 else {
00873                         return false;
00874                 }
00875         }
00876         else {
00877                 return false;
00878         }
00879 }
00880 
00881 
00886 inline void set_ri(bool is_ri)
00887 {
00888         if (is_ri) {
00889                 attr_dict["is_complex_ri"] = int(1);
00890         }
00891         else {
00892                 attr_dict["is_complex_ri"] = int(0);
00893         }
00894 }
00895 
00896 
00900 inline bool is_fftpadded() const
00901 {
00902         if (flags & EMDATA_PAD) {
00903                 return true;
00904         }
00905 
00906         if(has_attr("is_fftpad")) {
00907                 return get_attr("is_fftpad");
00908         }
00909 
00910         return false;
00911 
00912 }
00913 
00914 
00919 inline void set_fftpad(bool is_fftpadded)
00920 {
00921         if (is_fftpadded) {
00922                 set_attr("is_fftpad", int(1));
00923         }
00924         else {
00925                 set_attr("is_fftpad", int(0));
00926         }
00927 }
00928 
00929 
00933 inline bool is_fftodd() const
00934 {
00935         if(flags & EMDATA_FFTODD) {
00936                 return true;
00937         }
00938         else if( attr_dict.has_key("is_fftodd") && (int)attr_dict["is_fftodd"] == 1 ) {
00939                 return true;
00940         }
00941         else {
00942                 return false;
00943         }
00944 }
00945 
00946 
00951 inline void set_fftodd(bool is_fftodd)
00952 {
00953         if (is_fftodd) {
00954                 set_attr("is_fftodd", int(1));
00955         }
00956         else {
00957                 set_attr("is_fftodd", int(0));
00958         }
00959 }
00960 
00961 
00965 inline void set_nxc(int nxc)
00966 {
00967         attr_dict["nxc"] = nxc;
00968 }
00969 
00970 /******************************************************************************
00971  ** These functions are used for EMData's pickling, do not use it for         *
00972  *  other purpose, e.g. get flags of a EMData object                          *
00973  * ***************************************************************************/
00974 inline int get_flags() const
00975 {
00976         return flags;
00977 }
00978 
00979 inline void set_flags(int f)
00980 {
00981         flags = f;
00982 }
00983 
00984 inline int get_changecount() const
00985 {
00986         return changecount;
00987 }
00988 
00989 inline void set_changecount(int c)
00990 {
00991         changecount = c;
00992 }
00993 
00994 inline int get_xoff() const
00995 {
00996         return xoff;
00997 }
00998 
00999 inline int get_yoff() const
01000 {
01001         return yoff;
01002 }
01003 
01004 inline int get_zoff() const
01005 {
01006         return zoff;
01007 }
01008 
01009 inline void set_xyzoff(int x, int y, int z)
01010 {
01011         xoff = x;
01012         yoff = y;
01013         zoff = z;
01014 }
01015 
01021 void scale_pixel(float scale_factor) const;
01022 
01023 inline string get_path() const
01024 {
01025         return path;
01026 }
01027 
01028 inline int get_pathnum() const
01029 {
01030         return pathnum;
01031 }
01032 
01033 //vector<float> get_data_pickle() const;
01034 std::string get_data_pickle() const;
01035 
01036 //void set_data_pickle(const vector<float>& vf);
01037 void set_data_pickle(std::string vf);
01038 
01039 //we don't actually pickle supp, just a place holder to set supp to NULL
01040 int get_supp_pickle() const;
01041 
01042 void set_supp_pickle(int i);
01043 
01044 vector<Vec3i> mask_contig_region(const float& val, const Vec3i& seed);
01045 
01051 float get_amplitude_thres(float thres);
01052 
01053 private:
01059 void set_attr_dict_explicit(const Dict & new_dict);
01060 
01061 /*****************************************************************************/
01062 
01063 #endif  //emdata__metadata_h__