EMAN2
Classes | Functions
a function or class that is CUDA enabled

Classes

class  EMAN::TranslationalAligner
 Translational 2D Alignment using cross correlation. More...
 
class  EMAN::RotationalAligner
 rotational alignment using angular correlation More...
 
class  EMAN::RotateTranslateAligner
 rotational, translational alignment More...
 
class  EMAN::RotateFlipAligner
 rotational and flip alignment More...
 
class  EMAN::Refine3DAlignerGrid
 Refine alignment. More...
 
class  EMAN::Refine3DAlignerQuaternion
 Refine alignment. More...
 
class  EMAN::RT3DGridAligner
 rotational and translational alignment using a square qrid of Altitude and Azimuth values (the phi range is specifiable) This aligner is ported from the original tomohunter.py - it is less efficient than searching on the sphere (RT3DSphereAligner). More...
 
class  EMAN::RT3DSphereAligner
 3D rotational and translational alignment using spherical sampling, can reduce the search space based on symmetry. More...
 
class  EMAN::RT3DSymmetryAligner
 3D rotational symmetry aligner. More...
 
class  EMAN::CccCmp
 Compute the cross-correlation coefficient between two images. More...
 
class  EMAN::DotCmp
 Use dot product of 2 same-size images to do the comparison. More...
 
class  EMAN::TomoCccCmp
 This implements the technique of Mike Schmid where by the cross correlation is normalized in an effort to remove the effects of the missing wedge. More...
 
class  EMAN::TomoFscCmp
 This is a FSC comparitor for tomography. More...
 
class  EMAN::Rotate180Processor
 Rotate by 180 using pixel swapping, works for 2D only. More...
 
class  EMAN::TransformProcessor
 Transform the image using a Transform object. More...
 
class  EMAN::IntTranslateProcessor
 Translate the image an integer amount Uses EMData::clip_inplace (inplace) and EMData::get_clip (out of place) to do the translation. More...
 
class  EMAN::StandardProjector
 Fast real-space 3D projection. More...
 
class  EMAN::FourierReconstructor
 Fourier space 3D reconstruction The Fourier reconstructor is designed to work in an iterative fashion, where similarity ("quality") metrics are used to determine if a slice should be inserted into the 3D in each subsequent iteration. More...
 

Functions

 EMAN::EMData::EMData (int nx, int ny, int nz=1, bool is_real=true)
 
 EMAN::EMData::EMData (float *data, float *cudadata, const int nx, const int ny, const int nz, const Dict &attr_dict=Dict())
 Construction from a data pointer for usage in cuda, dimensions must be supplied. More...
 
 EMAN::EMData::EMData (const EMData &that)
 Construct from an EMData (copy constructor). More...
 
EMDataEMAN::EMData::operator= (const EMData &that)
 EMData assignment operator Performs a deep copy. More...
 
EMDataEMAN::EMData::calc_ccf (EMData *with=0, fp_flag fpflag=CIRCULANT, bool center=false)
 Calculate Cross-Correlation Function (CCF). More...
 
EMDataEMAN::EMData::calc_ccfx (EMData *const with, int y0=0, int y1=-1, bool nosum=false, bool flip=false, bool usez=false)
 Calculate Cross-Correlation Function (CCF) in the x-direction and adds them up, result in 1D. More...
 
EMDataEMAN::EMData::make_rotational_footprint (bool unwrap=true)
 Makes a 'rotational footprint', which is an 'unwound' autocorrelation function. More...
 
EMDataEMAN::EMData::unwrap (int r1=-1, int r2=-1, int xs=-1, int dx=0, int dy=0, bool do360=false, bool weight_radial=true) const
 Maps to polar coordinates from Cartesian coordinates. More...
 
void insert_clip (const EMData *const block, const IntPoint &origin)
 Insert a clip into this image. More...
 

Detailed Description

Function Documentation

◆ calc_ccf()

EMData * EMData::calc_ccf ( EMData with = 0,
fp_flag  fpflag = CIRCULANT,
bool  center = false 
)

Calculate Cross-Correlation Function (CCF).

Calculate the correlation of two 1-, 2-, or 3-dimensional images. Note: this method internally just calls the correlation function from fundamentals.h.

Parameters
[in]withThe image used to calculate the CCF. If 'with' is NULL, the autocorrelation function is computed instead.
[in]fpflagSpecify how periodicity (or normalization) should be handled. See fundamentals.h The default is "CIRCULANT". for specific flags.
centerwhether or not to center the image (bring bottom left corner to center)
Returns
Real-space image.
Exceptions
ImageDimensionExceptionif nx > 1 and nx < 2*radius + 1

Definition at line 1499 of file emdata.cpp.

