Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

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 float *get_data() const;
00071 #else
00072 inline float *get_data() const { return rdata; }
00073 #endif
00074 
00078 inline const float * const get_const_data() const { return get_data(); }
00079 
00087 inline void set_data(float* data, const int x, const int y, const int z) {
00088         if (rdata) { EMUtil::em_free(rdata); rdata = 0; }
00089 #ifdef EMAN2_USING_CUDA
00090         free_cuda_memory();
00091 #endif
00092         rdata = data;
00093         nx = x; ny = y; nz = z;
00094         nxy = nx*ny;
00095         nxyz = nx*ny*nz;
00096         update();
00097 }
00098 
00099 
00110 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);
00111 
00123 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);
00124 
00125 
00126 
00128 inline void update()
00129 {
00130         flags |= EMDATA_NEEDUPD | EMDATA_GPU_NEEDS_UPDATE | EMDATA_GPU_RO_NEEDS_UPDATE;
00131         changecount++;
00132 }
00133 
00134 
00138 inline bool has_ctff() const
00139 {
00140         if (this->has_attr("ctf")) {
00141                 return true;
00142         }
00143         else {
00144                 return false;
00145         }
00146 }
00147 
00148 
00153 float calc_center_density();
00154 
00155 
00160 float calc_sigma_diff();
00161 
00162 
00166 IntPoint calc_min_location() const;
00167 
00168 
00172 IntPoint calc_max_location() const;
00173 
00181 IntPoint calc_max_location_wrap(const int maxshiftx=-1, const int maxshifty=-1, const int maxshiftz=-1);
00182 
00187 FloatPoint calc_center_of_mass(const float threshold=0);
00188 
00193 int calc_min_index() const;
00194 
00195 
00200 int calc_max_index() const;
00201 
00202 
00212 vector<Pixel> calc_highest_locations(float threshold)  const;
00213 
00219 vector<Pixel> calc_n_highest_locations(int n);
00220 
00225 vector<Pixel> find_pixels_with_value(float val);
00226 
00232 float get_edge_mean() const;
00233 
00234 
00239 float get_circle_mean();
00240 
00241 
00245 Ctf * get_ctf() const;
00246 
00247 
00251 void set_ctf(Ctf * ctf);
00252 
00253 
00259 inline Vec3f get_translation() const
00260 {
00261         return all_translation;
00262 }
00263 
00264 
00269 inline void set_translation(const Vec3f &t)
00270 {
00271         all_translation = t;
00272 }
00273 
00274 
00281 inline void set_translation(float dx, float dy, float dz)
00282 {
00283         all_translation = Vec3f(dx, dy, dz);
00284 }
00285 
00286 
00290 inline Transform get_transform() const
00291 {
00292         Dict rotation_dict;
00293         rotation_dict["type"] = "eman";
00294         rotation_dict["alt"] = attr_dict["euler_alt"];
00295         rotation_dict["az"] = attr_dict["euler_az"];
00296         rotation_dict["phi"] = attr_dict["euler_phi"];
00297 
00298         Transform trans;
00299         trans.to_identity();
00300         trans.set_rotation(rotation_dict);
00301 
00302         return trans;
00303 }
00304 
00312 inline void set_rotation(float az, float alt, float phi)
00313 {
00314     attr_dict["orientation_convention"] = "EMAN";
00315         attr_dict["euler_alt"]=alt;
00316         attr_dict["euler_az"]=az;
00317         attr_dict["euler_phi"]=phi;
00318 }
00319 
00320 
00326 inline void set_rotation(const Transform3D& t3d)
00327 {
00328         Dict d = t3d.get_rotation(Transform3D::EMAN);
00329         attr_dict["orientation_convention"] = "EMAN";
00330         attr_dict["euler_alt"] = (float) d["alt"];
00331         attr_dict["euler_az"] = (float) d["az"];
00332         attr_dict["euler_phi"] = (float) d["phi"];;
00333 }
00334 
00335 
00343 void set_size(int nx, int ny=1, int nz=1);
00344 
00345 #ifdef EMAN2_USING_CUDA
00346 
00353 void set_size_cuda(int nx, int ny=1, int nz=1);
00354 #endif //#EMAN2_USING_CUDA
00355 
00356 
00363 void set_complex_size(int nx, int ny=1, int nz=1) {
00364         set_size(nx*2, ny, nz);
00365 }
00366 
00367 
00371 inline void set_path(const string & new_path)
00372 {
00373         path = new_path;
00374 }
00375 
00376 
00380 inline void set_pathnum(int n)
00381 {
00382         pathnum = n;
00383 }
00384 
00385 
00394 MArray2D get_2dview() const;
00395 
00396 
00405 MArray3D get_3dview() const;
00406 
00407 
00415 MCArray2D get_2dcview() const;
00416 
00417 
00425 MCArray3D get_3dcview() const;
00426 
00427 
00435 MCArray3D* get_3dcviewptr() const;
00436 
00437 
00450 MArray2D get_2dview(int x0, int y0) const;
00451 
00452 
00466 MArray3D get_3dview(int x0, int y0, int z0) const;
00467 
00468 
00481 MCArray2D get_2dcview(int x0, int y0) const;
00482 
00483 
00497 MCArray3D get_3dcview(int x0, int y0, int z0) const;
00498 
00499 
00508 EMObject get_attr(const string & attr_name) const;
00509 
00519 EMObject get_attr_default(const string & attr_name, const EMObject & em_obj = EMObject()) const;
00520 
00526 void set_attr(const string & key, EMObject val);
00527 
00528 
00534 void set_attr_python(const string & key, EMObject val);
00535 
00540 inline bool has_attr(const string& key) const {
00541         return attr_dict.has_key(key);
00542 }
00543 
00550 Dict get_attr_dict() const;
00551 
00552 
00557 void set_attr_dict(const Dict & new_dict);
00558 
00559 
00560 
00565  void del_attr(const string & attr_name);
00566 
00567 
00572  void del_attr_dict(const vector<string> & del_keys);
00573 
00574 
00578 inline int get_xsize() const
00579 {
00580         return nx;
00581 }
00582 
00583 
00587 inline int get_ysize() const
00588 {
00589         return ny;
00590 }
00591 
00592 
00596 inline int get_zsize() const
00597 {
00598         return nz;
00599 }
00600 
00601 
00605 inline size_t get_size() const
00606 {
00607         return (size_t)nx*(size_t)ny*(size_t)nz;
00608 }
00609 
00613 inline vector<float> get_data_as_vector() const {
00614         int size = get_size();
00615         vector<float> v(size);
00616         float* data = get_data();
00617         std::copy(data,data+size,v.begin());
00618         return v;
00619 }
00620 
00624 inline int get_ndim() const
00625 {
00626         if (nz <= 1) {
00627                 if (ny <= 1) {
00628                         return 1;
00629                 }
00630                 else {
00631                         return 2;
00632                 }
00633         }
00634 
00635         return 3;
00636 }
00637 
00638 
00642 inline bool is_shuffled() const
00643 {  //     PRB
00644         if (flags & EMDATA_SHUFFLE) {
00645                 return true;
00646         }
00647 
00648         if(has_attr("is_shuffled")) {
00649                 return get_attr("is_shuffled");
00650         }
00651 
00652         return false;
00653 }
00654 
00655 
00659 inline bool is_FH() const
00660 {  //     PRB
00661         if (flags & EMDATA_FH) {
00662                 return true;
00663         }
00664 
00665         if(has_attr("is_fh")) {
00666                 return get_attr("is_fh");
00667         }
00668 
00669         return false;
00670 }
00671 
00672 
00676 inline bool is_complex() const
00677 {
00678         if(attr_dict.has_key("is_complex")) {
00679                 if (int(attr_dict["is_complex"])) {
00680                         return true;
00681                 }
00682                 else {
00683                         return false;
00684                 }
00685         }
00686         else {
00687                 return false;
00688         }
00689 }
00690 
00691 
00695 inline bool is_real() const
00696 {
00697         return !is_complex();
00698 }
00699 
00700 
00705 inline void set_shuffled(bool is_shuffled)
00706 { // PRB
00707         if (is_shuffled) {
00708 //              printf("entered correct part of set_shuffled \n");
00709 //              flags |=  EMDATA_SHUFFLE;
00710                 set_attr("is_shuffled", (int)1);
00711         }
00712         else {
00713 //              flags &= ~EMDATA_SHUFFLE;
00714                 set_attr("is_shuffled", (int)0);
00715         }
00716 }
00717 
00718 
00723 inline void set_FH(bool is_FH)
00724 { // PRB
00725         if (is_FH) {
00726 //              flags |=  EMDATA_FH;
00727                 set_attr("is_fh", (int)1);
00728         }
00729         else {
00730 //              flags &= ~EMDATA_FH;
00731                 set_attr("is_fh", (int)0);
00732         }
00733 }
00734 
00735 
00740 inline void set_complex(bool is_complex)
00741 {
00742         if (is_complex) {
00743                 attr_dict["is_complex"] = int(1);
00744         }
00745         else {
00746                 attr_dict["is_complex"] = int(0);
00747         }
00748 }
00749 
00750 
00755 inline bool is_complex_x() const
00756 {
00757         if(attr_dict.has_key("is_complex_x")) {
00758                 if (int(attr_dict["is_complex_x"])) {
00759                         return true;
00760                 }
00761                 else {
00762                         return false;
00763                 }
00764         }
00765         else {
00766                 return false;
00767         }
00768 }
00769 
00770 ;
00775 inline void set_complex_x(bool is_complex_x)
00776 {
00777         if (is_complex_x) {
00778                 attr_dict["is_complex_x"] = int(1);
00779         }
00780         else {
00781                 attr_dict["is_complex_x"] = int(0);
00782         }
00783 }
00784 
00785 
00789 inline bool is_flipped() const
00790 {
00791         if (flags & EMDATA_FLIP) { //keep here for back compatibility
00792                 return true;
00793         }
00794 
00795         if(attr_dict.has_key("is_flipped")) {
00796                 if(get_attr("is_flipped")) {
00797                         return true;
00798                 }
00799         }
00800 
00801         return false;
00802 
00803 }
00804 
00805 
00810 inline void set_flipped(bool is_flipped)
00811 {
00812         if (is_flipped) {
00813                 set_attr("is_flipped", (int)1);
00814         }
00815         else {
00816                 set_attr("is_flipped", (int)0);
00817         }
00818 }
00819 
00820 
00825 inline bool is_ri() const
00826 {
00827         if(attr_dict.has_key("is_complex_ri")) {
00828                 if (int(attr_dict["is_complex_ri"])) {
00829                         return true;
00830                 }
00831                 else {
00832                         return false;
00833                 }
00834         }
00835         else {
00836                 return false;
00837         }
00838 }
00839 
00840 
00845 inline void set_ri(bool is_ri)
00846 {
00847         if (is_ri) {
00848                 attr_dict["is_complex_ri"] = int(1);
00849         }
00850         else {
00851                 attr_dict["is_complex_ri"] = int(0);
00852         }
00853 }
00854 
00855 
00859 inline bool is_fftpadded() const
00860 {
00861         if (flags & EMDATA_PAD) {
00862                 return true;
00863         }
00864 
00865         if(has_attr("is_fftpad")) {
00866                 return get_attr("is_fftpad");
00867         }
00868 
00869         return false;
00870 
00871 }
00872 
00873 
00878 inline void set_fftpad(bool is_fftpadded)
00879 {
00880         if (is_fftpadded) {
00881                 set_attr("is_fftpad", int(1));
00882         }
00883         else {
00884                 set_attr("is_fftpad", int(0));
00885         }
00886 }
00887 
00888 
00892 inline bool is_fftodd() const
00893 {
00894         if(flags & EMDATA_FFTODD) {
00895                 return true;
00896         }
00897         else if( attr_dict.has_key("is_fftodd") && (int)attr_dict["is_fftodd"] == 1 ) {
00898                 return true;
00899         }
00900         else {
00901                 return false;
00902         }
00903 }
00904 
00905 
00910 inline void set_fftodd(bool is_fftodd)
00911 {
00912         if (is_fftodd) {
00913                 set_attr("is_fftodd", int(1));
00914         }
00915         else {
00916                 set_attr("is_fftodd", int(0));
00917         }
00918 }
00919 
00920 
00924 inline void set_nxc(int nxc)
00925 {
00926         attr_dict["nxc"] = nxc;
00927 }
00928 
00929 /******************************************************************************
00930  ** These functions are used for EMData's pickling, do not use it for         *
00931  *  other purpose, e.g. get flags of a EMData object                          *
00932  * ***************************************************************************/
00933 inline int get_flags() const
00934 {
00935         return flags;
00936 }
00937 
00938 inline void set_flags(int f)
00939 {
00940         flags = f;
00941 }
00942 
00943 inline int get_changecount() const
00944 {
00945         return changecount;
00946 }
00947 
00948 inline void set_changecount(int c)
00949 {
00950         changecount = c;
00951 }
00952 
00953 inline int get_xoff() const
00954 {
00955         return xoff;
00956 }
00957 
00958 inline int get_yoff() const
00959 {
00960         return yoff;
00961 }
00962 
00963 inline int get_zoff() const
00964 {
00965         return zoff;
00966 }
00967 
00968 inline void set_xyzoff(int x, int y, int z)
00969 {
00970         xoff = x;
00971         yoff = y;
00972         zoff = z;
00973 }
00974 
00980 void scale_pixel(float scale_factor) const;
00981 
00982 inline string get_path() const
00983 {
00984         return path;
00985 }
00986 
00987 inline int get_pathnum() const
00988 {
00989         return pathnum;
00990 }
00991 
00992 //vector<float> get_data_pickle() const;
00993 std::string get_data_pickle() const;
00994 
00995 //void set_data_pickle(const vector<float>& vf);
00996 void set_data_pickle(std::string vf);
00997 
00998 //we don't actually pickle supp, just a place holder to set supp to NULL
00999 int get_supp_pickle() const;
01000 
01001 void set_supp_pickle(int i);
01002 
01003 vector<Vec3i> mask_contig_region(const float& val, const Vec3i& seed);
01004 
01010 float get_amplitude_thres(float thres);
01011 
01012 private:
01018 void set_attr_dict_explicit(const Dict & new_dict);
01019 
01020 /*****************************************************************************/
01021 
01022 #endif  //emdata__metadata_h__

Generated on Thu Dec 9 13:45:45 2010 for EMAN2 by  doxygen 1.3.9.1