#include <util.h>
Static Public Member Functions | |
int | coveig (int n, float *covmat, float *eigval, float *eigvec) |
This file is a part of util.h, To use this file's functions, you should include "util.h" NEVER directly include this file. | |
Dict | coveig_for_py (int ncov, const vector< float > &covmatpy) |
same function than Util::coveig but wrapped to use directly in python code | |
void | WTF (EMData *PROJ, vector< float > SS, float SNR, int K) |
void | WTM (EMData *PROJ, vector< float > SS, int DIAMETER, int NUMP) |
Dict | CANG (float PHI, float THETA, float PSI) |
void | BPCQ (EMData *B, EMData *CUBE, vector< float > DM) |
vector< float > | infomask (EMData *Vol, EMData *mask, bool) |
void | colreverse (float *beg, float *end, int nx) |
void | slicereverse (float *beg, float *end, int nx, int ny) |
void | cyclicshift (EMData *image, Dict params) |
Performs inplace integer cyclic shift as specified by the "dx","dy","dz" parameters on a 3d volume. | |
Dict | im_diff (EMData *V1, EMData *V2, EMData *mask=0) |
EMData * | TwoDTestFunc (int Size, float p, float q, float a, float b, int flag=0, float alphaDeg=0) |
Creates a Two D Test Pattern. | |
void | spline_mat (float *x, float *y, int n, float *xq, float *yq, int m) |
Given a tabulated function y of x (n unordered points), and Given the values of the m values xq to be interpolated This routine returns the interpolated array yq, PRB This function is called by splint. | |
void | spline (float *x, float *y, int n, float yp1, float ypn, float *y2) |
Given a tabulated function y of x (unordered), and Given the values of the first derivatives at the end points This routine returns an array y2, that contains the second derivatives of the function at the tabulated points. | |
void | splint (float *xa, float *ya, float *y2a, int n, float *xq, float *yq, int m) |
Given the arrays xa(ordered, ya of length n, which tabulate a function and given the array y2a which is the output of spline and an unordered array xq, this routine returns a cubic-spline interpolated array yq. | |
void | Radialize (int *PermMatTr, float *kValsSorted, float *weightofkvalsSorted, int Size, int *SizeReturned) |
list the sorted lengths of the integer lattice sites of a square sided image of size Size. | |
vector< float > | even_angles (float delta, float t1=0, float t2=90, float p1=0, float p2=359.999) |
Compute a vector containing quasi-evenly spaced Euler angles. | |
float | quadri (float x, float y, int nx, int ny, float *image) |
Quadratic interpolation (2D). | |
float | quadri_background (float x, float y, int nx, int ny, float *image, int xnew, int ynew) |
Quadratic interpolation (2D). | |
float | get_pixel_conv_new (int nx, int ny, int nz, float delx, float dely, float delz, float *data, Util::KaiserBessel &kb) |
float | get_pixel_conv_new_background (int nx, int ny, int nz, float delx, float dely, float delz, float *data, Util::KaiserBessel &kb, int xnew, int ynew) |
std::complex< float > | extractpoint2 (int nx, int ny, float nuxnew, float nuynew, EMData *fimage, Util::KaiserBessel &kb) |
float | bilinear (float xold, float yold, int nsam, int nrow, float *xim) |
float | triquad (float r, float s, float t, float *fdata) |
Quadratic interpolation (3D). | |
EMData * | Polar2D (EMData *image, vector< int > numr, string mode) |
EMData * | Polar2Dm (EMData *image, float cns2, float cnr2, vector< int > numr, string cmode) |
void | alrl_ms (float *xim, int nsam, int nrow, float cns2, float cnr2, int *numr, float *circ, int lcirc, int nring, char mode) |
EMData * | Polar2Dmi (EMData *image, float cns2, float cnr2, vector< int > numr, string cmode, Util::KaiserBessel &kb) |
void | fftr_q (float *xcmplx, int nv) |
void | fftr_d (double *xcmplx, int nv) |
void | fftc_q (float *br, float *bi, int ln, int ks) |
void | fftc_d (double *br, double *bi, int ln, int ks) |
void | Frngs (EMData *circ, vector< int > numr) |
This function conducts the Single Precision Fourier Transform for a set of rings. | |
void | Normalize_ring (EMData *ring, const vector< int > &numr) |
void | Frngs_inv (EMData *circ, vector< int > numr) |
This function conducts the Single Precision Inverse Fourier Transform for a set of rings. | |
Dict | Crosrng_e (EMData *circ1, EMData *circ2, vector< int > numr, int neg) |
Dict | Crosrng_ew (EMData *circ1, EMData *circ2, vector< int > numr, vector< float > w, int neg) |
Dict | Crosrng_ms (EMData *circ1, EMData *circ2, vector< int > numr) |
Dict | Crosrng_ms_delta (EMData *circ1, EMData *circ2, vector< int > numr, float delta_start, float delta) |
Dict | Crosrng_sm_psi (EMData *circ1, EMData *circ2, vector< int > numr, float psi, int flag) |
checks both straight & mirrored position input - fourier transforms of rings!! circ1 already multiplied by weights! | |
Dict | Crosrng_psi_0_180 (EMData *circ1, EMData *circ2, vector< int > numr, float psi_max) |
checks both straight & mirrored positions Find only positions within +/-pis_max of 0 and 180 (for helcal use) input - fourier transforms of rings! circ1 already multiplied by weights! | |
Dict | Crosrng_ns (EMData *circ1, EMData *circ2, vector< int > numr) |
EMData * | Crosrng_msg (EMData *circ1, EMData *circ2, vector< int > numr) |
checks both straight & mirrored positions input - fourier transforms of rings!! circ1 already multiplied by weights! returns EM object with 1D ccf | |
void | Crosrng_msg_vec (EMData *circ1, EMData *circ2, vector< int > numr, float *q, float *t) |
checks both straight & mirrored positions input - fourier transforms of rings!! circ1 already multiplied by weights! returns EM object with 1D ccf | |
EMData * | Crosrng_msg_s (EMData *circ1, EMData *circ2, vector< int > numr) |
This program is half of the Crosrng_msg. | |
EMData * | Crosrng_msg_m (EMData *circ1, EMData *circ2, vector< int > numr) |
This program is half of the Crosrng_msg. | |
vector< float > | Crosrng_msg_vec_p (EMData *circ1, EMData *circ2, vector< int > numr) |
void | prb1d (double *b, int npoint, float *pos) |
void | update_fav (EMData *ave, EMData *dat, float tot, int mirror, vector< int > numr) |
void | sub_fav (EMData *ave, EMData *dat, float tot, int mirror, vector< int > numr) |
float | ener (EMData *ave, vector< int > numr) |
float | ener_tot (const vector< EMData * > &data, vector< int > numr, vector< float > tot) |
Dict | min_dist_real (EMData *image, const vector< EMData * > &data) |
k-means helper | |
Dict | min_dist_four (EMData *image, const vector< EMData * > &data) |
helper function for k-means | |
int | k_means_cont_table_ (int *group1, int *group2, int *stb, long int s1, long int s2, int flag) |
helper to create the contengency table for partition matching (k-means) flag define is the list of stable obj must be store to stb, but the size st must be know before. | |
void | initial_prune (vector< vector< int * > > &Parts, int *dimClasses, int nParts, int K, int T) |
initial_prune removes all classes C from Parts where there does not exist ANY feasible matching containing class C which has weight gt T. | |
bool | explore (vector< vector< int * > > &Parts, int *dimClasses, int nParts, int K, int T, int partref, int *curintx, int size_curintx, int *next, int size_next, int depth) |
Each class in Parts has its dummy variable set to 0 or 1. | |
int | generatesubmax (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int n_guesses, int LARGEST_CLASS) |
make an intelligent "guess" at the largest weight of all possible feasible matches. | |
void | search2 (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int *matchlist, int *costlist, int J) |
return the weight of the largest weighted feasible match, along with the match in the (preallocated) argument curmax. | |
void | explore2 (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int *curintx, int size_curintx, int *next, int size_next, int depth, int J, int *matchlist, int *costlist, int *curbranch) |
bool | sanitycheck (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int *output) |
First element of output is total cost of the matches in the output Second element of output is the total number of matches in output So output has 2+(*(output+1))nParts elements. | |
vector< int > | bb_enumerateMPI_ (int *argParts, int *dimClasses, int nParts, int K, int T, int n_guesses, int LARGEST_CLASS, int J, int max_branching, float stmult, int branchfunc, int LIM) |
K is the number of classes in each partition (should be the same for all partitions) the first element of each class is its original index in the partition, and second is dummy var MPI: if nTop <= 0, then initial prune is called, and the pruned partitions are returned in a 1D array. | |
int * | branchMPI (int *argParts, int *Indices, int *dimClasses, int nParts, int K, int T, int curlevel, int n_guesses, int LARGEST_CLASS, int J, int max_branching, float stmult, int branchfunc, int LIM) |
same as branch except the nFirst (=Levels[0]) possibilites for the first match are already chosen firstmatches stores the matches and corresponding cost, where each match is preceded by its cost.... | |
int | branch_factor_2 (int *costlist, int *matchlist, int J, int T, int nParts, int curlevel, int max_branching, int LIM) |
int | branch_factor_3 (int *costlist, int *matchlist, int J, int T, int nParts, int curlevel, int max_branching, int K, int LIM) |
int | branch_factor_4 (int *costlist, int *matchlist, int J, int T, int nParts, int curlevel, int max_branching, float stmult) |
vector< double > | cml_weights (const vector< float > &cml) |
vector< int > | cml_line_insino (vector< float > Rot, int i_prj, int n_prj) |
2009-03-25 15:35:53 JB. | |
vector< int > | cml_line_insino_all (vector< float > Rot, vector< int > seq, int n_prj, int n_lines) |
2009-03-30 15:35:07 JB. | |
vector< double > | cml_init_rot (vector< float > Ori) |
2009-03-25 15:35:05 JB. | |
vector< float > | cml_update_rot (vector< float > Rot, int iprj, float nph, float th, float nps) |
2009-03-25 15:35:37 JB. | |
vector< double > | cml_line_in3d (vector< float > Ori, vector< int > seq, int nprj, int nlines) |
2009-03-26 10:46:14 JB. | |
vector< double > | cml_spin_psi (const vector< EMData * > &data, vector< int > com, vector< float > weights, int iprj, vector< int > iw, int n_psi, int d_psi, int n_prj) |
2009-03-26 11:37:53 JB. | |
double | cml_disc (const vector< EMData * > &data, vector< int > com, vector< int > seq, vector< float > weights, int n_lines) |
2009-03-30 15:44:05 JB. | |
void | set_line (EMData *img, int posline, EMData *line, int offset, int length) |
This function drop a line (line) to an 2D image (img). | |
void | cml_prepare_line (EMData *sino, EMData *line, int ilf, int ihf, int pos_line, int nblines) |
This function prepare the line from sinogram by cutting off some frequencies, and creating the mirror part (complexe conjugate of the first part). | |
EMData * | decimate (EMData *img, int x_step, int y_step=1, int z_step=1) |
EMData * | window (EMData *img, int new_nx, int new_ny=1, int new_nz=1, int x_offset=0, int y_offset=0, int z_offset=0) |
EMData * | pad (EMData *img, int new_nx, int new_ny=1, int new_nz=1, int x_offset=0, int y_offset=0, int z_offset=0, char *params="average") |
vector< float > | histogram (EMData *image, EMData *mask, int nbins=128, float hmin=0.0f, float hmax=0.0f) |
Dict | histc (EMData *ref, EMData *img, EMData *mask) |
float | hist_comp_freq (float PA, float PB, int size_img, int hist_len, EMData *img, vector< float > ref_freq_hist, EMData *mask, float ref_h_diff, float ref_h_min) |
float | tf (float dzz, float ak, float voltage=300.0f, float cs=2.0f, float wgh=0.1f, float b_factor=0.0f, float sign=-1.0f) |
EMData * | compress_image_mask (EMData *image, EMData *mask) |
EMData * | reconstitute_image_mask (EMData *image, EMData *mask) |
Recreates a n-d image using its compressed 1-D form and the mask. | |
vector< float > | merge_peaks (vector< float > peak1, vector< float > peak2, float p_size) |
vector< float > | pw_extract (vector< float >pw, int n, int iswi, float ps) |
vector< float > | call_cl1 (long int *k, long int *n, float *ps, long int *iswi, float *pw, float *q2, double *q, double *x, double *res, double *cu, double *s, long int *iu) |
vector< float > | lsfit (long int *ks, long int *n, long int *klm2d, long int *iswi, float *q1, double *q, double *x, double *res, double *cu, double *s, long int *iu) |
void | cl1 (long int *k, long int *l, long int *m, long int *n, long int *klm2d, double *q, double *x, double *res, double *cu, long int *iu, double *s) |
float | eval (char *images, EMData *img, vector< int > S, int N, int K, int size) |
vector< double > | vrdg (const vector< float > &ph, const vector< float > &th) |
void | hsortd (double *theta, double *phi, int *key, int len, int option) |
void | voronoidiag (double *theta, double *phi, double *weight, int n) |
void | voronoi (double *phi, double *theta, double *weight, int nt) |
void | disorder2 (double *x, double *y, int *key, int len) |
void | ang_to_xyz (double *x, double *y, double *z, int len) |
void | flip23 (double *x, double *y, double *z, int *key, int k, int len) |
bool | cmp1 (tmpstruct tmp1, tmpstruct tmp2) |
bool | cmp2 (tmpstruct tmp1, tmpstruct tmp2) |
int | trmsh3_ (int *n0, double *tol, double *x, double *y, double *z__, int *n, int *list, int *lptr, int *lend, int *lnew, int *indx, int *lcnt, int *near__, int *next, double *dist, int *ier) |
double | areav_ (int *k, int *n, double *x, double *y, double *z__, int *list, int *lptr, int *lend, int *ier) |
EMData * | madn_scalar (EMData *img, EMData *img1, float scalar) |
EMData * | mult_scalar (EMData *img, float scalar) |
EMData * | addn_img (EMData *img, EMData *img1) |
EMData * | subn_img (EMData *img, EMData *img1) |
EMData * | muln_img (EMData *img, EMData *img1) |
EMData * | divn_img (EMData *img, EMData *img1) |
EMData * | divn_filter (EMData *img, EMData *img1) |
void | mad_scalar (EMData *img, EMData *img1, float scalar) |
void | mul_scalar (EMData *img, float scalar) |
void | add_img (EMData *img, EMData *img1) |
void | add_img_abs (EMData *img, EMData *img1) |
void | add_img2 (EMData *img, EMData *img1) |
void | sub_img (EMData *img, EMData *img1) |
void | mul_img (EMData *img, EMData *img1) |
void | div_img (EMData *img, EMData *img1) |
void | div_filter (EMData *img, EMData *img1) |
EMData * | pack_complex_to_real (EMData *img) |
vector< float > | multiref_polar_ali_2d (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny) |
formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation | |
vector< float > | multiref_polar_ali_2d_peaklist (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny) |
vector< float > | multiref_polar_ali_2d_delta (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny, float delta_start, float delta) |
formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation | |
vector< float > | multiref_polar_ali_2d_nom (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny) |
formerly known as apnq DO NOT CONSIDER MIRROR Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation | |
vector< float > | multiref_polar_ali_2d_local (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, float ant, string mode, vector< int >numr, float cnx, float cny) |
formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation | |
vector< float > | multiref_polar_ali_helical (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, float psi_max, string mode, vector< int >numr, float cnx, float cny, int ynumber=-1) |
formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation Search for peaks only within +/-psi_max from 0 and 180 (helical) | |
vector< float > | multiref_polar_ali_2d_local_psi (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, float ant, float psi_max, string mode, vector< int >numr, float cnx, float cny) |
formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation | |
void | multiref_peaks_ali2d (EMData *image, EMData *crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny, EMData *peaks, EMData *peakm) |
Determine shift and rotation between image and one reference image (crefim, weights have to be applied) using quadratic interpolation, return a list of peaks PAP 07/21/08. | |
void | multiref_peaks_compress_ali2d (EMData *image, EMData *crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny, EMData *peaks, EMData *peakm, EMData *peaks_compress, EMData *peakm_compress) |
Determine shift and rotation between image and one reference image (crefim, weights have to be applied) using quadratic interpolation, return a list of peaks PAP 07/21/08. | |
vector< float > | ali2d_ccf_list (EMData *image, EMData *crefim, float xrng, float yrng, float step, string mode, vector< int >numr, float cnx, float cny, double T) |
Determine shift and rotation between image and one reference image (crefim, weights have to be applied) using quadratic interpolation. | |
vector< float > | twoD_fine_ali (EMData *image, EMData *refim, EMData *mask, float ang, float sxs, float sys) |
vector< float > | twoD_fine_ali_G (EMData *image, EMData *refim, EMData *mask, Util::KaiserBessel &kb, float ang, float sxs, float sys) |
vector< float > | twoD_to_3D_ali (EMData *volft, Util::KaiserBessel &kb, EMData *refim, EMData *mask, float phi, float theta, float psi, float sxs, float sxy) |
vector< float > | twoD_fine_ali_SD (EMData *image, EMData *refim, EMData *mask, float ang, float sxs, float sys) |
float | ccc_images (EMData *, EMData *, EMData *, float, float, float) |
vector< float > | twoD_fine_ali_SD_G (EMData *image, EMData *refim, EMData *mask, Util::KaiserBessel &kb, float ang, float sxs, float sys) |
float | ccc_images_G (EMData *image, EMData *refim, EMData *mask, Util::KaiserBessel &kb, float ang, float sx, float sy) |
EMData * | move_points (EMData *img, float qprob, int ri, int ro) |
EMData * | get_biggest_cluster (EMData *mg) |
EMData * | ctf_img (int nx, int ny, int nz, float dz, float ps, float voltage, float cs, float wgh, float b_factor, float dza, float azz, float sign) |
int | mono (int k1, int k2) |
int | nint180 (float arg) |
float | mean (float *x, int n) |
float | var (float *x, int n) |
void | rot_shift (float x, float y, float alpha, float x0, float y0, float *x1, float *y1) |
vector< float > | multi_align_error (vector< float > args, vector< float > all_ali_params) |
float | multi_align_error_func (double *x, vector< float > all_ali_params, int nima, int num_ali) |
void | multi_align_error_dfunc (double *x, vector< float > all_ali_params, int nima, int num_ali, double *g) |
vector< float > | cluster_pairwise (EMData *d, int K, float T, float F) |
vector< float > | cluster_equalsize (EMData *d) |
vector< float > | vareas (EMData *d) |
EMData * | get_slice (EMData *vol, int dim, int index) |
This function returns a 2-D slice from a 3-D EMData object dim denotes the slice is perpendicular to which dimension 1 for x-dimension, 2 for y-dimension and 3 for z-dimension. | |
void | image_mutation (EMData *img, float mutation_rate) |
void | array_mutation (float *list, int len_list, float mutation_rate, float min_val, float max_val, int K, int is_mirror) |
The purpose of this function is to convert a list to grey code and mutate them and convert them back. | |
vector< float > | list_mutation (vector< float > list, float mutation_rate, float min_val, float max_val, int K, int is_mirror) |
float | restrict1 (float x, int nx) |
void | ap2ri (float *data, size_t n) |
convert complex data array from Amplitude/Phase format into Real/Imaginary format. | |
void | flip_complex_phase (float *data, size_t n) |
flip the phase of a complex data array. | |
void | rotate_phase_origin (float *data, size_t nx, size_t ny, size_t nz) |
rotate data vertically by ny/2, to make the mrc phase origin compliance with EMAN1 and TNF reader | |
int | file_lock_wait (FILE *file) |
lock a file. | |
bool | check_file_by_magic (const void *first_block, const char *magic) |
check whether a file starts with certain magic string. | |
bool | is_file_exist (const string &filename) |
check whether a file exists or not | |
void | flip_image (float *data, size_t nx, size_t ny) |
Vertically flip the data of a 2D real image. | |
vector< EMData * > | svdcmp (const vector< EMData * > &data, int nvec) |
Perform singular value decomposition on a set of images. | |
string | str_to_lower (const string &s) |
Return a lower case version of the argument string. | |
bool | sstrncmp (const char *s1, const char *s2) |
Safe string compare. | |
string | int2str (int n) |
Get a string format of an integer, e.g. | |
string | get_line_from_string (char **str) |
Extract a single line from a multi-line string. | |
bool | get_str_float (const char *str, const char *float_var, float *p_val) |
Extract the float value from a variable=value string with format like "XYZ=1.1", where 'str' is "XYZ=1.1"; 'float_var' is "XYZ="; 'p_val' points to float number 1.1. | |
bool | get_str_float (const char *str, const char *float_var, float *p_v1, float *p_v2) |
Extract the float values from a variable=value1,value2 string with format like "XYZ=1.1,1.2", where 'str' is "XYZ=1.1,1.2"; 'float_var' is "XYZ="; 'p_v1' points to 1.1; 'p_v2' points to 1.2. | |
bool | get_str_float (const char *str, const char *float_var, int *p_nvalues, float *p_v1, float *p_v2) |
Extract number of values and the float values, if any, from a string whose format is either "variable=value1,value2 " or "variable". | |
bool | get_str_int (const char *str, const char *int_var, int *p_val) |
Extract the int value from a variable=value string with format like "XYZ=1", where 'str' is "XYZ=1"; 'int_var' is "XYZ="; 'p_val' points to float number 1. | |
bool | get_str_int (const char *str, const char *int_var, int *p_v1, int *p_v2) |
Extract the int value from a variable=value1,value2 string with format like "XYZ=1,2", where 'str' is "XYZ=1,2"; 'int_var' is "XYZ="; 'p_val' points to float number 1. | |
bool | get_str_int (const char *str, const char *int_var, int *p_nvalues, int *p_v1, int *p_v2) |
Extract number of values and the int values, if any, from a string whose format is either "variable=value1,value2 " or "variable". | |
string | change_filename_ext (const string &old_filename, const string &new_ext) |
Change a file's extension and return the new filename. | |
string | remove_filename_ext (const string &filename) |
Remove a filename's extension and return the new filename. | |
string | get_filename_ext (const string &filename) |
Get a filename's extension. | |
string | sbasename (const string &filename) |
Get a filename's basename. | |
void | calc_least_square_fit (size_t nitems, const float *data_x, const float *data_y, float *p_slope, float *p_intercept, bool ignore_zero, float absmax=0) |
calculate the least square fit value. | |
Vec3f | calc_bilinear_least_square (const vector< float > &points) |
calculate bilinear least-square fit, z = a + b x + c y Takes a set of x,y,z vectors and produces an a,b,c vector does not accept error bars on z or return goodness of fit | |
void | save_data (const vector< float > &x_array, const vector< float > &y_array, const string &filename) |
Save (x y) data array into a file. | |
void | save_data (float x0, float dx, const vector< float > &y_array, const string &filename) |
Save x, y data into a file. | |
void | save_data (float x0, float dx, float *y_array, size_t array_size, const string &filename) |
Save x, y data into a file. | |
void | sort_mat (float *left, float *right, int *leftPerm, int *rightPerm) |
does a sort as in Matlab. | |
unsigned long int | get_randnum_seed () |
Get the seed for Randnum class. | |
void | set_randnum_seed (unsigned long int seed) |
Set the seed for Randnum class. | |
int | get_irand (int low, int high) |
Get an integer random number between low and high, [low, high]. | |
float | get_frand (int low, int high) |
Get a float random number between low and high, [low, high). | |
float | get_frand (float low, float high) |
Get a float random number between low and high, [low, high). | |
float | get_frand (double low, double high) |
Get a float random number between low and high, [low, high). | |
float | get_gauss_rand (float mean, float sigma) |
Get a Gaussian random number. | |
int | round (float x) |
Get ceiling round of a float number x. | |
int | round (double x) |
Get ceiling round of a float number x. | |
float | linear_interpolate (float p1, float p2, float t) |
Calculate linear interpolation. | |
float | bilinear_interpolate (float p1, float p2, float p3, float p4, float t, float u) |
Calculate bilinear interpolation. | |
float | trilinear_interpolate (float p1, float p2, float p3, float p4, float p5, float p6, float p7, float p8, float t, float u, float v) |
Calculate trilinear interpolation. | |
void | find_max (const float *data, size_t nitems, float *p_max_val, int *p_max_index=0) |
Find the maximum value and (optional) its index in an array. | |
void | find_min_and_max (const float *data, size_t nitems, float *p_max_val, float *p_min_val, int *p_max_index=0, int *p_min_index=0) |
Find the maximum value and (optional) its index, minimum value and (optional) its index in an array. | |
Dict | get_stats (const vector< float > &data) |
Get the mean, standard deviation, skewness and kurtosis of the input data. | |
Dict | get_stats_cstyle (const vector< float > &data) |
Performs the same calculations as in get_stats, but uses a single pass, optimized c approach Should perform better than get_stats. | |
int | calc_best_fft_size (int low) |
Search the best FFT size with good primes. | |
EMData * | calc_bessel (const int n, const float &x) |
int | square (int n) |
Calculate a number's square. | |
float | square (float x) |
Calculate a number's square. | |
float | square (double x) |
Calculate a number's square. | |
float | square_sum (float x, float y) |
Calcuate (x*x + y*y). | |
float | hypot2 (float x, float y) |
Euclidean distance function in 2D: f(x,y) = sqrt(x*x + y*y);. | |
int | hypot3sq (int x, int y, int z) |
Euclidean distance function squared in 3D: f(x,y,z) = (x*x + y*y + z*z);. | |
float | hypot3sq (float x, float y, float z) |
Euclidean distance function squared in 3D: f(x,y,z) = (x*x + y*y + z*z);. | |
float | hypot3 (int x, int y, int z) |
Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);. | |
float | hypot3 (float x, float y, float z) |
Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);. | |
float | hypot3 (double x, double y, double z) |
Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);. | |
float | hypot_fast (int x, int y) |
Euclidean distance in 2D for integers computed fast using a cached lookup table. | |
short | hypot_fast_int (int x, int y) |
Euclidean distance in 2D for integers computed fast using a cached lookup table. | |
int | fast_floor (float x) |
A fast way to calculate a floor, which is largest integral value not greater than argument. | |
float | fast_exp (const float &f) |
Returns an approximate of exp(x) using a cached table uses actual exp(x) outside the cached range. | |
float | fast_acos (const float &f) |
Returns an approximate of acos(x) using a cached table and linear interpolation tolerates values very slightly outside the -1 - 1 range (returning 0). | |
float | agauss (float a, float dx, float dy, float dz, float d) |
Calculate Gaussian value. | |
int | get_min (int f1, int f2) |
Get the minimum of 2 numbers. | |
int | get_min (int f1, int f2, int f3) |
Get the minimum of 3 numbers. | |
float | get_min (float f1, float f2) |
Get the minimum of 2 numbers. | |
float | get_min (float f1, float f2, float f3) |
Get the minimum of 3 numbers. | |
float | get_min (float f1, float f2, float f3, float f4) |
Get the minimum of 4 numbers. | |
float | get_max (float f1, float f2) |
Get the maximum of 2 numbers. | |
float | get_max (float f1, float f2, float f3) |
Get the maximum of 3 numbers. | |
float | get_max (float f1, float f2, float f3, float f4) |
Get the maximum of 4 numbers. | |
float | angle_sub_2pi (float x, float y) |
Calculate the difference of 2 angles and makes the equivalent result to be less than Pi. | |
float | angle_sub_pi (float x, float y) |
Calculate the difference of 2 angles and makes the equivalent result to be less than Pi/2. | |
float | angle_err_ri (float r1, float i1, float r2, float i2) |
Calculate the angular phase difference between two r/i vectors. | |
int | goodf (const float *p_f) |
Check whether a number is a good float. | |
int | goodf (const double *p_f) |
string | recv_broadcast (int port) |
string | get_time_label () |
Get the current time in a string with format "mm/dd/yyyy hh:mm". | |
void | set_log_level (int argc, char *argv[]) |
Set program logging level through command line option "-v N", where N is the level. | |
float | eman_copysign (float a, float b) |
copy sign of a number. | |
float | eman_erfc (float x) |
complementary error function. | |
void | equation_of_plane (const Vec3f &p1, const Vec3f &p2, const Vec3f &p3, float *plane) |
Determine the equation of a plane that intersects 3 points in 3D space. | |
bool | point_is_in_convex_polygon_2d (const Vec2f &p1, const Vec2f &p2, const Vec2f &p3, const Vec2f &p4, const Vec2f &actual_point) |
Determines if a point is in a 2D convex polygon described by 4 points using the Barycentric method, which is a fast way of performing the query. | |
bool | point_is_in_triangle_2d (const Vec2f &p1, const Vec2f &p2, const Vec2f &p3, const Vec2f &actual_point) |
Determines if a point is in a 2D triangle using the Barycentric method, which is a fast way of performing the query Triangle points can be specified in any order. | |
void | printMatI3D (MIArray3D &mat, const string str=string(""), ostream &out=std::cout) |
Print a 3D integer matrix to a file stream (std out by default). | |
template<class T> | |
T | sgn (T &val) |
Sign function. | |
float * | getBaldwinGridWeights (const int &freq_cutoff, const float &P, const float &r, const float &dfreq=1, const float &alpha=0.5, const float &beta=0.2) |
bool | IsPower2 (int x) |
Return true if an integer is positive and is power of 2. | |
void | apply_precision (float &value, const float &precision) |
Static Private Member Functions | |
float | ang_n (float peakp, string mode, int maxrin) |
Definition at line 81 of file util.h.
|
Definition at line 17492 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, NullPointerException, nx, ny, and EMAN::EMData::update(). 17493 { 17494 ENTERFUNC; 17495 /* Exception Handle */ 17496 if (!img) { 17497 throw NullPointerException("NULL input image"); 17498 } 17499 /* ========= img += img1 ===================== */ 17500 17501 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17502 int size = nx*ny*nz; 17503 float *img_ptr = img->get_data(); 17504 float *img1_ptr = img1->get_data(); 17505 for (int i=0;i<size;i++) img_ptr[i] += img1_ptr[i]; 17506 img->update(); 17507 17508 EXITFUNC; 17509 }
|
|
Definition at line 17530 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, EMAN::EMData::is_complex(), NullPointerException, nx, ny, and EMAN::EMData::update(). 17531 { 17532 ENTERFUNC; 17533 /* Exception Handle */ 17534 if (!img) { 17535 throw NullPointerException("NULL input image"); 17536 } 17537 /* ========= img += img1**2 ===================== */ 17538 17539 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17540 int size = nx*ny*nz; 17541 float *img_ptr = img->get_data(); 17542 float *img1_ptr = img1->get_data(); 17543 if(img->is_complex()) { 17544 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] ; 17545 } else { 17546 for (int i=0;i<size;i++) img_ptr[i] += img1_ptr[i]*img1_ptr[i]; 17547 } 17548 img->update(); 17549 17550 EXITFUNC; 17551 }
|
|
Definition at line 17511 of file util_sparx.cpp. References abs, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, NullPointerException, nx, ny, and EMAN::EMData::update(). 17512 { 17513 ENTERFUNC; 17514 /* Exception Handle */ 17515 if (!img) { 17516 throw NullPointerException("NULL input image"); 17517 } 17518 /* ========= img += img1 ===================== */ 17519 17520 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17521 int size = nx*ny*nz; 17522 float *img_ptr = img->get_data(); 17523 float *img1_ptr = img1->get_data(); 17524 for (int i=0;i<size;i++) img_ptr[i] += abs(img1_ptr[i]); 17525 img->update(); 17526 17527 EXITFUNC; 17528 }
|
|
Definition at line 17309 of file util_sparx.cpp. References EMAN::EMData::copy_head(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img2_ptr, img_ptr, EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), NullPointerException, nx, ny, EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), and EMAN::EMData::update(). 17310 { 17311 ENTERFUNC; 17312 /* Exception Handle */ 17313 if (!img) { 17314 throw NullPointerException("NULL input image"); 17315 } 17316 /* ============== output = img + img1 ================ */ 17317 17318 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17319 int size = nx*ny*nz; 17320 EMData * img2 = img->copy_head(); 17321 float *img_ptr =img->get_data(); 17322 float *img2_ptr = img2->get_data(); 17323 float *img1_ptr = img1->get_data(); 17324 for (int i=0;i<size;i++) img2_ptr[i] = img_ptr[i] + img1_ptr[i]; 17325 img2->update(); 17326 if(img->is_complex()) { 17327 img2->set_complex(true); 17328 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17329 } 17330 17331 EXITFUNC; 17332 return img2; 17333 }
|
|
Calculate Gaussian value. a * exp(-(dx * dx + dy * dy + dz * dz) / d)
Definition at line 1708 of file util.h. Referenced by EMAN::FourierReconstructorSimple2D::insert_slice(), and EMAN::GaussFFTProjector::interp_ft_3d(). |
|
Determine shift and rotation between image and one reference image (crefim, weights have to be applied) using quadratic interpolation.
Definition at line 18473 of file util_sparx.cpp. References Crosrng_msg_vec(), Frngs(), get_frand(), ccf_point::i, ccf_point::j, ccf_point::k, ccf_point::mirror, numr, Polar2Dm(), t, and ccf_point::value. 18475 { 18476 18477 int maxrin = numr[numr.size()-1]; 18478 18479 int ky = int(2*yrng/step+0.5)/2; 18480 int kx = int(2*xrng/step+0.5)/2; 18481 18482 float *p_ccf1ds = (float *)malloc(maxrin*sizeof(float)); 18483 float *p_ccf1dm = (float *)malloc(maxrin*sizeof(float)); 18484 int vol = maxrin*(2*kx+1)*(2*ky+1); 18485 vector<ccf_point> ccf(2*vol); 18486 ccf_point temp; 18487 18488 int index = 0; 18489 for (int i = -ky; i <= ky; i++) { 18490 float iy = i * step; 18491 for (int j = -kx; j <= kx; j++) { 18492 float ix = j*step; 18493 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18494 Frngs(cimage, numr); 18495 Crosrng_msg_vec(crefim, cimage, numr, p_ccf1ds, p_ccf1dm); 18496 for (int k=0; k<maxrin; k++) { 18497 temp.value = p_ccf1ds[k]; 18498 temp.i = k; 18499 temp.j = j; 18500 temp.k = i; 18501 temp.mirror = 0; 18502 ccf[index] = temp; 18503 index++; 18504 temp.value = p_ccf1dm[k]; 18505 temp.mirror = 1; 18506 ccf[index] = temp; 18507 index++; 18508 } 18509 delete cimage; cimage = 0; 18510 } 18511 } 18512 18513 delete p_ccf1ds; 18514 delete p_ccf1dm; 18515 std::sort(ccf.begin(), ccf.end(), ccf_value()); 18516 18517 double qt = (double)ccf[0].value; 18518 vector <double> p(2*vol), cp(2*vol); 18519 18520 double sump = 0.0; 18521 for (int i=0; i<2*vol; i++) { 18522 p[i] = pow(double(ccf[i].value)/qt, 1.0/T); 18523 sump += p[i]; 18524 } 18525 for (int i=0; i<2*vol; i++) { 18526 p[i] /= sump; 18527 } 18528 for (int i=1; i<2*vol; i++) { 18529 p[i] += p[i-1]; 18530 } 18531 p[2*vol-1] = 2.0; 18532 18533 float t = get_frand(0.0f, 1.0f); 18534 int select = 0; 18535 while (p[select] < t) select += 1; 18536 18537 vector<float> a(6); 18538 a[0] = ccf[select].value; 18539 a[1] = (float)ccf[select].i; 18540 a[2] = (float)ccf[select].j; 18541 a[3] = (float)ccf[select].k; 18542 a[4] = (float)ccf[select].mirror; 18543 a[5] = (float)select; 18544 return a; 18545 }
|
|
Definition at line 2359 of file util_sparx.cpp. References circ, numr, quadri(), x, xim, and y. 02360 { 02361 double dpi, dfi; 02362 int it, jt, inr, l, nsim, kcirc, lt; 02363 float xold, yold, fi, x, y; 02364 02365 // cns2 and cnr2 are predefined centers 02366 // no need to set to zero, all elements are defined 02367 02368 dpi = 2*atan(1.0); 02369 for (it=1; it<=nring; it++) { 02370 // radius of the ring 02371 inr = numr(1,it); 02372 02373 l = numr(3,it); 02374 if ( mode == 'h' || mode == 'H' ) lt = l / 2; 02375 else lt = l / 4; 02376 02377 nsim = lt - 1; 02378 dfi = dpi / (nsim+1); 02379 kcirc = numr(2,it); 02380 02381 02382 xold = 0.0f+cns2; 02383 yold = inr+cnr2; 02384 02385 circ(kcirc) = quadri(xold,yold,nsam,nrow,xim); 02386 02387 xold = inr+cns2; 02388 yold = 0.0f+cnr2; 02389 circ(lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02390 02391 if ( mode == 'f' || mode == 'F' ) { 02392 xold = 0.0f+cns2; 02393 yold = -inr+cnr2; 02394 circ(lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02395 02396 xold = -inr+cns2; 02397 yold = 0.0f+cnr2; 02398 circ(lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02399 } 02400 02401 for (jt=1; jt<=nsim; jt++) { 02402 fi = static_cast<float>(dfi * jt); 02403 x = sin(fi) * inr; 02404 y = cos(fi) * inr; 02405 02406 xold = x+cns2; 02407 yold = y+cnr2; 02408 circ(jt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02409 02410 xold = y+cns2; 02411 yold = -x+cnr2; 02412 circ(jt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02413 02414 if ( mode == 'f' || mode == 'F' ) { 02415 xold = -x+cns2; 02416 yold = -y+cnr2; 02417 circ(jt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02418 02419 xold = -y+cns2; 02420 yold = x+cnr2; 02421 circ(jt+lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); 02422 } 02423 } // end for jt 02424 } //end for it 02425 }
|
|
Definition at line 17739 of file util_sparx.cpp. Referenced by multiref_polar_ali_2d(), multiref_polar_ali_2d_delta(), multiref_polar_ali_2d_local(), multiref_polar_ali_2d_local_psi(), multiref_polar_ali_2d_nom(), multiref_polar_ali_2d_peaklist(), and multiref_polar_ali_helical(). 17740 { 17741 if (mode == "f" || mode == "F") 17742 return fmodf(((peakp-1.0f) / maxrin+1.0f)*360.0f,360.0f); 17743 else 17744 return fmodf(((peakp-1.0f) / maxrin+1.0f)*180.0f,180.0f); 17745 }
|
|
Definition at line 7685 of file util_sparx.cpp. References dgr_to_rad, x, and y. 07686 { 07687 ENTERFUNC; 07688 double costheta,sintheta,cosphi,sinphi; 07689 for(int i = 0; i<len; i++) 07690 { 07691 cosphi = cos(y[i]*dgr_to_rad); 07692 sinphi = sin(y[i]*dgr_to_rad); 07693 if(fabs(x[i]-90.0)< 1.0e-5){ 07694 x[i] = cosphi; 07695 y[i] = sinphi; 07696 z[i] = 0.0; 07697 } 07698 else{ 07699 costheta = cos(x[i]*dgr_to_rad); 07700 sintheta = sin(x[i]*dgr_to_rad); 07701 x[i] = cosphi*sintheta; 07702 y[i] = sinphi*sintheta; 07703 z[i] = costheta; 07704 } 07705 } 07706 EXITFUNC; 07707 }
|
|
Calculate the angular phase difference between two r/i vectors.
Definition at line 1878 of file util.h. Referenced by EMAN::PhaseCmp::cmp(). |
|
Calculate the difference of 2 angles and makes the equivalent result to be less than Pi.
|
|
Calculate the difference of 2 angles and makes the equivalent result to be less than Pi/2.
|
|
convert complex data array from Amplitude/Phase format into Real/Imaginary format.
Definition at line 67 of file util.cpp. References Assert, data, and NullPointerException. 00068 { 00069 Assert(n > 0); 00070 00071 if (!data) { 00072 throw NullPointerException("pixel data array"); 00073 } 00074 00075 for (size_t i = 0; i < n; i += 2) { 00076 float f = data[i] * sin(data[i + 1]); 00077 data[i] = data[i] * cos(data[i + 1]); 00078 data[i + 1] = f; 00079 } 00080 }
|
|
Definition at line 2101 of file util.h. Referenced by EMAN::Transform::get_determinant(), EMAN::Transform::get_scale(), EMAN::Transform::get_scale_and_mirror(), EMAN::Transform::get_trans(), EMAN::Transform::is_identity(), and EMAN::Transform::set_scale(). |
|
Definition at line 8750 of file util_sparx.cpp. References areas_(), circum_(), ierr, x, and y. 08753 { 08754 /* Initialized data */ 08755 08756 static double amax = 6.28; 08757 08758 /* System generated locals */ 08759 double ret_val; 08760 08761 /* Local variables */ 08762 static double a, c0[3], c2[3], c3[3]; 08763 static int n1, n2, n3; 08764 static double v1[3], v2[3], v3[3]; 08765 static int lp, lpl, ierr; 08766 static double asum; 08767 extern double areas_(double *, double *, double *); 08768 static long int first; 08769 extern /* Subroutine */ int circum_(double *, double *, 08770 double *, double *, int *); 08771 08772 08773 /* *********************************************************** */ 08774 08775 /* Robert J. Renka */ 08776 /* Dept. of Computer Science */ 08777 /* Univ. of North Texas */ 08778 /* renka@cs.unt.edu */ 08779 /* 10/25/02 */ 08780 08781 /* Given a Delaunay triangulation and the index K of an */ 08782 /* interior node, this subroutine returns the (surface) area */ 08783 /* of the Voronoi region associated with node K. The Voronoi */ 08784 /* region is the polygon whose vertices are the circumcenters */ 08785 /* of the triangles that contain node K, where a triangle */ 08786 /* circumcenter is the point (unit vector) lying at the same */ 08787 /* angular distance from the three vertices and contained in */ 08788 /* the same hemisphere as the vertices. */ 08789 08790 08791 /* On input: */ 08792 08793 /* K = Nodal index in the range 1 to N. */ 08794 08795 /* N = Number of nodes in the triangulation. N > 3. */ 08796 08797 /* X,Y,Z = Arrays of length N containing the Cartesian */ 08798 /* coordinates of the nodes (unit vectors). */ 08799 08800 /* LIST,LPTR,LEND = Data structure defining the trian- */ 08801 /* gulation. Refer to Subroutine */ 08802 /* TRMESH. */ 08803 08804 /* Input parameters are not altered by this function. */ 08805 08806 /* On output: */ 08807 08808 /* AREAV = Area of Voronoi region K unless IER > 0, */ 08809 /* in which case AREAV = 0. */ 08810 08811 /* IER = Error indicator: */ 08812 /* IER = 0 if no errors were encountered. */ 08813 /* IER = 1 if K or N is outside its valid range */ 08814 /* on input. */ 08815 /* IER = 2 if K indexes a boundary node. */ 08816 /* IER = 3 if an error flag is returned by CIRCUM */ 08817 /* (null triangle). */ 08818 /* IER = 4 if AREAS returns a value greater than */ 08819 /* AMAX (defined below). */ 08820 08821 /* Modules required by AREAV: AREAS, CIRCUM */ 08822 08823 /* *********************************************************** */ 08824 08825 08826 /* Maximum valid triangle area is less than 2*Pi: */ 08827 08828 /* Parameter adjustments */ 08829 --lend; 08830 --z__; 08831 --y; 08832 --x; 08833 --list; 08834 --lptr; 08835 08836 /* Function Body */ 08837 08838 /* Test for invalid input. */ 08839 08840 if (*k < 1 || *k > *n || *n <= 3) { 08841 goto L11; 08842 } 08843 08844 /* Initialization: Set N3 to the last neighbor of N1 = K. */ 08845 /* FIRST = TRUE only for the first triangle. */ 08846 /* The Voronoi region area is accumulated in ASUM. */ 08847 08848 n1 = *k; 08849 v1[0] = x[n1]; 08850 v1[1] = y[n1]; 08851 v1[2] = z__[n1]; 08852 lpl = lend[n1]; 08853 n3 = list[lpl]; 08854 if (n3 < 0) { 08855 goto L12; 08856 } 08857 lp = lpl; 08858 first = TRUE_; 08859 asum = 0.; 08860 08861 /* Loop on triangles (N1,N2,N3) containing N1 = K. */ 08862 08863 L1: 08864 n2 = n3; 08865 lp = lptr[lp]; 08866 n3 = list[lp]; 08867 v2[0] = x[n2]; 08868 v2[1] = y[n2]; 08869 v2[2] = z__[n2]; 08870 v3[0] = x[n3]; 08871 v3[1] = y[n3]; 08872 v3[2] = z__[n3]; 08873 if (first) { 08874 08875 /* First triangle: compute the circumcenter C3 and save a */ 08876 /* copy in C0. */ 08877 08878 circum_(v1, v2, v3, c3, &ierr); 08879 if (ierr != 0) { 08880 goto L13; 08881 } 08882 c0[0] = c3[0]; 08883 c0[1] = c3[1]; 08884 c0[2] = c3[2]; 08885 first = FALSE_; 08886 } else { 08887 08888 /* Set C2 to C3, compute the new circumcenter C3, and compute */ 08889 /* the area A of triangle (V1,C2,C3). */ 08890 08891 c2[0] = c3[0]; 08892 c2[1] = c3[1]; 08893 c2[2] = c3[2]; 08894 circum_(v1, v2, v3, c3, &ierr); 08895 if (ierr != 0) { 08896 goto L13; 08897 } 08898 a = areas_(v1, c2, c3); 08899 if (a > amax) { 08900 goto L14; 08901 } 08902 asum += a; 08903 } 08904 08905 /* Bottom on loop on neighbors of K. */ 08906 08907 if (lp != lpl) { 08908 goto L1; 08909 } 08910 08911 /* Compute the area of triangle (V1,C3,C0). */ 08912 08913 a = areas_(v1, c3, c0); 08914 if (a > amax) { 08915 goto L14; 08916 } 08917 asum += a; 08918 08919 /* No error encountered. */ 08920 08921 *ier = 0; 08922 ret_val = asum; 08923 return ret_val; 08924 08925 /* Invalid input. */ 08926 08927 L11: 08928 *ier = 1; 08929 ret_val = 0.; 08930 return ret_val; 08931 08932 /* K indexes a boundary node. */ 08933 08934 L12: 08935 *ier = 2; 08936 ret_val = 0.; 08937 return ret_val; 08938 08939 /* Error in CIRCUM. */ 08940 08941 L13: 08942 *ier = 3; 08943 ret_val = 0.; 08944 return ret_val; 08945 08946 /* AREAS value larger than AMAX. */ 08947 08948 L14: 08949 *ier = 4; 08950 ret_val = 0.; 08951 return ret_val; 08952 } /* areav_ */
|
|
The purpose of this function is to convert a list to grey code and mutate them and convert them back.
Definition at line 20055 of file util_sparx.cpp. References t. Referenced by image_mutation(). 20055 { 20056 20057 if (is_mirror != 0) { 20058 for (int i=0; i<len_list; i++) { 20059 int r = rand()%10000; 20060 float f = r/10000.0f; 20061 if (f < mutation_rate) list[i] = 1-list[i]; 20062 } 20063 } else { 20064 map<int, vector<int> > graycode; 20065 map<vector<int>, int> rev_graycode; 20066 vector <int> gray; 20067 20068 int K=1; 20069 for (int i=0; i<L; i++) K*=2; 20070 20071 for (int k=0; k<K; k++) { 20072 int shift = 0; 20073 vector <int> gray; 20074 for (int i=L-1; i>-1; i--) { 20075 int t = ((k>>i)%2-shift)%2; 20076 gray.push_back(t); 20077 shift += t-2; 20078 } 20079 graycode[k] = gray; 20080 rev_graycode[gray] = k; 20081 } 20082 20083 float gap = (K-1)/(max_val-min_val); 20084 for (int i=0; i<len_list; i++) { 20085 float val = list[i]; 20086 if (val < min_val) { val = min_val; } 20087 else if (val > max_val) { val = max_val; } 20088 int k = int((val-min_val)*gap+0.5); 20089 vector<int> gray = graycode[k]; 20090 bool changed = false; 20091 for (vector<int>::iterator p=gray.begin(); p!=gray.end(); p++) { 20092 int r = rand()%10000; 20093 float f = r/10000.0f; 20094 if (f < mutation_rate) { 20095 *p = 1-*p; 20096 changed = true; 20097 } 20098 } 20099 if (changed) { 20100 k = rev_graycode[gray]; 20101 list[i] = k/gap+min_val; 20102 } 20103 } 20104 } 20105 20106 }
|
|
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 20474 of file util_sparx.cpp. References branchMPI(), initial_prune(), and sanitycheck(). 20475 { 20476 20477 20478 // 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 20479 // 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 20480 // Make a vector of nParts vectors of K int* each 20481 int* Indices = new int[nParts*K]; 20482 int ind_c = 0; 20483 for (int i=0; i < nParts; i++){ 20484 for(int j = 0; j < K; j++){ 20485 Indices[i*K + j] = ind_c; 20486 ind_c = ind_c + *(dimClasses+i*K + j); 20487 20488 } 20489 } 20490 20491 // do initial pruning on argParts and return the pruned partitions 20492 20493 // Make a vector of nParts vectors of K int* each 20494 vector <vector <int*> > Parts(nParts,vector<int*>(K)); 20495 ind_c = 0; 20496 int argParts_size=0; 20497 for (int i=0; i < nParts; i++){ 20498 for(int j = 0; j < K; j++){ 20499 Parts[i][j]=argParts + ind_c; 20500 ind_c = ind_c + *(dimClasses+i*K + j); 20501 argParts_size = argParts_size + *(dimClasses+i*K + j); 20502 20503 } 20504 } 20505 20506 // in the following we call initial_prune with Parts which is a vector. This is not the most 20507 // efficient since vector does not allow for direct addressing. But since initial_prune doesn't have very high complexity, and 20508 // 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..... 20509 20510 // comment out for testing 20511 Util::initial_prune(Parts, dimClasses, nParts, K,T); 20512 for(int i = 0; i < nParts; i++){ 20513 for(int j=0; j < K; j++){ 20514 *(argParts + Indices[i*K + j]+1) = -1; 20515 } 20516 } 20517 20518 int num_classes; 20519 int old_index; 20520 for(int i=0; i<nParts; i++){ 20521 num_classes = Parts[i].size();// number of classes in partition i after pruning 20522 for (int j=0; j < num_classes; j++){ 20523 old_index = *(Parts[i][j]); 20524 //cout << "old_index: " << old_index<<"\n"; 20525 *(argParts + Indices[i*K + old_index]+1) = 1; 20526 } 20527 } 20528 20529 20530 // if we're not doing mpi then keep going and call branchMPI and return the output 20531 //cout <<"begin partition matching\n"; 20532 //int* dummy(0); 20533 int* output = Util::branchMPI(argParts, Indices,dimClasses, nParts, K, T,0,n_guesses,LARGEST_CLASS, J, max_branching, stmult, 20534 branchfunc, LIM); 20535 20536 //cout<<"total cost: "<<*output<<"\n"; 20537 //cout<<"number of matches: "<<*(output+1)<<"\n"; 20538 // 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 20539 bool correct = Util::sanitycheck(argParts, Indices,dimClasses, nParts, K, T,output); 20540 20541 // something is wrong with output of branchMPI! 20542 if (correct < 1){ 20543 cout << "something is wrong with output of branchMPI!\n"; 20544 vector<int> ret(1); 20545 ret[0]=-1; 20546 return ret; 20547 } 20548 20549 // output is not nonsense, so now put it into a single dimension vector and return 20550 // 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 20551 // and the rest is the list of matches. output is one dimensional 20552 20553 int output_size = 2+ *(output+1) * nParts; 20554 vector<int> ret(output_size); 20555 for (int i = 0; i < output_size; i++){ 20556 ret[i]=*(output+i); 20557 } 20558 return ret; 20559 20560 }
|
|
Definition at line 2310 of file util_sparx.cpp. References xim. 02311 { 02312 /* 02313 c purpose: linear interpolation 02314 Optimized for speed, circular closer removed, checking of ranges removed 02315 */ 02316 float bilinear; 02317 int ixold, iyold; 02318 02319 /* 02320 float xdif, ydif, xrem, yrem; 02321 ixold = (int) floor(xold); 02322 iyold = (int) floor(yold); 02323 ydif = yold - iyold; 02324 yrem = 1.0f - ydif; 02325 02326 // May want to insert if? 02327 // IF ((IYOLD .GE. 1 .AND. IYOLD .LE. NROW-1) .AND. 02328 // & (IXOLD .GE. 1 .AND. IXOLD .LE. NSAM-1)) THEN 02329 //c INSIDE BOUNDARIES OF OUTPUT IMAGE 02330 xdif = xold - ixold; 02331 xrem = 1.0f- xdif; 02332 // RBUF(K) = YDIF*(BUF(NADDR+NSAM)*XREM 02333 // & +BUF(NADDR+NSAM+1)*XDIF) 02334 // & +YREM*(BUF(NADDR)*XREM + BUF(NADDR+1)*XDIF) 02335 bilinear = ydif*(xim(ixold,iyold+1)*xrem + xim(ixold+1,iyold+1)*xdif) + 02336 yrem*(xim(ixold,iyold)*xrem+xim(ixold+1,iyold)*xdif); 02337 02338 return bilinear; 02339 } 02340 */ 02341 float xdif, ydif; 02342 02343 ixold = (int) xold; 02344 iyold = (int) yold; 02345 ydif = yold - iyold; 02346 02347 // May want to insert it? 02348 // IF ((IYOLD .GE. 1 .AND. IYOLD .LE. NROW-1) .AND. 02349 // & (IXOLD .GE. 1 .AND. IXOLD .LE. NSAM-1)) THEN 02350 //c INSIDE BOUNDARIES OF OUTPUT IMAGE 02351 xdif = xold - ixold; 02352 bilinear = xim(ixold, iyold) + ydif* (xim(ixold, iyold+1) - xim(ixold, iyold)) + 02353 xdif* (xim(ixold+1, iyold) - xim(ixold, iyold) + 02354 ydif* (xim(ixold+1, iyold+1) - xim(ixold+1, iyold) - xim(ixold, iyold+1) + xim(ixold, iyold)) ); 02355 02356 return bilinear; 02357 }
|
|
Calculate bilinear interpolation.
Definition at line 1479 of file util.h. Referenced by EMAN::StandardProjector::project3d(), EMAN::EMData::sget_value_at_interp(), and EMAN::TransformProcessor::transform(). |
|
Definition at line 5643 of file util_sparx.cpp. References B, CUBE, DM, EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::Transform::get_params(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), and t. 05644 { 05645 05646 float *Bptr = B->get_data(); 05647 float *CUBEptr = CUBE->get_data(); 05648 05649 int NSAM,NROW,NX3D,NY3D,NZC,KZ,IQX,IQY,LDPX,LDPY,LDPZ,LDPNMX,LDPNMY,NZ1; 05650 float DIPX,DIPY,XB,YB,XBB,YBB; 05651 05652 Transform * t = B->get_attr("xform.projection"); 05653 Dict d = t->get_params("spider"); 05654 if(t) {delete t; t=0;} 05655 // Unsure about sign of shifts, check later PAP 06/28/09 05656 float x_shift = d[ "tx" ]; 05657 float y_shift = d[ "ty" ]; 05658 x_shift = -x_shift; 05659 y_shift = -y_shift; 05660 05661 NSAM = B->get_xsize(); 05662 NROW = B->get_ysize(); 05663 NX3D = CUBE->get_xsize(); 05664 NY3D = CUBE->get_ysize(); 05665 NZC = CUBE->get_zsize(); 05666 05667 05668 LDPX = NX3D/2 +1; 05669 LDPY = NY3D/2 +1; 05670 LDPZ = NZC/2 +1; 05671 LDPNMX = NSAM/2 +1; 05672 LDPNMY = NROW/2 +1; 05673 NZ1 = 1; 05674 05675 for(int K=1;K<=NZC;K++) { 05676 KZ=K-1+NZ1; 05677 for(int J=1;J<=NY3D;J++) { 05678 XBB = (1-LDPX)*DM(1)+(J-LDPY)*DM(2)+(KZ-LDPZ)*DM(3); 05679 YBB = (1-LDPX)*DM(4)+(J-LDPY)*DM(5)+(KZ-LDPZ)*DM(6); 05680 for(int I=1;I<=NX3D;I++) { 05681 XB = (I-1)*DM(1)+XBB-x_shift; 05682 IQX = int(XB+float(LDPNMX)); 05683 if (IQX <1 || IQX >= NSAM) continue; 05684 YB = (I-1)*DM(4)+YBB-y_shift; 05685 IQY = int(YB+float(LDPNMY)); 05686 if (IQY<1 || IQY>=NROW) continue; 05687 DIPX = XB+LDPNMX-IQX; 05688 DIPY = YB+LDPNMY-IQY; 05689 05690 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))); 05691 } 05692 } 05693 } 05694 }
|
|
Definition at line 20730 of file util_sparx.cpp. References B, branch_all, and costlist_global. Referenced by branchMPI(). 20730 { 20731 20732 int ntot=0; 20733 for (int jit=0; jit < J; jit++){ 20734 if (*(costlist+jit) > T) ntot++; 20735 } 20736 20737 int cur; 20738 // sort matchlist by cost 20739 int* indx = new int[J]; 20740 for (int jit=0; jit < J; jit++) indx[jit]=jit; 20741 vector<int> myindx (indx, indx+J); 20742 vector<int>::iterator it; 20743 costlist_global=costlist; 20744 sort(myindx.begin(), myindx.begin()+J, jiafunc); 20745 20746 // put matchlist in the order of mycost 20747 int* templist = new int[J]; 20748 int* temp2list = new int[J*nParts]; 20749 int next = 0; 20750 20751 for (it=myindx.begin(); it!=myindx.end();++it){ 20752 cur = *(costlist + *it); 20753 if (cur > T){ 20754 20755 templist[next] = cur; 20756 for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt]; 20757 next = next + 1; 20758 } 20759 } 20760 20761 for (int jit=0; jit < ntot; jit++){ 20762 *(costlist+jit)=*(templist + jit); 20763 //cout <<*(costlist+jit)<<", "; 20764 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit]; 20765 } 20766 //cout <<"\n"; 20767 20768 delete [] indx; 20769 //compute the average 20770 20771 // partition matches into groups where matches in each group is mutually feasible, and matches from different groups are not feasible 20772 // The number of branches to explore are the mutually exclusive matches. Take the largest of these 20773 20774 20775 int B=1; 20776 int B_init=B; 20777 int infeasible=0; 20778 20779 for (int i=B_init; i<ntot; i++){ 20780 if (i==ntot) continue; 20781 // look at the i-th match. branch on it only if it is infeasible with ALL previous matches we have decided to 20782 // branch on 20783 infeasible = 0; 20784 if (LIM < 0) LIM = B; 20785 for (int j=0; j<B; j++){ 20786 20787 for (int vit=0; vit<nParts; vit++){ 20788 if (temp2list[i*nParts+vit] == matchlist[j*nParts+vit]) {infeasible++; break;} 20789 } 20790 if (infeasible >= LIM) break; 20791 } 20792 20793 if (infeasible >= LIM){ 20794 *(costlist+B)=*(templist+i); 20795 for (int vit=0; vit < nParts; vit++) 20796 *(matchlist+B*nParts + vit)=*(temp2list+i*nParts + vit); 20797 B=B+1; 20798 } 20799 } 20800 20801 delete [] templist; 20802 delete [] temp2list; 20803 //cout<<"**************************************** "<<B<<" ***************************\n"; 20804 20805 if (branch_all < max_branching){ 20806 if (B>1) 20807 {branch_all = branch_all + B -1 ; } 20808 } 20809 else B=1; 20810 20811 return B; 20812 20813 20814 }
|
|
Definition at line 20818 of file util_sparx.cpp. References B, branch_all, and costlist_global. Referenced by branchMPI(). 20818 { 20819 20820 int ntot=0; 20821 for (int jit=0; jit < J; jit++){ 20822 if (*(costlist+jit) > T) ntot++; 20823 } 20824 20825 int cur; 20826 // sort matchlist by cost 20827 int* indx = new int[J]; 20828 for (int jit=0; jit < J; jit++) indx[jit]=jit; 20829 vector<int> myindx (indx, indx+J); 20830 vector<int>::iterator it; 20831 costlist_global=costlist; 20832 sort(myindx.begin(), myindx.begin()+J, jiafunc); 20833 20834 // put matchlist in the order of mycost 20835 int* templist = new int[J]; 20836 int* temp2list = new int[J*nParts]; 20837 int next = 0; 20838 20839 for (it=myindx.begin(); it!=myindx.end();++it){ 20840 cur = *(costlist + *it); 20841 if (cur > T){ 20842 20843 templist[next] = cur; 20844 for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt]; 20845 next = next + 1; 20846 } 20847 } 20848 20849 for (int jit=0; jit < ntot; jit++){ 20850 *(costlist+jit)=*(templist + jit); 20851 //cout <<*(costlist+jit)<<", "; 20852 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit]; 20853 } 20854 //cout <<"\n"; 20855 20856 delete [] indx; 20857 //compute the average 20858 20859 // partition matches into groups where matches in each group is mutually feasible, and matches from different groups are not feasible 20860 // The number of branches to explore are the mutually exclusive matches. Take the largest of these 20861 20862 20863 int B=1; 20864 int B_init=B; 20865 int infeasible=0; 20866 // if we're near the bottom of the tree then explore more... this is because the larger weights are not likely to change much, 20867 // whereas the smaller ones can have many permutations 20868 if (LIM < 0) LIM = ntot-1; 20869 for (int i=B_init; i<ntot; i++){ 20870 if (i==ntot) continue; 20871 // look at the i-th match. branch on it only if it is infeasible with ALL previous matches we have decided to 20872 // branch on 20873 infeasible = 0; 20874 20875 for (int j=0; j<ntot; j++){ 20876 if (j == i) continue; 20877 for (int vit=0; vit<nParts; vit++){ 20878 if (temp2list[i*nParts+vit] == temp2list[j*nParts+vit]) {infeasible++; break;} 20879 } 20880 if (infeasible >= LIM) break; 20881 } 20882 20883 if (infeasible >= LIM){ 20884 *(costlist+B)=*(templist+i); 20885 for (int vit=0; vit < nParts; vit++) 20886 *(matchlist+B*nParts + vit)=*(temp2list+i*nParts + vit); 20887 B=B+1; 20888 } 20889 } 20890 20891 delete [] templist; 20892 delete [] temp2list; 20893 //cout<<"**************************************** "<<B<<" ***************************\n"; 20894 20895 20896 if (branch_all < max_branching){ 20897 if (B>1) 20898 {branch_all = branch_all + B-1;} 20899 } 20900 else B=1; 20901 20902 return B; 20903 20904 20905 }
|
|
Definition at line 20911 of file util_sparx.cpp. References B, branch_all, and costlist_global. Referenced by branchMPI(). 20911 { 20912 int sum=0; 20913 float average =0; 20914 int ntot=0; 20915 for (int jit=0; jit < J; jit++){ 20916 if (*(costlist+jit) > T) {ntot++; sum = sum +*(costlist+jit);} 20917 } 20918 average = ((float)sum)/((float)ntot); 20919 int cur; 20920 // sort matchlist by cost 20921 int* indx = new int[J]; 20922 for (int jit=0; jit < J; jit++) indx[jit]=jit; 20923 vector<int> myindx (indx, indx+J); 20924 vector<int>::iterator it; 20925 costlist_global=costlist; 20926 sort(myindx.begin(), myindx.begin()+J, jiafunc); 20927 20928 // put matchlist in the order of mycost 20929 int* templist = new int[J]; 20930 int* temp2list = new int[J*nParts]; 20931 int next = 0; 20932 20933 for (it=myindx.begin(); it!=myindx.end();++it){ 20934 cur = *(costlist + *it); 20935 if (cur > T){ 20936 20937 templist[next] = cur; 20938 for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt]; 20939 next = next + 1; 20940 } 20941 } 20942 20943 for (int jit=0; jit < ntot; jit++){ 20944 *(costlist+jit)=*(templist + jit); 20945 //cout <<*(costlist+jit)<<", "; 20946 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit]; 20947 } 20948 //cout <<"\n"; 20949 20950 delete [] indx; 20951 delete [] templist; 20952 delete [] temp2list; 20953 20954 if (ntot == 1) return 1; 20955 20956 // look at the average, standard dev etc. If standard dev very small, i.e., costs very similar, then branch on the similar 20957 // costs 20958 float sq_sum=0.0; 20959 //cout <<"costlist:"; 20960 for (int i=0; i< ntot; i++){ 20961 sq_sum = sq_sum + (float) pow((float) *(costlist+i) - average, (float)2.0); 20962 //cout <<*(costlist+i)<<", "; 20963 } 20964 //cout <<"\n"; 20965 20966 float variance = sq_sum/ntot; 20967 float stdev = (float)pow((float)variance,(float)0.5); 20968 20969 //cout <<"stdev: "<<int(stdev)<<"\n"; 20970 20971 int B=1; 20972 int largest = *costlist; 20973 //cout <<"largest: "<<largest<<"\n"; 20974 for (int i=1; i<ntot; i++){ 20975 int cur = *(costlist+i); 20976 if (largest-cur < (float)(stdev*stmult)) B++; 20977 else break; 20978 20979 } 20980 //cout <<"B: "<<B<<"\n"; 20981 if (branch_all < max_branching){ 20982 if (B>1) 20983 {branch_all = branch_all + B-1;} 20984 } 20985 else B=1; 20986 20987 return B; 20988 20989 20990 }
|
|
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 20564 of file util_sparx.cpp. References branch_all, branch_factor_2(), branch_factor_3(), branch_factor_4(), branchMPI(), and search2(). 20565 { 20566 20567 //************************************* 20568 //testing search2 20569 if (1 == 0){ 20570 cout <<"begin test search2\n"; 20571 int* matchlist = new int[J*nParts]; 20572 int* costlist = new int[J]; 20573 for (int jit = 0; jit < nParts; jit++) *(costlist+jit) = 0; 20574 Util::search2(argParts,Indices, dimClasses, nParts, K, T, matchlist,costlist,J); 20575 20576 for (int jit = 0; jit < J; jit++) { 20577 cout << *(costlist +jit)<<": "; 20578 for (int yit = 0; yit < nParts; yit++) 20579 cout << *(matchlist + jit*nParts + yit)<<","; 20580 cout <<"\n"; 20581 20582 } 20583 cout <<"end test search2\n"; 20584 int* ret = new int[1]; 20585 *ret=1; 20586 delete [] matchlist; 20587 delete [] costlist; 20588 return ret; 20589 } 20590 //************************************** 20591 20592 // Base Case: we're at a leaf, no more feasible matches possible 20593 if (curlevel > K -1){ 20594 int* res = new int[2]; 20595 *res = 0; 20596 *(res+1)=0; 20597 return res; 20598 } 20599 20600 // branch dynamically depending on results of search 2! 20601 20602 int* matchlist = new int[J*nParts]; 20603 int* costlist = new int[J]; 20604 Util::search2(argParts,Indices, dimClasses, nParts, K, T, matchlist,costlist,J); 20605 20606 20607 // each class in the matches found by findTopLargest is encoded by the original index of the first element of the class in argPart 20608 // each match contains nParts classes, with the i-th class belonging to the i-th partition. 20609 20610 // if there are no feasible matches with cost gt T, then return 0 20611 for (int jit = 0; jit < J ; jit++){ 20612 20613 if (costlist[jit] > T) break; 20614 if (jit == J-1){ 20615 int* res = new int[2]; 20616 *res = 0; 20617 *(res+1)=0; 20618 return res; 20619 } 20620 } 20621 20622 20623 20624 // note that costlist and matchlist are NOT sorted by weight, and branch factor takes care of that... 20625 if (curlevel==0) branch_all = 0; 20626 int* newcostlist; 20627 int* newmatchlist; 20628 20629 int nBranches = -1; 20630 20631 if (branchfunc == 2) 20632 nBranches = branch_factor_2(costlist,matchlist,J, T, nParts, curlevel, max_branching, LIM); // branch based on distribution of top J (weighted) matches with cost > T 20633 20634 if (branchfunc == 3) 20635 nBranches = branch_factor_3(costlist,matchlist,J, T, nParts, curlevel, max_branching, K, LIM); // branch based on distribution of top J (weighted) matches with cost > T 20636 20637 if (branchfunc == 4) 20638 nBranches = branch_factor_4(costlist,matchlist,J, T, nParts, curlevel, max_branching, stmult); // branch based on distribution of top J (weighted) matches with cost > T 20639 20640 newcostlist= new int[nBranches]; 20641 newmatchlist = new int[nBranches*nParts]; 20642 for (int i=0; i<nBranches; i++){ 20643 *(newcostlist + i) = *(costlist+i); 20644 for (int j=0; j< nParts; j++) 20645 *(newmatchlist + i*nParts + j) = *(matchlist + i*nParts+j); 20646 } 20647 20648 delete[] costlist; 20649 delete[] matchlist; 20650 20651 int* maxreturn = new int[2];//initialize to placeholder 20652 *maxreturn=0; 20653 *(maxreturn+1)=0; 20654 // some temporary variables 20655 int old_index; 20656 int totalcost; 20657 int nmatches; 20658 //int offset; 20659 20660 for(int i=0; i < nBranches ; i++){ 20661 20662 // consider the i-th match returned by findTopLargest 20663 //if (newcostlist[i] <= T) continue; 20664 20665 // 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. 20666 // After branch returns, compute overall cost, unmark the classes just marked as 1 again in preparation for next loop. 20667 20668 for(int j=0; j < nParts; j++){ 20669 // matchlist[i*nParts + j] is the original index of the class belonging to the j-th partition in the i-th match. 20670 old_index=newmatchlist[i*nParts + j]; 20671 *(argParts + Indices[j*K+old_index] + 1) = -2; 20672 } 20673 20674 20675 int* ret = Util::branchMPI(argParts, Indices, dimClasses, nParts, K, T,curlevel+1,n_guesses, LARGEST_CLASS, 20676 J,max_branching, stmult,branchfunc, LIM); 20677 20678 // first element of ret is the total cost of all the matches in ret, and second element is the number of matches in ret 20679 totalcost = newcostlist[i] + *ret; 20680 20681 //if (curlevel == 0) { 20682 // cout <<"totalcost*****************************************************************: "<<totalcost<<", costlist["<<i<<"]="<<newcostlist[i]<<", *ret="<<*ret<<", level: "<<curlevel<<"\n"; 20683 20684 //} 20685 if (totalcost > *maxreturn) // option 1 20686 { 20687 nmatches = 1 + *(ret+1); 20688 delete[] maxreturn; // get rid of the old maxreturn 20689 maxreturn = new int[2+nmatches*nParts]; 20690 *maxreturn = totalcost; 20691 20692 *(maxreturn + 1)= nmatches; 20693 int nret = 2+(nmatches-1)*nParts; 20694 for(int iret=2; iret <nret;iret++) *(maxreturn+iret)=*(ret+iret); 20695 for(int imax=0; imax<nParts;imax++) *(maxreturn+nret+imax)=newmatchlist[i*nParts + imax]; 20696 } 20697 20698 20699 delete[] ret; 20700 20701 // unmark the marked classes in preparation for the next iteration 20702 20703 for(int j=0; j < nParts; j++){ 20704 old_index=newmatchlist[i*nParts + j]; 20705 *(argParts + Indices[j*K+old_index] + 1) = 1; 20706 } 20707 20708 } 20709 20710 delete[] newmatchlist; 20711 delete[] newcostlist; 20712 20713 return maxreturn; 20714 20715 }
|
|
|
|
Search the best FFT size with good primes. It supports FFT size up to 4096 now.
Definition at line 984 of file util.cpp. References Assert, and LOGERR. Referenced by EMAN::RTFExhaustiveAligner::align(), and EMAN::RotatePrecenterAligner::align(). 00985 { 00986 Assert(low >= 0); 00987 00988 //array containing valid sizes <1024 for speed 00989 static char *valid = NULL; 00990 00991 if (!valid) { 00992 valid = (char *) calloc(4096, 1); 00993 00994 for (float i2 = 1; i2 < 12.0; i2 += 1.0) { 00995 00996 float f1 = pow((float) 2.0, i2); 00997 for (float i3 = 0; i3 < 8.0; i3 += 1.0) { 00998 00999 float f2 = pow((float) 3.0, i3); 01000 for (float i5 = 0; i5 < 6.0; i5 += 1.0) { 01001 01002 float f3 = pow((float) 5.0, i5); 01003 for (float i7 = 0; i7 < 5.0; i7 += 1.0) { 01004 01005 float f = f1 * f2 * f3 * pow((float) 7.0, i7); 01006 if (f <= 4095.0) { 01007 int n = (int) f; 01008 valid[n] = 1; 01009 } 01010 } 01011 } 01012 } 01013 } 01014 } 01015 01016 for (int i = low; i < 4096; i++) { 01017 if (valid[i]) { 01018 return i; 01019 } 01020 } 01021 01022 LOGERR("Sorry, can only find good fft sizes up to 4096 right now."); 01023 01024 return 1; 01025 }
|
|
calculate bilinear least-square fit, z = a + b x + c y Takes a set of x,y,z vectors and produces an a,b,c vector does not accept error bars on z or return goodness of fit
Definition at line 548 of file util.cpp. References EMAN::Vec3f. Referenced by EMAN::PointArray::align_2d(). 00548 { 00549 unsigned int i; 00550 00551 // various sums used in the final solution 00552 double Sx=0,Sy=0,Sxy=0,Sxx=0,Syy=0,Sz=0,Sxz=0,Syz=0,S=0; 00553 for (i=0; i<p.size(); i+=3) { 00554 Sx+=p[i]; 00555 Sy+=p[i+1]; 00556 Sz+=p[i+2]; 00557 Sxx+=p[i]*p[i]; 00558 Syy+=p[i+1]*p[i+1]; 00559 Sxy+=p[i]*p[i+1]; 00560 S+=1.0; 00561 Sxz+=p[i]*p[i+2]; 00562 Syz+=p[i+1]*p[i+2]; 00563 } 00564 double d=S*Sxy*Sxy - 2*Sx*Sxy*Sy + Sxx*Sy*Sy + Sx*Sx*Syy - S*Sxx*Syy; 00565 00566 Vec3f ret(0,0,0); 00567 00568 ret[0]=static_cast<float>(-((Sxy*Sxz*Sy - Sx*Sxz*Syy + Sx*Sxy*Syz - Sxx*Sy*Syz - Sxy*Sxy*Sz +Sxx*Syy*Sz)/d)); 00569 ret[1]=static_cast<float>(-((-Sxz*Sy*Sy + S*Sxz*Syy - S*Sxy*Syz + Sx*Sy*Syz + Sxy*Sy*Sz -Sx*Syy*Sz) /d)); 00570 ret[2]=static_cast<float>(-((-S*Sxy*Sxz + Sx*Sxz*Sy - Sx*Sx*Syz + S*Sxx*Syz + Sx*Sxy*Sz -Sxx*Sy*Sz) /d)); 00571 00572 return ret; 00573 }
|
|
calculate the least square fit value.
Definition at line 509 of file util.cpp. References Assert, div(), NullPointerException, x, and y. Referenced by EMAN::OptVarianceCmp::cmp(), EMAN::LowpassAutoBProcessor::create_radial_func(), and EMAN::GradientRemoverProcessor::process_inplace(). 00511 { 00512 Assert(nitems > 0); 00513 00514 if (!data_x || !data_y || !slope || !intercept) { 00515 throw NullPointerException("null float pointer"); 00516 } 00517 double sum = 0; 00518 double sum_x = 0; 00519 double sum_y = 0; 00520 double sum_xx = 0; 00521 double sum_xy = 0; 00522 00523 for (size_t i = 0; i < nitems; i++) { 00524 if ((!ignore_zero || (data_x[i] != 0 && data_y[i] != 0))&&(!absmax ||(data_y[i]<absmax && data_y[i]>-absmax))) { 00525 double y = data_y[i]; 00526 double x = i; 00527 if (data_x) { 00528 x = data_x[i]; 00529 } 00530 00531 sum_x += x; 00532 sum_y += y; 00533 sum_xx += x * x; 00534 sum_xy += x * y; 00535 sum++; 00536 } 00537 } 00538 00539 double div = sum * sum_xx - sum_x * sum_x; 00540 if (div == 0) { 00541 div = 0.0000001f; 00542 } 00543 00544 *intercept = (float) ((sum_xx * sum_y - sum_x * sum_xy) / div); 00545 *slope = (float) ((sum * sum_xy - sum_x * sum_y) / div); 00546 }
|
|
Definition at line 6298 of file util_sparx.cpp. 06299 { 06300 long int q2_dim1, q2_offset, q_dim1, q_offset, i__1, i__2; 06301 float r__1; 06302 int tmp__i; 06303 long int i__, j; 06304 --s; 06305 --res; 06306 iu -= 3; 06307 cu -= 3; 06308 --x; 06309 long int klm2d; 06310 klm2d= *k+*k+2; 06311 klm2d=klm2d+klm2d; 06312 q_dim1 = klm2d; 06313 q_offset = 1 + q_dim1; 06314 q -= q_offset; 06315 q2_dim1 = klm2d; 06316 q2_offset = 1 + q2_dim1; 06317 q2 -= q2_offset; 06318 i__2=0; 06319 i__1 = *n - 1; 06320 tmp__i=0; 06321 for (j = 1; j <= i__1; ++j) { 06322 i__2 = *k; 06323 tmp__i+=1; 06324 for (i__ = 1; i__ <= i__2; ++i__) { 06325 r__1 = float(i__ - 1) /(float) *k / (*ps * 2); 06326 q2[i__ + j * q2_dim1] = pow(r__1, tmp__i); 06327 } 06328 } 06329 for (i__ = 1; i__ <= i__2; ++i__) 06330 { q2[i__ + *n * q2_dim1] = 1.f; 06331 q2[i__ + (*n + 1) * q2_dim1] = pw[i__-1]; 06332 } 06333 vector<float> fit_res; 06334 fit_res=Util::lsfit(k, n, &klm2d, iswi, &q2[q2_offset], &q[q_offset], &x[1], &res[1], &cu[3], &s[1], &iu[3]); 06335 return fit_res; 06336 }
|
|
Definition at line 5595 of file util_sparx.cpp. References DGR_TO_RAD, DM, and SS. 05596 { 05597 double CPHI,SPHI,CTHE,STHE,CPSI,SPSI; 05598 vector<float> DM,SS; 05599 05600 for(int i =0;i<9;i++) DM.push_back(0); 05601 05602 for(int i =0;i<6;i++) SS.push_back(0); 05603 05604 CPHI = cos(double(PHI)*DGR_TO_RAD); 05605 SPHI = sin(double(PHI)*DGR_TO_RAD); 05606 CTHE = cos(double(THETA)*DGR_TO_RAD); 05607 STHE = sin(double(THETA)*DGR_TO_RAD); 05608 CPSI = cos(double(PSI)*DGR_TO_RAD); 05609 SPSI = sin(double(PSI)*DGR_TO_RAD); 05610 05611 SS(1) = float(CPHI); 05612 SS(2) = float(SPHI); 05613 SS(3) = float(CTHE); 05614 SS(4) = float(STHE); 05615 SS(5) = float(CPSI); 05616 SS(6) = float(SPSI); 05617 05618 DM(1) = float(CPHI*CTHE*CPSI-SPHI*SPSI); 05619 DM(2) = float(SPHI*CTHE*CPSI+CPHI*SPSI); 05620 DM(3) = float(-STHE*CPSI); 05621 DM(4) = float(-CPHI*CTHE*SPSI-SPHI*CPSI); 05622 DM(5) = float(-SPHI*CTHE*SPSI+CPHI*CPSI); 05623 DM(6) = float(STHE*SPSI); 05624 DM(7) = float(STHE*CPHI); 05625 DM(8) = float(STHE*SPHI); 05626 DM(9) = float(CTHE); 05627 05628 Dict DMnSS; 05629 DMnSS["DM"] = DM; 05630 DMnSS["SS"] = SS; 05631 05632 return(DMnSS); 05633 }
|
|
Definition at line 19234 of file util_sparx.cpp. References EMAN::EMData::cmp(), and EMAN::EMData::rot_scale_trans2D(). 19234 { 19235 19236 EMData *rot= new EMData(); 19237 float ccc; 19238 19239 rot = image->rot_scale_trans2D(ang, sx, sy, 1.0); 19240 ccc = -rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19241 delete rot; 19242 return ccc; 19243 }
|
|
Definition at line 19271 of file util_sparx.cpp. References EMAN::EMData::cmp(), pi, and EMAN::EMData::rot_scale_conv7(). 19271 { 19272 19273 EMData *rot= new EMData(); 19274 float ccc; 19275 19276 rot = image->rot_scale_conv7(static_cast<float>(ang*pi/180.0), sx, sy, kb, 1.0f); 19277 ccc = -rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 19278 delete rot; 19279 return ccc; 19280 }
|
|
Change a file's extension and return the new filename. If the given new extension is empty, the old filename is not changed. If the old filename has no extension, add the new extension to it.
Definition at line 430 of file util.cpp. References Assert. Referenced by EMAN::EMUtil::get_image_type(), EMAN::ImagicIO::ImagicIO(), and EMAN::ImagicIO2::ImagicIO2(). 00432 { 00433 Assert(old_filename != ""); 00434 if (ext == "") { 00435 return old_filename; 00436 } 00437 00438 string filename = old_filename; 00439 size_t dot_pos = filename.rfind("."); 00440 if (dot_pos != string::npos) { 00441 filename = filename.substr(0, dot_pos+1); 00442 } 00443 else { 00444 filename = filename + "."; 00445 } 00446 filename = filename + ext; 00447 return filename; 00448 }
|
|
check whether a file starts with certain magic string.
Definition at line 194 of file util.cpp. References NullPointerException. Referenced by EMAN::VtkIO::is_valid(), EMAN::SalIO::is_valid(), EMAN::LstIO::is_valid(), EMAN::LstFastIO::is_valid(), and EMAN::AmiraIO::is_valid(). 00195 { 00196 if (!first_block || !magic) { 00197 throw NullPointerException("first_block/magic"); 00198 } 00199 00200 const char *buf = static_cast < const char *>(first_block); 00201 00202 if (strncmp(buf, magic, strlen(magic)) == 0) { 00203 return true; 00204 } 00205 return false; 00206 }
|
|
Definition at line 6483 of file util_sparx.cpp. 06485 { 06486 06487 long int q_dim1, q_offset, i__1, i__2; 06488 double d__1; 06489 06490 static long int i__, j; 06491 static double z__; 06492 static long int n1, n2, ia, ii, kk, in, nk, js; 06493 static double sn, zu, zv; 06494 static long int nk1, klm, nkl, jmn, jpn; 06495 static double cuv; 06496 static long int klm1, nkl1, klm2, kode, iimn, nklm, iter; 06497 static float xmin; 06498 static double xmax; 06499 static long int iout; 06500 static double xsum; 06501 static long int iineg, maxit; 06502 static double toler; 06503 static float error; 06504 static double pivot; 06505 static long int kforce, iphase; 06506 static double tpivot; 06507 06508 --s; 06509 --res; 06510 iu -= 3; 06511 cu -= 3; 06512 --x; 06513 q_dim1 = *klm2d; 06514 q_offset = 1 + q_dim1; 06515 q -= q_offset; 06516 06517 /* Function Body */ 06518 maxit = 500; 06519 kode = 0; 06520 toler = 1e-4f; 06521 iter = 0; 06522 n1 = *n + 1; 06523 n2 = *n + 2; 06524 nk = *n + *k; 06525 nk1 = nk + 1; 06526 nkl = nk + *l; 06527 nkl1 = nkl + 1; 06528 klm = *k + *l + *m; 06529 klm1 = klm + 1; 06530 klm2 = klm + 2; 06531 nklm = *n + klm; 06532 kforce = 1; 06533 iter = 0; 06534 js = 1; 06535 ia = 0; 06536 /* SET UP LABELS IN Q. */ 06537 i__1 = *n; 06538 for (j = 1; j <= i__1; ++j) { 06539 q[klm2 + j * q_dim1] = (double) j; 06540 /* L10: */ 06541 } 06542 i__1 = klm; 06543 for (i__ = 1; i__ <= i__1; ++i__) { 06544 q[i__ + n2 * q_dim1] = (double) (*n + i__); 06545 if (q[i__ + n1 * q_dim1] >= 0.f) { 06546 goto L30; 06547 } 06548 i__2 = n2; 06549 for (j = 1; j <= i__2; ++j) { 06550 q[i__ + j * q_dim1] = -q[i__ + j * q_dim1]; 06551 /* L20: */ 06552 } 06553 L30: 06554 ; 06555 } 06556 /* SET UP PHASE 1 COSTS. */ 06557 iphase = 2; 06558 i__1 = nklm; 06559 for (j = 1; j <= i__1; ++j) { 06560 cu[(j << 1) + 1] = 0.f; 06561 cu[(j << 1) + 2] = 0.f; 06562 iu[(j << 1) + 1] = 0; 06563 iu[(j << 1) + 2] = 0; 06564 /* L40: */ 06565 } 06566 if (*l == 0) { 06567 goto L60; 06568 } 06569 i__1 = nkl; 06570 for (j = nk1; j <= i__1; ++j) { 06571 cu[(j << 1) + 1] = 1.f; 06572 cu[(j << 1) + 2] = 1.f; 06573 iu[(j << 1) + 1] = 1; 06574 iu[(j << 1) + 2] = 1; 06575 /* L50: */ 06576 } 06577 iphase = 1; 06578 L60: 06579 if (*m == 0) { 06580 goto L80; 06581 } 06582 i__1 = nklm; 06583 for (j = nkl1; j <= i__1; ++j) { 06584 cu[(j << 1) + 2] = 1.f; 06585 iu[(j << 1) + 2] = 1; 06586 jmn = j - *n; 06587 if (q[jmn + n2 * q_dim1] < 0.f) { 06588 iphase = 1; 06589 } 06590 /* L70: */ 06591 } 06592 L80: 06593 if (kode == 0) { 06594 goto L150; 06595 } 06596 i__1 = *n; 06597 for (j = 1; j <= i__1; ++j) { 06598 if ((d__1 = x[j]) < 0.) { 06599 goto L90; 06600 } else if (d__1 == 0) { 06601 goto L110; 06602 } else { 06603 goto L100; 06604 } 06605 L90: 06606 cu[(j << 1) + 1] = 1.f; 06607 iu[(j << 1) + 1] = 1; 06608 goto L110; 06609 L100: 06610 cu[(j << 1) + 2] = 1.f; 06611 iu[(j << 1) + 2] = 1; 06612 L110: 06613 ; 06614 } 06615 i__1 = *k; 06616 for (j = 1; j <= i__1; ++j) { 06617 jpn = j + *n; 06618 if ((d__1 = res[j]) < 0.) { 06619 goto L120; 06620 } else if (d__1 == 0) { 06621 goto L140; 06622 } else { 06623 goto L130; 06624 } 06625 L120: 06626 cu[(jpn << 1) + 1] = 1.f; 06627 iu[(jpn << 1) + 1] = 1; 06628 if (q[j + n2 * q_dim1] > 0.f) { 06629 iphase = 1; 06630 } 06631 goto L140; 06632 L130: 06633 cu[(jpn << 1) + 2] = 1.f; 06634 iu[(jpn << 1) + 2] = 1; 06635 if (q[j + n2 * q_dim1] < 0.f) { 06636 iphase = 1; 06637 } 06638 L140: 06639 ; 06640 } 06641 L150: 06642 if (iphase == 2) { 06643 goto L500; 06644 } 06645 /* COMPUTE THE MARGINAL COSTS. */ 06646 L160: 06647 i__1 = n1; 06648 for (j = js; j <= i__1; ++j) { 06649 xsum = 0.; 06650 i__2 = klm; 06651 for (i__ = 1; i__ <= i__2; ++i__) { 06652 ii = (long int) q[i__ + n2 * q_dim1]; 06653 if (ii < 0) { 06654 goto L170; 06655 } 06656 z__ = cu[(ii << 1) + 1]; 06657 goto L180; 06658 L170: 06659 iineg = -ii; 06660 z__ = cu[(iineg << 1) + 2]; 06661 L180: 06662 xsum += q[i__ + j * q_dim1] * z__; 06663 /* 180 XSUM = XSUM + Q(I,J)*Z */ 06664 /* L190: */ 06665 } 06666 q[klm1 + j * q_dim1] = xsum; 06667 /* L200: */ 06668 } 06669 i__1 = *n; 06670 for (j = js; j <= i__1; ++j) { 06671 ii = (long int) q[klm2 + j * q_dim1]; 06672 if (ii < 0) { 06673 goto L210; 06674 } 06675 z__ = cu[(ii << 1) + 1]; 06676 goto L220; 06677 L210: 06678 iineg = -ii; 06679 z__ = cu[(iineg << 1) + 2]; 06680 L220: 06681 q[klm1 + j * q_dim1] -= z__; 06682 /* L230: */ 06683 } 06684 /* DETERMINE THE VECTOR TO ENTER THE BASIS. */ 06685 L240: 06686 xmax = 0.f; 06687 if (js > *n) { 06688 goto L490; 06689 } 06690 i__1 = *n; 06691 for (j = js; j <= i__1; ++j) { 06692 zu = q[klm1 + j * q_dim1]; 06693 ii = (long int) q[klm2 + j * q_dim1]; 06694 if (ii > 0) { 06695 goto L250; 06696 } 06697 ii = -ii; 06698 zv = zu; 06699 zu = -zu - cu[(ii << 1) + 1] - cu[(ii << 1) + 2]; 06700 goto L260; 06701 L250: 06702 zv = -zu - cu[(ii << 1) + 1] - cu[(ii << 1) + 2]; 06703 L260: 06704 if (kforce == 1 && ii > *n) { 06705 goto L280; 06706 } 06707 if (iu[(ii << 1) + 1] == 1) { 06708 goto L270; 06709 } 06710 if (zu <= xmax) { 06711 goto L270; 06712 } 06713 xmax = zu; 06714 in = j; 06715 L270: 06716 if (iu[(ii << 1) + 2] == 1) { 06717 goto L280; 06718 } 06719 if (zv <= xmax) { 06720 goto L280; 06721 } 06722 xmax = zv; 06723 in = j; 06724 L280: 06725 ; 06726 } 06727 if (xmax <= toler) { 06728 goto L490; 06729 } 06730 if (q[klm1 + in * q_dim1] == xmax) { 06731 goto L300; 06732 } 06733 i__1 = klm2; 06734 for (i__ = 1; i__ <= i__1; ++i__) { 06735 q[i__ + in * q_dim1] = -q[i__ + in * q_dim1]; 06736 /* L290: */ 06737 } 06738 q[klm1 + in * q_dim1] = xmax; 06739 /* DETERMINE THE VECTOR TO LEAVE THE BASIS. */ 06740 L300: 06741 if (iphase == 1 || ia == 0) { 06742 goto L330; 06743 } 06744 xmax = 0.f; 06745 i__1 = ia; 06746 for (i__ = 1; i__ <= i__1; ++i__) { 06747 z__ = (d__1 = q[i__ + in * q_dim1], abs(d__1)); 06748 if (z__ <= xmax) { 06749 goto L310; 06750 } 06751 xmax = z__; 06752 iout = i__; 06753 L310: 06754 ; 06755 } 06756 if (xmax <= toler) { 06757 goto L330; 06758 } 06759 i__1 = n2; 06760 for (j = 1; j <= i__1; ++j) { 06761 z__ = q[ia + j * q_dim1]; 06762 q[ia + j * q_dim1] = q[iout + j * q_dim1]; 06763 q[iout + j * q_dim1] = z__; 06764 /* L320: */ 06765 } 06766 iout = ia; 06767 --ia; 06768 pivot = q[iout + in * q_dim1]; 06769 goto L420; 06770 L330: 06771 kk = 0; 06772 i__1 = klm; 06773 for (i__ = 1; i__ <= i__1; ++i__) { 06774 z__ = q[i__ + in * q_dim1]; 06775 if (z__ <= toler) { 06776 goto L340; 06777 } 06778 ++kk; 06779 res[kk] = q[i__ + n1 * q_dim1] / z__; 06780 s[kk] = (double) i__; 06781 L340: 06782 ; 06783 } 06784 L350: 06785 if (kk > 0) { 06786 goto L360; 06787 } 06788 kode = 2; 06789 goto L590; 06790 L360: 06791 xmin = static_cast<float>( res[1] ); 06792 iout = (long int) s[1]; 06793 j = 1; 06794 if (kk == 1) { 06795 goto L380; 06796 } 06797 i__1 = kk; 06798 for (i__ = 2; i__ <= i__1; ++i__) { 06799 if (res[i__] >= xmin) { 06800 goto L370; 06801 } 06802 j = i__; 06803 xmin = static_cast<float>( res[i__] ); 06804 iout = (long int) s[i__]; 06805 L370: 06806 ; 06807 } 06808 res[j] = res[kk]; 06809 s[j] = s[kk]; 06810 L380: 06811 --kk; 06812 pivot = q[iout + in * q_dim1]; 06813 ii = (long int) q[iout + n2 * q_dim1]; 06814 if (iphase == 1) { 06815 goto L400; 06816 } 06817 if (ii < 0) { 06818 goto L390; 06819 } 06820 if (iu[(ii << 1) + 2] == 1) { 06821 goto L420; 06822 } 06823 goto L400; 06824 L390: 06825 iineg = -ii; 06826 if (iu[(iineg << 1) + 1] == 1) { 06827 goto L420; 06828 } 06829 /* 400 II = IABS(II) */ 06830 L400: 06831 ii = abs(ii); 06832 cuv = cu[(ii << 1) + 1] + cu[(ii << 1) + 2]; 06833 if (q[klm1 + in * q_dim1] - pivot * cuv <= toler) { 06834 goto L420; 06835 } 06836 /* BYPASS INTERMEDIATE VERTICES. */ 06837 i__1 = n1; 06838 for (j = js; j <= i__1; ++j) { 06839 z__ = q[iout + j * q_dim1]; 06840 q[klm1 + j * q_dim1] -= z__ * cuv; 06841 q[iout + j * q_dim1] = -z__; 06842 /* L410: */ 06843 } 06844 q[iout + n2 * q_dim1] = -q[iout + n2 * q_dim1]; 06845 goto L350; 06846 /* GAUSS-JORDAN ELIMINATION. */ 06847 L420: 06848 if (iter < maxit) { 06849 goto L430; 06850 } 06851 kode = 3; 06852 goto L590; 06853 L430: 06854 ++iter; 06855 i__1 = n1; 06856 for (j = js; j <= i__1; ++j) { 06857 if (j != in) { 06858 q[iout + j * q_dim1] /= pivot; 06859 } 06860 /* L440: */ 06861 } 06862 /* IF PERMITTED, USE SUBROUTINE COL OF THE DESCRIPTION */ 06863 /* SECTION AND REPLACE THE FOLLOWING SEVEN STATEMENTS DOWN */ 06864 /* TO AND INCLUDING STATEMENT NUMBER 460 BY.. */ 06865 /* DO 460 J=JS,N1 */ 06866 /* IF(J .EQ. IN) GO TO 460 */ 06867 /* Z = -Q(IOUT,J) */ 06868 /* CALL COL(Q(1,J), Q(1,IN), Z, IOUT, KLM1) */ 06869 /* 460 CONTINUE */ 06870 i__1 = n1; 06871 for (j = js; j <= i__1; ++j) { 06872 if (j == in) { 06873 goto L460; 06874 } 06875 z__ = -q[iout + j * q_dim1]; 06876 i__2 = klm1; 06877 for (i__ = 1; i__ <= i__2; ++i__) { 06878 if (i__ != iout) { 06879 q[i__ + j * q_dim1] += z__ * q[i__ + in * q_dim1]; 06880 } 06881 /* L450: */ 06882 } 06883 L460: 06884 ; 06885 } 06886 tpivot = -pivot; 06887 i__1 = klm1; 06888 for (i__ = 1; i__ <= i__1; ++i__) { 06889 if (i__ != iout) { 06890 q[i__ + in * q_dim1] /= tpivot; 06891 } 06892 /* L470: */ 06893 } 06894 q[iout + in * q_dim1] = 1.f / pivot; 06895 z__ = q[iout + n2 * q_dim1]; 06896 q[iout + n2 * q_dim1] = q[klm2 + in * q_dim1]; 06897 q[klm2 + in * q_dim1] = z__; 06898 ii = (long int) abs(z__); 06899 if (iu[(ii << 1) + 1] == 0 || iu[(ii << 1) + 2] == 0) { 06900 goto L240; 06901 } 06902 i__1 = klm2; 06903 for (i__ = 1; i__ <= i__1; ++i__) { 06904 z__ = q[i__ + in * q_dim1]; 06905 q[i__ + in * q_dim1] = q[i__ + js * q_dim1]; 06906 q[i__ + js * q_dim1] = z__; 06907 /* L480: */ 06908 } 06909 ++js; 06910 goto L240; 06911 /* TEST FOR OPTIMALITY. */ 06912 L490: 06913 if (kforce == 0) { 06914 goto L580; 06915 } 06916 if (iphase == 1 && q[klm1 + n1 * q_dim1] <= toler) { 06917 goto L500; 06918 } 06919 kforce = 0; 06920 goto L240; 06921 /* SET UP PHASE 2 COSTS. */ 06922 L500: 06923 iphase = 2; 06924 i__1 = nklm; 06925 for (j = 1; j <= i__1; ++j) { 06926 cu[(j << 1) + 1] = 0.f; 06927 cu[(j << 1) + 2] = 0.f; 06928 /* L510: */ 06929 } 06930 i__1 = nk; 06931 for (j = n1; j <= i__1; ++j) { 06932 cu[(j << 1) + 1] = 1.f; 06933 cu[(j << 1) + 2] = 1.f; 06934 /* L520: */ 06935 } 06936 i__1 = klm; 06937 for (i__ = 1; i__ <= i__1; ++i__) { 06938 ii = (long int) q[i__ + n2 * q_dim1]; 06939 if (ii > 0) { 06940 goto L530; 06941 } 06942 ii = -ii; 06943 if (iu[(ii << 1) + 2] == 0) { 06944 goto L560; 06945 } 06946 cu[(ii << 1) + 2] = 0.f; 06947 goto L540; 06948 L530: 06949 if (iu[(ii << 1) + 1] == 0) { 06950 goto L560; 06951 } 06952 cu[(ii << 1) + 1] = 0.f; 06953 L540: 06954 ++ia; 06955 i__2 = n2; 06956 for (j = 1; j <= i__2; ++j) { 06957 z__ = q[ia + j * q_dim1]; 06958 q[ia + j * q_dim1] = q[i__ + j * q_dim1]; 06959 q[i__ + j * q_dim1] = z__; 06960 /* L550: */ 06961 } 06962 L560: 06963 ; 06964 } 06965 goto L160; 06966 L570: 06967 if (q[klm1 + n1 * q_dim1] <= toler) { 06968 goto L500; 06969 } 06970 kode = 1; 06971 goto L590; 06972 L580: 06973 if (iphase == 1) { 06974 goto L570; 06975 } 06976 /* PREPARE OUTPUT. */ 06977 kode = 0; 06978 L590: 06979 xsum = 0.; 06980 i__1 = *n; 06981 for (j = 1; j <= i__1; ++j) { 06982 x[j] = 0.f; 06983 /* L600: */ 06984 } 06985 i__1 = klm; 06986 for (i__ = 1; i__ <= i__1; ++i__) { 06987 res[i__] = 0.f; 06988 /* L610: */ 06989 } 06990 i__1 = klm; 06991 for (i__ = 1; i__ <= i__1; ++i__) { 06992 ii = (long int) q[i__ + n2 * q_dim1]; 06993 sn = 1.f; 06994 if (ii > 0) { 06995 goto L620; 06996 } 06997 ii = -ii; 06998 sn = -1.f; 06999 L620: 07000 if (ii > *n) { 07001 goto L630; 07002 } 07003 x[ii] = sn * q[i__ + n1 * q_dim1]; 07004 goto L640; 07005 L630: 07006 iimn = ii - *n; 07007 res[iimn] = sn * q[i__ + n1 * q_dim1]; 07008 if (ii >= n1 && ii <= nk) { 07009 xsum += q[i__ + n1 * q_dim1]; 07010 } 07011 L640: 07012 ; 07013 } 07014 error = (float)xsum; 07015 return; 07016 }
|
|
Definition at line 19868 of file util_sparx.cpp. References dm, EMAN::EMData::get_xsize(), nx, and sqrt(). 19868 { 19869 // WORKS ONLY FOR NUMBER OF OBJECTS N=l^2 !! 19870 int nx = d->get_xsize(); 19871 int N = 1 + int((sqrt(1.0 + 8.0*nx)-1.0)/2.0); 19872 int K = N/2; 19873 vector<float> group(N); 19874 if(N*(N-1)/2 != nx) { 19875 //print " incorrect dimension" 19876 return group;} 19877 //bool active[N]; //this does not compile in VS2005. --Grant Tang 19878 bool * active = new bool[N]; 19879 for(int i=0; i<N; i++) active[i] = true; 19880 19881 float dm, qd; 19882 int ppi = 0, ppj = 0; 19883 for(int k=0; k<K; k++) { 19884 // find pairs of most similiar objects among active 19885 //cout<<" k "<<k<<endl; 19886 dm = 1.0e23f; 19887 for(int i=1; i<N; i++) { 19888 if(active[i]) { 19889 for(int j=0; j<i; j++) { 19890 if(active[j]) { 19891 qd = (*d)(i*(i - 1)/2 + j); 19892 if(qd < dm) { 19893 dm = qd; 19894 ppi = i; 19895 ppj = j; 19896 } 19897 } 19898 } 19899 } 19900 } 19901 group[2*k] = float(ppi); 19902 group[1+2*k] = float(ppj); 19903 active[ppi] = false; 19904 active[ppj] = false; 19905 } 19906 19907 delete [] active; 19908 active = NULL; 19909 return group; 19910 }
|
|
Definition at line 19660 of file util_sparx.cpp. References assign, cent, dt, EMAN::EMData::get_xsize(), mono(), nx, q, and sqrt(). 19660 { 19661 int nx = d->get_xsize(); 19662 int N = 1 + int((sqrt(1.0 + 8.0*nx)-1.0)/2.0); 19663 vector<float> out(N+K+2); 19664 if(N*(N-1)/2 != nx) { 19665 //print " incorrect dimension" 19666 return out;} 19667 // assign random objects as centers 19668 for(int i=0; i<N; i++) assign(i) = float(i); 19669 // shuffle 19670 for(int i=0; i<N; i++) { 19671 int j = Util::get_irand(0,N-1); 19672 float temp = assign(i); 19673 assign(i) = assign(j); 19674 assign(j) = temp; 19675 } 19676 for(int k=0; k<K; k++) cent(k) = float(assign(k)); 19677 //for(int k=0; k<K; k++) cout<<cent(k)<<" ";cout<<endl; 19678 // 19679 for(int i=0; i<N; i++) assign(i) = 0.0f; 19680 float qm, dispold = 1.1e22f, disp = 1.0e22f, na=0.0f; 19681 bool change = true; 19682 int it = -1; 19683 int ct = -1; 19684 while ((change && disp < dispold) || ct > 0) { 19685 19686 change = false; 19687 dispold = disp; 19688 it++; 19689 19690 // dispersion is a sum of distance from objects to object center 19691 disp = 0.0f; 19692 ct = 0; 19693 for(int i=0; i<N; i++) { 19694 qm = 1.0e23f; 19695 for(int k=0; k<K; k++) { 19696 if(float(i) == cent(k)) { 19697 qm = 0.0f; 19698 na = (float)k; 19699 } else { 19700 float dt = (*d)(mono(i,int(cent(k)))); 19701 if(dt < qm) { 19702 qm = dt; 19703 na = (float)k; 19704 } 19705 } 19706 } 19707 19708 19709 // Simulated annealing 19710 if(exp(-1.0/float(T)) > Util::get_irand(1,1000)/1000.0) { 19711 na = (float)(Util::get_irand(0, K)); 19712 qm = (*d)(mono(i,int(na))); 19713 ct++; 19714 } 19715 19716 disp += qm; 19717 19718 if(na != assign(i)) { 19719 assign(i) = na; 19720 change = true; 19721 } 19722 } 19723 19724 //cout<<"Iteration: "<<it<< " disp " <<disp << " T " << T << " disturb " << ct << endl; 19725 T = T*F; 19726 19727 //for(int k=0; k<N; k++) cout<<assign(k)<<" ";cout<<endl; 19728 //print disp 19729 //print assign 19730 // find centers 19731 for(int k=0; k<K; k++) { 19732 qm = 1.0e23f; 19733 for(int i=0; i<N; i++) { 19734 if(assign(i) == float(k)) { 19735 float q = 0.0; 19736 for(int j=0; j<N; j++) { 19737 if(assign(j) == float(k)) { 19738 //it cannot be the same object 19739 if(i != j) q += (*d)(mono(i,j)); 19740 //cout<<q<<" "<<i<<" "<<j<<" "<<k<<endl;} 19741 } 19742 } 19743 if(q < qm) { 19744 //cout<<qm<<" "<<q<<" "<<i<<" "<<k<<endl; 19745 qm = q; 19746 cent(k) = float(i); 19747 } 19748 } 19749 } 19750 } 19751 //for(int k=0; k<K; k++) cout<<cent(k)<<" ";cout<<endl;cout<<disp<<endl; 19752 } 19753 out[N+K] = disp; 19754 out[N+K+1] = float(it); 19755 return out; 19756 }
|
|
2009-03-30 15:44:05 JB. Compute the discrepancy belong all common-lines Definition at line 4915 of file util_sparx.cpp. References data, EMAN::EMData::get_data(), and EMAN::EMData::get_xsize(). 04915 { 04916 double res = 0; 04917 double buf = 0; 04918 float* line_1; 04919 float* line_2; 04920 int i, n, ind; 04921 int lnlen = data[0]->get_xsize(); 04922 for (n=0; n<n_lines; ++n) { 04923 ind = n*2; 04924 line_1 = data[seq[ind]]->get_data() + com[ind] * lnlen; 04925 line_2 = data[seq[ind+1]]->get_data() + com[ind+1] *lnlen; 04926 buf = 0; 04927 for (i=0; i<lnlen; ++i) { 04928 buf += (line_1[i]-line_2[i])*(line_1[i]-line_2[i]); 04929 } 04930 res += buf * weights[n]; 04931 } 04932 04933 return res; 04934 04935 }
|
|
2009-03-25 15:35:05 JB. This function prepare rotation matrix for common-lines Definition at line 4692 of file util_sparx.cpp. 04692 { 04693 int nb_ori = Ori.size() / 4; 04694 int i, ind; 04695 float ph, th, ps; 04696 double cph, cth, cps, sph, sth, sps; 04697 vector<double> Rot(nb_ori*9); 04698 for (i=0; i<nb_ori; ++i){ 04699 ind = i*4; 04700 // spider convention phi=psi-90, psi=phi+90 04701 ph = Ori[ind+2]-90; 04702 th = Ori[ind+1]; 04703 ps = Ori[ind]+90; 04704 ph *= deg_rad; 04705 th *= deg_rad; 04706 ps *= deg_rad; 04707 // pre-calculate some trigo stuffs 04708 cph = cos(ph); 04709 cth = cos(th); 04710 cps = cos(ps); 04711 sph = sin(ph); 04712 sth = sin(th); 04713 sps = sin(ps); 04714 // fill rotation matrix 04715 ind = i*9; 04716 Rot[ind] = cph*cps-cth*sps*sph; 04717 Rot[ind+1] = cph*sps+cth*cps*sph; 04718 Rot[ind+2] = sth*sph; 04719 Rot[ind+3] = -sph*cps-cth*sps*cph; 04720 Rot[ind+4] = -sph*sps+cth*cps*cph; 04721 Rot[ind+5] = sth*cph; 04722 Rot[ind+6] = sth*sps; 04723 Rot[ind+7] = -sth*cps; 04724 Rot[ind+8] = cth; 04725 } 04726 04727 return Rot; 04728 }
|
|
2009-03-26 10:46:14 JB. This function calculate all common-lines in space for Voronoi Definition at line 4860 of file util_sparx.cpp. References norm(), nx, ny, rad_deg, and sqrt(). 04860 { 04861 // seq is the pairwise index ij: 0, 1, 0, 2, 0, 3, 1, 2, 1, 3, 2, 3 04862 vector<double> cml(2*nlines); // [phi, theta] / line 04863 float ph1, th1; 04864 float ph2, th2; 04865 double nx, ny, nz; 04866 double norm; 04867 double sth1=0, sph1=0, cth1=0, cph1=0; 04868 double sth2, sph2, cth2, cph2; 04869 int l, ind, c; 04870 int mem = -1; 04871 for (l=0; l<nlines; ++l){ 04872 c = 2*l; 04873 if (seq[c]!=mem){ 04874 mem = seq[c]; 04875 ind = 4*seq[c]; 04876 ph1 = Ori[ind]*deg_rad; 04877 th1 = Ori[ind+1]*deg_rad; 04878 sth1 = sin(th1); 04879 sph1 = sin(ph1); 04880 cth1 = cos(th1); 04881 cph1 = cos(ph1); 04882 } 04883 ind = 4*seq[c+1]; 04884 ph2 = Ori[ind]*deg_rad; 04885 th2 = Ori[ind+1]*deg_rad; 04886 sth2 = sin(th2); 04887 cth2 = cos(th2); 04888 sph2 = sin(ph2); 04889 cph2 = cos(ph2); 04890 // cross product 04891 nx = sth1*cph1*cth2 - cth1*sth2*cph2; 04892 ny = cth1*sth2*sph2 - cth2*sth1*sph1; 04893 nz = sth1*sph1*sth2*cph2 - sth1*cph1*sth2*sph2; 04894 norm = sqrt(nx*nx+ny*ny+nz*nz); 04895 nx /= norm; 04896 ny /= norm; 04897 nz /= norm; 04898 // apply mirror if need 04899 if (nz<0) {nx=-nx; ny=-ny; nz=-nz;} 04900 // compute theta and phi 04901 cml[c+1] = acos(nz); 04902 if (cml[c+1] == 0) {cml[c] = 0;} 04903 else { 04904 cml[c+1] *= rad_deg; 04905 if (cml[c+1] > 89.99) {cml[c+1] = 89.99;} // this fix some pb in Voronoi 04906 cml[c] = rad_deg * atan2(nx, ny); 04907 cml[c] = fmod(360 + cml[c], 360); 04908 04909 } 04910 } 04911 04912 return cml; 04913 }
|
|
2009-03-25 15:35:53 JB. This function calculates common-lines between sinogram Definition at line 4761 of file util_sparx.cpp. References abs, b, nint180(), and rad_deg. 04761 { 04762 vector<int> com(2*(n_prj - 1)); 04763 int a = i_prj*9; 04764 int i, b, c; 04765 int n1=0, n2=0; 04766 float vmax = 1 - 1.0e-6f; 04767 double r11, r12, r13, r23, r31, r32, r33; 04768 04769 c = 0; 04770 for (i=0; i<n_prj; ++i){ 04771 if (i!=i_prj){ 04772 b = i*9; 04773 // this is equivalent to R = A*B' 04774 r11 = Rot[a]*Rot[b]+Rot[a+1]*Rot[b+1]+Rot[a+2]*Rot[b+2]; 04775 r12 = Rot[a]*Rot[b+3]+Rot[a+1]*Rot[b+4]+Rot[a+2]*Rot[b+5]; 04776 r13 = Rot[a]*Rot[b+6]+Rot[a+1]*Rot[b+7]+Rot[a+2]*Rot[b+8]; 04777 r23 = Rot[a+3]*Rot[b+6]+Rot[a+4]*Rot[b+7]+Rot[a+5]*Rot[b+8]; 04778 r31 = Rot[a+6]*Rot[b]+Rot[a+7]*Rot[b+1]+Rot[a+8]*Rot[b+2]; 04779 r32 = Rot[a+6]*Rot[b+3]+Rot[a+7]*Rot[b+4]+Rot[a+8]*Rot[b+5]; 04780 r33 = Rot[a+6]*Rot[b+6]+Rot[a+7]*Rot[b+7]+Rot[a+8]*Rot[b+8]; 04781 if (r33 > vmax) { 04782 n2 = 270; 04783 n1 = 270 + nint180((float)(rad_deg*atan2(r12, r11))); 04784 } 04785 else if (r33 < -vmax) { 04786 n2 = 270; 04787 n1 = 270 - nint180((float)(rad_deg*atan2(r12, r11))); 04788 } else { 04789 n2 = nint180((float)(rad_deg*atan2(r31, -r32))); 04790 n1 = nint180((float)(rad_deg*atan2(r13, r23))); 04791 if (n1 < 0) {n1 += 360;} 04792 if (n2 <= 0) {n2 = abs(n2);} 04793 else {n2 = 360 - n2;} 04794 } 04795 04796 if (n1 >= 360){n1 = n1 % 360;} 04797 if (n2 >= 360){n2 = n2 % 360;} 04798 04799 // store common-lines 04800 b = c*2; 04801 com[b] = n1; 04802 com[b+1] = n2; 04803 ++c; 04804 } 04805 } 04806 04807 return com; 04808 04809 }
|
|
2009-03-30 15:35:07 JB. This function calculates all common-lines between sinogram Definition at line 4811 of file util_sparx.cpp. References abs, b, nint180(), and rad_deg. 04811 { 04812 vector<int> com(2*n_lines); 04813 int a=0, b, c, l; 04814 int n1=0, n2=0, mem=-1; 04815 float vmax = 1 - 1.0e-6f; 04816 double r11, r12, r13, r23, r31, r32, r33; 04817 c = 0; 04818 for (l=0; l<n_lines; ++l){ 04819 c = 2*l; 04820 if (seq[c]!=mem){ 04821 mem = seq[c]; 04822 a = seq[c]*9; 04823 } 04824 b = seq[c+1]*9; 04825 04826 // this is equivalent to R = A*B' 04827 r11 = Rot[a]*Rot[b]+Rot[a+1]*Rot[b+1]+Rot[a+2]*Rot[b+2]; 04828 r12 = Rot[a]*Rot[b+3]+Rot[a+1]*Rot[b+4]+Rot[a+2]*Rot[b+5]; 04829 r13 = Rot[a]*Rot[b+6]+Rot[a+1]*Rot[b+7]+Rot[a+2]*Rot[b+8]; 04830 r23 = Rot[a+3]*Rot[b+6]+Rot[a+4]*Rot[b+7]+Rot[a+5]*Rot[b+8]; 04831 r31 = Rot[a+6]*Rot[b]+Rot[a+7]*Rot[b+1]+Rot[a+8]*Rot[b+2]; 04832 r32 = Rot[a+6]*Rot[b+3]+Rot[a+7]*Rot[b+4]+Rot[a+8]*Rot[b+5]; 04833 r33 = Rot[a+6]*Rot[b+6]+Rot[a+7]*Rot[b+7]+Rot[a+8]*Rot[b+8]; 04834 if (r33 > vmax) { 04835 n2 = 270; 04836 n1 = 270 + nint180((float)(rad_deg*atan2(r12, r11))); 04837 } 04838 else if (r33 < -vmax) { 04839 n2 = 270; 04840 n1 = 270 - nint180((float)(rad_deg*atan2(r12, r11))); 04841 } else { 04842 n2 = nint180((float)(rad_deg*atan2(r31, -r32))); 04843 n1 = nint180((float)(rad_deg*atan2(r13, r23))); 04844 if (n1 < 0) {n1 += 360;} 04845 if (n2 <= 0) {n2 = abs(n2);} 04846 else {n2 = 360 - n2;} 04847 } 04848 if (n1 >= 360){n1 = n1 % 360;} 04849 if (n2 >= 360){n2 = n2 % 360;} 04850 04851 // store common-lines 04852 com[c] = n1; 04853 com[c+1] = n2; 04854 } 04855 04856 return com; 04857 04858 }
|
|
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 4674 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), nx, and EMAN::EMData::update(). 04674 { 04675 int j; 04676 int nx = sino->get_xsize(); 04677 int i = nx * pos_line; 04678 float r1, r2; 04679 float *line_ptr = line->get_data(); 04680 float *sino_ptr = sino->get_data(); 04681 for (j=ilf;j<=ihf; j += 2) { 04682 r1 = line_ptr[j]; 04683 r2 = line_ptr[j + 1]; 04684 sino_ptr[i + j - ilf] = r1; 04685 sino_ptr[i + j - ilf + 1] = r2; 04686 sino_ptr[i + nx * nblines + j - ilf] = r1; 04687 sino_ptr[i + nx * nblines + j - ilf + 1] = -r2; 04688 } 04689 sino->update(); 04690 }
|
|
2009-03-26 11:37:53 JB. This function spin all angle psi and evaluate the partial discrepancy belong common-lines |
|
2009-03-25 15:35:37 JB. this function update only one rotation amtrix according a new orientation Definition at line 4730 of file util_sparx.cpp. 04730 { 04731 float ph, ps; 04732 double cph, cth, cps, sph, sth, sps; 04733 int ind = iprj*9; 04734 // spider convention phi=psi-90, psi=phi+90 04735 ph = nps-90; 04736 ps = nph+90; 04737 ph *= deg_rad; 04738 th *= deg_rad; 04739 ps *= deg_rad; 04740 // pre-calculate some trigo stuffs 04741 cph = cos(ph); 04742 cth = cos(th); 04743 cps = cos(ps); 04744 sph = sin(ph); 04745 sth = sin(th); 04746 sps = sin(ps); 04747 // fill rotation matrix 04748 Rot[ind] = (float)(cph*cps-cth*sps*sph); 04749 Rot[ind+1] = (float)(cph*sps+cth*cps*sph); 04750 Rot[ind+2] = (float)(sth*sph); 04751 Rot[ind+3] = (float)(-sph*cps-cth*sps*cph); 04752 Rot[ind+4] = (float)(-sph*sps+cth*cps*cph); 04753 Rot[ind+5] = (float)(sth*cph); 04754 Rot[ind+6] = (float)(sth*sps); 04755 Rot[ind+7] = (float)(-sth*cps); 04756 Rot[ind+8] = (float)(cth); 04757 04758 return Rot; 04759 }
|
|
Definition at line 4584 of file util_sparx.cpp. References Assert, ori_t::id, ori_t::iphi, ori_t::itht, PI2, and vrdg(). 04584 { 04585 static const int NBIN = 100; 04586 int nline=cml.size()/2; 04587 vector<double> weights(nline); 04588 04589 vector<ori_t> angs(nline); 04590 for( int i=0; i < nline; ++i ) { 04591 angs[i].iphi = int( NBIN*cml[2*i] ); 04592 angs[i].itht = int( NBIN*cml[2*i+1] ); 04593 if( angs[i].itht == 180*NBIN ) angs[i].itht = 0; 04594 angs[i].id = i; 04595 } 04596 04597 //std::cout << "# of angs: " << angs.size() << std::endl; 04598 04599 std::sort( angs.begin(), angs.end(), cmpang() ); 04600 04601 vector<float> newphi; 04602 vector<float> newtht; 04603 vector< vector<int> > indices; 04604 04605 int curt_iphi = -1; 04606 int curt_itht = -1; 04607 for(unsigned int i=0 ;i < angs.size(); ++i ) { 04608 if( angs[i].iphi==curt_iphi && angs[i].itht==curt_itht ) { 04609 Assert( indices.size() > 0 ); 04610 indices.back().push_back(angs[i].id); 04611 } else { 04612 curt_iphi = angs[i].iphi; 04613 curt_itht = angs[i].itht; 04614 04615 newphi.push_back( float(curt_iphi)/NBIN ); 04616 newtht.push_back( float(curt_itht)/NBIN ); 04617 indices.push_back( vector<int>(1,angs[i].id) ); 04618 } 04619 } 04620 04621 //std::cout << "# of indpendent ang: " << newphi.size() << std::endl; 04622 04623 04624 int num_agl = newphi.size(); 04625 04626 if(num_agl>2) { 04627 vector<double> w=Util::vrdg(newphi, newtht); 04628 04629 Assert( w.size()==newphi.size() ); 04630 Assert( indices.size()==newphi.size() ); 04631 04632 for(unsigned int i=0; i < newphi.size(); ++i ) { 04633 /* 04634 std::cout << "phi,tht,w,n: "; 04635 std::cout << boost::format( "%10.3f" ) % newphi[i] << " "; 04636 std::cout << boost::format( "%10.3f" ) % newtht[i] << " "; 04637 std::cout << boost::format( "%8.6f" ) % w[i] << " "; 04638 std::cout << indices[i].size() << "("; 04639 */ 04640 04641 for(unsigned int j=0; j < indices[i].size(); ++j ) { 04642 int id = indices[i][j]; 04643 weights[id] = w[i]/indices[i].size(); 04644 //std::cout << id << " "; 04645 } 04646 04647 //std::cout << ")" << std::endl; 04648 04649 } 04650 } else { 04651 cout<<"warning in Util.cml_weights"<<endl; 04652 double val = PI2/float(nline); 04653 for(int i=0; i<nline; i++) weights[i]=val; 04654 } 04655 04656 return weights; 04657 04658 }
|
|
Definition at line 7154 of file util_sparx.cpp. References EMAN::Util::tmpstruct::theta1.
|
|
Definition at line 7159 of file util_sparx.cpp. References EMAN::Util::tmpstruct::key1.
|
|
Definition at line 5345 of file util_sparx.cpp. References nx. Referenced by cyclicshift(), and slicereverse(). 05345 { 05346 float* tmp = new float[nx]; 05347 int n = (end - beg)/nx; 05348 int nhalf = n/2; 05349 for (int i = 0; i < nhalf; i++) { 05350 // swap col i and col n-1-i 05351 memcpy(tmp, beg+i*nx, nx*sizeof(float)); 05352 memcpy(beg+i*nx, beg+(n-1-i)*nx, nx*sizeof(float)); 05353 memcpy(beg+(n-1-i)*nx, tmp, nx*sizeof(float)); 05354 } 05355 delete[] tmp; 05356 }
|
|
Definition at line 6037 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(). 06038 { 06039 /*********** 06040 ***get the size of the image for validation purpose 06041 **************/ 06042 int nx = image->get_xsize(),ny = image->get_ysize(),nz = image->get_zsize(); //Aren't these implied? Please check and let me know, PAP. 06043 /******** 06044 ***Exception Handle 06045 *************/ 06046 if(nx != mask->get_xsize() || ny != mask->get_ysize() || nz != mask->get_zsize()) 06047 throw ImageDimensionException("The dimension of the image does not match the dimension of the mask!"); 06048 06049 int i, size = nx*ny*nz; 06050 06051 float* img_ptr = image->get_data(); 06052 float* mask_ptr = mask->get_data(); 06053 06054 int ln=0; //length of the output image = number of points under the mask. 06055 for(i = 0;i < size;i++) if(mask_ptr[i] > 0.5f) ln++; 06056 06057 EMData* new_image = new EMData(); 06058 new_image->set_size(ln,1,1); /* set size of the new image */ 06059 float *new_ptr = new_image->get_data(); 06060 06061 ln=-1; 06062 for(i = 0;i < size;i++){ 06063 if(mask_ptr[i] > 0.5f) { 06064 ln++; 06065 new_ptr[ln]=img_ptr[i]; 06066 } 06067 } 06068 06069 return new_image; 06070 }
|
|
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 6166 of file util_sparx.cpp. References covmat, eigval, eigvec, and ssyev_(). 06167 { 06168 // n size of the covariance/correlation matrix 06169 // covmat --- covariance/correlation matrix (n by n) 06170 // eigval --- returns eigenvalues 06171 // eigvec --- returns eigenvectors 06172 06173 ENTERFUNC; 06174 06175 int i; 06176 06177 // make a copy of covmat so that it will not be overwritten 06178 for ( i = 0 ; i < n * n ; i++ ) eigvec[i] = covmat[i]; 06179 06180 char NEEDV = 'V'; 06181 char UPLO = 'U'; 06182 int lwork = -1; 06183 int info = 0; 06184 float *work, wsize; 06185 06186 // query to get optimal workspace 06187 ssyev_(&NEEDV, &UPLO, &n, eigvec, &n, eigval, &wsize, &lwork, &info); 06188 lwork = (int)wsize; 06189 06190 work = (float *)calloc(lwork, sizeof(float)); 06191 // calculate eigs 06192 ssyev_(&NEEDV, &UPLO, &n, eigvec, &n, eigval, work, &lwork, &info); 06193 free(work); 06194 EXITFUNC; 06195 return info; 06196 }
|
|
same function than Util::coveig but wrapped to use directly in python code
Definition at line 6198 of file util_sparx.cpp. References coveig(), covmat, eigval, eigvec, EMAN::Dict::size(), and status. 06199 { 06200 06201 ENTERFUNC; 06202 int len = covmatpy.size(); 06203 float *eigvec; 06204 float *eigval; 06205 float *covmat; 06206 int status = 0; 06207 eigval = (float*)calloc(ncov,sizeof(float)); 06208 eigvec = (float*)calloc(ncov*ncov,sizeof(float)); 06209 covmat = (float*)calloc(ncov*ncov, sizeof(float)); 06210 06211 const float *covmat_ptr; 06212 covmat_ptr = &covmatpy[0]; 06213 for(int i=0;i<len;i++){ 06214 covmat[i] = covmat_ptr[i]; 06215 } 06216 06217 status = Util::coveig(ncov, covmat, eigval, eigvec); 06218 06219 vector<float> eigval_py(ncov); 06220 const float *eigval_ptr; 06221 eigval_ptr = &eigval[0]; 06222 for(int i=0;i<ncov;i++){ 06223 eigval_py[i] = eigval_ptr[i]; 06224 } 06225 06226 vector<float> eigvec_py(ncov*ncov); 06227 const float *eigvec_ptr; 06228 eigvec_ptr = &eigvec[0]; 06229 for(int i=0;i<ncov*ncov;i++){ 06230 eigvec_py[i] = eigvec_ptr[i]; 06231 } 06232 06233 Dict res; 06234 res["eigval"] = eigval_py; 06235 res["eigvec"] = eigvec_py; 06236 06237 EXITFUNC; 06238 return res; 06239 }
|
|
Definition at line 3164 of file util_sparx.cpp. References circ1, circ2, fftr_d(), EMAN::EMData::get_data(), log(), numr, prb1d(), q, t, t7, and tot. 03164 { 03165 // neg = 0 straight, neg = 1 mirrored 03166 int nring = numr.size()/3; 03167 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03168 int maxrin = numr[numr.size()-1]; 03169 double qn; float tot; 03170 float *circ1 = circ1p->get_data(); 03171 float *circ2 = circ2p->get_data(); 03172 /* 03173 c checks single position, neg is flag for checking mirrored position 03174 c 03175 c input - fourier transforms of rings! 03176 c first set is conjugated (mirrored) if neg 03177 c circ1 already multiplied by weights! 03178 c automatic arrays 03179 dimension t(maxrin) removed +2 as it is only needed for other ffts 03180 double precision q(maxrin) 03181 double precision t7(-3:3) 03182 */ 03183 float *t; 03184 double t7[7], *q; 03185 int i, j, k, ip, jc, numr3i, numr2i, jtot = 0; 03186 float pos; 03187 03188 #ifdef _WIN32 03189 ip = -(int)(log((float)maxrin)/log(2.0f)); 03190 #else 03191 ip = -(int) (log2(maxrin)); 03192 #endif //_WIN32 03193 03194 q = (double*)calloc(maxrin, sizeof(double)); 03195 t = (float*)calloc(maxrin, sizeof(float)); 03196 03197 // cout << *qn <<" " <<*tot<<" "<<ip<<endl; 03198 for (i=1; i<=nring; i++) { 03199 numr3i = numr(3,i); 03200 numr2i = numr(2,i); 03201 03202 t(1) = (circ1(numr2i)) * circ2(numr2i); 03203 03204 if (numr3i != maxrin) { 03205 // test .ne. first for speed on some compilers 03206 t(numr3i+1) = circ1(numr2i+1) * circ2(numr2i+1); 03207 t(2) = 0.0; 03208 03209 if (neg) { 03210 // first set is conjugated (mirrored) 03211 for (j=3;j<=numr3i;j=j+2) { 03212 jc = j+numr2i-1; 03213 t(j) =(circ1(jc))*circ2(jc)-(circ1(jc+1))*circ2(jc+1); 03214 t(j+1) = -(circ1(jc))*circ2(jc+1)-(circ1(jc+1))*circ2(jc); 03215 } 03216 } else { 03217 for (j=3;j<=numr3i;j=j+2) { 03218 jc = j+numr2i-1; 03219 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1); 03220 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc); 03221 } 03222 } 03223 for (j=1;j<=numr3i+1;j++) q(j) = q(j) + t(j); 03224 } else { 03225 t(2) = circ1(numr2i+1) * circ2(numr2i+1); 03226 if (neg) { 03227 // first set is conjugated (mirrored) 03228 for (j=3;j<=maxrin;j=j+2) { 03229 jc = j+numr2i-1; 03230 t(j) = (circ1(jc))*circ2(jc) - (circ1(jc+1))*circ2(jc+1); 03231 t(j+1) = -(circ1(jc))*circ2(jc+1) - (circ1(jc+1))*circ2(jc); 03232 } 03233 } else { 03234 for (j=3;j<=maxrin;j=j+2) { 03235 jc = j+numr2i-1; 03236 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1); 03237 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc); 03238 } 03239 } 03240 for (j = 1; j <= maxrin; j++) q(j) += t(j); 03241 } 03242 } 03243 03244 fftr_d(q,ip); 03245 03246 qn = -1.0e20; 03247 for (j=1;j<=maxrin;j++) { 03248 if (q(j) >= qn) { 03249 qn = q(j); jtot = j; 03250 } 03251 } 03252 03253 for (k=-3; k<=3; k++) { 03254 j = (jtot+k+maxrin-1)%maxrin + 1; 03255 t7(k+4) = q(j); 03256 } 03257 03258 prb1d(t7,7,&pos); 03259 03260 tot = (float)jtot + pos; 03261 03262 if (q) free(q); 03263 if (t) free(t); 03264 03265 Dict retvals; 03266 retvals["qn"] = qn; 03267 retvals["tot"] = tot; 03268 return retvals; 03269 }
|
|
Definition at line 3271 of file util_sparx.cpp. References circ1, circ2, fftr_d(), EMAN::EMData::get_data(), log(), numr, prb1d(), q, EMAN::Dict::size(), t, t7, and tot. 03271 { 03272 // neg = 0 straight, neg = 1 mirrored 03273 int nring = numr.size()/3; 03274 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03275 int maxrin = numr[numr.size()-1]; 03276 double qn; float tot; 03277 float *circ1 = circ1p->get_data(); 03278 float *circ2 = circ2p->get_data(); 03279 /* 03280 c checks single position, neg is flag for checking mirrored position 03281 c 03282 c input - fourier transforms of rings! 03283 c first set is conjugated (mirrored) if neg 03284 c multiplication by weights! 03285 c automatic arrays 03286 dimension t(maxrin) removed +2 as it is only needed for other ffts 03287 double precision q(maxrin) 03288 double precision t7(-3:3) 03289 */ 03290 float *t; 03291 double t7[7], *q; 03292 int i, j, k, ip, jc, numr3i, numr2i, jtot = 0; 03293 float pos; 03294 03295 #ifdef _WIN32 03296 ip = -(int)(log((float)maxrin)/log(2.0f)); 03297 #else 03298 ip = -(int) (log2(maxrin)); 03299 #endif //_WIN32 03300 03301 q = (double*)calloc(maxrin, sizeof(double)); 03302 t = (float*)calloc(maxrin, sizeof(float)); 03303 03304 // cout << *qn <<" " <<*tot<<" "<<ip<<endl; 03305 for (i=1;i<=nring;i++) { 03306 numr3i = numr(3,i); 03307 numr2i = numr(2,i); 03308 03309 t(1) = circ1(numr2i) * circ2(numr2i); 03310 03311 if (numr3i != maxrin) { 03312 // test .ne. first for speed on some compilers 03313 t(numr3i+1) = circ1(numr2i+1) * circ2(numr2i+1); 03314 t(2) = 0.0; 03315 03316 if (neg) { 03317 // first set is conjugated (mirrored) 03318 for (j=3; j<=numr3i; j=j+2) { 03319 jc = j+numr2i-1; 03320 t(j) = (circ1(jc))*circ2(jc)-(circ1(jc+1))*circ2(jc+1); 03321 t(j+1) = -(circ1(jc))*circ2(jc+1)-(circ1(jc+1))*circ2(jc); 03322 } 03323 } else { 03324 for (j=3; j<=numr3i; j=j+2) { 03325 jc = j+numr2i-1; 03326 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1); 03327 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc); 03328 } 03329 } 03330 for (j=1;j<=numr3i+1;j++) q(j) += t(j)*w[i-1]; 03331 } else { 03332 t(2) = circ1(numr2i+1) * circ2(numr2i+1); 03333 if (neg) { 03334 // first set is conjugated (mirrored) 03335 for (j=3; j<=maxrin; j=j+2) { 03336 jc = j+numr2i-1; 03337 t(j) = (circ1(jc))*circ2(jc) - (circ1(jc+1))*circ2(jc+1); 03338 t(j+1) = -(circ1(jc))*circ2(jc+1) - (circ1(jc+1))*circ2(jc); 03339 } 03340 } else { 03341 for (j=3; j<=maxrin; j=j+2) { 03342 jc = j+numr2i-1; 03343 t(j) = (circ1(jc))*circ2(jc) + (circ1(jc+1))*circ2(jc+1); 03344 t(j+1) = -(circ1(jc))*circ2(jc+1) + (circ1(jc+1))*circ2(jc); 03345 } 03346 } 03347 for (j = 1; j <= maxrin; j++) q(j) += t(j)*w[i-1]; 03348 } 03349 } 03350 03351 fftr_d(q,ip); 03352 03353 qn = -1.0e20; 03354 for (j=1;j<=maxrin;j++) { 03355 //cout << j << " " << q(j) << endl; 03356 if (q(j) >= qn) { 03357 qn = q(j); 03358 jtot = j; 03359 } 03360 } 03361 03362 for (k=-3; k<=3; k++) { 03363 j = (jtot+k+maxrin-1)%maxrin + 1; 03364 t7(k+4) = q(j); 03365 } 03366 03367 prb1d(t7,7,&pos); 03368 03369 tot = (float)jtot + pos; 03370 03371 //if (q) free(q); 03372 if (t) free(t); 03373 03374 Dict retvals; 03375 //tot = 1; 03376 //qn = q(1); 03377 retvals["qn"] = qn; 03378 retvals["tot"] = tot; 03379 03380 if (q) free(q); 03381 03382 return retvals; 03383 }
|
|
Definition at line 3385 of file util_sparx.cpp. References circ1, circ2, fftr_d(), EMAN::EMData::get_data(), log(), numr, prb1d(), q, EMAN::Dict::size(), t, t7, tmt, and tot. Referenced by multiref_polar_ali_2d(), multiref_polar_ali_2d_local(), and multiref_polar_ali_2d_peaklist(). 03385 { 03386 int nring = numr.size()/3; 03387 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03388 int maxrin = numr[numr.size()-1]; 03389 double qn; float tot; double qm; float tmt; 03390 float *circ1 = circ1p->get_data(); 03391 float *circ2 = circ2p->get_data(); 03392 /* 03393 c 03394 c checks both straight & mirrored positions 03395 c 03396 c input - fourier transforms of rings!! 03397 c circ1 already multiplied by weights! 03398 c 03399 */ 03400 03401 // dimension circ1(lcirc),circ2(lcirc) 03402 03403 // t(maxrin), q(maxrin), t7(-3:3) //maxrin+2 removed 03404 double *t, *q, t7[7]; 03405 03406 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 03407 float t1, t2, t3, t4, c1, c2, d1, d2, pos; 03408 03409 qn = 0.0f; 03410 qm = 0.0f; 03411 tot = 0.0f; 03412 tmt = 0.0f; 03413 #ifdef _WIN32 03414 ip = -(int)(log((float)maxrin)/log(2.0f)); 03415 #else 03416 ip = -(int)(log2(maxrin)); 03417 #endif //_WIN32 03418 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl; 03419 03420 // c - straight = circ1 * conjg(circ2) 03421 // zero q array 03422 03423 q = (double*)calloc(maxrin,sizeof(double)); 03424 03425 // t - mirrored = conjg(circ1) * conjg(circ2) 03426 // zero t array 03427 t = (double*)calloc(maxrin,sizeof(double)); 03428 03429 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03430 for (i=1; i<=nring; i++) { 03431 03432 numr3i = numr(3,i); // Number of samples of this ring 03433 numr2i = numr(2,i); // The beginning point of this ring 03434 03435 t1 = circ1(numr2i) * circ2(numr2i); 03436 q(1) += t1; 03437 t(1) += t1; 03438 03439 t1 = circ1(numr2i+1) * circ2(numr2i+1); 03440 if (numr3i == maxrin) { 03441 q(2) += t1; 03442 t(2) += t1; 03443 } else { 03444 q(numr3i+1) += t1; 03445 t(numr3i+1) += t1; 03446 } 03447 03448 for (j=3; j<=numr3i; j += 2) { 03449 jc = j+numr2i-1; 03450 03451 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03452 // ----- ----- ----- ----- 03453 // t1 t2 t3 t4 03454 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i 03455 // ----- ----- ----- ----- 03456 // t1 t2 t3 t4 03457 03458 c1 = circ1(jc); 03459 c2 = circ1(jc+1); 03460 d1 = circ2(jc); 03461 d2 = circ2(jc+1); 03462 03463 t1 = c1 * d1; 03464 t2 = c2 * d2; 03465 t3 = c1 * d2; 03466 t4 = c2 * d1; 03467 03468 q(j) += t1 + t2; 03469 q(j+1) += -t3 + t4; 03470 t(j) += t1 - t2; 03471 t(j+1) += -t3 - t4; 03472 } 03473 } 03474 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<" "<<t(j) <<endl; 03475 fftr_d(q,ip); 03476 03477 qn = -1.0e20; 03478 for (j=1; j<=maxrin; j++) {//cout <<" "<<j<<" "<<q(j) <<endl; 03479 if (q(j) >= qn) { 03480 qn = q(j); 03481 jtot = j; 03482 } 03483 } 03484 03485 for (k=-3; k<=3; k++) { 03486 j = ((jtot+k+maxrin-1)%maxrin)+1; 03487 t7(k+4) = q(j); 03488 } 03489 03490 // interpolate 03491 prb1d(t7,7,&pos); 03492 tot = (float)(jtot)+pos; 03493 // Do not interpolate 03494 //tot = (float)(jtot); 03495 03496 // mirrored 03497 fftr_d(t,ip); 03498 03499 // find angle 03500 qm = -1.0e20; 03501 for (j=1; j<=maxrin;j++) {//cout <<" "<<j<<" "<<t(j) <<endl; 03502 if ( t(j) >= qm ) { 03503 qm = t(j); 03504 jtot = j; 03505 } 03506 } 03507 03508 for (k=-3; k<=3; k++) { 03509 j = ((jtot+k+maxrin-1)%maxrin) + 1; 03510 t7(k+4) = t(j); 03511 } 03512 03513 // interpolate 03514 03515 prb1d(t7,7,&pos); 03516 tmt = float(jtot) + pos; 03517 // Do not interpolate 03518 //tmt = float(jtot); 03519 03520 free(t); 03521 free(q); 03522 03523 Dict retvals; 03524 retvals["qn"] = qn; 03525 retvals["tot"] = tot; 03526 retvals["qm"] = qm; 03527 retvals["tmt"] = tmt; 03528 return retvals; 03529 }
|
|
Definition at line 3531 of file util_sparx.cpp. References circ1, circ2, fftr_d(), EMAN::EMData::get_data(), log(), numr, q, EMAN::Dict::size(), t, tmt, and tot. Referenced by multiref_polar_ali_2d_delta(). 03531 { 03532 int nring = numr.size()/3; 03533 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03534 int maxrin = numr[numr.size()-1]; 03535 double qn; float tot; double qm; float tmt; 03536 float *circ1 = circ1p->get_data(); 03537 float *circ2 = circ2p->get_data(); 03538 /* 03539 c 03540 c checks both straight & mirrored positions 03541 c 03542 c input - fourier transforms of rings!! 03543 c circ1 already multiplied by weights! 03544 c 03545 */ 03546 03547 // dimension circ1(lcirc),circ2(lcirc) 03548 03549 // t(maxrin), q(maxrin), t7(-3:3) //maxrin+2 removed 03550 double *t, *q; 03551 03552 int ip, jc, numr3i, numr2i, i, j, jtot = 0; 03553 float t1, t2, t3, t4, c1, c2, d1, d2; 03554 03555 qn = 0.0f; 03556 qm = 0.0f; 03557 tot = 0.0f; 03558 tmt = 0.0f; 03559 #ifdef _WIN32 03560 ip = -(int)(log((float)maxrin)/log(2.0f)); 03561 #else 03562 ip = -(int)(log2(maxrin)); 03563 #endif //_WIN32 03564 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl; 03565 03566 // c - straight = circ1 * conjg(circ2) 03567 // zero q array 03568 03569 q = (double*)calloc(maxrin,sizeof(double)); 03570 03571 // t - mirrored = conjg(circ1) * conjg(circ2) 03572 // zero t array 03573 t = (double*)calloc(maxrin,sizeof(double)); 03574 03575 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03576 for (i=1; i<=nring; i++) { 03577 03578 numr3i = numr(3,i); // Number of samples of this ring 03579 numr2i = numr(2,i); // The beginning point of this ring 03580 03581 t1 = circ1(numr2i) * circ2(numr2i); 03582 q(1) += t1; 03583 t(1) += t1; 03584 03585 t1 = circ1(numr2i+1) * circ2(numr2i+1); 03586 if (numr3i == maxrin) { 03587 q(2) += t1; 03588 t(2) += t1; 03589 } else { 03590 q(numr3i+1) += t1; 03591 t(numr3i+1) += t1; 03592 } 03593 03594 for (j=3; j<=numr3i; j += 2) { 03595 jc = j+numr2i-1; 03596 03597 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03598 // ----- ----- ----- ----- 03599 // t1 t2 t3 t4 03600 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i 03601 // ----- ----- ----- ----- 03602 // t1 t2 t3 t4 03603 03604 c1 = circ1(jc); 03605 c2 = circ1(jc+1); 03606 d1 = circ2(jc); 03607 d2 = circ2(jc+1); 03608 03609 t1 = c1 * d1; 03610 t2 = c2 * d2; 03611 t3 = c1 * d2; 03612 t4 = c2 * d1; 03613 03614 q(j) += t1 + t2; 03615 q(j+1) += -t3 + t4; 03616 t(j) += t1 - t2; 03617 t(j+1) += -t3 - t4; 03618 } 03619 } 03620 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<" "<<t(j) <<endl; 03621 fftr_d(q,ip); 03622 03623 qn = -1.0e20; 03624 03625 int jstart = 1+static_cast<int>(delta_start/360.0*maxrin); 03626 int jstep = static_cast<int>(delta/360.0*maxrin); 03627 if (jstep < 1) { jstep = 1; } 03628 03629 for (j=jstart; j<=maxrin; j+=jstep) {//cout <<" "<<j<<" "<<q(j) <<endl; 03630 if (q(j) >= qn) { 03631 qn = q(j); 03632 jtot = j; 03633 } 03634 } 03635 03636 //for (k=-3; k<=3; k++) { 03637 // j = ((jtot+k+maxrin-1)%maxrin)+1; 03638 // t7(k+4) = q(j); 03639 //} 03640 03641 // interpolate 03642 //prb1d(t7,7,&pos); 03643 //tot = (float)(jtot)+pos; 03644 // Do not interpolate 03645 tot = (float)(jtot); 03646 03647 // mirrored 03648 fftr_d(t,ip); 03649 03650 // find angle 03651 qm = -1.0e20; 03652 for (j=jstart; j<=maxrin;j+=jstep) {//cout <<" "<<j<<" "<<t(j) <<endl; 03653 if ( t(j) >= qm ) { 03654 qm = t(j); 03655 jtot = j; 03656 } 03657 } 03658 03659 //for (k=-3; k<=3; k++) { 03660 // j = ((jtot+k+maxrin-1)%maxrin) + 1; 03661 // t7(k+4) = t(j); 03662 //} 03663 03664 // interpolate 03665 03666 //prb1d(t7,7,&pos); 03667 //tmt = float(jtot) + pos; 03668 // Do not interpolate 03669 tmt = float(jtot); 03670 03671 free(t); 03672 free(q); 03673 03674 Dict retvals; 03675 retvals["qn"] = qn; 03676 retvals["tot"] = tot; 03677 retvals["qm"] = qm; 03678 retvals["tmt"] = tmt; 03679 return retvals; 03680 }
|
|
checks both straight & mirrored positions input - fourier transforms of rings!! circ1 already multiplied by weights! returns EM object with 1D ccf
Definition at line 4077 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. 04077 { 04078 04079 // dimension circ1(lcirc),circ2(lcirc) 04080 04081 int ip, jc, numr3i, numr2i, i, j; 04082 float t1, t2, t3, t4, c1, c2, d1, d2; 04083 04084 int nring = numr.size()/3; 04085 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 04086 int maxrin = numr[numr.size()-1]; 04087 04088 float* circ1b = circ1->get_data(); 04089 float* circ2b = circ2->get_data(); 04090 04091 // t(maxrin), q(maxrin) // removed +2 04092 double *t, *q; 04093 04094 q = (double*)calloc(maxrin,sizeof(double)); 04095 t = (double*)calloc(maxrin,sizeof(double)); 04096 04097 #ifdef _WIN32 04098 ip = -(int)(log((float)maxrin)/log(2.0f)); 04099 #else 04100 ip = -(int)(log2(maxrin)); 04101 #endif //_WIN32 04102 04103 // q - straight = circ1 * conjg(circ2) 04104 04105 // t - mirrored = conjg(circ1) * conjg(circ2) 04106 04107 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 04108 04109 for (i=1; i<=nring; i++) { 04110 04111 numr3i = numr(3,i); 04112 numr2i = numr(2,i); 04113 04114 t1 = circ1b(numr2i) * circ2b(numr2i); 04115 q(1) = q(1)+t1; 04116 t(1) = t(1)+t1; 04117 04118 t1 = circ1b(numr2i+1) * circ2b(numr2i+1); 04119 if (numr3i == maxrin) { 04120 q(2) += t1; 04121 t(2) += t1; 04122 } else { 04123 q(numr3i+1) += t1; 04124 t(numr3i+1) += t1; 04125 } 04126 04127 for (j=3; j<=numr3i; j=j+2) { 04128 jc = j+numr2i-1; 04129 04130 c1 = circ1b(jc); 04131 c2 = circ1b(jc+1); 04132 d1 = circ2b(jc); 04133 d2 = circ2b(jc+1); 04134 04135 t1 = c1 * d1; 04136 t3 = c1 * d2; 04137 t2 = c2 * d2; 04138 t4 = c2 * d1; 04139 04140 q(j) += t1 + t2; 04141 q(j+1) += - t3 + t4; 04142 t(j) += t1 - t2; 04143 t(j+1) += - t3 - t4; 04144 } 04145 } 04146 04147 // straight 04148 fftr_d(q,ip); 04149 04150 // mirrored 04151 fftr_d(t,ip); 04152 04153 EMData* out = new EMData(); 04154 out->set_size(maxrin,2,1); 04155 float *dout = out->get_data(); 04156 for (int i=0; i<maxrin; i++) {dout(i,0)=static_cast<float>(q[i]); dout(i,1)=static_cast<float>(t[i]);} 04157 //out->set_size(maxrin,1,1); 04158 //float *dout = out->get_data(); 04159 //for (int i=0; i<maxrin; i++) {dout(i,0)=q[i];} 04160 free(t); 04161 free(q); 04162 return out; 04163 }
|
|
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 4324 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. 04325 { 04326 04327 int ip, jc, numr3i, numr2i, i, j; 04328 float t1, t2, t3, t4, c1, c2, d1, d2; 04329 04330 int nring = numr.size()/3; 04331 int maxrin = numr[numr.size()-1]; 04332 04333 float* circ1b = circ1->get_data(); 04334 float* circ2b = circ2->get_data(); 04335 04336 double *t; 04337 04338 t = (double*)calloc(maxrin,sizeof(double)); 04339 04340 #ifdef _WIN32 04341 ip = -(int)(log((float)maxrin)/log(2.0f)); 04342 #else 04343 ip = -(int)(log2(maxrin)); 04344 #endif //_WIN32 04345 04346 // t - mirrored = conjg(circ1) * conjg(circ2) 04347 04348 for (i=1;i<=nring;i++) { 04349 04350 numr3i = numr(3,i); 04351 numr2i = numr(2,i); 04352 04353 t1 = circ1b(numr2i) * circ2b(numr2i); 04354 t(1) = t(1)+t1; 04355 04356 if (numr3i == maxrin) { 04357 t1 = circ1b(numr2i+1) * circ2b(numr2i+1); 04358 t(2) = t(2)+t1; 04359 } 04360 04361 for (j=3;j<=numr3i;j=j+2) { 04362 jc = j+numr2i-1; 04363 04364 c1 = circ1b(jc); 04365 c2 = circ1b(jc+1); 04366 d1 = circ2b(jc); 04367 d2 = circ2b(jc+1); 04368 04369 t1 = c1 * d1; 04370 t3 = c1 * d2; 04371 t2 = c2 * d2; 04372 t4 = c2 * d1; 04373 04374 t(j) = t(j) + t1 - t2; 04375 t(j+1) = t(j+1) - t3 - t4; 04376 } 04377 } 04378 04379 // mirrored 04380 fftr_d(t,ip); 04381 04382 EMData* out = new EMData(); 04383 out->set_size(maxrin,1,1); 04384 float *dout = out->get_data(); 04385 for (int i=0; i<maxrin; i++) dout[i]=static_cast<float>(t[i]); 04386 free(t); 04387 return out; 04388 04389 }
|
|
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 4253 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(). 04254 { 04255 04256 int ip, jc, numr3i, numr2i, i, j; 04257 float t1, t2, t3, t4, c1, c2, d1, d2; 04258 04259 int nring = numr.size()/3; 04260 int maxrin = numr[numr.size()-1]; 04261 04262 float* circ1b = circ1->get_data(); 04263 float* circ2b = circ2->get_data(); 04264 04265 double *q; 04266 04267 q = (double*)calloc(maxrin,sizeof(double)); 04268 04269 #ifdef _WIN32 04270 ip = -(int)(log((float)maxrin)/log(2.0f)); 04271 #else 04272 ip = -(int)(log2(maxrin)); 04273 #endif //_WIN32 04274 04275 // q - straight = circ1 * conjg(circ2) 04276 04277 for (i=1;i<=nring;i++) { 04278 04279 numr3i = numr(3,i); 04280 numr2i = numr(2,i); 04281 04282 t1 = circ1b(numr2i) * circ2b(numr2i); 04283 q(1) = q(1)+t1; 04284 04285 if (numr3i == maxrin) { 04286 t1 = circ1b(numr2i+1) * circ2b(numr2i+1); 04287 q(2) = q(2)+t1; 04288 } else { 04289 t1 = circ1b(numr2i+1) * circ2b(numr2i+1); 04290 q(numr3i+1) = q(numr3i+1)+t1; 04291 } 04292 04293 for (j=3;j<=numr3i;j=j+2) { 04294 jc = j+numr2i-1; 04295 04296 c1 = circ1b(jc); 04297 c2 = circ1b(jc+1); 04298 d1 = circ2b(jc); 04299 d2 = circ2b(jc+1); 04300 04301 t1 = c1 * d1; 04302 t3 = c1 * d2; 04303 t2 = c2 * d2; 04304 t4 = c2 * d1; 04305 04306 q(j) = q(j) + t1 + t2; 04307 q(j+1) = q(j+1) - t3 + t4; 04308 } 04309 } 04310 04311 // straight 04312 fftr_d(q,ip); 04313 04314 EMData* out = new EMData(); 04315 out->set_size(maxrin,1,1); 04316 float *dout = out->get_data(); 04317 for (int i=0; i<maxrin; i++) dout[i]=static_cast<float>(q[i]); 04318 free(q); 04319 return out; 04320 04321 }
|
|
checks both straight & mirrored positions input - fourier transforms of rings!! circ1 already multiplied by weights! returns EM object with 1D ccf
Definition at line 4181 of file util_sparx.cpp. References circ1, circ1b, circ2, circ2b, fftr_q(), EMAN::EMData::get_data(), log(), numr, q, and t. Referenced by ali2d_ccf_list(), Crosrng_msg_vec_p(), multiref_peaks_ali2d(), and multiref_peaks_compress_ali2d(). 04181 { 04182 04183 // dimension circ1(lcirc),circ2(lcirc) 04184 04185 int ip, jc, numr3i, numr2i, i, j; 04186 float t1, t2, t3, t4, c1, c2, d1, d2; 04187 04188 int nring = numr.size()/3; 04189 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 04190 int maxrin = numr[numr.size()-1]; 04191 04192 float* circ1b = circ1->get_data(); 04193 float* circ2b = circ2->get_data(); 04194 04195 #ifdef _WIN32 04196 ip = -(int)(log((float)maxrin)/log(2.0f)); 04197 #else 04198 ip = -(int)(log2(maxrin)); 04199 #endif //_WIN32 04200 for (int i=1; i<=maxrin; i++) {q(i) = 0.0f; t(i) = 0.0f;} 04201 04202 // q - straight = circ1 * conjg(circ2) 04203 04204 // t - mirrored = conjg(circ1) * conjg(circ2) 04205 04206 for (i=1; i<=nring; i++) { 04207 04208 numr3i = numr(3,i); 04209 numr2i = numr(2,i); 04210 04211 t1 = circ1b(numr2i) * circ2b(numr2i); 04212 q(1) += t1; 04213 t(1) += t1; 04214 04215 t1 = circ1b(numr2i+1) * circ2b(numr2i+1); 04216 if (numr3i == maxrin) { 04217 q(2) += t1; 04218 t(2) += t1; 04219 } else { 04220 q(numr3i+1) += t1; 04221 t(numr3i+1) += t1; 04222 } 04223 04224 for (j=3; j<=numr3i; j=j+2) { 04225 jc = j+numr2i-1; 04226 04227 c1 = circ1b(jc); 04228 c2 = circ1b(jc+1); 04229 d1 = circ2b(jc); 04230 d2 = circ2b(jc+1); 04231 04232 t1 = c1 * d1; 04233 t3 = c1 * d2; 04234 t2 = c2 * d2; 04235 t4 = c2 * d1; 04236 04237 q(j) += t1 + t2; 04238 q(j+1) += -t3 + t4; 04239 t(j) += t1 - t2; 04240 t(j+1) += -t3 - t4; 04241 } 04242 } 04243 // straight 04244 fftr_q(q,ip); 04245 //for (int i=0; i<maxrin; i++) cout<<i<<" B "<<q[i]<<" "<<t[i]<<endl; 04246 04247 // mirrored 04248 fftr_q(t,ip); 04249 }
|
|
Definition at line 4166 of file util_sparx.cpp. References circ1, circ2, Crosrng_msg_vec(), and numr. 04166 { 04167 04168 int maxrin = numr[numr.size()-1]; 04169 04170 vector<float> r(2*maxrin); 04171 04172 Crosrng_msg_vec( circ1, circ2, numr, &r[0], &r[maxrin] ); 04173 04174 return r; 04175 }
|
|
Definition at line 3978 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(). 03978 { 03979 int nring = numr.size()/3; 03980 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03981 int maxrin = numr[numr.size()-1]; 03982 double qn; float tot; 03983 float *circ1 = circ1p->get_data(); 03984 float *circ2 = circ2p->get_data(); 03985 /* 03986 c 03987 c checks only straight position 03988 c 03989 c input - fourier transforms of rings!! 03990 c circ1 already multiplied by weights! 03991 c 03992 */ 03993 03994 // dimension circ1(lcirc),circ2(lcirc) 03995 03996 // q(maxrin), t7(-3:3) //maxrin+2 removed 03997 double *q, t7[7]; 03998 03999 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 04000 float c1, c2, d1, d2, pos; 04001 04002 qn = 0.0; 04003 tot = 0.0; 04004 #ifdef _WIN32 04005 ip = -(int)(log((float)maxrin)/log(2.0f)); 04006 #else 04007 ip = -(int)(log2(maxrin)); 04008 #endif //_WIN32 04009 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl; 04010 04011 // c - straight = circ1 * conjg(circ2) 04012 // zero q array 04013 04014 q = (double*)calloc(maxrin,sizeof(double)); 04015 04016 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 04017 for (i=1; i<=nring; i++) { 04018 04019 numr3i = numr(3,i); // Number of samples of this ring 04020 numr2i = numr(2,i); // The beginning point of this ring 04021 04022 q(1) += circ1(numr2i) * circ2(numr2i); 04023 04024 if (numr3i == maxrin) q(2) += circ1(numr2i+1) * circ2(numr2i+1); 04025 else q(numr3i+1) += circ1(numr2i+1) * circ2(numr2i+1); 04026 04027 for (j=3; j<=numr3i; j += 2) { 04028 jc = j+numr2i-1; 04029 04030 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 04031 // ----- ----- ----- ----- 04032 // t1 t2 t3 t4 04033 04034 c1 = circ1(jc); 04035 c2 = circ1(jc+1); 04036 d1 = circ2(jc); 04037 d2 = circ2(jc+1); 04038 04039 q(j) += c1 * d1 + c2 * d2; 04040 q(j+1) += -c1 * d2 + c2 * d1; 04041 } 04042 } 04043 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<endl; 04044 fftr_d(q,ip); 04045 04046 qn = -1.0e20; 04047 for (j=1; j<=maxrin; j++) {//cout <<" "<<j<<" "<<q(j) <<endl; 04048 if (q(j) >= qn) { 04049 qn = q(j); 04050 jtot = j; 04051 } 04052 } 04053 04054 for (k=-3; k<=3; k++) { 04055 j = ((jtot+k+maxrin-1)%maxrin)+1; 04056 t7(k+4) = q(j); 04057 } 04058 04059 // interpolate 04060 prb1d(t7,7,&pos); 04061 tot = (float)(jtot)+pos; 04062 // Do not interpolate 04063 //*tot = (float)(jtot); 04064 04065 free(q); 04066 04067 Dict retvals; 04068 retvals["qn"] = qn; 04069 retvals["tot"] = tot; 04070 return retvals; 04071 }
|
|
checks both straight & mirrored positions Find only positions within +/-pis_max of 0 and 180 (for helcal use) input - fourier transforms of rings! circ1 already multiplied by weights!
Definition at line 3683 of file util_sparx.cpp. References circ1, circ2, fftr_d(), EMAN::EMData::get_data(), log(), numr, prb1d(), q, EMAN::Dict::size(), t, t7, tmt, and tot. Referenced by multiref_polar_ali_helical(). 03683 { 03684 int nring = numr.size()/3; 03685 //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 03686 int maxrin = numr[numr.size()-1]; 03687 double qn; float tot; double qm; float tmt; 03688 float *circ1 = circ1p->get_data(); 03689 float *circ2 = circ2p->get_data(); 03690 03691 // dimension circ1(lcirc),circ2(lcirc) 03692 03693 // t(maxrin), q(maxrin), t7(-3:3) //maxrin+2 removed 03694 double *t, *q, t7[7]; 03695 03696 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 03697 float t1, t2, t3, t4, c1, c2, d1, d2, pos; 03698 03699 qn = 0.0f; 03700 qm = 0.0f; 03701 tot = 0.0f; 03702 tmt = 0.0f; 03703 #ifdef _WIN32 03704 ip = -(int)(log((float)maxrin)/log(2.0f)); 03705 #else 03706 ip = -(int)(log2(maxrin)); 03707 #endif //_WIN32 03708 //for (j=1; j<=maxrin;j++) cout <<" "<<j<<" "<<circ1(j)<<" "<<circ2(j) <<endl; 03709 03710 // c - straight = circ1 * conjg(circ2) 03711 // zero q array 03712 03713 q = (double*)calloc(maxrin,sizeof(double)); 03714 03715 // t - mirrored = conjg(circ1) * conjg(circ2) 03716 // zero t array 03717 t = (double*)calloc(maxrin,sizeof(double)); 03718 03719 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03720 for (i=1; i<=nring; i++) { 03721 03722 numr3i = numr(3,i); // Number of samples of this ring 03723 numr2i = numr(2,i); // The beginning point of this ring 03724 03725 t1 = circ1(numr2i) * circ2(numr2i); 03726 q(1) += t1; 03727 t(1) += t1; 03728 03729 t1 = circ1(numr2i+1) * circ2(numr2i+1); 03730 if (numr3i == maxrin) { 03731 q(2) += t1; 03732 t(2) += t1; 03733 } else { 03734 q(numr3i+1) += t1; 03735 t(numr3i+1) += t1; 03736 } 03737 03738 for (j=3; j<=numr3i; j += 2) { 03739 jc = j+numr2i-1; 03740 03741 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03742 // ----- ----- ----- ----- 03743 // t1 t2 t3 t4 03744 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i 03745 // ----- ----- ----- ----- 03746 // t1 t2 t3 t4 03747 03748 c1 = circ1(jc); 03749 c2 = circ1(jc+1); 03750 d1 = circ2(jc); 03751 d2 = circ2(jc+1); 03752 03753 t1 = c1 * d1; 03754 t2 = c2 * d2; 03755 t3 = c1 * d2; 03756 t4 = c2 * d1; 03757 03758 q(j) += t1 + t2; 03759 q(j+1) += -t3 + t4; 03760 t(j) += t1 - t2; 03761 t(j+1) += -t3 - t4; 03762 } 03763 } 03764 //for (j=1; j<=maxrin; j++) cout <<" "<<j<<" "<<q(j) <<" "<<t(j) <<endl; 03765 fftr_d(q,ip); 03766 03767 int psi_range = int(psi_max/360.0*maxrin+0.5); 03768 const int psi_0 = 0; 03769 int psi_180 = int( 180.0/360.0*maxrin+0.5); 03770 03771 qn = -1.0e20; 03772 for (k=-psi_range; k<=psi_range; k++) { 03773 j = (k+psi_0+maxrin-1)%maxrin+1;//string modemo = "f";cout <<" 90 "<<j<<" "<<ang_n(j,modemo,maxrin) <<" "<<float(j)/maxrin*360.0<<" "<<q(j) <<endl; 03774 if (q(j) >= qn) { 03775 qn = q(j); 03776 jtot = j; 03777 } 03778 } 03779 03780 for (k=-psi_range; k<=psi_range; k++) { 03781 j = (k+psi_180+maxrin-1)%maxrin+1; //cout <<" 270 "<<j<<" "<<ang_n(j,modemo,maxrin) <<" "<<float(j)/maxrin*360.0<<" "<<q(j) <<endl; 03782 if (q(j) >= qn) { 03783 qn = q(j); 03784 jtot = j; 03785 } 03786 } 03787 03788 for (k=-3; k<=3; k++) { 03789 j = ((jtot+k+maxrin-1)%maxrin)+1; 03790 t7(k+4) = q(j); 03791 } 03792 03793 // interpolate 03794 prb1d(t7,7,&pos); 03795 tot = (float)(jtot)+pos; 03796 // Do not interpolate 03797 //tot = (float)(jtot); 03798 03799 // mirrored 03800 fftr_d(t,ip); 03801 03802 // find angle 03803 qm = -1.0e20; 03804 for (k=-psi_range; k<=psi_range; k++) { 03805 j = (k+psi_0+maxrin-1)%maxrin+1;//string modemo = "f";cout <<" 90 "<<j<<" "<<ang_n(j,modemo,maxrin) <<" "<<float(j)/maxrin*360.0<<" "<<q(j) <<endl; 03806 if (t(j) >= qm) { 03807 qm = t(j); 03808 jtot = j; 03809 } 03810 } 03811 03812 for (k=-psi_range; k<=psi_range; k++) { 03813 j = (k+psi_180+maxrin-1)%maxrin+1; //cout <<" 270 "<<j<<" "<<ang_n(j,modemo,maxrin) <<" "<<float(j)/maxrin*360.0<<" "<<q(j) <<endl; 03814 if (t(j) >= qm) { 03815 qm = t(j); 03816 jtot = j; 03817 } 03818 } 03819 03820 for (k=-3; k<=3; k++) { 03821 j = ((jtot+k+maxrin-1)%maxrin) + 1; 03822 t7(k+4) = t(j); 03823 } 03824 03825 // interpolate 03826 03827 prb1d(t7,7,&pos); 03828 tmt = float(jtot) + pos; 03829 // Do not interpolate 03830 //tmt = float(jtot); 03831 03832 free(t); 03833 free(q); 03834 03835 Dict retvals; 03836 retvals["qn"] = qn; 03837 retvals["tot"] = tot; 03838 retvals["qm"] = qm; 03839 retvals["tmt"] = tmt; 03840 return retvals; 03841 }
|
|
checks both straight & mirrored position input - fourier transforms of rings!! circ1 already multiplied by weights!
Definition at line 3844 of file util_sparx.cpp. References circ1, circ2, fftr_d(), flag, EMAN::EMData::get_data(), log(), numr, prb1d(), q, EMAN::Dict::size(), t7, tmt, and tot. Referenced by multiref_polar_ali_2d_local_psi(). 03844 { 03845 // flag 0 - straignt, 1 - mirror 03846 03847 int nring = numr.size()/3; 03848 int maxrin = numr[numr.size()-1]; 03849 double qn; float tot; double qm; float tmt; 03850 float *circ1 = circ1p->get_data(); 03851 float *circ2 = circ2p->get_data(); 03852 03853 double *q, t7[7]; 03854 03855 int ip, jc, numr3i, numr2i, i, j, k, jtot = 0; 03856 float t1, t2, t3, t4, c1, c2, d1, d2, pos; 03857 03858 qn = 0.0f; 03859 qm = 0.0f; 03860 tot = 0.0f; 03861 tmt = 0.0f; 03862 #ifdef _WIN32 03863 ip = -(int)(log((float)maxrin)/log(2.0f)); 03864 #else 03865 ip = -(int)(log2(maxrin)); 03866 #endif //_WIN32 03867 03868 // c - straight = circ1 * conjg(circ2) 03869 // zero q array 03870 03871 q = (double*)calloc(maxrin,sizeof(double)); 03872 03873 // premultiply arrays ie( circ12 = circ1 * circ2) much slower 03874 if (flag==0) { 03875 for (i=1; i<=nring; i++) { 03876 03877 numr3i = numr(3,i); // Number of samples of this ring 03878 numr2i = numr(2,i); // The beginning point of this ring 03879 03880 t1 = circ1(numr2i) * circ2(numr2i); 03881 q(1) += t1; 03882 03883 t1 = circ1(numr2i+1) * circ2(numr2i+1); 03884 if (numr3i == maxrin) { 03885 q(2) += t1; 03886 } else { 03887 q(numr3i+1) += t1; 03888 } 03889 03890 for (j=3; j<=numr3i; j += 2) { 03891 jc = j+numr2i-1; 03892 03893 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03894 // ----- ----- ----- ----- 03895 // t1 t2 t3 t4 03896 03897 c1 = circ1(jc); 03898 c2 = circ1(jc+1); 03899 d1 = circ2(jc); 03900 d2 = circ2(jc+1); 03901 03902 t1 = c1 * d1; 03903 t3 = c1 * d2; 03904 t2 = c2 * d2; 03905 t4 = c2 * d1; 03906 03907 q(j) += t1 + t2; 03908 q(j+1) += -t3 + t4; 03909 } 03910 } 03911 } else { 03912 for (i=1; i<=nring; i++) { 03913 03914 numr3i = numr(3,i); // Number of samples of this ring 03915 numr2i = numr(2,i); // The beginning point of this ring 03916 03917 t1 = circ1(numr2i) * circ2(numr2i); 03918 q(1) += t1; 03919 03920 t1 = circ1(numr2i+1) * circ2(numr2i+1); 03921 if (numr3i == maxrin) { 03922 q(2) += t1; 03923 } else { 03924 q(numr3i+1) += t1; 03925 } 03926 03927 for (j=3; j<=numr3i; j += 2) { 03928 jc = j+numr2i-1; 03929 03930 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i 03931 // ----- ----- ----- ----- 03932 // t1 t2 t3 t4 03933 03934 c1 = circ1(jc); 03935 c2 = circ1(jc+1); 03936 d1 = circ2(jc); 03937 d2 = circ2(jc+1); 03938 03939 t1 = c1 * d1; 03940 t3 = c1 * d2; 03941 t2 = c2 * d2; 03942 t4 = c2 * d1; 03943 03944 q(j) += t1 - t2; 03945 q(j+1) += -t3 - t4; 03946 } 03947 } 03948 } 03949 fftr_d(q,ip); 03950 03951 qn = -1.0e20; 03952 int psi_pos = int(psi/360.0*maxrin+0.5); 03953 03954 for (k=-5; k<=5; k++) { 03955 j = (psi_pos+maxrin-1)%maxrin+1; 03956 if (q(j) >= qn) { 03957 qn = q(j); 03958 jtot = j; 03959 } 03960 } 03961 03962 for (k=-3; k<=3; k++) { 03963 j = ((jtot+k+maxrin-1)%maxrin)+1; 03964 t7(k+4) = q(j); 03965 } 03966 03967 // interpolate 03968 prb1d(t7,7,&pos); 03969 tot = (float)(jtot)+pos; 03970 free(q); 03971 03972 Dict retvals; 03973 retvals["qn"] = qn; 03974 retvals["tot"] = tot; 03975 return retvals; 03976 }
|
|
Definition at line 19532 of file util_sparx.cpp. References nx, ny, EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), EMAN::EMData::set_ri(), EMAN::EMData::set_size(), sign, tf(), and EMAN::EMData::update(). 19533 { 19534 int ix, iy, iz; 19535 int i, j, k; 19536 int nr2, nl2; 19537 float dzz, az, ak; 19538 float scx, scy, scz; 19539 int offset = 2 - nx%2; 19540 int lsm = nx + offset; 19541 EMData* ctf_img1 = new EMData(); 19542 ctf_img1->set_size(lsm, ny, nz); 19543 float freq = 1.0f/(2.0f*ps); 19544 scx = 2.0f/float(nx); 19545 if(ny>=1) scy = 2.0f/float(ny); else scy=0.0f; 19546 if(nz>=1) scz = 2.0f/float(nz); else scz=0.0f; 19547 nr2 = ny/2 ; 19548 nl2 = nz/2 ; 19549 for ( k=0; k<nz;k++) { 19550 iz = k; if(k>nl2) iz=k-nz; 19551 for ( j=0; j<ny;j++) { 19552 iy = j; if(j>nr2) iy=j - ny; 19553 for ( i=0; i<lsm/2; i++) { 19554 ix=i; 19555 ak=pow(ix*ix*scx*scx+iy*scy*iy*scy+iz*scz*iz*scz, 0.5f)*freq; 19556 if(ak!=0) az=0.0; else az=M_PI; 19557 dzz = dz + dza/2.0f*sin(2*(az-azz*M_PI/180.0f)); 19558 (*ctf_img1) (i*2,j,k) = Util::tf(dzz, ak, voltage, cs, wgh, b_factor, sign); 19559 (*ctf_img1) (i*2+1,j,k) = 0.0f; 19560 } 19561 } 19562 } 19563 ctf_img1->update(); 19564 ctf_img1->set_complex(true); 19565 ctf_img1->set_ri(true); 19566 //ctf_img1->attr_dict["is_complex"] = 1; 19567 //ctf_img1->attr_dict["is_ri"] = 1; 19568 if(nx%2==0) ctf_img1->set_fftodd(false); else ctf_img1->set_fftodd(true); 19569 return ctf_img1; 19570 }
|
|
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 5365 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(). 05365 { 05366 05367 if (image->is_complex()) throw ImageFormatException("Real image required for IntegerCyclicShift2DProcessor"); 05368 05369 int dx = params["dx"]; 05370 int dy = params["dy"]; 05371 int dz = params["dz"]; 05372 05373 // The reverse trick we're using shifts to the left (a negative shift) 05374 int nx = image->get_xsize(); 05375 dx %= nx; 05376 if (dx < 0) dx += nx; 05377 int ny = image->get_ysize(); 05378 dy %= ny; 05379 if (dy < 0) dy += ny; 05380 int nz = image->get_zsize(); 05381 dz %= nz; 05382 if (dz < 0) dz += nz; 05383 05384 int mx = -(dx - nx); 05385 int my = -(dy - ny); 05386 int mz = -(dz - nz); 05387 05388 float* data = image->get_data(); 05389 // x-reverses 05390 if (mx != 0) { 05391 for (int iz = 0; iz < nz; iz++) 05392 for (int iy = 0; iy < ny; iy++) { 05393 // reverses for column iy 05394 int offset = nx*iy + nx*ny*iz; // starting location for column iy in slice iz 05395 reverse(&data[offset],&data[offset+mx]); 05396 reverse(&data[offset+mx],&data[offset+nx]); 05397 reverse(&data[offset],&data[offset+nx]); 05398 } 05399 } 05400 // y-reverses 05401 if (my != 0) { 05402 for (int iz = 0; iz < nz; iz++) { 05403 int offset = nx*ny*iz; 05404 colreverse(&data[offset], &data[offset + my*nx], nx); 05405 colreverse(&data[offset + my*nx], &data[offset + ny*nx], nx); 05406 colreverse(&data[offset], &data[offset + ny*nx], nx); 05407 } 05408 } 05409 if (mz != 0) { 05410 slicereverse(&data[0], &data[mz*ny*nx], nx, ny); 05411 slicereverse(&data[mz*ny*nx], &data[nz*ny*nx], nx, ny); 05412 slicereverse(&data[0], &data[nz*ny*nx], nx ,ny); 05413 } 05414 image->update(); 05415 }
|
|
Definition at line 5159 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(). 05160 { 05161 /* Exception Handle */ 05162 if (!img) { 05163 throw NullPointerException("NULL input image"); 05164 } 05165 /* ============================== */ 05166 05167 // Get the size of the input image 05168 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 05169 /* ============================== */ 05170 05171 05172 /* Exception Handle */ 05173 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) 05174 { 05175 LOGERR("Parameters for decimation cannot exceed the center of the image."); 05176 throw ImageDimensionException("Parameters for decimation cannot exceed the center of the image."); 05177 } 05178 /* ============================== */ 05179 05180 05181 /* Calculation of the start point */ 05182 int new_st_x=(nx/2)%x_step, new_st_y=(ny/2)%y_step, new_st_z=(nz/2)%z_step; 05183 /* ============================*/ 05184 05185 05186 /* Calculation of the size of the decimated image */ 05187 int rx=2*(nx/(2*x_step)), ry=2*(ny/(2*y_step)), rz=2*(nz/(2*z_step)); 05188 int r1=int(ceil((nx-(x_step*rx))/(1.f*x_step))), r2=int(ceil((ny-(y_step*ry))/(1.f*y_step))); 05189 int r3=int(ceil((nz-(z_step*rz))/(1.f*z_step))); 05190 if(r1>1){r1=1;} 05191 if(r2>1){r2=1;} 05192 if(r3>1){r3=1;} 05193 int new_nx=rx+r1, new_ny=ry+r2, new_nz=rz+r3; 05194 /* ===========================================*/ 05195 05196 05197 EMData* img2 = new EMData(); 05198 img2->set_size(new_nx,new_ny,new_nz); 05199 float *new_ptr = img2->get_data(); 05200 float *old_ptr = img->get_data(); 05201 int iptr, jptr, kptr = 0; 05202 for (int k=new_st_z; k<nz; k+=z_step) {jptr=0; 05203 for (int j=new_st_y; j<ny; j+=y_step) {iptr=0; 05204 for (int i=new_st_x; i<nx; i+=x_step) { 05205 new_ptr(iptr,jptr,kptr) = old_ptr(i,j,k); 05206 iptr++;} 05207 jptr++;} 05208 kptr++;} 05209 img2->update(); 05210 return img2; 05211 }
|
|
Definition at line 7670 of file util_sparx.cpp. 07671 { 07672 ENTERFUNC; 07673 int k, i; 07674 for(i=0; i<len; i++) key[i]=i+1; 07675 07676 for(i = 0; i<len;i++){ 07677 k = rand()%len; 07678 std::swap(key[k], key[i]); 07679 std::swap(x[k], x[i]); 07680 std::swap(y[k], y[i]); 07681 } 07682 EXITFUNC; 07683 }
|
|
Definition at line 17629 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageFormatException, img_ptr, EMAN::EMData::is_complex(), NullPointerException, nx, ny, and EMAN::EMData::update(). 17630 { 17631 ENTERFUNC; 17632 /* Exception Handle */ 17633 if (!img) { 17634 throw NullPointerException("NULL input image"); 17635 } 17636 /* ========= img /= img1 ===================== */ 17637 17638 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17639 int size = nx*ny*nz; 17640 float *img_ptr = img->get_data(); 17641 float *img1_ptr = img1->get_data(); 17642 if(img->is_complex()) { 17643 for (int i=0; i<size; i+=2) { 17644 if(img1_ptr[i] > 1.e-10f) { 17645 img_ptr[i] /= img1_ptr[i]; 17646 img_ptr[i+1] /= img1_ptr[i]; 17647 } else img_ptr[i] = img_ptr[i+1] = 0.0f; 17648 } 17649 } else throw ImageFormatException("Only Fourier image allowed"); 17650 17651 img->update(); 17652 17653 EXITFUNC; 17654 }
|
|
Definition at line 17600 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, EMAN::EMData::is_complex(), NullPointerException, nx, ny, and EMAN::EMData::update(). 17601 { 17602 ENTERFUNC; 17603 /* Exception Handle */ 17604 if (!img) { 17605 throw NullPointerException("NULL input image"); 17606 } 17607 /* ========= img /= img1 ===================== */ 17608 17609 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17610 int size = nx*ny*nz; 17611 float *img_ptr = img->get_data(); 17612 float *img1_ptr = img1->get_data(); 17613 if(img->is_complex()) { 17614 float sq2; 17615 for (int i=0; i<size; i+=2) { 17616 sq2 = 1.0f/(img1_ptr[i] * img1_ptr[i] + img1_ptr[i+1] * img1_ptr[i+1]); 17617 float tmp = sq2*(img_ptr[i] * img1_ptr[i] + img_ptr[i+1] * img1_ptr[i+1]) ; 17618 img_ptr[i+1] = sq2*(img_ptr[i+1] * img1_ptr[i] - img_ptr[i] * img1_ptr[i+1]) ; 17619 img_ptr[i] = tmp; 17620 } 17621 } else { 17622 for (int i=0; i<size; i++) img_ptr[i] /= img1_ptr[i]; 17623 } 17624 img->update(); 17625 17626 EXITFUNC; 17627 }
|
|
Definition at line 17425 of file util_sparx.cpp. References EMAN::EMData::copy_head(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageFormatException, img2_ptr, img_ptr, EMAN::EMData::is_complex(), NullPointerException, nx, ny, and EMAN::EMData::update(). 17426 { 17427 ENTERFUNC; 17428 /* Exception Handle */ 17429 if (!img) { 17430 throw NullPointerException("NULL input image"); 17431 } 17432 /* ========= img /= img1 ===================== */ 17433 17434 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17435 int size = nx*ny*nz; 17436 EMData * img2 = img->copy_head(); 17437 float *img_ptr =img->get_data(); 17438 float *img1_ptr = img1->get_data(); 17439 float *img2_ptr = img2->get_data(); 17440 if(img->is_complex()) { 17441 for (int i=0; i<size; i+=2) { 17442 if(img1_ptr[i] > 1.e-10f) { 17443 img2_ptr[i] = img_ptr[i] /img1_ptr[i]; 17444 img2_ptr[i+1] = img_ptr[i+1]/img1_ptr[i]; 17445 } else img2_ptr[i] = img2_ptr[i+1] = 0.0f; 17446 } 17447 } else throw ImageFormatException("Only Fourier image allowed"); 17448 17449 img->update(); 17450 17451 EXITFUNC; 17452 return img2; 17453 }
|
|
Definition at line 17392 of file util_sparx.cpp. References EMAN::EMData::copy_head(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img2_ptr, img_ptr, EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), NullPointerException, nx, ny, EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), and EMAN::EMData::update(). 17393 { 17394 ENTERFUNC; 17395 /* Exception Handle */ 17396 if (!img) { 17397 throw NullPointerException("NULL input image"); 17398 } 17399 /* ============== output = img / img1 ================ */ 17400 17401 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17402 int size = nx*ny*nz; 17403 EMData * img2 = img->copy_head(); 17404 float *img_ptr =img->get_data(); 17405 float *img2_ptr = img2->get_data(); 17406 float *img1_ptr = img1->get_data(); 17407 if(img->is_complex()) { 17408 float sq2; 17409 for (int i=0; i<size; i+=2) { 17410 sq2 = 1.0f/(img1_ptr[i] * img1_ptr[i] + img1_ptr[i+1] * img1_ptr[i+1]); 17411 img2_ptr[i] = sq2*(img_ptr[i] * img1_ptr[i] + img_ptr[i+1] * img1_ptr[i+1]) ; 17412 img2_ptr[i+1] = sq2*(img_ptr[i+1] * img1_ptr[i] - img_ptr[i] * img1_ptr[i+1]) ; 17413 } 17414 img2->set_complex(true); 17415 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17416 } else { 17417 for (int i=0; i<size; i++) img2_ptr[i] = img_ptr[i] / img1_ptr[i]; 17418 img2->update(); 17419 } 17420 17421 EXITFUNC; 17422 return img2; 17423 }
|
|
copy sign of a number. return a value whose absolute value matches that of 'a', but whose sign matches that of 'b'. If 'a' is a NaN, then a NaN with the sign of 'b' is returned. It is exactly copysign() on non-Windows system.
|
|
complementary error function. It is exactly erfc() on non-Windows system. On Windows, it tries to simulate erfc(). The erf() function returns the error function of x; defined as erf(x) = 2/sqrt(pi)* integral from 0 to x of exp(-t*t) dt The erfc() function returns the complementary error function of x, that is 1.0 - erf(x).
Definition at line 1974 of file util.h. Referenced by EMAN::IterationAverager::finish(). |
|
Definition at line 4406 of file util_sparx.cpp. References EMAN::EMData::get_data(), numr, and PI2. 04406 { 04407 ENTERFUNC; 04408 long double ener,en; 04409 04410 int nring = numr.size()/3; 04411 float *aveptr = ave->get_data(); 04412 04413 ener = 0.0; 04414 for (int i=1; i<=nring; i++) { 04415 int numr3i = numr(3,i); 04416 int np = numr(2,i)-1; 04417 float tq = static_cast<float>(PI2*numr(1,i)/numr3i); 04418 en = tq*(aveptr[np]*aveptr[np]+aveptr[np+1]*aveptr[np+1])*0.5; 04419 for (int j=np+2; j<np+numr3i-1; j++) en += tq*aveptr[j]*aveptr[j]; 04420 ener += en/numr3i; 04421 } 04422 EXITFUNC; 04423 return static_cast<float>(ener); 04424 }
|
|
Definition at line 4426 of file util_sparx.cpp. References data, EMAN::EMData::get_data(), numr, PI2, and tot. 04426 { 04427 ENTERFUNC; 04428 long double ener, en; 04429 float arg, cs, si; 04430 04431 int nima = data.size(); 04432 int nring = numr.size()/3; 04433 int maxrin = numr(3,nring); 04434 04435 ener = 0.0; 04436 for (int i=1; i<=nring; i++) { 04437 int numr3i = numr(3,i); 04438 int np = numr(2,i)-1; 04439 float tq = static_cast<float>(PI2*numr(1,i)/numr3i); 04440 float temp1 = 0.0, temp2 = 0.0; 04441 for (int kk=0; kk<nima; kk++) { 04442 float *ptr = data[kk]->get_data(); 04443 temp1 += ptr[np]; 04444 temp2 += static_cast<float>(ptr[np+1]*cos(PI2*(tot[kk]-1.0f)/2.0f*numr3i/maxrin)); 04445 } 04446 en = tq*(temp1*temp1+temp2*temp2)*0.5; 04447 for (int j=2; j<numr3i; j+=2) { 04448 float tempr = 0.0, tempi = 0.0; 04449 for (int kk=0; kk<nima; kk++) { 04450 float *ptr = data[kk]->get_data(); 04451 arg = static_cast<float>( PI2*(tot[kk]-1.0)*(j/2)/maxrin ); 04452 cs = cos(arg); 04453 si = sin(arg); 04454 tempr += ptr[np + j]*cs - ptr[np + j +1]*si; 04455 tempi += ptr[np + j]*si + ptr[np + j +1]*cs; 04456 } 04457 en += tq*(tempr*tempr+tempi*tempi); 04458 } 04459 ener += en/numr3i; 04460 } 04461 EXITFUNC; 04462 return static_cast<float>(ener); 04463 }
|
|
Determine the equation of a plane that intersects 3 points in 3D space. Required by Symmetry3D::reduce IMPORTANT - does no error checking, if the float pointer is less than 4 in size will get unknown behavior
Definition at line 1223 of file util.cpp. References EMAN::Vec3f, x, and y. Referenced by EMAN::Symmetry3D::cache_au_planes(). 01224 { 01225 int x=0,y=1,z=2; 01226 plane[0] = p1[y]*(p2[z]-p3[z])+p2[y]*(p3[z]-p1[z])+p3[y]*(p1[z]-p2[z]); 01227 plane[1] = p1[z]*(p2[x]-p3[x])+p2[z]*(p3[x]-p1[x])+p3[z]*(p1[x]-p2[x]); 01228 plane[2] = p1[x]*(p2[y]-p3[y])+p2[x]*(p3[y]-p1[y])+p3[x]*(p1[y]-p2[y]); 01229 plane[3] = p1[x]*(p2[y]*p3[z]-p3[y]*p2[z])+p2[x]*(p3[y]*p1[z]-p1[y]*p3[z])+p3[x]*(p1[y]*p2[z]-p2[y]*p1[z]); 01230 plane[3] = -plane[3]; 01231 }
|
|
Definition at line 7018 of file util_sparx.cpp. References EMAN::EMData::get_data(), images, and EMAN::EMData::read_image(). 07019 { 07020 int j,d; 07021 EMData * e = new EMData(); 07022 float *eptr, *imgptr; 07023 imgptr = img->get_data(); 07024 float SSE = 0.f; 07025 for (j = 0 ; j < N ; j++) { 07026 e->read_image(images,S[j]); 07027 eptr = e->get_data(); 07028 for (d = 0; d < size; d++) { 07029 SSE += ((eptr[d] - imgptr[d])*(eptr[d] - imgptr[d]));} 07030 } 07031 delete e; 07032 return SSE; 07033 }
|
|
Compute a vector containing quasi-evenly spaced Euler angles. The order of angles in the vector is phi, theta, psi.
Definition at line 506 of file util_sparx.cpp. References angles, dgr_to_rad, phi, and theta. 00507 { 00508 vector<float> angles; 00509 float psi = 0.0; 00510 if ((0.0 == t1 && 0.0 == t2)||(t1 >= t2)) { 00511 t1 = 0.0f; 00512 t2 = 90.0f; 00513 } 00514 if ((0.0 == p1 && 0.0 == p2)||(p1 >= p2)) { 00515 p1 = 0.0f; 00516 p2 = 359.9f; 00517 } 00518 bool skip = ((t1 < 90.0)&&(90.0 == t2)&&(0.0 == p1)&&(p2 > 180.0)); 00519 for (float theta = t1; theta <= t2; theta += delta) { 00520 float detphi; 00521 int lt; 00522 if ((0.0 == theta)||(180.0 == theta)) { 00523 detphi = 360.0f; 00524 lt = 1; 00525 } else { 00526 detphi = delta/sin(theta*static_cast<float>(dgr_to_rad)); 00527 lt = int((p2 - p1)/detphi)-1; 00528 if (lt < 1) lt = 1; 00529 detphi = (p2 - p1)/lt; 00530 } 00531 for (int i = 0; i < lt; i++) { 00532 float phi = p1 + i*detphi; 00533 if (skip&&(90.0 == theta)&&(phi > 180.0)) continue; 00534 angles.push_back(phi); 00535 angles.push_back(theta); 00536 angles.push_back(psi); 00537 } 00538 } 00539 return angles; 00540 }
|
|
Each class in Parts has its dummy variable set to 0 or 1. Only consider those with its dummy variable set to 1 (the 'active' ones) First element of each class is its original index, second is the dummy variable slot. Definition at line 20436 of file util_sparx.cpp. References k_means_cont_table_(). Referenced by initial_prune(). 20436 { 20437 20438 20439 if (size_next <= T) return 0; 20440 20441 // take the intx of next and cur 20442 int* curintx2(0); 20443 int nintx = Util::k_means_cont_table_(curintx, next+2, curintx2, size_curintx, size_next,0); 20444 if (nintx <= T) return 0; 20445 20446 int old_depth=depth; 20447 if (depth == partref) depth = depth + 1; // we skip classes in partref 20448 if (depth == (nParts)) { if (old_depth>0) return 1;} 20449 20450 // have not yet reached a leaf, and current weight is still greather than T, so keep on going. 20451 20452 curintx2 = new int[nintx]; // put the intersection set in here 20453 Util::k_means_cont_table_(curintx,next+2,curintx2, size_curintx, size_next,1); 20454 20455 // if (old_depth > 0) {delete[] curintx;} // don't delete when depth == 0 because curintx in that case is a pointer into Parts 20456 20457 // we now consider each of the classes in partition (depth+1) in turn 20458 bool gt_thresh; 20459 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 20460 20461 for (int i=0; i < num_classes; i++){ 20462 if (*(Parts[depth][i]+1) < 1) continue; // class is not active so move on 20463 size_next = (*(dimClasses + depth*K+(*(Parts[depth][i])) ))-2; 20464 gt_thresh = explore(Parts,dimClasses, nParts, K, T, partref, curintx2,nintx, Parts[depth][i], size_next, depth+1); 20465 if (gt_thresh) return 1; 20466 } 20467 delete[] curintx2; 20468 return 0; 20469 }
|
|
Definition at line 20269 of file util_sparx.cpp. References explore2(), and k_means_cont_table_(). 20269 { 20270 20271 // depth is the level which is going to be explored in the current iteration 20272 int* curintx2(0); 20273 int nintx = size_curintx; 20274 20275 20276 // 2. take the intx of next and cur. Prune if <= T 20277 if (depth >0){ 20278 nintx = Util::k_means_cont_table_(curintx,next, curintx2, size_curintx, size_next,0); 20279 if (nintx <= T) return; //prune! 20280 } 20281 20282 // 1. we're at a leaf with weight > T, so determine if there is any empty space. If so, put it in. If not, determine if current cost is larger than any of the cost in matchlist, if so, replace the smallest one in matchlist 20283 if (depth == (nParts-1)) { 20284 20285 int replace = 0; 20286 int ind_smallest = -1; 20287 int smallest_cost = -1; 20288 20289 for (int jit = 0; jit < J; jit++){ 20290 if (*(costlist+jit) < nintx){ 20291 replace = 1; 20292 if (ind_smallest == -1) {ind_smallest = jit; smallest_cost = *(costlist+jit);} 20293 if (*(costlist+jit) < smallest_cost) {ind_smallest = jit; smallest_cost = *(costlist+jit);} 20294 } 20295 } 20296 20297 if (replace > 0){ 20298 // replace the smallest cost in matchlist with the current stuff 20299 *(costlist + ind_smallest) = nintx; 20300 for (int xit = 0; xit < nParts; xit++) 20301 *(matchlist + ind_smallest*nParts + xit) = *(curbranch+xit); 20302 20303 } 20304 20305 return; 20306 } 20307 20308 20309 // 3. have not yet reached a leaf, and current weight is still greather than T, so keep on going. 20310 20311 if (depth > 0){ 20312 curintx2 = new int[nintx]; // put the intersection set in here 20313 Util::k_means_cont_table_(curintx,next,curintx2, size_curintx, size_next,1); 20314 } 20315 20316 if (depth == 0){ 20317 // set curintx2 to curintx 20318 curintx2 = new int[size_curintx]; 20319 for (int cp = 0; cp < size_curintx; cp++) *(curintx2+cp) = *(curintx+cp); 20320 } 20321 20322 20323 // recursion (non-leaf case) 20324 depth=depth+1; 20325 // we now consider each of the classes in partition depth and recurse upon each of them 20326 for (int i=0; i < K; i++){ 20327 20328 if (*(argParts + Indices[depth*K+i] + 1) < 1) continue; // class is not active so move on 20329 size_next = (*(dimClasses + depth*K+i ))-2; 20330 if (size_next <= T) continue; 20331 *(curbranch+depth) = i; 20332 Util::explore2(argParts,Indices, dimClasses, nParts, K, T, curintx2, nintx, argParts + Indices[depth*K+i] + 2, size_next, depth,J, matchlist, 20333 costlist, curbranch); 20334 20335 } 20336 20337 delete[] curintx2; 20338 }
|
|
Definition at line 1684 of file util_sparx.cpp. References EMAN::EMData::cmplx(), EMAN::Util::KaiserBessel::i0win_tab(), ImageDimensionException, and nx. 01684 { 01685 01686 int nxreal = nx - 2; 01687 if (nxreal != ny) 01688 throw ImageDimensionException("extractpoint requires ny == nx"); 01689 int nhalf = nxreal/2; 01690 bool flip = (nuxnew < 0.f); 01691 if (flip) { 01692 nuxnew *= -1; 01693 nuynew *= -1; 01694 } 01695 if (nuynew >= nhalf-0.5) { 01696 nuynew -= nxreal; 01697 } else if (nuynew < -nhalf-0.5) { 01698 nuynew += nxreal; 01699 } 01700 01701 // put (xnew,ynew) on a grid. The indices will be wrong for 01702 // the Fourier elements in the image, but the grid sizing will 01703 // be correct. 01704 int ixn = int(Util::round(nuxnew)); 01705 int iyn = int(Util::round(nuynew)); 01706 01707 // set up some temporary weighting arrays 01708 static float wy[7]; 01709 static float wx[7]; 01710 01711 float iynn = nuynew - iyn; 01712 wy[0] = kb.i0win_tab(iynn+3); 01713 wy[1] = kb.i0win_tab(iynn+2); 01714 wy[2] = kb.i0win_tab(iynn+1); 01715 wy[3] = kb.i0win_tab(iynn); 01716 wy[4] = kb.i0win_tab(iynn-1); 01717 wy[5] = kb.i0win_tab(iynn-2); 01718 wy[6] = kb.i0win_tab(iynn-3); 01719 01720 float ixnn = nuxnew - ixn; 01721 wx[0] = kb.i0win_tab(ixnn+3); 01722 wx[1] = kb.i0win_tab(ixnn+2); 01723 wx[2] = kb.i0win_tab(ixnn+1); 01724 wx[3] = kb.i0win_tab(ixnn); 01725 wx[4] = kb.i0win_tab(ixnn-1); 01726 wx[5] = kb.i0win_tab(ixnn-2); 01727 wx[6] = kb.i0win_tab(ixnn-3); 01728 01729 float wsum = (wx[0]+wx[1]+wx[2]+wx[3]+wx[4]+wx[5]+wx[6])*(wy[0]+wy[1]+wy[2]+wy[3]+wy[4]+wy[5]+wy[6]); 01730 01731 complex<float> result(0.f,0.f); 01732 if ((ixn >= 3) && (ixn <= nhalf-3) && (iyn >= -nhalf+3) && (iyn <= nhalf-4)) { 01733 // (xin,yin) not within window border from the edge 01734 for (int iy = 0; iy < 7; iy++) { 01735 int iyp = iyn + iy - 3 ; 01736 for (int ix = 0; ix < 7; ix++) { 01737 int ixp = ixn + ix - 3; 01738 float w = wx[ix]*wy[iy]; 01739 complex<float> val = fimage->cmplx(ixp,iyp); 01740 result += val*w; 01741 } 01742 } 01743 } else { 01744 // points that "stick out" 01745 for (int iy = 0; iy < 7; iy++) { 01746 int iyp = iyn + iy - 3; 01747 for (int ix = 0; ix < 7; ix++) { 01748 int ixp = ixn + ix - 3; 01749 bool mirror = false; 01750 int ixt = ixp, iyt = iyp; 01751 if (ixt < 0) { 01752 ixt = -ixt; 01753 iyt = -iyt; 01754 mirror = !mirror; 01755 } 01756 if (ixt > nhalf) { 01757 ixt = nxreal - ixt; 01758 iyt = -iyt; 01759 mirror = !mirror; 01760 } 01761 if (iyt > nhalf-1) iyt -= nxreal; 01762 if (iyt < -nhalf) iyt += nxreal; 01763 float w = wx[ix]*wy[iy]; 01764 complex<float> val = fimage->cmplx(ixt,iyt); 01765 if (mirror) result += conj(val)*w; 01766 else result += val*w; 01767 } 01768 } 01769 } 01770 if (flip) result = conj(result)/wsum; 01771 else result /= wsum; 01772 return result; 01773 }
|
|
Returns an approximate of acos(x) using a cached table and linear interpolation tolerates values very slightly outside the -1 - 1 range (returning 0).
Definition at line 783 of file util.cpp. 00783 { 00784 if (f>=1.0) return 0.0; 00785 if (f<=-1.0) return M_PI; 00786 00787 static float *mem = (float *)malloc(sizeof(float)*2001); 00788 static bool needinit=true; 00789 00790 00791 if (needinit) { 00792 needinit=false; 00793 for (int i=0; i<=2000; i++) mem[i]=(float)acos(i/1000.0-1.0); 00794 } 00795 float f2=f*1000.0f+1000.0f; 00796 00797 int g=(int)(f2+.5); 00798 00799 return mem[g]; 00800 00801 // This version interpolates, but is slower 00802 /*int g=(int)f2; 00803 f2-=g; 00804 return mem[g+1]*f2+mem[g]*(1.0-f2);*/ 00805 }
|
|
Returns an approximate of exp(x) using a cached table uses actual exp(x) outside the cached range.
Definition at line 767 of file util.cpp. Referenced by EMAN::FourierInserter3DMode5::insert_pixel(), EMAN::FourierInserter3DMode3::insert_pixel(), EMAN::FourierInserter3DMode2::insert_pixel(), EMAN::WienerFourierReconstructor::pixel_at(), and EMAN::FourierReconstructor::pixel_at(). 00767 { 00768 static float *mem = (float *)malloc(sizeof(float)*1000); 00769 static bool needinit=true; 00770 00771 if (needinit) { 00772 needinit=false; 00773 for (int i=0; i<1000; i++) mem[i]=(float)exp(-i/50.0); 00774 } 00775 if (f>0 || f<-19.98) return exp(f); 00776 int g=(int)(-f*50.0+0.5); 00777 00778 return mem[g]; 00779 }
|
|
A fast way to calculate a floor, which is largest integral value not greater than argument.
Definition at line 1679 of file util.h. Referenced by EMAN::CtfAverager::add_image(), EMAN::CtfAverager::finish(), EMAN::SymSearchProcessor::process_inplace(), EMAN::AddRandomNoiseProcessor::process_inplace(), EMAN::RotationalAverageProcessor::process_inplace(), EMAN::StandardProjector::project3d(), EMAN::EMData::sget_value_at_interp(), and EMAN::TransformProcessor::transform(). |
|
Definition at line 2617 of file util_sparx.cpp. References abs, bi, br, status, t, and tab1. Referenced by fftr_d(). 02618 { 02619 double rni,sgn,tr1,tr2,ti1,ti2; 02620 double cc,c,ss,s,t,x2,x3,x4,x5; 02621 int b3,b4,b5,b6,b7,b56; 02622 int n, k, l, j, i, ix0, ix1, status=0; 02623 02624 const double tab1[] = { 02625 9.58737990959775e-5, 02626 1.91747597310703e-4, 02627 3.83495187571395e-4, 02628 7.66990318742704e-4, 02629 1.53398018628476e-3, 02630 3.06795676296598e-3, 02631 6.13588464915449e-3, 02632 1.22715382857199e-2, 02633 2.45412285229123e-2, 02634 4.90676743274181e-2, 02635 9.80171403295604e-2, 02636 1.95090322016128e-1, 02637 3.82683432365090e-1, 02638 7.07106781186546e-1, 02639 1.00000000000000, 02640 }; 02641 02642 n=(int)pow(2.0f,ln); 02643 02644 k=abs(ks); 02645 l=16-ln; 02646 b3=n*k; 02647 b6=b3; 02648 b7=k; 02649 if (ks > 0) { 02650 sgn=1.0f; 02651 } else { 02652 sgn=-1.0f; 02653 rni=1.0f/(float)(n); 02654 j=1; 02655 for (i=1; i<=n; i++) { 02656 br(j)=br(j)*rni; 02657 bi(j)=bi(j)*rni; 02658 j=j+k; 02659 } 02660 } 02661 02662 L12: 02663 b6=b6/2; 02664 b5=b6; 02665 b4=2*b6; 02666 b56=b5-b6; 02667 02668 L14: 02669 tr1=br(b5+1); 02670 ti1=bi(b5+1); 02671 tr2=br(b56+1); 02672 ti2=bi(b56+1); 02673 02674 br(b5+1)=tr2-tr1; 02675 bi(b5+1)=ti2-ti1; 02676 br(b56+1)=tr1+tr2; 02677 bi(b56+1)=ti1+ti2; 02678 02679 b5=b5+b4; 02680 b56=b5-b6; 02681 if ( b5 <= b3 ) goto L14; 02682 if ( b6 == b7 ) goto L20; 02683 02684 b4=b7; 02685 cc=2.0f*pow(tab1(l),2); 02686 c=1.0f-cc; 02687 l++; 02688 ss=sgn*tab1(l); 02689 s=ss; 02690 02691 L16: 02692 b5=b6+b4; 02693 b4=2*b6; 02694 b56=b5-b6; 02695 02696 L18: 02697 tr1=br(b5+1); 02698 ti1=bi(b5+1); 02699 tr2=br(b56+1); 02700 ti2=bi(b56+1); 02701 br(b5+1)=c*(tr2-tr1)-s*(ti2-ti1); 02702 bi(b5+1)=s*(tr2-tr1)+c*(ti2-ti1); 02703 br(b56+1)=tr1+tr2; 02704 bi(b56+1)=ti1+ti2; 02705 02706 b5=b5+b4; 02707 b56=b5-b6; 02708 if ( b5 <= b3 ) goto L18; 02709 b4=b5-b6; 02710 b5=b4-b3; 02711 c=-c; 02712 b4=b6-b5; 02713 if ( b5 < b4 ) goto L16; 02714 b4=b4+b7; 02715 if ( b4 >= b5 ) goto L12; 02716 02717 t=c-cc*c-ss*s; 02718 s=s+ss*c-cc*s; 02719 c=t; 02720 goto L16; 02721 02722 L20: 02723 ix0=b3/2; 02724 b3=b3-b7; 02725 b4=0; 02726 b5=0; 02727 b6=ix0; 02728 ix1=0; 02729 if (b6 == b7) goto EXIT; 02730 02731 L22: 02732 b4=b3-b4; 02733 b5=b3-b5; 02734 x2=br(b4+1); 02735 x3=br(b5+1); 02736 x4=bi(b4+1); 02737 x5=bi(b5+1); 02738 br(b4+1)=x3; 02739 br(b5+1)=x2; 02740 bi(b4+1)=x5; 02741 bi(b5+1)=x4; 02742 if(b6 < b4) goto L22; 02743 02744 L24: 02745 b4=b4+b7; 02746 b5=b6+b5; 02747 x2=br(b4+1); 02748 x3=br(b5+1); 02749 x4=bi(b4+1); 02750 x5=bi(b5+1); 02751 br(b4+1)=x3; 02752 br(b5+1)=x2; 02753 bi(b4+1)=x5; 02754 bi(b5+1)=x4; 02755 ix0=b6; 02756 02757 L26: 02758 ix0=ix0/2; 02759 ix1=ix1-ix0; 02760 if( ix1 >= 0) goto L26; 02761 02762 ix0=2*ix0; 02763 b4=b4+b7; 02764 ix1=ix1+ix0; 02765 b5=ix1; 02766 if ( b5 >= b4) goto L22; 02767 if ( b4 < b6) goto L24; 02768 02769 EXIT: 02770 status = 0; 02771 }
|
|
Definition at line 2774 of file util_sparx.cpp. References abs, bi, br, status, t, and tab1. Referenced by fftr_q(). 02775 { 02776 // dimension br(1),bi(1) 02777 02778 int b3,b4,b5,b6,b7,b56; 02779 int n, k, l, j, i, ix0, ix1; 02780 float rni, tr1, ti1, tr2, ti2, cc, c, ss, s, t, x2, x3, x4, x5, sgn; 02781 int status=0; 02782 02783 const float tab1[] = { 02784 9.58737990959775e-5f, 02785 1.91747597310703e-4f, 02786 3.83495187571395e-4f, 02787 7.66990318742704e-4f, 02788 1.53398018628476e-3f, 02789 3.06795676296598e-3f, 02790 6.13588464915449e-3f, 02791 1.22715382857199e-2f, 02792 2.45412285229123e-2f, 02793 4.90676743274181e-2f, 02794 9.80171403295604e-2f, 02795 1.95090322016128e-1f, 02796 3.82683432365090e-1f, 02797 7.07106781186546e-1f, 02798 1.00000000000000f, 02799 }; 02800 02801 n=(int)pow(2.0f,ln); 02802 02803 k=abs(ks); 02804 l=16-ln; 02805 b3=n*k; 02806 b6=b3; 02807 b7=k; 02808 if( ks > 0 ) { 02809 sgn=1.0f; 02810 } else { 02811 sgn=-1.0f; 02812 rni=1.0f/(float)n; 02813 j=1; 02814 for (i=1; i<=n; i++) { 02815 br(j)=br(j)*rni; 02816 bi(j)=bi(j)*rni; 02817 j=j+k; 02818 } 02819 } 02820 L12: 02821 b6=b6/2; 02822 b5=b6; 02823 b4=2*b6; 02824 b56=b5-b6; 02825 L14: 02826 tr1=br(b5+1); 02827 ti1=bi(b5+1); 02828 02829 tr2=br(b56+1); 02830 ti2=bi(b56+1); 02831 02832 br(b5+1)=tr2-tr1; 02833 bi(b5+1)=ti2-ti1; 02834 br(b56+1)=tr1+tr2; 02835 bi(b56+1)=ti1+ti2; 02836 02837 b5=b5+b4; 02838 b56=b5-b6; 02839 if ( b5 <= b3 ) goto L14; 02840 if ( b6 == b7 ) goto L20; 02841 02842 b4=b7; 02843 cc=2.0f*pow(tab1(l),2); 02844 c=1.0f-cc; 02845 l++; 02846 ss=sgn*tab1(l); 02847 s=ss; 02848 L16: 02849 b5=b6+b4; 02850 b4=2*b6; 02851 b56=b5-b6; 02852 L18: 02853 tr1=br(b5+1); 02854 ti1=bi(b5+1); 02855 tr2=br(b56+1); 02856 ti2=bi(b56+1); 02857 br(b5+1)=c*(tr2-tr1)-s*(ti2-ti1); 02858 bi(b5+1)=s*(tr2-tr1)+c*(ti2-ti1); 02859 br(b56+1)=tr1+tr2; 02860 bi(b56+1)=ti1+ti2; 02861 02862 b5=b5+b4; 02863 b56=b5-b6; 02864 if(b5 <= b3) goto L18; 02865 b4=b5-b6; 02866 b5=b4-b3; 02867 c=-c; 02868 b4=b6-b5; 02869 if(b5 < b4) goto L16; 02870 b4=b4+b7; 02871 if(b4 >= b5) goto L12; 02872 02873 t=c-cc*c-ss*s; 02874 s=s+ss*c-cc*s; 02875 c=t; 02876 goto L16; 02877 L20: 02878 ix0=b3/2; 02879 b3=b3-b7; 02880 b4=0; 02881 b5=0; 02882 b6=ix0; 02883 ix1=0; 02884 if ( b6 == b7) goto EXIT; 02885 L22: 02886 b4=b3-b4; 02887 b5=b3-b5; 02888 x2=br(b4+1); 02889 x3=br(b5+1); 02890 x4=bi(b4+1); 02891 x5=bi(b5+1); 02892 br(b4+1)=x3; 02893 br(b5+1)=x2; 02894 bi(b4+1)=x5; 02895 bi(b5+1)=x4; 02896 if (b6 < b4) goto L22; 02897 L24: 02898 b4=b4+b7; 02899 b5=b6+b5; 02900 x2=br(b4+1); 02901 x3=br(b5+1); 02902 x4=bi(b4+1); 02903 x5=bi(b5+1); 02904 br(b4+1)=x3; 02905 br(b5+1)=x2; 02906 bi(b4+1)=x5; 02907 bi(b5+1)=x4; 02908 ix0=b6; 02909 L26: 02910 ix0=ix0/2; 02911 ix1=ix1-ix0; 02912 if(ix1 >= 0) goto L26; 02913 02914 ix0=2*ix0; 02915 b4=b4+b7; 02916 ix1=ix1+ix0; 02917 b5=ix1; 02918 if (b5 >= b4) goto L22; 02919 if (b4 < b6) goto L24; 02920 EXIT: 02921 status = 0; 02922 }
|
|
Definition at line 3006 of file util_sparx.cpp. References abs, fftc_d(), t, tab1, and xcmplx. Referenced by Crosrng_e(), Crosrng_ew(), Crosrng_ms(), Crosrng_ms_delta(), Crosrng_msg(), Crosrng_msg_m(), Crosrng_msg_s(), Crosrng_ns(), Crosrng_psi_0_180(), and Crosrng_sm_psi(). 03007 { 03008 // double precision x(2,1) 03009 int i1, i2, nu, inv, nu1, n, isub, n2, i; 03010 double tr1,tr2,ti1,ti2,tr,ti; 03011 double cc,c,ss,s,t; 03012 const double tab1[] = { 03013 9.58737990959775e-5, 03014 1.91747597310703e-4, 03015 3.83495187571395e-4, 03016 7.66990318742704e-4, 03017 1.53398018628476e-3, 03018 3.06795676296598e-3, 03019 6.13588464915449e-3, 03020 1.22715382857199e-2, 03021 2.45412285229123e-2, 03022 4.90676743274181e-2, 03023 9.80171403295604e-2, 03024 1.95090322016128e-1, 03025 3.82683432365090e-1, 03026 7.07106781186546e-1, 03027 1.00000000000000, 03028 }; 03029 03030 nu=abs(nv); 03031 inv=nv/nu; 03032 nu1=nu-1; 03033 n=(int)pow(2.0f,nu1); 03034 isub=16-nu1; 03035 ss=-tab1(isub); 03036 cc=-2.0*pow(tab1(isub-1),2); 03037 c=1.0f; 03038 s=0.0f; 03039 n2=n/2; 03040 03041 if ( inv > 0 ) { 03042 fftc_d(&xcmplx(1,1),&xcmplx(2,1),nu1,2); 03043 tr=xcmplx(1,1); 03044 ti=xcmplx(2,1); 03045 xcmplx(1,1)=tr+ti; 03046 xcmplx(2,1)=tr-ti; 03047 for (i=1;i<=n2;i++) { 03048 i1=i+1; 03049 i2=n-i+1; 03050 tr1=xcmplx(1,i1); 03051 tr2=xcmplx(1,i2); 03052 ti1=xcmplx(2,i1); 03053 ti2=xcmplx(2,i2); 03054 t=(cc*c-ss*s)+c; 03055 s=(cc*s+ss*c)+s; 03056 c=t; 03057 xcmplx(1,i1)=0.5*((tr1+tr2)+(ti1+ti2)*c-(tr1-tr2)*s); 03058 xcmplx(1,i2)=0.5*((tr1+tr2)-(ti1+ti2)*c+(tr1-tr2)*s); 03059 xcmplx(2,i1)=0.5*((ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c); 03060 xcmplx(2,i2)=0.5*(-(ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c); 03061 } 03062 } else { 03063 tr=xcmplx(1,1); 03064 ti=xcmplx(2,1); 03065 xcmplx(1,1)=0.5*(tr+ti); 03066 xcmplx(2,1)=0.5*(tr-ti); 03067 for (i=1; i<=n2; i++) { 03068 i1=i+1; 03069 i2=n-i+1; 03070 tr1=xcmplx(1,i1); 03071 tr2=xcmplx(1,i2); 03072 ti1=xcmplx(2,i1); 03073 ti2=xcmplx(2,i2); 03074 t=(cc*c-ss*s)+c; 03075 s=(cc*s+ss*c)+s; 03076 c=t; 03077 xcmplx(1,i1)=0.5*((tr1+tr2)-(tr1-tr2)*s-(ti1+ti2)*c); 03078 xcmplx(1,i2)=0.5*((tr1+tr2)+(tr1-tr2)*s+(ti1+ti2)*c); 03079 xcmplx(2,i1)=0.5*((ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s); 03080 xcmplx(2,i2)=0.5*(-(ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s); 03081 } 03082 fftc_d(&xcmplx(1,1),&xcmplx(2,1),nu1,-2); 03083 } 03084 }
|
|
Definition at line 2924 of file util_sparx.cpp. References abs, fftc_q(), t, tab1, and xcmplx. Referenced by Crosrng_msg_vec(), Frngs(), and Frngs_inv(). 02925 { 02926 // dimension xcmplx(2,1); xcmplx(1,i) --- real, xcmplx(2,i) --- imaginary 02927 02928 int nu, inv, nu1, n, isub, n2, i1, i2, i; 02929 float ss, cc, c, s, tr, ti, tr1, tr2, ti1, ti2, t; 02930 02931 const float tab1[] = { 02932 9.58737990959775e-5f, 02933 1.91747597310703e-4f, 02934 3.83495187571395e-4f, 02935 7.66990318742704e-4f, 02936 1.53398018628476e-3f, 02937 3.06795676296598e-3f, 02938 6.13588464915449e-3f, 02939 1.22715382857199e-2f, 02940 2.45412285229123e-2f, 02941 4.90676743274181e-2f, 02942 9.80171403295604e-2f, 02943 1.95090322016128e-1f, 02944 3.82683432365090e-1f, 02945 7.07106781186546e-1f, 02946 1.00000000000000f, 02947 }; 02948 02949 nu=abs(nv); 02950 inv=nv/nu; 02951 nu1=nu-1; 02952 n=(int)pow(2.f,nu1); 02953 isub=16-nu1; 02954 02955 ss=-tab1(isub); 02956 cc=-2.0f*pow(tab1(isub-1),2.f); 02957 c=1.0f; 02958 s=0.0f; 02959 n2=n/2; 02960 if ( inv > 0) { 02961 fftc_q(&xcmplx(1,1),&xcmplx(2,1),nu1,2); 02962 tr=xcmplx(1,1); 02963 ti=xcmplx(2,1); 02964 xcmplx(1,1)=tr+ti; 02965 xcmplx(2,1)=tr-ti; 02966 for (i=1;i<=n2;i++) { 02967 i1=i+1; 02968 i2=n-i+1; 02969 tr1=xcmplx(1,i1); 02970 tr2=xcmplx(1,i2); 02971 ti1=xcmplx(2,i1); 02972 ti2=xcmplx(2,i2); 02973 t=(cc*c-ss*s)+c; 02974 s=(cc*s+ss*c)+s; 02975 c=t; 02976 xcmplx(1,i1)=0.5f*((tr1+tr2)+(ti1+ti2)*c-(tr1-tr2)*s); 02977 xcmplx(1,i2)=0.5f*((tr1+tr2)-(ti1+ti2)*c+(tr1-tr2)*s); 02978 xcmplx(2,i1)=0.5f*((ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c); 02979 xcmplx(2,i2)=0.5f*(-(ti1-ti2)-(ti1+ti2)*s-(tr1-tr2)*c); 02980 } 02981 } else { 02982 tr=xcmplx(1,1); 02983 ti=xcmplx(2,1); 02984 xcmplx(1,1)=0.5f*(tr+ti); 02985 xcmplx(2,1)=0.5f*(tr-ti); 02986 for (i=1; i<=n2; i++) { 02987 i1=i+1; 02988 i2=n-i+1; 02989 tr1=xcmplx(1,i1); 02990 tr2=xcmplx(1,i2); 02991 ti1=xcmplx(2,i1); 02992 ti2=xcmplx(2,i2); 02993 t=(cc*c-ss*s)+c; 02994 s=(cc*s+ss*c)+s; 02995 c=t; 02996 xcmplx(1,i1)=0.5f*((tr1+tr2)-(tr1-tr2)*s-(ti1+ti2)*c); 02997 xcmplx(1,i2)=0.5f*((tr1+tr2)+(tr1-tr2)*s+(ti1+ti2)*c); 02998 xcmplx(2,i1)=0.5f*((ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s); 02999 xcmplx(2,i2)=0.5f*(-(ti1-ti2)+(tr1-tr2)*c-(ti1+ti2)*s); 03000 } 03001 fftc_q(&xcmplx(1,1),&xcmplx(2,1),nu1,-2); 03002 } 03003 }
|
|
lock a file. If the lock fails, wait for 1 second; then try again. Repleat this wait-try for a maxinum of 5 times unless the lock succeeds.
Definition at line 137 of file util.cpp. References LOGERR, and NullPointerException. 00138 { 00139 #ifdef WIN32 00140 return 1; 00141 #else 00142 00143 if (!file) { 00144 throw NullPointerException("Tried to lock NULL file"); 00145 } 00146 00147 int fdes = fileno(file); 00148 00149 struct flock fl; 00150 fl.l_type = F_WRLCK; 00151 fl.l_whence = SEEK_SET; 00152 fl.l_start = 0; 00153 fl.l_len = 0; 00154 #ifdef WIN32 00155 fl.l_pid = _getpid(); 00156 #else 00157 fl.l_pid = getpid(); 00158 #endif 00159 00160 #if defined __sgi 00161 fl.l_sysid = getpid(); 00162 #endif 00163 00164 int err = 0; 00165 if (fcntl(fdes, F_SETLKW, &fl) == -1) { 00166 LOGERR("file locking error! NFS problem?"); 00167 00168 int i = 0; 00169 for (i = 0; i < 5; i++) { 00170 if (fcntl(fdes, F_SETLKW, &fl) != -1) { 00171 break; 00172 } 00173 else { 00174 #ifdef WIN32 00175 Sleep(1000); 00176 #else 00177 sleep(1); 00178 #endif 00179 00180 } 00181 } 00182 if (i == 5) { 00183 LOGERR("Fatal file locking error"); 00184 err = 1; 00185 } 00186 } 00187 00188 return err; 00189 #endif 00190 }
|
|
Find the maximum value and (optional) its index in an array.
Definition at line 814 of file util.cpp. References Assert, data, max, and NullPointerException. Referenced by EMAN::RotationalAlignerIterative::align(), EMAN::RotatePrecenterAligner::align(), and EMAN::RotationalAligner::align_180_ambiguous(). 00815 { 00816 Assert(nitems > 0); 00817 00818 if (!data || !max_val || !max_index) { 00819 throw NullPointerException("data/max_val/max_index"); 00820 } 00821 float max = -FLT_MAX; 00822 int m = 0; 00823 00824 for (size_t i = 0; i < nitems; i++) { 00825 if (data[i] > max) { 00826 max = data[i]; 00827 m = (int)i; 00828 } 00829 } 00830 00831 *max_val = (float)m; 00832 00833 if (max_index) { 00834 *max_index = m; 00835 } 00836 }
|
|
Find the maximum value and (optional) its index, minimum value and (optional) its index in an array.
Definition at line 838 of file util.cpp. References Assert, data, max, min, and NullPointerException. 00841 { 00842 Assert(nitems > 0); 00843 00844 if (!data || !max_val || !min_val || !max_index || !min_index) { 00845 throw NullPointerException("data/max_val/min_val/max_index/min_index"); 00846 } 00847 float max = -FLT_MAX; 00848 float min = FLT_MAX; 00849 int max_i = 0; 00850 int min_i = 0; 00851 00852 for (size_t i = 0; i < nitems; i++) { 00853 if (data[i] > max) { 00854 max = data[i]; 00855 max_i = (int)i; 00856 } 00857 if (data[i] < min) { 00858 min = data[i]; 00859 min_i = (int)i; 00860 } 00861 } 00862 00863 *max_val = max; 00864 *min_val = min; 00865 00866 if (min_index) { 00867 *min_index = min_i; 00868 } 00869 00870 if (max_index) { 00871 *max_index = max_i; 00872 } 00873 00874 }
|
|
Definition at line 7709 of file util_sparx.cpp. 07710 { 07711 ENTERFUNC; 07712 int i = k; 07713 while( i == k ) i = rand()%len; 07714 std::swap(key[i], key[k]); 07715 std::swap(x[i], x[k]); 07716 std::swap(y[i], y[k]); 07717 std::swap(z[i], z[k]); 07718 EXITFUNC; 07719 }
|
|
flip the phase of a complex data array.
Definition at line 82 of file util.cpp. References Assert, data, and NullPointerException. 00083 { 00084 Assert(n > 0); 00085 00086 if (!data) { 00087 throw NullPointerException("pixel data array"); 00088 } 00089 00090 for (size_t i = 0; i < n; i += 2) { 00091 data[i + 1] *= -1; 00092 } 00093 }
|
|
Vertically flip the data of a 2D real image.
Definition at line 217 of file util.cpp. References Assert, data, NullPointerException, nx, and ny. 00218 { 00219 if (!data) { 00220 throw NullPointerException("image data array"); 00221 } 00222 Assert(nx > 0); 00223 Assert(ny > 0); 00224 00225 float *buf = new float[nx]; 00226 size_t row_size = nx * sizeof(float); 00227 00228 for (size_t i = 0; i < ny / 2; i++) { 00229 memcpy(buf, &data[i * nx], row_size); 00230 memcpy(&data[i * nx], &data[(ny - 1 - i) * nx], row_size); 00231 memcpy(&data[(ny - 1 - i) * nx], buf, row_size); 00232 } 00233 00234 if( buf ) 00235 { 00236 delete[]buf; 00237 buf = 0; 00238 } 00239 }
|
|
This function conducts the Single Precision Fourier Transform for a set of rings.
Definition at line 3091 of file util_sparx.cpp. References circ, fftr_q(), EMAN::EMData::get_data(), log(), and numr. Referenced by ali2d_ccf_list(), multiref_peaks_ali2d(), multiref_peaks_compress_ali2d(), multiref_polar_ali_2d(), multiref_polar_ali_2d_delta(), multiref_polar_ali_2d_local(), multiref_polar_ali_2d_local_psi(), multiref_polar_ali_2d_nom(), multiref_polar_ali_2d_peaklist(), and multiref_polar_ali_helical(). 03091 { 03092 int nring = numr.size()/3; 03093 float *circ = circp->get_data(); 03094 int i, l; 03095 for (i=1; i<=nring;i++) { 03096 03097 #ifdef _WIN32 03098 l = (int)( log((float)numr(3,i))/log(2.0f) ); 03099 #else 03100 l=(int)(log2(numr(3,i))); 03101 #endif //_WIN32 03102 03103 fftr_q(&circ(numr(2,i)),l); 03104 } 03105 }
|
|
This function conducts the Single Precision Inverse Fourier Transform for a set of rings.
Definition at line 3107 of file util_sparx.cpp. References circ, fftr_q(), EMAN::EMData::get_data(), log(), and numr. 03107 { 03108 int nring = numr.size()/3; 03109 float *circ = circp->get_data(); 03110 int i, l; 03111 for (i=1; i<=nring;i++) { 03112 03113 #ifdef _WIN32 03114 l = (int)( log((float)numr(3,i))/log(2.0f) ); 03115 #else 03116 l=(int)(log2(numr(3,i))); 03117 #endif //_WIN32 03118 03119 fftr_q(&circ(numr(2,i)),-l); 03120 } 03121 }
|
|
make an intelligent "guess" at the largest weight of all possible feasible matches. we make "n_guesses" guesses and return the largest one. the largest weight of all feasible matches is guaranteed to be larger than or equal to the returned guess. |
|
Definition at line 19476 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(). 19477 { 19478 int nx = mg->get_xsize(); 19479 int ny = mg->get_ysize(); 19480 int nz = mg->get_zsize(); 19481 19482 EMData* visited = new EMData(); 19483 visited->set_size( nx, ny, nz ); 19484 visited->to_zero(); 19485 int grpid = 0; 19486 int maxgrp = 0; 19487 int maxsize = 0; 19488 for( int iz=0; iz < nz; ++iz ) { 19489 for( int iy=0; iy < ny; ++iy ) { 19490 for( int ix=0; ix < nx; ++ix ) { 19491 if( (*mg)(ix, iy, iz)==0.0 ) continue; 19492 19493 if( (*visited)(ix, iy, iz) > 0.0 ) { 19494 // visited before, must be in other group. 19495 continue; 19496 } 19497 19498 grpid++; 19499 int grpsize = find_group( ix, iy, iz, grpid, mg, visited ); 19500 if( grpsize > maxsize ) { 19501 maxsize = grpsize; 19502 maxgrp = grpid; 19503 } 19504 } 19505 } 19506 } 19507 19508 Assert( maxgrp > 0 ); 19509 19510 int npoint = 0; 19511 EMData* result = new EMData(); 19512 result->set_size( nx, ny, nz ); 19513 result->to_zero(); 19514 19515 for( int iz=0; iz < nz; ++iz ) { 19516 for( int iy=0; iy < ny; ++iy ) { 19517 for( int ix=0; ix < nx; ++ix ) { 19518 if( (*visited)(ix, iy, iz)==maxgrp ) { 19519 (*result)(ix,iy,iz) = 1.0; 19520 npoint++; 19521 } 19522 } 19523 } 19524 } 19525 19526 Assert( npoint==maxsize ); 19527 delete visited; 19528 return result; 19529 19530 }
|
|
Get a filename's extension.
Definition at line 492 of file util.cpp. Referenced by EMAN::EMUtil::fast_get_image_type(), and EMAN::EMUtil::get_image_type(). 00493 { 00494 if (filename == "") { 00495 return ""; 00496 } 00497 00498 string result = ""; 00499 const char *ext = strrchr(filename.c_str(), '.'); 00500 if (ext) { 00501 ext++; 00502 result = string(ext); 00503 } 00504 return result; 00505 }
|
|
Get a float random number between low and high, [low, high).
Definition at line 707 of file util.cpp. References EMAN::Randnum::get_frand(). 00708 { 00709 Randnum* randnum = Randnum::Instance(); 00710 return randnum->get_frand(lo, hi); 00711 }
|
|
Get a float random number between low and high, [low, high).
Definition at line 701 of file util.cpp. References EMAN::Randnum::get_frand(). 00702 { 00703 Randnum* randnum = Randnum::Instance(); 00704 return randnum->get_frand(lo, hi); 00705 }
|
|
Get a float random number between low and high, [low, high).
Definition at line 696 of file util.cpp. Referenced by EMAN::OrientationGenerator::add_orientation(), ali2d_ccf_list(), EMAN::RandomOrientationGenerator::gen_orientations(), EMAN::KmeansSegmentProcessor::process(), EMAN::TestImageFourierNoiseProfile::process_inplace(), and EMAN::TestImageFourierNoiseGaussian::process_inplace(). 00697 { 00698 return get_frand((float)lo, (float)hi); 00699 }
|
|
Get a Gaussian random number.
Definition at line 808 of file util.cpp. References EMAN::Randnum::get_gauss_rand(). Referenced by EMAN::EmanOrientationGenerator::gen_orientations(), and main(). 00809 { 00810 Randnum* randnum = Randnum::Instance(); 00811 return randnum->get_gauss_rand(mean, sigma); 00812 }
|
|
Get an integer random number between low and high, [low, high].
Definition at line 690 of file util.cpp. References EMAN::Randnum::get_irand(). 00691 { 00692 Randnum* randnum = Randnum::Instance(); 00693 return randnum->get_irand(lo, hi); 00694 }
|
|
Extract a single line from a multi-line string.
The line delimiter is '
Definition at line 267 of file util.cpp. References NullPointerException. Referenced by EMAN::XplorIO::is_valid(). 00268 { 00269 if (!slines || !(*slines)) { 00270 throw NullPointerException("Null string"); 00271 } 00272 00273 string result = ""; 00274 char *str = *slines; 00275 00276 while (*str != '\n' && *str != '\0') { 00277 result.push_back(*str); 00278 str++; 00279 } 00280 if (*str != '\0') { 00281 str++; 00282 } 00283 *slines = str; 00284 00285 return result; 00286 }
|
|
Get the maximum of 4 numbers.
|
|
Get the maximum of 3 numbers.
|
|
Get the maximum of 2 numbers.
|
|
Get the minimum of 4 numbers.
|
|
Get the minimum of 3 numbers.
|
|
Get the minimum of 2 numbers.
|
|
Get the minimum of 3 numbers.
|
|
Get the minimum of 2 numbers.
Definition at line 1718 of file util.h. Referenced by EMAN::PawelProjector::backproject3d(), EMAN::ChaoProjector::backproject3d(), EMAN::ChaoProjector::project3d(), EMAN::FourierGriddingProjector::project3d(), and EMAN::PawelProjector::project3d(). |
|
Definition at line 774 of file util_sparx.cpp. References data, EMAN::Util::KaiserBessel::get_window_size(), EMAN::Util::KaiserBessel::i0win_tab(), nx, ny, restrict1(), and round(). Referenced by Polar2Dmi(). 00774 { 00775 int K = kb.get_window_size(); 00776 int kbmin = -K/2; 00777 int kbmax = -kbmin; 00778 int kbc = kbmax+1; 00779 00780 float pixel =0.0f; 00781 float w=0.0f; 00782 00783 delx = restrict1(delx, nx); 00784 int inxold = int(round(delx)); 00785 if ( ny < 2 ) { //1D 00786 float tablex1 = kb.i0win_tab(delx-inxold+3); 00787 float tablex2 = kb.i0win_tab(delx-inxold+2); 00788 float tablex3 = kb.i0win_tab(delx-inxold+1); 00789 float tablex4 = kb.i0win_tab(delx-inxold); 00790 float tablex5 = kb.i0win_tab(delx-inxold-1); 00791 float tablex6 = kb.i0win_tab(delx-inxold-2); 00792 float tablex7 = kb.i0win_tab(delx-inxold-3); 00793 00794 int x1, x2, x3, x4, x5, x6, x7; 00795 00796 if ( inxold <= kbc || inxold >=nx-kbc-2 ) { 00797 x1 = (inxold-3+nx)%nx; 00798 x2 = (inxold-2+nx)%nx; 00799 x3 = (inxold-1+nx)%nx; 00800 x4 = (inxold +nx)%nx; 00801 x5 = (inxold+1+nx)%nx; 00802 x6 = (inxold+2+nx)%nx; 00803 x7 = (inxold+3+nx)%nx; 00804 } else { 00805 x1 = inxold-3; 00806 x2 = inxold-2; 00807 x3 = inxold-1; 00808 x4 = inxold; 00809 x5 = inxold+1; 00810 x6 = inxold+2; 00811 x7 = inxold+3; 00812 } 00813 00814 pixel = data[x1]*tablex1 + data[x2]*tablex2 + data[x3]*tablex3 + 00815 data[x4]*tablex4 + data[x5]*tablex5 + data[x6]*tablex6 + 00816 data[x7]*tablex7 ; 00817 00818 w = tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7; 00819 } else if ( nz < 2 ) { // 2D 00820 dely = restrict1(dely, ny); 00821 int inyold = int(round(dely)); 00822 float tablex1 = kb.i0win_tab(delx-inxold+3); 00823 float tablex2 = kb.i0win_tab(delx-inxold+2); 00824 float tablex3 = kb.i0win_tab(delx-inxold+1); 00825 float tablex4 = kb.i0win_tab(delx-inxold); 00826 float tablex5 = kb.i0win_tab(delx-inxold-1); 00827 float tablex6 = kb.i0win_tab(delx-inxold-2); 00828 float tablex7 = kb.i0win_tab(delx-inxold-3); 00829 00830 float tabley1 = kb.i0win_tab(dely-inyold+3); 00831 float tabley2 = kb.i0win_tab(dely-inyold+2); 00832 float tabley3 = kb.i0win_tab(dely-inyold+1); 00833 float tabley4 = kb.i0win_tab(dely-inyold); 00834 float tabley5 = kb.i0win_tab(dely-inyold-1); 00835 float tabley6 = kb.i0win_tab(dely-inyold-2); 00836 float tabley7 = kb.i0win_tab(dely-inyold-3); 00837 00838 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7; 00839 00840 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 ) { 00841 x1 = (inxold-3+nx)%nx; 00842 x2 = (inxold-2+nx)%nx; 00843 x3 = (inxold-1+nx)%nx; 00844 x4 = (inxold +nx)%nx; 00845 x5 = (inxold+1+nx)%nx; 00846 x6 = (inxold+2+nx)%nx; 00847 x7 = (inxold+3+nx)%nx; 00848 00849 y1 = ((inyold-3+ny)%ny)*nx; 00850 y2 = ((inyold-2+ny)%ny)*nx; 00851 y3 = ((inyold-1+ny)%ny)*nx; 00852 y4 = ((inyold +ny)%ny)*nx; 00853 y5 = ((inyold+1+ny)%ny)*nx; 00854 y6 = ((inyold+2+ny)%ny)*nx; 00855 y7 = ((inyold+3+ny)%ny)*nx; 00856 } else { 00857 x1 = inxold-3; 00858 x2 = inxold-2; 00859 x3 = inxold-1; 00860 x4 = inxold; 00861 x5 = inxold+1; 00862 x6 = inxold+2; 00863 x7 = inxold+3; 00864 00865 y1 = (inyold-3)*nx; 00866 y2 = (inyold-2)*nx; 00867 y3 = (inyold-1)*nx; 00868 y4 = inyold*nx; 00869 y5 = (inyold+1)*nx; 00870 y6 = (inyold+2)*nx; 00871 y7 = (inyold+3)*nx; 00872 } 00873 00874 pixel = ( data[x1+y1]*tablex1 + data[x2+y1]*tablex2 + data[x3+y1]*tablex3 + 00875 data[x4+y1]*tablex4 + data[x5+y1]*tablex5 + data[x6+y1]*tablex6 + 00876 data[x7+y1]*tablex7 ) * tabley1 + 00877 ( data[x1+y2]*tablex1 + data[x2+y2]*tablex2 + data[x3+y2]*tablex3 + 00878 data[x4+y2]*tablex4 + data[x5+y2]*tablex5 + data[x6+y2]*tablex6 + 00879 data[x7+y2]*tablex7 ) * tabley2 + 00880 ( data[x1+y3]*tablex1 + data[x2+y3]*tablex2 + data[x3+y3]*tablex3 + 00881 data[x4+y3]*tablex4 + data[x5+y3]*tablex5 + data[x6+y3]*tablex6 + 00882 data[x7+y3]*tablex7 ) * tabley3 + 00883 ( data[x1+y4]*tablex1 + data[x2+y4]*tablex2 + data[x3+y4]*tablex3 + 00884 data[x4+y4]*tablex4 + data[x5+y4]*tablex5 + data[x6+y4]*tablex6 + 00885 data[x7+y4]*tablex7 ) * tabley4 + 00886 ( data[x1+y5]*tablex1 + data[x2+y5]*tablex2 + data[x3+y5]*tablex3 + 00887 data[x4+y5]*tablex4 + data[x5+y5]*tablex5 + data[x6+y5]*tablex6 + 00888 data[x7+y5]*tablex7 ) * tabley5 + 00889 ( data[x1+y6]*tablex1 + data[x2+y6]*tablex2 + data[x3+y6]*tablex3 + 00890 data[x4+y6]*tablex4 + data[x5+y6]*tablex5 + data[x6+y6]*tablex6 + 00891 data[x7+y6]*tablex7 ) * tabley6 + 00892 ( data[x1+y7]*tablex1 + data[x2+y7]*tablex2 + data[x3+y7]*tablex3 + 00893 data[x4+y7]*tablex4 + data[x5+y7]*tablex5 + data[x6+y7]*tablex6 + 00894 data[x7+y7]*tablex7 ) * tabley7; 00895 00896 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) * 00897 (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7); 00898 } else { // 3D 00899 dely = restrict1(dely, ny); 00900 int inyold = int(Util::round(dely)); 00901 delz = restrict1(delz, nz); 00902 int inzold = int(Util::round(delz)); 00903 00904 float tablex1 = kb.i0win_tab(delx-inxold+3); 00905 float tablex2 = kb.i0win_tab(delx-inxold+2); 00906 float tablex3 = kb.i0win_tab(delx-inxold+1); 00907 float tablex4 = kb.i0win_tab(delx-inxold); 00908 float tablex5 = kb.i0win_tab(delx-inxold-1); 00909 float tablex6 = kb.i0win_tab(delx-inxold-2); 00910 float tablex7 = kb.i0win_tab(delx-inxold-3); 00911 00912 float tabley1 = kb.i0win_tab(dely-inyold+3); 00913 float tabley2 = kb.i0win_tab(dely-inyold+2); 00914 float tabley3 = kb.i0win_tab(dely-inyold+1); 00915 float tabley4 = kb.i0win_tab(dely-inyold); 00916 float tabley5 = kb.i0win_tab(dely-inyold-1); 00917 float tabley6 = kb.i0win_tab(dely-inyold-2); 00918 float tabley7 = kb.i0win_tab(dely-inyold-3); 00919 00920 float tablez1 = kb.i0win_tab(delz-inzold+3); 00921 float tablez2 = kb.i0win_tab(delz-inzold+2); 00922 float tablez3 = kb.i0win_tab(delz-inzold+1); 00923 float tablez4 = kb.i0win_tab(delz-inzold); 00924 float tablez5 = kb.i0win_tab(delz-inzold-1); 00925 float tablez6 = kb.i0win_tab(delz-inzold-2); 00926 float tablez7 = kb.i0win_tab(delz-inzold-3); 00927 00928 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7, z1, z2, z3, z4, z5, z6, z7; 00929 00930 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 || inzold <= kbc || inzold >= nz-kbc-2 ) { 00931 x1 = (inxold-3+nx)%nx; 00932 x2 = (inxold-2+nx)%nx; 00933 x3 = (inxold-1+nx)%nx; 00934 x4 = (inxold +nx)%nx; 00935 x5 = (inxold+1+nx)%nx; 00936 x6 = (inxold+2+nx)%nx; 00937 x7 = (inxold+3+nx)%nx; 00938 00939 y1 = ((inyold-3+ny)%ny)*nx; 00940 y2 = ((inyold-2+ny)%ny)*nx; 00941 y3 = ((inyold-1+ny)%ny)*nx; 00942 y4 = ((inyold +ny)%ny)*nx; 00943 y5 = ((inyold+1+ny)%ny)*nx; 00944 y6 = ((inyold+2+ny)%ny)*nx; 00945 y7 = ((inyold+3+ny)%ny)*nx; 00946 00947 z1 = ((inzold-3+nz)%nz)*nx*ny; 00948 z2 = ((inzold-2+nz)%nz)*nx*ny; 00949 z3 = ((inzold-1+nz)%nz)*nx*ny; 00950 z4 = ((inzold +nz)%nz)*nx*ny; 00951 z5 = ((inzold+1+nz)%nz)*nx*ny; 00952 z6 = ((inzold+2+nz)%nz)*nx*ny; 00953 z7 = ((inzold+3+nz)%nz)*nx*ny; 00954 } else { 00955 x1 = inxold-3; 00956 x2 = inxold-2; 00957 x3 = inxold-1; 00958 x4 = inxold; 00959 x5 = inxold+1; 00960 x6 = inxold+2; 00961 x7 = inxold+3; 00962 00963 y1 = (inyold-3)*nx; 00964 y2 = (inyold-2)*nx; 00965 y3 = (inyold-1)*nx; 00966 y4 = inyold*nx; 00967 y5 = (inyold+1)*nx; 00968 y6 = (inyold+2)*nx; 00969 y7 = (inyold+3)*nx; 00970 00971 z1 = (inzold-3)*nx*ny; 00972 z2 = (inzold-2)*nx*ny; 00973 z3 = (inzold-1)*nx*ny; 00974 z4 = inzold*nx*ny; 00975 z5 = (inzold+1)*nx*ny; 00976 z6 = (inzold+2)*nx*ny; 00977 z7 = (inzold+3)*nx*ny; 00978 } 00979 00980 pixel = ( ( data[x1+y1+z1]*tablex1 + data[x2+y1+z1]*tablex2 + data[x3+y1+z1]*tablex3 + 00981 data[x4+y1+z1]*tablex4 + data[x5+y1+z1]*tablex5 + data[x6+y1+z1]*tablex6 + 00982 data[x7+y1+z1]*tablex7 ) * tabley1 + 00983 ( data[x1+y2+z1]*tablex1 + data[x2+y2+z1]*tablex2 + data[x3+y2+z1]*tablex3 + 00984 data[x4+y2+z1]*tablex4 + data[x5+y2+z1]*tablex5 + data[x6+y2+z1]*tablex6 + 00985 data[x7+y2+z1]*tablex7 ) * tabley2 + 00986 ( data[x1+y3+z1]*tablex1 + data[x2+y3+z1]*tablex2 + data[x3+y3+z1]*tablex3 + 00987 data[x4+y3+z1]*tablex4 + data[x5+y3+z1]*tablex5 + data[x6+y3+z1]*tablex6 + 00988 data[x7+y3+z1]*tablex7 ) * tabley3 + 00989 ( data[x1+y4+z1]*tablex1 + data[x2+y4+z1]*tablex2 + data[x3+y4+z1]*tablex3 + 00990 data[x4+y4+z1]*tablex4 + data[x5+y4+z1]*tablex5 + data[x6+y4+z1]*tablex6 + 00991 data[x7+y4+z1]*tablex7 ) * tabley4 + 00992 ( data[x1+y5+z1]*tablex1 + data[x2+y5+z1]*tablex2 + data[x3+y5+z1]*tablex3 + 00993 data[x4+y5+z1]*tablex4 + data[x5+y5+z1]*tablex5 + data[x6+y5+z1]*tablex6 + 00994 data[x7+y5+z1]*tablex7 ) * tabley5 + 00995 ( data[x1+y6+z1]*tablex1 + data[x2+y6+z1]*tablex2 + data[x3+y6+z1]*tablex3 + 00996 data[x4+y6+z1]*tablex4 + data[x5+y6+z1]*tablex5 + data[x6+y6+z1]*tablex6 + 00997 data[x7+y6+z1]*tablex7 ) * tabley6 + 00998 ( data[x1+y7+z1]*tablex1 + data[x2+y7+z1]*tablex2 + data[x3+y7+z1]*tablex3 + 00999 data[x4+y7+z1]*tablex4 + data[x5+y7+z1]*tablex5 + data[x6+y7+z1]*tablex6 + 01000 data[x7+y7+z1]*tablex7 ) * tabley7 ) *tablez1 + 01001 ( ( data[x1+y1+z2]*tablex1 + data[x2+y1+z2]*tablex2 + data[x3+y1+z2]*tablex3 + 01002 data[x4+y1+z2]*tablex4 + data[x5+y1+z2]*tablex5 + data[x6+y1+z2]*tablex6 + 01003 data[x7+y1+z2]*tablex7 ) * tabley1 + 01004 ( data[x1+y2+z2]*tablex1 + data[x2+y2+z2]*tablex2 + data[x3+y2+z2]*tablex3 + 01005 data[x4+y2+z2]*tablex4 + data[x5+y2+z2]*tablex5 + data[x6+y2+z2]*tablex6 + 01006 data[x7+y2+z2]*tablex7 ) * tabley2 + 01007 ( data[x1+y3+z2]*tablex1 + data[x2+y3+z2]*tablex2 + data[x3+y3+z2]*tablex3 + 01008 data[x4+y3+z2]*tablex4 + data[x5+y3+z2]*tablex5 + data[x6+y3+z2]*tablex6 + 01009 data[x7+y3+z2]*tablex7 ) * tabley3 + 01010 ( data[x1+y4+z2]*tablex1 + data[x2+y4+z2]*tablex2 + data[x3+y4+z2]*tablex3 + 01011 data[x4+y4+z2]*tablex4 + data[x5+y4+z2]*tablex5 + data[x6+y4+z2]*tablex6 + 01012 data[x7+y4+z2]*tablex7 ) * tabley4 + 01013 ( data[x1+y5+z2]*tablex1 + data[x2+y5+z2]*tablex2 + data[x3+y5+z2]*tablex3 + 01014 data[x4+y5+z2]*tablex4 + data[x5+y5+z2]*tablex5 + data[x6+y5+z2]*tablex6 + 01015 data[x7+y5+z2]*tablex7 ) * tabley5 + 01016 ( data[x1+y6+z2]*tablex1 + data[x2+y6+z2]*tablex2 + data[x3+y6+z2]*tablex3 + 01017 data[x4+y6+z2]*tablex4 + data[x5+y6+z2]*tablex5 + data[x6+y6+z2]*tablex6 + 01018 data[x7+y6+z2]*tablex7 ) * tabley6 + 01019 ( data[x1+y7+z2]*tablex1 + data[x2+y7+z2]*tablex2 + data[x3+y7+z2]*tablex3 + 01020 data[x4+y7+z2]*tablex4 + data[x5+y7+z2]*tablex5 + data[x6+y7+z2]*tablex6 + 01021 data[x7+y7+z2]*tablex7 ) * tabley7 ) *tablez2 + 01022 ( ( data[x1+y1+z3]*tablex1 + data[x2+y1+z3]*tablex2 + data[x3+y1+z3]*tablex3 + 01023 data[x4+y1+z3]*tablex4 + data[x5+y1+z3]*tablex5 + data[x6+y1+z3]*tablex6 + 01024 data[x7+y1+z3]*tablex7 ) * tabley1 + 01025 ( data[x1+y2+z3]*tablex1 + data[x2+y2+z3]*tablex2 + data[x3+y2+z3]*tablex3 + 01026 data[x4+y2+z3]*tablex4 + data[x5+y2+z3]*tablex5 + data[x6+y2+z3]*tablex6 + 01027 data[x7+y2+z3]*tablex7 ) * tabley2 + 01028 ( data[x1+y3+z3]*tablex1 + data[x2+y3+z3]*tablex2 + data[x3+y3+z3]*tablex3 + 01029 data[x4+y3+z3]*tablex4 + data[x5+y3+z3]*tablex5 + data[x6+y3+z3]*tablex6 + 01030 data[x7+y3+z3]*tablex7 ) * tabley3 + 01031 ( data[x1+y4+z3]*tablex1 + data[x2+y4+z3]*tablex2 + data[x3+y4+z3]*tablex3 + 01032 data[x4+y4+z3]*tablex4 + data[x5+y4+z3]*tablex5 + data[x6+y4+z3]*tablex6 + 01033 data[x7+y4+z3]*tablex7 ) * tabley4 + 01034 ( data[x1+y5+z3]*tablex1 + data[x2+y5+z3]*tablex2 + data[x3+y5+z3]*tablex3 + 01035 data[x4+y5+z3]*tablex4 + data[x5+y5+z3]*tablex5 + data[x6+y5+z3]*tablex6 + 01036 data[x7+y5+z3]*tablex7 ) * tabley5 + 01037 ( data[x1+y6+z3]*tablex1 + data[x2+y6+z3]*tablex2 + data[x3+y6+z3]*tablex3 + 01038 data[x4+y6+z3]*tablex4 + data[x5+y6+z3]*tablex5 + data[x6+y6+z3]*tablex6 + 01039 data[x7+y6+z3]*tablex7 ) * tabley6 + 01040 ( data[x1+y7+z3]*tablex1 + data[x2+y7+z3]*tablex2 + data[x3+y7+z3]*tablex3 + 01041 data[x4+y7+z3]*tablex4 + data[x5+y7+z3]*tablex5 + data[x6+y7+z3]*tablex6 + 01042 data[x7+y7+z3]*tablex7 ) * tabley7 ) *tablez3 + 01043 ( ( data[x1+y1+z4]*tablex1 + data[x2+y1+z4]*tablex2 + data[x3+y1+z4]*tablex3 + 01044 data[x4+y1+z4]*tablex4 + data[x5+y1+z4]*tablex5 + data[x6+y1+z4]*tablex6 + 01045 data[x7+y1+z4]*tablex7 ) * tabley1 + 01046 ( data[x1+y2+z4]*tablex1 + data[x2+y2+z4]*tablex2 + data[x3+y2+z4]*tablex3 + 01047 data[x4+y2+z4]*tablex4 + data[x5+y2+z4]*tablex5 + data[x6+y2+z4]*tablex6 + 01048 data[x7+y2+z4]*tablex7 ) * tabley2 + 01049 ( data[x1+y3+z4]*tablex1 + data[x2+y3+z4]*tablex2 + data[x3+y3+z4]*tablex3 + 01050 data[x4+y3+z4]*tablex4 + data[x5+y3+z4]*tablex5 + data[x6+y3+z4]*tablex6 + 01051 data[x7+y3+z4]*tablex7 ) * tabley3 + 01052 ( data[x1+y4+z4]*tablex1 + data[x2+y4+z4]*tablex2 + data[x3+y4+z4]*tablex3 + 01053 data[x4+y4+z4]*tablex4 + data[x5+y4+z4]*tablex5 + data[x6+y4+z4]*tablex6 + 01054 data[x7+y4+z4]*tablex7 ) * tabley4 + 01055 ( data[x1+y5+z4]*tablex1 + data[x2+y5+z4]*tablex2 + data[x3+y5+z4]*tablex3 + 01056 data[x4+y5+z4]*tablex4 + data[x5+y5+z4]*tablex5 + data[x6+y5+z4]*tablex6 + 01057 data[x7+y5+z4]*tablex7 ) * tabley5 + 01058 ( data[x1+y6+z4]*tablex1 + data[x2+y6+z4]*tablex2 + data[x3+y6+z4]*tablex3 + 01059 data[x4+y6+z4]*tablex4 + data[x5+y6+z4]*tablex5 + data[x6+y6+z4]*tablex6 + 01060 data[x7+y6+z4]*tablex7 ) * tabley6 + 01061 ( data[x1+y7+z4]*tablex1 + data[x2+y7+z4]*tablex2 + data[x3+y7+z4]*tablex3 + 01062 data[x4+y7+z4]*tablex4 + data[x5+y7+z4]*tablex5 + data[x6+y7+z4]*tablex6 + 01063 data[x7+y7+z4]*tablex7 ) * tabley7 ) *tablez4 + 01064 ( ( data[x1+y1+z5]*tablex1 + data[x2+y1+z5]*tablex2 + data[x3+y1+z5]*tablex3 + 01065 data[x4+y1+z5]*tablex4 + data[x5+y1+z5]*tablex5 + data[x6+y1+z5]*tablex6 + 01066 data[x7+y1+z5]*tablex7 ) * tabley1 + 01067 ( data[x1+y2+z5]*tablex1 + data[x2+y2+z5]*tablex2 + data[x3+y2+z5]*tablex3 + 01068 data[x4+y2+z5]*tablex4 + data[x5+y2+z5]*tablex5 + data[x6+y2+z5]*tablex6 + 01069 data[x7+y2+z5]*tablex7 ) * tabley2 + 01070 ( data[x1+y3+z5]*tablex1 + data[x2+y3+z5]*tablex2 + data[x3+y3+z5]*tablex3 + 01071 data[x4+y3+z5]*tablex4 + data[x5+y3+z5]*tablex5 + data[x6+y3+z5]*tablex6 + 01072 data[x7+y3+z5]*tablex7 ) * tabley3 + 01073 ( data[x1+y4+z5]*tablex1 + data[x2+y4+z5]*tablex2 + data[x3+y4+z5]*tablex3 + 01074 data[x4+y4+z5]*tablex4 + data[x5+y4+z5]*tablex5 + data[x6+y4+z5]*tablex6 + 01075 data[x7+y4+z5]*tablex7 ) * tabley4 + 01076 ( data[x1+y5+z5]*tablex1 + data[x2+y5+z5]*tablex2 + data[x3+y5+z5]*tablex3 + 01077 data[x4+y5+z5]*tablex4 + data[x5+y5+z5]*tablex5 + data[x6+y5+z5]*tablex6 + 01078 data[x7+y5+z5]*tablex7 ) * tabley5 + 01079 ( data[x1+y6+z5]*tablex1 + data[x2+y6+z5]*tablex2 + data[x3+y6+z5]*tablex3 + 01080 data[x4+y6+z5]*tablex4 + data[x5+y6+z5]*tablex5 + data[x6+y6+z5]*tablex6 + 01081 data[x7+y6+z5]*tablex7 ) * tabley6 + 01082 ( data[x1+y7+z5]*tablex1 + data[x2+y7+z5]*tablex2 + data[x3+y7+z5]*tablex3 + 01083 data[x4+y7+z5]*tablex4 + data[x5+y7+z5]*tablex5 + data[x6+y7+z5]*tablex6 + 01084 data[x7+y7+z5]*tablex7 ) * tabley7 ) *tablez5 + 01085 ( ( data[x1+y1+z6]*tablex1 + data[x2+y1+z6]*tablex2 + data[x3+y1+z6]*tablex3 + 01086 data[x4+y1+z6]*tablex4 + data[x5+y1+z6]*tablex5 + data[x6+y1+z6]*tablex6 + 01087 data[x7+y1+z6]*tablex7 ) * tabley1 + 01088 ( data[x1+y2+z6]*tablex1 + data[x2+y2+z6]*tablex2 + data[x3+y2+z6]*tablex3 + 01089 data[x4+y2+z6]*tablex4 + data[x5+y2+z6]*tablex5 + data[x6+y2+z6]*tablex6 + 01090 data[x7+y2+z6]*tablex7 ) * tabley2 + 01091 ( data[x1+y3+z6]*tablex1 + data[x2+y3+z6]*tablex2 + data[x3+y3+z6]*tablex3 + 01092 data[x4+y3+z6]*tablex4 + data[x5+y3+z6]*tablex5 + data[x6+y3+z6]*tablex6 + 01093 data[x7+y3+z6]*tablex7 ) * tabley3 + 01094 ( data[x1+y4+z6]*tablex1 + data[x2+y4+z6]*tablex2 + data[x3+y4+z6]*tablex3 + 01095 data[x4+y4+z6]*tablex4 + data[x5+y4+z6]*tablex5 + data[x6+y4+z6]*tablex6 + 01096 data[x7+y4+z6]*tablex7 ) * tabley4 + 01097 ( data[x1+y5+z6]*tablex1 + data[x2+y5+z6]*tablex2 + data[x3+y5+z6]*tablex3 + 01098 data[x4+y5+z6]*tablex4 + data[x5+y5+z6]*tablex5 + data[x6+y5+z6]*tablex6 + 01099 data[x7+y5+z6]*tablex7 ) * tabley5 + 01100 ( data[x1+y6+z6]*tablex1 + data[x2+y6+z6]*tablex2 + data[x3+y6+z6]*tablex3 + 01101 data[x4+y6+z6]*tablex4 + data[x5+y6+z6]*tablex5 + data[x6+y6+z6]*tablex6 + 01102 data[x7+y6+z6]*tablex7 ) * tabley6 + 01103 ( data[x1+y7+z6]*tablex1 + data[x2+y7+z6]*tablex2 + data[x3+y7+z6]*tablex3 + 01104 data[x4+y7+z6]*tablex4 + data[x5+y7+z6]*tablex5 + data[x6+y7+z6]*tablex6 + 01105 data[x7+y7+z6]*tablex7 ) * tabley7 ) *tablez6 + 01106 ( ( data[x1+y1+z7]*tablex1 + data[x2+y1+z7]*tablex2 + data[x3+y1+z7]*tablex3 + 01107 data[x4+y1+z7]*tablex4 + data[x5+y1+z7]*tablex5 + data[x6+y1+z7]*tablex6 + 01108 data[x7+y1+z7]*tablex7 ) * tabley1 + 01109 ( data[x1+y2+z7]*tablex1 + data[x2+y2+z7]*tablex2 + data[x3+y2+z7]*tablex3 + 01110 data[x4+y2+z7]*tablex4 + data[x5+y2+z7]*tablex5 + data[x6+y2+z7]*tablex6 + 01111 data[x7+y2+z7]*tablex7 ) * tabley2 + 01112 ( data[x1+y3+z7]*tablex1 + data[x2+y3+z7]*tablex2 + data[x3+y3+z7]*tablex3 + 01113 data[x4+y3+z7]*tablex4 + data[x5+y3+z7]*tablex5 + data[x6+y3+z7]*tablex6 + 01114 data[x7+y3+z7]*tablex7 ) * tabley3 + 01115 ( data[x1+y4+z7]*tablex1 + data[x2+y4+z7]*tablex2 + data[x3+y4+z7]*tablex3 + 01116 data[x4+y4+z7]*tablex4 + data[x5+y4+z7]*tablex5 + data[x6+y4+z7]*tablex6 + 01117 data[x7+y4+z7]*tablex7 ) * tabley4 + 01118 ( data[x1+y5+z7]*tablex1 + data[x2+y5+z7]*tablex2 + data[x3+y5+z7]*tablex3 + 01119 data[x4+y5+z7]*tablex4 + data[x5+y5+z7]*tablex5 + data[x6+y5+z7]*tablex6 + 01120 data[x7+y5+z7]*tablex7 ) * tabley5 + 01121 ( data[x1+y6+z7]*tablex1 + data[x2+y6+z7]*tablex2 + data[x3+y6+z7]*tablex3 + 01122 data[x4+y6+z7]*tablex4 + data[x5+y6+z7]*tablex5 + data[x6+y6+z7]*tablex6 + 01123 data[x7+y6+z7]*tablex7 ) * tabley6 + 01124 ( data[x1+y7+z7]*tablex1 + data[x2+y7+z7]*tablex2 + data[x3+y7+z7]*tablex3 + 01125 data[x4+y7+z7]*tablex4 + data[x5+y7+z7]*tablex5 + data[x6+y7+z7]*tablex6 + 01126 data[x7+y7+z7]*tablex7 ) * tabley7 ) *tablez7; 01127 01128 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) * 01129 (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7) * 01130 (tablez1+tablez2+tablez3+tablez4+tablez5+tablez6+tablez7); 01131 } 01132 return pixel/w; 01133 }
|
|
Definition at line 1135 of file util_sparx.cpp. References data, EMAN::Util::KaiserBessel::get_window_size(), EMAN::Util::KaiserBessel::i0win_tab(), nx, ny, restrict1(), and round(). 01135 { 01136 int K = kb.get_window_size(); 01137 int kbmin = -K/2; 01138 int kbmax = -kbmin; 01139 int kbc = kbmax+1; 01140 01141 float pixel =0.0f; 01142 float w=0.0f; 01143 01144 float argdelx = delx; // adding this for 2D case where the wrap around is not done circulantly using restrict1. 01145 delx = restrict1(delx, nx); 01146 int inxold = int(round(delx)); 01147 if ( ny < 2 ) { //1D 01148 float tablex1 = kb.i0win_tab(delx-inxold+3); 01149 float tablex2 = kb.i0win_tab(delx-inxold+2); 01150 float tablex3 = kb.i0win_tab(delx-inxold+1); 01151 float tablex4 = kb.i0win_tab(delx-inxold); 01152 float tablex5 = kb.i0win_tab(delx-inxold-1); 01153 float tablex6 = kb.i0win_tab(delx-inxold-2); 01154 float tablex7 = kb.i0win_tab(delx-inxold-3); 01155 01156 int x1, x2, x3, x4, x5, x6, x7; 01157 01158 if ( inxold <= kbc || inxold >=nx-kbc-2 ) { 01159 x1 = (inxold-3+nx)%nx; 01160 x2 = (inxold-2+nx)%nx; 01161 x3 = (inxold-1+nx)%nx; 01162 x4 = (inxold +nx)%nx; 01163 x5 = (inxold+1+nx)%nx; 01164 x6 = (inxold+2+nx)%nx; 01165 x7 = (inxold+3+nx)%nx; 01166 } else { 01167 x1 = inxold-3; 01168 x2 = inxold-2; 01169 x3 = inxold-1; 01170 x4 = inxold; 01171 x5 = inxold+1; 01172 x6 = inxold+2; 01173 x7 = inxold+3; 01174 } 01175 01176 pixel = data[x1]*tablex1 + data[x2]*tablex2 + data[x3]*tablex3 + 01177 data[x4]*tablex4 + data[x5]*tablex5 + data[x6]*tablex6 + 01178 data[x7]*tablex7 ; 01179 01180 w = tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7; 01181 } else if ( nz < 2 ) { // 2D 01182 01183 delx = argdelx; 01184 // the wrap around is not done circulantly for 2D case; if (argdelx, argdely) is not in the image, then make them (xnew, ynew) which is definitely in the image 01185 if ((delx < 0.0f) || (delx >= (float) (nx)) || (dely < 0.0f) || (dely >= (float) (ny)) ){ 01186 delx = (float)xnew*2.0f; 01187 dely = (float)ynew*2.0f; 01188 } 01189 01190 int inxold = int(round(delx)); 01191 int inyold = int(round(dely)); 01192 01193 float tablex1 = kb.i0win_tab(delx-inxold+3); 01194 float tablex2 = kb.i0win_tab(delx-inxold+2); 01195 float tablex3 = kb.i0win_tab(delx-inxold+1); 01196 float tablex4 = kb.i0win_tab(delx-inxold); 01197 float tablex5 = kb.i0win_tab(delx-inxold-1); 01198 float tablex6 = kb.i0win_tab(delx-inxold-2); 01199 float tablex7 = kb.i0win_tab(delx-inxold-3); 01200 01201 float tabley1 = kb.i0win_tab(dely-inyold+3); 01202 float tabley2 = kb.i0win_tab(dely-inyold+2); 01203 float tabley3 = kb.i0win_tab(dely-inyold+1); 01204 float tabley4 = kb.i0win_tab(dely-inyold); 01205 float tabley5 = kb.i0win_tab(dely-inyold-1); 01206 float tabley6 = kb.i0win_tab(dely-inyold-2); 01207 float tabley7 = kb.i0win_tab(dely-inyold-3); 01208 01209 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7; 01210 01211 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 ) { 01212 x1 = (inxold-3+nx)%nx; 01213 x2 = (inxold-2+nx)%nx; 01214 x3 = (inxold-1+nx)%nx; 01215 x4 = (inxold +nx)%nx; 01216 x5 = (inxold+1+nx)%nx; 01217 x6 = (inxold+2+nx)%nx; 01218 x7 = (inxold+3+nx)%nx; 01219 01220 y1 = ((inyold-3+ny)%ny)*nx; 01221 y2 = ((inyold-2+ny)%ny)*nx; 01222 y3 = ((inyold-1+ny)%ny)*nx; 01223 y4 = ((inyold +ny)%ny)*nx; 01224 y5 = ((inyold+1+ny)%ny)*nx; 01225 y6 = ((inyold+2+ny)%ny)*nx; 01226 y7 = ((inyold+3+ny)%ny)*nx; 01227 } else { 01228 x1 = inxold-3; 01229 x2 = inxold-2; 01230 x3 = inxold-1; 01231 x4 = inxold; 01232 x5 = inxold+1; 01233 x6 = inxold+2; 01234 x7 = inxold+3; 01235 01236 y1 = (inyold-3)*nx; 01237 y2 = (inyold-2)*nx; 01238 y3 = (inyold-1)*nx; 01239 y4 = inyold*nx; 01240 y5 = (inyold+1)*nx; 01241 y6 = (inyold+2)*nx; 01242 y7 = (inyold+3)*nx; 01243 } 01244 01245 pixel = ( data[x1+y1]*tablex1 + data[x2+y1]*tablex2 + data[x3+y1]*tablex3 + 01246 data[x4+y1]*tablex4 + data[x5+y1]*tablex5 + data[x6+y1]*tablex6 + 01247 data[x7+y1]*tablex7 ) * tabley1 + 01248 ( data[x1+y2]*tablex1 + data[x2+y2]*tablex2 + data[x3+y2]*tablex3 + 01249 data[x4+y2]*tablex4 + data[x5+y2]*tablex5 + data[x6+y2]*tablex6 + 01250 data[x7+y2]*tablex7 ) * tabley2 + 01251 ( data[x1+y3]*tablex1 + data[x2+y3]*tablex2 + data[x3+y3]*tablex3 + 01252 data[x4+y3]*tablex4 + data[x5+y3]*tablex5 + data[x6+y3]*tablex6 + 01253 data[x7+y3]*tablex7 ) * tabley3 + 01254 ( data[x1+y4]*tablex1 + data[x2+y4]*tablex2 + data[x3+y4]*tablex3 + 01255 data[x4+y4]*tablex4 + data[x5+y4]*tablex5 + data[x6+y4]*tablex6 + 01256 data[x7+y4]*tablex7 ) * tabley4 + 01257 ( data[x1+y5]*tablex1 + data[x2+y5]*tablex2 + data[x3+y5]*tablex3 + 01258 data[x4+y5]*tablex4 + data[x5+y5]*tablex5 + data[x6+y5]*tablex6 + 01259 data[x7+y5]*tablex7 ) * tabley5 + 01260 ( data[x1+y6]*tablex1 + data[x2+y6]*tablex2 + data[x3+y6]*tablex3 + 01261 data[x4+y6]*tablex4 + data[x5+y6]*tablex5 + data[x6+y6]*tablex6 + 01262 data[x7+y6]*tablex7 ) * tabley6 + 01263 ( data[x1+y7]*tablex1 + data[x2+y7]*tablex2 + data[x3+y7]*tablex3 + 01264 data[x4+y7]*tablex4 + data[x5+y7]*tablex5 + data[x6+y7]*tablex6 + 01265 data[x7+y7]*tablex7 ) * tabley7; 01266 01267 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) * 01268 (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7); 01269 } else { // 3D 01270 dely = restrict1(dely, ny); 01271 int inyold = int(Util::round(dely)); 01272 delz = restrict1(delz, nz); 01273 int inzold = int(Util::round(delz)); 01274 01275 float tablex1 = kb.i0win_tab(delx-inxold+3); 01276 float tablex2 = kb.i0win_tab(delx-inxold+2); 01277 float tablex3 = kb.i0win_tab(delx-inxold+1); 01278 float tablex4 = kb.i0win_tab(delx-inxold); 01279 float tablex5 = kb.i0win_tab(delx-inxold-1); 01280 float tablex6 = kb.i0win_tab(delx-inxold-2); 01281 float tablex7 = kb.i0win_tab(delx-inxold-3); 01282 01283 float tabley1 = kb.i0win_tab(dely-inyold+3); 01284 float tabley2 = kb.i0win_tab(dely-inyold+2); 01285 float tabley3 = kb.i0win_tab(dely-inyold+1); 01286 float tabley4 = kb.i0win_tab(dely-inyold); 01287 float tabley5 = kb.i0win_tab(dely-inyold-1); 01288 float tabley6 = kb.i0win_tab(dely-inyold-2); 01289 float tabley7 = kb.i0win_tab(dely-inyold-3); 01290 01291 float tablez1 = kb.i0win_tab(delz-inzold+3); 01292 float tablez2 = kb.i0win_tab(delz-inzold+2); 01293 float tablez3 = kb.i0win_tab(delz-inzold+1); 01294 float tablez4 = kb.i0win_tab(delz-inzold); 01295 float tablez5 = kb.i0win_tab(delz-inzold-1); 01296 float tablez6 = kb.i0win_tab(delz-inzold-2); 01297 float tablez7 = kb.i0win_tab(delz-inzold-3); 01298 01299 int x1, x2, x3, x4, x5, x6, x7, y1, y2, y3, y4, y5, y6, y7, z1, z2, z3, z4, z5, z6, z7; 01300 01301 if ( inxold <= kbc || inxold >=nx-kbc-2 || inyold <= kbc || inyold >=ny-kbc-2 || inzold <= kbc || inzold >= nz-kbc-2 ) { 01302 x1 = (inxold-3+nx)%nx; 01303 x2 = (inxold-2+nx)%nx; 01304 x3 = (inxold-1+nx)%nx; 01305 x4 = (inxold +nx)%nx; 01306 x5 = (inxold+1+nx)%nx; 01307 x6 = (inxold+2+nx)%nx; 01308 x7 = (inxold+3+nx)%nx; 01309 01310 y1 = ((inyold-3+ny)%ny)*nx; 01311 y2 = ((inyold-2+ny)%ny)*nx; 01312 y3 = ((inyold-1+ny)%ny)*nx; 01313 y4 = ((inyold +ny)%ny)*nx; 01314 y5 = ((inyold+1+ny)%ny)*nx; 01315 y6 = ((inyold+2+ny)%ny)*nx; 01316 y7 = ((inyold+3+ny)%ny)*nx; 01317 01318 z1 = ((inzold-3+nz)%nz)*nx*ny; 01319 z2 = ((inzold-2+nz)%nz)*nx*ny; 01320 z3 = ((inzold-1+nz)%nz)*nx*ny; 01321 z4 = ((inzold +nz)%nz)*nx*ny; 01322 z5 = ((inzold+1+nz)%nz)*nx*ny; 01323 z6 = ((inzold+2+nz)%nz)*nx*ny; 01324 z7 = ((inzold+3+nz)%nz)*nx*ny; 01325 } else { 01326 x1 = inxold-3; 01327 x2 = inxold-2; 01328 x3 = inxold-1; 01329 x4 = inxold; 01330 x5 = inxold+1; 01331 x6 = inxold+2; 01332 x7 = inxold+3; 01333 01334 y1 = (inyold-3)*nx; 01335 y2 = (inyold-2)*nx; 01336 y3 = (inyold-1)*nx; 01337 y4 = inyold*nx; 01338 y5 = (inyold+1)*nx; 01339 y6 = (inyold+2)*nx; 01340 y7 = (inyold+3)*nx; 01341 01342 z1 = (inzold-3)*nx*ny; 01343 z2 = (inzold-2)*nx*ny; 01344 z3 = (inzold-1)*nx*ny; 01345 z4 = inzold*nx*ny; 01346 z5 = (inzold+1)*nx*ny; 01347 z6 = (inzold+2)*nx*ny; 01348 z7 = (inzold+3)*nx*ny; 01349 } 01350 01351 pixel = ( ( data[x1+y1+z1]*tablex1 + data[x2+y1+z1]*tablex2 + data[x3+y1+z1]*tablex3 + 01352 data[x4+y1+z1]*tablex4 + data[x5+y1+z1]*tablex5 + data[x6+y1+z1]*tablex6 + 01353 data[x7+y1+z1]*tablex7 ) * tabley1 + 01354 ( data[x1+y2+z1]*tablex1 + data[x2+y2+z1]*tablex2 + data[x3+y2+z1]*tablex3 + 01355 data[x4+y2+z1]*tablex4 + data[x5+y2+z1]*tablex5 + data[x6+y2+z1]*tablex6 + 01356 data[x7+y2+z1]*tablex7 ) * tabley2 + 01357 ( data[x1+y3+z1]*tablex1 + data[x2+y3+z1]*tablex2 + data[x3+y3+z1]*tablex3 + 01358 data[x4+y3+z1]*tablex4 + data[x5+y3+z1]*tablex5 + data[x6+y3+z1]*tablex6 + 01359 data[x7+y3+z1]*tablex7 ) * tabley3 + 01360 ( data[x1+y4+z1]*tablex1 + data[x2+y4+z1]*tablex2 + data[x3+y4+z1]*tablex3 + 01361 data[x4+y4+z1]*tablex4 + data[x5+y4+z1]*tablex5 + data[x6+y4+z1]*tablex6 + 01362 data[x7+y4+z1]*tablex7 ) * tabley4 + 01363 ( data[x1+y5+z1]*tablex1 + data[x2+y5+z1]*tablex2 + data[x3+y5+z1]*tablex3 + 01364 data[x4+y5+z1]*tablex4 + data[x5+y5+z1]*tablex5 + data[x6+y5+z1]*tablex6 + 01365 data[x7+y5+z1]*tablex7 ) * tabley5 + 01366 ( data[x1+y6+z1]*tablex1 + data[x2+y6+z1]*tablex2 + data[x3+y6+z1]*tablex3 + 01367 data[x4+y6+z1]*tablex4 + data[x5+y6+z1]*tablex5 + data[x6+y6+z1]*tablex6 + 01368 data[x7+y6+z1]*tablex7 ) * tabley6 + 01369 ( data[x1+y7+z1]*tablex1 + data[x2+y7+z1]*tablex2 + data[x3+y7+z1]*tablex3 + 01370 data[x4+y7+z1]*tablex4 + data[x5+y7+z1]*tablex5 + data[x6+y7+z1]*tablex6 + 01371 data[x7+y7+z1]*tablex7 ) * tabley7 ) *tablez1 + 01372 ( ( data[x1+y1+z2]*tablex1 + data[x2+y1+z2]*tablex2 + data[x3+y1+z2]*tablex3 + 01373 data[x4+y1+z2]*tablex4 + data[x5+y1+z2]*tablex5 + data[x6+y1+z2]*tablex6 + 01374 data[x7+y1+z2]*tablex7 ) * tabley1 + 01375 ( data[x1+y2+z2]*tablex1 + data[x2+y2+z2]*tablex2 + data[x3+y2+z2]*tablex3 + 01376 data[x4+y2+z2]*tablex4 + data[x5+y2+z2]*tablex5 + data[x6+y2+z2]*tablex6 + 01377 data[x7+y2+z2]*tablex7 ) * tabley2 + 01378 ( data[x1+y3+z2]*tablex1 + data[x2+y3+z2]*tablex2 + data[x3+y3+z2]*tablex3 + 01379 data[x4+y3+z2]*tablex4 + data[x5+y3+z2]*tablex5 + data[x6+y3+z2]*tablex6 + 01380 data[x7+y3+z2]*tablex7 ) * tabley3 + 01381 ( data[x1+y4+z2]*tablex1 + data[x2+y4+z2]*tablex2 + data[x3+y4+z2]*tablex3 + 01382 data[x4+y4+z2]*tablex4 + data[x5+y4+z2]*tablex5 + data[x6+y4+z2]*tablex6 + 01383 data[x7+y4+z2]*tablex7 ) * tabley4 + 01384 ( data[x1+y5+z2]*tablex1 + data[x2+y5+z2]*tablex2 + data[x3+y5+z2]*tablex3 + 01385 data[x4+y5+z2]*tablex4 + data[x5+y5+z2]*tablex5 + data[x6+y5+z2]*tablex6 + 01386 data[x7+y5+z2]*tablex7 ) * tabley5 + 01387 ( data[x1+y6+z2]*tablex1 + data[x2+y6+z2]*tablex2 + data[x3+y6+z2]*tablex3 + 01388 data[x4+y6+z2]*tablex4 + data[x5+y6+z2]*tablex5 + data[x6+y6+z2]*tablex6 + 01389 data[x7+y6+z2]*tablex7 ) * tabley6 + 01390 ( data[x1+y7+z2]*tablex1 + data[x2+y7+z2]*tablex2 + data[x3+y7+z2]*tablex3 + 01391 data[x4+y7+z2]*tablex4 + data[x5+y7+z2]*tablex5 + data[x6+y7+z2]*tablex6 + 01392 data[x7+y7+z2]*tablex7 ) * tabley7 ) *tablez2 + 01393 ( ( data[x1+y1+z3]*tablex1 + data[x2+y1+z3]*tablex2 + data[x3+y1+z3]*tablex3 + 01394 data[x4+y1+z3]*tablex4 + data[x5+y1+z3]*tablex5 + data[x6+y1+z3]*tablex6 + 01395 data[x7+y1+z3]*tablex7 ) * tabley1 + 01396 ( data[x1+y2+z3]*tablex1 + data[x2+y2+z3]*tablex2 + data[x3+y2+z3]*tablex3 + 01397 data[x4+y2+z3]*tablex4 + data[x5+y2+z3]*tablex5 + data[x6+y2+z3]*tablex6 + 01398 data[x7+y2+z3]*tablex7 ) * tabley2 + 01399 ( data[x1+y3+z3]*tablex1 + data[x2+y3+z3]*tablex2 + data[x3+y3+z3]*tablex3 + 01400 data[x4+y3+z3]*tablex4 + data[x5+y3+z3]*tablex5 + data[x6+y3+z3]*tablex6 + 01401 data[x7+y3+z3]*tablex7 ) * tabley3 + 01402 ( data[x1+y4+z3]*tablex1 + data[x2+y4+z3]*tablex2 + data[x3+y4+z3]*tablex3 + 01403 data[x4+y4+z3]*tablex4 + data[x5+y4+z3]*tablex5 + data[x6+y4+z3]*tablex6 + 01404 data[x7+y4+z3]*tablex7 ) * tabley4 + 01405 ( data[x1+y5+z3]*tablex1 + data[x2+y5+z3]*tablex2 + data[x3+y5+z3]*tablex3 + 01406 data[x4+y5+z3]*tablex4 + data[x5+y5+z3]*tablex5 + data[x6+y5+z3]*tablex6 + 01407 data[x7+y5+z3]*tablex7 ) * tabley5 + 01408 ( data[x1+y6+z3]*tablex1 + data[x2+y6+z3]*tablex2 + data[x3+y6+z3]*tablex3 + 01409 data[x4+y6+z3]*tablex4 + data[x5+y6+z3]*tablex5 + data[x6+y6+z3]*tablex6 + 01410 data[x7+y6+z3]*tablex7 ) * tabley6 + 01411 ( data[x1+y7+z3]*tablex1 + data[x2+y7+z3]*tablex2 + data[x3+y7+z3]*tablex3 + 01412 data[x4+y7+z3]*tablex4 + data[x5+y7+z3]*tablex5 + data[x6+y7+z3]*tablex6 + 01413 data[x7+y7+z3]*tablex7 ) * tabley7 ) *tablez3 + 01414 ( ( data[x1+y1+z4]*tablex1 + data[x2+y1+z4]*tablex2 + data[x3+y1+z4]*tablex3 + 01415 data[x4+y1+z4]*tablex4 + data[x5+y1+z4]*tablex5 + data[x6+y1+z4]*tablex6 + 01416 data[x7+y1+z4]*tablex7 ) * tabley1 + 01417 ( data[x1+y2+z4]*tablex1 + data[x2+y2+z4]*tablex2 + data[x3+y2+z4]*tablex3 + 01418 data[x4+y2+z4]*tablex4 + data[x5+y2+z4]*tablex5 + data[x6+y2+z4]*tablex6 + 01419 data[x7+y2+z4]*tablex7 ) * tabley2 + 01420 ( data[x1+y3+z4]*tablex1 + data[x2+y3+z4]*tablex2 + data[x3+y3+z4]*tablex3 + 01421 data[x4+y3+z4]*tablex4 + data[x5+y3+z4]*tablex5 + data[x6+y3+z4]*tablex6 + 01422 data[x7+y3+z4]*tablex7 ) * tabley3 + 01423 ( data[x1+y4+z4]*tablex1 + data[x2+y4+z4]*tablex2 + data[x3+y4+z4]*tablex3 + 01424 data[x4+y4+z4]*tablex4 + data[x5+y4+z4]*tablex5 + data[x6+y4+z4]*tablex6 + 01425 data[x7+y4+z4]*tablex7 ) * tabley4 + 01426 ( data[x1+y5+z4]*tablex1 + data[x2+y5+z4]*tablex2 + data[x3+y5+z4]*tablex3 + 01427 data[x4+y5+z4]*tablex4 + data[x5+y5+z4]*tablex5 + data[x6+y5+z4]*tablex6 + 01428 data[x7+y5+z4]*tablex7 ) * tabley5 + 01429 ( data[x1+y6+z4]*tablex1 + data[x2+y6+z4]*tablex2 + data[x3+y6+z4]*tablex3 + 01430 data[x4+y6+z4]*tablex4 + data[x5+y6+z4]*tablex5 + data[x6+y6+z4]*tablex6 + 01431 data[x7+y6+z4]*tablex7 ) * tabley6 + 01432 ( data[x1+y7+z4]*tablex1 + data[x2+y7+z4]*tablex2 + data[x3+y7+z4]*tablex3 + 01433 data[x4+y7+z4]*tablex4 + data[x5+y7+z4]*tablex5 + data[x6+y7+z4]*tablex6 + 01434 data[x7+y7+z4]*tablex7 ) * tabley7 ) *tablez4 + 01435 ( ( data[x1+y1+z5]*tablex1 + data[x2+y1+z5]*tablex2 + data[x3+y1+z5]*tablex3 + 01436 data[x4+y1+z5]*tablex4 + data[x5+y1+z5]*tablex5 + data[x6+y1+z5]*tablex6 + 01437 data[x7+y1+z5]*tablex7 ) * tabley1 + 01438 ( data[x1+y2+z5]*tablex1 + data[x2+y2+z5]*tablex2 + data[x3+y2+z5]*tablex3 + 01439 data[x4+y2+z5]*tablex4 + data[x5+y2+z5]*tablex5 + data[x6+y2+z5]*tablex6 + 01440 data[x7+y2+z5]*tablex7 ) * tabley2 + 01441 ( data[x1+y3+z5]*tablex1 + data[x2+y3+z5]*tablex2 + data[x3+y3+z5]*tablex3 + 01442 data[x4+y3+z5]*tablex4 + data[x5+y3+z5]*tablex5 + data[x6+y3+z5]*tablex6 + 01443 data[x7+y3+z5]*tablex7 ) * tabley3 + 01444 ( data[x1+y4+z5]*tablex1 + data[x2+y4+z5]*tablex2 + data[x3+y4+z5]*tablex3 + 01445 data[x4+y4+z5]*tablex4 + data[x5+y4+z5]*tablex5 + data[x6+y4+z5]*tablex6 + 01446 data[x7+y4+z5]*tablex7 ) * tabley4 + 01447 ( data[x1+y5+z5]*tablex1 + data[x2+y5+z5]*tablex2 + data[x3+y5+z5]*tablex3 + 01448 data[x4+y5+z5]*tablex4 + data[x5+y5+z5]*tablex5 + data[x6+y5+z5]*tablex6 + 01449 data[x7+y5+z5]*tablex7 ) * tabley5 + 01450 ( data[x1+y6+z5]*tablex1 + data[x2+y6+z5]*tablex2 + data[x3+y6+z5]*tablex3 + 01451 data[x4+y6+z5]*tablex4 + data[x5+y6+z5]*tablex5 + data[x6+y6+z5]*tablex6 + 01452 data[x7+y6+z5]*tablex7 ) * tabley6 + 01453 ( data[x1+y7+z5]*tablex1 + data[x2+y7+z5]*tablex2 + data[x3+y7+z5]*tablex3 + 01454 data[x4+y7+z5]*tablex4 + data[x5+y7+z5]*tablex5 + data[x6+y7+z5]*tablex6 + 01455 data[x7+y7+z5]*tablex7 ) * tabley7 ) *tablez5 + 01456 ( ( data[x1+y1+z6]*tablex1 + data[x2+y1+z6]*tablex2 + data[x3+y1+z6]*tablex3 + 01457 data[x4+y1+z6]*tablex4 + data[x5+y1+z6]*tablex5 + data[x6+y1+z6]*tablex6 + 01458 data[x7+y1+z6]*tablex7 ) * tabley1 + 01459 ( data[x1+y2+z6]*tablex1 + data[x2+y2+z6]*tablex2 + data[x3+y2+z6]*tablex3 + 01460 data[x4+y2+z6]*tablex4 + data[x5+y2+z6]*tablex5 + data[x6+y2+z6]*tablex6 + 01461 data[x7+y2+z6]*tablex7 ) * tabley2 + 01462 ( data[x1+y3+z6]*tablex1 + data[x2+y3+z6]*tablex2 + data[x3+y3+z6]*tablex3 + 01463 data[x4+y3+z6]*tablex4 + data[x5+y3+z6]*tablex5 + data[x6+y3+z6]*tablex6 + 01464 data[x7+y3+z6]*tablex7 ) * tabley3 + 01465 ( data[x1+y4+z6]*tablex1 + data[x2+y4+z6]*tablex2 + data[x3+y4+z6]*tablex3 + 01466 data[x4+y4+z6]*tablex4 + data[x5+y4+z6]*tablex5 + data[x6+y4+z6]*tablex6 + 01467 data[x7+y4+z6]*tablex7 ) * tabley4 + 01468 ( data[x1+y5+z6]*tablex1 + data[x2+y5+z6]*tablex2 + data[x3+y5+z6]*tablex3 + 01469 data[x4+y5+z6]*tablex4 + data[x5+y5+z6]*tablex5 + data[x6+y5+z6]*tablex6 + 01470 data[x7+y5+z6]*tablex7 ) * tabley5 + 01471 ( data[x1+y6+z6]*tablex1 + data[x2+y6+z6]*tablex2 + data[x3+y6+z6]*tablex3 + 01472 data[x4+y6+z6]*tablex4 + data[x5+y6+z6]*tablex5 + data[x6+y6+z6]*tablex6 + 01473 data[x7+y6+z6]*tablex7 ) * tabley6 + 01474 ( data[x1+y7+z6]*tablex1 + data[x2+y7+z6]*tablex2 + data[x3+y7+z6]*tablex3 + 01475 data[x4+y7+z6]*tablex4 + data[x5+y7+z6]*tablex5 + data[x6+y7+z6]*tablex6 + 01476 data[x7+y7+z6]*tablex7 ) * tabley7 ) *tablez6 + 01477 ( ( data[x1+y1+z7]*tablex1 + data[x2+y1+z7]*tablex2 + data[x3+y1+z7]*tablex3 + 01478 data[x4+y1+z7]*tablex4 + data[x5+y1+z7]*tablex5 + data[x6+y1+z7]*tablex6 + 01479 data[x7+y1+z7]*tablex7 ) * tabley1 + 01480 ( data[x1+y2+z7]*tablex1 + data[x2+y2+z7]*tablex2 + data[x3+y2+z7]*tablex3 + 01481 data[x4+y2+z7]*tablex4 + data[x5+y2+z7]*tablex5 + data[x6+y2+z7]*tablex6 + 01482 data[x7+y2+z7]*tablex7 ) * tabley2 + 01483 ( data[x1+y3+z7]*tablex1 + data[x2+y3+z7]*tablex2 + data[x3+y3+z7]*tablex3 + 01484 data[x4+y3+z7]*tablex4 + data[x5+y3+z7]*tablex5 + data[x6+y3+z7]*tablex6 + 01485 data[x7+y3+z7]*tablex7 ) * tabley3 + 01486 ( data[x1+y4+z7]*tablex1 + data[x2+y4+z7]*tablex2 + data[x3+y4+z7]*tablex3 + 01487 data[x4+y4+z7]*tablex4 + data[x5+y4+z7]*tablex5 + data[x6+y4+z7]*tablex6 + 01488 data[x7+y4+z7]*tablex7 ) * tabley4 + 01489 ( data[x1+y5+z7]*tablex1 + data[x2+y5+z7]*tablex2 + data[x3+y5+z7]*tablex3 + 01490 data[x4+y5+z7]*tablex4 + data[x5+y5+z7]*tablex5 + data[x6+y5+z7]*tablex6 + 01491 data[x7+y5+z7]*tablex7 ) * tabley5 + 01492 ( data[x1+y6+z7]*tablex1 + data[x2+y6+z7]*tablex2 + data[x3+y6+z7]*tablex3 + 01493 data[x4+y6+z7]*tablex4 + data[x5+y6+z7]*tablex5 + data[x6+y6+z7]*tablex6 + 01494 data[x7+y6+z7]*tablex7 ) * tabley6 + 01495 ( data[x1+y7+z7]*tablex1 + data[x2+y7+z7]*tablex2 + data[x3+y7+z7]*tablex3 + 01496 data[x4+y7+z7]*tablex4 + data[x5+y7+z7]*tablex5 + data[x6+y7+z7]*tablex6 + 01497 data[x7+y7+z7]*tablex7 ) * tabley7 ) *tablez7; 01498 01499 w = (tablex1+tablex2+tablex3+tablex4+tablex5+tablex6+tablex7) * 01500 (tabley1+tabley2+tabley3+tabley4+tabley5+tabley6+tabley7) * 01501 (tablez1+tablez2+tablez3+tablez4+tablez5+tablez6+tablez7); 01502 } 01503 return pixel/w; 01504 }
|
|
Get the seed for Randnum class.
Definition at line 684 of file util.cpp. References EMAN::Randnum::get_seed().
|
|
This function returns a 2-D slice from a 3-D EMData object dim denotes the slice is perpendicular to which dimension 1 for x-dimension, 2 for y-dimension and 3 for z-dimension.
Definition at line 19996 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, nx, ny, EMAN::EMData::set_size(), x, and y. 19996 { 19997 19998 int nx = vol->get_xsize(); 19999 int ny = vol->get_ysize(); 20000 int nz = vol->get_zsize(); 20001 float *vol_data = vol->get_data(); 20002 int new_nx, new_ny; 20003 20004 if (nz == 1) 20005 throw ImageDimensionException("Error: Input must be a 3-D object"); 20006 if ((dim < 1) || (dim > 3)) 20007 throw ImageDimensionException("Error: dim must be 1 (x-dimension), 2 (y-dimension) or 3 (z-dimension)"); 20008 if (((dim == 1) && (index < 0 || index > nx-1)) || 20009 ((dim == 1) && (index < 0 || index > nx-1)) || 20010 ((dim == 1) && (index < 0 || index > nx-1))) 20011 throw ImageDimensionException("Error: index exceeds the size of the 3-D object"); 20012 20013 if (dim == 1) { 20014 new_nx = ny; 20015 new_ny = nz; 20016 } else if (dim == 2) { 20017 new_nx = nx; 20018 new_ny = nz; 20019 } else { 20020 new_nx = nx; 20021 new_ny = ny; 20022 } 20023 20024 EMData *slice = new EMData(); 20025 slice->set_size(new_nx, new_ny, 1); 20026 float *slice_data = slice->get_data(); 20027 20028 if (dim == 1) { 20029 for (int x=0; x<new_nx; x++) 20030 for (int y=0; y<new_ny; y++) 20031 slice_data[y*new_nx+x] = vol_data[(y*ny+x)*nx+index]; 20032 } else if (dim == 2) { 20033 for (int x=0; x<new_nx; x++) 20034 for (int y=0; y<new_ny; y++) 20035 slice_data[y*new_nx+x] = vol_data[(y*ny+index)*nx+x]; 20036 } else { 20037 for (int x=0; x<new_nx; x++) 20038 for (int y=0; y<new_ny; y++) 20039 slice_data[y*new_nx+x] = vol_data[(index*ny+y)*nx+x]; 20040 } 20041 20042 return slice; 20043 }
|
|
Get the mean, standard deviation, skewness and kurtosis of the input data.
Definition at line 876 of file util.cpp. References data, EmptyContainerException, mean(), sqrt(), and square_sum(). 00877 { 00878 // Note that this is a heavy STL approach using generic algorithms - some memory could be saved 00879 // using plain c style code, as in get_stats_cstyle below 00880 00881 if (data.size() == 0) EmptyContainerException("Error, attempting to call get stats on an empty container (vector<double>)"); 00882 00883 double sum = accumulate(data.begin(), data.end(), 0.0); 00884 00885 double mean = sum / static_cast<double> (data.size()); 00886 00887 double std_dev = 0.0, skewness = 0.0, kurtosis = 0.0; 00888 00889 if (data.size() > 1) 00890 { 00891 // read mm is "minus_mean" 00892 vector<double> data_mm(data.size()); 00893 // read ts as "then squared" 00894 vector<double> data_mm_sq(data.size()); 00895 00896 // Subtract the mean from the data and store it in data_mm 00897 transform(data.begin(), data.end(), data_mm.begin(), std::bind2nd(std::minus<double>(), mean)); 00898 00899 // Get the square of the data minus the mean and store it in data_mm_sq 00900 transform(data_mm.begin(), data_mm.end(), data_mm.begin(), data_mm_sq.begin(), std::multiplies<double>()); 00901 00902 // Get the sum of the squares for the calculation of the standard deviation 00903 double square_sum = accumulate(data_mm_sq.begin(), data_mm_sq.end(), 0.0); 00904 00905 //Calculate teh standard deviation 00906 std_dev = sqrt(square_sum / static_cast<double>(data.size()-1)); 00907 double std_dev_sq = std_dev * std_dev; 00908 00909 // The numerator for the skewness fraction, as defined in http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm 00910 double cubic_sum = inner_product(data_mm.begin(), data_mm.end(),data_mm_sq.begin(), 0.0); 00911 00912 // The numerator for the kurtosis fraction, as defined in http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm 00913 double quartic_sum = inner_product(data_mm_sq.begin(), data_mm_sq.end(),data_mm_sq.begin(), 0.0); 00914 00915 // Finalize the calculation of the skewness and kurtosis, as defined in 00916 // http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm 00917 skewness = cubic_sum / ((data.size()-1) * std_dev_sq * std_dev ); 00918 kurtosis = quartic_sum / ((data.size()-1) * std_dev_sq * std_dev_sq ); 00919 00920 } 00921 00922 Dict parms; 00923 parms["mean"] = mean; 00924 parms["std_dev"] = std_dev; 00925 parms["skewness"] = skewness; 00926 parms["kurtosis"] = kurtosis; 00927 00928 return parms; 00929 }
|
|
Performs the same calculations as in get_stats, but uses a single pass, optimized c approach Should perform better than get_stats.
Definition at line 932 of file util.cpp. References data, EmptyContainerException, mean(), sqrt(), square, square(), and square_sum(). 00933 { 00934 if (data.size() == 0) EmptyContainerException("Error, attempting to call get stats on an empty container (vector<double>)"); 00935 00936 double square_sum = 0.0, sum = 0.0, cube_sum = 0.0, quart_sum = 0.0; 00937 for( vector<float>::const_iterator it = data.begin(); it != data.end(); ++it ) 00938 { 00939 double val = *it; 00940 double square = val*val; 00941 quart_sum += square*square; 00942 cube_sum += square*val; 00943 square_sum += square; 00944 sum += val; 00945 } 00946 00947 double mean = sum/(double)data.size(); 00948 00949 double std_dev = 0.0, skewness = 0.0, kurtosis = 0.0; 00950 00951 if (data.size() > 1) 00952 { 00953 // The standard deviation is calculated here 00954 std_dev = sqrt( (square_sum - mean*sum)/(double)(data.size()-1)); 00955 00956 double square_mean = mean*mean; 00957 double cube_mean = mean*square_mean; 00958 00959 double square_std_dev = std_dev*std_dev; 00960 00961 // This is the numerator of the skewness fraction, if you expand the brackets, as defined in 00962 // http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm 00963 double cubic_sum = cube_sum - 3*square_sum*mean + 3*sum*square_mean - cube_mean*data.size(); 00964 // Complete the skewness fraction 00965 skewness = cubic_sum/((data.size()-1)*square_std_dev*std_dev); 00966 00967 // This is the numerator of the kurtosis fraction, if you expand the brackets, as defined in 00968 // http://www.itl.nist.gov/div898/handbook/eda/section3/eda35b.htm 00969 double quartic_sum = quart_sum - 4*cube_sum*mean + 6*square_sum*square_mean - 4*sum*cube_mean + square_mean*square_mean*data.size(); 00970 // Complete the kurtosis fraction 00971 kurtosis = quartic_sum /( (data.size()-1)*square_std_dev*square_std_dev); 00972 } 00973 00974 Dict parms; 00975 parms["mean"] = mean; 00976 parms["std_dev"] = std_dev; 00977 parms["skewness"] = skewness; 00978 parms["kurtosis"] = kurtosis; 00979 00980 return parms; 00981 }
|
|
Extract number of values and the float values, if any, from a string whose format is either "variable=value1,value2 " or "variable". for example, if the string is "XYZ=1.1,1.2", then 'str' is "XYZ=1.1,1.2"; 'float_var' is "XYZ"; 'p_nvalues' points to 2. 'p_v1' points to 1.1; 'p_v2' points to 1.2. If the string is "XYZ", then 'str' is "XYZ"; 'float_var' is "XYZ". 'p_nvalues' points to 0. 'p_v1' and 'p_v2' unchanged.
Definition at line 359 of file util.cpp. References NullPointerException. 00361 { 00362 if (!s || !float_var || !p_v0 || !p_v1 || !p_v2) { 00363 throw NullPointerException("string float"); 00364 } 00365 00366 size_t n = strlen(float_var); 00367 *p_v0 = 0; 00368 if (strncmp(s, float_var, n) == 0) { 00369 if (s[n] == '=') { 00370 *p_v0 = 2; 00371 sscanf(&s[n + 1], "%f,%f", p_v1, p_v2); 00372 } 00373 else { 00374 *p_v0 = 1; 00375 } 00376 return true; 00377 } 00378 return false; 00379 }
|
|
Extract the float values from a variable=value1,value2 string with format like "XYZ=1.1,1.2", where 'str' is "XYZ=1.1,1.2"; 'float_var' is "XYZ="; 'p_v1' points to 1.1; 'p_v2' points to 1.2.
Definition at line 344 of file util.cpp. References NullPointerException. 00345 { 00346 if (!s || !float_var || !p_v1 || !p_v2) { 00347 throw NullPointerException("string float"); 00348 } 00349 00350 size_t n = strlen(float_var); 00351 if (strncmp(s, float_var, n) == 0) { 00352 sscanf(&s[n], "%f,%f", p_v1, p_v2); 00353 return true; 00354 } 00355 00356 return false; 00357 }
|
|
Extract the float value from a variable=value string with format like "XYZ=1.1", where 'str' is "XYZ=1.1"; 'float_var' is "XYZ="; 'p_val' points to float number 1.1.
Definition at line 330 of file util.cpp. References NullPointerException. Referenced by main(). 00331 { 00332 if (!s || !float_var || !p_val) { 00333 throw NullPointerException("string float"); 00334 } 00335 size_t n = strlen(float_var); 00336 if (strncmp(s, float_var, n) == 0) { 00337 *p_val = (float) atof(&s[n]); 00338 return true; 00339 } 00340 00341 return false; 00342 }
|
|
Extract number of values and the int values, if any, from a string whose format is either "variable=value1,value2 " or "variable". for example, if the string is "XYZ=1,2", then 'str' is "XYZ=1,2"; 'int_var' is "XYZ"; 'p_nvalues' points to 2. 'p_v1' points to 1; 'p_v2' points to 2. If the string is "XYZ", then 'str' is "XYZ"; 'int_var' is "XYZ". 'p_nvalues' points to 0. 'p_v1' and 'p_v2' unchanged.
Definition at line 409 of file util.cpp. References NullPointerException. 00410 { 00411 if (!s || !int_var || !p_v0 || !p_v1 || !p_v2) { 00412 throw NullPointerException("string int"); 00413 } 00414 00415 size_t n = strlen(int_var); 00416 *p_v0 = 0; 00417 if (strncmp(s, int_var, n) == 0) { 00418 if (s[n] == '=') { 00419 *p_v0 = 2; 00420 sscanf(&s[n + 1], "%d,%d", p_v1, p_v2); 00421 } 00422 else { 00423 *p_v0 = 1; 00424 } 00425 return true; 00426 } 00427 return false; 00428 }
|
|
Extract the int value from a variable=value1,value2 string with format like "XYZ=1,2", where 'str' is "XYZ=1,2"; 'int_var' is "XYZ="; 'p_val' points to float number 1.
Definition at line 395 of file util.cpp. References NullPointerException. 00396 { 00397 if (!s || !int_var || !p_v1 || !p_v2) { 00398 throw NullPointerException("string int"); 00399 } 00400 00401 size_t n = strlen(int_var); 00402 if (strncmp(s, int_var, n) == 0) { 00403 sscanf(&s[n], "%d,%d", p_v1, p_v2); 00404 return true; 00405 } 00406 return false; 00407 }
|
|
Extract the int value from a variable=value string with format like "XYZ=1", where 'str' is "XYZ=1"; 'int_var' is "XYZ="; 'p_val' points to float number 1.
Definition at line 381 of file util.cpp. References NullPointerException. Referenced by main(). 00382 { 00383 if (!s || !int_var || !p_val) { 00384 throw NullPointerException("string int"); 00385 } 00386 00387 size_t n = strlen(int_var); 00388 if (strncmp(s, int_var, n) == 0) { 00389 *p_val = atoi(&s[n]); 00390 return true; 00391 } 00392 return false; 00393 }
|
|
Get the current time in a string with format "mm/dd/yyyy hh:mm".
Definition at line 1097 of file util.cpp. References t. 01098 { 01099 time_t t0 = time(0); 01100 struct tm *t = localtime(&t0); 01101 char label[32]; 01102 sprintf(label, "%d/%02d/%04d %d:%02d", 01103 t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour, t->tm_min); 01104 return string(label); 01105 }
|
|
Definition at line 1162 of file util.cpp. References abs, printmatrix(), printvector(), q, rhs, V, and W. Referenced by EMAN::FourierInserter3DMode8::init(). 01163 { 01164 int i = 0; 01165 int discs = (int)(1+2*freq_cutoff/dfreq); 01166 01167 float* W = new float[discs]; 01168 01169 int fc = (int)(2*freq_cutoff + 1); 01170 gsl_matrix* M = gsl_matrix_calloc(fc,fc); 01171 01172 gsl_vector* rhs = gsl_vector_calloc(fc); 01173 cout << i++ << endl; 01174 for(int k = -freq_cutoff; k <= freq_cutoff; ++k){ 01175 for(int kp = -freq_cutoff; kp <= freq_cutoff; ++kp){ 01176 int kdiff =abs( k-kp); 01177 int evenoddfac = ( kdiff % 2 == 0 ? 1 : -1); 01178 01179 if (kdiff !=0){ 01180 float val = sin(M_PI*(float)kdiff*r)/(sin(M_PI*(float)kdiff/(float)P))*(alpha+2.0f*beta*evenoddfac); 01181 gsl_matrix_set(M,int(k+freq_cutoff),int(kp+freq_cutoff),val); 01182 } 01183 } 01184 gsl_matrix_set(M,int(k+freq_cutoff),int(k+freq_cutoff),r*P* (alpha+2*beta)); 01185 float val = alpha*sin(M_PI*k*r)/(sin(M_PI*(float)k/(float)P)); 01186 if (k!=0) { 01187 gsl_vector_set(rhs,int(k+freq_cutoff),val); 01188 } 01189 } 01190 printmatrix(M,fc,fc,"M"); 01191 01192 gsl_vector_set(rhs,int(freq_cutoff),alpha*r*P); 01193 gsl_matrix* V = gsl_matrix_calloc(fc,fc); 01194 gsl_vector* S = gsl_vector_calloc(fc); 01195 gsl_vector* soln = gsl_vector_calloc(fc); 01196 gsl_linalg_SV_decomp(M,V,S,soln); 01197 01198 gsl_linalg_SV_solve(M, V, S, rhs, soln); // soln now runs from -freq_cutoff to + freq_cutoff 01199 printvector(soln,fc,"soln"); 01200 01201 // we want to solve for W, which ranges from -freq_cutoff to +freq_cutoff in steps of dfreq 2 01202 int Count=0; 01203 for(float q = (float)(-freq_cutoff); q <= (float)(freq_cutoff); q+= dfreq){ 01204 float temp=0; 01205 for(int k = -freq_cutoff; k <= freq_cutoff; ++k){ 01206 float dtemp; 01207 if (q!=k) { 01208 dtemp=(1/(float) P)* (float)gsl_vector_get(soln,int(k+freq_cutoff)) * sin(M_PI*(q-k))/sin(M_PI*(q-k)/((float) P)); 01209 } else{ 01210 dtemp = (1/(float) P)* (float)gsl_vector_get(soln,int(k+freq_cutoff)) * P; 01211 } 01212 temp +=dtemp; 01213 } 01214 W[Count]=temp; 01215 cout << W[Count] << " "; 01216 Count+=1; 01217 } 01218 cout << endl; 01219 return W; 01220 }
|
|
|
|
Check whether a number is a good float. A number is a good float if it is not abnormal zero, and not inf, -inf or NaN
Definition at line 1891 of file util.h. Referenced by EMAN::FRCCmp::cmp(), EMAN::SqEuclideanCmp::cmp(), EMAN::EMObject::EMObject(), EMAN::ByteOrder::is_float_big_endian(), main(), EMAN::NormalizeProcessor::process_inplace(), and EMAN::FiniteProcessor::process_pixel(). |
|
Definition at line 5570 of file util_sparx.cpp. References EMAN::EMData::get_data(), and img_ptr. 05571 { 05572 float *img_ptr = img->get_data(); 05573 float *mask_ptr = (mask == NULL)?img->get_data():mask->get_data(); 05574 05575 int *img_freq_bin = new int[3*hist_len]; 05576 for(int i = 0;i < (3*hist_len);i++) img_freq_bin[i] = 0; 05577 for(int i = 0;i < size_img;i++) { 05578 if(mask_ptr[i] > 0.5f) { 05579 float img_xn = img_ptr[i]*PA + PB; 05580 int L = static_cast<int>(((img_xn - ref_h_min)/ref_h_diff) * (hist_len-1) + hist_len+1); 05581 if(L >= 0 && L < (3*hist_len)) img_freq_bin[L]++; 05582 } 05583 } 05584 int freq_hist = 0; 05585 05586 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); 05587 freq_hist = (-freq_hist); 05588 return static_cast<float>(freq_hist); 05589 }
|
|
Definition at line 5478 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. 05479 { 05480 /* Exception Handle */ 05481 if (img->is_complex() || ref->is_complex()) 05482 throw ImageFormatException("Cannot do Histogram on Fourier Image"); 05483 05484 if(mask != NULL){ 05485 if(img->get_xsize() != mask->get_xsize() || img->get_ysize() != mask->get_ysize() || img->get_zsize() != mask->get_zsize()) 05486 throw ImageDimensionException("The size of mask image should be of same size as the input image"); } 05487 /* ===================================================== */ 05488 05489 /* Image size calculation */ 05490 int size_ref = ((ref->get_xsize())*(ref->get_ysize())*(ref->get_zsize())); 05491 int size_img = ((img->get_xsize())*(img->get_ysize())*(img->get_zsize())); 05492 /* ===================================================== */ 05493 05494 /* The reference image attributes */ 05495 float *ref_ptr = ref->get_data(); 05496 float ref_h_min = ref->get_attr("minimum"); 05497 float ref_h_max = ref->get_attr("maximum"); 05498 float ref_h_avg = ref->get_attr("mean"); 05499 float ref_h_sig = ref->get_attr("sigma"); 05500 /* ===================================================== */ 05501 05502 /* Input image under mask attributes */ 05503 float *mask_ptr = (mask == NULL)?img->get_data():mask->get_data(); 05504 05505 vector<float> img_data = Util::infomask(img, mask); 05506 float img_avg = img_data[0]; 05507 float img_sig = img_data[1]; 05508 05509 /* The image under mask -- size calculation */ 05510 int cnt=0; 05511 for(int i=0;i<size_img;i++) 05512 if (mask_ptr[i]>0.5f) 05513 cnt++; 05514 /* ===================================================== */ 05515 05516 /* Histogram of reference image calculation */ 05517 float ref_h_diff = ref_h_max - ref_h_min; 05518 05519 #ifdef _WIN32 05520 int hist_len = _cpp_min((int)size_ref/16,_cpp_min((int)size_img/16,256)); 05521 #else 05522 int hist_len = std::min((int)size_ref/16,std::min((int)size_img/16,256)); 05523 #endif //_WIN32 05524 05525 float *ref_freq_bin = new float[3*hist_len]; 05526 05527 //initialize value in each bin to zero 05528 for (int i = 0;i < (3*hist_len);i++) ref_freq_bin[i] = 0.f; 05529 05530 for (int i = 0;i < size_ref;i++) { 05531 int L = static_cast<int>(((ref_ptr[i] - ref_h_min)/ref_h_diff) * (hist_len-1) + hist_len+1); 05532 ref_freq_bin[L]++; 05533 } 05534 for (int i = 0;i < (3*hist_len);i++) ref_freq_bin[i] *= static_cast<float>(cnt)/static_cast<float>(size_ref); 05535 05536 //Parameters Calculation (i.e) 'A' x + 'B' 05537 float A = ref_h_sig/img_sig; 05538 float B = ref_h_avg - (A*img_avg); 05539 05540 vector<float> args; 05541 args.push_back(A); 05542 args.push_back(B); 05543 05544 vector<float> scale; 05545 scale.push_back(1.e-7f*A); 05546 scale.push_back(-1.e-7f*B); 05547 05548 vector<float> ref_freq_hist; 05549 for(int i = 0;i < (3*hist_len);i++) ref_freq_hist.push_back((int)ref_freq_bin[i]); 05550 05551 vector<float> data; 05552 data.push_back(ref_h_diff); 05553 data.push_back(ref_h_min); 05554 05555 Dict parameter; 05556 05557 /* Parameters displaying the arguments A & B, and the scaling function and the data's */ 05558 parameter["args"] = args; 05559 parameter["scale"]= scale; 05560 parameter["data"] = data; 05561 parameter["ref_freq_bin"] = ref_freq_hist; 05562 parameter["size_img"]=size_img; 05563 parameter["hist_len"]=hist_len; 05564 /* ===================================================== */ 05565 05566 return parameter; 05567 }
|
|
Definition at line 5420 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. 05421 { 05422 if (image->is_complex()) 05423 throw ImageFormatException("Cannot do histogram on Fourier image"); 05424 //float hmax, hmin; 05425 float *imageptr=0, *maskptr=0; 05426 int nx=image->get_xsize(); 05427 int ny=image->get_ysize(); 05428 int nz=image->get_zsize(); 05429 05430 if(mask != NULL){ 05431 if(nx != mask->get_xsize() || ny != mask->get_ysize() || nz != mask->get_zsize()) 05432 throw ImageDimensionException("The size of mask image should be of same size as the input image"); 05433 maskptr =mask->get_data(); 05434 } 05435 if( nbins == 0) nbins = nx; 05436 vector <float> freq(2*nbins, 0.0); 05437 05438 imageptr=image->get_data(); 05439 if( hmin == hmax ) { 05440 if(mask == NULL) { 05441 hmax = image->get_attr("maximum"); 05442 hmin = image->get_attr("minimum"); 05443 } else { 05444 bool First = true; 05445 for (int i = 0;i < nx*ny*nz; i++) { 05446 if (maskptr[i]>=0.5f) { 05447 if(First) { 05448 hmax = imageptr[i]; 05449 hmin = imageptr[i]; 05450 First = false; 05451 } else { 05452 hmax = (hmax < imageptr[i])?imageptr[i]:hmax; 05453 hmin = (hmin > imageptr[i])?imageptr[i]:hmin; 05454 } 05455 } 05456 } 05457 } 05458 } 05459 float hdiff = hmax - hmin; 05460 float ff = (nbins-1)/hdiff; 05461 for (int i = 0; i < nbins; i++) freq[nbins+i] = hmin + (float(i)+0.5f)/ff; 05462 if(mask == NULL) { 05463 for(int i = 0; i < nx*ny*nz; i++) { 05464 int jbin = static_cast<int>((imageptr[i]-hmin)*ff + 1.5); 05465 if(jbin >= 1 && jbin <= nbins) freq[jbin-1] += 1.0; 05466 } 05467 } else { 05468 for(int i = 0; i < nx*ny*nz; i++) { 05469 if(maskptr[i] >= 0.5) { 05470 int jbin = static_cast<int>((imageptr[i]-hmin)*ff + 1.5); 05471 if(jbin >= 1 && jbin <= nbins) freq[jbin-1] += 1.0; 05472 } 05473 } 05474 } 05475 return freq; 05476 }
|
|
Definition at line 7130 of file util_sparx.cpp. References key, phi, and theta. 07131 { 07132 ENTERFUNC; 07133 vector<tmpstruct> tmp(len); 07134 int i; 07135 for(i = 1;i<=len;i++) 07136 { 07137 tmp[i-1].theta1 = theta(i); 07138 tmp[i-1].phi1 = phi(i); 07139 tmp[i-1].key1 = key(i); 07140 } 07141 07142 if (option == 1) sort(tmp.begin(),tmp.end(),Util::cmp1); 07143 if (option == 2) sort(tmp.begin(),tmp.end(),Util::cmp2); 07144 07145 for(i = 1;i<=len;i++) 07146 { 07147 theta(i) = tmp[i-1].theta1; 07148 phi(i) = tmp[i-1].phi1; 07149 key(i) = tmp[i-1].key1; 07150 } 07151 EXITFUNC; 07152 }
|
|
Euclidean distance function in 2D: f(x,y) = sqrt(x*x + y*y);.
|
|
Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);.
|
|
Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);.
|
|
Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);.
Definition at line 1632 of file util.h. Referenced by EMAN::PhaseCmp::cmp(), EMAN::Interp::init_gimx(), EMAN::FourierInserter3DMode5::insert_pixel(), EMAN::FourierInserter3DMode3::insert_pixel(), EMAN::KmeansSegmentProcessor::process(), EMAN::DistanceSegmentProcessor::process(), EMAN::TestImageSphericalWave::process_inplace(), EMAN::AddRandomNoiseProcessor::process_inplace(), and EMAN::RotationalAverageProcessor::process_inplace(). |
|
Euclidean distance function squared in 3D: f(x,y,z) = (x*x + y*y + z*z);.
|
|
Euclidean distance function squared in 3D: f(x,y,z) = (x*x + y*y + z*z);.
Definition at line 1610 of file util.h. Referenced by EMAN::FourierInserter3DMode6::insert_pixel(), EMAN::FourierInserter3DMode5::insert_pixel(), EMAN::FourierInserter3DMode3::insert_pixel(), EMAN::FourierInserter3DMode2::insert_pixel(), EMAN::GaussFFTProjector::interp_ft_3d(), EMAN::WienerFourierReconstructor::pixel_at(), and EMAN::FourierReconstructor::pixel_at(). |
|
Euclidean distance in 2D for integers computed fast using a cached lookup table.
Definition at line 713 of file util.cpp. Referenced by EMAN::EMAN2Ctf::compute_2d_complex(). 00714 { 00715 static float *mem = (float *)malloc(4*128*128); 00716 static int dim = 0; 00717 x=abs(x); 00718 y=abs(y); 00719 00720 if (x>=dim || y>=dim) { 00721 if (x>2048 || y>2048) return (float)hypot((float)x,(float)y); // We won't cache anything bigger than 4096^2 00722 dim=x>=dim?x+1:dim; 00723 dim=y>=dim?y+1:dim; 00724 mem=(float*)realloc(mem,4*dim*dim); 00725 for (int y=0; y<dim; y++) { 00726 for (int x=0; x<dim; x++) { 00727 #ifdef _WIN32 00728 mem[x+y*dim]=(float)_hypot((float)x,(float)y); 00729 #else 00730 mem[x+y*dim]=hypot((float)x,(float)y); 00731 #endif 00732 } 00733 } 00734 } 00735 00736 return mem[x+y*dim]; 00737 }
|
|
Euclidean distance in 2D for integers computed fast using a cached lookup table.
Definition at line 739 of file util.cpp. Referenced by EMAN::PhaseCmp::cmp(). 00740 { 00741 static short *mem = (short *)malloc(2*128*128); 00742 static int dim = 0; 00743 x=abs(x); 00744 y=abs(y); 00745 00746 if (x>=dim || y>=dim) { 00747 if (x>4095 || y>4095) return (short)hypot((float)x,(float)y); // We won't cache anything bigger than 4096^2 00748 dim=x>=dim?x+1:dim; 00749 dim=y>=dim?y+1:dim; 00750 mem=(short*)realloc(mem,2*dim*dim); 00751 for (int y=0; y<dim; y++) { 00752 for (int x=0; x<dim; x++) { 00753 #ifdef _WIN32 00754 mem[x+y*dim]=(short)Util::round(_hypot((float)x,(float)y)); 00755 #else 00756 mem[x+y*dim]=(short)Util::round(hypot((float)x,(float)y)); 00757 #endif 00758 } 00759 } 00760 } 00761 00762 return mem[x+y*dim]; 00763 }
|
|
Definition at line 143 of file util_sparx.cpp. References B, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageFormatException, LOGERR, nx, ny, EMAN::EMData::set_size(), EMAN::EMData::to_one(), and EMAN::EMData::update(). 00144 { 00145 ENTERFUNC; 00146 00147 if (!EMUtil::is_same_size(V1, V2)) { 00148 LOGERR("images not same size"); 00149 throw ImageFormatException( "images not same size"); 00150 } 00151 00152 size_t nx = V1->get_xsize(); 00153 size_t ny = V1->get_ysize(); 00154 size_t nz = V1->get_zsize(); 00155 size_t size = nx*ny*nz; 00156 00157 EMData *BD = new EMData(); 00158 BD->set_size(nx, ny, nz); 00159 00160 float *params = new float[2]; 00161 00162 float *V1ptr, *V2ptr, *MASKptr, *BDptr, A, B; 00163 long double S1=0.L,S2=0.L,S3=0.L,S4=0.L; 00164 int nvox = 0L; 00165 00166 V1ptr = V1->get_data(); 00167 V2ptr = V2->get_data(); 00168 BDptr = BD->get_data(); 00169 00170 00171 if(!mask){ 00172 EMData * Mask = new EMData(); 00173 Mask->set_size(nx,ny,nz); 00174 Mask->to_one(); 00175 MASKptr = Mask->get_data(); 00176 } else { 00177 if (!EMUtil::is_same_size(V1, mask)) { 00178 LOGERR("mask not same size"); 00179 throw ImageFormatException( "mask not same size"); 00180 } 00181 00182 MASKptr = mask->get_data(); 00183 } 00184 00185 00186 00187 // calculation of S1,S2,S3,S3,nvox 00188 00189 for (size_t i = 0L;i < size; i++) { 00190 if (MASKptr[i]>0.5f) { 00191 S1 += V1ptr[i]*V2ptr[i]; 00192 S2 += V1ptr[i]*V1ptr[i]; 00193 S3 += V2ptr[i]; 00194 S4 += V1ptr[i]; 00195 nvox ++; 00196 } 00197 } 00198 00199 if ((nvox*S1 - S3*S4) == 0. || (nvox*S2 - S4*S4) == 0) { 00200 A =1.0f ; 00201 } else { 00202 A = static_cast<float>( (nvox*S1 - S3*S4)/(nvox*S2 - S4*S4) ); 00203 } 00204 B = static_cast<float> (A*S4 - S3)/nvox; 00205 00206 // calculation of the difference image 00207 00208 for (size_t i = 0L;i < size; i++) { 00209 if (MASKptr[i]>0.5f) { 00210 BDptr[i] = A*V1ptr[i] - B - V2ptr[i]; 00211 } else { 00212 BDptr[i] = 0.f; 00213 } 00214 } 00215 00216 BD->update(); 00217 00218 params[0] = A; 00219 params[1] = B; 00220 00221 Dict BDnParams; 00222 BDnParams["imdiff"] = BD; 00223 BDnParams["A"] = params[0]; 00224 BDnParams["B"] = params[1]; 00225 00226 EXITFUNC; 00227 return BDnParams; 00228 }
|
|
Definition at line 20045 of file util_sparx.cpp. References array_mutation(), EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), max, min, and nx. 20045 { 20046 int nx = img->get_xsize(); 20047 float min = img->get_attr("minimum"); 20048 float max = img->get_attr("maximum"); 20049 float* img_data = img->get_data(); 20050 array_mutation(img_data, nx*nx, mutation_rate, min, max, 8, 0); 20051 return; 20052 }
|
|
Definition at line 62 of file util_sparx.cpp. References EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, ImageFormatException, LOGERR, nx, ny, and sqrt(). 00063 : find statistics under the mask (mask >0.5) 00064 // flip false: find statistics ourside the mask (mask <0.5) 00065 { 00066 ENTERFUNC; 00067 vector<float> stats; 00068 float *Volptr, *maskptr,MAX,MIN; 00069 long double Sum1,Sum2; 00070 long count; 00071 00072 MAX = -FLT_MAX; 00073 MIN = FLT_MAX; 00074 count = 0L; 00075 Sum1 = 0.0L; 00076 Sum2 = 0.0L; 00077 00078 if (mask == NULL) { 00079 //Vol->update_stat(); 00080 stats.push_back(Vol->get_attr("mean")); 00081 stats.push_back(Vol->get_attr("sigma")); 00082 stats.push_back(Vol->get_attr("minimum")); 00083 stats.push_back(Vol->get_attr("maximum")); 00084 return stats; 00085 } 00086 00087 /* Check if the sizes of the mask and image are same */ 00088 00089 size_t nx = Vol->get_xsize(); 00090 size_t ny = Vol->get_ysize(); 00091 size_t nz = Vol->get_zsize(); 00092 00093 size_t mask_nx = mask->get_xsize(); 00094 size_t mask_ny = mask->get_ysize(); 00095 size_t mask_nz = mask->get_zsize(); 00096 00097 if (nx != mask_nx || ny != mask_ny || nz != mask_nz ) 00098 throw ImageDimensionException("The dimension of the image does not match the dimension of the mask!"); 00099 00100 /* if (nx != mask_nx || 00101 ny != mask_ny || 00102 nz != mask_nz ) { 00103 // should throw an exception here!!! (will clean it up later CY) 00104 fprintf(stderr, "The dimension of the image does not match the dimension of the mask!\n"); 00105 fprintf(stderr, " nx = %d, mask_nx = %d\n", nx, mask_nx); 00106 fprintf(stderr, " ny = %d, mask_ny = %d\n", ny, mask_ny); 00107 fprintf(stderr, " nz = %d, mask_nz = %d\n", nz, mask_nz); 00108 exit(1); 00109 } 00110 */ 00111 Volptr = Vol->get_data(); 00112 maskptr = mask->get_data(); 00113 00114 for (size_t i = 0; i < nx*ny*nz; i++) { 00115 if ((maskptr[i]>0.5f) == flip) { 00116 Sum1 += Volptr[i]; 00117 Sum2 += Volptr[i]*double(Volptr[i]); 00118 MAX = (MAX < Volptr[i])?Volptr[i]:MAX; 00119 MIN = (MIN > Volptr[i])?Volptr[i]:MIN; 00120 count++; 00121 } 00122 } 00123 00124 if (count == 0) { 00125 LOGERR("Invalid mask"); 00126 throw ImageFormatException( "Invalid mask"); 00127 } 00128 00129 float avg = static_cast<float>(Sum1/count); 00130 float sig = static_cast<float>(sqrt((Sum2 - Sum1*Sum1/count)/(count-1))); 00131 00132 stats.push_back(avg); 00133 stats.push_back(sig); 00134 stats.push_back(MIN); 00135 stats.push_back(MAX); 00136 00137 return stats; 00138 }
|
|
initial_prune removes all classes C from Parts where there does not exist ANY feasible matching containing class C which has weight gt T. The first element of each class is its original index, and second is dummy variable Definition at line 20340 of file util_sparx.cpp. References b, explore(), and k_means_cont_table_(). 20340 { 20341 //cout<<"initial_prune\n"; 20342 // simple initial pruning. For class indClass of partition indPart: 20343 // 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 20344 // If for some partition (not equal to indPart) for which there is no such class, then return 0 immediately. 20345 20346 // 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 20347 20348 // remember when calling k_means_cont_table, the first element of each class is an index, and actual number of elements in the class 20349 // (as stored in dimClasses) should be decremented by 1 accordingly, and second is dummy variable 20350 20351 int* dummy(0); 20352 int* cref; 20353 int cref_size; 20354 int* ccomp; 20355 int ccomp_size; 20356 int nintx; 20357 for (int i=0; i < nParts; i++){ 20358 for (int j =0; j < K; j++){ 20359 20360 // consider class Parts[i][j] 20361 cref = Parts[i][j];//incr by 1 since first element is index and second is dummy 20362 cref_size = (*(dimClasses+i*K+(*cref)))-2; 20363 20364 20365 if (cref_size <= T){ 20366 20367 *cref = -1; 20368 continue; 20369 } 20370 bool done = 0; 20371 for (int a = 0; a < nParts; a++){ 20372 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 20373 bool hasActive=0; 20374 for (unsigned int b=0; b < Parts[a].size(); b++){ 20375 // get the card of the intx between Parts[i][j] and Parts[a][b] using k_means_cont_table 20376 // remember first element of each class is the index of the class 20377 ccomp = Parts[a][b]; 20378 ccomp_size= (*(dimClasses+a*K+(*ccomp)))-2; 20379 nintx = Util::k_means_cont_table_(cref+2,ccomp+2, dummy, cref_size, ccomp_size,0); 20380 20381 20382 if (nintx <= T) 20383 *(ccomp+1) = 0; // class Parts[a][b] is 'inactive' for cref 20384 else{ 20385 *(ccomp+1)=1; // class Parts[a][b] is 'active' for cref 20386 hasActive=1; 20387 } 20388 } 20389 // see if partition a has at least one active class.if not then we're done with cref 20390 if (hasActive < 1){ 20391 done=1; 20392 break; 20393 } 20394 20395 } 20396 20397 if (done > 0){ 20398 // remove class j from partition i 20399 20400 *cref = -1; // mark for deletion later 20401 continue; // move on to class Parts[i][j+1] 20402 } 20403 20404 // now we adopt more aggressive measures. we find the match with the largest weight which has class Parts[i][j] for partition i. 20405 // 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. 20406 20407 // (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. 20408 // Note that if there are ALOT of partitions, then sorting the partititions may actually take longer than the time saved by ordering hte 20409 // partitions. However, we do not have a lot of partitions, (usually around 10), so sorting time will be trivial compared to exploring time. 20410 20411 // explore returns one if there is a feasible matching containing class cref which has weight gt T, and otherwise returns 0 20412 //bool found = 1; 20413 bool found = explore(Parts, dimClasses, nParts, K, T, i, cref+2, cref_size, cref, cref_size,0); 20414 20415 if (found<1){ // There is NO feasible matching with class j (cref) with weight greater than T, so delete this class from Parts 20416 // Parts[i].erase(Parts[i].begin()+j); 20417 *cref = -1; 20418 } 20419 } 20420 20421 // Erase from Parts[i] all the classes that's being designated for erasure 20422 20423 for (int d = K-1; d > -1; d--){ 20424 if (*(Parts[i][d]) < 0) Parts[i].erase(Parts[i].begin()+d); 20425 } 20426 20427 } 20428 //cout <<"number of classes left in each partition after initial prune\n"; 20429 // Print out how many classes are left in each partition 20430 //for (int i =0; i < nParts; i++) 20431 // cout << Parts[i].size()<<", "; 20432 //cout << "\n"; 20433 }
|
|
Get a string format of an integer, e.g. 123 will be "123".
Definition at line 260 of file util.cpp. Referenced by EMAN::Log::loc(), and EMAN::E2Exception::what(). 00261 { 00262 char s[32] = {'\0'}; 00263 sprintf(s, "%d", n); 00264 return string(s); 00265 }
|
|
check whether a file exists or not
Definition at line 208 of file util.cpp. Referenced by EMAN::TestUtil::check_image(), EMAN::GlobalCache::get_imageio(), and EMAN::SpiderIO::SpiderIO(). 00209 { 00210 if (access(filename.c_str(), F_OK) == 0) { 00211 return true; 00212 } 00213 return false; 00214 }
|
|
Return true if an integer is positive and is power of 2.
Definition at line 2096 of file util.h. Referenced by EMAN::WaveletProcessor::process_inplace(). |
|
helper to create the contengency table for partition matching (k-means) flag define is the list of stable obj must be store to stb, but the size st must be know before. The trick is first start wihtout the flag to get number of elements stable, then again with the flag to get the list. This avoid to have two differents functions for the same thing. Definition at line 5107 of file util_sparx.cpp. References max. 05107 { 05108 long int d2 = group2[s2 - 1] - group2[0]; 05109 long int p2 = 0; 05110 long int i1 = 0; 05111 long int i2 = 0; 05112 long int max = 0; 05113 long int cont = 0; 05114 long int i = 0; 05115 int stop1 = 0; 05116 int stop2 = 0; 05117 05118 for (i=0; i<s1; i++) { 05119 p2 = (long int)(s2 * (double)group1[i] / (double)d2); 05120 if (p2 >= s2) {p2 = s2 - 1;} 05121 i1 = p2; 05122 i2 = p2; 05123 max = s2; 05124 if (group1[i] < group2[0] || group1[i] > group2[s2 - 1]) {continue;} 05125 05126 stop1 = 0; 05127 stop2 = 0; 05128 while (max--) { 05129 if (group1[i] == group2[i1]) { 05130 if (flag) {stb[cont] = group1[i];} 05131 cont++; 05132 break; 05133 } 05134 if (group2[i1] < group1[i]) {stop1=1;} 05135 if (group1[i] == group2[i2]) { 05136 if (flag) {stb[cont] = group1[i];} 05137 cont++; 05138 break; 05139 } 05140 if (group2[i2] > group1[i]) {stop2=1;} 05141 //printf("i1 %li i2 %li v2 %i v2 %i stop1 %i stop2 %i\n", i1, i2, group2[i1], group2[i2], stop1, stop2); 05142 05143 if (stop1 & stop2) {break;} 05144 i1--; 05145 i2++; 05146 if (i1 < 0) {i1 = 0;} 05147 if (i2 >= s2) {i2 = s2 - 1;} 05148 } 05149 //printf("v1: %i ite: %li cont: %li\n", group1[i], s2-max, cont); 05150 } 05151 05152 return cont; 05153 }
|
|
Calculate linear interpolation.
Definition at line 1465 of file util.h. Referenced by EMAN::WienerFourierReconstructor::do_insert_slice_work(), and EMAN::StandardProjector::project3d(). |
|
Definition at line 20108 of file util_sparx.cpp. 20108 { 20109 20110 if (is_mirror != 0) { 20111 for (vector<float>::iterator q=list.begin(); q!=list.end(); q++) { 20112 int r = rand()%10000; 20113 float f = r/10000.0f; 20114 if (f < mutation_rate) *q = 1-*q; 20115 } 20116 } else { 20117 map<int, vector<int> > graycode; 20118 map<vector<int>, int> rev_graycode; 20119 vector <int> gray; 20120 20121 int K=1; 20122 for (int i=0; i<L; i++) K*=2; 20123 20124 for (int k=0; k<K; k++) { 20125 int shift = 0; 20126 vector <int> gray; 20127 for (int i=L-1; i>-1; i--) { 20128 int t = ((k>>i)%2-shift)%2; 20129 gray.push_back(t); 20130 shift += t-2; 20131 } 20132 graycode[k] = gray; 20133 rev_graycode[gray] = k; 20134 } 20135 20136 float gap = (K-1)/(max_val-min_val); 20137 for (vector<float>::iterator q=list.begin(); q!=list.end(); q++) { 20138 float val = *q; 20139 if (val < min_val) { val = min_val; } 20140 else if (val > max_val) { val = max_val; } 20141 int k = int((val-min_val)*gap+0.5); 20142 vector<int> gray = graycode[k]; 20143 bool changed = false; 20144 for (vector<int>::iterator p=gray.begin(); p!=gray.end(); p++) { 20145 int r = rand()%10000; 20146 float f = r/10000.0f; 20147 if (f < mutation_rate) { 20148 *p = 1-*p; 20149 changed = true; 20150 } 20151 } 20152 if (changed) { 20153 k = rev_graycode[gray]; 20154 *q = k/gap+min_val; 20155 } 20156 } 20157 } 20158 return list; 20159 }
|
|
Definition at line 6337 of file util_sparx.cpp. 06338 { 06339 /* System generated locals */ 06340 long int q_dim1, q_offset, q1_dim1, q1_offset, i__1, i__2; 06341 06342 /* Local variables */ 06343 long int i__, j, m, n1, ii, jj; 06344 double tmp; 06345 vector<float> p; 06346 --x; 06347 q_dim1 = *klm2d; 06348 q_offset = 1 + q_dim1; 06349 q -= q_offset; 06350 q1_dim1 = *klm2d; 06351 q1_offset = 1 + q1_dim1; 06352 q1 -= q1_offset; 06353 --s; 06354 --res; 06355 iu -= 3; 06356 cu -= 3; 06357 06358 /* Function Body */ 06359 long int l = 0; 06360 06361 /* C==ZHONG HUANG,JULY,12,02;L=0,1,2,3,4,5,6 correspond to different equality constraints */ 06362 m = *ks; 06363 n1 = *n + 1; 06364 if (*iswi == 1) { 06365 i__1 = n1; 06366 for (jj = 1; jj <= i__1; ++jj) { 06367 i__2 = *ks; 06368 for (ii = 1; ii <= i__2; ++ii) { 06369 /* q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];*/ 06370 06371 q[*ks + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1] 06372 ; 06373 } 06374 } 06375 } else if (*iswi == 2) { 06376 i__1 = *ks; 06377 for (ii = 1; ii <= i__1; ++ii) { 06378 i__2 = n1; 06379 for (jj = 1; jj <= i__2; ++jj) { 06380 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06381 q[*ks + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06382 } 06383 } 06384 } else if (*iswi == 3) { 06385 l = 2; 06386 i__1 = n1; 06387 for (jj = 1; jj <= i__1; ++jj) { 06388 i__2 = *ks + 2; 06389 for (ii = 1; ii <= i__2; ++ii) { 06390 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06391 } 06392 i__2 = *ks; 06393 for (ii = 1; ii <= i__2; ++ii) { 06394 q[*ks + 2 + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06395 } 06396 } 06397 } else if (*iswi == 4) { 06398 l = 2; 06399 i__1 = n1; 06400 for (jj = 1; jj <= i__1; ++jj) { 06401 i__2 = *ks + 2; 06402 for (ii = 1; ii <= i__2; ++ii) { 06403 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06404 } 06405 i__2 = *ks; 06406 for (ii = 1; ii <= i__2; ++ii) { 06407 q[*ks + 2 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06408 } 06409 } 06410 } else if (*iswi == 5) { 06411 l = 1; 06412 i__1 = n1; 06413 for (jj = 1; jj <= i__1; ++jj) { 06414 i__2 = *ks + 1; 06415 for (ii = 1; ii <= i__2; ++ii) { 06416 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06417 } 06418 i__2 = *ks; 06419 for (ii = 1; ii <= i__2; ++ii) { 06420 q[*ks + 1 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06421 } 06422 } 06423 } else if (*iswi == 6) { 06424 l = 1; 06425 i__1 = n1; 06426 for (jj = 1; jj <= i__1; ++jj) { 06427 i__2 = *ks + 1; 06428 for (ii = 1; ii <= i__2; ++ii) { 06429 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06430 } 06431 i__2 = *ks; 06432 for (ii = 1; ii <= i__2; ++ii) { 06433 q[*ks + 1 + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06434 } 06435 } 06436 } else if (*iswi == 7) { 06437 l = 3; 06438 i__1 = n1; 06439 for (jj = 1; jj <= i__1; ++jj) { 06440 i__2 = *ks + 3; 06441 for (ii = 1; ii <= i__2; ++ii) { 06442 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06443 } 06444 i__2 = *ks; 06445 for (ii = 1; ii <= i__2; ++ii) { 06446 q[*ks + 3 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06447 } 06448 } 06449 } else if (*iswi == 8) { 06450 l = 4; 06451 i__1 = n1; 06452 for (jj = 1; jj <= i__1; ++jj) { 06453 i__2 = *ks + 4; 06454 for (ii = 1; ii <= i__2; ++ii) { 06455 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]; 06456 } 06457 i__2 = *ks; 06458 for (ii = 1; ii <= i__2; ++ii) { 06459 q[*ks + 4 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]); 06460 } 06461 } 06462 } 06463 06464 Util::cl1(ks, &l, &m, n, klm2d, &q[q_offset], &x[1], &res[1], &cu[3], &iu[3], &s[1]); 06465 i__1 = *ks; 06466 int tmp__j=0; 06467 for (i__ = 1; i__ <= i__1; ++i__) { 06468 tmp = 0.f; 06469 i__2 = *n - 1; 06470 for (j = 1; j <= i__2; ++j) { 06471 tmp__j=j; 06472 tmp += pow(q1[i__ + q1_dim1], tmp__j) * x[j]; 06473 } 06474 tmp += x[*n]; 06475 p.push_back(static_cast<float>(exp(tmp))); 06476 p.push_back(q1[i__ + q1_dim1]); 06477 } 06478 i__2=*n; 06479 for (i__=1;i__<=i__2;++i__) 06480 { p.push_back(static_cast<float>(x[i__]));} 06481 return p; 06482 }
|
|
Definition at line 17473 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, NullPointerException, nx, ny, and EMAN::EMData::update(). 17474 { 17475 ENTERFUNC; 17476 /* Exception Handle */ 17477 if (!img) { 17478 throw NullPointerException("NULL input image"); 17479 } 17480 /* ============== img += scalar*img1 ================ */ 17481 17482 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17483 int size = nx*ny*nz; 17484 float *img_ptr =img->get_data(); 17485 float *img1_ptr = img1->get_data(); 17486 for (int i=0;i<size;i++)img_ptr[i] += img1_ptr[i]*scalar; 17487 img1->update(); 17488 17489 EXITFUNC; 17490 }
|
|
Definition at line 17283 of file util_sparx.cpp. References EMAN::EMData::copy_head(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img2_ptr, img_ptr, EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), NullPointerException, nx, ny, EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), and EMAN::EMData::update(). 17284 { 17285 ENTERFUNC; 17286 /* Exception Handle */ 17287 if (!img) { 17288 throw NullPointerException("NULL input image"); 17289 } 17290 /* ============== output = img + scalar*img1 ================ */ 17291 17292 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17293 int size = nx*ny*nz; 17294 EMData * img2 = img->copy_head(); 17295 float *img_ptr =img->get_data(); 17296 float *img2_ptr = img2->get_data(); 17297 float *img1_ptr = img1->get_data(); 17298 for (int i=0;i<size;i++) img2_ptr[i] = img_ptr[i] + img1_ptr[i]*scalar; 17299 img2->update(); 17300 if(img->is_complex()) { 17301 img2->set_complex(true); 17302 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17303 } 17304 17305 EXITFUNC; 17306 return img2; 17307 }
|
|
Definition at line 1034 of file util.h. Referenced by get_stats(), get_stats_cstyle(), and multi_align_error_dfunc(). |
|
Definition at line 6119 of file util_sparx.cpp. 06120 { 06121 vector<float>new_peak; 06122 int n1=peak1.size()/3; 06123 float p_size2=p_size*p_size; 06124 for (int i=0;i<n1;++i) { 06125 vector<float>::iterator it2= peak1.begin()+3*i; 06126 bool push_back1=true; 06127 int n2=peak2.size()/3; 06128 /*cout<<"peak2 size==="<<n2<<"i====="<<i<<endl; 06129 cout<<"new peak size==="<<new_peak.size()/3<<endl;*/ 06130 if(n2 ==0) { 06131 new_peak.push_back(*it2); 06132 new_peak.push_back(*(it2+1)); 06133 new_peak.push_back(*(it2+2)); 06134 } else { 06135 int j=0; 06136 while (j< n2-1 ) { 06137 vector<float>::iterator it3= peak2.begin()+3*j; 06138 float d2=((*(it2+1))-(*(it3+1)))*((*(it2+1))-(*(it3+1)))+((*(it2+2))-(*(it3+2)))*((*(it2+2))-(*(it3+2))); 06139 if(d2< p_size2 ) { 06140 if( (*it2)<(*it3) ) { 06141 new_peak.push_back(*it3); 06142 new_peak.push_back(*(it3+1)); 06143 new_peak.push_back(*(it3+2)); 06144 peak2.erase(it3); 06145 peak2.erase(it3); 06146 peak2.erase(it3); 06147 push_back1=false; 06148 } else { 06149 peak2.erase(it3); 06150 peak2.erase(it3); 06151 peak2.erase(it3); 06152 } 06153 } else j=j+1; 06154 n2=peak2.size()/3; 06155 } 06156 if(push_back1) { 06157 new_peak.push_back(*it2); 06158 new_peak.push_back(*(it2+1)); 06159 new_peak.push_back(*(it2+2)); 06160 } 06161 } 06162 } 06163 return new_peak; 06164 }
|
|
helper function for k-means
Definition at line 5032 of file util_sparx.cpp. References data, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), nx, ny, and EMAN::Dict::size(). 05032 { 05033 ENTERFUNC; 05034 05035 int nima = data.size(); 05036 vector<float> res(nima); 05037 double result = 0.; 05038 double valmin = 1.0e20; 05039 int valpos = -1; 05040 05041 for (int kk=0; kk<nima; kk++){ 05042 result = 0; 05043 //validate_input_args(image, data[kk]); 05044 05045 float *y_data = data[kk]->get_data(); 05046 float *x_data = image->get_data(); 05047 05048 // Implemented by PAP 01/09/06 - please do not change. If in doubts, write/call me. 05049 int nx = data[kk]->get_xsize(); 05050 int ny = data[kk]->get_ysize(); 05051 nx = (nx - 2 + data[kk]->is_fftodd()); // nx is the real-space size of the input image 05052 int lsd2 = (nx + 2 - nx%2) ; // Extended x-dimension of the complex image 05053 05054 int ixb = 2*((nx+1)%2); 05055 int iyb = ny%2; 05056 int iz = 0; 05057 05058 for ( int iy = 0; iy <= ny-1; iy++) { 05059 for ( int ix = 2; ix <= lsd2 - 1 - ixb; ix++) { 05060 int ii = ix + (iy + iz * ny)* lsd2; 05061 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05062 } 05063 } 05064 for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) { 05065 int ii = (iy + iz * ny)* lsd2; 05066 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05067 result += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]); 05068 } 05069 if(nx%2 == 0) { 05070 for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) { 05071 int ii = lsd2 - 2 + (iy + iz * ny)* lsd2; 05072 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05073 result += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]); 05074 } 05075 05076 } 05077 result *= 2; 05078 result += (x_data[0] - y_data[0])*double(x_data[0] - y_data[0]); 05079 if(ny%2 == 0) { 05080 int ii = (ny/2 + iz * ny)* lsd2; 05081 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05082 } 05083 if(nx%2 == 0) { 05084 int ii = lsd2 - 2 + (0 + iz * ny)* lsd2; 05085 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05086 if(ny%2 == 0) { 05087 int ii = lsd2 - 2 +(ny/2 + iz * ny)* lsd2; 05088 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 05089 } 05090 } 05091 05092 result /= (long int)nx*(long int)ny*(long int)nx*(long int)ny; 05093 res[kk] = (float)result; 05094 05095 if(result<valmin) {valmin = result; valpos = kk;} 05096 05097 } 05098 05099 Dict retvals; 05100 retvals["dist"] = res; 05101 retvals["pos"] = valpos; 05102 05103 EXITFUNC; 05104 return retvals; 05105 }
|
|
k-means helper
Definition at line 4997 of file util_sparx.cpp. References data, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), and EMAN::Dict::size(). 04997 { 04998 ENTERFUNC; 04999 05000 int nima = data.size(); 05001 vector<float> res(nima); 05002 double result = 0.; 05003 double valmin = 1.0e20; 05004 int valpos = -1; 05005 05006 for (int kk=0; kk<nima; kk++){ 05007 result = 0; 05008 05009 float *y_data = data[kk]->get_data(); 05010 float *x_data = image->get_data(); 05011 long totsize = image->get_xsize()*image->get_ysize(); 05012 for (long i = 0; i < totsize; i++) { 05013 double temp = x_data[i]- y_data[i]; 05014 result += temp*temp; 05015 } 05016 result /= totsize; 05017 res[kk] = (float)result; 05018 05019 if(result<valmin) {valmin = result; valpos = kk;} 05020 05021 } 05022 05023 Dict retvals; 05024 retvals["dist"] = res; 05025 retvals["pos"] = valpos; 05026 05027 EXITFUNC; 05028 return retvals; 05029 05030 }
|
|
Definition at line 1019 of file util.h. Referenced by cluster_pairwise(). |
|
Definition at line 19284 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img2_ptr, img_ptr, NullPointerException, nx, ny, EMAN::EMData::set_size(), EMAN::EMData::to_zero(), and EMAN::EMData::update(). 19285 { 19286 ENTERFUNC; 19287 /* Exception Handle */ 19288 if (!img) { 19289 throw NullPointerException("NULL input image"); 19290 } 19291 19292 int newx, newy, newz; 19293 bool keep_going; 19294 cout << " entered " <<endl; 19295 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 19296 //int size = nx*ny*nz; 19297 EMData * img2 = new EMData(); 19298 img2->set_size(nx,ny,nz); 19299 img2->to_zero(); 19300 float *img_ptr =img->get_data(); 19301 float *img2_ptr = img2->get_data(); 19302 int r2 = ro*ro; 19303 int r3 = r2*ro; 19304 int ri2 = ri*ri; 19305 int ri3 = ri2*ri; 19306 19307 int n2 = nx/2; 19308 19309 for (int k=-n2; k<=n2; k++) { //cout << " k "<<k <<endl; 19310 float z2 = static_cast<float>(k*k); 19311 for (int j=-n2; j<=n2; j++) { 19312 float y2 = z2 + j*j; 19313 if(y2 <= r2) { 19314 //cout << " j "<<j <<endl; 19315 19316 for (int i=-n2; i<=n2; i++) { 19317 float x2 = y2 + i*i; 19318 if(x2 <= r3) { 19319 //cout << " i "<<i <<endl; 19320 int ib = i+n2; int jb = j+n2; int kb = k+n2; 19321 if(x2 >= ri3) { 19322 // this is the outer shell, here points can only vanish 19323 if(img_ptr(ib,jb,kb) == 1.0f) { 19324 //cout << " 1 "<<ib <<endl; 19325 if(Util::get_frand(0.0f, 1.0f) > qprob){ 19326 img2_ptr(ib,jb,kb) = 0.0f; 19327 keep_going = true; 19328 //cout << " try "<<ib <<endl; 19329 while(keep_going) { 19330 newx = Util::get_irand(-ro,ro); 19331 newy = Util::get_irand(-ro,ro); 19332 newz = Util::get_irand(-ro,ro); 19333 if(newx*newx+newy*newy+newz*newz <= r3) { 19334 newx += n2; newy += n2; newz += n2; 19335 if( img_ptr(newx,newy,newz) == 0.0f) { 19336 img2_ptr(newx,newy,newz) = 1.0f; 19337 keep_going = false; } 19338 } 19339 } 19340 } else img2_ptr(ib,jb,kb) = 1.0f; 19341 } 19342 } else { 19343 // this is inner shell, the point can only move (or vanish, if all neighbors exist) 19344 if(img_ptr(ib,jb,kb) == 1.0) { 19345 if(Util::get_frand(0.0f,1.0f) > qprob) { 19346 // find out the number of neighbors 19347 float numn = -1.0f; // we already know the central one is 1 19348 for (newz = -1; newz <= 1; newz++) 19349 for (newy = -1; newy <= 1; newy++) 19350 for (newx = -1; newx <= 1; newx++) 19351 numn += img_ptr(ib+newx,jb+newy,kb+newz); 19352 img2_ptr(ib,jb,kb) = 0.0; 19353 if(numn == 26.0f) { 19354 // all neighbors exist, it has to vanish 19355 keep_going = true; 19356 while(keep_going) { 19357 newx = Util::get_irand(-ro,ro); 19358 newy = Util::get_irand(-ro,ro); 19359 newz = Util::get_irand(-ro,ro); 19360 if(newx*newx+newy*newy+newz*newz < r3) { 19361 newx += n2; newy += n2; newz += n2; 19362 if( img_ptr(newx,newy,newz) == 0.0f) { 19363 if(newx*newx+newy*newy+newz*newz < r3) { 19364 if(newx*newx+newy*newy+newz*newz < r3) { 19365 newx += n2; newy += n2; newz += n2; 19366 if( img_ptr(newx,newy,newz) == 0.0f) { 19367 img2_ptr(newx,newy,newz) = 1.0f; 19368 keep_going = false; } 19369 } 19370 } 19371 } 19372 } 19373 } 19374 } else if(numn == 25.0f) { 19375 // there is only one empty neighbor, move there 19376 for (newz = -1; newz <= 1; newz++) { 19377 for (newy = -1; newy <= 1; newy++) { 19378 for (newx = -1; newx <= 1; newx++) { 19379 if( newx != 0 && newy != 0 && newz != 0) { 19380 if(img_ptr(newx+ib,newy+jb,newz+kb) == 0.0f) { 19381 img2_ptr(newx+ib,newy+jb,newz+kb) = 1.0f; 19382 } 19383 } 19384 } 19385 } 19386 } 19387 } else { 19388 // more than one neighbor is zero, select randomly one and move there 19389 keep_going = true; 19390 while(keep_going) { 19391 newx = Util::get_irand(-1,1); 19392 newy = Util::get_irand(-1,1); 19393 newz = Util::get_irand(-1,1); 19394 if(newx != 0 && newy != 0 && newz != 0) { 19395 if(img_ptr(ib+newx,jb+newy,kb+newz) == 0.0f) { 19396 img2_ptr(ib+newx,jb+newy,kb+newz) = 1.0f;//????? 19397 keep_going = false; 19398 } 19399 } 19400 } 19401 } 19402 } else img2_ptr(ib,jb,kb) = 1.0f; 19403 } 19404 } 19405 } 19406 } 19407 } 19408 } 19409 } 19410 //for (int i=0;i<size;i++) img2_ptr[i] = img_ptr[i] + Util::get_irand(1,7); 19411 img2->update(); 19412 19413 EXITFUNC; 19414 return img2; 19415 }
|
|
Definition at line 17572 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, EMAN::EMData::is_complex(), NullPointerException, nx, ny, and EMAN::EMData::update(). 17573 { 17574 ENTERFUNC; 17575 /* Exception Handle */ 17576 if (!img) { 17577 throw NullPointerException("NULL input image"); 17578 } 17579 /* ========= img *= img1 ===================== */ 17580 17581 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17582 int size = nx*ny*nz; 17583 float *img_ptr = img->get_data(); 17584 float *img1_ptr = img1->get_data(); 17585 if(img->is_complex()) { 17586 for (int i=0; i<size; i+=2) { 17587 float tmp = img_ptr[i] * img1_ptr[i] - img_ptr[i+1] * img1_ptr[i+1] ; 17588 img_ptr[i+1] = img_ptr[i] * img1_ptr[i+1] + img_ptr[i+1] * img1_ptr[i] ; 17589 img_ptr[i] = tmp; 17590 17591 } 17592 } else { 17593 for (int i=0;i<size;i++) img_ptr[i] *= img1_ptr[i]; 17594 } 17595 img->update(); 17596 17597 EXITFUNC; 17598 }
|
|
Definition at line 17455 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, NullPointerException, nx, ny, and EMAN::EMData::update(). 17456 { 17457 ENTERFUNC; 17458 /* Exception Handle */ 17459 if (!img) { 17460 throw NullPointerException("NULL input image"); 17461 } 17462 /* ============ output = scalar*input ================== */ 17463 17464 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17465 int size = nx*ny*nz; 17466 float *img_ptr =img->get_data(); 17467 for (int i=0;i<size;i++) img_ptr[i] *= scalar; 17468 img->update(); 17469 17470 EXITFUNC; 17471 }
|
|
Definition at line 17361 of file util_sparx.cpp. References EMAN::EMData::copy_head(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img2_ptr, img_ptr, EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), NullPointerException, nx, ny, EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), and EMAN::EMData::update(). 17362 { 17363 ENTERFUNC; 17364 /* Exception Handle */ 17365 if (!img) { 17366 throw NullPointerException("NULL input image"); 17367 } 17368 /* ============== output = img * img1 ================ */ 17369 17370 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17371 int size = nx*ny*nz; 17372 EMData * img2 = img->copy_head(); 17373 float *img_ptr =img->get_data(); 17374 float *img2_ptr = img2->get_data(); 17375 float *img1_ptr = img1->get_data(); 17376 if(img->is_complex()) { 17377 for (int i=0; i<size; i+=2) { 17378 img2_ptr[i] = img_ptr[i] * img1_ptr[i] - img_ptr[i+1] * img1_ptr[i+1] ; 17379 img2_ptr[i+1] = img_ptr[i] * img1_ptr[i+1] + img_ptr[i+1] * img1_ptr[i] ; 17380 } 17381 img2->set_complex(true); 17382 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17383 } else { 17384 for (int i=0; i<size; i++) img2_ptr[i] = img_ptr[i] * img1_ptr[i]; 17385 img2->update(); 17386 } 17387 17388 EXITFUNC; 17389 return img2; 17390 }
|
|
Definition at line 17258 of file util_sparx.cpp. References EMAN::EMData::copy_head(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img2_ptr, img_ptr, EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), NullPointerException, nx, ny, EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), and EMAN::EMData::update(). 17259 { 17260 ENTERFUNC; 17261 /* Exception Handle */ 17262 if (!img) { 17263 throw NullPointerException("NULL input image"); 17264 } 17265 /* ============ output = scalar*input ================== */ 17266 17267 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17268 int size = nx*ny*nz; 17269 EMData * img2 = img->copy_head(); 17270 float *img_ptr =img->get_data(); 17271 float *img2_ptr = img2->get_data(); 17272 for (int i=0;i<size;i++)img2_ptr[i] = img_ptr[i]*scalar; 17273 img2->update(); 17274 17275 if(img->is_complex()) { 17276 img2->set_complex(true); 17277 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17278 } 17279 EXITFUNC; 17280 return img2; 17281 }
|
|
Definition at line 18987 of file util_sparx.cpp. References multi_align_error_dfunc(), multi_align_error_func(), setulb_(), SIXTY, and x. 18987 { 18988 18989 const int nmax=args.size(), mmax=nmax; 18990 char task[60], csave[60]; 18991 long int lsave[4]; 18992 long int n, m, iprint, isave[44]; 18993 long int* nbd = new long int[nmax]; 18994 long int* iwa = new long int[3*nmax]; 18995 double f, factr, pgtol; 18996 double* x = new double[nmax]; 18997 double* l = new double[nmax]; 18998 double* u = new double[nmax]; 18999 double* g = new double[nmax]; 19000 double dsave[29]; 19001 double* wa = new double[2*mmax*nmax+4*nmax+12*mmax*mmax+12*mmax]; 19002 long int SIXTY=60; 19003 19004 int num_ali = nmax/3+1; 19005 int nima = all_ali_params.size()/(num_ali*4); 19006 19007 // We wish to have no output. 19008 iprint = -1; 19009 19010 //c We specify the tolerances in the stopping criteria. 19011 factr=1.0e1; 19012 pgtol=1.0e-9; 19013 19014 // We specify the dimension n of the sample problem and the number 19015 // m of limited memory corrections stored. (n and m should not 19016 // exceed the limits nmax and mmax respectively.) 19017 n=nmax; 19018 m=mmax; 19019 19020 // We now provide nbd which defines the bounds on the variables: 19021 // l specifies the lower bounds, 19022 // u specifies the upper bounds. 19023 // x specifies the initial guess 19024 for (int i=0; i<nmax; i++) { 19025 x[i] = args[i]; 19026 nbd[i] = 0; 19027 } 19028 19029 // We start the iteration by initializing task. 19030 // (**MUST clear remaining chars in task with spaces (else crash)!**) 19031 strcpy(task,"START"); 19032 for (int i=5;i<60;i++) task[i]=' '; 19033 19034 // This is the call to the L-BFGS-B code. 19035 // (* call the L-BFGS-B routine with task='START' once before loop *) 19036 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19037 int step = 1; 19038 19039 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *) 19040 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) { 19041 19042 if (strncmp(task,"FG",2)==0) { 19043 // the minimization routine has returned to request the 19044 // function f and gradient g values at the current x 19045 19046 // Compute function value f for the sample problem. 19047 f = multi_align_error_func(x, all_ali_params, nima, num_ali); 19048 19049 // Compute gradient g for the sample problem. 19050 multi_align_error_dfunc(x, all_ali_params, nima, num_ali, g); 19051 } 19052 19053 //c go back to the minimization routine. 19054 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 19055 step++; 19056 } 19057 19058 //printf("Total step is %d\n", step); 19059 vector<float> res; 19060 for (int i=0; i<nmax; i++) res.push_back(static_cast<float>(x[i])); 19061 res.push_back(f); 19062 19063 delete[] nbd; 19064 delete[] iwa; 19065 delete[] x; 19066 delete[] l; 19067 delete[] u; 19068 delete[] g; 19069 delete[] wa; 19070 19071 return res; 19072 19073 }
|
|
Definition at line 19131 of file util_sparx.cpp. References mean(), rot_shift(), and x. Referenced by multi_align_error(). 19131 { 19132 19133 19134 for (int i=0; i<num_ali*3-3; i++) g[i] = 0.0; 19135 19136 float x1 = 1.0; 19137 float y1 = 0.0; 19138 float x2 = 0.0; 19139 float y2 = 1.0; 19140 19141 float* x1_new = new float[num_ali]; 19142 float* y1_new = new float[num_ali]; 19143 float* x2_new = new float[num_ali]; 19144 float* y2_new = new float[num_ali]; 19145 19146 float* alpha12_0 = new float[num_ali-1]; 19147 float* dalpha12 = new float[num_ali-1]; 19148 float* dsx12 = new float[num_ali-1]; 19149 float* dsy12 = new float[num_ali-1]; 19150 float* mirror1_0 = new float[num_ali-1]; 19151 19152 for (int i=0; i<nima; i++) { 19153 19154 float alpha2 = all_ali_params[(num_ali-1)*(nima*4)+i*4]; 19155 float sx2 = all_ali_params[(num_ali-1)*(nima*4)+i*4+1]; 19156 float sy2 = all_ali_params[(num_ali-1)*(nima*4)+i*4+2]; 19157 19158 rot_shift(x1, y1, alpha2, sx2, sy2, x1_new+num_ali-1, y1_new+num_ali-1); 19159 rot_shift(x2, y2, alpha2, sx2, sy2, x2_new+num_ali-1, y2_new+num_ali-1); 19160 19161 for (int j=0; j<num_ali-1; j++) { 19162 float alpha1 = all_ali_params[j*(nima*4)+i*4]; 19163 float sx1 = all_ali_params[j*(nima*4)+i*4+1]; 19164 float sy1 = all_ali_params[j*(nima*4)+i*4+2]; 19165 int mirror1 = static_cast<int>(all_ali_params[j*(nima*4)+i*4+3]); 19166 19167 float alphai = x[j*3]; 19168 float sxi = x[j*3+1]; 19169 float syi = x[j*3+2]; 19170 19171 float cosi = cos(alphai/180.0f*M_PI); 19172 float sini = sin(alphai/180.0f*M_PI); 19173 19174 float alpha12, sx12, sy12; 19175 int mirror12; 19176 if (mirror1 == 0) { 19177 alpha12 = fmod(alpha1+alphai, 360.0f); 19178 rot_shift(sx1, sy1, alphai, sxi, syi, &sx12, &sy12); 19179 mirror12 = 0; 19180 } else { 19181 alpha12 = fmod(alpha1-alphai, 360.0f); 19182 rot_shift(sx1, sy1, -alphai, -sxi, syi, &sx12, &sy12); 19183 mirror12 = 1; 19184 } 19185 19186 rot_shift(x1, y1, alpha12, sx12, sy12, x1_new+j, y1_new+j); 19187 rot_shift(x2, y2, alpha12, sx12, sy12, x2_new+j, y2_new+j); 19188 19189 alpha12_0[j] = alpha12; 19190 mirror1_0[j] = mirror1; 19191 if (mirror1 == 0) { 19192 dalpha12[j] = M_PI/180.0f; 19193 dsx12[j] = (-sini*sx1+cosi*sy1)/180.0f*M_PI; 19194 dsy12[j] = (-cosi*sx1-sini*sy1)/180.0f*M_PI; 19195 } else { 19196 dalpha12[j] = -M_PI/180.0f; 19197 dsx12[j] = (sini*(-sx1)-cosi*sy1)/180.0f*M_PI; 19198 dsy12[j] = (-cosi*(-sx1)-sini*sy1)/180.0f*M_PI; 19199 } 19200 } 19201 19202 for (int j=0; j<num_ali-1; j++) { 19203 float cosa = cos(alpha12_0[j]/180.0f*M_PI); 19204 float sina = sin(alpha12_0[j]/180.0f*M_PI); 19205 float diffx1 = x1_new[j]-mean(x1_new, num_ali); 19206 float diffx2 = x2_new[j]-mean(x2_new, num_ali); 19207 float diffy1 = y1_new[j]-mean(y1_new, num_ali); 19208 float diffy2 = y2_new[j]-mean(y2_new, num_ali); 19209 19210 float p = diffx1*((-x1*sina+y1*cosa)*dalpha12[j]+dsx12[j])+diffx2*((-x2*sina+y2*cosa)*dalpha12[j]+dsx12[j])+diffy1*((-x1*cosa-y1*sina)*dalpha12[j]+dsy12[j])+diffy2*((-x2*cosa-y2*sina)*dalpha12[j]+dsy12[j]); 19211 g[j*3] += p; 19212 19213 p = diffx1+diffx2; 19214 if (mirror1_0[j] == 0) g[j*3+1] += p; 19215 else g[j*3+1] -= p; 19216 19217 p = diffy1+diffy2; 19218 g[j*3+2] += p; 19219 } 19220 } 19221 19222 delete[] x1_new; 19223 delete[] y1_new; 19224 delete[] x2_new; 19225 delete[] y2_new; 19226 delete[] alpha12_0; 19227 delete[] dalpha12; 19228 delete[] dsx12; 19229 delete[] dsy12; 19230 delete[] mirror1_0; 19231 19232 }
|
|
Definition at line 19075 of file util_sparx.cpp. References rot_shift(), var(), and x. Referenced by multi_align_error(). 19075 { 19076 19077 float x1 = 1.0; 19078 float y1 = 0.0; 19079 float x2 = 0.0; 19080 float y2 = 1.0; 19081 19082 float all_var = 0; 19083 float* x1_new = new float[num_ali]; 19084 float* y1_new = new float[num_ali]; 19085 float* x2_new = new float[num_ali]; 19086 float* y2_new = new float[num_ali]; 19087 19088 for (int i=0; i<nima; i++) { 19089 float alpha2 = all_ali_params[(num_ali-1)*(nima*4)+i*4]; 19090 float sx2 = all_ali_params[(num_ali-1)*(nima*4)+i*4+1]; 19091 float sy2 = all_ali_params[(num_ali-1)*(nima*4)+i*4+2]; 19092 19093 rot_shift(x1, y1, alpha2, sx2, sy2, x1_new+num_ali-1, y1_new+num_ali-1); 19094 rot_shift(x2, y2, alpha2, sx2, sy2, x2_new+num_ali-1, y2_new+num_ali-1); 19095 for (int j=0; j<num_ali-1; j++) { 19096 float alpha1 = all_ali_params[j*(nima*4)+i*4]; 19097 float sx1 = all_ali_params[j*(nima*4)+i*4+1]; 19098 float sy1 = all_ali_params[j*(nima*4)+i*4+2]; 19099 int mirror1 = static_cast<int>(all_ali_params[j*(nima*4)+i*4+3]); 19100 19101 float alphai = x[j*3]; 19102 float sxi = x[j*3+1]; 19103 float syi = x[j*3+2]; 19104 19105 float alpha12, sx12, sy12; 19106 int mirror12; 19107 if (mirror1 == 0) { 19108 alpha12 = fmod(alpha1+alphai, 360.0f); 19109 rot_shift(sx1, sy1, alphai, sxi, syi, &sx12, &sy12); 19110 mirror12 = 0; 19111 } else { 19112 alpha12 = fmod(alpha1-alphai, 360.0f); 19113 rot_shift(sx1, sy1, -alphai, -sxi, syi, &sx12, &sy12); 19114 mirror12 = 1; 19115 } 19116 19117 rot_shift(x1, y1, alpha12, sx12, sy12, x1_new+j, y1_new+j); 19118 rot_shift(x2, y2, alpha12, sx12, sy12, x2_new+j, y2_new+j); 19119 } 19120 19121 float p = var(x1_new, num_ali)+var(y1_new, num_ali)+var(x2_new, num_ali)+var(y2_new, num_ali); 19122 all_var += p; 19123 } 19124 delete[] x1_new; 19125 delete[] y1_new; 19126 delete[] x2_new; 19127 delete[] y2_new; 19128 return all_var/static_cast<float>(nima); 19129 }
|
|
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 18365 of file util_sparx.cpp. References Crosrng_msg_vec(), Frngs(), EMAN::EMData::get_data(), numr, Polar2Dm(), and EMAN::EMData::set_size(). 18368 { 18369 18370 int maxrin = numr[numr.size()-1]; 18371 18372 int ky = int(2*yrng/step+0.5)/2; 18373 int kx = int(2*xrng/step+0.5)/2; 18374 18375 peaks->set_size(maxrin, 2*kx+3, 2*ky+3); 18376 float *p_ccf1ds = peaks->get_data(); 18377 18378 peakm->set_size(maxrin, 2*kx+3, 2*ky+3); 18379 float *p_ccf1dm = peakm->get_data(); 18380 18381 for ( int i = 0; i<maxrin*(2*kx+3)*(2*ky+3); i++) { 18382 p_ccf1ds[i] = -1.e20f; 18383 p_ccf1dm[i] = -1.e20f; 18384 } 18385 18386 for (int i = -ky; i <= ky; i++) { 18387 float iy = i * step; 18388 for (int j = -kx; j <= kx; j++) { 18389 float ix = j*step; 18390 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18391 Frngs(cimage, numr); 18392 Crosrng_msg_vec(crefim, cimage, numr, 18393 p_ccf1ds+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin, 18394 p_ccf1dm+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin); 18395 delete cimage; cimage = 0; 18396 } 18397 } 18398 return; 18399 }
|
|
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 18401 of file util_sparx.cpp. References Crosrng_msg_vec(), Frngs(), EMAN::EMData::get_data(), numr, Polar2Dm(), EMAN::EMData::set_size(), and x. 18403 { 18404 18405 int maxrin = numr[numr.size()-1]; 18406 18407 int ky = int(2*yrng/step+0.5)/2; 18408 int kx = int(2*xrng/step+0.5)/2; 18409 18410 peaks->set_size(maxrin, 2*kx+3, 2*ky+3); 18411 float *p_ccf1ds = peaks->get_data(); 18412 18413 peakm->set_size(maxrin, 2*kx+3, 2*ky+3); 18414 float *p_ccf1dm = peakm->get_data(); 18415 18416 peaks_compress->set_size(maxrin, 1, 1); 18417 float *p_ccf1ds_compress = peaks_compress->get_data(); 18418 18419 peakm_compress->set_size(maxrin, 1, 1); 18420 float *p_ccf1dm_compress = peakm_compress->get_data(); 18421 18422 for ( int i = 0; i<maxrin*(2*kx+3)*(2*ky+3); i++) { 18423 p_ccf1ds[i] = -1.e20f; 18424 p_ccf1dm[i] = -1.e20f; 18425 } 18426 18427 for (int i = -ky; i <= ky; i++) { 18428 float iy = i * step; 18429 for (int j = -kx; j <= kx; j++) { 18430 float ix = j*step; 18431 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18432 Frngs(cimage, numr); 18433 Crosrng_msg_vec(crefim, cimage, numr, 18434 p_ccf1ds+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin, 18435 p_ccf1dm+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin); 18436 delete cimage; cimage = 0; 18437 } 18438 } 18439 for (int x=0; x<maxrin; x++) { 18440 float maxs = -1.0e22f; 18441 float maxm = -1.0e22f; 18442 for (int i=1; i<=2*ky+1; i++) { 18443 for (int j=1; j<=2*kx+1; j++) { 18444 if (p_ccf1ds[(i*(2*kx+3)+j)*maxrin+x] > maxs) maxs = p_ccf1ds[(i*(2*kx+3)+j)*maxrin+x]; 18445 if (p_ccf1dm[(i*(2*kx+3)+j)*maxrin+x] > maxm) maxm = p_ccf1dm[(i*(2*kx+3)+j)*maxrin+x]; 18446 } 18447 } 18448 p_ccf1ds_compress[x] = maxs; 18449 p_ccf1dm_compress[x] = maxm; 18450 } 18451 return; 18452 }
|
|
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 17781 of file util_sparx.cpp. References ang_n(), Crosrng_ms(), Frngs(), Normalize_ring(), numr, pi, Polar2Dm(), and EMAN::Dict::size(). 17783 { 17784 17785 // Manually extract. 17786 /* vector< EMAN::EMData* > crefim; 17787 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 17788 crefim.reserve(crefim_len); 17789 17790 for(std::size_t i=0;i<crefim_len;i++) { 17791 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 17792 crefim.push_back(proxy()); 17793 } 17794 */ 17795 17796 size_t crefim_len = crefim.size(); 17797 17798 int ky = int(2*yrng/step+0.5)/2; 17799 int kx = int(2*xrng/step+0.5)/2; 17800 int iref, nref=0, mirror=0; 17801 float iy, ix, sx=0, sy=0; 17802 float peak = -1.0E23f; 17803 float ang=0.0f; 17804 for (int i = -ky; i <= ky; i++) { 17805 iy = i * step ; 17806 for (int j = -kx; j <= kx; j++) { 17807 ix = j*step ; 17808 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 17809 17810 Normalize_ring( cimage, numr ); 17811 17812 Frngs(cimage, numr); 17813 // compare with all reference images 17814 // for iref in xrange(len(crefim)): 17815 for ( iref = 0; iref < (int)crefim_len; iref++) { 17816 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr); 17817 double qn = retvals["qn"]; 17818 double qm = retvals["qm"]; 17819 if(qn >= peak || qm >= peak) { 17820 sx = -ix; 17821 sy = -iy; 17822 nref = iref; 17823 if (qn >= qm) { 17824 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 17825 peak = static_cast<float>(qn); 17826 mirror = 0; 17827 } else { 17828 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 17829 peak = static_cast<float>(qm); 17830 mirror = 1; 17831 } 17832 } 17833 } delete cimage; cimage = 0; 17834 } 17835 } 17836 float co, so, sxs, sys; 17837 co = static_cast<float>( cos(ang*pi/180.0) ); 17838 so = static_cast<float>( -sin(ang*pi/180.0) ); 17839 sxs = sx*co - sy*so; 17840 sys = sx*so + sy*co; 17841 vector<float> res; 17842 res.push_back(ang); 17843 res.push_back(sxs); 17844 res.push_back(sys); 17845 res.push_back(static_cast<float>(mirror)); 17846 res.push_back(static_cast<float>(nref)); 17847 res.push_back(peak); 17848 return res; 17849 }
|
|
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 17905 of file util_sparx.cpp. References ang_n(), Crosrng_ms_delta(), Frngs(), Normalize_ring(), numr, pi, Polar2Dm(), and EMAN::Dict::size(). 17907 { 17908 17909 // Manually extract. 17910 /* vector< EMAN::EMData* > crefim; 17911 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 17912 crefim.reserve(crefim_len); 17913 17914 for(std::size_t i=0;i<crefim_len;i++) { 17915 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 17916 crefim.push_back(proxy()); 17917 } 17918 */ 17919 17920 size_t crefim_len = crefim.size(); 17921 17922 int ky = int(2*yrng/step+0.5)/2; 17923 int kx = int(2*xrng/step+0.5)/2; 17924 int iref, nref=0, mirror=0; 17925 float iy, ix, sx=0, sy=0; 17926 float peak = -1.0E23f; 17927 float ang=0.0f; 17928 for (int i = -ky; i <= ky; i++) { 17929 iy = i * step ; 17930 for (int j = -kx; j <= kx; j++) { 17931 ix = j*step ; 17932 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 17933 17934 Normalize_ring( cimage, numr ); 17935 17936 Frngs(cimage, numr); 17937 // compare with all reference images 17938 // for iref in xrange(len(crefim)): 17939 for ( iref = 0; iref < (int)crefim_len; iref++) { 17940 Dict retvals = Crosrng_ms_delta(crefim[iref], cimage, numr, delta_start, delta); 17941 double qn = retvals["qn"]; 17942 double qm = retvals["qm"]; 17943 if(qn >= peak || qm >= peak) { 17944 sx = -ix; 17945 sy = -iy; 17946 nref = iref; 17947 if (qn >= qm) { 17948 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 17949 peak = static_cast<float>(qn); 17950 mirror = 0; 17951 } else { 17952 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 17953 peak = static_cast<float>(qm); 17954 mirror = 1; 17955 } 17956 } 17957 } delete cimage; cimage = 0; 17958 } 17959 } 17960 float co, so, sxs, sys; 17961 co = static_cast<float>( cos(ang*pi/180.0) ); 17962 so = static_cast<float>( -sin(ang*pi/180.0) ); 17963 sxs = sx*co - sy*so; 17964 sys = sx*so + sy*co; 17965 vector<float> res; 17966 res.push_back(ang); 17967 res.push_back(sxs); 17968 res.push_back(sys); 17969 res.push_back(static_cast<float>(mirror)); 17970 res.push_back(static_cast<float>(nref)); 17971 res.push_back(peak); 17972 return res; 17973 }
|
|
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 18032 of file util_sparx.cpp. References abs, ang_n(), Crosrng_ms(), Frngs(), EMAN::EMData::get_attr(), EMAN::Transform::get_params(), Normalize_ring(), numr, phi, pi, Polar2Dm(), EMAN::Dict::size(), t, and theta. 18034 { 18035 18036 // Manually extract. 18037 /* vector< EMAN::EMData* > crefim; 18038 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 18039 crefim.reserve(crefim_len); 18040 18041 for(std::size_t i=0;i<crefim_len;i++) { 18042 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 18043 crefim.push_back(proxy()); 18044 } 18045 */ 18046 size_t crefim_len = crefim.size(); 18047 const float qv = static_cast<float>( pi/180.0 ); 18048 18049 Transform * t = image->get_attr("xform.projection"); 18050 Dict d = t->get_params("spider"); 18051 if(t) {delete t; t=0;} 18052 float phi = d["phi"]; 18053 float theta = d["theta"]; 18054 int ky = int(2*yrng/step+0.5)/2; 18055 int kx = int(2*xrng/step+0.5)/2; 18056 int iref, nref=0, mirror=0; 18057 float iy, ix, sx=0, sy=0; 18058 float peak = -1.0E23f; 18059 float ang=0.0f; 18060 float imn1 = sin(theta*qv)*cos(phi*qv); 18061 float imn2 = sin(theta*qv)*sin(phi*qv); 18062 float imn3 = cos(theta*qv); 18063 vector<float> n1(crefim_len); 18064 vector<float> n2(crefim_len); 18065 vector<float> n3(crefim_len); 18066 for ( iref = 0; iref < (int)crefim_len; iref++) { 18067 n1[iref] = crefim[iref]->get_attr("n1"); 18068 n2[iref] = crefim[iref]->get_attr("n2"); 18069 n3[iref] = crefim[iref]->get_attr("n3"); 18070 } 18071 for (int i = -ky; i <= ky; i++) { 18072 iy = i * step ; 18073 for (int j = -kx; j <= kx; j++) { 18074 ix = j*step; 18075 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18076 18077 Normalize_ring( cimage, numr ); 18078 18079 Frngs(cimage, numr); 18080 // compare with all reference images 18081 // for iref in xrange(len(crefim)): 18082 for ( iref = 0; iref < (int)crefim_len; iref++) { 18083 if(abs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) { 18084 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr); 18085 double qn = retvals["qn"]; 18086 double qm = retvals["qm"]; 18087 if(qn >= peak || qm >= peak) { 18088 sx = -ix; 18089 sy = -iy; 18090 nref = iref; 18091 if (qn >= qm) { 18092 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18093 peak = static_cast<float>( qn ); 18094 mirror = 0; 18095 } else { 18096 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 18097 peak = static_cast<float>( qm ); 18098 mirror = 1; 18099 } 18100 } 18101 } 18102 } delete cimage; cimage = 0; 18103 } 18104 } 18105 float co, so, sxs, sys; 18106 if(peak == -1.0E23) { 18107 ang=0.0; sxs=0.0; sys=0.0; mirror=0; 18108 nref = -1; 18109 } else { 18110 co = cos(ang*qv); 18111 so = -sin(ang*qv); 18112 sxs = sx*co - sy*so; 18113 sys = sx*so + sy*co; 18114 } 18115 vector<float> res; 18116 res.push_back(ang); 18117 res.push_back(sxs); 18118 res.push_back(sys); 18119 res.push_back(static_cast<float>(mirror)); 18120 res.push_back(static_cast<float>(nref)); 18121 res.push_back(peak); 18122 return res; 18123 }
|
|
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 18125 of file util_sparx.cpp. References abs, ang_n(), Crosrng_sm_psi(), Frngs(), EMAN::EMData::get_attr(), EMAN::Transform::get_params(), Normalize_ring(), numr, phi, pi, Polar2Dm(), EMAN::Dict::size(), t, and theta. 18127 { 18128 18129 // Manually extract. 18130 /* vector< EMAN::EMData* > crefim; 18131 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 18132 crefim.reserve(crefim_len); 18133 18134 for(std::size_t i=0;i<crefim_len;i++) { 18135 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 18136 crefim.push_back(proxy()); 18137 } 18138 */ 18139 size_t crefim_len = crefim.size(); 18140 const float qv = static_cast<float>(pi/180.0); 18141 18142 Transform* t = image->get_attr("xform.projection"); 18143 Dict d = t->get_params("spider"); 18144 if(t) {delete t; t=0;} 18145 float phi = d["phi"]; 18146 float theta = d["theta"]; 18147 float psi = d["psi"]; 18148 int ky = int(2*yrng/step+0.5)/2; 18149 int kx = int(2*xrng/step+0.5)/2; 18150 int iref, nref = 0, mirror = 0; 18151 float iy, ix, sx = 0, sy = 0; 18152 float peak = -1.0E23f; 18153 float ang = 0.0f; 18154 float imn1 = sin(theta*qv)*cos(phi*qv); 18155 float imn2 = sin(theta*qv)*sin(phi*qv); 18156 float imn3 = cos(theta*qv); 18157 vector<float> n1(crefim_len); 18158 vector<float> n2(crefim_len); 18159 vector<float> n3(crefim_len); 18160 for (iref = 0; iref < (int)crefim_len; iref++) { 18161 n1[iref] = crefim[iref]->get_attr("n1"); 18162 n2[iref] = crefim[iref]->get_attr("n2"); 18163 n3[iref] = crefim[iref]->get_attr("n3"); 18164 } 18165 bool nomirror = (theta<90.0) || ((theta==90.0) && (psi<psi_max)); 18166 if (!nomirror) { 18167 phi = fmod(phi+540.0f, 360.0f); 18168 theta = 180-theta; 18169 psi = fmod(540.0f-psi, 360.0f); 18170 } 18171 for (int i = -ky; i <= ky; i++) { 18172 iy = i * step ; 18173 for (int j = -kx; j <= kx; j++) { 18174 ix = j*step; 18175 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18176 18177 Normalize_ring(cimage, numr); 18178 18179 Frngs(cimage, numr); 18180 // compare with all reference images 18181 // for iref in xrange(len(crefim)): 18182 for (iref = 0; iref < (int)crefim_len; iref++) { 18183 if (abs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) { 18184 if (nomirror) { 18185 Dict retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, psi, 0); 18186 double qn = retvals["qn"]; 18187 if (qn >= peak) { 18188 sx = -ix; 18189 sy = -iy; 18190 nref = iref; 18191 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18192 peak = static_cast<float>(qn); 18193 mirror = 0; 18194 } 18195 } else { 18196 Dict retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, psi, 1); 18197 double qn = retvals["qn"]; 18198 if (qn >= peak) { 18199 sx = -ix; 18200 sy = -iy; 18201 nref = iref; 18202 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18203 peak = static_cast<float>(qn); 18204 mirror = 1; 18205 } 18206 } 18207 } 18208 } delete cimage; cimage = 0; 18209 } 18210 } 18211 float co, so, sxs, sys; 18212 if(peak == -1.0E23) { 18213 ang=0.0; sxs=0.0; sys=0.0; mirror=0; 18214 nref = -1; 18215 } else { 18216 co = cos(ang*qv); 18217 so = -sin(ang*qv); 18218 sxs = sx*co - sy*so; 18219 sys = sx*so + sy*co; 18220 } 18221 vector<float> res; 18222 res.push_back(ang); 18223 res.push_back(sxs); 18224 res.push_back(sys); 18225 res.push_back(static_cast<float>(mirror)); 18226 res.push_back(static_cast<float>(nref)); 18227 res.push_back(peak); 18228 return res; 18229 }
|
|
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 17975 of file util_sparx.cpp. References ang_n(), Crosrng_ns(), Frngs(), numr, pi, Polar2Dm(), and EMAN::Dict::size(). 17977 { 17978 17979 // Manually extract. 17980 /* vector< EMAN::EMData* > crefim; 17981 std::size_t crefim_len = PyObject_Length(crefim_list.ptr()); 17982 crefim.reserve(crefim_len); 17983 17984 for(std::size_t i=0;i<crefim_len;i++) { 17985 boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]); 17986 crefim.push_back(proxy()); 17987 } 17988 */ 17989 size_t crefim_len = crefim.size(); 17990 17991 int ky = int(2*yrng/step+0.5)/2; 17992 int kx = int(2*xrng/step+0.5)/2; 17993 int iref, nref=0; 17994 float iy, ix, sx=0, sy=0; 17995 float peak = -1.0E23f; 17996 float ang=0.0f; 17997 for (int i = -ky; i <= ky; i++) { 17998 iy = i * step ; 17999 for (int j = -kx; j <= kx; j++) { 18000 ix = j*step ; 18001 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18002 Frngs(cimage, numr); 18003 // compare with all reference images 18004 // for iref in xrange(len(crefim)): 18005 for ( iref = 0; iref < (int)crefim_len; iref++) { 18006 Dict retvals = Crosrng_ns(crefim[iref], cimage, numr); 18007 double qn = retvals["qn"]; 18008 if(qn >= peak) { 18009 sx = -ix; 18010 sy = -iy; 18011 nref = iref; 18012 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18013 peak = static_cast<float>(qn); 18014 } 18015 } delete cimage; cimage = 0; 18016 } 18017 } 18018 float co, so, sxs, sys; 18019 co = static_cast<float>( cos(ang*pi/180.0) ); 18020 so = static_cast<float>( -sin(ang*pi/180.0) ); 18021 sxs = sx*co - sy*so; 18022 sys = sx*so + sy*co; 18023 vector<float> res; 18024 res.push_back(ang); 18025 res.push_back(sxs); 18026 res.push_back(sys); 18027 res.push_back(static_cast<float>(nref)); 18028 res.push_back(peak); 18029 return res; 18030 }
|
|
Definition at line 17851 of file util_sparx.cpp. References ang_n(), Crosrng_ms(), Frngs(), Normalize_ring(), numr, pi, Polar2Dm(), and EMAN::Dict::size(). 17853 { 17854 17855 size_t crefim_len = crefim.size(); 17856 17857 int ky = int(2*yrng/step+0.5)/2; 17858 int kx = int(2*xrng/step+0.5)/2; 17859 float iy, ix; 17860 vector<float> peak(crefim_len*5, -1.0e23f); 17861 for (int i = -ky; i <= ky; i++) { 17862 iy = i * step ; 17863 for (int j = -kx; j <= kx; j++) { 17864 ix = j*step ; 17865 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 17866 Normalize_ring( cimage, numr ); 17867 Frngs(cimage, numr); 17868 for (int iref = 0; iref < (int)crefim_len; iref++) { 17869 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr); 17870 double qn = retvals["qn"]; 17871 double qm = retvals["qm"]; 17872 if(qn >= peak[iref*5] || qm >= peak[iref*5]) { 17873 if (qn >= qm) { 17874 peak[iref*5] = static_cast<float>(qn); 17875 peak[iref*5+1] = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 17876 peak[iref*5+2] = -ix; 17877 peak[iref*5+3] = -iy; 17878 peak[iref*5+4] = 0; 17879 } else { 17880 peak[iref*5] = static_cast<float>(qm); 17881 peak[iref*5+1] = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 17882 peak[iref*5+2] = -ix; 17883 peak[iref*5+3] = -iy; 17884 peak[iref*5+4] = 1; 17885 } 17886 } 17887 } delete cimage; cimage = 0; 17888 } 17889 } 17890 for (int iref = 0; iref < (int)crefim_len; iref++) { 17891 float ang = peak[iref*5+1]; 17892 float sx = peak[iref*5+2]; 17893 float sy = peak[iref*5+3]; 17894 float co = cos(ang*pi/180.0); 17895 float so = -sin(ang*pi/180.0); 17896 float sxs = sx*co - sy*so; 17897 float sys = sx*so + sy*co; 17898 peak[iref*5+2] = sxs; 17899 peak[iref*5+3] = sys; 17900 } 17901 return peak; 17902 }
|
|
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 18232 of file util_sparx.cpp. References ang_n(), Crosrng_psi_0_180(), Frngs(), Normalize_ring(), numr, pi, Polar2Dm(), and EMAN::Dict::size(). 18234 { 18235 18236 size_t crefim_len = crefim.size(); 18237 18238 int iref, nref=0, mirror=0; 18239 float iy, ix, sx=0, sy=0; 18240 float peak = -1.0E23f; 18241 float ang=0.0f; 18242 int kx = int(2*xrng/step+0.5)/2; 18243 //if ynumber==-1, use the old code which process x and y direction equally. 18244 if(ynumber==-1) { 18245 int ky = int(2*yrng/step+0.5)/2; 18246 for (int i = -ky; i <= ky; i++) { 18247 iy = i * step ; 18248 for (int j = -kx; j <= kx; j++) { 18249 ix = j*step ; 18250 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18251 18252 Normalize_ring( cimage, numr ); 18253 18254 Frngs(cimage, numr); 18255 // compare with all reference images 18256 // for iref in xrange(len(crefim)): 18257 for ( iref = 0; iref < (int)crefim_len; iref++) { 18258 Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max); 18259 double qn = retvals["qn"]; 18260 double qm = retvals["qm"]; 18261 if(qn >= peak || qm >= peak) { 18262 sx = -ix; 18263 sy = -iy; 18264 nref = iref; 18265 if (qn >= qm) { 18266 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18267 peak = static_cast<float>(qn); 18268 mirror = 0; 18269 } else { 18270 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 18271 peak = static_cast<float>(qm); 18272 mirror = 1; 18273 } 18274 } 18275 } 18276 delete cimage; cimage = 0; 18277 } 18278 } 18279 } 18280 //if ynumber is given, it should be even. We need to check whether it is zero 18281 else if(ynumber==0) { 18282 sy = 0.0f; 18283 for (int j = -kx; j <= kx; j++) { 18284 ix = j*step ; 18285 EMData* cimage = Polar2Dm(image, cnx+ix, cny, numr, mode); 18286 18287 Normalize_ring( cimage, numr ); 18288 18289 Frngs(cimage, numr); 18290 // compare with all reference images 18291 // for iref in xrange(len(crefim)): 18292 for ( iref = 0; iref < (int)crefim_len; iref++) { 18293 Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max); 18294 double qn = retvals["qn"]; 18295 double qm = retvals["qm"]; 18296 if(qn >= peak || qm >= peak) { 18297 sx = -ix; 18298 nref = iref; 18299 if (qn >= qm) { 18300 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18301 peak = static_cast<float>(qn); 18302 mirror = 0; 18303 } else { 18304 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 18305 peak = static_cast<float>(qm); 18306 mirror = 1; 18307 } 18308 } 18309 } 18310 delete cimage; cimage = 0; 18311 } 18312 } else { 18313 int ky = int(ynumber/2); 18314 float stepy=2*yrng/ynumber; 18315 //std::cout<<"yrng="<<yrng<<"ynumber="<<ynumber<<"stepy=="<<stepy<<"stepx=="<<step<<std::endl; 18316 for (int i = -ky+1; i <= ky; i++) { 18317 iy = i * stepy ; 18318 for (int j = -kx; j <= kx; j++) { 18319 ix = j*step ; 18320 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode); 18321 18322 Normalize_ring( cimage, numr ); 18323 18324 Frngs(cimage, numr); 18325 // compare with all reference images 18326 // for iref in xrange(len(crefim)): 18327 for ( iref = 0; iref < (int)crefim_len; iref++) { 18328 Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max); 18329 double qn = retvals["qn"]; 18330 double qm = retvals["qm"]; 18331 if(qn >= peak || qm >= peak) { 18332 sx = -ix; 18333 sy = -iy; 18334 nref = iref; 18335 if (qn >= qm) { 18336 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]); 18337 peak = static_cast<float>(qn); 18338 mirror = 0; 18339 } else { 18340 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]); 18341 peak = static_cast<float>(qm); 18342 mirror = 1; 18343 } 18344 } 18345 } 18346 delete cimage; cimage = 0; 18347 } 18348 } 18349 } 18350 float co, so, sxs, sys; 18351 co = static_cast<float>( cos(ang*pi/180.0) ); 18352 so = static_cast<float>( -sin(ang*pi/180.0) ); 18353 sxs = sx*co - sy*so; 18354 sys = sx*so + sy*co; 18355 vector<float> res; 18356 res.push_back(ang); 18357 res.push_back(sxs); 18358 res.push_back(sys); 18359 res.push_back(static_cast<float>(mirror)); 18360 res.push_back(static_cast<float>(nref)); 18361 res.push_back(peak); 18362 return res; 18363 }
|
|
Definition at line 1029 of file util.h. Referenced by cml_line_insino(), and cml_line_insino_all(). |
|
Definition at line 17748 of file util_sparx.cpp. References data, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), nn(), numr, sqrt(), and EMAN::EMData::update(). Referenced by multiref_polar_ali_2d(), multiref_polar_ali_2d_delta(), multiref_polar_ali_2d_local(), multiref_polar_ali_2d_local_psi(), multiref_polar_ali_2d_peaklist(), and multiref_polar_ali_helical(). 17749 { 17750 float* data = ring->get_data(); 17751 float av=0.0; 17752 float sq=0.0; 17753 float nn=0.0; 17754 int nring = numr.size()/3; 17755 for( int i=0; i < nring; ++i ) 17756 { 17757 int numr3i = numr[3*i+2]; 17758 int numr2i = numr[3*i+1]-1; 17759 float w = numr[3*i]*2*M_PI/float(numr[3*i+2]); 17760 for( int j=0; j < numr3i; ++j ) 17761 { 17762 int jc = numr2i+j; 17763 av += data[jc] * w; 17764 sq += data[jc] * data[jc] * w; 17765 nn += w; 17766 } 17767 } 17768 17769 float avg = av/nn; 17770 float sgm = sqrt( (sq-av*av/nn)/nn ); 17771 int n = ring->get_xsize() * ring->get_ysize() * ring->get_zsize(); 17772 for( int i=0; i < n; ++i ) 17773 { 17774 data[i] -= avg; 17775 data[i] /= sgm; 17776 } 17777 17778 ring->update(); 17779 }
|
|
Definition at line 17658 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, EMAN::EMData::is_fftodd(), NullPointerException, nx, ny, power(), EMAN::EMData::set_array_offsets(), EMAN::EMData::set_size(), and EMAN::EMData::update(). 17659 { 17660 ENTERFUNC; 17661 /* Exception Handle */ 17662 if (!img) { 17663 throw NullPointerException("NULL input image"); 17664 } 17665 /* ============== img is modulus of a complex image in FFT format (so its imaginary parts are zero), 17666 output is img packed into real image with Friedel part added, ================ */ 17667 17668 int nxo=img->get_xsize(), ny=img->get_ysize(), nz=img->get_zsize(); 17669 int nx = nxo - 2 + img->is_fftodd(); 17670 int lsd2 = (nx + 2 - nx%2) / 2; // Extended x-dimension of the complex image 17671 int nyt, nzt; 17672 int nx2 = nx/2; 17673 int ny2 = ny/2; if(ny2 == 0) nyt =0; else nyt=ny; 17674 int nz2 = nz/2; if(nz2 == 0) nzt =0; else nzt=nz; 17675 int nx2p = nx2+nx%2; 17676 int ny2p = ny2+ny%2; 17677 int nz2p = nz2+nz%2; 17678 EMData& power = *(new EMData()); // output image 17679 power.set_size(nx, ny, nz); 17680 power.set_array_offsets(-nx2,-ny2,-nz2); 17681 //img->set_array_offsets(1,1,1); 17682 float *img_ptr = img->get_data(); 17683 for (int iz = 1; iz <= nz; iz++) { 17684 int jz=iz-1; 17685 if(jz>=nz2p) jz=jz-nzt; 17686 for (int iy = 1; iy <= ny; iy++) { 17687 int jy=iy-1; 17688 if(jy>=ny2p) jy=jy-nyt; 17689 for (int ix = 1; ix <= lsd2; ix++) { 17690 int jx=ix-1; 17691 if(jx>=nx2p) jx=jx-nx; 17692 power(jx,jy,jz) = img_ptr(ix,iy,iz); //real(img->cmplx(ix,iy,iz)); 17693 } 17694 } 17695 } 17696 // Create the Friedel related half 17697 int nzb, nze, nyb, nye, nxb, nxe; 17698 nxb =-nx2+(nx+1)%2; 17699 nxe = nx2-(nx+1)%2; 17700 if(ny2 == 0) {nyb =0; nye = 0;} else {nyb =-ny2+(ny+1)%2; nye = ny2-(ny+1)%2;} 17701 if(nz2 == 0) {nzb =0; nze = 0;} else {nzb =-nz2+(nz+1)%2; nze = nz2-(nz+1)%2;} 17702 for (int iz = nzb; iz <= nze; iz++) { 17703 for (int iy = nyb; iy <= nye; iy++) { 17704 for (int ix = 1; ix <= nxe; ix++) { // Note this loop begins with 1 - FFT should create correct Friedel related 0 plane 17705 power(-ix,-iy,-iz) = power(ix,iy,iz); 17706 } 17707 } 17708 } 17709 if(ny2 != 0) { 17710 if(nz2 != 0) { 17711 if(nz%2 == 0) { //if nz even, fix the first slice 17712 for (int iy = nyb; iy <= nye; iy++) { 17713 for (int ix = nxb; ix <= -1; ix++) { 17714 power(ix,iy,-nz2) = power(-ix,-iy,-nz2); 17715 } 17716 } 17717 if(ny%2 == 0) { //if ny even, fix the first line 17718 for (int ix = nxb; ix <= -1; ix++) { 17719 power(ix,-ny2,-nz2) = power(-ix,-ny2,-nz2); 17720 } 17721 } 17722 } 17723 } 17724 if(ny%2 == 0) { //if ny even, fix the first column 17725 for (int iz = nzb; iz <= nze; iz++) { 17726 for (int ix = nxb; ix <= -1; ix++) { 17727 power(ix,-ny2,-iz) = power(-ix,-ny2,iz); 17728 } 17729 } 17730 } 17731 17732 } 17733 power.update(); 17734 power.set_array_offsets(0,0,0); 17735 return &power; 17736 }
|
|
Definition at line 5264 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(). 05265 { 05266 /* Exception Handle */ 05267 if (!img) throw NullPointerException("NULL input image"); 05268 /* ============================== */ 05269 05270 // Get the size of the input image 05271 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 05272 /* ============================== */ 05273 05274 /* Exception Handle */ 05275 if(new_nx<nx || new_ny<ny || new_nz<nz) 05276 throw ImageDimensionException("The size of the padded image cannot be lower than the input image size."); 05277 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) 05278 throw ImageDimensionException("The offset imconsistent with the input image size. Solution: Change the offset parameters"); 05279 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)))) 05280 throw ImageDimensionException("The offset imconsistent with the input image size. Solution: Change the offset parameters"); 05281 /* ============================== */ 05282 05283 EMData* pading = img->copy_head(); 05284 pading->set_size(new_nx, new_ny, new_nz); 05285 float *inp = img->get_data(); 05286 float *outp = pading->get_data(); 05287 05288 05289 /* Calculation of the average and the circumference values for background substitution 05290 =======================================================================================*/ 05291 float background; 05292 05293 if (strcmp(params,"average")==0) background = img->get_attr("mean"); 05294 else if (strcmp(params,"circumference")==0) { 05295 float sum1=0.0f; 05296 int cnt=0; 05297 for(int i=0;i<nx;i++) { 05298 sum1 += inp(i,0,0) + inp(i,ny-1,nz-1); 05299 cnt+=2; 05300 } 05301 if(nz-1 == 0) { 05302 for (int j=1;j<ny-1;j++) { 05303 sum1 += inp(1,j,0) + inp(nx-1,j,0); 05304 cnt+=2; 05305 } 05306 } else { 05307 for (int k=1;k<nz-1;k++) { 05308 for (int j=1;j<ny-1;j++) { 05309 sum1 += inp(1,j,0) + inp(nx-1,j,0); 05310 cnt+=2; 05311 } 05312 } 05313 } 05314 background = sum1/cnt; 05315 } else { 05316 background = static_cast<float>( atof( params ) ); 05317 } 05318 /*=====================================================================================*/ 05319 05320 /*Initial Padding */ 05321 int new_st_x=0,new_st_y=0,new_st_z=0; 05322 for (int k=0;k<new_nz;k++) 05323 for(int j=0;j<new_ny;j++) 05324 for (int i=0;i<new_nx;i++) 05325 outp(i,j,k)=background; 05326 /*============================== */ 05327 05328 /* Calculation of the start point */ 05329 new_st_x=int((new_nx/2-nx/2) + x_offset); 05330 new_st_y=int((new_ny/2-ny/2) + y_offset); 05331 new_st_z=int((new_nz/2-nz/2) + z_offset); 05332 /* ============================== */ 05333 05334 for (int k=0;k<nz;k++) 05335 for(int j=0;j<ny;j++) 05336 for(int i=0;i<nx;i++) 05337 outp(i,j,k)=inp(i,j,k); 05338 pading->update(); 05339 return pading; 05340 }
|
|
Determines if a point is in a 2D convex polygon described by 4 points using the Barycentric method, which is a fast way of performing the query. The points must be ordered in the way you would encounter them if you traversed the boundary of the polygon. Direction is irrelevant. Could be generalized for polygons with more points
Definition at line 1269 of file util.cpp. References point_is_in_triangle_2d(), and EMAN::Vec2f. 01270 { 01271 01272 if (point_is_in_triangle_2d(p1,p2,p4,actual_point)) return true; 01273 else return point_is_in_triangle_2d(p3,p2,p4,actual_point); 01274 }
|
|
Determines if a point is in a 2D triangle using the Barycentric method, which is a fast way of performing the query Triangle points can be specified in any order.
Definition at line 1234 of file util.cpp. References EMAN::Vec2< Type >::dot(), t, v, and EMAN::Vec2f. Referenced by point_is_in_convex_polygon_2d(). 01235 { 01236 01237 Vec2f u = p2 - p1; 01238 Vec2f v = p3 - p1; 01239 Vec2f w = point - p1; 01240 01241 float udotu = u.dot(u); 01242 float udotv = u.dot(v); 01243 float udotw = u.dot(w); 01244 float vdotv = v.dot(v); 01245 float vdotw = v.dot(w); 01246 01247 float d = 1.0f/(udotv*udotv - udotu*vdotv); 01248 float s = udotv*vdotw - vdotv*udotw; 01249 s *= d; 01250 01251 float t = udotv*udotw - udotu*vdotw; 01252 t *= d; 01253 01254 // We've done a few multiplications, so detect when there are tiny residuals that may throw off the final 01255 // decision 01256 if (fabs(s) < Transform::ERR_LIMIT ) s = 0; 01257 if (fabs(t) < Transform::ERR_LIMIT ) t = 0; 01258 01259 if ( fabs((fabs(s)-1.0)) < Transform::ERR_LIMIT ) s = 1; 01260 if ( fabs((fabs(t)-1.0)) < Transform::ERR_LIMIT ) t = 1; 01261 01262 // cout << "s and t are " << s << " " << t << endl; 01263 01264 // The final decision, if this is true then we've hit the jackpot 01265 if ( s >= 0 && t >= 0 && (s+t) <= 1 ) return true; 01266 else return false; 01267 }
|
|
Definition at line 2136 of file util_sparx.cpp. References circ, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), numr, quadri(), EMAN::EMData::set_size(), x, xim, and y. 02136 { 02137 int nsam = image->get_xsize(); 02138 int nrow = image->get_ysize(); 02139 int nring = numr.size()/3; 02140 int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 02141 EMData* out = new EMData(); 02142 out->set_size(lcirc,1,1); 02143 char mode = (cmode == "F" || cmode == "f") ? 'f' : 'h'; 02144 float *xim = image->get_data(); 02145 float *circ = out->get_data(); 02146 /* alrq(image->get_data(), nsam, nrow, &numr[0], out->get_data(), lcirc, nring, cmode); 02147 return out; 02148 } 02149 void Util::alrq(float *xim, int nsam , int nrow , int *numr, 02150 float *circ, int lcirc, int nring, char mode) 02151 {*/ 02152 /* 02153 c 02154 c purpose: 02155 c 02156 c resmaple to polar coordinates 02157 c 02158 */ 02159 // dimension xim(nsam,nrow),circ(lcirc) 02160 // integer numr(3,nring) 02161 02162 double dfi, dpi; 02163 int ns2, nr2, i, inr, l, nsim, kcirc, lt, j; 02164 float yq, xold, yold, fi, x, y; 02165 02166 ns2 = nsam/2+1; 02167 nr2 = nrow/2+1; 02168 dpi = 2.0*atan(1.0); 02169 02170 for (i=1;i<=nring;i++) { 02171 // radius of the ring 02172 inr = numr(1,i); 02173 yq = static_cast<float>(inr); 02174 l = numr(3,i); 02175 if (mode == 'h' || mode == 'H') lt = l/2; 02176 else lt = l/4; 02177 02178 nsim = lt-1; 02179 dfi = dpi/(nsim+1); 02180 kcirc = numr(2,i); 02181 xold = 0.0f; 02182 yold = static_cast<float>(inr); 02183 circ(kcirc) = quadri(xold+(float)ns2,yold+(float)nr2,nsam,nrow,xim); 02184 xold = static_cast<float>(inr); 02185 yold = 0.0f; 02186 circ(lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02187 02188 if (mode == 'f' || mode == 'F') { 02189 xold = 0.0f; 02190 yold = static_cast<float>(-inr); 02191 circ(lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02192 xold = static_cast<float>(-inr); 02193 yold = 0.0f; 02194 circ(lt+lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02195 } 02196 02197 for (j=1;j<=nsim;j++) { 02198 fi = static_cast<float>(dfi*j); 02199 x = sin(fi)*yq; 02200 y = cos(fi)*yq; 02201 xold = x; 02202 yold = y; 02203 circ(j+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02204 xold = y; 02205 yold = -x; 02206 circ(j+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02207 02208 if (mode == 'f' || mode == 'F') { 02209 xold = -x; 02210 yold = -y; 02211 circ(j+lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02212 xold = -y; 02213 yold = x; 02214 circ(j+lt+lt+lt+kcirc) = quadri(xold+ns2,yold+nr2,nsam,nrow,xim); 02215 } 02216 } 02217 } 02218 return out; 02219 }
|
|
Definition at line 2221 of file util_sparx.cpp. References Assert, circ, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), numr, quadri(), EMAN::EMData::set_size(), x, xim, and y. Referenced by ali2d_ccf_list(), multiref_peaks_ali2d(), multiref_peaks_compress_ali2d(), multiref_polar_ali_2d(), multiref_polar_ali_2d_delta(), multiref_polar_ali_2d_local(), multiref_polar_ali_2d_local_psi(), multiref_polar_ali_2d_nom(), multiref_polar_ali_2d_peaklist(), and multiref_polar_ali_helical(). 02221 { 02222 int nsam = image->get_xsize(); 02223 int nrow = image->get_ysize(); 02224 int nring = numr.size()/3; 02225 int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 02226 EMData* out = new EMData(); 02227 out->set_size(lcirc,1,1); 02228 char mode = (cmode == "F" || cmode == "f") ? 'f' : 'h'; 02229 float *xim = image->get_data(); 02230 float *circ = out->get_data(); 02231 double dpi, dfi; 02232 int it, jt, inr, l, nsim, kcirc, lt; 02233 float xold, yold, fi, x, y; 02234 02235 // cns2 and cnr2 are predefined centers 02236 // no need to set to zero, all elements are defined 02237 dpi = 2*atan(1.0); 02238 for (it=1; it<=nring; it++) { 02239 // radius of the ring 02240 inr = numr(1,it); 02241 02242 // "F" means a full circle interpolation 02243 // "H" means a half circle interpolation 02244 02245 l = numr(3,it); 02246 if ( mode == 'h' || mode == 'H' ) lt = l / 2; 02247 else lt = l / 4; 02248 02249 nsim = lt - 1; 02250 dfi = dpi / (nsim+1); 02251 kcirc = numr(2,it); 02252 xold = 0.0f+cns2; 02253 yold = inr+cnr2; 02254 02255 Assert( kcirc <= lcirc ); 02256 circ(kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on 90 degree 02257 02258 xold = inr+cns2; 02259 yold = 0.0f+cnr2; 02260 Assert( lt+kcirc <= lcirc ); 02261 circ(lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on 0 degree 02262 02263 if ( mode == 'f' || mode == 'F' ) { 02264 xold = 0.0f+cns2; 02265 yold = -inr+cnr2; 02266 Assert( lt+lt+kcirc <= lcirc ); 02267 circ(lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on 270 degree 02268 02269 xold = -inr+cns2; 02270 yold = 0.0f+cnr2; 02271 Assert(lt+lt+lt+kcirc <= lcirc ); 02272 circ(lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on 180 degree 02273 } 02274 02275 for (jt=1; jt<=nsim; jt++) { 02276 fi = static_cast<float>(dfi * jt); 02277 x = sin(fi) * inr; 02278 y = cos(fi) * inr; 02279 02280 xold = x+cns2; 02281 yold = y+cnr2; 02282 02283 Assert( jt+kcirc <= lcirc ); 02284 circ(jt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on the first quadrant 02285 02286 xold = y+cns2; 02287 yold = -x+cnr2; 02288 02289 Assert( jt+lt+kcirc <= lcirc ); 02290 circ(jt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on the fourth quadrant 02291 02292 if ( mode == 'f' || mode == 'F' ) { 02293 xold = -x+cns2; 02294 yold = -y+cnr2; 02295 02296 Assert( jt+lt+lt+kcirc <= lcirc ); 02297 circ(jt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on the third quadrant 02298 02299 xold = -y+cns2; 02300 yold = x+cnr2; 02301 02302 Assert( jt+lt+lt+lt+kcirc <= lcirc ); 02303 circ(jt+lt+lt+lt+kcirc) = quadri(xold,yold,nsam,nrow,xim); // Sampling on the second quadrant 02304 } 02305 } // end for jt 02306 } //end for it 02307 return out; 02308 }
|
|
Definition at line 2504 of file util_sparx.cpp. References circ, EMAN::EMData::get_data(), get_pixel_conv_new(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), numr, nx, ny, EMAN::EMData::set_size(), x, and y. 02504 { 02505 // input image is twice the size of the original image 02506 int nring = numr.size()/3; 02507 int lcirc = numr[3*nring-2]+numr[3*nring-1]-1; 02508 EMData* out = new EMData(); 02509 out->set_size(lcirc,1,1); 02510 char mode = (cmode == "F" || cmode == "f") ? 'f' : 'h'; 02511 float *circ = out->get_data(); 02512 float *fimage = image->get_data(); 02513 int nx = image->get_xsize(); 02514 int ny = image->get_ysize(); 02515 int nz = image->get_zsize(); 02516 double dpi, dfi; 02517 int it, jt, inr, l, nsim, kcirc, lt; 02518 float yq, xold, yold, fi, x, y; 02519 02520 // cns2 and cnr2 are predefined centers 02521 // no need to set to zero, all elements are defined 02522 02523 dpi = 2*atan(1.0); 02524 for (it=1;it<=nring;it++) { 02525 // radius of the ring 02526 inr = numr(1,it); 02527 yq = static_cast<float>(inr); 02528 02529 l = numr(3,it); 02530 if ( mode == 'h' || mode == 'H' ) lt = l / 2; 02531 else lt = l / 4; 02532 02533 nsim = lt - 1; 02534 dfi = dpi / (nsim+1); 02535 kcirc = numr(2,it); 02536 xold = 0.0f; 02537 yold = static_cast<float>(inr); 02538 circ(kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02539 // circ(kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02540 02541 xold = static_cast<float>(inr); 02542 yold = 0.0f; 02543 circ(lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02544 // circ(lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02545 02546 if ( mode == 'f' || mode == 'F' ) { 02547 xold = 0.0f; 02548 yold = static_cast<float>(-inr); 02549 circ(lt+lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02550 // circ(lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02551 02552 xold = static_cast<float>(-inr); 02553 yold = 0.0f; 02554 circ(lt+lt+lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02555 // circ(lt+lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02556 } 02557 02558 for (jt=1;jt<=nsim;jt++) { 02559 fi = static_cast<float>(dfi * jt); 02560 x = sin(fi) * yq; 02561 y = cos(fi) * yq; 02562 02563 xold = x; 02564 yold = y; 02565 circ(jt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02566 // circ(jt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02567 02568 xold = y; 02569 yold = -x; 02570 circ(jt+lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02571 // circ(jt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02572 02573 if ( mode == 'f' || mode == 'F' ) { 02574 xold = -x; 02575 yold = -y; 02576 circ(jt+lt+lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02577 // circ(jt+lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02578 02579 xold = -y; 02580 yold = x; 02581 circ(jt+lt+lt+lt+kcirc) = get_pixel_conv_new(nx,ny,nz,2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,fimage,kb); 02582 // circ(jt+lt+lt+lt+kcirc) = image->get_pixel_conv(2*(xold+cns2-1.0f),2*(yold+cnr2-1.0f),0,kb); 02583 } 02584 } // end for jt 02585 } //end for it 02586 return out; 02587 }
|
|
Definition at line 3125 of file util_sparx.cpp. References b. Referenced by Crosrng_e(), Crosrng_ew(), Crosrng_ms(), Crosrng_ns(), Crosrng_psi_0_180(), and Crosrng_sm_psi(). 03125 { 03126 double c2,c3; 03127 int nhalf; 03128 03129 nhalf = npoint/2 + 1; 03130 *pos = 0.0; 03131 03132 if (npoint == 7) { 03133 c2 = 49.*b(1) + 6.*b(2) - 21.*b(3) - 32.*b(4) - 27.*b(5) 03134 - 6.*b(6) + 31.*b(7); 03135 c3 = 5.*b(1) - 3.*b(3) - 4.*b(4) - 3.*b(5) + 5.*b(7); 03136 } 03137 else if (npoint == 5) { 03138 c2 = (74.*b(1) - 23.*b(2) - 60.*b(3) - 37.*b(4) 03139 + 46.*b(5) ) / (-70.); 03140 c3 = (2.*b(1) - b(2) - 2.*b(3) - b(4) + 2.*b(5) ) / 14.0; 03141 } 03142 else if (npoint == 3) { 03143 c2 = (5.*b(1) - 8.*b(2) + 3.*b(3) ) / (-2.0); 03144 c3 = (b(1) - 2.*b(2) + b(3) ) / 2.0; 03145 } 03146 //else if (npoint == 9) { 03147 else { // at least one has to be true!! 03148 c2 = (1708.*b(1) + 581.*b(2) - 246.*b(3) - 773.*b(4) 03149 - 1000.*b(5) - 927.*b(6) - 554.*b(7) + 119.*b(8) 03150 + 1092.*b(9) ) / (-4620.); 03151 c3 = (28.*b(1) + 7.*b(2) - 8.*b(3) - 17.*b(4) - 20.*b(5) 03152 - 17.*b(6) - 8.*b(7) + 7.*b(8) + 28.*b(9) ) / 924.0; 03153 } 03154 if (c3 != 0.0) *pos = static_cast<float>(c2/(2.0*c3) - nhalf); 03155 }
|
|
Print a 3D integer matrix to a file stream (std out by default).
Definition at line 1118 of file util.cpp. 01118 { 01119 // Note: Don't need to check if 3-D because 3D is part of 01120 // the MIArray3D typedef. 01121 out << "Printing 3D Integer data: " << str << std::endl; 01122 const multi_array_types::size_type* sizes = mat.shape(); 01123 int nx = sizes[0], ny = sizes[1], nz = sizes[2]; 01124 const multi_array_types::index* indices = mat.index_bases(); 01125 int bx = indices[0], by = indices[1], bz = indices[2]; 01126 for (int iz = bz; iz < nz+bz; iz++) { 01127 cout << "(z = " << iz << " slice)" << endl; 01128 for (int ix = bx; ix < nx+bx; ix++) { 01129 for (int iy = by; iy < ny+by; iy++) { 01130 cout << setiosflags(ios::fixed) << setw(5) 01131 << mat[ix][iy][iz] << " "; 01132 } 01133 cout << endl; 01134 } 01135 } 01136 }
|
|
Definition at line 6241 of file util_sparx.cpp. References call_cl1(), log(), q, EMAN::Dict::size(), and x. 06242 { 06243 int k,m,n1,klmd,klm2d,nklmd,n2d,n_larg,l, n2; 06244 06245 k=(int)pw.size(); 06246 l=0; 06247 m=k; 06248 n2=n+2; 06249 n1=n+1; 06250 klmd=k+l+m; 06251 klm2d= k+l+m+2; 06252 nklmd=k+l+m+n; 06253 n2d=n+2; 06254 /*size has to be increased when N is large*/ 06255 n_larg=klmd*2; 06256 klm2d=n_larg+klm2d; 06257 klmd=n_larg+klmd; 06258 nklmd=n_larg+nklmd; 06259 int size_q=klm2d*n2d; 06260 int size_cu=nklmd*2; 06261 static int i__; 06262 06263 double *q ; 06264 double *x ; 06265 double *res; 06266 double *cu; 06267 float *q2; 06268 float *pw_; 06269 long int *iu; 06270 double *s; 06271 q = (double*)calloc(size_q,sizeof(double)); 06272 x = (double*)calloc(n2d,sizeof(double)); 06273 res = (double*)calloc(klmd,sizeof(double)); 06274 cu =(double*)calloc(size_cu,sizeof(double)); 06275 s = (double*)calloc(klmd,sizeof(double)); 06276 q2 = (float*)calloc(size_q,sizeof(float)); 06277 iu = (long int*)calloc(size_cu,sizeof(long int)); 06278 pw_ = (float*)calloc(k,sizeof(float)); 06279 06280 for( i__ =0;i__<k;++i__) 06281 { 06282 pw_[i__]=log(pw[i__]); } 06283 long int l_k=k; 06284 long int l_n=n; 06285 long int l_iswi=iswi; 06286 vector<float> cl1_res; 06287 cl1_res=Util::call_cl1(&l_k, &l_n, &ps, &l_iswi, pw_, q2, q, x, res, cu, s, iu); 06288 free(q); 06289 free(x); 06290 free(res); 06291 free(s); 06292 free(cu); 06293 free(q2); 06294 free(iu); 06295 free(pw_); 06296 return cl1_res; 06297 }
|
|
Quadratic interpolation (2D). Note: This routine starts counting from 1, not 0! This routine uses six image points for interpolation:
f3 fc | | x f2-----f0----f1 | | f4 * f0 - f4 are image values near the interpolated point X. f0 is the interior mesh point nearest x. Coords:
Definition at line 645 of file util_sparx.cpp. References fdata, quadri(), x, and y. Referenced by alrl_ms(), Polar2D(), and Polar2Dm(). 00646 { 00647 // purpose: quadratic interpolation 00648 // Optimized for speed, circular closer removed, checking of ranges removed 00649 float x, y, dx0, dy0, f0, c1, c2, c3, c4, c5, dxb, dyb; 00650 float quadri; 00651 int i, j, ip1, im1, jp1, jm1, ic, jc, hxc, hyc; 00652 00653 x = xx; 00654 y = yy; 00655 00656 // any xx and yy 00657 while ( x < 1.0 ) x += nxdata; 00658 while ( x >= (float)(nxdata+1) ) x -= nxdata; 00659 while ( y < 1.0 ) y += nydata; 00660 while ( y >= (float)(nydata+1) ) y -= nydata; 00661 00662 i = (int) x; 00663 j = (int) y; 00664 00665 dx0 = x - i; 00666 dy0 = y - j; 00667 00668 ip1 = i + 1; 00669 im1 = i - 1; 00670 jp1 = j + 1; 00671 jm1 = j - 1; 00672 00673 if (ip1 > nxdata) ip1 -= nxdata; 00674 if (im1 < 1) im1 += nxdata; 00675 if (jp1 > nydata) jp1 -= nydata; 00676 if (jm1 < 1) jm1 += nydata; 00677 00678 f0 = fdata(i,j); 00679 c1 = fdata(ip1,j) - f0; 00680 c2 = (c1 - f0 + fdata(im1,j)) * 0.5f; 00681 c3 = fdata(i,jp1) - f0; 00682 c4 = (c3 - f0 + fdata(i,jm1)) * 0.5f; 00683 00684 dxb = dx0 - 1; 00685 dyb = dy0 - 1; 00686 00687 // hxc & hyc are either 1 or -1 00688 if (dx0 >= 0) hxc = 1; else hxc = -1; 00689 if (dy0 >= 0) hyc = 1; else hyc = -1; 00690 00691 ic = i + hxc; 00692 jc = j + hyc; 00693 00694 if (ic > nxdata) ic -= nxdata; else if (ic < 1) ic += nxdata; 00695 if (jc > nydata) jc -= nydata; else if (jc < 1) jc += nydata; 00696 00697 c5 = ( (fdata(ic,jc) - f0 - hxc * c1 - (hxc * (hxc - 1.0f)) * c2 00698 - hyc * c3 - (hyc * (hyc - 1.0f)) * c4) * (hxc * hyc)); 00699 00700 00701 quadri = f0 + dx0 * (c1 + dxb * c2 + dy0 * c5) + dy0 * (c3 + dyb * c4); 00702 00703 return quadri; 00704 }
|
|
Quadratic interpolation (2D). This is identical to quadri except the wrap around is not done circulantly. Note: This routine starts counting from 1, not 0! This routine uses six image points for interpolation:
f3 fc | | x f2-----f0----f1 | | f4 * f0 - f4 are image values near the interpolated point X. f0 is the interior mesh point nearest x. Coords:
Definition at line 709 of file util_sparx.cpp. References fdata, quadri(), x, and y. 00710 { 00711 // purpose: quadratic interpolation 00712 // Optimized for speed, circular closer removed, checking of ranges removed 00713 float x, y, dx0, dy0, f0, c1, c2, c3, c4, c5, dxb, dyb; 00714 float quadri; 00715 int i, j, ip1, im1, jp1, jm1, ic, jc, hxc, hyc; 00716 00717 x = xx; 00718 y = yy; 00719 00720 // wrap around is not done circulantly; if (x,y) is not in the image, then x = xnew and y = ynew 00721 if ( (x < 1.0) || ( x >= (float)(nxdata+1) ) || ( y < 1.0 ) || ( y >= (float)(nydata+1) )){ 00722 x = (float)xnew; 00723 y = (float)ynew; 00724 } 00725 00726 00727 i = (int) x; 00728 j = (int) y; 00729 00730 dx0 = x - i; 00731 dy0 = y - j; 00732 00733 ip1 = i + 1; 00734 im1 = i - 1; 00735 jp1 = j + 1; 00736 jm1 = j - 1; 00737 00738 if (ip1 > nxdata) ip1 -= nxdata; 00739 if (im1 < 1) im1 += nxdata; 00740 if (jp1 > nydata) jp1 -= nydata; 00741 if (jm1 < 1) jm1 += nydata; 00742 00743 f0 = fdata(i,j); 00744 c1 = fdata(ip1,j) - f0; 00745 c2 = (c1 - f0 + fdata(im1,j)) * 0.5f; 00746 c3 = fdata(i,jp1) - f0; 00747 c4 = (c3 - f0 + fdata(i,jm1)) * 0.5f; 00748 00749 dxb = dx0 - 1; 00750 dyb = dy0 - 1; 00751 00752 // hxc & hyc are either 1 or -1 00753 if (dx0 >= 0) hxc = 1; else hxc = -1; 00754 if (dy0 >= 0) hyc = 1; else hyc = -1; 00755 00756 ic = i + hxc; 00757 jc = j + hyc; 00758 00759 if (ic > nxdata) ic -= nxdata; else if (ic < 1) ic += nxdata; 00760 if (jc > nydata) jc -= nydata; else if (jc < 1) jc += nydata; 00761 00762 c5 = ( (fdata(ic,jc) - f0 - hxc * c1 - (hxc * (hxc - 1.0f)) * c2 00763 - hyc * c3 - (hyc * (hyc - 1.0f)) * c4) * (hxc * hyc)); 00764 00765 00766 quadri = f0 + dx0 * (c1 + dxb * c2 + dy0 * c5) + dy0 * (c3 + dyb * c4); 00767 00768 return quadri; 00769 }
|
|
list the sorted lengths of the integer lattice sites of a square sided image of size Size. PRB
Definition at line 433 of file util_sparx.cpp. References sort_mat(). 00435 { 00436 int iMax = (int) floor( (Size-1.0)/2 +.01); 00437 int CountMax = (iMax+2)*(iMax+1)/2; 00438 int Count=-1; 00439 float *kVals = new float[CountMax]; 00440 float *weightMat = new float[CountMax]; 00441 int *PermMat = new int[CountMax]; 00442 SizeReturned[0] = CountMax; 00443 00444 // printf("Aa \n"); fflush(stdout); 00445 for (int jkx=0; jkx< iMax+1; jkx++) { 00446 for (int jky=0; jky< jkx+1; jky++) { 00447 Count++; 00448 kVals[Count] = sqrtf((float) (jkx*jkx +jky*jky)); 00449 weightMat[Count]= 1.0; 00450 if (jkx!=0) { weightMat[Count] *=2;} 00451 if (jky!=0) { weightMat[Count] *=2;} 00452 if (jkx!=jky){ weightMat[Count] *=2;} 00453 PermMat[Count]=Count+1; 00454 } 00455 } 00456 00457 int lkVals = Count+1; 00458 // printf("Cc \n");fflush(stdout); 00459 00460 sort_mat(&kVals[0],&kVals[Count], 00461 &PermMat[0], &PermMat[Count]); //PermMat is 00462 //also returned as well as kValsSorted 00463 fflush(stdout); 00464 00465 int newInd; 00466 00467 for (int iP=0; iP < lkVals ; iP++ ) { 00468 newInd = PermMat[iP]; 00469 PermMatTr[newInd-1] = iP+1; 00470 } 00471 00472 // printf("Ee \n"); fflush(stdout); 00473 00474 int CountA=-1; 00475 int CountB=-1; 00476 00477 while (CountB< (CountMax-1)) { 00478 CountA++; 00479 CountB++; 00480 // printf("CountA=%d ; CountB=%d \n", CountA,CountB);fflush(stdout); 00481 kValsSorted[CountA] = kVals[CountB] ; 00482 if (CountB<(CountMax-1) ) { 00483 while (fabs(kVals[CountB] -kVals[CountB+1])<.0000001 ) { 00484 SizeReturned[0]--; 00485 for (int iP=0; iP < lkVals; iP++){ 00486 // printf("iP=%d \n", iP);fflush(stdout); 00487 if (PermMatTr[iP]>CountA+1) { 00488 PermMatTr[iP]--; 00489 } 00490 } 00491 CountB++; 00492 } 00493 } 00494 } 00495 00496 00497 for (int CountD=0; CountD < CountMax; CountD++) { 00498 newInd = PermMatTr[CountD]; 00499 weightofkValsSorted[newInd-1] += weightMat[CountD]; 00500 } 00501 00502 }
|
|
Recreates a n-d image using its compressed 1-D form and the mask.
Definition at line 6072 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(). 06073 { 06074 /******** 06075 ***Exception Handle 06076 *************/ 06077 if(mask == NULL) 06078 throw ImageDimensionException("The mask cannot be an null image"); 06079 06080 /*********** 06081 ***get the size of the mask 06082 **************/ 06083 int nx = mask->get_xsize(),ny = mask->get_ysize(),nz = mask->get_zsize(); 06084 06085 int i,size = nx*ny*nz; /* loop counters */ 06086 /* new image declaration */ 06087 EMData *new_image = new EMData(); 06088 new_image->set_size(nx,ny,nz); /* set the size of new image */ 06089 float *new_ptr = new_image->get_data(); /* set size of the new image */ 06090 float *mask_ptr = mask->get_data(); /* assign a pointer to the mask image */ 06091 float *img_ptr = image->get_data(); /* assign a pointer to the 1D image */ 06092 int count = 0; 06093 float sum_under_mask = 0.0 ; 06094 for(i = 0;i < size;i++){ 06095 if(mask_ptr[i] > 0.5f){ 06096 new_ptr[i] = img_ptr[count]; 06097 sum_under_mask += img_ptr[count]; 06098 count++; 06099 if( count > image->get_xsize() ) { 06100 throw ImageDimensionException("Error: in reconstitute_image_mask, the mask doesn't match the image, it is too large"); 06101 } 06102 } 06103 } 06104 06105 if( count > image->get_xsize() ) { 06106 throw ImageDimensionException("Error: in reconstitute_image_mask, the mask doesn't match the image, it is too small"); 06107 } 06108 06109 float avg_under_mask = sum_under_mask / count; 06110 for(i = 0;i < size;i++) { 06111 if(mask_ptr[i] <= 0.5f) new_ptr[i] = avg_under_mask; 06112 } 06113 new_image->update(); 06114 return new_image; 06115 }
|
|
Definition at line 1041 of file util.cpp. References BPKT::data, BPKT::hdr, BPKT::len, BPKT::oseq, and BPKT::pseq. 01041 { 01042 // struct sockaddr_in sadr = { AF_INET, 9989, INADDR_ANY}; 01043 // int sock=socket(AF_INET,SOCK_DGRAM,0); 01044 // if (bind(sock,&sadr,sizeof(sockaddr_in))) return string(); 01045 01046 if (ByteOrder::is_host_big_endian()) { 01047 printf("No cache mirroring on Big endian machines yet\n"); 01048 return string(); // FIXME: no support for big endian hosts 01049 } 01050 01051 BPKT pkt; 01052 string ret; 01053 vector<char> fill; 01054 int obj=-1; 01055 unsigned int i=0; 01056 // printf ("Listening\n"); 01057 01058 while (1) { 01059 int l = recv(sock,&pkt,1044,0); 01060 if (l<=0) { 01061 if (obj!=-1) printf("Timeout with incomplete obj %d %d/%d\n",obj,i,(int)fill.size()); 01062 return string(); // probably a timeout 01063 } 01064 if (l<20) { 01065 printf("Bad packet from broadcast"); 01066 continue; 01067 } 01068 01069 if (strncmp(pkt.hdr,"EMAN",4)!=0) continue; 01070 01071 // new object coming in 01072 if (obj!=pkt.oseq) { 01073 obj=pkt.oseq; 01074 ret.resize(pkt.len); 01075 fill.resize((pkt.len-1)/1024+1); 01076 for (i=0; i<fill.size(); i++) fill[i]=0; 01077 } 01078 if (obj==-1) printf("Something wierd happened. please report\n"); 01079 01080 // copy the packet into the output buffer 01081 fill[pkt.pseq]=1; 01082 ret.replace(pkt.pseq*1024,l-20,(char *)pkt.data,l-20); 01083 01084 // see if we got everything 01085 for (i=0; i<fill.size(); i++) { 01086 if (fill[i]!=1) break; 01087 } 01088 // printf("\t\t\tObj %d %d/%d \r",obj,i,(int)fill.size()); 01089 fflush(stdout); 01090 01091 if (i==fill.size()) return ret; // Yea ! We got a good packet 01092 } 01093 01094 }
|
|
Remove a filename's extension and return the new filename.
Definition at line 450 of file util.cpp. 00451 { 00452 if (filename == "") { 00453 return ""; 00454 } 00455 00456 char *buf = new char[filename.size()+1]; 00457 strcpy(buf, filename.c_str()); 00458 char *old_ext = strrchr(buf, '.'); 00459 if (old_ext) { 00460 buf[strlen(buf) - strlen(old_ext)] = '\0'; 00461 } 00462 string result = string(buf); 00463 if( buf ) 00464 { 00465 delete [] buf; 00466 buf = 0; 00467 } 00468 return result; 00469 }
|
|
Definition at line 1079 of file util.h. Referenced by get_pixel_conv_new(), and get_pixel_conv_new_background(). 01095 {
|
|
Definition at line 1047 of file util.h. Referenced by multi_align_error_dfunc(), and multi_align_error_func(). |
|
rotate data vertically by ny/2, to make the mrc phase origin compliance with EMAN1 and TNF reader
Definition at line 95 of file util.cpp. References data, nx, ny, and t. 00096 { 00097 if(ny==1 && nz==1) { //1D, do nothing 00098 return; 00099 } 00100 else if(ny!=1 && nz==1) { //2D, rotate vertically by ny/2 00101 size_t i, j, k, l; 00102 float re; 00103 l=ny/2*nx; 00104 for (i=0; i<ny/2; i++) { 00105 for (j=0; j<nx; j++) { 00106 k=j+i*nx; 00107 re=data[k]; 00108 data[k]=data[k+l]; 00109 data[k+l]=re; 00110 } 00111 } 00112 } 00113 else { //3D, in the y,z plane, swaps quadrants I,III and II,IV, this is the 'rotation' in y and z 00114 size_t i, j, k, l, ii, jj; 00115 char * t=(char *)malloc(sizeof(float)*nx); 00116 00117 k=nx*ny*(nz+1)/2; 00118 l=nx*ny*(nz-1)/2; 00119 jj=nx*sizeof(float); 00120 for (j=ii=0; j<nz/2; ++j) { 00121 for (i=0; i<ny; ++i,ii+=nx) { 00122 memcpy(t,data+ii,jj); 00123 if (i<ny/2) { 00124 memcpy(data+ii,data+ii+k,jj); 00125 memcpy(data+ii+k,t,jj); 00126 } 00127 else { 00128 memcpy(data+ii,data+ii+l,jj); 00129 memcpy(data+ii+l,t,jj); 00130 } 00131 } 00132 } 00133 free(t); 00134 } 00135 }
|
|
Get ceiling round of a float number x.
|
|
Get ceiling round of a float number x.
Definition at line 1439 of file util.h. Referenced by EMAN::Util::FakeKaiserBessel::build_I0table(), EMAN::Util::KaiserBessel::build_I0table(), EMAN::Util::sincBlackman::build_sBtable(), EMAN::nnSSNR_ctfReconstructor::finish(), EMAN::nnSSNR_Reconstructor::finish(), get_pixel_conv_new(), get_pixel_conv_new_background(), EMAN::ApplyPolynomialProfileToHelix::process_inplace(), and EMAN::BeamstopProcessor::process_inplace(). |
|
First element of output is total cost of the matches in the output Second element of output is the total number of matches in output So output has 2+(*(output+1))nParts elements.
Definition at line 20162 of file util_sparx.cpp. References k_means_cont_table_(). 20162 { 20163 //cout<<"sanitycheck called\n"; 20164 int total_cost = *output; 20165 int num_matches = *(output+1); 20166 20167 int cost=0; 20168 int* intx; 20169 int intx_size; 20170 int* intx_next(0); 20171 int intx_next_size = 0; 20172 int curclass; 20173 int curclass_size; 20174 //cout<<"cost by match: ["; 20175 for(int i = 0; i < num_matches; i++){ 20176 curclass = *(output+2+ i*nParts); 20177 // check feasibility 20178 if (*(argParts + Indices[curclass]+1) == -5) {cout<<"infeasible match!\n"; return 0;} 20179 *(argParts + Indices[curclass]+1) = -5; 20180 // initialize intx to the number of elements in class curclass of partition 0 of the i-th match 20181 curclass_size = *(dimClasses+curclass)-2; 20182 intx = new int[curclass_size]; 20183 for (int ic = 0; ic < curclass_size; ic++) *(intx+ic) = *(argParts + Indices[curclass]+2+ic); 20184 intx_size = curclass_size; 20185 20186 for (int j=1; j < nParts; j++){ 20187 curclass = *(output+2+ i*nParts+j); 20188 if (*(argParts + Indices[j*K+curclass]+1)==-5){cout<<"infeasible match!\n"; return 0;} 20189 *(argParts + Indices[j*K+curclass]+1)=-5; 20190 // compute the intersection of intx and class curclass of partition j of the i-th match 20191 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); 20192 intx_next = new int[intx_next_size]; 20193 Util::k_means_cont_table_(intx,argParts + Indices[j*K+curclass]+2, intx_next, intx_size, *(dimClasses + j*K+curclass)-2,1); 20194 delete[] intx; 20195 intx=intx_next; 20196 intx_size= intx_next_size; 20197 if (j==nParts-1) delete[] intx_next; 20198 } 20199 20200 if (intx_next_size <= T) {cout << "something wrong with solution!\n"; return 0;} 20201 //cout <<intx_next_size<<","; 20202 cost = cost + intx_next_size; 20203 } 20204 //cout<<"]\n"; 20205 if (cost != total_cost) {cout << "something wrong with solution!\n"; return 0;} 20206 20207 return 1; 20208 20209 }
|
|
Save x, y data into a file. Each line of the file have the format "x1TABy1", where x1 = x0 + dx*i; y1 = y_array[i].
Definition at line 618 of file util.cpp. References Assert, FileAccessException, and NullPointerException. 00620 { 00621 Assert(dx > 0); 00622 Assert(array_size > 0); 00623 Assert(filename != ""); 00624 00625 if (!y_array) { 00626 throw NullPointerException("y array"); 00627 } 00628 00629 FILE *out = fopen(filename.c_str(), "wb"); 00630 if (!out) { 00631 throw FileAccessException(filename); 00632 } 00633 00634 for (size_t i = 0; i < array_size; i++) { 00635 fprintf(out, "%g\t%g\n", x0 + dx * i, y_array[i]); 00636 } 00637 fclose(out); 00638 }
|
|
Save x, y data into a file. Each line of the file have the format "x1TABy1", where x1 = x0 + dx*i; y1 = y_array[i].
Definition at line 599 of file util.cpp. References Assert, and FileAccessException. 00601 { 00602 Assert(dx != 0); 00603 Assert(y_array.size() > 0); 00604 Assert(filename != ""); 00605 00606 FILE *out = fopen(filename.c_str(), "wb"); 00607 if (!out) { 00608 throw FileAccessException(filename); 00609 } 00610 00611 for (size_t i = 0; i < y_array.size(); i++) { 00612 fprintf(out, "%g\t%g\n", x0 + dx * i, y_array[i]); 00613 } 00614 fclose(out); 00615 }
|
|
Save (x y) data array into a file. Each line of the file have the format "x1TABy1", where x1, y1 are elements of x array and y array. The x, y arrays must have the same number of items.
Definition at line 575 of file util.cpp. References Assert, FileAccessException, and LOGERR. Referenced by EMAN::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 }
|
|
Get a filename's basename. For example, the basename of "hello.c" is still "hello.c"; The basename of "/tmp/abc/hello.c" is "hello.c".
Definition at line 471 of file util.cpp. Referenced by EMAN::Log::begin(), EMAN::TestUtil::check_image(), EMAN::TestUtil::dump_emdata(), EMAN::Log::loc(), and EMAN::TestUtil::set_progname(). 00472 { 00473 if (filename == "") { 00474 return ""; 00475 } 00476 00477 char s = '/'; 00478 #ifdef _WIN32 00479 s = '\\'; 00480 #endif 00481 const char * c = strrchr(filename.c_str(), s); 00482 if (!c) { 00483 return filename; 00484 } 00485 else { 00486 c++; 00487 } 00488 return string(c); 00489 }
|
|
return the weight of the largest weighted feasible match, along with the match in the (preallocated) argument curmax. The returned weight has to be gt newT. If there is no such feasible matching, return 0 as *curmax Definition at line 20216 of file util_sparx.cpp. References explore2(), flag, and k_means_cont_table_(). 20216 { 20217 20218 // some temp variables 20219 bool flag = 0; 20220 int nintx; 20221 int* dummy(0); 20222 //int* ret; 20223 int* curbranch = new int[nParts]; 20224 20225 //initialize costlist to all 0 20226 for(int jit= 0; jit< J; jit++) *(costlist+jit) = 0; 20227 20228 20229 for(int a=0; a<K; a++) 20230 { 20231 20232 // check that class a of partition 0 is active and has greater than T elements. If not the case, then skip to the next class 20233 if (*(argParts + Indices[a] + 1) < 1) continue; 20234 if (*(dimClasses + a)-2 <= T) continue; 20235 20236 // 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 20237 20238 for( int i=1; i < nParts; i++){ 20239 flag = 0; // if flag stays 0 then no class in this partition has more than T objects in common with a, which implies no feasible match (> T) with class a of part 0 is possible. 20240 for(int j=0; j < K; j++){ 20241 if (*(argParts + Indices[i*K+j] + 1) < 1) continue; 20242 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); 20243 if (nintx > T) flag=1; 20244 else *(argParts + Indices[i*K+j] + 1) =-4; 20245 } 20246 if (flag==0) {break;} 20247 } 20248 20249 // explore determines J matchs with the largest weight greater than T where class in partition 0 is class a 20250 *curbranch = a; 20251 20252 if (flag > 0) // Each partition has one or more active class 20253 Util::explore2(argParts, Indices, dimClasses, nParts, K, T, argParts+Indices[a]+2, *(dimClasses+a)-2, argParts+Indices[a]+2, 20254 *(dimClasses+a)-2,0, J, matchlist, costlist, curbranch); 20255 20256 // take all the classes marked as -4 and remark it as 1 in preparation for next round 20257 for( int i=1; i < nParts; i++){ 20258 for(int j=0; j < K; j++){ 20259 if (*(argParts + Indices[i*K+j] + 1) == -4) *(argParts + Indices[i*K+j] + 1) =1; 20260 20261 } 20262 } 20263 } 20264 20265 delete[] curbranch; 20266 }
|
|
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 4664 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), img_ptr, nx, and EMAN::EMData::update(). 04665 { 04666 int i; 04667 int nx=img->get_xsize(); 04668 float *img_ptr = img->get_data(); 04669 float *line_ptr = line->get_data(); 04670 for (i=0;i<length;i++) img_ptr[nx*posline + i] = line_ptr[offset + i]; 04671 img->update(); 04672 }
|
|
Set program logging level through command line option "-v N", where N is the level.
Definition at line 1108 of file util.cpp. Referenced by main(). 01109 { 01110 if (argc > 1 && strncmp(argv[1], "-v", 2) == 0) { 01111 char level_str[32]; 01112 strcpy(level_str, argv[1] + 2); 01113 Log::LogLevel log_level = (Log::LogLevel) atoi(level_str); 01114 Log::logger()->set_level(log_level); 01115 } 01116 }
|
|
Set the seed for Randnum class.
Definition at line 678 of file util.cpp. References EMAN::Randnum::set_seed().
|
|
Sign function.
|
|
Definition at line 5358 of file util_sparx.cpp. References colreverse(), and nx. Referenced by cyclicshift(). 05359 { 05360 int nxy = nx*ny; 05361 colreverse(beg, end, nxy); 05362 }
|
|
does a sort as in Matlab. Carries along the Permutation matrix
Definition at line 641 of file util.cpp. Referenced by Radialize(). 00643 { 00644 float *pivot ; int *pivotPerm; 00645 00646 { 00647 float *pLeft = left; int *pLeftPerm = leftPerm; 00648 float *pRight = right; int *pRightPerm = rightPerm; 00649 float scratch = *left; int scratchPerm = *leftPerm; 00650 00651 while (pLeft < pRight) { 00652 while ((*pRight > scratch) && (pLeft < pRight)) { 00653 pRight--; pRightPerm--; 00654 } 00655 if (pLeft != pRight) { 00656 *pLeft = *pRight; *pLeftPerm = *pRightPerm; 00657 pLeft++; pLeftPerm++; 00658 } 00659 while ((*pLeft < scratch) && (pLeft < pRight)) { 00660 pLeft++; pLeftPerm++; 00661 } 00662 if (pLeft != pRight) { 00663 *pRight = *pLeft; *pRightPerm = *pLeftPerm; 00664 pRight--; pRightPerm--; 00665 } 00666 } 00667 *pLeft = scratch; *pLeftPerm = scratchPerm; 00668 pivot = pLeft; pivotPerm= pLeftPerm; 00669 } 00670 if (left < pivot) { 00671 sort_mat(left, pivot - 1,leftPerm,pivotPerm-1); 00672 } 00673 if (right > pivot) { 00674 sort_mat(pivot + 1, right,pivotPerm+1,rightPerm); 00675 } 00676 }
|
|
Given a tabulated function y of x (unordered), and Given the values of the first derivatives at the end points This routine returns an array y2, that contains the second derivatives of the function at the tabulated points. PRB This function is called by splint
Definition at line 372 of file util_sparx.cpp. 00373 { 00374 int i,k; 00375 float p, qn, sig, un, *u; 00376 u = new float[n-1]; 00377 00378 if (yp1 > .99e30){ 00379 y2[0]=u[0]=0.0; 00380 } else { 00381 y2[0]=-.5f; 00382 u[0] =(3.0f/ (x[1] -x[0]))*( (y[1]-y[0])/(x[1]-x[0]) -yp1); 00383 } 00384 00385 for (i=1; i < n-1; i++) { 00386 sig= (x[i] - x[i-1])/(x[i+1] - x[i-1]); 00387 p = sig*y2[i-1] + 2.0f; 00388 y2[i] = (sig-1.0f)/p; 00389 u[i] = (y[i+1] - y[i] )/(x[i+1]-x[i] ) - (y[i] - y[i-1] )/(x[i] -x[i-1]); 00390 u[i] = (6.0f*u[i]/ (x[i+1]-x[i-1]) - sig*u[i-1])/p; 00391 } 00392 00393 if (ypn>.99e30){ 00394 qn=0; un=0; 00395 } else { 00396 qn= .5f; 00397 un= (3.0f/(x[n-1] -x[n-2])) * (ypn - (y[n-1]-y[n-2])/(x[n-1]-x[n-2])); 00398 } 00399 y2[n-1]= (un - qn*u[n-2])/(qn*y2[n-2]+1.0f); 00400 for (k=n-2; k>=0; k--){ 00401 y2[k]=y2[k]*y2[k+1]+u[k]; 00402 } 00403 delete [] u; 00404 }
|
|
Given a tabulated function y of x (n unordered points), and Given the values of the m values xq to be interpolated This routine returns the interpolated array yq, PRB This function is called by splint.
Definition at line 347 of file util_sparx.cpp. References spline(), splint(), x, and y. 00348 { 00349 00350 float x0= x[0]; 00351 float x1= x[1]; 00352 float x2= x[2]; 00353 float y0= y[0]; 00354 float y1= y[1]; 00355 float y2= y[2]; 00356 float yp1 = (y1-y0)/(x1-x0) + (y2-y0)/(x2-x0) - (y2-y1)/(x2-x1) ; 00357 float xn = x[n]; 00358 float xnm1= x[n-1]; 00359 float xnm2= x[n-2]; 00360 float yn = y[n]; 00361 float ynm1= y[n-1]; 00362 float ynm2= y[n-2]; 00363 float ypn= (yn-ynm1)/(xn-xnm1) + (yn-ynm2)/(xn-xnm2) - (ynm1-ynm2)/(xnm1-xnm2) ; 00364 float *y2d = new float[n]; 00365 Util::spline(x,y,n,yp1,ypn,y2d); 00366 Util::splint(x,y,y2d,n,xq,yq,m); //PRB 00367 delete [] y2d; 00368 return; 00369 }
|
|
Given the arrays xa(ordered, ya of length n, which tabulate a function and given the array y2a which is the output of spline and an unordered array xq, this routine returns a cubic-spline interpolated array yq.
Definition at line 407 of file util_sparx.cpp. References b. 00408 { 00409 int klo, khi, k; 00410 float h, b, a; 00411 00412 // klo=0; // can try to put here 00413 for (int j=0; j<m;j++){ 00414 klo=0; 00415 khi=n-1; 00416 while (khi-klo >1) { 00417 k=(khi+klo) >>1; 00418 if (xa[k]>xq[j]){ khi=k;} 00419 else { klo=k;} 00420 } 00421 h=xa[khi]- xa[klo]; 00422 if (h==0.0) printf("Bad XA input to routine SPLINT \n"); 00423 a =(xa[khi]-xq[j])/h; 00424 b=(xq[j]-xa[klo])/h; 00425 yq[j]=a*ya[klo] + b*ya[khi] 00426 + ((a*a*a-a)*y2a[klo] 00427 +(b*b*b-b)*y2a[khi]) *(h*h)/6.0f; 00428 } 00429 // printf("h=%f, a = %f, b=%f, ya[klo]=%f, ya[khi]=%f , yq=%f\n",h, a, b, ya[klo], ya[khi],yq[0]); 00430 }
|
|
Calculate a number's square.
|
|
Calculate a number's square.
|
|
Calculate a number's square.
Definition at line 1561 of file util.h. Referenced by get_stats_cstyle(). |
|
Calcuate (x*x + y*y).
Definition at line 1589 of file util.h. Referenced by get_stats(), and get_stats_cstyle(). |
|
Safe string compare. It compares 's2' with the first N characters of 's1', where N is the length of 's2'.
Definition at line 247 of file util.cpp. References NullPointerException. Referenced by EMAN::TestUtil::dump_emdata(), and main(). 00248 { 00249 if (!s1 || !s2) { 00250 throw NullPointerException("Null string"); 00251 } 00252 00253 if (strncmp(s1, s2, strlen(s2)) == 0) { 00254 return true; 00255 } 00256 00257 return false; 00258 }
|
|
Return a lower case version of the argument string.
Definition at line 241 of file util.cpp. Referenced by EMAN::Transform::detect_problem_keys(), EMAN::Symmetry3D::gen_orientations(), EMAN::Dict::get_ci(), EMAN::Transform::get_params(), EMAN::Transform::get_params_inverse(), EMAN::Transform::get_rotation(), EMAN::Dict::has_key_ci(), and EMAN::Transform::set_rotation(). 00241 {
00242 string ret(s);
00243 std::transform(s.begin(),s.end(),ret.begin(), (int (*)(int) ) std::tolower);
00244 return ret;
00245 }
|
|
Definition at line 4507 of file util_sparx.cpp. References EMAN::EMData::get_data(), numr, PI2, tot, and EMAN::EMData::update(). 04507 { 04508 int nring = numr.size()/3; 04509 float *ave = avep->get_data(); 04510 float *dat = datp->get_data(); 04511 int i, j, numr3i, np; 04512 float arg, cs, si; 04513 int maxrin = numr(3,nring); 04514 if(mirror == 1) { //for mirrored data has to be conjugated 04515 for (i=1; i<=nring; i++) { 04516 numr3i = numr(3,i); 04517 np = numr(2,i)-1; 04518 ave[np] -= dat[np]; 04519 ave[np+1] -= static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) ); 04520 for (j=2; j<numr3i; j=j+2) { 04521 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin ); 04522 cs = cos(arg); 04523 si = sin(arg); 04524 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg)) 04525 ave[np + j] -= dat[np + j]*cs - dat[np + j +1]*si; 04526 ave[np + j +1] += dat[np + j]*si + dat[np + j +1]*cs; 04527 } 04528 } 04529 } else { 04530 for (i=1; i<=nring; i++) { 04531 numr3i = numr(3,i); 04532 np = numr(2,i)-1; 04533 ave[np] -= dat[np]; 04534 ave[np+1] -= static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) ); 04535 for (j=2; j<numr3i; j=j+2) { 04536 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin ); 04537 cs = cos(arg); 04538 si = sin(arg); 04539 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg)) 04540 ave[np + j] -= dat[np + j]*cs - dat[np + j +1]*si; 04541 ave[np + j +1] -= dat[np + j]*si + dat[np + j +1]*cs; 04542 } 04543 } 04544 } 04545 avep->update(); 04546 EXITFUNC; 04547 }
|
|
Definition at line 17553 of file util_sparx.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img_ptr, NullPointerException, nx, ny, and EMAN::EMData::update(). 17554 { 17555 ENTERFUNC; 17556 /* Exception Handle */ 17557 if (!img) { 17558 throw NullPointerException("NULL input image"); 17559 } 17560 /* ========= img -= img1 ===================== */ 17561 17562 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17563 int size = nx*ny*nz; 17564 float *img_ptr = img->get_data(); 17565 float *img1_ptr = img1->get_data(); 17566 for (int i=0;i<size;i++) img_ptr[i] -= img1_ptr[i]; 17567 img->update(); 17568 17569 EXITFUNC; 17570 }
|
|
Definition at line 17335 of file util_sparx.cpp. References EMAN::EMData::copy_head(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), img2_ptr, img_ptr, EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), NullPointerException, nx, ny, EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), and EMAN::EMData::update(). 17336 { 17337 ENTERFUNC; 17338 /* Exception Handle */ 17339 if (!img) { 17340 throw NullPointerException("NULL input image"); 17341 } 17342 /* ============== output = img - img1 ================ */ 17343 17344 int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize(); 17345 int size = nx*ny*nz; 17346 EMData * img2 = img->copy_head(); 17347 float *img_ptr =img->get_data(); 17348 float *img2_ptr = img2->get_data(); 17349 float *img1_ptr = img1->get_data(); 17350 for (int i=0;i<size;i++) img2_ptr[i] = img_ptr[i] - img1_ptr[i]; 17351 img2->update(); 17352 if(img->is_complex()) { 17353 img2->set_complex(true); 17354 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false); 17355 } 17356 17357 EXITFUNC; 17358 return img2; 17359 }
|
|
Perform singular value decomposition on a set of images.
Definition at line 288 of file util.cpp. References data, get_value_at(), EMAN::EMData::set_value_at(), V, x, X, and y. Referenced by EMAN::PCA::dopca(). 00288 { 00289 int nimg=data.size(); 00290 if (nvec==0) nvec=nimg; 00291 vector<EMData *> ret(nvec); 00292 if (nimg==0) return ret; 00293 int pixels=data[0]->get_xsize()*data[0]->get_ysize()*data[0]->get_zsize(); 00294 00295 // Allocate the working space 00296 gsl_vector *work=gsl_vector_alloc(nimg); 00297 gsl_vector *S=gsl_vector_alloc(nimg); 00298 gsl_matrix *A=gsl_matrix_alloc(pixels,nimg); 00299 gsl_matrix *V=gsl_matrix_alloc(nimg,nimg); 00300 gsl_matrix *X=gsl_matrix_alloc(nimg,nimg); 00301 00302 int im,x,y,z,i; 00303 for (im=0; im<nimg; im++) { 00304 for (z=0,i=0; z<data[0]->get_zsize(); z++) { 00305 for (y=0; y<data[0]->get_ysize(); y++) { 00306 for (x=0; x<data[0]->get_xsize(); x++,i++) { 00307 gsl_matrix_set(A,i,im,data[im]->get_value_at(x,y,z)); 00308 } 00309 } 00310 } 00311 } 00312 00313 // This calculates the SVD 00314 gsl_linalg_SV_decomp_mod (A,X, V, S, work); 00315 00316 for (im=0; im<nvec; im++) { 00317 EMData *a=data[0]->copy_head(); 00318 ret[im]=a; 00319 for (z=0,i=0; z<data[0]->get_zsize(); z++) { 00320 for (y=0; y<data[0]->get_ysize(); y++) { 00321 for (x=0; x<data[0]->get_xsize(); x++,i++) { 00322 a->set_value_at(x,y,z,static_cast<float>(gsl_matrix_get(A,i,im))); 00323 } 00324 } 00325 } 00326 } 00327 return ret; 00328 }
|
|
Definition at line 6020 of file util_sparx.cpp. References phase(), and sqrt(). 06021 { 06022 float cst = cs*1.0e7f; 06023 06024 wgh /= 100.0; 06025 float phase = atan(wgh/sqrt(1.0f-wgh*wgh)); 06026 float lambda=12.398f/sqrt(voltage*(1022.0f+voltage)); 06027 float ak2 = ak*ak; 06028 float g1 = dzz*1.0e4f*lambda*ak2; 06029 float g2 = cst*lambda*lambda*lambda*ak2*ak2/2.0f; 06030 06031 float ctfv = static_cast<float>( sin(M_PI*(g1-g2)+phase)*sign ); 06032 if(b_factor != 0.0f) ctfv *= exp(-b_factor*ak2/4.0f); 06033 06034 return ctfv; 06035 }
|
|
Calculate trilinear interpolation.
Definition at line 1500 of file util.h. Referenced by EMAN::SymSearchProcessor::process_inplace(), EMAN::StandardProjector::project3d(), EMAN::EMData::sget_value_at_interp(), and EMAN::TransformProcessor::transform(). |
|
Quadratic interpolation (3D).
Definition at line 1903 of file util_sparx.cpp. References fdata, R, and triquad(). Referenced by triquad(). 01904 { 01905 01906 const float C2 = 0.5f; //1.0 / 2.0; 01907 const float C4 = 0.25f; //1.0 / 4.0; 01908 const float C8 = 0.125f; //1.0 / 8.0; 01909 01910 float RS = R * S; 01911 float ST = S * T; 01912 float RT = R * T; 01913 float RST = R * ST; 01914 01915 float RSQ = 1-R*R; 01916 float SSQ = 1-S*S; 01917 float TSQ = 1-T*T; 01918 01919 float RM1 = (1-R); 01920 float SM1 = (1-S); 01921 float TM1 = (1-T); 01922 01923 float RP1 = (1+R); 01924 float SP1 = (1+S); 01925 float TP1 = (1+T); 01926 01927 float triquad = 01928 (-C8) * RST * RM1 * SM1 * TM1 * fdata[0] + 01929 ( C4) * ST * RSQ * SM1 * TM1 * fdata[1] + 01930 ( C8) * RST * RP1 * SM1 * TM1 * fdata[2] + 01931 ( C4) * RT * RM1 * SSQ * TM1 * fdata[3] + 01932 (-C2) * T * RSQ * SSQ * TM1 * fdata[4] + 01933 (-C4) * RT * RP1 * SSQ * TM1 * fdata[5] + 01934 ( C8) * RST * RM1 * SP1 * TM1 * fdata[6] + 01935 (-C4) * ST * RSQ * SP1 * TM1 * fdata[7] + 01936 (-C8) * RST * RP1 * SP1 * TM1 * fdata[8] + 01937 // 01938 ( C4) * RS * RM1 * SM1 * TSQ * fdata[9] + 01939 (-C2) * S * RSQ * SM1 * TSQ * fdata[10] + 01940 (-C4) * RS * RP1 * SM1 * TSQ * fdata[11] + 01941 (-C2) * R * RM1 * SSQ * TSQ * fdata[12] + 01942 RSQ * SSQ * TSQ * fdata[13] + 01943 ( C2) * R * RP1 * SSQ * TSQ * fdata[14] + 01944 (-C4) * RS * RM1 * SP1 * TSQ * fdata[15] + 01945 ( C2) * S * RSQ * SP1 * TSQ * fdata[16] + 01946 ( C4) * RS * RP1 * SP1 * TSQ * fdata[17] + 01947 // 01948 ( C8) * RST * RM1 * SM1 * TP1 * fdata[18] + 01949 (-C4) * ST * RSQ * SM1 * TP1 * fdata[19] + 01950 (-C8) * RST * RP1 * SM1 * TP1 * fdata[20] + 01951 (-C4) * RT * RM1 * SSQ * TP1 * fdata[21] + 01952 ( C2) * T * RSQ * SSQ * TP1 * fdata[22] + 01953 ( C4) * RT * RP1 * SSQ * TP1 * fdata[23] + 01954 (-C8) * RST * RM1 * SP1 * TP1 * fdata[24] + 01955 ( C4) * ST * RSQ * SP1 * TP1 * fdata[25] + 01956 ( C8) * RST * RP1 * SP1 * TP1 * fdata[26] ; 01957 return triquad; 01958 }
|
|
Definition at line 7772 of file util_sparx.cpp. References abs, addnod_(), dist(), left_(), x, and y. 07776 { 07777 /* System generated locals */ 07778 int i__1, i__2; 07779 07780 /* Local variables */ 07781 static double d__; 07782 static int i__, j; 07783 static double d1, d2, d3; 07784 static int i0, lp, kt, ku, lpl, nku; 07785 extern long int left_(double *, double *, double *, double 07786 *, double *, double *, double *, double *, 07787 double *); 07788 static int nexti; 07789 extern /* Subroutine */ int addnod_(int *, int *, double *, 07790 double *, double *, int *, int *, int *, 07791 int *, int *); 07792 07793 07794 /* *********************************************************** */ 07795 07796 /* From STRIPACK */ 07797 /* Robert J. Renka */ 07798 /* Dept. of Computer Science */ 07799 /* Univ. of North Texas */ 07800 /* renka@cs.unt.edu */ 07801 /* 01/20/03 */ 07802 07803 /* This is an alternative to TRMESH with the inclusion of */ 07804 /* an efficient means of removing duplicate or nearly dupli- */ 07805 /* cate nodes. */ 07806 07807 /* This subroutine creates a Delaunay triangulation of a */ 07808 /* set of N arbitrarily distributed points, referred to as */ 07809 /* nodes, on the surface of the unit sphere. Refer to Sub- */ 07810 /* routine TRMESH for definitions and a list of additional */ 07811 /* subroutines. This routine is an alternative to TRMESH */ 07812 /* with the inclusion of an efficient means of removing dup- */ 07813 /* licate or nearly duplicate nodes. */ 07814 07815 /* The algorithm has expected time complexity O(N*log(N)) */ 07816 /* for random nodal distributions. */ 07817 07818 07819 /* On input: */ 07820 07821 /* N0 = Number of nodes, possibly including duplicates. */ 07822 /* N0 .GE. 3. */ 07823 07824 /* TOL = Tolerance defining a pair of duplicate nodes: */ 07825 /* bound on the deviation from 1 of the cosine of */ 07826 /* the angle between the nodes. Note that */ 07827 /* |1-cos(A)| is approximately A*A/2. */ 07828 07829 /* The above parameters are not altered by this routine. */ 07830 07831 /* X,Y,Z = Arrays of length at least N0 containing the */ 07832 /* Cartesian coordinates of nodes. (X(K),Y(K), */ 07833 /* Z(K)) is referred to as node K, and K is re- */ 07834 /* ferred to as a nodal index. It is required */ 07835 /* that X(K)**2 + Y(K)**2 + Z(K)**2 = 1 for all */ 07836 /* K. The first three nodes must not be col- */ 07837 /* linear (lie on a common great circle). */ 07838 07839 /* LIST,LPTR = Arrays of length at least 6*N0-12. */ 07840 07841 /* LEND = Array of length at least N0. */ 07842 07843 /* INDX = Array of length at least N0. */ 07844 07845 /* LCNT = Array of length at least N0 (length N is */ 07846 /* sufficient). */ 07847 07848 /* NEAR,NEXT,DIST = Work space arrays of length at */ 07849 /* least N0. The space is used to */ 07850 /* efficiently determine the nearest */ 07851 /* triangulation node to each un- */ 07852 /* processed node for use by ADDNOD. */ 07853 07854 /* On output: */ 07855 07856 /* N = Number of nodes in the triangulation. 3 .LE. N */ 07857 /* .LE. N0, or N = 0 if IER < 0. */ 07858 07859 /* X,Y,Z = Arrays containing the Cartesian coordinates */ 07860 /* of the triangulation nodes in the first N */ 07861 /* locations. The original array elements are */ 07862 /* shifted down as necessary to eliminate dup- */ 07863 /* licate nodes. */ 07864 07865 /* LIST = Set of nodal indexes which, along with LPTR, */ 07866 /* LEND, and LNEW, define the triangulation as a */ 07867 /* set of N adjacency lists -- counterclockwise- */ 07868 /* ordered sequences of neighboring nodes such */ 07869 /* that the first and last neighbors of a bound- */ 07870 /* ary node are boundary nodes (the first neigh- */ 07871 /* bor of an interior node is arbitrary). In */ 07872 /* order to distinguish between interior and */ 07873 /* boundary nodes, the last neighbor of each */ 07874 /* boundary node is represented by the negative */ 07875 /* of its index. */ 07876 07877 /* LPTR = Set of pointers (LIST indexes) in one-to-one */ 07878 /* correspondence with the elements of LIST. */ 07879 /* LIST(LPTR(I)) indexes the node which follows */ 07880 /* LIST(I) in cyclical counterclockwise order */ 07881 /* (the first neighbor follows the last neigh- */ 07882 /* bor). */ 07883 07884 /* LEND = Set of pointers to adjacency lists. LEND(K) */ 07885 /* points to the last neighbor of node K for */ 07886 /* K = 1,...,N. Thus, LIST(LEND(K)) < 0 if and */ 07887 /* only if K is a boundary node. */ 07888 07889 /* LNEW = Pointer to the first empty location in LIST */ 07890 /* and LPTR (list length plus one). LIST, LPTR, */ 07891 /* LEND, and LNEW are not altered if IER < 0, */ 07892 /* and are incomplete if IER > 0. */ 07893 07894 /* INDX = Array of output (triangulation) nodal indexes */ 07895 /* associated with input nodes. For I = 1 to */ 07896 /* N0, INDX(I) is the index (for X, Y, and Z) of */ 07897 /* the triangulation node with the same (or */ 07898 /* nearly the same) coordinates as input node I. */ 07899 07900 /* LCNT = Array of int weights (counts) associated */ 07901 /* with the triangulation nodes. For I = 1 to */ 07902 /* N, LCNT(I) is the number of occurrences of */ 07903 /* node I in the input node set, and thus the */ 07904 /* number of duplicates is LCNT(I)-1. */ 07905 07906 /* NEAR,NEXT,DIST = Garbage. */ 07907 07908 /* IER = Error indicator: */ 07909 /* IER = 0 if no errors were encountered. */ 07910 /* IER = -1 if N0 < 3 on input. */ 07911 /* IER = -2 if the first three nodes are */ 07912 /* collinear. */ 07913 /* IER = -3 if Subroutine ADDNOD returns an error */ 07914 /* flag. This should not occur. */ 07915 07916 /* Modules required by TRMSH3: ADDNOD, BDYADD, COVSPH, */ 07917 /* INSERT, INTADD, JRAND, */ 07918 /* LEFT, LSTPTR, STORE, SWAP, */ 07919 /* SWPTST, TRFIND */ 07920 07921 /* Intrinsic function called by TRMSH3: ABS */ 07922 07923 /* *********************************************************** */ 07924 07925 07926 /* Local parameters: */ 07927 07928 /* D = (Negative cosine of) distance from node KT to */ 07929 /* node I */ 07930 /* D1,D2,D3 = Distances from node KU to nodes 1, 2, and 3, */ 07931 /* respectively */ 07932 /* I,J = Nodal indexes */ 07933 /* I0 = Index of the node preceding I in a sequence of */ 07934 /* unprocessed nodes: I = NEXT(I0) */ 07935 /* KT = Index of a triangulation node */ 07936 /* KU = Index of an unprocessed node and DO-loop index */ 07937 /* LP = LIST index (pointer) of a neighbor of KT */ 07938 /* LPL = Pointer to the last neighbor of KT */ 07939 /* NEXTI = NEXT(I) */ 07940 /* NKU = NEAR(KU) */ 07941 07942 /* Parameter adjustments */ 07943 --dist; 07944 --next; 07945 --near__; 07946 --indx; 07947 --lend; 07948 --z__; 07949 --y; 07950 --x; 07951 --list; 07952 --lptr; 07953 --lcnt; 07954 07955 /* Function Body */ 07956 if (*n0 < 3) { 07957 *n = 0; 07958 *ier = -1; 07959 return 0; 07960 } 07961 07962 /* Store the first triangle in the linked list. */ 07963 07964 if (! left_(&x[1], &y[1], &z__[1], &x[2], &y[2], &z__[2], &x[3], &y[3], & 07965 z__[3])) { 07966 07967 /* The first triangle is (3,2,1) = (2,1,3) = (1,3,2). */ 07968 07969 list[1] = 3; 07970 lptr[1] = 2; 07971 list[2] = -2; 07972 lptr[2] = 1; 07973 lend[1] = 2; 07974 07975 list[3] = 1; 07976 lptr[3] = 4; 07977 list[4] = -3; 07978 lptr[4] = 3; 07979 lend[2] = 4; 07980 07981 list[5] = 2; 07982 lptr[5] = 6; 07983 list[6] = -1; 07984 lptr[6] = 5; 07985 lend[3] = 6; 07986 07987 } else if (! left_(&x[2], &y[2], &z__[2], &x[1], &y[1], &z__[1], &x[3], & 07988 y[3], &z__[3])) { 07989 07990 /* The first triangle is (1,2,3): 3 Strictly Left 1->2, */ 07991 /* i.e., node 3 lies in the left hemisphere defined by */ 07992 /* arc 1->2. */ 07993 07994 list[1] = 2; 07995 lptr[1] = 2; 07996 list[2] = -3; 07997 lptr[2] = 1; 07998 lend[1] = 2; 07999 08000 list[3] = 3; 08001 lptr[3] = 4; 08002 list[4] = -1; 08003 lptr[4] = 3; 08004 lend[2] = 4; 08005 08006 list[5] = 1; 08007 lptr[5] = 6; 08008 list[6] = -2; 08009 lptr[6] = 5; 08010 lend[3] = 6; 08011 08012 08013 } else { 08014 08015 /* The first three nodes are collinear. */ 08016 08017 *n = 0; 08018 *ier = -2; 08019 return 0; 08020 } 08021 08022 //printf("pass check colinear\n"); 08023 08024 /* Initialize LNEW, INDX, and LCNT, and test for N = 3. */ 08025 08026 *lnew = 7; 08027 indx[1] = 1; 08028 indx[2] = 2; 08029 indx[3] = 3; 08030 lcnt[1] = 1; 08031 lcnt[2] = 1; 08032 lcnt[3] = 1; 08033 if (*n0 == 3) { 08034 *n = 3; 08035 *ier = 0; 08036 return 0; 08037 } 08038 08039 /* A nearest-node data structure (NEAR, NEXT, and DIST) is */ 08040 /* used to obtain an expected-time (N*log(N)) incremental */ 08041 /* algorithm by enabling constant search time for locating */ 08042 /* each new node in the triangulation. */ 08043 08044 /* For each unprocessed node KU, NEAR(KU) is the index of the */ 08045 /* triangulation node closest to KU (used as the starting */ 08046 /* point for the search in Subroutine TRFIND) and DIST(KU) */ 08047 /* is an increasing function of the arc length (angular */ 08048 /* distance) between nodes KU and NEAR(KU): -Cos(a) for */ 08049 /* arc length a. */ 08050 08051 /* Since it is necessary to efficiently find the subset of */ 08052 /* unprocessed nodes associated with each triangulation */ 08053 /* node J (those that have J as their NEAR entries), the */ 08054 /* subsets are stored in NEAR and NEXT as follows: for */ 08055 /* each node J in the triangulation, I = NEAR(J) is the */ 08056 /* first unprocessed node in J's set (with I = 0 if the */ 08057 /* set is empty), L = NEXT(I) (if I > 0) is the second, */ 08058 /* NEXT(L) (if L > 0) is the third, etc. The nodes in each */ 08059 /* set are initially ordered by increasing indexes (which */ 08060 /* maximizes efficiency) but that ordering is not main- */ 08061 /* tained as the data structure is updated. */ 08062 08063 /* Initialize the data structure for the single triangle. */ 08064 08065 near__[1] = 0; 08066 near__[2] = 0; 08067 near__[3] = 0; 08068 for (ku = *n0; ku >= 4; --ku) { 08069 d1 = -(x[ku] * x[1] + y[ku] * y[1] + z__[ku] * z__[1]); 08070 d2 = -(x[ku] * x[2] + y[ku] * y[2] + z__[ku] * z__[2]); 08071 d3 = -(x[ku] * x[3] + y[ku] * y[3] + z__[ku] * z__[3]); 08072 if (d1 <= d2 && d1 <= d3) { 08073 near__[ku] = 1; 08074 dist[ku] = d1; 08075 next[ku] = near__[1]; 08076 near__[1] = ku; 08077 } else if (d2 <= d1 && d2 <= d3) { 08078 near__[ku] = 2; 08079 dist[ku] = d2; 08080 next[ku] = near__[2]; 08081 near__[2] = ku; 08082 } else { 08083 near__[ku] = 3; 08084 dist[ku] = d3; 08085 next[ku] = near__[3]; 08086 near__[3] = ku; 08087 } 08088 /* L1: */ 08089 } 08090 08091 /* Loop on unprocessed nodes KU. KT is the number of nodes */ 08092 /* in the triangulation, and NKU = NEAR(KU). */ 08093 08094 kt = 3; 08095 i__1 = *n0; 08096 for (ku = 4; ku <= i__1; ++ku) { 08097 nku = near__[ku]; 08098 08099 /* Remove KU from the set of unprocessed nodes associated */ 08100 /* with NEAR(KU). */ 08101 i__ = nku; 08102 if (near__[i__] == ku) { 08103 near__[i__] = next[ku]; 08104 } else { 08105 i__ = near__[i__]; 08106 L2: 08107 i0 = i__; 08108 i__ = next[i0]; 08109 if (i__ != ku) { 08110 goto L2; 08111 } 08112 next[i0] = next[ku]; 08113 } 08114 near__[ku] = 0; 08115 08116 /* Bypass duplicate nodes. */ 08117 08118 if (dist[ku] <= *tol - 1.) { 08119 indx[ku] = -nku; 08120 ++lcnt[nku]; 08121 goto L6; 08122 } 08123 08124 08125 /* Add a new triangulation node KT with LCNT(KT) = 1. */ 08126 ++kt; 08127 x[kt] = x[ku]; 08128 y[kt] = y[ku]; 08129 z__[kt] = z__[ku]; 08130 indx[ku] = kt; 08131 lcnt[kt] = 1; 08132 addnod_(&nku, &kt, &x[1], &y[1], &z__[1], &list[1], &lptr[1], &lend[1] 08133 , lnew, ier); 08134 if (*ier != 0) { 08135 *n = 0; 08136 *ier = -3; 08137 return 0; 08138 } 08139 08140 /* Loop on neighbors J of node KT. */ 08141 08142 lpl = lend[kt]; 08143 lp = lpl; 08144 L3: 08145 lp = lptr[lp]; 08146 j = (i__2 = list[lp], abs(i__2)); 08147 08148 /* Loop on elements I in the sequence of unprocessed nodes */ 08149 /* associated with J: KT is a candidate for replacing J */ 08150 /* as the nearest triangulation node to I. The next value */ 08151 /* of I in the sequence, NEXT(I), must be saved before I */ 08152 /* is moved because it is altered by adding I to KT's set. */ 08153 08154 i__ = near__[j]; 08155 L4: 08156 if (i__ == 0) { 08157 goto L5; 08158 } 08159 nexti = next[i__]; 08160 08161 /* Test for the distance from I to KT less than the distance */ 08162 /* from I to J. */ 08163 08164 d__ = -(x[i__] * x[kt] + y[i__] * y[kt] + z__[i__] * z__[kt]); 08165 if (d__ < dist[i__]) { 08166 08167 /* Replace J by KT as the nearest triangulation node to I: */ 08168 /* update NEAR(I) and DIST(I), and remove I from J's set */ 08169 /* of unprocessed nodes and add it to KT's set. */ 08170 08171 near__[i__] = kt; 08172 dist[i__] = d__; 08173 if (i__ == near__[j]) { 08174 near__[j] = nexti; 08175 } else { 08176 next[i0] = nexti; 08177 } 08178 next[i__] = near__[kt]; 08179 near__[kt] = i__; 08180 } else { 08181 i0 = i__; 08182 } 08183 08184 /* Bottom of loop on I. */ 08185 08186 i__ = nexti; 08187 goto L4; 08188 08189 /* Bottom of loop on neighbors J. */ 08190 08191 L5: 08192 if (lp != lpl) { 08193 goto L3; 08194 } 08195 L6: 08196 ; 08197 } 08198 *n = kt; 08199 *ier = 0; 08200 return 0; 08201 } /* trmsh3_ */
|
|
Definition at line 18614 of file util_sparx.cpp. References EMAN::EMData::cmp(), dt, EMAN::EMData::rot_scale_trans2D(), setulb_(), SIXTY, and x. 18614 { 18615 18616 EMData *rot; 18617 18618 const int nmax=3, mmax=3; 18619 char task[60], csave[60]; 18620 long int lsave[4]; 18621 long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44]; 18622 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]; 18623 long int SIXTY=60; 18624 18625 // We wish to have no output. 18626 iprint = -1; 18627 18628 //c We specify the tolerances in the stopping criteria. 18629 factr=1.0e1; 18630 pgtol=1.0e-5; 18631 18632 // We specify the dimension n of the sample problem and the number 18633 // m of limited memory corrections stored. (n and m should not 18634 // exceed the limits nmax and mmax respectively.) 18635 n=3; 18636 m=3; 18637 18638 // We now provide nbd which defines the bounds on the variables: 18639 // l specifies the lower bounds, 18640 // u specifies the upper bounds. 18641 // x specifies the initial guess 18642 x[0] = ang; nbd[0] = 2; l[0] = ang-2.0; u[0] = ang+2.0; 18643 x[1] = sxs; nbd[1] = 2; l[1] = sxs-1.5; u[1] = sxs+1.5; 18644 x[2] = sys; nbd[2] = 2; l[2] = sys-1.5; u[2] = sys+1.5; 18645 18646 18647 // We start the iteration by initializing task. 18648 // (**MUST clear remaining chars in task with spaces (else crash)!**) 18649 strcpy(task,"START"); 18650 for (int i=5;i<60;i++) task[i]=' '; 18651 18652 // This is the call to the L-BFGS-B code. 18653 // (* call the L-BFGS-B routine with task='START' once before loop *) 18654 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 18655 //int step = 1; 18656 18657 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *) 18658 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) { 18659 18660 if (strncmp(task,"FG",2)==0) { 18661 // the minimization routine has returned to request the 18662 // function f and gradient g values at the current x 18663 18664 // Compute function value f for the sample problem. 18665 rot = new EMData(); 18666 rot = image->rot_scale_trans2D((float)x[0], (float)x[1], (float)x[2], 1.0f); 18667 f = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 18668 //f = -f; 18669 delete rot; 18670 18671 // Compute gradient g for the sample problem. 18672 float dt = 1.0e-3f; 18673 rot = new EMData(); 18674 rot = image->rot_scale_trans2D((float)x[0]+dt, (float)x[1], (float)x[2], 1.0f); 18675 f1 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 18676 //f1 = -f1; 18677 g[0] = (f1-f)/dt; 18678 delete rot; 18679 18680 dt = 1.0e-2f; 18681 rot = new EMData(); 18682 rot = image->rot_scale_trans2D((float)x[0], (float)x[1]+dt, (float)x[2], 1.0f); 18683 f2 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 18684 //f2 = -f2; 18685 g[1] = (f2-f)/dt; 18686 delete rot; 18687 18688 rot = new EMData(); 18689 rot = image->rot_scale_trans2D((float)x[0], (float)x[1], (float)x[2]+dt, 1.0f); 18690 f3 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 18691 //f3 = -f3; 18692 g[2] = (f3-f)/dt; 18693 delete rot; 18694 } 18695 18696 //c go back to the minimization routine. 18697 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 18698 //step++; 18699 } 18700 18701 //printf("Total step is %d\n", step); 18702 vector<float> res; 18703 res.push_back(static_cast<float>(x[0])); 18704 res.push_back(static_cast<float>(x[1])); 18705 res.push_back(static_cast<float>(x[2])); 18706 //res.push_back(step); 18707 return res; 18708 }
|
|
Definition at line 18710 of file util_sparx.cpp. References EMAN::EMData::cmp(), dt, pi, EMAN::EMData::rot_scale_conv7(), setulb_(), SIXTY, and x. 18710 { 18711 18712 EMData *rot; 18713 18714 const int nmax=3, mmax=3; 18715 char task[60], csave[60]; 18716 long int lsave[4]; 18717 long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44]; 18718 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]; 18719 long int SIXTY=60; 18720 18721 // We wish to have no output. 18722 iprint = -1; 18723 18724 //c We specify the tolerances in the stopping criteria. 18725 factr=1.0e1; 18726 pgtol=1.0e-5; 18727 18728 // We specify the dimension n of the sample problem and the number 18729 // m of limited memory corrections stored. (n and m should not 18730 // exceed the limits nmax and mmax respectively.) 18731 n=3; 18732 m=3; 18733 18734 // We now provide nbd which defines the bounds on the variables: 18735 // l specifies the lower bounds, 18736 // u specifies the upper bounds. 18737 // x specifies the initial guess 18738 x[0] = ang; nbd[0] = 2; l[0] = ang-2.0; u[0] = ang+2.0; 18739 x[1] = sxs; nbd[1] = 2; l[1] = sxs-1.5; u[1] = sxs+1.5; 18740 x[2] = sys; nbd[2] = 2; l[2] = sys-1.5; u[2] = sys+1.5; 18741 18742 18743 // We start the iteration by initializing task. 18744 // (**MUST clear remaining chars in task with spaces (else crash)!**) 18745 strcpy(task,"START"); 18746 for (int i=5;i<60;i++) task[i]=' '; 18747 18748 // This is the call to the L-BFGS-B code. 18749 // (* call the L-BFGS-B routine with task='START' once before loop *) 18750 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 18751 //int step = 1; 18752 18753 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *) 18754 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) { 18755 18756 if (strncmp(task,"FG",2)==0) { 18757 // the minimization routine has returned to request the 18758 // function f and gradient g values at the current x 18759 18760 // Compute function value f for the sample problem. 18761 rot = new EMData(); 18762 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1], (float)x[2], kb, 1.0f); 18763 f = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 18764 //f = -f; 18765 delete rot; 18766 18767 // Compute gradient g for the sample problem. 18768 float dt = 1.0e-3f; 18769 rot = new EMData(); 18770 rot = image->rot_scale_conv7((float)((x[0]+dt)*pi/180), (float)x[1], (float)x[2], kb, 1.0f); 18771 f1 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 18772 //f1 = -f1; 18773 g[0] = (f1-f)/dt; 18774 delete rot; 18775 18776 rot = new EMData(); 18777 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1]+dt, (float)x[2], kb, 1.0); 18778 f2 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 18779 //f2 = -f2; 18780 g[1] = (f2-f)/dt; 18781 delete rot; 18782 18783 rot = new EMData(); 18784 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1], (float)x[2]+dt, kb, 1.0f); 18785 f3 = rot->cmp("sqeuclidean", refim, Dict("mask", mask)); 18786 //f3 = -f3; 18787 g[2] = (f3-f)/dt; 18788 delete rot; 18789 } 18790 18791 //c go back to the minimization routine. 18792 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 18793 //step++; 18794 } 18795 18796 //printf("Total step is %d\n", step); 18797 vector<float> res; 18798 res.push_back(static_cast<float>(x[0])); 18799 res.push_back(static_cast<float>(x[1])); 18800 res.push_back(static_cast<float>(x[2])); 18801 //res.push_back(step); 18802 return res; 18803 }
|
|
Definition at line 18962 of file util_sparx.cpp. 18962 { 18963 18964 double x[4]; 18965 int n; 18966 int l = 3; 18967 int m = 200; 18968 double e = 1e-9; 18969 double step = 0.01; 18970 float (*my_func)(EMData* , EMData* , EMData* , float , float , float) = ccc_images; 18971 18972 x[1] = ang; 18973 x[2] = sxs; 18974 x[3] = sys; 18975 18976 Steepda(x, step, e, l, m, &n, my_func, image, refim, mask); // Call steepest descent optimization subroutine 18977 //printf("Took %d steps\n", n); 18978 18979 vector<float> res; 18980 res.push_back(static_cast<float>(x[1])); 18981 res.push_back(static_cast<float>(x[2])); 18982 res.push_back(static_cast<float>(x[3])); 18983 res.push_back(static_cast<float>(n)); 18984 return res; 18985 }
|
|
Definition at line 19245 of file util_sparx.cpp. References Steepda_G(), and x. 19245 { 19246 19247 double x[4]; 19248 int n; 19249 int l = 3; 19250 int m = 200; 19251 double e = 1e-9; 19252 double step = 0.001; 19253 float (*my_func)(EMData* , EMData* , EMData* , Util::KaiserBessel&, float , float , float) = ccc_images_G; 19254 19255 x[1] = ang; 19256 x[2] = sxs; 19257 x[3] = sys; 19258 19259 Steepda_G(x, step, e, l, m, &n, my_func, image, refim, mask, kb); // Call steepest descent optimization subroutine 19260 //printf("Took %d steps\n", n); 19261 19262 vector<float> res; 19263 res.push_back(static_cast<float>(x[1])); 19264 res.push_back(static_cast<float>(x[2])); 19265 res.push_back(static_cast<float>(x[3])); 19266 res.push_back(static_cast<float>(n)); 19267 return res; 19268 }
|
|
Definition at line 18805 of file util_sparx.cpp. References EMAN::EMData::center_origin_fft(), EMAN::EMData::cmp(), EMAN::EMData::do_ift_inplace(), dt, EMAN::EMData::extract_plane(), EMAN::EMData::fft_shuffle(), EMAN::EMData::get_ysize(), phi, EMAN::EMData::process_inplace(), proj, setulb_(), SIXTY, theta, EMAN::EMData::window_center(), and x. 18805 { 18806 18807 EMData *proj, *proj2; 18808 18809 const int nmax=5, mmax=5; 18810 char task[60], csave[60]; 18811 long int lsave[4]; 18812 long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44]; 18813 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]; 18814 long int SIXTY=60; 18815 18816 // We wish to have no output. 18817 iprint = -1; 18818 18819 //c We specify the tolerances in the stopping criteria. 18820 factr=1.0e1; 18821 pgtol=1.0e-5; 18822 18823 // We specify the dimension n of the sample problem and the number 18824 // m of limited memory corrections stored. (n and m should not 18825 // exceed the limits nmax and mmax respectively.) 18826 n=5; 18827 m=5; 18828 18829 // We now provide nbd which defines the bounds on the variables: 18830 // l specifies the lower bounds, 18831 // u specifies the upper bounds. 18832 // x specifies the initial guess 18833 x[0] = phi; nbd[0] = 2; l[0] = phi-2.0; u[0] = phi+2.0; 18834 x[1] = theta; nbd[1] = 2; l[1] = theta-2.0; u[1] = theta+2.0; 18835 x[2] = psi; nbd[2] = 2; l[2] = psi-2.0; u[2] = psi+2.0; 18836 x[3] = sxs; nbd[3] = 2; l[3] = sxs-2.0; u[3] = sxs+2.0; 18837 x[4] = sys; nbd[4] = 2; l[4] = sys-2.0; u[4] = sys+2.0; 18838 18839 18840 // We start the iteration by initializing task. 18841 // (**MUST clear remaining chars in task with spaces (else crash)!**) 18842 strcpy(task,"START"); 18843 for (int i=5;i<60;i++) task[i]=' '; 18844 18845 // This is the call to the L-BFGS-B code. 18846 // (* call the L-BFGS-B routine with task='START' once before loop *) 18847 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 18848 int step = 1; 18849 18850 // (* while routine returns "FG" or "NEW_X" in task, keep calling it *) 18851 while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) { 18852 18853 if (strncmp(task,"FG",2)==0) { 18854 // the minimization routine has returned to request the 18855 // function f and gradient g values at the current x 18856 18857 // Compute function value f for the sample problem. 18858 proj = new EMData(); 18859 proj2 = new EMData(); 18860 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb); 18861 proj->fft_shuffle(); 18862 proj->center_origin_fft(); 18863 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f)); 18864 proj->do_ift_inplace(); 18865 int M = proj->get_ysize()/2; 18866 proj2 = proj->window_center(M); 18867 f = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 18868 //f = -f; 18869 delete proj; 18870 delete proj2; 18871 18872 // Compute gradient g for the sample problem. 18873 float dt = 1.0e-3f; 18874 proj = new EMData(); 18875 proj2 = new EMData(); 18876 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0]+dt, "theta", (float)x[1], "psi", (float)x[2])), kb); 18877 proj->fft_shuffle(); 18878 proj->center_origin_fft(); 18879 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f)); 18880 proj->do_ift_inplace(); 18881 proj2 = proj->window_center(M); 18882 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 18883 //ft = -ft; 18884 delete proj; 18885 delete proj2; 18886 g[0] = (ft-f)/dt; 18887 18888 proj = new EMData(); 18889 proj2 = new EMData(); 18890 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1]+dt, "psi", (float)x[2])), kb); 18891 proj->fft_shuffle(); 18892 proj->center_origin_fft(); 18893 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f)); 18894 proj->do_ift_inplace(); 18895 proj2 = proj->window_center(M); 18896 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 18897 //ft = -ft; 18898 delete proj; 18899 delete proj2; 18900 g[1] = (ft-f)/dt; 18901 18902 proj = new EMData(); 18903 proj2 = new EMData(); 18904 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2]+dt)), kb); 18905 proj->fft_shuffle(); 18906 proj->center_origin_fft(); 18907 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f)); 18908 proj->do_ift_inplace(); 18909 proj2 = proj->window_center(M); 18910 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 18911 //ft = -ft; 18912 delete proj; 18913 delete proj2; 18914 g[2] = (ft-f)/dt; 18915 18916 proj = new EMData(); 18917 proj2 = new EMData(); 18918 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb); 18919 proj->fft_shuffle(); 18920 proj->center_origin_fft(); 18921 proj->process_inplace("filter.shift", Dict("x_shift", x[3]+dt, "y_shift", x[4], "z_shift", 0.0f)); 18922 proj->do_ift_inplace(); 18923 proj2 = proj->window_center(M); 18924 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 18925 //ft = -ft; 18926 delete proj; 18927 delete proj2; 18928 g[3] = (ft-f)/dt; 18929 18930 proj = new EMData(); 18931 proj2 = new EMData(); 18932 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb); 18933 proj->fft_shuffle(); 18934 proj->center_origin_fft(); 18935 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4]+dt, "z_shift", 0.0f)); 18936 proj->do_ift_inplace(); 18937 proj2 = proj->window_center(M); 18938 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask)); 18939 //ft = -ft; 18940 delete proj; 18941 delete proj2; 18942 g[4] = (ft-f)/dt; 18943 } 18944 18945 //c go back to the minimization routine. 18946 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY); 18947 step++; 18948 } 18949 18950 //printf("Total step is %d\n", step); 18951 vector<float> res; 18952 res.push_back(static_cast<float>(x[0])); 18953 res.push_back(static_cast<float>(x[1])); 18954 res.push_back(static_cast<float>(x[2])); 18955 res.push_back(static_cast<float>(x[3])); 18956 res.push_back(static_cast<float>(x[4])); 18957 //res.push_back(step); 18958 return res; 18959 }
|
|
Creates a Two D Test Pattern.
Definition at line 234 of file util_sparx.cpp. References b, C, flag, pi, q, real2FH(), set_complex(), EMAN::EMData::set_complex(), EMAN::EMData::set_fftodd(), set_ri(), EMAN::EMData::set_ri(), EMAN::EMData::set_shuffled(), EMAN::EMData::set_size(), sqrt(), EMAN::EMData::to_zero(), update(), EMAN::EMData::update(), x, and y. 00235 { 00236 ENTERFUNC; 00237 int Mid= (Size+1)/2; 00238 00239 if (flag==0) { // This is the real function 00240 EMData* ImBW = new EMData(); 00241 ImBW->set_size(Size,Size,1); 00242 ImBW->to_zero(); 00243 00244 float tempIm; 00245 float x,y; 00246 00247 for (int ix=(1-Mid); ix<Mid; ix++){ 00248 for (int iy=(1-Mid); iy<Mid; iy++){ 00249 x = (float)ix; 00250 y = (float)iy; 00251 tempIm= static_cast<float>( (1/(2*M_PI)) * cos(p*x)* cos(q*y) * exp(-.5*x*x/(a*a))* exp(-.5*y*y/(b*b)) ); 00252 (*ImBW)(ix+Mid-1,iy+Mid-1) = tempIm * exp(.5f*p*p*a*a)* exp(.5f*q*q*b*b); 00253 } 00254 } 00255 ImBW->update(); 00256 ImBW->set_complex(false); 00257 ImBW->set_ri(true); 00258 00259 return ImBW; 00260 } 00261 else if (flag==1) { // This is the Fourier Transform 00262 EMData* ImBWFFT = new EMData(); 00263 ImBWFFT ->set_size(2*Size,Size,1); 00264 ImBWFFT ->to_zero(); 00265 00266 float r,s; 00267 00268 for (int ir=(1-Mid); ir<Mid; ir++){ 00269 for (int is=(1-Mid); is<Mid; is++){ 00270 r = (float)ir; 00271 s = (float)is; 00272 (*ImBWFFT)(2*(ir+Mid-1),is+Mid-1)= cosh(p*r*a*a) * cosh(q*s*b*b) * 00273 exp(-.5f*r*r*a*a)* exp(-.5f*s*s*b*b); 00274 } 00275 } 00276 ImBWFFT->update(); 00277 ImBWFFT->set_complex(true); 00278 ImBWFFT->set_ri(true); 00279 ImBWFFT->set_shuffled(true); 00280 ImBWFFT->set_fftodd(true); 00281 00282 return ImBWFFT; 00283 } 00284 else if (flag==2 || flag==3) { // This is the projection in Real Space 00285 float alpha = static_cast<float>( alphaDeg*M_PI/180.0 ); 00286 float C=cos(alpha); 00287 float S=sin(alpha); 00288 float D= sqrt(S*S*b*b + C*C*a*a); 00289 //float D2 = D*D; PAP - to get rid of warning 00290 00291 float P = p * C *a*a/D ; 00292 float Q = q * S *b*b/D ; 00293 00294 if (flag==2) { 00295 EMData* pofalpha = new EMData(); 00296 pofalpha ->set_size(Size,1,1); 00297 pofalpha ->to_zero(); 00298 00299 float Norm0 = D*(float)sqrt(2*pi); 00300 float Norm1 = exp( .5f*(P+Q)*(P+Q)) / Norm0 ; 00301 float Norm2 = exp( .5f*(P-Q)*(P-Q)) / Norm0 ; 00302 float sD; 00303 00304 for (int is=(1-Mid); is<Mid; is++){ 00305 sD = is/D ; 00306 (*pofalpha)(is+Mid-1) = Norm1 * exp(-.5f*sD*sD)*cos(sD*(P+Q)) 00307 + Norm2 * exp(-.5f*sD*sD)*cos(sD*(P-Q)); 00308 } 00309 pofalpha-> update(); 00310 pofalpha-> set_complex(false); 00311 pofalpha-> set_ri(true); 00312 00313 return pofalpha; 00314 } 00315 if (flag==3) { // This is the projection in Fourier Space 00316 float vD; 00317 00318 EMData* pofalphak = new EMData(); 00319 pofalphak ->set_size(2*Size,1,1); 00320 pofalphak ->to_zero(); 00321 00322 for (int iv=(1-Mid); iv<Mid; iv++){ 00323 vD = iv*D ; 00324 (*pofalphak)(2*(iv+Mid-1)) = exp(-.5f*vD*vD)*(cosh(vD*(P+Q)) + cosh(vD*(P-Q)) ); 00325 } 00326 pofalphak-> update(); 00327 pofalphak-> set_complex(false); 00328 pofalphak-> set_ri(true); 00329 00330 return pofalphak; 00331 } 00332 } 00333 else if (flag==4) { 00334 cout <<" FH under construction"; 00335 EMData* OutFT= TwoDTestFunc(Size, p, q, a, b, 1); 00336 EMData* TryFH= OutFT -> real2FH(4.0); 00337 return TryFH; 00338 } else { 00339 cout <<" flag must be 0,1,2,3, or 4"; 00340 } 00341 00342 EXITFUNC; 00343 return 0; 00344 }
|
|
Definition at line 4465 of file util_sparx.cpp. References EMAN::EMData::get_data(), numr, PI2, tot, and EMAN::EMData::update(). 04465 { 04466 int nring = numr.size()/3; 04467 float *ave = avep->get_data(); 04468 float *dat = datp->get_data(); 04469 int i, j, numr3i, np; 04470 float arg, cs, si; 04471 int maxrin = numr(3,nring); 04472 if(mirror == 1) { //for mirrored data has to be conjugated 04473 for (i=1; i<=nring; i++) { 04474 numr3i = numr(3,i); 04475 np = numr(2,i)-1; 04476 ave[np] += dat[np]; 04477 ave[np+1] += static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) ); 04478 for (j=2; j<numr3i; j=j+2) { 04479 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin ); 04480 cs = cos(arg); 04481 si = sin(arg); 04482 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg)) 04483 ave[np + j] += dat[np + j]*cs - dat[np + j +1]*si; 04484 ave[np + j +1] -= dat[np + j]*si + dat[np + j +1]*cs; 04485 } 04486 } 04487 } else { 04488 for (i=1; i<=nring; i++) { 04489 numr3i = numr(3,i); 04490 np = numr(2,i)-1; 04491 ave[np] += dat[np]; 04492 ave[np+1] += static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) ); 04493 for (j=2; j<numr3i; j=j+2) { 04494 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin ); 04495 cs = cos(arg); 04496 si = sin(arg); 04497 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg)) 04498 ave[np + j] += dat[np + j]*cs - dat[np + j +1]*si; 04499 ave[np + j +1] += dat[np + j]*si + dat[np + j +1]*cs; 04500 } 04501 } 04502 } 04503 avep->update(); 04504 EXITFUNC; 04505 }
|
|
Definition at line 1040 of file util.h. Referenced by multi_align_error_func(). |
|
Definition at line 19966 of file util_sparx.cpp. References data, dm, EMAN::EMData::get_ysize(), and ny. 19966 { 19967 const float step=0.001f; 19968 int ny = d->get_ysize(); 19969 // input emdata should have size 2xN, where N is number of points 19970 // output vector should be 2xN, first element is the number of elements 19971 // associated with this point, second is 0 is the element is touching the border, 1 if it is interior 19972 vector<float> group(2*ny); 19973 for(int i=0; i<2*ny; i++) group[i] = 0.0f; 19974 int K = int(1.0f/step) +1; 19975 int hit = 0; 19976 for(int kx=0; kx<=K; kx++) { 19977 float tx = kx*step; 19978 for(int ky=0; ky<=K; ky++) { 19979 float ty = ky*step; 19980 float dm = 1.0e23f; 19981 for(int i=0; i<ny; i++) { 19982 float qd = pow(tx-(*d)(0,i),2) + pow(ty-(*d)(1,i),2); 19983 if( qd < dm) { 19984 dm = qd; 19985 hit = i; 19986 } 19987 } 19988 data(0,hit) += 1.0f; 19989 if(kx == 0 || ky == 0 || kx == K || ky == K) data(1,hit) = 1.0f; 19990 } 19991 } 19992 return group; 19993 }
|
|
Definition at line 7482 of file util_sparx.cpp. References ang_to_xyz(), areav_(), Assert, disorder2(), flip23(), key, phi, status, theta, trmsh3_(), weight, x, and y. 07483 { 07484 07485 ENTERFUNC; 07486 07487 int *list, *lptr, *lend, *iwk, *key,*lcnt,*indx,*good; 07488 int nt6, n, ier, nout, lnew, mdup, nd; 07489 int i,k,mt,status; 07490 07491 07492 double *ds, *x, *y, *z; 07493 double tol = 1.0e-8; 07494 double dtol = 15; 07495 double a; 07496 07497 /*if(last){ 07498 if(medium>nt) n = nt+nt; 07499 else n = nt+nt-medium+1; 07500 } 07501 else{ 07502 n=nt; 07503 }*/ 07504 07505 n = nt + nt; 07506 07507 nt6 = n*6; 07508 07509 list = (int*)calloc(nt6,sizeof(int)); 07510 lptr = (int*)calloc(nt6,sizeof(int)); 07511 lend = (int*)calloc(n ,sizeof(int)); 07512 iwk = (int*)calloc(n ,sizeof(int)); 07513 good = (int*)calloc(n ,sizeof(int)); 07514 key = (int*)calloc(n ,sizeof(int)); 07515 indx = (int*)calloc(n ,sizeof(int)); 07516 lcnt = (int*)calloc(n ,sizeof(int)); 07517 07518 ds = (double*) calloc(n,sizeof(double)); 07519 x = (double*) calloc(n,sizeof(double)); 07520 y = (double*) calloc(n,sizeof(double)); 07521 z = (double*) calloc(n,sizeof(double)); 07522 07523 if (list == NULL || 07524 lptr == NULL || 07525 lend == NULL || 07526 iwk == NULL || 07527 good == NULL || 07528 key == NULL || 07529 indx == NULL || 07530 lcnt == NULL || 07531 x == NULL || 07532 y == NULL || 07533 z == NULL || 07534 ds == NULL) { 07535 printf("memory allocation failure!\n"); 07536 exit(1); 07537 } 07538 07539 bool colinear=true; 07540 while(colinear) 07541 { 07542 07543 L1: 07544 for(i = 0; i<nt; i++){ 07545 x[i] = theta[i]; 07546 y[i] = phi[i]; 07547 x[nt+i] = 180.0 - x[i]; 07548 y[nt+i] = 180.0 + y[i]; 07549 } 07550 07551 Util::disorder2(x, y, key, n); 07552 07553 // check if the first three angles are not close, else shuffle 07554 double val; 07555 for(k=0; k<2; k++){ 07556 for(i=k+1; i<3; i++){ 07557 val = (x[i]-x[k])*(x[i]-x[k]) + (y[i]-y[k])*(y[i]-y[k]); 07558 if( val < dtol) { 07559 goto L1; 07560 } 07561 } 07562 } 07563 07564 Util::ang_to_xyz(x, y, z, n); 07565 07566 // Make sure that first three has no duplication 07567 bool dupnode=true; 07568 dupnode=true; 07569 while(dupnode) 07570 { 07571 for(k=0; k<2; k++){ 07572 for(i=k+1; i<3; i++){ 07573 if( x[i]*x[k]+y[i]*y[k]+z[i]*z[k] > 1.0-tol) { 07574 Util::flip23(x, y, z, key, k, n); 07575 continue; 07576 } 07577 } 07578 } 07579 dupnode = false; 07580 } 07581 07582 07583 ier = 0; 07584 07585 status = Util::trmsh3_(&n,&tol,x,y,z,&nout,list,lptr,lend,&lnew, indx, lcnt, iwk, good, ds, &ier); 07586 07587 if (status != 0) { 07588 printf(" error in trmsh3 \n"); 07589 exit(1); 07590 } 07591 07592 if (ier > 0) { 07593 printf("*** Error in TRMESH: duplicate nodes encountered ***\n"); 07594 exit(1); 07595 } 07596 07597 mdup=n-nout; 07598 if (ier == -2) { 07599 //printf("in TRMESH:the first three nodes are colinear*** disorder again\n"); 07600 } 07601 else 07602 { 07603 colinear=false; 07604 } 07605 } 07606 07607 07608 Assert( ier != -2 ); 07609 // Create a list of unique nodes GOOD, the numbers refer to locations on the full list 07610 // INDX contains node numbers from the squeezed list 07611 nd=0; 07612 for (k=1; k<=n; k++){ 07613 if (indx[k-1]>0) { 07614 nd++; 07615 good[nd-1]=k; 07616 } 07617 } 07618 07619 // 07620 // *** Compute the Voronoi region areas. 07621 // 07622 for(i = 1; i<=nout; i++) { 07623 k=good[i-1]; 07624 // We only need n weights from hemisphere 07625 if (key[k-1] <= nt) { 07626 // CALCULATE THE AREA 07627 a = Util::areav_(&i, &nout, x, y, z, list, lptr, lend, &ier); 07628 if (ier != 0){ 07629 // We set the weight to -1, this will signal the error in the calling 07630 // program, as the area will turn out incorrect 07631 printf(" *** error in areav: ier = %d ***\n", ier); 07632 weight[key[k-1]-1] =-1.0; 07633 } else { 07634 // Assign the weight 07635 weight[key[k-1]-1]=a/lcnt[i-1]; 07636 } 07637 } 07638 } 07639 07640 07641 // Fill out the duplicated weights 07642 for(i = 1; i<=n; i++){ 07643 mt =- indx[i-1]; 07644 if (mt>0){ 07645 k = good[mt-1]; 07646 // This is a duplicated entry, get the already calculated 07647 // weight and assign it. 07648 // We only need n weights from hemisphere 07649 if (key[i-1] <= nt && key[k-1] <= nt) { weight[key[i-1]-1] = weight[key[k-1]-1];} 07650 } 07651 } 07652 07653 free(list); 07654 free(lend); 07655 free(iwk); 07656 free(good); 07657 free(key); 07658 free(lptr); 07659 free(indx); 07660 free(lcnt); 07661 free(ds); 07662 free(x); 07663 free(y); 07664 free(z); 07665 07666 07667 EXITFUNC; 07668 }
|
|
|
|
Definition at line 7059 of file util_sparx.cpp. References hsortd(), ImageFormatException, key, LOGERR, phi, theta, voronoi(), and weight. 07060 { 07061 07062 ENTERFUNC; 07063 07064 if ( th.size() != ph.size() ) { 07065 LOGERR("images not same size"); 07066 throw ImageFormatException( "images not same size"); 07067 } 07068 07069 // rand_seed 07070 srand(10); 07071 07072 int i,*key; 07073 int len = th.size(); 07074 double *theta,*phi,*weight; 07075 theta = (double*) calloc(len,sizeof(double)); 07076 phi = (double*) calloc(len,sizeof(double)); 07077 weight = (double*) calloc(len,sizeof(double)); 07078 key = (int*) calloc(len,sizeof(int)); 07079 const float *thptr, *phptr; 07080 07081 thptr = &th[0]; 07082 phptr = &ph[0]; 07083 for(i=1;i<=len;i++){ 07084 key(i) = i; 07085 weight(i) = 0.0; 07086 } 07087 07088 for(i = 0;i<len;i++){ 07089 theta[i] = thptr[i]; 07090 phi[i] = phptr[i]; 07091 } 07092 07093 // sort by theta 07094 Util::hsortd(theta, phi, key, len, 1); 07095 07096 //Util::voronoidiag(theta,phi, weight, len); 07097 Util::voronoi(phi, theta, weight, len); 07098 07099 //sort by key 07100 Util::hsortd(weight, weight, key, len, 2); 07101 07102 free(theta); 07103 free(phi); 07104 free(key); 07105 vector<double> wt; 07106 double count = 0; 07107 for(i=1; i<= len; i++) 07108 { 07109 wt.push_back(weight(i)); 07110 count += weight(i); 07111 } 07112 07113 //if( abs(count-6.28) > 0.1 ) 07114 //{ 07115 // printf("Warning: SUM OF VORONOI CELLS AREAS IS %lf, should 2*PI\n", count); 07116 //} 07117 07118 free(weight); 07119 07120 EXITFUNC; 07121 return wt; 07122 07123 }
|
|
Definition at line 5217 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(). 05218 { 05219 /* Exception Handle */ 05220 if (!img) throw NullPointerException("NULL input image"); 05221 /* ============================== */ 05222 05223 // Get the size of the input image 05224 int nx=img->get_xsize(), ny=img->get_ysize(), nz=img->get_zsize(); 05225 /* ============================== */ 05226 05227 /* Exception Handle */ 05228 if(new_nx>nx || new_ny>ny || new_nz>nz) 05229 throw ImageDimensionException("The size of the windowed image cannot exceed the input image size."); 05230 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) 05231 throw ImageDimensionException("The offset inconsistent with the input image size."); 05232 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)))) 05233 throw ImageDimensionException("The offset inconsistent with the input image size."); 05234 /* ============================== */ 05235 05236 /* Calculation of the start point */ 05237 int new_st_x = nx/2-new_nx/2 + x_offset, 05238 new_st_y = ny/2-new_ny/2 + y_offset, 05239 new_st_z = nz/2-new_nz/2 + z_offset; 05240 /* ============================== */ 05241 05242 /* Exception Handle */ 05243 if (new_st_x<0 || new_st_y<0 || new_st_z<0) // WHAT HAPPENS WITH THE END POINT CHECK?? PAP 05244 throw ImageDimensionException("The offset inconsistent with the input image size."); 05245 /* ============================== */ 05246 05247 EMData* wind = img->copy_head(); 05248 wind->set_size(new_nx, new_ny, new_nz); 05249 float *outp=wind->get_data(); 05250 float *inp=img->get_data(); 05251 05252 for (int k=0; k<new_nz; k++) 05253 for(int j=0; j<new_ny; j++) 05254 for(int i=0; i<new_nx; i++) 05255 outp(i,j,k) = inp(i,j,k); 05256 wind->update(); 05257 return wind; 05258 }
|
|
Definition at line 5705 of file util_sparx.cpp. References EMAN::EMData::depad(), EMAN::EMData::do_fft_inplace(), EMAN::EMData::do_ift_inplace(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), max, min, EMAN::EMData::norm_pad(), PROJ, q, EMAN::EMData::set_size(), SS, EMAN::EMData::to_zero(), EMAN::EMData::update(), W, and Y. 05706 { 05707 int NSAM,NROW,NNNN,NR2,L,JY,KX,NANG; 05708 float WW,OX,OY; 05709 05710 NSAM = PROJ->get_xsize(); 05711 NROW = PROJ->get_ysize(); 05712 int ntotal = NSAM*NROW; 05713 float q = 2.0f; 05714 float qt = 8.0f/q; 05715 // Fix for padding 2x 05716 int ipad = 1; 05717 NSAM *= ipad; 05718 NROW *= ipad; 05719 NNNN = NSAM+2-(NSAM%2); 05720 int NX2 = NSAM/2; 05721 NR2 = NROW/2; 05722 05723 NANG = int(SS.size())/6; 05724 05725 EMData* W = new EMData(); 05726 int Wnx = NNNN/2; 05727 W->set_size(Wnx,NROW,1); 05728 W->to_zero(); 05729 float *Wptr = W->get_data(); 05730 float *PROJptr = PROJ->get_data(); 05731 for (L=1; L<=NANG; L++) { 05732 float tmp1 = SS(3,K)*SS(4,L)*(SS(1,K)*SS(1,L) + SS(2,K)*SS(2,L)) - SS(3,L)*SS(4,K); 05733 float tmp2 = SS(4,L)*( SS(1,K)*SS(2,L) - SS(1,L)*SS(2,K) ); 05734 OX = SS(6,K)*tmp2 + SS(5,K)*tmp1; 05735 OY = SS(5,K)*tmp2 - SS(6,K)*tmp1; 05736 if(OX < 0.0f) { 05737 OX = -OX; 05738 OY = -OY; 05739 } 05740 05741 if( fabs(OX) > 1.0e-6f || fabs(OY) > 1.0e6f ) { 05742 for(int J=1;J<=NROW;J++) { 05743 JY = (J-1); 05744 if(JY > NR2) JY -= NROW; 05745 #ifdef _WIN32 05746 int xma = _cpp_min(int(0.5f+(q-JY*OY)/OX),NX2); 05747 int xmi = _cpp_max(int((-q-JY*OY)/OX+0.5+NSAM)-NSAM,0); 05748 #else 05749 int xma = std::min(int(0.5f+(q-JY*OY)/OX),NX2); 05750 int xmi = std::max(int((-q-JY*OY)/OX+0.5+NSAM)-NSAM,0); 05751 #endif //_WIN32 05752 if( xmi <= xma) { 05753 for(int I=xmi;I<=xma;I++) { 05754 float Y = fabs(OX*I + OY*JY); 05755 W(I+1,J) += exp(-qt*Y*Y); 05756 //cout << " L "<<L << " I "<<I << " JY "<<JY << " ARG "<<qt*Y*Y <<endl; 05757 } 05758 } 05759 } 05760 } else { 05761 for(int J=1;J<=NROW;J++) for(int I=1;I<=NNNN/2;I++) W(I,J) += 1.0f; 05762 } 05763 } 05764 EMData* proj_in = PROJ; 05765 05766 PROJ = PROJ->norm_pad( false, ipad); 05767 PROJ->do_fft_inplace(); 05768 PROJ->update(); 05769 //cout << " x "<<PROJ->get_xsize() << " y "<<PROJ->get_ysize() <<endl; 05770 PROJptr = PROJ->get_data(); 05771 05772 float WNRMinv,temp; 05773 float osnr = 1.0f/SNR; 05774 WNRMinv = 1.0f/W(1,1); 05775 for(int J=1;J<=NROW;J++) { 05776 JY = J-1; 05777 if( JY > NR2) JY -= NROW; 05778 float sy = JY; 05779 sy /= NROW; 05780 sy *= sy; 05781 for(int I=1;I<=NNNN;I+=2) { 05782 KX = (I+1)/2; 05783 temp = W(KX,J)*WNRMinv; 05784 WW = temp/(temp*temp + osnr); 05785 // This is supposed to fix fall-off due to Gaussian function in the weighting function 05786 float sx = KX-1; 05787 sx /= NSAM; 05788 WW *= exp(qt*(sy + sx*sx)); 05789 PROJ(I,J) *= WW; 05790 PROJ(I+1,J) *= WW; 05791 } 05792 } 05793 delete W; W = 0; 05794 PROJ->do_ift_inplace(); 05795 PROJ->depad(); 05796 05797 float* data_src = PROJ->get_data(); 05798 float* data_dst = proj_in->get_data(); 05799 05800 for( int i=0; i < ntotal; ++i ) data_dst[i] = data_src[i]; 05801 05802 proj_in->update(); 05803 05804 delete PROJ; 05805 }
|
|
Definition at line 5899 of file util_sparx.cpp. References AMAX1, AMIN1, CC, CP, EMAN::EMData::depad(), EMAN::EMData::do_fft_inplace(), EMAN::EMData::do_ift_inplace(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::norm_pad(), PROJ, RI, EMAN::EMData::set_size(), sqrt(), SS, EMAN::EMData::to_one(), EMAN::EMData::update(), VP, VV, and W. 05900 { 05901 float rad2deg =(180.0f/3.1415926f); 05902 float deg2rad = (3.1415926f/180.0f); 05903 05904 int NSAM,NROW,NNNN,NR2,NANG,L,JY; 05905 05906 NSAM = PROJ->get_xsize(); 05907 NROW = PROJ->get_ysize(); 05908 NNNN = NSAM+2-(NSAM%2); 05909 NR2 = NROW/2; 05910 NANG = int(SS.size())/6; 05911 05912 float RI[9]; 05913 RI(1,1)=SS(1,NUMP)*SS(3,NUMP)*SS(5,NUMP)-SS(2,NUMP)*SS(6,NUMP); 05914 RI(2,1)=-SS(1,NUMP)*SS(3,NUMP)*SS(6,NUMP)-SS(2,NUMP)*SS(5,NUMP); 05915 RI(3,1)=SS(1,NUMP)*SS(4,NUMP); 05916 RI(1,2)=SS(2,NUMP)*SS(3,NUMP)*SS(5,NUMP)+SS(1,NUMP)*SS(6,NUMP); 05917 RI(2,2)=-SS(2,NUMP)*SS(3,NUMP)*SS(6,NUMP)+SS(1,NUMP)*SS(5,NUMP); 05918 RI(3,2)=SS(2,NUMP)*SS(4,NUMP); 05919 RI(1,3)=-SS(4,NUMP)*SS(5,NUMP); 05920 RI(2,3)=SS(4,NUMP)*SS(6,NUMP); 05921 RI(3,3)=SS(3,NUMP); 05922 05923 float THICK=static_cast<float>( NSAM)/DIAMETER/2.0f ; 05924 05925 EMData* W = new EMData(); 05926 int Wnx = NNNN/2; 05927 W->set_size(NNNN/2,NROW,1); 05928 W->to_one(); 05929 float *Wptr = W->get_data(); 05930 05931 float ALPHA,TMP,FV,RT,FM,CCN,CC[3],CP[2],VP[2],VV[3]; 05932 05933 for (L=1; L<=NANG; L++) { 05934 if (L != NUMP) { 05935 CC(1)=SS(2,L)*SS(4,L)*SS(3,NUMP)-SS(3,L)*SS(2,NUMP)*SS(4,NUMP); 05936 CC(2)=SS(3,L)*SS(1,NUMP)*SS(4,NUMP)-SS(1,L)*SS(4,L)*SS(3,NUMP); 05937 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); 05938 05939 TMP = sqrt(CC(1)*CC(1) + CC(2)*CC(2) + CC(3)*CC(3)); 05940 CCN=static_cast<float>( AMAX1( AMIN1(TMP,1.0) ,-1.0) ); 05941 ALPHA=rad2deg*float(asin(CCN)); 05942 if (ALPHA>180.0f) ALPHA=ALPHA-180.0f; 05943 if (ALPHA>90.0f) ALPHA=180.0f-ALPHA; 05944 if(ALPHA<1.0E-6) { 05945 for(int J=1;J<=NROW;J++) for(int I=1;I<=NNNN/2;I++) W(I,J)+=1.0; 05946 } else { 05947 FM=THICK/(fabs(sin(ALPHA*deg2rad))); 05948 CC(1) = CC(1)/CCN;CC(2) = CC(2)/CCN;CC(3) = CC(3)/CCN; 05949 VV(1)= SS(2,L)*SS(4,L)*CC(3)-SS(3,L)*CC(2); 05950 VV(2)= SS(3,L)*CC(1)-SS(1,L)*SS(4,L)*CC(3); 05951 VV(3)= SS(1,L)*SS(4,L)*CC(2)-SS(2,L)*SS(4,L)*CC(1); 05952 CP(1) = 0.0;CP(2) = 0.0; 05953 VP(1) = 0.0;VP(2) = 0.0; 05954 05955 CP(1) = CP(1) + RI(1,1)*CC(1) + RI(1,2)*CC(2) + RI(1,3)*CC(3); 05956 CP(2) = CP(2) + RI(2,1)*CC(1) + RI(2,2)*CC(2) + RI(2,3)*CC(3); 05957 VP(1) = VP(1) + RI(1,1)*VV(1) + RI(1,2)*VV(2) + RI(1,3)*VV(3); 05958 VP(2) = VP(2) + RI(2,1)*VV(1) + RI(2,2)*VV(2) + RI(2,3)*VV(3); 05959 05960 TMP = CP(1)*VP(2)-CP(2)*VP(1); 05961 05962 // PREVENT TMP TO BE TOO SMALL, SIGN IS IRRELEVANT 05963 TMP = AMAX1(1.0E-4f,fabs(TMP)); 05964 float tmpinv = 1.0f/TMP; 05965 for(int J=1;J<=NROW;J++) { 05966 JY = (J-1); 05967 if (JY>NR2) JY=JY-NROW; 05968 for(int I=1;I<=NNNN/2;I++) { 05969 FV = fabs((JY*CP(1)-(I-1)*CP(2))*tmpinv); 05970 RT = 1.0f-FV/FM; 05971 W(I,J) += ((RT>0.0f)*RT); 05972 } 05973 } 05974 } 05975 } 05976 } 05977 05978 EMData* proj_in = PROJ; 05979 05980 PROJ = PROJ->norm_pad( false, 1); 05981 PROJ->do_fft_inplace(); 05982 PROJ->update(); 05983 float *PROJptr = PROJ->get_data(); 05984 05985 int KX; 05986 float WW; 05987 for(int J=1; J<=NROW; J++) 05988 for(int I=1; I<=NNNN; I+=2) { 05989 KX = (I+1)/2; 05990 WW = 1.0f/W(KX,J); 05991 PROJ(I,J) = PROJ(I,J)*WW; 05992 PROJ(I+1,J) = PROJ(I+1,J)*WW; 05993 } 05994 delete W; W = 0; 05995 PROJ->do_ift_inplace(); 05996 PROJ->depad(); 05997 05998 float* data_src = PROJ->get_data(); 05999 float* data_dst = proj_in->get_data(); 06000 06001 int ntotal = NSAM*NROW; 06002 for( int i=0; i < ntotal; ++i ) data_dst[i] = data_src[i]; 06003 06004 proj_in->update(); 06005 delete PROJ; 06006 }
|