1500{
1501 ENTERFUNC;
1502
1503 if( with == 0 ) {
1504#ifdef EMAN2_USING_CUDA //CUDA
1505 if(EMData::usecuda == 1 && cudarwdata) {
1506 //cout << "calc ccf" << endl;
1507 EMData* ifft = 0;
1508 bool delifft = false;
1509 int offset = 0;
1510
1511 //do fft if not alreay done
1512 if(!is_complex()){
1513 ifft = do_fft_cuda();
1514 delifft = true;
1515 offset = 2 - nx%2;
1516 }else{
1517 ifft = this;
1518 }
1519 calc_conv_cuda(ifft->cudarwdata,ifft->cudarwdata,nx + offset, ny, nz); //this is the business end, results go in afft
1520
1521 EMData * conv = ifft->do_ift_cuda();
1522 if(delifft) delete ifft;
1523 conv->update();
1524
1525 return conv;
1526 }
1527#endif
1528 EXITFUNC;
1529 return convolution(this,this,fpflag, center);
1530 }
1531 else if ( with == this ){ // this if statement is not necessary, the correlation function tests to see if with == this
1532 EXITFUNC;
1533 return correlation(this, this, fpflag,center);
1534 }
1535 else {
1536
1537#ifdef EMAN2_USING_CUDA //CUDA
1538 // assume always get rw data (makes life a lot easier!!!
1539 // also assume that both images are the same size. When using CUDA we are only interested in speed, not flexibility!!
1540 // P.S. (I feel like I am pounding square pegs into a round holes with CUDA)
1541 if(EMData::usecuda == 1 && cudarwdata && with->cudarwdata) {
1542 //cout << "using CUDA for ccf" << endl;
1543 EMData* afft = 0;
1544 EMData* bfft = 0;
1545 bool delafft = false, delbfft = false;
1546 int offset = 0;
1547
1548 //do ffts if not alreay done
1549 if(!is_complex()){
1550 afft = do_fft_cuda();
1551 delafft = true;
1552 offset = 2 - nx%2;
1553 //cout << "Do cuda FFT A" << endl;
1554 }else{
1555 afft = this;
1556 }
1557 if(!with->is_complex()){
1558 bfft = with->do_fft_cuda();
1559 //cout << "Do cuda FFT B" << endl;
1560 delbfft = true;
1561 }else{
1562 bfft = with;
1563 }
1564
1565 calc_ccf_cuda(afft->cudarwdata,bfft->cudarwdata,nx + offset, ny, nz); //this is the business end, results go in afft
1566
1567 if(delbfft) delete bfft;
1568
1569 EMData * corr = afft->do_ift_cuda();
1570 if(delafft) delete afft;
1571 //cor->do_ift_inplace_cuda();//a bit faster, but I'll alos need to rearrnage the mem structure for it to work, BUT this is very SLOW.
1572 corr->update();
1573
1574 return corr;
1575 }
1576#endif
1577
1578 // If the argument EMData pointer is not the same size we automatically resize it
1579 bool undoresize = false;
1580 int wnx = with->get_xsize(); int wny = with->get_ysize(); int wnz = with->get_zsize();
1581 if (!(is_complex()^with->is_complex()) && (wnx != nx || wny != ny || wnz != nz) ) {
1582 Region r((wnx-nx)/2, (wny-ny)/2, (wnz-nz)/2,nx,ny,nz);
1583 with->clip_inplace(r);
1584 undoresize = true;
1585 }
1586
1587 EMData* cor = correlation(this, with, fpflag, center);
1588
1589 // If the argument EMData pointer was resized, it is returned to its original dimensions
1590 if ( undoresize ) {
1591 Region r((nx-wnx)/2, (ny-wny)/2,(nz-wnz)/2,wnx,wny,wnz);
1592 with->clip_inplace(r);
1593 }
1594
1595 EXITFUNC;
1596 return cor;
1597 }
1598}
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
int nx
image size
Definition: emdata.h:848
void clip_inplace(const Region &area, const float &fill_value=0)
Clip the image inplace - clipping region must be smaller than the current region internally memory is...
Definition: emdata.cpp:350
Region defines a 2D or 3D rectangular region specified by its origin coordinates and all edges' sizes...
Definition: geometry.h:497
void calc_ccf_cuda(float *afft, const float *bfft, const int nx, const int ny, const int nz)
void calc_conv_cuda(float *afft, const float *bfft, const int nx, const int ny, const int nz)
bool is_complex() const
Is this a complex image?
#define ENTERFUNC
Definition: log.h:48
#define EXITFUNC
Definition: log.h:49

References calc_ccf_cuda(), calc_conv_cuda(), EMAN::EMData::clip_inplace(), ENTERFUNC, EXITFUNC, is_complex(), EMAN::EMData::nx, EMAN::EMData::ny, and EMAN::EMData::nz.

