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::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

void EMAN::EMData::insert_clip (const EMData *const block, const IntPoint &origin)
 Insert a clip into this image.
 EMAN::EMData::EMData (int nx, int ny, int nz=1, bool is_real=true)
 # makes an image of the specified size, either real or complex.
 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.
 EMAN::EMData::EMData (const EMData &that)
 Construct from an EMData (copy constructor).
EMDataEMAN::EMData::operator= (const EMData &that)
 EMData assignment operator Performs a deep copy.
EMDataEMAN::EMData::calc_ccf (EMData *with, fp_flag fpflag=CIRCULANT, bool center=false)
 Calculate Cross-Correlation Function (CCF).
EMDataEMAN::EMData::calc_ccfx (EMData *const with, int y0=0, int y1=-1, bool nosum=false, bool flip=false)
 Calculate Cross-Correlation Function (CCF) in the x-direction and adds them up, result in 1D.
EMDataEMAN::EMData::make_rotational_footprint (bool unwrap=true)
 Makes a 'rotational footprint', which is an 'unwound' autocorrelation function.
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.
void insert_clip (const EMData *const block, const IntPoint &origin)
 Insert a clip into this image.

Function Documentation

EMData * EMData::calc_ccf ( EMData with,
fp_flag  fpflag = CIRCULANT,
bool  center = false 
) [inherited]

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] with The image used to calculate the CCF. If 'with' is NULL, the autocorrelation function is computed instead.
[in] fpflag Specify how periodicity (or normalization) should be handled. See fundamentals.h The default is "CIRCULANT". for specific flags.
center whether or not to center the image (bring bottom left corner to center)
Returns:
Real-space image.
Exceptions:
ImageDimensionException if nx > 1 and nx < 2*radius + 1

Definition at line 1464 of file emdata.cpp.

References calc_ccf_cuda(), EMAN::EMData::clip_inplace(), EMAN::convolution(), EMAN::correlation(), ENTERFUNC, EXITFUNC, EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::EMData::is_complex(), EMAN::EMData::nx, EMAN::EMData::ny, and EMAN::EMData::nz.

Referenced by EMAN::Refine3DAlignerGrid::align(), EMAN::TranslationalAligner::align(), EMAN::EMData::calc_flcf(), EMAN::TomoCccCmp::cmp(), EMAN::EMData::make_rotational_footprint(), EMAN::RT3DSphereAligner::xform_align_nbest(), and EMAN::RT3DGridAligner::xform_align_nbest().

01465 {
01466         ENTERFUNC;
01467         if( with == 0 ) {
01468                 EXITFUNC;
01469                 return convolution(this,this,fpflag, center);
01470         }
01471         else if ( with == this ){ // this if statement is not necessary, the correlation function tests to see if with == this
01472                 EXITFUNC;
01473                 return correlation(this, this, fpflag,center);
01474         }
01475         else {
01476 
01477 #ifdef EMAN2_USING_CUDA //CUDA 
01478                 // assume always get rw data (makes life a lot easier!!! 
01479                 // also assume that both images are the same size. When using CUDA we are only interested in speed, not flexibility!!
01480                 // P.S. (I feel like I am pounding square pegs into a round holes with CUDA)
01481                 if(cudarwdata && with->cudarwdata) {
01482                         //cout << "using CUDA for ccf" << endl;
01483                         EMData* afft = 0;
01484                         EMData* bfft = 0;
01485                         bool delafft = false, delbfft = false;
01486                         int offset = 0;
01487                         
01488                         //do ffts if not alreay done
01489                         if(!is_complex()){
01490                                 afft = do_fft_cuda();
01491                                 delafft = true;
01492                                 offset = 2 - nx%2;
01493                                 //cout << "Do cuda FFT A" << endl;
01494                         }else{
01495                                 afft = this;
01496                         }
01497                         if(!with->is_complex()){
01498                                 bfft = with->do_fft_cuda();
01499                                 //cout << "Do cuda FFT B" << endl;
01500                                 delbfft = true;
01501                         }else{
01502                                 bfft = with;
01503                         }
01504 
01505                         calc_ccf_cuda(afft->cudarwdata,bfft->cudarwdata,nx + offset, ny, nz); //this is the business end, results go in afft
01506                         
01507                         if(delbfft) delete bfft;
01508                         
01509                         EMData * corr = afft->do_ift_cuda();
01510                         if(delafft) delete afft;
01511                         //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.
01512                         
01513                         return corr;
01514                 }
01515 #endif
01516                 
01517                 // If the argument EMData pointer is not the same size we automatically resize it
01518                 bool undoresize = false;
01519                 int wnx = with->get_xsize(); int wny = with->get_ysize(); int wnz = with->get_zsize(); // obviously is one image is complex and the other real they won't be the same size and we DONT! want to clip JFF
01520                 if (!(is_complex() ^ with->is_complex()) && (wnx != nx || wny != ny || wnz != nz)) {
01521                         cout << "Warning!!! resizing image before CCF calculation" << endl;
01522                         Region r((wnx-nx)/2, (wny-ny)/2, (wnz-nz)/2,nx,ny,nz);
01523                         with->clip_inplace(r);
01524                         undoresize = true;
01525                 }
01526 
01527                 EMData* cor = correlation(this, with, fpflag, center);
01528 
01529                 // If the argument EMData pointer was resized, it is returned to its original dimensions
01530                 if ( undoresize ) {
01531                         Region r((nx-wnx)/2, (ny-wny)/2,(nz-wnz)/2,wnx,wny,wnz);
01532                         with->clip_inplace(r);
01533                 }
01534 
01535                 EXITFUNC;
01536                 return cor;
01537         }
01538 }

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

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:
with The image used to calculate CCF.
y0 Starting position in x-direction.
y1 Ending position in x-direction. '-1' means the end of the row.
nosum If true, returns an image y1-y0+1 pixels high.
See also:
calc_ccf()
Exceptions:
NullPointerException If input image 'with' is NULL.
ImageFormatException If 'with' and 'this' are not same size.
ImageDimensionException If 'this' image is 3D.
Returns:
The result image containing the CCF.

