#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 Dict | ExpMinus4YSqr (float ymax, int nsamples) |
static void | WTM (EMData *PROJ, vector< float > SS, int DIAMETER, int NUMP) |
static void | WTF (EMData *PROJ, vector< float > SS, float SNR, int K, vector< float > exptable) |
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_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 | bb_enumerate_ (int *Parts, int *classDims, int nParts, int nClasses, int T, int n_guesses, int *levels) |
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. | |
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 * | branch (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int *Levels, int nLevels, int curlevel, int n_guesses) |
static int | findTopLargest (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int *matchlist, int max_num_matches, int *costlist, int n_guesses) |
find max_num_matches feasible matches (if possible) which has weight gt T, and weight gteq weight of all other feasible matches. | |
static int | generatesubmax (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int n_guesses) |
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 newT, int *curmax) |
return the weight of the largest weighted feasible match, along with the match in the (preallocated) argument curmax. | |
static int * | explore2 (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int newT, int *curintx, int size_curintx, int *next, int size_next, int depth) |
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 nTop, int n_guesses, bool doMPI, int *Levels) |
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 vector< int > | branchMPIpy_ (int *argParts, int *dimClasses, int nParts, int K, int T, int *Levels, int nLevels, int n_guesses, int nFirst, int *firstmatches) |
an interface function between python code and branchMPI. | |
static int * | branchMPI (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int *Levels, int nLevels, int curlevel, int n_guesses, int nFirst, int *firstmatches) |
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 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 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, 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, int 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_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) |
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_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 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 17418 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().
17419 { 17420 ENTERFUNC; 17421 /* Exception Handle */ 17422 if (!img) { 17423 throw NullPointerException("NULL input image"); 17424 } 17425 /* ========= img += img1 ===================== */ 17426 17427 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17428 int size = nx*ny*nz; 17429 float *img_ptr = img->get_data(); 17430 float *img1_ptr = img1->get_data(); 17431 for (int i=0;i<size;i++) img_ptr[i] += img1_ptr[i]; 17432 img->update(); 17433 17434 EXITFUNC; 17435 }
Definition at line 17456 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().
17457 { 17458 ENTERFUNC; 17459 /* Exception Handle */ 17460 if (!img) { 17461 throw NullPointerException("NULL input image"); 17462 } 17463 /* ========= img += img1**2 ===================== */ 17464 17465 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17466 int size = nx*ny*nz; 17467 float *img_ptr = img->get_data(); 17468 float *img1_ptr = img1->get_data(); 17469 if(img->is_complex()) { 17470 for (int i=0; i<size; i+=2) img_ptr[i] += img1_ptr[i] * img1_ptr[i] + img1_ptr[i+1] * img1_ptr[i+1] ; 17471 } else { 17472 for (int i=0;i<size;i++) img_ptr[i] += img1_ptr[i]*img1_ptr[i]; 17473 } 17474 img->update(); 17475 17476 EXITFUNC; 17477 }
Definition at line 17437 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().
17438 { 17439 ENTERFUNC; 17440 /* Exception Handle */ 17441 if (!img) { 17442 throw NullPointerException("NULL input image"); 17443 } 17444 /* ========= img += img1 ===================== */ 17445 17446 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17447 int size = nx*ny*nz; 17448 float *img_ptr = img->get_data(); 17449 float *img1_ptr = img1->get_data(); 17450 for (int i=0;i<size;i++) img_ptr[i] += abs(img1_ptr[i]); 17451 img->update(); 17452 17453 EXITFUNC; 17454 }
Definition at line 17235 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().
17236 { 17237 ENTERFUNC; 17238 /* Exception Handle */ 17239 if (!img) { 17240 throw NullPointerException("NULL input image"); 17241 } 17242 /* ============== output = img + img1 ================ */ 17243 17244 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17245 int size = nx*ny*nz; 17246 EMData * img2 = img->copy_head(); 17247 float *img_ptr =img->get_data(); 17248 float *img2_ptr = img2->get_data(); 17249 float *img1_ptr = img1->get_data(); 17250 for (int i=0;i<size;i++) img2_ptr[i] = img_ptr[i] + img1_ptr[i]; 17251 img2->update(); 17252 if(img->is_complex()) { 17253 img2->set_complex(true); 17254 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17255 } 17256 17257 EXITFUNC; 17258 return img2; 17259 }
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 1702 of file util.h.
Referenced by EMAN::WienerFourierReconstructor::insert_slice(), 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 18271 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.
18273 { 18274 18275 int maxrin = numr[numr.size()-1]; 18276 18277 int ky = int(2*yrng/step+0.5)/2; 18278 int kx = int(2*xrng/step+0.5)/2; 18279 18280 float *p_ccf1ds = (float *)malloc(maxrin*sizeof(float)); 18281 float *p_ccf1dm = (float *)malloc(maxrin*sizeof(float)); 18282 int vol = maxrin*(2*kx+1)*(2*ky+1); 18283 vector<ccf_point> ccf(2*vol); 18284 ccf_point temp; 18285 18286 int index = 0; 18287 for (int i = -ky; i <= ky; i++) { 18288 float iy = i * step; 18289 for (int j = -kx; j <= kx; j++) { 18290 float ix = j*step; 18291 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18292 Frngs(cimage, numr); 18293 Crosrng_msg_vec(crefim, cimage, numr, p_ccf1ds, p_ccf1dm); 18294 for (int k=0; k<maxrin; k++) { 18295 temp.value = p_ccf1ds[k]; 18296 temp.i = k; 18297 temp.j = j; 18298 temp.k = i; 18299 temp.mirror = 0; 18300 ccf[index] = temp; 18301 index++; 18302 temp.value = p_ccf1dm[k]; 18303 temp.mirror = 1; 18304 ccf[index] = temp; 18305 index++; 18306 } 18307 delete cimage; cimage = 0; 18308 } 18309 } 18310 18311 delete p_ccf1ds; 18312 delete p_ccf1dm; 18313 std::sort(ccf.begin(), ccf.end(), ccf_value()); 18314 18315 double qt = (double)ccf[0].value; 18316 vector <double> p(2*vol), cp(2*vol); 18317 18318 double sump = 0.0; 18319 for (int i=0; i<2*vol; i++) { 18320 p[i] = pow(double(ccf[i].value)/qt, 1.0/T); 18321 sump += p[i]; 18322 } 18323 for (int i=0; i<2*vol; i++) { 18324 p[i] /= sump; 18325 } 18326 for (int i=1; i<2*vol; i++) { 18327 p[i] += p[i-1]; 18328 } 18329 p[2*vol-1] = 2.0; 18330 18331 float t = get_frand(0.0f, 1.0f); 18332 int select = 0; 18333 while (p[select] < t) select += 1; 18334 18335 vector<float> a(6); 18336 a[0] = ccf[select].value; 18337 a[1] = (float)ccf[select].i; 18338 a[2] = (float)ccf[select].j; 18339 a[3] = (float)ccf[select].k; 18340 a[4] = (float)ccf[select].mirror; 18341 a[5] = (float)select; 18342 return a; 18343 }
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 2360 of file util_sparx.cpp.
References circ, numr, quadri(), and y.
02361 { 02362 double dpi, dfi; 02363 int it, jt, inr, l, nsim, kcirc, lt; 02364 float xold, yold, fi, x, y; 02365 02366 // cns2 and cnr2 are predefined centers 02367 // no need to set to zero, all elements are defined 02368 02369 dpi = 2*atan(1.0); 02370 for (it=1; it<=nring; it++) { 02371 // radius of the ring 02372 inr = numr(1,it); 02373 02374 l = numr(3,it); 02375 if ( mode == 'h' || mode == 'H' ) lt = l / 2; 02376 else lt = l / 4; 02377 02378 nsim = lt - 1; 02379 dfi = dpi / (nsim+1); 02380 kcirc = numr(2,it); 02381 02382 02383 xold = 0.0f+cns2; 02384 yold = inr+cnr2; 02385 02386 circ(kcirc) = quadri(xold,yold,nsam,nrow,xim); 02387 02388 xold = inr+cns2; 02389 yold = 0.0f+cnr2; 02390 circ(lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02391 02392 if ( mode == 'f' || mode == 'F' ) { 02393 xold = 0.0f+cns2; 02394 yold = -inr+cnr2; 02395 circ(lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02396 02397 xold = -inr+cns2; 02398 yold = 0.0f+cnr2; 02399 circ(lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02400 } 02401 02402 for (jt=1; jt<=nsim; jt++) { 02403 fi = static_cast<float>(dfi * jt); 02404 x = sin(fi) * inr; 02405 y = cos(fi) * inr; 02406 02407 xold = x+cns2; 02408 yold = y+cnr2; 02409 circ(jt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02410 02411 xold = y+cns2; 02412 yold = -x+cnr2; 02413 circ(jt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02414 02415 if ( mode == 'f' || mode == 'F' ) { 02416 xold = -x+cns2; 02417 yold = -y+cnr2; 02418 circ(jt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02419 02420 xold = -y+cns2; 02421 yold = x+cnr2; 02422 circ(jt+lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02423 } 02424 } // end for jt 02425 } //end for it 02426 }
float Util::ang_n | ( | float | peakp, | |
string | mode, | |||
int | maxrin | |||
) | [static, private] |
Definition at line 17665 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(), and multiref_polar_ali_helical().
17666 { 17667 if (mode == "f" || mode == "F") 17668 return fmodf(((peakp-1.0f) / maxrin+1.0f)*360.0f,360.0f); 17669 else 17670 return fmodf(((peakp-1.0f) / maxrin+1.0f)*180.0f,180.0f); 17671 }
void Util::ang_to_xyz | ( | double * | x, | |
double * | y, | |||
double * | z, | |||
int | len | |||
) | [static] |
Definition at line 7611 of file util_sparx.cpp.
References dgr_to_rad, ENTERFUNC, and EXITFUNC.
07612 { 07613 ENTERFUNC; 07614 double costheta,sintheta,cosphi,sinphi; 07615 for(int i = 0; i<len; i++) 07616 { 07617 cosphi = cos(y[i]*dgr_to_rad); 07618 sinphi = sin(y[i]*dgr_to_rad); 07619 if(fabs(x[i]-90.0)< 1.0e-5){ 07620 x[i] = cosphi; 07621 y[i] = sinphi; 07622 z[i] = 0.0; 07623 } 07624 else{ 07625 costheta = cos(x[i]*dgr_to_rad); 07626 sintheta = sin(x[i]*dgr_to_rad); 07627 x[i] = cosphi*sintheta; 07628 y[i] = sinphi*sintheta; 07629 z[i] = costheta; 07630 } 07631 } 07632 EXITFUNC; 07633 }
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 1872 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 1840 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 2095 of file util.h.
Referenced by EMAN::Transform::get_determinant(), EMAN::Transform::get_scale(), EMAN::Transform::get_scale_and_mirror(), EMAN::Transform::get_trans(), EMAN::Transform::is_identity(), and EMAN::Transform::set_scale().
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 8676 of file util_sparx.cpp.
References areas_(), circum_(), FALSE_, ierr, and TRUE_.
Referenced by voronoi().
08679 { 08680 /* Initialized data */ 08681 08682 static double amax = 6.28; 08683 08684 /* System generated locals */ 08685 double ret_val; 08686 08687 /* Local variables */ 08688 static double a, c0[3], c2[3], c3[3]; 08689 static int n1, n2, n3; 08690 static double v1[3], v2[3], v3[3]; 08691 static int lp, lpl, ierr; 08692 static double asum; 08693 extern double areas_(double *, double *, double *); 08694 static long int first; 08695 extern /* Subroutine */ int circum_(double *, double *, 08696 double *, double *, int *); 08697 08698 08699 /* *********************************************************** */ 08700 08701 /* Robert J. Renka */ 08702 /* Dept. of Computer Science */ 08703 /* Univ. of North Texas */ 08704 /* renka@cs.unt.edu */ 08705 /* 10/25/02 */ 08706 08707 /* Given a Delaunay triangulation and the index K of an */ 08708 /* interior node, this subroutine returns the (surface) area */ 08709 /* of the Voronoi region associated with node K. The Voronoi */ 08710 /* region is the polygon whose vertices are the circumcenters */ 08711 /* of the triangles that contain node K, where a triangle */ 08712 /* circumcenter is the point (unit vector) lying at the same */ 08713 /* angular distance from the three vertices and contained in */ 08714 /* the same hemisphere as the vertices. */ 08715 08716 08717 /* On input: */ 08718 08719 /* K = Nodal index in the range 1 to N. */ 08720 08721 /* N = Number of nodes in the triangulation. N > 3. */ 08722 08723 /* X,Y,Z = Arrays of length N containing the Cartesian */ 08724 /* coordinates of the nodes (unit vectors). */ 08725 08726 /* LIST,LPTR,LEND = Data structure defining the trian- */ 08727 /* gulation. Refer to Subroutine */ 08728 /* TRMESH. */ 08729 08730 /* Input parameters are not altered by this function. */ 08731 08732 /* On output: */ 08733 08734 /* AREAV = Area of Voronoi region K unless IER > 0, */ 08735 /* in which case AREAV = 0. */ 08736 08737 /* IER = Error indicator: */ 08738 /* IER = 0 if no errors were encountered. */ 08739 /* IER = 1 if K or N is outside its valid range */ 08740 /* on input. */ 08741 /* IER = 2 if K indexes a boundary node. */ 08742 /* IER = 3 if an error flag is returned by CIRCUM */ 08743 /* (null triangle). */ 08744 /* IER = 4 if AREAS returns a value greater than */ 08745 /* AMAX (defined below). */ 08746 08747 /* Modules required by AREAV: AREAS, CIRCUM */ 08748 08749 /* *********************************************************** */ 08750 08751 08752 /* Maximum valid triangle area is less than 2*Pi: */ 08753 08754 /* Parameter adjustments */ 08755 --lend; 08756 --z__; 08757 --y; 08758 --x; 08759 --list; 08760 --lptr; 08761 08762 /* Function Body */ 08763 08764 /* Test for invalid input. */ 08765 08766 if (*k < 1 || *k > *n || *n <= 3) { 08767 goto L11; 08768 } 08769 08770 /* Initialization: Set N3 to the last neighbor of N1 = K. */ 08771 /* FIRST = TRUE only for the first triangle. */ 08772 /* The Voronoi region area is accumulated in ASUM. */ 08773 08774 n1 = *k; 08775 v1[0] = x[n1]; 08776 v1[1] = y[n1]; 08777 v1[2] = z__[n1]; 08778 lpl = lend[n1]; 08779 n3 = list[lpl]; 08780 if (n3 < 0) { 08781 goto L12; 08782 } 08783 lp = lpl; 08784 first = TRUE_; 08785 asum = 0.; 08786 08787 /* Loop on triangles (N1,N2,N3) containing N1 = K. */ 08788 08789 L1: 08790 n2 = n3; 08791 lp = lptr[lp]; 08792 n3 = list[lp]; 08793 v2[0] = x[n2]; 08794 v2[1] = y[n2]; 08795 v2[2] = z__[n2]; 08796 v3[0] = x[n3]; 08797 v3[1] = y[n3]; 08798 v3[2] = z__[n3]; 08799 if (first) { 08800 08801 /* First triangle: compute the circumcenter C3 and save a */ 08802 /* copy in C0. */ 08803 08804 circum_(v1, v2, v3, c3, &ierr); 08805 if (ierr != 0) { 08806 goto L13; 08807 } 08808 c0[0] = c3[0]; 08809 c0[1] = c3[1]; 08810 c0[2] = c3[2]; 08811 first = FALSE_; 08812 } else { 08813 08814 /* Set C2 to C3, compute the new circumcenter C3, and compute */ 08815 /* the area A of triangle (V1,C2,C3). */ 08816 08817 c2[0] = c3[0]; 08818 c2[1] = c3[1]; 08819 c2[2] = c3[2]; 08820 circum_(v1, v2, v3, c3, &ierr); 08821 if (ierr != 0) { 08822 goto L13; 08823 } 08824 a = areas_(v1, c2, c3); 08825 if (a > amax) { 08826 goto L14; 08827 } 08828 asum += a; 08829 } 08830 08831 /* Bottom on loop on neighbors of K. */ 08832 08833 if (lp != lpl) { 08834 goto L1; 08835 } 08836 08837 /* Compute the area of triangle (V1,C3,C0). */ 08838 08839 a = areas_(v1, c3, c0); 08840 if (a > amax) { 08841 goto L14; 08842 } 08843 asum += a; 08844 08845 /* No error encountered. */ 08846 08847 *ier = 0; 08848 ret_val = asum; 08849 return ret_val; 08850 08851 /* Invalid input. */ 08852 08853 L11: 08854 *ier = 1; 08855 ret_val = 0.; 08856 return ret_val; 08857 08858 /* K indexes a boundary node. */ 08859 08860 L12: 08861 *ier = 2; 08862 ret_val = 0.; 08863 return ret_val; 08864 08865 /* Error in CIRCUM. */ 08866 08867 L13: 08868 *ier = 3; 08869 ret_val = 0.; 08870 return ret_val; 08871 08872 /* AREAS value larger than AMAX. */ 08873 08874 L14: 08875 *ier = 4; 08876 ret_val = 0.; 08877 return ret_val; 08878 } /* 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 19607 of file util_sparx.cpp.
References t.
Referenced by image_mutation().
19607 { 19608 19609 if (is_mirror != 0) { 19610 for (int i=0; i<len_list; i++) { 19611 int r = rand()%10000; 19612 float f = r/10000.0f; 19613 if (f < mutation_rate) list[i] = 1-list[i]; 19614 } 19615 } else { 19616 map<int, vector<int> > graycode; 19617 map<vector<int>, int> rev_graycode; 19618 vector <int> gray; 19619 19620 int K=1; 19621 for (int i=0; i<L; i++) K*=2; 19622 19623 for (int k=0; k<K; k++) { 19624 int shift = 0; 19625 vector <int> gray; 19626 for (int i=L-1; i>-1; i--) { 19627 int t = ((k>>i)%2-shift)%2; 19628 gray.push_back(t); 19629 shift += t-2; 19630 } 19631 graycode[k] = gray; 19632 rev_graycode[gray] = k; 19633 } 19634 19635 float gap = (K-1)/(max_val-min_val); 19636 for (int i=0; i<len_list; i++) { 19637 float val = list[i]; 19638 if (val < min_val) { val = min_val; } 19639 else if (val > max_val) { val = max_val; } 19640 int k = int((val-min_val)*gap+0.5); 19641 vector<int> gray = graycode[k]; 19642 bool changed = false; 19643 for (vector<int>::iterator p=gray.begin(); p!=gray.end(); p++) { 19644 int r = rand()%10000; 19645 float f = r/10000.0f; 19646 if (f < mutation_rate) { 19647 *p = 1-*p; 19648 changed = true; 19649 } 19650 } 19651 if (changed) { 19652 k = rev_graycode[gray]; 19653 list[i] = k/gap+min_val; 19654 } 19655 } 19656 } 19657 19658 }
void Util::bb_enumerate_ | ( | int * | Parts, | |
int * | classDims, | |||
int | nParts, | |||
int | nClasses, | |||
int | T, | |||
int | n_guesses, | |||
int * | levels | |||
) | [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.
Turn the one dimensional Parts into vectors for easier manipulation While we're at it, construct Indices, an nParts*K int array storing the index (into argparts) of the first element of the i-th class of the j-th partition 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
will delete this soon.... use bb_enumerateMPI instead
Definition at line 19714 of file util_sparx.cpp.
References branch(), initial_prune(), and sanitycheck().
19714 { 19715 19716 int* Indices = new int[nParts*K]; 19717 // Make a vector of nParts vectors of K int* each 19718 vector <vector <int*> > Parts(nParts,vector<int*>(K)); 19719 int ind_c = 0; 19720 19721 for (int i=0; i < nParts; i++){ 19722 for(int j = 0; j < K; j++){ 19723 Parts[i][j]=argParts + ind_c; 19724 Indices[i*K + j] = ind_c; 19725 ind_c = ind_c + *(dimClasses+i*K + j); 19726 19727 } 19728 } 19729 19730 // make a copy of vector Parts for debugging purposes. 19731 // comment out if not debugging 19732 vector <vector <int*> > oldParts = Parts; 19733 19734 // in the following we call initial_prune with Parts which is a vector. This is not the most 19735 // efficient since vector does not allow for direct addressing. But since initial_prune doesn't have very high complexity, and 19736 // the running time for 7 partitions with 288 classes per partition is on the order of a couple of minutes at most, i'll just leave it for now..... 19737 Util::initial_prune(Parts, dimClasses, nParts, K,T); 19738 //********************************************************************************************************************************************** 19739 19740 // figure out the partition with the smallest number of classes. that will be the MAXIMUM number of matches we can find 19741 int numLevels = Parts[0].size();// initialize to number of classes in the first partition 19742 for (int i=1; i < nParts; i++){ 19743 if (Parts[i].size() < numLevels) numLevels = Parts[i].size(); 19744 } 19745 19746 // To maintain feasibility there can be at most 19747 // numLevel matches in the optimal solution. 19748 19749 // int* Levels = new int[numLevels]; // Levels[i] corresponds to the number of possibilities we consider for the i-th match, and this 19750 // determines how many branches occur at that level. 19751 // numLevels is at most K. Since Levels is pre-allocated in python code with K elements, it should be fine. 19752 //for(int i =0; i < numLevels; i++) 19753 // Levels[i] = 1; 19754 // modify argParts so the dummy variable of each class is set to 1 if the class is not removed by initial_prune, and -1 otherwise. 19755 // since the branch function is extremely computationally intensive, we have to pass it argParts (the 1-dimensional array) instead 19756 // of the vector Parts (which doesn't allow for direct access). 19757 19758 // Indices[i*K + j] is the number of offsets from the beginning of argParts of the first element of the j-th class of hte i-th partition 19759 19760 for(int i = 0; i < nParts; i++){ 19761 for(int j=0; j < K; j++){ 19762 *(argParts + Indices[i*K + j]+1) = -1; 19763 } 19764 } 19765 19766 int num_classes; 19767 int old_index; 19768 for(int i=0; i<nParts; i++){ 19769 num_classes = Parts[i].size();// number of classes in partition i after pruning 19770 //cout<<"num_classes: "<< num_classes<<"\n"; 19771 for (int j=0; j < num_classes; j++){ 19772 old_index = *(Parts[i][j]); 19773 //cout << "old_index: " << old_index<<"\n"; 19774 *(argParts + Indices[i*K + old_index]+1) = 1; 19775 } 19776 } 19777 19778 // 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 19779 // and the rest is the list of matches 19780 // in one dimensional form. 19781 cout <<"begin partition matching\n"; 19782 int* output = Util::branch(argParts, Indices,dimClasses, nParts, K, T,Levels, numLevels,0,n_guesses); 19783 cout <<"done with partition matching \n"; 19784 cout<<"total cost: "<<*output<<"\n"; 19785 cout<<"number of matches: "<<*(output+1)<<"\n"; 19786 // 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 19787 bool correct = Util::sanitycheck(argParts, Indices,dimClasses, nParts, K, T,output); 19788 }
vector< int > Util::bb_enumerateMPI_ | ( | int * | argParts, | |
int * | dimClasses, | |||
int | nParts, | |||
int | K, | |||
int | T, | |||
int | nTop, | |||
int | n_guesses, | |||
bool | doMPI, | |||
int * | Levels | |||
) | [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 20350 of file util_sparx.cpp.
References branchMPI(), findTopLargest(), initial_prune(), and sanitycheck().
20350 { 20351 20352 // 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 20353 // 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 20354 // Make a vector of nParts vectors of K int* each 20355 int* Indices = new int[nParts*K]; 20356 int ind_c = 0; 20357 for (int i=0; i < nParts; i++){ 20358 for(int j = 0; j < K; j++){ 20359 Indices[i*K + j] = ind_c; 20360 ind_c = ind_c + *(dimClasses+i*K + j); 20361 20362 } 20363 } 20364 20365 // return top weighted matches for mpi version 20366 if (nTop > 0 && doMPI > 0){ 20367 // find the nTop largest matches (not required to be mutually feasible) 20368 int* matchlist = new int[nTop*nParts]; 20369 int* costlist=new int[nTop]; 20370 for (int i=0; i< nTop; i++) {*(costlist+i) = 0;} 20371 int matchesFound = Util::findTopLargest(argParts,Indices, dimClasses, nParts, K, T, matchlist, nTop,costlist,n_guesses); 20372 vector<int> ret(nTop*(nParts+1) + 1); 20373 ret[0] = matchesFound; 20374 int m = nParts + 1; 20375 // For each match in matchlist and its corresponding cost in costlist, put them in ret 20376 for(int i=0; i < nTop; i++){ 20377 ret[1+i*m] = *(costlist+i); 20378 for (int j=0; j < nParts; j++){ 20379 ret[1+i*m + 1 + j] = matchlist[i*nParts + j]; 20380 } 20381 } 20382 20383 return ret; 20384 20385 } 20386 20387 // do initial pruning on argParts and return the pruned partitions 20388 20389 // Make a vector of nParts vectors of K int* each 20390 vector <vector <int*> > Parts(nParts,vector<int*>(K)); 20391 ind_c = 0; 20392 int argParts_size=0; 20393 for (int i=0; i < nParts; i++){ 20394 for(int j = 0; j < K; j++){ 20395 Parts[i][j]=argParts + ind_c; 20396 ind_c = ind_c + *(dimClasses+i*K + j); 20397 argParts_size = argParts_size + *(dimClasses+i*K + j); 20398 20399 } 20400 } 20401 20402 // in the following we call initial_prune with Parts which is a vector. This is not the most 20403 // efficient since vector does not allow for direct addressing. But since initial_prune doesn't have very high complexity, and 20404 // 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..... 20405 20406 Util::initial_prune(Parts, dimClasses, nParts, K,T); 20407 for(int i = 0; i < nParts; i++){ 20408 for(int j=0; j < K; j++){ 20409 *(argParts + Indices[i*K + j]+1) = -1; 20410 } 20411 } 20412 20413 int num_classes; 20414 int old_index; 20415 for(int i=0; i<nParts; i++){ 20416 num_classes = Parts[i].size();// number of classes in partition i after pruning 20417 for (int j=0; j < num_classes; j++){ 20418 old_index = *(Parts[i][j]); 20419 //cout << "old_index: " << old_index<<"\n"; 20420 *(argParts + Indices[i*K + old_index]+1) = 1; 20421 } 20422 } 20423 20424 20425 if (doMPI > 0){ 20426 // turn argParts into vector ret and return ret 20427 vector<int> ret(argParts_size); 20428 for(int i=0; i < argParts_size; i++) 20429 ret[i]= (*(argParts+i)); 20430 20431 return ret; 20432 } 20433 20434 // if we're not doing mpi then keep going and call branchMPI and return the output 20435 //cout <<"begin partition matching\n"; 20436 int* dummy; 20437 int* output = Util::branchMPI(argParts, Indices,dimClasses, nParts, K, T,Levels, K,0,n_guesses,-1, dummy); 20438 //cout <<"done with partition matching \n"; 20439 //cout<<"total cost: "<<*output<<"\n"; 20440 //cout<<"number of matches: "<<*(output+1)<<"\n"; 20441 // 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 20442 bool correct = Util::sanitycheck(argParts, Indices,dimClasses, nParts, K, T,output); 20443 20444 // something is wrong with output of branchMPI! 20445 if (correct < 1){ 20446 cout << "something is wrong with output of branchMPI!\n"; 20447 vector<int> ret(1); 20448 ret[0]=-1; 20449 return ret; 20450 } 20451 20452 // output is not nonsense, so now put it into a single dimension vector and return 20453 // 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 20454 // and the rest is the list of matches. output is one dimensional 20455 20456 int output_size = 2+ *(output+1) * nParts; 20457 vector<int> ret(output_size); 20458 for (int i = 0; i < output_size; i++){ 20459 ret[i]=*(output+i); 20460 } 20461 return ret; 20462 20463 }
float Util::bilinear | ( | float | xold, | |
float | yold, | |||
int | nsam, | |||
int | nrow, | |||
float * | xim | |||
) | [static] |
Definition at line 2311 of file util_sparx.cpp.
References xim.
02312 { 02313 /* 02314 c purpose: linear interpolation 02315 Optimized for speed, circular closer removed, checking of ranges removed 02316 */ 02317 float bilinear; 02318 int ixold, iyold; 02319 02320 /* 02321 float xdif, ydif, xrem, yrem; 02322 ixold = (int) floor(xold); 02323 iyold = (int) floor(yold); 02324 ydif = yold - iyold; 02325 yrem = 1.0f - ydif; 02326 02327 // May want to insert if? 02328 // IF ((IYOLD .GE. 1 .AND. IYOLD .LE. NROW-1) .AND. 02329 // & (IXOLD .GE. 1 .AND. IXOLD .LE. NSAM-1)) THEN 02330 //c INSIDE BOUNDARIES OF OUTPUT IMAGE 02331 xdif = xold - ixold; 02332 xrem = 1.0f- xdif; 02333 // RBUF(K) = YDIF*(BUF(NADDR+NSAM)*XREM 02334 // & +BUF(NADDR+NSAM+1)*XDIF) 02335 // & +YREM*(BUF(NADDR)*XREM + BUF(NADDR+1)*XDIF) 02336 bilinear = ydif*(xim(ixold,iyold+1)*xrem + xim(ixold+1,iyold+1)*xdif) + 02337 yrem*(xim(ixold,iyold)*xrem+xim(ixold+1,iyold)*xdif); 02338 02339 return bilinear; 02340 } 02341 */ 02342 float xdif, ydif; 02343 02344 ixold = (int) xold; 02345 iyold = (int) yold; 02346 ydif = yold - iyold; 02347 02348 // May want to insert it? 02349 // IF ((IYOLD .GE. 1 .AND. IYOLD .LE. NROW-1) .AND. 02350 // & (IXOLD .GE. 1 .AND. IXOLD .LE. NSAM-1)) THEN 02351 //c INSIDE BOUNDARIES OF OUTPUT IMAGE 02352 xdif = xold - ixold; 02353 bilinear = xim(ixold, iyold) + ydif* (xim(ixold, iyold+1) - xim(ixold, iyold)) + 02354 xdif* (xim(ixold+1, iyold) - xim(ixold, iyold) + 02355 ydif* (xim(ixold+1, iyold+1) - xim(ixold+1, iyold) - xim(ixold, iyold+1) + xim(ixold, iyold)) ); 02356 02357 return bilinear; 02358 }
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 1473 of file util.h.
Referenced by EMAN::EMData::common_lines(), EMAN::EMData::cut_slice(), EMAN::StandardProjector::project3d(), EMAN::EMData::rotate_translate(), EMAN::EMData::sget_value_at_interp(), EMAN::TransformProcessor::transform(), and EMAN::EMData::unwrap().
Definition at line 5644 of file util_sparx.cpp.
References B, CUBE, DM, and t.
05645 { 05646 05647 float *Bptr = B->get_data(); 05648 float *CUBEptr = CUBE->get_data(); 05649 05650 int NSAM,NROW,NX3D,NY3D,NZC,KZ,IQX,IQY,LDPX,LDPY,LDPZ,LDPNMX,LDPNMY,NZ1; 05651 float DIPX,DIPY,XB,YB,XBB,YBB; 05652 05653 Transform * t = B->get_attr("xform.projection"); 05654 Dict d = t->get_params("spider"); 05655 if(t) {delete t; t=0;} 05656 // Unsure about sign of shifts, check later PAP 06/28/09 05657 float x_shift = d[ "tx" ]; 05658 float y_shift = d[ "ty" ]; 05659 x_shift = -x_shift; 05660 y_shift = -y_shift; 05661 05662 NSAM = B->get_xsize(); 05663 NROW = B->get_ysize(); 05664 NX3D = CUBE->get_xsize(); 05665 NY3D = CUBE->get_ysize(); 05666 NZC = CUBE->get_zsize(); 05667 05668 05669 LDPX = NX3D/2 +1; 05670 LDPY = NY3D/2 +1; 05671 LDPZ = NZC/2 +1; 05672 LDPNMX = NSAM/2 +1; 05673 LDPNMY = NROW/2 +1; 05674 NZ1 = 1; 05675 05676 for(int K=1;K<=NZC;K++) { 05677 KZ=K-1+NZ1; 05678 for(int J=1;J<=NY3D;J++) { 05679 XBB = (1-LDPX)*DM(1)+(J-LDPY)*DM(2)+(KZ-LDPZ)*DM(3); 05680 YBB = (1-LDPX)*DM(4)+(J-LDPY)*DM(5)+(KZ-LDPZ)*DM(6); 05681 for(int I=1;I<=NX3D;I++) { 05682 XB = (I-1)*DM(1)+XBB-x_shift; 05683 IQX = int(XB+float(LDPNMX)); 05684 if (IQX <1 || IQX >= NSAM) continue; 05685 YB = (I-1)*DM(4)+YBB-y_shift; 05686 IQY = int(YB+float(LDPNMY)); 05687 if (IQY<1 || IQY>=NROW) continue; 05688 DIPX = XB+LDPNMX-IQX; 05689 DIPY = YB+LDPNMY-IQY; 05690 05691 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))); 05692 } 05693 } 05694 } 05695 }
int * Util::branch | ( | int * | argParts, | |
int * | Indices, | |||
int * | dimClasses, | |||
int | nParts, | |||
int | K, | |||
int | T, | |||
int * | Levels, | |||
int | nLevels, | |||
int | curlevel, | |||
int | n_guesses | |||
) | [static] |
Definition at line 19839 of file util_sparx.cpp.
References branch(), and findTopLargest().
19839 { 19840 // Base Case: we're at a leaf, no more feasible matches possible 19841 19842 if (curlevel > nLevels-1){ 19843 int* res = new int[2]; 19844 *res = 0; 19845 *(res+1)=0; 19846 return res; 19847 } 19848 19849 // We may still find more feasible matchings with cost gt T, so explore level curlevel 19850 int nBranches = *(Levels + curlevel); 19851 19852 // call findTopLargest to get the nBranches feasible matchings with the largest weight (gt T) over all other feasible matches 19853 // matchlist is in one dimensional array form...... 19854 19855 int* matchlist = new int[nBranches*nParts]; 19856 int* costlist = new int[nBranches];// cost of each of the nBranches matches. If cost[i] < T then that means findTopLargest found less than i+1 matches 19857 // with cost > T 19858 19859 // initialize elements of costlist to 0 19860 for (int i=0; i < nBranches; i++) *(costlist+i)=0; 19861 19862 // each class in the matches found by findTopLargest is encoded by the original index of the first element of the class in argPart 19863 // each match contains nParts classes, with the i-th class belonging to the i-th partition. 19864 19865 Util::findTopLargest(argParts,Indices, dimClasses, nParts, K, T, matchlist, nBranches,costlist,n_guesses); 19866 19867 // if there are no feasible matches with cost gt T, then return 0 19868 if (costlist[0]<= T){ 19869 int* res = new int[2]; 19870 *res = 0; 19871 *(res+1)=0; 19872 return res; 19873 } 19874 19875 int* maxreturn = new int[2];//initialize to placeholder 19876 *maxreturn=0; 19877 *(maxreturn+1)=0; 19878 19879 // some temporary variables 19880 int old_index; 19881 int totalcost; 19882 int nmatches; 19883 //int offset; 19884 19885 for(int i=0; i < nBranches ; i++){ 19886 19887 // consider the i-th match returned by findTopLargest 19888 19889 if (costlist[i] <= T) break; 19890 19891 // 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. 19892 // After branch returns, compute overall cost, unmark the classes just marked as 1 again in preparation for next loop. 19893 19894 for(int j=0; j < nParts; j++){ 19895 // matchlist[i*nParts + j] is the original index of the class belonging to the j-th partition in the i-th match. 19896 old_index=matchlist[i*nParts + j]; 19897 *(argParts + Indices[j*K+old_index] + 1) = -2; 19898 } 19899 19900 19901 int* ret = Util::branch(argParts, Indices, dimClasses, nParts, K, T, Levels, nLevels, curlevel+1,n_guesses); 19902 19903 // first element of ret is the total cost of all the matches in ret, and second element is the number of matches in ret 19904 totalcost = costlist[i] + *ret; 19905 19906 // ************************************************************************************* 19907 // for debugging purposes 19908 19909 // debug 1: for multi-branching in levels i less some pre-specified maxLevel. Assume maxLevel is pretty small else way too many print outs to be useful 19910 bool debug1 = 0; 19911 if (debug1){ 19912 int maxLevel = 2; 19913 if (curlevel < maxLevel) cout<<"total cost level" << curlevel<<": "<<totalcost<<"\n"; 19914 } 19915 19916 // debug 2: for multi-branching in ALL (or many ...) levels. This is data specific so it's all hard coded 19917 bool debug2 = 0; 19918 if (debug2){ 19919 int skip1 = 5; 19920 int max1=20; 19921 if ((curlevel <= max1) && (curlevel%skip1 == 0)) cout << "total cost level "<< curlevel<<": "<<totalcost<<"\n"; 19922 19923 int skip2 = 10; 19924 int max2 = 70; 19925 if ((curlevel > max1 )&&(curlevel <= max2) && (curlevel%skip2 == 0)) cout << "total cost level "<< curlevel<<": "<<totalcost<<"\n"; 19926 } 19927 // ************************************************************************************* 19928 19929 19930 // if totalcost > maxcost, or some variatio thereof, then copy the stuff over to maxreturn. 19931 // There are several possibilities here: 19932 // Option 1: Simply compare costs and take the largest one. 19933 // Option 2: At each level, if two costs are equal, then take the one which contains fewer matches, and thus 19934 // ensuring matches with larger weights. The motivation for this is largely the (possibly naive) assumption that 19935 // if we take the average of a larger number of images, then the averaged image will be "better". 19936 // Option 3: Do option 2 only on the highest level, i.e., curlevel=0 19937 19938 if (totalcost > *maxreturn) // option 1 19939 // if ((totalcost > *maxreturn) || ( (curlevel==0) && (totalcost == *maxreturn) && (*(ret+1)+1 < *(maxreturn+1)) )) // option 3 19940 19941 //if ((totalcost > *maxreturn) || ( (totalcost == *maxreturn) && (*(ret+1)+1 < *(maxreturn+1)) )) // option 2 19942 { 19943 nmatches = 1 + *(ret+1); 19944 delete[] maxreturn; // get rid of the old maxreturn 19945 maxreturn = new int[2+nmatches*nParts]; 19946 *maxreturn = totalcost; 19947 *(maxreturn + 1)= nmatches; 19948 int nret = 2+(nmatches-1)*nParts; 19949 for(int iret=2; iret <nret;iret++) *(maxreturn+iret)=*(ret+iret); 19950 for(int imax=0; imax<nParts;imax++) *(maxreturn+nret+imax)=matchlist[i*nParts + imax]; 19951 } 19952 19953 19954 delete[] ret; 19955 19956 // unmark the marked classes in preparation for the next iteration 19957 19958 for(int j=0; j < nParts; j++){ 19959 // matchlist[i*nParts + j] is the original index of the class belonging to the j-th partition in the i-th match. 19960 old_index=matchlist[i*nParts + j]; 19961 *(argParts + Indices[j*K+old_index] + 1) = 1; 19962 } 19963 19964 } 19965 19966 delete[] matchlist; 19967 delete[] costlist; 19968 return maxreturn; 19969 19970 }
int * Util::branchMPI | ( | int * | argParts, | |
int * | Indices, | |||
int * | dimClasses, | |||
int | nParts, | |||
int | K, | |||
int | T, | |||
int * | Levels, | |||
int | nLevels, | |||
int | curlevel, | |||
int | n_guesses, | |||
int | nFirst, | |||
int * | firstmatches | |||
) | [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 20519 of file util_sparx.cpp.
References branchMPI(), and findTopLargest().
20519 { 20520 20521 // Base Case: we're at a leaf, no more feasible matches possible 20522 if (curlevel > nLevels-1){ 20523 int* res = new int[2]; 20524 *res = 0; 20525 *(res+1)=0; 20526 return res; 20527 } 20528 20529 20530 // We may still find more feasible matchings with cost gt T, so explore level curlevel 20531 int nBranches = *(Levels + curlevel); 20532 20533 // MPI: the first match is already chosen in MPI version, so we are going to branch only once at level 0 20534 if (curlevel==0 && nFirst > 0) 20535 { 20536 nBranches = nFirst; 20537 } 20538 20539 // call findTopLargest to get the nBranches feasible matchings with the largest weight (gt T) over all other feasible matches 20540 20541 int* matchlist = new int[nBranches*nParts]; 20542 int* costlist = new int[nBranches];// cost of each of the nBranches matches. If cost[i] < T then that means findTopLargest found less than i+1 matches 20543 // with cost > T 20544 20545 for (int i=0; i < nBranches; i++) 20546 *(costlist+i)=0; 20547 20548 // each class in the matches found by findTopLargest is encoded by the original index of the first element of the class in argPart 20549 // each match contains nParts classes, with the i-th class belonging to the i-th partition. 20550 20551 // MPI: first match is already chosen, so copy the match in first match over to matchlist, compute weight of match, and set costlist to the weight 20552 if (curlevel == 0 && nFirst > 0){ 20553 for(int i = 0; i < nBranches; i++){ 20554 *(costlist+i) = *(firstmatches +i*(nParts+1)); 20555 for (int j=0; j< nParts; j++) 20556 *(matchlist + i*nParts +j) = *(firstmatches +i*(nParts+1) + 1 + j); 20557 } 20558 } 20559 else 20560 Util::findTopLargest(argParts,Indices, dimClasses, nParts, K, T, matchlist, nBranches,costlist,n_guesses); 20561 20562 // if there are no feasible matches with cost gt T, then return 0 20563 if (costlist[0]<= T){ 20564 int* res = new int[2]; 20565 *res = 0; 20566 *(res+1)=0; 20567 return res; 20568 } 20569 20570 int* maxreturn = new int[2];//initialize to placeholder 20571 *maxreturn=0; 20572 *(maxreturn+1)=0; 20573 20574 // some temporary variables 20575 int old_index; 20576 int totalcost; 20577 int nmatches; 20578 //int offset; 20579 20580 for(int i=0; i < nBranches ; i++){ 20581 20582 // consider the i-th match returned by findTopLargest 20583 20584 if (costlist[i] <= T) break; 20585 20586 // 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. 20587 // After branch returns, compute overall cost, unmark the classes just marked as 1 again in preparation for next loop. 20588 20589 for(int j=0; j < nParts; j++){ 20590 // matchlist[i*nParts + j] is the original index of the class belonging to the j-th partition in the i-th match. 20591 old_index=matchlist[i*nParts + j]; 20592 *(argParts + Indices[j*K+old_index] + 1) = -2; 20593 } 20594 20595 20596 int* ret = Util::branchMPI(argParts, Indices, dimClasses, nParts, K, T, Levels, nLevels, curlevel+1,n_guesses, nFirst, firstmatches); 20597 20598 // first element of ret is the total cost of all the matches in ret, and second element is the number of matches in ret 20599 totalcost = costlist[i] + *ret; 20600 20601 20602 if (totalcost > *maxreturn) // option 1 20603 { 20604 nmatches = 1 + *(ret+1); 20605 delete[] maxreturn; // get rid of the old maxreturn 20606 maxreturn = new int[2+nmatches*nParts]; 20607 *maxreturn = totalcost; 20608 *(maxreturn + 1)= nmatches; 20609 int nret = 2+(nmatches-1)*nParts; 20610 for(int iret=2; iret <nret;iret++) *(maxreturn+iret)=*(ret+iret); 20611 for(int imax=0; imax<nParts;imax++) *(maxreturn+nret+imax)=matchlist[i*nParts + imax]; 20612 } 20613 20614 20615 delete[] ret; 20616 20617 // unmark the marked classes in preparation for the next iteration 20618 20619 for(int j=0; j < nParts; j++){ 20620 // matchlist[i*nParts + j] is the original index of the class belonging to the j-th partition in the i-th match. 20621 old_index=matchlist[i*nParts + j]; 20622 *(argParts + Indices[j*K+old_index] + 1) = 1; 20623 } 20624 20625 } 20626 20627 delete[] matchlist; 20628 delete[] costlist; 20629 20630 return maxreturn; 20631 20632 }
vector< int > Util::branchMPIpy_ | ( | int * | argParts, | |
int * | dimClasses, | |||
int | nParts, | |||
int | K, | |||
int | T, | |||
int * | Levels, | |||
int | nLevels, | |||
int | n_guesses, | |||
int | nFirst, | |||
int * | firstmatches | |||
) | [static] |
an interface function between python code and branchMPI.
Doesn't do much except compute Indices, call branchMPI, and check if the output make sense (i.e., feasible etc), and process the output to return to python as a vector. nFirst is the number of matches in firstmatches
Definition at line 20465 of file util_sparx.cpp.
References branchMPI(), and sanitycheck().
20465 { 20466 //cout<<"branchMPIpy_ called\n"; 20467 // if nLevels == K, then we compute nLevels - which is the number of active classes of the partition with the smallest number of active classes 20468 // this is not really necessary but would save a call to findTopLargest in branchMPI 20469 int num_active; 20470 int* Indices = new int[nParts*K]; 20471 // Make a vector of nParts vectors of K int* each 20472 int ind_c = 0; 20473 for (int i=0; i < nParts; i++){ 20474 num_active = 0; 20475 for(int j = 0; j < K; j++){ 20476 Indices[i*K + j] = ind_c; // offset from argParts of the first element of the jth class of the i-th partition 20477 if (*(argParts+ind_c + 1) == 1) num_active = num_active + 1; 20478 ind_c = ind_c + *(dimClasses+i*K + j); 20479 } 20480 20481 if (num_active < nLevels) {nLevels = num_active;} 20482 } 20483 20484 20485 //add in code for dynamically changing levels 20486 20487 //cout<<"num levels "<<nLevels<<"\n"; 20488 //cout<<"calling branchMPI\n"; 20489 20490 int* output = Util::branchMPI(argParts, Indices, dimClasses, nParts, K, T, Levels, nLevels, 0,n_guesses, nFirst,firstmatches); 20491 20492 // call sanity check on outupt to make sure the returned matches are feasible with cost over the threshold T 20493 //cout<<"total cost: "<<*output<<"\n"; 20494 //cout<<"number of matches: "<<*(output+1)<<"\n"; 20495 // 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 20496 bool correct = Util::sanitycheck(argParts, Indices,dimClasses, nParts, K, T,output); 20497 20498 // something is wrong with output of branchMPI! 20499 if (correct < 1){ 20500 cout << "something is wrong with output of branchMPI!\n"; 20501 vector<int> ret(1); 20502 ret[0]=-1; 20503 return ret; 20504 } 20505 20506 // output is not nonsense, so now put it into a single dimension vector and return 20507 // 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 20508 // and the rest is the list of matches. output is one dimensional 20509 20510 int output_size = 2+ *(output+1) * nParts; 20511 vector<int> ret(output_size); 20512 for (int i = 0; i < output_size; i++){ 20513 ret[i]=*(output+i); 20514 } 20515 return ret; 20516 }
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 982 of file util.cpp.
References Assert, and LOGERR.
Referenced by EMAN::RTFExhaustiveAligner::align(), EMAN::RotatePrecenterAligner::align(), and EMAN::EMData::unwrap_largerR().
00983 { 00984 Assert(low >= 0); 00985 00986 //array containing valid sizes <1024 for speed 00987 static char *valid = NULL; 00988 00989 if (!valid) { 00990 valid = (char *) calloc(4096, 1); 00991 00992 for (float i2 = 1; i2 < 12.0; i2 += 1.0) { 00993 00994 float f1 = pow((float) 2.0, i2); 00995 for (float i3 = 0; i3 < 8.0; i3 += 1.0) { 00996 00997 float f2 = pow((float) 3.0, i3); 00998 for (float i5 = 0; i5 < 6.0; i5 += 1.0) { 00999 01000 float f3 = pow((float) 5.0, i5); 01001 for (float i7 = 0; i7 < 5.0; i7 += 1.0) { 01002 01003 float f = f1 * f2 * f3 * pow((float) 7.0, i7); 01004 if (f <= 4095.0) { 01005 int n = (int) f; 01006 valid[n] = 1; 01007 } 01008 } 01009 } 01010 } 01011 } 01012 } 01013 01014 for (int i = low; i < 4096; i++) { 01015 if (valid[i]) { 01016 return i; 01017 } 01018 } 01019 01020 LOGERR("Sorry, can only find good fft sizes up to 4096 right now."); 01021 01022 return 1; 01023 }
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 6224 of file util_sparx.cpp.
References lsfit().
06225 { 06226 long int q2_dim1, q2_offset, q_dim1, q_offset, i__1, i__2; 06227 float r__1; 06228 int tmp__i; 06229 long int i__, j; 06230 --s; 06231 --res; 06232 iu -= 3; 06233 cu -= 3; 06234 --x; 06235 long int klm2d; 06236 klm2d= *k+*k+2; 06237 klm2d=klm2d+klm2d; 06238 q_dim1 = klm2d; 06239 q_offset = 1 + q_dim1; 06240 q -= q_offset; 06241 q2_dim1 = klm2d; 06242 q2_offset = 1 + q2_dim1; 06243 q2 -= q2_offset; 06244 i__2=0; 06245 i__1 = *n - 1; 06246 tmp__i=0; 06247 for (j = 1; j <= i__1; ++j) { 06248 i__2 = *k; 06249 tmp__i+=1; 06250 for (i__ = 1; i__ <= i__2; ++i__) { 06251 r__1 = float(i__ - 1) /(float) *k / (*ps * 2); 06252 q2[i__ + j * q2_dim1] = pow(r__1, tmp__i); 06253 } 06254 } 06255 for (i__ = 1; i__ <= i__2; ++i__) 06256 { q2[i__ + *n * q2_dim1] = 1.f; 06257 q2[i__ + (*n + 1) * q2_dim1] = pw[i__-1]; 06258 } 06259 vector<float> fit_res; 06260 fit_res=Util::lsfit(k, n, &klm2d, iswi, &q2[q2_offset], &q[q_offset], &x[1], &res[1], &cu[3], &s[1], &iu[3]); 06261 return fit_res; 06262 }
Dict Util::CANG | ( | float | PHI, | |
float | THETA, | |||
float | PSI | |||
) | [static] |
Definition at line 5596 of file util_sparx.cpp.
References DGR_TO_RAD, DM, and SS.
05597 { 05598 double CPHI,SPHI,CTHE,STHE,CPSI,SPSI; 05599 vector<float> DM,SS; 05600 05601 for(int i =0;i<9;i++) DM.push_back(0); 05602 05603 for(int i =0;i<6;i++) SS.push_back(0); 05604 05605 CPHI = cos(double(PHI)*DGR_TO_RAD); 05606 SPHI = sin(double(PHI)*DGR_TO_RAD); 05607 CTHE = cos(double(THETA)*DGR_TO_RAD); 05608 STHE = sin(double(THETA)*DGR_TO_RAD); 05609 CPSI = cos(double(PSI)*DGR_TO_RAD); 05610 SPSI = sin(double(PSI)*DGR_TO_RAD); 05611 05612 SS(1) = float(CPHI); 05613 SS(2) = float(SPHI); 05614 SS(3) = float(CTHE); 05615 SS(4) = float(STHE); 05616 SS(5) = float(CPSI); 05617 SS(6) = float(SPSI); 05618 05619 DM(1) = float(CPHI*CTHE*CPSI-SPHI*SPSI); 05620 DM(2) = float(SPHI*CTHE*CPSI+CPHI*SPSI); 05621 DM(3) = float(-STHE*CPSI); 05622 DM(4) = float(-CPHI*CTHE*SPSI-SPHI*CPSI); 05623 DM(5) = float(-SPHI*CTHE*SPSI+CPHI*CPSI); 05624 DM(6) = float(STHE*SPSI); 05625 DM(7) = float(STHE*CPHI); 05626 DM(8) = float(STHE*SPHI); 05627 DM(9) = float(CTHE); 05628 05629 Dict DMnSS; 05630 DMnSS["DM"] = DM; 05631 DMnSS["SS"] = SS; 05632 05633 return(DMnSS); 05634 }
Definition at line 18786 of file util_sparx.cpp.
References EMAN::EMData::cmp(), and EMAN::EMData::rot_scale_trans2D().
Referenced by twoD_fine_ali_SD().
18786 { 18787 18788 EMData *rot= new EMData(); 18789 float ccc; 18790 18791 rot = image->rot_scale_trans2D(ang, sx, sy, 1.0); 18792 ccc = -rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 18793 delete rot; 18794 return ccc; 18795 }
float Util::ccc_images_G | ( | EMData * | image, | |
EMData * | refim, | |||
EMData * | mask, | |||
Util::KaiserBessel & | kb, | |||
float | ang, | |||
float | sx, | |||
float | sy | |||
) | [static] |
Definition at line 18823 of file util_sparx.cpp.
References EMAN::EMData::cmp(), pi, and EMAN::EMData::rot_scale_conv7().
Referenced by twoD_fine_ali_SD_G().
18823 { 18824 18825 EMData *rot= new EMData(); 18826 float ccc; 18827 18828 rot = image->rot_scale_conv7(static_cast<float>(ang*pi/180.0), sx, sy, kb, 1.0f); 18829 ccc = -rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 18830 delete rot; 18831 return ccc; 18832 }
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 6409 of file util_sparx.cpp.
06411 { 06412 06413 long int q_dim1, q_offset, i__1, i__2; 06414 double d__1; 06415 06416 static long int i__, j; 06417 static double z__; 06418 static long int n1, n2, ia, ii, kk, in, nk, js; 06419 static double sn, zu, zv; 06420 static long int nk1, klm, nkl, jmn, jpn; 06421 static double cuv; 06422 static long int klm1, nkl1, klm2, kode, iimn, nklm, iter; 06423 static float xmin; 06424 static double xmax; 06425 static long int iout; 06426 static double xsum; 06427 static long int iineg, maxit; 06428 static double toler; 06429 static float error; 06430 static double pivot; 06431 static long int kforce, iphase; 06432 static double tpivot; 06433 06434 --s; 06435 --res; 06436 iu -= 3; 06437 cu -= 3; 06438 --x; 06439 q_dim1 = *klm2d; 06440 q_offset = 1 + q_dim1; 06441 q -= q_offset; 06442 06443 /* Function Body */ 06444 maxit = 500; 06445 kode = 0; 06446 toler = 1e-4f; 06447 iter = 0; 06448 n1 = *n + 1; 06449 n2 = *n + 2; 06450 nk = *n + *k; 06451 nk1 = nk + 1; 06452 nkl = nk + *l; 06453 nkl1 = nkl + 1; 06454 klm = *k + *l + *m; 06455 klm1 = klm + 1; 06456 klm2 = klm + 2; 06457 nklm = *n + klm; 06458 kforce = 1; 06459 iter = 0; 06460 js = 1; 06461 ia = 0; 06462 /* SET UP LABELS IN Q. */ 06463 i__1 = *n; 06464 for (j = 1; j <= i__1; ++j) { 06465 q[klm2 + j * q_dim1] = (double) j; 06466 /* L10: */ 06467 } 06468 i__1 = klm; 06469 for (i__ = 1; i__ <= i__1; ++i__) { 06470 q[i__ + n2 * q_dim1] = (double) (*n + i__); 06471 if (q[i__ + n1 * q_dim1] >= 0.f) { 06472 goto L30; 06473 } 06474 i__2 = n2; 06475 for (j = 1; j <= i__2; ++j) { 06476 q[i__ + j * q_dim1] = -q[i__ + j * q_dim1]; 06477 /* L20: */ 06478 } 06479 L30: 06480 ; 06481 } 06482 /* SET UP PHASE 1 COSTS. */ 06483 iphase = 2; 06484 i__1 = nklm; 06485 for (j = 1; j <= i__1; ++j) { 06486 cu[(j << 1) + 1] = 0.f; 06487 cu[(j << 1) + 2] = 0.f; 06488 iu[(j << 1) + 1] = 0; 06489 iu[(j << 1) + 2] = 0; 06490 /* L40: */ 06491 } 06492 if (*l == 0) { 06493 goto L60; 06494 } 06495 i__1 = nkl; 06496 for (j = nk1; j <= i__1; ++j) { 06497 cu[(j << 1) + 1] = 1.f; 06498 cu[(j << 1) + 2] = 1.f; 06499 iu[(j << 1) + 1] = 1; 06500 iu[(j << 1) + 2] = 1; 06501 /* L50: */ 06502 } 06503 iphase = 1; 06504 L60: 06505 if (*m == 0) { 06506 goto L80; 06507 } 06508 i__1 = nklm; 06509 for (j = nkl1; j <= i__1; ++j) { 06510 cu[(j << 1) + 2] = 1.f; 06511 iu[(j << 1) + 2] = 1; 06512 jmn = j - *n; 06513 if (q[jmn + n2 * q_dim1] < 0.f) { 06514 iphase = 1; 06515 } 06516 /* L70: */ 06517 } 06518 L80: 06519 if (kode == 0) { 06520 goto L150; 06521 } 06522 i__1 = *n; 06523 for (j = 1; j <= i__1; ++j) { 06524 if ((d__1 = x[j]) < 0.) { 06525 goto L90; 06526 } else if (d__1 == 0) { 06527 goto L110; 06528 } else { 06529 goto L100; 06530 } 06531 L90: 06532 cu[(j << 1) + 1] = 1.f; 06533 iu[(j << 1) + 1] = 1; 06534 goto L110; 06535 L100: 06536 cu[(j << 1) + 2] = 1.f; 06537 iu[(j << 1) + 2] = 1; 06538 L110: 06539 ; 06540 } 06541 i__1 = *k; 06542 for (j = 1; j <= i__1; ++j) { 06543 jpn = j + *n; 06544 if ((d__1 = res[j]) < 0.) { 06545 goto L120; 06546 } else if (d__1 == 0) { 06547 goto L140; 06548 } else { 06549 goto L130; 06550 } 06551 L120: 06552 cu[(jpn << 1) + 1] = 1.f; 06553 iu[(jpn << 1) + 1] = 1; 06554 if (q[j + n2 * q_dim1] > 0.f) { 06555 iphase = 1; 06556 } 06557 goto L140; 06558 L130: 06559 cu[(jpn << 1) + 2] = 1.f; 06560 iu[(jpn << 1) + 2] = 1; 06561 if (q[j + n2 * q_dim1] < 0.f) { 06562 iphase = 1; 06563 } 06564 L140: 06565 ; 06566 } 06567 L150: 06568 if (iphase == 2) { 06569 goto L500; 06570 } 06571 /* COMPUTE THE MARGINAL COSTS. */ 06572 L160: 06573 i__1 = n1; 06574 for (j = js; j <= i__1; ++j) { 06575 xsum = 0.; 06576 i__2 = klm; 06577 for (i__ = 1; i__ <= i__2; ++i__) { 06578 ii = (long int) q[i__ + n2 * q_dim1]; 06579 if (ii < 0) { 06580 goto L170; 06581 } 06582 z__ = cu[(ii << 1) + 1]; 06583 goto L180; 06584 L170: 06585 iineg = -ii; 06586 z__ = cu[(iineg << 1) + 2]; 06587 L180: 06588 xsum += q[i__ + j * q_dim1] * z__; 06589 /* 180 XSUM = XSUM + Q(I,J)*Z */ 06590 /* L190: */ 06591 } 06592 q[klm1 + j * q_dim1] = xsum; 06593 /* L200: */ 06594 } 06595 i__1 = *n; 06596 for (j = js; j <= i__1; ++j) { 06597 ii = (long int) q[klm2 + j * q_dim1]; 06598 if (ii < 0) { 06599 goto L210; 06600 } 06601 z__ = cu[(ii << 1) + 1]; 06602 goto L220; 06603 L210: 06604 iineg = -ii; 06605 z__ = cu[(iineg << 1) + 2]; 06606 L220: 06607 q[klm1 + j * q_dim1] -= z__; 06608 /* L230: */ 06609 } 06610 /* DETERMINE THE VECTOR TO ENTER THE BASIS. */ 06611 L240: 06612 xmax = 0.f; 06613 if (js > *n) { 06614 goto L490; 06615 } 06616 i__1 = *n; 06617 for (j = js; j <= i__1; ++j) { 06618 zu = q[klm1 + j * q_dim1]; 06619 ii = (long int) q[klm2 + j * q_dim1]; 06620 if (ii > 0) { 06621 goto L250; 06622 } 06623 ii = -ii; 06624 zv = zu; 06625 zu = -zu - cu[(ii << 1) + 1] - cu[(ii << 1) + 2]; 06626 goto L260; 06627 L250: 06628 zv = -zu - cu[(ii << 1) + 1] - cu[(ii << 1) + 2]; 06629 L260: 06630 if (kforce == 1 && ii > *n) { 06631 goto L280; 06632 } 06633 if (iu[(ii << 1) + 1] == 1) { 06634 goto L270; 06635 } 06636 if (zu <= xmax) { 06637 goto L270; 06638 } 06639 xmax = zu; 06640 in = j; 06641 L270: 06642 if (iu[(ii << 1) + 2] == 1) { 06643 goto L280; 06644 } 06645 if (zv <= xmax) { 06646 goto L280; 06647 } 06648 xmax = zv; 06649 in = j; 06650 L280: 06651 ; 06652 } 06653 if (xmax <= toler) { 06654 goto L490; 06655 } 06656 if (q[klm1 + in * q_dim1] == xmax) { 06657 goto L300; 06658 } 06659 i__1 = klm2; 06660 for (i__ = 1; i__ <= i__1; ++i__) { 06661 q[i__ + in * q_dim1] = -q[i__ + in * q_dim1]; 06662 /* L290: */ 06663 } 06664 q[klm1 + in * q_dim1] = xmax; 06665 /* DETERMINE THE VECTOR TO LEAVE THE BASIS. */ 06666 L300: 06667 if (iphase == 1 || ia == 0) { 06668 goto L330; 06669 } 06670 xmax = 0.f; 06671 i__1 = ia; 06672 for (i__ = 1; i__ <= i__1; ++i__) { 06673 z__ = (d__1 = q[i__ + in * q_dim1], abs(d__1)); 06674 if (z__ <= xmax) { 06675 goto L310; 06676 } 06677 xmax = z__; 06678 iout = i__; 06679 L310: 06680 ; 06681 } 06682 if (xmax <= toler) { 06683 goto L330; 06684 } 06685 i__1 = n2; 06686 for (j = 1; j <= i__1; ++j) { 06687 z__ = q[ia + j * q_dim1]; 06688 q[ia + j * q_dim1] = q[iout + j * q_dim1]; 06689 q[iout + j * q_dim1] = z__; 06690 /* L320: */ 06691 } 06692 iout = ia; 06693 --ia; 06694 pivot = q[iout + in * q_dim1]; 06695 goto L420; 06696 L330: 06697 kk = 0; 06698 i__1 = klm; 06699 for (i__ = 1; i__ <= i__1; ++i__) { 06700 z__ = q[i__ + in * q_dim1]; 06701 if (z__ <= toler) { 06702 goto L340; 06703 } 06704 ++kk; 06705 res[kk] = q[i__ + n1 * q_dim1] / z__; 06706 s[kk] = (double) i__; 06707 L340: 06708 ; 06709 } 06710 L350: 06711 if (kk > 0) { 06712 goto L360; 06713 } 06714 kode = 2; 06715 goto L590; 06716 L360: 06717 xmin = static_cast<float>( res[1] ); 06718 iout = (long int) s[1]; 06719 j = 1; 06720 if (kk == 1) { 06721 goto L380; 06722 } 06723 i__1 = kk; 06724 for (i__ = 2; i__ <= i__1; ++i__) { 06725 if (res[i__] >= xmin) { 06726 goto L370; 06727 } 06728 j = i__; 06729 xmin = static_cast<float>( res[i__] ); 06730 iout = (long int) s[i__]; 06731 L370: 06732 ; 06733 } 06734 res[j] = res[kk]; 06735 s[j] = s[kk]; 06736 L380: 06737 --kk; 06738 pivot = q[iout + in * q_dim1]; 06739 ii = (long int) q[iout + n2 * q_dim1]; 06740 if (iphase == 1) { 06741 goto L400; 06742 } 06743 if (ii < 0) { 06744 goto L390; 06745 } 06746 if (iu[(ii << 1) + 2] == 1) { 06747 goto L420; 06748 } 06749 goto L400; 06750 L390: 06751 iineg = -ii; 06752 if (iu[(iineg << 1) + 1] == 1) { 06753 goto L420; 06754 } 06755 /* 400 II = IABS(II) */ 06756 L400: 06757 ii = abs(ii); 06758 cuv = cu[(ii << 1) + 1] + cu[(ii << 1) + 2]; 06759 if (q[klm1 + in * q_dim1] - pivot * cuv <= toler) { 06760 goto L420; 06761 } 06762 /* BYPASS INTERMEDIATE VERTICES. */ 06763 i__1 = n1; 06764 for (j = js; j <= i__1; ++j) { 06765 z__ = q[iout + j * q_dim1]; 06766 q[klm1 + j * q_dim1] -= z__ * cuv; 06767 q[iout + j * q_dim1] = -z__; 06768 /* L410: */ 06769 } 06770 q[iout + n2 * q_dim1] = -q[iout + n2 * q_dim1]; 06771 goto L350; 06772 /* GAUSS-JORDAN ELIMINATION. */ 06773 L420: 06774 if (iter < maxit) { 06775 goto L430; 06776 } 06777 kode = 3; 06778 goto L590; 06779 L430: 06780 ++iter; 06781 i__1 = n1; 06782 for (j = js; j <= i__1; ++j) { 06783 if (j != in) { 06784 q[iout + j * q_dim1] /= pivot; 06785 } 06786 /* L440: */ 06787 } 06788 /* IF PERMITTED, USE SUBROUTINE COL OF THE DESCRIPTION */ 06789 /* SECTION AND REPLACE THE FOLLOWING SEVEN STATEMENTS DOWN */ 06790 /* TO AND INCLUDING STATEMENT NUMBER 460 BY.. */ 06791 /* DO 460 J=JS,N1 */ 06792 /* IF(J .EQ. IN) GO TO 460 */ 06793 /* Z = -Q(IOUT,J) */ 06794 /* CALL COL(Q(1,J), Q(1,IN), Z, IOUT, KLM1) */ 06795 /* 460 CONTINUE */ 06796 i__1 = n1; 06797 for (j = js; j <= i__1; ++j) { 06798 if (j == in) { 06799 goto L460; 06800 } 06801 z__ = -q[iout + j * q_dim1]; 06802 i__2 = klm1; 06803 for (i__ = 1; i__ <= i__2; ++i__) { 06804 if (i__ != iout) { 06805 q[i__ + j * q_dim1] += z__ * q[i__ + in * q_dim1]; 06806 } 06807 /* L450: */ 06808 } 06809 L460: 06810 ; 06811 } 06812 tpivot = -pivot; 06813 i__1 = klm1; 06814 for (i__ = 1; i__ <= i__1; ++i__) { 06815 if (i__ != iout) { 06816 q[i__ + in * q_dim1] /= tpivot; 06817 } 06818 /* L470: */ 06819 } 06820 q[iout + in * q_dim1] = 1.f / pivot; 06821 z__ = q[iout + n2 * q_dim1]; 06822 q[iout + n2 * q_dim1] = q[klm2 + in * q_dim1]; 06823 q[klm2 + in * q_dim1] = z__; 06824 ii = (long int) abs(z__); 06825 if (iu[(ii << 1) + 1] == 0 || iu[(ii << 1) + 2] == 0) { 06826 goto L240; 06827 } 06828 i__1 = klm2; 06829 for (i__ = 1; i__ <= i__1; ++i__) { 06830 z__ = q[i__ + in * q_dim1]; 06831 q[i__ + in * q_dim1] = q[i__ + js * q_dim1]; 06832 q[i__ + js * q_dim1] = z__; 06833 /* L480: */ 06834 } 06835 ++js; 06836 goto L240; 06837 /* TEST FOR OPTIMALITY. */ 06838 L490: 06839 if (kforce == 0) { 06840 goto L580; 06841 } 06842 if (iphase == 1 && q[klm1 + n1 * q_dim1] <= toler) { 06843 goto L500; 06844 } 06845 kforce = 0; 06846 goto L240; 06847 /* SET UP PHASE 2 COSTS. */ 06848 L500: 06849 iphase = 2; 06850 i__1 = nklm; 06851 for (j = 1; j <= i__1; ++j) { 06852 cu[(j << 1) + 1] = 0.f; 06853 cu[(j << 1) + 2] = 0.f; 06854 /* L510: */ 06855 } 06856 i__1 = nk; 06857 for (j = n1; j <= i__1; ++j) { 06858 cu[(j << 1) + 1] = 1.f; 06859 cu[(j << 1) + 2] = 1.f; 06860 /* L520: */ 06861 } 06862 i__1 = klm; 06863 for (i__ = 1; i__ <= i__1; ++i__) { 06864 ii = (long int) q[i__ + n2 * q_dim1]; 06865 if (ii > 0) { 06866 goto L530; 06867 } 06868 ii = -ii; 06869 if (iu[(ii << 1) + 2] == 0) { 06870 goto L560; 06871 } 06872 cu[(ii << 1) + 2] = 0.f; 06873 goto L540; 06874 L530: 06875 if (iu[(ii << 1) + 1] == 0) { 06876 goto L560; 06877 } 06878 cu[(ii << 1) + 1] = 0.f; 06879 L540: 06880 ++ia; 06881 i__2 = n2; 06882 for (j = 1; j <= i__2; ++j) { 06883 z__ = q[ia + j * q_dim1]; 06884 q[ia + j * q_dim1] = q[i__ + j * q_dim1]; 06885 q[i__ + j * q_dim1] = z__; 06886 /* L550: */ 06887 } 06888 L560: 06889 ; 06890 } 06891 goto L160; 06892 L570: 06893 if (q[klm1 + n1 * q_dim1] <= toler) { 06894 goto L500; 06895 } 06896 kode = 1; 06897 goto L590; 06898 L580: 06899 if (iphase == 1) { 06900 goto L570; 06901 } 06902 /* PREPARE OUTPUT. */ 06903 kode = 0; 06904 L590: 06905 xsum = 0.; 06906 i__1 = *n; 06907 for (j = 1; j <= i__1; ++j) { 06908 x[j] = 0.f; 06909 /* L600: */ 06910 } 06911 i__1 = klm; 06912 for (i__ = 1; i__ <= i__1; ++i__) { 06913 res[i__] = 0.f; 06914 /* L610: */ 06915 } 06916 i__1 = klm; 06917 for (i__ = 1; i__ <= i__1; ++i__) { 06918 ii = (long int) q[i__ + n2 * q_dim1]; 06919 sn = 1.f; 06920 if (ii > 0) { 06921 goto L620; 06922 } 06923 ii = -ii; 06924 sn = -1.f; 06925 L620: 06926 if (ii > *n) { 06927 goto L630; 06928 } 06929 x[ii] = sn * q[i__ + n1 * q_dim1]; 06930 goto L640; 06931 L630: 06932 iimn = ii - *n; 06933 res[iimn] = sn * q[i__ + n1 * q_dim1]; 06934 if (ii >= n1 && ii <= nk) { 06935 xsum += q[i__ + n1 * q_dim1]; 06936 } 06937 L640: 06938 ; 06939 } 06940 error = (float)xsum; 06941 return; 06942 }
vector< float > Util::cluster_equalsize | ( | EMData * | d | ) | [static] |
Definition at line 19420 of file util_sparx.cpp.
References dm, EMAN::EMData::get_xsize(), nx, and sqrt().
19420 { 19421 // WORKS ONLY FOR NUMBER OF OBJECTS N=l^2 !! 19422 int nx = d->get_xsize(); 19423 int N = 1 + int((sqrt(1.0 + 8.0*nx)-1.0)/2.0); 19424 int K = N/2; 19425 vector<float> group(N); 19426 if(N*(N-1)/2 != nx) { 19427 //print " incorrect dimension" 19428 return group;} 19429 //bool active[N]; //this does not compile in VS2005. --Grant Tang 19430 bool * active = new bool[N]; 19431 for(int i=0; i<N; i++) active[i] = true; 19432 19433 float dm, qd; 19434 int ppi = 0, ppj = 0; 19435 for(int k=0; k<K; k++) { 19436 // find pairs of most similiar objects among active 19437 //cout<<" k "<<k<<endl; 19438 dm = 1.0e23f; 19439 for(int i=1; i<N; i++) { 19440 if(active[i]) { 19441 for(int j=0; j<i; j++) { 19442 if(active[j]) { 19443 qd = (*d)(i*(i - 1)/2 + j); 19444 if(qd < dm) { 19445 dm = qd; 19446 ppi = i; 19447 ppj = j; 19448 } 19449 } 19450 } 19451 } 19452 } 19453 group[2*k] = float(ppi); 19454 group[1+2*k] = float(ppj); 19455 active[ppi] = false; 19456 active[ppj] = false; 19457 } 19458 19459 delete [] active; 19460 active = NULL; 19461 return group; 19462 }
vector< float > Util::cluster_pairwise | ( | EMData * | d, | |
int | K, | |||
float | T, | |||
float | F | |||
) | [static] |
Definition at line 19212 of file util_sparx.cpp.
References assign, cent, dt, get_irand(), EMAN::EMData::get_xsize(), mono(), nx, q, and sqrt().
19212 { 19213 int nx = d->get_xsize(); 19214 int N = 1 + int((sqrt(1.0 + 8.0*nx)-1.0)/2.0); 19215 vector<float> out(N+K+2); 19216 if(N*(N-1)/2 != nx) { 19217 //print " incorrect dimension" 19218 return out;} 19219 // assign random objects as centers 19220 for(int i=0; i<N; i++) assign(i) = float(i); 19221 // shuffle 19222 for(int i=0; i<N; i++) { 19223 int j = Util::get_irand(0,N-1); 19224 float temp = assign(i); 19225 assign(i) = assign(j); 19226 assign(j) = temp; 19227 } 19228 for(int k=0; k<K; k++) cent(k) = float(assign(k)); 19229 //for(int k=0; k<K; k++) cout<<cent(k)<<" ";cout<<endl; 19230 // 19231 for(int i=0; i<N; i++) assign(i) = 0.0f; 19232 float qm, dispold = 1.1e22f, disp = 1.0e22f, na=0.0f; 19233 bool change = true; 19234 int it = -1; 19235 int ct = -1; 19236 while(change && disp < dispold || ct > 0) { 19237 19238 change = false; 19239 dispold = disp; 19240 it++; 19241 19242 // dispersion is a sum of distance from objects to object center 19243 disp = 0.0f; 19244 ct = 0; 19245 for(int i=0; i<N; i++) { 19246 qm = 1.0e23f; 19247 for(int k=0; k<K; k++) { 19248 if(float(i) == cent(k)) { 19249 qm = 0.0f; 19250 na = (float)k; 19251 } else { 19252 float dt = (*d)(mono(i,int(cent(k)))); 19253 if(dt < qm) { 19254 qm = dt; 19255 na = (float)k; 19256 } 19257 } 19258 } 19259 19260 19261 // Simulated annealing 19262 if(exp(-1.0/float(T)) > Util::get_irand(1,1000)/1000.0) { 19263 na = (float)(Util::get_irand(0, K)); 19264 qm = (*d)(mono(i,int(na))); 19265 ct++; 19266 } 19267 19268 disp += qm; 19269 19270 if(na != assign(i)) { 19271 assign(i) = na; 19272 change = true; 19273 } 19274 } 19275 19276 //cout<<"Iteration: "<<it<< " disp " <<disp << " T " << T << " disturb " << ct << endl; 19277 T = T*F; 19278 19279 //for(int k=0; k<N; k++) cout<<assign(k)<<" ";cout<<endl; 19280 //print disp 19281 //print assign 19282 // find centers 19283 for(int k=0; k<K; k++) { 19284 qm = 1.0e23f; 19285 for(int i=0; i<N; i++) { 19286 if(assign(i) == float(k)) { 19287 float q = 0.0; 19288 for(int j=0; j<N; j++) { 19289 if(assign(j) == float(k)) { 19290 //it cannot be the same object 19291 if(i != j) q += (*d)(mono(i,j)); 19292 //cout<<q<<" "<<i<<" "<<j<<" "<<k<<endl;} 19293 } 19294 } 19295 if(q < qm) { 19296 //cout<<qm<<" "<<q<<" "<<i<<" "<<k<<endl; 19297 qm = q; 19298 cent(k) = float(i); 19299 } 19300 } 19301 } 19302 } 19303 //for(int k=0; k<K; k++) cout<<cent(k)<<" ";cout<<endl;cout<<disp<<endl; 19304 } 19305 out[N+K] = disp; 19306 out[N+K+1] = float(it); 19307 return out; 19308 }
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 4916 of file util_sparx.cpp.
04916 { 04917 double res = 0; 04918 double buf = 0; 04919 float* line_1; 04920 float* line_2; 04921 int i, n, ind; 04922 int lnlen = data[0]->get_xsize(); 04923 for (n=0; n<n_lines; ++n) { 04924 ind = n*2; 04925 line_1 = data[seq[ind]]->get_data() + com[ind] * lnlen; 04926 line_2 = data[seq[ind+1]]->get_data() + com[ind+1] *lnlen; 04927 buf = 0; 04928 for (i=0; i<lnlen; ++i) { 04929 buf += (line_1[i]-line_2[i])*(line_1[i]-line_2[i]); 04930 } 04931 res += buf * weights[n]; 04932 } 04933 04934 return res; 04935 04936 }
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 4693 of file util_sparx.cpp.
References deg_rad.
04693 { 04694 int nb_ori = Ori.size() / 4; 04695 int i, ind; 04696 float ph, th, ps; 04697 double cph, cth, cps, sph, sth, sps; 04698 vector<double> Rot(nb_ori*9); 04699 for (i=0; i<nb_ori; ++i){ 04700 ind = i*4; 04701 // spider convention phi=psi-90, psi=phi+90 04702 ph = Ori[ind+2]-90; 04703 th = Ori[ind+1]; 04704 ps = Ori[ind]+90; 04705 ph *= deg_rad; 04706 th *= deg_rad; 04707 ps *= deg_rad; 04708 // pre-calculate some trigo stuffs 04709 cph = cos(ph); 04710 cth = cos(th); 04711 cps = cos(ps); 04712 sph = sin(ph); 04713 sth = sin(th); 04714 sps = sin(ps); 04715 // fill rotation matrix 04716 ind = i*9; 04717 Rot[ind] = cph*cps-cth*sps*sph; 04718 Rot[ind+1] = cph*sps+cth*cps*sph; 04719 Rot[ind+2] = sth*sph; 04720 Rot[ind+3] = -sph*cps-cth*sps*cph; 04721 Rot[ind+4] = -sph*sps+cth*cps*cph; 04722 Rot[ind+5] = sth*cph; 04723 Rot[ind+6] = sth*sps; 04724 Rot[ind+7] = -sth*cps; 04725 Rot[ind+8] = cth; 04726 } 04727 04728 return Rot; 04729 }
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 4861 of file util_sparx.cpp.
References deg_rad, norm(), nx, ny, rad_deg, and sqrt().
04861 { 04862 // seq is the pairwise index ij: 0, 1, 0, 2, 0, 3, 1, 2, 1, 3, 2, 3 04863 vector<double> cml(2*nlines); // [phi, theta] / line 04864 float ph1, th1; 04865 float ph2, th2; 04866 double nx, ny, nz; 04867 double norm; 04868 double sth1=0, sph1=0, cth1=0, cph1=0; 04869 double sth2, sph2, cth2, cph2; 04870 int l, ind, c; 04871 int mem = -1; 04872 for (l=0; l<nlines; ++l){ 04873 c = 2*l; 04874 if (seq[c]!=mem){ 04875 mem = seq[c]; 04876 ind = 4*seq[c]; 04877 ph1 = Ori[ind]*deg_rad; 04878 th1 = Ori[ind+1]*deg_rad; 04879 sth1 = sin(th1); 04880 sph1 = sin(ph1); 04881 cth1 = cos(th1); 04882 cph1 = cos(ph1); 04883 } 04884 ind = 4*seq[c+1]; 04885 ph2 = Ori[ind]*deg_rad; 04886 th2 = Ori[ind+1]*deg_rad; 04887 sth2 = sin(th2); 04888 cth2 = cos(th2); 04889 sph2 = sin(ph2); 04890 cph2 = cos(ph2); 04891 // cross product 04892 nx = sth1*cph1*cth2 - cth1*sth2*cph2; 04893 ny = cth1*sth2*sph2 - cth2*sth1*sph1; 04894 nz = sth1*sph1*sth2*cph2 - sth1*cph1*sth2*sph2; 04895 norm = sqrt(nx*nx+ny*ny+nz*nz); 04896 nx /= norm; 04897 ny /= norm; 04898 nz /= norm; 04899 // apply mirror if need 04900 if (nz<0) {nx=-nx; ny=-ny; nz=-nz;} 04901 // compute theta and phi 04902 cml[c+1] = acos(nz); 04903 if (cml[c+1] == 0) {cml[c] = 0;} 04904 else { 04905 cml[c+1] *= rad_deg; 04906 if (cml[c+1] > 89.99) {cml[c+1] = 89.99;} // this fix some pb in Voronoi 04907 cml[c] = rad_deg * atan2(nx, ny); 04908 cml[c] = fmod(360 + cml[c], 360); 04909 04910 } 04911 } 04912 04913 return cml; 04914 }
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 4762 of file util_sparx.cpp.
References abs, b, nint180(), and rad_deg.
04762 { 04763 vector<int> com(2*(n_prj - 1)); 04764 int a = i_prj*9; 04765 int i, b, c; 04766 int n1=0, n2=0; 04767 float vmax = 1 - 1.0e-6f; 04768 double r11, r12, r13, r23, r31, r32, r33; 04769 04770 c = 0; 04771 for (i=0; i<n_prj; ++i){ 04772 if (i!=i_prj){ 04773 b = i*9; 04774 // this is equivalent to R = A*B' 04775 r11 = Rot[a]*Rot[b]+Rot[a+1]*Rot[b+1]+Rot[a+2]*Rot[b+2]; 04776 r12 = Rot[a]*Rot[b+3]+Rot[a+1]*Rot[b+4]+Rot[a+2]*Rot[b+5]; 04777 r13 = Rot[a]*Rot[b+6]+Rot[a+1]*Rot[b+7]+Rot[a+2]*Rot[b+8]; 04778 r23 = Rot[a+3]*Rot[b+6]+Rot[a+4]*Rot[b+7]+Rot[a+5]*Rot[b+8]; 04779 r31 = Rot[a+6]*Rot[b]+Rot[a+7]*Rot[b+1]+Rot[a+8]*Rot[b+2]; 04780 r32 = Rot[a+6]*Rot[b+3]+Rot[a+7]*Rot[b+4]+Rot[a+8]*Rot[b+5]; 04781 r33 = Rot[a+6]*Rot[b+6]+Rot[a+7]*Rot[b+7]+Rot[a+8]*Rot[b+8]; 04782 if (r33 > vmax) { 04783 n2 = 270; 04784 n1 = 270 + nint180((float)(rad_deg*atan2(r12, r11))); 04785 } 04786 else if (r33 < -vmax) { 04787 n2 = 270; 04788 n1 = 270 - nint180((float)(rad_deg*atan2(r12, r11))); 04789 } else { 04790 n2 = nint180((float)(rad_deg*atan2(r31, -r32))); 04791 n1 = nint180((float)(rad_deg*atan2(r13, r23))); 04792 if (n1 < 0) {n1 += 360;} 04793 if (n2 <= 0) {n2 = abs(n2);} 04794 else {n2 = 360 - n2;} 04795 } 04796 04797 if (n1 >= 360){n1 = n1 % 360;} 04798 if (n2 >= 360){n2 = n2 % 360;} 04799 04800 // store common-lines 04801 b = c*2; 04802 com[b] = n1; 04803 com[b+1] = n2; 04804 ++c; 04805 } 04806 } 04807 04808 return com; 04809 04810 }
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 4812 of file util_sparx.cpp.
References abs, b, nint180(), and rad_deg.
04812 { 04813 vector<int> com(2*n_lines); 04814 int a=0, b, c, l; 04815 int n1=0, n2=0, mem=-1; 04816 float vmax = 1 - 1.0e-6f; 04817 double r11, r12, r13, r23, r31, r32, r33; 04818 c = 0; 04819 for (l=0; l<n_lines; ++l){ 04820 c = 2*l; 04821 if (seq[c]!=mem){ 04822 mem = seq[c]; 04823 a = seq[c]*9; 04824 } 04825 b = seq[c+1]*9; 04826 04827 // this is equivalent to R = A*B' 04828 r11 = Rot[a]*Rot[b]+Rot[a+1]*Rot[b+1]+Rot[a+2]*Rot[b+2]; 04829 r12 = Rot[a]*Rot[b+3]+Rot[a+1]*Rot[b+4]+Rot[a+2]*Rot[b+5]; 04830 r13 = Rot[a]*Rot[b+6]+Rot[a+1]*Rot[b+7]+Rot[a+2]*Rot[b+8]; 04831 r23 = Rot[a+3]*Rot[b+6]+Rot[a+4]*Rot[b+7]+Rot[a+5]*Rot[b+8]; 04832 r31 = Rot[a+6]*Rot[b]+Rot[a+7]*Rot[b+1]+Rot[a+8]*Rot[b+2]; 04833 r32 = Rot[a+6]*Rot[b+3]+Rot[a+7]*Rot[b+4]+Rot[a+8]*Rot[b+5]; 04834 r33 = Rot[a+6]*Rot[b+6]+Rot[a+7]*Rot[b+7]+Rot[a+8]*Rot[b+8]; 04835 if (r33 > vmax) { 04836 n2 = 270; 04837 n1 = 270 + nint180((float)(rad_deg*atan2(r12, r11))); 04838 } 04839 else if (r33 < -vmax) { 04840 n2 = 270; 04841 n1 = 270 - nint180((float)(rad_deg*atan2(r12, r11))); 04842 } else { 04843 n2 = nint180((float)(rad_deg*atan2(r31, -r32))); 04844 n1 = nint180((float)(rad_deg*atan2(r13, r23))); 04845 if (n1 < 0) {n1 += 360;} 04846 if (n2 <= 0) {n2 = abs(n2);} 04847 else {n2 = 360 - n2;} 04848 } 04849 if (n1 >= 360){n1 = n1 % 360;} 04850 if (n2 >= 360){n2 = n2 % 360;} 04851 04852 // store common-lines 04853 com[c] = n1; 04854 com[c+1] = n2; 04855 } 04856 04857 return com; 04858 04859 }
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 4675 of file util_sparx.cpp.
References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), nx, and EMAN::EMData::update().
04675 { 04676 int j; 04677 int nx = sino->get_xsize(); 04678 int i = nx * pos_line; 04679 float r1, r2; 04680 float *line_ptr = line->get_data(); 04681 float *sino_ptr = sino->get_data(); 04682 for (j=ilf;j<=ihf; j += 2) { 04683 r1 = line_ptr[j]; 04684 r2 = line_ptr[j + 1]; 04685 sino_ptr[i + j - ilf] = r1; 04686 sino_ptr[i + j - ilf + 1] = r2; 04687 sino_ptr[i + nx * nblines + j - ilf] = r1; 04688 sino_ptr[i + nx * nblines + j - ilf + 1] = -r2; 04689 } 04690 sino->update(); 04691 }
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 4938 of file util_sparx.cpp.
04939 { 04940 // res: [best_disc, best_ipsi] 04941 // seq: pairwise indexes ij, 0, 1, 0, 2, 0, 3, 1, 2, 1, 3, 2, 3 04942 // iw : index to know where is the weight for the common-lines on the current projection in the all weights, [12, 4, 2, 7] 04943 vector<double> res(2); 04944 int lnlen = data[0]->get_xsize(); 04945 int end = 2*(n_prj-1); 04946 double disc, buf, bdisc, tmp; 04947 int n, i, ipsi, ind, bipsi, c; 04948 float* line_1; 04949 float* line_2; 04950 bdisc = 1.0e6; 04951 bipsi = -1; 04952 // loop psi 04953 for(ipsi=0; ipsi<n_psi; ipsi += d_psi) { 04954 // discrepancy 04955 disc = 0; 04956 c = 0; 04957 for (n=0; n<n_prj; ++n) { 04958 if(n!=iprj) { 04959 ind = 2*c; 04960 line_1 = data[iprj]->get_data() + com[ind] * lnlen; 04961 line_2 = data[n]->get_data() + com[ind+1] * lnlen; 04962 buf = 0; 04963 for (i=0; i<lnlen; ++i) { 04964 tmp = line_1[i]-line_2[i]; 04965 buf += tmp*tmp; 04966 } 04967 disc += buf * weights[iw[c]]; 04968 ++c; 04969 } 04970 } 04971 // select the best value 04972 if (disc <= bdisc) { 04973 bdisc = disc; 04974 bipsi = ipsi; 04975 } 04976 // update common-lines 04977 for (i=0; i<end; i+=2){ 04978 com[i] += d_psi; 04979 if (com[i] >= n_psi) {com[i] = com[i] % n_psi;} 04980 } 04981 } 04982 res[0] = bdisc; 04983 res[1] = float(bipsi); 04984 04985 return res; 04986 }
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 4731 of file util_sparx.cpp.
References deg_rad.
04731 { 04732 float ph, ps; 04733 double cph, cth, cps, sph, sth, sps; 04734 int ind = iprj*9; 04735 // spider convention phi=psi-90, psi=phi+90 04736 ph = nps-90; 04737 ps = nph+90; 04738 ph *= deg_rad; 04739 th *= deg_rad; 04740 ps *= deg_rad; 04741 // pre-calculate some trigo stuffs 04742 cph = cos(ph); 04743 cth = cos(th); 04744 cps = cos(ps); 04745 sph = sin(ph); 04746 sth = sin(th); 04747 sps = sin(ps); 04748 // fill rotation matrix 04749 Rot[ind] = (float)(cph*cps-cth*sps*sph); 04750 Rot[ind+1] = (float)(cph*sps+cth*cps*sph); 04751 Rot[ind+2] = (float)(sth*sph); 04752 Rot[ind+3] = (float)(-sph*cps-cth*sps*cph); 04753 Rot[ind+4] = (float)(-sph*sps+cth*cps*cph); 04754 Rot[ind+5] = (float)(sth*cph); 04755 Rot[ind+6] = (float)(sth*sps); 04756 Rot[ind+7] = (float)(-sth*cps); 04757 Rot[ind+8] = (float)(cth); 04758 04759 return Rot; 04760 }
vector< double > Util::cml_weights | ( | const vector< float > & | cml | ) | [static] |
Definition at line 4585 of file util_sparx.cpp.
References Assert, PI2, and vrdg().
04585 { 04586 static const int NBIN = 100; 04587 int nline=cml.size()/2; 04588 vector<double> weights(nline); 04589 04590 vector<ori_t> angs(nline); 04591 for( int i=0; i < nline; ++i ) { 04592 angs[i].iphi = int( NBIN*cml[2*i] ); 04593 angs[i].itht = int( NBIN*cml[2*i+1] ); 04594 if( angs[i].itht == 180*NBIN ) angs[i].itht = 0; 04595 angs[i].id = i; 04596 } 04597 04598 //std::cout << "# of angs: " << angs.size() << std::endl; 04599 04600 std::sort( angs.begin(), angs.end(), cmpang() ); 04601 04602 vector<float> newphi; 04603 vector<float> newtht; 04604 vector< vector<int> > indices; 04605 04606 int curt_iphi = -1; 04607 int curt_itht = -1; 04608 for(unsigned int i=0 ;i < angs.size(); ++i ) { 04609 if( angs[i].iphi==curt_iphi && angs[i].itht==curt_itht ) { 04610 Assert( indices.size() > 0 ); 04611 indices.back().push_back(angs[i].id); 04612 } else { 04613 curt_iphi = angs[i].iphi; 04614 curt_itht = angs[i].itht; 04615 04616 newphi.push_back( float(curt_iphi)/NBIN ); 04617 newtht.push_back( float(curt_itht)/NBIN ); 04618 indices.push_back( vector<int>(1,angs[i].id) ); 04619 } 04620 } 04621 04622 //std::cout << "# of indpendent ang: " << newphi.size() << std::endl; 04623 04624 04625 int num_agl = newphi.size(); 04626 04627 if(num_agl>2) { 04628 vector<double> w=Util::vrdg(newphi, newtht); 04629 04630 Assert( w.size()==newphi.size() ); 04631 Assert( indices.size()==newphi.size() ); 04632 04633 for(unsigned int i=0; i < newphi.size(); ++i ) { 04634 /* 04635 std::cout << "phi,tht,w,n: "; 04636 std::cout << boost::format( "%10.3f" ) % newphi[i] << " "; 04637 std::cout << boost::format( "%10.3f" ) % newtht[i] << " "; 04638 std::cout << boost::format( "%8.6f" ) % w[i] << " "; 04639 std::cout << indices[i].size() << "("; 04640 */ 04641 04642 for(unsigned int j=0; j < indices[i].size(); ++j ) { 04643 int id = indices[i][j]; 04644 weights[id] = w[i]/indices[i].size(); 04645 //std::cout << id << " "; 04646 } 04647 04648 //std::cout << ")" << std::endl; 04649 04650 } 04651 } else { 04652 cout<<"warning in Util.cml_weights"<<endl; 04653 double val = PI2/float(nline); 04654 for(int i=0; i<nline; i++) weights[i]=val; 04655 } 04656 04657 return weights; 04658 04659 }
Definition at line 7080 of file util_sparx.cpp.
References EMAN::Util::tmpstruct::theta1.
Referenced by hsortd().
Definition at line 7085 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 5346 of file util_sparx.cpp.
Referenced by cyclicshift(), and slicereverse().
05346 { 05347 float* tmp = new float[nx]; 05348 int n = (end - beg)/nx; 05349 int nhalf = n/2; 05350 for (int i = 0; i < nhalf; i++) { 05351 // swap col i and col n-1-i 05352 memcpy(tmp, beg+i*nx, nx*sizeof(float)); 05353 memcpy(beg+i*nx, beg+(n-1-i)*nx, nx*sizeof(float)); 05354 memcpy(beg+(n-1-i)*nx, tmp, nx*sizeof(float)); 05355 } 05356 delete[] tmp; 05357 }
Definition at line 5963 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().
05964 { 05965 /*********** 05966 ***get the size of the image for validation purpose 05967 **************/ 05968 int nx = image->get_xsize(),ny = image->get_ysize(),nz = image->get_zsize(); //Aren't these implied? Please check and let me know, PAP. 05969 /******** 05970 ***Exception Handle 05971 *************/ 05972 if(nx != mask->get_xsize() || ny != mask->get_ysize() || nz != mask->get_zsize()) 05973 throw ImageDimensionException("The dimension of the image does not match the dimension of the mask!"); 05974 05975 int i, size = nx*ny*nz; 05976 05977 float* img_ptr = image->get_data(); 05978 float* mask_ptr = mask->get_data(); 05979 05980 int ln=0; //length of the output image = number of points under the mask. 05981 for(i = 0;i < size;i++) if(mask_ptr[i] > 0.5f) ln++; 05982 05983 EMData* new_image = new EMData(); 05984 new_image->set_size(ln,1,1); /* set size of the new image */ 05985 float *new_ptr = new_image->get_data(); 05986 05987 ln=-1; 05988 for(i = 0;i < size;i++){ 05989 if(mask_ptr[i] > 0.5f) { 05990 ln++; 05991 new_ptr[ln]=img_ptr[i]; 05992 } 05993 } 05994 05995 return new_image; 05996 }
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 6092 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, and ssyev_().
06093 { 06094 // n size of the covariance/correlation matrix 06095 // covmat --- covariance/correlation matrix (n by n) 06096 // eigval --- returns eigenvalues 06097 // eigvec --- returns eigenvectors 06098 06099 ENTERFUNC; 06100 06101 int i; 06102 06103 // make a copy of covmat so that it will not be overwritten 06104 for ( i = 0 ; i < n * n ; i++ ) eigvec[i] = covmat[i]; 06105 06106 char NEEDV = 'V'; 06107 char UPLO = 'U'; 06108 int lwork = -1; 06109 int info = 0; 06110 float *work, wsize; 06111 06112 // query to get optimal workspace 06113 ssyev_(&NEEDV, &UPLO, &n, eigvec, &n, eigval, &wsize, &lwork, &info); 06114 lwork = (int)wsize; 06115 06116 work = (float *)calloc(lwork, sizeof(float)); 06117 // calculate eigs 06118 ssyev_(&NEEDV, &UPLO, &n, eigvec, &n, eigval, work, &lwork, &info); 06119 free(work); 06120 EXITFUNC; 06121 return info; 06122 }
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 6124 of file util_sparx.cpp.
References coveig(), covmat, eigval, eigvec, ENTERFUNC, EXITFUNC, and status.
06125 { 06126 06127 ENTERFUNC; 06128 int len = covmatpy.size(); 06129 float *eigvec; 06130 float *eigval; 06131 float *covmat; 06132 int status = 0; 06133 eigval = (float*)calloc(ncov,sizeof(float)); 06134 eigvec = (float*)calloc(ncov*ncov,sizeof(float)); 06135 covmat = (float*)calloc(ncov*ncov, sizeof(float)); 06136 06137 const float *covmat_ptr; 06138 covmat_ptr = &covmatpy[0]; 06139 for(int i=0;i<len;i++){ 06140 covmat[i] = covmat_ptr[i]; 06141 } 06142 06143 status = Util::coveig(ncov, covmat, eigval, eigvec); 06144 06145 vector<float> eigval_py(ncov); 06146 const float *eigval_ptr; 06147 eigval_ptr = &eigval[0]; 06148 for(int i=0;i<ncov;i++){ 06149 eigval_py[i] = eigval_ptr[i]; 06150 } 06151 06152 vector<float> eigvec_py(ncov*ncov); 06153 const float *eigvec_ptr; 06154 eigvec_ptr = &eigvec[0]; 06155 for(int i=0;i<ncov*ncov;i++){ 06156 eigvec_py[i] = eigvec_ptr[i]; 06157 } 06158 06159 Dict res; 06160 res["eigval"] = eigval_py; 06161 res["eigvec"] = eigvec_py; 06162 06163 EXITFUNC; 06164 return res; 06165 }
Definition at line 3165 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.
03165 { 03166 // neg = 0 straight, neg = 1 mirrored 03167 int nring = numr.size()/3; 03168 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03169 int maxrin = numr[numr.size()-1]; 03170 double qn; float tot; 03171 float *circ1 = circ1p->get_data(); 03172 float *circ2 = circ2p->get_data(); 03173 /* 03174 c checks single position, neg is flag for checking mirrored position 03175 c 03176 c input - fourier transforms of rings! 03177 c first set is conjugated (mirrored) if neg 03178 c circ1 already multiplied by weights! 03179 c automatic arrays 03180 dimension t(maxrin) removed +2 as it is only needed for other ffts 03181 double precision q(maxrin) 03182 double precision t7(-3:3) 03183 */ 03184 float *t; 03185 double t7[7], *q; 03186 int i, j, k, ip, jc, numr3i, numr2i, jtot = 0; 03187 float pos; 03188 03189 #ifdef _WIN32 03190 ip = -(int)(log((float)maxrin)/log(2.0f)); 03191 #else 03192 ip = -(int) (log2(maxrin)); 03193 #endif //_WIN32 03194 03195 q = (double*)calloc(maxrin, sizeof(double)); 03196 t = (float*)calloc(maxrin, sizeof(float)); 03197 03198 // cout << *qn <<" " <<*tot<<" "<<ip<<endl; 03199 for (i=1; i<=nring; i++) { 03200 numr3i = numr(3,i); 03201 numr2i = numr(2,i); 03202 03203 t(1) = (circ1(numr2i)) * circ2(numr2i); 03204 03205 if (numr3i != maxrin) { 03206 // test .ne. first for speed on some compilers 03207 t(numr3i+1) = circ1(numr2i+1) * circ2(numr2i+1); 03208 t(2) = 0.0; 03209 03210 if (neg) { 03211 // first set is conjugated (mirrored) 03212 for (j=3;j<=numr3i;j=j+2) { 03213 jc = j+numr2i-1; 03214 t(j) =(circ1(jc))*circ2(jc)-(circ1(jc+1))*circ2(jc+1); 03215 t(j+1) = -(circ1(jc))*circ2(jc+1)-(circ1(jc+1))*circ2(jc); 03216 } 03217 } else { 03218 for (j=3;j<=numr3i;j=j+2) { 03219 jc = j+numr2i-1; 03220 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1); 03221 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc); 03222 } 03223 } 03224 for (j=1;j<=numr3i+1;j++) q(j) = q(j) + t(j); 03225 } else { 03226 t(2) = circ1(numr2i+1) * circ2(numr2i+1); 03227 if (neg) { 03228 // first set is conjugated (mirrored) 03229 for (j=3;j<=maxrin;j=j+2) { 03230 jc = j+numr2i-1; 03231 t(j) = (circ1(jc))*circ2(jc) - (circ1(jc+1))*circ2(jc+1); 03232 t(j+1) = -(circ1(jc))*circ2(jc+1) - (circ1(jc+1))*circ2(jc); 03233 } 03234 } else { 03235 for (j=3;j<=maxrin;j=j+2) { 03236 jc = j+numr2i-1; 03237 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1); 03238 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc); 03239 } 03240 } 03241 for (j = 1; j <= maxrin; j++) q(j) += t(j); 03242 } 03243 } 03244 03245 fftr_d(q,ip); 03246 03247 qn = -1.0e20; 03248 for (j=1;j<=maxrin;j++) { 03249 if (q(j) >= qn) { 03250 qn = q(j); jtot = j; 03251 } 03252 } 03253 03254 for (k=-3; k<=3; k++) { 03255 j = (jtot+k+maxrin-1)%maxrin + 1; 03256 t7(k+4) = q(j); 03257 } 03258 03259 prb1d(t7,7,&pos); 03260 03261 tot = (float)jtot + pos; 03262 03263 if (q) free(q); 03264 if (t) free(t); 03265 03266 Dict retvals; 03267 retvals["qn"] = qn; 03268 retvals["tot"] = tot; 03269 return retvals; 03270 }
Dict Util::Crosrng_ew | ( | EMData * | circ1, | |
EMData * | circ2, | |||
vector< int > | numr, | |||
vector< float > | w, | |||
int | neg | |||
) | [static] |
Definition at line 3272 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.
03272 { 03273 // neg = 0 straight, neg = 1 mirrored 03274 int nring = numr.size()/3; 03275 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03276 int maxrin = numr[numr.size()-1]; 03277 double qn; float tot; 03278 float *circ1 = circ1p->get_data(); 03279 float *circ2 = circ2p->get_data(); 03280 /* 03281 c checks single position, neg is flag for checking mirrored position 03282 c 03283 c input - fourier transforms of rings! 03284 c first set is conjugated (mirrored) if neg 03285 c multiplication by weights! 03286 c automatic arrays 03287 dimension t(maxrin) removed +2 as it is only needed for other ffts 03288 double precision q(maxrin) 03289 double precision t7(-3:3) 03290 */ 03291 float *t; 03292 double t7[7], *q; 03293 int i, j, k, ip, jc, numr3i, numr2i, jtot = 0; 03294 float pos; 03295 03296 #ifdef _WIN32 03297 ip = -(int)(log((float)maxrin)/log(2.0f)); 03298 #else 03299 ip = -(int) (log2(maxrin)); 03300 #endif //_WIN32 03301 03302 q = (double*)calloc(maxrin, sizeof(double)); 03303 t = (float*)calloc(maxrin, sizeof(float)); 03304 03305 // cout << *qn <<" " <<*tot<<" "<<ip<<endl; 03306 for (i=1;i<=nring;i++) { 03307 numr3i = numr(3,i); 03308 numr2i = numr(2,i); 03309 03310 t(1) = circ1(numr2i) * circ2(numr2i); 03311 03312 if (numr3i != maxrin) { 03313 // test .ne. first for speed on some compilers 03314 t(numr3i+1) = circ1(numr2i+1) * circ2(numr2i+1); 03315 t(2) = 0.0; 03316 03317 if (neg) { 03318 // first set is conjugated (mirrored) 03319 for (j=3; j<=numr3i; j=j+2) { 03320 jc = j+numr2i-1; 03321 t(j) = (circ1(jc))*circ2(jc)-(circ1(jc+1))*circ2(jc+1); 03322 t(j+1) = -(circ1(jc))*circ2(jc+1)-(circ1(jc+1))*circ2(jc); 03323 } 03324 } else { 03325 for (j=3; j<=numr3i; j=j+2) { 03326 jc = j+numr2i-1; 03327 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1); 03328 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc); 03329 } 03330 } 03331 for (j=1;j<=numr3i+1;j++) q(j) += t(j)*w[i-1]; 03332 } else { 03333 t(2) = circ1(numr2i+1) * circ2(numr2i+1); 03334 if (neg) { 03335 // first set is conjugated (mirrored) 03336 for (j=3; j<=maxrin; j=j+2) { 03337 jc = j+numr2i-1; 03338 t(j) = (circ1(jc))*circ2(jc) - (circ1(jc+1))*circ2(jc+1); 03339 t(j+1) = -(circ1(jc))*circ2(jc+1) - (circ1(jc+1))*circ2(jc); 03340 } 03341 } else { 03342 for (j=3; j<=maxrin; j=j+2) { 03343 jc = j+numr2i-1; 03344 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1); 03345 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc); 03346 } 03347 } 03348 for (j = 1; j <= maxrin; j++) q(j) += t(j)*w[i-1]; 03349 } 03350 } 03351 03352 fftr_d(q,ip); 03353 03354 qn = -1.0e20; 03355 for (j=1;j<=maxrin;j++) { 03356 //cout << j << " " << q(j) << endl; 03357 if (q(j) >= qn) { 03358 qn = q(j); 03359 jtot = j; 03360 } 03361 } 03362 03363 for (k=-3; k<=3; k++) { 03364 j = (jtot+k+maxrin-1)%maxrin + 1; 03365 t7(k+4) = q(j); 03366 } 03367 03368 prb1d(t7,7,&pos); 03369 03370 tot = (float)jtot + pos; 03371 03372 //if (q) free(q); 03373 if (t) free(t); 03374 03375 Dict retvals; 03376 //tot = 1; 03377 //qn = q(1); 03378 retvals["qn"] = qn; 03379 retvals["tot"] = tot; 03380 03381 if (q) free(q); 03382 03383 return retvals; 03384 }
Definition at line 3386 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(), and multiref_polar_ali_2d_local().
03386 { 03387 int nring = numr.size()/3; 03388 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03389 int maxrin = numr[numr.size()-1]; 03390 double qn; float tot; double qm; float tmt; 03391 float *circ1 = circ1p->get_data(); 03392 float *circ2 = circ2p->get_data(); 03393 /* 03394 c 03395 c checks both straight & mirrored positions 03396 c 03397 c input - fourier transforms of rings!! 03398 c circ1 already multiplied by weights! 03399 c 03400 */ 03401 03402 // dimension circ1(lcirc),circ2(lcirc) 03403 03404 // t(maxrin), q(maxrin), t7(-3:3) //maxrin+2 removed 03405 double *t, *q, t7[7]; 03406 03407 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 03408 float t1, t2, t3, t4, c1, c2, d1, d2, pos; 03409 03410 qn = 0.0f; 03411 qm = 0.0f; 03412 tot = 0.0f; 03413 tmt = 0.0f; 03414 #ifdef _WIN32 03415 ip = -(int)(log((float)maxrin)/log(2.0f)); 03416 #else 03417 ip = -(int)(log2(maxrin)); 03418 #endif //_WIN32 03419 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl; 03420 03421 // c - straight = circ1 * conjg(circ2) 03422 // zero q array 03423 03424 q = (double*)calloc(maxrin,sizeof(double)); 03425 03426 // t - mirrored = conjg(circ1) * conjg(circ2) 03427 // zero t array 03428 t = (double*)calloc(maxrin,sizeof(double)); 03429 03430 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03431 for (i=1; i<=nring; i++) { 03432 03433 numr3i = numr(3,i); // Number of samples of this ring 03434 numr2i = numr(2,i); // The beginning point of this ring 03435 03436 t1 = circ1(numr2i) * circ2(numr2i); 03437 q(1) += t1; 03438 t(1) += t1; 03439 03440 t1 = circ1(numr2i+1) * circ2(numr2i+1); 03441 if (numr3i == maxrin) { 03442 q(2) += t1; 03443 t(2) += t1; 03444 } else { 03445 q(numr3i+1) += t1; 03446 t(numr3i+1) += t1; 03447 } 03448 03449 for (j=3; j<=numr3i; j += 2) { 03450 jc = j+numr2i-1; 03451 03452 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03453 // ----- ----- ----- ----- 03454 // t1 t2 t3 t4 03455 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i 03456 // ----- ----- ----- ----- 03457 // t1 t2 t3 t4 03458 03459 c1 = circ1(jc); 03460 c2 = circ1(jc+1); 03461 d1 = circ2(jc); 03462 d2 = circ2(jc+1); 03463 03464 t1 = c1 * d1; 03465 t2 = c2 * d2; 03466 t3 = c1 * d2; 03467 t4 = c2 * d1; 03468 03469 q(j) += t1 + t2; 03470 q(j+1) += -t3 + t4; 03471 t(j) += t1 - t2; 03472 t(j+1) += -t3 - t4; 03473 } 03474 } 03475 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<" "<<t(j) <<endl; 03476 fftr_d(q,ip); 03477 03478 qn = -1.0e20; 03479 for (j=1; j<=maxrin; j++) {//cout <<" "<<j<<" "<<q(j) <<endl; 03480 if (q(j) >= qn) { 03481 qn = q(j); 03482 jtot = j; 03483 } 03484 } 03485 03486 for (k=-3; k<=3; k++) { 03487 j = ((jtot+k+maxrin-1)%maxrin)+1; 03488 t7(k+4) = q(j); 03489 } 03490 03491 // interpolate 03492 prb1d(t7,7,&pos); 03493 tot = (float)(jtot)+pos; 03494 // Do not interpolate 03495 //tot = (float)(jtot); 03496 03497 // mirrored 03498 fftr_d(t,ip); 03499 03500 // find angle 03501 qm = -1.0e20; 03502 for (j=1; j<=maxrin;j++) {//cout <<" "<<j<<" "<<t(j) <<endl; 03503 if ( t(j) >= qm ) { 03504 qm = t(j); 03505 jtot = j; 03506 } 03507 } 03508 03509 for (k=-3; k<=3; k++) { 03510 j = ((jtot+k+maxrin-1)%maxrin) + 1; 03511 t7(k+4) = t(j); 03512 } 03513 03514 // interpolate 03515 03516 prb1d(t7,7,&pos); 03517 tmt = float(jtot) + pos; 03518 // Do not interpolate 03519 //tmt = float(jtot); 03520 03521 free(t); 03522 free(q); 03523 03524 Dict retvals; 03525 retvals["qn"] = qn; 03526 retvals["tot"] = tot; 03527 retvals["qm"] = qm; 03528 retvals["tmt"] = tmt; 03529 return retvals; 03530 }
Dict Util::Crosrng_ms_delta | ( | EMData * | circ1, | |
EMData * | circ2, | |||
vector< int > | numr, | |||
float | delta_start, | |||
float | delta | |||
) | [static] |
Definition at line 3532 of file util_sparx.cpp.
References circ1, circ2, fftr_d(), EMAN::EMData::get_data(), log(), numr, q, EMAN::Dict::size(), t, t7, tmt, and tot.
Referenced by multiref_polar_ali_2d_delta().
03532 { 03533 int nring = numr.size()/3; 03534 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03535 int maxrin = numr[numr.size()-1]; 03536 double qn; float tot; double qm; float tmt; 03537 float *circ1 = circ1p->get_data(); 03538 float *circ2 = circ2p->get_data(); 03539 /* 03540 c 03541 c checks both straight & mirrored positions 03542 c 03543 c input - fourier transforms of rings!! 03544 c circ1 already multiplied by weights! 03545 c 03546 */ 03547 03548 // dimension circ1(lcirc),circ2(lcirc) 03549 03550 // t(maxrin), q(maxrin), t7(-3:3) //maxrin+2 removed 03551 double *t, *q, t7[7]; 03552 03553 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 03554 float t1, t2, t3, t4, c1, c2, d1, d2, pos; 03555 03556 qn = 0.0f; 03557 qm = 0.0f; 03558 tot = 0.0f; 03559 tmt = 0.0f; 03560 #ifdef _WIN32 03561 ip = -(int)(log((float)maxrin)/log(2.0f)); 03562 #else 03563 ip = -(int)(log2(maxrin)); 03564 #endif //_WIN32 03565 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl; 03566 03567 // c - straight = circ1 * conjg(circ2) 03568 // zero q array 03569 03570 q = (double*)calloc(maxrin,sizeof(double)); 03571 03572 // t - mirrored = conjg(circ1) * conjg(circ2) 03573 // zero t array 03574 t = (double*)calloc(maxrin,sizeof(double)); 03575 03576 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03577 for (i=1; i<=nring; i++) { 03578 03579 numr3i = numr(3,i); // Number of samples of this ring 03580 numr2i = numr(2,i); // The beginning point of this ring 03581 03582 t1 = circ1(numr2i) * circ2(numr2i); 03583 q(1) += t1; 03584 t(1) += t1; 03585 03586 t1 = circ1(numr2i+1) * circ2(numr2i+1); 03587 if (numr3i == maxrin) { 03588 q(2) += t1; 03589 t(2) += t1; 03590 } else { 03591 q(numr3i+1) += t1; 03592 t(numr3i+1) += t1; 03593 } 03594 03595 for (j=3; j<=numr3i; j += 2) { 03596 jc = j+numr2i-1; 03597 03598 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03599 // ----- ----- ----- ----- 03600 // t1 t2 t3 t4 03601 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i 03602 // ----- ----- ----- ----- 03603 // t1 t2 t3 t4 03604 03605 c1 = circ1(jc); 03606 c2 = circ1(jc+1); 03607 d1 = circ2(jc); 03608 d2 = circ2(jc+1); 03609 03610 t1 = c1 * d1; 03611 t2 = c2 * d2; 03612 t3 = c1 * d2; 03613 t4 = c2 * d1; 03614 03615 q(j) += t1 + t2; 03616 q(j+1) += -t3 + t4; 03617 t(j) += t1 - t2; 03618 t(j+1) += -t3 - t4; 03619 } 03620 } 03621 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<" "<<t(j) <<endl; 03622 fftr_d(q,ip); 03623 03624 qn = -1.0e20; 03625 03626 int jstart = 1+static_cast<int>(delta_start/360.0*maxrin); 03627 int jstep = static_cast<int>(delta/360.0*maxrin); 03628 if (jstep < 1) { jstep = 1; } 03629 03630 for (j=jstart; j<=maxrin; j+=jstep) {//cout <<" "<<j<<" "<<q(j) <<endl; 03631 if (q(j) >= qn) { 03632 qn = q(j); 03633 jtot = j; 03634 } 03635 } 03636 03637 //for (k=-3; k<=3; k++) { 03638 // j = ((jtot+k+maxrin-1)%maxrin)+1; 03639 // t7(k+4) = q(j); 03640 //} 03641 03642 // interpolate 03643 //prb1d(t7,7,&pos); 03644 //tot = (float)(jtot)+pos; 03645 // Do not interpolate 03646 tot = (float)(jtot); 03647 03648 // mirrored 03649 fftr_d(t,ip); 03650 03651 // find angle 03652 qm = -1.0e20; 03653 for (j=jstart; j<=maxrin;j+=jstep) {//cout <<" "<<j<<" "<<t(j) <<endl; 03654 if ( t(j) >= qm ) { 03655 qm = t(j); 03656 jtot = j; 03657 } 03658 } 03659 03660 //for (k=-3; k<=3; k++) { 03661 // j = ((jtot+k+maxrin-1)%maxrin) + 1; 03662 // t7(k+4) = t(j); 03663 //} 03664 03665 // interpolate 03666 03667 //prb1d(t7,7,&pos); 03668 //tmt = float(jtot) + pos; 03669 // Do not interpolate 03670 tmt = float(jtot); 03671 03672 free(t); 03673 free(q); 03674 03675 Dict retvals; 03676 retvals["qn"] = qn; 03677 retvals["tot"] = tot; 03678 retvals["qm"] = qm; 03679 retvals["tmt"] = tmt; 03680 return retvals; 03681 }
checks both straight & mirrored positions input - fourier transforms of rings!! circ1 already multiplied by weights! returns EM object with 1D ccf
Definition at line 4078 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.
04078 { 04079 04080 // dimension circ1(lcirc),circ2(lcirc) 04081 04082 int ip, jc, numr3i, numr2i, i, j; 04083 float t1, t2, t3, t4, c1, c2, d1, d2; 04084 04085 int nring = numr.size()/3; 04086 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 04087 int maxrin = numr[numr.size()-1]; 04088 04089 float* circ1b = circ1->get_data(); 04090 float* circ2b = circ2->get_data(); 04091 04092 // t(maxrin), q(maxrin) // removed +2 04093 double *t, *q; 04094 04095 q = (double*)calloc(maxrin,sizeof(double)); 04096 t = (double*)calloc(maxrin,sizeof(double)); 04097 04098 #ifdef _WIN32 04099 ip = -(int)(log((float)maxrin)/log(2.0f)); 04100 #else 04101 ip = -(int)(log2(maxrin)); 04102 #endif //_WIN32 04103 04104 // q - straight = circ1 * conjg(circ2) 04105 04106 // t - mirrored = conjg(circ1) * conjg(circ2) 04107 04108 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 04109 04110 for (i=1; i<=nring; i++) { 04111 04112 numr3i = numr(3,i); 04113 numr2i = numr(2,i); 04114 04115 t1 = circ1b(numr2i) * circ2b(numr2i); 04116 q(1) = q(1)+t1; 04117 t(1) = t(1)+t1; 04118 04119 t1 = circ1b(numr2i+1) * circ2b(numr2i+1); 04120 if (numr3i == maxrin) { 04121 q(2) += t1; 04122 t(2) += t1; 04123 } else { 04124 q(numr3i+1) += t1; 04125 t(numr3i+1) += t1; 04126 } 04127 04128 for (j=3; j<=numr3i; j=j+2) { 04129 jc = j+numr2i-1; 04130 04131 c1 = circ1b(jc); 04132 c2 = circ1b(jc+1); 04133 d1 = circ2b(jc); 04134 d2 = circ2b(jc+1); 04135 04136 t1 = c1 * d1; 04137 t3 = c1 * d2; 04138 t2 = c2 * d2; 04139 t4 = c2 * d1; 04140 04141 q(j) += t1 + t2; 04142 q(j+1) += - t3 + t4; 04143 t(j) += t1 - t2; 04144 t(j+1) += - t3 - t4; 04145 } 04146 } 04147 04148 // straight 04149 fftr_d(q,ip); 04150 04151 // mirrored 04152 fftr_d(t,ip); 04153 04154 EMData* out = new EMData(); 04155 out->set_size(maxrin,2,1); 04156 float *dout = out->get_data(); 04157 for (int i=0; i<maxrin; i++) {dout(i,0)=static_cast<float>(q[i]); dout(i,1)=static_cast<float>(t[i]);} 04158 //out->set_size(maxrin,1,1); 04159 //float *dout = out->get_data(); 04160 //for (int i=0; i<maxrin; i++) {dout(i,0)=q[i];} 04161 free(t); 04162 free(q); 04163 return out; 04164 }
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 4325 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.
04326 { 04327 04328 int ip, jc, numr3i, numr2i, i, j; 04329 float t1, t2, t3, t4, c1, c2, d1, d2; 04330 04331 int nring = numr.size()/3; 04332 int maxrin = numr[numr.size()-1]; 04333 04334 float* circ1b = circ1->get_data(); 04335 float* circ2b = circ2->get_data(); 04336 04337 double *t; 04338 04339 t = (double*)calloc(maxrin,sizeof(double)); 04340 04341 #ifdef _WIN32 04342 ip = -(int)(log((float)maxrin)/log(2.0f)); 04343 #else 04344 ip = -(int)(log2(maxrin)); 04345 #endif //_WIN32 04346 04347 // t - mirrored = conjg(circ1) * conjg(circ2) 04348 04349 for (i=1;i<=nring;i++) { 04350 04351 numr3i = numr(3,i); 04352 numr2i = numr(2,i); 04353 04354 t1 = circ1b(numr2i) * circ2b(numr2i); 04355 t(1) = t(1)+t1; 04356 04357 if (numr3i == maxrin) { 04358 t1 = circ1b(numr2i+1) * circ2b(numr2i+1); 04359 t(2) = t(2)+t1; 04360 } 04361 04362 for (j=3;j<=numr3i;j=j+2) { 04363 jc = j+numr2i-1; 04364 04365 c1 = circ1b(jc); 04366 c2 = circ1b(jc+1); 04367 d1 = circ2b(jc); 04368 d2 = circ2b(jc+1); 04369 04370 t1 = c1 * d1; 04371 t3 = c1 * d2; 04372 t2 = c2 * d2; 04373 t4 = c2 * d1; 04374 04375 t(j) = t(j) + t1 - t2; 04376 t(j+1) = t(j+1) - t3 - t4; 04377 } 04378 } 04379 04380 // mirrored 04381 fftr_d(t,ip); 04382 04383 EMData* out = new EMData(); 04384 out->set_size(maxrin,1,1); 04385 float *dout = out->get_data(); 04386 for (int i=0; i<maxrin; i++) dout[i]=static_cast<float>(t[i]); 04387 free(t); 04388 return out; 04389 04390 }
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 4254 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().
04255 { 04256 04257 int ip, jc, numr3i, numr2i, i, j; 04258 float t1, t2, t3, t4, c1, c2, d1, d2; 04259 04260 int nring = numr.size()/3; 04261 int maxrin = numr[numr.size()-1]; 04262 04263 float* circ1b = circ1->get_data(); 04264 float* circ2b = circ2->get_data(); 04265 04266 double *q; 04267 04268 q = (double*)calloc(maxrin,sizeof(double)); 04269 04270 #ifdef _WIN32 04271 ip = -(int)(log((float)maxrin)/log(2.0f)); 04272 #else 04273 ip = -(int)(log2(maxrin)); 04274 #endif //_WIN32 04275 04276 // q - straight = circ1 * conjg(circ2) 04277 04278 for (i=1;i<=nring;i++) { 04279 04280 numr3i = numr(3,i); 04281 numr2i = numr(2,i); 04282 04283 t1 = circ1b(numr2i) * circ2b(numr2i); 04284 q(1) = q(1)+t1; 04285 04286 if (numr3i == maxrin) { 04287 t1 = circ1b(numr2i+1) * circ2b(numr2i+1); 04288 q(2) = q(2)+t1; 04289 } else { 04290 t1 = circ1b(numr2i+1) * circ2b(numr2i+1); 04291 q(numr3i+1) = q(numr3i+1)+t1; 04292 } 04293 04294 for (j=3;j<=numr3i;j=j+2) { 04295 jc = j+numr2i-1; 04296 04297 c1 = circ1b(jc); 04298 c2 = circ1b(jc+1); 04299 d1 = circ2b(jc); 04300 d2 = circ2b(jc+1); 04301 04302 t1 = c1 * d1; 04303 t3 = c1 * d2; 04304 t2 = c2 * d2; 04305 t4 = c2 * d1; 04306 04307 q(j) = q(j) + t1 + t2; 04308 q(j+1) = q(j+1) - t3 + t4; 04309 } 04310 } 04311 04312 // straight 04313 fftr_d(q,ip); 04314 04315 EMData* out = new EMData(); 04316 out->set_size(maxrin,1,1); 04317 float *dout = out->get_data(); 04318 for (int i=0; i<maxrin; i++) dout[i]=static_cast<float>(q[i]); 04319 free(q); 04320 return out; 04321 04322 }
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 4182 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().
04182 { 04183 04184 // dimension circ1(lcirc),circ2(lcirc) 04185 04186 int ip, jc, numr3i, numr2i, i, j; 04187 float t1, t2, t3, t4, c1, c2, d1, d2; 04188 04189 int nring = numr.size()/3; 04190 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 04191 int maxrin = numr[numr.size()-1]; 04192 04193 float* circ1b = circ1->get_data(); 04194 float* circ2b = circ2->get_data(); 04195 04196 #ifdef _WIN32 04197 ip = -(int)(log((float)maxrin)/log(2.0f)); 04198 #else 04199 ip = -(int)(log2(maxrin)); 04200 #endif //_WIN32 04201 for (int i=1; i<=maxrin; i++) {q(i) = 0.0f; t(i) = 0.0f;} 04202 04203 // q - straight = circ1 * conjg(circ2) 04204 04205 // t - mirrored = conjg(circ1) * conjg(circ2) 04206 04207 for (i=1; i<=nring; i++) { 04208 04209 numr3i = numr(3,i); 04210 numr2i = numr(2,i); 04211 04212 t1 = circ1b(numr2i) * circ2b(numr2i); 04213 q(1) += t1; 04214 t(1) += t1; 04215 04216 t1 = circ1b(numr2i+1) * circ2b(numr2i+1); 04217 if (numr3i == maxrin) { 04218 q(2) += t1; 04219 t(2) += t1; 04220 } else { 04221 q(numr3i+1) += t1; 04222 t(numr3i+1) += t1; 04223 } 04224 04225 for (j=3; j<=numr3i; j=j+2) { 04226 jc = j+numr2i-1; 04227 04228 c1 = circ1b(jc); 04229 c2 = circ1b(jc+1); 04230 d1 = circ2b(jc); 04231 d2 = circ2b(jc+1); 04232 04233 t1 = c1 * d1; 04234 t3 = c1 * d2; 04235 t2 = c2 * d2; 04236 t4 = c2 * d1; 04237 04238 q(j) += t1 + t2; 04239 q(j+1) += -t3 + t4; 04240 t(j) += t1 - t2; 04241 t(j+1) += -t3 - t4; 04242 } 04243 } 04244 // straight 04245 fftr_q(q,ip); 04246 //for (int i=0; i<maxrin; i++) cout<<i<<" B "<<q[i]<<" "<<t[i]<<endl; 04247 04248 // mirrored 04249 fftr_q(t,ip); 04250 }
vector< float > Util::Crosrng_msg_vec_p | ( | EMData * | circ1, | |
EMData * | circ2, | |||
vector< int > | numr | |||
) | [static] |
Definition at line 4167 of file util_sparx.cpp.
References circ1, circ2, and Crosrng_msg_vec().
04167 { 04168 04169 int maxrin = numr[numr.size()-1]; 04170 04171 vector<float> r(2*maxrin); 04172 04173 Crosrng_msg_vec( circ1, circ2, numr, &r[0], &r[maxrin] ); 04174 04175 return r; 04176 }
Definition at line 3979 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().
03979 { 03980 int nring = numr.size()/3; 03981 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03982 int maxrin = numr[numr.size()-1]; 03983 double qn; float tot; 03984 float *circ1 = circ1p->get_data(); 03985 float *circ2 = circ2p->get_data(); 03986 /* 03987 c 03988 c checks only straight position 03989 c 03990 c input - fourier transforms of rings!! 03991 c circ1 already multiplied by weights! 03992 c 03993 */ 03994 03995 // dimension circ1(lcirc),circ2(lcirc) 03996 03997 // q(maxrin), t7(-3:3) //maxrin+2 removed 03998 double *q, t7[7]; 03999 04000 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 04001 float c1, c2, d1, d2, pos; 04002 04003 qn = 0.0; 04004 tot = 0.0; 04005 #ifdef _WIN32 04006 ip = -(int)(log((float)maxrin)/log(2.0f)); 04007 #else 04008 ip = -(int)(log2(maxrin)); 04009 #endif //_WIN32 04010 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl; 04011 04012 // c - straight = circ1 * conjg(circ2) 04013 // zero q array 04014 04015 q = (double*)calloc(maxrin,sizeof(double)); 04016 04017 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 04018 for (i=1; i<=nring; i++) { 04019 04020 numr3i = numr(3,i); // Number of samples of this ring 04021 numr2i = numr(2,i); // The beginning point of this ring 04022 04023 q(1) += circ1(numr2i) * circ2(numr2i); 04024 04025 if (numr3i == maxrin) q(2) += circ1(numr2i+1) * circ2(numr2i+1); 04026 else q(numr3i+1) += circ1(numr2i+1) * circ2(numr2i+1); 04027 04028 for (j=3; j<=numr3i; j += 2) { 04029 jc = j+numr2i-1; 04030 04031 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 04032 // ----- ----- ----- ----- 04033 // t1 t2 t3 t4 04034 04035 c1 = circ1(jc); 04036 c2 = circ1(jc+1); 04037 d1 = circ2(jc); 04038 d2 = circ2(jc+1); 04039 04040 q(j) += c1 * d1 + c2 * d2; 04041 q(j+1) += -c1 * d2 + c2 * d1; 04042 } 04043 } 04044 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<endl; 04045 fftr_d(q,ip); 04046 04047 qn = -1.0e20; 04048 for (j=1; j<=maxrin; j++) {//cout <<" "<<j<<" "<<q(j) <<endl; 04049 if (q(j) >= qn) { 04050 qn = q(j); 04051 jtot = j; 04052 } 04053 } 04054 04055 for (k=-3; k<=3; k++) { 04056 j = ((jtot+k+maxrin-1)%maxrin)+1; 04057 t7(k+4) = q(j); 04058 } 04059 04060 // interpolate 04061 prb1d(t7,7,&pos); 04062 tot = (float)(jtot)+pos; 04063 // Do not interpolate 04064 //*tot = (float)(jtot); 04065 04066 free(q); 04067 04068 Dict retvals; 04069 retvals["qn"] = qn; 04070 retvals["tot"] = tot; 04071 return retvals; 04072 }
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 3684 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().
03684 { 03685 int nring = numr.size()/3; 03686 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03687 int maxrin = numr[numr.size()-1]; 03688 double qn; float tot; double qm; float tmt; 03689 float *circ1 = circ1p->get_data(); 03690 float *circ2 = circ2p->get_data(); 03691 03692 // dimension circ1(lcirc),circ2(lcirc) 03693 03694 // t(maxrin), q(maxrin), t7(-3:3) //maxrin+2 removed 03695 double *t, *q, t7[7]; 03696 03697 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 03698 float t1, t2, t3, t4, c1, c2, d1, d2, pos; 03699 03700 qn = 0.0f; 03701 qm = 0.0f; 03702 tot = 0.0f; 03703 tmt = 0.0f; 03704 #ifdef _WIN32 03705 ip = -(int)(log((float)maxrin)/log(2.0f)); 03706 #else 03707 ip = -(int)(log2(maxrin)); 03708 #endif //_WIN32 03709 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl; 03710 03711 // c - straight = circ1 * conjg(circ2) 03712 // zero q array 03713 03714 q = (double*)calloc(maxrin,sizeof(double)); 03715 03716 // t - mirrored = conjg(circ1) * conjg(circ2) 03717 // zero t array 03718 t = (double*)calloc(maxrin,sizeof(double)); 03719 03720 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03721 for (i=1; i<=nring; i++) { 03722 03723 numr3i = numr(3,i); // Number of samples of this ring 03724 numr2i = numr(2,i); // The beginning point of this ring 03725 03726 t1 = circ1(numr2i) * circ2(numr2i); 03727 q(1) += t1; 03728 t(1) += t1; 03729 03730 t1 = circ1(numr2i+1) * circ2(numr2i+1); 03731 if (numr3i == maxrin) { 03732 q(2) += t1; 03733 t(2) += t1; 03734 } else { 03735 q(numr3i+1) += t1; 03736 t(numr3i+1) += t1; 03737 } 03738 03739 for (j=3; j<=numr3i; j += 2) { 03740 jc = j+numr2i-1; 03741 03742 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03743 // ----- ----- ----- ----- 03744 // t1 t2 t3 t4 03745 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i 03746 // ----- ----- ----- ----- 03747 // t1 t2 t3 t4 03748 03749 c1 = circ1(jc); 03750 c2 = circ1(jc+1); 03751 d1 = circ2(jc); 03752 d2 = circ2(jc+1); 03753 03754 t1 = c1 * d1; 03755 t2 = c2 * d2; 03756 t3 = c1 * d2; 03757 t4 = c2 * d1; 03758 03759 q(j) += t1 + t2; 03760 q(j+1) += -t3 + t4; 03761 t(j) += t1 - t2; 03762 t(j+1) += -t3 - t4; 03763 } 03764 } 03765 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<" "<<t(j) <<endl; 03766 fftr_d(q,ip); 03767 03768 int psi_range = int(psi_max/360.0*maxrin+0.5); 03769 const int psi_0 = 0; 03770 int psi_180 = int( 180.0/360.0*maxrin+0.5); 03771 03772 qn = -1.0e20; 03773 for (k=-psi_range; k<=psi_range; k++) { 03774 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; 03775 if (q(j) >= qn) { 03776 qn = q(j); 03777 jtot = j; 03778 } 03779 } 03780 03781 for (k=-psi_range; k<=psi_range; k++) { 03782 j = (k+psi_180+maxrin-1)%maxrin+1; //cout <<" 270 "<<j<<" "<<ang_n(j,modemo,maxrin) <<" "<<float(j)/maxrin*360.0<<" "<<q(j) <<endl; 03783 if (q(j) >= qn) { 03784 qn = q(j); 03785 jtot = j; 03786 } 03787 } 03788 03789 for (k=-3; k<=3; k++) { 03790 j = ((jtot+k+maxrin-1)%maxrin)+1; 03791 t7(k+4) = q(j); 03792 } 03793 03794 // interpolate 03795 prb1d(t7,7,&pos); 03796 tot = (float)(jtot)+pos; 03797 // Do not interpolate 03798 //tot = (float)(jtot); 03799 03800 // mirrored 03801 fftr_d(t,ip); 03802 03803 // find angle 03804 qm = -1.0e20; 03805 for (k=-psi_range; k<=psi_range; k++) { 03806 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; 03807 if (t(j) >= qm) { 03808 qm = t(j); 03809 jtot = j; 03810 } 03811 } 03812 03813 for (k=-psi_range; k<=psi_range; k++) { 03814 j = (k+psi_180+maxrin-1)%maxrin+1; //cout <<" 270 "<<j<<" "<<ang_n(j,modemo,maxrin) <<" "<<float(j)/maxrin*360.0<<" "<<q(j) <<endl; 03815 if (t(j) >= qm) { 03816 qm = t(j); 03817 jtot = j; 03818 } 03819 } 03820 03821 for (k=-3; k<=3; k++) { 03822 j = ((jtot+k+maxrin-1)%maxrin) + 1; 03823 t7(k+4) = t(j); 03824 } 03825 03826 // interpolate 03827 03828 prb1d(t7,7,&pos); 03829 tmt = float(jtot) + pos; 03830 // Do not interpolate 03831 //tmt = float(jtot); 03832 03833 free(t); 03834 free(q); 03835 03836 Dict retvals; 03837 retvals["qn"] = qn; 03838 retvals["tot"] = tot; 03839 retvals["qm"] = qm; 03840 retvals["tmt"] = tmt; 03841 return retvals; 03842 }
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 3845 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().
03845 { 03846 // flag 0 - straignt, 1 - mirror 03847 03848 int nring = numr.size()/3; 03849 int maxrin = numr[numr.size()-1]; 03850 double qn; float tot; double qm; float tmt; 03851 float *circ1 = circ1p->get_data(); 03852 float *circ2 = circ2p->get_data(); 03853 03854 double *q, t7[7]; 03855 03856 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 03857 float t1, t2, t3, t4, c1, c2, d1, d2, pos; 03858 03859 qn = 0.0f; 03860 qm = 0.0f; 03861 tot = 0.0f; 03862 tmt = 0.0f; 03863 #ifdef _WIN32 03864 ip = -(int)(log((float)maxrin)/log(2.0f)); 03865 #else 03866 ip = -(int)(log2(maxrin)); 03867 #endif //_WIN32 03868 03869 // c - straight = circ1 * conjg(circ2) 03870 // zero q array 03871 03872 q = (double*)calloc(maxrin,sizeof(double)); 03873 03874 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03875 if (flag==0) { 03876 for (i=1; i<=nring; i++) { 03877 03878 numr3i = numr(3,i); // Number of samples of this ring 03879 numr2i = numr(2,i); // The beginning point of this ring 03880 03881 t1 = circ1(numr2i) * circ2(numr2i); 03882 q(1) += t1; 03883 03884 t1 = circ1(numr2i+1) * circ2(numr2i+1); 03885 if (numr3i == maxrin) { 03886 q(2) += t1; 03887 } else { 03888 q(numr3i+1) += t1; 03889 } 03890 03891 for (j=3; j<=numr3i; j += 2) { 03892 jc = j+numr2i-1; 03893 03894 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03895 // ----- ----- ----- ----- 03896 // t1 t2 t3 t4 03897 03898 c1 = circ1(jc); 03899 c2 = circ1(jc+1); 03900 d1 = circ2(jc); 03901 d2 = circ2(jc+1); 03902 03903 t1 = c1 * d1; 03904 t3 = c1 * d2; 03905 t2 = c2 * d2; 03906 t4 = c2 * d1; 03907 03908 q(j) += t1 + t2; 03909 q(j+1) += -t3 + t4; 03910 } 03911 } 03912 } else { 03913 for (i=1; i<=nring; i++) { 03914 03915 numr3i = numr(3,i); // Number of samples of this ring 03916 numr2i = numr(2,i); // The beginning point of this ring 03917 03918 t1 = circ1(numr2i) * circ2(numr2i); 03919 q(1) += t1; 03920 03921 t1 = circ1(numr2i+1) * circ2(numr2i+1); 03922 if (numr3i == maxrin) { 03923 q(2) += t1; 03924 } else { 03925 q(numr3i+1) += t1; 03926 } 03927 03928 for (j=3; j<=numr3i; j += 2) { 03929 jc = j+numr2i-1; 03930 03931 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03932 // ----- ----- ----- ----- 03933 // t1 t2 t3 t4 03934 03935 c1 = circ1(jc); 03936 c2 = circ1(jc+1); 03937 d1 = circ2(jc); 03938 d2 = circ2(jc+1); 03939 03940 t1 = c1 * d1; 03941 t3 = c1 * d2; 03942 t2 = c2 * d2; 03943 t4 = c2 * d1; 03944 03945 q(j) += t1 - t2; 03946 q(j+1) += -t3 - t4; 03947 } 03948 } 03949 } 03950 fftr_d(q,ip); 03951 03952 qn = -1.0e20; 03953 int psi_pos = int(psi/360.0*maxrin+0.5); 03954 03955 for (k=-5; k<=5; k++) { 03956 j = (psi_pos+maxrin-1)%maxrin+1; 03957 if (q(j) >= qn) { 03958 qn = q(j); 03959 jtot = j; 03960 } 03961 } 03962 03963 for (k=-3; k<=3; k++) { 03964 j = ((jtot+k+maxrin-1)%maxrin)+1; 03965 t7(k+4) = q(j); 03966 } 03967 03968 // interpolate 03969 prb1d(t7,7,&pos); 03970 tot = (float)(jtot)+pos; 03971 free(q); 03972 03973 Dict retvals; 03974 retvals["qn"] = qn; 03975 retvals["tot"] = tot; 03976 return retvals; 03977 }
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 19084 of file util_sparx.cpp.
References EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), EMAN::EMData::set_ri(), EMAN::EMData::set_size(), tf(), and EMAN::EMData::update().
19085 { 19086 int ix, iy, iz; 19087 int i, j, k; 19088 int nr2, nl2; 19089 float dzz, az, ak; 19090 float scx, scy, scz; 19091 int offset = 2 - nx%2; 19092 int lsm = nx + offset; 19093 EMData* ctf_img1 = new EMData(); 19094 ctf_img1->set_size(lsm, ny, nz); 19095 float freq = 1.0f/(2.0f*ps); 19096 scx = 2.0f/float(nx); 19097 if(ny>=1) scy = 2.0f/float(ny); else scy=0.0f; 19098 if(nz>=1) scz = 2.0f/float(nz); else scz=0.0f; 19099 nr2 = ny/2 ; 19100 nl2 = nz/2 ; 19101 for ( k=0; k<nz;k++) { 19102 iz = k; if(k>nl2) iz=k-nz; 19103 for ( j=0; j<ny;j++) { 19104 iy = j; if(j>nr2) iy=j - ny; 19105 for ( i=0; i<lsm/2; i++) { 19106 ix=i; 19107 ak=pow(ix*ix*scx*scx+iy*scy*iy*scy+iz*scz*iz*scz, 0.5f)*freq; 19108 if(ak!=0) az=0.0; else az=M_PI; 19109 dzz = dz + dza/2.0f*sin(2*(az-azz*M_PI/180.0f)); 19110 (*ctf_img1) (i*2,j,k) = Util::tf(dzz, ak, voltage, cs, wgh, b_factor, sign); 19111 (*ctf_img1) (i*2+1,j,k) = 0.0f; 19112 } 19113 } 19114 } 19115 ctf_img1->update(); 19116 ctf_img1->set_complex(true); 19117 ctf_img1->set_ri(true); 19118 //ctf_img1->attr_dict["is_complex"] = 1; 19119 //ctf_img1->attr_dict["is_ri"] = 1; 19120 if(nx%2==0) ctf_img1->set_fftodd(false); else ctf_img1->set_fftodd(true); 19121 return ctf_img1; 19122 }
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 5366 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().
05366 { 05367 05368 if (image->is_complex()) throw ImageFormatException("Real image required for IntegerCyclicShift2DProcessor"); 05369 05370 int dx = params["dx"]; 05371 int dy = params["dy"]; 05372 int dz = params["dz"]; 05373 05374 // The reverse trick we're using shifts to the left (a negative shift) 05375 int nx = image->get_xsize(); 05376 dx %= nx; 05377 if (dx < 0) dx += nx; 05378 int ny = image->get_ysize(); 05379 dy %= ny; 05380 if (dy < 0) dy += ny; 05381 int nz = image->get_zsize(); 05382 dz %= nz; 05383 if (dz < 0) dz += nz; 05384 05385 int mx = -(dx - nx); 05386 int my = -(dy - ny); 05387 int mz = -(dz - nz); 05388 05389 float* data = image->get_data(); 05390 // x-reverses 05391 if (mx != 0) { 05392 for (int iz = 0; iz < nz; iz++) 05393 for (int iy = 0; iy < ny; iy++) { 05394 // reverses for column iy 05395 int offset = nx*iy + nx*ny*iz; // starting location for column iy in slice iz 05396 reverse(&data[offset],&data[offset+mx]); 05397 reverse(&data[offset+mx],&data[offset+nx]); 05398 reverse(&data[offset],&data[offset+nx]); 05399 } 05400 } 05401 // y-reverses 05402 if (my != 0) { 05403 for (int iz = 0; iz < nz; iz++) { 05404 int offset = nx*ny*iz; 05405 colreverse(&data[offset], &data[offset + my*nx], nx); 05406 colreverse(&data[offset + my*nx], &data[offset + ny*nx], nx); 05407 colreverse(&data[offset], &data[offset + ny*nx], nx); 05408 } 05409 } 05410 if (mz != 0) { 05411 slicereverse(&data[0], &data[mz*ny*nx], nx, ny); 05412 slicereverse(&data[mz*ny*nx], &data[nz*ny*nx], nx, ny); 05413 slicereverse(&data[0], &data[nz*ny*nx], nx ,ny); 05414 } 05415 image->update(); 05416 }
Definition at line 5160 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().
05161 { 05162 /* Exception Handle */ 05163 if (!img) { 05164 throw NullPointerException("NULL input image"); 05165 } 05166 /* ============================== */ 05167 05168 // Get the size of the input image 05169 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 05170 /* ============================== */ 05171 05172 05173 /* Exception Handle */ 05174 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) 05175 { 05176 LOGERR("Parameters for decimation cannot exceed the center of the image."); 05177 throw ImageDimensionException("Parameters for decimation cannot exceed the center of the image."); 05178 } 05179 /* ============================== */ 05180 05181 05182 /* Calculation of the start point */ 05183 int new_st_x=(nx/2)%x_step, new_st_y=(ny/2)%y_step, new_st_z=(nz/2)%z_step; 05184 /* ============================*/ 05185 05186 05187 /* Calculation of the size of the decimated image */ 05188 int rx=2*(nx/(2*x_step)), ry=2*(ny/(2*y_step)), rz=2*(nz/(2*z_step)); 05189 int r1=int(ceil((nx-(x_step*rx))/(1.f*x_step))), r2=int(ceil((ny-(y_step*ry))/(1.f*y_step))); 05190 int r3=int(ceil((nz-(z_step*rz))/(1.f*z_step))); 05191 if(r1>1){r1=1;} 05192 if(r2>1){r2=1;} 05193 if(r3>1){r3=1;} 05194 int new_nx=rx+r1, new_ny=ry+r2, new_nz=rz+r3; 05195 /* ===========================================*/ 05196 05197 05198 EMData* img2 = new EMData(); 05199 img2->set_size(new_nx,new_ny,new_nz); 05200 float *new_ptr = img2->get_data(); 05201 float *old_ptr = img->get_data(); 05202 int iptr, jptr, kptr = 0; 05203 for (int k=new_st_z; k<nz; k+=z_step) {jptr=0; 05204 for (int j=new_st_y; j<ny; j+=y_step) {iptr=0; 05205 for (int i=new_st_x; i<nx; i+=x_step) { 05206 new_ptr(iptr,jptr,kptr) = old_ptr(i,j,k); 05207 iptr++;} 05208 jptr++;} 05209 kptr++;} 05210 img2->update(); 05211 return img2; 05212 }
void Util::disorder2 | ( | double * | x, | |
double * | y, | |||
int * | key, | |||
int | len | |||
) | [static] |
Definition at line 7596 of file util_sparx.cpp.
References ENTERFUNC, and EXITFUNC.
07597 { 07598 ENTERFUNC; 07599 int k, i; 07600 for(i=0; i<len; i++) key[i]=i+1; 07601 07602 for(i = 0; i<len;i++){ 07603 k = rand()%len; 07604 std::swap(key[k], key[i]); 07605 std::swap(x[k], x[i]); 07606 std::swap(y[k], y[i]); 07607 } 07608 EXITFUNC; 07609 }
Definition at line 17555 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().
17556 { 17557 ENTERFUNC; 17558 /* Exception Handle */ 17559 if (!img) { 17560 throw NullPointerException("NULL input image"); 17561 } 17562 /* ========= img /= img1 ===================== */ 17563 17564 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17565 int size = nx*ny*nz; 17566 float *img_ptr = img->get_data(); 17567 float *img1_ptr = img1->get_data(); 17568 if(img->is_complex()) { 17569 for (int i=0; i<size; i+=2) { 17570 if(img1_ptr[i] > 1.e-10f) { 17571 img_ptr[i] /= img1_ptr[i]; 17572 img_ptr[i+1] /= img1_ptr[i]; 17573 } else img_ptr[i] = img_ptr[i+1] = 0.0f; 17574 } 17575 } else throw ImageFormatException("Only Fourier image allowed"); 17576 17577 img->update(); 17578 17579 EXITFUNC; 17580 }
Definition at line 17526 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().
17527 { 17528 ENTERFUNC; 17529 /* Exception Handle */ 17530 if (!img) { 17531 throw NullPointerException("NULL input image"); 17532 } 17533 /* ========= img /= img1 ===================== */ 17534 17535 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17536 int size = nx*ny*nz; 17537 float *img_ptr = img->get_data(); 17538 float *img1_ptr = img1->get_data(); 17539 if(img->is_complex()) { 17540 float sq2; 17541 for (int i=0; i<size; i+=2) { 17542 sq2 = 1.0f/(img1_ptr[i] * img1_ptr[i] + img1_ptr[i+1] * img1_ptr[i+1]); 17543 float tmp = sq2*(img_ptr[i] * img1_ptr[i] + img_ptr[i+1] * img1_ptr[i+1]) ; 17544 img_ptr[i+1] = sq2*(img_ptr[i+1] * img1_ptr[i] - img_ptr[i] * img1_ptr[i+1]) ; 17545 img_ptr[i] = tmp; 17546 } 17547 } else { 17548 for (int i=0; i<size; i++) img_ptr[i] /= img1_ptr[i]; 17549 } 17550 img->update(); 17551 17552 EXITFUNC; 17553 }
Definition at line 17351 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().
17352 { 17353 ENTERFUNC; 17354 /* Exception Handle */ 17355 if (!img) { 17356 throw NullPointerException("NULL input image"); 17357 } 17358 /* ========= img /= img1 ===================== */ 17359 17360 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17361 int size = nx*ny*nz; 17362 EMData * img2 = img->copy_head(); 17363 float *img_ptr =img->get_data(); 17364 float *img1_ptr = img1->get_data(); 17365 float *img2_ptr = img2->get_data(); 17366 if(img->is_complex()) { 17367 for (int i=0; i<size; i+=2) { 17368 if(img1_ptr[i] > 1.e-10f) { 17369 img2_ptr[i] = img_ptr[i] /img1_ptr[i]; 17370 img2_ptr[i+1] = img_ptr[i+1]/img1_ptr[i]; 17371 } else img2_ptr[i] = img2_ptr[i+1] = 0.0f; 17372 } 17373 } else throw ImageFormatException("Only Fourier image allowed"); 17374 17375 img->update(); 17376 17377 EXITFUNC; 17378 return img2; 17379 }
Definition at line 17318 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().
17319 { 17320 ENTERFUNC; 17321 /* Exception Handle */ 17322 if (!img) { 17323 throw NullPointerException("NULL input image"); 17324 } 17325 /* ============== output = img / img1 ================ */ 17326 17327 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17328 int size = nx*ny*nz; 17329 EMData * img2 = img->copy_head(); 17330 float *img_ptr =img->get_data(); 17331 float *img2_ptr = img2->get_data(); 17332 float *img1_ptr = img1->get_data(); 17333 if(img->is_complex()) { 17334 float sq2; 17335 for (int i=0; i<size; i+=2) { 17336 sq2 = 1.0f/(img1_ptr[i] * img1_ptr[i] + img1_ptr[i+1] * img1_ptr[i+1]); 17337 img2_ptr[i] = sq2*(img_ptr[i] * img1_ptr[i] + img_ptr[i+1] * img1_ptr[i+1]) ; 17338 img2_ptr[i+1] = sq2*(img_ptr[i+1] * img1_ptr[i] - img_ptr[i] * img1_ptr[i+1]) ; 17339 } 17340 img2->set_complex(true); 17341 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17342 } else { 17343 for (int i=0; i<size; i++) img2_ptr[i] = img_ptr[i] / img1_ptr[i]; 17344 img2->update(); 17345 } 17346 17347 EXITFUNC; 17348 return img2; 17349 }
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 1968 of file util.h.
Referenced by EMAN::IterationAverager::finish().
float Util::ener | ( | EMData * | ave, | |
vector< int > | numr | |||
) | [static] |
Definition at line 4407 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), numr, and PI2.
Referenced by ener_tot().
04407 { 04408 ENTERFUNC; 04409 long double ener,en; 04410 04411 int nring = numr.size()/3; 04412 float *aveptr = ave->get_data(); 04413 04414 ener = 0.0; 04415 for (int i=1; i<=nring; i++) { 04416 int numr3i = numr(3,i); 04417 int np = numr(2,i)-1; 04418 float tq = static_cast<float>(PI2*numr(1,i)/numr3i); 04419 en = tq*(aveptr[np]*aveptr[np]+aveptr[np+1]*aveptr[np+1])*0.5; 04420 for (int j=np+2; j<np+numr3i-1; j++) en += tq*aveptr[j]*aveptr[j]; 04421 ener += en/numr3i; 04422 } 04423 EXITFUNC; 04424 return static_cast<float>(ener); 04425 }
float Util::ener_tot | ( | const vector< EMData * > & | data, | |
vector< int > | numr, | |||
vector< float > | tot | |||
) | [static] |
Definition at line 4427 of file util_sparx.cpp.
References ener(), ENTERFUNC, EXITFUNC, get_data(), numr, and PI2.
04427 { 04428 ENTERFUNC; 04429 long double ener, en; 04430 float arg, cs, si; 04431 04432 int nima = data.size(); 04433 int nring = numr.size()/3; 04434 int maxrin = numr(3,nring); 04435 04436 ener = 0.0; 04437 for (int i=1; i<=nring; i++) { 04438 int numr3i = numr(3,i); 04439 int np = numr(2,i)-1; 04440 float tq = static_cast<float>(PI2*numr(1,i)/numr3i); 04441 float temp1 = 0.0, temp2 = 0.0; 04442 for (int kk=0; kk<nima; kk++) { 04443 float *ptr = data[kk]->get_data(); 04444 temp1 += ptr[np]; 04445 temp2 += static_cast<float>(ptr[np+1]*cos(PI2*(tot[kk]-1.0f)/2.0f*numr3i/maxrin)); 04446 } 04447 en = tq*(temp1*temp1+temp2*temp2)*0.5; 04448 for (int j=2; j<numr3i; j+=2) { 04449 float tempr = 0.0, tempi = 0.0; 04450 for (int kk=0; kk<nima; kk++) { 04451 float *ptr = data[kk]->get_data(); 04452 arg = static_cast<float>( PI2*(tot[kk]-1.0)*(j/2)/maxrin ); 04453 cs = cos(arg); 04454 si = sin(arg); 04455 tempr += ptr[np + j]*cs - ptr[np + j +1]*si; 04456 tempi += ptr[np + j]*si + ptr[np + j +1]*cs; 04457 } 04458 en += tq*(tempr*tempr+tempi*tempi); 04459 } 04460 ener += en/numr3i; 04461 } 04462 EXITFUNC; 04463 return static_cast<float>(ener); 04464 }
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 1220 of file util.cpp.
Referenced by EMAN::Symmetry3D::cache_au_planes().
01221 { 01222 int x=0,y=1,z=2; 01223 plane[0] = p1[y]*(p2[z]-p3[z])+p2[y]*(p3[z]-p1[z])+p3[y]*(p1[z]-p2[z]); 01224 plane[1] = p1[z]*(p2[x]-p3[x])+p2[z]*(p3[x]-p1[x])+p3[z]*(p1[x]-p2[x]); 01225 plane[2] = p1[x]*(p2[y]-p3[y])+p2[x]*(p3[y]-p1[y])+p3[x]*(p1[y]-p2[y]); 01226 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]); 01227 plane[3] = -plane[3]; 01228 }
float Util::eval | ( | char * | images, | |
EMData * | img, | |||
vector< int > | S, | |||
int | N, | |||
int | K, | |||
int | size | |||
) | [static] |
Definition at line 6944 of file util_sparx.cpp.
References EMAN::EMData::get_data(), and EMAN::EMData::read_image().
06945 { 06946 int j,d; 06947 EMData * e = new EMData(); 06948 float *eptr, *imgptr; 06949 imgptr = img->get_data(); 06950 float SSE = 0.f; 06951 for (j = 0 ; j < N ; j++) { 06952 e->read_image(images,S[j]); 06953 eptr = e->get_data(); 06954 for (d = 0; d < size; d++) { 06955 SSE += ((eptr[d] - imgptr[d])*(eptr[d] - imgptr[d]));} 06956 } 06957 delete e; 06958 return SSE; 06959 }
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 507 of file util_sparx.cpp.
References angles, dgr_to_rad, phi, and theta.
00508 { 00509 vector<float> angles; 00510 float psi = 0.0; 00511 if ((0.0 == t1)&&(0.0 == t2)||(t1 >= t2)) { 00512 t1 = 0.0f; 00513 t2 = 90.0f; 00514 } 00515 if ((0.0 == p1)&&(0.0 == p2)||(p1 >= p2)) { 00516 p1 = 0.0f; 00517 p2 = 359.9f; 00518 } 00519 bool skip = ((t1 < 90.0)&&(90.0 == t2)&&(0.0 == p1)&&(p2 > 180.0)); 00520 for (float theta = t1; theta <= t2; theta += delta) { 00521 float detphi; 00522 int lt; 00523 if ((0.0 == theta)||(180.0 == theta)) { 00524 detphi = 360.0f; 00525 lt = 1; 00526 } else { 00527 detphi = delta/sin(theta*static_cast<float>(dgr_to_rad)); 00528 lt = int((p2 - p1)/detphi)-1; 00529 if (lt < 1) lt = 1; 00530 detphi = (p2 - p1)/lt; 00531 } 00532 for (int i = 0; i < lt; i++) { 00533 float phi = p1 + i*detphi; 00534 if (skip&&(90.0 == theta)&&(phi > 180.0)) continue; 00535 angles.push_back(phi); 00536 angles.push_back(theta); 00537 angles.push_back(psi); 00538 } 00539 } 00540 return angles; 00541 }
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 20225 of file util_sparx.cpp.
References k_means_cont_table_().
Referenced by initial_prune().
20225 { 20226 20227 20228 if (size_next <= T) return 0; 20229 20230 // take the intx of next and cur 20231 int* curintx2; 20232 int nintx = Util::k_means_cont_table_(curintx,next+2, curintx2, size_curintx, size_next,0); 20233 if (nintx <= T) return 0; 20234 20235 int old_depth=depth; 20236 if (depth == partref) depth = depth + 1; // we skip classes in partref 20237 if (depth == (nParts)) { if (old_depth>0) return 1;} 20238 20239 // have not yet reached a leaf, and current weight is still greather than T, so keep on going. 20240 20241 curintx2 = new int[nintx]; // put the intersection set in here 20242 Util::k_means_cont_table_(curintx,next+2,curintx2, size_curintx, size_next,1); 20243 20244 // if (old_depth > 0) {delete[] curintx;} // don't delete when depth == 0 because curintx in that case is a pointer into Parts 20245 20246 // we now consider each of the classes in partition (depth+1) in turn 20247 bool gt_thresh; 20248 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 20249 20250 for (int i=0; i < num_classes; i++){ 20251 if (*(Parts[depth][i]+1) < 1) continue; // class is not active so move on 20252 size_next = (*(dimClasses + depth*K+(*(Parts[depth][i])) ))-2; 20253 gt_thresh = explore(Parts,dimClasses, nParts, K, T, partref, curintx2,nintx, Parts[depth][i], size_next, depth+1); 20254 if (gt_thresh) return 1; 20255 } 20256 delete[] curintx2; 20257 return 0; 20258 }
int * Util::explore2 | ( | int * | argParts, | |
int * | Indices, | |||
int * | dimClasses, | |||
int | nParts, | |||
int | K, | |||
int | newT, | |||
int * | curintx, | |||
int | size_curintx, | |||
int * | next, | |||
int | size_next, | |||
int | depth | |||
) | [static] |
Definition at line 20074 of file util_sparx.cpp.
References explore2(), and k_means_cont_table_().
20074 { 20075 // depth is the level which is going to be explored in the current iteration 20076 int* curintx2; 20077 20078 int nintx = size_curintx; 20079 20080 // take the intx of next and cur 20081 if (depth >0){ 20082 nintx = Util::k_means_cont_table_(curintx,next, curintx2, size_curintx, size_next,0); 20083 if (nintx <= newT) {curintx2 = new int[1]; *curintx2=0;return curintx2;} 20084 } 20085 20086 // we're at a leaf so return. 20087 if (depth == (nParts-1)) { curintx2 = new int[1]; *curintx2 = nintx; return curintx2;} 20088 20089 20090 // have not yet reached a leaf, and current weight is still greather than T, so keep on going. 20091 20092 if (depth > 0){ 20093 curintx2 = new int[nintx]; // put the intersection set in here 20094 Util::k_means_cont_table_(curintx,next,curintx2, size_curintx, size_next,1); 20095 } 20096 20097 if (depth == 0){ 20098 // set curintx2 to curintx 20099 curintx2 = new int[size_curintx]; 20100 for (int cp = 0; cp < size_curintx; cp++) *(curintx2+cp) = *(curintx+cp); 20101 } 20102 20103 20104 // recursion (non-leaf case) 20105 depth=depth+1; 20106 int* curmax = new int[nParts-depth+1]; 20107 *curmax=0; 20108 int* ret; 20109 // we now consider each of the classes in partition depth in turn 20110 for (int i=0; i < K; i++){ 20111 20112 if (*(argParts + Indices[depth*K+i] + 1) < 1) continue; // class is not active so move on 20113 size_next = (*(dimClasses + depth*K+i ))-2; 20114 if (size_next <= newT) continue; 20115 ret = Util::explore2(argParts,Indices, dimClasses, nParts, K, newT, curintx2, nintx, argParts + Indices[depth*K+i] + 2, size_next, depth); 20116 if (*ret > *curmax && *ret > newT){ 20117 *curmax = *ret; 20118 *(curmax+1)=i; 20119 for (int j=0; j<nParts-depth-1; j++) { *(curmax+2 + j) = *(ret+1+j);} 20120 } 20121 delete[] ret; 20122 } 20123 20124 delete[] curintx2; 20125 return curmax; 20126 }
Dict Util::ExpMinus4YSqr | ( | float | ymax, | |
int | nsamples | |||
) | [static] |
Definition at line 5924 of file util_sparx.cpp.
05925 { 05926 //exp(-16) is 1.0E-7 approximately) 05927 vector<float> expvect; 05928 05929 double inc = double(ymax)/nsamples; 05930 double temp; 05931 for(int i =0;i<nsamples;i++) { 05932 temp = exp((-4*(i*inc)*(i*inc))); 05933 expvect.push_back(float(temp)); 05934 } 05935 expvect.push_back(0.0); 05936 Dict lookupdict; 05937 lookupdict["table"] = expvect; 05938 lookupdict["ymax"] = ymax; 05939 lookupdict["nsamples"] = nsamples; 05940 05941 return lookupdict; 05942 }
complex< float > Util::extractpoint2 | ( | int | nx, | |
int | ny, | |||
float | nuxnew, | |||
float | nuynew, | |||
EMData * | fimage, | |||
Util::KaiserBessel & | kb | |||
) | [static] |
Definition at line 1685 of file util_sparx.cpp.
References EMAN::EMData::cmplx(), EMAN::Util::KaiserBessel::i0win_tab(), ImageDimensionException, and round().
01685 { 01686 01687 int nxreal = nx - 2; 01688 if (nxreal != ny) 01689 throw ImageDimensionException("extractpoint requires ny == nx"); 01690 int nhalf = nxreal/2; 01691 bool flip = (nuxnew < 0.f); 01692 if (flip) { 01693 nuxnew *= -1; 01694 nuynew *= -1; 01695 } 01696 if (nuynew >= nhalf-0.5) { 01697 nuynew -= nxreal; 01698 } else if (nuynew < -nhalf-0.5) { 01699 nuynew += nxreal; 01700 } 01701 01702 // put (xnew,ynew) on a grid. The indices will be wrong for 01703 // the Fourier elements in the image, but the grid sizing will 01704 // be correct. 01705 int ixn = int(Util::round(nuxnew)); 01706 int iyn = int(Util::round(nuynew)); 01707 01708 // set up some temporary weighting arrays 01709 static float wy[7]; 01710 static float wx[7]; 01711 01712 float iynn = nuynew - iyn; 01713 wy[0] = kb.i0win_tab(iynn+3); 01714 wy[1] = kb.i0win_tab(iynn+2); 01715 wy[2] = kb.i0win_tab(iynn+1); 01716 wy[3] = kb.i0win_tab(iynn); 01717 wy[4] = kb.i0win_tab(iynn-1); 01718 wy[5] = kb.i0win_tab(iynn-2); 01719 wy[6] = kb.i0win_tab(iynn-3); 01720 01721 float ixnn = nuxnew - ixn; 01722 wx[0] = kb.i0win_tab(ixnn+3); 01723 wx[1] = kb.i0win_tab(ixnn+2); 01724 wx[2] = kb.i0win_tab(ixnn+1); 01725 wx[3] = kb.i0win_tab(ixnn); 01726 wx[4] = kb.i0win_tab(ixnn-1); 01727 wx[5] = kb.i0win_tab(ixnn-2); 01728 wx[6] = kb.i0win_tab(ixnn-3); 01729 01730 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]); 01731 01732 complex<float> result(0.f,0.f); 01733 if ((ixn >= 3) && (ixn <= nhalf-3) && (iyn >= -nhalf+3) && (iyn <= nhalf-4)) { 01734 // (xin,yin) not within window border from the edge 01735 for (int iy = 0; iy < 7; iy++) { 01736 int iyp = iyn + iy - 3 ; 01737 for (int ix = 0; ix < 7; ix++) { 01738 int ixp = ixn + ix - 3; 01739 float w = wx[ix]*wy[iy]; 01740 complex<float> val = fimage->cmplx(ixp,iyp); 01741 result += val*w; 01742 } 01743 } 01744 } else { 01745 // points that "stick out" 01746 for (int iy = 0; iy < 7; iy++) { 01747 int iyp = iyn + iy - 3; 01748 for (int ix = 0; ix < 7; ix++) { 01749 int ixp = ixn + ix - 3; 01750 bool mirror = false; 01751 int ixt = ixp, iyt = iyp; 01752 if (ixt < 0) { 01753 ixt = -ixt; 01754 iyt = -iyt; 01755 mirror = !mirror; 01756 } 01757 if (ixt > nhalf) { 01758 ixt = nxreal - ixt; 01759 iyt = -iyt; 01760 mirror = !mirror; 01761 } 01762 if (iyt > nhalf-1) iyt -= nxreal; 01763 if (iyt < -nhalf) iyt += nxreal; 01764 float w = wx[ix]*wy[iy]; 01765 complex<float> val = fimage->cmplx(ixt,iyt); 01766 if (mirror) result += conj(val)*w; 01767 else result += val*w; 01768 } 01769 } 01770 } 01771 if (flip) result = conj(result)/wsum; 01772 else result /= wsum; 01773 return result; 01774 }
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 781 of file util.cpp.
00781 { 00782 if (f>=1.0) return 0.0; 00783 if (f<=-1.0) return M_PI; 00784 00785 static float *mem = (float *)malloc(sizeof(float)*2001); 00786 static bool needinit=true; 00787 00788 00789 if (needinit) { 00790 needinit=false; 00791 for (int i=0; i<=2000; i++) mem[i]=(float)acos(i/1000.0-1.0); 00792 } 00793 float f2=f*1000.0f+1000.0f; 00794 00795 int g=(int)(f2+.5); 00796 00797 return mem[g]; 00798 00799 // This version interpolates, but is slower 00800 /*int g=(int)f2; 00801 f2-=g; 00802 return mem[g+1]*f2+mem[g]*(1.0-f2);*/ 00803 }
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 765 of file util.cpp.
Referenced by EMAN::FourierInserter3DMode5::insert_pixel(), EMAN::FourierInserter3DMode3::insert_pixel(), EMAN::FourierInserter3DMode2::insert_pixel(), and EMAN::FourierReconstructor::pixel_at().
00765 { 00766 static float *mem = (float *)malloc(sizeof(float)*1000); 00767 static bool needinit=true; 00768 00769 if (needinit) { 00770 needinit=false; 00771 for (int i=0; i<1000; i++) mem[i]=(float)exp(-i/50.0); 00772 } 00773 if (f>0 || f<-19.98) return exp(f); 00774 int g=(int)(-f*50.0+0.5); 00775 00776 return mem[g]; 00777 }
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 1673 of file util.h.
Referenced by EMAN::CtfAverager::add_image(), EMAN::EMData::cut_slice(), EMAN::EMData::dot_rotate_translate(), EMAN::CtfAverager::finish(), EMAN::SymSearchProcessor::process_inplace(), EMAN::AddRandomNoiseProcessor::process_inplace(), EMAN::RotationalAverageProcessor::process_inplace(), EMAN::StandardProjector::project3d(), EMAN::EMData::rotate_translate(), 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 2618 of file util_sparx.cpp.
References abs, bi, br, sgn(), status, t, and tab1.
Referenced by fftr_d().
02619 { 02620 double rni,sgn,tr1,tr2,ti1,ti2; 02621 double cc,c,ss,s,t,x2,x3,x4,x5; 02622 int b3,b4,b5,b6,b7,b56; 02623 int n, k, l, j, i, ix0, ix1, status=0; 02624 02625 const double tab1[] = { 02626 9.58737990959775e-5, 02627 1.91747597310703e-4, 02628 3.83495187571395e-4, 02629 7.66990318742704e-4, 02630 1.53398018628476e-3, 02631 3.06795676296598e-3, 02632 6.13588464915449e-3, 02633 1.22715382857199e-2, 02634 2.45412285229123e-2, 02635 4.90676743274181e-2, 02636 9.80171403295604e-2, 02637 1.95090322016128e-1, 02638 3.82683432365090e-1, 02639 7.07106781186546e-1, 02640 1.00000000000000, 02641 }; 02642 02643 n=(int)pow(2.0f,ln); 02644 02645 k=abs(ks); 02646 l=16-ln; 02647 b3=n*k; 02648 b6=b3; 02649 b7=k; 02650 if (ks > 0) { 02651 sgn=1.0f; 02652 } else { 02653 sgn=-1.0f; 02654 rni=1.0f/(float)(n); 02655 j=1; 02656 for (i=1; i<=n; i++) { 02657 br(j)=br(j)*rni; 02658 bi(j)=bi(j)*rni; 02659 j=j+k; 02660 } 02661 } 02662 02663 L12: 02664 b6=b6/2; 02665 b5=b6; 02666 b4=2*b6; 02667 b56=b5-b6; 02668 02669 L14: 02670 tr1=br(b5+1); 02671 ti1=bi(b5+1); 02672 tr2=br(b56+1); 02673 ti2=bi(b56+1); 02674 02675 br(b5+1)=tr2-tr1; 02676 bi(b5+1)=ti2-ti1; 02677 br(b56+1)=tr1+tr2; 02678 bi(b56+1)=ti1+ti2; 02679 02680 b5=b5+b4; 02681 b56=b5-b6; 02682 if ( b5 <= b3 ) goto L14; 02683 if ( b6 == b7 ) goto L20; 02684 02685 b4=b7; 02686 cc=2.0f*pow(tab1(l),2); 02687 c=1.0f-cc; 02688 l++; 02689 ss=sgn*tab1(l); 02690 s=ss; 02691 02692 L16: 02693 b5=b6+b4; 02694 b4=2*b6; 02695 b56=b5-b6; 02696 02697 L18: 02698 tr1=br(b5+1); 02699 ti1=bi(b5+1); 02700 tr2=br(b56+1); 02701 ti2=bi(b56+1); 02702 br(b5+1)=c*(tr2-tr1)-s*(ti2-ti1); 02703 bi(b5+1)=s*(tr2-tr1)+c*(ti2-ti1); 02704 br(b56+1)=tr1+tr2; 02705 bi(b56+1)=ti1+ti2; 02706 02707 b5=b5+b4; 02708 b56=b5-b6; 02709 if ( b5 <= b3 ) goto L18; 02710 b4=b5-b6; 02711 b5=b4-b3; 02712 c=-c; 02713 b4=b6-b5; 02714 if ( b5 < b4 ) goto L16; 02715 b4=b4+b7; 02716 if ( b4 >= b5 ) goto L12; 02717 02718 t=c-cc*c-ss*s; 02719 s=s+ss*c-cc*s; 02720 c=t; 02721 goto L16; 02722 02723 L20: 02724 ix0=b3/2; 02725 b3=b3-b7; 02726 b4=0; 02727 b5=0; 02728 b6=ix0; 02729 ix1=0; 02730 if (b6 == b7) goto EXIT; 02731 02732 L22: 02733 b4=b3-b4; 02734 b5=b3-b5; 02735 x2=br(b4+1); 02736 x3=br(b5+1); 02737 x4=bi(b4+1); 02738 x5=bi(b5+1); 02739 br(b4+1)=x3; 02740 br(b5+1)=x2; 02741 bi(b4+1)=x5; 02742 bi(b5+1)=x4; 02743 if(b6 < b4) goto L22; 02744 02745 L24: 02746 b4=b4+b7; 02747 b5=b6+b5; 02748 x2=br(b4+1); 02749 x3=br(b5+1); 02750 x4=bi(b4+1); 02751 x5=bi(b5+1); 02752 br(b4+1)=x3; 02753 br(b5+1)=x2; 02754 bi(b4+1)=x5; 02755 bi(b5+1)=x4; 02756 ix0=b6; 02757 02758 L26: 02759 ix0=ix0/2; 02760 ix1=ix1-ix0; 02761 if( ix1 >= 0) goto L26; 02762 02763 ix0=2*ix0; 02764 b4=b4+b7; 02765 ix1=ix1+ix0; 02766 b5=ix1; 02767 if ( b5 >= b4) goto L22; 02768 if ( b4 < b6) goto L24; 02769 02770 EXIT: 02771 status = 0; 02772 }
void Util::fftc_q | ( | float * | br, | |
float * | bi, | |||
int | ln, | |||
int | ks | |||
) | [static] |
Definition at line 2775 of file util_sparx.cpp.
References abs, bi, br, sgn(), status, t, and tab1.
Referenced by fftr_q().
02776 { 02777 // dimension br(1),bi(1) 02778 02779 int b3,b4,b5,b6,b7,b56; 02780 int n, k, l, j, i, ix0, ix1; 02781 float rni, tr1, ti1, tr2, ti2, cc, c, ss, s, t, x2, x3, x4, x5, sgn; 02782 int status=0; 02783 02784 const float tab1[] = { 02785 9.58737990959775e-5f, 02786 1.91747597310703e-4f, 02787 3.83495187571395e-4f, 02788 7.66990318742704e-4f, 02789 1.53398018628476e-3f, 02790 3.06795676296598e-3f, 02791 6.13588464915449e-3f, 02792 1.22715382857199e-2f, 02793 2.45412285229123e-2f, 02794 4.90676743274181e-2f, 02795 9.80171403295604e-2f, 02796 1.95090322016128e-1f, 02797 3.82683432365090e-1f, 02798 7.07106781186546e-1f, 02799 1.00000000000000f, 02800 }; 02801 02802 n=(int)pow(2.0f,ln); 02803 02804 k=abs(ks); 02805 l=16-ln; 02806 b3=n*k; 02807 b6=b3; 02808 b7=k; 02809 if( ks > 0 ) { 02810 sgn=1.0f; 02811 } else { 02812 sgn=-1.0f; 02813 rni=1.0f/(float)n; 02814 j=1; 02815 for (i=1; i<=n; i++) { 02816 br(j)=br(j)*rni; 02817 bi(j)=bi(j)*rni; 02818 j=j+k; 02819 } 02820 } 02821 L12: 02822 b6=b6/2; 02823 b5=b6; 02824 b4=2*b6; 02825 b56=b5-b6; 02826 L14: 02827 tr1=br(b5+1); 02828 ti1=bi(b5+1); 02829 02830 tr2=br(b56+1); 02831 ti2=bi(b56+1); 02832 02833 br(b5+1)=tr2-tr1; 02834 bi(b5+1)=ti2-ti1; 02835 br(b56+1)=tr1+tr2; 02836 bi(b56+1)=ti1+ti2; 02837 02838 b5=b5+b4; 02839 b56=b5-b6; 02840 if ( b5 <= b3 ) goto L14; 02841 if ( b6 == b7 ) goto L20; 02842 02843 b4=b7; 02844 cc=2.0f*pow(tab1(l),2); 02845 c=1.0f-cc; 02846 l++; 02847 ss=sgn*tab1(l); 02848 s=ss; 02849 L16: 02850 b5=b6+b4; 02851 b4=2*b6; 02852 b56=b5-b6; 02853 L18: 02854 tr1=br(b5+1); 02855 ti1=bi(b5+1); 02856 tr2=br(b56+1); 02857 ti2=bi(b56+1); 02858 br(b5+1)=c*(tr2-tr1)-s*(ti2-ti1); 02859 bi(b5+1)=s*(tr2-tr1)+c*(ti2-ti1); 02860 br(b56+1)=tr1+tr2; 02861 bi(b56+1)=ti1+ti2; 02862 02863 b5=b5+b4; 02864 b56=b5-b6; 02865 if(b5 <= b3) goto L18; 02866 b4=b5-b6; 02867 b5=b4-b3; 02868 c=-c; 02869 b4=b6-b5; 02870 if(b5 < b4) goto L16; 02871 b4=b4+b7; 02872 if(b4 >= b5) goto L12; 02873 02874 t=c-cc*c-ss*s; 02875 s=s+ss*c-cc*s; 02876 c=t; 02877 goto L16; 02878 L20: 02879 ix0=b3/2; 02880 b3=b3-b7; 02881 b4=0; 02882 b5=0; 02883 b6=ix0; 02884 ix1=0; 02885 if ( b6 == b7) goto EXIT; 02886 L22: 02887 b4=b3-b4; 02888 b5=b3-b5; 02889 x2=br(b4+1); 02890 x3=br(b5+1); 02891 x4=bi(b4+1); 02892 x5=bi(b5+1); 02893 br(b4+1)=x3; 02894 br(b5+1)=x2; 02895 bi(b4+1)=x5; 02896 bi(b5+1)=x4; 02897 if (b6 < b4) goto L22; 02898 L24: 02899 b4=b4+b7; 02900 b5=b6+b5; 02901 x2=br(b4+1); 02902 x3=br(b5+1); 02903 x4=bi(b4+1); 02904 x5=bi(b5+1); 02905 br(b4+1)=x3; 02906 br(b5+1)=x2; 02907 bi(b4+1)=x5; 02908 bi(b5+1)=x4; 02909 ix0=b6; 02910 L26: 02911 ix0=ix0/2; 02912 ix1=ix1-ix0; 02913 if(ix1 >= 0) goto L26; 02914 02915 ix0=2*ix0; 02916 b4=b4+b7; 02917 ix1=ix1+ix0; 02918 b5=ix1; 02919 if (b5 >= b4) goto L22; 02920 if (b4 < b6) goto L24; 02921 EXIT: 02922 status = 0; 02923 }
void Util::fftr_d | ( | double * | xcmplx, | |
int | nv | |||
) | [static] |
Definition at line 3007 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(), and Crosrng_sm_psi().
03008 { 03009 // double precision x(2,1) 03010 int i1, i2, nu, inv, nu1, n, isub, n2, i; 03011 double tr1,tr2,ti1,ti2,tr,ti; 03012 double cc,c,ss,s,t; 03013 const double tab1[] = { 03014 9.58737990959775e-5, 03015 1.91747597310703e-4, 03016 3.83495187571395e-4, 03017 7.66990318742704e-4, 03018 1.53398018628476e-3, 03019 3.06795676296598e-3, 03020 6.13588464915449e-3, 03021 1.22715382857199e-2, 03022 2.45412285229123e-2, 03023 4.90676743274181e-2, 03024 9.80171403295604e-2, 03025 1.95090322016128e-1, 03026 3.82683432365090e-1, 03027 7.07106781186546e-1, 03028 1.00000000000000, 03029 }; 03030 03031 nu=abs(nv); 03032 inv=nv/nu; 03033 nu1=nu-1; 03034 n=(int)pow(2.0f,nu1); 03035 isub=16-nu1; 03036 ss=-tab1(isub); 03037 cc=-2.0*pow(tab1(isub-1),2); 03038 c=1.0f; 03039 s=0.0f; 03040 n2=n/2; 03041 03042 if ( inv > 0 ) { 03043 fftc_d(&xcmplx(1,1),&xcmplx(2,1),nu1,2); 03044 tr=xcmplx(1,1); 03045 ti=xcmplx(2,1); 03046 xcmplx(1,1)=tr+ti; 03047 xcmplx(2,1)=tr-ti; 03048 for (i=1;i<=n2;i++) { 03049 i1=i+1; 03050 i2=n-i+1; 03051 tr1=xcmplx(1,i1); 03052 tr2=xcmplx(1,i2); 03053 ti1=xcmplx(2,i1); 03054 ti2=xcmplx(2,i2); 03055 t=(cc*c-ss*s)+c; 03056 s=(cc*s+ss*c)+s; 03057 c=t; 03058 xcmplx(1,i1)=0.5*((tr1+tr2)+(ti1+ti2)*c-(tr1-tr2)*s); 03059 xcmplx(1,i2)=0.5*((tr1+tr2)-(ti1+ti2)*c+(tr1-tr2)*s); 03060 xcmplx(2,i1)=0.5*((ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c); 03061 xcmplx(2,i2)=0.5*(-(ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c); 03062 } 03063 } else { 03064 tr=xcmplx(1,1); 03065 ti=xcmplx(2,1); 03066 xcmplx(1,1)=0.5*(tr+ti); 03067 xcmplx(2,1)=0.5*(tr-ti); 03068 for (i=1; i<=n2; i++) { 03069 i1=i+1; 03070 i2=n-i+1; 03071 tr1=xcmplx(1,i1); 03072 tr2=xcmplx(1,i2); 03073 ti1=xcmplx(2,i1); 03074 ti2=xcmplx(2,i2); 03075 t=(cc*c-ss*s)+c; 03076 s=(cc*s+ss*c)+s; 03077 c=t; 03078 xcmplx(1,i1)=0.5*((tr1+tr2)-(tr1-tr2)*s-(ti1+ti2)*c); 03079 xcmplx(1,i2)=0.5*((tr1+tr2)+(tr1-tr2)*s+(ti1+ti2)*c); 03080 xcmplx(2,i1)=0.5*((ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s); 03081 xcmplx(2,i2)=0.5*(-(ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s); 03082 } 03083 fftc_d(&xcmplx(1,1),&xcmplx(2,1),nu1,-2); 03084 } 03085 }
void Util::fftr_q | ( | float * | xcmplx, | |
int | nv | |||
) | [static] |
Definition at line 2925 of file util_sparx.cpp.
References abs, fftc_q(), t, tab1, and xcmplx.
Referenced by Crosrng_msg_vec(), Frngs(), and Frngs_inv().
02926 { 02927 // dimension xcmplx(2,1); xcmplx(1,i) --- real, xcmplx(2,i) --- imaginary 02928 02929 int nu, inv, nu1, n, isub, n2, i1, i2, i; 02930 float ss, cc, c, s, tr, ti, tr1, tr2, ti1, ti2, t; 02931 02932 const float tab1[] = { 02933 9.58737990959775e-5f, 02934 1.91747597310703e-4f, 02935 3.83495187571395e-4f, 02936 7.66990318742704e-4f, 02937 1.53398018628476e-3f, 02938 3.06795676296598e-3f, 02939 6.13588464915449e-3f, 02940 1.22715382857199e-2f, 02941 2.45412285229123e-2f, 02942 4.90676743274181e-2f, 02943 9.80171403295604e-2f, 02944 1.95090322016128e-1f, 02945 3.82683432365090e-1f, 02946 7.07106781186546e-1f, 02947 1.00000000000000f, 02948 }; 02949 02950 nu=abs(nv); 02951 inv=nv/nu; 02952 nu1=nu-1; 02953 n=(int)pow(2.f,nu1); 02954 isub=16-nu1; 02955 02956 ss=-tab1(isub); 02957 cc=-2.0f*pow(tab1(isub-1),2.f); 02958 c=1.0f; 02959 s=0.0f; 02960 n2=n/2; 02961 if ( inv > 0) { 02962 fftc_q(&xcmplx(1,1),&xcmplx(2,1),nu1,2); 02963 tr=xcmplx(1,1); 02964 ti=xcmplx(2,1); 02965 xcmplx(1,1)=tr+ti; 02966 xcmplx(2,1)=tr-ti; 02967 for (i=1;i<=n2;i++) { 02968 i1=i+1; 02969 i2=n-i+1; 02970 tr1=xcmplx(1,i1); 02971 tr2=xcmplx(1,i2); 02972 ti1=xcmplx(2,i1); 02973 ti2=xcmplx(2,i2); 02974 t=(cc*c-ss*s)+c; 02975 s=(cc*s+ss*c)+s; 02976 c=t; 02977 xcmplx(1,i1)=0.5f*((tr1+tr2)+(ti1+ti2)*c-(tr1-tr2)*s); 02978 xcmplx(1,i2)=0.5f*((tr1+tr2)-(ti1+ti2)*c+(tr1-tr2)*s); 02979 xcmplx(2,i1)=0.5f*((ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c); 02980 xcmplx(2,i2)=0.5f*(-(ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c); 02981 } 02982 } else { 02983 tr=xcmplx(1,1); 02984 ti=xcmplx(2,1); 02985 xcmplx(1,1)=0.5f*(tr+ti); 02986 xcmplx(2,1)=0.5f*(tr-ti); 02987 for (i=1; i<=n2; i++) { 02988 i1=i+1; 02989 i2=n-i+1; 02990 tr1=xcmplx(1,i1); 02991 tr2=xcmplx(1,i2); 02992 ti1=xcmplx(2,i1); 02993 ti2=xcmplx(2,i2); 02994 t=(cc*c-ss*s)+c; 02995 s=(cc*s+ss*c)+s; 02996 c=t; 02997 xcmplx(1,i1)=0.5f*((tr1+tr2)-(tr1-tr2)*s-(ti1+ti2)*c); 02998 xcmplx(1,i2)=0.5f*((tr1+tr2)+(tr1-tr2)*s+(ti1+ti2)*c); 02999 xcmplx(2,i1)=0.5f*((ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s); 03000 xcmplx(2,i2)=0.5f*(-(ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s); 03001 } 03002 fftc_q(&xcmplx(1,1),&xcmplx(2,1),nu1,-2); 03003 } 03004 }
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 812 of file util.cpp.
References Assert, max, and NullPointerException.
Referenced by EMAN::RotatePrecenterAligner::align(), and EMAN::RotationalAligner::align_180_ambiguous().
00813 { 00814 Assert(nitems > 0); 00815 00816 if (!data || !max_val || !max_index) { 00817 throw NullPointerException("data/max_val/max_index"); 00818 } 00819 float max = -FLT_MAX; 00820 int m = 0; 00821 00822 for (size_t i = 0; i < nitems; i++) { 00823 if (data[i] > max) { 00824 max = data[i]; 00825 m = (int)i; 00826 } 00827 } 00828 00829 *max_val = (float)m; 00830 00831 if (max_index) { 00832 *max_index = m; 00833 } 00834 }
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 836 of file util.cpp.
References Assert, max, min, and NullPointerException.
00839 { 00840 Assert(nitems > 0); 00841 00842 if (!data || !max_val || !min_val || !max_index || !min_index) { 00843 throw NullPointerException("data/max_val/min_val/max_index/min_index"); 00844 } 00845 float max = -FLT_MAX; 00846 float min = FLT_MAX; 00847 int max_i = 0; 00848 int min_i = 0; 00849 00850 for (size_t i = 0; i < nitems; i++) { 00851 if (data[i] > max) { 00852 max = data[i]; 00853 max_i = (int)i; 00854 } 00855 if (data[i] < min) { 00856 min = data[i]; 00857 min_i = (int)i; 00858 } 00859 } 00860 00861 *max_val = max; 00862 *min_val = min; 00863 00864 if (min_index) { 00865 *min_index = min_i; 00866 } 00867 00868 if (max_index) { 00869 *max_index = max_i; 00870 } 00871 00872 }
int Util::findTopLargest | ( | int * | argParts, | |
int * | Indices, | |||
int * | dimClasses, | |||
int | nParts, | |||
int | K, | |||
int | T, | |||
int * | matchlist, | |||
int | max_num_matches, | |||
int * | costlist, | |||
int | n_guesses | |||
) | [static] |
find max_num_matches feasible matches (if possible) which has weight gt T, and weight gteq weight of all other feasible matches.
return the results in the pre-allocated arrays matchlist and costlist. Each match is a sequence (stored in a 1D array) of nParts numbers, where the i-th element in the sequence is the original index of the class from the i-th partition. Those classes in argParts whose dummy variable is 1 are the classes which are not yet used (i.e., those which can be used to construct the feasible matches) returns the number of matches found. it's less than the number request if there aren't that many that's over the threshold
Definition at line 19972 of file util_sparx.cpp.
References generatesubmax(), and search2().
19972 { 19973 int guess; 19974 int* curmax = new int[nParts+1]; // first element is the max weight and the subsequent elements is the match with the weight. 19975 int newT=T; 19976 int num_found=0; 19977 19978 for(int i=0; i < max_num_matches; i++){ 19979 guess = Util::generatesubmax(argParts, Indices,dimClasses,nParts, K, T, n_guesses); 19980 19981 if (T < guess) newT = guess -1; 19982 // find the feasible match with the largest weight and put results in curmax 19983 Util::search2(argParts, Indices,dimClasses,nParts, K, newT,curmax); 19984 if (*curmax <= T){ 19985 max_num_matches=i; 19986 break; 19987 } 19988 else { 19989 *(costlist+i) = *curmax; 19990 19991 for (int j=0; j<nParts; j++){ 19992 *(matchlist+i*nParts+j) = *(curmax+1+j); 19993 *(argParts + Indices[j*K+*(curmax+1+j)] + 1) = -3;// mark the classes in curmax as unavailable using -3 (remember to change it back) 19994 19995 } 19996 num_found = num_found+1; 19997 } 19998 19999 } 20000 20001 20002 delete[] curmax; 20003 // go through the selected classes (in matchlist) and reset to 1 20004 20005 for (int i=0 ; i < max_num_matches; i++){ 20006 for (int j = 0; j < nParts; j++){ 20007 *(argParts + Indices[j*K+*(matchlist+i*nParts +j)] + 1) = 1; 20008 } 20009 20010 } 20011 20012 20013 return num_found; 20014 }
void Util::flip23 | ( | double * | x, | |
double * | y, | |||
double * | z, | |||
int * | key, | |||
int | k, | |||
int | len | |||
) | [static] |
Definition at line 7635 of file util_sparx.cpp.
References ENTERFUNC, and EXITFUNC.
Referenced by voronoi().
07636 { 07637 ENTERFUNC; 07638 int i = k; 07639 while( i == k ) i = rand()%len; 07640 std::swap(key[i], key[k]); 07641 std::swap(x[i], x[k]); 07642 std::swap(y[i], y[k]); 07643 std::swap(z[i], z[k]); 07644 EXITFUNC; 07645 }
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 3092 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(), and multiref_polar_ali_helical().
03092 { 03093 int nring = numr.size()/3; 03094 float *circ = circp->get_data(); 03095 int i, l; 03096 for (i=1; i<=nring;i++) { 03097 03098 #ifdef _WIN32 03099 l = (int)( log((float)numr(3,i))/log(2.0f) ); 03100 #else 03101 l=(int)(log2(numr(3,i))); 03102 #endif //_WIN32 03103 03104 fftr_q(&circ(numr(2,i)),l); 03105 } 03106 }
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 3108 of file util_sparx.cpp.
References circ, fftr_q(), EMAN::EMData::get_data(), log(), and numr.
03108 { 03109 int nring = numr.size()/3; 03110 float *circ = circp->get_data(); 03111 int i, l; 03112 for (i=1; i<=nring;i++) { 03113 03114 #ifdef _WIN32 03115 l = (int)( log((float)numr(3,i))/log(2.0f) ); 03116 #else 03117 l=(int)(log2(numr(3,i))); 03118 #endif //_WIN32 03119 03120 fftr_q(&circ(numr(2,i)),-l); 03121 } 03122 }
int Util::generatesubmax | ( | int * | argParts, | |
int * | Indices, | |||
int * | dimClasses, | |||
int | nParts, | |||
int | K, | |||
int | T, | |||
int | n_guesses | |||
) | [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 20261 of file util_sparx.cpp.
References b, and k_means_cont_table_().
Referenced by findTopLargest().
20261 { 20262 int guess=0; 20263 20264 int* perm = new int[nParts]; 20265 for(int i=0; i<nParts; i++) perm[i]=i; 20266 20267 // some temporary variables 20268 int* intx; 20269 int* intx_next; 20270 int nintx; 20271 int nintxmax=0; 20272 int class_max, class_max_next; 20273 int intx_size, part, part_next; 20274 int ipold,indsw; 20275 20276 for(int i=0; i< n_guesses; i++){ 20277 // shuffle perm array 20278 for(int ip = 0; ip<nParts; ip++){ 20279 indsw = (rand())%nParts; 20280 // swap ip(th) element with the (indsw)th element 20281 ipold = perm[ip]; 20282 perm[ip]=perm[indsw]; 20283 perm[indsw]=ipold; 20284 } 20285 20286 20287 // find the two classes in partitions perm[0] and perm[1] that yield the largest intersection 20288 part=*perm; 20289 part_next=*(perm+1); 20290 for (int a=0; a < K; a++) 20291 { 20292 if (*(argParts + Indices[part*K+a] + 1) < 1) continue; 20293 for (int b=0; b < K; b++) 20294 { 20295 if (*(argParts + Indices[part_next*K + b] + 1) < 1) continue; 20296 nintx = Util::k_means_cont_table_(argParts + Indices[part*K+a]+2,argParts + Indices[part_next*K + b]+2, intx, *(dimClasses + part*K+a)-2, *(dimClasses + part_next*K + b)-2,0); 20297 if (nintx <= nintxmax) continue; 20298 nintxmax = nintx; 20299 class_max = a; 20300 class_max_next = b; 20301 } 20302 } 20303 20304 // no more.... 20305 if (nintxmax < 1) {continue;} 20306 20307 if (nParts > 2){ 20308 intx = new int[nintxmax]; 20309 intx_size = nintxmax; 20310 Util::k_means_cont_table_(argParts + Indices[part*K+class_max]+2,argParts + Indices[part_next*K + class_max_next]+2, intx, *(dimClasses + part*K+class_max)-2, *(dimClasses+part_next*K+class_max_next)-2,1); // get intx 20311 } 20312 20313 // for each subsequent partition perm[i], i>=2, find the partition that yields the largest weight with the current intx 20314 for(int j = 2; j < nParts; j++){ 20315 part = *(perm+j); 20316 nintxmax=0; 20317 for(int a = 0; a < K; a++){ 20318 if (*(argParts + Indices[part*K+a] + 1) < 1) continue; // skip inactive classes 20319 nintx = Util::k_means_cont_table_(intx, argParts + Indices[part*K + a]+2, intx_next, intx_size, (*(dimClasses + part*K+a))-2,0); 20320 if (nintx <= nintxmax) continue; 20321 nintxmax = nintx; 20322 class_max = a; 20323 } 20324 20325 // no more stuff.... 20326 if (nintxmax < 1) { 20327 20328 delete[] intx; 20329 break; 20330 } 20331 20332 20333 intx_next = new int[nintxmax]; 20334 Util::k_means_cont_table_(intx, argParts + Indices[part*K + class_max]+2, intx_next, intx_size, *(dimClasses + part*K+class_max)-2,1); 20335 delete[] intx; 20336 intx = intx_next; 20337 intx_size = nintxmax; 20338 if (j==nParts - 1) delete[] intx_next; 20339 20340 } 20341 20342 if (nintxmax > guess) guess = nintxmax; 20343 20344 } 20345 delete[] perm; 20346 return guess; 20347 }
Definition at line 19028 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().
19029 { 19030 int nx = mg->get_xsize(); 19031 int ny = mg->get_ysize(); 19032 int nz = mg->get_zsize(); 19033 19034 EMData* visited = new EMData(); 19035 visited->set_size( nx, ny, nz ); 19036 visited->to_zero(); 19037 int grpid = 0; 19038 int maxgrp = 0; 19039 int maxsize = 0; 19040 for( int iz=0; iz < nz; ++iz ) { 19041 for( int iy=0; iy < ny; ++iy ) { 19042 for( int ix=0; ix < nx; ++ix ) { 19043 if( (*mg)(ix, iy, iz)==0.0 ) continue; 19044 19045 if( (*visited)(ix, iy, iz) > 0.0 ) { 19046 // visited before, must be in other group. 19047 continue; 19048 } 19049 19050 grpid++; 19051 int grpsize = find_group( ix, iy, iz, grpid, mg, visited ); 19052 if( grpsize > maxsize ) { 19053 maxsize = grpsize; 19054 maxgrp = grpid; 19055 } 19056 } 19057 } 19058 } 19059 19060 Assert( maxgrp > 0 ); 19061 19062 int npoint = 0; 19063 EMData* result = new EMData(); 19064 result->set_size( nx, ny, nz ); 19065 result->to_zero(); 19066 19067 for( int iz=0; iz < nz; ++iz ) { 19068 for( int iy=0; iy < ny; ++iy ) { 19069 for( int ix=0; ix < nx; ++ix ) { 19070 if( (*visited)(ix, iy, iz)==maxgrp ) { 19071 (*result)(ix,iy,iz) = 1.0; 19072 npoint++; 19073 } 19074 } 19075 } 19076 } 19077 19078 Assert( npoint==maxsize ); 19079 delete visited; 19080 return result; 19081 19082 }
string Util::get_filename_ext | ( | const string & | filename | ) | [static] |
Get a filename's extension.
[in] | filename | A given filename. |
Definition at line 492 of file util.cpp.
Referenced by EMAN::EMUtil::fast_get_image_type(), EMAN::EMUtil::get_image_type(), and EMAN::EMUtil::is_valid_filename().
00493 { 00494 if (filename == "") { 00495 return ""; 00496 } 00497 00498 string result = ""; 00499 const char *ext = strrchr(filename.c_str(), '.'); 00500 if (ext) { 00501 ext++; 00502 result = string(ext); 00503 } 00504 return result; 00505 }
float Util::get_frand | ( | double | low, | |
double | high | |||
) | [static] |
Get a float random number between low and high, [low, high).
[in] | low | The lower bound of the random number. |
[in] | high | The upper bound of the random number. |
Definition at line 707 of file util.cpp.
References EMAN::Randnum::get_frand(), and EMAN::Randnum::Instance().
00708 { 00709 Randnum* randnum = Randnum::Instance(); 00710 return randnum->get_frand(lo, hi); 00711 }
float Util::get_frand | ( | float | low, | |
float | high | |||
) | [static] |
Get a float random number between low and high, [low, high).
[in] | low | The lower bound of the random number. |
[in] | high | The upper bound of the random number. |
Definition at line 701 of file util.cpp.
References EMAN::Randnum::get_frand(), and EMAN::Randnum::Instance().
00702 { 00703 Randnum* randnum = Randnum::Instance(); 00704 return randnum->get_frand(lo, hi); 00705 }
float Util::get_frand | ( | int | low, | |
int | high | |||
) | [static] |
Get a float random number between low and high, [low, high).
[in] | low | The lower bound of the random number. |
[in] | high | The upper bound of the random number. |
Definition at line 696 of file util.cpp.
Referenced by EMAN::OrientationGenerator::add_orientation(), ali2d_ccf_list(), EMAN::RandomOrientationGenerator::gen_orientations(), move_points(), EMAN::KmeansSegmentProcessor::process(), EMAN::TestImageFourierNoiseProfile::process_inplace(), EMAN::TestImageFourierNoiseGaussian::process_inplace(), EMAN::PointArray::set_from_density_map(), and EMAN::WienerFourierReconstructor::setup().
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 806 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().
00807 { 00808 Randnum* randnum = Randnum::Instance(); 00809 return randnum->get_gauss_rand(mean, sigma); 00810 }
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().
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 1712 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 775 of file util_sparx.cpp.
References EMAN::Util::KaiserBessel::get_window_size(), EMAN::Util::KaiserBessel::i0win_tab(), restrict1(), and round().
Referenced by Polar2Dmi(), and EMAN::EMData::rot_scale_conv_new().
00775 { 00776 int K = kb.get_window_size(); 00777 int kbmin = -K/2; 00778 int kbmax = -kbmin; 00779 int kbc = kbmax+1; 00780 00781 float pixel =0.0f; 00782 float w=0.0f; 00783 00784 delx = restrict1(delx, nx); 00785 int inxold = int(round(delx)); 00786 if ( ny < 2 ) { //1D 00787 float tablex1 = kb.i0win_tab(delx-inxold+3); 00788 float tablex2 = kb.i0win_tab(delx-inxold+2); 00789 float tablex3 = kb.i0win_tab(delx-inxold+1); 00790 float tablex4 = kb.i0win_tab(delx-inxold); 00791 float tablex5 = kb.i0win_tab(delx-inxold-1); 00792 float tablex6 = kb.i0win_tab(delx-inxold-2); 00793 float tablex7 = kb.i0win_tab(delx-inxold-3); 00794 00795 int x1, x2, x3, x4, x5, x6, x7; 00796 00797 if ( inxold <= kbc || inxold >=nx-kbc-2 ) { 00798 x1 = (inxold-3+nx)%nx; 00799 x2 = (inxold-2+nx)%nx; 00800 x3 = (inxold-1+nx)%nx; 00801 x4 = (inxold +nx)%nx; 00802 x5 = (inxold+1+nx)%nx; 00803 x6 = (inxold+2+nx)%nx; 00804 x7 = (inxold+3+nx)%nx; 00805 } else { 00806 x1 = inxold-3; 00807 x2 = inxold-2; 00808 x3 = inxold-1; 00809 x4 = inxold; 00810 x5 = inxold+1; 00811 x6 = inxold+2; 00812 x7 = inxold+3; 00813 } 00814 00815 pixel = data[x1]*tablex1 + data[x2]*tablex2 + data[x3]*tablex3 + 00816 data[x4]*tablex4 + data[x5]*tablex5 + data[x6]*tablex6 + 00817 data[x7]*tablex7 ; 00818 00819 w = tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7; 00820 } else if ( nz < 2 ) { // 2D 00821 dely = restrict1(dely, ny); 00822 int inyold = int(round(dely)); 00823 float tablex1 = kb.i0win_tab(delx-inxold+3); 00824 float tablex2 = kb.i0win_tab(delx-inxold+2); 00825 float tablex3 = kb.i0win_tab(delx-inxold+1); 00826 float tablex4 = kb.i0win_tab(delx-inxold); 00827 float tablex5 = kb.i0win_tab(delx-inxold-1); 00828 float tablex6 = kb.i0win_tab(delx-inxold-2); 00829 float tablex7 = kb.i0win_tab(delx-inxold-3); 00830 00831 float tabley1 = kb.i0win_tab(dely-inyold+3); 00832 float tabley2 = kb.i0win_tab(dely-inyold+2); 00833 float tabley3 = kb.i0win_tab(dely-inyold+1); 00834 float tabley4 = kb.i0win_tab(dely-inyold); 00835 float tabley5 = kb.i0win_tab(dely-inyold-1); 00836 float tabley6 = kb.i0win_tab(dely-inyold-2); 00837 float tabley7 = kb.i0win_tab(dely-inyold-3); 00838 00839 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7; 00840 00841 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 ) { 00842 x1 = (inxold-3+nx)%nx; 00843 x2 = (inxold-2+nx)%nx; 00844 x3 = (inxold-1+nx)%nx; 00845 x4 = (inxold +nx)%nx; 00846 x5 = (inxold+1+nx)%nx; 00847 x6 = (inxold+2+nx)%nx; 00848 x7 = (inxold+3+nx)%nx; 00849 00850 y1 = ((inyold-3+ny)%ny)*nx; 00851 y2 = ((inyold-2+ny)%ny)*nx; 00852 y3 = ((inyold-1+ny)%ny)*nx; 00853 y4 = ((inyold +ny)%ny)*nx; 00854 y5 = ((inyold+1+ny)%ny)*nx; 00855 y6 = ((inyold+2+ny)%ny)*nx; 00856 y7 = ((inyold+3+ny)%ny)*nx; 00857 } else { 00858 x1 = inxold-3; 00859 x2 = inxold-2; 00860 x3 = inxold-1; 00861 x4 = inxold; 00862 x5 = inxold+1; 00863 x6 = inxold+2; 00864 x7 = inxold+3; 00865 00866 y1 = (inyold-3)*nx; 00867 y2 = (inyold-2)*nx; 00868 y3 = (inyold-1)*nx; 00869 y4 = inyold*nx; 00870 y5 = (inyold+1)*nx; 00871 y6 = (inyold+2)*nx; 00872 y7 = (inyold+3)*nx; 00873 } 00874 00875 pixel = ( data[x1+y1]*tablex1 + data[x2+y1]*tablex2 + data[x3+y1]*tablex3 + 00876 data[x4+y1]*tablex4 + data[x5+y1]*tablex5 + data[x6+y1]*tablex6 + 00877 data[x7+y1]*tablex7 ) * tabley1 + 00878 ( data[x1+y2]*tablex1 + data[x2+y2]*tablex2 + data[x3+y2]*tablex3 + 00879 data[x4+y2]*tablex4 + data[x5+y2]*tablex5 + data[x6+y2]*tablex6 + 00880 data[x7+y2]*tablex7 ) * tabley2 + 00881 ( data[x1+y3]*tablex1 + data[x2+y3]*tablex2 + data[x3+y3]*tablex3 + 00882 data[x4+y3]*tablex4 + data[x5+y3]*tablex5 + data[x6+y3]*tablex6 + 00883 data[x7+y3]*tablex7 ) * tabley3 + 00884 ( data[x1+y4]*tablex1 + data[x2+y4]*tablex2 + data[x3+y4]*tablex3 + 00885 data[x4+y4]*tablex4 + data[x5+y4]*tablex5 + data[x6+y4]*tablex6 + 00886 data[x7+y4]*tablex7 ) * tabley4 + 00887 ( data[x1+y5]*tablex1 + data[x2+y5]*tablex2 + data[x3+y5]*tablex3 + 00888 data[x4+y5]*tablex4 + data[x5+y5]*tablex5 + data[x6+y5]*tablex6 + 00889 data[x7+y5]*tablex7 ) * tabley5 + 00890 ( data[x1+y6]*tablex1 + data[x2+y6]*tablex2 + data[x3+y6]*tablex3 + 00891 data[x4+y6]*tablex4 + data[x5+y6]*tablex5 + data[x6+y6]*tablex6 + 00892 data[x7+y6]*tablex7 ) * tabley6 + 00893 ( data[x1+y7]*tablex1 + data[x2+y7]*tablex2 + data[x3+y7]*tablex3 + 00894 data[x4+y7]*tablex4 + data[x5+y7]*tablex5 + data[x6+y7]*tablex6 + 00895 data[x7+y7]*tablex7 ) * tabley7; 00896 00897 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) * 00898 (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7); 00899 } else { // 3D 00900 dely = restrict1(dely, ny); 00901 int inyold = int(Util::round(dely)); 00902 delz = restrict1(delz, nz); 00903 int inzold = int(Util::round(delz)); 00904 00905 float tablex1 = kb.i0win_tab(delx-inxold+3); 00906 float tablex2 = kb.i0win_tab(delx-inxold+2); 00907 float tablex3 = kb.i0win_tab(delx-inxold+1); 00908 float tablex4 = kb.i0win_tab(delx-inxold); 00909 float tablex5 = kb.i0win_tab(delx-inxold-1); 00910 float tablex6 = kb.i0win_tab(delx-inxold-2); 00911 float tablex7 = kb.i0win_tab(delx-inxold-3); 00912 00913 float tabley1 = kb.i0win_tab(dely-inyold+3); 00914 float tabley2 = kb.i0win_tab(dely-inyold+2); 00915 float tabley3 = kb.i0win_tab(dely-inyold+1); 00916 float tabley4 = kb.i0win_tab(dely-inyold); 00917 float tabley5 = kb.i0win_tab(dely-inyold-1); 00918 float tabley6 = kb.i0win_tab(dely-inyold-2); 00919 float tabley7 = kb.i0win_tab(dely-inyold-3); 00920 00921 float tablez1 = kb.i0win_tab(delz-inzold+3); 00922 float tablez2 = kb.i0win_tab(delz-inzold+2); 00923 float tablez3 = kb.i0win_tab(delz-inzold+1); 00924 float tablez4 = kb.i0win_tab(delz-inzold); 00925 float tablez5 = kb.i0win_tab(delz-inzold-1); 00926 float tablez6 = kb.i0win_tab(delz-inzold-2); 00927 float tablez7 = kb.i0win_tab(delz-inzold-3); 00928 00929 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7, z1, z2, z3, z4, z5, z6, z7; 00930 00931 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 || inzold <= kbc || inzold >= nz-kbc-2 ) { 00932 x1 = (inxold-3+nx)%nx; 00933 x2 = (inxold-2+nx)%nx; 00934 x3 = (inxold-1+nx)%nx; 00935 x4 = (inxold +nx)%nx; 00936 x5 = (inxold+1+nx)%nx; 00937 x6 = (inxold+2+nx)%nx; 00938 x7 = (inxold+3+nx)%nx; 00939 00940 y1 = ((inyold-3+ny)%ny)*nx; 00941 y2 = ((inyold-2+ny)%ny)*nx; 00942 y3 = ((inyold-1+ny)%ny)*nx; 00943 y4 = ((inyold +ny)%ny)*nx; 00944 y5 = ((inyold+1+ny)%ny)*nx; 00945 y6 = ((inyold+2+ny)%ny)*nx; 00946 y7 = ((inyold+3+ny)%ny)*nx; 00947 00948 z1 = ((inzold-3+nz)%nz)*nx*ny; 00949 z2 = ((inzold-2+nz)%nz)*nx*ny; 00950 z3 = ((inzold-1+nz)%nz)*nx*ny; 00951 z4 = ((inzold +nz)%nz)*nx*ny; 00952 z5 = ((inzold+1+nz)%nz)*nx*ny; 00953 z6 = ((inzold+2+nz)%nz)*nx*ny; 00954 z7 = ((inzold+3+nz)%nz)*nx*ny; 00955 } else { 00956 x1 = inxold-3; 00957 x2 = inxold-2; 00958 x3 = inxold-1; 00959 x4 = inxold; 00960 x5 = inxold+1; 00961 x6 = inxold+2; 00962 x7 = inxold+3; 00963 00964 y1 = (inyold-3)*nx; 00965 y2 = (inyold-2)*nx; 00966 y3 = (inyold-1)*nx; 00967 y4 = inyold*nx; 00968 y5 = (inyold+1)*nx; 00969 y6 = (inyold+2)*nx; 00970 y7 = (inyold+3)*nx; 00971 00972 z1 = (inzold-3)*nx*ny; 00973 z2 = (inzold-2)*nx*ny; 00974 z3 = (inzold-1)*nx*ny; 00975 z4 = inzold*nx*ny; 00976 z5 = (inzold+1)*nx*ny; 00977 z6 = (inzold+2)*nx*ny; 00978 z7 = (inzold+3)*nx*ny; 00979 } 00980 00981 pixel = ( ( data[x1+y1+z1]*tablex1 + data[x2+y1+z1]*tablex2 + data[x3+y1+z1]*tablex3 + 00982 data[x4+y1+z1]*tablex4 + data[x5+y1+z1]*tablex5 + data[x6+y1+z1]*tablex6 + 00983 data[x7+y1+z1]*tablex7 ) * tabley1 + 00984 ( data[x1+y2+z1]*tablex1 + data[x2+y2+z1]*tablex2 + data[x3+y2+z1]*tablex3 + 00985 data[x4+y2+z1]*tablex4 + data[x5+y2+z1]*tablex5 + data[x6+y2+z1]*tablex6 + 00986 data[x7+y2+z1]*tablex7 ) * tabley2 + 00987 ( data[x1+y3+z1]*tablex1 + data[x2+y3+z1]*tablex2 + data[x3+y3+z1]*tablex3 + 00988 data[x4+y3+z1]*tablex4 + data[x5+y3+z1]*tablex5 + data[x6+y3+z1]*tablex6 + 00989 data[x7+y3+z1]*tablex7 ) * tabley3 + 00990 ( data[x1+y4+z1]*tablex1 + data[x2+y4+z1]*tablex2 + data[x3+y4+z1]*tablex3 + 00991 data[x4+y4+z1]*tablex4 + data[x5+y4+z1]*tablex5 + data[x6+y4+z1]*tablex6 + 00992 data[x7+y4+z1]*tablex7 ) * tabley4 + 00993 ( data[x1+y5+z1]*tablex1 + data[x2+y5+z1]*tablex2 + data[x3+y5+z1]*tablex3 + 00994 data[x4+y5+z1]*tablex4 + data[x5+y5+z1]*tablex5 + data[x6+y5+z1]*tablex6 + 00995 data[x7+y5+z1]*tablex7 ) * tabley5 + 00996 ( data[x1+y6+z1]*tablex1 + data[x2+y6+z1]*tablex2 + data[x3+y6+z1]*tablex3 + 00997 data[x4+y6+z1]*tablex4 + data[x5+y6+z1]*tablex5 + data[x6+y6+z1]*tablex6 + 00998 data[x7+y6+z1]*tablex7 ) * tabley6 + 00999 ( data[x1+y7+z1]*tablex1 + data[x2+y7+z1]*tablex2 + data[x3+y7+z1]*tablex3 + 01000 data[x4+y7+z1]*tablex4 + data[x5+y7+z1]*tablex5 + data[x6+y7+z1]*tablex6 + 01001 data[x7+y7+z1]*tablex7 ) * tabley7 ) *tablez1 + 01002 ( ( data[x1+y1+z2]*tablex1 + data[x2+y1+z2]*tablex2 + data[x3+y1+z2]*tablex3 + 01003 data[x4+y1+z2]*tablex4 + data[x5+y1+z2]*tablex5 + data[x6+y1+z2]*tablex6 + 01004 data[x7+y1+z2]*tablex7 ) * tabley1 + 01005 ( data[x1+y2+z2]*tablex1 + data[x2+y2+z2]*tablex2 + data[x3+y2+z2]*tablex3 + 01006 data[x4+y2+z2]*tablex4 + data[x5+y2+z2]*tablex5 + data[x6+y2+z2]*tablex6 + 01007 data[x7+y2+z2]*tablex7 ) * tabley2 + 01008 ( data[x1+y3+z2]*tablex1 + data[x2+y3+z2]*tablex2 + data[x3+y3+z2]*tablex3 + 01009 data[x4+y3+z2]*tablex4 + data[x5+y3+z2]*tablex5 + data[x6+y3+z2]*tablex6 + 01010 data[x7+y3+z2]*tablex7 ) * tabley3 + 01011 ( data[x1+y4+z2]*tablex1 + data[x2+y4+z2]*tablex2 + data[x3+y4+z2]*tablex3 + 01012 data[x4+y4+z2]*tablex4 + data[x5+y4+z2]*tablex5 + data[x6+y4+z2]*tablex6 + 01013 data[x7+y4+z2]*tablex7 ) * tabley4 + 01014 ( data[x1+y5+z2]*tablex1 + data[x2+y5+z2]*tablex2 + data[x3+y5+z2]*tablex3 + 01015 data[x4+y5+z2]*tablex4 + data[x5+y5+z2]*tablex5 + data[x6+y5+z2]*tablex6 + 01016 data[x7+y5+z2]*tablex7 ) * tabley5 + 01017 ( data[x1+y6+z2]*tablex1 + data[x2+y6+z2]*tablex2 + data[x3+y6+z2]*tablex3 + 01018 data[x4+y6+z2]*tablex4 + data[x5+y6+z2]*tablex5 + data[x6+y6+z2]*tablex6 + 01019 data[x7+y6+z2]*tablex7 ) * tabley6 + 01020 ( data[x1+y7+z2]*tablex1 + data[x2+y7+z2]*tablex2 + data[x3+y7+z2]*tablex3 + 01021 data[x4+y7+z2]*tablex4 + data[x5+y7+z2]*tablex5 + data[x6+y7+z2]*tablex6 + 01022 data[x7+y7+z2]*tablex7 ) * tabley7 ) *tablez2 + 01023 ( ( data[x1+y1+z3]*tablex1 + data[x2+y1+z3]*tablex2 + data[x3+y1+z3]*tablex3 + 01024 data[x4+y1+z3]*tablex4 + data[x5+y1+z3]*tablex5 + data[x6+y1+z3]*tablex6 + 01025 data[x7+y1+z3]*tablex7 ) * tabley1 + 01026 ( data[x1+y2+z3]*tablex1 + data[x2+y2+z3]*tablex2 + data[x3+y2+z3]*tablex3 + 01027 data[x4+y2+z3]*tablex4 + data[x5+y2+z3]*tablex5 + data[x6+y2+z3]*tablex6 + 01028 data[x7+y2+z3]*tablex7 ) * tabley2 + 01029 ( data[x1+y3+z3]*tablex1 + data[x2+y3+z3]*tablex2 + data[x3+y3+z3]*tablex3 + 01030 data[x4+y3+z3]*tablex4 + data[x5+y3+z3]*tablex5 + data[x6+y3+z3]*tablex6 + 01031 data[x7+y3+z3]*tablex7 ) * tabley3 + 01032 ( data[x1+y4+z3]*tablex1 + data[x2+y4+z3]*tablex2 + data[x3+y4+z3]*tablex3 + 01033 data[x4+y4+z3]*tablex4 + data[x5+y4+z3]*tablex5 + data[x6+y4+z3]*tablex6 + 01034 data[x7+y4+z3]*tablex7 ) * tabley4 + 01035 ( data[x1+y5+z3]*tablex1 + data[x2+y5+z3]*tablex2 + data[x3+y5+z3]*tablex3 + 01036 data[x4+y5+z3]*tablex4 + data[x5+y5+z3]*tablex5 + data[x6+y5+z3]*tablex6 + 01037 data[x7+y5+z3]*tablex7 ) * tabley5 + 01038 ( data[x1+y6+z3]*tablex1 + data[x2+y6+z3]*tablex2 + data[x3+y6+z3]*tablex3 + 01039 data[x4+y6+z3]*tablex4 + data[x5+y6+z3]*tablex5 + data[x6+y6+z3]*tablex6 + 01040 data[x7+y6+z3]*tablex7 ) * tabley6 + 01041 ( data[x1+y7+z3]*tablex1 + data[x2+y7+z3]*tablex2 + data[x3+y7+z3]*tablex3 + 01042 data[x4+y7+z3]*tablex4 + data[x5+y7+z3]*tablex5 + data[x6+y7+z3]*tablex6 + 01043 data[x7+y7+z3]*tablex7 ) * tabley7 ) *tablez3 + 01044 ( ( data[x1+y1+z4]*tablex1 + data[x2+y1+z4]*tablex2 + data[x3+y1+z4]*tablex3 + 01045 data[x4+y1+z4]*tablex4 + data[x5+y1+z4]*tablex5 + data[x6+y1+z4]*tablex6 + 01046 data[x7+y1+z4]*tablex7 ) * tabley1 + 01047 ( data[x1+y2+z4]*tablex1 + data[x2+y2+z4]*tablex2 + data[x3+y2+z4]*tablex3 + 01048 data[x4+y2+z4]*tablex4 + data[x5+y2+z4]*tablex5 + data[x6+y2+z4]*tablex6 + 01049 data[x7+y2+z4]*tablex7 ) * tabley2 + 01050 ( data[x1+y3+z4]*tablex1 + data[x2+y3+z4]*tablex2 + data[x3+y3+z4]*tablex3 + 01051 data[x4+y3+z4]*tablex4 + data[x5+y3+z4]*tablex5 + data[x6+y3+z4]*tablex6 + 01052 data[x7+y3+z4]*tablex7 ) * tabley3 + 01053 ( data[x1+y4+z4]*tablex1 + data[x2+y4+z4]*tablex2 + data[x3+y4+z4]*tablex3 + 01054 data[x4+y4+z4]*tablex4 + data[x5+y4+z4]*tablex5 + data[x6+y4+z4]*tablex6 + 01055 data[x7+y4+z4]*tablex7 ) * tabley4 + 01056 ( data[x1+y5+z4]*tablex1 + data[x2+y5+z4]*tablex2 + data[x3+y5+z4]*tablex3 + 01057 data[x4+y5+z4]*tablex4 + data[x5+y5+z4]*tablex5 + data[x6+y5+z4]*tablex6 + 01058 data[x7+y5+z4]*tablex7 ) * tabley5 + 01059 ( data[x1+y6+z4]*tablex1 + data[x2+y6+z4]*tablex2 + data[x3+y6+z4]*tablex3 + 01060 data[x4+y6+z4]*tablex4 + data[x5+y6+z4]*tablex5 + data[x6+y6+z4]*tablex6 + 01061 data[x7+y6+z4]*tablex7 ) * tabley6 + 01062 ( data[x1+y7+z4]*tablex1 + data[x2+y7+z4]*tablex2 + data[x3+y7+z4]*tablex3 + 01063 data[x4+y7+z4]*tablex4 + data[x5+y7+z4]*tablex5 + data[x6+y7+z4]*tablex6 + 01064 data[x7+y7+z4]*tablex7 ) * tabley7 ) *tablez4 + 01065 ( ( data[x1+y1+z5]*tablex1 + data[x2+y1+z5]*tablex2 + data[x3+y1+z5]*tablex3 + 01066 data[x4+y1+z5]*tablex4 + data[x5+y1+z5]*tablex5 + data[x6+y1+z5]*tablex6 + 01067 data[x7+y1+z5]*tablex7 ) * tabley1 + 01068 ( data[x1+y2+z5]*tablex1 + data[x2+y2+z5]*tablex2 + data[x3+y2+z5]*tablex3 + 01069 data[x4+y2+z5]*tablex4 + data[x5+y2+z5]*tablex5 + data[x6+y2+z5]*tablex6 + 01070 data[x7+y2+z5]*tablex7 ) * tabley2 + 01071 ( data[x1+y3+z5]*tablex1 + data[x2+y3+z5]*tablex2 + data[x3+y3+z5]*tablex3 + 01072 data[x4+y3+z5]*tablex4 + data[x5+y3+z5]*tablex5 + data[x6+y3+z5]*tablex6 + 01073 data[x7+y3+z5]*tablex7 ) * tabley3 + 01074 ( data[x1+y4+z5]*tablex1 + data[x2+y4+z5]*tablex2 + data[x3+y4+z5]*tablex3 + 01075 data[x4+y4+z5]*tablex4 + data[x5+y4+z5]*tablex5 + data[x6+y4+z5]*tablex6 + 01076 data[x7+y4+z5]*tablex7 ) * tabley4 + 01077 ( data[x1+y5+z5]*tablex1 + data[x2+y5+z5]*tablex2 + data[x3+y5+z5]*tablex3 + 01078 data[x4+y5+z5]*tablex4 + data[x5+y5+z5]*tablex5 + data[x6+y5+z5]*tablex6 + 01079 data[x7+y5+z5]*tablex7 ) * tabley5 + 01080 ( data[x1+y6+z5]*tablex1 + data[x2+y6+z5]*tablex2 + data[x3+y6+z5]*tablex3 + 01081 data[x4+y6+z5]*tablex4 + data[x5+y6+z5]*tablex5 + data[x6+y6+z5]*tablex6 + 01082 data[x7+y6+z5]*tablex7 ) * tabley6 + 01083 ( data[x1+y7+z5]*tablex1 + data[x2+y7+z5]*tablex2 + data[x3+y7+z5]*tablex3 + 01084 data[x4+y7+z5]*tablex4 + data[x5+y7+z5]*tablex5 + data[x6+y7+z5]*tablex6 + 01085 data[x7+y7+z5]*tablex7 ) * tabley7 ) *tablez5 + 01086 ( ( data[x1+y1+z6]*tablex1 + data[x2+y1+z6]*tablex2 + data[x3+y1+z6]*tablex3 + 01087 data[x4+y1+z6]*tablex4 + data[x5+y1+z6]*tablex5 + data[x6+y1+z6]*tablex6 + 01088 data[x7+y1+z6]*tablex7 ) * tabley1 + 01089 ( data[x1+y2+z6]*tablex1 + data[x2+y2+z6]*tablex2 + data[x3+y2+z6]*tablex3 + 01090 data[x4+y2+z6]*tablex4 + data[x5+y2+z6]*tablex5 + data[x6+y2+z6]*tablex6 + 01091 data[x7+y2+z6]*tablex7 ) * tabley2 + 01092 ( data[x1+y3+z6]*tablex1 + data[x2+y3+z6]*tablex2 + data[x3+y3+z6]*tablex3 + 01093 data[x4+y3+z6]*tablex4 + data[x5+y3+z6]*tablex5 + data[x6+y3+z6]*tablex6 + 01094 data[x7+y3+z6]*tablex7 ) * tabley3 + 01095 ( data[x1+y4+z6]*tablex1 + data[x2+y4+z6]*tablex2 + data[x3+y4+z6]*tablex3 + 01096 data[x4+y4+z6]*tablex4 + data[x5+y4+z6]*tablex5 + data[x6+y4+z6]*tablex6 + 01097 data[x7+y4+z6]*tablex7 ) * tabley4 + 01098 ( data[x1+y5+z6]*tablex1 + data[x2+y5+z6]*tablex2 + data[x3+y5+z6]*tablex3 + 01099 data[x4+y5+z6]*tablex4 + data[x5+y5+z6]*tablex5 + data[x6+y5+z6]*tablex6 + 01100 data[x7+y5+z6]*tablex7 ) * tabley5 + 01101 ( data[x1+y6+z6]*tablex1 + data[x2+y6+z6]*tablex2 + data[x3+y6+z6]*tablex3 + 01102 data[x4+y6+z6]*tablex4 + data[x5+y6+z6]*tablex5 + data[x6+y6+z6]*tablex6 + 01103 data[x7+y6+z6]*tablex7 ) * tabley6 + 01104 ( data[x1+y7+z6]*tablex1 + data[x2+y7+z6]*tablex2 + data[x3+y7+z6]*tablex3 + 01105 data[x4+y7+z6]*tablex4 + data[x5+y7+z6]*tablex5 + data[x6+y7+z6]*tablex6 + 01106 data[x7+y7+z6]*tablex7 ) * tabley7 ) *tablez6 + 01107 ( ( data[x1+y1+z7]*tablex1 + data[x2+y1+z7]*tablex2 + data[x3+y1+z7]*tablex3 + 01108 data[x4+y1+z7]*tablex4 + data[x5+y1+z7]*tablex5 + data[x6+y1+z7]*tablex6 + 01109 data[x7+y1+z7]*tablex7 ) * tabley1 + 01110 ( data[x1+y2+z7]*tablex1 + data[x2+y2+z7]*tablex2 + data[x3+y2+z7]*tablex3 + 01111 data[x4+y2+z7]*tablex4 + data[x5+y2+z7]*tablex5 + data[x6+y2+z7]*tablex6 + 01112 data[x7+y2+z7]*tablex7 ) * tabley2 + 01113 ( data[x1+y3+z7]*tablex1 + data[x2+y3+z7]*tablex2 + data[x3+y3+z7]*tablex3 + 01114 data[x4+y3+z7]*tablex4 + data[x5+y3+z7]*tablex5 + data[x6+y3+z7]*tablex6 + 01115 data[x7+y3+z7]*tablex7 ) * tabley3 + 01116 ( data[x1+y4+z7]*tablex1 + data[x2+y4+z7]*tablex2 + data[x3+y4+z7]*tablex3 + 01117 data[x4+y4+z7]*tablex4 + data[x5+y4+z7]*tablex5 + data[x6+y4+z7]*tablex6 + 01118 data[x7+y4+z7]*tablex7 ) * tabley4 + 01119 ( data[x1+y5+z7]*tablex1 + data[x2+y5+z7]*tablex2 + data[x3+y5+z7]*tablex3 + 01120 data[x4+y5+z7]*tablex4 + data[x5+y5+z7]*tablex5 + data[x6+y5+z7]*tablex6 + 01121 data[x7+y5+z7]*tablex7 ) * tabley5 + 01122 ( data[x1+y6+z7]*tablex1 + data[x2+y6+z7]*tablex2 + data[x3+y6+z7]*tablex3 + 01123 data[x4+y6+z7]*tablex4 + data[x5+y6+z7]*tablex5 + data[x6+y6+z7]*tablex6 + 01124 data[x7+y6+z7]*tablex7 ) * tabley6 + 01125 ( data[x1+y7+z7]*tablex1 + data[x2+y7+z7]*tablex2 + data[x3+y7+z7]*tablex3 + 01126 data[x4+y7+z7]*tablex4 + data[x5+y7+z7]*tablex5 + data[x6+y7+z7]*tablex6 + 01127 data[x7+y7+z7]*tablex7 ) * tabley7 ) *tablez7; 01128 01129 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) * 01130 (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7) * 01131 (tablez1+tablez2+tablez3+tablez4+tablez5+tablez6+tablez7); 01132 } 01133 return pixel/w; 01134 }
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 1136 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().
01136 { 01137 int K = kb.get_window_size(); 01138 int kbmin = -K/2; 01139 int kbmax = -kbmin; 01140 int kbc = kbmax+1; 01141 01142 float pixel =0.0f; 01143 float w=0.0f; 01144 01145 float argdelx = delx; // adding this for 2D case where the wrap around is not done circulantly using restrict1. 01146 delx = restrict1(delx, nx); 01147 int inxold = int(round(delx)); 01148 if ( ny < 2 ) { //1D 01149 float tablex1 = kb.i0win_tab(delx-inxold+3); 01150 float tablex2 = kb.i0win_tab(delx-inxold+2); 01151 float tablex3 = kb.i0win_tab(delx-inxold+1); 01152 float tablex4 = kb.i0win_tab(delx-inxold); 01153 float tablex5 = kb.i0win_tab(delx-inxold-1); 01154 float tablex6 = kb.i0win_tab(delx-inxold-2); 01155 float tablex7 = kb.i0win_tab(delx-inxold-3); 01156 01157 int x1, x2, x3, x4, x5, x6, x7; 01158 01159 if ( inxold <= kbc || inxold >=nx-kbc-2 ) { 01160 x1 = (inxold-3+nx)%nx; 01161 x2 = (inxold-2+nx)%nx; 01162 x3 = (inxold-1+nx)%nx; 01163 x4 = (inxold +nx)%nx; 01164 x5 = (inxold+1+nx)%nx; 01165 x6 = (inxold+2+nx)%nx; 01166 x7 = (inxold+3+nx)%nx; 01167 } else { 01168 x1 = inxold-3; 01169 x2 = inxold-2; 01170 x3 = inxold-1; 01171 x4 = inxold; 01172 x5 = inxold+1; 01173 x6 = inxold+2; 01174 x7 = inxold+3; 01175 } 01176 01177 pixel = data[x1]*tablex1 + data[x2]*tablex2 + data[x3]*tablex3 + 01178 data[x4]*tablex4 + data[x5]*tablex5 + data[x6]*tablex6 + 01179 data[x7]*tablex7 ; 01180 01181 w = tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7; 01182 } else if ( nz < 2 ) { // 2D 01183 01184 delx = argdelx; 01185 // 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 01186 if ((delx < 0.0f) || (delx >= (float) (nx)) || (dely < 0.0f) || (dely >= (float) (ny)) ){ 01187 delx = (float)xnew*2.0f; 01188 dely = (float)ynew*2.0f; 01189 } 01190 01191 int inxold = int(round(delx)); 01192 int inyold = int(round(dely)); 01193 01194 float tablex1 = kb.i0win_tab(delx-inxold+3); 01195 float tablex2 = kb.i0win_tab(delx-inxold+2); 01196 float tablex3 = kb.i0win_tab(delx-inxold+1); 01197 float tablex4 = kb.i0win_tab(delx-inxold); 01198 float tablex5 = kb.i0win_tab(delx-inxold-1); 01199 float tablex6 = kb.i0win_tab(delx-inxold-2); 01200 float tablex7 = kb.i0win_tab(delx-inxold-3); 01201 01202 float tabley1 = kb.i0win_tab(dely-inyold+3); 01203 float tabley2 = kb.i0win_tab(dely-inyold+2); 01204 float tabley3 = kb.i0win_tab(dely-inyold+1); 01205 float tabley4 = kb.i0win_tab(dely-inyold); 01206 float tabley5 = kb.i0win_tab(dely-inyold-1); 01207 float tabley6 = kb.i0win_tab(dely-inyold-2); 01208 float tabley7 = kb.i0win_tab(dely-inyold-3); 01209 01210 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7; 01211 01212 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 ) { 01213 x1 = (inxold-3+nx)%nx; 01214 x2 = (inxold-2+nx)%nx; 01215 x3 = (inxold-1+nx)%nx; 01216 x4 = (inxold +nx)%nx; 01217 x5 = (inxold+1+nx)%nx; 01218 x6 = (inxold+2+nx)%nx; 01219 x7 = (inxold+3+nx)%nx; 01220 01221 y1 = ((inyold-3+ny)%ny)*nx; 01222 y2 = ((inyold-2+ny)%ny)*nx; 01223 y3 = ((inyold-1+ny)%ny)*nx; 01224 y4 = ((inyold +ny)%ny)*nx; 01225 y5 = ((inyold+1+ny)%ny)*nx; 01226 y6 = ((inyold+2+ny)%ny)*nx; 01227 y7 = ((inyold+3+ny)%ny)*nx; 01228 } else { 01229 x1 = inxold-3; 01230 x2 = inxold-2; 01231 x3 = inxold-1; 01232 x4 = inxold; 01233 x5 = inxold+1; 01234 x6 = inxold+2; 01235 x7 = inxold+3; 01236 01237 y1 = (inyold-3)*nx; 01238 y2 = (inyold-2)*nx; 01239 y3 = (inyold-1)*nx; 01240 y4 = inyold*nx; 01241 y5 = (inyold+1)*nx; 01242 y6 = (inyold+2)*nx; 01243 y7 = (inyold+3)*nx; 01244 } 01245 01246 pixel = ( data[x1+y1]*tablex1 + data[x2+y1]*tablex2 + data[x3+y1]*tablex3 + 01247 data[x4+y1]*tablex4 + data[x5+y1]*tablex5 + data[x6+y1]*tablex6 + 01248 data[x7+y1]*tablex7 ) * tabley1 + 01249 ( data[x1+y2]*tablex1 + data[x2+y2]*tablex2 + data[x3+y2]*tablex3 + 01250 data[x4+y2]*tablex4 + data[x5+y2]*tablex5 + data[x6+y2]*tablex6 + 01251 data[x7+y2]*tablex7 ) * tabley2 + 01252 ( data[x1+y3]*tablex1 + data[x2+y3]*tablex2 + data[x3+y3]*tablex3 + 01253 data[x4+y3]*tablex4 + data[x5+y3]*tablex5 + data[x6+y3]*tablex6 + 01254 data[x7+y3]*tablex7 ) * tabley3 + 01255 ( data[x1+y4]*tablex1 + data[x2+y4]*tablex2 + data[x3+y4]*tablex3 + 01256 data[x4+y4]*tablex4 + data[x5+y4]*tablex5 + data[x6+y4]*tablex6 + 01257 data[x7+y4]*tablex7 ) * tabley4 + 01258 ( data[x1+y5]*tablex1 + data[x2+y5]*tablex2 + data[x3+y5]*tablex3 + 01259 data[x4+y5]*tablex4 + data[x5+y5]*tablex5 + data[x6+y5]*tablex6 + 01260 data[x7+y5]*tablex7 ) * tabley5 + 01261 ( data[x1+y6]*tablex1 + data[x2+y6]*tablex2 + data[x3+y6]*tablex3 + 01262 data[x4+y6]*tablex4 + data[x5+y6]*tablex5 + data[x6+y6]*tablex6 + 01263 data[x7+y6]*tablex7 ) * tabley6 + 01264 ( data[x1+y7]*tablex1 + data[x2+y7]*tablex2 + data[x3+y7]*tablex3 + 01265 data[x4+y7]*tablex4 + data[x5+y7]*tablex5 + data[x6+y7]*tablex6 + 01266 data[x7+y7]*tablex7 ) * tabley7; 01267 01268 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) * 01269 (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7); 01270 } else { // 3D 01271 dely = restrict1(dely, ny); 01272 int inyold = int(Util::round(dely)); 01273 delz = restrict1(delz, nz); 01274 int inzold = int(Util::round(delz)); 01275 01276 float tablex1 = kb.i0win_tab(delx-inxold+3); 01277 float tablex2 = kb.i0win_tab(delx-inxold+2); 01278 float tablex3 = kb.i0win_tab(delx-inxold+1); 01279 float tablex4 = kb.i0win_tab(delx-inxold); 01280 float tablex5 = kb.i0win_tab(delx-inxold-1); 01281 float tablex6 = kb.i0win_tab(delx-inxold-2); 01282 float tablex7 = kb.i0win_tab(delx-inxold-3); 01283 01284 float tabley1 = kb.i0win_tab(dely-inyold+3); 01285 float tabley2 = kb.i0win_tab(dely-inyold+2); 01286 float tabley3 = kb.i0win_tab(dely-inyold+1); 01287 float tabley4 = kb.i0win_tab(dely-inyold); 01288 float tabley5 = kb.i0win_tab(dely-inyold-1); 01289 float tabley6 = kb.i0win_tab(dely-inyold-2); 01290 float tabley7 = kb.i0win_tab(dely-inyold-3); 01291 01292 float tablez1 = kb.i0win_tab(delz-inzold+3); 01293 float tablez2 = kb.i0win_tab(delz-inzold+2); 01294 float tablez3 = kb.i0win_tab(delz-inzold+1); 01295 float tablez4 = kb.i0win_tab(delz-inzold); 01296 float tablez5 = kb.i0win_tab(delz-inzold-1); 01297 float tablez6 = kb.i0win_tab(delz-inzold-2); 01298 float tablez7 = kb.i0win_tab(delz-inzold-3); 01299 01300 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7, z1, z2, z3, z4, z5, z6, z7; 01301 01302 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 || inzold <= kbc || inzold >= nz-kbc-2 ) { 01303 x1 = (inxold-3+nx)%nx; 01304 x2 = (inxold-2+nx)%nx; 01305 x3 = (inxold-1+nx)%nx; 01306 x4 = (inxold +nx)%nx; 01307 x5 = (inxold+1+nx)%nx; 01308 x6 = (inxold+2+nx)%nx; 01309 x7 = (inxold+3+nx)%nx; 01310 01311 y1 = ((inyold-3+ny)%ny)*nx; 01312 y2 = ((inyold-2+ny)%ny)*nx; 01313 y3 = ((inyold-1+ny)%ny)*nx; 01314 y4 = ((inyold +ny)%ny)*nx; 01315 y5 = ((inyold+1+ny)%ny)*nx; 01316 y6 = ((inyold+2+ny)%ny)*nx; 01317 y7 = ((inyold+3+ny)%ny)*nx; 01318 01319 z1 = ((inzold-3+nz)%nz)*nx*ny; 01320 z2 = ((inzold-2+nz)%nz)*nx*ny; 01321 z3 = ((inzold-1+nz)%nz)*nx*ny; 01322 z4 = ((inzold +nz)%nz)*nx*ny; 01323 z5 = ((inzold+1+nz)%nz)*nx*ny; 01324 z6 = ((inzold+2+nz)%nz)*nx*ny; 01325 z7 = ((inzold+3+nz)%nz)*nx*ny; 01326 } else { 01327 x1 = inxold-3; 01328 x2 = inxold-2; 01329 x3 = inxold-1; 01330 x4 = inxold; 01331 x5 = inxold+1; 01332 x6 = inxold+2; 01333 x7 = inxold+3; 01334 01335 y1 = (inyold-3)*nx; 01336 y2 = (inyold-2)*nx; 01337 y3 = (inyold-1)*nx; 01338 y4 = inyold*nx; 01339 y5 = (inyold+1)*nx; 01340 y6 = (inyold+2)*nx; 01341 y7 = (inyold+3)*nx; 01342 01343 z1 = (inzold-3)*nx*ny; 01344 z2 = (inzold-2)*nx*ny; 01345 z3 = (inzold-1)*nx*ny; 01346 z4 = inzold*nx*ny; 01347 z5 = (inzold+1)*nx*ny; 01348 z6 = (inzold+2)*nx*ny; 01349 z7 = (inzold+3)*nx*ny; 01350 } 01351 01352 pixel = ( ( data[x1+y1+z1]*tablex1 + data[x2+y1+z1]*tablex2 + data[x3+y1+z1]*tablex3 + 01353 data[x4+y1+z1]*tablex4 + data[x5+y1+z1]*tablex5 + data[x6+y1+z1]*tablex6 + 01354 data[x7+y1+z1]*tablex7 ) * tabley1 + 01355 ( data[x1+y2+z1]*tablex1 + data[x2+y2+z1]*tablex2 + data[x3+y2+z1]*tablex3 + 01356 data[x4+y2+z1]*tablex4 + data[x5+y2+z1]*tablex5 + data[x6+y2+z1]*tablex6 + 01357 data[x7+y2+z1]*tablex7 ) * tabley2 + 01358 ( data[x1+y3+z1]*tablex1 + data[x2+y3+z1]*tablex2 + data[x3+y3+z1]*tablex3 + 01359 data[x4+y3+z1]*tablex4 + data[x5+y3+z1]*tablex5 + data[x6+y3+z1]*tablex6 + 01360 data[x7+y3+z1]*tablex7 ) * tabley3 + 01361 ( data[x1+y4+z1]*tablex1 + data[x2+y4+z1]*tablex2 + data[x3+y4+z1]*tablex3 + 01362 data[x4+y4+z1]*tablex4 + data[x5+y4+z1]*tablex5 + data[x6+y4+z1]*tablex6 + 01363 data[x7+y4+z1]*tablex7 ) * tabley4 + 01364 ( data[x1+y5+z1]*tablex1 + data[x2+y5+z1]*tablex2 + data[x3+y5+z1]*tablex3 + 01365 data[x4+y5+z1]*tablex4 + data[x5+y5+z1]*tablex5 + data[x6+y5+z1]*tablex6 + 01366 data[x7+y5+z1]*tablex7 ) * tabley5 + 01367 ( data[x1+y6+z1]*tablex1 + data[x2+y6+z1]*tablex2 + data[x3+y6+z1]*tablex3 + 01368 data[x4+y6+z1]*tablex4 + data[x5+y6+z1]*tablex5 + data[x6+y6+z1]*tablex6 + 01369 data[x7+y6+z1]*tablex7 ) * tabley6 + 01370 ( data[x1+y7+z1]*tablex1 + data[x2+y7+z1]*tablex2 + data[x3+y7+z1]*tablex3 + 01371 data[x4+y7+z1]*tablex4 + data[x5+y7+z1]*tablex5 + data[x6+y7+z1]*tablex6 + 01372 data[x7+y7+z1]*tablex7 ) * tabley7 ) *tablez1 + 01373 ( ( data[x1+y1+z2]*tablex1 + data[x2+y1+z2]*tablex2 + data[x3+y1+z2]*tablex3 + 01374 data[x4+y1+z2]*tablex4 + data[x5+y1+z2]*tablex5 + data[x6+y1+z2]*tablex6 + 01375 data[x7+y1+z2]*tablex7 ) * tabley1 + 01376 ( data[x1+y2+z2]*tablex1 + data[x2+y2+z2]*tablex2 + data[x3+y2+z2]*tablex3 + 01377 data[x4+y2+z2]*tablex4 + data[x5+y2+z2]*tablex5 + data[x6+y2+z2]*tablex6 + 01378 data[x7+y2+z2]*tablex7 ) * tabley2 + 01379 ( data[x1+y3+z2]*tablex1 + data[x2+y3+z2]*tablex2 + data[x3+y3+z2]*tablex3 + 01380 data[x4+y3+z2]*tablex4 + data[x5+y3+z2]*tablex5 + data[x6+y3+z2]*tablex6 + 01381 data[x7+y3+z2]*tablex7 ) * tabley3 + 01382 ( data[x1+y4+z2]*tablex1 + data[x2+y4+z2]*tablex2 + data[x3+y4+z2]*tablex3 + 01383 data[x4+y4+z2]*tablex4 + data[x5+y4+z2]*tablex5 + data[x6+y4+z2]*tablex6 + 01384 data[x7+y4+z2]*tablex7 ) * tabley4 + 01385 ( data[x1+y5+z2]*tablex1 + data[x2+y5+z2]*tablex2 + data[x3+y5+z2]*tablex3 + 01386 data[x4+y5+z2]*tablex4 + data[x5+y5+z2]*tablex5 + data[x6+y5+z2]*tablex6 + 01387 data[x7+y5+z2]*tablex7 ) * tabley5 + 01388 ( data[x1+y6+z2]*tablex1 + data[x2+y6+z2]*tablex2 + data[x3+y6+z2]*tablex3 + 01389 data[x4+y6+z2]*tablex4 + data[x5+y6+z2]*tablex5 + data[x6+y6+z2]*tablex6 + 01390 data[x7+y6+z2]*tablex7 ) * tabley6 + 01391 ( data[x1+y7+z2]*tablex1 + data[x2+y7+z2]*tablex2 + data[x3+y7+z2]*tablex3 + 01392 data[x4+y7+z2]*tablex4 + data[x5+y7+z2]*tablex5 + data[x6+y7+z2]*tablex6 + 01393 data[x7+y7+z2]*tablex7 ) * tabley7 ) *tablez2 + 01394 ( ( data[x1+y1+z3]*tablex1 + data[x2+y1+z3]*tablex2 + data[x3+y1+z3]*tablex3 + 01395 data[x4+y1+z3]*tablex4 + data[x5+y1+z3]*tablex5 + data[x6+y1+z3]*tablex6 + 01396 data[x7+y1+z3]*tablex7 ) * tabley1 + 01397 ( data[x1+y2+z3]*tablex1 + data[x2+y2+z3]*tablex2 + data[x3+y2+z3]*tablex3 + 01398 data[x4+y2+z3]*tablex4 + data[x5+y2+z3]*tablex5 + data[x6+y2+z3]*tablex6 + 01399 data[x7+y2+z3]*tablex7 ) * tabley2 + 01400 ( data[x1+y3+z3]*tablex1 + data[x2+y3+z3]*tablex2 + data[x3+y3+z3]*tablex3 + 01401 data[x4+y3+z3]*tablex4 + data[x5+y3+z3]*tablex5 + data[x6+y3+z3]*tablex6 + 01402 data[x7+y3+z3]*tablex7 ) * tabley3 + 01403 ( data[x1+y4+z3]*tablex1 + data[x2+y4+z3]*tablex2 + data[x3+y4+z3]*tablex3 + 01404 data[x4+y4+z3]*tablex4 + data[x5+y4+z3]*tablex5 + data[x6+y4+z3]*tablex6 + 01405 data[x7+y4+z3]*tablex7 ) * tabley4 + 01406 ( data[x1+y5+z3]*tablex1 + data[x2+y5+z3]*tablex2 + data[x3+y5+z3]*tablex3 + 01407 data[x4+y5+z3]*tablex4 + data[x5+y5+z3]*tablex5 + data[x6+y5+z3]*tablex6 + 01408 data[x7+y5+z3]*tablex7 ) * tabley5 + 01409 ( data[x1+y6+z3]*tablex1 + data[x2+y6+z3]*tablex2 + data[x3+y6+z3]*tablex3 + 01410 data[x4+y6+z3]*tablex4 + data[x5+y6+z3]*tablex5 + data[x6+y6+z3]*tablex6 + 01411 data[x7+y6+z3]*tablex7 ) * tabley6 + 01412 ( data[x1+y7+z3]*tablex1 + data[x2+y7+z3]*tablex2 + data[x3+y7+z3]*tablex3 + 01413 data[x4+y7+z3]*tablex4 + data[x5+y7+z3]*tablex5 + data[x6+y7+z3]*tablex6 + 01414 data[x7+y7+z3]*tablex7 ) * tabley7 ) *tablez3 + 01415 ( ( data[x1+y1+z4]*tablex1 + data[x2+y1+z4]*tablex2 + data[x3+y1+z4]*tablex3 + 01416 data[x4+y1+z4]*tablex4 + data[x5+y1+z4]*tablex5 + data[x6+y1+z4]*tablex6 + 01417 data[x7+y1+z4]*tablex7 ) * tabley1 + 01418 ( data[x1+y2+z4]*tablex1 + data[x2+y2+z4]*tablex2 + data[x3+y2+z4]*tablex3 + 01419 data[x4+y2+z4]*tablex4 + data[x5+y2+z4]*tablex5 + data[x6+y2+z4]*tablex6 + 01420 data[x7+y2+z4]*tablex7 ) * tabley2 + 01421 ( data[x1+y3+z4]*tablex1 + data[x2+y3+z4]*tablex2 + data[x3+y3+z4]*tablex3 + 01422 data[x4+y3+z4]*tablex4 + data[x5+y3+z4]*tablex5 + data[x6+y3+z4]*tablex6 + 01423 data[x7+y3+z4]*tablex7 ) * tabley3 + 01424 ( data[x1+y4+z4]*tablex1 + data[x2+y4+z4]*tablex2 + data[x3+y4+z4]*tablex3 + 01425 data[x4+y4+z4]*tablex4 + data[x5+y4+z4]*tablex5 + data[x6+y4+z4]*tablex6 + 01426 data[x7+y4+z4]*tablex7 ) * tabley4 + 01427 ( data[x1+y5+z4]*tablex1 + data[x2+y5+z4]*tablex2 + data[x3+y5+z4]*tablex3 + 01428 data[x4+y5+z4]*tablex4 + data[x5+y5+z4]*tablex5 + data[x6+y5+z4]*tablex6 + 01429 data[x7+y5+z4]*tablex7 ) * tabley5 + 01430 ( data[x1+y6+z4]*tablex1 + data[x2+y6+z4]*tablex2 + data[x3+y6+z4]*tablex3 + 01431 data[x4+y6+z4]*tablex4 + data[x5+y6+z4]*tablex5 + data[x6+y6+z4]*tablex6 + 01432 data[x7+y6+z4]*tablex7 ) * tabley6 + 01433 ( data[x1+y7+z4]*tablex1 + data[x2+y7+z4]*tablex2 + data[x3+y7+z4]*tablex3 + 01434 data[x4+y7+z4]*tablex4 + data[x5+y7+z4]*tablex5 + data[x6+y7+z4]*tablex6 + 01435 data[x7+y7+z4]*tablex7 ) * tabley7 ) *tablez4 + 01436 ( ( data[x1+y1+z5]*tablex1 + data[x2+y1+z5]*tablex2 + data[x3+y1+z5]*tablex3 + 01437 data[x4+y1+z5]*tablex4 + data[x5+y1+z5]*tablex5 + data[x6+y1+z5]*tablex6 + 01438 data[x7+y1+z5]*tablex7 ) * tabley1 + 01439 ( data[x1+y2+z5]*tablex1 + data[x2+y2+z5]*tablex2 + data[x3+y2+z5]*tablex3 + 01440 data[x4+y2+z5]*tablex4 + data[x5+y2+z5]*tablex5 + data[x6+y2+z5]*tablex6 + 01441 data[x7+y2+z5]*tablex7 ) * tabley2 + 01442 ( data[x1+y3+z5]*tablex1 + data[x2+y3+z5]*tablex2 + data[x3+y3+z5]*tablex3 + 01443 data[x4+y3+z5]*tablex4 + data[x5+y3+z5]*tablex5 + data[x6+y3+z5]*tablex6 + 01444 data[x7+y3+z5]*tablex7 ) * tabley3 + 01445 ( data[x1+y4+z5]*tablex1 + data[x2+y4+z5]*tablex2 + data[x3+y4+z5]*tablex3 + 01446 data[x4+y4+z5]*tablex4 + data[x5+y4+z5]*tablex5 + data[x6+y4+z5]*tablex6 + 01447 data[x7+y4+z5]*tablex7 ) * tabley4 + 01448 ( data[x1+y5+z5]*tablex1 + data[x2+y5+z5]*tablex2 + data[x3+y5+z5]*tablex3 + 01449 data[x4+y5+z5]*tablex4 + data[x5+y5+z5]*tablex5 + data[x6+y5+z5]*tablex6 + 01450 data[x7+y5+z5]*tablex7 ) * tabley5 + 01451 ( data[x1+y6+z5]*tablex1 + data[x2+y6+z5]*tablex2 + data[x3+y6+z5]*tablex3 + 01452 data[x4+y6+z5]*tablex4 + data[x5+y6+z5]*tablex5 + data[x6+y6+z5]*tablex6 + 01453 data[x7+y6+z5]*tablex7 ) * tabley6 + 01454 ( data[x1+y7+z5]*tablex1 + data[x2+y7+z5]*tablex2 + data[x3+y7+z5]*tablex3 + 01455 data[x4+y7+z5]*tablex4 + data[x5+y7+z5]*tablex5 + data[x6+y7+z5]*tablex6 + 01456 data[x7+y7+z5]*tablex7 ) * tabley7 ) *tablez5 + 01457 ( ( data[x1+y1+z6]*tablex1 + data[x2+y1+z6]*tablex2 + data[x3+y1+z6]*tablex3 + 01458 data[x4+y1+z6]*tablex4 + data[x5+y1+z6]*tablex5 + data[x6+y1+z6]*tablex6 + 01459 data[x7+y1+z6]*tablex7 ) * tabley1 + 01460 ( data[x1+y2+z6]*tablex1 + data[x2+y2+z6]*tablex2 + data[x3+y2+z6]*tablex3 + 01461 data[x4+y2+z6]*tablex4 + data[x5+y2+z6]*tablex5 + data[x6+y2+z6]*tablex6 + 01462 data[x7+y2+z6]*tablex7 ) * tabley2 + 01463 ( data[x1+y3+z6]*tablex1 + data[x2+y3+z6]*tablex2 + data[x3+y3+z6]*tablex3 + 01464 data[x4+y3+z6]*tablex4 + data[x5+y3+z6]*tablex5 + data[x6+y3+z6]*tablex6 + 01465 data[x7+y3+z6]*tablex7 ) * tabley3 + 01466 ( data[x1+y4+z6]*tablex1 + data[x2+y4+z6]*tablex2 + data[x3+y4+z6]*tablex3 + 01467 data[x4+y4+z6]*tablex4 + data[x5+y4+z6]*tablex5 + data[x6+y4+z6]*tablex6 + 01468 data[x7+y4+z6]*tablex7 ) * tabley4 + 01469 ( data[x1+y5+z6]*tablex1 + data[x2+y5+z6]*tablex2 + data[x3+y5+z6]*tablex3 + 01470 data[x4+y5+z6]*tablex4 + data[x5+y5+z6]*tablex5 + data[x6+y5+z6]*tablex6 + 01471 data[x7+y5+z6]*tablex7 ) * tabley5 + 01472 ( data[x1+y6+z6]*tablex1 + data[x2+y6+z6]*tablex2 + data[x3+y6+z6]*tablex3 + 01473 data[x4+y6+z6]*tablex4 + data[x5+y6+z6]*tablex5 + data[x6+y6+z6]*tablex6 + 01474 data[x7+y6+z6]*tablex7 ) * tabley6 + 01475 ( data[x1+y7+z6]*tablex1 + data[x2+y7+z6]*tablex2 + data[x3+y7+z6]*tablex3 + 01476 data[x4+y7+z6]*tablex4 + data[x5+y7+z6]*tablex5 + data[x6+y7+z6]*tablex6 + 01477 data[x7+y7+z6]*tablex7 ) * tabley7 ) *tablez6 + 01478 ( ( data[x1+y1+z7]*tablex1 + data[x2+y1+z7]*tablex2 + data[x3+y1+z7]*tablex3 + 01479 data[x4+y1+z7]*tablex4 + data[x5+y1+z7]*tablex5 + data[x6+y1+z7]*tablex6 + 01480 data[x7+y1+z7]*tablex7 ) * tabley1 + 01481 ( data[x1+y2+z7]*tablex1 + data[x2+y2+z7]*tablex2 + data[x3+y2+z7]*tablex3 + 01482 data[x4+y2+z7]*tablex4 + data[x5+y2+z7]*tablex5 + data[x6+y2+z7]*tablex6 + 01483 data[x7+y2+z7]*tablex7 ) * tabley2 + 01484 ( data[x1+y3+z7]*tablex1 + data[x2+y3+z7]*tablex2 + data[x3+y3+z7]*tablex3 + 01485 data[x4+y3+z7]*tablex4 + data[x5+y3+z7]*tablex5 + data[x6+y3+z7]*tablex6 + 01486 data[x7+y3+z7]*tablex7 ) * tabley3 + 01487 ( data[x1+y4+z7]*tablex1 + data[x2+y4+z7]*tablex2 + data[x3+y4+z7]*tablex3 + 01488 data[x4+y4+z7]*tablex4 + data[x5+y4+z7]*tablex5 + data[x6+y4+z7]*tablex6 + 01489 data[x7+y4+z7]*tablex7 ) * tabley4 + 01490 ( data[x1+y5+z7]*tablex1 + data[x2+y5+z7]*tablex2 + data[x3+y5+z7]*tablex3 + 01491 data[x4+y5+z7]*tablex4 + data[x5+y5+z7]*tablex5 + data[x6+y5+z7]*tablex6 + 01492 data[x7+y5+z7]*tablex7 ) * tabley5 + 01493 ( data[x1+y6+z7]*tablex1 + data[x2+y6+z7]*tablex2 + data[x3+y6+z7]*tablex3 + 01494 data[x4+y6+z7]*tablex4 + data[x5+y6+z7]*tablex5 + data[x6+y6+z7]*tablex6 + 01495 data[x7+y6+z7]*tablex7 ) * tabley6 + 01496 ( data[x1+y7+z7]*tablex1 + data[x2+y7+z7]*tablex2 + data[x3+y7+z7]*tablex3 + 01497 data[x4+y7+z7]*tablex4 + data[x5+y7+z7]*tablex5 + data[x6+y7+z7]*tablex6 + 01498 data[x7+y7+z7]*tablex7 ) * tabley7 ) *tablez7; 01499 01500 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) * 01501 (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7) * 01502 (tablez1+tablez2+tablez3+tablez4+tablez5+tablez6+tablez7); 01503 } 01504 return pixel/w; 01505 }
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 19548 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().
19548 { 19549 19550 int nx = vol->get_xsize(); 19551 int ny = vol->get_ysize(); 19552 int nz = vol->get_zsize(); 19553 float *vol_data = vol->get_data(); 19554 int new_nx, new_ny; 19555 19556 if (nz == 1) 19557 throw ImageDimensionException("Error: Input must be a 3-D object"); 19558 if ((dim < 1) || (dim > 3)) 19559 throw ImageDimensionException("Error: dim must be 1 (x-dimension), 2 (y-dimension) or 3 (z-dimension)"); 19560 if (((dim == 1) && (index < 0 || index > nx-1)) || 19561 ((dim == 1) && (index < 0 || index > nx-1)) || 19562 ((dim == 1) && (index < 0 || index > nx-1))) 19563 throw ImageDimensionException("Error: index exceeds the size of the 3-D object"); 19564 19565 if (dim == 1) { 19566 new_nx = ny; 19567 new_ny = nz; 19568 } else if (dim == 2) { 19569 new_nx = nx; 19570 new_ny = nz; 19571 } else { 19572 new_nx = nx; 19573 new_ny = ny; 19574 } 19575 19576 EMData *slice = new EMData(); 19577 slice->set_size(new_nx, new_ny, 1); 19578 float *slice_data = slice->get_data(); 19579 19580 if (dim == 1) { 19581 for (int x=0; x<new_nx; x++) 19582 for (int y=0; y<new_ny; y++) 19583 slice_data[y*new_nx+x] = vol_data[(y*ny+x)*nx+index]; 19584 } else if (dim == 2) { 19585 for (int x=0; x<new_nx; x++) 19586 for (int y=0; y<new_ny; y++) 19587 slice_data[y*new_nx+x] = vol_data[(y*ny+index)*nx+x]; 19588 } else { 19589 for (int x=0; x<new_nx; x++) 19590 for (int y=0; y<new_ny; y++) 19591 slice_data[y*new_nx+x] = vol_data[(index*ny+y)*nx+x]; 19592 } 19593 19594 return slice; 19595 }
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 874 of file util.cpp.
References EmptyContainerException, sqrt(), and square_sum().
00875 { 00876 // Note that this is a heavy STL approach using generic algorithms - some memory could be saved 00877 // using plain c style code, as in get_stats_cstyle below 00878 00879 if (data.size() == 0) EmptyContainerException("Error, attempting to call get stats on an empty container (vector<double>)"); 00880 00881 double sum = accumulate(data.begin(), data.end(), 0.0); 00882 00883 double mean = sum / static_cast<double> (data.size()); 00884 00885 double std_dev = 0.0, skewness = 0.0, kurtosis = 0.0; 00886 00887 if (data.size() > 1) 00888 { 00889 // read mm is "minus_mean" 00890 vector<double> data_mm(data.size()); 00891 // read ts as "then squared" 00892 vector<double> data_mm_sq(data.size()); 00893 00894 // Subtract the mean from the data and store it in data_mm 00895 transform(data.begin(), data.end(), data_mm.begin(), std::bind2nd(std::minus<double>(), mean)); 00896 00897 // Get the square of the data minus the mean and store it in data_mm_sq 00898 transform(data_mm.begin(), data_mm.end(), data_mm.begin(), data_mm_sq.begin(), std::multiplies<double>()); 00899 00900 // Get the sum of the squares for the calculation of the standard deviation 00901 double square_sum = accumulate(data_mm_sq.begin(), data_mm_sq.end(), 0.0); 00902 00903 //Calculate teh standard deviation 00904 std_dev = sqrt(square_sum / static_cast<double>(data.size()-1)); 00905 double std_dev_sq = std_dev * std_dev; 00906 00907 // The numerator for the skewness fraction, as defined in http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm 00908 double cubic_sum = inner_product(data_mm.begin(), data_mm.end(),data_mm_sq.begin(), 0.0); 00909 00910 // The numerator for the kurtosis fraction, as defined in http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm 00911 double quartic_sum = inner_product(data_mm_sq.begin(), data_mm_sq.end(),data_mm_sq.begin(), 0.0); 00912 00913 // Finalize the calculation of the skewness and kurtosis, as defined in 00914 // http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm 00915 skewness = cubic_sum / ((data.size()-1) * std_dev_sq * std_dev ); 00916 kurtosis = quartic_sum / ((data.size()-1) * std_dev_sq * std_dev_sq ); 00917 00918 } 00919 00920 Dict parms; 00921 parms["mean"] = mean; 00922 parms["std_dev"] = std_dev; 00923 parms["skewness"] = skewness; 00924 parms["kurtosis"] = kurtosis; 00925 00926 return parms; 00927 }
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 930 of file util.cpp.
References EmptyContainerException, sqrt(), square(), and square_sum().
00931 { 00932 if (data.size() == 0) EmptyContainerException("Error, attempting to call get stats on an empty container (vector<double>)"); 00933 00934 double square_sum = 0.0, sum = 0.0, cube_sum = 0.0, quart_sum = 0.0; 00935 for( vector<float>::const_iterator it = data.begin(); it != data.end(); ++it ) 00936 { 00937 double val = *it; 00938 double square = val*val; 00939 quart_sum += square*square; 00940 cube_sum += square*val; 00941 square_sum += square; 00942 sum += val; 00943 } 00944 00945 double mean = sum/(double)data.size(); 00946 00947 double std_dev = 0.0, skewness = 0.0, kurtosis = 0.0; 00948 00949 if (data.size() > 1) 00950 { 00951 // The standard deviation is calculated here 00952 std_dev = sqrt( (square_sum - mean*sum)/(double)(data.size()-1)); 00953 00954 double square_mean = mean*mean; 00955 double cube_mean = mean*square_mean; 00956 00957 double square_std_dev = std_dev*std_dev; 00958 00959 // This is the numerator of the skewness fraction, if you expand the brackets, as defined in 00960 // http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm 00961 double cubic_sum = cube_sum - 3*square_sum*mean + 3*sum*square_mean - cube_mean*data.size(); 00962 // Complete the skewness fraction 00963 skewness = cubic_sum/((data.size()-1)*square_std_dev*std_dev); 00964 00965 // This is the numerator of the kurtosis fraction, if you expand the brackets, as defined in 00966 // http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm 00967 double quartic_sum = quart_sum - 4*cube_sum*mean + 6*square_sum*square_mean - 4*sum*cube_mean + square_mean*square_mean*data.size(); 00968 // Complete the kurtosis fraction 00969 kurtosis = quartic_sum /( (data.size()-1)*square_std_dev*square_std_dev); 00970 } 00971 00972 Dict parms; 00973 parms["mean"] = mean; 00974 parms["std_dev"] = std_dev; 00975 parms["skewness"] = skewness; 00976 parms["kurtosis"] = kurtosis; 00977 00978 return parms; 00979 }
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 1094 of file util.cpp.
References t.
01095 { 01096 time_t t0 = time(0); 01097 struct tm *t = localtime(&t0); 01098 char label[32]; 01099 sprintf(label, "%d/%02d/%04d %d:%02d", 01100 t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour, t->tm_min); 01101 return string(label); 01102 }
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 1159 of file util.cpp.
References abs, printmatrix(), printvector(), q, rhs, V, and W.
Referenced by EMAN::FourierInserter3DMode8::init().
01160 { 01161 int i = 0; 01162 int discs = (int)(1+2*freq_cutoff/dfreq); 01163 01164 float* W = new float[discs]; 01165 01166 int fc = (int)(2*freq_cutoff + 1); 01167 gsl_matrix* M = gsl_matrix_calloc(fc,fc); 01168 01169 gsl_vector* rhs = gsl_vector_calloc(fc); 01170 cout << i++ << endl; 01171 for(int k = -freq_cutoff; k <= freq_cutoff; ++k){ 01172 for(int kp = -freq_cutoff; kp <= freq_cutoff; ++kp){ 01173 int kdiff =abs( k-kp); 01174 int evenoddfac = ( kdiff % 2 == 0 ? 1 : -1); 01175 01176 if (kdiff !=0){ 01177 float val = sin(M_PI*(float)kdiff*r)/(sin(M_PI*(float)kdiff/(float)P))*(alpha+2.0f*beta*evenoddfac); 01178 gsl_matrix_set(M,int(k+freq_cutoff),int(kp+freq_cutoff),val); 01179 } 01180 } 01181 gsl_matrix_set(M,int(k+freq_cutoff),int(k+freq_cutoff),r*P* (alpha+2*beta)); 01182 float val = alpha*sin(M_PI*k*r)/(sin(M_PI*(float)k/(float)P)); 01183 if (k!=0) { 01184 gsl_vector_set(rhs,int(k+freq_cutoff),val); 01185 } 01186 } 01187 printmatrix(M,fc,fc,"M"); 01188 01189 gsl_vector_set(rhs,int(freq_cutoff),alpha*r*P); 01190 gsl_matrix* V = gsl_matrix_calloc(fc,fc); 01191 gsl_vector* S = gsl_vector_calloc(fc); 01192 gsl_vector* soln = gsl_vector_calloc(fc); 01193 gsl_linalg_SV_decomp(M,V,S,soln); 01194 01195 gsl_linalg_SV_solve(M, V, S, rhs, soln); // soln now runs from -freq_cutoff to + freq_cutoff 01196 printvector(soln,fc,"soln"); 01197 01198 // we want to solve for W, which ranges from -freq_cutoff to +freq_cutoff in steps of dfreq 2 01199 int Count=0; 01200 for(float q = (float)(-freq_cutoff); q <= (float)(freq_cutoff); q+= dfreq){ 01201 float temp=0; 01202 for(int k = -freq_cutoff; k <= freq_cutoff; ++k){ 01203 float dtemp; 01204 if (q!=k) { 01205 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)); 01206 } else{ 01207 dtemp = (1/(float) P)* (float)gsl_vector_get(soln,int(k+freq_cutoff)) * P; 01208 } 01209 temp +=dtemp; 01210 } 01211 W[Count]=temp; 01212 cout << W[Count] << " "; 01213 Count+=1; 01214 } 01215 cout << endl; 01216 return W; 01217 }
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 1885 of file util.h.
Referenced by 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, | |||
int | 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 5571 of file util_sparx.cpp.
References EMAN::EMData::get_data(), and img_ptr.
05572 { 05573 float *img_ptr = img->get_data(); 05574 float *mask_ptr = (mask == NULL)?img->get_data():mask->get_data(); 05575 05576 int *img_freq_bin = new int[3*hist_len]; 05577 for(int i = 0;i < (3*hist_len);i++) img_freq_bin[i] = 0; 05578 for(int i = 0;i < size_img;i++) { 05579 if(mask_ptr[i] > 0.5f) { 05580 float img_xn = img_ptr[i]*PA + PB; 05581 int L = static_cast<int>(((img_xn - ref_h_min)/ref_h_diff) * (hist_len-1) + hist_len+1); 05582 if(L >= 0 && L < (3*hist_len)) img_freq_bin[L]++; 05583 } 05584 } 05585 int freq_hist = 0; 05586 05587 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); 05588 freq_hist = (-freq_hist); 05589 return static_cast<float>(freq_hist); 05590 }
Definition at line 5479 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.
05480 { 05481 /* Exception Handle */ 05482 if (img->is_complex() || ref->is_complex()) 05483 throw ImageFormatException("Cannot do Histogram on Fourier Image"); 05484 05485 if(mask != NULL){ 05486 if(img->get_xsize() != mask->get_xsize() || img->get_ysize() != mask->get_ysize() || img->get_zsize() != mask->get_zsize()) 05487 throw ImageDimensionException("The size of mask image should be of same size as the input image"); } 05488 /* ===================================================== */ 05489 05490 /* Image size calculation */ 05491 int size_ref = ((ref->get_xsize())*(ref->get_ysize())*(ref->get_zsize())); 05492 int size_img = ((img->get_xsize())*(img->get_ysize())*(img->get_zsize())); 05493 /* ===================================================== */ 05494 05495 /* The reference image attributes */ 05496 float *ref_ptr = ref->get_data(); 05497 float ref_h_min = ref->get_attr("minimum"); 05498 float ref_h_max = ref->get_attr("maximum"); 05499 float ref_h_avg = ref->get_attr("mean"); 05500 float ref_h_sig = ref->get_attr("sigma"); 05501 /* ===================================================== */ 05502 05503 /* Input image under mask attributes */ 05504 float *mask_ptr = (mask == NULL)?img->get_data():mask->get_data(); 05505 05506 vector<float> img_data = Util::infomask(img, mask); 05507 float img_avg = img_data[0]; 05508 float img_sig = img_data[1]; 05509 05510 /* The image under mask -- size calculation */ 05511 int cnt=0; 05512 for(int i=0;i<size_img;i++) 05513 if (mask_ptr[i]>0.5f) 05514 cnt++; 05515 /* ===================================================== */ 05516 05517 /* Histogram of reference image calculation */ 05518 float ref_h_diff = ref_h_max - ref_h_min; 05519 05520 #ifdef _WIN32 05521 int hist_len = _MIN((int)size_ref/16,_MIN((int)size_img/16,256)); 05522 #else 05523 int hist_len = std::min((int)size_ref/16,std::min((int)size_img/16,256)); 05524 #endif //_WIN32 05525 05526 float *ref_freq_bin = new float[3*hist_len]; 05527 05528 //initialize value in each bin to zero 05529 for (int i = 0;i < (3*hist_len);i++) ref_freq_bin[i] = 0.f; 05530 05531 for (int i = 0;i < size_ref;i++) { 05532 int L = static_cast<int>(((ref_ptr[i] - ref_h_min)/ref_h_diff) * (hist_len-1) + hist_len+1); 05533 ref_freq_bin[L]++; 05534 } 05535 for (int i = 0;i < (3*hist_len);i++) ref_freq_bin[i] *= static_cast<float>(cnt)/static_cast<float>(size_ref); 05536 05537 //Parameters Calculation (i.e) 'A' x + 'B' 05538 float A = ref_h_sig/img_sig; 05539 float B = ref_h_avg - (A*img_avg); 05540 05541 vector<float> args; 05542 args.push_back(A); 05543 args.push_back(B); 05544 05545 vector<float> scale; 05546 scale.push_back(1.e-7f*A); 05547 scale.push_back(-1.e-7f*B); 05548 05549 vector<float> ref_freq_hist; 05550 for(int i = 0;i < (3*hist_len);i++) ref_freq_hist.push_back((int)ref_freq_bin[i]); 05551 05552 vector<float> data; 05553 data.push_back(ref_h_diff); 05554 data.push_back(ref_h_min); 05555 05556 Dict parameter; 05557 05558 /* Parameters displaying the arguments A & B, and the scaling function and the data's */ 05559 parameter["args"] = args; 05560 parameter["scale"]= scale; 05561 parameter["data"] = data; 05562 parameter["ref_freq_bin"] = ref_freq_hist; 05563 parameter["size_img"]=size_img; 05564 parameter["hist_len"]=hist_len; 05565 /* ===================================================== */ 05566 05567 return parameter; 05568 }
vector< float > Util::histogram | ( | EMData * | image, | |
EMData * | mask, | |||
int | nbins = 128 , |
|||
float | hmin = 0.0f , |
|||
float | hmax = 0.0f | |||
) | [static] |
Definition at line 5421 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.
05422 { 05423 if (image->is_complex()) 05424 throw ImageFormatException("Cannot do histogram on Fourier image"); 05425 //float hmax, hmin; 05426 float *imageptr=0, *maskptr=0; 05427 int nx=image->get_xsize(); 05428 int ny=image->get_ysize(); 05429 int nz=image->get_zsize(); 05430 05431 if(mask != NULL){ 05432 if(nx != mask->get_xsize() || ny != mask->get_ysize() || nz != mask->get_zsize()) 05433 throw ImageDimensionException("The size of mask image should be of same size as the input image"); 05434 maskptr =mask->get_data(); 05435 } 05436 if( nbins == 0) nbins = nx; 05437 vector <float> freq(2*nbins, 0.0); 05438 05439 imageptr=image->get_data(); 05440 if( hmin == hmax ) { 05441 if(mask == NULL) { 05442 hmax = image->get_attr("maximum"); 05443 hmin = image->get_attr("minimum"); 05444 } else { 05445 bool First = true; 05446 for (int i = 0;i < nx*ny*nz; i++) { 05447 if (maskptr[i]>=0.5f) { 05448 if(First) { 05449 hmax = imageptr[i]; 05450 hmin = imageptr[i]; 05451 First = false; 05452 } else { 05453 hmax = (hmax < imageptr[i])?imageptr[i]:hmax; 05454 hmin = (hmin > imageptr[i])?imageptr[i]:hmin; 05455 } 05456 } 05457 } 05458 } 05459 } 05460 float hdiff = hmax - hmin; 05461 float ff = (nbins-1)/hdiff; 05462 for (int i = 0; i < nbins; i++) freq[nbins+i] = hmin + (float(i)+0.5f)/ff; 05463 if(mask == NULL) { 05464 for(int i = 0; i < nx*ny*nz; i++) { 05465 int jbin = static_cast<int>((imageptr[i]-hmin)*ff + 1.5); 05466 if(jbin >= 1 && jbin <= nbins) freq[jbin-1] += 1.0; 05467 } 05468 } else { 05469 for(int i = 0; i < nx*ny*nz; i++) { 05470 if(maskptr[i] >= 0.5) { 05471 int jbin = static_cast<int>((imageptr[i]-hmin)*ff + 1.5); 05472 if(jbin >= 1 && jbin <= nbins) freq[jbin-1] += 1.0; 05473 } 05474 } 05475 } 05476 return freq; 05477 }
void Util::hsortd | ( | double * | theta, | |
double * | phi, | |||
int * | key, | |||
int | len, | |||
int | option | |||
) | [static] |
Definition at line 7056 of file util_sparx.cpp.
References cmp1(), cmp2(), ENTERFUNC, EXITFUNC, key, phi, and theta.
07057 { 07058 ENTERFUNC; 07059 vector<tmpstruct> tmp(len); 07060 int i; 07061 for(i = 1;i<=len;i++) 07062 { 07063 tmp[i-1].theta1 = theta(i); 07064 tmp[i-1].phi1 = phi(i); 07065 tmp[i-1].key1 = key(i); 07066 } 07067 07068 if (option == 1) sort(tmp.begin(),tmp.end(),Util::cmp1); 07069 if (option == 2) sort(tmp.begin(),tmp.end(),Util::cmp2); 07070 07071 for(i = 1;i<=len;i++) 07072 { 07073 theta(i) = tmp[i-1].theta1; 07074 phi(i) = tmp[i-1].phi1; 07075 key(i) = tmp[i-1].key1; 07076 } 07077 EXITFUNC; 07078 }
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 1626 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::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 1604 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::WienerFourierReconstructor::insert_slice(), EMAN::GaussFFTProjector::interp_ft_3d(), 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>4095 || y>4095) return (float)hypot((float)x,(float)y); // We won't cache anything bigger than 4096^2 00722 dim=dim==0?128:dim*2; 00723 mem=(float*)realloc(mem,4*dim*dim); 00724 for (int y=0; y<dim; y++) { 00725 for (int x=0; x<dim; x++) { 00726 #ifdef _WIN32 00727 mem[x+y*dim]=(float)_hypot((float)x,(float)y); 00728 #else 00729 mem[x+y*dim]=hypot((float)x,(float)y); 00730 #endif 00731 } 00732 } 00733 } 00734 00735 return mem[x+y*dim]; 00736 }
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 738 of file util.cpp.
Referenced by EMAN::PhaseCmp::cmp().
00739 { 00740 static short *mem = (short *)malloc(2*128*128); 00741 static int dim = 0; 00742 x=abs(x); 00743 y=abs(y); 00744 00745 if (x>=dim || y>=dim) { 00746 if (x>4095 || y>4095) return (short)hypot((float)x,(float)y); // We won't cache anything bigger than 4096^2 00747 dim=dim==0?128:dim*2; 00748 mem=(short*)realloc(mem,2*dim*dim); 00749 for (int y=0; y<dim; y++) { 00750 for (int x=0; x<dim; x++) { 00751 #ifdef _WIN32 00752 mem[x+y*dim]=(short)Util::round(_hypot((float)x,(float)y)); 00753 #else 00754 mem[x+y*dim]=(short)Util::round(hypot((float)x,(float)y)); 00755 #endif 00756 } 00757 } 00758 } 00759 00760 return mem[x+y*dim]; 00761 }
Definition at line 144 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().
00145 { 00146 ENTERFUNC; 00147 00148 if (!EMUtil::is_same_size(V1, V2)) { 00149 LOGERR("images not same size"); 00150 throw ImageFormatException( "images not same size"); 00151 } 00152 00153 size_t nx = V1->get_xsize(); 00154 size_t ny = V1->get_ysize(); 00155 size_t nz = V1->get_zsize(); 00156 size_t size = nx*ny*nz; 00157 00158 EMData *BD = new EMData(); 00159 BD->set_size(nx, ny, nz); 00160 00161 float *params = new float[2]; 00162 00163 float *V1ptr, *V2ptr, *MASKptr, *BDptr, A, B; 00164 long double S1=0.L,S2=0.L,S3=0.L,S4=0.L; 00165 int nvox = 0L; 00166 00167 V1ptr = V1->get_data(); 00168 V2ptr = V2->get_data(); 00169 BDptr = BD->get_data(); 00170 00171 00172 if(!mask){ 00173 EMData * Mask = new EMData(); 00174 Mask->set_size(nx,ny,nz); 00175 Mask->to_one(); 00176 MASKptr = Mask->get_data(); 00177 } else { 00178 if (!EMUtil::is_same_size(V1, mask)) { 00179 LOGERR("mask not same size"); 00180 throw ImageFormatException( "mask not same size"); 00181 } 00182 00183 MASKptr = mask->get_data(); 00184 } 00185 00186 00187 00188 // calculation of S1,S2,S3,S3,nvox 00189 00190 for (size_t i = 0L;i < size; i++) { 00191 if (MASKptr[i]>0.5f) { 00192 S1 += V1ptr[i]*V2ptr[i]; 00193 S2 += V1ptr[i]*V1ptr[i]; 00194 S3 += V2ptr[i]; 00195 S4 += V1ptr[i]; 00196 nvox ++; 00197 } 00198 } 00199 00200 if ((nvox*S1 - S3*S4) == 0. || (nvox*S2 - S4*S4) == 0) { 00201 A =1.0f ; 00202 } else { 00203 A = static_cast<float>( (nvox*S1 - S3*S4)/(nvox*S2 - S4*S4) ); 00204 } 00205 B = static_cast<float> (A*S4 - S3)/nvox; 00206 00207 // calculation of the difference image 00208 00209 for (size_t i = 0L;i < size; i++) { 00210 if (MASKptr[i]>0.5f) { 00211 BDptr[i] = A*V1ptr[i] - B - V2ptr[i]; 00212 } else { 00213 BDptr[i] = 0.f; 00214 } 00215 } 00216 00217 BD->update(); 00218 00219 params[0] = A; 00220 params[1] = B; 00221 00222 Dict BDnParams; 00223 BDnParams["imdiff"] = BD; 00224 BDnParams["A"] = params[0]; 00225 BDnParams["B"] = params[1]; 00226 00227 EXITFUNC; 00228 return BDnParams; 00229 }
void Util::image_mutation | ( | EMData * | img, | |
float | mutation_rate | |||
) | [static] |
Definition at line 19597 of file util_sparx.cpp.
References array_mutation(), EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), max, min, and nx.
19597 { 19598 int nx = img->get_xsize(); 19599 float min = img->get_attr("minimum"); 19600 float max = img->get_attr("maximum"); 19601 float* img_data = img->get_data(); 19602 array_mutation(img_data, nx*nx, mutation_rate, min, max, 8, 0); 19603 return; 19604 }
Definition at line 62 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().
00063 : find statistics under the mask (mask >0.5) 00064 // flip false: find statistics ourside the mask (mask <0.5) 00065 { 00066 ENTERFUNC; 00067 vector<float> stats; 00068 float *Volptr, *maskptr,MAX,MIN; 00069 long double Sum1,Sum2; 00070 long count; 00071 00072 MAX = -FLT_MAX; 00073 MIN = FLT_MAX; 00074 count = 0L; 00075 Sum1 = 0.0L; 00076 Sum2 = 0.0L; 00077 00078 if (mask == NULL) { 00079 //Vol->update_stat(); 00080 stats.push_back(Vol->get_attr("mean")); 00081 stats.push_back(Vol->get_attr("sigma")); 00082 stats.push_back(Vol->get_attr("minimum")); 00083 stats.push_back(Vol->get_attr("maximum")); 00084 return stats; 00085 } 00086 00087 /* Check if the sizes of the mask and image are same */ 00088 00089 size_t nx = Vol->get_xsize(); 00090 size_t ny = Vol->get_ysize(); 00091 size_t nz = Vol->get_zsize(); 00092 00093 size_t mask_nx = mask->get_xsize(); 00094 size_t mask_ny = mask->get_ysize(); 00095 size_t mask_nz = mask->get_zsize(); 00096 00097 if (nx != mask_nx || ny != mask_ny || nz != mask_nz ) 00098 throw ImageDimensionException("The dimension of the image does not match the dimension of the mask!"); 00099 00100 /* if (nx != mask_nx || 00101 ny != mask_ny || 00102 nz != mask_nz ) { 00103 // should throw an exception here!!! (will clean it up later CY) 00104 fprintf(stderr, "The dimension of the image does not match the dimension of the mask!\n"); 00105 fprintf(stderr, " nx = %d, mask_nx = %d\n", nx, mask_nx); 00106 fprintf(stderr, " ny = %d, mask_ny = %d\n", ny, mask_ny); 00107 fprintf(stderr, " nz = %d, mask_nz = %d\n", nz, mask_nz); 00108 exit(1); 00109 } 00110 */ 00111 Volptr = Vol->get_data(); 00112 maskptr = mask->get_data(); 00113 00114 for (size_t i = 0; i < nx*ny*nz; i++) { 00115 if (maskptr[i]>0.5f == flip) { 00116 Sum1 += Volptr[i]; 00117 Sum2 += Volptr[i]*Volptr[i]; 00118 MAX = (MAX < Volptr[i])?Volptr[i]:MAX; 00119 MIN = (MIN > Volptr[i])?Volptr[i]:MIN; 00120 count++; 00121 } 00122 } 00123 00124 if (count == 0) { 00125 LOGERR("Invalid mask"); 00126 throw ImageFormatException( "Invalid mask"); 00127 } 00128 00129 float avg = static_cast<float>(Sum1/count); 00130 float sig2 = static_cast<float>(Sum2 - count*avg*avg)/(count-1); 00131 float sig = sqrt(sig2); 00132 00133 stats.push_back(avg); 00134 stats.push_back(sig); 00135 stats.push_back(MIN); 00136 stats.push_back(MAX); 00137 00138 return stats; 00139 }
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 20129 of file util_sparx.cpp.
References b, explore(), and k_means_cont_table_().
20129 { 20130 //cout<<"initial_prune\n"; 20131 // simple initial pruning. For class indClass of partition indPart: 20132 // 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 20133 // If for some partition (not equal to indPart) for which there is no such class, then return 0 immediately. 20134 20135 // 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 20136 20137 // remember when calling k_means_cont_table, the first element of each class is an index, and actual number of elements in the class 20138 // (as stored in dimClasses) should be decremented by 1 accordingly, and second is dummy variable 20139 20140 int* dummy; 20141 int* cref; 20142 int cref_size; 20143 int* ccomp; 20144 int ccomp_size; 20145 int nintx; 20146 for (int i=0; i < nParts; i++){ 20147 for (int j =0; j < K; j++){ 20148 20149 // consider class Parts[i][j] 20150 cref = Parts[i][j];//incr by 1 since first element is index and second is dummy 20151 cref_size = (*(dimClasses+i*K+(*cref)))-2; 20152 20153 20154 if (cref_size <= T){ 20155 20156 *cref = -1; 20157 continue; 20158 } 20159 bool done = 0; 20160 for (int a = 0; a < nParts; a++){ 20161 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 20162 bool hasActive=0; 20163 for (int b=0; b < Parts[a].size(); b++){ 20164 // get the card of the intx between Parts[i][j] and Parts[a][b] using k_means_cont_table 20165 // remember first element of each class is the index of the class 20166 ccomp = Parts[a][b]; 20167 ccomp_size= (*(dimClasses+a*K+(*ccomp)))-2; 20168 nintx = Util::k_means_cont_table_(cref+2,ccomp+2, dummy, cref_size, ccomp_size,0); 20169 20170 20171 if (nintx <= T) 20172 *(ccomp+1) = 0; // class Parts[a][b] is 'inactive' for cref 20173 else{ 20174 *(ccomp+1)=1; // class Parts[a][b] is 'active' for cref 20175 hasActive=1; 20176 } 20177 } 20178 // see if partition a has at least one active class.if not then we're done with cref 20179 if (hasActive < 1){ 20180 done=1; 20181 break; 20182 } 20183 20184 } 20185 20186 if (done > 0){ 20187 // remove class j from partition i 20188 20189 *cref = -1; // mark for deletion later 20190 continue; // move on to class Parts[i][j+1] 20191 } 20192 20193 // now we adopt more aggressive measures. we find the match with the largest weight which has class Parts[i][j] for partition i. 20194 // 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. 20195 20196 // (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. 20197 // Note that if there are ALOT of partitions, then sorting the partititions may actually take longer than the time saved by ordering hte 20198 // partitions. However, we do not have a lot of partitions, (usually around 10), so sorting time will be trivial compared to exploring time. 20199 20200 // explore returns one if there is a feasible matching containing class cref which has weight gt T, and otherwise returns 0 20201 //bool found = 1; 20202 bool found = explore(Parts, dimClasses, nParts, K, T, i, cref+2, cref_size, cref, cref_size,0); 20203 20204 if (found<1){ // There is NO feasible matching with class j (cref) with weight greater than T, so delete this class from Parts 20205 // Parts[i].erase(Parts[i].begin()+j); 20206 *cref = -1; 20207 } 20208 } 20209 20210 // Erase from Parts[i] all the classes that's being designated for erasure 20211 20212 for (int d = K-1; d > -1; d--){ 20213 if (*(Parts[i][d]) < 0) Parts[i].erase(Parts[i].begin()+d); 20214 } 20215 20216 } 20217 20218 // Print out how many classes are left in each partition 20219 //for (int i =0; i < nParts; i++) 20220 // cout << Parts[i].size()<<", "; 20221 //cout << "\n"; 20222 }
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 2090 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 5108 of file util_sparx.cpp.
References max.
05108 { 05109 long int d2 = group2[s2 - 1] - group2[0]; 05110 long int p2 = 0; 05111 long int i1 = 0; 05112 long int i2 = 0; 05113 long int max = 0; 05114 long int cont = 0; 05115 long int i = 0; 05116 int stop1 = 0; 05117 int stop2 = 0; 05118 05119 for (i=0; i<s1; i++) { 05120 p2 = (long int)(s2 * (double)group1[i] / (double)d2); 05121 if (p2 >= s2) {p2 = s2 - 1;} 05122 i1 = p2; 05123 i2 = p2; 05124 max = s2; 05125 if (group1[i] < group2[0] || group1[i] > group2[s2 - 1]) {continue;} 05126 05127 stop1 = 0; 05128 stop2 = 0; 05129 while (max--) { 05130 if (group1[i] == group2[i1]) { 05131 if (flag) {stb[cont] = group1[i];} 05132 cont++; 05133 break; 05134 } 05135 if (group2[i1] < group1[i]) {stop1=1;} 05136 if (group1[i] == group2[i2]) { 05137 if (flag) {stb[cont] = group1[i];} 05138 cont++; 05139 break; 05140 } 05141 if (group2[i2] > group1[i]) {stop2=1;} 05142 //printf("i1 %li i2 %li v2 %i v2 %i stop1 %i stop2 %i\n", i1, i2, group2[i1], group2[i2], stop1, stop2); 05143 05144 if (stop1 & stop2) {break;} 05145 i1--; 05146 i2++; 05147 if (i1 < 0) {i1 = 0;} 05148 if (i2 >= s2) {i2 = s2 - 1;} 05149 } 05150 //printf("v1: %i ite: %li cont: %li\n", group1[i], s2-max, cont); 05151 } 05152 05153 return cont; 05154 }
static float EMAN::Util::linear_interpolate | ( | float | p1, | |
float | p2, | |||
float | t | |||
) | [inline, static] |
Calculate linear interpolation.
[in] | p1 | The first number. corresponding to (x0,y0). |
[in] | p2 | The second number. corresponding to (x1,y0). |
[in] | t | the distance the separates the interpolated point from p1 |
Definition at line 1459 of file util.h.
Referenced by EMAN::EMData::cut_slice(), 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 19660 of file util_sparx.cpp.
19660 { 19661 19662 if (is_mirror != 0) { 19663 for (vector<float>::iterator q=list.begin(); q!=list.end(); q++) { 19664 int r = rand()%10000; 19665 float f = r/10000.0f; 19666 if (f < mutation_rate) *q = 1-*q; 19667 } 19668 } else { 19669 map<int, vector<int> > graycode; 19670 map<vector<int>, int> rev_graycode; 19671 vector <int> gray; 19672 19673 int K=1; 19674 for (int i=0; i<L; i++) K*=2; 19675 19676 for (int k=0; k<K; k++) { 19677 int shift = 0; 19678 vector <int> gray; 19679 for (int i=L-1; i>-1; i--) { 19680 int t = ((k>>i)%2-shift)%2; 19681 gray.push_back(t); 19682 shift += t-2; 19683 } 19684 graycode[k] = gray; 19685 rev_graycode[gray] = k; 19686 } 19687 19688 float gap = (K-1)/(max_val-min_val); 19689 for (vector<float>::iterator q=list.begin(); q!=list.end(); q++) { 19690 float val = *q; 19691 if (val < min_val) { val = min_val; } 19692 else if (val > max_val) { val = max_val; } 19693 int k = int((val-min_val)*gap+0.5); 19694 vector<int> gray = graycode[k]; 19695 bool changed = false; 19696 for (vector<int>::iterator p=gray.begin(); p!=gray.end(); p++) { 19697 int r = rand()%10000; 19698 float f = r/10000.0f; 19699 if (f < mutation_rate) { 19700 *p = 1-*p; 19701 changed = true; 19702 } 19703 } 19704 if (changed) { 19705 k = rev_graycode[gray]; 19706 *q = k/gap+min_val; 19707 } 19708 } 19709 } 19710 return list; 19711 }
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 6263 of file util_sparx.cpp.
References cl1().
06264 { 06265 /* System generated locals */ 06266 long int q_dim1, q_offset, q1_dim1, q1_offset, i__1, i__2; 06267 06268 /* Local variables */ 06269 long int i__, j, m, n1, ii, jj; 06270 double tmp; 06271 vector<float> p; 06272 --x; 06273 q_dim1 = *klm2d; 06274 q_offset = 1 + q_dim1; 06275 q -= q_offset; 06276 q1_dim1 = *klm2d; 06277 q1_offset = 1 + q1_dim1; 06278 q1 -= q1_offset; 06279 --s; 06280 --res; 06281 iu -= 3; 06282 cu -= 3; 06283 06284 /* Function Body */ 06285 long int l = 0; 06286 06287 /* C==ZHONG HUANG,JULY,12,02;L=0,1,2,3,4,5,6 correspond to different equality constraints */ 06288 m = *ks; 06289 n1 = *n + 1; 06290 if (*iswi == 1) { 06291 i__1 = n1; 06292 for (jj = 1; jj <= i__1; ++jj) { 06293 i__2 = *ks; 06294 for (ii = 1; ii <= i__2; ++ii) { 06295 /* q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];*/ 06296 06297 q[*ks + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1] 06298 ; 06299 } 06300 } 06301 } else if (*iswi == 2) { 06302 i__1 = *ks; 06303 for (ii = 1; ii <= i__1; ++ii) { 06304 i__2 = n1; 06305 for (jj = 1; jj <= i__2; ++jj) { 06306 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06307 q[*ks + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06308 } 06309 } 06310 } else if (*iswi == 3) { 06311 l = 2; 06312 i__1 = n1; 06313 for (jj = 1; jj <= i__1; ++jj) { 06314 i__2 = *ks + 2; 06315 for (ii = 1; ii <= i__2; ++ii) { 06316 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06317 } 06318 i__2 = *ks; 06319 for (ii = 1; ii <= i__2; ++ii) { 06320 q[*ks + 2 + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06321 } 06322 } 06323 } else if (*iswi == 4) { 06324 l = 2; 06325 i__1 = n1; 06326 for (jj = 1; jj <= i__1; ++jj) { 06327 i__2 = *ks + 2; 06328 for (ii = 1; ii <= i__2; ++ii) { 06329 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06330 } 06331 i__2 = *ks; 06332 for (ii = 1; ii <= i__2; ++ii) { 06333 q[*ks + 2 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06334 } 06335 } 06336 } else if (*iswi == 5) { 06337 l = 1; 06338 i__1 = n1; 06339 for (jj = 1; jj <= i__1; ++jj) { 06340 i__2 = *ks + 1; 06341 for (ii = 1; ii <= i__2; ++ii) { 06342 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06343 } 06344 i__2 = *ks; 06345 for (ii = 1; ii <= i__2; ++ii) { 06346 q[*ks + 1 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06347 } 06348 } 06349 } else if (*iswi == 6) { 06350 l = 1; 06351 i__1 = n1; 06352 for (jj = 1; jj <= i__1; ++jj) { 06353 i__2 = *ks + 1; 06354 for (ii = 1; ii <= i__2; ++ii) { 06355 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06356 } 06357 i__2 = *ks; 06358 for (ii = 1; ii <= i__2; ++ii) { 06359 q[*ks + 1 + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06360 } 06361 } 06362 } else if (*iswi == 7) { 06363 l = 3; 06364 i__1 = n1; 06365 for (jj = 1; jj <= i__1; ++jj) { 06366 i__2 = *ks + 3; 06367 for (ii = 1; ii <= i__2; ++ii) { 06368 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06369 } 06370 i__2 = *ks; 06371 for (ii = 1; ii <= i__2; ++ii) { 06372 q[*ks + 3 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06373 } 06374 } 06375 } else if (*iswi == 8) { 06376 l = 4; 06377 i__1 = n1; 06378 for (jj = 1; jj <= i__1; ++jj) { 06379 i__2 = *ks + 4; 06380 for (ii = 1; ii <= i__2; ++ii) { 06381 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06382 } 06383 i__2 = *ks; 06384 for (ii = 1; ii <= i__2; ++ii) { 06385 q[*ks + 4 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06386 } 06387 } 06388 } 06389 06390 Util::cl1(ks, &l, &m, n, klm2d, &q[q_offset], &x[1], &res[1], &cu[3], &iu[3], &s[1]); 06391 i__1 = *ks; 06392 int tmp__j=0; 06393 for (i__ = 1; i__ <= i__1; ++i__) { 06394 tmp = 0.f; 06395 i__2 = *n - 1; 06396 for (j = 1; j <= i__2; ++j) { 06397 tmp__j=j; 06398 tmp += pow(q1[i__ + q1_dim1], tmp__j) * x[j]; 06399 } 06400 tmp += x[*n]; 06401 p.push_back(static_cast<float>(exp(tmp))); 06402 p.push_back(q1[i__ + q1_dim1]); 06403 } 06404 i__2=*n; 06405 for (i__=1;i__<=i__2;++i__) 06406 { p.push_back(static_cast<float>(x[i__]));} 06407 return p; 06408 }
Definition at line 17399 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().
17400 { 17401 ENTERFUNC; 17402 /* Exception Handle */ 17403 if (!img) { 17404 throw NullPointerException("NULL input image"); 17405 } 17406 /* ============== img += scalar*img1 ================ */ 17407 17408 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17409 int size = nx*ny*nz; 17410 float *img_ptr =img->get_data(); 17411 float *img1_ptr = img1->get_data(); 17412 for (int i=0;i<size;i++)img_ptr[i] += img1_ptr[i]*scalar; 17413 img1->update(); 17414 17415 EXITFUNC; 17416 }
Definition at line 17209 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().
17210 { 17211 ENTERFUNC; 17212 /* Exception Handle */ 17213 if (!img) { 17214 throw NullPointerException("NULL input image"); 17215 } 17216 /* ============== output = img + scalar*img1 ================ */ 17217 17218 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17219 int size = nx*ny*nz; 17220 EMData * img2 = img->copy_head(); 17221 float *img_ptr =img->get_data(); 17222 float *img2_ptr = img2->get_data(); 17223 float *img1_ptr = img1->get_data(); 17224 for (int i=0;i<size;i++) img2_ptr[i] = img_ptr[i] + img1_ptr[i]*scalar; 17225 img2->update(); 17226 if(img->is_complex()) { 17227 img2->set_complex(true); 17228 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17229 } 17230 17231 EXITFUNC; 17232 return img2; 17233 }
vector< float > Util::merge_peaks | ( | vector< float > | peak1, | |
vector< float > | peak2, | |||
float | p_size | |||
) | [static] |
Definition at line 6045 of file util_sparx.cpp.
06046 { 06047 vector<float>new_peak; 06048 int n1=peak1.size()/3; 06049 float p_size2=p_size*p_size; 06050 for (int i=0;i<n1;++i) { 06051 vector<float>::iterator it2= peak1.begin()+3*i; 06052 bool push_back1=true; 06053 int n2=peak2.size()/3; 06054 /*cout<<"peak2 size==="<<n2<<"i====="<<i<<endl; 06055 cout<<"new peak size==="<<new_peak.size()/3<<endl;*/ 06056 if(n2 ==0) { 06057 new_peak.push_back(*it2); 06058 new_peak.push_back(*(it2+1)); 06059 new_peak.push_back(*(it2+2)); 06060 } else { 06061 int j=0; 06062 while (j< n2-1 ) { 06063 vector<float>::iterator it3= peak2.begin()+3*j; 06064 float d2=((*(it2+1))-(*(it3+1)))*((*(it2+1))-(*(it3+1)))+((*(it2+2))-(*(it3+2)))*((*(it2+2))-(*(it3+2))); 06065 if(d2< p_size2 ) { 06066 if( (*it2)<(*it3) ) { 06067 new_peak.push_back(*it3); 06068 new_peak.push_back(*(it3+1)); 06069 new_peak.push_back(*(it3+2)); 06070 peak2.erase(it3); 06071 peak2.erase(it3); 06072 peak2.erase(it3); 06073 push_back1=false; 06074 } else { 06075 peak2.erase(it3); 06076 peak2.erase(it3); 06077 peak2.erase(it3); 06078 } 06079 } else j=j+1; 06080 n2=peak2.size()/3; 06081 } 06082 if(push_back1) { 06083 new_peak.push_back(*it2); 06084 new_peak.push_back(*(it2+1)); 06085 new_peak.push_back(*(it2+2)); 06086 } 06087 } 06088 } 06089 return new_peak; 06090 }
helper function for k-means
Definition at line 5033 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), nx, and ny.
05033 { 05034 ENTERFUNC; 05035 05036 int nima = data.size(); 05037 vector<float> res(nima); 05038 double result = 0.; 05039 double valmin = 1.0e20; 05040 int valpos = -1; 05041 05042 for (int kk=0; kk<nima; kk++){ 05043 result = 0; 05044 //validate_input_args(image, data[kk]); 05045 05046 float *y_data = data[kk]->get_data(); 05047 float *x_data = image->get_data(); 05048 05049 // Implemented by PAP 01/09/06 - please do not change. If in doubts, write/call me. 05050 int nx = data[kk]->get_xsize(); 05051 int ny = data[kk]->get_ysize(); 05052 nx = (nx - 2 + data[kk]->is_fftodd()); // nx is the real-space size of the input image 05053 int lsd2 = (nx + 2 - nx%2) ; // Extended x-dimension of the complex image 05054 05055 int ixb = 2*((nx+1)%2); 05056 int iyb = ny%2; 05057 int iz = 0; 05058 05059 for ( int iy = 0; iy <= ny-1; iy++) { 05060 for ( int ix = 2; ix <= lsd2 - 1 - ixb; ix++) { 05061 int ii = ix + (iy + iz * ny)* lsd2; 05062 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05063 } 05064 } 05065 for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) { 05066 int ii = (iy + iz * ny)* lsd2; 05067 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05068 result += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]); 05069 } 05070 if(nx%2 == 0) { 05071 for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) { 05072 int ii = lsd2 - 2 + (iy + iz * ny)* lsd2; 05073 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05074 result += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]); 05075 } 05076 05077 } 05078 result *= 2; 05079 result += (x_data[0] - y_data[0])*double(x_data[0] - y_data[0]); 05080 if(ny%2 == 0) { 05081 int ii = (ny/2 + iz * ny)* lsd2; 05082 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05083 } 05084 if(nx%2 == 0) { 05085 int ii = lsd2 - 2 + (0 + iz * ny)* lsd2; 05086 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05087 if(ny%2 == 0) { 05088 int ii = lsd2 - 2 +(ny/2 + iz * ny)* lsd2; 05089 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05090 } 05091 } 05092 05093 result /= (long int)nx*(long int)ny*(long int)nx*(long int)ny; 05094 res[kk] = (float)result; 05095 05096 if(result<valmin) {valmin = result; valpos = kk;} 05097 05098 } 05099 05100 Dict retvals; 05101 retvals["dist"] = res; 05102 retvals["pos"] = valpos; 05103 05104 EXITFUNC; 05105 return retvals; 05106 }
k-means helper
Definition at line 4998 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), and EMAN::EMData::get_ysize().
04998 { 04999 ENTERFUNC; 05000 05001 int nima = data.size(); 05002 vector<float> res(nima); 05003 double result = 0.; 05004 double valmin = 1.0e20; 05005 int valpos = -1; 05006 05007 for (int kk=0; kk<nima; kk++){ 05008 result = 0; 05009 05010 float *y_data = data[kk]->get_data(); 05011 float *x_data = image->get_data(); 05012 long totsize = image->get_xsize()*image->get_ysize(); 05013 for (long i = 0; i < totsize; i++) { 05014 double temp = x_data[i]- y_data[i]; 05015 result += temp*temp; 05016 } 05017 result /= totsize; 05018 res[kk] = (float)result; 05019 05020 if(result<valmin) {valmin = result; valpos = kk;} 05021 05022 } 05023 05024 Dict retvals; 05025 retvals["dist"] = res; 05026 retvals["pos"] = valpos; 05027 05028 EXITFUNC; 05029 return retvals; 05030 05031 }
static int EMAN::Util::mono | ( | int | k1, | |
int | k2 | |||
) | [inline, static] |
Definition at line 18836 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().
18837 { 18838 ENTERFUNC; 18839 /* Exception Handle */ 18840 if (!img) { 18841 throw NullPointerException("NULL input image"); 18842 } 18843 18844 int newx, newy, newz; 18845 bool keep_going; 18846 cout << " entered " <<endl; 18847 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 18848 //int size = nx*ny*nz; 18849 EMData * img2 = new EMData(); 18850 img2->set_size(nx,ny,nz); 18851 img2->to_zero(); 18852 float *img_ptr =img->get_data(); 18853 float *img2_ptr = img2->get_data(); 18854 int r2 = ro*ro; 18855 int r3 = r2*ro; 18856 int ri2 = ri*ri; 18857 int ri3 = ri2*ri; 18858 18859 int n2 = nx/2; 18860 18861 for (int k=-n2; k<=n2; k++) { //cout << " k "<<k <<endl; 18862 float z2 = static_cast<float>(k*k); 18863 for (int j=-n2; j<=n2; j++) { 18864 float y2 = z2 + j*j; 18865 if(y2 <= r2) { 18866 //cout << " j "<<j <<endl; 18867 18868 for (int i=-n2; i<=n2; i++) { 18869 float x2 = y2 + i*i; 18870 if(x2 <= r3) { 18871 //cout << " i "<<i <<endl; 18872 int ib = i+n2; int jb = j+n2; int kb = k+n2; 18873 if(x2 >= ri3) { 18874 // this is the outer shell, here points can only vanish 18875 if(img_ptr(ib,jb,kb) == 1.0f) { 18876 //cout << " 1 "<<ib <<endl; 18877 if(Util::get_frand(0.0f, 1.0f) > qprob){ 18878 img2_ptr(ib,jb,kb) = 0.0f; 18879 keep_going = true; 18880 //cout << " try "<<ib <<endl; 18881 while(keep_going) { 18882 newx = Util::get_irand(-ro,ro); 18883 newy = Util::get_irand(-ro,ro); 18884 newz = Util::get_irand(-ro,ro); 18885 if(newx*newx+newy*newy+newz*newz <= r3) { 18886 newx += n2; newy += n2; newz += n2; 18887 if( img_ptr(newx,newy,newz) == 0.0f) { 18888 img2_ptr(newx,newy,newz) = 1.0f; 18889 keep_going = false; } 18890 } 18891 } 18892 } else img2_ptr(ib,jb,kb) = 1.0f; 18893 } 18894 } else { 18895 // this is inner shell, the point can only move (or vanish, if all neighbors exist) 18896 if(img_ptr(ib,jb,kb) == 1.0) { 18897 if(Util::get_frand(0.0f,1.0f) > qprob) { 18898 // find out the number of neighbors 18899 float numn = -1.0f; // we already know the central one is 1 18900 for (newz = -1; newz <= 1; newz++) 18901 for (newy = -1; newy <= 1; newy++) 18902 for (newx = -1; newx <= 1; newx++) 18903 numn += img_ptr(ib+newx,jb+newy,kb+newz); 18904 img2_ptr(ib,jb,kb) = 0.0; 18905 if(numn == 26.0f) { 18906 // all neighbors exist, it has to vanish 18907 keep_going = true; 18908 while(keep_going) { 18909 newx = Util::get_irand(-ro,ro); 18910 newy = Util::get_irand(-ro,ro); 18911 newz = Util::get_irand(-ro,ro); 18912 if(newx*newx+newy*newy+newz*newz < r3) { 18913 newx += n2; newy += n2; newz += n2; 18914 if( img_ptr(newx,newy,newz) == 0.0f) { 18915 if(newx*newx+newy*newy+newz*newz < r3) { 18916 if(newx*newx+newy*newy+newz*newz < r3) { 18917 newx += n2; newy += n2; newz += n2; 18918 if( img_ptr(newx,newy,newz) == 0.0f) { 18919 img2_ptr(newx,newy,newz) = 1.0f; 18920 keep_going = false; } 18921 } 18922 } 18923 } 18924 } 18925 } 18926 } else if(numn == 25.0f) { 18927 // there is only one empty neighbor, move there 18928 for (newz = -1; newz <= 1; newz++) { 18929 for (newy = -1; newy <= 1; newy++) { 18930 for (newx = -1; newx <= 1; newx++) { 18931 if( newx != 0 && newy != 0 && newz != 0) { 18932 if(img_ptr(newx+ib,newy+jb,newz+kb) == 0.0f) { 18933 img2_ptr(newx+ib,newy+jb,newz+kb) = 1.0f; 18934 } 18935 } 18936 } 18937 } 18938 } 18939 } else { 18940 // more than one neighbor is zero, select randomly one and move there 18941 keep_going = true; 18942 while(keep_going) { 18943 newx = Util::get_irand(-1,1); 18944 newy = Util::get_irand(-1,1); 18945 newz = Util::get_irand(-1,1); 18946 if(newx != 0 && newy != 0 && newz != 0) { 18947 if(img_ptr(ib+newx,jb+newy,kb+newz) == 0.0f) { 18948 img2_ptr(ib+newx,jb+newy,kb+newz) = 1.0f;//????? 18949 keep_going = false; 18950 } 18951 } 18952 } 18953 } 18954 } else img2_ptr(ib,jb,kb) = 1.0f; 18955 } 18956 } 18957 } 18958 } 18959 } 18960 } 18961 } 18962 //for (int i=0;i<size;i++) img2_ptr[i] = img_ptr[i] + Util::get_irand(1,7); 18963 img2->update(); 18964 18965 EXITFUNC; 18966 return img2; 18967 }
Definition at line 17498 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().
17499 { 17500 ENTERFUNC; 17501 /* Exception Handle */ 17502 if (!img) { 17503 throw NullPointerException("NULL input image"); 17504 } 17505 /* ========= img *= img1 ===================== */ 17506 17507 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17508 int size = nx*ny*nz; 17509 float *img_ptr = img->get_data(); 17510 float *img1_ptr = img1->get_data(); 17511 if(img->is_complex()) { 17512 for (int i=0; i<size; i+=2) { 17513 float tmp = img_ptr[i] * img1_ptr[i] - img_ptr[i+1] * img1_ptr[i+1] ; 17514 img_ptr[i+1] = img_ptr[i] * img1_ptr[i+1] + img_ptr[i+1] * img1_ptr[i] ; 17515 img_ptr[i] = tmp; 17516 17517 } 17518 } else { 17519 for (int i=0;i<size;i++) img_ptr[i] *= img1_ptr[i]; 17520 } 17521 img->update(); 17522 17523 EXITFUNC; 17524 }
void Util::mul_scalar | ( | EMData * | img, | |
float | scalar | |||
) | [static] |
Definition at line 17381 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().
17382 { 17383 ENTERFUNC; 17384 /* Exception Handle */ 17385 if (!img) { 17386 throw NullPointerException("NULL input image"); 17387 } 17388 /* ============ output = scalar*input ================== */ 17389 17390 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17391 int size = nx*ny*nz; 17392 float *img_ptr =img->get_data(); 17393 for (int i=0;i<size;i++) img_ptr[i] *= scalar; 17394 img->update(); 17395 17396 EXITFUNC; 17397 }
Definition at line 17287 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().
17288 { 17289 ENTERFUNC; 17290 /* Exception Handle */ 17291 if (!img) { 17292 throw NullPointerException("NULL input image"); 17293 } 17294 /* ============== output = img * img1 ================ */ 17295 17296 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17297 int size = nx*ny*nz; 17298 EMData * img2 = img->copy_head(); 17299 float *img_ptr =img->get_data(); 17300 float *img2_ptr = img2->get_data(); 17301 float *img1_ptr = img1->get_data(); 17302 if(img->is_complex()) { 17303 for (int i=0; i<size; i+=2) { 17304 img2_ptr[i] = img_ptr[i] * img1_ptr[i] - img_ptr[i+1] * img1_ptr[i+1] ; 17305 img2_ptr[i+1] = img_ptr[i] * img1_ptr[i+1] + img_ptr[i+1] * img1_ptr[i] ; 17306 } 17307 img2->set_complex(true); 17308 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17309 } else { 17310 for (int i=0; i<size; i++) img2_ptr[i] = img_ptr[i] * img1_ptr[i]; 17311 img2->update(); 17312 } 17313 17314 EXITFUNC; 17315 return img2; 17316 }
Definition at line 17184 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().
17185 { 17186 ENTERFUNC; 17187 /* Exception Handle */ 17188 if (!img) { 17189 throw NullPointerException("NULL input image"); 17190 } 17191 /* ============ output = scalar*input ================== */ 17192 17193 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17194 int size = nx*ny*nz; 17195 EMData * img2 = img->copy_head(); 17196 float *img_ptr =img->get_data(); 17197 float *img2_ptr = img2->get_data(); 17198 for (int i=0;i<size;i++)img2_ptr[i] = img_ptr[i]*scalar; 17199 img2->update(); 17200 17201 if(img->is_complex()) { 17202 img2->set_complex(true); 17203 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17204 } 17205 EXITFUNC; 17206 return img2; 17207 }
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 18163 of file util_sparx.cpp.
References Crosrng_msg_vec(), Frngs(), EMAN::EMData::get_data(), Polar2Dm(), and EMAN::EMData::set_size().
18166 { 18167 18168 int maxrin = numr[numr.size()-1]; 18169 18170 int ky = int(2*yrng/step+0.5)/2; 18171 int kx = int(2*xrng/step+0.5)/2; 18172 18173 peaks->set_size(maxrin, 2*kx+3, 2*ky+3); 18174 float *p_ccf1ds = peaks->get_data(); 18175 18176 peakm->set_size(maxrin, 2*kx+3, 2*ky+3); 18177 float *p_ccf1dm = peakm->get_data(); 18178 18179 for ( int i = 0; i<maxrin*(2*kx+3)*(2*ky+3); i++) { 18180 p_ccf1ds[i] = -1.e20f; 18181 p_ccf1dm[i] = -1.e20f; 18182 } 18183 18184 for (int i = -ky; i <= ky; i++) { 18185 float iy = i * step; 18186 for (int j = -kx; j <= kx; j++) { 18187 float ix = j*step; 18188 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18189 Frngs(cimage, numr); 18190 Crosrng_msg_vec(crefim, cimage, numr, 18191 p_ccf1ds+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin, 18192 p_ccf1dm+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin); 18193 delete cimage; cimage = 0; 18194 } 18195 } 18196 return; 18197 }
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 18199 of file util_sparx.cpp.
References Crosrng_msg_vec(), Frngs(), EMAN::EMData::get_data(), Polar2Dm(), and EMAN::EMData::set_size().
18201 { 18202 18203 int maxrin = numr[numr.size()-1]; 18204 18205 int ky = int(2*yrng/step+0.5)/2; 18206 int kx = int(2*xrng/step+0.5)/2; 18207 18208 peaks->set_size(maxrin, 2*kx+3, 2*ky+3); 18209 float *p_ccf1ds = peaks->get_data(); 18210 18211 peakm->set_size(maxrin, 2*kx+3, 2*ky+3); 18212 float *p_ccf1dm = peakm->get_data(); 18213 18214 peaks_compress->set_size(maxrin, 1, 1); 18215 float *p_ccf1ds_compress = peaks_compress->get_data(); 18216 18217 peakm_compress->set_size(maxrin, 1, 1); 18218 float *p_ccf1dm_compress = peakm_compress->get_data(); 18219 18220 for ( int i = 0; i<maxrin*(2*kx+3)*(2*ky+3); i++) { 18221 p_ccf1ds[i] = -1.e20f; 18222 p_ccf1dm[i] = -1.e20f; 18223 } 18224 18225 for (int i = -ky; i <= ky; i++) { 18226 float iy = i * step; 18227 for (int j = -kx; j <= kx; j++) { 18228 float ix = j*step; 18229 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18230 Frngs(cimage, numr); 18231 Crosrng_msg_vec(crefim, cimage, numr, 18232 p_ccf1ds+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin, 18233 p_ccf1dm+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin); 18234 delete cimage; cimage = 0; 18235 } 18236 } 18237 for (int x=0; x<maxrin; x++) { 18238 float maxs = -1.0e22f; 18239 float maxm = -1.0e22f; 18240 for (int i=1; i<=2*ky+1; i++) { 18241 for (int j=1; j<=2*kx+1; j++) { 18242 if (p_ccf1ds[(i*(2*kx+3)+j)*maxrin+x] > maxs) maxs = p_ccf1ds[(i*(2*kx+3)+j)*maxrin+x]; 18243 if (p_ccf1dm[(i*(2*kx+3)+j)*maxrin+x] > maxm) maxm = p_ccf1dm[(i*(2*kx+3)+j)*maxrin+x]; 18244 } 18245 } 18246 p_ccf1ds_compress[x] = maxs; 18247 p_ccf1dm_compress[x] = maxm; 18248 } 18249 return; 18250 }
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 17707 of file util_sparx.cpp.
References ang_n(), Crosrng_ms(), Frngs(), Normalize_ring(), pi, and Polar2Dm().
17709 { 17710 17711 // Manually extract. 17712 /* vector< EMAN::EMData* > crefim; 17713 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 17714 crefim.reserve(crefim_len); 17715 17716 for(std::size_t i=0;i<crefim_len;i++) { 17717 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 17718 crefim.push_back(proxy()); 17719 } 17720 */ 17721 17722 size_t crefim_len = crefim.size(); 17723 17724 int ky = int(2*yrng/step+0.5)/2; 17725 int kx = int(2*xrng/step+0.5)/2; 17726 int iref, nref=0, mirror=0; 17727 float iy, ix, sx=0, sy=0; 17728 float peak = -1.0E23f; 17729 float ang=0.0f; 17730 for (int i = -ky; i <= ky; i++) { 17731 iy = i * step ; 17732 for (int j = -kx; j <= kx; j++) { 17733 ix = j*step ; 17734 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 17735 17736 Normalize_ring( cimage, numr ); 17737 17738 Frngs(cimage, numr); 17739 // compare with all reference images 17740 // for iref in xrange(len(crefim)): 17741 for ( iref = 0; iref < (int)crefim_len; iref++) { 17742 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr); 17743 double qn = retvals["qn"]; 17744 double qm = retvals["qm"]; 17745 if(qn >= peak || qm >= peak) { 17746 sx = -ix; 17747 sy = -iy; 17748 nref = iref; 17749 if (qn >= qm) { 17750 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 17751 peak = static_cast<float>(qn); 17752 mirror = 0; 17753 } else { 17754 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 17755 peak = static_cast<float>(qm); 17756 mirror = 1; 17757 } 17758 } 17759 } delete cimage; cimage = 0; 17760 } 17761 } 17762 float co, so, sxs, sys; 17763 co = static_cast<float>( cos(ang*pi/180.0) ); 17764 so = static_cast<float>( -sin(ang*pi/180.0) ); 17765 sxs = sx*co - sy*so; 17766 sys = sx*so + sy*co; 17767 vector<float> res; 17768 res.push_back(ang); 17769 res.push_back(sxs); 17770 res.push_back(sys); 17771 res.push_back(static_cast<float>(mirror)); 17772 res.push_back(static_cast<float>(nref)); 17773 res.push_back(peak); 17774 return res; 17775 }
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 17777 of file util_sparx.cpp.
References ang_n(), Crosrng_ms_delta(), Frngs(), Normalize_ring(), pi, and Polar2Dm().
17779 { 17780 17781 // Manually extract. 17782 /* vector< EMAN::EMData* > crefim; 17783 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 17784 crefim.reserve(crefim_len); 17785 17786 for(std::size_t i=0;i<crefim_len;i++) { 17787 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 17788 crefim.push_back(proxy()); 17789 } 17790 */ 17791 17792 size_t crefim_len = crefim.size(); 17793 17794 int ky = int(2*yrng/step+0.5)/2; 17795 int kx = int(2*xrng/step+0.5)/2; 17796 int iref, nref=0, mirror=0; 17797 float iy, ix, sx=0, sy=0; 17798 float peak = -1.0E23f; 17799 float ang=0.0f; 17800 for (int i = -ky; i <= ky; i++) { 17801 iy = i * step ; 17802 for (int j = -kx; j <= kx; j++) { 17803 ix = j*step ; 17804 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 17805 17806 Normalize_ring( cimage, numr ); 17807 17808 Frngs(cimage, numr); 17809 // compare with all reference images 17810 // for iref in xrange(len(crefim)): 17811 for ( iref = 0; iref < (int)crefim_len; iref++) { 17812 Dict retvals = Crosrng_ms_delta(crefim[iref], cimage, numr, delta_start, delta); 17813 double qn = retvals["qn"]; 17814 double qm = retvals["qm"]; 17815 if(qn >= peak || qm >= peak) { 17816 sx = -ix; 17817 sy = -iy; 17818 nref = iref; 17819 if (qn >= qm) { 17820 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 17821 peak = static_cast<float>(qn); 17822 mirror = 0; 17823 } else { 17824 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 17825 peak = static_cast<float>(qm); 17826 mirror = 1; 17827 } 17828 } 17829 } delete cimage; cimage = 0; 17830 } 17831 } 17832 float co, so, sxs, sys; 17833 co = static_cast<float>( cos(ang*pi/180.0) ); 17834 so = static_cast<float>( -sin(ang*pi/180.0) ); 17835 sxs = sx*co - sy*so; 17836 sys = sx*so + sy*co; 17837 vector<float> res; 17838 res.push_back(ang); 17839 res.push_back(sxs); 17840 res.push_back(sys); 17841 res.push_back(static_cast<float>(mirror)); 17842 res.push_back(static_cast<float>(nref)); 17843 res.push_back(peak); 17844 return res; 17845 }
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 17904 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.
17906 { 17907 17908 // Manually extract. 17909 /* vector< EMAN::EMData* > crefim; 17910 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 17911 crefim.reserve(crefim_len); 17912 17913 for(std::size_t i=0;i<crefim_len;i++) { 17914 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 17915 crefim.push_back(proxy()); 17916 } 17917 */ 17918 size_t crefim_len = crefim.size(); 17919 const float qv = static_cast<float>( pi/180.0 ); 17920 17921 Transform * t = image->get_attr("xform.projection"); 17922 Dict d = t->get_params("spider"); 17923 if(t) {delete t; t=0;} 17924 float phi = d["phi"]; 17925 float theta = d["theta"]; 17926 int ky = int(2*yrng/step+0.5)/2; 17927 int kx = int(2*xrng/step+0.5)/2; 17928 int iref, nref=0, mirror=0; 17929 float iy, ix, sx=0, sy=0; 17930 float peak = -1.0E23f; 17931 float ang=0.0f; 17932 float imn1 = sin(theta*qv)*cos(phi*qv); 17933 float imn2 = sin(theta*qv)*sin(phi*qv); 17934 float imn3 = cos(theta*qv); 17935 vector<float> n1(crefim_len); 17936 vector<float> n2(crefim_len); 17937 vector<float> n3(crefim_len); 17938 for ( iref = 0; iref < (int)crefim_len; iref++) { 17939 n1[iref] = crefim[iref]->get_attr("n1"); 17940 n2[iref] = crefim[iref]->get_attr("n2"); 17941 n3[iref] = crefim[iref]->get_attr("n3"); 17942 } 17943 for (int i = -ky; i <= ky; i++) { 17944 iy = i * step ; 17945 for (int j = -kx; j <= kx; j++) { 17946 ix = j*step; 17947 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 17948 17949 Normalize_ring( cimage, numr ); 17950 17951 Frngs(cimage, numr); 17952 // compare with all reference images 17953 // for iref in xrange(len(crefim)): 17954 for ( iref = 0; iref < (int)crefim_len; iref++) { 17955 if(abs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) { 17956 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr); 17957 double qn = retvals["qn"]; 17958 double qm = retvals["qm"]; 17959 if(qn >= peak || qm >= peak) { 17960 sx = -ix; 17961 sy = -iy; 17962 nref = iref; 17963 if (qn >= qm) { 17964 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 17965 peak = static_cast<float>( qn ); 17966 mirror = 0; 17967 } else { 17968 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 17969 peak = static_cast<float>( qm ); 17970 mirror = 1; 17971 } 17972 } 17973 } 17974 } delete cimage; cimage = 0; 17975 } 17976 } 17977 float co, so, sxs, sys; 17978 if(peak == -1.0E23) { 17979 ang=0.0; sxs=0.0; sys=0.0; mirror=0; 17980 nref = -1; 17981 } else { 17982 co = cos(ang*qv); 17983 so = -sin(ang*qv); 17984 sxs = sx*co - sy*so; 17985 sys = sx*so + sy*co; 17986 } 17987 vector<float> res; 17988 res.push_back(ang); 17989 res.push_back(sxs); 17990 res.push_back(sys); 17991 res.push_back(static_cast<float>(mirror)); 17992 res.push_back(static_cast<float>(nref)); 17993 res.push_back(peak); 17994 return res; 17995 }
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 17997 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.
17999 { 18000 18001 // Manually extract. 18002 /* vector< EMAN::EMData* > crefim; 18003 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 18004 crefim.reserve(crefim_len); 18005 18006 for(std::size_t i=0;i<crefim_len;i++) { 18007 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 18008 crefim.push_back(proxy()); 18009 } 18010 */ 18011 size_t crefim_len = crefim.size(); 18012 const float qv = static_cast<float>(pi/180.0); 18013 18014 Transform* t = image->get_attr("xform.projection"); 18015 Dict d = t->get_params("spider"); 18016 if(t) {delete t; t=0;} 18017 float phi = d["phi"]; 18018 float theta = d["theta"]; 18019 float psi = d["psi"]; 18020 int ky = int(2*yrng/step+0.5)/2; 18021 int kx = int(2*xrng/step+0.5)/2; 18022 int iref, nref = 0, mirror = 0; 18023 float iy, ix, sx = 0, sy = 0; 18024 float peak = -1.0E23f; 18025 float ang = 0.0f; 18026 float imn1 = sin(theta*qv)*cos(phi*qv); 18027 float imn2 = sin(theta*qv)*sin(phi*qv); 18028 float imn3 = cos(theta*qv); 18029 vector<float> n1(crefim_len); 18030 vector<float> n2(crefim_len); 18031 vector<float> n3(crefim_len); 18032 for (iref = 0; iref < (int)crefim_len; iref++) { 18033 n1[iref] = crefim[iref]->get_attr("n1"); 18034 n2[iref] = crefim[iref]->get_attr("n2"); 18035 n3[iref] = crefim[iref]->get_attr("n3"); 18036 } 18037 bool nomirror = (theta<90.0) || (theta==90.0) && (psi<psi_max); 18038 if (!nomirror) { 18039 phi = fmod(phi+540.0f, 360.0f); 18040 theta = 180-theta; 18041 psi = fmod(540.0f-psi, 360.0f); 18042 } 18043 for (int i = -ky; i <= ky; i++) { 18044 iy = i * step ; 18045 for (int j = -kx; j <= kx; j++) { 18046 ix = j*step; 18047 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18048 18049 Normalize_ring(cimage, numr); 18050 18051 Frngs(cimage, numr); 18052 // compare with all reference images 18053 // for iref in xrange(len(crefim)): 18054 for (iref = 0; iref < (int)crefim_len; iref++) { 18055 if (abs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) { 18056 if (nomirror) { 18057 Dict retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, psi, 0); 18058 double qn = retvals["qn"]; 18059 if (qn >= peak) { 18060 sx = -ix; 18061 sy = -iy; 18062 nref = iref; 18063 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18064 peak = static_cast<float>(qn); 18065 mirror = 0; 18066 } 18067 } else { 18068 Dict retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, psi, 1); 18069 double qn = retvals["qn"]; 18070 if (qn >= peak) { 18071 sx = -ix; 18072 sy = -iy; 18073 nref = iref; 18074 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18075 peak = static_cast<float>(qn); 18076 mirror = 1; 18077 } 18078 } 18079 } 18080 } delete cimage; cimage = 0; 18081 } 18082 } 18083 float co, so, sxs, sys; 18084 if(peak == -1.0E23) { 18085 ang=0.0; sxs=0.0; sys=0.0; mirror=0; 18086 nref = -1; 18087 } else { 18088 co = cos(ang*qv); 18089 so = -sin(ang*qv); 18090 sxs = sx*co - sy*so; 18091 sys = sx*so + sy*co; 18092 } 18093 vector<float> res; 18094 res.push_back(ang); 18095 res.push_back(sxs); 18096 res.push_back(sys); 18097 res.push_back(static_cast<float>(mirror)); 18098 res.push_back(static_cast<float>(nref)); 18099 res.push_back(peak); 18100 return res; 18101 }
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 17847 of file util_sparx.cpp.
References ang_n(), Crosrng_ns(), Frngs(), pi, and Polar2Dm().
17849 { 17850 17851 // Manually extract. 17852 /* vector< EMAN::EMData* > crefim; 17853 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 17854 crefim.reserve(crefim_len); 17855 17856 for(std::size_t i=0;i<crefim_len;i++) { 17857 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 17858 crefim.push_back(proxy()); 17859 } 17860 */ 17861 size_t crefim_len = crefim.size(); 17862 17863 int ky = int(2*yrng/step+0.5)/2; 17864 int kx = int(2*xrng/step+0.5)/2; 17865 int iref, nref=0; 17866 float iy, ix, sx=0, sy=0; 17867 float peak = -1.0E23f; 17868 float ang=0.0f; 17869 for (int i = -ky; i <= ky; i++) { 17870 iy = i * step ; 17871 for (int j = -kx; j <= kx; j++) { 17872 ix = j*step ; 17873 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 17874 Frngs(cimage, numr); 17875 // compare with all reference images 17876 // for iref in xrange(len(crefim)): 17877 for ( iref = 0; iref < (int)crefim_len; iref++) { 17878 Dict retvals = Crosrng_ns(crefim[iref], cimage, numr); 17879 double qn = retvals["qn"]; 17880 if(qn >= peak) { 17881 sx = -ix; 17882 sy = -iy; 17883 nref = iref; 17884 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 17885 peak = static_cast<float>(qn); 17886 } 17887 } delete cimage; cimage = 0; 17888 } 17889 } 17890 float co, so, sxs, sys; 17891 co = static_cast<float>( cos(ang*pi/180.0) ); 17892 so = static_cast<float>( -sin(ang*pi/180.0) ); 17893 sxs = sx*co - sy*so; 17894 sys = sx*so + sy*co; 17895 vector<float> res; 17896 res.push_back(ang); 17897 res.push_back(sxs); 17898 res.push_back(sys); 17899 res.push_back(static_cast<float>(nref)); 17900 res.push_back(peak); 17901 return res; 17902 }
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 | |||
) | [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 18104 of file util_sparx.cpp.
References ang_n(), Crosrng_psi_0_180(), Frngs(), Normalize_ring(), pi, and Polar2Dm().
18106 { 18107 18108 size_t crefim_len = crefim.size(); 18109 18110 int ky = int(2*yrng/step+0.5)/2; 18111 int kx = int(2*xrng/step+0.5)/2; 18112 int iref, nref=0, mirror=0; 18113 float iy, ix, sx=0, sy=0; 18114 float peak = -1.0E23f; 18115 float ang=0.0f; 18116 for (int i = -ky; i <= ky; i++) { 18117 iy = i * step ; 18118 for (int j = -kx; j <= kx; j++) { 18119 ix = j*step ; 18120 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18121 18122 Normalize_ring( cimage, numr ); 18123 18124 Frngs(cimage, numr); 18125 // compare with all reference images 18126 // for iref in xrange(len(crefim)): 18127 for ( iref = 0; iref < (int)crefim_len; iref++) { 18128 Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max); 18129 double qn = retvals["qn"]; 18130 double qm = retvals["qm"]; 18131 if(qn >= peak || qm >= peak) { 18132 sx = -ix; 18133 sy = -iy; 18134 nref = iref; 18135 if (qn >= qm) { 18136 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18137 peak = static_cast<float>(qn); 18138 mirror = 0; 18139 } else { 18140 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 18141 peak = static_cast<float>(qm); 18142 mirror = 1; 18143 } 18144 } 18145 } delete cimage; cimage = 0; 18146 } 18147 } 18148 float co, so, sxs, sys; 18149 co = static_cast<float>( cos(ang*pi/180.0) ); 18150 so = static_cast<float>( -sin(ang*pi/180.0) ); 18151 sxs = sx*co - sy*so; 18152 sys = sx*so + sy*co; 18153 vector<float> res; 18154 res.push_back(ang); 18155 res.push_back(sxs); 18156 res.push_back(sys); 18157 res.push_back(static_cast<float>(mirror)); 18158 res.push_back(static_cast<float>(nref)); 18159 res.push_back(peak); 18160 return res; 18161 }
static int EMAN::Util::nint180 | ( | float | arg | ) | [inline, static] |
void Util::Normalize_ring | ( | EMData * | ring, | |
const vector< int > & | numr | |||
) | [static] |
Definition at line 17674 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(), and multiref_polar_ali_helical().
17675 { 17676 float* data = ring->get_data(); 17677 float av=0.0; 17678 float sq=0.0; 17679 float nn=0.0; 17680 int nring = numr.size()/3; 17681 for( int i=0; i < nring; ++i ) 17682 { 17683 int numr3i = numr[3*i+2]; 17684 int numr2i = numr[3*i+1]-1; 17685 float w = numr[3*i]*2*M_PI/float(numr[3*i+2]); 17686 for( int j=0; j < numr3i; ++j ) 17687 { 17688 int jc = numr2i+j; 17689 av += data[jc] * w; 17690 sq += data[jc] * data[jc] * w; 17691 nn += w; 17692 } 17693 } 17694 17695 float avg = av/nn; 17696 float sgm = sqrt( (sq-av*av/nn)/nn ); 17697 int n = ring->get_xsize() * ring->get_ysize() * ring->get_zsize(); 17698 for( int i=0; i < n; ++i ) 17699 { 17700 data[i] -= avg; 17701 data[i] /= sgm; 17702 } 17703 17704 ring->update(); 17705 }
Definition at line 17584 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().
17585 { 17586 ENTERFUNC; 17587 /* Exception Handle */ 17588 if (!img) { 17589 throw NullPointerException("NULL input image"); 17590 } 17591 /* ============== img is modulus of a complex image in FFT format (so its imaginary parts are zero), 17592 output is img packed into real image with Friedel part added, ================ */ 17593 17594 int nxo=img->get_xsize(), ny=img->get_ysize(), nz=img->get_zsize(); 17595 int nx = nxo - 2 + img->is_fftodd(); 17596 int lsd2 = (nx + 2 - nx%2) / 2; // Extended x-dimension of the complex image 17597 int nyt, nzt; 17598 int nx2 = nx/2; 17599 int ny2 = ny/2; if(ny2 == 0) nyt =0; else nyt=ny; 17600 int nz2 = nz/2; if(nz2 == 0) nzt =0; else nzt=nz; 17601 int nx2p = nx2+nx%2; 17602 int ny2p = ny2+ny%2; 17603 int nz2p = nz2+nz%2; 17604 EMData& power = *(new EMData()); // output image 17605 power.set_size(nx, ny, nz); 17606 power.set_array_offsets(-nx2,-ny2,-nz2); 17607 //img->set_array_offsets(1,1,1); 17608 float *img_ptr = img->get_data(); 17609 for (int iz = 1; iz <= nz; iz++) { 17610 int jz=iz-1; 17611 if(jz>=nz2p) jz=jz-nzt; 17612 for (int iy = 1; iy <= ny; iy++) { 17613 int jy=iy-1; 17614 if(jy>=ny2p) jy=jy-nyt; 17615 for (int ix = 1; ix <= lsd2; ix++) { 17616 int jx=ix-1; 17617 if(jx>=nx2p) jx=jx-nx; 17618 power(jx,jy,jz) = img_ptr(ix,iy,iz); //real(img->cmplx(ix,iy,iz)); 17619 } 17620 } 17621 } 17622 // Create the Friedel related half 17623 int nzb, nze, nyb, nye, nxb, nxe; 17624 nxb =-nx2+(nx+1)%2; 17625 nxe = nx2-(nx+1)%2; 17626 if(ny2 == 0) {nyb =0; nye = 0;} else {nyb =-ny2+(ny+1)%2; nye = ny2-(ny+1)%2;} 17627 if(nz2 == 0) {nzb =0; nze = 0;} else {nzb =-nz2+(nz+1)%2; nze = nz2-(nz+1)%2;} 17628 for (int iz = nzb; iz <= nze; iz++) { 17629 for (int iy = nyb; iy <= nye; iy++) { 17630 for (int ix = 1; ix <= nxe; ix++) { // Note this loop begins with 1 - FFT should create correct Friedel related 0 plane 17631 power(-ix,-iy,-iz) = power(ix,iy,iz); 17632 } 17633 } 17634 } 17635 if(ny2 != 0) { 17636 if(nz2 != 0) { 17637 if(nz%2 == 0) { //if nz even, fix the first slice 17638 for (int iy = nyb; iy <= nye; iy++) { 17639 for (int ix = nxb; ix <= -1; ix++) { 17640 power(ix,iy,-nz2) = power(-ix,-iy,-nz2); 17641 } 17642 } 17643 if(ny%2 == 0) { //if ny even, fix the first line 17644 for (int ix = nxb; ix <= -1; ix++) { 17645 power(ix,-ny2,-nz2) = power(-ix,-ny2,-nz2); 17646 } 17647 } 17648 } 17649 } 17650 if(ny%2 == 0) { //if ny even, fix the first column 17651 for (int iz = nzb; iz <= nze; iz++) { 17652 for (int ix = nxb; ix <= -1; ix++) { 17653 power(ix,-ny2,-iz) = power(-ix,-ny2,iz); 17654 } 17655 } 17656 } 17657 17658 } 17659 power.update(); 17660 power.set_array_offsets(0,0,0); 17661 return &power; 17662 }
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 , |
|||
char * | params = "average" | |||
) | [static] |
Definition at line 5265 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().
05266 { 05267 /* Exception Handle */ 05268 if (!img) throw NullPointerException("NULL input image"); 05269 /* ============================== */ 05270 05271 // Get the size of the input image 05272 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 05273 /* ============================== */ 05274 05275 /* Exception Handle */ 05276 if(new_nx<nx || new_ny<ny || new_nz<nz) 05277 throw ImageDimensionException("The size of the padded image cannot be lower than the input image size."); 05278 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) 05279 throw ImageDimensionException("The offset imconsistent with the input image size. Solution: Change the offset parameters"); 05280 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)))) 05281 throw ImageDimensionException("The offset imconsistent with the input image size. Solution: Change the offset parameters"); 05282 /* ============================== */ 05283 05284 EMData* pading = img->copy_head(); 05285 pading->set_size(new_nx, new_ny, new_nz); 05286 float *inp = img->get_data(); 05287 float *outp = pading->get_data(); 05288 05289 05290 /* Calculation of the average and the circumference values for background substitution 05291 =======================================================================================*/ 05292 float background; 05293 05294 if (strcmp(params,"average")==0) background = img->get_attr("mean"); 05295 else if (strcmp(params,"circumference")==0) { 05296 float sum1=0.0f; 05297 int cnt=0; 05298 for(int i=0;i<nx;i++) { 05299 sum1 += inp(i,0,0) + inp(i,ny-1,nz-1); 05300 cnt+=2; 05301 } 05302 if(nz-1 == 0) { 05303 for (int j=1;j<ny-1;j++) { 05304 sum1 += inp(1,j,0) + inp(nx-1,j,0); 05305 cnt+=2; 05306 } 05307 } else { 05308 for (int k=1;k<nz-1;k++) { 05309 for (int j=1;j<ny-1;j++) { 05310 sum1 += inp(1,j,0) + inp(nx-1,j,0); 05311 cnt+=2; 05312 } 05313 } 05314 } 05315 background = sum1/cnt; 05316 } else { 05317 background = static_cast<float>( atof( params ) ); 05318 } 05319 /*=====================================================================================*/ 05320 05321 /*Initial Padding */ 05322 int new_st_x=0,new_st_y=0,new_st_z=0; 05323 for (int k=0;k<new_nz;k++) 05324 for(int j=0;j<new_ny;j++) 05325 for (int i=0;i<new_nx;i++) 05326 outp(i,j,k)=background; 05327 /*============================== */ 05328 05329 /* Calculation of the start point */ 05330 new_st_x=int((new_nx/2-nx/2) + x_offset); 05331 new_st_y=int((new_ny/2-ny/2) + y_offset); 05332 new_st_z=int((new_nz/2-nz/2) + z_offset); 05333 /* ============================== */ 05334 05335 for (int k=0;k<nz;k++) 05336 for(int j=0;j<ny;j++) 05337 for(int i=0;i<nx;i++) 05338 outp(i,j,k)=inp(i,j,k); 05339 pading->update(); 05340 return pading; 05341 }
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 1266 of file util.cpp.
References point_is_in_triangle_2d().
01267 { 01268 01269 if (point_is_in_triangle_2d(p1,p2,p4,actual_point)) return true; 01270 else return point_is_in_triangle_2d(p3,p2,p4,actual_point); 01271 }
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 1231 of file util.cpp.
References EMAN::Vec2< Type >::dot(), EMAN::Transform::ERR_LIMIT, t, and v.
Referenced by point_is_in_convex_polygon_2d().
01232 { 01233 01234 Vec2f u = p2 - p1; 01235 Vec2f v = p3 - p1; 01236 Vec2f w = point - p1; 01237 01238 float udotu = u.dot(u); 01239 float udotv = u.dot(v); 01240 float udotw = u.dot(w); 01241 float vdotv = v.dot(v); 01242 float vdotw = v.dot(w); 01243 01244 float d = 1.0f/(udotv*udotv - udotu*vdotv); 01245 float s = udotv*vdotw - vdotv*udotw; 01246 s *= d; 01247 01248 float t = udotv*udotw - udotu*vdotw; 01249 t *= d; 01250 01251 // We've done a few multiplications, so detect when there are tiny residuals that may throw off the final 01252 // decision 01253 if (fabs(s) < Transform::ERR_LIMIT ) s = 0; 01254 if (fabs(t) < Transform::ERR_LIMIT ) t = 0; 01255 01256 if ( fabs((fabs(s)-1.0)) < Transform::ERR_LIMIT ) s = 1; 01257 if ( fabs((fabs(t)-1.0)) < Transform::ERR_LIMIT ) t = 1; 01258 01259 // cout << "s and t are " << s << " " << t << endl; 01260 01261 // The final decision, if this is true then we've hit the jackpot 01262 if ( s >= 0 && t >= 0 && (s+t) <= 1 ) return true; 01263 else return false; 01264 }
Definition at line 2137 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.
02137 { 02138 int nsam = image->get_xsize(); 02139 int nrow = image->get_ysize(); 02140 int nring = numr.size()/3; 02141 int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 02142 EMData* out = new EMData(); 02143 out->set_size(lcirc,1,1); 02144 char mode = (cmode == "F" || cmode == "f") ? 'f' : 'h'; 02145 float *xim = image->get_data(); 02146 float *circ = out->get_data(); 02147 /* alrq(image->get_data(), nsam, nrow, &numr[0], out->get_data(), lcirc, nring, cmode); 02148 return out; 02149 } 02150 void Util::alrq(float *xim, int nsam , int nrow , int *numr, 02151 float *circ, int lcirc, int nring, char mode) 02152 {*/ 02153 /* 02154 c 02155 c purpose: 02156 c 02157 c resmaple to polar coordinates 02158 c 02159 */ 02160 // dimension xim(nsam,nrow),circ(lcirc) 02161 // integer numr(3,nring) 02162 02163 double dfi, dpi; 02164 int ns2, nr2, i, inr, l, nsim, kcirc, lt, j; 02165 float yq, xold, yold, fi, x, y; 02166 02167 ns2 = nsam/2+1; 02168 nr2 = nrow/2+1; 02169 dpi = 2.0*atan(1.0); 02170 02171 for (i=1;i<=nring;i++) { 02172 // radius of the ring 02173 inr = numr(1,i); 02174 yq = static_cast<float>(inr); 02175 l = numr(3,i); 02176 if (mode == 'h' || mode == 'H') lt = l/2; 02177 else lt = l/4; 02178 02179 nsim = lt-1; 02180 dfi = dpi/(nsim+1); 02181 kcirc = numr(2,i); 02182 xold = 0.0f; 02183 yold = static_cast<float>(inr); 02184 circ(kcirc) = quadri(xold+(float)ns2,yold+(float)nr2,nsam,nrow,xim); 02185 xold = static_cast<float>(inr); 02186 yold = 0.0f; 02187 circ(lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02188 02189 if (mode == 'f' || mode == 'F') { 02190 xold = 0.0f; 02191 yold = static_cast<float>(-inr); 02192 circ(lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02193 xold = static_cast<float>(-inr); 02194 yold = 0.0f; 02195 circ(lt+lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02196 } 02197 02198 for (j=1;j<=nsim;j++) { 02199 fi = static_cast<float>(dfi*j); 02200 x = sin(fi)*yq; 02201 y = cos(fi)*yq; 02202 xold = x; 02203 yold = y; 02204 circ(j+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02205 xold = y; 02206 yold = -x; 02207 circ(j+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02208 02209 if (mode == 'f' || mode == 'F') { 02210 xold = -x; 02211 yold = -y; 02212 circ(j+lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02213 xold = -y; 02214 yold = x; 02215 circ(j+lt+lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02216 } 02217 } 02218 } 02219 return out; 02220 }
EMData * Util::Polar2Dm | ( | EMData * | image, | |
float | cns2, | |||
float | cnr2, | |||
vector< int > | numr, | |||
string | cmode | |||
) | [static] |
Definition at line 2222 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(), and multiref_polar_ali_helical().
02222 { 02223 int nsam = image->get_xsize(); 02224 int nrow = image->get_ysize(); 02225 int nring = numr.size()/3; 02226 int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 02227 EMData* out = new EMData(); 02228 out->set_size(lcirc,1,1); 02229 char mode = (cmode == "F" || cmode == "f") ? 'f' : 'h'; 02230 float *xim = image->get_data(); 02231 float *circ = out->get_data(); 02232 double dpi, dfi; 02233 int it, jt, inr, l, nsim, kcirc, lt; 02234 float xold, yold, fi, x, y; 02235 02236 // cns2 and cnr2 are predefined centers 02237 // no need to set to zero, all elements are defined 02238 dpi = 2*atan(1.0); 02239 for (it=1; it<=nring; it++) { 02240 // radius of the ring 02241 inr = numr(1,it); 02242 02243 // "F" means a full circle interpolation 02244 // "H" means a half circle interpolation 02245 02246 l = numr(3,it); 02247 if ( mode == 'h' || mode == 'H' ) lt = l / 2; 02248 else lt = l / 4; 02249 02250 nsim = lt - 1; 02251 dfi = dpi / (nsim+1); 02252 kcirc = numr(2,it); 02253 xold = 0.0f+cns2; 02254 yold = inr+cnr2; 02255 02256 Assert( kcirc <= lcirc ); 02257 circ(kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on 90 degree 02258 02259 xold = inr+cns2; 02260 yold = 0.0f+cnr2; 02261 Assert( lt+kcirc <= lcirc ); 02262 circ(lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on 0 degree 02263 02264 if ( mode == 'f' || mode == 'F' ) { 02265 xold = 0.0f+cns2; 02266 yold = -inr+cnr2; 02267 Assert( lt+lt+kcirc <= lcirc ); 02268 circ(lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on 270 degree 02269 02270 xold = -inr+cns2; 02271 yold = 0.0f+cnr2; 02272 Assert(lt+lt+lt+kcirc <= lcirc ); 02273 circ(lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on 180 degree 02274 } 02275 02276 for (jt=1; jt<=nsim; jt++) { 02277 fi = static_cast<float>(dfi * jt); 02278 x = sin(fi) * inr; 02279 y = cos(fi) * inr; 02280 02281 xold = x+cns2; 02282 yold = y+cnr2; 02283 02284 Assert( jt+kcirc <= lcirc ); 02285 circ(jt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on the first quadrant 02286 02287 xold = y+cns2; 02288 yold = -x+cnr2; 02289 02290 Assert( jt+lt+kcirc <= lcirc ); 02291 circ(jt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on the fourth quadrant 02292 02293 if ( mode == 'f' || mode == 'F' ) { 02294 xold = -x+cns2; 02295 yold = -y+cnr2; 02296 02297 Assert( jt+lt+lt+kcirc <= lcirc ); 02298 circ(jt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on the third quadrant 02299 02300 xold = -y+cns2; 02301 yold = x+cnr2; 02302 02303 Assert( jt+lt+lt+lt+kcirc <= lcirc ); 02304 circ(jt+lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on the second quadrant 02305 } 02306 } // end for jt 02307 } //end for it 02308 return out; 02309 }
EMData * Util::Polar2Dmi | ( | EMData * | image, | |
float | cns2, | |||
float | cnr2, | |||
vector< int > | numr, | |||
string | cmode, | |||
Util::KaiserBessel & | kb | |||
) | [static] |
Definition at line 2505 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.
02505 { 02506 // input image is twice the size of the original image 02507 int nring = numr.size()/3; 02508 int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 02509 EMData* out = new EMData(); 02510 out->set_size(lcirc,1,1); 02511 char mode = (cmode == "F" || cmode == "f") ? 'f' : 'h'; 02512 float *circ = out->get_data(); 02513 float *fimage = image->get_data(); 02514 int nx = image->get_xsize(); 02515 int ny = image->get_ysize(); 02516 int nz = image->get_zsize(); 02517 double dpi, dfi; 02518 int it, jt, inr, l, nsim, kcirc, lt; 02519 float yq, xold, yold, fi, x, y; 02520 02521 // cns2 and cnr2 are predefined centers 02522 // no need to set to zero, all elements are defined 02523 02524 dpi = 2*atan(1.0); 02525 for (it=1;it<=nring;it++) { 02526 // radius of the ring 02527 inr = numr(1,it); 02528 yq = static_cast<float>(inr); 02529 02530 l = numr(3,it); 02531 if ( mode == 'h' || mode == 'H' ) lt = l / 2; 02532 else lt = l / 4; 02533 02534 nsim = lt - 1; 02535 dfi = dpi / (nsim+1); 02536 kcirc = numr(2,it); 02537 xold = 0.0f; 02538 yold = static_cast<float>(inr); 02539 circ(kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02540 // circ(kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02541 02542 xold = static_cast<float>(inr); 02543 yold = 0.0f; 02544 circ(lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02545 // circ(lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02546 02547 if ( mode == 'f' || mode == 'F' ) { 02548 xold = 0.0f; 02549 yold = static_cast<float>(-inr); 02550 circ(lt+lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02551 // circ(lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02552 02553 xold = static_cast<float>(-inr); 02554 yold = 0.0f; 02555 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); 02556 // circ(lt+lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02557 } 02558 02559 for (jt=1;jt<=nsim;jt++) { 02560 fi = static_cast<float>(dfi * jt); 02561 x = sin(fi) * yq; 02562 y = cos(fi) * yq; 02563 02564 xold = x; 02565 yold = y; 02566 circ(jt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02567 // circ(jt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02568 02569 xold = y; 02570 yold = -x; 02571 circ(jt+lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02572 // circ(jt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02573 02574 if ( mode == 'f' || mode == 'F' ) { 02575 xold = -x; 02576 yold = -y; 02577 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); 02578 // circ(jt+lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02579 02580 xold = -y; 02581 yold = x; 02582 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); 02583 // circ(jt+lt+lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02584 } 02585 } // end for jt 02586 } //end for it 02587 return out; 02588 }
void Util::prb1d | ( | double * | b, | |
int | npoint, | |||
float * | pos | |||
) | [static] |
Definition at line 3126 of file util_sparx.cpp.
References b.
Referenced by Crosrng_e(), Crosrng_ew(), Crosrng_ms(), Crosrng_ns(), Crosrng_psi_0_180(), and Crosrng_sm_psi().
03126 { 03127 double c2,c3; 03128 int nhalf; 03129 03130 nhalf = npoint/2 + 1; 03131 *pos = 0.0; 03132 03133 if (npoint == 7) { 03134 c2 = 49.*b(1) + 6.*b(2) - 21.*b(3) - 32.*b(4) - 27.*b(5) 03135 - 6.*b(6) + 31.*b(7); 03136 c3 = 5.*b(1) - 3.*b(3) - 4.*b(4) - 3.*b(5) + 5.*b(7); 03137 } 03138 else if (npoint == 5) { 03139 c2 = (74.*b(1) - 23.*b(2) - 60.*b(3) - 37.*b(4) 03140 + 46.*b(5) ) / (-70.); 03141 c3 = (2.*b(1) - b(2) - 2.*b(3) - b(4) + 2.*b(5) ) / 14.0; 03142 } 03143 else if (npoint == 3) { 03144 c2 = (5.*b(1) - 8.*b(2) + 3.*b(3) ) / (-2.0); 03145 c3 = (b(1) - 2.*b(2) + b(3) ) / 2.0; 03146 } 03147 //else if (npoint == 9) { 03148 else { // at least one has to be true!! 03149 c2 = (1708.*b(1) + 581.*b(2) - 246.*b(3) - 773.*b(4) 03150 - 1000.*b(5) - 927.*b(6) - 554.*b(7) + 119.*b(8) 03151 + 1092.*b(9) ) / (-4620.); 03152 c3 = (28.*b(1) + 7.*b(2) - 8.*b(3) - 17.*b(4) - 20.*b(5) 03153 - 17.*b(6) - 8.*b(7) + 7.*b(8) + 28.*b(9) ) / 924.0; 03154 } 03155 if (c3 != 0.0) *pos = static_cast<float>(c2/(2.0*c3) - nhalf); 03156 }
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 1115 of file util.cpp.
01115 { 01116 // Note: Don't need to check if 3-D because 3D is part of 01117 // the MIArray3D typedef. 01118 out << "Printing 3D Integer data: " << str << std::endl; 01119 const multi_array_types::size_type* sizes = mat.shape(); 01120 int nx = sizes[0], ny = sizes[1], nz = sizes[2]; 01121 const multi_array_types::index* indices = mat.index_bases(); 01122 int bx = indices[0], by = indices[1], bz = indices[2]; 01123 for (int iz = bz; iz < nz+bz; iz++) { 01124 cout << "(z = " << iz << " slice)" << endl; 01125 for (int ix = bx; ix < nx+bx; ix++) { 01126 for (int iy = by; iy < ny+by; iy++) { 01127 cout << setiosflags(ios::fixed) << setw(5) 01128 << mat[ix][iy][iz] << " "; 01129 } 01130 cout << endl; 01131 } 01132 } 01133 }
vector< float > Util::pw_extract | ( | vector< float > | pw, | |
int | n, | |||
int | iswi, | |||
float | ps | |||
) | [static] |
Definition at line 6167 of file util_sparx.cpp.
References call_cl1(), log(), and q.
06168 { 06169 int k,m,n1,klmd,klm2d,nklmd,n2d,n_larg,l, n2; 06170 06171 k=(int)pw.size(); 06172 l=0; 06173 m=k; 06174 n2=n+2; 06175 n1=n+1; 06176 klmd=k+l+m; 06177 klm2d= k+l+m+2; 06178 nklmd=k+l+m+n; 06179 n2d=n+2; 06180 /*size has to be increased when N is large*/ 06181 n_larg=klmd*2; 06182 klm2d=n_larg+klm2d; 06183 klmd=n_larg+klmd; 06184 nklmd=n_larg+nklmd; 06185 int size_q=klm2d*n2d; 06186 int size_cu=nklmd*2; 06187 static int i__; 06188 06189 double *q ; 06190 double *x ; 06191 double *res; 06192 double *cu; 06193 float *q2; 06194 float *pw_; 06195 long int *iu; 06196 double *s; 06197 q = (double*)calloc(size_q,sizeof(double)); 06198 x = (double*)calloc(n2d,sizeof(double)); 06199 res = (double*)calloc(klmd,sizeof(double)); 06200 cu =(double*)calloc(size_cu,sizeof(double)); 06201 s = (double*)calloc(klmd,sizeof(double)); 06202 q2 = (float*)calloc(size_q,sizeof(float)); 06203 iu = (long int*)calloc(size_cu,sizeof(long int)); 06204 pw_ = (float*)calloc(k,sizeof(float)); 06205 06206 for( i__ =0;i__<k;++i__) 06207 { 06208 pw_[i__]=log(pw[i__]); } 06209 long int l_k=k; 06210 long int l_n=n; 06211 long int l_iswi=iswi; 06212 vector<float> cl1_res; 06213 cl1_res=Util::call_cl1(&l_k, &l_n, &ps, &l_iswi, pw_, q2, q, x, res, cu, s, iu); 06214 free(q); 06215 free(x); 06216 free(res); 06217 free(s); 06218 free(cu); 06219 free(q2); 06220 free(iu); 06221 free(pw_); 06222 return cl1_res; 06223 }
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 646 of file util_sparx.cpp.
Referenced by alrl_ms(), Polar2D(), Polar2Dm(), quadri_background(), and EMAN::EMData::rot_scale_trans2D().
00647 { 00648 // purpose: quadratic interpolation 00649 // Optimized for speed, circular closer removed, checking of ranges removed 00650 float x, y, dx0, dy0, f0, c1, c2, c3, c4, c5, dxb, dyb; 00651 float quadri; 00652 int i, j, ip1, im1, jp1, jm1, ic, jc, hxc, hyc; 00653 00654 x = xx; 00655 y = yy; 00656 00657 // any xx and yy 00658 while ( x < 1.0 ) x += nxdata; 00659 while ( x >= (float)(nxdata+1) ) x -= nxdata; 00660 while ( y < 1.0 ) y += nydata; 00661 while ( y >= (float)(nydata+1) ) y -= nydata; 00662 00663 i = (int) x; 00664 j = (int) y; 00665 00666 dx0 = x - i; 00667 dy0 = y - j; 00668 00669 ip1 = i + 1; 00670 im1 = i - 1; 00671 jp1 = j + 1; 00672 jm1 = j - 1; 00673 00674 if (ip1 > nxdata) ip1 -= nxdata; 00675 if (im1 < 1) im1 += nxdata; 00676 if (jp1 > nydata) jp1 -= nydata; 00677 if (jm1 < 1) jm1 += nydata; 00678 00679 f0 = fdata(i,j); 00680 c1 = fdata(ip1,j) - f0; 00681 c2 = (c1 - f0 + fdata(im1,j)) * 0.5f; 00682 c3 = fdata(i,jp1) - f0; 00683 c4 = (c3 - f0 + fdata(i,jm1)) * 0.5f; 00684 00685 dxb = dx0 - 1; 00686 dyb = dy0 - 1; 00687 00688 // hxc & hyc are either 1 or -1 00689 if (dx0 >= 0) hxc = 1; else hxc = -1; 00690 if (dy0 >= 0) hyc = 1; else hyc = -1; 00691 00692 ic = i + hxc; 00693 jc = j + hyc; 00694 00695 if (ic > nxdata) ic -= nxdata; else if (ic < 1) ic += nxdata; 00696 if (jc > nydata) jc -= nydata; else if (jc < 1) jc += nydata; 00697 00698 c5 = ( (fdata(ic,jc) - f0 - hxc * c1 - (hxc * (hxc - 1.0f)) * c2 00699 - hyc * c3 - (hyc * (hyc - 1.0f)) * c4) * (hxc * hyc)); 00700 00701 00702 quadri = f0 + dx0 * (c1 + dxb * c2 + dy0 * c5) + dy0 * (c3 + dyb * c4); 00703 00704 return quadri; 00705 }
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 710 of file util_sparx.cpp.
References fdata, quadri(), x, and y.
Referenced by EMAN::EMData::rot_scale_trans2D_background().
00711 { 00712 // purpose: quadratic interpolation 00713 // Optimized for speed, circular closer removed, checking of ranges removed 00714 float x, y, dx0, dy0, f0, c1, c2, c3, c4, c5, dxb, dyb; 00715 float quadri; 00716 int i, j, ip1, im1, jp1, jm1, ic, jc, hxc, hyc; 00717 00718 x = xx; 00719 y = yy; 00720 00721 // wrap around is not done circulantly; if (x,y) is not in the image, then x = xnew and y = ynew 00722 if ( (x < 1.0) || ( x >= (float)(nxdata+1) ) || ( y < 1.0 ) || ( y >= (float)(nydata+1) )){ 00723 x = (float)xnew; 00724 y = (float)ynew; 00725 } 00726 00727 00728 i = (int) x; 00729 j = (int) y; 00730 00731 dx0 = x - i; 00732 dy0 = y - j; 00733 00734 ip1 = i + 1; 00735 im1 = i - 1; 00736 jp1 = j + 1; 00737 jm1 = j - 1; 00738 00739 if (ip1 > nxdata) ip1 -= nxdata; 00740 if (im1 < 1) im1 += nxdata; 00741 if (jp1 > nydata) jp1 -= nydata; 00742 if (jm1 < 1) jm1 += nydata; 00743 00744 f0 = fdata(i,j); 00745 c1 = fdata(ip1,j) - f0; 00746 c2 = (c1 - f0 + fdata(im1,j)) * 0.5f; 00747 c3 = fdata(i,jp1) - f0; 00748 c4 = (c3 - f0 + fdata(i,jm1)) * 0.5f; 00749 00750 dxb = dx0 - 1; 00751 dyb = dy0 - 1; 00752 00753 // hxc & hyc are either 1 or -1 00754 if (dx0 >= 0) hxc = 1; else hxc = -1; 00755 if (dy0 >= 0) hyc = 1; else hyc = -1; 00756 00757 ic = i + hxc; 00758 jc = j + hyc; 00759 00760 if (ic > nxdata) ic -= nxdata; else if (ic < 1) ic += nxdata; 00761 if (jc > nydata) jc -= nydata; else if (jc < 1) jc += nydata; 00762 00763 c5 = ( (fdata(ic,jc) - f0 - hxc * c1 - (hxc * (hxc - 1.0f)) * c2 00764 - hyc * c3 - (hyc * (hyc - 1.0f)) * c4) * (hxc * hyc)); 00765 00766 00767 quadri = f0 + dx0 * (c1 + dxb * c2 + dy0 * c5) + dy0 * (c3 + dyb * c4); 00768 00769 return quadri; 00770 }
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 434 of file util_sparx.cpp.
References sort_mat().
00436 { 00437 int iMax = (int) floor( (Size-1.0)/2 +.01); 00438 int CountMax = (iMax+2)*(iMax+1)/2; 00439 int Count=-1; 00440 float *kVals = new float[CountMax]; 00441 float *weightMat = new float[CountMax]; 00442 int *PermMat = new int[CountMax]; 00443 SizeReturned[0] = CountMax; 00444 00445 // printf("Aa \n"); fflush(stdout); 00446 for (int jkx=0; jkx< iMax+1; jkx++) { 00447 for (int jky=0; jky< jkx+1; jky++) { 00448 Count++; 00449 kVals[Count] = sqrtf((float) (jkx*jkx +jky*jky)); 00450 weightMat[Count]= 1.0; 00451 if (jkx!=0) { weightMat[Count] *=2;} 00452 if (jky!=0) { weightMat[Count] *=2;} 00453 if (jkx!=jky){ weightMat[Count] *=2;} 00454 PermMat[Count]=Count+1; 00455 } 00456 } 00457 00458 int lkVals = Count+1; 00459 // printf("Cc \n");fflush(stdout); 00460 00461 sort_mat(&kVals[0],&kVals[Count], 00462 &PermMat[0], &PermMat[Count]); //PermMat is 00463 //also returned as well as kValsSorted 00464 fflush(stdout); 00465 00466 int newInd; 00467 00468 for (int iP=0; iP < lkVals ; iP++ ) { 00469 newInd = PermMat[iP]; 00470 PermMatTr[newInd-1] = iP+1; 00471 } 00472 00473 // printf("Ee \n"); fflush(stdout); 00474 00475 int CountA=-1; 00476 int CountB=-1; 00477 00478 while (CountB< (CountMax-1)) { 00479 CountA++; 00480 CountB++; 00481 // printf("CountA=%d ; CountB=%d \n", CountA,CountB);fflush(stdout); 00482 kValsSorted[CountA] = kVals[CountB] ; 00483 if (CountB<(CountMax-1) ) { 00484 while (fabs(kVals[CountB] -kVals[CountB+1])<.0000001 ) { 00485 SizeReturned[0]--; 00486 for (int iP=0; iP < lkVals; iP++){ 00487 // printf("iP=%d \n", iP);fflush(stdout); 00488 if (PermMatTr[iP]>CountA+1) { 00489 PermMatTr[iP]--; 00490 } 00491 } 00492 CountB++; 00493 } 00494 } 00495 } 00496 00497 00498 for (int CountD=0; CountD < CountMax; CountD++) { 00499 newInd = PermMatTr[CountD]; 00500 weightofkValsSorted[newInd-1] += weightMat[CountD]; 00501 } 00502 00503 }
Recreates a n-d image using its compressed 1-D form and the mask.
Definition at line 5998 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().
05999 { 06000 /******** 06001 ***Exception Handle 06002 *************/ 06003 if(mask == NULL) 06004 throw ImageDimensionException("The mask cannot be an null image"); 06005 06006 /*********** 06007 ***get the size of the mask 06008 **************/ 06009 int nx = mask->get_xsize(),ny = mask->get_ysize(),nz = mask->get_zsize(); 06010 06011 int i,size = nx*ny*nz; /* loop counters */ 06012 /* new image declaration */ 06013 EMData *new_image = new EMData(); 06014 new_image->set_size(nx,ny,nz); /* set the size of new image */ 06015 float *new_ptr = new_image->get_data(); /* set size of the new image */ 06016 float *mask_ptr = mask->get_data(); /* assign a pointer to the mask image */ 06017 float *img_ptr = image->get_data(); /* assign a pointer to the 1D image */ 06018 int count = 0; 06019 float sum_under_mask = 0.0 ; 06020 for(i = 0;i < size;i++){ 06021 if(mask_ptr[i] > 0.5f){ 06022 new_ptr[i] = img_ptr[count]; 06023 sum_under_mask += img_ptr[count]; 06024 count++; 06025 if( count > image->get_xsize() ) { 06026 throw ImageDimensionException("Error: in reconstitute_image_mask, the mask doesn't match the image, it is too large"); 06027 } 06028 } 06029 } 06030 06031 if( count > image->get_xsize() ) { 06032 throw ImageDimensionException("Error: in reconstitute_image_mask, the mask doesn't match the image, it is too small"); 06033 } 06034 06035 float avg_under_mask = sum_under_mask / count; 06036 for(i = 0;i < size;i++) { 06037 if(mask_ptr[i] <= 0.5f) new_ptr[i] = avg_under_mask; 06038 } 06039 new_image->update(); 06040 return new_image; 06041 }
string Util::recv_broadcast | ( | int | port | ) | [static] |
Definition at line 1039 of file util.cpp.
References BPKT::data, BPKT::hdr, EMAN::ByteOrder::is_host_big_endian(), BPKT::len, BPKT::oseq, and BPKT::pseq.
01039 { 01040 // struct sockaddr_in sadr = { AF_INET, 9989, INADDR_ANY}; 01041 // int sock=socket(AF_INET,SOCK_DGRAM,0); 01042 // if (bind(sock,&sadr,sizeof(sockaddr_in))) return string(); 01043 01044 if (ByteOrder::is_host_big_endian()) { 01045 printf("No cache mirroring on Big endian machines yet\n"); 01046 return string(); // FIXME: no support for big endian hosts 01047 } 01048 01049 BPKT pkt; 01050 string ret; 01051 vector<char> fill; 01052 int obj=-1,i=0; 01053 // printf ("Listening\n"); 01054 01055 while (1) { 01056 int l = recv(sock,&pkt,1044,0); 01057 if (l<=0) { 01058 if (obj!=-1) printf("Timeout with incomplete obj %d %d/%d\n",obj,i,(int)fill.size()); 01059 return string(); // probably a timeout 01060 } 01061 if (l<20) { 01062 printf("Bad packet from broadcast"); 01063 continue; 01064 } 01065 01066 if (strncmp(pkt.hdr,"EMAN",4)!=0) continue; 01067 01068 // new object coming in 01069 if (obj!=pkt.oseq) { 01070 obj=pkt.oseq; 01071 ret.resize(pkt.len); 01072 fill.resize((pkt.len-1)/1024+1); 01073 for (i=0; i<fill.size(); i++) fill[i]=0; 01074 } 01075 if (obj==-1) printf("Something wierd happened. please report\n"); 01076 01077 // copy the packet into the output buffer 01078 fill[pkt.pseq]=1; 01079 ret.replace(pkt.pseq*1024,l-20,(char *)pkt.data,l-20); 01080 01081 // see if we got everything 01082 for (i=0; i<fill.size(); i++) { 01083 if (fill[i]!=1) break; 01084 } 01085 // printf("\t\t\tObj %d %d/%d \r",obj,i,(int)fill.size()); 01086 fflush(stdout); 01087 01088 if (i==fill.size()) return ret; // Yea ! We got a good packet 01089 } 01090 01091 }
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 1073 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 1433 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::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::WienerFourierReconstructor::insert_slice(), 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 19790 of file util_sparx.cpp.
References k_means_cont_table_().
19790 { 19791 //cout<<"sanitycheck called\n"; 19792 int total_cost = *output; 19793 int num_matches = *(output+1); 19794 19795 int cost=0; 19796 int* intx; 19797 int intx_size; 19798 int* intx_next; 19799 int intx_next_size; 19800 int curclass; 19801 int curclass_size; 19802 //cout<<"cost by match: ["; 19803 for(int i = 0; i < num_matches; i++){ 19804 curclass = *(output+2+ i*nParts); 19805 // check feasibility 19806 if (*(argParts + Indices[curclass]+1) == -5) {cout<<"infeasible match!\n"; return 0;} 19807 *(argParts + Indices[curclass]+1) = -5; 19808 // initialize intx to the number of elements in class curclass of partition 0 of the i-th match 19809 curclass_size = *(dimClasses+curclass)-2; 19810 intx = new int[curclass_size]; 19811 for (int ic = 0; ic < curclass_size; ic++) *(intx+ic) = *(argParts + Indices[curclass]+2+ic); 19812 intx_size = curclass_size; 19813 19814 for (int j=1; j < nParts; j++){ 19815 curclass = *(output+2+ i*nParts+j); 19816 if (*(argParts + Indices[j*K+curclass]+1)==-5){cout<<"infeasible match!\n"; return 0;} 19817 *(argParts + Indices[j*K+curclass]+1)=-5; 19818 // compute the intersection of intx and class curclass of partition j of the i-th match 19819 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); 19820 intx_next = new int[intx_next_size]; 19821 Util::k_means_cont_table_(intx,argParts + Indices[j*K+curclass]+2, intx_next, intx_size, *(dimClasses + j*K+curclass)-2,1); 19822 delete[] intx; 19823 intx=intx_next; 19824 intx_size= intx_next_size; 19825 if (j==nParts-1) delete[] intx_next; 19826 } 19827 19828 if (intx_next_size <= T) {cout << "something wrong with solution!\n"; return 0;} 19829 //cout <<intx_next_size<<","; 19830 cost = cost + intx_next_size; 19831 } 19832 //cout<<"]\n"; 19833 if (cost != total_cost) {cout << "something wrong with solution!\n"; return 0;} 19834 19835 return 1; 19836 19837 }
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::MatchSFProcessor::create_radial_func(), 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 | newT, | |||
int * | curmax | |||
) | [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 20017 of file util_sparx.cpp.
References explore2(), and k_means_cont_table_().
20017 { 20018 // initialize the current max weight to 0 20019 *curmax= 0; 20020 // some temp variables 20021 bool flag; 20022 int nintx; 20023 int* dummy; 20024 int* ret; 20025 20026 for(int a=0; a<K; a++) 20027 { 20028 // check that class a of partition 0 is active and has greater than newT elements. If not the case, then skip to the next class 20029 if (*(argParts + Indices[a] + 1) < 1) continue; 20030 if (*(dimClasses + a)-2 <= newT) continue; 20031 20032 // 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 20033 20034 for( int i=1; i < nParts; i++){ 20035 flag = 0; // if flag stays 0 then no class in this partition is active, which implies no feasible match with class a of part 0 20036 for(int j=0; j < K; j++){ 20037 if (*(argParts + Indices[i*K+j] + 1) < 1) continue; 20038 if (*(dimClasses + i*K+j)-2 <= newT) {*(argParts + Indices[i*K+j] + 1) =-4; continue;} 20039 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); 20040 if (nintx > newT) flag=1; 20041 else *(argParts + Indices[i*K+j] + 1) =-4; 20042 } 20043 if (flag==0) {break;} 20044 } 20045 20046 // explore determines the feasible match with the largest weight greater than newT 20047 if (flag > 0){ // Each partition has one or more active class 20048 ret=Util::explore2(argParts, Indices, dimClasses, nParts, K, newT, argParts+Indices[a]+2, *(dimClasses+a)-2, argParts+Indices[a]+2, *(dimClasses+a)-2,0); 20049 20050 if (*ret > *curmax){ 20051 *curmax = *ret; 20052 *(curmax+1)=a; 20053 for (int cp =0; cp < nParts-1; cp++) *(curmax+2+cp) = *(ret+1+cp); 20054 20055 } 20056 delete[] ret; 20057 } 20058 // take all the classes marked as -4 and remark it as 1 in preparation for next round 20059 for( int i=1; i < nParts; i++){ 20060 for(int j=0; j < K; j++){ 20061 if (*(argParts + Indices[i*K+j] + 1) == -4) *(argParts + Indices[i*K+j] + 1) =1; 20062 20063 } 20064 } 20065 20066 20067 20068 } 20069 20070 20071 }
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 4665 of file util_sparx.cpp.
References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), img_ptr, nx, and EMAN::EMData::update().
04666 { 04667 int i; 04668 int nx=img->get_xsize(); 04669 float *img_ptr = img->get_data(); 04670 float *line_ptr = line->get_data(); 04671 for (i=0;i<length;i++) img_ptr[nx*posline + i] = line_ptr[offset + i]; 04672 img->update(); 04673 }
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 1105 of file util.cpp.
References EMAN::Log::logger(), and EMAN::Log::set_level().
01106 { 01107 if (argc > 1 && strncmp(argv[1], "-v", 2) == 0) { 01108 char level_str[32]; 01109 strcpy(level_str, argv[1] + 2); 01110 Log::LogLevel log_level = (Log::LogLevel) atoi(level_str); 01111 Log::logger()->set_level(log_level); 01112 } 01113 }
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 2055 of file util.h.
Referenced by EMAN::EMData::extract_plane(), 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 5359 of file util_sparx.cpp.
References colreverse().
Referenced by cyclicshift().
05360 { 05361 int nxy = nx*ny; 05362 colreverse(beg, end, nxy); 05363 }
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 373 of file util_sparx.cpp.
00374 { 00375 int i,k; 00376 float p, qn, sig, un, *u; 00377 u = new float[n-1]; 00378 00379 if (yp1 > .99e30){ 00380 y2[0]=u[0]=0.0; 00381 } else { 00382 y2[0]=-.5f; 00383 u[0] =(3.0f/ (x[1] -x[0]))*( (y[1]-y[0])/(x[1]-x[0]) -yp1); 00384 } 00385 00386 for (i=1; i < n-1; i++) { 00387 sig= (x[i] - x[i-1])/(x[i+1] - x[i-1]); 00388 p = sig*y2[i-1] + 2.0f; 00389 y2[i] = (sig-1.0f)/p; 00390 u[i] = (y[i+1] - y[i] )/(x[i+1]-x[i] ) - (y[i] - y[i-1] )/(x[i] -x[i-1]); 00391 u[i] = (6.0f*u[i]/ (x[i+1]-x[i-1]) - sig*u[i-1])/p; 00392 } 00393 00394 if (ypn>.99e30){ 00395 qn=0; un=0; 00396 } else { 00397 qn= .5f; 00398 un= (3.0f/(x[n-1] -x[n-2])) * (ypn - (y[n-1]-y[n-2])/(x[n-1]-x[n-2])); 00399 } 00400 y2[n-1]= (un - qn*u[n-2])/(qn*y2[n-2]+1.0f); 00401 for (k=n-2; k>=0; k--){ 00402 y2[k]=y2[k]*y2[k+1]+u[k]; 00403 } 00404 delete [] u; 00405 }
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 348 of file util_sparx.cpp.
References spline(), and splint().
00349 { 00350 00351 float x0= x[0]; 00352 float x1= x[1]; 00353 float x2= x[2]; 00354 float y0= y[0]; 00355 float y1= y[1]; 00356 float y2= y[2]; 00357 float yp1 = (y1-y0)/(x1-x0) + (y2-y0)/(x2-x0) - (y2-y1)/(x2-x1) ; 00358 float xn = x[n]; 00359 float xnm1= x[n-1]; 00360 float xnm2= x[n-2]; 00361 float yn = y[n]; 00362 float ynm1= y[n-1]; 00363 float ynm2= y[n-2]; 00364 float ypn= (yn-ynm1)/(xn-xnm1) + (yn-ynm2)/(xn-xnm2) - (ynm1-ynm2)/(xnm1-xnm2) ; 00365 float *y2d = new float[n]; 00366 Util::spline(x,y,n,yp1,ypn,y2d); 00367 Util::splint(x,y,y2d,n,xq,yq,m); //PRB 00368 delete [] y2d; 00369 return; 00370 }
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 408 of file util_sparx.cpp.
References b.
00409 { 00410 int klo, khi, k; 00411 float h, b, a; 00412 00413 // klo=0; // can try to put here 00414 for (int j=0; j<m;j++){ 00415 klo=0; 00416 khi=n-1; 00417 while (khi-klo >1) { 00418 k=(khi+klo) >>1; 00419 if (xa[k]>xq[j]){ khi=k;} 00420 else { klo=k;} 00421 } 00422 h=xa[khi]- xa[klo]; 00423 if (h==0.0) printf("Bad XA input to routine SPLINT \n"); 00424 a =(xa[khi]-xq[j])/h; 00425 b=(xq[j]-xa[klo])/h; 00426 yq[j]=a*ya[klo] + b*ya[khi] 00427 + ((a*a*a-a)*y2a[klo] 00428 +(b*b*b-b)*y2a[khi]) *(h*h)/6.0f; 00429 } 00430 // 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]); 00431 }
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 1555 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::WienerFourierReconstructor::insert_slice(), 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 1583 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 4508 of file util_sparx.cpp.
References EXITFUNC, EMAN::EMData::get_data(), numr, PI2, and EMAN::EMData::update().
04508 { 04509 int nring = numr.size()/3; 04510 float *ave = avep->get_data(); 04511 float *dat = datp->get_data(); 04512 int i, j, numr3i, np; 04513 float arg, cs, si; 04514 int maxrin = numr(3,nring); 04515 if(mirror == 1) { //for mirrored data has to be conjugated 04516 for (i=1; i<=nring; i++) { 04517 numr3i = numr(3,i); 04518 np = numr(2,i)-1; 04519 ave[np] -= dat[np]; 04520 ave[np+1] -= static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) ); 04521 for (j=2; j<numr3i; j=j+2) { 04522 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin ); 04523 cs = cos(arg); 04524 si = sin(arg); 04525 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg)) 04526 ave[np + j] -= dat[np + j]*cs - dat[np + j +1]*si; 04527 ave[np + j +1] += dat[np + j]*si + dat[np + j +1]*cs; 04528 } 04529 } 04530 } else { 04531 for (i=1; i<=nring; i++) { 04532 numr3i = numr(3,i); 04533 np = numr(2,i)-1; 04534 ave[np] -= dat[np]; 04535 ave[np+1] -= static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) ); 04536 for (j=2; j<numr3i; j=j+2) { 04537 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin ); 04538 cs = cos(arg); 04539 si = sin(arg); 04540 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg)) 04541 ave[np + j] -= dat[np + j]*cs - dat[np + j +1]*si; 04542 ave[np + j +1] -= dat[np + j]*si + dat[np + j +1]*cs; 04543 } 04544 } 04545 } 04546 avep->update(); 04547 EXITFUNC; 04548 }
Definition at line 17479 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().
17480 { 17481 ENTERFUNC; 17482 /* Exception Handle */ 17483 if (!img) { 17484 throw NullPointerException("NULL input image"); 17485 } 17486 /* ========= img -= img1 ===================== */ 17487 17488 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17489 int size = nx*ny*nz; 17490 float *img_ptr = img->get_data(); 17491 float *img1_ptr = img1->get_data(); 17492 for (int i=0;i<size;i++) img_ptr[i] -= img1_ptr[i]; 17493 img->update(); 17494 17495 EXITFUNC; 17496 }
Definition at line 17261 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().
17262 { 17263 ENTERFUNC; 17264 /* Exception Handle */ 17265 if (!img) { 17266 throw NullPointerException("NULL input image"); 17267 } 17268 /* ============== output = img - img1 ================ */ 17269 17270 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17271 int size = nx*ny*nz; 17272 EMData * img2 = img->copy_head(); 17273 float *img_ptr =img->get_data(); 17274 float *img2_ptr = img2->get_data(); 17275 float *img1_ptr = img1->get_data(); 17276 for (int i=0;i<size;i++) img2_ptr[i] = img_ptr[i] - img1_ptr[i]; 17277 img2->update(); 17278 if(img->is_complex()) { 17279 img2->set_complex(true); 17280 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17281 } 17282 17283 EXITFUNC; 17284 return img2; 17285 }
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 5946 of file util_sparx.cpp.
References phase(), and sqrt().
Referenced by ctf_img().
05947 { 05948 float cst = cs*1.0e7f; 05949 05950 wgh /= 100.0; 05951 float phase = atan(wgh/sqrt(1.0f-wgh*wgh)); 05952 float lambda=12.398f/sqrt(voltage*(1022.0f+voltage)); 05953 float ak2 = ak*ak; 05954 float g1 = dzz*1.0e4f*lambda*ak2; 05955 float g2 = cst*lambda*lambda*lambda*ak2*ak2/2.0f; 05956 05957 float ctfv = static_cast<float>( sin(M_PI*(g1-g2)+phase)*sign ); 05958 if(b_factor != 0.0f) ctfv *= exp(-b_factor*ak2/4.0f); 05959 05960 return ctfv; 05961 }
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 1494 of file util.h.
Referenced by EMAN::EMData::cut_slice(), EMAN::SymSearchProcessor::process_inplace(), EMAN::StandardProjector::project3d(), EMAN::EMData::rotate_translate(), 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 1904 of file util_sparx.cpp.
01905 { 01906 01907 const float C2 = 0.5f; //1.0 / 2.0; 01908 const float C4 = 0.25f; //1.0 / 4.0; 01909 const float C8 = 0.125f; //1.0 / 8.0; 01910 01911 float RS = R * S; 01912 float ST = S * T; 01913 float RT = R * T; 01914 float RST = R * ST; 01915 01916 float RSQ = 1-R*R; 01917 float SSQ = 1-S*S; 01918 float TSQ = 1-T*T; 01919 01920 float RM1 = (1-R); 01921 float SM1 = (1-S); 01922 float TM1 = (1-T); 01923 01924 float RP1 = (1+R); 01925 float SP1 = (1+S); 01926 float TP1 = (1+T); 01927 01928 float triquad = 01929 (-C8) * RST * RM1 * SM1 * TM1 * fdata[0] + 01930 ( C4) * ST * RSQ * SM1 * TM1 * fdata[1] + 01931 ( C8) * RST * RP1 * SM1 * TM1 * fdata[2] + 01932 ( C4) * RT * RM1 * SSQ * TM1 * fdata[3] + 01933 (-C2) * T * RSQ * SSQ * TM1 * fdata[4] + 01934 (-C4) * RT * RP1 * SSQ * TM1 * fdata[5] + 01935 ( C8) * RST * RM1 * SP1 * TM1 * fdata[6] + 01936 (-C4) * ST * RSQ * SP1 * TM1 * fdata[7] + 01937 (-C8) * RST * RP1 * SP1 * TM1 * fdata[8] + 01938 // 01939 ( C4) * RS * RM1 * SM1 * TSQ * fdata[9] + 01940 (-C2) * S * RSQ * SM1 * TSQ * fdata[10] + 01941 (-C4) * RS * RP1 * SM1 * TSQ * fdata[11] + 01942 (-C2) * R * RM1 * SSQ * TSQ * fdata[12] + 01943 RSQ * SSQ * TSQ * fdata[13] + 01944 ( C2) * R * RP1 * SSQ * TSQ * fdata[14] + 01945 (-C4) * RS * RM1 * SP1 * TSQ * fdata[15] + 01946 ( C2) * S * RSQ * SP1 * TSQ * fdata[16] + 01947 ( C4) * RS * RP1 * SP1 * TSQ * fdata[17] + 01948 // 01949 ( C8) * RST * RM1 * SM1 * TP1 * fdata[18] + 01950 (-C4) * ST * RSQ * SM1 * TP1 * fdata[19] + 01951 (-C8) * RST * RP1 * SM1 * TP1 * fdata[20] + 01952 (-C4) * RT * RM1 * SSQ * TP1 * fdata[21] + 01953 ( C2) * T * RSQ * SSQ * TP1 * fdata[22] + 01954 ( C4) * RT * RP1 * SSQ * TP1 * fdata[23] + 01955 (-C8) * RST * RM1 * SP1 * TP1 * fdata[24] + 01956 ( C4) * ST * RSQ * SP1 * TP1 * fdata[25] + 01957 ( C8) * RST * RP1 * SP1 * TP1 * fdata[26] ; 01958 return triquad; 01959 }
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 7698 of file util_sparx.cpp.
References abs, addnod_(), and left_().
07702 { 07703 /* System generated locals */ 07704 int i__1, i__2; 07705 07706 /* Local variables */ 07707 static double d__; 07708 static int i__, j; 07709 static double d1, d2, d3; 07710 static int i0, lp, kt, ku, lpl, nku; 07711 extern long int left_(double *, double *, double *, double 07712 *, double *, double *, double *, double *, 07713 double *); 07714 static int nexti; 07715 extern /* Subroutine */ int addnod_(int *, int *, double *, 07716 double *, double *, int *, int *, int *, 07717 int *, int *); 07718 07719 07720 /* *********************************************************** */ 07721 07722 /* From STRIPACK */ 07723 /* Robert J. Renka */ 07724 /* Dept. of Computer Science */ 07725 /* Univ. of North Texas */ 07726 /* renka@cs.unt.edu */ 07727 /* 01/20/03 */ 07728 07729 /* This is an alternative to TRMESH with the inclusion of */ 07730 /* an efficient means of removing duplicate or nearly dupli- */ 07731 /* cate nodes. */ 07732 07733 /* This subroutine creates a Delaunay triangulation of a */ 07734 /* set of N arbitrarily distributed points, referred to as */ 07735 /* nodes, on the surface of the unit sphere. Refer to Sub- */ 07736 /* routine TRMESH for definitions and a list of additional */ 07737 /* subroutines. This routine is an alternative to TRMESH */ 07738 /* with the inclusion of an efficient means of removing dup- */ 07739 /* licate or nearly duplicate nodes. */ 07740 07741 /* The algorithm has expected time complexity O(N*log(N)) */ 07742 /* for random nodal distributions. */ 07743 07744 07745 /* On input: */ 07746 07747 /* N0 = Number of nodes, possibly including duplicates. */ 07748 /* N0 .GE. 3. */ 07749 07750 /* TOL = Tolerance defining a pair of duplicate nodes: */ 07751 /* bound on the deviation from 1 of the cosine of */ 07752 /* the angle between the nodes. Note that */ 07753 /* |1-cos(A)| is approximately A*A/2. */ 07754 07755 /* The above parameters are not altered by this routine. */ 07756 07757 /* X,Y,Z = Arrays of length at least N0 containing the */ 07758 /* Cartesian coordinates of nodes. (X(K),Y(K), */ 07759 /* Z(K)) is referred to as node K, and K is re- */ 07760 /* ferred to as a nodal index. It is required */ 07761 /* that X(K)**2 + Y(K)**2 + Z(K)**2 = 1 for all */ 07762 /* K. The first three nodes must not be col- */ 07763 /* linear (lie on a common great circle). */ 07764 07765 /* LIST,LPTR = Arrays of length at least 6*N0-12. */ 07766 07767 /* LEND = Array of length at least N0. */ 07768 07769 /* INDX = Array of length at least N0. */ 07770 07771 /* LCNT = Array of length at least N0 (length N is */ 07772 /* sufficient). */ 07773 07774 /* NEAR,NEXT,DIST = Work space arrays of length at */ 07775 /* least N0. The space is used to */ 07776 /* efficiently determine the nearest */ 07777 /* triangulation node to each un- */ 07778 /* processed node for use by ADDNOD. */ 07779 07780 /* On output: */ 07781 07782 /* N = Number of nodes in the triangulation. 3 .LE. N */ 07783 /* .LE. N0, or N = 0 if IER < 0. */ 07784 07785 /* X,Y,Z = Arrays containing the Cartesian coordinates */ 07786 /* of the triangulation nodes in the first N */ 07787 /* locations. The original array elements are */ 07788 /* shifted down as necessary to eliminate dup- */ 07789 /* licate nodes. */ 07790 07791 /* LIST = Set of nodal indexes which, along with LPTR, */ 07792 /* LEND, and LNEW, define the triangulation as a */ 07793 /* set of N adjacency lists -- counterclockwise- */ 07794 /* ordered sequences of neighboring nodes such */ 07795 /* that the first and last neighbors of a bound- */ 07796 /* ary node are boundary nodes (the first neigh- */ 07797 /* bor of an interior node is arbitrary). In */ 07798 /* order to distinguish between interior and */ 07799 /* boundary nodes, the last neighbor of each */ 07800 /* boundary node is represented by the negative */ 07801 /* of its index. */ 07802 07803 /* LPTR = Set of pointers (LIST indexes) in one-to-one */ 07804 /* correspondence with the elements of LIST. */ 07805 /* LIST(LPTR(I)) indexes the node which follows */ 07806 /* LIST(I) in cyclical counterclockwise order */ 07807 /* (the first neighbor follows the last neigh- */ 07808 /* bor). */ 07809 07810 /* LEND = Set of pointers to adjacency lists. LEND(K) */ 07811 /* points to the last neighbor of node K for */ 07812 /* K = 1,...,N. Thus, LIST(LEND(K)) < 0 if and */ 07813 /* only if K is a boundary node. */ 07814 07815 /* LNEW = Pointer to the first empty location in LIST */ 07816 /* and LPTR (list length plus one). LIST, LPTR, */ 07817 /* LEND, and LNEW are not altered if IER < 0, */ 07818 /* and are incomplete if IER > 0. */ 07819 07820 /* INDX = Array of output (triangulation) nodal indexes */ 07821 /* associated with input nodes. For I = 1 to */ 07822 /* N0, INDX(I) is the index (for X, Y, and Z) of */ 07823 /* the triangulation node with the same (or */ 07824 /* nearly the same) coordinates as input node I. */ 07825 07826 /* LCNT = Array of int weights (counts) associated */ 07827 /* with the triangulation nodes. For I = 1 to */ 07828 /* N, LCNT(I) is the number of occurrences of */ 07829 /* node I in the input node set, and thus the */ 07830 /* number of duplicates is LCNT(I)-1. */ 07831 07832 /* NEAR,NEXT,DIST = Garbage. */ 07833 07834 /* IER = Error indicator: */ 07835 /* IER = 0 if no errors were encountered. */ 07836 /* IER = -1 if N0 < 3 on input. */ 07837 /* IER = -2 if the first three nodes are */ 07838 /* collinear. */ 07839 /* IER = -3 if Subroutine ADDNOD returns an error */ 07840 /* flag. This should not occur. */ 07841 07842 /* Modules required by TRMSH3: ADDNOD, BDYADD, COVSPH, */ 07843 /* INSERT, INTADD, JRAND, */ 07844 /* LEFT, LSTPTR, STORE, SWAP, */ 07845 /* SWPTST, TRFIND */ 07846 07847 /* Intrinsic function called by TRMSH3: ABS */ 07848 07849 /* *********************************************************** */ 07850 07851 07852 /* Local parameters: */ 07853 07854 /* D = (Negative cosine of) distance from node KT to */ 07855 /* node I */ 07856 /* D1,D2,D3 = Distances from node KU to nodes 1, 2, and 3, */ 07857 /* respectively */ 07858 /* I,J = Nodal indexes */ 07859 /* I0 = Index of the node preceding I in a sequence of */ 07860 /* unprocessed nodes: I = NEXT(I0) */ 07861 /* KT = Index of a triangulation node */ 07862 /* KU = Index of an unprocessed node and DO-loop index */ 07863 /* LP = LIST index (pointer) of a neighbor of KT */ 07864 /* LPL = Pointer to the last neighbor of KT */ 07865 /* NEXTI = NEXT(I) */ 07866 /* NKU = NEAR(KU) */ 07867 07868 /* Parameter adjustments */ 07869 --dist; 07870 --next; 07871 --near__; 07872 --indx; 07873 --lend; 07874 --z__; 07875 --y; 07876 --x; 07877 --list; 07878 --lptr; 07879 --lcnt; 07880 07881 /* Function Body */ 07882 if (*n0 < 3) { 07883 *n = 0; 07884 *ier = -1; 07885 return 0; 07886 } 07887 07888 /* Store the first triangle in the linked list. */ 07889 07890 if (! left_(&x[1], &y[1], &z__[1], &x[2], &y[2], &z__[2], &x[3], &y[3], & 07891 z__[3])) { 07892 07893 /* The first triangle is (3,2,1) = (2,1,3) = (1,3,2). */ 07894 07895 list[1] = 3; 07896 lptr[1] = 2; 07897 list[2] = -2; 07898 lptr[2] = 1; 07899 lend[1] = 2; 07900 07901 list[3] = 1; 07902 lptr[3] = 4; 07903 list[4] = -3; 07904 lptr[4] = 3; 07905 lend[2] = 4; 07906 07907 list[5] = 2; 07908 lptr[5] = 6; 07909 list[6] = -1; 07910 lptr[6] = 5; 07911 lend[3] = 6; 07912 07913 } else if (! left_(&x[2], &y[2], &z__[2], &x[1], &y[1], &z__[1], &x[3], & 07914 y[3], &z__[3])) { 07915 07916 /* The first triangle is (1,2,3): 3 Strictly Left 1->2, */ 07917 /* i.e., node 3 lies in the left hemisphere defined by */ 07918 /* arc 1->2. */ 07919 07920 list[1] = 2; 07921 lptr[1] = 2; 07922 list[2] = -3; 07923 lptr[2] = 1; 07924 lend[1] = 2; 07925 07926 list[3] = 3; 07927 lptr[3] = 4; 07928 list[4] = -1; 07929 lptr[4] = 3; 07930 lend[2] = 4; 07931 07932 list[5] = 1; 07933 lptr[5] = 6; 07934 list[6] = -2; 07935 lptr[6] = 5; 07936 lend[3] = 6; 07937 07938 07939 } else { 07940 07941 /* The first three nodes are collinear. */ 07942 07943 *n = 0; 07944 *ier = -2; 07945 return 0; 07946 } 07947 07948 //printf("pass check colinear\n"); 07949 07950 /* Initialize LNEW, INDX, and LCNT, and test for N = 3. */ 07951 07952 *lnew = 7; 07953 indx[1] = 1; 07954 indx[2] = 2; 07955 indx[3] = 3; 07956 lcnt[1] = 1; 07957 lcnt[2] = 1; 07958 lcnt[3] = 1; 07959 if (*n0 == 3) { 07960 *n = 3; 07961 *ier = 0; 07962 return 0; 07963 } 07964 07965 /* A nearest-node data structure (NEAR, NEXT, and DIST) is */ 07966 /* used to obtain an expected-time (N*log(N)) incremental */ 07967 /* algorithm by enabling constant search time for locating */ 07968 /* each new node in the triangulation. */ 07969 07970 /* For each unprocessed node KU, NEAR(KU) is the index of the */ 07971 /* triangulation node closest to KU (used as the starting */ 07972 /* point for the search in Subroutine TRFIND) and DIST(KU) */ 07973 /* is an increasing function of the arc length (angular */ 07974 /* distance) between nodes KU and NEAR(KU): -Cos(a) for */ 07975 /* arc length a. */ 07976 07977 /* Since it is necessary to efficiently find the subset of */ 07978 /* unprocessed nodes associated with each triangulation */ 07979 /* node J (those that have J as their NEAR entries), the */ 07980 /* subsets are stored in NEAR and NEXT as follows: for */ 07981 /* each node J in the triangulation, I = NEAR(J) is the */ 07982 /* first unprocessed node in J's set (with I = 0 if the */ 07983 /* set is empty), L = NEXT(I) (if I > 0) is the second, */ 07984 /* NEXT(L) (if L > 0) is the third, etc. The nodes in each */ 07985 /* set are initially ordered by increasing indexes (which */ 07986 /* maximizes efficiency) but that ordering is not main- */ 07987 /* tained as the data structure is updated. */ 07988 07989 /* Initialize the data structure for the single triangle. */ 07990 07991 near__[1] = 0; 07992 near__[2] = 0; 07993 near__[3] = 0; 07994 for (ku = *n0; ku >= 4; --ku) { 07995 d1 = -(x[ku] * x[1] + y[ku] * y[1] + z__[ku] * z__[1]); 07996 d2 = -(x[ku] * x[2] + y[ku] * y[2] + z__[ku] * z__[2]); 07997 d3 = -(x[ku] * x[3] + y[ku] * y[3] + z__[ku] * z__[3]); 07998 if (d1 <= d2 && d1 <= d3) { 07999 near__[ku] = 1; 08000 dist[ku] = d1; 08001 next[ku] = near__[1]; 08002 near__[1] = ku; 08003 } else if (d2 <= d1 && d2 <= d3) { 08004 near__[ku] = 2; 08005 dist[ku] = d2; 08006 next[ku] = near__[2]; 08007 near__[2] = ku; 08008 } else { 08009 near__[ku] = 3; 08010 dist[ku] = d3; 08011 next[ku] = near__[3]; 08012 near__[3] = ku; 08013 } 08014 /* L1: */ 08015 } 08016 08017 /* Loop on unprocessed nodes KU. KT is the number of nodes */ 08018 /* in the triangulation, and NKU = NEAR(KU). */ 08019 08020 kt = 3; 08021 i__1 = *n0; 08022 for (ku = 4; ku <= i__1; ++ku) { 08023 nku = near__[ku]; 08024 08025 /* Remove KU from the set of unprocessed nodes associated */ 08026 /* with NEAR(KU). */ 08027 i__ = nku; 08028 if (near__[i__] == ku) { 08029 near__[i__] = next[ku]; 08030 } else { 08031 i__ = near__[i__]; 08032 L2: 08033 i0 = i__; 08034 i__ = next[i0]; 08035 if (i__ != ku) { 08036 goto L2; 08037 } 08038 next[i0] = next[ku]; 08039 } 08040 near__[ku] = 0; 08041 08042 /* Bypass duplicate nodes. */ 08043 08044 if (dist[ku] <= *tol - 1.) { 08045 indx[ku] = -nku; 08046 ++lcnt[nku]; 08047 goto L6; 08048 } 08049 08050 08051 /* Add a new triangulation node KT with LCNT(KT) = 1. */ 08052 ++kt; 08053 x[kt] = x[ku]; 08054 y[kt] = y[ku]; 08055 z__[kt] = z__[ku]; 08056 indx[ku] = kt; 08057 lcnt[kt] = 1; 08058 addnod_(&nku, &kt, &x[1], &y[1], &z__[1], &list[1], &lptr[1], &lend[1] 08059 , lnew, ier); 08060 if (*ier != 0) { 08061 *n = 0; 08062 *ier = -3; 08063 return 0; 08064 } 08065 08066 /* Loop on neighbors J of node KT. */ 08067 08068 lpl = lend[kt]; 08069 lp = lpl; 08070 L3: 08071 lp = lptr[lp]; 08072 j = (i__2 = list[lp], abs(i__2)); 08073 08074 /* Loop on elements I in the sequence of unprocessed nodes */ 08075 /* associated with J: KT is a candidate for replacing J */ 08076 /* as the nearest triangulation node to I. The next value */ 08077 /* of I in the sequence, NEXT(I), must be saved before I */ 08078 /* is moved because it is altered by adding I to KT's set. */ 08079 08080 i__ = near__[j]; 08081 L4: 08082 if (i__ == 0) { 08083 goto L5; 08084 } 08085 nexti = next[i__]; 08086 08087 /* Test for the distance from I to KT less than the distance */ 08088 /* from I to J. */ 08089 08090 d__ = -(x[i__] * x[kt] + y[i__] * y[kt] + z__[i__] * z__[kt]); 08091 if (d__ < dist[i__]) { 08092 08093 /* Replace J by KT as the nearest triangulation node to I: */ 08094 /* update NEAR(I) and DIST(I), and remove I from J's set */ 08095 /* of unprocessed nodes and add it to KT's set. */ 08096 08097 near__[i__] = kt; 08098 dist[i__] = d__; 08099 if (i__ == near__[j]) { 08100 near__[j] = nexti; 08101 } else { 08102 next[i0] = nexti; 08103 } 08104 next[i__] = near__[kt]; 08105 near__[kt] = i__; 08106 } else { 08107 i0 = i__; 08108 } 08109 08110 /* Bottom of loop on I. */ 08111 08112 i__ = nexti; 08113 goto L4; 08114 08115 /* Bottom of loop on neighbors J. */ 08116 08117 L5: 08118 if (lp != lpl) { 08119 goto L3; 08120 } 08121 L6: 08122 ; 08123 } 08124 *n = kt; 08125 *ier = 0; 08126 return 0; 08127 } /* trmsh3_ */
vector< float > Util::twoD_fine_ali | ( | EMData * | image, | |
EMData * | refim, | |||
EMData * | mask, | |||
float | ang, | |||
float | sxs, | |||
float | sys | |||
) | [static] |
Definition at line 18412 of file util_sparx.cpp.
References EMAN::EMData::cmp(), dt, EMAN::EMData::rot_scale_trans2D(), setulb_(), and SIXTY.
18412 { 18413 18414 EMData *rot; 18415 18416 const int nmax=3, mmax=3; 18417 char task[60], csave[60]; 18418 long int lsave[4]; 18419 long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44]; 18420 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]; 18421 long int SIXTY=60; 18422 18423 // We wish to have no output. 18424 iprint = -1; 18425 18426 //c We specify the tolerances in the stopping criteria. 18427 factr=1.0e1; 18428 pgtol=1.0e-5; 18429 18430 // We specify the dimension n of the sample problem and the number 18431 // m of limited memory corrections stored. (n and m should not 18432 // exceed the limits nmax and mmax respectively.) 18433 n=3; 18434 m=3; 18435 18436 // We now provide nbd which defines the bounds on the variables: 18437 // l specifies the lower bounds, 18438 // u specifies the upper bounds. 18439 // x specifies the initial guess 18440 x[0] = ang; nbd[0] = 2; l[0] = ang-2.0; u[0] = ang+2.0; 18441 x[1] = sxs; nbd[1] = 2; l[1] = sxs-1.5; u[1] = sxs+1.5; 18442 x[2] = sys; nbd[2] = 2; l[2] = sys-1.5; u[2] = sys+1.5; 18443 18444 18445 // We start the iteration by initializing task. 18446 // (**MUST clear remaining chars in task with spaces (else crash)!**) 18447 strcpy(task,"START"); 18448 for (int i=5;i<60;i++) task[i]=' '; 18449 18450 // This is the call to the L-BFGS-B code. 18451 // (* call the L-BFGS-B routine with task='START' once before loop *) 18452 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 18453 //int step = 1; 18454 18455 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *) 18456 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) { 18457 18458 if (strncmp(task,"FG",2)==0) { 18459 // the minimization routine has returned to request the 18460 // function f and gradient g values at the current x 18461 18462 // Compute function value f for the sample problem. 18463 rot = new EMData(); 18464 rot = image->rot_scale_trans2D((float)x[0], (float)x[1], (float)x[2], 1.0f); 18465 f = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 18466 //f = -f; 18467 delete rot; 18468 18469 // Compute gradient g for the sample problem. 18470 float dt = 1.0e-3f; 18471 rot = new EMData(); 18472 rot = image->rot_scale_trans2D((float)x[0]+dt, (float)x[1], (float)x[2], 1.0f); 18473 f1 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 18474 //f1 = -f1; 18475 g[0] = (f1-f)/dt; 18476 delete rot; 18477 18478 dt = 1.0e-2f; 18479 rot = new EMData(); 18480 rot = image->rot_scale_trans2D((float)x[0], (float)x[1]+dt, (float)x[2], 1.0f); 18481 f2 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 18482 //f2 = -f2; 18483 g[1] = (f2-f)/dt; 18484 delete rot; 18485 18486 rot = new EMData(); 18487 rot = image->rot_scale_trans2D((float)x[0], (float)x[1], (float)x[2]+dt, 1.0f); 18488 f3 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 18489 //f3 = -f3; 18490 g[2] = (f3-f)/dt; 18491 delete rot; 18492 } 18493 18494 //c go back to the minimization routine. 18495 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 18496 //step++; 18497 } 18498 18499 //printf("Total step is %d\n", step); 18500 vector<float> res; 18501 res.push_back(static_cast<float>(x[0])); 18502 res.push_back(static_cast<float>(x[1])); 18503 res.push_back(static_cast<float>(x[2])); 18504 //res.push_back(step); 18505 return res; 18506 }
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 18508 of file util_sparx.cpp.
References EMAN::EMData::cmp(), dt, pi, EMAN::EMData::rot_scale_conv7(), setulb_(), and SIXTY.
18508 { 18509 18510 EMData *rot; 18511 18512 const int nmax=3, mmax=3; 18513 char task[60], csave[60]; 18514 long int lsave[4]; 18515 long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44]; 18516 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]; 18517 long int SIXTY=60; 18518 18519 // We wish to have no output. 18520 iprint = -1; 18521 18522 //c We specify the tolerances in the stopping criteria. 18523 factr=1.0e1; 18524 pgtol=1.0e-5; 18525 18526 // We specify the dimension n of the sample problem and the number 18527 // m of limited memory corrections stored. (n and m should not 18528 // exceed the limits nmax and mmax respectively.) 18529 n=3; 18530 m=3; 18531 18532 // We now provide nbd which defines the bounds on the variables: 18533 // l specifies the lower bounds, 18534 // u specifies the upper bounds. 18535 // x specifies the initial guess 18536 x[0] = ang; nbd[0] = 2; l[0] = ang-2.0; u[0] = ang+2.0; 18537 x[1] = sxs; nbd[1] = 2; l[1] = sxs-1.5; u[1] = sxs+1.5; 18538 x[2] = sys; nbd[2] = 2; l[2] = sys-1.5; u[2] = sys+1.5; 18539 18540 18541 // We start the iteration by initializing task. 18542 // (**MUST clear remaining chars in task with spaces (else crash)!**) 18543 strcpy(task,"START"); 18544 for (int i=5;i<60;i++) task[i]=' '; 18545 18546 // This is the call to the L-BFGS-B code. 18547 // (* call the L-BFGS-B routine with task='START' once before loop *) 18548 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 18549 //int step = 1; 18550 18551 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *) 18552 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) { 18553 18554 if (strncmp(task,"FG",2)==0) { 18555 // the minimization routine has returned to request the 18556 // function f and gradient g values at the current x 18557 18558 // Compute function value f for the sample problem. 18559 rot = new EMData(); 18560 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1], (float)x[2], kb, 1.0f); 18561 f = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 18562 //f = -f; 18563 delete rot; 18564 18565 // Compute gradient g for the sample problem. 18566 float dt = 1.0e-3f; 18567 rot = new EMData(); 18568 rot = image->rot_scale_conv7((float)((x[0]+dt)*pi/180), (float)x[1], (float)x[2], kb, 1.0f); 18569 f1 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 18570 //f1 = -f1; 18571 g[0] = (f1-f)/dt; 18572 delete rot; 18573 18574 rot = new EMData(); 18575 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1]+dt, (float)x[2], kb, 1.0); 18576 f2 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 18577 //f2 = -f2; 18578 g[1] = (f2-f)/dt; 18579 delete rot; 18580 18581 rot = new EMData(); 18582 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1], (float)x[2]+dt, kb, 1.0f); 18583 f3 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 18584 //f3 = -f3; 18585 g[2] = (f3-f)/dt; 18586 delete rot; 18587 } 18588 18589 //c go back to the minimization routine. 18590 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 18591 //step++; 18592 } 18593 18594 //printf("Total step is %d\n", step); 18595 vector<float> res; 18596 res.push_back(static_cast<float>(x[0])); 18597 res.push_back(static_cast<float>(x[1])); 18598 res.push_back(static_cast<float>(x[2])); 18599 //res.push_back(step); 18600 return res; 18601 }
vector< float > Util::twoD_fine_ali_SD | ( | EMData * | image, | |
EMData * | refim, | |||
EMData * | mask, | |||
float | ang, | |||
float | sxs, | |||
float | sys | |||
) | [static] |
Definition at line 18760 of file util_sparx.cpp.
References ccc_images(), and Steepda().
18760 { 18761 18762 double x[4]; 18763 int n; 18764 int l = 3; 18765 int m = 200; 18766 double e = 1e-9; 18767 double step = 0.01; 18768 float (*my_func)(EMData* , EMData* , EMData* , float , float , float) = ccc_images; 18769 18770 x[1] = ang; 18771 x[2] = sxs; 18772 x[3] = sys; 18773 18774 Steepda(x, step, e, l, m, &n, my_func, image, refim, mask); // Call steepest descent optimization subroutine 18775 //printf("Took %d steps\n", n); 18776 18777 vector<float> res; 18778 res.push_back(static_cast<float>(x[1])); 18779 res.push_back(static_cast<float>(x[2])); 18780 res.push_back(static_cast<float>(x[3])); 18781 res.push_back(static_cast<float>(n)); 18782 return res; 18783 }
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 18797 of file util_sparx.cpp.
References ccc_images_G(), and Steepda_G().
18797 { 18798 18799 double x[4]; 18800 int n; 18801 int l = 3; 18802 int m = 200; 18803 double e = 1e-9; 18804 double step = 0.001; 18805 float (*my_func)(EMData* , EMData* , EMData* , Util::KaiserBessel&, float , float , float) = ccc_images_G; 18806 18807 x[1] = ang; 18808 x[2] = sxs; 18809 x[3] = sys; 18810 18811 Steepda_G(x, step, e, l, m, &n, my_func, image, refim, mask, kb); // Call steepest descent optimization subroutine 18812 //printf("Took %d steps\n", n); 18813 18814 vector<float> res; 18815 res.push_back(static_cast<float>(x[1])); 18816 res.push_back(static_cast<float>(x[2])); 18817 res.push_back(static_cast<float>(x[3])); 18818 res.push_back(static_cast<float>(n)); 18819 return res; 18820 }
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 18603 of file util_sparx.cpp.
References EMAN::EMData::cmp(), dt, EMAN::EMData::extract_plane(), proj, setulb_(), and SIXTY.
18603 { 18604 18605 EMData *proj, *proj2; 18606 18607 const int nmax=5, mmax=5; 18608 char task[60], csave[60]; 18609 long int lsave[4]; 18610 long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44]; 18611 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]; 18612 long int SIXTY=60; 18613 18614 // We wish to have no output. 18615 iprint = -1; 18616 18617 //c We specify the tolerances in the stopping criteria. 18618 factr=1.0e1; 18619 pgtol=1.0e-5; 18620 18621 // We specify the dimension n of the sample problem and the number 18622 // m of limited memory corrections stored. (n and m should not 18623 // exceed the limits nmax and mmax respectively.) 18624 n=5; 18625 m=5; 18626 18627 // We now provide nbd which defines the bounds on the variables: 18628 // l specifies the lower bounds, 18629 // u specifies the upper bounds. 18630 // x specifies the initial guess 18631 x[0] = phi; nbd[0] = 2; l[0] = phi-2.0; u[0] = phi+2.0; 18632 x[1] = theta; nbd[1] = 2; l[1] = theta-2.0; u[1] = theta+2.0; 18633 x[2] = psi; nbd[2] = 2; l[2] = psi-2.0; u[2] = psi+2.0; 18634 x[3] = sxs; nbd[3] = 2; l[3] = sxs-2.0; u[3] = sxs+2.0; 18635 x[4] = sys; nbd[4] = 2; l[4] = sys-2.0; u[4] = sys+2.0; 18636 18637 18638 // We start the iteration by initializing task. 18639 // (**MUST clear remaining chars in task with spaces (else crash)!**) 18640 strcpy(task,"START"); 18641 for (int i=5;i<60;i++) task[i]=' '; 18642 18643 // This is the call to the L-BFGS-B code. 18644 // (* call the L-BFGS-B routine with task='START' once before loop *) 18645 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 18646 int step = 1; 18647 18648 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *) 18649 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) { 18650 18651 if (strncmp(task,"FG",2)==0) { 18652 // the minimization routine has returned to request the 18653 // function f and gradient g values at the current x 18654 18655 // Compute function value f for the sample problem. 18656 proj = new EMData(); 18657 proj2 = new EMData(); 18658 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb); 18659 proj->fft_shuffle(); 18660 proj->center_origin_fft(); 18661 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f)); 18662 proj->do_ift_inplace(); 18663 int M = proj->get_ysize()/2; 18664 proj2 = proj->window_center(M); 18665 f = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 18666 //f = -f; 18667 delete proj; 18668 delete proj2; 18669 18670 // Compute gradient g for the sample problem. 18671 float dt = 1.0e-3f; 18672 proj = new EMData(); 18673 proj2 = new EMData(); 18674 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0]+dt, "theta", (float)x[1], "psi", (float)x[2])), kb); 18675 proj->fft_shuffle(); 18676 proj->center_origin_fft(); 18677 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f)); 18678 proj->do_ift_inplace(); 18679 proj2 = proj->window_center(M); 18680 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 18681 //ft = -ft; 18682 delete proj; 18683 delete proj2; 18684 g[0] = (ft-f)/dt; 18685 18686 proj = new EMData(); 18687 proj2 = new EMData(); 18688 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1]+dt, "psi", (float)x[2])), kb); 18689 proj->fft_shuffle(); 18690 proj->center_origin_fft(); 18691 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f)); 18692 proj->do_ift_inplace(); 18693 proj2 = proj->window_center(M); 18694 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 18695 //ft = -ft; 18696 delete proj; 18697 delete proj2; 18698 g[1] = (ft-f)/dt; 18699 18700 proj = new EMData(); 18701 proj2 = new EMData(); 18702 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2]+dt)), kb); 18703 proj->fft_shuffle(); 18704 proj->center_origin_fft(); 18705 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f)); 18706 proj->do_ift_inplace(); 18707 proj2 = proj->window_center(M); 18708 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 18709 //ft = -ft; 18710 delete proj; 18711 delete proj2; 18712 g[2] = (ft-f)/dt; 18713 18714 proj = new EMData(); 18715 proj2 = new EMData(); 18716 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb); 18717 proj->fft_shuffle(); 18718 proj->center_origin_fft(); 18719 proj->process_inplace("filter.shift", Dict("x_shift", x[3]+dt, "y_shift", x[4], "z_shift", 0.0f)); 18720 proj->do_ift_inplace(); 18721 proj2 = proj->window_center(M); 18722 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 18723 //ft = -ft; 18724 delete proj; 18725 delete proj2; 18726 g[3] = (ft-f)/dt; 18727 18728 proj = new EMData(); 18729 proj2 = new EMData(); 18730 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb); 18731 proj->fft_shuffle(); 18732 proj->center_origin_fft(); 18733 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4]+dt, "z_shift", 0.0f)); 18734 proj->do_ift_inplace(); 18735 proj2 = proj->window_center(M); 18736 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 18737 //ft = -ft; 18738 delete proj; 18739 delete proj2; 18740 g[4] = (ft-f)/dt; 18741 } 18742 18743 //c go back to the minimization routine. 18744 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 18745 step++; 18746 } 18747 18748 //printf("Total step is %d\n", step); 18749 vector<float> res; 18750 res.push_back(static_cast<float>(x[0])); 18751 res.push_back(static_cast<float>(x[1])); 18752 res.push_back(static_cast<float>(x[2])); 18753 res.push_back(static_cast<float>(x[3])); 18754 res.push_back(static_cast<float>(x[4])); 18755 //res.push_back(step); 18756 return res; 18757 }
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 235 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.
00236 { 00237 ENTERFUNC; 00238 int Mid= (Size+1)/2; 00239 00240 if (flag==0) { // This is the real function 00241 EMData* ImBW = new EMData(); 00242 ImBW->set_size(Size,Size,1); 00243 ImBW->to_zero(); 00244 00245 float tempIm; 00246 float x,y; 00247 00248 for (int ix=(1-Mid); ix<Mid; ix++){ 00249 for (int iy=(1-Mid); iy<Mid; iy++){ 00250 x = (float)ix; 00251 y = (float)iy; 00252 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)) ); 00253 (*ImBW)(ix+Mid-1,iy+Mid-1) = tempIm * exp(.5f*p*p*a*a)* exp(.5f*q*q*b*b); 00254 } 00255 } 00256 ImBW->update(); 00257 ImBW->set_complex(false); 00258 ImBW->set_ri(true); 00259 00260 return ImBW; 00261 } 00262 else if (flag==1) { // This is the Fourier Transform 00263 EMData* ImBWFFT = new EMData(); 00264 ImBWFFT ->set_size(2*Size,Size,1); 00265 ImBWFFT ->to_zero(); 00266 00267 float r,s; 00268 00269 for (int ir=(1-Mid); ir<Mid; ir++){ 00270 for (int is=(1-Mid); is<Mid; is++){ 00271 r = (float)ir; 00272 s = (float)is; 00273 (*ImBWFFT)(2*(ir+Mid-1),is+Mid-1)= cosh(p*r*a*a) * cosh(q*s*b*b) * 00274 exp(-.5f*r*r*a*a)* exp(-.5f*s*s*b*b); 00275 } 00276 } 00277 ImBWFFT->update(); 00278 ImBWFFT->set_complex(true); 00279 ImBWFFT->set_ri(true); 00280 ImBWFFT->set_shuffled(true); 00281 ImBWFFT->set_fftodd(true); 00282 00283 return ImBWFFT; 00284 } 00285 else if (flag==2 || flag==3) { // This is the projection in Real Space 00286 float alpha = static_cast<float>( alphaDeg*M_PI/180.0 ); 00287 float C=cos(alpha); 00288 float S=sin(alpha); 00289 float D= sqrt(S*S*b*b + C*C*a*a); 00290 //float D2 = D*D; PAP - to get rid of warning 00291 00292 float P = p * C *a*a/D ; 00293 float Q = q * S *b*b/D ; 00294 00295 if (flag==2) { 00296 EMData* pofalpha = new EMData(); 00297 pofalpha ->set_size(Size,1,1); 00298 pofalpha ->to_zero(); 00299 00300 float Norm0 = D*(float)sqrt(2*pi); 00301 float Norm1 = exp( .5f*(P+Q)*(P+Q)) / Norm0 ; 00302 float Norm2 = exp( .5f*(P-Q)*(P-Q)) / Norm0 ; 00303 float sD; 00304 00305 for (int is=(1-Mid); is<Mid; is++){ 00306 sD = is/D ; 00307 (*pofalpha)(is+Mid-1) = Norm1 * exp(-.5f*sD*sD)*cos(sD*(P+Q)) 00308 + Norm2 * exp(-.5f*sD*sD)*cos(sD*(P-Q)); 00309 } 00310 pofalpha-> update(); 00311 pofalpha-> set_complex(false); 00312 pofalpha-> set_ri(true); 00313 00314 return pofalpha; 00315 } 00316 if (flag==3) { // This is the projection in Fourier Space 00317 float vD; 00318 00319 EMData* pofalphak = new EMData(); 00320 pofalphak ->set_size(2*Size,1,1); 00321 pofalphak ->to_zero(); 00322 00323 for (int iv=(1-Mid); iv<Mid; iv++){ 00324 vD = iv*D ; 00325 (*pofalphak)(2*(iv+Mid-1)) = exp(-.5f*vD*vD)*(cosh(vD*(P+Q)) + cosh(vD*(P-Q)) ); 00326 } 00327 pofalphak-> update(); 00328 pofalphak-> set_complex(false); 00329 pofalphak-> set_ri(true); 00330 00331 return pofalphak; 00332 } 00333 } 00334 else if (flag==4) { 00335 cout <<" FH under construction"; 00336 EMData* OutFT= TwoDTestFunc(Size, p, q, a, b, 1); 00337 EMData* TryFH= OutFT -> real2FH(4.0); 00338 return TryFH; 00339 } else { 00340 cout <<" flag must be 0,1,2,3, or 4"; 00341 } 00342 00343 EXITFUNC; 00344 return 0; 00345 }
void Util::update_fav | ( | EMData * | ave, | |
EMData * | dat, | |||
float | tot, | |||
int | mirror, | |||
vector< int > | numr | |||
) | [static] |
Definition at line 4466 of file util_sparx.cpp.
References EXITFUNC, EMAN::EMData::get_data(), numr, PI2, and EMAN::EMData::update().
04466 { 04467 int nring = numr.size()/3; 04468 float *ave = avep->get_data(); 04469 float *dat = datp->get_data(); 04470 int i, j, numr3i, np; 04471 float arg, cs, si; 04472 int maxrin = numr(3,nring); 04473 if(mirror == 1) { //for mirrored data has to be conjugated 04474 for (i=1; i<=nring; i++) { 04475 numr3i = numr(3,i); 04476 np = numr(2,i)-1; 04477 ave[np] += dat[np]; 04478 ave[np+1] += static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) ); 04479 for (j=2; j<numr3i; j=j+2) { 04480 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin ); 04481 cs = cos(arg); 04482 si = sin(arg); 04483 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg)) 04484 ave[np + j] += dat[np + j]*cs - dat[np + j +1]*si; 04485 ave[np + j +1] -= dat[np + j]*si + dat[np + j +1]*cs; 04486 } 04487 } 04488 } else { 04489 for (i=1; i<=nring; i++) { 04490 numr3i = numr(3,i); 04491 np = numr(2,i)-1; 04492 ave[np] += dat[np]; 04493 ave[np+1] += static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) ); 04494 for (j=2; j<numr3i; j=j+2) { 04495 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin ); 04496 cs = cos(arg); 04497 si = sin(arg); 04498 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg)) 04499 ave[np + j] += dat[np + j]*cs - dat[np + j +1]*si; 04500 ave[np + j +1] += dat[np + j]*si + dat[np + j +1]*cs; 04501 } 04502 } 04503 } 04504 avep->update(); 04505 EXITFUNC; 04506 }
vector< float > Util::vareas | ( | EMData * | d | ) | [static] |
Definition at line 19518 of file util_sparx.cpp.
References data, dm, EMAN::EMData::get_ysize(), and ny.
19518 { 19519 const float step=0.001f; 19520 int ny = d->get_ysize(); 19521 // input emdata should have size 2xN, where N is number of points 19522 // output vector should be 2xN, first element is the number of elements 19523 // associated with this point, second is 0 is the element is touching the border, 1 if it is interior 19524 vector<float> group(2*ny); 19525 for(int i=0; i<2*ny; i++) group[i] = 0.0f; 19526 int K = int(1.0f/step) +1; 19527 int hit = 0; 19528 for(int kx=0; kx<=K; kx++) { 19529 float tx = kx*step; 19530 for(int ky=0; ky<=K; ky++) { 19531 float ty = ky*step; 19532 float dm = 1.0e23f; 19533 for(int i=0; i<ny; i++) { 19534 float qd = pow(tx-(*d)(0,i),2) + pow(ty-(*d)(1,i),2); 19535 if( qd < dm) { 19536 dm = qd; 19537 hit = i; 19538 } 19539 } 19540 data(0,hit) += 1.0f; 19541 if(kx == 0 || ky == 0 || kx == K || ky == K) data(1,hit) = 1.0f; 19542 } 19543 } 19544 return group; 19545 }
void Util::voronoi | ( | double * | phi, | |
double * | theta, | |||
double * | weight, | |||
int | nt | |||
) | [static] |
Definition at line 7408 of file util_sparx.cpp.
References ang_to_xyz(), areav_(), Assert, disorder2(), ENTERFUNC, EXITFUNC, flip23(), key, status, trmsh3_(), and y.
07409 { 07410 07411 ENTERFUNC; 07412 07413 int *list, *lptr, *lend, *iwk, *key,*lcnt,*indx,*good; 07414 int nt6, n, ier, nout, lnew, mdup, nd; 07415 int i,k,mt,status; 07416 07417 07418 double *ds, *x, *y, *z; 07419 double tol = 1.0e-8; 07420 double dtol = 15; 07421 double a; 07422 07423 /*if(last){ 07424 if(medium>nt) n = nt+nt; 07425 else n = nt+nt-medium+1; 07426 } 07427 else{ 07428 n=nt; 07429 }*/ 07430 07431 n = nt + nt; 07432 07433 nt6 = n*6; 07434 07435 list = (int*)calloc(nt6,sizeof(int)); 07436 lptr = (int*)calloc(nt6,sizeof(int)); 07437 lend = (int*)calloc(n ,sizeof(int)); 07438 iwk = (int*)calloc(n ,sizeof(int)); 07439 good = (int*)calloc(n ,sizeof(int)); 07440 key = (int*)calloc(n ,sizeof(int)); 07441 indx = (int*)calloc(n ,sizeof(int)); 07442 lcnt = (int*)calloc(n ,sizeof(int)); 07443 07444 ds = (double*) calloc(n,sizeof(double)); 07445 x = (double*) calloc(n,sizeof(double)); 07446 y = (double*) calloc(n,sizeof(double)); 07447 z = (double*) calloc(n,sizeof(double)); 07448 07449 if (list == NULL || 07450 lptr == NULL || 07451 lend == NULL || 07452 iwk == NULL || 07453 good == NULL || 07454 key == NULL || 07455 indx == NULL || 07456 lcnt == NULL || 07457 x == NULL || 07458 y == NULL || 07459 z == NULL || 07460 ds == NULL) { 07461 printf("memory allocation failure!\n"); 07462 exit(1); 07463 } 07464 07465 bool colinear=true; 07466 while(colinear) 07467 { 07468 07469 L1: 07470 for(i = 0; i<nt; i++){ 07471 x[i] = theta[i]; 07472 y[i] = phi[i]; 07473 x[nt+i] = 180.0 - x[i]; 07474 y[nt+i] = 180.0 + y[i]; 07475 } 07476 07477 Util::disorder2(x, y, key, n); 07478 07479 // check if the first three angles are not close, else shuffle 07480 double val; 07481 for(k=0; k<2; k++){ 07482 for(i=k+1; i<3; i++){ 07483 val = (x[i]-x[k])*(x[i]-x[k]) + (y[i]-y[k])*(y[i]-y[k]); 07484 if( val < dtol) { 07485 goto L1; 07486 } 07487 } 07488 } 07489 07490 Util::ang_to_xyz(x, y, z, n); 07491 07492 // Make sure that first three has no duplication 07493 bool dupnode=true; 07494 dupnode=true; 07495 while(dupnode) 07496 { 07497 for(k=0; k<2; k++){ 07498 for(i=k+1; i<3; i++){ 07499 if( x[i]*x[k]+y[i]*y[k]+z[i]*z[k] > 1.0-tol) { 07500 Util::flip23(x, y, z, key, k, n); 07501 continue; 07502 } 07503 } 07504 } 07505 dupnode = false; 07506 } 07507 07508 07509 ier = 0; 07510 07511 status = Util::trmsh3_(&n,&tol,x,y,z,&nout,list,lptr,lend,&lnew, indx, lcnt, iwk, good, ds, &ier); 07512 07513 if (status != 0) { 07514 printf(" error in trmsh3 \n"); 07515 exit(1); 07516 } 07517 07518 if (ier > 0) { 07519 printf("*** Error in TRMESH: duplicate nodes encountered ***\n"); 07520 exit(1); 07521 } 07522 07523 mdup=n-nout; 07524 if (ier == -2) { 07525 //printf("in TRMESH:the first three nodes are colinear*** disorder again\n"); 07526 } 07527 else 07528 { 07529 colinear=false; 07530 } 07531 } 07532 07533 07534 Assert( ier != -2 ); 07535 // Create a list of unique nodes GOOD, the numbers refer to locations on the full list 07536 // INDX contains node numbers from the squeezed list 07537 nd=0; 07538 for (k=1; k<=n; k++){ 07539 if (indx[k-1]>0) { 07540 nd++; 07541 good[nd-1]=k; 07542 } 07543 } 07544 07545 // 07546 // *** Compute the Voronoi region areas. 07547 // 07548 for(i = 1; i<=nout; i++) { 07549 k=good[i-1]; 07550 // We only need n weights from hemisphere 07551 if (key[k-1] <= nt) { 07552 // CALCULATE THE AREA 07553 a = Util::areav_(&i, &nout, x, y, z, list, lptr, lend, &ier); 07554 if (ier != 0){ 07555 // We set the weight to -1, this will signal the error in the calling 07556 // program, as the area will turn out incorrect 07557 printf(" *** error in areav: ier = %d ***\n", ier); 07558 weight[key[k-1]-1] =-1.0; 07559 } else { 07560 // Assign the weight 07561 weight[key[k-1]-1]=a/lcnt[i-1]; 07562 } 07563 } 07564 } 07565 07566 07567 // Fill out the duplicated weights 07568 for(i = 1; i<=n; i++){ 07569 mt =- indx[i-1]; 07570 if (mt>0){ 07571 k = good[mt-1]; 07572 // This is a duplicated entry, get the already calculated 07573 // weight and assign it. 07574 // We only need n weights from hemisphere 07575 if (key[i-1] <= nt && key[k-1] <= nt) { weight[key[i-1]-1] = weight[key[k-1]-1];} 07576 } 07577 } 07578 07579 free(list); 07580 free(lend); 07581 free(iwk); 07582 free(good); 07583 free(key); 07584 free(lptr); 07585 free(indx); 07586 free(lcnt); 07587 free(ds); 07588 free(x); 07589 free(y); 07590 free(z); 07591 07592 07593 EXITFUNC; 07594 }
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 6985 of file util_sparx.cpp.
References ENTERFUNC, EXITFUNC, hsortd(), ImageFormatException, key, LOGERR, phi, theta, voronoi(), and weight.
06986 { 06987 06988 ENTERFUNC; 06989 06990 if ( th.size() != ph.size() ) { 06991 LOGERR("images not same size"); 06992 throw ImageFormatException( "images not same size"); 06993 } 06994 06995 // rand_seed 06996 srand(10); 06997 06998 int i,*key; 06999 int len = th.size(); 07000 double *theta,*phi,*weight; 07001 theta = (double*) calloc(len,sizeof(double)); 07002 phi = (double*) calloc(len,sizeof(double)); 07003 weight = (double*) calloc(len,sizeof(double)); 07004 key = (int*) calloc(len,sizeof(int)); 07005 const float *thptr, *phptr; 07006 07007 thptr = &th[0]; 07008 phptr = &ph[0]; 07009 for(i=1;i<=len;i++){ 07010 key(i) = i; 07011 weight(i) = 0.0; 07012 } 07013 07014 for(i = 0;i<len;i++){ 07015 theta[i] = thptr[i]; 07016 phi[i] = phptr[i]; 07017 } 07018 07019 // sort by theta 07020 Util::hsortd(theta, phi, key, len, 1); 07021 07022 //Util::voronoidiag(theta,phi, weight, len); 07023 Util::voronoi(phi, theta, weight, len); 07024 07025 //sort by key 07026 Util::hsortd(weight, weight, key, len, 2); 07027 07028 free(theta); 07029 free(phi); 07030 free(key); 07031 vector<double> wt; 07032 double count = 0; 07033 for(i=1; i<= len; i++) 07034 { 07035 wt.push_back(weight(i)); 07036 count += weight(i); 07037 } 07038 07039 //if( abs(count-6.28) > 0.1 ) 07040 //{ 07041 // printf("Warning: SUM OF VORONOI CELLS AREAS IS %lf, should 2*PI\n", count); 07042 //} 07043 07044 free(weight); 07045 07046 EXITFUNC; 07047 return wt; 07048 07049 }
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 5218 of file util_sparx.cpp.
References EMAN::EMData::copy_head(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, inp, NullPointerException, nx, ny, outp, EMAN::EMData::set_size(), and EMAN::EMData::update().
05219 { 05220 /* Exception Handle */ 05221 if (!img) throw NullPointerException("NULL input image"); 05222 /* ============================== */ 05223 05224 // Get the size of the input image 05225 int nx=img->get_xsize(), ny=img->get_ysize(), nz=img->get_zsize(); 05226 /* ============================== */ 05227 05228 /* Exception Handle */ 05229 if(new_nx>nx || new_ny>ny || new_nz>nz) 05230 throw ImageDimensionException("The size of the windowed image cannot exceed the input image size."); 05231 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) 05232 throw ImageDimensionException("The offset inconsistent with the input image size."); 05233 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)))) 05234 throw ImageDimensionException("The offset inconsistent with the input image size."); 05235 /* ============================== */ 05236 05237 /* Calculation of the start point */ 05238 int new_st_x = nx/2-new_nx/2 + x_offset, 05239 new_st_y = ny/2-new_ny/2 + y_offset, 05240 new_st_z = nz/2-new_nz/2 + z_offset; 05241 /* ============================== */ 05242 05243 /* Exception Handle */ 05244 if (new_st_x<0 || new_st_y<0 || new_st_z<0) // WHAT HAPPENS WITH THE END POINT CHECK?? PAP 05245 throw ImageDimensionException("The offset inconsistent with the input image size."); 05246 /* ============================== */ 05247 05248 EMData* wind = img->copy_head(); 05249 wind->set_size(new_nx, new_ny, new_nz); 05250 float *outp=wind->get_data(); 05251 float *inp=img->get_data(); 05252 05253 for (int k=0; k<new_nz; k++) 05254 for(int j=0; j<new_ny; j++) 05255 for(int i=0; i<new_nx; i++) 05256 outp(i,j,k) = inp(i,j,k); 05257 wind->update(); 05258 return wind; 05259 }
void Util::WTF | ( | EMData * | PROJ, | |
vector< float > | SS, | |||
float | SNR, | |||
int | K, | |||
vector< float > | exptable | |||
) | [static] |
Definition at line 5706 of file util_sparx.cpp.
References EMAN::EMData::get_data(), PROJ, SS, EMAN::EMData::update(), W, and Y.
05707 { 05708 int NSAM,NROW,NNNN,NR2,L,JY,KX,NANG; 05709 float WW,OX,OY,Y; 05710 05711 NSAM = PROJ->get_xsize(); 05712 NROW = PROJ->get_ysize(); 05713 NNNN = NSAM+2-(NSAM%2); 05714 NR2 = NROW/2; 05715 05716 NANG = int(SS.size())/6; 05717 05718 EMData* W = new EMData(); 05719 int Wnx = NNNN/2; 05720 W->set_size(Wnx,NROW,1); 05721 W->to_zero(); 05722 float *Wptr = W->get_data(); 05723 float *PROJptr = PROJ->get_data(); 05724 float indcnst = 1000/2.0; 05725 // we create look-up table for 1001 uniformly distributed samples [0,2]; 05726 05727 for (L=1; L<=NANG; L++) { 05728 OX = SS(6,K)*SS(4,L)*(-SS(1,L)*SS(2,K)+ SS(1,K)*SS(2,L)) + SS(5,K)*(-SS(3,L)*SS(4,K)+SS(3,K)*SS(4,L)*(SS(1,K)*SS(1,L) + SS(2,K)*SS(2,L))); 05729 OY = SS(5,K)*SS(4,L)*(-SS(1,L)*SS(2,K)+ SS(1,K)*SS(2,L)) - SS(6,K)*(-SS(3,L)*SS(4,K)+SS(3,K)*SS(4,L)*(SS(1,K)*SS(1,L) + SS(2,K)*SS(2,L))); 05730 05731 if(OX != 0.0f || OY!=0.0f) { 05732 //int count = 0; 05733 for(int J=1;J<=NROW;J++) { 05734 JY = (J-1); 05735 if(JY > NR2) JY=JY-NROW; 05736 for(int I=1;I<=NNNN/2;I++) { 05737 Y = fabs(OX * (I-1) + OY * JY); 05738 if(Y < 2.0f) W(I,J) += exptable[int(Y*indcnst)];//exp(-4*Y*Y);// 05739 //if(Y < 2.0f) Wptr[count++] += exp(-4*Y*Y);//exptable[int(Y*indcnst)];// 05740 } 05741 } 05742 } else { 05743 for(int J=1;J<=NROW;J++) for(int I=1;I<=NNNN/2;I++) W(I,J) += 1.0f; 05744 } 05745 } 05746 05747 EMData* proj_in = PROJ; 05748 05749 PROJ = PROJ->norm_pad( false, 2); 05750 PROJ->do_fft_inplace(); 05751 PROJ->update(); 05752 PROJptr = PROJ->get_data(); 05753 05754 float WNRMinv,temp; 05755 float osnr = 1.0f/SNR; 05756 WNRMinv = 1/W(1,1); 05757 for(int J=1;J<=NROW;J++) 05758 for(int I=1;I<=NNNN;I+=2) { 05759 KX = (I+1)/2; 05760 temp = W(KX,J)*WNRMinv; 05761 WW = temp/(temp*temp + osnr); 05762 PROJ(I,J) *= WW; 05763 PROJ(I+1,J) *= WW; 05764 } 05765 delete W; W = 0; 05766 PROJ->do_ift_inplace(); 05767 PROJ->depad(); 05768 05769 float* data_src = PROJ->get_data(); 05770 float* data_dst = proj_in->get_data(); 05771 05772 int ntotal = NSAM*NROW; 05773 for( int i=0; i < ntotal; ++i ) 05774 { 05775 data_dst[i] = data_src[i]; 05776 } 05777 05778 proj_in->update(); 05779 05780 delete PROJ; 05781 }
void Util::WTM | ( | EMData * | PROJ, | |
vector< float > | SS, | |||
int | DIAMETER, | |||
int | NUMP | |||
) | [static] |
Definition at line 5798 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.
05799 { 05800 float rad2deg =(180.0f/3.1415926f); 05801 float deg2rad = (3.1415926f/180.0f); 05802 05803 int NSAM,NROW,NNNN,NR2,NANG,L,JY; 05804 05805 NSAM = PROJ->get_xsize(); 05806 NROW = PROJ->get_ysize(); 05807 NNNN = NSAM+2-(NSAM%2); 05808 NR2 = NROW/2; 05809 NANG = int(SS.size())/6; 05810 05811 float RI[9]; 05812 RI(1,1)=SS(1,NUMP)*SS(3,NUMP)*SS(5,NUMP)-SS(2,NUMP)*SS(6,NUMP); 05813 RI(2,1)=-SS(1,NUMP)*SS(3,NUMP)*SS(6,NUMP)-SS(2,NUMP)*SS(5,NUMP); 05814 RI(3,1)=SS(1,NUMP)*SS(4,NUMP); 05815 RI(1,2)=SS(2,NUMP)*SS(3,NUMP)*SS(5,NUMP)+SS(1,NUMP)*SS(6,NUMP); 05816 RI(2,2)=-SS(2,NUMP)*SS(3,NUMP)*SS(6,NUMP)+SS(1,NUMP)*SS(5,NUMP); 05817 RI(3,2)=SS(2,NUMP)*SS(4,NUMP); 05818 RI(1,3)=-SS(4,NUMP)*SS(5,NUMP); 05819 RI(2,3)=SS(4,NUMP)*SS(6,NUMP); 05820 RI(3,3)=SS(3,NUMP); 05821 05822 float THICK=static_cast<float>( NSAM)/DIAMETER/2.0f ; 05823 05824 EMData* W = new EMData(); 05825 int Wnx = NNNN/2; 05826 W->set_size(NNNN/2,NROW,1); 05827 W->to_one(); 05828 float *Wptr = W->get_data(); 05829 05830 float ALPHA,TMP,FV,RT,FM,CCN,CC[3],CP[2],VP[2],VV[3]; 05831 05832 for (L=1; L<=NANG; L++) { 05833 if (L != NUMP) { 05834 CC(1)=SS(2,L)*SS(4,L)*SS(3,NUMP)-SS(3,L)*SS(2,NUMP)*SS(4,NUMP); 05835 CC(2)=SS(3,L)*SS(1,NUMP)*SS(4,NUMP)-SS(1,L)*SS(4,L)*SS(3,NUMP); 05836 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); 05837 05838 TMP = sqrt(CC(1)*CC(1) + CC(2)*CC(2) + CC(3)*CC(3)); 05839 CCN=static_cast<float>( AMAX1( AMIN1(TMP,1.0) ,-1.0) ); 05840 ALPHA=rad2deg*float(asin(CCN)); 05841 if (ALPHA>180.0f) ALPHA=ALPHA-180.0f; 05842 if (ALPHA>90.0f) ALPHA=180.0f-ALPHA; 05843 if(ALPHA<1.0E-6) { 05844 for(int J=1;J<=NROW;J++) for(int I=1;I<=NNNN/2;I++) W(I,J)+=1.0; 05845 } else { 05846 FM=THICK/(fabs(sin(ALPHA*deg2rad))); 05847 CC(1) = CC(1)/CCN;CC(2) = CC(2)/CCN;CC(3) = CC(3)/CCN; 05848 VV(1)= SS(2,L)*SS(4,L)*CC(3)-SS(3,L)*CC(2); 05849 VV(2)= SS(3,L)*CC(1)-SS(1,L)*SS(4,L)*CC(3); 05850 VV(3)= SS(1,L)*SS(4,L)*CC(2)-SS(2,L)*SS(4,L)*CC(1); 05851 CP(1) = 0.0;CP(2) = 0.0; 05852 VP(1) = 0.0;VP(2) = 0.0; 05853 05854 CP(1) = CP(1) + RI(1,1)*CC(1) + RI(1,2)*CC(2) + RI(1,3)*CC(3); 05855 CP(2) = CP(2) + RI(2,1)*CC(1) + RI(2,2)*CC(2) + RI(2,3)*CC(3); 05856 VP(1) = VP(1) + RI(1,1)*VV(1) + RI(1,2)*VV(2) + RI(1,3)*VV(3); 05857 VP(2) = VP(2) + RI(2,1)*VV(1) + RI(2,2)*VV(2) + RI(2,3)*VV(3); 05858 05859 TMP = CP(1)*VP(2)-CP(2)*VP(1); 05860 05861 // PREVENT TMP TO BE TOO SMALL, SIGN IS IRRELEVANT 05862 TMP = AMAX1(1.0E-4f,fabs(TMP)); 05863 float tmpinv = 1.0f/TMP; 05864 for(int J=1;J<=NROW;J++) { 05865 JY = (J-1); 05866 if (JY>NR2) JY=JY-NROW; 05867 for(int I=1;I<=NNNN/2;I++) { 05868 FV = fabs((JY*CP(1)-(I-1)*CP(2))*tmpinv); 05869 RT = 1.0f-FV/FM; 05870 W(I,J) += ((RT>0.0f)*RT); 05871 } 05872 } 05873 } 05874 } 05875 } 05876 05877 EMData* proj_in = PROJ; 05878 05879 PROJ = PROJ->norm_pad( false, 2); 05880 PROJ->do_fft_inplace(); 05881 PROJ->update(); 05882 float *PROJptr = PROJ->get_data(); 05883 05884 int KX; 05885 float WW; 05886 for(int J=1; J<=NROW; J++) 05887 for(int I=1; I<=NNNN; I+=2) { 05888 KX = (I+1)/2; 05889 WW = 1.0f/W(KX,J); 05890 PROJ(I,J) = PROJ(I,J)*WW; 05891 PROJ(I+1,J) = PROJ(I+1,J)*WW; 05892 } 05893 delete W; W = 0; 05894 PROJ->do_ift_inplace(); 05895 PROJ->depad(); 05896 05897 float* data_src = PROJ->get_data(); 05898 float* data_dst = proj_in->get_data(); 05899 05900 int ntotal = NSAM*NROW; 05901 for( int i=0; i < ntotal; ++i ) 05902 { 05903 data_dst[i] = data_src[i]; 05904 } 05905 05906 proj_in->update(); 05907 delete PROJ; 05908 }