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 
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 //#ifdef EMAN2_USING_CUDA
00097 //      free_cuda_memory();
00098 //#endif
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 
00203 vector<float> calc_max_location_wrap_intp(const int maxshiftx=-1, const int maxshifty=-1, const int maxshiftz=-1);
00204 
00209 FloatPoint calc_center_of_mass(const float threshold=0);
00210 
00215 size_t calc_min_index() const;
00216 
00217 
00222 size_t calc_max_index() const;
00223 
00224 
00234 vector<Pixel> calc_highest_locations(float threshold)  const;
00235 
00241 vector<Pixel> calc_n_highest_locations(int n);
00242 
00247 vector<Pixel> find_pixels_with_value(float val);
00248 
00254 float get_edge_mean() const;
00255 
00256 
00261 float get_circle_mean();
00262 
00263 
00267 Ctf * get_ctf() const;
00268 
00269 
00273 void set_ctf(Ctf * ctf);
00274 
00275 
00281 inline Vec3f get_translation() const
00282 {
00283         return all_translation;
00284 }
00285 
00286 
00291 inline void set_translation(const Vec3f &t)
00292 {
00293         all_translation = t;
00294 }
00295 
00296 
00303 inline void set_translation(float dx, float dy, float dz)
00304 {
00305         all_translation = Vec3f(dx, dy, dz);
00306 }
00307 
00308 
00312 inline Transform get_transform() const
00313 {
00314         Dict rotation_dict;
00315         rotation_dict["type"] = "eman";
00316         rotation_dict["alt"] = attr_dict["euler_alt"];
00317         rotation_dict["az"] = attr_dict["euler_az"];
00318         rotation_dict["phi"] = attr_dict["euler_phi"];
00319 
00320         Transform trans;
00321         trans.to_identity();
00322         trans.set_rotation(rotation_dict);
00323 
00324         return trans;
00325 }
00326 
00334 inline void set_rotation(float az, float alt, float phi)
00335 {
00336     attr_dict["orientation_convention"] = "EMAN";
00337         attr_dict["euler_alt"]=alt;
00338         attr_dict["euler_az"]=az;
00339         attr_dict["euler_phi"]=phi;
00340 }
00341 
00342 
00348 inline void set_rotation(const Transform& t3d)
00349 {
00350         Dict d = t3d.get_rotation("eman");
00351         attr_dict["orientation_convention"] = "EMAN";
00352         attr_dict["euler_alt"] = (float) d["alt"];
00353         attr_dict["euler_az"] = (float) d["az"];
00354         attr_dict["euler_phi"] = (float) d["phi"];;
00355 }
00356 
00357 
00365 void set_size(int nx, int ny=1, int nz=1);
00366 
00367 #ifdef EMAN2_USING_CUDA
00368 
00375 void set_size_cuda(int nx, int ny=1, int nz=1);
00376 #endif //#EMAN2_USING_CUDA
00377 
00378 
00385 void set_complex_size(int nx, int ny=1, int nz=1) {
00386         set_size(nx*2, ny, nz);
00387 }
00388 
00389 
00393 inline void set_path(const string & new_path)
00394 {
00395         path = new_path;
00396 }
00397 
00398 
00402 inline void set_pathnum(int n)
00403 {
00404         pathnum = n;
00405 }
00406 
00407 
00416 MArray2D get_2dview() const;
00417 
00418 
00427 MArray3D get_3dview() const;
00428 
00429 
00437 MCArray2D get_2dcview() const;
00438 
00439 
00447 MCArray3D get_3dcview() const;
00448 
00449 
00457 MCArray3D* get_3dcviewptr() const;
00458 
00459 
00472 MArray2D get_2dview(int x0, int y0) const;
00473 
00474 
00488 MArray3D get_3dview(int x0, int y0, int z0) const;
00489 
00490 
00503 MCArray2D get_2dcview(int x0, int y0) const;
00504 
00505 
00519 MCArray3D get_3dcview(int x0, int y0, int z0) const;
00520 
00521 
00530 EMObject get_attr(const string & attr_name) const;
00531 
00541 EMObject get_attr_default(const string & attr_name, const EMObject & em_obj = EMObject()) const;
00542 
00548 void set_attr(const string & key, EMObject val);
00549 
00550 
00556 void set_attr_python(const string & key, EMObject val);
00557 
00562 inline bool has_attr(const string& key) const {
00563         return attr_dict.has_key(key);
00564 }
00565 
00572 Dict get_attr_dict() const;
00573 
00574 #ifdef EMAN2_USING_CUDA
00575 
00580 inline Dict get_attr_dict_cuda() const {return attr_dict;}
00581 #endif
00582 
00587 void set_attr_dict(const Dict & new_dict);
00588 
00589 
00590 
00595  void del_attr(const string & attr_name);
00596 
00597 
00602  void del_attr_dict(const vector<string> & del_keys);
00603 
00604 
00608 inline int get_xsize() const
00609 {
00610         return nx;
00611 }
00612 
00613 
00617 inline int get_ysize() const
00618 {
00619         return ny;
00620 }
00621 
00622 
00626 inline int get_zsize() const
00627 {
00628         return nz;
00629 }
00630 
00631 
00635 inline size_t get_size() const
00636 {
00637         return (size_t)nx*(size_t)ny*(size_t)nz;
00638 }
00639 
00643 inline vector<float> get_data_as_vector() const {
00644         int size = get_size();
00645         vector<float> v(size);
00646         float* data = get_data();
00647         std::copy(data,data+size,v.begin());
00648         return v;
00649 }
00650 
00654 inline int get_ndim() const
00655 {
00656         if (nz <= 1) {
00657                 if (ny <= 1) {
00658                         return 1;
00659                 }
00660                 else {
00661                         return 2;
00662                 }
00663         }
00664 
00665         return 3;
00666 }
00667 
00668 
00672 inline bool is_shuffled() const
00673 {  //     PRB
00674         if (flags & EMDATA_SHUFFLE) {
00675                 return true;
00676         }
00677 
00678         if(has_attr("is_shuffled")) {
00679                 return get_attr("is_shuffled");
00680         }
00681 
00682         return false;
00683 }
00684 
00685 
00689 inline bool is_FH() const
00690 {  //     PRB
00691         if (flags & EMDATA_FH) {
00692                 return true;
00693         }
00694 
00695         if(has_attr("is_fh")) {
00696                 return get_attr("is_fh");
00697         }
00698 
00699         return false;
00700 }
00701 
00702 
00706 inline bool is_complex() const
00707 {
00708         if(attr_dict.has_key("is_complex")) {
00709                 if (int(attr_dict["is_complex"])) {
00710                         return true;
00711                 }
00712                 else {
00713                         return false;
00714                 }
00715         }
00716         else {
00717                 return false;
00718         }
00719 }
00720 
00721 
00725 inline bool is_real() const
00726 {
00727         return !is_complex();
00728 }
00729 
00730 
00735 inline void set_shuffled(bool is_shuffled)
00736 { // PRB
00737         if (is_shuffled) {
00738 //              printf("entered correct part of set_shuffled \n");
00739 //              flags |=  EMDATA_SHUFFLE;
00740                 set_attr("is_shuffled", (int)1);
00741         }
00742         else {
00743 //              flags &= ~EMDATA_SHUFFLE;
00744                 set_attr("is_shuffled", (int)0);
00745         }
00746 }
00747 
00748 
00753 inline void set_FH(bool is_FH)
00754 { // PRB
00755         if (is_FH) {
00756 //              flags |=  EMDATA_FH;
00757                 set_attr("is_fh", (int)1);
00758         }
00759         else {
00760 //              flags &= ~EMDATA_FH;
00761                 set_attr("is_fh", (int)0);
00762         }
00763 }
00764 
00765 
00770 inline void set_complex(bool is_complex)
00771 {
00772         if (is_complex) {
00773                 attr_dict["is_complex"] = int(1);
00774         }
00775         else {
00776                 attr_dict["is_complex"] = int(0);
00777         }
00778 }
00779 
00780 
00785 inline bool is_complex_x() const
00786 {
00787         if(attr_dict.has_key("is_complex_x")) {
00788                 if (int(attr_dict["is_complex_x"])) {
00789                         return true;
00790                 }
00791                 else {
00792                         return false;
00793                 }
00794         }
00795         else {
00796                 return false;
00797         }
00798 }
00799 
00800 ;
00805 inline void set_complex_x(bool is_complex_x)
00806 {
00807         if (is_complex_x) {
00808                 attr_dict["is_complex_x"] = int(1);
00809         }
00810         else {
00811                 attr_dict["is_complex_x"] = int(0);
00812         }
00813 }
00814 
00815 
00819 inline bool is_flipped() const
00820 {
00821         if (flags & EMDATA_FLIP) { //keep here for back compatibility
00822                 return true;
00823         }
00824 
00825         if(attr_dict.has_key("is_flipped")) {
00826                 if(get_attr("is_flipped")) {
00827                         return true;
00828                 }
00829         }
00830 
00831         return false;
00832 
00833 }
00834 
00835 
00840 inline void set_flipped(bool is_flipped)
00841 {
00842         if (is_flipped) {
00843                 set_attr("is_flipped", (int)1);
00844         }
00845         else {
00846                 set_attr("is_flipped", (int)0);
00847         }
00848 }
00849 
00850 
00855 inline bool is_ri() const
00856 {
00857         if(attr_dict.has_key("is_complex_ri")) {
00858                 if (int(attr_dict["is_complex_ri"])) {
00859                         return true;
00860                 }
00861                 else {
00862                         return false;
00863                 }
00864         }
00865         else {
00866                 return false;
00867         }
00868 }
00869 
00870 
00875 inline void set_ri(bool is_ri)
00876 {
00877         if (is_ri) {
00878                 attr_dict["is_complex_ri"] = int(1);
00879         }
00880         else {
00881                 attr_dict["is_complex_ri"] = int(0);
00882         }
00883 }
00884 
00885 
00889 inline bool is_fftpadded() const
00890 {
00891         if (flags & EMDATA_PAD) {
00892                 return true;
00893         }
00894 
00895         if(has_attr("is_fftpad")) {
00896                 return get_attr("is_fftpad");
00897         }
00898 
00899         return false;
00900 
00901 }
00902 
00903 
00908 inline void set_fftpad(bool is_fftpadded)
00909 {
00910         if (is_fftpadded) {
00911                 set_attr("is_fftpad", int(1));
00912         }
00913         else {
00914                 set_attr("is_fftpad", int(0));
00915         }
00916 }
00917 
00918 
00922 inline bool is_fftodd() const
00923 {
00924         if(flags & EMDATA_FFTODD) {
00925                 return true;
00926         }
00927         else if( attr_dict.has_key("is_fftodd") && (int)attr_dict["is_fftodd"] == 1 ) {
00928                 return true;
00929         }
00930         else {
00931                 return false;
00932         }
00933 }
00934 
00935 
00940 inline void set_fftodd(bool is_fftodd)
00941 {
00942         if (is_fftodd) {
00943                 set_attr("is_fftodd", int(1));
00944         }
00945         else {
00946                 set_attr("is_fftodd", int(0));
00947         }
00948 }
00949 
00950 
00954 inline void set_nxc(int nxc)
00955 {
00956         attr_dict["nxc"] = nxc;
00957 }
00958 
00959 /******************************************************************************
00960  ** These functions are used for EMData's pickling, do not use it for         *
00961  *  other purpose, e.g. get flags of a EMData object                          *
00962  * ***************************************************************************/
00963 inline int get_flags() const
00964 {
00965         return flags;
00966 }
00967 
00968 inline void set_flags(int f)
00969 {
00970         flags = f;
00971 }
00972 
00973 inline int get_changecount() const
00974 {
00975         return changecount;
00976 }
00977 
00978 inline void set_changecount(int c)
00979 {
00980         changecount = c;
00981 }
00982 
00983 inline int get_xoff() const
00984 {
00985         return xoff;
00986 }
00987 
00988 inline int get_yoff() const
00989 {
00990         return yoff;
00991 }
00992 
00993 inline int get_zoff() const
00994 {
00995         return zoff;
00996 }
00997 
00998 inline void set_xyzoff(int x, int y, int z)
00999 {
01000         xoff = x;
01001         yoff = y;
01002         zoff = z;
01003 }
01004 
01010 void scale_pixel(float scale_factor) const;
01011 
01012 inline string get_path() const
01013 {
01014         return path;
01015 }
01016 
01017 inline int get_pathnum() const
01018 {
01019         return pathnum;
01020 }
01021 
01022 //vector<float> get_data_pickle() const;
01023 std::string get_data_pickle() const;
01024 
01025 //void set_data_pickle(const vector<float>& vf);
01026 void set_data_pickle(std::string vf);
01027 
01028 //we don't actually pickle supp, just a place holder to set supp to NULL
01029 int get_supp_pickle() const;
01030 
01031 void set_supp_pickle(int i);
01032 
01033 vector<Vec3i> mask_contig_region(const float& val, const Vec3i& seed);
01034 
01040 float get_amplitude_thres(float thres);
01041 
01042 private:
01048 void set_attr_dict_explicit(const Dict & new_dict);
01049 
01050 /*****************************************************************************/
01051 
01052 #endif  //emdata__metadata_h__

Generated on Thu Mar 10 22:56:40 2011 for EMAN2 by  doxygen 1.4.7