Definition at line 1540 of file emdata.cpp.

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, EMAN::EMData::get_data(), EMAN::EMData::get_ndim(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, ImageFormatException, EMAN::EMData::is_complex_x(), EMAN::EMUtil::is_same_size(), LOGERR, NullPointerException, EMAN::EMData::nx, EMAN::EMData::ny, EMAN::EMData::nz, EMAN::EMData::set_size(), EMAN::EMData::to_zero(), and EMAN::EMData::update().

Referenced by EMAN::RTFExhaustiveAligner::align(), EMAN::RotateTranslateFlipAlignerPawel::align(), EMAN::RotateTranslateAlignerPawel::align(), EMAN::RotationalAlignerIterative::align(), EMAN::RotatePrecenterAligner::align(), EMAN::RotationalAligner::align_180_ambiguous(), and EMAN::EMData::make_footprint().

01541 {
01542         ENTERFUNC;
01543 
01544         if (!with) {
01545                 LOGERR("NULL 'with' image. ");
01546                 throw NullPointerException("NULL input image");
01547         }
01548 
01549         if (!EMUtil::is_same_size(this, with)) {
01550                 LOGERR("images not same size: (%d,%d,%d) != (%d,%d,%d)",
01551                            nx, ny, nz,
01552                            with->get_xsize(), with->get_ysize(), with->get_zsize());
01553                 throw ImageFormatException("images not same size");
01554         }
01555         if (get_ndim() > 2) {
01556                 LOGERR("2D images only");
01557                 throw ImageDimensionException("2D images only");
01558         }
01559 
01560         if (y1 <= y0) {
01561                 y1 = ny;
01562         }
01563 
01564         if (y0 >= y1) {
01565                 y0 = 0;
01566         }
01567 
01568         if (y0 < 0) {
01569                 y0 = 0;
01570         }
01571 
01572         if (y1 > ny) {
01573                 y1 = ny;
01574         }
01575         if (is_complex_x() || with->is_complex_x() ) throw; // Woops don't support this anymore!
01576 
01577         static int nx_fft = 0;
01578         static int ny_fft = 0;
01579         static EMData f1;
01580         static EMData f2;
01581         static EMData rslt;
01582 
01583         int height = y1-y0;
01584         int width = (nx+2-(nx%2));
01585         if (width != nx_fft || height != ny_fft ) {
01586                 f1.set_size(width,height);
01587                 f2.set_size(width,height);
01588                 rslt.set_size(nx,height);
01589                 nx_fft = width;
01590                 ny_fft = height;
01591         }
01592 
01593 #ifdef EMAN2_USING_CUDA
01594         if (cudarwdata && with->cudarwdata) {
01595                 //cout << "calc_ccfx CUDA" << endl;
01596                 if(!f1.cudarwdata) f1.rw_alloc();
01597                 if(!f2.cudarwdata) f2.rw_alloc();
01598                 if(!rslt.cudarwdata) rslt.rw_alloc();
01599                 cuda_dd_fft_real_to_complex_nd(cudarwdata, f1.cudarwdata, nx, 1, 1, height);
01600                 cuda_dd_fft_real_to_complex_nd(with->cudarwdata, f2.cudarwdata, nx, 1, 1, height);
01601                 calc_ccf_cuda(f1.cudarwdata, f2.cudarwdata, nx, ny, nz);
01602                 cuda_dd_fft_complex_to_real_nd(f1.cudarwdata, rslt.cudarwdata, nx, 1, 1, height);
01603                 if(no_sum){
01604                         EMData* result = new EMData(rslt);
01605                         return result;
01606                 }
01607                 EMData* cf = new EMData(0,0,nx,1,1); //cuda constructor
01608                 cf->runcuda(emdata_column_sum(rslt.cudarwdata, nx, ny));
01609 
01610                 EXITFUNC;
01611                 return cf;
01612         }
01613 #endif
01614 
01615         float *d1 = get_data();
01616         float *d2 = with->get_data();
01617         float *f1d = f1.get_data();
01618         float *f2d = f2.get_data();
01619         for (int j = 0; j < height; j++) {
01620                 EMfft::real_to_complex_1d(d1 + j * nx, f1d+j*width, nx);
01621                 EMfft::real_to_complex_1d(d2 + j * nx, f2d+j*width, nx);
01622         }
01623 
01624         if(flip == false) {
01625                 for (int j = 0; j < height; j++) {
01626                         float *f1a = f1d + j * width;
01627                         float *f2a = f2d + j * width;
01628 
01629                         for (int i = 0; i < width / 2; i++) {
01630                                 float re1 = f1a[2*i];
01631                                 float re2 = f2a[2*i];
01632                                 float im1 = f1a[2*i+1];
01633                                 float im2 = f2a[2*i+1];
01634 
01635                                 f1d[j*width+i*2] = re1 * re2 + im1 * im2;
01636                                 f1d[j*width+i*2+1] = im1 * re2 - re1 * im2;
01637                         }
01638                 }
01639         } else {
01640                 for (int j = 0; j < height; j++) {
01641                         float *f1a = f1d + j * width;
01642                         float *f2a = f2d + j * width;
01643 
01644                         for (int i = 0; i < width / 2; i++) {
01645                                 float re1 = f1a[2*i];
01646                                 float re2 = f2a[2*i];
01647                                 float im1 = f1a[2*i+1];
01648                                 float im2 = f2a[2*i+1];
01649 
01650                                 f1d[j*width+i*2] = re1 * re2 - im1 * im2;
01651                                 f1d[j*width+i*2+1] = im1 * re2 + re1 * im2;
01652                         }
01653                 }
01654         }
01655 
01656         float* rd = rslt.get_data();
01657         for (int j = y0; j < y1; j++) {
01658                 EMfft::complex_to_real_1d(f1d+j*width, rd+j*nx, nx);
01659         }
01660 
01661         if (no_sum) {
01662                 rslt.update(); // This is important in terms of the copy - the returned object won't have the correct flags unless we do this
01663                 EXITFUNC;
01664                 return new EMData(rslt);
01665         } else {
01666                 EMData *cf = new EMData(nx,1,1);
01667                 cf->to_zero();
01668                 float *c = cf->get_data();
01669                 for (int j = 0; j < height; j++) {
01670                         for(int i = 0; i < nx; ++i) {
01671                                 c[i] += rd[i+j*nx];
01672                         }
01673                 }
01674                 cf->update();
01675                 EXITFUNC;
01676                 return cf;
01677         }
01678 }

EMData::EMData ( const EMData that  )  [inherited]

Construct from an EMData (copy constructor).

Performs a deep copy

Parameters:
that the EMData to copy

Definition at line 131 of file emdata.cpp.

References data, 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.

00131                                  :
00132 #ifdef EMAN2_USING_CUDA
00133                 cudarwdata(0), cudarodata(0), num_bytes(0), nextlistitem(0), prevlistitem(0), roneedsupdate(0),
00134 #endif //EMAN2_USING_CUDA
00135                 attr_dict(that.attr_dict), rdata(0), supp(0), flags(that.flags), changecount(that.changecount), nx(that.nx), ny(that.ny), nz(that.nz),
00136                 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),
00137                 pathnum(that.pathnum), rot_fp(0)
00138 {
00139         ENTERFUNC;
00140         
00141         float* data = that.rdata;
00142         size_t num_bytes = (size_t)nx*ny*nz*sizeof(float);
00143         if (data && num_bytes != 0)
00144         {
00145                 rdata = (float*)EMUtil::em_malloc(num_bytes);
00146                 EMUtil::em_memcpy(rdata, data, num_bytes);
00147         }
00148 #ifdef EMAN2_USING_CUDA
00149         if (num_bytes != 0 && that.cudarwdata != 0) {
00150                 //cout << "That copy constructor" << endl;
00151                 rw_alloc();
00152                 cudaError_t error = cudaMemcpy(cudarwdata,that.cudarwdata,num_bytes,cudaMemcpyDeviceToDevice);
00153                 if ( error != cudaSuccess ) throw UnexpectedBehaviorException("cudaMemcpy failed in EMData copy construction with error: " + string(cudaGetErrorString(error)));
00154         }
00155 #endif //EMAN2_USING_CUDA
00156 
00157         if (that.rot_fp != 0) rot_fp = new EMData(*(that.rot_fp));
00158 
00159         EMData::totalalloc++;
00160 #ifdef MEMDEBUG2
00161         printf("EMDATA+  %4d    %p\n",EMData::totalalloc,this);
00162 #endif
00163 
00164         ENTERFUNC;
00165 }

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

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:
data a pointer to the pixel data which is stored in memory. Takes possession
cudadata a pointer to the pixel data which is stored in cudamemory. Takes possession
nx the number of pixels in the x direction
ny the number of pixels in the y direction
nz the number of pixels in the z direction

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

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

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