Referenced by EMAN::EMData::calc_ccf_masked(), EMAN::EMData::calc_flcf(), EMAN::TomoCccCmp::cmp(), EMAN::EMData::make_rotational_footprint(), EMAN::RT2Dto3DTreeAligner::testort(), EMAN::RT3DTreeAligner::testort(), EMAN::RT3DGridAligner::xform_align_nbest(), EMAN::RT3DSphereAligner::xform_align_nbest(), EMAN::RT2DTreeAligner::xform_align_nbest(), EMAN::RT2Dto3DTreeAligner::xform_align_nbest(), and EMAN::RT3DTreeAligner::xform_align_nbest().

◆ calc_ccfx()

EMData * EMData::calc_ccfx ( EMData *const  with,
int  y0 = 0,
int  y1 = -1,
bool  nosum = false,
bool  flip = false,
bool  usez = false 
)

Calculate Cross-Correlation Function (CCF) in the x-direction and adds them up, result in 1D.

WARNING: this routine will modify the 'this' and 'with' to contain 1D fft's without setting some flags. This is an optimization for rotational alignment.

Parameters
withThe image used to calculate CCF.
y0Starting position in x-direction.
y1Ending position in x-direction. '-1' means the end of the row.
nosumIf true, returns an image y1-y0+1 pixels high.
usezIf true, will convert each line in the CCF stack to a Z value, indicating its relative strength as a predictor of alignment
See also
calc_ccf()
Exceptions
NullPointerExceptionIf input image 'with' is NULL.
ImageFormatExceptionIf 'with' and 'this' are not same size.
ImageDimensionExceptionIf 'this' image is 3D.
Returns
The result image containing the CCF.

Definition at line 1628 of file emdata.cpp.

