#include <util.h>
Static Public Member Functions | |
static 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. | |
static Dict | coveig_for_py (int ncov, const vector< float > &covmatpy) |
same function than Util::coveig but wrapped to use directly in python code | |
static void | WTF (EMData *PROJ, vector< float > SS, float SNR, int K) |
static void | WTM (EMData *PROJ, vector< float > SS, int DIAMETER, int NUMP) |
static Dict | CANG (float PHI, float THETA, float PSI) |
static void | BPCQ (EMData *B, EMData *CUBE, const int radius) |
static vector< float > | infomask (EMData *Vol, EMData *mask, bool) |
static void | colreverse (float *beg, float *end, int nx) |
static void | slicereverse (float *beg, float *end, int nx, int ny) |
static void | cyclicshift (EMData *image, Dict params) |
Performs inplace integer cyclic shift as specified by the "dx","dy","dz" parameters on a 3d volume. | |
static Dict | im_diff (EMData *V1, EMData *V2, EMData *mask=0) |
static EMData * | TwoDTestFunc (int Size, float p, float q, float a, float b, int flag=0, float alphaDeg=0) |
Creates a Two D Test Pattern. | |
static 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. | |
static 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. | |
static 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. | |
static 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. | |
static 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. | |
static float | quadri (float x, float y, int nx, int ny, float *image) |
Quadratic interpolation (2D). | |
static float | quadri_background (float x, float y, int nx, int ny, float *image, int xnew, int ynew) |
Quadratic interpolation (2D). | |
static float | get_pixel_conv_new (int nx, int ny, int nz, float delx, float dely, float delz, float *data, Util::KaiserBessel &kb) |
static 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) |
static std::complex< float > | extractpoint2 (int nx, int ny, float nuxnew, float nuynew, EMData *fimage, Util::KaiserBessel &kb) |
static float | bilinear (float xold, float yold, int nsam, int nrow, float *xim) |
static float | triquad (float r, float s, float t, float *fdata) |
Quadratic interpolation (3D). | |
static EMData * | Polar2D (EMData *image, vector< int > numr, string mode) |
static EMData * | Polar2Dm (EMData *image, float cns2, float cnr2, vector< int > numr, string cmode) |
static void | alrl_ms (float *xim, int nsam, int nrow, float cns2, float cnr2, int *numr, float *circ, int lcirc, int nring, char mode) |
static EMData * | Polar2Dmi (EMData *image, float cns2, float cnr2, vector< int > numr, string cmode, Util::KaiserBessel &kb) |
static void | fftr_q (float *xcmplx, int nv) |
static void | fftr_d (double *xcmplx, int nv) |
static void | fftc_q (float *br, float *bi, int ln, int ks) |
static void | fftc_d (double *br, double *bi, int ln, int ks) |
static void | Frngs (EMData *circ, vector< int > numr) |
This function conducts the Single Precision Fourier Transform for a set of rings. | |
static void | Normalize_ring (EMData *ring, const vector< int > &numr) |
static void | Frngs_inv (EMData *circ, vector< int > numr) |
This function conducts the Single Precision Inverse Fourier Transform for a set of rings. | |
static void | Applyws (EMData *circ, vector< int > numr, vector< float > wr) |
This is a copy of Applyws routine from alignment.py. | |
static Dict | Crosrng_e (EMData *circ1, EMData *circ2, vector< int > numr, int neg) |
static Dict | Crosrng_ew (EMData *circ1, EMData *circ2, vector< int > numr, vector< float > w, int neg) |
static Dict | Crosrng_ms (EMData *circ1, EMData *circ2, vector< int > numr) |
static Dict | Crosrng_ms_delta (EMData *circ1, EMData *circ2, vector< int > numr, float delta_start, float delta) |
static Dict | Crosrng_sm_psi (EMData *circ1, EMData *circ2, vector< int > numr, float psi, int flag, float psimax) |
checks either straight or mirrored position depending on flag input - fourier transforms of rings!! circ1 already multiplied by weights! | |
static Dict | Crosrng_psi (EMData *circ1, EMData *circ2, vector< int > numr, float psi, float psimax) |
checks both straight & mirrored position input - fourier transforms of rings!! circ1 already multiplied by weights! | |
static Dict | Crosrng_ns (EMData *circ1, EMData *circ2, vector< int > numr) |
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! | |
static 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 | |
static 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 | |
static EMData * | Crosrng_msg_s (EMData *circ1, EMData *circ2, vector< int > numr) |
This program is half of the Crosrng_msg. | |
static EMData * | Crosrng_msg_m (EMData *circ1, EMData *circ2, vector< int > numr) |
This program is half of the Crosrng_msg. | |
static vector< float > | Crosrng_msg_vec_p (EMData *circ1, EMData *circ2, vector< int > numr) |
static void | prb1d (double *b, int npoint, float *pos) |
static void | update_fav (EMData *ave, EMData *dat, float tot, int mirror, vector< int > numr) |
static void | sub_fav (EMData *ave, EMData *dat, float tot, int mirror, vector< int > numr) |
static float | ener (EMData *ave, vector< int > numr) |
static float | ener_tot (const vector< EMData * > &data, vector< int > numr, vector< float > tot) |
static Dict | min_dist_real (EMData *image, const vector< EMData * > &data) |
k-means helper | |
static Dict | min_dist_four (EMData *image, const vector< EMData * > &data) |
helper function for k-means | |
static 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. | |
static 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. | |
static 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. | |
static 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. | |
static 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. | |
static 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) |
static 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. | |
static 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. | |
static 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. | |
static int | branch_factor_0 (int *costlist, int *matchlist, int J, int T, int nParts, int curlevel, int max_branching, int LIM) |
static int | branch_factor_2 (int *costlist, int *matchlist, int J, int T, int nParts, int curlevel, int max_branching, int LIM) |
static int | branch_factor_3 (int *costlist, int *matchlist, int J, int T, int nParts, int curlevel, int max_branching, int K, int LIM) |
static int | branch_factor_4 (int *costlist, int *matchlist, int J, int T, int nParts, int curlevel, int max_branching, float stmult) |
static vector< double > | cml_weights (const vector< float > &cml) |
static vector< int > | cml_line_insino (vector< float > Rot, int i_prj, int n_prj) |
2009-03-25 15:35:53 JB. | |
static 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. | |
static vector< double > | cml_init_rot (vector< float > Ori) |
2009-03-25 15:35:05 JB. | |
static vector< float > | cml_update_rot (vector< float > Rot, int iprj, float nph, float th, float nps) |
2009-03-25 15:35:37 JB. | |
static vector< double > | cml_line_in3d (vector< float > Ori, vector< int > seq, int nprj, int nlines) |
2009-03-26 10:46:14 JB. | |
static 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. | |
static vector< double > | cml_spin_psi_now (const vector< EMData * > &data, vector< int > com, int iprj, vector< int > iw, int n_psi, int d_psi, int n_prj) |
static 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. | |
static void | set_line (EMData *img, int posline, EMData *line, int offset, int length) |
This function drop a line (line) to an 2D image (img). | |
static 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). | |
static EMData * | decimate (EMData *img, int x_step, int y_step=1, int z_step=1) |
static 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) |
static 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, const char *params="average") |
static vector< float > | histogram (EMData *image, EMData *mask, int nbins=128, float hmin=0.0f, float hmax=0.0f) |
static Dict | histc (EMData *ref, EMData *img, EMData *mask) |
static 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) |
static 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) |
static EMData * | compress_image_mask (EMData *image, EMData *mask) |
static EMData * | reconstitute_image_mask (EMData *image, EMData *mask) |
Recreates a n-d image using its compressed 1-D form and the mask. | |
static vector< float > | merge_peaks (vector< float > peak1, vector< float > peak2, float p_size) |
static vector< float > | pw_extract (vector< float >pw, int n, int iswi, float ps) |
static 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) |
static 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) |
static 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) |
static float | eval (char *images, EMData *img, vector< int > S, int N, int K, int size) |
static vector< double > | vrdg (const vector< float > &ph, const vector< float > &th) |
static void | hsortd (double *theta, double *phi, int *key, int len, int option) |
static void | voronoidiag (double *theta, double *phi, double *weight, int n) |
static void | voronoi (double *phi, double *theta, double *weight, int nt) |
static void | disorder2 (double *x, double *y, int *key, int len) |
static void | ang_to_xyz (double *x, double *y, double *z, int len) |
static void | flip23 (double *x, double *y, double *z, int *key, int k, int len) |
static bool | cmp1 (tmpstruct tmp1, tmpstruct tmp2) |
static bool | cmp2 (tmpstruct tmp1, tmpstruct tmp2) |
static 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) |
static double | areav_ (int *k, int *n, double *x, double *y, double *z__, int *list, int *lptr, int *lend, int *ier) |
static EMData * | madn_scalar (EMData *img, EMData *img1, float scalar) |
static EMData * | mult_scalar (EMData *img, float scalar) |
static EMData * | addn_img (EMData *img, EMData *img1) |
static EMData * | subn_img (EMData *img, EMData *img1) |
static EMData * | muln_img (EMData *img, EMData *img1) |
static EMData * | divn_img (EMData *img, EMData *img1) |
static EMData * | divn_filter (EMData *img, EMData *img1) |
static void | mad_scalar (EMData *img, EMData *img1, float scalar) |
static void | mul_scalar (EMData *img, float scalar) |
static void | add_img (EMData *img, EMData *img1) |
static void | add_img_abs (EMData *img, EMData *img1) |
static void | add_img2 (EMData *img, EMData *img1) |
static void | sub_img (EMData *img, EMData *img1) |
static void | mul_img (EMData *img, EMData *img1) |
static void | div_img (EMData *img, EMData *img1) |
static void | div_filter (EMData *img, EMData *img1) |
static EMData * | pack_complex_to_real (EMData *img) |
static 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 | |
static 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) |
static vector< int > | assign_groups (std::string matrix_address, int nref, int nima) |
static void | getvec (float phi, float theta, float &x, float &y, float &z, int option=0) |
static float | ang_diff (float v11, float v12, float v13, float v21, float v22, float v23, int &mirror) |
static int | nearest_ang (const vector< float > &vecref, float x, float y, float z) |
static vector< int > | assign_projangles (const vector< float > &projangles, const vector< float > &refangles) |
static vector< int > | nearestk_to_refdir (const vector< float > &projangles, const vector< float > &refangles, const int howmany) |
static vector< int > | group_proj_by_phitheta (const vector< float > &projangles, const vector< float > &ref_ang, const int img_per_grp) |
static 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 | |
static 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 | |
static 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 | |
static vector< float > | hans (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, float ant, string mode, vector< int >numr, float cnx, float cny) |
static 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) | |
static 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, float yrnglocal=-1.0) |
static 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) |
static 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, float yrnglocal=-1.0) |
static 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 | |
static 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. | |
static 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. | |
static 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. | |
static vector< float > | twoD_fine_ali (EMData *image, EMData *refim, EMData *mask, float ang, float sxs, float sys) |
static vector< float > | twoD_fine_ali_G (EMData *image, EMData *refim, EMData *mask, Util::KaiserBessel &kb, float ang, float sxs, float sys) |
static 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) |
static vector< float > | twoD_fine_ali_SD (EMData *image, EMData *refim, EMData *mask, float ang, float sxs, float sys) |
static float | ccc_images (EMData *, EMData *, EMData *, float, float, float) |
static vector< float > | twoD_fine_ali_SD_G (EMData *image, EMData *refim, EMData *mask, Util::KaiserBessel &kb, float ang, float sxs, float sys) |
static float | ccc_images_G (EMData *image, EMData *refim, EMData *mask, Util::KaiserBessel &kb, float ang, float sx, float sy) |
static EMData * | move_points (EMData *img, float qprob, int ri, int ro) |
static EMData * | get_biggest_cluster (EMData *mg) |
static 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) |
static EMData * | ctf_rimg (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) |
static EMData * | ctf2_rimg (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) |
static int | mono (int k1, int k2) |
static int | nint180 (float arg) |
static double | mean (double *x, int n) |
static double | var (double *x, int n) |
static vector< float > | multi_align_error (vector< float > args, vector< float > all_ali_params, int d) |
static double | multi_align_error_func (double *x, vector< float > all_ali_params, int nima, int num_ali, int d) |
static vector< double > | multi_align_error_func2 (double *x, vector< float > all_ali_params, int nima, int num_ali, int d) |
static void | multi_align_error_dfunc (double *x, vector< float > all_ali_params, int nima, int num_ali, double *g, int d) |
static vector< float > | cluster_pairwise (EMData *d, int K, float T, float F) |
static vector< float > | cluster_equalsize (EMData *d) |
static vector< float > | vareas (EMData *d) |
static 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. | |
static void | image_mutation (EMData *img, float mutation_rate) |
static 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. | |
static vector< float > | list_mutation (vector< float > list, float mutation_rate, float min_val, float max_val, int K, int is_mirror) |
static float | restrict1 (float x, int nx) |
static Dict | get_transform_params (EMData *image, string xform, string convention) |
This function returns parameters from Transform object as a Dict object. | |
static void | constrained_helix (vector< EMData * > data, vector< EMData * > fdata, vector< EMData * > refproj, vector< EMData * > rotproj, vector< float > dp_dphi_rise_delta, vector< int > nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc, bool FindPsi, float psi_max, vector< EMData * > crefim, vector< int > numr, int maxrin, string mode, int cnx, int cny) |
static void | constrained_helix_test (vector< EMData * > data, vector< EMData * > fdata, vector< EMData * > refproj, vector< EMData * > rotproj, vector< float > dp_dphi_rise_delta, vector< int > nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc, bool FindPsi, float psi_max, vector< EMData * > crefim, vector< int > numr, int maxrin, string mode, int cnx, int cny) |
static Dict | predict (float phig, float yg, float dst, float sgn, float ysgn, float dpp, float dphi, bool backpred) |
static int | MUTEX_INIT (MUTEX *mutex) |
static int | MUTEX_LOCK (MUTEX *mutex) |
static int | MUTEX_UNLOCK (MUTEX *mutex) |
static void | ap2ri (float *data, size_t n) |
convert complex data array from Amplitude/Phase format into Real/Imaginary format. | |
static void | flip_complex_phase (float *data, size_t n) |
flip the phase of a complex data array. | |
static 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 | |
static int | file_lock_wait (FILE *file) |
lock a file. | |
static bool | check_file_by_magic (const void *first_block, const char *magic) |
check whether a file starts with certain magic string. | |
static bool | is_file_exist (const string &filename) |
check whether a file exists or not | |
static void | flip_image (float *data, size_t nx, size_t ny) |
Vertically flip the data of a 2D real image. | |
static vector< EMData * > | svdcmp (const vector< EMData * > &data, int nvec) |
Perform singular value decomposition on a set of images. | |
static string | str_to_lower (const string &s) |
Return a lower case version of the argument string. | |
static bool | sstrncmp (const char *s1, const char *s2) |
Safe string compare. | |
static string | int2str (int n) |
Get a string format of an integer, e.g. | |
static string | get_line_from_string (char **str) |
Extract a single line from a multi-line string. | |
static 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. | |
static 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. | |
static 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". | |
static 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. | |
static 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. | |
static 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". | |
static string | change_filename_ext (const string &old_filename, const string &new_ext) |
Change a file's extension and return the new filename. | |
static string | remove_filename_ext (const string &filename) |
Remove a filename's extension and return the new filename. | |
static string | get_filename_ext (const string &filename) |
Get a filename's extension. | |
static string | sbasename (const string &filename) |
Get a filename's basename. | |
static 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. | |
static 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 | |
static void | save_data (const vector< float > &x_array, const vector< float > &y_array, const string &filename) |
Save (x y) data array into a file. | |
static void | save_data (float x0, float dx, const vector< float > &y_array, const string &filename) |
Save x, y data into a file. | |
static void | save_data (float x0, float dx, float *y_array, size_t array_size, const string &filename) |
Save x, y data into a file. | |
static void | sort_mat (float *left, float *right, int *leftPerm, int *rightPerm) |
does a sort as in Matlab. | |
static unsigned long long | get_randnum_seed () |
Get the seed for Randnum class. | |
static void | set_randnum_seed (unsigned long long seed) |
Set the seed for Randnum class. | |
static int | get_irand (int low, int high) |
Get an integer random number between low and high, [low, high]. | |
static float | get_frand (int low, int high) |
Get a float random number between low and high, [low, high). | |
static float | get_frand (float low, float high) |
Get a float random number between low and high, [low, high). | |
static float | get_frand (double low, double high) |
Get a float random number between low and high, [low, high). | |
static float | get_gauss_rand (float mean, float sigma) |
Get a Gaussian random number. | |
static int | round (float x) |
Get ceiling round of a float number x. | |
static int | round (double x) |
Get ceiling round of a float number x. | |
static float | linear_interpolate (float p1, float p2, float t) |
Calculate linear interpolation. | |
static float | bilinear_interpolate (float p1, float p2, float p3, float p4, float t, float u) |
Calculate bilinear interpolation. | |
static 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. | |
static 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. | |
static 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. | |
static Dict | get_stats (const vector< float > &data) |
Get the mean, standard deviation, skewness and kurtosis of the input data. | |
static 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. | |
static int | calc_best_fft_size (int low) |
Search the best FFT size with good primes. | |
static vector< float > | nonconvex (const vector< float > &curve, int first=3) |
Returns a non-convex version of a curve. | |
static EMData * | calc_bessel (const int n, const float &x) |
static int | square (int n) |
Calculate a number's square. | |
static float | square (float x) |
Calculate a number's square. | |
static float | square (double x) |
Calculate a number's square. | |
static float | square_sum (float x, float y) |
Calcuate (x*x + y*y). | |
static float | hypot2 (float x, float y) |
Euclidean distance function in 2D: f(x,y) = sqrt(x*x + y*y);. | |
static int | hypot3sq (int x, int y, int z) |
Euclidean distance function squared in 3D: f(x,y,z) = (x*x + y*y + z*z);. | |
static float | hypot3sq (float x, float y, float z) |
Euclidean distance function squared in 3D: f(x,y,z) = (x*x + y*y + z*z);. | |
static float | hypot3 (int x, int y, int z) |
Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);. | |
static float | hypot3 (float x, float y, float z) |
Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);. | |
static float | hypot3 (double x, double y, double z) |
Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);. | |
static float | hypot_fast (int x, int y) |
Euclidean distance in 2D for integers computed fast using a cached lookup table. | |
static short | hypot_fast_int (int x, int y) |
Euclidean distance in 2D for integers computed fast using a cached lookup table. | |
static int | fast_floor (float x) |
A fast way to calculate a floor, which is largest integral value not greater than argument. | |
static float | fast_exp (const float &f) |
Returns an approximate of exp(x) using a cached table uses actual exp(x) outside the cached range. | |
static 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). | |
static float | agauss (float a, float dx, float dy, float dz, float d) |
Calculate Gaussian value. | |
static int | get_min (int f1, int f2) |
Get the minimum of 2 numbers. | |
static int | get_min (int f1, int f2, int f3) |
Get the minimum of 3 numbers. | |
static float | get_min (float f1, float f2) |
Get the minimum of 2 numbers. | |
static float | get_min (float f1, float f2, float f3) |
Get the minimum of 3 numbers. | |
static float | get_min (float f1, float f2, float f3, float f4) |
Get the minimum of 4 numbers. | |
static float | get_max (float f1, float f2) |
Get the maximum of 2 numbers. | |
static float | get_max (float f1, float f2, float f3) |
Get the maximum of 3 numbers. | |
static float | get_max (float f1, float f2, float f3, float f4) |
Get the maximum of 4 numbers. | |
static float | angle_sub_2pi (float x, float y) |
Calculate the difference of 2 angles and makes the equivalent result to be less than Pi. | |
static 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. | |
static float | angle_err_ri (float r1, float i1, float r2, float i2) |
Calculate the angular phase difference between two r/i vectors. | |
static int | goodf (const float *p_f) |
Check whether a number is a good float. | |
static int | goodf (const double *p_f) |
static string | recv_broadcast (int port) |
static string | get_time_label () |
Get the current time in a string with format "mm/dd/yyyy hh:mm". | |
static void | set_log_level (int argc, char *argv[]) |
Set program logging level through command line option "-v N", where N is the level. | |
static float | eman_copysign (float a, float b) |
copy sign of a number. | |
static float | eman_erfc (float x) |
complementary error function. | |
static 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. | |
static 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. | |
static 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. | |
static 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> | |
static T | sgn (T &val) |
Sign function. | |
static 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) |
static bool | IsPower2 (int x) |
Return true if an integer is positive and is power of 2. | |
static void | apply_precision (float &value, const float &precision) |
Static Private Member Functions | |
static float | ang_n (float peakp, string mode, int maxrin) |
Classes | |
class | FakeKaiserBessel |
class | Gaussian |
Gaussian function class. More... | |
class | KaiserBessel |
1-D Kaiser-Bessel window function class. More... | |
class | sincBlackman |
struct | tmpstruct |
Definition at line 86 of file util.h.
Definition at line 17491 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, 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().
17492 { 17493 ENTERFUNC; 17494 /* Exception Handle */ 17495 if (!img || !img1) { 17496 throw NullPointerException("NULL input image"); 17497 } 17498 /* ========= img += img1 ===================== */ 17499 17500 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17501 size_t size = (size_t)nx*ny*nz; 17502 float *img_ptr = img->get_data(); 17503 float *img1_ptr = img1->get_data(); 17504 for (size_t i=0;i<size;++i) img_ptr[i] += img1_ptr[i]; 17505 img->update(); 17506 17507 EXITFUNC; 17508 }
Definition at line 17529 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, 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().
17530 { 17531 ENTERFUNC; 17532 /* Exception Handle */ 17533 if (!img) { 17534 throw NullPointerException("NULL input image"); 17535 } 17536 /* ========= img += img1**2 ===================== */ 17537 17538 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17539 size_t size = (size_t)nx*ny*nz; 17540 float *img_ptr = img->get_data(); 17541 float *img1_ptr = img1->get_data(); 17542 if(img->is_complex()) { 17543 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] ; 17544 } else { 17545 for (size_t i=0;i<size;++i) img_ptr[i] += img1_ptr[i]*img1_ptr[i]; 17546 } 17547 img->update(); 17548 17549 EXITFUNC; 17550 }
Definition at line 17510 of file util_sparx.cpp.
References abs, ENTERFUNC, EXITFUNC, 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().
17511 { 17512 ENTERFUNC; 17513 /* Exception Handle */ 17514 if (!img) { 17515 throw NullPointerException("NULL input image"); 17516 } 17517 /* ========= 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 float *img_ptr = img->get_data(); 17522 float *img1_ptr = img1->get_data(); 17523 for (size_t i=0;i<size;++i) img_ptr[i] += abs(img1_ptr[i]); 17524 img->update(); 17525 17526 EXITFUNC; 17527 }
Definition at line 17308 of file util_sparx.cpp.
References EMAN::EMData::copy_head(), ENTERFUNC, EXITFUNC, 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().
17309 { 17310 ENTERFUNC; 17311 /* Exception Handle */ 17312 if (!img) { 17313 throw NullPointerException("NULL input image"); 17314 } 17315 /* ============== output = img + img1 ================ */ 17316 17317 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17318 size_t size = (size_t)nx*ny*nz; 17319 EMData * img2 = img->copy_head(); 17320 float *img_ptr = img->get_data(); 17321 float *img2_ptr = img2->get_data(); 17322 float *img1_ptr = img1->get_data(); 17323 for (size_t i=0;i<size;++i) img2_ptr[i] = img_ptr[i] + img1_ptr[i]; 17324 img2->update(); 17325 if(img->is_complex()) { 17326 img2->set_complex(true); 17327 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17328 } 17329 17330 EXITFUNC; 17331 return img2; 17332 }
static float EMAN::Util::agauss | ( | float | a, | |
float | dx, | |||
float | dy, | |||
float | dz, | |||
float | d | |||
) | [inline, static] |
Calculate Gaussian value.
a * exp(-(dx * dx + dy * dy + dz * dz) / d)
[in] | a | amplitude |
[in] | dx | x center |
[in] | dy | y center |
[in] | dz | z center |
[in] | d | width of gaussian |
Definition at line 1812 of file util.h.
Referenced by EMAN::FourierReconstructorSimple2D::insert_slice(), and EMAN::GaussFFTProjector::interp_ft_3d().
vector< float > Util::ali2d_ccf_list | ( | EMData * | image, | |
EMData * | crefim, | |||
float | xrng, | |||
float | yrng, | |||
float | step, | |||
string | mode, | |||
vector< int > | numr, | |||
float | cnx, | |||
float | cny, | |||
double | T | |||
) | [static] |
Determine shift and rotation between image and one reference image (crefim, weights have to be applied) using quadratic interpolation.
Definition at line 19188 of file util_sparx.cpp.
References Crosrng_msg_vec(), Frngs(), get_frand(), ccf_point::i, ccf_point::j, ccf_point::k, ccf_point::mirror, Polar2Dm(), t, and ccf_point::value.
19190 { 19191 19192 int maxrin = numr[numr.size()-1]; 19193 19194 int ky = int(2*yrng/step+0.5)/2; 19195 int kx = int(2*xrng/step+0.5)/2; 19196 19197 float *p_ccf1ds = (float *)malloc(maxrin*sizeof(float)); 19198 float *p_ccf1dm = (float *)malloc(maxrin*sizeof(float)); 19199 int vol = maxrin*(2*kx+1)*(2*ky+1); 19200 vector<ccf_point> ccf(2*vol); 19201 ccf_point temp; 19202 19203 int index = 0; 19204 for (int i = -ky; i <= ky; i++) { 19205 float iy = i * step; 19206 for (int j = -kx; j <= kx; j++) { 19207 float ix = j*step; 19208 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 19209 Frngs(cimage, numr); 19210 Crosrng_msg_vec(crefim, cimage, numr, p_ccf1ds, p_ccf1dm); 19211 for (int k=0; k<maxrin; k++) { 19212 temp.value = p_ccf1ds[k]; 19213 temp.i = k; 19214 temp.j = j; 19215 temp.k = i; 19216 temp.mirror = 0; 19217 ccf[index] = temp; 19218 index++; 19219 temp.value = p_ccf1dm[k]; 19220 temp.mirror = 1; 19221 ccf[index] = temp; 19222 index++; 19223 } 19224 delete cimage; cimage = 0; 19225 } 19226 } 19227 19228 delete p_ccf1ds; 19229 delete p_ccf1dm; 19230 std::sort(ccf.begin(), ccf.end(), ccf_value()); 19231 19232 double qt = (double)ccf[0].value; 19233 vector <double> p(2*vol), cp(2*vol); 19234 19235 double sump = 0.0; 19236 for (int i=0; i<2*vol; i++) { 19237 p[i] = pow(double(ccf[i].value)/qt, 1.0/T); 19238 sump += p[i]; 19239 } 19240 for (int i=0; i<2*vol; i++) { 19241 p[i] /= sump; 19242 } 19243 for (int i=1; i<2*vol; i++) { 19244 p[i] += p[i-1]; 19245 } 19246 p[2*vol-1] = 2.0; 19247 19248 float t = get_frand(0.0f, 1.0f); 19249 int select = 0; 19250 while (p[select] < t) select += 1; 19251 19252 vector<float> a(6); 19253 a[0] = ccf[select].value; 19254 a[1] = (float)ccf[select].i; 19255 a[2] = (float)ccf[select].j; 19256 a[3] = (float)ccf[select].k; 19257 a[4] = (float)ccf[select].mirror; 19258 a[5] = (float)select; 19259 return a; 19260 }
void Util::alrl_ms | ( | float * | xim, | |
int | nsam, | |||
int | nrow, | |||
float | cns2, | |||
float | cnr2, | |||
int * | numr, | |||
float * | circ, | |||
int | lcirc, | |||
int | nring, | |||
char | mode | |||
) | [static] |
Definition at line 2366 of file util_sparx.cpp.
References circ, numr, quadri(), and y.
02367 { 02368 double dpi, dfi; 02369 int it, jt, inr, l, nsim, kcirc, lt; 02370 float xold, yold, fi, x, y; 02371 02372 // cns2 and cnr2 are predefined centers 02373 // no need to set to zero, all elements are defined 02374 02375 dpi = 2*atan(1.0); 02376 for (it=1; it<=nring; it++) { 02377 // radius of the ring 02378 inr = numr(1,it); 02379 02380 l = numr(3,it); 02381 if ( mode == 'h' || mode == 'H' ) lt = l / 2; 02382 else lt = l / 4; 02383 02384 nsim = lt - 1; 02385 dfi = dpi / (nsim+1); 02386 kcirc = numr(2,it); 02387 02388 02389 xold = 0.0f+cns2; 02390 yold = inr+cnr2; 02391 02392 circ(kcirc) = quadri(xold,yold,nsam,nrow,xim); 02393 02394 xold = inr+cns2; 02395 yold = 0.0f+cnr2; 02396 circ(lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02397 02398 if ( mode == 'f' || mode == 'F' ) { 02399 xold = 0.0f+cns2; 02400 yold = -inr+cnr2; 02401 circ(lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02402 02403 xold = -inr+cns2; 02404 yold = 0.0f+cnr2; 02405 circ(lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02406 } 02407 02408 for (jt=1; jt<=nsim; jt++) { 02409 fi = static_cast<float>(dfi * jt); 02410 x = sin(fi) * inr; 02411 y = cos(fi) * inr; 02412 02413 xold = x+cns2; 02414 yold = y+cnr2; 02415 circ(jt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02416 02417 xold = y+cns2; 02418 yold = -x+cnr2; 02419 circ(jt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02420 02421 if ( mode == 'f' || mode == 'F' ) { 02422 xold = -x+cns2; 02423 yold = -y+cnr2; 02424 circ(jt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02425 02426 xold = -y+cns2; 02427 yold = x+cnr2; 02428 circ(jt+lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02429 } 02430 } // end for jt 02431 } //end for it 02432 }
static float EMAN::Util::ang_diff | ( | float | v11, | |
float | v12, | |||
float | v13, | |||
float | v21, | |||
float | v22, | |||
float | v23, | |||
int & | mirror | |||
) | [inline, static] |
Definition at line 960 of file util.h.
Referenced by group_proj_by_phitheta().
00964 { 00965 #ifndef WIN32 00966 return copysign(a, b);
float Util::ang_n | ( | float | peakp, | |
string | mode, | |||
int | maxrin | |||
) | [static, private] |
Definition at line 17738 of file util_sparx.cpp.
Referenced by constrained_helix(), constrained_helix_test(), hans(), 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().
17739 { 17740 if (mode == "f" || mode == "F") 17741 return fmodf(((peakp-1.0f) / maxrin+1.0f)*360.0f,360.0f); 17742 else 17743 return fmodf(((peakp-1.0f) / maxrin+1.0f)*180.0f,180.0f); 17744 }
void Util::ang_to_xyz | ( | double * | x, | |
double * | y, | |||
double * | z, | |||
int | len | |||
) | [static] |
Definition at line 7708 of file util_sparx.cpp.
References dgr_to_rad, ENTERFUNC, and EXITFUNC.
07709 { 07710 ENTERFUNC; 07711 double costheta,sintheta,cosphi,sinphi; 07712 for(int i = 0; i<len; i++) { 07713 cosphi = cos(y[i]*dgr_to_rad); 07714 sinphi = sin(y[i]*dgr_to_rad); 07715 if(fabs(x[i]-90.0)< 1.0e-5){ 07716 x[i] = cosphi; 07717 y[i] = sinphi; 07718 z[i] = 0.0; 07719 } else { 07720 costheta = cos(x[i]*dgr_to_rad); 07721 sintheta = sin(x[i]*dgr_to_rad); 07722 x[i] = cosphi*sintheta; 07723 y[i] = sinphi*sintheta; 07724 z[i] = costheta; 07725 } 07726 } 07727 EXITFUNC; 07728 }
static float EMAN::Util::angle_err_ri | ( | float | r1, | |
float | i1, | |||
float | r2, | |||
float | i2 | |||
) | [inline, static] |
Calculate the angular phase difference between two r/i vectors.
[in] | r1/i1 | first vector, 2 floats |
[in] | r2/i2 | second vector, 2 floats |
Definition at line 1982 of file util.h.
Referenced by EMAN::PhaseCmp::cmp().
static float EMAN::Util::angle_sub_2pi | ( | float | x, | |
float | y | |||
) | [inline, static] |
Calculate the difference of 2 angles and makes the equivalent result to be less than Pi.
[in] | x | The first angle. |
[in] | y | The second angle. |
Definition at line 1950 of file util.h.
Referenced by EMAN::EMData::common_lines().
static float EMAN::Util::angle_sub_pi | ( | float | x, | |
float | y | |||
) | [inline, static] |
void Util::ap2ri | ( | float * | data, | |
size_t | n | |||
) | [static] |
convert complex data array from Amplitude/Phase format into Real/Imaginary format.
data | complex data array. | |
n | array size. |
Definition at line 101 of file util.cpp.
References Assert, and NullPointerException.
00102 { 00103 Assert(n > 0); 00104 00105 if (!data) { 00106 throw NullPointerException("pixel data array"); 00107 } 00108 00109 for (size_t i = 0; i < n; i += 2) { 00110 float f = data[i] * sin(data[i + 1]); 00111 data[i] = data[i] * cos(data[i + 1]); 00112 data[i + 1] = f; 00113 } 00114 }
static void EMAN::Util::apply_precision | ( | float & | value, | |
const float & | precision | |||
) | [inline, static] |
Definition at line 2194 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(), EMAN::Transform::is_rot_identity(), and EMAN::Transform::set_scale().
void Util::Applyws | ( | EMData * | circ, | |
vector< int > | numr, | |||
vector< float > | wr | |||
) | [static] |
This is a copy of Applyws routine from alignment.py.
Definition at line 3131 of file util_sparx.cpp.
References circ, and EMAN::EMData::get_data().
03132 { /* 03133 Apply weights to FTs of rings 03134 */ 03135 const int nring = numr.size() / 3; 03136 const int maxrin = numr.back(); 03137 float *circ = circp->get_data(); 03138 for (int i = 0; i < nring; ++i) { 03139 const int numr3i = numr[2+i*3]; 03140 const int numr2i = numr[1+i*3]-1; 03141 const float w = wr[i]; 03142 circ[numr2i] *= w; 03143 if (numr3i == maxrin) circ[numr2i+1] *= w; 03144 else circ[numr2i+1] *= 0.5*w; 03145 for (int j = 2+numr2i; j < numr3i+numr2i; ++j) circ[j] *= w; 03146 } 03147 }
double Util::areav_ | ( | int * | k, | |
int * | n, | |||
double * | x, | |||
double * | y, | |||
double * | z__, | |||
int * | list, | |||
int * | lptr, | |||
int * | lend, | |||
int * | ier | |||
) | [static] |
Definition at line 8764 of file util_sparx.cpp.
References areas_(), circum_(), FALSE_, ierr, and TRUE_.
Referenced by voronoi().
08767 { 08768 /* Initialized data */ 08769 08770 static double amax = 6.28; 08771 08772 /* System generated locals */ 08773 double ret_val; 08774 08775 /* Local variables */ 08776 static double a, c0[3], c2[3], c3[3]; 08777 static int n1, n2, n3; 08778 static double v1[3], v2[3], v3[3]; 08779 static int lp, lpl, ierr; 08780 static double asum; 08781 static long int first; 08782 08783 08784 /* *********************************************************** */ 08785 08786 /* Robert J. Renka */ 08787 /* Dept. of Computer Science */ 08788 /* Univ. of North Texas */ 08789 /* renka@cs.unt.edu */ 08790 /* 10/25/02 */ 08791 08792 /* Given a Delaunay triangulation and the index K of an */ 08793 /* interior node, this subroutine returns the (surface) area */ 08794 /* of the Voronoi region associated with node K. The Voronoi */ 08795 /* region is the polygon whose vertices are the circumcenters */ 08796 /* of the triangles that contain node K, where a triangle */ 08797 /* circumcenter is the point (unit vector) lying at the same */ 08798 /* angular distance from the three vertices and contained in */ 08799 /* the same hemisphere as the vertices. */ 08800 08801 08802 /* On input: */ 08803 08804 /* K = Nodal index in the range 1 to N. */ 08805 08806 /* N = Number of nodes in the triangulation. N > 3. */ 08807 08808 /* X,Y,Z = Arrays of length N containing the Cartesian */ 08809 /* coordinates of the nodes (unit vectors). */ 08810 08811 /* LIST,LPTR,LEND = Data structure defining the trian- */ 08812 /* gulation. Refer to Subroutine */ 08813 /* TRMESH. */ 08814 08815 /* Input parameters are not altered by this function. */ 08816 08817 /* On output: */ 08818 08819 /* AREAV = Area of Voronoi region K unless IER > 0, */ 08820 /* in which case AREAV = 0. */ 08821 08822 /* IER = Error indicator: */ 08823 /* IER = 0 if no errors were encountered. */ 08824 /* IER = 1 if K or N is outside its valid range */ 08825 /* on input. */ 08826 /* IER = 2 if K indexes a boundary node. */ 08827 /* IER = 3 if an error flag is returned by CIRCUM */ 08828 /* (null triangle). */ 08829 /* IER = 4 if AREAS returns a value greater than */ 08830 /* AMAX (defined below). */ 08831 08832 /* Modules required by AREAV: AREAS, CIRCUM */ 08833 08834 /* *********************************************************** */ 08835 08836 08837 /* Maximum valid triangle area is less than 2*Pi: */ 08838 08839 /* Parameter adjustments */ 08840 --lend; 08841 --z__; 08842 --y; 08843 --x; 08844 --list; 08845 --lptr; 08846 08847 /* Function Body */ 08848 08849 /* Test for invalid input. */ 08850 08851 if (*k < 1 || *k > *n || *n <= 3) { 08852 goto L11; 08853 } 08854 08855 /* Initialization: Set N3 to the last neighbor of N1 = K. */ 08856 /* FIRST = TRUE only for the first triangle. */ 08857 /* The Voronoi region area is accumulated in ASUM. */ 08858 08859 n1 = *k; 08860 v1[0] = x[n1]; 08861 v1[1] = y[n1]; 08862 v1[2] = z__[n1]; 08863 lpl = lend[n1]; 08864 n3 = list[lpl]; 08865 if (n3 < 0) { 08866 goto L12; 08867 } 08868 lp = lpl; 08869 first = TRUE_; 08870 asum = 0.; 08871 08872 /* Loop on triangles (N1,N2,N3) containing N1 = K. */ 08873 08874 L1: 08875 n2 = n3; 08876 lp = lptr[lp]; 08877 n3 = list[lp]; 08878 v2[0] = x[n2]; 08879 v2[1] = y[n2]; 08880 v2[2] = z__[n2]; 08881 v3[0] = x[n3]; 08882 v3[1] = y[n3]; 08883 v3[2] = z__[n3]; 08884 if (first) { 08885 08886 /* First triangle: compute the circumcenter C3 and save a */ 08887 /* copy in C0. */ 08888 08889 circum_(v1, v2, v3, c3, &ierr); 08890 if (ierr != 0) { 08891 goto L13; 08892 } 08893 c0[0] = c3[0]; 08894 c0[1] = c3[1]; 08895 c0[2] = c3[2]; 08896 first = FALSE_; 08897 } else { 08898 08899 /* Set C2 to C3, compute the new circumcenter C3, and compute */ 08900 /* the area A of triangle (V1,C2,C3). */ 08901 08902 c2[0] = c3[0]; 08903 c2[1] = c3[1]; 08904 c2[2] = c3[2]; 08905 circum_(v1, v2, v3, c3, &ierr); 08906 if (ierr != 0) { 08907 goto L13; 08908 } 08909 a = areas_(v1, c2, c3); 08910 if (a > amax) { 08911 goto L14; 08912 } 08913 asum += a; 08914 } 08915 08916 /* Bottom on loop on neighbors of K. */ 08917 08918 if (lp != lpl) { 08919 goto L1; 08920 } 08921 08922 /* Compute the area of triangle (V1,C3,C0). */ 08923 08924 a = areas_(v1, c3, c0); 08925 if (a > amax) { 08926 goto L14; 08927 } 08928 asum += a; 08929 08930 /* No error encountered. */ 08931 08932 *ier = 0; 08933 ret_val = asum; 08934 return ret_val; 08935 08936 /* Invalid input. */ 08937 08938 L11: 08939 *ier = 1; 08940 ret_val = 0.; 08941 return ret_val; 08942 08943 /* K indexes a boundary node. */ 08944 08945 L12: 08946 *ier = 2; 08947 ret_val = 0.; 08948 return ret_val; 08949 08950 /* Error in CIRCUM. */ 08951 08952 L13: 08953 *ier = 3; 08954 ret_val = 0.; 08955 return ret_val; 08956 08957 /* AREAS value larger than AMAX. */ 08958 08959 L14: 08960 *ier = 4; 08961 ret_val = 0.; 08962 return ret_val; 08963 } /* areav_ */
void Util::array_mutation | ( | float * | list, | |
int | len_list, | |||
float | mutation_rate, | |||
float | min_val, | |||
float | max_val, | |||
int | K, | |||
int | is_mirror | |||
) | [static] |
The purpose of this function is to convert a list to grey code and mutate them and convert them back.
Definition at line 20855 of file util_sparx.cpp.
References t.
Referenced by image_mutation().
20855 { 20856 20857 if (is_mirror != 0) { 20858 for (int i=0; i<len_list; i++) { 20859 int r = rand()%10000; 20860 float f = r/10000.0f; 20861 if (f < mutation_rate) list[i] = 1-list[i]; 20862 } 20863 } else { 20864 map<int, vector<int> > graycode; 20865 map<vector<int>, int> rev_graycode; 20866 vector <int> gray; 20867 20868 int K=1; 20869 for (int i=0; i<L; i++) K*=2; 20870 20871 for (int k=0; k<K; k++) { 20872 int shift = 0; 20873 vector <int> gray; 20874 for (int i=L-1; i>-1; i--) { 20875 int t = ((k>>i)%2-shift)%2; 20876 gray.push_back(t); 20877 shift += t-2; 20878 } 20879 graycode[k] = gray; 20880 rev_graycode[gray] = k; 20881 } 20882 20883 float gap = (K-1)/(max_val-min_val); 20884 for (int i=0; i<len_list; i++) { 20885 float val = list[i]; 20886 if (val < min_val) { val = min_val; } 20887 else if (val > max_val) { val = max_val; } 20888 int k = int((val-min_val)*gap+0.5); 20889 vector<int> gray = graycode[k]; 20890 bool changed = false; 20891 for (vector<int>::iterator p=gray.begin(); p!=gray.end(); p++) { 20892 int r = rand()%10000; 20893 float f = r/10000.0f; 20894 if (f < mutation_rate) { 20895 *p = 1-*p; 20896 changed = true; 20897 } 20898 } 20899 if (changed) { 20900 k = rev_graycode[gray]; 20901 list[i] = k/gap+min_val; 20902 } 20903 } 20904 } 20905 20906 }
vector< int > Util::assign_groups | ( | std::string | matrix_address, | |
int | nref, | |||
int | nima | |||
) | [static] |
Definition at line 17909 of file util_sparx.cpp.
References matrix().
17910 { 17911 const float * matrix; 17912 { // convert memory address sent as string to pointer to float 17913 size_t addr = 0; 17914 for ( std::string::const_iterator i = matrix_address.begin(); i != matrix_address.end(); ++i ) { 17915 int digit = *i - '0'; 17916 addr *= 10; 17917 addr += digit; 17918 } 17919 matrix = reinterpret_cast<float*>(addr); 17920 } 17921 17922 int kt = nref; 17923 unsigned int maxasi = nima/nref; 17924 vector< vector<int> > id_list(nref); 17925 int group, ima; 17926 17927 { 17928 int begin = 0; 17929 // allocate and sort vector of indexes 17930 std::vector<int> dd(nref*nima); 17931 for (int i=0; i<nref*nima; i++) { 17932 dd[i] = i; 17933 } 17934 assign_groups_comparator comparator(matrix); 17935 sort(dd.begin(), dd.end(), comparator); 17936 // main loop 17937 std::vector<bool> del_row(nref, false); 17938 std::vector<bool> del_column(nima, false); 17939 while (kt > 0) { 17940 bool flag = true; 17941 while (flag) { 17942 int l = dd[begin]; 17943 group = l/nima; 17944 ima = l%nima; 17945 if (del_column[ima] || del_row[group]) begin++; 17946 else flag = false; 17947 } 17948 17949 id_list[group].push_back(ima); 17950 if (kt > 1) { 17951 if (id_list[group].size() < maxasi) group = -1; 17952 else kt -= 1; 17953 } else { 17954 if (id_list[group].size() < maxasi+nima%nref) group = -1; 17955 else kt -= 1; 17956 } 17957 del_column[ima] = true; 17958 if (group != -1) { 17959 del_row[group] = true; 17960 } 17961 } 17962 } 17963 17964 vector<int> id_list_1; 17965 for (int iref=0; iref<nref; iref++) 17966 for (unsigned int im=0; im<maxasi; im++) 17967 id_list_1.push_back(id_list[iref][im]); 17968 for (unsigned int im=maxasi; im<maxasi+nima%nref; im++) 17969 id_list_1.push_back(id_list[group][im]); 17970 id_list_1.push_back(group); 17971 17972 return id_list_1; 17973 }
vector< int > Util::assign_projangles | ( | const vector< float > & | projangles, | |
const vector< float > & | refangles | |||
) | [static] |
Definition at line 17997 of file util_sparx.cpp.
References getvec(), and nearest_ang().
Referenced by group_proj_by_phitheta().
17997 { 17998 int nref = refangles.size()/2; 17999 int nproj = projangles.size()/2; 18000 vector<int> asg(nproj); 18001 vector<float> vecref(nref*3); 18002 for (int i=0; i<nref; i++) 18003 getvec(refangles[i*2], refangles[i*2+1], vecref[i*3], vecref[i*3+1], vecref[i*3+2]); 18004 for (int i=0; i<nproj; i++) { 18005 float x, y, z; 18006 getvec(projangles[i*2], projangles[i*2+1], x, y, z); 18007 asg[i] = nearest_ang(vecref, x, y, z); 18008 } 18009 return asg; 18010 }
vector< int > Util::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 | |||
) | [static] |
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 21273 of file util_sparx.cpp.
References branchMPI(), initial_prune(), and sanitycheck().
21274 { 21275 21276 21277 // 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 21278 // 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 21279 // Make a vector of nParts vectors of K int* each 21280 int* Indices = new int[nParts*K]; 21281 int ind_c = 0; 21282 for (int i=0; i < nParts; i++){ 21283 for(int j = 0; j < K; j++){ 21284 Indices[i*K + j] = ind_c; 21285 ind_c = ind_c + dimClasses[i*K + j]; 21286 } 21287 } 21288 21289 // do initial pruning on argParts and return the pruned partitions 21290 21291 // Make a vector of nParts vectors of K int* each 21292 vector <vector <int*> > Parts(nParts,vector<int*>(K)); 21293 ind_c = 0; 21294 int argParts_size=0; 21295 for (int i=0; i < nParts; i++){ 21296 for(int j = 0; j < K; j++){ 21297 Parts[i][j] = argParts + ind_c; 21298 ind_c = ind_c + dimClasses[i*K + j]; 21299 argParts_size = argParts_size + dimClasses[i*K + j]; 21300 } 21301 } 21302 21303 // in the following we call initial_prune with Parts which is a vector. This is not the most 21304 // efficient since vector does not allow for direct addressing. But since initial_prune doesn't have very high complexity, and 21305 // 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..... 21306 21307 // comment out for testing 21308 Util::initial_prune(Parts, dimClasses, nParts, K, T); 21309 for(int i = 0; i < nParts; i++){ 21310 for(int j=0; j < K; j++){ 21311 argParts[Indices[i*K + j]+1] = -1; 21312 } 21313 } 21314 21315 int num_classes; 21316 int old_index; 21317 for(int i=0; i<nParts; i++){ 21318 num_classes = Parts[i].size();// number of classes in partition i after pruning 21319 for (int j=0; j < num_classes; j++){ 21320 old_index = Parts[i][j][0]; 21321 //cout << "old_index: " << old_index<<"\n"; 21322 argParts[Indices[i*K + old_index]+1] = 1; 21323 } 21324 } 21325 21326 21327 // if we're not doing mpi then keep going and call branchMPI and return the output 21328 //cout <<"begin partition matching\n"; 21329 //int* dummy(0); 21330 int* output = Util::branchMPI(argParts, Indices,dimClasses, nParts, K, T, 0, n_guesses, LARGEST_CLASS, J, max_branching, stmult, branchfunc, LIM); 21331 21332 //cout<<"total cost: "<<*output<<"\n"; 21333 //cout<<"number of matches: "<<*(output+1)<<"\n"; 21334 // 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 21335 bool correct = Util::sanitycheck(argParts, Indices,dimClasses, nParts, K, T,output); 21336 21337 delete[] Indices; 21338 21339 // something is wrong with output of branchMPI! 21340 if (correct < 1){ 21341 cout << "something is wrong with output of branchMPI!\n"; 21342 vector<int> ret(1); 21343 ret[0] = -1; 21344 if (output != 0) { delete[] output; output = 0; } 21345 return ret; 21346 } 21347 21348 // output is not nonsense, so now put it into a single dimension vector and return 21349 // 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 21350 // and the rest is the list of matches. output is one dimensional 21351 21352 int output_size = 2 + output[1] * nParts; 21353 vector<int> ret(output_size); 21354 for (int i = 0; i < output_size; i++) { 21355 ret[i]= output[i]; 21356 } 21357 if (output != 0) { delete[] output; output = 0; } 21358 return ret; 21359 21360 }
float Util::bilinear | ( | float | xold, | |
float | yold, | |||
int | nsam, | |||
int | nrow, | |||
float * | xim | |||
) | [static] |
Definition at line 2317 of file util_sparx.cpp.
References xim.
02318 { 02319 /* 02320 c purpose: linear interpolation 02321 Optimized for speed, circular closer removed, checking of ranges removed 02322 */ 02323 float bilinear; 02324 int ixold, iyold; 02325 02326 /* 02327 float xdif, ydif, xrem, yrem; 02328 ixold = (int) floor(xold); 02329 iyold = (int) floor(yold); 02330 ydif = yold - iyold; 02331 yrem = 1.0f - ydif; 02332 02333 // May want to insert if? 02334 // IF ((IYOLD .GE. 1 .AND. IYOLD .LE. NROW-1) .AND. 02335 // & (IXOLD .GE. 1 .AND. IXOLD .LE. NSAM-1)) THEN 02336 //c INSIDE BOUNDARIES OF OUTPUT IMAGE 02337 xdif = xold - ixold; 02338 xrem = 1.0f- xdif; 02339 // RBUF(K) = YDIF*(BUF(NADDR+NSAM)*XREM 02340 // & +BUF(NADDR+NSAM+1)*XDIF) 02341 // & +YREM*(BUF(NADDR)*XREM + BUF(NADDR+1)*XDIF) 02342 bilinear = ydif*(xim(ixold,iyold+1)*xrem + xim(ixold+1,iyold+1)*xdif) + 02343 yrem*(xim(ixold,iyold)*xrem+xim(ixold+1,iyold)*xdif); 02344 02345 return bilinear; 02346 } 02347 */ 02348 float xdif, ydif; 02349 02350 ixold = (int) xold; 02351 iyold = (int) yold; 02352 ydif = yold - iyold; 02353 02354 // May want to insert it? 02355 // IF ((IYOLD .GE. 1 .AND. IYOLD .LE. NROW-1) .AND. 02356 // & (IXOLD .GE. 1 .AND. IXOLD .LE. NSAM-1)) THEN 02357 //c INSIDE BOUNDARIES OF OUTPUT IMAGE 02358 xdif = xold - ixold; 02359 bilinear = xim(ixold, iyold) + ydif* (xim(ixold, iyold+1) - xim(ixold, iyold)) + 02360 xdif* (xim(ixold+1, iyold) - xim(ixold, iyold) + 02361 ydif* (xim(ixold+1, iyold+1) - xim(ixold+1, iyold) - xim(ixold, iyold+1) + xim(ixold, iyold)) ); 02362 02363 return bilinear; 02364 }
static float EMAN::Util::bilinear_interpolate | ( | float | p1, | |
float | p2, | |||
float | p3, | |||
float | p4, | |||
float | t, | |||
float | u | |||
) | [inline, static] |
Calculate bilinear interpolation.
[in] | p1 | The first number. corresponding to (x0,y0). |
[in] | p2 | The second number. corresponding to (x1,y0). |
[in] | p3 | The third number. corresponding to (x1,y1). |
[in] | p4 | The fourth number. corresponding to (x0,y1). |
[in] | t | t |
[in] | u | u |
Definition at line 1569 of file util.h.
Referenced by EMAN::EMData::common_lines(), EMAN::EMData::cut_slice(), EMAN::MaxValProjector::project3d(), EMAN::StandardProjector::project3d(), EMAN::EMData::sget_value_at_interp(), EMAN::TransformProcessor::transform(), and EMAN::EMData::unwrap().
Definition at line 5606 of file util_sparx.cpp.
References EMAN::EMData::depad(), DM, EMAN::EMData::do_ift_inplace(), EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::Transform::get_matrix(), EMAN::Transform::get_params(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::EMData::is_complex(), t_BPCQ_line::offset, t_BPCQ_line::rX, t_BPCQ_line::xbb, and t_BPCQ_line::ybb.
05607 { 05608 if (B->is_complex()) { 05609 B->do_ift_inplace(); 05610 B->depad(); 05611 } 05612 05613 const Transform * transform = B->get_attr("xform.projection"); 05614 Dict transform_params = transform->get_params("spider"); 05615 05616 // ---- build DM matrix (transform matrix) - convert from 3x4 matrix to 2x3 matrix (only 2 first rows are nedeed) 05617 std::vector<float> DM = transform->get_matrix(); 05618 DM[3+0] = DM[4+0]; 05619 DM[3+1] = DM[4+1]; 05620 DM[3+2] = DM[4+2]; 05621 05622 delete transform; 05623 05624 const int NSAM = B->get_xsize(); 05625 const int NROW = B->get_ysize(); 05626 05627 // buffer "lines_to_process" should be aligned to size of cache line (usually 64 or 128 bytes) 05628 t_BPCQ_line * lines_to_process; 05629 #ifdef _WIN32 05630 if ( (lines_to_process = (t_BPCQ_line *)_aligned_malloc( 4*radius*radius*sizeof(t_BPCQ_line), 256 )) == NULL ) 05631 #else 05632 if ( posix_memalign( reinterpret_cast<void**>(&lines_to_process), 256, 4*radius*radius*sizeof(t_BPCQ_line) ) != 0 ) 05633 #endif //_WIN32 05634 { 05635 throw std::bad_alloc(); 05636 } 05637 t_BPCQ_line * first_free_line = lines_to_process; 05638 05639 // calculate lines parameters 05640 { 05641 // Unsure about sign of shifts, check later PAP 06/28/09 05642 const float x_shift_plus_center = float(NSAM/2 +1) + float(transform_params[ "tx" ]); 05643 const float y_shift_plus_center = float(NROW/2 +1) + float(transform_params[ "ty" ]); 05644 05645 const int sizeX = CUBE->get_xsize(); 05646 const int sizeY = CUBE->get_ysize(); 05647 const int sizeZ = CUBE->get_zsize(); 05648 05649 const int centerX = sizeX / 2; 05650 const int centerY = sizeY / 2; 05651 const int centerZ = sizeZ / 2; 05652 05653 const int minRZ = (centerZ >= radius) ? (-radius) : (-centerZ); 05654 const int maxRZ = (sizeZ > centerZ+radius) ? (radius) : (sizeZ-centerZ-1); 05655 05656 for ( int rZ=minRZ; rZ<=maxRZ; ++rZ ) { 05657 for ( int rY=-radius; rY<=radius; ++rY ) { 05658 const int sqRX = radius*radius - rZ*rZ - rY*rY; 05659 if (sqRX >= 0) { 05660 #ifdef _WIN32 05661 first_free_line->rX = static_cast<int>( floor(sqrtf(sqRX)+0.5) ); 05662 #else 05663 first_free_line->rX = static_cast<int>( roundf(sqrtf(sqRX)) ); 05664 #endif //_WIN32 05665 first_free_line->offset = sizeX*( centerY+rY + sizeY*(centerZ+rZ) ) + centerX - first_free_line->rX; 05666 first_free_line->xbb = rZ*DM[2] + rY*DM[1] + x_shift_plus_center; 05667 first_free_line->ybb = rZ*DM[5] + rY*DM[4] + y_shift_plus_center; 05668 ++first_free_line; 05669 } 05670 } 05671 } 05672 } 05673 05674 const float * const Bptr = B->get_data(); 05675 float * const CUBE_begin = CUBE->get_data(); 05676 05677 // update voxels in volume 05678 // this loop takes more than 95% of calculations time spent in Util::BPCQ function 05679 for ( t_BPCQ_line * iLine = lines_to_process; iLine < first_free_line; ++iLine ) { 05680 const int rX_first = -(iLine->rX); 05681 const int rX_last = iLine->rX; 05682 float *CUBE_ptr = CUBE_begin + iLine->offset; 05683 for (int rX=rX_first; rX<=rX_last; ++rX, ++CUBE_ptr) { 05684 const float XB = rX * DM[0] + iLine->xbb; 05685 const float YB = rX * DM[3] + iLine->ybb; 05686 const int IQX = int(XB); 05687 const int IQY = int(YB); 05688 if ( IQX < 1 || IQX >= NSAM || IQY < 1 || IQY >= NROW ) continue; 05689 const float DIPX = XB-IQX; 05690 const float DIPY = YB-IQY; 05691 const float b00 = Bptr[IQX-1+((IQY-1)*NSAM)]; 05692 const float b01 = Bptr[IQX-1+((IQY-0)*NSAM)]; 05693 const float b10 = Bptr[IQX-0+((IQY-1)*NSAM)]; 05694 const float b11 = Bptr[IQX-0+((IQY-0)*NSAM)]; 05695 *(CUBE_ptr) = *(CUBE_ptr) + b00 + DIPY*(b01-b00) + DIPX*(b10-b00+DIPY*(b11-b10-b01+b00)); 05696 } 05697 } 05698 05699 free(lines_to_process); 05700 }
int Util::branch_factor_0 | ( | int * | costlist, | |
int * | matchlist, | |||
int | J, | |||
int | T, | |||
int | nParts, | |||
int | curlevel, | |||
int | max_branching, | |||
int | LIM | |||
) | [static] |
Definition at line 21792 of file util_sparx.cpp.
References jiafunc().
Referenced by branchMPI().
21792 { 21793 21794 int ntot=0; 21795 for (int jit=0; jit < J; jit++){ 21796 if (*(costlist+jit) > T) ntot++; 21797 } 21798 21799 int cur; 21800 // sort matchlist by cost 21801 int* indx = new int[J]; 21802 for (int jit=0; jit < J; jit++) indx[jit]=jit; 21803 vector<int> myindx (indx, indx+J); 21804 vector<int>::iterator it; 21805 costlist_global=costlist; 21806 sort(myindx.begin(), myindx.begin()+J, jiafunc); 21807 21808 // put matchlist in the order of mycost 21809 int* templist = new int[J]; 21810 int* temp2list = new int[J*nParts]; 21811 int next = 0; 21812 21813 for (it=myindx.begin(); it!=myindx.end();++it){ 21814 cur = *(costlist + *it); 21815 if (cur > T){ 21816 21817 templist[next] = cur; 21818 for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt]; 21819 next = next + 1; 21820 } 21821 } 21822 21823 for (int jit=0; jit < ntot; jit++){ 21824 *(costlist+jit)=*(templist + jit); 21825 //cout <<*(costlist+jit)<<", "; 21826 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit]; 21827 } 21828 //cout <<"\n"; 21829 21830 for (int jit=1; jit < ntot; jit++){ 21831 21832 if ((costlist[jit] == costlist[0]) && costlist[jit] > T){ 21833 21834 for (int vit=0; vit < nParts; vit++){ 21835 if ( matchlist[jit*nParts + vit] > matchlist[vit]) 21836 break; 21837 if ( matchlist[jit*nParts + vit] == matchlist[vit]) 21838 continue; 21839 if ( matchlist[jit*nParts + vit] < matchlist[vit]) 21840 { 21841 // swap 21842 for (int swp=0; swp < nParts; swp++){ 21843 int tmp = matchlist[swp]; 21844 matchlist[swp]= matchlist[jit*nParts + swp]; 21845 matchlist[jit*nParts + swp] = tmp; 21846 } 21847 break; 21848 21849 } 21850 } 21851 } 21852 21853 } 21854 21855 21856 delete [] indx; 21857 //compute the average 21858 21859 // partition matches into groups where matches in each group is mutually feasible, and matches from different groups are not feasible 21860 // The number of branches to explore are the mutually exclusive matches. Take the largest of these 21861 21862 21863 int B=1; 21864 int B_init=B; 21865 int infeasible=0; 21866 21867 for (int i=B_init; i<ntot; i++){ 21868 if (i==ntot) continue; 21869 // look at the i-th match. branch on it only if it is infeasible with ALL previous matches we have decided to 21870 // branch on 21871 infeasible = 0; 21872 if (LIM < 0) LIM = B; 21873 for (int j=0; j<B; j++){ 21874 21875 for (int vit=0; vit<nParts; vit++){ 21876 if (temp2list[i*nParts+vit] == matchlist[j*nParts+vit]) {infeasible++; break;} 21877 } 21878 if (infeasible >= LIM) break; 21879 } 21880 21881 if (infeasible >= LIM){ 21882 *(costlist+B)=*(templist+i); 21883 for (int vit=0; vit < nParts; vit++) 21884 *(matchlist+B*nParts + vit)=*(temp2list+i*nParts + vit); 21885 B=B+1; 21886 } 21887 } 21888 21889 delete [] templist; 21890 delete [] temp2list; 21891 //cout<<"**************************************** "<<B<<" ***************************\n"; 21892 21893 if (branch_all < max_branching){ 21894 if (B>1) 21895 {branch_all = branch_all + B -1 ; } 21896 } 21897 else B=1; 21898 21899 return B; 21900 21901 21902 }
int Util::branch_factor_2 | ( | int * | costlist, | |
int * | matchlist, | |||
int | J, | |||
int | T, | |||
int | nParts, | |||
int | curlevel, | |||
int | max_branching, | |||
int | LIM | |||
) | [static] |
Definition at line 21530 of file util_sparx.cpp.
References jiafunc().
Referenced by branchMPI().
21530 { 21531 21532 int ntot=0; 21533 for (int jit=0; jit < J; jit++){ 21534 if (*(costlist+jit) > T) ntot++; 21535 } 21536 21537 int cur; 21538 // sort matchlist by cost 21539 int* indx = new int[J]; 21540 for (int jit=0; jit < J; jit++) indx[jit]=jit; 21541 vector<int> myindx (indx, indx+J); 21542 vector<int>::iterator it; 21543 costlist_global=costlist; 21544 sort(myindx.begin(), myindx.end(), jiafunc); 21545 21546 // put matchlist in the order of mycost 21547 int* templist = new int[J]; 21548 int* temp2list = new int[J*nParts]; 21549 int next = 0; 21550 21551 for (it=myindx.begin(); it!=myindx.end();++it){ 21552 cur = *(costlist + *it); 21553 if (cur > T){ 21554 21555 templist[next] = cur; 21556 for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt]; 21557 next = next + 1; 21558 } 21559 } 21560 21561 for (int jit=0; jit < ntot; jit++){ 21562 *(costlist+jit)=*(templist + jit); 21563 //cout <<*(costlist+jit)<<", "; 21564 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit]; 21565 } 21566 //cout <<"\n"; 21567 21568 delete [] indx; 21569 //compute the average 21570 21571 // partition matches into groups where matches in each group is mutually feasible, and matches from different groups are not feasible 21572 // The number of branches to explore are the mutually exclusive matches. Take the largest of these 21573 21574 21575 int B=1; 21576 int B_init=B; 21577 int infeasible=0; 21578 21579 for (int i=B_init; i<ntot; i++){ 21580 if (i==ntot) continue; 21581 // look at the i-th match. branch on it only if it is infeasible with ALL previous matches we have decided to 21582 // branch on 21583 infeasible = 0; 21584 if (LIM < 0) LIM = B; 21585 for (int j=0; j<B; j++){ 21586 21587 for (int vit=0; vit<nParts; vit++){ 21588 if (temp2list[i*nParts+vit] == matchlist[j*nParts+vit]) {infeasible++; break;} 21589 } 21590 if (infeasible >= LIM) break; 21591 } 21592 21593 if (infeasible >= LIM){ 21594 *(costlist+B)=*(templist+i); 21595 for (int vit=0; vit < nParts; vit++) 21596 *(matchlist+B*nParts + vit)=*(temp2list+i*nParts + vit); 21597 B=B+1; 21598 } 21599 } 21600 21601 delete [] templist; 21602 delete [] temp2list; 21603 //cout<<"**************************************** "<<B<<" ***************************\n"; 21604 21605 if (branch_all < max_branching){ 21606 if (B>1) 21607 {branch_all = branch_all + B -1 ; } 21608 } 21609 else B=1; 21610 21611 return B; 21612 21613 21614 }
int Util::branch_factor_3 | ( | int * | costlist, | |
int * | matchlist, | |||
int | J, | |||
int | T, | |||
int | nParts, | |||
int | curlevel, | |||
int | max_branching, | |||
int | K, | |||
int | LIM | |||
) | [static] |
Definition at line 21618 of file util_sparx.cpp.
References jiafunc().
Referenced by branchMPI().
21618 { 21619 21620 int ntot=0; 21621 for (int jit=0; jit < J; jit++){ 21622 if (*(costlist+jit) > T) ntot++; 21623 } 21624 21625 int cur; 21626 // sort matchlist by cost 21627 int* indx = new int[J]; 21628 for (int jit=0; jit < J; jit++) indx[jit]=jit; 21629 vector<int> myindx (indx, indx+J); 21630 vector<int>::iterator it; 21631 costlist_global=costlist; 21632 sort(myindx.begin(), myindx.begin()+J, jiafunc); 21633 21634 // put matchlist in the order of mycost 21635 int* templist = new int[J]; 21636 int* temp2list = new int[J*nParts]; 21637 int next = 0; 21638 21639 for (it=myindx.begin(); it!=myindx.end();++it){ 21640 cur = *(costlist + *it); 21641 if (cur > T){ 21642 21643 templist[next] = cur; 21644 for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt]; 21645 next = next + 1; 21646 } 21647 } 21648 21649 for (int jit=0; jit < ntot; jit++){ 21650 *(costlist+jit)=*(templist + jit); 21651 //cout <<*(costlist+jit)<<", "; 21652 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit]; 21653 } 21654 //cout <<"\n"; 21655 21656 delete [] indx; 21657 //compute the average 21658 21659 // partition matches into groups where matches in each group is mutually feasible, and matches from different groups are not feasible 21660 // The number of branches to explore are the mutually exclusive matches. Take the largest of these 21661 21662 21663 int B=1; 21664 int B_init=B; 21665 int infeasible=0; 21666 // if we're near the bottom of the tree then explore more... this is because the larger weights are not likely to change much, 21667 // whereas the smaller ones can have many permutations 21668 if (LIM < 0) LIM = ntot-1; 21669 for (int i=B_init; i<ntot; i++){ 21670 if (i==ntot) continue; 21671 // look at the i-th match. branch on it only if it is infeasible with ALL previous matches we have decided to 21672 // branch on 21673 infeasible = 0; 21674 21675 for (int j=0; j<ntot; j++){ 21676 if (j == i) continue; 21677 for (int vit=0; vit<nParts; vit++){ 21678 if (temp2list[i*nParts+vit] == temp2list[j*nParts+vit]) {infeasible++; break;} 21679 } 21680 if (infeasible >= LIM) break; 21681 } 21682 21683 if (infeasible >= LIM){ 21684 *(costlist+B)=*(templist+i); 21685 for (int vit=0; vit < nParts; vit++) 21686 *(matchlist+B*nParts + vit)=*(temp2list+i*nParts + vit); 21687 B=B+1; 21688 } 21689 } 21690 21691 delete [] templist; 21692 delete [] temp2list; 21693 //cout<<"**************************************** "<<B<<" ***************************\n"; 21694 21695 21696 if (branch_all < max_branching){ 21697 if (B>1) 21698 {branch_all = branch_all + B-1;} 21699 } 21700 else B=1; 21701 21702 return B; 21703 21704 21705 }
int Util::branch_factor_4 | ( | int * | costlist, | |
int * | matchlist, | |||
int | J, | |||
int | T, | |||
int | nParts, | |||
int | curlevel, | |||
int | max_branching, | |||
float | stmult | |||
) | [static] |
Definition at line 21711 of file util_sparx.cpp.
References jiafunc().
Referenced by branchMPI().
21711 { 21712 int sum=0; 21713 float average =0; 21714 int ntot=0; 21715 for (int jit=0; jit < J; jit++){ 21716 if (*(costlist+jit) > T) {ntot++; sum = sum +*(costlist+jit);} 21717 } 21718 average = ((float)sum)/((float)ntot); 21719 int cur; 21720 // sort matchlist by cost 21721 int* indx = new int[J]; 21722 for (int jit=0; jit < J; jit++) indx[jit]=jit; 21723 vector<int> myindx (indx, indx+J); 21724 vector<int>::iterator it; 21725 costlist_global=costlist; 21726 sort(myindx.begin(), myindx.begin()+J, jiafunc); 21727 21728 // put matchlist in the order of mycost 21729 int* templist = new int[J]; 21730 int* temp2list = new int[J*nParts]; 21731 int next = 0; 21732 21733 for (it=myindx.begin(); it!=myindx.end();++it){ 21734 cur = *(costlist + *it); 21735 if (cur > T){ 21736 21737 templist[next] = cur; 21738 for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt]; 21739 next = next + 1; 21740 } 21741 } 21742 21743 for (int jit=0; jit < ntot; jit++){ 21744 *(costlist+jit)=*(templist + jit); 21745 //cout <<*(costlist+jit)<<", "; 21746 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit]; 21747 } 21748 //cout <<"\n"; 21749 21750 delete [] indx; 21751 delete [] templist; 21752 delete [] temp2list; 21753 21754 if (ntot == 1) return 1; 21755 21756 // look at the average, standard dev etc. If standard dev very small, i.e., costs very similar, then branch on the similar 21757 // costs 21758 float sq_sum=0.0; 21759 //cout <<"costlist:"; 21760 for (int i=0; i< ntot; i++){ 21761 sq_sum = sq_sum + (float) pow((float) *(costlist+i) - average, (float)2.0); 21762 //cout <<*(costlist+i)<<", "; 21763 } 21764 //cout <<"\n"; 21765 21766 float variance = sq_sum/ntot; 21767 float stdev = (float)pow((float)variance,(float)0.5); 21768 21769 //cout <<"stdev: "<<int(stdev)<<"\n"; 21770 21771 int B=1; 21772 int largest = *costlist; 21773 //cout <<"largest: "<<largest<<"\n"; 21774 for (int i=1; i<ntot; i++){ 21775 int cur = *(costlist+i); 21776 if (largest-cur < (float)(stdev*stmult)) B++; 21777 else break; 21778 21779 } 21780 //cout <<"B: "<<B<<"\n"; 21781 if (branch_all < max_branching){ 21782 if (B>1) 21783 {branch_all = branch_all + B-1;} 21784 } 21785 else B=1; 21786 21787 return B; 21788 21789 21790 }
int * Util::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 | |||
) | [static] |
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 21364 of file util_sparx.cpp.
References branch_factor_0(), branch_factor_2(), branch_factor_3(), branch_factor_4(), branchMPI(), and search2().
21365 { 21366 21367 //************************************* 21368 //testing search2 21369 if (1 == 0){ 21370 cout <<"begin test search2\n"; 21371 int* matchlist = new int[J*nParts]; 21372 int* costlist = new int[J]; 21373 for (int jit = 0; jit < nParts; jit++) *(costlist+jit) = 0; 21374 Util::search2(argParts,Indices, dimClasses, nParts, K, T, matchlist,costlist,J); 21375 21376 for (int jit = 0; jit < J; jit++) { 21377 cout << *(costlist +jit)<<": "; 21378 for (int yit = 0; yit < nParts; yit++) 21379 cout << *(matchlist + jit*nParts + yit)<<","; 21380 cout <<"\n"; 21381 21382 } 21383 cout <<"end test search2\n"; 21384 int* output = new int[1]; 21385 output[0] = 1; 21386 delete [] matchlist; 21387 delete [] costlist; 21388 return output; 21389 } 21390 //************************************** 21391 21392 // Base Case: we're at a leaf, no more feasible matches possible 21393 if (curlevel > K -1){ 21394 int* output = new int[2]; 21395 output[0] = 0; 21396 output[1] = 0; 21397 return output; 21398 } 21399 21400 // branch dynamically depending on results of search 2! 21401 21402 int* matchlist = new int[J*nParts]; 21403 int* costlist = new int[J]; 21404 Util::search2(argParts, Indices, dimClasses, nParts, K, T, matchlist, costlist, J); 21405 21406 21407 // each class in the matches found by findTopLargest is encoded by the original index of the first element of the class in argPart 21408 // each match contains nParts classes, with the i-th class belonging to the i-th partition. 21409 21410 // if there are no feasible matches with cost gt T, then return 0 21411 for (int jit = 0; jit < J ; jit++){ 21412 21413 if (costlist[jit] > T) break; 21414 if (jit == J-1){ 21415 int* output = new int[2]; 21416 output[0] = 0; 21417 output[1] = 0; 21418 delete[] matchlist; 21419 delete[] costlist; 21420 return output; 21421 } 21422 } 21423 21424 21425 21426 // note that costlist and matchlist are NOT sorted by weight, and branch factor takes care of that... 21427 if (curlevel==0) branch_all = 0; 21428 21429 int nBranches = -1; 21430 21431 if (branchfunc == 0) 21432 nBranches = branch_factor_0(costlist,matchlist,J, T, nParts, curlevel, max_branching, LIM); // branch based on distribution of top J (weighted) matches with cost > T 21433 21434 if (branchfunc == 2) 21435 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 21436 21437 if (branchfunc == 3) 21438 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 21439 21440 if (branchfunc == 4) 21441 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 21442 21443 int* newcostlist= new int[nBranches]; 21444 int* newmatchlist = new int[nBranches*nParts]; 21445 for (int i=0; i<nBranches; i++){ 21446 newcostlist[i] = costlist[i]; 21447 for (int j=0; j< nParts; j++) 21448 newmatchlist[i*nParts + j] = matchlist[i*nParts + j]; 21449 } 21450 21451 delete[] costlist; 21452 delete[] matchlist; 21453 21454 //int* output = new int[2];//initialize to placeholder 21455 int* output = new int[2+K*nParts];//initialize to placeholder 21456 output[0] = 0; 21457 output[1] = 0; 21458 // some temporary variables 21459 int old_index; 21460 int totalcost; 21461 int nmatches; 21462 //int offset; 21463 21464 for(int i=0; i < nBranches ; i++){ 21465 21466 // consider the i-th match returned by findTopLargest 21467 //if (newcostlist[i] <= T) continue; 21468 21469 // 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. 21470 // After branch returns, compute overall cost, unmark the classes just marked as 1 again in preparation for next loop. 21471 21472 for(int j=0; j < nParts; j++){ 21473 // matchlist[i*nParts + j] is the original index of the class belonging to the j-th partition in the i-th match. 21474 old_index = newmatchlist[i*nParts + j]; 21475 argParts[Indices[j*K+old_index] + 1] = -2; 21476 } 21477 21478 21479 int* ret = Util::branchMPI(argParts, Indices, dimClasses, nParts, K, T, curlevel+1, n_guesses, LARGEST_CLASS, 21480 J, max_branching, stmult,branchfunc, LIM); 21481 21482 // first element of ret is the total cost of all the matches in ret, and second element is the number of matches in ret 21483 totalcost = newcostlist[i] + ret[0]; 21484 21485 //if (curlevel == 0) { 21486 // cout <<"totalcost*****************************************************************: "<<totalcost<<", costlist["<<i<<"]="<<newcostlist[i]<<", *ret="<<*ret<<", level: "<<curlevel<<"\n"; 21487 21488 //} 21489 if (totalcost > output[0]) // option 1 21490 { 21491 nmatches = 1 + ret[1]; 21492 //delete[] output; // get rid of the old maxreturn 21493 //output = new int[2+nmatches*nParts]; 21494 output[0] = totalcost; 21495 output[1] = nmatches; 21496 int nret = 2+(nmatches-1)*nParts; 21497 for(int iret=2; iret < nret; iret++) output[iret] = ret[iret]; 21498 for(int imax=0; imax < nParts; imax++) output[nret+imax] = newmatchlist[i*nParts + imax]; 21499 } 21500 21501 21502 delete[] ret; 21503 21504 // unmark the marked classes in preparation for the next iteration 21505 21506 for(int j=0; j < nParts; j++){ 21507 old_index = newmatchlist[i*nParts + j]; 21508 argParts[Indices[j*K+old_index] + 1] = 1; 21509 } 21510 21511 } 21512 21513 delete[] newmatchlist; 21514 delete[] newcostlist; 21515 21516 return output; 21517 }
static EMData* EMAN::Util::calc_bessel | ( | const int | n, | |
const float & | x | |||
) | [static] |
int Util::calc_best_fft_size | ( | int | low | ) | [static] |
Search the best FFT size with good primes.
It supports FFT size up to 4096 now.
[in] | low | low size the search starts with. |
Definition at line 1018 of file util.cpp.
References Assert, and LOGERR.
Referenced by EMAN::FRM2DAligner::align(), EMAN::RTFExhaustiveAligner::align(), EMAN::RotatePrecenterAligner::align(), EMAN::EMData::unwrap(), and EMAN::EMData::unwrap_largerR().
01019 { 01020 Assert(low >= 0); 01021 01022 //array containing valid sizes <1024 for speed 01023 static char *valid = NULL; 01024 01025 if (!valid) { 01026 valid = (char *) calloc(4096, 1); 01027 01028 for (float i2 = 1; i2 < 12.0; i2 += 1.0) { 01029 01030 float f1 = pow((float) 2.0, i2); 01031 for (float i3 = 0; i3 < 8.0; i3 += 1.0) { 01032 01033 float f2 = pow((float) 3.0, i3); 01034 for (float i5 = 0; i5 < 6.0; i5 += 1.0) { 01035 01036 float f3 = pow((float) 5.0, i5); 01037 for (float i7 = 0; i7 < 5.0; i7 += 1.0) { 01038 01039 float f = f1 * f2 * f3 * pow((float) 7.0, i7); 01040 if (f <= 4095.0) { 01041 int n = (int) f; 01042 valid[n] = 1; 01043 } 01044 } 01045 } 01046 } 01047 } 01048 } 01049 01050 for (int i = low; i < 4096; i++) { 01051 if (valid[i]) { 01052 return i; 01053 } 01054 } 01055 01056 LOGERR("Sorry, can only find good fft sizes up to 4096 right now."); 01057 01058 return 1; 01059 }
Vec3f Util::calc_bilinear_least_square | ( | const vector< float > & | points | ) | [static] |
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
[in] | points | a vector<float> of x,y,z values in (x1,y1,z1,x2,y2,z2...) sequence to fit a plane to |
Definition at line 582 of file util.cpp.
Referenced by EMAN::PointArray::align_2d().
00582 { 00583 unsigned int i; 00584 00585 // various sums used in the final solution 00586 double Sx=0,Sy=0,Sxy=0,Sxx=0,Syy=0,Sz=0,Sxz=0,Syz=0,S=0; 00587 for (i=0; i<p.size(); i+=3) { 00588 Sx+=p[i]; 00589 Sy+=p[i+1]; 00590 Sz+=p[i+2]; 00591 Sxx+=p[i]*p[i]; 00592 Syy+=p[i+1]*p[i+1]; 00593 Sxy+=p[i]*p[i+1]; 00594 S+=1.0; 00595 Sxz+=p[i]*p[i+2]; 00596 Syz+=p[i+1]*p[i+2]; 00597 } 00598 double d=S*Sxy*Sxy - 2*Sx*Sxy*Sy + Sxx*Sy*Sy + Sx*Sx*Syy - S*Sxx*Syy; 00599 00600 Vec3f ret(0,0,0); 00601 00602 ret[0]=static_cast<float>(-((Sxy*Sxz*Sy - Sx*Sxz*Syy + Sx*Sxy*Syz - Sxx*Sy*Syz - Sxy*Sxy*Sz +Sxx*Syy*Sz)/d)); 00603 ret[1]=static_cast<float>(-((-Sxz*Sy*Sy + S*Sxz*Syy - S*Sxy*Syz + Sx*Sy*Syz + Sxy*Sy*Sz -Sx*Syy*Sz) /d)); 00604 ret[2]=static_cast<float>(-((-S*Sxy*Sxz + Sx*Sxz*Sy - Sx*Sx*Syz + S*Sxx*Syz + Sx*Sxy*Sz -Sxx*Sy*Sz) /d)); 00605 00606 return ret; 00607 }
void Util::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 | |||
) | [static] |
calculate the least square fit value.
[in] | nitems | Number of items in array data_x and data_y. |
[in] | data_x | x data array. |
[in] | data_y | y data array. It should have the same number of items to data_x. |
[out] | p_slope | pointer to the result slope. |
[out] | p_intercept | pointer to the result intercept. |
[in] | ignore_zero | If true, ignore data where either x or y is 0. If false, includes all 0. |
[in] | absmax | Ignores values in y more than absmax from zero |
Definition at line 543 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().
00545 { 00546 Assert(nitems > 0); 00547 00548 if (!data_x || !data_y || !slope || !intercept) { 00549 throw NullPointerException("null float pointer"); 00550 } 00551 double sum = 0; 00552 double sum_x = 0; 00553 double sum_y = 0; 00554 double sum_xx = 0; 00555 double sum_xy = 0; 00556 00557 for (size_t i = 0; i < nitems; i++) { 00558 if ((!ignore_zero || (data_x[i] != 0 && data_y[i] != 0))&&(!absmax ||(data_y[i]<absmax && data_y[i]>-absmax))) { 00559 double y = data_y[i]; 00560 double x = i; 00561 if (data_x) { 00562 x = data_x[i]; 00563 } 00564 00565 sum_x += x; 00566 sum_y += y; 00567 sum_xx += x * x; 00568 sum_xy += x * y; 00569 sum++; 00570 } 00571 } 00572 00573 double div = sum * sum_xx - sum_x * sum_x; 00574 if (div == 0) { 00575 div = 0.0000001f; 00576 } 00577 00578 *intercept = (float) ((sum_xx * sum_y - sum_x * sum_xy) / div); 00579 *slope = (float) ((sum * sum_xy - sum_x * sum_y) / div); 00580 }
vector< float > Util::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 | |||
) | [static] |
Definition at line 6321 of file util_sparx.cpp.
References lsfit().
06322 { 06323 long int q2_dim1, q2_offset, q_dim1, q_offset, i__1, i__2; 06324 float r__1; 06325 int tmp__i; 06326 long int i__, j; 06327 --s; 06328 --res; 06329 iu -= 3; 06330 cu -= 3; 06331 --x; 06332 long int klm2d; 06333 klm2d= *k+*k+2; 06334 klm2d=klm2d+klm2d; 06335 q_dim1 = klm2d; 06336 q_offset = 1 + q_dim1; 06337 q -= q_offset; 06338 q2_dim1 = klm2d; 06339 q2_offset = 1 + q2_dim1; 06340 q2 -= q2_offset; 06341 i__2=0; 06342 i__1 = *n - 1; 06343 tmp__i=0; 06344 for (j = 1; j <= i__1; ++j) { 06345 i__2 = *k; 06346 tmp__i+=1; 06347 for (i__ = 1; i__ <= i__2; ++i__) { 06348 r__1 = float(i__ - 1) /(float) *k / (*ps * 2); 06349 q2[i__ + j * q2_dim1] = pow(r__1, tmp__i); 06350 } 06351 } 06352 for (i__ = 1; i__ <= i__2; ++i__) 06353 { q2[i__ + *n * q2_dim1] = 1.f; 06354 q2[i__ + (*n + 1) * q2_dim1] = pw[i__-1]; 06355 } 06356 vector<float> fit_res; 06357 fit_res=Util::lsfit(k, n, &klm2d, iswi, &q2[q2_offset], &q[q_offset], &x[1], &res[1], &cu[3], &s[1], &iu[3]); 06358 return fit_res; 06359 }
Dict Util::CANG | ( | float | PHI, | |
float | THETA, | |||
float | PSI | |||
) | [static] |
Definition at line 5555 of file util_sparx.cpp.
References DGR_TO_RAD, DM, and SS.
05556 { 05557 double CPHI,SPHI,CTHE,STHE,CPSI,SPSI; 05558 vector<float> DM,SS; 05559 05560 for(int i =0;i<9;i++) DM.push_back(0); 05561 05562 for(int i =0;i<6;i++) SS.push_back(0); 05563 05564 CPHI = cos(double(PHI)*DGR_TO_RAD); 05565 SPHI = sin(double(PHI)*DGR_TO_RAD); 05566 CTHE = cos(double(THETA)*DGR_TO_RAD); 05567 STHE = sin(double(THETA)*DGR_TO_RAD); 05568 CPSI = cos(double(PSI)*DGR_TO_RAD); 05569 SPSI = sin(double(PSI)*DGR_TO_RAD); 05570 05571 SS(1) = float(CPHI); 05572 SS(2) = float(SPHI); 05573 SS(3) = float(CTHE); 05574 SS(4) = float(STHE); 05575 SS(5) = float(CPSI); 05576 SS(6) = float(SPSI); 05577 05578 DM(1) = float(CPHI*CTHE*CPSI-SPHI*SPSI); 05579 DM(2) = float(SPHI*CTHE*CPSI+CPHI*SPSI); 05580 DM(3) = float(-STHE*CPSI); 05581 DM(4) = float(-CPHI*CTHE*SPSI-SPHI*CPSI); 05582 DM(5) = float(-SPHI*CTHE*SPSI+CPHI*CPSI); 05583 DM(6) = float(STHE*SPSI); 05584 DM(7) = float(STHE*CPHI); 05585 DM(8) = float(STHE*SPHI); 05586 DM(9) = float(CTHE); 05587 05588 Dict DMnSS; 05589 DMnSS["DM"] = DM; 05590 DMnSS["SS"] = SS; 05591 05592 return(DMnSS); 05593 }
Definition at line 19923 of file util_sparx.cpp.
References EMAN::EMData::cmp(), and EMAN::EMData::rot_scale_trans2D().
Referenced by twoD_fine_ali_SD().
19923 { 19924 19925 EMData *rot= new EMData(); 19926 float ccc; 19927 19928 rot = image->rot_scale_trans2D(ang, sx, sy, 1.0); 19929 ccc = -rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19930 delete rot; 19931 return ccc; 19932 }
float Util::ccc_images_G | ( | EMData * | image, | |
EMData * | refim, | |||
EMData * | mask, | |||
Util::KaiserBessel & | kb, | |||
float | ang, | |||
float | sx, | |||
float | sy | |||
) | [static] |
Definition at line 19960 of file util_sparx.cpp.
References EMAN::EMData::cmp(), pi, and EMAN::EMData::rot_scale_conv7().
Referenced by twoD_fine_ali_SD_G().
19960 { 19961 19962 EMData *rot= new EMData(); 19963 float ccc; 19964 19965 rot = image->rot_scale_conv7(static_cast<float>(ang*pi/180.0), sx, sy, kb, 1.0f); 19966 ccc = -rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19967 delete rot; 19968 return ccc; 19969 }
string Util::change_filename_ext | ( | const string & | old_filename, | |
const string & | new_ext | |||
) | [static] |
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.
[in] | old_filename | Old filename. |
[in] | new_ext | The new extension. It shouldn't have ".". e.g., for MRC file, it will be "mrc", not ".mrc". |
Definition at line 464 of file util.cpp.
References Assert.
Referenced by EMAN::EMUtil::get_image_type(), EMAN::ImagicIO::ImagicIO(), and EMAN::ImagicIO2::ImagicIO2().
00466 { 00467 Assert(old_filename != ""); 00468 if (ext == "") { 00469 return old_filename; 00470 } 00471 00472 string filename = old_filename; 00473 size_t dot_pos = filename.rfind("."); 00474 if (dot_pos != string::npos) { 00475 filename = filename.substr(0, dot_pos+1); 00476 } 00477 else { 00478 filename = filename + "."; 00479 } 00480 filename = filename + ext; 00481 return filename; 00482 }
bool Util::check_file_by_magic | ( | const void * | first_block, | |
const char * | magic | |||
) | [static] |
check whether a file starts with certain magic string.
first_block | The first block of the file. | |
magic | The magic string to identify a file format. |
Definition at line 228 of file util.cpp.
References NullPointerException.
Referenced by EMAN::VtkIO::is_valid(), EMAN::SalIO::is_valid(), EMAN::PgmIO::is_valid(), EMAN::LstIO::is_valid(), EMAN::LstFastIO::is_valid(), and EMAN::AmiraIO::is_valid().
00229 { 00230 if (!first_block || !magic) { 00231 throw NullPointerException("first_block/magic"); 00232 } 00233 00234 const char *buf = static_cast < const char *>(first_block); 00235 00236 if (strncmp(buf, magic, strlen(magic)) == 0) { 00237 return true; 00238 } 00239 return false; 00240 }
void Util::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 | |||
) | [static] |
Definition at line 6506 of file util_sparx.cpp.
06508 { 06509 06510 long int q_dim1, q_offset, i__1, i__2; 06511 double d__1; 06512 06513 static long int i__, j; 06514 static double z__; 06515 static long int n1, n2, ia, ii, kk, in, nk, js; 06516 static double sn, zu, zv; 06517 static long int nk1, klm, nkl, jmn, jpn; 06518 static double cuv; 06519 static long int klm1, nkl1, klm2, kode, iimn, nklm, iter; 06520 static float xmin; 06521 static double xmax; 06522 static long int iout; 06523 static double xsum; 06524 static long int iineg, maxit; 06525 static double toler; 06526 static float error; 06527 static double pivot; 06528 static long int kforce, iphase; 06529 static double tpivot; 06530 06531 --s; 06532 --res; 06533 iu -= 3; 06534 cu -= 3; 06535 --x; 06536 q_dim1 = *klm2d; 06537 q_offset = 1 + q_dim1; 06538 q -= q_offset; 06539 06540 /* Function Body */ 06541 maxit = 500; 06542 kode = 0; 06543 toler = 1e-4f; 06544 iter = 0; 06545 n1 = *n + 1; 06546 n2 = *n + 2; 06547 nk = *n + *k; 06548 nk1 = nk + 1; 06549 nkl = nk + *l; 06550 nkl1 = nkl + 1; 06551 klm = *k + *l + *m; 06552 klm1 = klm + 1; 06553 klm2 = klm + 2; 06554 nklm = *n + klm; 06555 kforce = 1; 06556 iter = 0; 06557 js = 1; 06558 ia = 0; 06559 /* SET UP LABELS IN Q. */ 06560 i__1 = *n; 06561 for (j = 1; j <= i__1; ++j) { 06562 q[klm2 + j * q_dim1] = (double) j; 06563 /* L10: */ 06564 } 06565 i__1 = klm; 06566 for (i__ = 1; i__ <= i__1; ++i__) { 06567 q[i__ + n2 * q_dim1] = (double) (*n + i__); 06568 if (q[i__ + n1 * q_dim1] >= 0.f) { 06569 goto L30; 06570 } 06571 i__2 = n2; 06572 for (j = 1; j <= i__2; ++j) { 06573 q[i__ + j * q_dim1] = -q[i__ + j * q_dim1]; 06574 /* L20: */ 06575 } 06576 L30: 06577 ; 06578 } 06579 /* SET UP PHASE 1 COSTS. */ 06580 iphase = 2; 06581 i__1 = nklm; 06582 for (j = 1; j <= i__1; ++j) { 06583 cu[(j << 1) + 1] = 0.f; 06584 cu[(j << 1) + 2] = 0.f; 06585 iu[(j << 1) + 1] = 0; 06586 iu[(j << 1) + 2] = 0; 06587 /* L40: */ 06588 } 06589 if (*l == 0) { 06590 goto L60; 06591 } 06592 i__1 = nkl; 06593 for (j = nk1; j <= i__1; ++j) { 06594 cu[(j << 1) + 1] = 1.f; 06595 cu[(j << 1) + 2] = 1.f; 06596 iu[(j << 1) + 1] = 1; 06597 iu[(j << 1) + 2] = 1; 06598 /* L50: */ 06599 } 06600 iphase = 1; 06601 L60: 06602 if (*m == 0) { 06603 goto L80; 06604 } 06605 i__1 = nklm; 06606 for (j = nkl1; j <= i__1; ++j) { 06607 cu[(j << 1) + 2] = 1.f; 06608 iu[(j << 1) + 2] = 1; 06609 jmn = j - *n; 06610 if (q[jmn + n2 * q_dim1] < 0.f) { 06611 iphase = 1; 06612 } 06613 /* L70: */ 06614 } 06615 L80: 06616 if (kode == 0) { 06617 goto L150; 06618 } 06619 i__1 = *n; 06620 for (j = 1; j <= i__1; ++j) { 06621 if ((d__1 = x[j]) < 0.) { 06622 goto L90; 06623 } else if (d__1 == 0) { 06624 goto L110; 06625 } else { 06626 goto L100; 06627 } 06628 L90: 06629 cu[(j << 1) + 1] = 1.f; 06630 iu[(j << 1) + 1] = 1; 06631 goto L110; 06632 L100: 06633 cu[(j << 1) + 2] = 1.f; 06634 iu[(j << 1) + 2] = 1; 06635 L110: 06636 ; 06637 } 06638 i__1 = *k; 06639 for (j = 1; j <= i__1; ++j) { 06640 jpn = j + *n; 06641 if ((d__1 = res[j]) < 0.) { 06642 goto L120; 06643 } else if (d__1 == 0) { 06644 goto L140; 06645 } else { 06646 goto L130; 06647 } 06648 L120: 06649 cu[(jpn << 1) + 1] = 1.f; 06650 iu[(jpn << 1) + 1] = 1; 06651 if (q[j + n2 * q_dim1] > 0.f) { 06652 iphase = 1; 06653 } 06654 goto L140; 06655 L130: 06656 cu[(jpn << 1) + 2] = 1.f; 06657 iu[(jpn << 1) + 2] = 1; 06658 if (q[j + n2 * q_dim1] < 0.f) { 06659 iphase = 1; 06660 } 06661 L140: 06662 ; 06663 } 06664 L150: 06665 if (iphase == 2) { 06666 goto L500; 06667 } 06668 /* COMPUTE THE MARGINAL COSTS. */ 06669 L160: 06670 i__1 = n1; 06671 for (j = js; j <= i__1; ++j) { 06672 xsum = 0.; 06673 i__2 = klm; 06674 for (i__ = 1; i__ <= i__2; ++i__) { 06675 ii = (long int) q[i__ + n2 * q_dim1]; 06676 if (ii < 0) { 06677 goto L170; 06678 } 06679 z__ = cu[(ii << 1) + 1]; 06680 goto L180; 06681 L170: 06682 iineg = -ii; 06683 z__ = cu[(iineg << 1) + 2]; 06684 L180: 06685 xsum += q[i__ + j * q_dim1] * z__; 06686 /* 180 XSUM = XSUM + Q(I,J)*Z */ 06687 /* L190: */ 06688 } 06689 q[klm1 + j * q_dim1] = xsum; 06690 /* L200: */ 06691 } 06692 i__1 = *n; 06693 for (j = js; j <= i__1; ++j) { 06694 ii = (long int) q[klm2 + j * q_dim1]; 06695 if (ii < 0) { 06696 goto L210; 06697 } 06698 z__ = cu[(ii << 1) + 1]; 06699 goto L220; 06700 L210: 06701 iineg = -ii; 06702 z__ = cu[(iineg << 1) + 2]; 06703 L220: 06704 q[klm1 + j * q_dim1] -= z__; 06705 /* L230: */ 06706 } 06707 /* DETERMINE THE VECTOR TO ENTER THE BASIS. */ 06708 L240: 06709 xmax = 0.f; 06710 if (js > *n) { 06711 goto L490; 06712 } 06713 i__1 = *n; 06714 for (j = js; j <= i__1; ++j) { 06715 zu = q[klm1 + j * q_dim1]; 06716 ii = (long int) q[klm2 + j * q_dim1]; 06717 if (ii > 0) { 06718 goto L250; 06719 } 06720 ii = -ii; 06721 zv = zu; 06722 zu = -zu - cu[(ii << 1) + 1] - cu[(ii << 1) + 2]; 06723 goto L260; 06724 L250: 06725 zv = -zu - cu[(ii << 1) + 1] - cu[(ii << 1) + 2]; 06726 L260: 06727 if (kforce == 1 && ii > *n) { 06728 goto L280; 06729 } 06730 if (iu[(ii << 1) + 1] == 1) { 06731 goto L270; 06732 } 06733 if (zu <= xmax) { 06734 goto L270; 06735 } 06736 xmax = zu; 06737 in = j; 06738 L270: 06739 if (iu[(ii << 1) + 2] == 1) { 06740 goto L280; 06741 } 06742 if (zv <= xmax) { 06743 goto L280; 06744 } 06745 xmax = zv; 06746 in = j; 06747 L280: 06748 ; 06749 } 06750 if (xmax <= toler) { 06751 goto L490; 06752 } 06753 if (q[klm1 + in * q_dim1] == xmax) { 06754 goto L300; 06755 } 06756 i__1 = klm2; 06757 for (i__ = 1; i__ <= i__1; ++i__) { 06758 q[i__ + in * q_dim1] = -q[i__ + in * q_dim1]; 06759 /* L290: */ 06760 } 06761 q[klm1 + in * q_dim1] = xmax; 06762 /* DETERMINE THE VECTOR TO LEAVE THE BASIS. */ 06763 L300: 06764 if (iphase == 1 || ia == 0) { 06765 goto L330; 06766 } 06767 xmax = 0.f; 06768 i__1 = ia; 06769 for (i__ = 1; i__ <= i__1; ++i__) { 06770 z__ = (d__1 = q[i__ + in * q_dim1], abs(d__1)); 06771 if (z__ <= xmax) { 06772 goto L310; 06773 } 06774 xmax = z__; 06775 iout = i__; 06776 L310: 06777 ; 06778 } 06779 if (xmax <= toler) { 06780 goto L330; 06781 } 06782 i__1 = n2; 06783 for (j = 1; j <= i__1; ++j) { 06784 z__ = q[ia + j * q_dim1]; 06785 q[ia + j * q_dim1] = q[iout + j * q_dim1]; 06786 q[iout + j * q_dim1] = z__; 06787 /* L320: */ 06788 } 06789 iout = ia; 06790 --ia; 06791 pivot = q[iout + in * q_dim1]; 06792 goto L420; 06793 L330: 06794 kk = 0; 06795 i__1 = klm; 06796 for (i__ = 1; i__ <= i__1; ++i__) { 06797 z__ = q[i__ + in * q_dim1]; 06798 if (z__ <= toler) { 06799 goto L340; 06800 } 06801 ++kk; 06802 res[kk] = q[i__ + n1 * q_dim1] / z__; 06803 s[kk] = (double) i__; 06804 L340: 06805 ; 06806 } 06807 L350: 06808 if (kk > 0) { 06809 goto L360; 06810 } 06811 kode = 2; 06812 goto L590; 06813 L360: 06814 xmin = static_cast<float>( res[1] ); 06815 iout = (long int) s[1]; 06816 j = 1; 06817 if (kk == 1) { 06818 goto L380; 06819 } 06820 i__1 = kk; 06821 for (i__ = 2; i__ <= i__1; ++i__) { 06822 if (res[i__] >= xmin) { 06823 goto L370; 06824 } 06825 j = i__; 06826 xmin = static_cast<float>( res[i__] ); 06827 iout = (long int) s[i__]; 06828 L370: 06829 ; 06830 } 06831 res[j] = res[kk]; 06832 s[j] = s[kk]; 06833 L380: 06834 --kk; 06835 pivot = q[iout + in * q_dim1]; 06836 ii = (long int) q[iout + n2 * q_dim1]; 06837 if (iphase == 1) { 06838 goto L400; 06839 } 06840 if (ii < 0) { 06841 goto L390; 06842 } 06843 if (iu[(ii << 1) + 2] == 1) { 06844 goto L420; 06845 } 06846 goto L400; 06847 L390: 06848 iineg = -ii; 06849 if (iu[(iineg << 1) + 1] == 1) { 06850 goto L420; 06851 } 06852 /* 400 II = IABS(II) */ 06853 L400: 06854 ii = abs(ii); 06855 cuv = cu[(ii << 1) + 1] + cu[(ii << 1) + 2]; 06856 if (q[klm1 + in * q_dim1] - pivot * cuv <= toler) { 06857 goto L420; 06858 } 06859 /* BYPASS INTERMEDIATE VERTICES. */ 06860 i__1 = n1; 06861 for (j = js; j <= i__1; ++j) { 06862 z__ = q[iout + j * q_dim1]; 06863 q[klm1 + j * q_dim1] -= z__ * cuv; 06864 q[iout + j * q_dim1] = -z__; 06865 /* L410: */ 06866 } 06867 q[iout + n2 * q_dim1] = -q[iout + n2 * q_dim1]; 06868 goto L350; 06869 /* GAUSS-JORDAN ELIMINATION. */ 06870 L420: 06871 if (iter < maxit) { 06872 goto L430; 06873 } 06874 kode = 3; 06875 goto L590; 06876 L430: 06877 ++iter; 06878 i__1 = n1; 06879 for (j = js; j <= i__1; ++j) { 06880 if (j != in) { 06881 q[iout + j * q_dim1] /= pivot; 06882 } 06883 /* L440: */ 06884 } 06885 /* IF PERMITTED, USE SUBROUTINE COL OF THE DESCRIPTION */ 06886 /* SECTION AND REPLACE THE FOLLOWING SEVEN STATEMENTS DOWN */ 06887 /* TO AND INCLUDING STATEMENT NUMBER 460 BY.. */ 06888 /* DO 460 J=JS,N1 */ 06889 /* IF(J .EQ. IN) GO TO 460 */ 06890 /* Z = -Q(IOUT,J) */ 06891 /* CALL COL(Q(1,J), Q(1,IN), Z, IOUT, KLM1) */ 06892 /* 460 CONTINUE */ 06893 i__1 = n1; 06894 for (j = js; j <= i__1; ++j) { 06895 if (j == in) { 06896 goto L460; 06897 } 06898 z__ = -q[iout + j * q_dim1]; 06899 i__2 = klm1; 06900 for (i__ = 1; i__ <= i__2; ++i__) { 06901 if (i__ != iout) { 06902 q[i__ + j * q_dim1] += z__ * q[i__ + in * q_dim1]; 06903 } 06904 /* L450: */ 06905 } 06906 L460: 06907 ; 06908 } 06909 tpivot = -pivot; 06910 i__1 = klm1; 06911 for (i__ = 1; i__ <= i__1; ++i__) { 06912 if (i__ != iout) { 06913 q[i__ + in * q_dim1] /= tpivot; 06914 } 06915 /* L470: */ 06916 } 06917 q[iout + in * q_dim1] = 1.f / pivot; 06918 z__ = q[iout + n2 * q_dim1]; 06919 q[iout + n2 * q_dim1] = q[klm2 + in * q_dim1]; 06920 q[klm2 + in * q_dim1] = z__; 06921 ii = (long int) abs(z__); 06922 if (iu[(ii << 1) + 1] == 0 || iu[(ii << 1) + 2] == 0) { 06923 goto L240; 06924 } 06925 i__1 = klm2; 06926 for (i__ = 1; i__ <= i__1; ++i__) { 06927 z__ = q[i__ + in * q_dim1]; 06928 q[i__ + in * q_dim1] = q[i__ + js * q_dim1]; 06929 q[i__ + js * q_dim1] = z__; 06930 /* L480: */ 06931 } 06932 ++js; 06933 goto L240; 06934 /* TEST FOR OPTIMALITY. */ 06935 L490: 06936 if (kforce == 0) { 06937 goto L580; 06938 } 06939 if (iphase == 1 && q[klm1 + n1 * q_dim1] <= toler) { 06940 goto L500; 06941 } 06942 kforce = 0; 06943 goto L240; 06944 /* SET UP PHASE 2 COSTS. */ 06945 L500: 06946 iphase = 2; 06947 i__1 = nklm; 06948 for (j = 1; j <= i__1; ++j) { 06949 cu[(j << 1) + 1] = 0.f; 06950 cu[(j << 1) + 2] = 0.f; 06951 /* L510: */ 06952 } 06953 i__1 = nk; 06954 for (j = n1; j <= i__1; ++j) { 06955 cu[(j << 1) + 1] = 1.f; 06956 cu[(j << 1) + 2] = 1.f; 06957 /* L520: */ 06958 } 06959 i__1 = klm; 06960 for (i__ = 1; i__ <= i__1; ++i__) { 06961 ii = (long int) q[i__ + n2 * q_dim1]; 06962 if (ii > 0) { 06963 goto L530; 06964 } 06965 ii = -ii; 06966 if (iu[(ii << 1) + 2] == 0) { 06967 goto L560; 06968 } 06969 cu[(ii << 1) + 2] = 0.f; 06970 goto L540; 06971 L530: 06972 if (iu[(ii << 1) + 1] == 0) { 06973 goto L560; 06974 } 06975 cu[(ii << 1) + 1] = 0.f; 06976 L540: 06977 ++ia; 06978 i__2 = n2; 06979 for (j = 1; j <= i__2; ++j) { 06980 z__ = q[ia + j * q_dim1]; 06981 q[ia + j * q_dim1] = q[i__ + j * q_dim1]; 06982 q[i__ + j * q_dim1] = z__; 06983 /* L550: */ 06984 } 06985 L560: 06986 ; 06987 } 06988 goto L160; 06989 L570: 06990 if (q[klm1 + n1 * q_dim1] <= toler) { 06991 goto L500; 06992 } 06993 kode = 1; 06994 goto L590; 06995 L580: 06996 if (iphase == 1) { 06997 goto L570; 06998 } 06999 /* PREPARE OUTPUT. */ 07000 kode = 0; 07001 L590: 07002 xsum = 0.; 07003 i__1 = *n; 07004 for (j = 1; j <= i__1; ++j) { 07005 x[j] = 0.f; 07006 /* L600: */ 07007 } 07008 i__1 = klm; 07009 for (i__ = 1; i__ <= i__1; ++i__) { 07010 res[i__] = 0.f; 07011 /* L610: */ 07012 } 07013 i__1 = klm; 07014 for (i__ = 1; i__ <= i__1; ++i__) { 07015 ii = (long int) q[i__ + n2 * q_dim1]; 07016 sn = 1.f; 07017 if (ii > 0) { 07018 goto L620; 07019 } 07020 ii = -ii; 07021 sn = -1.f; 07022 L620: 07023 if (ii > *n) { 07024 goto L630; 07025 } 07026 x[ii] = sn * q[i__ + n1 * q_dim1]; 07027 goto L640; 07028 L630: 07029 iimn = ii - *n; 07030 res[iimn] = sn * q[i__ + n1 * q_dim1]; 07031 if (ii >= n1 && ii <= nk) { 07032 xsum += q[i__ + n1 * q_dim1]; 07033 } 07034 L640: 07035 ; 07036 } 07037 error = (float)xsum; 07038 return; 07039 }
vector< float > Util::cluster_equalsize | ( | EMData * | d | ) | [static] |
Definition at line 20668 of file util_sparx.cpp.
References dm, EMAN::EMData::get_xsize(), nx, and sqrt().
20668 { 20669 // WORKS ONLY FOR NUMBER OF OBJECTS N=l^2 !! 20670 int nx = d->get_xsize(); 20671 int N = 1 + int((sqrt(1.0 + 8.0*nx)-1.0)/2.0); 20672 int K = N/2; 20673 vector<float> group(N); 20674 if(N*(N-1)/2 != nx) { 20675 //print " incorrect dimension" 20676 return group;} 20677 //bool active[N]; //this does not compile in VS2005. --Grant Tang 20678 bool * active = new bool[N]; 20679 for(int i=0; i<N; i++) active[i] = true; 20680 20681 float dm, qd; 20682 int ppi = 0, ppj = 0; 20683 for(int k=0; k<K; k++) { 20684 // find pairs of most similiar objects among active 20685 //cout<<" k "<<k<<endl; 20686 dm = 1.0e23f; 20687 for(int i=1; i<N; i++) { 20688 if(active[i]) { 20689 for(int j=0; j<i; j++) { 20690 if(active[j]) { 20691 qd = (*d)(i*(i - 1)/2 + j); 20692 if(qd < dm) { 20693 dm = qd; 20694 ppi = i; 20695 ppj = j; 20696 } 20697 } 20698 } 20699 } 20700 } 20701 group[2*k] = float(ppi); 20702 group[1+2*k] = float(ppj); 20703 active[ppi] = false; 20704 active[ppj] = false; 20705 } 20706 20707 delete [] active; 20708 active = NULL; 20709 return group; 20710 }
vector< float > Util::cluster_pairwise | ( | EMData * | d, | |
int | K, | |||
float | T, | |||
float | F | |||
) | [static] |
Definition at line 20460 of file util_sparx.cpp.
References assign, cent, dt, get_irand(), EMAN::EMData::get_xsize(), mono(), nx, q, and sqrt().
20460 { 20461 int nx = d->get_xsize(); 20462 int N = 1 + int((sqrt(1.0 + 8.0*nx)-1.0)/2.0); 20463 vector<float> out(N+K+2); 20464 if(N*(N-1)/2 != nx) { 20465 //print " incorrect dimension" 20466 return out;} 20467 // assign random objects as centers 20468 for(int i=0; i<N; i++) assign(i) = float(i); 20469 // shuffle 20470 for(int i=0; i<N; i++) { 20471 int j = Util::get_irand(0,N-1); 20472 float temp = assign(i); 20473 assign(i) = assign(j); 20474 assign(j) = temp; 20475 } 20476 for(int k=0; k<K; k++) cent(k) = float(assign(k)); 20477 //for(int k=0; k<K; k++) cout<<cent(k)<<" ";cout<<endl; 20478 // 20479 for(int i=0; i<N; i++) assign(i) = 0.0f; 20480 float qm, dispold = 1.1e22f, disp = 1.0e22f, na=0.0f; 20481 bool change = true; 20482 int it = -1; 20483 int ct = -1; 20484 while ((change && disp < dispold) || ct > 0) { 20485 20486 change = false; 20487 dispold = disp; 20488 it++; 20489 20490 // dispersion is a sum of distance from objects to object center 20491 disp = 0.0f; 20492 ct = 0; 20493 for(int i=0; i<N; i++) { 20494 qm = 1.0e23f; 20495 for(int k=0; k<K; k++) { 20496 if(float(i) == cent(k)) { 20497 qm = 0.0f; 20498 na = (float)k; 20499 } else { 20500 float dt = (*d)(mono(i,int(cent(k)))); 20501 if(dt < qm) { 20502 qm = dt; 20503 na = (float)k; 20504 } 20505 } 20506 } 20507 20508 20509 // Simulated annealing 20510 if(exp(-1.0/float(T)) > Util::get_irand(1,1000)/1000.0) { 20511 na = (float)(Util::get_irand(0, K)); 20512 qm = (*d)(mono(i,int(na))); 20513 ct++; 20514 } 20515 20516 disp += qm; 20517 20518 if(na != assign(i)) { 20519 assign(i) = na; 20520 change = true; 20521 } 20522 } 20523 20524 //cout<<"Iteration: "<<it<< " disp " <<disp << " T " << T << " disturb " << ct << endl; 20525 T = T*F; 20526 20527 //for(int k=0; k<N; k++) cout<<assign(k)<<" ";cout<<endl; 20528 //print disp 20529 //print assign 20530 // find centers 20531 for(int k=0; k<K; k++) { 20532 qm = 1.0e23f; 20533 for(int i=0; i<N; i++) { 20534 if(assign(i) == float(k)) { 20535 float q = 0.0; 20536 for(int j=0; j<N; j++) { 20537 if(assign(j) == float(k)) { 20538 //it cannot be the same object 20539 if(i != j) q += (*d)(mono(i,j)); 20540 //cout<<q<<" "<<i<<" "<<j<<" "<<k<<endl;} 20541 } 20542 } 20543 if(q < qm) { 20544 //cout<<qm<<" "<<q<<" "<<i<<" "<<k<<endl; 20545 qm = q; 20546 cent(k) = float(i); 20547 } 20548 } 20549 } 20550 } 20551 //for(int k=0; k<K; k++) cout<<cent(k)<<" ";cout<<endl;cout<<disp<<endl; 20552 } 20553 out[N+K] = disp; 20554 out[N+K+1] = float(it); 20555 return out; 20556 }
double Util::cml_disc | ( | const vector< EMData * > & | data, | |
vector< int > | com, | |||
vector< int > | seq, | |||
vector< float > | weights, | |||
int | n_lines | |||
) | [static] |
2009-03-30 15:44:05 JB.
Compute the discrepancy belong all common-lines
Definition at line 4825 of file util_sparx.cpp.
04825 { 04826 double res = 0; 04827 double buf = 0; 04828 float* line_1; 04829 float* line_2; 04830 int i, n, ind; 04831 int lnlen = data[0]->get_xsize(); 04832 for (n=0; n<n_lines; ++n) { 04833 ind = n*2; 04834 line_1 = data[seq[ind]]->get_data() + com[ind] * lnlen; 04835 line_2 = data[seq[ind+1]]->get_data() + com[ind+1] *lnlen; 04836 buf = 0; 04837 for (i=0; i<lnlen; ++i) { 04838 buf += (line_1[i]-line_2[i])*(line_1[i]-line_2[i]); 04839 } 04840 res += buf * weights[n]; 04841 } 04842 04843 return res; 04844 04845 }
vector< double > Util::cml_init_rot | ( | vector< float > | Ori | ) | [static] |
2009-03-25 15:35:05 JB.
This function prepare rotation matrix for common-lines
Definition at line 4602 of file util_sparx.cpp.
References deg_rad.
04602 { 04603 int nb_ori = Ori.size() / 4; 04604 int i, ind; 04605 float ph, th, ps; 04606 double cph, cth, cps, sph, sth, sps; 04607 vector<double> Rot(nb_ori*9); 04608 for (i=0; i<nb_ori; ++i){ 04609 ind = i*4; 04610 // spider convention phi=psi-90, psi=phi+90 04611 ph = Ori[ind+2]-90; 04612 th = Ori[ind+1]; 04613 ps = Ori[ind]+90; 04614 ph *= deg_rad; 04615 th *= deg_rad; 04616 ps *= deg_rad; 04617 // pre-calculate some trigo stuffs 04618 cph = cos(ph); 04619 cth = cos(th); 04620 cps = cos(ps); 04621 sph = sin(ph); 04622 sth = sin(th); 04623 sps = sin(ps); 04624 // fill rotation matrix 04625 ind = i*9; 04626 Rot[ind] = cph*cps-cth*sps*sph; 04627 Rot[ind+1] = cph*sps+cth*cps*sph; 04628 Rot[ind+2] = sth*sph; 04629 Rot[ind+3] = -sph*cps-cth*sps*cph; 04630 Rot[ind+4] = -sph*sps+cth*cps*cph; 04631 Rot[ind+5] = sth*cph; 04632 Rot[ind+6] = sth*sps; 04633 Rot[ind+7] = -sth*cps; 04634 Rot[ind+8] = cth; 04635 } 04636 04637 return Rot; 04638 }
vector< double > Util::cml_line_in3d | ( | vector< float > | Ori, | |
vector< int > | seq, | |||
int | nprj, | |||
int | nlines | |||
) | [static] |
2009-03-26 10:46:14 JB.
This function calculate all common-lines in space for Voronoi
Definition at line 4770 of file util_sparx.cpp.
References deg_rad, norm(), nx, ny, rad_deg, and sqrt().
04770 { 04771 // seq is the pairwise index ij: 0, 1, 0, 2, 0, 3, 1, 2, 1, 3, 2, 3 04772 vector<double> cml(2*nlines); // [phi, theta] / line 04773 float ph1, th1; 04774 float ph2, th2; 04775 double nx, ny, nz; 04776 double norm; 04777 double sth1=0, sph1=0, cth1=0, cph1=0; 04778 double sth2, sph2, cth2, cph2; 04779 int l, ind, c; 04780 int mem = -1; 04781 for (l=0; l<nlines; ++l){ 04782 c = 2*l; 04783 if (seq[c]!=mem){ 04784 mem = seq[c]; 04785 ind = 4*seq[c]; 04786 ph1 = Ori[ind]*deg_rad; 04787 th1 = Ori[ind+1]*deg_rad; 04788 sth1 = sin(th1); 04789 sph1 = sin(ph1); 04790 cth1 = cos(th1); 04791 cph1 = cos(ph1); 04792 } 04793 ind = 4*seq[c+1]; 04794 ph2 = Ori[ind]*deg_rad; 04795 th2 = Ori[ind+1]*deg_rad; 04796 sth2 = sin(th2); 04797 cth2 = cos(th2); 04798 sph2 = sin(ph2); 04799 cph2 = cos(ph2); 04800 // cross product 04801 nx = sth1*cph1*cth2 - cth1*sth2*cph2; 04802 ny = cth1*sth2*sph2 - cth2*sth1*sph1; 04803 nz = sth1*sph1*sth2*cph2 - sth1*cph1*sth2*sph2; 04804 norm = sqrt(nx*nx+ny*ny+nz*nz); 04805 nx /= norm; 04806 ny /= norm; 04807 nz /= norm; 04808 // apply mirror if need 04809 if (nz<0) {nx=-nx; ny=-ny; nz=-nz;} 04810 // compute theta and phi 04811 cml[c+1] = acos(nz); 04812 if (cml[c+1] == 0) {cml[c] = 0;} 04813 else { 04814 cml[c+1] *= rad_deg; 04815 if (cml[c+1] > 89.99) {cml[c+1] = 89.99;} // this fix some pb in Voronoi 04816 cml[c] = rad_deg * atan2(nx, ny); 04817 cml[c] = fmod(360 + cml[c], 360); 04818 04819 } 04820 } 04821 04822 return cml; 04823 }
vector< int > Util::cml_line_insino | ( | vector< float > | Rot, | |
int | i_prj, | |||
int | n_prj | |||
) | [static] |
2009-03-25 15:35:53 JB.
This function calculates common-lines between sinogram
Definition at line 4671 of file util_sparx.cpp.
References abs, b, nint180(), and rad_deg.
04671 { 04672 vector<int> com(2*(n_prj - 1)); 04673 int a = i_prj*9; 04674 int i, b, c; 04675 int n1=0, n2=0; 04676 float vmax = 1 - 1.0e-6f; 04677 double r11, r12, r13, r23, r31, r32, r33; 04678 04679 c = 0; 04680 for (i=0; i<n_prj; ++i){ 04681 if (i!=i_prj){ 04682 b = i*9; 04683 // this is equivalent to R = A*B' 04684 r11 = Rot[a]*Rot[b]+Rot[a+1]*Rot[b+1]+Rot[a+2]*Rot[b+2]; 04685 r12 = Rot[a]*Rot[b+3]+Rot[a+1]*Rot[b+4]+Rot[a+2]*Rot[b+5]; 04686 r13 = Rot[a]*Rot[b+6]+Rot[a+1]*Rot[b+7]+Rot[a+2]*Rot[b+8]; 04687 r23 = Rot[a+3]*Rot[b+6]+Rot[a+4]*Rot[b+7]+Rot[a+5]*Rot[b+8]; 04688 r31 = Rot[a+6]*Rot[b]+Rot[a+7]*Rot[b+1]+Rot[a+8]*Rot[b+2]; 04689 r32 = Rot[a+6]*Rot[b+3]+Rot[a+7]*Rot[b+4]+Rot[a+8]*Rot[b+5]; 04690 r33 = Rot[a+6]*Rot[b+6]+Rot[a+7]*Rot[b+7]+Rot[a+8]*Rot[b+8]; 04691 if (r33 > vmax) { 04692 n2 = 270; 04693 n1 = 270 + nint180((float)(rad_deg*atan2(r12, r11))); 04694 } 04695 else if (r33 < -vmax) { 04696 n2 = 270; 04697 n1 = 270 - nint180((float)(rad_deg*atan2(r12, r11))); 04698 } else { 04699 n2 = nint180((float)(rad_deg*atan2(r31, -r32))); 04700 n1 = nint180((float)(rad_deg*atan2(r13, r23))); 04701 if (n1 < 0) {n1 += 360;} 04702 if (n2 <= 0) {n2 = abs(n2);} 04703 else {n2 = 360 - n2;} 04704 } 04705 04706 if (n1 >= 360){n1 = n1 % 360;} 04707 if (n2 >= 360){n2 = n2 % 360;} 04708 04709 // store common-lines 04710 b = c*2; 04711 com[b] = n1; 04712 com[b+1] = n2; 04713 ++c; 04714 } 04715 } 04716 04717 return com; 04718 04719 }
vector< int > Util::cml_line_insino_all | ( | vector< float > | Rot, | |
vector< int > | seq, | |||
int | n_prj, | |||
int | n_lines | |||
) | [static] |
2009-03-30 15:35:07 JB.
This function calculates all common-lines between sinogram
Definition at line 4721 of file util_sparx.cpp.
References abs, b, nint180(), and rad_deg.
04721 { 04722 vector<int> com(2*n_lines); 04723 int a=0, b, c, l; 04724 int n1=0, n2=0, mem=-1; 04725 float vmax = 1 - 1.0e-6f; 04726 double r11, r12, r13, r23, r31, r32, r33; 04727 c = 0; 04728 for (l=0; l<n_lines; ++l){ 04729 c = 2*l; 04730 if (seq[c]!=mem){ 04731 mem = seq[c]; 04732 a = seq[c]*9; 04733 } 04734 b = seq[c+1]*9; 04735 04736 // this is equivalent to R = A*B' 04737 r11 = Rot[a]*Rot[b]+Rot[a+1]*Rot[b+1]+Rot[a+2]*Rot[b+2]; 04738 r12 = Rot[a]*Rot[b+3]+Rot[a+1]*Rot[b+4]+Rot[a+2]*Rot[b+5]; 04739 r13 = Rot[a]*Rot[b+6]+Rot[a+1]*Rot[b+7]+Rot[a+2]*Rot[b+8]; 04740 r23 = Rot[a+3]*Rot[b+6]+Rot[a+4]*Rot[b+7]+Rot[a+5]*Rot[b+8]; 04741 r31 = Rot[a+6]*Rot[b]+Rot[a+7]*Rot[b+1]+Rot[a+8]*Rot[b+2]; 04742 r32 = Rot[a+6]*Rot[b+3]+Rot[a+7]*Rot[b+4]+Rot[a+8]*Rot[b+5]; 04743 r33 = Rot[a+6]*Rot[b+6]+Rot[a+7]*Rot[b+7]+Rot[a+8]*Rot[b+8]; 04744 if (r33 > vmax) { 04745 n2 = 270; 04746 n1 = 270 + nint180((float)(rad_deg*atan2(r12, r11))); 04747 } 04748 else if (r33 < -vmax) { 04749 n2 = 270; 04750 n1 = 270 - nint180((float)(rad_deg*atan2(r12, r11))); 04751 } else { 04752 n2 = nint180((float)(rad_deg*atan2(r31, -r32))); 04753 n1 = nint180((float)(rad_deg*atan2(r13, r23))); 04754 if (n1 < 0) {n1 += 360;} 04755 if (n2 <= 0) {n2 = abs(n2);} 04756 else {n2 = 360 - n2;} 04757 } 04758 if (n1 >= 360){n1 = n1 % 360;} 04759 if (n2 >= 360){n2 = n2 % 360;} 04760 04761 // store common-lines 04762 com[c] = n1; 04763 com[c+1] = n2; 04764 } 04765 04766 return com; 04767 04768 }
void Util::cml_prepare_line | ( | EMData * | sino, | |
EMData * | line, | |||
int | ilf, | |||
int | ihf, | |||
int | pos_line, | |||
int | nblines | |||
) | [static] |
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 4584 of file util_sparx.cpp.
References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), nx, and EMAN::EMData::update().
04584 { 04585 int j; 04586 int nx = sino->get_xsize(); 04587 int i = nx * pos_line; 04588 float r1, r2; 04589 float *line_ptr = line->get_data(); 04590 float *sino_ptr = sino->get_data(); 04591 for (j=ilf;j<=ihf; j += 2) { 04592 r1 = line_ptr[j]; 04593 r2 = line_ptr[j + 1]; 04594 sino_ptr[i + j - ilf] = r1; 04595 sino_ptr[i + j - ilf + 1] = r2; 04596 sino_ptr[i + nx * nblines + j - ilf] = r1; 04597 sino_ptr[i + nx * nblines + j - ilf + 1] = -r2; 04598 } 04599 sino->update(); 04600 }
vector< double > Util::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 | |||
) | [static] |
2009-03-26 11:37:53 JB.
This function spin all angle psi and evaluate the partial discrepancy belong common-lines
Definition at line 4847 of file util_sparx.cpp.
04848 { 04849 // res: [best_disc, best_ipsi] 04850 // seq: pairwise indexes ij, 0, 1, 0, 2, 0, 3, 1, 2, 1, 3, 2, 3 04851 // iw : index to know where is the weight for the common-lines on the current projection in the all weights, [12, 4, 2, 7] 04852 vector<double> res(2); 04853 int lnlen = data[0]->get_xsize(); 04854 int end = 2*(n_prj-1); 04855 double disc, buf, bdisc, tmp; 04856 int n, i, ipsi, ind, bipsi, c; 04857 float* line_1; 04858 float* line_2; 04859 bdisc = 1.0e6; 04860 bipsi = -1; 04861 // loop psi 04862 for(ipsi=0; ipsi<n_psi; ipsi += d_psi) { 04863 // discrepancy 04864 disc = 0; 04865 c = 0; 04866 for (n=0; n<n_prj; ++n) { 04867 if(n!=iprj) { 04868 ind = 2*c; 04869 line_1 = data[iprj]->get_data() + com[ind] * lnlen; 04870 line_2 = data[n]->get_data() + com[ind+1] * lnlen; 04871 buf = 0; 04872 for (i=0; i<lnlen; ++i) { 04873 tmp = line_1[i]-line_2[i]; 04874 buf += tmp*tmp; 04875 } 04876 disc += buf * weights[iw[c]]; 04877 ++c; 04878 } 04879 } 04880 // select the best value 04881 if (disc <= bdisc) { 04882 bdisc = disc; 04883 bipsi = ipsi; 04884 } 04885 // update common-lines 04886 for (i=0; i<end; i+=2){ 04887 com[i] += d_psi; 04888 if (com[i] >= n_psi) com[i] = com[i] - n_psi; 04889 } 04890 } 04891 res[0] = bdisc; 04892 res[1] = float(bipsi); 04893 04894 return res; 04895 }
vector< double > Util::cml_spin_psi_now | ( | const vector< EMData * > & | data, | |
vector< int > | com, | |||
int | iprj, | |||
vector< int > | iw, | |||
int | n_psi, | |||
int | d_psi, | |||
int | n_prj | |||
) | [static] |
Definition at line 4897 of file util_sparx.cpp.
04898 { 04899 // res: [best_disc, best_ipsi] 04900 // seq: pairwise indexes ij, 0, 1, 0, 2, 0, 3, 1, 2, 1, 3, 2, 3 04901 // iw : index to know where is the weight for the common-lines on the current projection in the all weights, [12, 4, 2, 7] 04902 vector<double> res(2); 04903 int lnlen = data[0]->get_xsize(); 04904 int end = 2*(n_prj-1); 04905 double disc, buf, bdisc, tmp; 04906 int n, i, ipsi, ind, bipsi, c; 04907 float* line_1; 04908 float* line_2; 04909 bdisc = 1.0e6; 04910 bipsi = -1; 04911 // loop psi 04912 for(ipsi=0; ipsi<n_psi; ipsi += d_psi) { 04913 // discrepancy 04914 disc = 0; 04915 c = 0; 04916 for (n=0; n<n_prj; ++n) { 04917 if(n!=iprj) { 04918 ind = 2*c; 04919 line_1 = data[iprj]->get_data() + com[ind] * lnlen; 04920 line_2 = data[n]->get_data() + com[ind+1] * lnlen; 04921 buf = 0; 04922 for (i=0; i<lnlen; ++i) { 04923 tmp = line_1[i]-line_2[i]; 04924 buf += tmp*tmp; 04925 } 04926 disc += buf; 04927 ++c; 04928 } 04929 } 04930 // select the best value 04931 if (disc <= bdisc) { 04932 bdisc = disc; 04933 bipsi = ipsi; 04934 } 04935 // update common-lines 04936 for (i=0; i<end; i+=2){ 04937 com[i] += d_psi; 04938 if (com[i] >= n_psi) com[i] = com[i] - n_psi; 04939 } 04940 } 04941 res[0] = bdisc; 04942 res[1] = float(bipsi); 04943 04944 return res; 04945 }
vector< float > Util::cml_update_rot | ( | vector< float > | Rot, | |
int | iprj, | |||
float | nph, | |||
float | th, | |||
float | nps | |||
) | [static] |
2009-03-25 15:35:37 JB.
this function update only one rotation amtrix according a new orientation
Definition at line 4640 of file util_sparx.cpp.
References deg_rad.
04640 { 04641 float ph, ps; 04642 double cph, cth, cps, sph, sth, sps; 04643 int ind = iprj*9; 04644 // spider convention phi=psi-90, psi=phi+90 04645 ph = nps-90; 04646 ps = nph+90; 04647 ph *= deg_rad; 04648 th *= deg_rad; 04649 ps *= deg_rad; 04650 // pre-calculate some trigo stuffs 04651 cph = cos(ph); 04652 cth = cos(th); 04653 cps = cos(ps); 04654 sph = sin(ph); 04655 sth = sin(th); 04656 sps = sin(ps); 04657 // fill rotation matrix 04658 Rot[ind] = (float)(cph*cps-cth*sps*sph); 04659 Rot[ind+1] = (float)(cph*sps+cth*cps*sph); 04660 Rot[ind+2] = (float)(sth*sph); 04661 Rot[ind+3] = (float)(-sph*cps-cth*sps*cph); 04662 Rot[ind+4] = (float)(-sph*sps+cth*cps*cph); 04663 Rot[ind+5] = (float)(sth*cph); 04664 Rot[ind+6] = (float)(sth*sps); 04665 Rot[ind+7] = (float)(-sth*cps); 04666 Rot[ind+8] = (float)(cth); 04667 04668 return Rot; 04669 }
vector< double > Util::cml_weights | ( | const vector< float > & | cml | ) | [static] |
Definition at line 4494 of file util_sparx.cpp.
References Assert, PI2, and vrdg().
04494 { 04495 static const int NBIN = 100; 04496 int nline=cml.size()/2; 04497 vector<double> weights(nline); 04498 04499 vector<ori_t> angs(nline); 04500 for( int i=0; i < nline; ++i ) { 04501 angs[i].iphi = int( NBIN*cml[2*i] ); 04502 angs[i].itht = int( NBIN*cml[2*i+1] ); 04503 if( angs[i].itht == 180*NBIN ) angs[i].itht = 0; 04504 angs[i].id = i; 04505 } 04506 04507 //std::cout << "# of angs: " << angs.size() << std::endl; 04508 04509 std::sort( angs.begin(), angs.end(), cmpang() ); 04510 04511 vector<float> newphi; 04512 vector<float> newtht; 04513 vector< vector<int> > indices; 04514 04515 int curt_iphi = -1; 04516 int curt_itht = -1; 04517 for(unsigned int i=0 ;i < angs.size(); ++i ) { 04518 if( angs[i].iphi==curt_iphi && angs[i].itht==curt_itht ) { 04519 Assert( indices.size() > 0 ); 04520 indices.back().push_back(angs[i].id); 04521 } else { 04522 curt_iphi = angs[i].iphi; 04523 curt_itht = angs[i].itht; 04524 04525 newphi.push_back( float(curt_iphi)/NBIN ); 04526 newtht.push_back( float(curt_itht)/NBIN ); 04527 indices.push_back( vector<int>(1,angs[i].id) ); 04528 } 04529 } 04530 04531 //std::cout << "# of indpendent ang: " << newphi.size() << std::endl; 04532 04533 04534 int num_agl = newphi.size(); 04535 04536 if(num_agl>2) { 04537 vector<double> w=Util::vrdg(newphi, newtht); 04538 04539 Assert( w.size()==newphi.size() ); 04540 Assert( indices.size()==newphi.size() ); 04541 04542 for(unsigned int i=0; i < newphi.size(); ++i ) { 04543 /* 04544 std::cout << "phi,tht,w,n: "; 04545 std::cout << boost::format( "%10.3f" ) % newphi[i] << " "; 04546 std::cout << boost::format( "%10.3f" ) % newtht[i] << " "; 04547 std::cout << boost::format( "%8.6f" ) % w[i] << " "; 04548 std::cout << indices[i].size() << "("; 04549 */ 04550 04551 for(unsigned int j=0; j < indices[i].size(); ++j ) { 04552 int id = indices[i][j]; 04553 weights[id] = w[i]/indices[i].size(); 04554 //std::cout << id << " "; 04555 } 04556 04557 //std::cout << ")" << std::endl; 04558 04559 } 04560 } else { 04561 cout<<"warning in Util.cml_weights"<<endl; 04562 double val = PI2/float(nline); 04563 for(int i=0; i<nline; i++) weights[i]=val; 04564 } 04565 04566 return weights; 04567 04568 }
Definition at line 7177 of file util_sparx.cpp.
References EMAN::Util::tmpstruct::theta1.
Referenced by hsortd().
Definition at line 7182 of file util_sparx.cpp.
References EMAN::Util::tmpstruct::key1.
Referenced by hsortd().
void Util::colreverse | ( | float * | beg, | |
float * | end, | |||
int | nx | |||
) | [static] |
Definition at line 5305 of file util_sparx.cpp.
Referenced by cyclicshift(), and slicereverse().
05305 { 05306 float* tmp = new float[nx]; 05307 int n = (end - beg)/nx; 05308 int nhalf = n/2; 05309 for (int i = 0; i < nhalf; i++) { 05310 // swap col i and col n-1-i 05311 memcpy(tmp, beg+i*nx, nx*sizeof(float)); 05312 memcpy(beg+i*nx, beg+(n-1-i)*nx, nx*sizeof(float)); 05313 memcpy(beg+(n-1-i)*nx, tmp, nx*sizeof(float)); 05314 } 05315 delete[] tmp; 05316 }
Definition at line 6060 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().
Referenced by EMAN::PCA::dopca(), and EMAN::PCA::dopca_lan().
06061 { 06062 /*********** 06063 ***get the size of the image for validation purpose 06064 **************/ 06065 int nx = image->get_xsize(); 06066 int ny = image->get_ysize(); 06067 int nz = image->get_zsize(); 06068 /******** 06069 ***Exception Handle 06070 *************/ 06071 if(nx != mask->get_xsize() || ny != mask->get_ysize() || nz != mask->get_zsize()) 06072 throw ImageDimensionException("The dimension of the image does not match the dimension of the mask!"); 06073 06074 size_t i, size = (size_t)nx*ny*nz; 06075 06076 float* img_ptr = image->get_data(); 06077 float* mask_ptr = mask->get_data(); 06078 06079 int ln=0; //length of the output image = number of points under the mask. 06080 for(i = 0;i < size;i++) if(mask_ptr[i] > 0.5f) ln++; 06081 06082 EMData* new_image = new EMData(); 06083 new_image->set_size(ln,1,1); /* set size of the new image */ 06084 float *new_ptr = new_image->get_data(); 06085 06086 ln=-1; 06087 for(i = 0;i < size;i++){ 06088 if(mask_ptr[i] > 0.5f) { 06089 ln++; 06090 new_ptr[ln]=img_ptr[i]; 06091 } 06092 } 06093 06094 return new_image; 06095 }
void Util::constrained_helix | ( | vector< EMData * > | data, | |
vector< EMData * > | fdata, | |||
vector< EMData * > | refproj, | |||
vector< EMData * > | rotproj, | |||
vector< float > | dp_dphi_rise_delta, | |||
vector< int > | nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc, | |||
bool | FindPsi, | |||
float | psi_max, | |||
vector< EMData * > | crefim, | |||
vector< int > | numr, | |||
int | maxrin, | |||
string | mode, | |||
int | cnx, | |||
int | cny | |||
) | [static] |
Definition at line 21935 of file util_sparx.cpp.
References abs, ang_n(), EMAN::CIRCULANT, compose_transform2(), EMAN::correlation(), Crosrng_msg_s(), Frngs(), get_attr(), get_transform_params(), get_value_at(), max, min, Polar2Dm(), sqrt(), t, tot, and window().
21938 { 21939 if (dp_dphi_rise_delta.size() < 4) { 21940 printf("Not enough parameters (dp_dphi_rise_delta)"); 21941 return; 21942 } 21943 if (nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc.size() < 9) { 21944 printf("Not enough parameters (nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc)"); 21945 return; 21946 } 21947 float dpsi; 21948 //float dp = dp_dphi_rise_delta[0]; 21949 float dphi = dp_dphi_rise_delta[1]; 21950 int rise = static_cast<int>(dp_dphi_rise_delta[2] + 0.2); 21951 float delta = dp_dphi_rise_delta[3]; 21952 int nphi = nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc[0]; 21953 int phiwobble = nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc[1]; 21954 int range = nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc[2]; 21955 int ywobble = nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc[3]; 21956 bool Dsym = nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc[4]; 21957 int nwx = nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc[5]; 21958 int nwy = nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc[6]; 21959 int nwxc = nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc[7]; 21960 int nwyc = nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc[8]; 21961 21962 const int ndata = data.size(); 21963 21964 std::vector< boost::shared_ptr<EMData> > objectsToDelete; // objects added to this vector are automatically deleted at the end of this function 21965 21966 vector<float> c0 = data[0]->get_attr("ptcl_source_coord"); 21967 vector< vector<EMData*> > ccfs(ndata, vector<EMData*>(nphi)); 21968 vector< vector<EMData*> > ccfr(0); 21969 if (! Dsym) { 21970 ccfr.resize(ndata, vector<EMData*>(nphi)); 21971 } 21972 for (int im = 0; im < ndata; ++im) { 21973 for (int iphi = 0; iphi < nphi; ++iphi) { 21974 std::auto_ptr<EMData> corr( correlation( refproj[iphi], fdata[im], CIRCULANT, true) ); 21975 ccfs[im][iphi] = Util::window( corr.get(), nwx, nwy); 21976 objectsToDelete.push_back(boost::shared_ptr<EMData>(ccfs[im][iphi])); 21977 if (! Dsym) { 21978 std::auto_ptr<EMData> corr2( correlation( rotproj[iphi], fdata[im], CIRCULANT, true) ); 21979 ccfr[im][iphi] = Util::window( corr2.get(), nwx, nwy); 21980 objectsToDelete.push_back(boost::shared_ptr<EMData>(ccfr[im][iphi])); 21981 } 21982 } 21983 } 21984 vector<float> dxshiftlocal(ndata, 0); 21985 vector<float> dyshiftlocal(ndata, 0); 21986 vector<float> dphilocal(ndata, 0); 21987 21988 vector<float> xshiftlocal(ndata, 0); 21989 vector<float> xrshiftlocal(ndata, 0); 21990 vector<float> mxshiftlocal(ndata, 0); 21991 vector<float> yshiftlocal(ndata, 0); 21992 vector<float> yrshiftlocal(ndata, 0); 21993 vector<float> myshiftlocal(ndata, 0); 21994 vector<float> philocal(ndata, 0); 21995 vector<float> phirlocal(ndata, 0); 21996 vector<float> mphilocal(ndata, 0); 21997 float dirma = -1.0e23f; 21998 for (int idir = -1; idir < 2; idir += 2) { 21999 float tmax = -1.0e23f; 22000 float mpsi; 22001 for (int ix = 1; ix < nwx-1; ++ix) { //# X shift 22002 //#cout << "im: ", len(ccfs), ix,time()-start_time 22003 int six = ix - nwxc; 22004 for (int iy = 1+ywobble; iy < nwy-ywobble-1; ++iy) { //# Y shift 22005 int siy = iy - nwyc; 22006 yshiftlocal[0] = float(iy-nwyc); 22007 yrshiftlocal[0] = float(iy-nwyc); 22008 for (int iphi = 0; iphi < nphi; ++iphi) { //# phi search 22009 float qphi = iphi*delta; 22010 philocal[0] = qphi; 22011 phirlocal[0] = fmod( 180.0f - qphi + ((int)(fabs((180.0f-qphi)/360.0f))+1)*360.0f , 360.0f ); 22012 //# we use the first segment as a reference, so there is no interpolation, just copy the correlation 22013 //# Select largest correlation within +/- range pixels from the location we explore 22014 float mxm = -1.0e23f; 22015 float mxr; 22016 for (int iux = max(1, ix - range); iux < min(nwx - 1, ix+range+1); ++iux) { //# X wobble 22017 float qcf = ccfs[0][iphi]->get_value_at(iux,iy); 22018 if (qcf > mxm) { 22019 mxm = qcf; 22020 xshiftlocal[0] = float(iux-nwxc); 22021 } 22022 } 22023 if (! Dsym) { 22024 mxr = -1.0e23f; 22025 for (int iux = max(1, ix - range); iux < min(nwx - 1, ix+range+1); ++iux) { //# Xr wobble 22026 float qcf = ccfr[0][iphi]->get_value_at(iux,iy); 22027 if (qcf > mxr) { 22028 mxr = qcf; 22029 xrshiftlocal[0] = float(iux-nwxc); 22030 } 22031 } 22032 } 22033 for ( int im = 1; im < ndata; ++im) { //# predicted locations 22034 //# dst is distance between segment 0 and current segment in pixels 22035 vector<float> cim = data[im]->get_attr("ptcl_source_coord"); 22036 float dst = sqrt( (c0[0] - cim[0])*(c0[0] - cim[0]) + (c0[1] - cim[1])*(c0[1] - cim[1])); 22037 //# predict for all remaining segments assuming number 0 22038 qphi = idir*(dst/rise)*dphi; 22039 float pphi = fmod(philocal[0] + qphi + ((int)(abs(qphi/360.0f))+1)*360.0f , 360.0f); //# predicted phi with full angular accuracy, not an integer 22040 int pix = six; //# predicted x shift 22041 int piy = siy; //# predicted y shift 22042 int xix = pix + nwxc; 22043 int yiy = piy + nwyc; 22044 //# Local x search 22045 int fix = int(xix); 22046 float xdif = xix - fix; 22047 float xrem = 1.0f - xdif; 22048 int fiy = int(yiy); 22049 float ydif = yiy - fiy; 22050 float yrem = 1.0f - ydif; 22051 float ciq = -1.0e23f; 22052 //# interpolate correlation at pphi 22053 qphi = pphi/delta; 22054 int ttphi = (int( qphi + ((int)(abs(qphi/nphi))+1)*nphi+ 0.5))%nphi; 22055 for (int lphi = -phiwobble; lphi < phiwobble+1; ++lphi) { //# phi wobble 22056 int tphi = (ttphi+lphi+nphi)%nphi; 22057 for (int iux = max(1, fix - range); iux < min(nwx - 1, fix+range+1); ++iux) { //# X wobble 22058 for (int iuy = max(1, fiy - ywobble); iuy < min(nwy - 1, fiy+ywobble+1); ++iuy) { //# Y wobble 22059 float qcf = xrem*yrem*ccfs[im][tphi]->get_value_at(iux,iuy) 22060 + xdif*yrem*ccfs[im][tphi]->get_value_at(iux+1,iuy) 22061 + xrem*ydif*ccfs[im][tphi]->get_value_at(iux,iuy+1) 22062 + xdif*ydif*ccfs[im][tphi]->get_value_at(iux+1,iuy+1); 22063 if (qcf > ciq) { 22064 ciq = qcf; 22065 xshiftlocal[im] = iux + xdif - nwxc; 22066 yshiftlocal[im] = iuy + ydif - nwyc; 22067 philocal[im] = tphi * delta; 22068 } 22069 } 22070 } 22071 } 22072 mxm += ciq; 22073 //# now for rotated 22074 if (! Dsym) { 22075 qphi = idir*(dst/rise)*dphi; 22076 pphi = fmod(phirlocal[0] + qphi + ((int)(abs(qphi/360.0f))+1)*360.0f, 360.0f); //# predicted phi for rotated 180 defs with full angular accuracy, not an integer 22077 pix = six; //# predicted x shift 22078 piy = siy; //# predicted y shift 22079 xix = pix + nwxc; 22080 yiy = piy + nwyc; 22081 fix = int(xix); 22082 xdif = xix - fix; 22083 xrem = 1.0f - xdif; 22084 fiy = int(yiy); 22085 ydif = yiy - fiy; 22086 yrem = 1.0f - ydif; 22087 ciq = -1.0e23f; 22088 //# interpolate correlation at pphi 22089 for (int lphi = -phiwobble; lphi < phiwobble+1; ++lphi) { //# phi wobble 22090 qphi = lphi*delta; 22091 float qtphi = fmod( pphi + qphi + (int(fabs(qphi/360.0f))+1)*360.0f , 360.0f); 22092 qphi = fmod(540.0f-qtphi, 360.0f) / delta; 22093 int tphi = (int( qphi + (int(fabs(qphi/nphi))+1)*nphi + 0.5))%nphi; 22094 for (int iux = max(1, fix - range); iux < min(nwx - 1, fix+range+1); ++iux) { //# X wobble 22095 for (int iuy = max(1, fiy - ywobble); iuy < min(nwy - 1, fiy+ywobble+1); ++iuy) { //# Y wobble 22096 float qcf = xrem*yrem*ccfr[im][tphi]->get_value_at(iux,iuy) 22097 + xdif*yrem*ccfr[im][tphi]->get_value_at(iux+1,iuy) 22098 + xrem*ydif*ccfr[im][tphi]->get_value_at(iux,iuy+1) 22099 + xdif*ydif*ccfr[im][tphi]->get_value_at(iux+1,iuy+1); 22100 if (qcf > ciq) { 22101 ciq = qcf; 22102 xrshiftlocal[im] = iux + xdif - nwxc; 22103 yrshiftlocal[im] = iuy + ydif - nwyc; 22104 phirlocal[im] = int(qtphi/delta+0.5f)*delta; 22105 } 22106 } 22107 } 22108 } 22109 mxr += ciq; 22110 } else { 22111 mxr = mxm-1.e5; 22112 } 22113 } 22114 if ( mxr > mxm ) { 22115 if (mxr > tmax) { 22116 tmax = mxr; 22117 mpsi = 270.0f; 22118 for (int im = 0; im < ndata; ++im) mxshiftlocal[im] = xrshiftlocal[im]; 22119 for (int im = 0; im < ndata; ++im) myshiftlocal[im] = yrshiftlocal[im]; 22120 for (int im = 0; im < ndata; ++im) mphilocal[im] = fmod(540.0f-phirlocal[im], 360.0f); 22121 } 22122 } else { 22123 if (mxm > tmax) { 22124 tmax = mxm; 22125 mpsi = 90.0f; 22126 for (int im = 0; im < ndata; ++im) mxshiftlocal[im] = xshiftlocal[im]; 22127 for (int im = 0; im < ndata; ++im) myshiftlocal[im] = yshiftlocal[im]; 22128 for (int im = 0; im < ndata; ++im) mphilocal[im] = philocal[im]; 22129 } 22130 } 22131 } 22132 } 22133 } 22134 if (tmax > dirma) { 22135 dirma = tmax; 22136 dpsi = mpsi; 22137 for (int im = 0; im < ndata; ++im) dxshiftlocal[im] = mxshiftlocal[im]; 22138 for (int im = 0; im < ndata; ++im) dyshiftlocal[im] = myshiftlocal[im]; 22139 for (int im = 0; im < ndata; ++im) dphilocal[im] = mphilocal[im]; 22140 } 22141 } 22142 22143 for (int im = 0; im < ndata; ++im) { 22144 float psx = dxshiftlocal[im]; 22145 float psy = dyshiftlocal[im]; 22146 float pphi = dphilocal[im]; 22147 float epsi; 22148 float bestang; 22149 if (FindPsi) { 22150 float qphi = pphi/delta; 22151 int iphi = ( int(qphi + ((int)(abs(qphi/nphi))+1)*nphi + 0.5f))%nphi ; 22152 //#cout << " ref number and current parameters reduced to 2D ",iphi,0.0, psx, psy 22153 Dict params = Util::get_transform_params(data[im], "xform.projection", "spider"); 22154 float opsi3 = params["psi"]; 22155 float opx3 = -static_cast<float>(params["tx"]); 22156 float opy3 = -static_cast<float>(params["ty"]); 22157 //#cout << " old 3D params in data ",ophi, otheta, opsi3, opx3, opy3 22158 float gamma = (abs(opsi3 - 90) < abs(opsi3 - 270)) ? (90) : (270); 22159 float oalpha, osx, osy; 22160 compose_transform2(0, opx3, opy3, gamma-opsi3, 0, 0, oalpha, osx, osy); //# reduce 3D to 2D 22161 //#cout << " old 3D params, -> 2D ",oalpha, osx, osy 22162 //# combine previous with the current in plane 22163 //#cout << " current 2D combined with old 2D rotation",oalpha, csx, csy 22164 //# Find what the shift is without the angle 22165 float junk, nnsx, nnsy; 22166 compose_transform2(0, psx, psy, -oalpha, 0, 0, junk, nnsx, nnsy); 22167 //#cout << " 2D shift without angle ",nnsx, nnsy 22168 22169 std::auto_ptr<EMData> cimage( Util::Polar2Dm(data[im], cnx+nnsx, cny+nnsy, numr, mode) ); 22170 Util::Frngs(cimage.get(), numr); 22171 std::auto_ptr<EMData> temp( Util::Crosrng_msg_s( cimage.get(), crefim[iphi], numr) ); 22172 22173 int ipr = int(psi_max*maxrin/360.0f + 0.5f); 22174 int incpsi = (dpsi == 270.0f) ? (maxrin/2) : (0); 22175 float qn = -1.0e23f; 22176 for (int ips = -ipr; ips < ipr+1; ++ips) { 22177 int tot = (ips + incpsi + maxrin)%maxrin; 22178 float tval = temp->get_value_at(tot); 22179 if (tval > qn) { 22180 qn = tval; 22181 bestang = ang_n(tot+1.0f, mode, maxrin); 22182 } 22183 } 22184 //#cout << " best angle ",bestang 22185 bestang = fmod(bestang - (dpsi-90.0f) + 720.0f, 360.0f); 22186 //#cout << " angle applied ",bestang 22187 //#rot_shift2D(data[im],-bestang).write_image("rotated.hdf",im) 22188 //std::auto_ptr<EMData> rot_data_im( data[im]->rot_scale_trans2D_background(-bestang, 0, 0, 1) ); 22189 //fdata[im] = (rot_data_im->is_complex()) ? (rot_data_im->do_ift()) : (rot_data_im->do_fft()); 22190 22191 //#cout << " New composed 3D ",dpsi,bestang, nnsx, nnsy 22192 22193 epsi = fmod(bestang+dpsi, 360.0f); 22194 psx = nnsx; 22195 psy = nnsy; 22196 //#cout << " New composed 3D ",pphi,90.0,epsi, psx, psy 22197 } else { 22198 epsi = dpsi; 22199 bestang = 0; 22200 } 22201 data[im]->set_attr("bestang",fmod(720.0f-bestang, 360.0f)); 22202 //printf(" %7.2f %7.2f %7.2f %7.2f %7.2f\n", pphi, 90.0, epsi, psx, psy); 22203 Dict t_params; 22204 t_params["type"] = "spider"; 22205 t_params["phi"] = pphi; 22206 t_params["theta"] = 90.0f; 22207 t_params["psi"] = epsi; 22208 t_params["tx"] = -psx; 22209 t_params["ty"] = -psy; 22210 Transform t(t_params); 22211 data[im]->set_attr("xform.projection", &t); 22212 } 22213 }
void Util::constrained_helix_test | ( | vector< EMData * > | data, | |
vector< EMData * > | fdata, | |||
vector< EMData * > | refproj, | |||
vector< EMData * > | rotproj, | |||
vector< float > | dp_dphi_rise_delta, | |||
vector< int > | nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc, | |||
bool | FindPsi, | |||
float | psi_max, | |||
vector< EMData * > | crefim, | |||
vector< int > | numr, | |||
int | maxrin, | |||
string | mode, | |||
int | cnx, | |||
int | cny | |||
) | [static] |
Definition at line 22215 of file util_sparx.cpp.
References abs, ang_n(), EMAN::CIRCULANT, compose_transform2(), EMAN::correlation(), Crosrng_msg_s(), Frngs(), get_attr(), get_transform_params(), get_value_at(), max, min, Polar2Dm(), predict(), sqrt(), t, tot, and window().
22218 { 22219 if (dp_dphi_rise_delta.size() < 4) { 22220 printf("Not enough parameters (dp_dphi_rise_delta)"); 22221 return; 22222 } 22223 if (nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc.size() < 9) { 22224 printf("Not enough parameters (nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc)"); 22225 return; 22226 } 22227 float dpsi; 22228 //float dp = dp_dphi_rise_delta[0]; 22229 float dphi = dp_dphi_rise_delta[1]; 22230 int rise = static_cast<int>(dp_dphi_rise_delta[2] + 0.2); 22231 float delta = dp_dphi_rise_delta[3]; 22232 int nphi = nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc[0]; 22233 int phiwobble = nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc[1]; 22234 int range = nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc[2]; 22235 int ywobble = nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc[3]; 22236 bool Dsym = nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc[4]; 22237 int nwx = nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc[5]; 22238 int nwy = nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc[6]; 22239 int nwxc = nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc[7]; 22240 int nwyc = nphi_phiwobble_range_ywobble_Dsym_nwx_nwy_nwxc_nwyc[8]; 22241 22242 const int ndata = data.size(); 22243 22244 std::vector< boost::shared_ptr<EMData> > objectsToDelete; // objects added to this vector are automatically deleted at the end of this function 22245 22246 vector<float> c0 = data[0]->get_attr("ptcl_source_coord"); 22247 vector< vector<EMData*> > ccfs(ndata, vector<EMData*>(nphi)); 22248 vector< vector<EMData*> > ccfr(0); 22249 if (! Dsym) { 22250 ccfr.resize(ndata, vector<EMData*>(nphi)); 22251 } 22252 for (int im = 0; im < ndata; ++im) { 22253 for (int iphi = 0; iphi < nphi; ++iphi) { 22254 std::auto_ptr<EMData> corr( correlation( refproj[iphi], fdata[im], CIRCULANT, true) ); 22255 ccfs[im][iphi] = Util::window( corr.get(), nwx, nwy); 22256 objectsToDelete.push_back(boost::shared_ptr<EMData>(ccfs[im][iphi])); 22257 if (! Dsym) { 22258 std::auto_ptr<EMData> corr2( correlation( rotproj[iphi], fdata[im], CIRCULANT, true) ); 22259 ccfr[im][iphi] = Util::window( corr2.get(), nwx, nwy); 22260 objectsToDelete.push_back(boost::shared_ptr<EMData>(ccfr[im][iphi])); 22261 } 22262 } 22263 } 22264 vector<float> dxshiftlocal(ndata, 0); 22265 vector<float> dyshiftlocal(ndata, 0); 22266 vector<float> dphilocal(ndata, 0); 22267 22268 vector<float> xshiftlocal(ndata, 0); 22269 vector<float> xrshiftlocal(ndata, 0); 22270 vector<float> mxshiftlocal(ndata, 0); 22271 vector<float> yshiftlocal(ndata, 0); 22272 vector<float> yrshiftlocal(ndata, 0); 22273 vector<float> myshiftlocal(ndata, 0); 22274 vector<float> philocal(ndata, 0); 22275 vector<float> phirlocal(ndata, 0); 22276 vector<float> mphilocal(ndata, 0); 22277 float dirma = -1.0e23f; 22278 for (int yidir = -1; yidir < 2; yidir += 2) { 22279 for (int idir = -1; idir < 2; idir += 2) { 22280 float tmax = -1.0e23f; 22281 float mpsi; 22282 for (int ix = 1; ix < nwx-1; ++ix) { //# X shift 22283 //#cout << "im: ", len(ccfs), ix,time()-start_time 22284 int six = ix - nwxc; 22285 for (int iy = 1+ywobble; iy < nwy-ywobble-1; ++iy) { //# Y shift 22286 int siy = iy - nwyc; 22287 yshiftlocal[0] = float(iy-nwyc); 22288 yrshiftlocal[0] = float(iy-nwyc); 22289 for (int iphi = 0; iphi < nphi; ++iphi) { //# phi search 22290 float qphi = iphi*delta; 22291 philocal[0] = qphi; 22292 phirlocal[0] = fmod( 180.0f - qphi + ((int)(fabs((180.0f-qphi)/360.0f))+1)*360.0f , 360.0f ); 22293 //# we use the first segment as a reference, so there is no interpolation, just copy the correlation 22294 //# Select largest correlation within +/- range pixels from the location we explore 22295 float mxm = -1.0e23f; 22296 float mxr; 22297 for (int iux = max(1, ix - range); iux < min(nwx - 1, ix+range+1); ++iux) { //# X wobble 22298 float qcf = ccfs[0][iphi]->get_value_at(iux,iy); 22299 if (qcf > mxm) { 22300 mxm = qcf; 22301 xshiftlocal[0] = float(iux-nwxc); 22302 } 22303 } 22304 if (! Dsym) { 22305 mxr = -1.0e23f; 22306 for (int iux = max(1, ix - range); iux < min(nwx - 1, ix+range+1); ++iux) { //# Xr wobble 22307 float qcf = ccfr[0][iphi]->get_value_at(iux,iy); 22308 if (qcf > mxr) { 22309 mxr = qcf; 22310 xrshiftlocal[0] = float(iux-nwxc); 22311 } 22312 } 22313 } 22314 for ( int im = 1; im < ndata; ++im) { //# predicted locations 22315 //# dst is distance between segment 0 and current segment in pixels 22316 vector<float> cim = data[im]->get_attr("ptcl_source_coord"); 22317 float dst = sqrt( (c0[0] - cim[0])*(c0[0] - cim[0]) + (c0[1] - cim[1])*(c0[1] - cim[1])); 22318 //# predict for all remaining segments assuming number 0 22319 qphi = idir*(dst/rise)*dphi; 22320 //float pphi = fmod(philocal[0] + qphi + ((int)(abs(qphi/360.0f))+1)*360.0f , 360.0f); //# predicted phi with full angular accuracy, not an integer 22321 int pix = six; //# predicted x shift 22322 //int piy = siy; //# predicted y shift 22323 Dict pret = predict(philocal[0], siy, dst, idir, yidir, rise, dphi, true); 22324 float piy = pret["predy"]; 22325 float pphi = pret["predphi"]; 22326 int xix = pix + nwxc; 22327 float yiy = piy + nwyc; 22328 //# Local x search 22329 int fix = int(xix); 22330 float xdif = xix - fix; 22331 float xrem = 1.0f - xdif; 22332 int fiy = int(yiy); 22333 float ydif = yiy - fiy; 22334 float yrem = 1.0f - ydif; 22335 float ciq = -1.0e23f; 22336 //# interpolate correlation at pphi 22337 qphi = pphi/delta; 22338 int ttphi = (int( qphi + ((int)(abs(qphi/nphi))+1)*nphi+ 0.5))%nphi; 22339 for (int lphi = -phiwobble; lphi < phiwobble+1; ++lphi) { //# phi wobble 22340 int tphi = (ttphi+lphi+nphi)%nphi; 22341 for (int iux = max(1, fix - range); iux < min(nwx - 1, fix+range+1); ++iux) { //# X wobble 22342 for (int iuy = max(1, fiy - ywobble); iuy < min(nwy - 1, fiy+ywobble+1); ++iuy) { //# Y wobble 22343 float qcf = xrem*yrem*ccfs[im][tphi]->get_value_at(iux,iuy) 22344 + xdif*yrem*ccfs[im][tphi]->get_value_at(iux+1,iuy) 22345 + xrem*ydif*ccfs[im][tphi]->get_value_at(iux,iuy+1) 22346 + xdif*ydif*ccfs[im][tphi]->get_value_at(iux+1,iuy+1); 22347 if (qcf > ciq) { 22348 ciq = qcf; 22349 xshiftlocal[im] = iux + xdif - nwxc; 22350 yshiftlocal[im] = iuy + ydif - nwyc; 22351 philocal[im] = tphi * delta; 22352 } 22353 } 22354 } 22355 } 22356 mxm += ciq; 22357 //# now for rotated 22358 if (! Dsym) { 22359 qphi = idir*(dst/rise)*dphi; 22360 //pphi = fmod(phirlocal[0] + qphi + ((int)(abs(qphi/360.0f))+1)*360.0f, 360.0f); //# predicted phi for rotated 180 defs with full angular accuracy, not an integer 22361 pix = six; //# predicted x shift 22362 //piy = siy; //# predicted y shift 22363 Dict pret = predict(phirlocal[0], siy, dst, idir, yidir, rise, dphi, true); 22364 piy = pret["predy"]; 22365 pphi = pret["predphi"]; 22366 xix = pix + nwxc; 22367 yiy = piy + nwyc; 22368 fix = int(xix); 22369 xdif = xix - fix; 22370 xrem = 1.0f - xdif; 22371 fiy = int(yiy); 22372 ydif = yiy - fiy; 22373 yrem = 1.0f - ydif; 22374 ciq = -1.0e23f; 22375 //# interpolate correlation at pphi 22376 for (int lphi = -phiwobble; lphi < phiwobble+1; ++lphi) { //# phi wobble 22377 qphi = lphi*delta; 22378 float qtphi = fmod( pphi + qphi + (int(fabs(qphi/360.0f))+1)*360.0f , 360.0f); 22379 qphi = fmod(540.0f-qtphi, 360.0f) / delta; 22380 int tphi = (int( qphi + (int(fabs(qphi/nphi))+1)*nphi + 0.5))%nphi; 22381 for (int iux = max(1, fix - range); iux < min(nwx - 1, fix+range+1); ++iux) { //# X wobble 22382 for (int iuy = max(1, fiy - ywobble); iuy < min(nwy - 1, fiy+ywobble+1); ++iuy) { //# Y wobble 22383 float qcf = xrem*yrem*ccfr[im][tphi]->get_value_at(iux,iuy) 22384 + xdif*yrem*ccfr[im][tphi]->get_value_at(iux+1,iuy) 22385 + xrem*ydif*ccfr[im][tphi]->get_value_at(iux,iuy+1) 22386 + xdif*ydif*ccfr[im][tphi]->get_value_at(iux+1,iuy+1); 22387 if (qcf > ciq) { 22388 ciq = qcf; 22389 xrshiftlocal[im] = iux + xdif - nwxc; 22390 yrshiftlocal[im] = iuy + ydif - nwyc; 22391 phirlocal[im] = int(qtphi/delta+0.5f)*delta; 22392 } 22393 } 22394 } 22395 } 22396 mxr += ciq; 22397 } else { 22398 mxr = mxm-1.e5; 22399 } 22400 } 22401 if ( mxr > mxm ) { 22402 if (mxr > tmax) { 22403 tmax = mxr; 22404 mpsi = 270.0f; 22405 for (int im = 0; im < ndata; ++im) mxshiftlocal[im] = xrshiftlocal[im]; 22406 for (int im = 0; im < ndata; ++im) myshiftlocal[im] = yrshiftlocal[im]; 22407 for (int im = 0; im < ndata; ++im) mphilocal[im] = fmod(540.0f-phirlocal[im], 360.0f); 22408 } 22409 } else { 22410 if (mxm > tmax) { 22411 tmax = mxm; 22412 mpsi = 90.0f; 22413 for (int im = 0; im < ndata; ++im) mxshiftlocal[im] = xshiftlocal[im]; 22414 for (int im = 0; im < ndata; ++im) myshiftlocal[im] = yshiftlocal[im]; 22415 for (int im = 0; im < ndata; ++im) mphilocal[im] = philocal[im]; 22416 } 22417 } 22418 } 22419 } 22420 } 22421 if (tmax > dirma) { 22422 dirma = tmax; 22423 dpsi = mpsi; 22424 for (int im = 0; im < ndata; ++im) dxshiftlocal[im] = mxshiftlocal[im]; 22425 for (int im = 0; im < ndata; ++im) dyshiftlocal[im] = myshiftlocal[im]; 22426 for (int im = 0; im < ndata; ++im) dphilocal[im] = mphilocal[im]; 22427 } 22428 } 22429 } 22430 22431 for (int im = 0; im < ndata; ++im) { 22432 float psx = dxshiftlocal[im]; 22433 float psy = dyshiftlocal[im]; 22434 float pphi = dphilocal[im]; 22435 float epsi; 22436 float bestang; 22437 if (FindPsi) { 22438 float qphi = pphi/delta; 22439 int iphi = ( int(qphi + ((int)(abs(qphi/nphi))+1)*nphi + 0.5f))%nphi ; 22440 //#cout << " ref number and current parameters reduced to 2D ",iphi,0.0, psx, psy 22441 Dict params = Util::get_transform_params(data[im], "xform.projection", "spider"); 22442 float opsi3 = params["psi"]; 22443 float opx3 = -static_cast<float>(params["tx"]); 22444 float opy3 = -static_cast<float>(params["ty"]); 22445 //#cout << " old 3D params in data ",ophi, otheta, opsi3, opx3, opy3 22446 float gamma = (abs(opsi3 - 90) < abs(opsi3 - 270)) ? (90) : (270); 22447 float oalpha, osx, osy; 22448 compose_transform2(0, opx3, opy3, gamma-opsi3, 0, 0, oalpha, osx, osy); //# reduce 3D to 2D 22449 //#cout << " old 3D params, -> 2D ",oalpha, osx, osy 22450 //# combine previous with the current in plane 22451 //#cout << " current 2D combined with old 2D rotation",oalpha, csx, csy 22452 //# Find what the shift is without the angle 22453 float junk, nnsx, nnsy; 22454 compose_transform2(0, psx, psy, -oalpha, 0, 0, junk, nnsx, nnsy); 22455 //#cout << " 2D shift without angle ",nnsx, nnsy 22456 22457 std::auto_ptr<EMData> cimage( Util::Polar2Dm(data[im], cnx+nnsx, cny+nnsy, numr, mode) ); 22458 Util::Frngs(cimage.get(), numr); 22459 std::auto_ptr<EMData> temp( Util::Crosrng_msg_s( cimage.get(), crefim[iphi], numr) ); 22460 22461 int ipr = int(psi_max*maxrin/360.0f + 0.5f); 22462 int incpsi = (dpsi == 270.0f) ? (maxrin/2) : (0); 22463 float qn = -1.0e23f; 22464 for (int ips = -ipr; ips < ipr+1; ++ips) { 22465 int tot = (ips + incpsi + maxrin)%maxrin; 22466 float tval = temp->get_value_at(tot); 22467 if (tval > qn) { 22468 qn = tval; 22469 bestang = ang_n(tot+1.0f, mode, maxrin); 22470 } 22471 } 22472 //#cout << " best angle ",bestang 22473 bestang = fmod(bestang - (dpsi-90.0f) + 720.0f, 360.0f); 22474 //#cout << " angle applied ",bestang 22475 //#rot_shift2D(data[im],-bestang).write_image("rotated.hdf",im) 22476 //std::auto_ptr<EMData> rot_data_im( data[im]->rot_scale_trans2D_background(-bestang, 0, 0, 1) ); 22477 //fdata[im] = (rot_data_im->is_complex()) ? (rot_data_im->do_ift()) : (rot_data_im->do_fft()); 22478 22479 //#cout << " New composed 3D ",dpsi,bestang, nnsx, nnsy 22480 22481 epsi = fmod(bestang+dpsi, 360.0f); 22482 psx = nnsx; 22483 psy = nnsy; 22484 //#cout << " New composed 3D ",pphi,90.0,epsi, psx, psy 22485 } else { 22486 epsi = dpsi; 22487 bestang = 0; 22488 } 22489 data[im]->set_attr("bestang",fmod(720.0f-bestang, 360.0f)); 22490 //printf(" %7.2f %7.2f %7.2f %7.2f %7.2f\n", pphi, 90.0, epsi, psx, psy); 22491 Dict t_params; 22492 t_params["type"] = "spider"; 22493 t_params["phi"] = pphi; 22494 t_params["theta"] = 90.0f; 22495 t_params["psi"] = epsi; 22496 t_params["tx"] = -psx; 22497 t_params["ty"] = -psy; 22498 Transform t(t_params); 22499 data[im]->set_attr("xform.projection", &t); 22500 } 22501 }
int Util::coveig | ( | int | n, | |
float * | covmat, | |||
float * | eigval, | |||
float * | eigvec | |||
) | [static] |
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 6191 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, and ssyev_().
06192 { 06193 // n size of the covariance/correlation matrix 06194 // covmat --- covariance/correlation matrix (n by n) 06195 // eigval --- returns eigenvalues 06196 // eigvec --- returns eigenvectors 06197 06198 ENTERFUNC; 06199 06200 int i; 06201 06202 // make a copy of covmat so that it will not be overwritten 06203 for ( i = 0 ; i < n * n ; i++ ) eigvec[i] = covmat[i]; 06204 06205 char NEEDV = 'V'; 06206 char UPLO = 'U'; 06207 int lwork = -1; 06208 int info = 0; 06209 float *work, wsize; 06210 06211 // query to get optimal workspace 06212 ssyev_(&NEEDV, &UPLO, &n, eigvec, &n, eigval, &wsize, &lwork, &info); 06213 lwork = (int)wsize; 06214 06215 work = (float *)calloc(lwork, sizeof(float)); 06216 // calculate eigs 06217 ssyev_(&NEEDV, &UPLO, &n, eigvec, &n, eigval, work, &lwork, &info); 06218 free(work); 06219 EXITFUNC; 06220 return info; 06221 }
Dict Util::coveig_for_py | ( | int | ncov, | |
const vector< float > & | covmatpy | |||
) | [static] |
same function than Util::coveig but wrapped to use directly in python code
Definition at line 6223 of file util_sparx.cpp.
References coveig(), covmat, eigval, eigvec, ENTERFUNC, EXITFUNC, and status.
06224 { 06225 06226 ENTERFUNC; 06227 int len = covmatpy.size(); 06228 float *eigvec; 06229 float *eigval; 06230 float *covmat; 06231 int status = 0; 06232 eigval = (float*)calloc(ncov,sizeof(float)); 06233 eigvec = (float*)calloc(ncov*ncov,sizeof(float)); 06234 covmat = (float*)calloc(ncov*ncov, sizeof(float)); 06235 06236 const float *covmat_ptr; 06237 covmat_ptr = &covmatpy[0]; 06238 for(int i=0;i<len;i++){ 06239 covmat[i] = covmat_ptr[i]; 06240 } 06241 06242 status = Util::coveig(ncov, covmat, eigval, eigvec); 06243 06244 vector<float> eigval_py(ncov); 06245 const float *eigval_ptr; 06246 eigval_ptr = &eigval[0]; 06247 for(int i=0;i<ncov;i++){ 06248 eigval_py[i] = eigval_ptr[i]; 06249 } 06250 06251 vector<float> eigvec_py(ncov*ncov); 06252 const float *eigvec_ptr; 06253 eigvec_ptr = &eigvec[0]; 06254 for(int i=0;i<ncov*ncov;i++){ 06255 eigvec_py[i] = eigvec_ptr[i]; 06256 } 06257 06258 Dict res; 06259 res["eigval"] = eigval_py; 06260 res["eigvec"] = eigvec_py; 06261 06262 EXITFUNC; 06263 return res; 06264 }
Definition at line 3189 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.
03189 { 03190 // neg = 0 straight, neg = 1 mirrored 03191 int nring = numr.size()/3; 03192 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03193 int maxrin = numr[numr.size()-1]; 03194 double qn; float tot; 03195 float *circ1 = circ1p->get_data(); 03196 float *circ2 = circ2p->get_data(); 03197 /* 03198 c checks single position, neg is flag for checking mirrored position 03199 c 03200 c input - fourier transforms of rings! 03201 c first set is conjugated (mirrored) if neg 03202 c circ1 already multiplied by weights! 03203 c automatic arrays 03204 dimension t(maxrin) removed +2 as it is only needed for other ffts 03205 double precision q(maxrin) 03206 double precision t7(-3:3) 03207 */ 03208 float *t; 03209 double t7[7], *q; 03210 int i, j, k, ip, jc, numr3i, numr2i, jtot = 0; 03211 float pos; 03212 03213 #ifdef _WIN32 03214 ip = -(int)(log((float)maxrin)/log(2.0f)); 03215 #else 03216 ip = -(int) (log2(maxrin)); 03217 #endif //_WIN32 03218 03219 q = (double*)calloc(maxrin, sizeof(double)); 03220 t = (float*)calloc(maxrin, sizeof(float)); 03221 03222 // cout << *qn <<" " <<*tot<<" "<<ip<<endl; 03223 for (i=1; i<=nring; i++) { 03224 numr3i = numr(3,i); 03225 numr2i = numr(2,i); 03226 03227 t(1) = (circ1(numr2i)) * circ2(numr2i); 03228 03229 if (numr3i != maxrin) { 03230 // test .ne. first for speed on some compilers 03231 t(numr3i+1) = circ1(numr2i+1) * circ2(numr2i+1); 03232 t(2) = 0.0; 03233 03234 if (neg) { 03235 // first set is conjugated (mirrored) 03236 for (j=3;j<=numr3i;j=j+2) { 03237 jc = j+numr2i-1; 03238 t(j) =(circ1(jc))*circ2(jc)-(circ1(jc+1))*circ2(jc+1); 03239 t(j+1) = -(circ1(jc))*circ2(jc+1)-(circ1(jc+1))*circ2(jc); 03240 } 03241 } else { 03242 for (j=3;j<=numr3i;j=j+2) { 03243 jc = j+numr2i-1; 03244 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1); 03245 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc); 03246 } 03247 } 03248 for (j=1;j<=numr3i+1;j++) q(j) = q(j) + t(j); 03249 } else { 03250 t(2) = circ1(numr2i+1) * circ2(numr2i+1); 03251 if (neg) { 03252 // first set is conjugated (mirrored) 03253 for (j=3;j<=maxrin;j=j+2) { 03254 jc = j+numr2i-1; 03255 t(j) = (circ1(jc))*circ2(jc) - (circ1(jc+1))*circ2(jc+1); 03256 t(j+1) = -(circ1(jc))*circ2(jc+1) - (circ1(jc+1))*circ2(jc); 03257 } 03258 } else { 03259 for (j=3;j<=maxrin;j=j+2) { 03260 jc = j+numr2i-1; 03261 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1); 03262 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc); 03263 } 03264 } 03265 for (j = 1; j <= maxrin; j++) q(j) += t(j); 03266 } 03267 } 03268 03269 fftr_d(q,ip); 03270 03271 qn = -1.0e20; 03272 for (j=1;j<=maxrin;j++) { 03273 if (q(j) >= qn) { 03274 qn = q(j); jtot = j; 03275 } 03276 } 03277 03278 for (k=-3; k<=3; k++) { 03279 j = (jtot+k+maxrin-1)%maxrin + 1; 03280 t7(k+4) = q(j); 03281 } 03282 03283 prb1d(t7,7,&pos); 03284 03285 tot = (float)jtot + pos; 03286 03287 if (q) free(q); 03288 if (t) free(t); 03289 03290 Dict retvals; 03291 retvals["qn"] = qn; 03292 retvals["tot"] = tot; 03293 return retvals; 03294 }
Dict Util::Crosrng_ew | ( | EMData * | circ1, | |
EMData * | circ2, | |||
vector< int > | numr, | |||
vector< float > | w, | |||
int | neg | |||
) | [static] |
Definition at line 3296 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.
03296 { 03297 // neg = 0 straight, neg = 1 mirrored 03298 int nring = numr.size()/3; 03299 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03300 int maxrin = numr[numr.size()-1]; 03301 double qn; float tot; 03302 float *circ1 = circ1p->get_data(); 03303 float *circ2 = circ2p->get_data(); 03304 /* 03305 c checks single position, neg is flag for checking mirrored position 03306 c 03307 c input - fourier transforms of rings! 03308 c first set is conjugated (mirrored) if neg 03309 c multiplication by weights! 03310 c automatic arrays 03311 dimension t(maxrin) removed +2 as it is only needed for other ffts 03312 double precision q(maxrin) 03313 double precision t7(-3:3) 03314 */ 03315 float *t; 03316 double t7[7], *q; 03317 int i, j, k, ip, jc, numr3i, numr2i, jtot = 0; 03318 float pos; 03319 03320 #ifdef _WIN32 03321 ip = -(int)(log((float)maxrin)/log(2.0f)); 03322 #else 03323 ip = -(int) (log2(maxrin)); 03324 #endif //_WIN32 03325 03326 q = (double*)calloc(maxrin, sizeof(double)); 03327 t = (float*)calloc(maxrin, sizeof(float)); 03328 03329 // cout << *qn <<" " <<*tot<<" "<<ip<<endl; 03330 for (i=1;i<=nring;i++) { 03331 numr3i = numr(3,i); 03332 numr2i = numr(2,i); 03333 03334 t(1) = circ1(numr2i) * circ2(numr2i); 03335 03336 if (numr3i != maxrin) { 03337 // test .ne. first for speed on some compilers 03338 t(numr3i+1) = circ1(numr2i+1) * circ2(numr2i+1); 03339 t(2) = 0.0; 03340 03341 if (neg) { 03342 // first set is conjugated (mirrored) 03343 for (j=3; j<=numr3i; j=j+2) { 03344 jc = j+numr2i-1; 03345 t(j) = (circ1(jc))*circ2(jc)-(circ1(jc+1))*circ2(jc+1); 03346 t(j+1) = -(circ1(jc))*circ2(jc+1)-(circ1(jc+1))*circ2(jc); 03347 } 03348 } else { 03349 for (j=3; j<=numr3i; j=j+2) { 03350 jc = j+numr2i-1; 03351 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1); 03352 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc); 03353 } 03354 } 03355 for (j=1;j<=numr3i+1;j++) q(j) += t(j)*w[i-1]; 03356 } else { 03357 t(2) = circ1(numr2i+1) * circ2(numr2i+1); 03358 if (neg) { 03359 // first set is conjugated (mirrored) 03360 for (j=3; j<=maxrin; j=j+2) { 03361 jc = j+numr2i-1; 03362 t(j) = (circ1(jc))*circ2(jc) - (circ1(jc+1))*circ2(jc+1); 03363 t(j+1) = -(circ1(jc))*circ2(jc+1) - (circ1(jc+1))*circ2(jc); 03364 } 03365 } else { 03366 for (j=3; j<=maxrin; j=j+2) { 03367 jc = j+numr2i-1; 03368 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1); 03369 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc); 03370 } 03371 } 03372 for (j = 1; j <= maxrin; j++) q(j) += t(j)*w[i-1]; 03373 } 03374 } 03375 03376 fftr_d(q,ip); 03377 03378 qn = -1.0e20; 03379 for (j=1;j<=maxrin;j++) { 03380 //cout << j << " " << q(j) << endl; 03381 if (q(j) >= qn) { 03382 qn = q(j); 03383 jtot = j; 03384 } 03385 } 03386 03387 for (k=-3; k<=3; k++) { 03388 j = (jtot+k+maxrin-1)%maxrin + 1; 03389 t7(k+4) = q(j); 03390 } 03391 03392 prb1d(t7,7,&pos); 03393 03394 tot = (float)jtot + pos; 03395 03396 //if (q) free(q); 03397 if (t) free(t); 03398 03399 Dict retvals; 03400 //tot = 1; 03401 //qn = q(1); 03402 retvals["qn"] = qn; 03403 retvals["tot"] = tot; 03404 03405 if (q) free(q); 03406 03407 return retvals; 03408 }
Definition at line 3410 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 hans(), multiref_polar_ali_2d(), multiref_polar_ali_2d_local(), and multiref_polar_ali_2d_peaklist().
03410 { 03411 int nring = numr.size()/3; 03412 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03413 int maxrin = numr[numr.size()-1]; 03414 double qn; float tot; double qm; float tmt; 03415 float *circ1 = circ1p->get_data(); 03416 float *circ2 = circ2p->get_data(); 03417 /* 03418 c 03419 c checks both straight & mirrored positions 03420 c 03421 c input - fourier transforms of rings!! 03422 c circ1 already multiplied by weights! 03423 c 03424 */ 03425 03426 // dimension circ1(lcirc),circ2(lcirc) 03427 03428 // t(maxrin), q(maxrin), t7(-3:3) //maxrin+2 removed 03429 double *t, *q, t7[7]; 03430 03431 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 03432 float t1, t2, t3, t4, c1, c2, d1, d2, pos; 03433 03434 qn = 0.0f; 03435 qm = 0.0f; 03436 tot = 0.0f; 03437 tmt = 0.0f; 03438 #ifdef _WIN32 03439 ip = -(int)(log((float)maxrin)/log(2.0f)); 03440 #else 03441 ip = -(int)(log2(maxrin)); 03442 #endif //_WIN32 03443 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl; 03444 03445 // c - straight = circ1 * conjg(circ2) 03446 // zero q array 03447 03448 q = (double*)calloc(maxrin,sizeof(double)); 03449 03450 // t - mirrored = conjg(circ1) * conjg(circ2) 03451 // zero t array 03452 t = (double*)calloc(maxrin,sizeof(double)); 03453 03454 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03455 for (i=1; i<=nring; i++) { 03456 03457 numr3i = numr(3,i); // Number of samples of this ring 03458 numr2i = numr(2,i); // The beginning point of this ring 03459 03460 t1 = circ1(numr2i) * circ2(numr2i); 03461 q(1) += t1; 03462 t(1) += t1; 03463 03464 t1 = circ1(numr2i+1) * circ2(numr2i+1); 03465 if (numr3i == maxrin) { 03466 q(2) += t1; 03467 t(2) += t1; 03468 } else { 03469 q(numr3i+1) += t1; 03470 t(numr3i+1) += t1; 03471 } 03472 03473 for (j=3; j<=numr3i; j += 2) { 03474 jc = j+numr2i-1; 03475 03476 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03477 // ----- ----- ----- ----- 03478 // t1 t2 t3 t4 03479 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i 03480 // ----- ----- ----- ----- 03481 // t1 t2 t3 t4 03482 03483 c1 = circ1(jc); 03484 c2 = circ1(jc+1); 03485 d1 = circ2(jc); 03486 d2 = circ2(jc+1); 03487 03488 t1 = c1 * d1; 03489 t2 = c2 * d2; 03490 t3 = c1 * d2; 03491 t4 = c2 * d1; 03492 03493 q(j) += t1 + t2; 03494 q(j+1) += -t3 + t4; 03495 t(j) += t1 - t2; 03496 t(j+1) += -t3 - t4; 03497 } 03498 } 03499 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<" "<<t(j) <<endl; 03500 fftr_d(q,ip); 03501 03502 qn = -1.0e20; 03503 for (j=1; j<=maxrin; j++) {//cout <<" "<<j<<" "<<q(j) <<endl; 03504 if (q(j) >= qn) { 03505 qn = q(j); 03506 jtot = j; 03507 } 03508 } 03509 03510 for (k=-3; k<=3; k++) { 03511 j = ((jtot+k+maxrin-1)%maxrin)+1; 03512 t7(k+4) = q(j); 03513 } 03514 03515 // interpolate 03516 prb1d(t7,7,&pos); 03517 tot = (float)(jtot)+pos; 03518 // Do not interpolate 03519 //tot = (float)(jtot); 03520 03521 // mirrored 03522 fftr_d(t,ip); 03523 03524 // find angle 03525 qm = -1.0e20; 03526 for (j=1; j<=maxrin;j++) {//cout <<" "<<j<<" "<<t(j) <<endl; 03527 if ( t(j) >= qm ) { 03528 qm = t(j); 03529 jtot = j; 03530 } 03531 } 03532 03533 for (k=-3; k<=3; k++) { 03534 j = ((jtot+k+maxrin-1)%maxrin) + 1; 03535 t7(k+4) = t(j); 03536 } 03537 03538 // interpolate 03539 03540 prb1d(t7,7,&pos); 03541 tmt = float(jtot) + pos; 03542 // Do not interpolate 03543 //tmt = float(jtot); 03544 03545 free(t); 03546 free(q); 03547 03548 Dict retvals; 03549 retvals["qn"] = qn; 03550 retvals["tot"] = tot; 03551 retvals["qm"] = qm; 03552 retvals["tmt"] = tmt; 03553 return retvals; 03554 }
Dict Util::Crosrng_ms_delta | ( | EMData * | circ1, | |
EMData * | circ2, | |||
vector< int > | numr, | |||
float | delta_start, | |||
float | delta | |||
) | [static] |
Definition at line 3556 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().
03556 { 03557 int nring = numr.size()/3; 03558 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03559 int maxrin = numr[numr.size()-1]; 03560 double qn; float tot; double qm; float tmt; 03561 float *circ1 = circ1p->get_data(); 03562 float *circ2 = circ2p->get_data(); 03563 /* 03564 c 03565 c checks both straight & mirrored positions 03566 c 03567 c input - fourier transforms of rings!! 03568 c circ1 already multiplied by weights! 03569 c 03570 */ 03571 03572 // dimension circ1(lcirc),circ2(lcirc) 03573 03574 // t(maxrin), q(maxrin), t7(-3:3) //maxrin+2 removed 03575 double *t, *q; 03576 03577 int ip, jc, numr3i, numr2i, i, j, jtot = 0; 03578 float t1, t2, t3, t4, c1, c2, d1, d2; 03579 03580 qn = 0.0f; 03581 qm = 0.0f; 03582 tot = 0.0f; 03583 tmt = 0.0f; 03584 #ifdef _WIN32 03585 ip = -(int)(log((float)maxrin)/log(2.0f)); 03586 #else 03587 ip = -(int)(log2(maxrin)); 03588 #endif //_WIN32 03589 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl; 03590 03591 // c - straight = circ1 * conjg(circ2) 03592 // zero q array 03593 03594 q = (double*)calloc(maxrin,sizeof(double)); 03595 03596 // t - mirrored = conjg(circ1) * conjg(circ2) 03597 // zero t array 03598 t = (double*)calloc(maxrin,sizeof(double)); 03599 03600 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03601 for (i=1; i<=nring; i++) { 03602 03603 numr3i = numr(3,i); // Number of samples of this ring 03604 numr2i = numr(2,i); // The beginning point of this ring 03605 03606 t1 = circ1(numr2i) * circ2(numr2i); 03607 q(1) += t1; 03608 t(1) += t1; 03609 03610 t1 = circ1(numr2i+1) * circ2(numr2i+1); 03611 if (numr3i == maxrin) { 03612 q(2) += t1; 03613 t(2) += t1; 03614 } else { 03615 q(numr3i+1) += t1; 03616 t(numr3i+1) += t1; 03617 } 03618 03619 for (j=3; j<=numr3i; j += 2) { 03620 jc = j+numr2i-1; 03621 03622 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03623 // ----- ----- ----- ----- 03624 // t1 t2 t3 t4 03625 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i 03626 // ----- ----- ----- ----- 03627 // t1 t2 t3 t4 03628 03629 c1 = circ1(jc); 03630 c2 = circ1(jc+1); 03631 d1 = circ2(jc); 03632 d2 = circ2(jc+1); 03633 03634 t1 = c1 * d1; 03635 t2 = c2 * d2; 03636 t3 = c1 * d2; 03637 t4 = c2 * d1; 03638 03639 q(j) += t1 + t2; 03640 q(j+1) += -t3 + t4; 03641 t(j) += t1 - t2; 03642 t(j+1) += -t3 - t4; 03643 } 03644 } 03645 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<" "<<t(j) <<endl; 03646 fftr_d(q,ip); 03647 03648 qn = -1.0e20; 03649 03650 int jstart = 1+static_cast<int>(delta_start/360.0*maxrin); 03651 int jstep = static_cast<int>(delta/360.0*maxrin); 03652 if (jstep < 1) { jstep = 1; } 03653 03654 for (j=jstart; j<=maxrin; j+=jstep) {//cout <<" "<<j<<" "<<q(j) <<endl; 03655 if (q(j) >= qn) { 03656 qn = q(j); 03657 jtot = j; 03658 } 03659 } 03660 03661 //for (k=-3; k<=3; k++) { 03662 // j = ((jtot+k+maxrin-1)%maxrin)+1; 03663 // t7(k+4) = q(j); 03664 //} 03665 03666 // interpolate 03667 //prb1d(t7,7,&pos); 03668 //tot = (float)(jtot)+pos; 03669 // Do not interpolate 03670 tot = (float)(jtot); 03671 03672 // mirrored 03673 fftr_d(t,ip); 03674 03675 // find angle 03676 qm = -1.0e20; 03677 for (j=jstart; j<=maxrin;j+=jstep) {//cout <<" "<<j<<" "<<t(j) <<endl; 03678 if ( t(j) >= qm ) { 03679 qm = t(j); 03680 jtot = j; 03681 } 03682 } 03683 03684 //for (k=-3; k<=3; k++) { 03685 // j = ((jtot+k+maxrin-1)%maxrin) + 1; 03686 // t7(k+4) = t(j); 03687 //} 03688 03689 // interpolate 03690 03691 //prb1d(t7,7,&pos); 03692 //tmt = float(jtot) + pos; 03693 // Do not interpolate 03694 tmt = float(jtot); 03695 03696 free(t); 03697 free(q); 03698 03699 Dict retvals; 03700 retvals["qn"] = qn; 03701 retvals["tot"] = tot; 03702 retvals["qm"] = qm; 03703 retvals["tmt"] = tmt; 03704 return retvals; 03705 }
checks both straight & mirrored positions input - fourier transforms of rings!! circ1 already multiplied by weights! returns EM object with 1D ccf
Definition at line 4007 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.
04007 { 04008 04009 // dimension circ1(lcirc),circ2(lcirc) 04010 04011 int ip, jc, numr3i, numr2i, i, j; 04012 float t1, t2, t3, t4, c1, c2, d1, d2; 04013 04014 int nring = numr.size()/3; 04015 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 04016 int maxrin = numr[numr.size()-1]; 04017 04018 float* circ1b = circ1->get_data(); 04019 float* circ2b = circ2->get_data(); 04020 04021 // t(maxrin), q(maxrin) // removed +2 04022 double *t, *q; 04023 04024 q = (double*)calloc(maxrin,sizeof(double)); 04025 t = (double*)calloc(maxrin,sizeof(double)); 04026 04027 #ifdef _WIN32 04028 ip = -(int)(log((float)maxrin)/log(2.0f)); 04029 #else 04030 ip = -(int)(log2(maxrin)); 04031 #endif //_WIN32 04032 04033 // q - straight = circ1 * conjg(circ2) 04034 04035 // t - mirrored = conjg(circ1) * conjg(circ2) 04036 04037 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 04038 04039 for (i=1; i<=nring; i++) { 04040 04041 numr3i = numr(3,i); 04042 numr2i = numr(2,i); 04043 04044 t1 = circ1b(numr2i) * circ2b(numr2i); 04045 q(1) += t1; 04046 t(1) += t1; 04047 04048 t1 = circ1b(numr2i+1) * circ2b(numr2i+1); 04049 if (numr3i == maxrin) { 04050 q(2) += t1; 04051 t(2) += t1; 04052 } else { 04053 q(numr3i+1) += t1; 04054 t(numr3i+1) += t1; 04055 } 04056 04057 for (j=3; j<=numr3i; j=j+2) { 04058 jc = j+numr2i-1; 04059 04060 c1 = circ1b(jc); 04061 c2 = circ1b(jc+1); 04062 d1 = circ2b(jc); 04063 d2 = circ2b(jc+1); 04064 04065 t1 = c1 * d1; 04066 t3 = c1 * d2; 04067 t2 = c2 * d2; 04068 t4 = c2 * d1; 04069 04070 q(j) += t1 + t2; 04071 q(j+1) += -t3 + t4; 04072 t(j) += t1 - t2; 04073 t(j+1) += -t3 - t4; 04074 } 04075 } 04076 04077 // straight 04078 fftr_d(q,ip); 04079 04080 // mirrored 04081 fftr_d(t,ip); 04082 04083 EMData* out = new EMData(); 04084 out->set_size(maxrin,2,1); 04085 float *dout = out->get_data(); 04086 for (int i=0; i<maxrin; i++) {dout(i,0)=static_cast<float>(q[i]); dout(i,1)=static_cast<float>(t[i]);} 04087 //out->set_size(maxrin,1,1); 04088 //float *dout = out->get_data(); 04089 //for (int i=0; i<maxrin; i++) {dout(i,0)=q[i];} 04090 free(t); 04091 free(q); 04092 return out; 04093 }
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 4243 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.
04244 { 04245 04246 int ip, jc, numr3i, numr2i, i, j; 04247 float c1, c2, d1, d2; 04248 04249 int nring = numr.size()/3; 04250 int maxrin = numr[numr.size()-1]; 04251 04252 float* circ1b = circ1->get_data(); 04253 float* circ2b = circ2->get_data(); 04254 04255 double *t; 04256 04257 t = (double*)calloc(maxrin,sizeof(double)); 04258 04259 #ifdef _WIN32 04260 ip = -(int)(log((float)maxrin)/log(2.0f)); 04261 #else 04262 ip = -(int)(log2(maxrin)); 04263 #endif //_WIN32 04264 04265 // t - mirrored = conjg(circ1) * conjg(circ2) 04266 04267 for (i=1;i<=nring;i++) { 04268 04269 numr3i = numr(3,i); 04270 numr2i = numr(2,i); 04271 t(1) += circ1b(numr2i) * circ2b(numr2i); 04272 04273 if (numr3i == maxrin) t(2) += circ1b(numr2i+1) * circ2b(numr2i+1); 04274 else t(numr3i+1) += circ1b(numr2i+1) * circ2b(numr2i+1); 04275 04276 for (j=3;j<=numr3i;j=j+2) { 04277 jc = j+numr2i-1; 04278 04279 c1 = circ1b(jc); 04280 c2 = circ1b(jc+1); 04281 d1 = circ2b(jc); 04282 d2 = circ2b(jc+1); 04283 04284 t(j) += c1 * d1 - c2 * d2; 04285 t(j+1) += -c1 * d2 - c2 * d1; 04286 } 04287 } 04288 04289 // mirrored 04290 fftr_d(t,ip); 04291 04292 EMData* out = new EMData(); 04293 out->set_size(maxrin,1,1); 04294 float *dout = out->get_data(); 04295 for (int i=0; i<maxrin; i++) dout[i]=static_cast<float>(t[i]); 04296 free(t); 04297 return out; 04298 04299 }
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 4183 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().
Referenced by constrained_helix(), and constrained_helix_test().
04184 { 04185 04186 int ip, jc, numr3i, numr2i, i, j; 04187 float c1, c2, d1, d2; 04188 04189 int nring = numr.size()/3; 04190 int maxrin = numr[numr.size()-1]; 04191 04192 float* circ1b = circ1->get_data(); 04193 float* circ2b = circ2->get_data(); 04194 04195 double *q; 04196 04197 q = (double*)calloc(maxrin,sizeof(double)); 04198 04199 #ifdef _WIN32 04200 ip = -(int)(log((float)maxrin)/log(2.0f)); 04201 #else 04202 ip = -(int)(log2(maxrin)); 04203 #endif //_WIN32 04204 04205 // q - straight = circ1 * conjg(circ2) 04206 04207 for (i=1;i<=nring;i++) { 04208 04209 numr3i = numr(3,i); 04210 numr2i = numr(2,i); 04211 04212 q(1) += circ1b(numr2i) * circ2b(numr2i); 04213 04214 if (numr3i == maxrin) q(2) += circ1b(numr2i+1) * circ2b(numr2i+1); 04215 else q(numr3i+1) += circ1b(numr2i+1) * circ2b(numr2i+1); 04216 04217 for (j=3;j<=numr3i;j=j+2) { 04218 jc = j+numr2i-1; 04219 04220 c1 = circ1b(jc); 04221 c2 = circ1b(jc+1); 04222 d1 = circ2b(jc); 04223 d2 = circ2b(jc+1); 04224 04225 q(j) += c1 * d1 + c2 * d2; 04226 q(j+1) += -c1 * d2 + c2 * d1; 04227 } 04228 } 04229 04230 // straight 04231 fftr_d(q,ip); 04232 04233 EMData* out = new EMData(); 04234 out->set_size(maxrin,1,1); 04235 float *dout = out->get_data(); 04236 for (int i=0; i<maxrin; i++) dout[i]=static_cast<float>(q[i]); 04237 free(q); 04238 return out; 04239 04240 }
void Util::Crosrng_msg_vec | ( | EMData * | circ1, | |
EMData * | circ2, | |||
vector< int > | numr, | |||
float * | q, | |||
float * | t | |||
) | [static] |
checks both straight & mirrored positions input - fourier transforms of rings!! circ1 already multiplied by weights! returns EM object with 1D ccf
Definition at line 4111 of file util_sparx.cpp.
References circ1, circ1b, circ2, circ2b, fftr_q(), log(), numr, q, and t.
Referenced by ali2d_ccf_list(), Crosrng_msg_vec_p(), multiref_peaks_ali2d(), and multiref_peaks_compress_ali2d().
04111 { 04112 04113 // dimension circ1(lcirc),circ2(lcirc) 04114 04115 int ip, jc, numr3i, numr2i, i, j; 04116 float t1, t2, t3, t4, c1, c2, d1, d2; 04117 04118 int nring = numr.size()/3; 04119 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 04120 int maxrin = numr[numr.size()-1]; 04121 04122 float* circ1b = circ1->get_data(); 04123 float* circ2b = circ2->get_data(); 04124 04125 #ifdef _WIN32 04126 ip = -(int)(log((float)maxrin)/log(2.0f)); 04127 #else 04128 ip = -(int)(log2(maxrin)); 04129 #endif //_WIN32 04130 for (int i=1; i<=maxrin; i++) {q(i) = 0.0f; t(i) = 0.0f;} 04131 04132 // q - straight = circ1 * conjg(circ2) 04133 04134 // t - mirrored = conjg(circ1) * conjg(circ2) 04135 04136 for (i=1; i<=nring; i++) { 04137 04138 numr3i = numr(3,i); 04139 numr2i = numr(2,i); 04140 04141 t1 = circ1b(numr2i) * circ2b(numr2i); 04142 q(1) += t1; 04143 t(1) += t1; 04144 04145 t1 = circ1b(numr2i+1) * circ2b(numr2i+1); 04146 if (numr3i == maxrin) { 04147 q(2) += t1; 04148 t(2) += t1; 04149 } else { 04150 q(numr3i+1) += t1; 04151 t(numr3i+1) += t1; 04152 } 04153 04154 for (j=3; j<=numr3i; j=j+2) { 04155 jc = j+numr2i-1; 04156 04157 c1 = circ1b(jc); 04158 c2 = circ1b(jc+1); 04159 d1 = circ2b(jc); 04160 d2 = circ2b(jc+1); 04161 04162 t1 = c1 * d1; 04163 t3 = c1 * d2; 04164 t2 = c2 * d2; 04165 t4 = c2 * d1; 04166 04167 q(j) += t1 + t2; 04168 q(j+1) += -t3 + t4; 04169 t(j) += t1 - t2; 04170 t(j+1) += -t3 - t4; 04171 } 04172 } 04173 // straight 04174 fftr_q(q,ip); 04175 //for (int i=0; i<maxrin; i++) cout<<i<<" B "<<q[i]<<" "<<t[i]<<endl; 04176 04177 // mirrored 04178 fftr_q(t,ip); 04179 }
vector< float > Util::Crosrng_msg_vec_p | ( | EMData * | circ1, | |
EMData * | circ2, | |||
vector< int > | numr | |||
) | [static] |
Definition at line 4096 of file util_sparx.cpp.
References circ1, circ2, and Crosrng_msg_vec().
04096 { 04097 04098 int maxrin = numr[numr.size()-1]; 04099 04100 vector<float> r(2*maxrin); 04101 04102 Crosrng_msg_vec( circ1, circ2, numr, &r[0], &r[maxrin] ); 04103 04104 return r; 04105 }
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 3908 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().
03908 { 03909 int nring = numr.size()/3; 03910 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03911 int maxrin = numr[numr.size()-1]; 03912 double qn; float tot; 03913 float *circ1 = circ1p->get_data(); 03914 float *circ2 = circ2p->get_data(); 03915 /* 03916 c 03917 c checks only straight position 03918 c 03919 c input - fourier transforms of rings!! 03920 c circ1 already multiplied by weights! 03921 c 03922 */ 03923 03924 // dimension circ1(lcirc),circ2(lcirc) 03925 03926 // q(maxrin), t7(-3:3) //maxrin+2 removed 03927 double *q, t7[7]; 03928 03929 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 03930 float c1, c2, d1, d2, pos; 03931 03932 qn = 0.0; 03933 tot = 0.0; 03934 #ifdef _WIN32 03935 ip = -(int)(log((float)maxrin)/log(2.0f)); 03936 #else 03937 ip = -(int)(log2(maxrin)); 03938 #endif //_WIN32 03939 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl; 03940 03941 // c - straight = circ1 * conjg(circ2) 03942 // zero q array 03943 03944 q = (double*)calloc(maxrin,sizeof(double)); 03945 03946 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03947 for (i=1; i<=nring; i++) { 03948 03949 numr3i = numr(3,i); // Number of samples of this ring 03950 numr2i = numr(2,i); // The beginning point of this ring 03951 03952 q(1) += circ1(numr2i) * circ2(numr2i); 03953 03954 if (numr3i == maxrin) q(2) += circ1(numr2i+1) * circ2(numr2i+1); 03955 else q(numr3i+1) += circ1(numr2i+1) * circ2(numr2i+1); 03956 03957 for (j=3; j<=numr3i; j += 2) { 03958 jc = j+numr2i-1; 03959 03960 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03961 // ----- ----- ----- ----- 03962 // t1 t2 t3 t4 03963 03964 c1 = circ1(jc); 03965 c2 = circ1(jc+1); 03966 d1 = circ2(jc); 03967 d2 = circ2(jc+1); 03968 03969 q(j) += c1 * d1 + c2 * d2; 03970 q(j+1) += -c1 * d2 + c2 * d1; 03971 } 03972 } 03973 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<endl; 03974 fftr_d(q,ip); 03975 03976 qn = -1.0e20; 03977 for (j=1; j<=maxrin; j++) {//cout <<" "<<j<<" "<<q(j) <<endl; 03978 if (q(j) >= qn) { 03979 qn = q(j); 03980 jtot = j; 03981 } 03982 } 03983 03984 for (k=-3; k<=3; k++) { 03985 j = ((jtot+k+maxrin-1)%maxrin)+1; 03986 t7(k+4) = q(j); 03987 } 03988 03989 // interpolate 03990 prb1d(t7,7,&pos); 03991 tot = (float)(jtot)+pos; 03992 // Do not interpolate 03993 //*tot = (float)(jtot); 03994 03995 free(q); 03996 03997 Dict retvals; 03998 retvals["qn"] = qn; 03999 retvals["tot"] = tot; 04000 return retvals; 04001 }
Dict Util::Crosrng_psi | ( | EMData * | circ1, | |
EMData * | circ2, | |||
vector< int > | numr, | |||
float | psi, | |||
float | psimax | |||
) | [static] |
checks both straight & mirrored position input - fourier transforms of rings!! circ1 already multiplied by weights!
Definition at line 3789 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_helical().
03789 { 03790 // Computes both straight and mirrored 03791 03792 int nring = numr.size()/3; 03793 int maxrin = numr[numr.size()-1]; 03794 double qn; float tot; double qm; float tmt; 03795 float *circ1 = circ1p->get_data(); 03796 float *circ2 = circ2p->get_data(); 03797 03798 double *t, *q; 03799 03800 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 03801 float t1, t2, t3, t4, c1, c2, d1, d2; 03802 03803 qn = 0.0f; 03804 qm = 0.0f; 03805 tot = 0.0f; 03806 tmt = 0.0f; 03807 #ifdef _WIN32 03808 ip = -(int)(log((float)maxrin)/log(2.0f)); 03809 #else 03810 ip = -(int)(log2(maxrin)); 03811 #endif //_WIN32 03812 03813 // c - straight = circ1 * conjg(circ2) 03814 // zero q array 03815 03816 q = (double*)calloc(maxrin,sizeof(double)); 03817 03818 // t - mirrored = conjg(circ1) * conjg(circ2) 03819 // zero t array 03820 t = (double*)calloc(maxrin,sizeof(double)); 03821 03822 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03823 03824 for (i=1; i<=nring; i++) { 03825 03826 numr3i = numr(3,i); // Number of samples of this ring 03827 numr2i = numr(2,i); // The beginning point of this ring 03828 03829 t1 = circ1(numr2i) * circ2(numr2i); 03830 q(1) += t1; 03831 t(1) += t1; 03832 03833 t1 = circ1(numr2i+1) * circ2(numr2i+1); 03834 if (numr3i == maxrin) { 03835 q(2) += t1; 03836 t(2) += t1; 03837 } else { 03838 q(numr3i+1) += t1; 03839 t(numr3i+1) += t1; 03840 } 03841 03842 for (j=3; j<=numr3i; j += 2) { 03843 jc = j+numr2i-1; 03844 03845 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03846 // ----- ----- ----- ----- 03847 // t1 t2 t3 t4 03848 03849 c1 = circ1(jc); 03850 c2 = circ1(jc+1); 03851 d1 = circ2(jc); 03852 d2 = circ2(jc+1); 03853 03854 t1 = c1 * d1; 03855 t3 = c1 * d2; 03856 t2 = c2 * d2; 03857 t4 = c2 * d1; 03858 03859 q(j) += t1 + t2; 03860 q(j+1) += -t3 + t4; 03861 t(j) += t1 - t2; 03862 t(j+1) += -t3 - t4; 03863 } 03864 } 03865 03866 fftr_d(q,ip); 03867 03868 qn = -1.0e20; 03869 // psi = 0 should correspond to psi_pos = 1 03870 int psi_pos = int(psi/360.0*maxrin+0.5) + 1; 03871 const int psi_range = int(psi_max/360.0*maxrin + 0.5); 03872 03873 for (k=-psi_range; k<=psi_range; k++) { 03874 j = (k+psi_pos+maxrin-1)%maxrin+1; 03875 if (q(j) >= qn) { 03876 qn = q(j); 03877 jtot = j; 03878 } 03879 } 03880 03881 tot = (float)(jtot); 03882 free(q); 03883 03884 // mirrored 03885 fftr_d(t,ip); 03886 03887 qm = -1.0e20; 03888 03889 for (k=-psi_range; k<=psi_range; k++) { 03890 j = (k+psi_pos+maxrin-1)%maxrin+1; 03891 if (t(j) >= qm) { 03892 qm = t(j); 03893 jtot = j; 03894 } 03895 } 03896 03897 tmt = (float)(jtot); 03898 free(t); 03899 03900 Dict retvals; 03901 retvals["qn"] = qn; 03902 retvals["tot"] = tot; 03903 retvals["qm"] = qm; 03904 retvals["tmt"] = tmt; 03905 return retvals; 03906 }
Dict Util::Crosrng_sm_psi | ( | EMData * | circ1, | |
EMData * | circ2, | |||
vector< int > | numr, | |||
float | psi, | |||
int | flag, | |||
float | psimax | |||
) | [static] |
checks either straight or mirrored position depending on flag input - fourier transforms of rings!! circ1 already multiplied by weights!
Definition at line 3708 of file util_sparx.cpp.
References circ1, circ2, fftr_d(), EMAN::EMData::get_data(), log(), numr, q, EMAN::Dict::size(), and tot.
Referenced by multiref_polar_ali_2d_local_psi(), multiref_polar_ali_helical_90(), multiref_polar_ali_helical_90_local(), and multiref_polar_ali_helical_local().
03708 { 03709 // flag 0 - straight, 1 - mirror 03710 03711 int nring = numr.size()/3; 03712 int maxrin = numr[numr.size()-1]; 03713 double qn; float tot; 03714 float *circ1 = circ1p->get_data(); 03715 float *circ2 = circ2p->get_data(); 03716 03717 double *q; 03718 03719 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 03720 float c1, c2, d1, d2; 03721 03722 qn = 0.0f; 03723 tot = 0.0f; 03724 #ifdef _WIN32 03725 ip = -(int)(log((float)maxrin)/log(2.0f)); 03726 #else 03727 ip = -(int)(log2(maxrin)); 03728 #endif //_WIN32 03729 03730 // c - straight = circ1 * conjg(circ2) 03731 // zero q array 03732 03733 q = (double*)calloc(maxrin,sizeof(double)); 03734 int neg = 1-2*flag; 03735 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03736 03737 for (i=1; i<=nring; i++) { 03738 03739 numr3i = numr(3,i); // Number of samples of this ring 03740 numr2i = numr(2,i); // The beginning point of this ring 03741 03742 q(1) += circ1(numr2i) * circ2(numr2i); 03743 03744 float t1 = circ1(numr2i+1) * circ2(numr2i+1); 03745 if (numr3i == maxrin) q(2) += t1; 03746 else q(numr3i+1) += t1; 03747 03748 for (j=3; j<=numr3i; j += 2) { 03749 jc = j+numr2i-1; 03750 03751 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03752 // ----- ----- ----- ----- 03753 // t1 t2 t3 t4 03754 03755 c1 = circ1(jc); 03756 c2 = circ1(jc+1); 03757 d1 = circ2(jc); 03758 d2 = circ2(jc+1); 03759 03760 q(j) += c1 * d1 + c2 * d2*neg; 03761 q(j+1) += -c1 * d2 + c2 * d1*neg; 03762 } 03763 } 03764 03765 fftr_d(q,ip); 03766 03767 qn = -1.0e20; 03768 // psi = 0 should correspond to psi_pos = 1 (meaning no change in in-plane rotation) 03769 int psi_pos = int(psi/360.0*maxrin+0.5) + 1; 03770 const int psi_range = int(psi_max/360.0*maxrin + 0.5); 03771 03772 for (k=-psi_range; k<=psi_range; k++) { 03773 j = ( k + psi_pos + maxrin - 1)%maxrin+1; 03774 if (q(j) >= qn) { 03775 qn = q(j); 03776 jtot = j; 03777 } 03778 } 03779 03780 tot = (float)(jtot); 03781 free(q); 03782 03783 Dict retvals; 03784 retvals["qn"] = qn; 03785 retvals["tot"] = tot; 03786 return retvals; 03787 }
EMData * Util::ctf2_rimg | ( | 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 | |||
) | [static] |
Definition at line 20320 of file util_sparx.cpp.
References EMAN::EMData::set_size(), tf(), and EMAN::EMData::update().
20321 { 20322 int ix, iy, iz; 20323 int i, j, k; 20324 float ak; 20325 float scx, scy, scz; 20326 EMData* ctf_img1 = new EMData(); 20327 ctf_img1->set_size(nx, ny, nz); 20328 float freq = 1.0f/(2.0f*ps); 20329 scx = 2.0f/float(nx); 20330 if(ny>=1) scy = 2.0f/float(ny); else scy=0.0f; 20331 if(nz>=1) scz = 2.0f/float(nz); else scz=0.0f; 20332 int ns2 = nx/2 ; 20333 int nr2 = ny/2 ; 20334 int nl2 = nz/2 ; 20335 int nod = nx%2 ; 20336 int nok = ny%2 ; 20337 int noz = nz%2 ; 20338 for ( k=0; k<nz;k++) { 20339 iz = k - nl2; 20340 int kz = (nz - k - noz)%nz; 20341 float oz2 = iz*scz*iz*scz; 20342 for ( j=0; j<ny;j++) { 20343 iy = j - nr2; 20344 int jy = (ny - j - nok)%ny; 20345 float oy = iy*scy; 20346 float oy2 = oy*oy; 20347 for ( i=0; i<=ns2; i++) { 20348 ix = i - ns2; 20349 if( dza == 0.0f) { 20350 ak=pow(ix*ix*scx*scx + oy2 + oz2, 0.5f)*freq; 20351 (*ctf_img1) (i,j,k) = pow(Util::tf(dz, ak, voltage, cs, wgh, b_factor, sign),2); 20352 } else { 20353 float ox = ix*scx; 20354 ak=pow(ox*ox + oy2 + oz2, 0.5f)*freq; 20355 //az = atan2(oy, ox); 20356 //float dzz = dz + dza/2.0f*sin(2*(az-azz*M_PI/180.0f-pihalf)); 20357 float dzz = dz - dza/2.0f*sin(2*(atan2(oy, ox)+azz*M_PI/180.0f)); 20358 (*ctf_img1) (i,j,k) = pow(Util::tf(dzz, ak, voltage, cs, wgh, b_factor, sign),2); 20359 } 20360 ix = nx - i - nod; 20361 if(ix<nx) (*ctf_img1) (ix,jy,kz) = (*ctf_img1) (i,j,k); 20362 } 20363 } 20364 } 20365 ctf_img1->update(); 20366 return ctf_img1; 20367 }
EMData * Util::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 | |||
) | [static] |
Definition at line 20220 of file util_sparx.cpp.
References EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), EMAN::EMData::set_ri(), EMAN::EMData::set_size(), tf(), and EMAN::EMData::update().
20221 { 20222 int ix, iy, iz; 20223 int i, j, k; 20224 int nr2, nl2; 20225 float ak; 20226 float scx, scy, scz; 20227 int offset = 2 - nx%2; 20228 int lsm = nx + offset; 20229 EMData* ctf_img1 = new EMData(); 20230 ctf_img1->set_size(lsm, ny, nz); 20231 float freq = 1.0f/(2.0f*ps); 20232 scx = 2.0f/float(nx); 20233 if(ny>=1) scy = 2.0f/float(ny); else scy=0.0f; 20234 if(nz>=1) scz = 2.0f/float(nz); else scz=0.0f; 20235 nr2 = ny/2 ; 20236 nl2 = nz/2 ; 20237 for ( k=0; k<nz;k++) { 20238 iz = k; if(k>nl2) iz=k-nz; 20239 float oz2 = iz*scz*iz*scz; 20240 for ( j=0; j<ny;j++) { 20241 iy = j; if(j>nr2) iy=j - ny; 20242 float oy = iy*scy; 20243 float oy2 = oy*oy; 20244 for ( i=0; i<lsm/2; i++) { 20245 ix=i; 20246 if( dza == 0.0f) { 20247 ak=pow(ix*ix*scx*scx + oy2 + oz2, 0.5f)*freq; 20248 (*ctf_img1) (i*2,j,k) = Util::tf(dz, ak, voltage, cs, wgh, b_factor, sign); 20249 } else { 20250 float ox = ix*scx; 20251 ak=pow(ox*ox + oy2 + oz2, 0.5f)*freq; 20252 float dzz = dz - dza/2.0f*sin(2*(atan2(oy, ox)+azz*M_PI/180.0f)); 20253 (*ctf_img1) (i*2,j,k) = Util::tf(dzz, ak, voltage, cs, wgh, b_factor, sign); 20254 } 20255 //(*ctf_img1) (i*2+1,j,k) = 0.0f; PAP I assumed new EMData sets to zero 20256 } 20257 } 20258 } 20259 ctf_img1->update(); 20260 ctf_img1->set_complex(true); 20261 ctf_img1->set_ri(true); 20262 //ctf_img1->attr_dict["is_complex"] = 1; 20263 //ctf_img1->attr_dict["is_ri"] = 1; 20264 if(nx%2==0) ctf_img1->set_fftodd(false); else ctf_img1->set_fftodd(true); 20265 return ctf_img1; 20266 }
EMData * Util::ctf_rimg | ( | 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 | |||
) | [static] |
Definition at line 20270 of file util_sparx.cpp.
References EMAN::EMData::set_size(), tf(), and EMAN::EMData::update().
20271 { 20272 int ix, iy, iz; 20273 int i, j, k; 20274 float ak; 20275 float scx, scy, scz; 20276 EMData* ctf_img1 = new EMData(); 20277 ctf_img1->set_size(nx, ny, nz); 20278 float freq = 1.0f/(2.0f*ps); 20279 scx = 2.0f/float(nx); 20280 if(ny>=1) scy = 2.0f/float(ny); else scy=0.0f; 20281 if(nz>=1) scz = 2.0f/float(nz); else scz=0.0f; 20282 int ns2 = nx/2 ; 20283 int nr2 = ny/2 ; 20284 int nl2 = nz/2 ; 20285 int nod = nx%2 ; 20286 int nok = ny%2 ; 20287 int noz = nz%2 ; 20288 for ( k=0; k<nz;k++) { 20289 iz = k - nl2; 20290 int kz = (nz - k - noz)%nz; 20291 float oz2 = iz*scz*iz*scz; 20292 for ( j=0; j<ny;j++) { 20293 iy = j - nr2; 20294 int jy = (ny - j - nok)%ny; 20295 float oy = iy*scy; 20296 float oy2 = oy*oy; 20297 for ( i=0; i<=ns2; i++) { 20298 ix = i - ns2; 20299 if( dza == 0.0f) { 20300 ak=pow(ix*ix*scx*scx + oy2 + oz2, 0.5f)*freq; 20301 (*ctf_img1) (i,j,k) = Util::tf(dz, ak, voltage, cs, wgh, b_factor, sign); 20302 } else { 20303 float ox = ix*scx; 20304 ak=pow(ox*ox + oy2 + oz2, 0.5f)*freq; 20305 float dzz = dz - dza/2.0f*sin(2*(atan2(oy, ox)+azz*M_PI/180.0f)); 20306 (*ctf_img1) (i,j,k) = Util::tf(dzz, ak, voltage, cs, wgh, b_factor, sign); 20307 } 20308 ix = nx - i - nod; 20309 if(ix<nx) (*ctf_img1) (ix,jy,kz) = (*ctf_img1) (i,j,k); 20310 } 20311 } 20312 } 20313 ctf_img1->update(); 20314 return ctf_img1; 20315 }
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 5325 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().
05325 { 05326 05327 if (image->is_complex()) throw ImageFormatException("Real image required for IntegerCyclicShift2DProcessor"); 05328 05329 int dx = params["dx"]; 05330 int dy = params["dy"]; 05331 int dz = params["dz"]; 05332 05333 // The reverse trick we're using shifts to the left (a negative shift) 05334 int nx = image->get_xsize(); 05335 dx %= nx; 05336 if (dx < 0) dx += nx; 05337 int ny = image->get_ysize(); 05338 dy %= ny; 05339 if (dy < 0) dy += ny; 05340 int nz = image->get_zsize(); 05341 dz %= nz; 05342 if (dz < 0) dz += nz; 05343 05344 int mx = -(dx - nx); 05345 int my = -(dy - ny); 05346 int mz = -(dz - nz); 05347 05348 float* data = image->get_data(); 05349 // x-reverses 05350 if (mx != 0) { 05351 for (int iz = 0; iz < nz; iz++) 05352 for (int iy = 0; iy < ny; iy++) { 05353 // reverses for column iy 05354 size_t offset = nx*iy + (size_t)nx*ny*iz; // starting location for column iy in slice iz 05355 reverse(&data[offset],&data[offset+mx]); 05356 reverse(&data[offset+mx],&data[offset+nx]); 05357 reverse(&data[offset],&data[offset+nx]); 05358 } 05359 } 05360 // y-reverses 05361 if (my != 0) { 05362 for (int iz = 0; iz < nz; iz++) { 05363 size_t offset = (size_t)nx*ny*iz; 05364 colreverse(&data[offset], &data[offset + my*nx], nx); 05365 colreverse(&data[offset + my*nx], &data[offset + ny*nx], nx); 05366 colreverse(&data[offset], &data[offset + ny*nx], nx); 05367 } 05368 } 05369 if (mz != 0) { 05370 slicereverse(&data[0], &data[(size_t)mz*ny*nx], nx, ny); 05371 slicereverse(&data[mz*ny*nx], &data[(size_t)nz*ny*nx], nx, ny); 05372 slicereverse(&data[0], &data[(size_t)nz*ny*nx], nx ,ny); 05373 } 05374 image->update(); 05375 }
Definition at line 5119 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().
05120 { 05121 /* Exception Handle */ 05122 if (!img) { 05123 throw NullPointerException("NULL input image"); 05124 } 05125 /* ============================== */ 05126 05127 // Get the size of the input image 05128 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 05129 /* ============================== */ 05130 05131 05132 /* Exception Handle */ 05133 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) 05134 { 05135 LOGERR("Parameters for decimation cannot exceed the center of the image."); 05136 throw ImageDimensionException("Parameters for decimation cannot exceed the center of the image."); 05137 } 05138 /* ============================== */ 05139 05140 05141 /* Calculation of the start point */ 05142 int new_st_x=(nx/2)%x_step, new_st_y=(ny/2)%y_step, new_st_z=(nz/2)%z_step; 05143 /* ============================*/ 05144 05145 05146 /* Calculation of the size of the decimated image */ 05147 int rx=2*(nx/(2*x_step)), ry=2*(ny/(2*y_step)), rz=2*(nz/(2*z_step)); 05148 int r1=int(ceil((nx-(x_step*rx))/(1.f*x_step))), r2=int(ceil((ny-(y_step*ry))/(1.f*y_step))); 05149 int r3=int(ceil((nz-(z_step*rz))/(1.f*z_step))); 05150 if(r1>1){r1=1;} 05151 if(r2>1){r2=1;} 05152 if(r3>1){r3=1;} 05153 int new_nx=rx+r1, new_ny=ry+r2, new_nz=rz+r3; 05154 /* ===========================================*/ 05155 05156 05157 EMData* img2 = new EMData(); 05158 img2->set_size(new_nx,new_ny,new_nz); 05159 float *new_ptr = img2->get_data(); 05160 float *old_ptr = img->get_data(); 05161 int iptr, jptr, kptr = 0; 05162 for (int k=new_st_z; k<nz; k+=z_step) {jptr=0; 05163 for (int j=new_st_y; j<ny; j+=y_step) {iptr=0; 05164 for (int i=new_st_x; i<nx; i+=x_step) { 05165 new_ptr(iptr,jptr,kptr) = old_ptr(i,j,k); 05166 iptr++;} 05167 jptr++;} 05168 kptr++;} 05169 img2->update(); 05170 return img2; 05171 }
void Util::disorder2 | ( | double * | x, | |
double * | y, | |||
int * | key, | |||
int | len | |||
) | [static] |
Definition at line 7693 of file util_sparx.cpp.
References ENTERFUNC, and EXITFUNC.
07694 { 07695 ENTERFUNC; 07696 int k, i; 07697 for(i=0; i<len; i++) key[i]=i+1; 07698 07699 for(i = 0; i<len;i++){ 07700 k = rand()%len; 07701 std::swap(key[k], key[i]); 07702 std::swap(x[k], x[i]); 07703 std::swap(y[k], y[i]); 07704 } 07705 EXITFUNC; 07706 }
Definition at line 17628 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, 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().
17629 { 17630 ENTERFUNC; 17631 /* Exception Handle */ 17632 if (!img) { 17633 throw NullPointerException("NULL input image"); 17634 } 17635 /* ========= img /= img1 ===================== */ 17636 17637 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17638 size_t size = (size_t)nx*ny*nz; 17639 float *img_ptr = img->get_data(); 17640 float *img1_ptr = img1->get_data(); 17641 if(img->is_complex()) { 17642 for (size_t i=0; i<size; i+=2) { 17643 if(img1_ptr[i] > 1.e-10f) { 17644 img_ptr[i] /= img1_ptr[i]; 17645 img_ptr[i+1] /= img1_ptr[i]; 17646 } else img_ptr[i] = img_ptr[i+1] = 0.0f; 17647 } 17648 } else throw ImageFormatException("Only Fourier image allowed"); 17649 17650 img->update(); 17651 17652 EXITFUNC; 17653 }
Definition at line 17599 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, 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().
17600 { 17601 ENTERFUNC; 17602 /* Exception Handle */ 17603 if (!img) { 17604 throw NullPointerException("NULL input image"); 17605 } 17606 /* ========= img /= img1 ===================== */ 17607 17608 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17609 size_t size = (size_t)nx*ny*nz; 17610 float *img_ptr = img->get_data(); 17611 float *img1_ptr = img1->get_data(); 17612 if(img->is_complex()) { 17613 float sq2; 17614 for (size_t i=0; i<size; i+=2) { 17615 sq2 = 1.0f/(img1_ptr[i] * img1_ptr[i] + img1_ptr[i+1] * img1_ptr[i+1]); 17616 float tmp = sq2*(img_ptr[i] * img1_ptr[i] + img_ptr[i+1] * img1_ptr[i+1]) ; 17617 img_ptr[i+1] = sq2*(img_ptr[i+1] * img1_ptr[i] - img_ptr[i] * img1_ptr[i+1]) ; 17618 img_ptr[i] = tmp; 17619 } 17620 } else { 17621 for (size_t i=0; i<size; ++i) img_ptr[i] /= img1_ptr[i]; 17622 } 17623 img->update(); 17624 17625 EXITFUNC; 17626 }
Definition at line 17424 of file util_sparx.cpp.
References EMAN::EMData::copy_head(), ENTERFUNC, EXITFUNC, 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().
17425 { 17426 ENTERFUNC; 17427 /* Exception Handle */ 17428 if (!img) { 17429 throw NullPointerException("NULL input image"); 17430 } 17431 /* ========= img /= img1 ===================== */ 17432 17433 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17434 size_t size = (size_t)nx*ny*nz; 17435 EMData * img2 = img->copy_head(); 17436 float *img_ptr = img->get_data(); 17437 float *img1_ptr = img1->get_data(); 17438 float *img2_ptr = img2->get_data(); 17439 if(img->is_complex()) { 17440 for (size_t i=0; i<size; i+=2) { 17441 if(img1_ptr[i] > 1.e-10f) { 17442 img2_ptr[i] = img_ptr[i] /img1_ptr[i]; 17443 img2_ptr[i+1] = img_ptr[i+1]/img1_ptr[i]; 17444 } else img2_ptr[i] = img2_ptr[i+1] = 0.0f; 17445 } 17446 } else throw ImageFormatException("Only Fourier image allowed"); 17447 17448 img->update(); 17449 17450 EXITFUNC; 17451 return img2; 17452 }
Definition at line 17391 of file util_sparx.cpp.
References EMAN::EMData::copy_head(), ENTERFUNC, EXITFUNC, 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().
17392 { 17393 ENTERFUNC; 17394 /* Exception Handle */ 17395 if (!img) { 17396 throw NullPointerException("NULL input image"); 17397 } 17398 /* ============== output = img / img1 ================ */ 17399 17400 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17401 size_t size = (size_t)nx*ny*nz; 17402 EMData * img2 = img->copy_head(); 17403 float *img_ptr = img->get_data(); 17404 float *img2_ptr = img2->get_data(); 17405 float *img1_ptr = img1->get_data(); 17406 if(img->is_complex()) { 17407 float sq2; 17408 for (size_t i=0; i<size; i+=2) { 17409 sq2 = 1.0f/(img1_ptr[i] * img1_ptr[i] + img1_ptr[i+1] * img1_ptr[i+1]); 17410 img2_ptr[i] = sq2*(img_ptr[i] * img1_ptr[i] + img_ptr[i+1] * img1_ptr[i+1]) ; 17411 img2_ptr[i+1] = sq2*(img_ptr[i+1] * img1_ptr[i] - img_ptr[i] * img1_ptr[i+1]) ; 17412 } 17413 img2->set_complex(true); 17414 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17415 } else { 17416 for (size_t i=0; i<size; ++i) img2_ptr[i] = img_ptr[i] / img1_ptr[i]; 17417 img2->update(); 17418 } 17419 17420 EXITFUNC; 17421 return img2; 17422 }
static float EMAN::Util::eman_copysign | ( | float | a, | |
float | b | |||
) | [inline, static] |
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.
[in] | a | The first number. |
[in] | b | The second number. |
static float EMAN::Util::eman_erfc | ( | float | x | ) | [inline, static] |
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).
[in] | x | A float number. |
Definition at line 2067 of file util.h.
Referenced by EMAN::IterationAverager::finish().
float Util::ener | ( | EMData * | ave, | |
vector< int > | numr | |||
) | [static] |
Definition at line 4316 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), numr, and PI2.
Referenced by ener_tot().
04316 { 04317 ENTERFUNC; 04318 long double ener,en; 04319 04320 int nring = numr.size()/3; 04321 float *aveptr = ave->get_data(); 04322 04323 ener = 0.0; 04324 for (int i=1; i<=nring; i++) { 04325 int numr3i = numr(3,i); 04326 int np = numr(2,i)-1; 04327 float tq = static_cast<float>(PI2*numr(1,i)/numr3i); 04328 en = tq*(aveptr[np]*aveptr[np]+aveptr[np+1]*aveptr[np+1])*0.5; 04329 for (int j=np+2; j<np+numr3i-1; j++) en += tq*aveptr[j]*aveptr[j]; 04330 ener += en/numr3i; 04331 } 04332 EXITFUNC; 04333 return static_cast<float>(ener); 04334 }
float Util::ener_tot | ( | const vector< EMData * > & | data, | |
vector< int > | numr, | |||
vector< float > | tot | |||
) | [static] |
Definition at line 4336 of file util_sparx.cpp.
References ener(), ENTERFUNC, EXITFUNC, get_data(), numr, and PI2.
04336 { 04337 ENTERFUNC; 04338 long double ener, en; 04339 float arg, cs, si; 04340 04341 int nima = data.size(); 04342 int nring = numr.size()/3; 04343 int maxrin = numr(3,nring); 04344 04345 ener = 0.0; 04346 for (int i=1; i<=nring; i++) { 04347 int numr3i = numr(3,i); 04348 int np = numr(2,i)-1; 04349 float tq = static_cast<float>(PI2*numr(1,i)/numr3i); 04350 float temp1 = 0.0, temp2 = 0.0; 04351 for (int kk=0; kk<nima; kk++) { 04352 float *ptr = data[kk]->get_data(); 04353 temp1 += ptr[np]; 04354 temp2 += static_cast<float>(ptr[np+1]*cos(PI2*(tot[kk]-1.0f)/2.0f*numr3i/maxrin)); 04355 } 04356 en = tq*(temp1*temp1+temp2*temp2)*0.5; 04357 for (int j=2; j<numr3i; j+=2) { 04358 float tempr = 0.0, tempi = 0.0; 04359 for (int kk=0; kk<nima; kk++) { 04360 float *ptr = data[kk]->get_data(); 04361 arg = static_cast<float>( PI2*(tot[kk]-1.0)*(j/2)/maxrin ); 04362 cs = cos(arg); 04363 si = sin(arg); 04364 tempr += ptr[np + j]*cs - ptr[np + j +1]*si; 04365 tempi += ptr[np + j]*si + ptr[np + j +1]*cs; 04366 } 04367 en += tq*(tempr*tempr+tempi*tempi); 04368 } 04369 ener += en/numr3i; 04370 } 04371 EXITFUNC; 04372 return static_cast<float>(ener); 04373 }
void Util::equation_of_plane | ( | const Vec3f & | p1, | |
const Vec3f & | p2, | |||
const Vec3f & | p3, | |||
float * | plane | |||
) | [static] |
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
p1 | point one | |
p2 | point two | |
p3 | point three | |
plane | a float pointer - should have room for 4 elements which will be A,B,C, and D (in that order) for the equation Ax+By+Cz+D=0 |
Definition at line 1278 of file util.cpp.
Referenced by EMAN::Symmetry3D::cache_au_planes().
01279 { 01280 int x=0,y=1,z=2; 01281 plane[0] = p1[y]*(p2[z]-p3[z])+p2[y]*(p3[z]-p1[z])+p3[y]*(p1[z]-p2[z]); 01282 plane[1] = p1[z]*(p2[x]-p3[x])+p2[z]*(p3[x]-p1[x])+p3[z]*(p1[x]-p2[x]); 01283 plane[2] = p1[x]*(p2[y]-p3[y])+p2[x]*(p3[y]-p1[y])+p3[x]*(p1[y]-p2[y]); 01284 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]); 01285 plane[3] = -plane[3]; 01286 }
float Util::eval | ( | char * | images, | |
EMData * | img, | |||
vector< int > | S, | |||
int | N, | |||
int | K, | |||
int | size | |||
) | [static] |
Definition at line 7041 of file util_sparx.cpp.
References EMAN::EMData::get_data(), and EMAN::EMData::read_image().
07042 { 07043 int j,d; 07044 EMData * e = new EMData(); 07045 float *eptr, *imgptr; 07046 imgptr = img->get_data(); 07047 float SSE = 0.f; 07048 for (j = 0 ; j < N ; j++) { 07049 e->read_image(images,S[j]); 07050 eptr = e->get_data(); 07051 for (d = 0; d < size; d++) { 07052 SSE += ((eptr[d] - imgptr[d])*(eptr[d] - imgptr[d]));} 07053 } 07054 delete e; 07055 return SSE; 07056 }
vector< float > Util::even_angles | ( | float | delta, | |
float | t1 = 0 , |
|||
float | t2 = 90 , |
|||
float | p1 = 0 , |
|||
float | p2 = 359.999 | |||
) | [static] |
Compute a vector containing quasi-evenly spaced Euler angles.
The order of angles in the vector is phi, theta, psi.
[in] | delta | Delta theta (spacing in theta). |
[in] | t1 | Starting (min) value of theta in degrees, default = 0. |
[in] | t2 | Ending (max) value of theta in degrees, default = 90. |
[in] | p1 | Starting (min) value of phi in degrees, default = 0. |
[in] | p2 | Ending (max) value of phi in degrees, default = 359.9. |
Definition at line 513 of file util_sparx.cpp.
References angles, dgr_to_rad, phi, and theta.
00514 { 00515 vector<float> angles; 00516 float psi = 0.0; 00517 if ((0.0 == t1 && 0.0 == t2)||(t1 >= t2)) { 00518 t1 = 0.0f; 00519 t2 = 90.0f; 00520 } 00521 if ((0.0 == p1 && 0.0 == p2)||(p1 >= p2)) { 00522 p1 = 0.0f; 00523 p2 = 359.9f; 00524 } 00525 bool skip = ((t1 < 90.0) && (90.0 == t2) && (0.0 == p1) && (p2 > 180.0)); 00526 for (float theta = t1; theta <= t2; theta += delta) { 00527 float detphi; 00528 int lt; 00529 if ((0.0 == theta)||(180.0 == theta)) { 00530 detphi = 360.0f; 00531 lt = 1; 00532 } else { 00533 detphi = delta/sin(theta*static_cast<float>(dgr_to_rad)); 00534 lt = int((p2 - p1)/detphi)-1; 00535 if (lt < 1) lt = 1; 00536 detphi = (p2 - p1)/lt; 00537 } 00538 for (int i = 0; i < lt; i++) { 00539 float phi = p1 + i*detphi; 00540 if (skip&&(90.0 == theta)&&(phi > 180.0)) continue; 00541 angles.push_back(phi); 00542 angles.push_back(theta); 00543 angles.push_back(psi); 00544 } 00545 } 00546 return angles; 00547 }
bool Util::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 | |||
) | [static] |
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 21235 of file util_sparx.cpp.
References k_means_cont_table_().
Referenced by initial_prune().
21235 { 21236 21237 21238 if (size_next <= T) return 0; 21239 21240 // take the intx of next and cur 21241 int* curintx2(0); 21242 int nintx = Util::k_means_cont_table_(curintx, next+2, curintx2, size_curintx, size_next,0); 21243 if (nintx <= T) return 0; 21244 21245 int old_depth=depth; 21246 if (depth == partref) depth = depth + 1; // we skip classes in partref 21247 if (depth == nParts && old_depth>0) return 1; 21248 21249 // have not yet reached a leaf, and current weight is still greather than T, so keep on going. 21250 21251 curintx2 = new int[nintx]; // put the intersection set in here 21252 Util::k_means_cont_table_(curintx,next+2,curintx2, size_curintx, size_next,1); 21253 21254 // if (old_depth > 0) {delete[] curintx;} // don't delete when depth == 0 because curintx in that case is a pointer into Parts 21255 21256 // we now consider each of the classes in partition (depth+1) in turn 21257 bool gt_thresh; 21258 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 21259 21260 for (int i=0; i < num_classes; i++){ 21261 if (Parts[depth][i][1] < 1) continue; // class is not active so move on 21262 size_next = dimClasses[depth*K + Parts[depth][i][0] ]-2; 21263 gt_thresh = explore(Parts,dimClasses, nParts, K, T, partref, curintx2,nintx, Parts[depth][i], size_next, depth+1); 21264 if (gt_thresh) { delete[] curintx2; return 1; } 21265 } 21266 delete[] curintx2; 21267 return 0; 21268 }
void Util::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 | |||
) | [static] |
Definition at line 21069 of file util_sparx.cpp.
References explore2(), and k_means_cont_table_().
21069 { 21070 21071 // depth is the level which is going to be explored in the current iteration 21072 int* curintx2(0); 21073 int nintx = size_curintx; 21074 21075 21076 // 2. take the intx of next and cur. Prune if <= T 21077 if (depth >0){ 21078 nintx = Util::k_means_cont_table_(curintx,next, curintx2, size_curintx, size_next,0); 21079 if (nintx <= T) return; //prune! 21080 } 21081 21082 // 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 21083 if (depth == (nParts-1)) { 21084 21085 int replace = 0; 21086 int ind_smallest = -1; 21087 int smallest_cost = -1; 21088 21089 for (int jit = 0; jit < J; jit++){ 21090 if (*(costlist+jit) < nintx){ 21091 replace = 1; 21092 if (ind_smallest == -1) {ind_smallest = jit; smallest_cost = *(costlist+jit);} 21093 if (*(costlist+jit) < smallest_cost) {ind_smallest = jit; smallest_cost = *(costlist+jit);} 21094 } 21095 } 21096 21097 if (replace > 0){ 21098 // replace the smallest cost in matchlist with the current stuff 21099 *(costlist + ind_smallest) = nintx; 21100 for (int xit = 0; xit < nParts; xit++) 21101 *(matchlist + ind_smallest*nParts + xit) = *(curbranch+xit); 21102 21103 } 21104 21105 return; 21106 } 21107 21108 21109 // 3. have not yet reached a leaf, and current weight is still greather than T, so keep on going. 21110 21111 if (depth > 0){ 21112 curintx2 = new int[nintx]; // put the intersection set in here 21113 Util::k_means_cont_table_(curintx,next,curintx2, size_curintx, size_next,1); 21114 } 21115 21116 if (depth == 0){ 21117 // set curintx2 to curintx 21118 curintx2 = new int[size_curintx]; 21119 for (int cp = 0; cp < size_curintx; cp++) *(curintx2+cp) = *(curintx+cp); 21120 } 21121 21122 21123 // recursion (non-leaf case) 21124 depth=depth+1; 21125 // we now consider each of the classes in partition depth and recurse upon each of them 21126 for (int i=0; i < K; i++){ 21127 21128 if (*(argParts + Indices[depth*K+i] + 1) < 1) continue; // class is not active so move on 21129 size_next = (*(dimClasses + depth*K+i ))-2; 21130 if (size_next <= T) continue; 21131 *(curbranch+depth) = i; 21132 Util::explore2(argParts,Indices, dimClasses, nParts, K, T, curintx2, nintx, argParts + Indices[depth*K+i] + 2, size_next, depth,J, matchlist, 21133 costlist, curbranch); 21134 21135 } 21136 21137 delete[] curintx2; 21138 }
complex< float > Util::extractpoint2 | ( | int | nx, | |
int | ny, | |||
float | nuxnew, | |||
float | nuynew, | |||
EMData * | fimage, | |||
Util::KaiserBessel & | kb | |||
) | [static] |
Definition at line 1691 of file util_sparx.cpp.
References EMAN::EMData::cmplx(), EMAN::Util::KaiserBessel::i0win_tab(), ImageDimensionException, and round().
01691 { 01692 01693 int nxreal = nx - 2; 01694 if (nxreal != ny) 01695 throw ImageDimensionException("extractpoint requires ny == nx"); 01696 int nhalf = nxreal/2; 01697 bool flip = (nuxnew < 0.f); 01698 if (flip) { 01699 nuxnew *= -1; 01700 nuynew *= -1; 01701 } 01702 if (nuynew >= nhalf-0.5) { 01703 nuynew -= nxreal; 01704 } else if (nuynew < -nhalf-0.5) { 01705 nuynew += nxreal; 01706 } 01707 01708 // put (xnew,ynew) on a grid. The indices will be wrong for 01709 // the Fourier elements in the image, but the grid sizing will 01710 // be correct. 01711 int ixn = int(Util::round(nuxnew)); 01712 int iyn = int(Util::round(nuynew)); 01713 01714 // set up some temporary weighting arrays 01715 static float wy[7]; 01716 static float wx[7]; 01717 01718 float iynn = nuynew - iyn; 01719 wy[0] = kb.i0win_tab(iynn+3); 01720 wy[1] = kb.i0win_tab(iynn+2); 01721 wy[2] = kb.i0win_tab(iynn+1); 01722 wy[3] = kb.i0win_tab(iynn); 01723 wy[4] = kb.i0win_tab(iynn-1); 01724 wy[5] = kb.i0win_tab(iynn-2); 01725 wy[6] = kb.i0win_tab(iynn-3); 01726 01727 float ixnn = nuxnew - ixn; 01728 wx[0] = kb.i0win_tab(ixnn+3); 01729 wx[1] = kb.i0win_tab(ixnn+2); 01730 wx[2] = kb.i0win_tab(ixnn+1); 01731 wx[3] = kb.i0win_tab(ixnn); 01732 wx[4] = kb.i0win_tab(ixnn-1); 01733 wx[5] = kb.i0win_tab(ixnn-2); 01734 wx[6] = kb.i0win_tab(ixnn-3); 01735 01736 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]); 01737 01738 complex<float> result(0.f,0.f); 01739 if ((ixn >= 3) && (ixn <= nhalf-3) && (iyn >= -nhalf+3) && (iyn <= nhalf-4)) { 01740 // (xin,yin) not within window border from the edge 01741 for (int iy = 0; iy < 7; iy++) { 01742 int iyp = iyn + iy - 3 ; 01743 for (int ix = 0; ix < 7; ix++) { 01744 int ixp = ixn + ix - 3; 01745 float w = wx[ix]*wy[iy]; 01746 complex<float> val = fimage->cmplx(ixp,iyp); 01747 result += val*w; 01748 } 01749 } 01750 } else { 01751 // points that "stick out" 01752 for (int iy = 0; iy < 7; iy++) { 01753 int iyp = iyn + iy - 3; 01754 for (int ix = 0; ix < 7; ix++) { 01755 int ixp = ixn + ix - 3; 01756 bool mirror = false; 01757 int ixt = ixp, iyt = iyp; 01758 if (ixt < 0) { 01759 ixt = -ixt; 01760 iyt = -iyt; 01761 mirror = !mirror; 01762 } 01763 if (ixt > nhalf) { 01764 ixt = nxreal - ixt; 01765 iyt = -iyt; 01766 mirror = !mirror; 01767 } 01768 if (iyt > nhalf-1) iyt -= nxreal; 01769 if (iyt < -nhalf) iyt += nxreal; 01770 float w = wx[ix]*wy[iy]; 01771 complex<float> val = fimage->cmplx(ixt,iyt); 01772 if (mirror) result += conj(val)*w; 01773 else result += val*w; 01774 } 01775 } 01776 } 01777 if (flip) result = conj(result)/wsum; 01778 else result /= wsum; 01779 return result; 01780 }
float Util::fast_acos | ( | const float & | f | ) | [static] |
Returns an approximate of acos(x) using a cached table and linear interpolation tolerates values very slightly outside the -1 - 1 range (returning 0).
[in] | x | argument to acos(x) |
Definition at line 817 of file util.cpp.
00817 { 00818 if (f>=1.0) return 0.0; 00819 if (f<=-1.0) return M_PI; 00820 00821 static float *mem = (float *)malloc(sizeof(float)*2001); 00822 static bool needinit=true; 00823 00824 00825 if (needinit) { 00826 needinit=false; 00827 for (int i=0; i<=2000; i++) mem[i]=(float)acos(i/1000.0-1.0); 00828 } 00829 float f2=f*1000.0f+1000.0f; 00830 00831 int g=(int)(f2+.5); 00832 00833 return mem[g]; 00834 00835 // This version interpolates, but is slower 00836 /*int g=(int)f2; 00837 f2-=g; 00838 return mem[g+1]*f2+mem[g]*(1.0-f2);*/ 00839 }
float Util::fast_exp | ( | const float & | f | ) | [static] |
Returns an approximate of exp(x) using a cached table uses actual exp(x) outside the cached range.
[in] | f | argument to exp(f) |
Definition at line 801 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().
00801 { 00802 static float *mem = (float *)malloc(sizeof(float)*1000); 00803 static bool needinit=true; 00804 00805 if (needinit) { 00806 needinit=false; 00807 for (int i=0; i<1000; i++) mem[i]=(float)exp(-i/50.0); 00808 } 00809 if (f>0 || f<-19.98) return exp(f); 00810 int g=(int)(-f*50.0+0.5); 00811 00812 return mem[g]; 00813 }
static int EMAN::Util::fast_floor | ( | float | x | ) | [inline, static] |
A fast way to calculate a floor, which is largest integral value not greater than argument.
[in] | x | A float point number. |
Definition at line 1783 of file util.h.
Referenced by EMAN::MaskEdgeMeanProcessor::calc_locals(), EMAN::CircularMaskProcessor::calc_locals(), EMAN::EMData::cut_slice(), EMAN::EMData::dot_rotate_translate(), EMAN::EMData::extract_box(), EMAN::SymSearchProcessor::process_inplace(), EMAN::AddRandomNoiseProcessor::process_inplace(), EMAN::RotationalAverageProcessor::process_inplace(), EMAN::MaxValProjector::project3d(), EMAN::StandardProjector::project3d(), EMAN::EMData::sget_value_at_interp(), EMAN::TransformProcessor::transform(), and EMAN::EMData::unwrap().
void Util::fftc_d | ( | double * | br, | |
double * | bi, | |||
int | ln, | |||
int | ks | |||
) | [static] |
Definition at line 2624 of file util_sparx.cpp.
References abs, bi, br, sgn(), status, t, and tab1.
Referenced by fftr_d().
02625 { 02626 double rni,sgn,tr1,tr2,ti1,ti2; 02627 double cc,c,ss,s,t,x2,x3,x4,x5; 02628 int b3,b4,b5,b6,b7,b56; 02629 int n, k, l, j, i, ix0, ix1, status=0; 02630 02631 const double tab1[] = { 02632 9.58737990959775e-5, 02633 1.91747597310703e-4, 02634 3.83495187571395e-4, 02635 7.66990318742704e-4, 02636 1.53398018628476e-3, 02637 3.06795676296598e-3, 02638 6.13588464915449e-3, 02639 1.22715382857199e-2, 02640 2.45412285229123e-2, 02641 4.90676743274181e-2, 02642 9.80171403295604e-2, 02643 1.95090322016128e-1, 02644 3.82683432365090e-1, 02645 7.07106781186546e-1, 02646 1.00000000000000, 02647 }; 02648 02649 n=(int)pow(2.0f,ln); 02650 02651 k=abs(ks); 02652 l=16-ln; 02653 b3=n*k; 02654 b6=b3; 02655 b7=k; 02656 if (ks > 0) { 02657 sgn=1.0f; 02658 } else { 02659 sgn=-1.0f; 02660 rni=1.0f/(float)(n); 02661 j=1; 02662 for (i=1; i<=n; i++) { 02663 br(j)=br(j)*rni; 02664 bi(j)=bi(j)*rni; 02665 j=j+k; 02666 } 02667 } 02668 02669 L12: 02670 b6=b6/2; 02671 b5=b6; 02672 b4=2*b6; 02673 b56=b5-b6; 02674 02675 L14: 02676 tr1=br(b5+1); 02677 ti1=bi(b5+1); 02678 tr2=br(b56+1); 02679 ti2=bi(b56+1); 02680 02681 br(b5+1)=tr2-tr1; 02682 bi(b5+1)=ti2-ti1; 02683 br(b56+1)=tr1+tr2; 02684 bi(b56+1)=ti1+ti2; 02685 02686 b5=b5+b4; 02687 b56=b5-b6; 02688 if ( b5 <= b3 ) goto L14; 02689 if ( b6 == b7 ) goto L20; 02690 02691 b4=b7; 02692 cc=2.0f*pow(tab1(l),2); 02693 c=1.0f-cc; 02694 l++; 02695 ss=sgn*tab1(l); 02696 s=ss; 02697 02698 L16: 02699 b5=b6+b4; 02700 b4=2*b6; 02701 b56=b5-b6; 02702 02703 L18: 02704 tr1=br(b5+1); 02705 ti1=bi(b5+1); 02706 tr2=br(b56+1); 02707 ti2=bi(b56+1); 02708 br(b5+1)=c*(tr2-tr1)-s*(ti2-ti1); 02709 bi(b5+1)=s*(tr2-tr1)+c*(ti2-ti1); 02710 br(b56+1)=tr1+tr2; 02711 bi(b56+1)=ti1+ti2; 02712 02713 b5=b5+b4; 02714 b56=b5-b6; 02715 if ( b5 <= b3 ) goto L18; 02716 b4=b5-b6; 02717 b5=b4-b3; 02718 c=-c; 02719 b4=b6-b5; 02720 if ( b5 < b4 ) goto L16; 02721 b4=b4+b7; 02722 if ( b4 >= b5 ) goto L12; 02723 02724 t=c-cc*c-ss*s; 02725 s=s+ss*c-cc*s; 02726 c=t; 02727 goto L16; 02728 02729 L20: 02730 ix0=b3/2; 02731 b3=b3-b7; 02732 b4=0; 02733 b5=0; 02734 b6=ix0; 02735 ix1=0; 02736 if (b6 == b7) goto EXIT; 02737 02738 L22: 02739 b4=b3-b4; 02740 b5=b3-b5; 02741 x2=br(b4+1); 02742 x3=br(b5+1); 02743 x4=bi(b4+1); 02744 x5=bi(b5+1); 02745 br(b4+1)=x3; 02746 br(b5+1)=x2; 02747 bi(b4+1)=x5; 02748 bi(b5+1)=x4; 02749 if(b6 < b4) goto L22; 02750 02751 L24: 02752 b4=b4+b7; 02753 b5=b6+b5; 02754 x2=br(b4+1); 02755 x3=br(b5+1); 02756 x4=bi(b4+1); 02757 x5=bi(b5+1); 02758 br(b4+1)=x3; 02759 br(b5+1)=x2; 02760 bi(b4+1)=x5; 02761 bi(b5+1)=x4; 02762 ix0=b6; 02763 02764 L26: 02765 ix0=ix0/2; 02766 ix1=ix1-ix0; 02767 if( ix1 >= 0) goto L26; 02768 02769 ix0=2*ix0; 02770 b4=b4+b7; 02771 ix1=ix1+ix0; 02772 b5=ix1; 02773 if ( b5 >= b4) goto L22; 02774 if ( b4 < b6) goto L24; 02775 02776 EXIT: 02777 status = 0; 02778 }
void Util::fftc_q | ( | float * | br, | |
float * | bi, | |||
int | ln, | |||
int | ks | |||
) | [static] |
Definition at line 2781 of file util_sparx.cpp.
References abs, bi, br, sgn(), status, t, and tab1.
Referenced by fftr_q().
02782 { 02783 // dimension br(1),bi(1) 02784 02785 int b3,b4,b5,b6,b7,b56; 02786 int n, k, l, j, i, ix0, ix1; 02787 float rni, tr1, ti1, tr2, ti2, cc, c, ss, s, t, x2, x3, x4, x5, sgn; 02788 int status=0; 02789 02790 const float tab1[] = { 02791 9.58737990959775e-5f, 02792 1.91747597310703e-4f, 02793 3.83495187571395e-4f, 02794 7.66990318742704e-4f, 02795 1.53398018628476e-3f, 02796 3.06795676296598e-3f, 02797 6.13588464915449e-3f, 02798 1.22715382857199e-2f, 02799 2.45412285229123e-2f, 02800 4.90676743274181e-2f, 02801 9.80171403295604e-2f, 02802 1.95090322016128e-1f, 02803 3.82683432365090e-1f, 02804 7.07106781186546e-1f, 02805 1.00000000000000f, 02806 }; 02807 02808 n=(int)pow(2.0f,ln); 02809 02810 k=abs(ks); 02811 l=16-ln; 02812 b3=n*k; 02813 b6=b3; 02814 b7=k; 02815 if( ks > 0 ) { 02816 sgn=1.0f; 02817 } else { 02818 sgn=-1.0f; 02819 rni=1.0f/(float)n; 02820 j=1; 02821 for (i=1; i<=n; i++) { 02822 br(j)=br(j)*rni; 02823 bi(j)=bi(j)*rni; 02824 j=j+k; 02825 } 02826 } 02827 L12: 02828 b6=b6/2; 02829 b5=b6; 02830 b4=2*b6; 02831 b56=b5-b6; 02832 L14: 02833 tr1=br(b5+1); 02834 ti1=bi(b5+1); 02835 02836 tr2=br(b56+1); 02837 ti2=bi(b56+1); 02838 02839 br(b5+1)=tr2-tr1; 02840 bi(b5+1)=ti2-ti1; 02841 br(b56+1)=tr1+tr2; 02842 bi(b56+1)=ti1+ti2; 02843 02844 b5=b5+b4; 02845 b56=b5-b6; 02846 if ( b5 <= b3 ) goto L14; 02847 if ( b6 == b7 ) goto L20; 02848 02849 b4=b7; 02850 cc=2.0f*pow(tab1(l),2); 02851 c=1.0f-cc; 02852 l++; 02853 ss=sgn*tab1(l); 02854 s=ss; 02855 L16: 02856 b5=b6+b4; 02857 b4=2*b6; 02858 b56=b5-b6; 02859 L18: 02860 tr1=br(b5+1); 02861 ti1=bi(b5+1); 02862 tr2=br(b56+1); 02863 ti2=bi(b56+1); 02864 br(b5+1)=c*(tr2-tr1)-s*(ti2-ti1); 02865 bi(b5+1)=s*(tr2-tr1)+c*(ti2-ti1); 02866 br(b56+1)=tr1+tr2; 02867 bi(b56+1)=ti1+ti2; 02868 02869 b5=b5+b4; 02870 b56=b5-b6; 02871 if(b5 <= b3) goto L18; 02872 b4=b5-b6; 02873 b5=b4-b3; 02874 c=-c; 02875 b4=b6-b5; 02876 if(b5 < b4) goto L16; 02877 b4=b4+b7; 02878 if(b4 >= b5) goto L12; 02879 02880 t=c-cc*c-ss*s; 02881 s=s+ss*c-cc*s; 02882 c=t; 02883 goto L16; 02884 L20: 02885 ix0=b3/2; 02886 b3=b3-b7; 02887 b4=0; 02888 b5=0; 02889 b6=ix0; 02890 ix1=0; 02891 if ( b6 == b7) goto EXIT; 02892 L22: 02893 b4=b3-b4; 02894 b5=b3-b5; 02895 x2=br(b4+1); 02896 x3=br(b5+1); 02897 x4=bi(b4+1); 02898 x5=bi(b5+1); 02899 br(b4+1)=x3; 02900 br(b5+1)=x2; 02901 bi(b4+1)=x5; 02902 bi(b5+1)=x4; 02903 if (b6 < b4) goto L22; 02904 L24: 02905 b4=b4+b7; 02906 b5=b6+b5; 02907 x2=br(b4+1); 02908 x3=br(b5+1); 02909 x4=bi(b4+1); 02910 x5=bi(b5+1); 02911 br(b4+1)=x3; 02912 br(b5+1)=x2; 02913 bi(b4+1)=x5; 02914 bi(b5+1)=x4; 02915 ix0=b6; 02916 L26: 02917 ix0=ix0/2; 02918 ix1=ix1-ix0; 02919 if(ix1 >= 0) goto L26; 02920 02921 ix0=2*ix0; 02922 b4=b4+b7; 02923 ix1=ix1+ix0; 02924 b5=ix1; 02925 if (b5 >= b4) goto L22; 02926 if (b4 < b6) goto L24; 02927 EXIT: 02928 status = 0; 02929 }
void Util::fftr_d | ( | double * | xcmplx, | |
int | nv | |||
) | [static] |
Definition at line 3013 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(), and Crosrng_sm_psi().
03014 { 03015 // double precision x(2,1) 03016 int i1, i2, nu, inv, nu1, n, isub, n2, i; 03017 double tr1,tr2,ti1,ti2,tr,ti; 03018 double cc,c,ss,s,t; 03019 const double tab1[] = { 03020 9.58737990959775e-5, 03021 1.91747597310703e-4, 03022 3.83495187571395e-4, 03023 7.66990318742704e-4, 03024 1.53398018628476e-3, 03025 3.06795676296598e-3, 03026 6.13588464915449e-3, 03027 1.22715382857199e-2, 03028 2.45412285229123e-2, 03029 4.90676743274181e-2, 03030 9.80171403295604e-2, 03031 1.95090322016128e-1, 03032 3.82683432365090e-1, 03033 7.07106781186546e-1, 03034 1.00000000000000, 03035 }; 03036 03037 nu=abs(nv); 03038 inv=nv/nu; 03039 nu1=nu-1; 03040 n=(int)pow(2.0f,nu1); 03041 isub=16-nu1; 03042 ss=-tab1(isub); 03043 cc=-2.0*pow(tab1(isub-1),2); 03044 c=1.0f; 03045 s=0.0f; 03046 n2=n/2; 03047 03048 if ( inv > 0 ) { 03049 fftc_d(&xcmplx(1,1),&xcmplx(2,1),nu1,2); 03050 tr=xcmplx(1,1); 03051 ti=xcmplx(2,1); 03052 xcmplx(1,1)=tr+ti; 03053 xcmplx(2,1)=tr-ti; 03054 for (i=1;i<=n2;i++) { 03055 i1=i+1; 03056 i2=n-i+1; 03057 tr1=xcmplx(1,i1); 03058 tr2=xcmplx(1,i2); 03059 ti1=xcmplx(2,i1); 03060 ti2=xcmplx(2,i2); 03061 t=(cc*c-ss*s)+c; 03062 s=(cc*s+ss*c)+s; 03063 c=t; 03064 xcmplx(1,i1)=0.5*((tr1+tr2)+(ti1+ti2)*c-(tr1-tr2)*s); 03065 xcmplx(1,i2)=0.5*((tr1+tr2)-(ti1+ti2)*c+(tr1-tr2)*s); 03066 xcmplx(2,i1)=0.5*((ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c); 03067 xcmplx(2,i2)=0.5*(-(ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c); 03068 } 03069 } else { 03070 tr=xcmplx(1,1); 03071 ti=xcmplx(2,1); 03072 xcmplx(1,1)=0.5*(tr+ti); 03073 xcmplx(2,1)=0.5*(tr-ti); 03074 for (i=1; i<=n2; i++) { 03075 i1=i+1; 03076 i2=n-i+1; 03077 tr1=xcmplx(1,i1); 03078 tr2=xcmplx(1,i2); 03079 ti1=xcmplx(2,i1); 03080 ti2=xcmplx(2,i2); 03081 t=(cc*c-ss*s)+c; 03082 s=(cc*s+ss*c)+s; 03083 c=t; 03084 xcmplx(1,i1)=0.5*((tr1+tr2)-(tr1-tr2)*s-(ti1+ti2)*c); 03085 xcmplx(1,i2)=0.5*((tr1+tr2)+(tr1-tr2)*s+(ti1+ti2)*c); 03086 xcmplx(2,i1)=0.5*((ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s); 03087 xcmplx(2,i2)=0.5*(-(ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s); 03088 } 03089 fftc_d(&xcmplx(1,1),&xcmplx(2,1),nu1,-2); 03090 } 03091 }
void Util::fftr_q | ( | float * | xcmplx, | |
int | nv | |||
) | [static] |
Definition at line 2931 of file util_sparx.cpp.
References abs, fftc_q(), t, tab1, and xcmplx.
Referenced by Crosrng_msg_vec(), Frngs(), and Frngs_inv().
02932 { 02933 // dimension xcmplx(2,1); xcmplx(1,i) --- real, xcmplx(2,i) --- imaginary 02934 02935 int nu, inv, nu1, n, isub, n2, i1, i2, i; 02936 float ss, cc, c, s, tr, ti, tr1, tr2, ti1, ti2, t; 02937 02938 const float tab1[] = { 02939 9.58737990959775e-5f, 02940 1.91747597310703e-4f, 02941 3.83495187571395e-4f, 02942 7.66990318742704e-4f, 02943 1.53398018628476e-3f, 02944 3.06795676296598e-3f, 02945 6.13588464915449e-3f, 02946 1.22715382857199e-2f, 02947 2.45412285229123e-2f, 02948 4.90676743274181e-2f, 02949 9.80171403295604e-2f, 02950 1.95090322016128e-1f, 02951 3.82683432365090e-1f, 02952 7.07106781186546e-1f, 02953 1.00000000000000f, 02954 }; 02955 02956 nu=abs(nv); 02957 inv=nv/nu; 02958 nu1=nu-1; 02959 n=(int)pow(2.f,nu1); 02960 isub=16-nu1; 02961 02962 ss=-tab1(isub); 02963 cc=-2.0f*pow(tab1(isub-1),2.f); 02964 c=1.0f; 02965 s=0.0f; 02966 n2=n/2; 02967 if ( inv > 0) { 02968 fftc_q(&xcmplx(1,1),&xcmplx(2,1),nu1,2); 02969 tr=xcmplx(1,1); 02970 ti=xcmplx(2,1); 02971 xcmplx(1,1)=tr+ti; 02972 xcmplx(2,1)=tr-ti; 02973 for (i=1;i<=n2;i++) { 02974 i1=i+1; 02975 i2=n-i+1; 02976 tr1=xcmplx(1,i1); 02977 tr2=xcmplx(1,i2); 02978 ti1=xcmplx(2,i1); 02979 ti2=xcmplx(2,i2); 02980 t=(cc*c-ss*s)+c; 02981 s=(cc*s+ss*c)+s; 02982 c=t; 02983 xcmplx(1,i1)=0.5f*((tr1+tr2)+(ti1+ti2)*c-(tr1-tr2)*s); 02984 xcmplx(1,i2)=0.5f*((tr1+tr2)-(ti1+ti2)*c+(tr1-tr2)*s); 02985 xcmplx(2,i1)=0.5f*((ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c); 02986 xcmplx(2,i2)=0.5f*(-(ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c); 02987 } 02988 } else { 02989 tr=xcmplx(1,1); 02990 ti=xcmplx(2,1); 02991 xcmplx(1,1)=0.5f*(tr+ti); 02992 xcmplx(2,1)=0.5f*(tr-ti); 02993 for (i=1; i<=n2; i++) { 02994 i1=i+1; 02995 i2=n-i+1; 02996 tr1=xcmplx(1,i1); 02997 tr2=xcmplx(1,i2); 02998 ti1=xcmplx(2,i1); 02999 ti2=xcmplx(2,i2); 03000 t=(cc*c-ss*s)+c; 03001 s=(cc*s+ss*c)+s; 03002 c=t; 03003 xcmplx(1,i1)=0.5f*((tr1+tr2)-(tr1-tr2)*s-(ti1+ti2)*c); 03004 xcmplx(1,i2)=0.5f*((tr1+tr2)+(tr1-tr2)*s+(ti1+ti2)*c); 03005 xcmplx(2,i1)=0.5f*((ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s); 03006 xcmplx(2,i2)=0.5f*(-(ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s); 03007 } 03008 fftc_q(&xcmplx(1,1),&xcmplx(2,1),nu1,-2); 03009 } 03010 }
int Util::file_lock_wait | ( | FILE * | file | ) | [static] |
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.
file | The file to be locked. |
Definition at line 171 of file util.cpp.
References LOGERR, and NullPointerException.
00172 { 00173 #ifdef WIN32 00174 return 1; 00175 #else 00176 00177 if (!file) { 00178 throw NullPointerException("Tried to lock NULL file"); 00179 } 00180 00181 int fdes = fileno(file); 00182 00183 struct flock fl; 00184 fl.l_type = F_WRLCK; 00185 fl.l_whence = SEEK_SET; 00186 fl.l_start = 0; 00187 fl.l_len = 0; 00188 #ifdef WIN32 00189 fl.l_pid = _getpid(); 00190 #else 00191 fl.l_pid = getpid(); 00192 #endif 00193 00194 #if defined __sgi 00195 fl.l_sysid = getpid(); 00196 #endif 00197 00198 int err = 0; 00199 if (fcntl(fdes, F_SETLKW, &fl) == -1) { 00200 LOGERR("file locking error! NFS problem?"); 00201 00202 int i = 0; 00203 for (i = 0; i < 5; i++) { 00204 if (fcntl(fdes, F_SETLKW, &fl) != -1) { 00205 break; 00206 } 00207 else { 00208 #ifdef WIN32 00209 Sleep(1000); 00210 #else 00211 sleep(1); 00212 #endif 00213 00214 } 00215 } 00216 if (i == 5) { 00217 LOGERR("Fatal file locking error"); 00218 err = 1; 00219 } 00220 } 00221 00222 return err; 00223 #endif 00224 }
void Util::find_max | ( | const float * | data, | |
size_t | nitems, | |||
float * | p_max_val, | |||
int * | p_max_index = 0 | |||
) | [static] |
Find the maximum value and (optional) its index in an array.
[in] | data | data array. |
[in] | nitems | number of items in the data array. |
[out] | p_max_val | pointer to the maximum value. |
[out] | p_max_index | pointer to index of the maximum value. |
Definition at line 848 of file util.cpp.
References Assert, max, and NullPointerException.
Referenced by EMAN::RotateTranslateFlipAlignerPawel::align(), EMAN::RotateTranslateAlignerPawel::align(), EMAN::RotationalAlignerIterative::align(), EMAN::RotatePrecenterAligner::align(), and EMAN::RotationalAligner::align_180_ambiguous().
00849 { 00850 Assert(nitems > 0); 00851 00852 if (!data || !max_val || !max_index) { 00853 throw NullPointerException("data/max_val/max_index"); 00854 } 00855 float max = -FLT_MAX; 00856 int m = 0; 00857 00858 for (size_t i = 0; i < nitems; i++) { 00859 if (data[i] > max) { 00860 max = data[i]; 00861 m = (int)i; 00862 } 00863 } 00864 00865 *max_val = (float)max; 00866 00867 if (max_index) { 00868 *max_index = m; 00869 } 00870 }
void Util::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 | |||
) | [static] |
Find the maximum value and (optional) its index, minimum value and (optional) its index in an array.
[in] | data | data array. |
[in] | nitems | number of items in the data array. |
[out] | p_max_val | pointer to the maximum value. |
[out] | p_min_val | pointer to the minimum value. |
[out] | p_max_index | pointer to index of the maximum value. |
[out] | p_min_index | pointer to index of the minimum value. |
Definition at line 872 of file util.cpp.
References Assert, max, min, and NullPointerException.
00875 { 00876 Assert(nitems > 0); 00877 00878 if (!data || !max_val || !min_val || !max_index || !min_index) { 00879 throw NullPointerException("data/max_val/min_val/max_index/min_index"); 00880 } 00881 float max = -FLT_MAX; 00882 float min = FLT_MAX; 00883 int max_i = 0; 00884 int min_i = 0; 00885 00886 for (size_t i = 0; i < nitems; i++) { 00887 if (data[i] > max) { 00888 max = data[i]; 00889 max_i = (int)i; 00890 } 00891 if (data[i] < min) { 00892 min = data[i]; 00893 min_i = (int)i; 00894 } 00895 } 00896 00897 *max_val = max; 00898 *min_val = min; 00899 00900 if (min_index) { 00901 *min_index = min_i; 00902 } 00903 00904 if (max_index) { 00905 *max_index = max_i; 00906 } 00907 00908 }
void Util::flip23 | ( | double * | x, | |
double * | y, | |||
double * | z, | |||
int * | key, | |||
int | k, | |||
int | len | |||
) | [static] |
Definition at line 7730 of file util_sparx.cpp.
References ENTERFUNC, and EXITFUNC.
Referenced by voronoi().
07731 { 07732 ENTERFUNC; 07733 int i = k; 07734 while( i == k ) i = rand()%len; 07735 std::swap(key[i], key[k]); 07736 std::swap(x[i], x[k]); 07737 std::swap(y[i], y[k]); 07738 std::swap(z[i], z[k]); 07739 EXITFUNC; 07740 }
void Util::flip_complex_phase | ( | float * | data, | |
size_t | n | |||
) | [static] |
flip the phase of a complex data array.
data | complex data array. | |
n | array size. |
Definition at line 116 of file util.cpp.
References Assert, and NullPointerException.
00117 { 00118 Assert(n > 0); 00119 00120 if (!data) { 00121 throw NullPointerException("pixel data array"); 00122 } 00123 00124 for (size_t i = 0; i < n; i += 2) { 00125 data[i + 1] *= -1; 00126 } 00127 }
void Util::flip_image | ( | float * | data, | |
size_t | nx, | |||
size_t | ny | |||
) | [static] |
Vertically flip the data of a 2D real image.
data | Data array of the 2D real image. | |
nx | Image Width. | |
ny | Image Height. |
Definition at line 251 of file util.cpp.
References Assert, and NullPointerException.
00252 { 00253 if (!data) { 00254 throw NullPointerException("image data array"); 00255 } 00256 Assert(nx > 0); 00257 Assert(ny > 0); 00258 00259 float *buf = new float[nx]; 00260 size_t row_size = nx * sizeof(float); 00261 00262 for (size_t i = 0; i < ny / 2; i++) { 00263 memcpy(buf, &data[i * nx], row_size); 00264 memcpy(&data[i * nx], &data[(ny - 1 - i) * nx], row_size); 00265 memcpy(&data[(ny - 1 - i) * nx], buf, row_size); 00266 } 00267 00268 if( buf ) 00269 { 00270 delete[]buf; 00271 buf = 0; 00272 } 00273 }
void Util::Frngs | ( | EMData * | circ, | |
vector< int > | numr | |||
) | [static] |
This function conducts the Single Precision Fourier Transform for a set of rings.
Definition at line 3098 of file util_sparx.cpp.
References circ, fftr_q(), EMAN::EMData::get_data(), log(), and numr.
Referenced by ali2d_ccf_list(), hans(), 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().
03098 { 03099 int nring = numr.size()/3; 03100 float *circ = circp->get_data(); 03101 int i, l; 03102 for (i=1; i<=nring;i++) { 03103 03104 #ifdef _WIN32 03105 l = (int)( log((float)numr(3,i))/log(2.0f) ); 03106 #else 03107 l=(int)(log2(numr(3,i))); 03108 #endif //_WIN32 03109 03110 fftr_q(&circ(numr(2,i)),l); 03111 } 03112 }
void Util::Frngs_inv | ( | EMData * | circ, | |
vector< int > | numr | |||
) | [static] |
This function conducts the Single Precision Inverse Fourier Transform for a set of rings.
Definition at line 3114 of file util_sparx.cpp.
References circ, fftr_q(), EMAN::EMData::get_data(), log(), and numr.
03114 { 03115 int nring = numr.size()/3; 03116 float *circ = circp->get_data(); 03117 int i, l; 03118 for (i=1; i<=nring;i++) { 03119 03120 #ifdef _WIN32 03121 l = (int)( log((float)numr(3,i))/log(2.0f) ); 03122 #else 03123 l=(int)(log2(numr(3,i))); 03124 #endif //_WIN32 03125 03126 fftr_q(&circ(numr(2,i)),-l); 03127 } 03128 }
static int EMAN::Util::generatesubmax | ( | int * | argParts, | |
int * | Indices, | |||
int * | dimClasses, | |||
int | nParts, | |||
int | K, | |||
int | T, | |||
int | n_guesses, | |||
int | LARGEST_CLASS | |||
) | [static] |
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 20164 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().
20165 { 20166 int nx = mg->get_xsize(); 20167 int ny = mg->get_ysize(); 20168 int nz = mg->get_zsize(); 20169 20170 EMData* visited = new EMData(); 20171 visited->set_size( nx, ny, nz ); 20172 visited->to_zero(); 20173 int grpid = 0; 20174 int maxgrp = 0; 20175 int maxsize = 0; 20176 for( int iz=0; iz < nz; ++iz ) { 20177 for( int iy=0; iy < ny; ++iy ) { 20178 for( int ix=0; ix < nx; ++ix ) { 20179 if( (*mg)(ix, iy, iz)==0.0 ) continue; 20180 20181 if( (*visited)(ix, iy, iz) > 0.0 ) { 20182 // visited before, must be in other group. 20183 continue; 20184 } 20185 20186 grpid++; 20187 int grpsize = find_group( ix, iy, iz, grpid, mg, visited ); 20188 if( grpsize > maxsize ) { 20189 maxsize = grpsize; 20190 maxgrp = grpid; 20191 } 20192 } 20193 } 20194 } 20195 20196 Assert( maxgrp > 0 ); 20197 20198 int npoint = 0; 20199 EMData* result = new EMData(); 20200 result->set_size( nx, ny, nz ); 20201 result->to_zero(); 20202 20203 for( int iz=0; iz < nz; ++iz ) { 20204 for( int iy=0; iy < ny; ++iy ) { 20205 for( int ix=0; ix < nx; ++ix ) { 20206 if( (*visited)(ix, iy, iz)==maxgrp ) { 20207 (*result)(ix,iy,iz) = 1.0; 20208 npoint++; 20209 } 20210 } 20211 } 20212 } 20213 20214 Assert( npoint==maxsize ); 20215 delete visited; 20216 return result; 20217 20218 }
string Util::get_filename_ext | ( | const string & | filename | ) | [static] |
Get a filename's extension.
[in] | filename | A given filename. |
Definition at line 526 of file util.cpp.
Referenced by EMAN::EMUtil::fast_get_image_type(), EMAN::EMUtil::get_image_type(), and EMAN::EMUtil::is_valid_filename().
00527 { 00528 if (filename == "") { 00529 return ""; 00530 } 00531 00532 string result = ""; 00533 const char *ext = strrchr(filename.c_str(), '.'); 00534 if (ext) { 00535 ext++; 00536 result = string(ext); 00537 } 00538 return result; 00539 }
float Util::get_frand | ( | double | low, | |
double | high | |||
) | [static] |
Get a float random number between low and high, [low, high).
[in] | low | The lower bound of the random number. |
[in] | high | The upper bound of the random number. |
Definition at line 741 of file util.cpp.
References EMAN::Randnum::get_frand(), and EMAN::Randnum::Instance().
00742 { 00743 Randnum* randnum = Randnum::Instance(); 00744 return randnum->get_frand(lo, hi); 00745 }
float Util::get_frand | ( | float | low, | |
float | high | |||
) | [static] |
Get a float random number between low and high, [low, high).
[in] | low | The lower bound of the random number. |
[in] | high | The upper bound of the random number. |
Definition at line 735 of file util.cpp.
References EMAN::Randnum::get_frand(), and EMAN::Randnum::Instance().
00736 { 00737 Randnum* randnum = Randnum::Instance(); 00738 return randnum->get_frand(lo, hi); 00739 }
float Util::get_frand | ( | int | low, | |
int | high | |||
) | [static] |
Get a float random number between low and high, [low, high).
[in] | low | The lower bound of the random number. |
[in] | high | The upper bound of the random number. |
Definition at line 730 of file util.cpp.
Referenced by EMAN::OrientationGenerator::add_orientation(), ali2d_ccf_list(), EMAN::RandomOrientationGenerator::gen_orientations(), move_points(), EMAN::KmeansSegmentProcessor::process(), EMAN::TestImageFourierNoiseProfile::process_inplace(), EMAN::TestImageFourierNoiseGaussian::process_inplace(), EMAN::LowpassRandomPhaseProcessor::process_inplace(), and EMAN::PointArray::set_from_density_map().
00731 { 00732 return get_frand((float)lo, (float)hi); 00733 }
float Util::get_gauss_rand | ( | float | mean, | |
float | sigma | |||
) | [static] |
Get a Gaussian random number.
[in] | mean | The gaussian mean |
[in] | sigma | The gaussian sigma |
Definition at line 842 of file util.cpp.
References EMAN::Randnum::get_gauss_rand(), and EMAN::Randnum::Instance().
Referenced by EMAN::EmanOrientationGenerator::gen_orientations(), and EMAN::MaskNoiseProcessor::process_dist_pixel().
00843 { 00844 Randnum* randnum = Randnum::Instance(); 00845 return randnum->get_gauss_rand(mean, sigma); 00846 }
int Util::get_irand | ( | int | low, | |
int | high | |||
) | [static] |
Get an integer random number between low and high, [low, high].
[in] | low | The lower bound of the random number. |
[in] | high | The upper bound of the random number. |
Definition at line 724 of file util.cpp.
References EMAN::Randnum::get_irand(), and EMAN::Randnum::Instance().
Referenced by EMAN::KMeansAnalyzer::analyze(), cluster_pairwise(), hans(), move_points(), and EMAN::KMeansAnalyzer::reseed().
00725 { 00726 Randnum* randnum = Randnum::Instance(); 00727 return randnum->get_irand(lo, hi); 00728 }
string Util::get_line_from_string | ( | char ** | str | ) | [static] |
Extract a single line from a multi-line string.
The line delimiter is '
'. The multi-line string moves forward one line. If it is the last line, move to the end of the string.
[in,out] | str | A multiple-line string. |
Definition at line 301 of file util.cpp.
References NullPointerException.
Referenced by EMAN::XplorIO::is_valid(), and EMAN::SitusIO::is_valid().
00302 { 00303 if (!slines || !(*slines)) { 00304 throw NullPointerException("Null string"); 00305 } 00306 00307 string result = ""; 00308 char *str = *slines; 00309 00310 while (*str != '\n' && *str != '\0') { 00311 result.push_back(*str); 00312 str++; 00313 } 00314 if (*str != '\0') { 00315 str++; 00316 } 00317 *slines = str; 00318 00319 return result; 00320 }
static float EMAN::Util::get_max | ( | float | f1, | |
float | f2, | |||
float | f3, | |||
float | f4 | |||
) | [inline, static] |
static float EMAN::Util::get_max | ( | float | f1, | |
float | f2, | |||
float | f3 | |||
) | [inline, static] |
static float EMAN::Util::get_max | ( | float | f1, | |
float | f2 | |||
) | [inline, static] |
Get the maximum of 2 numbers.
[in] | f1 | The first number. |
[in] | f2 | The second number. |
Definition at line 1899 of file util.h.
Referenced by EMAN::MaxValProjector::project3d(), and EMAN::PawelProjector::project3d().
static float EMAN::Util::get_min | ( | float | f1, | |
float | f2, | |||
float | f3, | |||
float | f4 | |||
) | [inline, static] |
static float EMAN::Util::get_min | ( | float | f1, | |
float | f2, | |||
float | f3 | |||
) | [inline, static] |
static float EMAN::Util::get_min | ( | float | f1, | |
float | f2 | |||
) | [inline, static] |
static int EMAN::Util::get_min | ( | int | f1, | |
int | f2, | |||
int | f3 | |||
) | [inline, static] |
static int EMAN::Util::get_min | ( | int | f1, | |
int | f2 | |||
) | [inline, static] |
Get the minimum of 2 numbers.
[in] | f1 | The first number. |
[in] | f2 | The second number. |
Definition at line 1822 of file util.h.
Referenced by EMAN::PawelProjector::backproject3d(), EMAN::ChaoProjector::backproject3d(), EMAN::ChaoProjector::project3d(), and EMAN::FourierGriddingProjector::project3d().
float Util::get_pixel_conv_new | ( | int | nx, | |
int | ny, | |||
int | nz, | |||
float | delx, | |||
float | dely, | |||
float | delz, | |||
float * | data, | |||
Util::KaiserBessel & | kb | |||
) | [static] |
Definition at line 781 of file util_sparx.cpp.
References EMAN::Util::KaiserBessel::get_window_size(), EMAN::Util::KaiserBessel::i0win_tab(), restrict1(), and round().
Referenced by Polar2Dmi().
00781 { 00782 int K = kb.get_window_size(); 00783 int kbmin = -K/2; 00784 int kbmax = -kbmin; 00785 int kbc = kbmax+1; 00786 00787 float pixel =0.0f; 00788 float w=0.0f; 00789 00790 delx = restrict1(delx, nx); 00791 int inxold = int(round(delx)); 00792 if ( ny < 2 ) { //1D 00793 float tablex1 = kb.i0win_tab(delx-inxold+3); 00794 float tablex2 = kb.i0win_tab(delx-inxold+2); 00795 float tablex3 = kb.i0win_tab(delx-inxold+1); 00796 float tablex4 = kb.i0win_tab(delx-inxold); 00797 float tablex5 = kb.i0win_tab(delx-inxold-1); 00798 float tablex6 = kb.i0win_tab(delx-inxold-2); 00799 float tablex7 = kb.i0win_tab(delx-inxold-3); 00800 00801 int x1, x2, x3, x4, x5, x6, x7; 00802 00803 if ( inxold <= kbc || inxold >=nx-kbc-2 ) { 00804 x1 = (inxold-3+nx)%nx; 00805 x2 = (inxold-2+nx)%nx; 00806 x3 = (inxold-1+nx)%nx; 00807 x4 = (inxold +nx)%nx; 00808 x5 = (inxold+1+nx)%nx; 00809 x6 = (inxold+2+nx)%nx; 00810 x7 = (inxold+3+nx)%nx; 00811 } else { 00812 x1 = inxold-3; 00813 x2 = inxold-2; 00814 x3 = inxold-1; 00815 x4 = inxold; 00816 x5 = inxold+1; 00817 x6 = inxold+2; 00818 x7 = inxold+3; 00819 } 00820 00821 pixel = data[x1]*tablex1 + data[x2]*tablex2 + data[x3]*tablex3 + 00822 data[x4]*tablex4 + data[x5]*tablex5 + data[x6]*tablex6 + 00823 data[x7]*tablex7 ; 00824 00825 w = tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7; 00826 } else if ( nz < 2 ) { // 2D 00827 dely = restrict1(dely, ny); 00828 int inyold = int(round(dely)); 00829 float tablex1 = kb.i0win_tab(delx-inxold+3); 00830 float tablex2 = kb.i0win_tab(delx-inxold+2); 00831 float tablex3 = kb.i0win_tab(delx-inxold+1); 00832 float tablex4 = kb.i0win_tab(delx-inxold); 00833 float tablex5 = kb.i0win_tab(delx-inxold-1); 00834 float tablex6 = kb.i0win_tab(delx-inxold-2); 00835 float tablex7 = kb.i0win_tab(delx-inxold-3); 00836 00837 float tabley1 = kb.i0win_tab(dely-inyold+3); 00838 float tabley2 = kb.i0win_tab(dely-inyold+2); 00839 float tabley3 = kb.i0win_tab(dely-inyold+1); 00840 float tabley4 = kb.i0win_tab(dely-inyold); 00841 float tabley5 = kb.i0win_tab(dely-inyold-1); 00842 float tabley6 = kb.i0win_tab(dely-inyold-2); 00843 float tabley7 = kb.i0win_tab(dely-inyold-3); 00844 00845 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7; 00846 00847 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 ) { 00848 x1 = (inxold-3+nx)%nx; 00849 x2 = (inxold-2+nx)%nx; 00850 x3 = (inxold-1+nx)%nx; 00851 x4 = (inxold +nx)%nx; 00852 x5 = (inxold+1+nx)%nx; 00853 x6 = (inxold+2+nx)%nx; 00854 x7 = (inxold+3+nx)%nx; 00855 00856 y1 = ((inyold-3+ny)%ny)*nx; 00857 y2 = ((inyold-2+ny)%ny)*nx; 00858 y3 = ((inyold-1+ny)%ny)*nx; 00859 y4 = ((inyold +ny)%ny)*nx; 00860 y5 = ((inyold+1+ny)%ny)*nx; 00861 y6 = ((inyold+2+ny)%ny)*nx; 00862 y7 = ((inyold+3+ny)%ny)*nx; 00863 } else { 00864 x1 = inxold-3; 00865 x2 = inxold-2; 00866 x3 = inxold-1; 00867 x4 = inxold; 00868 x5 = inxold+1; 00869 x6 = inxold+2; 00870 x7 = inxold+3; 00871 00872 y1 = (inyold-3)*nx; 00873 y2 = (inyold-2)*nx; 00874 y3 = (inyold-1)*nx; 00875 y4 = inyold*nx; 00876 y5 = (inyold+1)*nx; 00877 y6 = (inyold+2)*nx; 00878 y7 = (inyold+3)*nx; 00879 } 00880 00881 pixel = ( data[x1+y1]*tablex1 + data[x2+y1]*tablex2 + data[x3+y1]*tablex3 + 00882 data[x4+y1]*tablex4 + data[x5+y1]*tablex5 + data[x6+y1]*tablex6 + 00883 data[x7+y1]*tablex7 ) * tabley1 + 00884 ( data[x1+y2]*tablex1 + data[x2+y2]*tablex2 + data[x3+y2]*tablex3 + 00885 data[x4+y2]*tablex4 + data[x5+y2]*tablex5 + data[x6+y2]*tablex6 + 00886 data[x7+y2]*tablex7 ) * tabley2 + 00887 ( data[x1+y3]*tablex1 + data[x2+y3]*tablex2 + data[x3+y3]*tablex3 + 00888 data[x4+y3]*tablex4 + data[x5+y3]*tablex5 + data[x6+y3]*tablex6 + 00889 data[x7+y3]*tablex7 ) * tabley3 + 00890 ( data[x1+y4]*tablex1 + data[x2+y4]*tablex2 + data[x3+y4]*tablex3 + 00891 data[x4+y4]*tablex4 + data[x5+y4]*tablex5 + data[x6+y4]*tablex6 + 00892 data[x7+y4]*tablex7 ) * tabley4 + 00893 ( data[x1+y5]*tablex1 + data[x2+y5]*tablex2 + data[x3+y5]*tablex3 + 00894 data[x4+y5]*tablex4 + data[x5+y5]*tablex5 + data[x6+y5]*tablex6 + 00895 data[x7+y5]*tablex7 ) * tabley5 + 00896 ( data[x1+y6]*tablex1 + data[x2+y6]*tablex2 + data[x3+y6]*tablex3 + 00897 data[x4+y6]*tablex4 + data[x5+y6]*tablex5 + data[x6+y6]*tablex6 + 00898 data[x7+y6]*tablex7 ) * tabley6 + 00899 ( data[x1+y7]*tablex1 + data[x2+y7]*tablex2 + data[x3+y7]*tablex3 + 00900 data[x4+y7]*tablex4 + data[x5+y7]*tablex5 + data[x6+y7]*tablex6 + 00901 data[x7+y7]*tablex7 ) * tabley7; 00902 00903 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) * 00904 (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7); 00905 } else { // 3D 00906 dely = restrict1(dely, ny); 00907 int inyold = int(Util::round(dely)); 00908 delz = restrict1(delz, nz); 00909 int inzold = int(Util::round(delz)); 00910 00911 float tablex1 = kb.i0win_tab(delx-inxold+3); 00912 float tablex2 = kb.i0win_tab(delx-inxold+2); 00913 float tablex3 = kb.i0win_tab(delx-inxold+1); 00914 float tablex4 = kb.i0win_tab(delx-inxold); 00915 float tablex5 = kb.i0win_tab(delx-inxold-1); 00916 float tablex6 = kb.i0win_tab(delx-inxold-2); 00917 float tablex7 = kb.i0win_tab(delx-inxold-3); 00918 00919 float tabley1 = kb.i0win_tab(dely-inyold+3); 00920 float tabley2 = kb.i0win_tab(dely-inyold+2); 00921 float tabley3 = kb.i0win_tab(dely-inyold+1); 00922 float tabley4 = kb.i0win_tab(dely-inyold); 00923 float tabley5 = kb.i0win_tab(dely-inyold-1); 00924 float tabley6 = kb.i0win_tab(dely-inyold-2); 00925 float tabley7 = kb.i0win_tab(dely-inyold-3); 00926 00927 float tablez1 = kb.i0win_tab(delz-inzold+3); 00928 float tablez2 = kb.i0win_tab(delz-inzold+2); 00929 float tablez3 = kb.i0win_tab(delz-inzold+1); 00930 float tablez4 = kb.i0win_tab(delz-inzold); 00931 float tablez5 = kb.i0win_tab(delz-inzold-1); 00932 float tablez6 = kb.i0win_tab(delz-inzold-2); 00933 float tablez7 = kb.i0win_tab(delz-inzold-3); 00934 00935 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7, z1, z2, z3, z4, z5, z6, z7; 00936 00937 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 || inzold <= kbc || inzold >= nz-kbc-2 ) { 00938 x1 = (inxold-3+nx)%nx; 00939 x2 = (inxold-2+nx)%nx; 00940 x3 = (inxold-1+nx)%nx; 00941 x4 = (inxold +nx)%nx; 00942 x5 = (inxold+1+nx)%nx; 00943 x6 = (inxold+2+nx)%nx; 00944 x7 = (inxold+3+nx)%nx; 00945 00946 y1 = ((inyold-3+ny)%ny)*nx; 00947 y2 = ((inyold-2+ny)%ny)*nx; 00948 y3 = ((inyold-1+ny)%ny)*nx; 00949 y4 = ((inyold +ny)%ny)*nx; 00950 y5 = ((inyold+1+ny)%ny)*nx; 00951 y6 = ((inyold+2+ny)%ny)*nx; 00952 y7 = ((inyold+3+ny)%ny)*nx; 00953 00954 z1 = ((inzold-3+nz)%nz)*nx*ny; 00955 z2 = ((inzold-2+nz)%nz)*nx*ny; 00956 z3 = ((inzold-1+nz)%nz)*nx*ny; 00957 z4 = ((inzold +nz)%nz)*nx*ny; 00958 z5 = ((inzold+1+nz)%nz)*nx*ny; 00959 z6 = ((inzold+2+nz)%nz)*nx*ny; 00960 z7 = ((inzold+3+nz)%nz)*nx*ny; 00961 } else { 00962 x1 = inxold-3; 00963 x2 = inxold-2; 00964 x3 = inxold-1; 00965 x4 = inxold; 00966 x5 = inxold+1; 00967 x6 = inxold+2; 00968 x7 = inxold+3; 00969 00970 y1 = (inyold-3)*nx; 00971 y2 = (inyold-2)*nx; 00972 y3 = (inyold-1)*nx; 00973 y4 = inyold*nx; 00974 y5 = (inyold+1)*nx; 00975 y6 = (inyold+2)*nx; 00976 y7 = (inyold+3)*nx; 00977 00978 z1 = (inzold-3)*nx*ny; 00979 z2 = (inzold-2)*nx*ny; 00980 z3 = (inzold-1)*nx*ny; 00981 z4 = inzold*nx*ny; 00982 z5 = (inzold+1)*nx*ny; 00983 z6 = (inzold+2)*nx*ny; 00984 z7 = (inzold+3)*nx*ny; 00985 } 00986 00987 pixel = ( ( data[x1+y1+z1]*tablex1 + data[x2+y1+z1]*tablex2 + data[x3+y1+z1]*tablex3 + 00988 data[x4+y1+z1]*tablex4 + data[x5+y1+z1]*tablex5 + data[x6+y1+z1]*tablex6 + 00989 data[x7+y1+z1]*tablex7 ) * tabley1 + 00990 ( data[x1+y2+z1]*tablex1 + data[x2+y2+z1]*tablex2 + data[x3+y2+z1]*tablex3 + 00991 data[x4+y2+z1]*tablex4 + data[x5+y2+z1]*tablex5 + data[x6+y2+z1]*tablex6 + 00992 data[x7+y2+z1]*tablex7 ) * tabley2 + 00993 ( data[x1+y3+z1]*tablex1 + data[x2+y3+z1]*tablex2 + data[x3+y3+z1]*tablex3 + 00994 data[x4+y3+z1]*tablex4 + data[x5+y3+z1]*tablex5 + data[x6+y3+z1]*tablex6 + 00995 data[x7+y3+z1]*tablex7 ) * tabley3 + 00996 ( data[x1+y4+z1]*tablex1 + data[x2+y4+z1]*tablex2 + data[x3+y4+z1]*tablex3 + 00997 data[x4+y4+z1]*tablex4 + data[x5+y4+z1]*tablex5 + data[x6+y4+z1]*tablex6 + 00998 data[x7+y4+z1]*tablex7 ) * tabley4 + 00999 ( data[x1+y5+z1]*tablex1 + data[x2+y5+z1]*tablex2 + data[x3+y5+z1]*tablex3 + 01000 data[x4+y5+z1]*tablex4 + data[x5+y5+z1]*tablex5 + data[x6+y5+z1]*tablex6 + 01001 data[x7+y5+z1]*tablex7 ) * tabley5 + 01002 ( data[x1+y6+z1]*tablex1 + data[x2+y6+z1]*tablex2 + data[x3+y6+z1]*tablex3 + 01003 data[x4+y6+z1]*tablex4 + data[x5+y6+z1]*tablex5 + data[x6+y6+z1]*tablex6 + 01004 data[x7+y6+z1]*tablex7 ) * tabley6 + 01005 ( data[x1+y7+z1]*tablex1 + data[x2+y7+z1]*tablex2 + data[x3+y7+z1]*tablex3 + 01006 data[x4+y7+z1]*tablex4 + data[x5+y7+z1]*tablex5 + data[x6+y7+z1]*tablex6 + 01007 data[x7+y7+z1]*tablex7 ) * tabley7 ) *tablez1 + 01008 ( ( data[x1+y1+z2]*tablex1 + data[x2+y1+z2]*tablex2 + data[x3+y1+z2]*tablex3 + 01009 data[x4+y1+z2]*tablex4 + data[x5+y1+z2]*tablex5 + data[x6+y1+z2]*tablex6 + 01010 data[x7+y1+z2]*tablex7 ) * tabley1 + 01011 ( data[x1+y2+z2]*tablex1 + data[x2+y2+z2]*tablex2 + data[x3+y2+z2]*tablex3 + 01012 data[x4+y2+z2]*tablex4 + data[x5+y2+z2]*tablex5 + data[x6+y2+z2]*tablex6 + 01013 data[x7+y2+z2]*tablex7 ) * tabley2 + 01014 ( data[x1+y3+z2]*tablex1 + data[x2+y3+z2]*tablex2 + data[x3+y3+z2]*tablex3 + 01015 data[x4+y3+z2]*tablex4 + data[x5+y3+z2]*tablex5 + data[x6+y3+z2]*tablex6 + 01016 data[x7+y3+z2]*tablex7 ) * tabley3 + 01017 ( data[x1+y4+z2]*tablex1 + data[x2+y4+z2]*tablex2 + data[x3+y4+z2]*tablex3 + 01018 data[x4+y4+z2]*tablex4 + data[x5+y4+z2]*tablex5 + data[x6+y4+z2]*tablex6 + 01019 data[x7+y4+z2]*tablex7 ) * tabley4 + 01020 ( data[x1+y5+z2]*tablex1 + data[x2+y5+z2]*tablex2 + data[x3+y5+z2]*tablex3 + 01021 data[x4+y5+z2]*tablex4 + data[x5+y5+z2]*tablex5 + data[x6+y5+z2]*tablex6 + 01022 data[x7+y5+z2]*tablex7 ) * tabley5 + 01023 ( data[x1+y6+z2]*tablex1 + data[x2+y6+z2]*tablex2 + data[x3+y6+z2]*tablex3 + 01024 data[x4+y6+z2]*tablex4 + data[x5+y6+z2]*tablex5 + data[x6+y6+z2]*tablex6 + 01025 data[x7+y6+z2]*tablex7 ) * tabley6 + 01026 ( data[x1+y7+z2]*tablex1 + data[x2+y7+z2]*tablex2 + data[x3+y7+z2]*tablex3 + 01027 data[x4+y7+z2]*tablex4 + data[x5+y7+z2]*tablex5 + data[x6+y7+z2]*tablex6 + 01028 data[x7+y7+z2]*tablex7 ) * tabley7 ) *tablez2 + 01029 ( ( data[x1+y1+z3]*tablex1 + data[x2+y1+z3]*tablex2 + data[x3+y1+z3]*tablex3 + 01030 data[x4+y1+z3]*tablex4 + data[x5+y1+z3]*tablex5 + data[x6+y1+z3]*tablex6 + 01031 data[x7+y1+z3]*tablex7 ) * tabley1 + 01032 ( data[x1+y2+z3]*tablex1 + data[x2+y2+z3]*tablex2 + data[x3+y2+z3]*tablex3 + 01033 data[x4+y2+z3]*tablex4 + data[x5+y2+z3]*tablex5 + data[x6+y2+z3]*tablex6 + 01034 data[x7+y2+z3]*tablex7 ) * tabley2 + 01035 ( data[x1+y3+z3]*tablex1 + data[x2+y3+z3]*tablex2 + data[x3+y3+z3]*tablex3 + 01036 data[x4+y3+z3]*tablex4 + data[x5+y3+z3]*tablex5 + data[x6+y3+z3]*tablex6 + 01037 data[x7+y3+z3]*tablex7 ) * tabley3 + 01038 ( data[x1+y4+z3]*tablex1 + data[x2+y4+z3]*tablex2 + data[x3+y4+z3]*tablex3 + 01039 data[x4+y4+z3]*tablex4 + data[x5+y4+z3]*tablex5 + data[x6+y4+z3]*tablex6 + 01040 data[x7+y4+z3]*tablex7 ) * tabley4 + 01041 ( data[x1+y5+z3]*tablex1 + data[x2+y5+z3]*tablex2 + data[x3+y5+z3]*tablex3 + 01042 data[x4+y5+z3]*tablex4 + data[x5+y5+z3]*tablex5 + data[x6+y5+z3]*tablex6 + 01043 data[x7+y5+z3]*tablex7 ) * tabley5 + 01044 ( data[x1+y6+z3]*tablex1 + data[x2+y6+z3]*tablex2 + data[x3+y6+z3]*tablex3 + 01045 data[x4+y6+z3]*tablex4 + data[x5+y6+z3]*tablex5 + data[x6+y6+z3]*tablex6 + 01046 data[x7+y6+z3]*tablex7 ) * tabley6 + 01047 ( data[x1+y7+z3]*tablex1 + data[x2+y7+z3]*tablex2 + data[x3+y7+z3]*tablex3 + 01048 data[x4+y7+z3]*tablex4 + data[x5+y7+z3]*tablex5 + data[x6+y7+z3]*tablex6 + 01049 data[x7+y7+z3]*tablex7 ) * tabley7 ) *tablez3 + 01050 ( ( data[x1+y1+z4]*tablex1 + data[x2+y1+z4]*tablex2 + data[x3+y1+z4]*tablex3 + 01051 data[x4+y1+z4]*tablex4 + data[x5+y1+z4]*tablex5 + data[x6+y1+z4]*tablex6 + 01052 data[x7+y1+z4]*tablex7 ) * tabley1 + 01053 ( data[x1+y2+z4]*tablex1 + data[x2+y2+z4]*tablex2 + data[x3+y2+z4]*tablex3 + 01054 data[x4+y2+z4]*tablex4 + data[x5+y2+z4]*tablex5 + data[x6+y2+z4]*tablex6 + 01055 data[x7+y2+z4]*tablex7 ) * tabley2 + 01056 ( data[x1+y3+z4]*tablex1 + data[x2+y3+z4]*tablex2 + data[x3+y3+z4]*tablex3 + 01057 data[x4+y3+z4]*tablex4 + data[x5+y3+z4]*tablex5 + data[x6+y3+z4]*tablex6 + 01058 data[x7+y3+z4]*tablex7 ) * tabley3 + 01059 ( data[x1+y4+z4]*tablex1 + data[x2+y4+z4]*tablex2 + data[x3+y4+z4]*tablex3 + 01060 data[x4+y4+z4]*tablex4 + data[x5+y4+z4]*tablex5 + data[x6+y4+z4]*tablex6 + 01061 data[x7+y4+z4]*tablex7 ) * tabley4 + 01062 ( data[x1+y5+z4]*tablex1 + data[x2+y5+z4]*tablex2 + data[x3+y5+z4]*tablex3 + 01063 data[x4+y5+z4]*tablex4 + data[x5+y5+z4]*tablex5 + data[x6+y5+z4]*tablex6 + 01064 data[x7+y5+z4]*tablex7 ) * tabley5 + 01065 ( data[x1+y6+z4]*tablex1 + data[x2+y6+z4]*tablex2 + data[x3+y6+z4]*tablex3 + 01066 data[x4+y6+z4]*tablex4 + data[x5+y6+z4]*tablex5 + data[x6+y6+z4]*tablex6 + 01067 data[x7+y6+z4]*tablex7 ) * tabley6 + 01068 ( data[x1+y7+z4]*tablex1 + data[x2+y7+z4]*tablex2 + data[x3+y7+z4]*tablex3 + 01069 data[x4+y7+z4]*tablex4 + data[x5+y7+z4]*tablex5 + data[x6+y7+z4]*tablex6 + 01070 data[x7+y7+z4]*tablex7 ) * tabley7 ) *tablez4 + 01071 ( ( data[x1+y1+z5]*tablex1 + data[x2+y1+z5]*tablex2 + data[x3+y1+z5]*tablex3 + 01072 data[x4+y1+z5]*tablex4 + data[x5+y1+z5]*tablex5 + data[x6+y1+z5]*tablex6 + 01073 data[x7+y1+z5]*tablex7 ) * tabley1 + 01074 ( data[x1+y2+z5]*tablex1 + data[x2+y2+z5]*tablex2 + data[x3+y2+z5]*tablex3 + 01075 data[x4+y2+z5]*tablex4 + data[x5+y2+z5]*tablex5 + data[x6+y2+z5]*tablex6 + 01076 data[x7+y2+z5]*tablex7 ) * tabley2 + 01077 ( data[x1+y3+z5]*tablex1 + data[x2+y3+z5]*tablex2 + data[x3+y3+z5]*tablex3 + 01078 data[x4+y3+z5]*tablex4 + data[x5+y3+z5]*tablex5 + data[x6+y3+z5]*tablex6 + 01079 data[x7+y3+z5]*tablex7 ) * tabley3 + 01080 ( data[x1+y4+z5]*tablex1 + data[x2+y4+z5]*tablex2 + data[x3+y4+z5]*tablex3 + 01081 data[x4+y4+z5]*tablex4 + data[x5+y4+z5]*tablex5 + data[x6+y4+z5]*tablex6 + 01082 data[x7+y4+z5]*tablex7 ) * tabley4 + 01083 ( data[x1+y5+z5]*tablex1 + data[x2+y5+z5]*tablex2 + data[x3+y5+z5]*tablex3 + 01084 data[x4+y5+z5]*tablex4 + data[x5+y5+z5]*tablex5 + data[x6+y5+z5]*tablex6 + 01085 data[x7+y5+z5]*tablex7 ) * tabley5 + 01086 ( data[x1+y6+z5]*tablex1 + data[x2+y6+z5]*tablex2 + data[x3+y6+z5]*tablex3 + 01087 data[x4+y6+z5]*tablex4 + data[x5+y6+z5]*tablex5 + data[x6+y6+z5]*tablex6 + 01088 data[x7+y6+z5]*tablex7 ) * tabley6 + 01089 ( data[x1+y7+z5]*tablex1 + data[x2+y7+z5]*tablex2 + data[x3+y7+z5]*tablex3 + 01090 data[x4+y7+z5]*tablex4 + data[x5+y7+z5]*tablex5 + data[x6+y7+z5]*tablex6 + 01091 data[x7+y7+z5]*tablex7 ) * tabley7 ) *tablez5 + 01092 ( ( data[x1+y1+z6]*tablex1 + data[x2+y1+z6]*tablex2 + data[x3+y1+z6]*tablex3 + 01093 data[x4+y1+z6]*tablex4 + data[x5+y1+z6]*tablex5 + data[x6+y1+z6]*tablex6 + 01094 data[x7+y1+z6]*tablex7 ) * tabley1 + 01095 ( data[x1+y2+z6]*tablex1 + data[x2+y2+z6]*tablex2 + data[x3+y2+z6]*tablex3 + 01096 data[x4+y2+z6]*tablex4 + data[x5+y2+z6]*tablex5 + data[x6+y2+z6]*tablex6 + 01097 data[x7+y2+z6]*tablex7 ) * tabley2 + 01098 ( data[x1+y3+z6]*tablex1 + data[x2+y3+z6]*tablex2 + data[x3+y3+z6]*tablex3 + 01099 data[x4+y3+z6]*tablex4 + data[x5+y3+z6]*tablex5 + data[x6+y3+z6]*tablex6 + 01100 data[x7+y3+z6]*tablex7 ) * tabley3 + 01101 ( data[x1+y4+z6]*tablex1 + data[x2+y4+z6]*tablex2 + data[x3+y4+z6]*tablex3 + 01102 data[x4+y4+z6]*tablex4 + data[x5+y4+z6]*tablex5 + data[x6+y4+z6]*tablex6 + 01103 data[x7+y4+z6]*tablex7 ) * tabley4 + 01104 ( data[x1+y5+z6]*tablex1 + data[x2+y5+z6]*tablex2 + data[x3+y5+z6]*tablex3 + 01105 data[x4+y5+z6]*tablex4 + data[x5+y5+z6]*tablex5 + data[x6+y5+z6]*tablex6 + 01106 data[x7+y5+z6]*tablex7 ) * tabley5 + 01107 ( data[x1+y6+z6]*tablex1 + data[x2+y6+z6]*tablex2 + data[x3+y6+z6]*tablex3 + 01108 data[x4+y6+z6]*tablex4 + data[x5+y6+z6]*tablex5 + data[x6+y6+z6]*tablex6 + 01109 data[x7+y6+z6]*tablex7 ) * tabley6 + 01110 ( data[x1+y7+z6]*tablex1 + data[x2+y7+z6]*tablex2 + data[x3+y7+z6]*tablex3 + 01111 data[x4+y7+z6]*tablex4 + data[x5+y7+z6]*tablex5 + data[x6+y7+z6]*tablex6 + 01112 data[x7+y7+z6]*tablex7 ) * tabley7 ) *tablez6 + 01113 ( ( data[x1+y1+z7]*tablex1 + data[x2+y1+z7]*tablex2 + data[x3+y1+z7]*tablex3 + 01114 data[x4+y1+z7]*tablex4 + data[x5+y1+z7]*tablex5 + data[x6+y1+z7]*tablex6 + 01115 data[x7+y1+z7]*tablex7 ) * tabley1 + 01116 ( data[x1+y2+z7]*tablex1 + data[x2+y2+z7]*tablex2 + data[x3+y2+z7]*tablex3 + 01117 data[x4+y2+z7]*tablex4 + data[x5+y2+z7]*tablex5 + data[x6+y2+z7]*tablex6 + 01118 data[x7+y2+z7]*tablex7 ) * tabley2 + 01119 ( data[x1+y3+z7]*tablex1 + data[x2+y3+z7]*tablex2 + data[x3+y3+z7]*tablex3 + 01120 data[x4+y3+z7]*tablex4 + data[x5+y3+z7]*tablex5 + data[x6+y3+z7]*tablex6 + 01121 data[x7+y3+z7]*tablex7 ) * tabley3 + 01122 ( data[x1+y4+z7]*tablex1 + data[x2+y4+z7]*tablex2 + data[x3+y4+z7]*tablex3 + 01123 data[x4+y4+z7]*tablex4 + data[x5+y4+z7]*tablex5 + data[x6+y4+z7]*tablex6 + 01124 data[x7+y4+z7]*tablex7 ) * tabley4 + 01125 ( data[x1+y5+z7]*tablex1 + data[x2+y5+z7]*tablex2 + data[x3+y5+z7]*tablex3 + 01126 data[x4+y5+z7]*tablex4 + data[x5+y5+z7]*tablex5 + data[x6+y5+z7]*tablex6 + 01127 data[x7+y5+z7]*tablex7 ) * tabley5 + 01128 ( data[x1+y6+z7]*tablex1 + data[x2+y6+z7]*tablex2 + data[x3+y6+z7]*tablex3 + 01129 data[x4+y6+z7]*tablex4 + data[x5+y6+z7]*tablex5 + data[x6+y6+z7]*tablex6 + 01130 data[x7+y6+z7]*tablex7 ) * tabley6 + 01131 ( data[x1+y7+z7]*tablex1 + data[x2+y7+z7]*tablex2 + data[x3+y7+z7]*tablex3 + 01132 data[x4+y7+z7]*tablex4 + data[x5+y7+z7]*tablex5 + data[x6+y7+z7]*tablex6 + 01133 data[x7+y7+z7]*tablex7 ) * tabley7 ) *tablez7; 01134 01135 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) * 01136 (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7) * 01137 (tablez1+tablez2+tablez3+tablez4+tablez5+tablez6+tablez7); 01138 } 01139 return pixel/w; 01140 }
float Util::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 | |||
) | [static] |
Definition at line 1142 of file util_sparx.cpp.
References EMAN::Util::KaiserBessel::get_window_size(), EMAN::Util::KaiserBessel::i0win_tab(), restrict1(), and round().
01142 { 01143 int K = kb.get_window_size(); 01144 int kbmin = -K/2; 01145 int kbmax = -kbmin; 01146 int kbc = kbmax+1; 01147 01148 float pixel =0.0f; 01149 float w=0.0f; 01150 01151 float argdelx = delx; // adding this for 2D case where the wrap around is not done circulantly using restrict1. 01152 delx = restrict1(delx, nx); 01153 int inxold = int(round(delx)); 01154 if ( ny < 2 ) { //1D 01155 float tablex1 = kb.i0win_tab(delx-inxold+3); 01156 float tablex2 = kb.i0win_tab(delx-inxold+2); 01157 float tablex3 = kb.i0win_tab(delx-inxold+1); 01158 float tablex4 = kb.i0win_tab(delx-inxold); 01159 float tablex5 = kb.i0win_tab(delx-inxold-1); 01160 float tablex6 = kb.i0win_tab(delx-inxold-2); 01161 float tablex7 = kb.i0win_tab(delx-inxold-3); 01162 01163 int x1, x2, x3, x4, x5, x6, x7; 01164 01165 if ( inxold <= kbc || inxold >=nx-kbc-2 ) { 01166 x1 = (inxold-3+nx)%nx; 01167 x2 = (inxold-2+nx)%nx; 01168 x3 = (inxold-1+nx)%nx; 01169 x4 = (inxold +nx)%nx; 01170 x5 = (inxold+1+nx)%nx; 01171 x6 = (inxold+2+nx)%nx; 01172 x7 = (inxold+3+nx)%nx; 01173 } else { 01174 x1 = inxold-3; 01175 x2 = inxold-2; 01176 x3 = inxold-1; 01177 x4 = inxold; 01178 x5 = inxold+1; 01179 x6 = inxold+2; 01180 x7 = inxold+3; 01181 } 01182 01183 pixel = data[x1]*tablex1 + data[x2]*tablex2 + data[x3]*tablex3 + 01184 data[x4]*tablex4 + data[x5]*tablex5 + data[x6]*tablex6 + 01185 data[x7]*tablex7 ; 01186 01187 w = tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7; 01188 } else if ( nz < 2 ) { // 2D 01189 01190 delx = argdelx; 01191 // 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 01192 if ((delx < 0.0f) || (delx >= (float) (nx)) || (dely < 0.0f) || (dely >= (float) (ny)) ){ 01193 delx = (float)xnew*2.0f; 01194 dely = (float)ynew*2.0f; 01195 } 01196 01197 int inxold = int(round(delx)); 01198 int inyold = int(round(dely)); 01199 01200 float tablex1 = kb.i0win_tab(delx-inxold+3); 01201 float tablex2 = kb.i0win_tab(delx-inxold+2); 01202 float tablex3 = kb.i0win_tab(delx-inxold+1); 01203 float tablex4 = kb.i0win_tab(delx-inxold); 01204 float tablex5 = kb.i0win_tab(delx-inxold-1); 01205 float tablex6 = kb.i0win_tab(delx-inxold-2); 01206 float tablex7 = kb.i0win_tab(delx-inxold-3); 01207 01208 float tabley1 = kb.i0win_tab(dely-inyold+3); 01209 float tabley2 = kb.i0win_tab(dely-inyold+2); 01210 float tabley3 = kb.i0win_tab(dely-inyold+1); 01211 float tabley4 = kb.i0win_tab(dely-inyold); 01212 float tabley5 = kb.i0win_tab(dely-inyold-1); 01213 float tabley6 = kb.i0win_tab(dely-inyold-2); 01214 float tabley7 = kb.i0win_tab(dely-inyold-3); 01215 01216 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7; 01217 01218 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 ) { 01219 x1 = (inxold-3+nx)%nx; 01220 x2 = (inxold-2+nx)%nx; 01221 x3 = (inxold-1+nx)%nx; 01222 x4 = (inxold +nx)%nx; 01223 x5 = (inxold+1+nx)%nx; 01224 x6 = (inxold+2+nx)%nx; 01225 x7 = (inxold+3+nx)%nx; 01226 01227 y1 = ((inyold-3+ny)%ny)*nx; 01228 y2 = ((inyold-2+ny)%ny)*nx; 01229 y3 = ((inyold-1+ny)%ny)*nx; 01230 y4 = ((inyold +ny)%ny)*nx; 01231 y5 = ((inyold+1+ny)%ny)*nx; 01232 y6 = ((inyold+2+ny)%ny)*nx; 01233 y7 = ((inyold+3+ny)%ny)*nx; 01234 } else { 01235 x1 = inxold-3; 01236 x2 = inxold-2; 01237 x3 = inxold-1; 01238 x4 = inxold; 01239 x5 = inxold+1; 01240 x6 = inxold+2; 01241 x7 = inxold+3; 01242 01243 y1 = (inyold-3)*nx; 01244 y2 = (inyold-2)*nx; 01245 y3 = (inyold-1)*nx; 01246 y4 = inyold*nx; 01247 y5 = (inyold+1)*nx; 01248 y6 = (inyold+2)*nx; 01249 y7 = (inyold+3)*nx; 01250 } 01251 01252 pixel = ( data[x1+y1]*tablex1 + data[x2+y1]*tablex2 + data[x3+y1]*tablex3 + 01253 data[x4+y1]*tablex4 + data[x5+y1]*tablex5 + data[x6+y1]*tablex6 + 01254 data[x7+y1]*tablex7 ) * tabley1 + 01255 ( data[x1+y2]*tablex1 + data[x2+y2]*tablex2 + data[x3+y2]*tablex3 + 01256 data[x4+y2]*tablex4 + data[x5+y2]*tablex5 + data[x6+y2]*tablex6 + 01257 data[x7+y2]*tablex7 ) * tabley2 + 01258 ( data[x1+y3]*tablex1 + data[x2+y3]*tablex2 + data[x3+y3]*tablex3 + 01259 data[x4+y3]*tablex4 + data[x5+y3]*tablex5 + data[x6+y3]*tablex6 + 01260 data[x7+y3]*tablex7 ) * tabley3 + 01261 ( data[x1+y4]*tablex1 + data[x2+y4]*tablex2 + data[x3+y4]*tablex3 + 01262 data[x4+y4]*tablex4 + data[x5+y4]*tablex5 + data[x6+y4]*tablex6 + 01263 data[x7+y4]*tablex7 ) * tabley4 + 01264 ( data[x1+y5]*tablex1 + data[x2+y5]*tablex2 + data[x3+y5]*tablex3 + 01265 data[x4+y5]*tablex4 + data[x5+y5]*tablex5 + data[x6+y5]*tablex6 + 01266 data[x7+y5]*tablex7 ) * tabley5 + 01267 ( data[x1+y6]*tablex1 + data[x2+y6]*tablex2 + data[x3+y6]*tablex3 + 01268 data[x4+y6]*tablex4 + data[x5+y6]*tablex5 + data[x6+y6]*tablex6 + 01269 data[x7+y6]*tablex7 ) * tabley6 + 01270 ( data[x1+y7]*tablex1 + data[x2+y7]*tablex2 + data[x3+y7]*tablex3 + 01271 data[x4+y7]*tablex4 + data[x5+y7]*tablex5 + data[x6+y7]*tablex6 + 01272 data[x7+y7]*tablex7 ) * tabley7; 01273 01274 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) * 01275 (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7); 01276 } else { // 3D 01277 dely = restrict1(dely, ny); 01278 int inyold = int(Util::round(dely)); 01279 delz = restrict1(delz, nz); 01280 int inzold = int(Util::round(delz)); 01281 01282 float tablex1 = kb.i0win_tab(delx-inxold+3); 01283 float tablex2 = kb.i0win_tab(delx-inxold+2); 01284 float tablex3 = kb.i0win_tab(delx-inxold+1); 01285 float tablex4 = kb.i0win_tab(delx-inxold); 01286 float tablex5 = kb.i0win_tab(delx-inxold-1); 01287 float tablex6 = kb.i0win_tab(delx-inxold-2); 01288 float tablex7 = kb.i0win_tab(delx-inxold-3); 01289 01290 float tabley1 = kb.i0win_tab(dely-inyold+3); 01291 float tabley2 = kb.i0win_tab(dely-inyold+2); 01292 float tabley3 = kb.i0win_tab(dely-inyold+1); 01293 float tabley4 = kb.i0win_tab(dely-inyold); 01294 float tabley5 = kb.i0win_tab(dely-inyold-1); 01295 float tabley6 = kb.i0win_tab(dely-inyold-2); 01296 float tabley7 = kb.i0win_tab(dely-inyold-3); 01297 01298 float tablez1 = kb.i0win_tab(delz-inzold+3); 01299 float tablez2 = kb.i0win_tab(delz-inzold+2); 01300 float tablez3 = kb.i0win_tab(delz-inzold+1); 01301 float tablez4 = kb.i0win_tab(delz-inzold); 01302 float tablez5 = kb.i0win_tab(delz-inzold-1); 01303 float tablez6 = kb.i0win_tab(delz-inzold-2); 01304 float tablez7 = kb.i0win_tab(delz-inzold-3); 01305 01306 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7, z1, z2, z3, z4, z5, z6, z7; 01307 01308 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 || inzold <= kbc || inzold >= nz-kbc-2 ) { 01309 x1 = (inxold-3+nx)%nx; 01310 x2 = (inxold-2+nx)%nx; 01311 x3 = (inxold-1+nx)%nx; 01312 x4 = (inxold +nx)%nx; 01313 x5 = (inxold+1+nx)%nx; 01314 x6 = (inxold+2+nx)%nx; 01315 x7 = (inxold+3+nx)%nx; 01316 01317 y1 = ((inyold-3+ny)%ny)*nx; 01318 y2 = ((inyold-2+ny)%ny)*nx; 01319 y3 = ((inyold-1+ny)%ny)*nx; 01320 y4 = ((inyold +ny)%ny)*nx; 01321 y5 = ((inyold+1+ny)%ny)*nx; 01322 y6 = ((inyold+2+ny)%ny)*nx; 01323 y7 = ((inyold+3+ny)%ny)*nx; 01324 01325 z1 = ((inzold-3+nz)%nz)*nx*ny; 01326 z2 = ((inzold-2+nz)%nz)*nx*ny; 01327 z3 = ((inzold-1+nz)%nz)*nx*ny; 01328 z4 = ((inzold +nz)%nz)*nx*ny; 01329 z5 = ((inzold+1+nz)%nz)*nx*ny; 01330 z6 = ((inzold+2+nz)%nz)*nx*ny; 01331 z7 = ((inzold+3+nz)%nz)*nx*ny; 01332 } else { 01333 x1 = inxold-3; 01334 x2 = inxold-2; 01335 x3 = inxold-1; 01336 x4 = inxold; 01337 x5 = inxold+1; 01338 x6 = inxold+2; 01339 x7 = inxold+3; 01340 01341 y1 = (inyold-3)*nx; 01342 y2 = (inyold-2)*nx; 01343 y3 = (inyold-1)*nx; 01344 y4 = inyold*nx; 01345 y5 = (inyold+1)*nx; 01346 y6 = (inyold+2)*nx; 01347 y7 = (inyold+3)*nx; 01348 01349 z1 = (inzold-3)*nx*ny; 01350 z2 = (inzold-2)*nx*ny; 01351 z3 = (inzold-1)*nx*ny; 01352 z4 = inzold*nx*ny; 01353 z5 = (inzold+1)*nx*ny; 01354 z6 = (inzold+2)*nx*ny; 01355 z7 = (inzold+3)*nx*ny; 01356 } 01357 01358 pixel = ( ( data[x1+y1+z1]*tablex1 + data[x2+y1+z1]*tablex2 + data[x3+y1+z1]*tablex3 + 01359 data[x4+y1+z1]*tablex4 + data[x5+y1+z1]*tablex5 + data[x6+y1+z1]*tablex6 + 01360 data[x7+y1+z1]*tablex7 ) * tabley1 + 01361 ( data[x1+y2+z1]*tablex1 + data[x2+y2+z1]*tablex2 + data[x3+y2+z1]*tablex3 + 01362 data[x4+y2+z1]*tablex4 + data[x5+y2+z1]*tablex5 + data[x6+y2+z1]*tablex6 + 01363 data[x7+y2+z1]*tablex7 ) * tabley2 + 01364 ( data[x1+y3+z1]*tablex1 + data[x2+y3+z1]*tablex2 + data[x3+y3+z1]*tablex3 + 01365 data[x4+y3+z1]*tablex4 + data[x5+y3+z1]*tablex5 + data[x6+y3+z1]*tablex6 + 01366 data[x7+y3+z1]*tablex7 ) * tabley3 + 01367 ( data[x1+y4+z1]*tablex1 + data[x2+y4+z1]*tablex2 + data[x3+y4+z1]*tablex3 + 01368 data[x4+y4+z1]*tablex4 + data[x5+y4+z1]*tablex5 + data[x6+y4+z1]*tablex6 + 01369 data[x7+y4+z1]*tablex7 ) * tabley4 + 01370 ( data[x1+y5+z1]*tablex1 + data[x2+y5+z1]*tablex2 + data[x3+y5+z1]*tablex3 + 01371 data[x4+y5+z1]*tablex4 + data[x5+y5+z1]*tablex5 + data[x6+y5+z1]*tablex6 + 01372 data[x7+y5+z1]*tablex7 ) * tabley5 + 01373 ( data[x1+y6+z1]*tablex1 + data[x2+y6+z1]*tablex2 + data[x3+y6+z1]*tablex3 + 01374 data[x4+y6+z1]*tablex4 + data[x5+y6+z1]*tablex5 + data[x6+y6+z1]*tablex6 + 01375 data[x7+y6+z1]*tablex7 ) * tabley6 + 01376 ( data[x1+y7+z1]*tablex1 + data[x2+y7+z1]*tablex2 + data[x3+y7+z1]*tablex3 + 01377 data[x4+y7+z1]*tablex4 + data[x5+y7+z1]*tablex5 + data[x6+y7+z1]*tablex6 + 01378 data[x7+y7+z1]*tablex7 ) * tabley7 ) *tablez1 + 01379 ( ( data[x1+y1+z2]*tablex1 + data[x2+y1+z2]*tablex2 + data[x3+y1+z2]*tablex3 + 01380 data[x4+y1+z2]*tablex4 + data[x5+y1+z2]*tablex5 + data[x6+y1+z2]*tablex6 + 01381 data[x7+y1+z2]*tablex7 ) * tabley1 + 01382 ( data[x1+y2+z2]*tablex1 + data[x2+y2+z2]*tablex2 + data[x3+y2+z2]*tablex3 + 01383 data[x4+y2+z2]*tablex4 + data[x5+y2+z2]*tablex5 + data[x6+y2+z2]*tablex6 + 01384 data[x7+y2+z2]*tablex7 ) * tabley2 + 01385 ( data[x1+y3+z2]*tablex1 + data[x2+y3+z2]*tablex2 + data[x3+y3+z2]*tablex3 + 01386 data[x4+y3+z2]*tablex4 + data[x5+y3+z2]*tablex5 + data[x6+y3+z2]*tablex6 + 01387 data[x7+y3+z2]*tablex7 ) * tabley3 + 01388 ( data[x1+y4+z2]*tablex1 + data[x2+y4+z2]*tablex2 + data[x3+y4+z2]*tablex3 + 01389 data[x4+y4+z2]*tablex4 + data[x5+y4+z2]*tablex5 + data[x6+y4+z2]*tablex6 + 01390 data[x7+y4+z2]*tablex7 ) * tabley4 + 01391 ( data[x1+y5+z2]*tablex1 + data[x2+y5+z2]*tablex2 + data[x3+y5+z2]*tablex3 + 01392 data[x4+y5+z2]*tablex4 + data[x5+y5+z2]*tablex5 + data[x6+y5+z2]*tablex6 + 01393 data[x7+y5+z2]*tablex7 ) * tabley5 + 01394 ( data[x1+y6+z2]*tablex1 + data[x2+y6+z2]*tablex2 + data[x3+y6+z2]*tablex3 + 01395 data[x4+y6+z2]*tablex4 + data[x5+y6+z2]*tablex5 + data[x6+y6+z2]*tablex6 + 01396 data[x7+y6+z2]*tablex7 ) * tabley6 + 01397 ( data[x1+y7+z2]*tablex1 + data[x2+y7+z2]*tablex2 + data[x3+y7+z2]*tablex3 + 01398 data[x4+y7+z2]*tablex4 + data[x5+y7+z2]*tablex5 + data[x6+y7+z2]*tablex6 + 01399 data[x7+y7+z2]*tablex7 ) * tabley7 ) *tablez2 + 01400 ( ( data[x1+y1+z3]*tablex1 + data[x2+y1+z3]*tablex2 + data[x3+y1+z3]*tablex3 + 01401 data[x4+y1+z3]*tablex4 + data[x5+y1+z3]*tablex5 + data[x6+y1+z3]*tablex6 + 01402 data[x7+y1+z3]*tablex7 ) * tabley1 + 01403 ( data[x1+y2+z3]*tablex1 + data[x2+y2+z3]*tablex2 + data[x3+y2+z3]*tablex3 + 01404 data[x4+y2+z3]*tablex4 + data[x5+y2+z3]*tablex5 + data[x6+y2+z3]*tablex6 + 01405 data[x7+y2+z3]*tablex7 ) * tabley2 + 01406 ( data[x1+y3+z3]*tablex1 + data[x2+y3+z3]*tablex2 + data[x3+y3+z3]*tablex3 + 01407 data[x4+y3+z3]*tablex4 + data[x5+y3+z3]*tablex5 + data[x6+y3+z3]*tablex6 + 01408 data[x7+y3+z3]*tablex7 ) * tabley3 + 01409 ( data[x1+y4+z3]*tablex1 + data[x2+y4+z3]*tablex2 + data[x3+y4+z3]*tablex3 + 01410 data[x4+y4+z3]*tablex4 + data[x5+y4+z3]*tablex5 + data[x6+y4+z3]*tablex6 + 01411 data[x7+y4+z3]*tablex7 ) * tabley4 + 01412 ( data[x1+y5+z3]*tablex1 + data[x2+y5+z3]*tablex2 + data[x3+y5+z3]*tablex3 + 01413 data[x4+y5+z3]*tablex4 + data[x5+y5+z3]*tablex5 + data[x6+y5+z3]*tablex6 + 01414 data[x7+y5+z3]*tablex7 ) * tabley5 + 01415 ( data[x1+y6+z3]*tablex1 + data[x2+y6+z3]*tablex2 + data[x3+y6+z3]*tablex3 + 01416 data[x4+y6+z3]*tablex4 + data[x5+y6+z3]*tablex5 + data[x6+y6+z3]*tablex6 + 01417 data[x7+y6+z3]*tablex7 ) * tabley6 + 01418 ( data[x1+y7+z3]*tablex1 + data[x2+y7+z3]*tablex2 + data[x3+y7+z3]*tablex3 + 01419 data[x4+y7+z3]*tablex4 + data[x5+y7+z3]*tablex5 + data[x6+y7+z3]*tablex6 + 01420 data[x7+y7+z3]*tablex7 ) * tabley7 ) *tablez3 + 01421 ( ( data[x1+y1+z4]*tablex1 + data[x2+y1+z4]*tablex2 + data[x3+y1+z4]*tablex3 + 01422 data[x4+y1+z4]*tablex4 + data[x5+y1+z4]*tablex5 + data[x6+y1+z4]*tablex6 + 01423 data[x7+y1+z4]*tablex7 ) * tabley1 + 01424 ( data[x1+y2+z4]*tablex1 + data[x2+y2+z4]*tablex2 + data[x3+y2+z4]*tablex3 + 01425 data[x4+y2+z4]*tablex4 + data[x5+y2+z4]*tablex5 + data[x6+y2+z4]*tablex6 + 01426 data[x7+y2+z4]*tablex7 ) * tabley2 + 01427 ( data[x1+y3+z4]*tablex1 + data[x2+y3+z4]*tablex2 + data[x3+y3+z4]*tablex3 + 01428 data[x4+y3+z4]*tablex4 + data[x5+y3+z4]*tablex5 + data[x6+y3+z4]*tablex6 + 01429 data[x7+y3+z4]*tablex7 ) * tabley3 + 01430 ( data[x1+y4+z4]*tablex1 + data[x2+y4+z4]*tablex2 + data[x3+y4+z4]*tablex3 + 01431 data[x4+y4+z4]*tablex4 + data[x5+y4+z4]*tablex5 + data[x6+y4+z4]*tablex6 + 01432 data[x7+y4+z4]*tablex7 ) * tabley4 + 01433 ( data[x1+y5+z4]*tablex1 + data[x2+y5+z4]*tablex2 + data[x3+y5+z4]*tablex3 + 01434 data[x4+y5+z4]*tablex4 + data[x5+y5+z4]*tablex5 + data[x6+y5+z4]*tablex6 + 01435 data[x7+y5+z4]*tablex7 ) * tabley5 + 01436 ( data[x1+y6+z4]*tablex1 + data[x2+y6+z4]*tablex2 + data[x3+y6+z4]*tablex3 + 01437 data[x4+y6+z4]*tablex4 + data[x5+y6+z4]*tablex5 + data[x6+y6+z4]*tablex6 + 01438 data[x7+y6+z4]*tablex7 ) * tabley6 + 01439 ( data[x1+y7+z4]*tablex1 + data[x2+y7+z4]*tablex2 + data[x3+y7+z4]*tablex3 + 01440 data[x4+y7+z4]*tablex4 + data[x5+y7+z4]*tablex5 + data[x6+y7+z4]*tablex6 + 01441 data[x7+y7+z4]*tablex7 ) * tabley7 ) *tablez4 + 01442 ( ( data[x1+y1+z5]*tablex1 + data[x2+y1+z5]*tablex2 + data[x3+y1+z5]*tablex3 + 01443 data[x4+y1+z5]*tablex4 + data[x5+y1+z5]*tablex5 + data[x6+y1+z5]*tablex6 + 01444 data[x7+y1+z5]*tablex7 ) * tabley1 + 01445 ( data[x1+y2+z5]*tablex1 + data[x2+y2+z5]*tablex2 + data[x3+y2+z5]*tablex3 + 01446 data[x4+y2+z5]*tablex4 + data[x5+y2+z5]*tablex5 + data[x6+y2+z5]*tablex6 + 01447 data[x7+y2+z5]*tablex7 ) * tabley2 + 01448 ( data[x1+y3+z5]*tablex1 + data[x2+y3+z5]*tablex2 + data[x3+y3+z5]*tablex3 + 01449 data[x4+y3+z5]*tablex4 + data[x5+y3+z5]*tablex5 + data[x6+y3+z5]*tablex6 + 01450 data[x7+y3+z5]*tablex7 ) * tabley3 + 01451 ( data[x1+y4+z5]*tablex1 + data[x2+y4+z5]*tablex2 + data[x3+y4+z5]*tablex3 + 01452 data[x4+y4+z5]*tablex4 + data[x5+y4+z5]*tablex5 + data[x6+y4+z5]*tablex6 + 01453 data[x7+y4+z5]*tablex7 ) * tabley4 + 01454 ( data[x1+y5+z5]*tablex1 + data[x2+y5+z5]*tablex2 + data[x3+y5+z5]*tablex3 + 01455 data[x4+y5+z5]*tablex4 + data[x5+y5+z5]*tablex5 + data[x6+y5+z5]*tablex6 + 01456 data[x7+y5+z5]*tablex7 ) * tabley5 + 01457 ( data[x1+y6+z5]*tablex1 + data[x2+y6+z5]*tablex2 + data[x3+y6+z5]*tablex3 + 01458 data[x4+y6+z5]*tablex4 + data[x5+y6+z5]*tablex5 + data[x6+y6+z5]*tablex6 + 01459 data[x7+y6+z5]*tablex7 ) * tabley6 + 01460 ( data[x1+y7+z5]*tablex1 + data[x2+y7+z5]*tablex2 + data[x3+y7+z5]*tablex3 + 01461 data[x4+y7+z5]*tablex4 + data[x5+y7+z5]*tablex5 + data[x6+y7+z5]*tablex6 + 01462 data[x7+y7+z5]*tablex7 ) * tabley7 ) *tablez5 + 01463 ( ( data[x1+y1+z6]*tablex1 + data[x2+y1+z6]*tablex2 + data[x3+y1+z6]*tablex3 + 01464 data[x4+y1+z6]*tablex4 + data[x5+y1+z6]*tablex5 + data[x6+y1+z6]*tablex6 + 01465 data[x7+y1+z6]*tablex7 ) * tabley1 + 01466 ( data[x1+y2+z6]*tablex1 + data[x2+y2+z6]*tablex2 + data[x3+y2+z6]*tablex3 + 01467 data[x4+y2+z6]*tablex4 + data[x5+y2+z6]*tablex5 + data[x6+y2+z6]*tablex6 + 01468 data[x7+y2+z6]*tablex7 ) * tabley2 + 01469 ( data[x1+y3+z6]*tablex1 + data[x2+y3+z6]*tablex2 + data[x3+y3+z6]*tablex3 + 01470 data[x4+y3+z6]*tablex4 + data[x5+y3+z6]*tablex5 + data[x6+y3+z6]*tablex6 + 01471 data[x7+y3+z6]*tablex7 ) * tabley3 + 01472 ( data[x1+y4+z6]*tablex1 + data[x2+y4+z6]*tablex2 + data[x3+y4+z6]*tablex3 + 01473 data[x4+y4+z6]*tablex4 + data[x5+y4+z6]*tablex5 + data[x6+y4+z6]*tablex6 + 01474 data[x7+y4+z6]*tablex7 ) * tabley4 + 01475 ( data[x1+y5+z6]*tablex1 + data[x2+y5+z6]*tablex2 + data[x3+y5+z6]*tablex3 + 01476 data[x4+y5+z6]*tablex4 + data[x5+y5+z6]*tablex5 + data[x6+y5+z6]*tablex6 + 01477 data[x7+y5+z6]*tablex7 ) * tabley5 + 01478 ( data[x1+y6+z6]*tablex1 + data[x2+y6+z6]*tablex2 + data[x3+y6+z6]*tablex3 + 01479 data[x4+y6+z6]*tablex4 + data[x5+y6+z6]*tablex5 + data[x6+y6+z6]*tablex6 + 01480 data[x7+y6+z6]*tablex7 ) * tabley6 + 01481 ( data[x1+y7+z6]*tablex1 + data[x2+y7+z6]*tablex2 + data[x3+y7+z6]*tablex3 + 01482 data[x4+y7+z6]*tablex4 + data[x5+y7+z6]*tablex5 + data[x6+y7+z6]*tablex6 + 01483 data[x7+y7+z6]*tablex7 ) * tabley7 ) *tablez6 + 01484 ( ( data[x1+y1+z7]*tablex1 + data[x2+y1+z7]*tablex2 + data[x3+y1+z7]*tablex3 + 01485 data[x4+y1+z7]*tablex4 + data[x5+y1+z7]*tablex5 + data[x6+y1+z7]*tablex6 + 01486 data[x7+y1+z7]*tablex7 ) * tabley1 + 01487 ( data[x1+y2+z7]*tablex1 + data[x2+y2+z7]*tablex2 + data[x3+y2+z7]*tablex3 + 01488 data[x4+y2+z7]*tablex4 + data[x5+y2+z7]*tablex5 + data[x6+y2+z7]*tablex6 + 01489 data[x7+y2+z7]*tablex7 ) * tabley2 + 01490 ( data[x1+y3+z7]*tablex1 + data[x2+y3+z7]*tablex2 + data[x3+y3+z7]*tablex3 + 01491 data[x4+y3+z7]*tablex4 + data[x5+y3+z7]*tablex5 + data[x6+y3+z7]*tablex6 + 01492 data[x7+y3+z7]*tablex7 ) * tabley3 + 01493 ( data[x1+y4+z7]*tablex1 + data[x2+y4+z7]*tablex2 + data[x3+y4+z7]*tablex3 + 01494 data[x4+y4+z7]*tablex4 + data[x5+y4+z7]*tablex5 + data[x6+y4+z7]*tablex6 + 01495 data[x7+y4+z7]*tablex7 ) * tabley4 + 01496 ( data[x1+y5+z7]*tablex1 + data[x2+y5+z7]*tablex2 + data[x3+y5+z7]*tablex3 + 01497 data[x4+y5+z7]*tablex4 + data[x5+y5+z7]*tablex5 + data[x6+y5+z7]*tablex6 + 01498 data[x7+y5+z7]*tablex7 ) * tabley5 + 01499 ( data[x1+y6+z7]*tablex1 + data[x2+y6+z7]*tablex2 + data[x3+y6+z7]*tablex3 + 01500 data[x4+y6+z7]*tablex4 + data[x5+y6+z7]*tablex5 + data[x6+y6+z7]*tablex6 + 01501 data[x7+y6+z7]*tablex7 ) * tabley6 + 01502 ( data[x1+y7+z7]*tablex1 + data[x2+y7+z7]*tablex2 + data[x3+y7+z7]*tablex3 + 01503 data[x4+y7+z7]*tablex4 + data[x5+y7+z7]*tablex5 + data[x6+y7+z7]*tablex6 + 01504 data[x7+y7+z7]*tablex7 ) * tabley7 ) *tablez7; 01505 01506 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) * 01507 (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7) * 01508 (tablez1+tablez2+tablez3+tablez4+tablez5+tablez6+tablez7); 01509 } 01510 return pixel/w; 01511 }
unsigned long long Util::get_randnum_seed | ( | ) | [static] |
Get the seed for Randnum class.
Definition at line 718 of file util.cpp.
References EMAN::Randnum::get_seed(), and EMAN::Randnum::Instance().
00719 { 00720 Randnum* randnum = Randnum::Instance(); 00721 return randnum->get_seed(); 00722 }
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 20796 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, and EMAN::EMData::set_size().
20796 { 20797 20798 int nx = vol->get_xsize(); 20799 int ny = vol->get_ysize(); 20800 int nz = vol->get_zsize(); 20801 float *vol_data = vol->get_data(); 20802 int new_nx, new_ny; 20803 20804 if (nz == 1) 20805 throw ImageDimensionException("Error: Input must be a 3-D object"); 20806 if ((dim < 1) || (dim > 3)) 20807 throw ImageDimensionException("Error: dim must be 1 (x-dimension), 2 (y-dimension) or 3 (z-dimension)"); 20808 if (((dim == 1) && (index < 0 || index > nx-1)) || 20809 ((dim == 1) && (index < 0 || index > nx-1)) || 20810 ((dim == 1) && (index < 0 || index > nx-1))) 20811 throw ImageDimensionException("Error: index exceeds the size of the 3-D object"); 20812 20813 if (dim == 1) { 20814 new_nx = ny; 20815 new_ny = nz; 20816 } else if (dim == 2) { 20817 new_nx = nx; 20818 new_ny = nz; 20819 } else { 20820 new_nx = nx; 20821 new_ny = ny; 20822 } 20823 20824 EMData *slice = new EMData(); 20825 slice->set_size(new_nx, new_ny, 1); 20826 float *slice_data = slice->get_data(); 20827 20828 if (dim == 1) { 20829 for (int x=0; x<new_nx; x++) 20830 for (int y=0; y<new_ny; y++) 20831 slice_data[y*new_nx+x] = vol_data[(y*ny+x)*nx+index]; 20832 } else if (dim == 2) { 20833 for (int x=0; x<new_nx; x++) 20834 for (int y=0; y<new_ny; y++) 20835 slice_data[y*new_nx+x] = vol_data[(y*ny+index)*nx+x]; 20836 } else { 20837 for (int x=0; x<new_nx; x++) 20838 for (int y=0; y<new_ny; y++) 20839 slice_data[y*new_nx+x] = vol_data[((size_t)index*ny+y)*nx+x]; 20840 } 20841 20842 return slice; 20843 }
Dict Util::get_stats | ( | const vector< float > & | data | ) | [static] |
Get the mean, standard deviation, skewness and kurtosis of the input data.
data | the vector of input data |
EmptyContainerException | when the argument vector is empty |
Definition at line 910 of file util.cpp.
References EmptyContainerException, mean(), sqrt(), and square_sum().
00911 { 00912 // Note that this is a heavy STL approach using generic algorithms - some memory could be saved 00913 // using plain c style code, as in get_stats_cstyle below 00914 00915 if (data.size() == 0) EmptyContainerException("Error, attempting to call get stats on an empty container (vector<double>)"); 00916 00917 double sum = accumulate(data.begin(), data.end(), 0.0); 00918 00919 double mean = sum / static_cast<double> (data.size()); 00920 00921 double std_dev = 0.0, skewness = 0.0, kurtosis = 0.0; 00922 00923 if (data.size() > 1) 00924 { 00925 // read mm is "minus_mean" 00926 vector<double> data_mm(data.size()); 00927 // read ts as "then squared" 00928 vector<double> data_mm_sq(data.size()); 00929 00930 // Subtract the mean from the data and store it in data_mm 00931 transform(data.begin(), data.end(), data_mm.begin(), std::bind2nd(std::minus<double>(), mean)); 00932 00933 // Get the square of the data minus the mean and store it in data_mm_sq 00934 transform(data_mm.begin(), data_mm.end(), data_mm.begin(), data_mm_sq.begin(), std::multiplies<double>()); 00935 00936 // Get the sum of the squares for the calculation of the standard deviation 00937 double square_sum = accumulate(data_mm_sq.begin(), data_mm_sq.end(), 0.0); 00938 00939 //Calculate teh standard deviation 00940 std_dev = sqrt(square_sum / static_cast<double>(data.size()-1)); 00941 double std_dev_sq = std_dev * std_dev; 00942 00943 // The numerator for the skewness fraction, as defined in http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm 00944 double cubic_sum = inner_product(data_mm.begin(), data_mm.end(),data_mm_sq.begin(), 0.0); 00945 00946 // The numerator for the kurtosis fraction, as defined in http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm 00947 double quartic_sum = inner_product(data_mm_sq.begin(), data_mm_sq.end(),data_mm_sq.begin(), 0.0); 00948 00949 // Finalize the calculation of the skewness and kurtosis, as defined in 00950 // http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm 00951 skewness = cubic_sum / ((data.size()-1) * std_dev_sq * std_dev ); 00952 kurtosis = quartic_sum / ((data.size()-1) * std_dev_sq * std_dev_sq ); 00953 00954 } 00955 00956 Dict parms; 00957 parms["mean"] = mean; 00958 parms["std_dev"] = std_dev; 00959 parms["skewness"] = skewness; 00960 parms["kurtosis"] = kurtosis; 00961 00962 return parms; 00963 }
Dict Util::get_stats_cstyle | ( | const vector< float > & | data | ) | [static] |
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 966 of file util.cpp.
References EmptyContainerException, mean(), sqrt(), square(), and square_sum().
00967 { 00968 if (data.size() == 0) EmptyContainerException("Error, attempting to call get stats on an empty container (vector<double>)"); 00969 00970 double square_sum = 0.0, sum = 0.0, cube_sum = 0.0, quart_sum = 0.0; 00971 for( vector<float>::const_iterator it = data.begin(); it != data.end(); ++it ) 00972 { 00973 double val = *it; 00974 double square = val*val; 00975 quart_sum += square*square; 00976 cube_sum += square*val; 00977 square_sum += square; 00978 sum += val; 00979 } 00980 00981 double mean = sum/(double)data.size(); 00982 00983 double std_dev = 0.0, skewness = 0.0, kurtosis = 0.0; 00984 00985 if (data.size() > 1) 00986 { 00987 // The standard deviation is calculated here 00988 std_dev = sqrt( (square_sum - mean*sum)/(double)(data.size()-1)); 00989 00990 double square_mean = mean*mean; 00991 double cube_mean = mean*square_mean; 00992 00993 double square_std_dev = std_dev*std_dev; 00994 00995 // This is the numerator of the skewness fraction, if you expand the brackets, as defined in 00996 // http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm 00997 double cubic_sum = cube_sum - 3*square_sum*mean + 3*sum*square_mean - cube_mean*data.size(); 00998 // Complete the skewness fraction 00999 skewness = cubic_sum/((data.size()-1)*square_std_dev*std_dev); 01000 01001 // This is the numerator of the kurtosis fraction, if you expand the brackets, as defined in 01002 // http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm 01003 double quartic_sum = quart_sum - 4*cube_sum*mean + 6*square_sum*square_mean - 4*sum*cube_mean + square_mean*square_mean*data.size(); 01004 // Complete the kurtosis fraction 01005 kurtosis = quartic_sum /( (data.size()-1)*square_std_dev*square_std_dev); 01006 } 01007 01008 Dict parms; 01009 parms["mean"] = mean; 01010 parms["std_dev"] = std_dev; 01011 parms["skewness"] = skewness; 01012 parms["kurtosis"] = kurtosis; 01013 01014 return parms; 01015 }
bool Util::get_str_float | ( | const char * | str, | |
const char * | float_var, | |||
int * | p_nvalues, | |||
float * | p_v1, | |||
float * | p_v2 | |||
) | [static] |
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.
[in] | str | A string like "XYZ=1.1,1.2" or "XYZ". |
[in] | float_var | The variable name "XYZ". |
[out] | p_nvalues | Number of values in the string. |
[out] | p_v1 | The pointer to the first float, if any. |
[out] | p_v2 | The pointer to the second float, if any. |
Definition at line 393 of file util.cpp.
References NullPointerException.
00395 { 00396 if (!s || !float_var || !p_v0 || !p_v1 || !p_v2) { 00397 throw NullPointerException("string float"); 00398 } 00399 00400 size_t n = strlen(float_var); 00401 *p_v0 = 0; 00402 if (strncmp(s, float_var, n) == 0) { 00403 if (s[n] == '=') { 00404 *p_v0 = 2; 00405 sscanf(&s[n + 1], "%f,%f", p_v1, p_v2); 00406 } 00407 else { 00408 *p_v0 = 1; 00409 } 00410 return true; 00411 } 00412 return false; 00413 }
bool Util::get_str_float | ( | const char * | str, | |
const char * | float_var, | |||
float * | p_v1, | |||
float * | p_v2 | |||
) | [static] |
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.
[in] | str | A string like "XYZ=1.1,1.2"; |
[in] | float_var | The variable name "XYZ=". |
[out] | p_v1 | The pointer to the first float. |
[out] | p_v2 | The pointer to the second float. |
Definition at line 378 of file util.cpp.
References NullPointerException.
00379 { 00380 if (!s || !float_var || !p_v1 || !p_v2) { 00381 throw NullPointerException("string float"); 00382 } 00383 00384 size_t n = strlen(float_var); 00385 if (strncmp(s, float_var, n) == 0) { 00386 sscanf(&s[n], "%f,%f", p_v1, p_v2); 00387 return true; 00388 } 00389 00390 return false; 00391 }
bool Util::get_str_float | ( | const char * | str, | |
const char * | float_var, | |||
float * | p_val | |||
) | [static] |
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.
[in] | str | A string like "XYZ=1.1"; |
[in] | float_var | The variable name "XYZ=". |
[out] | p_val | The pointer to the float number. |
Definition at line 364 of file util.cpp.
References NullPointerException.
00365 { 00366 if (!s || !float_var || !p_val) { 00367 throw NullPointerException("string float"); 00368 } 00369 size_t n = strlen(float_var); 00370 if (strncmp(s, float_var, n) == 0) { 00371 *p_val = (float) atof(&s[n]); 00372 return true; 00373 } 00374 00375 return false; 00376 }
bool Util::get_str_int | ( | const char * | str, | |
const char * | int_var, | |||
int * | p_nvalues, | |||
int * | p_v1, | |||
int * | p_v2 | |||
) | [static] |
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.
[in] | str | A string like "XYZ=1,2" or "XYZ". |
[in] | int_var | The variable name "XYZ". |
[out] | p_nvalues | Number of values in the string. |
[out] | p_v1 | The pointer to the first int, if any. |
[out] | p_v2 | The pointer to the second int, if any. |
Definition at line 443 of file util.cpp.
References NullPointerException.
00444 { 00445 if (!s || !int_var || !p_v0 || !p_v1 || !p_v2) { 00446 throw NullPointerException("string int"); 00447 } 00448 00449 size_t n = strlen(int_var); 00450 *p_v0 = 0; 00451 if (strncmp(s, int_var, n) == 0) { 00452 if (s[n] == '=') { 00453 *p_v0 = 2; 00454 sscanf(&s[n + 1], "%d,%d", p_v1, p_v2); 00455 } 00456 else { 00457 *p_v0 = 1; 00458 } 00459 return true; 00460 } 00461 return false; 00462 }
bool Util::get_str_int | ( | const char * | str, | |
const char * | int_var, | |||
int * | p_v1, | |||
int * | p_v2 | |||
) | [static] |
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.
[in] | str | A string like "XYZ=1"; |
[in] | int_var | The variable name "XYZ=". |
[out] | p_v1 | The pointer to the first int. |
[out] | p_v2 | The pointer to the second int. |
Definition at line 429 of file util.cpp.
References NullPointerException.
00430 { 00431 if (!s || !int_var || !p_v1 || !p_v2) { 00432 throw NullPointerException("string int"); 00433 } 00434 00435 size_t n = strlen(int_var); 00436 if (strncmp(s, int_var, n) == 0) { 00437 sscanf(&s[n], "%d,%d", p_v1, p_v2); 00438 return true; 00439 } 00440 return false; 00441 }
bool Util::get_str_int | ( | const char * | str, | |
const char * | int_var, | |||
int * | p_val | |||
) | [static] |
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.
[in] | str | A string like "XYZ=1"; |
[in] | int_var | The variable name "XYZ=". |
[out] | p_val | The pointer to the int number. |
Definition at line 415 of file util.cpp.
References NullPointerException.
00416 { 00417 if (!s || !int_var || !p_val) { 00418 throw NullPointerException("string int"); 00419 } 00420 00421 size_t n = strlen(int_var); 00422 if (strncmp(s, int_var, n) == 0) { 00423 *p_val = atoi(&s[n]); 00424 return true; 00425 } 00426 return false; 00427 }
string Util::get_time_label | ( | ) | [static] |
Get the current time in a string with format "mm/dd/yyyy hh:mm".
Definition at line 1152 of file util.cpp.
References t.
01153 { 01154 time_t t0 = time(0); 01155 struct tm *t = localtime(&t0); 01156 char label[32]; 01157 sprintf(label, "%d/%02d/%04d %d:%02d", 01158 t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour, t->tm_min); 01159 return string(label); 01160 }
This function returns parameters from Transform object as a Dict object.
It allows to omit problem with passing Transform object through C++/Python layer (It causes memory leak).
Definition at line 21905 of file util_sparx.cpp.
References EMAN::EMData::get_attr(), and EMAN::Transform::get_params().
21906 { 21907 const Transform * transform = image->get_attr(xform); 21908 Dict transform_params = transform->get_params(convention); 21909 delete transform; 21910 return transform_params; 21911 }
float * Util::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 | |||
) | [static] |
[in] | freq_cutoff | |
[in] | P | |
[in] | r | |
[in] | dfreq | |
[in] | alpha | |
[in] | beta |
Definition at line 1217 of file util.cpp.
References abs, printmatrix(), printvector(), q, rhs, V, and W.
Referenced by EMAN::FourierInserter3DMode8::init().
01218 { 01219 int i = 0; 01220 int discs = (int)(1+2*freq_cutoff/dfreq); 01221 01222 float* W = new float[discs]; 01223 01224 int fc = (int)(2*freq_cutoff + 1); 01225 gsl_matrix* M = gsl_matrix_calloc(fc,fc); 01226 01227 gsl_vector* rhs = gsl_vector_calloc(fc); 01228 cout << i++ << endl; 01229 for(int k = -freq_cutoff; k <= freq_cutoff; ++k){ 01230 for(int kp = -freq_cutoff; kp <= freq_cutoff; ++kp){ 01231 int kdiff =abs( k-kp); 01232 int evenoddfac = ( kdiff % 2 == 0 ? 1 : -1); 01233 01234 if (kdiff !=0){ 01235 float val = sin(M_PI*(float)kdiff*r)/(sin(M_PI*(float)kdiff/(float)P))*(alpha+2.0f*beta*evenoddfac); 01236 gsl_matrix_set(M,int(k+freq_cutoff),int(kp+freq_cutoff),val); 01237 } 01238 } 01239 gsl_matrix_set(M,int(k+freq_cutoff),int(k+freq_cutoff),r*P* (alpha+2*beta)); 01240 float val = alpha*sin(M_PI*k*r)/(sin(M_PI*(float)k/(float)P)); 01241 if (k!=0) { 01242 gsl_vector_set(rhs,int(k+freq_cutoff),val); 01243 } 01244 } 01245 printmatrix(M,fc,fc,"M"); 01246 01247 gsl_vector_set(rhs,int(freq_cutoff),alpha*r*P); 01248 gsl_matrix* V = gsl_matrix_calloc(fc,fc); 01249 gsl_vector* S = gsl_vector_calloc(fc); 01250 gsl_vector* soln = gsl_vector_calloc(fc); 01251 gsl_linalg_SV_decomp(M,V,S,soln); 01252 01253 gsl_linalg_SV_solve(M, V, S, rhs, soln); // soln now runs from -freq_cutoff to + freq_cutoff 01254 printvector(soln,fc,"soln"); 01255 01256 // we want to solve for W, which ranges from -freq_cutoff to +freq_cutoff in steps of dfreq 2 01257 int Count=0; 01258 for(float q = (float)(-freq_cutoff); q <= (float)(freq_cutoff); q+= dfreq){ 01259 float temp=0; 01260 for(int k = -freq_cutoff; k <= freq_cutoff; ++k){ 01261 float dtemp; 01262 if (q!=k) { 01263 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)); 01264 } else{ 01265 dtemp = (1/(float) P)* (float)gsl_vector_get(soln,int(k+freq_cutoff)) * P; 01266 } 01267 temp +=dtemp; 01268 } 01269 W[Count]=temp; 01270 cout << W[Count] << " "; 01271 Count+=1; 01272 } 01273 cout << endl; 01274 return W; 01275 }
static void EMAN::Util::getvec | ( | float | phi, | |
float | theta, | |||
float & | x, | |||
float & | y, | |||
float & | z, | |||
int | option = 0 | |||
) | [inline, static] |
Definition at line 939 of file util.h.
Referenced by assign_projangles(), group_proj_by_phitheta(), and nearestk_to_refdir().
00940 :mm". 00941 * @return The current time string. 00942 */ 00943 static string get_time_label(); 00944 00951 static void set_log_level(int argc, char *argv[]); 00952
static int EMAN::Util::goodf | ( | const double * | p_f | ) | [inline, static] |
static int EMAN::Util::goodf | ( | const float * | p_f | ) | [inline, static] |
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
[in] | p_f | Pointer to the given float number. |
Definition at line 1995 of file util.h.
Referenced by EMAN::FRCCmp::cmp(), EMAN::SqEuclideanCmp::cmp(), EMAN::CccCmp::cmp(), EMAN::EMObject::EMObject(), EMAN::ByteOrder::is_float_big_endian(), EMAN::NormalizeProcessor::process_inplace(), and EMAN::FiniteProcessor::process_pixel().
vector< int > Util::group_proj_by_phitheta | ( | const vector< float > & | projangles, | |
const vector< float > & | ref_ang, | |||
const int | img_per_grp | |||
) | [static] |
Definition at line 18047 of file util_sparx.cpp.
References ang_diff(), assign_projangles(), getvec(), max, q, sqrt(), and v.
18047 { 18048 float c = 100.0; 18049 int L = max(100, img_per_grp); 18050 int N = projangles.size()/2; 18051 18052 int sz = ref_ang.size(); 18053 int nref1 = ref_ang[sz-4]; 18054 int nref2 = ref_ang[sz-3]; 18055 int nref3 = ref_ang[sz-2]; 18056 int nref4 = ref_ang[sz-1]; 18057 int nref; 18058 18059 set<int> pt; 18060 for (int i=0; i<N; i++) pt.insert(i); 18061 vector<float> v(N*3, 0.0f); 18062 for (int i=0; i<N; i++) 18063 getvec(projangles[i*2], projangles[i*2+1], v[i*3], v[i*3+1], v[i*3+2], 1); 18064 18065 int previous_group = -1; 18066 int previous_zone = 5; 18067 int max_group = 0; 18068 vector<float> ref_ang_list; 18069 vector<float> diff_table; 18070 map<int, int> diff_table_index; 18071 vector<int> proj_list; 18072 vector<int> sg; 18073 vector<int> remain_index; 18074 vector<int> asg; 18075 int mirror; 18076 for (int grp=0; grp<N/img_per_grp; grp++) { 18077 int N_remain = N-grp*img_per_grp; 18078 assert(N_remain == static_cast<int>(pt.size())); 18079 if (N_remain >= nref4*L) { 18080 if (previous_zone > 4) { 18081 ref_ang_list.resize(nref4*2); 18082 for (int i=0; i<nref4*2; i++) ref_ang_list[i] = ref_ang[(nref1+nref2+nref3)*2+i]; 18083 nref = nref4; 18084 previous_group = -1; 18085 previous_zone = 4; 18086 } 18087 } else if (N_remain >= nref3*L) { 18088 if (previous_zone > 3) { 18089 ref_ang_list.resize(nref3*2); 18090 for (int i=0; i<nref3*2; i++) ref_ang_list[i] = ref_ang[(nref1+nref2)*2+i]; 18091 nref = nref3; 18092 previous_group = -1; 18093 previous_zone = 3; 18094 } 18095 } else if (N_remain >= nref2*L) { 18096 if (previous_zone > 2) { 18097 ref_ang_list.resize(nref2*2); 18098 for (int i=0; i<nref2*2; i++) ref_ang_list[i] = ref_ang[nref1*2+i]; 18099 nref = nref2; 18100 previous_group = -1; 18101 previous_zone = 2; 18102 } 18103 } else if (N_remain >= nref1*L) { 18104 if (previous_zone > 1) { 18105 ref_ang_list.resize(nref1*2); 18106 for (int i=0; i<nref1*2; i++) ref_ang_list[i] = ref_ang[i]; 18107 nref = nref1; 18108 previous_group = -1; 18109 previous_zone = 1; 18110 } 18111 } else if (previous_zone > 0) { 18112 previous_group = -1; 18113 previous_zone = 0; 18114 } 18115 18116 vector<int> index; 18117 if (N_remain >= nref1*L) { 18118 if (previous_group == -1) { // which means it just changed zone 18119 vector<float> proj_ang_list(N_remain*2, 0.0f); 18120 remain_index.resize(N_remain); 18121 int l = 0; 18122 for (set<int>::const_iterator si = pt.begin(); si != pt.end(); ++si) { 18123 remain_index[l] = (*si); 18124 proj_ang_list[l*2] = projangles[(*si)*2]; 18125 proj_ang_list[l*2+1] = projangles[(*si)*2+1]; 18126 l++; 18127 } 18128 assert(N_remain == l); 18129 asg = assign_projangles(proj_ang_list, ref_ang_list); 18130 sg.resize(nref); 18131 for (int i=0; i<nref; i++) sg[i] = 0; 18132 for (int i=0; i<N_remain; i++) sg[asg[i]]++; 18133 } 18134 int max_group_size = 0; 18135 for (int i=0; i<nref; i++) 18136 if (sg[i] > max_group_size) { max_group_size = sg[i]; max_group = i; } 18137 for (unsigned int i=0; i<remain_index.size(); i++) 18138 if (asg[i] == max_group) index.push_back(remain_index[i]); 18139 } else { 18140 for (set<int>::const_iterator si = pt.begin(); si != pt.end(); ++si) 18141 index.push_back(*si); 18142 max_group = 0; 18143 } 18144 18145 int Nn = index.size(); 18146 if (max_group != previous_group) { 18147 diff_table.resize(Nn*Nn); 18148 diff_table_index.clear(); 18149 for (int i=0; i<Nn-1; i++) 18150 for (int j=i+1; j<Nn; j++) { 18151 float diff = ang_diff(v[index[i]*3], v[index[i]*3+1], v[index[i]*3+2], v[index[j]*3], v[index[j]*3+1], v[index[j]*3+2], mirror); 18152 float q = exp(-c*pow(diff/180.0f*static_cast<float>(M_PI), 2.0f)); 18153 diff_table[i*Nn+j] = q; 18154 diff_table[j*Nn+i] = q; 18155 } 18156 for (int i=0; i<Nn; i++) { 18157 diff_table[i*Nn+i] = 0.0f; // diagonal values 18158 diff_table_index[index[i]] = i; 18159 } 18160 previous_group = max_group; 18161 } 18162 18163 int diff_table_size = static_cast<int>(sqrt((float)diff_table.size())+0.5f); 18164 float max_density = -1; 18165 int max_density_i = -1; 18166 for (int i=0; i<Nn; i++) { 18167 float s = 0.0f; 18168 int z = diff_table_index[index[i]]; 18169 for (int j=0; j<diff_table_size; j++) s += diff_table[z*diff_table_size+j]; 18170 if (s > max_density) { 18171 max_density = s; 18172 max_density_i = i; 18173 } 18174 } 18175 18176 vector<d_ang> dang(Nn, d_ang(0.0, 0, 0)); 18177 for (int i=0; i<Nn; i++) { 18178 dang[i].d = ang_diff(v[index[i]*3], v[index[i]*3+1], v[index[i]*3+2], 18179 v[index[max_density_i]*3], v[index[max_density_i]*3+1], v[index[max_density_i]*3+2], mirror); 18180 dang[i].mirror = mirror; 18181 dang[i].i = i; 18182 } 18183 dang[max_density_i].d = -1; 18184 sort(dang.begin(), dang.end()); 18185 18186 for (int i=0; i<img_per_grp; i++) { 18187 int idd = index[dang[i].i]; 18188 mirror = dang[i].mirror; 18189 for (unsigned int j=0; j<remain_index.size(); j++) 18190 if (idd == remain_index[j]) asg[j] = -1; 18191 for (int j=0; j<diff_table_size; j++) { 18192 diff_table[diff_table_index[idd]*diff_table_size+j] = 0.0f; 18193 diff_table[diff_table_index[idd]+diff_table_size*j] = 0.0f; 18194 } 18195 proj_list.push_back(mirror*idd); 18196 pt.erase(idd); 18197 } 18198 sg[max_group] -= img_per_grp; 18199 } 18200 for (set<int>::const_iterator si = pt.begin(); si != pt.end(); ++si) { 18201 proj_list.push_back(*si); 18202 } 18203 return proj_list; 18204 }
vector< float > Util::hans | ( | EMData * | image, | |
const vector< EMData * > & | crefim, | |||
float | xrng, | |||
float | yrng, | |||
float | step, | |||
float | ant, | |||
string | mode, | |||
vector< int > | numr, | |||
float | cnx, | |||
float | cny | |||
) | [static] |
Definition at line 18424 of file util_sparx.cpp.
References ang_n(), Crosrng_ms(), EMAN::EMObject::f, Frngs(), EMAN::EMData::get_attr(), get_irand(), Normalize_ring(), pi, Polar2Dm(), EMAN::EMData::set_attr(), and EMAN::Dict::size().
18426 { 18427 18428 // Manually extract. 18429 /* vector< EMAN::EMData* > crefim; 18430 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 18431 crefim.reserve(crefim_len); 18432 18433 for(std::size_t i=0;i<crefim_len;i++) { 18434 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 18435 crefim.push_back(proxy()); 18436 } 18437 */ 18438 size_t crefim_len = crefim.size(); 18439 const float qv = static_cast<float>( pi/180.0 ); 18440 18441 //Transform * t = image->get_attr("xform.projection"); 18442 float previousmax = image->get_attr("previousmax"); 18443 //Dict d = t->get_params("spider"); 18444 //if(t) {delete t; t=0;} 18445 //float phi = d["phi"]; 18446 //float theta = d["theta"]; 18447 int ky = int(2*yrng/step+0.5)/2; 18448 int kx = int(2*xrng/step+0.5)/2; 18449 int iref, nref=0, mirror=0; 18450 float iy, ix, sx=0, sy=0; 18451 float peak = previousmax; 18452 float ang=0.0f; 18453 18454 vector< vector<EMData*> > cimages( 2*ky+1, vector<EMData*>(2*kx+1) ); 18455 18456 for (int i = -ky; i <= ky; i++) { 18457 iy = i * step ; 18458 for (int j = -kx; j <= kx; j++) { 18459 ix = j*step; 18460 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18461 Normalize_ring( cimage, numr ); 18462 Frngs(cimage, numr); 18463 cimages[i+ky][j+kx] = cimage; 18464 } 18465 } 18466 18467 vector<unsigned> listr(crefim_len); 18468 for (unsigned i = 0; i < crefim_len; ++i) listr[i] = i; 18469 for (unsigned i = 0; i < crefim_len; ++i) { 18470 unsigned r = Util::get_irand(0,crefim_len-1); 18471 swap( listr[r], listr[i] ); 18472 } 18473 18474 bool found_better = false; 18475 for ( int tiref = 0; (tiref < (int)crefim_len) && (! found_better); tiref++) { 18476 iref = listr[tiref]; 18477 float best_for_ref = -1.0E23f; 18478 for (int i = -ky; i <= ky; i++) { 18479 iy = i * step ; 18480 for (int j = -kx; j <= kx; j++) { 18481 ix = j*step; 18482 EMData* cimage = cimages[i+ky][j+kx]; 18483 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr); 18484 double qn = retvals["qn"]; 18485 double qm = retvals["qm"]; 18486 if (qn >= best_for_ref || qm >= best_for_ref) { 18487 sx = -ix; 18488 sy = -iy; 18489 nref = iref; 18490 if (qn >= qm) { 18491 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18492 peak = static_cast<float>( qn ); 18493 mirror = 0; 18494 } else { 18495 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 18496 peak = static_cast<float>( qm ); 18497 mirror = 1; 18498 } 18499 best_for_ref = peak; 18500 //cout <<" iref "<<iref<<" tiref "<<tiref<<" "<<previousmax<<" "<<qn<<" "<<qm<<endl; 18501 } 18502 } 18503 } 18504 found_better = (best_for_ref >= previousmax); 18505 } 18506 18507 for (unsigned i = 0; i < cimages.size(); ++i) { 18508 for (unsigned j = 0; j < cimages[i].size(); ++j) { 18509 delete cimages[i][j]; 18510 cimages[i][j] = NULL; 18511 } 18512 } 18513 18514 float sxs, sys; 18515 if (found_better) { 18516 float co = cos(ang*qv); 18517 float so = -sin(ang*qv); 18518 sxs = sx*co - sy*so; 18519 sys = sx*so + sy*co; 18520 image->set_attr("previousmax",peak); 18521 } else { 18522 ang=0.0; sxs=0.0; sys=0.0; mirror=0; 18523 nref = -1; 18524 peak = previousmax; 18525 } 18526 vector<float> res; 18527 res.push_back(ang); 18528 res.push_back(sxs); 18529 res.push_back(sys); 18530 res.push_back(static_cast<float>(mirror)); 18531 res.push_back(static_cast<float>(nref)); 18532 res.push_back(peak); 18533 return res; 18534 }
float Util::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 | |||
) | [static] |
Definition at line 5530 of file util_sparx.cpp.
References EMAN::EMData::get_data(), and img_ptr.
05531 { 05532 float *img_ptr = img->get_data(); 05533 float *mask_ptr = (mask == NULL)?img->get_data():mask->get_data(); 05534 05535 int *img_freq_bin = new int[3*hist_len]; 05536 for(int i = 0;i < (3*hist_len);i++) img_freq_bin[i] = 0; 05537 for(size_t i = 0;i < size_img;++i) { 05538 if(mask_ptr[i] > 0.5f) { 05539 float img_xn = img_ptr[i]*PA + PB; 05540 int L = static_cast<int>(((img_xn - ref_h_min)/ref_h_diff) * (hist_len-1) + hist_len+1); 05541 if(L >= 0 && L < (3*hist_len)) img_freq_bin[L]++; 05542 } 05543 } 05544 int freq_hist = 0; 05545 05546 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); 05547 freq_hist = (-freq_hist); 05548 return static_cast<float>(freq_hist); 05549 }
Definition at line 5438 of file util_sparx.cpp.
References 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.
05439 { 05440 /* Exception Handle */ 05441 if (img->is_complex() || ref->is_complex()) 05442 throw ImageFormatException("Cannot do Histogram on Fourier Image"); 05443 05444 if(mask != NULL){ 05445 if(img->get_xsize() != mask->get_xsize() || img->get_ysize() != mask->get_ysize() || img->get_zsize() != mask->get_zsize()) 05446 throw ImageDimensionException("The size of mask image should be of same size as the input image"); } 05447 /* ===================================================== */ 05448 05449 /* Image size calculation */ 05450 size_t size_ref = ((size_t)(ref->get_xsize())*(ref->get_ysize())*(ref->get_zsize())); 05451 size_t size_img = ((size_t)(img->get_xsize())*(img->get_ysize())*(img->get_zsize())); 05452 /* ===================================================== */ 05453 05454 /* The reference image attributes */ 05455 float *ref_ptr = ref->get_data(); 05456 float ref_h_min = ref->get_attr("minimum"); 05457 float ref_h_max = ref->get_attr("maximum"); 05458 float ref_h_avg = ref->get_attr("mean"); 05459 float ref_h_sig = ref->get_attr("sigma"); 05460 /* ===================================================== */ 05461 05462 /* Input image under mask attributes */ 05463 float *mask_ptr = (mask == NULL)?img->get_data():mask->get_data(); 05464 05465 vector<float> img_data = Util::infomask(img, mask); 05466 float img_avg = img_data[0]; 05467 float img_sig = img_data[1]; 05468 05469 /* The image under mask -- size calculation */ 05470 int cnt=0; 05471 for(size_t i=0;i<size_img;++i) 05472 if (mask_ptr[i]>0.5f) 05473 cnt++; 05474 /* ===================================================== */ 05475 05476 /* Histogram of reference image calculation */ 05477 float ref_h_diff = ref_h_max - ref_h_min; 05478 05479 #ifdef _WIN32 05480 int hist_len = _cpp_min((unsigned long)size_ref/16,_cpp_min((unsigned long)size_img/16,256lu)); 05481 #else 05482 int hist_len = std::min((unsigned long)size_ref/16,std::min((unsigned long)size_img/16,256lu)); 05483 #endif //_WIN32 05484 05485 float *ref_freq_bin = new float[3*hist_len]; 05486 05487 //initialize value in each bin to zero 05488 for (int i = 0;i < (3*hist_len);i++) ref_freq_bin[i] = 0.f; 05489 05490 for (size_t i = 0;i < size_ref;++i) { 05491 int L = static_cast<int>(((ref_ptr[i] - ref_h_min)/ref_h_diff) * (hist_len-1) + hist_len+1); 05492 ref_freq_bin[L]++; 05493 } 05494 for (int i = 0;i < (3*hist_len);i++) ref_freq_bin[i] *= static_cast<float>(cnt)/static_cast<float>(size_ref); 05495 05496 //Parameters Calculation (i.e) 'A' x + 'B' 05497 float A = ref_h_sig/img_sig; 05498 float B = ref_h_avg - (A*img_avg); 05499 05500 vector<float> args; 05501 args.push_back(A); 05502 args.push_back(B); 05503 05504 vector<float> scale; 05505 scale.push_back(1.e-7f*A); 05506 scale.push_back(-1.e-7f*B); 05507 05508 vector<float> ref_freq_hist; 05509 for(int i = 0;i < (3*hist_len);i++) ref_freq_hist.push_back((int)ref_freq_bin[i]); 05510 05511 vector<float> data; 05512 data.push_back(ref_h_diff); 05513 data.push_back(ref_h_min); 05514 05515 Dict parameter; 05516 05517 /* Parameters displaying the arguments A & B, and the scaling function and the data's */ 05518 parameter["args"] = args; 05519 parameter["scale"]= scale; 05520 parameter["data"] = data; 05521 parameter["ref_freq_bin"] = ref_freq_hist; 05522 parameter["size_img"]=(double)size_img; 05523 parameter["hist_len"]=hist_len; 05524 /* ===================================================== */ 05525 05526 return parameter; 05527 }
vector< float > Util::histogram | ( | EMData * | image, | |
EMData * | mask, | |||
int | nbins = 128 , |
|||
float | hmin = 0.0f , |
|||
float | hmax = 0.0f | |||
) | [static] |
Definition at line 5380 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.
05381 { 05382 if (image->is_complex()) 05383 throw ImageFormatException("Cannot do histogram on Fourier image"); 05384 //float hmax, hmin; 05385 float *imageptr=0, *maskptr=0; 05386 int nx=image->get_xsize(); 05387 int ny=image->get_ysize(); 05388 int nz=image->get_zsize(); 05389 05390 if(mask != NULL){ 05391 if(nx != mask->get_xsize() || ny != mask->get_ysize() || nz != mask->get_zsize()) 05392 throw ImageDimensionException("The size of mask image should be of same size as the input image"); 05393 maskptr =mask->get_data(); 05394 } 05395 if( nbins == 0) nbins = nx; 05396 vector <float> freq(2*nbins, 0.0); 05397 05398 imageptr=image->get_data(); 05399 if( hmin == hmax ) { 05400 if(mask == NULL) { 05401 hmax = image->get_attr("maximum"); 05402 hmin = image->get_attr("minimum"); 05403 } else { 05404 bool First = true; 05405 for (size_t i = 0;i < (size_t)nx*ny*nz; i++) { 05406 if (maskptr[i]>=0.5f) { 05407 if(First) { 05408 hmax = imageptr[i]; 05409 hmin = imageptr[i]; 05410 First = false; 05411 } else { 05412 hmax = (hmax < imageptr[i])?imageptr[i]:hmax; 05413 hmin = (hmin > imageptr[i])?imageptr[i]:hmin; 05414 } 05415 } 05416 } 05417 } 05418 } 05419 float hdiff = hmax - hmin; 05420 float ff = (nbins-1)/hdiff; 05421 for (int i = 0; i < nbins; i++) freq[nbins+i] = hmin + (float(i)+0.5f)/ff; 05422 if(mask == NULL) { 05423 for(size_t i = 0; i < (size_t)nx*ny*nz; i++) { 05424 int jbin = static_cast<int>((imageptr[i]-hmin)*ff + 1.5); 05425 if(jbin >= 1 && jbin <= nbins) freq[jbin-1] += 1.0; 05426 } 05427 } else { 05428 for(size_t i = 0; i < (size_t)nx*ny*nz; i++) { 05429 if(maskptr[i] >= 0.5) { 05430 int jbin = static_cast<int>((imageptr[i]-hmin)*ff + 1.5); 05431 if(jbin >= 1 && jbin <= nbins) freq[jbin-1] += 1.0; 05432 } 05433 } 05434 } 05435 return freq; 05436 }
void Util::hsortd | ( | double * | theta, | |
double * | phi, | |||
int * | key, | |||
int | len, | |||
int | option | |||
) | [static] |
Definition at line 7153 of file util_sparx.cpp.
References cmp1(), cmp2(), ENTERFUNC, EXITFUNC, key, phi, and theta.
07154 { 07155 ENTERFUNC; 07156 vector<tmpstruct> tmp(len); 07157 int i; 07158 for(i = 1;i<=len;i++) 07159 { 07160 tmp[i-1].theta1 = theta(i); 07161 tmp[i-1].phi1 = phi(i); 07162 tmp[i-1].key1 = key(i); 07163 } 07164 07165 if (option == 1) sort(tmp.begin(),tmp.end(),Util::cmp1); 07166 if (option == 2) sort(tmp.begin(),tmp.end(),Util::cmp2); 07167 07168 for(i = 1;i<=len;i++) 07169 { 07170 theta(i) = tmp[i-1].theta1; 07171 phi(i) = tmp[i-1].phi1; 07172 key(i) = tmp[i-1].key1; 07173 } 07174 EXITFUNC; 07175 }
static float EMAN::Util::hypot2 | ( | float | x, | |
float | y | |||
) | [inline, static] |
Euclidean distance function in 2D: f(x,y) = sqrt(x*x + y*y);.
[in] | x | The first number. |
[in] | y | The second number. |
Definition at line 1697 of file util.h.
Referenced by EMAN::FourierWeightAverager::add_image().
static float EMAN::Util::hypot3 | ( | double | x, | |
double | y, | |||
double | z | |||
) | [inline, static] |
static float EMAN::Util::hypot3 | ( | float | x, | |
float | y, | |||
float | z | |||
) | [inline, static] |
static float EMAN::Util::hypot3 | ( | int | x, | |
int | y, | |||
int | z | |||
) | [inline, static] |
Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);.
[in] | x | The first number. |
[in] | y | The second number. |
[in] | z | The third number. |
Definition at line 1736 of file util.h.
Referenced by EMAN::EMData::calc_radial_dist(), 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(), EMAN::RotationalAverageProcessor::process_inplace(), and EMAN::LowpassRandomPhaseProcessor::process_inplace().
static float EMAN::Util::hypot3sq | ( | float | x, | |
float | y, | |||
float | z | |||
) | [inline, static] |
static int EMAN::Util::hypot3sq | ( | int | x, | |
int | y, | |||
int | z | |||
) | [inline, static] |
Euclidean distance function squared in 3D: f(x,y,z) = (x*x + y*y + z*z);.
[in] | x | The first number. |
[in] | y | The second number. |
[in] | z | The third number. |
Definition at line 1714 of file util.h.
Referenced by EMAN::FourierInserter3DMode7::insert_pixel(), 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().
float Util::hypot_fast | ( | int | x, | |
int | y | |||
) | [static] |
Euclidean distance in 2D for integers computed fast using a cached lookup table.
[in] | x | The first number |
[in] | y | The second number |
Definition at line 747 of file util.cpp.
References abs.
Referenced by EMAN::EMData::calc_az_dist(), EMAN::EMData::calc_radial_dist(), and EMAN::EMAN2Ctf::compute_2d_complex().
00748 { 00749 static float *mem = (float *)malloc(4*128*128); 00750 static int dim = 0; 00751 x=abs(x); 00752 y=abs(y); 00753 00754 if (x>=dim || y>=dim) { 00755 if (x>2048 || y>2048) return (float)hypot((float)x,(float)y); // We won't cache anything bigger than 4096^2 00756 dim=x>=dim?x+1:dim; 00757 dim=y>=dim?y+1:dim; 00758 mem=(float*)realloc(mem,4*dim*dim); 00759 for (int y=0; y<dim; y++) { 00760 for (int x=0; x<dim; x++) { 00761 #ifdef _WIN32 00762 mem[x+y*dim]=(float)_hypot((float)x,(float)y); 00763 #else 00764 mem[x+y*dim]=hypot((float)x,(float)y); 00765 #endif 00766 } 00767 } 00768 } 00769 00770 return mem[x+y*dim]; 00771 }
short Util::hypot_fast_int | ( | int | x, | |
int | y | |||
) | [static] |
Euclidean distance in 2D for integers computed fast using a cached lookup table.
[in] | x | The first number |
[in] | y | The second number |
Definition at line 773 of file util.cpp.
Referenced by EMAN::PhaseCmp::cmp().
00774 { 00775 static short *mem = (short *)malloc(2*128*128); 00776 static int dim = 0; 00777 x=abs(x); 00778 y=abs(y); 00779 00780 if (x>=dim || y>=dim) { 00781 if (x>4095 || y>4095) return (short)hypot((float)x,(float)y); // We won't cache anything bigger than 4096^2 00782 dim=x>=dim?x+1:dim; 00783 dim=y>=dim?y+1:dim; 00784 mem=(short*)realloc(mem,2*dim*dim); 00785 for (int y=0; y<dim; y++) { 00786 for (int x=0; x<dim; x++) { 00787 #ifdef _WIN32 00788 mem[x+y*dim]=(short)Util::round(_hypot((float)x,(float)y)); 00789 #else 00790 mem[x+y*dim]=(short)Util::round(hypot((float)x,(float)y)); 00791 #endif 00792 } 00793 } 00794 } 00795 00796 return mem[x+y*dim]; 00797 }
Definition at line 150 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), ImageFormatException, EMAN::EMUtil::is_same_size(), LOGERR, nx, ny, EMAN::EMData::set_size(), EMAN::EMData::to_one(), and EMAN::EMData::update().
00151 { 00152 ENTERFUNC; 00153 00154 if (!EMUtil::is_same_size(V1, V2)) { 00155 LOGERR("images not same size"); 00156 throw ImageFormatException( "images not same size"); 00157 } 00158 00159 size_t nx = V1->get_xsize(); 00160 size_t ny = V1->get_ysize(); 00161 size_t nz = V1->get_zsize(); 00162 size_t size = (size_t)nx*ny*nz; 00163 00164 EMData *BD = new EMData(); 00165 BD->set_size(nx, ny, nz); 00166 00167 float *params = new float[2]; 00168 00169 float *V1ptr, *V2ptr, *MASKptr, *BDptr, A, B; 00170 long double S1=0.L,S2=0.L,S3=0.L,S4=0.L; 00171 int nvox = 0L; 00172 00173 V1ptr = V1->get_data(); 00174 V2ptr = V2->get_data(); 00175 BDptr = BD->get_data(); 00176 00177 00178 if(!mask){ 00179 EMData * Mask = new EMData(); 00180 Mask->set_size(nx,ny,nz); 00181 Mask->to_one(); 00182 MASKptr = Mask->get_data(); 00183 } else { 00184 if (!EMUtil::is_same_size(V1, mask)) { 00185 LOGERR("mask not same size"); 00186 throw ImageFormatException( "mask not same size"); 00187 } 00188 00189 MASKptr = mask->get_data(); 00190 } 00191 00192 00193 00194 // calculation of S1,S2,S3,S3,nvox 00195 00196 for (size_t i = 0L;i < size; i++) { 00197 if (MASKptr[i]>0.5f) { 00198 S1 += V1ptr[i]*V2ptr[i]; 00199 S2 += V1ptr[i]*V1ptr[i]; 00200 S3 += V2ptr[i]; 00201 S4 += V1ptr[i]; 00202 nvox ++; 00203 } 00204 } 00205 00206 if ((nvox*S1 - S3*S4) == 0. || (nvox*S2 - S4*S4) == 0) { 00207 A =1.0f ; 00208 } else { 00209 A = static_cast<float>( (nvox*S1 - S3*S4)/(nvox*S2 - S4*S4) ); 00210 } 00211 B = static_cast<float> (A*S4 - S3)/nvox; 00212 00213 // calculation of the difference image 00214 00215 for (size_t i = 0L;i < size; i++) { 00216 if (MASKptr[i]>0.5f) { 00217 BDptr[i] = A*V1ptr[i] - B - V2ptr[i]; 00218 } else { 00219 BDptr[i] = 0.f; 00220 } 00221 } 00222 00223 BD->update(); 00224 00225 params[0] = A; 00226 params[1] = B; 00227 00228 Dict BDnParams; 00229 BDnParams["imdiff"] = BD; 00230 BDnParams["A"] = params[0]; 00231 BDnParams["B"] = params[1]; 00232 00233 EXITFUNC; 00234 return BDnParams; 00235 }
void Util::image_mutation | ( | EMData * | img, | |
float | mutation_rate | |||
) | [static] |
Definition at line 20845 of file util_sparx.cpp.
References array_mutation(), EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), max, min, and nx.
20845 { 20846 int nx = img->get_xsize(); 20847 float min = img->get_attr("minimum"); 20848 float max = img->get_attr("maximum"); 20849 float* img_data = img->get_data(); 20850 array_mutation(img_data, nx*nx, mutation_rate, min, max, 8, 0); 20851 return; 20852 }
Definition at line 69 of file util_sparx.cpp.
References ENTERFUNC, 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().
00070 : find statistics under the mask (mask >0.5) 00071 // flip false: find statistics ourside the mask (mask <0.5) 00072 { 00073 ENTERFUNC; 00074 vector<float> stats; 00075 float *Volptr, *maskptr,MAX,MIN; 00076 long double Sum1,Sum2; 00077 long count; 00078 00079 MAX = -FLT_MAX; 00080 MIN = FLT_MAX; 00081 count = 0L; 00082 Sum1 = 0.0L; 00083 Sum2 = 0.0L; 00084 00085 if (mask == NULL) { 00086 //Vol->update_stat(); 00087 stats.push_back(Vol->get_attr("mean")); 00088 stats.push_back(Vol->get_attr("sigma")); 00089 stats.push_back(Vol->get_attr("minimum")); 00090 stats.push_back(Vol->get_attr("maximum")); 00091 return stats; 00092 } 00093 00094 /* Check if the sizes of the mask and image are same */ 00095 00096 size_t nx = Vol->get_xsize(); 00097 size_t ny = Vol->get_ysize(); 00098 size_t nz = Vol->get_zsize(); 00099 00100 size_t mask_nx = mask->get_xsize(); 00101 size_t mask_ny = mask->get_ysize(); 00102 size_t mask_nz = mask->get_zsize(); 00103 00104 if (nx != mask_nx || ny != mask_ny || nz != mask_nz ) 00105 throw ImageDimensionException("The dimension of the image does not match the dimension of the mask!"); 00106 00107 /* if (nx != mask_nx || 00108 ny != mask_ny || 00109 nz != mask_nz ) { 00110 // should throw an exception here!!! (will clean it up later CY) 00111 fprintf(stderr, "The dimension of the image does not match the dimension of the mask!\n"); 00112 fprintf(stderr, " nx = %d, mask_nx = %d\n", nx, mask_nx); 00113 fprintf(stderr, " ny = %d, mask_ny = %d\n", ny, mask_ny); 00114 fprintf(stderr, " nz = %d, mask_nz = %d\n", nz, mask_nz); 00115 exit(1); 00116 } 00117 */ 00118 Volptr = Vol->get_data(); 00119 maskptr = mask->get_data(); 00120 00121 for (size_t i = 0; i < (size_t)nx*ny*nz; ++i) { 00122 if ((maskptr[i]>0.5f) == flip) { 00123 Sum1 += Volptr[i]; 00124 Sum2 += Volptr[i]*double(Volptr[i]); 00125 MAX = (MAX < Volptr[i])?Volptr[i]:MAX; 00126 MIN = (MIN > Volptr[i])?Volptr[i]:MIN; 00127 count++; 00128 } 00129 } 00130 00131 if (count == 0) { 00132 LOGERR("Invalid mask"); 00133 throw ImageFormatException( "Invalid mask"); 00134 } 00135 00136 float avg = static_cast<float>(Sum1/count); 00137 float sig = static_cast<float>(sqrt((Sum2 - Sum1*Sum1/count)/(count-1))); 00138 00139 stats.push_back(avg); 00140 stats.push_back(sig); 00141 stats.push_back(MIN); 00142 stats.push_back(MAX); 00143 00144 return stats; 00145 }
void Util::initial_prune | ( | vector< vector< int * > > & | Parts, | |
int * | dimClasses, | |||
int | nParts, | |||
int | K, | |||
int | T | |||
) | [static] |
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 21140 of file util_sparx.cpp.
References b, explore(), and k_means_cont_table_().
21140 { 21141 //cout<<"initial_prune\n"; 21142 // simple initial pruning. For class indClass of partition indPart: 21143 // 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 21144 // If for some partition (not equal to indPart) for which there is no such class, then return 0 immediately. 21145 21146 // 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 21147 21148 // remember when calling k_means_cont_table, the first element of each class is an index, and actual number of elements in the class 21149 // (as stored in dimClasses) should be decremented by 1 accordingly, and second is dummy variable 21150 21151 int* dummy(0); 21152 int* cref; 21153 int cref_size; 21154 int* ccomp; 21155 int ccomp_size; 21156 int nintx; 21157 for (int i=0; i < nParts; i++){ 21158 for (int j =0; j < K; j++){ 21159 21160 // consider class Parts[i][j] 21161 cref = Parts[i][j];//incr by 1 since first element is index and second is dummy 21162 cref_size = dimClasses[i*K+cref[0]]-2; 21163 21164 21165 if (cref_size <= T){ 21166 cref[0] = -1; 21167 continue; 21168 } 21169 bool done = 0; 21170 for (int a = 0; a < nParts; a++){ 21171 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 21172 bool hasActive=0; 21173 for (unsigned int b=0; b < Parts[a].size(); b++){ 21174 // get the card of the intx between Parts[i][j] and Parts[a][b] using k_means_cont_table 21175 // remember first element of each class is the index of the class 21176 ccomp = Parts[a][b]; 21177 ccomp_size= dimClasses[a*K+ccomp[0]]-2; 21178 nintx = Util::k_means_cont_table_(cref+2,ccomp+2, dummy, cref_size, ccomp_size,0); 21179 21180 21181 if (nintx <= T) 21182 ccomp[1] = 0; // class Parts[a][b] is 'inactive' for cref 21183 else{ 21184 ccomp[1] = 1; // class Parts[a][b] is 'active' for cref 21185 hasActive=1; 21186 } 21187 } 21188 // see if partition a has at least one active class.if not then we're done with cref 21189 if (hasActive < 1){ 21190 done=1; 21191 break; 21192 } 21193 21194 } 21195 21196 if (done > 0){ 21197 // remove class j from partition i 21198 21199 cref[0] = -1; // mark for deletion later 21200 continue; // move on to class Parts[i][j+1] 21201 } 21202 21203 // now we adopt more aggressive measures. we find the match with the largest weight which has class Parts[i][j] for partition i. 21204 // 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. 21205 21206 // (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. 21207 // Note that if there are ALOT of partitions, then sorting the partititions may actually take longer than the time saved by ordering hte 21208 // partitions. However, we do not have a lot of partitions, (usually around 10), so sorting time will be trivial compared to exploring time. 21209 21210 // explore returns one if there is a feasible matching containing class cref which has weight gt T, and otherwise returns 0 21211 //bool found = 1; 21212 bool found = explore(Parts, dimClasses, nParts, K, T, i, cref+2, cref_size, cref, cref_size,0); 21213 21214 if (found<1){ // There is NO feasible matching with class j (cref) with weight greater than T, so delete this class from Parts 21215 // Parts[i].erase(Parts[i].begin()+j); 21216 cref[0] = -1; 21217 } 21218 } 21219 21220 // Erase from Parts[i] all the classes that's being designated for erasure 21221 21222 for (int d = K-1; d > -1; d--){ 21223 if (Parts[i][d][0] < 0) Parts[i].erase(Parts[i].begin()+d); 21224 } 21225 21226 } 21227 //cout <<"number of classes left in each partition after initial prune\n"; 21228 // Print out how many classes are left in each partition 21229 //for (int i =0; i < nParts; i++) 21230 // cout << Parts[i].size()<<", "; 21231 //cout << "\n"; 21232 }
string Util::int2str | ( | int | n | ) | [static] |
Get a string format of an integer, e.g.
123 will be "123".
[in] | n | The input integer. |
Definition at line 294 of file util.cpp.
Referenced by EMAN::Log::loc(), EMAN::SerIO::read_dim_arr(), and EMAN::E2Exception::what().
bool Util::is_file_exist | ( | const string & | filename | ) | [static] |
check whether a file exists or not
Definition at line 242 of file util.cpp.
Referenced by EMAN::TestUtil::check_image(), EMAN::GlobalCache::get_imageio(), EMAN::SpiderIO::SpiderIO(), and EMAN::EMData::write_image().
00243 { 00244 if (access(filename.c_str(), F_OK) == 0) { 00245 return true; 00246 } 00247 return false; 00248 }
static bool EMAN::Util::IsPower2 | ( | int | x | ) | [inline, static] |
Return true if an integer is positive and is power of 2.
[in] | x | integer to be checked |
Definition at line 2189 of file util.h.
Referenced by EMAN::WaveletProcessor::process_inplace().
int Util::k_means_cont_table_ | ( | int * | group1, | |
int * | group2, | |||
int * | stb, | |||
long int | s1, | |||
long int | s2, | |||
int | flag | |||
) | [static] |
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 5067 of file util_sparx.cpp.
References max.
05067 { 05068 long int d2 = group2[s2 - 1] - group2[0]; 05069 long int p2 = 0; 05070 long int i1 = 0; 05071 long int i2 = 0; 05072 long int max = 0; 05073 long int cont = 0; 05074 long int i = 0; 05075 int stop1 = 0; 05076 int stop2 = 0; 05077 05078 for (i=0; i<s1; i++) { 05079 p2 = (long int)(s2 * (double)group1[i] / (double)d2); 05080 if (p2 >= s2) {p2 = s2 - 1;} 05081 i1 = p2; 05082 i2 = p2; 05083 max = s2; 05084 if (group1[i] < group2[0] || group1[i] > group2[s2 - 1]) {continue;} 05085 05086 stop1 = 0; 05087 stop2 = 0; 05088 while (max--) { 05089 if (group1[i] == group2[i1]) { 05090 if (flag) {stb[cont] = group1[i];} 05091 cont++; 05092 break; 05093 } 05094 if (group2[i1] < group1[i]) {stop1=1;} 05095 if (group1[i] == group2[i2]) { 05096 if (flag) {stb[cont] = group1[i];} 05097 cont++; 05098 break; 05099 } 05100 if (group2[i2] > group1[i]) {stop2=1;} 05101 //printf("i1 %li i2 %li v2 %i v2 %i stop1 %i stop2 %i\n", i1, i2, group2[i1], group2[i2], stop1, stop2); 05102 05103 if (stop1 & stop2) {break;} 05104 i1--; 05105 i2++; 05106 if (i1 < 0) {i1 = 0;} 05107 if (i2 >= s2) {i2 = s2 - 1;} 05108 } 05109 //printf("v1: %i ite: %li cont: %li\n", group1[i], s2-max, cont); 05110 } 05111 05112 return cont; 05113 }
static float EMAN::Util::linear_interpolate | ( | float | p1, | |
float | p2, | |||
float | t | |||
) | [inline, static] |
Calculate linear interpolation.
[in] | p1 | The first number (at x1). |
[in] | p2 | The second number (at x2). |
[in] | t | (x-x1)/(x2-x1) |
Definition at line 1555 of file util.h.
Referenced by EMAN::EMData::cut_slice(), EMAN::WienerFourierReconstructor::do_insert_slice_work(), EMAN::MaxValProjector::project3d(), and EMAN::StandardProjector::project3d().
vector< float > Util::list_mutation | ( | vector< float > | list, | |
float | mutation_rate, | |||
float | min_val, | |||
float | max_val, | |||
int | K, | |||
int | is_mirror | |||
) | [static] |
Definition at line 20908 of file util_sparx.cpp.
20908 { 20909 20910 if (is_mirror != 0) { 20911 for (vector<float>::iterator q=list.begin(); q!=list.end(); q++) { 20912 int r = rand()%10000; 20913 float f = r/10000.0f; 20914 if (f < mutation_rate) *q = 1-*q; 20915 } 20916 } else { 20917 map<int, vector<int> > graycode; 20918 map<vector<int>, int> rev_graycode; 20919 vector <int> gray; 20920 20921 int K=1; 20922 for (int i=0; i<L; i++) K*=2; 20923 20924 for (int k=0; k<K; k++) { 20925 int shift = 0; 20926 vector <int> gray; 20927 for (int i=L-1; i>-1; i--) { 20928 int t = ((k>>i)%2-shift)%2; 20929 gray.push_back(t); 20930 shift += t-2; 20931 } 20932 graycode[k] = gray; 20933 rev_graycode[gray] = k; 20934 } 20935 20936 float gap = (K-1)/(max_val-min_val); 20937 for (vector<float>::iterator q=list.begin(); q!=list.end(); q++) { 20938 float val = *q; 20939 if (val < min_val) { val = min_val; } 20940 else if (val > max_val) { val = max_val; } 20941 int k = int((val-min_val)*gap+0.5); 20942 vector<int> gray = graycode[k]; 20943 bool changed = false; 20944 for (vector<int>::iterator p=gray.begin(); p!=gray.end(); p++) { 20945 int r = rand()%10000; 20946 float f = r/10000.0f; 20947 if (f < mutation_rate) { 20948 *p = 1-*p; 20949 changed = true; 20950 } 20951 } 20952 if (changed) { 20953 k = rev_graycode[gray]; 20954 *q = k/gap+min_val; 20955 } 20956 } 20957 } 20958 return list; 20959 }
vector< float > Util::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 | |||
) | [static] |
Definition at line 6360 of file util_sparx.cpp.
References cl1().
06361 { 06362 /* System generated locals */ 06363 long int q_dim1, q_offset, q1_dim1, q1_offset, i__1, i__2; 06364 06365 /* Local variables */ 06366 long int i__, j, m, n1, ii, jj; 06367 double tmp; 06368 vector<float> p; 06369 --x; 06370 q_dim1 = *klm2d; 06371 q_offset = 1 + q_dim1; 06372 q -= q_offset; 06373 q1_dim1 = *klm2d; 06374 q1_offset = 1 + q1_dim1; 06375 q1 -= q1_offset; 06376 --s; 06377 --res; 06378 iu -= 3; 06379 cu -= 3; 06380 06381 /* Function Body */ 06382 long int l = 0; 06383 06384 /* C==ZHONG HUANG,JULY,12,02;L=0,1,2,3,4,5,6 correspond to different equality constraints */ 06385 m = *ks; 06386 n1 = *n + 1; 06387 if (*iswi == 1) { 06388 i__1 = n1; 06389 for (jj = 1; jj <= i__1; ++jj) { 06390 i__2 = *ks; 06391 for (ii = 1; ii <= i__2; ++ii) { 06392 /* q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];*/ 06393 06394 q[*ks + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1] 06395 ; 06396 } 06397 } 06398 } else if (*iswi == 2) { 06399 i__1 = *ks; 06400 for (ii = 1; ii <= i__1; ++ii) { 06401 i__2 = n1; 06402 for (jj = 1; jj <= i__2; ++jj) { 06403 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06404 q[*ks + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06405 } 06406 } 06407 } else if (*iswi == 3) { 06408 l = 2; 06409 i__1 = n1; 06410 for (jj = 1; jj <= i__1; ++jj) { 06411 i__2 = *ks + 2; 06412 for (ii = 1; ii <= i__2; ++ii) { 06413 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06414 } 06415 i__2 = *ks; 06416 for (ii = 1; ii <= i__2; ++ii) { 06417 q[*ks + 2 + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06418 } 06419 } 06420 } else if (*iswi == 4) { 06421 l = 2; 06422 i__1 = n1; 06423 for (jj = 1; jj <= i__1; ++jj) { 06424 i__2 = *ks + 2; 06425 for (ii = 1; ii <= i__2; ++ii) { 06426 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06427 } 06428 i__2 = *ks; 06429 for (ii = 1; ii <= i__2; ++ii) { 06430 q[*ks + 2 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06431 } 06432 } 06433 } else if (*iswi == 5) { 06434 l = 1; 06435 i__1 = n1; 06436 for (jj = 1; jj <= i__1; ++jj) { 06437 i__2 = *ks + 1; 06438 for (ii = 1; ii <= i__2; ++ii) { 06439 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06440 } 06441 i__2 = *ks; 06442 for (ii = 1; ii <= i__2; ++ii) { 06443 q[*ks + 1 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06444 } 06445 } 06446 } else if (*iswi == 6) { 06447 l = 1; 06448 i__1 = n1; 06449 for (jj = 1; jj <= i__1; ++jj) { 06450 i__2 = *ks + 1; 06451 for (ii = 1; ii <= i__2; ++ii) { 06452 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06453 } 06454 i__2 = *ks; 06455 for (ii = 1; ii <= i__2; ++ii) { 06456 q[*ks + 1 + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06457 } 06458 } 06459 } else if (*iswi == 7) { 06460 l = 3; 06461 i__1 = n1; 06462 for (jj = 1; jj <= i__1; ++jj) { 06463 i__2 = *ks + 3; 06464 for (ii = 1; ii <= i__2; ++ii) { 06465 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06466 } 06467 i__2 = *ks; 06468 for (ii = 1; ii <= i__2; ++ii) { 06469 q[*ks + 3 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06470 } 06471 } 06472 } else if (*iswi == 8) { 06473 l = 4; 06474 i__1 = n1; 06475 for (jj = 1; jj <= i__1; ++jj) { 06476 i__2 = *ks + 4; 06477 for (ii = 1; ii <= i__2; ++ii) { 06478 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06479 } 06480 i__2 = *ks; 06481 for (ii = 1; ii <= i__2; ++ii) { 06482 q[*ks + 4 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06483 } 06484 } 06485 } 06486 06487 Util::cl1(ks, &l, &m, n, klm2d, &q[q_offset], &x[1], &res[1], &cu[3], &iu[3], &s[1]); 06488 i__1 = *ks; 06489 int tmp__j=0; 06490 for (i__ = 1; i__ <= i__1; ++i__) { 06491 tmp = 0.f; 06492 i__2 = *n - 1; 06493 for (j = 1; j <= i__2; ++j) { 06494 tmp__j=j; 06495 tmp += pow(q1[i__ + q1_dim1], tmp__j) * x[j]; 06496 } 06497 tmp += x[*n]; 06498 p.push_back(static_cast<float>(exp(tmp))); 06499 p.push_back(q1[i__ + q1_dim1]); 06500 } 06501 i__2=*n; 06502 for (i__=1;i__<=i__2;++i__) 06503 { p.push_back(static_cast<float>(x[i__]));} 06504 return p; 06505 }
Definition at line 17472 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, 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().
17473 { 17474 ENTERFUNC; 17475 /* Exception Handle */ 17476 if (!img) { 17477 throw NullPointerException("NULL input image"); 17478 } 17479 /* ============== img += scalar*img1 ================ */ 17480 17481 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17482 size_t size = (size_t)nx*ny*nz; 17483 float *img_ptr = img->get_data(); 17484 float *img1_ptr = img1->get_data(); 17485 for (size_t i=0;i<size;++i)img_ptr[i] += img1_ptr[i]*scalar; 17486 img1->update(); 17487 17488 EXITFUNC; 17489 }
Definition at line 17282 of file util_sparx.cpp.
References EMAN::EMData::copy_head(), ENTERFUNC, EXITFUNC, 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().
17283 { 17284 ENTERFUNC; 17285 /* Exception Handle */ 17286 if (!img) { 17287 throw NullPointerException("NULL input image"); 17288 } 17289 /* ============== output = img + scalar*img1 ================ */ 17290 17291 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17292 size_t size = (size_t)nx*ny*nz; 17293 EMData * img2 = img->copy_head(); 17294 float *img_ptr = img->get_data(); 17295 float *img2_ptr = img2->get_data(); 17296 float *img1_ptr = img1->get_data(); 17297 for (size_t i=0;i<size;++i) img2_ptr[i] = img_ptr[i] + img1_ptr[i]*scalar; 17298 img2->update(); 17299 if(img->is_complex()) { 17300 img2->set_complex(true); 17301 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17302 } 17303 17304 EXITFUNC; 17305 return img2; 17306 }
static double EMAN::Util::mean | ( | double * | x, | |
int | n | |||
) | [inline, static] |
Definition at line 1111 of file util.h.
Referenced by get_stats(), get_stats_cstyle(), and multi_align_error_dfunc().
vector< float > Util::merge_peaks | ( | vector< float > | peak1, | |
vector< float > | peak2, | |||
float | p_size | |||
) | [static] |
Definition at line 6144 of file util_sparx.cpp.
06145 { 06146 vector<float>new_peak; 06147 int n1=peak1.size()/3; 06148 float p_size2=p_size*p_size; 06149 for (int i=0;i<n1;++i) { 06150 vector<float>::iterator it2= peak1.begin()+3*i; 06151 bool push_back1=true; 06152 int n2=peak2.size()/3; 06153 /*cout<<"peak2 size==="<<n2<<"i====="<<i<<endl; 06154 cout<<"new peak size==="<<new_peak.size()/3<<endl;*/ 06155 if(n2 ==0) { 06156 new_peak.push_back(*it2); 06157 new_peak.push_back(*(it2+1)); 06158 new_peak.push_back(*(it2+2)); 06159 } else { 06160 int j=0; 06161 while (j< n2-1 ) { 06162 vector<float>::iterator it3= peak2.begin()+3*j; 06163 float d2=((*(it2+1))-(*(it3+1)))*((*(it2+1))-(*(it3+1)))+((*(it2+2))-(*(it3+2)))*((*(it2+2))-(*(it3+2))); 06164 if(d2< p_size2 ) { 06165 if( (*it2)<(*it3) ) { 06166 new_peak.push_back(*it3); 06167 new_peak.push_back(*(it3+1)); 06168 new_peak.push_back(*(it3+2)); 06169 peak2.erase(it3); 06170 peak2.erase(it3); 06171 peak2.erase(it3); 06172 push_back1=false; 06173 } else { 06174 peak2.erase(it3); 06175 peak2.erase(it3); 06176 peak2.erase(it3); 06177 } 06178 } else j=j+1; 06179 n2=peak2.size()/3; 06180 } 06181 if(push_back1) { 06182 new_peak.push_back(*it2); 06183 new_peak.push_back(*(it2+1)); 06184 new_peak.push_back(*(it2+2)); 06185 } 06186 } 06187 } 06188 return new_peak; 06189 }
helper function for k-means
Definition at line 4992 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), nx, and ny.
04992 { 04993 ENTERFUNC; 04994 04995 int nima = data.size(); 04996 vector<float> res(nima); 04997 double result = 0.; 04998 double valmin = 1.0e20; 04999 int valpos = -1; 05000 05001 for (int kk=0; kk<nima; kk++){ 05002 result = 0; 05003 //validate_input_args(image, data[kk]); 05004 05005 float *y_data = data[kk]->get_data(); 05006 float *x_data = image->get_data(); 05007 05008 // Implemented by PAP 01/09/06 - please do not change. If in doubts, write/call me. 05009 int nx = data[kk]->get_xsize(); 05010 int ny = data[kk]->get_ysize(); 05011 nx = (nx - 2 + data[kk]->is_fftodd()); // nx is the real-space size of the input image 05012 int lsd2 = (nx + 2 - nx%2) ; // Extended x-dimension of the complex image 05013 05014 int ixb = 2*((nx+1)%2); 05015 int iyb = ny%2; 05016 int iz = 0; 05017 05018 for ( int iy = 0; iy <= ny-1; iy++) { 05019 for ( int ix = 2; ix <= lsd2 - 1 - ixb; ix++) { 05020 int ii = ix + (iy + iz * ny)* lsd2; 05021 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05022 } 05023 } 05024 for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) { 05025 int ii = (iy + iz * ny)* lsd2; 05026 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05027 result += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]); 05028 } 05029 if(nx%2 == 0) { 05030 for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) { 05031 int ii = lsd2 - 2 + (iy + iz * ny)* lsd2; 05032 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05033 result += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]); 05034 } 05035 05036 } 05037 result *= 2; 05038 result += (x_data[0] - y_data[0])*double(x_data[0] - y_data[0]); 05039 if(ny%2 == 0) { 05040 int ii = (ny/2 + iz * ny)* lsd2; 05041 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05042 } 05043 if(nx%2 == 0) { 05044 int ii = lsd2 - 2 + (0 + iz * ny)* lsd2; 05045 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05046 if(ny%2 == 0) { 05047 int ii = lsd2 - 2 +(ny/2 + iz * ny)* lsd2; 05048 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05049 } 05050 } 05051 05052 result /= (long int)nx*(long int)ny*(long int)nx*(long int)ny; 05053 res[kk] = (float)result; 05054 05055 if(result<valmin) {valmin = result; valpos = kk;} 05056 05057 } 05058 05059 Dict retvals; 05060 retvals["dist"] = res; 05061 retvals["pos"] = valpos; 05062 05063 EXITFUNC; 05064 return retvals; 05065 }
k-means helper
Definition at line 4957 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), and EMAN::EMData::get_ysize().
04957 { 04958 ENTERFUNC; 04959 04960 int nima = data.size(); 04961 vector<float> res(nima); 04962 double result = 0.; 04963 double valmin = 1.0e20; 04964 int valpos = -1; 04965 04966 for (int kk=0; kk<nima; kk++){ 04967 result = 0; 04968 04969 float *y_data = data[kk]->get_data(); 04970 float *x_data = image->get_data(); 04971 long totsize = image->get_xsize()*image->get_ysize(); 04972 for (long i = 0; i < totsize; i++) { 04973 double temp = x_data[i]- y_data[i]; 04974 result += temp*temp; 04975 } 04976 result /= totsize; 04977 res[kk] = (float)result; 04978 04979 if(result<valmin) {valmin = result; valpos = kk;} 04980 04981 } 04982 04983 Dict retvals; 04984 retvals["dist"] = res; 04985 retvals["pos"] = valpos; 04986 04987 EXITFUNC; 04988 return retvals; 04989 04990 }
static int EMAN::Util::mono | ( | int | k1, | |
int | k2 | |||
) | [inline, static] |
Definition at line 19973 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), get_frand(), get_irand(), 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().
19974 { 19975 ENTERFUNC; 19976 /* Exception Handle */ 19977 if (!img) { 19978 throw NullPointerException("NULL input image"); 19979 } 19980 cout <<" VERSION 05/20/2013 3:00pm"<<endl; 19981 int newx, newy, newz; 19982 bool keep_going; 19983 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 19984 //int size = nx*ny*nz; 19985 EMData * img2 = new EMData(); 19986 img2->set_size(nx,ny,nz); 19987 img2->to_zero(); 19988 float *img_ptr =img->get_data(); 19989 float *img2_ptr = img2->get_data(); 19990 int r2 = ro*ro; 19991 int r3 = r2*ro; 19992 int ri2 = ri*ri; 19993 int ri3 = ri2*ri; 19994 19995 int n2 = nx/2; 19996 19997 for (int k=-n2; k<=n2; k++) { //cout << " k "<<k <<endl; 19998 float z2 = static_cast<float>(k*k); 19999 for (int j=-n2; j<=n2; j++) { 20000 float y2 = z2 + j*j; 20001 if(y2 <= r2) { 20002 //cout << " j "<<j <<endl; 20003 20004 for (int i=-n2; i<=n2; i++) { 20005 float x2 = y2 + i*i; 20006 if(x2 <= r3) { 20007 //cout << " i "<<i <<endl; 20008 int ib = i+n2; int jb = j+n2; int kb = k+n2; 20009 if(x2 >= ri3) { 20010 // this is the outer shell, here points can only vanish 20011 if(img_ptr(ib,jb,kb) == 1.0f) { 20012 //cout << " 1 "<<ib <<endl; 20013 if(Util::get_frand(0.0f, 1.0f) > qprob){ 20014 img2_ptr(ib,jb,kb) = 0.0f; 20015 keep_going = true; 20016 //cout << " try "<<ib <<endl; 20017 while(keep_going) { 20018 newx = Util::get_irand(-ro,ro); 20019 newy = Util::get_irand(-ro,ro); 20020 newz = Util::get_irand(-ro,ro); 20021 if(newx*newx+newy*newy+newz*newz <= r3) { 20022 newx += n2; newy += n2; newz += n2; 20023 if( img_ptr(newx,newy,newz) == 0.0f) { 20024 img2_ptr(newx,newy,newz) = 1.0f; 20025 keep_going = false; } 20026 } 20027 } 20028 } else img2_ptr(ib,jb,kb) = 1.0f; 20029 } 20030 } else { 20031 // this is inner shell, the point can only move (or vanish, if all neighbors exist) 20032 if(img_ptr(ib,jb,kb) == 1.0) { 20033 if(Util::get_frand(0.0f,1.0f) > qprob) { 20034 // find out the number of neighbors 20035 float numn = -1.0f; // we already know the central one is 1 20036 for (newz = -1; newz <= 1; newz++) 20037 for (newy = -1; newy <= 1; newy++) 20038 for (newx = -1; newx <= 1; newx++) 20039 numn += img_ptr(ib+newx,jb+newy,kb+newz); 20040 img2_ptr(ib,jb,kb) = 0.0; 20041 if(numn == 26.0f) { 20042 // all neighbors exist, it has to vanish 20043 keep_going = true; 20044 while(keep_going) { 20045 newx = Util::get_irand(-ro,ro); 20046 newy = Util::get_irand(-ro,ro); 20047 newz = Util::get_irand(-ro,ro); 20048 if(newx*newx+newy*newy+newz*newz < r3) { 20049 newx += n2; newy += n2; newz += n2; 20050 if( img_ptr(newx,newy,newz) == 0.0f) { 20051 if(newx*newx+newy*newy+newz*newz < r3) { 20052 if(newx*newx+newy*newy+newz*newz < r3) { 20053 newx += n2; newy += n2; newz += n2; 20054 if( img_ptr(newx,newy,newz) == 0.0f) { 20055 img2_ptr(newx,newy,newz) = 1.0f; 20056 keep_going = false; } 20057 } 20058 } 20059 } 20060 } 20061 } 20062 } else if(numn == 25.0f) { 20063 // there is only one empty neighbor, move there 20064 for (newz = -1; newz <= 1; newz++) { 20065 for (newy = -1; newy <= 1; newy++) { 20066 for (newx = -1; newx <= 1; newx++) { 20067 if( newx != 0 && newy != 0 && newz != 0) { 20068 if(img_ptr(newx+ib,newy+jb,newz+kb) == 0.0f) { 20069 img2_ptr(newx+ib,newy+jb,newz+kb) = 1.0f; 20070 } 20071 } 20072 } 20073 } 20074 } 20075 } else { 20076 // more than one neighbor is zero, select randomly one and move there 20077 keep_going = true; 20078 while(keep_going) { 20079 newx = Util::get_irand(-1,1); 20080 newy = Util::get_irand(-1,1); 20081 newz = Util::get_irand(-1,1); 20082 if(newx != 0 && newy != 0 && newz != 0) { 20083 if(img_ptr(ib+newx,jb+newy,kb+newz) == 0.0f) { 20084 img2_ptr(ib+newx,jb+newy,kb+newz) = 1.0f;//????? 20085 keep_going = false; 20086 } 20087 } 20088 } 20089 } 20090 } else img2_ptr(ib,jb,kb) = 1.0f; 20091 } 20092 } 20093 } 20094 } 20095 } 20096 } 20097 } 20098 //for (int i=0;i<size;i++) img2_ptr[i] = img_ptr[i] + Util::get_irand(1,7); 20099 img2->update(); 20100 20101 EXITFUNC; 20102 return img2; 20103 }
Definition at line 17571 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, 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().
17572 { 17573 ENTERFUNC; 17574 /* Exception Handle */ 17575 if (!img) { 17576 throw NullPointerException("NULL input image"); 17577 } 17578 /* ========= img *= img1 ===================== */ 17579 17580 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17581 size_t size = (size_t)nx*ny*nz; 17582 float *img_ptr = img->get_data(); 17583 float *img1_ptr = img1->get_data(); 17584 if(img->is_complex()) { 17585 for (size_t i=0; i<size; i+=2) { 17586 float tmp = img_ptr[i] * img1_ptr[i] - img_ptr[i+1] * img1_ptr[i+1] ; 17587 img_ptr[i+1] = img_ptr[i] * img1_ptr[i+1] + img_ptr[i+1] * img1_ptr[i] ; 17588 img_ptr[i] = tmp; 17589 17590 } 17591 } else { 17592 for (size_t i=0;i<size;++i) img_ptr[i] *= img1_ptr[i]; 17593 } 17594 img->update(); 17595 17596 EXITFUNC; 17597 }
void Util::mul_scalar | ( | EMData * | img, | |
float | scalar | |||
) | [static] |
Definition at line 17454 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, 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().
17455 { 17456 ENTERFUNC; 17457 /* Exception Handle */ 17458 if (!img) { 17459 throw NullPointerException("NULL input image"); 17460 } 17461 /* ============ output = scalar*input ================== */ 17462 17463 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17464 size_t size = (size_t)nx*ny*nz; 17465 float *img_ptr =img->get_data(); 17466 for (size_t i=0;i<size;++i) img_ptr[i] *= scalar; 17467 img->update(); 17468 17469 EXITFUNC; 17470 }
Definition at line 17360 of file util_sparx.cpp.
References EMAN::EMData::copy_head(), ENTERFUNC, EXITFUNC, 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().
17361 { 17362 ENTERFUNC; 17363 /* Exception Handle */ 17364 if (!img) { 17365 throw NullPointerException("NULL input image"); 17366 } 17367 /* ============== output = img * img1 ================ */ 17368 17369 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17370 size_t size = (size_t)nx*ny*nz; 17371 EMData * img2 = img->copy_head(); 17372 float *img_ptr = img->get_data(); 17373 float *img2_ptr = img2->get_data(); 17374 float *img1_ptr = img1->get_data(); 17375 if(img->is_complex()) { 17376 for (size_t i=0; i<size; i+=2) { 17377 img2_ptr[i] = img_ptr[i] * img1_ptr[i] - img_ptr[i+1] * img1_ptr[i+1] ; 17378 img2_ptr[i+1] = img_ptr[i] * img1_ptr[i+1] + img_ptr[i+1] * img1_ptr[i] ; 17379 } 17380 img2->set_complex(true); 17381 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17382 } else { 17383 for (size_t i=0; i<size; ++i) img2_ptr[i] = img_ptr[i] * img1_ptr[i]; 17384 img2->update(); 17385 } 17386 17387 EXITFUNC; 17388 return img2; 17389 }
Definition at line 17257 of file util_sparx.cpp.
References EMAN::EMData::copy_head(), ENTERFUNC, EXITFUNC, 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().
17258 { 17259 ENTERFUNC; 17260 /* Exception Handle */ 17261 if (!img) { 17262 throw NullPointerException("NULL input image"); 17263 } 17264 /* ============ output = scalar*input ================== */ 17265 17266 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17267 size_t size = (size_t)nx*ny*nz; 17268 EMData * img2 = img->copy_head(); 17269 float *img_ptr = img->get_data(); 17270 float *img2_ptr = img2->get_data(); 17271 for (size_t i=0;i<size;++i)img2_ptr[i] = img_ptr[i]*scalar; 17272 img2->update(); 17273 17274 if(img->is_complex()) { 17275 img2->set_complex(true); 17276 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17277 } 17278 EXITFUNC; 17279 return img2; 17280 }
vector< float > Util::multi_align_error | ( | vector< float > | args, | |
vector< float > | all_ali_params, | |||
int | d | |||
) | [static] |
Definition at line 19708 of file util_sparx.cpp.
References multi_align_error_dfunc(), multi_align_error_func(), setulb_(), and SIXTY.
19708 { 19709 19710 const int nmax=args.size(), mmax=nmax; 19711 char task[60], csave[60]; 19712 long int lsave[4]; 19713 long int n, m, iprint, isave[44]; 19714 long int* nbd = new long int[nmax]; 19715 long int* iwa = new long int[3*nmax]; 19716 double f, factr, pgtol; 19717 double* x = new double[nmax]; 19718 double* l = new double[nmax]; 19719 double* u = new double[nmax]; 19720 double* g = new double[nmax]; 19721 double dsave[29]; 19722 double* wa = new double[2*mmax*nmax+4*nmax+12*mmax*mmax+12*mmax]; 19723 long int SIXTY=60; 19724 19725 int num_ali = nmax/3+1; 19726 int nima = all_ali_params.size()/(num_ali*4); 19727 19728 // We wish to have no output. 19729 iprint = -1; 19730 19731 //c We specify the tolerances in the stopping criteria. 19732 factr=1.0e1; 19733 pgtol=1.0e-9; 19734 19735 // We specify the dimension n of the sample problem and the number 19736 // m of limited memory corrections stored. (n and m should not 19737 // exceed the limits nmax and mmax respectively.) 19738 n=nmax; 19739 m=mmax; 19740 19741 // We now provide nbd which defines the bounds on the variables: 19742 // l specifies the lower bounds, 19743 // u specifies the upper bounds. 19744 // x specifies the initial guess 19745 for (int i=0; i<nmax; i++) { 19746 x[i] = args[i]; 19747 nbd[i] = 0; 19748 } 19749 19750 // We start the iteration by initializing task. 19751 // (**MUST clear remaining chars in task with spaces (else crash)!**) 19752 strcpy(task,"START"); 19753 for (int i=5;i<60;i++) task[i]=' '; 19754 19755 // This is the call to the L-BFGS-B code. 19756 // (* call the L-BFGS-B routine with task='START' once before loop *) 19757 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19758 int step = 1; 19759 19760 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *) 19761 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) { 19762 19763 if (strncmp(task,"FG",2)==0) { 19764 // the minimization routine has returned to request the 19765 // function f and gradient g values at the current x 19766 19767 // Compute function value f for the sample problem. 19768 f = multi_align_error_func(x, all_ali_params, nima, num_ali, d); 19769 19770 // Compute gradient g for the sample problem. 19771 multi_align_error_dfunc(x, all_ali_params, nima, num_ali, g, d); 19772 19773 } 19774 //c go back to the minimization routine. 19775 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19776 step++; 19777 } 19778 19779 //printf("Total step is %d\n", step); 19780 vector<float> res; 19781 for (int i=0; i<nmax; i++) res.push_back(static_cast<float>(x[i])); 19782 res.push_back(static_cast<float>(f)); 19783 19784 delete[] nbd; 19785 delete[] iwa; 19786 delete[] x; 19787 delete[] l; 19788 delete[] u; 19789 delete[] g; 19790 delete[] wa; 19791 19792 return res; 19793 19794 }
void Util::multi_align_error_dfunc | ( | double * | x, | |
vector< float > | all_ali_params, | |||
int | nima, | |||
int | num_ali, | |||
double * | g, | |||
int | d | |||
) | [static] |
Definition at line 19854 of file util_sparx.cpp.
References mean(), and sqrt().
Referenced by multi_align_error().
19854 { 19855 19856 for (int i=0; i<num_ali*3-3; i++) g[i] = 0.0; 19857 19858 double* args = new double[num_ali*3]; 19859 for (int i=0; i<3*num_ali-3; i++) args[i] = x[i]; 19860 args[3*num_ali-3] = 0.0; 19861 args[3*num_ali-2] = 0.0; 19862 args[3*num_ali-1] = 0.0; 19863 double* cosa = new double[num_ali]; 19864 double* sina = new double[num_ali]; 19865 for (int i=0; i<num_ali; i++) { 19866 cosa[i] = cos(args[i*3]*M_PI/180.0); 19867 sina[i] = sin(args[i*3]*M_PI/180.0); 19868 } 19869 double* sx = new double[num_ali]; 19870 double* sy = new double[num_ali]; 19871 19872 vector<float> sqr_pixel_error(nima); 19873 19874 for (int i=0; i<nima; i++) { 19875 double sum_cosa = 0.0; 19876 double sum_sina = 0.0; 19877 for (int j=0; j<num_ali; j++) { 19878 if (static_cast<int>(ali_params[j*nima*4+i*4+3]) == 0) { 19879 sum_cosa += cos((args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 19880 sum_sina += sin((args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 19881 sx[j] = args[j*3+1] + ali_params[j*nima*4+i*4+1]*cosa[j] + ali_params[j*nima*4+i*4+2]*sina[j]; 19882 sy[j] = args[j*3+2] - ali_params[j*nima*4+i*4+1]*sina[j] + ali_params[j*nima*4+i*4+2]*cosa[j]; 19883 } else { 19884 sum_cosa += cos((-args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 19885 sum_sina += sin((-args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 19886 sx[j] = -args[j*3+1] + ali_params[j*nima*4+i*4+1]*cosa[j] - ali_params[j*nima*4+i*4+2]*sina[j]; 19887 sy[j] = args[j*3+2] + ali_params[j*nima*4+i*4+1]*sina[j] + ali_params[j*nima*4+i*4+2]*cosa[j]; 19888 } 19889 } 19890 double P = sqrt(sum_cosa*sum_cosa+sum_sina*sum_sina); 19891 sum_cosa /= P; 19892 sum_sina /= P; 19893 for (int j=0; j<num_ali-1; j++) { 19894 double dx = 2.0*(sx[j]-mean(sx, num_ali)); 19895 double dy = 2.0*(sy[j]-mean(sy, num_ali)); 19896 if (static_cast<int>(ali_params[j*nima*4+i*4+3]) == 0) { 19897 g[j*3] += (d*d/4.0*(sum_cosa*sin((args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0) - 19898 sum_sina*cos((args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0)) + 19899 dx*(-ali_params[j*nima*4+i*4+1]*sina[j]+ali_params[j*nima*4+i*4+2]*cosa[j])+ 19900 dy*(-ali_params[j*nima*4+i*4+1]*cosa[j]-ali_params[j*nima*4+i*4+2]*sina[j]))*M_PI/180.0; 19901 g[j*3+1] += dx; 19902 g[j*3+2] += dy; 19903 } else { 19904 g[j*3] += (d*d/4.0*(-sum_cosa*sin((-args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0) + 19905 sum_sina*cos((-args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0)) + 19906 dx*( ali_params[j*nima*4+i*4+1]*sina[j]+ali_params[j*nima*4+i*4+2]*cosa[j])+ 19907 dy*(-ali_params[j*nima*4+i*4+1]*cosa[j]+ali_params[j*nima*4+i*4+2]*sina[j]))*M_PI/180.0; 19908 g[j*3+1] += -dx; 19909 g[j*3+2] += dy; 19910 } 19911 } 19912 } 19913 19914 for (int i=0; i<3*num_ali-3; i++) g[i] /= (num_ali*nima); 19915 19916 delete[] args; 19917 delete[] cosa; 19918 delete[] sina; 19919 delete[] sx; 19920 delete[] sy; 19921 }
double Util::multi_align_error_func | ( | double * | x, | |
vector< float > | all_ali_params, | |||
int | nima, | |||
int | num_ali, | |||
int | d | |||
) | [static] |
Definition at line 19796 of file util_sparx.cpp.
References multi_align_error_func2().
Referenced by multi_align_error().
19797 { 19798 vector<double> sqr_pixel_error = multi_align_error_func2(x, all_ali_params, nima, num_ali, d); 19799 double sum_sqr_pixel_error = 0.0; 19800 for (int i=0; i<nima; i++) { 19801 sum_sqr_pixel_error += sqr_pixel_error[i]; 19802 } 19803 return ( sum_sqr_pixel_error / nima ); 19804 }
vector< double > Util::multi_align_error_func2 | ( | double * | x, | |
vector< float > | all_ali_params, | |||
int | nima, | |||
int | num_ali, | |||
int | d | |||
) | [static] |
Definition at line 19807 of file util_sparx.cpp.
Referenced by multi_align_error_func().
19808 { 19809 double* args = new double[num_ali*3]; 19810 for (int i=0; i<3*num_ali-3; i++) args[i] = x[i]; 19811 args[3*num_ali-3] = 0.0; 19812 args[3*num_ali-2] = 0.0; 19813 args[3*num_ali-1] = 0.0; 19814 double* cosa = new double[num_ali]; 19815 double* sina = new double[num_ali]; 19816 for (int i=0; i<num_ali; i++) { 19817 cosa[i] = cos(args[i*3]*M_PI/180.0); 19818 sina[i] = sin(args[i*3]*M_PI/180.0); 19819 } 19820 double* sx = new double[num_ali]; 19821 double* sy = new double[num_ali]; 19822 19823 vector<double> sqr_pixel_error(nima); 19824 19825 for (int i=0; i<nima; i++) { 19826 double sum_cosa = 0.0; 19827 double sum_sina = 0.0; 19828 for (int j=0; j<num_ali; j++) { 19829 if (static_cast<int>(ali_params[j*nima*4+i*4+3]) == 0) { 19830 sum_cosa += cos((args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 19831 sum_sina += sin((args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 19832 sx[j] = args[j*3+1] + ali_params[j*nima*4+i*4+1]*cosa[j] + ali_params[j*nima*4+i*4+2]*sina[j]; 19833 sy[j] = args[j*3+2] - ali_params[j*nima*4+i*4+1]*sina[j] + ali_params[j*nima*4+i*4+2]*cosa[j]; 19834 } else { 19835 sum_cosa += cos((-args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 19836 sum_sina += sin((-args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 19837 sx[j] = -args[j*3+1] + ali_params[j*nima*4+i*4+1]*cosa[j] - ali_params[j*nima*4+i*4+2]*sina[j]; 19838 sy[j] = args[j*3+2] + ali_params[j*nima*4+i*4+1]*sina[j] + ali_params[j*nima*4+i*4+2]*cosa[j]; 19839 } 19840 } 19841 double sqrtP = sqrt(sum_cosa*sum_cosa+sum_sina*sum_sina); 19842 sqr_pixel_error[i] = d*d/4.0*(1.0-sqrtP/num_ali)+var(sx, num_ali)+var(sy, num_ali); 19843 } 19844 19845 delete[] args; 19846 delete[] cosa; 19847 delete[] sina; 19848 delete[] sx; 19849 delete[] sy; 19850 19851 return sqr_pixel_error; 19852 }
void Util::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 | |||
) | [static] |
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 19080 of file util_sparx.cpp.
References Crosrng_msg_vec(), Frngs(), EMAN::EMData::get_data(), Polar2Dm(), and EMAN::EMData::set_size().
19083 { 19084 19085 int maxrin = numr[numr.size()-1]; 19086 19087 int ky = int(2*yrng/step+0.5)/2; 19088 int kx = int(2*xrng/step+0.5)/2; 19089 19090 peaks->set_size(maxrin, 2*kx+3, 2*ky+3); 19091 float *p_ccf1ds = peaks->get_data(); 19092 19093 peakm->set_size(maxrin, 2*kx+3, 2*ky+3); 19094 float *p_ccf1dm = peakm->get_data(); 19095 19096 for ( int i = 0; i<maxrin*(2*kx+3)*(2*ky+3); i++) { 19097 p_ccf1ds[i] = -1.e20f; 19098 p_ccf1dm[i] = -1.e20f; 19099 } 19100 19101 for (int i = -ky; i <= ky; i++) { 19102 float iy = i * step; 19103 for (int j = -kx; j <= kx; j++) { 19104 float ix = j*step; 19105 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 19106 Frngs(cimage, numr); 19107 Crosrng_msg_vec(crefim, cimage, numr, 19108 p_ccf1ds+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin, 19109 p_ccf1dm+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin); 19110 delete cimage; cimage = 0; 19111 } 19112 } 19113 return; 19114 }
void Util::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 | |||
) | [static] |
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 19116 of file util_sparx.cpp.
References Crosrng_msg_vec(), Frngs(), EMAN::EMData::get_data(), Polar2Dm(), and EMAN::EMData::set_size().
19118 { 19119 19120 int maxrin = numr[numr.size()-1]; 19121 19122 int ky = int(2*yrng/step+0.5)/2; 19123 int kx = int(2*xrng/step+0.5)/2; 19124 19125 peaks->set_size(maxrin, 2*kx+3, 2*ky+3); 19126 float *p_ccf1ds = peaks->get_data(); 19127 19128 peakm->set_size(maxrin, 2*kx+3, 2*ky+3); 19129 float *p_ccf1dm = peakm->get_data(); 19130 19131 peaks_compress->set_size(maxrin, 1, 1); 19132 float *p_ccf1ds_compress = peaks_compress->get_data(); 19133 19134 peakm_compress->set_size(maxrin, 1, 1); 19135 float *p_ccf1dm_compress = peakm_compress->get_data(); 19136 19137 for ( int i = 0; i<maxrin*(2*kx+3)*(2*ky+3); i++) { 19138 p_ccf1ds[i] = -1.e20f; 19139 p_ccf1dm[i] = -1.e20f; 19140 } 19141 19142 for (int i = -ky; i <= ky; i++) { 19143 float iy = i * step; 19144 for (int j = -kx; j <= kx; j++) { 19145 float ix = j*step; 19146 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 19147 Frngs(cimage, numr); 19148 Crosrng_msg_vec(crefim, cimage, numr, 19149 p_ccf1ds+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin, 19150 p_ccf1dm+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin); 19151 delete cimage; cimage = 0; 19152 } 19153 } 19154 for (int x=0; x<maxrin; x++) { 19155 float maxs = -1.0e22f; 19156 float maxm = -1.0e22f; 19157 for (int i=1; i<=2*ky+1; i++) { 19158 for (int j=1; j<=2*kx+1; j++) { 19159 if (p_ccf1ds[(i*(2*kx+3)+j)*maxrin+x] > maxs) maxs = p_ccf1ds[(i*(2*kx+3)+j)*maxrin+x]; 19160 if (p_ccf1dm[(i*(2*kx+3)+j)*maxrin+x] > maxm) maxm = p_ccf1dm[(i*(2*kx+3)+j)*maxrin+x]; 19161 } 19162 } 19163 p_ccf1ds_compress[x] = maxs; 19164 p_ccf1dm_compress[x] = maxm; 19165 } 19166 return; 19167 }
vector< float > Util::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 | |||
) | [static] |
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 17780 of file util_sparx.cpp.
References ang_n(), Crosrng_ms(), Frngs(), Normalize_ring(), pi, and Polar2Dm().
17782 { 17783 17784 // Manually extract. 17785 /* vector< EMAN::EMData* > crefim; 17786 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 17787 crefim.reserve(crefim_len); 17788 17789 for(std::size_t i=0;i<crefim_len;i++) { 17790 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 17791 crefim.push_back(proxy()); 17792 } 17793 */ 17794 17795 size_t crefim_len = crefim.size(); 17796 17797 int ky = int(2*yrng/step+0.5)/2; 17798 int kx = int(2*xrng/step+0.5)/2; 17799 int iref, nref=0, mirror=0; 17800 float iy, ix, sx=0, sy=0; 17801 float peak = -1.0E23f; 17802 float ang=0.0f; 17803 for (int i = -ky; i <= ky; i++) { 17804 iy = i * step ; 17805 for (int j = -kx; j <= kx; j++) { 17806 ix = j*step ; 17807 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 17808 17809 Normalize_ring( cimage, numr ); 17810 17811 Frngs(cimage, numr); 17812 // compare with all reference images 17813 // for iref in xrange(len(crefim)): 17814 for ( iref = 0; iref < (int)crefim_len; iref++) { 17815 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr); 17816 double qn = retvals["qn"]; 17817 double qm = retvals["qm"]; 17818 if(qn >= peak || qm >= peak) { 17819 sx = -ix; 17820 sy = -iy; 17821 nref = iref; 17822 if (qn >= qm) { 17823 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 17824 peak = static_cast<float>(qn); 17825 mirror = 0; 17826 } else { 17827 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 17828 peak = static_cast<float>(qm); 17829 mirror = 1; 17830 } 17831 } 17832 } delete cimage; cimage = 0; 17833 } 17834 } 17835 float co, so, sxs, sys; 17836 co = static_cast<float>( cos(ang*pi/180.0) ); 17837 so = static_cast<float>( -sin(ang*pi/180.0) ); 17838 sxs = sx*co - sy*so; 17839 sys = sx*so + sy*co; 17840 vector<float> res; 17841 res.push_back(ang); 17842 res.push_back(sxs); 17843 res.push_back(sys); 17844 res.push_back(static_cast<float>(mirror)); 17845 res.push_back(static_cast<float>(nref)); 17846 res.push_back(peak); 17847 return res; 17848 }
vector< float > Util::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 | |||
) | [static] |
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 18206 of file util_sparx.cpp.
References ang_n(), Crosrng_ms_delta(), Frngs(), Normalize_ring(), pi, and Polar2Dm().
18208 { 18209 18210 // Manually extract. 18211 /* vector< EMAN::EMData* > crefim; 18212 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 18213 crefim.reserve(crefim_len); 18214 18215 for(std::size_t i=0;i<crefim_len;i++) { 18216 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 18217 crefim.push_back(proxy()); 18218 } 18219 */ 18220 18221 size_t crefim_len = crefim.size(); 18222 18223 int ky = int(2*yrng/step+0.5)/2; 18224 int kx = int(2*xrng/step+0.5)/2; 18225 int iref, nref=0, mirror=0; 18226 float iy, ix, sx=0, sy=0; 18227 float peak = -1.0E23f; 18228 float ang=0.0f; 18229 for (int i = -ky; i <= ky; i++) { 18230 iy = i * step ; 18231 for (int j = -kx; j <= kx; j++) { 18232 ix = j*step ; 18233 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18234 18235 Normalize_ring( cimage, numr ); 18236 18237 Frngs(cimage, numr); 18238 // compare with all reference images 18239 // for iref in xrange(len(crefim)): 18240 for ( iref = 0; iref < (int)crefim_len; iref++) { 18241 Dict retvals = Crosrng_ms_delta(crefim[iref], cimage, numr, delta_start, delta); 18242 double qn = retvals["qn"]; 18243 double qm = retvals["qm"]; 18244 if(qn >= peak || qm >= peak) { 18245 sx = -ix; 18246 sy = -iy; 18247 nref = iref; 18248 if (qn >= qm) { 18249 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18250 peak = static_cast<float>(qn); 18251 mirror = 0; 18252 } else { 18253 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 18254 peak = static_cast<float>(qm); 18255 mirror = 1; 18256 } 18257 } 18258 } delete cimage; cimage = 0; 18259 } 18260 } 18261 float co, so, sxs, sys; 18262 co = static_cast<float>( cos(ang*pi/180.0) ); 18263 so = static_cast<float>( -sin(ang*pi/180.0) ); 18264 sxs = sx*co - sy*so; 18265 sys = sx*so + sy*co; 18266 vector<float> res; 18267 res.push_back(ang); 18268 res.push_back(sxs); 18269 res.push_back(sys); 18270 res.push_back(static_cast<float>(mirror)); 18271 res.push_back(static_cast<float>(nref)); 18272 res.push_back(peak); 18273 return res; 18274 }
vector< float > Util::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 | |||
) | [static] |
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 18333 of file util_sparx.cpp.
References abs, ang_n(), Crosrng_ms(), Frngs(), get_attr(), EMAN::EMData::get_attr(), Normalize_ring(), phi, pi, Polar2Dm(), t, and theta.
18335 { 18336 18337 // Manually extract. 18338 /* vector< EMAN::EMData* > crefim; 18339 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 18340 crefim.reserve(crefim_len); 18341 18342 for(std::size_t i=0;i<crefim_len;i++) { 18343 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 18344 crefim.push_back(proxy()); 18345 } 18346 */ 18347 size_t crefim_len = crefim.size(); 18348 const float qv = static_cast<float>( pi/180.0 ); 18349 18350 Transform * t = image->get_attr("xform.projection"); 18351 Dict d = t->get_params("spider"); 18352 if(t) {delete t; t=0;} 18353 float phi = d["phi"]; 18354 float theta = d["theta"]; 18355 int ky = int(2*yrng/step+0.5)/2; 18356 int kx = int(2*xrng/step+0.5)/2; 18357 int iref, nref=0, mirror=0; 18358 float iy, ix, sx=0, sy=0; 18359 float peak = -1.0E23f; 18360 float ang=0.0f; 18361 float imn1 = sin(theta*qv)*cos(phi*qv); 18362 float imn2 = sin(theta*qv)*sin(phi*qv); 18363 float imn3 = cos(theta*qv); 18364 vector<float> n1(crefim_len); 18365 vector<float> n2(crefim_len); 18366 vector<float> n3(crefim_len); 18367 for ( iref = 0; iref < (int)crefim_len; iref++) { 18368 n1[iref] = crefim[iref]->get_attr("n1"); 18369 n2[iref] = crefim[iref]->get_attr("n2"); 18370 n3[iref] = crefim[iref]->get_attr("n3"); 18371 } 18372 for (int i = -ky; i <= ky; i++) { 18373 iy = i * step ; 18374 for (int j = -kx; j <= kx; j++) { 18375 ix = j*step; 18376 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18377 Normalize_ring( cimage, numr ); 18378 Frngs(cimage, numr); 18379 // compare with all reference images 18380 // for iref in xrange(len(crefim)): 18381 for ( iref = 0; iref < (int)crefim_len; iref++) { 18382 if(abs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) { 18383 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr); 18384 double qn = retvals["qn"]; 18385 double qm = retvals["qm"]; 18386 if(qn >= peak || qm >= peak) { 18387 sx = -ix; 18388 sy = -iy; 18389 nref = iref; 18390 if (qn >= qm) { 18391 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18392 peak = static_cast<float>( qn ); 18393 mirror = 0; 18394 } else { 18395 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 18396 peak = static_cast<float>( qm ); 18397 mirror = 1; 18398 } 18399 } 18400 } 18401 } delete cimage; cimage = 0; 18402 } 18403 } 18404 float co, so, sxs, sys; 18405 if(peak == -1.0E23) { 18406 ang=0.0; sxs=0.0; sys=0.0; mirror=0; 18407 nref = -1; 18408 } else { 18409 co = cos(ang*qv); 18410 so = -sin(ang*qv); 18411 sxs = sx*co - sy*so; 18412 sys = sx*so + sy*co; 18413 } 18414 vector<float> res; 18415 res.push_back(ang); 18416 res.push_back(sxs); 18417 res.push_back(sys); 18418 res.push_back(static_cast<float>(mirror)); 18419 res.push_back(static_cast<float>(nref)); 18420 res.push_back(peak); 18421 return res; 18422 }
vector< float > Util::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 | |||
) | [static] |
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 18537 of file util_sparx.cpp.
References abs, ang_n(), Crosrng_sm_psi(), Frngs(), get_attr(), EMAN::EMData::get_attr(), Normalize_ring(), phi, pi, Polar2Dm(), EMAN::Dict::size(), t, and theta.
18539 { 18540 18541 // Manually extract. 18542 /* vector< EMAN::EMData* > crefim; 18543 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 18544 crefim.reserve(crefim_len); 18545 18546 for(std::size_t i=0;i<crefim_len;i++) { 18547 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 18548 crefim.push_back(proxy()); 18549 } 18550 */ 18551 size_t crefim_len = crefim.size(); 18552 const float qv = static_cast<float>(pi/180.0); 18553 18554 Transform* t = image->get_attr("xform.projection"); 18555 Dict d = t->get_params("spider"); 18556 if(t) {delete t; t=0;} 18557 float phi = d["phi"]; 18558 float theta = d["theta"]; 18559 float psi = d["psi"]; 18560 int ky = int(2*yrng/step+0.5)/2; 18561 int kx = int(2*xrng/step+0.5)/2; 18562 int iref, nref = 0, mirror = 0; 18563 float iy, ix, sx = 0, sy = 0; 18564 float peak = -1.0E23f; 18565 float ang = 0.0f; 18566 float imn1 = sin(theta*qv)*cos(phi*qv); 18567 float imn2 = sin(theta*qv)*sin(phi*qv); 18568 float imn3 = cos(theta*qv); 18569 vector<float> n1(crefim_len); 18570 vector<float> n2(crefim_len); 18571 vector<float> n3(crefim_len); 18572 for (iref = 0; iref < (int)crefim_len; iref++) { 18573 n1[iref] = crefim[iref]->get_attr("n1"); 18574 n2[iref] = crefim[iref]->get_attr("n2"); 18575 n3[iref] = crefim[iref]->get_attr("n3"); 18576 } 18577 bool nomirror = (theta<90.0) || (theta==90.0); 18578 if (!nomirror) { 18579 phi = fmod(phi+540.0f, 360.0f); 18580 theta = 180-theta; 18581 psi = fmod(540.0f-psi, 360.0f); 18582 } else { psi = fmod(360.0f-psi, 360.0f); } 18583 for (int i = -ky; i <= ky; i++) { 18584 iy = i * step ; 18585 for (int j = -kx; j <= kx; j++) { 18586 ix = j*step; 18587 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18588 18589 Normalize_ring(cimage, numr); 18590 18591 Frngs(cimage, numr); 18592 // compare with all reference images 18593 // for iref in xrange(len(crefim)): 18594 for (iref = 0; iref < (int)crefim_len; iref++) { 18595 if (abs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) { 18596 float refpsi = crefim[iref]->get_attr("psi"); 18597 if (nomirror) { 18598 Dict retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, fmod(360.0+psi+refpsi, 360.0), 0, psi_max); 18599 double qn = retvals["qn"]; 18600 if (qn >= peak) { 18601 sx = -ix; 18602 sy = -iy; 18603 nref = iref; 18604 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18605 peak = static_cast<float>(qn); 18606 mirror = 0; 18607 } 18608 } else { 18609 Dict retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, fmod(360.0+psi-refpsi, 360.0), 1, psi_max); 18610 double qn = retvals["qn"]; 18611 if (qn >= peak) { 18612 sx = -ix; 18613 sy = -iy; 18614 nref = iref; 18615 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18616 peak = static_cast<float>(qn); 18617 mirror = 1; 18618 } 18619 } 18620 } 18621 } delete cimage; cimage = 0; 18622 } 18623 } 18624 float co, so, sxs, sys; 18625 if(peak == -1.0E23) { 18626 ang=0.0; sxs=0.0; sys=0.0; mirror=0; 18627 nref = -1; 18628 } else { 18629 co = cos(ang*qv); 18630 so = -sin(ang*qv); 18631 sxs = sx*co - sy*so; 18632 sys = sx*so + sy*co; 18633 } 18634 vector<float> res; 18635 res.push_back(ang); 18636 res.push_back(sxs); 18637 res.push_back(sys); 18638 res.push_back(static_cast<float>(mirror)); 18639 res.push_back(static_cast<float>(nref)); 18640 res.push_back(peak); 18641 return res; 18642 }
vector< float > Util::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 | |||
) | [static] |
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 18276 of file util_sparx.cpp.
References ang_n(), Crosrng_ns(), Frngs(), pi, and Polar2Dm().
18278 { 18279 18280 // Manually extract. 18281 /* vector< EMAN::EMData* > crefim; 18282 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 18283 crefim.reserve(crefim_len); 18284 18285 for(std::size_t i=0;i<crefim_len;i++) { 18286 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 18287 crefim.push_back(proxy()); 18288 } 18289 */ 18290 size_t crefim_len = crefim.size(); 18291 18292 int ky = int(2*yrng/step+0.5)/2; 18293 int kx = int(2*xrng/step+0.5)/2; 18294 int iref, nref=0; 18295 float iy, ix, sx=0, sy=0; 18296 float peak = -1.0E23f; 18297 float ang=0.0f; 18298 for (int i = -ky; i <= ky; i++) { 18299 iy = i * step ; 18300 for (int j = -kx; j <= kx; j++) { 18301 ix = j*step ; 18302 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18303 Frngs(cimage, numr); 18304 // compare with all reference images 18305 // for iref in xrange(len(crefim)): 18306 for ( iref = 0; iref < (int)crefim_len; iref++) { 18307 Dict retvals = Crosrng_ns(crefim[iref], cimage, numr); 18308 double qn = retvals["qn"]; 18309 if(qn >= peak) { 18310 sx = -ix; 18311 sy = -iy; 18312 nref = iref; 18313 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18314 peak = static_cast<float>(qn); 18315 } 18316 } delete cimage; cimage = 0; 18317 } 18318 } 18319 float co, so, sxs, sys; 18320 co = static_cast<float>( cos(ang*pi/180.0) ); 18321 so = static_cast<float>( -sin(ang*pi/180.0) ); 18322 sxs = sx*co - sy*so; 18323 sys = sx*so + sy*co; 18324 vector<float> res; 18325 res.push_back(ang); 18326 res.push_back(sxs); 18327 res.push_back(sys); 18328 res.push_back(static_cast<float>(nref)); 18329 res.push_back(peak); 18330 return res; 18331 }
vector< float > Util::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 | |||
) | [static] |
Definition at line 17850 of file util_sparx.cpp.
References ang_n(), Crosrng_ms(), Frngs(), Normalize_ring(), pi, and Polar2Dm().
17852 { 17853 17854 size_t crefim_len = crefim.size(); 17855 17856 int ky = int(2*yrng/step+0.5)/2; 17857 int kx = int(2*xrng/step+0.5)/2; 17858 float iy, ix; 17859 vector<float> peak(crefim_len*5, -1.0e23f); 17860 for (int i = -ky; i <= ky; i++) { 17861 iy = i * step ; 17862 for (int j = -kx; j <= kx; j++) { 17863 ix = j*step ; 17864 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 17865 Normalize_ring( cimage, numr ); 17866 Frngs(cimage, numr); 17867 for (int iref = 0; iref < (int)crefim_len; iref++) { 17868 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr); 17869 double qn = retvals["qn"]; 17870 double qm = retvals["qm"]; 17871 if(qn >= peak[iref*5] || qm >= peak[iref*5]) { 17872 if (qn >= qm) { 17873 peak[iref*5] = static_cast<float>(qn); 17874 peak[iref*5+1] = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 17875 peak[iref*5+2] = -ix; 17876 peak[iref*5+3] = -iy; 17877 peak[iref*5+4] = 0; 17878 } else { 17879 peak[iref*5] = static_cast<float>(qm); 17880 peak[iref*5+1] = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 17881 peak[iref*5+2] = -ix; 17882 peak[iref*5+3] = -iy; 17883 peak[iref*5+4] = 1; 17884 } 17885 } 17886 } delete cimage; cimage = 0; 17887 } 17888 } 17889 for (int iref = 0; iref < (int)crefim_len; iref++) { 17890 float ang = peak[iref*5+1]; 17891 float sx = peak[iref*5+2]; 17892 float sy = peak[iref*5+3]; 17893 float co = cos(ang*pi/180.0); 17894 float so = -sin(ang*pi/180.0); 17895 float sxs = sx*co - sy*so; 17896 float sys = sx*so + sy*co; 17897 peak[iref*5+2] = sxs; 17898 peak[iref*5+3] = sys; 17899 } 17900 return peak; 17901 }
vector< float > Util::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 | |||
) | [static] |
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 18645 of file util_sparx.cpp.
References ang_n(), Crosrng_psi(), Frngs(), Normalize_ring(), pi, Polar2Dm(), and EMAN::Dict::size().
18647 { 18648 18649 size_t crefim_len = crefim.size(); 18650 18651 int iref, nref=0, mirror=0; 18652 float iy, ix, sx=0, sy=0; 18653 float peak = -1.0E23f; 18654 float ang=0.0f; 18655 int kx = int(2*xrng/step+0.5)/2; 18656 //if ynumber==-1, use the old code which process x and y direction equally. 18657 //if ynumber is given, it should be even. We need to check whether it is zero 18658 18659 int ky; 18660 float stepy; 18661 int kystart; 18662 18663 if (ynumber == -1) { 18664 ky = int(2*yrng/step+0.5)/2; 18665 stepy = step; 18666 kystart = -ky; 18667 } else if(ynumber == 0) { 18668 ky = 0; 18669 stepy = 0.0f; 18670 kystart = ky; 18671 } else { 18672 ky = int(ynumber/2); 18673 stepy=2*yrng/ynumber; 18674 kystart = -ky + 1; 18675 } 18676 //std::cout<<"yrng="<<yrng<<"ynumber="<<ynumber<<"stepy=="<<stepy<<"stepx=="<<step<<std::endl; 18677 for (int i = kystart; i <= ky; i++) { 18678 iy = i * stepy ; 18679 for (int j = -kx; j <= kx; j++) { 18680 ix = j*step ; 18681 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18682 18683 Normalize_ring( cimage, numr ); 18684 18685 Frngs(cimage, numr); 18686 // compare with all reference images 18687 // for iref in xrange(len(crefim)): 18688 for ( iref = 0; iref < (int)crefim_len; iref++) { 18689 Dict retvals_0 = Crosrng_psi(crefim[iref], cimage, numr, 0, psi_max); 18690 Dict retvals_180 = Crosrng_psi(crefim[iref], cimage, numr, 180, psi_max); 18691 double qn_0 = retvals_0["qn"]; 18692 double qn_180 = retvals_180["qn"]; 18693 double qm_0 = retvals_0["qm"]; 18694 double qm_180 = retvals_180["qm"]; 18695 double qn; 18696 double qm; 18697 bool qn_is_zero = false; 18698 bool qm_is_zero = false; 18699 18700 if (qn_0 >= qn_180) { 18701 qn = qn_0; 18702 qn_is_zero = true; 18703 } else { 18704 qn = qn_180; 18705 qn_is_zero = false; 18706 } 18707 18708 if (qm_0 >= qm_180) { 18709 qm = qm_0; 18710 qm_is_zero = true; 18711 } else { 18712 qm = qm_180; 18713 qm_is_zero = false; 18714 } 18715 18716 if(qn >= peak || qm >= peak) { 18717 sx = -ix; 18718 sy = -iy; 18719 nref = iref; 18720 if (qn >= qm) { 18721 if (qn_is_zero) ang = ang_n(retvals_0["tot"], mode, numr[numr.size()-1]); 18722 else ang = ang_n(retvals_180["tot"], mode, numr[numr.size()-1]); 18723 peak = static_cast<float>(qn); 18724 mirror = 0; 18725 } else { 18726 if (qm_is_zero) ang = ang_n(retvals_0["tmt"], mode, numr[numr.size()-1]); 18727 else ang = ang_n(retvals_180["tmt"], mode, numr[numr.size()-1]); 18728 peak = static_cast<float>(qm); 18729 mirror = 1; 18730 } 18731 } 18732 } 18733 delete cimage; cimage = 0; 18734 } 18735 } 18736 float co, so, sxs, sys; 18737 co = static_cast<float>( cos(ang*pi/180.0) ); 18738 so = static_cast<float>( -sin(ang*pi/180.0) ); 18739 sxs = sx*co - sy*so; 18740 sys = sx*so + sy*co; 18741 vector<float> res; 18742 res.push_back(ang); 18743 res.push_back(sxs); 18744 res.push_back(sys); 18745 res.push_back(static_cast<float>(mirror)); 18746 res.push_back(static_cast<float>(nref)); 18747 res.push_back(peak); 18748 return res; 18749 }
vector< float > Util::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 | |||
) | [static] |
Definition at line 18883 of file util_sparx.cpp.
References ang_n(), Crosrng_sm_psi(), Frngs(), Normalize_ring(), pi, Polar2Dm(), and EMAN::Dict::size().
18885 { 18886 18887 size_t crefim_len = crefim.size(); 18888 18889 int iref, nref=0, mirror=0; 18890 float iy, ix, sx=0, sy=0; 18891 float peak = -1.0E23f; 18892 float ang=0.0f; 18893 int kx = int(2*xrng/step+0.5)/2; 18894 //if ynumber==-1, use the old code which process x and y direction equally. 18895 18896 int ky; 18897 float stepy; 18898 int kystart; 18899 18900 if (ynumber == -1) { 18901 ky = int(2*yrng/step+0.5)/2; 18902 stepy = step; 18903 kystart = -ky; 18904 } else if(ynumber == 0) { 18905 ky = 0; 18906 stepy = 0.0f; 18907 kystart = ky; 18908 } else { 18909 ky = int(ynumber/2); 18910 stepy=2*yrng/ynumber; 18911 kystart = -ky + 1; 18912 } 18913 18914 //std::cout<<"yrng="<<yrng<<"ynumber="<<ynumber<<"stepy=="<<stepy<<"stepx=="<<step<<std::endl; 18915 for (int i = kystart; i <= ky; i++) { 18916 iy = i * stepy ; 18917 for (int j = -kx; j <= kx; j++) { 18918 ix = j*step ; 18919 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18920 18921 Normalize_ring( cimage, numr ); 18922 18923 Frngs(cimage, numr); 18924 // compare with all reference images 18925 // for iref in xrange(len(crefim)): 18926 for ( iref = 0; iref < (int)crefim_len; iref++) { 18927 Dict retvals_0 = Crosrng_sm_psi(crefim[iref], cimage, numr, 0, 0, psi_max); 18928 Dict retvals_180 = Crosrng_sm_psi(crefim[iref], cimage, numr, 180, 0, psi_max); 18929 double qn_0 = retvals_0["qn"]; 18930 double qn_180 = retvals_180["qn"]; 18931 double qn; 18932 bool qn_is_zero = false; 18933 18934 if (qn_0 >= qn_180){ 18935 qn = qn_0; 18936 qn_is_zero = true; 18937 } 18938 else{ 18939 qn = qn_180; 18940 qn_is_zero = false; 18941 } 18942 18943 if(qn >= peak) { 18944 sx = -ix; 18945 sy = -iy; 18946 nref = iref; 18947 18948 if (qn_is_zero){ 18949 ang = ang_n(retvals_0["tot"], mode, numr[numr.size()-1]); 18950 } 18951 else{ 18952 ang = ang_n(retvals_180["tot"], mode, numr[numr.size()-1]); 18953 } 18954 peak = static_cast<float>(qn); 18955 mirror = 0; 18956 18957 } 18958 } 18959 delete cimage; cimage = 0; 18960 } 18961 } 18962 float co, so, sxs, sys; 18963 co = static_cast<float>( cos(ang*pi/180.0) ); 18964 so = static_cast<float>( -sin(ang*pi/180.0) ); 18965 sxs = sx*co - sy*so; 18966 sys = sx*so + sy*co; 18967 vector<float> res; 18968 res.push_back(ang); 18969 res.push_back(sxs); 18970 res.push_back(sys); 18971 res.push_back(static_cast<float>(mirror)); 18972 res.push_back(static_cast<float>(nref)); 18973 res.push_back(peak); 18974 return res; 18975 }
vector< float > Util::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 , |
|||
float | yrnglocal = -1.0 | |||
) | [static] |
Definition at line 18977 of file util_sparx.cpp.
References ang_n(), Crosrng_sm_psi(), Frngs(), get_attr(), EMAN::EMData::get_attr(), Normalize_ring(), phi, pi, Polar2Dm(), t, and theta.
18979 { 18980 18981 size_t crefim_len = crefim.size(); 18982 const float qv = static_cast<float>( pi/180.0 ); 18983 Transform * t = image->get_attr("xform.projection"); 18984 Dict d = t->get_params("spider"); 18985 if(t) {delete t; t=0;} 18986 float phi = d["phi"]; 18987 float theta = d["theta"]; 18988 float psi = d["psi"]; 18989 float imn1 = sin(theta*qv)*cos(phi*qv); 18990 float imn2 = sin(theta*qv)*sin(phi*qv); 18991 float imn3 = cos(theta*qv); 18992 vector<float> n1(crefim_len); 18993 vector<float> n2(crefim_len); 18994 vector<float> n3(crefim_len); 18995 int iref, nref=-1, mirror=0; 18996 float iy, ix, sx=0, sy=0; 18997 float peak = -1.0E23f; 18998 float ang = 0.0f; 18999 int kx = int(2*xrng/step+0.5)/2; 19000 19001 for ( iref = 0; iref < (int)crefim_len; iref++) { 19002 n1[iref] = crefim[iref]->get_attr("n1"); 19003 n2[iref] = crefim[iref]->get_attr("n2"); 19004 n3[iref] = crefim[iref]->get_attr("n3"); 19005 } 19006 19007 float stepy; 19008 int ky; 19009 19010 if (ynumber == 0) { 19011 ky = 0; 19012 } 19013 else { 19014 19015 if (ynumber > 0) stepy=2*yrng/ynumber; 19016 else if (ynumber == -1) stepy = step; 19017 19018 if (yrnglocal >= 0.0) { 19019 ky = int(yrnglocal/stepy); 19020 } 19021 else { // search range is not restricted 19022 if (ynumber > 0) { 19023 ky = int(ynumber/2); 19024 } 19025 else{ 19026 ky = int(2*yrng/stepy+0.5)/2; 19027 } 19028 19029 } 19030 } 19031 19032 for (int i = -ky; i <= ky; i++) { 19033 iy = i * stepy ; 19034 for (int j = -kx; j <= kx; j++) { 19035 ix = j*step ; 19036 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 19037 19038 Normalize_ring( cimage, numr ); 19039 19040 Frngs(cimage, numr); 19041 // compare with all reference images 19042 // for iref in xrange(len(crefim)): 19043 for ( iref = 0; iref < (int)crefim_len; iref++) { 19044 if(fabs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) { 19045 Dict retvals; 19046 if ((psi-90.0f) < 90.0f) retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, 0, 0, psi_max); 19047 else retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, 180, 0, psi_max); 19048 19049 double qn = retvals["qn"]; 19050 if( qn >= peak) { 19051 sx = -ix; 19052 sy = -iy; 19053 nref = iref; 19054 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 19055 peak = static_cast<float>(qn); 19056 mirror = 0; 19057 } 19058 } 19059 } 19060 delete cimage; cimage = 0; 19061 } 19062 } 19063 19064 float co, so, sxs, sys; 19065 co = static_cast<float>( cos(ang*pi/180.0) ); 19066 so = static_cast<float>( -sin(ang*pi/180.0) ); 19067 sxs = sx*co - sy*so; 19068 sys = sx*so + sy*co; 19069 vector<float> res; 19070 res.push_back(ang); 19071 res.push_back(sxs); 19072 res.push_back(sys); 19073 res.push_back(static_cast<float>(mirror)); 19074 res.push_back(static_cast<float>(nref)); 19075 res.push_back(peak); 19076 return res; 19077 }
vector< float > Util::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 , |
|||
float | yrnglocal = -1.0 | |||
) | [static] |
Definition at line 18751 of file util_sparx.cpp.
References ang_n(), Crosrng_sm_psi(), Frngs(), get_attr(), EMAN::EMData::get_attr(), Normalize_ring(), phi, pi, Polar2Dm(), EMAN::Dict::size(), t, and theta.
18753 { 18754 18755 size_t crefim_len = crefim.size(); 18756 18757 int iref, nref=-1, mirror=0; 18758 float iy, ix, sx=0, sy=0; 18759 float peak = -1.0E23f; 18760 float ang=0.0f; 18761 const float qv = static_cast<float>( pi/180.0 ); 18762 Transform * t = image->get_attr("xform.projection"); 18763 Dict d = t->get_params("spider"); 18764 if(t) {delete t; t=0;} 18765 float phi = d["phi"]; 18766 float theta = d["theta"]; 18767 float psi = d["psi"]; 18768 float imn1 = sin(theta*qv)*cos(phi*qv); 18769 float imn2 = sin(theta*qv)*sin(phi*qv); 18770 float imn3 = cos(theta*qv); 18771 vector<float> n1(crefim_len); 18772 vector<float> n2(crefim_len); 18773 vector<float> n3(crefim_len); 18774 for ( iref = 0; iref < (int)crefim_len; iref++) { 18775 n1[iref] = crefim[iref]->get_attr("n1"); 18776 n2[iref] = crefim[iref]->get_attr("n2"); 18777 n3[iref] = crefim[iref]->get_attr("n3"); 18778 } 18779 float nbrinp; 18780 float nbrinp_mirror; 18781 bool use_ref; 18782 bool use_ref_mirror; 18783 int kx = int(2*xrng/step+0.5)/2; 18784 int ky; 18785 float stepy; 18786 18787 if (ynumber == 0) { 18788 ky = 0; 18789 } 18790 else { 18791 18792 if (ynumber > 0) stepy=2*yrng/ynumber; 18793 else if (ynumber == -1) stepy = step; 18794 18795 if (yrnglocal >= 0.0) { 18796 ky = int(yrnglocal/stepy); 18797 } 18798 else { // search range is not restricted 18799 if (ynumber > 0) { 18800 ky = int(ynumber/2); 18801 } 18802 else{ 18803 ky = int(2*yrng/stepy+0.5)/2; 18804 } 18805 18806 } 18807 } 18808 for (int i = -ky; i <= ky; i++) { 18809 iy = i * stepy ; 18810 for (int j = -kx; j <= kx; j++) { 18811 ix = j*step ; 18812 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18813 Normalize_ring( cimage, numr ); 18814 18815 Frngs(cimage, numr); 18816 // Compare with All reference images within neighborhood ant 18817 // for iref in xrange(len(crefim)): 18818 for ( iref = 0; iref < (int)crefim_len; iref++) { 18819 18820 use_ref = false; 18821 use_ref_mirror = false; 18822 18823 // inner product of iref's Eulerian angles with that of the data 18824 nbrinp = n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3; 18825 if (nbrinp >= ant) use_ref = true; 18826 18827 // inner product of the mirror of iref's Eulerian angles with that of the data 18828 nbrinp_mirror = n3[iref]*imn3 - n1[iref]*imn1 - n2[iref]*imn2; 18829 if (nbrinp_mirror >= ant) use_ref_mirror = true; 18830 if(use_ref || use_ref_mirror){ 18831 18832 Dict retvals; 18833 Dict retvals_mirror; 18834 if (use_ref_mirror == true) { 18835 if ((psi-90.0f) < 90.0f) retvals_mirror = Crosrng_sm_psi(crefim[iref], cimage, numr, 0, 1, psi_max); 18836 else retvals_mirror = Crosrng_sm_psi(crefim[iref], cimage, numr, 180, 1, psi_max); 18837 } 18838 if (use_ref == true) { 18839 if ((psi-90.0f) < 90.0f) retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, 0, 0, psi_max); 18840 else retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, 180, 0, psi_max); 18841 } 18842 double qn = retvals["qn"]; 18843 double qm = retvals_mirror["qn"]; 18844 18845 if(qn >= peak || qm >= peak) { 18846 sx = -ix; 18847 sy = -iy; 18848 nref = iref; 18849 if (qn >= qm){ 18850 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18851 mirror = 0; 18852 peak = static_cast<float>(qn); 18853 } 18854 else{ 18855 ang = ang_n(retvals_mirror["tot"], mode, numr[numr.size()-1]); 18856 mirror = 1; 18857 peak = static_cast<float>(qm); 18858 } 18859 18860 } 18861 } 18862 } 18863 delete cimage; cimage = 0; 18864 } 18865 } 18866 18867 float co, so, sxs, sys; 18868 co = static_cast<float>( cos(ang*pi/180.0) ); 18869 so = static_cast<float>( -sin(ang*pi/180.0) ); 18870 sxs = sx*co - sy*so; 18871 sys = sx*so + sy*co; 18872 vector<float> res; 18873 res.push_back(ang); 18874 res.push_back(sxs); 18875 res.push_back(sys); 18876 res.push_back(static_cast<float>(mirror)); 18877 res.push_back(static_cast<float>(nref)); 18878 res.push_back(peak); 18879 return res; 18880 }
int Util::MUTEX_INIT | ( | MUTEX * | mutex | ) | [static] |
int Util::MUTEX_LOCK | ( | MUTEX * | mutex | ) | [static] |
int Util::MUTEX_UNLOCK | ( | MUTEX * | mutex | ) | [static] |
int Util::nearest_ang | ( | const vector< float > & | vecref, | |
float | x, | |||
float | y, | |||
float | z | |||
) | [static] |
Definition at line 17975 of file util_sparx.cpp.
Referenced by assign_projangles().
17975 { 17976 float best_v = -1.0f; 17977 int best_i = -1; 17978 17979 for (unsigned int i=0; i<vecref.size()/3; i++) { 17980 float v = abs(vecref[i*3]*x+vecref[i*3+1]*y+vecref[i*3+2]*z); 17981 if (v > best_v) { 17982 best_v = v; 17983 best_i = i; 17984 } 17985 } 17986 return best_i; 17987 }
vector< int > Util::nearestk_to_refdir | ( | const vector< float > & | projangles, | |
const vector< float > & | refangles, | |||
const int | howmany | |||
) | [static] |
Definition at line 18013 of file util_sparx.cpp.
References abs, getvec(), and v.
18013 { 18014 int nref = refangles.size()/2; 18015 int nproj = projangles.size()/2; 18016 vector<int> asg(howmany*nref); 18017 vector<float> vecproj(nproj*3); 18018 for (int i=0; i<nproj; i++) 18019 getvec(projangles[i*2], projangles[i*2+1], vecproj[i*3], vecproj[i*3+1], vecproj[i*3+2]); 18020 18021 18022 vector<bool> taken(nproj); 18023 for (int k=0; k<nref; k++) { 18024 for (int i=0; i<nproj; i++) taken[i] = true; 18025 float x, y, z; 18026 getvec(refangles[k*2], refangles[k*2+1], x, y, z); 18027 for (int h=0; h<howmany; h++) { 18028 float best_v = -1.0f; 18029 int best_i = -1; 18030 for (int i=0; i<nproj; i++) { 18031 if( taken[i] ) { 18032 float v = abs(vecproj[i*3]*x+vecproj[i*3+1]*y+vecproj[i*3+2]*z); 18033 if (v > best_v) { 18034 best_v = v; 18035 best_i = i; 18036 } 18037 } 18038 } 18039 asg[k*howmany + h] = best_i; 18040 taken[best_i] = false; 18041 } 18042 } 18043 return asg; 18044 }
static int EMAN::Util::nint180 | ( | float | arg | ) | [inline, static] |
vector< float > Util::nonconvex | ( | const vector< float > & | curve, | |
int | first = 3 | |||
) | [static] |
Returns a non-convex version of a curve.
This is used for finding a good approximate background curve when evaluating power spectra.
[in] | curve | The data array (vector<float>) |
[in] | first | First point to consider, default = 3 |
[out] | outcurve | Returned data array |
Definition at line 1063 of file util.cpp.
References q.
01063 { 01064 01065 vector<float> ret(curve); 01066 if (first<1) first=1; // we need one point at each end as an anchor 01067 01068 int cont=1; 01069 while (cont) { 01070 cont=0; 01071 for (int i=first; i<ret.size()-1; i++) { 01072 float q= (ret[i-1]+ret[i+1])/2.0; 01073 if (ret[i]>q) { ret[i]=q; cont=1; } 01074 // printf("%1.2f (%1.2f) ",ret[i],q); 01075 } 01076 // printf("\n"); 01077 } 01078 01079 return ret; 01080 }
void Util::Normalize_ring | ( | EMData * | ring, | |
const vector< int > & | numr | |||
) | [static] |
Definition at line 17747 of file util_sparx.cpp.
References data, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), nn(), sqrt(), and EMAN::EMData::update().
Referenced by hans(), 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().
17748 { 17749 float* data = ring->get_data(); 17750 float av=0.0; 17751 float sq=0.0; 17752 float nn=0.0; 17753 int nring = numr.size()/3; 17754 for( int i=0; i < nring; ++i ) 17755 { 17756 int numr3i = numr[3*i+2]; 17757 int numr2i = numr[3*i+1]-1; 17758 float w = numr[3*i]*2*M_PI/float(numr[3*i+2]); 17759 for( int j=0; j < numr3i; ++j ) 17760 { 17761 int jc = numr2i+j; 17762 av += data[jc] * w; 17763 sq += data[jc] * data[jc] * w; 17764 nn += w; 17765 } 17766 } 17767 17768 float avg = av/nn; 17769 float sgm = sqrt( (sq-av*av/nn)/nn ); 17770 size_t n = (size_t)ring->get_xsize() * ring->get_ysize() * ring->get_zsize(); 17771 for( size_t i=0; i < n; ++i ) 17772 { 17773 data[i] -= avg; 17774 data[i] /= sgm; 17775 } 17776 17777 ring->update(); 17778 }
Definition at line 17657 of file util_sparx.cpp.
References ENTERFUNC, 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().
17658 { 17659 ENTERFUNC; 17660 /* Exception Handle */ 17661 if (!img) { 17662 throw NullPointerException("NULL input image"); 17663 } 17664 /* ============== img is modulus of a complex image in FFT format (so its imaginary parts are zero), 17665 output is img packed into real image with Friedel part added, ================ */ 17666 17667 int nxo=img->get_xsize(), ny=img->get_ysize(), nz=img->get_zsize(); 17668 int nx = nxo - 2 + img->is_fftodd(); 17669 int lsd2 = (nx + 2 - nx%2) / 2; // Extended x-dimension of the complex image 17670 int nyt, nzt; 17671 int nx2 = nx/2; 17672 int ny2 = ny/2; if(ny2 == 0) nyt =0; else nyt=ny; 17673 int nz2 = nz/2; if(nz2 == 0) nzt =0; else nzt=nz; 17674 int nx2p = nx2+nx%2; 17675 int ny2p = ny2+ny%2; 17676 int nz2p = nz2+nz%2; 17677 EMData& power = *(new EMData()); // output image 17678 power.set_size(nx, ny, nz); 17679 power.set_array_offsets(-nx2,-ny2,-nz2); 17680 //img->set_array_offsets(1,1,1); 17681 float *img_ptr = img->get_data(); 17682 for (int iz = 1; iz <= nz; iz++) { 17683 int jz=iz-1; 17684 if(jz>=nz2p) jz=jz-nzt; 17685 for (int iy = 1; iy <= ny; iy++) { 17686 int jy=iy-1; 17687 if(jy>=ny2p) jy=jy-nyt; 17688 for (int ix = 1; ix <= lsd2; ix++) { 17689 int jx=ix-1; 17690 if(jx>=nx2p) jx=jx-nx; 17691 power(jx,jy,jz) = img_ptr(ix,iy,iz); //real(img->cmplx(ix,iy,iz)); 17692 } 17693 } 17694 } 17695 // Create the Friedel related half 17696 int nzb, nze, nyb, nye, nxb, nxe; 17697 nxb =-nx2+(nx+1)%2; 17698 nxe = nx2-(nx+1)%2; 17699 if(ny2 == 0) {nyb =0; nye = 0;} else {nyb =-ny2+(ny+1)%2; nye = ny2-(ny+1)%2;} 17700 if(nz2 == 0) {nzb =0; nze = 0;} else {nzb =-nz2+(nz+1)%2; nze = nz2-(nz+1)%2;} 17701 for (int iz = nzb; iz <= nze; iz++) { 17702 for (int iy = nyb; iy <= nye; iy++) { 17703 for (int ix = 1; ix <= nxe; ix++) { // Note this loop begins with 1 - FFT should create correct Friedel related 0 plane 17704 power(-ix,-iy,-iz) = power(ix,iy,iz); 17705 } 17706 } 17707 } 17708 if(ny2 != 0) { 17709 if(nz2 != 0) { 17710 if(nz%2 == 0) { //if nz even, fix the first slice 17711 for (int iy = nyb; iy <= nye; iy++) { 17712 for (int ix = nxb; ix <= -1; ix++) { 17713 power(ix,iy,-nz2) = power(-ix,-iy,-nz2); 17714 } 17715 } 17716 if(ny%2 == 0) { //if ny even, fix the first line 17717 for (int ix = nxb; ix <= -1; ix++) { 17718 power(ix,-ny2,-nz2) = power(-ix,-ny2,-nz2); 17719 } 17720 } 17721 } 17722 } 17723 if(ny%2 == 0) { //if ny even, fix the first column 17724 for (int iz = nzb; iz <= nze; iz++) { 17725 for (int ix = nxb; ix <= -1; ix++) { 17726 power(ix,-ny2,-iz) = power(-ix,-ny2,iz); 17727 } 17728 } 17729 } 17730 17731 } 17732 power.update(); 17733 power.set_array_offsets(0,0,0); 17734 return &power; 17735 }
EMData * Util::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 , |
|||
const char * | params = "average" | |||
) | [static] |
Definition at line 5224 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().
05225 { 05226 /* Exception Handle */ 05227 if (!img) throw NullPointerException("NULL input image"); 05228 /* ============================== */ 05229 05230 // Get the size of the input image 05231 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 05232 /* ============================== */ 05233 05234 /* Exception Handle */ 05235 if(new_nx<nx || new_ny<ny || new_nz<nz) 05236 throw ImageDimensionException("The size of the padded image cannot be lower than the input image size."); 05237 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) 05238 throw ImageDimensionException("The offset inconsistent with the input image size. Solution: Change the offset parameters"); 05239 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)))) 05240 throw ImageDimensionException("The offset inconsistent with the input image size. Solution: Change the offset parameters"); 05241 /* ============================== */ 05242 05243 EMData* pading = img->copy_head(); 05244 pading->set_size(new_nx, new_ny, new_nz); 05245 float *inp = img->get_data(); 05246 float *outp = pading->get_data(); 05247 05248 05249 /* Calculation of the average and the circumference values for background substitution 05250 =======================================================================================*/ 05251 float background; 05252 05253 if (strcmp(params,"average")==0) background = img->get_attr("mean"); 05254 else if (strcmp(params,"circumference")==0) { 05255 float sum1=0.0f; 05256 size_t cnt=0; 05257 for(int i=0;i<nx;i++) { 05258 sum1 += inp(i,0,0) + inp(i,ny-1,nz-1); 05259 cnt+=2; 05260 } 05261 if(nz-1 == 0) { 05262 for (int j=1;j<ny-1;j++) { 05263 sum1 += inp(1,j,0) + inp(nx-1,j,0); 05264 cnt+=2; 05265 } 05266 } else { 05267 for (int k=1;k<nz-1;k++) { 05268 for (int j=1;j<ny-1;j++) { 05269 sum1 += inp(1,j,0) + inp(nx-1,j,0); 05270 cnt+=2; 05271 } 05272 } 05273 } 05274 background = sum1/cnt; 05275 } else { 05276 background = static_cast<float>( atof( params ) ); 05277 } 05278 /*=====================================================================================*/ 05279 05280 /*Initial Padding */ 05281 int new_st_x=0,new_st_y=0,new_st_z=0; 05282 for (int k=0;k<new_nz;k++) 05283 for(int j=0;j<new_ny;j++) 05284 for (int i=0;i<new_nx;i++) 05285 outp(i,j,k)=background; 05286 /*============================== */ 05287 05288 /* Calculation of the start point */ 05289 new_st_x=int((new_nx/2-nx/2) + x_offset); 05290 new_st_y=int((new_ny/2-ny/2) + y_offset); 05291 new_st_z=int((new_nz/2-nz/2) + z_offset); 05292 /* ============================== */ 05293 05294 for (int k=0;k<nz;k++) 05295 for(int j=0;j<ny;j++) 05296 for(int i=0;i<nx;i++) 05297 outp(i,j,k)=inp(i,j,k); 05298 pading->update(); 05299 return pading; 05300 }
bool Util::point_is_in_convex_polygon_2d | ( | const Vec2f & | p1, | |
const Vec2f & | p2, | |||
const Vec2f & | p3, | |||
const Vec2f & | p4, | |||
const Vec2f & | actual_point | |||
) | [static] |
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
p1 | point one | |
p2 | point two | |
p3 | point three | |
p4 | point three | |
actual_point | the point which might be in the polygon described by p1,p2,p3 and p4 |
Definition at line 1324 of file util.cpp.
References point_is_in_triangle_2d().
01325 { 01326 01327 if (point_is_in_triangle_2d(p1,p2,p4,actual_point)) return true; 01328 else return point_is_in_triangle_2d(p3,p2,p4,actual_point); 01329 }
bool Util::point_is_in_triangle_2d | ( | const Vec2f & | p1, | |
const Vec2f & | p2, | |||
const Vec2f & | p3, | |||
const Vec2f & | actual_point | |||
) | [static] |
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.
p1 | point one | |
p2 | point two | |
p3 | point three | |
actual_point | the point which might be in the triangle described by p1,p2 and p3 |
Definition at line 1289 of file util.cpp.
References EMAN::Vec2< Type >::dot(), EMAN::Transform::ERR_LIMIT, t, and v.
Referenced by point_is_in_convex_polygon_2d().
01290 { 01291 01292 Vec2f u = p2 - p1; 01293 Vec2f v = p3 - p1; 01294 Vec2f w = point - p1; 01295 01296 float udotu = u.dot(u); 01297 float udotv = u.dot(v); 01298 float udotw = u.dot(w); 01299 float vdotv = v.dot(v); 01300 float vdotw = v.dot(w); 01301 01302 float d = 1.0f/(udotv*udotv - udotu*vdotv); 01303 float s = udotv*vdotw - vdotv*udotw; 01304 s *= d; 01305 01306 float t = udotv*udotw - udotu*vdotw; 01307 t *= d; 01308 01309 // We've done a few multiplications, so detect when there are tiny residuals that may throw off the final 01310 // decision 01311 if (fabs(s) < Transform::ERR_LIMIT ) s = 0; 01312 if (fabs(t) < Transform::ERR_LIMIT ) t = 0; 01313 01314 if ( fabs((fabs(s)-1.0)) < Transform::ERR_LIMIT ) s = 1; 01315 if ( fabs((fabs(t)-1.0)) < Transform::ERR_LIMIT ) t = 1; 01316 01317 // cout << "s and t are " << s << " " << t << endl; 01318 01319 // The final decision, if this is true then we've hit the jackpot 01320 if ( s >= 0 && t >= 0 && (s+t) <= 1 ) return true; 01321 else return false; 01322 }
Definition at line 2143 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(), xim, and y.
02143 { 02144 int nsam = image->get_xsize(); 02145 int nrow = image->get_ysize(); 02146 int nring = numr.size()/3; 02147 int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 02148 EMData* out = new EMData(); 02149 out->set_size(lcirc,1,1); 02150 char mode = (cmode == "F" || cmode == "f") ? 'f' : 'h'; 02151 float *xim = image->get_data(); 02152 float *circ = out->get_data(); 02153 /* alrq(image->get_data(), nsam, nrow, &numr[0], out->get_data(), lcirc, nring, cmode); 02154 return out; 02155 } 02156 void Util::alrq(float *xim, int nsam , int nrow , int *numr, 02157 float *circ, int lcirc, int nring, char mode) 02158 {*/ 02159 /* 02160 c 02161 c purpose: 02162 c 02163 c resmaple to polar coordinates 02164 c 02165 */ 02166 // dimension xim(nsam,nrow),circ(lcirc) 02167 // integer numr(3,nring) 02168 02169 double dfi, dpi; 02170 int ns2, nr2, i, inr, l, nsim, kcirc, lt, j; 02171 float yq, xold, yold, fi, x, y; 02172 02173 ns2 = nsam/2+1; 02174 nr2 = nrow/2+1; 02175 dpi = 2.0*atan(1.0); 02176 02177 for (i=1;i<=nring;i++) { 02178 // radius of the ring 02179 inr = numr(1,i); 02180 yq = static_cast<float>(inr); 02181 l = numr(3,i); 02182 if (mode == 'h' || mode == 'H') lt = l/2; 02183 else lt = l/4; 02184 02185 nsim = lt-1; 02186 dfi = dpi/(nsim+1); 02187 kcirc = numr(2,i); 02188 xold = 0.0f; 02189 yold = static_cast<float>(inr); 02190 circ(kcirc) = quadri(xold+(float)ns2,yold+(float)nr2,nsam,nrow,xim); 02191 xold = static_cast<float>(inr); 02192 yold = 0.0f; 02193 circ(lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02194 02195 if (mode == 'f' || mode == 'F') { 02196 xold = 0.0f; 02197 yold = static_cast<float>(-inr); 02198 circ(lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02199 xold = static_cast<float>(-inr); 02200 yold = 0.0f; 02201 circ(lt+lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02202 } 02203 02204 for (j=1;j<=nsim;j++) { 02205 fi = static_cast<float>(dfi*j); 02206 x = sin(fi)*yq; 02207 y = cos(fi)*yq; 02208 xold = x; 02209 yold = y; 02210 circ(j+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02211 xold = y; 02212 yold = -x; 02213 circ(j+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02214 02215 if (mode == 'f' || mode == 'F') { 02216 xold = -x; 02217 yold = -y; 02218 circ(j+lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02219 xold = -y; 02220 yold = x; 02221 circ(j+lt+lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02222 } 02223 } 02224 } 02225 return out; 02226 }
EMData * Util::Polar2Dm | ( | EMData * | image, | |
float | cns2, | |||
float | cnr2, | |||
vector< int > | numr, | |||
string | cmode | |||
) | [static] |
Definition at line 2228 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(), xim, and y.
Referenced by ali2d_ccf_list(), constrained_helix(), constrained_helix_test(), hans(), 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().
02228 { 02229 int nsam = image->get_xsize(); 02230 int nrow = image->get_ysize(); 02231 int nring = numr.size()/3; 02232 int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 02233 EMData* out = new EMData(); 02234 out->set_size(lcirc,1,1); 02235 char mode = (cmode == "F" || cmode == "f") ? 'f' : 'h'; 02236 float *xim = image->get_data(); 02237 float *circ = out->get_data(); 02238 double dpi, dfi; 02239 int it, jt, inr, l, nsim, kcirc, lt; 02240 float xold, yold, fi, x, y; 02241 02242 // cns2 and cnr2 are predefined centers 02243 // no need to set to zero, all elements are defined 02244 dpi = 2*atan(1.0); 02245 for (it=1; it<=nring; it++) { 02246 // radius of the ring 02247 inr = numr(1,it); 02248 02249 // "F" means a full circle interpolation 02250 // "H" means a half circle interpolation 02251 02252 l = numr(3,it); 02253 if ( mode == 'h' || mode == 'H' ) lt = l / 2; 02254 else lt = l / 4; 02255 02256 nsim = lt - 1; 02257 dfi = dpi / (nsim+1); 02258 kcirc = numr(2,it); 02259 xold = 0.0f+cns2; 02260 yold = inr+cnr2; 02261 02262 Assert( kcirc <= lcirc ); 02263 circ(kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on 90 degree 02264 02265 xold = inr+cns2; 02266 yold = 0.0f+cnr2; 02267 Assert( lt+kcirc <= lcirc ); 02268 circ(lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on 0 degree 02269 02270 if ( mode == 'f' || mode == 'F' ) { 02271 xold = 0.0f+cns2; 02272 yold = -inr+cnr2; 02273 Assert( lt+lt+kcirc <= lcirc ); 02274 circ(lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on 270 degree 02275 02276 xold = -inr+cns2; 02277 yold = 0.0f+cnr2; 02278 Assert(lt+lt+lt+kcirc <= lcirc ); 02279 circ(lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on 180 degree 02280 } 02281 02282 for (jt=1; jt<=nsim; jt++) { 02283 fi = static_cast<float>(dfi * jt); 02284 x = sin(fi) * inr; 02285 y = cos(fi) * inr; 02286 02287 xold = x+cns2; 02288 yold = y+cnr2; 02289 02290 Assert( jt+kcirc <= lcirc ); 02291 circ(jt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on the first quadrant 02292 02293 xold = y+cns2; 02294 yold = -x+cnr2; 02295 02296 Assert( jt+lt+kcirc <= lcirc ); 02297 circ(jt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on the fourth quadrant 02298 02299 if ( mode == 'f' || mode == 'F' ) { 02300 xold = -x+cns2; 02301 yold = -y+cnr2; 02302 02303 Assert( jt+lt+lt+kcirc <= lcirc ); 02304 circ(jt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on the third quadrant 02305 02306 xold = -y+cns2; 02307 yold = x+cnr2; 02308 02309 Assert( jt+lt+lt+lt+kcirc <= lcirc ); 02310 circ(jt+lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on the second quadrant 02311 } 02312 } // end for jt 02313 } //end for it 02314 return out; 02315 }
EMData * Util::Polar2Dmi | ( | EMData * | image, | |
float | cns2, | |||
float | cnr2, | |||
vector< int > | numr, | |||
string | cmode, | |||
Util::KaiserBessel & | kb | |||
) | [static] |
Definition at line 2511 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(), and y.
02511 { 02512 // input image is twice the size of the original image 02513 int nring = numr.size()/3; 02514 int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 02515 EMData* out = new EMData(); 02516 out->set_size(lcirc,1,1); 02517 char mode = (cmode == "F" || cmode == "f") ? 'f' : 'h'; 02518 float *circ = out->get_data(); 02519 float *fimage = image->get_data(); 02520 int nx = image->get_xsize(); 02521 int ny = image->get_ysize(); 02522 int nz = image->get_zsize(); 02523 double dpi, dfi; 02524 int it, jt, inr, l, nsim, kcirc, lt; 02525 float yq, xold, yold, fi, x, y; 02526 02527 // cns2 and cnr2 are predefined centers 02528 // no need to set to zero, all elements are defined 02529 02530 dpi = 2*atan(1.0); 02531 for (it=1;it<=nring;it++) { 02532 // radius of the ring 02533 inr = numr(1,it); 02534 yq = static_cast<float>(inr); 02535 02536 l = numr(3,it); 02537 if ( mode == 'h' || mode == 'H' ) lt = l / 2; 02538 else lt = l / 4; 02539 02540 nsim = lt - 1; 02541 dfi = dpi / (nsim+1); 02542 kcirc = numr(2,it); 02543 xold = 0.0f; 02544 yold = static_cast<float>(inr); 02545 circ(kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02546 // circ(kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02547 02548 xold = static_cast<float>(inr); 02549 yold = 0.0f; 02550 circ(lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02551 // circ(lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02552 02553 if ( mode == 'f' || mode == 'F' ) { 02554 xold = 0.0f; 02555 yold = static_cast<float>(-inr); 02556 circ(lt+lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02557 // circ(lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02558 02559 xold = static_cast<float>(-inr); 02560 yold = 0.0f; 02561 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); 02562 // circ(lt+lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02563 } 02564 02565 for (jt=1;jt<=nsim;jt++) { 02566 fi = static_cast<float>(dfi * jt); 02567 x = sin(fi) * yq; 02568 y = cos(fi) * yq; 02569 02570 xold = x; 02571 yold = y; 02572 circ(jt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02573 // circ(jt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02574 02575 xold = y; 02576 yold = -x; 02577 circ(jt+lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02578 // circ(jt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02579 02580 if ( mode == 'f' || mode == 'F' ) { 02581 xold = -x; 02582 yold = -y; 02583 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); 02584 // circ(jt+lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02585 02586 xold = -y; 02587 yold = x; 02588 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); 02589 // circ(jt+lt+lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02590 } 02591 } // end for jt 02592 } //end for it 02593 return out; 02594 }
void Util::prb1d | ( | double * | b, | |
int | npoint, | |||
float * | pos | |||
) | [static] |
Definition at line 3150 of file util_sparx.cpp.
References b.
Referenced by Crosrng_e(), Crosrng_ew(), Crosrng_ms(), and Crosrng_ns().
03150 { 03151 double c2,c3; 03152 int nhalf; 03153 03154 nhalf = npoint/2 + 1; 03155 *pos = 0.0; 03156 03157 if (npoint == 7) { 03158 c2 = 49.*b(1) + 6.*b(2) - 21.*b(3) - 32.*b(4) - 27.*b(5) 03159 - 6.*b(6) + 31.*b(7); 03160 c3 = 5.*b(1) - 3.*b(3) - 4.*b(4) - 3.*b(5) + 5.*b(7); 03161 } 03162 else if (npoint == 5) { 03163 c2 = (74.*b(1) - 23.*b(2) - 60.*b(3) - 37.*b(4) 03164 + 46.*b(5) ) / (-70.); 03165 c3 = (2.*b(1) - b(2) - 2.*b(3) - b(4) + 2.*b(5) ) / 14.0; 03166 } 03167 else if (npoint == 3) { 03168 c2 = (5.*b(1) - 8.*b(2) + 3.*b(3) ) / (-2.0); 03169 c3 = (b(1) - 2.*b(2) + b(3) ) / 2.0; 03170 } 03171 //else if (npoint == 9) { 03172 else { // at least one has to be true!! 03173 c2 = (1708.*b(1) + 581.*b(2) - 246.*b(3) - 773.*b(4) 03174 - 1000.*b(5) - 927.*b(6) - 554.*b(7) + 119.*b(8) 03175 + 1092.*b(9) ) / (-4620.); 03176 c3 = (28.*b(1) + 7.*b(2) - 8.*b(3) - 17.*b(4) - 20.*b(5) 03177 - 17.*b(6) - 8.*b(7) + 7.*b(8) + 28.*b(9) ) / 924.0; 03178 } 03179 if (c3 != 0.0) *pos = static_cast<float>(c2/(2.0*c3) - nhalf); 03180 }
Dict Util::predict | ( | float | phig, | |
float | yg, | |||
float | dst, | |||
float | sgn, | |||
float | ysgn, | |||
float | dpp, | |||
float | dphi, | |||
bool | backpred | |||
) | [static] |
Definition at line 22503 of file util_sparx.cpp.
References abs.
Referenced by constrained_helix_test().
22503 { 22504 22505 float back = 1.0; 22506 if (!backpred) 22507 back=-1.0; 22508 float predphi; 22509 float predy; 22510 if (fmod(dst, dpp) <= 0.5*dpp) { 22511 predphi = fmod( phig + back*sgn * floor(dst/dpp)* dphi, float(360.0)); 22512 predy = yg + back*ysgn*(fmod(dst, dpp)); 22513 if (predy > 0) 22514 if (fmod(predy,dpp) > 0.5*dpp){ 22515 predy = predy - dpp; 22516 predphi = fmod( (predphi + sgn*dphi),float(360.0)); 22517 } 22518 else{ 22519 if (fmod(abs(predy), dpp) > 0.5*dpp) { 22520 predy = predy + dpp; 22521 predphi = fmod( (predphi - sgn*dphi), float(360.0)); 22522 } 22523 } 22524 22525 } 22526 else{ 22527 predphi = fmod ( (phig + back*sgn * (floor(dst/dpp)* dphi + dphi)), float(360.0)); 22528 predy = yg + back*ysgn*(fmod(dst,dpp) - dpp) ; 22529 if (predy > 0){ 22530 if (fmod(predy, dpp) > 0.5*dpp){ 22531 predy = predy - dpp; 22532 predphi = fmod( (predphi + sgn*dphi),float(360.0)); 22533 } 22534 } 22535 else{ 22536 if (fmod(abs(predy), dpp) > 0.5*dpp){ 22537 predy = predy + dpp; 22538 predphi = fmod( (predphi - sgn*dphi), float(360.0)); 22539 } 22540 } 22541 22542 } 22543 Dict retvals; 22544 retvals["predy"] = predy; 22545 retvals["predphi"] = predphi; 22546 return retvals; 22547 }
void Util::printMatI3D | ( | MIArray3D & | mat, | |
const string | str = string("") , |
|||
ostream & | out = std::cout | |||
) | [static] |
Print a 3D integer matrix to a file stream (std out by default).
[in] | mat | integer 3-d multi_array reference |
[in] | str | Message string to be printed. |
[out] | out | stream; cout by default. |
Definition at line 1173 of file util.cpp.
01173 { 01174 // Note: Don't need to check if 3-D because 3D is part of 01175 // the MIArray3D typedef. 01176 out << "Printing 3D Integer data: " << str << std::endl; 01177 const multi_array_types::size_type* sizes = mat.shape(); 01178 int nx = sizes[0], ny = sizes[1], nz = sizes[2]; 01179 const multi_array_types::index* indices = mat.index_bases(); 01180 int bx = indices[0], by = indices[1], bz = indices[2]; 01181 for (int iz = bz; iz < nz+bz; iz++) { 01182 cout << "(z = " << iz << " slice)" << endl; 01183 for (int ix = bx; ix < nx+bx; ix++) { 01184 for (int iy = by; iy < ny+by; iy++) { 01185 cout << setiosflags(ios::fixed) << setw(5) 01186 << mat[ix][iy][iz] << " "; 01187 } 01188 cout << endl; 01189 } 01190 } 01191 }
vector< float > Util::pw_extract | ( | vector< float > | pw, | |
int | n, | |||
int | iswi, | |||
float | ps | |||
) | [static] |
Definition at line 6266 of file util_sparx.cpp.
References call_cl1(), log(), and q.
06267 { 06268 int k,m,n1,klmd,klm2d,nklmd,n2d,n_larg,l, n2; 06269 06270 k=(int)pw.size(); 06271 l=0; 06272 m=k; 06273 n2=n+2; 06274 n1=n+1; 06275 klmd=k+l+m; 06276 klm2d= k+l+m+2; 06277 nklmd=k+l+m+n; 06278 n2d=n+2; 06279 /*size has to be increased when N is large*/ 06280 n_larg=klmd*2; 06281 klm2d=n_larg+klm2d; 06282 klmd=n_larg+klmd; 06283 nklmd=n_larg+nklmd; 06284 int size_q=klm2d*n2d; 06285 int size_cu=nklmd*2; 06286 static int i__; 06287 06288 double *q ; 06289 double *x ; 06290 double *res; 06291 double *cu; 06292 float *q2; 06293 float *pw_; 06294 long int *iu; 06295 double *s; 06296 q = (double*)calloc(size_q,sizeof(double)); 06297 x = (double*)calloc(n2d,sizeof(double)); 06298 res = (double*)calloc(klmd,sizeof(double)); 06299 cu = (double*)calloc(size_cu,sizeof(double)); 06300 s = (double*)calloc(klmd,sizeof(double)); 06301 q2 = (float*)calloc(size_q,sizeof(float)); 06302 iu = (long int*)calloc(size_cu,sizeof(long int)); 06303 pw_ = (float*)calloc(k,sizeof(float)); 06304 06305 for( i__ =0; i__<k; ++i__) pw_[i__] = log(pw[i__]); 06306 long int l_k=k; 06307 long int l_n=n; 06308 long int l_iswi=iswi; 06309 vector<float> cl1_res; 06310 cl1_res = Util::call_cl1(&l_k, &l_n, &ps, &l_iswi, pw_, q2, q, x, res, cu, s, iu); 06311 free(q); 06312 free(x); 06313 free(res); 06314 free(s); 06315 free(cu); 06316 free(q2); 06317 free(iu); 06318 free(pw_); 06319 return cl1_res; 06320 }
float Util::quadri | ( | float | x, | |
float | y, | |||
int | nx, | |||
int | ny, | |||
float * | image | |||
) | [static] |
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:
[in] | x | x-coord value |
[in] | y | y-coord value |
nx | ||
ny | ||
[in] | image | Image object (pointer) |
Definition at line 652 of file util_sparx.cpp.
Referenced by alrl_ms(), Polar2D(), Polar2Dm(), and quadri_background().
00653 { 00654 // purpose: quadratic interpolation 00655 // Optimized for speed, circular closer removed, checking of ranges removed 00656 float x, y, dx0, dy0, f0, c1, c2, c3, c4, c5, dxb, dyb; 00657 float quadri; 00658 int i, j, ip1, im1, jp1, jm1, ic, jc, hxc, hyc; 00659 00660 x = xx; 00661 y = yy; 00662 00663 // any xx and yy 00664 while ( x < 1.0 ) x += nxdata; 00665 while ( x >= (float)(nxdata+1) ) x -= nxdata; 00666 while ( y < 1.0 ) y += nydata; 00667 while ( y >= (float)(nydata+1) ) y -= nydata; 00668 00669 i = (int) x; 00670 j = (int) y; 00671 00672 dx0 = x - i; 00673 dy0 = y - j; 00674 00675 ip1 = i + 1; 00676 im1 = i - 1; 00677 jp1 = j + 1; 00678 jm1 = j - 1; 00679 00680 if (ip1 > nxdata) ip1 -= nxdata; 00681 if (im1 < 1) im1 += nxdata; 00682 if (jp1 > nydata) jp1 -= nydata; 00683 if (jm1 < 1) jm1 += nydata; 00684 00685 f0 = fdata(i,j); 00686 c1 = fdata(ip1,j) - f0; 00687 c2 = (c1 - f0 + fdata(im1,j)) * 0.5f; 00688 c3 = fdata(i,jp1) - f0; 00689 c4 = (c3 - f0 + fdata(i,jm1)) * 0.5f; 00690 00691 dxb = dx0 - 1; 00692 dyb = dy0 - 1; 00693 00694 // hxc & hyc are either 1 or -1 00695 if (dx0 >= 0) hxc = 1; else hxc = -1; 00696 if (dy0 >= 0) hyc = 1; else hyc = -1; 00697 00698 ic = i + hxc; 00699 jc = j + hyc; 00700 00701 if (ic > nxdata) ic -= nxdata; else if (ic < 1) ic += nxdata; 00702 if (jc > nydata) jc -= nydata; else if (jc < 1) jc += nydata; 00703 00704 c5 = ( (fdata(ic,jc) - f0 - hxc * c1 - (hxc * (hxc - 1.0f)) * c2 00705 - hyc * c3 - (hyc * (hyc - 1.0f)) * c4) * (hxc * hyc)); 00706 00707 00708 quadri = f0 + dx0 * (c1 + dxb * c2 + dy0 * c5) + dy0 * (c3 + dyb * c4); 00709 00710 return quadri; 00711 }
float Util::quadri_background | ( | float | x, | |
float | y, | |||
int | nx, | |||
int | ny, | |||
float * | image, | |||
int | xnew, | |||
int | ynew | |||
) | [static] |
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:
[in] | x | x-coord value |
[in] | y | y-coord value |
nx | ||
ny | ||
[in] | image | Image object (pointer) |
Definition at line 716 of file util_sparx.cpp.
References fdata, quadri(), x, and y.
00717 { 00718 // purpose: quadratic interpolation 00719 // Optimized for speed, circular closer removed, checking of ranges removed 00720 float x, y, dx0, dy0, f0, c1, c2, c3, c4, c5, dxb, dyb; 00721 float quadri; 00722 int i, j, ip1, im1, jp1, jm1, ic, jc, hxc, hyc; 00723 00724 x = xx; 00725 y = yy; 00726 00727 // wrap around is not done circulantly; if (x,y) is not in the image, then x = xnew and y = ynew 00728 if ( (x < 1.0) || ( x >= (float)(nxdata+1) ) || ( y < 1.0 ) || ( y >= (float)(nydata+1) )){ 00729 x = (float)xnew; 00730 y = (float)ynew; 00731 } 00732 00733 00734 i = (int) x; 00735 j = (int) y; 00736 00737 dx0 = x - i; 00738 dy0 = y - j; 00739 00740 ip1 = i + 1; 00741 im1 = i - 1; 00742 jp1 = j + 1; 00743 jm1 = j - 1; 00744 00745 if (ip1 > nxdata) ip1 -= nxdata; 00746 if (im1 < 1) im1 += nxdata; 00747 if (jp1 > nydata) jp1 -= nydata; 00748 if (jm1 < 1) jm1 += nydata; 00749 00750 f0 = fdata(i,j); 00751 c1 = fdata(ip1,j) - f0; 00752 c2 = (c1 - f0 + fdata(im1,j)) * 0.5f; 00753 c3 = fdata(i,jp1) - f0; 00754 c4 = (c3 - f0 + fdata(i,jm1)) * 0.5f; 00755 00756 dxb = dx0 - 1; 00757 dyb = dy0 - 1; 00758 00759 // hxc & hyc are either 1 or -1 00760 if (dx0 >= 0) hxc = 1; else hxc = -1; 00761 if (dy0 >= 0) hyc = 1; else hyc = -1; 00762 00763 ic = i + hxc; 00764 jc = j + hyc; 00765 00766 if (ic > nxdata) ic -= nxdata; else if (ic < 1) ic += nxdata; 00767 if (jc > nydata) jc -= nydata; else if (jc < 1) jc += nydata; 00768 00769 c5 = ( (fdata(ic,jc) - f0 - hxc * c1 - (hxc * (hxc - 1.0f)) * c2 00770 - hyc * c3 - (hyc * (hyc - 1.0f)) * c4) * (hxc * hyc)); 00771 00772 00773 quadri = f0 + dx0 * (c1 + dxb * c2 + dy0 * c5) + dy0 * (c3 + dyb * c4); 00774 00775 return quadri; 00776 }
void Util::Radialize | ( | int * | PermMatTr, | |
float * | kValsSorted, | |||
float * | weightofkvalsSorted, | |||
int | Size, | |||
int * | SizeReturned | |||
) | [static] |
list the sorted lengths of the integer lattice sites of a square sided image of size Size.
PRB
[out] | PermMatTr | The matrix telling the ordering of the lattice sites wrt the array |
[out] | kValsSorted | |
[out] | weightofkvalsSorted | the number of sites at that distance |
[in] | Size | The length of the image |
[out] | SizeReturned |
Definition at line 440 of file util_sparx.cpp.
References sort_mat().
00442 { 00443 int iMax = (int) floor( (Size-1.0)/2 +.01); 00444 int CountMax = (iMax+2)*(iMax+1)/2; 00445 int Count=-1; 00446 float *kVals = new float[CountMax]; 00447 float *weightMat = new float[CountMax]; 00448 int *PermMat = new int[CountMax]; 00449 SizeReturned[0] = CountMax; 00450 00451 // printf("Aa \n"); fflush(stdout); 00452 for (int jkx=0; jkx< iMax+1; jkx++) { 00453 for (int jky=0; jky< jkx+1; jky++) { 00454 Count++; 00455 kVals[Count] = sqrtf((float) (jkx*jkx +jky*jky)); 00456 weightMat[Count]= 1.0; 00457 if (jkx!=0) { weightMat[Count] *=2;} 00458 if (jky!=0) { weightMat[Count] *=2;} 00459 if (jkx!=jky){ weightMat[Count] *=2;} 00460 PermMat[Count]=Count+1; 00461 } 00462 } 00463 00464 int lkVals = Count+1; 00465 // printf("Cc \n");fflush(stdout); 00466 00467 sort_mat(&kVals[0],&kVals[Count], 00468 &PermMat[0], &PermMat[Count]); //PermMat is 00469 //also returned as well as kValsSorted 00470 fflush(stdout); 00471 00472 int newInd; 00473 00474 for (int iP=0; iP < lkVals ; iP++ ) { 00475 newInd = PermMat[iP]; 00476 PermMatTr[newInd-1] = iP+1; 00477 } 00478 00479 // printf("Ee \n"); fflush(stdout); 00480 00481 int CountA=-1; 00482 int CountB=-1; 00483 00484 while (CountB< (CountMax-1)) { 00485 CountA++; 00486 CountB++; 00487 // printf("CountA=%d ; CountB=%d \n", CountA,CountB);fflush(stdout); 00488 kValsSorted[CountA] = kVals[CountB] ; 00489 if (CountB<(CountMax-1) ) { 00490 while (fabs(kVals[CountB] -kVals[CountB+1])<.0000001 ) { 00491 SizeReturned[0]--; 00492 for (int iP=0; iP < lkVals; iP++){ 00493 // printf("iP=%d \n", iP);fflush(stdout); 00494 if (PermMatTr[iP]>CountA+1) { 00495 PermMatTr[iP]--; 00496 } 00497 } 00498 CountB++; 00499 } 00500 } 00501 } 00502 00503 00504 for (int CountD=0; CountD < CountMax; CountD++) { 00505 newInd = PermMatTr[CountD]; 00506 weightofkValsSorted[newInd-1] += weightMat[CountD]; 00507 } 00508 00509 }
Recreates a n-d image using its compressed 1-D form and the mask.
Definition at line 6097 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().
Referenced by EMAN::PCA::dopca(), and EMAN::PCA::dopca_lan().
06098 { 06099 /******** 06100 ***Exception Handle 06101 *************/ 06102 if(mask == NULL) 06103 throw ImageDimensionException("The mask cannot be an null image"); 06104 06105 /*********** 06106 ***get the size of the mask 06107 **************/ 06108 int nx = mask->get_xsize(),ny = mask->get_ysize(),nz = mask->get_zsize(); 06109 06110 size_t i,size = (size_t)nx*ny*nz; /* loop counters */ 06111 /* new image declaration */ 06112 EMData *new_image = new EMData(); 06113 new_image->set_size(nx,ny,nz); /* set the size of new image */ 06114 float *new_ptr = new_image->get_data(); /* set size of the new image */ 06115 float *mask_ptr = mask->get_data(); /* assign a pointer to the mask image */ 06116 float *img_ptr = image->get_data(); /* assign a pointer to the 1D image */ 06117 int count = 0; 06118 float sum_under_mask = 0.0 ; 06119 for(i = 0;i < size;i++){ 06120 if(mask_ptr[i] > 0.5f){ 06121 new_ptr[i] = img_ptr[count]; 06122 sum_under_mask += img_ptr[count]; 06123 count++; 06124 if( count > image->get_xsize() ) { 06125 throw ImageDimensionException("Error: in reconstitute_image_mask, the mask doesn't match the image, it is too large"); 06126 } 06127 } 06128 } 06129 06130 if( count > image->get_xsize() ) { 06131 throw ImageDimensionException("Error: in reconstitute_image_mask, the mask doesn't match the image, it is too small"); 06132 } 06133 06134 float avg_under_mask = sum_under_mask / count; 06135 for(i = 0;i < size;i++) { 06136 if(mask_ptr[i] <= 0.5f) new_ptr[i] = avg_under_mask; 06137 } 06138 new_image->update(); 06139 return new_image; 06140 }
string Util::recv_broadcast | ( | int | port | ) | [static] |
Definition at line 1096 of file util.cpp.
References BPKT::data, BPKT::hdr, EMAN::ByteOrder::is_host_big_endian(), BPKT::len, BPKT::oseq, and BPKT::pseq.
01096 { 01097 // struct sockaddr_in sadr = { AF_INET, 9989, INADDR_ANY}; 01098 // int sock=socket(AF_INET,SOCK_DGRAM,0); 01099 // if (bind(sock,&sadr,sizeof(sockaddr_in))) return string(); 01100 01101 if (ByteOrder::is_host_big_endian()) { 01102 printf("No cache mirroring on Big endian machines yet\n"); 01103 return string(); // FIXME: no support for big endian hosts 01104 } 01105 01106 BPKT pkt; 01107 string ret; 01108 vector<char> fill; 01109 int obj=-1; 01110 unsigned int i=0; 01111 // printf ("Listening\n"); 01112 01113 while (1) { 01114 int l = recv(sock,&pkt,1044,0); 01115 if (l<=0) { 01116 if (obj!=-1) printf("Timeout with incomplete obj %d %d/%d\n",obj,i,(int)fill.size()); 01117 return string(); // probably a timeout 01118 } 01119 if (l<20) { 01120 printf("Bad packet from broadcast"); 01121 continue; 01122 } 01123 01124 if (strncmp(pkt.hdr,"EMAN",4)!=0) continue; 01125 01126 // new object coming in 01127 if (obj!=pkt.oseq) { 01128 obj=pkt.oseq; 01129 ret.resize(pkt.len); 01130 fill.resize((pkt.len-1)/1024+1); 01131 for (i=0; i<fill.size(); i++) fill[i]=0; 01132 } 01133 if (obj==-1) printf("Something wierd happened. please report\n"); 01134 01135 // copy the packet into the output buffer 01136 fill[pkt.pseq]=1; 01137 ret.replace(pkt.pseq*1024,l-20,(char *)pkt.data,l-20); 01138 01139 // see if we got everything 01140 for (i=0; i<fill.size(); i++) { 01141 if (fill[i]!=1) break; 01142 } 01143 // printf("\t\t\tObj %d %d/%d \r",obj,i,(int)fill.size()); 01144 fflush(stdout); 01145 01146 if (i==fill.size()) return ret; // Yea ! We got a good packet 01147 } 01148 01149 }
string Util::remove_filename_ext | ( | const string & | filename | ) | [static] |
Remove a filename's extension and return the new filename.
[in] | filename | The old filename whose extension is going to be removed. |
Definition at line 484 of file util.cpp.
00485 { 00486 if (filename == "") { 00487 return ""; 00488 } 00489 00490 char *buf = new char[filename.size()+1]; 00491 strcpy(buf, filename.c_str()); 00492 char *old_ext = strrchr(buf, '.'); 00493 if (old_ext) { 00494 buf[strlen(buf) - strlen(old_ext)] = '\0'; 00495 } 00496 string result = string(buf); 00497 if( buf ) 00498 { 00499 delete [] buf; 00500 buf = 0; 00501 } 00502 return result; 00503 }
static float EMAN::Util::restrict1 | ( | float | x, | |
int | nx | |||
) | [inline, static] |
Definition at line 1150 of file util.h.
Referenced by get_pixel_conv_new(), and get_pixel_conv_new_background().
void Util::rotate_phase_origin | ( | float * | data, | |
size_t | nx, | |||
size_t | ny, | |||
size_t | nz | |||
) | [static] |
rotate data vertically by ny/2, to make the mrc phase origin compliance with EMAN1 and TNF reader
data | complex data array | |
nx | x dimension size | |
ny | y dimension size | |
nz | z dimension size |
Definition at line 129 of file util.cpp.
References t.
00130 { 00131 if(ny==1 && nz==1) { //1D, do nothing 00132 return; 00133 } 00134 else if(ny!=1 && nz==1) { //2D, rotate vertically by ny/2 00135 size_t i, j, k, l; 00136 float re; 00137 l=ny/2*nx; 00138 for (i=0; i<ny/2; i++) { 00139 for (j=0; j<nx; j++) { 00140 k=j+i*nx; 00141 re=data[k]; 00142 data[k]=data[k+l]; 00143 data[k+l]=re; 00144 } 00145 } 00146 } 00147 else { //3D, in the y,z plane, swaps quadrants I,III and II,IV, this is the 'rotation' in y and z 00148 size_t i, j, k, l, ii, jj; 00149 char * t=(char *)malloc(sizeof(float)*nx); 00150 00151 k=nx*ny*(nz+1)/2; 00152 l=nx*ny*(nz-1)/2; 00153 jj=nx*sizeof(float); 00154 for (j=ii=0; j<nz/2; ++j) { 00155 for (i=0; i<ny; ++i,ii+=nx) { 00156 memcpy(t,data+ii,jj); 00157 if (i<ny/2) { 00158 memcpy(data+ii,data+ii+k,jj); 00159 memcpy(data+ii+k,t,jj); 00160 } 00161 else { 00162 memcpy(data+ii,data+ii+l,jj); 00163 memcpy(data+ii+l,t,jj); 00164 } 00165 } 00166 } 00167 free(t); 00168 } 00169 }
static int EMAN::Util::round | ( | double | x | ) | [inline, static] |
static int EMAN::Util::round | ( | float | x | ) | [inline, static] |
Get ceiling round of a float number x.
[in] | x | Given float number. |
Definition at line 1529 of file util.h.
Referenced by EMAN::Util::FakeKaiserBessel::build_I0table(), EMAN::Util::KaiserBessel::build_I0table(), EMAN::Util::sincBlackman::build_sBtable(), EMAN::EMData::calc_fourier_shell_correlation(), EMAN::EMData::calc_hist(), EMAN::EMData::cog(), EMAN::EMData::cut_slice(), extractpoint2(), EMAN::nnSSNR_ctfReconstructor::finish(), EMAN::nnSSNR_Reconstructor::finish(), get_pixel_conv_new(), get_pixel_conv_new_background(), hypot_fast_int(), EMAN::EMData::phase_cog(), EMAN::ApplyPolynomialProfileToHelix::process_inplace(), EMAN::BeamstopProcessor::process_inplace(), EMAN::EMData::translate(), and EMAN::EMData::uncut_slice().
bool Util::sanitycheck | ( | int * | argParts, | |
int * | Indices, | |||
int * | dimClasses, | |||
int | nParts, | |||
int | K, | |||
int | T, | |||
int * | output | |||
) | [static] |
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 20962 of file util_sparx.cpp.
References k_means_cont_table_().
20962 { 20963 //cout<<"sanitycheck called\n"; 20964 int total_cost = *output; 20965 int num_matches = *(output+1); 20966 20967 int cost=0; 20968 int* intx; 20969 int intx_size; 20970 int* intx_next(0); 20971 int intx_next_size = 0; 20972 int curclass; 20973 int curclass_size; 20974 //cout<<"cost by match: ["; 20975 for(int i = 0; i < num_matches; i++){ 20976 curclass = *(output+2+ i*nParts); 20977 // check feasibility 20978 if (*(argParts + Indices[curclass]+1) == -5) {cout<<"infeasible match!\n"; return 0;} 20979 *(argParts + Indices[curclass]+1) = -5; 20980 // initialize intx to the number of elements in class curclass of partition 0 of the i-th match 20981 curclass_size = *(dimClasses+curclass)-2; 20982 intx = new int[curclass_size]; 20983 for (int ic = 0; ic < curclass_size; ic++) *(intx+ic) = *(argParts + Indices[curclass]+2+ic); 20984 intx_size = curclass_size; 20985 20986 for (int j=1; j < nParts; j++){ 20987 curclass = *(output+2+ i*nParts+j); 20988 if (*(argParts + Indices[j*K+curclass]+1)==-5){cout<<"infeasible match!\n"; return 0;} 20989 *(argParts + Indices[j*K+curclass]+1)=-5; 20990 // compute the intersection of intx and class curclass of partition j of the i-th match 20991 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); 20992 intx_next = new int[intx_next_size]; 20993 Util::k_means_cont_table_(intx,argParts + Indices[j*K+curclass]+2, intx_next, intx_size, *(dimClasses + j*K+curclass)-2,1); 20994 delete[] intx; 20995 intx=intx_next; 20996 intx_size= intx_next_size; 20997 } 20998 delete[] intx_next; 20999 21000 if (intx_next_size <= T) {cout << "something wrong with solution!\n"; return 0;} 21001 //cout <<intx_next_size<<","; 21002 cost = cost + intx_next_size; 21003 } 21004 //cout<<"]\n"; 21005 if (cost != total_cost) {cout << "something wrong with solution!\n"; return 0;} 21006 21007 return 1; 21008 21009 }
void Util::save_data | ( | float | x0, | |
float | dx, | |||
float * | y_array, | |||
size_t | array_size, | |||
const string & | filename | |||
) | [static] |
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].
[in] | x0 | The starting point of x. |
[in] | dx | delta x. The increase step of x data. |
[in] | y_array | The y data array. |
[in] | array_size | The y data array size. |
[in] | filename | The output filename. |
Definition at line 652 of file util.cpp.
References Assert, FileAccessException, and NullPointerException.
00654 { 00655 Assert(dx > 0); 00656 Assert(array_size > 0); 00657 Assert(filename != ""); 00658 00659 if (!y_array) { 00660 throw NullPointerException("y array"); 00661 } 00662 00663 FILE *out = fopen(filename.c_str(), "wb"); 00664 if (!out) { 00665 throw FileAccessException(filename); 00666 } 00667 00668 for (size_t i = 0; i < array_size; i++) { 00669 fprintf(out, "%g\t%g\n", x0 + dx * i, y_array[i]); 00670 } 00671 fclose(out); 00672 }
void Util::save_data | ( | float | x0, | |
float | dx, | |||
const vector< float > & | y_array, | |||
const string & | filename | |||
) | [static] |
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].
[in] | x0 | The starting point of x. |
[in] | dx | delta x. The increase step of x data. |
[in] | y_array | The y data array. |
[in] | filename | The output filename. |
Definition at line 633 of file util.cpp.
References Assert, and FileAccessException.
00635 { 00636 Assert(dx != 0); 00637 Assert(y_array.size() > 0); 00638 Assert(filename != ""); 00639 00640 FILE *out = fopen(filename.c_str(), "wb"); 00641 if (!out) { 00642 throw FileAccessException(filename); 00643 } 00644 00645 for (size_t i = 0; i < y_array.size(); i++) { 00646 fprintf(out, "%g\t%g\n", x0 + dx * i, y_array[i]); 00647 } 00648 fclose(out); 00649 }
void Util::save_data | ( | const vector< float > & | x_array, | |
const vector< float > & | y_array, | |||
const string & | filename | |||
) | [static] |
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.
[in] | x_array | The x array. |
[in] | y_array | The y array. |
[in] | filename | The output filename. |
Definition at line 609 of file util.cpp.
References Assert, FileAccessException, and LOGERR.
Referenced by EMAN::LowpassAutoBProcessor::create_radial_func().
00611 { 00612 Assert(x_array.size() > 0); 00613 Assert(y_array.size() > 0); 00614 Assert(filename != ""); 00615 00616 if (x_array.size() != y_array.size()) { 00617 LOGERR("array x and array y have different size: %d != %d\n", 00618 x_array.size(), y_array.size()); 00619 return; 00620 } 00621 00622 FILE *out = fopen(filename.c_str(), "wb"); 00623 if (!out) { 00624 throw FileAccessException(filename); 00625 } 00626 00627 for (size_t i = 0; i < x_array.size(); i++) { 00628 fprintf(out, "%g\t%g\n", x_array[i], y_array[i]); 00629 } 00630 fclose(out); 00631 }
string Util::sbasename | ( | const string & | filename | ) | [static] |
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".
[in] | filename | The given filename, full path or relative path. |
Definition at line 505 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().
00506 { 00507 if (filename == "") { 00508 return ""; 00509 } 00510 00511 char s = '/'; 00512 #ifdef _WIN32 00513 s = '\\'; 00514 #endif 00515 const char * c = strrchr(filename.c_str(), s); 00516 if (!c) { 00517 return filename; 00518 } 00519 else { 00520 c++; 00521 } 00522 return string(c); 00523 }
void Util::search2 | ( | int * | argParts, | |
int * | Indices, | |||
int * | dimClasses, | |||
int | nParts, | |||
int | K, | |||
int | T, | |||
int * | matchlist, | |||
int * | costlist, | |||
int | J | |||
) | [static] |
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 21016 of file util_sparx.cpp.
References explore2(), and k_means_cont_table_().
21016 { 21017 21018 // some temp variables 21019 bool flag = 0; 21020 int nintx; 21021 int* dummy(0); 21022 //int* ret; 21023 int* curbranch = new int[nParts]; 21024 21025 //initialize costlist to all 0 21026 for(int jit= 0; jit< J; jit++) *(costlist+jit) = 0; 21027 21028 21029 for(int a=0; a<K; a++) 21030 { 21031 21032 // 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 21033 if (*(argParts + Indices[a] + 1) < 1) continue; 21034 if (*(dimClasses + a)-2 <= T) continue; 21035 21036 // 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 21037 21038 for( int i=1; i < nParts; i++){ 21039 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. 21040 for(int j=0; j < K; j++){ 21041 if (*(argParts + Indices[i*K+j] + 1) < 1) continue; 21042 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); 21043 if (nintx > T) flag=1; 21044 else *(argParts + Indices[i*K+j] + 1) =-4; 21045 } 21046 if (flag==0) {break;} 21047 } 21048 21049 // explore determines J matchs with the largest weight greater than T where class in partition 0 is class a 21050 *curbranch = a; 21051 21052 if (flag > 0) // Each partition has one or more active class 21053 Util::explore2(argParts, Indices, dimClasses, nParts, K, T, argParts+Indices[a]+2, *(dimClasses+a)-2, argParts+Indices[a]+2, 21054 *(dimClasses+a)-2,0, J, matchlist, costlist, curbranch); 21055 21056 // take all the classes marked as -4 and remark it as 1 in preparation for next round 21057 for( int i=1; i < nParts; i++){ 21058 for(int j=0; j < K; j++){ 21059 if (*(argParts + Indices[i*K+j] + 1) == -4) *(argParts + Indices[i*K+j] + 1) =1; 21060 21061 } 21062 } 21063 } 21064 21065 delete[] curbranch; 21066 }
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 4574 of file util_sparx.cpp.
References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), img_ptr, nx, and EMAN::EMData::update().
04575 { 04576 int i; 04577 int nx=img->get_xsize(); 04578 float *img_ptr = img->get_data(); 04579 float *line_ptr = line->get_data(); 04580 for (i=0;i<length;i++) img_ptr[nx*posline + i] = line_ptr[offset + i]; 04581 img->update(); 04582 }
void Util::set_log_level | ( | int | argc, | |
char * | argv[] | |||
) | [static] |
Set program logging level through command line option "-v N", where N is the level.
[in] | argc | Number of arguments. |
[in] | argv | Argument arrays. |
Definition at line 1163 of file util.cpp.
References EMAN::Log::logger(), and EMAN::Log::set_level().
01164 { 01165 if (argc > 1 && strncmp(argv[1], "-v", 2) == 0) { 01166 char level_str[32]; 01167 strcpy(level_str, argv[1] + 2); 01168 Log::LogLevel log_level = (Log::LogLevel) atoi(level_str); 01169 Log::logger()->set_level(log_level); 01170 } 01171 }
void Util::set_randnum_seed | ( | unsigned long long | seed | ) | [static] |
Set the seed for Randnum class.
[in] | seed | the seed for current random number generator |
Definition at line 712 of file util.cpp.
References EMAN::Randnum::Instance(), and EMAN::Randnum::set_seed().
00713 { 00714 Randnum* randnum = Randnum::Instance(); 00715 randnum->set_seed(seed); 00716 }
static T EMAN::Util::sgn | ( | T & | val | ) | [inline, static] |
void Util::slicereverse | ( | float * | beg, | |
float * | end, | |||
int | nx, | |||
int | ny | |||
) | [static] |
Definition at line 5318 of file util_sparx.cpp.
References colreverse().
Referenced by cyclicshift().
05319 { 05320 int nxy = nx*ny; 05321 colreverse(beg, end, nxy); 05322 }
void Util::sort_mat | ( | float * | left, | |
float * | right, | |||
int * | leftPerm, | |||
int * | rightPerm | |||
) | [static] |
does a sort as in Matlab.
Carries along the Permutation matrix
[in] | left | The array [left .. right] is sorted |
[in] | right | The array [left .. right] is sorted |
[in] | leftPerm | The array [leftPerm rightPerm] is shuffled due to the sorting |
[in] | rightPerm | The array [leftPerm rightPerm] is shuffled due to the sorting Both arrays are reshuffled. |
Definition at line 675 of file util.cpp.
Referenced by Radialize().
00677 { 00678 float *pivot ; int *pivotPerm; 00679 00680 { 00681 float *pLeft = left; int *pLeftPerm = leftPerm; 00682 float *pRight = right; int *pRightPerm = rightPerm; 00683 float scratch = *left; int scratchPerm = *leftPerm; 00684 00685 while (pLeft < pRight) { 00686 while ((*pRight > scratch) && (pLeft < pRight)) { 00687 pRight--; pRightPerm--; 00688 } 00689 if (pLeft != pRight) { 00690 *pLeft = *pRight; *pLeftPerm = *pRightPerm; 00691 pLeft++; pLeftPerm++; 00692 } 00693 while ((*pLeft < scratch) && (pLeft < pRight)) { 00694 pLeft++; pLeftPerm++; 00695 } 00696 if (pLeft != pRight) { 00697 *pRight = *pLeft; *pRightPerm = *pLeftPerm; 00698 pRight--; pRightPerm--; 00699 } 00700 } 00701 *pLeft = scratch; *pLeftPerm = scratchPerm; 00702 pivot = pLeft; pivotPerm= pLeftPerm; 00703 } 00704 if (left < pivot) { 00705 sort_mat(left, pivot - 1,leftPerm,pivotPerm-1); 00706 } 00707 if (right > pivot) { 00708 sort_mat(pivot + 1, right,pivotPerm+1,rightPerm); 00709 } 00710 }
void Util::spline | ( | float * | x, | |
float * | y, | |||
int | n, | |||
float | yp1, | |||
float | ypn, | |||
float * | y2 | |||
) | [static] |
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
x | ||
[in] | y | of x is the tabulated function of length n |
n | ||
[in] | yp1 | : the derivatives of the first point. |
[in] | ypn | : the derivatives of the last point. |
[out] | y2 | is the value of the second derivatives |
Definition at line 379 of file util_sparx.cpp.
00380 { 00381 int i,k; 00382 float p, qn, sig, un, *u; 00383 u = new float[n-1]; 00384 00385 if (yp1 > .99e30){ 00386 y2[0]=u[0]=0.0; 00387 } else { 00388 y2[0]=-.5f; 00389 u[0] =(3.0f/ (x[1] -x[0]))*( (y[1]-y[0])/(x[1]-x[0]) -yp1); 00390 } 00391 00392 for (i=1; i < n-1; i++) { 00393 sig= (x[i] - x[i-1])/(x[i+1] - x[i-1]); 00394 p = sig*y2[i-1] + 2.0f; 00395 y2[i] = (sig-1.0f)/p; 00396 u[i] = (y[i+1] - y[i] )/(x[i+1]-x[i] ) - (y[i] - y[i-1] )/(x[i] -x[i-1]); 00397 u[i] = (6.0f*u[i]/ (x[i+1]-x[i-1]) - sig*u[i-1])/p; 00398 } 00399 00400 if (ypn>.99e30){ 00401 qn=0; un=0; 00402 } else { 00403 qn= .5f; 00404 un= (3.0f/(x[n-1] -x[n-2])) * (ypn - (y[n-1]-y[n-2])/(x[n-1]-x[n-2])); 00405 } 00406 y2[n-1]= (un - qn*u[n-2])/(qn*y2[n-2]+1.0f); 00407 for (k=n-2; k>=0; k--){ 00408 y2[k]=y2[k]*y2[k+1]+u[k]; 00409 } 00410 delete [] u; 00411 }
void Util::spline_mat | ( | float * | x, | |
float * | y, | |||
int | n, | |||
float * | xq, | |||
float * | yq, | |||
int | m | |||
) | [static] |
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.
x | ||
[in] | y | of x is the tabulated function of length n |
n | ||
[in] | xq | is the x values to be splined: has m points. |
[out] | yq | are the splined values |
m |
Definition at line 354 of file util_sparx.cpp.
References spline(), and splint().
00355 { 00356 00357 float x0= x[0]; 00358 float x1= x[1]; 00359 float x2= x[2]; 00360 float y0= y[0]; 00361 float y1= y[1]; 00362 float y2= y[2]; 00363 float yp1 = (y1-y0)/(x1-x0) + (y2-y0)/(x2-x0) - (y2-y1)/(x2-x1) ; 00364 float xn = x[n]; 00365 float xnm1= x[n-1]; 00366 float xnm2= x[n-2]; 00367 float yn = y[n]; 00368 float ynm1= y[n-1]; 00369 float ynm2= y[n-2]; 00370 float ypn= (yn-ynm1)/(xn-xnm1) + (yn-ynm2)/(xn-xnm2) - (ynm1-ynm2)/(xnm1-xnm2) ; 00371 float *y2d = new float[n]; 00372 Util::spline(x,y,n,yp1,ypn,y2d); 00373 Util::splint(x,y,y2d,n,xq,yq,m); //PRB 00374 delete [] y2d; 00375 return; 00376 }
void Util::splint | ( | float * | xa, | |
float * | ya, | |||
float * | y2a, | |||
int | n, | |||
float * | xq, | |||
float * | yq, | |||
int | m | |||
) | [static] |
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.
xa | ||
[in] | ya | of x is the tabulated function of length n |
[in] | y2a | is returned from spline: second derivs |
n | ||
[in] | xq | is the x values to be splined: has m points. |
[out] | yq | are the splined values |
m |
Definition at line 414 of file util_sparx.cpp.
References b.
00415 { 00416 int klo, khi, k; 00417 float h, b, a; 00418 00419 // klo=0; // can try to put here 00420 for (int j=0; j<m;j++){ 00421 klo=0; 00422 khi=n-1; 00423 while (khi-klo >1) { 00424 k=(khi+klo) >>1; 00425 if (xa[k]>xq[j]){ khi=k;} 00426 else { klo=k;} 00427 } 00428 h=xa[khi]- xa[klo]; 00429 if (h==0.0) printf("Bad XA input to routine SPLINT \n"); 00430 a =(xa[khi]-xq[j])/h; 00431 b=(xq[j]-xa[klo])/h; 00432 yq[j]=a*ya[klo] + b*ya[khi] 00433 + ((a*a*a-a)*y2a[klo] 00434 +(b*b*b-b)*y2a[khi]) *(h*h)/6.0f; 00435 } 00436 // 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]); 00437 }
static float EMAN::Util::square | ( | double | x | ) | [inline, static] |
static float EMAN::Util::square | ( | float | x | ) | [inline, static] |
static int EMAN::Util::square | ( | int | n | ) | [inline, static] |
Calculate a number's square.
[in] | n | Given number. |
Definition at line 1659 of file util.h.
Referenced by EMAN::EMData::calc_dist(), EMAN::EMData::calc_mutual_correlation(), EMAN::EMData::calc_sigma_diff(), EMAN::OptVarianceCmp::cmp(), EMAN::EMData::do_radon(), get_stats_cstyle(), EMAN::EMData::little_big_dot(), EMAN::SmartMaskProcessor::process_inplace(), and EMAN::PaintProcessor::process_inplace().
static float EMAN::Util::square_sum | ( | float | x, | |
float | y | |||
) | [inline, static] |
Calcuate (x*x + y*y).
[in] | x | The first number. |
[in] | y | The second number. |
Definition at line 1687 of file util.h.
Referenced by EMAN::EMData::common_lines(), get_stats(), and get_stats_cstyle().
bool Util::sstrncmp | ( | const char * | s1, | |
const char * | s2 | |||
) | [static] |
Safe string compare.
It compares 's2' with the first N characters of 's1', where N is the length of 's2'.
s1 | String 1. Its first strlen(s2) characters will be used to do the comparison. | |
s2 | String 2. Its whole string will be used to do the comparison. |
Definition at line 281 of file util.cpp.
References NullPointerException.
Referenced by EMAN::TestUtil::dump_emdata().
00282 { 00283 if (!s1 || !s2) { 00284 throw NullPointerException("Null string"); 00285 } 00286 00287 if (strncmp(s1, s2, strlen(s2)) == 0) { 00288 return true; 00289 } 00290 00291 return false; 00292 }
string Util::str_to_lower | ( | const string & | s | ) | [static] |
Return a lower case version of the argument string.
s | the string you want to convert to lower case |
Definition at line 275 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::Symmetry3D::get_symmetries(), EMAN::Dict::has_key_ci(), and EMAN::Transform::set_rotation().
00275 { 00276 string ret(s); 00277 std::transform(s.begin(),s.end(),ret.begin(), (int (*)(int) ) std::tolower); 00278 return ret; 00279 }
void Util::sub_fav | ( | EMData * | ave, | |
EMData * | dat, | |||
float | tot, | |||
int | mirror, | |||
vector< int > | numr | |||
) | [static] |
Definition at line 4417 of file util_sparx.cpp.
References EXITFUNC, EMAN::EMData::get_data(), numr, PI2, and EMAN::EMData::update().
04417 { 04418 int nring = numr.size()/3; 04419 float *ave = avep->get_data(); 04420 float *dat = datp->get_data(); 04421 int i, j, numr3i, np; 04422 float arg, cs, si; 04423 int maxrin = numr(3,nring); 04424 if(mirror == 1) { //for mirrored data has to be conjugated 04425 for (i=1; i<=nring; i++) { 04426 numr3i = numr(3,i); 04427 np = numr(2,i)-1; 04428 ave[np] -= dat[np]; 04429 ave[np+1] -= static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) ); 04430 for (j=2; j<numr3i; j=j+2) { 04431 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin ); 04432 cs = cos(arg); 04433 si = sin(arg); 04434 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg)) 04435 ave[np + j] -= dat[np + j]*cs - dat[np + j +1]*si; 04436 ave[np + j +1] += dat[np + j]*si + dat[np + j +1]*cs; 04437 } 04438 } 04439 } else { 04440 for (i=1; i<=nring; i++) { 04441 numr3i = numr(3,i); 04442 np = numr(2,i)-1; 04443 ave[np] -= dat[np]; 04444 ave[np+1] -= static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) ); 04445 for (j=2; j<numr3i; j=j+2) { 04446 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin ); 04447 cs = cos(arg); 04448 si = sin(arg); 04449 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg)) 04450 ave[np + j] -= dat[np + j]*cs - dat[np + j +1]*si; 04451 ave[np + j +1] -= dat[np + j]*si + dat[np + j +1]*cs; 04452 } 04453 } 04454 } 04455 avep->update(); 04456 EXITFUNC; 04457 }
Definition at line 17552 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, 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().
17553 { 17554 ENTERFUNC; 17555 /* Exception Handle */ 17556 if (!img) { 17557 throw NullPointerException("NULL input image"); 17558 } 17559 /* ========= img -= img1 ===================== */ 17560 17561 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17562 size_t size = (size_t)nx*ny*nz; 17563 float *img_ptr = img->get_data(); 17564 float *img1_ptr = img1->get_data(); 17565 for (size_t i=0;i<size;++i) img_ptr[i] -= img1_ptr[i]; 17566 img->update(); 17567 17568 EXITFUNC; 17569 }
Definition at line 17334 of file util_sparx.cpp.
References EMAN::EMData::copy_head(), ENTERFUNC, EXITFUNC, 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().
17335 { 17336 ENTERFUNC; 17337 /* Exception Handle */ 17338 if (!img) { 17339 throw NullPointerException("NULL input image"); 17340 } 17341 /* ============== output = img - img1 ================ */ 17342 17343 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17344 size_t size = (size_t)nx*ny*nz; 17345 EMData * img2 = img->copy_head(); 17346 float *img_ptr = img->get_data(); 17347 float *img2_ptr = img2->get_data(); 17348 float *img1_ptr = img1->get_data(); 17349 for (size_t i=0;i<size;++i) img2_ptr[i] = img_ptr[i] - img1_ptr[i]; 17350 img2->update(); 17351 if(img->is_complex()) { 17352 img2->set_complex(true); 17353 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17354 } 17355 17356 EXITFUNC; 17357 return img2; 17358 }
Perform singular value decomposition on a set of images.
data | A List of data objects to be decomposed | |
nvec | Number of basis vectors to return, 0 returns full decomposition |
Definition at line 322 of file util.cpp.
References copy_head(), get_value_at(), EMAN::EMData::set_value_at(), V, x, X, and y.
Referenced by EMAN::PCA::dopca().
00322 { 00323 int nimg=data.size(); 00324 if (nvec==0) nvec=nimg; 00325 vector<EMData *> ret(nvec); 00326 if (nimg==0) return ret; 00327 int pixels=data[0]->get_xsize()*data[0]->get_ysize()*data[0]->get_zsize(); 00328 00329 // Allocate the working space 00330 gsl_vector *work=gsl_vector_alloc(nimg); 00331 gsl_vector *S=gsl_vector_alloc(nimg); 00332 gsl_matrix *A=gsl_matrix_alloc(pixels,nimg); 00333 gsl_matrix *V=gsl_matrix_alloc(nimg,nimg); 00334 gsl_matrix *X=gsl_matrix_alloc(nimg,nimg); 00335 00336 int im,x,y,z,i; 00337 for (im=0; im<nimg; im++) { 00338 for (z=0,i=0; z<data[0]->get_zsize(); z++) { 00339 for (y=0; y<data[0]->get_ysize(); y++) { 00340 for (x=0; x<data[0]->get_xsize(); x++,i++) { 00341 gsl_matrix_set(A,i,im,data[im]->get_value_at(x,y,z)); 00342 } 00343 } 00344 } 00345 } 00346 00347 // This calculates the SVD 00348 gsl_linalg_SV_decomp_mod (A,X, V, S, work); 00349 00350 for (im=0; im<nvec; im++) { 00351 EMData *a=data[0]->copy_head(); 00352 ret[im]=a; 00353 for (z=0,i=0; z<data[0]->get_zsize(); z++) { 00354 for (y=0; y<data[0]->get_ysize(); y++) { 00355 for (x=0; x<data[0]->get_xsize(); x++,i++) { 00356 a->set_value_at(x,y,z,static_cast<float>(gsl_matrix_get(A,i,im))); 00357 } 00358 } 00359 } 00360 } 00361 return ret; 00362 }
float Util::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 | |||
) | [static] |
Definition at line 6043 of file util_sparx.cpp.
References phase(), and sqrt().
Referenced by ctf2_rimg(), ctf_img(), ctf_rimg(), and EMAN::Processor::EMFourierFilterFunc().
06044 { 06045 float cst = cs*1.0e7f; 06046 06047 wgh /= 100.0; 06048 float phase = atan(wgh/sqrt(1.0f-wgh*wgh)); 06049 float lambda=12.398f/sqrt(voltage*(1022.0f+voltage)); 06050 float ak2 = ak*ak; 06051 float g1 = dzz*1.0e4f*lambda*ak2; 06052 float g2 = cst*lambda*lambda*lambda*ak2*ak2/2.0f; 06053 06054 float ctfv = static_cast<float>( sin(M_PI*(g1-g2)+phase)*sign ); 06055 if(b_factor != 0.0f) ctfv *= exp(-b_factor*ak2/4.0f); 06056 06057 return ctfv; 06058 }
static float EMAN::Util::trilinear_interpolate | ( | float | p1, | |
float | p2, | |||
float | p3, | |||
float | p4, | |||
float | p5, | |||
float | p6, | |||
float | p7, | |||
float | p8, | |||
float | t, | |||
float | u, | |||
float | v | |||
) | [inline, static] |
Calculate trilinear interpolation.
[in] | p1 | The first number. corresponding to (x0,y0,z0). |
[in] | p2 | The second number. corresponding to (x1,y0,z0). |
[in] | p3 | The third number. corresponding to (x0,y1, z0). |
[in] | p4 | The fourth number. corresponding to (x1,y1,z0). |
[in] | p5 | The fifth number. corresponding to (x0,y0,z1). |
[in] | p6 | The sixth number. corresponding to (x1,y0,z1). |
[in] | p7 | The seventh number. corresponding to (x0,y1,z1). |
[in] | p8 | The eighth number. corresponding to (x1,y1,z1). |
[in] | t | t |
[in] | u | u |
[in] | v | v |
Definition at line 1590 of file util.h.
Referenced by EMAN::EMData::cut_slice(), EMAN::EMData::extract_box(), EMAN::SymSearchProcessor::process_inplace(), EMAN::MaxValProjector::project3d(), EMAN::StandardProjector::project3d(), EMAN::EMData::sget_value_at_interp(), and EMAN::TransformProcessor::transform().
float Util::triquad | ( | float | r, | |
float | s, | |||
float | t, | |||
float * | fdata | |||
) | [static] |
Quadratic interpolation (3D).
r | ||
s | ||
t | ||
fdata |
Definition at line 1910 of file util_sparx.cpp.
01911 { 01912 01913 const float C2 = 0.5f; //1.0 / 2.0; 01914 const float C4 = 0.25f; //1.0 / 4.0; 01915 const float C8 = 0.125f; //1.0 / 8.0; 01916 01917 float RS = R * S; 01918 float ST = S * T; 01919 float RT = R * T; 01920 float RST = R * ST; 01921 01922 float RSQ = 1-R*R; 01923 float SSQ = 1-S*S; 01924 float TSQ = 1-T*T; 01925 01926 float RM1 = (1-R); 01927 float SM1 = (1-S); 01928 float TM1 = (1-T); 01929 01930 float RP1 = (1+R); 01931 float SP1 = (1+S); 01932 float TP1 = (1+T); 01933 01934 float triquad = 01935 (-C8) * RST * RM1 * SM1 * TM1 * fdata[0] + 01936 ( C4) * ST * RSQ * SM1 * TM1 * fdata[1] + 01937 ( C8) * RST * RP1 * SM1 * TM1 * fdata[2] + 01938 ( C4) * RT * RM1 * SSQ * TM1 * fdata[3] + 01939 (-C2) * T * RSQ * SSQ * TM1 * fdata[4] + 01940 (-C4) * RT * RP1 * SSQ * TM1 * fdata[5] + 01941 ( C8) * RST * RM1 * SP1 * TM1 * fdata[6] + 01942 (-C4) * ST * RSQ * SP1 * TM1 * fdata[7] + 01943 (-C8) * RST * RP1 * SP1 * TM1 * fdata[8] + 01944 // 01945 ( C4) * RS * RM1 * SM1 * TSQ * fdata[9] + 01946 (-C2) * S * RSQ * SM1 * TSQ * fdata[10] + 01947 (-C4) * RS * RP1 * SM1 * TSQ * fdata[11] + 01948 (-C2) * R * RM1 * SSQ * TSQ * fdata[12] + 01949 RSQ * SSQ * TSQ * fdata[13] + 01950 ( C2) * R * RP1 * SSQ * TSQ * fdata[14] + 01951 (-C4) * RS * RM1 * SP1 * TSQ * fdata[15] + 01952 ( C2) * S * RSQ * SP1 * TSQ * fdata[16] + 01953 ( C4) * RS * RP1 * SP1 * TSQ * fdata[17] + 01954 // 01955 ( C8) * RST * RM1 * SM1 * TP1 * fdata[18] + 01956 (-C4) * ST * RSQ * SM1 * TP1 * fdata[19] + 01957 (-C8) * RST * RP1 * SM1 * TP1 * fdata[20] + 01958 (-C4) * RT * RM1 * SSQ * TP1 * fdata[21] + 01959 ( C2) * T * RSQ * SSQ * TP1 * fdata[22] + 01960 ( C4) * RT * RP1 * SSQ * TP1 * fdata[23] + 01961 (-C8) * RST * RM1 * SP1 * TP1 * fdata[24] + 01962 ( C4) * ST * RSQ * SP1 * TP1 * fdata[25] + 01963 ( C8) * RST * RP1 * SP1 * TP1 * fdata[26] ; 01964 return triquad; 01965 }
int Util::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 | |||
) | [static] |
Definition at line 7793 of file util_sparx.cpp.
References abs, addnod_(), and left_().
07797 { 07798 /* System generated locals */ 07799 int i__1, i__2; 07800 07801 /* Local variables */ 07802 static double d__; 07803 static int i__, j; 07804 static double d1, d2, d3; 07805 static int i0, lp, kt, ku, lpl, nku; 07806 static int nexti; 07807 07808 07809 /* *********************************************************** */ 07810 07811 /* From STRIPACK */ 07812 /* Robert J. Renka */ 07813 /* Dept. of Computer Science */ 07814 /* Univ. of North Texas */ 07815 /* renka@cs.unt.edu */ 07816 /* 01/20/03 */ 07817 07818 /* This is an alternative to TRMESH with the inclusion of */ 07819 /* an efficient means of removing duplicate or nearly dupli- */ 07820 /* cate nodes. */ 07821 07822 /* This subroutine creates a Delaunay triangulation of a */ 07823 /* set of N arbitrarily distributed points, referred to as */ 07824 /* nodes, on the surface of the unit sphere. Refer to Sub- */ 07825 /* routine TRMESH for definitions and a list of additional */ 07826 /* subroutines. This routine is an alternative to TRMESH */ 07827 /* with the inclusion of an efficient means of removing dup- */ 07828 /* licate or nearly duplicate nodes. */ 07829 07830 /* The algorithm has expected time complexity O(N*log(N)) */ 07831 /* for random nodal distributions. */ 07832 07833 07834 /* On input: */ 07835 07836 /* N0 = Number of nodes, possibly including duplicates. */ 07837 /* N0 .GE. 3. */ 07838 07839 /* TOL = Tolerance defining a pair of duplicate nodes: */ 07840 /* bound on the deviation from 1 of the cosine of */ 07841 /* the angle between the nodes. Note that */ 07842 /* |1-cos(A)| is approximately A*A/2. */ 07843 07844 /* The above parameters are not altered by this routine. */ 07845 07846 /* X,Y,Z = Arrays of length at least N0 containing the */ 07847 /* Cartesian coordinates of nodes. (X(K),Y(K), */ 07848 /* Z(K)) is referred to as node K, and K is re- */ 07849 /* ferred to as a nodal index. It is required */ 07850 /* that X(K)**2 + Y(K)**2 + Z(K)**2 = 1 for all */ 07851 /* K. The first three nodes must not be col- */ 07852 /* linear (lie on a common great circle). */ 07853 07854 /* LIST,LPTR = Arrays of length at least 6*N0-12. */ 07855 07856 /* LEND = Array of length at least N0. */ 07857 07858 /* INDX = Array of length at least N0. */ 07859 07860 /* LCNT = Array of length at least N0 (length N is */ 07861 /* sufficient). */ 07862 07863 /* NEAR,NEXT,DIST = Work space arrays of length at */ 07864 /* least N0. The space is used to */ 07865 /* efficiently determine the nearest */ 07866 /* triangulation node to each un- */ 07867 /* processed node for use by ADDNOD. */ 07868 07869 /* On output: */ 07870 07871 /* N = Number of nodes in the triangulation. 3 .LE. N */ 07872 /* .LE. N0, or N = 0 if IER < 0. */ 07873 07874 /* X,Y,Z = Arrays containing the Cartesian coordinates */ 07875 /* of the triangulation nodes in the first N */ 07876 /* locations. The original array elements are */ 07877 /* shifted down as necessary to eliminate dup- */ 07878 /* licate nodes. */ 07879 07880 /* LIST = Set of nodal indexes which, along with LPTR, */ 07881 /* LEND, and LNEW, define the triangulation as a */ 07882 /* set of N adjacency lists -- counterclockwise- */ 07883 /* ordered sequences of neighboring nodes such */ 07884 /* that the first and last neighbors of a bound- */ 07885 /* ary node are boundary nodes (the first neigh- */ 07886 /* bor of an interior node is arbitrary). In */ 07887 /* order to distinguish between interior and */ 07888 /* boundary nodes, the last neighbor of each */ 07889 /* boundary node is represented by the negative */ 07890 /* of its index. */ 07891 07892 /* LPTR = Set of pointers (LIST indexes) in one-to-one */ 07893 /* correspondence with the elements of LIST. */ 07894 /* LIST(LPTR(I)) indexes the node which follows */ 07895 /* LIST(I) in cyclical counterclockwise order */ 07896 /* (the first neighbor follows the last neigh- */ 07897 /* bor). */ 07898 07899 /* LEND = Set of pointers to adjacency lists. LEND(K) */ 07900 /* points to the last neighbor of node K for */ 07901 /* K = 1,...,N. Thus, LIST(LEND(K)) < 0 if and */ 07902 /* only if K is a boundary node. */ 07903 07904 /* LNEW = Pointer to the first empty location in LIST */ 07905 /* and LPTR (list length plus one). LIST, LPTR, */ 07906 /* LEND, and LNEW are not altered if IER < 0, */ 07907 /* and are incomplete if IER > 0. */ 07908 07909 /* INDX = Array of output (triangulation) nodal indexes */ 07910 /* associated with input nodes. For I = 1 to */ 07911 /* N0, INDX(I) is the index (for X, Y, and Z) of */ 07912 /* the triangulation node with the same (or */ 07913 /* nearly the same) coordinates as input node I. */ 07914 07915 /* LCNT = Array of int weights (counts) associated */ 07916 /* with the triangulation nodes. For I = 1 to */ 07917 /* N, LCNT(I) is the number of occurrences of */ 07918 /* node I in the input node set, and thus the */ 07919 /* number of duplicates is LCNT(I)-1. */ 07920 07921 /* NEAR,NEXT,DIST = Garbage. */ 07922 07923 /* IER = Error indicator: */ 07924 /* IER = 0 if no errors were encountered. */ 07925 /* IER = -1 if N0 < 3 on input. */ 07926 /* IER = -2 if the first three nodes are */ 07927 /* collinear. */ 07928 /* IER = -3 if Subroutine ADDNOD returns an error */ 07929 /* flag. This should not occur. */ 07930 07931 /* Modules required by TRMSH3: ADDNOD, BDYADD, COVSPH, */ 07932 /* INSERT, INTADD, JRAND, */ 07933 /* LEFT, LSTPTR, STORE, SWAP, */ 07934 /* SWPTST, TRFIND */ 07935 07936 /* Intrinsic function called by TRMSH3: ABS */ 07937 07938 /* *********************************************************** */ 07939 07940 07941 /* Local parameters: */ 07942 07943 /* D = (Negative cosine of) distance from node KT to */ 07944 /* node I */ 07945 /* D1,D2,D3 = Distances from node KU to nodes 1, 2, and 3, */ 07946 /* respectively */ 07947 /* I,J = Nodal indexes */ 07948 /* I0 = Index of the node preceding I in a sequence of */ 07949 /* unprocessed nodes: I = NEXT(I0) */ 07950 /* KT = Index of a triangulation node */ 07951 /* KU = Index of an unprocessed node and DO-loop index */ 07952 /* LP = LIST index (pointer) of a neighbor of KT */ 07953 /* LPL = Pointer to the last neighbor of KT */ 07954 /* NEXTI = NEXT(I) */ 07955 /* NKU = NEAR(KU) */ 07956 07957 /* Parameter adjustments */ 07958 --dist; 07959 --next; 07960 --near__; 07961 --indx; 07962 --lend; 07963 --z__; 07964 --y; 07965 --x; 07966 --list; 07967 --lptr; 07968 --lcnt; 07969 07970 /* Function Body */ 07971 if (*n0 < 3) { 07972 *n = 0; 07973 *ier = -1; 07974 return 0; 07975 } 07976 07977 /* Store the first triangle in the linked list. */ 07978 07979 if (! left_(&x[1], &y[1], &z__[1], &x[2], &y[2], &z__[2], &x[3], &y[3], & 07980 z__[3])) { 07981 07982 /* The first triangle is (3,2,1) = (2,1,3) = (1,3,2). */ 07983 07984 list[1] = 3; 07985 lptr[1] = 2; 07986 list[2] = -2; 07987 lptr[2] = 1; 07988 lend[1] = 2; 07989 07990 list[3] = 1; 07991 lptr[3] = 4; 07992 list[4] = -3; 07993 lptr[4] = 3; 07994 lend[2] = 4; 07995 07996 list[5] = 2; 07997 lptr[5] = 6; 07998 list[6] = -1; 07999 lptr[6] = 5; 08000 lend[3] = 6; 08001 08002 } else if (! left_(&x[2], &y[2], &z__[2], &x[1], &y[1], &z__[1], &x[3], & 08003 y[3], &z__[3])) { 08004 08005 /* The first triangle is (1,2,3): 3 Strictly Left 1->2, */ 08006 /* i.e., node 3 lies in the left hemisphere defined by */ 08007 /* arc 1->2. */ 08008 08009 list[1] = 2; 08010 lptr[1] = 2; 08011 list[2] = -3; 08012 lptr[2] = 1; 08013 lend[1] = 2; 08014 08015 list[3] = 3; 08016 lptr[3] = 4; 08017 list[4] = -1; 08018 lptr[4] = 3; 08019 lend[2] = 4; 08020 08021 list[5] = 1; 08022 lptr[5] = 6; 08023 list[6] = -2; 08024 lptr[6] = 5; 08025 lend[3] = 6; 08026 08027 08028 } else { 08029 08030 /* The first three nodes are collinear. */ 08031 08032 *n = 0; 08033 *ier = -2; 08034 return 0; 08035 } 08036 08037 //printf("pass check colinear\n"); 08038 08039 /* Initialize LNEW, INDX, and LCNT, and test for N = 3. */ 08040 08041 *lnew = 7; 08042 indx[1] = 1; 08043 indx[2] = 2; 08044 indx[3] = 3; 08045 lcnt[1] = 1; 08046 lcnt[2] = 1; 08047 lcnt[3] = 1; 08048 if (*n0 == 3) { 08049 *n = 3; 08050 *ier = 0; 08051 return 0; 08052 } 08053 08054 /* A nearest-node data structure (NEAR, NEXT, and DIST) is */ 08055 /* used to obtain an expected-time (N*log(N)) incremental */ 08056 /* algorithm by enabling constant search time for locating */ 08057 /* each new node in the triangulation. */ 08058 08059 /* For each unprocessed node KU, NEAR(KU) is the index of the */ 08060 /* triangulation node closest to KU (used as the starting */ 08061 /* point for the search in Subroutine TRFIND) and DIST(KU) */ 08062 /* is an increasing function of the arc length (angular */ 08063 /* distance) between nodes KU and NEAR(KU): -Cos(a) for */ 08064 /* arc length a. */ 08065 08066 /* Since it is necessary to efficiently find the subset of */ 08067 /* unprocessed nodes associated with each triangulation */ 08068 /* node J (those that have J as their NEAR entries), the */ 08069 /* subsets are stored in NEAR and NEXT as follows: for */ 08070 /* each node J in the triangulation, I = NEAR(J) is the */ 08071 /* first unprocessed node in J's set (with I = 0 if the */ 08072 /* set is empty), L = NEXT(I) (if I > 0) is the second, */ 08073 /* NEXT(L) (if L > 0) is the third, etc. The nodes in each */ 08074 /* set are initially ordered by increasing indexes (which */ 08075 /* maximizes efficiency) but that ordering is not main- */ 08076 /* tained as the data structure is updated. */ 08077 08078 /* Initialize the data structure for the single triangle. */ 08079 08080 near__[1] = 0; 08081 near__[2] = 0; 08082 near__[3] = 0; 08083 for (ku = *n0; ku >= 4; --ku) { 08084 d1 = -(x[ku] * x[1] + y[ku] * y[1] + z__[ku] * z__[1]); 08085 d2 = -(x[ku] * x[2] + y[ku] * y[2] + z__[ku] * z__[2]); 08086 d3 = -(x[ku] * x[3] + y[ku] * y[3] + z__[ku] * z__[3]); 08087 if (d1 <= d2 && d1 <= d3) { 08088 near__[ku] = 1; 08089 dist[ku] = d1; 08090 next[ku] = near__[1]; 08091 near__[1] = ku; 08092 } else if (d2 <= d1 && d2 <= d3) { 08093 near__[ku] = 2; 08094 dist[ku] = d2; 08095 next[ku] = near__[2]; 08096 near__[2] = ku; 08097 } else { 08098 near__[ku] = 3; 08099 dist[ku] = d3; 08100 next[ku] = near__[3]; 08101 near__[3] = ku; 08102 } 08103 /* L1: */ 08104 } 08105 08106 /* Loop on unprocessed nodes KU. KT is the number of nodes */ 08107 /* in the triangulation, and NKU = NEAR(KU). */ 08108 08109 kt = 3; 08110 i__1 = *n0; 08111 for (ku = 4; ku <= i__1; ++ku) { 08112 nku = near__[ku]; 08113 08114 /* Remove KU from the set of unprocessed nodes associated */ 08115 /* with NEAR(KU). */ 08116 i__ = nku; 08117 if (near__[i__] == ku) { 08118 near__[i__] = next[ku]; 08119 } else { 08120 i__ = near__[i__]; 08121 L2: 08122 i0 = i__; 08123 i__ = next[i0]; 08124 if (i__ != ku) { 08125 goto L2; 08126 } 08127 next[i0] = next[ku]; 08128 } 08129 near__[ku] = 0; 08130 08131 /* Bypass duplicate nodes. */ 08132 08133 if (dist[ku] <= *tol - 1.) { 08134 indx[ku] = -nku; 08135 ++lcnt[nku]; 08136 goto L6; 08137 } 08138 08139 08140 /* Add a new triangulation node KT with LCNT(KT) = 1. */ 08141 ++kt; 08142 x[kt] = x[ku]; 08143 y[kt] = y[ku]; 08144 z__[kt] = z__[ku]; 08145 indx[ku] = kt; 08146 lcnt[kt] = 1; 08147 addnod_(&nku, &kt, &x[1], &y[1], &z__[1], &list[1], &lptr[1], &lend[1] 08148 , lnew, ier); 08149 if (*ier != 0) { 08150 *n = 0; 08151 *ier = -3; 08152 return 0; 08153 } 08154 08155 /* Loop on neighbors J of node KT. */ 08156 08157 lpl = lend[kt]; 08158 lp = lpl; 08159 L3: 08160 lp = lptr[lp]; 08161 j = (i__2 = list[lp], abs(i__2)); 08162 08163 /* Loop on elements I in the sequence of unprocessed nodes */ 08164 /* associated with J: KT is a candidate for replacing J */ 08165 /* as the nearest triangulation node to I. The next value */ 08166 /* of I in the sequence, NEXT(I), must be saved before I */ 08167 /* is moved because it is altered by adding I to KT's set. */ 08168 08169 i__ = near__[j]; 08170 L4: 08171 if (i__ == 0) { 08172 goto L5; 08173 } 08174 nexti = next[i__]; 08175 08176 /* Test for the distance from I to KT less than the distance */ 08177 /* from I to J. */ 08178 08179 d__ = -(x[i__] * x[kt] + y[i__] * y[kt] + z__[i__] * z__[kt]); 08180 if (d__ < dist[i__]) { 08181 08182 /* Replace J by KT as the nearest triangulation node to I: */ 08183 /* update NEAR(I) and DIST(I), and remove I from J's set */ 08184 /* of unprocessed nodes and add it to KT's set. */ 08185 08186 near__[i__] = kt; 08187 dist[i__] = d__; 08188 if (i__ == near__[j]) { 08189 near__[j] = nexti; 08190 } else { 08191 next[i0] = nexti; 08192 } 08193 next[i__] = near__[kt]; 08194 near__[kt] = i__; 08195 } else { 08196 i0 = i__; 08197 } 08198 08199 /* Bottom of loop on I. */ 08200 08201 i__ = nexti; 08202 goto L4; 08203 08204 /* Bottom of loop on neighbors J. */ 08205 08206 L5: 08207 if (lp != lpl) { 08208 goto L3; 08209 } 08210 L6: 08211 ; 08212 } 08213 *n = kt; 08214 *ier = 0; 08215 return 0; 08216 } /* trmsh3_ */
vector< float > Util::twoD_fine_ali | ( | EMData * | image, | |
EMData * | refim, | |||
EMData * | mask, | |||
float | ang, | |||
float | sxs, | |||
float | sys | |||
) | [static] |
Definition at line 19329 of file util_sparx.cpp.
References EMAN::EMData::cmp(), dt, EMAN::EMData::rot_scale_trans2D(), setulb_(), and SIXTY.
19329 { 19330 19331 EMData *rot; 19332 19333 const int nmax=3, mmax=3; 19334 char task[60], csave[60]; 19335 long int lsave[4]; 19336 long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44]; 19337 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]; 19338 long int SIXTY=60; 19339 19340 // We wish to have no output. 19341 iprint = -1; 19342 19343 //c We specify the tolerances in the stopping criteria. 19344 factr=1.0e1; 19345 pgtol=1.0e-5; 19346 19347 // We specify the dimension n of the sample problem and the number 19348 // m of limited memory corrections stored. (n and m should not 19349 // exceed the limits nmax and mmax respectively.) 19350 n=3; 19351 m=3; 19352 19353 // We now provide nbd which defines the bounds on the variables: 19354 // l specifies the lower bounds, 19355 // u specifies the upper bounds. 19356 // x specifies the initial guess 19357 x[0] = ang; nbd[0] = 2; l[0] = ang-2.0; u[0] = ang+2.0; 19358 x[1] = sxs; nbd[1] = 2; l[1] = sxs-1.5; u[1] = sxs+1.5; 19359 x[2] = sys; nbd[2] = 2; l[2] = sys-1.5; u[2] = sys+1.5; 19360 19361 19362 // We start the iteration by initializing task. 19363 // (**MUST clear remaining chars in task with spaces (else crash)!**) 19364 strcpy(task,"START"); 19365 for (int i=5;i<60;i++) task[i]=' '; 19366 19367 // This is the call to the L-BFGS-B code. 19368 // (* call the L-BFGS-B routine with task='START' once before loop *) 19369 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19370 //int step = 1; 19371 19372 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *) 19373 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) { 19374 19375 if (strncmp(task,"FG",2)==0) { 19376 // the minimization routine has returned to request the 19377 // function f and gradient g values at the current x 19378 19379 // Compute function value f for the sample problem. 19380 rot = new EMData(); 19381 rot = image->rot_scale_trans2D((float)x[0], (float)x[1], (float)x[2], 1.0f); 19382 f = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19383 //f = -f; 19384 delete rot; 19385 19386 // Compute gradient g for the sample problem. 19387 float dt = 1.0e-3f; 19388 rot = new EMData(); 19389 rot = image->rot_scale_trans2D((float)x[0]+dt, (float)x[1], (float)x[2], 1.0f); 19390 f1 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19391 //f1 = -f1; 19392 g[0] = (f1-f)/dt; 19393 delete rot; 19394 19395 dt = 1.0e-2f; 19396 rot = new EMData(); 19397 rot = image->rot_scale_trans2D((float)x[0], (float)x[1]+dt, (float)x[2], 1.0f); 19398 f2 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19399 //f2 = -f2; 19400 g[1] = (f2-f)/dt; 19401 delete rot; 19402 19403 rot = new EMData(); 19404 rot = image->rot_scale_trans2D((float)x[0], (float)x[1], (float)x[2]+dt, 1.0f); 19405 f3 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19406 //f3 = -f3; 19407 g[2] = (f3-f)/dt; 19408 delete rot; 19409 } 19410 19411 //c go back to the minimization routine. 19412 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19413 //step++; 19414 } 19415 19416 //printf("Total step is %d\n", step); 19417 vector<float> res; 19418 res.push_back(static_cast<float>(x[0])); 19419 res.push_back(static_cast<float>(x[1])); 19420 res.push_back(static_cast<float>(x[2])); 19421 //res.push_back(step); 19422 return res; 19423 }
vector< float > Util::twoD_fine_ali_G | ( | EMData * | image, | |
EMData * | refim, | |||
EMData * | mask, | |||
Util::KaiserBessel & | kb, | |||
float | ang, | |||
float | sxs, | |||
float | sys | |||
) | [static] |
Definition at line 19425 of file util_sparx.cpp.
References EMAN::EMData::cmp(), dt, pi, EMAN::EMData::rot_scale_conv7(), setulb_(), and SIXTY.
19425 { 19426 19427 EMData *rot; 19428 19429 const int nmax=3, mmax=3; 19430 char task[60], csave[60]; 19431 long int lsave[4]; 19432 long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44]; 19433 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]; 19434 long int SIXTY=60; 19435 19436 // We wish to have no output. 19437 iprint = -1; 19438 19439 //c We specify the tolerances in the stopping criteria. 19440 factr=1.0e1; 19441 pgtol=1.0e-5; 19442 19443 // We specify the dimension n of the sample problem and the number 19444 // m of limited memory corrections stored. (n and m should not 19445 // exceed the limits nmax and mmax respectively.) 19446 n=3; 19447 m=3; 19448 19449 // We now provide nbd which defines the bounds on the variables: 19450 // l specifies the lower bounds, 19451 // u specifies the upper bounds. 19452 // x specifies the initial guess 19453 x[0] = ang; nbd[0] = 2; l[0] = ang-2.0; u[0] = ang+2.0; 19454 x[1] = sxs; nbd[1] = 2; l[1] = sxs-1.5; u[1] = sxs+1.5; 19455 x[2] = sys; nbd[2] = 2; l[2] = sys-1.5; u[2] = sys+1.5; 19456 19457 19458 // We start the iteration by initializing task. 19459 // (**MUST clear remaining chars in task with spaces (else crash)!**) 19460 strcpy(task,"START"); 19461 for (int i=5;i<60;i++) task[i]=' '; 19462 19463 // This is the call to the L-BFGS-B code. 19464 // (* call the L-BFGS-B routine with task='START' once before loop *) 19465 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19466 //int step = 1; 19467 19468 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *) 19469 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) { 19470 19471 if (strncmp(task,"FG",2)==0) { 19472 // the minimization routine has returned to request the 19473 // function f and gradient g values at the current x 19474 19475 // Compute function value f for the sample problem. 19476 rot = new EMData(); 19477 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1], (float)x[2], kb, 1.0f); 19478 f = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19479 //f = -f; 19480 delete rot; 19481 19482 // Compute gradient g for the sample problem. 19483 float dt = 1.0e-3f; 19484 rot = new EMData(); 19485 rot = image->rot_scale_conv7((float)((x[0]+dt)*pi/180), (float)x[1], (float)x[2], kb, 1.0f); 19486 f1 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19487 //f1 = -f1; 19488 g[0] = (f1-f)/dt; 19489 delete rot; 19490 19491 rot = new EMData(); 19492 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1]+dt, (float)x[2], kb, 1.0); 19493 f2 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19494 //f2 = -f2; 19495 g[1] = (f2-f)/dt; 19496 delete rot; 19497 19498 rot = new EMData(); 19499 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1], (float)x[2]+dt, kb, 1.0f); 19500 f3 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19501 //f3 = -f3; 19502 g[2] = (f3-f)/dt; 19503 delete rot; 19504 } 19505 19506 //c go back to the minimization routine. 19507 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19508 //step++; 19509 } 19510 19511 //printf("Total step is %d\n", step); 19512 vector<float> res; 19513 res.push_back(static_cast<float>(x[0])); 19514 res.push_back(static_cast<float>(x[1])); 19515 res.push_back(static_cast<float>(x[2])); 19516 //res.push_back(step); 19517 return res; 19518 }
vector< float > Util::twoD_fine_ali_SD | ( | EMData * | image, | |
EMData * | refim, | |||
EMData * | mask, | |||
float | ang, | |||
float | sxs, | |||
float | sys | |||
) | [static] |
Definition at line 19677 of file util_sparx.cpp.
References ccc_images(), and Steepda().
19677 { 19678 19679 double x[4]; 19680 int n; 19681 int l = 3; 19682 int m = 200; 19683 double e = 1e-9; 19684 double step = 0.01; 19685 float (*my_func)(EMData* , EMData* , EMData* , float , float , float) = ccc_images; 19686 19687 x[1] = ang; 19688 x[2] = sxs; 19689 x[3] = sys; 19690 19691 Steepda(x, step, e, l, m, &n, my_func, image, refim, mask); // Call steepest descent optimization subroutine 19692 //printf("Took %d steps\n", n); 19693 19694 vector<float> res; 19695 res.push_back(static_cast<float>(x[1])); 19696 res.push_back(static_cast<float>(x[2])); 19697 res.push_back(static_cast<float>(x[3])); 19698 res.push_back(static_cast<float>(n)); 19699 return res; 19700 }
vector< float > Util::twoD_fine_ali_SD_G | ( | EMData * | image, | |
EMData * | refim, | |||
EMData * | mask, | |||
Util::KaiserBessel & | kb, | |||
float | ang, | |||
float | sxs, | |||
float | sys | |||
) | [static] |
Definition at line 19934 of file util_sparx.cpp.
References ccc_images_G(), and Steepda_G().
19934 { 19935 19936 double x[4]; 19937 int n; 19938 int l = 3; 19939 int m = 200; 19940 double e = 1e-9; 19941 double step = 0.001; 19942 float (*my_func)(EMData* , EMData* , EMData* , Util::KaiserBessel&, float , float , float) = ccc_images_G; 19943 19944 x[1] = ang; 19945 x[2] = sxs; 19946 x[3] = sys; 19947 19948 Steepda_G(x, step, e, l, m, &n, my_func, image, refim, mask, kb); // Call steepest descent optimization subroutine 19949 //printf("Took %d steps\n", n); 19950 19951 vector<float> res; 19952 res.push_back(static_cast<float>(x[1])); 19953 res.push_back(static_cast<float>(x[2])); 19954 res.push_back(static_cast<float>(x[3])); 19955 res.push_back(static_cast<float>(n)); 19956 return res; 19957 }
vector< float > Util::twoD_to_3D_ali | ( | EMData * | volft, | |
Util::KaiserBessel & | kb, | |||
EMData * | refim, | |||
EMData * | mask, | |||
float | phi, | |||
float | theta, | |||
float | psi, | |||
float | sxs, | |||
float | sxy | |||
) | [static] |
Definition at line 19520 of file util_sparx.cpp.
References EMAN::EMData::cmp(), dt, EMAN::EMData::extract_plane(), proj, setulb_(), and SIXTY.
19520 { 19521 19522 EMData *proj, *proj2; 19523 19524 const int nmax=5, mmax=5; 19525 char task[60], csave[60]; 19526 long int lsave[4]; 19527 long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44]; 19528 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]; 19529 long int SIXTY=60; 19530 19531 // We wish to have no output. 19532 iprint = -1; 19533 19534 //c We specify the tolerances in the stopping criteria. 19535 factr=1.0e1; 19536 pgtol=1.0e-5; 19537 19538 // We specify the dimension n of the sample problem and the number 19539 // m of limited memory corrections stored. (n and m should not 19540 // exceed the limits nmax and mmax respectively.) 19541 n=5; 19542 m=5; 19543 19544 // We now provide nbd which defines the bounds on the variables: 19545 // l specifies the lower bounds, 19546 // u specifies the upper bounds. 19547 // x specifies the initial guess 19548 x[0] = phi; nbd[0] = 2; l[0] = phi-2.0; u[0] = phi+2.0; 19549 x[1] = theta; nbd[1] = 2; l[1] = theta-2.0; u[1] = theta+2.0; 19550 x[2] = psi; nbd[2] = 2; l[2] = psi-2.0; u[2] = psi+2.0; 19551 x[3] = sxs; nbd[3] = 2; l[3] = sxs-2.0; u[3] = sxs+2.0; 19552 x[4] = sys; nbd[4] = 2; l[4] = sys-2.0; u[4] = sys+2.0; 19553 19554 19555 // We start the iteration by initializing task. 19556 // (**MUST clear remaining chars in task with spaces (else crash)!**) 19557 strcpy(task,"START"); 19558 for (int i=5;i<60;i++) task[i]=' '; 19559 19560 // This is the call to the L-BFGS-B code. 19561 // (* call the L-BFGS-B routine with task='START' once before loop *) 19562 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19563 int step = 1; 19564 19565 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *) 19566 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) { 19567 19568 if (strncmp(task,"FG",2)==0) { 19569 // the minimization routine has returned to request the 19570 // function f and gradient g values at the current x 19571 19572 // Compute function value f for the sample problem. 19573 proj = new EMData(); 19574 proj2 = new EMData(); 19575 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb); 19576 proj->fft_shuffle(); 19577 proj->center_origin_fft(); 19578 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f)); 19579 proj->do_ift_inplace(); 19580 int M = proj->get_ysize()/2; 19581 proj2 = proj->window_center(M); 19582 f = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 19583 //f = -f; 19584 delete proj; 19585 delete proj2; 19586 19587 // Compute gradient g for the sample problem. 19588 float dt = 1.0e-3f; 19589 proj = new EMData(); 19590 proj2 = new EMData(); 19591 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0]+dt, "theta", (float)x[1], "psi", (float)x[2])), kb); 19592 proj->fft_shuffle(); 19593 proj->center_origin_fft(); 19594 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f)); 19595 proj->do_ift_inplace(); 19596 proj2 = proj->window_center(M); 19597 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 19598 //ft = -ft; 19599 delete proj; 19600 delete proj2; 19601 g[0] = (ft-f)/dt; 19602 19603 proj = new EMData(); 19604 proj2 = new EMData(); 19605 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1]+dt, "psi", (float)x[2])), kb); 19606 proj->fft_shuffle(); 19607 proj->center_origin_fft(); 19608 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f)); 19609 proj->do_ift_inplace(); 19610 proj2 = proj->window_center(M); 19611 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 19612 //ft = -ft; 19613 delete proj; 19614 delete proj2; 19615 g[1] = (ft-f)/dt; 19616 19617 proj = new EMData(); 19618 proj2 = new EMData(); 19619 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2]+dt)), kb); 19620 proj->fft_shuffle(); 19621 proj->center_origin_fft(); 19622 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f)); 19623 proj->do_ift_inplace(); 19624 proj2 = proj->window_center(M); 19625 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 19626 //ft = -ft; 19627 delete proj; 19628 delete proj2; 19629 g[2] = (ft-f)/dt; 19630 19631 proj = new EMData(); 19632 proj2 = new EMData(); 19633 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb); 19634 proj->fft_shuffle(); 19635 proj->center_origin_fft(); 19636 proj->process_inplace("filter.shift", Dict("x_shift", x[3]+dt, "y_shift", x[4], "z_shift", 0.0f)); 19637 proj->do_ift_inplace(); 19638 proj2 = proj->window_center(M); 19639 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 19640 //ft = -ft; 19641 delete proj; 19642 delete proj2; 19643 g[3] = (ft-f)/dt; 19644 19645 proj = new EMData(); 19646 proj2 = new EMData(); 19647 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb); 19648 proj->fft_shuffle(); 19649 proj->center_origin_fft(); 19650 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4]+dt, "z_shift", 0.0f)); 19651 proj->do_ift_inplace(); 19652 proj2 = proj->window_center(M); 19653 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 19654 //ft = -ft; 19655 delete proj; 19656 delete proj2; 19657 g[4] = (ft-f)/dt; 19658 } 19659 19660 //c go back to the minimization routine. 19661 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19662 step++; 19663 } 19664 19665 //printf("Total step is %d\n", step); 19666 vector<float> res; 19667 res.push_back(static_cast<float>(x[0])); 19668 res.push_back(static_cast<float>(x[1])); 19669 res.push_back(static_cast<float>(x[2])); 19670 res.push_back(static_cast<float>(x[3])); 19671 res.push_back(static_cast<float>(x[4])); 19672 //res.push_back(step); 19673 return res; 19674 }
EMData * Util::TwoDTestFunc | ( | int | Size, | |
float | p, | |||
float | q, | |||
float | a, | |||
float | b, | |||
int | flag = 0 , |
|||
float | alphaDeg = 0 | |||
) | [static] |
Creates a Two D Test Pattern.
[in] | Size | must be odd |
[in] | p | the x frequency |
[in] | q | the y frequency |
[in] | a | the x falloff |
b | the y falloff | |
flag | ||
[in] | alphaDeg | the projection angle |
Definition at line 241 of file util_sparx.cpp.
References C, ENTERFUNC, EXITFUNC, pi, 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.
00242 { 00243 ENTERFUNC; 00244 int Mid= (Size+1)/2; 00245 00246 if (flag==0) { // This is the real function 00247 EMData* ImBW = new EMData(); 00248 ImBW->set_size(Size,Size,1); 00249 ImBW->to_zero(); 00250 00251 float tempIm; 00252 float x,y; 00253 00254 for (int ix=(1-Mid); ix<Mid; ix++){ 00255 for (int iy=(1-Mid); iy<Mid; iy++){ 00256 x = (float)ix; 00257 y = (float)iy; 00258 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)) ); 00259 (*ImBW)(ix+Mid-1,iy+Mid-1) = tempIm * exp(.5f*p*p*a*a)* exp(.5f*q*q*b*b); 00260 } 00261 } 00262 ImBW->update(); 00263 ImBW->set_complex(false); 00264 ImBW->set_ri(true); 00265 00266 return ImBW; 00267 } 00268 else if (flag==1) { // This is the Fourier Transform 00269 EMData* ImBWFFT = new EMData(); 00270 ImBWFFT ->set_size(2*Size,Size,1); 00271 ImBWFFT ->to_zero(); 00272 00273 float r,s; 00274 00275 for (int ir=(1-Mid); ir<Mid; ir++){ 00276 for (int is=(1-Mid); is<Mid; is++){ 00277 r = (float)ir; 00278 s = (float)is; 00279 (*ImBWFFT)(2*(ir+Mid-1),is+Mid-1)= cosh(p*r*a*a) * cosh(q*s*b*b) * 00280 exp(-.5f*r*r*a*a)* exp(-.5f*s*s*b*b); 00281 } 00282 } 00283 ImBWFFT->update(); 00284 ImBWFFT->set_complex(true); 00285 ImBWFFT->set_ri(true); 00286 ImBWFFT->set_shuffled(true); 00287 ImBWFFT->set_fftodd(true); 00288 00289 return ImBWFFT; 00290 } 00291 else if (flag==2 || flag==3) { // This is the projection in Real Space 00292 float alpha = static_cast<float>( alphaDeg*M_PI/180.0 ); 00293 float C=cos(alpha); 00294 float S=sin(alpha); 00295 float D= sqrt(S*S*b*b + C*C*a*a); 00296 //float D2 = D*D; PAP - to get rid of warning 00297 00298 float P = p * C *a*a/D ; 00299 float Q = q * S *b*b/D ; 00300 00301 if (flag==2) { 00302 EMData* pofalpha = new EMData(); 00303 pofalpha ->set_size(Size,1,1); 00304 pofalpha ->to_zero(); 00305 00306 float Norm0 = D*(float)sqrt(2*pi); 00307 float Norm1 = exp( .5f*(P+Q)*(P+Q)) / Norm0 ; 00308 float Norm2 = exp( .5f*(P-Q)*(P-Q)) / Norm0 ; 00309 float sD; 00310 00311 for (int is=(1-Mid); is<Mid; is++){ 00312 sD = is/D ; 00313 (*pofalpha)(is+Mid-1) = Norm1 * exp(-.5f*sD*sD)*cos(sD*(P+Q)) 00314 + Norm2 * exp(-.5f*sD*sD)*cos(sD*(P-Q)); 00315 } 00316 pofalpha-> update(); 00317 pofalpha-> set_complex(false); 00318 pofalpha-> set_ri(true); 00319 00320 return pofalpha; 00321 } 00322 if (flag==3) { // This is the projection in Fourier Space 00323 float vD; 00324 00325 EMData* pofalphak = new EMData(); 00326 pofalphak ->set_size(2*Size,1,1); 00327 pofalphak ->to_zero(); 00328 00329 for (int iv=(1-Mid); iv<Mid; iv++){ 00330 vD = iv*D ; 00331 (*pofalphak)(2*(iv+Mid-1)) = exp(-.5f*vD*vD)*(cosh(vD*(P+Q)) + cosh(vD*(P-Q)) ); 00332 } 00333 pofalphak-> update(); 00334 pofalphak-> set_complex(false); 00335 pofalphak-> set_ri(true); 00336 00337 return pofalphak; 00338 } 00339 } 00340 else if (flag==4) { 00341 cout <<" FH under construction"; 00342 EMData* OutFT= TwoDTestFunc(Size, p, q, a, b, 1); 00343 EMData* TryFH= OutFT -> real2FH(4.0); 00344 return TryFH; 00345 } else { 00346 cout <<" flag must be 0,1,2,3, or 4"; 00347 } 00348 00349 EXITFUNC; 00350 return 0; 00351 }
void Util::update_fav | ( | EMData * | ave, | |
EMData * | dat, | |||
float | tot, | |||
int | mirror, | |||
vector< int > | numr | |||
) | [static] |
Definition at line 4375 of file util_sparx.cpp.
References EXITFUNC, EMAN::EMData::get_data(), numr, PI2, and EMAN::EMData::update().
04375 { 04376 int nring = numr.size()/3; 04377 float *ave = avep->get_data(); 04378 float *dat = datp->get_data(); 04379 int i, j, numr3i, np; 04380 float arg, cs, si; 04381 int maxrin = numr(3,nring); 04382 if(mirror == 1) { //for mirrored data has to be conjugated 04383 for (i=1; i<=nring; i++) { 04384 numr3i = numr(3,i); 04385 np = numr(2,i)-1; 04386 ave[np] += dat[np]; 04387 ave[np+1] += static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) ); 04388 for (j=2; j<numr3i; j=j+2) { 04389 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin ); 04390 cs = cos(arg); 04391 si = sin(arg); 04392 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg)) 04393 ave[np + j] += dat[np + j]*cs - dat[np + j +1]*si; 04394 ave[np + j +1] -= dat[np + j]*si + dat[np + j +1]*cs; 04395 } 04396 } 04397 } else { 04398 for (i=1; i<=nring; i++) { 04399 numr3i = numr(3,i); 04400 np = numr(2,i)-1; 04401 ave[np] += dat[np]; 04402 ave[np+1] += static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) ); 04403 for (j=2; j<numr3i; j=j+2) { 04404 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin ); 04405 cs = cos(arg); 04406 si = sin(arg); 04407 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg)) 04408 ave[np + j] += dat[np + j]*cs - dat[np + j +1]*si; 04409 ave[np + j +1] += dat[np + j]*si + dat[np + j +1]*cs; 04410 } 04411 } 04412 } 04413 avep->update(); 04414 EXITFUNC; 04415 }
static double EMAN::Util::var | ( | double * | x, | |
int | n | |||
) | [inline, static] |
Definition at line 1117 of file util.h.
Referenced by multi_align_error_func2().
01126 : set ts=4 noet nospell: */
vector< float > Util::vareas | ( | EMData * | d | ) | [static] |
Definition at line 20766 of file util_sparx.cpp.
References data, dm, EMAN::EMData::get_ysize(), and ny.
20766 { 20767 const float step=0.001f; 20768 int ny = d->get_ysize(); 20769 // input emdata should have size 2xN, where N is number of points 20770 // output vector should be 2xN, first element is the number of elements 20771 // associated with this point, second is 0 is the element is touching the border, 1 if it is interior 20772 vector<float> group(2*ny); 20773 for(int i=0; i<2*ny; i++) group[i] = 0.0f; 20774 int K = int(1.0f/step) +1; 20775 int hit = 0; 20776 for(int kx=0; kx<=K; kx++) { 20777 float tx = kx*step; 20778 for(int ky=0; ky<=K; ky++) { 20779 float ty = ky*step; 20780 float dm = 1.0e23f; 20781 for(int i=0; i<ny; i++) { 20782 float qd = pow(tx-(*d)(0,i),2) + pow(ty-(*d)(1,i),2); 20783 if( qd < dm) { 20784 dm = qd; 20785 hit = i; 20786 } 20787 } 20788 data(0,hit) += 1.0f; 20789 if(kx == 0 || ky == 0 || kx == K || ky == K) data(1,hit) = 1.0f; 20790 } 20791 } 20792 return group; 20793 }
void Util::voronoi | ( | double * | phi, | |
double * | theta, | |||
double * | weight, | |||
int | nt | |||
) | [static] |
Definition at line 7505 of file util_sparx.cpp.
References ang_to_xyz(), areav_(), Assert, disorder2(), ENTERFUNC, EXITFUNC, flip23(), key, status, trmsh3_(), and y.
07506 { 07507 07508 ENTERFUNC; 07509 07510 int *list, *lptr, *lend, *iwk, *key,*lcnt,*indx,*good; 07511 int nt6, n, ier, nout, lnew, mdup, nd; 07512 int i,k,mt,status; 07513 07514 07515 double *ds, *x, *y, *z; 07516 double tol = 1.0e-8; 07517 double dtol = 15; 07518 double a; 07519 07520 /*if(last){ 07521 if(medium>nt) n = nt+nt; 07522 else n = nt+nt-medium+1; 07523 } 07524 else{ 07525 n=nt; 07526 }*/ 07527 07528 n = nt + nt; 07529 07530 nt6 = n*6; 07531 07532 list = (int*)calloc(nt6,sizeof(int)); 07533 lptr = (int*)calloc(nt6,sizeof(int)); 07534 lend = (int*)calloc(n ,sizeof(int)); 07535 iwk = (int*)calloc(n ,sizeof(int)); 07536 good = (int*)calloc(n ,sizeof(int)); 07537 key = (int*)calloc(n ,sizeof(int)); 07538 indx = (int*)calloc(n ,sizeof(int)); 07539 lcnt = (int*)calloc(n ,sizeof(int)); 07540 07541 ds = (double*) calloc(n,sizeof(double)); 07542 x = (double*) calloc(n,sizeof(double)); 07543 y = (double*) calloc(n,sizeof(double)); 07544 z = (double*) calloc(n,sizeof(double)); 07545 07546 if (list == NULL || 07547 lptr == NULL || 07548 lend == NULL || 07549 iwk == NULL || 07550 good == NULL || 07551 key == NULL || 07552 indx == NULL || 07553 lcnt == NULL || 07554 x == NULL || 07555 y == NULL || 07556 z == NULL || 07557 ds == NULL) { 07558 printf("memory allocation failure!\n"); 07559 exit(1); 07560 } 07561 07562 bool colinear=true; 07563 while(colinear) 07564 { 07565 07566 L1: 07567 for(i = 0; i<nt; i++){ 07568 x[i] = theta[i]; 07569 y[i] = phi[i]; 07570 x[nt+i] = 180.0 - x[i]; 07571 y[nt+i] = 180.0 + y[i]; 07572 } 07573 07574 Util::disorder2(x, y, key, n); 07575 07576 // check if the first three angles are not close, else shuffle 07577 double val; 07578 for(k=0; k<2; k++){ 07579 for(i=k+1; i<3; i++){ 07580 val = (x[i]-x[k])*(x[i]-x[k]) + (y[i]-y[k])*(y[i]-y[k]); 07581 if( val < dtol) { 07582 goto L1; 07583 } 07584 } 07585 } 07586 07587 Util::ang_to_xyz(x, y, z, n); 07588 07589 // Make sure that first three has no duplication 07590 bool dupnode=true; 07591 dupnode=true; 07592 while(dupnode) 07593 { 07594 for(k=0; k<2; k++){ 07595 for(i=k+1; i<3; i++){ 07596 if( x[i]*x[k]+y[i]*y[k]+z[i]*z[k] > 1.0-tol) { 07597 Util::flip23(x, y, z, key, k, n); 07598 continue; 07599 } 07600 } 07601 } 07602 dupnode = false; 07603 } 07604 07605 07606 ier = 0; 07607 07608 status = Util::trmsh3_(&n,&tol,x,y,z,&nout,list,lptr,lend,&lnew, indx, lcnt, iwk, good, ds, &ier); 07609 07610 if (status != 0) { 07611 printf(" error in trmsh3 \n"); 07612 exit(1); 07613 } 07614 07615 if (ier > 0) { 07616 printf("*** Error in TRMESH: duplicate nodes encountered ***\n"); 07617 exit(1); 07618 } 07619 07620 mdup=n-nout; 07621 if (ier == -2) { 07622 //printf("in TRMESH:the first three nodes are colinear*** disorder again\n"); 07623 } 07624 else 07625 { 07626 colinear=false; 07627 } 07628 } 07629 07630 07631 Assert( ier != -2 ); 07632 // Create a list of unique nodes GOOD, the numbers refer to locations on the full list 07633 // INDX contains node numbers from the squeezed list 07634 nd=0; 07635 for (k=1; k<=n; k++){ 07636 if (indx[k-1]>0) { 07637 nd++; 07638 good[nd-1]=k; 07639 } 07640 } 07641 07642 // 07643 // *** Compute the Voronoi region areas. 07644 // 07645 for(i = 1; i<=nout; i++) { 07646 k=good[i-1]; 07647 // We only need n weights from hemisphere 07648 if (key[k-1] <= nt) { 07649 // CALCULATE THE AREA 07650 a = Util::areav_(&i, &nout, x, y, z, list, lptr, lend, &ier); 07651 if (ier != 0){ 07652 // We set the weight to -1, this will signal the error in the calling 07653 // program, as the area will turn out incorrect 07654 printf(" *** error in areav: ier = %d ***\n", ier); 07655 weight[key[k-1]-1] =-1.0; 07656 } else { 07657 // Assign the weight 07658 weight[key[k-1]-1]=a/lcnt[i-1]; 07659 } 07660 } 07661 } 07662 07663 07664 // Fill out the duplicated weights 07665 for(i = 1; i<=n; i++){ 07666 mt =- indx[i-1]; 07667 if (mt>0){ 07668 k = good[mt-1]; 07669 // This is a duplicated entry, get the already calculated 07670 // weight and assign it. 07671 // We only need n weights from hemisphere 07672 if (key[i-1] <= nt && key[k-1] <= nt) { weight[key[i-1]-1] = weight[key[k-1]-1];} 07673 } 07674 } 07675 07676 free(list); 07677 free(lend); 07678 free(iwk); 07679 free(good); 07680 free(key); 07681 free(lptr); 07682 free(indx); 07683 free(lcnt); 07684 free(ds); 07685 free(x); 07686 free(y); 07687 free(z); 07688 07689 07690 EXITFUNC; 07691 }
static void EMAN::Util::voronoidiag | ( | double * | theta, | |
double * | phi, | |||
double * | weight, | |||
int | n | |||
) | [static] |
vector< double > Util::vrdg | ( | const vector< float > & | ph, | |
const vector< float > & | th | |||
) | [static] |
Definition at line 7082 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, hsortd(), ImageFormatException, key, LOGERR, phi, theta, voronoi(), and weight.
07083 { 07084 07085 ENTERFUNC; 07086 07087 if ( th.size() != ph.size() ) { 07088 LOGERR("images not same size"); 07089 throw ImageFormatException( "images not same size"); 07090 } 07091 07092 // rand_seed 07093 srand(10); 07094 07095 int i,*key; 07096 int len = th.size(); 07097 double *theta,*phi,*weight; 07098 theta = (double*) calloc(len,sizeof(double)); 07099 phi = (double*) calloc(len,sizeof(double)); 07100 weight = (double*) calloc(len,sizeof(double)); 07101 key = (int*) calloc(len,sizeof(int)); 07102 const float *thptr, *phptr; 07103 07104 thptr = &th[0]; 07105 phptr = &ph[0]; 07106 for(i=1;i<=len;i++){ 07107 key(i) = i; 07108 weight(i) = 0.0; 07109 } 07110 07111 for(i = 0;i<len;i++){ 07112 theta[i] = thptr[i]; 07113 phi[i] = phptr[i]; 07114 } 07115 07116 // sort by theta 07117 Util::hsortd(theta, phi, key, len, 1); 07118 07119 //Util::voronoidiag(theta,phi, weight, len); 07120 Util::voronoi(phi, theta, weight, len); 07121 07122 //sort by key 07123 Util::hsortd(weight, weight, key, len, 2); 07124 07125 free(theta); 07126 free(phi); 07127 free(key); 07128 vector<double> wt; 07129 double count = 0; 07130 for(i=1; i<= len; i++) 07131 { 07132 wt.push_back(weight(i)); 07133 count += weight(i); 07134 } 07135 07136 //if( abs(count-6.28) > 0.1 ) 07137 //{ 07138 // printf("Warning: SUM OF VORONOI CELLS AREAS IS %lf, should 2*PI\n", count); 07139 //} 07140 07141 free(weight); 07142 07143 EXITFUNC; 07144 return wt; 07145 07146 }
EMData * Util::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 | |||
) | [static] |
Definition at line 5177 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().
05178 { 05179 /* Exception Handle */ 05180 if (!img) throw NullPointerException("NULL input image"); 05181 /* ============================== */ 05182 05183 // Get the size of the input image 05184 int nx=img->get_xsize(), ny=img->get_ysize(), nz=img->get_zsize(); 05185 /* ============================== */ 05186 05187 /* Exception Handle */ 05188 if(new_nx>nx || new_ny>ny || new_nz>nz) 05189 throw ImageDimensionException("The size of the windowed image cannot exceed the input image size. 1"); 05190 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) 05191 throw ImageDimensionException("The offset inconsistent with the input image size. 2"); 05192 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)))) 05193 throw ImageDimensionException("The offset inconsistent with the input image size. 3"); 05194 /* ============================== */ 05195 05196 /* Calculation of the start point */ 05197 int new_st_x = nx/2-new_nx/2 + x_offset, 05198 new_st_y = ny/2-new_ny/2 + y_offset, 05199 new_st_z = nz/2-new_nz/2 + z_offset; 05200 /* ============================== */ 05201 05202 /* Exception Handle */ 05203 if (new_st_x<0 || new_st_y<0 || new_st_z<0) // WHAT HAPPENS WITH THE END POINT CHECK?? PAP 05204 throw ImageDimensionException("The offset inconsistent with the input image size. 4"); 05205 /* ============================== */ 05206 05207 EMData* wind = img->copy_empty_head(); 05208 wind->set_size(new_nx, new_ny, new_nz); 05209 float *outp=wind->get_data(); 05210 float *inp=img->get_data(); 05211 05212 for (int k=0; k<new_nz; k++) 05213 for(int j=0; j<new_ny; j++) 05214 for(int i=0; i<new_nx; i++) 05215 outp(i,j,k) = inp(i,j,k); 05216 wind->update(); 05217 return wind; 05218 }
void Util::WTF | ( | EMData * | PROJ, | |
vector< float > | SS, | |||
float | SNR, | |||
int | K | |||
) | [static] |
Definition at line 5706 of file util_sparx.cpp.
References EMAN::EMData::get_data(), PROJ, q, SS, EMAN::EMData::update(), W, and Y.
05707 { 05708 05709 --K; // now indexes are started from 0 05710 05711 int NSAM = PROJ->get_xsize(); 05712 int NROW = PROJ->get_ysize(); 05713 05714 if (PROJ->is_fftpadded()) { 05715 NSAM -= (PROJ->is_fftodd()) ? (1) : (2); // correction for DFT image 05716 } 05717 05718 const int ntotal = NSAM*NROW; 05719 const float q = 2.0f; 05720 const float qt = 8.0f/q; 05721 // Fix for padding 2x 05722 const int ipad = 1; 05723 NSAM *= ipad; 05724 NROW *= ipad; 05725 const int NNNN = NSAM+2-(NSAM%2); 05726 const int NX2 = NSAM/2; 05727 const int NR2 = NROW/2; 05728 05729 const int NANG = int(SS.size())/6; 05730 05731 EMData* W = new EMData(); 05732 const int Wnx = NNNN/2; 05733 W->set_size(Wnx,NROW,1); 05734 W->to_zero(); 05735 float *Wptr = W->get_data(); 05736 05737 for (int L=0; L<NANG; L++) { 05738 const float tmp1 = SS(2,K)*SS(3,L)*(SS(0,K)*SS(0,L) + SS(1,K)*SS(1,L)) - SS(2,L)*SS(3,K); 05739 const float tmp2 = SS(3,L)*( SS(0,K)*SS(1,L) - SS(0,L)*SS(1,K) ); 05740 float OX = SS(5,K)*tmp2 + SS(4,K)*tmp1; 05741 float OY = SS(4,K)*tmp2 - SS(5,K)*tmp1; 05742 if(OX < 0.0f) { 05743 OX = -OX; 05744 OY = -OY; 05745 } 05746 05747 if( OX > 1.0e-6f || fabs(OY) > 1.0e-6f ) { 05748 for (int J=0; J<NROW; ++J) { 05749 const float JY_OY = (J > NR2) ? ((J-NROW)*OY) : (J*OY); 05750 int xma = NX2; 05751 int xmi = 0; 05752 const float fxma = ( q-JY_OY) / OX; 05753 const float fxmi = (-q-JY_OY) / OX; 05754 if (fxma < xmi || fxmi > xma ) { 05755 continue; 05756 } 05757 if (fxma < xma) { 05758 xma = static_cast<int>(fxma+0.5f); 05759 } 05760 if (fxmi > xmi) { 05761 xmi = static_cast<int>(fxmi+0.5f); 05762 } 05763 for( int I=xmi; I<=xma; ++I ) { 05764 const float Y = I*OX + JY_OY; 05765 W(I,J) += exp(-qt*Y*Y); 05766 } 05767 } 05768 } else { 05769 for (int J=0; J<NROW; ++J) { 05770 for (int I=0; I<NNNN/2; ++I) { 05771 W(I,J) += 1.0f; 05772 } 05773 } 05774 } 05775 } 05776 05777 EMData* proj_in = PROJ; 05778 05779 const bool realOnInput = PROJ->is_real(); 05780 if (realOnInput) { 05781 // copy input image and run DFT on it 05782 PROJ = PROJ->norm_pad( false, ipad); 05783 PROJ->do_fft_inplace(); 05784 PROJ->update(); 05785 } 05786 float * PROJptr = PROJ->get_data(); 05787 05788 const float osnr = 1.0f/SNR; 05789 const float WNRMinv = 1.0f/W(0,0); 05790 for (int J=0; J<NROW; ++J) { 05791 float sy = (J > NR2) ? (J - NROW) : (J); 05792 sy /= NROW; 05793 sy *= sy; 05794 for (int I=0; I<NNNN; I+=2) { 05795 const int KX = I/2; 05796 const float temp = W(KX,J)*WNRMinv; 05797 float WW = temp/(temp*temp + osnr); 05798 // This is supposed to fix fall-off due to Gaussian function in the weighting function 05799 const float sx = float(KX) / NSAM; 05800 WW *= exp(qt*(sy + sx*sx)); 05801 PROJ(I,J) *= WW; 05802 PROJ(I+1,J) *= WW; 05803 } 05804 } 05805 delete W; W = 0; 05806 05807 PROJ->do_ift_inplace(); 05808 PROJ->depad(); 05809 05810 if (realOnInput) { 05811 // copy data back to input image 05812 float* data_src = PROJ->get_data(); 05813 float* data_dst = proj_in->get_data(); 05814 memcpy( data_dst, data_src, ntotal * sizeof(float) ); 05815 delete PROJ; 05816 } 05817 05818 proj_in->update(); 05819 }
void Util::WTM | ( | EMData * | PROJ, | |
vector< float > | SS, | |||
int | DIAMETER, | |||
int | NUMP | |||
) | [static] |
Definition at line 5913 of file util_sparx.cpp.
References AMAX1, AMIN1, CC, CP, EMAN::EMData::get_data(), PROJ, RI, sqrt(), SS, EMAN::EMData::update(), VP, VV, and W.
05914 { 05915 float rad2deg =(180.0f/3.1415926f); 05916 float deg2rad = (3.1415926f/180.0f); 05917 05918 int NSAM,NROW,NNNN,NR2,NANG,L,JY; 05919 05920 NSAM = PROJ->get_xsize(); 05921 NROW = PROJ->get_ysize(); 05922 05923 if (PROJ->is_fftpadded()) { 05924 NSAM -= (PROJ->is_fftodd()) ? (1) : (2); // correction for DFT image 05925 } 05926 05927 NNNN = NSAM+2-(NSAM%2); 05928 NR2 = NROW/2; 05929 NANG = int(SS.size())/6; 05930 05931 float RI[9]; 05932 RI(1,1)=SS(1,NUMP)*SS(3,NUMP)*SS(5,NUMP)-SS(2,NUMP)*SS(6,NUMP); 05933 RI(2,1)=-SS(1,NUMP)*SS(3,NUMP)*SS(6,NUMP)-SS(2,NUMP)*SS(5,NUMP); 05934 RI(3,1)=SS(1,NUMP)*SS(4,NUMP); 05935 RI(1,2)=SS(2,NUMP)*SS(3,NUMP)*SS(5,NUMP)+SS(1,NUMP)*SS(6,NUMP); 05936 RI(2,2)=-SS(2,NUMP)*SS(3,NUMP)*SS(6,NUMP)+SS(1,NUMP)*SS(5,NUMP); 05937 RI(3,2)=SS(2,NUMP)*SS(4,NUMP); 05938 RI(1,3)=-SS(4,NUMP)*SS(5,NUMP); 05939 RI(2,3)=SS(4,NUMP)*SS(6,NUMP); 05940 RI(3,3)=SS(3,NUMP); 05941 05942 float THICK=static_cast<float>( NSAM)/DIAMETER/2.0f ; 05943 05944 EMData* W = new EMData(); 05945 int Wnx = NNNN/2; 05946 W->set_size(NNNN/2,NROW,1); 05947 W->to_one(); 05948 float *Wptr = W->get_data(); 05949 05950 float ALPHA,TMP,FV,RT,FM,CCN,CC[3],CP[2],VP[2],VV[3]; 05951 05952 for (L=1; L<=NANG; L++) { 05953 if (L != NUMP) { 05954 CC(1)=SS(2,L)*SS(4,L)*SS(3,NUMP)-SS(3,L)*SS(2,NUMP)*SS(4,NUMP); 05955 CC(2)=SS(3,L)*SS(1,NUMP)*SS(4,NUMP)-SS(1,L)*SS(4,L)*SS(3,NUMP); 05956 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); 05957 05958 TMP = sqrt(CC(1)*CC(1) + CC(2)*CC(2) + CC(3)*CC(3)); 05959 CCN=static_cast<float>( AMAX1( AMIN1(TMP,1.0) ,-1.0) ); 05960 ALPHA=rad2deg*float(asin(CCN)); 05961 if (ALPHA>180.0f) ALPHA=ALPHA-180.0f; 05962 if (ALPHA>90.0f) ALPHA=180.0f-ALPHA; 05963 if(ALPHA<1.0E-6) { 05964 for(int J=1;J<=NROW;J++) for(int I=1;I<=NNNN/2;I++) W(I,J)+=1.0; 05965 } else { 05966 FM=THICK/(fabs(sin(ALPHA*deg2rad))); 05967 CC(1) = CC(1)/CCN;CC(2) = CC(2)/CCN;CC(3) = CC(3)/CCN; 05968 VV(1)= SS(2,L)*SS(4,L)*CC(3)-SS(3,L)*CC(2); 05969 VV(2)= SS(3,L)*CC(1)-SS(1,L)*SS(4,L)*CC(3); 05970 VV(3)= SS(1,L)*SS(4,L)*CC(2)-SS(2,L)*SS(4,L)*CC(1); 05971 CP(1) = 0.0;CP(2) = 0.0; 05972 VP(1) = 0.0;VP(2) = 0.0; 05973 05974 CP(1) = CP(1) + RI(1,1)*CC(1) + RI(1,2)*CC(2) + RI(1,3)*CC(3); 05975 CP(2) = CP(2) + RI(2,1)*CC(1) + RI(2,2)*CC(2) + RI(2,3)*CC(3); 05976 VP(1) = VP(1) + RI(1,1)*VV(1) + RI(1,2)*VV(2) + RI(1,3)*VV(3); 05977 VP(2) = VP(2) + RI(2,1)*VV(1) + RI(2,2)*VV(2) + RI(2,3)*VV(3); 05978 05979 TMP = CP(1)*VP(2)-CP(2)*VP(1); 05980 05981 // PREVENT TMP TO BE TOO SMALL, SIGN IS IRRELEVANT 05982 TMP = AMAX1(1.0E-4f,fabs(TMP)); 05983 float tmpinv = 1.0f/TMP; 05984 for(int J=1;J<=NROW;J++) { 05985 JY = (J-1); 05986 if (JY>NR2) JY=JY-NROW; 05987 for(int I=1;I<=NNNN/2;I++) { 05988 FV = fabs((JY*CP(1)-(I-1)*CP(2))*tmpinv); 05989 RT = 1.0f-FV/FM; 05990 W(I,J) += ((RT>0.0f)*RT); 05991 } 05992 } 05993 } 05994 } 05995 } 05996 05997 EMData* proj_in = PROJ; 05998 const bool realOnInput = PROJ->is_real(); 05999 06000 if (realOnInput) { 06001 // copy input image and run DFT on it 06002 PROJ = PROJ->norm_pad( false, 1 ); 06003 PROJ->do_fft_inplace(); 06004 PROJ->update(); 06005 } 06006 float *PROJptr = PROJ->get_data(); 06007 06008 int KX; 06009 float WW; 06010 for(int J=1; J<=NROW; J++) 06011 for(int I=1; I<=NNNN; I+=2) { 06012 KX = (I+1)/2; 06013 WW = 1.0f/W(KX,J); 06014 PROJ(I,J) = PROJ(I,J)*WW; 06015 PROJ(I+1,J) = PROJ(I+1,J)*WW; 06016 } 06017 delete W; W = 0; 06018 PROJ->do_ift_inplace(); 06019 PROJ->depad(); 06020 06021 if (realOnInput) { 06022 // copy data back to input image 06023 float* data_src = PROJ->get_data(); 06024 float* data_dst = proj_in->get_data(); 06025 int ntotal = NSAM*NROW; 06026 memcpy( data_dst, data_src, ntotal * sizeof(float) ); 06027 delete PROJ; 06028 } 06029 06030 proj_in->update(); 06031 }