Parameters:
nx size for x dimension
ny size for y dimension
nz size for z dimension, default 1
is_real boolean to specify real(true) or complex(false) image, default real

Definition at line 216 of file emdata.cpp.

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

00216                                                    :
00217 #ifdef EMAN2_USING_CUDA
00218                 cudarwdata(0), cudarodata(0), num_bytes(0), nextlistitem(0), prevlistitem(0), roneedsupdate(0),
00219 #endif //EMAN2_USING_CUDA
00220                 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),
00221                 all_translation(),      path(""), pathnum(0), rot_fp(0)
00222 {
00223         ENTERFUNC;
00224 
00225         // used to replace cube 'pixel'
00226         attr_dict["apix_x"] = 1.0f;
00227         attr_dict["apix_y"] = 1.0f;
00228         attr_dict["apix_z"] = 1.0f;
00229 
00230         if(is_real) {   // create a real image [nx, ny, nz]
00231                 attr_dict["is_complex"] = int(0);
00232                 attr_dict["is_complex_x"] = int(0);
00233                 attr_dict["is_complex_ri"] = int(1);
00234                 set_size(nx, ny, nz);
00235         }
00236         else {  //create a complex image which real dimension is [ny, ny, nz]
00237                 int new_nx = nx + 2 - nx%2;
00238                 set_size(new_nx, ny, nz);
00239 
00240                 attr_dict["is_complex"] = int(1);
00241 
00242                 if(ny==1 && nz ==1)     {
00243                         attr_dict["is_complex_x"] = int(1);
00244                 }
00245                 else {
00246                         attr_dict["is_complex_x"] = int(0);
00247                 }
00248 
00249                 attr_dict["is_complex_ri"] = int(1);
00250                 attr_dict["is_fftpad"] = int(1);
00251 
00252                 if(nx%2 == 1) {
00253                         attr_dict["is_fftodd"] = 1;
00254                 }
00255         }
00256 
00257         this->to_zero();
00258         update();
00259         EMData::totalalloc++;
00260 #ifdef MEMDEBUG2
00261         printf("EMDATA+  %4d    %p\n",EMData::totalalloc,this);
00262 #endif
00263 
00264         EXITFUNC;
00265 }

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:
block An image block.
origin The origin location to insert the clip. ( )

