#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, vector< float > DM) |
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 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) |
checks both straight & mirrored position input - fourier transforms of rings!! circ1 already multiplied by weights! | |
static Dict | Crosrng_psi_0_180 (EMData *circ1, EMData *circ2, vector< int > numr, float psi_max) |
checks both straight & mirrored positions Find only positions within +/-pis_max of 0 and 180 (for helcal use) input - fourier transforms of rings! circ1 already multiplied by weights! | |
static Dict | Crosrng_psi_0_180_no_mirror (EMData *circ1, EMData *circ2, vector< int > numr, float psi_max) |
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 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) |
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 int | get_randnum_seed () |
Get the seed for Randnum class. | |
static void | set_randnum_seed (unsigned long int 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 17643 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().
17644 { 17645 ENTERFUNC; 17646 /* Exception Handle */ 17647 if (!img) { 17648 throw NullPointerException("NULL input image"); 17649 } 17650 /* ========= img += img1 ===================== */ 17651 17652 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17653 size_t size = (size_t)nx*ny*nz; 17654 float *img_ptr = img->get_data(); 17655 float *img1_ptr = img1->get_data(); 17656 for (size_t i=0;i<size;++i) img_ptr[i] += img1_ptr[i]; 17657 img->update(); 17658 17659 EXITFUNC; 17660 }
Definition at line 17681 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().
17682 { 17683 ENTERFUNC; 17684 /* Exception Handle */ 17685 if (!img) { 17686 throw NullPointerException("NULL input image"); 17687 } 17688 /* ========= img += img1**2 ===================== */ 17689 17690 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17691 size_t size = (size_t)nx*ny*nz; 17692 float *img_ptr = img->get_data(); 17693 float *img1_ptr = img1->get_data(); 17694 if(img->is_complex()) { 17695 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] ; 17696 } else { 17697 for (size_t i=0;i<size;++i) img_ptr[i] += img1_ptr[i]*img1_ptr[i]; 17698 } 17699 img->update(); 17700 17701 EXITFUNC; 17702 }
Definition at line 17662 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().
17663 { 17664 ENTERFUNC; 17665 /* Exception Handle */ 17666 if (!img) { 17667 throw NullPointerException("NULL input image"); 17668 } 17669 /* ========= img += img1 ===================== */ 17670 17671 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17672 size_t size = (size_t)nx*ny*nz; 17673 float *img_ptr = img->get_data(); 17674 float *img1_ptr = img1->get_data(); 17675 for (size_t i=0;i<size;++i) img_ptr[i] += abs(img1_ptr[i]); 17676 img->update(); 17677 17678 EXITFUNC; 17679 }
Definition at line 17460 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().
17461 { 17462 ENTERFUNC; 17463 /* Exception Handle */ 17464 if (!img) { 17465 throw NullPointerException("NULL input image"); 17466 } 17467 /* ============== output = img + img1 ================ */ 17468 17469 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17470 size_t size = (size_t)nx*ny*nz; 17471 EMData * img2 = img->copy_head(); 17472 float *img_ptr =img->get_data(); 17473 float *img2_ptr = img2->get_data(); 17474 float *img1_ptr = img1->get_data(); 17475 for (size_t i=0;i<size;++i) img2_ptr[i] = img_ptr[i] + img1_ptr[i]; 17476 img2->update(); 17477 if(img->is_complex()) { 17478 img2->set_complex(true); 17479 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17480 } 17481 17482 EXITFUNC; 17483 return img2; 17484 }
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 1717 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 19098 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.
19100 { 19101 19102 int maxrin = numr[numr.size()-1]; 19103 19104 int ky = int(2*yrng/step+0.5)/2; 19105 int kx = int(2*xrng/step+0.5)/2; 19106 19107 float *p_ccf1ds = (float *)malloc(maxrin*sizeof(float)); 19108 float *p_ccf1dm = (float *)malloc(maxrin*sizeof(float)); 19109 int vol = maxrin*(2*kx+1)*(2*ky+1); 19110 vector<ccf_point> ccf(2*vol); 19111 ccf_point temp; 19112 19113 int index = 0; 19114 for (int i = -ky; i <= ky; i++) { 19115 float iy = i * step; 19116 for (int j = -kx; j <= kx; j++) { 19117 float ix = j*step; 19118 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 19119 Frngs(cimage, numr); 19120 Crosrng_msg_vec(crefim, cimage, numr, p_ccf1ds, p_ccf1dm); 19121 for (int k=0; k<maxrin; k++) { 19122 temp.value = p_ccf1ds[k]; 19123 temp.i = k; 19124 temp.j = j; 19125 temp.k = i; 19126 temp.mirror = 0; 19127 ccf[index] = temp; 19128 index++; 19129 temp.value = p_ccf1dm[k]; 19130 temp.mirror = 1; 19131 ccf[index] = temp; 19132 index++; 19133 } 19134 delete cimage; cimage = 0; 19135 } 19136 } 19137 19138 delete p_ccf1ds; 19139 delete p_ccf1dm; 19140 std::sort(ccf.begin(), ccf.end(), ccf_value()); 19141 19142 double qt = (double)ccf[0].value; 19143 vector <double> p(2*vol), cp(2*vol); 19144 19145 double sump = 0.0; 19146 for (int i=0; i<2*vol; i++) { 19147 p[i] = pow(double(ccf[i].value)/qt, 1.0/T); 19148 sump += p[i]; 19149 } 19150 for (int i=0; i<2*vol; i++) { 19151 p[i] /= sump; 19152 } 19153 for (int i=1; i<2*vol; i++) { 19154 p[i] += p[i-1]; 19155 } 19156 p[2*vol-1] = 2.0; 19157 19158 float t = get_frand(0.0f, 1.0f); 19159 int select = 0; 19160 while (p[select] < t) select += 1; 19161 19162 vector<float> a(6); 19163 a[0] = ccf[select].value; 19164 a[1] = (float)ccf[select].i; 19165 a[2] = (float)ccf[select].j; 19166 a[3] = (float)ccf[select].k; 19167 a[4] = (float)ccf[select].mirror; 19168 a[5] = (float)select; 19169 return a; 19170 }
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 2364 of file util_sparx.cpp.
References circ, numr, quadri(), and y.
02365 { 02366 double dpi, dfi; 02367 int it, jt, inr, l, nsim, kcirc, lt; 02368 float xold, yold, fi, x, y; 02369 02370 // cns2 and cnr2 are predefined centers 02371 // no need to set to zero, all elements are defined 02372 02373 dpi = 2*atan(1.0); 02374 for (it=1; it<=nring; it++) { 02375 // radius of the ring 02376 inr = numr(1,it); 02377 02378 l = numr(3,it); 02379 if ( mode == 'h' || mode == 'H' ) lt = l / 2; 02380 else lt = l / 4; 02381 02382 nsim = lt - 1; 02383 dfi = dpi / (nsim+1); 02384 kcirc = numr(2,it); 02385 02386 02387 xold = 0.0f+cns2; 02388 yold = inr+cnr2; 02389 02390 circ(kcirc) = quadri(xold,yold,nsam,nrow,xim); 02391 02392 xold = inr+cns2; 02393 yold = 0.0f+cnr2; 02394 circ(lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02395 02396 if ( mode == 'f' || mode == 'F' ) { 02397 xold = 0.0f+cns2; 02398 yold = -inr+cnr2; 02399 circ(lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02400 02401 xold = -inr+cns2; 02402 yold = 0.0f+cnr2; 02403 circ(lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02404 } 02405 02406 for (jt=1; jt<=nsim; jt++) { 02407 fi = static_cast<float>(dfi * jt); 02408 x = sin(fi) * inr; 02409 y = cos(fi) * inr; 02410 02411 xold = x+cns2; 02412 yold = y+cnr2; 02413 circ(jt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02414 02415 xold = y+cns2; 02416 yold = -x+cnr2; 02417 circ(jt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02418 02419 if ( mode == 'f' || mode == 'F' ) { 02420 xold = -x+cns2; 02421 yold = -y+cnr2; 02422 circ(jt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02423 02424 xold = -y+cns2; 02425 yold = x+cnr2; 02426 circ(jt+lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02427 } 02428 } // end for jt 02429 } //end for it 02430 }
float Util::ang_n | ( | float | peakp, | |
string | mode, | |||
int | maxrin | |||
) | [static, private] |
Definition at line 17890 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().
17891 { 17892 if (mode == "f" || mode == "F") 17893 return fmodf(((peakp-1.0f) / maxrin+1.0f)*360.0f,360.0f); 17894 else 17895 return fmodf(((peakp-1.0f) / maxrin+1.0f)*180.0f,180.0f); 17896 }
void Util::ang_to_xyz | ( | double * | x, | |
double * | y, | |||
double * | z, | |||
int | len | |||
) | [static] |
Definition at line 7858 of file util_sparx.cpp.
References dgr_to_rad, ENTERFUNC, and EXITFUNC.
07859 { 07860 ENTERFUNC; 07861 double costheta,sintheta,cosphi,sinphi; 07862 for(int i = 0; i<len; i++) 07863 { 07864 cosphi = cos(y[i]*dgr_to_rad); 07865 sinphi = sin(y[i]*dgr_to_rad); 07866 if(fabs(x[i]-90.0)< 1.0e-5){ 07867 x[i] = cosphi; 07868 y[i] = sinphi; 07869 z[i] = 0.0; 07870 } 07871 else{ 07872 costheta = cos(x[i]*dgr_to_rad); 07873 sintheta = sin(x[i]*dgr_to_rad); 07874 x[i] = cosphi*sintheta; 07875 y[i] = sinphi*sintheta; 07876 z[i] = costheta; 07877 } 07878 } 07879 EXITFUNC; 07880 }
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 1887 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 1855 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 2110 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().
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 8916 of file util_sparx.cpp.
References areas_(), circum_(), FALSE_, ierr, and TRUE_.
Referenced by voronoi().
08919 { 08920 /* Initialized data */ 08921 08922 static double amax = 6.28; 08923 08924 /* System generated locals */ 08925 double ret_val; 08926 08927 /* Local variables */ 08928 static double a, c0[3], c2[3], c3[3]; 08929 static int n1, n2, n3; 08930 static double v1[3], v2[3], v3[3]; 08931 static int lp, lpl, ierr; 08932 static double asum; 08933 static long int first; 08934 08935 08936 /* *********************************************************** */ 08937 08938 /* Robert J. Renka */ 08939 /* Dept. of Computer Science */ 08940 /* Univ. of North Texas */ 08941 /* renka@cs.unt.edu */ 08942 /* 10/25/02 */ 08943 08944 /* Given a Delaunay triangulation and the index K of an */ 08945 /* interior node, this subroutine returns the (surface) area */ 08946 /* of the Voronoi region associated with node K. The Voronoi */ 08947 /* region is the polygon whose vertices are the circumcenters */ 08948 /* of the triangles that contain node K, where a triangle */ 08949 /* circumcenter is the point (unit vector) lying at the same */ 08950 /* angular distance from the three vertices and contained in */ 08951 /* the same hemisphere as the vertices. */ 08952 08953 08954 /* On input: */ 08955 08956 /* K = Nodal index in the range 1 to N. */ 08957 08958 /* N = Number of nodes in the triangulation. N > 3. */ 08959 08960 /* X,Y,Z = Arrays of length N containing the Cartesian */ 08961 /* coordinates of the nodes (unit vectors). */ 08962 08963 /* LIST,LPTR,LEND = Data structure defining the trian- */ 08964 /* gulation. Refer to Subroutine */ 08965 /* TRMESH. */ 08966 08967 /* Input parameters are not altered by this function. */ 08968 08969 /* On output: */ 08970 08971 /* AREAV = Area of Voronoi region K unless IER > 0, */ 08972 /* in which case AREAV = 0. */ 08973 08974 /* IER = Error indicator: */ 08975 /* IER = 0 if no errors were encountered. */ 08976 /* IER = 1 if K or N is outside its valid range */ 08977 /* on input. */ 08978 /* IER = 2 if K indexes a boundary node. */ 08979 /* IER = 3 if an error flag is returned by CIRCUM */ 08980 /* (null triangle). */ 08981 /* IER = 4 if AREAS returns a value greater than */ 08982 /* AMAX (defined below). */ 08983 08984 /* Modules required by AREAV: AREAS, CIRCUM */ 08985 08986 /* *********************************************************** */ 08987 08988 08989 /* Maximum valid triangle area is less than 2*Pi: */ 08990 08991 /* Parameter adjustments */ 08992 --lend; 08993 --z__; 08994 --y; 08995 --x; 08996 --list; 08997 --lptr; 08998 08999 /* Function Body */ 09000 09001 /* Test for invalid input. */ 09002 09003 if (*k < 1 || *k > *n || *n <= 3) { 09004 goto L11; 09005 } 09006 09007 /* Initialization: Set N3 to the last neighbor of N1 = K. */ 09008 /* FIRST = TRUE only for the first triangle. */ 09009 /* The Voronoi region area is accumulated in ASUM. */ 09010 09011 n1 = *k; 09012 v1[0] = x[n1]; 09013 v1[1] = y[n1]; 09014 v1[2] = z__[n1]; 09015 lpl = lend[n1]; 09016 n3 = list[lpl]; 09017 if (n3 < 0) { 09018 goto L12; 09019 } 09020 lp = lpl; 09021 first = TRUE_; 09022 asum = 0.; 09023 09024 /* Loop on triangles (N1,N2,N3) containing N1 = K. */ 09025 09026 L1: 09027 n2 = n3; 09028 lp = lptr[lp]; 09029 n3 = list[lp]; 09030 v2[0] = x[n2]; 09031 v2[1] = y[n2]; 09032 v2[2] = z__[n2]; 09033 v3[0] = x[n3]; 09034 v3[1] = y[n3]; 09035 v3[2] = z__[n3]; 09036 if (first) { 09037 09038 /* First triangle: compute the circumcenter C3 and save a */ 09039 /* copy in C0. */ 09040 09041 circum_(v1, v2, v3, c3, &ierr); 09042 if (ierr != 0) { 09043 goto L13; 09044 } 09045 c0[0] = c3[0]; 09046 c0[1] = c3[1]; 09047 c0[2] = c3[2]; 09048 first = FALSE_; 09049 } else { 09050 09051 /* Set C2 to C3, compute the new circumcenter C3, and compute */ 09052 /* the area A of triangle (V1,C2,C3). */ 09053 09054 c2[0] = c3[0]; 09055 c2[1] = c3[1]; 09056 c2[2] = c3[2]; 09057 circum_(v1, v2, v3, c3, &ierr); 09058 if (ierr != 0) { 09059 goto L13; 09060 } 09061 a = areas_(v1, c2, c3); 09062 if (a > amax) { 09063 goto L14; 09064 } 09065 asum += a; 09066 } 09067 09068 /* Bottom on loop on neighbors of K. */ 09069 09070 if (lp != lpl) { 09071 goto L1; 09072 } 09073 09074 /* Compute the area of triangle (V1,C3,C0). */ 09075 09076 a = areas_(v1, c3, c0); 09077 if (a > amax) { 09078 goto L14; 09079 } 09080 asum += a; 09081 09082 /* No error encountered. */ 09083 09084 *ier = 0; 09085 ret_val = asum; 09086 return ret_val; 09087 09088 /* Invalid input. */ 09089 09090 L11: 09091 *ier = 1; 09092 ret_val = 0.; 09093 return ret_val; 09094 09095 /* K indexes a boundary node. */ 09096 09097 L12: 09098 *ier = 2; 09099 ret_val = 0.; 09100 return ret_val; 09101 09102 /* Error in CIRCUM. */ 09103 09104 L13: 09105 *ier = 3; 09106 ret_val = 0.; 09107 return ret_val; 09108 09109 /* AREAS value larger than AMAX. */ 09110 09111 L14: 09112 *ier = 4; 09113 ret_val = 0.; 09114 return ret_val; 09115 } /* 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 20658 of file util_sparx.cpp.
References t.
Referenced by image_mutation().
20658 { 20659 20660 if (is_mirror != 0) { 20661 for (int i=0; i<len_list; i++) { 20662 int r = rand()%10000; 20663 float f = r/10000.0f; 20664 if (f < mutation_rate) list[i] = 1-list[i]; 20665 } 20666 } else { 20667 map<int, vector<int> > graycode; 20668 map<vector<int>, int> rev_graycode; 20669 vector <int> gray; 20670 20671 int K=1; 20672 for (int i=0; i<L; i++) K*=2; 20673 20674 for (int k=0; k<K; k++) { 20675 int shift = 0; 20676 vector <int> gray; 20677 for (int i=L-1; i>-1; i--) { 20678 int t = ((k>>i)%2-shift)%2; 20679 gray.push_back(t); 20680 shift += t-2; 20681 } 20682 graycode[k] = gray; 20683 rev_graycode[gray] = k; 20684 } 20685 20686 float gap = (K-1)/(max_val-min_val); 20687 for (int i=0; i<len_list; i++) { 20688 float val = list[i]; 20689 if (val < min_val) { val = min_val; } 20690 else if (val > max_val) { val = max_val; } 20691 int k = int((val-min_val)*gap+0.5); 20692 vector<int> gray = graycode[k]; 20693 bool changed = false; 20694 for (vector<int>::iterator p=gray.begin(); p!=gray.end(); p++) { 20695 int r = rand()%10000; 20696 float f = r/10000.0f; 20697 if (f < mutation_rate) { 20698 *p = 1-*p; 20699 changed = true; 20700 } 20701 } 20702 if (changed) { 20703 k = rev_graycode[gray]; 20704 list[i] = k/gap+min_val; 20705 } 20706 } 20707 } 20708 20709 }
vector< int > Util::assign_groups | ( | const vector< float > & | d, | |
int | nref, | |||
int | nima | |||
) | [static] |
Definition at line 18061 of file util_sparx.cpp.
References peak_table::index.
18061 { 18062 18063 int kt = nref; 18064 unsigned int maxasi = nima/nref; 18065 vector< vector<int> > id_list; 18066 id_list.resize(nref); 18067 int group, ima; 18068 18069 peak_table* dd = new peak_table[nref*nima]; 18070 for (int i=0; i<nref*nima; i++) { 18071 dd[i].value = d[i]; 18072 dd[i].index = i; 18073 } 18074 sort(dd, dd+nref*nima); 18075 int begin = 0; 18076 18077 bool* del_row = new bool[nref]; 18078 for (int i=0; i<nref; i++) del_row[i] = false; 18079 bool* del_column = new bool[nima]; 18080 for (int i=0; i<nima; i++) del_column[i] = false; 18081 while (kt > 0) { 18082 bool flag = true; 18083 while (flag) { 18084 int l = dd[begin].index; 18085 group = l/nima; 18086 ima = l%nima; 18087 if (del_column[ima] || del_row[group]) begin++; 18088 else flag = false; 18089 } 18090 18091 id_list[group].push_back(ima); 18092 if (kt > 1) { 18093 if (id_list[group].size() < maxasi) group = -1; 18094 else kt -= 1; 18095 } else { 18096 if (id_list[group].size() < maxasi+nima%nref) group = -1; 18097 else kt -= 1; 18098 } 18099 del_column[ima] = true; 18100 if (group != -1) { 18101 del_row[group] = true; 18102 } 18103 } 18104 18105 vector<int> id_list_1; 18106 for (int iref=0; iref<nref; iref++) 18107 for (unsigned int im=0; im<maxasi; im++) 18108 id_list_1.push_back(id_list[iref][im]); 18109 for (unsigned int im=maxasi; im<maxasi+nima%nref; im++) 18110 id_list_1.push_back(id_list[group][im]); 18111 id_list_1.push_back(group); 18112 18113 delete[] del_row; 18114 delete[] del_column; 18115 delete[] dd; 18116 return id_list_1; 18117 }
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 21076 of file util_sparx.cpp.
References branchMPI(), initial_prune(), and sanitycheck().
21077 { 21078 21079 21080 // 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 21081 // 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 21082 // Make a vector of nParts vectors of K int* each 21083 int* Indices = new int[nParts*K]; 21084 int ind_c = 0; 21085 for (int i=0; i < nParts; i++){ 21086 for(int j = 0; j < K; j++){ 21087 Indices[i*K + j] = ind_c; 21088 ind_c = ind_c + dimClasses[i*K + j]; 21089 } 21090 } 21091 21092 // do initial pruning on argParts and return the pruned partitions 21093 21094 // Make a vector of nParts vectors of K int* each 21095 vector <vector <int*> > Parts(nParts,vector<int*>(K)); 21096 ind_c = 0; 21097 int argParts_size=0; 21098 for (int i=0; i < nParts; i++){ 21099 for(int j = 0; j < K; j++){ 21100 Parts[i][j] = argParts + ind_c; 21101 ind_c = ind_c + dimClasses[i*K + j]; 21102 argParts_size = argParts_size + dimClasses[i*K + j]; 21103 } 21104 } 21105 21106 // in the following we call initial_prune with Parts which is a vector. This is not the most 21107 // efficient since vector does not allow for direct addressing. But since initial_prune doesn't have very high complexity, and 21108 // 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..... 21109 21110 // comment out for testing 21111 Util::initial_prune(Parts, dimClasses, nParts, K, T); 21112 for(int i = 0; i < nParts; i++){ 21113 for(int j=0; j < K; j++){ 21114 argParts[Indices[i*K + j]+1] = -1; 21115 } 21116 } 21117 21118 int num_classes; 21119 int old_index; 21120 for(int i=0; i<nParts; i++){ 21121 num_classes = Parts[i].size();// number of classes in partition i after pruning 21122 for (int j=0; j < num_classes; j++){ 21123 old_index = Parts[i][j][0]; 21124 //cout << "old_index: " << old_index<<"\n"; 21125 argParts[Indices[i*K + old_index]+1] = 1; 21126 } 21127 } 21128 21129 21130 // if we're not doing mpi then keep going and call branchMPI and return the output 21131 //cout <<"begin partition matching\n"; 21132 //int* dummy(0); 21133 int* output = Util::branchMPI(argParts, Indices,dimClasses, nParts, K, T, 0, n_guesses, LARGEST_CLASS, J, max_branching, stmult, branchfunc, LIM); 21134 21135 //cout<<"total cost: "<<*output<<"\n"; 21136 //cout<<"number of matches: "<<*(output+1)<<"\n"; 21137 // 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 21138 bool correct = Util::sanitycheck(argParts, Indices,dimClasses, nParts, K, T,output); 21139 21140 delete[] Indices; 21141 21142 // something is wrong with output of branchMPI! 21143 if (correct < 1){ 21144 cout << "something is wrong with output of branchMPI!\n"; 21145 vector<int> ret(1); 21146 ret[0] = -1; 21147 if (output != 0) { delete[] output; output = 0; } 21148 return ret; 21149 } 21150 21151 // output is not nonsense, so now put it into a single dimension vector and return 21152 // 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 21153 // and the rest is the list of matches. output is one dimensional 21154 21155 int output_size = 2 + output[1] * nParts; 21156 vector<int> ret(output_size); 21157 for (int i = 0; i < output_size; i++) { 21158 ret[i]= output[i]; 21159 } 21160 if (output != 0) { delete[] output; output = 0; } 21161 return ret; 21162 21163 }
float Util::bilinear | ( | float | xold, | |
float | yold, | |||
int | nsam, | |||
int | nrow, | |||
float * | xim | |||
) | [static] |
Definition at line 2315 of file util_sparx.cpp.
References xim.
02316 { 02317 /* 02318 c purpose: linear interpolation 02319 Optimized for speed, circular closer removed, checking of ranges removed 02320 */ 02321 float bilinear; 02322 int ixold, iyold; 02323 02324 /* 02325 float xdif, ydif, xrem, yrem; 02326 ixold = (int) floor(xold); 02327 iyold = (int) floor(yold); 02328 ydif = yold - iyold; 02329 yrem = 1.0f - ydif; 02330 02331 // May want to insert if? 02332 // IF ((IYOLD .GE. 1 .AND. IYOLD .LE. NROW-1) .AND. 02333 // & (IXOLD .GE. 1 .AND. IXOLD .LE. NSAM-1)) THEN 02334 //c INSIDE BOUNDARIES OF OUTPUT IMAGE 02335 xdif = xold - ixold; 02336 xrem = 1.0f- xdif; 02337 // RBUF(K) = YDIF*(BUF(NADDR+NSAM)*XREM 02338 // & +BUF(NADDR+NSAM+1)*XDIF) 02339 // & +YREM*(BUF(NADDR)*XREM + BUF(NADDR+1)*XDIF) 02340 bilinear = ydif*(xim(ixold,iyold+1)*xrem + xim(ixold+1,iyold+1)*xdif) + 02341 yrem*(xim(ixold,iyold)*xrem+xim(ixold+1,iyold)*xdif); 02342 02343 return bilinear; 02344 } 02345 */ 02346 float xdif, ydif; 02347 02348 ixold = (int) xold; 02349 iyold = (int) yold; 02350 ydif = yold - iyold; 02351 02352 // May want to insert it? 02353 // IF ((IYOLD .GE. 1 .AND. IYOLD .LE. NROW-1) .AND. 02354 // & (IXOLD .GE. 1 .AND. IXOLD .LE. NSAM-1)) THEN 02355 //c INSIDE BOUNDARIES OF OUTPUT IMAGE 02356 xdif = xold - ixold; 02357 bilinear = xim(ixold, iyold) + ydif* (xim(ixold, iyold+1) - xim(ixold, iyold)) + 02358 xdif* (xim(ixold+1, iyold) - xim(ixold, iyold) + 02359 ydif* (xim(ixold+1, iyold+1) - xim(ixold+1, iyold) - xim(ixold, iyold+1) + xim(ixold, iyold)) ); 02360 02361 return bilinear; 02362 }
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 1488 of file util.h.
Referenced by EMAN::EMData::common_lines(), EMAN::EMData::cut_slice(), EMAN::StandardProjector::project3d(), EMAN::EMData::sget_value_at_interp(), EMAN::TransformProcessor::transform(), and EMAN::EMData::unwrap().
Definition at line 5816 of file util_sparx.cpp.
References B, CUBE, DM, and t.
05817 { 05818 05819 float *Bptr = B->get_data(); 05820 float *CUBEptr = CUBE->get_data(); 05821 05822 int NSAM,NROW,NX3D,NY3D,NZC,KZ,IQX,IQY,LDPX,LDPY,LDPZ,LDPNMX,LDPNMY,NZ1; 05823 float DIPX,DIPY,XB,YB,XBB,YBB; 05824 05825 Transform * t = B->get_attr("xform.projection"); 05826 Dict d = t->get_params("spider"); 05827 if(t) {delete t; t=0;} 05828 // Unsure about sign of shifts, check later PAP 06/28/09 05829 float x_shift = d[ "tx" ]; 05830 float y_shift = d[ "ty" ]; 05831 x_shift = -x_shift; 05832 y_shift = -y_shift; 05833 05834 NSAM = B->get_xsize(); 05835 NROW = B->get_ysize(); 05836 NX3D = CUBE->get_xsize(); 05837 NY3D = CUBE->get_ysize(); 05838 NZC = CUBE->get_zsize(); 05839 05840 05841 LDPX = NX3D/2 +1; 05842 LDPY = NY3D/2 +1; 05843 LDPZ = NZC/2 +1; 05844 LDPNMX = NSAM/2 +1; 05845 LDPNMY = NROW/2 +1; 05846 NZ1 = 1; 05847 05848 for(int K=1;K<=NZC;K++) { 05849 KZ=K-1+NZ1; 05850 for(int J=1;J<=NY3D;J++) { 05851 XBB = (1-LDPX)*DM(1)+(J-LDPY)*DM(2)+(KZ-LDPZ)*DM(3); 05852 YBB = (1-LDPX)*DM(4)+(J-LDPY)*DM(5)+(KZ-LDPZ)*DM(6); 05853 for(int I=1;I<=NX3D;I++) { 05854 XB = (I-1)*DM(1)+XBB-x_shift; 05855 IQX = int(XB+float(LDPNMX)); 05856 if (IQX <1 || IQX >= NSAM) continue; 05857 YB = (I-1)*DM(4)+YBB-y_shift; 05858 IQY = int(YB+float(LDPNMY)); 05859 if (IQY<1 || IQY>=NROW) continue; 05860 DIPX = XB+LDPNMX-IQX; 05861 DIPY = YB+LDPNMY-IQY; 05862 05863 CUBE(I,J,K) = CUBE(I,J,K)+B(IQX,IQY)+DIPY*(B(IQX,IQY+1)-B(IQX,IQY))+DIPX*(B(IQX+1,IQY)-B(IQX,IQY)+DIPY*(B(IQX+1,IQY+1)-B(IQX+1,IQY)-B(IQX,IQY+1)+B(IQX,IQY))); 05864 } 05865 } 05866 } 05867 }
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 21595 of file util_sparx.cpp.
Referenced by branchMPI().
21595 { 21596 21597 int ntot=0; 21598 for (int jit=0; jit < J; jit++){ 21599 if (*(costlist+jit) > T) ntot++; 21600 } 21601 21602 int cur; 21603 // sort matchlist by cost 21604 int* indx = new int[J]; 21605 for (int jit=0; jit < J; jit++) indx[jit]=jit; 21606 vector<int> myindx (indx, indx+J); 21607 vector<int>::iterator it; 21608 costlist_global=costlist; 21609 sort(myindx.begin(), myindx.begin()+J, jiafunc); 21610 21611 // put matchlist in the order of mycost 21612 int* templist = new int[J]; 21613 int* temp2list = new int[J*nParts]; 21614 int next = 0; 21615 21616 for (it=myindx.begin(); it!=myindx.end();++it){ 21617 cur = *(costlist + *it); 21618 if (cur > T){ 21619 21620 templist[next] = cur; 21621 for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt]; 21622 next = next + 1; 21623 } 21624 } 21625 21626 for (int jit=0; jit < ntot; jit++){ 21627 *(costlist+jit)=*(templist + jit); 21628 //cout <<*(costlist+jit)<<", "; 21629 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit]; 21630 } 21631 //cout <<"\n"; 21632 21633 for (int jit=1; jit < ntot; jit++){ 21634 21635 if ((costlist[jit] == costlist[0]) && costlist[jit] > T){ 21636 21637 for (int vit=0; vit < nParts; vit++){ 21638 if ( matchlist[jit*nParts + vit] > matchlist[vit]) 21639 break; 21640 if ( matchlist[jit*nParts + vit] == matchlist[vit]) 21641 continue; 21642 if ( matchlist[jit*nParts + vit] < matchlist[vit]) 21643 { 21644 // swap 21645 for (int swp=0; swp < nParts; swp++){ 21646 int tmp = matchlist[swp]; 21647 matchlist[swp]= matchlist[jit*nParts + swp]; 21648 matchlist[jit*nParts + swp] = tmp; 21649 } 21650 break; 21651 21652 } 21653 } 21654 } 21655 21656 } 21657 21658 21659 delete [] indx; 21660 //compute the average 21661 21662 // partition matches into groups where matches in each group is mutually feasible, and matches from different groups are not feasible 21663 // The number of branches to explore are the mutually exclusive matches. Take the largest of these 21664 21665 21666 int B=1; 21667 int B_init=B; 21668 int infeasible=0; 21669 21670 for (int i=B_init; i<ntot; i++){ 21671 if (i==ntot) continue; 21672 // look at the i-th match. branch on it only if it is infeasible with ALL previous matches we have decided to 21673 // branch on 21674 infeasible = 0; 21675 if (LIM < 0) LIM = B; 21676 for (int j=0; j<B; j++){ 21677 21678 for (int vit=0; vit<nParts; vit++){ 21679 if (temp2list[i*nParts+vit] == matchlist[j*nParts+vit]) {infeasible++; break;} 21680 } 21681 if (infeasible >= LIM) break; 21682 } 21683 21684 if (infeasible >= LIM){ 21685 *(costlist+B)=*(templist+i); 21686 for (int vit=0; vit < nParts; vit++) 21687 *(matchlist+B*nParts + vit)=*(temp2list+i*nParts + vit); 21688 B=B+1; 21689 } 21690 } 21691 21692 delete [] templist; 21693 delete [] temp2list; 21694 //cout<<"**************************************** "<<B<<" ***************************\n"; 21695 21696 if (branch_all < max_branching){ 21697 if (B>1) 21698 {branch_all = branch_all + B -1 ; } 21699 } 21700 else B=1; 21701 21702 return B; 21703 21704 21705 }
int Util::branch_factor_2 | ( | int * | costlist, | |
int * | matchlist, | |||
int | J, | |||
int | T, | |||
int | nParts, | |||
int | curlevel, | |||
int | max_branching, | |||
int | LIM | |||
) | [static] |
Definition at line 21333 of file util_sparx.cpp.
Referenced by branchMPI().
21333 { 21334 21335 int ntot=0; 21336 for (int jit=0; jit < J; jit++){ 21337 if (*(costlist+jit) > T) ntot++; 21338 } 21339 21340 int cur; 21341 // sort matchlist by cost 21342 int* indx = new int[J]; 21343 for (int jit=0; jit < J; jit++) indx[jit]=jit; 21344 vector<int> myindx (indx, indx+J); 21345 vector<int>::iterator it; 21346 costlist_global=costlist; 21347 sort(myindx.begin(), myindx.end(), jiafunc); 21348 21349 // put matchlist in the order of mycost 21350 int* templist = new int[J]; 21351 int* temp2list = new int[J*nParts]; 21352 int next = 0; 21353 21354 for (it=myindx.begin(); it!=myindx.end();++it){ 21355 cur = *(costlist + *it); 21356 if (cur > T){ 21357 21358 templist[next] = cur; 21359 for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt]; 21360 next = next + 1; 21361 } 21362 } 21363 21364 for (int jit=0; jit < ntot; jit++){ 21365 *(costlist+jit)=*(templist + jit); 21366 //cout <<*(costlist+jit)<<", "; 21367 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit]; 21368 } 21369 //cout <<"\n"; 21370 21371 delete [] indx; 21372 //compute the average 21373 21374 // partition matches into groups where matches in each group is mutually feasible, and matches from different groups are not feasible 21375 // The number of branches to explore are the mutually exclusive matches. Take the largest of these 21376 21377 21378 int B=1; 21379 int B_init=B; 21380 int infeasible=0; 21381 21382 for (int i=B_init; i<ntot; i++){ 21383 if (i==ntot) continue; 21384 // look at the i-th match. branch on it only if it is infeasible with ALL previous matches we have decided to 21385 // branch on 21386 infeasible = 0; 21387 if (LIM < 0) LIM = B; 21388 for (int j=0; j<B; j++){ 21389 21390 for (int vit=0; vit<nParts; vit++){ 21391 if (temp2list[i*nParts+vit] == matchlist[j*nParts+vit]) {infeasible++; break;} 21392 } 21393 if (infeasible >= LIM) break; 21394 } 21395 21396 if (infeasible >= LIM){ 21397 *(costlist+B)=*(templist+i); 21398 for (int vit=0; vit < nParts; vit++) 21399 *(matchlist+B*nParts + vit)=*(temp2list+i*nParts + vit); 21400 B=B+1; 21401 } 21402 } 21403 21404 delete [] templist; 21405 delete [] temp2list; 21406 //cout<<"**************************************** "<<B<<" ***************************\n"; 21407 21408 if (branch_all < max_branching){ 21409 if (B>1) 21410 {branch_all = branch_all + B -1 ; } 21411 } 21412 else B=1; 21413 21414 return B; 21415 21416 21417 }
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 21421 of file util_sparx.cpp.
Referenced by branchMPI().
21421 { 21422 21423 int ntot=0; 21424 for (int jit=0; jit < J; jit++){ 21425 if (*(costlist+jit) > T) ntot++; 21426 } 21427 21428 int cur; 21429 // sort matchlist by cost 21430 int* indx = new int[J]; 21431 for (int jit=0; jit < J; jit++) indx[jit]=jit; 21432 vector<int> myindx (indx, indx+J); 21433 vector<int>::iterator it; 21434 costlist_global=costlist; 21435 sort(myindx.begin(), myindx.begin()+J, jiafunc); 21436 21437 // put matchlist in the order of mycost 21438 int* templist = new int[J]; 21439 int* temp2list = new int[J*nParts]; 21440 int next = 0; 21441 21442 for (it=myindx.begin(); it!=myindx.end();++it){ 21443 cur = *(costlist + *it); 21444 if (cur > T){ 21445 21446 templist[next] = cur; 21447 for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt]; 21448 next = next + 1; 21449 } 21450 } 21451 21452 for (int jit=0; jit < ntot; jit++){ 21453 *(costlist+jit)=*(templist + jit); 21454 //cout <<*(costlist+jit)<<", "; 21455 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit]; 21456 } 21457 //cout <<"\n"; 21458 21459 delete [] indx; 21460 //compute the average 21461 21462 // partition matches into groups where matches in each group is mutually feasible, and matches from different groups are not feasible 21463 // The number of branches to explore are the mutually exclusive matches. Take the largest of these 21464 21465 21466 int B=1; 21467 int B_init=B; 21468 int infeasible=0; 21469 // if we're near the bottom of the tree then explore more... this is because the larger weights are not likely to change much, 21470 // whereas the smaller ones can have many permutations 21471 if (LIM < 0) LIM = ntot-1; 21472 for (int i=B_init; i<ntot; i++){ 21473 if (i==ntot) continue; 21474 // look at the i-th match. branch on it only if it is infeasible with ALL previous matches we have decided to 21475 // branch on 21476 infeasible = 0; 21477 21478 for (int j=0; j<ntot; j++){ 21479 if (j == i) continue; 21480 for (int vit=0; vit<nParts; vit++){ 21481 if (temp2list[i*nParts+vit] == temp2list[j*nParts+vit]) {infeasible++; break;} 21482 } 21483 if (infeasible >= LIM) break; 21484 } 21485 21486 if (infeasible >= LIM){ 21487 *(costlist+B)=*(templist+i); 21488 for (int vit=0; vit < nParts; vit++) 21489 *(matchlist+B*nParts + vit)=*(temp2list+i*nParts + vit); 21490 B=B+1; 21491 } 21492 } 21493 21494 delete [] templist; 21495 delete [] temp2list; 21496 //cout<<"**************************************** "<<B<<" ***************************\n"; 21497 21498 21499 if (branch_all < max_branching){ 21500 if (B>1) 21501 {branch_all = branch_all + B-1;} 21502 } 21503 else B=1; 21504 21505 return B; 21506 21507 21508 }
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 21514 of file util_sparx.cpp.
Referenced by branchMPI().
21514 { 21515 int sum=0; 21516 float average =0; 21517 int ntot=0; 21518 for (int jit=0; jit < J; jit++){ 21519 if (*(costlist+jit) > T) {ntot++; sum = sum +*(costlist+jit);} 21520 } 21521 average = ((float)sum)/((float)ntot); 21522 int cur; 21523 // sort matchlist by cost 21524 int* indx = new int[J]; 21525 for (int jit=0; jit < J; jit++) indx[jit]=jit; 21526 vector<int> myindx (indx, indx+J); 21527 vector<int>::iterator it; 21528 costlist_global=costlist; 21529 sort(myindx.begin(), myindx.begin()+J, jiafunc); 21530 21531 // put matchlist in the order of mycost 21532 int* templist = new int[J]; 21533 int* temp2list = new int[J*nParts]; 21534 int next = 0; 21535 21536 for (it=myindx.begin(); it!=myindx.end();++it){ 21537 cur = *(costlist + *it); 21538 if (cur > T){ 21539 21540 templist[next] = cur; 21541 for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt]; 21542 next = next + 1; 21543 } 21544 } 21545 21546 for (int jit=0; jit < ntot; jit++){ 21547 *(costlist+jit)=*(templist + jit); 21548 //cout <<*(costlist+jit)<<", "; 21549 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit]; 21550 } 21551 //cout <<"\n"; 21552 21553 delete [] indx; 21554 delete [] templist; 21555 delete [] temp2list; 21556 21557 if (ntot == 1) return 1; 21558 21559 // look at the average, standard dev etc. If standard dev very small, i.e., costs very similar, then branch on the similar 21560 // costs 21561 float sq_sum=0.0; 21562 //cout <<"costlist:"; 21563 for (int i=0; i< ntot; i++){ 21564 sq_sum = sq_sum + (float) pow((float) *(costlist+i) - average, (float)2.0); 21565 //cout <<*(costlist+i)<<", "; 21566 } 21567 //cout <<"\n"; 21568 21569 float variance = sq_sum/ntot; 21570 float stdev = (float)pow((float)variance,(float)0.5); 21571 21572 //cout <<"stdev: "<<int(stdev)<<"\n"; 21573 21574 int B=1; 21575 int largest = *costlist; 21576 //cout <<"largest: "<<largest<<"\n"; 21577 for (int i=1; i<ntot; i++){ 21578 int cur = *(costlist+i); 21579 if (largest-cur < (float)(stdev*stmult)) B++; 21580 else break; 21581 21582 } 21583 //cout <<"B: "<<B<<"\n"; 21584 if (branch_all < max_branching){ 21585 if (B>1) 21586 {branch_all = branch_all + B-1;} 21587 } 21588 else B=1; 21589 21590 return B; 21591 21592 21593 }
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 21167 of file util_sparx.cpp.
References branch_factor_0(), branch_factor_2(), branch_factor_3(), branch_factor_4(), branchMPI(), and search2().
21168 { 21169 21170 //************************************* 21171 //testing search2 21172 if (1 == 0){ 21173 cout <<"begin test search2\n"; 21174 int* matchlist = new int[J*nParts]; 21175 int* costlist = new int[J]; 21176 for (int jit = 0; jit < nParts; jit++) *(costlist+jit) = 0; 21177 Util::search2(argParts,Indices, dimClasses, nParts, K, T, matchlist,costlist,J); 21178 21179 for (int jit = 0; jit < J; jit++) { 21180 cout << *(costlist +jit)<<": "; 21181 for (int yit = 0; yit < nParts; yit++) 21182 cout << *(matchlist + jit*nParts + yit)<<","; 21183 cout <<"\n"; 21184 21185 } 21186 cout <<"end test search2\n"; 21187 int* output = new int[1]; 21188 output[0] = 1; 21189 delete [] matchlist; 21190 delete [] costlist; 21191 return output; 21192 } 21193 //************************************** 21194 21195 // Base Case: we're at a leaf, no more feasible matches possible 21196 if (curlevel > K -1){ 21197 int* output = new int[2]; 21198 output[0] = 0; 21199 output[1] = 0; 21200 return output; 21201 } 21202 21203 // branch dynamically depending on results of search 2! 21204 21205 int* matchlist = new int[J*nParts]; 21206 int* costlist = new int[J]; 21207 Util::search2(argParts, Indices, dimClasses, nParts, K, T, matchlist, costlist, J); 21208 21209 21210 // each class in the matches found by findTopLargest is encoded by the original index of the first element of the class in argPart 21211 // each match contains nParts classes, with the i-th class belonging to the i-th partition. 21212 21213 // if there are no feasible matches with cost gt T, then return 0 21214 for (int jit = 0; jit < J ; jit++){ 21215 21216 if (costlist[jit] > T) break; 21217 if (jit == J-1){ 21218 int* output = new int[2]; 21219 output[0] = 0; 21220 output[1] = 0; 21221 delete[] matchlist; 21222 delete[] costlist; 21223 return output; 21224 } 21225 } 21226 21227 21228 21229 // note that costlist and matchlist are NOT sorted by weight, and branch factor takes care of that... 21230 if (curlevel==0) branch_all = 0; 21231 21232 int nBranches = -1; 21233 21234 if (branchfunc == 0) 21235 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 21236 21237 if (branchfunc == 2) 21238 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 21239 21240 if (branchfunc == 3) 21241 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 21242 21243 if (branchfunc == 4) 21244 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 21245 21246 int* newcostlist= new int[nBranches]; 21247 int* newmatchlist = new int[nBranches*nParts]; 21248 for (int i=0; i<nBranches; i++){ 21249 newcostlist[i] = costlist[i]; 21250 for (int j=0; j< nParts; j++) 21251 newmatchlist[i*nParts + j] = matchlist[i*nParts + j]; 21252 } 21253 21254 delete[] costlist; 21255 delete[] matchlist; 21256 21257 //int* output = new int[2];//initialize to placeholder 21258 int* output = new int[2+K*nParts];//initialize to placeholder 21259 output[0] = 0; 21260 output[1] = 0; 21261 // some temporary variables 21262 int old_index; 21263 int totalcost; 21264 int nmatches; 21265 //int offset; 21266 21267 for(int i=0; i < nBranches ; i++){ 21268 21269 // consider the i-th match returned by findTopLargest 21270 //if (newcostlist[i] <= T) continue; 21271 21272 // 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. 21273 // After branch returns, compute overall cost, unmark the classes just marked as 1 again in preparation for next loop. 21274 21275 for(int j=0; j < nParts; j++){ 21276 // matchlist[i*nParts + j] is the original index of the class belonging to the j-th partition in the i-th match. 21277 old_index = newmatchlist[i*nParts + j]; 21278 argParts[Indices[j*K+old_index] + 1] = -2; 21279 } 21280 21281 21282 int* ret = Util::branchMPI(argParts, Indices, dimClasses, nParts, K, T, curlevel+1, n_guesses, LARGEST_CLASS, 21283 J, max_branching, stmult,branchfunc, LIM); 21284 21285 // first element of ret is the total cost of all the matches in ret, and second element is the number of matches in ret 21286 totalcost = newcostlist[i] + ret[0]; 21287 21288 //if (curlevel == 0) { 21289 // cout <<"totalcost*****************************************************************: "<<totalcost<<", costlist["<<i<<"]="<<newcostlist[i]<<", *ret="<<*ret<<", level: "<<curlevel<<"\n"; 21290 21291 //} 21292 if (totalcost > output[0]) // option 1 21293 { 21294 nmatches = 1 + ret[1]; 21295 //delete[] output; // get rid of the old maxreturn 21296 //output = new int[2+nmatches*nParts]; 21297 output[0] = totalcost; 21298 output[1] = nmatches; 21299 int nret = 2+(nmatches-1)*nParts; 21300 for(int iret=2; iret < nret; iret++) output[iret] = ret[iret]; 21301 for(int imax=0; imax < nParts; imax++) output[nret+imax] = newmatchlist[i*nParts + imax]; 21302 } 21303 21304 21305 delete[] ret; 21306 21307 // unmark the marked classes in preparation for the next iteration 21308 21309 for(int j=0; j < nParts; j++){ 21310 old_index = newmatchlist[i*nParts + j]; 21311 argParts[Indices[j*K+old_index] + 1] = 1; 21312 } 21313 21314 } 21315 21316 delete[] newmatchlist; 21317 delete[] newcostlist; 21318 21319 return output; 21320 }
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(), 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 6471 of file util_sparx.cpp.
References lsfit().
06472 { 06473 long int q2_dim1, q2_offset, q_dim1, q_offset, i__1, i__2; 06474 float r__1; 06475 int tmp__i; 06476 long int i__, j; 06477 --s; 06478 --res; 06479 iu -= 3; 06480 cu -= 3; 06481 --x; 06482 long int klm2d; 06483 klm2d= *k+*k+2; 06484 klm2d=klm2d+klm2d; 06485 q_dim1 = klm2d; 06486 q_offset = 1 + q_dim1; 06487 q -= q_offset; 06488 q2_dim1 = klm2d; 06489 q2_offset = 1 + q2_dim1; 06490 q2 -= q2_offset; 06491 i__2=0; 06492 i__1 = *n - 1; 06493 tmp__i=0; 06494 for (j = 1; j <= i__1; ++j) { 06495 i__2 = *k; 06496 tmp__i+=1; 06497 for (i__ = 1; i__ <= i__2; ++i__) { 06498 r__1 = float(i__ - 1) /(float) *k / (*ps * 2); 06499 q2[i__ + j * q2_dim1] = pow(r__1, tmp__i); 06500 } 06501 } 06502 for (i__ = 1; i__ <= i__2; ++i__) 06503 { q2[i__ + *n * q2_dim1] = 1.f; 06504 q2[i__ + (*n + 1) * q2_dim1] = pw[i__-1]; 06505 } 06506 vector<float> fit_res; 06507 fit_res=Util::lsfit(k, n, &klm2d, iswi, &q2[q2_offset], &q[q_offset], &x[1], &res[1], &cu[3], &s[1], &iu[3]); 06508 return fit_res; 06509 }
Dict Util::CANG | ( | float | PHI, | |
float | THETA, | |||
float | PSI | |||
) | [static] |
Definition at line 5768 of file util_sparx.cpp.
References DGR_TO_RAD, DM, and SS.
05769 { 05770 double CPHI,SPHI,CTHE,STHE,CPSI,SPSI; 05771 vector<float> DM,SS; 05772 05773 for(int i =0;i<9;i++) DM.push_back(0); 05774 05775 for(int i =0;i<6;i++) SS.push_back(0); 05776 05777 CPHI = cos(double(PHI)*DGR_TO_RAD); 05778 SPHI = sin(double(PHI)*DGR_TO_RAD); 05779 CTHE = cos(double(THETA)*DGR_TO_RAD); 05780 STHE = sin(double(THETA)*DGR_TO_RAD); 05781 CPSI = cos(double(PSI)*DGR_TO_RAD); 05782 SPSI = sin(double(PSI)*DGR_TO_RAD); 05783 05784 SS(1) = float(CPHI); 05785 SS(2) = float(SPHI); 05786 SS(3) = float(CTHE); 05787 SS(4) = float(STHE); 05788 SS(5) = float(CPSI); 05789 SS(6) = float(SPSI); 05790 05791 DM(1) = float(CPHI*CTHE*CPSI-SPHI*SPSI); 05792 DM(2) = float(SPHI*CTHE*CPSI+CPHI*SPSI); 05793 DM(3) = float(-STHE*CPSI); 05794 DM(4) = float(-CPHI*CTHE*SPSI-SPHI*CPSI); 05795 DM(5) = float(-SPHI*CTHE*SPSI+CPHI*CPSI); 05796 DM(6) = float(STHE*SPSI); 05797 DM(7) = float(STHE*CPHI); 05798 DM(8) = float(STHE*SPHI); 05799 DM(9) = float(CTHE); 05800 05801 Dict DMnSS; 05802 DMnSS["DM"] = DM; 05803 DMnSS["SS"] = SS; 05804 05805 return(DMnSS); 05806 }
Definition at line 19827 of file util_sparx.cpp.
References EMAN::EMData::cmp(), and EMAN::EMData::rot_scale_trans2D().
Referenced by twoD_fine_ali_SD().
19827 { 19828 19829 EMData *rot= new EMData(); 19830 float ccc; 19831 19832 rot = image->rot_scale_trans2D(ang, sx, sy, 1.0); 19833 ccc = -rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19834 delete rot; 19835 return ccc; 19836 }
float Util::ccc_images_G | ( | EMData * | image, | |
EMData * | refim, | |||
EMData * | mask, | |||
Util::KaiserBessel & | kb, | |||
float | ang, | |||
float | sx, | |||
float | sy | |||
) | [static] |
Definition at line 19864 of file util_sparx.cpp.
References EMAN::EMData::cmp(), pi, and EMAN::EMData::rot_scale_conv7().
Referenced by twoD_fine_ali_SD_G().
19864 { 19865 19866 EMData *rot= new EMData(); 19867 float ccc; 19868 19869 rot = image->rot_scale_conv7(static_cast<float>(ang*pi/180.0), sx, sy, kb, 1.0f); 19870 ccc = -rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19871 delete rot; 19872 return ccc; 19873 }
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 6656 of file util_sparx.cpp.
06658 { 06659 06660 long int q_dim1, q_offset, i__1, i__2; 06661 double d__1; 06662 06663 static long int i__, j; 06664 static double z__; 06665 static long int n1, n2, ia, ii, kk, in, nk, js; 06666 static double sn, zu, zv; 06667 static long int nk1, klm, nkl, jmn, jpn; 06668 static double cuv; 06669 static long int klm1, nkl1, klm2, kode, iimn, nklm, iter; 06670 static float xmin; 06671 static double xmax; 06672 static long int iout; 06673 static double xsum; 06674 static long int iineg, maxit; 06675 static double toler; 06676 static float error; 06677 static double pivot; 06678 static long int kforce, iphase; 06679 static double tpivot; 06680 06681 --s; 06682 --res; 06683 iu -= 3; 06684 cu -= 3; 06685 --x; 06686 q_dim1 = *klm2d; 06687 q_offset = 1 + q_dim1; 06688 q -= q_offset; 06689 06690 /* Function Body */ 06691 maxit = 500; 06692 kode = 0; 06693 toler = 1e-4f; 06694 iter = 0; 06695 n1 = *n + 1; 06696 n2 = *n + 2; 06697 nk = *n + *k; 06698 nk1 = nk + 1; 06699 nkl = nk + *l; 06700 nkl1 = nkl + 1; 06701 klm = *k + *l + *m; 06702 klm1 = klm + 1; 06703 klm2 = klm + 2; 06704 nklm = *n + klm; 06705 kforce = 1; 06706 iter = 0; 06707 js = 1; 06708 ia = 0; 06709 /* SET UP LABELS IN Q. */ 06710 i__1 = *n; 06711 for (j = 1; j <= i__1; ++j) { 06712 q[klm2 + j * q_dim1] = (double) j; 06713 /* L10: */ 06714 } 06715 i__1 = klm; 06716 for (i__ = 1; i__ <= i__1; ++i__) { 06717 q[i__ + n2 * q_dim1] = (double) (*n + i__); 06718 if (q[i__ + n1 * q_dim1] >= 0.f) { 06719 goto L30; 06720 } 06721 i__2 = n2; 06722 for (j = 1; j <= i__2; ++j) { 06723 q[i__ + j * q_dim1] = -q[i__ + j * q_dim1]; 06724 /* L20: */ 06725 } 06726 L30: 06727 ; 06728 } 06729 /* SET UP PHASE 1 COSTS. */ 06730 iphase = 2; 06731 i__1 = nklm; 06732 for (j = 1; j <= i__1; ++j) { 06733 cu[(j << 1) + 1] = 0.f; 06734 cu[(j << 1) + 2] = 0.f; 06735 iu[(j << 1) + 1] = 0; 06736 iu[(j << 1) + 2] = 0; 06737 /* L40: */ 06738 } 06739 if (*l == 0) { 06740 goto L60; 06741 } 06742 i__1 = nkl; 06743 for (j = nk1; j <= i__1; ++j) { 06744 cu[(j << 1) + 1] = 1.f; 06745 cu[(j << 1) + 2] = 1.f; 06746 iu[(j << 1) + 1] = 1; 06747 iu[(j << 1) + 2] = 1; 06748 /* L50: */ 06749 } 06750 iphase = 1; 06751 L60: 06752 if (*m == 0) { 06753 goto L80; 06754 } 06755 i__1 = nklm; 06756 for (j = nkl1; j <= i__1; ++j) { 06757 cu[(j << 1) + 2] = 1.f; 06758 iu[(j << 1) + 2] = 1; 06759 jmn = j - *n; 06760 if (q[jmn + n2 * q_dim1] < 0.f) { 06761 iphase = 1; 06762 } 06763 /* L70: */ 06764 } 06765 L80: 06766 if (kode == 0) { 06767 goto L150; 06768 } 06769 i__1 = *n; 06770 for (j = 1; j <= i__1; ++j) { 06771 if ((d__1 = x[j]) < 0.) { 06772 goto L90; 06773 } else if (d__1 == 0) { 06774 goto L110; 06775 } else { 06776 goto L100; 06777 } 06778 L90: 06779 cu[(j << 1) + 1] = 1.f; 06780 iu[(j << 1) + 1] = 1; 06781 goto L110; 06782 L100: 06783 cu[(j << 1) + 2] = 1.f; 06784 iu[(j << 1) + 2] = 1; 06785 L110: 06786 ; 06787 } 06788 i__1 = *k; 06789 for (j = 1; j <= i__1; ++j) { 06790 jpn = j + *n; 06791 if ((d__1 = res[j]) < 0.) { 06792 goto L120; 06793 } else if (d__1 == 0) { 06794 goto L140; 06795 } else { 06796 goto L130; 06797 } 06798 L120: 06799 cu[(jpn << 1) + 1] = 1.f; 06800 iu[(jpn << 1) + 1] = 1; 06801 if (q[j + n2 * q_dim1] > 0.f) { 06802 iphase = 1; 06803 } 06804 goto L140; 06805 L130: 06806 cu[(jpn << 1) + 2] = 1.f; 06807 iu[(jpn << 1) + 2] = 1; 06808 if (q[j + n2 * q_dim1] < 0.f) { 06809 iphase = 1; 06810 } 06811 L140: 06812 ; 06813 } 06814 L150: 06815 if (iphase == 2) { 06816 goto L500; 06817 } 06818 /* COMPUTE THE MARGINAL COSTS. */ 06819 L160: 06820 i__1 = n1; 06821 for (j = js; j <= i__1; ++j) { 06822 xsum = 0.; 06823 i__2 = klm; 06824 for (i__ = 1; i__ <= i__2; ++i__) { 06825 ii = (long int) q[i__ + n2 * q_dim1]; 06826 if (ii < 0) { 06827 goto L170; 06828 } 06829 z__ = cu[(ii << 1) + 1]; 06830 goto L180; 06831 L170: 06832 iineg = -ii; 06833 z__ = cu[(iineg << 1) + 2]; 06834 L180: 06835 xsum += q[i__ + j * q_dim1] * z__; 06836 /* 180 XSUM = XSUM + Q(I,J)*Z */ 06837 /* L190: */ 06838 } 06839 q[klm1 + j * q_dim1] = xsum; 06840 /* L200: */ 06841 } 06842 i__1 = *n; 06843 for (j = js; j <= i__1; ++j) { 06844 ii = (long int) q[klm2 + j * q_dim1]; 06845 if (ii < 0) { 06846 goto L210; 06847 } 06848 z__ = cu[(ii << 1) + 1]; 06849 goto L220; 06850 L210: 06851 iineg = -ii; 06852 z__ = cu[(iineg << 1) + 2]; 06853 L220: 06854 q[klm1 + j * q_dim1] -= z__; 06855 /* L230: */ 06856 } 06857 /* DETERMINE THE VECTOR TO ENTER THE BASIS. */ 06858 L240: 06859 xmax = 0.f; 06860 if (js > *n) { 06861 goto L490; 06862 } 06863 i__1 = *n; 06864 for (j = js; j <= i__1; ++j) { 06865 zu = q[klm1 + j * q_dim1]; 06866 ii = (long int) q[klm2 + j * q_dim1]; 06867 if (ii > 0) { 06868 goto L250; 06869 } 06870 ii = -ii; 06871 zv = zu; 06872 zu = -zu - cu[(ii << 1) + 1] - cu[(ii << 1) + 2]; 06873 goto L260; 06874 L250: 06875 zv = -zu - cu[(ii << 1) + 1] - cu[(ii << 1) + 2]; 06876 L260: 06877 if (kforce == 1 && ii > *n) { 06878 goto L280; 06879 } 06880 if (iu[(ii << 1) + 1] == 1) { 06881 goto L270; 06882 } 06883 if (zu <= xmax) { 06884 goto L270; 06885 } 06886 xmax = zu; 06887 in = j; 06888 L270: 06889 if (iu[(ii << 1) + 2] == 1) { 06890 goto L280; 06891 } 06892 if (zv <= xmax) { 06893 goto L280; 06894 } 06895 xmax = zv; 06896 in = j; 06897 L280: 06898 ; 06899 } 06900 if (xmax <= toler) { 06901 goto L490; 06902 } 06903 if (q[klm1 + in * q_dim1] == xmax) { 06904 goto L300; 06905 } 06906 i__1 = klm2; 06907 for (i__ = 1; i__ <= i__1; ++i__) { 06908 q[i__ + in * q_dim1] = -q[i__ + in * q_dim1]; 06909 /* L290: */ 06910 } 06911 q[klm1 + in * q_dim1] = xmax; 06912 /* DETERMINE THE VECTOR TO LEAVE THE BASIS. */ 06913 L300: 06914 if (iphase == 1 || ia == 0) { 06915 goto L330; 06916 } 06917 xmax = 0.f; 06918 i__1 = ia; 06919 for (i__ = 1; i__ <= i__1; ++i__) { 06920 z__ = (d__1 = q[i__ + in * q_dim1], abs(d__1)); 06921 if (z__ <= xmax) { 06922 goto L310; 06923 } 06924 xmax = z__; 06925 iout = i__; 06926 L310: 06927 ; 06928 } 06929 if (xmax <= toler) { 06930 goto L330; 06931 } 06932 i__1 = n2; 06933 for (j = 1; j <= i__1; ++j) { 06934 z__ = q[ia + j * q_dim1]; 06935 q[ia + j * q_dim1] = q[iout + j * q_dim1]; 06936 q[iout + j * q_dim1] = z__; 06937 /* L320: */ 06938 } 06939 iout = ia; 06940 --ia; 06941 pivot = q[iout + in * q_dim1]; 06942 goto L420; 06943 L330: 06944 kk = 0; 06945 i__1 = klm; 06946 for (i__ = 1; i__ <= i__1; ++i__) { 06947 z__ = q[i__ + in * q_dim1]; 06948 if (z__ <= toler) { 06949 goto L340; 06950 } 06951 ++kk; 06952 res[kk] = q[i__ + n1 * q_dim1] / z__; 06953 s[kk] = (double) i__; 06954 L340: 06955 ; 06956 } 06957 L350: 06958 if (kk > 0) { 06959 goto L360; 06960 } 06961 kode = 2; 06962 goto L590; 06963 L360: 06964 xmin = static_cast<float>( res[1] ); 06965 iout = (long int) s[1]; 06966 j = 1; 06967 if (kk == 1) { 06968 goto L380; 06969 } 06970 i__1 = kk; 06971 for (i__ = 2; i__ <= i__1; ++i__) { 06972 if (res[i__] >= xmin) { 06973 goto L370; 06974 } 06975 j = i__; 06976 xmin = static_cast<float>( res[i__] ); 06977 iout = (long int) s[i__]; 06978 L370: 06979 ; 06980 } 06981 res[j] = res[kk]; 06982 s[j] = s[kk]; 06983 L380: 06984 --kk; 06985 pivot = q[iout + in * q_dim1]; 06986 ii = (long int) q[iout + n2 * q_dim1]; 06987 if (iphase == 1) { 06988 goto L400; 06989 } 06990 if (ii < 0) { 06991 goto L390; 06992 } 06993 if (iu[(ii << 1) + 2] == 1) { 06994 goto L420; 06995 } 06996 goto L400; 06997 L390: 06998 iineg = -ii; 06999 if (iu[(iineg << 1) + 1] == 1) { 07000 goto L420; 07001 } 07002 /* 400 II = IABS(II) */ 07003 L400: 07004 ii = abs(ii); 07005 cuv = cu[(ii << 1) + 1] + cu[(ii << 1) + 2]; 07006 if (q[klm1 + in * q_dim1] - pivot * cuv <= toler) { 07007 goto L420; 07008 } 07009 /* BYPASS INTERMEDIATE VERTICES. */ 07010 i__1 = n1; 07011 for (j = js; j <= i__1; ++j) { 07012 z__ = q[iout + j * q_dim1]; 07013 q[klm1 + j * q_dim1] -= z__ * cuv; 07014 q[iout + j * q_dim1] = -z__; 07015 /* L410: */ 07016 } 07017 q[iout + n2 * q_dim1] = -q[iout + n2 * q_dim1]; 07018 goto L350; 07019 /* GAUSS-JORDAN ELIMINATION. */ 07020 L420: 07021 if (iter < maxit) { 07022 goto L430; 07023 } 07024 kode = 3; 07025 goto L590; 07026 L430: 07027 ++iter; 07028 i__1 = n1; 07029 for (j = js; j <= i__1; ++j) { 07030 if (j != in) { 07031 q[iout + j * q_dim1] /= pivot; 07032 } 07033 /* L440: */ 07034 } 07035 /* IF PERMITTED, USE SUBROUTINE COL OF THE DESCRIPTION */ 07036 /* SECTION AND REPLACE THE FOLLOWING SEVEN STATEMENTS DOWN */ 07037 /* TO AND INCLUDING STATEMENT NUMBER 460 BY.. */ 07038 /* DO 460 J=JS,N1 */ 07039 /* IF(J .EQ. IN) GO TO 460 */ 07040 /* Z = -Q(IOUT,J) */ 07041 /* CALL COL(Q(1,J), Q(1,IN), Z, IOUT, KLM1) */ 07042 /* 460 CONTINUE */ 07043 i__1 = n1; 07044 for (j = js; j <= i__1; ++j) { 07045 if (j == in) { 07046 goto L460; 07047 } 07048 z__ = -q[iout + j * q_dim1]; 07049 i__2 = klm1; 07050 for (i__ = 1; i__ <= i__2; ++i__) { 07051 if (i__ != iout) { 07052 q[i__ + j * q_dim1] += z__ * q[i__ + in * q_dim1]; 07053 } 07054 /* L450: */ 07055 } 07056 L460: 07057 ; 07058 } 07059 tpivot = -pivot; 07060 i__1 = klm1; 07061 for (i__ = 1; i__ <= i__1; ++i__) { 07062 if (i__ != iout) { 07063 q[i__ + in * q_dim1] /= tpivot; 07064 } 07065 /* L470: */ 07066 } 07067 q[iout + in * q_dim1] = 1.f / pivot; 07068 z__ = q[iout + n2 * q_dim1]; 07069 q[iout + n2 * q_dim1] = q[klm2 + in * q_dim1]; 07070 q[klm2 + in * q_dim1] = z__; 07071 ii = (long int) abs(z__); 07072 if (iu[(ii << 1) + 1] == 0 || iu[(ii << 1) + 2] == 0) { 07073 goto L240; 07074 } 07075 i__1 = klm2; 07076 for (i__ = 1; i__ <= i__1; ++i__) { 07077 z__ = q[i__ + in * q_dim1]; 07078 q[i__ + in * q_dim1] = q[i__ + js * q_dim1]; 07079 q[i__ + js * q_dim1] = z__; 07080 /* L480: */ 07081 } 07082 ++js; 07083 goto L240; 07084 /* TEST FOR OPTIMALITY. */ 07085 L490: 07086 if (kforce == 0) { 07087 goto L580; 07088 } 07089 if (iphase == 1 && q[klm1 + n1 * q_dim1] <= toler) { 07090 goto L500; 07091 } 07092 kforce = 0; 07093 goto L240; 07094 /* SET UP PHASE 2 COSTS. */ 07095 L500: 07096 iphase = 2; 07097 i__1 = nklm; 07098 for (j = 1; j <= i__1; ++j) { 07099 cu[(j << 1) + 1] = 0.f; 07100 cu[(j << 1) + 2] = 0.f; 07101 /* L510: */ 07102 } 07103 i__1 = nk; 07104 for (j = n1; j <= i__1; ++j) { 07105 cu[(j << 1) + 1] = 1.f; 07106 cu[(j << 1) + 2] = 1.f; 07107 /* L520: */ 07108 } 07109 i__1 = klm; 07110 for (i__ = 1; i__ <= i__1; ++i__) { 07111 ii = (long int) q[i__ + n2 * q_dim1]; 07112 if (ii > 0) { 07113 goto L530; 07114 } 07115 ii = -ii; 07116 if (iu[(ii << 1) + 2] == 0) { 07117 goto L560; 07118 } 07119 cu[(ii << 1) + 2] = 0.f; 07120 goto L540; 07121 L530: 07122 if (iu[(ii << 1) + 1] == 0) { 07123 goto L560; 07124 } 07125 cu[(ii << 1) + 1] = 0.f; 07126 L540: 07127 ++ia; 07128 i__2 = n2; 07129 for (j = 1; j <= i__2; ++j) { 07130 z__ = q[ia + j * q_dim1]; 07131 q[ia + j * q_dim1] = q[i__ + j * q_dim1]; 07132 q[i__ + j * q_dim1] = z__; 07133 /* L550: */ 07134 } 07135 L560: 07136 ; 07137 } 07138 goto L160; 07139 L570: 07140 if (q[klm1 + n1 * q_dim1] <= toler) { 07141 goto L500; 07142 } 07143 kode = 1; 07144 goto L590; 07145 L580: 07146 if (iphase == 1) { 07147 goto L570; 07148 } 07149 /* PREPARE OUTPUT. */ 07150 kode = 0; 07151 L590: 07152 xsum = 0.; 07153 i__1 = *n; 07154 for (j = 1; j <= i__1; ++j) { 07155 x[j] = 0.f; 07156 /* L600: */ 07157 } 07158 i__1 = klm; 07159 for (i__ = 1; i__ <= i__1; ++i__) { 07160 res[i__] = 0.f; 07161 /* L610: */ 07162 } 07163 i__1 = klm; 07164 for (i__ = 1; i__ <= i__1; ++i__) { 07165 ii = (long int) q[i__ + n2 * q_dim1]; 07166 sn = 1.f; 07167 if (ii > 0) { 07168 goto L620; 07169 } 07170 ii = -ii; 07171 sn = -1.f; 07172 L620: 07173 if (ii > *n) { 07174 goto L630; 07175 } 07176 x[ii] = sn * q[i__ + n1 * q_dim1]; 07177 goto L640; 07178 L630: 07179 iimn = ii - *n; 07180 res[iimn] = sn * q[i__ + n1 * q_dim1]; 07181 if (ii >= n1 && ii <= nk) { 07182 xsum += q[i__ + n1 * q_dim1]; 07183 } 07184 L640: 07185 ; 07186 } 07187 error = (float)xsum; 07188 return; 07189 }
vector< float > Util::cluster_equalsize | ( | EMData * | d | ) | [static] |
Definition at line 20471 of file util_sparx.cpp.
References dm, EMAN::EMData::get_xsize(), nx, and sqrt().
20471 { 20472 // WORKS ONLY FOR NUMBER OF OBJECTS N=l^2 !! 20473 int nx = d->get_xsize(); 20474 int N = 1 + int((sqrt(1.0 + 8.0*nx)-1.0)/2.0); 20475 int K = N/2; 20476 vector<float> group(N); 20477 if(N*(N-1)/2 != nx) { 20478 //print " incorrect dimension" 20479 return group;} 20480 //bool active[N]; //this does not compile in VS2005. --Grant Tang 20481 bool * active = new bool[N]; 20482 for(int i=0; i<N; i++) active[i] = true; 20483 20484 float dm, qd; 20485 int ppi = 0, ppj = 0; 20486 for(int k=0; k<K; k++) { 20487 // find pairs of most similiar objects among active 20488 //cout<<" k "<<k<<endl; 20489 dm = 1.0e23f; 20490 for(int i=1; i<N; i++) { 20491 if(active[i]) { 20492 for(int j=0; j<i; j++) { 20493 if(active[j]) { 20494 qd = (*d)(i*(i - 1)/2 + j); 20495 if(qd < dm) { 20496 dm = qd; 20497 ppi = i; 20498 ppj = j; 20499 } 20500 } 20501 } 20502 } 20503 } 20504 group[2*k] = float(ppi); 20505 group[1+2*k] = float(ppj); 20506 active[ppi] = false; 20507 active[ppj] = false; 20508 } 20509 20510 delete [] active; 20511 active = NULL; 20512 return group; 20513 }
vector< float > Util::cluster_pairwise | ( | EMData * | d, | |
int | K, | |||
float | T, | |||
float | F | |||
) | [static] |
Definition at line 20263 of file util_sparx.cpp.
References assign, cent, dt, get_irand(), EMAN::EMData::get_xsize(), mono(), nx, q, and sqrt().
20263 { 20264 int nx = d->get_xsize(); 20265 int N = 1 + int((sqrt(1.0 + 8.0*nx)-1.0)/2.0); 20266 vector<float> out(N+K+2); 20267 if(N*(N-1)/2 != nx) { 20268 //print " incorrect dimension" 20269 return out;} 20270 // assign random objects as centers 20271 for(int i=0; i<N; i++) assign(i) = float(i); 20272 // shuffle 20273 for(int i=0; i<N; i++) { 20274 int j = Util::get_irand(0,N-1); 20275 float temp = assign(i); 20276 assign(i) = assign(j); 20277 assign(j) = temp; 20278 } 20279 for(int k=0; k<K; k++) cent(k) = float(assign(k)); 20280 //for(int k=0; k<K; k++) cout<<cent(k)<<" ";cout<<endl; 20281 // 20282 for(int i=0; i<N; i++) assign(i) = 0.0f; 20283 float qm, dispold = 1.1e22f, disp = 1.0e22f, na=0.0f; 20284 bool change = true; 20285 int it = -1; 20286 int ct = -1; 20287 while ((change && disp < dispold) || ct > 0) { 20288 20289 change = false; 20290 dispold = disp; 20291 it++; 20292 20293 // dispersion is a sum of distance from objects to object center 20294 disp = 0.0f; 20295 ct = 0; 20296 for(int i=0; i<N; i++) { 20297 qm = 1.0e23f; 20298 for(int k=0; k<K; k++) { 20299 if(float(i) == cent(k)) { 20300 qm = 0.0f; 20301 na = (float)k; 20302 } else { 20303 float dt = (*d)(mono(i,int(cent(k)))); 20304 if(dt < qm) { 20305 qm = dt; 20306 na = (float)k; 20307 } 20308 } 20309 } 20310 20311 20312 // Simulated annealing 20313 if(exp(-1.0/float(T)) > Util::get_irand(1,1000)/1000.0) { 20314 na = (float)(Util::get_irand(0, K)); 20315 qm = (*d)(mono(i,int(na))); 20316 ct++; 20317 } 20318 20319 disp += qm; 20320 20321 if(na != assign(i)) { 20322 assign(i) = na; 20323 change = true; 20324 } 20325 } 20326 20327 //cout<<"Iteration: "<<it<< " disp " <<disp << " T " << T << " disturb " << ct << endl; 20328 T = T*F; 20329 20330 //for(int k=0; k<N; k++) cout<<assign(k)<<" ";cout<<endl; 20331 //print disp 20332 //print assign 20333 // find centers 20334 for(int k=0; k<K; k++) { 20335 qm = 1.0e23f; 20336 for(int i=0; i<N; i++) { 20337 if(assign(i) == float(k)) { 20338 float q = 0.0; 20339 for(int j=0; j<N; j++) { 20340 if(assign(j) == float(k)) { 20341 //it cannot be the same object 20342 if(i != j) q += (*d)(mono(i,j)); 20343 //cout<<q<<" "<<i<<" "<<j<<" "<<k<<endl;} 20344 } 20345 } 20346 if(q < qm) { 20347 //cout<<qm<<" "<<q<<" "<<i<<" "<<k<<endl; 20348 qm = q; 20349 cent(k) = float(i); 20350 } 20351 } 20352 } 20353 } 20354 //for(int k=0; k<K; k++) cout<<cent(k)<<" ";cout<<endl;cout<<disp<<endl; 20355 } 20356 out[N+K] = disp; 20357 out[N+K+1] = float(it); 20358 return out; 20359 }
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 5038 of file util_sparx.cpp.
05038 { 05039 double res = 0; 05040 double buf = 0; 05041 float* line_1; 05042 float* line_2; 05043 int i, n, ind; 05044 int lnlen = data[0]->get_xsize(); 05045 for (n=0; n<n_lines; ++n) { 05046 ind = n*2; 05047 line_1 = data[seq[ind]]->get_data() + com[ind] * lnlen; 05048 line_2 = data[seq[ind+1]]->get_data() + com[ind+1] *lnlen; 05049 buf = 0; 05050 for (i=0; i<lnlen; ++i) { 05051 buf += (line_1[i]-line_2[i])*(line_1[i]-line_2[i]); 05052 } 05053 res += buf * weights[n]; 05054 } 05055 05056 return res; 05057 05058 }
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 4815 of file util_sparx.cpp.
References deg_rad.
04815 { 04816 int nb_ori = Ori.size() / 4; 04817 int i, ind; 04818 float ph, th, ps; 04819 double cph, cth, cps, sph, sth, sps; 04820 vector<double> Rot(nb_ori*9); 04821 for (i=0; i<nb_ori; ++i){ 04822 ind = i*4; 04823 // spider convention phi=psi-90, psi=phi+90 04824 ph = Ori[ind+2]-90; 04825 th = Ori[ind+1]; 04826 ps = Ori[ind]+90; 04827 ph *= deg_rad; 04828 th *= deg_rad; 04829 ps *= deg_rad; 04830 // pre-calculate some trigo stuffs 04831 cph = cos(ph); 04832 cth = cos(th); 04833 cps = cos(ps); 04834 sph = sin(ph); 04835 sth = sin(th); 04836 sps = sin(ps); 04837 // fill rotation matrix 04838 ind = i*9; 04839 Rot[ind] = cph*cps-cth*sps*sph; 04840 Rot[ind+1] = cph*sps+cth*cps*sph; 04841 Rot[ind+2] = sth*sph; 04842 Rot[ind+3] = -sph*cps-cth*sps*cph; 04843 Rot[ind+4] = -sph*sps+cth*cps*cph; 04844 Rot[ind+5] = sth*cph; 04845 Rot[ind+6] = sth*sps; 04846 Rot[ind+7] = -sth*cps; 04847 Rot[ind+8] = cth; 04848 } 04849 04850 return Rot; 04851 }
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 4983 of file util_sparx.cpp.
References deg_rad, norm(), nx, ny, rad_deg, and sqrt().
04983 { 04984 // seq is the pairwise index ij: 0, 1, 0, 2, 0, 3, 1, 2, 1, 3, 2, 3 04985 vector<double> cml(2*nlines); // [phi, theta] / line 04986 float ph1, th1; 04987 float ph2, th2; 04988 double nx, ny, nz; 04989 double norm; 04990 double sth1=0, sph1=0, cth1=0, cph1=0; 04991 double sth2, sph2, cth2, cph2; 04992 int l, ind, c; 04993 int mem = -1; 04994 for (l=0; l<nlines; ++l){ 04995 c = 2*l; 04996 if (seq[c]!=mem){ 04997 mem = seq[c]; 04998 ind = 4*seq[c]; 04999 ph1 = Ori[ind]*deg_rad; 05000 th1 = Ori[ind+1]*deg_rad; 05001 sth1 = sin(th1); 05002 sph1 = sin(ph1); 05003 cth1 = cos(th1); 05004 cph1 = cos(ph1); 05005 } 05006 ind = 4*seq[c+1]; 05007 ph2 = Ori[ind]*deg_rad; 05008 th2 = Ori[ind+1]*deg_rad; 05009 sth2 = sin(th2); 05010 cth2 = cos(th2); 05011 sph2 = sin(ph2); 05012 cph2 = cos(ph2); 05013 // cross product 05014 nx = sth1*cph1*cth2 - cth1*sth2*cph2; 05015 ny = cth1*sth2*sph2 - cth2*sth1*sph1; 05016 nz = sth1*sph1*sth2*cph2 - sth1*cph1*sth2*sph2; 05017 norm = sqrt(nx*nx+ny*ny+nz*nz); 05018 nx /= norm; 05019 ny /= norm; 05020 nz /= norm; 05021 // apply mirror if need 05022 if (nz<0) {nx=-nx; ny=-ny; nz=-nz;} 05023 // compute theta and phi 05024 cml[c+1] = acos(nz); 05025 if (cml[c+1] == 0) {cml[c] = 0;} 05026 else { 05027 cml[c+1] *= rad_deg; 05028 if (cml[c+1] > 89.99) {cml[c+1] = 89.99;} // this fix some pb in Voronoi 05029 cml[c] = rad_deg * atan2(nx, ny); 05030 cml[c] = fmod(360 + cml[c], 360); 05031 05032 } 05033 } 05034 05035 return cml; 05036 }
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 4884 of file util_sparx.cpp.
References abs, b, nint180(), and rad_deg.
04884 { 04885 vector<int> com(2*(n_prj - 1)); 04886 int a = i_prj*9; 04887 int i, b, c; 04888 int n1=0, n2=0; 04889 float vmax = 1 - 1.0e-6f; 04890 double r11, r12, r13, r23, r31, r32, r33; 04891 04892 c = 0; 04893 for (i=0; i<n_prj; ++i){ 04894 if (i!=i_prj){ 04895 b = i*9; 04896 // this is equivalent to R = A*B' 04897 r11 = Rot[a]*Rot[b]+Rot[a+1]*Rot[b+1]+Rot[a+2]*Rot[b+2]; 04898 r12 = Rot[a]*Rot[b+3]+Rot[a+1]*Rot[b+4]+Rot[a+2]*Rot[b+5]; 04899 r13 = Rot[a]*Rot[b+6]+Rot[a+1]*Rot[b+7]+Rot[a+2]*Rot[b+8]; 04900 r23 = Rot[a+3]*Rot[b+6]+Rot[a+4]*Rot[b+7]+Rot[a+5]*Rot[b+8]; 04901 r31 = Rot[a+6]*Rot[b]+Rot[a+7]*Rot[b+1]+Rot[a+8]*Rot[b+2]; 04902 r32 = Rot[a+6]*Rot[b+3]+Rot[a+7]*Rot[b+4]+Rot[a+8]*Rot[b+5]; 04903 r33 = Rot[a+6]*Rot[b+6]+Rot[a+7]*Rot[b+7]+Rot[a+8]*Rot[b+8]; 04904 if (r33 > vmax) { 04905 n2 = 270; 04906 n1 = 270 + nint180((float)(rad_deg*atan2(r12, r11))); 04907 } 04908 else if (r33 < -vmax) { 04909 n2 = 270; 04910 n1 = 270 - nint180((float)(rad_deg*atan2(r12, r11))); 04911 } else { 04912 n2 = nint180((float)(rad_deg*atan2(r31, -r32))); 04913 n1 = nint180((float)(rad_deg*atan2(r13, r23))); 04914 if (n1 < 0) {n1 += 360;} 04915 if (n2 <= 0) {n2 = abs(n2);} 04916 else {n2 = 360 - n2;} 04917 } 04918 04919 if (n1 >= 360){n1 = n1 % 360;} 04920 if (n2 >= 360){n2 = n2 % 360;} 04921 04922 // store common-lines 04923 b = c*2; 04924 com[b] = n1; 04925 com[b+1] = n2; 04926 ++c; 04927 } 04928 } 04929 04930 return com; 04931 04932 }
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 4934 of file util_sparx.cpp.
References abs, b, nint180(), and rad_deg.
04934 { 04935 vector<int> com(2*n_lines); 04936 int a=0, b, c, l; 04937 int n1=0, n2=0, mem=-1; 04938 float vmax = 1 - 1.0e-6f; 04939 double r11, r12, r13, r23, r31, r32, r33; 04940 c = 0; 04941 for (l=0; l<n_lines; ++l){ 04942 c = 2*l; 04943 if (seq[c]!=mem){ 04944 mem = seq[c]; 04945 a = seq[c]*9; 04946 } 04947 b = seq[c+1]*9; 04948 04949 // this is equivalent to R = A*B' 04950 r11 = Rot[a]*Rot[b]+Rot[a+1]*Rot[b+1]+Rot[a+2]*Rot[b+2]; 04951 r12 = Rot[a]*Rot[b+3]+Rot[a+1]*Rot[b+4]+Rot[a+2]*Rot[b+5]; 04952 r13 = Rot[a]*Rot[b+6]+Rot[a+1]*Rot[b+7]+Rot[a+2]*Rot[b+8]; 04953 r23 = Rot[a+3]*Rot[b+6]+Rot[a+4]*Rot[b+7]+Rot[a+5]*Rot[b+8]; 04954 r31 = Rot[a+6]*Rot[b]+Rot[a+7]*Rot[b+1]+Rot[a+8]*Rot[b+2]; 04955 r32 = Rot[a+6]*Rot[b+3]+Rot[a+7]*Rot[b+4]+Rot[a+8]*Rot[b+5]; 04956 r33 = Rot[a+6]*Rot[b+6]+Rot[a+7]*Rot[b+7]+Rot[a+8]*Rot[b+8]; 04957 if (r33 > vmax) { 04958 n2 = 270; 04959 n1 = 270 + nint180((float)(rad_deg*atan2(r12, r11))); 04960 } 04961 else if (r33 < -vmax) { 04962 n2 = 270; 04963 n1 = 270 - nint180((float)(rad_deg*atan2(r12, r11))); 04964 } else { 04965 n2 = nint180((float)(rad_deg*atan2(r31, -r32))); 04966 n1 = nint180((float)(rad_deg*atan2(r13, r23))); 04967 if (n1 < 0) {n1 += 360;} 04968 if (n2 <= 0) {n2 = abs(n2);} 04969 else {n2 = 360 - n2;} 04970 } 04971 if (n1 >= 360){n1 = n1 % 360;} 04972 if (n2 >= 360){n2 = n2 % 360;} 04973 04974 // store common-lines 04975 com[c] = n1; 04976 com[c+1] = n2; 04977 } 04978 04979 return com; 04980 04981 }
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 4797 of file util_sparx.cpp.
References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), nx, and EMAN::EMData::update().
04797 { 04798 int j; 04799 int nx = sino->get_xsize(); 04800 int i = nx * pos_line; 04801 float r1, r2; 04802 float *line_ptr = line->get_data(); 04803 float *sino_ptr = sino->get_data(); 04804 for (j=ilf;j<=ihf; j += 2) { 04805 r1 = line_ptr[j]; 04806 r2 = line_ptr[j + 1]; 04807 sino_ptr[i + j - ilf] = r1; 04808 sino_ptr[i + j - ilf + 1] = r2; 04809 sino_ptr[i + nx * nblines + j - ilf] = r1; 04810 sino_ptr[i + nx * nblines + j - ilf + 1] = -r2; 04811 } 04812 sino->update(); 04813 }
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 5060 of file util_sparx.cpp.
05061 { 05062 // res: [best_disc, best_ipsi] 05063 // seq: pairwise indexes ij, 0, 1, 0, 2, 0, 3, 1, 2, 1, 3, 2, 3 05064 // iw : index to know where is the weight for the common-lines on the current projection in the all weights, [12, 4, 2, 7] 05065 vector<double> res(2); 05066 int lnlen = data[0]->get_xsize(); 05067 int end = 2*(n_prj-1); 05068 double disc, buf, bdisc, tmp; 05069 int n, i, ipsi, ind, bipsi, c; 05070 float* line_1; 05071 float* line_2; 05072 bdisc = 1.0e6; 05073 bipsi = -1; 05074 // loop psi 05075 for(ipsi=0; ipsi<n_psi; ipsi += d_psi) { 05076 // discrepancy 05077 disc = 0; 05078 c = 0; 05079 for (n=0; n<n_prj; ++n) { 05080 if(n!=iprj) { 05081 ind = 2*c; 05082 line_1 = data[iprj]->get_data() + com[ind] * lnlen; 05083 line_2 = data[n]->get_data() + com[ind+1] * lnlen; 05084 buf = 0; 05085 for (i=0; i<lnlen; ++i) { 05086 tmp = line_1[i]-line_2[i]; 05087 buf += tmp*tmp; 05088 } 05089 disc += buf * weights[iw[c]]; 05090 ++c; 05091 } 05092 } 05093 // select the best value 05094 if (disc <= bdisc) { 05095 bdisc = disc; 05096 bipsi = ipsi; 05097 } 05098 // update common-lines 05099 for (i=0; i<end; i+=2){ 05100 com[i] += d_psi; 05101 if (com[i] >= n_psi) com[i] = com[i] - n_psi; 05102 } 05103 } 05104 res[0] = bdisc; 05105 res[1] = float(bipsi); 05106 05107 return res; 05108 }
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 5110 of file util_sparx.cpp.
05111 { 05112 // res: [best_disc, best_ipsi] 05113 // seq: pairwise indexes ij, 0, 1, 0, 2, 0, 3, 1, 2, 1, 3, 2, 3 05114 // iw : index to know where is the weight for the common-lines on the current projection in the all weights, [12, 4, 2, 7] 05115 vector<double> res(2); 05116 int lnlen = data[0]->get_xsize(); 05117 int end = 2*(n_prj-1); 05118 double disc, buf, bdisc, tmp; 05119 int n, i, ipsi, ind, bipsi, c; 05120 float* line_1; 05121 float* line_2; 05122 bdisc = 1.0e6; 05123 bipsi = -1; 05124 // loop psi 05125 for(ipsi=0; ipsi<n_psi; ipsi += d_psi) { 05126 // discrepancy 05127 disc = 0; 05128 c = 0; 05129 for (n=0; n<n_prj; ++n) { 05130 if(n!=iprj) { 05131 ind = 2*c; 05132 line_1 = data[iprj]->get_data() + com[ind] * lnlen; 05133 line_2 = data[n]->get_data() + com[ind+1] * lnlen; 05134 buf = 0; 05135 for (i=0; i<lnlen; ++i) { 05136 tmp = line_1[i]-line_2[i]; 05137 buf += tmp*tmp; 05138 } 05139 disc += buf; 05140 ++c; 05141 } 05142 } 05143 // select the best value 05144 if (disc <= bdisc) { 05145 bdisc = disc; 05146 bipsi = ipsi; 05147 } 05148 // update common-lines 05149 for (i=0; i<end; i+=2){ 05150 com[i] += d_psi; 05151 if (com[i] >= n_psi) com[i] = com[i] - n_psi; 05152 } 05153 } 05154 res[0] = bdisc; 05155 res[1] = float(bipsi); 05156 05157 return res; 05158 }
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 4853 of file util_sparx.cpp.
References deg_rad.
04853 { 04854 float ph, ps; 04855 double cph, cth, cps, sph, sth, sps; 04856 int ind = iprj*9; 04857 // spider convention phi=psi-90, psi=phi+90 04858 ph = nps-90; 04859 ps = nph+90; 04860 ph *= deg_rad; 04861 th *= deg_rad; 04862 ps *= deg_rad; 04863 // pre-calculate some trigo stuffs 04864 cph = cos(ph); 04865 cth = cos(th); 04866 cps = cos(ps); 04867 sph = sin(ph); 04868 sth = sin(th); 04869 sps = sin(ps); 04870 // fill rotation matrix 04871 Rot[ind] = (float)(cph*cps-cth*sps*sph); 04872 Rot[ind+1] = (float)(cph*sps+cth*cps*sph); 04873 Rot[ind+2] = (float)(sth*sph); 04874 Rot[ind+3] = (float)(-sph*cps-cth*sps*cph); 04875 Rot[ind+4] = (float)(-sph*sps+cth*cps*cph); 04876 Rot[ind+5] = (float)(sth*cph); 04877 Rot[ind+6] = (float)(sth*sps); 04878 Rot[ind+7] = (float)(-sth*cps); 04879 Rot[ind+8] = (float)(cth); 04880 04881 return Rot; 04882 }
vector< double > Util::cml_weights | ( | const vector< float > & | cml | ) | [static] |
Definition at line 4707 of file util_sparx.cpp.
References Assert, PI2, and vrdg().
04707 { 04708 static const int NBIN = 100; 04709 int nline=cml.size()/2; 04710 vector<double> weights(nline); 04711 04712 vector<ori_t> angs(nline); 04713 for( int i=0; i < nline; ++i ) { 04714 angs[i].iphi = int( NBIN*cml[2*i] ); 04715 angs[i].itht = int( NBIN*cml[2*i+1] ); 04716 if( angs[i].itht == 180*NBIN ) angs[i].itht = 0; 04717 angs[i].id = i; 04718 } 04719 04720 //std::cout << "# of angs: " << angs.size() << std::endl; 04721 04722 std::sort( angs.begin(), angs.end(), cmpang() ); 04723 04724 vector<float> newphi; 04725 vector<float> newtht; 04726 vector< vector<int> > indices; 04727 04728 int curt_iphi = -1; 04729 int curt_itht = -1; 04730 for(unsigned int i=0 ;i < angs.size(); ++i ) { 04731 if( angs[i].iphi==curt_iphi && angs[i].itht==curt_itht ) { 04732 Assert( indices.size() > 0 ); 04733 indices.back().push_back(angs[i].id); 04734 } else { 04735 curt_iphi = angs[i].iphi; 04736 curt_itht = angs[i].itht; 04737 04738 newphi.push_back( float(curt_iphi)/NBIN ); 04739 newtht.push_back( float(curt_itht)/NBIN ); 04740 indices.push_back( vector<int>(1,angs[i].id) ); 04741 } 04742 } 04743 04744 //std::cout << "# of indpendent ang: " << newphi.size() << std::endl; 04745 04746 04747 int num_agl = newphi.size(); 04748 04749 if(num_agl>2) { 04750 vector<double> w=Util::vrdg(newphi, newtht); 04751 04752 Assert( w.size()==newphi.size() ); 04753 Assert( indices.size()==newphi.size() ); 04754 04755 for(unsigned int i=0; i < newphi.size(); ++i ) { 04756 /* 04757 std::cout << "phi,tht,w,n: "; 04758 std::cout << boost::format( "%10.3f" ) % newphi[i] << " "; 04759 std::cout << boost::format( "%10.3f" ) % newtht[i] << " "; 04760 std::cout << boost::format( "%8.6f" ) % w[i] << " "; 04761 std::cout << indices[i].size() << "("; 04762 */ 04763 04764 for(unsigned int j=0; j < indices[i].size(); ++j ) { 04765 int id = indices[i][j]; 04766 weights[id] = w[i]/indices[i].size(); 04767 //std::cout << id << " "; 04768 } 04769 04770 //std::cout << ")" << std::endl; 04771 04772 } 04773 } else { 04774 cout<<"warning in Util.cml_weights"<<endl; 04775 double val = PI2/float(nline); 04776 for(int i=0; i<nline; i++) weights[i]=val; 04777 } 04778 04779 return weights; 04780 04781 }
Definition at line 7327 of file util_sparx.cpp.
References EMAN::Util::tmpstruct::theta1.
Referenced by hsortd().
Definition at line 7332 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 5518 of file util_sparx.cpp.
Referenced by cyclicshift(), and slicereverse().
05518 { 05519 float* tmp = new float[nx]; 05520 int n = (end - beg)/nx; 05521 int nhalf = n/2; 05522 for (int i = 0; i < nhalf; i++) { 05523 // swap col i and col n-1-i 05524 memcpy(tmp, beg+i*nx, nx*sizeof(float)); 05525 memcpy(beg+i*nx, beg+(n-1-i)*nx, nx*sizeof(float)); 05526 memcpy(beg+(n-1-i)*nx, tmp, nx*sizeof(float)); 05527 } 05528 delete[] tmp; 05529 }
Definition at line 6210 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().
06211 { 06212 /*********** 06213 ***get the size of the image for validation purpose 06214 **************/ 06215 int nx = image->get_xsize(),ny = image->get_ysize(),nz = image->get_zsize(); //Aren't these implied? Please check and let me know, PAP. 06216 /******** 06217 ***Exception Handle 06218 *************/ 06219 if(nx != mask->get_xsize() || ny != mask->get_ysize() || nz != mask->get_zsize()) 06220 throw ImageDimensionException("The dimension of the image does not match the dimension of the mask!"); 06221 06222 size_t i, size = (size_t)nx*ny*nz; 06223 06224 float* img_ptr = image->get_data(); 06225 float* mask_ptr = mask->get_data(); 06226 06227 int ln=0; //length of the output image = number of points under the mask. 06228 for(i = 0;i < size;i++) if(mask_ptr[i] > 0.5f) ln++; 06229 06230 EMData* new_image = new EMData(); 06231 new_image->set_size(ln,1,1); /* set size of the new image */ 06232 float *new_ptr = new_image->get_data(); 06233 06234 ln=-1; 06235 for(i = 0;i < size;i++){ 06236 if(mask_ptr[i] > 0.5f) { 06237 ln++; 06238 new_ptr[ln]=img_ptr[i]; 06239 } 06240 } 06241 06242 return new_image; 06243 }
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 6339 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, and ssyev_().
06340 { 06341 // n size of the covariance/correlation matrix 06342 // covmat --- covariance/correlation matrix (n by n) 06343 // eigval --- returns eigenvalues 06344 // eigvec --- returns eigenvectors 06345 06346 ENTERFUNC; 06347 06348 int i; 06349 06350 // make a copy of covmat so that it will not be overwritten 06351 for ( i = 0 ; i < n * n ; i++ ) eigvec[i] = covmat[i]; 06352 06353 char NEEDV = 'V'; 06354 char UPLO = 'U'; 06355 int lwork = -1; 06356 int info = 0; 06357 float *work, wsize; 06358 06359 // query to get optimal workspace 06360 ssyev_(&NEEDV, &UPLO, &n, eigvec, &n, eigval, &wsize, &lwork, &info); 06361 lwork = (int)wsize; 06362 06363 work = (float *)calloc(lwork, sizeof(float)); 06364 // calculate eigs 06365 ssyev_(&NEEDV, &UPLO, &n, eigvec, &n, eigval, work, &lwork, &info); 06366 free(work); 06367 EXITFUNC; 06368 return info; 06369 }
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 6371 of file util_sparx.cpp.
References coveig(), covmat, eigval, eigvec, ENTERFUNC, EXITFUNC, and status.
06372 { 06373 06374 ENTERFUNC; 06375 int len = covmatpy.size(); 06376 float *eigvec; 06377 float *eigval; 06378 float *covmat; 06379 int status = 0; 06380 eigval = (float*)calloc(ncov,sizeof(float)); 06381 eigvec = (float*)calloc(ncov*ncov,sizeof(float)); 06382 covmat = (float*)calloc(ncov*ncov, sizeof(float)); 06383 06384 const float *covmat_ptr; 06385 covmat_ptr = &covmatpy[0]; 06386 for(int i=0;i<len;i++){ 06387 covmat[i] = covmat_ptr[i]; 06388 } 06389 06390 status = Util::coveig(ncov, covmat, eigval, eigvec); 06391 06392 vector<float> eigval_py(ncov); 06393 const float *eigval_ptr; 06394 eigval_ptr = &eigval[0]; 06395 for(int i=0;i<ncov;i++){ 06396 eigval_py[i] = eigval_ptr[i]; 06397 } 06398 06399 vector<float> eigvec_py(ncov*ncov); 06400 const float *eigvec_ptr; 06401 eigvec_ptr = &eigvec[0]; 06402 for(int i=0;i<ncov*ncov;i++){ 06403 eigvec_py[i] = eigvec_ptr[i]; 06404 } 06405 06406 Dict res; 06407 res["eigval"] = eigval_py; 06408 res["eigvec"] = eigvec_py; 06409 06410 EXITFUNC; 06411 return res; 06412 }
Definition at line 3169 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.
03169 { 03170 // neg = 0 straight, neg = 1 mirrored 03171 int nring = numr.size()/3; 03172 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03173 int maxrin = numr[numr.size()-1]; 03174 double qn; float tot; 03175 float *circ1 = circ1p->get_data(); 03176 float *circ2 = circ2p->get_data(); 03177 /* 03178 c checks single position, neg is flag for checking mirrored position 03179 c 03180 c input - fourier transforms of rings! 03181 c first set is conjugated (mirrored) if neg 03182 c circ1 already multiplied by weights! 03183 c automatic arrays 03184 dimension t(maxrin) removed +2 as it is only needed for other ffts 03185 double precision q(maxrin) 03186 double precision t7(-3:3) 03187 */ 03188 float *t; 03189 double t7[7], *q; 03190 int i, j, k, ip, jc, numr3i, numr2i, jtot = 0; 03191 float pos; 03192 03193 #ifdef _WIN32 03194 ip = -(int)(log((float)maxrin)/log(2.0f)); 03195 #else 03196 ip = -(int) (log2(maxrin)); 03197 #endif //_WIN32 03198 03199 q = (double*)calloc(maxrin, sizeof(double)); 03200 t = (float*)calloc(maxrin, sizeof(float)); 03201 03202 // cout << *qn <<" " <<*tot<<" "<<ip<<endl; 03203 for (i=1; i<=nring; i++) { 03204 numr3i = numr(3,i); 03205 numr2i = numr(2,i); 03206 03207 t(1) = (circ1(numr2i)) * circ2(numr2i); 03208 03209 if (numr3i != maxrin) { 03210 // test .ne. first for speed on some compilers 03211 t(numr3i+1) = circ1(numr2i+1) * circ2(numr2i+1); 03212 t(2) = 0.0; 03213 03214 if (neg) { 03215 // first set is conjugated (mirrored) 03216 for (j=3;j<=numr3i;j=j+2) { 03217 jc = j+numr2i-1; 03218 t(j) =(circ1(jc))*circ2(jc)-(circ1(jc+1))*circ2(jc+1); 03219 t(j+1) = -(circ1(jc))*circ2(jc+1)-(circ1(jc+1))*circ2(jc); 03220 } 03221 } else { 03222 for (j=3;j<=numr3i;j=j+2) { 03223 jc = j+numr2i-1; 03224 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1); 03225 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc); 03226 } 03227 } 03228 for (j=1;j<=numr3i+1;j++) q(j) = q(j) + t(j); 03229 } else { 03230 t(2) = circ1(numr2i+1) * circ2(numr2i+1); 03231 if (neg) { 03232 // first set is conjugated (mirrored) 03233 for (j=3;j<=maxrin;j=j+2) { 03234 jc = j+numr2i-1; 03235 t(j) = (circ1(jc))*circ2(jc) - (circ1(jc+1))*circ2(jc+1); 03236 t(j+1) = -(circ1(jc))*circ2(jc+1) - (circ1(jc+1))*circ2(jc); 03237 } 03238 } else { 03239 for (j=3;j<=maxrin;j=j+2) { 03240 jc = j+numr2i-1; 03241 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1); 03242 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc); 03243 } 03244 } 03245 for (j = 1; j <= maxrin; j++) q(j) += t(j); 03246 } 03247 } 03248 03249 fftr_d(q,ip); 03250 03251 qn = -1.0e20; 03252 for (j=1;j<=maxrin;j++) { 03253 if (q(j) >= qn) { 03254 qn = q(j); jtot = j; 03255 } 03256 } 03257 03258 for (k=-3; k<=3; k++) { 03259 j = (jtot+k+maxrin-1)%maxrin + 1; 03260 t7(k+4) = q(j); 03261 } 03262 03263 prb1d(t7,7,&pos); 03264 03265 tot = (float)jtot + pos; 03266 03267 if (q) free(q); 03268 if (t) free(t); 03269 03270 Dict retvals; 03271 retvals["qn"] = qn; 03272 retvals["tot"] = tot; 03273 return retvals; 03274 }
Dict Util::Crosrng_ew | ( | EMData * | circ1, | |
EMData * | circ2, | |||
vector< int > | numr, | |||
vector< float > | w, | |||
int | neg | |||
) | [static] |
Definition at line 3276 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.
03276 { 03277 // neg = 0 straight, neg = 1 mirrored 03278 int nring = numr.size()/3; 03279 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03280 int maxrin = numr[numr.size()-1]; 03281 double qn; float tot; 03282 float *circ1 = circ1p->get_data(); 03283 float *circ2 = circ2p->get_data(); 03284 /* 03285 c checks single position, neg is flag for checking mirrored position 03286 c 03287 c input - fourier transforms of rings! 03288 c first set is conjugated (mirrored) if neg 03289 c multiplication by weights! 03290 c automatic arrays 03291 dimension t(maxrin) removed +2 as it is only needed for other ffts 03292 double precision q(maxrin) 03293 double precision t7(-3:3) 03294 */ 03295 float *t; 03296 double t7[7], *q; 03297 int i, j, k, ip, jc, numr3i, numr2i, jtot = 0; 03298 float pos; 03299 03300 #ifdef _WIN32 03301 ip = -(int)(log((float)maxrin)/log(2.0f)); 03302 #else 03303 ip = -(int) (log2(maxrin)); 03304 #endif //_WIN32 03305 03306 q = (double*)calloc(maxrin, sizeof(double)); 03307 t = (float*)calloc(maxrin, sizeof(float)); 03308 03309 // cout << *qn <<" " <<*tot<<" "<<ip<<endl; 03310 for (i=1;i<=nring;i++) { 03311 numr3i = numr(3,i); 03312 numr2i = numr(2,i); 03313 03314 t(1) = circ1(numr2i) * circ2(numr2i); 03315 03316 if (numr3i != maxrin) { 03317 // test .ne. first for speed on some compilers 03318 t(numr3i+1) = circ1(numr2i+1) * circ2(numr2i+1); 03319 t(2) = 0.0; 03320 03321 if (neg) { 03322 // first set is conjugated (mirrored) 03323 for (j=3; j<=numr3i; j=j+2) { 03324 jc = j+numr2i-1; 03325 t(j) = (circ1(jc))*circ2(jc)-(circ1(jc+1))*circ2(jc+1); 03326 t(j+1) = -(circ1(jc))*circ2(jc+1)-(circ1(jc+1))*circ2(jc); 03327 } 03328 } else { 03329 for (j=3; j<=numr3i; j=j+2) { 03330 jc = j+numr2i-1; 03331 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1); 03332 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc); 03333 } 03334 } 03335 for (j=1;j<=numr3i+1;j++) q(j) += t(j)*w[i-1]; 03336 } else { 03337 t(2) = circ1(numr2i+1) * circ2(numr2i+1); 03338 if (neg) { 03339 // first set is conjugated (mirrored) 03340 for (j=3; j<=maxrin; j=j+2) { 03341 jc = j+numr2i-1; 03342 t(j) = (circ1(jc))*circ2(jc) - (circ1(jc+1))*circ2(jc+1); 03343 t(j+1) = -(circ1(jc))*circ2(jc+1) - (circ1(jc+1))*circ2(jc); 03344 } 03345 } else { 03346 for (j=3; j<=maxrin; j=j+2) { 03347 jc = j+numr2i-1; 03348 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1); 03349 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc); 03350 } 03351 } 03352 for (j = 1; j <= maxrin; j++) q(j) += t(j)*w[i-1]; 03353 } 03354 } 03355 03356 fftr_d(q,ip); 03357 03358 qn = -1.0e20; 03359 for (j=1;j<=maxrin;j++) { 03360 //cout << j << " " << q(j) << endl; 03361 if (q(j) >= qn) { 03362 qn = q(j); 03363 jtot = j; 03364 } 03365 } 03366 03367 for (k=-3; k<=3; k++) { 03368 j = (jtot+k+maxrin-1)%maxrin + 1; 03369 t7(k+4) = q(j); 03370 } 03371 03372 prb1d(t7,7,&pos); 03373 03374 tot = (float)jtot + pos; 03375 03376 //if (q) free(q); 03377 if (t) free(t); 03378 03379 Dict retvals; 03380 //tot = 1; 03381 //qn = q(1); 03382 retvals["qn"] = qn; 03383 retvals["tot"] = tot; 03384 03385 if (q) free(q); 03386 03387 return retvals; 03388 }
Definition at line 3390 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().
03390 { 03391 int nring = numr.size()/3; 03392 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03393 int maxrin = numr[numr.size()-1]; 03394 double qn; float tot; double qm; float tmt; 03395 float *circ1 = circ1p->get_data(); 03396 float *circ2 = circ2p->get_data(); 03397 /* 03398 c 03399 c checks both straight & mirrored positions 03400 c 03401 c input - fourier transforms of rings!! 03402 c circ1 already multiplied by weights! 03403 c 03404 */ 03405 03406 // dimension circ1(lcirc),circ2(lcirc) 03407 03408 // t(maxrin), q(maxrin), t7(-3:3) //maxrin+2 removed 03409 double *t, *q, t7[7]; 03410 03411 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 03412 float t1, t2, t3, t4, c1, c2, d1, d2, pos; 03413 03414 qn = 0.0f; 03415 qm = 0.0f; 03416 tot = 0.0f; 03417 tmt = 0.0f; 03418 #ifdef _WIN32 03419 ip = -(int)(log((float)maxrin)/log(2.0f)); 03420 #else 03421 ip = -(int)(log2(maxrin)); 03422 #endif //_WIN32 03423 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl; 03424 03425 // c - straight = circ1 * conjg(circ2) 03426 // zero q array 03427 03428 q = (double*)calloc(maxrin,sizeof(double)); 03429 03430 // t - mirrored = conjg(circ1) * conjg(circ2) 03431 // zero t array 03432 t = (double*)calloc(maxrin,sizeof(double)); 03433 03434 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03435 for (i=1; i<=nring; i++) { 03436 03437 numr3i = numr(3,i); // Number of samples of this ring 03438 numr2i = numr(2,i); // The beginning point of this ring 03439 03440 t1 = circ1(numr2i) * circ2(numr2i); 03441 q(1) += t1; 03442 t(1) += t1; 03443 03444 t1 = circ1(numr2i+1) * circ2(numr2i+1); 03445 if (numr3i == maxrin) { 03446 q(2) += t1; 03447 t(2) += t1; 03448 } else { 03449 q(numr3i+1) += t1; 03450 t(numr3i+1) += t1; 03451 } 03452 03453 for (j=3; j<=numr3i; j += 2) { 03454 jc = j+numr2i-1; 03455 03456 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03457 // ----- ----- ----- ----- 03458 // t1 t2 t3 t4 03459 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i 03460 // ----- ----- ----- ----- 03461 // t1 t2 t3 t4 03462 03463 c1 = circ1(jc); 03464 c2 = circ1(jc+1); 03465 d1 = circ2(jc); 03466 d2 = circ2(jc+1); 03467 03468 t1 = c1 * d1; 03469 t2 = c2 * d2; 03470 t3 = c1 * d2; 03471 t4 = c2 * d1; 03472 03473 q(j) += t1 + t2; 03474 q(j+1) += -t3 + t4; 03475 t(j) += t1 - t2; 03476 t(j+1) += -t3 - t4; 03477 } 03478 } 03479 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<" "<<t(j) <<endl; 03480 fftr_d(q,ip); 03481 03482 qn = -1.0e20; 03483 for (j=1; j<=maxrin; j++) {//cout <<" "<<j<<" "<<q(j) <<endl; 03484 if (q(j) >= qn) { 03485 qn = q(j); 03486 jtot = j; 03487 } 03488 } 03489 03490 for (k=-3; k<=3; k++) { 03491 j = ((jtot+k+maxrin-1)%maxrin)+1; 03492 t7(k+4) = q(j); 03493 } 03494 03495 // interpolate 03496 prb1d(t7,7,&pos); 03497 tot = (float)(jtot)+pos; 03498 // Do not interpolate 03499 //tot = (float)(jtot); 03500 03501 // mirrored 03502 fftr_d(t,ip); 03503 03504 // find angle 03505 qm = -1.0e20; 03506 for (j=1; j<=maxrin;j++) {//cout <<" "<<j<<" "<<t(j) <<endl; 03507 if ( t(j) >= qm ) { 03508 qm = t(j); 03509 jtot = j; 03510 } 03511 } 03512 03513 for (k=-3; k<=3; k++) { 03514 j = ((jtot+k+maxrin-1)%maxrin) + 1; 03515 t7(k+4) = t(j); 03516 } 03517 03518 // interpolate 03519 03520 prb1d(t7,7,&pos); 03521 tmt = float(jtot) + pos; 03522 // Do not interpolate 03523 //tmt = float(jtot); 03524 03525 free(t); 03526 free(q); 03527 03528 Dict retvals; 03529 retvals["qn"] = qn; 03530 retvals["tot"] = tot; 03531 retvals["qm"] = qm; 03532 retvals["tmt"] = tmt; 03533 return retvals; 03534 }
Dict Util::Crosrng_ms_delta | ( | EMData * | circ1, | |
EMData * | circ2, | |||
vector< int > | numr, | |||
float | delta_start, | |||
float | delta | |||
) | [static] |
Definition at line 3536 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().
03536 { 03537 int nring = numr.size()/3; 03538 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03539 int maxrin = numr[numr.size()-1]; 03540 double qn; float tot; double qm; float tmt; 03541 float *circ1 = circ1p->get_data(); 03542 float *circ2 = circ2p->get_data(); 03543 /* 03544 c 03545 c checks both straight & mirrored positions 03546 c 03547 c input - fourier transforms of rings!! 03548 c circ1 already multiplied by weights! 03549 c 03550 */ 03551 03552 // dimension circ1(lcirc),circ2(lcirc) 03553 03554 // t(maxrin), q(maxrin), t7(-3:3) //maxrin+2 removed 03555 double *t, *q; 03556 03557 int ip, jc, numr3i, numr2i, i, j, jtot = 0; 03558 float t1, t2, t3, t4, c1, c2, d1, d2; 03559 03560 qn = 0.0f; 03561 qm = 0.0f; 03562 tot = 0.0f; 03563 tmt = 0.0f; 03564 #ifdef _WIN32 03565 ip = -(int)(log((float)maxrin)/log(2.0f)); 03566 #else 03567 ip = -(int)(log2(maxrin)); 03568 #endif //_WIN32 03569 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl; 03570 03571 // c - straight = circ1 * conjg(circ2) 03572 // zero q array 03573 03574 q = (double*)calloc(maxrin,sizeof(double)); 03575 03576 // t - mirrored = conjg(circ1) * conjg(circ2) 03577 // zero t array 03578 t = (double*)calloc(maxrin,sizeof(double)); 03579 03580 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03581 for (i=1; i<=nring; i++) { 03582 03583 numr3i = numr(3,i); // Number of samples of this ring 03584 numr2i = numr(2,i); // The beginning point of this ring 03585 03586 t1 = circ1(numr2i) * circ2(numr2i); 03587 q(1) += t1; 03588 t(1) += t1; 03589 03590 t1 = circ1(numr2i+1) * circ2(numr2i+1); 03591 if (numr3i == maxrin) { 03592 q(2) += t1; 03593 t(2) += t1; 03594 } else { 03595 q(numr3i+1) += t1; 03596 t(numr3i+1) += t1; 03597 } 03598 03599 for (j=3; j<=numr3i; j += 2) { 03600 jc = j+numr2i-1; 03601 03602 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03603 // ----- ----- ----- ----- 03604 // t1 t2 t3 t4 03605 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i 03606 // ----- ----- ----- ----- 03607 // t1 t2 t3 t4 03608 03609 c1 = circ1(jc); 03610 c2 = circ1(jc+1); 03611 d1 = circ2(jc); 03612 d2 = circ2(jc+1); 03613 03614 t1 = c1 * d1; 03615 t2 = c2 * d2; 03616 t3 = c1 * d2; 03617 t4 = c2 * d1; 03618 03619 q(j) += t1 + t2; 03620 q(j+1) += -t3 + t4; 03621 t(j) += t1 - t2; 03622 t(j+1) += -t3 - t4; 03623 } 03624 } 03625 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<" "<<t(j) <<endl; 03626 fftr_d(q,ip); 03627 03628 qn = -1.0e20; 03629 03630 int jstart = 1+static_cast<int>(delta_start/360.0*maxrin); 03631 int jstep = static_cast<int>(delta/360.0*maxrin); 03632 if (jstep < 1) { jstep = 1; } 03633 03634 for (j=jstart; j<=maxrin; j+=jstep) {//cout <<" "<<j<<" "<<q(j) <<endl; 03635 if (q(j) >= qn) { 03636 qn = q(j); 03637 jtot = j; 03638 } 03639 } 03640 03641 //for (k=-3; k<=3; k++) { 03642 // j = ((jtot+k+maxrin-1)%maxrin)+1; 03643 // t7(k+4) = q(j); 03644 //} 03645 03646 // interpolate 03647 //prb1d(t7,7,&pos); 03648 //tot = (float)(jtot)+pos; 03649 // Do not interpolate 03650 tot = (float)(jtot); 03651 03652 // mirrored 03653 fftr_d(t,ip); 03654 03655 // find angle 03656 qm = -1.0e20; 03657 for (j=jstart; j<=maxrin;j+=jstep) {//cout <<" "<<j<<" "<<t(j) <<endl; 03658 if ( t(j) >= qm ) { 03659 qm = t(j); 03660 jtot = j; 03661 } 03662 } 03663 03664 //for (k=-3; k<=3; k++) { 03665 // j = ((jtot+k+maxrin-1)%maxrin) + 1; 03666 // t7(k+4) = t(j); 03667 //} 03668 03669 // interpolate 03670 03671 //prb1d(t7,7,&pos); 03672 //tmt = float(jtot) + pos; 03673 // Do not interpolate 03674 tmt = float(jtot); 03675 03676 free(t); 03677 free(q); 03678 03679 Dict retvals; 03680 retvals["qn"] = qn; 03681 retvals["tot"] = tot; 03682 retvals["qm"] = qm; 03683 retvals["tmt"] = tmt; 03684 return retvals; 03685 }
checks both straight & mirrored positions input - fourier transforms of rings!! circ1 already multiplied by weights! returns EM object with 1D ccf
Definition at line 4200 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.
04200 { 04201 04202 // dimension circ1(lcirc),circ2(lcirc) 04203 04204 int ip, jc, numr3i, numr2i, i, j; 04205 float t1, t2, t3, t4, c1, c2, d1, d2; 04206 04207 int nring = numr.size()/3; 04208 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 04209 int maxrin = numr[numr.size()-1]; 04210 04211 float* circ1b = circ1->get_data(); 04212 float* circ2b = circ2->get_data(); 04213 04214 // t(maxrin), q(maxrin) // removed +2 04215 double *t, *q; 04216 04217 q = (double*)calloc(maxrin,sizeof(double)); 04218 t = (double*)calloc(maxrin,sizeof(double)); 04219 04220 #ifdef _WIN32 04221 ip = -(int)(log((float)maxrin)/log(2.0f)); 04222 #else 04223 ip = -(int)(log2(maxrin)); 04224 #endif //_WIN32 04225 04226 // q - straight = circ1 * conjg(circ2) 04227 04228 // t - mirrored = conjg(circ1) * conjg(circ2) 04229 04230 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 04231 04232 for (i=1; i<=nring; i++) { 04233 04234 numr3i = numr(3,i); 04235 numr2i = numr(2,i); 04236 04237 t1 = circ1b(numr2i) * circ2b(numr2i); 04238 q(1) = q(1)+t1; 04239 t(1) = t(1)+t1; 04240 04241 t1 = circ1b(numr2i+1) * circ2b(numr2i+1); 04242 if (numr3i == maxrin) { 04243 q(2) += t1; 04244 t(2) += t1; 04245 } else { 04246 q(numr3i+1) += t1; 04247 t(numr3i+1) += t1; 04248 } 04249 04250 for (j=3; j<=numr3i; j=j+2) { 04251 jc = j+numr2i-1; 04252 04253 c1 = circ1b(jc); 04254 c2 = circ1b(jc+1); 04255 d1 = circ2b(jc); 04256 d2 = circ2b(jc+1); 04257 04258 t1 = c1 * d1; 04259 t3 = c1 * d2; 04260 t2 = c2 * d2; 04261 t4 = c2 * d1; 04262 04263 q(j) += t1 + t2; 04264 q(j+1) += - t3 + t4; 04265 t(j) += t1 - t2; 04266 t(j+1) += - t3 - t4; 04267 } 04268 } 04269 04270 // straight 04271 fftr_d(q,ip); 04272 04273 // mirrored 04274 fftr_d(t,ip); 04275 04276 EMData* out = new EMData(); 04277 out->set_size(maxrin,2,1); 04278 float *dout = out->get_data(); 04279 for (int i=0; i<maxrin; i++) {dout(i,0)=static_cast<float>(q[i]); dout(i,1)=static_cast<float>(t[i]);} 04280 //out->set_size(maxrin,1,1); 04281 //float *dout = out->get_data(); 04282 //for (int i=0; i<maxrin; i++) {dout(i,0)=q[i];} 04283 free(t); 04284 free(q); 04285 return out; 04286 }
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 4447 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.
04448 { 04449 04450 int ip, jc, numr3i, numr2i, i, j; 04451 float t1, t2, t3, t4, c1, c2, d1, d2; 04452 04453 int nring = numr.size()/3; 04454 int maxrin = numr[numr.size()-1]; 04455 04456 float* circ1b = circ1->get_data(); 04457 float* circ2b = circ2->get_data(); 04458 04459 double *t; 04460 04461 t = (double*)calloc(maxrin,sizeof(double)); 04462 04463 #ifdef _WIN32 04464 ip = -(int)(log((float)maxrin)/log(2.0f)); 04465 #else 04466 ip = -(int)(log2(maxrin)); 04467 #endif //_WIN32 04468 04469 // t - mirrored = conjg(circ1) * conjg(circ2) 04470 04471 for (i=1;i<=nring;i++) { 04472 04473 numr3i = numr(3,i); 04474 numr2i = numr(2,i); 04475 04476 t1 = circ1b(numr2i) * circ2b(numr2i); 04477 t(1) = t(1)+t1; 04478 04479 if (numr3i == maxrin) { 04480 t1 = circ1b(numr2i+1) * circ2b(numr2i+1); 04481 t(2) = t(2)+t1; 04482 } 04483 04484 for (j=3;j<=numr3i;j=j+2) { 04485 jc = j+numr2i-1; 04486 04487 c1 = circ1b(jc); 04488 c2 = circ1b(jc+1); 04489 d1 = circ2b(jc); 04490 d2 = circ2b(jc+1); 04491 04492 t1 = c1 * d1; 04493 t3 = c1 * d2; 04494 t2 = c2 * d2; 04495 t4 = c2 * d1; 04496 04497 t(j) = t(j) + t1 - t2; 04498 t(j+1) = t(j+1) - t3 - t4; 04499 } 04500 } 04501 04502 // mirrored 04503 fftr_d(t,ip); 04504 04505 EMData* out = new EMData(); 04506 out->set_size(maxrin,1,1); 04507 float *dout = out->get_data(); 04508 for (int i=0; i<maxrin; i++) dout[i]=static_cast<float>(t[i]); 04509 free(t); 04510 return out; 04511 04512 }
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 4376 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().
04377 { 04378 04379 int ip, jc, numr3i, numr2i, i, j; 04380 float t1, t2, t3, t4, c1, c2, d1, d2; 04381 04382 int nring = numr.size()/3; 04383 int maxrin = numr[numr.size()-1]; 04384 04385 float* circ1b = circ1->get_data(); 04386 float* circ2b = circ2->get_data(); 04387 04388 double *q; 04389 04390 q = (double*)calloc(maxrin,sizeof(double)); 04391 04392 #ifdef _WIN32 04393 ip = -(int)(log((float)maxrin)/log(2.0f)); 04394 #else 04395 ip = -(int)(log2(maxrin)); 04396 #endif //_WIN32 04397 04398 // q - straight = circ1 * conjg(circ2) 04399 04400 for (i=1;i<=nring;i++) { 04401 04402 numr3i = numr(3,i); 04403 numr2i = numr(2,i); 04404 04405 t1 = circ1b(numr2i) * circ2b(numr2i); 04406 q(1) = q(1)+t1; 04407 04408 if (numr3i == maxrin) { 04409 t1 = circ1b(numr2i+1) * circ2b(numr2i+1); 04410 q(2) = q(2)+t1; 04411 } else { 04412 t1 = circ1b(numr2i+1) * circ2b(numr2i+1); 04413 q(numr3i+1) = q(numr3i+1)+t1; 04414 } 04415 04416 for (j=3;j<=numr3i;j=j+2) { 04417 jc = j+numr2i-1; 04418 04419 c1 = circ1b(jc); 04420 c2 = circ1b(jc+1); 04421 d1 = circ2b(jc); 04422 d2 = circ2b(jc+1); 04423 04424 t1 = c1 * d1; 04425 t3 = c1 * d2; 04426 t2 = c2 * d2; 04427 t4 = c2 * d1; 04428 04429 q(j) = q(j) + t1 + t2; 04430 q(j+1) = q(j+1) - t3 + t4; 04431 } 04432 } 04433 04434 // straight 04435 fftr_d(q,ip); 04436 04437 EMData* out = new EMData(); 04438 out->set_size(maxrin,1,1); 04439 float *dout = out->get_data(); 04440 for (int i=0; i<maxrin; i++) dout[i]=static_cast<float>(q[i]); 04441 free(q); 04442 return out; 04443 04444 }
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 4304 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().
04304 { 04305 04306 // dimension circ1(lcirc),circ2(lcirc) 04307 04308 int ip, jc, numr3i, numr2i, i, j; 04309 float t1, t2, t3, t4, c1, c2, d1, d2; 04310 04311 int nring = numr.size()/3; 04312 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 04313 int maxrin = numr[numr.size()-1]; 04314 04315 float* circ1b = circ1->get_data(); 04316 float* circ2b = circ2->get_data(); 04317 04318 #ifdef _WIN32 04319 ip = -(int)(log((float)maxrin)/log(2.0f)); 04320 #else 04321 ip = -(int)(log2(maxrin)); 04322 #endif //_WIN32 04323 for (int i=1; i<=maxrin; i++) {q(i) = 0.0f; t(i) = 0.0f;} 04324 04325 // q - straight = circ1 * conjg(circ2) 04326 04327 // t - mirrored = conjg(circ1) * conjg(circ2) 04328 04329 for (i=1; i<=nring; i++) { 04330 04331 numr3i = numr(3,i); 04332 numr2i = numr(2,i); 04333 04334 t1 = circ1b(numr2i) * circ2b(numr2i); 04335 q(1) += t1; 04336 t(1) += t1; 04337 04338 t1 = circ1b(numr2i+1) * circ2b(numr2i+1); 04339 if (numr3i == maxrin) { 04340 q(2) += t1; 04341 t(2) += t1; 04342 } else { 04343 q(numr3i+1) += t1; 04344 t(numr3i+1) += t1; 04345 } 04346 04347 for (j=3; j<=numr3i; j=j+2) { 04348 jc = j+numr2i-1; 04349 04350 c1 = circ1b(jc); 04351 c2 = circ1b(jc+1); 04352 d1 = circ2b(jc); 04353 d2 = circ2b(jc+1); 04354 04355 t1 = c1 * d1; 04356 t3 = c1 * d2; 04357 t2 = c2 * d2; 04358 t4 = c2 * d1; 04359 04360 q(j) += t1 + t2; 04361 q(j+1) += -t3 + t4; 04362 t(j) += t1 - t2; 04363 t(j+1) += -t3 - t4; 04364 } 04365 } 04366 // straight 04367 fftr_q(q,ip); 04368 //for (int i=0; i<maxrin; i++) cout<<i<<" B "<<q[i]<<" "<<t[i]<<endl; 04369 04370 // mirrored 04371 fftr_q(t,ip); 04372 }
vector< float > Util::Crosrng_msg_vec_p | ( | EMData * | circ1, | |
EMData * | circ2, | |||
vector< int > | numr | |||
) | [static] |
Definition at line 4289 of file util_sparx.cpp.
References circ1, circ2, and Crosrng_msg_vec().
04289 { 04290 04291 int maxrin = numr[numr.size()-1]; 04292 04293 vector<float> r(2*maxrin); 04294 04295 Crosrng_msg_vec( circ1, circ2, numr, &r[0], &r[maxrin] ); 04296 04297 return r; 04298 }
Definition at line 4101 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().
04101 { 04102 int nring = numr.size()/3; 04103 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 04104 int maxrin = numr[numr.size()-1]; 04105 double qn; float tot; 04106 float *circ1 = circ1p->get_data(); 04107 float *circ2 = circ2p->get_data(); 04108 /* 04109 c 04110 c checks only straight position 04111 c 04112 c input - fourier transforms of rings!! 04113 c circ1 already multiplied by weights! 04114 c 04115 */ 04116 04117 // dimension circ1(lcirc),circ2(lcirc) 04118 04119 // q(maxrin), t7(-3:3) //maxrin+2 removed 04120 double *q, t7[7]; 04121 04122 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 04123 float c1, c2, d1, d2, pos; 04124 04125 qn = 0.0; 04126 tot = 0.0; 04127 #ifdef _WIN32 04128 ip = -(int)(log((float)maxrin)/log(2.0f)); 04129 #else 04130 ip = -(int)(log2(maxrin)); 04131 #endif //_WIN32 04132 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl; 04133 04134 // c - straight = circ1 * conjg(circ2) 04135 // zero q array 04136 04137 q = (double*)calloc(maxrin,sizeof(double)); 04138 04139 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 04140 for (i=1; i<=nring; i++) { 04141 04142 numr3i = numr(3,i); // Number of samples of this ring 04143 numr2i = numr(2,i); // The beginning point of this ring 04144 04145 q(1) += circ1(numr2i) * circ2(numr2i); 04146 04147 if (numr3i == maxrin) q(2) += circ1(numr2i+1) * circ2(numr2i+1); 04148 else q(numr3i+1) += circ1(numr2i+1) * circ2(numr2i+1); 04149 04150 for (j=3; j<=numr3i; j += 2) { 04151 jc = j+numr2i-1; 04152 04153 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 04154 // ----- ----- ----- ----- 04155 // t1 t2 t3 t4 04156 04157 c1 = circ1(jc); 04158 c2 = circ1(jc+1); 04159 d1 = circ2(jc); 04160 d2 = circ2(jc+1); 04161 04162 q(j) += c1 * d1 + c2 * d2; 04163 q(j+1) += -c1 * d2 + c2 * d1; 04164 } 04165 } 04166 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<endl; 04167 fftr_d(q,ip); 04168 04169 qn = -1.0e20; 04170 for (j=1; j<=maxrin; j++) {//cout <<" "<<j<<" "<<q(j) <<endl; 04171 if (q(j) >= qn) { 04172 qn = q(j); 04173 jtot = j; 04174 } 04175 } 04176 04177 for (k=-3; k<=3; k++) { 04178 j = ((jtot+k+maxrin-1)%maxrin)+1; 04179 t7(k+4) = q(j); 04180 } 04181 04182 // interpolate 04183 prb1d(t7,7,&pos); 04184 tot = (float)(jtot)+pos; 04185 // Do not interpolate 04186 //*tot = (float)(jtot); 04187 04188 free(q); 04189 04190 Dict retvals; 04191 retvals["qn"] = qn; 04192 retvals["tot"] = tot; 04193 return retvals; 04194 }
Dict Util::Crosrng_psi_0_180 | ( | 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 3688 of file util_sparx.cpp.
References circ1, circ2, fftr_d(), EMAN::EMData::get_data(), log(), numr, prb1d(), q, EMAN::Dict::size(), t, t7, tmt, and tot.
Referenced by multiref_polar_ali_helical(), and multiref_polar_ali_helical_local().
03688 { 03689 int nring = numr.size()/3; 03690 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03691 int maxrin = numr[numr.size()-1]; 03692 double qn; float tot; double qm; float tmt; 03693 float *circ1 = circ1p->get_data(); 03694 float *circ2 = circ2p->get_data(); 03695 03696 // dimension circ1(lcirc),circ2(lcirc) 03697 03698 // t(maxrin), q(maxrin), t7(-3:3) //maxrin+2 removed 03699 double *t, *q, t7[7]; 03700 03701 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 03702 float t1, t2, t3, t4, c1, c2, d1, d2, pos; 03703 03704 qn = 0.0f; 03705 qm = 0.0f; 03706 tot = 0.0f; 03707 tmt = 0.0f; 03708 #ifdef _WIN32 03709 ip = -(int)(log((float)maxrin)/log(2.0f)); 03710 #else 03711 ip = -(int)(log2(maxrin)); 03712 #endif //_WIN32 03713 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl; 03714 03715 // c - straight = circ1 * conjg(circ2) 03716 // zero q array 03717 03718 q = (double*)calloc(maxrin,sizeof(double)); 03719 03720 // t - mirrored = conjg(circ1) * conjg(circ2) 03721 // zero t array 03722 t = (double*)calloc(maxrin,sizeof(double)); 03723 03724 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03725 for (i=1; i<=nring; i++) { 03726 03727 numr3i = numr(3,i); // Number of samples of this ring 03728 numr2i = numr(2,i); // The beginning point of this ring 03729 03730 t1 = circ1(numr2i) * circ2(numr2i); 03731 q(1) += t1; 03732 t(1) += t1; 03733 03734 t1 = circ1(numr2i+1) * circ2(numr2i+1); 03735 if (numr3i == maxrin) { 03736 q(2) += t1; 03737 t(2) += t1; 03738 } else { 03739 q(numr3i+1) += t1; 03740 t(numr3i+1) += t1; 03741 } 03742 03743 for (j=3; j<=numr3i; j += 2) { 03744 jc = j+numr2i-1; 03745 03746 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03747 // ----- ----- ----- ----- 03748 // t1 t2 t3 t4 03749 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i 03750 // ----- ----- ----- ----- 03751 // t1 t2 t3 t4 03752 03753 c1 = circ1(jc); 03754 c2 = circ1(jc+1); 03755 d1 = circ2(jc); 03756 d2 = circ2(jc+1); 03757 03758 t1 = c1 * d1; 03759 t2 = c2 * d2; 03760 t3 = c1 * d2; 03761 t4 = c2 * d1; 03762 03763 q(j) += t1 + t2; 03764 q(j+1) += -t3 + t4; 03765 t(j) += t1 - t2; 03766 t(j+1) += -t3 - t4; 03767 } 03768 } 03769 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<" "<<t(j) <<endl; 03770 fftr_d(q,ip); 03771 03772 int psi_range = int(psi_max/360.0*maxrin+0.5); 03773 const int psi_0 = 0; 03774 int psi_180 = int( 180.0/360.0*maxrin+0.5); 03775 03776 qn = -1.0e20; 03777 for (k=-psi_range; k<=psi_range; k++) { 03778 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; 03779 if (q(j) >= qn) { 03780 qn = q(j); 03781 jtot = j; 03782 } 03783 } 03784 03785 for (k=-psi_range; k<=psi_range; k++) { 03786 j = (k+psi_180+maxrin-1)%maxrin+1; //cout <<" 270 "<<j<<" "<<ang_n(j,modemo,maxrin) <<" "<<float(j)/maxrin*360.0<<" "<<q(j) <<endl; 03787 if (q(j) >= qn) { 03788 qn = q(j); 03789 jtot = j; 03790 } 03791 } 03792 03793 for (k=-3; k<=3; k++) { 03794 j = ((jtot+k+maxrin-1)%maxrin)+1; 03795 t7(k+4) = q(j); 03796 } 03797 03798 // interpolate 03799 prb1d(t7,7,&pos); 03800 tot = (float)(jtot)+pos; 03801 // Do not interpolate 03802 //tot = (float)(jtot); 03803 03804 // mirrored 03805 fftr_d(t,ip); 03806 03807 // find angle 03808 qm = -1.0e20; 03809 for (k=-psi_range; k<=psi_range; k++) { 03810 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; 03811 if (t(j) >= qm) { 03812 qm = t(j); 03813 jtot = j; 03814 } 03815 } 03816 03817 for (k=-psi_range; k<=psi_range; k++) { 03818 j = (k+psi_180+maxrin-1)%maxrin+1; //cout <<" 270 "<<j<<" "<<ang_n(j,modemo,maxrin) <<" "<<float(j)/maxrin*360.0<<" "<<q(j) <<endl; 03819 if (t(j) >= qm) { 03820 qm = t(j); 03821 jtot = j; 03822 } 03823 } 03824 03825 for (k=-3; k<=3; k++) { 03826 j = ((jtot+k+maxrin-1)%maxrin) + 1; 03827 t7(k+4) = t(j); 03828 } 03829 03830 // interpolate 03831 03832 prb1d(t7,7,&pos); 03833 tmt = float(jtot) + pos; 03834 // Do not interpolate 03835 //tmt = float(jtot); 03836 03837 free(t); 03838 free(q); 03839 03840 Dict retvals; 03841 retvals["qn"] = qn; 03842 retvals["tot"] = tot; 03843 retvals["qm"] = qm; 03844 retvals["tmt"] = tmt; 03845 return retvals; 03846 }
Dict Util::Crosrng_psi_0_180_no_mirror | ( | EMData * | circ1, | |
EMData * | circ2, | |||
vector< int > | numr, | |||
float | psi_max | |||
) | [static] |
Definition at line 3848 of file util_sparx.cpp.
References circ1, circ2, fftr_d(), EMAN::EMData::get_data(), log(), numr, prb1d(), q, EMAN::Dict::size(), t7, and tot.
Referenced by multiref_polar_ali_helical_90(), and multiref_polar_ali_helical_90_local().
03848 { 03849 int nring = numr.size()/3; 03850 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03851 int maxrin = numr[numr.size()-1]; 03852 double qn; float tot; 03853 float *circ1 = circ1p->get_data(); 03854 float *circ2 = circ2p->get_data(); 03855 03856 // dimension circ1(lcirc),circ2(lcirc) 03857 03858 // t(maxrin), q(maxrin), t7(-3:3) //maxrin+2 removed 03859 double *q, t7[7]; 03860 03861 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 03862 float t1, t2, t3, t4, c1, c2, d1, d2, pos; 03863 03864 qn = 0.0f; 03865 tot = 0.0f; 03866 #ifdef _WIN32 03867 ip = -(int)(log((float)maxrin)/log(2.0f)); 03868 #else 03869 ip = -(int)(log2(maxrin)); 03870 #endif //_WIN32 03871 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl; 03872 03873 // c - straight = circ1 * conjg(circ2) 03874 // zero q array 03875 03876 q = (double*)calloc(maxrin,sizeof(double)); 03877 03878 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03879 for (i=1; i<=nring; i++) { 03880 03881 numr3i = numr(3,i); // Number of samples of this ring 03882 numr2i = numr(2,i); // The beginning point of this ring 03883 03884 t1 = circ1(numr2i) * circ2(numr2i); 03885 q(1) += t1; 03886 03887 03888 t1 = circ1(numr2i+1) * circ2(numr2i+1); 03889 if (numr3i == maxrin) { 03890 q(2) += t1; 03891 03892 } else { 03893 q(numr3i+1) += t1; 03894 } 03895 03896 for (j=3; j<=numr3i; j += 2) { 03897 jc = j+numr2i-1; 03898 03899 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03900 // ----- ----- ----- ----- 03901 // t1 t2 t3 t4 03902 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i 03903 // ----- ----- ----- ----- 03904 // t1 t2 t3 t4 03905 03906 c1 = circ1(jc); 03907 c2 = circ1(jc+1); 03908 d1 = circ2(jc); 03909 d2 = circ2(jc+1); 03910 03911 t1 = c1 * d1; 03912 t2 = c2 * d2; 03913 t3 = c1 * d2; 03914 t4 = c2 * d1; 03915 03916 q(j) += t1 + t2; 03917 q(j+1) += -t3 + t4; 03918 03919 } 03920 } 03921 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<" "<<t(j) <<endl; 03922 fftr_d(q,ip); 03923 03924 int psi_range = int(psi_max/360.0*maxrin+0.5); 03925 const int psi_0 = 0; 03926 int psi_180 = int( 180.0/360.0*maxrin+0.5); 03927 03928 qn = -1.0e20; 03929 for (k=-psi_range; k<=psi_range; k++) { 03930 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; 03931 if (q(j) >= qn) { 03932 qn = q(j); 03933 jtot = j; 03934 } 03935 } 03936 03937 for (k=-psi_range; k<=psi_range; k++) { 03938 j = (k+psi_180+maxrin-1)%maxrin+1; //cout <<" 270 "<<j<<" "<<ang_n(j,modemo,maxrin) <<" "<<float(j)/maxrin*360.0<<" "<<q(j) <<endl; 03939 if (q(j) >= qn) { 03940 qn = q(j); 03941 jtot = j; 03942 } 03943 } 03944 03945 for (k=-3; k<=3; k++) { 03946 j = ((jtot+k+maxrin-1)%maxrin)+1; 03947 t7(k+4) = q(j); 03948 } 03949 03950 // interpolate 03951 prb1d(t7,7,&pos); 03952 tot = (float)(jtot)+pos; 03953 // Do not interpolate 03954 //tot = (float)(jtot); 03955 03956 free(q); 03957 03958 Dict retvals; 03959 retvals["qn"] = qn; 03960 retvals["tot"] = tot; 03961 03962 return retvals; 03963 }
Dict Util::Crosrng_sm_psi | ( | EMData * | circ1, | |
EMData * | circ2, | |||
vector< int > | numr, | |||
float | psi, | |||
int | flag | |||
) | [static] |
checks both straight & mirrored position input - fourier transforms of rings!! circ1 already multiplied by weights!
Definition at line 3967 of file util_sparx.cpp.
References circ1, circ2, fftr_d(), EMAN::EMData::get_data(), log(), numr, prb1d(), q, EMAN::Dict::size(), t7, tmt, and tot.
Referenced by multiref_polar_ali_2d_local_psi().
03967 { 03968 // flag 0 - straignt, 1 - mirror 03969 03970 int nring = numr.size()/3; 03971 int maxrin = numr[numr.size()-1]; 03972 double qn; float tot; double qm; float tmt; 03973 float *circ1 = circ1p->get_data(); 03974 float *circ2 = circ2p->get_data(); 03975 03976 double *q, t7[7]; 03977 03978 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 03979 float t1, t2, t3, t4, c1, c2, d1, d2, pos; 03980 03981 qn = 0.0f; 03982 qm = 0.0f; 03983 tot = 0.0f; 03984 tmt = 0.0f; 03985 #ifdef _WIN32 03986 ip = -(int)(log((float)maxrin)/log(2.0f)); 03987 #else 03988 ip = -(int)(log2(maxrin)); 03989 #endif //_WIN32 03990 03991 // c - straight = circ1 * conjg(circ2) 03992 // zero q array 03993 03994 q = (double*)calloc(maxrin,sizeof(double)); 03995 03996 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03997 if (flag==0) { 03998 for (i=1; i<=nring; i++) { 03999 04000 numr3i = numr(3,i); // Number of samples of this ring 04001 numr2i = numr(2,i); // The beginning point of this ring 04002 04003 t1 = circ1(numr2i) * circ2(numr2i); 04004 q(1) += t1; 04005 04006 t1 = circ1(numr2i+1) * circ2(numr2i+1); 04007 if (numr3i == maxrin) { 04008 q(2) += t1; 04009 } else { 04010 q(numr3i+1) += t1; 04011 } 04012 04013 for (j=3; j<=numr3i; j += 2) { 04014 jc = j+numr2i-1; 04015 04016 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 04017 // ----- ----- ----- ----- 04018 // t1 t2 t3 t4 04019 04020 c1 = circ1(jc); 04021 c2 = circ1(jc+1); 04022 d1 = circ2(jc); 04023 d2 = circ2(jc+1); 04024 04025 t1 = c1 * d1; 04026 t3 = c1 * d2; 04027 t2 = c2 * d2; 04028 t4 = c2 * d1; 04029 04030 q(j) += t1 + t2; 04031 q(j+1) += -t3 + t4; 04032 } 04033 } 04034 } else { 04035 for (i=1; i<=nring; i++) { 04036 04037 numr3i = numr(3,i); // Number of samples of this ring 04038 numr2i = numr(2,i); // The beginning point of this ring 04039 04040 t1 = circ1(numr2i) * circ2(numr2i); 04041 q(1) += t1; 04042 04043 t1 = circ1(numr2i+1) * circ2(numr2i+1); 04044 if (numr3i == maxrin) { 04045 q(2) += t1; 04046 } else { 04047 q(numr3i+1) += t1; 04048 } 04049 04050 for (j=3; j<=numr3i; j += 2) { 04051 jc = j+numr2i-1; 04052 04053 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 04054 // ----- ----- ----- ----- 04055 // t1 t2 t3 t4 04056 04057 c1 = circ1(jc); 04058 c2 = circ1(jc+1); 04059 d1 = circ2(jc); 04060 d2 = circ2(jc+1); 04061 04062 t1 = c1 * d1; 04063 t3 = c1 * d2; 04064 t2 = c2 * d2; 04065 t4 = c2 * d1; 04066 04067 q(j) += t1 - t2; 04068 q(j+1) += -t3 - t4; 04069 } 04070 } 04071 } 04072 fftr_d(q,ip); 04073 04074 qn = -1.0e20; 04075 int psi_pos = int(psi/360.0*maxrin+0.5); 04076 04077 for (k=-5; k<=5; k++) { 04078 j = (psi_pos+maxrin-1)%maxrin+1; 04079 if (q(j) >= qn) { 04080 qn = q(j); 04081 jtot = j; 04082 } 04083 } 04084 04085 for (k=-3; k<=3; k++) { 04086 j = ((jtot+k+maxrin-1)%maxrin)+1; 04087 t7(k+4) = q(j); 04088 } 04089 04090 // interpolate 04091 prb1d(t7,7,&pos); 04092 tot = (float)(jtot)+pos; 04093 free(q); 04094 04095 Dict retvals; 04096 retvals["qn"] = qn; 04097 retvals["tot"] = tot; 04098 return retvals; 04099 }
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 20125 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().
20126 { 20127 int ix, iy, iz; 20128 int i, j, k; 20129 int nr2, nl2; 20130 float az, ak; 20131 float scx, scy, scz; 20132 int offset = 2 - nx%2; 20133 int lsm = nx + offset; 20134 EMData* ctf_img1 = new EMData(); 20135 ctf_img1->set_size(lsm, ny, nz); 20136 float freq = 1.0f/(2.0f*ps); 20137 scx = 2.0f/float(nx); 20138 if(ny>=1) scy = 2.0f/float(ny); else scy=0.0f; 20139 if(nz>=1) scz = 2.0f/float(nz); else scz=0.0f; 20140 nr2 = ny/2 ; 20141 nl2 = nz/2 ; 20142 float pihalf = M_PI/2.0f; 20143 for ( k=0; k<nz;k++) { 20144 iz = k; if(k>nl2) iz=k-nz; 20145 float oz2 = iz*scz*iz*scz; 20146 for ( j=0; j<ny;j++) { 20147 iy = j; if(j>nr2) iy=j - ny; 20148 float oy = iy*scy; 20149 float oy2 = oy*oy; 20150 for ( i=0; i<lsm/2; i++) { 20151 ix=i; 20152 if( dza == 0.0f) { 20153 ak=pow(ix*ix*scx*scx + oy2 + oz2, 0.5f)*freq; 20154 (*ctf_img1) (i*2,j,k) = Util::tf(dz, ak, voltage, cs, wgh, b_factor, sign); 20155 } else { 20156 float ox = ix*scx; 20157 ak=pow(ox*ox + oy2 + oz2, 0.5f)*freq; 20158 az = atan2(oy, ox); 20159 float dzz = dz + dza/2.0f*sin(2*(az-azz*M_PI/180.0f-pihalf)); 20160 (*ctf_img1) (i*2,j,k) = Util::tf(dzz, ak, voltage, cs, wgh, b_factor, sign); 20161 } 20162 //(*ctf_img1) (i*2+1,j,k) = 0.0f; PAP I assumed new EMData sets to zero 20163 } 20164 } 20165 } 20166 ctf_img1->update(); 20167 ctf_img1->set_complex(true); 20168 ctf_img1->set_ri(true); 20169 //ctf_img1->attr_dict["is_complex"] = 1; 20170 //ctf_img1->attr_dict["is_ri"] = 1; 20171 if(nx%2==0) ctf_img1->set_fftodd(false); else ctf_img1->set_fftodd(true); 20172 return ctf_img1; 20173 }
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 5538 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().
05538 { 05539 05540 if (image->is_complex()) throw ImageFormatException("Real image required for IntegerCyclicShift2DProcessor"); 05541 05542 int dx = params["dx"]; 05543 int dy = params["dy"]; 05544 int dz = params["dz"]; 05545 05546 // The reverse trick we're using shifts to the left (a negative shift) 05547 int nx = image->get_xsize(); 05548 dx %= nx; 05549 if (dx < 0) dx += nx; 05550 int ny = image->get_ysize(); 05551 dy %= ny; 05552 if (dy < 0) dy += ny; 05553 int nz = image->get_zsize(); 05554 dz %= nz; 05555 if (dz < 0) dz += nz; 05556 05557 int mx = -(dx - nx); 05558 int my = -(dy - ny); 05559 int mz = -(dz - nz); 05560 05561 float* data = image->get_data(); 05562 // x-reverses 05563 if (mx != 0) { 05564 for (int iz = 0; iz < nz; iz++) 05565 for (int iy = 0; iy < ny; iy++) { 05566 // reverses for column iy 05567 size_t offset = nx*iy + (size_t)nx*ny*iz; // starting location for column iy in slice iz 05568 reverse(&data[offset],&data[offset+mx]); 05569 reverse(&data[offset+mx],&data[offset+nx]); 05570 reverse(&data[offset],&data[offset+nx]); 05571 } 05572 } 05573 // y-reverses 05574 if (my != 0) { 05575 for (int iz = 0; iz < nz; iz++) { 05576 size_t offset = (size_t)nx*ny*iz; 05577 colreverse(&data[offset], &data[offset + my*nx], nx); 05578 colreverse(&data[offset + my*nx], &data[offset + ny*nx], nx); 05579 colreverse(&data[offset], &data[offset + ny*nx], nx); 05580 } 05581 } 05582 if (mz != 0) { 05583 slicereverse(&data[0], &data[(size_t)mz*ny*nx], nx, ny); 05584 slicereverse(&data[mz*ny*nx], &data[(size_t)nz*ny*nx], nx, ny); 05585 slicereverse(&data[0], &data[(size_t)nz*ny*nx], nx ,ny); 05586 } 05587 image->update(); 05588 }
Definition at line 5332 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().
05333 { 05334 /* Exception Handle */ 05335 if (!img) { 05336 throw NullPointerException("NULL input image"); 05337 } 05338 /* ============================== */ 05339 05340 // Get the size of the input image 05341 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 05342 /* ============================== */ 05343 05344 05345 /* Exception Handle */ 05346 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) 05347 { 05348 LOGERR("Parameters for decimation cannot exceed the center of the image."); 05349 throw ImageDimensionException("Parameters for decimation cannot exceed the center of the image."); 05350 } 05351 /* ============================== */ 05352 05353 05354 /* Calculation of the start point */ 05355 int new_st_x=(nx/2)%x_step, new_st_y=(ny/2)%y_step, new_st_z=(nz/2)%z_step; 05356 /* ============================*/ 05357 05358 05359 /* Calculation of the size of the decimated image */ 05360 int rx=2*(nx/(2*x_step)), ry=2*(ny/(2*y_step)), rz=2*(nz/(2*z_step)); 05361 int r1=int(ceil((nx-(x_step*rx))/(1.f*x_step))), r2=int(ceil((ny-(y_step*ry))/(1.f*y_step))); 05362 int r3=int(ceil((nz-(z_step*rz))/(1.f*z_step))); 05363 if(r1>1){r1=1;} 05364 if(r2>1){r2=1;} 05365 if(r3>1){r3=1;} 05366 int new_nx=rx+r1, new_ny=ry+r2, new_nz=rz+r3; 05367 /* ===========================================*/ 05368 05369 05370 EMData* img2 = new EMData(); 05371 img2->set_size(new_nx,new_ny,new_nz); 05372 float *new_ptr = img2->get_data(); 05373 float *old_ptr = img->get_data(); 05374 int iptr, jptr, kptr = 0; 05375 for (int k=new_st_z; k<nz; k+=z_step) {jptr=0; 05376 for (int j=new_st_y; j<ny; j+=y_step) {iptr=0; 05377 for (int i=new_st_x; i<nx; i+=x_step) { 05378 new_ptr(iptr,jptr,kptr) = old_ptr(i,j,k); 05379 iptr++;} 05380 jptr++;} 05381 kptr++;} 05382 img2->update(); 05383 return img2; 05384 }
void Util::disorder2 | ( | double * | x, | |
double * | y, | |||
int * | key, | |||
int | len | |||
) | [static] |
Definition at line 7843 of file util_sparx.cpp.
References ENTERFUNC, and EXITFUNC.
07844 { 07845 ENTERFUNC; 07846 int k, i; 07847 for(i=0; i<len; i++) key[i]=i+1; 07848 07849 for(i = 0; i<len;i++){ 07850 k = rand()%len; 07851 std::swap(key[k], key[i]); 07852 std::swap(x[k], x[i]); 07853 std::swap(y[k], y[i]); 07854 } 07855 EXITFUNC; 07856 }
Definition at line 17780 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().
17781 { 17782 ENTERFUNC; 17783 /* Exception Handle */ 17784 if (!img) { 17785 throw NullPointerException("NULL input image"); 17786 } 17787 /* ========= img /= img1 ===================== */ 17788 17789 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17790 size_t size = (size_t)nx*ny*nz; 17791 float *img_ptr = img->get_data(); 17792 float *img1_ptr = img1->get_data(); 17793 if(img->is_complex()) { 17794 for (size_t i=0; i<size; i+=2) { 17795 if(img1_ptr[i] > 1.e-10f) { 17796 img_ptr[i] /= img1_ptr[i]; 17797 img_ptr[i+1] /= img1_ptr[i]; 17798 } else img_ptr[i] = img_ptr[i+1] = 0.0f; 17799 } 17800 } else throw ImageFormatException("Only Fourier image allowed"); 17801 17802 img->update(); 17803 17804 EXITFUNC; 17805 }
Definition at line 17751 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().
17752 { 17753 ENTERFUNC; 17754 /* Exception Handle */ 17755 if (!img) { 17756 throw NullPointerException("NULL input image"); 17757 } 17758 /* ========= img /= img1 ===================== */ 17759 17760 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17761 size_t size = (size_t)nx*ny*nz; 17762 float *img_ptr = img->get_data(); 17763 float *img1_ptr = img1->get_data(); 17764 if(img->is_complex()) { 17765 float sq2; 17766 for (size_t i=0; i<size; i+=2) { 17767 sq2 = 1.0f/(img1_ptr[i] * img1_ptr[i] + img1_ptr[i+1] * img1_ptr[i+1]); 17768 float tmp = sq2*(img_ptr[i] * img1_ptr[i] + img_ptr[i+1] * img1_ptr[i+1]) ; 17769 img_ptr[i+1] = sq2*(img_ptr[i+1] * img1_ptr[i] - img_ptr[i] * img1_ptr[i+1]) ; 17770 img_ptr[i] = tmp; 17771 } 17772 } else { 17773 for (size_t i=0; i<size; ++i) img_ptr[i] /= img1_ptr[i]; 17774 } 17775 img->update(); 17776 17777 EXITFUNC; 17778 }
Definition at line 17576 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().
17577 { 17578 ENTERFUNC; 17579 /* Exception Handle */ 17580 if (!img) { 17581 throw NullPointerException("NULL input image"); 17582 } 17583 /* ========= img /= img1 ===================== */ 17584 17585 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17586 size_t size = (size_t)nx*ny*nz; 17587 EMData * img2 = img->copy_head(); 17588 float *img_ptr =img->get_data(); 17589 float *img1_ptr = img1->get_data(); 17590 float *img2_ptr = img2->get_data(); 17591 if(img->is_complex()) { 17592 for (size_t i=0; i<size; i+=2) { 17593 if(img1_ptr[i] > 1.e-10f) { 17594 img2_ptr[i] = img_ptr[i] /img1_ptr[i]; 17595 img2_ptr[i+1] = img_ptr[i+1]/img1_ptr[i]; 17596 } else img2_ptr[i] = img2_ptr[i+1] = 0.0f; 17597 } 17598 } else throw ImageFormatException("Only Fourier image allowed"); 17599 17600 img->update(); 17601 17602 EXITFUNC; 17603 return img2; 17604 }
Definition at line 17543 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().
17544 { 17545 ENTERFUNC; 17546 /* Exception Handle */ 17547 if (!img) { 17548 throw NullPointerException("NULL input image"); 17549 } 17550 /* ============== output = img / img1 ================ */ 17551 17552 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17553 size_t size = (size_t)nx*ny*nz; 17554 EMData * img2 = img->copy_head(); 17555 float *img_ptr =img->get_data(); 17556 float *img2_ptr = img2->get_data(); 17557 float *img1_ptr = img1->get_data(); 17558 if(img->is_complex()) { 17559 float sq2; 17560 for (size_t i=0; i<size; i+=2) { 17561 sq2 = 1.0f/(img1_ptr[i] * img1_ptr[i] + img1_ptr[i+1] * img1_ptr[i+1]); 17562 img2_ptr[i] = sq2*(img_ptr[i] * img1_ptr[i] + img_ptr[i+1] * img1_ptr[i+1]) ; 17563 img2_ptr[i+1] = sq2*(img_ptr[i+1] * img1_ptr[i] - img_ptr[i] * img1_ptr[i+1]) ; 17564 } 17565 img2->set_complex(true); 17566 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17567 } else { 17568 for (size_t i=0; i<size; ++i) img2_ptr[i] = img_ptr[i] / img1_ptr[i]; 17569 img2->update(); 17570 } 17571 17572 EXITFUNC; 17573 return img2; 17574 }
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 1983 of file util.h.
Referenced by EMAN::IterationAverager::finish().
float Util::ener | ( | EMData * | ave, | |
vector< int > | numr | |||
) | [static] |
Definition at line 4529 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), numr, and PI2.
Referenced by ener_tot().
04529 { 04530 ENTERFUNC; 04531 long double ener,en; 04532 04533 int nring = numr.size()/3; 04534 float *aveptr = ave->get_data(); 04535 04536 ener = 0.0; 04537 for (int i=1; i<=nring; i++) { 04538 int numr3i = numr(3,i); 04539 int np = numr(2,i)-1; 04540 float tq = static_cast<float>(PI2*numr(1,i)/numr3i); 04541 en = tq*(aveptr[np]*aveptr[np]+aveptr[np+1]*aveptr[np+1])*0.5; 04542 for (int j=np+2; j<np+numr3i-1; j++) en += tq*aveptr[j]*aveptr[j]; 04543 ener += en/numr3i; 04544 } 04545 EXITFUNC; 04546 return static_cast<float>(ener); 04547 }
float Util::ener_tot | ( | const vector< EMData * > & | data, | |
vector< int > | numr, | |||
vector< float > | tot | |||
) | [static] |
Definition at line 4549 of file util_sparx.cpp.
References ener(), ENTERFUNC, EXITFUNC, get_data(), numr, and PI2.
04549 { 04550 ENTERFUNC; 04551 long double ener, en; 04552 float arg, cs, si; 04553 04554 int nima = data.size(); 04555 int nring = numr.size()/3; 04556 int maxrin = numr(3,nring); 04557 04558 ener = 0.0; 04559 for (int i=1; i<=nring; i++) { 04560 int numr3i = numr(3,i); 04561 int np = numr(2,i)-1; 04562 float tq = static_cast<float>(PI2*numr(1,i)/numr3i); 04563 float temp1 = 0.0, temp2 = 0.0; 04564 for (int kk=0; kk<nima; kk++) { 04565 float *ptr = data[kk]->get_data(); 04566 temp1 += ptr[np]; 04567 temp2 += static_cast<float>(ptr[np+1]*cos(PI2*(tot[kk]-1.0f)/2.0f*numr3i/maxrin)); 04568 } 04569 en = tq*(temp1*temp1+temp2*temp2)*0.5; 04570 for (int j=2; j<numr3i; j+=2) { 04571 float tempr = 0.0, tempi = 0.0; 04572 for (int kk=0; kk<nima; kk++) { 04573 float *ptr = data[kk]->get_data(); 04574 arg = static_cast<float>( PI2*(tot[kk]-1.0)*(j/2)/maxrin ); 04575 cs = cos(arg); 04576 si = sin(arg); 04577 tempr += ptr[np + j]*cs - ptr[np + j +1]*si; 04578 tempi += ptr[np + j]*si + ptr[np + j +1]*cs; 04579 } 04580 en += tq*(tempr*tempr+tempi*tempi); 04581 } 04582 ener += en/numr3i; 04583 } 04584 EXITFUNC; 04585 return static_cast<float>(ener); 04586 }
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 7191 of file util_sparx.cpp.
References EMAN::EMData::get_data(), and EMAN::EMData::read_image().
07192 { 07193 int j,d; 07194 EMData * e = new EMData(); 07195 float *eptr, *imgptr; 07196 imgptr = img->get_data(); 07197 float SSE = 0.f; 07198 for (j = 0 ; j < N ; j++) { 07199 e->read_image(images,S[j]); 07200 eptr = e->get_data(); 07201 for (d = 0; d < size; d++) { 07202 SSE += ((eptr[d] - imgptr[d])*(eptr[d] - imgptr[d]));} 07203 } 07204 delete e; 07205 return SSE; 07206 }
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 511 of file util_sparx.cpp.
References angles, dgr_to_rad, phi, and theta.
00512 { 00513 vector<float> angles; 00514 float psi = 0.0; 00515 if ((0.0 == t1 && 0.0 == t2)||(t1 >= t2)) { 00516 t1 = 0.0f; 00517 t2 = 90.0f; 00518 } 00519 if ((0.0 == p1 && 0.0 == p2)||(p1 >= p2)) { 00520 p1 = 0.0f; 00521 p2 = 359.9f; 00522 } 00523 bool skip = ((t1 < 90.0)&&(90.0 == t2)&&(0.0 == p1)&&(p2 > 180.0)); 00524 for (float theta = t1; theta <= t2; theta += delta) { 00525 float detphi; 00526 int lt; 00527 if ((0.0 == theta)||(180.0 == theta)) { 00528 detphi = 360.0f; 00529 lt = 1; 00530 } else { 00531 detphi = delta/sin(theta*static_cast<float>(dgr_to_rad)); 00532 lt = int((p2 - p1)/detphi)-1; 00533 if (lt < 1) lt = 1; 00534 detphi = (p2 - p1)/lt; 00535 } 00536 for (int i = 0; i < lt; i++) { 00537 float phi = p1 + i*detphi; 00538 if (skip&&(90.0 == theta)&&(phi > 180.0)) continue; 00539 angles.push_back(phi); 00540 angles.push_back(theta); 00541 angles.push_back(psi); 00542 } 00543 } 00544 return angles; 00545 }
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 21038 of file util_sparx.cpp.
References k_means_cont_table_().
Referenced by initial_prune().
21038 { 21039 21040 21041 if (size_next <= T) return 0; 21042 21043 // take the intx of next and cur 21044 int* curintx2(0); 21045 int nintx = Util::k_means_cont_table_(curintx, next+2, curintx2, size_curintx, size_next,0); 21046 if (nintx <= T) return 0; 21047 21048 int old_depth=depth; 21049 if (depth == partref) depth = depth + 1; // we skip classes in partref 21050 if (depth == nParts && old_depth>0) return 1; 21051 21052 // have not yet reached a leaf, and current weight is still greather than T, so keep on going. 21053 21054 curintx2 = new int[nintx]; // put the intersection set in here 21055 Util::k_means_cont_table_(curintx,next+2,curintx2, size_curintx, size_next,1); 21056 21057 // if (old_depth > 0) {delete[] curintx;} // don't delete when depth == 0 because curintx in that case is a pointer into Parts 21058 21059 // we now consider each of the classes in partition (depth+1) in turn 21060 bool gt_thresh; 21061 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 21062 21063 for (int i=0; i < num_classes; i++){ 21064 if (Parts[depth][i][1] < 1) continue; // class is not active so move on 21065 size_next = dimClasses[depth*K + Parts[depth][i][0] ]-2; 21066 gt_thresh = explore(Parts,dimClasses, nParts, K, T, partref, curintx2,nintx, Parts[depth][i], size_next, depth+1); 21067 if (gt_thresh) { delete[] curintx2; return 1; } 21068 } 21069 delete[] curintx2; 21070 return 0; 21071 }
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 20872 of file util_sparx.cpp.
References explore2(), and k_means_cont_table_().
20872 { 20873 20874 // depth is the level which is going to be explored in the current iteration 20875 int* curintx2(0); 20876 int nintx = size_curintx; 20877 20878 20879 // 2. take the intx of next and cur. Prune if <= T 20880 if (depth >0){ 20881 nintx = Util::k_means_cont_table_(curintx,next, curintx2, size_curintx, size_next,0); 20882 if (nintx <= T) return; //prune! 20883 } 20884 20885 // 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 20886 if (depth == (nParts-1)) { 20887 20888 int replace = 0; 20889 int ind_smallest = -1; 20890 int smallest_cost = -1; 20891 20892 for (int jit = 0; jit < J; jit++){ 20893 if (*(costlist+jit) < nintx){ 20894 replace = 1; 20895 if (ind_smallest == -1) {ind_smallest = jit; smallest_cost = *(costlist+jit);} 20896 if (*(costlist+jit) < smallest_cost) {ind_smallest = jit; smallest_cost = *(costlist+jit);} 20897 } 20898 } 20899 20900 if (replace > 0){ 20901 // replace the smallest cost in matchlist with the current stuff 20902 *(costlist + ind_smallest) = nintx; 20903 for (int xit = 0; xit < nParts; xit++) 20904 *(matchlist + ind_smallest*nParts + xit) = *(curbranch+xit); 20905 20906 } 20907 20908 return; 20909 } 20910 20911 20912 // 3. have not yet reached a leaf, and current weight is still greather than T, so keep on going. 20913 20914 if (depth > 0){ 20915 curintx2 = new int[nintx]; // put the intersection set in here 20916 Util::k_means_cont_table_(curintx,next,curintx2, size_curintx, size_next,1); 20917 } 20918 20919 if (depth == 0){ 20920 // set curintx2 to curintx 20921 curintx2 = new int[size_curintx]; 20922 for (int cp = 0; cp < size_curintx; cp++) *(curintx2+cp) = *(curintx+cp); 20923 } 20924 20925 20926 // recursion (non-leaf case) 20927 depth=depth+1; 20928 // we now consider each of the classes in partition depth and recurse upon each of them 20929 for (int i=0; i < K; i++){ 20930 20931 if (*(argParts + Indices[depth*K+i] + 1) < 1) continue; // class is not active so move on 20932 size_next = (*(dimClasses + depth*K+i ))-2; 20933 if (size_next <= T) continue; 20934 *(curbranch+depth) = i; 20935 Util::explore2(argParts,Indices, dimClasses, nParts, K, T, curintx2, nintx, argParts + Indices[depth*K+i] + 2, size_next, depth,J, matchlist, 20936 costlist, curbranch); 20937 20938 } 20939 20940 delete[] curintx2; 20941 }
complex< float > Util::extractpoint2 | ( | int | nx, | |
int | ny, | |||
float | nuxnew, | |||
float | nuynew, | |||
EMData * | fimage, | |||
Util::KaiserBessel & | kb | |||
) | [static] |
Definition at line 1689 of file util_sparx.cpp.
References EMAN::EMData::cmplx(), EMAN::Util::KaiserBessel::i0win_tab(), ImageDimensionException, and round().
01689 { 01690 01691 int nxreal = nx - 2; 01692 if (nxreal != ny) 01693 throw ImageDimensionException("extractpoint requires ny == nx"); 01694 int nhalf = nxreal/2; 01695 bool flip = (nuxnew < 0.f); 01696 if (flip) { 01697 nuxnew *= -1; 01698 nuynew *= -1; 01699 } 01700 if (nuynew >= nhalf-0.5) { 01701 nuynew -= nxreal; 01702 } else if (nuynew < -nhalf-0.5) { 01703 nuynew += nxreal; 01704 } 01705 01706 // put (xnew,ynew) on a grid. The indices will be wrong for 01707 // the Fourier elements in the image, but the grid sizing will 01708 // be correct. 01709 int ixn = int(Util::round(nuxnew)); 01710 int iyn = int(Util::round(nuynew)); 01711 01712 // set up some temporary weighting arrays 01713 static float wy[7]; 01714 static float wx[7]; 01715 01716 float iynn = nuynew - iyn; 01717 wy[0] = kb.i0win_tab(iynn+3); 01718 wy[1] = kb.i0win_tab(iynn+2); 01719 wy[2] = kb.i0win_tab(iynn+1); 01720 wy[3] = kb.i0win_tab(iynn); 01721 wy[4] = kb.i0win_tab(iynn-1); 01722 wy[5] = kb.i0win_tab(iynn-2); 01723 wy[6] = kb.i0win_tab(iynn-3); 01724 01725 float ixnn = nuxnew - ixn; 01726 wx[0] = kb.i0win_tab(ixnn+3); 01727 wx[1] = kb.i0win_tab(ixnn+2); 01728 wx[2] = kb.i0win_tab(ixnn+1); 01729 wx[3] = kb.i0win_tab(ixnn); 01730 wx[4] = kb.i0win_tab(ixnn-1); 01731 wx[5] = kb.i0win_tab(ixnn-2); 01732 wx[6] = kb.i0win_tab(ixnn-3); 01733 01734 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]); 01735 01736 complex<float> result(0.f,0.f); 01737 if ((ixn >= 3) && (ixn <= nhalf-3) && (iyn >= -nhalf+3) && (iyn <= nhalf-4)) { 01738 // (xin,yin) not within window border from the edge 01739 for (int iy = 0; iy < 7; iy++) { 01740 int iyp = iyn + iy - 3 ; 01741 for (int ix = 0; ix < 7; ix++) { 01742 int ixp = ixn + ix - 3; 01743 float w = wx[ix]*wy[iy]; 01744 complex<float> val = fimage->cmplx(ixp,iyp); 01745 result += val*w; 01746 } 01747 } 01748 } else { 01749 // points that "stick out" 01750 for (int iy = 0; iy < 7; iy++) { 01751 int iyp = iyn + iy - 3; 01752 for (int ix = 0; ix < 7; ix++) { 01753 int ixp = ixn + ix - 3; 01754 bool mirror = false; 01755 int ixt = ixp, iyt = iyp; 01756 if (ixt < 0) { 01757 ixt = -ixt; 01758 iyt = -iyt; 01759 mirror = !mirror; 01760 } 01761 if (ixt > nhalf) { 01762 ixt = nxreal - ixt; 01763 iyt = -iyt; 01764 mirror = !mirror; 01765 } 01766 if (iyt > nhalf-1) iyt -= nxreal; 01767 if (iyt < -nhalf) iyt += nxreal; 01768 float w = wx[ix]*wy[iy]; 01769 complex<float> val = fimage->cmplx(ixt,iyt); 01770 if (mirror) result += conj(val)*w; 01771 else result += val*w; 01772 } 01773 } 01774 } 01775 if (flip) result = conj(result)/wsum; 01776 else result /= wsum; 01777 return result; 01778 }
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 1688 of file util.h.
Referenced by EMAN::CtfAverager::add_image(), EMAN::CircularMaskProcessor::calc_locals(), EMAN::EMData::cut_slice(), EMAN::EMData::dot_rotate_translate(), EMAN::EMData::extract_box(), EMAN::CtfAverager::finish(), EMAN::SymSearchProcessor::process_inplace(), EMAN::AddRandomNoiseProcessor::process_inplace(), EMAN::RotationalAverageProcessor::process_inplace(), 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 2622 of file util_sparx.cpp.
References abs, bi, br, sgn(), status, t, and tab1.
Referenced by fftr_d().
02623 { 02624 double rni,sgn,tr1,tr2,ti1,ti2; 02625 double cc,c,ss,s,t,x2,x3,x4,x5; 02626 int b3,b4,b5,b6,b7,b56; 02627 int n, k, l, j, i, ix0, ix1, status=0; 02628 02629 const double tab1[] = { 02630 9.58737990959775e-5, 02631 1.91747597310703e-4, 02632 3.83495187571395e-4, 02633 7.66990318742704e-4, 02634 1.53398018628476e-3, 02635 3.06795676296598e-3, 02636 6.13588464915449e-3, 02637 1.22715382857199e-2, 02638 2.45412285229123e-2, 02639 4.90676743274181e-2, 02640 9.80171403295604e-2, 02641 1.95090322016128e-1, 02642 3.82683432365090e-1, 02643 7.07106781186546e-1, 02644 1.00000000000000, 02645 }; 02646 02647 n=(int)pow(2.0f,ln); 02648 02649 k=abs(ks); 02650 l=16-ln; 02651 b3=n*k; 02652 b6=b3; 02653 b7=k; 02654 if (ks > 0) { 02655 sgn=1.0f; 02656 } else { 02657 sgn=-1.0f; 02658 rni=1.0f/(float)(n); 02659 j=1; 02660 for (i=1; i<=n; i++) { 02661 br(j)=br(j)*rni; 02662 bi(j)=bi(j)*rni; 02663 j=j+k; 02664 } 02665 } 02666 02667 L12: 02668 b6=b6/2; 02669 b5=b6; 02670 b4=2*b6; 02671 b56=b5-b6; 02672 02673 L14: 02674 tr1=br(b5+1); 02675 ti1=bi(b5+1); 02676 tr2=br(b56+1); 02677 ti2=bi(b56+1); 02678 02679 br(b5+1)=tr2-tr1; 02680 bi(b5+1)=ti2-ti1; 02681 br(b56+1)=tr1+tr2; 02682 bi(b56+1)=ti1+ti2; 02683 02684 b5=b5+b4; 02685 b56=b5-b6; 02686 if ( b5 <= b3 ) goto L14; 02687 if ( b6 == b7 ) goto L20; 02688 02689 b4=b7; 02690 cc=2.0f*pow(tab1(l),2); 02691 c=1.0f-cc; 02692 l++; 02693 ss=sgn*tab1(l); 02694 s=ss; 02695 02696 L16: 02697 b5=b6+b4; 02698 b4=2*b6; 02699 b56=b5-b6; 02700 02701 L18: 02702 tr1=br(b5+1); 02703 ti1=bi(b5+1); 02704 tr2=br(b56+1); 02705 ti2=bi(b56+1); 02706 br(b5+1)=c*(tr2-tr1)-s*(ti2-ti1); 02707 bi(b5+1)=s*(tr2-tr1)+c*(ti2-ti1); 02708 br(b56+1)=tr1+tr2; 02709 bi(b56+1)=ti1+ti2; 02710 02711 b5=b5+b4; 02712 b56=b5-b6; 02713 if ( b5 <= b3 ) goto L18; 02714 b4=b5-b6; 02715 b5=b4-b3; 02716 c=-c; 02717 b4=b6-b5; 02718 if ( b5 < b4 ) goto L16; 02719 b4=b4+b7; 02720 if ( b4 >= b5 ) goto L12; 02721 02722 t=c-cc*c-ss*s; 02723 s=s+ss*c-cc*s; 02724 c=t; 02725 goto L16; 02726 02727 L20: 02728 ix0=b3/2; 02729 b3=b3-b7; 02730 b4=0; 02731 b5=0; 02732 b6=ix0; 02733 ix1=0; 02734 if (b6 == b7) goto EXIT; 02735 02736 L22: 02737 b4=b3-b4; 02738 b5=b3-b5; 02739 x2=br(b4+1); 02740 x3=br(b5+1); 02741 x4=bi(b4+1); 02742 x5=bi(b5+1); 02743 br(b4+1)=x3; 02744 br(b5+1)=x2; 02745 bi(b4+1)=x5; 02746 bi(b5+1)=x4; 02747 if(b6 < b4) goto L22; 02748 02749 L24: 02750 b4=b4+b7; 02751 b5=b6+b5; 02752 x2=br(b4+1); 02753 x3=br(b5+1); 02754 x4=bi(b4+1); 02755 x5=bi(b5+1); 02756 br(b4+1)=x3; 02757 br(b5+1)=x2; 02758 bi(b4+1)=x5; 02759 bi(b5+1)=x4; 02760 ix0=b6; 02761 02762 L26: 02763 ix0=ix0/2; 02764 ix1=ix1-ix0; 02765 if( ix1 >= 0) goto L26; 02766 02767 ix0=2*ix0; 02768 b4=b4+b7; 02769 ix1=ix1+ix0; 02770 b5=ix1; 02771 if ( b5 >= b4) goto L22; 02772 if ( b4 < b6) goto L24; 02773 02774 EXIT: 02775 status = 0; 02776 }
void Util::fftc_q | ( | float * | br, | |
float * | bi, | |||
int | ln, | |||
int | ks | |||
) | [static] |
Definition at line 2779 of file util_sparx.cpp.
References abs, bi, br, sgn(), status, t, and tab1.
Referenced by fftr_q().
02780 { 02781 // dimension br(1),bi(1) 02782 02783 int b3,b4,b5,b6,b7,b56; 02784 int n, k, l, j, i, ix0, ix1; 02785 float rni, tr1, ti1, tr2, ti2, cc, c, ss, s, t, x2, x3, x4, x5, sgn; 02786 int status=0; 02787 02788 const float tab1[] = { 02789 9.58737990959775e-5f, 02790 1.91747597310703e-4f, 02791 3.83495187571395e-4f, 02792 7.66990318742704e-4f, 02793 1.53398018628476e-3f, 02794 3.06795676296598e-3f, 02795 6.13588464915449e-3f, 02796 1.22715382857199e-2f, 02797 2.45412285229123e-2f, 02798 4.90676743274181e-2f, 02799 9.80171403295604e-2f, 02800 1.95090322016128e-1f, 02801 3.82683432365090e-1f, 02802 7.07106781186546e-1f, 02803 1.00000000000000f, 02804 }; 02805 02806 n=(int)pow(2.0f,ln); 02807 02808 k=abs(ks); 02809 l=16-ln; 02810 b3=n*k; 02811 b6=b3; 02812 b7=k; 02813 if( ks > 0 ) { 02814 sgn=1.0f; 02815 } else { 02816 sgn=-1.0f; 02817 rni=1.0f/(float)n; 02818 j=1; 02819 for (i=1; i<=n; i++) { 02820 br(j)=br(j)*rni; 02821 bi(j)=bi(j)*rni; 02822 j=j+k; 02823 } 02824 } 02825 L12: 02826 b6=b6/2; 02827 b5=b6; 02828 b4=2*b6; 02829 b56=b5-b6; 02830 L14: 02831 tr1=br(b5+1); 02832 ti1=bi(b5+1); 02833 02834 tr2=br(b56+1); 02835 ti2=bi(b56+1); 02836 02837 br(b5+1)=tr2-tr1; 02838 bi(b5+1)=ti2-ti1; 02839 br(b56+1)=tr1+tr2; 02840 bi(b56+1)=ti1+ti2; 02841 02842 b5=b5+b4; 02843 b56=b5-b6; 02844 if ( b5 <= b3 ) goto L14; 02845 if ( b6 == b7 ) goto L20; 02846 02847 b4=b7; 02848 cc=2.0f*pow(tab1(l),2); 02849 c=1.0f-cc; 02850 l++; 02851 ss=sgn*tab1(l); 02852 s=ss; 02853 L16: 02854 b5=b6+b4; 02855 b4=2*b6; 02856 b56=b5-b6; 02857 L18: 02858 tr1=br(b5+1); 02859 ti1=bi(b5+1); 02860 tr2=br(b56+1); 02861 ti2=bi(b56+1); 02862 br(b5+1)=c*(tr2-tr1)-s*(ti2-ti1); 02863 bi(b5+1)=s*(tr2-tr1)+c*(ti2-ti1); 02864 br(b56+1)=tr1+tr2; 02865 bi(b56+1)=ti1+ti2; 02866 02867 b5=b5+b4; 02868 b56=b5-b6; 02869 if(b5 <= b3) goto L18; 02870 b4=b5-b6; 02871 b5=b4-b3; 02872 c=-c; 02873 b4=b6-b5; 02874 if(b5 < b4) goto L16; 02875 b4=b4+b7; 02876 if(b4 >= b5) goto L12; 02877 02878 t=c-cc*c-ss*s; 02879 s=s+ss*c-cc*s; 02880 c=t; 02881 goto L16; 02882 L20: 02883 ix0=b3/2; 02884 b3=b3-b7; 02885 b4=0; 02886 b5=0; 02887 b6=ix0; 02888 ix1=0; 02889 if ( b6 == b7) goto EXIT; 02890 L22: 02891 b4=b3-b4; 02892 b5=b3-b5; 02893 x2=br(b4+1); 02894 x3=br(b5+1); 02895 x4=bi(b4+1); 02896 x5=bi(b5+1); 02897 br(b4+1)=x3; 02898 br(b5+1)=x2; 02899 bi(b4+1)=x5; 02900 bi(b5+1)=x4; 02901 if (b6 < b4) goto L22; 02902 L24: 02903 b4=b4+b7; 02904 b5=b6+b5; 02905 x2=br(b4+1); 02906 x3=br(b5+1); 02907 x4=bi(b4+1); 02908 x5=bi(b5+1); 02909 br(b4+1)=x3; 02910 br(b5+1)=x2; 02911 bi(b4+1)=x5; 02912 bi(b5+1)=x4; 02913 ix0=b6; 02914 L26: 02915 ix0=ix0/2; 02916 ix1=ix1-ix0; 02917 if(ix1 >= 0) goto L26; 02918 02919 ix0=2*ix0; 02920 b4=b4+b7; 02921 ix1=ix1+ix0; 02922 b5=ix1; 02923 if (b5 >= b4) goto L22; 02924 if (b4 < b6) goto L24; 02925 EXIT: 02926 status = 0; 02927 }
void Util::fftr_d | ( | double * | xcmplx, | |
int | nv | |||
) | [static] |
Definition at line 3011 of file util_sparx.cpp.
References abs, fftc_d(), t, tab1, and xcmplx.
Referenced by Crosrng_e(), Crosrng_ew(), Crosrng_ms(), Crosrng_ms_delta(), Crosrng_msg(), Crosrng_msg_m(), Crosrng_msg_s(), Crosrng_ns(), Crosrng_psi_0_180(), Crosrng_psi_0_180_no_mirror(), and Crosrng_sm_psi().
03012 { 03013 // double precision x(2,1) 03014 int i1, i2, nu, inv, nu1, n, isub, n2, i; 03015 double tr1,tr2,ti1,ti2,tr,ti; 03016 double cc,c,ss,s,t; 03017 const double tab1[] = { 03018 9.58737990959775e-5, 03019 1.91747597310703e-4, 03020 3.83495187571395e-4, 03021 7.66990318742704e-4, 03022 1.53398018628476e-3, 03023 3.06795676296598e-3, 03024 6.13588464915449e-3, 03025 1.22715382857199e-2, 03026 2.45412285229123e-2, 03027 4.90676743274181e-2, 03028 9.80171403295604e-2, 03029 1.95090322016128e-1, 03030 3.82683432365090e-1, 03031 7.07106781186546e-1, 03032 1.00000000000000, 03033 }; 03034 03035 nu=abs(nv); 03036 inv=nv/nu; 03037 nu1=nu-1; 03038 n=(int)pow(2.0f,nu1); 03039 isub=16-nu1; 03040 ss=-tab1(isub); 03041 cc=-2.0*pow(tab1(isub-1),2); 03042 c=1.0f; 03043 s=0.0f; 03044 n2=n/2; 03045 03046 if ( inv > 0 ) { 03047 fftc_d(&xcmplx(1,1),&xcmplx(2,1),nu1,2); 03048 tr=xcmplx(1,1); 03049 ti=xcmplx(2,1); 03050 xcmplx(1,1)=tr+ti; 03051 xcmplx(2,1)=tr-ti; 03052 for (i=1;i<=n2;i++) { 03053 i1=i+1; 03054 i2=n-i+1; 03055 tr1=xcmplx(1,i1); 03056 tr2=xcmplx(1,i2); 03057 ti1=xcmplx(2,i1); 03058 ti2=xcmplx(2,i2); 03059 t=(cc*c-ss*s)+c; 03060 s=(cc*s+ss*c)+s; 03061 c=t; 03062 xcmplx(1,i1)=0.5*((tr1+tr2)+(ti1+ti2)*c-(tr1-tr2)*s); 03063 xcmplx(1,i2)=0.5*((tr1+tr2)-(ti1+ti2)*c+(tr1-tr2)*s); 03064 xcmplx(2,i1)=0.5*((ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c); 03065 xcmplx(2,i2)=0.5*(-(ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c); 03066 } 03067 } else { 03068 tr=xcmplx(1,1); 03069 ti=xcmplx(2,1); 03070 xcmplx(1,1)=0.5*(tr+ti); 03071 xcmplx(2,1)=0.5*(tr-ti); 03072 for (i=1; i<=n2; i++) { 03073 i1=i+1; 03074 i2=n-i+1; 03075 tr1=xcmplx(1,i1); 03076 tr2=xcmplx(1,i2); 03077 ti1=xcmplx(2,i1); 03078 ti2=xcmplx(2,i2); 03079 t=(cc*c-ss*s)+c; 03080 s=(cc*s+ss*c)+s; 03081 c=t; 03082 xcmplx(1,i1)=0.5*((tr1+tr2)-(tr1-tr2)*s-(ti1+ti2)*c); 03083 xcmplx(1,i2)=0.5*((tr1+tr2)+(tr1-tr2)*s+(ti1+ti2)*c); 03084 xcmplx(2,i1)=0.5*((ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s); 03085 xcmplx(2,i2)=0.5*(-(ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s); 03086 } 03087 fftc_d(&xcmplx(1,1),&xcmplx(2,1),nu1,-2); 03088 } 03089 }
void Util::fftr_q | ( | float * | xcmplx, | |
int | nv | |||
) | [static] |
Definition at line 2929 of file util_sparx.cpp.
References abs, fftc_q(), t, tab1, and xcmplx.
Referenced by Crosrng_msg_vec(), Frngs(), and Frngs_inv().
02930 { 02931 // dimension xcmplx(2,1); xcmplx(1,i) --- real, xcmplx(2,i) --- imaginary 02932 02933 int nu, inv, nu1, n, isub, n2, i1, i2, i; 02934 float ss, cc, c, s, tr, ti, tr1, tr2, ti1, ti2, t; 02935 02936 const float tab1[] = { 02937 9.58737990959775e-5f, 02938 1.91747597310703e-4f, 02939 3.83495187571395e-4f, 02940 7.66990318742704e-4f, 02941 1.53398018628476e-3f, 02942 3.06795676296598e-3f, 02943 6.13588464915449e-3f, 02944 1.22715382857199e-2f, 02945 2.45412285229123e-2f, 02946 4.90676743274181e-2f, 02947 9.80171403295604e-2f, 02948 1.95090322016128e-1f, 02949 3.82683432365090e-1f, 02950 7.07106781186546e-1f, 02951 1.00000000000000f, 02952 }; 02953 02954 nu=abs(nv); 02955 inv=nv/nu; 02956 nu1=nu-1; 02957 n=(int)pow(2.f,nu1); 02958 isub=16-nu1; 02959 02960 ss=-tab1(isub); 02961 cc=-2.0f*pow(tab1(isub-1),2.f); 02962 c=1.0f; 02963 s=0.0f; 02964 n2=n/2; 02965 if ( inv > 0) { 02966 fftc_q(&xcmplx(1,1),&xcmplx(2,1),nu1,2); 02967 tr=xcmplx(1,1); 02968 ti=xcmplx(2,1); 02969 xcmplx(1,1)=tr+ti; 02970 xcmplx(2,1)=tr-ti; 02971 for (i=1;i<=n2;i++) { 02972 i1=i+1; 02973 i2=n-i+1; 02974 tr1=xcmplx(1,i1); 02975 tr2=xcmplx(1,i2); 02976 ti1=xcmplx(2,i1); 02977 ti2=xcmplx(2,i2); 02978 t=(cc*c-ss*s)+c; 02979 s=(cc*s+ss*c)+s; 02980 c=t; 02981 xcmplx(1,i1)=0.5f*((tr1+tr2)+(ti1+ti2)*c-(tr1-tr2)*s); 02982 xcmplx(1,i2)=0.5f*((tr1+tr2)-(ti1+ti2)*c+(tr1-tr2)*s); 02983 xcmplx(2,i1)=0.5f*((ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c); 02984 xcmplx(2,i2)=0.5f*(-(ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c); 02985 } 02986 } else { 02987 tr=xcmplx(1,1); 02988 ti=xcmplx(2,1); 02989 xcmplx(1,1)=0.5f*(tr+ti); 02990 xcmplx(2,1)=0.5f*(tr-ti); 02991 for (i=1; i<=n2; i++) { 02992 i1=i+1; 02993 i2=n-i+1; 02994 tr1=xcmplx(1,i1); 02995 tr2=xcmplx(1,i2); 02996 ti1=xcmplx(2,i1); 02997 ti2=xcmplx(2,i2); 02998 t=(cc*c-ss*s)+c; 02999 s=(cc*s+ss*c)+s; 03000 c=t; 03001 xcmplx(1,i1)=0.5f*((tr1+tr2)-(tr1-tr2)*s-(ti1+ti2)*c); 03002 xcmplx(1,i2)=0.5f*((tr1+tr2)+(tr1-tr2)*s+(ti1+ti2)*c); 03003 xcmplx(2,i1)=0.5f*((ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s); 03004 xcmplx(2,i2)=0.5f*(-(ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s); 03005 } 03006 fftc_q(&xcmplx(1,1),&xcmplx(2,1),nu1,-2); 03007 } 03008 }
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 7882 of file util_sparx.cpp.
References ENTERFUNC, and EXITFUNC.
Referenced by voronoi().
07883 { 07884 ENTERFUNC; 07885 int i = k; 07886 while( i == k ) i = rand()%len; 07887 std::swap(key[i], key[k]); 07888 std::swap(x[i], x[k]); 07889 std::swap(y[i], y[k]); 07890 std::swap(z[i], z[k]); 07891 EXITFUNC; 07892 }
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 3096 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().
03096 { 03097 int nring = numr.size()/3; 03098 float *circ = circp->get_data(); 03099 int i, l; 03100 for (i=1; i<=nring;i++) { 03101 03102 #ifdef _WIN32 03103 l = (int)( log((float)numr(3,i))/log(2.0f) ); 03104 #else 03105 l=(int)(log2(numr(3,i))); 03106 #endif //_WIN32 03107 03108 fftr_q(&circ(numr(2,i)),l); 03109 } 03110 }
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 3112 of file util_sparx.cpp.
References circ, fftr_q(), EMAN::EMData::get_data(), log(), and numr.
03112 { 03113 int nring = numr.size()/3; 03114 float *circ = circp->get_data(); 03115 int i, l; 03116 for (i=1; i<=nring;i++) { 03117 03118 #ifdef _WIN32 03119 l = (int)( log((float)numr(3,i))/log(2.0f) ); 03120 #else 03121 l=(int)(log2(numr(3,i))); 03122 #endif //_WIN32 03123 03124 fftr_q(&circ(numr(2,i)),-l); 03125 } 03126 }
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 20069 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().
20070 { 20071 int nx = mg->get_xsize(); 20072 int ny = mg->get_ysize(); 20073 int nz = mg->get_zsize(); 20074 20075 EMData* visited = new EMData(); 20076 visited->set_size( nx, ny, nz ); 20077 visited->to_zero(); 20078 int grpid = 0; 20079 int maxgrp = 0; 20080 int maxsize = 0; 20081 for( int iz=0; iz < nz; ++iz ) { 20082 for( int iy=0; iy < ny; ++iy ) { 20083 for( int ix=0; ix < nx; ++ix ) { 20084 if( (*mg)(ix, iy, iz)==0.0 ) continue; 20085 20086 if( (*visited)(ix, iy, iz) > 0.0 ) { 20087 // visited before, must be in other group. 20088 continue; 20089 } 20090 20091 grpid++; 20092 int grpsize = find_group( ix, iy, iz, grpid, mg, visited ); 20093 if( grpsize > maxsize ) { 20094 maxsize = grpsize; 20095 maxgrp = grpid; 20096 } 20097 } 20098 } 20099 } 20100 20101 Assert( maxgrp > 0 ); 20102 20103 int npoint = 0; 20104 EMData* result = new EMData(); 20105 result->set_size( nx, ny, nz ); 20106 result->to_zero(); 20107 20108 for( int iz=0; iz < nz; ++iz ) { 20109 for( int iy=0; iy < ny; ++iy ) { 20110 for( int ix=0; ix < nx; ++ix ) { 20111 if( (*visited)(ix, iy, iz)==maxgrp ) { 20112 (*result)(ix,iy,iz) = 1.0; 20113 npoint++; 20114 } 20115 } 20116 } 20117 } 20118 20119 Assert( npoint==maxsize ); 20120 delete visited; 20121 return result; 20122 20123 }
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(), 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] |
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 1727 of file util.h.
Referenced by EMAN::PawelProjector::backproject3d(), EMAN::ChaoProjector::backproject3d(), EMAN::ChaoProjector::project3d(), EMAN::FourierGriddingProjector::project3d(), and EMAN::PawelProjector::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 779 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().
00779 { 00780 int K = kb.get_window_size(); 00781 int kbmin = -K/2; 00782 int kbmax = -kbmin; 00783 int kbc = kbmax+1; 00784 00785 float pixel =0.0f; 00786 float w=0.0f; 00787 00788 delx = restrict1(delx, nx); 00789 int inxold = int(round(delx)); 00790 if ( ny < 2 ) { //1D 00791 float tablex1 = kb.i0win_tab(delx-inxold+3); 00792 float tablex2 = kb.i0win_tab(delx-inxold+2); 00793 float tablex3 = kb.i0win_tab(delx-inxold+1); 00794 float tablex4 = kb.i0win_tab(delx-inxold); 00795 float tablex5 = kb.i0win_tab(delx-inxold-1); 00796 float tablex6 = kb.i0win_tab(delx-inxold-2); 00797 float tablex7 = kb.i0win_tab(delx-inxold-3); 00798 00799 int x1, x2, x3, x4, x5, x6, x7; 00800 00801 if ( inxold <= kbc || inxold >=nx-kbc-2 ) { 00802 x1 = (inxold-3+nx)%nx; 00803 x2 = (inxold-2+nx)%nx; 00804 x3 = (inxold-1+nx)%nx; 00805 x4 = (inxold +nx)%nx; 00806 x5 = (inxold+1+nx)%nx; 00807 x6 = (inxold+2+nx)%nx; 00808 x7 = (inxold+3+nx)%nx; 00809 } else { 00810 x1 = inxold-3; 00811 x2 = inxold-2; 00812 x3 = inxold-1; 00813 x4 = inxold; 00814 x5 = inxold+1; 00815 x6 = inxold+2; 00816 x7 = inxold+3; 00817 } 00818 00819 pixel = data[x1]*tablex1 + data[x2]*tablex2 + data[x3]*tablex3 + 00820 data[x4]*tablex4 + data[x5]*tablex5 + data[x6]*tablex6 + 00821 data[x7]*tablex7 ; 00822 00823 w = tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7; 00824 } else if ( nz < 2 ) { // 2D 00825 dely = restrict1(dely, ny); 00826 int inyold = int(round(dely)); 00827 float tablex1 = kb.i0win_tab(delx-inxold+3); 00828 float tablex2 = kb.i0win_tab(delx-inxold+2); 00829 float tablex3 = kb.i0win_tab(delx-inxold+1); 00830 float tablex4 = kb.i0win_tab(delx-inxold); 00831 float tablex5 = kb.i0win_tab(delx-inxold-1); 00832 float tablex6 = kb.i0win_tab(delx-inxold-2); 00833 float tablex7 = kb.i0win_tab(delx-inxold-3); 00834 00835 float tabley1 = kb.i0win_tab(dely-inyold+3); 00836 float tabley2 = kb.i0win_tab(dely-inyold+2); 00837 float tabley3 = kb.i0win_tab(dely-inyold+1); 00838 float tabley4 = kb.i0win_tab(dely-inyold); 00839 float tabley5 = kb.i0win_tab(dely-inyold-1); 00840 float tabley6 = kb.i0win_tab(dely-inyold-2); 00841 float tabley7 = kb.i0win_tab(dely-inyold-3); 00842 00843 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7; 00844 00845 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 ) { 00846 x1 = (inxold-3+nx)%nx; 00847 x2 = (inxold-2+nx)%nx; 00848 x3 = (inxold-1+nx)%nx; 00849 x4 = (inxold +nx)%nx; 00850 x5 = (inxold+1+nx)%nx; 00851 x6 = (inxold+2+nx)%nx; 00852 x7 = (inxold+3+nx)%nx; 00853 00854 y1 = ((inyold-3+ny)%ny)*nx; 00855 y2 = ((inyold-2+ny)%ny)*nx; 00856 y3 = ((inyold-1+ny)%ny)*nx; 00857 y4 = ((inyold +ny)%ny)*nx; 00858 y5 = ((inyold+1+ny)%ny)*nx; 00859 y6 = ((inyold+2+ny)%ny)*nx; 00860 y7 = ((inyold+3+ny)%ny)*nx; 00861 } else { 00862 x1 = inxold-3; 00863 x2 = inxold-2; 00864 x3 = inxold-1; 00865 x4 = inxold; 00866 x5 = inxold+1; 00867 x6 = inxold+2; 00868 x7 = inxold+3; 00869 00870 y1 = (inyold-3)*nx; 00871 y2 = (inyold-2)*nx; 00872 y3 = (inyold-1)*nx; 00873 y4 = inyold*nx; 00874 y5 = (inyold+1)*nx; 00875 y6 = (inyold+2)*nx; 00876 y7 = (inyold+3)*nx; 00877 } 00878 00879 pixel = ( data[x1+y1]*tablex1 + data[x2+y1]*tablex2 + data[x3+y1]*tablex3 + 00880 data[x4+y1]*tablex4 + data[x5+y1]*tablex5 + data[x6+y1]*tablex6 + 00881 data[x7+y1]*tablex7 ) * tabley1 + 00882 ( data[x1+y2]*tablex1 + data[x2+y2]*tablex2 + data[x3+y2]*tablex3 + 00883 data[x4+y2]*tablex4 + data[x5+y2]*tablex5 + data[x6+y2]*tablex6 + 00884 data[x7+y2]*tablex7 ) * tabley2 + 00885 ( data[x1+y3]*tablex1 + data[x2+y3]*tablex2 + data[x3+y3]*tablex3 + 00886 data[x4+y3]*tablex4 + data[x5+y3]*tablex5 + data[x6+y3]*tablex6 + 00887 data[x7+y3]*tablex7 ) * tabley3 + 00888 ( data[x1+y4]*tablex1 + data[x2+y4]*tablex2 + data[x3+y4]*tablex3 + 00889 data[x4+y4]*tablex4 + data[x5+y4]*tablex5 + data[x6+y4]*tablex6 + 00890 data[x7+y4]*tablex7 ) * tabley4 + 00891 ( data[x1+y5]*tablex1 + data[x2+y5]*tablex2 + data[x3+y5]*tablex3 + 00892 data[x4+y5]*tablex4 + data[x5+y5]*tablex5 + data[x6+y5]*tablex6 + 00893 data[x7+y5]*tablex7 ) * tabley5 + 00894 ( data[x1+y6]*tablex1 + data[x2+y6]*tablex2 + data[x3+y6]*tablex3 + 00895 data[x4+y6]*tablex4 + data[x5+y6]*tablex5 + data[x6+y6]*tablex6 + 00896 data[x7+y6]*tablex7 ) * tabley6 + 00897 ( data[x1+y7]*tablex1 + data[x2+y7]*tablex2 + data[x3+y7]*tablex3 + 00898 data[x4+y7]*tablex4 + data[x5+y7]*tablex5 + data[x6+y7]*tablex6 + 00899 data[x7+y7]*tablex7 ) * tabley7; 00900 00901 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) * 00902 (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7); 00903 } else { // 3D 00904 dely = restrict1(dely, ny); 00905 int inyold = int(Util::round(dely)); 00906 delz = restrict1(delz, nz); 00907 int inzold = int(Util::round(delz)); 00908 00909 float tablex1 = kb.i0win_tab(delx-inxold+3); 00910 float tablex2 = kb.i0win_tab(delx-inxold+2); 00911 float tablex3 = kb.i0win_tab(delx-inxold+1); 00912 float tablex4 = kb.i0win_tab(delx-inxold); 00913 float tablex5 = kb.i0win_tab(delx-inxold-1); 00914 float tablex6 = kb.i0win_tab(delx-inxold-2); 00915 float tablex7 = kb.i0win_tab(delx-inxold-3); 00916 00917 float tabley1 = kb.i0win_tab(dely-inyold+3); 00918 float tabley2 = kb.i0win_tab(dely-inyold+2); 00919 float tabley3 = kb.i0win_tab(dely-inyold+1); 00920 float tabley4 = kb.i0win_tab(dely-inyold); 00921 float tabley5 = kb.i0win_tab(dely-inyold-1); 00922 float tabley6 = kb.i0win_tab(dely-inyold-2); 00923 float tabley7 = kb.i0win_tab(dely-inyold-3); 00924 00925 float tablez1 = kb.i0win_tab(delz-inzold+3); 00926 float tablez2 = kb.i0win_tab(delz-inzold+2); 00927 float tablez3 = kb.i0win_tab(delz-inzold+1); 00928 float tablez4 = kb.i0win_tab(delz-inzold); 00929 float tablez5 = kb.i0win_tab(delz-inzold-1); 00930 float tablez6 = kb.i0win_tab(delz-inzold-2); 00931 float tablez7 = kb.i0win_tab(delz-inzold-3); 00932 00933 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7, z1, z2, z3, z4, z5, z6, z7; 00934 00935 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 || inzold <= kbc || inzold >= nz-kbc-2 ) { 00936 x1 = (inxold-3+nx)%nx; 00937 x2 = (inxold-2+nx)%nx; 00938 x3 = (inxold-1+nx)%nx; 00939 x4 = (inxold +nx)%nx; 00940 x5 = (inxold+1+nx)%nx; 00941 x6 = (inxold+2+nx)%nx; 00942 x7 = (inxold+3+nx)%nx; 00943 00944 y1 = ((inyold-3+ny)%ny)*nx; 00945 y2 = ((inyold-2+ny)%ny)*nx; 00946 y3 = ((inyold-1+ny)%ny)*nx; 00947 y4 = ((inyold +ny)%ny)*nx; 00948 y5 = ((inyold+1+ny)%ny)*nx; 00949 y6 = ((inyold+2+ny)%ny)*nx; 00950 y7 = ((inyold+3+ny)%ny)*nx; 00951 00952 z1 = ((inzold-3+nz)%nz)*nx*ny; 00953 z2 = ((inzold-2+nz)%nz)*nx*ny; 00954 z3 = ((inzold-1+nz)%nz)*nx*ny; 00955 z4 = ((inzold +nz)%nz)*nx*ny; 00956 z5 = ((inzold+1+nz)%nz)*nx*ny; 00957 z6 = ((inzold+2+nz)%nz)*nx*ny; 00958 z7 = ((inzold+3+nz)%nz)*nx*ny; 00959 } else { 00960 x1 = inxold-3; 00961 x2 = inxold-2; 00962 x3 = inxold-1; 00963 x4 = inxold; 00964 x5 = inxold+1; 00965 x6 = inxold+2; 00966 x7 = inxold+3; 00967 00968 y1 = (inyold-3)*nx; 00969 y2 = (inyold-2)*nx; 00970 y3 = (inyold-1)*nx; 00971 y4 = inyold*nx; 00972 y5 = (inyold+1)*nx; 00973 y6 = (inyold+2)*nx; 00974 y7 = (inyold+3)*nx; 00975 00976 z1 = (inzold-3)*nx*ny; 00977 z2 = (inzold-2)*nx*ny; 00978 z3 = (inzold-1)*nx*ny; 00979 z4 = inzold*nx*ny; 00980 z5 = (inzold+1)*nx*ny; 00981 z6 = (inzold+2)*nx*ny; 00982 z7 = (inzold+3)*nx*ny; 00983 } 00984 00985 pixel = ( ( data[x1+y1+z1]*tablex1 + data[x2+y1+z1]*tablex2 + data[x3+y1+z1]*tablex3 + 00986 data[x4+y1+z1]*tablex4 + data[x5+y1+z1]*tablex5 + data[x6+y1+z1]*tablex6 + 00987 data[x7+y1+z1]*tablex7 ) * tabley1 + 00988 ( data[x1+y2+z1]*tablex1 + data[x2+y2+z1]*tablex2 + data[x3+y2+z1]*tablex3 + 00989 data[x4+y2+z1]*tablex4 + data[x5+y2+z1]*tablex5 + data[x6+y2+z1]*tablex6 + 00990 data[x7+y2+z1]*tablex7 ) * tabley2 + 00991 ( data[x1+y3+z1]*tablex1 + data[x2+y3+z1]*tablex2 + data[x3+y3+z1]*tablex3 + 00992 data[x4+y3+z1]*tablex4 + data[x5+y3+z1]*tablex5 + data[x6+y3+z1]*tablex6 + 00993 data[x7+y3+z1]*tablex7 ) * tabley3 + 00994 ( data[x1+y4+z1]*tablex1 + data[x2+y4+z1]*tablex2 + data[x3+y4+z1]*tablex3 + 00995 data[x4+y4+z1]*tablex4 + data[x5+y4+z1]*tablex5 + data[x6+y4+z1]*tablex6 + 00996 data[x7+y4+z1]*tablex7 ) * tabley4 + 00997 ( data[x1+y5+z1]*tablex1 + data[x2+y5+z1]*tablex2 + data[x3+y5+z1]*tablex3 + 00998 data[x4+y5+z1]*tablex4 + data[x5+y5+z1]*tablex5 + data[x6+y5+z1]*tablex6 + 00999 data[x7+y5+z1]*tablex7 ) * tabley5 + 01000 ( data[x1+y6+z1]*tablex1 + data[x2+y6+z1]*tablex2 + data[x3+y6+z1]*tablex3 + 01001 data[x4+y6+z1]*tablex4 + data[x5+y6+z1]*tablex5 + data[x6+y6+z1]*tablex6 + 01002 data[x7+y6+z1]*tablex7 ) * tabley6 + 01003 ( data[x1+y7+z1]*tablex1 + data[x2+y7+z1]*tablex2 + data[x3+y7+z1]*tablex3 + 01004 data[x4+y7+z1]*tablex4 + data[x5+y7+z1]*tablex5 + data[x6+y7+z1]*tablex6 + 01005 data[x7+y7+z1]*tablex7 ) * tabley7 ) *tablez1 + 01006 ( ( data[x1+y1+z2]*tablex1 + data[x2+y1+z2]*tablex2 + data[x3+y1+z2]*tablex3 + 01007 data[x4+y1+z2]*tablex4 + data[x5+y1+z2]*tablex5 + data[x6+y1+z2]*tablex6 + 01008 data[x7+y1+z2]*tablex7 ) * tabley1 + 01009 ( data[x1+y2+z2]*tablex1 + data[x2+y2+z2]*tablex2 + data[x3+y2+z2]*tablex3 + 01010 data[x4+y2+z2]*tablex4 + data[x5+y2+z2]*tablex5 + data[x6+y2+z2]*tablex6 + 01011 data[x7+y2+z2]*tablex7 ) * tabley2 + 01012 ( data[x1+y3+z2]*tablex1 + data[x2+y3+z2]*tablex2 + data[x3+y3+z2]*tablex3 + 01013 data[x4+y3+z2]*tablex4 + data[x5+y3+z2]*tablex5 + data[x6+y3+z2]*tablex6 + 01014 data[x7+y3+z2]*tablex7 ) * tabley3 + 01015 ( data[x1+y4+z2]*tablex1 + data[x2+y4+z2]*tablex2 + data[x3+y4+z2]*tablex3 + 01016 data[x4+y4+z2]*tablex4 + data[x5+y4+z2]*tablex5 + data[x6+y4+z2]*tablex6 + 01017 data[x7+y4+z2]*tablex7 ) * tabley4 + 01018 ( data[x1+y5+z2]*tablex1 + data[x2+y5+z2]*tablex2 + data[x3+y5+z2]*tablex3 + 01019 data[x4+y5+z2]*tablex4 + data[x5+y5+z2]*tablex5 + data[x6+y5+z2]*tablex6 + 01020 data[x7+y5+z2]*tablex7 ) * tabley5 + 01021 ( data[x1+y6+z2]*tablex1 + data[x2+y6+z2]*tablex2 + data[x3+y6+z2]*tablex3 + 01022 data[x4+y6+z2]*tablex4 + data[x5+y6+z2]*tablex5 + data[x6+y6+z2]*tablex6 + 01023 data[x7+y6+z2]*tablex7 ) * tabley6 + 01024 ( data[x1+y7+z2]*tablex1 + data[x2+y7+z2]*tablex2 + data[x3+y7+z2]*tablex3 + 01025 data[x4+y7+z2]*tablex4 + data[x5+y7+z2]*tablex5 + data[x6+y7+z2]*tablex6 + 01026 data[x7+y7+z2]*tablex7 ) * tabley7 ) *tablez2 + 01027 ( ( data[x1+y1+z3]*tablex1 + data[x2+y1+z3]*tablex2 + data[x3+y1+z3]*tablex3 + 01028 data[x4+y1+z3]*tablex4 + data[x5+y1+z3]*tablex5 + data[x6+y1+z3]*tablex6 + 01029 data[x7+y1+z3]*tablex7 ) * tabley1 + 01030 ( data[x1+y2+z3]*tablex1 + data[x2+y2+z3]*tablex2 + data[x3+y2+z3]*tablex3 + 01031 data[x4+y2+z3]*tablex4 + data[x5+y2+z3]*tablex5 + data[x6+y2+z3]*tablex6 + 01032 data[x7+y2+z3]*tablex7 ) * tabley2 + 01033 ( data[x1+y3+z3]*tablex1 + data[x2+y3+z3]*tablex2 + data[x3+y3+z3]*tablex3 + 01034 data[x4+y3+z3]*tablex4 + data[x5+y3+z3]*tablex5 + data[x6+y3+z3]*tablex6 + 01035 data[x7+y3+z3]*tablex7 ) * tabley3 + 01036 ( data[x1+y4+z3]*tablex1 + data[x2+y4+z3]*tablex2 + data[x3+y4+z3]*tablex3 + 01037 data[x4+y4+z3]*tablex4 + data[x5+y4+z3]*tablex5 + data[x6+y4+z3]*tablex6 + 01038 data[x7+y4+z3]*tablex7 ) * tabley4 + 01039 ( data[x1+y5+z3]*tablex1 + data[x2+y5+z3]*tablex2 + data[x3+y5+z3]*tablex3 + 01040 data[x4+y5+z3]*tablex4 + data[x5+y5+z3]*tablex5 + data[x6+y5+z3]*tablex6 + 01041 data[x7+y5+z3]*tablex7 ) * tabley5 + 01042 ( data[x1+y6+z3]*tablex1 + data[x2+y6+z3]*tablex2 + data[x3+y6+z3]*tablex3 + 01043 data[x4+y6+z3]*tablex4 + data[x5+y6+z3]*tablex5 + data[x6+y6+z3]*tablex6 + 01044 data[x7+y6+z3]*tablex7 ) * tabley6 + 01045 ( data[x1+y7+z3]*tablex1 + data[x2+y7+z3]*tablex2 + data[x3+y7+z3]*tablex3 + 01046 data[x4+y7+z3]*tablex4 + data[x5+y7+z3]*tablex5 + data[x6+y7+z3]*tablex6 + 01047 data[x7+y7+z3]*tablex7 ) * tabley7 ) *tablez3 + 01048 ( ( data[x1+y1+z4]*tablex1 + data[x2+y1+z4]*tablex2 + data[x3+y1+z4]*tablex3 + 01049 data[x4+y1+z4]*tablex4 + data[x5+y1+z4]*tablex5 + data[x6+y1+z4]*tablex6 + 01050 data[x7+y1+z4]*tablex7 ) * tabley1 + 01051 ( data[x1+y2+z4]*tablex1 + data[x2+y2+z4]*tablex2 + data[x3+y2+z4]*tablex3 + 01052 data[x4+y2+z4]*tablex4 + data[x5+y2+z4]*tablex5 + data[x6+y2+z4]*tablex6 + 01053 data[x7+y2+z4]*tablex7 ) * tabley2 + 01054 ( data[x1+y3+z4]*tablex1 + data[x2+y3+z4]*tablex2 + data[x3+y3+z4]*tablex3 + 01055 data[x4+y3+z4]*tablex4 + data[x5+y3+z4]*tablex5 + data[x6+y3+z4]*tablex6 + 01056 data[x7+y3+z4]*tablex7 ) * tabley3 + 01057 ( data[x1+y4+z4]*tablex1 + data[x2+y4+z4]*tablex2 + data[x3+y4+z4]*tablex3 + 01058 data[x4+y4+z4]*tablex4 + data[x5+y4+z4]*tablex5 + data[x6+y4+z4]*tablex6 + 01059 data[x7+y4+z4]*tablex7 ) * tabley4 + 01060 ( data[x1+y5+z4]*tablex1 + data[x2+y5+z4]*tablex2 + data[x3+y5+z4]*tablex3 + 01061 data[x4+y5+z4]*tablex4 + data[x5+y5+z4]*tablex5 + data[x6+y5+z4]*tablex6 + 01062 data[x7+y5+z4]*tablex7 ) * tabley5 + 01063 ( data[x1+y6+z4]*tablex1 + data[x2+y6+z4]*tablex2 + data[x3+y6+z4]*tablex3 + 01064 data[x4+y6+z4]*tablex4 + data[x5+y6+z4]*tablex5 + data[x6+y6+z4]*tablex6 + 01065 data[x7+y6+z4]*tablex7 ) * tabley6 + 01066 ( data[x1+y7+z4]*tablex1 + data[x2+y7+z4]*tablex2 + data[x3+y7+z4]*tablex3 + 01067 data[x4+y7+z4]*tablex4 + data[x5+y7+z4]*tablex5 + data[x6+y7+z4]*tablex6 + 01068 data[x7+y7+z4]*tablex7 ) * tabley7 ) *tablez4 + 01069 ( ( data[x1+y1+z5]*tablex1 + data[x2+y1+z5]*tablex2 + data[x3+y1+z5]*tablex3 + 01070 data[x4+y1+z5]*tablex4 + data[x5+y1+z5]*tablex5 + data[x6+y1+z5]*tablex6 + 01071 data[x7+y1+z5]*tablex7 ) * tabley1 + 01072 ( data[x1+y2+z5]*tablex1 + data[x2+y2+z5]*tablex2 + data[x3+y2+z5]*tablex3 + 01073 data[x4+y2+z5]*tablex4 + data[x5+y2+z5]*tablex5 + data[x6+y2+z5]*tablex6 + 01074 data[x7+y2+z5]*tablex7 ) * tabley2 + 01075 ( data[x1+y3+z5]*tablex1 + data[x2+y3+z5]*tablex2 + data[x3+y3+z5]*tablex3 + 01076 data[x4+y3+z5]*tablex4 + data[x5+y3+z5]*tablex5 + data[x6+y3+z5]*tablex6 + 01077 data[x7+y3+z5]*tablex7 ) * tabley3 + 01078 ( data[x1+y4+z5]*tablex1 + data[x2+y4+z5]*tablex2 + data[x3+y4+z5]*tablex3 + 01079 data[x4+y4+z5]*tablex4 + data[x5+y4+z5]*tablex5 + data[x6+y4+z5]*tablex6 + 01080 data[x7+y4+z5]*tablex7 ) * tabley4 + 01081 ( data[x1+y5+z5]*tablex1 + data[x2+y5+z5]*tablex2 + data[x3+y5+z5]*tablex3 + 01082 data[x4+y5+z5]*tablex4 + data[x5+y5+z5]*tablex5 + data[x6+y5+z5]*tablex6 + 01083 data[x7+y5+z5]*tablex7 ) * tabley5 + 01084 ( data[x1+y6+z5]*tablex1 + data[x2+y6+z5]*tablex2 + data[x3+y6+z5]*tablex3 + 01085 data[x4+y6+z5]*tablex4 + data[x5+y6+z5]*tablex5 + data[x6+y6+z5]*tablex6 + 01086 data[x7+y6+z5]*tablex7 ) * tabley6 + 01087 ( data[x1+y7+z5]*tablex1 + data[x2+y7+z5]*tablex2 + data[x3+y7+z5]*tablex3 + 01088 data[x4+y7+z5]*tablex4 + data[x5+y7+z5]*tablex5 + data[x6+y7+z5]*tablex6 + 01089 data[x7+y7+z5]*tablex7 ) * tabley7 ) *tablez5 + 01090 ( ( data[x1+y1+z6]*tablex1 + data[x2+y1+z6]*tablex2 + data[x3+y1+z6]*tablex3 + 01091 data[x4+y1+z6]*tablex4 + data[x5+y1+z6]*tablex5 + data[x6+y1+z6]*tablex6 + 01092 data[x7+y1+z6]*tablex7 ) * tabley1 + 01093 ( data[x1+y2+z6]*tablex1 + data[x2+y2+z6]*tablex2 + data[x3+y2+z6]*tablex3 + 01094 data[x4+y2+z6]*tablex4 + data[x5+y2+z6]*tablex5 + data[x6+y2+z6]*tablex6 + 01095 data[x7+y2+z6]*tablex7 ) * tabley2 + 01096 ( data[x1+y3+z6]*tablex1 + data[x2+y3+z6]*tablex2 + data[x3+y3+z6]*tablex3 + 01097 data[x4+y3+z6]*tablex4 + data[x5+y3+z6]*tablex5 + data[x6+y3+z6]*tablex6 + 01098 data[x7+y3+z6]*tablex7 ) * tabley3 + 01099 ( data[x1+y4+z6]*tablex1 + data[x2+y4+z6]*tablex2 + data[x3+y4+z6]*tablex3 + 01100 data[x4+y4+z6]*tablex4 + data[x5+y4+z6]*tablex5 + data[x6+y4+z6]*tablex6 + 01101 data[x7+y4+z6]*tablex7 ) * tabley4 + 01102 ( data[x1+y5+z6]*tablex1 + data[x2+y5+z6]*tablex2 + data[x3+y5+z6]*tablex3 + 01103 data[x4+y5+z6]*tablex4 + data[x5+y5+z6]*tablex5 + data[x6+y5+z6]*tablex6 + 01104 data[x7+y5+z6]*tablex7 ) * tabley5 + 01105 ( data[x1+y6+z6]*tablex1 + data[x2+y6+z6]*tablex2 + data[x3+y6+z6]*tablex3 + 01106 data[x4+y6+z6]*tablex4 + data[x5+y6+z6]*tablex5 + data[x6+y6+z6]*tablex6 + 01107 data[x7+y6+z6]*tablex7 ) * tabley6 + 01108 ( data[x1+y7+z6]*tablex1 + data[x2+y7+z6]*tablex2 + data[x3+y7+z6]*tablex3 + 01109 data[x4+y7+z6]*tablex4 + data[x5+y7+z6]*tablex5 + data[x6+y7+z6]*tablex6 + 01110 data[x7+y7+z6]*tablex7 ) * tabley7 ) *tablez6 + 01111 ( ( data[x1+y1+z7]*tablex1 + data[x2+y1+z7]*tablex2 + data[x3+y1+z7]*tablex3 + 01112 data[x4+y1+z7]*tablex4 + data[x5+y1+z7]*tablex5 + data[x6+y1+z7]*tablex6 + 01113 data[x7+y1+z7]*tablex7 ) * tabley1 + 01114 ( data[x1+y2+z7]*tablex1 + data[x2+y2+z7]*tablex2 + data[x3+y2+z7]*tablex3 + 01115 data[x4+y2+z7]*tablex4 + data[x5+y2+z7]*tablex5 + data[x6+y2+z7]*tablex6 + 01116 data[x7+y2+z7]*tablex7 ) * tabley2 + 01117 ( data[x1+y3+z7]*tablex1 + data[x2+y3+z7]*tablex2 + data[x3+y3+z7]*tablex3 + 01118 data[x4+y3+z7]*tablex4 + data[x5+y3+z7]*tablex5 + data[x6+y3+z7]*tablex6 + 01119 data[x7+y3+z7]*tablex7 ) * tabley3 + 01120 ( data[x1+y4+z7]*tablex1 + data[x2+y4+z7]*tablex2 + data[x3+y4+z7]*tablex3 + 01121 data[x4+y4+z7]*tablex4 + data[x5+y4+z7]*tablex5 + data[x6+y4+z7]*tablex6 + 01122 data[x7+y4+z7]*tablex7 ) * tabley4 + 01123 ( data[x1+y5+z7]*tablex1 + data[x2+y5+z7]*tablex2 + data[x3+y5+z7]*tablex3 + 01124 data[x4+y5+z7]*tablex4 + data[x5+y5+z7]*tablex5 + data[x6+y5+z7]*tablex6 + 01125 data[x7+y5+z7]*tablex7 ) * tabley5 + 01126 ( data[x1+y6+z7]*tablex1 + data[x2+y6+z7]*tablex2 + data[x3+y6+z7]*tablex3 + 01127 data[x4+y6+z7]*tablex4 + data[x5+y6+z7]*tablex5 + data[x6+y6+z7]*tablex6 + 01128 data[x7+y6+z7]*tablex7 ) * tabley6 + 01129 ( data[x1+y7+z7]*tablex1 + data[x2+y7+z7]*tablex2 + data[x3+y7+z7]*tablex3 + 01130 data[x4+y7+z7]*tablex4 + data[x5+y7+z7]*tablex5 + data[x6+y7+z7]*tablex6 + 01131 data[x7+y7+z7]*tablex7 ) * tabley7 ) *tablez7; 01132 01133 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) * 01134 (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7) * 01135 (tablez1+tablez2+tablez3+tablez4+tablez5+tablez6+tablez7); 01136 } 01137 return pixel/w; 01138 }
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 1140 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().
01140 { 01141 int K = kb.get_window_size(); 01142 int kbmin = -K/2; 01143 int kbmax = -kbmin; 01144 int kbc = kbmax+1; 01145 01146 float pixel =0.0f; 01147 float w=0.0f; 01148 01149 float argdelx = delx; // adding this for 2D case where the wrap around is not done circulantly using restrict1. 01150 delx = restrict1(delx, nx); 01151 int inxold = int(round(delx)); 01152 if ( ny < 2 ) { //1D 01153 float tablex1 = kb.i0win_tab(delx-inxold+3); 01154 float tablex2 = kb.i0win_tab(delx-inxold+2); 01155 float tablex3 = kb.i0win_tab(delx-inxold+1); 01156 float tablex4 = kb.i0win_tab(delx-inxold); 01157 float tablex5 = kb.i0win_tab(delx-inxold-1); 01158 float tablex6 = kb.i0win_tab(delx-inxold-2); 01159 float tablex7 = kb.i0win_tab(delx-inxold-3); 01160 01161 int x1, x2, x3, x4, x5, x6, x7; 01162 01163 if ( inxold <= kbc || inxold >=nx-kbc-2 ) { 01164 x1 = (inxold-3+nx)%nx; 01165 x2 = (inxold-2+nx)%nx; 01166 x3 = (inxold-1+nx)%nx; 01167 x4 = (inxold +nx)%nx; 01168 x5 = (inxold+1+nx)%nx; 01169 x6 = (inxold+2+nx)%nx; 01170 x7 = (inxold+3+nx)%nx; 01171 } else { 01172 x1 = inxold-3; 01173 x2 = inxold-2; 01174 x3 = inxold-1; 01175 x4 = inxold; 01176 x5 = inxold+1; 01177 x6 = inxold+2; 01178 x7 = inxold+3; 01179 } 01180 01181 pixel = data[x1]*tablex1 + data[x2]*tablex2 + data[x3]*tablex3 + 01182 data[x4]*tablex4 + data[x5]*tablex5 + data[x6]*tablex6 + 01183 data[x7]*tablex7 ; 01184 01185 w = tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7; 01186 } else if ( nz < 2 ) { // 2D 01187 01188 delx = argdelx; 01189 // 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 01190 if ((delx < 0.0f) || (delx >= (float) (nx)) || (dely < 0.0f) || (dely >= (float) (ny)) ){ 01191 delx = (float)xnew*2.0f; 01192 dely = (float)ynew*2.0f; 01193 } 01194 01195 int inxold = int(round(delx)); 01196 int inyold = int(round(dely)); 01197 01198 float tablex1 = kb.i0win_tab(delx-inxold+3); 01199 float tablex2 = kb.i0win_tab(delx-inxold+2); 01200 float tablex3 = kb.i0win_tab(delx-inxold+1); 01201 float tablex4 = kb.i0win_tab(delx-inxold); 01202 float tablex5 = kb.i0win_tab(delx-inxold-1); 01203 float tablex6 = kb.i0win_tab(delx-inxold-2); 01204 float tablex7 = kb.i0win_tab(delx-inxold-3); 01205 01206 float tabley1 = kb.i0win_tab(dely-inyold+3); 01207 float tabley2 = kb.i0win_tab(dely-inyold+2); 01208 float tabley3 = kb.i0win_tab(dely-inyold+1); 01209 float tabley4 = kb.i0win_tab(dely-inyold); 01210 float tabley5 = kb.i0win_tab(dely-inyold-1); 01211 float tabley6 = kb.i0win_tab(dely-inyold-2); 01212 float tabley7 = kb.i0win_tab(dely-inyold-3); 01213 01214 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7; 01215 01216 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 ) { 01217 x1 = (inxold-3+nx)%nx; 01218 x2 = (inxold-2+nx)%nx; 01219 x3 = (inxold-1+nx)%nx; 01220 x4 = (inxold +nx)%nx; 01221 x5 = (inxold+1+nx)%nx; 01222 x6 = (inxold+2+nx)%nx; 01223 x7 = (inxold+3+nx)%nx; 01224 01225 y1 = ((inyold-3+ny)%ny)*nx; 01226 y2 = ((inyold-2+ny)%ny)*nx; 01227 y3 = ((inyold-1+ny)%ny)*nx; 01228 y4 = ((inyold +ny)%ny)*nx; 01229 y5 = ((inyold+1+ny)%ny)*nx; 01230 y6 = ((inyold+2+ny)%ny)*nx; 01231 y7 = ((inyold+3+ny)%ny)*nx; 01232 } else { 01233 x1 = inxold-3; 01234 x2 = inxold-2; 01235 x3 = inxold-1; 01236 x4 = inxold; 01237 x5 = inxold+1; 01238 x6 = inxold+2; 01239 x7 = inxold+3; 01240 01241 y1 = (inyold-3)*nx; 01242 y2 = (inyold-2)*nx; 01243 y3 = (inyold-1)*nx; 01244 y4 = inyold*nx; 01245 y5 = (inyold+1)*nx; 01246 y6 = (inyold+2)*nx; 01247 y7 = (inyold+3)*nx; 01248 } 01249 01250 pixel = ( data[x1+y1]*tablex1 + data[x2+y1]*tablex2 + data[x3+y1]*tablex3 + 01251 data[x4+y1]*tablex4 + data[x5+y1]*tablex5 + data[x6+y1]*tablex6 + 01252 data[x7+y1]*tablex7 ) * tabley1 + 01253 ( data[x1+y2]*tablex1 + data[x2+y2]*tablex2 + data[x3+y2]*tablex3 + 01254 data[x4+y2]*tablex4 + data[x5+y2]*tablex5 + data[x6+y2]*tablex6 + 01255 data[x7+y2]*tablex7 ) * tabley2 + 01256 ( data[x1+y3]*tablex1 + data[x2+y3]*tablex2 + data[x3+y3]*tablex3 + 01257 data[x4+y3]*tablex4 + data[x5+y3]*tablex5 + data[x6+y3]*tablex6 + 01258 data[x7+y3]*tablex7 ) * tabley3 + 01259 ( data[x1+y4]*tablex1 + data[x2+y4]*tablex2 + data[x3+y4]*tablex3 + 01260 data[x4+y4]*tablex4 + data[x5+y4]*tablex5 + data[x6+y4]*tablex6 + 01261 data[x7+y4]*tablex7 ) * tabley4 + 01262 ( data[x1+y5]*tablex1 + data[x2+y5]*tablex2 + data[x3+y5]*tablex3 + 01263 data[x4+y5]*tablex4 + data[x5+y5]*tablex5 + data[x6+y5]*tablex6 + 01264 data[x7+y5]*tablex7 ) * tabley5 + 01265 ( data[x1+y6]*tablex1 + data[x2+y6]*tablex2 + data[x3+y6]*tablex3 + 01266 data[x4+y6]*tablex4 + data[x5+y6]*tablex5 + data[x6+y6]*tablex6 + 01267 data[x7+y6]*tablex7 ) * tabley6 + 01268 ( data[x1+y7]*tablex1 + data[x2+y7]*tablex2 + data[x3+y7]*tablex3 + 01269 data[x4+y7]*tablex4 + data[x5+y7]*tablex5 + data[x6+y7]*tablex6 + 01270 data[x7+y7]*tablex7 ) * tabley7; 01271 01272 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) * 01273 (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7); 01274 } else { // 3D 01275 dely = restrict1(dely, ny); 01276 int inyold = int(Util::round(dely)); 01277 delz = restrict1(delz, nz); 01278 int inzold = int(Util::round(delz)); 01279 01280 float tablex1 = kb.i0win_tab(delx-inxold+3); 01281 float tablex2 = kb.i0win_tab(delx-inxold+2); 01282 float tablex3 = kb.i0win_tab(delx-inxold+1); 01283 float tablex4 = kb.i0win_tab(delx-inxold); 01284 float tablex5 = kb.i0win_tab(delx-inxold-1); 01285 float tablex6 = kb.i0win_tab(delx-inxold-2); 01286 float tablex7 = kb.i0win_tab(delx-inxold-3); 01287 01288 float tabley1 = kb.i0win_tab(dely-inyold+3); 01289 float tabley2 = kb.i0win_tab(dely-inyold+2); 01290 float tabley3 = kb.i0win_tab(dely-inyold+1); 01291 float tabley4 = kb.i0win_tab(dely-inyold); 01292 float tabley5 = kb.i0win_tab(dely-inyold-1); 01293 float tabley6 = kb.i0win_tab(dely-inyold-2); 01294 float tabley7 = kb.i0win_tab(dely-inyold-3); 01295 01296 float tablez1 = kb.i0win_tab(delz-inzold+3); 01297 float tablez2 = kb.i0win_tab(delz-inzold+2); 01298 float tablez3 = kb.i0win_tab(delz-inzold+1); 01299 float tablez4 = kb.i0win_tab(delz-inzold); 01300 float tablez5 = kb.i0win_tab(delz-inzold-1); 01301 float tablez6 = kb.i0win_tab(delz-inzold-2); 01302 float tablez7 = kb.i0win_tab(delz-inzold-3); 01303 01304 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7, z1, z2, z3, z4, z5, z6, z7; 01305 01306 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 || inzold <= kbc || inzold >= nz-kbc-2 ) { 01307 x1 = (inxold-3+nx)%nx; 01308 x2 = (inxold-2+nx)%nx; 01309 x3 = (inxold-1+nx)%nx; 01310 x4 = (inxold +nx)%nx; 01311 x5 = (inxold+1+nx)%nx; 01312 x6 = (inxold+2+nx)%nx; 01313 x7 = (inxold+3+nx)%nx; 01314 01315 y1 = ((inyold-3+ny)%ny)*nx; 01316 y2 = ((inyold-2+ny)%ny)*nx; 01317 y3 = ((inyold-1+ny)%ny)*nx; 01318 y4 = ((inyold +ny)%ny)*nx; 01319 y5 = ((inyold+1+ny)%ny)*nx; 01320 y6 = ((inyold+2+ny)%ny)*nx; 01321 y7 = ((inyold+3+ny)%ny)*nx; 01322 01323 z1 = ((inzold-3+nz)%nz)*nx*ny; 01324 z2 = ((inzold-2+nz)%nz)*nx*ny; 01325 z3 = ((inzold-1+nz)%nz)*nx*ny; 01326 z4 = ((inzold +nz)%nz)*nx*ny; 01327 z5 = ((inzold+1+nz)%nz)*nx*ny; 01328 z6 = ((inzold+2+nz)%nz)*nx*ny; 01329 z7 = ((inzold+3+nz)%nz)*nx*ny; 01330 } else { 01331 x1 = inxold-3; 01332 x2 = inxold-2; 01333 x3 = inxold-1; 01334 x4 = inxold; 01335 x5 = inxold+1; 01336 x6 = inxold+2; 01337 x7 = inxold+3; 01338 01339 y1 = (inyold-3)*nx; 01340 y2 = (inyold-2)*nx; 01341 y3 = (inyold-1)*nx; 01342 y4 = inyold*nx; 01343 y5 = (inyold+1)*nx; 01344 y6 = (inyold+2)*nx; 01345 y7 = (inyold+3)*nx; 01346 01347 z1 = (inzold-3)*nx*ny; 01348 z2 = (inzold-2)*nx*ny; 01349 z3 = (inzold-1)*nx*ny; 01350 z4 = inzold*nx*ny; 01351 z5 = (inzold+1)*nx*ny; 01352 z6 = (inzold+2)*nx*ny; 01353 z7 = (inzold+3)*nx*ny; 01354 } 01355 01356 pixel = ( ( data[x1+y1+z1]*tablex1 + data[x2+y1+z1]*tablex2 + data[x3+y1+z1]*tablex3 + 01357 data[x4+y1+z1]*tablex4 + data[x5+y1+z1]*tablex5 + data[x6+y1+z1]*tablex6 + 01358 data[x7+y1+z1]*tablex7 ) * tabley1 + 01359 ( data[x1+y2+z1]*tablex1 + data[x2+y2+z1]*tablex2 + data[x3+y2+z1]*tablex3 + 01360 data[x4+y2+z1]*tablex4 + data[x5+y2+z1]*tablex5 + data[x6+y2+z1]*tablex6 + 01361 data[x7+y2+z1]*tablex7 ) * tabley2 + 01362 ( data[x1+y3+z1]*tablex1 + data[x2+y3+z1]*tablex2 + data[x3+y3+z1]*tablex3 + 01363 data[x4+y3+z1]*tablex4 + data[x5+y3+z1]*tablex5 + data[x6+y3+z1]*tablex6 + 01364 data[x7+y3+z1]*tablex7 ) * tabley3 + 01365 ( data[x1+y4+z1]*tablex1 + data[x2+y4+z1]*tablex2 + data[x3+y4+z1]*tablex3 + 01366 data[x4+y4+z1]*tablex4 + data[x5+y4+z1]*tablex5 + data[x6+y4+z1]*tablex6 + 01367 data[x7+y4+z1]*tablex7 ) * tabley4 + 01368 ( data[x1+y5+z1]*tablex1 + data[x2+y5+z1]*tablex2 + data[x3+y5+z1]*tablex3 + 01369 data[x4+y5+z1]*tablex4 + data[x5+y5+z1]*tablex5 + data[x6+y5+z1]*tablex6 + 01370 data[x7+y5+z1]*tablex7 ) * tabley5 + 01371 ( data[x1+y6+z1]*tablex1 + data[x2+y6+z1]*tablex2 + data[x3+y6+z1]*tablex3 + 01372 data[x4+y6+z1]*tablex4 + data[x5+y6+z1]*tablex5 + data[x6+y6+z1]*tablex6 + 01373 data[x7+y6+z1]*tablex7 ) * tabley6 + 01374 ( data[x1+y7+z1]*tablex1 + data[x2+y7+z1]*tablex2 + data[x3+y7+z1]*tablex3 + 01375 data[x4+y7+z1]*tablex4 + data[x5+y7+z1]*tablex5 + data[x6+y7+z1]*tablex6 + 01376 data[x7+y7+z1]*tablex7 ) * tabley7 ) *tablez1 + 01377 ( ( data[x1+y1+z2]*tablex1 + data[x2+y1+z2]*tablex2 + data[x3+y1+z2]*tablex3 + 01378 data[x4+y1+z2]*tablex4 + data[x5+y1+z2]*tablex5 + data[x6+y1+z2]*tablex6 + 01379 data[x7+y1+z2]*tablex7 ) * tabley1 + 01380 ( data[x1+y2+z2]*tablex1 + data[x2+y2+z2]*tablex2 + data[x3+y2+z2]*tablex3 + 01381 data[x4+y2+z2]*tablex4 + data[x5+y2+z2]*tablex5 + data[x6+y2+z2]*tablex6 + 01382 data[x7+y2+z2]*tablex7 ) * tabley2 + 01383 ( data[x1+y3+z2]*tablex1 + data[x2+y3+z2]*tablex2 + data[x3+y3+z2]*tablex3 + 01384 data[x4+y3+z2]*tablex4 + data[x5+y3+z2]*tablex5 + data[x6+y3+z2]*tablex6 + 01385 data[x7+y3+z2]*tablex7 ) * tabley3 + 01386 ( data[x1+y4+z2]*tablex1 + data[x2+y4+z2]*tablex2 + data[x3+y4+z2]*tablex3 + 01387 data[x4+y4+z2]*tablex4 + data[x5+y4+z2]*tablex5 + data[x6+y4+z2]*tablex6 + 01388 data[x7+y4+z2]*tablex7 ) * tabley4 + 01389 ( data[x1+y5+z2]*tablex1 + data[x2+y5+z2]*tablex2 + data[x3+y5+z2]*tablex3 + 01390 data[x4+y5+z2]*tablex4 + data[x5+y5+z2]*tablex5 + data[x6+y5+z2]*tablex6 + 01391 data[x7+y5+z2]*tablex7 ) * tabley5 + 01392 ( data[x1+y6+z2]*tablex1 + data[x2+y6+z2]*tablex2 + data[x3+y6+z2]*tablex3 + 01393 data[x4+y6+z2]*tablex4 + data[x5+y6+z2]*tablex5 + data[x6+y6+z2]*tablex6 + 01394 data[x7+y6+z2]*tablex7 ) * tabley6 + 01395 ( data[x1+y7+z2]*tablex1 + data[x2+y7+z2]*tablex2 + data[x3+y7+z2]*tablex3 + 01396 data[x4+y7+z2]*tablex4 + data[x5+y7+z2]*tablex5 + data[x6+y7+z2]*tablex6 + 01397 data[x7+y7+z2]*tablex7 ) * tabley7 ) *tablez2 + 01398 ( ( data[x1+y1+z3]*tablex1 + data[x2+y1+z3]*tablex2 + data[x3+y1+z3]*tablex3 + 01399 data[x4+y1+z3]*tablex4 + data[x5+y1+z3]*tablex5 + data[x6+y1+z3]*tablex6 + 01400 data[x7+y1+z3]*tablex7 ) * tabley1 + 01401 ( data[x1+y2+z3]*tablex1 + data[x2+y2+z3]*tablex2 + data[x3+y2+z3]*tablex3 + 01402 data[x4+y2+z3]*tablex4 + data[x5+y2+z3]*tablex5 + data[x6+y2+z3]*tablex6 + 01403 data[x7+y2+z3]*tablex7 ) * tabley2 + 01404 ( data[x1+y3+z3]*tablex1 + data[x2+y3+z3]*tablex2 + data[x3+y3+z3]*tablex3 + 01405 data[x4+y3+z3]*tablex4 + data[x5+y3+z3]*tablex5 + data[x6+y3+z3]*tablex6 + 01406 data[x7+y3+z3]*tablex7 ) * tabley3 + 01407 ( data[x1+y4+z3]*tablex1 + data[x2+y4+z3]*tablex2 + data[x3+y4+z3]*tablex3 + 01408 data[x4+y4+z3]*tablex4 + data[x5+y4+z3]*tablex5 + data[x6+y4+z3]*tablex6 + 01409 data[x7+y4+z3]*tablex7 ) * tabley4 + 01410 ( data[x1+y5+z3]*tablex1 + data[x2+y5+z3]*tablex2 + data[x3+y5+z3]*tablex3 + 01411 data[x4+y5+z3]*tablex4 + data[x5+y5+z3]*tablex5 + data[x6+y5+z3]*tablex6 + 01412 data[x7+y5+z3]*tablex7 ) * tabley5 + 01413 ( data[x1+y6+z3]*tablex1 + data[x2+y6+z3]*tablex2 + data[x3+y6+z3]*tablex3 + 01414 data[x4+y6+z3]*tablex4 + data[x5+y6+z3]*tablex5 + data[x6+y6+z3]*tablex6 + 01415 data[x7+y6+z3]*tablex7 ) * tabley6 + 01416 ( data[x1+y7+z3]*tablex1 + data[x2+y7+z3]*tablex2 + data[x3+y7+z3]*tablex3 + 01417 data[x4+y7+z3]*tablex4 + data[x5+y7+z3]*tablex5 + data[x6+y7+z3]*tablex6 + 01418 data[x7+y7+z3]*tablex7 ) * tabley7 ) *tablez3 + 01419 ( ( data[x1+y1+z4]*tablex1 + data[x2+y1+z4]*tablex2 + data[x3+y1+z4]*tablex3 + 01420 data[x4+y1+z4]*tablex4 + data[x5+y1+z4]*tablex5 + data[x6+y1+z4]*tablex6 + 01421 data[x7+y1+z4]*tablex7 ) * tabley1 + 01422 ( data[x1+y2+z4]*tablex1 + data[x2+y2+z4]*tablex2 + data[x3+y2+z4]*tablex3 + 01423 data[x4+y2+z4]*tablex4 + data[x5+y2+z4]*tablex5 + data[x6+y2+z4]*tablex6 + 01424 data[x7+y2+z4]*tablex7 ) * tabley2 + 01425 ( data[x1+y3+z4]*tablex1 + data[x2+y3+z4]*tablex2 + data[x3+y3+z4]*tablex3 + 01426 data[x4+y3+z4]*tablex4 + data[x5+y3+z4]*tablex5 + data[x6+y3+z4]*tablex6 + 01427 data[x7+y3+z4]*tablex7 ) * tabley3 + 01428 ( data[x1+y4+z4]*tablex1 + data[x2+y4+z4]*tablex2 + data[x3+y4+z4]*tablex3 + 01429 data[x4+y4+z4]*tablex4 + data[x5+y4+z4]*tablex5 + data[x6+y4+z4]*tablex6 + 01430 data[x7+y4+z4]*tablex7 ) * tabley4 + 01431 ( data[x1+y5+z4]*tablex1 + data[x2+y5+z4]*tablex2 + data[x3+y5+z4]*tablex3 + 01432 data[x4+y5+z4]*tablex4 + data[x5+y5+z4]*tablex5 + data[x6+y5+z4]*tablex6 + 01433 data[x7+y5+z4]*tablex7 ) * tabley5 + 01434 ( data[x1+y6+z4]*tablex1 + data[x2+y6+z4]*tablex2 + data[x3+y6+z4]*tablex3 + 01435 data[x4+y6+z4]*tablex4 + data[x5+y6+z4]*tablex5 + data[x6+y6+z4]*tablex6 + 01436 data[x7+y6+z4]*tablex7 ) * tabley6 + 01437 ( data[x1+y7+z4]*tablex1 + data[x2+y7+z4]*tablex2 + data[x3+y7+z4]*tablex3 + 01438 data[x4+y7+z4]*tablex4 + data[x5+y7+z4]*tablex5 + data[x6+y7+z4]*tablex6 + 01439 data[x7+y7+z4]*tablex7 ) * tabley7 ) *tablez4 + 01440 ( ( data[x1+y1+z5]*tablex1 + data[x2+y1+z5]*tablex2 + data[x3+y1+z5]*tablex3 + 01441 data[x4+y1+z5]*tablex4 + data[x5+y1+z5]*tablex5 + data[x6+y1+z5]*tablex6 + 01442 data[x7+y1+z5]*tablex7 ) * tabley1 + 01443 ( data[x1+y2+z5]*tablex1 + data[x2+y2+z5]*tablex2 + data[x3+y2+z5]*tablex3 + 01444 data[x4+y2+z5]*tablex4 + data[x5+y2+z5]*tablex5 + data[x6+y2+z5]*tablex6 + 01445 data[x7+y2+z5]*tablex7 ) * tabley2 + 01446 ( data[x1+y3+z5]*tablex1 + data[x2+y3+z5]*tablex2 + data[x3+y3+z5]*tablex3 + 01447 data[x4+y3+z5]*tablex4 + data[x5+y3+z5]*tablex5 + data[x6+y3+z5]*tablex6 + 01448 data[x7+y3+z5]*tablex7 ) * tabley3 + 01449 ( data[x1+y4+z5]*tablex1 + data[x2+y4+z5]*tablex2 + data[x3+y4+z5]*tablex3 + 01450 data[x4+y4+z5]*tablex4 + data[x5+y4+z5]*tablex5 + data[x6+y4+z5]*tablex6 + 01451 data[x7+y4+z5]*tablex7 ) * tabley4 + 01452 ( data[x1+y5+z5]*tablex1 + data[x2+y5+z5]*tablex2 + data[x3+y5+z5]*tablex3 + 01453 data[x4+y5+z5]*tablex4 + data[x5+y5+z5]*tablex5 + data[x6+y5+z5]*tablex6 + 01454 data[x7+y5+z5]*tablex7 ) * tabley5 + 01455 ( data[x1+y6+z5]*tablex1 + data[x2+y6+z5]*tablex2 + data[x3+y6+z5]*tablex3 + 01456 data[x4+y6+z5]*tablex4 + data[x5+y6+z5]*tablex5 + data[x6+y6+z5]*tablex6 + 01457 data[x7+y6+z5]*tablex7 ) * tabley6 + 01458 ( data[x1+y7+z5]*tablex1 + data[x2+y7+z5]*tablex2 + data[x3+y7+z5]*tablex3 + 01459 data[x4+y7+z5]*tablex4 + data[x5+y7+z5]*tablex5 + data[x6+y7+z5]*tablex6 + 01460 data[x7+y7+z5]*tablex7 ) * tabley7 ) *tablez5 + 01461 ( ( data[x1+y1+z6]*tablex1 + data[x2+y1+z6]*tablex2 + data[x3+y1+z6]*tablex3 + 01462 data[x4+y1+z6]*tablex4 + data[x5+y1+z6]*tablex5 + data[x6+y1+z6]*tablex6 + 01463 data[x7+y1+z6]*tablex7 ) * tabley1 + 01464 ( data[x1+y2+z6]*tablex1 + data[x2+y2+z6]*tablex2 + data[x3+y2+z6]*tablex3 + 01465 data[x4+y2+z6]*tablex4 + data[x5+y2+z6]*tablex5 + data[x6+y2+z6]*tablex6 + 01466 data[x7+y2+z6]*tablex7 ) * tabley2 + 01467 ( data[x1+y3+z6]*tablex1 + data[x2+y3+z6]*tablex2 + data[x3+y3+z6]*tablex3 + 01468 data[x4+y3+z6]*tablex4 + data[x5+y3+z6]*tablex5 + data[x6+y3+z6]*tablex6 + 01469 data[x7+y3+z6]*tablex7 ) * tabley3 + 01470 ( data[x1+y4+z6]*tablex1 + data[x2+y4+z6]*tablex2 + data[x3+y4+z6]*tablex3 + 01471 data[x4+y4+z6]*tablex4 + data[x5+y4+z6]*tablex5 + data[x6+y4+z6]*tablex6 + 01472 data[x7+y4+z6]*tablex7 ) * tabley4 + 01473 ( data[x1+y5+z6]*tablex1 + data[x2+y5+z6]*tablex2 + data[x3+y5+z6]*tablex3 + 01474 data[x4+y5+z6]*tablex4 + data[x5+y5+z6]*tablex5 + data[x6+y5+z6]*tablex6 + 01475 data[x7+y5+z6]*tablex7 ) * tabley5 + 01476 ( data[x1+y6+z6]*tablex1 + data[x2+y6+z6]*tablex2 + data[x3+y6+z6]*tablex3 + 01477 data[x4+y6+z6]*tablex4 + data[x5+y6+z6]*tablex5 + data[x6+y6+z6]*tablex6 + 01478 data[x7+y6+z6]*tablex7 ) * tabley6 + 01479 ( data[x1+y7+z6]*tablex1 + data[x2+y7+z6]*tablex2 + data[x3+y7+z6]*tablex3 + 01480 data[x4+y7+z6]*tablex4 + data[x5+y7+z6]*tablex5 + data[x6+y7+z6]*tablex6 + 01481 data[x7+y7+z6]*tablex7 ) * tabley7 ) *tablez6 + 01482 ( ( data[x1+y1+z7]*tablex1 + data[x2+y1+z7]*tablex2 + data[x3+y1+z7]*tablex3 + 01483 data[x4+y1+z7]*tablex4 + data[x5+y1+z7]*tablex5 + data[x6+y1+z7]*tablex6 + 01484 data[x7+y1+z7]*tablex7 ) * tabley1 + 01485 ( data[x1+y2+z7]*tablex1 + data[x2+y2+z7]*tablex2 + data[x3+y2+z7]*tablex3 + 01486 data[x4+y2+z7]*tablex4 + data[x5+y2+z7]*tablex5 + data[x6+y2+z7]*tablex6 + 01487 data[x7+y2+z7]*tablex7 ) * tabley2 + 01488 ( data[x1+y3+z7]*tablex1 + data[x2+y3+z7]*tablex2 + data[x3+y3+z7]*tablex3 + 01489 data[x4+y3+z7]*tablex4 + data[x5+y3+z7]*tablex5 + data[x6+y3+z7]*tablex6 + 01490 data[x7+y3+z7]*tablex7 ) * tabley3 + 01491 ( data[x1+y4+z7]*tablex1 + data[x2+y4+z7]*tablex2 + data[x3+y4+z7]*tablex3 + 01492 data[x4+y4+z7]*tablex4 + data[x5+y4+z7]*tablex5 + data[x6+y4+z7]*tablex6 + 01493 data[x7+y4+z7]*tablex7 ) * tabley4 + 01494 ( data[x1+y5+z7]*tablex1 + data[x2+y5+z7]*tablex2 + data[x3+y5+z7]*tablex3 + 01495 data[x4+y5+z7]*tablex4 + data[x5+y5+z7]*tablex5 + data[x6+y5+z7]*tablex6 + 01496 data[x7+y5+z7]*tablex7 ) * tabley5 + 01497 ( data[x1+y6+z7]*tablex1 + data[x2+y6+z7]*tablex2 + data[x3+y6+z7]*tablex3 + 01498 data[x4+y6+z7]*tablex4 + data[x5+y6+z7]*tablex5 + data[x6+y6+z7]*tablex6 + 01499 data[x7+y6+z7]*tablex7 ) * tabley6 + 01500 ( data[x1+y7+z7]*tablex1 + data[x2+y7+z7]*tablex2 + data[x3+y7+z7]*tablex3 + 01501 data[x4+y7+z7]*tablex4 + data[x5+y7+z7]*tablex5 + data[x6+y7+z7]*tablex6 + 01502 data[x7+y7+z7]*tablex7 ) * tabley7 ) *tablez7; 01503 01504 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) * 01505 (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7) * 01506 (tablez1+tablez2+tablez3+tablez4+tablez5+tablez6+tablez7); 01507 } 01508 return pixel/w; 01509 }
unsigned long int 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 20599 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().
20599 { 20600 20601 int nx = vol->get_xsize(); 20602 int ny = vol->get_ysize(); 20603 int nz = vol->get_zsize(); 20604 float *vol_data = vol->get_data(); 20605 int new_nx, new_ny; 20606 20607 if (nz == 1) 20608 throw ImageDimensionException("Error: Input must be a 3-D object"); 20609 if ((dim < 1) || (dim > 3)) 20610 throw ImageDimensionException("Error: dim must be 1 (x-dimension), 2 (y-dimension) or 3 (z-dimension)"); 20611 if (((dim == 1) && (index < 0 || index > nx-1)) || 20612 ((dim == 1) && (index < 0 || index > nx-1)) || 20613 ((dim == 1) && (index < 0 || index > nx-1))) 20614 throw ImageDimensionException("Error: index exceeds the size of the 3-D object"); 20615 20616 if (dim == 1) { 20617 new_nx = ny; 20618 new_ny = nz; 20619 } else if (dim == 2) { 20620 new_nx = nx; 20621 new_ny = nz; 20622 } else { 20623 new_nx = nx; 20624 new_ny = ny; 20625 } 20626 20627 EMData *slice = new EMData(); 20628 slice->set_size(new_nx, new_ny, 1); 20629 float *slice_data = slice->get_data(); 20630 20631 if (dim == 1) { 20632 for (int x=0; x<new_nx; x++) 20633 for (int y=0; y<new_ny; y++) 20634 slice_data[y*new_nx+x] = vol_data[(y*ny+x)*nx+index]; 20635 } else if (dim == 2) { 20636 for (int x=0; x<new_nx; x++) 20637 for (int y=0; y<new_ny; y++) 20638 slice_data[y*new_nx+x] = vol_data[(y*ny+index)*nx+x]; 20639 } else { 20640 for (int x=0; x<new_nx; x++) 20641 for (int y=0; y<new_ny; y++) 20642 slice_data[y*new_nx+x] = vol_data[((size_t)index*ny+y)*nx+x]; 20643 } 20644 20645 return slice; 20646 }
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 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 1900 of file util.h.
Referenced by EMAN::FRCCmp::cmp(), EMAN::SqEuclideanCmp::cmp(), EMAN::EMObject::EMObject(), EMAN::ByteOrder::is_float_big_endian(), EMAN::NormalizeProcessor::process_inplace(), and EMAN::FiniteProcessor::process_pixel().
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 5743 of file util_sparx.cpp.
References EMAN::EMData::get_data(), and img_ptr.
05744 { 05745 float *img_ptr = img->get_data(); 05746 float *mask_ptr = (mask == NULL)?img->get_data():mask->get_data(); 05747 05748 int *img_freq_bin = new int[3*hist_len]; 05749 for(int i = 0;i < (3*hist_len);i++) img_freq_bin[i] = 0; 05750 for(size_t i = 0;i < size_img;++i) { 05751 if(mask_ptr[i] > 0.5f) { 05752 float img_xn = img_ptr[i]*PA + PB; 05753 int L = static_cast<int>(((img_xn - ref_h_min)/ref_h_diff) * (hist_len-1) + hist_len+1); 05754 if(L >= 0 && L < (3*hist_len)) img_freq_bin[L]++; 05755 } 05756 } 05757 int freq_hist = 0; 05758 05759 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); 05760 freq_hist = (-freq_hist); 05761 return static_cast<float>(freq_hist); 05762 }
Definition at line 5651 of file util_sparx.cpp.
References B, data, EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, ImageFormatException, infomask(), EMAN::EMData::is_complex(), and min.
05652 { 05653 /* Exception Handle */ 05654 if (img->is_complex() || ref->is_complex()) 05655 throw ImageFormatException("Cannot do Histogram on Fourier Image"); 05656 05657 if(mask != NULL){ 05658 if(img->get_xsize() != mask->get_xsize() || img->get_ysize() != mask->get_ysize() || img->get_zsize() != mask->get_zsize()) 05659 throw ImageDimensionException("The size of mask image should be of same size as the input image"); } 05660 /* ===================================================== */ 05661 05662 /* Image size calculation */ 05663 size_t size_ref = ((size_t)(ref->get_xsize())*(ref->get_ysize())*(ref->get_zsize())); 05664 size_t size_img = ((size_t)(img->get_xsize())*(img->get_ysize())*(img->get_zsize())); 05665 /* ===================================================== */ 05666 05667 /* The reference image attributes */ 05668 float *ref_ptr = ref->get_data(); 05669 float ref_h_min = ref->get_attr("minimum"); 05670 float ref_h_max = ref->get_attr("maximum"); 05671 float ref_h_avg = ref->get_attr("mean"); 05672 float ref_h_sig = ref->get_attr("sigma"); 05673 /* ===================================================== */ 05674 05675 /* Input image under mask attributes */ 05676 float *mask_ptr = (mask == NULL)?img->get_data():mask->get_data(); 05677 05678 vector<float> img_data = Util::infomask(img, mask); 05679 float img_avg = img_data[0]; 05680 float img_sig = img_data[1]; 05681 05682 /* The image under mask -- size calculation */ 05683 int cnt=0; 05684 for(size_t i=0;i<size_img;++i) 05685 if (mask_ptr[i]>0.5f) 05686 cnt++; 05687 /* ===================================================== */ 05688 05689 /* Histogram of reference image calculation */ 05690 float ref_h_diff = ref_h_max - ref_h_min; 05691 05692 #ifdef _WIN32 05693 int hist_len = _cpp_min((unsigned long)size_ref/16,_cpp_min((unsigned long)size_img/16,256lu)); 05694 #else 05695 int hist_len = std::min((unsigned long)size_ref/16,std::min((unsigned long)size_img/16,256lu)); 05696 #endif //_WIN32 05697 05698 float *ref_freq_bin = new float[3*hist_len]; 05699 05700 //initialize value in each bin to zero 05701 for (int i = 0;i < (3*hist_len);i++) ref_freq_bin[i] = 0.f; 05702 05703 for (size_t i = 0;i < size_ref;++i) { 05704 int L = static_cast<int>(((ref_ptr[i] - ref_h_min)/ref_h_diff) * (hist_len-1) + hist_len+1); 05705 ref_freq_bin[L]++; 05706 } 05707 for (int i = 0;i < (3*hist_len);i++) ref_freq_bin[i] *= static_cast<float>(cnt)/static_cast<float>(size_ref); 05708 05709 //Parameters Calculation (i.e) 'A' x + 'B' 05710 float A = ref_h_sig/img_sig; 05711 float B = ref_h_avg - (A*img_avg); 05712 05713 vector<float> args; 05714 args.push_back(A); 05715 args.push_back(B); 05716 05717 vector<float> scale; 05718 scale.push_back(1.e-7f*A); 05719 scale.push_back(-1.e-7f*B); 05720 05721 vector<float> ref_freq_hist; 05722 for(int i = 0;i < (3*hist_len);i++) ref_freq_hist.push_back((int)ref_freq_bin[i]); 05723 05724 vector<float> data; 05725 data.push_back(ref_h_diff); 05726 data.push_back(ref_h_min); 05727 05728 Dict parameter; 05729 05730 /* Parameters displaying the arguments A & B, and the scaling function and the data's */ 05731 parameter["args"] = args; 05732 parameter["scale"]= scale; 05733 parameter["data"] = data; 05734 parameter["ref_freq_bin"] = ref_freq_hist; 05735 parameter["size_img"]=(double)size_img; 05736 parameter["hist_len"]=hist_len; 05737 /* ===================================================== */ 05738 05739 return parameter; 05740 }
vector< float > Util::histogram | ( | EMData * | image, | |
EMData * | mask, | |||
int | nbins = 128 , |
|||
float | hmin = 0.0f , |
|||
float | hmax = 0.0f | |||
) | [static] |
Definition at line 5593 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.
05594 { 05595 if (image->is_complex()) 05596 throw ImageFormatException("Cannot do histogram on Fourier image"); 05597 //float hmax, hmin; 05598 float *imageptr=0, *maskptr=0; 05599 int nx=image->get_xsize(); 05600 int ny=image->get_ysize(); 05601 int nz=image->get_zsize(); 05602 05603 if(mask != NULL){ 05604 if(nx != mask->get_xsize() || ny != mask->get_ysize() || nz != mask->get_zsize()) 05605 throw ImageDimensionException("The size of mask image should be of same size as the input image"); 05606 maskptr =mask->get_data(); 05607 } 05608 if( nbins == 0) nbins = nx; 05609 vector <float> freq(2*nbins, 0.0); 05610 05611 imageptr=image->get_data(); 05612 if( hmin == hmax ) { 05613 if(mask == NULL) { 05614 hmax = image->get_attr("maximum"); 05615 hmin = image->get_attr("minimum"); 05616 } else { 05617 bool First = true; 05618 for (size_t i = 0;i < (size_t)nx*ny*nz; i++) { 05619 if (maskptr[i]>=0.5f) { 05620 if(First) { 05621 hmax = imageptr[i]; 05622 hmin = imageptr[i]; 05623 First = false; 05624 } else { 05625 hmax = (hmax < imageptr[i])?imageptr[i]:hmax; 05626 hmin = (hmin > imageptr[i])?imageptr[i]:hmin; 05627 } 05628 } 05629 } 05630 } 05631 } 05632 float hdiff = hmax - hmin; 05633 float ff = (nbins-1)/hdiff; 05634 for (int i = 0; i < nbins; i++) freq[nbins+i] = hmin + (float(i)+0.5f)/ff; 05635 if(mask == NULL) { 05636 for(size_t i = 0; i < (size_t)nx*ny*nz; i++) { 05637 int jbin = static_cast<int>((imageptr[i]-hmin)*ff + 1.5); 05638 if(jbin >= 1 && jbin <= nbins) freq[jbin-1] += 1.0; 05639 } 05640 } else { 05641 for(size_t i = 0; i < (size_t)nx*ny*nz; i++) { 05642 if(maskptr[i] >= 0.5) { 05643 int jbin = static_cast<int>((imageptr[i]-hmin)*ff + 1.5); 05644 if(jbin >= 1 && jbin <= nbins) freq[jbin-1] += 1.0; 05645 } 05646 } 05647 } 05648 return freq; 05649 }
void Util::hsortd | ( | double * | theta, | |
double * | phi, | |||
int * | key, | |||
int | len, | |||
int | option | |||
) | [static] |
Definition at line 7303 of file util_sparx.cpp.
References cmp1(), cmp2(), ENTERFUNC, EXITFUNC, key, phi, and theta.
07304 { 07305 ENTERFUNC; 07306 vector<tmpstruct> tmp(len); 07307 int i; 07308 for(i = 1;i<=len;i++) 07309 { 07310 tmp[i-1].theta1 = theta(i); 07311 tmp[i-1].phi1 = phi(i); 07312 tmp[i-1].key1 = key(i); 07313 } 07314 07315 if (option == 1) sort(tmp.begin(),tmp.end(),Util::cmp1); 07316 if (option == 2) sort(tmp.begin(),tmp.end(),Util::cmp2); 07317 07318 for(i = 1;i<=len;i++) 07319 { 07320 theta(i) = tmp[i-1].theta1; 07321 phi(i) = tmp[i-1].phi1; 07322 key(i) = tmp[i-1].key1; 07323 } 07324 EXITFUNC; 07325 }
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 1641 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(), and EMAN::RotationalAverageProcessor::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 1619 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 148 of file util_sparx.cpp.
References B, 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().
00149 { 00150 ENTERFUNC; 00151 00152 if (!EMUtil::is_same_size(V1, V2)) { 00153 LOGERR("images not same size"); 00154 throw ImageFormatException( "images not same size"); 00155 } 00156 00157 size_t nx = V1->get_xsize(); 00158 size_t ny = V1->get_ysize(); 00159 size_t nz = V1->get_zsize(); 00160 size_t size = (size_t)nx*ny*nz; 00161 00162 EMData *BD = new EMData(); 00163 BD->set_size(nx, ny, nz); 00164 00165 float *params = new float[2]; 00166 00167 float *V1ptr, *V2ptr, *MASKptr, *BDptr, A, B; 00168 long double S1=0.L,S2=0.L,S3=0.L,S4=0.L; 00169 int nvox = 0L; 00170 00171 V1ptr = V1->get_data(); 00172 V2ptr = V2->get_data(); 00173 BDptr = BD->get_data(); 00174 00175 00176 if(!mask){ 00177 EMData * Mask = new EMData(); 00178 Mask->set_size(nx,ny,nz); 00179 Mask->to_one(); 00180 MASKptr = Mask->get_data(); 00181 } else { 00182 if (!EMUtil::is_same_size(V1, mask)) { 00183 LOGERR("mask not same size"); 00184 throw ImageFormatException( "mask not same size"); 00185 } 00186 00187 MASKptr = mask->get_data(); 00188 } 00189 00190 00191 00192 // calculation of S1,S2,S3,S3,nvox 00193 00194 for (size_t i = 0L;i < size; i++) { 00195 if (MASKptr[i]>0.5f) { 00196 S1 += V1ptr[i]*V2ptr[i]; 00197 S2 += V1ptr[i]*V1ptr[i]; 00198 S3 += V2ptr[i]; 00199 S4 += V1ptr[i]; 00200 nvox ++; 00201 } 00202 } 00203 00204 if ((nvox*S1 - S3*S4) == 0. || (nvox*S2 - S4*S4) == 0) { 00205 A =1.0f ; 00206 } else { 00207 A = static_cast<float>( (nvox*S1 - S3*S4)/(nvox*S2 - S4*S4) ); 00208 } 00209 B = static_cast<float> (A*S4 - S3)/nvox; 00210 00211 // calculation of the difference image 00212 00213 for (size_t i = 0L;i < size; i++) { 00214 if (MASKptr[i]>0.5f) { 00215 BDptr[i] = A*V1ptr[i] - B - V2ptr[i]; 00216 } else { 00217 BDptr[i] = 0.f; 00218 } 00219 } 00220 00221 BD->update(); 00222 00223 params[0] = A; 00224 params[1] = B; 00225 00226 Dict BDnParams; 00227 BDnParams["imdiff"] = BD; 00228 BDnParams["A"] = params[0]; 00229 BDnParams["B"] = params[1]; 00230 00231 EXITFUNC; 00232 return BDnParams; 00233 }
void Util::image_mutation | ( | EMData * | img, | |
float | mutation_rate | |||
) | [static] |
Definition at line 20648 of file util_sparx.cpp.
References array_mutation(), EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), max, min, and nx.
20648 { 20649 int nx = img->get_xsize(); 20650 float min = img->get_attr("minimum"); 20651 float max = img->get_attr("maximum"); 20652 float* img_data = img->get_data(); 20653 array_mutation(img_data, nx*nx, mutation_rate, min, max, 8, 0); 20654 return; 20655 }
Definition at line 67 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().
00068 : find statistics under the mask (mask >0.5) 00069 // flip false: find statistics ourside the mask (mask <0.5) 00070 { 00071 ENTERFUNC; 00072 vector<float> stats; 00073 float *Volptr, *maskptr,MAX,MIN; 00074 long double Sum1,Sum2; 00075 long count; 00076 00077 MAX = -FLT_MAX; 00078 MIN = FLT_MAX; 00079 count = 0L; 00080 Sum1 = 0.0L; 00081 Sum2 = 0.0L; 00082 00083 if (mask == NULL) { 00084 //Vol->update_stat(); 00085 stats.push_back(Vol->get_attr("mean")); 00086 stats.push_back(Vol->get_attr("sigma")); 00087 stats.push_back(Vol->get_attr("minimum")); 00088 stats.push_back(Vol->get_attr("maximum")); 00089 return stats; 00090 } 00091 00092 /* Check if the sizes of the mask and image are same */ 00093 00094 size_t nx = Vol->get_xsize(); 00095 size_t ny = Vol->get_ysize(); 00096 size_t nz = Vol->get_zsize(); 00097 00098 size_t mask_nx = mask->get_xsize(); 00099 size_t mask_ny = mask->get_ysize(); 00100 size_t mask_nz = mask->get_zsize(); 00101 00102 if (nx != mask_nx || ny != mask_ny || nz != mask_nz ) 00103 throw ImageDimensionException("The dimension of the image does not match the dimension of the mask!"); 00104 00105 /* if (nx != mask_nx || 00106 ny != mask_ny || 00107 nz != mask_nz ) { 00108 // should throw an exception here!!! (will clean it up later CY) 00109 fprintf(stderr, "The dimension of the image does not match the dimension of the mask!\n"); 00110 fprintf(stderr, " nx = %d, mask_nx = %d\n", nx, mask_nx); 00111 fprintf(stderr, " ny = %d, mask_ny = %d\n", ny, mask_ny); 00112 fprintf(stderr, " nz = %d, mask_nz = %d\n", nz, mask_nz); 00113 exit(1); 00114 } 00115 */ 00116 Volptr = Vol->get_data(); 00117 maskptr = mask->get_data(); 00118 00119 for (size_t i = 0; i < (size_t)nx*ny*nz; ++i) { 00120 if ((maskptr[i]>0.5f) == flip) { 00121 Sum1 += Volptr[i]; 00122 Sum2 += Volptr[i]*double(Volptr[i]); 00123 MAX = (MAX < Volptr[i])?Volptr[i]:MAX; 00124 MIN = (MIN > Volptr[i])?Volptr[i]:MIN; 00125 count++; 00126 } 00127 } 00128 00129 if (count == 0) { 00130 LOGERR("Invalid mask"); 00131 throw ImageFormatException( "Invalid mask"); 00132 } 00133 00134 float avg = static_cast<float>(Sum1/count); 00135 float sig = static_cast<float>(sqrt((Sum2 - Sum1*Sum1/count)/(count-1))); 00136 00137 stats.push_back(avg); 00138 stats.push_back(sig); 00139 stats.push_back(MIN); 00140 stats.push_back(MAX); 00141 00142 return stats; 00143 }
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 20943 of file util_sparx.cpp.
References b, explore(), and k_means_cont_table_().
20943 { 20944 //cout<<"initial_prune\n"; 20945 // simple initial pruning. For class indClass of partition indPart: 20946 // 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 20947 // If for some partition (not equal to indPart) for which there is no such class, then return 0 immediately. 20948 20949 // 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 20950 20951 // remember when calling k_means_cont_table, the first element of each class is an index, and actual number of elements in the class 20952 // (as stored in dimClasses) should be decremented by 1 accordingly, and second is dummy variable 20953 20954 int* dummy(0); 20955 int* cref; 20956 int cref_size; 20957 int* ccomp; 20958 int ccomp_size; 20959 int nintx; 20960 for (int i=0; i < nParts; i++){ 20961 for (int j =0; j < K; j++){ 20962 20963 // consider class Parts[i][j] 20964 cref = Parts[i][j];//incr by 1 since first element is index and second is dummy 20965 cref_size = dimClasses[i*K+cref[0]]-2; 20966 20967 20968 if (cref_size <= T){ 20969 cref[0] = -1; 20970 continue; 20971 } 20972 bool done = 0; 20973 for (int a = 0; a < nParts; a++){ 20974 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 20975 bool hasActive=0; 20976 for (unsigned int b=0; b < Parts[a].size(); b++){ 20977 // get the card of the intx between Parts[i][j] and Parts[a][b] using k_means_cont_table 20978 // remember first element of each class is the index of the class 20979 ccomp = Parts[a][b]; 20980 ccomp_size= dimClasses[a*K+ccomp[0]]-2; 20981 nintx = Util::k_means_cont_table_(cref+2,ccomp+2, dummy, cref_size, ccomp_size,0); 20982 20983 20984 if (nintx <= T) 20985 ccomp[1] = 0; // class Parts[a][b] is 'inactive' for cref 20986 else{ 20987 ccomp[1] = 1; // class Parts[a][b] is 'active' for cref 20988 hasActive=1; 20989 } 20990 } 20991 // see if partition a has at least one active class.if not then we're done with cref 20992 if (hasActive < 1){ 20993 done=1; 20994 break; 20995 } 20996 20997 } 20998 20999 if (done > 0){ 21000 // remove class j from partition i 21001 21002 cref[0] = -1; // mark for deletion later 21003 continue; // move on to class Parts[i][j+1] 21004 } 21005 21006 // now we adopt more aggressive measures. we find the match with the largest weight which has class Parts[i][j] for partition i. 21007 // 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. 21008 21009 // (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. 21010 // Note that if there are ALOT of partitions, then sorting the partititions may actually take longer than the time saved by ordering hte 21011 // partitions. However, we do not have a lot of partitions, (usually around 10), so sorting time will be trivial compared to exploring time. 21012 21013 // explore returns one if there is a feasible matching containing class cref which has weight gt T, and otherwise returns 0 21014 //bool found = 1; 21015 bool found = explore(Parts, dimClasses, nParts, K, T, i, cref+2, cref_size, cref, cref_size,0); 21016 21017 if (found<1){ // There is NO feasible matching with class j (cref) with weight greater than T, so delete this class from Parts 21018 // Parts[i].erase(Parts[i].begin()+j); 21019 cref[0] = -1; 21020 } 21021 } 21022 21023 // Erase from Parts[i] all the classes that's being designated for erasure 21024 21025 for (int d = K-1; d > -1; d--){ 21026 if (Parts[i][d][0] < 0) Parts[i].erase(Parts[i].begin()+d); 21027 } 21028 21029 } 21030 //cout <<"number of classes left in each partition after initial prune\n"; 21031 // Print out how many classes are left in each partition 21032 //for (int i =0; i < nParts; i++) 21033 // cout << Parts[i].size()<<", "; 21034 //cout << "\n"; 21035 }
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(), 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 2105 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 5280 of file util_sparx.cpp.
References max.
05280 { 05281 long int d2 = group2[s2 - 1] - group2[0]; 05282 long int p2 = 0; 05283 long int i1 = 0; 05284 long int i2 = 0; 05285 long int max = 0; 05286 long int cont = 0; 05287 long int i = 0; 05288 int stop1 = 0; 05289 int stop2 = 0; 05290 05291 for (i=0; i<s1; i++) { 05292 p2 = (long int)(s2 * (double)group1[i] / (double)d2); 05293 if (p2 >= s2) {p2 = s2 - 1;} 05294 i1 = p2; 05295 i2 = p2; 05296 max = s2; 05297 if (group1[i] < group2[0] || group1[i] > group2[s2 - 1]) {continue;} 05298 05299 stop1 = 0; 05300 stop2 = 0; 05301 while (max--) { 05302 if (group1[i] == group2[i1]) { 05303 if (flag) {stb[cont] = group1[i];} 05304 cont++; 05305 break; 05306 } 05307 if (group2[i1] < group1[i]) {stop1=1;} 05308 if (group1[i] == group2[i2]) { 05309 if (flag) {stb[cont] = group1[i];} 05310 cont++; 05311 break; 05312 } 05313 if (group2[i2] > group1[i]) {stop2=1;} 05314 //printf("i1 %li i2 %li v2 %i v2 %i stop1 %i stop2 %i\n", i1, i2, group2[i1], group2[i2], stop1, stop2); 05315 05316 if (stop1 & stop2) {break;} 05317 i1--; 05318 i2++; 05319 if (i1 < 0) {i1 = 0;} 05320 if (i2 >= s2) {i2 = s2 - 1;} 05321 } 05322 //printf("v1: %i ite: %li cont: %li\n", group1[i], s2-max, cont); 05323 } 05324 05325 return cont; 05326 }
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 1474 of file util.h.
Referenced by EMAN::EMData::cut_slice(), EMAN::WienerFourierReconstructor::do_insert_slice_work(), 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 20711 of file util_sparx.cpp.
20711 { 20712 20713 if (is_mirror != 0) { 20714 for (vector<float>::iterator q=list.begin(); q!=list.end(); q++) { 20715 int r = rand()%10000; 20716 float f = r/10000.0f; 20717 if (f < mutation_rate) *q = 1-*q; 20718 } 20719 } else { 20720 map<int, vector<int> > graycode; 20721 map<vector<int>, int> rev_graycode; 20722 vector <int> gray; 20723 20724 int K=1; 20725 for (int i=0; i<L; i++) K*=2; 20726 20727 for (int k=0; k<K; k++) { 20728 int shift = 0; 20729 vector <int> gray; 20730 for (int i=L-1; i>-1; i--) { 20731 int t = ((k>>i)%2-shift)%2; 20732 gray.push_back(t); 20733 shift += t-2; 20734 } 20735 graycode[k] = gray; 20736 rev_graycode[gray] = k; 20737 } 20738 20739 float gap = (K-1)/(max_val-min_val); 20740 for (vector<float>::iterator q=list.begin(); q!=list.end(); q++) { 20741 float val = *q; 20742 if (val < min_val) { val = min_val; } 20743 else if (val > max_val) { val = max_val; } 20744 int k = int((val-min_val)*gap+0.5); 20745 vector<int> gray = graycode[k]; 20746 bool changed = false; 20747 for (vector<int>::iterator p=gray.begin(); p!=gray.end(); p++) { 20748 int r = rand()%10000; 20749 float f = r/10000.0f; 20750 if (f < mutation_rate) { 20751 *p = 1-*p; 20752 changed = true; 20753 } 20754 } 20755 if (changed) { 20756 k = rev_graycode[gray]; 20757 *q = k/gap+min_val; 20758 } 20759 } 20760 } 20761 return list; 20762 }
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 6510 of file util_sparx.cpp.
References cl1().
06511 { 06512 /* System generated locals */ 06513 long int q_dim1, q_offset, q1_dim1, q1_offset, i__1, i__2; 06514 06515 /* Local variables */ 06516 long int i__, j, m, n1, ii, jj; 06517 double tmp; 06518 vector<float> p; 06519 --x; 06520 q_dim1 = *klm2d; 06521 q_offset = 1 + q_dim1; 06522 q -= q_offset; 06523 q1_dim1 = *klm2d; 06524 q1_offset = 1 + q1_dim1; 06525 q1 -= q1_offset; 06526 --s; 06527 --res; 06528 iu -= 3; 06529 cu -= 3; 06530 06531 /* Function Body */ 06532 long int l = 0; 06533 06534 /* C==ZHONG HUANG,JULY,12,02;L=0,1,2,3,4,5,6 correspond to different equality constraints */ 06535 m = *ks; 06536 n1 = *n + 1; 06537 if (*iswi == 1) { 06538 i__1 = n1; 06539 for (jj = 1; jj <= i__1; ++jj) { 06540 i__2 = *ks; 06541 for (ii = 1; ii <= i__2; ++ii) { 06542 /* q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];*/ 06543 06544 q[*ks + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1] 06545 ; 06546 } 06547 } 06548 } else if (*iswi == 2) { 06549 i__1 = *ks; 06550 for (ii = 1; ii <= i__1; ++ii) { 06551 i__2 = n1; 06552 for (jj = 1; jj <= i__2; ++jj) { 06553 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06554 q[*ks + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06555 } 06556 } 06557 } else if (*iswi == 3) { 06558 l = 2; 06559 i__1 = n1; 06560 for (jj = 1; jj <= i__1; ++jj) { 06561 i__2 = *ks + 2; 06562 for (ii = 1; ii <= i__2; ++ii) { 06563 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06564 } 06565 i__2 = *ks; 06566 for (ii = 1; ii <= i__2; ++ii) { 06567 q[*ks + 2 + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06568 } 06569 } 06570 } else if (*iswi == 4) { 06571 l = 2; 06572 i__1 = n1; 06573 for (jj = 1; jj <= i__1; ++jj) { 06574 i__2 = *ks + 2; 06575 for (ii = 1; ii <= i__2; ++ii) { 06576 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06577 } 06578 i__2 = *ks; 06579 for (ii = 1; ii <= i__2; ++ii) { 06580 q[*ks + 2 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06581 } 06582 } 06583 } else if (*iswi == 5) { 06584 l = 1; 06585 i__1 = n1; 06586 for (jj = 1; jj <= i__1; ++jj) { 06587 i__2 = *ks + 1; 06588 for (ii = 1; ii <= i__2; ++ii) { 06589 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06590 } 06591 i__2 = *ks; 06592 for (ii = 1; ii <= i__2; ++ii) { 06593 q[*ks + 1 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06594 } 06595 } 06596 } else if (*iswi == 6) { 06597 l = 1; 06598 i__1 = n1; 06599 for (jj = 1; jj <= i__1; ++jj) { 06600 i__2 = *ks + 1; 06601 for (ii = 1; ii <= i__2; ++ii) { 06602 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06603 } 06604 i__2 = *ks; 06605 for (ii = 1; ii <= i__2; ++ii) { 06606 q[*ks + 1 + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06607 } 06608 } 06609 } else if (*iswi == 7) { 06610 l = 3; 06611 i__1 = n1; 06612 for (jj = 1; jj <= i__1; ++jj) { 06613 i__2 = *ks + 3; 06614 for (ii = 1; ii <= i__2; ++ii) { 06615 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06616 } 06617 i__2 = *ks; 06618 for (ii = 1; ii <= i__2; ++ii) { 06619 q[*ks + 3 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06620 } 06621 } 06622 } else if (*iswi == 8) { 06623 l = 4; 06624 i__1 = n1; 06625 for (jj = 1; jj <= i__1; ++jj) { 06626 i__2 = *ks + 4; 06627 for (ii = 1; ii <= i__2; ++ii) { 06628 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06629 } 06630 i__2 = *ks; 06631 for (ii = 1; ii <= i__2; ++ii) { 06632 q[*ks + 4 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06633 } 06634 } 06635 } 06636 06637 Util::cl1(ks, &l, &m, n, klm2d, &q[q_offset], &x[1], &res[1], &cu[3], &iu[3], &s[1]); 06638 i__1 = *ks; 06639 int tmp__j=0; 06640 for (i__ = 1; i__ <= i__1; ++i__) { 06641 tmp = 0.f; 06642 i__2 = *n - 1; 06643 for (j = 1; j <= i__2; ++j) { 06644 tmp__j=j; 06645 tmp += pow(q1[i__ + q1_dim1], tmp__j) * x[j]; 06646 } 06647 tmp += x[*n]; 06648 p.push_back(static_cast<float>(exp(tmp))); 06649 p.push_back(q1[i__ + q1_dim1]); 06650 } 06651 i__2=*n; 06652 for (i__=1;i__<=i__2;++i__) 06653 { p.push_back(static_cast<float>(x[i__]));} 06654 return p; 06655 }
Definition at line 17624 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().
17625 { 17626 ENTERFUNC; 17627 /* Exception Handle */ 17628 if (!img) { 17629 throw NullPointerException("NULL input image"); 17630 } 17631 /* ============== img += scalar*img1 ================ */ 17632 17633 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17634 size_t size = (size_t)nx*ny*nz; 17635 float *img_ptr =img->get_data(); 17636 float *img1_ptr = img1->get_data(); 17637 for (size_t i=0;i<size;++i)img_ptr[i] += img1_ptr[i]*scalar; 17638 img1->update(); 17639 17640 EXITFUNC; 17641 }
Definition at line 17434 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().
17435 { 17436 ENTERFUNC; 17437 /* Exception Handle */ 17438 if (!img) { 17439 throw NullPointerException("NULL input image"); 17440 } 17441 /* ============== output = img + scalar*img1 ================ */ 17442 17443 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17444 size_t size = (size_t)nx*ny*nz; 17445 EMData * img2 = img->copy_head(); 17446 float *img_ptr =img->get_data(); 17447 float *img2_ptr = img2->get_data(); 17448 float *img1_ptr = img1->get_data(); 17449 for (size_t i=0;i<size;++i) img2_ptr[i] = img_ptr[i] + img1_ptr[i]*scalar; 17450 img2->update(); 17451 if(img->is_complex()) { 17452 img2->set_complex(true); 17453 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17454 } 17455 17456 EXITFUNC; 17457 return img2; 17458 }
static double EMAN::Util::mean | ( | double * | x, | |
int | n | |||
) | [inline, static] |
Definition at line 1049 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 6292 of file util_sparx.cpp.
06293 { 06294 vector<float>new_peak; 06295 int n1=peak1.size()/3; 06296 float p_size2=p_size*p_size; 06297 for (int i=0;i<n1;++i) { 06298 vector<float>::iterator it2= peak1.begin()+3*i; 06299 bool push_back1=true; 06300 int n2=peak2.size()/3; 06301 /*cout<<"peak2 size==="<<n2<<"i====="<<i<<endl; 06302 cout<<"new peak size==="<<new_peak.size()/3<<endl;*/ 06303 if(n2 ==0) { 06304 new_peak.push_back(*it2); 06305 new_peak.push_back(*(it2+1)); 06306 new_peak.push_back(*(it2+2)); 06307 } else { 06308 int j=0; 06309 while (j< n2-1 ) { 06310 vector<float>::iterator it3= peak2.begin()+3*j; 06311 float d2=((*(it2+1))-(*(it3+1)))*((*(it2+1))-(*(it3+1)))+((*(it2+2))-(*(it3+2)))*((*(it2+2))-(*(it3+2))); 06312 if(d2< p_size2 ) { 06313 if( (*it2)<(*it3) ) { 06314 new_peak.push_back(*it3); 06315 new_peak.push_back(*(it3+1)); 06316 new_peak.push_back(*(it3+2)); 06317 peak2.erase(it3); 06318 peak2.erase(it3); 06319 peak2.erase(it3); 06320 push_back1=false; 06321 } else { 06322 peak2.erase(it3); 06323 peak2.erase(it3); 06324 peak2.erase(it3); 06325 } 06326 } else j=j+1; 06327 n2=peak2.size()/3; 06328 } 06329 if(push_back1) { 06330 new_peak.push_back(*it2); 06331 new_peak.push_back(*(it2+1)); 06332 new_peak.push_back(*(it2+2)); 06333 } 06334 } 06335 } 06336 return new_peak; 06337 }
helper function for k-means
Definition at line 5205 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), nx, and ny.
05205 { 05206 ENTERFUNC; 05207 05208 int nima = data.size(); 05209 vector<float> res(nima); 05210 double result = 0.; 05211 double valmin = 1.0e20; 05212 int valpos = -1; 05213 05214 for (int kk=0; kk<nima; kk++){ 05215 result = 0; 05216 //validate_input_args(image, data[kk]); 05217 05218 float *y_data = data[kk]->get_data(); 05219 float *x_data = image->get_data(); 05220 05221 // Implemented by PAP 01/09/06 - please do not change. If in doubts, write/call me. 05222 int nx = data[kk]->get_xsize(); 05223 int ny = data[kk]->get_ysize(); 05224 nx = (nx - 2 + data[kk]->is_fftodd()); // nx is the real-space size of the input image 05225 int lsd2 = (nx + 2 - nx%2) ; // Extended x-dimension of the complex image 05226 05227 int ixb = 2*((nx+1)%2); 05228 int iyb = ny%2; 05229 int iz = 0; 05230 05231 for ( int iy = 0; iy <= ny-1; iy++) { 05232 for ( int ix = 2; ix <= lsd2 - 1 - ixb; ix++) { 05233 int ii = ix + (iy + iz * ny)* lsd2; 05234 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05235 } 05236 } 05237 for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) { 05238 int ii = (iy + iz * ny)* lsd2; 05239 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05240 result += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]); 05241 } 05242 if(nx%2 == 0) { 05243 for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) { 05244 int ii = lsd2 - 2 + (iy + iz * ny)* lsd2; 05245 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05246 result += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]); 05247 } 05248 05249 } 05250 result *= 2; 05251 result += (x_data[0] - y_data[0])*double(x_data[0] - y_data[0]); 05252 if(ny%2 == 0) { 05253 int ii = (ny/2 + iz * ny)* lsd2; 05254 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05255 } 05256 if(nx%2 == 0) { 05257 int ii = lsd2 - 2 + (0 + iz * ny)* lsd2; 05258 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05259 if(ny%2 == 0) { 05260 int ii = lsd2 - 2 +(ny/2 + iz * ny)* lsd2; 05261 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05262 } 05263 } 05264 05265 result /= (long int)nx*(long int)ny*(long int)nx*(long int)ny; 05266 res[kk] = (float)result; 05267 05268 if(result<valmin) {valmin = result; valpos = kk;} 05269 05270 } 05271 05272 Dict retvals; 05273 retvals["dist"] = res; 05274 retvals["pos"] = valpos; 05275 05276 EXITFUNC; 05277 return retvals; 05278 }
k-means helper
Definition at line 5170 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), and EMAN::EMData::get_ysize().
05170 { 05171 ENTERFUNC; 05172 05173 int nima = data.size(); 05174 vector<float> res(nima); 05175 double result = 0.; 05176 double valmin = 1.0e20; 05177 int valpos = -1; 05178 05179 for (int kk=0; kk<nima; kk++){ 05180 result = 0; 05181 05182 float *y_data = data[kk]->get_data(); 05183 float *x_data = image->get_data(); 05184 long totsize = image->get_xsize()*image->get_ysize(); 05185 for (long i = 0; i < totsize; i++) { 05186 double temp = x_data[i]- y_data[i]; 05187 result += temp*temp; 05188 } 05189 result /= totsize; 05190 res[kk] = (float)result; 05191 05192 if(result<valmin) {valmin = result; valpos = kk;} 05193 05194 } 05195 05196 Dict retvals; 05197 retvals["dist"] = res; 05198 retvals["pos"] = valpos; 05199 05200 EXITFUNC; 05201 return retvals; 05202 05203 }
static int EMAN::Util::mono | ( | int | k1, | |
int | k2 | |||
) | [inline, static] |
Definition at line 19877 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().
19878 { 19879 ENTERFUNC; 19880 /* Exception Handle */ 19881 if (!img) { 19882 throw NullPointerException("NULL input image"); 19883 } 19884 19885 int newx, newy, newz; 19886 bool keep_going; 19887 cout << " entered " <<endl; 19888 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 19889 //int size = nx*ny*nz; 19890 EMData * img2 = new EMData(); 19891 img2->set_size(nx,ny,nz); 19892 img2->to_zero(); 19893 float *img_ptr =img->get_data(); 19894 float *img2_ptr = img2->get_data(); 19895 int r2 = ro*ro; 19896 int r3 = r2*ro; 19897 int ri2 = ri*ri; 19898 int ri3 = ri2*ri; 19899 19900 int n2 = nx/2; 19901 19902 for (int k=-n2; k<=n2; k++) { //cout << " k "<<k <<endl; 19903 float z2 = static_cast<float>(k*k); 19904 for (int j=-n2; j<=n2; j++) { 19905 float y2 = z2 + j*j; 19906 if(y2 <= r2) { 19907 //cout << " j "<<j <<endl; 19908 19909 for (int i=-n2; i<=n2; i++) { 19910 float x2 = y2 + i*i; 19911 if(x2 <= r3) { 19912 //cout << " i "<<i <<endl; 19913 int ib = i+n2; int jb = j+n2; int kb = k+n2; 19914 if(x2 >= ri3) { 19915 // this is the outer shell, here points can only vanish 19916 if(img_ptr(ib,jb,kb) == 1.0f) { 19917 //cout << " 1 "<<ib <<endl; 19918 if(Util::get_frand(0.0f, 1.0f) > qprob){ 19919 img2_ptr(ib,jb,kb) = 0.0f; 19920 keep_going = true; 19921 //cout << " try "<<ib <<endl; 19922 while(keep_going) { 19923 newx = Util::get_irand(-ro,ro); 19924 newy = Util::get_irand(-ro,ro); 19925 newz = Util::get_irand(-ro,ro); 19926 if(newx*newx+newy*newy+newz*newz <= r3) { 19927 newx += n2; newy += n2; newz += n2; 19928 if( img_ptr(newx,newy,newz) == 0.0f) { 19929 img2_ptr(newx,newy,newz) = 1.0f; 19930 keep_going = false; } 19931 } 19932 } 19933 } else img2_ptr(ib,jb,kb) = 1.0f; 19934 } 19935 } else { 19936 // this is inner shell, the point can only move (or vanish, if all neighbors exist) 19937 if(img_ptr(ib,jb,kb) == 1.0) { 19938 if(Util::get_frand(0.0f,1.0f) > qprob) { 19939 // find out the number of neighbors 19940 float numn = -1.0f; // we already know the central one is 1 19941 for (newz = -1; newz <= 1; newz++) 19942 for (newy = -1; newy <= 1; newy++) 19943 for (newx = -1; newx <= 1; newx++) 19944 numn += img_ptr(ib+newx,jb+newy,kb+newz); 19945 img2_ptr(ib,jb,kb) = 0.0; 19946 if(numn == 26.0f) { 19947 // all neighbors exist, it has to vanish 19948 keep_going = true; 19949 while(keep_going) { 19950 newx = Util::get_irand(-ro,ro); 19951 newy = Util::get_irand(-ro,ro); 19952 newz = Util::get_irand(-ro,ro); 19953 if(newx*newx+newy*newy+newz*newz < r3) { 19954 newx += n2; newy += n2; newz += n2; 19955 if( img_ptr(newx,newy,newz) == 0.0f) { 19956 if(newx*newx+newy*newy+newz*newz < r3) { 19957 if(newx*newx+newy*newy+newz*newz < r3) { 19958 newx += n2; newy += n2; newz += n2; 19959 if( img_ptr(newx,newy,newz) == 0.0f) { 19960 img2_ptr(newx,newy,newz) = 1.0f; 19961 keep_going = false; } 19962 } 19963 } 19964 } 19965 } 19966 } 19967 } else if(numn == 25.0f) { 19968 // there is only one empty neighbor, move there 19969 for (newz = -1; newz <= 1; newz++) { 19970 for (newy = -1; newy <= 1; newy++) { 19971 for (newx = -1; newx <= 1; newx++) { 19972 if( newx != 0 && newy != 0 && newz != 0) { 19973 if(img_ptr(newx+ib,newy+jb,newz+kb) == 0.0f) { 19974 img2_ptr(newx+ib,newy+jb,newz+kb) = 1.0f; 19975 } 19976 } 19977 } 19978 } 19979 } 19980 } else { 19981 // more than one neighbor is zero, select randomly one and move there 19982 keep_going = true; 19983 while(keep_going) { 19984 newx = Util::get_irand(-1,1); 19985 newy = Util::get_irand(-1,1); 19986 newz = Util::get_irand(-1,1); 19987 if(newx != 0 && newy != 0 && newz != 0) { 19988 if(img_ptr(ib+newx,jb+newy,kb+newz) == 0.0f) { 19989 img2_ptr(ib+newx,jb+newy,kb+newz) = 1.0f;//????? 19990 keep_going = false; 19991 } 19992 } 19993 } 19994 } 19995 } else img2_ptr(ib,jb,kb) = 1.0f; 19996 } 19997 } 19998 } 19999 } 20000 } 20001 } 20002 } 20003 //for (int i=0;i<size;i++) img2_ptr[i] = img_ptr[i] + Util::get_irand(1,7); 20004 img2->update(); 20005 20006 EXITFUNC; 20007 return img2; 20008 }
Definition at line 17723 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().
17724 { 17725 ENTERFUNC; 17726 /* Exception Handle */ 17727 if (!img) { 17728 throw NullPointerException("NULL input image"); 17729 } 17730 /* ========= img *= img1 ===================== */ 17731 17732 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17733 size_t size = (size_t)nx*ny*nz; 17734 float *img_ptr = img->get_data(); 17735 float *img1_ptr = img1->get_data(); 17736 if(img->is_complex()) { 17737 for (size_t i=0; i<size; i+=2) { 17738 float tmp = img_ptr[i] * img1_ptr[i] - img_ptr[i+1] * img1_ptr[i+1] ; 17739 img_ptr[i+1] = img_ptr[i] * img1_ptr[i+1] + img_ptr[i+1] * img1_ptr[i] ; 17740 img_ptr[i] = tmp; 17741 17742 } 17743 } else { 17744 for (size_t i=0;i<size;++i) img_ptr[i] *= img1_ptr[i]; 17745 } 17746 img->update(); 17747 17748 EXITFUNC; 17749 }
void Util::mul_scalar | ( | EMData * | img, | |
float | scalar | |||
) | [static] |
Definition at line 17606 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().
17607 { 17608 ENTERFUNC; 17609 /* Exception Handle */ 17610 if (!img) { 17611 throw NullPointerException("NULL input image"); 17612 } 17613 /* ============ output = scalar*input ================== */ 17614 17615 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17616 size_t size = (size_t)nx*ny*nz; 17617 float *img_ptr =img->get_data(); 17618 for (size_t i=0;i<size;++i) img_ptr[i] *= scalar; 17619 img->update(); 17620 17621 EXITFUNC; 17622 }
Definition at line 17512 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().
17513 { 17514 ENTERFUNC; 17515 /* Exception Handle */ 17516 if (!img) { 17517 throw NullPointerException("NULL input image"); 17518 } 17519 /* ============== output = img * img1 ================ */ 17520 17521 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17522 size_t size = (size_t)nx*ny*nz; 17523 EMData * img2 = img->copy_head(); 17524 float *img_ptr =img->get_data(); 17525 float *img2_ptr = img2->get_data(); 17526 float *img1_ptr = img1->get_data(); 17527 if(img->is_complex()) { 17528 for (size_t i=0; i<size; i+=2) { 17529 img2_ptr[i] = img_ptr[i] * img1_ptr[i] - img_ptr[i+1] * img1_ptr[i+1] ; 17530 img2_ptr[i+1] = img_ptr[i] * img1_ptr[i+1] + img_ptr[i+1] * img1_ptr[i] ; 17531 } 17532 img2->set_complex(true); 17533 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17534 } else { 17535 for (size_t i=0; i<size; ++i) img2_ptr[i] = img_ptr[i] * img1_ptr[i]; 17536 img2->update(); 17537 } 17538 17539 EXITFUNC; 17540 return img2; 17541 }
Definition at line 17409 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().
17410 { 17411 ENTERFUNC; 17412 /* Exception Handle */ 17413 if (!img) { 17414 throw NullPointerException("NULL input image"); 17415 } 17416 /* ============ output = scalar*input ================== */ 17417 17418 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17419 size_t size = (size_t)nx*ny*nz; 17420 EMData * img2 = img->copy_head(); 17421 float *img_ptr =img->get_data(); 17422 float *img2_ptr = img2->get_data(); 17423 for (size_t i=0;i<size;++i)img2_ptr[i] = img_ptr[i]*scalar; 17424 img2->update(); 17425 17426 if(img->is_complex()) { 17427 img2->set_complex(true); 17428 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17429 } 17430 EXITFUNC; 17431 return img2; 17432 }
vector< float > Util::multi_align_error | ( | vector< float > | args, | |
vector< float > | all_ali_params, | |||
int | d | |||
) | [static] |
Definition at line 19612 of file util_sparx.cpp.
References multi_align_error_dfunc(), multi_align_error_func(), setulb_(), and SIXTY.
19612 { 19613 19614 const int nmax=args.size(), mmax=nmax; 19615 char task[60], csave[60]; 19616 long int lsave[4]; 19617 long int n, m, iprint, isave[44]; 19618 long int* nbd = new long int[nmax]; 19619 long int* iwa = new long int[3*nmax]; 19620 double f, factr, pgtol; 19621 double* x = new double[nmax]; 19622 double* l = new double[nmax]; 19623 double* u = new double[nmax]; 19624 double* g = new double[nmax]; 19625 double dsave[29]; 19626 double* wa = new double[2*mmax*nmax+4*nmax+12*mmax*mmax+12*mmax]; 19627 long int SIXTY=60; 19628 19629 int num_ali = nmax/3+1; 19630 int nima = all_ali_params.size()/(num_ali*4); 19631 19632 // We wish to have no output. 19633 iprint = -1; 19634 19635 //c We specify the tolerances in the stopping criteria. 19636 factr=1.0e1; 19637 pgtol=1.0e-9; 19638 19639 // We specify the dimension n of the sample problem and the number 19640 // m of limited memory corrections stored. (n and m should not 19641 // exceed the limits nmax and mmax respectively.) 19642 n=nmax; 19643 m=mmax; 19644 19645 // We now provide nbd which defines the bounds on the variables: 19646 // l specifies the lower bounds, 19647 // u specifies the upper bounds. 19648 // x specifies the initial guess 19649 for (int i=0; i<nmax; i++) { 19650 x[i] = args[i]; 19651 nbd[i] = 0; 19652 } 19653 19654 // We start the iteration by initializing task. 19655 // (**MUST clear remaining chars in task with spaces (else crash)!**) 19656 strcpy(task,"START"); 19657 for (int i=5;i<60;i++) task[i]=' '; 19658 19659 // This is the call to the L-BFGS-B code. 19660 // (* call the L-BFGS-B routine with task='START' once before loop *) 19661 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19662 int step = 1; 19663 19664 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *) 19665 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) { 19666 19667 if (strncmp(task,"FG",2)==0) { 19668 // the minimization routine has returned to request the 19669 // function f and gradient g values at the current x 19670 19671 // Compute function value f for the sample problem. 19672 f = multi_align_error_func(x, all_ali_params, nima, num_ali, d); 19673 19674 // Compute gradient g for the sample problem. 19675 multi_align_error_dfunc(x, all_ali_params, nima, num_ali, g, d); 19676 19677 } 19678 //c go back to the minimization routine. 19679 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19680 step++; 19681 } 19682 19683 //printf("Total step is %d\n", step); 19684 vector<float> res; 19685 for (int i=0; i<nmax; i++) res.push_back(static_cast<float>(x[i])); 19686 res.push_back(static_cast<float>(f)); 19687 19688 delete[] nbd; 19689 delete[] iwa; 19690 delete[] x; 19691 delete[] l; 19692 delete[] u; 19693 delete[] g; 19694 delete[] wa; 19695 19696 return res; 19697 19698 }
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 19758 of file util_sparx.cpp.
References mean(), and sqrt().
Referenced by multi_align_error().
19758 { 19759 19760 for (int i=0; i<num_ali*3-3; i++) g[i] = 0.0; 19761 19762 double* args = new double[num_ali*3]; 19763 for (int i=0; i<3*num_ali-3; i++) args[i] = x[i]; 19764 args[3*num_ali-3] = 0.0; 19765 args[3*num_ali-2] = 0.0; 19766 args[3*num_ali-1] = 0.0; 19767 double* cosa = new double[num_ali]; 19768 double* sina = new double[num_ali]; 19769 for (int i=0; i<num_ali; i++) { 19770 cosa[i] = cos(args[i*3]*M_PI/180.0); 19771 sina[i] = sin(args[i*3]*M_PI/180.0); 19772 } 19773 double* sx = new double[num_ali]; 19774 double* sy = new double[num_ali]; 19775 19776 vector<float> sqr_pixel_error(nima); 19777 19778 for (int i=0; i<nima; i++) { 19779 double sum_cosa = 0.0; 19780 double sum_sina = 0.0; 19781 for (int j=0; j<num_ali; j++) { 19782 if (static_cast<int>(ali_params[j*nima*4+i*4+3]) == 0) { 19783 sum_cosa += cos((args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 19784 sum_sina += sin((args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 19785 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]; 19786 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]; 19787 } else { 19788 sum_cosa += cos((-args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 19789 sum_sina += sin((-args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 19790 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]; 19791 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]; 19792 } 19793 } 19794 double P = sqrt(sum_cosa*sum_cosa+sum_sina*sum_sina); 19795 sum_cosa /= P; 19796 sum_sina /= P; 19797 for (int j=0; j<num_ali-1; j++) { 19798 double dx = 2.0*(sx[j]-mean(sx, num_ali)); 19799 double dy = 2.0*(sy[j]-mean(sy, num_ali)); 19800 if (static_cast<int>(ali_params[j*nima*4+i*4+3]) == 0) { 19801 g[j*3] += (d*d/4.0*(sum_cosa*sin((args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0) - 19802 sum_sina*cos((args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0)) + 19803 dx*(-ali_params[j*nima*4+i*4+1]*sina[j]-ali_params[j*nima*4+i*4+2]*cosa[j])+ 19804 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; 19805 g[j*3+1] += dx; 19806 g[j*3+2] += dy; 19807 } else { 19808 g[j*3] += (d*d/4.0*(-sum_cosa*sin((-args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0) + 19809 sum_sina*cos((-args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0)) + 19810 dx*(-ali_params[j*nima*4+i*4+1]*sina[j]+ali_params[j*nima*4+i*4+2]*cosa[j])+ 19811 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; 19812 g[j*3+1] += -dx; 19813 g[j*3+2] += dy; 19814 } 19815 } 19816 } 19817 19818 for (int i=0; i<3*num_ali-3; i++) g[i] /= (num_ali*nima); 19819 19820 delete[] args; 19821 delete[] cosa; 19822 delete[] sina; 19823 delete[] sx; 19824 delete[] sy; 19825 }
double Util::multi_align_error_func | ( | double * | x, | |
vector< float > | all_ali_params, | |||
int | nima, | |||
int | num_ali, | |||
int | d | |||
) | [static] |
Definition at line 19700 of file util_sparx.cpp.
References multi_align_error_func2().
Referenced by multi_align_error().
19700 { 19701 19702 vector<double> sqr_pixel_error = multi_align_error_func2(x, all_ali_params, nima, num_ali, d); 19703 double sum_sqr_pixel_error = 0.0; 19704 for (int i=0; i<nima; i++) sum_sqr_pixel_error += sqr_pixel_error[i]; 19705 return sum_sqr_pixel_error/static_cast<float>(nima); 19706 }
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 19709 of file util_sparx.cpp.
Referenced by multi_align_error_func().
19709 { 19710 19711 double* args = new double[num_ali*3]; 19712 for (int i=0; i<3*num_ali-3; i++) args[i] = x[i]; 19713 args[3*num_ali-3] = 0.0; 19714 args[3*num_ali-2] = 0.0; 19715 args[3*num_ali-1] = 0.0; 19716 double* cosa = new double[num_ali]; 19717 double* sina = new double[num_ali]; 19718 for (int i=0; i<num_ali; i++) { 19719 cosa[i] = cos(args[i*3]*M_PI/180.0); 19720 sina[i] = sin(args[i*3]*M_PI/180.0); 19721 } 19722 double* sx = new double[num_ali]; 19723 double* sy = new double[num_ali]; 19724 19725 vector<double> sqr_pixel_error(nima); 19726 19727 for (int i=0; i<nima; i++) { 19728 double sum_cosa = 0.0; 19729 double sum_sina = 0.0; 19730 for (int j=0; j<num_ali; j++) { 19731 if (static_cast<int>(ali_params[j*nima*4+i*4+3]) == 0) { 19732 sum_cosa += cos((args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 19733 sum_sina += sin((args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 19734 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]; 19735 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]; 19736 } else { 19737 sum_cosa += cos((-args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 19738 sum_sina += sin((-args[j*3]+ali_params[j*nima*4+i*4])*M_PI/180.0); 19739 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]; 19740 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]; 19741 } 19742 } 19743 double P = sqrt(sum_cosa*sum_cosa+sum_sina*sum_sina); 19744 sum_cosa /= P; 19745 sum_sina /= P; 19746 sqr_pixel_error[i] = d*d/4.0*(1.0-P/num_ali)+var(sx, num_ali)+var(sy, num_ali); 19747 } 19748 19749 delete[] args; 19750 delete[] cosa; 19751 delete[] sina; 19752 delete[] sx; 19753 delete[] sy; 19754 19755 return sqr_pixel_error; 19756 }
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 18990 of file util_sparx.cpp.
References Crosrng_msg_vec(), Frngs(), EMAN::EMData::get_data(), Polar2Dm(), and EMAN::EMData::set_size().
18993 { 18994 18995 int maxrin = numr[numr.size()-1]; 18996 18997 int ky = int(2*yrng/step+0.5)/2; 18998 int kx = int(2*xrng/step+0.5)/2; 18999 19000 peaks->set_size(maxrin, 2*kx+3, 2*ky+3); 19001 float *p_ccf1ds = peaks->get_data(); 19002 19003 peakm->set_size(maxrin, 2*kx+3, 2*ky+3); 19004 float *p_ccf1dm = peakm->get_data(); 19005 19006 for ( int i = 0; i<maxrin*(2*kx+3)*(2*ky+3); i++) { 19007 p_ccf1ds[i] = -1.e20f; 19008 p_ccf1dm[i] = -1.e20f; 19009 } 19010 19011 for (int i = -ky; i <= ky; i++) { 19012 float iy = i * step; 19013 for (int j = -kx; j <= kx; j++) { 19014 float ix = j*step; 19015 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 19016 Frngs(cimage, numr); 19017 Crosrng_msg_vec(crefim, cimage, numr, 19018 p_ccf1ds+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin, 19019 p_ccf1dm+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin); 19020 delete cimage; cimage = 0; 19021 } 19022 } 19023 return; 19024 }
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 19026 of file util_sparx.cpp.
References Crosrng_msg_vec(), Frngs(), EMAN::EMData::get_data(), Polar2Dm(), and EMAN::EMData::set_size().
19028 { 19029 19030 int maxrin = numr[numr.size()-1]; 19031 19032 int ky = int(2*yrng/step+0.5)/2; 19033 int kx = int(2*xrng/step+0.5)/2; 19034 19035 peaks->set_size(maxrin, 2*kx+3, 2*ky+3); 19036 float *p_ccf1ds = peaks->get_data(); 19037 19038 peakm->set_size(maxrin, 2*kx+3, 2*ky+3); 19039 float *p_ccf1dm = peakm->get_data(); 19040 19041 peaks_compress->set_size(maxrin, 1, 1); 19042 float *p_ccf1ds_compress = peaks_compress->get_data(); 19043 19044 peakm_compress->set_size(maxrin, 1, 1); 19045 float *p_ccf1dm_compress = peakm_compress->get_data(); 19046 19047 for ( int i = 0; i<maxrin*(2*kx+3)*(2*ky+3); i++) { 19048 p_ccf1ds[i] = -1.e20f; 19049 p_ccf1dm[i] = -1.e20f; 19050 } 19051 19052 for (int i = -ky; i <= ky; i++) { 19053 float iy = i * step; 19054 for (int j = -kx; j <= kx; j++) { 19055 float ix = j*step; 19056 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 19057 Frngs(cimage, numr); 19058 Crosrng_msg_vec(crefim, cimage, numr, 19059 p_ccf1ds+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin, 19060 p_ccf1dm+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin); 19061 delete cimage; cimage = 0; 19062 } 19063 } 19064 for (int x=0; x<maxrin; x++) { 19065 float maxs = -1.0e22f; 19066 float maxm = -1.0e22f; 19067 for (int i=1; i<=2*ky+1; i++) { 19068 for (int j=1; j<=2*kx+1; j++) { 19069 if (p_ccf1ds[(i*(2*kx+3)+j)*maxrin+x] > maxs) maxs = p_ccf1ds[(i*(2*kx+3)+j)*maxrin+x]; 19070 if (p_ccf1dm[(i*(2*kx+3)+j)*maxrin+x] > maxm) maxm = p_ccf1dm[(i*(2*kx+3)+j)*maxrin+x]; 19071 } 19072 } 19073 p_ccf1ds_compress[x] = maxs; 19074 p_ccf1dm_compress[x] = maxm; 19075 } 19076 return; 19077 }
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 17932 of file util_sparx.cpp.
References ang_n(), Crosrng_ms(), Frngs(), Normalize_ring(), pi, and Polar2Dm().
17934 { 17935 17936 // Manually extract. 17937 /* vector< EMAN::EMData* > crefim; 17938 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 17939 crefim.reserve(crefim_len); 17940 17941 for(std::size_t i=0;i<crefim_len;i++) { 17942 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 17943 crefim.push_back(proxy()); 17944 } 17945 */ 17946 17947 size_t crefim_len = crefim.size(); 17948 17949 int ky = int(2*yrng/step+0.5)/2; 17950 int kx = int(2*xrng/step+0.5)/2; 17951 int iref, nref=0, mirror=0; 17952 float iy, ix, sx=0, sy=0; 17953 float peak = -1.0E23f; 17954 float ang=0.0f; 17955 for (int i = -ky; i <= ky; i++) { 17956 iy = i * step ; 17957 for (int j = -kx; j <= kx; j++) { 17958 ix = j*step ; 17959 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 17960 17961 Normalize_ring( cimage, numr ); 17962 17963 Frngs(cimage, numr); 17964 // compare with all reference images 17965 // for iref in xrange(len(crefim)): 17966 for ( iref = 0; iref < (int)crefim_len; iref++) { 17967 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr); 17968 double qn = retvals["qn"]; 17969 double qm = retvals["qm"]; 17970 if(qn >= peak || qm >= peak) { 17971 sx = -ix; 17972 sy = -iy; 17973 nref = iref; 17974 if (qn >= qm) { 17975 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 17976 peak = static_cast<float>(qn); 17977 mirror = 0; 17978 } else { 17979 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 17980 peak = static_cast<float>(qm); 17981 mirror = 1; 17982 } 17983 } 17984 } delete cimage; cimage = 0; 17985 } 17986 } 17987 float co, so, sxs, sys; 17988 co = static_cast<float>( cos(ang*pi/180.0) ); 17989 so = static_cast<float>( -sin(ang*pi/180.0) ); 17990 sxs = sx*co - sy*so; 17991 sys = sx*so + sy*co; 17992 vector<float> res; 17993 res.push_back(ang); 17994 res.push_back(sxs); 17995 res.push_back(sys); 17996 res.push_back(static_cast<float>(mirror)); 17997 res.push_back(static_cast<float>(nref)); 17998 res.push_back(peak); 17999 return res; 18000 }
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 18120 of file util_sparx.cpp.
References ang_n(), Crosrng_ms_delta(), Frngs(), Normalize_ring(), pi, and Polar2Dm().
18122 { 18123 18124 // Manually extract. 18125 /* vector< EMAN::EMData* > crefim; 18126 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 18127 crefim.reserve(crefim_len); 18128 18129 for(std::size_t i=0;i<crefim_len;i++) { 18130 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 18131 crefim.push_back(proxy()); 18132 } 18133 */ 18134 18135 size_t crefim_len = crefim.size(); 18136 18137 int ky = int(2*yrng/step+0.5)/2; 18138 int kx = int(2*xrng/step+0.5)/2; 18139 int iref, nref=0, mirror=0; 18140 float iy, ix, sx=0, sy=0; 18141 float peak = -1.0E23f; 18142 float ang=0.0f; 18143 for (int i = -ky; i <= ky; i++) { 18144 iy = i * step ; 18145 for (int j = -kx; j <= kx; j++) { 18146 ix = j*step ; 18147 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18148 18149 Normalize_ring( cimage, numr ); 18150 18151 Frngs(cimage, numr); 18152 // compare with all reference images 18153 // for iref in xrange(len(crefim)): 18154 for ( iref = 0; iref < (int)crefim_len; iref++) { 18155 Dict retvals = Crosrng_ms_delta(crefim[iref], cimage, numr, delta_start, delta); 18156 double qn = retvals["qn"]; 18157 double qm = retvals["qm"]; 18158 if(qn >= peak || qm >= peak) { 18159 sx = -ix; 18160 sy = -iy; 18161 nref = iref; 18162 if (qn >= qm) { 18163 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18164 peak = static_cast<float>(qn); 18165 mirror = 0; 18166 } else { 18167 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 18168 peak = static_cast<float>(qm); 18169 mirror = 1; 18170 } 18171 } 18172 } delete cimage; cimage = 0; 18173 } 18174 } 18175 float co, so, sxs, sys; 18176 co = static_cast<float>( cos(ang*pi/180.0) ); 18177 so = static_cast<float>( -sin(ang*pi/180.0) ); 18178 sxs = sx*co - sy*so; 18179 sys = sx*so + sy*co; 18180 vector<float> res; 18181 res.push_back(ang); 18182 res.push_back(sxs); 18183 res.push_back(sys); 18184 res.push_back(static_cast<float>(mirror)); 18185 res.push_back(static_cast<float>(nref)); 18186 res.push_back(peak); 18187 return res; 18188 }
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 18247 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.
18249 { 18250 18251 // Manually extract. 18252 /* vector< EMAN::EMData* > crefim; 18253 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 18254 crefim.reserve(crefim_len); 18255 18256 for(std::size_t i=0;i<crefim_len;i++) { 18257 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 18258 crefim.push_back(proxy()); 18259 } 18260 */ 18261 size_t crefim_len = crefim.size(); 18262 const float qv = static_cast<float>( pi/180.0 ); 18263 18264 Transform * t = image->get_attr("xform.projection"); 18265 Dict d = t->get_params("spider"); 18266 if(t) {delete t; t=0;} 18267 float phi = d["phi"]; 18268 float theta = d["theta"]; 18269 int ky = int(2*yrng/step+0.5)/2; 18270 int kx = int(2*xrng/step+0.5)/2; 18271 int iref, nref=0, mirror=0; 18272 float iy, ix, sx=0, sy=0; 18273 float peak = -1.0E23f; 18274 float ang=0.0f; 18275 float imn1 = sin(theta*qv)*cos(phi*qv); 18276 float imn2 = sin(theta*qv)*sin(phi*qv); 18277 float imn3 = cos(theta*qv); 18278 vector<float> n1(crefim_len); 18279 vector<float> n2(crefim_len); 18280 vector<float> n3(crefim_len); 18281 for ( iref = 0; iref < (int)crefim_len; iref++) { 18282 n1[iref] = crefim[iref]->get_attr("n1"); 18283 n2[iref] = crefim[iref]->get_attr("n2"); 18284 n3[iref] = crefim[iref]->get_attr("n3"); 18285 } 18286 for (int i = -ky; i <= ky; i++) { 18287 iy = i * step ; 18288 for (int j = -kx; j <= kx; j++) { 18289 ix = j*step; 18290 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18291 18292 Normalize_ring( cimage, numr ); 18293 18294 Frngs(cimage, numr); 18295 // compare with all reference images 18296 // for iref in xrange(len(crefim)): 18297 for ( iref = 0; iref < (int)crefim_len; iref++) { 18298 if(abs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) { 18299 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr); 18300 double qn = retvals["qn"]; 18301 double qm = retvals["qm"]; 18302 if(qn >= peak || qm >= peak) { 18303 sx = -ix; 18304 sy = -iy; 18305 nref = iref; 18306 if (qn >= qm) { 18307 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18308 peak = static_cast<float>( qn ); 18309 mirror = 0; 18310 } else { 18311 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 18312 peak = static_cast<float>( qm ); 18313 mirror = 1; 18314 } 18315 } 18316 } 18317 } delete cimage; cimage = 0; 18318 } 18319 } 18320 float co, so, sxs, sys; 18321 if(peak == -1.0E23) { 18322 ang=0.0; sxs=0.0; sys=0.0; mirror=0; 18323 nref = -1; 18324 } else { 18325 co = cos(ang*qv); 18326 so = -sin(ang*qv); 18327 sxs = sx*co - sy*so; 18328 sys = sx*so + sy*co; 18329 } 18330 vector<float> res; 18331 res.push_back(ang); 18332 res.push_back(sxs); 18333 res.push_back(sys); 18334 res.push_back(static_cast<float>(mirror)); 18335 res.push_back(static_cast<float>(nref)); 18336 res.push_back(peak); 18337 return res; 18338 }
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 18340 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.
18342 { 18343 18344 // Manually extract. 18345 /* vector< EMAN::EMData* > crefim; 18346 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 18347 crefim.reserve(crefim_len); 18348 18349 for(std::size_t i=0;i<crefim_len;i++) { 18350 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 18351 crefim.push_back(proxy()); 18352 } 18353 */ 18354 size_t crefim_len = crefim.size(); 18355 const float qv = static_cast<float>(pi/180.0); 18356 18357 Transform* t = image->get_attr("xform.projection"); 18358 Dict d = t->get_params("spider"); 18359 if(t) {delete t; t=0;} 18360 float phi = d["phi"]; 18361 float theta = d["theta"]; 18362 float psi = d["psi"]; 18363 int ky = int(2*yrng/step+0.5)/2; 18364 int kx = int(2*xrng/step+0.5)/2; 18365 int iref, nref = 0, mirror = 0; 18366 float iy, ix, sx = 0, sy = 0; 18367 float peak = -1.0E23f; 18368 float ang = 0.0f; 18369 float imn1 = sin(theta*qv)*cos(phi*qv); 18370 float imn2 = sin(theta*qv)*sin(phi*qv); 18371 float imn3 = cos(theta*qv); 18372 vector<float> n1(crefim_len); 18373 vector<float> n2(crefim_len); 18374 vector<float> n3(crefim_len); 18375 for (iref = 0; iref < (int)crefim_len; iref++) { 18376 n1[iref] = crefim[iref]->get_attr("n1"); 18377 n2[iref] = crefim[iref]->get_attr("n2"); 18378 n3[iref] = crefim[iref]->get_attr("n3"); 18379 } 18380 bool nomirror = (theta<90.0) || ((theta==90.0) && (psi<psi_max)); 18381 if (!nomirror) { 18382 phi = fmod(phi+540.0f, 360.0f); 18383 theta = 180-theta; 18384 psi = fmod(540.0f-psi, 360.0f); 18385 } 18386 for (int i = -ky; i <= ky; i++) { 18387 iy = i * step ; 18388 for (int j = -kx; j <= kx; j++) { 18389 ix = j*step; 18390 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18391 18392 Normalize_ring(cimage, numr); 18393 18394 Frngs(cimage, numr); 18395 // compare with all reference images 18396 // for iref in xrange(len(crefim)): 18397 for (iref = 0; iref < (int)crefim_len; iref++) { 18398 if (abs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) { 18399 if (nomirror) { 18400 Dict retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, psi, 0); 18401 double qn = retvals["qn"]; 18402 if (qn >= peak) { 18403 sx = -ix; 18404 sy = -iy; 18405 nref = iref; 18406 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18407 peak = static_cast<float>(qn); 18408 mirror = 0; 18409 } 18410 } else { 18411 Dict retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, psi, 1); 18412 double qn = retvals["qn"]; 18413 if (qn >= peak) { 18414 sx = -ix; 18415 sy = -iy; 18416 nref = iref; 18417 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18418 peak = static_cast<float>(qn); 18419 mirror = 1; 18420 } 18421 } 18422 } 18423 } delete cimage; cimage = 0; 18424 } 18425 } 18426 float co, so, sxs, sys; 18427 if(peak == -1.0E23) { 18428 ang=0.0; sxs=0.0; sys=0.0; mirror=0; 18429 nref = -1; 18430 } else { 18431 co = cos(ang*qv); 18432 so = -sin(ang*qv); 18433 sxs = sx*co - sy*so; 18434 sys = sx*so + sy*co; 18435 } 18436 vector<float> res; 18437 res.push_back(ang); 18438 res.push_back(sxs); 18439 res.push_back(sys); 18440 res.push_back(static_cast<float>(mirror)); 18441 res.push_back(static_cast<float>(nref)); 18442 res.push_back(peak); 18443 return res; 18444 }
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 18190 of file util_sparx.cpp.
References ang_n(), Crosrng_ns(), Frngs(), pi, and Polar2Dm().
18192 { 18193 18194 // Manually extract. 18195 /* vector< EMAN::EMData* > crefim; 18196 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 18197 crefim.reserve(crefim_len); 18198 18199 for(std::size_t i=0;i<crefim_len;i++) { 18200 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 18201 crefim.push_back(proxy()); 18202 } 18203 */ 18204 size_t crefim_len = crefim.size(); 18205 18206 int ky = int(2*yrng/step+0.5)/2; 18207 int kx = int(2*xrng/step+0.5)/2; 18208 int iref, nref=0; 18209 float iy, ix, sx=0, sy=0; 18210 float peak = -1.0E23f; 18211 float ang=0.0f; 18212 for (int i = -ky; i <= ky; i++) { 18213 iy = i * step ; 18214 for (int j = -kx; j <= kx; j++) { 18215 ix = j*step ; 18216 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18217 Frngs(cimage, numr); 18218 // compare with all reference images 18219 // for iref in xrange(len(crefim)): 18220 for ( iref = 0; iref < (int)crefim_len; iref++) { 18221 Dict retvals = Crosrng_ns(crefim[iref], cimage, numr); 18222 double qn = retvals["qn"]; 18223 if(qn >= peak) { 18224 sx = -ix; 18225 sy = -iy; 18226 nref = iref; 18227 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18228 peak = static_cast<float>(qn); 18229 } 18230 } delete cimage; cimage = 0; 18231 } 18232 } 18233 float co, so, sxs, sys; 18234 co = static_cast<float>( cos(ang*pi/180.0) ); 18235 so = static_cast<float>( -sin(ang*pi/180.0) ); 18236 sxs = sx*co - sy*so; 18237 sys = sx*so + sy*co; 18238 vector<float> res; 18239 res.push_back(ang); 18240 res.push_back(sxs); 18241 res.push_back(sys); 18242 res.push_back(static_cast<float>(nref)); 18243 res.push_back(peak); 18244 return res; 18245 }
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 18002 of file util_sparx.cpp.
References ang_n(), Crosrng_ms(), Frngs(), Normalize_ring(), pi, and Polar2Dm().
18004 { 18005 18006 size_t crefim_len = crefim.size(); 18007 18008 int ky = int(2*yrng/step+0.5)/2; 18009 int kx = int(2*xrng/step+0.5)/2; 18010 float iy, ix; 18011 vector<float> peak(crefim_len*5, -1.0e23f); 18012 for (int i = -ky; i <= ky; i++) { 18013 iy = i * step ; 18014 for (int j = -kx; j <= kx; j++) { 18015 ix = j*step ; 18016 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18017 Normalize_ring( cimage, numr ); 18018 Frngs(cimage, numr); 18019 for (int iref = 0; iref < (int)crefim_len; iref++) { 18020 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr); 18021 double qn = retvals["qn"]; 18022 double qm = retvals["qm"]; 18023 if(qn >= peak[iref*5] || qm >= peak[iref*5]) { 18024 if (qn >= qm) { 18025 peak[iref*5] = static_cast<float>(qn); 18026 peak[iref*5+1] = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18027 peak[iref*5+2] = -ix; 18028 peak[iref*5+3] = -iy; 18029 peak[iref*5+4] = 0; 18030 } else { 18031 peak[iref*5] = static_cast<float>(qm); 18032 peak[iref*5+1] = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 18033 peak[iref*5+2] = -ix; 18034 peak[iref*5+3] = -iy; 18035 peak[iref*5+4] = 1; 18036 } 18037 } 18038 } delete cimage; cimage = 0; 18039 } 18040 } 18041 for (int iref = 0; iref < (int)crefim_len; iref++) { 18042 float ang = peak[iref*5+1]; 18043 float sx = peak[iref*5+2]; 18044 float sy = peak[iref*5+3]; 18045 float co = cos(ang*pi/180.0); 18046 float so = -sin(ang*pi/180.0); 18047 float sxs = sx*co - sy*so; 18048 float sys = sx*so + sy*co; 18049 peak[iref*5+2] = sxs; 18050 peak[iref*5+3] = sys; 18051 } 18052 return peak; 18053 }
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 18447 of file util_sparx.cpp.
References ang_n(), Crosrng_psi_0_180(), Frngs(), Normalize_ring(), pi, and Polar2Dm().
18449 { 18450 18451 size_t crefim_len = crefim.size(); 18452 18453 int iref, nref=0, mirror=0; 18454 float iy, ix, sx=0, sy=0; 18455 float peak = -1.0E23f; 18456 float ang=0.0f; 18457 int kx = int(2*xrng/step+0.5)/2; 18458 //if ynumber==-1, use the old code which process x and y direction equally. 18459 if(ynumber==-1) { 18460 int ky = int(2*yrng/step+0.5)/2; 18461 for (int i = -ky; i <= ky; i++) { 18462 iy = i * step ; 18463 for (int j = -kx; j <= kx; j++) { 18464 ix = j*step ; 18465 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18466 18467 Normalize_ring( cimage, numr ); 18468 18469 Frngs(cimage, numr); 18470 // compare with all reference images 18471 // for iref in xrange(len(crefim)): 18472 for ( iref = 0; iref < (int)crefim_len; iref++) { 18473 Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max); 18474 double qn = retvals["qn"]; 18475 double qm = retvals["qm"]; 18476 if(qn >= peak || qm >= peak) { 18477 sx = -ix; 18478 sy = -iy; 18479 nref = iref; 18480 if (qn >= qm) { 18481 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18482 peak = static_cast<float>(qn); 18483 mirror = 0; 18484 } else { 18485 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 18486 peak = static_cast<float>(qm); 18487 mirror = 1; 18488 } 18489 } 18490 } 18491 delete cimage; cimage = 0; 18492 } 18493 } 18494 } 18495 //if ynumber is given, it should be even. We need to check whether it is zero 18496 else if(ynumber==0) { 18497 sy = 0.0f; 18498 for (int j = -kx; j <= kx; j++) { 18499 ix = j*step ; 18500 EMData* cimage = Polar2Dm(image, cnx+ix, cny, numr, mode); 18501 18502 Normalize_ring( cimage, numr ); 18503 18504 Frngs(cimage, numr); 18505 // compare with all reference images 18506 // for iref in xrange(len(crefim)): 18507 for ( iref = 0; iref < (int)crefim_len; iref++) { 18508 Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max); 18509 double qn = retvals["qn"]; 18510 double qm = retvals["qm"]; 18511 if(qn >= peak || qm >= peak) { 18512 sx = -ix; 18513 nref = iref; 18514 if (qn >= qm) { 18515 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18516 peak = static_cast<float>(qn); 18517 mirror = 0; 18518 } else { 18519 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 18520 peak = static_cast<float>(qm); 18521 mirror = 1; 18522 } 18523 } 18524 } 18525 delete cimage; cimage = 0; 18526 } 18527 } else { 18528 int ky = int(ynumber/2); 18529 float stepy=2*yrng/ynumber; 18530 //std::cout<<"yrng="<<yrng<<"ynumber="<<ynumber<<"stepy=="<<stepy<<"stepx=="<<step<<std::endl; 18531 for (int i = -ky+1; i <= ky; i++) { 18532 iy = i * stepy ; 18533 for (int j = -kx; j <= kx; j++) { 18534 ix = j*step ; 18535 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18536 18537 Normalize_ring( cimage, numr ); 18538 18539 Frngs(cimage, numr); 18540 // compare with all reference images 18541 // for iref in xrange(len(crefim)): 18542 for ( iref = 0; iref < (int)crefim_len; iref++) { 18543 Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max); 18544 double qn = retvals["qn"]; 18545 double qm = retvals["qm"]; 18546 if(qn >= peak || qm >= peak) { 18547 sx = -ix; 18548 sy = -iy; 18549 nref = iref; 18550 if (qn >= qm) { 18551 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18552 peak = static_cast<float>(qn); 18553 mirror = 0; 18554 } else { 18555 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 18556 peak = static_cast<float>(qm); 18557 mirror = 1; 18558 } 18559 } 18560 } 18561 delete cimage; cimage = 0; 18562 } 18563 } 18564 } 18565 float co, so, sxs, sys; 18566 co = static_cast<float>( cos(ang*pi/180.0) ); 18567 so = static_cast<float>( -sin(ang*pi/180.0) ); 18568 sxs = sx*co - sy*so; 18569 sys = sx*so + sy*co; 18570 vector<float> res; 18571 res.push_back(ang); 18572 res.push_back(sxs); 18573 res.push_back(sys); 18574 res.push_back(static_cast<float>(mirror)); 18575 res.push_back(static_cast<float>(nref)); 18576 res.push_back(peak); 18577 return res; 18578 }
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 18737 of file util_sparx.cpp.
References ang_n(), Crosrng_psi_0_180_no_mirror(), Frngs(), Normalize_ring(), pi, and Polar2Dm().
18739 { 18740 18741 size_t crefim_len = crefim.size(); 18742 18743 int iref, nref=0, mirror=0; 18744 float iy, ix, sx=0, sy=0; 18745 float peak = -1.0E23f; 18746 float ang=0.0f; 18747 int kx = int(2*xrng/step+0.5)/2; 18748 //if ynumber==-1, use the old code which process x and y direction equally. 18749 if(ynumber==-1) { 18750 int ky = int(2*yrng/step+0.5)/2; 18751 for (int i = -ky; i <= ky; i++) { 18752 iy = i * step ; 18753 for (int j = -kx; j <= kx; j++) { 18754 ix = j*step ; 18755 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18756 18757 Normalize_ring( cimage, numr ); 18758 18759 Frngs(cimage, numr); 18760 // compare with all reference images 18761 // for iref in xrange(len(crefim)): 18762 for ( iref = 0; iref < (int)crefim_len; iref++) { 18763 Dict retvals = Crosrng_psi_0_180_no_mirror(crefim[iref], cimage, numr, psi_max); 18764 double qn = retvals["qn"]; 18765 if( qn >= peak) { 18766 sx = -ix; 18767 sy = -iy; 18768 nref = iref; 18769 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18770 peak = static_cast<float>(qn); 18771 mirror = 0; 18772 } 18773 } 18774 delete cimage; cimage = 0; 18775 } 18776 } 18777 } 18778 //if ynumber is given, it should be even. We need to check whether it is zero 18779 else if(ynumber==0) { 18780 sy = 0.0f; 18781 for (int j = -kx; j <= kx; j++) { 18782 ix = j*step ; 18783 iy = 0.0f ; 18784 EMData* cimage = Polar2Dm(image, cnx+ix, cny, numr, mode); 18785 18786 Normalize_ring( cimage, numr ); 18787 18788 Frngs(cimage, numr); 18789 // compare with all reference images 18790 // for iref in xrange(len(crefim)): 18791 for ( iref = 0; iref < (int)crefim_len; iref++) { 18792 Dict retvals = Crosrng_psi_0_180_no_mirror(crefim[iref], cimage, numr, psi_max); 18793 double qn = retvals["qn"]; 18794 if( qn >= peak ) { 18795 sx = -ix; 18796 nref = iref; 18797 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18798 peak = static_cast<float>(qn); 18799 mirror = 0; 18800 } 18801 } 18802 delete cimage; cimage = 0; 18803 } 18804 } else { 18805 int ky = int(ynumber/2); 18806 float stepy=2*yrng/ynumber; 18807 //std::cout<<"yrng="<<yrng<<"ynumber="<<ynumber<<"stepy=="<<stepy<<"stepx=="<<step<<std::endl; 18808 for (int i = -ky+1; i <= ky; i++) { 18809 iy = i * stepy ; 18810 for (int j = -kx; j <= kx; j++) { 18811 ix = j*step ; 18812 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18813 18814 Normalize_ring( cimage, numr ); 18815 18816 Frngs(cimage, numr); 18817 // compare with all reference images 18818 // for iref in xrange(len(crefim)): 18819 for ( iref = 0; iref < (int)crefim_len; iref++) { 18820 Dict retvals = Crosrng_psi_0_180_no_mirror(crefim[iref], cimage, numr, psi_max); 18821 double qn = retvals["qn"]; 18822 if( qn >= peak) { 18823 sx = -ix; 18824 sy = -iy; 18825 nref = iref; 18826 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18827 peak = static_cast<float>(qn); 18828 mirror = 0; 18829 } 18830 } 18831 delete cimage; cimage = 0; 18832 } 18833 } 18834 } 18835 float co, so, sxs, sys; 18836 co = static_cast<float>( cos(ang*pi/180.0) ); 18837 so = static_cast<float>( -sin(ang*pi/180.0) ); 18838 sxs = sx*co - sy*so; 18839 sys = sx*so + sy*co; 18840 vector<float> res; 18841 res.push_back(ang); 18842 res.push_back(sxs); 18843 res.push_back(sys); 18844 res.push_back(static_cast<float>(mirror)); 18845 res.push_back(static_cast<float>(nref)); 18846 res.push_back(peak); 18847 return res; 18848 }
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 18852 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.
18854 { 18855 18856 size_t crefim_len = crefim.size(); 18857 const float qv = static_cast<float>( pi/180.0 ); 18858 Transform * t = image->get_attr("xform.projection"); 18859 Dict d = t->get_params("spider"); 18860 if(t) {delete t; t=0;} 18861 float phi = d["phi"]; 18862 float theta = d["theta"]; 18863 float imn1 = sin(theta*qv)*cos(phi*qv); 18864 float imn2 = sin(theta*qv)*sin(phi*qv); 18865 float imn3 = cos(theta*qv); 18866 vector<float> n1(crefim_len); 18867 vector<float> n2(crefim_len); 18868 vector<float> n3(crefim_len); 18869 int iref, nref=-1, mirror=0; 18870 float iy, ix, sx=0, sy=0; 18871 float peak = -1.0E23f; 18872 float ang=0.0f; 18873 int kx = int(2*xrng/step+0.5)/2; 18874 18875 for ( iref = 0; iref < (int)crefim_len; iref++) { 18876 n1[iref] = crefim[iref]->get_attr("n1"); 18877 n2[iref] = crefim[iref]->get_attr("n2"); 18878 n3[iref] = crefim[iref]->get_attr("n3"); 18879 } 18880 18881 //if ynumber==-1, use the old code which process x and y direction equally. 18882 if(ynumber==-1) { 18883 int ky = int(2*yrng/step+0.5)/2; 18884 for (int i = -ky; i <= ky; i++) { 18885 iy = i * step ; 18886 for (int j = -kx; j <= kx; j++) { 18887 ix = j*step ; 18888 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18889 18890 Normalize_ring( cimage, numr ); 18891 18892 Frngs(cimage, numr); 18893 // compare with all reference images 18894 // for iref in xrange(len(crefim)): 18895 for ( iref = 0; iref < (int)crefim_len; iref++) { 18896 if(fabs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) { 18897 Dict retvals = Crosrng_psi_0_180_no_mirror(crefim[iref], cimage, numr, psi_max); 18898 double qn = retvals["qn"]; 18899 if( qn >= peak) { 18900 sx = -ix; 18901 sy = -iy; 18902 nref = iref; 18903 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18904 peak = static_cast<float>(qn); 18905 mirror = 0; 18906 } 18907 } 18908 } 18909 delete cimage; cimage = 0; 18910 } 18911 } 18912 } 18913 //if ynumber is given, it should be even. We need to check whether it is zero 18914 else if(ynumber==0) { 18915 sy = 0.0f; 18916 for (int j = -kx; j <= kx; j++) { 18917 ix = j*step ; 18918 iy = 0.0f ; 18919 EMData* cimage = Polar2Dm(image, cnx+ix, cny, numr, mode); 18920 18921 Normalize_ring( cimage, numr ); 18922 18923 Frngs(cimage, numr); 18924 // compare with all reference images 18925 // for iref in xrange(len(crefim)): 18926 for ( iref = 0; iref < (int)crefim_len; iref++) { 18927 if(fabs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) { 18928 Dict retvals = Crosrng_psi_0_180_no_mirror(crefim[iref], cimage, numr, psi_max); 18929 double qn = retvals["qn"]; 18930 if( qn >= peak ) { 18931 sx = -ix; 18932 nref = iref; 18933 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18934 peak = static_cast<float>(qn); 18935 mirror = 0; 18936 } 18937 } 18938 } 18939 delete cimage; cimage = 0; 18940 } 18941 } else { 18942 int ky = int(ynumber/2); 18943 float stepy=2*yrng/ynumber; 18944 //std::cout<<"yrng="<<yrng<<"ynumber="<<ynumber<<"stepy=="<<stepy<<"stepx=="<<step<<std::endl; 18945 for (int i = -ky+1; i <= ky; i++) { 18946 iy = i * stepy ; 18947 for (int j = -kx; j <= kx; j++) { 18948 ix = j*step ; 18949 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18950 18951 Normalize_ring( cimage, numr ); 18952 18953 Frngs(cimage, numr); 18954 // compare with all reference images 18955 // for iref in xrange(len(crefim)): 18956 for ( iref = 0; iref < (int)crefim_len; iref++) { 18957 if(fabs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) { 18958 Dict retvals = Crosrng_psi_0_180_no_mirror(crefim[iref], cimage, numr, psi_max); 18959 double qn = retvals["qn"]; 18960 if( qn >= peak) { 18961 sx = -ix; 18962 sy = -iy; 18963 nref = iref; 18964 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18965 peak = static_cast<float>(qn); 18966 mirror = 0; 18967 } 18968 } 18969 } 18970 delete cimage; cimage = 0; 18971 } 18972 } 18973 } 18974 float co, so, sxs, sys; 18975 co = static_cast<float>( cos(ang*pi/180.0) ); 18976 so = static_cast<float>( -sin(ang*pi/180.0) ); 18977 sxs = sx*co - sy*so; 18978 sys = sx*so + sy*co; 18979 vector<float> res; 18980 res.push_back(ang); 18981 res.push_back(sxs); 18982 res.push_back(sys); 18983 res.push_back(static_cast<float>(mirror)); 18984 res.push_back(static_cast<float>(nref)); 18985 res.push_back(peak); 18986 return res; 18987 }
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 | |||
) | [static] |
Definition at line 18580 of file util_sparx.cpp.
References ang_n(), Crosrng_psi_0_180(), Frngs(), get_attr(), EMAN::EMData::get_attr(), Normalize_ring(), phi, pi, Polar2Dm(), t, and theta.
18582 { 18583 18584 size_t crefim_len = crefim.size(); 18585 18586 int iref, nref=-1, mirror=0; 18587 float iy, ix, sx=0, sy=0; 18588 float peak = -1.0E23f; 18589 float ang=0.0f; 18590 const float qv = static_cast<float>( pi/180.0 ); 18591 Transform * t = image->get_attr("xform.projection"); 18592 Dict d = t->get_params("spider"); 18593 if(t) {delete t; t=0;} 18594 float phi = d["phi"]; 18595 float theta = d["theta"]; 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 18608 int kx = int(2*xrng/step+0.5)/2; 18609 //if ynumber==-1, use the old code which process x and y direction equally. 18610 if(ynumber==-1) { 18611 int ky = int(2*yrng/step+0.5)/2; 18612 for (int i = -ky; i <= ky; i++) { 18613 iy = i * step ; 18614 for (int j = -kx; j <= kx; j++) { 18615 ix = j*step ; 18616 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18617 18618 Normalize_ring( cimage, numr ); 18619 18620 Frngs(cimage, numr); 18621 // compare with all reference images 18622 // for iref in xrange(len(crefim)): 18623 for ( iref = 0; iref < (int)crefim_len; iref++) { 18624 if(fabs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) { 18625 Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max); 18626 double qn = retvals["qn"]; 18627 double qm = retvals["qm"]; 18628 if(qn >= peak || qm >= peak) { 18629 sx = -ix; 18630 sy = -iy; 18631 nref = iref; 18632 if (qn >= qm) { 18633 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18634 peak = static_cast<float>(qn); 18635 mirror = 0; 18636 } else { 18637 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 18638 peak = static_cast<float>(qm); 18639 mirror = 1; 18640 } 18641 } 18642 } 18643 } 18644 delete cimage; cimage = 0; 18645 } 18646 } 18647 } 18648 //if ynumber is given, it should be even. We need to check whether it is zero 18649 else if(ynumber==0) { 18650 sy = 0.0f; 18651 for (int j = -kx; j <= kx; j++) { 18652 ix = j*step ; 18653 EMData* cimage = Polar2Dm(image, cnx+ix, cny, numr, mode); 18654 18655 Normalize_ring( cimage, numr ); 18656 18657 Frngs(cimage, numr); 18658 // compare with all reference images 18659 // for iref in xrange(len(crefim)): 18660 for ( iref = 0; iref < (int)crefim_len; iref++) { 18661 if(fabs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) { 18662 Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max); 18663 double qn = retvals["qn"]; 18664 double qm = retvals["qm"]; 18665 if(qn >= peak || qm >= peak) { 18666 sx = -ix; 18667 nref = iref; 18668 if (qn >= qm) { 18669 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18670 peak = static_cast<float>(qn); 18671 mirror = 0; 18672 } else { 18673 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 18674 peak = static_cast<float>(qm); 18675 mirror = 1; 18676 } 18677 } 18678 } 18679 } 18680 delete cimage; cimage = 0; 18681 } 18682 } else { 18683 int ky = int(ynumber/2); 18684 float stepy=2*yrng/ynumber; 18685 //std::cout<<"yrng="<<yrng<<"ynumber="<<ynumber<<"stepy=="<<stepy<<"stepx=="<<step<<std::endl; 18686 for (int i = -ky+1; i <= ky; i++) { 18687 iy = i * stepy ; 18688 for (int j = -kx; j <= kx; j++) { 18689 ix = j*step ; 18690 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18691 18692 Normalize_ring( cimage, numr ); 18693 18694 Frngs(cimage, numr); 18695 // compare with all reference images 18696 // for iref in xrange(len(crefim)): 18697 for ( iref = 0; iref < (int)crefim_len; iref++) { 18698 if(fabs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) { 18699 Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max); 18700 double qn = retvals["qn"]; 18701 double qm = retvals["qm"]; 18702 if(qn >= peak || qm >= peak) { 18703 sx = -ix; 18704 sy = -iy; 18705 nref = iref; 18706 if (qn >= qm) { 18707 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18708 peak = static_cast<float>(qn); 18709 mirror = 0; 18710 } else { 18711 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 18712 peak = static_cast<float>(qm); 18713 mirror = 1; 18714 } 18715 } 18716 } 18717 } 18718 delete cimage; cimage = 0; 18719 } 18720 } 18721 } 18722 float co, so, sxs, sys; 18723 co = static_cast<float>( cos(ang*pi/180.0) ); 18724 so = static_cast<float>( -sin(ang*pi/180.0) ); 18725 sxs = sx*co - sy*so; 18726 sys = sx*so + sy*co; 18727 vector<float> res; 18728 res.push_back(ang); 18729 res.push_back(sxs); 18730 res.push_back(sys); 18731 res.push_back(static_cast<float>(mirror)); 18732 res.push_back(static_cast<float>(nref)); 18733 res.push_back(peak); 18734 return res; 18735 }
static int EMAN::Util::nint180 | ( | float | arg | ) | [inline, static] |
void Util::Normalize_ring | ( | EMData * | ring, | |
const vector< int > & | numr | |||
) | [static] |
Definition at line 17899 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().
17900 { 17901 float* data = ring->get_data(); 17902 float av=0.0; 17903 float sq=0.0; 17904 float nn=0.0; 17905 int nring = numr.size()/3; 17906 for( int i=0; i < nring; ++i ) 17907 { 17908 int numr3i = numr[3*i+2]; 17909 int numr2i = numr[3*i+1]-1; 17910 float w = numr[3*i]*2*M_PI/float(numr[3*i+2]); 17911 for( int j=0; j < numr3i; ++j ) 17912 { 17913 int jc = numr2i+j; 17914 av += data[jc] * w; 17915 sq += data[jc] * data[jc] * w; 17916 nn += w; 17917 } 17918 } 17919 17920 float avg = av/nn; 17921 float sgm = sqrt( (sq-av*av/nn)/nn ); 17922 size_t n = (size_t)ring->get_xsize() * ring->get_ysize() * ring->get_zsize(); 17923 for( size_t i=0; i < n; ++i ) 17924 { 17925 data[i] -= avg; 17926 data[i] /= sgm; 17927 } 17928 17929 ring->update(); 17930 }
Definition at line 17809 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().
17810 { 17811 ENTERFUNC; 17812 /* Exception Handle */ 17813 if (!img) { 17814 throw NullPointerException("NULL input image"); 17815 } 17816 /* ============== img is modulus of a complex image in FFT format (so its imaginary parts are zero), 17817 output is img packed into real image with Friedel part added, ================ */ 17818 17819 int nxo=img->get_xsize(), ny=img->get_ysize(), nz=img->get_zsize(); 17820 int nx = nxo - 2 + img->is_fftodd(); 17821 int lsd2 = (nx + 2 - nx%2) / 2; // Extended x-dimension of the complex image 17822 int nyt, nzt; 17823 int nx2 = nx/2; 17824 int ny2 = ny/2; if(ny2 == 0) nyt =0; else nyt=ny; 17825 int nz2 = nz/2; if(nz2 == 0) nzt =0; else nzt=nz; 17826 int nx2p = nx2+nx%2; 17827 int ny2p = ny2+ny%2; 17828 int nz2p = nz2+nz%2; 17829 EMData& power = *(new EMData()); // output image 17830 power.set_size(nx, ny, nz); 17831 power.set_array_offsets(-nx2,-ny2,-nz2); 17832 //img->set_array_offsets(1,1,1); 17833 float *img_ptr = img->get_data(); 17834 for (int iz = 1; iz <= nz; iz++) { 17835 int jz=iz-1; 17836 if(jz>=nz2p) jz=jz-nzt; 17837 for (int iy = 1; iy <= ny; iy++) { 17838 int jy=iy-1; 17839 if(jy>=ny2p) jy=jy-nyt; 17840 for (int ix = 1; ix <= lsd2; ix++) { 17841 int jx=ix-1; 17842 if(jx>=nx2p) jx=jx-nx; 17843 power(jx,jy,jz) = img_ptr(ix,iy,iz); //real(img->cmplx(ix,iy,iz)); 17844 } 17845 } 17846 } 17847 // Create the Friedel related half 17848 int nzb, nze, nyb, nye, nxb, nxe; 17849 nxb =-nx2+(nx+1)%2; 17850 nxe = nx2-(nx+1)%2; 17851 if(ny2 == 0) {nyb =0; nye = 0;} else {nyb =-ny2+(ny+1)%2; nye = ny2-(ny+1)%2;} 17852 if(nz2 == 0) {nzb =0; nze = 0;} else {nzb =-nz2+(nz+1)%2; nze = nz2-(nz+1)%2;} 17853 for (int iz = nzb; iz <= nze; iz++) { 17854 for (int iy = nyb; iy <= nye; iy++) { 17855 for (int ix = 1; ix <= nxe; ix++) { // Note this loop begins with 1 - FFT should create correct Friedel related 0 plane 17856 power(-ix,-iy,-iz) = power(ix,iy,iz); 17857 } 17858 } 17859 } 17860 if(ny2 != 0) { 17861 if(nz2 != 0) { 17862 if(nz%2 == 0) { //if nz even, fix the first slice 17863 for (int iy = nyb; iy <= nye; iy++) { 17864 for (int ix = nxb; ix <= -1; ix++) { 17865 power(ix,iy,-nz2) = power(-ix,-iy,-nz2); 17866 } 17867 } 17868 if(ny%2 == 0) { //if ny even, fix the first line 17869 for (int ix = nxb; ix <= -1; ix++) { 17870 power(ix,-ny2,-nz2) = power(-ix,-ny2,-nz2); 17871 } 17872 } 17873 } 17874 } 17875 if(ny%2 == 0) { //if ny even, fix the first column 17876 for (int iz = nzb; iz <= nze; iz++) { 17877 for (int ix = nxb; ix <= -1; ix++) { 17878 power(ix,-ny2,-iz) = power(-ix,-ny2,iz); 17879 } 17880 } 17881 } 17882 17883 } 17884 power.update(); 17885 power.set_array_offsets(0,0,0); 17886 return &power; 17887 }
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 5437 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().
05438 { 05439 /* Exception Handle */ 05440 if (!img) throw NullPointerException("NULL input image"); 05441 /* ============================== */ 05442 05443 // Get the size of the input image 05444 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 05445 /* ============================== */ 05446 05447 /* Exception Handle */ 05448 if(new_nx<nx || new_ny<ny || new_nz<nz) 05449 throw ImageDimensionException("The size of the padded image cannot be lower than the input image size."); 05450 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) 05451 throw ImageDimensionException("The offset inconsistent with the input image size. Solution: Change the offset parameters"); 05452 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)))) 05453 throw ImageDimensionException("The offset inconsistent with the input image size. Solution: Change the offset parameters"); 05454 /* ============================== */ 05455 05456 EMData* pading = img->copy_head(); 05457 pading->set_size(new_nx, new_ny, new_nz); 05458 float *inp = img->get_data(); 05459 float *outp = pading->get_data(); 05460 05461 05462 /* Calculation of the average and the circumference values for background substitution 05463 =======================================================================================*/ 05464 float background; 05465 05466 if (strcmp(params,"average")==0) background = img->get_attr("mean"); 05467 else if (strcmp(params,"circumference")==0) { 05468 float sum1=0.0f; 05469 size_t cnt=0; 05470 for(int i=0;i<nx;i++) { 05471 sum1 += inp(i,0,0) + inp(i,ny-1,nz-1); 05472 cnt+=2; 05473 } 05474 if(nz-1 == 0) { 05475 for (int j=1;j<ny-1;j++) { 05476 sum1 += inp(1,j,0) + inp(nx-1,j,0); 05477 cnt+=2; 05478 } 05479 } else { 05480 for (int k=1;k<nz-1;k++) { 05481 for (int j=1;j<ny-1;j++) { 05482 sum1 += inp(1,j,0) + inp(nx-1,j,0); 05483 cnt+=2; 05484 } 05485 } 05486 } 05487 background = sum1/cnt; 05488 } else { 05489 background = static_cast<float>( atof( params ) ); 05490 } 05491 /*=====================================================================================*/ 05492 05493 /*Initial Padding */ 05494 int new_st_x=0,new_st_y=0,new_st_z=0; 05495 for (int k=0;k<new_nz;k++) 05496 for(int j=0;j<new_ny;j++) 05497 for (int i=0;i<new_nx;i++) 05498 outp(i,j,k)=background; 05499 /*============================== */ 05500 05501 /* Calculation of the start point */ 05502 new_st_x=int((new_nx/2-nx/2) + x_offset); 05503 new_st_y=int((new_ny/2-ny/2) + y_offset); 05504 new_st_z=int((new_nz/2-nz/2) + z_offset); 05505 /* ============================== */ 05506 05507 for (int k=0;k<nz;k++) 05508 for(int j=0;j<ny;j++) 05509 for(int i=0;i<nx;i++) 05510 outp(i,j,k)=inp(i,j,k); 05511 pading->update(); 05512 return pading; 05513 }
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 2141 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.
02141 { 02142 int nsam = image->get_xsize(); 02143 int nrow = image->get_ysize(); 02144 int nring = numr.size()/3; 02145 int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 02146 EMData* out = new EMData(); 02147 out->set_size(lcirc,1,1); 02148 char mode = (cmode == "F" || cmode == "f") ? 'f' : 'h'; 02149 float *xim = image->get_data(); 02150 float *circ = out->get_data(); 02151 /* alrq(image->get_data(), nsam, nrow, &numr[0], out->get_data(), lcirc, nring, cmode); 02152 return out; 02153 } 02154 void Util::alrq(float *xim, int nsam , int nrow , int *numr, 02155 float *circ, int lcirc, int nring, char mode) 02156 {*/ 02157 /* 02158 c 02159 c purpose: 02160 c 02161 c resmaple to polar coordinates 02162 c 02163 */ 02164 // dimension xim(nsam,nrow),circ(lcirc) 02165 // integer numr(3,nring) 02166 02167 double dfi, dpi; 02168 int ns2, nr2, i, inr, l, nsim, kcirc, lt, j; 02169 float yq, xold, yold, fi, x, y; 02170 02171 ns2 = nsam/2+1; 02172 nr2 = nrow/2+1; 02173 dpi = 2.0*atan(1.0); 02174 02175 for (i=1;i<=nring;i++) { 02176 // radius of the ring 02177 inr = numr(1,i); 02178 yq = static_cast<float>(inr); 02179 l = numr(3,i); 02180 if (mode == 'h' || mode == 'H') lt = l/2; 02181 else lt = l/4; 02182 02183 nsim = lt-1; 02184 dfi = dpi/(nsim+1); 02185 kcirc = numr(2,i); 02186 xold = 0.0f; 02187 yold = static_cast<float>(inr); 02188 circ(kcirc) = quadri(xold+(float)ns2,yold+(float)nr2,nsam,nrow,xim); 02189 xold = static_cast<float>(inr); 02190 yold = 0.0f; 02191 circ(lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02192 02193 if (mode == 'f' || mode == 'F') { 02194 xold = 0.0f; 02195 yold = static_cast<float>(-inr); 02196 circ(lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02197 xold = static_cast<float>(-inr); 02198 yold = 0.0f; 02199 circ(lt+lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02200 } 02201 02202 for (j=1;j<=nsim;j++) { 02203 fi = static_cast<float>(dfi*j); 02204 x = sin(fi)*yq; 02205 y = cos(fi)*yq; 02206 xold = x; 02207 yold = y; 02208 circ(j+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02209 xold = y; 02210 yold = -x; 02211 circ(j+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02212 02213 if (mode == 'f' || mode == 'F') { 02214 xold = -x; 02215 yold = -y; 02216 circ(j+lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02217 xold = -y; 02218 yold = x; 02219 circ(j+lt+lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02220 } 02221 } 02222 } 02223 return out; 02224 }
EMData * Util::Polar2Dm | ( | EMData * | image, | |
float | cns2, | |||
float | cnr2, | |||
vector< int > | numr, | |||
string | cmode | |||
) | [static] |
Definition at line 2226 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().
02226 { 02227 int nsam = image->get_xsize(); 02228 int nrow = image->get_ysize(); 02229 int nring = numr.size()/3; 02230 int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 02231 EMData* out = new EMData(); 02232 out->set_size(lcirc,1,1); 02233 char mode = (cmode == "F" || cmode == "f") ? 'f' : 'h'; 02234 float *xim = image->get_data(); 02235 float *circ = out->get_data(); 02236 double dpi, dfi; 02237 int it, jt, inr, l, nsim, kcirc, lt; 02238 float xold, yold, fi, x, y; 02239 02240 // cns2 and cnr2 are predefined centers 02241 // no need to set to zero, all elements are defined 02242 dpi = 2*atan(1.0); 02243 for (it=1; it<=nring; it++) { 02244 // radius of the ring 02245 inr = numr(1,it); 02246 02247 // "F" means a full circle interpolation 02248 // "H" means a half circle interpolation 02249 02250 l = numr(3,it); 02251 if ( mode == 'h' || mode == 'H' ) lt = l / 2; 02252 else lt = l / 4; 02253 02254 nsim = lt - 1; 02255 dfi = dpi / (nsim+1); 02256 kcirc = numr(2,it); 02257 xold = 0.0f+cns2; 02258 yold = inr+cnr2; 02259 02260 Assert( kcirc <= lcirc ); 02261 circ(kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on 90 degree 02262 02263 xold = inr+cns2; 02264 yold = 0.0f+cnr2; 02265 Assert( lt+kcirc <= lcirc ); 02266 circ(lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on 0 degree 02267 02268 if ( mode == 'f' || mode == 'F' ) { 02269 xold = 0.0f+cns2; 02270 yold = -inr+cnr2; 02271 Assert( lt+lt+kcirc <= lcirc ); 02272 circ(lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on 270 degree 02273 02274 xold = -inr+cns2; 02275 yold = 0.0f+cnr2; 02276 Assert(lt+lt+lt+kcirc <= lcirc ); 02277 circ(lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on 180 degree 02278 } 02279 02280 for (jt=1; jt<=nsim; jt++) { 02281 fi = static_cast<float>(dfi * jt); 02282 x = sin(fi) * inr; 02283 y = cos(fi) * inr; 02284 02285 xold = x+cns2; 02286 yold = y+cnr2; 02287 02288 Assert( jt+kcirc <= lcirc ); 02289 circ(jt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on the first quadrant 02290 02291 xold = y+cns2; 02292 yold = -x+cnr2; 02293 02294 Assert( jt+lt+kcirc <= lcirc ); 02295 circ(jt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on the fourth quadrant 02296 02297 if ( mode == 'f' || mode == 'F' ) { 02298 xold = -x+cns2; 02299 yold = -y+cnr2; 02300 02301 Assert( jt+lt+lt+kcirc <= lcirc ); 02302 circ(jt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on the third quadrant 02303 02304 xold = -y+cns2; 02305 yold = x+cnr2; 02306 02307 Assert( jt+lt+lt+lt+kcirc <= lcirc ); 02308 circ(jt+lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on the second quadrant 02309 } 02310 } // end for jt 02311 } //end for it 02312 return out; 02313 }
EMData * Util::Polar2Dmi | ( | EMData * | image, | |
float | cns2, | |||
float | cnr2, | |||
vector< int > | numr, | |||
string | cmode, | |||
Util::KaiserBessel & | kb | |||
) | [static] |
Definition at line 2509 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.
02509 { 02510 // input image is twice the size of the original image 02511 int nring = numr.size()/3; 02512 int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 02513 EMData* out = new EMData(); 02514 out->set_size(lcirc,1,1); 02515 char mode = (cmode == "F" || cmode == "f") ? 'f' : 'h'; 02516 float *circ = out->get_data(); 02517 float *fimage = image->get_data(); 02518 int nx = image->get_xsize(); 02519 int ny = image->get_ysize(); 02520 int nz = image->get_zsize(); 02521 double dpi, dfi; 02522 int it, jt, inr, l, nsim, kcirc, lt; 02523 float yq, xold, yold, fi, x, y; 02524 02525 // cns2 and cnr2 are predefined centers 02526 // no need to set to zero, all elements are defined 02527 02528 dpi = 2*atan(1.0); 02529 for (it=1;it<=nring;it++) { 02530 // radius of the ring 02531 inr = numr(1,it); 02532 yq = static_cast<float>(inr); 02533 02534 l = numr(3,it); 02535 if ( mode == 'h' || mode == 'H' ) lt = l / 2; 02536 else lt = l / 4; 02537 02538 nsim = lt - 1; 02539 dfi = dpi / (nsim+1); 02540 kcirc = numr(2,it); 02541 xold = 0.0f; 02542 yold = static_cast<float>(inr); 02543 circ(kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02544 // circ(kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02545 02546 xold = static_cast<float>(inr); 02547 yold = 0.0f; 02548 circ(lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02549 // circ(lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02550 02551 if ( mode == 'f' || mode == 'F' ) { 02552 xold = 0.0f; 02553 yold = static_cast<float>(-inr); 02554 circ(lt+lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02555 // circ(lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02556 02557 xold = static_cast<float>(-inr); 02558 yold = 0.0f; 02559 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); 02560 // circ(lt+lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02561 } 02562 02563 for (jt=1;jt<=nsim;jt++) { 02564 fi = static_cast<float>(dfi * jt); 02565 x = sin(fi) * yq; 02566 y = cos(fi) * yq; 02567 02568 xold = x; 02569 yold = y; 02570 circ(jt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02571 // circ(jt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02572 02573 xold = y; 02574 yold = -x; 02575 circ(jt+lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02576 // circ(jt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02577 02578 if ( mode == 'f' || mode == 'F' ) { 02579 xold = -x; 02580 yold = -y; 02581 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); 02582 // circ(jt+lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02583 02584 xold = -y; 02585 yold = x; 02586 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); 02587 // circ(jt+lt+lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02588 } 02589 } // end for jt 02590 } //end for it 02591 return out; 02592 }
void Util::prb1d | ( | double * | b, | |
int | npoint, | |||
float * | pos | |||
) | [static] |
Definition at line 3130 of file util_sparx.cpp.
References b.
Referenced by Crosrng_e(), Crosrng_ew(), Crosrng_ms(), Crosrng_ns(), Crosrng_psi_0_180(), Crosrng_psi_0_180_no_mirror(), and Crosrng_sm_psi().
03130 { 03131 double c2,c3; 03132 int nhalf; 03133 03134 nhalf = npoint/2 + 1; 03135 *pos = 0.0; 03136 03137 if (npoint == 7) { 03138 c2 = 49.*b(1) + 6.*b(2) - 21.*b(3) - 32.*b(4) - 27.*b(5) 03139 - 6.*b(6) + 31.*b(7); 03140 c3 = 5.*b(1) - 3.*b(3) - 4.*b(4) - 3.*b(5) + 5.*b(7); 03141 } 03142 else if (npoint == 5) { 03143 c2 = (74.*b(1) - 23.*b(2) - 60.*b(3) - 37.*b(4) 03144 + 46.*b(5) ) / (-70.); 03145 c3 = (2.*b(1) - b(2) - 2.*b(3) - b(4) + 2.*b(5) ) / 14.0; 03146 } 03147 else if (npoint == 3) { 03148 c2 = (5.*b(1) - 8.*b(2) + 3.*b(3) ) / (-2.0); 03149 c3 = (b(1) - 2.*b(2) + b(3) ) / 2.0; 03150 } 03151 //else if (npoint == 9) { 03152 else { // at least one has to be true!! 03153 c2 = (1708.*b(1) + 581.*b(2) - 246.*b(3) - 773.*b(4) 03154 - 1000.*b(5) - 927.*b(6) - 554.*b(7) + 119.*b(8) 03155 + 1092.*b(9) ) / (-4620.); 03156 c3 = (28.*b(1) + 7.*b(2) - 8.*b(3) - 17.*b(4) - 20.*b(5) 03157 - 17.*b(6) - 8.*b(7) + 7.*b(8) + 28.*b(9) ) / 924.0; 03158 } 03159 if (c3 != 0.0) *pos = static_cast<float>(c2/(2.0*c3) - nhalf); 03160 }
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 6414 of file util_sparx.cpp.
References call_cl1(), log(), and q.
06415 { 06416 int k,m,n1,klmd,klm2d,nklmd,n2d,n_larg,l, n2; 06417 06418 k=(int)pw.size(); 06419 l=0; 06420 m=k; 06421 n2=n+2; 06422 n1=n+1; 06423 klmd=k+l+m; 06424 klm2d= k+l+m+2; 06425 nklmd=k+l+m+n; 06426 n2d=n+2; 06427 /*size has to be increased when N is large*/ 06428 n_larg=klmd*2; 06429 klm2d=n_larg+klm2d; 06430 klmd=n_larg+klmd; 06431 nklmd=n_larg+nklmd; 06432 int size_q=klm2d*n2d; 06433 int size_cu=nklmd*2; 06434 static int i__; 06435 06436 double *q ; 06437 double *x ; 06438 double *res; 06439 double *cu; 06440 float *q2; 06441 float *pw_; 06442 long int *iu; 06443 double *s; 06444 q = (double*)calloc(size_q,sizeof(double)); 06445 x = (double*)calloc(n2d,sizeof(double)); 06446 res = (double*)calloc(klmd,sizeof(double)); 06447 cu =(double*)calloc(size_cu,sizeof(double)); 06448 s = (double*)calloc(klmd,sizeof(double)); 06449 q2 = (float*)calloc(size_q,sizeof(float)); 06450 iu = (long int*)calloc(size_cu,sizeof(long int)); 06451 pw_ = (float*)calloc(k,sizeof(float)); 06452 06453 for( i__ =0;i__<k;++i__) 06454 { 06455 pw_[i__]=log(pw[i__]); } 06456 long int l_k=k; 06457 long int l_n=n; 06458 long int l_iswi=iswi; 06459 vector<float> cl1_res; 06460 cl1_res=Util::call_cl1(&l_k, &l_n, &ps, &l_iswi, pw_, q2, q, x, res, cu, s, iu); 06461 free(q); 06462 free(x); 06463 free(res); 06464 free(s); 06465 free(cu); 06466 free(q2); 06467 free(iu); 06468 free(pw_); 06469 return cl1_res; 06470 }
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 650 of file util_sparx.cpp.
Referenced by alrl_ms(), Polar2D(), Polar2Dm(), quadri_background(), and EMAN::EMData::rot_scale_trans2D().
00651 { 00652 // purpose: quadratic interpolation 00653 // Optimized for speed, circular closer removed, checking of ranges removed 00654 float x, y, dx0, dy0, f0, c1, c2, c3, c4, c5, dxb, dyb; 00655 float quadri; 00656 int i, j, ip1, im1, jp1, jm1, ic, jc, hxc, hyc; 00657 00658 x = xx; 00659 y = yy; 00660 00661 // any xx and yy 00662 while ( x < 1.0 ) x += nxdata; 00663 while ( x >= (float)(nxdata+1) ) x -= nxdata; 00664 while ( y < 1.0 ) y += nydata; 00665 while ( y >= (float)(nydata+1) ) y -= nydata; 00666 00667 i = (int) x; 00668 j = (int) y; 00669 00670 dx0 = x - i; 00671 dy0 = y - j; 00672 00673 ip1 = i + 1; 00674 im1 = i - 1; 00675 jp1 = j + 1; 00676 jm1 = j - 1; 00677 00678 if (ip1 > nxdata) ip1 -= nxdata; 00679 if (im1 < 1) im1 += nxdata; 00680 if (jp1 > nydata) jp1 -= nydata; 00681 if (jm1 < 1) jm1 += nydata; 00682 00683 f0 = fdata(i,j); 00684 c1 = fdata(ip1,j) - f0; 00685 c2 = (c1 - f0 + fdata(im1,j)) * 0.5f; 00686 c3 = fdata(i,jp1) - f0; 00687 c4 = (c3 - f0 + fdata(i,jm1)) * 0.5f; 00688 00689 dxb = dx0 - 1; 00690 dyb = dy0 - 1; 00691 00692 // hxc & hyc are either 1 or -1 00693 if (dx0 >= 0) hxc = 1; else hxc = -1; 00694 if (dy0 >= 0) hyc = 1; else hyc = -1; 00695 00696 ic = i + hxc; 00697 jc = j + hyc; 00698 00699 if (ic > nxdata) ic -= nxdata; else if (ic < 1) ic += nxdata; 00700 if (jc > nydata) jc -= nydata; else if (jc < 1) jc += nydata; 00701 00702 c5 = ( (fdata(ic,jc) - f0 - hxc * c1 - (hxc * (hxc - 1.0f)) * c2 00703 - hyc * c3 - (hyc * (hyc - 1.0f)) * c4) * (hxc * hyc)); 00704 00705 00706 quadri = f0 + dx0 * (c1 + dxb * c2 + dy0 * c5) + dy0 * (c3 + dyb * c4); 00707 00708 return quadri; 00709 }
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 714 of file util_sparx.cpp.
References fdata, quadri(), x, and y.
Referenced by EMAN::EMData::rot_scale_trans2D_background().
00715 { 00716 // purpose: quadratic interpolation 00717 // Optimized for speed, circular closer removed, checking of ranges removed 00718 float x, y, dx0, dy0, f0, c1, c2, c3, c4, c5, dxb, dyb; 00719 float quadri; 00720 int i, j, ip1, im1, jp1, jm1, ic, jc, hxc, hyc; 00721 00722 x = xx; 00723 y = yy; 00724 00725 // wrap around is not done circulantly; if (x,y) is not in the image, then x = xnew and y = ynew 00726 if ( (x < 1.0) || ( x >= (float)(nxdata+1) ) || ( y < 1.0 ) || ( y >= (float)(nydata+1) )){ 00727 x = (float)xnew; 00728 y = (float)ynew; 00729 } 00730 00731 00732 i = (int) x; 00733 j = (int) y; 00734 00735 dx0 = x - i; 00736 dy0 = y - j; 00737 00738 ip1 = i + 1; 00739 im1 = i - 1; 00740 jp1 = j + 1; 00741 jm1 = j - 1; 00742 00743 if (ip1 > nxdata) ip1 -= nxdata; 00744 if (im1 < 1) im1 += nxdata; 00745 if (jp1 > nydata) jp1 -= nydata; 00746 if (jm1 < 1) jm1 += nydata; 00747 00748 f0 = fdata(i,j); 00749 c1 = fdata(ip1,j) - f0; 00750 c2 = (c1 - f0 + fdata(im1,j)) * 0.5f; 00751 c3 = fdata(i,jp1) - f0; 00752 c4 = (c3 - f0 + fdata(i,jm1)) * 0.5f; 00753 00754 dxb = dx0 - 1; 00755 dyb = dy0 - 1; 00756 00757 // hxc & hyc are either 1 or -1 00758 if (dx0 >= 0) hxc = 1; else hxc = -1; 00759 if (dy0 >= 0) hyc = 1; else hyc = -1; 00760 00761 ic = i + hxc; 00762 jc = j + hyc; 00763 00764 if (ic > nxdata) ic -= nxdata; else if (ic < 1) ic += nxdata; 00765 if (jc > nydata) jc -= nydata; else if (jc < 1) jc += nydata; 00766 00767 c5 = ( (fdata(ic,jc) - f0 - hxc * c1 - (hxc * (hxc - 1.0f)) * c2 00768 - hyc * c3 - (hyc * (hyc - 1.0f)) * c4) * (hxc * hyc)); 00769 00770 00771 quadri = f0 + dx0 * (c1 + dxb * c2 + dy0 * c5) + dy0 * (c3 + dyb * c4); 00772 00773 return quadri; 00774 }
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 438 of file util_sparx.cpp.
References sort_mat().
00440 { 00441 int iMax = (int) floor( (Size-1.0)/2 +.01); 00442 int CountMax = (iMax+2)*(iMax+1)/2; 00443 int Count=-1; 00444 float *kVals = new float[CountMax]; 00445 float *weightMat = new float[CountMax]; 00446 int *PermMat = new int[CountMax]; 00447 SizeReturned[0] = CountMax; 00448 00449 // printf("Aa \n"); fflush(stdout); 00450 for (int jkx=0; jkx< iMax+1; jkx++) { 00451 for (int jky=0; jky< jkx+1; jky++) { 00452 Count++; 00453 kVals[Count] = sqrtf((float) (jkx*jkx +jky*jky)); 00454 weightMat[Count]= 1.0; 00455 if (jkx!=0) { weightMat[Count] *=2;} 00456 if (jky!=0) { weightMat[Count] *=2;} 00457 if (jkx!=jky){ weightMat[Count] *=2;} 00458 PermMat[Count]=Count+1; 00459 } 00460 } 00461 00462 int lkVals = Count+1; 00463 // printf("Cc \n");fflush(stdout); 00464 00465 sort_mat(&kVals[0],&kVals[Count], 00466 &PermMat[0], &PermMat[Count]); //PermMat is 00467 //also returned as well as kValsSorted 00468 fflush(stdout); 00469 00470 int newInd; 00471 00472 for (int iP=0; iP < lkVals ; iP++ ) { 00473 newInd = PermMat[iP]; 00474 PermMatTr[newInd-1] = iP+1; 00475 } 00476 00477 // printf("Ee \n"); fflush(stdout); 00478 00479 int CountA=-1; 00480 int CountB=-1; 00481 00482 while (CountB< (CountMax-1)) { 00483 CountA++; 00484 CountB++; 00485 // printf("CountA=%d ; CountB=%d \n", CountA,CountB);fflush(stdout); 00486 kValsSorted[CountA] = kVals[CountB] ; 00487 if (CountB<(CountMax-1) ) { 00488 while (fabs(kVals[CountB] -kVals[CountB+1])<.0000001 ) { 00489 SizeReturned[0]--; 00490 for (int iP=0; iP < lkVals; iP++){ 00491 // printf("iP=%d \n", iP);fflush(stdout); 00492 if (PermMatTr[iP]>CountA+1) { 00493 PermMatTr[iP]--; 00494 } 00495 } 00496 CountB++; 00497 } 00498 } 00499 } 00500 00501 00502 for (int CountD=0; CountD < CountMax; CountD++) { 00503 newInd = PermMatTr[CountD]; 00504 weightofkValsSorted[newInd-1] += weightMat[CountD]; 00505 } 00506 00507 }
Recreates a n-d image using its compressed 1-D form and the mask.
Definition at line 6245 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().
06246 { 06247 /******** 06248 ***Exception Handle 06249 *************/ 06250 if(mask == NULL) 06251 throw ImageDimensionException("The mask cannot be an null image"); 06252 06253 /*********** 06254 ***get the size of the mask 06255 **************/ 06256 int nx = mask->get_xsize(),ny = mask->get_ysize(),nz = mask->get_zsize(); 06257 06258 size_t i,size = (size_t)nx*ny*nz; /* loop counters */ 06259 /* new image declaration */ 06260 EMData *new_image = new EMData(); 06261 new_image->set_size(nx,ny,nz); /* set the size of new image */ 06262 float *new_ptr = new_image->get_data(); /* set size of the new image */ 06263 float *mask_ptr = mask->get_data(); /* assign a pointer to the mask image */ 06264 float *img_ptr = image->get_data(); /* assign a pointer to the 1D image */ 06265 int count = 0; 06266 float sum_under_mask = 0.0 ; 06267 for(i = 0;i < size;i++){ 06268 if(mask_ptr[i] > 0.5f){ 06269 new_ptr[i] = img_ptr[count]; 06270 sum_under_mask += img_ptr[count]; 06271 count++; 06272 if( count > image->get_xsize() ) { 06273 throw ImageDimensionException("Error: in reconstitute_image_mask, the mask doesn't match the image, it is too large"); 06274 } 06275 } 06276 } 06277 06278 if( count > image->get_xsize() ) { 06279 throw ImageDimensionException("Error: in reconstitute_image_mask, the mask doesn't match the image, it is too small"); 06280 } 06281 06282 float avg_under_mask = sum_under_mask / count; 06283 for(i = 0;i < size;i++) { 06284 if(mask_ptr[i] <= 0.5f) new_ptr[i] = avg_under_mask; 06285 } 06286 new_image->update(); 06287 return new_image; 06288 }
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 1088 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 1448 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 20765 of file util_sparx.cpp.
References k_means_cont_table_().
20765 { 20766 //cout<<"sanitycheck called\n"; 20767 int total_cost = *output; 20768 int num_matches = *(output+1); 20769 20770 int cost=0; 20771 int* intx; 20772 int intx_size; 20773 int* intx_next(0); 20774 int intx_next_size = 0; 20775 int curclass; 20776 int curclass_size; 20777 //cout<<"cost by match: ["; 20778 for(int i = 0; i < num_matches; i++){ 20779 curclass = *(output+2+ i*nParts); 20780 // check feasibility 20781 if (*(argParts + Indices[curclass]+1) == -5) {cout<<"infeasible match!\n"; return 0;} 20782 *(argParts + Indices[curclass]+1) = -5; 20783 // initialize intx to the number of elements in class curclass of partition 0 of the i-th match 20784 curclass_size = *(dimClasses+curclass)-2; 20785 intx = new int[curclass_size]; 20786 for (int ic = 0; ic < curclass_size; ic++) *(intx+ic) = *(argParts + Indices[curclass]+2+ic); 20787 intx_size = curclass_size; 20788 20789 for (int j=1; j < nParts; j++){ 20790 curclass = *(output+2+ i*nParts+j); 20791 if (*(argParts + Indices[j*K+curclass]+1)==-5){cout<<"infeasible match!\n"; return 0;} 20792 *(argParts + Indices[j*K+curclass]+1)=-5; 20793 // compute the intersection of intx and class curclass of partition j of the i-th match 20794 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); 20795 intx_next = new int[intx_next_size]; 20796 Util::k_means_cont_table_(intx,argParts + Indices[j*K+curclass]+2, intx_next, intx_size, *(dimClasses + j*K+curclass)-2,1); 20797 delete[] intx; 20798 intx=intx_next; 20799 intx_size= intx_next_size; 20800 } 20801 delete[] intx_next; 20802 20803 if (intx_next_size <= T) {cout << "something wrong with solution!\n"; return 0;} 20804 //cout <<intx_next_size<<","; 20805 cost = cost + intx_next_size; 20806 } 20807 //cout<<"]\n"; 20808 if (cost != total_cost) {cout << "something wrong with solution!\n"; return 0;} 20809 20810 return 1; 20811 20812 }
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 20819 of file util_sparx.cpp.
References explore2(), and k_means_cont_table_().
20819 { 20820 20821 // some temp variables 20822 bool flag = 0; 20823 int nintx; 20824 int* dummy(0); 20825 //int* ret; 20826 int* curbranch = new int[nParts]; 20827 20828 //initialize costlist to all 0 20829 for(int jit= 0; jit< J; jit++) *(costlist+jit) = 0; 20830 20831 20832 for(int a=0; a<K; a++) 20833 { 20834 20835 // 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 20836 if (*(argParts + Indices[a] + 1) < 1) continue; 20837 if (*(dimClasses + a)-2 <= T) continue; 20838 20839 // 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 20840 20841 for( int i=1; i < nParts; i++){ 20842 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. 20843 for(int j=0; j < K; j++){ 20844 if (*(argParts + Indices[i*K+j] + 1) < 1) continue; 20845 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); 20846 if (nintx > T) flag=1; 20847 else *(argParts + Indices[i*K+j] + 1) =-4; 20848 } 20849 if (flag==0) {break;} 20850 } 20851 20852 // explore determines J matchs with the largest weight greater than T where class in partition 0 is class a 20853 *curbranch = a; 20854 20855 if (flag > 0) // Each partition has one or more active class 20856 Util::explore2(argParts, Indices, dimClasses, nParts, K, T, argParts+Indices[a]+2, *(dimClasses+a)-2, argParts+Indices[a]+2, 20857 *(dimClasses+a)-2,0, J, matchlist, costlist, curbranch); 20858 20859 // take all the classes marked as -4 and remark it as 1 in preparation for next round 20860 for( int i=1; i < nParts; i++){ 20861 for(int j=0; j < K; j++){ 20862 if (*(argParts + Indices[i*K+j] + 1) == -4) *(argParts + Indices[i*K+j] + 1) =1; 20863 20864 } 20865 } 20866 } 20867 20868 delete[] curbranch; 20869 }
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 4787 of file util_sparx.cpp.
References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), img_ptr, nx, and EMAN::EMData::update().
04788 { 04789 int i; 04790 int nx=img->get_xsize(); 04791 float *img_ptr = img->get_data(); 04792 float *line_ptr = line->get_data(); 04793 for (i=0;i<length;i++) img_ptr[nx*posline + i] = line_ptr[offset + i]; 04794 img->update(); 04795 }
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 int | 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 2070 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 5531 of file util_sparx.cpp.
References colreverse().
Referenced by cyclicshift().
05532 { 05533 int nxy = nx*ny; 05534 colreverse(beg, end, nxy); 05535 }
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 377 of file util_sparx.cpp.
00378 { 00379 int i,k; 00380 float p, qn, sig, un, *u; 00381 u = new float[n-1]; 00382 00383 if (yp1 > .99e30){ 00384 y2[0]=u[0]=0.0; 00385 } else { 00386 y2[0]=-.5f; 00387 u[0] =(3.0f/ (x[1] -x[0]))*( (y[1]-y[0])/(x[1]-x[0]) -yp1); 00388 } 00389 00390 for (i=1; i < n-1; i++) { 00391 sig= (x[i] - x[i-1])/(x[i+1] - x[i-1]); 00392 p = sig*y2[i-1] + 2.0f; 00393 y2[i] = (sig-1.0f)/p; 00394 u[i] = (y[i+1] - y[i] )/(x[i+1]-x[i] ) - (y[i] - y[i-1] )/(x[i] -x[i-1]); 00395 u[i] = (6.0f*u[i]/ (x[i+1]-x[i-1]) - sig*u[i-1])/p; 00396 } 00397 00398 if (ypn>.99e30){ 00399 qn=0; un=0; 00400 } else { 00401 qn= .5f; 00402 un= (3.0f/(x[n-1] -x[n-2])) * (ypn - (y[n-1]-y[n-2])/(x[n-1]-x[n-2])); 00403 } 00404 y2[n-1]= (un - qn*u[n-2])/(qn*y2[n-2]+1.0f); 00405 for (k=n-2; k>=0; k--){ 00406 y2[k]=y2[k]*y2[k+1]+u[k]; 00407 } 00408 delete [] u; 00409 }
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 352 of file util_sparx.cpp.
References spline(), and splint().
00353 { 00354 00355 float x0= x[0]; 00356 float x1= x[1]; 00357 float x2= x[2]; 00358 float y0= y[0]; 00359 float y1= y[1]; 00360 float y2= y[2]; 00361 float yp1 = (y1-y0)/(x1-x0) + (y2-y0)/(x2-x0) - (y2-y1)/(x2-x1) ; 00362 float xn = x[n]; 00363 float xnm1= x[n-1]; 00364 float xnm2= x[n-2]; 00365 float yn = y[n]; 00366 float ynm1= y[n-1]; 00367 float ynm2= y[n-2]; 00368 float ypn= (yn-ynm1)/(xn-xnm1) + (yn-ynm2)/(xn-xnm2) - (ynm1-ynm2)/(xnm1-xnm2) ; 00369 float *y2d = new float[n]; 00370 Util::spline(x,y,n,yp1,ypn,y2d); 00371 Util::splint(x,y,y2d,n,xq,yq,m); //PRB 00372 delete [] y2d; 00373 return; 00374 }
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 412 of file util_sparx.cpp.
References b.
00413 { 00414 int klo, khi, k; 00415 float h, b, a; 00416 00417 // klo=0; // can try to put here 00418 for (int j=0; j<m;j++){ 00419 klo=0; 00420 khi=n-1; 00421 while (khi-klo >1) { 00422 k=(khi+klo) >>1; 00423 if (xa[k]>xq[j]){ khi=k;} 00424 else { klo=k;} 00425 } 00426 h=xa[khi]- xa[klo]; 00427 if (h==0.0) printf("Bad XA input to routine SPLINT \n"); 00428 a =(xa[khi]-xq[j])/h; 00429 b=(xq[j]-xa[klo])/h; 00430 yq[j]=a*ya[klo] + b*ya[khi] 00431 + ((a*a*a-a)*y2a[klo] 00432 +(b*b*b-b)*y2a[khi]) *(h*h)/6.0f; 00433 } 00434 // 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]); 00435 }
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 1570 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 1598 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 4630 of file util_sparx.cpp.
References EXITFUNC, EMAN::EMData::get_data(), numr, PI2, and EMAN::EMData::update().
04630 { 04631 int nring = numr.size()/3; 04632 float *ave = avep->get_data(); 04633 float *dat = datp->get_data(); 04634 int i, j, numr3i, np; 04635 float arg, cs, si; 04636 int maxrin = numr(3,nring); 04637 if(mirror == 1) { //for mirrored data has to be conjugated 04638 for (i=1; i<=nring; i++) { 04639 numr3i = numr(3,i); 04640 np = numr(2,i)-1; 04641 ave[np] -= dat[np]; 04642 ave[np+1] -= static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) ); 04643 for (j=2; j<numr3i; j=j+2) { 04644 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin ); 04645 cs = cos(arg); 04646 si = sin(arg); 04647 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg)) 04648 ave[np + j] -= dat[np + j]*cs - dat[np + j +1]*si; 04649 ave[np + j +1] += dat[np + j]*si + dat[np + j +1]*cs; 04650 } 04651 } 04652 } else { 04653 for (i=1; i<=nring; i++) { 04654 numr3i = numr(3,i); 04655 np = numr(2,i)-1; 04656 ave[np] -= dat[np]; 04657 ave[np+1] -= static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) ); 04658 for (j=2; j<numr3i; j=j+2) { 04659 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin ); 04660 cs = cos(arg); 04661 si = sin(arg); 04662 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg)) 04663 ave[np + j] -= dat[np + j]*cs - dat[np + j +1]*si; 04664 ave[np + j +1] -= dat[np + j]*si + dat[np + j +1]*cs; 04665 } 04666 } 04667 } 04668 avep->update(); 04669 EXITFUNC; 04670 }
Definition at line 17704 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().
17705 { 17706 ENTERFUNC; 17707 /* Exception Handle */ 17708 if (!img) { 17709 throw NullPointerException("NULL input image"); 17710 } 17711 /* ========= img -= img1 ===================== */ 17712 17713 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17714 size_t size = (size_t)nx*ny*nz; 17715 float *img_ptr = img->get_data(); 17716 float *img1_ptr = img1->get_data(); 17717 for (size_t i=0;i<size;++i) img_ptr[i] -= img1_ptr[i]; 17718 img->update(); 17719 17720 EXITFUNC; 17721 }
Definition at line 17486 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().
17487 { 17488 ENTERFUNC; 17489 /* Exception Handle */ 17490 if (!img) { 17491 throw NullPointerException("NULL input image"); 17492 } 17493 /* ============== output = img - img1 ================ */ 17494 17495 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17496 size_t size = (size_t)nx*ny*nz; 17497 EMData * img2 = img->copy_head(); 17498 float *img_ptr =img->get_data(); 17499 float *img2_ptr = img2->get_data(); 17500 float *img1_ptr = img1->get_data(); 17501 for (size_t i=0;i<size;++i) img2_ptr[i] = img_ptr[i] - img1_ptr[i]; 17502 img2->update(); 17503 if(img->is_complex()) { 17504 img2->set_complex(true); 17505 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17506 } 17507 17508 EXITFUNC; 17509 return img2; 17510 }
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 6193 of file util_sparx.cpp.
References phase(), and sqrt().
Referenced by ctf_img(), and EMAN::Processor::EMFourierFilterFunc().
06194 { 06195 float cst = cs*1.0e7f; 06196 06197 wgh /= 100.0; 06198 float phase = atan(wgh/sqrt(1.0f-wgh*wgh)); 06199 float lambda=12.398f/sqrt(voltage*(1022.0f+voltage)); 06200 float ak2 = ak*ak; 06201 float g1 = dzz*1.0e4f*lambda*ak2; 06202 float g2 = cst*lambda*lambda*lambda*ak2*ak2/2.0f; 06203 06204 float ctfv = static_cast<float>( sin(M_PI*(g1-g2)+phase)*sign ); 06205 if(b_factor != 0.0f) ctfv *= exp(-b_factor*ak2/4.0f); 06206 06207 return ctfv; 06208 }
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 1509 of file util.h.
Referenced by EMAN::EMData::cut_slice(), EMAN::EMData::extract_box(), EMAN::SymSearchProcessor::process_inplace(), 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 1908 of file util_sparx.cpp.
01909 { 01910 01911 const float C2 = 0.5f; //1.0 / 2.0; 01912 const float C4 = 0.25f; //1.0 / 4.0; 01913 const float C8 = 0.125f; //1.0 / 8.0; 01914 01915 float RS = R * S; 01916 float ST = S * T; 01917 float RT = R * T; 01918 float RST = R * ST; 01919 01920 float RSQ = 1-R*R; 01921 float SSQ = 1-S*S; 01922 float TSQ = 1-T*T; 01923 01924 float RM1 = (1-R); 01925 float SM1 = (1-S); 01926 float TM1 = (1-T); 01927 01928 float RP1 = (1+R); 01929 float SP1 = (1+S); 01930 float TP1 = (1+T); 01931 01932 float triquad = 01933 (-C8) * RST * RM1 * SM1 * TM1 * fdata[0] + 01934 ( C4) * ST * RSQ * SM1 * TM1 * fdata[1] + 01935 ( C8) * RST * RP1 * SM1 * TM1 * fdata[2] + 01936 ( C4) * RT * RM1 * SSQ * TM1 * fdata[3] + 01937 (-C2) * T * RSQ * SSQ * TM1 * fdata[4] + 01938 (-C4) * RT * RP1 * SSQ * TM1 * fdata[5] + 01939 ( C8) * RST * RM1 * SP1 * TM1 * fdata[6] + 01940 (-C4) * ST * RSQ * SP1 * TM1 * fdata[7] + 01941 (-C8) * RST * RP1 * SP1 * TM1 * fdata[8] + 01942 // 01943 ( C4) * RS * RM1 * SM1 * TSQ * fdata[9] + 01944 (-C2) * S * RSQ * SM1 * TSQ * fdata[10] + 01945 (-C4) * RS * RP1 * SM1 * TSQ * fdata[11] + 01946 (-C2) * R * RM1 * SSQ * TSQ * fdata[12] + 01947 RSQ * SSQ * TSQ * fdata[13] + 01948 ( C2) * R * RP1 * SSQ * TSQ * fdata[14] + 01949 (-C4) * RS * RM1 * SP1 * TSQ * fdata[15] + 01950 ( C2) * S * RSQ * SP1 * TSQ * fdata[16] + 01951 ( C4) * RS * RP1 * SP1 * TSQ * fdata[17] + 01952 // 01953 ( C8) * RST * RM1 * SM1 * TP1 * fdata[18] + 01954 (-C4) * ST * RSQ * SM1 * TP1 * fdata[19] + 01955 (-C8) * RST * RP1 * SM1 * TP1 * fdata[20] + 01956 (-C4) * RT * RM1 * SSQ * TP1 * fdata[21] + 01957 ( C2) * T * RSQ * SSQ * TP1 * fdata[22] + 01958 ( C4) * RT * RP1 * SSQ * TP1 * fdata[23] + 01959 (-C8) * RST * RM1 * SP1 * TP1 * fdata[24] + 01960 ( C4) * ST * RSQ * SP1 * TP1 * fdata[25] + 01961 ( C8) * RST * RP1 * SP1 * TP1 * fdata[26] ; 01962 return triquad; 01963 }
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 7945 of file util_sparx.cpp.
References abs, addnod_(), and left_().
07949 { 07950 /* System generated locals */ 07951 int i__1, i__2; 07952 07953 /* Local variables */ 07954 static double d__; 07955 static int i__, j; 07956 static double d1, d2, d3; 07957 static int i0, lp, kt, ku, lpl, nku; 07958 static int nexti; 07959 07960 07961 /* *********************************************************** */ 07962 07963 /* From STRIPACK */ 07964 /* Robert J. Renka */ 07965 /* Dept. of Computer Science */ 07966 /* Univ. of North Texas */ 07967 /* renka@cs.unt.edu */ 07968 /* 01/20/03 */ 07969 07970 /* This is an alternative to TRMESH with the inclusion of */ 07971 /* an efficient means of removing duplicate or nearly dupli- */ 07972 /* cate nodes. */ 07973 07974 /* This subroutine creates a Delaunay triangulation of a */ 07975 /* set of N arbitrarily distributed points, referred to as */ 07976 /* nodes, on the surface of the unit sphere. Refer to Sub- */ 07977 /* routine TRMESH for definitions and a list of additional */ 07978 /* subroutines. This routine is an alternative to TRMESH */ 07979 /* with the inclusion of an efficient means of removing dup- */ 07980 /* licate or nearly duplicate nodes. */ 07981 07982 /* The algorithm has expected time complexity O(N*log(N)) */ 07983 /* for random nodal distributions. */ 07984 07985 07986 /* On input: */ 07987 07988 /* N0 = Number of nodes, possibly including duplicates. */ 07989 /* N0 .GE. 3. */ 07990 07991 /* TOL = Tolerance defining a pair of duplicate nodes: */ 07992 /* bound on the deviation from 1 of the cosine of */ 07993 /* the angle between the nodes. Note that */ 07994 /* |1-cos(A)| is approximately A*A/2. */ 07995 07996 /* The above parameters are not altered by this routine. */ 07997 07998 /* X,Y,Z = Arrays of length at least N0 containing the */ 07999 /* Cartesian coordinates of nodes. (X(K),Y(K), */ 08000 /* Z(K)) is referred to as node K, and K is re- */ 08001 /* ferred to as a nodal index. It is required */ 08002 /* that X(K)**2 + Y(K)**2 + Z(K)**2 = 1 for all */ 08003 /* K. The first three nodes must not be col- */ 08004 /* linear (lie on a common great circle). */ 08005 08006 /* LIST,LPTR = Arrays of length at least 6*N0-12. */ 08007 08008 /* LEND = Array of length at least N0. */ 08009 08010 /* INDX = Array of length at least N0. */ 08011 08012 /* LCNT = Array of length at least N0 (length N is */ 08013 /* sufficient). */ 08014 08015 /* NEAR,NEXT,DIST = Work space arrays of length at */ 08016 /* least N0. The space is used to */ 08017 /* efficiently determine the nearest */ 08018 /* triangulation node to each un- */ 08019 /* processed node for use by ADDNOD. */ 08020 08021 /* On output: */ 08022 08023 /* N = Number of nodes in the triangulation. 3 .LE. N */ 08024 /* .LE. N0, or N = 0 if IER < 0. */ 08025 08026 /* X,Y,Z = Arrays containing the Cartesian coordinates */ 08027 /* of the triangulation nodes in the first N */ 08028 /* locations. The original array elements are */ 08029 /* shifted down as necessary to eliminate dup- */ 08030 /* licate nodes. */ 08031 08032 /* LIST = Set of nodal indexes which, along with LPTR, */ 08033 /* LEND, and LNEW, define the triangulation as a */ 08034 /* set of N adjacency lists -- counterclockwise- */ 08035 /* ordered sequences of neighboring nodes such */ 08036 /* that the first and last neighbors of a bound- */ 08037 /* ary node are boundary nodes (the first neigh- */ 08038 /* bor of an interior node is arbitrary). In */ 08039 /* order to distinguish between interior and */ 08040 /* boundary nodes, the last neighbor of each */ 08041 /* boundary node is represented by the negative */ 08042 /* of its index. */ 08043 08044 /* LPTR = Set of pointers (LIST indexes) in one-to-one */ 08045 /* correspondence with the elements of LIST. */ 08046 /* LIST(LPTR(I)) indexes the node which follows */ 08047 /* LIST(I) in cyclical counterclockwise order */ 08048 /* (the first neighbor follows the last neigh- */ 08049 /* bor). */ 08050 08051 /* LEND = Set of pointers to adjacency lists. LEND(K) */ 08052 /* points to the last neighbor of node K for */ 08053 /* K = 1,...,N. Thus, LIST(LEND(K)) < 0 if and */ 08054 /* only if K is a boundary node. */ 08055 08056 /* LNEW = Pointer to the first empty location in LIST */ 08057 /* and LPTR (list length plus one). LIST, LPTR, */ 08058 /* LEND, and LNEW are not altered if IER < 0, */ 08059 /* and are incomplete if IER > 0. */ 08060 08061 /* INDX = Array of output (triangulation) nodal indexes */ 08062 /* associated with input nodes. For I = 1 to */ 08063 /* N0, INDX(I) is the index (for X, Y, and Z) of */ 08064 /* the triangulation node with the same (or */ 08065 /* nearly the same) coordinates as input node I. */ 08066 08067 /* LCNT = Array of int weights (counts) associated */ 08068 /* with the triangulation nodes. For I = 1 to */ 08069 /* N, LCNT(I) is the number of occurrences of */ 08070 /* node I in the input node set, and thus the */ 08071 /* number of duplicates is LCNT(I)-1. */ 08072 08073 /* NEAR,NEXT,DIST = Garbage. */ 08074 08075 /* IER = Error indicator: */ 08076 /* IER = 0 if no errors were encountered. */ 08077 /* IER = -1 if N0 < 3 on input. */ 08078 /* IER = -2 if the first three nodes are */ 08079 /* collinear. */ 08080 /* IER = -3 if Subroutine ADDNOD returns an error */ 08081 /* flag. This should not occur. */ 08082 08083 /* Modules required by TRMSH3: ADDNOD, BDYADD, COVSPH, */ 08084 /* INSERT, INTADD, JRAND, */ 08085 /* LEFT, LSTPTR, STORE, SWAP, */ 08086 /* SWPTST, TRFIND */ 08087 08088 /* Intrinsic function called by TRMSH3: ABS */ 08089 08090 /* *********************************************************** */ 08091 08092 08093 /* Local parameters: */ 08094 08095 /* D = (Negative cosine of) distance from node KT to */ 08096 /* node I */ 08097 /* D1,D2,D3 = Distances from node KU to nodes 1, 2, and 3, */ 08098 /* respectively */ 08099 /* I,J = Nodal indexes */ 08100 /* I0 = Index of the node preceding I in a sequence of */ 08101 /* unprocessed nodes: I = NEXT(I0) */ 08102 /* KT = Index of a triangulation node */ 08103 /* KU = Index of an unprocessed node and DO-loop index */ 08104 /* LP = LIST index (pointer) of a neighbor of KT */ 08105 /* LPL = Pointer to the last neighbor of KT */ 08106 /* NEXTI = NEXT(I) */ 08107 /* NKU = NEAR(KU) */ 08108 08109 /* Parameter adjustments */ 08110 --dist; 08111 --next; 08112 --near__; 08113 --indx; 08114 --lend; 08115 --z__; 08116 --y; 08117 --x; 08118 --list; 08119 --lptr; 08120 --lcnt; 08121 08122 /* Function Body */ 08123 if (*n0 < 3) { 08124 *n = 0; 08125 *ier = -1; 08126 return 0; 08127 } 08128 08129 /* Store the first triangle in the linked list. */ 08130 08131 if (! left_(&x[1], &y[1], &z__[1], &x[2], &y[2], &z__[2], &x[3], &y[3], & 08132 z__[3])) { 08133 08134 /* The first triangle is (3,2,1) = (2,1,3) = (1,3,2). */ 08135 08136 list[1] = 3; 08137 lptr[1] = 2; 08138 list[2] = -2; 08139 lptr[2] = 1; 08140 lend[1] = 2; 08141 08142 list[3] = 1; 08143 lptr[3] = 4; 08144 list[4] = -3; 08145 lptr[4] = 3; 08146 lend[2] = 4; 08147 08148 list[5] = 2; 08149 lptr[5] = 6; 08150 list[6] = -1; 08151 lptr[6] = 5; 08152 lend[3] = 6; 08153 08154 } else if (! left_(&x[2], &y[2], &z__[2], &x[1], &y[1], &z__[1], &x[3], & 08155 y[3], &z__[3])) { 08156 08157 /* The first triangle is (1,2,3): 3 Strictly Left 1->2, */ 08158 /* i.e., node 3 lies in the left hemisphere defined by */ 08159 /* arc 1->2. */ 08160 08161 list[1] = 2; 08162 lptr[1] = 2; 08163 list[2] = -3; 08164 lptr[2] = 1; 08165 lend[1] = 2; 08166 08167 list[3] = 3; 08168 lptr[3] = 4; 08169 list[4] = -1; 08170 lptr[4] = 3; 08171 lend[2] = 4; 08172 08173 list[5] = 1; 08174 lptr[5] = 6; 08175 list[6] = -2; 08176 lptr[6] = 5; 08177 lend[3] = 6; 08178 08179 08180 } else { 08181 08182 /* The first three nodes are collinear. */ 08183 08184 *n = 0; 08185 *ier = -2; 08186 return 0; 08187 } 08188 08189 //printf("pass check colinear\n"); 08190 08191 /* Initialize LNEW, INDX, and LCNT, and test for N = 3. */ 08192 08193 *lnew = 7; 08194 indx[1] = 1; 08195 indx[2] = 2; 08196 indx[3] = 3; 08197 lcnt[1] = 1; 08198 lcnt[2] = 1; 08199 lcnt[3] = 1; 08200 if (*n0 == 3) { 08201 *n = 3; 08202 *ier = 0; 08203 return 0; 08204 } 08205 08206 /* A nearest-node data structure (NEAR, NEXT, and DIST) is */ 08207 /* used to obtain an expected-time (N*log(N)) incremental */ 08208 /* algorithm by enabling constant search time for locating */ 08209 /* each new node in the triangulation. */ 08210 08211 /* For each unprocessed node KU, NEAR(KU) is the index of the */ 08212 /* triangulation node closest to KU (used as the starting */ 08213 /* point for the search in Subroutine TRFIND) and DIST(KU) */ 08214 /* is an increasing function of the arc length (angular */ 08215 /* distance) between nodes KU and NEAR(KU): -Cos(a) for */ 08216 /* arc length a. */ 08217 08218 /* Since it is necessary to efficiently find the subset of */ 08219 /* unprocessed nodes associated with each triangulation */ 08220 /* node J (those that have J as their NEAR entries), the */ 08221 /* subsets are stored in NEAR and NEXT as follows: for */ 08222 /* each node J in the triangulation, I = NEAR(J) is the */ 08223 /* first unprocessed node in J's set (with I = 0 if the */ 08224 /* set is empty), L = NEXT(I) (if I > 0) is the second, */ 08225 /* NEXT(L) (if L > 0) is the third, etc. The nodes in each */ 08226 /* set are initially ordered by increasing indexes (which */ 08227 /* maximizes efficiency) but that ordering is not main- */ 08228 /* tained as the data structure is updated. */ 08229 08230 /* Initialize the data structure for the single triangle. */ 08231 08232 near__[1] = 0; 08233 near__[2] = 0; 08234 near__[3] = 0; 08235 for (ku = *n0; ku >= 4; --ku) { 08236 d1 = -(x[ku] * x[1] + y[ku] * y[1] + z__[ku] * z__[1]); 08237 d2 = -(x[ku] * x[2] + y[ku] * y[2] + z__[ku] * z__[2]); 08238 d3 = -(x[ku] * x[3] + y[ku] * y[3] + z__[ku] * z__[3]); 08239 if (d1 <= d2 && d1 <= d3) { 08240 near__[ku] = 1; 08241 dist[ku] = d1; 08242 next[ku] = near__[1]; 08243 near__[1] = ku; 08244 } else if (d2 <= d1 && d2 <= d3) { 08245 near__[ku] = 2; 08246 dist[ku] = d2; 08247 next[ku] = near__[2]; 08248 near__[2] = ku; 08249 } else { 08250 near__[ku] = 3; 08251 dist[ku] = d3; 08252 next[ku] = near__[3]; 08253 near__[3] = ku; 08254 } 08255 /* L1: */ 08256 } 08257 08258 /* Loop on unprocessed nodes KU. KT is the number of nodes */ 08259 /* in the triangulation, and NKU = NEAR(KU). */ 08260 08261 kt = 3; 08262 i__1 = *n0; 08263 for (ku = 4; ku <= i__1; ++ku) { 08264 nku = near__[ku]; 08265 08266 /* Remove KU from the set of unprocessed nodes associated */ 08267 /* with NEAR(KU). */ 08268 i__ = nku; 08269 if (near__[i__] == ku) { 08270 near__[i__] = next[ku]; 08271 } else { 08272 i__ = near__[i__]; 08273 L2: 08274 i0 = i__; 08275 i__ = next[i0]; 08276 if (i__ != ku) { 08277 goto L2; 08278 } 08279 next[i0] = next[ku]; 08280 } 08281 near__[ku] = 0; 08282 08283 /* Bypass duplicate nodes. */ 08284 08285 if (dist[ku] <= *tol - 1.) { 08286 indx[ku] = -nku; 08287 ++lcnt[nku]; 08288 goto L6; 08289 } 08290 08291 08292 /* Add a new triangulation node KT with LCNT(KT) = 1. */ 08293 ++kt; 08294 x[kt] = x[ku]; 08295 y[kt] = y[ku]; 08296 z__[kt] = z__[ku]; 08297 indx[ku] = kt; 08298 lcnt[kt] = 1; 08299 addnod_(&nku, &kt, &x[1], &y[1], &z__[1], &list[1], &lptr[1], &lend[1] 08300 , lnew, ier); 08301 if (*ier != 0) { 08302 *n = 0; 08303 *ier = -3; 08304 return 0; 08305 } 08306 08307 /* Loop on neighbors J of node KT. */ 08308 08309 lpl = lend[kt]; 08310 lp = lpl; 08311 L3: 08312 lp = lptr[lp]; 08313 j = (i__2 = list[lp], abs(i__2)); 08314 08315 /* Loop on elements I in the sequence of unprocessed nodes */ 08316 /* associated with J: KT is a candidate for replacing J */ 08317 /* as the nearest triangulation node to I. The next value */ 08318 /* of I in the sequence, NEXT(I), must be saved before I */ 08319 /* is moved because it is altered by adding I to KT's set. */ 08320 08321 i__ = near__[j]; 08322 L4: 08323 if (i__ == 0) { 08324 goto L5; 08325 } 08326 nexti = next[i__]; 08327 08328 /* Test for the distance from I to KT less than the distance */ 08329 /* from I to J. */ 08330 08331 d__ = -(x[i__] * x[kt] + y[i__] * y[kt] + z__[i__] * z__[kt]); 08332 if (d__ < dist[i__]) { 08333 08334 /* Replace J by KT as the nearest triangulation node to I: */ 08335 /* update NEAR(I) and DIST(I), and remove I from J's set */ 08336 /* of unprocessed nodes and add it to KT's set. */ 08337 08338 near__[i__] = kt; 08339 dist[i__] = d__; 08340 if (i__ == near__[j]) { 08341 near__[j] = nexti; 08342 } else { 08343 next[i0] = nexti; 08344 } 08345 next[i__] = near__[kt]; 08346 near__[kt] = i__; 08347 } else { 08348 i0 = i__; 08349 } 08350 08351 /* Bottom of loop on I. */ 08352 08353 i__ = nexti; 08354 goto L4; 08355 08356 /* Bottom of loop on neighbors J. */ 08357 08358 L5: 08359 if (lp != lpl) { 08360 goto L3; 08361 } 08362 L6: 08363 ; 08364 } 08365 *n = kt; 08366 *ier = 0; 08367 return 0; 08368 } /* trmsh3_ */
vector< float > Util::twoD_fine_ali | ( | EMData * | image, | |
EMData * | refim, | |||
EMData * | mask, | |||
float | ang, | |||
float | sxs, | |||
float | sys | |||
) | [static] |
Definition at line 19239 of file util_sparx.cpp.
References EMAN::EMData::cmp(), dt, EMAN::EMData::rot_scale_trans2D(), setulb_(), and SIXTY.
19239 { 19240 19241 EMData *rot; 19242 19243 const int nmax=3, mmax=3; 19244 char task[60], csave[60]; 19245 long int lsave[4]; 19246 long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44]; 19247 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]; 19248 long int SIXTY=60; 19249 19250 // We wish to have no output. 19251 iprint = -1; 19252 19253 //c We specify the tolerances in the stopping criteria. 19254 factr=1.0e1; 19255 pgtol=1.0e-5; 19256 19257 // We specify the dimension n of the sample problem and the number 19258 // m of limited memory corrections stored. (n and m should not 19259 // exceed the limits nmax and mmax respectively.) 19260 n=3; 19261 m=3; 19262 19263 // We now provide nbd which defines the bounds on the variables: 19264 // l specifies the lower bounds, 19265 // u specifies the upper bounds. 19266 // x specifies the initial guess 19267 x[0] = ang; nbd[0] = 2; l[0] = ang-2.0; u[0] = ang+2.0; 19268 x[1] = sxs; nbd[1] = 2; l[1] = sxs-1.5; u[1] = sxs+1.5; 19269 x[2] = sys; nbd[2] = 2; l[2] = sys-1.5; u[2] = sys+1.5; 19270 19271 19272 // We start the iteration by initializing task. 19273 // (**MUST clear remaining chars in task with spaces (else crash)!**) 19274 strcpy(task,"START"); 19275 for (int i=5;i<60;i++) task[i]=' '; 19276 19277 // This is the call to the L-BFGS-B code. 19278 // (* call the L-BFGS-B routine with task='START' once before loop *) 19279 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19280 //int step = 1; 19281 19282 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *) 19283 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) { 19284 19285 if (strncmp(task,"FG",2)==0) { 19286 // the minimization routine has returned to request the 19287 // function f and gradient g values at the current x 19288 19289 // Compute function value f for the sample problem. 19290 rot = new EMData(); 19291 rot = image->rot_scale_trans2D((float)x[0], (float)x[1], (float)x[2], 1.0f); 19292 f = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19293 //f = -f; 19294 delete rot; 19295 19296 // Compute gradient g for the sample problem. 19297 float dt = 1.0e-3f; 19298 rot = new EMData(); 19299 rot = image->rot_scale_trans2D((float)x[0]+dt, (float)x[1], (float)x[2], 1.0f); 19300 f1 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19301 //f1 = -f1; 19302 g[0] = (f1-f)/dt; 19303 delete rot; 19304 19305 dt = 1.0e-2f; 19306 rot = new EMData(); 19307 rot = image->rot_scale_trans2D((float)x[0], (float)x[1]+dt, (float)x[2], 1.0f); 19308 f2 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19309 //f2 = -f2; 19310 g[1] = (f2-f)/dt; 19311 delete rot; 19312 19313 rot = new EMData(); 19314 rot = image->rot_scale_trans2D((float)x[0], (float)x[1], (float)x[2]+dt, 1.0f); 19315 f3 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19316 //f3 = -f3; 19317 g[2] = (f3-f)/dt; 19318 delete rot; 19319 } 19320 19321 //c go back to the minimization routine. 19322 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19323 //step++; 19324 } 19325 19326 //printf("Total step is %d\n", step); 19327 vector<float> res; 19328 res.push_back(static_cast<float>(x[0])); 19329 res.push_back(static_cast<float>(x[1])); 19330 res.push_back(static_cast<float>(x[2])); 19331 //res.push_back(step); 19332 return res; 19333 }
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 19335 of file util_sparx.cpp.
References EMAN::EMData::cmp(), dt, pi, EMAN::EMData::rot_scale_conv7(), setulb_(), and SIXTY.
19335 { 19336 19337 EMData *rot; 19338 19339 const int nmax=3, mmax=3; 19340 char task[60], csave[60]; 19341 long int lsave[4]; 19342 long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44]; 19343 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]; 19344 long int SIXTY=60; 19345 19346 // We wish to have no output. 19347 iprint = -1; 19348 19349 //c We specify the tolerances in the stopping criteria. 19350 factr=1.0e1; 19351 pgtol=1.0e-5; 19352 19353 // We specify the dimension n of the sample problem and the number 19354 // m of limited memory corrections stored. (n and m should not 19355 // exceed the limits nmax and mmax respectively.) 19356 n=3; 19357 m=3; 19358 19359 // We now provide nbd which defines the bounds on the variables: 19360 // l specifies the lower bounds, 19361 // u specifies the upper bounds. 19362 // x specifies the initial guess 19363 x[0] = ang; nbd[0] = 2; l[0] = ang-2.0; u[0] = ang+2.0; 19364 x[1] = sxs; nbd[1] = 2; l[1] = sxs-1.5; u[1] = sxs+1.5; 19365 x[2] = sys; nbd[2] = 2; l[2] = sys-1.5; u[2] = sys+1.5; 19366 19367 19368 // We start the iteration by initializing task. 19369 // (**MUST clear remaining chars in task with spaces (else crash)!**) 19370 strcpy(task,"START"); 19371 for (int i=5;i<60;i++) task[i]=' '; 19372 19373 // This is the call to the L-BFGS-B code. 19374 // (* call the L-BFGS-B routine with task='START' once before loop *) 19375 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19376 //int step = 1; 19377 19378 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *) 19379 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) { 19380 19381 if (strncmp(task,"FG",2)==0) { 19382 // the minimization routine has returned to request the 19383 // function f and gradient g values at the current x 19384 19385 // Compute function value f for the sample problem. 19386 rot = new EMData(); 19387 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1], (float)x[2], kb, 1.0f); 19388 f = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19389 //f = -f; 19390 delete rot; 19391 19392 // Compute gradient g for the sample problem. 19393 float dt = 1.0e-3f; 19394 rot = new EMData(); 19395 rot = image->rot_scale_conv7((float)((x[0]+dt)*pi/180), (float)x[1], (float)x[2], kb, 1.0f); 19396 f1 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19397 //f1 = -f1; 19398 g[0] = (f1-f)/dt; 19399 delete rot; 19400 19401 rot = new EMData(); 19402 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1]+dt, (float)x[2], kb, 1.0); 19403 f2 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19404 //f2 = -f2; 19405 g[1] = (f2-f)/dt; 19406 delete rot; 19407 19408 rot = new EMData(); 19409 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1], (float)x[2]+dt, kb, 1.0f); 19410 f3 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19411 //f3 = -f3; 19412 g[2] = (f3-f)/dt; 19413 delete rot; 19414 } 19415 19416 //c go back to the minimization routine. 19417 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19418 //step++; 19419 } 19420 19421 //printf("Total step is %d\n", step); 19422 vector<float> res; 19423 res.push_back(static_cast<float>(x[0])); 19424 res.push_back(static_cast<float>(x[1])); 19425 res.push_back(static_cast<float>(x[2])); 19426 //res.push_back(step); 19427 return res; 19428 }
vector< float > Util::twoD_fine_ali_SD | ( | EMData * | image, | |
EMData * | refim, | |||
EMData * | mask, | |||
float | ang, | |||
float | sxs, | |||
float | sys | |||
) | [static] |
Definition at line 19587 of file util_sparx.cpp.
References ccc_images(), and Steepda().
19587 { 19588 19589 double x[4]; 19590 int n; 19591 int l = 3; 19592 int m = 200; 19593 double e = 1e-9; 19594 double step = 0.01; 19595 float (*my_func)(EMData* , EMData* , EMData* , float , float , float) = ccc_images; 19596 19597 x[1] = ang; 19598 x[2] = sxs; 19599 x[3] = sys; 19600 19601 Steepda(x, step, e, l, m, &n, my_func, image, refim, mask); // Call steepest descent optimization subroutine 19602 //printf("Took %d steps\n", n); 19603 19604 vector<float> res; 19605 res.push_back(static_cast<float>(x[1])); 19606 res.push_back(static_cast<float>(x[2])); 19607 res.push_back(static_cast<float>(x[3])); 19608 res.push_back(static_cast<float>(n)); 19609 return res; 19610 }
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 19838 of file util_sparx.cpp.
References ccc_images_G(), and Steepda_G().
19838 { 19839 19840 double x[4]; 19841 int n; 19842 int l = 3; 19843 int m = 200; 19844 double e = 1e-9; 19845 double step = 0.001; 19846 float (*my_func)(EMData* , EMData* , EMData* , Util::KaiserBessel&, float , float , float) = ccc_images_G; 19847 19848 x[1] = ang; 19849 x[2] = sxs; 19850 x[3] = sys; 19851 19852 Steepda_G(x, step, e, l, m, &n, my_func, image, refim, mask, kb); // Call steepest descent optimization subroutine 19853 //printf("Took %d steps\n", n); 19854 19855 vector<float> res; 19856 res.push_back(static_cast<float>(x[1])); 19857 res.push_back(static_cast<float>(x[2])); 19858 res.push_back(static_cast<float>(x[3])); 19859 res.push_back(static_cast<float>(n)); 19860 return res; 19861 }
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 19430 of file util_sparx.cpp.
References EMAN::EMData::cmp(), dt, EMAN::EMData::extract_plane(), proj, setulb_(), and SIXTY.
19430 { 19431 19432 EMData *proj, *proj2; 19433 19434 const int nmax=5, mmax=5; 19435 char task[60], csave[60]; 19436 long int lsave[4]; 19437 long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44]; 19438 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]; 19439 long int SIXTY=60; 19440 19441 // We wish to have no output. 19442 iprint = -1; 19443 19444 //c We specify the tolerances in the stopping criteria. 19445 factr=1.0e1; 19446 pgtol=1.0e-5; 19447 19448 // We specify the dimension n of the sample problem and the number 19449 // m of limited memory corrections stored. (n and m should not 19450 // exceed the limits nmax and mmax respectively.) 19451 n=5; 19452 m=5; 19453 19454 // We now provide nbd which defines the bounds on the variables: 19455 // l specifies the lower bounds, 19456 // u specifies the upper bounds. 19457 // x specifies the initial guess 19458 x[0] = phi; nbd[0] = 2; l[0] = phi-2.0; u[0] = phi+2.0; 19459 x[1] = theta; nbd[1] = 2; l[1] = theta-2.0; u[1] = theta+2.0; 19460 x[2] = psi; nbd[2] = 2; l[2] = psi-2.0; u[2] = psi+2.0; 19461 x[3] = sxs; nbd[3] = 2; l[3] = sxs-2.0; u[3] = sxs+2.0; 19462 x[4] = sys; nbd[4] = 2; l[4] = sys-2.0; u[4] = sys+2.0; 19463 19464 19465 // We start the iteration by initializing task. 19466 // (**MUST clear remaining chars in task with spaces (else crash)!**) 19467 strcpy(task,"START"); 19468 for (int i=5;i<60;i++) task[i]=' '; 19469 19470 // This is the call to the L-BFGS-B code. 19471 // (* call the L-BFGS-B routine with task='START' once before loop *) 19472 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19473 int step = 1; 19474 19475 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *) 19476 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) { 19477 19478 if (strncmp(task,"FG",2)==0) { 19479 // the minimization routine has returned to request the 19480 // function f and gradient g values at the current x 19481 19482 // Compute function value f for the sample problem. 19483 proj = new EMData(); 19484 proj2 = new EMData(); 19485 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb); 19486 proj->fft_shuffle(); 19487 proj->center_origin_fft(); 19488 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f)); 19489 proj->do_ift_inplace(); 19490 int M = proj->get_ysize()/2; 19491 proj2 = proj->window_center(M); 19492 f = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 19493 //f = -f; 19494 delete proj; 19495 delete proj2; 19496 19497 // Compute gradient g for the sample problem. 19498 float dt = 1.0e-3f; 19499 proj = new EMData(); 19500 proj2 = new EMData(); 19501 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0]+dt, "theta", (float)x[1], "psi", (float)x[2])), kb); 19502 proj->fft_shuffle(); 19503 proj->center_origin_fft(); 19504 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f)); 19505 proj->do_ift_inplace(); 19506 proj2 = proj->window_center(M); 19507 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 19508 //ft = -ft; 19509 delete proj; 19510 delete proj2; 19511 g[0] = (ft-f)/dt; 19512 19513 proj = new EMData(); 19514 proj2 = new EMData(); 19515 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1]+dt, "psi", (float)x[2])), kb); 19516 proj->fft_shuffle(); 19517 proj->center_origin_fft(); 19518 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f)); 19519 proj->do_ift_inplace(); 19520 proj2 = proj->window_center(M); 19521 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 19522 //ft = -ft; 19523 delete proj; 19524 delete proj2; 19525 g[1] = (ft-f)/dt; 19526 19527 proj = new EMData(); 19528 proj2 = new EMData(); 19529 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2]+dt)), kb); 19530 proj->fft_shuffle(); 19531 proj->center_origin_fft(); 19532 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f)); 19533 proj->do_ift_inplace(); 19534 proj2 = proj->window_center(M); 19535 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 19536 //ft = -ft; 19537 delete proj; 19538 delete proj2; 19539 g[2] = (ft-f)/dt; 19540 19541 proj = new EMData(); 19542 proj2 = new EMData(); 19543 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb); 19544 proj->fft_shuffle(); 19545 proj->center_origin_fft(); 19546 proj->process_inplace("filter.shift", Dict("x_shift", x[3]+dt, "y_shift", x[4], "z_shift", 0.0f)); 19547 proj->do_ift_inplace(); 19548 proj2 = proj->window_center(M); 19549 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 19550 //ft = -ft; 19551 delete proj; 19552 delete proj2; 19553 g[3] = (ft-f)/dt; 19554 19555 proj = new EMData(); 19556 proj2 = new EMData(); 19557 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb); 19558 proj->fft_shuffle(); 19559 proj->center_origin_fft(); 19560 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4]+dt, "z_shift", 0.0f)); 19561 proj->do_ift_inplace(); 19562 proj2 = proj->window_center(M); 19563 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 19564 //ft = -ft; 19565 delete proj; 19566 delete proj2; 19567 g[4] = (ft-f)/dt; 19568 } 19569 19570 //c go back to the minimization routine. 19571 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19572 step++; 19573 } 19574 19575 //printf("Total step is %d\n", step); 19576 vector<float> res; 19577 res.push_back(static_cast<float>(x[0])); 19578 res.push_back(static_cast<float>(x[1])); 19579 res.push_back(static_cast<float>(x[2])); 19580 res.push_back(static_cast<float>(x[3])); 19581 res.push_back(static_cast<float>(x[4])); 19582 //res.push_back(step); 19583 return res; 19584 }
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 239 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.
00240 { 00241 ENTERFUNC; 00242 int Mid= (Size+1)/2; 00243 00244 if (flag==0) { // This is the real function 00245 EMData* ImBW = new EMData(); 00246 ImBW->set_size(Size,Size,1); 00247 ImBW->to_zero(); 00248 00249 float tempIm; 00250 float x,y; 00251 00252 for (int ix=(1-Mid); ix<Mid; ix++){ 00253 for (int iy=(1-Mid); iy<Mid; iy++){ 00254 x = (float)ix; 00255 y = (float)iy; 00256 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)) ); 00257 (*ImBW)(ix+Mid-1,iy+Mid-1) = tempIm * exp(.5f*p*p*a*a)* exp(.5f*q*q*b*b); 00258 } 00259 } 00260 ImBW->update(); 00261 ImBW->set_complex(false); 00262 ImBW->set_ri(true); 00263 00264 return ImBW; 00265 } 00266 else if (flag==1) { // This is the Fourier Transform 00267 EMData* ImBWFFT = new EMData(); 00268 ImBWFFT ->set_size(2*Size,Size,1); 00269 ImBWFFT ->to_zero(); 00270 00271 float r,s; 00272 00273 for (int ir=(1-Mid); ir<Mid; ir++){ 00274 for (int is=(1-Mid); is<Mid; is++){ 00275 r = (float)ir; 00276 s = (float)is; 00277 (*ImBWFFT)(2*(ir+Mid-1),is+Mid-1)= cosh(p*r*a*a) * cosh(q*s*b*b) * 00278 exp(-.5f*r*r*a*a)* exp(-.5f*s*s*b*b); 00279 } 00280 } 00281 ImBWFFT->update(); 00282 ImBWFFT->set_complex(true); 00283 ImBWFFT->set_ri(true); 00284 ImBWFFT->set_shuffled(true); 00285 ImBWFFT->set_fftodd(true); 00286 00287 return ImBWFFT; 00288 } 00289 else if (flag==2 || flag==3) { // This is the projection in Real Space 00290 float alpha = static_cast<float>( alphaDeg*M_PI/180.0 ); 00291 float C=cos(alpha); 00292 float S=sin(alpha); 00293 float D= sqrt(S*S*b*b + C*C*a*a); 00294 //float D2 = D*D; PAP - to get rid of warning 00295 00296 float P = p * C *a*a/D ; 00297 float Q = q * S *b*b/D ; 00298 00299 if (flag==2) { 00300 EMData* pofalpha = new EMData(); 00301 pofalpha ->set_size(Size,1,1); 00302 pofalpha ->to_zero(); 00303 00304 float Norm0 = D*(float)sqrt(2*pi); 00305 float Norm1 = exp( .5f*(P+Q)*(P+Q)) / Norm0 ; 00306 float Norm2 = exp( .5f*(P-Q)*(P-Q)) / Norm0 ; 00307 float sD; 00308 00309 for (int is=(1-Mid); is<Mid; is++){ 00310 sD = is/D ; 00311 (*pofalpha)(is+Mid-1) = Norm1 * exp(-.5f*sD*sD)*cos(sD*(P+Q)) 00312 + Norm2 * exp(-.5f*sD*sD)*cos(sD*(P-Q)); 00313 } 00314 pofalpha-> update(); 00315 pofalpha-> set_complex(false); 00316 pofalpha-> set_ri(true); 00317 00318 return pofalpha; 00319 } 00320 if (flag==3) { // This is the projection in Fourier Space 00321 float vD; 00322 00323 EMData* pofalphak = new EMData(); 00324 pofalphak ->set_size(2*Size,1,1); 00325 pofalphak ->to_zero(); 00326 00327 for (int iv=(1-Mid); iv<Mid; iv++){ 00328 vD = iv*D ; 00329 (*pofalphak)(2*(iv+Mid-1)) = exp(-.5f*vD*vD)*(cosh(vD*(P+Q)) + cosh(vD*(P-Q)) ); 00330 } 00331 pofalphak-> update(); 00332 pofalphak-> set_complex(false); 00333 pofalphak-> set_ri(true); 00334 00335 return pofalphak; 00336 } 00337 } 00338 else if (flag==4) { 00339 cout <<" FH under construction"; 00340 EMData* OutFT= TwoDTestFunc(Size, p, q, a, b, 1); 00341 EMData* TryFH= OutFT -> real2FH(4.0); 00342 return TryFH; 00343 } else { 00344 cout <<" flag must be 0,1,2,3, or 4"; 00345 } 00346 00347 EXITFUNC; 00348 return 0; 00349 }
void Util::update_fav | ( | EMData * | ave, | |
EMData * | dat, | |||
float | tot, | |||
int | mirror, | |||
vector< int > | numr | |||
) | [static] |
Definition at line 4588 of file util_sparx.cpp.
References EXITFUNC, EMAN::EMData::get_data(), numr, PI2, and EMAN::EMData::update().
04588 { 04589 int nring = numr.size()/3; 04590 float *ave = avep->get_data(); 04591 float *dat = datp->get_data(); 04592 int i, j, numr3i, np; 04593 float arg, cs, si; 04594 int maxrin = numr(3,nring); 04595 if(mirror == 1) { //for mirrored data has to be conjugated 04596 for (i=1; i<=nring; i++) { 04597 numr3i = numr(3,i); 04598 np = numr(2,i)-1; 04599 ave[np] += dat[np]; 04600 ave[np+1] += static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) ); 04601 for (j=2; j<numr3i; j=j+2) { 04602 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin ); 04603 cs = cos(arg); 04604 si = sin(arg); 04605 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg)) 04606 ave[np + j] += dat[np + j]*cs - dat[np + j +1]*si; 04607 ave[np + j +1] -= dat[np + j]*si + dat[np + j +1]*cs; 04608 } 04609 } 04610 } else { 04611 for (i=1; i<=nring; i++) { 04612 numr3i = numr(3,i); 04613 np = numr(2,i)-1; 04614 ave[np] += dat[np]; 04615 ave[np+1] += static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) ); 04616 for (j=2; j<numr3i; j=j+2) { 04617 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin ); 04618 cs = cos(arg); 04619 si = sin(arg); 04620 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg)) 04621 ave[np + j] += dat[np + j]*cs - dat[np + j +1]*si; 04622 ave[np + j +1] += dat[np + j]*si + dat[np + j +1]*cs; 04623 } 04624 } 04625 } 04626 avep->update(); 04627 EXITFUNC; 04628 }
static double EMAN::Util::var | ( | double * | x, | |
int | n | |||
) | [inline, static] |
vector< float > Util::vareas | ( | EMData * | d | ) | [static] |
Definition at line 20569 of file util_sparx.cpp.
References data, dm, EMAN::EMData::get_ysize(), and ny.
20569 { 20570 const float step=0.001f; 20571 int ny = d->get_ysize(); 20572 // input emdata should have size 2xN, where N is number of points 20573 // output vector should be 2xN, first element is the number of elements 20574 // associated with this point, second is 0 is the element is touching the border, 1 if it is interior 20575 vector<float> group(2*ny); 20576 for(int i=0; i<2*ny; i++) group[i] = 0.0f; 20577 int K = int(1.0f/step) +1; 20578 int hit = 0; 20579 for(int kx=0; kx<=K; kx++) { 20580 float tx = kx*step; 20581 for(int ky=0; ky<=K; ky++) { 20582 float ty = ky*step; 20583 float dm = 1.0e23f; 20584 for(int i=0; i<ny; i++) { 20585 float qd = pow(tx-(*d)(0,i),2) + pow(ty-(*d)(1,i),2); 20586 if( qd < dm) { 20587 dm = qd; 20588 hit = i; 20589 } 20590 } 20591 data(0,hit) += 1.0f; 20592 if(kx == 0 || ky == 0 || kx == K || ky == K) data(1,hit) = 1.0f; 20593 } 20594 } 20595 return group; 20596 }
void Util::voronoi | ( | double * | phi, | |
double * | theta, | |||
double * | weight, | |||
int | nt | |||
) | [static] |
Definition at line 7655 of file util_sparx.cpp.
References ang_to_xyz(), areav_(), Assert, disorder2(), ENTERFUNC, EXITFUNC, flip23(), key, status, trmsh3_(), and y.
07656 { 07657 07658 ENTERFUNC; 07659 07660 int *list, *lptr, *lend, *iwk, *key,*lcnt,*indx,*good; 07661 int nt6, n, ier, nout, lnew, mdup, nd; 07662 int i,k,mt,status; 07663 07664 07665 double *ds, *x, *y, *z; 07666 double tol = 1.0e-8; 07667 double dtol = 15; 07668 double a; 07669 07670 /*if(last){ 07671 if(medium>nt) n = nt+nt; 07672 else n = nt+nt-medium+1; 07673 } 07674 else{ 07675 n=nt; 07676 }*/ 07677 07678 n = nt + nt; 07679 07680 nt6 = n*6; 07681 07682 list = (int*)calloc(nt6,sizeof(int)); 07683 lptr = (int*)calloc(nt6,sizeof(int)); 07684 lend = (int*)calloc(n ,sizeof(int)); 07685 iwk = (int*)calloc(n ,sizeof(int)); 07686 good = (int*)calloc(n ,sizeof(int)); 07687 key = (int*)calloc(n ,sizeof(int)); 07688 indx = (int*)calloc(n ,sizeof(int)); 07689 lcnt = (int*)calloc(n ,sizeof(int)); 07690 07691 ds = (double*) calloc(n,sizeof(double)); 07692 x = (double*) calloc(n,sizeof(double)); 07693 y = (double*) calloc(n,sizeof(double)); 07694 z = (double*) calloc(n,sizeof(double)); 07695 07696 if (list == NULL || 07697 lptr == NULL || 07698 lend == NULL || 07699 iwk == NULL || 07700 good == NULL || 07701 key == NULL || 07702 indx == NULL || 07703 lcnt == NULL || 07704 x == NULL || 07705 y == NULL || 07706 z == NULL || 07707 ds == NULL) { 07708 printf("memory allocation failure!\n"); 07709 exit(1); 07710 } 07711 07712 bool colinear=true; 07713 while(colinear) 07714 { 07715 07716 L1: 07717 for(i = 0; i<nt; i++){ 07718 x[i] = theta[i]; 07719 y[i] = phi[i]; 07720 x[nt+i] = 180.0 - x[i]; 07721 y[nt+i] = 180.0 + y[i]; 07722 } 07723 07724 Util::disorder2(x, y, key, n); 07725 07726 // check if the first three angles are not close, else shuffle 07727 double val; 07728 for(k=0; k<2; k++){ 07729 for(i=k+1; i<3; i++){ 07730 val = (x[i]-x[k])*(x[i]-x[k]) + (y[i]-y[k])*(y[i]-y[k]); 07731 if( val < dtol) { 07732 goto L1; 07733 } 07734 } 07735 } 07736 07737 Util::ang_to_xyz(x, y, z, n); 07738 07739 // Make sure that first three has no duplication 07740 bool dupnode=true; 07741 dupnode=true; 07742 while(dupnode) 07743 { 07744 for(k=0; k<2; k++){ 07745 for(i=k+1; i<3; i++){ 07746 if( x[i]*x[k]+y[i]*y[k]+z[i]*z[k] > 1.0-tol) { 07747 Util::flip23(x, y, z, key, k, n); 07748 continue; 07749 } 07750 } 07751 } 07752 dupnode = false; 07753 } 07754 07755 07756 ier = 0; 07757 07758 status = Util::trmsh3_(&n,&tol,x,y,z,&nout,list,lptr,lend,&lnew, indx, lcnt, iwk, good, ds, &ier); 07759 07760 if (status != 0) { 07761 printf(" error in trmsh3 \n"); 07762 exit(1); 07763 } 07764 07765 if (ier > 0) { 07766 printf("*** Error in TRMESH: duplicate nodes encountered ***\n"); 07767 exit(1); 07768 } 07769 07770 mdup=n-nout; 07771 if (ier == -2) { 07772 //printf("in TRMESH:the first three nodes are colinear*** disorder again\n"); 07773 } 07774 else 07775 { 07776 colinear=false; 07777 } 07778 } 07779 07780 07781 Assert( ier != -2 ); 07782 // Create a list of unique nodes GOOD, the numbers refer to locations on the full list 07783 // INDX contains node numbers from the squeezed list 07784 nd=0; 07785 for (k=1; k<=n; k++){ 07786 if (indx[k-1]>0) { 07787 nd++; 07788 good[nd-1]=k; 07789 } 07790 } 07791 07792 // 07793 // *** Compute the Voronoi region areas. 07794 // 07795 for(i = 1; i<=nout; i++) { 07796 k=good[i-1]; 07797 // We only need n weights from hemisphere 07798 if (key[k-1] <= nt) { 07799 // CALCULATE THE AREA 07800 a = Util::areav_(&i, &nout, x, y, z, list, lptr, lend, &ier); 07801 if (ier != 0){ 07802 // We set the weight to -1, this will signal the error in the calling 07803 // program, as the area will turn out incorrect 07804 printf(" *** error in areav: ier = %d ***\n", ier); 07805 weight[key[k-1]-1] =-1.0; 07806 } else { 07807 // Assign the weight 07808 weight[key[k-1]-1]=a/lcnt[i-1]; 07809 } 07810 } 07811 } 07812 07813 07814 // Fill out the duplicated weights 07815 for(i = 1; i<=n; i++){ 07816 mt =- indx[i-1]; 07817 if (mt>0){ 07818 k = good[mt-1]; 07819 // This is a duplicated entry, get the already calculated 07820 // weight and assign it. 07821 // We only need n weights from hemisphere 07822 if (key[i-1] <= nt && key[k-1] <= nt) { weight[key[i-1]-1] = weight[key[k-1]-1];} 07823 } 07824 } 07825 07826 free(list); 07827 free(lend); 07828 free(iwk); 07829 free(good); 07830 free(key); 07831 free(lptr); 07832 free(indx); 07833 free(lcnt); 07834 free(ds); 07835 free(x); 07836 free(y); 07837 free(z); 07838 07839 07840 EXITFUNC; 07841 }
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 7232 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, hsortd(), ImageFormatException, key, LOGERR, phi, theta, voronoi(), and weight.
07233 { 07234 07235 ENTERFUNC; 07236 07237 if ( th.size() != ph.size() ) { 07238 LOGERR("images not same size"); 07239 throw ImageFormatException( "images not same size"); 07240 } 07241 07242 // rand_seed 07243 srand(10); 07244 07245 int i,*key; 07246 int len = th.size(); 07247 double *theta,*phi,*weight; 07248 theta = (double*) calloc(len,sizeof(double)); 07249 phi = (double*) calloc(len,sizeof(double)); 07250 weight = (double*) calloc(len,sizeof(double)); 07251 key = (int*) calloc(len,sizeof(int)); 07252 const float *thptr, *phptr; 07253 07254 thptr = &th[0]; 07255 phptr = &ph[0]; 07256 for(i=1;i<=len;i++){ 07257 key(i) = i; 07258 weight(i) = 0.0; 07259 } 07260 07261 for(i = 0;i<len;i++){ 07262 theta[i] = thptr[i]; 07263 phi[i] = phptr[i]; 07264 } 07265 07266 // sort by theta 07267 Util::hsortd(theta, phi, key, len, 1); 07268 07269 //Util::voronoidiag(theta,phi, weight, len); 07270 Util::voronoi(phi, theta, weight, len); 07271 07272 //sort by key 07273 Util::hsortd(weight, weight, key, len, 2); 07274 07275 free(theta); 07276 free(phi); 07277 free(key); 07278 vector<double> wt; 07279 double count = 0; 07280 for(i=1; i<= len; i++) 07281 { 07282 wt.push_back(weight(i)); 07283 count += weight(i); 07284 } 07285 07286 //if( abs(count-6.28) > 0.1 ) 07287 //{ 07288 // printf("Warning: SUM OF VORONOI CELLS AREAS IS %lf, should 2*PI\n", count); 07289 //} 07290 07291 free(weight); 07292 07293 EXITFUNC; 07294 return wt; 07295 07296 }
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 5390 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().
05391 { 05392 /* Exception Handle */ 05393 if (!img) throw NullPointerException("NULL input image"); 05394 /* ============================== */ 05395 05396 // Get the size of the input image 05397 int nx=img->get_xsize(), ny=img->get_ysize(), nz=img->get_zsize(); 05398 /* ============================== */ 05399 05400 /* Exception Handle */ 05401 if(new_nx>nx || new_ny>ny || new_nz>nz) 05402 throw ImageDimensionException("The size of the windowed image cannot exceed the input image size."); 05403 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) 05404 throw ImageDimensionException("The offset inconsistent with the input image size."); 05405 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)))) 05406 throw ImageDimensionException("The offset inconsistent with the input image size."); 05407 /* ============================== */ 05408 05409 /* Calculation of the start point */ 05410 int new_st_x = nx/2-new_nx/2 + x_offset, 05411 new_st_y = ny/2-new_ny/2 + y_offset, 05412 new_st_z = nz/2-new_nz/2 + z_offset; 05413 /* ============================== */ 05414 05415 /* Exception Handle */ 05416 if (new_st_x<0 || new_st_y<0 || new_st_z<0) // WHAT HAPPENS WITH THE END POINT CHECK?? PAP 05417 throw ImageDimensionException("The offset inconsistent with the input image size."); 05418 /* ============================== */ 05419 05420 EMData* wind = img->copy_empty_head(); 05421 wind->set_size(new_nx, new_ny, new_nz); 05422 float *outp=wind->get_data(); 05423 float *inp=img->get_data(); 05424 05425 for (int k=0; k<new_nz; k++) 05426 for(int j=0; j<new_ny; j++) 05427 for(int i=0; i<new_nx; i++) 05428 outp(i,j,k) = inp(i,j,k); 05429 wind->update(); 05430 return wind; 05431 }
void Util::WTF | ( | EMData * | PROJ, | |
vector< float > | SS, | |||
float | SNR, | |||
int | K | |||
) | [static] |
Definition at line 5878 of file util_sparx.cpp.
References EMAN::EMData::get_data(), max, min, PROJ, q, SS, EMAN::EMData::update(), W, and Y.
05879 { 05880 int NSAM,NROW,NNNN,NR2,L,JY,KX,NANG; 05881 float WW,OX,OY; 05882 05883 NSAM = PROJ->get_xsize(); 05884 NROW = PROJ->get_ysize(); 05885 int ntotal = NSAM*NROW; 05886 float q = 2.0f; 05887 float qt = 8.0f/q; 05888 // Fix for padding 2x 05889 int ipad = 1; 05890 NSAM *= ipad; 05891 NROW *= ipad; 05892 NNNN = NSAM+2-(NSAM%2); 05893 int NX2 = NSAM/2; 05894 NR2 = NROW/2; 05895 05896 NANG = int(SS.size())/6; 05897 05898 EMData* W = new EMData(); 05899 int Wnx = NNNN/2; 05900 W->set_size(Wnx,NROW,1); 05901 W->to_zero(); 05902 float *Wptr = W->get_data(); 05903 float *PROJptr = PROJ->get_data(); 05904 for (L=1; L<=NANG; L++) { 05905 float tmp1 = SS(3,K)*SS(4,L)*(SS(1,K)*SS(1,L) + SS(2,K)*SS(2,L)) - SS(3,L)*SS(4,K); 05906 float tmp2 = SS(4,L)*( SS(1,K)*SS(2,L) - SS(1,L)*SS(2,K) ); 05907 OX = SS(6,K)*tmp2 + SS(5,K)*tmp1; 05908 OY = SS(5,K)*tmp2 - SS(6,K)*tmp1; 05909 if(OX < 0.0f) { 05910 OX = -OX; 05911 OY = -OY; 05912 } 05913 05914 if( fabs(OX) > 1.0e-6f || fabs(OY) > 1.0e6f ) { 05915 for(int J=1;J<=NROW;J++) { 05916 JY = (J-1); 05917 if(JY > NR2) JY -= NROW; 05918 #ifdef _WIN32 05919 int xma = _cpp_min(int(0.5f+(q-JY*OY)/OX),NX2); 05920 int xmi = _cpp_max(int((-q-JY*OY)/OX+0.5+NSAM)-NSAM,0); 05921 #else 05922 int xma = std::min(int(0.5f+(q-JY*OY)/OX),NX2); 05923 int xmi = std::max(int((-q-JY*OY)/OX+0.5+NSAM)-NSAM,0); 05924 #endif //_WIN32 05925 if( xmi <= xma) { 05926 for(int I=xmi;I<=xma;I++) { 05927 float Y = fabs(OX*I + OY*JY); 05928 W(I+1,J) += exp(-qt*Y*Y); 05929 //cout << " L "<<L << " I "<<I << " JY "<<JY << " ARG "<<qt*Y*Y <<endl; 05930 } 05931 } 05932 } 05933 } else { 05934 for(int J=1;J<=NROW;J++) for(int I=1;I<=NNNN/2;I++) W(I,J) += 1.0f; 05935 } 05936 } 05937 EMData* proj_in = PROJ; 05938 05939 PROJ = PROJ->norm_pad( false, ipad); 05940 PROJ->do_fft_inplace(); 05941 PROJ->update(); 05942 //cout << " x "<<PROJ->get_xsize() << " y "<<PROJ->get_ysize() <<endl; 05943 PROJptr = PROJ->get_data(); 05944 05945 float WNRMinv,temp; 05946 float osnr = 1.0f/SNR; 05947 WNRMinv = 1.0f/W(1,1); 05948 for(int J=1;J<=NROW;J++) { 05949 JY = J-1; 05950 if( JY > NR2) JY -= NROW; 05951 float sy = JY; 05952 sy /= NROW; 05953 sy *= sy; 05954 for(int I=1;I<=NNNN;I+=2) { 05955 KX = (I+1)/2; 05956 temp = W(KX,J)*WNRMinv; 05957 WW = temp/(temp*temp + osnr); 05958 // This is supposed to fix fall-off due to Gaussian function in the weighting function 05959 float sx = KX-1; 05960 sx /= NSAM; 05961 WW *= exp(qt*(sy + sx*sx)); 05962 PROJ(I,J) *= WW; 05963 PROJ(I+1,J) *= WW; 05964 } 05965 } 05966 delete W; W = 0; 05967 PROJ->do_ift_inplace(); 05968 PROJ->depad(); 05969 05970 float* data_src = PROJ->get_data(); 05971 float* data_dst = proj_in->get_data(); 05972 05973 for( int i=0; i < ntotal; ++i ) data_dst[i] = data_src[i]; 05974 05975 proj_in->update(); 05976 05977 delete PROJ; 05978 }
void Util::WTM | ( | EMData * | PROJ, | |
vector< float > | SS, | |||
int | DIAMETER, | |||
int | NUMP | |||
) | [static] |
Definition at line 6072 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.
06073 { 06074 float rad2deg =(180.0f/3.1415926f); 06075 float deg2rad = (3.1415926f/180.0f); 06076 06077 int NSAM,NROW,NNNN,NR2,NANG,L,JY; 06078 06079 NSAM = PROJ->get_xsize(); 06080 NROW = PROJ->get_ysize(); 06081 NNNN = NSAM+2-(NSAM%2); 06082 NR2 = NROW/2; 06083 NANG = int(SS.size())/6; 06084 06085 float RI[9]; 06086 RI(1,1)=SS(1,NUMP)*SS(3,NUMP)*SS(5,NUMP)-SS(2,NUMP)*SS(6,NUMP); 06087 RI(2,1)=-SS(1,NUMP)*SS(3,NUMP)*SS(6,NUMP)-SS(2,NUMP)*SS(5,NUMP); 06088 RI(3,1)=SS(1,NUMP)*SS(4,NUMP); 06089 RI(1,2)=SS(2,NUMP)*SS(3,NUMP)*SS(5,NUMP)+SS(1,NUMP)*SS(6,NUMP); 06090 RI(2,2)=-SS(2,NUMP)*SS(3,NUMP)*SS(6,NUMP)+SS(1,NUMP)*SS(5,NUMP); 06091 RI(3,2)=SS(2,NUMP)*SS(4,NUMP); 06092 RI(1,3)=-SS(4,NUMP)*SS(5,NUMP); 06093 RI(2,3)=SS(4,NUMP)*SS(6,NUMP); 06094 RI(3,3)=SS(3,NUMP); 06095 06096 float THICK=static_cast<float>( NSAM)/DIAMETER/2.0f ; 06097 06098 EMData* W = new EMData(); 06099 int Wnx = NNNN/2; 06100 W->set_size(NNNN/2,NROW,1); 06101 W->to_one(); 06102 float *Wptr = W->get_data(); 06103 06104 float ALPHA,TMP,FV,RT,FM,CCN,CC[3],CP[2],VP[2],VV[3]; 06105 06106 for (L=1; L<=NANG; L++) { 06107 if (L != NUMP) { 06108 CC(1)=SS(2,L)*SS(4,L)*SS(3,NUMP)-SS(3,L)*SS(2,NUMP)*SS(4,NUMP); 06109 CC(2)=SS(3,L)*SS(1,NUMP)*SS(4,NUMP)-SS(1,L)*SS(4,L)*SS(3,NUMP); 06110 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); 06111 06112 TMP = sqrt(CC(1)*CC(1) + CC(2)*CC(2) + CC(3)*CC(3)); 06113 CCN=static_cast<float>( AMAX1( AMIN1(TMP,1.0) ,-1.0) ); 06114 ALPHA=rad2deg*float(asin(CCN)); 06115 if (ALPHA>180.0f) ALPHA=ALPHA-180.0f; 06116 if (ALPHA>90.0f) ALPHA=180.0f-ALPHA; 06117 if(ALPHA<1.0E-6) { 06118 for(int J=1;J<=NROW;J++) for(int I=1;I<=NNNN/2;I++) W(I,J)+=1.0; 06119 } else { 06120 FM=THICK/(fabs(sin(ALPHA*deg2rad))); 06121 CC(1) = CC(1)/CCN;CC(2) = CC(2)/CCN;CC(3) = CC(3)/CCN; 06122 VV(1)= SS(2,L)*SS(4,L)*CC(3)-SS(3,L)*CC(2); 06123 VV(2)= SS(3,L)*CC(1)-SS(1,L)*SS(4,L)*CC(3); 06124 VV(3)= SS(1,L)*SS(4,L)*CC(2)-SS(2,L)*SS(4,L)*CC(1); 06125 CP(1) = 0.0;CP(2) = 0.0; 06126 VP(1) = 0.0;VP(2) = 0.0; 06127 06128 CP(1) = CP(1) + RI(1,1)*CC(1) + RI(1,2)*CC(2) + RI(1,3)*CC(3); 06129 CP(2) = CP(2) + RI(2,1)*CC(1) + RI(2,2)*CC(2) + RI(2,3)*CC(3); 06130 VP(1) = VP(1) + RI(1,1)*VV(1) + RI(1,2)*VV(2) + RI(1,3)*VV(3); 06131 VP(2) = VP(2) + RI(2,1)*VV(1) + RI(2,2)*VV(2) + RI(2,3)*VV(3); 06132 06133 TMP = CP(1)*VP(2)-CP(2)*VP(1); 06134 06135 // PREVENT TMP TO BE TOO SMALL, SIGN IS IRRELEVANT 06136 TMP = AMAX1(1.0E-4f,fabs(TMP)); 06137 float tmpinv = 1.0f/TMP; 06138 for(int J=1;J<=NROW;J++) { 06139 JY = (J-1); 06140 if (JY>NR2) JY=JY-NROW; 06141 for(int I=1;I<=NNNN/2;I++) { 06142 FV = fabs((JY*CP(1)-(I-1)*CP(2))*tmpinv); 06143 RT = 1.0f-FV/FM; 06144 W(I,J) += ((RT>0.0f)*RT); 06145 } 06146 } 06147 } 06148 } 06149 } 06150 06151 EMData* proj_in = PROJ; 06152 06153 PROJ = PROJ->norm_pad( false, 1); 06154 PROJ->do_fft_inplace(); 06155 PROJ->update(); 06156 float *PROJptr = PROJ->get_data(); 06157 06158 int KX; 06159 float WW; 06160 for(int J=1; J<=NROW; J++) 06161 for(int I=1; I<=NNNN; I+=2) { 06162 KX = (I+1)/2; 06163 WW = 1.0f/W(KX,J); 06164 PROJ(I,J) = PROJ(I,J)*WW; 06165 PROJ(I+1,J) = PROJ(I+1,J)*WW; 06166 } 06167 delete W; W = 0; 06168 PROJ->do_ift_inplace(); 06169 PROJ->depad(); 06170 06171 float* data_src = PROJ->get_data(); 06172 float* data_dst = proj_in->get_data(); 06173 06174 int ntotal = NSAM*NROW; 06175 for( int i=0; i < ntotal; ++i ) data_dst[i] = data_src[i]; 06176 06177 proj_in->update(); 06178 delete PROJ; 06179 }