1629{
1630 ENTERFUNC;
1631
1632 if (!with) {
1633 LOGERR("NULL 'with' image. ");
1634 throw NullPointerException("NULL input image");
1635 }
1636
1637 if (!EMUtil::is_same_size(this, with)) {
1638 LOGERR("images not same size: (%d,%d,%d) != (%d,%d,%d)",
1639 nx, ny, nz,
1640 with->get_xsize(), with->get_ysize(), with->get_zsize());
1641 throw ImageFormatException("images not same size");
1642 }
1643 if (get_ndim() > 2) {
1644 LOGERR("2D images only");
1645 throw ImageDimensionException("2D images only");
1646 }
1647
1648 if (y1 <= y0) {
1649 y1 = ny;
1650 }
1651
1652 if (y0 >= y1) {
1653 y0 = 0;
1654 }
1655
1656 if (y0 < 0) {
1657 y0 = 0;
1658 }
1659
1660 if (y1 > ny) {
1661 y1 = ny;
1662 }
1663 if (is_complex_x() || with->is_complex_x() ) throw; // Woops don't support this anymore!
1664
1665// static int nx_fft = 0;
1666// static int ny_fft = 0;
1667// static EMData f1;
1668// static EMData f2;
1669// static EMData rslt;
1670
1671 int height = y1-y0;
1672 int width = (nx+2-(nx%2));
1673 int wpad = ((width+3)/4)*4; // This is for 128 bit alignment of rows to prevent SSE crashes
1674
1675 EMData f1(wpad,height);
1676 EMData f2(wpad,height);
1677 EMData rslt(nx,height);
1678
1679// if (wpad != nx_fft || height != ny_fft ) { // Seems meaningless, but due to static definitions above. f1,f2 are cached to prevent multiple reallocations
1680// f1.set_size(wpad,height);
1681// f2.set_size(wpad,height);
1682// rslt.set_size(nx,height);
1683// nx_fft = wpad;
1684// ny_fft = height;
1685// }
1686
1687#ifdef EMAN2_USING_CUDA
1688 // FIXME : Not tested with new wpad change
1689 if (EMData::usecuda == 1 && cudarwdata && with->cudarwdata) {
1690 //cout << "calc_ccfx CUDA" << endl;
1691 if(!f1.cudarwdata) f1.rw_alloc();
1692 if(!f2.cudarwdata) f2.rw_alloc();
1693 if(!rslt.cudarwdata) rslt.rw_alloc();
1694 cuda_dd_fft_real_to_complex_nd(cudarwdata, f1.cudarwdata, nx, 1, 1, height);
1695 cuda_dd_fft_real_to_complex_nd(with->cudarwdata, f2.cudarwdata, nx, 1, 1, height);
1696 calc_ccf_cuda(f1.cudarwdata, f2.cudarwdata, nx, ny, nz);
1697 cuda_dd_fft_complex_to_real_nd(f1.cudarwdata, rslt.cudarwdata, nx, 1, 1, height);
1698 if(no_sum){
1699 EMData* result = new EMData(rslt);
1700 return result;
1701 }
1702 EMData* cf = new EMData(0,0,nx,1,1); //cuda constructor
1703 cf->runcuda(emdata_column_sum(rslt.cudarwdata, nx, ny));
1704 cf->update();
1705
1706 EXITFUNC;
1707 return cf;
1708 }
1709#endif
1710
1711// printf("%d %d %d\n",(int)get_attr("nx"),(int)f2.get_attr("nx"),width);
1712
1713 float *d1 = get_data();
1714 float *d2 = with->get_data();
1715 float *f1d = f1.get_data();
1716 float *f2d = f2.get_data();
1717 for (int j = 0; j < height; j++) {
1718 EMfft::real_to_complex_1d(d1 + j * nx, f1d+j*wpad, nx);
1719 EMfft::real_to_complex_1d(d2 + j * nx, f2d+j*wpad, nx);
1720 }
1721
1722 if(flip == false) {
1723 for (int j = 0; j < height; j++) {
1724 float *f1a = f1d + j * wpad;
1725 float *f2a = f2d + j * wpad;
1726
1727 for (int i = 0; i < width / 2; i++) {
1728 float re1 = f1a[2*i];
1729 float re2 = f2a[2*i];
1730 float im1 = f1a[2*i+1];
1731 float im2 = f2a[2*i+1];
1732
1733 f1d[j*wpad+i*2] = re1 * re2 + im1 * im2;
1734 f1d[j*wpad+i*2+1] = im1 * re2 - re1 * im2;
1735 }
1736 }
1737 } else {
1738 for (int j = 0; j < height; j++) {
1739 float *f1a = f1d + j * wpad;
1740 float *f2a = f2d + j * wpad;
1741
1742 for (int i = 0; i < width / 2; i++) {
1743 float re1 = f1a[2*i];
1744 float re2 = f2a[2*i];
1745 float im1 = f1a[2*i+1];
1746 float im2 = f2a[2*i+1];
1747
1748 f1d[j*wpad+i*2] = re1 * re2 - im1 * im2;
1749 f1d[j*wpad+i*2+1] = im1 * re2 + re1 * im2;
1750 }
1751 }
1752 }
1753
1754 float* rd = rslt.get_data();
1755 for (int j = y0; j < y1; j++) {
1756 EMfft::complex_to_real_1d(f1d+j*wpad, rd+j*nx, nx);
1757 }
1758
1759 // This converts the CCF values to Z values (in terms of standard deviations above the mean), on a per-row basis
1760 // The theory is that this should better weight the radii that contribute most strongly to the orientation determination
1761 if (usez) {
1762 for (int y=0; y<height; y++) {
1763 float mn=0,sg=0;
1764 for (int x=0; x<nx; x++) {
1765 mn+=rd[x+y*nx];
1766 sg+=rd[x+y*nx]*rd[x+y*nx];
1767 }
1768 mn/=(float)nx; //mean
1769 sg=std::sqrt(sg/(float)nx-mn*mn); //sigma
1770 if (sg==0) sg=1.0;
1771
1772 for (int x=0; x<nx; x++) rd[x+y*nx]=(rd[x+y*nx]-mn)/sg;
1773 }
1774 }
1775
1776 if (no_sum) {
1777 rslt.update(); // This is important in terms of the copy - the returned object won't have the correct flags unless we do this
1778 EXITFUNC;
1779 return new EMData(rslt);
1780 } else {
1781 EMData *cf = new EMData(nx,1,1);
1782 cf->to_zero();
1783 float *c = cf->get_data();
1784 for (int j = 0; j < height; j++) {
1785 for(int i = 0; i < nx; ++i) {
1786 c[i] += rd[i+j*nx];
1787 }
1788 }
1789 cf->update();
1790 EXITFUNC;
1791 return cf;
1792 }
1793}
EMData()
For all image I/O.
Definition: emdata.cpp:70
static bool is_same_size(const EMData *image1, const EMData *image2)
Check whether two EMData images are of the same size.
Definition: emutil.cpp:1224
int cuda_dd_fft_real_to_complex_nd(float *real_data, float *complex_data, int nx, int ny, int nz, int batch)
int cuda_dd_fft_complex_to_real_nd(float *complex_data, float *real_data, int nx, int ny, int nz, int batch)
float * emdata_column_sum(const float *data, const int nx, const int ny)
EMData * sqrt() const
return square root of current image
int get_ndim() const
Get image dimension.
bool is_complex_x() const
Is this image a 1D FFT image in X direction?
float * get_data() const
Get the image pixel density data in a 1D float array.
#define ImageFormatException(desc)
Definition: exception.h:147
#define ImageDimensionException(desc)
Definition: exception.h:166
#define NullPointerException(desc)
Definition: exception.h:241
#define LOGERR
Definition: log.h:51
#define y(i, j)
Definition: projector.cpp:1516
#define x(i)
Definition: projector.cpp:1517

References calc_ccf_cuda(), cuda_dd_fft_complex_to_real_nd(), cuda_dd_fft_real_to_complex_nd(), EMAN::EMData::EMData(), emdata_column_sum(), ENTERFUNC, EXITFUNC, get_data(), get_ndim(), ImageDimensionException, ImageFormatException, is_complex_x(), EMAN::EMUtil::is_same_size(), LOGERR, NullPointerException, EMAN::EMData::nx, EMAN::EMData::ny, EMAN::EMData::nz, sqrt(), x, and y.