void EMData::insert_clip ( const EMData *const   block,
const IntPoint origin 
) [inherited]

Insert a clip into this image.

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

Parameters:
block An image block.
origin The origin location to insert the clip. ( )

Definition at line 1775 of file emdata_transform.cpp.

References EMAN::EMUtil::em_memcpy(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::EMData::nx, EMAN::EMData::ny, EMAN::EMData::nz, EMAN::Region::origin, and EMAN::Region::size.

Referenced by EMAN::EMData::get_clip(), and EMAN::EMData::make_rotational_footprint_e1().

01775                                                                            {
01776         int nx1 = block->get_xsize();
01777         int ny1 = block->get_ysize();
01778         int nz1 = block->get_zsize();
01779 
01780         Region area(origin[0], origin[1], origin[2],nx1, ny1, nz1);
01781 
01782         //make sure the block fits in EMData 
01783         int x0 = (int) area.origin[0];
01784         x0 = x0 < 0 ? 0 : x0;
01785 
01786         int y0 = (int) area.origin[1];
01787         y0 = y0 < 0 ? 0 : y0;
01788 
01789         int z0 = (int) area.origin[2];
01790         z0 = z0 < 0 ? 0 : z0;
01791 
01792         int x1 = (int) (area.origin[0] + area.size[0]);
01793         x1 = x1 > nx ? nx : x1;
01794 
01795         int y1 = (int) (area.origin[1] + area.size[1]);
01796         y1 = y1 > ny ? ny : y1;
01797 
01798         int z1 = (int) (area.origin[2] + area.size[2]);
01799         z1 = z1 > nz ? nz : z1;
01800         if (z1 <= 0) {
01801                 z1 = 1;
01802         }
01803 
01804         int xd0 = (int) (area.origin[0] < 0 ? -area.origin[0] : 0);
01805         int yd0 = (int) (area.origin[1] < 0 ? -area.origin[1] : 0);
01806         int zd0 = (int) (area.origin[2] < 0 ? -area.origin[2] : 0);
01807 
01808         if (x1 < x0 || y1 < y0 || z1 < z0) return; // out of bounds, this is fine, nothing happens
01809 
01810         size_t clipped_row_size = (x1-x0) * sizeof(float);
01811         int src_secsize =  nx1 * ny1;
01812         int dst_secsize = nx * ny;
01813 
01814 /*
01815 #ifdef EMAN2_USING_CUDA
01816         if(block->cudarwdata){
01817                 // this is VERY slow.....
01818                 float *cudasrc = block->cudarwdata + zd0 * src_secsize + yd0 * nx1 + xd0;
01819                 if(!cudarwdata) rw_alloc();
01820                 float *cudadst = cudarwdata + z0 * dst_secsize + y0 * nx + x0;
01821                 for (int i = z0; i < z1; i++) {
01822                         for (int j = y0; j < y1; j++) {
01823                                 //printf("%x %x %d\n", cudadst, cudasrc, clipped_row_size);
01824                                 cudaMemcpy(cudadst,cudasrc,clipped_row_size,cudaMemcpyDeviceToDevice);
01825                                 cudasrc += nx1;
01826                                 cudadst += nx;
01827                         }
01828                         cudasrc += src_gap;
01829                         cudadst += dst_gap;
01830                 }
01831                 return;
01832         }
01833 #endif
01834 */
01835         float *src = block->get_data() + zd0 * src_secsize + yd0 * nx1 + xd0;
01836         float *dst = get_data() + z0 * dst_secsize + y0 * nx + x0;
01837         
01838         int src_gap = src_secsize - (y1-y0) * nx1;
01839         int dst_gap = dst_secsize - (y1-y0) * nx;
01840         
01841         for (int i = z0; i < z1; i++) {
01842                 for (int j = y0; j < y1; j++) {
01843                         EMUtil::em_memcpy(dst, src, clipped_row_size);
01844                         src += nx1;
01845                         dst += nx;
01846                 }
01847                 src += src_gap;
01848                 dst += dst_gap;
01849         }
01850         
01851 #ifdef EMAN2_USING_CUDA 
01852         if(block->cudarwdata){
01853                 copy_to_cuda(); // copy back to device as padding is faster on the host
01854         }
01855 #endif
01856 
01857         update();
01858         EXITFUNC;
01859 }

EMData * EMData::make_rotational_footprint ( bool  unwrap = true  )  [inherited]

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

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

Parameters:
unwrap RFP undergoes polar->cartesian x-form
Exceptions:
ImageFormatException If image size is not even.
Returns:
The rotaional footprint image.

Definition at line 1732 of file emdata.cpp.

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

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

01732                                                       {
01733         ENTERFUNC;
01734         update_stat();
01735         // Note that rotational_footprint caching saves a large amount of time
01736         // but this is at the expense of memory. Note that a policy is hardcoded here,
01737         // that is that caching is only employed when premasked is false and unwrap
01738         // is true - this is probably going to be what is used in most scenarios
01739         // as advised by Steve Ludtke - In terms of performance this caching doubles the metric
01740         // generated by e2speedtest.
01741         if ( rot_fp != 0 && unwrap == true) {
01742                 return new EMData(*rot_fp);
01743         }
01744 
01745         EMData* ccf = this->calc_ccf(this,CIRCULANT,true);
01746         ccf->sub(ccf->get_edge_mean());
01747         //ccf->process_inplace("xform.phaseorigin.tocenter"); ccf did the centering
01748         EMData *result = ccf->unwrap();
01749         delete ccf; ccf = 0;
01750 
01751         EXITFUNC;
01752         if ( unwrap == true)
01753         { // this if statement reflects a strict policy of caching in only one scenario see comments at beginning of function block
01754 
01755 // Note that the if statement at the beginning of this function ensures that rot_fp is not zero, so there is no need
01756 // to throw any exception
01757 // if ( rot_fp != 0 ) throw UnexpectedBehaviorException("The rotational foot print is only expected to be cached if it is not NULL");
01758 
01759 // Here is where the caching occurs - the rot_fp takes ownsherhip of the pointer, and a deep copied EMData object is returned.
01760 // The deep copy invokes a cost in terms of CPU cycles and memory, but prevents the need for complicated memory management (reference counting)
01761                 rot_fp = result;
01762                 return new EMData(*rot_fp);
01763         }
01764         else return result;
01765 }

EMData & EMData::operator= ( const EMData that  )  [inherited]

EMData assignment operator Performs a deep copy.

Parameters:
that the EMData to copy

Definition at line 167 of file emdata.cpp.

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

00168 {
00169         ENTERFUNC;
00170 
00171         if ( this != &that )
00172         {
00173                 free_memory(); // Free memory sets nx,ny and nz to 0
00174 
00175                 // Only copy the rdata if it exists, we could be in a scenario where only the header has been read
00176                 float* data = that.rdata;
00177                 size_t num_bytes = that.nx*that.ny*that.nz*sizeof(float);
00178                 if (data && num_bytes != 0)
00179                 {
00180                         nx = 1; // This prevents a memset in set_size
00181                         set_size(that.nx,that.ny,that.nz);
00182                         EMUtil::em_memcpy(rdata, data, num_bytes);
00183                 }
00184 
00185                 flags = that.flags;
00186 
00187                 all_translation = that.all_translation;
00188 
00189                 path = that.path;
00190                 pathnum = that.pathnum;
00191                 attr_dict = that.attr_dict;
00192 
00193                 xoff = that.xoff;
00194                 yoff = that.yoff;
00195                 zoff = that.zoff;
00196 
00197 #ifdef EMAN2_USING_CUDA
00198                 cout << "That copy constructor #2" << endl;
00199                 if (num_bytes != 0 && that.cudarwdata != 0) {
00200                         rw_alloc();
00201                         cudaError_t error = cudaMemcpy(cudarwdata,that.cudarwdata,num_bytes,cudaMemcpyDeviceToDevice);
00202                         if ( error != cudaSuccess ) throw UnexpectedBehaviorException("cudaMemcpy failed in EMData copy construction with error: " + string(cudaGetErrorString(error)));
00203                         
00204                 }
00205 #endif //EMAN2_USING_CUDA
00206 
00207                 changecount = that.changecount;
00208 
00209                 if (that.rot_fp != 0) rot_fp = new EMData(*(that.rot_fp));
00210                 else rot_fp = 0;
00211         }
00212         EXITFUNC;
00213         return *this;
00214 }

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 [inherited]

Maps to polar coordinates from Cartesian coordinates.

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

Parameters:
r1 inner ring (all rings less than r1 are discarded) Default = 4
r2 outer ring (all rings > r2 are discarded) Default = ny/2 - 2 - floor(hyp(dx,dy))
xs Number of angular bins. Default = (2 if do360) PI * ny/4 - xs % 8
dx origin offset in x
dy origin offest in y
do360 If true, do 0-360 degree mapping. Otherwise, do 0-180 degree mapping.
weight_radial if true (default) reights the pixel value by its radius
Exceptions:
ImageDimensionException If 'this' image is not 2D.
UnexpectedBehaviorException if 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 2453 of file emdata.cpp.

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

Referenced by EMAN::RTFExhaustiveAligner::align(), EMAN::RotateTranslateFlipAlignerPawel::align(), EMAN::RotateTranslateAlignerPawel::align(), EMAN::RotationalAlignerIterative::align(), EMAN::RotatePrecenterAligner::align(), EMAN::EMData::make_rotational_footprint(), EMAN::EMData::make_rotational_footprint_cmc(), and EMAN::EMData::make_rotational_footprint_e1().

02454 {
02455         ENTERFUNC;
02456 
02457         if (get_ndim() != 2) {
02458                 throw ImageDimensionException("2D image only");
02459         }
02460 
02461         int p = 1;
02462         if (do360) {
02463                 p = 2;
02464         }
02465 
02466         if (xs < 1) {
02467                 xs = (int) Util::fast_floor(p * M_PI * ny / 4);
02468                 xs -= xs % 8;
02469                 if (xs<=8) xs=16;
02470         }
02471 
02472         if (r1 < 0) {
02473                 r1 = 4;
02474         }
02475 
02476 #ifdef  _WIN32
02477         int rr = ny / 2 - 2 - (int) Util::fast_floor(static_cast<float>(_hypot(dx, dy)));
02478 #else
02479         int rr = ny / 2 - 2 - (int) Util::fast_floor(static_cast<float>(hypot(dx, dy)));
02480 #endif  //_WIN32
02481         rr-=rr%2;
02482         if (r2 <= r1 || r2 > rr) {
02483                 r2 = rr;
02484         }
02485 
02486         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");
02487 
02488 #ifdef EMAN2_USING_CUDA
02489         if (isrodataongpu()){
02490                 //cout << " CUDA unwrap" << endl;
02491                 EMData* result = new EMData(0,0,xs,(r2-r1),1);
02492                 result->rw_alloc();
02493                 bindcudaarrayA(true);
02494                 emdata_unwrap(result->cudarwdata, r1, r2, xs, p, dx, dy, weight_radial, nx, ny);
02495                 unbindcudaarryA();
02496                 return result;
02497         }
02498 #endif
02499 
02500         EMData *ret = new EMData();
02501         ret->set_size(xs, r2 - r1, 1);
02502         const float *const d = get_const_data();
02503         float *dd = ret->get_data();
02504         float pfac = (float)p/(float)xs;
02505 
02506         int nxon2 = nx/2;
02507         int nyon2 = ny/2;
02508         for (int x = 0; x < xs; x++) {
02509                 float ang = x * M_PI * pfac;
02510                 float si = sin(ang);
02511                 float co = cos(ang);
02512 
02513                 for (int y = 0; y < r2 - r1; y++) {
02514                         float ypr1 = (float)y + r1;
02515                         float xx = ypr1 * co + nxon2 + dx;
02516                         float yy = ypr1 * si + nyon2 + dy;
02517 //                      float t = xx - Util::fast_floor(xx);
02518 //                      float u = yy - Util::fast_floor(yy);
02519                         float t = xx - (int)xx;
02520                         float u = yy - (int)yy;
02521 //                      int k = (int) Util::fast_floor(xx) + (int) (Util::fast_floor(yy)) * nx;
02522                         int k = (int) xx + ((int) yy) * nx;
02523                         float val = Util::bilinear_interpolate(d[k], d[k + 1], d[k + nx], d[k + nx+1], t,u);
02524                         if (weight_radial) val *=  ypr1;
02525                         dd[x + y * xs] = val;
02526                 }
02527 
02528         }
02529         ret->update();
02530 
02531         EXITFUNC;
02532         return ret;
02533 }


Generated on Thu Mar 10 22:58:36 2011 for EMAN2 by  doxygen 1.4.7