36#ifndef emdata__core_h__
37#define emdata__core_h__
56void add(
float f,
int keepzero=0);
64void add(
const EMData & image);
84void sub(
const EMData & image);
116void mult(
const EMData & image,
bool prevent_complex_multiplication=
false);
142void div(
const EMData & image);
183EMData *
get_row(
int row_index)
const;
192void set_row(
const EMData * data,
int row_index);
201EMData *
get_col(
int col_index)
const;
210void set_col(
const EMData * data,
int col_index);
223 return get_data()[(size_t)
x + (
size_t)
y * (size_t)nx + (
size_t)z * (size_t)nxy];
284std::complex<float>
get_complex_at(
const int &
x,
const int &
y,
const int &z)
const;
300size_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;
305 return (
size_t)
x*-2+(
y<=0?-
y:ny-
y)*(
size_t)nx+(z<=0?-z:nz-z)*(
size_t)nxy;
307 return x*2+(
y<0?ny+
y:
y)*(
size_t)nx+(z<0?nz+z:z)*(
size_t)nxy;
319 size_t idx=
x*2+
y*(size_t)nx+z*(
size_t)nxy;
320 rdata[idx]=(float)val.real();
321 rdata[idx+1]=(float)val.imag();
336void set_complex_at(
const int &
x,
const int &
y,
const std::complex<float> &val);
351void set_complex_at(
const int &
x,
const int &
y,
const int &z,
const std::complex<float> &val);
366size_t add_complex_at(
const int &
x,
const int &
y,
const int &z,
const std::complex<float> &val);
370if (abs(
x)>=nx/2 || abs(
y)>ny/2 || abs(z)>nz/2)
return nxyz;
377 rdata[0]+=(float)val.real();
382 size_t idx=(
y<=0?-
y:ny-
y)*(
size_t)nx+(z<=0?-z:nz-z)*(
size_t)nxy;
384 rdata[idx]+=(float)val.real();
385 rdata[idx+1]+=(float)-val.imag();
389 rdata[nx-2]+=(float)val.real();
394 size_t idx=nx-2+(
y<=0?-
y:ny-
y)*(
size_t)nx+(z<=0?-z:nz-z)*(
size_t)nxy;
396 rdata[idx]+=(float)val.real();
397 rdata[idx+1]+=(float)-val.imag();
400 idx=-
x*2+(
y<=0?-
y:ny-
y)*(
size_t)nx+(z<=0?-z:nz-z)*(
size_t)nxy;
402 rdata[idx]+=(float)val.real();
403 rdata[idx+1]+=-(float)val.imag();
407idx=
x*2+(
y<0?ny+
y:
y)*(
size_t)nx+(z<0?nz+z:z)*(
size_t)nxy;
409rdata[idx]+=(float)val.real();
410rdata[idx+1]+=(float)val.imag();
426size_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);
569 else if(
y>=ny ||
y<0 )
573 else if( z>=nz || z<0 )
579 get_data()[(size_t)
x + (
size_t)
y * (size_t)nx + (
size_t)z * (size_t)nxy] = v;
596 get_data()[(size_t)
x + (
size_t)
y * (size_t)nx + (
size_t)z * (size_t)nxy] *= v;
611 get_data()[(size_t)
x + (
size_t)
y * (size_t)nx + (
size_t)z * (size_t)nxy] = v;
640 else if(
y>=ny ||
y<0 )
724bool equal(
const EMData& that)
const;
727inline float&
operator()(
const int ix,
const int iy,
const int iz)
const {
728 ptrdiff_t pos = (size_t)(ix-xoff) + ((iy-yoff) + (
size_t)(iz-zoff)*ny)*nx;
729#ifdef BOUNDS_CHECKING
730 if (pos < 0 || pos >= (
size_t)nx*ny*nz) {
738 ptrdiff_t pos = (ix - xoff) + (iy-yoff)*nx;
739#ifdef BOUNDS_CHECKING
740 if (pos < 0 || pos >= (
size_t)nx*ny*nz)
750 ptrdiff_t pos = ix - xoff;
751#ifdef BOUNDS_CHECKING
752 if (pos < 0 || pos >= (
size_t)nx*ny*nz)
762 xoff=xoff_; yoff=yoff_; zoff=zoff_;
773 offsets.push_back(xoff);
774 offsets.push_back(yoff);
775 offsets.push_back(zoff);
781std::complex<float>&
cmplx(
const int ix,
const int iy,
const int iz) {
782 ptrdiff_t pos = 2*(ix-xoff)+((iy-yoff)+(iz-zoff)*ny)*(size_t)nx;
783#ifdef BOUNDS_CHECKING
784 if (pos < 0 || pos >= (
size_t)nx*ny*nz)
788 return *(
reinterpret_cast<std::complex<float>*
>(begin));
792std::complex<float>&
cmplx(
const int ix,
const int iy) {
793 ptrdiff_t pos = 2*(ix-xoff)+(iy-yoff)*nx;
794#ifdef BOUNDS_CHECKING
795 if (pos < 0 || pos >= (
size_t)nx*ny*nz)
799 return *(
reinterpret_cast<std::complex<float>*
>(begin));
803std::complex<float>&
cmplx(
const int ix) {
804 ptrdiff_t pos = 2*(ix-xoff);
805#ifdef BOUNDS_CHECKING
806 if (pos < 0 || pos >= (
size_t)nx*ny*nz)
810 return *(
reinterpret_cast<std::complex<float>*
>(begin));
819EMData *
power(
int n)
const;
825EMData *
sqrt()
const;
841EMData *
log10()
const;
863EMData *
absi()
const;
877EMData *
phase()
const;
void addsquare(const EMData &image)
add the squared value of each pixel from a same-size image to this image.
float sget_value_at_interp(float x, float y) const
Get pixel density value at interpolation of (x,y).
void set_value_at_index(size_t i, float v)
Set the pixel density value at index.
std::complex< float > get_complex_at_interp(float x, float y) const
Gets bilinear interpolated complex values.
EMData * copy() const
This file is a part of "emdata.h", to use functions in this file, you should "#include "emdata....
size_t add_complex_at(const int &x, const int &y, const int &z, const std::complex< float > &val)
Add complex<float> value at x,y,z.
void to_zero()
Set all the pixel value = 0.
EMData & operator+=(float n)
size_t get_complex_index(const int &x, const int &y, const int &z) const
Get complex<float> index for coords x,y,z.
EMData * get_col(int col_index) const
Get one column of a 2D images.
std::complex< float > & cmplx(const int ix, const int iy, const int iz)
Return reference to complex elements.
EMData * log() const
return natural logarithm image for a image
void mult(int n)
multiply an integer number to each pixel value of the image.
void set_complex_at_idx(const int &x, const int &y, const int &z, const std::complex< float > &val)
Set complex<float> value at x,y,z without reinterpreting the coordinates.
void set_value_at(Vec3i loc, float val)
set_value_at with Vec3i
EMData * absi() const
For a real image, it returns a same size image with abs() of each pixel.
void to_value(const float &value)
set all the pixel values to a value.
bool equal(const EMData &that) const
compare the equality of two EMData object based on their pixel values
void set_array_offsets(const int xoff_=0, const int yoff_=0, const int zoff_=0)
Set the array offsets.
EMData * power(int n) const
return a image to the power of n
vector< int > get_array_offsets()
float get_value_at_wrap(int x, int y, int z) const
Get the pixel density value at coordinates (x,y,z).
void add(float f, int keepzero=0)
add a number to each pixel value of the image.
void sub(float f)
subtract a float number to each pixel value of the image.
EMData * sqrt() const
return square root of current image
void to_one()
set all the pixel values = 1.
float get_value_at(int x, int y, int z) const
Get the pixel density value at coordinates (x,y,z).
EMData * real2complex(float img=0.0f) const
create a complex image from a real image, this complex image is in real/imaginary format
void mult_value_at_fast(int x, int y, int z, float v)
Multiplies the pixel density value at coordinates (x,y,z).
float sget_value_at(Vec3i v)
Vec3i version of save routines below.
EMData * log10() const
return base 10 logarithm image for a image
size_t add_complex_at_fast(const int &x, const int &y, const int &z, const std::complex< float > &val)
float dot(EMData *with)
Dot product 2 images.
EMData * amplitude() const
return amplitude part of a complex image as a real image format
void set_row(const EMData *data, int row_index)
Set one row of a 1D/2D image.
void mult_ri(const EMData &image)
multiply each complex RI pixel of this image with each pixel of some other same-size image.
EMData * imag() const
return imaginary part of a complex image as a real image format.
std::complex< float > get_complex_at_3ginterp(float x, float y) const
Gets 3x3 Gaussian interpolated complex values note that with Gaussian interpolation,...
float get_value_at_index(size_t i) const
Get the pixel density value at index i.
float & operator()(const int ix, const int iy, const int iz) const
Overload operator() for array indexing.
void set_complex_at(const int &x, const int &y, const std::complex< float > &val)
Set complex<float> value at x,y.
void free_memory()
Free memory associated with this EMData Called in destructor and in assignment operator.
EMData * real() const
return real part of a complex image as a real image format, if this image is a real image,...
size_t get_complex_index_fast(const int &x, const int &y, const int &z) const
void mult_complex_efficient(const EMData &em, const int radius)
std::complex< float > get_complex_at(const int &x, const int &y) const
Get complex<float> value at x,y.
void subsquare(const EMData &image)
subtract the squared value of each pixel from a same-size image to this image.
EMData & operator*=(float n)
void update_min(const EMData &image)
Replaces the value of each pixel with the minimum of the current value and the value in the provided ...
void set_value_at_fast(int x, int y, int z, float v)
Set the pixel density value at coordinates (x,y,z).
EMData * phase() const
return phase part of a complex image as a real image format
void div(float f)
make each pixel value divided by a float number.
EMData * copy_head() const
Make an image with a copy of the current image's header.
std::complex< float > get_complex_at_ginterp(float x, float y) const
Gets 2x2 Gaussian interpolated complex values note that with Gaussian interpolation,...
void free_rdata()
Free rdata memory associated with this EMData Called in CUDA.
void set_col(const EMData *data, int col_index)
Set one column of a 2D image.
EMData & operator/=(float n)
bool operator==(const EMData &that) const
EMData & operator-=(float n)
EMData * get_row(int row_index) const
Get one row of a 1D/2D image.
#define OutofRangeException(low, high, input, objname)