00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef eman__emdata_h__
00037 #define eman__emdata_h__ 1
00038
00039 #ifdef _WIN32
00040 #pragma warning(disable:4819)
00041 #endif //_WIN32
00042
00043 #include <cfloat>
00044 #include <complex>
00045 #include <fstream>
00046
00047 #include "sparx/fundamentals.h"
00048 #include "emutil.h"
00049 #include "util.h"
00050 #include "sparx/emarray.h"
00051 #include "geometry.h"
00052 #include "transform.h"
00053 #ifdef EMAN2_USING_CUDA
00054 #include <cuda_runtime_api.h>
00055 #include "cuda/cuda_util.h"
00056 #endif // EMAN2_USING_CUDA
00057 using std::string;
00058 using std::vector;
00059 using std::map;
00060
00061 using std::ostream;
00062
00063 #include <utility>
00064 using std::pair;
00065
00066 namespace EMAN
00067 {
00068 class ImageIO;
00069 class Ctf;
00070 class XYData;
00071 class Transform3D;
00072 class Transform;
00073 class GLUtil;
00074
00075 typedef boost::multi_array_ref<float, 2> MArray2D;
00076 typedef boost::multi_array_ref<float, 3> MArray3D;
00077 typedef boost::multi_array_ref<std::complex<float>, 2> MCArray2D;
00078 typedef boost::multi_array_ref<std::complex<float>, 3> MCArray3D;
00079 typedef boost::multi_array<int, 2> MIArray2D;
00080 typedef boost::multi_array<int, 3> MIArray3D;
00081
00088 class EMData
00089 {
00090 friend class GLUtil;
00091
00093 #include "emdata_io.h"
00094
00096 #include "emdata_metadata.h"
00097
00099 #include "emdata_modular.h"
00100
00102 #include "emdata_transform.h"
00103
00105 #include "emdata_core.h"
00106
00108 #include "sparx/emdata_sparx.h"
00109 #ifdef EMAN2_USING_CUDA
00110
00111 #include "emdata_cuda.h"
00112 #endif // EMAN2_USING_CUDA
00113
00114 static int totalalloc;
00115 public:
00116 enum FFTPLACE { FFT_OUT_OF_PLACE, FFT_IN_PLACE };
00117 enum WINDOWPLACE { WINDOW_OUT_OF_PLACE, WINDOW_IN_PLACE };
00118
00120 EMData();
00121 ~ EMData();
00122
00126 explicit EMData(const string& filename, int image_index=0);
00127
00134 EMData(int nx, int ny, int nz=1, bool is_real=true);
00135
00145 EMData(float* data, const int nx, const int ny, const int nz, const Dict& attr_dict = Dict());
00146
00152 EMData(const EMData& that);
00153
00159 EMData& operator=(const EMData& that);
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00215 EMData *get_clip(const Region & area, const float fill = 0) const;
00216
00223 void clip_inplace(const Region & area,const float& fill_value=0);
00224
00229 EMData *get_top_half() const;
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00252 EMData *get_rotated_clip(const Transform & xform, const IntSize &size, float scale=1.0);
00253
00264 EMData* window_center(int l);
00265
00266
00281 float *setup4slice(bool redo = true);
00282
00283
00287 void scale(float scale_factor);
00288
00289
00295 void translate(float dx, float dy, float dz);
00296
00297
00301 void translate(const Vec3f &translation);
00302
00303
00310 void translate(int dx, int dy, int dz);
00311
00312
00317 void translate(const Vec3i &translation);
00318
00319
00324 void rotate(const Transform3D & t);
00325
00326
00333 void rotate(float az, float alt, float phi);
00334
00335
00340 void rotate_translate(const Transform3D & t);
00341
00345 inline void transform(const Transform& t) {
00346 ENTERFUNC;
00347 process_inplace("math.transform",Dict("transform",(Transform*)(&t)));
00348
00349 EXITFUNC;
00350 }
00351
00356 inline void rotate_translate(const Transform & t) {
00357 cout << "Deprecation warning. Please consider using EMData::transform() instead " << endl;
00358 transform(t); }
00359
00369 void rotate_translate(float az, float alt, float phi, float dx, float dy, float dz);
00370
00371
00384 void rotate_translate(float az, float alt, float phi, float dx, float dy,
00385 float dz, float pdx, float pdy, float pdz);
00386
00387
00393 void rotate_x(int dx);
00394
00395
00400 inline void rotate_180() {
00401 ENTERFUNC;
00402 process_inplace("math.rotate.180",Dict());
00403 EXITFUNC;
00404 }
00405
00406
00420 double dot_rotate_translate(EMData * with, float dx, float dy, float da,const bool mirror=false);
00421
00422
00433 EMData *little_big_dot(EMData * little_img, bool do_sigma = false);
00434
00435
00448 EMData *do_radon();
00449
00450
00466 EMData *calc_ccf(EMData * with, fp_flag fpflag = CIRCULANT, bool center=false);
00467
00480 void zero_corner_circulant(const int radius = 0);
00481
00500 EMData *calc_ccfx( EMData * const with, int y0 = 0, int y1 = -1, bool nosum = false);
00501
00502
00511 EMData *make_rotational_footprint(bool unwrap = true);
00512 EMData *make_rotational_footprint_e1(bool unwrap = true);
00513 EMData *make_rotational_footprint_cmc(bool unwrap = true);
00514
00531 EMData *make_footprint(int type=0);
00532
00533
00546 EMData *calc_mutual_correlation(EMData * with, bool tocorner = false, EMData * filter = 0);
00547
00548
00564 EMData *unwrap(int r1 = -1, int r2 = -1, int xs = -1, int dx = 0,
00565 int dy = 0, bool do360 = false, bool weight_radial=true) const;
00566
00567
00575 void apply_radial_func(float x0, float dx, vector < float >array, bool interp = true);
00576
00577
00589 vector < float >calc_radial_dist(int n, float x0, float dx,bool inten);
00590
00591
00603 vector < float >calc_radial_dist(int n, float x0, float dx, int nwedge, bool inten);
00604
00605
00609 void cconj();
00610
00611
00619 void add_incoherent(EMData * obj);
00620
00621
00633 vector <float> calc_hist(int hist_size = 128, float hist_min = 0, float hist_max = 0, const float& brt = 0.0f, const float& cont = 1.0f);
00634
00635
00647 vector<float> calc_az_dist(int n, float a0, float da, float rmin,
00648 float rmax);
00649
00650 #if 0
00651 void calc_rcf(EMData * with, vector < float >&sum_array);
00652 #endif
00653
00666 float calc_dist(EMData * second_img, int y_index = 0) const;
00667
00684 EMData *calc_flcf(EMData * with);
00685
00704 EMData *calc_fast_sigma_image( EMData* mask);
00705
00711 EMData *convolute(EMData * with);
00712
00713 #if 0
00714 void create_ctf_map(CtfMapType type, XYData * sf = 0);
00715 #endif
00716
00717
00739 void common_lines(EMData * image1, EMData * image2, int mode = 0,
00740 int steps = 180, bool horizontal = false);
00741
00752 void common_lines_real(EMData * image1, EMData * image2,
00753 int steps = 180, bool horizontal = false);
00754
00768 void cut_slice(const EMData * const map, const Transform& tr, bool interpolate = true);
00769
00778
00779 #ifdef EMAN2_USING_CUDA
00780
00789 EMData* cut_slice_cuda(const Transform& tr);
00790 #endif // EMAN2_USING_CUDA
00791
00805 void uncut_slice(EMData * const map, const Transform& tr) const;
00806
00810 int getResolution() const {
00811 int resolution = 0;
00812 int num = 1;
00813 while(num < get_xsize()) {
00814 resolution++;
00815 num = 1 << resolution;
00816 }
00817
00818 return resolution;
00819 }
00820
00823 void debug_print_parms()
00824 {
00825 std::cout << "Printing EMData params" << std::endl;
00826 for ( Dict::const_iterator it = attr_dict.begin(); it != attr_dict.end(); ++it )
00827 {
00828 std::cout << (it->first) << " " << (it->second).to_str() << std::endl;
00829 }
00830 std::cout << "Done printing EMData params" << std::endl;
00831 }
00832
00838 void set_xyz_origin(float origin_x, float origin_y, float origin_z);
00839 private:
00846 enum EMDataFlags {
00847
00848
00849 EMDATA_BUSY = 1 << 3,
00850 EMDATA_HASCTFF = 1 << 4,
00851 EMDATA_NEEDUPD = 1 << 5,
00852
00853 EMDATA_FLIP = 1 << 7,
00854 EMDATA_PAD = 1 << 8,
00855 EMDATA_FFTODD = 1 << 9,
00856 EMDATA_SHUFFLE = 1 << 10,
00857 EMDATA_FH = 1 << 11,
00858 EMDATA_CPU_NEEDS_UPDATE = 1 << 12,
00859 EMDATA_GPU_NEEDS_UPDATE = 1 << 13,
00860 EMDATA_GPU_RO_NEEDS_UPDATE = 1 << 14
00861 };
00862
00863 void update_stat() const;
00864 void save_byteorder_to_dict(ImageIO * imageio);
00865
00866 private:
00868 mutable Dict attr_dict;
00870 mutable float *rdata;
00872 float *supp;
00873
00876
00877
00879 mutable int flags;
00880
00881 int changecount;
00883 int nx, ny, nz, nxy;
00885 int xoff, yoff, zoff;
00886
00888 Vec3f all_translation;
00889
00890
00891 string path;
00892 int pathnum;
00893
00895 mutable EMData* rot_fp;
00896
00897
00898
00899 class ClipInplaceVariables
00900 {
00901 public:
00902 ClipInplaceVariables(const int p_nx, const int p_ny, const int p_nz, const int n_nx, const int n_ny, const int n_nz,const int xtrans, const int ytrans, const int ztrans) :
00903 prv_nx(p_nx), prv_ny(p_ny), prv_nz(p_nz), new_nx(n_nx), new_ny(n_ny), new_nz(n_nz), xshift(xtrans), yshift(ytrans), zshift(ztrans),
00904 x_iter(prv_nx), y_iter(prv_ny), z_iter(prv_nz), new_z_top(0), new_z_bottom(0), new_y_back(0), new_y_front(0),new_x_left(0), new_x_right(0),
00905 prv_z_top(0), prv_z_bottom(0), prv_y_back(0), prv_y_front(0), prv_x_left(0), prv_x_right(0)
00906 {
00907 if ( xtrans > 0 ) x_iter -= xtrans;
00908 if ( x_iter < 0 ) x_iter = 0;
00909 if ( ytrans > 0 ) y_iter -= ytrans;
00910 if ( y_iter < 0 ) y_iter = 0;
00911 if ( ztrans > 0 ) z_iter -= ztrans;
00912 if ( z_iter < 0 ) z_iter = 0;
00913
00914
00915
00916
00917 if ( (new_nz + ztrans) > prv_nz ) new_z_top = new_nz + ztrans - prv_nz;
00918 if ( (new_ny + ytrans) > prv_ny ) new_y_back = new_ny + ytrans - prv_ny;
00919 if ( (new_nx + xtrans) > prv_nx ) new_x_right = new_nx + xtrans - prv_nx;
00920
00921 if ( (new_nz + ztrans) < prv_nz )
00922 {
00923 prv_z_top = prv_nz - new_nz - ztrans;
00924 z_iter -= prv_z_top;
00925 }
00926 if ( (new_ny + ytrans) < prv_ny )
00927 {
00928 prv_y_back = prv_ny - new_ny - ytrans;
00929 y_iter -= prv_y_back;
00930 }
00931 if ( (new_nx + xtrans) < prv_nx )
00932 {
00933 prv_x_right = prv_nx - new_nx - xtrans;
00934 x_iter -= prv_x_right;
00935 }
00936
00937 if ( xtrans > 0 ) prv_x_left = xtrans;
00938 if ( ytrans > 0 ) prv_y_front = ytrans;
00939 if ( ztrans > 0 ) prv_z_bottom = ztrans;
00940
00941 if ( xtrans < 0 ) new_x_left = -xtrans;
00942 if ( ytrans < 0 ) new_y_front = -ytrans;
00943 if ( ztrans < 0 ) new_z_bottom = -ztrans;
00944
00945 }
00946 ~ClipInplaceVariables() {}
00947
00948 int prv_nx, prv_ny, prv_nz, new_nx, new_ny, new_nz;
00949 int xshift, yshift, zshift;
00950 int x_iter, y_iter, z_iter;
00951 int new_z_top, new_z_bottom, new_y_back, new_y_front, new_x_left, new_x_right;
00952 int prv_z_top, prv_z_bottom, prv_y_back, prv_y_front, prv_x_left, prv_x_right;
00953 };
00954 };
00955
00956
00957 EMData * operator+(const EMData & em, float n);
00958 EMData * operator-(const EMData & em, float n);
00959 EMData * operator*(const EMData & em, float n);
00960 EMData * operator/(const EMData & em, float n);
00961
00962 EMData * operator+(float n, const EMData & em);
00963 EMData * operator-(float n, const EMData & em);
00964 EMData * operator*(float n, const EMData & em);
00965 EMData * operator/(float n, const EMData & em);
00966
00967 EMData * rsub(const EMData & em, float n);
00968 EMData * rdiv(const EMData & em, float n);
00969
00970 EMData * operator+(const EMData & a, const EMData & b);
00971 EMData * operator-(const EMData & a, const EMData & b);
00972 EMData * operator*(const EMData & a, const EMData & b);
00973 EMData * operator/(const EMData & a, const EMData & b);
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986 }
00987
00988
00989 #endif
00990
00991