Referenced by EMAN::RotationalAligner::align_180_ambiguous(), and EMAN::EMData::make_footprint().

◆ EMData() [1/3]

EMData::EMData ( const EMData that)

Construct from an EMData (copy constructor).

Performs a deep copy

Parameters
thatthe EMData to copy

Definition at line 134 of file emdata.cpp.

134 :
135#ifdef EMAN2_USING_CUDA
136 cudarwdata(0), cudarodata(0), num_bytes(0), nextlistitem(0), prevlistitem(0), roneedsupdate(0), cudadirtybit(0),
137#endif //EMAN2_USING_CUDA
138#ifdef FFT_CACHING
139 fftcache(0),
140#endif //FFT_CACHING
141 attr_dict(that.attr_dict), rdata(0), supp(0), flags(that.flags), changecount(that.changecount), nx(that.nx), ny(that.ny), nz(that.nz),
142 nxy(that.nx*that.ny), nxyz((size_t)that.nx*that.ny*that.nz), xoff(that.xoff), yoff(that.yoff), zoff(that.zoff),all_translation(that.all_translation), path(that.path),
143 pathnum(that.pathnum), rot_fp(0)
144{
145 ENTERFUNC;
146
147 float* data = that.rdata;
148 size_t num_bytes = (size_t)nx*ny*nz*sizeof(float);
149 if (data && num_bytes != 0)
150 {
151 rdata = (float*)EMUtil::em_malloc(num_bytes);
152 EMUtil::em_memcpy(rdata, data, num_bytes);
153 }
154#ifdef EMAN2_USING_CUDA
155 if (EMData::usecuda == 1 && num_bytes != 0 && that.cudarwdata != 0) {
156 //cout << "That copy constructor" << endl;
157 if(!rw_alloc()) throw UnexpectedBehaviorException("Bad alloc");
158 cudaError_t error = cudaMemcpy(cudarwdata,that.cudarwdata,num_bytes,cudaMemcpyDeviceToDevice);
159 if ( error != cudaSuccess ) throw UnexpectedBehaviorException("cudaMemcpy failed in EMData copy construction with error: " + string(cudaGetErrorString(error)));
160 }
161#endif //EMAN2_USING_CUDA
162
163 if (that.rot_fp != 0) rot_fp = new EMData(*(that.rot_fp));
164
166#ifdef MEMDEBUG2
167 printf("EMDATA+ %4d %p\n",EMData::totalalloc,this);
168#endif
169
170 ENTERFUNC;
171}
int pathnum
Definition: emdata.h:858
EMData * rot_fp
This is a cached rotational footprint, can save much time.
Definition: emdata.h:861
int yoff
Definition: emdata.h:851
static int totalalloc
Definition: emdata.h:803
float * supp
supplementary data array
Definition: emdata.h:837
int changecount
Definition: emdata.h:846
float * rdata
image real data
Definition: emdata.h:835
Dict attr_dict
to store all image header info
Definition: emdata.h:833
string path
Definition: emdata.h:857
int flags
CTF data All CTF data become attribute ctf(vector<float>) in attr_dict –Grant Tang.
Definition: emdata.h:844
Vec3f all_translation
translation from the original location
Definition: emdata.h:854
size_t nxyz
Definition: emdata.h:849
int xoff
array index offsets
Definition: emdata.h:851
int zoff
Definition: emdata.h:851
static void em_memcpy(void *dst, const void *const src, const size_t size)
Definition: emutil.h:384
static void * em_malloc(const size_t size)
Definition: emutil.h:366
#define UnexpectedBehaviorException(desc)
Definition: exception.h:400

References EMAN::EMUtil::em_malloc(), EMAN::EMUtil::em_memcpy(), EMAN::EMData::EMData(), ENTERFUNC, EMAN::EMData::nx, EMAN::EMData::ny, EMAN::EMData::nz, EMAN::EMData::rdata, EMAN::EMData::rot_fp, EMAN::EMData::totalalloc, and UnexpectedBehaviorException.

◆ EMData() [2/3]

EMAN::EMData::EMData ( float *  data,
float *  cudadata,
const int  nx,
const int  ny,
const int  nz,
const Dict attr_dict = Dict() 
)

Construction from a data pointer for usage in cuda, dimensions must be supplied.

Takes possession of the pointer. data pointer must be allocated using malloc!

Parameters
dataa pointer to the pixel data which is stored in memory. Takes possession
cudadataa pointer to the pixel data which is stored in cudamemory. Takes possession
nxthe number of pixels in the x direction
nythe number of pixels in the y direction
nzthe number of pixels in the z direction

◆ EMData() [3/3]

