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(int x,int y);
00247
00257 float get_value_at_wrap(int x, int y, int z) const;
00258 float& get_value_at_wrap(int x, int y, int z);
00259
00268 float get_value_at_wrap(int x, int y) const;
00269 float& get_value_at_wrap(int x, int y);
00270
00278 float get_value_at_wrap(int x) const;
00279 float& get_value_at_wrap(int x);
00280
00290 float sget_value_at(int x, int y, int z) const;
00291
00292
00301 float sget_value_at(int x, int y) const;
00302
00303
00312 float sget_value_at(size_t i) const;
00313
00314
00322 float sget_value_at_interp(float x, float y) const;
00323
00324
00333 float sget_value_at_interp(float x, float y, float z) const;
00334
00335
00345 inline void set_value_at(int x, int y, int z, float v)
00346 {
00347 if( x>=nx || x<0 )
00348 {
00349 throw OutofRangeException(0, nx-1, x, "x dimension index");
00350 }
00351 else if( y>=ny || y<0 )
00352 {
00353 throw OutofRangeException(0, ny-1, y, "y dimension index");
00354 }
00355 else if( z>=nz || z<0 )
00356 {
00357 throw OutofRangeException(0, nz-1, z, "z dimension index");
00358 }
00359 else
00360 {
00361 get_data()[x + y * nx + z * nxy] = v;
00362 flags |= EMDATA_NEEDUPD;
00363 changecount++;
00364 }
00365 }
00366
00367
00377 inline void set_value_at_fast(int x, int y, int z, float v)
00378 {
00379 get_data()[x + y * nx + z * nxy] = v;
00380 flags |= EMDATA_NEEDUPD;
00381 changecount++;
00382 }
00383
00384
00393 inline void set_value_at(int x, int y, float v)
00394 {
00395 if( x>=nx || x<0 )
00396 {
00397 throw OutofRangeException(0, nx-1, x, "x dimension index");
00398 }
00399 else if( y>=ny || y<0 )
00400 {
00401 throw OutofRangeException(0, ny-1, y, "y dimension index");
00402 }
00403 else
00404 {
00405 get_data()[x + y * nx] = v;
00406 flags |= EMDATA_NEEDUPD;
00407 changecount++;
00408 }
00409 }
00410
00411
00419 inline void set_value_at_fast(int x, int y, float v)
00420 {
00421 get_data()[x + y * nx] = v;
00422 flags |= EMDATA_NEEDUPD;
00423 changecount++;
00424 }
00425
00426
00434 inline void set_value_at(int x, float v)
00435 {
00436 if( x>=nx || x<0 )
00437 {
00438 throw OutofRangeException(0, nx-1, x, "x dimension index");
00439 }
00440 else
00441 {
00442 get_data()[x] = v;
00443 flags |= EMDATA_NEEDUPD;
00444 changecount++;
00445 }
00446 }
00447
00454 inline void set_value_at_fast(int x, float v)
00455 {
00456 get_data()[x] = v;
00457 flags |= EMDATA_NEEDUPD;
00458 changecount++;
00459 }
00460
00461
00465 void free_memory();
00466
00467 EMData & operator+=(float n);
00468 EMData & operator-=(float n);
00469 EMData & operator*=(float n);
00470 EMData & operator/=(float n);
00471
00472 EMData & operator+=(const EMData & em);
00473 EMData & operator-=(const EMData & em);
00474 EMData & operator*=(const EMData & em);
00475 EMData & operator/=(const EMData & em);
00476
00477 bool operator==(const EMData& that) const;
00478
00480 inline float& operator()(const int ix, const int iy, const int iz) const {
00481 ptrdiff_t pos = (ix-xoff) + ((iy-yoff) + (iz-zoff)*ny)*nx;
00482 #ifdef BOUNDS_CHECKING
00483 if (pos < 0 || pos >= nx*ny*nz) {
00484 throw OutofRangeException(0, nx*ny*nz-1, pos, "EMData");
00485 }
00486 #endif // BOUNDS_CHECKING
00487 return *(get_data() + pos);
00488 }
00489
00490 inline float& operator()(const int ix, const int iy) const {
00491 ptrdiff_t pos = (ix - xoff) + (iy-yoff)*nx;
00492 #ifdef BOUNDS_CHECKING
00493 if (pos < 0 || pos >= nx*ny*nz)
00494 {
00495 throw OutofRangeException(0, nx*ny*nz-1, pos, "EMData");
00496 }
00497 #endif // BOUNDS_CHECKING
00498 return *(get_data() + pos);
00499 }
00500
00501
00502 inline float& operator()(const int ix) const {
00503 ptrdiff_t pos = ix - xoff;
00504 #ifdef BOUNDS_CHECKING
00505 if (pos < 0 || pos >= nx*ny*nz)
00506 throw OutofRangeException(0, nx*ny*nz-1, pos, "EMData");
00507 #endif // BOUNDS_CHECKING
00508 return *(get_data() + pos);
00509 }
00510
00511
00513 void set_array_offsets(const int xoff_=0, const int yoff_=0,
00514 const int zoff_=0) {
00515 xoff=xoff_; yoff=yoff_; zoff=zoff_;
00516 }
00517
00518
00519 void set_array_offsets(vector<int> offsets) {
00520 set_array_offsets(offsets[0],offsets[1],offsets[2]);
00521 }
00522
00523
00524 vector<int> get_array_offsets() {
00525 vector<int> offsets;
00526 offsets.push_back(xoff);
00527 offsets.push_back(yoff);
00528 offsets.push_back(zoff);
00529 return offsets;
00530 }
00531
00532
00534 std::complex<float>& cmplx(const int ix, const int iy, const int iz) {
00535 ptrdiff_t pos = 2*(ix-xoff)+((iy-yoff)+(iz-zoff)*ny)*nx;
00536 #ifdef BOUNDS_CHECKING
00537 if (pos < 0 || pos >= nx*ny*nz)
00538 throw OutofRangeException(0, nx*ny*nz-1, pos, "EMData");
00539 #endif // BOUNDS_CHECKING
00540 float* begin = get_data() + pos;
00541 return *(reinterpret_cast<std::complex<float>* >(begin));
00542 }
00543
00544
00545 std::complex<float>& cmplx(const int ix, const int iy) {
00546 ptrdiff_t pos = 2*(ix-xoff)+(iy-yoff)*nx;
00547 #ifdef BOUNDS_CHECKING
00548 if (pos < 0 || pos >= nx*ny*nz)
00549 throw OutofRangeException(0, nx*ny*nz-1, pos, "EMData");
00550 #endif // BOUNDS_CHECKING
00551 float* begin = get_data() + pos;
00552 return *(reinterpret_cast<std::complex<float>* >(begin));
00553 }
00554
00555
00556 std::complex<float>& cmplx(const int ix) {
00557 ptrdiff_t pos = 2*(ix-xoff);
00558 #ifdef BOUNDS_CHECKING
00559 if (pos < 0 || pos >= nx*ny*nz)
00560 throw OutofRangeException(0, nx*ny*nz-1, pos, "EMData");
00561 #endif // BOUNDS_CHECKING
00562 float* begin = get_data() + pos;
00563 return *(reinterpret_cast<std::complex<float>* >(begin));
00564 }
00565
00566
00572 EMData * power(int n) const;
00573
00578 EMData * sqrt() const;
00579
00580
00586 EMData * log() const;
00587
00588
00594 EMData * log10() const;
00595
00596
00601 EMData * real() const;
00602
00603
00609 EMData * imag() const;
00610
00616 EMData * absi() const;
00617
00618
00623 EMData * amplitude() const;
00624
00625
00630 EMData * phase() const;
00631
00632
00638 EMData * real2complex(float img = 0.0f) const;
00639
00640 #endif //emdata__core_h__