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         //cout << "set data" << endl;
00098 //      free_cuda_memory();
00099 #endif
00100         rdata = data;
00101         nx = x; ny = y; nz = z;
00102         nxy = nx*ny;
00103         nxyz = (size_t)nx*ny*nz;
00104         update();
00105 }
00106 
00107 
00118 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);
00119 
00131 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);
00132 
00133 
00134 
00136 inline void update()
00137 {
00138         flags |= EMDATA_NEEDUPD;
00139         changecount++;
00140 }
00141 
00143 inline void clearupdate()
00144 {
00145         flags &= ~EMDATA_NEEDUPD;
00146         changecount--;
00147 }
00148 
00152 inline bool has_ctff() const
00153 {
00154         if (this->has_attr("ctf")) {
00155                 return true;
00156         }
00157         else {
00158                 return false;
00159         }
00160 }
00161 
00162 
00167 float calc_center_density();
00168 
00169 
00174 float calc_sigma_diff();
00175 
00176 
00180 IntPoint calc_min_location() const;
00181 
00182 
00186 IntPoint calc_max_location() const;
00187 
00195 IntPoint calc_max_location_wrap(const int maxshiftx=-1, const int maxshifty=-1, const int maxshiftz=-1);
00196 
00204 vector<float> calc_max_location_wrap_intp(const int maxshiftx=-1, const int maxshifty=-1, const int maxshiftz=-1);
00205 
00210 FloatPoint calc_center_of_mass(const float threshold=0);
00211 
00216 size_t calc_min_index() const;
00217 
00218 
00223 size_t calc_max_index() const;
00224 
00225 
00235 vector<Pixel> calc_highest_locations(float threshold)  const;
00236 
00242 vector<Pixel> calc_n_highest_locations(int n);
00243 
00248 vector<Pixel> find_pixels_with_value(float val);
00249 
00255 float get_edge_mean() const;
00256 
00257 
00262 float get_circle_mean();
00263 
00264 
00268 Ctf * get_ctf() const;
00269 
00270 
00274 void set_ctf(Ctf * ctf);
00275 
00276 
00282 inline Vec3f get_translation() const
00283 {
00284         return all_translation;
00285 }
00286 
00287 
00292 inline void set_translation(const Vec3f &t)
00293 {
00294         all_translation = t;
00295 }
00296 
00297 
00304 inline void set_translation(float dx, float dy, float dz)
00305 {
00306         all_translation = Vec3f(dx, dy, dz);
00307 }
00308 
00309 
00313 inline Transform get_transform() const
00314 {
00315         Dict rotation_dict;
00316         rotation_dict["type"] = "eman";
00317         rotation_dict["alt"] = attr_dict["euler_alt"];
00318         rotation_dict["az"] = attr_dict["euler_az"];
00319         rotation_dict["phi"] = attr_dict["euler_phi"];
00320 
00321         Transform trans;
00322         trans.to_identity();
00323         trans.set_rotation(rotation_dict);
00324 
00325         return trans;
00326 }
00327 
00335 inline void set_rotation(float az, float alt, float phi)
00336 {
00337     attr_dict["orientation_convention"] = "EMAN";
00338         attr_dict["euler_alt"]=alt;
00339         attr_dict["euler_az"]=az;
00340         attr_dict["euler_phi"]=phi;
00341 }
00342 
00343 
00349 inline void set_rotation(const Transform& t3d)
00350 {
00351         Dict d = t3d.get_rotation("eman");
00352         attr_dict["orientation_convention"] = "EMAN";
00353         attr_dict["euler_alt"] = (float) d["alt"];
00354         attr_dict["euler_az"] = (float) d["az"];
00355         attr_dict["euler_phi"] = (float) d["phi"];;
00356 }
00357 
00358 
00366 void set_size(int nx, int ny=1, int nz=1);
00367 
00368 #ifdef EMAN2_USING_CUDA
00369 
00376 void set_size_cuda(int nx, int ny=1, int nz=1);
00377 #endif //#EMAN2_USING_CUDA
00378 
00379 
00386 void set_complex_size(int nx, int ny=1, int nz=1) {
00387         set_size(nx*2, ny, nz);
00388 }
00389 
00390 
00394 inline void set_path(const string & new_path)
00395 {
00396         path = new_path;
00397 }
00398 
00399 
00403 inline void set_pathnum(int n)
00404 {
00405         pathnum = n;
00406 }
00407 
00408 
00417 MArray2D get_2dview() const;
00418 
00419 
00428 MArray3D get_3dview() const;
00429 
00430 
00438 MCArray2D get_2dcview() const;
00439 
00440 
00448 MCArray3D get_3dcview() const;
00449 
00450 
00458 MCArray3D* get_3dcviewptr() const;
00459 
00460 
00473 MArray2D get_2dview(int x0, int y0) const;
00474 
00475 
00489 MArray3D get_3dview(int x0, int y0, int z0) const;
00490 
00491 
00504 MCArray2D get_2dcview(int x0, int y0) const;
00505 
00506 
00520 MCArray3D get_3dcview(int x0, int y0, int z0) const;
00521 
00522 
00531 EMObject get_attr(const string & attr_name) const;
00532 
00542 EMObject get_attr_default(const string & attr_name, const EMObject & em_obj = EMObject()) const;
00543 
00549 void set_attr(const string & key, EMObject val);
00550 
00551 
00557 void set_attr_python(const string & key, EMObject val);
00558 
00563 inline bool has_attr(const string& key) const {
00564         return attr_dict.has_key(key);
00565 }
00566 
00573 Dict get_attr_dict() const;
00574 
00575 #ifdef EMAN2_USING_CUDA
00576 
00581 inline Dict get_attr_dict_cuda() const {return attr_dict;}
00582 #endif
00583 
00588 void set_attr_dict(const Dict & new_dict);
00589 
00590 
00591 
00596  void del_attr(const string & attr_name);
00597 
00598 
00603  void del_attr_dict(const vector<string> & del_keys);
00604 
00605 
00609 inline int get_xsize() const
00610 {
00611         return nx;
00612 }
00613 
00614 
00618 inline int get_ysize() const
00619 {
00620         return ny;
00621 }
00622 
00623 
00627 inline int get_zsize() const
00628 {
00629         return nz;
00630 }
00631 
00632 
00636 inline size_t get_size() const
00637 {
00638         return (size_t)nx*(size_t)ny*(size_t)nz;
00639 }
00640 
00644 inline vector<float> get_data_as_vector() const {
00645         int size = get_size();
00646         vector<float> v(size);
00647         float* data = get_data();
00648         std::copy(data,data+size,v.begin());
00649         return v;
00650 }
00651 
00655 inline int get_ndim() const
00656 {
00657         if (nz <= 1) {
00658                 if (ny <= 1) {
00659                         return 1;
00660                 }
00661                 else {
00662                         return 2;
00663                 }
00664         }
00665 
00666         return 3;
00667 }
00668 
00669 
00673 inline bool is_shuffled() const
00674 {  //     PRB
00675         if (flags & EMDATA_SHUFFLE) {
00676                 return true;
00677         }
00678 
00679         if(has_attr("is_shuffled")) {
00680                 return get_attr("is_shuffled");
00681         }
00682 
00683         return false;
00684 }
00685 
00686 
00690 inline bool is_FH() const
00691 {  //     PRB
00692         if (flags & EMDATA_FH) {
00693                 return true;
00694         }
00695 
00696         if(has_attr("is_fh")) {
00697                 return get_attr("is_fh");
00698         }
00699 
00700         return false;
00701 }
00702 
00703 
00707 inline bool is_complex() const
00708 {
00709         if(attr_dict.has_key("is_complex")) {
00710                 if (int(attr_dict["is_complex"])) {
00711                         return true;
00712                 }
00713                 else {
00714                         return false;
00715                 }
00716         }
00717         else {
00718                 return false;
00719         }
00720 }
00721 
00722 
00726 inline bool is_real() const
00727 {
00728         return !is_complex();
00729 }
00730 
00731 
00736 inline void set_shuffled(bool is_shuffled)
00737 { // PRB
00738         if (is_shuffled) {
00739 //              printf("entered correct part of set_shuffled \n");
00740 //              flags |=  EMDATA_SHUFFLE;
00741                 set_attr("is_shuffled", (int)1);
00742         }
00743         else {
00744 //              flags &= ~EMDATA_SHUFFLE;
00745                 set_attr("is_shuffled", (int)0);
00746         }
00747 }
00748 
00749 
00754 inline void set_FH(bool is_FH)
00755 { // PRB
00756         if (is_FH) {
00757 //              flags |=  EMDATA_FH;
00758                 set_attr("is_fh", (int)1);
00759         }
00760         else {
00761 //              flags &= ~EMDATA_FH;
00762                 set_attr("is_fh", (int)0);
00763         }
00764 }
00765 
00766 
00771 inline void set_complex(bool is_complex)
00772 {
00773         if (is_complex) {
00774                 attr_dict["is_complex"] = int(1);
00775         }
00776         else {
00777                 attr_dict["is_complex"] = int(0);
00778         }
00779 }
00780 
00781 
00786 inline bool is_complex_x() const
00787 {
00788         if(attr_dict.has_key("is_complex_x")) {
00789                 if (int(attr_dict["is_complex_x"])) {
00790                         return true;
00791                 }
00792                 else {
00793                         return false;
00794                 }
00795         }
00796         else {
00797                 return false;
00798         }
00799 }
00800 
00801 ;
00806 inline void set_complex_x(bool is_complex_x)
00807 {
00808         if (is_complex_x) {
00809                 attr_dict["is_complex_x"] = int(1);
00810         }
00811         else {
00812                 attr_dict["is_complex_x"] = int(0);
00813         }
00814 }
00815 
00816 
00820 inline bool is_flipped() const
00821 {
00822         if (flags & EMDATA_FLIP) { //keep here for back compatibility
00823                 return true;
00824         }
00825 
00826         if(attr_dict.has_key("is_flipped")) {
00827                 if(get_attr("is_flipped")) {
00828                         return true;
00829                 }
00830         }
00831 
00832         return false;
00833 
00834 }
00835 
00836 
00841 inline void set_flipped(bool is_flipped)
00842 {
00843         if (is_flipped) {
00844                 set_attr("is_flipped", (int)1);
00845         }
00846         else {
00847                 set_attr("is_flipped", (int)0);
00848         }
00849 }
00850 
00851 
00856 inline bool is_ri() const
00857 {
00858         if(attr_dict.has_key("is_complex_ri")) {
00859                 if (int(attr_dict["is_complex_ri"])) {
00860                         return true;
00861                 }
00862                 else {
00863                         return false;
00864                 }
00865         }
00866         else {
00867                 return false;
00868         }
00869 }
00870 
00871 
00876 inline void set_ri(bool is_ri)
00877 {
00878         if (is_ri) {
00879                 attr_dict["is_complex_ri"] = int(1);
00880         }
00881         else {
00882                 attr_dict["is_complex_ri"] = int(0);
00883         }
00884 }
00885 
00886 
00890 inline bool is_fftpadded() const
00891 {
00892         if (flags & EMDATA_PAD) {
00893                 return true;
00894         }
00895 
00896         if(has_attr("is_fftpad")) {
00897                 return get_attr("is_fftpad");
00898         }
00899 
00900         return false;
00901 
00902 }
00903 
00904 
00909 inline void set_fftpad(bool is_fftpadded)
00910 {
00911         if (is_fftpadded) {
00912                 set_attr("is_fftpad", int(1));
00913         }
00914         else {
00915                 set_attr("is_fftpad", int(0));
00916         }
00917 }
00918 
00919 
00923 inline bool is_fftodd() const
00924 {
00925         if(flags & EMDATA_FFTODD) {
00926                 return true;
00927         }
00928         else if( attr_dict.has_key("is_fftodd") && (int)attr_dict["is_fftodd"] == 1 ) {
00929                 return true;
00930         }
00931         else {
00932                 return false;
00933         }
00934 }
00935 
00936 
00941 inline void set_fftodd(bool is_fftodd)
00942 {
00943         if (is_fftodd) {
00944                 set_attr("is_fftodd", int(1));
00945         }
00946         else {
00947                 set_attr("is_fftodd", int(0));
00948         }
00949 }
00950 
00951 
00955 inline void set_nxc(int nxc)
00956 {
00957         attr_dict["nxc"] = nxc;
00958 }
00959 
00960 /******************************************************************************
00961  ** These functions are used for EMData's pickling, do not use it for         *
00962  *  other purpose, e.g. get flags of a EMData object                          *
00963  * ***************************************************************************/
00964 inline int get_flags() const
00965 {
00966         return flags;
00967 }
00968 
00969 inline void set_flags(int f)
00970 {
00971         flags = f;
00972 }
00973 
00974 inline int get_changecount() const
00975 {
00976         return changecount;
00977 }
00978 
00979 inline void set_changecount(int c)
00980 {
00981         changecount = c;
00982 }
00983 
00984 inline int get_xoff() const
00985 {
00986         return xoff;
00987 }
00988 
00989 inline int get_yoff() const
00990 {
00991         return yoff;
00992 }
00993 
00994 inline int get_zoff() const
00995 {
00996         return zoff;
00997 }
00998 
00999 inline void set_xyzoff(int x, int y, int z)
01000 {
01001         xoff = x;
01002         yoff = y;
01003         zoff = z;
01004 }
01005 
01011 void scale_pixel(float scale_factor) const;
01012 
01013 inline string get_path() const
01014 {
01015         return path;
01016 }
01017 
01018 inline int get_pathnum() const
01019 {
01020         return pathnum;
01021 }
01022 
01023 //vector<float> get_data_pickle() const;
01024 std::string get_data_pickle() const;
01025 
01026 //void set_data_pickle(const vector<float>& vf);
01027 void set_data_pickle(std::string vf);
01028 
01029 //we don't actually pickle supp, just a place holder to set supp to NULL
01030 int get_supp_pickle() const;
01031 
01032 void set_supp_pickle(int i);
01033 
01034 vector<Vec3i> mask_contig_region(const float& val, const Vec3i& seed);
01035 
01041 float get_amplitude_thres(float thres);
01042 
01043 private:
01049 void set_attr_dict_explicit(const Dict & new_dict);
01050 
01051 /*****************************************************************************/
01052 
01053 #endif  //emdata__metadata_h__

Generated on Tue Jul 12 13:45:47 2011 for EMAN2 by  doxygen 1.4.7