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 float *get_data() const;
00073 inline const float * const get_const_data() const { return get_data(); }
00074 
00082 inline void set_data(float* data, const int x, const int y, const int z) {
00083         if (rdata) { EMUtil::em_free(rdata); rdata = 0; }
00084 #ifdef EMAN2_USING_CUDA
00085         free_cuda_memory();
00086 #endif
00087         rdata = data;
00088         nx = x; ny = y; nz = z;
00089         nxy = nx*ny;
00090         update();
00091 }
00092 
00093 
00104 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);
00105 
00117 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);
00118 
00119 
00120 
00122 inline void update()
00123 {
00124         flags |= EMDATA_NEEDUPD | EMDATA_GPU_NEEDS_UPDATE | EMDATA_GPU_RO_NEEDS_UPDATE;
00125         changecount++;
00126 }
00127 
00128 
00132 inline bool has_ctff() const
00133 {
00134         if (this->has_attr("ctf")) {
00135                 return true;
00136         }
00137         else {
00138                 return false;
00139         }
00140 }
00141 
00142 
00147 float calc_center_density();
00148 
00149 
00154 float calc_sigma_diff();
00155 
00156 
00160 IntPoint calc_min_location() const;
00161 
00162 
00166 IntPoint calc_max_location() const;
00167 
00175 IntPoint calc_max_location_wrap(const int maxshiftx=-1, const int maxshifty=-1, const int maxshiftz=-1);
00176 
00181 FloatPoint calc_center_of_mass();
00182 
00187 int calc_min_index() const;
00188 
00189 
00194 int calc_max_index() const;
00195 
00196 
00206 vector<Pixel> calc_highest_locations(float threshold);
00207 
00208 
00214 float get_edge_mean() const;
00215 
00216 
00221 float get_circle_mean();
00222 
00223 
00227 Ctf * get_ctf() const;
00228 
00229 
00233 void set_ctf(Ctf * ctf);
00234 
00235 
00241 inline Vec3f get_translation() const
00242 {
00243         return all_translation;
00244 }
00245 
00246 
00251 inline void set_translation(const Vec3f &t)
00252 {
00253         all_translation = t;
00254 }
00255 
00256 
00263 inline void set_translation(float dx, float dy, float dz)
00264 {
00265         all_translation = Vec3f(dx, dy, dz);
00266 }
00267 
00268 
00272 inline Transform3D get_transform() const
00273 {
00274         return Transform3D( (float)attr_dict["euler_alt"],
00275                             (float)attr_dict["euler_az"],
00276                             (float)attr_dict["euler_phi"]);
00277 }
00278 
00279 
00287 inline void set_rotation(float az, float alt, float phi)
00288 {
00289     attr_dict["orientation_convention"] = "EMAN";
00290         attr_dict["euler_alt"]=alt;
00291         attr_dict["euler_az"]=az;
00292         attr_dict["euler_phi"]=phi;
00293 }
00294 
00295 
00301 inline void set_rotation(const Transform3D& t3d)
00302 {
00303         Dict d = t3d.get_rotation(Transform3D::EMAN);
00304         attr_dict["orientation_convention"] = "EMAN";
00305         attr_dict["euler_alt"] = (float) d["alt"];
00306         attr_dict["euler_az"] = (float) d["az"];
00307         attr_dict["euler_phi"] = (float) d["phi"];;
00308 }
00309 
00310 
00318 void set_size(int nx, int ny=1, int nz=1);
00319 
00320 #ifdef EMAN2_USING_CUDA
00321 
00328 void set_size_cuda(int nx, int ny=1, int nz=1);
00329 #endif //#EMAN2_USING_CUDA
00330 
00331 
00338 void set_complex_size(int nx, int ny=1, int nz=1) {
00339         set_size(nx*2, ny, nz);
00340 }
00341 
00342 
00346 inline void set_path(const string & new_path)
00347 {
00348         path = new_path;
00349 }
00350 
00351 
00355 inline void set_pathnum(int n)
00356 {
00357         pathnum = n;
00358 }
00359 
00360 
00369 MArray2D get_2dview() const;
00370 
00371 
00380 MArray3D get_3dview() const;
00381 
00382 
00390 MCArray2D get_2dcview() const;
00391 
00392 
00400 MCArray3D get_3dcview() const;
00401 
00402 
00410 MCArray3D* get_3dcviewptr() const;
00411 
00412 
00425 MArray2D get_2dview(int x0, int y0) const;
00426 
00427 
00441 MArray3D get_3dview(int x0, int y0, int z0) const;
00442 
00443 
00456 MCArray2D get_2dcview(int x0, int y0) const;
00457 
00458 
00472 MCArray3D get_3dcview(int x0, int y0, int z0) const;
00473 
00474 
00483 EMObject get_attr(const string & attr_name) const;
00484 
00494 EMObject get_attr_default(const string & attr_name, const EMObject & em_obj = EMObject()) const;
00495 
00501 void set_attr(const string & key, EMObject val);
00502 
00503 
00509 void set_attr_python(const string & key, EMObject val);
00510 
00515 inline bool has_attr(const string& key) const {
00516         return attr_dict.has_key(key);
00517 }
00518 
00525 Dict get_attr_dict() const;
00526 
00527 
00532 void set_attr_dict(const Dict & new_dict);
00533 
00534 
00535 
00540  void del_attr(const string & attr_name);
00541 
00542 
00547  void del_attr_dict(const vector<string> & del_keys);
00548 
00549 
00553 inline int get_xsize() const
00554 {
00555         return nx;
00556 }
00557 
00558 
00562 inline int get_ysize() const
00563 {
00564         return ny;
00565 }
00566 
00567 
00571 inline int get_zsize() const
00572 {
00573         return nz;
00574 }
00575 
00576 
00580 inline size_t get_size() const
00581 {
00582         return (size_t)nx*(size_t)ny*(size_t)nz;
00583 }
00584 
00588 inline vector<float> get_data_as_vector() const {
00589         int size = get_size();
00590         vector<float> v(size);
00591         float* data = get_data();
00592         std::copy(data,data+size,v.begin());
00593         return v;
00594 }
00595 
00599 inline int get_ndim() const
00600 {
00601         if (nz <= 1) {
00602                 if (ny <= 1) {
00603                         return 1;
00604                 }
00605                 else {
00606                         return 2;
00607                 }
00608         }
00609 
00610         return 3;
00611 }
00612 
00613 
00617 inline bool is_shuffled() const
00618 {  //     PRB
00619         if (flags & EMDATA_SHUFFLE) {
00620                 return true;
00621         }
00622 
00623         if(has_attr("is_shuffled")) {
00624                 return get_attr("is_shuffled");
00625         }
00626 
00627         return false;
00628 }
00629 
00630 
00634 inline bool is_FH() const
00635 {  //     PRB
00636         if (flags & EMDATA_FH) {
00637                 return true;
00638         }
00639 
00640         if(has_attr("is_fh")) {
00641                 return get_attr("is_fh");
00642         }
00643 
00644         return false;
00645 }
00646 
00647 
00651 inline bool is_complex() const
00652 {
00653         if(attr_dict.has_key("is_complex")) {
00654                 if (int(attr_dict["is_complex"])) {
00655                         return true;
00656                 }
00657                 else {
00658                         return false;
00659                 }
00660         }
00661         else {
00662                 return false;
00663         }
00664 }
00665 
00666 
00670 inline bool is_real() const
00671 {
00672         return !is_complex();
00673 }
00674 
00675 
00680 inline void set_shuffled(bool is_shuffled)
00681 { // PRB
00682         if (is_shuffled) {
00683 //              printf("entered correct part of set_shuffled \n");
00684 //              flags |=  EMDATA_SHUFFLE;
00685                 set_attr("is_shuffled", (int)1);
00686         }
00687         else {
00688 //              flags &= ~EMDATA_SHUFFLE;
00689                 set_attr("is_shuffled", (int)0);
00690         }
00691 }
00692 
00693 
00698 inline void set_FH(bool is_FH)
00699 { // PRB
00700         if (is_FH) {
00701 //              flags |=  EMDATA_FH;
00702                 set_attr("is_fh", (int)1);
00703         }
00704         else {
00705 //              flags &= ~EMDATA_FH;
00706                 set_attr("is_fh", (int)0);
00707         }
00708 }
00709 
00710 
00715 inline void set_complex(bool is_complex)
00716 {
00717         if (is_complex) {
00718                 attr_dict["is_complex"] = int(1);
00719         }
00720         else {
00721                 attr_dict["is_complex"] = int(0);
00722         }
00723 }
00724 
00725 
00730 inline bool is_complex_x() const
00731 {
00732         if(attr_dict.has_key("is_complex_x")) {
00733                 if (int(attr_dict["is_complex_x"])) {
00734                         return true;
00735                 }
00736                 else {
00737                         return false;
00738                 }
00739         }
00740         else {
00741                 return false;
00742         }
00743 }
00744 
00745 ;
00750 inline void set_complex_x(bool is_complex_x)
00751 {
00752         if (is_complex_x) {
00753                 attr_dict["is_complex_x"] = int(1);
00754         }
00755         else {
00756                 attr_dict["is_complex_x"] = int(0);
00757         }
00758 }
00759 
00760 
00764 inline bool is_flipped() const
00765 {
00766         if (flags & EMDATA_FLIP) { //keep here for back compatibility
00767                 return true;
00768         }
00769 
00770         if(attr_dict.has_key("is_flipped")) {
00771                 if(get_attr("is_flipped")) {
00772                         return true;
00773                 }
00774         }
00775 
00776         return false;
00777 
00778 }
00779 
00780 
00785 inline void set_flipped(bool is_flipped)
00786 {
00787         if (is_flipped) {
00788                 set_attr("is_flipped", (int)1);
00789         }
00790         else {
00791                 set_attr("is_flipped", (int)0);
00792         }
00793 }
00794 
00795 
00800 inline bool is_ri() const
00801 {
00802         if(attr_dict.has_key("is_complex_ri")) {
00803                 if (int(attr_dict["is_complex_ri"])) {
00804                         return true;
00805                 }
00806                 else {
00807                         return false;
00808                 }
00809         }
00810         else {
00811                 return false;
00812         }
00813 }
00814 
00815 
00820 inline void set_ri(bool is_ri)
00821 {
00822         if (is_ri) {
00823                 attr_dict["is_complex_ri"] = int(1);
00824         }
00825         else {
00826                 attr_dict["is_complex_ri"] = int(0);
00827         }
00828 }
00829 
00830 
00834 inline bool is_fftpadded() const
00835 {
00836         if (flags & EMDATA_PAD) {
00837                 return true;
00838         }
00839 
00840         if(has_attr("is_fftpad")) {
00841                 return get_attr("is_fftpad");
00842         }
00843 
00844         return false;
00845 
00846 }
00847 
00848 
00853 inline void set_fftpad(bool is_fftpadded)
00854 {
00855         if (is_fftpadded) {
00856                 set_attr("is_fftpad", int(1));
00857         }
00858         else {
00859                 set_attr("is_fftpad", int(0));
00860         }
00861 }
00862 
00863 
00867 inline bool is_fftodd() const
00868 {
00869         if(flags & EMDATA_FFTODD) {
00870                 return true;
00871         }
00872         else if( attr_dict.has_key("is_fftodd") && (int)attr_dict["is_fftodd"] == 1 ) {
00873                 return true;
00874         }
00875         else {
00876                 return false;
00877         }
00878 }
00879 
00880 
00885 inline void set_fftodd(bool is_fftodd)
00886 {
00887         if (is_fftodd) {
00888                 set_attr("is_fftodd", int(1));
00889         }
00890         else {
00891                 set_attr("is_fftodd", int(0));
00892         }
00893 }
00894 
00895 
00899 inline void set_nxc(int nxc)
00900 {
00901         attr_dict["nxc"] = nxc;
00902 }
00903 
00904 /******************************************************************************
00905  ** These functions are used for EMData's pickling, do not use it for         *
00906  *  other purpose, e.g. get flags of a EMData object                          *
00907  * ***************************************************************************/
00908 inline int get_flags() const
00909 {
00910         return flags;
00911 }
00912 
00913 inline void set_flags(int f)
00914 {
00915         flags = f;
00916 }
00917 
00918 inline int get_changecount() const
00919 {
00920         return changecount;
00921 }
00922 
00923 inline void set_changecount(int c)
00924 {
00925         changecount = c;
00926 }
00927 
00928 inline int get_xoff() const
00929 {
00930         return xoff;
00931 }
00932 
00933 inline int get_yoff() const
00934 {
00935         return yoff;
00936 }
00937 
00938 inline int get_zoff() const
00939 {
00940         return zoff;
00941 }
00942 
00943 inline void set_xyzoff(int x, int y, int z)
00944 {
00945         xoff = x;
00946         yoff = y;
00947         zoff = z;
00948 }
00949 
00955 void scale_pixel(float scale_factor) const;
00956 
00957 inline string get_path() const
00958 {
00959         return path;
00960 }
00961 
00962 inline int get_pathnum() const
00963 {
00964         return pathnum;
00965 }
00966 
00967 //vector<float> get_data_pickle() const;
00968 std::string get_data_pickle() const;
00969 
00970 //void set_data_pickle(const vector<float>& vf);
00971 void set_data_pickle(std::string vf);
00972 
00973 //we don't actually pickle supp, just a place holder to set supp to NULL
00974 int get_supp_pickle() const;
00975 
00976 void set_supp_pickle(int i);
00977 
00978 vector<Vec3i> mask_contig_region(const float& val, const Vec3i& seed);
00979 
00980 
00981 private:
00987 void set_attr_dict_explicit(const Dict & new_dict);
00988 
00989 /*****************************************************************************/
00990 
00991 #endif  //emdata__metadata_h__

Generated on Sat Nov 7 02:18:55 2009 for EMAN2 by  doxygen 1.5.6