EMData::EMData ( int  nx,
int  ny,
int  nz = 1,
bool  is_real = true 
)

makes an image of the specified size, either real or complex.

For complex image, the user would specify the real-space dimensions.

Parameters
nxsize for x dimension
nysize for y dimension
nzsize for z dimension, default 1
is_realboolean to specify real(true) or complex(false) image, default real

Definition at line 221 of file emdata.cpp.

221 :
222#ifdef EMAN2_USING_CUDA
223 cudarwdata(0), cudarodata(0), num_bytes(0), nextlistitem(0), prevlistitem(0), roneedsupdate(0), cudadirtybit(0),
224#endif //EMAN2_USING_CUDA
225#ifdef FFT_CACHING
226 fftcache(0),
227#endif //FFT_CACHING
228 attr_dict(), rdata(0), supp(0), flags(0), changecount(0), nx(0), ny(0), nz(0), nxy(0), nxyz(0), xoff(0), yoff(0), zoff(0),
229 all_translation(), path(""), pathnum(0), rot_fp(0)
230{
231 ENTERFUNC;
232
233 // used to replace cube 'pixel'
234 attr_dict["apix_x"] = 1.0f;
235 attr_dict["apix_y"] = 1.0f;
236 attr_dict["apix_z"] = 1.0f;
237
238 if(is_real) { // create a real image [nx, ny, nz]
239 attr_dict["is_complex"] = int(0);
240 attr_dict["is_complex_x"] = int(0);
241 attr_dict["is_complex_ri"] = int(1);
242 set_size(nx, ny, nz);
243 }
244 else { //create a complex image which real dimension is [ny, ny, nz]
245 int new_nx = nx + 2 - nx%2;
246 set_size(new_nx, ny, nz);
247
248 attr_dict["is_complex"] = int(1);
249
250 if(ny==1 && nz ==1) {
251 attr_dict["is_complex_x"] = int(1);
252 }
253 else {
254 attr_dict["is_complex_x"] = int(0);
255 }
256
257 attr_dict["is_complex_ri"] = int(1);
258 attr_dict["is_fftpad"] = int(1);
259
260 if(nx%2 == 1) {
261 attr_dict["is_fftodd"] = 1;
262 }
263 }
264
265 this->to_zero();
266 update();
268#ifdef MEMDEBUG2
269 printf("EMDATA+ %4d %p\n",EMData::totalalloc,this);
270#endif
271
272 EXITFUNC;
273}
void to_zero()
Set all the pixel value = 0.
bool is_real() const
Is this a real image?
void set_size(int nx, int ny=1, int nz=1, bool noalloc=false)
Resize this EMData's main board memory pointer.
void update()
Mark EMData as changed, statistics, etc will be updated at need.

References EMAN::EMData::attr_dict, ENTERFUNC, EXITFUNC, is_real(), EMAN::EMData::nx, EMAN::EMData::ny, EMAN::EMData::nz, set_size(), to_zero(), EMAN::EMData::totalalloc, and update().

◆ insert_clip()

void insert_clip ( const EMData *const  block,
const IntPoint &  origin 
)

Insert a clip into this image.

Very robust clip insertion code works in all way you might think possible

Parameters
blockAn image block.
originThe origin location to insert the clip. ( )

◆ make_rotational_footprint()

EMData * EMData::make_rotational_footprint ( bool  unwrap = true)

Makes a 'rotational footprint', which is an 'unwound' autocorrelation function.

generally the image should be edge-normalized and masked before using this.

Parameters
unwrapRFP undergoes polar->cartesian x-form
Exceptions
ImageFormatExceptionIf image size is not even.
Returns
The rotaional footprint image.

Definition at line 1862 of file emdata.cpp.

