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
00040 #ifndef emdata__core_h__
00041 #define emdata__core_h__
00042
00043 public:
00047 EMData *copy() const;
00048
00049
00053 EMData *copy_head() const;
00054
00055
00060 void add(float f,int keepzero=0);
00061
00062
00068 void add(const EMData & image);
00069
00075 void addsquare(const EMData & image);
00076
00077
00081 void sub(float f);
00082
00083
00088 void sub(const EMData & image);
00089
00095 void subsquare(const EMData & image);
00096
00097
00101 void mult(int n)
00102 {
00103 mult((float)n);
00104 }
00105
00106
00110 void mult(float f);
00111
00112
00120 void mult(const EMData & image, bool prevent_complex_multiplication=false);
00121
00122 void mult_complex_efficient(const EMData & em, const int radius);
00123
00127 void div(float f);
00128
00129
00135 void div(const EMData & image);
00136
00138 void to_zero();
00139
00140
00142 void to_one();
00143
00145 void to_value(const float& value);
00146
00157 float dot(EMData * with);
00158
00159
00166 EMData *get_row(int row_index) const;
00167
00168
00175 void set_row(const EMData * data, int row_index);
00176
00177
00184 EMData *get_col(int col_index) const;
00185
00186
00193 void set_col(const EMData * data, int col_index);
00194
00195
00204 inline float get_value_at(int x, int y, int z) const
00205 {
00206 return get_data()[x + y * nx + z * nxy];
00207 }
00208
00209
00217 inline float get_value_at(int x, int y) const
00218 {
00219 return get_data()[x + y * nx];
00220 }
00221
00222
00230 inline float get_value_at(size_t i) const
00231 {
00232 return get_data()[i];
00233 }
00234
00246 std::complex<float> get_complex_at(const int &x,const int &y) const;
00247
00260 std::complex<float> get_complex_at(const int &x,const int &y,const int &z) const;
00261
00274 size_t get_complex_index(const int &x,const int &y,const int &z) const;
00275
00276 size_t get_complex_index(int x,int y,int z,const int &subx0,const int &suby0,const int &subz0,const int &fullnx,const int &fullny,const int &fullnz) const;
00277
00278 inline size_t get_complex_index_fast(const int &x,const int &y,const int &z) const {
00279
00280 if (x<0) {
00281 return (size_t)x*-2+(y<=0?-y:ny-y)*(size_t)nx+(z<=0?-z:nz-z)*(size_t)nxy;
00282 }
00283 return x*2+(y<0?ny+y:y)*(size_t)nx+(z<0?nz+z:z)*(size_t)nxy;
00284 }
00285
00298 void set_complex_at(const int &x,const int &y,const std::complex<float> &val);
00299
00313 void set_complex_at(const int &x,const int &y,const int &z,const std::complex<float> &val);
00314
00328 size_t add_complex_at(const int &x,const int &y,const int &z,const std::complex<float> &val);
00329
00330 inline size_t add_complex_at_fast(const int &x,const int &y,const int &z,const std::complex<float> &val) {
00331
00332
00333 size_t idx;
00334 if (x<0) {
00335 idx=-x*2+(y<=0?-y:ny-y)*(size_t)nx+(z<=0?-z:nz-z)*(size_t)nxy;
00336 rdata[idx]+=(float)val.real();
00337 rdata[idx+1]-=(float)val.imag();
00338 return idx;
00339 }
00340
00341 idx=x*2+(y<0?ny+y:y)*(size_t)nx+(z<0?nz+z:z)*(size_t)nxy;
00342 rdata[idx]+=(float)val.real();
00343 rdata[idx+1]+=(float)val.imag();
00344
00345 return idx;
00346 }
00347
00359 size_t add_complex_at(int x,int y,int z,const int &subx0,const int &suby0,const int &subz0,const int &fullnx,const int &fullny,const int &fullnz,const std::complex<float> &val);
00360
00370 float get_value_at_wrap(int x, int y, int z) const;
00371 float& get_value_at_wrap(int x, int y, int z);
00372
00381 float get_value_at_wrap(int x, int y) const;
00382 float& get_value_at_wrap(int x, int y);
00383
00391 float get_value_at_wrap(int x) const;
00392 float& get_value_at_wrap(int x);
00393
00403 float sget_value_at(int x, int y, int z) const;
00404
00405
00414 float sget_value_at(int x, int y) const;
00415
00416
00425 float sget_value_at(size_t i) const;
00426
00427
00435 float sget_value_at_interp(float x, float y) const;
00436
00437
00446 float sget_value_at_interp(float x, float y, float z) const;
00447
00448
00458 inline void set_value_at(int x, int y, int z, float v)
00459 {
00460 if( x>=nx || x<0 )
00461 {
00462 throw OutofRangeException(0, nx-1, x, "x dimension index");
00463 }
00464 else if( y>=ny || y<0 )
00465 {
00466 throw OutofRangeException(0, ny-1, y, "y dimension index");
00467 }
00468 else if( z>=nz || z<0 )
00469 {
00470 throw OutofRangeException(0, nz-1, z, "z dimension index");
00471 }
00472 else
00473 {
00474 get_data()[x + y * nx + z * nxy] = v;
00475 flags |= EMDATA_NEEDUPD;
00476 changecount++;
00477 }
00478 }
00479
00480
00490 inline void set_value_at_fast(int x, int y, int z, float v)
00491 {
00492 get_data()[x + y * nx + z * nxy] = v;
00493 flags |= EMDATA_NEEDUPD;
00494 changecount++;
00495 }
00496
00497
00506 inline void set_value_at(int x, int y, float v)
00507 {
00508 if( x>=nx || x<0 )
00509 {
00510 throw OutofRangeException(0, nx-1, x, "x dimension index");
00511 }
00512 else if( y>=ny || y<0 )
00513 {
00514 throw OutofRangeException(0, ny-1, y, "y dimension index");
00515 }
00516 else
00517 {
00518 get_data()[x + y * nx] = v;
00519 flags |= EMDATA_NEEDUPD;
00520 changecount++;
00521 }
00522 }
00523
00524
00532 inline void set_value_at_fast(int x, int y, float v)
00533 {
00534 get_data()[x + y * nx] = v;
00535 flags |= EMDATA_NEEDUPD;
00536 changecount++;
00537 }
00538
00539
00547 inline void set_value_at(int x, float v)
00548 {
00549 if( x>=nx || x<0 )
00550 {
00551 throw OutofRangeException(0, nx-1, x, "x dimension index");
00552 }
00553 else
00554 {
00555 get_data()[x] = v;
00556 flags |= EMDATA_NEEDUPD;
00557 changecount++;
00558 }
00559 }
00560
00567 inline void set_value_at_fast(int x, float v)
00568 {
00569 get_data()[x] = v;
00570 flags |= EMDATA_NEEDUPD;
00571 changecount++;
00572 }
00573
00574
00578 void free_memory();
00579
00580 EMData & operator+=(float n);
00581 EMData & operator-=(float n);
00582 EMData & operator*=(float n);
00583 EMData & operator/=(float n);
00584
00585 EMData & operator+=(const EMData & em);
00586 EMData & operator-=(const EMData & em);
00587 EMData & operator*=(const EMData & em);
00588 EMData & operator/=(const EMData & em);
00589
00590 bool operator==(const EMData& that) const;
00591
00593 inline float& operator()(const int ix, const int iy, const int iz) const {
00594 ptrdiff_t pos = (ix-xoff) + ((iy-yoff) + (iz-zoff)*ny)*nx;
00595 #ifdef BOUNDS_CHECKING
00596 if (pos < 0 || pos >= nx*ny*nz) {
00597 throw OutofRangeException(0, nx*ny*nz-1, pos, "EMData");
00598 }
00599 #endif // BOUNDS_CHECKING
00600 return *(get_data() + pos);
00601 }
00602
00603 inline float& operator()(const int ix, const int iy) const {
00604 ptrdiff_t pos = (ix - xoff) + (iy-yoff)*nx;
00605 #ifdef BOUNDS_CHECKING
00606 if (pos < 0 || pos >= nx*ny*nz)
00607 {
00608 throw OutofRangeException(0, nx*ny*nz-1, pos, "EMData");
00609 }
00610 #endif // BOUNDS_CHECKING
00611 return *(get_data() + pos);
00612 }
00613
00614
00615 inline float& operator()(const int ix) const {
00616 ptrdiff_t pos = ix - xoff;
00617 #ifdef BOUNDS_CHECKING
00618 if (pos < 0 || pos >= nx*ny*nz)
00619 throw OutofRangeException(0, nx*ny*nz-1, pos, "EMData");
00620 #endif // BOUNDS_CHECKING
00621 return *(get_data() + pos);
00622 }
00623
00624
00626 void set_array_offsets(const int xoff_=0, const int yoff_=0,
00627 const int zoff_=0) {
00628 xoff=xoff_; yoff=yoff_; zoff=zoff_;
00629 }
00630
00631
00632 void set_array_offsets(vector<int> offsets) {
00633 set_array_offsets(offsets[0],offsets[1],offsets[2]);
00634 }
00635
00636
00637 vector<int> get_array_offsets() {
00638 vector<int> offsets;
00639 offsets.push_back(xoff);
00640 offsets.push_back(yoff);
00641 offsets.push_back(zoff);
00642 return offsets;
00643 }
00644
00645
00647 std::complex<float>& cmplx(const int ix, const int iy, const int iz) {
00648 ptrdiff_t pos = 2*(ix-xoff)+((iy-yoff)+(iz-zoff)*ny)*nx;
00649 #ifdef BOUNDS_CHECKING
00650 if (pos < 0 || pos >= nx*ny*nz)
00651 throw OutofRangeException(0, nx*ny*nz-1, pos, "EMData");
00652 #endif // BOUNDS_CHECKING
00653 float* begin = get_data() + pos;
00654 return *(reinterpret_cast<std::complex<float>* >(begin));
00655 }
00656
00657
00658 std::complex<float>& cmplx(const int ix, const int iy) {
00659 ptrdiff_t pos = 2*(ix-xoff)+(iy-yoff)*nx;
00660 #ifdef BOUNDS_CHECKING
00661 if (pos < 0 || pos >= nx*ny*nz)
00662 throw OutofRangeException(0, nx*ny*nz-1, pos, "EMData");
00663 #endif // BOUNDS_CHECKING
00664 float* begin = get_data() + pos;
00665 return *(reinterpret_cast<std::complex<float>* >(begin));
00666 }
00667
00668
00669 std::complex<float>& cmplx(const int ix) {
00670 ptrdiff_t pos = 2*(ix-xoff);
00671 #ifdef BOUNDS_CHECKING
00672 if (pos < 0 || pos >= nx*ny*nz)
00673 throw OutofRangeException(0, nx*ny*nz-1, pos, "EMData");
00674 #endif // BOUNDS_CHECKING
00675 float* begin = get_data() + pos;
00676 return *(reinterpret_cast<std::complex<float>* >(begin));
00677 }
00678
00679
00685 EMData * power(int n) const;
00686
00691 EMData * sqrt() const;
00692
00693
00699 EMData * log() const;
00700
00701
00707 EMData * log10() const;
00708
00709
00714 EMData * real() const;
00715
00716
00722 EMData * imag() const;
00723
00729 EMData * absi() const;
00730
00731
00736 EMData * amplitude() const;
00737
00738
00743 EMData * phase() const;
00744
00745
00751 EMData * real2complex(float img = 0.0f) const;
00752
00753 #endif //emdata__core_h__