#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_psi_0_180_no_mirror (EMData *circ1, EMData *circ2, vector< int > numr, float psi_max) |
checks both straight & mirrored positions Find only positions within +/-pis_max of 0 and 180 (for helcal use) input - fourier transforms of rings! circ1 already multiplied by weights! | |
static Dict | Crosrng_ns (EMData *circ1, EMData *circ2, vector< int > numr) |
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 (const vector< float > &d, 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 > | 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, bool mirror_only=false, float yrnglocal=-1.0, bool CONS=false) |
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) |
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 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 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 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 81 of file util.h.
Definition at line 17640 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().
17641 { 17642 ENTERFUNC; 17643 /* Exception Handle */ 17644 if (!img || !img1) { 17645 throw NullPointerException("NULL input image"); 17646 } 17647 /* ========= img += img1 ===================== */ 17648 17649 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17650 size_t size = (size_t)nx*ny*nz; 17651 float *img_ptr = img->get_data(); 17652 float *img1_ptr = img1->get_data(); 17653 for (size_t i=0;i<size;++i) img_ptr[i] += img1_ptr[i]; 17654 img->update(); 17655 17656 EXITFUNC; 17657 }
Definition at line 17678 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().
17679 { 17680 ENTERFUNC; 17681 /* Exception Handle */ 17682 if (!img) { 17683 throw NullPointerException("NULL input image"); 17684 } 17685 /* ========= img += img1**2 ===================== */ 17686 17687 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17688 size_t size = (size_t)nx*ny*nz; 17689 float *img_ptr = img->get_data(); 17690 float *img1_ptr = img1->get_data(); 17691 if(img->is_complex()) { 17692 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] ; 17693 } else { 17694 for (size_t i=0;i<size;++i) img_ptr[i] += img1_ptr[i]*img1_ptr[i]; 17695 } 17696 img->update(); 17697 17698 EXITFUNC; 17699 }
Definition at line 17659 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().
17660 { 17661 ENTERFUNC; 17662 /* Exception Handle */ 17663 if (!img) { 17664 throw NullPointerException("NULL input image"); 17665 } 17666 /* ========= img += img1 ===================== */ 17667 17668 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17669 size_t size = (size_t)nx*ny*nz; 17670 float *img_ptr = img->get_data(); 17671 float *img1_ptr = img1->get_data(); 17672 for (size_t i=0;i<size;++i) img_ptr[i] += abs(img1_ptr[i]); 17673 img->update(); 17674 17675 EXITFUNC; 17676 }
Definition at line 17457 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().
17458 { 17459 ENTERFUNC; 17460 /* Exception Handle */ 17461 if (!img) { 17462 throw NullPointerException("NULL input image"); 17463 } 17464 /* ============== output = img + img1 ================ */ 17465 17466 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17467 size_t size = (size_t)nx*ny*nz; 17468 EMData * img2 = img->copy_head(); 17469 float *img_ptr =img->get_data(); 17470 float *img2_ptr = img2->get_data(); 17471 float *img1_ptr = img1->get_data(); 17472 for (size_t i=0;i<size;++i) img2_ptr[i] = img_ptr[i] + img1_ptr[i]; 17473 img2->update(); 17474 if(img->is_complex()) { 17475 img2->set_complex(true); 17476 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17477 } 17478 17479 EXITFUNC; 17480 return img2; 17481 }
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 1771 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 19443 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.
19445 { 19446 19447 int maxrin = numr[numr.size()-1]; 19448 19449 int ky = int(2*yrng/step+0.5)/2; 19450 int kx = int(2*xrng/step+0.5)/2; 19451 19452 float *p_ccf1ds = (float *)malloc(maxrin*sizeof(float)); 19453 float *p_ccf1dm = (float *)malloc(maxrin*sizeof(float)); 19454 int vol = maxrin*(2*kx+1)*(2*ky+1); 19455 vector<ccf_point> ccf(2*vol); 19456 ccf_point temp; 19457 19458 int index = 0; 19459 for (int i = -ky; i <= ky; i++) { 19460 float iy = i * step; 19461 for (int j = -kx; j <= kx; j++) { 19462 float ix = j*step; 19463 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 19464 Frngs(cimage, numr); 19465 Crosrng_msg_vec(crefim, cimage, numr, p_ccf1ds, p_ccf1dm); 19466 for (int k=0; k<maxrin; k++) { 19467 temp.value = p_ccf1ds[k]; 19468 temp.i = k; 19469 temp.j = j; 19470 temp.k = i; 19471 temp.mirror = 0; 19472 ccf[index] = temp; 19473 index++; 19474 temp.value = p_ccf1dm[k]; 19475 temp.mirror = 1; 19476 ccf[index] = temp; 19477 index++; 19478 } 19479 delete cimage; cimage = 0; 19480 } 19481 } 19482 19483 delete p_ccf1ds; 19484 delete p_ccf1dm; 19485 std::sort(ccf.begin(), ccf.end(), ccf_value()); 19486 19487 double qt = (double)ccf[0].value; 19488 vector <double> p(2*vol), cp(2*vol); 19489 19490 double sump = 0.0; 19491 for (int i=0; i<2*vol; i++) { 19492 p[i] = pow(double(ccf[i].value)/qt, 1.0/T); 19493 sump += p[i]; 19494 } 19495 for (int i=0; i<2*vol; i++) { 19496 p[i] /= sump; 19497 } 19498 for (int i=1; i<2*vol; i++) { 19499 p[i] += p[i-1]; 19500 } 19501 p[2*vol-1] = 2.0; 19502 19503 float t = get_frand(0.0f, 1.0f); 19504 int select = 0; 19505 while (p[select] < t) select += 1; 19506 19507 vector<float> a(6); 19508 a[0] = ccf[select].value; 19509 a[1] = (float)ccf[select].i; 19510 a[2] = (float)ccf[select].j; 19511 a[3] = (float)ccf[select].k; 19512 a[4] = (float)ccf[select].mirror; 19513 a[5] = (float)select; 19514 return a; 19515 }
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] |
float Util::ang_n | ( | float | peakp, | |
string | mode, | |||
int | maxrin | |||
) | [static, private] |
Definition at line 17887 of file util_sparx.cpp.
Referenced by multiref_polar_ali_2d(), multiref_polar_ali_2d_delta(), multiref_polar_ali_2d_local(), multiref_polar_ali_2d_local_psi(), multiref_polar_ali_2d_nom(), multiref_polar_ali_2d_peaklist(), multiref_polar_ali_helical(), multiref_polar_ali_helical_90(), multiref_polar_ali_helical_90_local(), and multiref_polar_ali_helical_local().
17888 { 17889 if (mode == "f" || mode == "F") 17890 return fmodf(((peakp-1.0f) / maxrin+1.0f)*360.0f,360.0f); 17891 else 17892 return fmodf(((peakp-1.0f) / maxrin+1.0f)*180.0f,180.0f); 17893 }
void Util::ang_to_xyz | ( | double * | x, | |
double * | y, | |||
double * | z, | |||
int | len | |||
) | [static] |
Definition at line 7855 of file util_sparx.cpp.
References dgr_to_rad, ENTERFUNC, and EXITFUNC.
07856 { 07857 ENTERFUNC; 07858 double costheta,sintheta,cosphi,sinphi; 07859 for(int i = 0; i<len; i++) 07860 { 07861 cosphi = cos(y[i]*dgr_to_rad); 07862 sinphi = sin(y[i]*dgr_to_rad); 07863 if(fabs(x[i]-90.0)< 1.0e-5){ 07864 x[i] = cosphi; 07865 y[i] = sinphi; 07866 z[i] = 0.0; 07867 } 07868 else{ 07869 costheta = cos(x[i]*dgr_to_rad); 07870 sintheta = sin(x[i]*dgr_to_rad); 07871 x[i] = cosphi*sintheta; 07872 y[i] = sinphi*sintheta; 07873 z[i] = costheta; 07874 } 07875 } 07876 EXITFUNC; 07877 }
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 1941 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 1909 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 67 of file util.cpp.
References Assert, and NullPointerException.
00068 { 00069 Assert(n > 0); 00070 00071 if (!data) { 00072 throw NullPointerException("pixel data array"); 00073 } 00074 00075 for (size_t i = 0; i < n; i += 2) { 00076 float f = data[i] * sin(data[i + 1]); 00077 data[i] = data[i] * cos(data[i + 1]); 00078 data[i + 1] = f; 00079 } 00080 }
static void EMAN::Util::apply_precision | ( | float & | value, | |
const float & | precision | |||
) | [inline, static] |
Definition at line 2153 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) { 03144 circ[numr2i+1] *= w; 03145 } else { 03146 circ[numr2i+1] *= 0.5*w; 03147 } 03148 for (int j = 2+numr2i; j < numr3i+numr2i; ++j) { 03149 circ[j] *= w; 03150 } 03151 } 03152 }
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 8913 of file util_sparx.cpp.
References areas_(), circum_(), FALSE_, ierr, and TRUE_.
Referenced by voronoi().
08916 { 08917 /* Initialized data */ 08918 08919 static double amax = 6.28; 08920 08921 /* System generated locals */ 08922 double ret_val; 08923 08924 /* Local variables */ 08925 static double a, c0[3], c2[3], c3[3]; 08926 static int n1, n2, n3; 08927 static double v1[3], v2[3], v3[3]; 08928 static int lp, lpl, ierr; 08929 static double asum; 08930 static long int first; 08931 08932 08933 /* *********************************************************** */ 08934 08935 /* Robert J. Renka */ 08936 /* Dept. of Computer Science */ 08937 /* Univ. of North Texas */ 08938 /* renka@cs.unt.edu */ 08939 /* 10/25/02 */ 08940 08941 /* Given a Delaunay triangulation and the index K of an */ 08942 /* interior node, this subroutine returns the (surface) area */ 08943 /* of the Voronoi region associated with node K. The Voronoi */ 08944 /* region is the polygon whose vertices are the circumcenters */ 08945 /* of the triangles that contain node K, where a triangle */ 08946 /* circumcenter is the point (unit vector) lying at the same */ 08947 /* angular distance from the three vertices and contained in */ 08948 /* the same hemisphere as the vertices. */ 08949 08950 08951 /* On input: */ 08952 08953 /* K = Nodal index in the range 1 to N. */ 08954 08955 /* N = Number of nodes in the triangulation. N > 3. */ 08956 08957 /* X,Y,Z = Arrays of length N containing the Cartesian */ 08958 /* coordinates of the nodes (unit vectors). */ 08959 08960 /* LIST,LPTR,LEND = Data structure defining the trian- */ 08961 /* gulation. Refer to Subroutine */ 08962 /* TRMESH. */ 08963 08964 /* Input parameters are not altered by this function. */ 08965 08966 /* On output: */ 08967 08968 /* AREAV = Area of Voronoi region K unless IER > 0, */ 08969 /* in which case AREAV = 0. */ 08970 08971 /* IER = Error indicator: */ 08972 /* IER = 0 if no errors were encountered. */ 08973 /* IER = 1 if K or N is outside its valid range */ 08974 /* on input. */ 08975 /* IER = 2 if K indexes a boundary node. */ 08976 /* IER = 3 if an error flag is returned by CIRCUM */ 08977 /* (null triangle). */ 08978 /* IER = 4 if AREAS returns a value greater than */ 08979 /* AMAX (defined below). */ 08980 08981 /* Modules required by AREAV: AREAS, CIRCUM */ 08982 08983 /* *********************************************************** */ 08984 08985 08986 /* Maximum valid triangle area is less than 2*Pi: */ 08987 08988 /* Parameter adjustments */ 08989 --lend; 08990 --z__; 08991 --y; 08992 --x; 08993 --list; 08994 --lptr; 08995 08996 /* Function Body */ 08997 08998 /* Test for invalid input. */ 08999 09000 if (*k < 1 || *k > *n || *n <= 3) { 09001 goto L11; 09002 } 09003 09004 /* Initialization: Set N3 to the last neighbor of N1 = K. */ 09005 /* FIRST = TRUE only for the first triangle. */ 09006 /* The Voronoi region area is accumulated in ASUM. */ 09007 09008 n1 = *k; 09009 v1[0] = x[n1]; 09010 v1[1] = y[n1]; 09011 v1[2] = z__[n1]; 09012 lpl = lend[n1]; 09013 n3 = list[lpl]; 09014 if (n3 < 0) { 09015 goto L12; 09016 } 09017 lp = lpl; 09018 first = TRUE_; 09019 asum = 0.; 09020 09021 /* Loop on triangles (N1,N2,N3) containing N1 = K. */ 09022 09023 L1: 09024 n2 = n3; 09025 lp = lptr[lp]; 09026 n3 = list[lp]; 09027 v2[0] = x[n2]; 09028 v2[1] = y[n2]; 09029 v2[2] = z__[n2]; 09030 v3[0] = x[n3]; 09031 v3[1] = y[n3]; 09032 v3[2] = z__[n3]; 09033 if (first) { 09034 09035 /* First triangle: compute the circumcenter C3 and save a */ 09036 /* copy in C0. */ 09037 09038 circum_(v1, v2, v3, c3, &ierr); 09039 if (ierr != 0) { 09040 goto L13; 09041 } 09042 c0[0] = c3[0]; 09043 c0[1] = c3[1]; 09044 c0[2] = c3[2]; 09045 first = FALSE_; 09046 } else { 09047 09048 /* Set C2 to C3, compute the new circumcenter C3, and compute */ 09049 /* the area A of triangle (V1,C2,C3). */ 09050 09051 c2[0] = c3[0]; 09052 c2[1] = c3[1]; 09053 c2[2] = c3[2]; 09054 circum_(v1, v2, v3, c3, &ierr); 09055 if (ierr != 0) { 09056 goto L13; 09057 } 09058 a = areas_(v1, c2, c3); 09059 if (a > amax) { 09060 goto L14; 09061 } 09062 asum += a; 09063 } 09064 09065 /* Bottom on loop on neighbors of K. */ 09066 09067 if (lp != lpl) { 09068 goto L1; 09069 } 09070 09071 /* Compute the area of triangle (V1,C3,C0). */ 09072 09073 a = areas_(v1, c3, c0); 09074 if (a > amax) { 09075 goto L14; 09076 } 09077 asum += a; 09078 09079 /* No error encountered. */ 09080 09081 *ier = 0; 09082 ret_val = asum; 09083 return ret_val; 09084 09085 /* Invalid input. */ 09086 09087 L11: 09088 *ier = 1; 09089 ret_val = 0.; 09090 return ret_val; 09091 09092 /* K indexes a boundary node. */ 09093 09094 L12: 09095 *ier = 2; 09096 ret_val = 0.; 09097 return ret_val; 09098 09099 /* Error in CIRCUM. */ 09100 09101 L13: 09102 *ier = 3; 09103 ret_val = 0.; 09104 return ret_val; 09105 09106 /* AREAS value larger than AMAX. */ 09107 09108 L14: 09109 *ier = 4; 09110 ret_val = 0.; 09111 return ret_val; 09112 } /* 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 21003 of file util_sparx.cpp.
References t.
Referenced by image_mutation().
21003 { 21004 21005 if (is_mirror != 0) { 21006 for (int i=0; i<len_list; i++) { 21007 int r = rand()%10000; 21008 float f = r/10000.0f; 21009 if (f < mutation_rate) list[i] = 1-list[i]; 21010 } 21011 } else { 21012 map<int, vector<int> > graycode; 21013 map<vector<int>, int> rev_graycode; 21014 vector <int> gray; 21015 21016 int K=1; 21017 for (int i=0; i<L; i++) K*=2; 21018 21019 for (int k=0; k<K; k++) { 21020 int shift = 0; 21021 vector <int> gray; 21022 for (int i=L-1; i>-1; i--) { 21023 int t = ((k>>i)%2-shift)%2; 21024 gray.push_back(t); 21025 shift += t-2; 21026 } 21027 graycode[k] = gray; 21028 rev_graycode[gray] = k; 21029 } 21030 21031 float gap = (K-1)/(max_val-min_val); 21032 for (int i=0; i<len_list; i++) { 21033 float val = list[i]; 21034 if (val < min_val) { val = min_val; } 21035 else if (val > max_val) { val = max_val; } 21036 int k = int((val-min_val)*gap+0.5); 21037 vector<int> gray = graycode[k]; 21038 bool changed = false; 21039 for (vector<int>::iterator p=gray.begin(); p!=gray.end(); p++) { 21040 int r = rand()%10000; 21041 float f = r/10000.0f; 21042 if (f < mutation_rate) { 21043 *p = 1-*p; 21044 changed = true; 21045 } 21046 } 21047 if (changed) { 21048 k = rev_graycode[gray]; 21049 list[i] = k/gap+min_val; 21050 } 21051 } 21052 } 21053 21054 }
vector< int > Util::assign_groups | ( | const vector< float > & | d, | |
int | nref, | |||
int | nima | |||
) | [static] |
Definition at line 18058 of file util_sparx.cpp.
References peak_table::index.
18058 { 18059 18060 int kt = nref; 18061 unsigned int maxasi = nima/nref; 18062 vector< vector<int> > id_list; 18063 id_list.resize(nref); 18064 int group, ima; 18065 18066 peak_table* dd = new peak_table[nref*nima]; 18067 for (int i=0; i<nref*nima; i++) { 18068 dd[i].value = d[i]; 18069 dd[i].index = i; 18070 } 18071 sort(dd, dd+nref*nima); 18072 int begin = 0; 18073 18074 bool* del_row = new bool[nref]; 18075 for (int i=0; i<nref; i++) del_row[i] = false; 18076 bool* del_column = new bool[nima]; 18077 for (int i=0; i<nima; i++) del_column[i] = false; 18078 while (kt > 0) { 18079 bool flag = true; 18080 while (flag) { 18081 int l = dd[begin].index; 18082 group = l/nima; 18083 ima = l%nima; 18084 if (del_column[ima] || del_row[group]) begin++; 18085 else flag = false; 18086 } 18087 18088 id_list[group].push_back(ima); 18089 if (kt > 1) { 18090 if (id_list[group].size() < maxasi) group = -1; 18091 else kt -= 1; 18092 } else { 18093 if (id_list[group].size() < maxasi+nima%nref) group = -1; 18094 else kt -= 1; 18095 } 18096 del_column[ima] = true; 18097 if (group != -1) { 18098 del_row[group] = true; 18099 } 18100 } 18101 18102 vector<int> id_list_1; 18103 for (int iref=0; iref<nref; iref++) 18104 for (unsigned int im=0; im<maxasi; im++) 18105 id_list_1.push_back(id_list[iref][im]); 18106 for (unsigned int im=maxasi; im<maxasi+nima%nref; im++) 18107 id_list_1.push_back(id_list[group][im]); 18108 id_list_1.push_back(group); 18109 18110 delete[] del_row; 18111 delete[] del_column; 18112 delete[] dd; 18113 return id_list_1; 18114 }
vector< int > Util::assign_projangles | ( | const vector< float > & | projangles, | |
const vector< float > & | refangles | |||
) | [static] |
Definition at line 18138 of file util_sparx.cpp.
References getvec(), and nearest_ang().
Referenced by group_proj_by_phitheta().
18138 { 18139 int nref = refangles.size()/2; 18140 int nproj = projangles.size()/2; 18141 vector<int> asg(nproj); 18142 vector<float> vecref(nref*3); 18143 for (int i=0; i<nref; i++) 18144 getvec(refangles[i*2], refangles[i*2+1], vecref[i*3], vecref[i*3+1], vecref[i*3+2]); 18145 for (int i=0; i<nproj; i++) { 18146 float x, y, z; 18147 getvec(projangles[i*2], projangles[i*2+1], x, y, z); 18148 asg[i] = nearest_ang(vecref, x, y, z); 18149 } 18150 return asg; 18151 }
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 21421 of file util_sparx.cpp.
References branchMPI(), initial_prune(), and sanitycheck().
21422 { 21423 21424 21425 // 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 21426 // 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 21427 // Make a vector of nParts vectors of K int* each 21428 int* Indices = new int[nParts*K]; 21429 int ind_c = 0; 21430 for (int i=0; i < nParts; i++){ 21431 for(int j = 0; j < K; j++){ 21432 Indices[i*K + j] = ind_c; 21433 ind_c = ind_c + dimClasses[i*K + j]; 21434 } 21435 } 21436 21437 // do initial pruning on argParts and return the pruned partitions 21438 21439 // Make a vector of nParts vectors of K int* each 21440 vector <vector <int*> > Parts(nParts,vector<int*>(K)); 21441 ind_c = 0; 21442 int argParts_size=0; 21443 for (int i=0; i < nParts; i++){ 21444 for(int j = 0; j < K; j++){ 21445 Parts[i][j] = argParts + ind_c; 21446 ind_c = ind_c + dimClasses[i*K + j]; 21447 argParts_size = argParts_size + dimClasses[i*K + j]; 21448 } 21449 } 21450 21451 // in the following we call initial_prune with Parts which is a vector. This is not the most 21452 // efficient since vector does not allow for direct addressing. But since initial_prune doesn't have very high complexity, and 21453 // 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..... 21454 21455 // comment out for testing 21456 Util::initial_prune(Parts, dimClasses, nParts, K, T); 21457 for(int i = 0; i < nParts; i++){ 21458 for(int j=0; j < K; j++){ 21459 argParts[Indices[i*K + j]+1] = -1; 21460 } 21461 } 21462 21463 int num_classes; 21464 int old_index; 21465 for(int i=0; i<nParts; i++){ 21466 num_classes = Parts[i].size();// number of classes in partition i after pruning 21467 for (int j=0; j < num_classes; j++){ 21468 old_index = Parts[i][j][0]; 21469 //cout << "old_index: " << old_index<<"\n"; 21470 argParts[Indices[i*K + old_index]+1] = 1; 21471 } 21472 } 21473 21474 21475 // if we're not doing mpi then keep going and call branchMPI and return the output 21476 //cout <<"begin partition matching\n"; 21477 //int* dummy(0); 21478 int* output = Util::branchMPI(argParts, Indices,dimClasses, nParts, K, T, 0, n_guesses, LARGEST_CLASS, J, max_branching, stmult, branchfunc, LIM); 21479 21480 //cout<<"total cost: "<<*output<<"\n"; 21481 //cout<<"number of matches: "<<*(output+1)<<"\n"; 21482 // 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 21483 bool correct = Util::sanitycheck(argParts, Indices,dimClasses, nParts, K, T,output); 21484 21485 delete[] Indices; 21486 21487 // something is wrong with output of branchMPI! 21488 if (correct < 1){ 21489 cout << "something is wrong with output of branchMPI!\n"; 21490 vector<int> ret(1); 21491 ret[0] = -1; 21492 if (output != 0) { delete[] output; output = 0; } 21493 return ret; 21494 } 21495 21496 // output is not nonsense, so now put it into a single dimension vector and return 21497 // 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 21498 // and the rest is the list of matches. output is one dimensional 21499 21500 int output_size = 2 + output[1] * nParts; 21501 vector<int> ret(output_size); 21502 for (int i = 0; i < output_size; i++) { 21503 ret[i]= output[i]; 21504 } 21505 if (output != 0) { delete[] output; output = 0; } 21506 return ret; 21507 21508 }
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 1542 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 5757 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.
05758 { 05759 if (B->is_complex()) { 05760 B->do_ift_inplace(); 05761 B->depad(); 05762 } 05763 05764 const Transform * transform = B->get_attr("xform.projection"); 05765 Dict transform_params = transform->get_params("spider"); 05766 05767 // ---- build DM matrix (transform matrix) - convert from 3x4 matrix to 2x3 matrix (only 2 first rows are nedeed) 05768 std::vector<float> DM = transform->get_matrix(); 05769 DM[3+0] = DM[4+0]; 05770 DM[3+1] = DM[4+1]; 05771 DM[3+2] = DM[4+2]; 05772 05773 delete transform; 05774 05775 const int NSAM = B->get_xsize(); 05776 const int NROW = B->get_ysize(); 05777 05778 // buffer "lines_to_process" should be aligned to size of cache line (usually 64 or 128 bytes) 05779 t_BPCQ_line * lines_to_process; 05780 #ifdef _WIN32 05781 if ( (lines_to_process = (t_BPCQ_line *)_aligned_malloc( 4*radius*radius*sizeof(t_BPCQ_line), 256 )) == NULL ) 05782 #else 05783 if ( posix_memalign( reinterpret_cast<void**>(&lines_to_process), 256, 4*radius*radius*sizeof(t_BPCQ_line) ) != 0 ) 05784 #endif //_WIN32 05785 { 05786 throw std::bad_alloc(); 05787 } 05788 t_BPCQ_line * first_free_line = lines_to_process; 05789 05790 // calculate lines parameters 05791 { 05792 // Unsure about sign of shifts, check later PAP 06/28/09 05793 const float x_shift_plus_center = float(NSAM/2 +1) + float(transform_params[ "tx" ]); 05794 const float y_shift_plus_center = float(NROW/2 +1) + float(transform_params[ "ty" ]); 05795 05796 const int sizeX = CUBE->get_xsize(); 05797 const int sizeY = CUBE->get_ysize(); 05798 05799 const int centerX = sizeX / 2; 05800 const int centerY = sizeY / 2; 05801 const int centerZ = CUBE->get_zsize() /2; 05802 05803 for ( int rZ=-radius; rZ<=radius; ++rZ ) { 05804 for ( int rY=-radius; rY<=radius; ++rY ) { 05805 const int sqRX = radius*radius - rZ*rZ - rY*rY; 05806 if (sqRX >= 0) { 05807 #ifdef _WIN32 05808 first_free_line->rX = static_cast<int>( floor(sqrtf(sqRX)+0.5) ); 05809 #else 05810 first_free_line->rX = static_cast<int>( roundf(sqrtf(sqRX)) ); 05811 #endif //_WIN32 05812 first_free_line->offset = sizeX*( centerY+rY + sizeY*(centerZ+rZ) ) + centerX - first_free_line->rX; 05813 first_free_line->xbb = rZ*DM[2] + rY*DM[1] + x_shift_plus_center; 05814 first_free_line->ybb = rZ*DM[5] + rY*DM[4] + y_shift_plus_center; 05815 ++first_free_line; 05816 } 05817 } 05818 } 05819 } 05820 05821 const float * const Bptr = B->get_data(); 05822 float * const CUBE_begin = CUBE->get_data(); 05823 05824 // update voxels in volume 05825 // this loop takes more than 95% of calculations time spent in Util::BPCQ function 05826 for ( t_BPCQ_line * iLine = lines_to_process; iLine < first_free_line; ++iLine ) { 05827 const int rX_first = -(iLine->rX); 05828 const int rX_last = iLine->rX; 05829 float *CUBE_ptr = CUBE_begin + iLine->offset; 05830 for (int rX=rX_first; rX<=rX_last; ++rX, ++CUBE_ptr) { 05831 const float XB = rX * DM[0] + iLine->xbb; 05832 const float YB = rX * DM[3] + iLine->ybb; 05833 const int IQX = int(XB); 05834 const int IQY = int(YB); 05835 if ( IQX < 1 || IQX >= NSAM || IQY < 1 || IQY >= NROW ) continue; 05836 const float DIPX = XB-IQX; 05837 const float DIPY = YB-IQY; 05838 const float b00 = Bptr[IQX-1+((IQY-1)*NSAM)]; 05839 const float b01 = Bptr[IQX-1+((IQY-0)*NSAM)]; 05840 const float b10 = Bptr[IQX-0+((IQY-1)*NSAM)]; 05841 const float b11 = Bptr[IQX-0+((IQY-0)*NSAM)]; 05842 *(CUBE_ptr) = *(CUBE_ptr) + b00 + DIPY*(b01-b00) + DIPX*(b10-b00+DIPY*(b11-b10-b01+b00)); 05843 } 05844 } 05845 05846 free(lines_to_process); 05847 }
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 21940 of file util_sparx.cpp.
References jiafunc().
Referenced by branchMPI().
21940 { 21941 21942 int ntot=0; 21943 for (int jit=0; jit < J; jit++){ 21944 if (*(costlist+jit) > T) ntot++; 21945 } 21946 21947 int cur; 21948 // sort matchlist by cost 21949 int* indx = new int[J]; 21950 for (int jit=0; jit < J; jit++) indx[jit]=jit; 21951 vector<int> myindx (indx, indx+J); 21952 vector<int>::iterator it; 21953 costlist_global=costlist; 21954 sort(myindx.begin(), myindx.begin()+J, jiafunc); 21955 21956 // put matchlist in the order of mycost 21957 int* templist = new int[J]; 21958 int* temp2list = new int[J*nParts]; 21959 int next = 0; 21960 21961 for (it=myindx.begin(); it!=myindx.end();++it){ 21962 cur = *(costlist + *it); 21963 if (cur > T){ 21964 21965 templist[next] = cur; 21966 for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt]; 21967 next = next + 1; 21968 } 21969 } 21970 21971 for (int jit=0; jit < ntot; jit++){ 21972 *(costlist+jit)=*(templist + jit); 21973 //cout <<*(costlist+jit)<<", "; 21974 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit]; 21975 } 21976 //cout <<"\n"; 21977 21978 for (int jit=1; jit < ntot; jit++){ 21979 21980 if ((costlist[jit] == costlist[0]) && costlist[jit] > T){ 21981 21982 for (int vit=0; vit < nParts; vit++){ 21983 if ( matchlist[jit*nParts + vit] > matchlist[vit]) 21984 break; 21985 if ( matchlist[jit*nParts + vit] == matchlist[vit]) 21986 continue; 21987 if ( matchlist[jit*nParts + vit] < matchlist[vit]) 21988 { 21989 // swap 21990 for (int swp=0; swp < nParts; swp++){ 21991 int tmp = matchlist[swp]; 21992 matchlist[swp]= matchlist[jit*nParts + swp]; 21993 matchlist[jit*nParts + swp] = tmp; 21994 } 21995 break; 21996 21997 } 21998 } 21999 } 22000 22001 } 22002 22003 22004 delete [] indx; 22005 //compute the average 22006 22007 // partition matches into groups where matches in each group is mutually feasible, and matches from different groups are not feasible 22008 // The number of branches to explore are the mutually exclusive matches. Take the largest of these 22009 22010 22011 int B=1; 22012 int B_init=B; 22013 int infeasible=0; 22014 22015 for (int i=B_init; i<ntot; i++){ 22016 if (i==ntot) continue; 22017 // look at the i-th match. branch on it only if it is infeasible with ALL previous matches we have decided to 22018 // branch on 22019 infeasible = 0; 22020 if (LIM < 0) LIM = B; 22021 for (int j=0; j<B; j++){ 22022 22023 for (int vit=0; vit<nParts; vit++){ 22024 if (temp2list[i*nParts+vit] == matchlist[j*nParts+vit]) {infeasible++; break;} 22025 } 22026 if (infeasible >= LIM) break; 22027 } 22028 22029 if (infeasible >= LIM){ 22030 *(costlist+B)=*(templist+i); 22031 for (int vit=0; vit < nParts; vit++) 22032 *(matchlist+B*nParts + vit)=*(temp2list+i*nParts + vit); 22033 B=B+1; 22034 } 22035 } 22036 22037 delete [] templist; 22038 delete [] temp2list; 22039 //cout<<"**************************************** "<<B<<" ***************************\n"; 22040 22041 if (branch_all < max_branching){ 22042 if (B>1) 22043 {branch_all = branch_all + B -1 ; } 22044 } 22045 else B=1; 22046 22047 return B; 22048 22049 22050 }
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 21678 of file util_sparx.cpp.
References jiafunc().
Referenced by branchMPI().
21678 { 21679 21680 int ntot=0; 21681 for (int jit=0; jit < J; jit++){ 21682 if (*(costlist+jit) > T) ntot++; 21683 } 21684 21685 int cur; 21686 // sort matchlist by cost 21687 int* indx = new int[J]; 21688 for (int jit=0; jit < J; jit++) indx[jit]=jit; 21689 vector<int> myindx (indx, indx+J); 21690 vector<int>::iterator it; 21691 costlist_global=costlist; 21692 sort(myindx.begin(), myindx.end(), jiafunc); 21693 21694 // put matchlist in the order of mycost 21695 int* templist = new int[J]; 21696 int* temp2list = new int[J*nParts]; 21697 int next = 0; 21698 21699 for (it=myindx.begin(); it!=myindx.end();++it){ 21700 cur = *(costlist + *it); 21701 if (cur > T){ 21702 21703 templist[next] = cur; 21704 for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt]; 21705 next = next + 1; 21706 } 21707 } 21708 21709 for (int jit=0; jit < ntot; jit++){ 21710 *(costlist+jit)=*(templist + jit); 21711 //cout <<*(costlist+jit)<<", "; 21712 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit]; 21713 } 21714 //cout <<"\n"; 21715 21716 delete [] indx; 21717 //compute the average 21718 21719 // partition matches into groups where matches in each group is mutually feasible, and matches from different groups are not feasible 21720 // The number of branches to explore are the mutually exclusive matches. Take the largest of these 21721 21722 21723 int B=1; 21724 int B_init=B; 21725 int infeasible=0; 21726 21727 for (int i=B_init; i<ntot; i++){ 21728 if (i==ntot) continue; 21729 // look at the i-th match. branch on it only if it is infeasible with ALL previous matches we have decided to 21730 // branch on 21731 infeasible = 0; 21732 if (LIM < 0) LIM = B; 21733 for (int j=0; j<B; j++){ 21734 21735 for (int vit=0; vit<nParts; vit++){ 21736 if (temp2list[i*nParts+vit] == matchlist[j*nParts+vit]) {infeasible++; break;} 21737 } 21738 if (infeasible >= LIM) break; 21739 } 21740 21741 if (infeasible >= LIM){ 21742 *(costlist+B)=*(templist+i); 21743 for (int vit=0; vit < nParts; vit++) 21744 *(matchlist+B*nParts + vit)=*(temp2list+i*nParts + vit); 21745 B=B+1; 21746 } 21747 } 21748 21749 delete [] templist; 21750 delete [] temp2list; 21751 //cout<<"**************************************** "<<B<<" ***************************\n"; 21752 21753 if (branch_all < max_branching){ 21754 if (B>1) 21755 {branch_all = branch_all + B -1 ; } 21756 } 21757 else B=1; 21758 21759 return B; 21760 21761 21762 }
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 21766 of file util_sparx.cpp.
References jiafunc().
Referenced by branchMPI().
21766 { 21767 21768 int ntot=0; 21769 for (int jit=0; jit < J; jit++){ 21770 if (*(costlist+jit) > T) ntot++; 21771 } 21772 21773 int cur; 21774 // sort matchlist by cost 21775 int* indx = new int[J]; 21776 for (int jit=0; jit < J; jit++) indx[jit]=jit; 21777 vector<int> myindx (indx, indx+J); 21778 vector<int>::iterator it; 21779 costlist_global=costlist; 21780 sort(myindx.begin(), myindx.begin()+J, jiafunc); 21781 21782 // put matchlist in the order of mycost 21783 int* templist = new int[J]; 21784 int* temp2list = new int[J*nParts]; 21785 int next = 0; 21786 21787 for (it=myindx.begin(); it!=myindx.end();++it){ 21788 cur = *(costlist + *it); 21789 if (cur > T){ 21790 21791 templist[next] = cur; 21792 for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt]; 21793 next = next + 1; 21794 } 21795 } 21796 21797 for (int jit=0; jit < ntot; jit++){ 21798 *(costlist+jit)=*(templist + jit); 21799 //cout <<*(costlist+jit)<<", "; 21800 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit]; 21801 } 21802 //cout <<"\n"; 21803 21804 delete [] indx; 21805 //compute the average 21806 21807 // partition matches into groups where matches in each group is mutually feasible, and matches from different groups are not feasible 21808 // The number of branches to explore are the mutually exclusive matches. Take the largest of these 21809 21810 21811 int B=1; 21812 int B_init=B; 21813 int infeasible=0; 21814 // if we're near the bottom of the tree then explore more... this is because the larger weights are not likely to change much, 21815 // whereas the smaller ones can have many permutations 21816 if (LIM < 0) LIM = ntot-1; 21817 for (int i=B_init; i<ntot; i++){ 21818 if (i==ntot) continue; 21819 // look at the i-th match. branch on it only if it is infeasible with ALL previous matches we have decided to 21820 // branch on 21821 infeasible = 0; 21822 21823 for (int j=0; j<ntot; j++){ 21824 if (j == i) continue; 21825 for (int vit=0; vit<nParts; vit++){ 21826 if (temp2list[i*nParts+vit] == temp2list[j*nParts+vit]) {infeasible++; break;} 21827 } 21828 if (infeasible >= LIM) break; 21829 } 21830 21831 if (infeasible >= LIM){ 21832 *(costlist+B)=*(templist+i); 21833 for (int vit=0; vit < nParts; vit++) 21834 *(matchlist+B*nParts + vit)=*(temp2list+i*nParts + vit); 21835 B=B+1; 21836 } 21837 } 21838 21839 delete [] templist; 21840 delete [] temp2list; 21841 //cout<<"**************************************** "<<B<<" ***************************\n"; 21842 21843 21844 if (branch_all < max_branching){ 21845 if (B>1) 21846 {branch_all = branch_all + B-1;} 21847 } 21848 else B=1; 21849 21850 return B; 21851 21852 21853 }
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 21859 of file util_sparx.cpp.
References jiafunc().
Referenced by branchMPI().
21859 { 21860 int sum=0; 21861 float average =0; 21862 int ntot=0; 21863 for (int jit=0; jit < J; jit++){ 21864 if (*(costlist+jit) > T) {ntot++; sum = sum +*(costlist+jit);} 21865 } 21866 average = ((float)sum)/((float)ntot); 21867 int cur; 21868 // sort matchlist by cost 21869 int* indx = new int[J]; 21870 for (int jit=0; jit < J; jit++) indx[jit]=jit; 21871 vector<int> myindx (indx, indx+J); 21872 vector<int>::iterator it; 21873 costlist_global=costlist; 21874 sort(myindx.begin(), myindx.begin()+J, jiafunc); 21875 21876 // put matchlist in the order of mycost 21877 int* templist = new int[J]; 21878 int* temp2list = new int[J*nParts]; 21879 int next = 0; 21880 21881 for (it=myindx.begin(); it!=myindx.end();++it){ 21882 cur = *(costlist + *it); 21883 if (cur > T){ 21884 21885 templist[next] = cur; 21886 for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt]; 21887 next = next + 1; 21888 } 21889 } 21890 21891 for (int jit=0; jit < ntot; jit++){ 21892 *(costlist+jit)=*(templist + jit); 21893 //cout <<*(costlist+jit)<<", "; 21894 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit]; 21895 } 21896 //cout <<"\n"; 21897 21898 delete [] indx; 21899 delete [] templist; 21900 delete [] temp2list; 21901 21902 if (ntot == 1) return 1; 21903 21904 // look at the average, standard dev etc. If standard dev very small, i.e., costs very similar, then branch on the similar 21905 // costs 21906 float sq_sum=0.0; 21907 //cout <<"costlist:"; 21908 for (int i=0; i< ntot; i++){ 21909 sq_sum = sq_sum + (float) pow((float) *(costlist+i) - average, (float)2.0); 21910 //cout <<*(costlist+i)<<", "; 21911 } 21912 //cout <<"\n"; 21913 21914 float variance = sq_sum/ntot; 21915 float stdev = (float)pow((float)variance,(float)0.5); 21916 21917 //cout <<"stdev: "<<int(stdev)<<"\n"; 21918 21919 int B=1; 21920 int largest = *costlist; 21921 //cout <<"largest: "<<largest<<"\n"; 21922 for (int i=1; i<ntot; i++){ 21923 int cur = *(costlist+i); 21924 if (largest-cur < (float)(stdev*stmult)) B++; 21925 else break; 21926 21927 } 21928 //cout <<"B: "<<B<<"\n"; 21929 if (branch_all < max_branching){ 21930 if (B>1) 21931 {branch_all = branch_all + B-1;} 21932 } 21933 else B=1; 21934 21935 return B; 21936 21937 21938 }
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 21512 of file util_sparx.cpp.
References branch_factor_0(), branch_factor_2(), branch_factor_3(), branch_factor_4(), branchMPI(), and search2().
21513 { 21514 21515 //************************************* 21516 //testing search2 21517 if (1 == 0){ 21518 cout <<"begin test search2\n"; 21519 int* matchlist = new int[J*nParts]; 21520 int* costlist = new int[J]; 21521 for (int jit = 0; jit < nParts; jit++) *(costlist+jit) = 0; 21522 Util::search2(argParts,Indices, dimClasses, nParts, K, T, matchlist,costlist,J); 21523 21524 for (int jit = 0; jit < J; jit++) { 21525 cout << *(costlist +jit)<<": "; 21526 for (int yit = 0; yit < nParts; yit++) 21527 cout << *(matchlist + jit*nParts + yit)<<","; 21528 cout <<"\n"; 21529 21530 } 21531 cout <<"end test search2\n"; 21532 int* output = new int[1]; 21533 output[0] = 1; 21534 delete [] matchlist; 21535 delete [] costlist; 21536 return output; 21537 } 21538 //************************************** 21539 21540 // Base Case: we're at a leaf, no more feasible matches possible 21541 if (curlevel > K -1){ 21542 int* output = new int[2]; 21543 output[0] = 0; 21544 output[1] = 0; 21545 return output; 21546 } 21547 21548 // branch dynamically depending on results of search 2! 21549 21550 int* matchlist = new int[J*nParts]; 21551 int* costlist = new int[J]; 21552 Util::search2(argParts, Indices, dimClasses, nParts, K, T, matchlist, costlist, J); 21553 21554 21555 // each class in the matches found by findTopLargest is encoded by the original index of the first element of the class in argPart 21556 // each match contains nParts classes, with the i-th class belonging to the i-th partition. 21557 21558 // if there are no feasible matches with cost gt T, then return 0 21559 for (int jit = 0; jit < J ; jit++){ 21560 21561 if (costlist[jit] > T) break; 21562 if (jit == J-1){ 21563 int* output = new int[2]; 21564 output[0] = 0; 21565 output[1] = 0; 21566 delete[] matchlist; 21567 delete[] costlist; 21568 return output; 21569 } 21570 } 21571 21572 21573 21574 // note that costlist and matchlist are NOT sorted by weight, and branch factor takes care of that... 21575 if (curlevel==0) branch_all = 0; 21576 21577 int nBranches = -1; 21578 21579 if (branchfunc == 0) 21580 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 21581 21582 if (branchfunc == 2) 21583 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 21584 21585 if (branchfunc == 3) 21586 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 21587 21588 if (branchfunc == 4) 21589 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 21590 21591 int* newcostlist= new int[nBranches]; 21592 int* newmatchlist = new int[nBranches*nParts]; 21593 for (int i=0; i<nBranches; i++){ 21594 newcostlist[i] = costlist[i]; 21595 for (int j=0; j< nParts; j++) 21596 newmatchlist[i*nParts + j] = matchlist[i*nParts + j]; 21597 } 21598 21599 delete[] costlist; 21600 delete[] matchlist; 21601 21602 //int* output = new int[2];//initialize to placeholder 21603 int* output = new int[2+K*nParts];//initialize to placeholder 21604 output[0] = 0; 21605 output[1] = 0; 21606 // some temporary variables 21607 int old_index; 21608 int totalcost; 21609 int nmatches; 21610 //int offset; 21611 21612 for(int i=0; i < nBranches ; i++){ 21613 21614 // consider the i-th match returned by findTopLargest 21615 //if (newcostlist[i] <= T) continue; 21616 21617 // 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. 21618 // After branch returns, compute overall cost, unmark the classes just marked as 1 again in preparation for next loop. 21619 21620 for(int j=0; j < nParts; j++){ 21621 // matchlist[i*nParts + j] is the original index of the class belonging to the j-th partition in the i-th match. 21622 old_index = newmatchlist[i*nParts + j]; 21623 argParts[Indices[j*K+old_index] + 1] = -2; 21624 } 21625 21626 21627 int* ret = Util::branchMPI(argParts, Indices, dimClasses, nParts, K, T, curlevel+1, n_guesses, LARGEST_CLASS, 21628 J, max_branching, stmult,branchfunc, LIM); 21629 21630 // first element of ret is the total cost of all the matches in ret, and second element is the number of matches in ret 21631 totalcost = newcostlist[i] + ret[0]; 21632 21633 //if (curlevel == 0) { 21634 // cout <<"totalcost*****************************************************************: "<<totalcost<<", costlist["<<i<<"]="<<newcostlist[i]<<", *ret="<<*ret<<", level: "<<curlevel<<"\n"; 21635 21636 //} 21637 if (totalcost > output[0]) // option 1 21638 { 21639 nmatches = 1 + ret[1]; 21640 //delete[] output; // get rid of the old maxreturn 21641 //output = new int[2+nmatches*nParts]; 21642 output[0] = totalcost; 21643 output[1] = nmatches; 21644 int nret = 2+(nmatches-1)*nParts; 21645 for(int iret=2; iret < nret; iret++) output[iret] = ret[iret]; 21646 for(int imax=0; imax < nParts; imax++) output[nret+imax] = newmatchlist[i*nParts + imax]; 21647 } 21648 21649 21650 delete[] ret; 21651 21652 // unmark the marked classes in preparation for the next iteration 21653 21654 for(int j=0; j < nParts; j++){ 21655 old_index = newmatchlist[i*nParts + j]; 21656 argParts[Indices[j*K+old_index] + 1] = 1; 21657 } 21658 21659 } 21660 21661 delete[] newmatchlist; 21662 delete[] newcostlist; 21663 21664 return output; 21665 }
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 984 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().
00985 { 00986 Assert(low >= 0); 00987 00988 //array containing valid sizes <1024 for speed 00989 static char *valid = NULL; 00990 00991 if (!valid) { 00992 valid = (char *) calloc(4096, 1); 00993 00994 for (float i2 = 1; i2 < 12.0; i2 += 1.0) { 00995 00996 float f1 = pow((float) 2.0, i2); 00997 for (float i3 = 0; i3 < 8.0; i3 += 1.0) { 00998 00999 float f2 = pow((float) 3.0, i3); 01000 for (float i5 = 0; i5 < 6.0; i5 += 1.0) { 01001 01002 float f3 = pow((float) 5.0, i5); 01003 for (float i7 = 0; i7 < 5.0; i7 += 1.0) { 01004 01005 float f = f1 * f2 * f3 * pow((float) 7.0, i7); 01006 if (f <= 4095.0) { 01007 int n = (int) f; 01008 valid[n] = 1; 01009 } 01010 } 01011 } 01012 } 01013 } 01014 } 01015 01016 for (int i = low; i < 4096; i++) { 01017 if (valid[i]) { 01018 return i; 01019 } 01020 } 01021 01022 LOGERR("Sorry, can only find good fft sizes up to 4096 right now."); 01023 01024 return 1; 01025 }
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 548 of file util.cpp.
Referenced by EMAN::PointArray::align_2d().
00548 { 00549 unsigned int i; 00550 00551 // various sums used in the final solution 00552 double Sx=0,Sy=0,Sxy=0,Sxx=0,Syy=0,Sz=0,Sxz=0,Syz=0,S=0; 00553 for (i=0; i<p.size(); i+=3) { 00554 Sx+=p[i]; 00555 Sy+=p[i+1]; 00556 Sz+=p[i+2]; 00557 Sxx+=p[i]*p[i]; 00558 Syy+=p[i+1]*p[i+1]; 00559 Sxy+=p[i]*p[i+1]; 00560 S+=1.0; 00561 Sxz+=p[i]*p[i+2]; 00562 Syz+=p[i+1]*p[i+2]; 00563 } 00564 double d=S*Sxy*Sxy - 2*Sx*Sxy*Sy + Sxx*Sy*Sy + Sx*Sx*Syy - S*Sxx*Syy; 00565 00566 Vec3f ret(0,0,0); 00567 00568 ret[0]=static_cast<float>(-((Sxy*Sxz*Sy - Sx*Sxz*Syy + Sx*Sxy*Syz - Sxx*Sy*Syz - Sxy*Sxy*Sz +Sxx*Syy*Sz)/d)); 00569 ret[1]=static_cast<float>(-((-Sxz*Sy*Sy + S*Sxz*Syy - S*Sxy*Syz + Sx*Sy*Syz + Sxy*Sy*Sz -Sx*Syy*Sz) /d)); 00570 ret[2]=static_cast<float>(-((-S*Sxy*Sxz + Sx*Sxz*Sy - Sx*Sx*Syz + S*Sxx*Syz + Sx*Sxy*Sz -Sxx*Sy*Sz) /d)); 00571 00572 return ret; 00573 }
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 509 of file util.cpp.
References Assert, div(), NullPointerException, x, and y.
Referenced by EMAN::OptVarianceCmp::cmp(), EMAN::LowpassAutoBProcessor::create_radial_func(), and EMAN::GradientRemoverProcessor::process_inplace().
00511 { 00512 Assert(nitems > 0); 00513 00514 if (!data_x || !data_y || !slope || !intercept) { 00515 throw NullPointerException("null float pointer"); 00516 } 00517 double sum = 0; 00518 double sum_x = 0; 00519 double sum_y = 0; 00520 double sum_xx = 0; 00521 double sum_xy = 0; 00522 00523 for (size_t i = 0; i < nitems; i++) { 00524 if ((!ignore_zero || (data_x[i] != 0 && data_y[i] != 0))&&(!absmax ||(data_y[i]<absmax && data_y[i]>-absmax))) { 00525 double y = data_y[i]; 00526 double x = i; 00527 if (data_x) { 00528 x = data_x[i]; 00529 } 00530 00531 sum_x += x; 00532 sum_y += y; 00533 sum_xx += x * x; 00534 sum_xy += x * y; 00535 sum++; 00536 } 00537 } 00538 00539 double div = sum * sum_xx - sum_x * sum_x; 00540 if (div == 0) { 00541 div = 0.0000001f; 00542 } 00543 00544 *intercept = (float) ((sum_xx * sum_y - sum_x * sum_xy) / div); 00545 *slope = (float) ((sum * sum_xy - sum_x * sum_y) / div); 00546 }
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 6468 of file util_sparx.cpp.
References lsfit().
06469 { 06470 long int q2_dim1, q2_offset, q_dim1, q_offset, i__1, i__2; 06471 float r__1; 06472 int tmp__i; 06473 long int i__, j; 06474 --s; 06475 --res; 06476 iu -= 3; 06477 cu -= 3; 06478 --x; 06479 long int klm2d; 06480 klm2d= *k+*k+2; 06481 klm2d=klm2d+klm2d; 06482 q_dim1 = klm2d; 06483 q_offset = 1 + q_dim1; 06484 q -= q_offset; 06485 q2_dim1 = klm2d; 06486 q2_offset = 1 + q2_dim1; 06487 q2 -= q2_offset; 06488 i__2=0; 06489 i__1 = *n - 1; 06490 tmp__i=0; 06491 for (j = 1; j <= i__1; ++j) { 06492 i__2 = *k; 06493 tmp__i+=1; 06494 for (i__ = 1; i__ <= i__2; ++i__) { 06495 r__1 = float(i__ - 1) /(float) *k / (*ps * 2); 06496 q2[i__ + j * q2_dim1] = pow(r__1, tmp__i); 06497 } 06498 } 06499 for (i__ = 1; i__ <= i__2; ++i__) 06500 { q2[i__ + *n * q2_dim1] = 1.f; 06501 q2[i__ + (*n + 1) * q2_dim1] = pw[i__-1]; 06502 } 06503 vector<float> fit_res; 06504 fit_res=Util::lsfit(k, n, &klm2d, iswi, &q2[q2_offset], &q[q_offset], &x[1], &res[1], &cu[3], &s[1], &iu[3]); 06505 return fit_res; 06506 }
Dict Util::CANG | ( | float | PHI, | |
float | THETA, | |||
float | PSI | |||
) | [static] |
Definition at line 5706 of file util_sparx.cpp.
References DGR_TO_RAD, DM, and SS.
05707 { 05708 double CPHI,SPHI,CTHE,STHE,CPSI,SPSI; 05709 vector<float> DM,SS; 05710 05711 for(int i =0;i<9;i++) DM.push_back(0); 05712 05713 for(int i =0;i<6;i++) SS.push_back(0); 05714 05715 CPHI = cos(double(PHI)*DGR_TO_RAD); 05716 SPHI = sin(double(PHI)*DGR_TO_RAD); 05717 CTHE = cos(double(THETA)*DGR_TO_RAD); 05718 STHE = sin(double(THETA)*DGR_TO_RAD); 05719 CPSI = cos(double(PSI)*DGR_TO_RAD); 05720 SPSI = sin(double(PSI)*DGR_TO_RAD); 05721 05722 SS(1) = float(CPHI); 05723 SS(2) = float(SPHI); 05724 SS(3) = float(CTHE); 05725 SS(4) = float(STHE); 05726 SS(5) = float(CPSI); 05727 SS(6) = float(SPSI); 05728 05729 DM(1) = float(CPHI*CTHE*CPSI-SPHI*SPSI); 05730 DM(2) = float(SPHI*CTHE*CPSI+CPHI*SPSI); 05731 DM(3) = float(-STHE*CPSI); 05732 DM(4) = float(-CPHI*CTHE*SPSI-SPHI*CPSI); 05733 DM(5) = float(-SPHI*CTHE*SPSI+CPHI*CPSI); 05734 DM(6) = float(STHE*SPSI); 05735 DM(7) = float(STHE*CPHI); 05736 DM(8) = float(STHE*SPHI); 05737 DM(9) = float(CTHE); 05738 05739 Dict DMnSS; 05740 DMnSS["DM"] = DM; 05741 DMnSS["SS"] = SS; 05742 05743 return(DMnSS); 05744 }
Definition at line 20172 of file util_sparx.cpp.
References EMAN::EMData::cmp(), and EMAN::EMData::rot_scale_trans2D().
Referenced by twoD_fine_ali_SD().
20172 { 20173 20174 EMData *rot= new EMData(); 20175 float ccc; 20176 20177 rot = image->rot_scale_trans2D(ang, sx, sy, 1.0); 20178 ccc = -rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 20179 delete rot; 20180 return ccc; 20181 }
float Util::ccc_images_G | ( | EMData * | image, | |
EMData * | refim, | |||
EMData * | mask, | |||
Util::KaiserBessel & | kb, | |||
float | ang, | |||
float | sx, | |||
float | sy | |||
) | [static] |
Definition at line 20209 of file util_sparx.cpp.
References EMAN::EMData::cmp(), pi, and EMAN::EMData::rot_scale_conv7().
Referenced by twoD_fine_ali_SD_G().
20209 { 20210 20211 EMData *rot= new EMData(); 20212 float ccc; 20213 20214 rot = image->rot_scale_conv7(static_cast<float>(ang*pi/180.0), sx, sy, kb, 1.0f); 20215 ccc = -rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 20216 delete rot; 20217 return ccc; 20218 }
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 430 of file util.cpp.
References Assert.
Referenced by EMAN::EMUtil::get_image_type(), EMAN::ImagicIO::ImagicIO(), and EMAN::ImagicIO2::ImagicIO2().
00432 { 00433 Assert(old_filename != ""); 00434 if (ext == "") { 00435 return old_filename; 00436 } 00437 00438 string filename = old_filename; 00439 size_t dot_pos = filename.rfind("."); 00440 if (dot_pos != string::npos) { 00441 filename = filename.substr(0, dot_pos+1); 00442 } 00443 else { 00444 filename = filename + "."; 00445 } 00446 filename = filename + ext; 00447 return filename; 00448 }
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 194 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().
00195 { 00196 if (!first_block || !magic) { 00197 throw NullPointerException("first_block/magic"); 00198 } 00199 00200 const char *buf = static_cast < const char *>(first_block); 00201 00202 if (strncmp(buf, magic, strlen(magic)) == 0) { 00203 return true; 00204 } 00205 return false; 00206 }
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 6653 of file util_sparx.cpp.
06655 { 06656 06657 long int q_dim1, q_offset, i__1, i__2; 06658 double d__1; 06659 06660 static long int i__, j; 06661 static double z__; 06662 static long int n1, n2, ia, ii, kk, in, nk, js; 06663 static double sn, zu, zv; 06664 static long int nk1, klm, nkl, jmn, jpn; 06665 static double cuv; 06666 static long int klm1, nkl1, klm2, kode, iimn, nklm, iter; 06667 static float xmin; 06668 static double xmax; 06669 static long int iout; 06670 static double xsum; 06671 static long int iineg, maxit; 06672 static double toler; 06673 static float error; 06674 static double pivot; 06675 static long int kforce, iphase; 06676 static double tpivot; 06677 06678 --s; 06679 --res; 06680 iu -= 3; 06681 cu -= 3; 06682 --x; 06683 q_dim1 = *klm2d; 06684 q_offset = 1 + q_dim1; 06685 q -= q_offset; 06686 06687 /* Function Body */ 06688 maxit = 500; 06689 kode = 0; 06690 toler = 1e-4f; 06691 iter = 0; 06692 n1 = *n + 1; 06693 n2 = *n + 2; 06694 nk = *n + *k; 06695 nk1 = nk + 1; 06696 nkl = nk + *l; 06697 nkl1 = nkl + 1; 06698 klm = *k + *l + *m; 06699 klm1 = klm + 1; 06700 klm2 = klm + 2; 06701 nklm = *n + klm; 06702 kforce = 1; 06703 iter = 0; 06704 js = 1; 06705 ia = 0; 06706 /* SET UP LABELS IN Q. */ 06707 i__1 = *n; 06708 for (j = 1; j <= i__1; ++j) { 06709 q[klm2 + j * q_dim1] = (double) j; 06710 /* L10: */ 06711 } 06712 i__1 = klm; 06713 for (i__ = 1; i__ <= i__1; ++i__) { 06714 q[i__ + n2 * q_dim1] = (double) (*n + i__); 06715 if (q[i__ + n1 * q_dim1] >= 0.f) { 06716 goto L30; 06717 } 06718 i__2 = n2; 06719 for (j = 1; j <= i__2; ++j) { 06720 q[i__ + j * q_dim1] = -q[i__ + j * q_dim1]; 06721 /* L20: */ 06722 } 06723 L30: 06724 ; 06725 } 06726 /* SET UP PHASE 1 COSTS. */ 06727 iphase = 2; 06728 i__1 = nklm; 06729 for (j = 1; j <= i__1; ++j) { 06730 cu[(j << 1) + 1] = 0.f; 06731 cu[(j << 1) + 2] = 0.f; 06732 iu[(j << 1) + 1] = 0; 06733 iu[(j << 1) + 2] = 0; 06734 /* L40: */ 06735 } 06736 if (*l == 0) { 06737 goto L60; 06738 } 06739 i__1 = nkl; 06740 for (j = nk1; j <= i__1; ++j) { 06741 cu[(j << 1) + 1] = 1.f; 06742 cu[(j << 1) + 2] = 1.f; 06743 iu[(j << 1) + 1] = 1; 06744 iu[(j << 1) + 2] = 1; 06745 /* L50: */ 06746 } 06747 iphase = 1; 06748 L60: 06749 if (*m == 0) { 06750 goto L80; 06751 } 06752 i__1 = nklm; 06753 for (j = nkl1; j <= i__1; ++j) { 06754 cu[(j << 1) + 2] = 1.f; 06755 iu[(j << 1) + 2] = 1; 06756 jmn = j - *n; 06757 if (q[jmn + n2 * q_dim1] < 0.f) { 06758 iphase = 1; 06759 } 06760 /* L70: */ 06761 } 06762 L80: 06763 if (kode == 0) { 06764 goto L150; 06765 } 06766 i__1 = *n; 06767 for (j = 1; j <= i__1; ++j) { 06768 if ((d__1 = x[j]) < 0.) { 06769 goto L90; 06770 } else if (d__1 == 0) { 06771 goto L110; 06772 } else { 06773 goto L100; 06774 } 06775 L90: 06776 cu[(j << 1) + 1] = 1.f; 06777 iu[(j << 1) + 1] = 1; 06778 goto L110; 06779 L100: 06780 cu[(j << 1) + 2] = 1.f; 06781 iu[(j << 1) + 2] = 1; 06782 L110: 06783 ; 06784 } 06785 i__1 = *k; 06786 for (j = 1; j <= i__1; ++j) { 06787 jpn = j + *n; 06788 if ((d__1 = res[j]) < 0.) { 06789 goto L120; 06790 } else if (d__1 == 0) { 06791 goto L140; 06792 } else { 06793 goto L130; 06794 } 06795 L120: 06796 cu[(jpn << 1) + 1] = 1.f; 06797 iu[(jpn << 1) + 1] = 1; 06798 if (q[j + n2 * q_dim1] > 0.f) { 06799 iphase = 1; 06800 } 06801 goto L140; 06802 L130: 06803 cu[(jpn << 1) + 2] = 1.f; 06804 iu[(jpn << 1) + 2] = 1; 06805 if (q[j + n2 * q_dim1] < 0.f) { 06806 iphase = 1; 06807 } 06808 L140: 06809 ; 06810 } 06811 L150: 06812 if (iphase == 2) { 06813 goto L500; 06814 } 06815 /* COMPUTE THE MARGINAL COSTS. */ 06816 L160: 06817 i__1 = n1; 06818 for (j = js; j <= i__1; ++j) { 06819 xsum = 0.; 06820 i__2 = klm; 06821 for (i__ = 1; i__ <= i__2; ++i__) { 06822 ii = (long int) q[i__ + n2 * q_dim1]; 06823 if (ii < 0) { 06824 goto L170; 06825 } 06826 z__ = cu[(ii << 1) + 1]; 06827 goto L180; 06828 L170: 06829 iineg = -ii; 06830 z__ = cu[(iineg << 1) + 2]; 06831 L180: 06832 xsum += q[i__ + j * q_dim1] * z__; 06833 /* 180 XSUM = XSUM + Q(I,J)*Z */ 06834 /* L190: */ 06835 } 06836 q[klm1 + j * q_dim1] = xsum; 06837 /* L200: */ 06838 } 06839 i__1 = *n; 06840 for (j = js; j <= i__1; ++j) { 06841 ii = (long int) q[klm2 + j * q_dim1]; 06842 if (ii < 0) { 06843 goto L210; 06844 } 06845 z__ = cu[(ii << 1) + 1]; 06846 goto L220; 06847 L210: 06848 iineg = -ii; 06849 z__ = cu[(iineg << 1) + 2]; 06850 L220: 06851 q[klm1 + j * q_dim1] -= z__; 06852 /* L230: */ 06853 } 06854 /* DETERMINE THE VECTOR TO ENTER THE BASIS. */ 06855 L240: 06856 xmax = 0.f; 06857 if (js > *n) { 06858 goto L490; 06859 } 06860 i__1 = *n; 06861 for (j = js; j <= i__1; ++j) { 06862 zu = q[klm1 + j * q_dim1]; 06863 ii = (long int) q[klm2 + j * q_dim1]; 06864 if (ii > 0) { 06865 goto L250; 06866 } 06867 ii = -ii; 06868 zv = zu; 06869 zu = -zu - cu[(ii << 1) + 1] - cu[(ii << 1) + 2]; 06870 goto L260; 06871 L250: 06872 zv = -zu - cu[(ii << 1) + 1] - cu[(ii << 1) + 2]; 06873 L260: 06874 if (kforce == 1 && ii > *n) { 06875 goto L280; 06876 } 06877 if (iu[(ii << 1) + 1] == 1) { 06878 goto L270; 06879 } 06880 if (zu <= xmax) { 06881 goto L270; 06882 } 06883 xmax = zu; 06884 in = j; 06885 L270: 06886 if (iu[(ii << 1) + 2] == 1) { 06887 goto L280; 06888 } 06889 if (zv <= xmax) { 06890 goto L280; 06891 } 06892 xmax = zv; 06893 in = j; 06894 L280: 06895 ; 06896 } 06897 if (xmax <= toler) { 06898 goto L490; 06899 } 06900 if (q[klm1 + in * q_dim1] == xmax) { 06901 goto L300; 06902 } 06903 i__1 = klm2; 06904 for (i__ = 1; i__ <= i__1; ++i__) { 06905 q[i__ + in * q_dim1] = -q[i__ + in * q_dim1]; 06906 /* L290: */ 06907 } 06908 q[klm1 + in * q_dim1] = xmax; 06909 /* DETERMINE THE VECTOR TO LEAVE THE BASIS. */ 06910 L300: 06911 if (iphase == 1 || ia == 0) { 06912 goto L330; 06913 } 06914 xmax = 0.f; 06915 i__1 = ia; 06916 for (i__ = 1; i__ <= i__1; ++i__) { 06917 z__ = (d__1 = q[i__ + in * q_dim1], abs(d__1)); 06918 if (z__ <= xmax) { 06919 goto L310; 06920 } 06921 xmax = z__; 06922 iout = i__; 06923 L310: 06924 ; 06925 } 06926 if (xmax <= toler) { 06927 goto L330; 06928 } 06929 i__1 = n2; 06930 for (j = 1; j <= i__1; ++j) { 06931 z__ = q[ia + j * q_dim1]; 06932 q[ia + j * q_dim1] = q[iout + j * q_dim1]; 06933 q[iout + j * q_dim1] = z__; 06934 /* L320: */ 06935 } 06936 iout = ia; 06937 --ia; 06938 pivot = q[iout + in * q_dim1]; 06939 goto L420; 06940 L330: 06941 kk = 0; 06942 i__1 = klm; 06943 for (i__ = 1; i__ <= i__1; ++i__) { 06944 z__ = q[i__ + in * q_dim1]; 06945 if (z__ <= toler) { 06946 goto L340; 06947 } 06948 ++kk; 06949 res[kk] = q[i__ + n1 * q_dim1] / z__; 06950 s[kk] = (double) i__; 06951 L340: 06952 ; 06953 } 06954 L350: 06955 if (kk > 0) { 06956 goto L360; 06957 } 06958 kode = 2; 06959 goto L590; 06960 L360: 06961 xmin = static_cast<float>( res[1] ); 06962 iout = (long int) s[1]; 06963 j = 1; 06964 if (kk == 1) { 06965 goto L380; 06966 } 06967 i__1 = kk; 06968 for (i__ = 2; i__ <= i__1; ++i__) { 06969 if (res[i__] >= xmin) { 06970 goto L370; 06971 } 06972 j = i__; 06973 xmin = static_cast<float>( res[i__] ); 06974 iout = (long int) s[i__]; 06975 L370: 06976 ; 06977 } 06978 res[j] = res[kk]; 06979 s[j] = s[kk]; 06980 L380: 06981 --kk; 06982 pivot = q[iout + in * q_dim1]; 06983 ii = (long int) q[iout + n2 * q_dim1]; 06984 if (iphase == 1) { 06985 goto L400; 06986 } 06987 if (ii < 0) { 06988 goto L390; 06989 } 06990 if (iu[(ii << 1) + 2] == 1) { 06991 goto L420; 06992 } 06993 goto L400; 06994 L390: 06995 iineg = -ii; 06996 if (iu[(iineg << 1) + 1] == 1) { 06997 goto L420; 06998 } 06999 /* 400 II = IABS(II) */ 07000 L400: 07001 ii = abs(ii); 07002 cuv = cu[(ii << 1) + 1] + cu[(ii << 1) + 2]; 07003 if (q[klm1 + in * q_dim1] - pivot * cuv <= toler) { 07004 goto L420; 07005 } 07006 /* BYPASS INTERMEDIATE VERTICES. */ 07007 i__1 = n1; 07008 for (j = js; j <= i__1; ++j) { 07009 z__ = q[iout + j * q_dim1]; 07010 q[klm1 + j * q_dim1] -= z__ * cuv; 07011 q[iout + j * q_dim1] = -z__; 07012 /* L410: */ 07013 } 07014 q[iout + n2 * q_dim1] = -q[iout + n2 * q_dim1]; 07015 goto L350; 07016 /* GAUSS-JORDAN ELIMINATION. */ 07017 L420: 07018 if (iter < maxit) { 07019 goto L430; 07020 } 07021 kode = 3; 07022 goto L590; 07023 L430: 07024 ++iter; 07025 i__1 = n1; 07026 for (j = js; j <= i__1; ++j) { 07027 if (j != in) { 07028 q[iout + j * q_dim1] /= pivot; 07029 } 07030 /* L440: */ 07031 } 07032 /* IF PERMITTED, USE SUBROUTINE COL OF THE DESCRIPTION */ 07033 /* SECTION AND REPLACE THE FOLLOWING SEVEN STATEMENTS DOWN */ 07034 /* TO AND INCLUDING STATEMENT NUMBER 460 BY.. */ 07035 /* DO 460 J=JS,N1 */ 07036 /* IF(J .EQ. IN) GO TO 460 */ 07037 /* Z = -Q(IOUT,J) */ 07038 /* CALL COL(Q(1,J), Q(1,IN), Z, IOUT, KLM1) */ 07039 /* 460 CONTINUE */ 07040 i__1 = n1; 07041 for (j = js; j <= i__1; ++j) { 07042 if (j == in) { 07043 goto L460; 07044 } 07045 z__ = -q[iout + j * q_dim1]; 07046 i__2 = klm1; 07047 for (i__ = 1; i__ <= i__2; ++i__) { 07048 if (i__ != iout) { 07049 q[i__ + j * q_dim1] += z__ * q[i__ + in * q_dim1]; 07050 } 07051 /* L450: */ 07052 } 07053 L460: 07054 ; 07055 } 07056 tpivot = -pivot; 07057 i__1 = klm1; 07058 for (i__ = 1; i__ <= i__1; ++i__) { 07059 if (i__ != iout) { 07060 q[i__ + in * q_dim1] /= tpivot; 07061 } 07062 /* L470: */ 07063 } 07064 q[iout + in * q_dim1] = 1.f / pivot; 07065 z__ = q[iout + n2 * q_dim1]; 07066 q[iout + n2 * q_dim1] = q[klm2 + in * q_dim1]; 07067 q[klm2 + in * q_dim1] = z__; 07068 ii = (long int) abs(z__); 07069 if (iu[(ii << 1) + 1] == 0 || iu[(ii << 1) + 2] == 0) { 07070 goto L240; 07071 } 07072 i__1 = klm2; 07073 for (i__ = 1; i__ <= i__1; ++i__) { 07074 z__ = q[i__ + in * q_dim1]; 07075 q[i__ + in * q_dim1] = q[i__ + js * q_dim1]; 07076 q[i__ + js * q_dim1] = z__; 07077 /* L480: */ 07078 } 07079 ++js; 07080 goto L240; 07081 /* TEST FOR OPTIMALITY. */ 07082 L490: 07083 if (kforce == 0) { 07084 goto L580; 07085 } 07086 if (iphase == 1 && q[klm1 + n1 * q_dim1] <= toler) { 07087 goto L500; 07088 } 07089 kforce = 0; 07090 goto L240; 07091 /* SET UP PHASE 2 COSTS. */ 07092 L500: 07093 iphase = 2; 07094 i__1 = nklm; 07095 for (j = 1; j <= i__1; ++j) { 07096 cu[(j << 1) + 1] = 0.f; 07097 cu[(j << 1) + 2] = 0.f; 07098 /* L510: */ 07099 } 07100 i__1 = nk; 07101 for (j = n1; j <= i__1; ++j) { 07102 cu[(j << 1) + 1] = 1.f; 07103 cu[(j << 1) + 2] = 1.f; 07104 /* L520: */ 07105 } 07106 i__1 = klm; 07107 for (i__ = 1; i__ <= i__1; ++i__) { 07108 ii = (long int) q[i__ + n2 * q_dim1]; 07109 if (ii > 0) { 07110 goto L530; 07111 } 07112 ii = -ii; 07113 if (iu[(ii << 1) + 2] == 0) { 07114 goto L560; 07115 } 07116 cu[(ii << 1) + 2] = 0.f; 07117 goto L540; 07118 L530: 07119 if (iu[(ii << 1) + 1] == 0) { 07120 goto L560; 07121 } 07122 cu[(ii << 1) + 1] = 0.f; 07123 L540: 07124 ++ia; 07125 i__2 = n2; 07126 for (j = 1; j <= i__2; ++j) { 07127 z__ = q[ia + j * q_dim1]; 07128 q[ia + j * q_dim1] = q[i__ + j * q_dim1]; 07129 q[i__ + j * q_dim1] = z__; 07130 /* L550: */ 07131 } 07132 L560: 07133 ; 07134 } 07135 goto L160; 07136 L570: 07137 if (q[klm1 + n1 * q_dim1] <= toler) { 07138 goto L500; 07139 } 07140 kode = 1; 07141 goto L590; 07142 L580: 07143 if (iphase == 1) { 07144 goto L570; 07145 } 07146 /* PREPARE OUTPUT. */ 07147 kode = 0; 07148 L590: 07149 xsum = 0.; 07150 i__1 = *n; 07151 for (j = 1; j <= i__1; ++j) { 07152 x[j] = 0.f; 07153 /* L600: */ 07154 } 07155 i__1 = klm; 07156 for (i__ = 1; i__ <= i__1; ++i__) { 07157 res[i__] = 0.f; 07158 /* L610: */ 07159 } 07160 i__1 = klm; 07161 for (i__ = 1; i__ <= i__1; ++i__) { 07162 ii = (long int) q[i__ + n2 * q_dim1]; 07163 sn = 1.f; 07164 if (ii > 0) { 07165 goto L620; 07166 } 07167 ii = -ii; 07168 sn = -1.f; 07169 L620: 07170 if (ii > *n) { 07171 goto L630; 07172 } 07173 x[ii] = sn * q[i__ + n1 * q_dim1]; 07174 goto L640; 07175 L630: 07176 iimn = ii - *n; 07177 res[iimn] = sn * q[i__ + n1 * q_dim1]; 07178 if (ii >= n1 && ii <= nk) { 07179 xsum += q[i__ + n1 * q_dim1]; 07180 } 07181 L640: 07182 ; 07183 } 07184 error = (float)xsum; 07185 return; 07186 }
vector< float > Util::cluster_equalsize | ( | EMData * | d | ) | [static] |
Definition at line 20816 of file util_sparx.cpp.
References dm, EMAN::EMData::get_xsize(), nx, and sqrt().
20816 { 20817 // WORKS ONLY FOR NUMBER OF OBJECTS N=l^2 !! 20818 int nx = d->get_xsize(); 20819 int N = 1 + int((sqrt(1.0 + 8.0*nx)-1.0)/2.0); 20820 int K = N/2; 20821 vector<float> group(N); 20822 if(N*(N-1)/2 != nx) { 20823 //print " incorrect dimension" 20824 return group;} 20825 //bool active[N]; //this does not compile in VS2005. --Grant Tang 20826 bool * active = new bool[N]; 20827 for(int i=0; i<N; i++) active[i] = true; 20828 20829 float dm, qd; 20830 int ppi = 0, ppj = 0; 20831 for(int k=0; k<K; k++) { 20832 // find pairs of most similiar objects among active 20833 //cout<<" k "<<k<<endl; 20834 dm = 1.0e23f; 20835 for(int i=1; i<N; i++) { 20836 if(active[i]) { 20837 for(int j=0; j<i; j++) { 20838 if(active[j]) { 20839 qd = (*d)(i*(i - 1)/2 + j); 20840 if(qd < dm) { 20841 dm = qd; 20842 ppi = i; 20843 ppj = j; 20844 } 20845 } 20846 } 20847 } 20848 } 20849 group[2*k] = float(ppi); 20850 group[1+2*k] = float(ppj); 20851 active[ppi] = false; 20852 active[ppj] = false; 20853 } 20854 20855 delete [] active; 20856 active = NULL; 20857 return group; 20858 }
vector< float > Util::cluster_pairwise | ( | EMData * | d, | |
int | K, | |||
float | T, | |||
float | F | |||
) | [static] |
Definition at line 20608 of file util_sparx.cpp.
References assign, cent, dt, get_irand(), EMAN::EMData::get_xsize(), mono(), nx, q, and sqrt().
20608 { 20609 int nx = d->get_xsize(); 20610 int N = 1 + int((sqrt(1.0 + 8.0*nx)-1.0)/2.0); 20611 vector<float> out(N+K+2); 20612 if(N*(N-1)/2 != nx) { 20613 //print " incorrect dimension" 20614 return out;} 20615 // assign random objects as centers 20616 for(int i=0; i<N; i++) assign(i) = float(i); 20617 // shuffle 20618 for(int i=0; i<N; i++) { 20619 int j = Util::get_irand(0,N-1); 20620 float temp = assign(i); 20621 assign(i) = assign(j); 20622 assign(j) = temp; 20623 } 20624 for(int k=0; k<K; k++) cent(k) = float(assign(k)); 20625 //for(int k=0; k<K; k++) cout<<cent(k)<<" ";cout<<endl; 20626 // 20627 for(int i=0; i<N; i++) assign(i) = 0.0f; 20628 float qm, dispold = 1.1e22f, disp = 1.0e22f, na=0.0f; 20629 bool change = true; 20630 int it = -1; 20631 int ct = -1; 20632 while ((change && disp < dispold) || ct > 0) { 20633 20634 change = false; 20635 dispold = disp; 20636 it++; 20637 20638 // dispersion is a sum of distance from objects to object center 20639 disp = 0.0f; 20640 ct = 0; 20641 for(int i=0; i<N; i++) { 20642 qm = 1.0e23f; 20643 for(int k=0; k<K; k++) { 20644 if(float(i) == cent(k)) { 20645 qm = 0.0f; 20646 na = (float)k; 20647 } else { 20648 float dt = (*d)(mono(i,int(cent(k)))); 20649 if(dt < qm) { 20650 qm = dt; 20651 na = (float)k; 20652 } 20653 } 20654 } 20655 20656 20657 // Simulated annealing 20658 if(exp(-1.0/float(T)) > Util::get_irand(1,1000)/1000.0) { 20659 na = (float)(Util::get_irand(0, K)); 20660 qm = (*d)(mono(i,int(na))); 20661 ct++; 20662 } 20663 20664 disp += qm; 20665 20666 if(na != assign(i)) { 20667 assign(i) = na; 20668 change = true; 20669 } 20670 } 20671 20672 //cout<<"Iteration: "<<it<< " disp " <<disp << " T " << T << " disturb " << ct << endl; 20673 T = T*F; 20674 20675 //for(int k=0; k<N; k++) cout<<assign(k)<<" ";cout<<endl; 20676 //print disp 20677 //print assign 20678 // find centers 20679 for(int k=0; k<K; k++) { 20680 qm = 1.0e23f; 20681 for(int i=0; i<N; i++) { 20682 if(assign(i) == float(k)) { 20683 float q = 0.0; 20684 for(int j=0; j<N; j++) { 20685 if(assign(j) == float(k)) { 20686 //it cannot be the same object 20687 if(i != j) q += (*d)(mono(i,j)); 20688 //cout<<q<<" "<<i<<" "<<j<<" "<<k<<endl;} 20689 } 20690 } 20691 if(q < qm) { 20692 //cout<<qm<<" "<<q<<" "<<i<<" "<<k<<endl; 20693 qm = q; 20694 cent(k) = float(i); 20695 } 20696 } 20697 } 20698 } 20699 //for(int k=0; k<K; k++) cout<<cent(k)<<" ";cout<<endl;cout<<disp<<endl; 20700 } 20701 out[N+K] = disp; 20702 out[N+K+1] = float(it); 20703 return out; 20704 }
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 4976 of file util_sparx.cpp.
04976 { 04977 double res = 0; 04978 double buf = 0; 04979 float* line_1; 04980 float* line_2; 04981 int i, n, ind; 04982 int lnlen = data[0]->get_xsize(); 04983 for (n=0; n<n_lines; ++n) { 04984 ind = n*2; 04985 line_1 = data[seq[ind]]->get_data() + com[ind] * lnlen; 04986 line_2 = data[seq[ind+1]]->get_data() + com[ind+1] *lnlen; 04987 buf = 0; 04988 for (i=0; i<lnlen; ++i) { 04989 buf += (line_1[i]-line_2[i])*(line_1[i]-line_2[i]); 04990 } 04991 res += buf * weights[n]; 04992 } 04993 04994 return res; 04995 04996 }
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 4753 of file util_sparx.cpp.
References deg_rad.
04753 { 04754 int nb_ori = Ori.size() / 4; 04755 int i, ind; 04756 float ph, th, ps; 04757 double cph, cth, cps, sph, sth, sps; 04758 vector<double> Rot(nb_ori*9); 04759 for (i=0; i<nb_ori; ++i){ 04760 ind = i*4; 04761 // spider convention phi=psi-90, psi=phi+90 04762 ph = Ori[ind+2]-90; 04763 th = Ori[ind+1]; 04764 ps = Ori[ind]+90; 04765 ph *= deg_rad; 04766 th *= deg_rad; 04767 ps *= deg_rad; 04768 // pre-calculate some trigo stuffs 04769 cph = cos(ph); 04770 cth = cos(th); 04771 cps = cos(ps); 04772 sph = sin(ph); 04773 sth = sin(th); 04774 sps = sin(ps); 04775 // fill rotation matrix 04776 ind = i*9; 04777 Rot[ind] = cph*cps-cth*sps*sph; 04778 Rot[ind+1] = cph*sps+cth*cps*sph; 04779 Rot[ind+2] = sth*sph; 04780 Rot[ind+3] = -sph*cps-cth*sps*cph; 04781 Rot[ind+4] = -sph*sps+cth*cps*cph; 04782 Rot[ind+5] = sth*cph; 04783 Rot[ind+6] = sth*sps; 04784 Rot[ind+7] = -sth*cps; 04785 Rot[ind+8] = cth; 04786 } 04787 04788 return Rot; 04789 }
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 4921 of file util_sparx.cpp.
References deg_rad, norm(), nx, ny, rad_deg, and sqrt().
04921 { 04922 // seq is the pairwise index ij: 0, 1, 0, 2, 0, 3, 1, 2, 1, 3, 2, 3 04923 vector<double> cml(2*nlines); // [phi, theta] / line 04924 float ph1, th1; 04925 float ph2, th2; 04926 double nx, ny, nz; 04927 double norm; 04928 double sth1=0, sph1=0, cth1=0, cph1=0; 04929 double sth2, sph2, cth2, cph2; 04930 int l, ind, c; 04931 int mem = -1; 04932 for (l=0; l<nlines; ++l){ 04933 c = 2*l; 04934 if (seq[c]!=mem){ 04935 mem = seq[c]; 04936 ind = 4*seq[c]; 04937 ph1 = Ori[ind]*deg_rad; 04938 th1 = Ori[ind+1]*deg_rad; 04939 sth1 = sin(th1); 04940 sph1 = sin(ph1); 04941 cth1 = cos(th1); 04942 cph1 = cos(ph1); 04943 } 04944 ind = 4*seq[c+1]; 04945 ph2 = Ori[ind]*deg_rad; 04946 th2 = Ori[ind+1]*deg_rad; 04947 sth2 = sin(th2); 04948 cth2 = cos(th2); 04949 sph2 = sin(ph2); 04950 cph2 = cos(ph2); 04951 // cross product 04952 nx = sth1*cph1*cth2 - cth1*sth2*cph2; 04953 ny = cth1*sth2*sph2 - cth2*sth1*sph1; 04954 nz = sth1*sph1*sth2*cph2 - sth1*cph1*sth2*sph2; 04955 norm = sqrt(nx*nx+ny*ny+nz*nz); 04956 nx /= norm; 04957 ny /= norm; 04958 nz /= norm; 04959 // apply mirror if need 04960 if (nz<0) {nx=-nx; ny=-ny; nz=-nz;} 04961 // compute theta and phi 04962 cml[c+1] = acos(nz); 04963 if (cml[c+1] == 0) {cml[c] = 0;} 04964 else { 04965 cml[c+1] *= rad_deg; 04966 if (cml[c+1] > 89.99) {cml[c+1] = 89.99;} // this fix some pb in Voronoi 04967 cml[c] = rad_deg * atan2(nx, ny); 04968 cml[c] = fmod(360 + cml[c], 360); 04969 04970 } 04971 } 04972 04973 return cml; 04974 }
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 4822 of file util_sparx.cpp.
References abs, b, nint180(), and rad_deg.
04822 { 04823 vector<int> com(2*(n_prj - 1)); 04824 int a = i_prj*9; 04825 int i, b, c; 04826 int n1=0, n2=0; 04827 float vmax = 1 - 1.0e-6f; 04828 double r11, r12, r13, r23, r31, r32, r33; 04829 04830 c = 0; 04831 for (i=0; i<n_prj; ++i){ 04832 if (i!=i_prj){ 04833 b = i*9; 04834 // this is equivalent to R = A*B' 04835 r11 = Rot[a]*Rot[b]+Rot[a+1]*Rot[b+1]+Rot[a+2]*Rot[b+2]; 04836 r12 = Rot[a]*Rot[b+3]+Rot[a+1]*Rot[b+4]+Rot[a+2]*Rot[b+5]; 04837 r13 = Rot[a]*Rot[b+6]+Rot[a+1]*Rot[b+7]+Rot[a+2]*Rot[b+8]; 04838 r23 = Rot[a+3]*Rot[b+6]+Rot[a+4]*Rot[b+7]+Rot[a+5]*Rot[b+8]; 04839 r31 = Rot[a+6]*Rot[b]+Rot[a+7]*Rot[b+1]+Rot[a+8]*Rot[b+2]; 04840 r32 = Rot[a+6]*Rot[b+3]+Rot[a+7]*Rot[b+4]+Rot[a+8]*Rot[b+5]; 04841 r33 = Rot[a+6]*Rot[b+6]+Rot[a+7]*Rot[b+7]+Rot[a+8]*Rot[b+8]; 04842 if (r33 > vmax) { 04843 n2 = 270; 04844 n1 = 270 + nint180((float)(rad_deg*atan2(r12, r11))); 04845 } 04846 else if (r33 < -vmax) { 04847 n2 = 270; 04848 n1 = 270 - nint180((float)(rad_deg*atan2(r12, r11))); 04849 } else { 04850 n2 = nint180((float)(rad_deg*atan2(r31, -r32))); 04851 n1 = nint180((float)(rad_deg*atan2(r13, r23))); 04852 if (n1 < 0) {n1 += 360;} 04853 if (n2 <= 0) {n2 = abs(n2);} 04854 else {n2 = 360 - n2;} 04855 } 04856 04857 if (n1 >= 360){n1 = n1 % 360;} 04858 if (n2 >= 360){n2 = n2 % 360;} 04859 04860 // store common-lines 04861 b = c*2; 04862 com[b] = n1; 04863 com[b+1] = n2; 04864 ++c; 04865 } 04866 } 04867 04868 return com; 04869 04870 }
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 4872 of file util_sparx.cpp.
References abs, b, nint180(), and rad_deg.
04872 { 04873 vector<int> com(2*n_lines); 04874 int a=0, b, c, l; 04875 int n1=0, n2=0, mem=-1; 04876 float vmax = 1 - 1.0e-6f; 04877 double r11, r12, r13, r23, r31, r32, r33; 04878 c = 0; 04879 for (l=0; l<n_lines; ++l){ 04880 c = 2*l; 04881 if (seq[c]!=mem){ 04882 mem = seq[c]; 04883 a = seq[c]*9; 04884 } 04885 b = seq[c+1]*9; 04886 04887 // this is equivalent to R = A*B' 04888 r11 = Rot[a]*Rot[b]+Rot[a+1]*Rot[b+1]+Rot[a+2]*Rot[b+2]; 04889 r12 = Rot[a]*Rot[b+3]+Rot[a+1]*Rot[b+4]+Rot[a+2]*Rot[b+5]; 04890 r13 = Rot[a]*Rot[b+6]+Rot[a+1]*Rot[b+7]+Rot[a+2]*Rot[b+8]; 04891 r23 = Rot[a+3]*Rot[b+6]+Rot[a+4]*Rot[b+7]+Rot[a+5]*Rot[b+8]; 04892 r31 = Rot[a+6]*Rot[b]+Rot[a+7]*Rot[b+1]+Rot[a+8]*Rot[b+2]; 04893 r32 = Rot[a+6]*Rot[b+3]+Rot[a+7]*Rot[b+4]+Rot[a+8]*Rot[b+5]; 04894 r33 = Rot[a+6]*Rot[b+6]+Rot[a+7]*Rot[b+7]+Rot[a+8]*Rot[b+8]; 04895 if (r33 > vmax) { 04896 n2 = 270; 04897 n1 = 270 + nint180((float)(rad_deg*atan2(r12, r11))); 04898 } 04899 else if (r33 < -vmax) { 04900 n2 = 270; 04901 n1 = 270 - nint180((float)(rad_deg*atan2(r12, r11))); 04902 } else { 04903 n2 = nint180((float)(rad_deg*atan2(r31, -r32))); 04904 n1 = nint180((float)(rad_deg*atan2(r13, r23))); 04905 if (n1 < 0) {n1 += 360;} 04906 if (n2 <= 0) {n2 = abs(n2);} 04907 else {n2 = 360 - n2;} 04908 } 04909 if (n1 >= 360){n1 = n1 % 360;} 04910 if (n2 >= 360){n2 = n2 % 360;} 04911 04912 // store common-lines 04913 com[c] = n1; 04914 com[c+1] = n2; 04915 } 04916 04917 return com; 04918 04919 }
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 4735 of file util_sparx.cpp.
References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), nx, and EMAN::EMData::update().
04735 { 04736 int j; 04737 int nx = sino->get_xsize(); 04738 int i = nx * pos_line; 04739 float r1, r2; 04740 float *line_ptr = line->get_data(); 04741 float *sino_ptr = sino->get_data(); 04742 for (j=ilf;j<=ihf; j += 2) { 04743 r1 = line_ptr[j]; 04744 r2 = line_ptr[j + 1]; 04745 sino_ptr[i + j - ilf] = r1; 04746 sino_ptr[i + j - ilf + 1] = r2; 04747 sino_ptr[i + nx * nblines + j - ilf] = r1; 04748 sino_ptr[i + nx * nblines + j - ilf + 1] = -r2; 04749 } 04750 sino->update(); 04751 }
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 4998 of file util_sparx.cpp.
04999 { 05000 // res: [best_disc, best_ipsi] 05001 // seq: pairwise indexes ij, 0, 1, 0, 2, 0, 3, 1, 2, 1, 3, 2, 3 05002 // iw : index to know where is the weight for the common-lines on the current projection in the all weights, [12, 4, 2, 7] 05003 vector<double> res(2); 05004 int lnlen = data[0]->get_xsize(); 05005 int end = 2*(n_prj-1); 05006 double disc, buf, bdisc, tmp; 05007 int n, i, ipsi, ind, bipsi, c; 05008 float* line_1; 05009 float* line_2; 05010 bdisc = 1.0e6; 05011 bipsi = -1; 05012 // loop psi 05013 for(ipsi=0; ipsi<n_psi; ipsi += d_psi) { 05014 // discrepancy 05015 disc = 0; 05016 c = 0; 05017 for (n=0; n<n_prj; ++n) { 05018 if(n!=iprj) { 05019 ind = 2*c; 05020 line_1 = data[iprj]->get_data() + com[ind] * lnlen; 05021 line_2 = data[n]->get_data() + com[ind+1] * lnlen; 05022 buf = 0; 05023 for (i=0; i<lnlen; ++i) { 05024 tmp = line_1[i]-line_2[i]; 05025 buf += tmp*tmp; 05026 } 05027 disc += buf * weights[iw[c]]; 05028 ++c; 05029 } 05030 } 05031 // select the best value 05032 if (disc <= bdisc) { 05033 bdisc = disc; 05034 bipsi = ipsi; 05035 } 05036 // update common-lines 05037 for (i=0; i<end; i+=2){ 05038 com[i] += d_psi; 05039 if (com[i] >= n_psi) com[i] = com[i] - n_psi; 05040 } 05041 } 05042 res[0] = bdisc; 05043 res[1] = float(bipsi); 05044 05045 return res; 05046 }
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 5048 of file util_sparx.cpp.
05049 { 05050 // res: [best_disc, best_ipsi] 05051 // seq: pairwise indexes ij, 0, 1, 0, 2, 0, 3, 1, 2, 1, 3, 2, 3 05052 // iw : index to know where is the weight for the common-lines on the current projection in the all weights, [12, 4, 2, 7] 05053 vector<double> res(2); 05054 int lnlen = data[0]->get_xsize(); 05055 int end = 2*(n_prj-1); 05056 double disc, buf, bdisc, tmp; 05057 int n, i, ipsi, ind, bipsi, c; 05058 float* line_1; 05059 float* line_2; 05060 bdisc = 1.0e6; 05061 bipsi = -1; 05062 // loop psi 05063 for(ipsi=0; ipsi<n_psi; ipsi += d_psi) { 05064 // discrepancy 05065 disc = 0; 05066 c = 0; 05067 for (n=0; n<n_prj; ++n) { 05068 if(n!=iprj) { 05069 ind = 2*c; 05070 line_1 = data[iprj]->get_data() + com[ind] * lnlen; 05071 line_2 = data[n]->get_data() + com[ind+1] * lnlen; 05072 buf = 0; 05073 for (i=0; i<lnlen; ++i) { 05074 tmp = line_1[i]-line_2[i]; 05075 buf += tmp*tmp; 05076 } 05077 disc += buf; 05078 ++c; 05079 } 05080 } 05081 // select the best value 05082 if (disc <= bdisc) { 05083 bdisc = disc; 05084 bipsi = ipsi; 05085 } 05086 // update common-lines 05087 for (i=0; i<end; i+=2){ 05088 com[i] += d_psi; 05089 if (com[i] >= n_psi) com[i] = com[i] - n_psi; 05090 } 05091 } 05092 res[0] = bdisc; 05093 res[1] = float(bipsi); 05094 05095 return res; 05096 }
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 4791 of file util_sparx.cpp.
References deg_rad.
04791 { 04792 float ph, ps; 04793 double cph, cth, cps, sph, sth, sps; 04794 int ind = iprj*9; 04795 // spider convention phi=psi-90, psi=phi+90 04796 ph = nps-90; 04797 ps = nph+90; 04798 ph *= deg_rad; 04799 th *= deg_rad; 04800 ps *= deg_rad; 04801 // pre-calculate some trigo stuffs 04802 cph = cos(ph); 04803 cth = cos(th); 04804 cps = cos(ps); 04805 sph = sin(ph); 04806 sth = sin(th); 04807 sps = sin(ps); 04808 // fill rotation matrix 04809 Rot[ind] = (float)(cph*cps-cth*sps*sph); 04810 Rot[ind+1] = (float)(cph*sps+cth*cps*sph); 04811 Rot[ind+2] = (float)(sth*sph); 04812 Rot[ind+3] = (float)(-sph*cps-cth*sps*cph); 04813 Rot[ind+4] = (float)(-sph*sps+cth*cps*cph); 04814 Rot[ind+5] = (float)(sth*cph); 04815 Rot[ind+6] = (float)(sth*sps); 04816 Rot[ind+7] = (float)(-sth*cps); 04817 Rot[ind+8] = (float)(cth); 04818 04819 return Rot; 04820 }
vector< double > Util::cml_weights | ( | const vector< float > & | cml | ) | [static] |
Definition at line 4645 of file util_sparx.cpp.
References Assert, PI2, and vrdg().
04645 { 04646 static const int NBIN = 100; 04647 int nline=cml.size()/2; 04648 vector<double> weights(nline); 04649 04650 vector<ori_t> angs(nline); 04651 for( int i=0; i < nline; ++i ) { 04652 angs[i].iphi = int( NBIN*cml[2*i] ); 04653 angs[i].itht = int( NBIN*cml[2*i+1] ); 04654 if( angs[i].itht == 180*NBIN ) angs[i].itht = 0; 04655 angs[i].id = i; 04656 } 04657 04658 //std::cout << "# of angs: " << angs.size() << std::endl; 04659 04660 std::sort( angs.begin(), angs.end(), cmpang() ); 04661 04662 vector<float> newphi; 04663 vector<float> newtht; 04664 vector< vector<int> > indices; 04665 04666 int curt_iphi = -1; 04667 int curt_itht = -1; 04668 for(unsigned int i=0 ;i < angs.size(); ++i ) { 04669 if( angs[i].iphi==curt_iphi && angs[i].itht==curt_itht ) { 04670 Assert( indices.size() > 0 ); 04671 indices.back().push_back(angs[i].id); 04672 } else { 04673 curt_iphi = angs[i].iphi; 04674 curt_itht = angs[i].itht; 04675 04676 newphi.push_back( float(curt_iphi)/NBIN ); 04677 newtht.push_back( float(curt_itht)/NBIN ); 04678 indices.push_back( vector<int>(1,angs[i].id) ); 04679 } 04680 } 04681 04682 //std::cout << "# of indpendent ang: " << newphi.size() << std::endl; 04683 04684 04685 int num_agl = newphi.size(); 04686 04687 if(num_agl>2) { 04688 vector<double> w=Util::vrdg(newphi, newtht); 04689 04690 Assert( w.size()==newphi.size() ); 04691 Assert( indices.size()==newphi.size() ); 04692 04693 for(unsigned int i=0; i < newphi.size(); ++i ) { 04694 /* 04695 std::cout << "phi,tht,w,n: "; 04696 std::cout << boost::format( "%10.3f" ) % newphi[i] << " "; 04697 std::cout << boost::format( "%10.3f" ) % newtht[i] << " "; 04698 std::cout << boost::format( "%8.6f" ) % w[i] << " "; 04699 std::cout << indices[i].size() << "("; 04700 */ 04701 04702 for(unsigned int j=0; j < indices[i].size(); ++j ) { 04703 int id = indices[i][j]; 04704 weights[id] = w[i]/indices[i].size(); 04705 //std::cout << id << " "; 04706 } 04707 04708 //std::cout << ")" << std::endl; 04709 04710 } 04711 } else { 04712 cout<<"warning in Util.cml_weights"<<endl; 04713 double val = PI2/float(nline); 04714 for(int i=0; i<nline; i++) weights[i]=val; 04715 } 04716 04717 return weights; 04718 04719 }
Definition at line 7324 of file util_sparx.cpp.
References EMAN::Util::tmpstruct::theta1.
Referenced by hsortd().
Definition at line 7329 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 5456 of file util_sparx.cpp.
Referenced by cyclicshift(), and slicereverse().
05456 { 05457 float* tmp = new float[nx]; 05458 int n = (end - beg)/nx; 05459 int nhalf = n/2; 05460 for (int i = 0; i < nhalf; i++) { 05461 // swap col i and col n-1-i 05462 memcpy(tmp, beg+i*nx, nx*sizeof(float)); 05463 memcpy(beg+i*nx, beg+(n-1-i)*nx, nx*sizeof(float)); 05464 memcpy(beg+(n-1-i)*nx, tmp, nx*sizeof(float)); 05465 } 05466 delete[] tmp; 05467 }
Definition at line 6207 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().
06208 { 06209 /*********** 06210 ***get the size of the image for validation purpose 06211 **************/ 06212 int nx = image->get_xsize(),ny = image->get_ysize(),nz = image->get_zsize(); //Aren't these implied? Please check and let me know, PAP. 06213 /******** 06214 ***Exception Handle 06215 *************/ 06216 if(nx != mask->get_xsize() || ny != mask->get_ysize() || nz != mask->get_zsize()) 06217 throw ImageDimensionException("The dimension of the image does not match the dimension of the mask!"); 06218 06219 size_t i, size = (size_t)nx*ny*nz; 06220 06221 float* img_ptr = image->get_data(); 06222 float* mask_ptr = mask->get_data(); 06223 06224 int ln=0; //length of the output image = number of points under the mask. 06225 for(i = 0;i < size;i++) if(mask_ptr[i] > 0.5f) ln++; 06226 06227 EMData* new_image = new EMData(); 06228 new_image->set_size(ln,1,1); /* set size of the new image */ 06229 float *new_ptr = new_image->get_data(); 06230 06231 ln=-1; 06232 for(i = 0;i < size;i++){ 06233 if(mask_ptr[i] > 0.5f) { 06234 ln++; 06235 new_ptr[ln]=img_ptr[i]; 06236 } 06237 } 06238 06239 return new_image; 06240 }
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 6336 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, and ssyev_().
06337 { 06338 // n size of the covariance/correlation matrix 06339 // covmat --- covariance/correlation matrix (n by n) 06340 // eigval --- returns eigenvalues 06341 // eigvec --- returns eigenvectors 06342 06343 ENTERFUNC; 06344 06345 int i; 06346 06347 // make a copy of covmat so that it will not be overwritten 06348 for ( i = 0 ; i < n * n ; i++ ) eigvec[i] = covmat[i]; 06349 06350 char NEEDV = 'V'; 06351 char UPLO = 'U'; 06352 int lwork = -1; 06353 int info = 0; 06354 float *work, wsize; 06355 06356 // query to get optimal workspace 06357 ssyev_(&NEEDV, &UPLO, &n, eigvec, &n, eigval, &wsize, &lwork, &info); 06358 lwork = (int)wsize; 06359 06360 work = (float *)calloc(lwork, sizeof(float)); 06361 // calculate eigs 06362 ssyev_(&NEEDV, &UPLO, &n, eigvec, &n, eigval, work, &lwork, &info); 06363 free(work); 06364 EXITFUNC; 06365 return info; 06366 }
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 6368 of file util_sparx.cpp.
References coveig(), covmat, eigval, eigvec, ENTERFUNC, EXITFUNC, and status.
06369 { 06370 06371 ENTERFUNC; 06372 int len = covmatpy.size(); 06373 float *eigvec; 06374 float *eigval; 06375 float *covmat; 06376 int status = 0; 06377 eigval = (float*)calloc(ncov,sizeof(float)); 06378 eigvec = (float*)calloc(ncov*ncov,sizeof(float)); 06379 covmat = (float*)calloc(ncov*ncov, sizeof(float)); 06380 06381 const float *covmat_ptr; 06382 covmat_ptr = &covmatpy[0]; 06383 for(int i=0;i<len;i++){ 06384 covmat[i] = covmat_ptr[i]; 06385 } 06386 06387 status = Util::coveig(ncov, covmat, eigval, eigvec); 06388 06389 vector<float> eigval_py(ncov); 06390 const float *eigval_ptr; 06391 eigval_ptr = &eigval[0]; 06392 for(int i=0;i<ncov;i++){ 06393 eigval_py[i] = eigval_ptr[i]; 06394 } 06395 06396 vector<float> eigvec_py(ncov*ncov); 06397 const float *eigvec_ptr; 06398 eigvec_ptr = &eigvec[0]; 06399 for(int i=0;i<ncov*ncov;i++){ 06400 eigvec_py[i] = eigvec_ptr[i]; 06401 } 06402 06403 Dict res; 06404 res["eigval"] = eigval_py; 06405 res["eigvec"] = eigvec_py; 06406 06407 EXITFUNC; 06408 return res; 06409 }
Definition at line 3194 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.
03194 { 03195 // neg = 0 straight, neg = 1 mirrored 03196 int nring = numr.size()/3; 03197 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03198 int maxrin = numr[numr.size()-1]; 03199 double qn; float tot; 03200 float *circ1 = circ1p->get_data(); 03201 float *circ2 = circ2p->get_data(); 03202 /* 03203 c checks single position, neg is flag for checking mirrored position 03204 c 03205 c input - fourier transforms of rings! 03206 c first set is conjugated (mirrored) if neg 03207 c circ1 already multiplied by weights! 03208 c automatic arrays 03209 dimension t(maxrin) removed +2 as it is only needed for other ffts 03210 double precision q(maxrin) 03211 double precision t7(-3:3) 03212 */ 03213 float *t; 03214 double t7[7], *q; 03215 int i, j, k, ip, jc, numr3i, numr2i, jtot = 0; 03216 float pos; 03217 03218 #ifdef _WIN32 03219 ip = -(int)(log((float)maxrin)/log(2.0f)); 03220 #else 03221 ip = -(int) (log2(maxrin)); 03222 #endif //_WIN32 03223 03224 q = (double*)calloc(maxrin, sizeof(double)); 03225 t = (float*)calloc(maxrin, sizeof(float)); 03226 03227 // cout << *qn <<" " <<*tot<<" "<<ip<<endl; 03228 for (i=1; i<=nring; i++) { 03229 numr3i = numr(3,i); 03230 numr2i = numr(2,i); 03231 03232 t(1) = (circ1(numr2i)) * circ2(numr2i); 03233 03234 if (numr3i != maxrin) { 03235 // test .ne. first for speed on some compilers 03236 t(numr3i+1) = circ1(numr2i+1) * circ2(numr2i+1); 03237 t(2) = 0.0; 03238 03239 if (neg) { 03240 // first set is conjugated (mirrored) 03241 for (j=3;j<=numr3i;j=j+2) { 03242 jc = j+numr2i-1; 03243 t(j) =(circ1(jc))*circ2(jc)-(circ1(jc+1))*circ2(jc+1); 03244 t(j+1) = -(circ1(jc))*circ2(jc+1)-(circ1(jc+1))*circ2(jc); 03245 } 03246 } else { 03247 for (j=3;j<=numr3i;j=j+2) { 03248 jc = j+numr2i-1; 03249 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1); 03250 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc); 03251 } 03252 } 03253 for (j=1;j<=numr3i+1;j++) q(j) = q(j) + t(j); 03254 } else { 03255 t(2) = circ1(numr2i+1) * circ2(numr2i+1); 03256 if (neg) { 03257 // first set is conjugated (mirrored) 03258 for (j=3;j<=maxrin;j=j+2) { 03259 jc = j+numr2i-1; 03260 t(j) = (circ1(jc))*circ2(jc) - (circ1(jc+1))*circ2(jc+1); 03261 t(j+1) = -(circ1(jc))*circ2(jc+1) - (circ1(jc+1))*circ2(jc); 03262 } 03263 } else { 03264 for (j=3;j<=maxrin;j=j+2) { 03265 jc = j+numr2i-1; 03266 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1); 03267 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc); 03268 } 03269 } 03270 for (j = 1; j <= maxrin; j++) q(j) += t(j); 03271 } 03272 } 03273 03274 fftr_d(q,ip); 03275 03276 qn = -1.0e20; 03277 for (j=1;j<=maxrin;j++) { 03278 if (q(j) >= qn) { 03279 qn = q(j); jtot = j; 03280 } 03281 } 03282 03283 for (k=-3; k<=3; k++) { 03284 j = (jtot+k+maxrin-1)%maxrin + 1; 03285 t7(k+4) = q(j); 03286 } 03287 03288 prb1d(t7,7,&pos); 03289 03290 tot = (float)jtot + pos; 03291 03292 if (q) free(q); 03293 if (t) free(t); 03294 03295 Dict retvals; 03296 retvals["qn"] = qn; 03297 retvals["tot"] = tot; 03298 return retvals; 03299 }
Dict Util::Crosrng_ew | ( | EMData * | circ1, | |
EMData * | circ2, | |||
vector< int > | numr, | |||
vector< float > | w, | |||
int | neg | |||
) | [static] |
Definition at line 3301 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.
03301 { 03302 // neg = 0 straight, neg = 1 mirrored 03303 int nring = numr.size()/3; 03304 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03305 int maxrin = numr[numr.size()-1]; 03306 double qn; float tot; 03307 float *circ1 = circ1p->get_data(); 03308 float *circ2 = circ2p->get_data(); 03309 /* 03310 c checks single position, neg is flag for checking mirrored position 03311 c 03312 c input - fourier transforms of rings! 03313 c first set is conjugated (mirrored) if neg 03314 c multiplication by weights! 03315 c automatic arrays 03316 dimension t(maxrin) removed +2 as it is only needed for other ffts 03317 double precision q(maxrin) 03318 double precision t7(-3:3) 03319 */ 03320 float *t; 03321 double t7[7], *q; 03322 int i, j, k, ip, jc, numr3i, numr2i, jtot = 0; 03323 float pos; 03324 03325 #ifdef _WIN32 03326 ip = -(int)(log((float)maxrin)/log(2.0f)); 03327 #else 03328 ip = -(int) (log2(maxrin)); 03329 #endif //_WIN32 03330 03331 q = (double*)calloc(maxrin, sizeof(double)); 03332 t = (float*)calloc(maxrin, sizeof(float)); 03333 03334 // cout << *qn <<" " <<*tot<<" "<<ip<<endl; 03335 for (i=1;i<=nring;i++) { 03336 numr3i = numr(3,i); 03337 numr2i = numr(2,i); 03338 03339 t(1) = circ1(numr2i) * circ2(numr2i); 03340 03341 if (numr3i != maxrin) { 03342 // test .ne. first for speed on some compilers 03343 t(numr3i+1) = circ1(numr2i+1) * circ2(numr2i+1); 03344 t(2) = 0.0; 03345 03346 if (neg) { 03347 // first set is conjugated (mirrored) 03348 for (j=3; j<=numr3i; j=j+2) { 03349 jc = j+numr2i-1; 03350 t(j) = (circ1(jc))*circ2(jc)-(circ1(jc+1))*circ2(jc+1); 03351 t(j+1) = -(circ1(jc))*circ2(jc+1)-(circ1(jc+1))*circ2(jc); 03352 } 03353 } else { 03354 for (j=3; j<=numr3i; j=j+2) { 03355 jc = j+numr2i-1; 03356 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1); 03357 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc); 03358 } 03359 } 03360 for (j=1;j<=numr3i+1;j++) q(j) += t(j)*w[i-1]; 03361 } else { 03362 t(2) = circ1(numr2i+1) * circ2(numr2i+1); 03363 if (neg) { 03364 // first set is conjugated (mirrored) 03365 for (j=3; j<=maxrin; j=j+2) { 03366 jc = j+numr2i-1; 03367 t(j) = (circ1(jc))*circ2(jc) - (circ1(jc+1))*circ2(jc+1); 03368 t(j+1) = -(circ1(jc))*circ2(jc+1) - (circ1(jc+1))*circ2(jc); 03369 } 03370 } else { 03371 for (j=3; j<=maxrin; j=j+2) { 03372 jc = j+numr2i-1; 03373 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1); 03374 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc); 03375 } 03376 } 03377 for (j = 1; j <= maxrin; j++) q(j) += t(j)*w[i-1]; 03378 } 03379 } 03380 03381 fftr_d(q,ip); 03382 03383 qn = -1.0e20; 03384 for (j=1;j<=maxrin;j++) { 03385 //cout << j << " " << q(j) << endl; 03386 if (q(j) >= qn) { 03387 qn = q(j); 03388 jtot = j; 03389 } 03390 } 03391 03392 for (k=-3; k<=3; k++) { 03393 j = (jtot+k+maxrin-1)%maxrin + 1; 03394 t7(k+4) = q(j); 03395 } 03396 03397 prb1d(t7,7,&pos); 03398 03399 tot = (float)jtot + pos; 03400 03401 //if (q) free(q); 03402 if (t) free(t); 03403 03404 Dict retvals; 03405 //tot = 1; 03406 //qn = q(1); 03407 retvals["qn"] = qn; 03408 retvals["tot"] = tot; 03409 03410 if (q) free(q); 03411 03412 return retvals; 03413 }
Definition at line 3415 of file util_sparx.cpp.
References circ1, circ2, fftr_d(), EMAN::EMData::get_data(), log(), numr, prb1d(), q, EMAN::Dict::size(), t, t7, tmt, and tot.
Referenced by multiref_polar_ali_2d(), multiref_polar_ali_2d_local(), and multiref_polar_ali_2d_peaklist().
03415 { 03416 int nring = numr.size()/3; 03417 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03418 int maxrin = numr[numr.size()-1]; 03419 double qn; float tot; double qm; float tmt; 03420 float *circ1 = circ1p->get_data(); 03421 float *circ2 = circ2p->get_data(); 03422 /* 03423 c 03424 c checks both straight & mirrored positions 03425 c 03426 c input - fourier transforms of rings!! 03427 c circ1 already multiplied by weights! 03428 c 03429 */ 03430 03431 // dimension circ1(lcirc),circ2(lcirc) 03432 03433 // t(maxrin), q(maxrin), t7(-3:3) //maxrin+2 removed 03434 double *t, *q, t7[7]; 03435 03436 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 03437 float t1, t2, t3, t4, c1, c2, d1, d2, pos; 03438 03439 qn = 0.0f; 03440 qm = 0.0f; 03441 tot = 0.0f; 03442 tmt = 0.0f; 03443 #ifdef _WIN32 03444 ip = -(int)(log((float)maxrin)/log(2.0f)); 03445 #else 03446 ip = -(int)(log2(maxrin)); 03447 #endif //_WIN32 03448 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl; 03449 03450 // c - straight = circ1 * conjg(circ2) 03451 // zero q array 03452 03453 q = (double*)calloc(maxrin,sizeof(double)); 03454 03455 // t - mirrored = conjg(circ1) * conjg(circ2) 03456 // zero t array 03457 t = (double*)calloc(maxrin,sizeof(double)); 03458 03459 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03460 for (i=1; i<=nring; i++) { 03461 03462 numr3i = numr(3,i); // Number of samples of this ring 03463 numr2i = numr(2,i); // The beginning point of this ring 03464 03465 t1 = circ1(numr2i) * circ2(numr2i); 03466 q(1) += t1; 03467 t(1) += t1; 03468 03469 t1 = circ1(numr2i+1) * circ2(numr2i+1); 03470 if (numr3i == maxrin) { 03471 q(2) += t1; 03472 t(2) += t1; 03473 } else { 03474 q(numr3i+1) += t1; 03475 t(numr3i+1) += t1; 03476 } 03477 03478 for (j=3; j<=numr3i; j += 2) { 03479 jc = j+numr2i-1; 03480 03481 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03482 // ----- ----- ----- ----- 03483 // t1 t2 t3 t4 03484 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i 03485 // ----- ----- ----- ----- 03486 // t1 t2 t3 t4 03487 03488 c1 = circ1(jc); 03489 c2 = circ1(jc+1); 03490 d1 = circ2(jc); 03491 d2 = circ2(jc+1); 03492 03493 t1 = c1 * d1; 03494 t2 = c2 * d2; 03495 t3 = c1 * d2; 03496 t4 = c2 * d1; 03497 03498 q(j) += t1 + t2; 03499 q(j+1) += -t3 + t4; 03500 t(j) += t1 - t2; 03501 t(j+1) += -t3 - t4; 03502 } 03503 } 03504 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<" "<<t(j) <<endl; 03505 fftr_d(q,ip); 03506 03507 qn = -1.0e20; 03508 for (j=1; j<=maxrin; j++) {//cout <<" "<<j<<" "<<q(j) <<endl; 03509 if (q(j) >= qn) { 03510 qn = q(j); 03511 jtot = j; 03512 } 03513 } 03514 03515 for (k=-3; k<=3; k++) { 03516 j = ((jtot+k+maxrin-1)%maxrin)+1; 03517 t7(k+4) = q(j); 03518 } 03519 03520 // interpolate 03521 prb1d(t7,7,&pos); 03522 tot = (float)(jtot)+pos; 03523 // Do not interpolate 03524 //tot = (float)(jtot); 03525 03526 // mirrored 03527 fftr_d(t,ip); 03528 03529 // find angle 03530 qm = -1.0e20; 03531 for (j=1; j<=maxrin;j++) {//cout <<" "<<j<<" "<<t(j) <<endl; 03532 if ( t(j) >= qm ) { 03533 qm = t(j); 03534 jtot = j; 03535 } 03536 } 03537 03538 for (k=-3; k<=3; k++) { 03539 j = ((jtot+k+maxrin-1)%maxrin) + 1; 03540 t7(k+4) = t(j); 03541 } 03542 03543 // interpolate 03544 03545 prb1d(t7,7,&pos); 03546 tmt = float(jtot) + pos; 03547 // Do not interpolate 03548 //tmt = float(jtot); 03549 03550 free(t); 03551 free(q); 03552 03553 Dict retvals; 03554 retvals["qn"] = qn; 03555 retvals["tot"] = tot; 03556 retvals["qm"] = qm; 03557 retvals["tmt"] = tmt; 03558 return retvals; 03559 }
Dict Util::Crosrng_ms_delta | ( | EMData * | circ1, | |
EMData * | circ2, | |||
vector< int > | numr, | |||
float | delta_start, | |||
float | delta | |||
) | [static] |
Definition at line 3561 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().
03561 { 03562 int nring = numr.size()/3; 03563 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03564 int maxrin = numr[numr.size()-1]; 03565 double qn; float tot; double qm; float tmt; 03566 float *circ1 = circ1p->get_data(); 03567 float *circ2 = circ2p->get_data(); 03568 /* 03569 c 03570 c checks both straight & mirrored positions 03571 c 03572 c input - fourier transforms of rings!! 03573 c circ1 already multiplied by weights! 03574 c 03575 */ 03576 03577 // dimension circ1(lcirc),circ2(lcirc) 03578 03579 // t(maxrin), q(maxrin), t7(-3:3) //maxrin+2 removed 03580 double *t, *q; 03581 03582 int ip, jc, numr3i, numr2i, i, j, jtot = 0; 03583 float t1, t2, t3, t4, c1, c2, d1, d2; 03584 03585 qn = 0.0f; 03586 qm = 0.0f; 03587 tot = 0.0f; 03588 tmt = 0.0f; 03589 #ifdef _WIN32 03590 ip = -(int)(log((float)maxrin)/log(2.0f)); 03591 #else 03592 ip = -(int)(log2(maxrin)); 03593 #endif //_WIN32 03594 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl; 03595 03596 // c - straight = circ1 * conjg(circ2) 03597 // zero q array 03598 03599 q = (double*)calloc(maxrin,sizeof(double)); 03600 03601 // t - mirrored = conjg(circ1) * conjg(circ2) 03602 // zero t array 03603 t = (double*)calloc(maxrin,sizeof(double)); 03604 03605 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03606 for (i=1; i<=nring; i++) { 03607 03608 numr3i = numr(3,i); // Number of samples of this ring 03609 numr2i = numr(2,i); // The beginning point of this ring 03610 03611 t1 = circ1(numr2i) * circ2(numr2i); 03612 q(1) += t1; 03613 t(1) += t1; 03614 03615 t1 = circ1(numr2i+1) * circ2(numr2i+1); 03616 if (numr3i == maxrin) { 03617 q(2) += t1; 03618 t(2) += t1; 03619 } else { 03620 q(numr3i+1) += t1; 03621 t(numr3i+1) += t1; 03622 } 03623 03624 for (j=3; j<=numr3i; j += 2) { 03625 jc = j+numr2i-1; 03626 03627 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03628 // ----- ----- ----- ----- 03629 // t1 t2 t3 t4 03630 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i 03631 // ----- ----- ----- ----- 03632 // t1 t2 t3 t4 03633 03634 c1 = circ1(jc); 03635 c2 = circ1(jc+1); 03636 d1 = circ2(jc); 03637 d2 = circ2(jc+1); 03638 03639 t1 = c1 * d1; 03640 t2 = c2 * d2; 03641 t3 = c1 * d2; 03642 t4 = c2 * d1; 03643 03644 q(j) += t1 + t2; 03645 q(j+1) += -t3 + t4; 03646 t(j) += t1 - t2; 03647 t(j+1) += -t3 - t4; 03648 } 03649 } 03650 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<" "<<t(j) <<endl; 03651 fftr_d(q,ip); 03652 03653 qn = -1.0e20; 03654 03655 int jstart = 1+static_cast<int>(delta_start/360.0*maxrin); 03656 int jstep = static_cast<int>(delta/360.0*maxrin); 03657 if (jstep < 1) { jstep = 1; } 03658 03659 for (j=jstart; j<=maxrin; j+=jstep) {//cout <<" "<<j<<" "<<q(j) <<endl; 03660 if (q(j) >= qn) { 03661 qn = q(j); 03662 jtot = j; 03663 } 03664 } 03665 03666 //for (k=-3; k<=3; k++) { 03667 // j = ((jtot+k+maxrin-1)%maxrin)+1; 03668 // t7(k+4) = q(j); 03669 //} 03670 03671 // interpolate 03672 //prb1d(t7,7,&pos); 03673 //tot = (float)(jtot)+pos; 03674 // Do not interpolate 03675 tot = (float)(jtot); 03676 03677 // mirrored 03678 fftr_d(t,ip); 03679 03680 // find angle 03681 qm = -1.0e20; 03682 for (j=jstart; j<=maxrin;j+=jstep) {//cout <<" "<<j<<" "<<t(j) <<endl; 03683 if ( t(j) >= qm ) { 03684 qm = t(j); 03685 jtot = j; 03686 } 03687 } 03688 03689 //for (k=-3; k<=3; k++) { 03690 // j = ((jtot+k+maxrin-1)%maxrin) + 1; 03691 // t7(k+4) = t(j); 03692 //} 03693 03694 // interpolate 03695 03696 //prb1d(t7,7,&pos); 03697 //tmt = float(jtot) + pos; 03698 // Do not interpolate 03699 tmt = float(jtot); 03700 03701 free(t); 03702 free(q); 03703 03704 Dict retvals; 03705 retvals["qn"] = qn; 03706 retvals["tot"] = tot; 03707 retvals["qm"] = qm; 03708 retvals["tmt"] = tmt; 03709 return retvals; 03710 }
checks both straight & mirrored positions input - fourier transforms of rings!! circ1 already multiplied by weights! returns EM object with 1D ccf
Definition at line 4138 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.
04138 { 04139 04140 // dimension circ1(lcirc),circ2(lcirc) 04141 04142 int ip, jc, numr3i, numr2i, i, j; 04143 float t1, t2, t3, t4, c1, c2, d1, d2; 04144 04145 int nring = numr.size()/3; 04146 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 04147 int maxrin = numr[numr.size()-1]; 04148 04149 float* circ1b = circ1->get_data(); 04150 float* circ2b = circ2->get_data(); 04151 04152 // t(maxrin), q(maxrin) // removed +2 04153 double *t, *q; 04154 04155 q = (double*)calloc(maxrin,sizeof(double)); 04156 t = (double*)calloc(maxrin,sizeof(double)); 04157 04158 #ifdef _WIN32 04159 ip = -(int)(log((float)maxrin)/log(2.0f)); 04160 #else 04161 ip = -(int)(log2(maxrin)); 04162 #endif //_WIN32 04163 04164 // q - straight = circ1 * conjg(circ2) 04165 04166 // t - mirrored = conjg(circ1) * conjg(circ2) 04167 04168 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 04169 04170 for (i=1; i<=nring; i++) { 04171 04172 numr3i = numr(3,i); 04173 numr2i = numr(2,i); 04174 04175 t1 = circ1b(numr2i) * circ2b(numr2i); 04176 q(1) = q(1)+t1; 04177 t(1) = t(1)+t1; 04178 04179 t1 = circ1b(numr2i+1) * circ2b(numr2i+1); 04180 if (numr3i == maxrin) { 04181 q(2) += t1; 04182 t(2) += t1; 04183 } else { 04184 q(numr3i+1) += t1; 04185 t(numr3i+1) += t1; 04186 } 04187 04188 for (j=3; j<=numr3i; j=j+2) { 04189 jc = j+numr2i-1; 04190 04191 c1 = circ1b(jc); 04192 c2 = circ1b(jc+1); 04193 d1 = circ2b(jc); 04194 d2 = circ2b(jc+1); 04195 04196 t1 = c1 * d1; 04197 t3 = c1 * d2; 04198 t2 = c2 * d2; 04199 t4 = c2 * d1; 04200 04201 q(j) += t1 + t2; 04202 q(j+1) += - t3 + t4; 04203 t(j) += t1 - t2; 04204 t(j+1) += - t3 - t4; 04205 } 04206 } 04207 04208 // straight 04209 fftr_d(q,ip); 04210 04211 // mirrored 04212 fftr_d(t,ip); 04213 04214 EMData* out = new EMData(); 04215 out->set_size(maxrin,2,1); 04216 float *dout = out->get_data(); 04217 for (int i=0; i<maxrin; i++) {dout(i,0)=static_cast<float>(q[i]); dout(i,1)=static_cast<float>(t[i]);} 04218 //out->set_size(maxrin,1,1); 04219 //float *dout = out->get_data(); 04220 //for (int i=0; i<maxrin; i++) {dout(i,0)=q[i];} 04221 free(t); 04222 free(q); 04223 return out; 04224 }
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 4385 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.
04386 { 04387 04388 int ip, jc, numr3i, numr2i, i, j; 04389 float t1, t2, t3, t4, c1, c2, d1, d2; 04390 04391 int nring = numr.size()/3; 04392 int maxrin = numr[numr.size()-1]; 04393 04394 float* circ1b = circ1->get_data(); 04395 float* circ2b = circ2->get_data(); 04396 04397 double *t; 04398 04399 t = (double*)calloc(maxrin,sizeof(double)); 04400 04401 #ifdef _WIN32 04402 ip = -(int)(log((float)maxrin)/log(2.0f)); 04403 #else 04404 ip = -(int)(log2(maxrin)); 04405 #endif //_WIN32 04406 04407 // t - mirrored = conjg(circ1) * conjg(circ2) 04408 04409 for (i=1;i<=nring;i++) { 04410 04411 numr3i = numr(3,i); 04412 numr2i = numr(2,i); 04413 04414 t1 = circ1b(numr2i) * circ2b(numr2i); 04415 t(1) = t(1)+t1; 04416 04417 if (numr3i == maxrin) { 04418 t1 = circ1b(numr2i+1) * circ2b(numr2i+1); 04419 t(2) = t(2)+t1; 04420 } 04421 04422 for (j=3;j<=numr3i;j=j+2) { 04423 jc = j+numr2i-1; 04424 04425 c1 = circ1b(jc); 04426 c2 = circ1b(jc+1); 04427 d1 = circ2b(jc); 04428 d2 = circ2b(jc+1); 04429 04430 t1 = c1 * d1; 04431 t3 = c1 * d2; 04432 t2 = c2 * d2; 04433 t4 = c2 * d1; 04434 04435 t(j) = t(j) + t1 - t2; 04436 t(j+1) = t(j+1) - t3 - t4; 04437 } 04438 } 04439 04440 // mirrored 04441 fftr_d(t,ip); 04442 04443 EMData* out = new EMData(); 04444 out->set_size(maxrin,1,1); 04445 float *dout = out->get_data(); 04446 for (int i=0; i<maxrin; i++) dout[i]=static_cast<float>(t[i]); 04447 free(t); 04448 return out; 04449 04450 }
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 4314 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().
04315 { 04316 04317 int ip, jc, numr3i, numr2i, i, j; 04318 float t1, t2, t3, t4, c1, c2, d1, d2; 04319 04320 int nring = numr.size()/3; 04321 int maxrin = numr[numr.size()-1]; 04322 04323 float* circ1b = circ1->get_data(); 04324 float* circ2b = circ2->get_data(); 04325 04326 double *q; 04327 04328 q = (double*)calloc(maxrin,sizeof(double)); 04329 04330 #ifdef _WIN32 04331 ip = -(int)(log((float)maxrin)/log(2.0f)); 04332 #else 04333 ip = -(int)(log2(maxrin)); 04334 #endif //_WIN32 04335 04336 // q - straight = circ1 * conjg(circ2) 04337 04338 for (i=1;i<=nring;i++) { 04339 04340 numr3i = numr(3,i); 04341 numr2i = numr(2,i); 04342 04343 t1 = circ1b(numr2i) * circ2b(numr2i); 04344 q(1) = q(1)+t1; 04345 04346 if (numr3i == maxrin) { 04347 t1 = circ1b(numr2i+1) * circ2b(numr2i+1); 04348 q(2) = q(2)+t1; 04349 } else { 04350 t1 = circ1b(numr2i+1) * circ2b(numr2i+1); 04351 q(numr3i+1) = q(numr3i+1)+t1; 04352 } 04353 04354 for (j=3;j<=numr3i;j=j+2) { 04355 jc = j+numr2i-1; 04356 04357 c1 = circ1b(jc); 04358 c2 = circ1b(jc+1); 04359 d1 = circ2b(jc); 04360 d2 = circ2b(jc+1); 04361 04362 t1 = c1 * d1; 04363 t3 = c1 * d2; 04364 t2 = c2 * d2; 04365 t4 = c2 * d1; 04366 04367 q(j) = q(j) + t1 + t2; 04368 q(j+1) = q(j+1) - t3 + t4; 04369 } 04370 } 04371 04372 // straight 04373 fftr_d(q,ip); 04374 04375 EMData* out = new EMData(); 04376 out->set_size(maxrin,1,1); 04377 float *dout = out->get_data(); 04378 for (int i=0; i<maxrin; i++) dout[i]=static_cast<float>(q[i]); 04379 free(q); 04380 return out; 04381 04382 }
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 4242 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().
04242 { 04243 04244 // dimension circ1(lcirc),circ2(lcirc) 04245 04246 int ip, jc, numr3i, numr2i, i, j; 04247 float t1, t2, t3, t4, c1, c2, d1, d2; 04248 04249 int nring = numr.size()/3; 04250 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 04251 int maxrin = numr[numr.size()-1]; 04252 04253 float* circ1b = circ1->get_data(); 04254 float* circ2b = circ2->get_data(); 04255 04256 #ifdef _WIN32 04257 ip = -(int)(log((float)maxrin)/log(2.0f)); 04258 #else 04259 ip = -(int)(log2(maxrin)); 04260 #endif //_WIN32 04261 for (int i=1; i<=maxrin; i++) {q(i) = 0.0f; t(i) = 0.0f;} 04262 04263 // q - straight = circ1 * conjg(circ2) 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 04272 t1 = circ1b(numr2i) * circ2b(numr2i); 04273 q(1) += t1; 04274 t(1) += t1; 04275 04276 t1 = circ1b(numr2i+1) * circ2b(numr2i+1); 04277 if (numr3i == maxrin) { 04278 q(2) += t1; 04279 t(2) += t1; 04280 } else { 04281 q(numr3i+1) += t1; 04282 t(numr3i+1) += t1; 04283 } 04284 04285 for (j=3; j<=numr3i; j=j+2) { 04286 jc = j+numr2i-1; 04287 04288 c1 = circ1b(jc); 04289 c2 = circ1b(jc+1); 04290 d1 = circ2b(jc); 04291 d2 = circ2b(jc+1); 04292 04293 t1 = c1 * d1; 04294 t3 = c1 * d2; 04295 t2 = c2 * d2; 04296 t4 = c2 * d1; 04297 04298 q(j) += t1 + t2; 04299 q(j+1) += -t3 + t4; 04300 t(j) += t1 - t2; 04301 t(j+1) += -t3 - t4; 04302 } 04303 } 04304 // straight 04305 fftr_q(q,ip); 04306 //for (int i=0; i<maxrin; i++) cout<<i<<" B "<<q[i]<<" "<<t[i]<<endl; 04307 04308 // mirrored 04309 fftr_q(t,ip); 04310 }
vector< float > Util::Crosrng_msg_vec_p | ( | EMData * | circ1, | |
EMData * | circ2, | |||
vector< int > | numr | |||
) | [static] |
Definition at line 4227 of file util_sparx.cpp.
References circ1, circ2, and Crosrng_msg_vec().
04227 { 04228 04229 int maxrin = numr[numr.size()-1]; 04230 04231 vector<float> r(2*maxrin); 04232 04233 Crosrng_msg_vec( circ1, circ2, numr, &r[0], &r[maxrin] ); 04234 04235 return r; 04236 }
Definition at line 4039 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().
04039 { 04040 int nring = numr.size()/3; 04041 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 04042 int maxrin = numr[numr.size()-1]; 04043 double qn; float tot; 04044 float *circ1 = circ1p->get_data(); 04045 float *circ2 = circ2p->get_data(); 04046 /* 04047 c 04048 c checks only straight position 04049 c 04050 c input - fourier transforms of rings!! 04051 c circ1 already multiplied by weights! 04052 c 04053 */ 04054 04055 // dimension circ1(lcirc),circ2(lcirc) 04056 04057 // q(maxrin), t7(-3:3) //maxrin+2 removed 04058 double *q, t7[7]; 04059 04060 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 04061 float c1, c2, d1, d2, pos; 04062 04063 qn = 0.0; 04064 tot = 0.0; 04065 #ifdef _WIN32 04066 ip = -(int)(log((float)maxrin)/log(2.0f)); 04067 #else 04068 ip = -(int)(log2(maxrin)); 04069 #endif //_WIN32 04070 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl; 04071 04072 // c - straight = circ1 * conjg(circ2) 04073 // zero q array 04074 04075 q = (double*)calloc(maxrin,sizeof(double)); 04076 04077 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 04078 for (i=1; i<=nring; i++) { 04079 04080 numr3i = numr(3,i); // Number of samples of this ring 04081 numr2i = numr(2,i); // The beginning point of this ring 04082 04083 q(1) += circ1(numr2i) * circ2(numr2i); 04084 04085 if (numr3i == maxrin) q(2) += circ1(numr2i+1) * circ2(numr2i+1); 04086 else q(numr3i+1) += circ1(numr2i+1) * circ2(numr2i+1); 04087 04088 for (j=3; j<=numr3i; j += 2) { 04089 jc = j+numr2i-1; 04090 04091 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 04092 // ----- ----- ----- ----- 04093 // t1 t2 t3 t4 04094 04095 c1 = circ1(jc); 04096 c2 = circ1(jc+1); 04097 d1 = circ2(jc); 04098 d2 = circ2(jc+1); 04099 04100 q(j) += c1 * d1 + c2 * d2; 04101 q(j+1) += -c1 * d2 + c2 * d1; 04102 } 04103 } 04104 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<endl; 04105 fftr_d(q,ip); 04106 04107 qn = -1.0e20; 04108 for (j=1; j<=maxrin; j++) {//cout <<" "<<j<<" "<<q(j) <<endl; 04109 if (q(j) >= qn) { 04110 qn = q(j); 04111 jtot = j; 04112 } 04113 } 04114 04115 for (k=-3; k<=3; k++) { 04116 j = ((jtot+k+maxrin-1)%maxrin)+1; 04117 t7(k+4) = q(j); 04118 } 04119 04120 // interpolate 04121 prb1d(t7,7,&pos); 04122 tot = (float)(jtot)+pos; 04123 // Do not interpolate 04124 //*tot = (float)(jtot); 04125 04126 free(q); 04127 04128 Dict retvals; 04129 retvals["qn"] = qn; 04130 retvals["tot"] = tot; 04131 return retvals; 04132 }
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 3921 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().
03921 { 03922 // Computes both straight and mirrored 03923 03924 int nring = numr.size()/3; 03925 int maxrin = numr[numr.size()-1]; 03926 double qn; float tot; double qm; float tmt; 03927 float *circ1 = circ1p->get_data(); 03928 float *circ2 = circ2p->get_data(); 03929 03930 double *t, *q; 03931 03932 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 03933 float t1, t2, t3, t4, c1, c2, d1, d2; 03934 03935 qn = 0.0f; 03936 qm = 0.0f; 03937 tot = 0.0f; 03938 tmt = 0.0f; 03939 #ifdef _WIN32 03940 ip = -(int)(log((float)maxrin)/log(2.0f)); 03941 #else 03942 ip = -(int)(log2(maxrin)); 03943 #endif //_WIN32 03944 03945 // c - straight = circ1 * conjg(circ2) 03946 // zero q array 03947 03948 q = (double*)calloc(maxrin,sizeof(double)); 03949 03950 // t - mirrored = conjg(circ1) * conjg(circ2) 03951 // zero t array 03952 t = (double*)calloc(maxrin,sizeof(double)); 03953 03954 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03955 03956 for (i=1; i<=nring; i++) { 03957 03958 numr3i = numr(3,i); // Number of samples of this ring 03959 numr2i = numr(2,i); // The beginning point of this ring 03960 03961 t1 = circ1(numr2i) * circ2(numr2i); 03962 q(1) += t1; 03963 t(1) += t1; 03964 03965 t1 = circ1(numr2i+1) * circ2(numr2i+1); 03966 if (numr3i == maxrin) { 03967 q(2) += t1; 03968 t(2) += t1; 03969 } else { 03970 q(numr3i+1) += t1; 03971 t(numr3i+1) += t1; 03972 } 03973 03974 for (j=3; j<=numr3i; j += 2) { 03975 jc = j+numr2i-1; 03976 03977 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03978 // ----- ----- ----- ----- 03979 // t1 t2 t3 t4 03980 03981 c1 = circ1(jc); 03982 c2 = circ1(jc+1); 03983 d1 = circ2(jc); 03984 d2 = circ2(jc+1); 03985 03986 t1 = c1 * d1; 03987 t3 = c1 * d2; 03988 t2 = c2 * d2; 03989 t4 = c2 * d1; 03990 03991 q(j) += t1 + t2; 03992 q(j+1) += -t3 + t4; 03993 t(j) += t1 - t2; 03994 t(j+1) += -t3 - t4; 03995 } 03996 } 03997 03998 fftr_d(q,ip); 03999 04000 qn = -1.0e20; 04001 int psi_pos = int(psi/360.0*maxrin+0.5); 04002 const int psi_range = int(psi_max/360.0*maxrin + 0.5); 04003 04004 for (k=-psi_range; k<=psi_range; k++) { 04005 j = (k+psi_pos+maxrin-1)%maxrin+1; 04006 if (q(j) >= qn) { 04007 qn = q(j); 04008 jtot = j; 04009 } 04010 } 04011 04012 tot = (float)(jtot); 04013 free(q); 04014 04015 // mirrored 04016 fftr_d(t,ip); 04017 04018 qm = -1.0e20; 04019 04020 for (k=-psi_range; k<=psi_range; k++) { 04021 j = (k+psi_pos+maxrin-1)%maxrin+1; 04022 if (t(j) >= qm) { 04023 qm = t(j); 04024 jtot = j; 04025 } 04026 } 04027 04028 tmt = (float)(jtot); 04029 free(t); 04030 04031 Dict retvals; 04032 retvals["qn"] = qn; 04033 retvals["tot"] = tot; 04034 retvals["qm"] = qm; 04035 retvals["tmt"] = tmt; 04036 return retvals; 04037 }
Dict Util::Crosrng_psi_0_180_no_mirror | ( | EMData * | circ1, | |
EMData * | circ2, | |||
vector< int > | numr, | |||
float | psi_max | |||
) | [static] |
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 3713 of file util_sparx.cpp.
References circ1, circ2, fftr_d(), EMAN::EMData::get_data(), log(), numr, prb1d(), q, EMAN::Dict::size(), t7, and tot.
Referenced by multiref_polar_ali_helical_90_local().
03713 { 03714 int nring = numr.size()/3; 03715 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03716 int maxrin = numr[numr.size()-1]; 03717 double qn; float tot; 03718 float *circ1 = circ1p->get_data(); 03719 float *circ2 = circ2p->get_data(); 03720 03721 // dimension circ1(lcirc),circ2(lcirc) 03722 03723 // t(maxrin), q(maxrin), t7(-3:3) //maxrin+2 removed 03724 double *q, t7[7]; 03725 03726 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 03727 float t1, t2, t3, t4, c1, c2, d1, d2, pos; 03728 03729 qn = 0.0f; 03730 tot = 0.0f; 03731 #ifdef _WIN32 03732 ip = -(int)(log((float)maxrin)/log(2.0f)); 03733 #else 03734 ip = -(int)(log2(maxrin)); 03735 #endif //_WIN32 03736 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl; 03737 03738 // c - straight = circ1 * conjg(circ2) 03739 // zero q array 03740 03741 q = (double*)calloc(maxrin,sizeof(double)); 03742 03743 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03744 for (i=1; i<=nring; i++) { 03745 03746 numr3i = numr(3,i); // Number of samples of this ring 03747 numr2i = numr(2,i); // The beginning point of this ring 03748 03749 t1 = circ1(numr2i) * circ2(numr2i); 03750 q(1) += t1; 03751 03752 t1 = circ1(numr2i+1) * circ2(numr2i+1); 03753 if (numr3i == maxrin) { 03754 q(2) += t1; 03755 03756 } else { 03757 q(numr3i+1) += t1; 03758 } 03759 03760 for (j=3; j<=numr3i; j += 2) { 03761 jc = j+numr2i-1; 03762 03763 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03764 // ----- ----- ----- ----- 03765 // t1 t2 t3 t4 03766 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i 03767 // ----- ----- ----- ----- 03768 // t1 t2 t3 t4 03769 03770 c1 = circ1(jc); 03771 c2 = circ1(jc+1); 03772 d1 = circ2(jc); 03773 d2 = circ2(jc+1); 03774 03775 t1 = c1 * d1; 03776 t2 = c2 * d2; 03777 t3 = c1 * d2; 03778 t4 = c2 * d1; 03779 03780 q(j) += t1 + t2; 03781 q(j+1) += -t3 + t4; 03782 03783 } 03784 } 03785 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<" "<<t(j) <<endl; 03786 03787 fftr_d(q,ip); 03788 03789 int psi_range = int(psi_max/360.0*maxrin+0.5); 03790 const int psi_0 = 0; 03791 int psi_180 = int( 180.0/360.0*maxrin+0.5); 03792 03793 qn = -1.0e20; 03794 for (k=-psi_range; k<=psi_range; k++) { 03795 j = (k+psi_0+maxrin-1)%maxrin+1;//string modemo = "f";cout <<" 90 "<<j<<" "<<ang_n(j,modemo,maxrin) <<" "<<float(j)/maxrin*360.0<<" "<<q(j) <<endl; 03796 if (q(j) >= qn) { 03797 qn = q(j); 03798 jtot = j; 03799 } 03800 } 03801 03802 for (k=-psi_range; k<=psi_range; k++) { 03803 j = (k+psi_180+maxrin-1)%maxrin+1; //cout <<" 270 "<<j<<" "<<ang_n(j,modemo,maxrin) <<" "<<float(j)/maxrin*360.0<<" "<<q(j) <<endl; 03804 if (q(j) >= qn) { 03805 qn = q(j); 03806 jtot = j; 03807 } 03808 } 03809 03810 for (k=-3; k<=3; k++) { 03811 j = ((jtot+k+maxrin-1)%maxrin)+1; 03812 t7(k+4) = q(j); 03813 } 03814 03815 // interpolate 03816 prb1d(t7,7,&pos); 03817 tot = (float)(jtot)+pos; 03818 // Do not interpolate 03819 //tot = (float)(jtot); 03820 03821 free(q); 03822 03823 Dict retvals; 03824 retvals["qn"] = qn; 03825 retvals["tot"] = tot; 03826 03827 return retvals; 03828 }
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 3832 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(), and multiref_polar_ali_helical_local().
03832 { 03833 // flag 0 - straight, 1 - mirror 03834 03835 int nring = numr.size()/3; 03836 int maxrin = numr[numr.size()-1]; 03837 double qn; float tot; 03838 float *circ1 = circ1p->get_data(); 03839 float *circ2 = circ2p->get_data(); 03840 03841 double *q; 03842 03843 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 03844 float t1, t2, t3, t4, c1, c2, d1, d2; 03845 03846 qn = 0.0f; 03847 tot = 0.0f; 03848 #ifdef _WIN32 03849 ip = -(int)(log((float)maxrin)/log(2.0f)); 03850 #else 03851 ip = -(int)(log2(maxrin)); 03852 #endif //_WIN32 03853 03854 // c - straight = circ1 * conjg(circ2) 03855 // zero q array 03856 03857 q = (double*)calloc(maxrin,sizeof(double)); 03858 int neg = 1-2*flag; 03859 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03860 03861 for (i=1; i<=nring; i++) { 03862 03863 numr3i = numr(3,i); // Number of samples of this ring 03864 numr2i = numr(2,i); // The beginning point of this ring 03865 03866 t1 = circ1(numr2i) * circ2(numr2i); 03867 q(1) += t1; 03868 03869 t1 = circ1(numr2i+1) * circ2(numr2i+1); 03870 if (numr3i == maxrin) { 03871 q(2) += t1; 03872 } else { 03873 q(numr3i+1) += t1; 03874 } 03875 03876 for (j=3; j<=numr3i; j += 2) { 03877 jc = j+numr2i-1; 03878 03879 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03880 // ----- ----- ----- ----- 03881 // t1 t2 t3 t4 03882 03883 c1 = circ1(jc); 03884 c2 = circ1(jc+1); 03885 d1 = circ2(jc); 03886 d2 = circ2(jc+1); 03887 03888 t1 = c1 * d1; 03889 t3 = c1 * d2; 03890 t2 = c2 * d2; 03891 t4 = c2 * d1; 03892 03893 q(j) += t1 + t2*neg; 03894 q(j+1) += -t3 + t4*neg; 03895 } 03896 } 03897 03898 fftr_d(q,ip); 03899 03900 qn = -1.0e20; 03901 int psi_pos = int(psi/360.0*maxrin+0.5); 03902 const int psi_range = int(psi_max/360.0*maxrin + 0.5); 03903 03904 for (k=-psi_range; k<=psi_range; k++) { 03905 j = ( k + psi_pos + maxrin -1 )%maxrin+1; 03906 if (q(j) >= qn) { 03907 qn = q(j); 03908 jtot = j; 03909 } 03910 } 03911 03912 tot = (float)(jtot); 03913 free(q); 03914 03915 Dict retvals; 03916 retvals["qn"] = qn; 03917 retvals["tot"] = tot; 03918 return retvals; 03919 }
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 20470 of file util_sparx.cpp.
References pihalf, EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), EMAN::EMData::set_ri(), EMAN::EMData::set_size(), tf(), and EMAN::EMData::update().
20471 { 20472 int ix, iy, iz; 20473 int i, j, k; 20474 int nr2, nl2; 20475 float az, ak; 20476 float scx, scy, scz; 20477 int offset = 2 - nx%2; 20478 int lsm = nx + offset; 20479 EMData* ctf_img1 = new EMData(); 20480 ctf_img1->set_size(lsm, ny, nz); 20481 float freq = 1.0f/(2.0f*ps); 20482 scx = 2.0f/float(nx); 20483 if(ny>=1) scy = 2.0f/float(ny); else scy=0.0f; 20484 if(nz>=1) scz = 2.0f/float(nz); else scz=0.0f; 20485 nr2 = ny/2 ; 20486 nl2 = nz/2 ; 20487 float pihalf = M_PI/2.0f; 20488 for ( k=0; k<nz;k++) { 20489 iz = k; if(k>nl2) iz=k-nz; 20490 float oz2 = iz*scz*iz*scz; 20491 for ( j=0; j<ny;j++) { 20492 iy = j; if(j>nr2) iy=j - ny; 20493 float oy = iy*scy; 20494 float oy2 = oy*oy; 20495 for ( i=0; i<lsm/2; i++) { 20496 ix=i; 20497 if( dza == 0.0f) { 20498 ak=pow(ix*ix*scx*scx + oy2 + oz2, 0.5f)*freq; 20499 (*ctf_img1) (i*2,j,k) = Util::tf(dz, ak, voltage, cs, wgh, b_factor, sign); 20500 } else { 20501 float ox = ix*scx; 20502 ak=pow(ox*ox + oy2 + oz2, 0.5f)*freq; 20503 az = atan2(oy, ox); 20504 float dzz = dz + dza/2.0f*sin(2*(az-azz*M_PI/180.0f-pihalf)); 20505 (*ctf_img1) (i*2,j,k) = Util::tf(dzz, ak, voltage, cs, wgh, b_factor, sign); 20506 } 20507 //(*ctf_img1) (i*2+1,j,k) = 0.0f; PAP I assumed new EMData sets to zero 20508 } 20509 } 20510 } 20511 ctf_img1->update(); 20512 ctf_img1->set_complex(true); 20513 ctf_img1->set_ri(true); 20514 //ctf_img1->attr_dict["is_complex"] = 1; 20515 //ctf_img1->attr_dict["is_ri"] = 1; 20516 if(nx%2==0) ctf_img1->set_fftodd(false); else ctf_img1->set_fftodd(true); 20517 return ctf_img1; 20518 }
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 5476 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().
05476 { 05477 05478 if (image->is_complex()) throw ImageFormatException("Real image required for IntegerCyclicShift2DProcessor"); 05479 05480 int dx = params["dx"]; 05481 int dy = params["dy"]; 05482 int dz = params["dz"]; 05483 05484 // The reverse trick we're using shifts to the left (a negative shift) 05485 int nx = image->get_xsize(); 05486 dx %= nx; 05487 if (dx < 0) dx += nx; 05488 int ny = image->get_ysize(); 05489 dy %= ny; 05490 if (dy < 0) dy += ny; 05491 int nz = image->get_zsize(); 05492 dz %= nz; 05493 if (dz < 0) dz += nz; 05494 05495 int mx = -(dx - nx); 05496 int my = -(dy - ny); 05497 int mz = -(dz - nz); 05498 05499 float* data = image->get_data(); 05500 // x-reverses 05501 if (mx != 0) { 05502 for (int iz = 0; iz < nz; iz++) 05503 for (int iy = 0; iy < ny; iy++) { 05504 // reverses for column iy 05505 size_t offset = nx*iy + (size_t)nx*ny*iz; // starting location for column iy in slice iz 05506 reverse(&data[offset],&data[offset+mx]); 05507 reverse(&data[offset+mx],&data[offset+nx]); 05508 reverse(&data[offset],&data[offset+nx]); 05509 } 05510 } 05511 // y-reverses 05512 if (my != 0) { 05513 for (int iz = 0; iz < nz; iz++) { 05514 size_t offset = (size_t)nx*ny*iz; 05515 colreverse(&data[offset], &data[offset + my*nx], nx); 05516 colreverse(&data[offset + my*nx], &data[offset + ny*nx], nx); 05517 colreverse(&data[offset], &data[offset + ny*nx], nx); 05518 } 05519 } 05520 if (mz != 0) { 05521 slicereverse(&data[0], &data[(size_t)mz*ny*nx], nx, ny); 05522 slicereverse(&data[mz*ny*nx], &data[(size_t)nz*ny*nx], nx, ny); 05523 slicereverse(&data[0], &data[(size_t)nz*ny*nx], nx ,ny); 05524 } 05525 image->update(); 05526 }
Definition at line 5270 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().
05271 { 05272 /* Exception Handle */ 05273 if (!img) { 05274 throw NullPointerException("NULL input image"); 05275 } 05276 /* ============================== */ 05277 05278 // Get the size of the input image 05279 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 05280 /* ============================== */ 05281 05282 05283 /* Exception Handle */ 05284 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) 05285 { 05286 LOGERR("Parameters for decimation cannot exceed the center of the image."); 05287 throw ImageDimensionException("Parameters for decimation cannot exceed the center of the image."); 05288 } 05289 /* ============================== */ 05290 05291 05292 /* Calculation of the start point */ 05293 int new_st_x=(nx/2)%x_step, new_st_y=(ny/2)%y_step, new_st_z=(nz/2)%z_step; 05294 /* ============================*/ 05295 05296 05297 /* Calculation of the size of the decimated image */ 05298 int rx=2*(nx/(2*x_step)), ry=2*(ny/(2*y_step)), rz=2*(nz/(2*z_step)); 05299 int r1=int(ceil((nx-(x_step*rx))/(1.f*x_step))), r2=int(ceil((ny-(y_step*ry))/(1.f*y_step))); 05300 int r3=int(ceil((nz-(z_step*rz))/(1.f*z_step))); 05301 if(r1>1){r1=1;} 05302 if(r2>1){r2=1;} 05303 if(r3>1){r3=1;} 05304 int new_nx=rx+r1, new_ny=ry+r2, new_nz=rz+r3; 05305 /* ===========================================*/ 05306 05307 05308 EMData* img2 = new EMData(); 05309 img2->set_size(new_nx,new_ny,new_nz); 05310 float *new_ptr = img2->get_data(); 05311 float *old_ptr = img->get_data(); 05312 int iptr, jptr, kptr = 0; 05313 for (int k=new_st_z; k<nz; k+=z_step) {jptr=0; 05314 for (int j=new_st_y; j<ny; j+=y_step) {iptr=0; 05315 for (int i=new_st_x; i<nx; i+=x_step) { 05316 new_ptr(iptr,jptr,kptr) = old_ptr(i,j,k); 05317 iptr++;} 05318 jptr++;} 05319 kptr++;} 05320 img2->update(); 05321 return img2; 05322 }
void Util::disorder2 | ( | double * | x, | |
double * | y, | |||
int * | key, | |||
int | len | |||
) | [static] |
Definition at line 7840 of file util_sparx.cpp.
References ENTERFUNC, and EXITFUNC.
07841 { 07842 ENTERFUNC; 07843 int k, i; 07844 for(i=0; i<len; i++) key[i]=i+1; 07845 07846 for(i = 0; i<len;i++){ 07847 k = rand()%len; 07848 std::swap(key[k], key[i]); 07849 std::swap(x[k], x[i]); 07850 std::swap(y[k], y[i]); 07851 } 07852 EXITFUNC; 07853 }
Definition at line 17777 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().
17778 { 17779 ENTERFUNC; 17780 /* Exception Handle */ 17781 if (!img) { 17782 throw NullPointerException("NULL input image"); 17783 } 17784 /* ========= img /= img1 ===================== */ 17785 17786 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17787 size_t size = (size_t)nx*ny*nz; 17788 float *img_ptr = img->get_data(); 17789 float *img1_ptr = img1->get_data(); 17790 if(img->is_complex()) { 17791 for (size_t i=0; i<size; i+=2) { 17792 if(img1_ptr[i] > 1.e-10f) { 17793 img_ptr[i] /= img1_ptr[i]; 17794 img_ptr[i+1] /= img1_ptr[i]; 17795 } else img_ptr[i] = img_ptr[i+1] = 0.0f; 17796 } 17797 } else throw ImageFormatException("Only Fourier image allowed"); 17798 17799 img->update(); 17800 17801 EXITFUNC; 17802 }
Definition at line 17748 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().
17749 { 17750 ENTERFUNC; 17751 /* Exception Handle */ 17752 if (!img) { 17753 throw NullPointerException("NULL input image"); 17754 } 17755 /* ========= img /= img1 ===================== */ 17756 17757 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17758 size_t size = (size_t)nx*ny*nz; 17759 float *img_ptr = img->get_data(); 17760 float *img1_ptr = img1->get_data(); 17761 if(img->is_complex()) { 17762 float sq2; 17763 for (size_t i=0; i<size; i+=2) { 17764 sq2 = 1.0f/(img1_ptr[i] * img1_ptr[i] + img1_ptr[i+1] * img1_ptr[i+1]); 17765 float tmp = sq2*(img_ptr[i] * img1_ptr[i] + img_ptr[i+1] * img1_ptr[i+1]) ; 17766 img_ptr[i+1] = sq2*(img_ptr[i+1] * img1_ptr[i] - img_ptr[i] * img1_ptr[i+1]) ; 17767 img_ptr[i] = tmp; 17768 } 17769 } else { 17770 for (size_t i=0; i<size; ++i) img_ptr[i] /= img1_ptr[i]; 17771 } 17772 img->update(); 17773 17774 EXITFUNC; 17775 }
Definition at line 17573 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().
17574 { 17575 ENTERFUNC; 17576 /* Exception Handle */ 17577 if (!img) { 17578 throw NullPointerException("NULL input image"); 17579 } 17580 /* ========= img /= img1 ===================== */ 17581 17582 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17583 size_t size = (size_t)nx*ny*nz; 17584 EMData * img2 = img->copy_head(); 17585 float *img_ptr =img->get_data(); 17586 float *img1_ptr = img1->get_data(); 17587 float *img2_ptr = img2->get_data(); 17588 if(img->is_complex()) { 17589 for (size_t i=0; i<size; i+=2) { 17590 if(img1_ptr[i] > 1.e-10f) { 17591 img2_ptr[i] = img_ptr[i] /img1_ptr[i]; 17592 img2_ptr[i+1] = img_ptr[i+1]/img1_ptr[i]; 17593 } else img2_ptr[i] = img2_ptr[i+1] = 0.0f; 17594 } 17595 } else throw ImageFormatException("Only Fourier image allowed"); 17596 17597 img->update(); 17598 17599 EXITFUNC; 17600 return img2; 17601 }
Definition at line 17540 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().
17541 { 17542 ENTERFUNC; 17543 /* Exception Handle */ 17544 if (!img) { 17545 throw NullPointerException("NULL input image"); 17546 } 17547 /* ============== output = img / img1 ================ */ 17548 17549 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17550 size_t size = (size_t)nx*ny*nz; 17551 EMData * img2 = img->copy_head(); 17552 float *img_ptr =img->get_data(); 17553 float *img2_ptr = img2->get_data(); 17554 float *img1_ptr = img1->get_data(); 17555 if(img->is_complex()) { 17556 float sq2; 17557 for (size_t i=0; i<size; i+=2) { 17558 sq2 = 1.0f/(img1_ptr[i] * img1_ptr[i] + img1_ptr[i+1] * img1_ptr[i+1]); 17559 img2_ptr[i] = sq2*(img_ptr[i] * img1_ptr[i] + img_ptr[i+1] * img1_ptr[i+1]) ; 17560 img2_ptr[i+1] = sq2*(img_ptr[i+1] * img1_ptr[i] - img_ptr[i] * img1_ptr[i+1]) ; 17561 } 17562 img2->set_complex(true); 17563 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17564 } else { 17565 for (size_t i=0; i<size; ++i) img2_ptr[i] = img_ptr[i] / img1_ptr[i]; 17566 img2->update(); 17567 } 17568 17569 EXITFUNC; 17570 return img2; 17571 }
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 2026 of file util.h.
Referenced by EMAN::IterationAverager::finish().
float Util::ener | ( | EMData * | ave, | |
vector< int > | numr | |||
) | [static] |
Definition at line 4467 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), numr, and PI2.
Referenced by ener_tot().
04467 { 04468 ENTERFUNC; 04469 long double ener,en; 04470 04471 int nring = numr.size()/3; 04472 float *aveptr = ave->get_data(); 04473 04474 ener = 0.0; 04475 for (int i=1; i<=nring; i++) { 04476 int numr3i = numr(3,i); 04477 int np = numr(2,i)-1; 04478 float tq = static_cast<float>(PI2*numr(1,i)/numr3i); 04479 en = tq*(aveptr[np]*aveptr[np]+aveptr[np+1]*aveptr[np+1])*0.5; 04480 for (int j=np+2; j<np+numr3i-1; j++) en += tq*aveptr[j]*aveptr[j]; 04481 ener += en/numr3i; 04482 } 04483 EXITFUNC; 04484 return static_cast<float>(ener); 04485 }
float Util::ener_tot | ( | const vector< EMData * > & | data, | |
vector< int > | numr, | |||
vector< float > | tot | |||
) | [static] |
Definition at line 4487 of file util_sparx.cpp.
References ener(), ENTERFUNC, EXITFUNC, get_data(), numr, and PI2.
04487 { 04488 ENTERFUNC; 04489 long double ener, en; 04490 float arg, cs, si; 04491 04492 int nima = data.size(); 04493 int nring = numr.size()/3; 04494 int maxrin = numr(3,nring); 04495 04496 ener = 0.0; 04497 for (int i=1; i<=nring; i++) { 04498 int numr3i = numr(3,i); 04499 int np = numr(2,i)-1; 04500 float tq = static_cast<float>(PI2*numr(1,i)/numr3i); 04501 float temp1 = 0.0, temp2 = 0.0; 04502 for (int kk=0; kk<nima; kk++) { 04503 float *ptr = data[kk]->get_data(); 04504 temp1 += ptr[np]; 04505 temp2 += static_cast<float>(ptr[np+1]*cos(PI2*(tot[kk]-1.0f)/2.0f*numr3i/maxrin)); 04506 } 04507 en = tq*(temp1*temp1+temp2*temp2)*0.5; 04508 for (int j=2; j<numr3i; j+=2) { 04509 float tempr = 0.0, tempi = 0.0; 04510 for (int kk=0; kk<nima; kk++) { 04511 float *ptr = data[kk]->get_data(); 04512 arg = static_cast<float>( PI2*(tot[kk]-1.0)*(j/2)/maxrin ); 04513 cs = cos(arg); 04514 si = sin(arg); 04515 tempr += ptr[np + j]*cs - ptr[np + j +1]*si; 04516 tempi += ptr[np + j]*si + ptr[np + j +1]*cs; 04517 } 04518 en += tq*(tempr*tempr+tempi*tempi); 04519 } 04520 ener += en/numr3i; 04521 } 04522 EXITFUNC; 04523 return static_cast<float>(ener); 04524 }
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 1223 of file util.cpp.
Referenced by EMAN::Symmetry3D::cache_au_planes().
01224 { 01225 int x=0,y=1,z=2; 01226 plane[0] = p1[y]*(p2[z]-p3[z])+p2[y]*(p3[z]-p1[z])+p3[y]*(p1[z]-p2[z]); 01227 plane[1] = p1[z]*(p2[x]-p3[x])+p2[z]*(p3[x]-p1[x])+p3[z]*(p1[x]-p2[x]); 01228 plane[2] = p1[x]*(p2[y]-p3[y])+p2[x]*(p3[y]-p1[y])+p3[x]*(p1[y]-p2[y]); 01229 plane[3] = p1[x]*(p2[y]*p3[z]-p3[y]*p2[z])+p2[x]*(p3[y]*p1[z]-p1[y]*p3[z])+p3[x]*(p1[y]*p2[z]-p2[y]*p1[z]); 01230 plane[3] = -plane[3]; 01231 }
float Util::eval | ( | char * | images, | |
EMData * | img, | |||
vector< int > | S, | |||
int | N, | |||
int | K, | |||
int | size | |||
) | [static] |
Definition at line 7188 of file util_sparx.cpp.
References EMAN::EMData::get_data(), and EMAN::EMData::read_image().
07189 { 07190 int j,d; 07191 EMData * e = new EMData(); 07192 float *eptr, *imgptr; 07193 imgptr = img->get_data(); 07194 float SSE = 0.f; 07195 for (j = 0 ; j < N ; j++) { 07196 e->read_image(images,S[j]); 07197 eptr = e->get_data(); 07198 for (d = 0; d < size; d++) { 07199 SSE += ((eptr[d] - imgptr[d])*(eptr[d] - imgptr[d]));} 07200 } 07201 delete e; 07202 return SSE; 07203 }
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 21383 of file util_sparx.cpp.
References k_means_cont_table_().
Referenced by initial_prune().
21383 { 21384 21385 21386 if (size_next <= T) return 0; 21387 21388 // take the intx of next and cur 21389 int* curintx2(0); 21390 int nintx = Util::k_means_cont_table_(curintx, next+2, curintx2, size_curintx, size_next,0); 21391 if (nintx <= T) return 0; 21392 21393 int old_depth=depth; 21394 if (depth == partref) depth = depth + 1; // we skip classes in partref 21395 if (depth == nParts && old_depth>0) return 1; 21396 21397 // have not yet reached a leaf, and current weight is still greather than T, so keep on going. 21398 21399 curintx2 = new int[nintx]; // put the intersection set in here 21400 Util::k_means_cont_table_(curintx,next+2,curintx2, size_curintx, size_next,1); 21401 21402 // if (old_depth > 0) {delete[] curintx;} // don't delete when depth == 0 because curintx in that case is a pointer into Parts 21403 21404 // we now consider each of the classes in partition (depth+1) in turn 21405 bool gt_thresh; 21406 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 21407 21408 for (int i=0; i < num_classes; i++){ 21409 if (Parts[depth][i][1] < 1) continue; // class is not active so move on 21410 size_next = dimClasses[depth*K + Parts[depth][i][0] ]-2; 21411 gt_thresh = explore(Parts,dimClasses, nParts, K, T, partref, curintx2,nintx, Parts[depth][i], size_next, depth+1); 21412 if (gt_thresh) { delete[] curintx2; return 1; } 21413 } 21414 delete[] curintx2; 21415 return 0; 21416 }
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 21217 of file util_sparx.cpp.
References explore2(), and k_means_cont_table_().
21217 { 21218 21219 // depth is the level which is going to be explored in the current iteration 21220 int* curintx2(0); 21221 int nintx = size_curintx; 21222 21223 21224 // 2. take the intx of next and cur. Prune if <= T 21225 if (depth >0){ 21226 nintx = Util::k_means_cont_table_(curintx,next, curintx2, size_curintx, size_next,0); 21227 if (nintx <= T) return; //prune! 21228 } 21229 21230 // 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 21231 if (depth == (nParts-1)) { 21232 21233 int replace = 0; 21234 int ind_smallest = -1; 21235 int smallest_cost = -1; 21236 21237 for (int jit = 0; jit < J; jit++){ 21238 if (*(costlist+jit) < nintx){ 21239 replace = 1; 21240 if (ind_smallest == -1) {ind_smallest = jit; smallest_cost = *(costlist+jit);} 21241 if (*(costlist+jit) < smallest_cost) {ind_smallest = jit; smallest_cost = *(costlist+jit);} 21242 } 21243 } 21244 21245 if (replace > 0){ 21246 // replace the smallest cost in matchlist with the current stuff 21247 *(costlist + ind_smallest) = nintx; 21248 for (int xit = 0; xit < nParts; xit++) 21249 *(matchlist + ind_smallest*nParts + xit) = *(curbranch+xit); 21250 21251 } 21252 21253 return; 21254 } 21255 21256 21257 // 3. have not yet reached a leaf, and current weight is still greather than T, so keep on going. 21258 21259 if (depth > 0){ 21260 curintx2 = new int[nintx]; // put the intersection set in here 21261 Util::k_means_cont_table_(curintx,next,curintx2, size_curintx, size_next,1); 21262 } 21263 21264 if (depth == 0){ 21265 // set curintx2 to curintx 21266 curintx2 = new int[size_curintx]; 21267 for (int cp = 0; cp < size_curintx; cp++) *(curintx2+cp) = *(curintx+cp); 21268 } 21269 21270 21271 // recursion (non-leaf case) 21272 depth=depth+1; 21273 // we now consider each of the classes in partition depth and recurse upon each of them 21274 for (int i=0; i < K; i++){ 21275 21276 if (*(argParts + Indices[depth*K+i] + 1) < 1) continue; // class is not active so move on 21277 size_next = (*(dimClasses + depth*K+i ))-2; 21278 if (size_next <= T) continue; 21279 *(curbranch+depth) = i; 21280 Util::explore2(argParts,Indices, dimClasses, nParts, K, T, curintx2, nintx, argParts + Indices[depth*K+i] + 2, size_next, depth,J, matchlist, 21281 costlist, curbranch); 21282 21283 } 21284 21285 delete[] curintx2; 21286 }
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 783 of file util.cpp.
00783 { 00784 if (f>=1.0) return 0.0; 00785 if (f<=-1.0) return M_PI; 00786 00787 static float *mem = (float *)malloc(sizeof(float)*2001); 00788 static bool needinit=true; 00789 00790 00791 if (needinit) { 00792 needinit=false; 00793 for (int i=0; i<=2000; i++) mem[i]=(float)acos(i/1000.0-1.0); 00794 } 00795 float f2=f*1000.0f+1000.0f; 00796 00797 int g=(int)(f2+.5); 00798 00799 return mem[g]; 00800 00801 // This version interpolates, but is slower 00802 /*int g=(int)f2; 00803 f2-=g; 00804 return mem[g+1]*f2+mem[g]*(1.0-f2);*/ 00805 }
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 767 of file util.cpp.
Referenced by EMAN::FourierInserter3DMode5::insert_pixel(), EMAN::FourierInserter3DMode3::insert_pixel(), EMAN::FourierInserter3DMode2::insert_pixel(), EMAN::WienerFourierReconstructor::pixel_at(), and EMAN::FourierReconstructor::pixel_at().
00767 { 00768 static float *mem = (float *)malloc(sizeof(float)*1000); 00769 static bool needinit=true; 00770 00771 if (needinit) { 00772 needinit=false; 00773 for (int i=0; i<1000; i++) mem[i]=(float)exp(-i/50.0); 00774 } 00775 if (f>0 || f<-19.98) return exp(f); 00776 int g=(int)(-f*50.0+0.5); 00777 00778 return mem[g]; 00779 }
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 1742 of file util.h.
Referenced by EMAN::CtfAverager::add_image(), EMAN::MaskEdgeMeanProcessor::calc_locals(), EMAN::CircularMaskProcessor::calc_locals(), EMAN::EMData::cut_slice(), EMAN::EMData::dot_rotate_translate(), EMAN::EMData::extract_box(), EMAN::CtfAverager::finish(), mono(), 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(), Crosrng_psi_0_180_no_mirror(), 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 137 of file util.cpp.
References LOGERR, and NullPointerException.
00138 { 00139 #ifdef WIN32 00140 return 1; 00141 #else 00142 00143 if (!file) { 00144 throw NullPointerException("Tried to lock NULL file"); 00145 } 00146 00147 int fdes = fileno(file); 00148 00149 struct flock fl; 00150 fl.l_type = F_WRLCK; 00151 fl.l_whence = SEEK_SET; 00152 fl.l_start = 0; 00153 fl.l_len = 0; 00154 #ifdef WIN32 00155 fl.l_pid = _getpid(); 00156 #else 00157 fl.l_pid = getpid(); 00158 #endif 00159 00160 #if defined __sgi 00161 fl.l_sysid = getpid(); 00162 #endif 00163 00164 int err = 0; 00165 if (fcntl(fdes, F_SETLKW, &fl) == -1) { 00166 LOGERR("file locking error! NFS problem?"); 00167 00168 int i = 0; 00169 for (i = 0; i < 5; i++) { 00170 if (fcntl(fdes, F_SETLKW, &fl) != -1) { 00171 break; 00172 } 00173 else { 00174 #ifdef WIN32 00175 Sleep(1000); 00176 #else 00177 sleep(1); 00178 #endif 00179 00180 } 00181 } 00182 if (i == 5) { 00183 LOGERR("Fatal file locking error"); 00184 err = 1; 00185 } 00186 } 00187 00188 return err; 00189 #endif 00190 }
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 814 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().
00815 { 00816 Assert(nitems > 0); 00817 00818 if (!data || !max_val || !max_index) { 00819 throw NullPointerException("data/max_val/max_index"); 00820 } 00821 float max = -FLT_MAX; 00822 int m = 0; 00823 00824 for (size_t i = 0; i < nitems; i++) { 00825 if (data[i] > max) { 00826 max = data[i]; 00827 m = (int)i; 00828 } 00829 } 00830 00831 *max_val = (float)max; 00832 00833 if (max_index) { 00834 *max_index = m; 00835 } 00836 }
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 838 of file util.cpp.
References Assert, max, min, and NullPointerException.
00841 { 00842 Assert(nitems > 0); 00843 00844 if (!data || !max_val || !min_val || !max_index || !min_index) { 00845 throw NullPointerException("data/max_val/min_val/max_index/min_index"); 00846 } 00847 float max = -FLT_MAX; 00848 float min = FLT_MAX; 00849 int max_i = 0; 00850 int min_i = 0; 00851 00852 for (size_t i = 0; i < nitems; i++) { 00853 if (data[i] > max) { 00854 max = data[i]; 00855 max_i = (int)i; 00856 } 00857 if (data[i] < min) { 00858 min = data[i]; 00859 min_i = (int)i; 00860 } 00861 } 00862 00863 *max_val = max; 00864 *min_val = min; 00865 00866 if (min_index) { 00867 *min_index = min_i; 00868 } 00869 00870 if (max_index) { 00871 *max_index = max_i; 00872 } 00873 00874 }
void Util::flip23 | ( | double * | x, | |
double * | y, | |||
double * | z, | |||
int * | key, | |||
int | k, | |||
int | len | |||
) | [static] |
Definition at line 7879 of file util_sparx.cpp.
References ENTERFUNC, and EXITFUNC.
Referenced by voronoi().
07880 { 07881 ENTERFUNC; 07882 int i = k; 07883 while( i == k ) i = rand()%len; 07884 std::swap(key[i], key[k]); 07885 std::swap(x[i], x[k]); 07886 std::swap(y[i], y[k]); 07887 std::swap(z[i], z[k]); 07888 EXITFUNC; 07889 }
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 82 of file util.cpp.
References Assert, and NullPointerException.
00083 { 00084 Assert(n > 0); 00085 00086 if (!data) { 00087 throw NullPointerException("pixel data array"); 00088 } 00089 00090 for (size_t i = 0; i < n; i += 2) { 00091 data[i + 1] *= -1; 00092 } 00093 }
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 217 of file util.cpp.
References Assert, and NullPointerException.
00218 { 00219 if (!data) { 00220 throw NullPointerException("image data array"); 00221 } 00222 Assert(nx > 0); 00223 Assert(ny > 0); 00224 00225 float *buf = new float[nx]; 00226 size_t row_size = nx * sizeof(float); 00227 00228 for (size_t i = 0; i < ny / 2; i++) { 00229 memcpy(buf, &data[i * nx], row_size); 00230 memcpy(&data[i * nx], &data[(ny - 1 - i) * nx], row_size); 00231 memcpy(&data[(ny - 1 - i) * nx], buf, row_size); 00232 } 00233 00234 if( buf ) 00235 { 00236 delete[]buf; 00237 buf = 0; 00238 } 00239 }
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(), 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 20414 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().
20415 { 20416 int nx = mg->get_xsize(); 20417 int ny = mg->get_ysize(); 20418 int nz = mg->get_zsize(); 20419 20420 EMData* visited = new EMData(); 20421 visited->set_size( nx, ny, nz ); 20422 visited->to_zero(); 20423 int grpid = 0; 20424 int maxgrp = 0; 20425 int maxsize = 0; 20426 for( int iz=0; iz < nz; ++iz ) { 20427 for( int iy=0; iy < ny; ++iy ) { 20428 for( int ix=0; ix < nx; ++ix ) { 20429 if( (*mg)(ix, iy, iz)==0.0 ) continue; 20430 20431 if( (*visited)(ix, iy, iz) > 0.0 ) { 20432 // visited before, must be in other group. 20433 continue; 20434 } 20435 20436 grpid++; 20437 int grpsize = find_group( ix, iy, iz, grpid, mg, visited ); 20438 if( grpsize > maxsize ) { 20439 maxsize = grpsize; 20440 maxgrp = grpid; 20441 } 20442 } 20443 } 20444 } 20445 20446 Assert( maxgrp > 0 ); 20447 20448 int npoint = 0; 20449 EMData* result = new EMData(); 20450 result->set_size( nx, ny, nz ); 20451 result->to_zero(); 20452 20453 for( int iz=0; iz < nz; ++iz ) { 20454 for( int iy=0; iy < ny; ++iy ) { 20455 for( int ix=0; ix < nx; ++ix ) { 20456 if( (*visited)(ix, iy, iz)==maxgrp ) { 20457 (*result)(ix,iy,iz) = 1.0; 20458 npoint++; 20459 } 20460 } 20461 } 20462 } 20463 20464 Assert( npoint==maxsize ); 20465 delete visited; 20466 return result; 20467 20468 }
string Util::get_filename_ext | ( | const string & | filename | ) | [static] |
Get a filename's extension.
[in] | filename | A given filename. |
Definition at line 492 of file util.cpp.
Referenced by EMAN::EMUtil::fast_get_image_type(), EMAN::EMUtil::get_image_type(), and EMAN::EMUtil::is_valid_filename().
00493 { 00494 if (filename == "") { 00495 return ""; 00496 } 00497 00498 string result = ""; 00499 const char *ext = strrchr(filename.c_str(), '.'); 00500 if (ext) { 00501 ext++; 00502 result = string(ext); 00503 } 00504 return result; 00505 }
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 707 of file util.cpp.
References EMAN::Randnum::get_frand(), and EMAN::Randnum::Instance().
00708 { 00709 Randnum* randnum = Randnum::Instance(); 00710 return randnum->get_frand(lo, hi); 00711 }
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 701 of file util.cpp.
References EMAN::Randnum::get_frand(), and EMAN::Randnum::Instance().
00702 { 00703 Randnum* randnum = Randnum::Instance(); 00704 return randnum->get_frand(lo, hi); 00705 }
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 696 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().
00697 { 00698 return get_frand((float)lo, (float)hi); 00699 }
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 808 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().
00809 { 00810 Randnum* randnum = Randnum::Instance(); 00811 return randnum->get_gauss_rand(mean, sigma); 00812 }
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 690 of file util.cpp.
References EMAN::Randnum::get_irand(), and EMAN::Randnum::Instance().
Referenced by EMAN::KMeansAnalyzer::analyze(), cluster_pairwise(), move_points(), and EMAN::KMeansAnalyzer::reseed().
00691 { 00692 Randnum* randnum = Randnum::Instance(); 00693 return randnum->get_irand(lo, hi); 00694 }
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 267 of file util.cpp.
References NullPointerException.
Referenced by EMAN::XplorIO::is_valid(), and EMAN::SitusIO::is_valid().
00268 { 00269 if (!slines || !(*slines)) { 00270 throw NullPointerException("Null string"); 00271 } 00272 00273 string result = ""; 00274 char *str = *slines; 00275 00276 while (*str != '\n' && *str != '\0') { 00277 result.push_back(*str); 00278 str++; 00279 } 00280 if (*str != '\0') { 00281 str++; 00282 } 00283 *slines = str; 00284 00285 return result; 00286 }
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 1858 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 1781 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 EMAN::EMData::helicise_grid(), Polar2Dmi(), EMAN::EMData::rot_scale_conv_new(), and EMAN::EMData::rot_scale_conv_new_3D().
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().
Referenced by EMAN::EMData::rot_scale_conv_new_background(), and EMAN::EMData::rot_scale_conv_new_background_3D().
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 684 of file util.cpp.
References EMAN::Randnum::get_seed(), and EMAN::Randnum::Instance().
00685 { 00686 Randnum* randnum = Randnum::Instance(); 00687 return randnum->get_seed(); 00688 }
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 20944 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().
20944 { 20945 20946 int nx = vol->get_xsize(); 20947 int ny = vol->get_ysize(); 20948 int nz = vol->get_zsize(); 20949 float *vol_data = vol->get_data(); 20950 int new_nx, new_ny; 20951 20952 if (nz == 1) 20953 throw ImageDimensionException("Error: Input must be a 3-D object"); 20954 if ((dim < 1) || (dim > 3)) 20955 throw ImageDimensionException("Error: dim must be 1 (x-dimension), 2 (y-dimension) or 3 (z-dimension)"); 20956 if (((dim == 1) && (index < 0 || index > nx-1)) || 20957 ((dim == 1) && (index < 0 || index > nx-1)) || 20958 ((dim == 1) && (index < 0 || index > nx-1))) 20959 throw ImageDimensionException("Error: index exceeds the size of the 3-D object"); 20960 20961 if (dim == 1) { 20962 new_nx = ny; 20963 new_ny = nz; 20964 } else if (dim == 2) { 20965 new_nx = nx; 20966 new_ny = nz; 20967 } else { 20968 new_nx = nx; 20969 new_ny = ny; 20970 } 20971 20972 EMData *slice = new EMData(); 20973 slice->set_size(new_nx, new_ny, 1); 20974 float *slice_data = slice->get_data(); 20975 20976 if (dim == 1) { 20977 for (int x=0; x<new_nx; x++) 20978 for (int y=0; y<new_ny; y++) 20979 slice_data[y*new_nx+x] = vol_data[(y*ny+x)*nx+index]; 20980 } else if (dim == 2) { 20981 for (int x=0; x<new_nx; x++) 20982 for (int y=0; y<new_ny; y++) 20983 slice_data[y*new_nx+x] = vol_data[(y*ny+index)*nx+x]; 20984 } else { 20985 for (int x=0; x<new_nx; x++) 20986 for (int y=0; y<new_ny; y++) 20987 slice_data[y*new_nx+x] = vol_data[((size_t)index*ny+y)*nx+x]; 20988 } 20989 20990 return slice; 20991 }
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 876 of file util.cpp.
References EmptyContainerException, mean(), sqrt(), and square_sum().
00877 { 00878 // Note that this is a heavy STL approach using generic algorithms - some memory could be saved 00879 // using plain c style code, as in get_stats_cstyle below 00880 00881 if (data.size() == 0) EmptyContainerException("Error, attempting to call get stats on an empty container (vector<double>)"); 00882 00883 double sum = accumulate(data.begin(), data.end(), 0.0); 00884 00885 double mean = sum / static_cast<double> (data.size()); 00886 00887 double std_dev = 0.0, skewness = 0.0, kurtosis = 0.0; 00888 00889 if (data.size() > 1) 00890 { 00891 // read mm is "minus_mean" 00892 vector<double> data_mm(data.size()); 00893 // read ts as "then squared" 00894 vector<double> data_mm_sq(data.size()); 00895 00896 // Subtract the mean from the data and store it in data_mm 00897 transform(data.begin(), data.end(), data_mm.begin(), std::bind2nd(std::minus<double>(), mean)); 00898 00899 // Get the square of the data minus the mean and store it in data_mm_sq 00900 transform(data_mm.begin(), data_mm.end(), data_mm.begin(), data_mm_sq.begin(), std::multiplies<double>()); 00901 00902 // Get the sum of the squares for the calculation of the standard deviation 00903 double square_sum = accumulate(data_mm_sq.begin(), data_mm_sq.end(), 0.0); 00904 00905 //Calculate teh standard deviation 00906 std_dev = sqrt(square_sum / static_cast<double>(data.size()-1)); 00907 double std_dev_sq = std_dev * std_dev; 00908 00909 // The numerator for the skewness fraction, as defined in http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm 00910 double cubic_sum = inner_product(data_mm.begin(), data_mm.end(),data_mm_sq.begin(), 0.0); 00911 00912 // The numerator for the kurtosis fraction, as defined in http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm 00913 double quartic_sum = inner_product(data_mm_sq.begin(), data_mm_sq.end(),data_mm_sq.begin(), 0.0); 00914 00915 // Finalize the calculation of the skewness and kurtosis, as defined in 00916 // http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm 00917 skewness = cubic_sum / ((data.size()-1) * std_dev_sq * std_dev ); 00918 kurtosis = quartic_sum / ((data.size()-1) * std_dev_sq * std_dev_sq ); 00919 00920 } 00921 00922 Dict parms; 00923 parms["mean"] = mean; 00924 parms["std_dev"] = std_dev; 00925 parms["skewness"] = skewness; 00926 parms["kurtosis"] = kurtosis; 00927 00928 return parms; 00929 }
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 932 of file util.cpp.
References EmptyContainerException, mean(), sqrt(), square(), and square_sum().
00933 { 00934 if (data.size() == 0) EmptyContainerException("Error, attempting to call get stats on an empty container (vector<double>)"); 00935 00936 double square_sum = 0.0, sum = 0.0, cube_sum = 0.0, quart_sum = 0.0; 00937 for( vector<float>::const_iterator it = data.begin(); it != data.end(); ++it ) 00938 { 00939 double val = *it; 00940 double square = val*val; 00941 quart_sum += square*square; 00942 cube_sum += square*val; 00943 square_sum += square; 00944 sum += val; 00945 } 00946 00947 double mean = sum/(double)data.size(); 00948 00949 double std_dev = 0.0, skewness = 0.0, kurtosis = 0.0; 00950 00951 if (data.size() > 1) 00952 { 00953 // The standard deviation is calculated here 00954 std_dev = sqrt( (square_sum - mean*sum)/(double)(data.size()-1)); 00955 00956 double square_mean = mean*mean; 00957 double cube_mean = mean*square_mean; 00958 00959 double square_std_dev = std_dev*std_dev; 00960 00961 // This is the numerator of the skewness fraction, if you expand the brackets, as defined in 00962 // http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm 00963 double cubic_sum = cube_sum - 3*square_sum*mean + 3*sum*square_mean - cube_mean*data.size(); 00964 // Complete the skewness fraction 00965 skewness = cubic_sum/((data.size()-1)*square_std_dev*std_dev); 00966 00967 // This is the numerator of the kurtosis fraction, if you expand the brackets, as defined in 00968 // http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm 00969 double quartic_sum = quart_sum - 4*cube_sum*mean + 6*square_sum*square_mean - 4*sum*cube_mean + square_mean*square_mean*data.size(); 00970 // Complete the kurtosis fraction 00971 kurtosis = quartic_sum /( (data.size()-1)*square_std_dev*square_std_dev); 00972 } 00973 00974 Dict parms; 00975 parms["mean"] = mean; 00976 parms["std_dev"] = std_dev; 00977 parms["skewness"] = skewness; 00978 parms["kurtosis"] = kurtosis; 00979 00980 return parms; 00981 }
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 359 of file util.cpp.
References NullPointerException.
00361 { 00362 if (!s || !float_var || !p_v0 || !p_v1 || !p_v2) { 00363 throw NullPointerException("string float"); 00364 } 00365 00366 size_t n = strlen(float_var); 00367 *p_v0 = 0; 00368 if (strncmp(s, float_var, n) == 0) { 00369 if (s[n] == '=') { 00370 *p_v0 = 2; 00371 sscanf(&s[n + 1], "%f,%f", p_v1, p_v2); 00372 } 00373 else { 00374 *p_v0 = 1; 00375 } 00376 return true; 00377 } 00378 return false; 00379 }
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 344 of file util.cpp.
References NullPointerException.
00345 { 00346 if (!s || !float_var || !p_v1 || !p_v2) { 00347 throw NullPointerException("string float"); 00348 } 00349 00350 size_t n = strlen(float_var); 00351 if (strncmp(s, float_var, n) == 0) { 00352 sscanf(&s[n], "%f,%f", p_v1, p_v2); 00353 return true; 00354 } 00355 00356 return false; 00357 }
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 330 of file util.cpp.
References NullPointerException.
00331 { 00332 if (!s || !float_var || !p_val) { 00333 throw NullPointerException("string float"); 00334 } 00335 size_t n = strlen(float_var); 00336 if (strncmp(s, float_var, n) == 0) { 00337 *p_val = (float) atof(&s[n]); 00338 return true; 00339 } 00340 00341 return false; 00342 }
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 409 of file util.cpp.
References NullPointerException.
00410 { 00411 if (!s || !int_var || !p_v0 || !p_v1 || !p_v2) { 00412 throw NullPointerException("string int"); 00413 } 00414 00415 size_t n = strlen(int_var); 00416 *p_v0 = 0; 00417 if (strncmp(s, int_var, n) == 0) { 00418 if (s[n] == '=') { 00419 *p_v0 = 2; 00420 sscanf(&s[n + 1], "%d,%d", p_v1, p_v2); 00421 } 00422 else { 00423 *p_v0 = 1; 00424 } 00425 return true; 00426 } 00427 return false; 00428 }
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 395 of file util.cpp.
References NullPointerException.
00396 { 00397 if (!s || !int_var || !p_v1 || !p_v2) { 00398 throw NullPointerException("string int"); 00399 } 00400 00401 size_t n = strlen(int_var); 00402 if (strncmp(s, int_var, n) == 0) { 00403 sscanf(&s[n], "%d,%d", p_v1, p_v2); 00404 return true; 00405 } 00406 return false; 00407 }
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 381 of file util.cpp.
References NullPointerException.
00382 { 00383 if (!s || !int_var || !p_val) { 00384 throw NullPointerException("string int"); 00385 } 00386 00387 size_t n = strlen(int_var); 00388 if (strncmp(s, int_var, n) == 0) { 00389 *p_val = atoi(&s[n]); 00390 return true; 00391 } 00392 return false; 00393 }
string Util::get_time_label | ( | ) | [static] |
Get the current time in a string with format "mm/dd/yyyy hh:mm".
Definition at line 1097 of file util.cpp.
References t.
01098 { 01099 time_t t0 = time(0); 01100 struct tm *t = localtime(&t0); 01101 char label[32]; 01102 sprintf(label, "%d/%02d/%04d %d:%02d", 01103 t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour, t->tm_min); 01104 return string(label); 01105 }
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 1162 of file util.cpp.
References abs, printmatrix(), printvector(), q, rhs, V, and W.
Referenced by EMAN::FourierInserter3DMode8::init().
01163 { 01164 int i = 0; 01165 int discs = (int)(1+2*freq_cutoff/dfreq); 01166 01167 float* W = new float[discs]; 01168 01169 int fc = (int)(2*freq_cutoff + 1); 01170 gsl_matrix* M = gsl_matrix_calloc(fc,fc); 01171 01172 gsl_vector* rhs = gsl_vector_calloc(fc); 01173 cout << i++ << endl; 01174 for(int k = -freq_cutoff; k <= freq_cutoff; ++k){ 01175 for(int kp = -freq_cutoff; kp <= freq_cutoff; ++kp){ 01176 int kdiff =abs( k-kp); 01177 int evenoddfac = ( kdiff % 2 == 0 ? 1 : -1); 01178 01179 if (kdiff !=0){ 01180 float val = sin(M_PI*(float)kdiff*r)/(sin(M_PI*(float)kdiff/(float)P))*(alpha+2.0f*beta*evenoddfac); 01181 gsl_matrix_set(M,int(k+freq_cutoff),int(kp+freq_cutoff),val); 01182 } 01183 } 01184 gsl_matrix_set(M,int(k+freq_cutoff),int(k+freq_cutoff),r*P* (alpha+2*beta)); 01185 float val = alpha*sin(M_PI*k*r)/(sin(M_PI*(float)k/(float)P)); 01186 if (k!=0) { 01187 gsl_vector_set(rhs,int(k+freq_cutoff),val); 01188 } 01189 } 01190 printmatrix(M,fc,fc,"M"); 01191 01192 gsl_vector_set(rhs,int(freq_cutoff),alpha*r*P); 01193 gsl_matrix* V = gsl_matrix_calloc(fc,fc); 01194 gsl_vector* S = gsl_vector_calloc(fc); 01195 gsl_vector* soln = gsl_vector_calloc(fc); 01196 gsl_linalg_SV_decomp(M,V,S,soln); 01197 01198 gsl_linalg_SV_solve(M, V, S, rhs, soln); // soln now runs from -freq_cutoff to + freq_cutoff 01199 printvector(soln,fc,"soln"); 01200 01201 // we want to solve for W, which ranges from -freq_cutoff to +freq_cutoff in steps of dfreq 2 01202 int Count=0; 01203 for(float q = (float)(-freq_cutoff); q <= (float)(freq_cutoff); q+= dfreq){ 01204 float temp=0; 01205 for(int k = -freq_cutoff; k <= freq_cutoff; ++k){ 01206 float dtemp; 01207 if (q!=k) { 01208 dtemp=(1/(float) P)* (float)gsl_vector_get(soln,int(k+freq_cutoff)) * sin(M_PI*(q-k))/sin(M_PI*(q-k)/((float) P)); 01209 } else{ 01210 dtemp = (1/(float) P)* (float)gsl_vector_get(soln,int(k+freq_cutoff)) * P; 01211 } 01212 temp +=dtemp; 01213 } 01214 W[Count]=temp; 01215 cout << W[Count] << " "; 01216 Count+=1; 01217 } 01218 cout << endl; 01219 return W; 01220 }
static void EMAN::Util::getvec | ( | float | phi, | |
float | theta, | |||
float & | x, | |||
float & | y, | |||
float & | z, | |||
int | option = 0 | |||
) | [inline, static] |
Definition at line 935 of file util.h.
Referenced by assign_projangles(), group_proj_by_phitheta(), and nearestk_to_refdir().
00938 { 00939 #ifndef WIN32 00940 return copysign(a, b); 00941 #else 00942 int flip = -1; 00943 if ((a <= 0 && b <= 0) || (a > 0 && b > 0)) { 00944 flip = 1; 00945 } 00946 return a * flip; 00947 #endif 00948 } 00949
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 1954 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 18188 of file util_sparx.cpp.
References ang_diff(), assign_projangles(), getvec(), max, q, sqrt(), and v.
18188 { 18189 float c = 100.0; 18190 int L = max(100, img_per_grp); 18191 int N = projangles.size()/2; 18192 18193 int sz = ref_ang.size(); 18194 int nref1 = ref_ang[sz-4]; 18195 int nref2 = ref_ang[sz-3]; 18196 int nref3 = ref_ang[sz-2]; 18197 int nref4 = ref_ang[sz-1]; 18198 int nref; 18199 18200 set<int> pt; 18201 for (int i=0; i<N; i++) pt.insert(i); 18202 vector<float> v(N*3, 0.0f); 18203 for (int i=0; i<N; i++) 18204 getvec(projangles[i*2], projangles[i*2+1], v[i*3], v[i*3+1], v[i*3+2], 1); 18205 18206 int previous_group = -1; 18207 int previous_zone = 5; 18208 int max_group = 0; 18209 vector<float> ref_ang_list; 18210 vector<float> diff_table; 18211 map<int, int> diff_table_index; 18212 vector<int> proj_list; 18213 vector<int> sg; 18214 vector<int> remain_index; 18215 vector<int> asg; 18216 int mirror; 18217 for (int grp=0; grp<N/img_per_grp; grp++) { 18218 int N_remain = N-grp*img_per_grp; 18219 assert(N_remain == static_cast<int>(pt.size())); 18220 if (N_remain >= nref4*L) { 18221 if (previous_zone > 4) { 18222 ref_ang_list.resize(nref4*2); 18223 for (int i=0; i<nref4*2; i++) ref_ang_list[i] = ref_ang[(nref1+nref2+nref3)*2+i]; 18224 nref = nref4; 18225 previous_group = -1; 18226 previous_zone = 4; 18227 } 18228 } else if (N_remain >= nref3*L) { 18229 if (previous_zone > 3) { 18230 ref_ang_list.resize(nref3*2); 18231 for (int i=0; i<nref3*2; i++) ref_ang_list[i] = ref_ang[(nref1+nref2)*2+i]; 18232 nref = nref3; 18233 previous_group = -1; 18234 previous_zone = 3; 18235 } 18236 } else if (N_remain >= nref2*L) { 18237 if (previous_zone > 2) { 18238 ref_ang_list.resize(nref2*2); 18239 for (int i=0; i<nref2*2; i++) ref_ang_list[i] = ref_ang[nref1*2+i]; 18240 nref = nref2; 18241 previous_group = -1; 18242 previous_zone = 2; 18243 } 18244 } else if (N_remain >= nref1*L) { 18245 if (previous_zone > 1) { 18246 ref_ang_list.resize(nref1*2); 18247 for (int i=0; i<nref1*2; i++) ref_ang_list[i] = ref_ang[i]; 18248 nref = nref1; 18249 previous_group = -1; 18250 previous_zone = 1; 18251 } 18252 } else if (previous_zone > 0) { 18253 previous_group = -1; 18254 previous_zone = 0; 18255 } 18256 18257 vector<int> index; 18258 if (N_remain >= nref1*L) { 18259 if (previous_group == -1) { // which means it just changed zone 18260 vector<float> proj_ang_list(N_remain*2, 0.0f); 18261 remain_index.resize(N_remain); 18262 int l = 0; 18263 for (set<int>::const_iterator si = pt.begin(); si != pt.end(); ++si) { 18264 remain_index[l] = (*si); 18265 proj_ang_list[l*2] = projangles[(*si)*2]; 18266 proj_ang_list[l*2+1] = projangles[(*si)*2+1]; 18267 l++; 18268 } 18269 assert(N_remain == l); 18270 asg = assign_projangles(proj_ang_list, ref_ang_list); 18271 sg.resize(nref); 18272 for (int i=0; i<nref; i++) sg[i] = 0; 18273 for (int i=0; i<N_remain; i++) sg[asg[i]]++; 18274 } 18275 int max_group_size = 0; 18276 for (int i=0; i<nref; i++) 18277 if (sg[i] > max_group_size) { max_group_size = sg[i]; max_group = i; } 18278 for (unsigned int i=0; i<remain_index.size(); i++) 18279 if (asg[i] == max_group) index.push_back(remain_index[i]); 18280 } else { 18281 for (set<int>::const_iterator si = pt.begin(); si != pt.end(); ++si) 18282 index.push_back(*si); 18283 max_group = 0; 18284 } 18285 18286 int Nn = index.size(); 18287 if (max_group != previous_group) { 18288 diff_table.resize(Nn*Nn); 18289 diff_table_index.clear(); 18290 for (int i=0; i<Nn-1; i++) 18291 for (int j=i+1; j<Nn; j++) { 18292 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); 18293 float q = exp(-c*pow(diff/180.0f*static_cast<float>(M_PI), 2.0f)); 18294 diff_table[i*Nn+j] = q; 18295 diff_table[j*Nn+i] = q; 18296 } 18297 for (int i=0; i<Nn; i++) { 18298 diff_table[i*Nn+i] = 0.0f; // diagonal values 18299 diff_table_index[index[i]] = i; 18300 } 18301 previous_group = max_group; 18302 } 18303 18304 int diff_table_size = static_cast<int>(sqrt((float)diff_table.size())+0.5f); 18305 float max_density = -1; 18306 int max_density_i = -1; 18307 for (int i=0; i<Nn; i++) { 18308 float s = 0.0f; 18309 int z = diff_table_index[index[i]]; 18310 for (int j=0; j<diff_table_size; j++) s += diff_table[z*diff_table_size+j]; 18311 if (s > max_density) { 18312 max_density = s; 18313 max_density_i = i; 18314 } 18315 } 18316 18317 vector<d_ang> dang(Nn, d_ang(0.0, 0, 0)); 18318 for (int i=0; i<Nn; i++) { 18319 dang[i].d = ang_diff(v[index[i]*3], v[index[i]*3+1], v[index[i]*3+2], 18320 v[index[max_density_i]*3], v[index[max_density_i]*3+1], v[index[max_density_i]*3+2], mirror); 18321 dang[i].mirror = mirror; 18322 dang[i].i = i; 18323 } 18324 dang[max_density_i].d = -1; 18325 sort(dang.begin(), dang.end()); 18326 18327 for (int i=0; i<img_per_grp; i++) { 18328 int idd = index[dang[i].i]; 18329 mirror = dang[i].mirror; 18330 for (unsigned int j=0; j<remain_index.size(); j++) 18331 if (idd == remain_index[j]) asg[j] = -1; 18332 for (int j=0; j<diff_table_size; j++) { 18333 diff_table[diff_table_index[idd]*diff_table_size+j] = 0.0f; 18334 diff_table[diff_table_index[idd]+diff_table_size*j] = 0.0f; 18335 } 18336 proj_list.push_back(mirror*idd); 18337 pt.erase(idd); 18338 } 18339 sg[max_group] -= img_per_grp; 18340 } 18341 for (set<int>::const_iterator si = pt.begin(); si != pt.end(); ++si) { 18342 proj_list.push_back(*si); 18343 } 18344 return proj_list; 18345 }
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 5681 of file util_sparx.cpp.
References EMAN::EMData::get_data(), and img_ptr.
05682 { 05683 float *img_ptr = img->get_data(); 05684 float *mask_ptr = (mask == NULL)?img->get_data():mask->get_data(); 05685 05686 int *img_freq_bin = new int[3*hist_len]; 05687 for(int i = 0;i < (3*hist_len);i++) img_freq_bin[i] = 0; 05688 for(size_t i = 0;i < size_img;++i) { 05689 if(mask_ptr[i] > 0.5f) { 05690 float img_xn = img_ptr[i]*PA + PB; 05691 int L = static_cast<int>(((img_xn - ref_h_min)/ref_h_diff) * (hist_len-1) + hist_len+1); 05692 if(L >= 0 && L < (3*hist_len)) img_freq_bin[L]++; 05693 } 05694 } 05695 int freq_hist = 0; 05696 05697 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); 05698 freq_hist = (-freq_hist); 05699 return static_cast<float>(freq_hist); 05700 }
Definition at line 5589 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.
05590 { 05591 /* Exception Handle */ 05592 if (img->is_complex() || ref->is_complex()) 05593 throw ImageFormatException("Cannot do Histogram on Fourier Image"); 05594 05595 if(mask != NULL){ 05596 if(img->get_xsize() != mask->get_xsize() || img->get_ysize() != mask->get_ysize() || img->get_zsize() != mask->get_zsize()) 05597 throw ImageDimensionException("The size of mask image should be of same size as the input image"); } 05598 /* ===================================================== */ 05599 05600 /* Image size calculation */ 05601 size_t size_ref = ((size_t)(ref->get_xsize())*(ref->get_ysize())*(ref->get_zsize())); 05602 size_t size_img = ((size_t)(img->get_xsize())*(img->get_ysize())*(img->get_zsize())); 05603 /* ===================================================== */ 05604 05605 /* The reference image attributes */ 05606 float *ref_ptr = ref->get_data(); 05607 float ref_h_min = ref->get_attr("minimum"); 05608 float ref_h_max = ref->get_attr("maximum"); 05609 float ref_h_avg = ref->get_attr("mean"); 05610 float ref_h_sig = ref->get_attr("sigma"); 05611 /* ===================================================== */ 05612 05613 /* Input image under mask attributes */ 05614 float *mask_ptr = (mask == NULL)?img->get_data():mask->get_data(); 05615 05616 vector<float> img_data = Util::infomask(img, mask); 05617 float img_avg = img_data[0]; 05618 float img_sig = img_data[1]; 05619 05620 /* The image under mask -- size calculation */ 05621 int cnt=0; 05622 for(size_t i=0;i<size_img;++i) 05623 if (mask_ptr[i]>0.5f) 05624 cnt++; 05625 /* ===================================================== */ 05626 05627 /* Histogram of reference image calculation */ 05628 float ref_h_diff = ref_h_max - ref_h_min; 05629 05630 #ifdef _WIN32 05631 int hist_len = _cpp_min((unsigned long)size_ref/16,_cpp_min((unsigned long)size_img/16,256lu)); 05632 #else 05633 int hist_len = std::min((unsigned long)size_ref/16,std::min((unsigned long)size_img/16,256lu)); 05634 #endif //_WIN32 05635 05636 float *ref_freq_bin = new float[3*hist_len]; 05637 05638 //initialize value in each bin to zero 05639 for (int i = 0;i < (3*hist_len);i++) ref_freq_bin[i] = 0.f; 05640 05641 for (size_t i = 0;i < size_ref;++i) { 05642 int L = static_cast<int>(((ref_ptr[i] - ref_h_min)/ref_h_diff) * (hist_len-1) + hist_len+1); 05643 ref_freq_bin[L]++; 05644 } 05645 for (int i = 0;i < (3*hist_len);i++) ref_freq_bin[i] *= static_cast<float>(cnt)/static_cast<float>(size_ref); 05646 05647 //Parameters Calculation (i.e) 'A' x + 'B' 05648 float A = ref_h_sig/img_sig; 05649 float B = ref_h_avg - (A*img_avg); 05650 05651 vector<float> args; 05652 args.push_back(A); 05653 args.push_back(B); 05654 05655 vector<float> scale; 05656 scale.push_back(1.e-7f*A); 05657 scale.push_back(-1.e-7f*B); 05658 05659 vector<float> ref_freq_hist; 05660 for(int i = 0;i < (3*hist_len);i++) ref_freq_hist.push_back((int)ref_freq_bin[i]); 05661 05662 vector<float> data; 05663 data.push_back(ref_h_diff); 05664 data.push_back(ref_h_min); 05665 05666 Dict parameter; 05667 05668 /* Parameters displaying the arguments A & B, and the scaling function and the data's */ 05669 parameter["args"] = args; 05670 parameter["scale"]= scale; 05671 parameter["data"] = data; 05672 parameter["ref_freq_bin"] = ref_freq_hist; 05673 parameter["size_img"]=(double)size_img; 05674 parameter["hist_len"]=hist_len; 05675 /* ===================================================== */ 05676 05677 return parameter; 05678 }
vector< float > Util::histogram | ( | EMData * | image, | |
EMData * | mask, | |||
int | nbins = 128 , |
|||
float | hmin = 0.0f , |
|||
float | hmax = 0.0f | |||
) | [static] |
Definition at line 5531 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.
05532 { 05533 if (image->is_complex()) 05534 throw ImageFormatException("Cannot do histogram on Fourier image"); 05535 //float hmax, hmin; 05536 float *imageptr=0, *maskptr=0; 05537 int nx=image->get_xsize(); 05538 int ny=image->get_ysize(); 05539 int nz=image->get_zsize(); 05540 05541 if(mask != NULL){ 05542 if(nx != mask->get_xsize() || ny != mask->get_ysize() || nz != mask->get_zsize()) 05543 throw ImageDimensionException("The size of mask image should be of same size as the input image"); 05544 maskptr =mask->get_data(); 05545 } 05546 if( nbins == 0) nbins = nx; 05547 vector <float> freq(2*nbins, 0.0); 05548 05549 imageptr=image->get_data(); 05550 if( hmin == hmax ) { 05551 if(mask == NULL) { 05552 hmax = image->get_attr("maximum"); 05553 hmin = image->get_attr("minimum"); 05554 } else { 05555 bool First = true; 05556 for (size_t i = 0;i < (size_t)nx*ny*nz; i++) { 05557 if (maskptr[i]>=0.5f) { 05558 if(First) { 05559 hmax = imageptr[i]; 05560 hmin = imageptr[i]; 05561 First = false; 05562 } else { 05563 hmax = (hmax < imageptr[i])?imageptr[i]:hmax; 05564 hmin = (hmin > imageptr[i])?imageptr[i]:hmin; 05565 } 05566 } 05567 } 05568 } 05569 } 05570 float hdiff = hmax - hmin; 05571 float ff = (nbins-1)/hdiff; 05572 for (int i = 0; i < nbins; i++) freq[nbins+i] = hmin + (float(i)+0.5f)/ff; 05573 if(mask == NULL) { 05574 for(size_t i = 0; i < (size_t)nx*ny*nz; i++) { 05575 int jbin = static_cast<int>((imageptr[i]-hmin)*ff + 1.5); 05576 if(jbin >= 1 && jbin <= nbins) freq[jbin-1] += 1.0; 05577 } 05578 } else { 05579 for(size_t i = 0; i < (size_t)nx*ny*nz; i++) { 05580 if(maskptr[i] >= 0.5) { 05581 int jbin = static_cast<int>((imageptr[i]-hmin)*ff + 1.5); 05582 if(jbin >= 1 && jbin <= nbins) freq[jbin-1] += 1.0; 05583 } 05584 } 05585 } 05586 return freq; 05587 }
void Util::hsortd | ( | double * | theta, | |
double * | phi, | |||
int * | key, | |||
int | len, | |||
int | option | |||
) | [static] |
Definition at line 7300 of file util_sparx.cpp.
References cmp1(), cmp2(), ENTERFUNC, EXITFUNC, key, phi, and theta.
07301 { 07302 ENTERFUNC; 07303 vector<tmpstruct> tmp(len); 07304 int i; 07305 for(i = 1;i<=len;i++) 07306 { 07307 tmp[i-1].theta1 = theta(i); 07308 tmp[i-1].phi1 = phi(i); 07309 tmp[i-1].key1 = key(i); 07310 } 07311 07312 if (option == 1) sort(tmp.begin(),tmp.end(),Util::cmp1); 07313 if (option == 2) sort(tmp.begin(),tmp.end(),Util::cmp2); 07314 07315 for(i = 1;i<=len;i++) 07316 { 07317 theta(i) = tmp[i-1].theta1; 07318 phi(i) = tmp[i-1].phi1; 07319 key(i) = tmp[i-1].key1; 07320 } 07321 EXITFUNC; 07322 }
static float EMAN::Util::hypot2 | ( | float | x, | |
float | y | |||
) | [inline, static] |
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 1695 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 1673 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 713 of file util.cpp.
References abs.
Referenced by EMAN::EMData::calc_az_dist(), EMAN::EMData::calc_radial_dist(), and EMAN::EMAN2Ctf::compute_2d_complex().
00714 { 00715 static float *mem = (float *)malloc(4*128*128); 00716 static int dim = 0; 00717 x=abs(x); 00718 y=abs(y); 00719 00720 if (x>=dim || y>=dim) { 00721 if (x>2048 || y>2048) return (float)hypot((float)x,(float)y); // We won't cache anything bigger than 4096^2 00722 dim=x>=dim?x+1:dim; 00723 dim=y>=dim?y+1:dim; 00724 mem=(float*)realloc(mem,4*dim*dim); 00725 for (int y=0; y<dim; y++) { 00726 for (int x=0; x<dim; x++) { 00727 #ifdef _WIN32 00728 mem[x+y*dim]=(float)_hypot((float)x,(float)y); 00729 #else 00730 mem[x+y*dim]=hypot((float)x,(float)y); 00731 #endif 00732 } 00733 } 00734 } 00735 00736 return mem[x+y*dim]; 00737 }
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 739 of file util.cpp.
Referenced by EMAN::PhaseCmp::cmp().
00740 { 00741 static short *mem = (short *)malloc(2*128*128); 00742 static int dim = 0; 00743 x=abs(x); 00744 y=abs(y); 00745 00746 if (x>=dim || y>=dim) { 00747 if (x>4095 || y>4095) return (short)hypot((float)x,(float)y); // We won't cache anything bigger than 4096^2 00748 dim=x>=dim?x+1:dim; 00749 dim=y>=dim?y+1:dim; 00750 mem=(short*)realloc(mem,2*dim*dim); 00751 for (int y=0; y<dim; y++) { 00752 for (int x=0; x<dim; x++) { 00753 #ifdef _WIN32 00754 mem[x+y*dim]=(short)Util::round(_hypot((float)x,(float)y)); 00755 #else 00756 mem[x+y*dim]=(short)Util::round(hypot((float)x,(float)y)); 00757 #endif 00758 } 00759 } 00760 } 00761 00762 return mem[x+y*dim]; 00763 }
Definition at line 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 20993 of file util_sparx.cpp.
References array_mutation(), EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), max, min, and nx.
20993 { 20994 int nx = img->get_xsize(); 20995 float min = img->get_attr("minimum"); 20996 float max = img->get_attr("maximum"); 20997 float* img_data = img->get_data(); 20998 array_mutation(img_data, nx*nx, mutation_rate, min, max, 8, 0); 20999 return; 21000 }
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 21288 of file util_sparx.cpp.
References b, explore(), and k_means_cont_table_().
21288 { 21289 //cout<<"initial_prune\n"; 21290 // simple initial pruning. For class indClass of partition indPart: 21291 // 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 21292 // If for some partition (not equal to indPart) for which there is no such class, then return 0 immediately. 21293 21294 // 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 21295 21296 // remember when calling k_means_cont_table, the first element of each class is an index, and actual number of elements in the class 21297 // (as stored in dimClasses) should be decremented by 1 accordingly, and second is dummy variable 21298 21299 int* dummy(0); 21300 int* cref; 21301 int cref_size; 21302 int* ccomp; 21303 int ccomp_size; 21304 int nintx; 21305 for (int i=0; i < nParts; i++){ 21306 for (int j =0; j < K; j++){ 21307 21308 // consider class Parts[i][j] 21309 cref = Parts[i][j];//incr by 1 since first element is index and second is dummy 21310 cref_size = dimClasses[i*K+cref[0]]-2; 21311 21312 21313 if (cref_size <= T){ 21314 cref[0] = -1; 21315 continue; 21316 } 21317 bool done = 0; 21318 for (int a = 0; a < nParts; a++){ 21319 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 21320 bool hasActive=0; 21321 for (unsigned int b=0; b < Parts[a].size(); b++){ 21322 // get the card of the intx between Parts[i][j] and Parts[a][b] using k_means_cont_table 21323 // remember first element of each class is the index of the class 21324 ccomp = Parts[a][b]; 21325 ccomp_size= dimClasses[a*K+ccomp[0]]-2; 21326 nintx = Util::k_means_cont_table_(cref+2,ccomp+2, dummy, cref_size, ccomp_size,0); 21327 21328 21329 if (nintx <= T) 21330 ccomp[1] = 0; // class Parts[a][b] is 'inactive' for cref 21331 else{ 21332 ccomp[1] = 1; // class Parts[a][b] is 'active' for cref 21333 hasActive=1; 21334 } 21335 } 21336 // see if partition a has at least one active class.if not then we're done with cref 21337 if (hasActive < 1){ 21338 done=1; 21339 break; 21340 } 21341 21342 } 21343 21344 if (done > 0){ 21345 // remove class j from partition i 21346 21347 cref[0] = -1; // mark for deletion later 21348 continue; // move on to class Parts[i][j+1] 21349 } 21350 21351 // now we adopt more aggressive measures. we find the match with the largest weight which has class Parts[i][j] for partition i. 21352 // 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. 21353 21354 // (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. 21355 // Note that if there are ALOT of partitions, then sorting the partititions may actually take longer than the time saved by ordering hte 21356 // partitions. However, we do not have a lot of partitions, (usually around 10), so sorting time will be trivial compared to exploring time. 21357 21358 // explore returns one if there is a feasible matching containing class cref which has weight gt T, and otherwise returns 0 21359 //bool found = 1; 21360 bool found = explore(Parts, dimClasses, nParts, K, T, i, cref+2, cref_size, cref, cref_size,0); 21361 21362 if (found<1){ // There is NO feasible matching with class j (cref) with weight greater than T, so delete this class from Parts 21363 // Parts[i].erase(Parts[i].begin()+j); 21364 cref[0] = -1; 21365 } 21366 } 21367 21368 // Erase from Parts[i] all the classes that's being designated for erasure 21369 21370 for (int d = K-1; d > -1; d--){ 21371 if (Parts[i][d][0] < 0) Parts[i].erase(Parts[i].begin()+d); 21372 } 21373 21374 } 21375 //cout <<"number of classes left in each partition after initial prune\n"; 21376 // Print out how many classes are left in each partition 21377 //for (int i =0; i < nParts; i++) 21378 // cout << Parts[i].size()<<", "; 21379 //cout << "\n"; 21380 }
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 260 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 208 of file util.cpp.
Referenced by EMAN::TestUtil::check_image(), EMAN::GlobalCache::get_imageio(), EMAN::SpiderIO::SpiderIO(), and EMAN::EMData::write_image().
00209 { 00210 if (access(filename.c_str(), F_OK) == 0) { 00211 return true; 00212 } 00213 return false; 00214 }
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 2148 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 5218 of file util_sparx.cpp.
References max.
05218 { 05219 long int d2 = group2[s2 - 1] - group2[0]; 05220 long int p2 = 0; 05221 long int i1 = 0; 05222 long int i2 = 0; 05223 long int max = 0; 05224 long int cont = 0; 05225 long int i = 0; 05226 int stop1 = 0; 05227 int stop2 = 0; 05228 05229 for (i=0; i<s1; i++) { 05230 p2 = (long int)(s2 * (double)group1[i] / (double)d2); 05231 if (p2 >= s2) {p2 = s2 - 1;} 05232 i1 = p2; 05233 i2 = p2; 05234 max = s2; 05235 if (group1[i] < group2[0] || group1[i] > group2[s2 - 1]) {continue;} 05236 05237 stop1 = 0; 05238 stop2 = 0; 05239 while (max--) { 05240 if (group1[i] == group2[i1]) { 05241 if (flag) {stb[cont] = group1[i];} 05242 cont++; 05243 break; 05244 } 05245 if (group2[i1] < group1[i]) {stop1=1;} 05246 if (group1[i] == group2[i2]) { 05247 if (flag) {stb[cont] = group1[i];} 05248 cont++; 05249 break; 05250 } 05251 if (group2[i2] > group1[i]) {stop2=1;} 05252 //printf("i1 %li i2 %li v2 %i v2 %i stop1 %i stop2 %i\n", i1, i2, group2[i1], group2[i2], stop1, stop2); 05253 05254 if (stop1 & stop2) {break;} 05255 i1--; 05256 i2++; 05257 if (i1 < 0) {i1 = 0;} 05258 if (i2 >= s2) {i2 = s2 - 1;} 05259 } 05260 //printf("v1: %i ite: %li cont: %li\n", group1[i], s2-max, cont); 05261 } 05262 05263 return cont; 05264 }
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 1528 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 21056 of file util_sparx.cpp.
21056 { 21057 21058 if (is_mirror != 0) { 21059 for (vector<float>::iterator q=list.begin(); q!=list.end(); q++) { 21060 int r = rand()%10000; 21061 float f = r/10000.0f; 21062 if (f < mutation_rate) *q = 1-*q; 21063 } 21064 } else { 21065 map<int, vector<int> > graycode; 21066 map<vector<int>, int> rev_graycode; 21067 vector <int> gray; 21068 21069 int K=1; 21070 for (int i=0; i<L; i++) K*=2; 21071 21072 for (int k=0; k<K; k++) { 21073 int shift = 0; 21074 vector <int> gray; 21075 for (int i=L-1; i>-1; i--) { 21076 int t = ((k>>i)%2-shift)%2; 21077 gray.push_back(t); 21078 shift += t-2; 21079 } 21080 graycode[k] = gray; 21081 rev_graycode[gray] = k; 21082 } 21083 21084 float gap = (K-1)/(max_val-min_val); 21085 for (vector<float>::iterator q=list.begin(); q!=list.end(); q++) { 21086 float val = *q; 21087 if (val < min_val) { val = min_val; } 21088 else if (val > max_val) { val = max_val; } 21089 int k = int((val-min_val)*gap+0.5); 21090 vector<int> gray = graycode[k]; 21091 bool changed = false; 21092 for (vector<int>::iterator p=gray.begin(); p!=gray.end(); p++) { 21093 int r = rand()%10000; 21094 float f = r/10000.0f; 21095 if (f < mutation_rate) { 21096 *p = 1-*p; 21097 changed = true; 21098 } 21099 } 21100 if (changed) { 21101 k = rev_graycode[gray]; 21102 *q = k/gap+min_val; 21103 } 21104 } 21105 } 21106 return list; 21107 }
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 6507 of file util_sparx.cpp.
References cl1().
06508 { 06509 /* System generated locals */ 06510 long int q_dim1, q_offset, q1_dim1, q1_offset, i__1, i__2; 06511 06512 /* Local variables */ 06513 long int i__, j, m, n1, ii, jj; 06514 double tmp; 06515 vector<float> p; 06516 --x; 06517 q_dim1 = *klm2d; 06518 q_offset = 1 + q_dim1; 06519 q -= q_offset; 06520 q1_dim1 = *klm2d; 06521 q1_offset = 1 + q1_dim1; 06522 q1 -= q1_offset; 06523 --s; 06524 --res; 06525 iu -= 3; 06526 cu -= 3; 06527 06528 /* Function Body */ 06529 long int l = 0; 06530 06531 /* C==ZHONG HUANG,JULY,12,02;L=0,1,2,3,4,5,6 correspond to different equality constraints */ 06532 m = *ks; 06533 n1 = *n + 1; 06534 if (*iswi == 1) { 06535 i__1 = n1; 06536 for (jj = 1; jj <= i__1; ++jj) { 06537 i__2 = *ks; 06538 for (ii = 1; ii <= i__2; ++ii) { 06539 /* q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];*/ 06540 06541 q[*ks + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1] 06542 ; 06543 } 06544 } 06545 } else if (*iswi == 2) { 06546 i__1 = *ks; 06547 for (ii = 1; ii <= i__1; ++ii) { 06548 i__2 = n1; 06549 for (jj = 1; jj <= i__2; ++jj) { 06550 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06551 q[*ks + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06552 } 06553 } 06554 } else if (*iswi == 3) { 06555 l = 2; 06556 i__1 = n1; 06557 for (jj = 1; jj <= i__1; ++jj) { 06558 i__2 = *ks + 2; 06559 for (ii = 1; ii <= i__2; ++ii) { 06560 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06561 } 06562 i__2 = *ks; 06563 for (ii = 1; ii <= i__2; ++ii) { 06564 q[*ks + 2 + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06565 } 06566 } 06567 } else if (*iswi == 4) { 06568 l = 2; 06569 i__1 = n1; 06570 for (jj = 1; jj <= i__1; ++jj) { 06571 i__2 = *ks + 2; 06572 for (ii = 1; ii <= i__2; ++ii) { 06573 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06574 } 06575 i__2 = *ks; 06576 for (ii = 1; ii <= i__2; ++ii) { 06577 q[*ks + 2 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06578 } 06579 } 06580 } else if (*iswi == 5) { 06581 l = 1; 06582 i__1 = n1; 06583 for (jj = 1; jj <= i__1; ++jj) { 06584 i__2 = *ks + 1; 06585 for (ii = 1; ii <= i__2; ++ii) { 06586 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06587 } 06588 i__2 = *ks; 06589 for (ii = 1; ii <= i__2; ++ii) { 06590 q[*ks + 1 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06591 } 06592 } 06593 } else if (*iswi == 6) { 06594 l = 1; 06595 i__1 = n1; 06596 for (jj = 1; jj <= i__1; ++jj) { 06597 i__2 = *ks + 1; 06598 for (ii = 1; ii <= i__2; ++ii) { 06599 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06600 } 06601 i__2 = *ks; 06602 for (ii = 1; ii <= i__2; ++ii) { 06603 q[*ks + 1 + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06604 } 06605 } 06606 } else if (*iswi == 7) { 06607 l = 3; 06608 i__1 = n1; 06609 for (jj = 1; jj <= i__1; ++jj) { 06610 i__2 = *ks + 3; 06611 for (ii = 1; ii <= i__2; ++ii) { 06612 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06613 } 06614 i__2 = *ks; 06615 for (ii = 1; ii <= i__2; ++ii) { 06616 q[*ks + 3 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06617 } 06618 } 06619 } else if (*iswi == 8) { 06620 l = 4; 06621 i__1 = n1; 06622 for (jj = 1; jj <= i__1; ++jj) { 06623 i__2 = *ks + 4; 06624 for (ii = 1; ii <= i__2; ++ii) { 06625 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06626 } 06627 i__2 = *ks; 06628 for (ii = 1; ii <= i__2; ++ii) { 06629 q[*ks + 4 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06630 } 06631 } 06632 } 06633 06634 Util::cl1(ks, &l, &m, n, klm2d, &q[q_offset], &x[1], &res[1], &cu[3], &iu[3], &s[1]); 06635 i__1 = *ks; 06636 int tmp__j=0; 06637 for (i__ = 1; i__ <= i__1; ++i__) { 06638 tmp = 0.f; 06639 i__2 = *n - 1; 06640 for (j = 1; j <= i__2; ++j) { 06641 tmp__j=j; 06642 tmp += pow(q1[i__ + q1_dim1], tmp__j) * x[j]; 06643 } 06644 tmp += x[*n]; 06645 p.push_back(static_cast<float>(exp(tmp))); 06646 p.push_back(q1[i__ + q1_dim1]); 06647 } 06648 i__2=*n; 06649 for (i__=1;i__<=i__2;++i__) 06650 { p.push_back(static_cast<float>(x[i__]));} 06651 return p; 06652 }
Definition at line 17621 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().
17622 { 17623 ENTERFUNC; 17624 /* Exception Handle */ 17625 if (!img) { 17626 throw NullPointerException("NULL input image"); 17627 } 17628 /* ============== img += scalar*img1 ================ */ 17629 17630 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17631 size_t size = (size_t)nx*ny*nz; 17632 float *img_ptr =img->get_data(); 17633 float *img1_ptr = img1->get_data(); 17634 for (size_t i=0;i<size;++i)img_ptr[i] += img1_ptr[i]*scalar; 17635 img1->update(); 17636 17637 EXITFUNC; 17638 }
Definition at line 17431 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().
17432 { 17433 ENTERFUNC; 17434 /* Exception Handle */ 17435 if (!img) { 17436 throw NullPointerException("NULL input image"); 17437 } 17438 /* ============== output = img + scalar*img1 ================ */ 17439 17440 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17441 size_t size = (size_t)nx*ny*nz; 17442 EMData * img2 = img->copy_head(); 17443 float *img_ptr =img->get_data(); 17444 float *img2_ptr = img2->get_data(); 17445 float *img1_ptr = img1->get_data(); 17446 for (size_t i=0;i<size;++i) img2_ptr[i] = img_ptr[i] + img1_ptr[i]*scalar; 17447 img2->update(); 17448 if(img->is_complex()) { 17449 img2->set_complex(true); 17450 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17451 } 17452 17453 EXITFUNC; 17454 return img2; 17455 }
static double EMAN::Util::mean | ( | double * | x, | |
int | n | |||
) | [inline, static] |
Definition at line 1103 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 6289 of file util_sparx.cpp.
06290 { 06291 vector<float>new_peak; 06292 int n1=peak1.size()/3; 06293 float p_size2=p_size*p_size; 06294 for (int i=0;i<n1;++i) { 06295 vector<float>::iterator it2= peak1.begin()+3*i; 06296 bool push_back1=true; 06297 int n2=peak2.size()/3; 06298 /*cout<<"peak2 size==="<<n2<<"i====="<<i<<endl; 06299 cout<<"new peak size==="<<new_peak.size()/3<<endl;*/ 06300 if(n2 ==0) { 06301 new_peak.push_back(*it2); 06302 new_peak.push_back(*(it2+1)); 06303 new_peak.push_back(*(it2+2)); 06304 } else { 06305 int j=0; 06306 while (j< n2-1 ) { 06307 vector<float>::iterator it3= peak2.begin()+3*j; 06308 float d2=((*(it2+1))-(*(it3+1)))*((*(it2+1))-(*(it3+1)))+((*(it2+2))-(*(it3+2)))*((*(it2+2))-(*(it3+2))); 06309 if(d2< p_size2 ) { 06310 if( (*it2)<(*it3) ) { 06311 new_peak.push_back(*it3); 06312 new_peak.push_back(*(it3+1)); 06313 new_peak.push_back(*(it3+2)); 06314 peak2.erase(it3); 06315 peak2.erase(it3); 06316 peak2.erase(it3); 06317 push_back1=false; 06318 } else { 06319 peak2.erase(it3); 06320 peak2.erase(it3); 06321 peak2.erase(it3); 06322 } 06323 } else j=j+1; 06324 n2=peak2.size()/3; 06325 } 06326 if(push_back1) { 06327 new_peak.push_back(*it2); 06328 new_peak.push_back(*(it2+1)); 06329 new_peak.push_back(*(it2+2)); 06330 } 06331 } 06332 } 06333 return new_peak; 06334 }
helper function for k-means
Definition at line 5143 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), nx, and ny.
05143 { 05144 ENTERFUNC; 05145 05146 int nima = data.size(); 05147 vector<float> res(nima); 05148 double result = 0.; 05149 double valmin = 1.0e20; 05150 int valpos = -1; 05151 05152 for (int kk=0; kk<nima; kk++){ 05153 result = 0; 05154 //validate_input_args(image, data[kk]); 05155 05156 float *y_data = data[kk]->get_data(); 05157 float *x_data = image->get_data(); 05158 05159 // Implemented by PAP 01/09/06 - please do not change. If in doubts, write/call me. 05160 int nx = data[kk]->get_xsize(); 05161 int ny = data[kk]->get_ysize(); 05162 nx = (nx - 2 + data[kk]->is_fftodd()); // nx is the real-space size of the input image 05163 int lsd2 = (nx + 2 - nx%2) ; // Extended x-dimension of the complex image 05164 05165 int ixb = 2*((nx+1)%2); 05166 int iyb = ny%2; 05167 int iz = 0; 05168 05169 for ( int iy = 0; iy <= ny-1; iy++) { 05170 for ( int ix = 2; ix <= lsd2 - 1 - ixb; ix++) { 05171 int ii = ix + (iy + iz * ny)* lsd2; 05172 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05173 } 05174 } 05175 for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) { 05176 int ii = (iy + iz * ny)* lsd2; 05177 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05178 result += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]); 05179 } 05180 if(nx%2 == 0) { 05181 for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) { 05182 int ii = lsd2 - 2 + (iy + iz * ny)* lsd2; 05183 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05184 result += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]); 05185 } 05186 05187 } 05188 result *= 2; 05189 result += (x_data[0] - y_data[0])*double(x_data[0] - y_data[0]); 05190 if(ny%2 == 0) { 05191 int ii = (ny/2 + iz * ny)* lsd2; 05192 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05193 } 05194 if(nx%2 == 0) { 05195 int ii = lsd2 - 2 + (0 + iz * ny)* lsd2; 05196 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05197 if(ny%2 == 0) { 05198 int ii = lsd2 - 2 +(ny/2 + iz * ny)* lsd2; 05199 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05200 } 05201 } 05202 05203 result /= (long int)nx*(long int)ny*(long int)nx*(long int)ny; 05204 res[kk] = (float)result; 05205 05206 if(result<valmin) {valmin = result; valpos = kk;} 05207 05208 } 05209 05210 Dict retvals; 05211 retvals["dist"] = res; 05212 retvals["pos"] = valpos; 05213 05214 EXITFUNC; 05215 return retvals; 05216 }
k-means helper
Definition at line 5108 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), and EMAN::EMData::get_ysize().
05108 { 05109 ENTERFUNC; 05110 05111 int nima = data.size(); 05112 vector<float> res(nima); 05113 double result = 0.; 05114 double valmin = 1.0e20; 05115 int valpos = -1; 05116 05117 for (int kk=0; kk<nima; kk++){ 05118 result = 0; 05119 05120 float *y_data = data[kk]->get_data(); 05121 float *x_data = image->get_data(); 05122 long totsize = image->get_xsize()*image->get_ysize(); 05123 for (long i = 0; i < totsize; i++) { 05124 double temp = x_data[i]- y_data[i]; 05125 result += temp*temp; 05126 } 05127 result /= totsize; 05128 res[kk] = (float)result; 05129 05130 if(result<valmin) {valmin = result; valpos = kk;} 05131 05132 } 05133 05134 Dict retvals; 05135 retvals["dist"] = res; 05136 retvals["pos"] = valpos; 05137 05138 EXITFUNC; 05139 return retvals; 05140 05141 }
static int EMAN::Util::mono | ( | int | k1, | |
int | k2 | |||
) | [inline, static] |
Definition at line 1088 of file util.h.
References fast_floor().
Referenced by cluster_pairwise().
01089 { 01090 float c = ceilf(value); 01091 float f = (float)fast_floor(value); 01092 if (fabs(value - c) < precision) value = c; 01093 else if (fabs(value - f) < precision) value = f; 01094 } 01095 }; 01096 }
Definition at line 20222 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().
20223 { 20224 ENTERFUNC; 20225 /* Exception Handle */ 20226 if (!img) { 20227 throw NullPointerException("NULL input image"); 20228 } 20229 20230 int newx, newy, newz; 20231 bool keep_going; 20232 cout << " entered " <<endl; 20233 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 20234 //int size = nx*ny*nz; 20235 EMData * img2 = new EMData(); 20236 img2->set_size(nx,ny,nz); 20237 img2->to_zero(); 20238 float *img_ptr =img->get_data(); 20239 float *img2_ptr = img2->get_data(); 20240 int r2 = ro*ro; 20241 int r3 = r2*ro; 20242 int ri2 = ri*ri; 20243 int ri3 = ri2*ri; 20244 20245 int n2 = nx/2; 20246 20247 for (int k=-n2; k<=n2; k++) { //cout << " k "<<k <<endl; 20248 float z2 = static_cast<float>(k*k); 20249 for (int j=-n2; j<=n2; j++) { 20250 float y2 = z2 + j*j; 20251 if(y2 <= r2) { 20252 //cout << " j "<<j <<endl; 20253 20254 for (int i=-n2; i<=n2; i++) { 20255 float x2 = y2 + i*i; 20256 if(x2 <= r3) { 20257 //cout << " i "<<i <<endl; 20258 int ib = i+n2; int jb = j+n2; int kb = k+n2; 20259 if(x2 >= ri3) { 20260 // this is the outer shell, here points can only vanish 20261 if(img_ptr(ib,jb,kb) == 1.0f) { 20262 //cout << " 1 "<<ib <<endl; 20263 if(Util::get_frand(0.0f, 1.0f) > qprob){ 20264 img2_ptr(ib,jb,kb) = 0.0f; 20265 keep_going = true; 20266 //cout << " try "<<ib <<endl; 20267 while(keep_going) { 20268 newx = Util::get_irand(-ro,ro); 20269 newy = Util::get_irand(-ro,ro); 20270 newz = Util::get_irand(-ro,ro); 20271 if(newx*newx+newy*newy+newz*newz <= r3) { 20272 newx += n2; newy += n2; newz += n2; 20273 if( img_ptr(newx,newy,newz) == 0.0f) { 20274 img2_ptr(newx,newy,newz) = 1.0f; 20275 keep_going = false; } 20276 } 20277 } 20278 } else img2_ptr(ib,jb,kb) = 1.0f; 20279 } 20280 } else { 20281 // this is inner shell, the point can only move (or vanish, if all neighbors exist) 20282 if(img_ptr(ib,jb,kb) == 1.0) { 20283 if(Util::get_frand(0.0f,1.0f) > qprob) { 20284 // find out the number of neighbors 20285 float numn = -1.0f; // we already know the central one is 1 20286 for (newz = -1; newz <= 1; newz++) 20287 for (newy = -1; newy <= 1; newy++) 20288 for (newx = -1; newx <= 1; newx++) 20289 numn += img_ptr(ib+newx,jb+newy,kb+newz); 20290 img2_ptr(ib,jb,kb) = 0.0; 20291 if(numn == 26.0f) { 20292 // all neighbors exist, it has to vanish 20293 keep_going = true; 20294 while(keep_going) { 20295 newx = Util::get_irand(-ro,ro); 20296 newy = Util::get_irand(-ro,ro); 20297 newz = Util::get_irand(-ro,ro); 20298 if(newx*newx+newy*newy+newz*newz < r3) { 20299 newx += n2; newy += n2; newz += n2; 20300 if( img_ptr(newx,newy,newz) == 0.0f) { 20301 if(newx*newx+newy*newy+newz*newz < r3) { 20302 if(newx*newx+newy*newy+newz*newz < r3) { 20303 newx += n2; newy += n2; newz += n2; 20304 if( img_ptr(newx,newy,newz) == 0.0f) { 20305 img2_ptr(newx,newy,newz) = 1.0f; 20306 keep_going = false; } 20307 } 20308 } 20309 } 20310 } 20311 } 20312 } else if(numn == 25.0f) { 20313 // there is only one empty neighbor, move there 20314 for (newz = -1; newz <= 1; newz++) { 20315 for (newy = -1; newy <= 1; newy++) { 20316 for (newx = -1; newx <= 1; newx++) { 20317 if( newx != 0 && newy != 0 && newz != 0) { 20318 if(img_ptr(newx+ib,newy+jb,newz+kb) == 0.0f) { 20319 img2_ptr(newx+ib,newy+jb,newz+kb) = 1.0f; 20320 } 20321 } 20322 } 20323 } 20324 } 20325 } else { 20326 // more than one neighbor is zero, select randomly one and move there 20327 keep_going = true; 20328 while(keep_going) { 20329 newx = Util::get_irand(-1,1); 20330 newy = Util::get_irand(-1,1); 20331 newz = Util::get_irand(-1,1); 20332 if(newx != 0 && newy != 0 && newz != 0) { 20333 if(img_ptr(ib+newx,jb+newy,kb+newz) == 0.0f) { 20334 img2_ptr(ib+newx,jb+newy,kb+newz) = 1.0f;//????? 20335 keep_going = false; 20336 } 20337 } 20338 } 20339 } 20340 } else img2_ptr(ib,jb,kb) = 1.0f; 20341 } 20342 } 20343 } 20344 } 20345 } 20346 } 20347 } 20348 //for (int i=0;i<size;i++) img2_ptr[i] = img_ptr[i] + Util::get_irand(1,7); 20349 img2->update(); 20350 20351 EXITFUNC; 20352 return img2; 20353 }
Definition at line 17720 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().
17721 { 17722 ENTERFUNC; 17723 /* Exception Handle */ 17724 if (!img) { 17725 throw NullPointerException("NULL input image"); 17726 } 17727 /* ========= img *= img1 ===================== */ 17728 17729 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17730 size_t size = (size_t)nx*ny*nz; 17731 float *img_ptr = img->get_data(); 17732 float *img1_ptr = img1->get_data(); 17733 if(img->is_complex()) { 17734 for (size_t i=0; i<size; i+=2) { 17735 float tmp = img_ptr[i] * img1_ptr[i] - img_ptr[i+1] * img1_ptr[i+1] ; 17736 img_ptr[i+1] = img_ptr[i] * img1_ptr[i+1] + img_ptr[i+1] * img1_ptr[i] ; 17737 img_ptr[i] = tmp; 17738 17739 } 17740 } else { 17741 for (size_t i=0;i<size;++i) img_ptr[i] *= img1_ptr[i]; 17742 } 17743 img->update(); 17744 17745 EXITFUNC; 17746 }
void Util::mul_scalar | ( | EMData * | img, | |
float | scalar | |||
) | [static] |
Definition at line 17603 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().
17604 { 17605 ENTERFUNC; 17606 /* Exception Handle */ 17607 if (!img) { 17608 throw NullPointerException("NULL input image"); 17609 } 17610 /* ============ output = scalar*input ================== */ 17611 17612 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17613 size_t size = (size_t)nx*ny*nz; 17614 float *img_ptr =img->get_data(); 17615 for (size_t i=0;i<size;++i) img_ptr[i] *= scalar; 17616 img->update(); 17617 17618 EXITFUNC; 17619 }
Definition at line 17509 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().
17510 { 17511 ENTERFUNC; 17512 /* Exception Handle */ 17513 if (!img) { 17514 throw NullPointerException("NULL input image"); 17515 } 17516 /* ============== output = img * img1 ================ */ 17517 17518 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17519 size_t size = (size_t)nx*ny*nz; 17520 EMData * img2 = img->copy_head(); 17521 float *img_ptr =img->get_data(); 17522 float *img2_ptr = img2->get_data(); 17523 float *img1_ptr = img1->get_data(); 17524 if(img->is_complex()) { 17525 for (size_t i=0; i<size; i+=2) { 17526 img2_ptr[i] = img_ptr[i] * img1_ptr[i] - img_ptr[i+1] * img1_ptr[i+1] ; 17527 img2_ptr[i+1] = img_ptr[i] * img1_ptr[i+1] + img_ptr[i+1] * img1_ptr[i] ; 17528 } 17529 img2->set_complex(true); 17530 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17531 } else { 17532 for (size_t i=0; i<size; ++i) img2_ptr[i] = img_ptr[i] * img1_ptr[i]; 17533 img2->update(); 17534 } 17535 17536 EXITFUNC; 17537 return img2; 17538 }
Definition at line 17406 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().
17407 { 17408 ENTERFUNC; 17409 /* Exception Handle */ 17410 if (!img) { 17411 throw NullPointerException("NULL input image"); 17412 } 17413 /* ============ output = scalar*input ================== */ 17414 17415 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17416 size_t size = (size_t)nx*ny*nz; 17417 EMData * img2 = img->copy_head(); 17418 float *img_ptr =img->get_data(); 17419 float *img2_ptr = img2->get_data(); 17420 for (size_t i=0;i<size;++i)img2_ptr[i] = img_ptr[i]*scalar; 17421 img2->update(); 17422 17423 if(img->is_complex()) { 17424 img2->set_complex(true); 17425 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17426 } 17427 EXITFUNC; 17428 return img2; 17429 }
vector< float > Util::multi_align_error | ( | vector< float > | args, | |
vector< float > | all_ali_params, | |||
int | d | |||
) | [static] |
Definition at line 19957 of file util_sparx.cpp.
References multi_align_error_dfunc(), multi_align_error_func(), setulb_(), and SIXTY.
19957 { 19958 19959 const int nmax=args.size(), mmax=nmax; 19960 char task[60], csave[60]; 19961 long int lsave[4]; 19962 long int n, m, iprint, isave[44]; 19963 long int* nbd = new long int[nmax]; 19964 long int* iwa = new long int[3*nmax]; 19965 double f, factr, pgtol; 19966 double* x = new double[nmax]; 19967 double* l = new double[nmax]; 19968 double* u = new double[nmax]; 19969 double* g = new double[nmax]; 19970 double dsave[29]; 19971 double* wa = new double[2*mmax*nmax+4*nmax+12*mmax*mmax+12*mmax]; 19972 long int SIXTY=60; 19973 19974 int num_ali = nmax/3+1; 19975 int nima = all_ali_params.size()/(num_ali*4); 19976 19977 // We wish to have no output. 19978 iprint = -1; 19979 19980 //c We specify the tolerances in the stopping criteria. 19981 factr=1.0e1; 19982 pgtol=1.0e-9; 19983 19984 // We specify the dimension n of the sample problem and the number 19985 // m of limited memory corrections stored. (n and m should not 19986 // exceed the limits nmax and mmax respectively.) 19987 n=nmax; 19988 m=mmax; 19989 19990 // We now provide nbd which defines the bounds on the variables: 19991 // l specifies the lower bounds, 19992 // u specifies the upper bounds. 19993 // x specifies the initial guess 19994 for (int i=0; i<nmax; i++) { 19995 x[i] = args[i]; 19996 nbd[i] = 0; 19997 } 19998 19999 // We start the iteration by initializing task. 20000 // (**MUST clear remaining chars in task with spaces (else crash)!**) 20001 strcpy(task,"START"); 20002 for (int i=5;i<60;i++) task[i]=' '; 20003 20004 // This is the call to the L-BFGS-B code. 20005 // (* call the L-BFGS-B routine with task='START' once before loop *) 20006 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 20007 int step = 1; 20008 20009 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *) 20010 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) { 20011 20012 if (strncmp(task,"FG",2)==0) { 20013 // the minimization routine has returned to request the 20014 // function f and gradient g values at the current x 20015 20016 // Compute function value f for the sample problem. 20017 f = multi_align_error_func(x, all_ali_params, nima, num_ali, d); 20018 20019 // Compute gradient g for the sample problem. 20020 multi_align_error_dfunc(x, all_ali_params, nima, num_ali, g, d); 20021 20022 } 20023 //c go back to the minimization routine. 20024 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 20025 step++; 20026 } 20027 20028 //printf("Total step is %d\n", step); 20029 vector<float> res; 20030 for (int i=0; i<nmax; i++) res.push_back(static_cast<float>(x[i])); 20031 res.push_back(static_cast<float>(f)); 20032 20033 delete[] nbd; 20034 delete[] iwa; 20035 delete[] x; 20036 delete[] l; 20037 delete[] u; 20038 delete[] g; 20039 delete[] wa; 20040 20041 return res; 20042 20043 }
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 20103 of file util_sparx.cpp.
References mean(), and sqrt().
Referenced by multi_align_error().
20103 { 20104 20105 for (int i=0; i<num_ali*3-3; i++) g[i] = 0.0; 20106 20107 double* args = new double[num_ali*3]; 20108 for (int i=0; i<3*num_ali-3; i++) args[i] = x[i]; 20109 args[3*num_ali-3] = 0.0; 20110 args[3*num_ali-2] = 0.0; 20111 args[3*num_ali-1] = 0.0; 20112 double* cosa = new double[num_ali]; 20113 double* sina = new double[num_ali]; 20114 for (int i=0; i<num_ali; i++) { 20115 cosa[i] = cos(args[i*3]*M_PI/180.0); 20116 sina[i] = sin(args[i*3]*M_PI/180.0); 20117 } 20118 double* sx = new double[num_ali]; 20119 double* sy = new double[num_ali]; 20120 20121 vector<float> sqr_pixel_error(nima); 20122 20123 for (int i=0; i<nima; i++) { 20124 double sum_cosa = 0.0; 20125 double sum_sina = 0.0; 20126 for (int j=0; j<num_ali; j++) { 20127 if (static_cast<int>(ali_params[j*nima*4+i*4+3]) == 0) { 20128 sum_cosa += cos((args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 20129 sum_sina += sin((args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 20130 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]; 20131 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]; 20132 } else { 20133 sum_cosa += cos((-args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 20134 sum_sina += sin((-args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 20135 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]; 20136 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]; 20137 } 20138 } 20139 double P = sqrt(sum_cosa*sum_cosa+sum_sina*sum_sina); 20140 sum_cosa /= P; 20141 sum_sina /= P; 20142 for (int j=0; j<num_ali-1; j++) { 20143 double dx = 2.0*(sx[j]-mean(sx, num_ali)); 20144 double dy = 2.0*(sy[j]-mean(sy, num_ali)); 20145 if (static_cast<int>(ali_params[j*nima*4+i*4+3]) == 0) { 20146 g[j*3] += (d*d/4.0*(sum_cosa*sin((args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0) - 20147 sum_sina*cos((args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0)) + 20148 dx*(-ali_params[j*nima*4+i*4+1]*sina[j]-ali_params[j*nima*4+i*4+2]*cosa[j])+ 20149 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; 20150 g[j*3+1] += dx; 20151 g[j*3+2] += dy; 20152 } else { 20153 g[j*3] += (d*d/4.0*(-sum_cosa*sin((-args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0) + 20154 sum_sina*cos((-args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0)) + 20155 dx*(-ali_params[j*nima*4+i*4+1]*sina[j]+ali_params[j*nima*4+i*4+2]*cosa[j])+ 20156 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; 20157 g[j*3+1] += -dx; 20158 g[j*3+2] += dy; 20159 } 20160 } 20161 } 20162 20163 for (int i=0; i<3*num_ali-3; i++) g[i] /= (num_ali*nima); 20164 20165 delete[] args; 20166 delete[] cosa; 20167 delete[] sina; 20168 delete[] sx; 20169 delete[] sy; 20170 }
double Util::multi_align_error_func | ( | double * | x, | |
vector< float > | all_ali_params, | |||
int | nima, | |||
int | num_ali, | |||
int | d | |||
) | [static] |
Definition at line 20045 of file util_sparx.cpp.
References multi_align_error_func2().
Referenced by multi_align_error().
20045 { 20046 20047 vector<double> sqr_pixel_error = multi_align_error_func2(x, all_ali_params, nima, num_ali, d); 20048 double sum_sqr_pixel_error = 0.0; 20049 for (int i=0; i<nima; i++) sum_sqr_pixel_error += sqr_pixel_error[i]; 20050 return sum_sqr_pixel_error/static_cast<float>(nima); 20051 }
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 20054 of file util_sparx.cpp.
Referenced by multi_align_error_func().
20054 { 20055 20056 double* args = new double[num_ali*3]; 20057 for (int i=0; i<3*num_ali-3; i++) args[i] = x[i]; 20058 args[3*num_ali-3] = 0.0; 20059 args[3*num_ali-2] = 0.0; 20060 args[3*num_ali-1] = 0.0; 20061 double* cosa = new double[num_ali]; 20062 double* sina = new double[num_ali]; 20063 for (int i=0; i<num_ali; i++) { 20064 cosa[i] = cos(args[i*3]*M_PI/180.0); 20065 sina[i] = sin(args[i*3]*M_PI/180.0); 20066 } 20067 double* sx = new double[num_ali]; 20068 double* sy = new double[num_ali]; 20069 20070 vector<double> sqr_pixel_error(nima); 20071 20072 for (int i=0; i<nima; i++) { 20073 double sum_cosa = 0.0; 20074 double sum_sina = 0.0; 20075 for (int j=0; j<num_ali; j++) { 20076 if (static_cast<int>(ali_params[j*nima*4+i*4+3]) == 0) { 20077 sum_cosa += cos((args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 20078 sum_sina += sin((args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 20079 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]; 20080 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]; 20081 } else { 20082 sum_cosa += cos((-args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 20083 sum_sina += sin((-args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 20084 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]; 20085 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]; 20086 } 20087 } 20088 double P = sqrt(sum_cosa*sum_cosa+sum_sina*sum_sina); 20089 sum_cosa /= P; 20090 sum_sina /= P; 20091 sqr_pixel_error[i] = d*d/4.0*(1.0-P/num_ali)+var(sx, num_ali)+var(sy, num_ali); 20092 } 20093 20094 delete[] args; 20095 delete[] cosa; 20096 delete[] sina; 20097 delete[] sx; 20098 delete[] sy; 20099 20100 return sqr_pixel_error; 20101 }
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 19335 of file util_sparx.cpp.
References Crosrng_msg_vec(), Frngs(), EMAN::EMData::get_data(), Polar2Dm(), and EMAN::EMData::set_size().
19338 { 19339 19340 int maxrin = numr[numr.size()-1]; 19341 19342 int ky = int(2*yrng/step+0.5)/2; 19343 int kx = int(2*xrng/step+0.5)/2; 19344 19345 peaks->set_size(maxrin, 2*kx+3, 2*ky+3); 19346 float *p_ccf1ds = peaks->get_data(); 19347 19348 peakm->set_size(maxrin, 2*kx+3, 2*ky+3); 19349 float *p_ccf1dm = peakm->get_data(); 19350 19351 for ( int i = 0; i<maxrin*(2*kx+3)*(2*ky+3); i++) { 19352 p_ccf1ds[i] = -1.e20f; 19353 p_ccf1dm[i] = -1.e20f; 19354 } 19355 19356 for (int i = -ky; i <= ky; i++) { 19357 float iy = i * step; 19358 for (int j = -kx; j <= kx; j++) { 19359 float ix = j*step; 19360 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 19361 Frngs(cimage, numr); 19362 Crosrng_msg_vec(crefim, cimage, numr, 19363 p_ccf1ds+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin, 19364 p_ccf1dm+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin); 19365 delete cimage; cimage = 0; 19366 } 19367 } 19368 return; 19369 }
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 19371 of file util_sparx.cpp.
References Crosrng_msg_vec(), Frngs(), EMAN::EMData::get_data(), Polar2Dm(), and EMAN::EMData::set_size().
19373 { 19374 19375 int maxrin = numr[numr.size()-1]; 19376 19377 int ky = int(2*yrng/step+0.5)/2; 19378 int kx = int(2*xrng/step+0.5)/2; 19379 19380 peaks->set_size(maxrin, 2*kx+3, 2*ky+3); 19381 float *p_ccf1ds = peaks->get_data(); 19382 19383 peakm->set_size(maxrin, 2*kx+3, 2*ky+3); 19384 float *p_ccf1dm = peakm->get_data(); 19385 19386 peaks_compress->set_size(maxrin, 1, 1); 19387 float *p_ccf1ds_compress = peaks_compress->get_data(); 19388 19389 peakm_compress->set_size(maxrin, 1, 1); 19390 float *p_ccf1dm_compress = peakm_compress->get_data(); 19391 19392 for ( int i = 0; i<maxrin*(2*kx+3)*(2*ky+3); i++) { 19393 p_ccf1ds[i] = -1.e20f; 19394 p_ccf1dm[i] = -1.e20f; 19395 } 19396 19397 for (int i = -ky; i <= ky; i++) { 19398 float iy = i * step; 19399 for (int j = -kx; j <= kx; j++) { 19400 float ix = j*step; 19401 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 19402 Frngs(cimage, numr); 19403 Crosrng_msg_vec(crefim, cimage, numr, 19404 p_ccf1ds+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin, 19405 p_ccf1dm+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin); 19406 delete cimage; cimage = 0; 19407 } 19408 } 19409 for (int x=0; x<maxrin; x++) { 19410 float maxs = -1.0e22f; 19411 float maxm = -1.0e22f; 19412 for (int i=1; i<=2*ky+1; i++) { 19413 for (int j=1; j<=2*kx+1; j++) { 19414 if (p_ccf1ds[(i*(2*kx+3)+j)*maxrin+x] > maxs) maxs = p_ccf1ds[(i*(2*kx+3)+j)*maxrin+x]; 19415 if (p_ccf1dm[(i*(2*kx+3)+j)*maxrin+x] > maxm) maxm = p_ccf1dm[(i*(2*kx+3)+j)*maxrin+x]; 19416 } 19417 } 19418 p_ccf1ds_compress[x] = maxs; 19419 p_ccf1dm_compress[x] = maxm; 19420 } 19421 return; 19422 }
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 17929 of file util_sparx.cpp.
References ang_n(), Crosrng_ms(), Frngs(), Normalize_ring(), pi, and Polar2Dm().
17931 { 17932 17933 // Manually extract. 17934 /* vector< EMAN::EMData* > crefim; 17935 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 17936 crefim.reserve(crefim_len); 17937 17938 for(std::size_t i=0;i<crefim_len;i++) { 17939 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 17940 crefim.push_back(proxy()); 17941 } 17942 */ 17943 17944 size_t crefim_len = crefim.size(); 17945 17946 int ky = int(2*yrng/step+0.5)/2; 17947 int kx = int(2*xrng/step+0.5)/2; 17948 int iref, nref=0, mirror=0; 17949 float iy, ix, sx=0, sy=0; 17950 float peak = -1.0E23f; 17951 float ang=0.0f; 17952 for (int i = -ky; i <= ky; i++) { 17953 iy = i * step ; 17954 for (int j = -kx; j <= kx; j++) { 17955 ix = j*step ; 17956 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 17957 17958 Normalize_ring( cimage, numr ); 17959 17960 Frngs(cimage, numr); 17961 // compare with all reference images 17962 // for iref in xrange(len(crefim)): 17963 for ( iref = 0; iref < (int)crefim_len; iref++) { 17964 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr); 17965 double qn = retvals["qn"]; 17966 double qm = retvals["qm"]; 17967 if(qn >= peak || qm >= peak) { 17968 sx = -ix; 17969 sy = -iy; 17970 nref = iref; 17971 if (qn >= qm) { 17972 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 17973 peak = static_cast<float>(qn); 17974 mirror = 0; 17975 } else { 17976 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 17977 peak = static_cast<float>(qm); 17978 mirror = 1; 17979 } 17980 } 17981 } delete cimage; cimage = 0; 17982 } 17983 } 17984 float co, so, sxs, sys; 17985 co = static_cast<float>( cos(ang*pi/180.0) ); 17986 so = static_cast<float>( -sin(ang*pi/180.0) ); 17987 sxs = sx*co - sy*so; 17988 sys = sx*so + sy*co; 17989 vector<float> res; 17990 res.push_back(ang); 17991 res.push_back(sxs); 17992 res.push_back(sys); 17993 res.push_back(static_cast<float>(mirror)); 17994 res.push_back(static_cast<float>(nref)); 17995 res.push_back(peak); 17996 return res; 17997 }
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 18347 of file util_sparx.cpp.
References ang_n(), Crosrng_ms_delta(), Frngs(), Normalize_ring(), pi, and Polar2Dm().
18349 { 18350 18351 // Manually extract. 18352 /* vector< EMAN::EMData* > crefim; 18353 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 18354 crefim.reserve(crefim_len); 18355 18356 for(std::size_t i=0;i<crefim_len;i++) { 18357 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 18358 crefim.push_back(proxy()); 18359 } 18360 */ 18361 18362 size_t crefim_len = crefim.size(); 18363 18364 int ky = int(2*yrng/step+0.5)/2; 18365 int kx = int(2*xrng/step+0.5)/2; 18366 int iref, nref=0, mirror=0; 18367 float iy, ix, sx=0, sy=0; 18368 float peak = -1.0E23f; 18369 float ang=0.0f; 18370 for (int i = -ky; i <= ky; i++) { 18371 iy = i * step ; 18372 for (int j = -kx; j <= kx; j++) { 18373 ix = j*step ; 18374 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18375 18376 Normalize_ring( cimage, numr ); 18377 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 Dict retvals = Crosrng_ms_delta(crefim[iref], cimage, numr, delta_start, delta); 18383 double qn = retvals["qn"]; 18384 double qm = retvals["qm"]; 18385 if(qn >= peak || qm >= peak) { 18386 sx = -ix; 18387 sy = -iy; 18388 nref = iref; 18389 if (qn >= qm) { 18390 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18391 peak = static_cast<float>(qn); 18392 mirror = 0; 18393 } else { 18394 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 18395 peak = static_cast<float>(qm); 18396 mirror = 1; 18397 } 18398 } 18399 } delete cimage; cimage = 0; 18400 } 18401 } 18402 float co, so, sxs, sys; 18403 co = static_cast<float>( cos(ang*pi/180.0) ); 18404 so = static_cast<float>( -sin(ang*pi/180.0) ); 18405 sxs = sx*co - sy*so; 18406 sys = sx*so + sy*co; 18407 vector<float> res; 18408 res.push_back(ang); 18409 res.push_back(sxs); 18410 res.push_back(sys); 18411 res.push_back(static_cast<float>(mirror)); 18412 res.push_back(static_cast<float>(nref)); 18413 res.push_back(peak); 18414 return res; 18415 }
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 18474 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.
18476 { 18477 18478 // Manually extract. 18479 /* vector< EMAN::EMData* > crefim; 18480 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 18481 crefim.reserve(crefim_len); 18482 18483 for(std::size_t i=0;i<crefim_len;i++) { 18484 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 18485 crefim.push_back(proxy()); 18486 } 18487 */ 18488 size_t crefim_len = crefim.size(); 18489 const float qv = static_cast<float>( pi/180.0 ); 18490 18491 Transform * t = image->get_attr("xform.projection"); 18492 Dict d = t->get_params("spider"); 18493 if(t) {delete t; t=0;} 18494 float phi = d["phi"]; 18495 float theta = d["theta"]; 18496 int ky = int(2*yrng/step+0.5)/2; 18497 int kx = int(2*xrng/step+0.5)/2; 18498 int iref, nref=0, mirror=0; 18499 float iy, ix, sx=0, sy=0; 18500 float peak = -1.0E23f; 18501 float ang=0.0f; 18502 float imn1 = sin(theta*qv)*cos(phi*qv); 18503 float imn2 = sin(theta*qv)*sin(phi*qv); 18504 float imn3 = cos(theta*qv); 18505 vector<float> n1(crefim_len); 18506 vector<float> n2(crefim_len); 18507 vector<float> n3(crefim_len); 18508 for ( iref = 0; iref < (int)crefim_len; iref++) { 18509 n1[iref] = crefim[iref]->get_attr("n1"); 18510 n2[iref] = crefim[iref]->get_attr("n2"); 18511 n3[iref] = crefim[iref]->get_attr("n3"); 18512 } 18513 for (int i = -ky; i <= ky; i++) { 18514 iy = i * step ; 18515 for (int j = -kx; j <= kx; j++) { 18516 ix = j*step; 18517 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18518 18519 Normalize_ring( cimage, numr ); 18520 18521 Frngs(cimage, numr); 18522 // compare with all reference images 18523 // for iref in xrange(len(crefim)): 18524 for ( iref = 0; iref < (int)crefim_len; iref++) { 18525 if(abs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) { 18526 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr); 18527 double qn = retvals["qn"]; 18528 double qm = retvals["qm"]; 18529 if(qn >= peak || qm >= peak) { 18530 sx = -ix; 18531 sy = -iy; 18532 nref = iref; 18533 if (qn >= qm) { 18534 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18535 peak = static_cast<float>( qn ); 18536 mirror = 0; 18537 } else { 18538 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 18539 peak = static_cast<float>( qm ); 18540 mirror = 1; 18541 } 18542 } 18543 } 18544 } delete cimage; cimage = 0; 18545 } 18546 } 18547 float co, so, sxs, sys; 18548 if(peak == -1.0E23) { 18549 ang=0.0; sxs=0.0; sys=0.0; mirror=0; 18550 nref = -1; 18551 } else { 18552 co = cos(ang*qv); 18553 so = -sin(ang*qv); 18554 sxs = sx*co - sy*so; 18555 sys = sx*so + sy*co; 18556 } 18557 vector<float> res; 18558 res.push_back(ang); 18559 res.push_back(sxs); 18560 res.push_back(sys); 18561 res.push_back(static_cast<float>(mirror)); 18562 res.push_back(static_cast<float>(nref)); 18563 res.push_back(peak); 18564 return res; 18565 }
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 18567 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.
18569 { 18570 18571 // Manually extract. 18572 /* vector< EMAN::EMData* > crefim; 18573 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 18574 crefim.reserve(crefim_len); 18575 18576 for(std::size_t i=0;i<crefim_len;i++) { 18577 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 18578 crefim.push_back(proxy()); 18579 } 18580 */ 18581 size_t crefim_len = crefim.size(); 18582 const float qv = static_cast<float>(pi/180.0); 18583 18584 Transform* t = image->get_attr("xform.projection"); 18585 Dict d = t->get_params("spider"); 18586 if(t) {delete t; t=0;} 18587 float phi = d["phi"]; 18588 float theta = d["theta"]; 18589 float psi = d["psi"]; 18590 int ky = int(2*yrng/step+0.5)/2; 18591 int kx = int(2*xrng/step+0.5)/2; 18592 int iref, nref = 0, mirror = 0; 18593 float iy, ix, sx = 0, sy = 0; 18594 float peak = -1.0E23f; 18595 float ang = 0.0f; 18596 float imn1 = sin(theta*qv)*cos(phi*qv); 18597 float imn2 = sin(theta*qv)*sin(phi*qv); 18598 float imn3 = cos(theta*qv); 18599 vector<float> n1(crefim_len); 18600 vector<float> n2(crefim_len); 18601 vector<float> n3(crefim_len); 18602 for (iref = 0; iref < (int)crefim_len; iref++) { 18603 n1[iref] = crefim[iref]->get_attr("n1"); 18604 n2[iref] = crefim[iref]->get_attr("n2"); 18605 n3[iref] = crefim[iref]->get_attr("n3"); 18606 } 18607 bool nomirror = (theta<90.0) || (theta==90.0); 18608 if (!nomirror) { 18609 phi = fmod(phi+540.0f, 360.0f); 18610 theta = 180-theta; 18611 psi = fmod(540.0f-psi, 360.0f); 18612 } else { psi = fmod(360.0f-psi, 360.0f); } 18613 for (int i = -ky; i <= ky; i++) { 18614 iy = i * step ; 18615 for (int j = -kx; j <= kx; j++) { 18616 ix = j*step; 18617 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18618 18619 Normalize_ring(cimage, numr); 18620 18621 Frngs(cimage, numr); 18622 // compare with all reference images 18623 // for iref in xrange(len(crefim)): 18624 for (iref = 0; iref < (int)crefim_len; iref++) { 18625 if (abs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) { 18626 float refpsi = crefim[iref]->get_attr("psi"); 18627 if (nomirror) { 18628 Dict retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, fmod(360.0+psi+refpsi, 360.0), 0, psi_max); 18629 double qn = retvals["qn"]; 18630 if (qn >= peak) { 18631 sx = -ix; 18632 sy = -iy; 18633 nref = iref; 18634 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18635 peak = static_cast<float>(qn); 18636 mirror = 0; 18637 } 18638 } else { 18639 Dict retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, fmod(360.0+psi-refpsi, 360.0), 1, psi_max); 18640 double qn = retvals["qn"]; 18641 if (qn >= peak) { 18642 sx = -ix; 18643 sy = -iy; 18644 nref = iref; 18645 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18646 peak = static_cast<float>(qn); 18647 mirror = 1; 18648 } 18649 } 18650 } 18651 } delete cimage; cimage = 0; 18652 } 18653 } 18654 float co, so, sxs, sys; 18655 if(peak == -1.0E23) { 18656 ang=0.0; sxs=0.0; sys=0.0; mirror=0; 18657 nref = -1; 18658 } else { 18659 co = cos(ang*qv); 18660 so = -sin(ang*qv); 18661 sxs = sx*co - sy*so; 18662 sys = sx*so + sy*co; 18663 } 18664 vector<float> res; 18665 res.push_back(ang); 18666 res.push_back(sxs); 18667 res.push_back(sys); 18668 res.push_back(static_cast<float>(mirror)); 18669 res.push_back(static_cast<float>(nref)); 18670 res.push_back(peak); 18671 return res; 18672 }
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 18417 of file util_sparx.cpp.
References ang_n(), Crosrng_ns(), Frngs(), pi, and Polar2Dm().
18419 { 18420 18421 // Manually extract. 18422 /* vector< EMAN::EMData* > crefim; 18423 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 18424 crefim.reserve(crefim_len); 18425 18426 for(std::size_t i=0;i<crefim_len;i++) { 18427 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 18428 crefim.push_back(proxy()); 18429 } 18430 */ 18431 size_t crefim_len = crefim.size(); 18432 18433 int ky = int(2*yrng/step+0.5)/2; 18434 int kx = int(2*xrng/step+0.5)/2; 18435 int iref, nref=0; 18436 float iy, ix, sx=0, sy=0; 18437 float peak = -1.0E23f; 18438 float ang=0.0f; 18439 for (int i = -ky; i <= ky; i++) { 18440 iy = i * step ; 18441 for (int j = -kx; j <= kx; j++) { 18442 ix = j*step ; 18443 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18444 Frngs(cimage, numr); 18445 // compare with all reference images 18446 // for iref in xrange(len(crefim)): 18447 for ( iref = 0; iref < (int)crefim_len; iref++) { 18448 Dict retvals = Crosrng_ns(crefim[iref], cimage, numr); 18449 double qn = retvals["qn"]; 18450 if(qn >= peak) { 18451 sx = -ix; 18452 sy = -iy; 18453 nref = iref; 18454 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18455 peak = static_cast<float>(qn); 18456 } 18457 } delete cimage; cimage = 0; 18458 } 18459 } 18460 float co, so, sxs, sys; 18461 co = static_cast<float>( cos(ang*pi/180.0) ); 18462 so = static_cast<float>( -sin(ang*pi/180.0) ); 18463 sxs = sx*co - sy*so; 18464 sys = sx*so + sy*co; 18465 vector<float> res; 18466 res.push_back(ang); 18467 res.push_back(sxs); 18468 res.push_back(sys); 18469 res.push_back(static_cast<float>(nref)); 18470 res.push_back(peak); 18471 return res; 18472 }
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 17999 of file util_sparx.cpp.
References ang_n(), Crosrng_ms(), Frngs(), Normalize_ring(), pi, and Polar2Dm().
18001 { 18002 18003 size_t crefim_len = crefim.size(); 18004 18005 int ky = int(2*yrng/step+0.5)/2; 18006 int kx = int(2*xrng/step+0.5)/2; 18007 float iy, ix; 18008 vector<float> peak(crefim_len*5, -1.0e23f); 18009 for (int i = -ky; i <= ky; i++) { 18010 iy = i * step ; 18011 for (int j = -kx; j <= kx; j++) { 18012 ix = j*step ; 18013 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18014 Normalize_ring( cimage, numr ); 18015 Frngs(cimage, numr); 18016 for (int iref = 0; iref < (int)crefim_len; iref++) { 18017 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr); 18018 double qn = retvals["qn"]; 18019 double qm = retvals["qm"]; 18020 if(qn >= peak[iref*5] || qm >= peak[iref*5]) { 18021 if (qn >= qm) { 18022 peak[iref*5] = static_cast<float>(qn); 18023 peak[iref*5+1] = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18024 peak[iref*5+2] = -ix; 18025 peak[iref*5+3] = -iy; 18026 peak[iref*5+4] = 0; 18027 } else { 18028 peak[iref*5] = static_cast<float>(qm); 18029 peak[iref*5+1] = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 18030 peak[iref*5+2] = -ix; 18031 peak[iref*5+3] = -iy; 18032 peak[iref*5+4] = 1; 18033 } 18034 } 18035 } delete cimage; cimage = 0; 18036 } 18037 } 18038 for (int iref = 0; iref < (int)crefim_len; iref++) { 18039 float ang = peak[iref*5+1]; 18040 float sx = peak[iref*5+2]; 18041 float sy = peak[iref*5+3]; 18042 float co = cos(ang*pi/180.0); 18043 float so = -sin(ang*pi/180.0); 18044 float sxs = sx*co - sy*so; 18045 float sys = sx*so + sy*co; 18046 peak[iref*5+2] = sxs; 18047 peak[iref*5+3] = sys; 18048 } 18049 return peak; 18050 }
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 18675 of file util_sparx.cpp.
References ang_n(), Crosrng_psi(), Frngs(), Normalize_ring(), pi, Polar2Dm(), and EMAN::Dict::size().
18677 { 18678 18679 size_t crefim_len = crefim.size(); 18680 18681 int iref, nref=0, mirror=0; 18682 float iy, ix, sx=0, sy=0; 18683 float peak = -1.0E23f; 18684 float ang=0.0f; 18685 int kx = int(2*xrng/step+0.5)/2; 18686 //if ynumber==-1, use the old code which process x and y direction equally. 18687 //if ynumber is given, it should be even. We need to check whether it is zero 18688 18689 int ky; 18690 float stepy; 18691 int kystart; 18692 18693 if (ynumber == -1){ 18694 ky = int(2*yrng/step+0.5)/2; 18695 stepy = step; 18696 kystart = -ky; 18697 } 18698 else if(ynumber == 0){ 18699 ky = 0; 18700 stepy = 0.0f; 18701 kystart = ky; 18702 } 18703 else { 18704 ky = int(ynumber/2); 18705 stepy=2*yrng/ynumber; 18706 kystart = -ky + 1; 18707 } 18708 //std::cout<<"yrng="<<yrng<<"ynumber="<<ynumber<<"stepy=="<<stepy<<"stepx=="<<step<<std::endl; 18709 for (int i = kystart; i <= ky; i++) { 18710 iy = i * stepy ; 18711 for (int j = -kx; j <= kx; j++) { 18712 ix = j*step ; 18713 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18714 18715 Normalize_ring( cimage, numr ); 18716 18717 Frngs(cimage, numr); 18718 // compare with all reference images 18719 // for iref in xrange(len(crefim)): 18720 for ( iref = 0; iref < (int)crefim_len; iref++) { 18721 Dict retvals_0 = Crosrng_psi(crefim[iref], cimage, numr, 0, psi_max); 18722 Dict retvals_180 = Crosrng_psi(crefim[iref], cimage, numr, 180, psi_max); 18723 double qn_0 = retvals_0["qn"]; 18724 double qn_180 = retvals_180["qn"]; 18725 double qm_0 = retvals_0["qm"]; 18726 double qm_180 = retvals_180["qm"]; 18727 double qn; 18728 double qm; 18729 bool qn_is_zero = false; 18730 bool qm_is_zero = false; 18731 18732 if (qn_0 >= qn_180){ 18733 qn = qn_0; 18734 qn_is_zero = true; 18735 } 18736 else{ 18737 qn = qn_180; 18738 qn_is_zero = false; 18739 } 18740 18741 if (qm_0 >= qm_180){ 18742 qm = qm_0; 18743 qm_is_zero = true; 18744 } 18745 else{ 18746 qm = qm_180; 18747 qm_is_zero = false; 18748 } 18749 18750 if(qn >= peak || qm >= peak) { 18751 sx = -ix; 18752 sy = -iy; 18753 nref = iref; 18754 if (qn >= qm) { 18755 if (qn_is_zero){ 18756 ang = ang_n(retvals_0["tot"], mode, numr[numr.size()-1]); 18757 } 18758 else{ 18759 ang = ang_n(retvals_180["tot"], mode, numr[numr.size()-1]); 18760 } 18761 peak = static_cast<float>(qn); 18762 mirror = 0; 18763 } else { 18764 if (qm_is_zero){ 18765 ang = ang_n(retvals_0["tmt"], mode, numr[numr.size()-1]); 18766 } 18767 else{ 18768 ang = ang_n(retvals_180["tmt"], mode, numr[numr.size()-1]); 18769 } 18770 peak = static_cast<float>(qm); 18771 mirror = 1; 18772 } 18773 } 18774 } 18775 delete cimage; cimage = 0; 18776 } 18777 } 18778 float co, so, sxs, sys; 18779 co = static_cast<float>( cos(ang*pi/180.0) ); 18780 so = static_cast<float>( -sin(ang*pi/180.0) ); 18781 sxs = sx*co - sy*so; 18782 sys = sx*so + sy*co; 18783 vector<float> res; 18784 res.push_back(ang); 18785 res.push_back(sxs); 18786 res.push_back(sys); 18787 res.push_back(static_cast<float>(mirror)); 18788 res.push_back(static_cast<float>(nref)); 18789 res.push_back(peak); 18790 return res; 18791 }
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 19100 of file util_sparx.cpp.
References ang_n(), Crosrng_sm_psi(), Frngs(), Normalize_ring(), pi, Polar2Dm(), and EMAN::Dict::size().
19102 { 19103 19104 size_t crefim_len = crefim.size(); 19105 19106 int iref, nref=0, mirror=0; 19107 float iy, ix, sx=0, sy=0; 19108 float peak = -1.0E23f; 19109 float ang=0.0f; 19110 int kx = int(2*xrng/step+0.5)/2; 19111 //if ynumber==-1, use the old code which process x and y direction equally. 19112 19113 int ky; 19114 float stepy; 19115 int kystart; 19116 19117 if (ynumber == -1){ 19118 ky = int(2*yrng/step+0.5)/2; 19119 stepy = step; 19120 kystart = -ky; 19121 } 19122 else if(ynumber == 0){ 19123 ky = 0; 19124 stepy = 0.0f; 19125 kystart = ky; 19126 } 19127 else { 19128 ky = int(ynumber/2); 19129 stepy=2*yrng/ynumber; 19130 kystart = -ky + 1; 19131 } 19132 19133 //std::cout<<"yrng="<<yrng<<"ynumber="<<ynumber<<"stepy=="<<stepy<<"stepx=="<<step<<std::endl; 19134 for (int i = kystart; i <= ky; i++) { 19135 iy = i * stepy ; 19136 for (int j = -kx; j <= kx; j++) { 19137 ix = j*step ; 19138 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 19139 19140 Normalize_ring( cimage, numr ); 19141 19142 Frngs(cimage, numr); 19143 // compare with all reference images 19144 // for iref in xrange(len(crefim)): 19145 for ( iref = 0; iref < (int)crefim_len; iref++) { 19146 Dict retvals_0 = Crosrng_sm_psi(crefim[iref], cimage, numr, 0, 0, psi_max); 19147 Dict retvals_180 = Crosrng_sm_psi(crefim[iref], cimage, numr, 180, 0, psi_max); 19148 double qn_0 = retvals_0["qn"]; 19149 double qn_180 = retvals_180["qn"]; 19150 double qn; 19151 bool qn_is_zero = false; 19152 19153 if (qn_0 >= qn_180){ 19154 qn = qn_0; 19155 qn_is_zero = true; 19156 } 19157 else{ 19158 qn = qn_180; 19159 qn_is_zero = false; 19160 } 19161 19162 if(qn >= peak) { 19163 sx = -ix; 19164 sy = -iy; 19165 nref = iref; 19166 19167 if (qn_is_zero){ 19168 ang = ang_n(retvals_0["tot"], mode, numr[numr.size()-1]); 19169 } 19170 else{ 19171 ang = ang_n(retvals_180["tot"], mode, numr[numr.size()-1]); 19172 } 19173 peak = static_cast<float>(qn); 19174 mirror = 0; 19175 19176 } 19177 } 19178 delete cimage; cimage = 0; 19179 } 19180 } 19181 float co, so, sxs, sys; 19182 co = static_cast<float>( cos(ang*pi/180.0) ); 19183 so = static_cast<float>( -sin(ang*pi/180.0) ); 19184 sxs = sx*co - sy*so; 19185 sys = sx*so + sy*co; 19186 vector<float> res; 19187 res.push_back(ang); 19188 res.push_back(sxs); 19189 res.push_back(sys); 19190 res.push_back(static_cast<float>(mirror)); 19191 res.push_back(static_cast<float>(nref)); 19192 res.push_back(peak); 19193 return res; 19194 }
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 | |||
) | [static] |
Definition at line 19197 of file util_sparx.cpp.
References ang_n(), Crosrng_psi_0_180_no_mirror(), Frngs(), get_attr(), EMAN::EMData::get_attr(), Normalize_ring(), phi, pi, Polar2Dm(), t, and theta.
19199 { 19200 19201 size_t crefim_len = crefim.size(); 19202 const float qv = static_cast<float>( pi/180.0 ); 19203 Transform * t = image->get_attr("xform.projection"); 19204 Dict d = t->get_params("spider"); 19205 if(t) {delete t; t=0;} 19206 float phi = d["phi"]; 19207 float theta = d["theta"]; 19208 float imn1 = sin(theta*qv)*cos(phi*qv); 19209 float imn2 = sin(theta*qv)*sin(phi*qv); 19210 float imn3 = cos(theta*qv); 19211 vector<float> n1(crefim_len); 19212 vector<float> n2(crefim_len); 19213 vector<float> n3(crefim_len); 19214 int iref, nref=-1, mirror=0; 19215 float iy, ix, sx=0, sy=0; 19216 float peak = -1.0E23f; 19217 float ang=0.0f; 19218 int kx = int(2*xrng/step+0.5)/2; 19219 19220 for ( iref = 0; iref < (int)crefim_len; iref++) { 19221 n1[iref] = crefim[iref]->get_attr("n1"); 19222 n2[iref] = crefim[iref]->get_attr("n2"); 19223 n3[iref] = crefim[iref]->get_attr("n3"); 19224 } 19225 19226 //if ynumber==-1, use the old code which process x and y direction equally. 19227 if(ynumber==-1) { 19228 int ky = int(2*yrng/step+0.5)/2; 19229 for (int i = -ky; i <= ky; i++) { 19230 iy = i * step ; 19231 for (int j = -kx; j <= kx; j++) { 19232 ix = j*step ; 19233 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 19234 19235 Normalize_ring( cimage, numr ); 19236 19237 Frngs(cimage, numr); 19238 // compare with all reference images 19239 // for iref in xrange(len(crefim)): 19240 for ( iref = 0; iref < (int)crefim_len; iref++) { 19241 if(fabs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) { 19242 Dict retvals = Crosrng_psi_0_180_no_mirror(crefim[iref], cimage, numr, psi_max); 19243 double qn = retvals["qn"]; 19244 if( qn >= peak) { 19245 sx = -ix; 19246 sy = -iy; 19247 nref = iref; 19248 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 19249 peak = static_cast<float>(qn); 19250 mirror = 0; 19251 } 19252 } 19253 } 19254 delete cimage; cimage = 0; 19255 } 19256 } 19257 } 19258 //if ynumber is given, it should be even. We need to check whether it is zero 19259 else if(ynumber==0) { 19260 sy = 0.0f; 19261 for (int j = -kx; j <= kx; j++) { 19262 ix = j*step ; 19263 iy = 0.0f ; 19264 EMData* cimage = Polar2Dm(image, cnx+ix, cny, numr, mode); 19265 19266 Normalize_ring( cimage, numr ); 19267 19268 Frngs(cimage, numr); 19269 // compare with all reference images 19270 // for iref in xrange(len(crefim)): 19271 for ( iref = 0; iref < (int)crefim_len; iref++) { 19272 if(fabs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) { 19273 Dict retvals = Crosrng_psi_0_180_no_mirror(crefim[iref], cimage, numr, psi_max); 19274 double qn = retvals["qn"]; 19275 if( qn >= peak ) { 19276 sx = -ix; 19277 nref = iref; 19278 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 19279 peak = static_cast<float>(qn); 19280 mirror = 0; 19281 } 19282 } 19283 } 19284 delete cimage; cimage = 0; 19285 } 19286 } else { 19287 int ky = int(ynumber/2); 19288 float stepy=2*yrng/ynumber; 19289 //std::cout<<"yrng="<<yrng<<"ynumber="<<ynumber<<"stepy=="<<stepy<<"stepx=="<<step<<std::endl; 19290 for (int i = -ky+1; i <= ky; i++) { 19291 iy = i * stepy ; 19292 for (int j = -kx; j <= kx; j++) { 19293 ix = j*step ; 19294 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 19295 19296 Normalize_ring( cimage, numr ); 19297 19298 Frngs(cimage, numr); 19299 // compare with all reference images 19300 // for iref in xrange(len(crefim)): 19301 for ( iref = 0; iref < (int)crefim_len; iref++) { 19302 if(fabs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) { 19303 Dict retvals = Crosrng_psi_0_180_no_mirror(crefim[iref], cimage, numr, psi_max); 19304 double qn = retvals["qn"]; 19305 if( qn >= peak) { 19306 sx = -ix; 19307 sy = -iy; 19308 nref = iref; 19309 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 19310 peak = static_cast<float>(qn); 19311 mirror = 0; 19312 } 19313 } 19314 } 19315 delete cimage; cimage = 0; 19316 } 19317 } 19318 } 19319 float co, so, sxs, sys; 19320 co = static_cast<float>( cos(ang*pi/180.0) ); 19321 so = static_cast<float>( -sin(ang*pi/180.0) ); 19322 sxs = sx*co - sy*so; 19323 sys = sx*so + sy*co; 19324 vector<float> res; 19325 res.push_back(ang); 19326 res.push_back(sxs); 19327 res.push_back(sys); 19328 res.push_back(static_cast<float>(mirror)); 19329 res.push_back(static_cast<float>(nref)); 19330 res.push_back(peak); 19331 return res; 19332 }
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 , |
|||
bool | mirror_only = false , |
|||
float | yrnglocal = -1.0 , |
|||
bool | CONS = false | |||
) | [static] |
Definition at line 18793 of file util_sparx.cpp.
References abs, ang_n(), Crosrng_sm_psi(), EMAN::EMObject::f, Frngs(), get_attr(), EMAN::EMData::get_attr(), Normalize_ring(), phi, pi, Polar2Dm(), EMAN::Dict::size(), t, and theta.
18795 { 18796 18797 size_t crefim_len = crefim.size(); 18798 18799 float phi_lhs=1000.0; 18800 float phi_rhs=1000.0; 18801 float y_lhs=1000.0; 18802 float y_rhs=1000.0; 18803 18804 if (CONS){ 18805 phi_lhs = image->get_attr("phi_lhs"); 18806 phi_rhs = image->get_attr("phi_rhs"); 18807 y_lhs = image->get_attr("y_lhs"); 18808 y_rhs = image->get_attr("y_rhs"); 18809 } 18810 int iref, nref=-1, mirror=0; 18811 float iy, ix, sx=0, sy=0; 18812 float peak = -1.0E23f; 18813 float ang=0.0f; 18814 const float qv = static_cast<float>( pi/180.0 ); 18815 Transform * t = image->get_attr("xform.projection"); 18816 Dict d = t->get_params("spider"); 18817 if(t) {delete t; t=0;} 18818 float phi = d["phi"]; 18819 float phi_upper = phi+phi_rhs; 18820 float phi_lower = phi+phi_lhs; 18821 float theta = d["theta"]; 18822 float psi = d["psi"]; 18823 float imn1 = sin(theta*qv)*cos(phi*qv); 18824 float imn2 = sin(theta*qv)*sin(phi*qv); 18825 float imn3 = cos(theta*qv); 18826 vector<float> n1(crefim_len); 18827 vector<float> n2(crefim_len); 18828 vector<float> n3(crefim_len); 18829 vector<float> ref_phi(crefim_len); 18830 for ( iref = 0; iref < (int)crefim_len; iref++) { 18831 n1[iref] = crefim[iref]->get_attr("n1"); 18832 n2[iref] = crefim[iref]->get_attr("n2"); 18833 n3[iref] = crefim[iref]->get_attr("n3"); 18834 18835 ref_phi[iref] = crefim[iref]->get_attr("phi"); 18836 } 18837 float nbrinp; 18838 bool use_ref; 18839 int kx = int(2*xrng/step+0.5)/2; 18840 int ychoice = 0; 18841 int phichoice = 0; 18842 //if ynumber==-1, use the old code which process x and y direction equally. 18843 if(ynumber==-1) { 18844 int ky = int(2*yrng/step+0.5)/2; 18845 for (int i = -ky; i <= ky; i++) { 18846 iy = i * step ; 18847 for (int j = -kx; j <= kx; j++) { 18848 ix = j*step ; 18849 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18850 18851 Normalize_ring( cimage, numr ); 18852 18853 Frngs(cimage, numr); 18854 // compare with all reference images 18855 // for iref in xrange(len(crefim)): 18856 for ( iref = 0; iref < (int)crefim_len; iref++) { 18857 18858 use_ref = false; 18859 if (!mirror_only){ 18860 // inner product of iref's Eulerian angles with that of the data 18861 nbrinp = n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3; 18862 if (nbrinp >= ant){ 18863 use_ref = true; 18864 } 18865 } 18866 else if (mirror_only) { 18867 // inner product of the mirror of iref's Eulerian angles with that of the data 18868 nbrinp = (-1.0*n1[iref]*imn1) + (-1.0*n2[iref]*imn2) + n3[iref]*imn3; 18869 if (nbrinp >= ant){ 18870 use_ref = true; 18871 } 18872 } 18873 18874 18875 if(use_ref) { 18876 Dict retvals; 18877 if (mirror_only == true){ 18878 if ((psi-90) < 90) 18879 retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, 0, 1, psi_max); 18880 else 18881 retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, 180, 1, psi_max); 18882 } 18883 else{ 18884 if ((psi-90) < 90) 18885 retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, 0, 0, psi_max); 18886 else 18887 retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, 180, 0, psi_max); 18888 } 18889 double qn = retvals["qn"]; 18890 18891 if(qn >= peak) { 18892 sx = -ix; 18893 sy = -iy; 18894 nref = iref; 18895 if (!mirror_only) { 18896 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18897 peak = static_cast<float>(qn); 18898 mirror = 0; 18899 } else { 18900 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18901 peak = static_cast<float>(qn); 18902 mirror = 1; 18903 } 18904 } 18905 } 18906 } 18907 delete cimage; cimage = 0; 18908 } 18909 } 18910 } 18911 //if ynumber is given, it should be even. We need to check whether it is zero 18912 else if(ynumber==0) { 18913 sy = 0.0f; 18914 for (int j = -kx; j <= kx; j++) { 18915 ix = j*step ; 18916 EMData* cimage = Polar2Dm(image, cnx+ix, cny, numr, mode); 18917 18918 Normalize_ring( cimage, numr ); 18919 18920 Frngs(cimage, numr); 18921 // compare with all reference images 18922 // for iref in xrange(len(crefim)): 18923 for ( iref = 0; iref < (int)crefim_len; iref++) { 18924 18925 use_ref = false; 18926 if (!mirror_only){ 18927 // inner product of iref's Eulerian angles with that of the data 18928 nbrinp = n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3; 18929 if (nbrinp >= ant){ 18930 use_ref = true; 18931 } 18932 } 18933 else if (mirror_only) { 18934 // inner product of the mirror of iref's Eulerian angles with that of the data 18935 nbrinp = (-1.0f*n1[iref]*imn1) + (-1.0f*n2[iref]*imn2) + n3[iref]*imn3; 18936 if (nbrinp >= ant){ 18937 use_ref = true; 18938 } 18939 } 18940 18941 if(use_ref) { 18942 Dict retvals; 18943 if (mirror_only == true){ 18944 if ((psi-90) < 90) 18945 retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, 0, 1, psi_max); 18946 else 18947 retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, 180, 1, psi_max); 18948 } 18949 else{ 18950 if ((psi-90) < 90) 18951 retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, 0, 0, psi_max); 18952 else 18953 retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, 180, 0, psi_max); 18954 } 18955 double qn = retvals["qn"]; 18956 18957 if(qn >= peak) { 18958 sx = -ix; 18959 sy = -iy; 18960 nref = iref; 18961 if (!mirror_only) { 18962 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18963 peak = static_cast<float>(qn); 18964 mirror = 0; 18965 } else { 18966 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18967 peak = static_cast<float>(qn); 18968 mirror = 1; 18969 } 18970 } 18971 } 18972 } 18973 delete cimage; cimage = 0; 18974 } 18975 } else { 18976 int ky = int(ynumber/2); 18977 float stepy=2*yrng/ynumber; 18978 int ky_rhs = ky; 18979 int ky_lhs = -ky + 1; 18980 18981 // when yrnglocal is not equal to -1.0, the search range is limited to +/- yrnglocal 18982 // leave step size the same 18983 18984 if (CONS){ 18985 18986 ky_rhs = floor((abs(y_lhs))/stepy); 18987 ky_lhs = -1.0*floor((abs(y_rhs))/stepy); 18988 18989 } 18990 else{ 18991 if (yrnglocal >= 0.0){ 18992 ky_rhs = int(yrnglocal/stepy); 18993 ky_lhs = -ky_rhs + 1; 18994 } 18995 } 18996 18997 //std::cout<<"yrnglocal="<<yrnglocal<<"ynumber="<<ynumber<<"stepy=="<<stepy<<"stepx=="<<step<<std::endl; 18998 //cout<<"ky stepy: "<<ky<<" "<<stepy<<endl; 18999 for (int i = ky_lhs; i <= ky_rhs; i++) { 19000 iy = i * stepy ; 19001 ychoice = ychoice+1; 19002 for (int j = -kx; j <= kx; j++) { 19003 ix = j*step ; 19004 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 19005 19006 Normalize_ring( cimage, numr ); 19007 19008 Frngs(cimage, numr); 19009 // compare with all reference images 19010 // for iref in xrange(len(crefim)): 19011 for ( iref = 0; iref < (int)crefim_len; iref++) { 19012 19013 use_ref = false; 19014 if (!mirror_only){ 19015 // inner product of iref's Eulerian angles with that of the data 19016 nbrinp = n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3; 19017 if (CONS){ 19018 19019 if ((ref_phi[iref] <= phi_upper) && (ref_phi[iref] >= phi_lower)){ 19020 use_ref = true; 19021 } 19022 } 19023 else{ 19024 if (nbrinp >= ant){ 19025 use_ref = true; 19026 } 19027 } 19028 } 19029 else if (mirror_only) { 19030 // inner product of the mirror of iref's Eulerian angles with that of the data 19031 nbrinp = (-1.0*n1[iref]*imn1) + (-1.0*n2[iref]*imn2) + n3[iref]*imn3; 19032 if (CONS){ 19033 if ((ref_phi[iref] + 180. <= phi_upper) && (ref_phi[iref]+180. >= phi_lower)){ 19034 use_ref = true; 19035 } 19036 } 19037 else{ 19038 if (nbrinp >= ant){ 19039 use_ref = true; 19040 } 19041 } 19042 19043 } 19044 if(use_ref) { 19045 phichoice = phichoice + 1; 19046 Dict retvals; 19047 if (mirror_only == true){ 19048 if ((psi-90) < 90) 19049 retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, 0, 1, psi_max); 19050 else 19051 retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, 180, 1, psi_max); 19052 } 19053 else{ 19054 if ((psi-90) < 90) 19055 retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, 0, 0, psi_max); 19056 else 19057 retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, 180, 0, psi_max); 19058 } 19059 double qn = retvals["qn"]; 19060 19061 if(qn >= peak) { 19062 sx = -ix; 19063 sy = -iy; 19064 nref = iref; 19065 if (!mirror_only) { 19066 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 19067 peak = static_cast<float>(qn); 19068 mirror = 0; 19069 } else { 19070 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 19071 peak = static_cast<float>(qn); 19072 mirror = 1; 19073 } 19074 } 19075 } 19076 } 19077 delete cimage; cimage = 0; 19078 } 19079 } 19080 } 19081 if ((phichoice < 1) || (ychoice < 1)) 19082 cout<<ychoice<<", "<<phichoice<<", ..."<<mirror_only<<"...,"<<phi<<","<<phi_lhs<<","<<phi_rhs<<endl; 19083 19084 float co, so, sxs, sys; 19085 co = static_cast<float>( cos(ang*pi/180.0) ); 19086 so = static_cast<float>( -sin(ang*pi/180.0) ); 19087 sxs = sx*co - sy*so; 19088 sys = sx*so + sy*co; 19089 vector<float> res; 19090 res.push_back(ang); 19091 res.push_back(sxs); 19092 res.push_back(sys); 19093 res.push_back(static_cast<float>(mirror)); 19094 res.push_back(static_cast<float>(nref)); 19095 res.push_back(peak); 19096 return res; 19097 }
int Util::nearest_ang | ( | const vector< float > & | vecref, | |
float | x, | |||
float | y, | |||
float | z | |||
) | [static] |
Definition at line 18116 of file util_sparx.cpp.
Referenced by assign_projangles().
18116 { 18117 float best_v = -1.0f; 18118 int best_i = -1; 18119 18120 for (unsigned int i=0; i<vecref.size()/3; i++) { 18121 float v = abs(vecref[i*3]*x+vecref[i*3+1]*y+vecref[i*3+2]*z); 18122 if (v > best_v) { 18123 best_v = v; 18124 best_i = i; 18125 } 18126 } 18127 return best_i; 18128 }
vector< int > Util::nearestk_to_refdir | ( | const vector< float > & | projangles, | |
const vector< float > & | refangles, | |||
const int | howmany | |||
) | [static] |
Definition at line 18154 of file util_sparx.cpp.
References abs, getvec(), and v.
18154 { 18155 int nref = refangles.size()/2; 18156 int nproj = projangles.size()/2; 18157 vector<int> asg(howmany*nref); 18158 vector<float> vecproj(nproj*3); 18159 for (int i=0; i<nproj; i++) 18160 getvec(projangles[i*2], projangles[i*2+1], vecproj[i*3], vecproj[i*3+1], vecproj[i*3+2]); 18161 18162 18163 vector<bool> taken(nproj); 18164 for (int k=0; k<nref; k++) { 18165 for (int i=0; i<nproj; i++) taken[i] = true; 18166 float x, y, z; 18167 getvec(refangles[k*2], refangles[k*2+1], x, y, z); 18168 for (int h=0; h<howmany; h++) { 18169 float best_v = -1.0f; 18170 int best_i = -1; 18171 for (int i=0; i<nproj; i++) { 18172 if( taken[i] ) { 18173 float v = abs(vecproj[i*3]*x+vecproj[i*3+1]*y+vecproj[i*3+2]*z); 18174 if (v > best_v) { 18175 best_v = v; 18176 best_i = i; 18177 } 18178 } 18179 } 18180 asg[k*howmany + h] = best_i; 18181 taken[best_i] = false; 18182 } 18183 } 18184 return asg; 18185 }
static int EMAN::Util::nint180 | ( | float | arg | ) | [inline, static] |
void Util::Normalize_ring | ( | EMData * | ring, | |
const vector< int > & | numr | |||
) | [static] |
Definition at line 17896 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 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().
17897 { 17898 float* data = ring->get_data(); 17899 float av=0.0; 17900 float sq=0.0; 17901 float nn=0.0; 17902 int nring = numr.size()/3; 17903 for( int i=0; i < nring; ++i ) 17904 { 17905 int numr3i = numr[3*i+2]; 17906 int numr2i = numr[3*i+1]-1; 17907 float w = numr[3*i]*2*M_PI/float(numr[3*i+2]); 17908 for( int j=0; j < numr3i; ++j ) 17909 { 17910 int jc = numr2i+j; 17911 av += data[jc] * w; 17912 sq += data[jc] * data[jc] * w; 17913 nn += w; 17914 } 17915 } 17916 17917 float avg = av/nn; 17918 float sgm = sqrt( (sq-av*av/nn)/nn ); 17919 size_t n = (size_t)ring->get_xsize() * ring->get_ysize() * ring->get_zsize(); 17920 for( size_t i=0; i < n; ++i ) 17921 { 17922 data[i] -= avg; 17923 data[i] /= sgm; 17924 } 17925 17926 ring->update(); 17927 }
Definition at line 17806 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().
17807 { 17808 ENTERFUNC; 17809 /* Exception Handle */ 17810 if (!img) { 17811 throw NullPointerException("NULL input image"); 17812 } 17813 /* ============== img is modulus of a complex image in FFT format (so its imaginary parts are zero), 17814 output is img packed into real image with Friedel part added, ================ */ 17815 17816 int nxo=img->get_xsize(), ny=img->get_ysize(), nz=img->get_zsize(); 17817 int nx = nxo - 2 + img->is_fftodd(); 17818 int lsd2 = (nx + 2 - nx%2) / 2; // Extended x-dimension of the complex image 17819 int nyt, nzt; 17820 int nx2 = nx/2; 17821 int ny2 = ny/2; if(ny2 == 0) nyt =0; else nyt=ny; 17822 int nz2 = nz/2; if(nz2 == 0) nzt =0; else nzt=nz; 17823 int nx2p = nx2+nx%2; 17824 int ny2p = ny2+ny%2; 17825 int nz2p = nz2+nz%2; 17826 EMData& power = *(new EMData()); // output image 17827 power.set_size(nx, ny, nz); 17828 power.set_array_offsets(-nx2,-ny2,-nz2); 17829 //img->set_array_offsets(1,1,1); 17830 float *img_ptr = img->get_data(); 17831 for (int iz = 1; iz <= nz; iz++) { 17832 int jz=iz-1; 17833 if(jz>=nz2p) jz=jz-nzt; 17834 for (int iy = 1; iy <= ny; iy++) { 17835 int jy=iy-1; 17836 if(jy>=ny2p) jy=jy-nyt; 17837 for (int ix = 1; ix <= lsd2; ix++) { 17838 int jx=ix-1; 17839 if(jx>=nx2p) jx=jx-nx; 17840 power(jx,jy,jz) = img_ptr(ix,iy,iz); //real(img->cmplx(ix,iy,iz)); 17841 } 17842 } 17843 } 17844 // Create the Friedel related half 17845 int nzb, nze, nyb, nye, nxb, nxe; 17846 nxb =-nx2+(nx+1)%2; 17847 nxe = nx2-(nx+1)%2; 17848 if(ny2 == 0) {nyb =0; nye = 0;} else {nyb =-ny2+(ny+1)%2; nye = ny2-(ny+1)%2;} 17849 if(nz2 == 0) {nzb =0; nze = 0;} else {nzb =-nz2+(nz+1)%2; nze = nz2-(nz+1)%2;} 17850 for (int iz = nzb; iz <= nze; iz++) { 17851 for (int iy = nyb; iy <= nye; iy++) { 17852 for (int ix = 1; ix <= nxe; ix++) { // Note this loop begins with 1 - FFT should create correct Friedel related 0 plane 17853 power(-ix,-iy,-iz) = power(ix,iy,iz); 17854 } 17855 } 17856 } 17857 if(ny2 != 0) { 17858 if(nz2 != 0) { 17859 if(nz%2 == 0) { //if nz even, fix the first slice 17860 for (int iy = nyb; iy <= nye; iy++) { 17861 for (int ix = nxb; ix <= -1; ix++) { 17862 power(ix,iy,-nz2) = power(-ix,-iy,-nz2); 17863 } 17864 } 17865 if(ny%2 == 0) { //if ny even, fix the first line 17866 for (int ix = nxb; ix <= -1; ix++) { 17867 power(ix,-ny2,-nz2) = power(-ix,-ny2,-nz2); 17868 } 17869 } 17870 } 17871 } 17872 if(ny%2 == 0) { //if ny even, fix the first column 17873 for (int iz = nzb; iz <= nze; iz++) { 17874 for (int ix = nxb; ix <= -1; ix++) { 17875 power(ix,-ny2,-iz) = power(-ix,-ny2,iz); 17876 } 17877 } 17878 } 17879 17880 } 17881 power.update(); 17882 power.set_array_offsets(0,0,0); 17883 return &power; 17884 }
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 5375 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().
05376 { 05377 /* Exception Handle */ 05378 if (!img) throw NullPointerException("NULL input image"); 05379 /* ============================== */ 05380 05381 // Get the size of the input image 05382 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 05383 /* ============================== */ 05384 05385 /* Exception Handle */ 05386 if(new_nx<nx || new_ny<ny || new_nz<nz) 05387 throw ImageDimensionException("The size of the padded image cannot be lower than the input image size."); 05388 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) 05389 throw ImageDimensionException("The offset inconsistent with the input image size. Solution: Change the offset parameters"); 05390 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)))) 05391 throw ImageDimensionException("The offset inconsistent with the input image size. Solution: Change the offset parameters"); 05392 /* ============================== */ 05393 05394 EMData* pading = img->copy_head(); 05395 pading->set_size(new_nx, new_ny, new_nz); 05396 float *inp = img->get_data(); 05397 float *outp = pading->get_data(); 05398 05399 05400 /* Calculation of the average and the circumference values for background substitution 05401 =======================================================================================*/ 05402 float background; 05403 05404 if (strcmp(params,"average")==0) background = img->get_attr("mean"); 05405 else if (strcmp(params,"circumference")==0) { 05406 float sum1=0.0f; 05407 size_t cnt=0; 05408 for(int i=0;i<nx;i++) { 05409 sum1 += inp(i,0,0) + inp(i,ny-1,nz-1); 05410 cnt+=2; 05411 } 05412 if(nz-1 == 0) { 05413 for (int j=1;j<ny-1;j++) { 05414 sum1 += inp(1,j,0) + inp(nx-1,j,0); 05415 cnt+=2; 05416 } 05417 } else { 05418 for (int k=1;k<nz-1;k++) { 05419 for (int j=1;j<ny-1;j++) { 05420 sum1 += inp(1,j,0) + inp(nx-1,j,0); 05421 cnt+=2; 05422 } 05423 } 05424 } 05425 background = sum1/cnt; 05426 } else { 05427 background = static_cast<float>( atof( params ) ); 05428 } 05429 /*=====================================================================================*/ 05430 05431 /*Initial Padding */ 05432 int new_st_x=0,new_st_y=0,new_st_z=0; 05433 for (int k=0;k<new_nz;k++) 05434 for(int j=0;j<new_ny;j++) 05435 for (int i=0;i<new_nx;i++) 05436 outp(i,j,k)=background; 05437 /*============================== */ 05438 05439 /* Calculation of the start point */ 05440 new_st_x=int((new_nx/2-nx/2) + x_offset); 05441 new_st_y=int((new_ny/2-ny/2) + y_offset); 05442 new_st_z=int((new_nz/2-nz/2) + z_offset); 05443 /* ============================== */ 05444 05445 for (int k=0;k<nz;k++) 05446 for(int j=0;j<ny;j++) 05447 for(int i=0;i<nx;i++) 05448 outp(i,j,k)=inp(i,j,k); 05449 pading->update(); 05450 return pading; 05451 }
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 1269 of file util.cpp.
References point_is_in_triangle_2d().
01270 { 01271 01272 if (point_is_in_triangle_2d(p1,p2,p4,actual_point)) return true; 01273 else return point_is_in_triangle_2d(p3,p2,p4,actual_point); 01274 }
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 1234 of file util.cpp.
References EMAN::Vec2< Type >::dot(), EMAN::Transform::ERR_LIMIT, t, and v.
Referenced by point_is_in_convex_polygon_2d().
01235 { 01236 01237 Vec2f u = p2 - p1; 01238 Vec2f v = p3 - p1; 01239 Vec2f w = point - p1; 01240 01241 float udotu = u.dot(u); 01242 float udotv = u.dot(v); 01243 float udotw = u.dot(w); 01244 float vdotv = v.dot(v); 01245 float vdotw = v.dot(w); 01246 01247 float d = 1.0f/(udotv*udotv - udotu*vdotv); 01248 float s = udotv*vdotw - vdotv*udotw; 01249 s *= d; 01250 01251 float t = udotv*udotw - udotu*vdotw; 01252 t *= d; 01253 01254 // We've done a few multiplications, so detect when there are tiny residuals that may throw off the final 01255 // decision 01256 if (fabs(s) < Transform::ERR_LIMIT ) s = 0; 01257 if (fabs(t) < Transform::ERR_LIMIT ) t = 0; 01258 01259 if ( fabs((fabs(s)-1.0)) < Transform::ERR_LIMIT ) s = 1; 01260 if ( fabs((fabs(t)-1.0)) < Transform::ERR_LIMIT ) t = 1; 01261 01262 // cout << "s and t are " << s << " " << t << endl; 01263 01264 // The final decision, if this is true then we've hit the jackpot 01265 if ( s >= 0 && t >= 0 && (s+t) <= 1 ) return true; 01266 else return false; 01267 }
Definition at line 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(), 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 3155 of file util_sparx.cpp.
References b.
Referenced by Crosrng_e(), Crosrng_ew(), Crosrng_ms(), Crosrng_ns(), and Crosrng_psi_0_180_no_mirror().
03155 { 03156 double c2,c3; 03157 int nhalf; 03158 03159 nhalf = npoint/2 + 1; 03160 *pos = 0.0; 03161 03162 if (npoint == 7) { 03163 c2 = 49.*b(1) + 6.*b(2) - 21.*b(3) - 32.*b(4) - 27.*b(5) 03164 - 6.*b(6) + 31.*b(7); 03165 c3 = 5.*b(1) - 3.*b(3) - 4.*b(4) - 3.*b(5) + 5.*b(7); 03166 } 03167 else if (npoint == 5) { 03168 c2 = (74.*b(1) - 23.*b(2) - 60.*b(3) - 37.*b(4) 03169 + 46.*b(5) ) / (-70.); 03170 c3 = (2.*b(1) - b(2) - 2.*b(3) - b(4) + 2.*b(5) ) / 14.0; 03171 } 03172 else if (npoint == 3) { 03173 c2 = (5.*b(1) - 8.*b(2) + 3.*b(3) ) / (-2.0); 03174 c3 = (b(1) - 2.*b(2) + b(3) ) / 2.0; 03175 } 03176 //else if (npoint == 9) { 03177 else { // at least one has to be true!! 03178 c2 = (1708.*b(1) + 581.*b(2) - 246.*b(3) - 773.*b(4) 03179 - 1000.*b(5) - 927.*b(6) - 554.*b(7) + 119.*b(8) 03180 + 1092.*b(9) ) / (-4620.); 03181 c3 = (28.*b(1) + 7.*b(2) - 8.*b(3) - 17.*b(4) - 20.*b(5) 03182 - 17.*b(6) - 8.*b(7) + 7.*b(8) + 28.*b(9) ) / 924.0; 03183 } 03184 if (c3 != 0.0) *pos = static_cast<float>(c2/(2.0*c3) - nhalf); 03185 }
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 1118 of file util.cpp.
01118 { 01119 // Note: Don't need to check if 3-D because 3D is part of 01120 // the MIArray3D typedef. 01121 out << "Printing 3D Integer data: " << str << std::endl; 01122 const multi_array_types::size_type* sizes = mat.shape(); 01123 int nx = sizes[0], ny = sizes[1], nz = sizes[2]; 01124 const multi_array_types::index* indices = mat.index_bases(); 01125 int bx = indices[0], by = indices[1], bz = indices[2]; 01126 for (int iz = bz; iz < nz+bz; iz++) { 01127 cout << "(z = " << iz << " slice)" << endl; 01128 for (int ix = bx; ix < nx+bx; ix++) { 01129 for (int iy = by; iy < ny+by; iy++) { 01130 cout << setiosflags(ios::fixed) << setw(5) 01131 << mat[ix][iy][iz] << " "; 01132 } 01133 cout << endl; 01134 } 01135 } 01136 }
vector< float > Util::pw_extract | ( | vector< float > | pw, | |
int | n, | |||
int | iswi, | |||
float | ps | |||
) | [static] |
Definition at line 6411 of file util_sparx.cpp.
References call_cl1(), log(), and q.
06412 { 06413 int k,m,n1,klmd,klm2d,nklmd,n2d,n_larg,l, n2; 06414 06415 k=(int)pw.size(); 06416 l=0; 06417 m=k; 06418 n2=n+2; 06419 n1=n+1; 06420 klmd=k+l+m; 06421 klm2d= k+l+m+2; 06422 nklmd=k+l+m+n; 06423 n2d=n+2; 06424 /*size has to be increased when N is large*/ 06425 n_larg=klmd*2; 06426 klm2d=n_larg+klm2d; 06427 klmd=n_larg+klmd; 06428 nklmd=n_larg+nklmd; 06429 int size_q=klm2d*n2d; 06430 int size_cu=nklmd*2; 06431 static int i__; 06432 06433 double *q ; 06434 double *x ; 06435 double *res; 06436 double *cu; 06437 float *q2; 06438 float *pw_; 06439 long int *iu; 06440 double *s; 06441 q = (double*)calloc(size_q,sizeof(double)); 06442 x = (double*)calloc(n2d,sizeof(double)); 06443 res = (double*)calloc(klmd,sizeof(double)); 06444 cu =(double*)calloc(size_cu,sizeof(double)); 06445 s = (double*)calloc(klmd,sizeof(double)); 06446 q2 = (float*)calloc(size_q,sizeof(float)); 06447 iu = (long int*)calloc(size_cu,sizeof(long int)); 06448 pw_ = (float*)calloc(k,sizeof(float)); 06449 06450 for( i__ =0;i__<k;++i__) 06451 { 06452 pw_[i__]=log(pw[i__]); } 06453 long int l_k=k; 06454 long int l_n=n; 06455 long int l_iswi=iswi; 06456 vector<float> cl1_res; 06457 cl1_res=Util::call_cl1(&l_k, &l_n, &ps, &l_iswi, pw_, q2, q, x, res, cu, s, iu); 06458 free(q); 06459 free(x); 06460 free(res); 06461 free(s); 06462 free(cu); 06463 free(q2); 06464 free(iu); 06465 free(pw_); 06466 return cl1_res; 06467 }
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(), quadri_background(), and EMAN::EMData::rot_scale_trans2D().
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.
Referenced by EMAN::EMData::rot_scale_trans2D_background().
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 6242 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().
06243 { 06244 /******** 06245 ***Exception Handle 06246 *************/ 06247 if(mask == NULL) 06248 throw ImageDimensionException("The mask cannot be an null image"); 06249 06250 /*********** 06251 ***get the size of the mask 06252 **************/ 06253 int nx = mask->get_xsize(),ny = mask->get_ysize(),nz = mask->get_zsize(); 06254 06255 size_t i,size = (size_t)nx*ny*nz; /* loop counters */ 06256 /* new image declaration */ 06257 EMData *new_image = new EMData(); 06258 new_image->set_size(nx,ny,nz); /* set the size of new image */ 06259 float *new_ptr = new_image->get_data(); /* set size of the new image */ 06260 float *mask_ptr = mask->get_data(); /* assign a pointer to the mask image */ 06261 float *img_ptr = image->get_data(); /* assign a pointer to the 1D image */ 06262 int count = 0; 06263 float sum_under_mask = 0.0 ; 06264 for(i = 0;i < size;i++){ 06265 if(mask_ptr[i] > 0.5f){ 06266 new_ptr[i] = img_ptr[count]; 06267 sum_under_mask += img_ptr[count]; 06268 count++; 06269 if( count > image->get_xsize() ) { 06270 throw ImageDimensionException("Error: in reconstitute_image_mask, the mask doesn't match the image, it is too large"); 06271 } 06272 } 06273 } 06274 06275 if( count > image->get_xsize() ) { 06276 throw ImageDimensionException("Error: in reconstitute_image_mask, the mask doesn't match the image, it is too small"); 06277 } 06278 06279 float avg_under_mask = sum_under_mask / count; 06280 for(i = 0;i < size;i++) { 06281 if(mask_ptr[i] <= 0.5f) new_ptr[i] = avg_under_mask; 06282 } 06283 new_image->update(); 06284 return new_image; 06285 }
string Util::recv_broadcast | ( | int | port | ) | [static] |
Definition at line 1041 of file util.cpp.
References BPKT::data, BPKT::hdr, EMAN::ByteOrder::is_host_big_endian(), BPKT::len, BPKT::oseq, and BPKT::pseq.
01041 { 01042 // struct sockaddr_in sadr = { AF_INET, 9989, INADDR_ANY}; 01043 // int sock=socket(AF_INET,SOCK_DGRAM,0); 01044 // if (bind(sock,&sadr,sizeof(sockaddr_in))) return string(); 01045 01046 if (ByteOrder::is_host_big_endian()) { 01047 printf("No cache mirroring on Big endian machines yet\n"); 01048 return string(); // FIXME: no support for big endian hosts 01049 } 01050 01051 BPKT pkt; 01052 string ret; 01053 vector<char> fill; 01054 int obj=-1; 01055 unsigned int i=0; 01056 // printf ("Listening\n"); 01057 01058 while (1) { 01059 int l = recv(sock,&pkt,1044,0); 01060 if (l<=0) { 01061 if (obj!=-1) printf("Timeout with incomplete obj %d %d/%d\n",obj,i,(int)fill.size()); 01062 return string(); // probably a timeout 01063 } 01064 if (l<20) { 01065 printf("Bad packet from broadcast"); 01066 continue; 01067 } 01068 01069 if (strncmp(pkt.hdr,"EMAN",4)!=0) continue; 01070 01071 // new object coming in 01072 if (obj!=pkt.oseq) { 01073 obj=pkt.oseq; 01074 ret.resize(pkt.len); 01075 fill.resize((pkt.len-1)/1024+1); 01076 for (i=0; i<fill.size(); i++) fill[i]=0; 01077 } 01078 if (obj==-1) printf("Something wierd happened. please report\n"); 01079 01080 // copy the packet into the output buffer 01081 fill[pkt.pseq]=1; 01082 ret.replace(pkt.pseq*1024,l-20,(char *)pkt.data,l-20); 01083 01084 // see if we got everything 01085 for (i=0; i<fill.size(); i++) { 01086 if (fill[i]!=1) break; 01087 } 01088 // printf("\t\t\tObj %d %d/%d \r",obj,i,(int)fill.size()); 01089 fflush(stdout); 01090 01091 if (i==fill.size()) return ret; // Yea ! We got a good packet 01092 } 01093 01094 }
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 450 of file util.cpp.
00451 { 00452 if (filename == "") { 00453 return ""; 00454 } 00455 00456 char *buf = new char[filename.size()+1]; 00457 strcpy(buf, filename.c_str()); 00458 char *old_ext = strrchr(buf, '.'); 00459 if (old_ext) { 00460 buf[strlen(buf) - strlen(old_ext)] = '\0'; 00461 } 00462 string result = string(buf); 00463 if( buf ) 00464 { 00465 delete [] buf; 00466 buf = 0; 00467 } 00468 return result; 00469 }
static float EMAN::Util::restrict1 | ( | float | x, | |
int | nx | |||
) | [inline, static] |
Definition at line 1142 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 95 of file util.cpp.
References t.
00096 { 00097 if(ny==1 && nz==1) { //1D, do nothing 00098 return; 00099 } 00100 else if(ny!=1 && nz==1) { //2D, rotate vertically by ny/2 00101 size_t i, j, k, l; 00102 float re; 00103 l=ny/2*nx; 00104 for (i=0; i<ny/2; i++) { 00105 for (j=0; j<nx; j++) { 00106 k=j+i*nx; 00107 re=data[k]; 00108 data[k]=data[k+l]; 00109 data[k+l]=re; 00110 } 00111 } 00112 } 00113 else { //3D, in the y,z plane, swaps quadrants I,III and II,IV, this is the 'rotation' in y and z 00114 size_t i, j, k, l, ii, jj; 00115 char * t=(char *)malloc(sizeof(float)*nx); 00116 00117 k=nx*ny*(nz+1)/2; 00118 l=nx*ny*(nz-1)/2; 00119 jj=nx*sizeof(float); 00120 for (j=ii=0; j<nz/2; ++j) { 00121 for (i=0; i<ny; ++i,ii+=nx) { 00122 memcpy(t,data+ii,jj); 00123 if (i<ny/2) { 00124 memcpy(data+ii,data+ii+k,jj); 00125 memcpy(data+ii+k,t,jj); 00126 } 00127 else { 00128 memcpy(data+ii,data+ii+l,jj); 00129 memcpy(data+ii+l,t,jj); 00130 } 00131 } 00132 } 00133 free(t); 00134 } 00135 }
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 1502 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(), EMAN::EMData::extract_plane(), EMAN::EMData::extract_plane_rect(), EMAN::EMData::extract_plane_rect_fast(), EMAN::EMData::extractline(), EMAN::EMData::extractpoint(), extractpoint2(), EMAN::nnSSNR_ctfReconstructor::finish(), EMAN::nnSSNR_Reconstructor::finish(), EMAN::EMData::get_pixel_conv(), get_pixel_conv_new(), get_pixel_conv_new_background(), EMAN::EMData::get_pixel_filtered(), hypot_fast_int(), EMAN::EMData::phase_cog(), EMAN::ApplyPolynomialProfileToHelix::process_inplace(), EMAN::BeamstopProcessor::process_inplace(), EMAN::EMData::rot_scale_conv(), EMAN::EMData::rot_scale_conv7(), 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 21110 of file util_sparx.cpp.
References k_means_cont_table_().
21110 { 21111 //cout<<"sanitycheck called\n"; 21112 int total_cost = *output; 21113 int num_matches = *(output+1); 21114 21115 int cost=0; 21116 int* intx; 21117 int intx_size; 21118 int* intx_next(0); 21119 int intx_next_size = 0; 21120 int curclass; 21121 int curclass_size; 21122 //cout<<"cost by match: ["; 21123 for(int i = 0; i < num_matches; i++){ 21124 curclass = *(output+2+ i*nParts); 21125 // check feasibility 21126 if (*(argParts + Indices[curclass]+1) == -5) {cout<<"infeasible match!\n"; return 0;} 21127 *(argParts + Indices[curclass]+1) = -5; 21128 // initialize intx to the number of elements in class curclass of partition 0 of the i-th match 21129 curclass_size = *(dimClasses+curclass)-2; 21130 intx = new int[curclass_size]; 21131 for (int ic = 0; ic < curclass_size; ic++) *(intx+ic) = *(argParts + Indices[curclass]+2+ic); 21132 intx_size = curclass_size; 21133 21134 for (int j=1; j < nParts; j++){ 21135 curclass = *(output+2+ i*nParts+j); 21136 if (*(argParts + Indices[j*K+curclass]+1)==-5){cout<<"infeasible match!\n"; return 0;} 21137 *(argParts + Indices[j*K+curclass]+1)=-5; 21138 // compute the intersection of intx and class curclass of partition j of the i-th match 21139 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); 21140 intx_next = new int[intx_next_size]; 21141 Util::k_means_cont_table_(intx,argParts + Indices[j*K+curclass]+2, intx_next, intx_size, *(dimClasses + j*K+curclass)-2,1); 21142 delete[] intx; 21143 intx=intx_next; 21144 intx_size= intx_next_size; 21145 } 21146 delete[] intx_next; 21147 21148 if (intx_next_size <= T) {cout << "something wrong with solution!\n"; return 0;} 21149 //cout <<intx_next_size<<","; 21150 cost = cost + intx_next_size; 21151 } 21152 //cout<<"]\n"; 21153 if (cost != total_cost) {cout << "something wrong with solution!\n"; return 0;} 21154 21155 return 1; 21156 21157 }
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 618 of file util.cpp.
References Assert, FileAccessException, and NullPointerException.
00620 { 00621 Assert(dx > 0); 00622 Assert(array_size > 0); 00623 Assert(filename != ""); 00624 00625 if (!y_array) { 00626 throw NullPointerException("y array"); 00627 } 00628 00629 FILE *out = fopen(filename.c_str(), "wb"); 00630 if (!out) { 00631 throw FileAccessException(filename); 00632 } 00633 00634 for (size_t i = 0; i < array_size; i++) { 00635 fprintf(out, "%g\t%g\n", x0 + dx * i, y_array[i]); 00636 } 00637 fclose(out); 00638 }
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 599 of file util.cpp.
References Assert, and FileAccessException.
00601 { 00602 Assert(dx != 0); 00603 Assert(y_array.size() > 0); 00604 Assert(filename != ""); 00605 00606 FILE *out = fopen(filename.c_str(), "wb"); 00607 if (!out) { 00608 throw FileAccessException(filename); 00609 } 00610 00611 for (size_t i = 0; i < y_array.size(); i++) { 00612 fprintf(out, "%g\t%g\n", x0 + dx * i, y_array[i]); 00613 } 00614 fclose(out); 00615 }
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 575 of file util.cpp.
References Assert, FileAccessException, and LOGERR.
Referenced by EMAN::LowpassAutoBProcessor::create_radial_func(), and EMAN::CtfAverager::finish().
00577 { 00578 Assert(x_array.size() > 0); 00579 Assert(y_array.size() > 0); 00580 Assert(filename != ""); 00581 00582 if (x_array.size() != y_array.size()) { 00583 LOGERR("array x and array y have different size: %d != %d\n", 00584 x_array.size(), y_array.size()); 00585 return; 00586 } 00587 00588 FILE *out = fopen(filename.c_str(), "wb"); 00589 if (!out) { 00590 throw FileAccessException(filename); 00591 } 00592 00593 for (size_t i = 0; i < x_array.size(); i++) { 00594 fprintf(out, "%g\t%g\n", x_array[i], y_array[i]); 00595 } 00596 fclose(out); 00597 }
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 471 of file util.cpp.
Referenced by EMAN::Log::begin(), EMAN::TestUtil::check_image(), EMAN::TestUtil::dump_emdata(), EMAN::Log::loc(), and EMAN::TestUtil::set_progname().
00472 { 00473 if (filename == "") { 00474 return ""; 00475 } 00476 00477 char s = '/'; 00478 #ifdef _WIN32 00479 s = '\\'; 00480 #endif 00481 const char * c = strrchr(filename.c_str(), s); 00482 if (!c) { 00483 return filename; 00484 } 00485 else { 00486 c++; 00487 } 00488 return string(c); 00489 }
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 21164 of file util_sparx.cpp.
References explore2(), and k_means_cont_table_().
21164 { 21165 21166 // some temp variables 21167 bool flag = 0; 21168 int nintx; 21169 int* dummy(0); 21170 //int* ret; 21171 int* curbranch = new int[nParts]; 21172 21173 //initialize costlist to all 0 21174 for(int jit= 0; jit< J; jit++) *(costlist+jit) = 0; 21175 21176 21177 for(int a=0; a<K; a++) 21178 { 21179 21180 // 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 21181 if (*(argParts + Indices[a] + 1) < 1) continue; 21182 if (*(dimClasses + a)-2 <= T) continue; 21183 21184 // 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 21185 21186 for( int i=1; i < nParts; i++){ 21187 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. 21188 for(int j=0; j < K; j++){ 21189 if (*(argParts + Indices[i*K+j] + 1) < 1) continue; 21190 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); 21191 if (nintx > T) flag=1; 21192 else *(argParts + Indices[i*K+j] + 1) =-4; 21193 } 21194 if (flag==0) {break;} 21195 } 21196 21197 // explore determines J matchs with the largest weight greater than T where class in partition 0 is class a 21198 *curbranch = a; 21199 21200 if (flag > 0) // Each partition has one or more active class 21201 Util::explore2(argParts, Indices, dimClasses, nParts, K, T, argParts+Indices[a]+2, *(dimClasses+a)-2, argParts+Indices[a]+2, 21202 *(dimClasses+a)-2,0, J, matchlist, costlist, curbranch); 21203 21204 // take all the classes marked as -4 and remark it as 1 in preparation for next round 21205 for( int i=1; i < nParts; i++){ 21206 for(int j=0; j < K; j++){ 21207 if (*(argParts + Indices[i*K+j] + 1) == -4) *(argParts + Indices[i*K+j] + 1) =1; 21208 21209 } 21210 } 21211 } 21212 21213 delete[] curbranch; 21214 }
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 4725 of file util_sparx.cpp.
References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), img_ptr, nx, and EMAN::EMData::update().
04726 { 04727 int i; 04728 int nx=img->get_xsize(); 04729 float *img_ptr = img->get_data(); 04730 float *line_ptr = line->get_data(); 04731 for (i=0;i<length;i++) img_ptr[nx*posline + i] = line_ptr[offset + i]; 04732 img->update(); 04733 }
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 1108 of file util.cpp.
References EMAN::Log::logger(), and EMAN::Log::set_level().
01109 { 01110 if (argc > 1 && strncmp(argv[1], "-v", 2) == 0) { 01111 char level_str[32]; 01112 strcpy(level_str, argv[1] + 2); 01113 Log::LogLevel log_level = (Log::LogLevel) atoi(level_str); 01114 Log::logger()->set_level(log_level); 01115 } 01116 }
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 678 of file util.cpp.
References EMAN::Randnum::Instance(), and EMAN::Randnum::set_seed().
00679 { 00680 Randnum* randnum = Randnum::Instance(); 00681 randnum->set_seed(seed); 00682 }
static T EMAN::Util::sgn | ( | T & | val | ) | [inline, static] |
Sign function.
[in] | val | value who's sign is to be checked |
Definition at line 2113 of file util.h.
Referenced by EMAN::EMData::extract_plane(), EMAN::EMData::extract_plane_rect(), EMAN::EMData::extract_plane_rect_fast(), EMAN::EMData::extractline(), fftc_d(), fftc_q(), and EMAN::EMData::getconvpt2d_kbi0().
void Util::slicereverse | ( | float * | beg, | |
float * | end, | |||
int | nx, | |||
int | ny | |||
) | [static] |
Definition at line 5469 of file util_sparx.cpp.
References colreverse().
Referenced by cyclicshift().
05470 { 05471 int nxy = nx*ny; 05472 colreverse(beg, end, nxy); 05473 }
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 641 of file util.cpp.
Referenced by Radialize().
00643 { 00644 float *pivot ; int *pivotPerm; 00645 00646 { 00647 float *pLeft = left; int *pLeftPerm = leftPerm; 00648 float *pRight = right; int *pRightPerm = rightPerm; 00649 float scratch = *left; int scratchPerm = *leftPerm; 00650 00651 while (pLeft < pRight) { 00652 while ((*pRight > scratch) && (pLeft < pRight)) { 00653 pRight--; pRightPerm--; 00654 } 00655 if (pLeft != pRight) { 00656 *pLeft = *pRight; *pLeftPerm = *pRightPerm; 00657 pLeft++; pLeftPerm++; 00658 } 00659 while ((*pLeft < scratch) && (pLeft < pRight)) { 00660 pLeft++; pLeftPerm++; 00661 } 00662 if (pLeft != pRight) { 00663 *pRight = *pLeft; *pRightPerm = *pLeftPerm; 00664 pRight--; pRightPerm--; 00665 } 00666 } 00667 *pLeft = scratch; *pLeftPerm = scratchPerm; 00668 pivot = pLeft; pivotPerm= pLeftPerm; 00669 } 00670 if (left < pivot) { 00671 sort_mat(left, pivot - 1,leftPerm,pivotPerm-1); 00672 } 00673 if (right > pivot) { 00674 sort_mat(pivot + 1, right,pivotPerm+1,rightPerm); 00675 } 00676 }
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 1624 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 1652 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 247 of file util.cpp.
References NullPointerException.
Referenced by EMAN::TestUtil::dump_emdata().
00248 { 00249 if (!s1 || !s2) { 00250 throw NullPointerException("Null string"); 00251 } 00252 00253 if (strncmp(s1, s2, strlen(s2)) == 0) { 00254 return true; 00255 } 00256 00257 return false; 00258 }
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 241 of file util.cpp.
Referenced by EMAN::Transform::detect_problem_keys(), EMAN::Symmetry3D::gen_orientations(), EMAN::Dict::get_ci(), EMAN::Transform::get_params(), EMAN::Transform::get_params_inverse(), EMAN::Transform::get_rotation(), EMAN::Symmetry3D::get_symmetries(), EMAN::Dict::has_key_ci(), and EMAN::Transform::set_rotation().
00241 { 00242 string ret(s); 00243 std::transform(s.begin(),s.end(),ret.begin(), (int (*)(int) ) std::tolower); 00244 return ret; 00245 }
void Util::sub_fav | ( | EMData * | ave, | |
EMData * | dat, | |||
float | tot, | |||
int | mirror, | |||
vector< int > | numr | |||
) | [static] |
Definition at line 4568 of file util_sparx.cpp.
References EXITFUNC, EMAN::EMData::get_data(), numr, PI2, and EMAN::EMData::update().
04568 { 04569 int nring = numr.size()/3; 04570 float *ave = avep->get_data(); 04571 float *dat = datp->get_data(); 04572 int i, j, numr3i, np; 04573 float arg, cs, si; 04574 int maxrin = numr(3,nring); 04575 if(mirror == 1) { //for mirrored data has to be conjugated 04576 for (i=1; i<=nring; i++) { 04577 numr3i = numr(3,i); 04578 np = numr(2,i)-1; 04579 ave[np] -= dat[np]; 04580 ave[np+1] -= static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) ); 04581 for (j=2; j<numr3i; j=j+2) { 04582 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin ); 04583 cs = cos(arg); 04584 si = sin(arg); 04585 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg)) 04586 ave[np + j] -= dat[np + j]*cs - dat[np + j +1]*si; 04587 ave[np + j +1] += dat[np + j]*si + dat[np + j +1]*cs; 04588 } 04589 } 04590 } else { 04591 for (i=1; i<=nring; i++) { 04592 numr3i = numr(3,i); 04593 np = numr(2,i)-1; 04594 ave[np] -= dat[np]; 04595 ave[np+1] -= static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) ); 04596 for (j=2; j<numr3i; j=j+2) { 04597 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin ); 04598 cs = cos(arg); 04599 si = sin(arg); 04600 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg)) 04601 ave[np + j] -= dat[np + j]*cs - dat[np + j +1]*si; 04602 ave[np + j +1] -= dat[np + j]*si + dat[np + j +1]*cs; 04603 } 04604 } 04605 } 04606 avep->update(); 04607 EXITFUNC; 04608 }
Definition at line 17701 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().
17702 { 17703 ENTERFUNC; 17704 /* Exception Handle */ 17705 if (!img) { 17706 throw NullPointerException("NULL input image"); 17707 } 17708 /* ========= img -= img1 ===================== */ 17709 17710 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17711 size_t size = (size_t)nx*ny*nz; 17712 float *img_ptr = img->get_data(); 17713 float *img1_ptr = img1->get_data(); 17714 for (size_t i=0;i<size;++i) img_ptr[i] -= img1_ptr[i]; 17715 img->update(); 17716 17717 EXITFUNC; 17718 }
Definition at line 17483 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().
17484 { 17485 ENTERFUNC; 17486 /* Exception Handle */ 17487 if (!img) { 17488 throw NullPointerException("NULL input image"); 17489 } 17490 /* ============== output = img - img1 ================ */ 17491 17492 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17493 size_t size = (size_t)nx*ny*nz; 17494 EMData * img2 = img->copy_head(); 17495 float *img_ptr =img->get_data(); 17496 float *img2_ptr = img2->get_data(); 17497 float *img1_ptr = img1->get_data(); 17498 for (size_t i=0;i<size;++i) img2_ptr[i] = img_ptr[i] - img1_ptr[i]; 17499 img2->update(); 17500 if(img->is_complex()) { 17501 img2->set_complex(true); 17502 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17503 } 17504 17505 EXITFUNC; 17506 return img2; 17507 }
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 288 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().
00288 { 00289 int nimg=data.size(); 00290 if (nvec==0) nvec=nimg; 00291 vector<EMData *> ret(nvec); 00292 if (nimg==0) return ret; 00293 int pixels=data[0]->get_xsize()*data[0]->get_ysize()*data[0]->get_zsize(); 00294 00295 // Allocate the working space 00296 gsl_vector *work=gsl_vector_alloc(nimg); 00297 gsl_vector *S=gsl_vector_alloc(nimg); 00298 gsl_matrix *A=gsl_matrix_alloc(pixels,nimg); 00299 gsl_matrix *V=gsl_matrix_alloc(nimg,nimg); 00300 gsl_matrix *X=gsl_matrix_alloc(nimg,nimg); 00301 00302 int im,x,y,z,i; 00303 for (im=0; im<nimg; im++) { 00304 for (z=0,i=0; z<data[0]->get_zsize(); z++) { 00305 for (y=0; y<data[0]->get_ysize(); y++) { 00306 for (x=0; x<data[0]->get_xsize(); x++,i++) { 00307 gsl_matrix_set(A,i,im,data[im]->get_value_at(x,y,z)); 00308 } 00309 } 00310 } 00311 } 00312 00313 // This calculates the SVD 00314 gsl_linalg_SV_decomp_mod (A,X, V, S, work); 00315 00316 for (im=0; im<nvec; im++) { 00317 EMData *a=data[0]->copy_head(); 00318 ret[im]=a; 00319 for (z=0,i=0; z<data[0]->get_zsize(); z++) { 00320 for (y=0; y<data[0]->get_ysize(); y++) { 00321 for (x=0; x<data[0]->get_xsize(); x++,i++) { 00322 a->set_value_at(x,y,z,static_cast<float>(gsl_matrix_get(A,i,im))); 00323 } 00324 } 00325 } 00326 } 00327 return ret; 00328 }
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 6190 of file util_sparx.cpp.
References phase(), and sqrt().
Referenced by ctf_img(), and EMAN::Processor::EMFourierFilterFunc().
06191 { 06192 float cst = cs*1.0e7f; 06193 06194 wgh /= 100.0; 06195 float phase = atan(wgh/sqrt(1.0f-wgh*wgh)); 06196 float lambda=12.398f/sqrt(voltage*(1022.0f+voltage)); 06197 float ak2 = ak*ak; 06198 float g1 = dzz*1.0e4f*lambda*ak2; 06199 float g2 = cst*lambda*lambda*lambda*ak2*ak2/2.0f; 06200 06201 float ctfv = static_cast<float>( sin(M_PI*(g1-g2)+phase)*sign ); 06202 if(b_factor != 0.0f) ctfv *= exp(-b_factor*ak2/4.0f); 06203 06204 return ctfv; 06205 }
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 1563 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 7942 of file util_sparx.cpp.
References abs, addnod_(), and left_().
07946 { 07947 /* System generated locals */ 07948 int i__1, i__2; 07949 07950 /* Local variables */ 07951 static double d__; 07952 static int i__, j; 07953 static double d1, d2, d3; 07954 static int i0, lp, kt, ku, lpl, nku; 07955 static int nexti; 07956 07957 07958 /* *********************************************************** */ 07959 07960 /* From STRIPACK */ 07961 /* Robert J. Renka */ 07962 /* Dept. of Computer Science */ 07963 /* Univ. of North Texas */ 07964 /* renka@cs.unt.edu */ 07965 /* 01/20/03 */ 07966 07967 /* This is an alternative to TRMESH with the inclusion of */ 07968 /* an efficient means of removing duplicate or nearly dupli- */ 07969 /* cate nodes. */ 07970 07971 /* This subroutine creates a Delaunay triangulation of a */ 07972 /* set of N arbitrarily distributed points, referred to as */ 07973 /* nodes, on the surface of the unit sphere. Refer to Sub- */ 07974 /* routine TRMESH for definitions and a list of additional */ 07975 /* subroutines. This routine is an alternative to TRMESH */ 07976 /* with the inclusion of an efficient means of removing dup- */ 07977 /* licate or nearly duplicate nodes. */ 07978 07979 /* The algorithm has expected time complexity O(N*log(N)) */ 07980 /* for random nodal distributions. */ 07981 07982 07983 /* On input: */ 07984 07985 /* N0 = Number of nodes, possibly including duplicates. */ 07986 /* N0 .GE. 3. */ 07987 07988 /* TOL = Tolerance defining a pair of duplicate nodes: */ 07989 /* bound on the deviation from 1 of the cosine of */ 07990 /* the angle between the nodes. Note that */ 07991 /* |1-cos(A)| is approximately A*A/2. */ 07992 07993 /* The above parameters are not altered by this routine. */ 07994 07995 /* X,Y,Z = Arrays of length at least N0 containing the */ 07996 /* Cartesian coordinates of nodes. (X(K),Y(K), */ 07997 /* Z(K)) is referred to as node K, and K is re- */ 07998 /* ferred to as a nodal index. It is required */ 07999 /* that X(K)**2 + Y(K)**2 + Z(K)**2 = 1 for all */ 08000 /* K. The first three nodes must not be col- */ 08001 /* linear (lie on a common great circle). */ 08002 08003 /* LIST,LPTR = Arrays of length at least 6*N0-12. */ 08004 08005 /* LEND = Array of length at least N0. */ 08006 08007 /* INDX = Array of length at least N0. */ 08008 08009 /* LCNT = Array of length at least N0 (length N is */ 08010 /* sufficient). */ 08011 08012 /* NEAR,NEXT,DIST = Work space arrays of length at */ 08013 /* least N0. The space is used to */ 08014 /* efficiently determine the nearest */ 08015 /* triangulation node to each un- */ 08016 /* processed node for use by ADDNOD. */ 08017 08018 /* On output: */ 08019 08020 /* N = Number of nodes in the triangulation. 3 .LE. N */ 08021 /* .LE. N0, or N = 0 if IER < 0. */ 08022 08023 /* X,Y,Z = Arrays containing the Cartesian coordinates */ 08024 /* of the triangulation nodes in the first N */ 08025 /* locations. The original array elements are */ 08026 /* shifted down as necessary to eliminate dup- */ 08027 /* licate nodes. */ 08028 08029 /* LIST = Set of nodal indexes which, along with LPTR, */ 08030 /* LEND, and LNEW, define the triangulation as a */ 08031 /* set of N adjacency lists -- counterclockwise- */ 08032 /* ordered sequences of neighboring nodes such */ 08033 /* that the first and last neighbors of a bound- */ 08034 /* ary node are boundary nodes (the first neigh- */ 08035 /* bor of an interior node is arbitrary). In */ 08036 /* order to distinguish between interior and */ 08037 /* boundary nodes, the last neighbor of each */ 08038 /* boundary node is represented by the negative */ 08039 /* of its index. */ 08040 08041 /* LPTR = Set of pointers (LIST indexes) in one-to-one */ 08042 /* correspondence with the elements of LIST. */ 08043 /* LIST(LPTR(I)) indexes the node which follows */ 08044 /* LIST(I) in cyclical counterclockwise order */ 08045 /* (the first neighbor follows the last neigh- */ 08046 /* bor). */ 08047 08048 /* LEND = Set of pointers to adjacency lists. LEND(K) */ 08049 /* points to the last neighbor of node K for */ 08050 /* K = 1,...,N. Thus, LIST(LEND(K)) < 0 if and */ 08051 /* only if K is a boundary node. */ 08052 08053 /* LNEW = Pointer to the first empty location in LIST */ 08054 /* and LPTR (list length plus one). LIST, LPTR, */ 08055 /* LEND, and LNEW are not altered if IER < 0, */ 08056 /* and are incomplete if IER > 0. */ 08057 08058 /* INDX = Array of output (triangulation) nodal indexes */ 08059 /* associated with input nodes. For I = 1 to */ 08060 /* N0, INDX(I) is the index (for X, Y, and Z) of */ 08061 /* the triangulation node with the same (or */ 08062 /* nearly the same) coordinates as input node I. */ 08063 08064 /* LCNT = Array of int weights (counts) associated */ 08065 /* with the triangulation nodes. For I = 1 to */ 08066 /* N, LCNT(I) is the number of occurrences of */ 08067 /* node I in the input node set, and thus the */ 08068 /* number of duplicates is LCNT(I)-1. */ 08069 08070 /* NEAR,NEXT,DIST = Garbage. */ 08071 08072 /* IER = Error indicator: */ 08073 /* IER = 0 if no errors were encountered. */ 08074 /* IER = -1 if N0 < 3 on input. */ 08075 /* IER = -2 if the first three nodes are */ 08076 /* collinear. */ 08077 /* IER = -3 if Subroutine ADDNOD returns an error */ 08078 /* flag. This should not occur. */ 08079 08080 /* Modules required by TRMSH3: ADDNOD, BDYADD, COVSPH, */ 08081 /* INSERT, INTADD, JRAND, */ 08082 /* LEFT, LSTPTR, STORE, SWAP, */ 08083 /* SWPTST, TRFIND */ 08084 08085 /* Intrinsic function called by TRMSH3: ABS */ 08086 08087 /* *********************************************************** */ 08088 08089 08090 /* Local parameters: */ 08091 08092 /* D = (Negative cosine of) distance from node KT to */ 08093 /* node I */ 08094 /* D1,D2,D3 = Distances from node KU to nodes 1, 2, and 3, */ 08095 /* respectively */ 08096 /* I,J = Nodal indexes */ 08097 /* I0 = Index of the node preceding I in a sequence of */ 08098 /* unprocessed nodes: I = NEXT(I0) */ 08099 /* KT = Index of a triangulation node */ 08100 /* KU = Index of an unprocessed node and DO-loop index */ 08101 /* LP = LIST index (pointer) of a neighbor of KT */ 08102 /* LPL = Pointer to the last neighbor of KT */ 08103 /* NEXTI = NEXT(I) */ 08104 /* NKU = NEAR(KU) */ 08105 08106 /* Parameter adjustments */ 08107 --dist; 08108 --next; 08109 --near__; 08110 --indx; 08111 --lend; 08112 --z__; 08113 --y; 08114 --x; 08115 --list; 08116 --lptr; 08117 --lcnt; 08118 08119 /* Function Body */ 08120 if (*n0 < 3) { 08121 *n = 0; 08122 *ier = -1; 08123 return 0; 08124 } 08125 08126 /* Store the first triangle in the linked list. */ 08127 08128 if (! left_(&x[1], &y[1], &z__[1], &x[2], &y[2], &z__[2], &x[3], &y[3], & 08129 z__[3])) { 08130 08131 /* The first triangle is (3,2,1) = (2,1,3) = (1,3,2). */ 08132 08133 list[1] = 3; 08134 lptr[1] = 2; 08135 list[2] = -2; 08136 lptr[2] = 1; 08137 lend[1] = 2; 08138 08139 list[3] = 1; 08140 lptr[3] = 4; 08141 list[4] = -3; 08142 lptr[4] = 3; 08143 lend[2] = 4; 08144 08145 list[5] = 2; 08146 lptr[5] = 6; 08147 list[6] = -1; 08148 lptr[6] = 5; 08149 lend[3] = 6; 08150 08151 } else if (! left_(&x[2], &y[2], &z__[2], &x[1], &y[1], &z__[1], &x[3], & 08152 y[3], &z__[3])) { 08153 08154 /* The first triangle is (1,2,3): 3 Strictly Left 1->2, */ 08155 /* i.e., node 3 lies in the left hemisphere defined by */ 08156 /* arc 1->2. */ 08157 08158 list[1] = 2; 08159 lptr[1] = 2; 08160 list[2] = -3; 08161 lptr[2] = 1; 08162 lend[1] = 2; 08163 08164 list[3] = 3; 08165 lptr[3] = 4; 08166 list[4] = -1; 08167 lptr[4] = 3; 08168 lend[2] = 4; 08169 08170 list[5] = 1; 08171 lptr[5] = 6; 08172 list[6] = -2; 08173 lptr[6] = 5; 08174 lend[3] = 6; 08175 08176 08177 } else { 08178 08179 /* The first three nodes are collinear. */ 08180 08181 *n = 0; 08182 *ier = -2; 08183 return 0; 08184 } 08185 08186 //printf("pass check colinear\n"); 08187 08188 /* Initialize LNEW, INDX, and LCNT, and test for N = 3. */ 08189 08190 *lnew = 7; 08191 indx[1] = 1; 08192 indx[2] = 2; 08193 indx[3] = 3; 08194 lcnt[1] = 1; 08195 lcnt[2] = 1; 08196 lcnt[3] = 1; 08197 if (*n0 == 3) { 08198 *n = 3; 08199 *ier = 0; 08200 return 0; 08201 } 08202 08203 /* A nearest-node data structure (NEAR, NEXT, and DIST) is */ 08204 /* used to obtain an expected-time (N*log(N)) incremental */ 08205 /* algorithm by enabling constant search time for locating */ 08206 /* each new node in the triangulation. */ 08207 08208 /* For each unprocessed node KU, NEAR(KU) is the index of the */ 08209 /* triangulation node closest to KU (used as the starting */ 08210 /* point for the search in Subroutine TRFIND) and DIST(KU) */ 08211 /* is an increasing function of the arc length (angular */ 08212 /* distance) between nodes KU and NEAR(KU): -Cos(a) for */ 08213 /* arc length a. */ 08214 08215 /* Since it is necessary to efficiently find the subset of */ 08216 /* unprocessed nodes associated with each triangulation */ 08217 /* node J (those that have J as their NEAR entries), the */ 08218 /* subsets are stored in NEAR and NEXT as follows: for */ 08219 /* each node J in the triangulation, I = NEAR(J) is the */ 08220 /* first unprocessed node in J's set (with I = 0 if the */ 08221 /* set is empty), L = NEXT(I) (if I > 0) is the second, */ 08222 /* NEXT(L) (if L > 0) is the third, etc. The nodes in each */ 08223 /* set are initially ordered by increasing indexes (which */ 08224 /* maximizes efficiency) but that ordering is not main- */ 08225 /* tained as the data structure is updated. */ 08226 08227 /* Initialize the data structure for the single triangle. */ 08228 08229 near__[1] = 0; 08230 near__[2] = 0; 08231 near__[3] = 0; 08232 for (ku = *n0; ku >= 4; --ku) { 08233 d1 = -(x[ku] * x[1] + y[ku] * y[1] + z__[ku] * z__[1]); 08234 d2 = -(x[ku] * x[2] + y[ku] * y[2] + z__[ku] * z__[2]); 08235 d3 = -(x[ku] * x[3] + y[ku] * y[3] + z__[ku] * z__[3]); 08236 if (d1 <= d2 && d1 <= d3) { 08237 near__[ku] = 1; 08238 dist[ku] = d1; 08239 next[ku] = near__[1]; 08240 near__[1] = ku; 08241 } else if (d2 <= d1 && d2 <= d3) { 08242 near__[ku] = 2; 08243 dist[ku] = d2; 08244 next[ku] = near__[2]; 08245 near__[2] = ku; 08246 } else { 08247 near__[ku] = 3; 08248 dist[ku] = d3; 08249 next[ku] = near__[3]; 08250 near__[3] = ku; 08251 } 08252 /* L1: */ 08253 } 08254 08255 /* Loop on unprocessed nodes KU. KT is the number of nodes */ 08256 /* in the triangulation, and NKU = NEAR(KU). */ 08257 08258 kt = 3; 08259 i__1 = *n0; 08260 for (ku = 4; ku <= i__1; ++ku) { 08261 nku = near__[ku]; 08262 08263 /* Remove KU from the set of unprocessed nodes associated */ 08264 /* with NEAR(KU). */ 08265 i__ = nku; 08266 if (near__[i__] == ku) { 08267 near__[i__] = next[ku]; 08268 } else { 08269 i__ = near__[i__]; 08270 L2: 08271 i0 = i__; 08272 i__ = next[i0]; 08273 if (i__ != ku) { 08274 goto L2; 08275 } 08276 next[i0] = next[ku]; 08277 } 08278 near__[ku] = 0; 08279 08280 /* Bypass duplicate nodes. */ 08281 08282 if (dist[ku] <= *tol - 1.) { 08283 indx[ku] = -nku; 08284 ++lcnt[nku]; 08285 goto L6; 08286 } 08287 08288 08289 /* Add a new triangulation node KT with LCNT(KT) = 1. */ 08290 ++kt; 08291 x[kt] = x[ku]; 08292 y[kt] = y[ku]; 08293 z__[kt] = z__[ku]; 08294 indx[ku] = kt; 08295 lcnt[kt] = 1; 08296 addnod_(&nku, &kt, &x[1], &y[1], &z__[1], &list[1], &lptr[1], &lend[1] 08297 , lnew, ier); 08298 if (*ier != 0) { 08299 *n = 0; 08300 *ier = -3; 08301 return 0; 08302 } 08303 08304 /* Loop on neighbors J of node KT. */ 08305 08306 lpl = lend[kt]; 08307 lp = lpl; 08308 L3: 08309 lp = lptr[lp]; 08310 j = (i__2 = list[lp], abs(i__2)); 08311 08312 /* Loop on elements I in the sequence of unprocessed nodes */ 08313 /* associated with J: KT is a candidate for replacing J */ 08314 /* as the nearest triangulation node to I. The next value */ 08315 /* of I in the sequence, NEXT(I), must be saved before I */ 08316 /* is moved because it is altered by adding I to KT's set. */ 08317 08318 i__ = near__[j]; 08319 L4: 08320 if (i__ == 0) { 08321 goto L5; 08322 } 08323 nexti = next[i__]; 08324 08325 /* Test for the distance from I to KT less than the distance */ 08326 /* from I to J. */ 08327 08328 d__ = -(x[i__] * x[kt] + y[i__] * y[kt] + z__[i__] * z__[kt]); 08329 if (d__ < dist[i__]) { 08330 08331 /* Replace J by KT as the nearest triangulation node to I: */ 08332 /* update NEAR(I) and DIST(I), and remove I from J's set */ 08333 /* of unprocessed nodes and add it to KT's set. */ 08334 08335 near__[i__] = kt; 08336 dist[i__] = d__; 08337 if (i__ == near__[j]) { 08338 near__[j] = nexti; 08339 } else { 08340 next[i0] = nexti; 08341 } 08342 next[i__] = near__[kt]; 08343 near__[kt] = i__; 08344 } else { 08345 i0 = i__; 08346 } 08347 08348 /* Bottom of loop on I. */ 08349 08350 i__ = nexti; 08351 goto L4; 08352 08353 /* Bottom of loop on neighbors J. */ 08354 08355 L5: 08356 if (lp != lpl) { 08357 goto L3; 08358 } 08359 L6: 08360 ; 08361 } 08362 *n = kt; 08363 *ier = 0; 08364 return 0; 08365 } /* trmsh3_ */
vector< float > Util::twoD_fine_ali | ( | EMData * | image, | |
EMData * | refim, | |||
EMData * | mask, | |||
float | ang, | |||
float | sxs, | |||
float | sys | |||
) | [static] |
Definition at line 19584 of file util_sparx.cpp.
References EMAN::EMData::cmp(), dt, EMAN::EMData::rot_scale_trans2D(), setulb_(), and SIXTY.
19584 { 19585 19586 EMData *rot; 19587 19588 const int nmax=3, mmax=3; 19589 char task[60], csave[60]; 19590 long int lsave[4]; 19591 long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44]; 19592 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]; 19593 long int SIXTY=60; 19594 19595 // We wish to have no output. 19596 iprint = -1; 19597 19598 //c We specify the tolerances in the stopping criteria. 19599 factr=1.0e1; 19600 pgtol=1.0e-5; 19601 19602 // We specify the dimension n of the sample problem and the number 19603 // m of limited memory corrections stored. (n and m should not 19604 // exceed the limits nmax and mmax respectively.) 19605 n=3; 19606 m=3; 19607 19608 // We now provide nbd which defines the bounds on the variables: 19609 // l specifies the lower bounds, 19610 // u specifies the upper bounds. 19611 // x specifies the initial guess 19612 x[0] = ang; nbd[0] = 2; l[0] = ang-2.0; u[0] = ang+2.0; 19613 x[1] = sxs; nbd[1] = 2; l[1] = sxs-1.5; u[1] = sxs+1.5; 19614 x[2] = sys; nbd[2] = 2; l[2] = sys-1.5; u[2] = sys+1.5; 19615 19616 19617 // We start the iteration by initializing task. 19618 // (**MUST clear remaining chars in task with spaces (else crash)!**) 19619 strcpy(task,"START"); 19620 for (int i=5;i<60;i++) task[i]=' '; 19621 19622 // This is the call to the L-BFGS-B code. 19623 // (* call the L-BFGS-B routine with task='START' once before loop *) 19624 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19625 //int step = 1; 19626 19627 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *) 19628 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) { 19629 19630 if (strncmp(task,"FG",2)==0) { 19631 // the minimization routine has returned to request the 19632 // function f and gradient g values at the current x 19633 19634 // Compute function value f for the sample problem. 19635 rot = new EMData(); 19636 rot = image->rot_scale_trans2D((float)x[0], (float)x[1], (float)x[2], 1.0f); 19637 f = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19638 //f = -f; 19639 delete rot; 19640 19641 // Compute gradient g for the sample problem. 19642 float dt = 1.0e-3f; 19643 rot = new EMData(); 19644 rot = image->rot_scale_trans2D((float)x[0]+dt, (float)x[1], (float)x[2], 1.0f); 19645 f1 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19646 //f1 = -f1; 19647 g[0] = (f1-f)/dt; 19648 delete rot; 19649 19650 dt = 1.0e-2f; 19651 rot = new EMData(); 19652 rot = image->rot_scale_trans2D((float)x[0], (float)x[1]+dt, (float)x[2], 1.0f); 19653 f2 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19654 //f2 = -f2; 19655 g[1] = (f2-f)/dt; 19656 delete rot; 19657 19658 rot = new EMData(); 19659 rot = image->rot_scale_trans2D((float)x[0], (float)x[1], (float)x[2]+dt, 1.0f); 19660 f3 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19661 //f3 = -f3; 19662 g[2] = (f3-f)/dt; 19663 delete rot; 19664 } 19665 19666 //c go back to the minimization routine. 19667 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19668 //step++; 19669 } 19670 19671 //printf("Total step is %d\n", step); 19672 vector<float> res; 19673 res.push_back(static_cast<float>(x[0])); 19674 res.push_back(static_cast<float>(x[1])); 19675 res.push_back(static_cast<float>(x[2])); 19676 //res.push_back(step); 19677 return res; 19678 }
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 19680 of file util_sparx.cpp.
References EMAN::EMData::cmp(), dt, pi, EMAN::EMData::rot_scale_conv7(), setulb_(), and SIXTY.
19680 { 19681 19682 EMData *rot; 19683 19684 const int nmax=3, mmax=3; 19685 char task[60], csave[60]; 19686 long int lsave[4]; 19687 long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44]; 19688 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]; 19689 long int SIXTY=60; 19690 19691 // We wish to have no output. 19692 iprint = -1; 19693 19694 //c We specify the tolerances in the stopping criteria. 19695 factr=1.0e1; 19696 pgtol=1.0e-5; 19697 19698 // We specify the dimension n of the sample problem and the number 19699 // m of limited memory corrections stored. (n and m should not 19700 // exceed the limits nmax and mmax respectively.) 19701 n=3; 19702 m=3; 19703 19704 // We now provide nbd which defines the bounds on the variables: 19705 // l specifies the lower bounds, 19706 // u specifies the upper bounds. 19707 // x specifies the initial guess 19708 x[0] = ang; nbd[0] = 2; l[0] = ang-2.0; u[0] = ang+2.0; 19709 x[1] = sxs; nbd[1] = 2; l[1] = sxs-1.5; u[1] = sxs+1.5; 19710 x[2] = sys; nbd[2] = 2; l[2] = sys-1.5; u[2] = sys+1.5; 19711 19712 19713 // We start the iteration by initializing task. 19714 // (**MUST clear remaining chars in task with spaces (else crash)!**) 19715 strcpy(task,"START"); 19716 for (int i=5;i<60;i++) task[i]=' '; 19717 19718 // This is the call to the L-BFGS-B code. 19719 // (* call the L-BFGS-B routine with task='START' once before loop *) 19720 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19721 //int step = 1; 19722 19723 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *) 19724 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) { 19725 19726 if (strncmp(task,"FG",2)==0) { 19727 // the minimization routine has returned to request the 19728 // function f and gradient g values at the current x 19729 19730 // Compute function value f for the sample problem. 19731 rot = new EMData(); 19732 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1], (float)x[2], kb, 1.0f); 19733 f = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19734 //f = -f; 19735 delete rot; 19736 19737 // Compute gradient g for the sample problem. 19738 float dt = 1.0e-3f; 19739 rot = new EMData(); 19740 rot = image->rot_scale_conv7((float)((x[0]+dt)*pi/180), (float)x[1], (float)x[2], kb, 1.0f); 19741 f1 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19742 //f1 = -f1; 19743 g[0] = (f1-f)/dt; 19744 delete rot; 19745 19746 rot = new EMData(); 19747 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1]+dt, (float)x[2], kb, 1.0); 19748 f2 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19749 //f2 = -f2; 19750 g[1] = (f2-f)/dt; 19751 delete rot; 19752 19753 rot = new EMData(); 19754 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1], (float)x[2]+dt, kb, 1.0f); 19755 f3 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19756 //f3 = -f3; 19757 g[2] = (f3-f)/dt; 19758 delete rot; 19759 } 19760 19761 //c go back to the minimization routine. 19762 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19763 //step++; 19764 } 19765 19766 //printf("Total step is %d\n", step); 19767 vector<float> res; 19768 res.push_back(static_cast<float>(x[0])); 19769 res.push_back(static_cast<float>(x[1])); 19770 res.push_back(static_cast<float>(x[2])); 19771 //res.push_back(step); 19772 return res; 19773 }
vector< float > Util::twoD_fine_ali_SD | ( | EMData * | image, | |
EMData * | refim, | |||
EMData * | mask, | |||
float | ang, | |||
float | sxs, | |||
float | sys | |||
) | [static] |
Definition at line 19932 of file util_sparx.cpp.
References ccc_images(), and Steepda().
19932 { 19933 19934 double x[4]; 19935 int n; 19936 int l = 3; 19937 int m = 200; 19938 double e = 1e-9; 19939 double step = 0.01; 19940 float (*my_func)(EMData* , EMData* , EMData* , float , float , float) = ccc_images; 19941 19942 x[1] = ang; 19943 x[2] = sxs; 19944 x[3] = sys; 19945 19946 Steepda(x, step, e, l, m, &n, my_func, image, refim, mask); // Call steepest descent optimization subroutine 19947 //printf("Took %d steps\n", n); 19948 19949 vector<float> res; 19950 res.push_back(static_cast<float>(x[1])); 19951 res.push_back(static_cast<float>(x[2])); 19952 res.push_back(static_cast<float>(x[3])); 19953 res.push_back(static_cast<float>(n)); 19954 return res; 19955 }
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 20183 of file util_sparx.cpp.
References ccc_images_G(), and Steepda_G().
20183 { 20184 20185 double x[4]; 20186 int n; 20187 int l = 3; 20188 int m = 200; 20189 double e = 1e-9; 20190 double step = 0.001; 20191 float (*my_func)(EMData* , EMData* , EMData* , Util::KaiserBessel&, float , float , float) = ccc_images_G; 20192 20193 x[1] = ang; 20194 x[2] = sxs; 20195 x[3] = sys; 20196 20197 Steepda_G(x, step, e, l, m, &n, my_func, image, refim, mask, kb); // Call steepest descent optimization subroutine 20198 //printf("Took %d steps\n", n); 20199 20200 vector<float> res; 20201 res.push_back(static_cast<float>(x[1])); 20202 res.push_back(static_cast<float>(x[2])); 20203 res.push_back(static_cast<float>(x[3])); 20204 res.push_back(static_cast<float>(n)); 20205 return res; 20206 }
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 19775 of file util_sparx.cpp.
References EMAN::EMData::cmp(), dt, EMAN::EMData::extract_plane(), proj, setulb_(), and SIXTY.
19775 { 19776 19777 EMData *proj, *proj2; 19778 19779 const int nmax=5, mmax=5; 19780 char task[60], csave[60]; 19781 long int lsave[4]; 19782 long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44]; 19783 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]; 19784 long int SIXTY=60; 19785 19786 // We wish to have no output. 19787 iprint = -1; 19788 19789 //c We specify the tolerances in the stopping criteria. 19790 factr=1.0e1; 19791 pgtol=1.0e-5; 19792 19793 // We specify the dimension n of the sample problem and the number 19794 // m of limited memory corrections stored. (n and m should not 19795 // exceed the limits nmax and mmax respectively.) 19796 n=5; 19797 m=5; 19798 19799 // We now provide nbd which defines the bounds on the variables: 19800 // l specifies the lower bounds, 19801 // u specifies the upper bounds. 19802 // x specifies the initial guess 19803 x[0] = phi; nbd[0] = 2; l[0] = phi-2.0; u[0] = phi+2.0; 19804 x[1] = theta; nbd[1] = 2; l[1] = theta-2.0; u[1] = theta+2.0; 19805 x[2] = psi; nbd[2] = 2; l[2] = psi-2.0; u[2] = psi+2.0; 19806 x[3] = sxs; nbd[3] = 2; l[3] = sxs-2.0; u[3] = sxs+2.0; 19807 x[4] = sys; nbd[4] = 2; l[4] = sys-2.0; u[4] = sys+2.0; 19808 19809 19810 // We start the iteration by initializing task. 19811 // (**MUST clear remaining chars in task with spaces (else crash)!**) 19812 strcpy(task,"START"); 19813 for (int i=5;i<60;i++) task[i]=' '; 19814 19815 // This is the call to the L-BFGS-B code. 19816 // (* call the L-BFGS-B routine with task='START' once before loop *) 19817 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19818 int step = 1; 19819 19820 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *) 19821 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) { 19822 19823 if (strncmp(task,"FG",2)==0) { 19824 // the minimization routine has returned to request the 19825 // function f and gradient g values at the current x 19826 19827 // Compute function value f for the sample problem. 19828 proj = new EMData(); 19829 proj2 = new EMData(); 19830 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb); 19831 proj->fft_shuffle(); 19832 proj->center_origin_fft(); 19833 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f)); 19834 proj->do_ift_inplace(); 19835 int M = proj->get_ysize()/2; 19836 proj2 = proj->window_center(M); 19837 f = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 19838 //f = -f; 19839 delete proj; 19840 delete proj2; 19841 19842 // Compute gradient g for the sample problem. 19843 float dt = 1.0e-3f; 19844 proj = new EMData(); 19845 proj2 = new EMData(); 19846 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0]+dt, "theta", (float)x[1], "psi", (float)x[2])), kb); 19847 proj->fft_shuffle(); 19848 proj->center_origin_fft(); 19849 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f)); 19850 proj->do_ift_inplace(); 19851 proj2 = proj->window_center(M); 19852 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 19853 //ft = -ft; 19854 delete proj; 19855 delete proj2; 19856 g[0] = (ft-f)/dt; 19857 19858 proj = new EMData(); 19859 proj2 = new EMData(); 19860 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1]+dt, "psi", (float)x[2])), kb); 19861 proj->fft_shuffle(); 19862 proj->center_origin_fft(); 19863 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f)); 19864 proj->do_ift_inplace(); 19865 proj2 = proj->window_center(M); 19866 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 19867 //ft = -ft; 19868 delete proj; 19869 delete proj2; 19870 g[1] = (ft-f)/dt; 19871 19872 proj = new EMData(); 19873 proj2 = new EMData(); 19874 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2]+dt)), kb); 19875 proj->fft_shuffle(); 19876 proj->center_origin_fft(); 19877 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f)); 19878 proj->do_ift_inplace(); 19879 proj2 = proj->window_center(M); 19880 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 19881 //ft = -ft; 19882 delete proj; 19883 delete proj2; 19884 g[2] = (ft-f)/dt; 19885 19886 proj = new EMData(); 19887 proj2 = new EMData(); 19888 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb); 19889 proj->fft_shuffle(); 19890 proj->center_origin_fft(); 19891 proj->process_inplace("filter.shift", Dict("x_shift", x[3]+dt, "y_shift", x[4], "z_shift", 0.0f)); 19892 proj->do_ift_inplace(); 19893 proj2 = proj->window_center(M); 19894 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 19895 //ft = -ft; 19896 delete proj; 19897 delete proj2; 19898 g[3] = (ft-f)/dt; 19899 19900 proj = new EMData(); 19901 proj2 = new EMData(); 19902 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb); 19903 proj->fft_shuffle(); 19904 proj->center_origin_fft(); 19905 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4]+dt, "z_shift", 0.0f)); 19906 proj->do_ift_inplace(); 19907 proj2 = proj->window_center(M); 19908 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 19909 //ft = -ft; 19910 delete proj; 19911 delete proj2; 19912 g[4] = (ft-f)/dt; 19913 } 19914 19915 //c go back to the minimization routine. 19916 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19917 step++; 19918 } 19919 19920 //printf("Total step is %d\n", step); 19921 vector<float> res; 19922 res.push_back(static_cast<float>(x[0])); 19923 res.push_back(static_cast<float>(x[1])); 19924 res.push_back(static_cast<float>(x[2])); 19925 res.push_back(static_cast<float>(x[3])); 19926 res.push_back(static_cast<float>(x[4])); 19927 //res.push_back(step); 19928 return res; 19929 }
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 4526 of file util_sparx.cpp.
References EXITFUNC, EMAN::EMData::get_data(), numr, PI2, and EMAN::EMData::update().
04526 { 04527 int nring = numr.size()/3; 04528 float *ave = avep->get_data(); 04529 float *dat = datp->get_data(); 04530 int i, j, numr3i, np; 04531 float arg, cs, si; 04532 int maxrin = numr(3,nring); 04533 if(mirror == 1) { //for mirrored data has to be conjugated 04534 for (i=1; i<=nring; i++) { 04535 numr3i = numr(3,i); 04536 np = numr(2,i)-1; 04537 ave[np] += dat[np]; 04538 ave[np+1] += static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) ); 04539 for (j=2; j<numr3i; j=j+2) { 04540 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin ); 04541 cs = cos(arg); 04542 si = sin(arg); 04543 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg)) 04544 ave[np + j] += dat[np + j]*cs - dat[np + j +1]*si; 04545 ave[np + j +1] -= dat[np + j]*si + dat[np + j +1]*cs; 04546 } 04547 } 04548 } else { 04549 for (i=1; i<=nring; i++) { 04550 numr3i = numr(3,i); 04551 np = numr(2,i)-1; 04552 ave[np] += dat[np]; 04553 ave[np+1] += static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) ); 04554 for (j=2; j<numr3i; j=j+2) { 04555 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin ); 04556 cs = cos(arg); 04557 si = sin(arg); 04558 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg)) 04559 ave[np + j] += dat[np + j]*cs - dat[np + j +1]*si; 04560 ave[np + j +1] += dat[np + j]*si + dat[np + j +1]*cs; 04561 } 04562 } 04563 } 04564 avep->update(); 04565 EXITFUNC; 04566 }
static double EMAN::Util::var | ( | double * | x, | |
int | n | |||
) | [inline, static] |
vector< float > Util::vareas | ( | EMData * | d | ) | [static] |
Definition at line 20914 of file util_sparx.cpp.
References data, dm, EMAN::EMData::get_ysize(), and ny.
20914 { 20915 const float step=0.001f; 20916 int ny = d->get_ysize(); 20917 // input emdata should have size 2xN, where N is number of points 20918 // output vector should be 2xN, first element is the number of elements 20919 // associated with this point, second is 0 is the element is touching the border, 1 if it is interior 20920 vector<float> group(2*ny); 20921 for(int i=0; i<2*ny; i++) group[i] = 0.0f; 20922 int K = int(1.0f/step) +1; 20923 int hit = 0; 20924 for(int kx=0; kx<=K; kx++) { 20925 float tx = kx*step; 20926 for(int ky=0; ky<=K; ky++) { 20927 float ty = ky*step; 20928 float dm = 1.0e23f; 20929 for(int i=0; i<ny; i++) { 20930 float qd = pow(tx-(*d)(0,i),2) + pow(ty-(*d)(1,i),2); 20931 if( qd < dm) { 20932 dm = qd; 20933 hit = i; 20934 } 20935 } 20936 data(0,hit) += 1.0f; 20937 if(kx == 0 || ky == 0 || kx == K || ky == K) data(1,hit) = 1.0f; 20938 } 20939 } 20940 return group; 20941 }
void Util::voronoi | ( | double * | phi, | |
double * | theta, | |||
double * | weight, | |||
int | nt | |||
) | [static] |
Definition at line 7652 of file util_sparx.cpp.
References ang_to_xyz(), areav_(), Assert, disorder2(), ENTERFUNC, EXITFUNC, flip23(), key, status, trmsh3_(), and y.
07653 { 07654 07655 ENTERFUNC; 07656 07657 int *list, *lptr, *lend, *iwk, *key,*lcnt,*indx,*good; 07658 int nt6, n, ier, nout, lnew, mdup, nd; 07659 int i,k,mt,status; 07660 07661 07662 double *ds, *x, *y, *z; 07663 double tol = 1.0e-8; 07664 double dtol = 15; 07665 double a; 07666 07667 /*if(last){ 07668 if(medium>nt) n = nt+nt; 07669 else n = nt+nt-medium+1; 07670 } 07671 else{ 07672 n=nt; 07673 }*/ 07674 07675 n = nt + nt; 07676 07677 nt6 = n*6; 07678 07679 list = (int*)calloc(nt6,sizeof(int)); 07680 lptr = (int*)calloc(nt6,sizeof(int)); 07681 lend = (int*)calloc(n ,sizeof(int)); 07682 iwk = (int*)calloc(n ,sizeof(int)); 07683 good = (int*)calloc(n ,sizeof(int)); 07684 key = (int*)calloc(n ,sizeof(int)); 07685 indx = (int*)calloc(n ,sizeof(int)); 07686 lcnt = (int*)calloc(n ,sizeof(int)); 07687 07688 ds = (double*) calloc(n,sizeof(double)); 07689 x = (double*) calloc(n,sizeof(double)); 07690 y = (double*) calloc(n,sizeof(double)); 07691 z = (double*) calloc(n,sizeof(double)); 07692 07693 if (list == NULL || 07694 lptr == NULL || 07695 lend == NULL || 07696 iwk == NULL || 07697 good == NULL || 07698 key == NULL || 07699 indx == NULL || 07700 lcnt == NULL || 07701 x == NULL || 07702 y == NULL || 07703 z == NULL || 07704 ds == NULL) { 07705 printf("memory allocation failure!\n"); 07706 exit(1); 07707 } 07708 07709 bool colinear=true; 07710 while(colinear) 07711 { 07712 07713 L1: 07714 for(i = 0; i<nt; i++){ 07715 x[i] = theta[i]; 07716 y[i] = phi[i]; 07717 x[nt+i] = 180.0 - x[i]; 07718 y[nt+i] = 180.0 + y[i]; 07719 } 07720 07721 Util::disorder2(x, y, key, n); 07722 07723 // check if the first three angles are not close, else shuffle 07724 double val; 07725 for(k=0; k<2; k++){ 07726 for(i=k+1; i<3; i++){ 07727 val = (x[i]-x[k])*(x[i]-x[k]) + (y[i]-y[k])*(y[i]-y[k]); 07728 if( val < dtol) { 07729 goto L1; 07730 } 07731 } 07732 } 07733 07734 Util::ang_to_xyz(x, y, z, n); 07735 07736 // Make sure that first three has no duplication 07737 bool dupnode=true; 07738 dupnode=true; 07739 while(dupnode) 07740 { 07741 for(k=0; k<2; k++){ 07742 for(i=k+1; i<3; i++){ 07743 if( x[i]*x[k]+y[i]*y[k]+z[i]*z[k] > 1.0-tol) { 07744 Util::flip23(x, y, z, key, k, n); 07745 continue; 07746 } 07747 } 07748 } 07749 dupnode = false; 07750 } 07751 07752 07753 ier = 0; 07754 07755 status = Util::trmsh3_(&n,&tol,x,y,z,&nout,list,lptr,lend,&lnew, indx, lcnt, iwk, good, ds, &ier); 07756 07757 if (status != 0) { 07758 printf(" error in trmsh3 \n"); 07759 exit(1); 07760 } 07761 07762 if (ier > 0) { 07763 printf("*** Error in TRMESH: duplicate nodes encountered ***\n"); 07764 exit(1); 07765 } 07766 07767 mdup=n-nout; 07768 if (ier == -2) { 07769 //printf("in TRMESH:the first three nodes are colinear*** disorder again\n"); 07770 } 07771 else 07772 { 07773 colinear=false; 07774 } 07775 } 07776 07777 07778 Assert( ier != -2 ); 07779 // Create a list of unique nodes GOOD, the numbers refer to locations on the full list 07780 // INDX contains node numbers from the squeezed list 07781 nd=0; 07782 for (k=1; k<=n; k++){ 07783 if (indx[k-1]>0) { 07784 nd++; 07785 good[nd-1]=k; 07786 } 07787 } 07788 07789 // 07790 // *** Compute the Voronoi region areas. 07791 // 07792 for(i = 1; i<=nout; i++) { 07793 k=good[i-1]; 07794 // We only need n weights from hemisphere 07795 if (key[k-1] <= nt) { 07796 // CALCULATE THE AREA 07797 a = Util::areav_(&i, &nout, x, y, z, list, lptr, lend, &ier); 07798 if (ier != 0){ 07799 // We set the weight to -1, this will signal the error in the calling 07800 // program, as the area will turn out incorrect 07801 printf(" *** error in areav: ier = %d ***\n", ier); 07802 weight[key[k-1]-1] =-1.0; 07803 } else { 07804 // Assign the weight 07805 weight[key[k-1]-1]=a/lcnt[i-1]; 07806 } 07807 } 07808 } 07809 07810 07811 // Fill out the duplicated weights 07812 for(i = 1; i<=n; i++){ 07813 mt =- indx[i-1]; 07814 if (mt>0){ 07815 k = good[mt-1]; 07816 // This is a duplicated entry, get the already calculated 07817 // weight and assign it. 07818 // We only need n weights from hemisphere 07819 if (key[i-1] <= nt && key[k-1] <= nt) { weight[key[i-1]-1] = weight[key[k-1]-1];} 07820 } 07821 } 07822 07823 free(list); 07824 free(lend); 07825 free(iwk); 07826 free(good); 07827 free(key); 07828 free(lptr); 07829 free(indx); 07830 free(lcnt); 07831 free(ds); 07832 free(x); 07833 free(y); 07834 free(z); 07835 07836 07837 EXITFUNC; 07838 }
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 7229 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, hsortd(), ImageFormatException, key, LOGERR, phi, theta, voronoi(), and weight.
07230 { 07231 07232 ENTERFUNC; 07233 07234 if ( th.size() != ph.size() ) { 07235 LOGERR("images not same size"); 07236 throw ImageFormatException( "images not same size"); 07237 } 07238 07239 // rand_seed 07240 srand(10); 07241 07242 int i,*key; 07243 int len = th.size(); 07244 double *theta,*phi,*weight; 07245 theta = (double*) calloc(len,sizeof(double)); 07246 phi = (double*) calloc(len,sizeof(double)); 07247 weight = (double*) calloc(len,sizeof(double)); 07248 key = (int*) calloc(len,sizeof(int)); 07249 const float *thptr, *phptr; 07250 07251 thptr = &th[0]; 07252 phptr = &ph[0]; 07253 for(i=1;i<=len;i++){ 07254 key(i) = i; 07255 weight(i) = 0.0; 07256 } 07257 07258 for(i = 0;i<len;i++){ 07259 theta[i] = thptr[i]; 07260 phi[i] = phptr[i]; 07261 } 07262 07263 // sort by theta 07264 Util::hsortd(theta, phi, key, len, 1); 07265 07266 //Util::voronoidiag(theta,phi, weight, len); 07267 Util::voronoi(phi, theta, weight, len); 07268 07269 //sort by key 07270 Util::hsortd(weight, weight, key, len, 2); 07271 07272 free(theta); 07273 free(phi); 07274 free(key); 07275 vector<double> wt; 07276 double count = 0; 07277 for(i=1; i<= len; i++) 07278 { 07279 wt.push_back(weight(i)); 07280 count += weight(i); 07281 } 07282 07283 //if( abs(count-6.28) > 0.1 ) 07284 //{ 07285 // printf("Warning: SUM OF VORONOI CELLS AREAS IS %lf, should 2*PI\n", count); 07286 //} 07287 07288 free(weight); 07289 07290 EXITFUNC; 07291 return wt; 07292 07293 }
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 5328 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().
05329 { 05330 /* Exception Handle */ 05331 if (!img) throw NullPointerException("NULL input image"); 05332 /* ============================== */ 05333 05334 // Get the size of the input image 05335 int nx=img->get_xsize(), ny=img->get_ysize(), nz=img->get_zsize(); 05336 /* ============================== */ 05337 05338 /* Exception Handle */ 05339 if(new_nx>nx || new_ny>ny || new_nz>nz) 05340 throw ImageDimensionException("The size of the windowed image cannot exceed the input image size. 1"); 05341 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) 05342 throw ImageDimensionException("The offset inconsistent with the input image size. 2"); 05343 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)))) 05344 throw ImageDimensionException("The offset inconsistent with the input image size. 3"); 05345 /* ============================== */ 05346 05347 /* Calculation of the start point */ 05348 int new_st_x = nx/2-new_nx/2 + x_offset, 05349 new_st_y = ny/2-new_ny/2 + y_offset, 05350 new_st_z = nz/2-new_nz/2 + z_offset; 05351 /* ============================== */ 05352 05353 /* Exception Handle */ 05354 if (new_st_x<0 || new_st_y<0 || new_st_z<0) // WHAT HAPPENS WITH THE END POINT CHECK?? PAP 05355 throw ImageDimensionException("The offset inconsistent with the input image size. 4"); 05356 /* ============================== */ 05357 05358 EMData* wind = img->copy_empty_head(); 05359 wind->set_size(new_nx, new_ny, new_nz); 05360 float *outp=wind->get_data(); 05361 float *inp=img->get_data(); 05362 05363 for (int k=0; k<new_nz; k++) 05364 for(int j=0; j<new_ny; j++) 05365 for(int i=0; i<new_nx; i++) 05366 outp(i,j,k) = inp(i,j,k); 05367 wind->update(); 05368 return wind; 05369 }
void Util::WTF | ( | EMData * | PROJ, | |
vector< float > | SS, | |||
float | SNR, | |||
int | K | |||
) | [static] |
Definition at line 5853 of file util_sparx.cpp.
References EMAN::EMData::get_data(), PROJ, q, SS, EMAN::EMData::update(), W, and Y.
05854 { 05855 05856 --K; // now indexes are started from 0 05857 05858 int NSAM = PROJ->get_xsize(); 05859 int NROW = PROJ->get_ysize(); 05860 05861 if (PROJ->is_fftpadded()) { 05862 NSAM -= (PROJ->is_fftodd()) ? (1) : (2); // correction for DFT image 05863 } 05864 05865 const int ntotal = NSAM*NROW; 05866 const float q = 2.0f; 05867 const float qt = 8.0f/q; 05868 // Fix for padding 2x 05869 const int ipad = 1; 05870 NSAM *= ipad; 05871 NROW *= ipad; 05872 const int NNNN = NSAM+2-(NSAM%2); 05873 const int NX2 = NSAM/2; 05874 const int NR2 = NROW/2; 05875 05876 const int NANG = int(SS.size())/6; 05877 05878 EMData* W = new EMData(); 05879 const int Wnx = NNNN/2; 05880 W->set_size(Wnx,NROW,1); 05881 W->to_zero(); 05882 float *Wptr = W->get_data(); 05883 05884 for (int L=0; L<NANG; L++) { 05885 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); 05886 const float tmp2 = SS(3,L)*( SS(0,K)*SS(1,L) - SS(0,L)*SS(1,K) ); 05887 float OX = SS(5,K)*tmp2 + SS(4,K)*tmp1; 05888 float OY = SS(4,K)*tmp2 - SS(5,K)*tmp1; 05889 if(OX < 0.0f) { 05890 OX = -OX; 05891 OY = -OY; 05892 } 05893 05894 if( OX > 1.0e-6f || fabs(OY) > 1.0e-6f ) { 05895 for (int J=0; J<NROW; ++J) { 05896 const float JY_OY = (J > NR2) ? ((J-NROW)*OY) : (J*OY); 05897 int xma = NX2; 05898 int xmi = 0; 05899 const float fxma = ( q-JY_OY) / OX; 05900 const float fxmi = (-q-JY_OY) / OX; 05901 if (fxma < xmi || fxmi > xma ) { 05902 continue; 05903 } 05904 if (fxma < xma) { 05905 xma = static_cast<int>(fxma+0.5f); 05906 } 05907 if (fxmi > xmi) { 05908 xmi = static_cast<int>(fxmi+0.5f); 05909 } 05910 for( int I=xmi; I<=xma; ++I ) { 05911 const float Y = I*OX + JY_OY; 05912 W(I,J) += exp(-qt*Y*Y); 05913 } 05914 } 05915 } else { 05916 for (int J=0; J<NROW; ++J) { 05917 for (int I=0; I<NNNN/2; ++I) { 05918 W(I,J) += 1.0f; 05919 } 05920 } 05921 } 05922 } 05923 05924 EMData* proj_in = PROJ; 05925 05926 const bool realOnInput = PROJ->is_real(); 05927 if (realOnInput) { 05928 // copy input image and run DFT on it 05929 PROJ = PROJ->norm_pad( false, ipad); 05930 PROJ->do_fft_inplace(); 05931 PROJ->update(); 05932 } 05933 float * PROJptr = PROJ->get_data(); 05934 05935 const float osnr = 1.0f/SNR; 05936 const float WNRMinv = 1.0f/W(0,0); 05937 for (int J=0; J<NROW; ++J) { 05938 float sy = (J > NR2) ? (J - NROW) : (J); 05939 sy /= NROW; 05940 sy *= sy; 05941 for (int I=0; I<NNNN; I+=2) { 05942 const int KX = I/2; 05943 const float temp = W(KX,J)*WNRMinv; 05944 float WW = temp/(temp*temp + osnr); 05945 // This is supposed to fix fall-off due to Gaussian function in the weighting function 05946 const float sx = float(KX) / NSAM; 05947 WW *= exp(qt*(sy + sx*sx)); 05948 PROJ(I,J) *= WW; 05949 PROJ(I+1,J) *= WW; 05950 } 05951 } 05952 delete W; W = 0; 05953 05954 PROJ->do_ift_inplace(); 05955 PROJ->depad(); 05956 05957 if (realOnInput) { 05958 // copy data back to input image 05959 float* data_src = PROJ->get_data(); 05960 float* data_dst = proj_in->get_data(); 05961 memcpy( data_dst, data_src, ntotal * sizeof(float) ); 05962 delete PROJ; 05963 } 05964 05965 proj_in->update(); 05966 }
void Util::WTM | ( | EMData * | PROJ, | |
vector< float > | SS, | |||
int | DIAMETER, | |||
int | NUMP | |||
) | [static] |
Definition at line 6060 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.
06061 { 06062 float rad2deg =(180.0f/3.1415926f); 06063 float deg2rad = (3.1415926f/180.0f); 06064 06065 int NSAM,NROW,NNNN,NR2,NANG,L,JY; 06066 06067 NSAM = PROJ->get_xsize(); 06068 NROW = PROJ->get_ysize(); 06069 06070 if (PROJ->is_fftpadded()) { 06071 NSAM -= (PROJ->is_fftodd()) ? (1) : (2); // correction for DFT image 06072 } 06073 06074 NNNN = NSAM+2-(NSAM%2); 06075 NR2 = NROW/2; 06076 NANG = int(SS.size())/6; 06077 06078 float RI[9]; 06079 RI(1,1)=SS(1,NUMP)*SS(3,NUMP)*SS(5,NUMP)-SS(2,NUMP)*SS(6,NUMP); 06080 RI(2,1)=-SS(1,NUMP)*SS(3,NUMP)*SS(6,NUMP)-SS(2,NUMP)*SS(5,NUMP); 06081 RI(3,1)=SS(1,NUMP)*SS(4,NUMP); 06082 RI(1,2)=SS(2,NUMP)*SS(3,NUMP)*SS(5,NUMP)+SS(1,NUMP)*SS(6,NUMP); 06083 RI(2,2)=-SS(2,NUMP)*SS(3,NUMP)*SS(6,NUMP)+SS(1,NUMP)*SS(5,NUMP); 06084 RI(3,2)=SS(2,NUMP)*SS(4,NUMP); 06085 RI(1,3)=-SS(4,NUMP)*SS(5,NUMP); 06086 RI(2,3)=SS(4,NUMP)*SS(6,NUMP); 06087 RI(3,3)=SS(3,NUMP); 06088 06089 float THICK=static_cast<float>( NSAM)/DIAMETER/2.0f ; 06090 06091 EMData* W = new EMData(); 06092 int Wnx = NNNN/2; 06093 W->set_size(NNNN/2,NROW,1); 06094 W->to_one(); 06095 float *Wptr = W->get_data(); 06096 06097 float ALPHA,TMP,FV,RT,FM,CCN,CC[3],CP[2],VP[2],VV[3]; 06098 06099 for (L=1; L<=NANG; L++) { 06100 if (L != NUMP) { 06101 CC(1)=SS(2,L)*SS(4,L)*SS(3,NUMP)-SS(3,L)*SS(2,NUMP)*SS(4,NUMP); 06102 CC(2)=SS(3,L)*SS(1,NUMP)*SS(4,NUMP)-SS(1,L)*SS(4,L)*SS(3,NUMP); 06103 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); 06104 06105 TMP = sqrt(CC(1)*CC(1) + CC(2)*CC(2) + CC(3)*CC(3)); 06106 CCN=static_cast<float>( AMAX1( AMIN1(TMP,1.0) ,-1.0) ); 06107 ALPHA=rad2deg*float(asin(CCN)); 06108 if (ALPHA>180.0f) ALPHA=ALPHA-180.0f; 06109 if (ALPHA>90.0f) ALPHA=180.0f-ALPHA; 06110 if(ALPHA<1.0E-6) { 06111 for(int J=1;J<=NROW;J++) for(int I=1;I<=NNNN/2;I++) W(I,J)+=1.0; 06112 } else { 06113 FM=THICK/(fabs(sin(ALPHA*deg2rad))); 06114 CC(1) = CC(1)/CCN;CC(2) = CC(2)/CCN;CC(3) = CC(3)/CCN; 06115 VV(1)= SS(2,L)*SS(4,L)*CC(3)-SS(3,L)*CC(2); 06116 VV(2)= SS(3,L)*CC(1)-SS(1,L)*SS(4,L)*CC(3); 06117 VV(3)= SS(1,L)*SS(4,L)*CC(2)-SS(2,L)*SS(4,L)*CC(1); 06118 CP(1) = 0.0;CP(2) = 0.0; 06119 VP(1) = 0.0;VP(2) = 0.0; 06120 06121 CP(1) = CP(1) + RI(1,1)*CC(1) + RI(1,2)*CC(2) + RI(1,3)*CC(3); 06122 CP(2) = CP(2) + RI(2,1)*CC(1) + RI(2,2)*CC(2) + RI(2,3)*CC(3); 06123 VP(1) = VP(1) + RI(1,1)*VV(1) + RI(1,2)*VV(2) + RI(1,3)*VV(3); 06124 VP(2) = VP(2) + RI(2,1)*VV(1) + RI(2,2)*VV(2) + RI(2,3)*VV(3); 06125 06126 TMP = CP(1)*VP(2)-CP(2)*VP(1); 06127 06128 // PREVENT TMP TO BE TOO SMALL, SIGN IS IRRELEVANT 06129 TMP = AMAX1(1.0E-4f,fabs(TMP)); 06130 float tmpinv = 1.0f/TMP; 06131 for(int J=1;J<=NROW;J++) { 06132 JY = (J-1); 06133 if (JY>NR2) JY=JY-NROW; 06134 for(int I=1;I<=NNNN/2;I++) { 06135 FV = fabs((JY*CP(1)-(I-1)*CP(2))*tmpinv); 06136 RT = 1.0f-FV/FM; 06137 W(I,J) += ((RT>0.0f)*RT); 06138 } 06139 } 06140 } 06141 } 06142 } 06143 06144 EMData* proj_in = PROJ; 06145 const bool realOnInput = PROJ->is_real(); 06146 06147 if (realOnInput) { 06148 // copy input image and run DFT on it 06149 PROJ = PROJ->norm_pad( false, 1 ); 06150 PROJ->do_fft_inplace(); 06151 PROJ->update(); 06152 } 06153 float *PROJptr = PROJ->get_data(); 06154 06155 int KX; 06156 float WW; 06157 for(int J=1; J<=NROW; J++) 06158 for(int I=1; I<=NNNN; I+=2) { 06159 KX = (I+1)/2; 06160 WW = 1.0f/W(KX,J); 06161 PROJ(I,J) = PROJ(I,J)*WW; 06162 PROJ(I+1,J) = PROJ(I+1,J)*WW; 06163 } 06164 delete W; W = 0; 06165 PROJ->do_ift_inplace(); 06166 PROJ->depad(); 06167 06168 if (realOnInput) { 06169 // copy data back to input image 06170 float* data_src = PROJ->get_data(); 06171 float* data_dst = proj_in->get_data(); 06172 int ntotal = NSAM*NROW; 06173 memcpy( data_dst, data_src, ntotal * sizeof(float) ); 06174 delete PROJ; 06175 } 06176 06177 proj_in->update(); 06178 }