1862 {
1863 ENTERFUNC;
1864 update_stat();
1865 // Note that rotational_footprint caching saves a large amount of time
1866 // but this is at the expense of memory. Note that a policy is hardcoded here,
1867 // that is that caching is only employed when premasked is false and unwrap
1868 // is true - this is probably going to be what is used in most scenarios
1869 // as advised by Steve Ludtke - In terms of performance this caching doubles the metric
1870 // generated by e2speedtest.
1871 if ( rot_fp != 0 && unwrap == true) {
1872 return new EMData(*rot_fp);
1873 }
1874
1875 EMData* ccf = this->calc_ccf(this,CIRCULANT,true);
1876// EMData* ccf = this->calc_ccf(this,PADDED,true); # this would probably be a bit better, but takes 4x longer :^/
1877 ccf->sub(ccf->get_edge_mean());
1878 //ccf->process_inplace("xform.phaseorigin.tocenter"); ccf did the centering
1879 EMData *result = ccf->unwrap();
1880 delete ccf; ccf = 0;
1881
1882 EXITFUNC;
1883 if ( unwrap == true)
1884 { // this if statement reflects a strict policy of caching in only one scenario see comments at beginning of function block
1885
1886// Note that the if statement at the beginning of this function ensures that rot_fp is not zero, so there is no need
1887// to throw any exception
1888// if ( rot_fp != 0 ) throw UnexpectedBehaviorException("The rotational foot print is only expected to be cached if it is not NULL");
1889
1890// Here is where the caching occurs - the rot_fp takes ownsherhip of the pointer, and a deep copied EMData object is returned.
1891// The deep copy invokes a cost in terms of CPU cycles and memory, but prevents the need for complicated memory management (reference counting)
1892 rot_fp = result;
1893 return new EMData(*rot_fp);
1894 }
1895 else return result;
1896}
void update_stat() const
Definition: emdata.cpp:3091
EMData * calc_ccf(EMData *with=0, fp_flag fpflag=CIRCULANT, bool center=false)
Calculate Cross-Correlation Function (CCF).
Definition: emdata.cpp:1499
EMData * unwrap(int r1=-1, int r2=-1, int xs=-1, int dx=0, int dy=0, bool do360=false, bool weight_radial=true) const
Maps to polar coordinates from Cartesian coordinates.
Definition: emdata.cpp:2596

References EMAN::EMData::calc_ccf(), EMAN::EMData::EMData(), ENTERFUNC, EXITFUNC, EMAN::EMData::rot_fp, EMAN::EMData::unwrap(), and EMAN::EMData::update_stat().

Referenced by EMAN::RotationalAligner::align_180_ambiguous().

◆ operator=()

EMData & EMData::operator= ( const EMData that)

EMData assignment operator Performs a deep copy.

Parameters
thatthe EMData to copy

Definition at line 173 of file emdata.cpp.

174{
175 ENTERFUNC;
176
177 if ( this != &that )
178 {
179 free_memory(); // Free memory sets nx,ny and nz to 0
180
181 // Only copy the rdata if it exists, we could be in a scenario where only the header has been read
182 float* data = that.rdata;
183 size_t num_bytes = that.nx*that.ny*that.nz*sizeof(float);
184 if (data && num_bytes != 0)
185 {
186 nx = 1; // This prevents a memset in set_size
187 set_size(that.nx,that.ny,that.nz);
188 EMUtil::em_memcpy(rdata, data, num_bytes);
189 }
190
191 flags = that.flags;
192
194
195 path = that.path;
196 pathnum = that.pathnum;
197 attr_dict = that.attr_dict;
198
199 xoff = that.xoff;
200 yoff = that.yoff;
201 zoff = that.zoff;
202
203#ifdef EMAN2_USING_CUDA
204 if (EMData::usecuda == 1 && num_bytes != 0 && that.cudarwdata != 0) {
205 if(cudarwdata){rw_free();}
206 if(!rw_alloc()) throw UnexpectedBehaviorException("Bad alloc");;
207 cudaError_t error = cudaMemcpy(cudarwdata,that.cudarwdata,num_bytes,cudaMemcpyDeviceToDevice);
208 if ( error != cudaSuccess ) throw UnexpectedBehaviorException("cudaMemcpy failed in EMData copy construction with error: " + string(cudaGetErrorString(error)));
209 }
210#endif //EMAN2_USING_CUDA
211
213
214 if (that.rot_fp != 0) rot_fp = new EMData(*(that.rot_fp));
215 else rot_fp = 0;
216 }
217 EXITFUNC;
218 return *this;
219}
void free_memory()
Free memory associated with this EMData Called in destructor and in assignment operator.

References EMAN::EMData::all_translation, EMAN::EMData::attr_dict, EMAN::EMData::changecount, EMAN::EMUtil::em_memcpy(), EMAN::EMData::EMData(), ENTERFUNC, EXITFUNC, EMAN::EMData::flags, free_memory(), EMAN::EMData::nx, EMAN::EMData::ny, EMAN::EMData::nz, EMAN::EMData::path, EMAN::EMData::pathnum, EMAN::EMData::rdata, EMAN::EMData::rot_fp, set_size(), UnexpectedBehaviorException, EMAN::EMData::xoff, EMAN::EMData::yoff, and EMAN::EMData::zoff.

◆ unwrap()

EMData * EMData::unwrap ( int  r1 = -1,
int  r2 = -1,
int  xs = -1,
int  dx = 0,
int  dy = 0,
bool  do360 = false,
bool  weight_radial = true 
) const

Maps to polar coordinates from Cartesian coordinates.

Optionaly radially weighted. When used with RFP, this provides roughly 1 pixel accuracy at 50% radius. 2D only.

