#include <util.h>
Static Public Member Functions | |
| int | coveig (int n, float *covmat, float *eigval, float *eigvec) |
| This file is a part of util.h, To use this file's functions, you should include "util.h" NEVER directly include this file. | |
| Dict | coveig_for_py (int ncov, const vector< float > &covmatpy) |
| same function than Util::coveig but wrapped to use directly in python code | |
| void | WTF (EMData *PROJ, vector< float > SS, float SNR, int K) |
| void | WTM (EMData *PROJ, vector< float > SS, int DIAMETER, int NUMP) |
| Dict | CANG (float PHI, float THETA, float PSI) |
| void | BPCQ (EMData *B, EMData *CUBE, vector< float > DM) |
| vector< float > | infomask (EMData *Vol, EMData *mask, bool) |
| void | colreverse (float *beg, float *end, int nx) |
| void | slicereverse (float *beg, float *end, int nx, int ny) |
| void | cyclicshift (EMData *image, Dict params) |
| Performs inplace integer cyclic shift as specified by the "dx","dy","dz" parameters on a 3d volume. | |
| Dict | im_diff (EMData *V1, EMData *V2, EMData *mask=0) |
| EMData * | TwoDTestFunc (int Size, float p, float q, float a, float b, int flag=0, float alphaDeg=0) |
| Creates a Two D Test Pattern. | |
| void | spline_mat (float *x, float *y, int n, float *xq, float *yq, int m) |
| Given a tabulated function y of x (n unordered points), and Given the values of the m values xq to be interpolated This routine returns the interpolated array yq, PRB This function is called by splint. | |
| void | spline (float *x, float *y, int n, float yp1, float ypn, float *y2) |
| Given a tabulated function y of x (unordered), and Given the values of the first derivatives at the end points This routine returns an array y2, that contains the second derivatives of the function at the tabulated points. | |
| void | splint (float *xa, float *ya, float *y2a, int n, float *xq, float *yq, int m) |
| Given the arrays xa(ordered, ya of length n, which tabulate a function and given the array y2a which is the output of spline and an unordered array xq, this routine returns a cubic-spline interpolated array yq. | |
| void | Radialize (int *PermMatTr, float *kValsSorted, float *weightofkvalsSorted, int Size, int *SizeReturned) |
| list the sorted lengths of the integer lattice sites of a square sided image of size Size. | |
| vector< float > | even_angles (float delta, float t1=0, float t2=90, float p1=0, float p2=359.999) |
| Compute a vector containing quasi-evenly spaced Euler angles. | |
| float | quadri (float x, float y, int nx, int ny, float *image) |
| Quadratic interpolation (2D). | |
| float | quadri_background (float x, float y, int nx, int ny, float *image, int xnew, int ynew) |
| Quadratic interpolation (2D). | |
| float | get_pixel_conv_new (int nx, int ny, int nz, float delx, float dely, float delz, float *data, Util::KaiserBessel &kb) |
| float | get_pixel_conv_new_background (int nx, int ny, int nz, float delx, float dely, float delz, float *data, Util::KaiserBessel &kb, int xnew, int ynew) |
| std::complex< float > | extractpoint2 (int nx, int ny, float nuxnew, float nuynew, EMData *fimage, Util::KaiserBessel &kb) |
| float | bilinear (float xold, float yold, int nsam, int nrow, float *xim) |
| float | triquad (float r, float s, float t, float *fdata) |
| Quadratic interpolation (3D). | |
| EMData * | Polar2D (EMData *image, vector< int > numr, string mode) |
| EMData * | Polar2Dm (EMData *image, float cns2, float cnr2, vector< int > numr, string cmode) |
| void | alrl_ms (float *xim, int nsam, int nrow, float cns2, float cnr2, int *numr, float *circ, int lcirc, int nring, char mode) |
| EMData * | Polar2Dmi (EMData *image, float cns2, float cnr2, vector< int > numr, string cmode, Util::KaiserBessel &kb) |
| void | fftr_q (float *xcmplx, int nv) |
| void | fftr_d (double *xcmplx, int nv) |
| void | fftc_q (float *br, float *bi, int ln, int ks) |
| void | fftc_d (double *br, double *bi, int ln, int ks) |
| void | Frngs (EMData *circ, vector< int > numr) |
| This function conducts the Single Precision Fourier Transform for a set of rings. | |
| void | Normalize_ring (EMData *ring, const vector< int > &numr) |
| void | Frngs_inv (EMData *circ, vector< int > numr) |
| This function conducts the Single Precision Inverse Fourier Transform for a set of rings. | |
| Dict | Crosrng_e (EMData *circ1, EMData *circ2, vector< int > numr, int neg) |
| Dict | Crosrng_ew (EMData *circ1, EMData *circ2, vector< int > numr, vector< float > w, int neg) |
| Dict | Crosrng_ms (EMData *circ1, EMData *circ2, vector< int > numr) |
| Dict | Crosrng_ms_delta (EMData *circ1, EMData *circ2, vector< int > numr, float delta_start, float delta) |
| Dict | Crosrng_sm_psi (EMData *circ1, EMData *circ2, vector< int > numr, float psi, int flag) |
| checks both straight & mirrored position input - fourier transforms of rings!! circ1 already multiplied by weights! | |
| Dict | Crosrng_psi_0_180 (EMData *circ1, EMData *circ2, vector< int > numr, float psi_max) |
| checks both straight & mirrored positions Find only positions within +/-pis_max of 0 and 180 (for helcal use) input - fourier transforms of rings! circ1 already multiplied by weights! | |
| Dict | Crosrng_psi_0_180_no_mirror (EMData *circ1, EMData *circ2, vector< int > numr, float psi_max) |
| Dict | Crosrng_ns (EMData *circ1, EMData *circ2, vector< int > numr) |
| EMData * | Crosrng_msg (EMData *circ1, EMData *circ2, vector< int > numr) |
| checks both straight & mirrored positions input - fourier transforms of rings!! circ1 already multiplied by weights! returns EM object with 1D ccf | |
| void | Crosrng_msg_vec (EMData *circ1, EMData *circ2, vector< int > numr, float *q, float *t) |
| checks both straight & mirrored positions input - fourier transforms of rings!! circ1 already multiplied by weights! returns EM object with 1D ccf | |
| EMData * | Crosrng_msg_s (EMData *circ1, EMData *circ2, vector< int > numr) |
| This program is half of the Crosrng_msg. | |
| EMData * | Crosrng_msg_m (EMData *circ1, EMData *circ2, vector< int > numr) |
| This program is half of the Crosrng_msg. | |
| vector< float > | Crosrng_msg_vec_p (EMData *circ1, EMData *circ2, vector< int > numr) |
| void | prb1d (double *b, int npoint, float *pos) |
| void | update_fav (EMData *ave, EMData *dat, float tot, int mirror, vector< int > numr) |
| void | sub_fav (EMData *ave, EMData *dat, float tot, int mirror, vector< int > numr) |
| float | ener (EMData *ave, vector< int > numr) |
| float | ener_tot (const vector< EMData * > &data, vector< int > numr, vector< float > tot) |
| Dict | min_dist_real (EMData *image, const vector< EMData * > &data) |
| k-means helper | |
| Dict | min_dist_four (EMData *image, const vector< EMData * > &data) |
| helper function for k-means | |
| int | k_means_cont_table_ (int *group1, int *group2, int *stb, long int s1, long int s2, int flag) |
| helper to create the contengency table for partition matching (k-means) flag define is the list of stable obj must be store to stb, but the size st must be know before. | |
| void | initial_prune (vector< vector< int * > > &Parts, int *dimClasses, int nParts, int K, int T) |
| initial_prune removes all classes C from Parts where there does not exist ANY feasible matching containing class C which has weight gt T. | |
| bool | explore (vector< vector< int * > > &Parts, int *dimClasses, int nParts, int K, int T, int partref, int *curintx, int size_curintx, int *next, int size_next, int depth) |
| Each class in Parts has its dummy variable set to 0 or 1. | |
| int | generatesubmax (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int n_guesses, int LARGEST_CLASS) |
| make an intelligent "guess" at the largest weight of all possible feasible matches. | |
| void | search2 (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int *matchlist, int *costlist, int J) |
| return the weight of the largest weighted feasible match, along with the match in the (preallocated) argument curmax. | |
| void | explore2 (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int *curintx, int size_curintx, int *next, int size_next, int depth, int J, int *matchlist, int *costlist, int *curbranch) |
| bool | sanitycheck (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int *output) |
| First element of output is total cost of the matches in the output Second element of output is the total number of matches in output So output has 2+(*(output+1))nParts elements. | |
| vector< int > | bb_enumerateMPI_ (int *argParts, int *dimClasses, int nParts, int K, int T, int n_guesses, int LARGEST_CLASS, int J, int max_branching, float stmult, int branchfunc, int LIM) |
| K is the number of classes in each partition (should be the same for all partitions) the first element of each class is its original index in the partition, and second is dummy var MPI: if nTop <= 0, then initial prune is called, and the pruned partitions are returned in a 1D array. | |
| int * | branchMPI (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int curlevel, int n_guesses, int LARGEST_CLASS, int J, int max_branching, float stmult, int branchfunc, int LIM) |
| same as branch except the nFirst (=Levels[0]) possibilites for the first match are already chosen firstmatches stores the matches and corresponding cost, where each match is preceded by its cost.... | |
| int | branch_factor_2 (int *costlist, int *matchlist, int J, int T, int nParts, int curlevel, int max_branching, int LIM) |
| int | branch_factor_3 (int *costlist, int *matchlist, int J, int T, int nParts, int curlevel, int max_branching, int K, int LIM) |
| int | branch_factor_4 (int *costlist, int *matchlist, int J, int T, int nParts, int curlevel, int max_branching, float stmult) |
| vector< double > | cml_weights (const vector< float > &cml) |
| vector< int > | cml_line_insino (vector< float > Rot, int i_prj, int n_prj) |
| 2009-03-25 15:35:53 JB. | |
| vector< int > | cml_line_insino_all (vector< float > Rot, vector< int > seq, int n_prj, int n_lines) |
| 2009-03-30 15:35:07 JB. | |
| vector< double > | cml_init_rot (vector< float > Ori) |
| 2009-03-25 15:35:05 JB. | |
| vector< float > | cml_update_rot (vector< float > Rot, int iprj, float nph, float th, float nps) |
| 2009-03-25 15:35:37 JB. | |
| vector< double > | cml_line_in3d (vector< float > Ori, vector< int > seq, int nprj, int nlines) |
| 2009-03-26 10:46:14 JB. | |
| vector< double > | cml_spin_psi (const vector< EMData * > &data, vector< int > com, vector< float > weights, int iprj, vector< int > iw, int n_psi, int d_psi, int n_prj) |
| 2009-03-26 11:37:53 JB. | |
| double | cml_disc (const vector< EMData * > &data, vector< int > com, vector< int > seq, vector< float > weights, int n_lines) |
| 2009-03-30 15:44:05 JB. | |
| void | set_line (EMData *img, int posline, EMData *line, int offset, int length) |
| This function drop a line (line) to an 2D image (img). | |
| void | cml_prepare_line (EMData *sino, EMData *line, int ilf, int ihf, int pos_line, int nblines) |
| This function prepare the line from sinogram by cutting off some frequencies, and creating the mirror part (complexe conjugate of the first part). | |
| EMData * | decimate (EMData *img, int x_step, int y_step=1, int z_step=1) |
| EMData * | window (EMData *img, int new_nx, int new_ny=1, int new_nz=1, int x_offset=0, int y_offset=0, int z_offset=0) |
| EMData * | pad (EMData *img, int new_nx, int new_ny=1, int new_nz=1, int x_offset=0, int y_offset=0, int z_offset=0, char *params="average") |
| vector< float > | histogram (EMData *image, EMData *mask, int nbins=128, float hmin=0.0f, float hmax=0.0f) |
| Dict | histc (EMData *ref, EMData *img, EMData *mask) |
| float | hist_comp_freq (float PA, float PB, size_t size_img, int hist_len, EMData *img, vector< float > ref_freq_hist, EMData *mask, float ref_h_diff, float ref_h_min) |
| float | tf (float dzz, float ak, float voltage=300.0f, float cs=2.0f, float wgh=0.1f, float b_factor=0.0f, float sign=-1.0f) |
| EMData * | compress_image_mask (EMData *image, EMData *mask) |
| EMData * | reconstitute_image_mask (EMData *image, EMData *mask) |
| Recreates a n-d image using its compressed 1-D form and the mask. | |
| vector< float > | merge_peaks (vector< float > peak1, vector< float > peak2, float p_size) |
| vector< float > | pw_extract (vector< float >pw, int n, int iswi, float ps) |
| vector< float > | call_cl1 (long int *k, long int *n, float *ps, long int *iswi, float *pw, float *q2, double *q, double *x, double *res, double *cu, double *s, long int *iu) |
| vector< float > | lsfit (long int *ks, long int *n, long int *klm2d, long int *iswi, float *q1, double *q, double *x, double *res, double *cu, double *s, long int *iu) |
| void | cl1 (long int *k, long int *l, long int *m, long int *n, long int *klm2d, double *q, double *x, double *res, double *cu, long int *iu, double *s) |
| float | eval (char *images, EMData *img, vector< int > S, int N, int K, int size) |
| vector< double > | vrdg (const vector< float > &ph, const vector< float > &th) |
| void | hsortd (double *theta, double *phi, int *key, int len, int option) |
| void | voronoidiag (double *theta, double *phi, double *weight, int n) |
| void | voronoi (double *phi, double *theta, double *weight, int nt) |
| void | disorder2 (double *x, double *y, int *key, int len) |
| void | ang_to_xyz (double *x, double *y, double *z, int len) |
| void | flip23 (double *x, double *y, double *z, int *key, int k, int len) |
| bool | cmp1 (tmpstruct tmp1, tmpstruct tmp2) |
| bool | cmp2 (tmpstruct tmp1, tmpstruct tmp2) |
| int | trmsh3_ (int *n0, double *tol, double *x, double *y, double *z__, int *n, int *list, int *lptr, int *lend, int *lnew, int *indx, int *lcnt, int *near__, int *next, double *dist, int *ier) |
| double | areav_ (int *k, int *n, double *x, double *y, double *z__, int *list, int *lptr, int *lend, int *ier) |
| EMData * | madn_scalar (EMData *img, EMData *img1, float scalar) |
| EMData * | mult_scalar (EMData *img, float scalar) |
| EMData * | addn_img (EMData *img, EMData *img1) |
| EMData * | subn_img (EMData *img, EMData *img1) |
| EMData * | muln_img (EMData *img, EMData *img1) |
| EMData * | divn_img (EMData *img, EMData *img1) |
| EMData * | divn_filter (EMData *img, EMData *img1) |
| void | mad_scalar (EMData *img, EMData *img1, float scalar) |
| void | mul_scalar (EMData *img, float scalar) |
| void | add_img (EMData *img, EMData *img1) |
| void | add_img_abs (EMData *img, EMData *img1) |
| void | add_img2 (EMData *img, EMData *img1) |
| void | sub_img (EMData *img, EMData *img1) |
| void | mul_img (EMData *img, EMData *img1) |
| void | div_img (EMData *img, EMData *img1) |
| void | div_filter (EMData *img, EMData *img1) |
| EMData * | pack_complex_to_real (EMData *img) |
| vector< float > | multiref_polar_ali_2d (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny) |
| formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation | |
| vector< float > | multiref_polar_ali_2d_peaklist (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny) |
| vector< int > | assign_groups (const vector< float > &d, int nref, int nima) |
| vector< float > | multiref_polar_ali_2d_delta (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny, float delta_start, float delta) |
| formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation | |
| vector< float > | multiref_polar_ali_2d_nom (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny) |
| formerly known as apnq DO NOT CONSIDER MIRROR Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation | |
| vector< float > | multiref_polar_ali_2d_local (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, float ant, string mode, vector< int >numr, float cnx, float cny) |
| formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation | |
| vector< float > | multiref_polar_ali_helical (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, float psi_max, string mode, vector< int >numr, float cnx, float cny, int ynumber=-1) |
| formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation Search for peaks only within +/-psi_max from 0 and 180 (helical) | |
| vector< float > | multiref_polar_ali_helical_local (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, float ant, float psi_max, string mode, vector< int >numr, float cnx, float cny, int ynumber=-1) |
| vector< float > | multiref_polar_ali_helical_90 (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, float psi_max, string mode, vector< int >numr, float cnx, float cny, int ynumber=-1) |
| vector< float > | multiref_polar_ali_helical_90_local (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, float ant, float psi_max, string mode, vector< int >numr, float cnx, float cny, int ynumber=-1) |
| vector< float > | multiref_polar_ali_2d_local_psi (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, float ant, float psi_max, string mode, vector< int >numr, float cnx, float cny) |
| formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation | |
| void | multiref_peaks_ali2d (EMData *image, EMData *crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny, EMData *peaks, EMData *peakm) |
| Determine shift and rotation between image and one reference image (crefim, weights have to be applied) using quadratic interpolation, return a list of peaks PAP 07/21/08. | |
| void | multiref_peaks_compress_ali2d (EMData *image, EMData *crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny, EMData *peaks, EMData *peakm, EMData *peaks_compress, EMData *peakm_compress) |
| Determine shift and rotation between image and one reference image (crefim, weights have to be applied) using quadratic interpolation, return a list of peaks PAP 07/21/08. | |
| vector< float > | ali2d_ccf_list (EMData *image, EMData *crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny, double T) |
| Determine shift and rotation between image and one reference image (crefim, weights have to be applied) using quadratic interpolation. | |
| vector< float > | twoD_fine_ali (EMData *image, EMData *refim, EMData *mask, float ang, float sxs, float sys) |
| vector< float > | twoD_fine_ali_G (EMData *image, EMData *refim, EMData *mask, Util::KaiserBessel &kb, float ang, float sxs, float sys) |
| vector< float > | twoD_to_3D_ali (EMData *volft, Util::KaiserBessel &kb, EMData *refim, EMData *mask, float phi, float theta, float psi, float sxs, float sxy) |
| vector< float > | twoD_fine_ali_SD (EMData *image, EMData *refim, EMData *mask, float ang, float sxs, float sys) |
| float | ccc_images (EMData *, EMData *, EMData *, float, float, float) |
| vector< float > | twoD_fine_ali_SD_G (EMData *image, EMData *refim, EMData *mask, Util::KaiserBessel &kb, float ang, float sxs, float sys) |
| float | ccc_images_G (EMData *image, EMData *refim, EMData *mask, Util::KaiserBessel &kb, float ang, float sx, float sy) |
| EMData * | move_points (EMData *img, float qprob, int ri, int ro) |
| EMData * | get_biggest_cluster (EMData *mg) |
| EMData * | ctf_img (int nx, int ny, int nz, float dz, float ps, float voltage, float cs, float wgh, float b_factor, float dza, float azz, float sign) |
| int | mono (int k1, int k2) |
| int | nint180 (float arg) |
| float | mean (float *x, int n) |
| float | var (float *x, int n) |
| void | rot_shift (float x, float y, float alpha, float x0, float y0, float *x1, float *y1) |
| vector< float > | multi_align_error (vector< float > args, vector< float > all_ali_params) |
| float | multi_align_error_func (double *x, vector< float > all_ali_params, int nima, int num_ali) |
| void | multi_align_error_dfunc (double *x, vector< float > all_ali_params, int nima, int num_ali, double *g) |
| vector< float > | cluster_pairwise (EMData *d, int K, float T, float F) |
| vector< float > | cluster_equalsize (EMData *d) |
| vector< float > | vareas (EMData *d) |
| EMData * | get_slice (EMData *vol, int dim, int index) |
| This function returns a 2-D slice from a 3-D EMData object dim denotes the slice is perpendicular to which dimension 1 for x-dimension, 2 for y-dimension and 3 for z-dimension. | |
| void | image_mutation (EMData *img, float mutation_rate) |
| void | array_mutation (float *list, int len_list, float mutation_rate, float min_val, float max_val, int K, int is_mirror) |
| The purpose of this function is to convert a list to grey code and mutate them and convert them back. | |
| vector< float > | list_mutation (vector< float > list, float mutation_rate, float min_val, float max_val, int K, int is_mirror) |
| float | restrict1 (float x, int nx) |
| void | ap2ri (float *data, size_t n) |
| convert complex data array from Amplitude/Phase format into Real/Imaginary format. | |
| void | flip_complex_phase (float *data, size_t n) |
| flip the phase of a complex data array. | |
| void | rotate_phase_origin (float *data, size_t nx, size_t ny, size_t nz) |
| rotate data vertically by ny/2, to make the mrc phase origin compliance with EMAN1 and TNF reader | |
| int | file_lock_wait (FILE *file) |
| lock a file. | |
| bool | check_file_by_magic (const void *first_block, const char *magic) |
| check whether a file starts with certain magic string. | |
| bool | is_file_exist (const string &filename) |
| check whether a file exists or not | |
| void | flip_image (float *data, size_t nx, size_t ny) |
| Vertically flip the data of a 2D real image. | |
| vector< EMData * > | svdcmp (const vector< EMData * > &data, int nvec) |
| Perform singular value decomposition on a set of images. | |
| string | str_to_lower (const string &s) |
| Return a lower case version of the argument string. | |
| bool | sstrncmp (const char *s1, const char *s2) |
| Safe string compare. | |
| string | int2str (int n) |
| Get a string format of an integer, e.g. | |
| string | get_line_from_string (char **str) |
| Extract a single line from a multi-line string. | |
| bool | get_str_float (const char *str, const char *float_var, float *p_val) |
| Extract the float value from a variable=value string with format like "XYZ=1.1", where 'str' is "XYZ=1.1"; 'float_var' is "XYZ="; 'p_val' points to float number 1.1. | |
| bool | get_str_float (const char *str, const char *float_var, float *p_v1, float *p_v2) |
| Extract the float values from a variable=value1,value2 string with format like "XYZ=1.1,1.2", where 'str' is "XYZ=1.1,1.2"; 'float_var' is "XYZ="; 'p_v1' points to 1.1; 'p_v2' points to 1.2. | |
| bool | get_str_float (const char *str, const char *float_var, int *p_nvalues, float *p_v1, float *p_v2) |
| Extract number of values and the float values, if any, from a string whose format is either "variable=value1,value2 " or "variable". | |
| bool | get_str_int (const char *str, const char *int_var, int *p_val) |
| Extract the int value from a variable=value string with format like "XYZ=1", where 'str' is "XYZ=1"; 'int_var' is "XYZ="; 'p_val' points to float number 1. | |
| bool | get_str_int (const char *str, const char *int_var, int *p_v1, int *p_v2) |
| Extract the int value from a variable=value1,value2 string with format like "XYZ=1,2", where 'str' is "XYZ=1,2"; 'int_var' is "XYZ="; 'p_val' points to float number 1. | |
| bool | get_str_int (const char *str, const char *int_var, int *p_nvalues, int *p_v1, int *p_v2) |
| Extract number of values and the int values, if any, from a string whose format is either "variable=value1,value2 " or "variable". | |
| string | change_filename_ext (const string &old_filename, const string &new_ext) |
| Change a file's extension and return the new filename. | |
| string | remove_filename_ext (const string &filename) |
| Remove a filename's extension and return the new filename. | |
| string | get_filename_ext (const string &filename) |
| Get a filename's extension. | |
| string | sbasename (const string &filename) |
| Get a filename's basename. | |
| void | calc_least_square_fit (size_t nitems, const float *data_x, const float *data_y, float *p_slope, float *p_intercept, bool ignore_zero, float absmax=0) |
| calculate the least square fit value. | |
| Vec3f | calc_bilinear_least_square (const vector< float > &points) |
| calculate bilinear least-square fit, z = a + b x + c y Takes a set of x,y,z vectors and produces an a,b,c vector does not accept error bars on z or return goodness of fit | |
| void | save_data (const vector< float > &x_array, const vector< float > &y_array, const string &filename) |
| Save (x y) data array into a file. | |
| void | save_data (float x0, float dx, const vector< float > &y_array, const string &filename) |
| Save x, y data into a file. | |
| void | save_data (float x0, float dx, float *y_array, size_t array_size, const string &filename) |
| Save x, y data into a file. | |
| void | sort_mat (float *left, float *right, int *leftPerm, int *rightPerm) |
| does a sort as in Matlab. | |
| unsigned long int | get_randnum_seed () |
| Get the seed for Randnum class. | |
| void | set_randnum_seed (unsigned long int seed) |
| Set the seed for Randnum class. | |
| int | get_irand (int low, int high) |
| Get an integer random number between low and high, [low, high]. | |
| float | get_frand (int low, int high) |
| Get a float random number between low and high, [low, high). | |
| float | get_frand (float low, float high) |
| Get a float random number between low and high, [low, high). | |
| float | get_frand (double low, double high) |
| Get a float random number between low and high, [low, high). | |
| float | get_gauss_rand (float mean, float sigma) |
| Get a Gaussian random number. | |
| int | round (float x) |
| Get ceiling round of a float number x. | |
| int | round (double x) |
| Get ceiling round of a float number x. | |
| float | linear_interpolate (float p1, float p2, float t) |
| Calculate linear interpolation. | |
| float | bilinear_interpolate (float p1, float p2, float p3, float p4, float t, float u) |
| Calculate bilinear interpolation. | |
| float | trilinear_interpolate (float p1, float p2, float p3, float p4, float p5, float p6, float p7, float p8, float t, float u, float v) |
| Calculate trilinear interpolation. | |
| void | find_max (const float *data, size_t nitems, float *p_max_val, int *p_max_index=0) |
| Find the maximum value and (optional) its index in an array. | |
| void | find_min_and_max (const float *data, size_t nitems, float *p_max_val, float *p_min_val, int *p_max_index=0, int *p_min_index=0) |
| Find the maximum value and (optional) its index, minimum value and (optional) its index in an array. | |
| Dict | get_stats (const vector< float > &data) |
| Get the mean, standard deviation, skewness and kurtosis of the input data. | |
| Dict | get_stats_cstyle (const vector< float > &data) |
| Performs the same calculations as in get_stats, but uses a single pass, optimized c approach Should perform better than get_stats. | |
| int | calc_best_fft_size (int low) |
| Search the best FFT size with good primes. | |
| EMData * | calc_bessel (const int n, const float &x) |
| int | square (int n) |
| Calculate a number's square. | |
| float | square (float x) |
| Calculate a number's square. | |
| float | square (double x) |
| Calculate a number's square. | |
| float | square_sum (float x, float y) |
| Calcuate (x*x + y*y). | |
| float | hypot2 (float x, float y) |
| Euclidean distance function in 2D: f(x,y) = sqrt(x*x + y*y);. | |
| int | hypot3sq (int x, int y, int z) |
| Euclidean distance function squared in 3D: f(x,y,z) = (x*x + y*y + z*z);. | |
| float | hypot3sq (float x, float y, float z) |
| Euclidean distance function squared in 3D: f(x,y,z) = (x*x + y*y + z*z);. | |
| float | hypot3 (int x, int y, int z) |
| Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);. | |
| float | hypot3 (float x, float y, float z) |
| Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);. | |
| float | hypot3 (double x, double y, double z) |
| Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);. | |
| float | hypot_fast (int x, int y) |
| Euclidean distance in 2D for integers computed fast using a cached lookup table. | |
| short | hypot_fast_int (int x, int y) |
| Euclidean distance in 2D for integers computed fast using a cached lookup table. | |
| int | fast_floor (float x) |
| A fast way to calculate a floor, which is largest integral value not greater than argument. | |
| float | fast_exp (const float &f) |
| Returns an approximate of exp(x) using a cached table uses actual exp(x) outside the cached range. | |
| float | fast_acos (const float &f) |
| Returns an approximate of acos(x) using a cached table and linear interpolation tolerates values very slightly outside the -1 - 1 range (returning 0). | |
| float | agauss (float a, float dx, float dy, float dz, float d) |
| Calculate Gaussian value. | |
| int | get_min (int f1, int f2) |
| Get the minimum of 2 numbers. | |
| int | get_min (int f1, int f2, int f3) |
| Get the minimum of 3 numbers. | |
| float | get_min (float f1, float f2) |
| Get the minimum of 2 numbers. | |
| float | get_min (float f1, float f2, float f3) |
| Get the minimum of 3 numbers. | |
| float | get_min (float f1, float f2, float f3, float f4) |
| Get the minimum of 4 numbers. | |
| float | get_max (float f1, float f2) |
| Get the maximum of 2 numbers. | |
| float | get_max (float f1, float f2, float f3) |
| Get the maximum of 3 numbers. | |
| float | get_max (float f1, float f2, float f3, float f4) |
| Get the maximum of 4 numbers. | |
| float | angle_sub_2pi (float x, float y) |
| Calculate the difference of 2 angles and makes the equivalent result to be less than Pi. | |
| float | angle_sub_pi (float x, float y) |
| Calculate the difference of 2 angles and makes the equivalent result to be less than Pi/2. | |
| float | angle_err_ri (float r1, float i1, float r2, float i2) |
| Calculate the angular phase difference between two r/i vectors. | |
| int | goodf (const float *p_f) |
| Check whether a number is a good float. | |
| int | goodf (const double *p_f) |
| string | recv_broadcast (int port) |
| string | get_time_label () |
| Get the current time in a string with format "mm/dd/yyyy hh:mm". | |
| void | set_log_level (int argc, char *argv[]) |
| Set program logging level through command line option "-v N", where N is the level. | |
| float | eman_copysign (float a, float b) |
| copy sign of a number. | |
| float | eman_erfc (float x) |
| complementary error function. | |
| void | equation_of_plane (const Vec3f &p1, const Vec3f &p2, const Vec3f &p3, float *plane) |
| Determine the equation of a plane that intersects 3 points in 3D space. | |
| bool | point_is_in_convex_polygon_2d (const Vec2f &p1, const Vec2f &p2, const Vec2f &p3, const Vec2f &p4, const Vec2f &actual_point) |
| Determines if a point is in a 2D convex polygon described by 4 points using the Barycentric method, which is a fast way of performing the query. | |
| bool | point_is_in_triangle_2d (const Vec2f &p1, const Vec2f &p2, const Vec2f &p3, const Vec2f &actual_point) |
| Determines if a point is in a 2D triangle using the Barycentric method, which is a fast way of performing the query Triangle points can be specified in any order. | |
| void | printMatI3D (MIArray3D &mat, const string str=string(""), ostream &out=std::cout) |
| Print a 3D integer matrix to a file stream (std out by default). | |
| template<class T> | |
| T | sgn (T &val) |
| Sign function. | |
| float * | getBaldwinGridWeights (const int &freq_cutoff, const float &P, const float &r, const float &dfreq=1, const float &alpha=0.5, const float &beta=0.2) |
| bool | IsPower2 (int x) |
| Return true if an integer is positive and is power of 2. | |
| void | apply_precision (float &value, const float &precision) |
Static Private Member Functions | |
| float | ang_n (float peakp, string mode, int maxrin) |
Definition at line 81 of file util.h.
|
||||||||||||
|
Definition at line 17610 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, NullPointerException, nx, ny, and EMAN::EMData::update(). 17611 {
17612 ENTERFUNC;
17613 /* Exception Handle */
17614 if (!img) {
17615 throw NullPointerException("NULL input image");
17616 }
17617 /* ========= img += img1 ===================== */
17618
17619 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17620 size_t size = (size_t)nx*ny*nz;
17621 float *img_ptr = img->get_data();
17622 float *img1_ptr = img1->get_data();
17623 for (size_t i=0;i<size;++i) img_ptr[i] += img1_ptr[i];
17624 img->update();
17625
17626 EXITFUNC;
17627 }
|
|
||||||||||||
|
Definition at line 17648 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, EMAN::EMData::is_complex(), NullPointerException, nx, ny, and EMAN::EMData::update(). 17649 {
17650 ENTERFUNC;
17651 /* Exception Handle */
17652 if (!img) {
17653 throw NullPointerException("NULL input image");
17654 }
17655 /* ========= img += img1**2 ===================== */
17656
17657 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17658 size_t size = (size_t)nx*ny*nz;
17659 float *img_ptr = img->get_data();
17660 float *img1_ptr = img1->get_data();
17661 if(img->is_complex()) {
17662 for (size_t i=0; i<size; i+=2) img_ptr[i] += img1_ptr[i] * img1_ptr[i] + img1_ptr[i+1] * img1_ptr[i+1] ;
17663 } else {
17664 for (size_t i=0;i<size;++i) img_ptr[i] += img1_ptr[i]*img1_ptr[i];
17665 }
17666 img->update();
17667
17668 EXITFUNC;
17669 }
|
|
||||||||||||
|
Definition at line 17629 of file util_sparx.cpp. References abs, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, NullPointerException, nx, ny, and EMAN::EMData::update(). 17630 {
17631 ENTERFUNC;
17632 /* Exception Handle */
17633 if (!img) {
17634 throw NullPointerException("NULL input image");
17635 }
17636 /* ========= img += img1 ===================== */
17637
17638 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17639 size_t size = (size_t)nx*ny*nz;
17640 float *img_ptr = img->get_data();
17641 float *img1_ptr = img1->get_data();
17642 for (size_t i=0;i<size;++i) img_ptr[i] += abs(img1_ptr[i]);
17643 img->update();
17644
17645 EXITFUNC;
17646 }
|
|
||||||||||||
|
Definition at line 17427 of file util_sparx.cpp. References EMAN::EMData::copy_head(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img2_ptr, img_ptr, EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), NullPointerException, nx, ny, EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), and EMAN::EMData::update(). 17428 {
17429 ENTERFUNC;
17430 /* Exception Handle */
17431 if (!img) {
17432 throw NullPointerException("NULL input image");
17433 }
17434 /* ============== output = img + img1 ================ */
17435
17436 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17437 size_t size = (size_t)nx*ny*nz;
17438 EMData * img2 = img->copy_head();
17439 float *img_ptr =img->get_data();
17440 float *img2_ptr = img2->get_data();
17441 float *img1_ptr = img1->get_data();
17442 for (size_t i=0;i<size;++i) img2_ptr[i] = img_ptr[i] + img1_ptr[i];
17443 img2->update();
17444 if(img->is_complex()) {
17445 img2->set_complex(true);
17446 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false);
17447 }
17448
17449 EXITFUNC;
17450 return img2;
17451 }
|
|
||||||||||||||||||||||||
|
Calculate Gaussian value. a * exp(-(dx * dx + dy * dy + dz * dz) / d)
Definition at line 1721 of file util.h. Referenced by EMAN::GaussFFTProjector::interp_ft_3d(). |
|
||||||||||||||||||||||||||||||||||||||||||||
|
Determine shift and rotation between image and one reference image (crefim, weights have to be applied) using quadratic interpolation.
Definition at line 19065 of file util_sparx.cpp. References Crosrng_msg_vec(), Frngs(), get_frand(), ccf_point::i, ccf_point::j, ccf_point::k, ccf_point::mirror, numr, Polar2Dm(), t, and ccf_point::value. 19067 {
19068
19069 int maxrin = numr[numr.size()-1];
19070
19071 int ky = int(2*yrng/step+0.5)/2;
19072 int kx = int(2*xrng/step+0.5)/2;
19073
19074 float *p_ccf1ds = (float *)malloc(maxrin*sizeof(float));
19075 float *p_ccf1dm = (float *)malloc(maxrin*sizeof(float));
19076 int vol = maxrin*(2*kx+1)*(2*ky+1);
19077 vector<ccf_point> ccf(2*vol);
19078 ccf_point temp;
19079
19080 int index = 0;
19081 for (int i = -ky; i <= ky; i++) {
19082 float iy = i * step;
19083 for (int j = -kx; j <= kx; j++) {
19084 float ix = j*step;
19085 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
19086 Frngs(cimage, numr);
19087 Crosrng_msg_vec(crefim, cimage, numr, p_ccf1ds, p_ccf1dm);
19088 for (int k=0; k<maxrin; k++) {
19089 temp.value = p_ccf1ds[k];
19090 temp.i = k;
19091 temp.j = j;
19092 temp.k = i;
19093 temp.mirror = 0;
19094 ccf[index] = temp;
19095 index++;
19096 temp.value = p_ccf1dm[k];
19097 temp.mirror = 1;
19098 ccf[index] = temp;
19099 index++;
19100 }
19101 delete cimage; cimage = 0;
19102 }
19103 }
19104
19105 delete p_ccf1ds;
19106 delete p_ccf1dm;
19107 std::sort(ccf.begin(), ccf.end(), ccf_value());
19108
19109 double qt = (double)ccf[0].value;
19110 vector <double> p(2*vol), cp(2*vol);
19111
19112 double sump = 0.0;
19113 for (int i=0; i<2*vol; i++) {
19114 p[i] = pow(double(ccf[i].value)/qt, 1.0/T);
19115 sump += p[i];
19116 }
19117 for (int i=0; i<2*vol; i++) {
19118 p[i] /= sump;
19119 }
19120 for (int i=1; i<2*vol; i++) {
19121 p[i] += p[i-1];
19122 }
19123 p[2*vol-1] = 2.0;
19124
19125 float t = get_frand(0.0f, 1.0f);
19126 int select = 0;
19127 while (p[select] < t) select += 1;
19128
19129 vector<float> a(6);
19130 a[0] = ccf[select].value;
19131 a[1] = (float)ccf[select].i;
19132 a[2] = (float)ccf[select].j;
19133 a[3] = (float)ccf[select].k;
19134 a[4] = (float)ccf[select].mirror;
19135 a[5] = (float)select;
19136 return a;
19137 }
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
Definition at line 2359 of file util_sparx.cpp. References circ, numr, quadri(), x, xim, and y. 02360 {
02361 double dpi, dfi;
02362 int it, jt, inr, l, nsim, kcirc, lt;
02363 float xold, yold, fi, x, y;
02364
02365 // cns2 and cnr2 are predefined centers
02366 // no need to set to zero, all elements are defined
02367
02368 dpi = 2*atan(1.0);
02369 for (it=1; it<=nring; it++) {
02370 // radius of the ring
02371 inr = numr(1,it);
02372
02373 l = numr(3,it);
02374 if ( mode == 'h' || mode == 'H' ) lt = l / 2;
02375 else lt = l / 4;
02376
02377 nsim = lt - 1;
02378 dfi = dpi / (nsim+1);
02379 kcirc = numr(2,it);
02380
02381
02382 xold = 0.0f+cns2;
02383 yold = inr+cnr2;
02384
02385 circ(kcirc) = quadri(xold,yold,nsam,nrow,xim);
02386
02387 xold = inr+cns2;
02388 yold = 0.0f+cnr2;
02389 circ(lt+kcirc) = quadri(xold,yold,nsam,nrow,xim);
02390
02391 if ( mode == 'f' || mode == 'F' ) {
02392 xold = 0.0f+cns2;
02393 yold = -inr+cnr2;
02394 circ(lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim);
02395
02396 xold = -inr+cns2;
02397 yold = 0.0f+cnr2;
02398 circ(lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim);
02399 }
02400
02401 for (jt=1; jt<=nsim; jt++) {
02402 fi = static_cast<float>(dfi * jt);
02403 x = sin(fi) * inr;
02404 y = cos(fi) * inr;
02405
02406 xold = x+cns2;
02407 yold = y+cnr2;
02408 circ(jt+kcirc) = quadri(xold,yold,nsam,nrow,xim);
02409
02410 xold = y+cns2;
02411 yold = -x+cnr2;
02412 circ(jt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim);
02413
02414 if ( mode == 'f' || mode == 'F' ) {
02415 xold = -x+cns2;
02416 yold = -y+cnr2;
02417 circ(jt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim);
02418
02419 xold = -y+cns2;
02420 yold = x+cnr2;
02421 circ(jt+lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim);
02422 }
02423 } // end for jt
02424 } //end for it
02425 }
|
|
||||||||||||||||
|
Definition at line 17857 of file util_sparx.cpp. Referenced by multiref_polar_ali_2d(), multiref_polar_ali_2d_delta(), multiref_polar_ali_2d_local(), multiref_polar_ali_2d_local_psi(), multiref_polar_ali_2d_nom(), multiref_polar_ali_2d_peaklist(), multiref_polar_ali_helical(), multiref_polar_ali_helical_90(), multiref_polar_ali_helical_90_local(), and multiref_polar_ali_helical_local(). 17858 {
17859 if (mode == "f" || mode == "F")
17860 return fmodf(((peakp-1.0f) / maxrin+1.0f)*360.0f,360.0f);
17861 else
17862 return fmodf(((peakp-1.0f) / maxrin+1.0f)*180.0f,180.0f);
17863 }
|
|
||||||||||||||||||||
|
Definition at line 7803 of file util_sparx.cpp. References dgr_to_rad, x, and y. 07804 {
07805 ENTERFUNC;
07806 double costheta,sintheta,cosphi,sinphi;
07807 for(int i = 0; i<len; i++)
07808 {
07809 cosphi = cos(y[i]*dgr_to_rad);
07810 sinphi = sin(y[i]*dgr_to_rad);
07811 if(fabs(x[i]-90.0)< 1.0e-5){
07812 x[i] = cosphi;
07813 y[i] = sinphi;
07814 z[i] = 0.0;
07815 }
07816 else{
07817 costheta = cos(x[i]*dgr_to_rad);
07818 sintheta = sin(x[i]*dgr_to_rad);
07819 x[i] = cosphi*sintheta;
07820 y[i] = sinphi*sintheta;
07821 z[i] = costheta;
07822 }
07823 }
07824 EXITFUNC;
07825 }
|
|
||||||||||||||||||||
|
Calculate the angular phase difference between two r/i vectors.
Definition at line 1891 of file util.h. Referenced by EMAN::PhaseCmp::cmp(). |
|
||||||||||||
|
Calculate the difference of 2 angles and makes the equivalent result to be less than Pi.
|
|
||||||||||||
|
Calculate the difference of 2 angles and makes the equivalent result to be less than Pi/2.
|
|
||||||||||||
|
convert complex data array from Amplitude/Phase format into Real/Imaginary format.
Definition at line 67 of file util.cpp. References Assert, data, and NullPointerException. 00068 {
00069 Assert(n > 0);
00070
00071 if (!data) {
00072 throw NullPointerException("pixel data array");
00073 }
00074
00075 for (size_t i = 0; i < n; i += 2) {
00076 float f = data[i] * sin(data[i + 1]);
00077 data[i] = data[i] * cos(data[i + 1]);
00078 data[i + 1] = f;
00079 }
00080 }
|
|
||||||||||||
|
Definition at line 2114 of file util.h. Referenced by EMAN::Transform::get_determinant(), EMAN::Transform::get_scale(), EMAN::Transform::get_scale_and_mirror(), EMAN::Transform::get_trans(), EMAN::Transform::is_identity(), and EMAN::Transform::set_scale(). |
|
||||||||||||||||||||||||||||||||||||||||
|
Definition at line 8868 of file util_sparx.cpp. References areas_(), circum_(), ierr, x, and y. 08871 {
08872 /* Initialized data */
08873
08874 static double amax = 6.28;
08875
08876 /* System generated locals */
08877 double ret_val;
08878
08879 /* Local variables */
08880 static double a, c0[3], c2[3], c3[3];
08881 static int n1, n2, n3;
08882 static double v1[3], v2[3], v3[3];
08883 static int lp, lpl, ierr;
08884 static double asum;
08885 extern double areas_(double *, double *, double *);
08886 static long int first;
08887 extern /* Subroutine */ int circum_(double *, double *,
08888 double *, double *, int *);
08889
08890
08891 /* *********************************************************** */
08892
08893 /* Robert J. Renka */
08894 /* Dept. of Computer Science */
08895 /* Univ. of North Texas */
08896 /* renka@cs.unt.edu */
08897 /* 10/25/02 */
08898
08899 /* Given a Delaunay triangulation and the index K of an */
08900 /* interior node, this subroutine returns the (surface) area */
08901 /* of the Voronoi region associated with node K. The Voronoi */
08902 /* region is the polygon whose vertices are the circumcenters */
08903 /* of the triangles that contain node K, where a triangle */
08904 /* circumcenter is the point (unit vector) lying at the same */
08905 /* angular distance from the three vertices and contained in */
08906 /* the same hemisphere as the vertices. */
08907
08908
08909 /* On input: */
08910
08911 /* K = Nodal index in the range 1 to N. */
08912
08913 /* N = Number of nodes in the triangulation. N > 3. */
08914
08915 /* X,Y,Z = Arrays of length N containing the Cartesian */
08916 /* coordinates of the nodes (unit vectors). */
08917
08918 /* LIST,LPTR,LEND = Data structure defining the trian- */
08919 /* gulation. Refer to Subroutine */
08920 /* TRMESH. */
08921
08922 /* Input parameters are not altered by this function. */
08923
08924 /* On output: */
08925
08926 /* AREAV = Area of Voronoi region K unless IER > 0, */
08927 /* in which case AREAV = 0. */
08928
08929 /* IER = Error indicator: */
08930 /* IER = 0 if no errors were encountered. */
08931 /* IER = 1 if K or N is outside its valid range */
08932 /* on input. */
08933 /* IER = 2 if K indexes a boundary node. */
08934 /* IER = 3 if an error flag is returned by CIRCUM */
08935 /* (null triangle). */
08936 /* IER = 4 if AREAS returns a value greater than */
08937 /* AMAX (defined below). */
08938
08939 /* Modules required by AREAV: AREAS, CIRCUM */
08940
08941 /* *********************************************************** */
08942
08943
08944 /* Maximum valid triangle area is less than 2*Pi: */
08945
08946 /* Parameter adjustments */
08947 --lend;
08948 --z__;
08949 --y;
08950 --x;
08951 --list;
08952 --lptr;
08953
08954 /* Function Body */
08955
08956 /* Test for invalid input. */
08957
08958 if (*k < 1 || *k > *n || *n <= 3) {
08959 goto L11;
08960 }
08961
08962 /* Initialization: Set N3 to the last neighbor of N1 = K. */
08963 /* FIRST = TRUE only for the first triangle. */
08964 /* The Voronoi region area is accumulated in ASUM. */
08965
08966 n1 = *k;
08967 v1[0] = x[n1];
08968 v1[1] = y[n1];
08969 v1[2] = z__[n1];
08970 lpl = lend[n1];
08971 n3 = list[lpl];
08972 if (n3 < 0) {
08973 goto L12;
08974 }
08975 lp = lpl;
08976 first = TRUE_;
08977 asum = 0.;
08978
08979 /* Loop on triangles (N1,N2,N3) containing N1 = K. */
08980
08981 L1:
08982 n2 = n3;
08983 lp = lptr[lp];
08984 n3 = list[lp];
08985 v2[0] = x[n2];
08986 v2[1] = y[n2];
08987 v2[2] = z__[n2];
08988 v3[0] = x[n3];
08989 v3[1] = y[n3];
08990 v3[2] = z__[n3];
08991 if (first) {
08992
08993 /* First triangle: compute the circumcenter C3 and save a */
08994 /* copy in C0. */
08995
08996 circum_(v1, v2, v3, c3, &ierr);
08997 if (ierr != 0) {
08998 goto L13;
08999 }
09000 c0[0] = c3[0];
09001 c0[1] = c3[1];
09002 c0[2] = c3[2];
09003 first = FALSE_;
09004 } else {
09005
09006 /* Set C2 to C3, compute the new circumcenter C3, and compute */
09007 /* the area A of triangle (V1,C2,C3). */
09008
09009 c2[0] = c3[0];
09010 c2[1] = c3[1];
09011 c2[2] = c3[2];
09012 circum_(v1, v2, v3, c3, &ierr);
09013 if (ierr != 0) {
09014 goto L13;
09015 }
09016 a = areas_(v1, c2, c3);
09017 if (a > amax) {
09018 goto L14;
09019 }
09020 asum += a;
09021 }
09022
09023 /* Bottom on loop on neighbors of K. */
09024
09025 if (lp != lpl) {
09026 goto L1;
09027 }
09028
09029 /* Compute the area of triangle (V1,C3,C0). */
09030
09031 a = areas_(v1, c3, c0);
09032 if (a > amax) {
09033 goto L14;
09034 }
09035 asum += a;
09036
09037 /* No error encountered. */
09038
09039 *ier = 0;
09040 ret_val = asum;
09041 return ret_val;
09042
09043 /* Invalid input. */
09044
09045 L11:
09046 *ier = 1;
09047 ret_val = 0.;
09048 return ret_val;
09049
09050 /* K indexes a boundary node. */
09051
09052 L12:
09053 *ier = 2;
09054 ret_val = 0.;
09055 return ret_val;
09056
09057 /* Error in CIRCUM. */
09058
09059 L13:
09060 *ier = 3;
09061 ret_val = 0.;
09062 return ret_val;
09063
09064 /* AREAS value larger than AMAX. */
09065
09066 L14:
09067 *ier = 4;
09068 ret_val = 0.;
09069 return ret_val;
09070 } /* areav_ */
|
|
||||||||||||||||||||||||||||||||
|
The purpose of this function is to convert a list to grey code and mutate them and convert them back.
Definition at line 20646 of file util_sparx.cpp. References t. Referenced by image_mutation(). 20646 {
20647
20648 if (is_mirror != 0) {
20649 for (int i=0; i<len_list; i++) {
20650 int r = rand()%10000;
20651 float f = r/10000.0f;
20652 if (f < mutation_rate) list[i] = 1-list[i];
20653 }
20654 } else {
20655 map<int, vector<int> > graycode;
20656 map<vector<int>, int> rev_graycode;
20657 vector <int> gray;
20658
20659 int K=1;
20660 for (int i=0; i<L; i++) K*=2;
20661
20662 for (int k=0; k<K; k++) {
20663 int shift = 0;
20664 vector <int> gray;
20665 for (int i=L-1; i>-1; i--) {
20666 int t = ((k>>i)%2-shift)%2;
20667 gray.push_back(t);
20668 shift += t-2;
20669 }
20670 graycode[k] = gray;
20671 rev_graycode[gray] = k;
20672 }
20673
20674 float gap = (K-1)/(max_val-min_val);
20675 for (int i=0; i<len_list; i++) {
20676 float val = list[i];
20677 if (val < min_val) { val = min_val; }
20678 else if (val > max_val) { val = max_val; }
20679 int k = int((val-min_val)*gap+0.5);
20680 vector<int> gray = graycode[k];
20681 bool changed = false;
20682 for (vector<int>::iterator p=gray.begin(); p!=gray.end(); p++) {
20683 int r = rand()%10000;
20684 float f = r/10000.0f;
20685 if (f < mutation_rate) {
20686 *p = 1-*p;
20687 changed = true;
20688 }
20689 }
20690 if (changed) {
20691 k = rev_graycode[gray];
20692 list[i] = k/gap+min_val;
20693 }
20694 }
20695 }
20696
20697 }
|
|
||||||||||||||||
|
Definition at line 18028 of file util_sparx.cpp. References flag, peak_table::index, and peak_table::value. 18028 {
18029
18030 int kt = nref;
18031 unsigned int maxasi = nima/nref;
18032 vector< vector<int> > id_list;
18033 id_list.resize(nref);
18034 int group, ima;
18035
18036 peak_table* dd = new peak_table[nref*nima];
18037 for (int i=0; i<nref*nima; i++) {
18038 dd[i].value = d[i];
18039 dd[i].index = i;
18040 }
18041 sort(dd, dd+nref*nima);
18042 int begin = 0;
18043
18044 bool* del_row = new bool[nref];
18045 for (int i=0; i<nref; i++) del_row[i] = false;
18046 bool* del_column = new bool[nima];
18047 for (int i=0; i<nima; i++) del_column[i] = false;
18048 while (kt > 0) {
18049 bool flag = true;
18050 while (flag) {
18051 int l = dd[begin].index;
18052 group = l/nima;
18053 ima = l%nima;
18054 if (del_column[ima] || del_row[group]) begin++;
18055 else flag = false;
18056 }
18057
18058 id_list[group].push_back(ima);
18059 if (kt > 1) {
18060 if (id_list[group].size() < maxasi) group = -1;
18061 else kt -= 1;
18062 } else {
18063 if (id_list[group].size() < maxasi+nima%nref) group = -1;
18064 else kt -= 1;
18065 }
18066 del_column[ima] = true;
18067 if (group != -1) {
18068 del_row[group] = true;
18069 }
18070 }
18071
18072 vector<int> id_list_1;
18073 for (int iref=0; iref<nref; iref++)
18074 for (unsigned int im=0; im<maxasi; im++)
18075 id_list_1.push_back(id_list[iref][im]);
18076 for (unsigned int im=maxasi; im<maxasi+nima%nref; im++)
18077 id_list_1.push_back(id_list[group][im]);
18078 id_list_1.push_back(group);
18079
18080 delete[] del_row;
18081 delete[] del_column;
18082 delete[] dd;
18083 return id_list_1;
18084 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
K is the number of classes in each partition (should be the same for all partitions) the first element of each class is its original index in the partition, and second is dummy var MPI: if nTop <= 0, then initial prune is called, and the pruned partitions are returned in a 1D array. The first element is reserved for max_levels (the size of the smallest partition after pruning). if nTop > 0, then partitions are assumed to have been pruned, where only dummy variables of un-pruned partitions are set to 1, and findTopLargest is called to find the top weighted matches. The matches, where each match is preceded by its cost, is returned in a one dimensional vector. essentially the same as bb_enumerate but with the option to do mpi version. Definition at line 21064 of file util_sparx.cpp. References branchMPI(), initial_prune(), and sanitycheck(). 21065 {
21066
21067
21068 // Indices is an nParts*K int array storing the index (into argparts) of the first element of the i-th class of the j-th partition
21069 // So Indices[j*K + i] is the offset from argparts of the first element of the first element of the i-th class of the j-th partition
21070 // Make a vector of nParts vectors of K int* each
21071 int* Indices = new int[nParts*K];
21072 int ind_c = 0;
21073 for (int i=0; i < nParts; i++){
21074 for(int j = 0; j < K; j++){
21075 Indices[i*K + j] = ind_c;
21076 ind_c = ind_c + dimClasses[i*K + j];
21077 }
21078 }
21079
21080 // do initial pruning on argParts and return the pruned partitions
21081
21082 // Make a vector of nParts vectors of K int* each
21083 vector <vector <int*> > Parts(nParts,vector<int*>(K));
21084 ind_c = 0;
21085 int argParts_size=0;
21086 for (int i=0; i < nParts; i++){
21087 for(int j = 0; j < K; j++){
21088 Parts[i][j] = argParts + ind_c;
21089 ind_c = ind_c + dimClasses[i*K + j];
21090 argParts_size = argParts_size + dimClasses[i*K + j];
21091 }
21092 }
21093
21094 // in the following we call initial_prune with Parts which is a vector. This is not the most
21095 // efficient since vector does not allow for direct addressing. But since initial_prune doesn't have very high complexity, and
21096 // the running time for 7 partitions with 288 classes per partition is a couple of minutes at most, i'll just leave it for now.....
21097
21098 // comment out for testing
21099 Util::initial_prune(Parts, dimClasses, nParts, K, T);
21100 for(int i = 0; i < nParts; i++){
21101 for(int j=0; j < K; j++){
21102 argParts[Indices[i*K + j]+1] = -1;
21103 }
21104 }
21105
21106 int num_classes;
21107 int old_index;
21108 for(int i=0; i<nParts; i++){
21109 num_classes = Parts[i].size();// number of classes in partition i after pruning
21110 for (int j=0; j < num_classes; j++){
21111 old_index = Parts[i][j][0];
21112 //cout << "old_index: " << old_index<<"\n";
21113 argParts[Indices[i*K + old_index]+1] = 1;
21114 }
21115 }
21116
21117
21118 // if we're not doing mpi then keep going and call branchMPI and return the output
21119 //cout <<"begin partition matching\n";
21120 //int* dummy(0);
21121 int* output = Util::branchMPI(argParts, Indices,dimClasses, nParts, K, T, 0, n_guesses, LARGEST_CLASS, J, max_branching, stmult, branchfunc, LIM);
21122
21123 //cout<<"total cost: "<<*output<<"\n";
21124 //cout<<"number of matches: "<<*(output+1)<<"\n";
21125 // now go check if the matches are sensical! i.e, if the matches are feasible, if the sum of the match weights in output is equal to *output, and if each match in output has weight at least T
21126 bool correct = Util::sanitycheck(argParts, Indices,dimClasses, nParts, K, T,output);
21127
21128 delete[] Indices;
21129
21130 // something is wrong with output of branchMPI!
21131 if (correct < 1){
21132 cout << "something is wrong with output of branchMPI!\n";
21133 vector<int> ret(1);
21134 ret[0] = -1;
21135 if (output != 0) { delete[] output; output = 0; }
21136 return ret;
21137 }
21138
21139 // output is not nonsense, so now put it into a single dimension vector and return
21140 // output is an int array, the first element is the cost of the output solution, the second element is the total number of matches in the solution
21141 // and the rest is the list of matches. output is one dimensional
21142
21143 int output_size = 2 + output[1] * nParts;
21144 vector<int> ret(output_size);
21145 for (int i = 0; i < output_size; i++) {
21146 ret[i]= output[i];
21147 }
21148 if (output != 0) { delete[] output; output = 0; }
21149 return ret;
21150
21151 }
|
|
||||||||||||||||||||||||
|
Definition at line 2310 of file util_sparx.cpp. References xim. 02311 {
02312 /*
02313 c purpose: linear interpolation
02314 Optimized for speed, circular closer removed, checking of ranges removed
02315 */
02316 float bilinear;
02317 int ixold, iyold;
02318
02319 /*
02320 float xdif, ydif, xrem, yrem;
02321 ixold = (int) floor(xold);
02322 iyold = (int) floor(yold);
02323 ydif = yold - iyold;
02324 yrem = 1.0f - ydif;
02325
02326 // May want to insert if?
02327 // IF ((IYOLD .GE. 1 .AND. IYOLD .LE. NROW-1) .AND.
02328 // & (IXOLD .GE. 1 .AND. IXOLD .LE. NSAM-1)) THEN
02329 //c INSIDE BOUNDARIES OF OUTPUT IMAGE
02330 xdif = xold - ixold;
02331 xrem = 1.0f- xdif;
02332 // RBUF(K) = YDIF*(BUF(NADDR+NSAM)*XREM
02333 // & +BUF(NADDR+NSAM+1)*XDIF)
02334 // & +YREM*(BUF(NADDR)*XREM + BUF(NADDR+1)*XDIF)
02335 bilinear = ydif*(xim(ixold,iyold+1)*xrem + xim(ixold+1,iyold+1)*xdif) +
02336 yrem*(xim(ixold,iyold)*xrem+xim(ixold+1,iyold)*xdif);
02337
02338 return bilinear;
02339 }
02340 */
02341 float xdif, ydif;
02342
02343 ixold = (int) xold;
02344 iyold = (int) yold;
02345 ydif = yold - iyold;
02346
02347 // May want to insert it?
02348 // IF ((IYOLD .GE. 1 .AND. IYOLD .LE. NROW-1) .AND.
02349 // & (IXOLD .GE. 1 .AND. IXOLD .LE. NSAM-1)) THEN
02350 //c INSIDE BOUNDARIES OF OUTPUT IMAGE
02351 xdif = xold - ixold;
02352 bilinear = xim(ixold, iyold) + ydif* (xim(ixold, iyold+1) - xim(ixold, iyold)) +
02353 xdif* (xim(ixold+1, iyold) - xim(ixold, iyold) +
02354 ydif* (xim(ixold+1, iyold+1) - xim(ixold+1, iyold) - xim(ixold, iyold+1) + xim(ixold, iyold)) );
02355
02356 return bilinear;
02357 }
|
|
||||||||||||||||||||||||||||
|
Calculate bilinear interpolation.
Definition at line 1492 of file util.h. Referenced by EMAN::StandardProjector::project3d(), EMAN::EMData::sget_value_at_interp(), and EMAN::TransformProcessor::transform(). |
|
||||||||||||||||
|
Definition at line 5761 of file util_sparx.cpp. References B, CUBE, DM, EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::Transform::get_params(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), and t. 05762 {
05763
05764 float *Bptr = B->get_data();
05765 float *CUBEptr = CUBE->get_data();
05766
05767 int NSAM,NROW,NX3D,NY3D,NZC,KZ,IQX,IQY,LDPX,LDPY,LDPZ,LDPNMX,LDPNMY,NZ1;
05768 float DIPX,DIPY,XB,YB,XBB,YBB;
05769
05770 Transform * t = B->get_attr("xform.projection");
05771 Dict d = t->get_params("spider");
05772 if(t) {delete t; t=0;}
05773 // Unsure about sign of shifts, check later PAP 06/28/09
05774 float x_shift = d[ "tx" ];
05775 float y_shift = d[ "ty" ];
05776 x_shift = -x_shift;
05777 y_shift = -y_shift;
05778
05779 NSAM = B->get_xsize();
05780 NROW = B->get_ysize();
05781 NX3D = CUBE->get_xsize();
05782 NY3D = CUBE->get_ysize();
05783 NZC = CUBE->get_zsize();
05784
05785
05786 LDPX = NX3D/2 +1;
05787 LDPY = NY3D/2 +1;
05788 LDPZ = NZC/2 +1;
05789 LDPNMX = NSAM/2 +1;
05790 LDPNMY = NROW/2 +1;
05791 NZ1 = 1;
05792
05793 for(int K=1;K<=NZC;K++) {
05794 KZ=K-1+NZ1;
05795 for(int J=1;J<=NY3D;J++) {
05796 XBB = (1-LDPX)*DM(1)+(J-LDPY)*DM(2)+(KZ-LDPZ)*DM(3);
05797 YBB = (1-LDPX)*DM(4)+(J-LDPY)*DM(5)+(KZ-LDPZ)*DM(6);
05798 for(int I=1;I<=NX3D;I++) {
05799 XB = (I-1)*DM(1)+XBB-x_shift;
05800 IQX = int(XB+float(LDPNMX));
05801 if (IQX <1 || IQX >= NSAM) continue;
05802 YB = (I-1)*DM(4)+YBB-y_shift;
05803 IQY = int(YB+float(LDPNMY));
05804 if (IQY<1 || IQY>=NROW) continue;
05805 DIPX = XB+LDPNMX-IQX;
05806 DIPY = YB+LDPNMY-IQY;
05807
05808 CUBE(I,J,K) = CUBE(I,J,K)+B(IQX,IQY)+DIPY*(B(IQX,IQY+1)-B(IQX,IQY))+DIPX*(B(IQX+1,IQY)-B(IQX,IQY)+DIPY*(B(IQX+1,IQY+1)-B(IQX+1,IQY)-B(IQX,IQY+1)+B(IQX,IQY)));
05809 }
05810 }
05811 }
05812 }
|
|
||||||||||||||||||||||||||||||||||||
|
Definition at line 21320 of file util_sparx.cpp. References B, branch_all, and costlist_global. Referenced by branchMPI(). 21320 {
21321
21322 int ntot=0;
21323 for (int jit=0; jit < J; jit++){
21324 if (*(costlist+jit) > T) ntot++;
21325 }
21326
21327 int cur;
21328 // sort matchlist by cost
21329 int* indx = new int[J];
21330 for (int jit=0; jit < J; jit++) indx[jit]=jit;
21331 vector<int> myindx (indx, indx+J);
21332 vector<int>::iterator it;
21333 costlist_global=costlist;
21334 sort(myindx.begin(), myindx.begin()+J, jiafunc);
21335
21336 // put matchlist in the order of mycost
21337 int* templist = new int[J];
21338 int* temp2list = new int[J*nParts];
21339 int next = 0;
21340
21341 for (it=myindx.begin(); it!=myindx.end();++it){
21342 cur = *(costlist + *it);
21343 if (cur > T){
21344
21345 templist[next] = cur;
21346 for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt];
21347 next = next + 1;
21348 }
21349 }
21350
21351 for (int jit=0; jit < ntot; jit++){
21352 *(costlist+jit)=*(templist + jit);
21353 //cout <<*(costlist+jit)<<", ";
21354 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit];
21355 }
21356 //cout <<"\n";
21357
21358 delete [] indx;
21359 //compute the average
21360
21361 // partition matches into groups where matches in each group is mutually feasible, and matches from different groups are not feasible
21362 // The number of branches to explore are the mutually exclusive matches. Take the largest of these
21363
21364
21365 int B=1;
21366 int B_init=B;
21367 int infeasible=0;
21368
21369 for (int i=B_init; i<ntot; i++){
21370 if (i==ntot) continue;
21371 // look at the i-th match. branch on it only if it is infeasible with ALL previous matches we have decided to
21372 // branch on
21373 infeasible = 0;
21374 if (LIM < 0) LIM = B;
21375 for (int j=0; j<B; j++){
21376
21377 for (int vit=0; vit<nParts; vit++){
21378 if (temp2list[i*nParts+vit] == matchlist[j*nParts+vit]) {infeasible++; break;}
21379 }
21380 if (infeasible >= LIM) break;
21381 }
21382
21383 if (infeasible >= LIM){
21384 *(costlist+B)=*(templist+i);
21385 for (int vit=0; vit < nParts; vit++)
21386 *(matchlist+B*nParts + vit)=*(temp2list+i*nParts + vit);
21387 B=B+1;
21388 }
21389 }
21390
21391 delete [] templist;
21392 delete [] temp2list;
21393 //cout<<"**************************************** "<<B<<" ***************************\n";
21394
21395 if (branch_all < max_branching){
21396 if (B>1)
21397 {branch_all = branch_all + B -1 ; }
21398 }
21399 else B=1;
21400
21401 return B;
21402
21403
21404 }
|
|
||||||||||||||||||||||||||||||||||||||||
|
Definition at line 21408 of file util_sparx.cpp. References B, branch_all, and costlist_global. Referenced by branchMPI(). 21408 {
21409
21410 int ntot=0;
21411 for (int jit=0; jit < J; jit++){
21412 if (*(costlist+jit) > T) ntot++;
21413 }
21414
21415 int cur;
21416 // sort matchlist by cost
21417 int* indx = new int[J];
21418 for (int jit=0; jit < J; jit++) indx[jit]=jit;
21419 vector<int> myindx (indx, indx+J);
21420 vector<int>::iterator it;
21421 costlist_global=costlist;
21422 sort(myindx.begin(), myindx.begin()+J, jiafunc);
21423
21424 // put matchlist in the order of mycost
21425 int* templist = new int[J];
21426 int* temp2list = new int[J*nParts];
21427 int next = 0;
21428
21429 for (it=myindx.begin(); it!=myindx.end();++it){
21430 cur = *(costlist + *it);
21431 if (cur > T){
21432
21433 templist[next] = cur;
21434 for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt];
21435 next = next + 1;
21436 }
21437 }
21438
21439 for (int jit=0; jit < ntot; jit++){
21440 *(costlist+jit)=*(templist + jit);
21441 //cout <<*(costlist+jit)<<", ";
21442 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit];
21443 }
21444 //cout <<"\n";
21445
21446 delete [] indx;
21447 //compute the average
21448
21449 // partition matches into groups where matches in each group is mutually feasible, and matches from different groups are not feasible
21450 // The number of branches to explore are the mutually exclusive matches. Take the largest of these
21451
21452
21453 int B=1;
21454 int B_init=B;
21455 int infeasible=0;
21456 // if we're near the bottom of the tree then explore more... this is because the larger weights are not likely to change much,
21457 // whereas the smaller ones can have many permutations
21458 if (LIM < 0) LIM = ntot-1;
21459 for (int i=B_init; i<ntot; i++){
21460 if (i==ntot) continue;
21461 // look at the i-th match. branch on it only if it is infeasible with ALL previous matches we have decided to
21462 // branch on
21463 infeasible = 0;
21464
21465 for (int j=0; j<ntot; j++){
21466 if (j == i) continue;
21467 for (int vit=0; vit<nParts; vit++){
21468 if (temp2list[i*nParts+vit] == temp2list[j*nParts+vit]) {infeasible++; break;}
21469 }
21470 if (infeasible >= LIM) break;
21471 }
21472
21473 if (infeasible >= LIM){
21474 *(costlist+B)=*(templist+i);
21475 for (int vit=0; vit < nParts; vit++)
21476 *(matchlist+B*nParts + vit)=*(temp2list+i*nParts + vit);
21477 B=B+1;
21478 }
21479 }
21480
21481 delete [] templist;
21482 delete [] temp2list;
21483 //cout<<"**************************************** "<<B<<" ***************************\n";
21484
21485
21486 if (branch_all < max_branching){
21487 if (B>1)
21488 {branch_all = branch_all + B-1;}
21489 }
21490 else B=1;
21491
21492 return B;
21493
21494
21495 }
|
|
||||||||||||||||||||||||||||||||||||
|
Definition at line 21501 of file util_sparx.cpp. References B, branch_all, and costlist_global. Referenced by branchMPI(). 21501 {
21502 int sum=0;
21503 float average =0;
21504 int ntot=0;
21505 for (int jit=0; jit < J; jit++){
21506 if (*(costlist+jit) > T) {ntot++; sum = sum +*(costlist+jit);}
21507 }
21508 average = ((float)sum)/((float)ntot);
21509 int cur;
21510 // sort matchlist by cost
21511 int* indx = new int[J];
21512 for (int jit=0; jit < J; jit++) indx[jit]=jit;
21513 vector<int> myindx (indx, indx+J);
21514 vector<int>::iterator it;
21515 costlist_global=costlist;
21516 sort(myindx.begin(), myindx.begin()+J, jiafunc);
21517
21518 // put matchlist in the order of mycost
21519 int* templist = new int[J];
21520 int* temp2list = new int[J*nParts];
21521 int next = 0;
21522
21523 for (it=myindx.begin(); it!=myindx.end();++it){
21524 cur = *(costlist + *it);
21525 if (cur > T){
21526
21527 templist[next] = cur;
21528 for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt];
21529 next = next + 1;
21530 }
21531 }
21532
21533 for (int jit=0; jit < ntot; jit++){
21534 *(costlist+jit)=*(templist + jit);
21535 //cout <<*(costlist+jit)<<", ";
21536 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit];
21537 }
21538 //cout <<"\n";
21539
21540 delete [] indx;
21541 delete [] templist;
21542 delete [] temp2list;
21543
21544 if (ntot == 1) return 1;
21545
21546 // look at the average, standard dev etc. If standard dev very small, i.e., costs very similar, then branch on the similar
21547 // costs
21548 float sq_sum=0.0;
21549 //cout <<"costlist:";
21550 for (int i=0; i< ntot; i++){
21551 sq_sum = sq_sum + (float) pow((float) *(costlist+i) - average, (float)2.0);
21552 //cout <<*(costlist+i)<<", ";
21553 }
21554 //cout <<"\n";
21555
21556 float variance = sq_sum/ntot;
21557 float stdev = (float)pow((float)variance,(float)0.5);
21558
21559 //cout <<"stdev: "<<int(stdev)<<"\n";
21560
21561 int B=1;
21562 int largest = *costlist;
21563 //cout <<"largest: "<<largest<<"\n";
21564 for (int i=1; i<ntot; i++){
21565 int cur = *(costlist+i);
21566 if (largest-cur < (float)(stdev*stmult)) B++;
21567 else break;
21568
21569 }
21570 //cout <<"B: "<<B<<"\n";
21571 if (branch_all < max_branching){
21572 if (B>1)
21573 {branch_all = branch_all + B-1;}
21574 }
21575 else B=1;
21576
21577 return B;
21578
21579
21580 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
same as branch except the nFirst (=Levels[0]) possibilites for the first match are already chosen firstmatches stores the matches and corresponding cost, where each match is preceded by its cost.... output is an int array, the first element is the cost of the output solution, the second element is the total number of matches in the solution and the rest is the list of matches. output is in one dimensional form. Definition at line 21155 of file util_sparx.cpp. References branch_all, branch_factor_2(), branch_factor_3(), branch_factor_4(), branchMPI(), and search2(). 21156 {
21157
21158 //*************************************
21159 //testing search2
21160 if (1 == 0){
21161 cout <<"begin test search2\n";
21162 int* matchlist = new int[J*nParts];
21163 int* costlist = new int[J];
21164 for (int jit = 0; jit < nParts; jit++) *(costlist+jit) = 0;
21165 Util::search2(argParts,Indices, dimClasses, nParts, K, T, matchlist,costlist,J);
21166
21167 for (int jit = 0; jit < J; jit++) {
21168 cout << *(costlist +jit)<<": ";
21169 for (int yit = 0; yit < nParts; yit++)
21170 cout << *(matchlist + jit*nParts + yit)<<",";
21171 cout <<"\n";
21172
21173 }
21174 cout <<"end test search2\n";
21175 int* output = new int[1];
21176 output[0] = 1;
21177 delete [] matchlist;
21178 delete [] costlist;
21179 return output;
21180 }
21181 //**************************************
21182
21183 // Base Case: we're at a leaf, no more feasible matches possible
21184 if (curlevel > K -1){
21185 int* output = new int[2];
21186 output[0] = 0;
21187 output[1] = 0;
21188 return output;
21189 }
21190
21191 // branch dynamically depending on results of search 2!
21192
21193 int* matchlist = new int[J*nParts];
21194 int* costlist = new int[J];
21195 Util::search2(argParts, Indices, dimClasses, nParts, K, T, matchlist, costlist, J);
21196
21197
21198 // each class in the matches found by findTopLargest is encoded by the original index of the first element of the class in argPart
21199 // each match contains nParts classes, with the i-th class belonging to the i-th partition.
21200
21201 // if there are no feasible matches with cost gt T, then return 0
21202 for (int jit = 0; jit < J ; jit++){
21203
21204 if (costlist[jit] > T) break;
21205 if (jit == J-1){
21206 int* output = new int[2];
21207 output[0] = 0;
21208 output[1] = 0;
21209 delete[] matchlist;
21210 delete[] costlist;
21211 return output;
21212 }
21213 }
21214
21215
21216
21217 // note that costlist and matchlist are NOT sorted by weight, and branch factor takes care of that...
21218 if (curlevel==0) branch_all = 0;
21219
21220 int nBranches = -1;
21221
21222 if (branchfunc == 2)
21223 nBranches = branch_factor_2(costlist,matchlist,J, T, nParts, curlevel, max_branching, LIM); // branch based on distribution of top J (weighted) matches with cost > T
21224
21225 if (branchfunc == 3)
21226 nBranches = branch_factor_3(costlist,matchlist,J, T, nParts, curlevel, max_branching, K, LIM); // branch based on distribution of top J (weighted) matches with cost > T
21227
21228 if (branchfunc == 4)
21229 nBranches = branch_factor_4(costlist,matchlist,J, T, nParts, curlevel, max_branching, stmult); // branch based on distribution of top J (weighted) matches with cost > T
21230
21231 int* newcostlist= new int[nBranches];
21232 int* newmatchlist = new int[nBranches*nParts];
21233 for (int i=0; i<nBranches; i++){
21234 newcostlist[i] = costlist[i];
21235 for (int j=0; j< nParts; j++)
21236 newmatchlist[i*nParts + j] = matchlist[i*nParts + j];
21237 }
21238
21239 delete[] costlist;
21240 delete[] matchlist;
21241
21242 //int* output = new int[2];//initialize to placeholder
21243 int* output = new int[2+K*nParts];//initialize to placeholder
21244 output[0] = 0;
21245 output[1] = 0;
21246 // some temporary variables
21247 int old_index;
21248 int totalcost;
21249 int nmatches;
21250 //int offset;
21251
21252 for(int i=0; i < nBranches ; i++){
21253
21254 // consider the i-th match returned by findTopLargest
21255 //if (newcostlist[i] <= T) continue;
21256
21257 // mark the classes in the i-th match of matchlist as taken (using the dummy variable and -2), and then call branch again on argParts.
21258 // After branch returns, compute overall cost, unmark the classes just marked as 1 again in preparation for next loop.
21259
21260 for(int j=0; j < nParts; j++){
21261 // matchlist[i*nParts + j] is the original index of the class belonging to the j-th partition in the i-th match.
21262 old_index = newmatchlist[i*nParts + j];
21263 argParts[Indices[j*K+old_index] + 1] = -2;
21264 }
21265
21266
21267 int* ret = Util::branchMPI(argParts, Indices, dimClasses, nParts, K, T, curlevel+1, n_guesses, LARGEST_CLASS,
21268 J, max_branching, stmult,branchfunc, LIM);
21269
21270 // first element of ret is the total cost of all the matches in ret, and second element is the number of matches in ret
21271 totalcost = newcostlist[i] + ret[0];
21272
21273 //if (curlevel == 0) {
21274 // cout <<"totalcost*****************************************************************: "<<totalcost<<", costlist["<<i<<"]="<<newcostlist[i]<<", *ret="<<*ret<<", level: "<<curlevel<<"\n";
21275
21276 //}
21277 if (totalcost > output[0]) // option 1
21278 {
21279 nmatches = 1 + ret[1];
21280 //delete[] output; // get rid of the old maxreturn
21281 //output = new int[2+nmatches*nParts];
21282 output[0] = totalcost;
21283 output[1] = nmatches;
21284 int nret = 2+(nmatches-1)*nParts;
21285 for(int iret=2; iret < nret; iret++) output[iret] = ret[iret];
21286 for(int imax=0; imax < nParts; imax++) output[nret+imax] = newmatchlist[i*nParts + imax];
21287 }
21288
21289
21290 delete[] ret;
21291
21292 // unmark the marked classes in preparation for the next iteration
21293
21294 for(int j=0; j < nParts; j++){
21295 old_index = newmatchlist[i*nParts + j];
21296 argParts[Indices[j*K+old_index] + 1] = 1;
21297 }
21298
21299 }
21300
21301 delete[] newmatchlist;
21302 delete[] newcostlist;
21303
21304 return output;
21305 }
|
|
||||||||||||
|
|
|
|
Search the best FFT size with good primes. It supports FFT size up to 4096 now.
Definition at line 984 of file util.cpp. References Assert, and LOGERR. Referenced by EMAN::RTFExhaustiveAligner::align(), and EMAN::RotatePrecenterAligner::align(). 00985 {
00986 Assert(low >= 0);
00987
00988 //array containing valid sizes <1024 for speed
00989 static char *valid = NULL;
00990
00991 if (!valid) {
00992 valid = (char *) calloc(4096, 1);
00993
00994 for (float i2 = 1; i2 < 12.0; i2 += 1.0) {
00995
00996 float f1 = pow((float) 2.0, i2);
00997 for (float i3 = 0; i3 < 8.0; i3 += 1.0) {
00998
00999 float f2 = pow((float) 3.0, i3);
01000 for (float i5 = 0; i5 < 6.0; i5 += 1.0) {
01001
01002 float f3 = pow((float) 5.0, i5);
01003 for (float i7 = 0; i7 < 5.0; i7 += 1.0) {
01004
01005 float f = f1 * f2 * f3 * pow((float) 7.0, i7);
01006 if (f <= 4095.0) {
01007 int n = (int) f;
01008 valid[n] = 1;
01009 }
01010 }
01011 }
01012 }
01013 }
01014 }
01015
01016 for (int i = low; i < 4096; i++) {
01017 if (valid[i]) {
01018 return i;
01019 }
01020 }
01021
01022 LOGERR("Sorry, can only find good fft sizes up to 4096 right now.");
01023
01024 return 1;
01025 }
|
|
|
calculate bilinear least-square fit, z = a + b x + c y Takes a set of x,y,z vectors and produces an a,b,c vector does not accept error bars on z or return goodness of fit
Definition at line 548 of file util.cpp. References EMAN::Vec3f. Referenced by EMAN::PointArray::align_2d(). 00548 {
00549 unsigned int i;
00550
00551 // various sums used in the final solution
00552 double Sx=0,Sy=0,Sxy=0,Sxx=0,Syy=0,Sz=0,Sxz=0,Syz=0,S=0;
00553 for (i=0; i<p.size(); i+=3) {
00554 Sx+=p[i];
00555 Sy+=p[i+1];
00556 Sz+=p[i+2];
00557 Sxx+=p[i]*p[i];
00558 Syy+=p[i+1]*p[i+1];
00559 Sxy+=p[i]*p[i+1];
00560 S+=1.0;
00561 Sxz+=p[i]*p[i+2];
00562 Syz+=p[i+1]*p[i+2];
00563 }
00564 double d=S*Sxy*Sxy - 2*Sx*Sxy*Sy + Sxx*Sy*Sy + Sx*Sx*Syy - S*Sxx*Syy;
00565
00566 Vec3f ret(0,0,0);
00567
00568 ret[0]=static_cast<float>(-((Sxy*Sxz*Sy - Sx*Sxz*Syy + Sx*Sxy*Syz - Sxx*Sy*Syz - Sxy*Sxy*Sz +Sxx*Syy*Sz)/d));
00569 ret[1]=static_cast<float>(-((-Sxz*Sy*Sy + S*Sxz*Syy - S*Sxy*Syz + Sx*Sy*Syz + Sxy*Sy*Sz -Sx*Syy*Sz) /d));
00570 ret[2]=static_cast<float>(-((-S*Sxy*Sxz + Sx*Sxz*Sy - Sx*Sx*Syz + S*Sxx*Syz + Sx*Sxy*Sz -Sxx*Sy*Sz) /d));
00571
00572 return ret;
00573 }
|
|
||||||||||||||||||||||||||||||||
|
calculate the least square fit value.
Definition at line 509 of file util.cpp. References Assert, div(), NullPointerException, x, and y. Referenced by EMAN::OptVarianceCmp::cmp(), EMAN::LowpassAutoBProcessor::create_radial_func(), and EMAN::GradientRemoverProcessor::process_inplace(). 00511 {
00512 Assert(nitems > 0);
00513
00514 if (!data_x || !data_y || !slope || !intercept) {
00515 throw NullPointerException("null float pointer");
00516 }
00517 double sum = 0;
00518 double sum_x = 0;
00519 double sum_y = 0;
00520 double sum_xx = 0;
00521 double sum_xy = 0;
00522
00523 for (size_t i = 0; i < nitems; i++) {
00524 if ((!ignore_zero || (data_x[i] != 0 && data_y[i] != 0))&&(!absmax ||(data_y[i]<absmax && data_y[i]>-absmax))) {
00525 double y = data_y[i];
00526 double x = i;
00527 if (data_x) {
00528 x = data_x[i];
00529 }
00530
00531 sum_x += x;
00532 sum_y += y;
00533 sum_xx += x * x;
00534 sum_xy += x * y;
00535 sum++;
00536 }
00537 }
00538
00539 double div = sum * sum_xx - sum_x * sum_x;
00540 if (div == 0) {
00541 div = 0.0000001f;
00542 }
00543
00544 *intercept = (float) ((sum_xx * sum_y - sum_x * sum_xy) / div);
00545 *slope = (float) ((sum * sum_xy - sum_x * sum_y) / div);
00546 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Definition at line 6416 of file util_sparx.cpp. 06417 {
06418 long int q2_dim1, q2_offset, q_dim1, q_offset, i__1, i__2;
06419 float r__1;
06420 int tmp__i;
06421 long int i__, j;
06422 --s;
06423 --res;
06424 iu -= 3;
06425 cu -= 3;
06426 --x;
06427 long int klm2d;
06428 klm2d= *k+*k+2;
06429 klm2d=klm2d+klm2d;
06430 q_dim1 = klm2d;
06431 q_offset = 1 + q_dim1;
06432 q -= q_offset;
06433 q2_dim1 = klm2d;
06434 q2_offset = 1 + q2_dim1;
06435 q2 -= q2_offset;
06436 i__2=0;
06437 i__1 = *n - 1;
06438 tmp__i=0;
06439 for (j = 1; j <= i__1; ++j) {
06440 i__2 = *k;
06441 tmp__i+=1;
06442 for (i__ = 1; i__ <= i__2; ++i__) {
06443 r__1 = float(i__ - 1) /(float) *k / (*ps * 2);
06444 q2[i__ + j * q2_dim1] = pow(r__1, tmp__i);
06445 }
06446 }
06447 for (i__ = 1; i__ <= i__2; ++i__)
06448 { q2[i__ + *n * q2_dim1] = 1.f;
06449 q2[i__ + (*n + 1) * q2_dim1] = pw[i__-1];
06450 }
06451 vector<float> fit_res;
06452 fit_res=Util::lsfit(k, n, &klm2d, iswi, &q2[q2_offset], &q[q_offset], &x[1], &res[1], &cu[3], &s[1], &iu[3]);
06453 return fit_res;
06454 }
|
|
||||||||||||||||
|
Definition at line 5713 of file util_sparx.cpp. References DGR_TO_RAD, DM, and SS. 05714 {
05715 double CPHI,SPHI,CTHE,STHE,CPSI,SPSI;
05716 vector<float> DM,SS;
05717
05718 for(int i =0;i<9;i++) DM.push_back(0);
05719
05720 for(int i =0;i<6;i++) SS.push_back(0);
05721
05722 CPHI = cos(double(PHI)*DGR_TO_RAD);
05723 SPHI = sin(double(PHI)*DGR_TO_RAD);
05724 CTHE = cos(double(THETA)*DGR_TO_RAD);
05725 STHE = sin(double(THETA)*DGR_TO_RAD);
05726 CPSI = cos(double(PSI)*DGR_TO_RAD);
05727 SPSI = sin(double(PSI)*DGR_TO_RAD);
05728
05729 SS(1) = float(CPHI);
05730 SS(2) = float(SPHI);
05731 SS(3) = float(CTHE);
05732 SS(4) = float(STHE);
05733 SS(5) = float(CPSI);
05734 SS(6) = float(SPSI);
05735
05736 DM(1) = float(CPHI*CTHE*CPSI-SPHI*SPSI);
05737 DM(2) = float(SPHI*CTHE*CPSI+CPHI*SPSI);
05738 DM(3) = float(-STHE*CPSI);
05739 DM(4) = float(-CPHI*CTHE*SPSI-SPHI*CPSI);
05740 DM(5) = float(-SPHI*CTHE*SPSI+CPHI*CPSI);
05741 DM(6) = float(STHE*SPSI);
05742 DM(7) = float(STHE*CPHI);
05743 DM(8) = float(STHE*SPHI);
05744 DM(9) = float(CTHE);
05745
05746 Dict DMnSS;
05747 DMnSS["DM"] = DM;
05748 DMnSS["SS"] = SS;
05749
05750 return(DMnSS);
05751 }
|
|
||||||||||||||||||||||||||||
|
Definition at line 19825 of file util_sparx.cpp. References EMAN::EMData::cmp(), and EMAN::EMData::rot_scale_trans2D(). 19825 {
19826
19827 EMData *rot= new EMData();
19828 float ccc;
19829
19830 rot = image->rot_scale_trans2D(ang, sx, sy, 1.0);
19831 ccc = -rot->cmp("sqeuclidean", refim, Dict("mask", mask));
19832 delete rot;
19833 return ccc;
19834 }
|
|
||||||||||||||||||||||||||||||||
|
Definition at line 19862 of file util_sparx.cpp. References EMAN::EMData::cmp(), pi, and EMAN::EMData::rot_scale_conv7(). 19862 {
19863
19864 EMData *rot= new EMData();
19865 float ccc;
19866
19867 rot = image->rot_scale_conv7(static_cast<float>(ang*pi/180.0), sx, sy, kb, 1.0f);
19868 ccc = -rot->cmp("sqeuclidean", refim, Dict("mask", mask));
19869 delete rot;
19870 return ccc;
19871 }
|
|
||||||||||||
|
Change a file's extension and return the new filename. If the given new extension is empty, the old filename is not changed. If the old filename has no extension, add the new extension to it.
Definition at line 430 of file util.cpp. References Assert. Referenced by EMAN::EMUtil::get_image_type(), EMAN::ImagicIO::ImagicIO(), and EMAN::ImagicIO2::ImagicIO2(). 00432 {
00433 Assert(old_filename != "");
00434 if (ext == "") {
00435 return old_filename;
00436 }
00437
00438 string filename = old_filename;
00439 size_t dot_pos = filename.rfind(".");
00440 if (dot_pos != string::npos) {
00441 filename = filename.substr(0, dot_pos+1);
00442 }
00443 else {
00444 filename = filename + ".";
00445 }
00446 filename = filename + ext;
00447 return filename;
00448 }
|
|
||||||||||||
|
check whether a file starts with certain magic string.
Definition at line 194 of file util.cpp. References NullPointerException. Referenced by EMAN::VtkIO::is_valid(), EMAN::SalIO::is_valid(), EMAN::LstIO::is_valid(), EMAN::LstFastIO::is_valid(), and EMAN::AmiraIO::is_valid(). 00195 {
00196 if (!first_block || !magic) {
00197 throw NullPointerException("first_block/magic");
00198 }
00199
00200 const char *buf = static_cast < const char *>(first_block);
00201
00202 if (strncmp(buf, magic, strlen(magic)) == 0) {
00203 return true;
00204 }
00205 return false;
00206 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Definition at line 6601 of file util_sparx.cpp. 06603 {
06604
06605 long int q_dim1, q_offset, i__1, i__2;
06606 double d__1;
06607
06608 static long int i__, j;
06609 static double z__;
06610 static long int n1, n2, ia, ii, kk, in, nk, js;
06611 static double sn, zu, zv;
06612 static long int nk1, klm, nkl, jmn, jpn;
06613 static double cuv;
06614 static long int klm1, nkl1, klm2, kode, iimn, nklm, iter;
06615 static float xmin;
06616 static double xmax;
06617 static long int iout;
06618 static double xsum;
06619 static long int iineg, maxit;
06620 static double toler;
06621 static float error;
06622 static double pivot;
06623 static long int kforce, iphase;
06624 static double tpivot;
06625
06626 --s;
06627 --res;
06628 iu -= 3;
06629 cu -= 3;
06630 --x;
06631 q_dim1 = *klm2d;
06632 q_offset = 1 + q_dim1;
06633 q -= q_offset;
06634
06635 /* Function Body */
06636 maxit = 500;
06637 kode = 0;
06638 toler = 1e-4f;
06639 iter = 0;
06640 n1 = *n + 1;
06641 n2 = *n + 2;
06642 nk = *n + *k;
06643 nk1 = nk + 1;
06644 nkl = nk + *l;
06645 nkl1 = nkl + 1;
06646 klm = *k + *l + *m;
06647 klm1 = klm + 1;
06648 klm2 = klm + 2;
06649 nklm = *n + klm;
06650 kforce = 1;
06651 iter = 0;
06652 js = 1;
06653 ia = 0;
06654 /* SET UP LABELS IN Q. */
06655 i__1 = *n;
06656 for (j = 1; j <= i__1; ++j) {
06657 q[klm2 + j * q_dim1] = (double) j;
06658 /* L10: */
06659 }
06660 i__1 = klm;
06661 for (i__ = 1; i__ <= i__1; ++i__) {
06662 q[i__ + n2 * q_dim1] = (double) (*n + i__);
06663 if (q[i__ + n1 * q_dim1] >= 0.f) {
06664 goto L30;
06665 }
06666 i__2 = n2;
06667 for (j = 1; j <= i__2; ++j) {
06668 q[i__ + j * q_dim1] = -q[i__ + j * q_dim1];
06669 /* L20: */
06670 }
06671 L30:
06672 ;
06673 }
06674 /* SET UP PHASE 1 COSTS. */
06675 iphase = 2;
06676 i__1 = nklm;
06677 for (j = 1; j <= i__1; ++j) {
06678 cu[(j << 1) + 1] = 0.f;
06679 cu[(j << 1) + 2] = 0.f;
06680 iu[(j << 1) + 1] = 0;
06681 iu[(j << 1) + 2] = 0;
06682 /* L40: */
06683 }
06684 if (*l == 0) {
06685 goto L60;
06686 }
06687 i__1 = nkl;
06688 for (j = nk1; j <= i__1; ++j) {
06689 cu[(j << 1) + 1] = 1.f;
06690 cu[(j << 1) + 2] = 1.f;
06691 iu[(j << 1) + 1] = 1;
06692 iu[(j << 1) + 2] = 1;
06693 /* L50: */
06694 }
06695 iphase = 1;
06696 L60:
06697 if (*m == 0) {
06698 goto L80;
06699 }
06700 i__1 = nklm;
06701 for (j = nkl1; j <= i__1; ++j) {
06702 cu[(j << 1) + 2] = 1.f;
06703 iu[(j << 1) + 2] = 1;
06704 jmn = j - *n;
06705 if (q[jmn + n2 * q_dim1] < 0.f) {
06706 iphase = 1;
06707 }
06708 /* L70: */
06709 }
06710 L80:
06711 if (kode == 0) {
06712 goto L150;
06713 }
06714 i__1 = *n;
06715 for (j = 1; j <= i__1; ++j) {
06716 if ((d__1 = x[j]) < 0.) {
06717 goto L90;
06718 } else if (d__1 == 0) {
06719 goto L110;
06720 } else {
06721 goto L100;
06722 }
06723 L90:
06724 cu[(j << 1) + 1] = 1.f;
06725 iu[(j << 1) + 1] = 1;
06726 goto L110;
06727 L100:
06728 cu[(j << 1) + 2] = 1.f;
06729 iu[(j << 1) + 2] = 1;
06730 L110:
06731 ;
06732 }
06733 i__1 = *k;
06734 for (j = 1; j <= i__1; ++j) {
06735 jpn = j + *n;
06736 if ((d__1 = res[j]) < 0.) {
06737 goto L120;
06738 } else if (d__1 == 0) {
06739 goto L140;
06740 } else {
06741 goto L130;
06742 }
06743 L120:
06744 cu[(jpn << 1) + 1] = 1.f;
06745 iu[(jpn << 1) + 1] = 1;
06746 if (q[j + n2 * q_dim1] > 0.f) {
06747 iphase = 1;
06748 }
06749 goto L140;
06750 L130:
06751 cu[(jpn << 1) + 2] = 1.f;
06752 iu[(jpn << 1) + 2] = 1;
06753 if (q[j + n2 * q_dim1] < 0.f) {
06754 iphase = 1;
06755 }
06756 L140:
06757 ;
06758 }
06759 L150:
06760 if (iphase == 2) {
06761 goto L500;
06762 }
06763 /* COMPUTE THE MARGINAL COSTS. */
06764 L160:
06765 i__1 = n1;
06766 for (j = js; j <= i__1; ++j) {
06767 xsum = 0.;
06768 i__2 = klm;
06769 for (i__ = 1; i__ <= i__2; ++i__) {
06770 ii = (long int) q[i__ + n2 * q_dim1];
06771 if (ii < 0) {
06772 goto L170;
06773 }
06774 z__ = cu[(ii << 1) + 1];
06775 goto L180;
06776 L170:
06777 iineg = -ii;
06778 z__ = cu[(iineg << 1) + 2];
06779 L180:
06780 xsum += q[i__ + j * q_dim1] * z__;
06781 /* 180 XSUM = XSUM + Q(I,J)*Z */
06782 /* L190: */
06783 }
06784 q[klm1 + j * q_dim1] = xsum;
06785 /* L200: */
06786 }
06787 i__1 = *n;
06788 for (j = js; j <= i__1; ++j) {
06789 ii = (long int) q[klm2 + j * q_dim1];
06790 if (ii < 0) {
06791 goto L210;
06792 }
06793 z__ = cu[(ii << 1) + 1];
06794 goto L220;
06795 L210:
06796 iineg = -ii;
06797 z__ = cu[(iineg << 1) + 2];
06798 L220:
06799 q[klm1 + j * q_dim1] -= z__;
06800 /* L230: */
06801 }
06802 /* DETERMINE THE VECTOR TO ENTER THE BASIS. */
06803 L240:
06804 xmax = 0.f;
06805 if (js > *n) {
06806 goto L490;
06807 }
06808 i__1 = *n;
06809 for (j = js; j <= i__1; ++j) {
06810 zu = q[klm1 + j * q_dim1];
06811 ii = (long int) q[klm2 + j * q_dim1];
06812 if (ii > 0) {
06813 goto L250;
06814 }
06815 ii = -ii;
06816 zv = zu;
06817 zu = -zu - cu[(ii << 1) + 1] - cu[(ii << 1) + 2];
06818 goto L260;
06819 L250:
06820 zv = -zu - cu[(ii << 1) + 1] - cu[(ii << 1) + 2];
06821 L260:
06822 if (kforce == 1 && ii > *n) {
06823 goto L280;
06824 }
06825 if (iu[(ii << 1) + 1] == 1) {
06826 goto L270;
06827 }
06828 if (zu <= xmax) {
06829 goto L270;
06830 }
06831 xmax = zu;
06832 in = j;
06833 L270:
06834 if (iu[(ii << 1) + 2] == 1) {
06835 goto L280;
06836 }
06837 if (zv <= xmax) {
06838 goto L280;
06839 }
06840 xmax = zv;
06841 in = j;
06842 L280:
06843 ;
06844 }
06845 if (xmax <= toler) {
06846 goto L490;
06847 }
06848 if (q[klm1 + in * q_dim1] == xmax) {
06849 goto L300;
06850 }
06851 i__1 = klm2;
06852 for (i__ = 1; i__ <= i__1; ++i__) {
06853 q[i__ + in * q_dim1] = -q[i__ + in * q_dim1];
06854 /* L290: */
06855 }
06856 q[klm1 + in * q_dim1] = xmax;
06857 /* DETERMINE THE VECTOR TO LEAVE THE BASIS. */
06858 L300:
06859 if (iphase == 1 || ia == 0) {
06860 goto L330;
06861 }
06862 xmax = 0.f;
06863 i__1 = ia;
06864 for (i__ = 1; i__ <= i__1; ++i__) {
06865 z__ = (d__1 = q[i__ + in * q_dim1], abs(d__1));
06866 if (z__ <= xmax) {
06867 goto L310;
06868 }
06869 xmax = z__;
06870 iout = i__;
06871 L310:
06872 ;
06873 }
06874 if (xmax <= toler) {
06875 goto L330;
06876 }
06877 i__1 = n2;
06878 for (j = 1; j <= i__1; ++j) {
06879 z__ = q[ia + j * q_dim1];
06880 q[ia + j * q_dim1] = q[iout + j * q_dim1];
06881 q[iout + j * q_dim1] = z__;
06882 /* L320: */
06883 }
06884 iout = ia;
06885 --ia;
06886 pivot = q[iout + in * q_dim1];
06887 goto L420;
06888 L330:
06889 kk = 0;
06890 i__1 = klm;
06891 for (i__ = 1; i__ <= i__1; ++i__) {
06892 z__ = q[i__ + in * q_dim1];
06893 if (z__ <= toler) {
06894 goto L340;
06895 }
06896 ++kk;
06897 res[kk] = q[i__ + n1 * q_dim1] / z__;
06898 s[kk] = (double) i__;
06899 L340:
06900 ;
06901 }
06902 L350:
06903 if (kk > 0) {
06904 goto L360;
06905 }
06906 kode = 2;
06907 goto L590;
06908 L360:
06909 xmin = static_cast<float>( res[1] );
06910 iout = (long int) s[1];
06911 j = 1;
06912 if (kk == 1) {
06913 goto L380;
06914 }
06915 i__1 = kk;
06916 for (i__ = 2; i__ <= i__1; ++i__) {
06917 if (res[i__] >= xmin) {
06918 goto L370;
06919 }
06920 j = i__;
06921 xmin = static_cast<float>( res[i__] );
06922 iout = (long int) s[i__];
06923 L370:
06924 ;
06925 }
06926 res[j] = res[kk];
06927 s[j] = s[kk];
06928 L380:
06929 --kk;
06930 pivot = q[iout + in * q_dim1];
06931 ii = (long int) q[iout + n2 * q_dim1];
06932 if (iphase == 1) {
06933 goto L400;
06934 }
06935 if (ii < 0) {
06936 goto L390;
06937 }
06938 if (iu[(ii << 1) + 2] == 1) {
06939 goto L420;
06940 }
06941 goto L400;
06942 L390:
06943 iineg = -ii;
06944 if (iu[(iineg << 1) + 1] == 1) {
06945 goto L420;
06946 }
06947 /* 400 II = IABS(II) */
06948 L400:
06949 ii = abs(ii);
06950 cuv = cu[(ii << 1) + 1] + cu[(ii << 1) + 2];
06951 if (q[klm1 + in * q_dim1] - pivot * cuv <= toler) {
06952 goto L420;
06953 }
06954 /* BYPASS INTERMEDIATE VERTICES. */
06955 i__1 = n1;
06956 for (j = js; j <= i__1; ++j) {
06957 z__ = q[iout + j * q_dim1];
06958 q[klm1 + j * q_dim1] -= z__ * cuv;
06959 q[iout + j * q_dim1] = -z__;
06960 /* L410: */
06961 }
06962 q[iout + n2 * q_dim1] = -q[iout + n2 * q_dim1];
06963 goto L350;
06964 /* GAUSS-JORDAN ELIMINATION. */
06965 L420:
06966 if (iter < maxit) {
06967 goto L430;
06968 }
06969 kode = 3;
06970 goto L590;
06971 L430:
06972 ++iter;
06973 i__1 = n1;
06974 for (j = js; j <= i__1; ++j) {
06975 if (j != in) {
06976 q[iout + j * q_dim1] /= pivot;
06977 }
06978 /* L440: */
06979 }
06980 /* IF PERMITTED, USE SUBROUTINE COL OF THE DESCRIPTION */
06981 /* SECTION AND REPLACE THE FOLLOWING SEVEN STATEMENTS DOWN */
06982 /* TO AND INCLUDING STATEMENT NUMBER 460 BY.. */
06983 /* DO 460 J=JS,N1 */
06984 /* IF(J .EQ. IN) GO TO 460 */
06985 /* Z = -Q(IOUT,J) */
06986 /* CALL COL(Q(1,J), Q(1,IN), Z, IOUT, KLM1) */
06987 /* 460 CONTINUE */
06988 i__1 = n1;
06989 for (j = js; j <= i__1; ++j) {
06990 if (j == in) {
06991 goto L460;
06992 }
06993 z__ = -q[iout + j * q_dim1];
06994 i__2 = klm1;
06995 for (i__ = 1; i__ <= i__2; ++i__) {
06996 if (i__ != iout) {
06997 q[i__ + j * q_dim1] += z__ * q[i__ + in * q_dim1];
06998 }
06999 /* L450: */
07000 }
07001 L460:
07002 ;
07003 }
07004 tpivot = -pivot;
07005 i__1 = klm1;
07006 for (i__ = 1; i__ <= i__1; ++i__) {
07007 if (i__ != iout) {
07008 q[i__ + in * q_dim1] /= tpivot;
07009 }
07010 /* L470: */
07011 }
07012 q[iout + in * q_dim1] = 1.f / pivot;
07013 z__ = q[iout + n2 * q_dim1];
07014 q[iout + n2 * q_dim1] = q[klm2 + in * q_dim1];
07015 q[klm2 + in * q_dim1] = z__;
07016 ii = (long int) abs(z__);
07017 if (iu[(ii << 1) + 1] == 0 || iu[(ii << 1) + 2] == 0) {
07018 goto L240;
07019 }
07020 i__1 = klm2;
07021 for (i__ = 1; i__ <= i__1; ++i__) {
07022 z__ = q[i__ + in * q_dim1];
07023 q[i__ + in * q_dim1] = q[i__ + js * q_dim1];
07024 q[i__ + js * q_dim1] = z__;
07025 /* L480: */
07026 }
07027 ++js;
07028 goto L240;
07029 /* TEST FOR OPTIMALITY. */
07030 L490:
07031 if (kforce == 0) {
07032 goto L580;
07033 }
07034 if (iphase == 1 && q[klm1 + n1 * q_dim1] <= toler) {
07035 goto L500;
07036 }
07037 kforce = 0;
07038 goto L240;
07039 /* SET UP PHASE 2 COSTS. */
07040 L500:
07041 iphase = 2;
07042 i__1 = nklm;
07043 for (j = 1; j <= i__1; ++j) {
07044 cu[(j << 1) + 1] = 0.f;
07045 cu[(j << 1) + 2] = 0.f;
07046 /* L510: */
07047 }
07048 i__1 = nk;
07049 for (j = n1; j <= i__1; ++j) {
07050 cu[(j << 1) + 1] = 1.f;
07051 cu[(j << 1) + 2] = 1.f;
07052 /* L520: */
07053 }
07054 i__1 = klm;
07055 for (i__ = 1; i__ <= i__1; ++i__) {
07056 ii = (long int) q[i__ + n2 * q_dim1];
07057 if (ii > 0) {
07058 goto L530;
07059 }
07060 ii = -ii;
07061 if (iu[(ii << 1) + 2] == 0) {
07062 goto L560;
07063 }
07064 cu[(ii << 1) + 2] = 0.f;
07065 goto L540;
07066 L530:
07067 if (iu[(ii << 1) + 1] == 0) {
07068 goto L560;
07069 }
07070 cu[(ii << 1) + 1] = 0.f;
07071 L540:
07072 ++ia;
07073 i__2 = n2;
07074 for (j = 1; j <= i__2; ++j) {
07075 z__ = q[ia + j * q_dim1];
07076 q[ia + j * q_dim1] = q[i__ + j * q_dim1];
07077 q[i__ + j * q_dim1] = z__;
07078 /* L550: */
07079 }
07080 L560:
07081 ;
07082 }
07083 goto L160;
07084 L570:
07085 if (q[klm1 + n1 * q_dim1] <= toler) {
07086 goto L500;
07087 }
07088 kode = 1;
07089 goto L590;
07090 L580:
07091 if (iphase == 1) {
07092 goto L570;
07093 }
07094 /* PREPARE OUTPUT. */
07095 kode = 0;
07096 L590:
07097 xsum = 0.;
07098 i__1 = *n;
07099 for (j = 1; j <= i__1; ++j) {
07100 x[j] = 0.f;
07101 /* L600: */
07102 }
07103 i__1 = klm;
07104 for (i__ = 1; i__ <= i__1; ++i__) {
07105 res[i__] = 0.f;
07106 /* L610: */
07107 }
07108 i__1 = klm;
07109 for (i__ = 1; i__ <= i__1; ++i__) {
07110 ii = (long int) q[i__ + n2 * q_dim1];
07111 sn = 1.f;
07112 if (ii > 0) {
07113 goto L620;
07114 }
07115 ii = -ii;
07116 sn = -1.f;
07117 L620:
07118 if (ii > *n) {
07119 goto L630;
07120 }
07121 x[ii] = sn * q[i__ + n1 * q_dim1];
07122 goto L640;
07123 L630:
07124 iimn = ii - *n;
07125 res[iimn] = sn * q[i__ + n1 * q_dim1];
07126 if (ii >= n1 && ii <= nk) {
07127 xsum += q[i__ + n1 * q_dim1];
07128 }
07129 L640:
07130 ;
07131 }
07132 error = (float)xsum;
07133 return;
07134 }
|
|
|
Definition at line 20459 of file util_sparx.cpp. References dm, EMAN::EMData::get_xsize(), nx, and sqrt(). 20459 {
20460 // WORKS ONLY FOR NUMBER OF OBJECTS N=l^2 !!
20461 int nx = d->get_xsize();
20462 int N = 1 + int((sqrt(1.0 + 8.0*nx)-1.0)/2.0);
20463 int K = N/2;
20464 vector<float> group(N);
20465 if(N*(N-1)/2 != nx) {
20466 //print " incorrect dimension"
20467 return group;}
20468 //bool active[N]; //this does not compile in VS2005. --Grant Tang
20469 bool * active = new bool[N];
20470 for(int i=0; i<N; i++) active[i] = true;
20471
20472 float dm, qd;
20473 int ppi = 0, ppj = 0;
20474 for(int k=0; k<K; k++) {
20475 // find pairs of most similiar objects among active
20476 //cout<<" k "<<k<<endl;
20477 dm = 1.0e23f;
20478 for(int i=1; i<N; i++) {
20479 if(active[i]) {
20480 for(int j=0; j<i; j++) {
20481 if(active[j]) {
20482 qd = (*d)(i*(i - 1)/2 + j);
20483 if(qd < dm) {
20484 dm = qd;
20485 ppi = i;
20486 ppj = j;
20487 }
20488 }
20489 }
20490 }
20491 }
20492 group[2*k] = float(ppi);
20493 group[1+2*k] = float(ppj);
20494 active[ppi] = false;
20495 active[ppj] = false;
20496 }
20497
20498 delete [] active;
20499 active = NULL;
20500 return group;
20501 }
|
|
||||||||||||||||||||
|
Definition at line 20251 of file util_sparx.cpp. References assign, cent, dt, EMAN::EMData::get_xsize(), mono(), nx, q, and sqrt(). 20251 {
20252 int nx = d->get_xsize();
20253 int N = 1 + int((sqrt(1.0 + 8.0*nx)-1.0)/2.0);
20254 vector<float> out(N+K+2);
20255 if(N*(N-1)/2 != nx) {
20256 //print " incorrect dimension"
20257 return out;}
20258 // assign random objects as centers
20259 for(int i=0; i<N; i++) assign(i) = float(i);
20260 // shuffle
20261 for(int i=0; i<N; i++) {
20262 int j = Util::get_irand(0,N-1);
20263 float temp = assign(i);
20264 assign(i) = assign(j);
20265 assign(j) = temp;
20266 }
20267 for(int k=0; k<K; k++) cent(k) = float(assign(k));
20268 //for(int k=0; k<K; k++) cout<<cent(k)<<" ";cout<<endl;
20269 //
20270 for(int i=0; i<N; i++) assign(i) = 0.0f;
20271 float qm, dispold = 1.1e22f, disp = 1.0e22f, na=0.0f;
20272 bool change = true;
20273 int it = -1;
20274 int ct = -1;
20275 while ((change && disp < dispold) || ct > 0) {
20276
20277 change = false;
20278 dispold = disp;
20279 it++;
20280
20281 // dispersion is a sum of distance from objects to object center
20282 disp = 0.0f;
20283 ct = 0;
20284 for(int i=0; i<N; i++) {
20285 qm = 1.0e23f;
20286 for(int k=0; k<K; k++) {
20287 if(float(i) == cent(k)) {
20288 qm = 0.0f;
20289 na = (float)k;
20290 } else {
20291 float dt = (*d)(mono(i,int(cent(k))));
20292 if(dt < qm) {
20293 qm = dt;
20294 na = (float)k;
20295 }
20296 }
20297 }
20298
20299
20300 // Simulated annealing
20301 if(exp(-1.0/float(T)) > Util::get_irand(1,1000)/1000.0) {
20302 na = (float)(Util::get_irand(0, K));
20303 qm = (*d)(mono(i,int(na)));
20304 ct++;
20305 }
20306
20307 disp += qm;
20308
20309 if(na != assign(i)) {
20310 assign(i) = na;
20311 change = true;
20312 }
20313 }
20314
20315 //cout<<"Iteration: "<<it<< " disp " <<disp << " T " << T << " disturb " << ct << endl;
20316 T = T*F;
20317
20318 //for(int k=0; k<N; k++) cout<<assign(k)<<" ";cout<<endl;
20319 //print disp
20320 //print assign
20321 // find centers
20322 for(int k=0; k<K; k++) {
20323 qm = 1.0e23f;
20324 for(int i=0; i<N; i++) {
20325 if(assign(i) == float(k)) {
20326 float q = 0.0;
20327 for(int j=0; j<N; j++) {
20328 if(assign(j) == float(k)) {
20329 //it cannot be the same object
20330 if(i != j) q += (*d)(mono(i,j));
20331 //cout<<q<<" "<<i<<" "<<j<<" "<<k<<endl;}
20332 }
20333 }
20334 if(q < qm) {
20335 //cout<<qm<<" "<<q<<" "<<i<<" "<<k<<endl;
20336 qm = q;
20337 cent(k) = float(i);
20338 }
20339 }
20340 }
20341 }
20342 //for(int k=0; k<K; k++) cout<<cent(k)<<" ";cout<<endl;cout<<disp<<endl;
20343 }
20344 out[N+K] = disp;
20345 out[N+K+1] = float(it);
20346 return out;
20347 }
|
|
||||||||||||||||||||||||
|
2009-03-30 15:44:05 JB. Compute the discrepancy belong all common-lines Definition at line 5033 of file util_sparx.cpp. References data, EMAN::EMData::get_data(), and EMAN::EMData::get_xsize(). 05033 {
05034 double res = 0;
05035 double buf = 0;
05036 float* line_1;
05037 float* line_2;
05038 int i, n, ind;
05039 int lnlen = data[0]->get_xsize();
05040 for (n=0; n<n_lines; ++n) {
05041 ind = n*2;
05042 line_1 = data[seq[ind]]->get_data() + com[ind] * lnlen;
05043 line_2 = data[seq[ind+1]]->get_data() + com[ind+1] *lnlen;
05044 buf = 0;
05045 for (i=0; i<lnlen; ++i) {
05046 buf += (line_1[i]-line_2[i])*(line_1[i]-line_2[i]);
05047 }
05048 res += buf * weights[n];
05049 }
05050
05051 return res;
05052
05053 }
|
|
|
2009-03-25 15:35:05 JB. This function prepare rotation matrix for common-lines Definition at line 4810 of file util_sparx.cpp. 04810 {
04811 int nb_ori = Ori.size() / 4;
04812 int i, ind;
04813 float ph, th, ps;
04814 double cph, cth, cps, sph, sth, sps;
04815 vector<double> Rot(nb_ori*9);
04816 for (i=0; i<nb_ori; ++i){
04817 ind = i*4;
04818 // spider convention phi=psi-90, psi=phi+90
04819 ph = Ori[ind+2]-90;
04820 th = Ori[ind+1];
04821 ps = Ori[ind]+90;
04822 ph *= deg_rad;
04823 th *= deg_rad;
04824 ps *= deg_rad;
04825 // pre-calculate some trigo stuffs
04826 cph = cos(ph);
04827 cth = cos(th);
04828 cps = cos(ps);
04829 sph = sin(ph);
04830 sth = sin(th);
04831 sps = sin(ps);
04832 // fill rotation matrix
04833 ind = i*9;
04834 Rot[ind] = cph*cps-cth*sps*sph;
04835 Rot[ind+1] = cph*sps+cth*cps*sph;
04836 Rot[ind+2] = sth*sph;
04837 Rot[ind+3] = -sph*cps-cth*sps*cph;
04838 Rot[ind+4] = -sph*sps+cth*cps*cph;
04839 Rot[ind+5] = sth*cph;
04840 Rot[ind+6] = sth*sps;
04841 Rot[ind+7] = -sth*cps;
04842 Rot[ind+8] = cth;
04843 }
04844
04845 return Rot;
04846 }
|
|
||||||||||||||||||||
|
2009-03-26 10:46:14 JB. This function calculate all common-lines in space for Voronoi Definition at line 4978 of file util_sparx.cpp. References norm(), nx, ny, rad_deg, and sqrt(). 04978 {
04979 // seq is the pairwise index ij: 0, 1, 0, 2, 0, 3, 1, 2, 1, 3, 2, 3
04980 vector<double> cml(2*nlines); // [phi, theta] / line
04981 float ph1, th1;
04982 float ph2, th2;
04983 double nx, ny, nz;
04984 double norm;
04985 double sth1=0, sph1=0, cth1=0, cph1=0;
04986 double sth2, sph2, cth2, cph2;
04987 int l, ind, c;
04988 int mem = -1;
04989 for (l=0; l<nlines; ++l){
04990 c = 2*l;
04991 if (seq[c]!=mem){
04992 mem = seq[c];
04993 ind = 4*seq[c];
04994 ph1 = Ori[ind]*deg_rad;
04995 th1 = Ori[ind+1]*deg_rad;
04996 sth1 = sin(th1);
04997 sph1 = sin(ph1);
04998 cth1 = cos(th1);
04999 cph1 = cos(ph1);
05000 }
05001 ind = 4*seq[c+1];
05002 ph2 = Ori[ind]*deg_rad;
05003 th2 = Ori[ind+1]*deg_rad;
05004 sth2 = sin(th2);
05005 cth2 = cos(th2);
05006 sph2 = sin(ph2);
05007 cph2 = cos(ph2);
05008 // cross product
05009 nx = sth1*cph1*cth2 - cth1*sth2*cph2;
05010 ny = cth1*sth2*sph2 - cth2*sth1*sph1;
05011 nz = sth1*sph1*sth2*cph2 - sth1*cph1*sth2*sph2;
05012 norm = sqrt(nx*nx+ny*ny+nz*nz);
05013 nx /= norm;
05014 ny /= norm;
05015 nz /= norm;
05016 // apply mirror if need
05017 if (nz<0) {nx=-nx; ny=-ny; nz=-nz;}
05018 // compute theta and phi
05019 cml[c+1] = acos(nz);
05020 if (cml[c+1] == 0) {cml[c] = 0;}
05021 else {
05022 cml[c+1] *= rad_deg;
05023 if (cml[c+1] > 89.99) {cml[c+1] = 89.99;} // this fix some pb in Voronoi
05024 cml[c] = rad_deg * atan2(nx, ny);
05025 cml[c] = fmod(360 + cml[c], 360);
05026
05027 }
05028 }
05029
05030 return cml;
05031 }
|
|
||||||||||||||||
|
2009-03-25 15:35:53 JB. This function calculates common-lines between sinogram Definition at line 4879 of file util_sparx.cpp. References abs, b, nint180(), and rad_deg. 04879 {
04880 vector<int> com(2*(n_prj - 1));
04881 int a = i_prj*9;
04882 int i, b, c;
04883 int n1=0, n2=0;
04884 float vmax = 1 - 1.0e-6f;
04885 double r11, r12, r13, r23, r31, r32, r33;
04886
04887 c = 0;
04888 for (i=0; i<n_prj; ++i){
04889 if (i!=i_prj){
04890 b = i*9;
04891 // this is equivalent to R = A*B'
04892 r11 = Rot[a]*Rot[b]+Rot[a+1]*Rot[b+1]+Rot[a+2]*Rot[b+2];
04893 r12 = Rot[a]*Rot[b+3]+Rot[a+1]*Rot[b+4]+Rot[a+2]*Rot[b+5];
04894 r13 = Rot[a]*Rot[b+6]+Rot[a+1]*Rot[b+7]+Rot[a+2]*Rot[b+8];
04895 r23 = Rot[a+3]*Rot[b+6]+Rot[a+4]*Rot[b+7]+Rot[a+5]*Rot[b+8];
04896 r31 = Rot[a+6]*Rot[b]+Rot[a+7]*Rot[b+1]+Rot[a+8]*Rot[b+2];
04897 r32 = Rot[a+6]*Rot[b+3]+Rot[a+7]*Rot[b+4]+Rot[a+8]*Rot[b+5];
04898 r33 = Rot[a+6]*Rot[b+6]+Rot[a+7]*Rot[b+7]+Rot[a+8]*Rot[b+8];
04899 if (r33 > vmax) {
04900 n2 = 270;
04901 n1 = 270 + nint180((float)(rad_deg*atan2(r12, r11)));
04902 }
04903 else if (r33 < -vmax) {
04904 n2 = 270;
04905 n1 = 270 - nint180((float)(rad_deg*atan2(r12, r11)));
04906 } else {
04907 n2 = nint180((float)(rad_deg*atan2(r31, -r32)));
04908 n1 = nint180((float)(rad_deg*atan2(r13, r23)));
04909 if (n1 < 0) {n1 += 360;}
04910 if (n2 <= 0) {n2 = abs(n2);}
04911 else {n2 = 360 - n2;}
04912 }
04913
04914 if (n1 >= 360){n1 = n1 % 360;}
04915 if (n2 >= 360){n2 = n2 % 360;}
04916
04917 // store common-lines
04918 b = c*2;
04919 com[b] = n1;
04920 com[b+1] = n2;
04921 ++c;
04922 }
04923 }
04924
04925 return com;
04926
04927 }
|
|
||||||||||||||||||||
|
2009-03-30 15:35:07 JB. This function calculates all common-lines between sinogram Definition at line 4929 of file util_sparx.cpp. References abs, b, nint180(), and rad_deg. 04929 {
04930 vector<int> com(2*n_lines);
04931 int a=0, b, c, l;
04932 int n1=0, n2=0, mem=-1;
04933 float vmax = 1 - 1.0e-6f;
04934 double r11, r12, r13, r23, r31, r32, r33;
04935 c = 0;
04936 for (l=0; l<n_lines; ++l){
04937 c = 2*l;
04938 if (seq[c]!=mem){
04939 mem = seq[c];
04940 a = seq[c]*9;
04941 }
04942 b = seq[c+1]*9;
04943
04944 // this is equivalent to R = A*B'
04945 r11 = Rot[a]*Rot[b]+Rot[a+1]*Rot[b+1]+Rot[a+2]*Rot[b+2];
04946 r12 = Rot[a]*Rot[b+3]+Rot[a+1]*Rot[b+4]+Rot[a+2]*Rot[b+5];
04947 r13 = Rot[a]*Rot[b+6]+Rot[a+1]*Rot[b+7]+Rot[a+2]*Rot[b+8];
04948 r23 = Rot[a+3]*Rot[b+6]+Rot[a+4]*Rot[b+7]+Rot[a+5]*Rot[b+8];
04949 r31 = Rot[a+6]*Rot[b]+Rot[a+7]*Rot[b+1]+Rot[a+8]*Rot[b+2];
04950 r32 = Rot[a+6]*Rot[b+3]+Rot[a+7]*Rot[b+4]+Rot[a+8]*Rot[b+5];
04951 r33 = Rot[a+6]*Rot[b+6]+Rot[a+7]*Rot[b+7]+Rot[a+8]*Rot[b+8];
04952 if (r33 > vmax) {
04953 n2 = 270;
04954 n1 = 270 + nint180((float)(rad_deg*atan2(r12, r11)));
04955 }
04956 else if (r33 < -vmax) {
04957 n2 = 270;
04958 n1 = 270 - nint180((float)(rad_deg*atan2(r12, r11)));
04959 } else {
04960 n2 = nint180((float)(rad_deg*atan2(r31, -r32)));
04961 n1 = nint180((float)(rad_deg*atan2(r13, r23)));
04962 if (n1 < 0) {n1 += 360;}
04963 if (n2 <= 0) {n2 = abs(n2);}
04964 else {n2 = 360 - n2;}
04965 }
04966 if (n1 >= 360){n1 = n1 % 360;}
04967 if (n2 >= 360){n2 = n2 % 360;}
04968
04969 // store common-lines
04970 com[c] = n1;
04971 com[c+1] = n2;
04972 }
04973
04974 return com;
04975
04976 }
|
|
||||||||||||||||||||||||||||
|
This function prepare the line from sinogram by cutting off some frequencies, and creating the mirror part (complexe conjugate of the first part). Then both lines (mirror and without) are drop to the sinogram. line is in Fourrier space, ilf low frequency, ihf high frequency, nblines number of lines of the half sinogram (the non miror part), sino the sinogram, pos_line the position of the line in the sino. Definition at line 4792 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), nx, and EMAN::EMData::update(). 04792 {
04793 int j;
04794 int nx = sino->get_xsize();
04795 int i = nx * pos_line;
04796 float r1, r2;
04797 float *line_ptr = line->get_data();
04798 float *sino_ptr = sino->get_data();
04799 for (j=ilf;j<=ihf; j += 2) {
04800 r1 = line_ptr[j];
04801 r2 = line_ptr[j + 1];
04802 sino_ptr[i + j - ilf] = r1;
04803 sino_ptr[i + j - ilf + 1] = r2;
04804 sino_ptr[i + nx * nblines + j - ilf] = r1;
04805 sino_ptr[i + nx * nblines + j - ilf + 1] = -r2;
04806 }
04807 sino->update();
04808 }
|
|
||||||||||||||||||||||||||||||||||||
|
2009-03-26 11:37:53 JB. This function spin all angle psi and evaluate the partial discrepancy belong common-lines |
|
||||||||||||||||||||||||
|
2009-03-25 15:35:37 JB. this function update only one rotation amtrix according a new orientation Definition at line 4848 of file util_sparx.cpp. 04848 {
04849 float ph, ps;
04850 double cph, cth, cps, sph, sth, sps;
04851 int ind = iprj*9;
04852 // spider convention phi=psi-90, psi=phi+90
04853 ph = nps-90;
04854 ps = nph+90;
04855 ph *= deg_rad;
04856 th *= deg_rad;
04857 ps *= deg_rad;
04858 // pre-calculate some trigo stuffs
04859 cph = cos(ph);
04860 cth = cos(th);
04861 cps = cos(ps);
04862 sph = sin(ph);
04863 sth = sin(th);
04864 sps = sin(ps);
04865 // fill rotation matrix
04866 Rot[ind] = (float)(cph*cps-cth*sps*sph);
04867 Rot[ind+1] = (float)(cph*sps+cth*cps*sph);
04868 Rot[ind+2] = (float)(sth*sph);
04869 Rot[ind+3] = (float)(-sph*cps-cth*sps*cph);
04870 Rot[ind+4] = (float)(-sph*sps+cth*cps*cph);
04871 Rot[ind+5] = (float)(sth*cph);
04872 Rot[ind+6] = (float)(sth*sps);
04873 Rot[ind+7] = (float)(-sth*cps);
04874 Rot[ind+8] = (float)(cth);
04875
04876 return Rot;
04877 }
|
|
|
Definition at line 4702 of file util_sparx.cpp. References Assert, ori_t::id, ori_t::iphi, ori_t::itht, PI2, and vrdg(). 04702 {
04703 static const int NBIN = 100;
04704 int nline=cml.size()/2;
04705 vector<double> weights(nline);
04706
04707 vector<ori_t> angs(nline);
04708 for( int i=0; i < nline; ++i ) {
04709 angs[i].iphi = int( NBIN*cml[2*i] );
04710 angs[i].itht = int( NBIN*cml[2*i+1] );
04711 if( angs[i].itht == 180*NBIN ) angs[i].itht = 0;
04712 angs[i].id = i;
04713 }
04714
04715 //std::cout << "# of angs: " << angs.size() << std::endl;
04716
04717 std::sort( angs.begin(), angs.end(), cmpang() );
04718
04719 vector<float> newphi;
04720 vector<float> newtht;
04721 vector< vector<int> > indices;
04722
04723 int curt_iphi = -1;
04724 int curt_itht = -1;
04725 for(unsigned int i=0 ;i < angs.size(); ++i ) {
04726 if( angs[i].iphi==curt_iphi && angs[i].itht==curt_itht ) {
04727 Assert( indices.size() > 0 );
04728 indices.back().push_back(angs[i].id);
04729 } else {
04730 curt_iphi = angs[i].iphi;
04731 curt_itht = angs[i].itht;
04732
04733 newphi.push_back( float(curt_iphi)/NBIN );
04734 newtht.push_back( float(curt_itht)/NBIN );
04735 indices.push_back( vector<int>(1,angs[i].id) );
04736 }
04737 }
04738
04739 //std::cout << "# of indpendent ang: " << newphi.size() << std::endl;
04740
04741
04742 int num_agl = newphi.size();
04743
04744 if(num_agl>2) {
04745 vector<double> w=Util::vrdg(newphi, newtht);
04746
04747 Assert( w.size()==newphi.size() );
04748 Assert( indices.size()==newphi.size() );
04749
04750 for(unsigned int i=0; i < newphi.size(); ++i ) {
04751 /*
04752 std::cout << "phi,tht,w,n: ";
04753 std::cout << boost::format( "%10.3f" ) % newphi[i] << " ";
04754 std::cout << boost::format( "%10.3f" ) % newtht[i] << " ";
04755 std::cout << boost::format( "%8.6f" ) % w[i] << " ";
04756 std::cout << indices[i].size() << "(";
04757 */
04758
04759 for(unsigned int j=0; j < indices[i].size(); ++j ) {
04760 int id = indices[i][j];
04761 weights[id] = w[i]/indices[i].size();
04762 //std::cout << id << " ";
04763 }
04764
04765 //std::cout << ")" << std::endl;
04766
04767 }
04768 } else {
04769 cout<<"warning in Util.cml_weights"<<endl;
04770 double val = PI2/float(nline);
04771 for(int i=0; i<nline; i++) weights[i]=val;
04772 }
04773
04774 return weights;
04775
04776 }
|
|
||||||||||||
|
Definition at line 7272 of file util_sparx.cpp. References EMAN::Util::tmpstruct::theta1.
|
|
||||||||||||
|
Definition at line 7277 of file util_sparx.cpp. References EMAN::Util::tmpstruct::key1.
|
|
||||||||||||||||
|
Definition at line 5463 of file util_sparx.cpp. References nx. Referenced by cyclicshift(), and slicereverse(). 05463 {
05464 float* tmp = new float[nx];
05465 int n = (end - beg)/nx;
05466 int nhalf = n/2;
05467 for (int i = 0; i < nhalf; i++) {
05468 // swap col i and col n-1-i
05469 memcpy(tmp, beg+i*nx, nx*sizeof(float));
05470 memcpy(beg+i*nx, beg+(n-1-i)*nx, nx*sizeof(float));
05471 memcpy(beg+(n-1-i)*nx, tmp, nx*sizeof(float));
05472 }
05473 delete[] tmp;
05474 }
|
|
||||||||||||
|
Definition at line 6155 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, img_ptr, new_ptr, nx, ny, and EMAN::EMData::set_size(). 06156 {
06157 /***********
06158 ***get the size of the image for validation purpose
06159 **************/
06160 int nx = image->get_xsize(),ny = image->get_ysize(),nz = image->get_zsize(); //Aren't these implied? Please check and let me know, PAP.
06161 /********
06162 ***Exception Handle
06163 *************/
06164 if(nx != mask->get_xsize() || ny != mask->get_ysize() || nz != mask->get_zsize())
06165 throw ImageDimensionException("The dimension of the image does not match the dimension of the mask!");
06166
06167 size_t i, size = (size_t)nx*ny*nz;
06168
06169 float* img_ptr = image->get_data();
06170 float* mask_ptr = mask->get_data();
06171
06172 int ln=0; //length of the output image = number of points under the mask.
06173 for(i = 0;i < size;i++) if(mask_ptr[i] > 0.5f) ln++;
06174
06175 EMData* new_image = new EMData();
06176 new_image->set_size(ln,1,1); /* set size of the new image */
06177 float *new_ptr = new_image->get_data();
06178
06179 ln=-1;
06180 for(i = 0;i < size;i++){
06181 if(mask_ptr[i] > 0.5f) {
06182 ln++;
06183 new_ptr[ln]=img_ptr[i];
06184 }
06185 }
06186
06187 return new_image;
06188 }
|
|
||||||||||||||||||||
|
This file is a part of util.h, To use this file's functions, you should include "util.h" NEVER directly include this file.
Definition at line 6284 of file util_sparx.cpp. References covmat, eigval, eigvec, and ssyev_(). 06285 {
06286 // n size of the covariance/correlation matrix
06287 // covmat --- covariance/correlation matrix (n by n)
06288 // eigval --- returns eigenvalues
06289 // eigvec --- returns eigenvectors
06290
06291 ENTERFUNC;
06292
06293 int i;
06294
06295 // make a copy of covmat so that it will not be overwritten
06296 for ( i = 0 ; i < n * n ; i++ ) eigvec[i] = covmat[i];
06297
06298 char NEEDV = 'V';
06299 char UPLO = 'U';
06300 int lwork = -1;
06301 int info = 0;
06302 float *work, wsize;
06303
06304 // query to get optimal workspace
06305 ssyev_(&NEEDV, &UPLO, &n, eigvec, &n, eigval, &wsize, &lwork, &info);
06306 lwork = (int)wsize;
06307
06308 work = (float *)calloc(lwork, sizeof(float));
06309 // calculate eigs
06310 ssyev_(&NEEDV, &UPLO, &n, eigvec, &n, eigval, work, &lwork, &info);
06311 free(work);
06312 EXITFUNC;
06313 return info;
06314 }
|
|
||||||||||||
|
same function than Util::coveig but wrapped to use directly in python code
Definition at line 6316 of file util_sparx.cpp. References coveig(), covmat, eigval, eigvec, EMAN::Dict::size(), and status. 06317 {
06318
06319 ENTERFUNC;
06320 int len = covmatpy.size();
06321 float *eigvec;
06322 float *eigval;
06323 float *covmat;
06324 int status = 0;
06325 eigval = (float*)calloc(ncov,sizeof(float));
06326 eigvec = (float*)calloc(ncov*ncov,sizeof(float));
06327 covmat = (float*)calloc(ncov*ncov, sizeof(float));
06328
06329 const float *covmat_ptr;
06330 covmat_ptr = &covmatpy[0];
06331 for(int i=0;i<len;i++){
06332 covmat[i] = covmat_ptr[i];
06333 }
06334
06335 status = Util::coveig(ncov, covmat, eigval, eigvec);
06336
06337 vector<float> eigval_py(ncov);
06338 const float *eigval_ptr;
06339 eigval_ptr = &eigval[0];
06340 for(int i=0;i<ncov;i++){
06341 eigval_py[i] = eigval_ptr[i];
06342 }
06343
06344 vector<float> eigvec_py(ncov*ncov);
06345 const float *eigvec_ptr;
06346 eigvec_ptr = &eigvec[0];
06347 for(int i=0;i<ncov*ncov;i++){
06348 eigvec_py[i] = eigvec_ptr[i];
06349 }
06350
06351 Dict res;
06352 res["eigval"] = eigval_py;
06353 res["eigvec"] = eigvec_py;
06354
06355 EXITFUNC;
06356 return res;
06357 }
|
|
||||||||||||||||||||
|
Definition at line 3164 of file util_sparx.cpp. References circ1, circ2, fftr_d(), EMAN::EMData::get_data(), log(), numr, prb1d(), q, t, t7, and tot. 03164 {
03165 // neg = 0 straight, neg = 1 mirrored
03166 int nring = numr.size()/3;
03167 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
03168 int maxrin = numr[numr.size()-1];
03169 double qn; float tot;
03170 float *circ1 = circ1p->get_data();
03171 float *circ2 = circ2p->get_data();
03172 /*
03173 c checks single position, neg is flag for checking mirrored position
03174 c
03175 c input - fourier transforms of rings!
03176 c first set is conjugated (mirrored) if neg
03177 c circ1 already multiplied by weights!
03178 c automatic arrays
03179 dimension t(maxrin) removed +2 as it is only needed for other ffts
03180 double precision q(maxrin)
03181 double precision t7(-3:3)
03182 */
03183 float *t;
03184 double t7[7], *q;
03185 int i, j, k, ip, jc, numr3i, numr2i, jtot = 0;
03186 float pos;
03187
03188 #ifdef _WIN32
03189 ip = -(int)(log((float)maxrin)/log(2.0f));
03190 #else
03191 ip = -(int) (log2(maxrin));
03192 #endif //_WIN32
03193
03194 q = (double*)calloc(maxrin, sizeof(double));
03195 t = (float*)calloc(maxrin, sizeof(float));
03196
03197 // cout << *qn <<" " <<*tot<<" "<<ip<<endl;
03198 for (i=1; i<=nring; i++) {
03199 numr3i = numr(3,i);
03200 numr2i = numr(2,i);
03201
03202 t(1) = (circ1(numr2i)) * circ2(numr2i);
03203
03204 if (numr3i != maxrin) {
03205 // test .ne. first for speed on some compilers
03206 t(numr3i+1) = circ1(numr2i+1) * circ2(numr2i+1);
03207 t(2) = 0.0;
03208
03209 if (neg) {
03210 // first set is conjugated (mirrored)
03211 for (j=3;j<=numr3i;j=j+2) {
03212 jc = j+numr2i-1;
03213 t(j) =(circ1(jc))*circ2(jc)-(circ1(jc+1))*circ2(jc+1);
03214 t(j+1) = -(circ1(jc))*circ2(jc+1)-(circ1(jc+1))*circ2(jc);
03215 }
03216 } else {
03217 for (j=3;j<=numr3i;j=j+2) {
03218 jc = j+numr2i-1;
03219 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1);
03220 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc);
03221 }
03222 }
03223 for (j=1;j<=numr3i+1;j++) q(j) = q(j) + t(j);
03224 } else {
03225 t(2) = circ1(numr2i+1) * circ2(numr2i+1);
03226 if (neg) {
03227 // first set is conjugated (mirrored)
03228 for (j=3;j<=maxrin;j=j+2) {
03229 jc = j+numr2i-1;
03230 t(j) = (circ1(jc))*circ2(jc) - (circ1(jc+1))*circ2(jc+1);
03231 t(j+1) = -(circ1(jc))*circ2(jc+1) - (circ1(jc+1))*circ2(jc);
03232 }
03233 } else {
03234 for (j=3;j<=maxrin;j=j+2) {
03235 jc = j+numr2i-1;
03236 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1);
03237 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc);
03238 }
03239 }
03240 for (j = 1; j <= maxrin; j++) q(j) += t(j);
03241 }
03242 }
03243
03244 fftr_d(q,ip);
03245
03246 qn = -1.0e20;
03247 for (j=1;j<=maxrin;j++) {
03248 if (q(j) >= qn) {
03249 qn = q(j); jtot = j;
03250 }
03251 }
03252
03253 for (k=-3; k<=3; k++) {
03254 j = (jtot+k+maxrin-1)%maxrin + 1;
03255 t7(k+4) = q(j);
03256 }
03257
03258 prb1d(t7,7,&pos);
03259
03260 tot = (float)jtot + pos;
03261
03262 if (q) free(q);
03263 if (t) free(t);
03264
03265 Dict retvals;
03266 retvals["qn"] = qn;
03267 retvals["tot"] = tot;
03268 return retvals;
03269 }
|
|
||||||||||||||||||||||||
|
Definition at line 3271 of file util_sparx.cpp. References circ1, circ2, fftr_d(), EMAN::EMData::get_data(), log(), numr, prb1d(), q, EMAN::Dict::size(), t, t7, and tot. 03271 {
03272 // neg = 0 straight, neg = 1 mirrored
03273 int nring = numr.size()/3;
03274 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
03275 int maxrin = numr[numr.size()-1];
03276 double qn; float tot;
03277 float *circ1 = circ1p->get_data();
03278 float *circ2 = circ2p->get_data();
03279 /*
03280 c checks single position, neg is flag for checking mirrored position
03281 c
03282 c input - fourier transforms of rings!
03283 c first set is conjugated (mirrored) if neg
03284 c multiplication by weights!
03285 c automatic arrays
03286 dimension t(maxrin) removed +2 as it is only needed for other ffts
03287 double precision q(maxrin)
03288 double precision t7(-3:3)
03289 */
03290 float *t;
03291 double t7[7], *q;
03292 int i, j, k, ip, jc, numr3i, numr2i, jtot = 0;
03293 float pos;
03294
03295 #ifdef _WIN32
03296 ip = -(int)(log((float)maxrin)/log(2.0f));
03297 #else
03298 ip = -(int) (log2(maxrin));
03299 #endif //_WIN32
03300
03301 q = (double*)calloc(maxrin, sizeof(double));
03302 t = (float*)calloc(maxrin, sizeof(float));
03303
03304 // cout << *qn <<" " <<*tot<<" "<<ip<<endl;
03305 for (i=1;i<=nring;i++) {
03306 numr3i = numr(3,i);
03307 numr2i = numr(2,i);
03308
03309 t(1) = circ1(numr2i) * circ2(numr2i);
03310
03311 if (numr3i != maxrin) {
03312 // test .ne. first for speed on some compilers
03313 t(numr3i+1) = circ1(numr2i+1) * circ2(numr2i+1);
03314 t(2) = 0.0;
03315
03316 if (neg) {
03317 // first set is conjugated (mirrored)
03318 for (j=3; j<=numr3i; j=j+2) {
03319 jc = j+numr2i-1;
03320 t(j) = (circ1(jc))*circ2(jc)-(circ1(jc+1))*circ2(jc+1);
03321 t(j+1) = -(circ1(jc))*circ2(jc+1)-(circ1(jc+1))*circ2(jc);
03322 }
03323 } else {
03324 for (j=3; j<=numr3i; j=j+2) {
03325 jc = j+numr2i-1;
03326 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1);
03327 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc);
03328 }
03329 }
03330 for (j=1;j<=numr3i+1;j++) q(j) += t(j)*w[i-1];
03331 } else {
03332 t(2) = circ1(numr2i+1) * circ2(numr2i+1);
03333 if (neg) {
03334 // first set is conjugated (mirrored)
03335 for (j=3; j<=maxrin; j=j+2) {
03336 jc = j+numr2i-1;
03337 t(j) = (circ1(jc))*circ2(jc) - (circ1(jc+1))*circ2(jc+1);
03338 t(j+1) = -(circ1(jc))*circ2(jc+1) - (circ1(jc+1))*circ2(jc);
03339 }
03340 } else {
03341 for (j=3; j<=maxrin; j=j+2) {
03342 jc = j+numr2i-1;
03343 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1);
03344 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc);
03345 }
03346 }
03347 for (j = 1; j <= maxrin; j++) q(j) += t(j)*w[i-1];
03348 }
03349 }
03350
03351 fftr_d(q,ip);
03352
03353 qn = -1.0e20;
03354 for (j=1;j<=maxrin;j++) {
03355 //cout << j << " " << q(j) << endl;
03356 if (q(j) >= qn) {
03357 qn = q(j);
03358 jtot = j;
03359 }
03360 }
03361
03362 for (k=-3; k<=3; k++) {
03363 j = (jtot+k+maxrin-1)%maxrin + 1;
03364 t7(k+4) = q(j);
03365 }
03366
03367 prb1d(t7,7,&pos);
03368
03369 tot = (float)jtot + pos;
03370
03371 //if (q) free(q);
03372 if (t) free(t);
03373
03374 Dict retvals;
03375 //tot = 1;
03376 //qn = q(1);
03377 retvals["qn"] = qn;
03378 retvals["tot"] = tot;
03379
03380 if (q) free(q);
03381
03382 return retvals;
03383 }
|
|
||||||||||||||||
|
Definition at line 3385 of file util_sparx.cpp. References circ1, circ2, fftr_d(), EMAN::EMData::get_data(), log(), numr, prb1d(), q, EMAN::Dict::size(), t, t7, tmt, and tot. Referenced by multiref_polar_ali_2d(), multiref_polar_ali_2d_local(), and multiref_polar_ali_2d_peaklist(). 03385 {
03386 int nring = numr.size()/3;
03387 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
03388 int maxrin = numr[numr.size()-1];
03389 double qn; float tot; double qm; float tmt;
03390 float *circ1 = circ1p->get_data();
03391 float *circ2 = circ2p->get_data();
03392 /*
03393 c
03394 c checks both straight & mirrored positions
03395 c
03396 c input - fourier transforms of rings!!
03397 c circ1 already multiplied by weights!
03398 c
03399 */
03400
03401 // dimension circ1(lcirc),circ2(lcirc)
03402
03403 // t(maxrin), q(maxrin), t7(-3:3) //maxrin+2 removed
03404 double *t, *q, t7[7];
03405
03406 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0;
03407 float t1, t2, t3, t4, c1, c2, d1, d2, pos;
03408
03409 qn = 0.0f;
03410 qm = 0.0f;
03411 tot = 0.0f;
03412 tmt = 0.0f;
03413 #ifdef _WIN32
03414 ip = -(int)(log((float)maxrin)/log(2.0f));
03415 #else
03416 ip = -(int)(log2(maxrin));
03417 #endif //_WIN32
03418 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl;
03419
03420 // c - straight = circ1 * conjg(circ2)
03421 // zero q array
03422
03423 q = (double*)calloc(maxrin,sizeof(double));
03424
03425 // t - mirrored = conjg(circ1) * conjg(circ2)
03426 // zero t array
03427 t = (double*)calloc(maxrin,sizeof(double));
03428
03429 // premultiply arrays ie( circ12 = circ1 * circ2) much slower
03430 for (i=1; i<=nring; i++) {
03431
03432 numr3i = numr(3,i); // Number of samples of this ring
03433 numr2i = numr(2,i); // The beginning point of this ring
03434
03435 t1 = circ1(numr2i) * circ2(numr2i);
03436 q(1) += t1;
03437 t(1) += t1;
03438
03439 t1 = circ1(numr2i+1) * circ2(numr2i+1);
03440 if (numr3i == maxrin) {
03441 q(2) += t1;
03442 t(2) += t1;
03443 } else {
03444 q(numr3i+1) += t1;
03445 t(numr3i+1) += t1;
03446 }
03447
03448 for (j=3; j<=numr3i; j += 2) {
03449 jc = j+numr2i-1;
03450
03451 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i
03452 // ----- ----- ----- -----
03453 // t1 t2 t3 t4
03454 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i
03455 // ----- ----- ----- -----
03456 // t1 t2 t3 t4
03457
03458 c1 = circ1(jc);
03459 c2 = circ1(jc+1);
03460 d1 = circ2(jc);
03461 d2 = circ2(jc+1);
03462
03463 t1 = c1 * d1;
03464 t2 = c2 * d2;
03465 t3 = c1 * d2;
03466 t4 = c2 * d1;
03467
03468 q(j) += t1 + t2;
03469 q(j+1) += -t3 + t4;
03470 t(j) += t1 - t2;
03471 t(j+1) += -t3 - t4;
03472 }
03473 }
03474 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<" "<<t(j) <<endl;
03475 fftr_d(q,ip);
03476
03477 qn = -1.0e20;
03478 for (j=1; j<=maxrin; j++) {//cout <<" "<<j<<" "<<q(j) <<endl;
03479 if (q(j) >= qn) {
03480 qn = q(j);
03481 jtot = j;
03482 }
03483 }
03484
03485 for (k=-3; k<=3; k++) {
03486 j = ((jtot+k+maxrin-1)%maxrin)+1;
03487 t7(k+4) = q(j);
03488 }
03489
03490 // interpolate
03491 prb1d(t7,7,&pos);
03492 tot = (float)(jtot)+pos;
03493 // Do not interpolate
03494 //tot = (float)(jtot);
03495
03496 // mirrored
03497 fftr_d(t,ip);
03498
03499 // find angle
03500 qm = -1.0e20;
03501 for (j=1; j<=maxrin;j++) {//cout <<" "<<j<<" "<<t(j) <<endl;
03502 if ( t(j) >= qm ) {
03503 qm = t(j);
03504 jtot = j;
03505 }
03506 }
03507
03508 for (k=-3; k<=3; k++) {
03509 j = ((jtot+k+maxrin-1)%maxrin) + 1;
03510 t7(k+4) = t(j);
03511 }
03512
03513 // interpolate
03514
03515 prb1d(t7,7,&pos);
03516 tmt = float(jtot) + pos;
03517 // Do not interpolate
03518 //tmt = float(jtot);
03519
03520 free(t);
03521 free(q);
03522
03523 Dict retvals;
03524 retvals["qn"] = qn;
03525 retvals["tot"] = tot;
03526 retvals["qm"] = qm;
03527 retvals["tmt"] = tmt;
03528 return retvals;
03529 }
|
|
||||||||||||||||||||||||
|
Definition at line 3531 of file util_sparx.cpp. References circ1, circ2, fftr_d(), EMAN::EMData::get_data(), log(), numr, q, EMAN::Dict::size(), t, tmt, and tot. Referenced by multiref_polar_ali_2d_delta(). 03531 {
03532 int nring = numr.size()/3;
03533 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
03534 int maxrin = numr[numr.size()-1];
03535 double qn; float tot; double qm; float tmt;
03536 float *circ1 = circ1p->get_data();
03537 float *circ2 = circ2p->get_data();
03538 /*
03539 c
03540 c checks both straight & mirrored positions
03541 c
03542 c input - fourier transforms of rings!!
03543 c circ1 already multiplied by weights!
03544 c
03545 */
03546
03547 // dimension circ1(lcirc),circ2(lcirc)
03548
03549 // t(maxrin), q(maxrin), t7(-3:3) //maxrin+2 removed
03550 double *t, *q;
03551
03552 int ip, jc, numr3i, numr2i, i, j, jtot = 0;
03553 float t1, t2, t3, t4, c1, c2, d1, d2;
03554
03555 qn = 0.0f;
03556 qm = 0.0f;
03557 tot = 0.0f;
03558 tmt = 0.0f;
03559 #ifdef _WIN32
03560 ip = -(int)(log((float)maxrin)/log(2.0f));
03561 #else
03562 ip = -(int)(log2(maxrin));
03563 #endif //_WIN32
03564 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl;
03565
03566 // c - straight = circ1 * conjg(circ2)
03567 // zero q array
03568
03569 q = (double*)calloc(maxrin,sizeof(double));
03570
03571 // t - mirrored = conjg(circ1) * conjg(circ2)
03572 // zero t array
03573 t = (double*)calloc(maxrin,sizeof(double));
03574
03575 // premultiply arrays ie( circ12 = circ1 * circ2) much slower
03576 for (i=1; i<=nring; i++) {
03577
03578 numr3i = numr(3,i); // Number of samples of this ring
03579 numr2i = numr(2,i); // The beginning point of this ring
03580
03581 t1 = circ1(numr2i) * circ2(numr2i);
03582 q(1) += t1;
03583 t(1) += t1;
03584
03585 t1 = circ1(numr2i+1) * circ2(numr2i+1);
03586 if (numr3i == maxrin) {
03587 q(2) += t1;
03588 t(2) += t1;
03589 } else {
03590 q(numr3i+1) += t1;
03591 t(numr3i+1) += t1;
03592 }
03593
03594 for (j=3; j<=numr3i; j += 2) {
03595 jc = j+numr2i-1;
03596
03597 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i
03598 // ----- ----- ----- -----
03599 // t1 t2 t3 t4
03600 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i
03601 // ----- ----- ----- -----
03602 // t1 t2 t3 t4
03603
03604 c1 = circ1(jc);
03605 c2 = circ1(jc+1);
03606 d1 = circ2(jc);
03607 d2 = circ2(jc+1);
03608
03609 t1 = c1 * d1;
03610 t2 = c2 * d2;
03611 t3 = c1 * d2;
03612 t4 = c2 * d1;
03613
03614 q(j) += t1 + t2;
03615 q(j+1) += -t3 + t4;
03616 t(j) += t1 - t2;
03617 t(j+1) += -t3 - t4;
03618 }
03619 }
03620 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<" "<<t(j) <<endl;
03621 fftr_d(q,ip);
03622
03623 qn = -1.0e20;
03624
03625 int jstart = 1+static_cast<int>(delta_start/360.0*maxrin);
03626 int jstep = static_cast<int>(delta/360.0*maxrin);
03627 if (jstep < 1) { jstep = 1; }
03628
03629 for (j=jstart; j<=maxrin; j+=jstep) {//cout <<" "<<j<<" "<<q(j) <<endl;
03630 if (q(j) >= qn) {
03631 qn = q(j);
03632 jtot = j;
03633 }
03634 }
03635
03636 //for (k=-3; k<=3; k++) {
03637 // j = ((jtot+k+maxrin-1)%maxrin)+1;
03638 // t7(k+4) = q(j);
03639 //}
03640
03641 // interpolate
03642 //prb1d(t7,7,&pos);
03643 //tot = (float)(jtot)+pos;
03644 // Do not interpolate
03645 tot = (float)(jtot);
03646
03647 // mirrored
03648 fftr_d(t,ip);
03649
03650 // find angle
03651 qm = -1.0e20;
03652 for (j=jstart; j<=maxrin;j+=jstep) {//cout <<" "<<j<<" "<<t(j) <<endl;
03653 if ( t(j) >= qm ) {
03654 qm = t(j);
03655 jtot = j;
03656 }
03657 }
03658
03659 //for (k=-3; k<=3; k++) {
03660 // j = ((jtot+k+maxrin-1)%maxrin) + 1;
03661 // t7(k+4) = t(j);
03662 //}
03663
03664 // interpolate
03665
03666 //prb1d(t7,7,&pos);
03667 //tmt = float(jtot) + pos;
03668 // Do not interpolate
03669 tmt = float(jtot);
03670
03671 free(t);
03672 free(q);
03673
03674 Dict retvals;
03675 retvals["qn"] = qn;
03676 retvals["tot"] = tot;
03677 retvals["qm"] = qm;
03678 retvals["tmt"] = tmt;
03679 return retvals;
03680 }
|
|
||||||||||||||||
|
checks both straight & mirrored positions input - fourier transforms of rings!! circ1 already multiplied by weights! returns EM object with 1D ccf
Definition at line 4195 of file util_sparx.cpp. References circ1, circ1b, circ2, circ2b, dout, fftr_d(), EMAN::EMData::get_data(), log(), numr, q, EMAN::EMData::set_size(), and t. 04195 {
04196
04197 // dimension circ1(lcirc),circ2(lcirc)
04198
04199 int ip, jc, numr3i, numr2i, i, j;
04200 float t1, t2, t3, t4, c1, c2, d1, d2;
04201
04202 int nring = numr.size()/3;
04203 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
04204 int maxrin = numr[numr.size()-1];
04205
04206 float* circ1b = circ1->get_data();
04207 float* circ2b = circ2->get_data();
04208
04209 // t(maxrin), q(maxrin) // removed +2
04210 double *t, *q;
04211
04212 q = (double*)calloc(maxrin,sizeof(double));
04213 t = (double*)calloc(maxrin,sizeof(double));
04214
04215 #ifdef _WIN32
04216 ip = -(int)(log((float)maxrin)/log(2.0f));
04217 #else
04218 ip = -(int)(log2(maxrin));
04219 #endif //_WIN32
04220
04221 // q - straight = circ1 * conjg(circ2)
04222
04223 // t - mirrored = conjg(circ1) * conjg(circ2)
04224
04225 // premultiply arrays ie( circ12 = circ1 * circ2) much slower
04226
04227 for (i=1; i<=nring; i++) {
04228
04229 numr3i = numr(3,i);
04230 numr2i = numr(2,i);
04231
04232 t1 = circ1b(numr2i) * circ2b(numr2i);
04233 q(1) = q(1)+t1;
04234 t(1) = t(1)+t1;
04235
04236 t1 = circ1b(numr2i+1) * circ2b(numr2i+1);
04237 if (numr3i == maxrin) {
04238 q(2) += t1;
04239 t(2) += t1;
04240 } else {
04241 q(numr3i+1) += t1;
04242 t(numr3i+1) += t1;
04243 }
04244
04245 for (j=3; j<=numr3i; j=j+2) {
04246 jc = j+numr2i-1;
04247
04248 c1 = circ1b(jc);
04249 c2 = circ1b(jc+1);
04250 d1 = circ2b(jc);
04251 d2 = circ2b(jc+1);
04252
04253 t1 = c1 * d1;
04254 t3 = c1 * d2;
04255 t2 = c2 * d2;
04256 t4 = c2 * d1;
04257
04258 q(j) += t1 + t2;
04259 q(j+1) += - t3 + t4;
04260 t(j) += t1 - t2;
04261 t(j+1) += - t3 - t4;
04262 }
04263 }
04264
04265 // straight
04266 fftr_d(q,ip);
04267
04268 // mirrored
04269 fftr_d(t,ip);
04270
04271 EMData* out = new EMData();
04272 out->set_size(maxrin,2,1);
04273 float *dout = out->get_data();
04274 for (int i=0; i<maxrin; i++) {dout(i,0)=static_cast<float>(q[i]); dout(i,1)=static_cast<float>(t[i]);}
04275 //out->set_size(maxrin,1,1);
04276 //float *dout = out->get_data();
04277 //for (int i=0; i<maxrin; i++) {dout(i,0)=q[i];}
04278 free(t);
04279 free(q);
04280 return out;
04281 }
|
|
||||||||||||||||
|
This program is half of the Crosrng_msg. It only checks mirrored position. input - fourier transforms of rings!! circ1 already multiplied by weights! returns EM object with 1D ccf Definition at line 4442 of file util_sparx.cpp. References circ1, circ1b, circ2, circ2b, dout, fftr_d(), EMAN::EMData::get_data(), log(), numr, EMAN::EMData::set_size(), and t. 04443 {
04444
04445 int ip, jc, numr3i, numr2i, i, j;
04446 float t1, t2, t3, t4, c1, c2, d1, d2;
04447
04448 int nring = numr.size()/3;
04449 int maxrin = numr[numr.size()-1];
04450
04451 float* circ1b = circ1->get_data();
04452 float* circ2b = circ2->get_data();
04453
04454 double *t;
04455
04456 t = (double*)calloc(maxrin,sizeof(double));
04457
04458 #ifdef _WIN32
04459 ip = -(int)(log((float)maxrin)/log(2.0f));
04460 #else
04461 ip = -(int)(log2(maxrin));
04462 #endif //_WIN32
04463
04464 // t - mirrored = conjg(circ1) * conjg(circ2)
04465
04466 for (i=1;i<=nring;i++) {
04467
04468 numr3i = numr(3,i);
04469 numr2i = numr(2,i);
04470
04471 t1 = circ1b(numr2i) * circ2b(numr2i);
04472 t(1) = t(1)+t1;
04473
04474 if (numr3i == maxrin) {
04475 t1 = circ1b(numr2i+1) * circ2b(numr2i+1);
04476 t(2) = t(2)+t1;
04477 }
04478
04479 for (j=3;j<=numr3i;j=j+2) {
04480 jc = j+numr2i-1;
04481
04482 c1 = circ1b(jc);
04483 c2 = circ1b(jc+1);
04484 d1 = circ2b(jc);
04485 d2 = circ2b(jc+1);
04486
04487 t1 = c1 * d1;
04488 t3 = c1 * d2;
04489 t2 = c2 * d2;
04490 t4 = c2 * d1;
04491
04492 t(j) = t(j) + t1 - t2;
04493 t(j+1) = t(j+1) - t3 - t4;
04494 }
04495 }
04496
04497 // mirrored
04498 fftr_d(t,ip);
04499
04500 EMData* out = new EMData();
04501 out->set_size(maxrin,1,1);
04502 float *dout = out->get_data();
04503 for (int i=0; i<maxrin; i++) dout[i]=static_cast<float>(t[i]);
04504 free(t);
04505 return out;
04506
04507 }
|
|
||||||||||||||||
|
This program is half of the Crosrng_msg. It only checks straight position. input - fourier transforms of rings!! circ1 already multiplied by weights! returns EM object with 1D ccf Definition at line 4371 of file util_sparx.cpp. References circ1, circ1b, circ2, circ2b, dout, fftr_d(), EMAN::EMData::get_data(), log(), numr, q, and EMAN::EMData::set_size(). 04372 {
04373
04374 int ip, jc, numr3i, numr2i, i, j;
04375 float t1, t2, t3, t4, c1, c2, d1, d2;
04376
04377 int nring = numr.size()/3;
04378 int maxrin = numr[numr.size()-1];
04379
04380 float* circ1b = circ1->get_data();
04381 float* circ2b = circ2->get_data();
04382
04383 double *q;
04384
04385 q = (double*)calloc(maxrin,sizeof(double));
04386
04387 #ifdef _WIN32
04388 ip = -(int)(log((float)maxrin)/log(2.0f));
04389 #else
04390 ip = -(int)(log2(maxrin));
04391 #endif //_WIN32
04392
04393 // q - straight = circ1 * conjg(circ2)
04394
04395 for (i=1;i<=nring;i++) {
04396
04397 numr3i = numr(3,i);
04398 numr2i = numr(2,i);
04399
04400 t1 = circ1b(numr2i) * circ2b(numr2i);
04401 q(1) = q(1)+t1;
04402
04403 if (numr3i == maxrin) {
04404 t1 = circ1b(numr2i+1) * circ2b(numr2i+1);
04405 q(2) = q(2)+t1;
04406 } else {
04407 t1 = circ1b(numr2i+1) * circ2b(numr2i+1);
04408 q(numr3i+1) = q(numr3i+1)+t1;
04409 }
04410
04411 for (j=3;j<=numr3i;j=j+2) {
04412 jc = j+numr2i-1;
04413
04414 c1 = circ1b(jc);
04415 c2 = circ1b(jc+1);
04416 d1 = circ2b(jc);
04417 d2 = circ2b(jc+1);
04418
04419 t1 = c1 * d1;
04420 t3 = c1 * d2;
04421 t2 = c2 * d2;
04422 t4 = c2 * d1;
04423
04424 q(j) = q(j) + t1 + t2;
04425 q(j+1) = q(j+1) - t3 + t4;
04426 }
04427 }
04428
04429 // straight
04430 fftr_d(q,ip);
04431
04432 EMData* out = new EMData();
04433 out->set_size(maxrin,1,1);
04434 float *dout = out->get_data();
04435 for (int i=0; i<maxrin; i++) dout[i]=static_cast<float>(q[i]);
04436 free(q);
04437 return out;
04438
04439 }
|
|
||||||||||||||||||||||||
|
checks both straight & mirrored positions input - fourier transforms of rings!! circ1 already multiplied by weights! returns EM object with 1D ccf
Definition at line 4299 of file util_sparx.cpp. References circ1, circ1b, circ2, circ2b, fftr_q(), EMAN::EMData::get_data(), log(), numr, q, and t. Referenced by ali2d_ccf_list(), Crosrng_msg_vec_p(), multiref_peaks_ali2d(), and multiref_peaks_compress_ali2d(). 04299 {
04300
04301 // dimension circ1(lcirc),circ2(lcirc)
04302
04303 int ip, jc, numr3i, numr2i, i, j;
04304 float t1, t2, t3, t4, c1, c2, d1, d2;
04305
04306 int nring = numr.size()/3;
04307 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
04308 int maxrin = numr[numr.size()-1];
04309
04310 float* circ1b = circ1->get_data();
04311 float* circ2b = circ2->get_data();
04312
04313 #ifdef _WIN32
04314 ip = -(int)(log((float)maxrin)/log(2.0f));
04315 #else
04316 ip = -(int)(log2(maxrin));
04317 #endif //_WIN32
04318 for (int i=1; i<=maxrin; i++) {q(i) = 0.0f; t(i) = 0.0f;}
04319
04320 // q - straight = circ1 * conjg(circ2)
04321
04322 // t - mirrored = conjg(circ1) * conjg(circ2)
04323
04324 for (i=1; i<=nring; i++) {
04325
04326 numr3i = numr(3,i);
04327 numr2i = numr(2,i);
04328
04329 t1 = circ1b(numr2i) * circ2b(numr2i);
04330 q(1) += t1;
04331 t(1) += t1;
04332
04333 t1 = circ1b(numr2i+1) * circ2b(numr2i+1);
04334 if (numr3i == maxrin) {
04335 q(2) += t1;
04336 t(2) += t1;
04337 } else {
04338 q(numr3i+1) += t1;
04339 t(numr3i+1) += t1;
04340 }
04341
04342 for (j=3; j<=numr3i; j=j+2) {
04343 jc = j+numr2i-1;
04344
04345 c1 = circ1b(jc);
04346 c2 = circ1b(jc+1);
04347 d1 = circ2b(jc);
04348 d2 = circ2b(jc+1);
04349
04350 t1 = c1 * d1;
04351 t3 = c1 * d2;
04352 t2 = c2 * d2;
04353 t4 = c2 * d1;
04354
04355 q(j) += t1 + t2;
04356 q(j+1) += -t3 + t4;
04357 t(j) += t1 - t2;
04358 t(j+1) += -t3 - t4;
04359 }
04360 }
04361 // straight
04362 fftr_q(q,ip);
04363 //for (int i=0; i<maxrin; i++) cout<<i<<" B "<<q[i]<<" "<<t[i]<<endl;
04364
04365 // mirrored
04366 fftr_q(t,ip);
04367 }
|
|
||||||||||||||||
|
Definition at line 4284 of file util_sparx.cpp. References circ1, circ2, Crosrng_msg_vec(), and numr. 04284 {
04285
04286 int maxrin = numr[numr.size()-1];
04287
04288 vector<float> r(2*maxrin);
04289
04290 Crosrng_msg_vec( circ1, circ2, numr, &r[0], &r[maxrin] );
04291
04292 return r;
04293 }
|
|
||||||||||||||||
|
Definition at line 4096 of file util_sparx.cpp. References circ1, circ2, fftr_d(), EMAN::EMData::get_data(), log(), numr, prb1d(), q, EMAN::Dict::size(), t7, and tot. Referenced by multiref_polar_ali_2d_nom(). 04096 {
04097 int nring = numr.size()/3;
04098 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
04099 int maxrin = numr[numr.size()-1];
04100 double qn; float tot;
04101 float *circ1 = circ1p->get_data();
04102 float *circ2 = circ2p->get_data();
04103 /*
04104 c
04105 c checks only straight position
04106 c
04107 c input - fourier transforms of rings!!
04108 c circ1 already multiplied by weights!
04109 c
04110 */
04111
04112 // dimension circ1(lcirc),circ2(lcirc)
04113
04114 // q(maxrin), t7(-3:3) //maxrin+2 removed
04115 double *q, t7[7];
04116
04117 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0;
04118 float c1, c2, d1, d2, pos;
04119
04120 qn = 0.0;
04121 tot = 0.0;
04122 #ifdef _WIN32
04123 ip = -(int)(log((float)maxrin)/log(2.0f));
04124 #else
04125 ip = -(int)(log2(maxrin));
04126 #endif //_WIN32
04127 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl;
04128
04129 // c - straight = circ1 * conjg(circ2)
04130 // zero q array
04131
04132 q = (double*)calloc(maxrin,sizeof(double));
04133
04134 // premultiply arrays ie( circ12 = circ1 * circ2) much slower
04135 for (i=1; i<=nring; i++) {
04136
04137 numr3i = numr(3,i); // Number of samples of this ring
04138 numr2i = numr(2,i); // The beginning point of this ring
04139
04140 q(1) += circ1(numr2i) * circ2(numr2i);
04141
04142 if (numr3i == maxrin) q(2) += circ1(numr2i+1) * circ2(numr2i+1);
04143 else q(numr3i+1) += circ1(numr2i+1) * circ2(numr2i+1);
04144
04145 for (j=3; j<=numr3i; j += 2) {
04146 jc = j+numr2i-1;
04147
04148 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i
04149 // ----- ----- ----- -----
04150 // t1 t2 t3 t4
04151
04152 c1 = circ1(jc);
04153 c2 = circ1(jc+1);
04154 d1 = circ2(jc);
04155 d2 = circ2(jc+1);
04156
04157 q(j) += c1 * d1 + c2 * d2;
04158 q(j+1) += -c1 * d2 + c2 * d1;
04159 }
04160 }
04161 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<endl;
04162 fftr_d(q,ip);
04163
04164 qn = -1.0e20;
04165 for (j=1; j<=maxrin; j++) {//cout <<" "<<j<<" "<<q(j) <<endl;
04166 if (q(j) >= qn) {
04167 qn = q(j);
04168 jtot = j;
04169 }
04170 }
04171
04172 for (k=-3; k<=3; k++) {
04173 j = ((jtot+k+maxrin-1)%maxrin)+1;
04174 t7(k+4) = q(j);
04175 }
04176
04177 // interpolate
04178 prb1d(t7,7,&pos);
04179 tot = (float)(jtot)+pos;
04180 // Do not interpolate
04181 //*tot = (float)(jtot);
04182
04183 free(q);
04184
04185 Dict retvals;
04186 retvals["qn"] = qn;
04187 retvals["tot"] = tot;
04188 return retvals;
04189 }
|
|
||||||||||||||||||||
|
checks both straight & mirrored positions Find only positions within +/-pis_max of 0 and 180 (for helcal use) input - fourier transforms of rings! circ1 already multiplied by weights!
Definition at line 3683 of file util_sparx.cpp. References circ1, circ2, fftr_d(), EMAN::EMData::get_data(), log(), numr, prb1d(), q, EMAN::Dict::size(), t, t7, tmt, and tot. Referenced by multiref_polar_ali_helical(), and multiref_polar_ali_helical_local(). 03683 {
03684 int nring = numr.size()/3;
03685 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
03686 int maxrin = numr[numr.size()-1];
03687 double qn; float tot; double qm; float tmt;
03688 float *circ1 = circ1p->get_data();
03689 float *circ2 = circ2p->get_data();
03690
03691 // dimension circ1(lcirc),circ2(lcirc)
03692
03693 // t(maxrin), q(maxrin), t7(-3:3) //maxrin+2 removed
03694 double *t, *q, t7[7];
03695
03696 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0;
03697 float t1, t2, t3, t4, c1, c2, d1, d2, pos;
03698
03699 qn = 0.0f;
03700 qm = 0.0f;
03701 tot = 0.0f;
03702 tmt = 0.0f;
03703 #ifdef _WIN32
03704 ip = -(int)(log((float)maxrin)/log(2.0f));
03705 #else
03706 ip = -(int)(log2(maxrin));
03707 #endif //_WIN32
03708 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl;
03709
03710 // c - straight = circ1 * conjg(circ2)
03711 // zero q array
03712
03713 q = (double*)calloc(maxrin,sizeof(double));
03714
03715 // t - mirrored = conjg(circ1) * conjg(circ2)
03716 // zero t array
03717 t = (double*)calloc(maxrin,sizeof(double));
03718
03719 // premultiply arrays ie( circ12 = circ1 * circ2) much slower
03720 for (i=1; i<=nring; i++) {
03721
03722 numr3i = numr(3,i); // Number of samples of this ring
03723 numr2i = numr(2,i); // The beginning point of this ring
03724
03725 t1 = circ1(numr2i) * circ2(numr2i);
03726 q(1) += t1;
03727 t(1) += t1;
03728
03729 t1 = circ1(numr2i+1) * circ2(numr2i+1);
03730 if (numr3i == maxrin) {
03731 q(2) += t1;
03732 t(2) += t1;
03733 } else {
03734 q(numr3i+1) += t1;
03735 t(numr3i+1) += t1;
03736 }
03737
03738 for (j=3; j<=numr3i; j += 2) {
03739 jc = j+numr2i-1;
03740
03741 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i
03742 // ----- ----- ----- -----
03743 // t1 t2 t3 t4
03744 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i
03745 // ----- ----- ----- -----
03746 // t1 t2 t3 t4
03747
03748 c1 = circ1(jc);
03749 c2 = circ1(jc+1);
03750 d1 = circ2(jc);
03751 d2 = circ2(jc+1);
03752
03753 t1 = c1 * d1;
03754 t2 = c2 * d2;
03755 t3 = c1 * d2;
03756 t4 = c2 * d1;
03757
03758 q(j) += t1 + t2;
03759 q(j+1) += -t3 + t4;
03760 t(j) += t1 - t2;
03761 t(j+1) += -t3 - t4;
03762 }
03763 }
03764 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<" "<<t(j) <<endl;
03765 fftr_d(q,ip);
03766
03767 int psi_range = int(psi_max/360.0*maxrin+0.5);
03768 const int psi_0 = 0;
03769 int psi_180 = int( 180.0/360.0*maxrin+0.5);
03770
03771 qn = -1.0e20;
03772 for (k=-psi_range; k<=psi_range; k++) {
03773 j = (k+psi_0+maxrin-1)%maxrin+1;//string modemo = "f";cout <<" 90 "<<j<<" "<<ang_n(j,modemo,maxrin) <<" "<<float(j)/maxrin*360.0<<" "<<q(j) <<endl;
03774 if (q(j) >= qn) {
03775 qn = q(j);
03776 jtot = j;
03777 }
03778 }
03779
03780 for (k=-psi_range; k<=psi_range; k++) {
03781 j = (k+psi_180+maxrin-1)%maxrin+1; //cout <<" 270 "<<j<<" "<<ang_n(j,modemo,maxrin) <<" "<<float(j)/maxrin*360.0<<" "<<q(j) <<endl;
03782 if (q(j) >= qn) {
03783 qn = q(j);
03784 jtot = j;
03785 }
03786 }
03787
03788 for (k=-3; k<=3; k++) {
03789 j = ((jtot+k+maxrin-1)%maxrin)+1;
03790 t7(k+4) = q(j);
03791 }
03792
03793 // interpolate
03794 prb1d(t7,7,&pos);
03795 tot = (float)(jtot)+pos;
03796 // Do not interpolate
03797 //tot = (float)(jtot);
03798
03799 // mirrored
03800 fftr_d(t,ip);
03801
03802 // find angle
03803 qm = -1.0e20;
03804 for (k=-psi_range; k<=psi_range; k++) {
03805 j = (k+psi_0+maxrin-1)%maxrin+1;//string modemo = "f";cout <<" 90 "<<j<<" "<<ang_n(j,modemo,maxrin) <<" "<<float(j)/maxrin*360.0<<" "<<q(j) <<endl;
03806 if (t(j) >= qm) {
03807 qm = t(j);
03808 jtot = j;
03809 }
03810 }
03811
03812 for (k=-psi_range; k<=psi_range; k++) {
03813 j = (k+psi_180+maxrin-1)%maxrin+1; //cout <<" 270 "<<j<<" "<<ang_n(j,modemo,maxrin) <<" "<<float(j)/maxrin*360.0<<" "<<q(j) <<endl;
03814 if (t(j) >= qm) {
03815 qm = t(j);
03816 jtot = j;
03817 }
03818 }
03819
03820 for (k=-3; k<=3; k++) {
03821 j = ((jtot+k+maxrin-1)%maxrin) + 1;
03822 t7(k+4) = t(j);
03823 }
03824
03825 // interpolate
03826
03827 prb1d(t7,7,&pos);
03828 tmt = float(jtot) + pos;
03829 // Do not interpolate
03830 //tmt = float(jtot);
03831
03832 free(t);
03833 free(q);
03834
03835 Dict retvals;
03836 retvals["qn"] = qn;
03837 retvals["tot"] = tot;
03838 retvals["qm"] = qm;
03839 retvals["tmt"] = tmt;
03840 return retvals;
03841 }
|
|
||||||||||||||||||||
|
Definition at line 3843 of file util_sparx.cpp. References circ1, circ2, fftr_d(), EMAN::EMData::get_data(), log(), numr, prb1d(), q, EMAN::Dict::size(), t7, and tot. Referenced by multiref_polar_ali_helical_90(), and multiref_polar_ali_helical_90_local(). 03843 {
03844 int nring = numr.size()/3;
03845 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
03846 int maxrin = numr[numr.size()-1];
03847 double qn; float tot;
03848 float *circ1 = circ1p->get_data();
03849 float *circ2 = circ2p->get_data();
03850
03851 // dimension circ1(lcirc),circ2(lcirc)
03852
03853 // t(maxrin), q(maxrin), t7(-3:3) //maxrin+2 removed
03854 double *q, t7[7];
03855
03856 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0;
03857 float t1, t2, t3, t4, c1, c2, d1, d2, pos;
03858
03859 qn = 0.0f;
03860 tot = 0.0f;
03861 #ifdef _WIN32
03862 ip = -(int)(log((float)maxrin)/log(2.0f));
03863 #else
03864 ip = -(int)(log2(maxrin));
03865 #endif //_WIN32
03866 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl;
03867
03868 // c - straight = circ1 * conjg(circ2)
03869 // zero q array
03870
03871 q = (double*)calloc(maxrin,sizeof(double));
03872
03873 // premultiply arrays ie( circ12 = circ1 * circ2) much slower
03874 for (i=1; i<=nring; i++) {
03875
03876 numr3i = numr(3,i); // Number of samples of this ring
03877 numr2i = numr(2,i); // The beginning point of this ring
03878
03879 t1 = circ1(numr2i) * circ2(numr2i);
03880 q(1) += t1;
03881
03882
03883 t1 = circ1(numr2i+1) * circ2(numr2i+1);
03884 if (numr3i == maxrin) {
03885 q(2) += t1;
03886
03887 } else {
03888 q(numr3i+1) += t1;
03889 }
03890
03891 for (j=3; j<=numr3i; j += 2) {
03892 jc = j+numr2i-1;
03893
03894 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i
03895 // ----- ----- ----- -----
03896 // t1 t2 t3 t4
03897 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i
03898 // ----- ----- ----- -----
03899 // t1 t2 t3 t4
03900
03901 c1 = circ1(jc);
03902 c2 = circ1(jc+1);
03903 d1 = circ2(jc);
03904 d2 = circ2(jc+1);
03905
03906 t1 = c1 * d1;
03907 t2 = c2 * d2;
03908 t3 = c1 * d2;
03909 t4 = c2 * d1;
03910
03911 q(j) += t1 + t2;
03912 q(j+1) += -t3 + t4;
03913
03914 }
03915 }
03916 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<" "<<t(j) <<endl;
03917 fftr_d(q,ip);
03918
03919 int psi_range = int(psi_max/360.0*maxrin+0.5);
03920 const int psi_0 = 0;
03921 int psi_180 = int( 180.0/360.0*maxrin+0.5);
03922
03923 qn = -1.0e20;
03924 for (k=-psi_range; k<=psi_range; k++) {
03925 j = (k+psi_0+maxrin-1)%maxrin+1;//string modemo = "f";cout <<" 90 "<<j<<" "<<ang_n(j,modemo,maxrin) <<" "<<float(j)/maxrin*360.0<<" "<<q(j) <<endl;
03926 if (q(j) >= qn) {
03927 qn = q(j);
03928 jtot = j;
03929 }
03930 }
03931
03932 for (k=-psi_range; k<=psi_range; k++) {
03933 j = (k+psi_180+maxrin-1)%maxrin+1; //cout <<" 270 "<<j<<" "<<ang_n(j,modemo,maxrin) <<" "<<float(j)/maxrin*360.0<<" "<<q(j) <<endl;
03934 if (q(j) >= qn) {
03935 qn = q(j);
03936 jtot = j;
03937 }
03938 }
03939
03940 for (k=-3; k<=3; k++) {
03941 j = ((jtot+k+maxrin-1)%maxrin)+1;
03942 t7(k+4) = q(j);
03943 }
03944
03945 // interpolate
03946 prb1d(t7,7,&pos);
03947 tot = (float)(jtot)+pos;
03948 // Do not interpolate
03949 //tot = (float)(jtot);
03950
03951 free(q);
03952
03953 Dict retvals;
03954 retvals["qn"] = qn;
03955 retvals["tot"] = tot;
03956
03957 return retvals;
03958 }
|
|
||||||||||||||||||||||||
|
checks both straight & mirrored position input - fourier transforms of rings!! circ1 already multiplied by weights!
Definition at line 3962 of file util_sparx.cpp. References circ1, circ2, fftr_d(), flag, EMAN::EMData::get_data(), log(), numr, prb1d(), q, EMAN::Dict::size(), t7, tmt, and tot. Referenced by multiref_polar_ali_2d_local_psi(). 03962 {
03963 // flag 0 - straignt, 1 - mirror
03964
03965 int nring = numr.size()/3;
03966 int maxrin = numr[numr.size()-1];
03967 double qn; float tot; double qm; float tmt;
03968 float *circ1 = circ1p->get_data();
03969 float *circ2 = circ2p->get_data();
03970
03971 double *q, t7[7];
03972
03973 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0;
03974 float t1, t2, t3, t4, c1, c2, d1, d2, pos;
03975
03976 qn = 0.0f;
03977 qm = 0.0f;
03978 tot = 0.0f;
03979 tmt = 0.0f;
03980 #ifdef _WIN32
03981 ip = -(int)(log((float)maxrin)/log(2.0f));
03982 #else
03983 ip = -(int)(log2(maxrin));
03984 #endif //_WIN32
03985
03986 // c - straight = circ1 * conjg(circ2)
03987 // zero q array
03988
03989 q = (double*)calloc(maxrin,sizeof(double));
03990
03991 // premultiply arrays ie( circ12 = circ1 * circ2) much slower
03992 if (flag==0) {
03993 for (i=1; i<=nring; i++) {
03994
03995 numr3i = numr(3,i); // Number of samples of this ring
03996 numr2i = numr(2,i); // The beginning point of this ring
03997
03998 t1 = circ1(numr2i) * circ2(numr2i);
03999 q(1) += t1;
04000
04001 t1 = circ1(numr2i+1) * circ2(numr2i+1);
04002 if (numr3i == maxrin) {
04003 q(2) += t1;
04004 } else {
04005 q(numr3i+1) += t1;
04006 }
04007
04008 for (j=3; j<=numr3i; j += 2) {
04009 jc = j+numr2i-1;
04010
04011 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i
04012 // ----- ----- ----- -----
04013 // t1 t2 t3 t4
04014
04015 c1 = circ1(jc);
04016 c2 = circ1(jc+1);
04017 d1 = circ2(jc);
04018 d2 = circ2(jc+1);
04019
04020 t1 = c1 * d1;
04021 t3 = c1 * d2;
04022 t2 = c2 * d2;
04023 t4 = c2 * d1;
04024
04025 q(j) += t1 + t2;
04026 q(j+1) += -t3 + t4;
04027 }
04028 }
04029 } else {
04030 for (i=1; i<=nring; i++) {
04031
04032 numr3i = numr(3,i); // Number of samples of this ring
04033 numr2i = numr(2,i); // The beginning point of this ring
04034
04035 t1 = circ1(numr2i) * circ2(numr2i);
04036 q(1) += t1;
04037
04038 t1 = circ1(numr2i+1) * circ2(numr2i+1);
04039 if (numr3i == maxrin) {
04040 q(2) += t1;
04041 } else {
04042 q(numr3i+1) += t1;
04043 }
04044
04045 for (j=3; j<=numr3i; j += 2) {
04046 jc = j+numr2i-1;
04047
04048 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i
04049 // ----- ----- ----- -----
04050 // t1 t2 t3 t4
04051
04052 c1 = circ1(jc);
04053 c2 = circ1(jc+1);
04054 d1 = circ2(jc);
04055 d2 = circ2(jc+1);
04056
04057 t1 = c1 * d1;
04058 t3 = c1 * d2;
04059 t2 = c2 * d2;
04060 t4 = c2 * d1;
04061
04062 q(j) += t1 - t2;
04063 q(j+1) += -t3 - t4;
04064 }
04065 }
04066 }
04067 fftr_d(q,ip);
04068
04069 qn = -1.0e20;
04070 int psi_pos = int(psi/360.0*maxrin+0.5);
04071
04072 for (k=-5; k<=5; k++) {
04073 j = (psi_pos+maxrin-1)%maxrin+1;
04074 if (q(j) >= qn) {
04075 qn = q(j);
04076 jtot = j;
04077 }
04078 }
04079
04080 for (k=-3; k<=3; k++) {
04081 j = ((jtot+k+maxrin-1)%maxrin)+1;
04082 t7(k+4) = q(j);
04083 }
04084
04085 // interpolate
04086 prb1d(t7,7,&pos);
04087 tot = (float)(jtot)+pos;
04088 free(q);
04089
04090 Dict retvals;
04091 retvals["qn"] = qn;
04092 retvals["tot"] = tot;
04093 return retvals;
04094 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Definition at line 20123 of file util_sparx.cpp. References nx, ny, EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), EMAN::EMData::set_ri(), EMAN::EMData::set_size(), sign, tf(), and EMAN::EMData::update(). 20124 {
20125 int ix, iy, iz;
20126 int i, j, k;
20127 int nr2, nl2;
20128 float dzz, az, ak;
20129 float scx, scy, scz;
20130 int offset = 2 - nx%2;
20131 int lsm = nx + offset;
20132 EMData* ctf_img1 = new EMData();
20133 ctf_img1->set_size(lsm, ny, nz);
20134 float freq = 1.0f/(2.0f*ps);
20135 scx = 2.0f/float(nx);
20136 if(ny>=1) scy = 2.0f/float(ny); else scy=0.0f;
20137 if(nz>=1) scz = 2.0f/float(nz); else scz=0.0f;
20138 nr2 = ny/2 ;
20139 nl2 = nz/2 ;
20140 for ( k=0; k<nz;k++) {
20141 iz = k; if(k>nl2) iz=k-nz;
20142 for ( j=0; j<ny;j++) {
20143 iy = j; if(j>nr2) iy=j - ny;
20144 for ( i=0; i<lsm/2; i++) {
20145 ix=i;
20146 ak=pow(ix*ix*scx*scx+iy*scy*iy*scy+iz*scz*iz*scz, 0.5f)*freq;
20147 if(ak!=0) az=0.0; else az=M_PI;
20148 dzz = dz + dza/2.0f*sin(2*(az-azz*M_PI/180.0f));
20149 (*ctf_img1) (i*2,j,k) = Util::tf(dzz, ak, voltage, cs, wgh, b_factor, sign);
20150 (*ctf_img1) (i*2+1,j,k) = 0.0f;
20151 }
20152 }
20153 }
20154 ctf_img1->update();
20155 ctf_img1->set_complex(true);
20156 ctf_img1->set_ri(true);
20157 //ctf_img1->attr_dict["is_complex"] = 1;
20158 //ctf_img1->attr_dict["is_ri"] = 1;
20159 if(nx%2==0) ctf_img1->set_fftodd(false); else ctf_img1->set_fftodd(true);
20160 return ctf_img1;
20161 }
|
|
||||||||||||
|
Performs inplace integer cyclic shift as specified by the "dx","dy","dz" parameters on a 3d volume. Implements the inplace swapping using reversals as descibed in also: http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Intro/Eg01/
10 20 30 40 50 60 70 80 90 100 ------------ m = 3 (shift left three places) Reverse the items from 0..m-1 and m..N-1: 30 20 10 100 90 80 70 60 50 40 Now reverse the entire sequence: 40 50 60 70 80 90 100 10 20 30 cycl_shift() in libpy/fundementals.py calls this function Usage: EMData *im1 = new EMData(); im1->set_size(70,80,85); im1->to_one(); Dict params; params["dx"] = 10;params["dy"] = 10000;params["dz"] = -10; Utils::cyclicshift(im1,params); im1.peak_search(1,1) Definition at line 5483 of file util_sparx.cpp. References colreverse(), data, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageFormatException, EMAN::EMData::is_complex(), nx, ny, slicereverse(), and EMAN::EMData::update(). 05483 {
05484
05485 if (image->is_complex()) throw ImageFormatException("Real image required for IntegerCyclicShift2DProcessor");
05486
05487 int dx = params["dx"];
05488 int dy = params["dy"];
05489 int dz = params["dz"];
05490
05491 // The reverse trick we're using shifts to the left (a negative shift)
05492 int nx = image->get_xsize();
05493 dx %= nx;
05494 if (dx < 0) dx += nx;
05495 int ny = image->get_ysize();
05496 dy %= ny;
05497 if (dy < 0) dy += ny;
05498 int nz = image->get_zsize();
05499 dz %= nz;
05500 if (dz < 0) dz += nz;
05501
05502 int mx = -(dx - nx);
05503 int my = -(dy - ny);
05504 int mz = -(dz - nz);
05505
05506 float* data = image->get_data();
05507 // x-reverses
05508 if (mx != 0) {
05509 for (int iz = 0; iz < nz; iz++)
05510 for (int iy = 0; iy < ny; iy++) {
05511 // reverses for column iy
05512 size_t offset = nx*iy + (size_t)nx*ny*iz; // starting location for column iy in slice iz
05513 reverse(&data[offset],&data[offset+mx]);
05514 reverse(&data[offset+mx],&data[offset+nx]);
05515 reverse(&data[offset],&data[offset+nx]);
05516 }
05517 }
05518 // y-reverses
05519 if (my != 0) {
05520 for (int iz = 0; iz < nz; iz++) {
05521 size_t offset = (size_t)nx*ny*iz;
05522 colreverse(&data[offset], &data[offset + my*nx], nx);
05523 colreverse(&data[offset + my*nx], &data[offset + ny*nx], nx);
05524 colreverse(&data[offset], &data[offset + ny*nx], nx);
05525 }
05526 }
05527 if (mz != 0) {
05528 slicereverse(&data[0], &data[(size_t)mz*ny*nx], nx, ny);
05529 slicereverse(&data[mz*ny*nx], &data[(size_t)nz*ny*nx], nx, ny);
05530 slicereverse(&data[0], &data[(size_t)nz*ny*nx], nx ,ny);
05531 }
05532 image->update();
05533 }
|
|
||||||||||||||||||||
|
Definition at line 5277 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, LOGERR, new_ptr, NullPointerException, nx, ny, old_ptr, EMAN::EMData::set_size(), and EMAN::EMData::update(). 05278 {
05279 /* Exception Handle */
05280 if (!img) {
05281 throw NullPointerException("NULL input image");
05282 }
05283 /* ============================== */
05284
05285 // Get the size of the input image
05286 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
05287 /* ============================== */
05288
05289
05290 /* Exception Handle */
05291 if ((x_step-1 > nx/2 || y_step-1 > ny/2 || z_step-1 > nz/2) || (x_step-1)<0 || (y_step-1)<0 || (z_step-1)<0)
05292 {
05293 LOGERR("Parameters for decimation cannot exceed the center of the image.");
05294 throw ImageDimensionException("Parameters for decimation cannot exceed the center of the image.");
05295 }
05296 /* ============================== */
05297
05298
05299 /* Calculation of the start point */
05300 int new_st_x=(nx/2)%x_step, new_st_y=(ny/2)%y_step, new_st_z=(nz/2)%z_step;
05301 /* ============================*/
05302
05303
05304 /* Calculation of the size of the decimated image */
05305 int rx=2*(nx/(2*x_step)), ry=2*(ny/(2*y_step)), rz=2*(nz/(2*z_step));
05306 int r1=int(ceil((nx-(x_step*rx))/(1.f*x_step))), r2=int(ceil((ny-(y_step*ry))/(1.f*y_step)));
05307 int r3=int(ceil((nz-(z_step*rz))/(1.f*z_step)));
05308 if(r1>1){r1=1;}
05309 if(r2>1){r2=1;}
05310 if(r3>1){r3=1;}
05311 int new_nx=rx+r1, new_ny=ry+r2, new_nz=rz+r3;
05312 /* ===========================================*/
05313
05314
05315 EMData* img2 = new EMData();
05316 img2->set_size(new_nx,new_ny,new_nz);
05317 float *new_ptr = img2->get_data();
05318 float *old_ptr = img->get_data();
05319 int iptr, jptr, kptr = 0;
05320 for (int k=new_st_z; k<nz; k+=z_step) {jptr=0;
05321 for (int j=new_st_y; j<ny; j+=y_step) {iptr=0;
05322 for (int i=new_st_x; i<nx; i+=x_step) {
05323 new_ptr(iptr,jptr,kptr) = old_ptr(i,j,k);
05324 iptr++;}
05325 jptr++;}
05326 kptr++;}
05327 img2->update();
05328 return img2;
05329 }
|
|
||||||||||||||||||||
|
Definition at line 7788 of file util_sparx.cpp. 07789 {
07790 ENTERFUNC;
07791 int k, i;
07792 for(i=0; i<len; i++) key[i]=i+1;
07793
07794 for(i = 0; i<len;i++){
07795 k = rand()%len;
07796 std::swap(key[k], key[i]);
07797 std::swap(x[k], x[i]);
07798 std::swap(y[k], y[i]);
07799 }
07800 EXITFUNC;
07801 }
|
|
||||||||||||
|
Definition at line 17747 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageFormatException, img_ptr, EMAN::EMData::is_complex(), NullPointerException, nx, ny, and EMAN::EMData::update(). 17748 {
17749 ENTERFUNC;
17750 /* Exception Handle */
17751 if (!img) {
17752 throw NullPointerException("NULL input image");
17753 }
17754 /* ========= img /= img1 ===================== */
17755
17756 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17757 size_t size = (size_t)nx*ny*nz;
17758 float *img_ptr = img->get_data();
17759 float *img1_ptr = img1->get_data();
17760 if(img->is_complex()) {
17761 for (size_t i=0; i<size; i+=2) {
17762 if(img1_ptr[i] > 1.e-10f) {
17763 img_ptr[i] /= img1_ptr[i];
17764 img_ptr[i+1] /= img1_ptr[i];
17765 } else img_ptr[i] = img_ptr[i+1] = 0.0f;
17766 }
17767 } else throw ImageFormatException("Only Fourier image allowed");
17768
17769 img->update();
17770
17771 EXITFUNC;
17772 }
|
|
||||||||||||
|
Definition at line 17718 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, EMAN::EMData::is_complex(), NullPointerException, nx, ny, and EMAN::EMData::update(). 17719 {
17720 ENTERFUNC;
17721 /* Exception Handle */
17722 if (!img) {
17723 throw NullPointerException("NULL input image");
17724 }
17725 /* ========= img /= img1 ===================== */
17726
17727 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17728 size_t size = (size_t)nx*ny*nz;
17729 float *img_ptr = img->get_data();
17730 float *img1_ptr = img1->get_data();
17731 if(img->is_complex()) {
17732 float sq2;
17733 for (size_t i=0; i<size; i+=2) {
17734 sq2 = 1.0f/(img1_ptr[i] * img1_ptr[i] + img1_ptr[i+1] * img1_ptr[i+1]);
17735 float tmp = sq2*(img_ptr[i] * img1_ptr[i] + img_ptr[i+1] * img1_ptr[i+1]) ;
17736 img_ptr[i+1] = sq2*(img_ptr[i+1] * img1_ptr[i] - img_ptr[i] * img1_ptr[i+1]) ;
17737 img_ptr[i] = tmp;
17738 }
17739 } else {
17740 for (size_t i=0; i<size; ++i) img_ptr[i] /= img1_ptr[i];
17741 }
17742 img->update();
17743
17744 EXITFUNC;
17745 }
|
|
||||||||||||
|
Definition at line 17543 of file util_sparx.cpp. References EMAN::EMData::copy_head(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageFormatException, img2_ptr, img_ptr, EMAN::EMData::is_complex(), NullPointerException, nx, ny, and EMAN::EMData::update(). 17544 {
17545 ENTERFUNC;
17546 /* Exception Handle */
17547 if (!img) {
17548 throw NullPointerException("NULL input image");
17549 }
17550 /* ========= img /= img1 ===================== */
17551
17552 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17553 size_t size = (size_t)nx*ny*nz;
17554 EMData * img2 = img->copy_head();
17555 float *img_ptr =img->get_data();
17556 float *img1_ptr = img1->get_data();
17557 float *img2_ptr = img2->get_data();
17558 if(img->is_complex()) {
17559 for (size_t i=0; i<size; i+=2) {
17560 if(img1_ptr[i] > 1.e-10f) {
17561 img2_ptr[i] = img_ptr[i] /img1_ptr[i];
17562 img2_ptr[i+1] = img_ptr[i+1]/img1_ptr[i];
17563 } else img2_ptr[i] = img2_ptr[i+1] = 0.0f;
17564 }
17565 } else throw ImageFormatException("Only Fourier image allowed");
17566
17567 img->update();
17568
17569 EXITFUNC;
17570 return img2;
17571 }
|
|
||||||||||||
|
Definition at line 17510 of file util_sparx.cpp. References EMAN::EMData::copy_head(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img2_ptr, img_ptr, EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), NullPointerException, nx, ny, EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), and EMAN::EMData::update(). 17511 {
17512 ENTERFUNC;
17513 /* Exception Handle */
17514 if (!img) {
17515 throw NullPointerException("NULL input image");
17516 }
17517 /* ============== output = img / img1 ================ */
17518
17519 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17520 size_t size = (size_t)nx*ny*nz;
17521 EMData * img2 = img->copy_head();
17522 float *img_ptr =img->get_data();
17523 float *img2_ptr = img2->get_data();
17524 float *img1_ptr = img1->get_data();
17525 if(img->is_complex()) {
17526 float sq2;
17527 for (size_t i=0; i<size; i+=2) {
17528 sq2 = 1.0f/(img1_ptr[i] * img1_ptr[i] + img1_ptr[i+1] * img1_ptr[i+1]);
17529 img2_ptr[i] = sq2*(img_ptr[i] * img1_ptr[i] + img_ptr[i+1] * img1_ptr[i+1]) ;
17530 img2_ptr[i+1] = sq2*(img_ptr[i+1] * img1_ptr[i] - img_ptr[i] * img1_ptr[i+1]) ;
17531 }
17532 img2->set_complex(true);
17533 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false);
17534 } else {
17535 for (size_t i=0; i<size; ++i) img2_ptr[i] = img_ptr[i] / img1_ptr[i];
17536 img2->update();
17537 }
17538
17539 EXITFUNC;
17540 return img2;
17541 }
|
|
||||||||||||
|
copy sign of a number. return a value whose absolute value matches that of 'a', but whose sign matches that of 'b'. If 'a' is a NaN, then a NaN with the sign of 'b' is returned. It is exactly copysign() on non-Windows system.
|
|
|
complementary error function. It is exactly erfc() on non-Windows system. On Windows, it tries to simulate erfc(). The erf() function returns the error function of x; defined as erf(x) = 2/sqrt(pi)* integral from 0 to x of exp(-t*t) dt The erfc() function returns the complementary error function of x, that is 1.0 - erf(x).
Definition at line 1987 of file util.h. Referenced by EMAN::IterationAverager::finish(). |
|
||||||||||||
|
Definition at line 4524 of file util_sparx.cpp. References EMAN::EMData::get_data(), numr, and PI2. 04524 {
04525 ENTERFUNC;
04526 long double ener,en;
04527
04528 int nring = numr.size()/3;
04529 float *aveptr = ave->get_data();
04530
04531 ener = 0.0;
04532 for (int i=1; i<=nring; i++) {
04533 int numr3i = numr(3,i);
04534 int np = numr(2,i)-1;
04535 float tq = static_cast<float>(PI2*numr(1,i)/numr3i);
04536 en = tq*(aveptr[np]*aveptr[np]+aveptr[np+1]*aveptr[np+1])*0.5;
04537 for (int j=np+2; j<np+numr3i-1; j++) en += tq*aveptr[j]*aveptr[j];
04538 ener += en/numr3i;
04539 }
04540 EXITFUNC;
04541 return static_cast<float>(ener);
04542 }
|
|
||||||||||||||||
|
Definition at line 4544 of file util_sparx.cpp. References data, EMAN::EMData::get_data(), numr, PI2, and tot. 04544 {
04545 ENTERFUNC;
04546 long double ener, en;
04547 float arg, cs, si;
04548
04549 int nima = data.size();
04550 int nring = numr.size()/3;
04551 int maxrin = numr(3,nring);
04552
04553 ener = 0.0;
04554 for (int i=1; i<=nring; i++) {
04555 int numr3i = numr(3,i);
04556 int np = numr(2,i)-1;
04557 float tq = static_cast<float>(PI2*numr(1,i)/numr3i);
04558 float temp1 = 0.0, temp2 = 0.0;
04559 for (int kk=0; kk<nima; kk++) {
04560 float *ptr = data[kk]->get_data();
04561 temp1 += ptr[np];
04562 temp2 += static_cast<float>(ptr[np+1]*cos(PI2*(tot[kk]-1.0f)/2.0f*numr3i/maxrin));
04563 }
04564 en = tq*(temp1*temp1+temp2*temp2)*0.5;
04565 for (int j=2; j<numr3i; j+=2) {
04566 float tempr = 0.0, tempi = 0.0;
04567 for (int kk=0; kk<nima; kk++) {
04568 float *ptr = data[kk]->get_data();
04569 arg = static_cast<float>( PI2*(tot[kk]-1.0)*(j/2)/maxrin );
04570 cs = cos(arg);
04571 si = sin(arg);
04572 tempr += ptr[np + j]*cs - ptr[np + j +1]*si;
04573 tempi += ptr[np + j]*si + ptr[np + j +1]*cs;
04574 }
04575 en += tq*(tempr*tempr+tempi*tempi);
04576 }
04577 ener += en/numr3i;
04578 }
04579 EXITFUNC;
04580 return static_cast<float>(ener);
04581 }
|
|
||||||||||||||||||||
|
Determine the equation of a plane that intersects 3 points in 3D space. Required by Symmetry3D::reduce IMPORTANT - does no error checking, if the float pointer is less than 4 in size will get unknown behavior
Definition at line 1223 of file util.cpp. References EMAN::Vec3f, x, and y. Referenced by EMAN::Symmetry3D::cache_au_planes(). 01224 {
01225 int x=0,y=1,z=2;
01226 plane[0] = p1[y]*(p2[z]-p3[z])+p2[y]*(p3[z]-p1[z])+p3[y]*(p1[z]-p2[z]);
01227 plane[1] = p1[z]*(p2[x]-p3[x])+p2[z]*(p3[x]-p1[x])+p3[z]*(p1[x]-p2[x]);
01228 plane[2] = p1[x]*(p2[y]-p3[y])+p2[x]*(p3[y]-p1[y])+p3[x]*(p1[y]-p2[y]);
01229 plane[3] = p1[x]*(p2[y]*p3[z]-p3[y]*p2[z])+p2[x]*(p3[y]*p1[z]-p1[y]*p3[z])+p3[x]*(p1[y]*p2[z]-p2[y]*p1[z]);
01230 plane[3] = -plane[3];
01231 }
|
|
||||||||||||||||||||||||||||
|
Definition at line 7136 of file util_sparx.cpp. References EMAN::EMData::get_data(), images, and EMAN::EMData::read_image(). 07137 {
07138 int j,d;
07139 EMData * e = new EMData();
07140 float *eptr, *imgptr;
07141 imgptr = img->get_data();
07142 float SSE = 0.f;
07143 for (j = 0 ; j < N ; j++) {
07144 e->read_image(images,S[j]);
07145 eptr = e->get_data();
07146 for (d = 0; d < size; d++) {
07147 SSE += ((eptr[d] - imgptr[d])*(eptr[d] - imgptr[d]));}
07148 }
07149 delete e;
07150 return SSE;
07151 }
|
|
||||||||||||||||||||||||
|
Compute a vector containing quasi-evenly spaced Euler angles. The order of angles in the vector is phi, theta, psi.
Definition at line 506 of file util_sparx.cpp. References angles, dgr_to_rad, phi, and theta. 00507 {
00508 vector<float> angles;
00509 float psi = 0.0;
00510 if ((0.0 == t1 && 0.0 == t2)||(t1 >= t2)) {
00511 t1 = 0.0f;
00512 t2 = 90.0f;
00513 }
00514 if ((0.0 == p1 && 0.0 == p2)||(p1 >= p2)) {
00515 p1 = 0.0f;
00516 p2 = 359.9f;
00517 }
00518 bool skip = ((t1 < 90.0)&&(90.0 == t2)&&(0.0 == p1)&&(p2 > 180.0));
00519 for (float theta = t1; theta <= t2; theta += delta) {
00520 float detphi;
00521 int lt;
00522 if ((0.0 == theta)||(180.0 == theta)) {
00523 detphi = 360.0f;
00524 lt = 1;
00525 } else {
00526 detphi = delta/sin(theta*static_cast<float>(dgr_to_rad));
00527 lt = int((p2 - p1)/detphi)-1;
00528 if (lt < 1) lt = 1;
00529 detphi = (p2 - p1)/lt;
00530 }
00531 for (int i = 0; i < lt; i++) {
00532 float phi = p1 + i*detphi;
00533 if (skip&&(90.0 == theta)&&(phi > 180.0)) continue;
00534 angles.push_back(phi);
00535 angles.push_back(theta);
00536 angles.push_back(psi);
00537 }
00538 }
00539 return angles;
00540 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Each class in Parts has its dummy variable set to 0 or 1. Only consider those with its dummy variable set to 1 (the 'active' ones) First element of each class is its original index, second is the dummy variable slot. Definition at line 21026 of file util_sparx.cpp. References k_means_cont_table_(). Referenced by initial_prune(). 21026 {
21027
21028
21029 if (size_next <= T) return 0;
21030
21031 // take the intx of next and cur
21032 int* curintx2(0);
21033 int nintx = Util::k_means_cont_table_(curintx, next+2, curintx2, size_curintx, size_next,0);
21034 if (nintx <= T) return 0;
21035
21036 int old_depth=depth;
21037 if (depth == partref) depth = depth + 1; // we skip classes in partref
21038 if (depth == nParts && old_depth>0) return 1;
21039
21040 // have not yet reached a leaf, and current weight is still greather than T, so keep on going.
21041
21042 curintx2 = new int[nintx]; // put the intersection set in here
21043 Util::k_means_cont_table_(curintx,next+2,curintx2, size_curintx, size_next,1);
21044
21045 // if (old_depth > 0) {delete[] curintx;} // don't delete when depth == 0 because curintx in that case is a pointer into Parts
21046
21047 // we now consider each of the classes in partition (depth+1) in turn
21048 bool gt_thresh;
21049 int num_classes = Parts[depth].size(); // (TO DO) have to figure out how many classes partition (depth) has since some may have being removed from before iterations
21050
21051 for (int i=0; i < num_classes; i++){
21052 if (Parts[depth][i][1] < 1) continue; // class is not active so move on
21053 size_next = dimClasses[depth*K + Parts[depth][i][0] ]-2;
21054 gt_thresh = explore(Parts,dimClasses, nParts, K, T, partref, curintx2,nintx, Parts[depth][i], size_next, depth+1);
21055 if (gt_thresh) { delete[] curintx2; return 1; }
21056 }
21057 delete[] curintx2;
21058 return 0;
21059 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Definition at line 20860 of file util_sparx.cpp. References explore2(), and k_means_cont_table_(). 20860 {
20861
20862 // depth is the level which is going to be explored in the current iteration
20863 int* curintx2(0);
20864 int nintx = size_curintx;
20865
20866
20867 // 2. take the intx of next and cur. Prune if <= T
20868 if (depth >0){
20869 nintx = Util::k_means_cont_table_(curintx,next, curintx2, size_curintx, size_next,0);
20870 if (nintx <= T) return; //prune!
20871 }
20872
20873 // 1. we're at a leaf with weight > T, so determine if there is any empty space. If so, put it in. If not, determine if current cost is larger than any of the cost in matchlist, if so, replace the smallest one in matchlist
20874 if (depth == (nParts-1)) {
20875
20876 int replace = 0;
20877 int ind_smallest = -1;
20878 int smallest_cost = -1;
20879
20880 for (int jit = 0; jit < J; jit++){
20881 if (*(costlist+jit) < nintx){
20882 replace = 1;
20883 if (ind_smallest == -1) {ind_smallest = jit; smallest_cost = *(costlist+jit);}
20884 if (*(costlist+jit) < smallest_cost) {ind_smallest = jit; smallest_cost = *(costlist+jit);}
20885 }
20886 }
20887
20888 if (replace > 0){
20889 // replace the smallest cost in matchlist with the current stuff
20890 *(costlist + ind_smallest) = nintx;
20891 for (int xit = 0; xit < nParts; xit++)
20892 *(matchlist + ind_smallest*nParts + xit) = *(curbranch+xit);
20893
20894 }
20895
20896 return;
20897 }
20898
20899
20900 // 3. have not yet reached a leaf, and current weight is still greather than T, so keep on going.
20901
20902 if (depth > 0){
20903 curintx2 = new int[nintx]; // put the intersection set in here
20904 Util::k_means_cont_table_(curintx,next,curintx2, size_curintx, size_next,1);
20905 }
20906
20907 if (depth == 0){
20908 // set curintx2 to curintx
20909 curintx2 = new int[size_curintx];
20910 for (int cp = 0; cp < size_curintx; cp++) *(curintx2+cp) = *(curintx+cp);
20911 }
20912
20913
20914 // recursion (non-leaf case)
20915 depth=depth+1;
20916 // we now consider each of the classes in partition depth and recurse upon each of them
20917 for (int i=0; i < K; i++){
20918
20919 if (*(argParts + Indices[depth*K+i] + 1) < 1) continue; // class is not active so move on
20920 size_next = (*(dimClasses + depth*K+i ))-2;
20921 if (size_next <= T) continue;
20922 *(curbranch+depth) = i;
20923 Util::explore2(argParts,Indices, dimClasses, nParts, K, T, curintx2, nintx, argParts + Indices[depth*K+i] + 2, size_next, depth,J, matchlist,
20924 costlist, curbranch);
20925
20926 }
20927
20928 delete[] curintx2;
20929 }
|
|
||||||||||||||||||||||||||||
|
Definition at line 1684 of file util_sparx.cpp. References EMAN::EMData::cmplx(), EMAN::Util::KaiserBessel::i0win_tab(), ImageDimensionException, and nx. 01684 {
01685
01686 int nxreal = nx - 2;
01687 if (nxreal != ny)
01688 throw ImageDimensionException("extractpoint requires ny == nx");
01689 int nhalf = nxreal/2;
01690 bool flip = (nuxnew < 0.f);
01691 if (flip) {
01692 nuxnew *= -1;
01693 nuynew *= -1;
01694 }
01695 if (nuynew >= nhalf-0.5) {
01696 nuynew -= nxreal;
01697 } else if (nuynew < -nhalf-0.5) {
01698 nuynew += nxreal;
01699 }
01700
01701 // put (xnew,ynew) on a grid. The indices will be wrong for
01702 // the Fourier elements in the image, but the grid sizing will
01703 // be correct.
01704 int ixn = int(Util::round(nuxnew));
01705 int iyn = int(Util::round(nuynew));
01706
01707 // set up some temporary weighting arrays
01708 static float wy[7];
01709 static float wx[7];
01710
01711 float iynn = nuynew - iyn;
01712 wy[0] = kb.i0win_tab(iynn+3);
01713 wy[1] = kb.i0win_tab(iynn+2);
01714 wy[2] = kb.i0win_tab(iynn+1);
01715 wy[3] = kb.i0win_tab(iynn);
01716 wy[4] = kb.i0win_tab(iynn-1);
01717 wy[5] = kb.i0win_tab(iynn-2);
01718 wy[6] = kb.i0win_tab(iynn-3);
01719
01720 float ixnn = nuxnew - ixn;
01721 wx[0] = kb.i0win_tab(ixnn+3);
01722 wx[1] = kb.i0win_tab(ixnn+2);
01723 wx[2] = kb.i0win_tab(ixnn+1);
01724 wx[3] = kb.i0win_tab(ixnn);
01725 wx[4] = kb.i0win_tab(ixnn-1);
01726 wx[5] = kb.i0win_tab(ixnn-2);
01727 wx[6] = kb.i0win_tab(ixnn-3);
01728
01729 float wsum = (wx[0]+wx[1]+wx[2]+wx[3]+wx[4]+wx[5]+wx[6])*(wy[0]+wy[1]+wy[2]+wy[3]+wy[4]+wy[5]+wy[6]);
01730
01731 complex<float> result(0.f,0.f);
01732 if ((ixn >= 3) && (ixn <= nhalf-3) && (iyn >= -nhalf+3) && (iyn <= nhalf-4)) {
01733 // (xin,yin) not within window border from the edge
01734 for (int iy = 0; iy < 7; iy++) {
01735 int iyp = iyn + iy - 3 ;
01736 for (int ix = 0; ix < 7; ix++) {
01737 int ixp = ixn + ix - 3;
01738 float w = wx[ix]*wy[iy];
01739 complex<float> val = fimage->cmplx(ixp,iyp);
01740 result += val*w;
01741 }
01742 }
01743 } else {
01744 // points that "stick out"
01745 for (int iy = 0; iy < 7; iy++) {
01746 int iyp = iyn + iy - 3;
01747 for (int ix = 0; ix < 7; ix++) {
01748 int ixp = ixn + ix - 3;
01749 bool mirror = false;
01750 int ixt = ixp, iyt = iyp;
01751 if (ixt < 0) {
01752 ixt = -ixt;
01753 iyt = -iyt;
01754 mirror = !mirror;
01755 }
01756 if (ixt > nhalf) {
01757 ixt = nxreal - ixt;
01758 iyt = -iyt;
01759 mirror = !mirror;
01760 }
01761 if (iyt > nhalf-1) iyt -= nxreal;
01762 if (iyt < -nhalf) iyt += nxreal;
01763 float w = wx[ix]*wy[iy];
01764 complex<float> val = fimage->cmplx(ixt,iyt);
01765 if (mirror) result += conj(val)*w;
01766 else result += val*w;
01767 }
01768 }
01769 }
01770 if (flip) result = conj(result)/wsum;
01771 else result /= wsum;
01772 return result;
01773 }
|
|
|
Returns an approximate of acos(x) using a cached table and linear interpolation tolerates values very slightly outside the -1 - 1 range (returning 0).
Definition at line 783 of file util.cpp. 00783 {
00784 if (f>=1.0) return 0.0;
00785 if (f<=-1.0) return M_PI;
00786
00787 static float *mem = (float *)malloc(sizeof(float)*2001);
00788 static bool needinit=true;
00789
00790
00791 if (needinit) {
00792 needinit=false;
00793 for (int i=0; i<=2000; i++) mem[i]=(float)acos(i/1000.0-1.0);
00794 }
00795 float f2=f*1000.0f+1000.0f;
00796
00797 int g=(int)(f2+.5);
00798
00799 return mem[g];
00800
00801 // This version interpolates, but is slower
00802 /*int g=(int)f2;
00803 f2-=g;
00804 return mem[g+1]*f2+mem[g]*(1.0-f2);*/
00805 }
|
|
|
Returns an approximate of exp(x) using a cached table uses actual exp(x) outside the cached range.
Definition at line 767 of file util.cpp. Referenced by EMAN::FourierInserter3DMode5::insert_pixel(), EMAN::FourierInserter3DMode3::insert_pixel(), EMAN::FourierInserter3DMode2::insert_pixel(), EMAN::WienerFourierReconstructor::pixel_at(), and EMAN::FourierReconstructor::pixel_at(). 00767 {
00768 static float *mem = (float *)malloc(sizeof(float)*1000);
00769 static bool needinit=true;
00770
00771 if (needinit) {
00772 needinit=false;
00773 for (int i=0; i<1000; i++) mem[i]=(float)exp(-i/50.0);
00774 }
00775 if (f>0 || f<-19.98) return exp(f);
00776 int g=(int)(-f*50.0+0.5);
00777
00778 return mem[g];
00779 }
|
|
|
A fast way to calculate a floor, which is largest integral value not greater than argument.
Definition at line 1692 of file util.h. Referenced by EMAN::CtfAverager::add_image(), EMAN::CircularMaskProcessor::calc_locals(), EMAN::CtfAverager::finish(), EMAN::SymSearchProcessor::process_inplace(), EMAN::AddRandomNoiseProcessor::process_inplace(), EMAN::RotationalAverageProcessor::process_inplace(), EMAN::StandardProjector::project3d(), EMAN::EMData::sget_value_at_interp(), and EMAN::TransformProcessor::transform(). |
|
||||||||||||||||||||
|
Definition at line 2617 of file util_sparx.cpp. References abs, bi, br, status, t, and tab1. Referenced by fftr_d(). 02618 {
02619 double rni,sgn,tr1,tr2,ti1,ti2;
02620 double cc,c,ss,s,t,x2,x3,x4,x5;
02621 int b3,b4,b5,b6,b7,b56;
02622 int n, k, l, j, i, ix0, ix1, status=0;
02623
02624 const double tab1[] = {
02625 9.58737990959775e-5,
02626 1.91747597310703e-4,
02627 3.83495187571395e-4,
02628 7.66990318742704e-4,
02629 1.53398018628476e-3,
02630 3.06795676296598e-3,
02631 6.13588464915449e-3,
02632 1.22715382857199e-2,
02633 2.45412285229123e-2,
02634 4.90676743274181e-2,
02635 9.80171403295604e-2,
02636 1.95090322016128e-1,
02637 3.82683432365090e-1,
02638 7.07106781186546e-1,
02639 1.00000000000000,
02640 };
02641
02642 n=(int)pow(2.0f,ln);
02643
02644 k=abs(ks);
02645 l=16-ln;
02646 b3=n*k;
02647 b6=b3;
02648 b7=k;
02649 if (ks > 0) {
02650 sgn=1.0f;
02651 } else {
02652 sgn=-1.0f;
02653 rni=1.0f/(float)(n);
02654 j=1;
02655 for (i=1; i<=n; i++) {
02656 br(j)=br(j)*rni;
02657 bi(j)=bi(j)*rni;
02658 j=j+k;
02659 }
02660 }
02661
02662 L12:
02663 b6=b6/2;
02664 b5=b6;
02665 b4=2*b6;
02666 b56=b5-b6;
02667
02668 L14:
02669 tr1=br(b5+1);
02670 ti1=bi(b5+1);
02671 tr2=br(b56+1);
02672 ti2=bi(b56+1);
02673
02674 br(b5+1)=tr2-tr1;
02675 bi(b5+1)=ti2-ti1;
02676 br(b56+1)=tr1+tr2;
02677 bi(b56+1)=ti1+ti2;
02678
02679 b5=b5+b4;
02680 b56=b5-b6;
02681 if ( b5 <= b3 ) goto L14;
02682 if ( b6 == b7 ) goto L20;
02683
02684 b4=b7;
02685 cc=2.0f*pow(tab1(l),2);
02686 c=1.0f-cc;
02687 l++;
02688 ss=sgn*tab1(l);
02689 s=ss;
02690
02691 L16:
02692 b5=b6+b4;
02693 b4=2*b6;
02694 b56=b5-b6;
02695
02696 L18:
02697 tr1=br(b5+1);
02698 ti1=bi(b5+1);
02699 tr2=br(b56+1);
02700 ti2=bi(b56+1);
02701 br(b5+1)=c*(tr2-tr1)-s*(ti2-ti1);
02702 bi(b5+1)=s*(tr2-tr1)+c*(ti2-ti1);
02703 br(b56+1)=tr1+tr2;
02704 bi(b56+1)=ti1+ti2;
02705
02706 b5=b5+b4;
02707 b56=b5-b6;
02708 if ( b5 <= b3 ) goto L18;
02709 b4=b5-b6;
02710 b5=b4-b3;
02711 c=-c;
02712 b4=b6-b5;
02713 if ( b5 < b4 ) goto L16;
02714 b4=b4+b7;
02715 if ( b4 >= b5 ) goto L12;
02716
02717 t=c-cc*c-ss*s;
02718 s=s+ss*c-cc*s;
02719 c=t;
02720 goto L16;
02721
02722 L20:
02723 ix0=b3/2;
02724 b3=b3-b7;
02725 b4=0;
02726 b5=0;
02727 b6=ix0;
02728 ix1=0;
02729 if (b6 == b7) goto EXIT;
02730
02731 L22:
02732 b4=b3-b4;
02733 b5=b3-b5;
02734 x2=br(b4+1);
02735 x3=br(b5+1);
02736 x4=bi(b4+1);
02737 x5=bi(b5+1);
02738 br(b4+1)=x3;
02739 br(b5+1)=x2;
02740 bi(b4+1)=x5;
02741 bi(b5+1)=x4;
02742 if(b6 < b4) goto L22;
02743
02744 L24:
02745 b4=b4+b7;
02746 b5=b6+b5;
02747 x2=br(b4+1);
02748 x3=br(b5+1);
02749 x4=bi(b4+1);
02750 x5=bi(b5+1);
02751 br(b4+1)=x3;
02752 br(b5+1)=x2;
02753 bi(b4+1)=x5;
02754 bi(b5+1)=x4;
02755 ix0=b6;
02756
02757 L26:
02758 ix0=ix0/2;
02759 ix1=ix1-ix0;
02760 if( ix1 >= 0) goto L26;
02761
02762 ix0=2*ix0;
02763 b4=b4+b7;
02764 ix1=ix1+ix0;
02765 b5=ix1;
02766 if ( b5 >= b4) goto L22;
02767 if ( b4 < b6) goto L24;
02768
02769 EXIT:
02770 status = 0;
02771 }
|
|
||||||||||||||||||||
|
Definition at line 2774 of file util_sparx.cpp. References abs, bi, br, status, t, and tab1. Referenced by fftr_q(). 02775 {
02776 // dimension br(1),bi(1)
02777
02778 int b3,b4,b5,b6,b7,b56;
02779 int n, k, l, j, i, ix0, ix1;
02780 float rni, tr1, ti1, tr2, ti2, cc, c, ss, s, t, x2, x3, x4, x5, sgn;
02781 int status=0;
02782
02783 const float tab1[] = {
02784 9.58737990959775e-5f,
02785 1.91747597310703e-4f,
02786 3.83495187571395e-4f,
02787 7.66990318742704e-4f,
02788 1.53398018628476e-3f,
02789 3.06795676296598e-3f,
02790 6.13588464915449e-3f,
02791 1.22715382857199e-2f,
02792 2.45412285229123e-2f,
02793 4.90676743274181e-2f,
02794 9.80171403295604e-2f,
02795 1.95090322016128e-1f,
02796 3.82683432365090e-1f,
02797 7.07106781186546e-1f,
02798 1.00000000000000f,
02799 };
02800
02801 n=(int)pow(2.0f,ln);
02802
02803 k=abs(ks);
02804 l=16-ln;
02805 b3=n*k;
02806 b6=b3;
02807 b7=k;
02808 if( ks > 0 ) {
02809 sgn=1.0f;
02810 } else {
02811 sgn=-1.0f;
02812 rni=1.0f/(float)n;
02813 j=1;
02814 for (i=1; i<=n; i++) {
02815 br(j)=br(j)*rni;
02816 bi(j)=bi(j)*rni;
02817 j=j+k;
02818 }
02819 }
02820 L12:
02821 b6=b6/2;
02822 b5=b6;
02823 b4=2*b6;
02824 b56=b5-b6;
02825 L14:
02826 tr1=br(b5+1);
02827 ti1=bi(b5+1);
02828
02829 tr2=br(b56+1);
02830 ti2=bi(b56+1);
02831
02832 br(b5+1)=tr2-tr1;
02833 bi(b5+1)=ti2-ti1;
02834 br(b56+1)=tr1+tr2;
02835 bi(b56+1)=ti1+ti2;
02836
02837 b5=b5+b4;
02838 b56=b5-b6;
02839 if ( b5 <= b3 ) goto L14;
02840 if ( b6 == b7 ) goto L20;
02841
02842 b4=b7;
02843 cc=2.0f*pow(tab1(l),2);
02844 c=1.0f-cc;
02845 l++;
02846 ss=sgn*tab1(l);
02847 s=ss;
02848 L16:
02849 b5=b6+b4;
02850 b4=2*b6;
02851 b56=b5-b6;
02852 L18:
02853 tr1=br(b5+1);
02854 ti1=bi(b5+1);
02855 tr2=br(b56+1);
02856 ti2=bi(b56+1);
02857 br(b5+1)=c*(tr2-tr1)-s*(ti2-ti1);
02858 bi(b5+1)=s*(tr2-tr1)+c*(ti2-ti1);
02859 br(b56+1)=tr1+tr2;
02860 bi(b56+1)=ti1+ti2;
02861
02862 b5=b5+b4;
02863 b56=b5-b6;
02864 if(b5 <= b3) goto L18;
02865 b4=b5-b6;
02866 b5=b4-b3;
02867 c=-c;
02868 b4=b6-b5;
02869 if(b5 < b4) goto L16;
02870 b4=b4+b7;
02871 if(b4 >= b5) goto L12;
02872
02873 t=c-cc*c-ss*s;
02874 s=s+ss*c-cc*s;
02875 c=t;
02876 goto L16;
02877 L20:
02878 ix0=b3/2;
02879 b3=b3-b7;
02880 b4=0;
02881 b5=0;
02882 b6=ix0;
02883 ix1=0;
02884 if ( b6 == b7) goto EXIT;
02885 L22:
02886 b4=b3-b4;
02887 b5=b3-b5;
02888 x2=br(b4+1);
02889 x3=br(b5+1);
02890 x4=bi(b4+1);
02891 x5=bi(b5+1);
02892 br(b4+1)=x3;
02893 br(b5+1)=x2;
02894 bi(b4+1)=x5;
02895 bi(b5+1)=x4;
02896 if (b6 < b4) goto L22;
02897 L24:
02898 b4=b4+b7;
02899 b5=b6+b5;
02900 x2=br(b4+1);
02901 x3=br(b5+1);
02902 x4=bi(b4+1);
02903 x5=bi(b5+1);
02904 br(b4+1)=x3;
02905 br(b5+1)=x2;
02906 bi(b4+1)=x5;
02907 bi(b5+1)=x4;
02908 ix0=b6;
02909 L26:
02910 ix0=ix0/2;
02911 ix1=ix1-ix0;
02912 if(ix1 >= 0) goto L26;
02913
02914 ix0=2*ix0;
02915 b4=b4+b7;
02916 ix1=ix1+ix0;
02917 b5=ix1;
02918 if (b5 >= b4) goto L22;
02919 if (b4 < b6) goto L24;
02920 EXIT:
02921 status = 0;
02922 }
|
|
||||||||||||
|
Definition at line 3006 of file util_sparx.cpp. References abs, fftc_d(), t, tab1, and xcmplx. Referenced by Crosrng_e(), Crosrng_ew(), Crosrng_ms(), Crosrng_ms_delta(), Crosrng_msg(), Crosrng_msg_m(), Crosrng_msg_s(), Crosrng_ns(), Crosrng_psi_0_180(), Crosrng_psi_0_180_no_mirror(), and Crosrng_sm_psi(). 03007 {
03008 // double precision x(2,1)
03009 int i1, i2, nu, inv, nu1, n, isub, n2, i;
03010 double tr1,tr2,ti1,ti2,tr,ti;
03011 double cc,c,ss,s,t;
03012 const double tab1[] = {
03013 9.58737990959775e-5,
03014 1.91747597310703e-4,
03015 3.83495187571395e-4,
03016 7.66990318742704e-4,
03017 1.53398018628476e-3,
03018 3.06795676296598e-3,
03019 6.13588464915449e-3,
03020 1.22715382857199e-2,
03021 2.45412285229123e-2,
03022 4.90676743274181e-2,
03023 9.80171403295604e-2,
03024 1.95090322016128e-1,
03025 3.82683432365090e-1,
03026 7.07106781186546e-1,
03027 1.00000000000000,
03028 };
03029
03030 nu=abs(nv);
03031 inv=nv/nu;
03032 nu1=nu-1;
03033 n=(int)pow(2.0f,nu1);
03034 isub=16-nu1;
03035 ss=-tab1(isub);
03036 cc=-2.0*pow(tab1(isub-1),2);
03037 c=1.0f;
03038 s=0.0f;
03039 n2=n/2;
03040
03041 if ( inv > 0 ) {
03042 fftc_d(&xcmplx(1,1),&xcmplx(2,1),nu1,2);
03043 tr=xcmplx(1,1);
03044 ti=xcmplx(2,1);
03045 xcmplx(1,1)=tr+ti;
03046 xcmplx(2,1)=tr-ti;
03047 for (i=1;i<=n2;i++) {
03048 i1=i+1;
03049 i2=n-i+1;
03050 tr1=xcmplx(1,i1);
03051 tr2=xcmplx(1,i2);
03052 ti1=xcmplx(2,i1);
03053 ti2=xcmplx(2,i2);
03054 t=(cc*c-ss*s)+c;
03055 s=(cc*s+ss*c)+s;
03056 c=t;
03057 xcmplx(1,i1)=0.5*((tr1+tr2)+(ti1+ti2)*c-(tr1-tr2)*s);
03058 xcmplx(1,i2)=0.5*((tr1+tr2)-(ti1+ti2)*c+(tr1-tr2)*s);
03059 xcmplx(2,i1)=0.5*((ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c);
03060 xcmplx(2,i2)=0.5*(-(ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c);
03061 }
03062 } else {
03063 tr=xcmplx(1,1);
03064 ti=xcmplx(2,1);
03065 xcmplx(1,1)=0.5*(tr+ti);
03066 xcmplx(2,1)=0.5*(tr-ti);
03067 for (i=1; i<=n2; i++) {
03068 i1=i+1;
03069 i2=n-i+1;
03070 tr1=xcmplx(1,i1);
03071 tr2=xcmplx(1,i2);
03072 ti1=xcmplx(2,i1);
03073 ti2=xcmplx(2,i2);
03074 t=(cc*c-ss*s)+c;
03075 s=(cc*s+ss*c)+s;
03076 c=t;
03077 xcmplx(1,i1)=0.5*((tr1+tr2)-(tr1-tr2)*s-(ti1+ti2)*c);
03078 xcmplx(1,i2)=0.5*((tr1+tr2)+(tr1-tr2)*s+(ti1+ti2)*c);
03079 xcmplx(2,i1)=0.5*((ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s);
03080 xcmplx(2,i2)=0.5*(-(ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s);
03081 }
03082 fftc_d(&xcmplx(1,1),&xcmplx(2,1),nu1,-2);
03083 }
03084 }
|
|
||||||||||||
|
Definition at line 2924 of file util_sparx.cpp. References abs, fftc_q(), t, tab1, and xcmplx. Referenced by Crosrng_msg_vec(), Frngs(), and Frngs_inv(). 02925 {
02926 // dimension xcmplx(2,1); xcmplx(1,i) --- real, xcmplx(2,i) --- imaginary
02927
02928 int nu, inv, nu1, n, isub, n2, i1, i2, i;
02929 float ss, cc, c, s, tr, ti, tr1, tr2, ti1, ti2, t;
02930
02931 const float tab1[] = {
02932 9.58737990959775e-5f,
02933 1.91747597310703e-4f,
02934 3.83495187571395e-4f,
02935 7.66990318742704e-4f,
02936 1.53398018628476e-3f,
02937 3.06795676296598e-3f,
02938 6.13588464915449e-3f,
02939 1.22715382857199e-2f,
02940 2.45412285229123e-2f,
02941 4.90676743274181e-2f,
02942 9.80171403295604e-2f,
02943 1.95090322016128e-1f,
02944 3.82683432365090e-1f,
02945 7.07106781186546e-1f,
02946 1.00000000000000f,
02947 };
02948
02949 nu=abs(nv);
02950 inv=nv/nu;
02951 nu1=nu-1;
02952 n=(int)pow(2.f,nu1);
02953 isub=16-nu1;
02954
02955 ss=-tab1(isub);
02956 cc=-2.0f*pow(tab1(isub-1),2.f);
02957 c=1.0f;
02958 s=0.0f;
02959 n2=n/2;
02960 if ( inv > 0) {
02961 fftc_q(&xcmplx(1,1),&xcmplx(2,1),nu1,2);
02962 tr=xcmplx(1,1);
02963 ti=xcmplx(2,1);
02964 xcmplx(1,1)=tr+ti;
02965 xcmplx(2,1)=tr-ti;
02966 for (i=1;i<=n2;i++) {
02967 i1=i+1;
02968 i2=n-i+1;
02969 tr1=xcmplx(1,i1);
02970 tr2=xcmplx(1,i2);
02971 ti1=xcmplx(2,i1);
02972 ti2=xcmplx(2,i2);
02973 t=(cc*c-ss*s)+c;
02974 s=(cc*s+ss*c)+s;
02975 c=t;
02976 xcmplx(1,i1)=0.5f*((tr1+tr2)+(ti1+ti2)*c-(tr1-tr2)*s);
02977 xcmplx(1,i2)=0.5f*((tr1+tr2)-(ti1+ti2)*c+(tr1-tr2)*s);
02978 xcmplx(2,i1)=0.5f*((ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c);
02979 xcmplx(2,i2)=0.5f*(-(ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c);
02980 }
02981 } else {
02982 tr=xcmplx(1,1);
02983 ti=xcmplx(2,1);
02984 xcmplx(1,1)=0.5f*(tr+ti);
02985 xcmplx(2,1)=0.5f*(tr-ti);
02986 for (i=1; i<=n2; i++) {
02987 i1=i+1;
02988 i2=n-i+1;
02989 tr1=xcmplx(1,i1);
02990 tr2=xcmplx(1,i2);
02991 ti1=xcmplx(2,i1);
02992 ti2=xcmplx(2,i2);
02993 t=(cc*c-ss*s)+c;
02994 s=(cc*s+ss*c)+s;
02995 c=t;
02996 xcmplx(1,i1)=0.5f*((tr1+tr2)-(tr1-tr2)*s-(ti1+ti2)*c);
02997 xcmplx(1,i2)=0.5f*((tr1+tr2)+(tr1-tr2)*s+(ti1+ti2)*c);
02998 xcmplx(2,i1)=0.5f*((ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s);
02999 xcmplx(2,i2)=0.5f*(-(ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s);
03000 }
03001 fftc_q(&xcmplx(1,1),&xcmplx(2,1),nu1,-2);
03002 }
03003 }
|
|
|
lock a file. If the lock fails, wait for 1 second; then try again. Repleat this wait-try for a maxinum of 5 times unless the lock succeeds.
Definition at line 137 of file util.cpp. References LOGERR, and NullPointerException. 00138 {
00139 #ifdef WIN32
00140 return 1;
00141 #else
00142
00143 if (!file) {
00144 throw NullPointerException("Tried to lock NULL file");
00145 }
00146
00147 int fdes = fileno(file);
00148
00149 struct flock fl;
00150 fl.l_type = F_WRLCK;
00151 fl.l_whence = SEEK_SET;
00152 fl.l_start = 0;
00153 fl.l_len = 0;
00154 #ifdef WIN32
00155 fl.l_pid = _getpid();
00156 #else
00157 fl.l_pid = getpid();
00158 #endif
00159
00160 #if defined __sgi
00161 fl.l_sysid = getpid();
00162 #endif
00163
00164 int err = 0;
00165 if (fcntl(fdes, F_SETLKW, &fl) == -1) {
00166 LOGERR("file locking error! NFS problem?");
00167
00168 int i = 0;
00169 for (i = 0; i < 5; i++) {
00170 if (fcntl(fdes, F_SETLKW, &fl) != -1) {
00171 break;
00172 }
00173 else {
00174 #ifdef WIN32
00175 Sleep(1000);
00176 #else
00177 sleep(1);
00178 #endif
00179
00180 }
00181 }
00182 if (i == 5) {
00183 LOGERR("Fatal file locking error");
00184 err = 1;
00185 }
00186 }
00187
00188 return err;
00189 #endif
00190 }
|
|
||||||||||||||||||||
|
Find the maximum value and (optional) its index in an array.
Definition at line 814 of file util.cpp. References Assert, data, max, and NullPointerException. Referenced by EMAN::RotateTranslateFlipAlignerPawel::align(), EMAN::RotateTranslateAlignerPawel::align(), EMAN::RotationalAlignerIterative::align(), EMAN::RotatePrecenterAligner::align(), and EMAN::RotationalAligner::align_180_ambiguous(). 00815 {
00816 Assert(nitems > 0);
00817
00818 if (!data || !max_val || !max_index) {
00819 throw NullPointerException("data/max_val/max_index");
00820 }
00821 float max = -FLT_MAX;
00822 int m = 0;
00823
00824 for (size_t i = 0; i < nitems; i++) {
00825 if (data[i] > max) {
00826 max = data[i];
00827 m = (int)i;
00828 }
00829 }
00830
00831 *max_val = (float)max;
00832
00833 if (max_index) {
00834 *max_index = m;
00835 }
00836 }
|
|
||||||||||||||||||||||||||||
|
Find the maximum value and (optional) its index, minimum value and (optional) its index in an array.
Definition at line 838 of file util.cpp. References Assert, data, max, min, and NullPointerException. 00841 {
00842 Assert(nitems > 0);
00843
00844 if (!data || !max_val || !min_val || !max_index || !min_index) {
00845 throw NullPointerException("data/max_val/min_val/max_index/min_index");
00846 }
00847 float max = -FLT_MAX;
00848 float min = FLT_MAX;
00849 int max_i = 0;
00850 int min_i = 0;
00851
00852 for (size_t i = 0; i < nitems; i++) {
00853 if (data[i] > max) {
00854 max = data[i];
00855 max_i = (int)i;
00856 }
00857 if (data[i] < min) {
00858 min = data[i];
00859 min_i = (int)i;
00860 }
00861 }
00862
00863 *max_val = max;
00864 *min_val = min;
00865
00866 if (min_index) {
00867 *min_index = min_i;
00868 }
00869
00870 if (max_index) {
00871 *max_index = max_i;
00872 }
00873
00874 }
|
|
||||||||||||||||||||||||||||
|
Definition at line 7827 of file util_sparx.cpp. 07828 {
07829 ENTERFUNC;
07830 int i = k;
07831 while( i == k ) i = rand()%len;
07832 std::swap(key[i], key[k]);
07833 std::swap(x[i], x[k]);
07834 std::swap(y[i], y[k]);
07835 std::swap(z[i], z[k]);
07836 EXITFUNC;
07837 }
|
|
||||||||||||
|
flip the phase of a complex data array.
Definition at line 82 of file util.cpp. References Assert, data, and NullPointerException. 00083 {
00084 Assert(n > 0);
00085
00086 if (!data) {
00087 throw NullPointerException("pixel data array");
00088 }
00089
00090 for (size_t i = 0; i < n; i += 2) {
00091 data[i + 1] *= -1;
00092 }
00093 }
|
|
||||||||||||||||
|
Vertically flip the data of a 2D real image.
Definition at line 217 of file util.cpp. References Assert, data, NullPointerException, nx, and ny. 00218 {
00219 if (!data) {
00220 throw NullPointerException("image data array");
00221 }
00222 Assert(nx > 0);
00223 Assert(ny > 0);
00224
00225 float *buf = new float[nx];
00226 size_t row_size = nx * sizeof(float);
00227
00228 for (size_t i = 0; i < ny / 2; i++) {
00229 memcpy(buf, &data[i * nx], row_size);
00230 memcpy(&data[i * nx], &data[(ny - 1 - i) * nx], row_size);
00231 memcpy(&data[(ny - 1 - i) * nx], buf, row_size);
00232 }
00233
00234 if( buf )
00235 {
00236 delete[]buf;
00237 buf = 0;
00238 }
00239 }
|
|
||||||||||||
|
This function conducts the Single Precision Fourier Transform for a set of rings.
Definition at line 3091 of file util_sparx.cpp. References circ, fftr_q(), EMAN::EMData::get_data(), log(), and numr. Referenced by ali2d_ccf_list(), multiref_peaks_ali2d(), multiref_peaks_compress_ali2d(), multiref_polar_ali_2d(), multiref_polar_ali_2d_delta(), multiref_polar_ali_2d_local(), multiref_polar_ali_2d_local_psi(), multiref_polar_ali_2d_nom(), multiref_polar_ali_2d_peaklist(), multiref_polar_ali_helical(), multiref_polar_ali_helical_90(), multiref_polar_ali_helical_90_local(), and multiref_polar_ali_helical_local(). 03091 {
03092 int nring = numr.size()/3;
03093 float *circ = circp->get_data();
03094 int i, l;
03095 for (i=1; i<=nring;i++) {
03096
03097 #ifdef _WIN32
03098 l = (int)( log((float)numr(3,i))/log(2.0f) );
03099 #else
03100 l=(int)(log2(numr(3,i)));
03101 #endif //_WIN32
03102
03103 fftr_q(&circ(numr(2,i)),l);
03104 }
03105 }
|
|
||||||||||||
|
This function conducts the Single Precision Inverse Fourier Transform for a set of rings.
Definition at line 3107 of file util_sparx.cpp. References circ, fftr_q(), EMAN::EMData::get_data(), log(), and numr. 03107 {
03108 int nring = numr.size()/3;
03109 float *circ = circp->get_data();
03110 int i, l;
03111 for (i=1; i<=nring;i++) {
03112
03113 #ifdef _WIN32
03114 l = (int)( log((float)numr(3,i))/log(2.0f) );
03115 #else
03116 l=(int)(log2(numr(3,i)));
03117 #endif //_WIN32
03118
03119 fftr_q(&circ(numr(2,i)),-l);
03120 }
03121 }
|
|
||||||||||||||||||||||||||||||||||||
|
make an intelligent "guess" at the largest weight of all possible feasible matches. we make "n_guesses" guesses and return the largest one. the largest weight of all feasible matches is guaranteed to be larger than or equal to the returned guess. |
|
|
Definition at line 20067 of file util_sparx.cpp. References Assert, find_group(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), nx, ny, EMAN::EMData::set_size(), and EMAN::EMData::to_zero(). 20068 {
20069 int nx = mg->get_xsize();
20070 int ny = mg->get_ysize();
20071 int nz = mg->get_zsize();
20072
20073 EMData* visited = new EMData();
20074 visited->set_size( nx, ny, nz );
20075 visited->to_zero();
20076 int grpid = 0;
20077 int maxgrp = 0;
20078 int maxsize = 0;
20079 for( int iz=0; iz < nz; ++iz ) {
20080 for( int iy=0; iy < ny; ++iy ) {
20081 for( int ix=0; ix < nx; ++ix ) {
20082 if( (*mg)(ix, iy, iz)==0.0 ) continue;
20083
20084 if( (*visited)(ix, iy, iz) > 0.0 ) {
20085 // visited before, must be in other group.
20086 continue;
20087 }
20088
20089 grpid++;
20090 int grpsize = find_group( ix, iy, iz, grpid, mg, visited );
20091 if( grpsize > maxsize ) {
20092 maxsize = grpsize;
20093 maxgrp = grpid;
20094 }
20095 }
20096 }
20097 }
20098
20099 Assert( maxgrp > 0 );
20100
20101 int npoint = 0;
20102 EMData* result = new EMData();
20103 result->set_size( nx, ny, nz );
20104 result->to_zero();
20105
20106 for( int iz=0; iz < nz; ++iz ) {
20107 for( int iy=0; iy < ny; ++iy ) {
20108 for( int ix=0; ix < nx; ++ix ) {
20109 if( (*visited)(ix, iy, iz)==maxgrp ) {
20110 (*result)(ix,iy,iz) = 1.0;
20111 npoint++;
20112 }
20113 }
20114 }
20115 }
20116
20117 Assert( npoint==maxsize );
20118 delete visited;
20119 return result;
20120
20121 }
|
|
|
Get a filename's extension.
Definition at line 492 of file util.cpp. Referenced by EMAN::EMUtil::fast_get_image_type(), and EMAN::EMUtil::get_image_type(). 00493 {
00494 if (filename == "") {
00495 return "";
00496 }
00497
00498 string result = "";
00499 const char *ext = strrchr(filename.c_str(), '.');
00500 if (ext) {
00501 ext++;
00502 result = string(ext);
00503 }
00504 return result;
00505 }
|
|
||||||||||||
|
Get a float random number between low and high, [low, high).
Definition at line 707 of file util.cpp. References EMAN::Randnum::get_frand(). 00708 {
00709 Randnum* randnum = Randnum::Instance();
00710 return randnum->get_frand(lo, hi);
00711 }
|
|
||||||||||||
|
Get a float random number between low and high, [low, high).
Definition at line 701 of file util.cpp. References EMAN::Randnum::get_frand(). 00702 {
00703 Randnum* randnum = Randnum::Instance();
00704 return randnum->get_frand(lo, hi);
00705 }
|
|
||||||||||||
|
Get a float random number between low and high, [low, high).
Definition at line 696 of file util.cpp. Referenced by EMAN::OrientationGenerator::add_orientation(), ali2d_ccf_list(), EMAN::RandomOrientationGenerator::gen_orientations(), EMAN::KmeansSegmentProcessor::process(), EMAN::TestImageFourierNoiseProfile::process_inplace(), and EMAN::TestImageFourierNoiseGaussian::process_inplace(). 00697 {
00698 return get_frand((float)lo, (float)hi);
00699 }
|
|
||||||||||||
|
Get a Gaussian random number.
Definition at line 808 of file util.cpp. References EMAN::Randnum::get_gauss_rand(). Referenced by EMAN::EmanOrientationGenerator::gen_orientations(), and main(). 00809 {
00810 Randnum* randnum = Randnum::Instance();
00811 return randnum->get_gauss_rand(mean, sigma);
00812 }
|
|
||||||||||||
|
Get an integer random number between low and high, [low, high].
Definition at line 690 of file util.cpp. References EMAN::Randnum::get_irand(). 00691 {
00692 Randnum* randnum = Randnum::Instance();
00693 return randnum->get_irand(lo, hi);
00694 }
|
|
|
Extract a single line from a multi-line string.
The line delimiter is '
Definition at line 267 of file util.cpp. References NullPointerException. Referenced by EMAN::XplorIO::is_valid(). 00268 {
00269 if (!slines || !(*slines)) {
00270 throw NullPointerException("Null string");
00271 }
00272
00273 string result = "";
00274 char *str = *slines;
00275
00276 while (*str != '\n' && *str != '\0') {
00277 result.push_back(*str);
00278 str++;
00279 }
00280 if (*str != '\0') {
00281 str++;
00282 }
00283 *slines = str;
00284
00285 return result;
00286 }
|
|
||||||||||||||||||||
|
Get the maximum of 4 numbers.
|
|
||||||||||||||||
|
Get the maximum of 3 numbers.
|
|
||||||||||||
|
Get the maximum of 2 numbers.
|
|
||||||||||||||||||||
|
Get the minimum of 4 numbers.
|
|
||||||||||||||||
|
Get the minimum of 3 numbers.
|
|
||||||||||||
|
Get the minimum of 2 numbers.
|
|
||||||||||||||||
|
Get the minimum of 3 numbers.
|
|
||||||||||||
|
Get the minimum of 2 numbers.
Definition at line 1731 of file util.h. Referenced by EMAN::PawelProjector::backproject3d(), EMAN::ChaoProjector::backproject3d(), EMAN::ChaoProjector::project3d(), EMAN::FourierGriddingProjector::project3d(), and EMAN::PawelProjector::project3d(). |
|
||||||||||||||||||||||||||||||||||||
|
Definition at line 774 of file util_sparx.cpp. References data, EMAN::Util::KaiserBessel::get_window_size(), EMAN::Util::KaiserBessel::i0win_tab(), nx, ny, restrict1(), and round(). Referenced by Polar2Dmi(). 00774 {
00775 int K = kb.get_window_size();
00776 int kbmin = -K/2;
00777 int kbmax = -kbmin;
00778 int kbc = kbmax+1;
00779
00780 float pixel =0.0f;
00781 float w=0.0f;
00782
00783 delx = restrict1(delx, nx);
00784 int inxold = int(round(delx));
00785 if ( ny < 2 ) { //1D
00786 float tablex1 = kb.i0win_tab(delx-inxold+3);
00787 float tablex2 = kb.i0win_tab(delx-inxold+2);
00788 float tablex3 = kb.i0win_tab(delx-inxold+1);
00789 float tablex4 = kb.i0win_tab(delx-inxold);
00790 float tablex5 = kb.i0win_tab(delx-inxold-1);
00791 float tablex6 = kb.i0win_tab(delx-inxold-2);
00792 float tablex7 = kb.i0win_tab(delx-inxold-3);
00793
00794 int x1, x2, x3, x4, x5, x6, x7;
00795
00796 if ( inxold <= kbc || inxold >=nx-kbc-2 ) {
00797 x1 = (inxold-3+nx)%nx;
00798 x2 = (inxold-2+nx)%nx;
00799 x3 = (inxold-1+nx)%nx;
00800 x4 = (inxold +nx)%nx;
00801 x5 = (inxold+1+nx)%nx;
00802 x6 = (inxold+2+nx)%nx;
00803 x7 = (inxold+3+nx)%nx;
00804 } else {
00805 x1 = inxold-3;
00806 x2 = inxold-2;
00807 x3 = inxold-1;
00808 x4 = inxold;
00809 x5 = inxold+1;
00810 x6 = inxold+2;
00811 x7 = inxold+3;
00812 }
00813
00814 pixel = data[x1]*tablex1 + data[x2]*tablex2 + data[x3]*tablex3 +
00815 data[x4]*tablex4 + data[x5]*tablex5 + data[x6]*tablex6 +
00816 data[x7]*tablex7 ;
00817
00818 w = tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7;
00819 } else if ( nz < 2 ) { // 2D
00820 dely = restrict1(dely, ny);
00821 int inyold = int(round(dely));
00822 float tablex1 = kb.i0win_tab(delx-inxold+3);
00823 float tablex2 = kb.i0win_tab(delx-inxold+2);
00824 float tablex3 = kb.i0win_tab(delx-inxold+1);
00825 float tablex4 = kb.i0win_tab(delx-inxold);
00826 float tablex5 = kb.i0win_tab(delx-inxold-1);
00827 float tablex6 = kb.i0win_tab(delx-inxold-2);
00828 float tablex7 = kb.i0win_tab(delx-inxold-3);
00829
00830 float tabley1 = kb.i0win_tab(dely-inyold+3);
00831 float tabley2 = kb.i0win_tab(dely-inyold+2);
00832 float tabley3 = kb.i0win_tab(dely-inyold+1);
00833 float tabley4 = kb.i0win_tab(dely-inyold);
00834 float tabley5 = kb.i0win_tab(dely-inyold-1);
00835 float tabley6 = kb.i0win_tab(dely-inyold-2);
00836 float tabley7 = kb.i0win_tab(dely-inyold-3);
00837
00838 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7;
00839
00840 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 ) {
00841 x1 = (inxold-3+nx)%nx;
00842 x2 = (inxold-2+nx)%nx;
00843 x3 = (inxold-1+nx)%nx;
00844 x4 = (inxold +nx)%nx;
00845 x5 = (inxold+1+nx)%nx;
00846 x6 = (inxold+2+nx)%nx;
00847 x7 = (inxold+3+nx)%nx;
00848
00849 y1 = ((inyold-3+ny)%ny)*nx;
00850 y2 = ((inyold-2+ny)%ny)*nx;
00851 y3 = ((inyold-1+ny)%ny)*nx;
00852 y4 = ((inyold +ny)%ny)*nx;
00853 y5 = ((inyold+1+ny)%ny)*nx;
00854 y6 = ((inyold+2+ny)%ny)*nx;
00855 y7 = ((inyold+3+ny)%ny)*nx;
00856 } else {
00857 x1 = inxold-3;
00858 x2 = inxold-2;
00859 x3 = inxold-1;
00860 x4 = inxold;
00861 x5 = inxold+1;
00862 x6 = inxold+2;
00863 x7 = inxold+3;
00864
00865 y1 = (inyold-3)*nx;
00866 y2 = (inyold-2)*nx;
00867 y3 = (inyold-1)*nx;
00868 y4 = inyold*nx;
00869 y5 = (inyold+1)*nx;
00870 y6 = (inyold+2)*nx;
00871 y7 = (inyold+3)*nx;
00872 }
00873
00874 pixel = ( data[x1+y1]*tablex1 + data[x2+y1]*tablex2 + data[x3+y1]*tablex3 +
00875 data[x4+y1]*tablex4 + data[x5+y1]*tablex5 + data[x6+y1]*tablex6 +
00876 data[x7+y1]*tablex7 ) * tabley1 +
00877 ( data[x1+y2]*tablex1 + data[x2+y2]*tablex2 + data[x3+y2]*tablex3 +
00878 data[x4+y2]*tablex4 + data[x5+y2]*tablex5 + data[x6+y2]*tablex6 +
00879 data[x7+y2]*tablex7 ) * tabley2 +
00880 ( data[x1+y3]*tablex1 + data[x2+y3]*tablex2 + data[x3+y3]*tablex3 +
00881 data[x4+y3]*tablex4 + data[x5+y3]*tablex5 + data[x6+y3]*tablex6 +
00882 data[x7+y3]*tablex7 ) * tabley3 +
00883 ( data[x1+y4]*tablex1 + data[x2+y4]*tablex2 + data[x3+y4]*tablex3 +
00884 data[x4+y4]*tablex4 + data[x5+y4]*tablex5 + data[x6+y4]*tablex6 +
00885 data[x7+y4]*tablex7 ) * tabley4 +
00886 ( data[x1+y5]*tablex1 + data[x2+y5]*tablex2 + data[x3+y5]*tablex3 +
00887 data[x4+y5]*tablex4 + data[x5+y5]*tablex5 + data[x6+y5]*tablex6 +
00888 data[x7+y5]*tablex7 ) * tabley5 +
00889 ( data[x1+y6]*tablex1 + data[x2+y6]*tablex2 + data[x3+y6]*tablex3 +
00890 data[x4+y6]*tablex4 + data[x5+y6]*tablex5 + data[x6+y6]*tablex6 +
00891 data[x7+y6]*tablex7 ) * tabley6 +
00892 ( data[x1+y7]*tablex1 + data[x2+y7]*tablex2 + data[x3+y7]*tablex3 +
00893 data[x4+y7]*tablex4 + data[x5+y7]*tablex5 + data[x6+y7]*tablex6 +
00894 data[x7+y7]*tablex7 ) * tabley7;
00895
00896 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) *
00897 (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7);
00898 } else { // 3D
00899 dely = restrict1(dely, ny);
00900 int inyold = int(Util::round(dely));
00901 delz = restrict1(delz, nz);
00902 int inzold = int(Util::round(delz));
00903
00904 float tablex1 = kb.i0win_tab(delx-inxold+3);
00905 float tablex2 = kb.i0win_tab(delx-inxold+2);
00906 float tablex3 = kb.i0win_tab(delx-inxold+1);
00907 float tablex4 = kb.i0win_tab(delx-inxold);
00908 float tablex5 = kb.i0win_tab(delx-inxold-1);
00909 float tablex6 = kb.i0win_tab(delx-inxold-2);
00910 float tablex7 = kb.i0win_tab(delx-inxold-3);
00911
00912 float tabley1 = kb.i0win_tab(dely-inyold+3);
00913 float tabley2 = kb.i0win_tab(dely-inyold+2);
00914 float tabley3 = kb.i0win_tab(dely-inyold+1);
00915 float tabley4 = kb.i0win_tab(dely-inyold);
00916 float tabley5 = kb.i0win_tab(dely-inyold-1);
00917 float tabley6 = kb.i0win_tab(dely-inyold-2);
00918 float tabley7 = kb.i0win_tab(dely-inyold-3);
00919
00920 float tablez1 = kb.i0win_tab(delz-inzold+3);
00921 float tablez2 = kb.i0win_tab(delz-inzold+2);
00922 float tablez3 = kb.i0win_tab(delz-inzold+1);
00923 float tablez4 = kb.i0win_tab(delz-inzold);
00924 float tablez5 = kb.i0win_tab(delz-inzold-1);
00925 float tablez6 = kb.i0win_tab(delz-inzold-2);
00926 float tablez7 = kb.i0win_tab(delz-inzold-3);
00927
00928 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7, z1, z2, z3, z4, z5, z6, z7;
00929
00930 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 || inzold <= kbc || inzold >= nz-kbc-2 ) {
00931 x1 = (inxold-3+nx)%nx;
00932 x2 = (inxold-2+nx)%nx;
00933 x3 = (inxold-1+nx)%nx;
00934 x4 = (inxold +nx)%nx;
00935 x5 = (inxold+1+nx)%nx;
00936 x6 = (inxold+2+nx)%nx;
00937 x7 = (inxold+3+nx)%nx;
00938
00939 y1 = ((inyold-3+ny)%ny)*nx;
00940 y2 = ((inyold-2+ny)%ny)*nx;
00941 y3 = ((inyold-1+ny)%ny)*nx;
00942 y4 = ((inyold +ny)%ny)*nx;
00943 y5 = ((inyold+1+ny)%ny)*nx;
00944 y6 = ((inyold+2+ny)%ny)*nx;
00945 y7 = ((inyold+3+ny)%ny)*nx;
00946
00947 z1 = ((inzold-3+nz)%nz)*nx*ny;
00948 z2 = ((inzold-2+nz)%nz)*nx*ny;
00949 z3 = ((inzold-1+nz)%nz)*nx*ny;
00950 z4 = ((inzold +nz)%nz)*nx*ny;
00951 z5 = ((inzold+1+nz)%nz)*nx*ny;
00952 z6 = ((inzold+2+nz)%nz)*nx*ny;
00953 z7 = ((inzold+3+nz)%nz)*nx*ny;
00954 } else {
00955 x1 = inxold-3;
00956 x2 = inxold-2;
00957 x3 = inxold-1;
00958 x4 = inxold;
00959 x5 = inxold+1;
00960 x6 = inxold+2;
00961 x7 = inxold+3;
00962
00963 y1 = (inyold-3)*nx;
00964 y2 = (inyold-2)*nx;
00965 y3 = (inyold-1)*nx;
00966 y4 = inyold*nx;
00967 y5 = (inyold+1)*nx;
00968 y6 = (inyold+2)*nx;
00969 y7 = (inyold+3)*nx;
00970
00971 z1 = (inzold-3)*nx*ny;
00972 z2 = (inzold-2)*nx*ny;
00973 z3 = (inzold-1)*nx*ny;
00974 z4 = inzold*nx*ny;
00975 z5 = (inzold+1)*nx*ny;
00976 z6 = (inzold+2)*nx*ny;
00977 z7 = (inzold+3)*nx*ny;
00978 }
00979
00980 pixel = ( ( data[x1+y1+z1]*tablex1 + data[x2+y1+z1]*tablex2 + data[x3+y1+z1]*tablex3 +
00981 data[x4+y1+z1]*tablex4 + data[x5+y1+z1]*tablex5 + data[x6+y1+z1]*tablex6 +
00982 data[x7+y1+z1]*tablex7 ) * tabley1 +
00983 ( data[x1+y2+z1]*tablex1 + data[x2+y2+z1]*tablex2 + data[x3+y2+z1]*tablex3 +
00984 data[x4+y2+z1]*tablex4 + data[x5+y2+z1]*tablex5 + data[x6+y2+z1]*tablex6 +
00985 data[x7+y2+z1]*tablex7 ) * tabley2 +
00986 ( data[x1+y3+z1]*tablex1 + data[x2+y3+z1]*tablex2 + data[x3+y3+z1]*tablex3 +
00987 data[x4+y3+z1]*tablex4 + data[x5+y3+z1]*tablex5 + data[x6+y3+z1]*tablex6 +
00988 data[x7+y3+z1]*tablex7 ) * tabley3 +
00989 ( data[x1+y4+z1]*tablex1 + data[x2+y4+z1]*tablex2 + data[x3+y4+z1]*tablex3 +
00990 data[x4+y4+z1]*tablex4 + data[x5+y4+z1]*tablex5 + data[x6+y4+z1]*tablex6 +
00991 data[x7+y4+z1]*tablex7 ) * tabley4 +
00992 ( data[x1+y5+z1]*tablex1 + data[x2+y5+z1]*tablex2 + data[x3+y5+z1]*tablex3 +
00993 data[x4+y5+z1]*tablex4 + data[x5+y5+z1]*tablex5 + data[x6+y5+z1]*tablex6 +
00994 data[x7+y5+z1]*tablex7 ) * tabley5 +
00995 ( data[x1+y6+z1]*tablex1 + data[x2+y6+z1]*tablex2 + data[x3+y6+z1]*tablex3 +
00996 data[x4+y6+z1]*tablex4 + data[x5+y6+z1]*tablex5 + data[x6+y6+z1]*tablex6 +
00997 data[x7+y6+z1]*tablex7 ) * tabley6 +
00998 ( data[x1+y7+z1]*tablex1 + data[x2+y7+z1]*tablex2 + data[x3+y7+z1]*tablex3 +
00999 data[x4+y7+z1]*tablex4 + data[x5+y7+z1]*tablex5 + data[x6+y7+z1]*tablex6 +
01000 data[x7+y7+z1]*tablex7 ) * tabley7 ) *tablez1 +
01001 ( ( data[x1+y1+z2]*tablex1 + data[x2+y1+z2]*tablex2 + data[x3+y1+z2]*tablex3 +
01002 data[x4+y1+z2]*tablex4 + data[x5+y1+z2]*tablex5 + data[x6+y1+z2]*tablex6 +
01003 data[x7+y1+z2]*tablex7 ) * tabley1 +
01004 ( data[x1+y2+z2]*tablex1 + data[x2+y2+z2]*tablex2 + data[x3+y2+z2]*tablex3 +
01005 data[x4+y2+z2]*tablex4 + data[x5+y2+z2]*tablex5 + data[x6+y2+z2]*tablex6 +
01006 data[x7+y2+z2]*tablex7 ) * tabley2 +
01007 ( data[x1+y3+z2]*tablex1 + data[x2+y3+z2]*tablex2 + data[x3+y3+z2]*tablex3 +
01008 data[x4+y3+z2]*tablex4 + data[x5+y3+z2]*tablex5 + data[x6+y3+z2]*tablex6 +
01009 data[x7+y3+z2]*tablex7 ) * tabley3 +
01010 ( data[x1+y4+z2]*tablex1 + data[x2+y4+z2]*tablex2 + data[x3+y4+z2]*tablex3 +
01011 data[x4+y4+z2]*tablex4 + data[x5+y4+z2]*tablex5 + data[x6+y4+z2]*tablex6 +
01012 data[x7+y4+z2]*tablex7 ) * tabley4 +
01013 ( data[x1+y5+z2]*tablex1 + data[x2+y5+z2]*tablex2 + data[x3+y5+z2]*tablex3 +
01014 data[x4+y5+z2]*tablex4 + data[x5+y5+z2]*tablex5 + data[x6+y5+z2]*tablex6 +
01015 data[x7+y5+z2]*tablex7 ) * tabley5 +
01016 ( data[x1+y6+z2]*tablex1 + data[x2+y6+z2]*tablex2 + data[x3+y6+z2]*tablex3 +
01017 data[x4+y6+z2]*tablex4 + data[x5+y6+z2]*tablex5 + data[x6+y6+z2]*tablex6 +
01018 data[x7+y6+z2]*tablex7 ) * tabley6 +
01019 ( data[x1+y7+z2]*tablex1 + data[x2+y7+z2]*tablex2 + data[x3+y7+z2]*tablex3 +
01020 data[x4+y7+z2]*tablex4 + data[x5+y7+z2]*tablex5 + data[x6+y7+z2]*tablex6 +
01021 data[x7+y7+z2]*tablex7 ) * tabley7 ) *tablez2 +
01022 ( ( data[x1+y1+z3]*tablex1 + data[x2+y1+z3]*tablex2 + data[x3+y1+z3]*tablex3 +
01023 data[x4+y1+z3]*tablex4 + data[x5+y1+z3]*tablex5 + data[x6+y1+z3]*tablex6 +
01024 data[x7+y1+z3]*tablex7 ) * tabley1 +
01025 ( data[x1+y2+z3]*tablex1 + data[x2+y2+z3]*tablex2 + data[x3+y2+z3]*tablex3 +
01026 data[x4+y2+z3]*tablex4 + data[x5+y2+z3]*tablex5 + data[x6+y2+z3]*tablex6 +
01027 data[x7+y2+z3]*tablex7 ) * tabley2 +
01028 ( data[x1+y3+z3]*tablex1 + data[x2+y3+z3]*tablex2 + data[x3+y3+z3]*tablex3 +
01029 data[x4+y3+z3]*tablex4 + data[x5+y3+z3]*tablex5 + data[x6+y3+z3]*tablex6 +
01030 data[x7+y3+z3]*tablex7 ) * tabley3 +
01031 ( data[x1+y4+z3]*tablex1 + data[x2+y4+z3]*tablex2 + data[x3+y4+z3]*tablex3 +
01032 data[x4+y4+z3]*tablex4 + data[x5+y4+z3]*tablex5 + data[x6+y4+z3]*tablex6 +
01033 data[x7+y4+z3]*tablex7 ) * tabley4 +
01034 ( data[x1+y5+z3]*tablex1 + data[x2+y5+z3]*tablex2 + data[x3+y5+z3]*tablex3 +
01035 data[x4+y5+z3]*tablex4 + data[x5+y5+z3]*tablex5 + data[x6+y5+z3]*tablex6 +
01036 data[x7+y5+z3]*tablex7 ) * tabley5 +
01037 ( data[x1+y6+z3]*tablex1 + data[x2+y6+z3]*tablex2 + data[x3+y6+z3]*tablex3 +
01038 data[x4+y6+z3]*tablex4 + data[x5+y6+z3]*tablex5 + data[x6+y6+z3]*tablex6 +
01039 data[x7+y6+z3]*tablex7 ) * tabley6 +
01040 ( data[x1+y7+z3]*tablex1 + data[x2+y7+z3]*tablex2 + data[x3+y7+z3]*tablex3 +
01041 data[x4+y7+z3]*tablex4 + data[x5+y7+z3]*tablex5 + data[x6+y7+z3]*tablex6 +
01042 data[x7+y7+z3]*tablex7 ) * tabley7 ) *tablez3 +
01043 ( ( data[x1+y1+z4]*tablex1 + data[x2+y1+z4]*tablex2 + data[x3+y1+z4]*tablex3 +
01044 data[x4+y1+z4]*tablex4 + data[x5+y1+z4]*tablex5 + data[x6+y1+z4]*tablex6 +
01045 data[x7+y1+z4]*tablex7 ) * tabley1 +
01046 ( data[x1+y2+z4]*tablex1 + data[x2+y2+z4]*tablex2 + data[x3+y2+z4]*tablex3 +
01047 data[x4+y2+z4]*tablex4 + data[x5+y2+z4]*tablex5 + data[x6+y2+z4]*tablex6 +
01048 data[x7+y2+z4]*tablex7 ) * tabley2 +
01049 ( data[x1+y3+z4]*tablex1 + data[x2+y3+z4]*tablex2 + data[x3+y3+z4]*tablex3 +
01050 data[x4+y3+z4]*tablex4 + data[x5+y3+z4]*tablex5 + data[x6+y3+z4]*tablex6 +
01051 data[x7+y3+z4]*tablex7 ) * tabley3 +
01052 ( data[x1+y4+z4]*tablex1 + data[x2+y4+z4]*tablex2 + data[x3+y4+z4]*tablex3 +
01053 data[x4+y4+z4]*tablex4 + data[x5+y4+z4]*tablex5 + data[x6+y4+z4]*tablex6 +
01054 data[x7+y4+z4]*tablex7 ) * tabley4 +
01055 ( data[x1+y5+z4]*tablex1 + data[x2+y5+z4]*tablex2 + data[x3+y5+z4]*tablex3 +
01056 data[x4+y5+z4]*tablex4 + data[x5+y5+z4]*tablex5 + data[x6+y5+z4]*tablex6 +
01057 data[x7+y5+z4]*tablex7 ) * tabley5 +
01058 ( data[x1+y6+z4]*tablex1 + data[x2+y6+z4]*tablex2 + data[x3+y6+z4]*tablex3 +
01059 data[x4+y6+z4]*tablex4 + data[x5+y6+z4]*tablex5 + data[x6+y6+z4]*tablex6 +
01060 data[x7+y6+z4]*tablex7 ) * tabley6 +
01061 ( data[x1+y7+z4]*tablex1 + data[x2+y7+z4]*tablex2 + data[x3+y7+z4]*tablex3 +
01062 data[x4+y7+z4]*tablex4 + data[x5+y7+z4]*tablex5 + data[x6+y7+z4]*tablex6 +
01063 data[x7+y7+z4]*tablex7 ) * tabley7 ) *tablez4 +
01064 ( ( data[x1+y1+z5]*tablex1 + data[x2+y1+z5]*tablex2 + data[x3+y1+z5]*tablex3 +
01065 data[x4+y1+z5]*tablex4 + data[x5+y1+z5]*tablex5 + data[x6+y1+z5]*tablex6 +
01066 data[x7+y1+z5]*tablex7 ) * tabley1 +
01067 ( data[x1+y2+z5]*tablex1 + data[x2+y2+z5]*tablex2 + data[x3+y2+z5]*tablex3 +
01068 data[x4+y2+z5]*tablex4 + data[x5+y2+z5]*tablex5 + data[x6+y2+z5]*tablex6 +
01069 data[x7+y2+z5]*tablex7 ) * tabley2 +
01070 ( data[x1+y3+z5]*tablex1 + data[x2+y3+z5]*tablex2 + data[x3+y3+z5]*tablex3 +
01071 data[x4+y3+z5]*tablex4 + data[x5+y3+z5]*tablex5 + data[x6+y3+z5]*tablex6 +
01072 data[x7+y3+z5]*tablex7 ) * tabley3 +
01073 ( data[x1+y4+z5]*tablex1 + data[x2+y4+z5]*tablex2 + data[x3+y4+z5]*tablex3 +
01074 data[x4+y4+z5]*tablex4 + data[x5+y4+z5]*tablex5 + data[x6+y4+z5]*tablex6 +
01075 data[x7+y4+z5]*tablex7 ) * tabley4 +
01076 ( data[x1+y5+z5]*tablex1 + data[x2+y5+z5]*tablex2 + data[x3+y5+z5]*tablex3 +
01077 data[x4+y5+z5]*tablex4 + data[x5+y5+z5]*tablex5 + data[x6+y5+z5]*tablex6 +
01078 data[x7+y5+z5]*tablex7 ) * tabley5 +
01079 ( data[x1+y6+z5]*tablex1 + data[x2+y6+z5]*tablex2 + data[x3+y6+z5]*tablex3 +
01080 data[x4+y6+z5]*tablex4 + data[x5+y6+z5]*tablex5 + data[x6+y6+z5]*tablex6 +
01081 data[x7+y6+z5]*tablex7 ) * tabley6 +
01082 ( data[x1+y7+z5]*tablex1 + data[x2+y7+z5]*tablex2 + data[x3+y7+z5]*tablex3 +
01083 data[x4+y7+z5]*tablex4 + data[x5+y7+z5]*tablex5 + data[x6+y7+z5]*tablex6 +
01084 data[x7+y7+z5]*tablex7 ) * tabley7 ) *tablez5 +
01085 ( ( data[x1+y1+z6]*tablex1 + data[x2+y1+z6]*tablex2 + data[x3+y1+z6]*tablex3 +
01086 data[x4+y1+z6]*tablex4 + data[x5+y1+z6]*tablex5 + data[x6+y1+z6]*tablex6 +
01087 data[x7+y1+z6]*tablex7 ) * tabley1 +
01088 ( data[x1+y2+z6]*tablex1 + data[x2+y2+z6]*tablex2 + data[x3+y2+z6]*tablex3 +
01089 data[x4+y2+z6]*tablex4 + data[x5+y2+z6]*tablex5 + data[x6+y2+z6]*tablex6 +
01090 data[x7+y2+z6]*tablex7 ) * tabley2 +
01091 ( data[x1+y3+z6]*tablex1 + data[x2+y3+z6]*tablex2 + data[x3+y3+z6]*tablex3 +
01092 data[x4+y3+z6]*tablex4 + data[x5+y3+z6]*tablex5 + data[x6+y3+z6]*tablex6 +
01093 data[x7+y3+z6]*tablex7 ) * tabley3 +
01094 ( data[x1+y4+z6]*tablex1 + data[x2+y4+z6]*tablex2 + data[x3+y4+z6]*tablex3 +
01095 data[x4+y4+z6]*tablex4 + data[x5+y4+z6]*tablex5 + data[x6+y4+z6]*tablex6 +
01096 data[x7+y4+z6]*tablex7 ) * tabley4 +
01097 ( data[x1+y5+z6]*tablex1 + data[x2+y5+z6]*tablex2 + data[x3+y5+z6]*tablex3 +
01098 data[x4+y5+z6]*tablex4 + data[x5+y5+z6]*tablex5 + data[x6+y5+z6]*tablex6 +
01099 data[x7+y5+z6]*tablex7 ) * tabley5 +
01100 ( data[x1+y6+z6]*tablex1 + data[x2+y6+z6]*tablex2 + data[x3+y6+z6]*tablex3 +
01101 data[x4+y6+z6]*tablex4 + data[x5+y6+z6]*tablex5 + data[x6+y6+z6]*tablex6 +
01102 data[x7+y6+z6]*tablex7 ) * tabley6 +
01103 ( data[x1+y7+z6]*tablex1 + data[x2+y7+z6]*tablex2 + data[x3+y7+z6]*tablex3 +
01104 data[x4+y7+z6]*tablex4 + data[x5+y7+z6]*tablex5 + data[x6+y7+z6]*tablex6 +
01105 data[x7+y7+z6]*tablex7 ) * tabley7 ) *tablez6 +
01106 ( ( data[x1+y1+z7]*tablex1 + data[x2+y1+z7]*tablex2 + data[x3+y1+z7]*tablex3 +
01107 data[x4+y1+z7]*tablex4 + data[x5+y1+z7]*tablex5 + data[x6+y1+z7]*tablex6 +
01108 data[x7+y1+z7]*tablex7 ) * tabley1 +
01109 ( data[x1+y2+z7]*tablex1 + data[x2+y2+z7]*tablex2 + data[x3+y2+z7]*tablex3 +
01110 data[x4+y2+z7]*tablex4 + data[x5+y2+z7]*tablex5 + data[x6+y2+z7]*tablex6 +
01111 data[x7+y2+z7]*tablex7 ) * tabley2 +
01112 ( data[x1+y3+z7]*tablex1 + data[x2+y3+z7]*tablex2 + data[x3+y3+z7]*tablex3 +
01113 data[x4+y3+z7]*tablex4 + data[x5+y3+z7]*tablex5 + data[x6+y3+z7]*tablex6 +
01114 data[x7+y3+z7]*tablex7 ) * tabley3 +
01115 ( data[x1+y4+z7]*tablex1 + data[x2+y4+z7]*tablex2 + data[x3+y4+z7]*tablex3 +
01116 data[x4+y4+z7]*tablex4 + data[x5+y4+z7]*tablex5 + data[x6+y4+z7]*tablex6 +
01117 data[x7+y4+z7]*tablex7 ) * tabley4 +
01118 ( data[x1+y5+z7]*tablex1 + data[x2+y5+z7]*tablex2 + data[x3+y5+z7]*tablex3 +
01119 data[x4+y5+z7]*tablex4 + data[x5+y5+z7]*tablex5 + data[x6+y5+z7]*tablex6 +
01120 data[x7+y5+z7]*tablex7 ) * tabley5 +
01121 ( data[x1+y6+z7]*tablex1 + data[x2+y6+z7]*tablex2 + data[x3+y6+z7]*tablex3 +
01122 data[x4+y6+z7]*tablex4 + data[x5+y6+z7]*tablex5 + data[x6+y6+z7]*tablex6 +
01123 data[x7+y6+z7]*tablex7 ) * tabley6 +
01124 ( data[x1+y7+z7]*tablex1 + data[x2+y7+z7]*tablex2 + data[x3+y7+z7]*tablex3 +
01125 data[x4+y7+z7]*tablex4 + data[x5+y7+z7]*tablex5 + data[x6+y7+z7]*tablex6 +
01126 data[x7+y7+z7]*tablex7 ) * tabley7 ) *tablez7;
01127
01128 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) *
01129 (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7) *
01130 (tablez1+tablez2+tablez3+tablez4+tablez5+tablez6+tablez7);
01131 }
01132 return pixel/w;
01133 }
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
Definition at line 1135 of file util_sparx.cpp. References data, EMAN::Util::KaiserBessel::get_window_size(), EMAN::Util::KaiserBessel::i0win_tab(), nx, ny, restrict1(), and round(). 01135 {
01136 int K = kb.get_window_size();
01137 int kbmin = -K/2;
01138 int kbmax = -kbmin;
01139 int kbc = kbmax+1;
01140
01141 float pixel =0.0f;
01142 float w=0.0f;
01143
01144 float argdelx = delx; // adding this for 2D case where the wrap around is not done circulantly using restrict1.
01145 delx = restrict1(delx, nx);
01146 int inxold = int(round(delx));
01147 if ( ny < 2 ) { //1D
01148 float tablex1 = kb.i0win_tab(delx-inxold+3);
01149 float tablex2 = kb.i0win_tab(delx-inxold+2);
01150 float tablex3 = kb.i0win_tab(delx-inxold+1);
01151 float tablex4 = kb.i0win_tab(delx-inxold);
01152 float tablex5 = kb.i0win_tab(delx-inxold-1);
01153 float tablex6 = kb.i0win_tab(delx-inxold-2);
01154 float tablex7 = kb.i0win_tab(delx-inxold-3);
01155
01156 int x1, x2, x3, x4, x5, x6, x7;
01157
01158 if ( inxold <= kbc || inxold >=nx-kbc-2 ) {
01159 x1 = (inxold-3+nx)%nx;
01160 x2 = (inxold-2+nx)%nx;
01161 x3 = (inxold-1+nx)%nx;
01162 x4 = (inxold +nx)%nx;
01163 x5 = (inxold+1+nx)%nx;
01164 x6 = (inxold+2+nx)%nx;
01165 x7 = (inxold+3+nx)%nx;
01166 } else {
01167 x1 = inxold-3;
01168 x2 = inxold-2;
01169 x3 = inxold-1;
01170 x4 = inxold;
01171 x5 = inxold+1;
01172 x6 = inxold+2;
01173 x7 = inxold+3;
01174 }
01175
01176 pixel = data[x1]*tablex1 + data[x2]*tablex2 + data[x3]*tablex3 +
01177 data[x4]*tablex4 + data[x5]*tablex5 + data[x6]*tablex6 +
01178 data[x7]*tablex7 ;
01179
01180 w = tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7;
01181 } else if ( nz < 2 ) { // 2D
01182
01183 delx = argdelx;
01184 // the wrap around is not done circulantly for 2D case; if (argdelx, argdely) is not in the image, then make them (xnew, ynew) which is definitely in the image
01185 if ((delx < 0.0f) || (delx >= (float) (nx)) || (dely < 0.0f) || (dely >= (float) (ny)) ){
01186 delx = (float)xnew*2.0f;
01187 dely = (float)ynew*2.0f;
01188 }
01189
01190 int inxold = int(round(delx));
01191 int inyold = int(round(dely));
01192
01193 float tablex1 = kb.i0win_tab(delx-inxold+3);
01194 float tablex2 = kb.i0win_tab(delx-inxold+2);
01195 float tablex3 = kb.i0win_tab(delx-inxold+1);
01196 float tablex4 = kb.i0win_tab(delx-inxold);
01197 float tablex5 = kb.i0win_tab(delx-inxold-1);
01198 float tablex6 = kb.i0win_tab(delx-inxold-2);
01199 float tablex7 = kb.i0win_tab(delx-inxold-3);
01200
01201 float tabley1 = kb.i0win_tab(dely-inyold+3);
01202 float tabley2 = kb.i0win_tab(dely-inyold+2);
01203 float tabley3 = kb.i0win_tab(dely-inyold+1);
01204 float tabley4 = kb.i0win_tab(dely-inyold);
01205 float tabley5 = kb.i0win_tab(dely-inyold-1);
01206 float tabley6 = kb.i0win_tab(dely-inyold-2);
01207 float tabley7 = kb.i0win_tab(dely-inyold-3);
01208
01209 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7;
01210
01211 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 ) {
01212 x1 = (inxold-3+nx)%nx;
01213 x2 = (inxold-2+nx)%nx;
01214 x3 = (inxold-1+nx)%nx;
01215 x4 = (inxold +nx)%nx;
01216 x5 = (inxold+1+nx)%nx;
01217 x6 = (inxold+2+nx)%nx;
01218 x7 = (inxold+3+nx)%nx;
01219
01220 y1 = ((inyold-3+ny)%ny)*nx;
01221 y2 = ((inyold-2+ny)%ny)*nx;
01222 y3 = ((inyold-1+ny)%ny)*nx;
01223 y4 = ((inyold +ny)%ny)*nx;
01224 y5 = ((inyold+1+ny)%ny)*nx;
01225 y6 = ((inyold+2+ny)%ny)*nx;
01226 y7 = ((inyold+3+ny)%ny)*nx;
01227 } else {
01228 x1 = inxold-3;
01229 x2 = inxold-2;
01230 x3 = inxold-1;
01231 x4 = inxold;
01232 x5 = inxold+1;
01233 x6 = inxold+2;
01234 x7 = inxold+3;
01235
01236 y1 = (inyold-3)*nx;
01237 y2 = (inyold-2)*nx;
01238 y3 = (inyold-1)*nx;
01239 y4 = inyold*nx;
01240 y5 = (inyold+1)*nx;
01241 y6 = (inyold+2)*nx;
01242 y7 = (inyold+3)*nx;
01243 }
01244
01245 pixel = ( data[x1+y1]*tablex1 + data[x2+y1]*tablex2 + data[x3+y1]*tablex3 +
01246 data[x4+y1]*tablex4 + data[x5+y1]*tablex5 + data[x6+y1]*tablex6 +
01247 data[x7+y1]*tablex7 ) * tabley1 +
01248 ( data[x1+y2]*tablex1 + data[x2+y2]*tablex2 + data[x3+y2]*tablex3 +
01249 data[x4+y2]*tablex4 + data[x5+y2]*tablex5 + data[x6+y2]*tablex6 +
01250 data[x7+y2]*tablex7 ) * tabley2 +
01251 ( data[x1+y3]*tablex1 + data[x2+y3]*tablex2 + data[x3+y3]*tablex3 +
01252 data[x4+y3]*tablex4 + data[x5+y3]*tablex5 + data[x6+y3]*tablex6 +
01253 data[x7+y3]*tablex7 ) * tabley3 +
01254 ( data[x1+y4]*tablex1 + data[x2+y4]*tablex2 + data[x3+y4]*tablex3 +
01255 data[x4+y4]*tablex4 + data[x5+y4]*tablex5 + data[x6+y4]*tablex6 +
01256 data[x7+y4]*tablex7 ) * tabley4 +
01257 ( data[x1+y5]*tablex1 + data[x2+y5]*tablex2 + data[x3+y5]*tablex3 +
01258 data[x4+y5]*tablex4 + data[x5+y5]*tablex5 + data[x6+y5]*tablex6 +
01259 data[x7+y5]*tablex7 ) * tabley5 +
01260 ( data[x1+y6]*tablex1 + data[x2+y6]*tablex2 + data[x3+y6]*tablex3 +
01261 data[x4+y6]*tablex4 + data[x5+y6]*tablex5 + data[x6+y6]*tablex6 +
01262 data[x7+y6]*tablex7 ) * tabley6 +
01263 ( data[x1+y7]*tablex1 + data[x2+y7]*tablex2 + data[x3+y7]*tablex3 +
01264 data[x4+y7]*tablex4 + data[x5+y7]*tablex5 + data[x6+y7]*tablex6 +
01265 data[x7+y7]*tablex7 ) * tabley7;
01266
01267 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) *
01268 (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7);
01269 } else { // 3D
01270 dely = restrict1(dely, ny);
01271 int inyold = int(Util::round(dely));
01272 delz = restrict1(delz, nz);
01273 int inzold = int(Util::round(delz));
01274
01275 float tablex1 = kb.i0win_tab(delx-inxold+3);
01276 float tablex2 = kb.i0win_tab(delx-inxold+2);
01277 float tablex3 = kb.i0win_tab(delx-inxold+1);
01278 float tablex4 = kb.i0win_tab(delx-inxold);
01279 float tablex5 = kb.i0win_tab(delx-inxold-1);
01280 float tablex6 = kb.i0win_tab(delx-inxold-2);
01281 float tablex7 = kb.i0win_tab(delx-inxold-3);
01282
01283 float tabley1 = kb.i0win_tab(dely-inyold+3);
01284 float tabley2 = kb.i0win_tab(dely-inyold+2);
01285 float tabley3 = kb.i0win_tab(dely-inyold+1);
01286 float tabley4 = kb.i0win_tab(dely-inyold);
01287 float tabley5 = kb.i0win_tab(dely-inyold-1);
01288 float tabley6 = kb.i0win_tab(dely-inyold-2);
01289 float tabley7 = kb.i0win_tab(dely-inyold-3);
01290
01291 float tablez1 = kb.i0win_tab(delz-inzold+3);
01292 float tablez2 = kb.i0win_tab(delz-inzold+2);
01293 float tablez3 = kb.i0win_tab(delz-inzold+1);
01294 float tablez4 = kb.i0win_tab(delz-inzold);
01295 float tablez5 = kb.i0win_tab(delz-inzold-1);
01296 float tablez6 = kb.i0win_tab(delz-inzold-2);
01297 float tablez7 = kb.i0win_tab(delz-inzold-3);
01298
01299 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7, z1, z2, z3, z4, z5, z6, z7;
01300
01301 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 || inzold <= kbc || inzold >= nz-kbc-2 ) {
01302 x1 = (inxold-3+nx)%nx;
01303 x2 = (inxold-2+nx)%nx;
01304 x3 = (inxold-1+nx)%nx;
01305 x4 = (inxold +nx)%nx;
01306 x5 = (inxold+1+nx)%nx;
01307 x6 = (inxold+2+nx)%nx;
01308 x7 = (inxold+3+nx)%nx;
01309
01310 y1 = ((inyold-3+ny)%ny)*nx;
01311 y2 = ((inyold-2+ny)%ny)*nx;
01312 y3 = ((inyold-1+ny)%ny)*nx;
01313 y4 = ((inyold +ny)%ny)*nx;
01314 y5 = ((inyold+1+ny)%ny)*nx;
01315 y6 = ((inyold+2+ny)%ny)*nx;
01316 y7 = ((inyold+3+ny)%ny)*nx;
01317
01318 z1 = ((inzold-3+nz)%nz)*nx*ny;
01319 z2 = ((inzold-2+nz)%nz)*nx*ny;
01320 z3 = ((inzold-1+nz)%nz)*nx*ny;
01321 z4 = ((inzold +nz)%nz)*nx*ny;
01322 z5 = ((inzold+1+nz)%nz)*nx*ny;
01323 z6 = ((inzold+2+nz)%nz)*nx*ny;
01324 z7 = ((inzold+3+nz)%nz)*nx*ny;
01325 } else {
01326 x1 = inxold-3;
01327 x2 = inxold-2;
01328 x3 = inxold-1;
01329 x4 = inxold;
01330 x5 = inxold+1;
01331 x6 = inxold+2;
01332 x7 = inxold+3;
01333
01334 y1 = (inyold-3)*nx;
01335 y2 = (inyold-2)*nx;
01336 y3 = (inyold-1)*nx;
01337 y4 = inyold*nx;
01338 y5 = (inyold+1)*nx;
01339 y6 = (inyold+2)*nx;
01340 y7 = (inyold+3)*nx;
01341
01342 z1 = (inzold-3)*nx*ny;
01343 z2 = (inzold-2)*nx*ny;
01344 z3 = (inzold-1)*nx*ny;
01345 z4 = inzold*nx*ny;
01346 z5 = (inzold+1)*nx*ny;
01347 z6 = (inzold+2)*nx*ny;
01348 z7 = (inzold+3)*nx*ny;
01349 }
01350
01351 pixel = ( ( data[x1+y1+z1]*tablex1 + data[x2+y1+z1]*tablex2 + data[x3+y1+z1]*tablex3 +
01352 data[x4+y1+z1]*tablex4 + data[x5+y1+z1]*tablex5 + data[x6+y1+z1]*tablex6 +
01353 data[x7+y1+z1]*tablex7 ) * tabley1 +
01354 ( data[x1+y2+z1]*tablex1 + data[x2+y2+z1]*tablex2 + data[x3+y2+z1]*tablex3 +
01355 data[x4+y2+z1]*tablex4 + data[x5+y2+z1]*tablex5 + data[x6+y2+z1]*tablex6 +
01356 data[x7+y2+z1]*tablex7 ) * tabley2 +
01357 ( data[x1+y3+z1]*tablex1 + data[x2+y3+z1]*tablex2 + data[x3+y3+z1]*tablex3 +
01358 data[x4+y3+z1]*tablex4 + data[x5+y3+z1]*tablex5 + data[x6+y3+z1]*tablex6 +
01359 data[x7+y3+z1]*tablex7 ) * tabley3 +
01360 ( data[x1+y4+z1]*tablex1 + data[x2+y4+z1]*tablex2 + data[x3+y4+z1]*tablex3 +
01361 data[x4+y4+z1]*tablex4 + data[x5+y4+z1]*tablex5 + data[x6+y4+z1]*tablex6 +
01362 data[x7+y4+z1]*tablex7 ) * tabley4 +
01363 ( data[x1+y5+z1]*tablex1 + data[x2+y5+z1]*tablex2 + data[x3+y5+z1]*tablex3 +
01364 data[x4+y5+z1]*tablex4 + data[x5+y5+z1]*tablex5 + data[x6+y5+z1]*tablex6 +
01365 data[x7+y5+z1]*tablex7 ) * tabley5 +
01366 ( data[x1+y6+z1]*tablex1 + data[x2+y6+z1]*tablex2 + data[x3+y6+z1]*tablex3 +
01367 data[x4+y6+z1]*tablex4 + data[x5+y6+z1]*tablex5 + data[x6+y6+z1]*tablex6 +
01368 data[x7+y6+z1]*tablex7 ) * tabley6 +
01369 ( data[x1+y7+z1]*tablex1 + data[x2+y7+z1]*tablex2 + data[x3+y7+z1]*tablex3 +
01370 data[x4+y7+z1]*tablex4 + data[x5+y7+z1]*tablex5 + data[x6+y7+z1]*tablex6 +
01371 data[x7+y7+z1]*tablex7 ) * tabley7 ) *tablez1 +
01372 ( ( data[x1+y1+z2]*tablex1 + data[x2+y1+z2]*tablex2 + data[x3+y1+z2]*tablex3 +
01373 data[x4+y1+z2]*tablex4 + data[x5+y1+z2]*tablex5 + data[x6+y1+z2]*tablex6 +
01374 data[x7+y1+z2]*tablex7 ) * tabley1 +
01375 ( data[x1+y2+z2]*tablex1 + data[x2+y2+z2]*tablex2 + data[x3+y2+z2]*tablex3 +
01376 data[x4+y2+z2]*tablex4 + data[x5+y2+z2]*tablex5 + data[x6+y2+z2]*tablex6 +
01377 data[x7+y2+z2]*tablex7 ) * tabley2 +
01378 ( data[x1+y3+z2]*tablex1 + data[x2+y3+z2]*tablex2 + data[x3+y3+z2]*tablex3 +
01379 data[x4+y3+z2]*tablex4 + data[x5+y3+z2]*tablex5 + data[x6+y3+z2]*tablex6 +
01380 data[x7+y3+z2]*tablex7 ) * tabley3 +
01381 ( data[x1+y4+z2]*tablex1 + data[x2+y4+z2]*tablex2 + data[x3+y4+z2]*tablex3 +
01382 data[x4+y4+z2]*tablex4 + data[x5+y4+z2]*tablex5 + data[x6+y4+z2]*tablex6 +
01383 data[x7+y4+z2]*tablex7 ) * tabley4 +
01384 ( data[x1+y5+z2]*tablex1 + data[x2+y5+z2]*tablex2 + data[x3+y5+z2]*tablex3 +
01385 data[x4+y5+z2]*tablex4 + data[x5+y5+z2]*tablex5 + data[x6+y5+z2]*tablex6 +
01386 data[x7+y5+z2]*tablex7 ) * tabley5 +
01387 ( data[x1+y6+z2]*tablex1 + data[x2+y6+z2]*tablex2 + data[x3+y6+z2]*tablex3 +
01388 data[x4+y6+z2]*tablex4 + data[x5+y6+z2]*tablex5 + data[x6+y6+z2]*tablex6 +
01389 data[x7+y6+z2]*tablex7 ) * tabley6 +
01390 ( data[x1+y7+z2]*tablex1 + data[x2+y7+z2]*tablex2 + data[x3+y7+z2]*tablex3 +
01391 data[x4+y7+z2]*tablex4 + data[x5+y7+z2]*tablex5 + data[x6+y7+z2]*tablex6 +
01392 data[x7+y7+z2]*tablex7 ) * tabley7 ) *tablez2 +
01393 ( ( data[x1+y1+z3]*tablex1 + data[x2+y1+z3]*tablex2 + data[x3+y1+z3]*tablex3 +
01394 data[x4+y1+z3]*tablex4 + data[x5+y1+z3]*tablex5 + data[x6+y1+z3]*tablex6 +
01395 data[x7+y1+z3]*tablex7 ) * tabley1 +
01396 ( data[x1+y2+z3]*tablex1 + data[x2+y2+z3]*tablex2 + data[x3+y2+z3]*tablex3 +
01397 data[x4+y2+z3]*tablex4 + data[x5+y2+z3]*tablex5 + data[x6+y2+z3]*tablex6 +
01398 data[x7+y2+z3]*tablex7 ) * tabley2 +
01399 ( data[x1+y3+z3]*tablex1 + data[x2+y3+z3]*tablex2 + data[x3+y3+z3]*tablex3 +
01400 data[x4+y3+z3]*tablex4 + data[x5+y3+z3]*tablex5 + data[x6+y3+z3]*tablex6 +
01401 data[x7+y3+z3]*tablex7 ) * tabley3 +
01402 ( data[x1+y4+z3]*tablex1 + data[x2+y4+z3]*tablex2 + data[x3+y4+z3]*tablex3 +
01403 data[x4+y4+z3]*tablex4 + data[x5+y4+z3]*tablex5 + data[x6+y4+z3]*tablex6 +
01404 data[x7+y4+z3]*tablex7 ) * tabley4 +
01405 ( data[x1+y5+z3]*tablex1 + data[x2+y5+z3]*tablex2 + data[x3+y5+z3]*tablex3 +
01406 data[x4+y5+z3]*tablex4 + data[x5+y5+z3]*tablex5 + data[x6+y5+z3]*tablex6 +
01407 data[x7+y5+z3]*tablex7 ) * tabley5 +
01408 ( data[x1+y6+z3]*tablex1 + data[x2+y6+z3]*tablex2 + data[x3+y6+z3]*tablex3 +
01409 data[x4+y6+z3]*tablex4 + data[x5+y6+z3]*tablex5 + data[x6+y6+z3]*tablex6 +
01410 data[x7+y6+z3]*tablex7 ) * tabley6 +
01411 ( data[x1+y7+z3]*tablex1 + data[x2+y7+z3]*tablex2 + data[x3+y7+z3]*tablex3 +
01412 data[x4+y7+z3]*tablex4 + data[x5+y7+z3]*tablex5 + data[x6+y7+z3]*tablex6 +
01413 data[x7+y7+z3]*tablex7 ) * tabley7 ) *tablez3 +
01414 ( ( data[x1+y1+z4]*tablex1 + data[x2+y1+z4]*tablex2 + data[x3+y1+z4]*tablex3 +
01415 data[x4+y1+z4]*tablex4 + data[x5+y1+z4]*tablex5 + data[x6+y1+z4]*tablex6 +
01416 data[x7+y1+z4]*tablex7 ) * tabley1 +
01417 ( data[x1+y2+z4]*tablex1 + data[x2+y2+z4]*tablex2 + data[x3+y2+z4]*tablex3 +
01418 data[x4+y2+z4]*tablex4 + data[x5+y2+z4]*tablex5 + data[x6+y2+z4]*tablex6 +
01419 data[x7+y2+z4]*tablex7 ) * tabley2 +
01420 ( data[x1+y3+z4]*tablex1 + data[x2+y3+z4]*tablex2 + data[x3+y3+z4]*tablex3 +
01421 data[x4+y3+z4]*tablex4 + data[x5+y3+z4]*tablex5 + data[x6+y3+z4]*tablex6 +
01422 data[x7+y3+z4]*tablex7 ) * tabley3 +
01423 ( data[x1+y4+z4]*tablex1 + data[x2+y4+z4]*tablex2 + data[x3+y4+z4]*tablex3 +
01424 data[x4+y4+z4]*tablex4 + data[x5+y4+z4]*tablex5 + data[x6+y4+z4]*tablex6 +
01425 data[x7+y4+z4]*tablex7 ) * tabley4 +
01426 ( data[x1+y5+z4]*tablex1 + data[x2+y5+z4]*tablex2 + data[x3+y5+z4]*tablex3 +
01427 data[x4+y5+z4]*tablex4 + data[x5+y5+z4]*tablex5 + data[x6+y5+z4]*tablex6 +
01428 data[x7+y5+z4]*tablex7 ) * tabley5 +
01429 ( data[x1+y6+z4]*tablex1 + data[x2+y6+z4]*tablex2 + data[x3+y6+z4]*tablex3 +
01430 data[x4+y6+z4]*tablex4 + data[x5+y6+z4]*tablex5 + data[x6+y6+z4]*tablex6 +
01431 data[x7+y6+z4]*tablex7 ) * tabley6 +
01432 ( data[x1+y7+z4]*tablex1 + data[x2+y7+z4]*tablex2 + data[x3+y7+z4]*tablex3 +
01433 data[x4+y7+z4]*tablex4 + data[x5+y7+z4]*tablex5 + data[x6+y7+z4]*tablex6 +
01434 data[x7+y7+z4]*tablex7 ) * tabley7 ) *tablez4 +
01435 ( ( data[x1+y1+z5]*tablex1 + data[x2+y1+z5]*tablex2 + data[x3+y1+z5]*tablex3 +
01436 data[x4+y1+z5]*tablex4 + data[x5+y1+z5]*tablex5 + data[x6+y1+z5]*tablex6 +
01437 data[x7+y1+z5]*tablex7 ) * tabley1 +
01438 ( data[x1+y2+z5]*tablex1 + data[x2+y2+z5]*tablex2 + data[x3+y2+z5]*tablex3 +
01439 data[x4+y2+z5]*tablex4 + data[x5+y2+z5]*tablex5 + data[x6+y2+z5]*tablex6 +
01440 data[x7+y2+z5]*tablex7 ) * tabley2 +
01441 ( data[x1+y3+z5]*tablex1 + data[x2+y3+z5]*tablex2 + data[x3+y3+z5]*tablex3 +
01442 data[x4+y3+z5]*tablex4 + data[x5+y3+z5]*tablex5 + data[x6+y3+z5]*tablex6 +
01443 data[x7+y3+z5]*tablex7 ) * tabley3 +
01444 ( data[x1+y4+z5]*tablex1 + data[x2+y4+z5]*tablex2 + data[x3+y4+z5]*tablex3 +
01445 data[x4+y4+z5]*tablex4 + data[x5+y4+z5]*tablex5 + data[x6+y4+z5]*tablex6 +
01446 data[x7+y4+z5]*tablex7 ) * tabley4 +
01447 ( data[x1+y5+z5]*tablex1 + data[x2+y5+z5]*tablex2 + data[x3+y5+z5]*tablex3 +
01448 data[x4+y5+z5]*tablex4 + data[x5+y5+z5]*tablex5 + data[x6+y5+z5]*tablex6 +
01449 data[x7+y5+z5]*tablex7 ) * tabley5 +
01450 ( data[x1+y6+z5]*tablex1 + data[x2+y6+z5]*tablex2 + data[x3+y6+z5]*tablex3 +
01451 data[x4+y6+z5]*tablex4 + data[x5+y6+z5]*tablex5 + data[x6+y6+z5]*tablex6 +
01452 data[x7+y6+z5]*tablex7 ) * tabley6 +
01453 ( data[x1+y7+z5]*tablex1 + data[x2+y7+z5]*tablex2 + data[x3+y7+z5]*tablex3 +
01454 data[x4+y7+z5]*tablex4 + data[x5+y7+z5]*tablex5 + data[x6+y7+z5]*tablex6 +
01455 data[x7+y7+z5]*tablex7 ) * tabley7 ) *tablez5 +
01456 ( ( data[x1+y1+z6]*tablex1 + data[x2+y1+z6]*tablex2 + data[x3+y1+z6]*tablex3 +
01457 data[x4+y1+z6]*tablex4 + data[x5+y1+z6]*tablex5 + data[x6+y1+z6]*tablex6 +
01458 data[x7+y1+z6]*tablex7 ) * tabley1 +
01459 ( data[x1+y2+z6]*tablex1 + data[x2+y2+z6]*tablex2 + data[x3+y2+z6]*tablex3 +
01460 data[x4+y2+z6]*tablex4 + data[x5+y2+z6]*tablex5 + data[x6+y2+z6]*tablex6 +
01461 data[x7+y2+z6]*tablex7 ) * tabley2 +
01462 ( data[x1+y3+z6]*tablex1 + data[x2+y3+z6]*tablex2 + data[x3+y3+z6]*tablex3 +
01463 data[x4+y3+z6]*tablex4 + data[x5+y3+z6]*tablex5 + data[x6+y3+z6]*tablex6 +
01464 data[x7+y3+z6]*tablex7 ) * tabley3 +
01465 ( data[x1+y4+z6]*tablex1 + data[x2+y4+z6]*tablex2 + data[x3+y4+z6]*tablex3 +
01466 data[x4+y4+z6]*tablex4 + data[x5+y4+z6]*tablex5 + data[x6+y4+z6]*tablex6 +
01467 data[x7+y4+z6]*tablex7 ) * tabley4 +
01468 ( data[x1+y5+z6]*tablex1 + data[x2+y5+z6]*tablex2 + data[x3+y5+z6]*tablex3 +
01469 data[x4+y5+z6]*tablex4 + data[x5+y5+z6]*tablex5 + data[x6+y5+z6]*tablex6 +
01470 data[x7+y5+z6]*tablex7 ) * tabley5 +
01471 ( data[x1+y6+z6]*tablex1 + data[x2+y6+z6]*tablex2 + data[x3+y6+z6]*tablex3 +
01472 data[x4+y6+z6]*tablex4 + data[x5+y6+z6]*tablex5 + data[x6+y6+z6]*tablex6 +
01473 data[x7+y6+z6]*tablex7 ) * tabley6 +
01474 ( data[x1+y7+z6]*tablex1 + data[x2+y7+z6]*tablex2 + data[x3+y7+z6]*tablex3 +
01475 data[x4+y7+z6]*tablex4 + data[x5+y7+z6]*tablex5 + data[x6+y7+z6]*tablex6 +
01476 data[x7+y7+z6]*tablex7 ) * tabley7 ) *tablez6 +
01477 ( ( data[x1+y1+z7]*tablex1 + data[x2+y1+z7]*tablex2 + data[x3+y1+z7]*tablex3 +
01478 data[x4+y1+z7]*tablex4 + data[x5+y1+z7]*tablex5 + data[x6+y1+z7]*tablex6 +
01479 data[x7+y1+z7]*tablex7 ) * tabley1 +
01480 ( data[x1+y2+z7]*tablex1 + data[x2+y2+z7]*tablex2 + data[x3+y2+z7]*tablex3 +
01481 data[x4+y2+z7]*tablex4 + data[x5+y2+z7]*tablex5 + data[x6+y2+z7]*tablex6 +
01482 data[x7+y2+z7]*tablex7 ) * tabley2 +
01483 ( data[x1+y3+z7]*tablex1 + data[x2+y3+z7]*tablex2 + data[x3+y3+z7]*tablex3 +
01484 data[x4+y3+z7]*tablex4 + data[x5+y3+z7]*tablex5 + data[x6+y3+z7]*tablex6 +
01485 data[x7+y3+z7]*tablex7 ) * tabley3 +
01486 ( data[x1+y4+z7]*tablex1 + data[x2+y4+z7]*tablex2 + data[x3+y4+z7]*tablex3 +
01487 data[x4+y4+z7]*tablex4 + data[x5+y4+z7]*tablex5 + data[x6+y4+z7]*tablex6 +
01488 data[x7+y4+z7]*tablex7 ) * tabley4 +
01489 ( data[x1+y5+z7]*tablex1 + data[x2+y5+z7]*tablex2 + data[x3+y5+z7]*tablex3 +
01490 data[x4+y5+z7]*tablex4 + data[x5+y5+z7]*tablex5 + data[x6+y5+z7]*tablex6 +
01491 data[x7+y5+z7]*tablex7 ) * tabley5 +
01492 ( data[x1+y6+z7]*tablex1 + data[x2+y6+z7]*tablex2 + data[x3+y6+z7]*tablex3 +
01493 data[x4+y6+z7]*tablex4 + data[x5+y6+z7]*tablex5 + data[x6+y6+z7]*tablex6 +
01494 data[x7+y6+z7]*tablex7 ) * tabley6 +
01495 ( data[x1+y7+z7]*tablex1 + data[x2+y7+z7]*tablex2 + data[x3+y7+z7]*tablex3 +
01496 data[x4+y7+z7]*tablex4 + data[x5+y7+z7]*tablex5 + data[x6+y7+z7]*tablex6 +
01497 data[x7+y7+z7]*tablex7 ) * tabley7 ) *tablez7;
01498
01499 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) *
01500 (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7) *
01501 (tablez1+tablez2+tablez3+tablez4+tablez5+tablez6+tablez7);
01502 }
01503 return pixel/w;
01504 }
|
|
|
Get the seed for Randnum class.
Definition at line 684 of file util.cpp. References EMAN::Randnum::get_seed().
|
|
||||||||||||||||
|
This function returns a 2-D slice from a 3-D EMData object dim denotes the slice is perpendicular to which dimension 1 for x-dimension, 2 for y-dimension and 3 for z-dimension.
Definition at line 20587 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, nx, ny, EMAN::EMData::set_size(), x, and y. 20587 {
20588
20589 int nx = vol->get_xsize();
20590 int ny = vol->get_ysize();
20591 int nz = vol->get_zsize();
20592 float *vol_data = vol->get_data();
20593 int new_nx, new_ny;
20594
20595 if (nz == 1)
20596 throw ImageDimensionException("Error: Input must be a 3-D object");
20597 if ((dim < 1) || (dim > 3))
20598 throw ImageDimensionException("Error: dim must be 1 (x-dimension), 2 (y-dimension) or 3 (z-dimension)");
20599 if (((dim == 1) && (index < 0 || index > nx-1)) ||
20600 ((dim == 1) && (index < 0 || index > nx-1)) ||
20601 ((dim == 1) && (index < 0 || index > nx-1)))
20602 throw ImageDimensionException("Error: index exceeds the size of the 3-D object");
20603
20604 if (dim == 1) {
20605 new_nx = ny;
20606 new_ny = nz;
20607 } else if (dim == 2) {
20608 new_nx = nx;
20609 new_ny = nz;
20610 } else {
20611 new_nx = nx;
20612 new_ny = ny;
20613 }
20614
20615 EMData *slice = new EMData();
20616 slice->set_size(new_nx, new_ny, 1);
20617 float *slice_data = slice->get_data();
20618
20619 if (dim == 1) {
20620 for (int x=0; x<new_nx; x++)
20621 for (int y=0; y<new_ny; y++)
20622 slice_data[y*new_nx+x] = vol_data[(y*ny+x)*nx+index];
20623 } else if (dim == 2) {
20624 for (int x=0; x<new_nx; x++)
20625 for (int y=0; y<new_ny; y++)
20626 slice_data[y*new_nx+x] = vol_data[(y*ny+index)*nx+x];
20627 } else {
20628 for (int x=0; x<new_nx; x++)
20629 for (int y=0; y<new_ny; y++)
20630 slice_data[y*new_nx+x] = vol_data[((size_t)index*ny+y)*nx+x];
20631 }
20632
20633 return slice;
20634 }
|
|
|
Get the mean, standard deviation, skewness and kurtosis of the input data.
Definition at line 876 of file util.cpp. References data, EmptyContainerException, mean(), sqrt(), and square_sum(). 00877 {
00878 // Note that this is a heavy STL approach using generic algorithms - some memory could be saved
00879 // using plain c style code, as in get_stats_cstyle below
00880
00881 if (data.size() == 0) EmptyContainerException("Error, attempting to call get stats on an empty container (vector<double>)");
00882
00883 double sum = accumulate(data.begin(), data.end(), 0.0);
00884
00885 double mean = sum / static_cast<double> (data.size());
00886
00887 double std_dev = 0.0, skewness = 0.0, kurtosis = 0.0;
00888
00889 if (data.size() > 1)
00890 {
00891 // read mm is "minus_mean"
00892 vector<double> data_mm(data.size());
00893 // read ts as "then squared"
00894 vector<double> data_mm_sq(data.size());
00895
00896 // Subtract the mean from the data and store it in data_mm
00897 transform(data.begin(), data.end(), data_mm.begin(), std::bind2nd(std::minus<double>(), mean));
00898
00899 // Get the square of the data minus the mean and store it in data_mm_sq
00900 transform(data_mm.begin(), data_mm.end(), data_mm.begin(), data_mm_sq.begin(), std::multiplies<double>());
00901
00902 // Get the sum of the squares for the calculation of the standard deviation
00903 double square_sum = accumulate(data_mm_sq.begin(), data_mm_sq.end(), 0.0);
00904
00905 //Calculate teh standard deviation
00906 std_dev = sqrt(square_sum / static_cast<double>(data.size()-1));
00907 double std_dev_sq = std_dev * std_dev;
00908
00909 // The numerator for the skewness fraction, as defined in http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm
00910 double cubic_sum = inner_product(data_mm.begin(), data_mm.end(),data_mm_sq.begin(), 0.0);
00911
00912 // The numerator for the kurtosis fraction, as defined in http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm
00913 double quartic_sum = inner_product(data_mm_sq.begin(), data_mm_sq.end(),data_mm_sq.begin(), 0.0);
00914
00915 // Finalize the calculation of the skewness and kurtosis, as defined in
00916 // http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm
00917 skewness = cubic_sum / ((data.size()-1) * std_dev_sq * std_dev );
00918 kurtosis = quartic_sum / ((data.size()-1) * std_dev_sq * std_dev_sq );
00919
00920 }
00921
00922 Dict parms;
00923 parms["mean"] = mean;
00924 parms["std_dev"] = std_dev;
00925 parms["skewness"] = skewness;
00926 parms["kurtosis"] = kurtosis;
00927
00928 return parms;
00929 }
|
|
|
Performs the same calculations as in get_stats, but uses a single pass, optimized c approach Should perform better than get_stats.
Definition at line 932 of file util.cpp. References data, EmptyContainerException, mean(), sqrt(), square, square(), and square_sum(). 00933 {
00934 if (data.size() == 0) EmptyContainerException("Error, attempting to call get stats on an empty container (vector<double>)");
00935
00936 double square_sum = 0.0, sum = 0.0, cube_sum = 0.0, quart_sum = 0.0;
00937 for( vector<float>::const_iterator it = data.begin(); it != data.end(); ++it )
00938 {
00939 double val = *it;
00940 double square = val*val;
00941 quart_sum += square*square;
00942 cube_sum += square*val;
00943 square_sum += square;
00944 sum += val;
00945 }
00946
00947 double mean = sum/(double)data.size();
00948
00949 double std_dev = 0.0, skewness = 0.0, kurtosis = 0.0;
00950
00951 if (data.size() > 1)
00952 {
00953 // The standard deviation is calculated here
00954 std_dev = sqrt( (square_sum - mean*sum)/(double)(data.size()-1));
00955
00956 double square_mean = mean*mean;
00957 double cube_mean = mean*square_mean;
00958
00959 double square_std_dev = std_dev*std_dev;
00960
00961 // This is the numerator of the skewness fraction, if you expand the brackets, as defined in
00962 // http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm
00963 double cubic_sum = cube_sum - 3*square_sum*mean + 3*sum*square_mean - cube_mean*data.size();
00964 // Complete the skewness fraction
00965 skewness = cubic_sum/((data.size()-1)*square_std_dev*std_dev);
00966
00967 // This is the numerator of the kurtosis fraction, if you expand the brackets, as defined in
00968 // http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm
00969 double quartic_sum = quart_sum - 4*cube_sum*mean + 6*square_sum*square_mean - 4*sum*cube_mean + square_mean*square_mean*data.size();
00970 // Complete the kurtosis fraction
00971 kurtosis = quartic_sum /( (data.size()-1)*square_std_dev*square_std_dev);
00972 }
00973
00974 Dict parms;
00975 parms["mean"] = mean;
00976 parms["std_dev"] = std_dev;
00977 parms["skewness"] = skewness;
00978 parms["kurtosis"] = kurtosis;
00979
00980 return parms;
00981 }
|
|
||||||||||||||||||||||||
|
Extract number of values and the float values, if any, from a string whose format is either "variable=value1,value2 " or "variable". for example, if the string is "XYZ=1.1,1.2", then 'str' is "XYZ=1.1,1.2"; 'float_var' is "XYZ"; 'p_nvalues' points to 2. 'p_v1' points to 1.1; 'p_v2' points to 1.2. If the string is "XYZ", then 'str' is "XYZ"; 'float_var' is "XYZ". 'p_nvalues' points to 0. 'p_v1' and 'p_v2' unchanged.
Definition at line 359 of file util.cpp. References NullPointerException. 00361 {
00362 if (!s || !float_var || !p_v0 || !p_v1 || !p_v2) {
00363 throw NullPointerException("string float");
00364 }
00365
00366 size_t n = strlen(float_var);
00367 *p_v0 = 0;
00368 if (strncmp(s, float_var, n) == 0) {
00369 if (s[n] == '=') {
00370 *p_v0 = 2;
00371 sscanf(&s[n + 1], "%f,%f", p_v1, p_v2);
00372 }
00373 else {
00374 *p_v0 = 1;
00375 }
00376 return true;
00377 }
00378 return false;
00379 }
|
|
||||||||||||||||||||
|
Extract the float values from a variable=value1,value2 string with format like "XYZ=1.1,1.2", where 'str' is "XYZ=1.1,1.2"; 'float_var' is "XYZ="; 'p_v1' points to 1.1; 'p_v2' points to 1.2.
Definition at line 344 of file util.cpp. References NullPointerException. 00345 {
00346 if (!s || !float_var || !p_v1 || !p_v2) {
00347 throw NullPointerException("string float");
00348 }
00349
00350 size_t n = strlen(float_var);
00351 if (strncmp(s, float_var, n) == 0) {
00352 sscanf(&s[n], "%f,%f", p_v1, p_v2);
00353 return true;
00354 }
00355
00356 return false;
00357 }
|
|
||||||||||||||||
|
Extract the float value from a variable=value string with format like "XYZ=1.1", where 'str' is "XYZ=1.1"; 'float_var' is "XYZ="; 'p_val' points to float number 1.1.
Definition at line 330 of file util.cpp. References NullPointerException. Referenced by main(). 00331 {
00332 if (!s || !float_var || !p_val) {
00333 throw NullPointerException("string float");
00334 }
00335 size_t n = strlen(float_var);
00336 if (strncmp(s, float_var, n) == 0) {
00337 *p_val = (float) atof(&s[n]);
00338 return true;
00339 }
00340
00341 return false;
00342 }
|
|
||||||||||||||||||||||||
|
Extract number of values and the int values, if any, from a string whose format is either "variable=value1,value2 " or "variable". for example, if the string is "XYZ=1,2", then 'str' is "XYZ=1,2"; 'int_var' is "XYZ"; 'p_nvalues' points to 2. 'p_v1' points to 1; 'p_v2' points to 2. If the string is "XYZ", then 'str' is "XYZ"; 'int_var' is "XYZ". 'p_nvalues' points to 0. 'p_v1' and 'p_v2' unchanged.
Definition at line 409 of file util.cpp. References NullPointerException. 00410 {
00411 if (!s || !int_var || !p_v0 || !p_v1 || !p_v2) {
00412 throw NullPointerException("string int");
00413 }
00414
00415 size_t n = strlen(int_var);
00416 *p_v0 = 0;
00417 if (strncmp(s, int_var, n) == 0) {
00418 if (s[n] == '=') {
00419 *p_v0 = 2;
00420 sscanf(&s[n + 1], "%d,%d", p_v1, p_v2);
00421 }
00422 else {
00423 *p_v0 = 1;
00424 }
00425 return true;
00426 }
00427 return false;
00428 }
|
|
||||||||||||||||||||
|
Extract the int value from a variable=value1,value2 string with format like "XYZ=1,2", where 'str' is "XYZ=1,2"; 'int_var' is "XYZ="; 'p_val' points to float number 1.
Definition at line 395 of file util.cpp. References NullPointerException. 00396 {
00397 if (!s || !int_var || !p_v1 || !p_v2) {
00398 throw NullPointerException("string int");
00399 }
00400
00401 size_t n = strlen(int_var);
00402 if (strncmp(s, int_var, n) == 0) {
00403 sscanf(&s[n], "%d,%d", p_v1, p_v2);
00404 return true;
00405 }
00406 return false;
00407 }
|
|
||||||||||||||||
|
Extract the int value from a variable=value string with format like "XYZ=1", where 'str' is "XYZ=1"; 'int_var' is "XYZ="; 'p_val' points to float number 1.
Definition at line 381 of file util.cpp. References NullPointerException. Referenced by main(). 00382 {
00383 if (!s || !int_var || !p_val) {
00384 throw NullPointerException("string int");
00385 }
00386
00387 size_t n = strlen(int_var);
00388 if (strncmp(s, int_var, n) == 0) {
00389 *p_val = atoi(&s[n]);
00390 return true;
00391 }
00392 return false;
00393 }
|
|
|
Get the current time in a string with format "mm/dd/yyyy hh:mm".
Definition at line 1097 of file util.cpp. References t. 01098 {
01099 time_t t0 = time(0);
01100 struct tm *t = localtime(&t0);
01101 char label[32];
01102 sprintf(label, "%d/%02d/%04d %d:%02d",
01103 t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour, t->tm_min);
01104 return string(label);
01105 }
|
|
||||||||||||||||||||||||||||
|
Definition at line 1162 of file util.cpp. References abs, printmatrix(), printvector(), q, rhs, V, and W. Referenced by EMAN::FourierInserter3DMode8::init(). 01163 {
01164 int i = 0;
01165 int discs = (int)(1+2*freq_cutoff/dfreq);
01166
01167 float* W = new float[discs];
01168
01169 int fc = (int)(2*freq_cutoff + 1);
01170 gsl_matrix* M = gsl_matrix_calloc(fc,fc);
01171
01172 gsl_vector* rhs = gsl_vector_calloc(fc);
01173 cout << i++ << endl;
01174 for(int k = -freq_cutoff; k <= freq_cutoff; ++k){
01175 for(int kp = -freq_cutoff; kp <= freq_cutoff; ++kp){
01176 int kdiff =abs( k-kp);
01177 int evenoddfac = ( kdiff % 2 == 0 ? 1 : -1);
01178
01179 if (kdiff !=0){
01180 float val = sin(M_PI*(float)kdiff*r)/(sin(M_PI*(float)kdiff/(float)P))*(alpha+2.0f*beta*evenoddfac);
01181 gsl_matrix_set(M,int(k+freq_cutoff),int(kp+freq_cutoff),val);
01182 }
01183 }
01184 gsl_matrix_set(M,int(k+freq_cutoff),int(k+freq_cutoff),r*P* (alpha+2*beta));
01185 float val = alpha*sin(M_PI*k*r)/(sin(M_PI*(float)k/(float)P));
01186 if (k!=0) {
01187 gsl_vector_set(rhs,int(k+freq_cutoff),val);
01188 }
01189 }
01190 printmatrix(M,fc,fc,"M");
01191
01192 gsl_vector_set(rhs,int(freq_cutoff),alpha*r*P);
01193 gsl_matrix* V = gsl_matrix_calloc(fc,fc);
01194 gsl_vector* S = gsl_vector_calloc(fc);
01195 gsl_vector* soln = gsl_vector_calloc(fc);
01196 gsl_linalg_SV_decomp(M,V,S,soln);
01197
01198 gsl_linalg_SV_solve(M, V, S, rhs, soln); // soln now runs from -freq_cutoff to + freq_cutoff
01199 printvector(soln,fc,"soln");
01200
01201 // we want to solve for W, which ranges from -freq_cutoff to +freq_cutoff in steps of dfreq 2
01202 int Count=0;
01203 for(float q = (float)(-freq_cutoff); q <= (float)(freq_cutoff); q+= dfreq){
01204 float temp=0;
01205 for(int k = -freq_cutoff; k <= freq_cutoff; ++k){
01206 float dtemp;
01207 if (q!=k) {
01208 dtemp=(1/(float) P)* (float)gsl_vector_get(soln,int(k+freq_cutoff)) * sin(M_PI*(q-k))/sin(M_PI*(q-k)/((float) P));
01209 } else{
01210 dtemp = (1/(float) P)* (float)gsl_vector_get(soln,int(k+freq_cutoff)) * P;
01211 }
01212 temp +=dtemp;
01213 }
01214 W[Count]=temp;
01215 cout << W[Count] << " ";
01216 Count+=1;
01217 }
01218 cout << endl;
01219 return W;
01220 }
|
|
|
|
|
|
Check whether a number is a good float. A number is a good float if it is not abnormal zero, and not inf, -inf or NaN
Definition at line 1904 of file util.h. Referenced by EMAN::FRCCmp::cmp(), EMAN::SqEuclideanCmp::cmp(), EMAN::EMObject::EMObject(), EMAN::ByteOrder::is_float_big_endian(), main(), EMAN::NormalizeProcessor::process_inplace(), and EMAN::FiniteProcessor::process_pixel(). |
|
||||||||||||||||||||||||||||||||||||||||
|
Definition at line 5688 of file util_sparx.cpp. References EMAN::EMData::get_data(), and img_ptr. 05689 {
05690 float *img_ptr = img->get_data();
05691 float *mask_ptr = (mask == NULL)?img->get_data():mask->get_data();
05692
05693 int *img_freq_bin = new int[3*hist_len];
05694 for(int i = 0;i < (3*hist_len);i++) img_freq_bin[i] = 0;
05695 for(size_t i = 0;i < size_img;++i) {
05696 if(mask_ptr[i] > 0.5f) {
05697 float img_xn = img_ptr[i]*PA + PB;
05698 int L = static_cast<int>(((img_xn - ref_h_min)/ref_h_diff) * (hist_len-1) + hist_len+1);
05699 if(L >= 0 && L < (3*hist_len)) img_freq_bin[L]++;
05700 }
05701 }
05702 int freq_hist = 0;
05703
05704 for(int i = 0;i < (3*hist_len);i++) freq_hist += (int)pow((float)((int)ref_freq_hist[i] - (int)img_freq_bin[i]),2.f);
05705 freq_hist = (-freq_hist);
05706 return static_cast<float>(freq_hist);
05707 }
|
|
||||||||||||||||
|
Definition at line 5596 of file util_sparx.cpp. References B, data, EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, ImageFormatException, infomask(), EMAN::EMData::is_complex(), and min. 05597 {
05598 /* Exception Handle */
05599 if (img->is_complex() || ref->is_complex())
05600 throw ImageFormatException("Cannot do Histogram on Fourier Image");
05601
05602 if(mask != NULL){
05603 if(img->get_xsize() != mask->get_xsize() || img->get_ysize() != mask->get_ysize() || img->get_zsize() != mask->get_zsize())
05604 throw ImageDimensionException("The size of mask image should be of same size as the input image"); }
05605 /* ===================================================== */
05606
05607 /* Image size calculation */
05608 size_t size_ref = ((size_t)(ref->get_xsize())*(ref->get_ysize())*(ref->get_zsize()));
05609 size_t size_img = ((size_t)(img->get_xsize())*(img->get_ysize())*(img->get_zsize()));
05610 /* ===================================================== */
05611
05612 /* The reference image attributes */
05613 float *ref_ptr = ref->get_data();
05614 float ref_h_min = ref->get_attr("minimum");
05615 float ref_h_max = ref->get_attr("maximum");
05616 float ref_h_avg = ref->get_attr("mean");
05617 float ref_h_sig = ref->get_attr("sigma");
05618 /* ===================================================== */
05619
05620 /* Input image under mask attributes */
05621 float *mask_ptr = (mask == NULL)?img->get_data():mask->get_data();
05622
05623 vector<float> img_data = Util::infomask(img, mask);
05624 float img_avg = img_data[0];
05625 float img_sig = img_data[1];
05626
05627 /* The image under mask -- size calculation */
05628 int cnt=0;
05629 for(size_t i=0;i<size_img;++i)
05630 if (mask_ptr[i]>0.5f)
05631 cnt++;
05632 /* ===================================================== */
05633
05634 /* Histogram of reference image calculation */
05635 float ref_h_diff = ref_h_max - ref_h_min;
05636
05637 #ifdef _WIN32
05638 int hist_len = _cpp_min((unsigned long)size_ref/16,_cpp_min((unsigned long)size_img/16,256lu));
05639 #else
05640 int hist_len = std::min((unsigned long)size_ref/16,std::min((unsigned long)size_img/16,256lu));
05641 #endif //_WIN32
05642
05643 float *ref_freq_bin = new float[3*hist_len];
05644
05645 //initialize value in each bin to zero
05646 for (int i = 0;i < (3*hist_len);i++) ref_freq_bin[i] = 0.f;
05647
05648 for (size_t i = 0;i < size_ref;++i) {
05649 int L = static_cast<int>(((ref_ptr[i] - ref_h_min)/ref_h_diff) * (hist_len-1) + hist_len+1);
05650 ref_freq_bin[L]++;
05651 }
05652 for (int i = 0;i < (3*hist_len);i++) ref_freq_bin[i] *= static_cast<float>(cnt)/static_cast<float>(size_ref);
05653
05654 //Parameters Calculation (i.e) 'A' x + 'B'
05655 float A = ref_h_sig/img_sig;
05656 float B = ref_h_avg - (A*img_avg);
05657
05658 vector<float> args;
05659 args.push_back(A);
05660 args.push_back(B);
05661
05662 vector<float> scale;
05663 scale.push_back(1.e-7f*A);
05664 scale.push_back(-1.e-7f*B);
05665
05666 vector<float> ref_freq_hist;
05667 for(int i = 0;i < (3*hist_len);i++) ref_freq_hist.push_back((int)ref_freq_bin[i]);
05668
05669 vector<float> data;
05670 data.push_back(ref_h_diff);
05671 data.push_back(ref_h_min);
05672
05673 Dict parameter;
05674
05675 /* Parameters displaying the arguments A & B, and the scaling function and the data's */
05676 parameter["args"] = args;
05677 parameter["scale"]= scale;
05678 parameter["data"] = data;
05679 parameter["ref_freq_bin"] = ref_freq_hist;
05680 parameter["size_img"]=(double)size_img;
05681 parameter["hist_len"]=hist_len;
05682 /* ===================================================== */
05683
05684 return parameter;
05685 }
|
|
||||||||||||||||||||||||
|
Definition at line 5538 of file util_sparx.cpp. References EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, ImageFormatException, EMAN::EMData::is_complex(), nx, and ny. 05539 {
05540 if (image->is_complex())
05541 throw ImageFormatException("Cannot do histogram on Fourier image");
05542 //float hmax, hmin;
05543 float *imageptr=0, *maskptr=0;
05544 int nx=image->get_xsize();
05545 int ny=image->get_ysize();
05546 int nz=image->get_zsize();
05547
05548 if(mask != NULL){
05549 if(nx != mask->get_xsize() || ny != mask->get_ysize() || nz != mask->get_zsize())
05550 throw ImageDimensionException("The size of mask image should be of same size as the input image");
05551 maskptr =mask->get_data();
05552 }
05553 if( nbins == 0) nbins = nx;
05554 vector <float> freq(2*nbins, 0.0);
05555
05556 imageptr=image->get_data();
05557 if( hmin == hmax ) {
05558 if(mask == NULL) {
05559 hmax = image->get_attr("maximum");
05560 hmin = image->get_attr("minimum");
05561 } else {
05562 bool First = true;
05563 for (size_t i = 0;i < (size_t)nx*ny*nz; i++) {
05564 if (maskptr[i]>=0.5f) {
05565 if(First) {
05566 hmax = imageptr[i];
05567 hmin = imageptr[i];
05568 First = false;
05569 } else {
05570 hmax = (hmax < imageptr[i])?imageptr[i]:hmax;
05571 hmin = (hmin > imageptr[i])?imageptr[i]:hmin;
05572 }
05573 }
05574 }
05575 }
05576 }
05577 float hdiff = hmax - hmin;
05578 float ff = (nbins-1)/hdiff;
05579 for (int i = 0; i < nbins; i++) freq[nbins+i] = hmin + (float(i)+0.5f)/ff;
05580 if(mask == NULL) {
05581 for(size_t i = 0; i < (size_t)nx*ny*nz; i++) {
05582 int jbin = static_cast<int>((imageptr[i]-hmin)*ff + 1.5);
05583 if(jbin >= 1 && jbin <= nbins) freq[jbin-1] += 1.0;
05584 }
05585 } else {
05586 for(size_t i = 0; i < (size_t)nx*ny*nz; i++) {
05587 if(maskptr[i] >= 0.5) {
05588 int jbin = static_cast<int>((imageptr[i]-hmin)*ff + 1.5);
05589 if(jbin >= 1 && jbin <= nbins) freq[jbin-1] += 1.0;
05590 }
05591 }
05592 }
05593 return freq;
05594 }
|
|
||||||||||||||||||||||||
|
Definition at line 7248 of file util_sparx.cpp. References key, phi, and theta. 07249 {
07250 ENTERFUNC;
07251 vector<tmpstruct> tmp(len);
07252 int i;
07253 for(i = 1;i<=len;i++)
07254 {
07255 tmp[i-1].theta1 = theta(i);
07256 tmp[i-1].phi1 = phi(i);
07257 tmp[i-1].key1 = key(i);
07258 }
07259
07260 if (option == 1) sort(tmp.begin(),tmp.end(),Util::cmp1);
07261 if (option == 2) sort(tmp.begin(),tmp.end(),Util::cmp2);
07262
07263 for(i = 1;i<=len;i++)
07264 {
07265 theta(i) = tmp[i-1].theta1;
07266 phi(i) = tmp[i-1].phi1;
07267 key(i) = tmp[i-1].key1;
07268 }
07269 EXITFUNC;
07270 }
|
|
||||||||||||
|
Euclidean distance function in 2D: f(x,y) = sqrt(x*x + y*y);.
|
|
||||||||||||||||
|
Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);.
|
|
||||||||||||||||
|
Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);.
|
|
||||||||||||||||
|
Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);.
Definition at line 1645 of file util.h. Referenced by EMAN::PhaseCmp::cmp(), EMAN::Interp::init_gimx(), EMAN::FourierInserter3DMode5::insert_pixel(), EMAN::FourierInserter3DMode3::insert_pixel(), EMAN::KmeansSegmentProcessor::process(), EMAN::DistanceSegmentProcessor::process(), EMAN::TestImageSphericalWave::process_inplace(), EMAN::AddRandomNoiseProcessor::process_inplace(), and EMAN::RotationalAverageProcessor::process_inplace(). |
|
||||||||||||||||
|
Euclidean distance function squared in 3D: f(x,y,z) = (x*x + y*y + z*z);.
|
|
||||||||||||||||
|
Euclidean distance function squared in 3D: f(x,y,z) = (x*x + y*y + z*z);.
Definition at line 1623 of file util.h. Referenced by EMAN::FourierInserter3DMode6::insert_pixel(), EMAN::FourierInserter3DMode5::insert_pixel(), EMAN::FourierInserter3DMode3::insert_pixel(), EMAN::FourierInserter3DMode2::insert_pixel(), EMAN::GaussFFTProjector::interp_ft_3d(), EMAN::WienerFourierReconstructor::pixel_at(), and EMAN::FourierReconstructor::pixel_at(). |
|
||||||||||||
|
Euclidean distance in 2D for integers computed fast using a cached lookup table.
Definition at line 713 of file util.cpp. Referenced by EMAN::EMAN2Ctf::compute_2d_complex(). 00714 {
00715 static float *mem = (float *)malloc(4*128*128);
00716 static int dim = 0;
00717 x=abs(x);
00718 y=abs(y);
00719
00720 if (x>=dim || y>=dim) {
00721 if (x>2048 || y>2048) return (float)hypot((float)x,(float)y); // We won't cache anything bigger than 4096^2
00722 dim=x>=dim?x+1:dim;
00723 dim=y>=dim?y+1:dim;
00724 mem=(float*)realloc(mem,4*dim*dim);
00725 for (int y=0; y<dim; y++) {
00726 for (int x=0; x<dim; x++) {
00727 #ifdef _WIN32
00728 mem[x+y*dim]=(float)_hypot((float)x,(float)y);
00729 #else
00730 mem[x+y*dim]=hypot((float)x,(float)y);
00731 #endif
00732 }
00733 }
00734 }
00735
00736 return mem[x+y*dim];
00737 }
|
|
||||||||||||
|
Euclidean distance in 2D for integers computed fast using a cached lookup table.
Definition at line 739 of file util.cpp. Referenced by EMAN::PhaseCmp::cmp(). 00740 {
00741 static short *mem = (short *)malloc(2*128*128);
00742 static int dim = 0;
00743 x=abs(x);
00744 y=abs(y);
00745
00746 if (x>=dim || y>=dim) {
00747 if (x>4095 || y>4095) return (short)hypot((float)x,(float)y); // We won't cache anything bigger than 4096^2
00748 dim=x>=dim?x+1:dim;
00749 dim=y>=dim?y+1:dim;
00750 mem=(short*)realloc(mem,2*dim*dim);
00751 for (int y=0; y<dim; y++) {
00752 for (int x=0; x<dim; x++) {
00753 #ifdef _WIN32
00754 mem[x+y*dim]=(short)Util::round(_hypot((float)x,(float)y));
00755 #else
00756 mem[x+y*dim]=(short)Util::round(hypot((float)x,(float)y));
00757 #endif
00758 }
00759 }
00760 }
00761
00762 return mem[x+y*dim];
00763 }
|
|
||||||||||||||||
|
Definition at line 143 of file util_sparx.cpp. References B, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageFormatException, LOGERR, nx, ny, EMAN::EMData::set_size(), EMAN::EMData::to_one(), and EMAN::EMData::update(). 00144 {
00145 ENTERFUNC;
00146
00147 if (!EMUtil::is_same_size(V1, V2)) {
00148 LOGERR("images not same size");
00149 throw ImageFormatException( "images not same size");
00150 }
00151
00152 size_t nx = V1->get_xsize();
00153 size_t ny = V1->get_ysize();
00154 size_t nz = V1->get_zsize();
00155 size_t size = (size_t)nx*ny*nz;
00156
00157 EMData *BD = new EMData();
00158 BD->set_size(nx, ny, nz);
00159
00160 float *params = new float[2];
00161
00162 float *V1ptr, *V2ptr, *MASKptr, *BDptr, A, B;
00163 long double S1=0.L,S2=0.L,S3=0.L,S4=0.L;
00164 int nvox = 0L;
00165
00166 V1ptr = V1->get_data();
00167 V2ptr = V2->get_data();
00168 BDptr = BD->get_data();
00169
00170
00171 if(!mask){
00172 EMData * Mask = new EMData();
00173 Mask->set_size(nx,ny,nz);
00174 Mask->to_one();
00175 MASKptr = Mask->get_data();
00176 } else {
00177 if (!EMUtil::is_same_size(V1, mask)) {
00178 LOGERR("mask not same size");
00179 throw ImageFormatException( "mask not same size");
00180 }
00181
00182 MASKptr = mask->get_data();
00183 }
00184
00185
00186
00187 // calculation of S1,S2,S3,S3,nvox
00188
00189 for (size_t i = 0L;i < size; i++) {
00190 if (MASKptr[i]>0.5f) {
00191 S1 += V1ptr[i]*V2ptr[i];
00192 S2 += V1ptr[i]*V1ptr[i];
00193 S3 += V2ptr[i];
00194 S4 += V1ptr[i];
00195 nvox ++;
00196 }
00197 }
00198
00199 if ((nvox*S1 - S3*S4) == 0. || (nvox*S2 - S4*S4) == 0) {
00200 A =1.0f ;
00201 } else {
00202 A = static_cast<float>( (nvox*S1 - S3*S4)/(nvox*S2 - S4*S4) );
00203 }
00204 B = static_cast<float> (A*S4 - S3)/nvox;
00205
00206 // calculation of the difference image
00207
00208 for (size_t i = 0L;i < size; i++) {
00209 if (MASKptr[i]>0.5f) {
00210 BDptr[i] = A*V1ptr[i] - B - V2ptr[i];
00211 } else {
00212 BDptr[i] = 0.f;
00213 }
00214 }
00215
00216 BD->update();
00217
00218 params[0] = A;
00219 params[1] = B;
00220
00221 Dict BDnParams;
00222 BDnParams["imdiff"] = BD;
00223 BDnParams["A"] = params[0];
00224 BDnParams["B"] = params[1];
00225
00226 EXITFUNC;
00227 return BDnParams;
00228 }
|
|
||||||||||||
|
Definition at line 20636 of file util_sparx.cpp. References array_mutation(), EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), max, min, and nx. 20636 {
20637 int nx = img->get_xsize();
20638 float min = img->get_attr("minimum");
20639 float max = img->get_attr("maximum");
20640 float* img_data = img->get_data();
20641 array_mutation(img_data, nx*nx, mutation_rate, min, max, 8, 0);
20642 return;
20643 }
|
|
||||||||||||||||
|
Definition at line 62 of file util_sparx.cpp. References EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, ImageFormatException, LOGERR, nx, ny, and sqrt(). 00063 : find statistics under the mask (mask >0.5) 00064 // flip false: find statistics ourside the mask (mask <0.5) 00065 { 00066 ENTERFUNC; 00067 vector<float> stats; 00068 float *Volptr, *maskptr,MAX,MIN; 00069 long double Sum1,Sum2; 00070 long count; 00071 00072 MAX = -FLT_MAX; 00073 MIN = FLT_MAX; 00074 count = 0L; 00075 Sum1 = 0.0L; 00076 Sum2 = 0.0L; 00077 00078 if (mask == NULL) { 00079 //Vol->update_stat(); 00080 stats.push_back(Vol->get_attr("mean")); 00081 stats.push_back(Vol->get_attr("sigma")); 00082 stats.push_back(Vol->get_attr("minimum")); 00083 stats.push_back(Vol->get_attr("maximum")); 00084 return stats; 00085 } 00086 00087 /* Check if the sizes of the mask and image are same */ 00088 00089 size_t nx = Vol->get_xsize(); 00090 size_t ny = Vol->get_ysize(); 00091 size_t nz = Vol->get_zsize(); 00092 00093 size_t mask_nx = mask->get_xsize(); 00094 size_t mask_ny = mask->get_ysize(); 00095 size_t mask_nz = mask->get_zsize(); 00096 00097 if (nx != mask_nx || ny != mask_ny || nz != mask_nz ) 00098 throw ImageDimensionException("The dimension of the image does not match the dimension of the mask!"); 00099 00100 /* if (nx != mask_nx || 00101 ny != mask_ny || 00102 nz != mask_nz ) { 00103 // should throw an exception here!!! (will clean it up later CY) 00104 fprintf(stderr, "The dimension of the image does not match the dimension of the mask!\n"); 00105 fprintf(stderr, " nx = %d, mask_nx = %d\n", nx, mask_nx); 00106 fprintf(stderr, " ny = %d, mask_ny = %d\n", ny, mask_ny); 00107 fprintf(stderr, " nz = %d, mask_nz = %d\n", nz, mask_nz); 00108 exit(1); 00109 } 00110 */ 00111 Volptr = Vol->get_data(); 00112 maskptr = mask->get_data(); 00113 00114 for (size_t i = 0; i < (size_t)nx*ny*nz; ++i) { 00115 if ((maskptr[i]>0.5f) == flip) { 00116 Sum1 += Volptr[i]; 00117 Sum2 += Volptr[i]*double(Volptr[i]); 00118 MAX = (MAX < Volptr[i])?Volptr[i]:MAX; 00119 MIN = (MIN > Volptr[i])?Volptr[i]:MIN; 00120 count++; 00121 } 00122 } 00123 00124 if (count == 0) { 00125 LOGERR("Invalid mask"); 00126 throw ImageFormatException( "Invalid mask"); 00127 } 00128 00129 float avg = static_cast<float>(Sum1/count); 00130 float sig = static_cast<float>(sqrt((Sum2 - Sum1*Sum1/count)/(count-1))); 00131 00132 stats.push_back(avg); 00133 stats.push_back(sig); 00134 stats.push_back(MIN); 00135 stats.push_back(MAX); 00136 00137 return stats; 00138 }
|
|
||||||||||||||||||||||||
|
initial_prune removes all classes C from Parts where there does not exist ANY feasible matching containing class C which has weight gt T. The first element of each class is its original index, and second is dummy variable Definition at line 20931 of file util_sparx.cpp. References b, explore(), and k_means_cont_table_(). 20931 {
20932 //cout<<"initial_prune\n";
20933 // simple initial pruning. For class indClass of partition indPart:
20934 // For each class of partition which is not indPart, see if there is a class in the partition with which indClass has intersection greater than T
20935 // If for some partition (not equal to indPart) for which there is no such class, then return 0 immediately.
20936
20937 // 1. For each class of partition which is not indPart, remove the class from Parts if its intx with indClass of indPart is not gt T
20938
20939 // remember when calling k_means_cont_table, the first element of each class is an index, and actual number of elements in the class
20940 // (as stored in dimClasses) should be decremented by 1 accordingly, and second is dummy variable
20941
20942 int* dummy(0);
20943 int* cref;
20944 int cref_size;
20945 int* ccomp;
20946 int ccomp_size;
20947 int nintx;
20948 for (int i=0; i < nParts; i++){
20949 for (int j =0; j < K; j++){
20950
20951 // consider class Parts[i][j]
20952 cref = Parts[i][j];//incr by 1 since first element is index and second is dummy
20953 cref_size = dimClasses[i*K+cref[0]]-2;
20954
20955
20956 if (cref_size <= T){
20957 cref[0] = -1;
20958 continue;
20959 }
20960 bool done = 0;
20961 for (int a = 0; a < nParts; a++){
20962 if (a == i) continue; //consider all classes not in partition i and set to inactive all those classes whose intx with cref is not gt T
20963 bool hasActive=0;
20964 for (unsigned int b=0; b < Parts[a].size(); b++){
20965 // get the card of the intx between Parts[i][j] and Parts[a][b] using k_means_cont_table
20966 // remember first element of each class is the index of the class
20967 ccomp = Parts[a][b];
20968 ccomp_size= dimClasses[a*K+ccomp[0]]-2;
20969 nintx = Util::k_means_cont_table_(cref+2,ccomp+2, dummy, cref_size, ccomp_size,0);
20970
20971
20972 if (nintx <= T)
20973 ccomp[1] = 0; // class Parts[a][b] is 'inactive' for cref
20974 else{
20975 ccomp[1] = 1; // class Parts[a][b] is 'active' for cref
20976 hasActive=1;
20977 }
20978 }
20979 // see if partition a has at least one active class.if not then we're done with cref
20980 if (hasActive < 1){
20981 done=1;
20982 break;
20983 }
20984
20985 }
20986
20987 if (done > 0){
20988 // remove class j from partition i
20989
20990 cref[0] = -1; // mark for deletion later
20991 continue; // move on to class Parts[i][j+1]
20992 }
20993
20994 // now we adopt more aggressive measures. we find the match with the largest weight which has class Parts[i][j] for partition i.
20995 // We get rid of Parts[i][j] if this weight is not gt T as no other feasible match containing class Parts[i][j] can be gt T.
20996
20997 // (To implement later:) To reduce complexity, determine the order the partitions are to be explored based on the cardinality of the active classes of each partition.
20998 // Note that if there are ALOT of partitions, then sorting the partititions may actually take longer than the time saved by ordering hte
20999 // partitions. However, we do not have a lot of partitions, (usually around 10), so sorting time will be trivial compared to exploring time.
21000
21001 // explore returns one if there is a feasible matching containing class cref which has weight gt T, and otherwise returns 0
21002 //bool found = 1;
21003 bool found = explore(Parts, dimClasses, nParts, K, T, i, cref+2, cref_size, cref, cref_size,0);
21004
21005 if (found<1){ // There is NO feasible matching with class j (cref) with weight greater than T, so delete this class from Parts
21006 // Parts[i].erase(Parts[i].begin()+j);
21007 cref[0] = -1;
21008 }
21009 }
21010
21011 // Erase from Parts[i] all the classes that's being designated for erasure
21012
21013 for (int d = K-1; d > -1; d--){
21014 if (Parts[i][d][0] < 0) Parts[i].erase(Parts[i].begin()+d);
21015 }
21016
21017 }
21018 //cout <<"number of classes left in each partition after initial prune\n";
21019 // Print out how many classes are left in each partition
21020 //for (int i =0; i < nParts; i++)
21021 // cout << Parts[i].size()<<", ";
21022 //cout << "\n";
21023 }
|
|
|
Get a string format of an integer, e.g. 123 will be "123".
Definition at line 260 of file util.cpp. Referenced by EMAN::Log::loc(), and EMAN::E2Exception::what(). 00261 {
00262 char s[32] = {'\0'};
00263 sprintf(s, "%d", n);
00264 return string(s);
00265 }
|
|
|
check whether a file exists or not
Definition at line 208 of file util.cpp. Referenced by EMAN::TestUtil::check_image(), EMAN::GlobalCache::get_imageio(), and EMAN::SpiderIO::SpiderIO(). 00209 {
00210 if (access(filename.c_str(), F_OK) == 0) {
00211 return true;
00212 }
00213 return false;
00214 }
|
|
|
Return true if an integer is positive and is power of 2.
Definition at line 2109 of file util.h. Referenced by EMAN::WaveletProcessor::process_inplace(). |
|
||||||||||||||||||||||||||||
|
helper to create the contengency table for partition matching (k-means) flag define is the list of stable obj must be store to stb, but the size st must be know before. The trick is first start wihtout the flag to get number of elements stable, then again with the flag to get the list. This avoid to have two differents functions for the same thing. Definition at line 5225 of file util_sparx.cpp. References max. 05225 {
05226 long int d2 = group2[s2 - 1] - group2[0];
05227 long int p2 = 0;
05228 long int i1 = 0;
05229 long int i2 = 0;
05230 long int max = 0;
05231 long int cont = 0;
05232 long int i = 0;
05233 int stop1 = 0;
05234 int stop2 = 0;
05235
05236 for (i=0; i<s1; i++) {
05237 p2 = (long int)(s2 * (double)group1[i] / (double)d2);
05238 if (p2 >= s2) {p2 = s2 - 1;}
05239 i1 = p2;
05240 i2 = p2;
05241 max = s2;
05242 if (group1[i] < group2[0] || group1[i] > group2[s2 - 1]) {continue;}
05243
05244 stop1 = 0;
05245 stop2 = 0;
05246 while (max--) {
05247 if (group1[i] == group2[i1]) {
05248 if (flag) {stb[cont] = group1[i];}
05249 cont++;
05250 break;
05251 }
05252 if (group2[i1] < group1[i]) {stop1=1;}
05253 if (group1[i] == group2[i2]) {
05254 if (flag) {stb[cont] = group1[i];}
05255 cont++;
05256 break;
05257 }
05258 if (group2[i2] > group1[i]) {stop2=1;}
05259 //printf("i1 %li i2 %li v2 %i v2 %i stop1 %i stop2 %i\n", i1, i2, group2[i1], group2[i2], stop1, stop2);
05260
05261 if (stop1 & stop2) {break;}
05262 i1--;
05263 i2++;
05264 if (i1 < 0) {i1 = 0;}
05265 if (i2 >= s2) {i2 = s2 - 1;}
05266 }
05267 //printf("v1: %i ite: %li cont: %li\n", group1[i], s2-max, cont);
05268 }
05269
05270 return cont;
05271 }
|
|
||||||||||||||||
|
Calculate linear interpolation.
Definition at line 1478 of file util.h. Referenced by EMAN::WienerFourierReconstructor::do_insert_slice_work(), and EMAN::StandardProjector::project3d(). |
|
||||||||||||||||||||||||||||
|
Definition at line 20699 of file util_sparx.cpp. 20699 {
20700
20701 if (is_mirror != 0) {
20702 for (vector<float>::iterator q=list.begin(); q!=list.end(); q++) {
20703 int r = rand()%10000;
20704 float f = r/10000.0f;
20705 if (f < mutation_rate) *q = 1-*q;
20706 }
20707 } else {
20708 map<int, vector<int> > graycode;
20709 map<vector<int>, int> rev_graycode;
20710 vector <int> gray;
20711
20712 int K=1;
20713 for (int i=0; i<L; i++) K*=2;
20714
20715 for (int k=0; k<K; k++) {
20716 int shift = 0;
20717 vector <int> gray;
20718 for (int i=L-1; i>-1; i--) {
20719 int t = ((k>>i)%2-shift)%2;
20720 gray.push_back(t);
20721 shift += t-2;
20722 }
20723 graycode[k] = gray;
20724 rev_graycode[gray] = k;
20725 }
20726
20727 float gap = (K-1)/(max_val-min_val);
20728 for (vector<float>::iterator q=list.begin(); q!=list.end(); q++) {
20729 float val = *q;
20730 if (val < min_val) { val = min_val; }
20731 else if (val > max_val) { val = max_val; }
20732 int k = int((val-min_val)*gap+0.5);
20733 vector<int> gray = graycode[k];
20734 bool changed = false;
20735 for (vector<int>::iterator p=gray.begin(); p!=gray.end(); p++) {
20736 int r = rand()%10000;
20737 float f = r/10000.0f;
20738 if (f < mutation_rate) {
20739 *p = 1-*p;
20740 changed = true;
20741 }
20742 }
20743 if (changed) {
20744 k = rev_graycode[gray];
20745 *q = k/gap+min_val;
20746 }
20747 }
20748 }
20749 return list;
20750 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Definition at line 6455 of file util_sparx.cpp. 06456 {
06457 /* System generated locals */
06458 long int q_dim1, q_offset, q1_dim1, q1_offset, i__1, i__2;
06459
06460 /* Local variables */
06461 long int i__, j, m, n1, ii, jj;
06462 double tmp;
06463 vector<float> p;
06464 --x;
06465 q_dim1 = *klm2d;
06466 q_offset = 1 + q_dim1;
06467 q -= q_offset;
06468 q1_dim1 = *klm2d;
06469 q1_offset = 1 + q1_dim1;
06470 q1 -= q1_offset;
06471 --s;
06472 --res;
06473 iu -= 3;
06474 cu -= 3;
06475
06476 /* Function Body */
06477 long int l = 0;
06478
06479 /* C==ZHONG HUANG,JULY,12,02;L=0,1,2,3,4,5,6 correspond to different equality constraints */
06480 m = *ks;
06481 n1 = *n + 1;
06482 if (*iswi == 1) {
06483 i__1 = n1;
06484 for (jj = 1; jj <= i__1; ++jj) {
06485 i__2 = *ks;
06486 for (ii = 1; ii <= i__2; ++ii) {
06487 /* q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];*/
06488
06489 q[*ks + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]
06490 ;
06491 }
06492 }
06493 } else if (*iswi == 2) {
06494 i__1 = *ks;
06495 for (ii = 1; ii <= i__1; ++ii) {
06496 i__2 = n1;
06497 for (jj = 1; jj <= i__2; ++jj) {
06498 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06499 q[*ks + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]);
06500 }
06501 }
06502 } else if (*iswi == 3) {
06503 l = 2;
06504 i__1 = n1;
06505 for (jj = 1; jj <= i__1; ++jj) {
06506 i__2 = *ks + 2;
06507 for (ii = 1; ii <= i__2; ++ii) {
06508 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06509 }
06510 i__2 = *ks;
06511 for (ii = 1; ii <= i__2; ++ii) {
06512 q[*ks + 2 + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06513 }
06514 }
06515 } else if (*iswi == 4) {
06516 l = 2;
06517 i__1 = n1;
06518 for (jj = 1; jj <= i__1; ++jj) {
06519 i__2 = *ks + 2;
06520 for (ii = 1; ii <= i__2; ++ii) {
06521 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06522 }
06523 i__2 = *ks;
06524 for (ii = 1; ii <= i__2; ++ii) {
06525 q[*ks + 2 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]);
06526 }
06527 }
06528 } else if (*iswi == 5) {
06529 l = 1;
06530 i__1 = n1;
06531 for (jj = 1; jj <= i__1; ++jj) {
06532 i__2 = *ks + 1;
06533 for (ii = 1; ii <= i__2; ++ii) {
06534 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06535 }
06536 i__2 = *ks;
06537 for (ii = 1; ii <= i__2; ++ii) {
06538 q[*ks + 1 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]);
06539 }
06540 }
06541 } else if (*iswi == 6) {
06542 l = 1;
06543 i__1 = n1;
06544 for (jj = 1; jj <= i__1; ++jj) {
06545 i__2 = *ks + 1;
06546 for (ii = 1; ii <= i__2; ++ii) {
06547 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06548 }
06549 i__2 = *ks;
06550 for (ii = 1; ii <= i__2; ++ii) {
06551 q[*ks + 1 + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06552 }
06553 }
06554 } else if (*iswi == 7) {
06555 l = 3;
06556 i__1 = n1;
06557 for (jj = 1; jj <= i__1; ++jj) {
06558 i__2 = *ks + 3;
06559 for (ii = 1; ii <= i__2; ++ii) {
06560 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06561 }
06562 i__2 = *ks;
06563 for (ii = 1; ii <= i__2; ++ii) {
06564 q[*ks + 3 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]);
06565 }
06566 }
06567 } else if (*iswi == 8) {
06568 l = 4;
06569 i__1 = n1;
06570 for (jj = 1; jj <= i__1; ++jj) {
06571 i__2 = *ks + 4;
06572 for (ii = 1; ii <= i__2; ++ii) {
06573 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06574 }
06575 i__2 = *ks;
06576 for (ii = 1; ii <= i__2; ++ii) {
06577 q[*ks + 4 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]);
06578 }
06579 }
06580 }
06581
06582 Util::cl1(ks, &l, &m, n, klm2d, &q[q_offset], &x[1], &res[1], &cu[3], &iu[3], &s[1]);
06583 i__1 = *ks;
06584 int tmp__j=0;
06585 for (i__ = 1; i__ <= i__1; ++i__) {
06586 tmp = 0.f;
06587 i__2 = *n - 1;
06588 for (j = 1; j <= i__2; ++j) {
06589 tmp__j=j;
06590 tmp += pow(q1[i__ + q1_dim1], tmp__j) * x[j];
06591 }
06592 tmp += x[*n];
06593 p.push_back(static_cast<float>(exp(tmp)));
06594 p.push_back(q1[i__ + q1_dim1]);
06595 }
06596 i__2=*n;
06597 for (i__=1;i__<=i__2;++i__)
06598 { p.push_back(static_cast<float>(x[i__]));}
06599 return p;
06600 }
|
|
||||||||||||||||
|
Definition at line 17591 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, NullPointerException, nx, ny, and EMAN::EMData::update(). 17592 {
17593 ENTERFUNC;
17594 /* Exception Handle */
17595 if (!img) {
17596 throw NullPointerException("NULL input image");
17597 }
17598 /* ============== img += scalar*img1 ================ */
17599
17600 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17601 size_t size = (size_t)nx*ny*nz;
17602 float *img_ptr =img->get_data();
17603 float *img1_ptr = img1->get_data();
17604 for (size_t i=0;i<size;++i)img_ptr[i] += img1_ptr[i]*scalar;
17605 img1->update();
17606
17607 EXITFUNC;
17608 }
|
|
||||||||||||||||
|
Definition at line 17401 of file util_sparx.cpp. References EMAN::EMData::copy_head(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img2_ptr, img_ptr, EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), NullPointerException, nx, ny, EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), and EMAN::EMData::update(). 17402 {
17403 ENTERFUNC;
17404 /* Exception Handle */
17405 if (!img) {
17406 throw NullPointerException("NULL input image");
17407 }
17408 /* ============== output = img + scalar*img1 ================ */
17409
17410 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17411 size_t size = (size_t)nx*ny*nz;
17412 EMData * img2 = img->copy_head();
17413 float *img_ptr =img->get_data();
17414 float *img2_ptr = img2->get_data();
17415 float *img1_ptr = img1->get_data();
17416 for (size_t i=0;i<size;++i) img2_ptr[i] = img_ptr[i] + img1_ptr[i]*scalar;
17417 img2->update();
17418 if(img->is_complex()) {
17419 img2->set_complex(true);
17420 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false);
17421 }
17422
17423 EXITFUNC;
17424 return img2;
17425 }
|
|
||||||||||||
|
Definition at line 1047 of file util.h. Referenced by get_stats(), get_stats_cstyle(), and multi_align_error_dfunc(). |
|
||||||||||||||||
|
Definition at line 6237 of file util_sparx.cpp. 06238 {
06239 vector<float>new_peak;
06240 int n1=peak1.size()/3;
06241 float p_size2=p_size*p_size;
06242 for (int i=0;i<n1;++i) {
06243 vector<float>::iterator it2= peak1.begin()+3*i;
06244 bool push_back1=true;
06245 int n2=peak2.size()/3;
06246 /*cout<<"peak2 size==="<<n2<<"i====="<<i<<endl;
06247 cout<<"new peak size==="<<new_peak.size()/3<<endl;*/
06248 if(n2 ==0) {
06249 new_peak.push_back(*it2);
06250 new_peak.push_back(*(it2+1));
06251 new_peak.push_back(*(it2+2));
06252 } else {
06253 int j=0;
06254 while (j< n2-1 ) {
06255 vector<float>::iterator it3= peak2.begin()+3*j;
06256 float d2=((*(it2+1))-(*(it3+1)))*((*(it2+1))-(*(it3+1)))+((*(it2+2))-(*(it3+2)))*((*(it2+2))-(*(it3+2)));
06257 if(d2< p_size2 ) {
06258 if( (*it2)<(*it3) ) {
06259 new_peak.push_back(*it3);
06260 new_peak.push_back(*(it3+1));
06261 new_peak.push_back(*(it3+2));
06262 peak2.erase(it3);
06263 peak2.erase(it3);
06264 peak2.erase(it3);
06265 push_back1=false;
06266 } else {
06267 peak2.erase(it3);
06268 peak2.erase(it3);
06269 peak2.erase(it3);
06270 }
06271 } else j=j+1;
06272 n2=peak2.size()/3;
06273 }
06274 if(push_back1) {
06275 new_peak.push_back(*it2);
06276 new_peak.push_back(*(it2+1));
06277 new_peak.push_back(*(it2+2));
06278 }
06279 }
06280 }
06281 return new_peak;
06282 }
|
|
||||||||||||
|
helper function for k-means
Definition at line 5150 of file util_sparx.cpp. References data, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), nx, ny, and EMAN::Dict::size(). 05150 {
05151 ENTERFUNC;
05152
05153 int nima = data.size();
05154 vector<float> res(nima);
05155 double result = 0.;
05156 double valmin = 1.0e20;
05157 int valpos = -1;
05158
05159 for (int kk=0; kk<nima; kk++){
05160 result = 0;
05161 //validate_input_args(image, data[kk]);
05162
05163 float *y_data = data[kk]->get_data();
05164 float *x_data = image->get_data();
05165
05166 // Implemented by PAP 01/09/06 - please do not change. If in doubts, write/call me.
05167 int nx = data[kk]->get_xsize();
05168 int ny = data[kk]->get_ysize();
05169 nx = (nx - 2 + data[kk]->is_fftodd()); // nx is the real-space size of the input image
05170 int lsd2 = (nx + 2 - nx%2) ; // Extended x-dimension of the complex image
05171
05172 int ixb = 2*((nx+1)%2);
05173 int iyb = ny%2;
05174 int iz = 0;
05175
05176 for ( int iy = 0; iy <= ny-1; iy++) {
05177 for ( int ix = 2; ix <= lsd2 - 1 - ixb; ix++) {
05178 int ii = ix + (iy + iz * ny)* lsd2;
05179 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
05180 }
05181 }
05182 for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) {
05183 int ii = (iy + iz * ny)* lsd2;
05184 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
05185 result += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]);
05186 }
05187 if(nx%2 == 0) {
05188 for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) {
05189 int ii = lsd2 - 2 + (iy + iz * ny)* lsd2;
05190 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
05191 result += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]);
05192 }
05193
05194 }
05195 result *= 2;
05196 result += (x_data[0] - y_data[0])*double(x_data[0] - y_data[0]);
05197 if(ny%2 == 0) {
05198 int ii = (ny/2 + iz * ny)* lsd2;
05199 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
05200 }
05201 if(nx%2 == 0) {
05202 int ii = lsd2 - 2 + (0 + iz * ny)* lsd2;
05203 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
05204 if(ny%2 == 0) {
05205 int ii = lsd2 - 2 +(ny/2 + iz * ny)* lsd2;
05206 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
05207 }
05208 }
05209
05210 result /= (long int)nx*(long int)ny*(long int)nx*(long int)ny;
05211 res[kk] = (float)result;
05212
05213 if(result<valmin) {valmin = result; valpos = kk;}
05214
05215 }
05216
05217 Dict retvals;
05218 retvals["dist"] = res;
05219 retvals["pos"] = valpos;
05220
05221 EXITFUNC;
05222 return retvals;
05223 }
|
|
||||||||||||
|
k-means helper
Definition at line 5115 of file util_sparx.cpp. References data, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), and EMAN::Dict::size(). 05115 {
05116 ENTERFUNC;
05117
05118 int nima = data.size();
05119 vector<float> res(nima);
05120 double result = 0.;
05121 double valmin = 1.0e20;
05122 int valpos = -1;
05123
05124 for (int kk=0; kk<nima; kk++){
05125 result = 0;
05126
05127 float *y_data = data[kk]->get_data();
05128 float *x_data = image->get_data();
05129 long totsize = image->get_xsize()*image->get_ysize();
05130 for (long i = 0; i < totsize; i++) {
05131 double temp = x_data[i]- y_data[i];
05132 result += temp*temp;
05133 }
05134 result /= totsize;
05135 res[kk] = (float)result;
05136
05137 if(result<valmin) {valmin = result; valpos = kk;}
05138
05139 }
05140
05141 Dict retvals;
05142 retvals["dist"] = res;
05143 retvals["pos"] = valpos;
05144
05145 EXITFUNC;
05146 return retvals;
05147
05148 }
|
|
||||||||||||
|
Definition at line 1032 of file util.h. Referenced by cluster_pairwise(). |
|
||||||||||||||||||||
|
Definition at line 19875 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img2_ptr, img_ptr, NullPointerException, nx, ny, EMAN::EMData::set_size(), EMAN::EMData::to_zero(), and EMAN::EMData::update(). 19876 {
19877 ENTERFUNC;
19878 /* Exception Handle */
19879 if (!img) {
19880 throw NullPointerException("NULL input image");
19881 }
19882
19883 int newx, newy, newz;
19884 bool keep_going;
19885 cout << " entered " <<endl;
19886 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
19887 //int size = nx*ny*nz;
19888 EMData * img2 = new EMData();
19889 img2->set_size(nx,ny,nz);
19890 img2->to_zero();
19891 float *img_ptr =img->get_data();
19892 float *img2_ptr = img2->get_data();
19893 int r2 = ro*ro;
19894 int r3 = r2*ro;
19895 int ri2 = ri*ri;
19896 int ri3 = ri2*ri;
19897
19898 int n2 = nx/2;
19899
19900 for (int k=-n2; k<=n2; k++) { //cout << " k "<<k <<endl;
19901 float z2 = static_cast<float>(k*k);
19902 for (int j=-n2; j<=n2; j++) {
19903 float y2 = z2 + j*j;
19904 if(y2 <= r2) {
19905 //cout << " j "<<j <<endl;
19906
19907 for (int i=-n2; i<=n2; i++) {
19908 float x2 = y2 + i*i;
19909 if(x2 <= r3) {
19910 //cout << " i "<<i <<endl;
19911 int ib = i+n2; int jb = j+n2; int kb = k+n2;
19912 if(x2 >= ri3) {
19913 // this is the outer shell, here points can only vanish
19914 if(img_ptr(ib,jb,kb) == 1.0f) {
19915 //cout << " 1 "<<ib <<endl;
19916 if(Util::get_frand(0.0f, 1.0f) > qprob){
19917 img2_ptr(ib,jb,kb) = 0.0f;
19918 keep_going = true;
19919 //cout << " try "<<ib <<endl;
19920 while(keep_going) {
19921 newx = Util::get_irand(-ro,ro);
19922 newy = Util::get_irand(-ro,ro);
19923 newz = Util::get_irand(-ro,ro);
19924 if(newx*newx+newy*newy+newz*newz <= r3) {
19925 newx += n2; newy += n2; newz += n2;
19926 if( img_ptr(newx,newy,newz) == 0.0f) {
19927 img2_ptr(newx,newy,newz) = 1.0f;
19928 keep_going = false; }
19929 }
19930 }
19931 } else img2_ptr(ib,jb,kb) = 1.0f;
19932 }
19933 } else {
19934 // this is inner shell, the point can only move (or vanish, if all neighbors exist)
19935 if(img_ptr(ib,jb,kb) == 1.0) {
19936 if(Util::get_frand(0.0f,1.0f) > qprob) {
19937 // find out the number of neighbors
19938 float numn = -1.0f; // we already know the central one is 1
19939 for (newz = -1; newz <= 1; newz++)
19940 for (newy = -1; newy <= 1; newy++)
19941 for (newx = -1; newx <= 1; newx++)
19942 numn += img_ptr(ib+newx,jb+newy,kb+newz);
19943 img2_ptr(ib,jb,kb) = 0.0;
19944 if(numn == 26.0f) {
19945 // all neighbors exist, it has to vanish
19946 keep_going = true;
19947 while(keep_going) {
19948 newx = Util::get_irand(-ro,ro);
19949 newy = Util::get_irand(-ro,ro);
19950 newz = Util::get_irand(-ro,ro);
19951 if(newx*newx+newy*newy+newz*newz < r3) {
19952 newx += n2; newy += n2; newz += n2;
19953 if( img_ptr(newx,newy,newz) == 0.0f) {
19954 if(newx*newx+newy*newy+newz*newz < r3) {
19955 if(newx*newx+newy*newy+newz*newz < r3) {
19956 newx += n2; newy += n2; newz += n2;
19957 if( img_ptr(newx,newy,newz) == 0.0f) {
19958 img2_ptr(newx,newy,newz) = 1.0f;
19959 keep_going = false; }
19960 }
19961 }
19962 }
19963 }
19964 }
19965 } else if(numn == 25.0f) {
19966 // there is only one empty neighbor, move there
19967 for (newz = -1; newz <= 1; newz++) {
19968 for (newy = -1; newy <= 1; newy++) {
19969 for (newx = -1; newx <= 1; newx++) {
19970 if( newx != 0 && newy != 0 && newz != 0) {
19971 if(img_ptr(newx+ib,newy+jb,newz+kb) == 0.0f) {
19972 img2_ptr(newx+ib,newy+jb,newz+kb) = 1.0f;
19973 }
19974 }
19975 }
19976 }
19977 }
19978 } else {
19979 // more than one neighbor is zero, select randomly one and move there
19980 keep_going = true;
19981 while(keep_going) {
19982 newx = Util::get_irand(-1,1);
19983 newy = Util::get_irand(-1,1);
19984 newz = Util::get_irand(-1,1);
19985 if(newx != 0 && newy != 0 && newz != 0) {
19986 if(img_ptr(ib+newx,jb+newy,kb+newz) == 0.0f) {
19987 img2_ptr(ib+newx,jb+newy,kb+newz) = 1.0f;//?????
19988 keep_going = false;
19989 }
19990 }
19991 }
19992 }
19993 } else img2_ptr(ib,jb,kb) = 1.0f;
19994 }
19995 }
19996 }
19997 }
19998 }
19999 }
20000 }
20001 //for (int i=0;i<size;i++) img2_ptr[i] = img_ptr[i] + Util::get_irand(1,7);
20002 img2->update();
20003
20004 EXITFUNC;
20005 return img2;
20006 }
|
|
||||||||||||
|
Definition at line 17690 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, EMAN::EMData::is_complex(), NullPointerException, nx, ny, and EMAN::EMData::update(). 17691 {
17692 ENTERFUNC;
17693 /* Exception Handle */
17694 if (!img) {
17695 throw NullPointerException("NULL input image");
17696 }
17697 /* ========= img *= img1 ===================== */
17698
17699 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17700 size_t size = (size_t)nx*ny*nz;
17701 float *img_ptr = img->get_data();
17702 float *img1_ptr = img1->get_data();
17703 if(img->is_complex()) {
17704 for (size_t i=0; i<size; i+=2) {
17705 float tmp = img_ptr[i] * img1_ptr[i] - img_ptr[i+1] * img1_ptr[i+1] ;
17706 img_ptr[i+1] = img_ptr[i] * img1_ptr[i+1] + img_ptr[i+1] * img1_ptr[i] ;
17707 img_ptr[i] = tmp;
17708
17709 }
17710 } else {
17711 for (size_t i=0;i<size;++i) img_ptr[i] *= img1_ptr[i];
17712 }
17713 img->update();
17714
17715 EXITFUNC;
17716 }
|
|
||||||||||||
|
Definition at line 17573 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, NullPointerException, nx, ny, and EMAN::EMData::update(). 17574 {
17575 ENTERFUNC;
17576 /* Exception Handle */
17577 if (!img) {
17578 throw NullPointerException("NULL input image");
17579 }
17580 /* ============ output = scalar*input ================== */
17581
17582 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17583 size_t size = (size_t)nx*ny*nz;
17584 float *img_ptr =img->get_data();
17585 for (size_t i=0;i<size;++i) img_ptr[i] *= scalar;
17586 img->update();
17587
17588 EXITFUNC;
17589 }
|
|
||||||||||||
|
Definition at line 17479 of file util_sparx.cpp. References EMAN::EMData::copy_head(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img2_ptr, img_ptr, EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), NullPointerException, nx, ny, EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), and EMAN::EMData::update(). 17480 {
17481 ENTERFUNC;
17482 /* Exception Handle */
17483 if (!img) {
17484 throw NullPointerException("NULL input image");
17485 }
17486 /* ============== output = img * img1 ================ */
17487
17488 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17489 size_t size = (size_t)nx*ny*nz;
17490 EMData * img2 = img->copy_head();
17491 float *img_ptr =img->get_data();
17492 float *img2_ptr = img2->get_data();
17493 float *img1_ptr = img1->get_data();
17494 if(img->is_complex()) {
17495 for (size_t i=0; i<size; i+=2) {
17496 img2_ptr[i] = img_ptr[i] * img1_ptr[i] - img_ptr[i+1] * img1_ptr[i+1] ;
17497 img2_ptr[i+1] = img_ptr[i] * img1_ptr[i+1] + img_ptr[i+1] * img1_ptr[i] ;
17498 }
17499 img2->set_complex(true);
17500 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false);
17501 } else {
17502 for (size_t i=0; i<size; ++i) img2_ptr[i] = img_ptr[i] * img1_ptr[i];
17503 img2->update();
17504 }
17505
17506 EXITFUNC;
17507 return img2;
17508 }
|
|
||||||||||||
|
Definition at line 17376 of file util_sparx.cpp. References EMAN::EMData::copy_head(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img2_ptr, img_ptr, EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), NullPointerException, nx, ny, EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), and EMAN::EMData::update(). 17377 {
17378 ENTERFUNC;
17379 /* Exception Handle */
17380 if (!img) {
17381 throw NullPointerException("NULL input image");
17382 }
17383 /* ============ output = scalar*input ================== */
17384
17385 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17386 size_t size = (size_t)nx*ny*nz;
17387 EMData * img2 = img->copy_head();
17388 float *img_ptr =img->get_data();
17389 float *img2_ptr = img2->get_data();
17390 for (size_t i=0;i<size;++i)img2_ptr[i] = img_ptr[i]*scalar;
17391 img2->update();
17392
17393 if(img->is_complex()) {
17394 img2->set_complex(true);
17395 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false);
17396 }
17397 EXITFUNC;
17398 return img2;
17399 }
|
|
||||||||||||
|
Definition at line 19579 of file util_sparx.cpp. References multi_align_error_dfunc(), multi_align_error_func(), setulb_(), SIXTY, and x. 19579 {
19580
19581 const int nmax=args.size(), mmax=nmax;
19582 char task[60], csave[60];
19583 long int lsave[4];
19584 long int n, m, iprint, isave[44];
19585 long int* nbd = new long int[nmax];
19586 long int* iwa = new long int[3*nmax];
19587 double f, factr, pgtol;
19588 double* x = new double[nmax];
19589 double* l = new double[nmax];
19590 double* u = new double[nmax];
19591 double* g = new double[nmax];
19592 double dsave[29];
19593 double* wa = new double[2*mmax*nmax+4*nmax+12*mmax*mmax+12*mmax];
19594 long int SIXTY=60;
19595
19596 int num_ali = nmax/3+1;
19597 int nima = all_ali_params.size()/(num_ali*4);
19598
19599 // We wish to have no output.
19600 iprint = -1;
19601
19602 //c We specify the tolerances in the stopping criteria.
19603 factr=1.0e1;
19604 pgtol=1.0e-9;
19605
19606 // We specify the dimension n of the sample problem and the number
19607 // m of limited memory corrections stored. (n and m should not
19608 // exceed the limits nmax and mmax respectively.)
19609 n=nmax;
19610 m=mmax;
19611
19612 // We now provide nbd which defines the bounds on the variables:
19613 // l specifies the lower bounds,
19614 // u specifies the upper bounds.
19615 // x specifies the initial guess
19616 for (int i=0; i<nmax; i++) {
19617 x[i] = args[i];
19618 nbd[i] = 0;
19619 }
19620
19621 // We start the iteration by initializing task.
19622 // (**MUST clear remaining chars in task with spaces (else crash)!**)
19623 strcpy(task,"START");
19624 for (int i=5;i<60;i++) task[i]=' ';
19625
19626 // This is the call to the L-BFGS-B code.
19627 // (* call the L-BFGS-B routine with task='START' once before loop *)
19628 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
19629 int step = 1;
19630
19631 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *)
19632 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) {
19633
19634 if (strncmp(task,"FG",2)==0) {
19635 // the minimization routine has returned to request the
19636 // function f and gradient g values at the current x
19637
19638 // Compute function value f for the sample problem.
19639 f = multi_align_error_func(x, all_ali_params, nima, num_ali);
19640
19641 // Compute gradient g for the sample problem.
19642 multi_align_error_dfunc(x, all_ali_params, nima, num_ali, g);
19643 }
19644
19645 //c go back to the minimization routine.
19646 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
19647 step++;
19648 }
19649
19650 //printf("Total step is %d\n", step);
19651 vector<float> res;
19652 for (int i=0; i<nmax; i++) res.push_back(static_cast<float>(x[i]));
19653 res.push_back((float)f);
19654
19655 delete[] nbd;
19656 delete[] iwa;
19657 delete[] x;
19658 delete[] l;
19659 delete[] u;
19660 delete[] g;
19661 delete[] wa;
19662
19663 return res;
19664
19665 }
|
|
||||||||||||||||||||||||
|
Definition at line 19722 of file util_sparx.cpp. References mean(), rot_shift(), and x. Referenced by multi_align_error(). 19722 {
19723
19724
19725 for (int i=0; i<num_ali*3-3; i++) g[i] = 0.0;
19726
19727 float x1 = 1.0;
19728 float y1 = 0.0;
19729 float x2 = 0.0;
19730 float y2 = 1.0;
19731
19732 float* x1_new = new float[num_ali];
19733 float* y1_new = new float[num_ali];
19734 float* x2_new = new float[num_ali];
19735 float* y2_new = new float[num_ali];
19736
19737 float* alpha12_0 = new float[num_ali-1];
19738 float* dalpha12 = new float[num_ali-1];
19739 float* dsx12 = new float[num_ali-1];
19740 float* dsy12 = new float[num_ali-1];
19741 float* mirror1_0 = new float[num_ali-1];
19742
19743 for (int i=0; i<nima; i++) {
19744
19745 float alpha2 = all_ali_params[(num_ali-1)*(nima*4)+i*4];
19746 float sx2 = all_ali_params[(num_ali-1)*(nima*4)+i*4+1];
19747 float sy2 = all_ali_params[(num_ali-1)*(nima*4)+i*4+2];
19748
19749 rot_shift(x1, y1, alpha2, sx2, sy2, x1_new+num_ali-1, y1_new+num_ali-1);
19750 rot_shift(x2, y2, alpha2, sx2, sy2, x2_new+num_ali-1, y2_new+num_ali-1);
19751
19752 for (int j=0; j<num_ali-1; j++) {
19753 float alpha1 = all_ali_params[j*(nima*4)+i*4];
19754 float sx1 = all_ali_params[j*(nima*4)+i*4+1];
19755 float sy1 = all_ali_params[j*(nima*4)+i*4+2];
19756 int mirror1 = static_cast<int>(all_ali_params[j*(nima*4)+i*4+3]);
19757
19758 float alphai = x[j*3];
19759 float sxi = x[j*3+1];
19760 float syi = x[j*3+2];
19761
19762 float cosi = cos(alphai/180.0f*M_PI);
19763 float sini = sin(alphai/180.0f*M_PI);
19764
19765 float alpha12, sx12, sy12;
19766 int mirror12;
19767 if (mirror1 == 0) {
19768 alpha12 = fmod(alpha1+alphai, 360.0f);
19769 rot_shift(sx1, sy1, alphai, sxi, syi, &sx12, &sy12);
19770 mirror12 = 0;
19771 } else {
19772 alpha12 = fmod(alpha1-alphai, 360.0f);
19773 rot_shift(sx1, sy1, -alphai, -sxi, syi, &sx12, &sy12);
19774 mirror12 = 1;
19775 }
19776
19777 rot_shift(x1, y1, alpha12, sx12, sy12, x1_new+j, y1_new+j);
19778 rot_shift(x2, y2, alpha12, sx12, sy12, x2_new+j, y2_new+j);
19779
19780 alpha12_0[j] = alpha12;
19781 mirror1_0[j] = mirror1;
19782 if (mirror1 == 0) {
19783 dalpha12[j] = M_PI/180.0f;
19784 dsx12[j] = (-sini*sx1+cosi*sy1)/180.0f*M_PI;
19785 dsy12[j] = (-cosi*sx1-sini*sy1)/180.0f*M_PI;
19786 } else {
19787 dalpha12[j] = -M_PI/180.0f;
19788 dsx12[j] = (sini*(-sx1)-cosi*sy1)/180.0f*M_PI;
19789 dsy12[j] = (-cosi*(-sx1)-sini*sy1)/180.0f*M_PI;
19790 }
19791 }
19792
19793 for (int j=0; j<num_ali-1; j++) {
19794 float cosa = cos(alpha12_0[j]/180.0f*M_PI);
19795 float sina = sin(alpha12_0[j]/180.0f*M_PI);
19796 float diffx1 = x1_new[j]-mean(x1_new, num_ali);
19797 float diffx2 = x2_new[j]-mean(x2_new, num_ali);
19798 float diffy1 = y1_new[j]-mean(y1_new, num_ali);
19799 float diffy2 = y2_new[j]-mean(y2_new, num_ali);
19800
19801 float p = diffx1*((-x1*sina+y1*cosa)*dalpha12[j]+dsx12[j])+diffx2*((-x2*sina+y2*cosa)*dalpha12[j]+dsx12[j])+diffy1*((-x1*cosa-y1*sina)*dalpha12[j]+dsy12[j])+diffy2*((-x2*cosa-y2*sina)*dalpha12[j]+dsy12[j]);
19802 g[j*3] += p;
19803
19804 p = diffx1+diffx2;
19805 if (mirror1_0[j] == 0) g[j*3+1] += p;
19806 else g[j*3+1] -= p;
19807
19808 p = diffy1+diffy2;
19809 g[j*3+2] += p;
19810 }
19811 }
19812
19813 delete[] x1_new;
19814 delete[] y1_new;
19815 delete[] x2_new;
19816 delete[] y2_new;
19817 delete[] alpha12_0;
19818 delete[] dalpha12;
19819 delete[] dsx12;
19820 delete[] dsy12;
19821 delete[] mirror1_0;
19822
19823 }
|
|
||||||||||||||||||||
|
Definition at line 19667 of file util_sparx.cpp. References rot_shift(), var(), and x. Referenced by multi_align_error(). 19667 {
19668
19669 float x1 = 1.0;
19670 float y1 = 0.0;
19671 float x2 = 0.0;
19672 float y2 = 1.0;
19673
19674 float all_var = 0;
19675 float* x1_new = new float[num_ali];
19676 float* y1_new = new float[num_ali];
19677 float* x2_new = new float[num_ali];
19678 float* y2_new = new float[num_ali];
19679
19680 for (int i=0; i<nima; i++) {
19681 float alpha2 = all_ali_params[(num_ali-1)*(nima*4)+i*4];
19682 float sx2 = all_ali_params[(num_ali-1)*(nima*4)+i*4+1];
19683 float sy2 = all_ali_params[(num_ali-1)*(nima*4)+i*4+2];
19684
19685 rot_shift(x1, y1, alpha2, sx2, sy2, x1_new+num_ali-1, y1_new+num_ali-1);
19686 rot_shift(x2, y2, alpha2, sx2, sy2, x2_new+num_ali-1, y2_new+num_ali-1);
19687 for (int j=0; j<num_ali-1; j++) {
19688 float alpha1 = all_ali_params[j*(nima*4)+i*4];
19689 float sx1 = all_ali_params[j*(nima*4)+i*4+1];
19690 float sy1 = all_ali_params[j*(nima*4)+i*4+2];
19691 int mirror1 = static_cast<int>(all_ali_params[j*(nima*4)+i*4+3]);
19692
19693 float alphai = x[j*3];
19694 float sxi = x[j*3+1];
19695 float syi = x[j*3+2];
19696
19697 float alpha12, sx12, sy12;
19698 int mirror12;
19699 if (mirror1 == 0) {
19700 alpha12 = fmod(alpha1+alphai, 360.0f);
19701 rot_shift(sx1, sy1, alphai, sxi, syi, &sx12, &sy12);
19702 mirror12 = 0;
19703 } else {
19704 alpha12 = fmod(alpha1-alphai, 360.0f);
19705 rot_shift(sx1, sy1, -alphai, -sxi, syi, &sx12, &sy12);
19706 mirror12 = 1;
19707 }
19708
19709 rot_shift(x1, y1, alpha12, sx12, sy12, x1_new+j, y1_new+j);
19710 rot_shift(x2, y2, alpha12, sx12, sy12, x2_new+j, y2_new+j);
19711 }
19712
19713 all_var += var(x1_new, num_ali)+var(y1_new, num_ali)+var(x2_new, num_ali)+var(y2_new, num_ali);
19714 }
19715 delete[] x1_new;
19716 delete[] y1_new;
19717 delete[] x2_new;
19718 delete[] y2_new;
19719 return all_var/static_cast<float>(nima);
19720 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Determine shift and rotation between image and one reference image (crefim, weights have to be applied) using quadratic interpolation, return a list of peaks PAP 07/21/08. ccf1d keeps 1d ccfs stored as (maxrin, -kx-1:kx+1, -ky-1:ky+1) margin is needed for peak search and both arrays are initialized with -1.0e20 Definition at line 18957 of file util_sparx.cpp. References Crosrng_msg_vec(), Frngs(), EMAN::EMData::get_data(), numr, Polar2Dm(), and EMAN::EMData::set_size(). 18960 {
18961
18962 int maxrin = numr[numr.size()-1];
18963
18964 int ky = int(2*yrng/step+0.5)/2;
18965 int kx = int(2*xrng/step+0.5)/2;
18966
18967 peaks->set_size(maxrin, 2*kx+3, 2*ky+3);
18968 float *p_ccf1ds = peaks->get_data();
18969
18970 peakm->set_size(maxrin, 2*kx+3, 2*ky+3);
18971 float *p_ccf1dm = peakm->get_data();
18972
18973 for ( int i = 0; i<maxrin*(2*kx+3)*(2*ky+3); i++) {
18974 p_ccf1ds[i] = -1.e20f;
18975 p_ccf1dm[i] = -1.e20f;
18976 }
18977
18978 for (int i = -ky; i <= ky; i++) {
18979 float iy = i * step;
18980 for (int j = -kx; j <= kx; j++) {
18981 float ix = j*step;
18982 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18983 Frngs(cimage, numr);
18984 Crosrng_msg_vec(crefim, cimage, numr,
18985 p_ccf1ds+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin,
18986 p_ccf1dm+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin);
18987 delete cimage; cimage = 0;
18988 }
18989 }
18990 return;
18991 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Determine shift and rotation between image and one reference image (crefim, weights have to be applied) using quadratic interpolation, return a list of peaks PAP 07/21/08. ccf1d keeps 1d ccfs stored as (maxrin, -kx-1:kx+1, -ky-1:ky+1) margin is needed for peak search and both arrays are initialized with -1.0e20 Definition at line 18993 of file util_sparx.cpp. References Crosrng_msg_vec(), Frngs(), EMAN::EMData::get_data(), numr, Polar2Dm(), EMAN::EMData::set_size(), and x. 18995 {
18996
18997 int maxrin = numr[numr.size()-1];
18998
18999 int ky = int(2*yrng/step+0.5)/2;
19000 int kx = int(2*xrng/step+0.5)/2;
19001
19002 peaks->set_size(maxrin, 2*kx+3, 2*ky+3);
19003 float *p_ccf1ds = peaks->get_data();
19004
19005 peakm->set_size(maxrin, 2*kx+3, 2*ky+3);
19006 float *p_ccf1dm = peakm->get_data();
19007
19008 peaks_compress->set_size(maxrin, 1, 1);
19009 float *p_ccf1ds_compress = peaks_compress->get_data();
19010
19011 peakm_compress->set_size(maxrin, 1, 1);
19012 float *p_ccf1dm_compress = peakm_compress->get_data();
19013
19014 for ( int i = 0; i<maxrin*(2*kx+3)*(2*ky+3); i++) {
19015 p_ccf1ds[i] = -1.e20f;
19016 p_ccf1dm[i] = -1.e20f;
19017 }
19018
19019 for (int i = -ky; i <= ky; i++) {
19020 float iy = i * step;
19021 for (int j = -kx; j <= kx; j++) {
19022 float ix = j*step;
19023 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
19024 Frngs(cimage, numr);
19025 Crosrng_msg_vec(crefim, cimage, numr,
19026 p_ccf1ds+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin,
19027 p_ccf1dm+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin);
19028 delete cimage; cimage = 0;
19029 }
19030 }
19031 for (int x=0; x<maxrin; x++) {
19032 float maxs = -1.0e22f;
19033 float maxm = -1.0e22f;
19034 for (int i=1; i<=2*ky+1; i++) {
19035 for (int j=1; j<=2*kx+1; j++) {
19036 if (p_ccf1ds[(i*(2*kx+3)+j)*maxrin+x] > maxs) maxs = p_ccf1ds[(i*(2*kx+3)+j)*maxrin+x];
19037 if (p_ccf1dm[(i*(2*kx+3)+j)*maxrin+x] > maxm) maxm = p_ccf1dm[(i*(2*kx+3)+j)*maxrin+x];
19038 }
19039 }
19040 p_ccf1ds_compress[x] = maxs;
19041 p_ccf1dm_compress[x] = maxm;
19042 }
19043 return;
19044 }
|
|
||||||||||||||||||||||||||||||||||||||||
|
formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation
Definition at line 17899 of file util_sparx.cpp. References ang_n(), Crosrng_ms(), Frngs(), Normalize_ring(), numr, pi, Polar2Dm(), and EMAN::Dict::size(). 17901 {
17902
17903 // Manually extract.
17904 /* vector< EMAN::EMData* > crefim;
17905 std::size_t crefim_len = PyObject_Length(crefim_list.ptr());
17906 crefim.reserve(crefim_len);
17907
17908 for(std::size_t i=0;i<crefim_len;i++) {
17909 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]);
17910 crefim.push_back(proxy());
17911 }
17912 */
17913
17914 size_t crefim_len = crefim.size();
17915
17916 int ky = int(2*yrng/step+0.5)/2;
17917 int kx = int(2*xrng/step+0.5)/2;
17918 int iref, nref=0, mirror=0;
17919 float iy, ix, sx=0, sy=0;
17920 float peak = -1.0E23f;
17921 float ang=0.0f;
17922 for (int i = -ky; i <= ky; i++) {
17923 iy = i * step ;
17924 for (int j = -kx; j <= kx; j++) {
17925 ix = j*step ;
17926 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
17927
17928 Normalize_ring( cimage, numr );
17929
17930 Frngs(cimage, numr);
17931 // compare with all reference images
17932 // for iref in xrange(len(crefim)):
17933 for ( iref = 0; iref < (int)crefim_len; iref++) {
17934 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr);
17935 double qn = retvals["qn"];
17936 double qm = retvals["qm"];
17937 if(qn >= peak || qm >= peak) {
17938 sx = -ix;
17939 sy = -iy;
17940 nref = iref;
17941 if (qn >= qm) {
17942 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
17943 peak = static_cast<float>(qn);
17944 mirror = 0;
17945 } else {
17946 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
17947 peak = static_cast<float>(qm);
17948 mirror = 1;
17949 }
17950 }
17951 } delete cimage; cimage = 0;
17952 }
17953 }
17954 float co, so, sxs, sys;
17955 co = static_cast<float>( cos(ang*pi/180.0) );
17956 so = static_cast<float>( -sin(ang*pi/180.0) );
17957 sxs = sx*co - sy*so;
17958 sys = sx*so + sy*co;
17959 vector<float> res;
17960 res.push_back(ang);
17961 res.push_back(sxs);
17962 res.push_back(sys);
17963 res.push_back(static_cast<float>(mirror));
17964 res.push_back(static_cast<float>(nref));
17965 res.push_back(peak);
17966 return res;
17967 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation
Definition at line 18087 of file util_sparx.cpp. References ang_n(), Crosrng_ms_delta(), Frngs(), Normalize_ring(), numr, pi, Polar2Dm(), and EMAN::Dict::size(). 18089 {
18090
18091 // Manually extract.
18092 /* vector< EMAN::EMData* > crefim;
18093 std::size_t crefim_len = PyObject_Length(crefim_list.ptr());
18094 crefim.reserve(crefim_len);
18095
18096 for(std::size_t i=0;i<crefim_len;i++) {
18097 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]);
18098 crefim.push_back(proxy());
18099 }
18100 */
18101
18102 size_t crefim_len = crefim.size();
18103
18104 int ky = int(2*yrng/step+0.5)/2;
18105 int kx = int(2*xrng/step+0.5)/2;
18106 int iref, nref=0, mirror=0;
18107 float iy, ix, sx=0, sy=0;
18108 float peak = -1.0E23f;
18109 float ang=0.0f;
18110 for (int i = -ky; i <= ky; i++) {
18111 iy = i * step ;
18112 for (int j = -kx; j <= kx; j++) {
18113 ix = j*step ;
18114 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18115
18116 Normalize_ring( cimage, numr );
18117
18118 Frngs(cimage, numr);
18119 // compare with all reference images
18120 // for iref in xrange(len(crefim)):
18121 for ( iref = 0; iref < (int)crefim_len; iref++) {
18122 Dict retvals = Crosrng_ms_delta(crefim[iref], cimage, numr, delta_start, delta);
18123 double qn = retvals["qn"];
18124 double qm = retvals["qm"];
18125 if(qn >= peak || qm >= peak) {
18126 sx = -ix;
18127 sy = -iy;
18128 nref = iref;
18129 if (qn >= qm) {
18130 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18131 peak = static_cast<float>(qn);
18132 mirror = 0;
18133 } else {
18134 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
18135 peak = static_cast<float>(qm);
18136 mirror = 1;
18137 }
18138 }
18139 } delete cimage; cimage = 0;
18140 }
18141 }
18142 float co, so, sxs, sys;
18143 co = static_cast<float>( cos(ang*pi/180.0) );
18144 so = static_cast<float>( -sin(ang*pi/180.0) );
18145 sxs = sx*co - sy*so;
18146 sys = sx*so + sy*co;
18147 vector<float> res;
18148 res.push_back(ang);
18149 res.push_back(sxs);
18150 res.push_back(sys);
18151 res.push_back(static_cast<float>(mirror));
18152 res.push_back(static_cast<float>(nref));
18153 res.push_back(peak);
18154 return res;
18155 }
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation
Definition at line 18214 of file util_sparx.cpp. References abs, ang_n(), Crosrng_ms(), Frngs(), EMAN::EMData::get_attr(), EMAN::Transform::get_params(), Normalize_ring(), numr, phi, pi, Polar2Dm(), EMAN::Dict::size(), t, and theta. 18216 {
18217
18218 // Manually extract.
18219 /* vector< EMAN::EMData* > crefim;
18220 std::size_t crefim_len = PyObject_Length(crefim_list.ptr());
18221 crefim.reserve(crefim_len);
18222
18223 for(std::size_t i=0;i<crefim_len;i++) {
18224 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]);
18225 crefim.push_back(proxy());
18226 }
18227 */
18228 size_t crefim_len = crefim.size();
18229 const float qv = static_cast<float>( pi/180.0 );
18230
18231 Transform * t = image->get_attr("xform.projection");
18232 Dict d = t->get_params("spider");
18233 if(t) {delete t; t=0;}
18234 float phi = d["phi"];
18235 float theta = d["theta"];
18236 int ky = int(2*yrng/step+0.5)/2;
18237 int kx = int(2*xrng/step+0.5)/2;
18238 int iref, nref=0, mirror=0;
18239 float iy, ix, sx=0, sy=0;
18240 float peak = -1.0E23f;
18241 float ang=0.0f;
18242 float imn1 = sin(theta*qv)*cos(phi*qv);
18243 float imn2 = sin(theta*qv)*sin(phi*qv);
18244 float imn3 = cos(theta*qv);
18245 vector<float> n1(crefim_len);
18246 vector<float> n2(crefim_len);
18247 vector<float> n3(crefim_len);
18248 for ( iref = 0; iref < (int)crefim_len; iref++) {
18249 n1[iref] = crefim[iref]->get_attr("n1");
18250 n2[iref] = crefim[iref]->get_attr("n2");
18251 n3[iref] = crefim[iref]->get_attr("n3");
18252 }
18253 for (int i = -ky; i <= ky; i++) {
18254 iy = i * step ;
18255 for (int j = -kx; j <= kx; j++) {
18256 ix = j*step;
18257 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18258
18259 Normalize_ring( cimage, numr );
18260
18261 Frngs(cimage, numr);
18262 // compare with all reference images
18263 // for iref in xrange(len(crefim)):
18264 for ( iref = 0; iref < (int)crefim_len; iref++) {
18265 if(abs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) {
18266 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr);
18267 double qn = retvals["qn"];
18268 double qm = retvals["qm"];
18269 if(qn >= peak || qm >= peak) {
18270 sx = -ix;
18271 sy = -iy;
18272 nref = iref;
18273 if (qn >= qm) {
18274 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18275 peak = static_cast<float>( qn );
18276 mirror = 0;
18277 } else {
18278 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
18279 peak = static_cast<float>( qm );
18280 mirror = 1;
18281 }
18282 }
18283 }
18284 } delete cimage; cimage = 0;
18285 }
18286 }
18287 float co, so, sxs, sys;
18288 if(peak == -1.0E23) {
18289 ang=0.0; sxs=0.0; sys=0.0; mirror=0;
18290 nref = -1;
18291 } else {
18292 co = cos(ang*qv);
18293 so = -sin(ang*qv);
18294 sxs = sx*co - sy*so;
18295 sys = sx*so + sy*co;
18296 }
18297 vector<float> res;
18298 res.push_back(ang);
18299 res.push_back(sxs);
18300 res.push_back(sys);
18301 res.push_back(static_cast<float>(mirror));
18302 res.push_back(static_cast<float>(nref));
18303 res.push_back(peak);
18304 return res;
18305 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation
Definition at line 18307 of file util_sparx.cpp. References abs, ang_n(), Crosrng_sm_psi(), Frngs(), EMAN::EMData::get_attr(), EMAN::Transform::get_params(), Normalize_ring(), numr, phi, pi, Polar2Dm(), EMAN::Dict::size(), t, and theta. 18309 {
18310
18311 // Manually extract.
18312 /* vector< EMAN::EMData* > crefim;
18313 std::size_t crefim_len = PyObject_Length(crefim_list.ptr());
18314 crefim.reserve(crefim_len);
18315
18316 for(std::size_t i=0;i<crefim_len;i++) {
18317 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]);
18318 crefim.push_back(proxy());
18319 }
18320 */
18321 size_t crefim_len = crefim.size();
18322 const float qv = static_cast<float>(pi/180.0);
18323
18324 Transform* t = image->get_attr("xform.projection");
18325 Dict d = t->get_params("spider");
18326 if(t) {delete t; t=0;}
18327 float phi = d["phi"];
18328 float theta = d["theta"];
18329 float psi = d["psi"];
18330 int ky = int(2*yrng/step+0.5)/2;
18331 int kx = int(2*xrng/step+0.5)/2;
18332 int iref, nref = 0, mirror = 0;
18333 float iy, ix, sx = 0, sy = 0;
18334 float peak = -1.0E23f;
18335 float ang = 0.0f;
18336 float imn1 = sin(theta*qv)*cos(phi*qv);
18337 float imn2 = sin(theta*qv)*sin(phi*qv);
18338 float imn3 = cos(theta*qv);
18339 vector<float> n1(crefim_len);
18340 vector<float> n2(crefim_len);
18341 vector<float> n3(crefim_len);
18342 for (iref = 0; iref < (int)crefim_len; iref++) {
18343 n1[iref] = crefim[iref]->get_attr("n1");
18344 n2[iref] = crefim[iref]->get_attr("n2");
18345 n3[iref] = crefim[iref]->get_attr("n3");
18346 }
18347 bool nomirror = (theta<90.0) || ((theta==90.0) && (psi<psi_max));
18348 if (!nomirror) {
18349 phi = fmod(phi+540.0f, 360.0f);
18350 theta = 180-theta;
18351 psi = fmod(540.0f-psi, 360.0f);
18352 }
18353 for (int i = -ky; i <= ky; i++) {
18354 iy = i * step ;
18355 for (int j = -kx; j <= kx; j++) {
18356 ix = j*step;
18357 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18358
18359 Normalize_ring(cimage, numr);
18360
18361 Frngs(cimage, numr);
18362 // compare with all reference images
18363 // for iref in xrange(len(crefim)):
18364 for (iref = 0; iref < (int)crefim_len; iref++) {
18365 if (abs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) {
18366 if (nomirror) {
18367 Dict retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, psi, 0);
18368 double qn = retvals["qn"];
18369 if (qn >= peak) {
18370 sx = -ix;
18371 sy = -iy;
18372 nref = iref;
18373 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18374 peak = static_cast<float>(qn);
18375 mirror = 0;
18376 }
18377 } else {
18378 Dict retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, psi, 1);
18379 double qn = retvals["qn"];
18380 if (qn >= peak) {
18381 sx = -ix;
18382 sy = -iy;
18383 nref = iref;
18384 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18385 peak = static_cast<float>(qn);
18386 mirror = 1;
18387 }
18388 }
18389 }
18390 } delete cimage; cimage = 0;
18391 }
18392 }
18393 float co, so, sxs, sys;
18394 if(peak == -1.0E23) {
18395 ang=0.0; sxs=0.0; sys=0.0; mirror=0;
18396 nref = -1;
18397 } else {
18398 co = cos(ang*qv);
18399 so = -sin(ang*qv);
18400 sxs = sx*co - sy*so;
18401 sys = sx*so + sy*co;
18402 }
18403 vector<float> res;
18404 res.push_back(ang);
18405 res.push_back(sxs);
18406 res.push_back(sys);
18407 res.push_back(static_cast<float>(mirror));
18408 res.push_back(static_cast<float>(nref));
18409 res.push_back(peak);
18410 return res;
18411 }
|
|
||||||||||||||||||||||||||||||||||||||||
|
formerly known as apnq DO NOT CONSIDER MIRROR Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation
Definition at line 18157 of file util_sparx.cpp. References ang_n(), Crosrng_ns(), Frngs(), numr, pi, Polar2Dm(), and EMAN::Dict::size(). 18159 {
18160
18161 // Manually extract.
18162 /* vector< EMAN::EMData* > crefim;
18163 std::size_t crefim_len = PyObject_Length(crefim_list.ptr());
18164 crefim.reserve(crefim_len);
18165
18166 for(std::size_t i=0;i<crefim_len;i++) {
18167 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]);
18168 crefim.push_back(proxy());
18169 }
18170 */
18171 size_t crefim_len = crefim.size();
18172
18173 int ky = int(2*yrng/step+0.5)/2;
18174 int kx = int(2*xrng/step+0.5)/2;
18175 int iref, nref=0;
18176 float iy, ix, sx=0, sy=0;
18177 float peak = -1.0E23f;
18178 float ang=0.0f;
18179 for (int i = -ky; i <= ky; i++) {
18180 iy = i * step ;
18181 for (int j = -kx; j <= kx; j++) {
18182 ix = j*step ;
18183 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18184 Frngs(cimage, numr);
18185 // compare with all reference images
18186 // for iref in xrange(len(crefim)):
18187 for ( iref = 0; iref < (int)crefim_len; iref++) {
18188 Dict retvals = Crosrng_ns(crefim[iref], cimage, numr);
18189 double qn = retvals["qn"];
18190 if(qn >= peak) {
18191 sx = -ix;
18192 sy = -iy;
18193 nref = iref;
18194 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18195 peak = static_cast<float>(qn);
18196 }
18197 } delete cimage; cimage = 0;
18198 }
18199 }
18200 float co, so, sxs, sys;
18201 co = static_cast<float>( cos(ang*pi/180.0) );
18202 so = static_cast<float>( -sin(ang*pi/180.0) );
18203 sxs = sx*co - sy*so;
18204 sys = sx*so + sy*co;
18205 vector<float> res;
18206 res.push_back(ang);
18207 res.push_back(sxs);
18208 res.push_back(sys);
18209 res.push_back(static_cast<float>(nref));
18210 res.push_back(peak);
18211 return res;
18212 }
|
|
||||||||||||||||||||||||||||||||||||||||
|
Definition at line 17969 of file util_sparx.cpp. References ang_n(), Crosrng_ms(), Frngs(), Normalize_ring(), numr, pi, Polar2Dm(), and EMAN::Dict::size(). 17971 {
17972
17973 size_t crefim_len = crefim.size();
17974
17975 int ky = int(2*yrng/step+0.5)/2;
17976 int kx = int(2*xrng/step+0.5)/2;
17977 float iy, ix;
17978 vector<float> peak(crefim_len*5, -1.0e23f);
17979 for (int i = -ky; i <= ky; i++) {
17980 iy = i * step ;
17981 for (int j = -kx; j <= kx; j++) {
17982 ix = j*step ;
17983 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
17984 Normalize_ring( cimage, numr );
17985 Frngs(cimage, numr);
17986 for (int iref = 0; iref < (int)crefim_len; iref++) {
17987 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr);
17988 double qn = retvals["qn"];
17989 double qm = retvals["qm"];
17990 if(qn >= peak[iref*5] || qm >= peak[iref*5]) {
17991 if (qn >= qm) {
17992 peak[iref*5] = static_cast<float>(qn);
17993 peak[iref*5+1] = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
17994 peak[iref*5+2] = -ix;
17995 peak[iref*5+3] = -iy;
17996 peak[iref*5+4] = 0;
17997 } else {
17998 peak[iref*5] = static_cast<float>(qm);
17999 peak[iref*5+1] = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
18000 peak[iref*5+2] = -ix;
18001 peak[iref*5+3] = -iy;
18002 peak[iref*5+4] = 1;
18003 }
18004 }
18005 } delete cimage; cimage = 0;
18006 }
18007 }
18008 for (int iref = 0; iref < (int)crefim_len; iref++) {
18009 float ang = peak[iref*5+1];
18010 float sx = peak[iref*5+2];
18011 float sy = peak[iref*5+3];
18012 float co = cos(ang*pi/180.0);
18013 float so = -sin(ang*pi/180.0);
18014 float sxs = sx*co - sy*so;
18015 float sys = sx*so + sy*co;
18016 peak[iref*5+2] = sxs;
18017 peak[iref*5+3] = sys;
18018 }
18019 return peak;
18020 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation Search for peaks only within +/-psi_max from 0 and 180 (helical)
Definition at line 18414 of file util_sparx.cpp. References ang_n(), Crosrng_psi_0_180(), Frngs(), Normalize_ring(), numr, pi, Polar2Dm(), and EMAN::Dict::size(). 18416 {
18417
18418 size_t crefim_len = crefim.size();
18419
18420 int iref, nref=0, mirror=0;
18421 float iy, ix, sx=0, sy=0;
18422 float peak = -1.0E23f;
18423 float ang=0.0f;
18424 int kx = int(2*xrng/step+0.5)/2;
18425 //if ynumber==-1, use the old code which process x and y direction equally.
18426 if(ynumber==-1) {
18427 int ky = int(2*yrng/step+0.5)/2;
18428 for (int i = -ky; i <= ky; i++) {
18429 iy = i * step ;
18430 for (int j = -kx; j <= kx; j++) {
18431 ix = j*step ;
18432 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18433
18434 Normalize_ring( cimage, numr );
18435
18436 Frngs(cimage, numr);
18437 // compare with all reference images
18438 // for iref in xrange(len(crefim)):
18439 for ( iref = 0; iref < (int)crefim_len; iref++) {
18440 Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max);
18441 double qn = retvals["qn"];
18442 double qm = retvals["qm"];
18443 if(qn >= peak || qm >= peak) {
18444 sx = -ix;
18445 sy = -iy;
18446 nref = iref;
18447 if (qn >= qm) {
18448 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18449 peak = static_cast<float>(qn);
18450 mirror = 0;
18451 } else {
18452 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
18453 peak = static_cast<float>(qm);
18454 mirror = 1;
18455 }
18456 }
18457 }
18458 delete cimage; cimage = 0;
18459 }
18460 }
18461 }
18462 //if ynumber is given, it should be even. We need to check whether it is zero
18463 else if(ynumber==0) {
18464 sy = 0.0f;
18465 for (int j = -kx; j <= kx; j++) {
18466 ix = j*step ;
18467 EMData* cimage = Polar2Dm(image, cnx+ix, cny, numr, mode);
18468
18469 Normalize_ring( cimage, numr );
18470
18471 Frngs(cimage, numr);
18472 // compare with all reference images
18473 // for iref in xrange(len(crefim)):
18474 for ( iref = 0; iref < (int)crefim_len; iref++) {
18475 Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max);
18476 double qn = retvals["qn"];
18477 double qm = retvals["qm"];
18478 if(qn >= peak || qm >= peak) {
18479 sx = -ix;
18480 nref = iref;
18481 if (qn >= qm) {
18482 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18483 peak = static_cast<float>(qn);
18484 mirror = 0;
18485 } else {
18486 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
18487 peak = static_cast<float>(qm);
18488 mirror = 1;
18489 }
18490 }
18491 }
18492 delete cimage; cimage = 0;
18493 }
18494 } else {
18495 int ky = int(ynumber/2);
18496 float stepy=2*yrng/ynumber;
18497 //std::cout<<"yrng="<<yrng<<"ynumber="<<ynumber<<"stepy=="<<stepy<<"stepx=="<<step<<std::endl;
18498 for (int i = -ky+1; i <= ky; i++) {
18499 iy = i * stepy ;
18500 for (int j = -kx; j <= kx; j++) {
18501 ix = j*step ;
18502 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18503
18504 Normalize_ring( cimage, numr );
18505
18506 Frngs(cimage, numr);
18507 // compare with all reference images
18508 // for iref in xrange(len(crefim)):
18509 for ( iref = 0; iref < (int)crefim_len; iref++) {
18510 Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max);
18511 double qn = retvals["qn"];
18512 double qm = retvals["qm"];
18513 if(qn >= peak || qm >= peak) {
18514 sx = -ix;
18515 sy = -iy;
18516 nref = iref;
18517 if (qn >= qm) {
18518 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18519 peak = static_cast<float>(qn);
18520 mirror = 0;
18521 } else {
18522 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
18523 peak = static_cast<float>(qm);
18524 mirror = 1;
18525 }
18526 }
18527 }
18528 delete cimage; cimage = 0;
18529 }
18530 }
18531 }
18532 float co, so, sxs, sys;
18533 co = static_cast<float>( cos(ang*pi/180.0) );
18534 so = static_cast<float>( -sin(ang*pi/180.0) );
18535 sxs = sx*co - sy*so;
18536 sys = sx*so + sy*co;
18537 vector<float> res;
18538 res.push_back(ang);
18539 res.push_back(sxs);
18540 res.push_back(sys);
18541 res.push_back(static_cast<float>(mirror));
18542 res.push_back(static_cast<float>(nref));
18543 res.push_back(peak);
18544 return res;
18545 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Definition at line 18704 of file util_sparx.cpp. References ang_n(), Crosrng_psi_0_180_no_mirror(), Frngs(), Normalize_ring(), numr, pi, Polar2Dm(), and EMAN::Dict::size(). 18706 {
18707
18708 size_t crefim_len = crefim.size();
18709
18710 int iref, nref=0, mirror=0;
18711 float iy, ix, sx=0, sy=0;
18712 float peak = -1.0E23f;
18713 float ang=0.0f;
18714 int kx = int(2*xrng/step+0.5)/2;
18715 //if ynumber==-1, use the old code which process x and y direction equally.
18716 if(ynumber==-1) {
18717 int ky = int(2*yrng/step+0.5)/2;
18718 for (int i = -ky; i <= ky; i++) {
18719 iy = i * step ;
18720 for (int j = -kx; j <= kx; j++) {
18721 ix = j*step ;
18722 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18723
18724 Normalize_ring( cimage, numr );
18725
18726 Frngs(cimage, numr);
18727 // compare with all reference images
18728 // for iref in xrange(len(crefim)):
18729 for ( iref = 0; iref < (int)crefim_len; iref++) {
18730 Dict retvals = Crosrng_psi_0_180_no_mirror(crefim[iref], cimage, numr, psi_max);
18731 double qn = retvals["qn"];
18732 if( qn >= peak) {
18733 sx = -ix;
18734 sy = -iy;
18735 nref = iref;
18736 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18737 peak = static_cast<float>(qn);
18738 mirror = 0;
18739 }
18740 }
18741 delete cimage; cimage = 0;
18742 }
18743 }
18744 }
18745 //if ynumber is given, it should be even. We need to check whether it is zero
18746 else if(ynumber==0) {
18747 sy = 0.0f;
18748 for (int j = -kx; j <= kx; j++) {
18749 ix = j*step ;
18750 iy = 0.0f ;
18751 EMData* cimage = Polar2Dm(image, cnx+ix, cny, numr, mode);
18752
18753 Normalize_ring( cimage, numr );
18754
18755 Frngs(cimage, numr);
18756 // compare with all reference images
18757 // for iref in xrange(len(crefim)):
18758 for ( iref = 0; iref < (int)crefim_len; iref++) {
18759 Dict retvals = Crosrng_psi_0_180_no_mirror(crefim[iref], cimage, numr, psi_max);
18760 double qn = retvals["qn"];
18761 if( qn >= peak ) {
18762 sx = -ix;
18763 nref = iref;
18764 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18765 peak = static_cast<float>(qn);
18766 mirror = 0;
18767 }
18768 }
18769 delete cimage; cimage = 0;
18770 }
18771 } else {
18772 int ky = int(ynumber/2);
18773 float stepy=2*yrng/ynumber;
18774 //std::cout<<"yrng="<<yrng<<"ynumber="<<ynumber<<"stepy=="<<stepy<<"stepx=="<<step<<std::endl;
18775 for (int i = -ky+1; i <= ky; i++) {
18776 iy = i * stepy ;
18777 for (int j = -kx; j <= kx; j++) {
18778 ix = j*step ;
18779 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18780
18781 Normalize_ring( cimage, numr );
18782
18783 Frngs(cimage, numr);
18784 // compare with all reference images
18785 // for iref in xrange(len(crefim)):
18786 for ( iref = 0; iref < (int)crefim_len; iref++) {
18787 Dict retvals = Crosrng_psi_0_180_no_mirror(crefim[iref], cimage, numr, psi_max);
18788 double qn = retvals["qn"];
18789 if( qn >= peak) {
18790 sx = -ix;
18791 sy = -iy;
18792 nref = iref;
18793 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18794 peak = static_cast<float>(qn);
18795 mirror = 0;
18796 }
18797 }
18798 delete cimage; cimage = 0;
18799 }
18800 }
18801 }
18802 float co, so, sxs, sys;
18803 co = static_cast<float>( cos(ang*pi/180.0) );
18804 so = static_cast<float>( -sin(ang*pi/180.0) );
18805 sxs = sx*co - sy*so;
18806 sys = sx*so + sy*co;
18807 vector<float> res;
18808 res.push_back(ang);
18809 res.push_back(sxs);
18810 res.push_back(sys);
18811 res.push_back(static_cast<float>(mirror));
18812 res.push_back(static_cast<float>(nref));
18813 res.push_back(peak);
18814 return res;
18815 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Definition at line 18819 of file util_sparx.cpp. References ang_n(), Crosrng_psi_0_180_no_mirror(), Frngs(), EMAN::EMData::get_attr(), EMAN::Transform::get_params(), Normalize_ring(), numr, phi, pi, Polar2Dm(), EMAN::Dict::size(), t, and theta. 18821 {
18822
18823 size_t crefim_len = crefim.size();
18824 const float qv = static_cast<float>( pi/180.0 );
18825 Transform * t = image->get_attr("xform.projection");
18826 Dict d = t->get_params("spider");
18827 if(t) {delete t; t=0;}
18828 float phi = d["phi"];
18829 float theta = d["theta"];
18830 float imn1 = sin(theta*qv)*cos(phi*qv);
18831 float imn2 = sin(theta*qv)*sin(phi*qv);
18832 float imn3 = cos(theta*qv);
18833 vector<float> n1(crefim_len);
18834 vector<float> n2(crefim_len);
18835 vector<float> n3(crefim_len);
18836 int iref, nref=-1, mirror=0;
18837 float iy, ix, sx=0, sy=0;
18838 float peak = -1.0E23f;
18839 float ang=0.0f;
18840 int kx = int(2*xrng/step+0.5)/2;
18841
18842 for ( iref = 0; iref < (int)crefim_len; iref++) {
18843 n1[iref] = crefim[iref]->get_attr("n1");
18844 n2[iref] = crefim[iref]->get_attr("n2");
18845 n3[iref] = crefim[iref]->get_attr("n3");
18846 }
18847
18848 //if ynumber==-1, use the old code which process x and y direction equally.
18849 if(ynumber==-1) {
18850 int ky = int(2*yrng/step+0.5)/2;
18851 for (int i = -ky; i <= ky; i++) {
18852 iy = i * step ;
18853 for (int j = -kx; j <= kx; j++) {
18854 ix = j*step ;
18855 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18856
18857 Normalize_ring( cimage, numr );
18858
18859 Frngs(cimage, numr);
18860 // compare with all reference images
18861 // for iref in xrange(len(crefim)):
18862 for ( iref = 0; iref < (int)crefim_len; iref++) {
18863 if(fabs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) {
18864 Dict retvals = Crosrng_psi_0_180_no_mirror(crefim[iref], cimage, numr, psi_max);
18865 double qn = retvals["qn"];
18866 if( qn >= peak) {
18867 sx = -ix;
18868 sy = -iy;
18869 nref = iref;
18870 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18871 peak = static_cast<float>(qn);
18872 mirror = 0;
18873 }
18874 }
18875 }
18876 delete cimage; cimage = 0;
18877 }
18878 }
18879 }
18880 //if ynumber is given, it should be even. We need to check whether it is zero
18881 else if(ynumber==0) {
18882 sy = 0.0f;
18883 for (int j = -kx; j <= kx; j++) {
18884 ix = j*step ;
18885 iy = 0.0f ;
18886 EMData* cimage = Polar2Dm(image, cnx+ix, cny, numr, mode);
18887
18888 Normalize_ring( cimage, numr );
18889
18890 Frngs(cimage, numr);
18891 // compare with all reference images
18892 // for iref in xrange(len(crefim)):
18893 for ( iref = 0; iref < (int)crefim_len; iref++) {
18894 if(fabs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) {
18895 Dict retvals = Crosrng_psi_0_180_no_mirror(crefim[iref], cimage, numr, psi_max);
18896 double qn = retvals["qn"];
18897 if( qn >= peak ) {
18898 sx = -ix;
18899 nref = iref;
18900 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18901 peak = static_cast<float>(qn);
18902 mirror = 0;
18903 }
18904 }
18905 }
18906 delete cimage; cimage = 0;
18907 }
18908 } else {
18909 int ky = int(ynumber/2);
18910 float stepy=2*yrng/ynumber;
18911 //std::cout<<"yrng="<<yrng<<"ynumber="<<ynumber<<"stepy=="<<stepy<<"stepx=="<<step<<std::endl;
18912 for (int i = -ky+1; i <= ky; i++) {
18913 iy = i * stepy ;
18914 for (int j = -kx; j <= kx; j++) {
18915 ix = j*step ;
18916 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18917
18918 Normalize_ring( cimage, numr );
18919
18920 Frngs(cimage, numr);
18921 // compare with all reference images
18922 // for iref in xrange(len(crefim)):
18923 for ( iref = 0; iref < (int)crefim_len; iref++) {
18924 if(fabs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) {
18925 Dict retvals = Crosrng_psi_0_180_no_mirror(crefim[iref], cimage, numr, psi_max);
18926 double qn = retvals["qn"];
18927 if( qn >= peak) {
18928 sx = -ix;
18929 sy = -iy;
18930 nref = iref;
18931 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18932 peak = static_cast<float>(qn);
18933 mirror = 0;
18934 }
18935 }
18936 }
18937 delete cimage; cimage = 0;
18938 }
18939 }
18940 }
18941 float co, so, sxs, sys;
18942 co = static_cast<float>( cos(ang*pi/180.0) );
18943 so = static_cast<float>( -sin(ang*pi/180.0) );
18944 sxs = sx*co - sy*so;
18945 sys = sx*so + sy*co;
18946 vector<float> res;
18947 res.push_back(ang);
18948 res.push_back(sxs);
18949 res.push_back(sys);
18950 res.push_back(static_cast<float>(mirror));
18951 res.push_back(static_cast<float>(nref));
18952 res.push_back(peak);
18953 return res;
18954 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Definition at line 18547 of file util_sparx.cpp. References ang_n(), Crosrng_psi_0_180(), Frngs(), EMAN::EMData::get_attr(), EMAN::Transform::get_params(), Normalize_ring(), numr, phi, pi, Polar2Dm(), EMAN::Dict::size(), t, and theta. 18549 {
18550
18551 size_t crefim_len = crefim.size();
18552
18553 int iref, nref=-1, mirror=0;
18554 float iy, ix, sx=0, sy=0;
18555 float peak = -1.0E23f;
18556 float ang=0.0f;
18557 const float qv = static_cast<float>( pi/180.0 );
18558 Transform * t = image->get_attr("xform.projection");
18559 Dict d = t->get_params("spider");
18560 if(t) {delete t; t=0;}
18561 float phi = d["phi"];
18562 float theta = d["theta"];
18563 float imn1 = sin(theta*qv)*cos(phi*qv);
18564 float imn2 = sin(theta*qv)*sin(phi*qv);
18565 float imn3 = cos(theta*qv);
18566 vector<float> n1(crefim_len);
18567 vector<float> n2(crefim_len);
18568 vector<float> n3(crefim_len);
18569 for ( iref = 0; iref < (int)crefim_len; iref++) {
18570 n1[iref] = crefim[iref]->get_attr("n1");
18571 n2[iref] = crefim[iref]->get_attr("n2");
18572 n3[iref] = crefim[iref]->get_attr("n3");
18573 }
18574
18575 int kx = int(2*xrng/step+0.5)/2;
18576 //if ynumber==-1, use the old code which process x and y direction equally.
18577 if(ynumber==-1) {
18578 int ky = int(2*yrng/step+0.5)/2;
18579 for (int i = -ky; i <= ky; i++) {
18580 iy = i * step ;
18581 for (int j = -kx; j <= kx; j++) {
18582 ix = j*step ;
18583 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18584
18585 Normalize_ring( cimage, numr );
18586
18587 Frngs(cimage, numr);
18588 // compare with all reference images
18589 // for iref in xrange(len(crefim)):
18590 for ( iref = 0; iref < (int)crefim_len; iref++) {
18591 if(fabs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) {
18592 Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max);
18593 double qn = retvals["qn"];
18594 double qm = retvals["qm"];
18595 if(qn >= peak || qm >= peak) {
18596 sx = -ix;
18597 sy = -iy;
18598 nref = iref;
18599 if (qn >= qm) {
18600 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18601 peak = static_cast<float>(qn);
18602 mirror = 0;
18603 } else {
18604 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
18605 peak = static_cast<float>(qm);
18606 mirror = 1;
18607 }
18608 }
18609 }
18610 }
18611 delete cimage; cimage = 0;
18612 }
18613 }
18614 }
18615 //if ynumber is given, it should be even. We need to check whether it is zero
18616 else if(ynumber==0) {
18617 sy = 0.0f;
18618 for (int j = -kx; j <= kx; j++) {
18619 ix = j*step ;
18620 EMData* cimage = Polar2Dm(image, cnx+ix, cny, numr, mode);
18621
18622 Normalize_ring( cimage, numr );
18623
18624 Frngs(cimage, numr);
18625 // compare with all reference images
18626 // for iref in xrange(len(crefim)):
18627 for ( iref = 0; iref < (int)crefim_len; iref++) {
18628 if(fabs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) {
18629 Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max);
18630 double qn = retvals["qn"];
18631 double qm = retvals["qm"];
18632 if(qn >= peak || qm >= peak) {
18633 sx = -ix;
18634 nref = iref;
18635 if (qn >= qm) {
18636 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18637 peak = static_cast<float>(qn);
18638 mirror = 0;
18639 } else {
18640 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
18641 peak = static_cast<float>(qm);
18642 mirror = 1;
18643 }
18644 }
18645 }
18646 }
18647 delete cimage; cimage = 0;
18648 }
18649 } else {
18650 int ky = int(ynumber/2);
18651 float stepy=2*yrng/ynumber;
18652 //std::cout<<"yrng="<<yrng<<"ynumber="<<ynumber<<"stepy=="<<stepy<<"stepx=="<<step<<std::endl;
18653 for (int i = -ky+1; i <= ky; i++) {
18654 iy = i * stepy ;
18655 for (int j = -kx; j <= kx; j++) {
18656 ix = j*step ;
18657 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18658
18659 Normalize_ring( cimage, numr );
18660
18661 Frngs(cimage, numr);
18662 // compare with all reference images
18663 // for iref in xrange(len(crefim)):
18664 for ( iref = 0; iref < (int)crefim_len; iref++) {
18665 if(fabs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) {
18666 Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max);
18667 double qn = retvals["qn"];
18668 double qm = retvals["qm"];
18669 if(qn >= peak || qm >= peak) {
18670 sx = -ix;
18671 sy = -iy;
18672 nref = iref;
18673 if (qn >= qm) {
18674 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18675 peak = static_cast<float>(qn);
18676 mirror = 0;
18677 } else {
18678 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
18679 peak = static_cast<float>(qm);
18680 mirror = 1;
18681 }
18682 }
18683 }
18684 }
18685 delete cimage; cimage = 0;
18686 }
18687 }
18688 }
18689 float co, so, sxs, sys;
18690 co = static_cast<float>( cos(ang*pi/180.0) );
18691 so = static_cast<float>( -sin(ang*pi/180.0) );
18692 sxs = sx*co - sy*so;
18693 sys = sx*so + sy*co;
18694 vector<float> res;
18695 res.push_back(ang);
18696 res.push_back(sxs);
18697 res.push_back(sys);
18698 res.push_back(static_cast<float>(mirror));
18699 res.push_back(static_cast<float>(nref));
18700 res.push_back(peak);
18701 return res;
18702 }
|
|
|
Definition at line 1042 of file util.h. Referenced by cml_line_insino(), and cml_line_insino_all(). |
|
||||||||||||
|
Definition at line 17866 of file util_sparx.cpp. References data, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), nn(), numr, sqrt(), and EMAN::EMData::update(). Referenced by multiref_polar_ali_2d(), multiref_polar_ali_2d_delta(), multiref_polar_ali_2d_local(), multiref_polar_ali_2d_local_psi(), multiref_polar_ali_2d_peaklist(), multiref_polar_ali_helical(), multiref_polar_ali_helical_90(), multiref_polar_ali_helical_90_local(), and multiref_polar_ali_helical_local(). 17867 {
17868 float* data = ring->get_data();
17869 float av=0.0;
17870 float sq=0.0;
17871 float nn=0.0;
17872 int nring = numr.size()/3;
17873 for( int i=0; i < nring; ++i )
17874 {
17875 int numr3i = numr[3*i+2];
17876 int numr2i = numr[3*i+1]-1;
17877 float w = numr[3*i]*2*M_PI/float(numr[3*i+2]);
17878 for( int j=0; j < numr3i; ++j )
17879 {
17880 int jc = numr2i+j;
17881 av += data[jc] * w;
17882 sq += data[jc] * data[jc] * w;
17883 nn += w;
17884 }
17885 }
17886
17887 float avg = av/nn;
17888 float sgm = sqrt( (sq-av*av/nn)/nn );
17889 size_t n = (size_t)ring->get_xsize() * ring->get_ysize() * ring->get_zsize();
17890 for( size_t i=0; i < n; ++i )
17891 {
17892 data[i] -= avg;
17893 data[i] /= sgm;
17894 }
17895
17896 ring->update();
17897 }
|
|
|
Definition at line 17776 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, EMAN::EMData::is_fftodd(), NullPointerException, nx, ny, power(), EMAN::EMData::set_array_offsets(), EMAN::EMData::set_size(), and EMAN::EMData::update(). 17777 {
17778 ENTERFUNC;
17779 /* Exception Handle */
17780 if (!img) {
17781 throw NullPointerException("NULL input image");
17782 }
17783 /* ============== img is modulus of a complex image in FFT format (so its imaginary parts are zero),
17784 output is img packed into real image with Friedel part added, ================ */
17785
17786 int nxo=img->get_xsize(), ny=img->get_ysize(), nz=img->get_zsize();
17787 int nx = nxo - 2 + img->is_fftodd();
17788 int lsd2 = (nx + 2 - nx%2) / 2; // Extended x-dimension of the complex image
17789 int nyt, nzt;
17790 int nx2 = nx/2;
17791 int ny2 = ny/2; if(ny2 == 0) nyt =0; else nyt=ny;
17792 int nz2 = nz/2; if(nz2 == 0) nzt =0; else nzt=nz;
17793 int nx2p = nx2+nx%2;
17794 int ny2p = ny2+ny%2;
17795 int nz2p = nz2+nz%2;
17796 EMData& power = *(new EMData()); // output image
17797 power.set_size(nx, ny, nz);
17798 power.set_array_offsets(-nx2,-ny2,-nz2);
17799 //img->set_array_offsets(1,1,1);
17800 float *img_ptr = img->get_data();
17801 for (int iz = 1; iz <= nz; iz++) {
17802 int jz=iz-1;
17803 if(jz>=nz2p) jz=jz-nzt;
17804 for (int iy = 1; iy <= ny; iy++) {
17805 int jy=iy-1;
17806 if(jy>=ny2p) jy=jy-nyt;
17807 for (int ix = 1; ix <= lsd2; ix++) {
17808 int jx=ix-1;
17809 if(jx>=nx2p) jx=jx-nx;
17810 power(jx,jy,jz) = img_ptr(ix,iy,iz); //real(img->cmplx(ix,iy,iz));
17811 }
17812 }
17813 }
17814 // Create the Friedel related half
17815 int nzb, nze, nyb, nye, nxb, nxe;
17816 nxb =-nx2+(nx+1)%2;
17817 nxe = nx2-(nx+1)%2;
17818 if(ny2 == 0) {nyb =0; nye = 0;} else {nyb =-ny2+(ny+1)%2; nye = ny2-(ny+1)%2;}
17819 if(nz2 == 0) {nzb =0; nze = 0;} else {nzb =-nz2+(nz+1)%2; nze = nz2-(nz+1)%2;}
17820 for (int iz = nzb; iz <= nze; iz++) {
17821 for (int iy = nyb; iy <= nye; iy++) {
17822 for (int ix = 1; ix <= nxe; ix++) { // Note this loop begins with 1 - FFT should create correct Friedel related 0 plane
17823 power(-ix,-iy,-iz) = power(ix,iy,iz);
17824 }
17825 }
17826 }
17827 if(ny2 != 0) {
17828 if(nz2 != 0) {
17829 if(nz%2 == 0) { //if nz even, fix the first slice
17830 for (int iy = nyb; iy <= nye; iy++) {
17831 for (int ix = nxb; ix <= -1; ix++) {
17832 power(ix,iy,-nz2) = power(-ix,-iy,-nz2);
17833 }
17834 }
17835 if(ny%2 == 0) { //if ny even, fix the first line
17836 for (int ix = nxb; ix <= -1; ix++) {
17837 power(ix,-ny2,-nz2) = power(-ix,-ny2,-nz2);
17838 }
17839 }
17840 }
17841 }
17842 if(ny%2 == 0) { //if ny even, fix the first column
17843 for (int iz = nzb; iz <= nze; iz++) {
17844 for (int ix = nxb; ix <= -1; ix++) {
17845 power(ix,-ny2,-iz) = power(-ix,-ny2,iz);
17846 }
17847 }
17848 }
17849
17850 }
17851 power.update();
17852 power.set_array_offsets(0,0,0);
17853 return &power;
17854 }
|
|
||||||||||||||||||||||||||||||||||||
|
Definition at line 5382 of file util_sparx.cpp. References EMAN::EMData::copy_head(), EMAN::EMObject::f, EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, inp, NullPointerException, nx, ny, outp, EMAN::EMData::set_size(), and EMAN::EMData::update(). 05383 {
05384 /* Exception Handle */
05385 if (!img) throw NullPointerException("NULL input image");
05386 /* ============================== */
05387
05388 // Get the size of the input image
05389 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
05390 /* ============================== */
05391
05392 /* Exception Handle */
05393 if(new_nx<nx || new_ny<ny || new_nz<nz)
05394 throw ImageDimensionException("The size of the padded image cannot be lower than the input image size.");
05395 if((new_nx/2)-(nx/2)+x_offset<0 || (new_ny/2)-(ny/2)+y_offset<0 || (new_nz/2)-(nz/2)+z_offset<0)
05396 throw ImageDimensionException("The offset imconsistent with the input image size. Solution: Change the offset parameters");
05397 if(x_offset>((new_nx-(new_nx/2))-(nx-(nx/2))) || y_offset>((new_ny-(new_ny/2))-(ny-(ny/2))) || z_offset>((new_nz-(new_nz/2))-(nz-(nz/2))))
05398 throw ImageDimensionException("The offset imconsistent with the input image size. Solution: Change the offset parameters");
05399 /* ============================== */
05400
05401 EMData* pading = img->copy_head();
05402 pading->set_size(new_nx, new_ny, new_nz);
05403 float *inp = img->get_data();
05404 float *outp = pading->get_data();
05405
05406
05407 /* Calculation of the average and the circumference values for background substitution
05408 =======================================================================================*/
05409 float background;
05410
05411 if (strcmp(params,"average")==0) background = img->get_attr("mean");
05412 else if (strcmp(params,"circumference")==0) {
05413 float sum1=0.0f;
05414 size_t cnt=0;
05415 for(int i=0;i<nx;i++) {
05416 sum1 += inp(i,0,0) + inp(i,ny-1,nz-1);
05417 cnt+=2;
05418 }
05419 if(nz-1 == 0) {
05420 for (int j=1;j<ny-1;j++) {
05421 sum1 += inp(1,j,0) + inp(nx-1,j,0);
05422 cnt+=2;
05423 }
05424 } else {
05425 for (int k=1;k<nz-1;k++) {
05426 for (int j=1;j<ny-1;j++) {
05427 sum1 += inp(1,j,0) + inp(nx-1,j,0);
05428 cnt+=2;
05429 }
05430 }
05431 }
05432 background = sum1/cnt;
05433 } else {
05434 background = static_cast<float>( atof( params ) );
05435 }
05436 /*=====================================================================================*/
05437
05438 /*Initial Padding */
05439 int new_st_x=0,new_st_y=0,new_st_z=0;
05440 for (int k=0;k<new_nz;k++)
05441 for(int j=0;j<new_ny;j++)
05442 for (int i=0;i<new_nx;i++)
05443 outp(i,j,k)=background;
05444 /*============================== */
05445
05446 /* Calculation of the start point */
05447 new_st_x=int((new_nx/2-nx/2) + x_offset);
05448 new_st_y=int((new_ny/2-ny/2) + y_offset);
05449 new_st_z=int((new_nz/2-nz/2) + z_offset);
05450 /* ============================== */
05451
05452 for (int k=0;k<nz;k++)
05453 for(int j=0;j<ny;j++)
05454 for(int i=0;i<nx;i++)
05455 outp(i,j,k)=inp(i,j,k);
05456 pading->update();
05457 return pading;
05458 }
|
|
||||||||||||||||||||||||
|
Determines if a point is in a 2D convex polygon described by 4 points using the Barycentric method, which is a fast way of performing the query. The points must be ordered in the way you would encounter them if you traversed the boundary of the polygon. Direction is irrelevant. Could be generalized for polygons with more points
Definition at line 1269 of file util.cpp. References point_is_in_triangle_2d(), and EMAN::Vec2f. 01270 {
01271
01272 if (point_is_in_triangle_2d(p1,p2,p4,actual_point)) return true;
01273 else return point_is_in_triangle_2d(p3,p2,p4,actual_point);
01274 }
|
|
||||||||||||||||||||
|
Determines if a point is in a 2D triangle using the Barycentric method, which is a fast way of performing the query Triangle points can be specified in any order.
Definition at line 1234 of file util.cpp. References EMAN::Vec2< Type >::dot(), t, v, and EMAN::Vec2f. Referenced by point_is_in_convex_polygon_2d(). 01235 {
01236
01237 Vec2f u = p2 - p1;
01238 Vec2f v = p3 - p1;
01239 Vec2f w = point - p1;
01240
01241 float udotu = u.dot(u);
01242 float udotv = u.dot(v);
01243 float udotw = u.dot(w);
01244 float vdotv = v.dot(v);
01245 float vdotw = v.dot(w);
01246
01247 float d = 1.0f/(udotv*udotv - udotu*vdotv);
01248 float s = udotv*vdotw - vdotv*udotw;
01249 s *= d;
01250
01251 float t = udotv*udotw - udotu*vdotw;
01252 t *= d;
01253
01254 // We've done a few multiplications, so detect when there are tiny residuals that may throw off the final
01255 // decision
01256 if (fabs(s) < Transform::ERR_LIMIT ) s = 0;
01257 if (fabs(t) < Transform::ERR_LIMIT ) t = 0;
01258
01259 if ( fabs((fabs(s)-1.0)) < Transform::ERR_LIMIT ) s = 1;
01260 if ( fabs((fabs(t)-1.0)) < Transform::ERR_LIMIT ) t = 1;
01261
01262 // cout << "s and t are " << s << " " << t << endl;
01263
01264 // The final decision, if this is true then we've hit the jackpot
01265 if ( s >= 0 && t >= 0 && (s+t) <= 1 ) return true;
01266 else return false;
01267 }
|
|
||||||||||||||||
|
Definition at line 2136 of file util_sparx.cpp. References circ, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), numr, quadri(), EMAN::EMData::set_size(), x, xim, and y. 02136 {
02137 int nsam = image->get_xsize();
02138 int nrow = image->get_ysize();
02139 int nring = numr.size()/3;
02140 int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
02141 EMData* out = new EMData();
02142 out->set_size(lcirc,1,1);
02143 char mode = (cmode == "F" || cmode == "f") ? 'f' : 'h';
02144 float *xim = image->get_data();
02145 float *circ = out->get_data();
02146 /* alrq(image->get_data(), nsam, nrow, &numr[0], out->get_data(), lcirc, nring, cmode);
02147 return out;
02148 }
02149 void Util::alrq(float *xim, int nsam , int nrow , int *numr,
02150 float *circ, int lcirc, int nring, char mode)
02151 {*/
02152 /*
02153 c
02154 c purpose:
02155 c
02156 c resmaple to polar coordinates
02157 c
02158 */
02159 // dimension xim(nsam,nrow),circ(lcirc)
02160 // integer numr(3,nring)
02161
02162 double dfi, dpi;
02163 int ns2, nr2, i, inr, l, nsim, kcirc, lt, j;
02164 float yq, xold, yold, fi, x, y;
02165
02166 ns2 = nsam/2+1;
02167 nr2 = nrow/2+1;
02168 dpi = 2.0*atan(1.0);
02169
02170 for (i=1;i<=nring;i++) {
02171 // radius of the ring
02172 inr = numr(1,i);
02173 yq = static_cast<float>(inr);
02174 l = numr(3,i);
02175 if (mode == 'h' || mode == 'H') lt = l/2;
02176 else lt = l/4;
02177
02178 nsim = lt-1;
02179 dfi = dpi/(nsim+1);
02180 kcirc = numr(2,i);
02181 xold = 0.0f;
02182 yold = static_cast<float>(inr);
02183 circ(kcirc) = quadri(xold+(float)ns2,yold+(float)nr2,nsam,nrow,xim);
02184 xold = static_cast<float>(inr);
02185 yold = 0.0f;
02186 circ(lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim);
02187
02188 if (mode == 'f' || mode == 'F') {
02189 xold = 0.0f;
02190 yold = static_cast<float>(-inr);
02191 circ(lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim);
02192 xold = static_cast<float>(-inr);
02193 yold = 0.0f;
02194 circ(lt+lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim);
02195 }
02196
02197 for (j=1;j<=nsim;j++) {
02198 fi = static_cast<float>(dfi*j);
02199 x = sin(fi)*yq;
02200 y = cos(fi)*yq;
02201 xold = x;
02202 yold = y;
02203 circ(j+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim);
02204 xold = y;
02205 yold = -x;
02206 circ(j+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim);
02207
02208 if (mode == 'f' || mode == 'F') {
02209 xold = -x;
02210 yold = -y;
02211 circ(j+lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim);
02212 xold = -y;
02213 yold = x;
02214 circ(j+lt+lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim);
02215 }
02216 }
02217 }
02218 return out;
02219 }
|
|
||||||||||||||||||||||||
|
Definition at line 2221 of file util_sparx.cpp. References Assert, circ, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), numr, quadri(), EMAN::EMData::set_size(), x, xim, and y. Referenced by ali2d_ccf_list(), multiref_peaks_ali2d(), multiref_peaks_compress_ali2d(), multiref_polar_ali_2d(), multiref_polar_ali_2d_delta(), multiref_polar_ali_2d_local(), multiref_polar_ali_2d_local_psi(), multiref_polar_ali_2d_nom(), multiref_polar_ali_2d_peaklist(), multiref_polar_ali_helical(), multiref_polar_ali_helical_90(), multiref_polar_ali_helical_90_local(), and multiref_polar_ali_helical_local(). 02221 {
02222 int nsam = image->get_xsize();
02223 int nrow = image->get_ysize();
02224 int nring = numr.size()/3;
02225 int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
02226 EMData* out = new EMData();
02227 out->set_size(lcirc,1,1);
02228 char mode = (cmode == "F" || cmode == "f") ? 'f' : 'h';
02229 float *xim = image->get_data();
02230 float *circ = out->get_data();
02231 double dpi, dfi;
02232 int it, jt, inr, l, nsim, kcirc, lt;
02233 float xold, yold, fi, x, y;
02234
02235 // cns2 and cnr2 are predefined centers
02236 // no need to set to zero, all elements are defined
02237 dpi = 2*atan(1.0);
02238 for (it=1; it<=nring; it++) {
02239 // radius of the ring
02240 inr = numr(1,it);
02241
02242 // "F" means a full circle interpolation
02243 // "H" means a half circle interpolation
02244
02245 l = numr(3,it);
02246 if ( mode == 'h' || mode == 'H' ) lt = l / 2;
02247 else lt = l / 4;
02248
02249 nsim = lt - 1;
02250 dfi = dpi / (nsim+1);
02251 kcirc = numr(2,it);
02252 xold = 0.0f+cns2;
02253 yold = inr+cnr2;
02254
02255 Assert( kcirc <= lcirc );
02256 circ(kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on 90 degree
02257
02258 xold = inr+cns2;
02259 yold = 0.0f+cnr2;
02260 Assert( lt+kcirc <= lcirc );
02261 circ(lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on 0 degree
02262
02263 if ( mode == 'f' || mode == 'F' ) {
02264 xold = 0.0f+cns2;
02265 yold = -inr+cnr2;
02266 Assert( lt+lt+kcirc <= lcirc );
02267 circ(lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on 270 degree
02268
02269 xold = -inr+cns2;
02270 yold = 0.0f+cnr2;
02271 Assert(lt+lt+lt+kcirc <= lcirc );
02272 circ(lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on 180 degree
02273 }
02274
02275 for (jt=1; jt<=nsim; jt++) {
02276 fi = static_cast<float>(dfi * jt);
02277 x = sin(fi) * inr;
02278 y = cos(fi) * inr;
02279
02280 xold = x+cns2;
02281 yold = y+cnr2;
02282
02283 Assert( jt+kcirc <= lcirc );
02284 circ(jt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on the first quadrant
02285
02286 xold = y+cns2;
02287 yold = -x+cnr2;
02288
02289 Assert( jt+lt+kcirc <= lcirc );
02290 circ(jt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on the fourth quadrant
02291
02292 if ( mode == 'f' || mode == 'F' ) {
02293 xold = -x+cns2;
02294 yold = -y+cnr2;
02295
02296 Assert( jt+lt+lt+kcirc <= lcirc );
02297 circ(jt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on the third quadrant
02298
02299 xold = -y+cns2;
02300 yold = x+cnr2;
02301
02302 Assert( jt+lt+lt+lt+kcirc <= lcirc );
02303 circ(jt+lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on the second quadrant
02304 }
02305 } // end for jt
02306 } //end for it
02307 return out;
02308 }
|
|
||||||||||||||||||||||||||||
|
Definition at line 2504 of file util_sparx.cpp. References circ, EMAN::EMData::get_data(), get_pixel_conv_new(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), numr, nx, ny, EMAN::EMData::set_size(), x, and y. 02504 {
02505 // input image is twice the size of the original image
02506 int nring = numr.size()/3;
02507 int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
02508 EMData* out = new EMData();
02509 out->set_size(lcirc,1,1);
02510 char mode = (cmode == "F" || cmode == "f") ? 'f' : 'h';
02511 float *circ = out->get_data();
02512 float *fimage = image->get_data();
02513 int nx = image->get_xsize();
02514 int ny = image->get_ysize();
02515 int nz = image->get_zsize();
02516 double dpi, dfi;
02517 int it, jt, inr, l, nsim, kcirc, lt;
02518 float yq, xold, yold, fi, x, y;
02519
02520 // cns2 and cnr2 are predefined centers
02521 // no need to set to zero, all elements are defined
02522
02523 dpi = 2*atan(1.0);
02524 for (it=1;it<=nring;it++) {
02525 // radius of the ring
02526 inr = numr(1,it);
02527 yq = static_cast<float>(inr);
02528
02529 l = numr(3,it);
02530 if ( mode == 'h' || mode == 'H' ) lt = l / 2;
02531 else lt = l / 4;
02532
02533 nsim = lt - 1;
02534 dfi = dpi / (nsim+1);
02535 kcirc = numr(2,it);
02536 xold = 0.0f;
02537 yold = static_cast<float>(inr);
02538 circ(kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb);
02539 // circ(kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb);
02540
02541 xold = static_cast<float>(inr);
02542 yold = 0.0f;
02543 circ(lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb);
02544 // circ(lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb);
02545
02546 if ( mode == 'f' || mode == 'F' ) {
02547 xold = 0.0f;
02548 yold = static_cast<float>(-inr);
02549 circ(lt+lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb);
02550 // circ(lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb);
02551
02552 xold = static_cast<float>(-inr);
02553 yold = 0.0f;
02554 circ(lt+lt+lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb);
02555 // circ(lt+lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb);
02556 }
02557
02558 for (jt=1;jt<=nsim;jt++) {
02559 fi = static_cast<float>(dfi * jt);
02560 x = sin(fi) * yq;
02561 y = cos(fi) * yq;
02562
02563 xold = x;
02564 yold = y;
02565 circ(jt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb);
02566 // circ(jt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb);
02567
02568 xold = y;
02569 yold = -x;
02570 circ(jt+lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb);
02571 // circ(jt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb);
02572
02573 if ( mode == 'f' || mode == 'F' ) {
02574 xold = -x;
02575 yold = -y;
02576 circ(jt+lt+lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb);
02577 // circ(jt+lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb);
02578
02579 xold = -y;
02580 yold = x;
02581 circ(jt+lt+lt+lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb);
02582 // circ(jt+lt+lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb);
02583 }
02584 } // end for jt
02585 } //end for it
02586 return out;
02587 }
|
|
||||||||||||||||
|
Definition at line 3125 of file util_sparx.cpp. References b. Referenced by Crosrng_e(), Crosrng_ew(), Crosrng_ms(), Crosrng_ns(), Crosrng_psi_0_180(), Crosrng_psi_0_180_no_mirror(), and Crosrng_sm_psi(). 03125 {
03126 double c2,c3;
03127 int nhalf;
03128
03129 nhalf = npoint/2 + 1;
03130 *pos = 0.0;
03131
03132 if (npoint == 7) {
03133 c2 = 49.*b(1) + 6.*b(2) - 21.*b(3) - 32.*b(4) - 27.*b(5)
03134 - 6.*b(6) + 31.*b(7);
03135 c3 = 5.*b(1) - 3.*b(3) - 4.*b(4) - 3.*b(5) + 5.*b(7);
03136 }
03137 else if (npoint == 5) {
03138 c2 = (74.*b(1) - 23.*b(2) - 60.*b(3) - 37.*b(4)
03139 + 46.*b(5) ) / (-70.);
03140 c3 = (2.*b(1) - b(2) - 2.*b(3) - b(4) + 2.*b(5) ) / 14.0;
03141 }
03142 else if (npoint == 3) {
03143 c2 = (5.*b(1) - 8.*b(2) + 3.*b(3) ) / (-2.0);
03144 c3 = (b(1) - 2.*b(2) + b(3) ) / 2.0;
03145 }
03146 //else if (npoint == 9) {
03147 else { // at least one has to be true!!
03148 c2 = (1708.*b(1) + 581.*b(2) - 246.*b(3) - 773.*b(4)
03149 - 1000.*b(5) - 927.*b(6) - 554.*b(7) + 119.*b(8)
03150 + 1092.*b(9) ) / (-4620.);
03151 c3 = (28.*b(1) + 7.*b(2) - 8.*b(3) - 17.*b(4) - 20.*b(5)
03152 - 17.*b(6) - 8.*b(7) + 7.*b(8) + 28.*b(9) ) / 924.0;
03153 }
03154 if (c3 != 0.0) *pos = static_cast<float>(c2/(2.0*c3) - nhalf);
03155 }
|
|
||||||||||||||||
|
Print a 3D integer matrix to a file stream (std out by default).
Definition at line 1118 of file util.cpp. 01118 {
01119 // Note: Don't need to check if 3-D because 3D is part of
01120 // the MIArray3D typedef.
01121 out << "Printing 3D Integer data: " << str << std::endl;
01122 const multi_array_types::size_type* sizes = mat.shape();
01123 int nx = sizes[0], ny = sizes[1], nz = sizes[2];
01124 const multi_array_types::index* indices = mat.index_bases();
01125 int bx = indices[0], by = indices[1], bz = indices[2];
01126 for (int iz = bz; iz < nz+bz; iz++) {
01127 cout << "(z = " << iz << " slice)" << endl;
01128 for (int ix = bx; ix < nx+bx; ix++) {
01129 for (int iy = by; iy < ny+by; iy++) {
01130 cout << setiosflags(ios::fixed) << setw(5)
01131 << mat[ix][iy][iz] << " ";
01132 }
01133 cout << endl;
01134 }
01135 }
01136 }
|
|
||||||||||||||||||||
|
Definition at line 6359 of file util_sparx.cpp. References call_cl1(), log(), q, EMAN::Dict::size(), and x. 06360 {
06361 int k,m,n1,klmd,klm2d,nklmd,n2d,n_larg,l, n2;
06362
06363 k=(int)pw.size();
06364 l=0;
06365 m=k;
06366 n2=n+2;
06367 n1=n+1;
06368 klmd=k+l+m;
06369 klm2d= k+l+m+2;
06370 nklmd=k+l+m+n;
06371 n2d=n+2;
06372 /*size has to be increased when N is large*/
06373 n_larg=klmd*2;
06374 klm2d=n_larg+klm2d;
06375 klmd=n_larg+klmd;
06376 nklmd=n_larg+nklmd;
06377 int size_q=klm2d*n2d;
06378 int size_cu=nklmd*2;
06379 static int i__;
06380
06381 double *q ;
06382 double *x ;
06383 double *res;
06384 double *cu;
06385 float *q2;
06386 float *pw_;
06387 long int *iu;
06388 double *s;
06389 q = (double*)calloc(size_q,sizeof(double));
06390 x = (double*)calloc(n2d,sizeof(double));
06391 res = (double*)calloc(klmd,sizeof(double));
06392 cu =(double*)calloc(size_cu,sizeof(double));
06393 s = (double*)calloc(klmd,sizeof(double));
06394 q2 = (float*)calloc(size_q,sizeof(float));
06395 iu = (long int*)calloc(size_cu,sizeof(long int));
06396 pw_ = (float*)calloc(k,sizeof(float));
06397
06398 for( i__ =0;i__<k;++i__)
06399 {
06400 pw_[i__]=log(pw[i__]); }
06401 long int l_k=k;
06402 long int l_n=n;
06403 long int l_iswi=iswi;
06404 vector<float> cl1_res;
06405 cl1_res=Util::call_cl1(&l_k, &l_n, &ps, &l_iswi, pw_, q2, q, x, res, cu, s, iu);
06406 free(q);
06407 free(x);
06408 free(res);
06409 free(s);
06410 free(cu);
06411 free(q2);
06412 free(iu);
06413 free(pw_);
06414 return cl1_res;
06415 }
|
|
||||||||||||||||||||||||
|
Quadratic interpolation (2D). Note: This routine starts counting from 1, not 0! This routine uses six image points for interpolation:
f3 fc
|
| x
f2-----f0----f1
|
|
f4
*f0 - f4 are image values near the interpolated point X. f0 is the interior mesh point nearest x. Coords:
Definition at line 645 of file util_sparx.cpp. References fdata, quadri(), x, and y. Referenced by alrl_ms(), Polar2D(), and Polar2Dm(). 00646 {
00647 // purpose: quadratic interpolation
00648 // Optimized for speed, circular closer removed, checking of ranges removed
00649 float x, y, dx0, dy0, f0, c1, c2, c3, c4, c5, dxb, dyb;
00650 float quadri;
00651 int i, j, ip1, im1, jp1, jm1, ic, jc, hxc, hyc;
00652
00653 x = xx;
00654 y = yy;
00655
00656 // any xx and yy
00657 while ( x < 1.0 ) x += nxdata;
00658 while ( x >= (float)(nxdata+1) ) x -= nxdata;
00659 while ( y < 1.0 ) y += nydata;
00660 while ( y >= (float)(nydata+1) ) y -= nydata;
00661
00662 i = (int) x;
00663 j = (int) y;
00664
00665 dx0 = x - i;
00666 dy0 = y - j;
00667
00668 ip1 = i + 1;
00669 im1 = i - 1;
00670 jp1 = j + 1;
00671 jm1 = j - 1;
00672
00673 if (ip1 > nxdata) ip1 -= nxdata;
00674 if (im1 < 1) im1 += nxdata;
00675 if (jp1 > nydata) jp1 -= nydata;
00676 if (jm1 < 1) jm1 += nydata;
00677
00678 f0 = fdata(i,j);
00679 c1 = fdata(ip1,j) - f0;
00680 c2 = (c1 - f0 + fdata(im1,j)) * 0.5f;
00681 c3 = fdata(i,jp1) - f0;
00682 c4 = (c3 - f0 + fdata(i,jm1)) * 0.5f;
00683
00684 dxb = dx0 - 1;
00685 dyb = dy0 - 1;
00686
00687 // hxc & hyc are either 1 or -1
00688 if (dx0 >= 0) hxc = 1; else hxc = -1;
00689 if (dy0 >= 0) hyc = 1; else hyc = -1;
00690
00691 ic = i + hxc;
00692 jc = j + hyc;
00693
00694 if (ic > nxdata) ic -= nxdata; else if (ic < 1) ic += nxdata;
00695 if (jc > nydata) jc -= nydata; else if (jc < 1) jc += nydata;
00696
00697 c5 = ( (fdata(ic,jc) - f0 - hxc * c1 - (hxc * (hxc - 1.0f)) * c2
00698 - hyc * c3 - (hyc * (hyc - 1.0f)) * c4) * (hxc * hyc));
00699
00700
00701 quadri = f0 + dx0 * (c1 + dxb * c2 + dy0 * c5) + dy0 * (c3 + dyb * c4);
00702
00703 return quadri;
00704 }
|
|
||||||||||||||||||||||||||||||||
|
Quadratic interpolation (2D). This is identical to quadri except the wrap around is not done circulantly. Note: This routine starts counting from 1, not 0! This routine uses six image points for interpolation:
f3 fc
|
| x
f2-----f0----f1
|
|
f4
*f0 - f4 are image values near the interpolated point X. f0 is the interior mesh point nearest x. Coords:
Definition at line 709 of file util_sparx.cpp. References fdata, quadri(), x, and y. 00710 {
00711 // purpose: quadratic interpolation
00712 // Optimized for speed, circular closer removed, checking of ranges removed
00713 float x, y, dx0, dy0, f0, c1, c2, c3, c4, c5, dxb, dyb;
00714 float quadri;
00715 int i, j, ip1, im1, jp1, jm1, ic, jc, hxc, hyc;
00716
00717 x = xx;
00718 y = yy;
00719
00720 // wrap around is not done circulantly; if (x,y) is not in the image, then x = xnew and y = ynew
00721 if ( (x < 1.0) || ( x >= (float)(nxdata+1) ) || ( y < 1.0 ) || ( y >= (float)(nydata+1) )){
00722 x = (float)xnew;
00723 y = (float)ynew;
00724 }
00725
00726
00727 i = (int) x;
00728 j = (int) y;
00729
00730 dx0 = x - i;
00731 dy0 = y - j;
00732
00733 ip1 = i + 1;
00734 im1 = i - 1;
00735 jp1 = j + 1;
00736 jm1 = j - 1;
00737
00738 if (ip1 > nxdata) ip1 -= nxdata;
00739 if (im1 < 1) im1 += nxdata;
00740 if (jp1 > nydata) jp1 -= nydata;
00741 if (jm1 < 1) jm1 += nydata;
00742
00743 f0 = fdata(i,j);
00744 c1 = fdata(ip1,j) - f0;
00745 c2 = (c1 - f0 + fdata(im1,j)) * 0.5f;
00746 c3 = fdata(i,jp1) - f0;
00747 c4 = (c3 - f0 + fdata(i,jm1)) * 0.5f;
00748
00749 dxb = dx0 - 1;
00750 dyb = dy0 - 1;
00751
00752 // hxc & hyc are either 1 or -1
00753 if (dx0 >= 0) hxc = 1; else hxc = -1;
00754 if (dy0 >= 0) hyc = 1; else hyc = -1;
00755
00756 ic = i + hxc;
00757 jc = j + hyc;
00758
00759 if (ic > nxdata) ic -= nxdata; else if (ic < 1) ic += nxdata;
00760 if (jc > nydata) jc -= nydata; else if (jc < 1) jc += nydata;
00761
00762 c5 = ( (fdata(ic,jc) - f0 - hxc * c1 - (hxc * (hxc - 1.0f)) * c2
00763 - hyc * c3 - (hyc * (hyc - 1.0f)) * c4) * (hxc * hyc));
00764
00765
00766 quadri = f0 + dx0 * (c1 + dxb * c2 + dy0 * c5) + dy0 * (c3 + dyb * c4);
00767
00768 return quadri;
00769 }
|
|
||||||||||||||||||||||||
|
list the sorted lengths of the integer lattice sites of a square sided image of size Size. PRB
Definition at line 433 of file util_sparx.cpp. References sort_mat(). 00435 {
00436 int iMax = (int) floor( (Size-1.0)/2 +.01);
00437 int CountMax = (iMax+2)*(iMax+1)/2;
00438 int Count=-1;
00439 float *kVals = new float[CountMax];
00440 float *weightMat = new float[CountMax];
00441 int *PermMat = new int[CountMax];
00442 SizeReturned[0] = CountMax;
00443
00444 // printf("Aa \n"); fflush(stdout);
00445 for (int jkx=0; jkx< iMax+1; jkx++) {
00446 for (int jky=0; jky< jkx+1; jky++) {
00447 Count++;
00448 kVals[Count] = sqrtf((float) (jkx*jkx +jky*jky));
00449 weightMat[Count]= 1.0;
00450 if (jkx!=0) { weightMat[Count] *=2;}
00451 if (jky!=0) { weightMat[Count] *=2;}
00452 if (jkx!=jky){ weightMat[Count] *=2;}
00453 PermMat[Count]=Count+1;
00454 }
00455 }
00456
00457 int lkVals = Count+1;
00458 // printf("Cc \n");fflush(stdout);
00459
00460 sort_mat(&kVals[0],&kVals[Count],
00461 &PermMat[0], &PermMat[Count]); //PermMat is
00462 //also returned as well as kValsSorted
00463 fflush(stdout);
00464
00465 int newInd;
00466
00467 for (int iP=0; iP < lkVals ; iP++ ) {
00468 newInd = PermMat[iP];
00469 PermMatTr[newInd-1] = iP+1;
00470 }
00471
00472 // printf("Ee \n"); fflush(stdout);
00473
00474 int CountA=-1;
00475 int CountB=-1;
00476
00477 while (CountB< (CountMax-1)) {
00478 CountA++;
00479 CountB++;
00480 // printf("CountA=%d ; CountB=%d \n", CountA,CountB);fflush(stdout);
00481 kValsSorted[CountA] = kVals[CountB] ;
00482 if (CountB<(CountMax-1) ) {
00483 while (fabs(kVals[CountB] -kVals[CountB+1])<.0000001 ) {
00484 SizeReturned[0]--;
00485 for (int iP=0; iP < lkVals; iP++){
00486 // printf("iP=%d \n", iP);fflush(stdout);
00487 if (PermMatTr[iP]>CountA+1) {
00488 PermMatTr[iP]--;
00489 }
00490 }
00491 CountB++;
00492 }
00493 }
00494 }
00495
00496
00497 for (int CountD=0; CountD < CountMax; CountD++) {
00498 newInd = PermMatTr[CountD];
00499 weightofkValsSorted[newInd-1] += weightMat[CountD];
00500 }
00501
00502 }
|
|
||||||||||||
|
Recreates a n-d image using its compressed 1-D form and the mask.
Definition at line 6190 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, img_ptr, new_ptr, nx, ny, EMAN::EMData::set_size(), and EMAN::EMData::update(). 06191 {
06192 /********
06193 ***Exception Handle
06194 *************/
06195 if(mask == NULL)
06196 throw ImageDimensionException("The mask cannot be an null image");
06197
06198 /***********
06199 ***get the size of the mask
06200 **************/
06201 int nx = mask->get_xsize(),ny = mask->get_ysize(),nz = mask->get_zsize();
06202
06203 size_t i,size = (size_t)nx*ny*nz; /* loop counters */
06204 /* new image declaration */
06205 EMData *new_image = new EMData();
06206 new_image->set_size(nx,ny,nz); /* set the size of new image */
06207 float *new_ptr = new_image->get_data(); /* set size of the new image */
06208 float *mask_ptr = mask->get_data(); /* assign a pointer to the mask image */
06209 float *img_ptr = image->get_data(); /* assign a pointer to the 1D image */
06210 int count = 0;
06211 float sum_under_mask = 0.0 ;
06212 for(i = 0;i < size;i++){
06213 if(mask_ptr[i] > 0.5f){
06214 new_ptr[i] = img_ptr[count];
06215 sum_under_mask += img_ptr[count];
06216 count++;
06217 if( count > image->get_xsize() ) {
06218 throw ImageDimensionException("Error: in reconstitute_image_mask, the mask doesn't match the image, it is too large");
06219 }
06220 }
06221 }
06222
06223 if( count > image->get_xsize() ) {
06224 throw ImageDimensionException("Error: in reconstitute_image_mask, the mask doesn't match the image, it is too small");
06225 }
06226
06227 float avg_under_mask = sum_under_mask / count;
06228 for(i = 0;i < size;i++) {
06229 if(mask_ptr[i] <= 0.5f) new_ptr[i] = avg_under_mask;
06230 }
06231 new_image->update();
06232 return new_image;
06233 }
|
|
|
Definition at line 1041 of file util.cpp. References BPKT::data, BPKT::hdr, BPKT::len, BPKT::oseq, and BPKT::pseq. 01041 {
01042 // struct sockaddr_in sadr = { AF_INET, 9989, INADDR_ANY};
01043 // int sock=socket(AF_INET,SOCK_DGRAM,0);
01044 // if (bind(sock,&sadr,sizeof(sockaddr_in))) return string();
01045
01046 if (ByteOrder::is_host_big_endian()) {
01047 printf("No cache mirroring on Big endian machines yet\n");
01048 return string(); // FIXME: no support for big endian hosts
01049 }
01050
01051 BPKT pkt;
01052 string ret;
01053 vector<char> fill;
01054 int obj=-1;
01055 unsigned int i=0;
01056 // printf ("Listening\n");
01057
01058 while (1) {
01059 int l = recv(sock,&pkt,1044,0);
01060 if (l<=0) {
01061 if (obj!=-1) printf("Timeout with incomplete obj %d %d/%d\n",obj,i,(int)fill.size());
01062 return string(); // probably a timeout
01063 }
01064 if (l<20) {
01065 printf("Bad packet from broadcast");
01066 continue;
01067 }
01068
01069 if (strncmp(pkt.hdr,"EMAN",4)!=0) continue;
01070
01071 // new object coming in
01072 if (obj!=pkt.oseq) {
01073 obj=pkt.oseq;
01074 ret.resize(pkt.len);
01075 fill.resize((pkt.len-1)/1024+1);
01076 for (i=0; i<fill.size(); i++) fill[i]=0;
01077 }
01078 if (obj==-1) printf("Something wierd happened. please report\n");
01079
01080 // copy the packet into the output buffer
01081 fill[pkt.pseq]=1;
01082 ret.replace(pkt.pseq*1024,l-20,(char *)pkt.data,l-20);
01083
01084 // see if we got everything
01085 for (i=0; i<fill.size(); i++) {
01086 if (fill[i]!=1) break;
01087 }
01088 // printf("\t\t\tObj %d %d/%d \r",obj,i,(int)fill.size());
01089 fflush(stdout);
01090
01091 if (i==fill.size()) return ret; // Yea ! We got a good packet
01092 }
01093
01094 }
|
|
|
Remove a filename's extension and return the new filename.
Definition at line 450 of file util.cpp. 00451 {
00452 if (filename == "") {
00453 return "";
00454 }
00455
00456 char *buf = new char[filename.size()+1];
00457 strcpy(buf, filename.c_str());
00458 char *old_ext = strrchr(buf, '.');
00459 if (old_ext) {
00460 buf[strlen(buf) - strlen(old_ext)] = '\0';
00461 }
00462 string result = string(buf);
00463 if( buf )
00464 {
00465 delete [] buf;
00466 buf = 0;
00467 }
00468 return result;
00469 }
|
|
||||||||||||
|
Definition at line 1092 of file util.h. Referenced by get_pixel_conv_new(), and get_pixel_conv_new_background().
|
|
||||||||||||||||||||||||||||||||
|
Definition at line 1060 of file util.h. Referenced by multi_align_error_dfunc(), and multi_align_error_func(). 01060 {
01061 return (val > 0) ? T(+1) : T(-1);
01062 }
01063
01064 // /** Get the isosurface value for 3D image.
01065 // *
|
|
||||||||||||||||||||
|
rotate data vertically by ny/2, to make the mrc phase origin compliance with EMAN1 and TNF reader
Definition at line 95 of file util.cpp. References data, nx, ny, and t. 00096 {
00097 if(ny==1 && nz==1) { //1D, do nothing
00098 return;
00099 }
00100 else if(ny!=1 && nz==1) { //2D, rotate vertically by ny/2
00101 size_t i, j, k, l;
00102 float re;
00103 l=ny/2*nx;
00104 for (i=0; i<ny/2; i++) {
00105 for (j=0; j<nx; j++) {
00106 k=j+i*nx;
00107 re=data[k];
00108 data[k]=data[k+l];
00109 data[k+l]=re;
00110 }
00111 }
00112 }
00113 else { //3D, in the y,z plane, swaps quadrants I,III and II,IV, this is the 'rotation' in y and z
00114 size_t i, j, k, l, ii, jj;
00115 char * t=(char *)malloc(sizeof(float)*nx);
00116
00117 k=nx*ny*(nz+1)/2;
00118 l=nx*ny*(nz-1)/2;
00119 jj=nx*sizeof(float);
00120 for (j=ii=0; j<nz/2; ++j) {
00121 for (i=0; i<ny; ++i,ii+=nx) {
00122 memcpy(t,data+ii,jj);
00123 if (i<ny/2) {
00124 memcpy(data+ii,data+ii+k,jj);
00125 memcpy(data+ii+k,t,jj);
00126 }
00127 else {
00128 memcpy(data+ii,data+ii+l,jj);
00129 memcpy(data+ii+l,t,jj);
00130 }
00131 }
00132 }
00133 free(t);
00134 }
00135 }
|
|
|
Get ceiling round of a float number x.
|
|
|
Get ceiling round of a float number x.
Definition at line 1452 of file util.h. Referenced by EMAN::Util::FakeKaiserBessel::build_I0table(), EMAN::Util::KaiserBessel::build_I0table(), EMAN::Util::sincBlackman::build_sBtable(), EMAN::nnSSNR_ctfReconstructor::finish(), EMAN::nnSSNR_Reconstructor::finish(), get_pixel_conv_new(), get_pixel_conv_new_background(), EMAN::ApplyPolynomialProfileToHelix::process_inplace(), and EMAN::BeamstopProcessor::process_inplace(). |
|
||||||||||||||||||||||||||||||||
|
First element of output is total cost of the matches in the output Second element of output is the total number of matches in output So output has 2+(*(output+1))nParts elements.
Definition at line 20753 of file util_sparx.cpp. References k_means_cont_table_(). 20753 {
20754 //cout<<"sanitycheck called\n";
20755 int total_cost = *output;
20756 int num_matches = *(output+1);
20757
20758 int cost=0;
20759 int* intx;
20760 int intx_size;
20761 int* intx_next(0);
20762 int intx_next_size = 0;
20763 int curclass;
20764 int curclass_size;
20765 //cout<<"cost by match: [";
20766 for(int i = 0; i < num_matches; i++){
20767 curclass = *(output+2+ i*nParts);
20768 // check feasibility
20769 if (*(argParts + Indices[curclass]+1) == -5) {cout<<"infeasible match!\n"; return 0;}
20770 *(argParts + Indices[curclass]+1) = -5;
20771 // initialize intx to the number of elements in class curclass of partition 0 of the i-th match
20772 curclass_size = *(dimClasses+curclass)-2;
20773 intx = new int[curclass_size];
20774 for (int ic = 0; ic < curclass_size; ic++) *(intx+ic) = *(argParts + Indices[curclass]+2+ic);
20775 intx_size = curclass_size;
20776
20777 for (int j=1; j < nParts; j++){
20778 curclass = *(output+2+ i*nParts+j);
20779 if (*(argParts + Indices[j*K+curclass]+1)==-5){cout<<"infeasible match!\n"; return 0;}
20780 *(argParts + Indices[j*K+curclass]+1)=-5;
20781 // compute the intersection of intx and class curclass of partition j of the i-th match
20782 intx_next_size = Util::k_means_cont_table_(intx,argParts + Indices[j*K+curclass]+2, intx_next, intx_size, *(dimClasses + j*K+curclass)-2,0);
20783 intx_next = new int[intx_next_size];
20784 Util::k_means_cont_table_(intx,argParts + Indices[j*K+curclass]+2, intx_next, intx_size, *(dimClasses + j*K+curclass)-2,1);
20785 delete[] intx;
20786 intx=intx_next;
20787 intx_size= intx_next_size;
20788 }
20789 delete[] intx_next;
20790
20791 if (intx_next_size <= T) {cout << "something wrong with solution!\n"; return 0;}
20792 //cout <<intx_next_size<<",";
20793 cost = cost + intx_next_size;
20794 }
20795 //cout<<"]\n";
20796 if (cost != total_cost) {cout << "something wrong with solution!\n"; return 0;}
20797
20798 return 1;
20799
20800 }
|
|
||||||||||||||||||||||||
|
Save x, y data into a file. Each line of the file have the format "x1TABy1", where x1 = x0 + dx*i; y1 = y_array[i].
Definition at line 618 of file util.cpp. References Assert, FileAccessException, and NullPointerException. 00620 {
00621 Assert(dx > 0);
00622 Assert(array_size > 0);
00623 Assert(filename != "");
00624
00625 if (!y_array) {
00626 throw NullPointerException("y array");
00627 }
00628
00629 FILE *out = fopen(filename.c_str(), "wb");
00630 if (!out) {
00631 throw FileAccessException(filename);
00632 }
00633
00634 for (size_t i = 0; i < array_size; i++) {
00635 fprintf(out, "%g\t%g\n", x0 + dx * i, y_array[i]);
00636 }
00637 fclose(out);
00638 }
|
|
||||||||||||||||||||
|
Save x, y data into a file. Each line of the file have the format "x1TABy1", where x1 = x0 + dx*i; y1 = y_array[i].
Definition at line 599 of file util.cpp. References Assert, and FileAccessException. 00601 {
00602 Assert(dx != 0);
00603 Assert(y_array.size() > 0);
00604 Assert(filename != "");
00605
00606 FILE *out = fopen(filename.c_str(), "wb");
00607 if (!out) {
00608 throw FileAccessException(filename);
00609 }
00610
00611 for (size_t i = 0; i < y_array.size(); i++) {
00612 fprintf(out, "%g\t%g\n", x0 + dx * i, y_array[i]);
00613 }
00614 fclose(out);
00615 }
|
|
||||||||||||||||
|
Save (x y) data array into a file. Each line of the file have the format "x1TABy1", where x1, y1 are elements of x array and y array. The x, y arrays must have the same number of items.
Definition at line 575 of file util.cpp. References Assert, FileAccessException, and LOGERR. Referenced by EMAN::LowpassAutoBProcessor::create_radial_func(), and EMAN::CtfAverager::finish(). 00577 {
00578 Assert(x_array.size() > 0);
00579 Assert(y_array.size() > 0);
00580 Assert(filename != "");
00581
00582 if (x_array.size() != y_array.size()) {
00583 LOGERR("array x and array y have different size: %d != %d\n",
00584 x_array.size(), y_array.size());
00585 return;
00586 }
00587
00588 FILE *out = fopen(filename.c_str(), "wb");
00589 if (!out) {
00590 throw FileAccessException(filename);
00591 }
00592
00593 for (size_t i = 0; i < x_array.size(); i++) {
00594 fprintf(out, "%g\t%g\n", x_array[i], y_array[i]);
00595 }
00596 fclose(out);
00597 }
|
|
|
Get a filename's basename. For example, the basename of "hello.c" is still "hello.c"; The basename of "/tmp/abc/hello.c" is "hello.c".
Definition at line 471 of file util.cpp. Referenced by EMAN::Log::begin(), EMAN::TestUtil::check_image(), EMAN::TestUtil::dump_emdata(), EMAN::Log::loc(), and EMAN::TestUtil::set_progname(). 00472 {
00473 if (filename == "") {
00474 return "";
00475 }
00476
00477 char s = '/';
00478 #ifdef _WIN32
00479 s = '\\';
00480 #endif
00481 const char * c = strrchr(filename.c_str(), s);
00482 if (!c) {
00483 return filename;
00484 }
00485 else {
00486 c++;
00487 }
00488 return string(c);
00489 }
|
|
||||||||||||||||||||||||||||||||||||||||
|
return the weight of the largest weighted feasible match, along with the match in the (preallocated) argument curmax. The returned weight has to be gt newT. If there is no such feasible matching, return 0 as *curmax Definition at line 20807 of file util_sparx.cpp. References explore2(), flag, and k_means_cont_table_(). 20807 {
20808
20809 // some temp variables
20810 bool flag = 0;
20811 int nintx;
20812 int* dummy(0);
20813 //int* ret;
20814 int* curbranch = new int[nParts];
20815
20816 //initialize costlist to all 0
20817 for(int jit= 0; jit< J; jit++) *(costlist+jit) = 0;
20818
20819
20820 for(int a=0; a<K; a++)
20821 {
20822
20823 // check that class a of partition 0 is active and has greater than T elements. If not the case, then skip to the next class
20824 if (*(argParts + Indices[a] + 1) < 1) continue;
20825 if (*(dimClasses + a)-2 <= T) continue;
20826
20827 // initial pruning: for each partition j>0, set the partition to inactive if its intersection with class a of partition 0 is less than new T
20828
20829 for( int i=1; i < nParts; i++){
20830 flag = 0; // if flag stays 0 then no class in this partition has more than T objects in common with a, which implies no feasible match (> T) with class a of part 0 is possible.
20831 for(int j=0; j < K; j++){
20832 if (*(argParts + Indices[i*K+j] + 1) < 1) continue;
20833 nintx = Util::k_means_cont_table_(argParts + Indices[a]+2,argParts + Indices[i*K+j]+2, dummy, *(dimClasses + a)-2, *(dimClasses + i*K+j)-2,0);
20834 if (nintx > T) flag=1;
20835 else *(argParts + Indices[i*K+j] + 1) =-4;
20836 }
20837 if (flag==0) {break;}
20838 }
20839
20840 // explore determines J matchs with the largest weight greater than T where class in partition 0 is class a
20841 *curbranch = a;
20842
20843 if (flag > 0) // Each partition has one or more active class
20844 Util::explore2(argParts, Indices, dimClasses, nParts, K, T, argParts+Indices[a]+2, *(dimClasses+a)-2, argParts+Indices[a]+2,
20845 *(dimClasses+a)-2,0, J, matchlist, costlist, curbranch);
20846
20847 // take all the classes marked as -4 and remark it as 1 in preparation for next round
20848 for( int i=1; i < nParts; i++){
20849 for(int j=0; j < K; j++){
20850 if (*(argParts + Indices[i*K+j] + 1) == -4) *(argParts + Indices[i*K+j] + 1) =1;
20851
20852 }
20853 }
20854 }
20855
20856 delete[] curbranch;
20857 }
|
|
||||||||||||||||||||||||
|
This function drop a line (line) to an 2D image (img). The position of the line to the image is defined by (postline). The part of the line paste is defined by (offset), the begin position and (length) the size. Definition at line 4782 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), img_ptr, nx, and EMAN::EMData::update(). 04783 {
04784 int i;
04785 int nx=img->get_xsize();
04786 float *img_ptr = img->get_data();
04787 float *line_ptr = line->get_data();
04788 for (i=0;i<length;i++) img_ptr[nx*posline + i] = line_ptr[offset + i];
04789 img->update();
04790 }
|
|
||||||||||||
|
Set program logging level through command line option "-v N", where N is the level.
Definition at line 1108 of file util.cpp. Referenced by main(). 01109 {
01110 if (argc > 1 && strncmp(argv[1], "-v", 2) == 0) {
01111 char level_str[32];
01112 strcpy(level_str, argv[1] + 2);
01113 Log::LogLevel log_level = (Log::LogLevel) atoi(level_str);
01114 Log::logger()->set_level(log_level);
01115 }
01116 }
|
|
|
Set the seed for Randnum class.
Definition at line 678 of file util.cpp. References EMAN::Randnum::set_seed().
|
|
||||||||||
|
Sign function.
|
|
||||||||||||||||||||
|
Definition at line 5476 of file util_sparx.cpp. References colreverse(), and nx. Referenced by cyclicshift(). 05477 {
05478 int nxy = nx*ny;
05479 colreverse(beg, end, nxy);
05480 }
|
|
||||||||||||||||||||
|
does a sort as in Matlab. Carries along the Permutation matrix
Definition at line 641 of file util.cpp. Referenced by Radialize(). 00643 {
00644 float *pivot ; int *pivotPerm;
00645
00646 {
00647 float *pLeft = left; int *pLeftPerm = leftPerm;
00648 float *pRight = right; int *pRightPerm = rightPerm;
00649 float scratch = *left; int scratchPerm = *leftPerm;
00650
00651 while (pLeft < pRight) {
00652 while ((*pRight > scratch) && (pLeft < pRight)) {
00653 pRight--; pRightPerm--;
00654 }
00655 if (pLeft != pRight) {
00656 *pLeft = *pRight; *pLeftPerm = *pRightPerm;
00657 pLeft++; pLeftPerm++;
00658 }
00659 while ((*pLeft < scratch) && (pLeft < pRight)) {
00660 pLeft++; pLeftPerm++;
00661 }
00662 if (pLeft != pRight) {
00663 *pRight = *pLeft; *pRightPerm = *pLeftPerm;
00664 pRight--; pRightPerm--;
00665 }
00666 }
00667 *pLeft = scratch; *pLeftPerm = scratchPerm;
00668 pivot = pLeft; pivotPerm= pLeftPerm;
00669 }
00670 if (left < pivot) {
00671 sort_mat(left, pivot - 1,leftPerm,pivotPerm-1);
00672 }
00673 if (right > pivot) {
00674 sort_mat(pivot + 1, right,pivotPerm+1,rightPerm);
00675 }
00676 }
|
|
||||||||||||||||||||||||||||
|
Given a tabulated function y of x (unordered), and Given the values of the first derivatives at the end points This routine returns an array y2, that contains the second derivatives of the function at the tabulated points. PRB This function is called by splint
Definition at line 372 of file util_sparx.cpp. 00373 {
00374 int i,k;
00375 float p, qn, sig, un, *u;
00376 u = new float[n-1];
00377
00378 if (yp1 > .99e30){
00379 y2[0]=u[0]=0.0;
00380 } else {
00381 y2[0]=-.5f;
00382 u[0] =(3.0f/ (x[1] -x[0]))*( (y[1]-y[0])/(x[1]-x[0]) -yp1);
00383 }
00384
00385 for (i=1; i < n-1; i++) {
00386 sig= (x[i] - x[i-1])/(x[i+1] - x[i-1]);
00387 p = sig*y2[i-1] + 2.0f;
00388 y2[i] = (sig-1.0f)/p;
00389 u[i] = (y[i+1] - y[i] )/(x[i+1]-x[i] ) - (y[i] - y[i-1] )/(x[i] -x[i-1]);
00390 u[i] = (6.0f*u[i]/ (x[i+1]-x[i-1]) - sig*u[i-1])/p;
00391 }
00392
00393 if (ypn>.99e30){
00394 qn=0; un=0;
00395 } else {
00396 qn= .5f;
00397 un= (3.0f/(x[n-1] -x[n-2])) * (ypn - (y[n-1]-y[n-2])/(x[n-1]-x[n-2]));
00398 }
00399 y2[n-1]= (un - qn*u[n-2])/(qn*y2[n-2]+1.0f);
00400 for (k=n-2; k>=0; k--){
00401 y2[k]=y2[k]*y2[k+1]+u[k];
00402 }
00403 delete [] u;
00404 }
|
|
||||||||||||||||||||||||||||
|
Given a tabulated function y of x (n unordered points), and Given the values of the m values xq to be interpolated This routine returns the interpolated array yq, PRB This function is called by splint.
Definition at line 347 of file util_sparx.cpp. References spline(), splint(), x, and y. 00348 {
00349
00350 float x0= x[0];
00351 float x1= x[1];
00352 float x2= x[2];
00353 float y0= y[0];
00354 float y1= y[1];
00355 float y2= y[2];
00356 float yp1 = (y1-y0)/(x1-x0) + (y2-y0)/(x2-x0) - (y2-y1)/(x2-x1) ;
00357 float xn = x[n];
00358 float xnm1= x[n-1];
00359 float xnm2= x[n-2];
00360 float yn = y[n];
00361 float ynm1= y[n-1];
00362 float ynm2= y[n-2];
00363 float ypn= (yn-ynm1)/(xn-xnm1) + (yn-ynm2)/(xn-xnm2) - (ynm1-ynm2)/(xnm1-xnm2) ;
00364 float *y2d = new float[n];
00365 Util::spline(x,y,n,yp1,ypn,y2d);
00366 Util::splint(x,y,y2d,n,xq,yq,m); //PRB
00367 delete [] y2d;
00368 return;
00369 }
|
|
||||||||||||||||||||||||||||||||
|
Given the arrays xa(ordered, ya of length n, which tabulate a function and given the array y2a which is the output of spline and an unordered array xq, this routine returns a cubic-spline interpolated array yq.
Definition at line 407 of file util_sparx.cpp. References b. 00408 {
00409 int klo, khi, k;
00410 float h, b, a;
00411
00412 // klo=0; // can try to put here
00413 for (int j=0; j<m;j++){
00414 klo=0;
00415 khi=n-1;
00416 while (khi-klo >1) {
00417 k=(khi+klo) >>1;
00418 if (xa[k]>xq[j]){ khi=k;}
00419 else { klo=k;}
00420 }
00421 h=xa[khi]- xa[klo];
00422 if (h==0.0) printf("Bad XA input to routine SPLINT \n");
00423 a =(xa[khi]-xq[j])/h;
00424 b=(xq[j]-xa[klo])/h;
00425 yq[j]=a*ya[klo] + b*ya[khi]
00426 + ((a*a*a-a)*y2a[klo]
00427 +(b*b*b-b)*y2a[khi]) *(h*h)/6.0f;
00428 }
00429 // printf("h=%f, a = %f, b=%f, ya[klo]=%f, ya[khi]=%f , yq=%f\n",h, a, b, ya[klo], ya[khi],yq[0]);
00430 }
|
|
|
Calculate a number's square.
|
|
|
Calculate a number's square.
|
|
|
Calculate a number's square.
Definition at line 1574 of file util.h. Referenced by get_stats_cstyle(). |
|
||||||||||||
|
Calcuate (x*x + y*y).
Definition at line 1602 of file util.h. Referenced by get_stats(), and get_stats_cstyle(). |
|
||||||||||||
|
Safe string compare. It compares 's2' with the first N characters of 's1', where N is the length of 's2'.
Definition at line 247 of file util.cpp. References NullPointerException. Referenced by EMAN::TestUtil::dump_emdata(), and main(). 00248 {
00249 if (!s1 || !s2) {
00250 throw NullPointerException("Null string");
00251 }
00252
00253 if (strncmp(s1, s2, strlen(s2)) == 0) {
00254 return true;
00255 }
00256
00257 return false;
00258 }
|
|
|
Return a lower case version of the argument string.
Definition at line 241 of file util.cpp. Referenced by EMAN::Transform::detect_problem_keys(), EMAN::Symmetry3D::gen_orientations(), EMAN::Dict::get_ci(), EMAN::Transform::get_params(), EMAN::Transform::get_params_inverse(), EMAN::Transform::get_rotation(), EMAN::Dict::has_key_ci(), and EMAN::Transform::set_rotation(). 00241 {
00242 string ret(s);
00243 std::transform(s.begin(),s.end(),ret.begin(), (int (*)(int) ) std::tolower);
00244 return ret;
00245 }
|
|
||||||||||||||||||||||||
|
Definition at line 4625 of file util_sparx.cpp. References EMAN::EMData::get_data(), numr, PI2, tot, and EMAN::EMData::update(). 04625 {
04626 int nring = numr.size()/3;
04627 float *ave = avep->get_data();
04628 float *dat = datp->get_data();
04629 int i, j, numr3i, np;
04630 float arg, cs, si;
04631 int maxrin = numr(3,nring);
04632 if(mirror == 1) { //for mirrored data has to be conjugated
04633 for (i=1; i<=nring; i++) {
04634 numr3i = numr(3,i);
04635 np = numr(2,i)-1;
04636 ave[np] -= dat[np];
04637 ave[np+1] -= static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) );
04638 for (j=2; j<numr3i; j=j+2) {
04639 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin );
04640 cs = cos(arg);
04641 si = sin(arg);
04642 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg))
04643 ave[np + j] -= dat[np + j]*cs - dat[np + j +1]*si;
04644 ave[np + j +1] += dat[np + j]*si + dat[np + j +1]*cs;
04645 }
04646 }
04647 } else {
04648 for (i=1; i<=nring; i++) {
04649 numr3i = numr(3,i);
04650 np = numr(2,i)-1;
04651 ave[np] -= dat[np];
04652 ave[np+1] -= static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) );
04653 for (j=2; j<numr3i; j=j+2) {
04654 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin );
04655 cs = cos(arg);
04656 si = sin(arg);
04657 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg))
04658 ave[np + j] -= dat[np + j]*cs - dat[np + j +1]*si;
04659 ave[np + j +1] -= dat[np + j]*si + dat[np + j +1]*cs;
04660 }
04661 }
04662 }
04663 avep->update();
04664 EXITFUNC;
04665 }
|
|
||||||||||||
|
Definition at line 17671 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, NullPointerException, nx, ny, and EMAN::EMData::update(). 17672 {
17673 ENTERFUNC;
17674 /* Exception Handle */
17675 if (!img) {
17676 throw NullPointerException("NULL input image");
17677 }
17678 /* ========= img -= img1 ===================== */
17679
17680 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17681 size_t size = (size_t)nx*ny*nz;
17682 float *img_ptr = img->get_data();
17683 float *img1_ptr = img1->get_data();
17684 for (size_t i=0;i<size;++i) img_ptr[i] -= img1_ptr[i];
17685 img->update();
17686
17687 EXITFUNC;
17688 }
|
|
||||||||||||
|
Definition at line 17453 of file util_sparx.cpp. References EMAN::EMData::copy_head(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img2_ptr, img_ptr, EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), NullPointerException, nx, ny, EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), and EMAN::EMData::update(). 17454 {
17455 ENTERFUNC;
17456 /* Exception Handle */
17457 if (!img) {
17458 throw NullPointerException("NULL input image");
17459 }
17460 /* ============== output = img - img1 ================ */
17461
17462 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17463 size_t size = (size_t)nx*ny*nz;
17464 EMData * img2 = img->copy_head();
17465 float *img_ptr =img->get_data();
17466 float *img2_ptr = img2->get_data();
17467 float *img1_ptr = img1->get_data();
17468 for (size_t i=0;i<size;++i) img2_ptr[i] = img_ptr[i] - img1_ptr[i];
17469 img2->update();
17470 if(img->is_complex()) {
17471 img2->set_complex(true);
17472 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false);
17473 }
17474
17475 EXITFUNC;
17476 return img2;
17477 }
|
|
||||||||||||
|
Perform singular value decomposition on a set of images.
Definition at line 288 of file util.cpp. References data, get_value_at(), EMAN::EMData::set_value_at(), V, x, X, and y. Referenced by EMAN::PCA::dopca(). 00288 {
00289 int nimg=data.size();
00290 if (nvec==0) nvec=nimg;
00291 vector<EMData *> ret(nvec);
00292 if (nimg==0) return ret;
00293 int pixels=data[0]->get_xsize()*data[0]->get_ysize()*data[0]->get_zsize();
00294
00295 // Allocate the working space
00296 gsl_vector *work=gsl_vector_alloc(nimg);
00297 gsl_vector *S=gsl_vector_alloc(nimg);
00298 gsl_matrix *A=gsl_matrix_alloc(pixels,nimg);
00299 gsl_matrix *V=gsl_matrix_alloc(nimg,nimg);
00300 gsl_matrix *X=gsl_matrix_alloc(nimg,nimg);
00301
00302 int im,x,y,z,i;
00303 for (im=0; im<nimg; im++) {
00304 for (z=0,i=0; z<data[0]->get_zsize(); z++) {
00305 for (y=0; y<data[0]->get_ysize(); y++) {
00306 for (x=0; x<data[0]->get_xsize(); x++,i++) {
00307 gsl_matrix_set(A,i,im,data[im]->get_value_at(x,y,z));
00308 }
00309 }
00310 }
00311 }
00312
00313 // This calculates the SVD
00314 gsl_linalg_SV_decomp_mod (A,X, V, S, work);
00315
00316 for (im=0; im<nvec; im++) {
00317 EMData *a=data[0]->copy_head();
00318 ret[im]=a;
00319 for (z=0,i=0; z<data[0]->get_zsize(); z++) {
00320 for (y=0; y<data[0]->get_ysize(); y++) {
00321 for (x=0; x<data[0]->get_xsize(); x++,i++) {
00322 a->set_value_at(x,y,z,static_cast<float>(gsl_matrix_get(A,i,im)));
00323 }
00324 }
00325 }
00326 }
00327 return ret;
00328 }
|
|
||||||||||||||||||||||||||||||||
|
Definition at line 6138 of file util_sparx.cpp. References phase(), and sqrt(). 06139 {
06140 float cst = cs*1.0e7f;
06141
06142 wgh /= 100.0;
06143 float phase = atan(wgh/sqrt(1.0f-wgh*wgh));
06144 float lambda=12.398f/sqrt(voltage*(1022.0f+voltage));
06145 float ak2 = ak*ak;
06146 float g1 = dzz*1.0e4f*lambda*ak2;
06147 float g2 = cst*lambda*lambda*lambda*ak2*ak2/2.0f;
06148
06149 float ctfv = static_cast<float>( sin(M_PI*(g1-g2)+phase)*sign );
06150 if(b_factor != 0.0f) ctfv *= exp(-b_factor*ak2/4.0f);
06151
06152 return ctfv;
06153 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Calculate trilinear interpolation.
Definition at line 1513 of file util.h. Referenced by EMAN::SymSearchProcessor::process_inplace(), EMAN::StandardProjector::project3d(), EMAN::EMData::sget_value_at_interp(), and EMAN::TransformProcessor::transform(). |
|
||||||||||||||||||||
|
Quadratic interpolation (3D).
Definition at line 1903 of file util_sparx.cpp. References fdata, R, and triquad(). Referenced by triquad(). 01904 {
01905
01906 const float C2 = 0.5f; //1.0 / 2.0;
01907 const float C4 = 0.25f; //1.0 / 4.0;
01908 const float C8 = 0.125f; //1.0 / 8.0;
01909
01910 float RS = R * S;
01911 float ST = S * T;
01912 float RT = R * T;
01913 float RST = R * ST;
01914
01915 float RSQ = 1-R*R;
01916 float SSQ = 1-S*S;
01917 float TSQ = 1-T*T;
01918
01919 float RM1 = (1-R);
01920 float SM1 = (1-S);
01921 float TM1 = (1-T);
01922
01923 float RP1 = (1+R);
01924 float SP1 = (1+S);
01925 float TP1 = (1+T);
01926
01927 float triquad =
01928 (-C8) * RST * RM1 * SM1 * TM1 * fdata[0] +
01929 ( C4) * ST * RSQ * SM1 * TM1 * fdata[1] +
01930 ( C8) * RST * RP1 * SM1 * TM1 * fdata[2] +
01931 ( C4) * RT * RM1 * SSQ * TM1 * fdata[3] +
01932 (-C2) * T * RSQ * SSQ * TM1 * fdata[4] +
01933 (-C4) * RT * RP1 * SSQ * TM1 * fdata[5] +
01934 ( C8) * RST * RM1 * SP1 * TM1 * fdata[6] +
01935 (-C4) * ST * RSQ * SP1 * TM1 * fdata[7] +
01936 (-C8) * RST * RP1 * SP1 * TM1 * fdata[8] +
01937 //
01938 ( C4) * RS * RM1 * SM1 * TSQ * fdata[9] +
01939 (-C2) * S * RSQ * SM1 * TSQ * fdata[10] +
01940 (-C4) * RS * RP1 * SM1 * TSQ * fdata[11] +
01941 (-C2) * R * RM1 * SSQ * TSQ * fdata[12] +
01942 RSQ * SSQ * TSQ * fdata[13] +
01943 ( C2) * R * RP1 * SSQ * TSQ * fdata[14] +
01944 (-C4) * RS * RM1 * SP1 * TSQ * fdata[15] +
01945 ( C2) * S * RSQ * SP1 * TSQ * fdata[16] +
01946 ( C4) * RS * RP1 * SP1 * TSQ * fdata[17] +
01947 //
01948 ( C8) * RST * RM1 * SM1 * TP1 * fdata[18] +
01949 (-C4) * ST * RSQ * SM1 * TP1 * fdata[19] +
01950 (-C8) * RST * RP1 * SM1 * TP1 * fdata[20] +
01951 (-C4) * RT * RM1 * SSQ * TP1 * fdata[21] +
01952 ( C2) * T * RSQ * SSQ * TP1 * fdata[22] +
01953 ( C4) * RT * RP1 * SSQ * TP1 * fdata[23] +
01954 (-C8) * RST * RM1 * SP1 * TP1 * fdata[24] +
01955 ( C4) * ST * RSQ * SP1 * TP1 * fdata[25] +
01956 ( C8) * RST * RP1 * SP1 * TP1 * fdata[26] ;
01957 return triquad;
01958 }
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Definition at line 7890 of file util_sparx.cpp. References abs, addnod_(), dist(), left_(), x, and y. 07894 {
07895 /* System generated locals */
07896 int i__1, i__2;
07897
07898 /* Local variables */
07899 static double d__;
07900 static int i__, j;
07901 static double d1, d2, d3;
07902 static int i0, lp, kt, ku, lpl, nku;
07903 extern long int left_(double *, double *, double *, double
07904 *, double *, double *, double *, double *,
07905 double *);
07906 static int nexti;
07907 extern /* Subroutine */ int addnod_(int *, int *, double *,
07908 double *, double *, int *, int *, int *,
07909 int *, int *);
07910
07911
07912 /* *********************************************************** */
07913
07914 /* From STRIPACK */
07915 /* Robert J. Renka */
07916 /* Dept. of Computer Science */
07917 /* Univ. of North Texas */
07918 /* renka@cs.unt.edu */
07919 /* 01/20/03 */
07920
07921 /* This is an alternative to TRMESH with the inclusion of */
07922 /* an efficient means of removing duplicate or nearly dupli- */
07923 /* cate nodes. */
07924
07925 /* This subroutine creates a Delaunay triangulation of a */
07926 /* set of N arbitrarily distributed points, referred to as */
07927 /* nodes, on the surface of the unit sphere. Refer to Sub- */
07928 /* routine TRMESH for definitions and a list of additional */
07929 /* subroutines. This routine is an alternative to TRMESH */
07930 /* with the inclusion of an efficient means of removing dup- */
07931 /* licate or nearly duplicate nodes. */
07932
07933 /* The algorithm has expected time complexity O(N*log(N)) */
07934 /* for random nodal distributions. */
07935
07936
07937 /* On input: */
07938
07939 /* N0 = Number of nodes, possibly including duplicates. */
07940 /* N0 .GE. 3. */
07941
07942 /* TOL = Tolerance defining a pair of duplicate nodes: */
07943 /* bound on the deviation from 1 of the cosine of */
07944 /* the angle between the nodes. Note that */
07945 /* |1-cos(A)| is approximately A*A/2. */
07946
07947 /* The above parameters are not altered by this routine. */
07948
07949 /* X,Y,Z = Arrays of length at least N0 containing the */
07950 /* Cartesian coordinates of nodes. (X(K),Y(K), */
07951 /* Z(K)) is referred to as node K, and K is re- */
07952 /* ferred to as a nodal index. It is required */
07953 /* that X(K)**2 + Y(K)**2 + Z(K)**2 = 1 for all */
07954 /* K. The first three nodes must not be col- */
07955 /* linear (lie on a common great circle). */
07956
07957 /* LIST,LPTR = Arrays of length at least 6*N0-12. */
07958
07959 /* LEND = Array of length at least N0. */
07960
07961 /* INDX = Array of length at least N0. */
07962
07963 /* LCNT = Array of length at least N0 (length N is */
07964 /* sufficient). */
07965
07966 /* NEAR,NEXT,DIST = Work space arrays of length at */
07967 /* least N0. The space is used to */
07968 /* efficiently determine the nearest */
07969 /* triangulation node to each un- */
07970 /* processed node for use by ADDNOD. */
07971
07972 /* On output: */
07973
07974 /* N = Number of nodes in the triangulation. 3 .LE. N */
07975 /* .LE. N0, or N = 0 if IER < 0. */
07976
07977 /* X,Y,Z = Arrays containing the Cartesian coordinates */
07978 /* of the triangulation nodes in the first N */
07979 /* locations. The original array elements are */
07980 /* shifted down as necessary to eliminate dup- */
07981 /* licate nodes. */
07982
07983 /* LIST = Set of nodal indexes which, along with LPTR, */
07984 /* LEND, and LNEW, define the triangulation as a */
07985 /* set of N adjacency lists -- counterclockwise- */
07986 /* ordered sequences of neighboring nodes such */
07987 /* that the first and last neighbors of a bound- */
07988 /* ary node are boundary nodes (the first neigh- */
07989 /* bor of an interior node is arbitrary). In */
07990 /* order to distinguish between interior and */
07991 /* boundary nodes, the last neighbor of each */
07992 /* boundary node is represented by the negative */
07993 /* of its index. */
07994
07995 /* LPTR = Set of pointers (LIST indexes) in one-to-one */
07996 /* correspondence with the elements of LIST. */
07997 /* LIST(LPTR(I)) indexes the node which follows */
07998 /* LIST(I) in cyclical counterclockwise order */
07999 /* (the first neighbor follows the last neigh- */
08000 /* bor). */
08001
08002 /* LEND = Set of pointers to adjacency lists. LEND(K) */
08003 /* points to the last neighbor of node K for */
08004 /* K = 1,...,N. Thus, LIST(LEND(K)) < 0 if and */
08005 /* only if K is a boundary node. */
08006
08007 /* LNEW = Pointer to the first empty location in LIST */
08008 /* and LPTR (list length plus one). LIST, LPTR, */
08009 /* LEND, and LNEW are not altered if IER < 0, */
08010 /* and are incomplete if IER > 0. */
08011
08012 /* INDX = Array of output (triangulation) nodal indexes */
08013 /* associated with input nodes. For I = 1 to */
08014 /* N0, INDX(I) is the index (for X, Y, and Z) of */
08015 /* the triangulation node with the same (or */
08016 /* nearly the same) coordinates as input node I. */
08017
08018 /* LCNT = Array of int weights (counts) associated */
08019 /* with the triangulation nodes. For I = 1 to */
08020 /* N, LCNT(I) is the number of occurrences of */
08021 /* node I in the input node set, and thus the */
08022 /* number of duplicates is LCNT(I)-1. */
08023
08024 /* NEAR,NEXT,DIST = Garbage. */
08025
08026 /* IER = Error indicator: */
08027 /* IER = 0 if no errors were encountered. */
08028 /* IER = -1 if N0 < 3 on input. */
08029 /* IER = -2 if the first three nodes are */
08030 /* collinear. */
08031 /* IER = -3 if Subroutine ADDNOD returns an error */
08032 /* flag. This should not occur. */
08033
08034 /* Modules required by TRMSH3: ADDNOD, BDYADD, COVSPH, */
08035 /* INSERT, INTADD, JRAND, */
08036 /* LEFT, LSTPTR, STORE, SWAP, */
08037 /* SWPTST, TRFIND */
08038
08039 /* Intrinsic function called by TRMSH3: ABS */
08040
08041 /* *********************************************************** */
08042
08043
08044 /* Local parameters: */
08045
08046 /* D = (Negative cosine of) distance from node KT to */
08047 /* node I */
08048 /* D1,D2,D3 = Distances from node KU to nodes 1, 2, and 3, */
08049 /* respectively */
08050 /* I,J = Nodal indexes */
08051 /* I0 = Index of the node preceding I in a sequence of */
08052 /* unprocessed nodes: I = NEXT(I0) */
08053 /* KT = Index of a triangulation node */
08054 /* KU = Index of an unprocessed node and DO-loop index */
08055 /* LP = LIST index (pointer) of a neighbor of KT */
08056 /* LPL = Pointer to the last neighbor of KT */
08057 /* NEXTI = NEXT(I) */
08058 /* NKU = NEAR(KU) */
08059
08060 /* Parameter adjustments */
08061 --dist;
08062 --next;
08063 --near__;
08064 --indx;
08065 --lend;
08066 --z__;
08067 --y;
08068 --x;
08069 --list;
08070 --lptr;
08071 --lcnt;
08072
08073 /* Function Body */
08074 if (*n0 < 3) {
08075 *n = 0;
08076 *ier = -1;
08077 return 0;
08078 }
08079
08080 /* Store the first triangle in the linked list. */
08081
08082 if (! left_(&x[1], &y[1], &z__[1], &x[2], &y[2], &z__[2], &x[3], &y[3], &
08083 z__[3])) {
08084
08085 /* The first triangle is (3,2,1) = (2,1,3) = (1,3,2). */
08086
08087 list[1] = 3;
08088 lptr[1] = 2;
08089 list[2] = -2;
08090 lptr[2] = 1;
08091 lend[1] = 2;
08092
08093 list[3] = 1;
08094 lptr[3] = 4;
08095 list[4] = -3;
08096 lptr[4] = 3;
08097 lend[2] = 4;
08098
08099 list[5] = 2;
08100 lptr[5] = 6;
08101 list[6] = -1;
08102 lptr[6] = 5;
08103 lend[3] = 6;
08104
08105 } else if (! left_(&x[2], &y[2], &z__[2], &x[1], &y[1], &z__[1], &x[3], &
08106 y[3], &z__[3])) {
08107
08108 /* The first triangle is (1,2,3): 3 Strictly Left 1->2, */
08109 /* i.e., node 3 lies in the left hemisphere defined by */
08110 /* arc 1->2. */
08111
08112 list[1] = 2;
08113 lptr[1] = 2;
08114 list[2] = -3;
08115 lptr[2] = 1;
08116 lend[1] = 2;
08117
08118 list[3] = 3;
08119 lptr[3] = 4;
08120 list[4] = -1;
08121 lptr[4] = 3;
08122 lend[2] = 4;
08123
08124 list[5] = 1;
08125 lptr[5] = 6;
08126 list[6] = -2;
08127 lptr[6] = 5;
08128 lend[3] = 6;
08129
08130
08131 } else {
08132
08133 /* The first three nodes are collinear. */
08134
08135 *n = 0;
08136 *ier = -2;
08137 return 0;
08138 }
08139
08140 //printf("pass check colinear\n");
08141
08142 /* Initialize LNEW, INDX, and LCNT, and test for N = 3. */
08143
08144 *lnew = 7;
08145 indx[1] = 1;
08146 indx[2] = 2;
08147 indx[3] = 3;
08148 lcnt[1] = 1;
08149 lcnt[2] = 1;
08150 lcnt[3] = 1;
08151 if (*n0 == 3) {
08152 *n = 3;
08153 *ier = 0;
08154 return 0;
08155 }
08156
08157 /* A nearest-node data structure (NEAR, NEXT, and DIST) is */
08158 /* used to obtain an expected-time (N*log(N)) incremental */
08159 /* algorithm by enabling constant search time for locating */
08160 /* each new node in the triangulation. */
08161
08162 /* For each unprocessed node KU, NEAR(KU) is the index of the */
08163 /* triangulation node closest to KU (used as the starting */
08164 /* point for the search in Subroutine TRFIND) and DIST(KU) */
08165 /* is an increasing function of the arc length (angular */
08166 /* distance) between nodes KU and NEAR(KU): -Cos(a) for */
08167 /* arc length a. */
08168
08169 /* Since it is necessary to efficiently find the subset of */
08170 /* unprocessed nodes associated with each triangulation */
08171 /* node J (those that have J as their NEAR entries), the */
08172 /* subsets are stored in NEAR and NEXT as follows: for */
08173 /* each node J in the triangulation, I = NEAR(J) is the */
08174 /* first unprocessed node in J's set (with I = 0 if the */
08175 /* set is empty), L = NEXT(I) (if I > 0) is the second, */
08176 /* NEXT(L) (if L > 0) is the third, etc. The nodes in each */
08177 /* set are initially ordered by increasing indexes (which */
08178 /* maximizes efficiency) but that ordering is not main- */
08179 /* tained as the data structure is updated. */
08180
08181 /* Initialize the data structure for the single triangle. */
08182
08183 near__[1] = 0;
08184 near__[2] = 0;
08185 near__[3] = 0;
08186 for (ku = *n0; ku >= 4; --ku) {
08187 d1 = -(x[ku] * x[1] + y[ku] * y[1] + z__[ku] * z__[1]);
08188 d2 = -(x[ku] * x[2] + y[ku] * y[2] + z__[ku] * z__[2]);
08189 d3 = -(x[ku] * x[3] + y[ku] * y[3] + z__[ku] * z__[3]);
08190 if (d1 <= d2 && d1 <= d3) {
08191 near__[ku] = 1;
08192 dist[ku] = d1;
08193 next[ku] = near__[1];
08194 near__[1] = ku;
08195 } else if (d2 <= d1 && d2 <= d3) {
08196 near__[ku] = 2;
08197 dist[ku] = d2;
08198 next[ku] = near__[2];
08199 near__[2] = ku;
08200 } else {
08201 near__[ku] = 3;
08202 dist[ku] = d3;
08203 next[ku] = near__[3];
08204 near__[3] = ku;
08205 }
08206 /* L1: */
08207 }
08208
08209 /* Loop on unprocessed nodes KU. KT is the number of nodes */
08210 /* in the triangulation, and NKU = NEAR(KU). */
08211
08212 kt = 3;
08213 i__1 = *n0;
08214 for (ku = 4; ku <= i__1; ++ku) {
08215 nku = near__[ku];
08216
08217 /* Remove KU from the set of unprocessed nodes associated */
08218 /* with NEAR(KU). */
08219 i__ = nku;
08220 if (near__[i__] == ku) {
08221 near__[i__] = next[ku];
08222 } else {
08223 i__ = near__[i__];
08224 L2:
08225 i0 = i__;
08226 i__ = next[i0];
08227 if (i__ != ku) {
08228 goto L2;
08229 }
08230 next[i0] = next[ku];
08231 }
08232 near__[ku] = 0;
08233
08234 /* Bypass duplicate nodes. */
08235
08236 if (dist[ku] <= *tol - 1.) {
08237 indx[ku] = -nku;
08238 ++lcnt[nku];
08239 goto L6;
08240 }
08241
08242
08243 /* Add a new triangulation node KT with LCNT(KT) = 1. */
08244 ++kt;
08245 x[kt] = x[ku];
08246 y[kt] = y[ku];
08247 z__[kt] = z__[ku];
08248 indx[ku] = kt;
08249 lcnt[kt] = 1;
08250 addnod_(&nku, &kt, &x[1], &y[1], &z__[1], &list[1], &lptr[1], &lend[1]
08251 , lnew, ier);
08252 if (*ier != 0) {
08253 *n = 0;
08254 *ier = -3;
08255 return 0;
08256 }
08257
08258 /* Loop on neighbors J of node KT. */
08259
08260 lpl = lend[kt];
08261 lp = lpl;
08262 L3:
08263 lp = lptr[lp];
08264 j = (i__2 = list[lp], abs(i__2));
08265
08266 /* Loop on elements I in the sequence of unprocessed nodes */
08267 /* associated with J: KT is a candidate for replacing J */
08268 /* as the nearest triangulation node to I. The next value */
08269 /* of I in the sequence, NEXT(I), must be saved before I */
08270 /* is moved because it is altered by adding I to KT's set. */
08271
08272 i__ = near__[j];
08273 L4:
08274 if (i__ == 0) {
08275 goto L5;
08276 }
08277 nexti = next[i__];
08278
08279 /* Test for the distance from I to KT less than the distance */
08280 /* from I to J. */
08281
08282 d__ = -(x[i__] * x[kt] + y[i__] * y[kt] + z__[i__] * z__[kt]);
08283 if (d__ < dist[i__]) {
08284
08285 /* Replace J by KT as the nearest triangulation node to I: */
08286 /* update NEAR(I) and DIST(I), and remove I from J's set */
08287 /* of unprocessed nodes and add it to KT's set. */
08288
08289 near__[i__] = kt;
08290 dist[i__] = d__;
08291 if (i__ == near__[j]) {
08292 near__[j] = nexti;
08293 } else {
08294 next[i0] = nexti;
08295 }
08296 next[i__] = near__[kt];
08297 near__[kt] = i__;
08298 } else {
08299 i0 = i__;
08300 }
08301
08302 /* Bottom of loop on I. */
08303
08304 i__ = nexti;
08305 goto L4;
08306
08307 /* Bottom of loop on neighbors J. */
08308
08309 L5:
08310 if (lp != lpl) {
08311 goto L3;
08312 }
08313 L6:
08314 ;
08315 }
08316 *n = kt;
08317 *ier = 0;
08318 return 0;
08319 } /* trmsh3_ */
|
|
||||||||||||||||||||||||||||
|
Definition at line 19206 of file util_sparx.cpp. References EMAN::EMData::cmp(), dt, EMAN::EMData::rot_scale_trans2D(), setulb_(), SIXTY, and x. 19206 {
19207
19208 EMData *rot;
19209
19210 const int nmax=3, mmax=3;
19211 char task[60], csave[60];
19212 long int lsave[4];
19213 long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44];
19214 double f, f1, f2, f3, factr, pgtol, x[nmax], l[nmax], u[nmax], g[nmax], dsave[29], wa[2*mmax*nmax+4*nmax+12*mmax*mmax+12*mmax];
19215 long int SIXTY=60;
19216
19217 // We wish to have no output.
19218 iprint = -1;
19219
19220 //c We specify the tolerances in the stopping criteria.
19221 factr=1.0e1;
19222 pgtol=1.0e-5;
19223
19224 // We specify the dimension n of the sample problem and the number
19225 // m of limited memory corrections stored. (n and m should not
19226 // exceed the limits nmax and mmax respectively.)
19227 n=3;
19228 m=3;
19229
19230 // We now provide nbd which defines the bounds on the variables:
19231 // l specifies the lower bounds,
19232 // u specifies the upper bounds.
19233 // x specifies the initial guess
19234 x[0] = ang; nbd[0] = 2; l[0] = ang-2.0; u[0] = ang+2.0;
19235 x[1] = sxs; nbd[1] = 2; l[1] = sxs-1.5; u[1] = sxs+1.5;
19236 x[2] = sys; nbd[2] = 2; l[2] = sys-1.5; u[2] = sys+1.5;
19237
19238
19239 // We start the iteration by initializing task.
19240 // (**MUST clear remaining chars in task with spaces (else crash)!**)
19241 strcpy(task,"START");
19242 for (int i=5;i<60;i++) task[i]=' ';
19243
19244 // This is the call to the L-BFGS-B code.
19245 // (* call the L-BFGS-B routine with task='START' once before loop *)
19246 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
19247 //int step = 1;
19248
19249 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *)
19250 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) {
19251
19252 if (strncmp(task,"FG",2)==0) {
19253 // the minimization routine has returned to request the
19254 // function f and gradient g values at the current x
19255
19256 // Compute function value f for the sample problem.
19257 rot = new EMData();
19258 rot = image->rot_scale_trans2D((float)x[0], (float)x[1], (float)x[2], 1.0f);
19259 f = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
19260 //f = -f;
19261 delete rot;
19262
19263 // Compute gradient g for the sample problem.
19264 float dt = 1.0e-3f;
19265 rot = new EMData();
19266 rot = image->rot_scale_trans2D((float)x[0]+dt, (float)x[1], (float)x[2], 1.0f);
19267 f1 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
19268 //f1 = -f1;
19269 g[0] = (f1-f)/dt;
19270 delete rot;
19271
19272 dt = 1.0e-2f;
19273 rot = new EMData();
19274 rot = image->rot_scale_trans2D((float)x[0], (float)x[1]+dt, (float)x[2], 1.0f);
19275 f2 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
19276 //f2 = -f2;
19277 g[1] = (f2-f)/dt;
19278 delete rot;
19279
19280 rot = new EMData();
19281 rot = image->rot_scale_trans2D((float)x[0], (float)x[1], (float)x[2]+dt, 1.0f);
19282 f3 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
19283 //f3 = -f3;
19284 g[2] = (f3-f)/dt;
19285 delete rot;
19286 }
19287
19288 //c go back to the minimization routine.
19289 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
19290 //step++;
19291 }
19292
19293 //printf("Total step is %d\n", step);
19294 vector<float> res;
19295 res.push_back(static_cast<float>(x[0]));
19296 res.push_back(static_cast<float>(x[1]));
19297 res.push_back(static_cast<float>(x[2]));
19298 //res.push_back(step);
19299 return res;
19300 }
|
|
||||||||||||||||||||||||||||||||
|
Definition at line 19302 of file util_sparx.cpp. References EMAN::EMData::cmp(), dt, pi, EMAN::EMData::rot_scale_conv7(), setulb_(), SIXTY, and x. 19302 {
19303
19304 EMData *rot;
19305
19306 const int nmax=3, mmax=3;
19307 char task[60], csave[60];
19308 long int lsave[4];
19309 long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44];
19310 double f, f1, f2, f3, factr, pgtol, x[nmax], l[nmax], u[nmax], g[nmax], dsave[29], wa[2*mmax*nmax+4*nmax+12*mmax*mmax+12*mmax];
19311 long int SIXTY=60;
19312
19313 // We wish to have no output.
19314 iprint = -1;
19315
19316 //c We specify the tolerances in the stopping criteria.
19317 factr=1.0e1;
19318 pgtol=1.0e-5;
19319
19320 // We specify the dimension n of the sample problem and the number
19321 // m of limited memory corrections stored. (n and m should not
19322 // exceed the limits nmax and mmax respectively.)
19323 n=3;
19324 m=3;
19325
19326 // We now provide nbd which defines the bounds on the variables:
19327 // l specifies the lower bounds,
19328 // u specifies the upper bounds.
19329 // x specifies the initial guess
19330 x[0] = ang; nbd[0] = 2; l[0] = ang-2.0; u[0] = ang+2.0;
19331 x[1] = sxs; nbd[1] = 2; l[1] = sxs-1.5; u[1] = sxs+1.5;
19332 x[2] = sys; nbd[2] = 2; l[2] = sys-1.5; u[2] = sys+1.5;
19333
19334
19335 // We start the iteration by initializing task.
19336 // (**MUST clear remaining chars in task with spaces (else crash)!**)
19337 strcpy(task,"START");
19338 for (int i=5;i<60;i++) task[i]=' ';
19339
19340 // This is the call to the L-BFGS-B code.
19341 // (* call the L-BFGS-B routine with task='START' once before loop *)
19342 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
19343 //int step = 1;
19344
19345 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *)
19346 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) {
19347
19348 if (strncmp(task,"FG",2)==0) {
19349 // the minimization routine has returned to request the
19350 // function f and gradient g values at the current x
19351
19352 // Compute function value f for the sample problem.
19353 rot = new EMData();
19354 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1], (float)x[2], kb, 1.0f);
19355 f = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
19356 //f = -f;
19357 delete rot;
19358
19359 // Compute gradient g for the sample problem.
19360 float dt = 1.0e-3f;
19361 rot = new EMData();
19362 rot = image->rot_scale_conv7((float)((x[0]+dt)*pi/180), (float)x[1], (float)x[2], kb, 1.0f);
19363 f1 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
19364 //f1 = -f1;
19365 g[0] = (f1-f)/dt;
19366 delete rot;
19367
19368 rot = new EMData();
19369 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1]+dt, (float)x[2], kb, 1.0);
19370 f2 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
19371 //f2 = -f2;
19372 g[1] = (f2-f)/dt;
19373 delete rot;
19374
19375 rot = new EMData();
19376 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1], (float)x[2]+dt, kb, 1.0f);
19377 f3 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
19378 //f3 = -f3;
19379 g[2] = (f3-f)/dt;
19380 delete rot;
19381 }
19382
19383 //c go back to the minimization routine.
19384 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
19385 //step++;
19386 }
19387
19388 //printf("Total step is %d\n", step);
19389 vector<float> res;
19390 res.push_back(static_cast<float>(x[0]));
19391 res.push_back(static_cast<float>(x[1]));
19392 res.push_back(static_cast<float>(x[2]));
19393 //res.push_back(step);
19394 return res;
19395 }
|
|
||||||||||||||||||||||||||||
|
Definition at line 19554 of file util_sparx.cpp. 19554 {
19555
19556 double x[4];
19557 int n;
19558 int l = 3;
19559 int m = 200;
19560 double e = 1e-9;
19561 double step = 0.01;
19562 float (*my_func)(EMData* , EMData* , EMData* , float , float , float) = ccc_images;
19563
19564 x[1] = ang;
19565 x[2] = sxs;
19566 x[3] = sys;
19567
19568 Steepda(x, step, e, l, m, &n, my_func, image, refim, mask); // Call steepest descent optimization subroutine
19569 //printf("Took %d steps\n", n);
19570
19571 vector<float> res;
19572 res.push_back(static_cast<float>(x[1]));
19573 res.push_back(static_cast<float>(x[2]));
19574 res.push_back(static_cast<float>(x[3]));
19575 res.push_back(static_cast<float>(n));
19576 return res;
19577 }
|
|
||||||||||||||||||||||||||||||||
|
Definition at line 19836 of file util_sparx.cpp. References Steepda_G(), and x. 19836 {
19837
19838 double x[4];
19839 int n;
19840 int l = 3;
19841 int m = 200;
19842 double e = 1e-9;
19843 double step = 0.001;
19844 float (*my_func)(EMData* , EMData* , EMData* , Util::KaiserBessel&, float , float , float) = ccc_images_G;
19845
19846 x[1] = ang;
19847 x[2] = sxs;
19848 x[3] = sys;
19849
19850 Steepda_G(x, step, e, l, m, &n, my_func, image, refim, mask, kb); // Call steepest descent optimization subroutine
19851 //printf("Took %d steps\n", n);
19852
19853 vector<float> res;
19854 res.push_back(static_cast<float>(x[1]));
19855 res.push_back(static_cast<float>(x[2]));
19856 res.push_back(static_cast<float>(x[3]));
19857 res.push_back(static_cast<float>(n));
19858 return res;
19859 }
|
|
||||||||||||||||||||||||||||||||||||||||
|
Definition at line 19397 of file util_sparx.cpp. References EMAN::EMData::center_origin_fft(), EMAN::EMData::cmp(), EMAN::EMData::do_ift_inplace(), dt, EMAN::EMData::extract_plane(), EMAN::EMData::fft_shuffle(), EMAN::EMData::get_ysize(), phi, EMAN::EMData::process_inplace(), proj, setulb_(), SIXTY, theta, EMAN::EMData::window_center(), and x. 19397 {
19398
19399 EMData *proj, *proj2;
19400
19401 const int nmax=5, mmax=5;
19402 char task[60], csave[60];
19403 long int lsave[4];
19404 long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44];
19405 double f, ft, factr, pgtol, x[nmax], l[nmax], u[nmax], g[nmax], dsave[29], wa[2*mmax*nmax+4*nmax+12*mmax*mmax+12*mmax];
19406 long int SIXTY=60;
19407
19408 // We wish to have no output.
19409 iprint = -1;
19410
19411 //c We specify the tolerances in the stopping criteria.
19412 factr=1.0e1;
19413 pgtol=1.0e-5;
19414
19415 // We specify the dimension n of the sample problem and the number
19416 // m of limited memory corrections stored. (n and m should not
19417 // exceed the limits nmax and mmax respectively.)
19418 n=5;
19419 m=5;
19420
19421 // We now provide nbd which defines the bounds on the variables:
19422 // l specifies the lower bounds,
19423 // u specifies the upper bounds.
19424 // x specifies the initial guess
19425 x[0] = phi; nbd[0] = 2; l[0] = phi-2.0; u[0] = phi+2.0;
19426 x[1] = theta; nbd[1] = 2; l[1] = theta-2.0; u[1] = theta+2.0;
19427 x[2] = psi; nbd[2] = 2; l[2] = psi-2.0; u[2] = psi+2.0;
19428 x[3] = sxs; nbd[3] = 2; l[3] = sxs-2.0; u[3] = sxs+2.0;
19429 x[4] = sys; nbd[4] = 2; l[4] = sys-2.0; u[4] = sys+2.0;
19430
19431
19432 // We start the iteration by initializing task.
19433 // (**MUST clear remaining chars in task with spaces (else crash)!**)
19434 strcpy(task,"START");
19435 for (int i=5;i<60;i++) task[i]=' ';
19436
19437 // This is the call to the L-BFGS-B code.
19438 // (* call the L-BFGS-B routine with task='START' once before loop *)
19439 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
19440 int step = 1;
19441
19442 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *)
19443 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) {
19444
19445 if (strncmp(task,"FG",2)==0) {
19446 // the minimization routine has returned to request the
19447 // function f and gradient g values at the current x
19448
19449 // Compute function value f for the sample problem.
19450 proj = new EMData();
19451 proj2 = new EMData();
19452 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb);
19453 proj->fft_shuffle();
19454 proj->center_origin_fft();
19455 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f));
19456 proj->do_ift_inplace();
19457 int M = proj->get_ysize()/2;
19458 proj2 = proj->window_center(M);
19459 f = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
19460 //f = -f;
19461 delete proj;
19462 delete proj2;
19463
19464 // Compute gradient g for the sample problem.
19465 float dt = 1.0e-3f;
19466 proj = new EMData();
19467 proj2 = new EMData();
19468 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0]+dt, "theta", (float)x[1], "psi", (float)x[2])), kb);
19469 proj->fft_shuffle();
19470 proj->center_origin_fft();
19471 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f));
19472 proj->do_ift_inplace();
19473 proj2 = proj->window_center(M);
19474 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
19475 //ft = -ft;
19476 delete proj;
19477 delete proj2;
19478 g[0] = (ft-f)/dt;
19479
19480 proj = new EMData();
19481 proj2 = new EMData();
19482 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1]+dt, "psi", (float)x[2])), kb);
19483 proj->fft_shuffle();
19484 proj->center_origin_fft();
19485 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f));
19486 proj->do_ift_inplace();
19487 proj2 = proj->window_center(M);
19488 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
19489 //ft = -ft;
19490 delete proj;
19491 delete proj2;
19492 g[1] = (ft-f)/dt;
19493
19494 proj = new EMData();
19495 proj2 = new EMData();
19496 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2]+dt)), kb);
19497 proj->fft_shuffle();
19498 proj->center_origin_fft();
19499 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f));
19500 proj->do_ift_inplace();
19501 proj2 = proj->window_center(M);
19502 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
19503 //ft = -ft;
19504 delete proj;
19505 delete proj2;
19506 g[2] = (ft-f)/dt;
19507
19508 proj = new EMData();
19509 proj2 = new EMData();
19510 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb);
19511 proj->fft_shuffle();
19512 proj->center_origin_fft();
19513 proj->process_inplace("filter.shift", Dict("x_shift", x[3]+dt, "y_shift", x[4], "z_shift", 0.0f));
19514 proj->do_ift_inplace();
19515 proj2 = proj->window_center(M);
19516 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
19517 //ft = -ft;
19518 delete proj;
19519 delete proj2;
19520 g[3] = (ft-f)/dt;
19521
19522 proj = new EMData();
19523 proj2 = new EMData();
19524 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb);
19525 proj->fft_shuffle();
19526 proj->center_origin_fft();
19527 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4]+dt, "z_shift", 0.0f));
19528 proj->do_ift_inplace();
19529 proj2 = proj->window_center(M);
19530 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
19531 //ft = -ft;
19532 delete proj;
19533 delete proj2;
19534 g[4] = (ft-f)/dt;
19535 }
19536
19537 //c go back to the minimization routine.
19538 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
19539 step++;
19540 }
19541
19542 //printf("Total step is %d\n", step);
19543 vector<float> res;
19544 res.push_back(static_cast<float>(x[0]));
19545 res.push_back(static_cast<float>(x[1]));
19546 res.push_back(static_cast<float>(x[2]));
19547 res.push_back(static_cast<float>(x[3]));
19548 res.push_back(static_cast<float>(x[4]));
19549 //res.push_back(step);
19550 return res;
19551 }
|
|
||||||||||||||||||||||||||||||||
|
Creates a Two D Test Pattern.
Definition at line 234 of file util_sparx.cpp. References b, C, flag, pi, q, real2FH(), set_complex(), EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), set_ri(), EMAN::EMData::set_ri(), EMAN::EMData::set_shuffled(), EMAN::EMData::set_size(), sqrt(), EMAN::EMData::to_zero(), update(), EMAN::EMData::update(), x, and y. 00235 {
00236 ENTERFUNC;
00237 int Mid= (Size+1)/2;
00238
00239 if (flag==0) { // This is the real function
00240 EMData* ImBW = new EMData();
00241 ImBW->set_size(Size,Size,1);
00242 ImBW->to_zero();
00243
00244 float tempIm;
00245 float x,y;
00246
00247 for (int ix=(1-Mid); ix<Mid; ix++){
00248 for (int iy=(1-Mid); iy<Mid; iy++){
00249 x = (float)ix;
00250 y = (float)iy;
00251 tempIm= static_cast<float>( (1/(2*M_PI)) * cos(p*x)* cos(q*y) * exp(-.5*x*x/(a*a))* exp(-.5*y*y/(b*b)) );
00252 (*ImBW)(ix+Mid-1,iy+Mid-1) = tempIm * exp(.5f*p*p*a*a)* exp(.5f*q*q*b*b);
00253 }
00254 }
00255 ImBW->update();
00256 ImBW->set_complex(false);
00257 ImBW->set_ri(true);
00258
00259 return ImBW;
00260 }
00261 else if (flag==1) { // This is the Fourier Transform
00262 EMData* ImBWFFT = new EMData();
00263 ImBWFFT ->set_size(2*Size,Size,1);
00264 ImBWFFT ->to_zero();
00265
00266 float r,s;
00267
00268 for (int ir=(1-Mid); ir<Mid; ir++){
00269 for (int is=(1-Mid); is<Mid; is++){
00270 r = (float)ir;
00271 s = (float)is;
00272 (*ImBWFFT)(2*(ir+Mid-1),is+Mid-1)= cosh(p*r*a*a) * cosh(q*s*b*b) *
00273 exp(-.5f*r*r*a*a)* exp(-.5f*s*s*b*b);
00274 }
00275 }
00276 ImBWFFT->update();
00277 ImBWFFT->set_complex(true);
00278 ImBWFFT->set_ri(true);
00279 ImBWFFT->set_shuffled(true);
00280 ImBWFFT->set_fftodd(true);
00281
00282 return ImBWFFT;
00283 }
00284 else if (flag==2 || flag==3) { // This is the projection in Real Space
00285 float alpha = static_cast<float>( alphaDeg*M_PI/180.0 );
00286 float C=cos(alpha);
00287 float S=sin(alpha);
00288 float D= sqrt(S*S*b*b + C*C*a*a);
00289 //float D2 = D*D; PAP - to get rid of warning
00290
00291 float P = p * C *a*a/D ;
00292 float Q = q * S *b*b/D ;
00293
00294 if (flag==2) {
00295 EMData* pofalpha = new EMData();
00296 pofalpha ->set_size(Size,1,1);
00297 pofalpha ->to_zero();
00298
00299 float Norm0 = D*(float)sqrt(2*pi);
00300 float Norm1 = exp( .5f*(P+Q)*(P+Q)) / Norm0 ;
00301 float Norm2 = exp( .5f*(P-Q)*(P-Q)) / Norm0 ;
00302 float sD;
00303
00304 for (int is=(1-Mid); is<Mid; is++){
00305 sD = is/D ;
00306 (*pofalpha)(is+Mid-1) = Norm1 * exp(-.5f*sD*sD)*cos(sD*(P+Q))
00307 + Norm2 * exp(-.5f*sD*sD)*cos(sD*(P-Q));
00308 }
00309 pofalpha-> update();
00310 pofalpha-> set_complex(false);
00311 pofalpha-> set_ri(true);
00312
00313 return pofalpha;
00314 }
00315 if (flag==3) { // This is the projection in Fourier Space
00316 float vD;
00317
00318 EMData* pofalphak = new EMData();
00319 pofalphak ->set_size(2*Size,1,1);
00320 pofalphak ->to_zero();
00321
00322 for (int iv=(1-Mid); iv<Mid; iv++){
00323 vD = iv*D ;
00324 (*pofalphak)(2*(iv+Mid-1)) = exp(-.5f*vD*vD)*(cosh(vD*(P+Q)) + cosh(vD*(P-Q)) );
00325 }
00326 pofalphak-> update();
00327 pofalphak-> set_complex(false);
00328 pofalphak-> set_ri(true);
00329
00330 return pofalphak;
00331 }
00332 }
00333 else if (flag==4) {
00334 cout <<" FH under construction";
00335 EMData* OutFT= TwoDTestFunc(Size, p, q, a, b, 1);
00336 EMData* TryFH= OutFT -> real2FH(4.0);
00337 return TryFH;
00338 } else {
00339 cout <<" flag must be 0,1,2,3, or 4";
00340 }
00341
00342 EXITFUNC;
00343 return 0;
00344 }
|
|
||||||||||||||||||||||||
|
Definition at line 4583 of file util_sparx.cpp. References EMAN::EMData::get_data(), numr, PI2, tot, and EMAN::EMData::update(). 04583 {
04584 int nring = numr.size()/3;
04585 float *ave = avep->get_data();
04586 float *dat = datp->get_data();
04587 int i, j, numr3i, np;
04588 float arg, cs, si;
04589 int maxrin = numr(3,nring);
04590 if(mirror == 1) { //for mirrored data has to be conjugated
04591 for (i=1; i<=nring; i++) {
04592 numr3i = numr(3,i);
04593 np = numr(2,i)-1;
04594 ave[np] += dat[np];
04595 ave[np+1] += static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) );
04596 for (j=2; j<numr3i; j=j+2) {
04597 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin );
04598 cs = cos(arg);
04599 si = sin(arg);
04600 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg))
04601 ave[np + j] += dat[np + j]*cs - dat[np + j +1]*si;
04602 ave[np + j +1] -= dat[np + j]*si + dat[np + j +1]*cs;
04603 }
04604 }
04605 } else {
04606 for (i=1; i<=nring; i++) {
04607 numr3i = numr(3,i);
04608 np = numr(2,i)-1;
04609 ave[np] += dat[np];
04610 ave[np+1] += static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) );
04611 for (j=2; j<numr3i; j=j+2) {
04612 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin );
04613 cs = cos(arg);
04614 si = sin(arg);
04615 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg))
04616 ave[np + j] += dat[np + j]*cs - dat[np + j +1]*si;
04617 ave[np + j +1] += dat[np + j]*si + dat[np + j +1]*cs;
04618 }
04619 }
04620 }
04621 avep->update();
04622 EXITFUNC;
04623 }
|
|
||||||||||||
|
Definition at line 1053 of file util.h. Referenced by multi_align_error_func(). 01060 {
|
|
|
Definition at line 20557 of file util_sparx.cpp. References data, dm, EMAN::EMData::get_ysize(), and ny. 20557 {
20558 const float step=0.001f;
20559 int ny = d->get_ysize();
20560 // input emdata should have size 2xN, where N is number of points
20561 // output vector should be 2xN, first element is the number of elements
20562 // associated with this point, second is 0 is the element is touching the border, 1 if it is interior
20563 vector<float> group(2*ny);
20564 for(int i=0; i<2*ny; i++) group[i] = 0.0f;
20565 int K = int(1.0f/step) +1;
20566 int hit = 0;
20567 for(int kx=0; kx<=K; kx++) {
20568 float tx = kx*step;
20569 for(int ky=0; ky<=K; ky++) {
20570 float ty = ky*step;
20571 float dm = 1.0e23f;
20572 for(int i=0; i<ny; i++) {
20573 float qd = pow(tx-(*d)(0,i),2) + pow(ty-(*d)(1,i),2);
20574 if( qd < dm) {
20575 dm = qd;
20576 hit = i;
20577 }
20578 }
20579 data(0,hit) += 1.0f;
20580 if(kx == 0 || ky == 0 || kx == K || ky == K) data(1,hit) = 1.0f;
20581 }
20582 }
20583 return group;
20584 }
|
|
||||||||||||||||||||
|
Definition at line 7600 of file util_sparx.cpp. References ang_to_xyz(), areav_(), Assert, disorder2(), flip23(), key, phi, status, theta, trmsh3_(), weight, x, and y. 07601 {
07602
07603 ENTERFUNC;
07604
07605 int *list, *lptr, *lend, *iwk, *key,*lcnt,*indx,*good;
07606 int nt6, n, ier, nout, lnew, mdup, nd;
07607 int i,k,mt,status;
07608
07609
07610 double *ds, *x, *y, *z;
07611 double tol = 1.0e-8;
07612 double dtol = 15;
07613 double a;
07614
07615 /*if(last){
07616 if(medium>nt) n = nt+nt;
07617 else n = nt+nt-medium+1;
07618 }
07619 else{
07620 n=nt;
07621 }*/
07622
07623 n = nt + nt;
07624
07625 nt6 = n*6;
07626
07627 list = (int*)calloc(nt6,sizeof(int));
07628 lptr = (int*)calloc(nt6,sizeof(int));
07629 lend = (int*)calloc(n ,sizeof(int));
07630 iwk = (int*)calloc(n ,sizeof(int));
07631 good = (int*)calloc(n ,sizeof(int));
07632 key = (int*)calloc(n ,sizeof(int));
07633 indx = (int*)calloc(n ,sizeof(int));
07634 lcnt = (int*)calloc(n ,sizeof(int));
07635
07636 ds = (double*) calloc(n,sizeof(double));
07637 x = (double*) calloc(n,sizeof(double));
07638 y = (double*) calloc(n,sizeof(double));
07639 z = (double*) calloc(n,sizeof(double));
07640
07641 if (list == NULL ||
07642 lptr == NULL ||
07643 lend == NULL ||
07644 iwk == NULL ||
07645 good == NULL ||
07646 key == NULL ||
07647 indx == NULL ||
07648 lcnt == NULL ||
07649 x == NULL ||
07650 y == NULL ||
07651 z == NULL ||
07652 ds == NULL) {
07653 printf("memory allocation failure!\n");
07654 exit(1);
07655 }
07656
07657 bool colinear=true;
07658 while(colinear)
07659 {
07660
07661 L1:
07662 for(i = 0; i<nt; i++){
07663 x[i] = theta[i];
07664 y[i] = phi[i];
07665 x[nt+i] = 180.0 - x[i];
07666 y[nt+i] = 180.0 + y[i];
07667 }
07668
07669 Util::disorder2(x, y, key, n);
07670
07671 // check if the first three angles are not close, else shuffle
07672 double val;
07673 for(k=0; k<2; k++){
07674 for(i=k+1; i<3; i++){
07675 val = (x[i]-x[k])*(x[i]-x[k]) + (y[i]-y[k])*(y[i]-y[k]);
07676 if( val < dtol) {
07677 goto L1;
07678 }
07679 }
07680 }
07681
07682 Util::ang_to_xyz(x, y, z, n);
07683
07684 // Make sure that first three has no duplication
07685 bool dupnode=true;
07686 dupnode=true;
07687 while(dupnode)
07688 {
07689 for(k=0; k<2; k++){
07690 for(i=k+1; i<3; i++){
07691 if( x[i]*x[k]+y[i]*y[k]+z[i]*z[k] > 1.0-tol) {
07692 Util::flip23(x, y, z, key, k, n);
07693 continue;
07694 }
07695 }
07696 }
07697 dupnode = false;
07698 }
07699
07700
07701 ier = 0;
07702
07703 status = Util::trmsh3_(&n,&tol,x,y,z,&nout,list,lptr,lend,&lnew, indx, lcnt, iwk, good, ds, &ier);
07704
07705 if (status != 0) {
07706 printf(" error in trmsh3 \n");
07707 exit(1);
07708 }
07709
07710 if (ier > 0) {
07711 printf("*** Error in TRMESH: duplicate nodes encountered ***\n");
07712 exit(1);
07713 }
07714
07715 mdup=n-nout;
07716 if (ier == -2) {
07717 //printf("in TRMESH:the first three nodes are colinear*** disorder again\n");
07718 }
07719 else
07720 {
07721 colinear=false;
07722 }
07723 }
07724
07725
07726 Assert( ier != -2 );
07727 // Create a list of unique nodes GOOD, the numbers refer to locations on the full list
07728 // INDX contains node numbers from the squeezed list
07729 nd=0;
07730 for (k=1; k<=n; k++){
07731 if (indx[k-1]>0) {
07732 nd++;
07733 good[nd-1]=k;
07734 }
07735 }
07736
07737 //
07738 // *** Compute the Voronoi region areas.
07739 //
07740 for(i = 1; i<=nout; i++) {
07741 k=good[i-1];
07742 // We only need n weights from hemisphere
07743 if (key[k-1] <= nt) {
07744 // CALCULATE THE AREA
07745 a = Util::areav_(&i, &nout, x, y, z, list, lptr, lend, &ier);
07746 if (ier != 0){
07747 // We set the weight to -1, this will signal the error in the calling
07748 // program, as the area will turn out incorrect
07749 printf(" *** error in areav: ier = %d ***\n", ier);
07750 weight[key[k-1]-1] =-1.0;
07751 } else {
07752 // Assign the weight
07753 weight[key[k-1]-1]=a/lcnt[i-1];
07754 }
07755 }
07756 }
07757
07758
07759 // Fill out the duplicated weights
07760 for(i = 1; i<=n; i++){
07761 mt =- indx[i-1];
07762 if (mt>0){
07763 k = good[mt-1];
07764 // This is a duplicated entry, get the already calculated
07765 // weight and assign it.
07766 // We only need n weights from hemisphere
07767 if (key[i-1] <= nt && key[k-1] <= nt) { weight[key[i-1]-1] = weight[key[k-1]-1];}
07768 }
07769 }
07770
07771 free(list);
07772 free(lend);
07773 free(iwk);
07774 free(good);
07775 free(key);
07776 free(lptr);
07777 free(indx);
07778 free(lcnt);
07779 free(ds);
07780 free(x);
07781 free(y);
07782 free(z);
07783
07784
07785 EXITFUNC;
07786 }
|
|
||||||||||||||||||||
|
|
|
||||||||||||
|
Definition at line 7177 of file util_sparx.cpp. References hsortd(), ImageFormatException, key, LOGERR, phi, theta, voronoi(), and weight. 07178 {
07179
07180 ENTERFUNC;
07181
07182 if ( th.size() != ph.size() ) {
07183 LOGERR("images not same size");
07184 throw ImageFormatException( "images not same size");
07185 }
07186
07187 // rand_seed
07188 srand(10);
07189
07190 int i,*key;
07191 int len = th.size();
07192 double *theta,*phi,*weight;
07193 theta = (double*) calloc(len,sizeof(double));
07194 phi = (double*) calloc(len,sizeof(double));
07195 weight = (double*) calloc(len,sizeof(double));
07196 key = (int*) calloc(len,sizeof(int));
07197 const float *thptr, *phptr;
07198
07199 thptr = &th[0];
07200 phptr = &ph[0];
07201 for(i=1;i<=len;i++){
07202 key(i) = i;
07203 weight(i) = 0.0;
07204 }
07205
07206 for(i = 0;i<len;i++){
07207 theta[i] = thptr[i];
07208 phi[i] = phptr[i];
07209 }
07210
07211 // sort by theta
07212 Util::hsortd(theta, phi, key, len, 1);
07213
07214 //Util::voronoidiag(theta,phi, weight, len);
07215 Util::voronoi(phi, theta, weight, len);
07216
07217 //sort by key
07218 Util::hsortd(weight, weight, key, len, 2);
07219
07220 free(theta);
07221 free(phi);
07222 free(key);
07223 vector<double> wt;
07224 double count = 0;
07225 for(i=1; i<= len; i++)
07226 {
07227 wt.push_back(weight(i));
07228 count += weight(i);
07229 }
07230
07231 //if( abs(count-6.28) > 0.1 )
07232 //{
07233 // printf("Warning: SUM OF VORONOI CELLS AREAS IS %lf, should 2*PI\n", count);
07234 //}
07235
07236 free(weight);
07237
07238 EXITFUNC;
07239 return wt;
07240
07241 }
|
|
||||||||||||||||||||||||||||||||
|
Definition at line 5335 of file util_sparx.cpp. References EMAN::EMData::copy_empty_head(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, inp, NullPointerException, nx, ny, outp, EMAN::EMData::set_size(), and EMAN::EMData::update(). 05336 {
05337 /* Exception Handle */
05338 if (!img) throw NullPointerException("NULL input image");
05339 /* ============================== */
05340
05341 // Get the size of the input image
05342 int nx=img->get_xsize(), ny=img->get_ysize(), nz=img->get_zsize();
05343 /* ============================== */
05344
05345 /* Exception Handle */
05346 if(new_nx>nx || new_ny>ny || new_nz>nz)
05347 throw ImageDimensionException("The size of the windowed image cannot exceed the input image size.");
05348 if((nx/2)-(new_nx/2)+x_offset<0 || (ny/2)-(new_ny/2)+y_offset<0 || (nz/2)-(new_nz/2)+z_offset<0)
05349 throw ImageDimensionException("The offset inconsistent with the input image size.");
05350 if(x_offset>((nx-(nx/2))-(new_nx-(new_nx/2))) || y_offset>((ny-(ny/2))-(new_ny-(new_ny/2))) || z_offset>((nz-(nz/2))-(new_nz-(new_nz/2))))
05351 throw ImageDimensionException("The offset inconsistent with the input image size.");
05352 /* ============================== */
05353
05354 /* Calculation of the start point */
05355 int new_st_x = nx/2-new_nx/2 + x_offset,
05356 new_st_y = ny/2-new_ny/2 + y_offset,
05357 new_st_z = nz/2-new_nz/2 + z_offset;
05358 /* ============================== */
05359
05360 /* Exception Handle */
05361 if (new_st_x<0 || new_st_y<0 || new_st_z<0) // WHAT HAPPENS WITH THE END POINT CHECK?? PAP
05362 throw ImageDimensionException("The offset inconsistent with the input image size.");
05363 /* ============================== */
05364
05365 EMData* wind = img->copy_empty_head();
05366 wind->set_size(new_nx, new_ny, new_nz);
05367 float *outp=wind->get_data();
05368 float *inp=img->get_data();
05369
05370 for (int k=0; k<new_nz; k++)
05371 for(int j=0; j<new_ny; j++)
05372 for(int i=0; i<new_nx; i++)
05373 outp(i,j,k) = inp(i,j,k);
05374 wind->update();
05375 return wind;
05376 }
|
|
||||||||||||||||||||
|
Definition at line 5823 of file util_sparx.cpp. References EMAN::EMData::depad(), EMAN::EMData::do_fft_inplace(), EMAN::EMData::do_ift_inplace(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), max, min, EMAN::EMData::norm_pad(), PROJ, q, EMAN::EMData::set_size(), SS, EMAN::EMData::to_zero(), EMAN::EMData::update(), W, and Y. 05824 {
05825 int NSAM,NROW,NNNN,NR2,L,JY,KX,NANG;
05826 float WW,OX,OY;
05827
05828 NSAM = PROJ->get_xsize();
05829 NROW = PROJ->get_ysize();
05830 int ntotal = NSAM*NROW;
05831 float q = 2.0f;
05832 float qt = 8.0f/q;
05833 // Fix for padding 2x
05834 int ipad = 1;
05835 NSAM *= ipad;
05836 NROW *= ipad;
05837 NNNN = NSAM+2-(NSAM%2);
05838 int NX2 = NSAM/2;
05839 NR2 = NROW/2;
05840
05841 NANG = int(SS.size())/6;
05842
05843 EMData* W = new EMData();
05844 int Wnx = NNNN/2;
05845 W->set_size(Wnx,NROW,1);
05846 W->to_zero();
05847 float *Wptr = W->get_data();
05848 float *PROJptr = PROJ->get_data();
05849 for (L=1; L<=NANG; L++) {
05850 float tmp1 = SS(3,K)*SS(4,L)*(SS(1,K)*SS(1,L) + SS(2,K)*SS(2,L)) - SS(3,L)*SS(4,K);
05851 float tmp2 = SS(4,L)*( SS(1,K)*SS(2,L) - SS(1,L)*SS(2,K) );
05852 OX = SS(6,K)*tmp2 + SS(5,K)*tmp1;
05853 OY = SS(5,K)*tmp2 - SS(6,K)*tmp1;
05854 if(OX < 0.0f) {
05855 OX = -OX;
05856 OY = -OY;
05857 }
05858
05859 if( fabs(OX) > 1.0e-6f || fabs(OY) > 1.0e6f ) {
05860 for(int J=1;J<=NROW;J++) {
05861 JY = (J-1);
05862 if(JY > NR2) JY -= NROW;
05863 #ifdef _WIN32
05864 int xma = _cpp_min(int(0.5f+(q-JY*OY)/OX),NX2);
05865 int xmi = _cpp_max(int((-q-JY*OY)/OX+0.5+NSAM)-NSAM,0);
05866 #else
05867 int xma = std::min(int(0.5f+(q-JY*OY)/OX),NX2);
05868 int xmi = std::max(int((-q-JY*OY)/OX+0.5+NSAM)-NSAM,0);
05869 #endif //_WIN32
05870 if( xmi <= xma) {
05871 for(int I=xmi;I<=xma;I++) {
05872 float Y = fabs(OX*I + OY*JY);
05873 W(I+1,J) += exp(-qt*Y*Y);
05874 //cout << " L "<<L << " I "<<I << " JY "<<JY << " ARG "<<qt*Y*Y <<endl;
05875 }
05876 }
05877 }
05878 } else {
05879 for(int J=1;J<=NROW;J++) for(int I=1;I<=NNNN/2;I++) W(I,J) += 1.0f;
05880 }
05881 }
05882 EMData* proj_in = PROJ;
05883
05884 PROJ = PROJ->norm_pad( false, ipad);
05885 PROJ->do_fft_inplace();
05886 PROJ->update();
05887 //cout << " x "<<PROJ->get_xsize() << " y "<<PROJ->get_ysize() <<endl;
05888 PROJptr = PROJ->get_data();
05889
05890 float WNRMinv,temp;
05891 float osnr = 1.0f/SNR;
05892 WNRMinv = 1.0f/W(1,1);
05893 for(int J=1;J<=NROW;J++) {
05894 JY = J-1;
05895 if( JY > NR2) JY -= NROW;
05896 float sy = JY;
05897 sy /= NROW;
05898 sy *= sy;
05899 for(int I=1;I<=NNNN;I+=2) {
05900 KX = (I+1)/2;
05901 temp = W(KX,J)*WNRMinv;
05902 WW = temp/(temp*temp + osnr);
05903 // This is supposed to fix fall-off due to Gaussian function in the weighting function
05904 float sx = KX-1;
05905 sx /= NSAM;
05906 WW *= exp(qt*(sy + sx*sx));
05907 PROJ(I,J) *= WW;
05908 PROJ(I+1,J) *= WW;
05909 }
05910 }
05911 delete W; W = 0;
05912 PROJ->do_ift_inplace();
05913 PROJ->depad();
05914
05915 float* data_src = PROJ->get_data();
05916 float* data_dst = proj_in->get_data();
05917
05918 for( int i=0; i < ntotal; ++i ) data_dst[i] = data_src[i];
05919
05920 proj_in->update();
05921
05922 delete PROJ;
05923 }
|
|
||||||||||||||||||||
|
Definition at line 6017 of file util_sparx.cpp. References AMAX1, AMIN1, CC, CP, EMAN::EMData::depad(), EMAN::EMData::do_fft_inplace(), EMAN::EMData::do_ift_inplace(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::norm_pad(), PROJ, RI, EMAN::EMData::set_size(), sqrt(), SS, EMAN::EMData::to_one(), EMAN::EMData::update(), VP, VV, and W. 06018 {
06019 float rad2deg =(180.0f/3.1415926f);
06020 float deg2rad = (3.1415926f/180.0f);
06021
06022 int NSAM,NROW,NNNN,NR2,NANG,L,JY;
06023
06024 NSAM = PROJ->get_xsize();
06025 NROW = PROJ->get_ysize();
06026 NNNN = NSAM+2-(NSAM%2);
06027 NR2 = NROW/2;
06028 NANG = int(SS.size())/6;
06029
06030 float RI[9];
06031 RI(1,1)=SS(1,NUMP)*SS(3,NUMP)*SS(5,NUMP)-SS(2,NUMP)*SS(6,NUMP);
06032 RI(2,1)=-SS(1,NUMP)*SS(3,NUMP)*SS(6,NUMP)-SS(2,NUMP)*SS(5,NUMP);
06033 RI(3,1)=SS(1,NUMP)*SS(4,NUMP);
06034 RI(1,2)=SS(2,NUMP)*SS(3,NUMP)*SS(5,NUMP)+SS(1,NUMP)*SS(6,NUMP);
06035 RI(2,2)=-SS(2,NUMP)*SS(3,NUMP)*SS(6,NUMP)+SS(1,NUMP)*SS(5,NUMP);
06036 RI(3,2)=SS(2,NUMP)*SS(4,NUMP);
06037 RI(1,3)=-SS(4,NUMP)*SS(5,NUMP);
06038 RI(2,3)=SS(4,NUMP)*SS(6,NUMP);
06039 RI(3,3)=SS(3,NUMP);
06040
06041 float THICK=static_cast<float>( NSAM)/DIAMETER/2.0f ;
06042
06043 EMData* W = new EMData();
06044 int Wnx = NNNN/2;
06045 W->set_size(NNNN/2,NROW,1);
06046 W->to_one();
06047 float *Wptr = W->get_data();
06048
06049 float ALPHA,TMP,FV,RT,FM,CCN,CC[3],CP[2],VP[2],VV[3];
06050
06051 for (L=1; L<=NANG; L++) {
06052 if (L != NUMP) {
06053 CC(1)=SS(2,L)*SS(4,L)*SS(3,NUMP)-SS(3,L)*SS(2,NUMP)*SS(4,NUMP);
06054 CC(2)=SS(3,L)*SS(1,NUMP)*SS(4,NUMP)-SS(1,L)*SS(4,L)*SS(3,NUMP);
06055 CC(3)=SS(1,L)*SS(4,L)*SS(2,NUMP)*SS(4,NUMP)-SS(2,L)*SS(4,L)*SS(1,NUMP)*SS(4,NUMP);
06056
06057 TMP = sqrt(CC(1)*CC(1) + CC(2)*CC(2) + CC(3)*CC(3));
06058 CCN=static_cast<float>( AMAX1( AMIN1(TMP,1.0) ,-1.0) );
06059 ALPHA=rad2deg*float(asin(CCN));
06060 if (ALPHA>180.0f) ALPHA=ALPHA-180.0f;
06061 if (ALPHA>90.0f) ALPHA=180.0f-ALPHA;
06062 if(ALPHA<1.0E-6) {
06063 for(int J=1;J<=NROW;J++) for(int I=1;I<=NNNN/2;I++) W(I,J)+=1.0;
06064 } else {
06065 FM=THICK/(fabs(sin(ALPHA*deg2rad)));
06066 CC(1) = CC(1)/CCN;CC(2) = CC(2)/CCN;CC(3) = CC(3)/CCN;
06067 VV(1)= SS(2,L)*SS(4,L)*CC(3)-SS(3,L)*CC(2);
06068 VV(2)= SS(3,L)*CC(1)-SS(1,L)*SS(4,L)*CC(3);
06069 VV(3)= SS(1,L)*SS(4,L)*CC(2)-SS(2,L)*SS(4,L)*CC(1);
06070 CP(1) = 0.0;CP(2) = 0.0;
06071 VP(1) = 0.0;VP(2) = 0.0;
06072
06073 CP(1) = CP(1) + RI(1,1)*CC(1) + RI(1,2)*CC(2) + RI(1,3)*CC(3);
06074 CP(2) = CP(2) + RI(2,1)*CC(1) + RI(2,2)*CC(2) + RI(2,3)*CC(3);
06075 VP(1) = VP(1) + RI(1,1)*VV(1) + RI(1,2)*VV(2) + RI(1,3)*VV(3);
06076 VP(2) = VP(2) + RI(2,1)*VV(1) + RI(2,2)*VV(2) + RI(2,3)*VV(3);
06077
06078 TMP = CP(1)*VP(2)-CP(2)*VP(1);
06079
06080 // PREVENT TMP TO BE TOO SMALL, SIGN IS IRRELEVANT
06081 TMP = AMAX1(1.0E-4f,fabs(TMP));
06082 float tmpinv = 1.0f/TMP;
06083 for(int J=1;J<=NROW;J++) {
06084 JY = (J-1);
06085 if (JY>NR2) JY=JY-NROW;
06086 for(int I=1;I<=NNNN/2;I++) {
06087 FV = fabs((JY*CP(1)-(I-1)*CP(2))*tmpinv);
06088 RT = 1.0f-FV/FM;
06089 W(I,J) += ((RT>0.0f)*RT);
06090 }
06091 }
06092 }
06093 }
06094 }
06095
06096 EMData* proj_in = PROJ;
06097
06098 PROJ = PROJ->norm_pad( false, 1);
06099 PROJ->do_fft_inplace();
06100 PROJ->update();
06101 float *PROJptr = PROJ->get_data();
06102
06103 int KX;
06104 float WW;
06105 for(int J=1; J<=NROW; J++)
06106 for(int I=1; I<=NNNN; I+=2) {
06107 KX = (I+1)/2;
06108 WW = 1.0f/W(KX,J);
06109 PROJ(I,J) = PROJ(I,J)*WW;
06110 PROJ(I+1,J) = PROJ(I+1,J)*WW;
06111 }
06112 delete W; W = 0;
06113 PROJ->do_ift_inplace();
06114 PROJ->depad();
06115
06116 float* data_src = PROJ->get_data();
06117 float* data_dst = proj_in->get_data();
06118
06119 int ntotal = NSAM*NROW;
06120 for( int i=0; i < ntotal; ++i ) data_dst[i] = data_src[i];
06121
06122 proj_in->update();
06123 delete PROJ;
06124 }
|
1.3.9.1