Parameters
r1inner ring (all rings less than r1 are discarded) Default = 4
r2outer ring (all rings > r2 are discarded) Default = ny/2 - 2 - floor(hyp(dx,dy))
xsNumber of angular bins. Default = (2 if do360) PI * ny/4 - xs % 8
dxorigin offset in x
dyorigin offest in y
do360If true, do 0-360 degree mapping. Otherwise, do 0-180 degree mapping.
weight_radialif true (default) reights the pixel value by its radius
Exceptions
ImageDimensionExceptionIf 'this' image is not 2D.
UnexpectedBehaviorExceptionif the dimension of this image and the function arguments are incompatibale - i.e. the return image is less than 0 in some dimension.
Returns
The image in Cartesian coordinates.

Definition at line 2596 of file emdata.cpp.

2597{
2598 ENTERFUNC;
2599
2600 if (get_ndim() != 2) {
2601 throw ImageDimensionException("2D image only");
2602 }
2603
2604 int p = 1;
2605 if (do360) {
2606 p = 2;
2607 }
2608
2609 if (xs < 1) {
2610 xs = (int) Util::fast_floor(p * M_PI * ny / 3.0);
2611 xs-=xs%4; // 128 bit alignment, though best_fft_size may override
2612 xs = Util::calc_best_fft_size(xs);
2613 if (xs<=8) xs=16;
2614 }
2615
2616 if (r1 < 0) {
2617 r1 = 4;
2618 }
2619
2620 int rr = ny / 2 - 2 - (int) Util::fast_floor((float)(hypot(dx, dy)));
2621 rr-=rr%2;
2622 if (r2 <= r1 || r2 > rr) {
2623 r2 = rr;
2624 }
2625
2626 if ( (r2-r1) < 0 ) throw UnexpectedBehaviorException("The combination of function the arguments and the image dimensions causes unexpected behavior internally. Use a larger image, or a smaller value of r1, or a combination of both");
2627
2628#ifdef EMAN2_USING_CUDA
2629 if (EMData::usecuda == 1 && isrodataongpu()){
2630 //cout << " CUDA unwrap" << endl;
2631 EMData* result = new EMData(0,0,xs,(r2-r1),1);
2632 if(!result->rw_alloc()) throw UnexpectedBehaviorException("Bad alloc");
2633 bindcudaarrayA(true);
2634 emdata_unwrap(result->cudarwdata, r1, r2, xs, p, dx, dy, weight_radial, nx, ny);
2635 unbindcudaarryA();
2636 result->update();
2637 return result;
2638 }
2639#endif
2640
2641 EMData *ret = new EMData();
2642 ret->set_size(xs, r2 - r1, 1);
2643 const float *const d = get_const_data();
2644 float *dd = ret->get_data();
2645 float pfac = (float)p/(float)xs;
2646 int nxon2 = nx/2;
2647 int nyon2 = ny/2;
2648 for (int x = 0; x < xs; x++) {
2649 float ang = x * M_PI * pfac;
2650 float si = sin(ang);
2651 float co = cos(ang);
2652
2653 for (int y = 0; y < r2 - r1; y++) {
2654 float ypr1 = (float)y + r1;
2655 float xx = ypr1 * co + nxon2 + dx;
2656 float yy = ypr1 * si + nyon2 + dy;
2657// float t = xx - Util::fast_floor(xx);
2658// float u = yy - Util::fast_floor(yy);
2659 float t = xx - (int)xx;
2660 float u = yy - (int)yy;
2661// int k = (int) Util::fast_floor(xx) + (int) (Util::fast_floor(yy)) * nx;
2662 int k = (int) xx + ((int) yy) * nx;
2663 float val = Util::bilinear_interpolate(d[k], d[k + 1], d[k + nx], d[k + nx+1], t,u);
2664 if (weight_radial) val *= ypr1;
2665 dd[x + y * xs] = val;
2666 }
2667
2668 }
2669 ret->update();
2670
2671 EXITFUNC;
2672 return ret;
2673}
static int fast_floor(float x)
A fast way to calculate a floor, which is largest integral value not greater than argument.
Definition: util.h:874
static int calc_best_fft_size(int low)
Search the best FFT size with good primes.
Definition: util.cpp:1021
static float bilinear_interpolate(float p1, float p2, float p3, float p4, float t, float u)
Calculate bilinear interpolation.
Definition: util.h:543
void emdata_unwrap(float *data, int r1, int r2, int xs, int num_pi, int dx, int dy, int weight_radial, int nx, int ny)
const float * get_const_data() const
Get the image pixel density data in a 1D float array - const version of get_data.

References EMAN::Util::bilinear_interpolate(), EMAN::Util::calc_best_fft_size(), EMAN::EMData::EMData(), emdata_unwrap(), ENTERFUNC, EXITFUNC, EMAN::Util::fast_floor(), get_const_data(), get_ndim(), ImageDimensionException, EMAN::EMData::nx, EMAN::EMData::ny, UnexpectedBehaviorException, x, and y.

Referenced by EMAN::EMData::make_rotational_footprint(), EMAN::EMData::make_rotational_footprint_cmc(), and EMAN::EMData::make_rotational_footprint_e1().