Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::Util Class Reference
[unit test in Python]

Util is a collection of utility functions. More...

#include <util.h>

List of all members.

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)
EMDataTwoDTestFunc (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).
EMDataPolar2D (EMData *image, vector< int > numr, string mode)
EMDataPolar2Dm (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)
EMDataPolar2Dmi (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_psi_0_180_no_mirror (EMData *circ1, EMData *circ2, vector< int > numr, float psi_max)
Dict Crosrng_ns (EMData *circ1, EMData *circ2, vector< int > numr)
EMDataCrosrng_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
EMDataCrosrng_msg_s (EMData *circ1, EMData *circ2, vector< int > numr)
 This program is half of the Crosrng_msg.
EMDataCrosrng_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).
EMDatadecimate (EMData *img, int x_step, int y_step=1, int z_step=1)
EMDatawindow (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)
EMDatapad (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, size_t 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)
EMDatacompress_image_mask (EMData *image, EMData *mask)
EMDatareconstitute_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)
EMDatamadn_scalar (EMData *img, EMData *img1, float scalar)
EMDatamult_scalar (EMData *img, float scalar)
EMDataaddn_img (EMData *img, EMData *img1)
EMDatasubn_img (EMData *img, EMData *img1)
EMDatamuln_img (EMData *img, EMData *img1)
EMDatadivn_img (EMData *img, EMData *img1)
EMDatadivn_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)
EMDatapack_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< int > assign_groups (const vector< float > &d, int nref, int nima)
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_helical_90 (EMData *image, const vector< EMData * > &crefim, float xrng, float yrng, float step, float psi_max, string mode, vector< int >numr, float cnx, float cny, int ynumber=-1)
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)
EMDatamove_points (EMData *img, float qprob, int ri, int ro)
EMDataget_biggest_cluster (EMData *mg)
EMDatactf_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)
EMDataget_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.
EMDatacalc_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>
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)


Detailed Description

Util is a collection of utility functions.

Definition at line 81 of file util.h.


Member Function Documentation

void Util::add_img EMData img,
EMData img1
[static]
 

Definition at line 17610 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().

17611 {
17612         ENTERFUNC;
17613         /* Exception Handle */
17614         if (!img) {
17615                 throw NullPointerException("NULL input image");
17616         }
17617         /* ========= img += img1 ===================== */
17618 
17619         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17620         size_t size = (size_t)nx*ny*nz;
17621         float *img_ptr  = img->get_data();
17622         float *img1_ptr = img1->get_data();
17623         for (size_t i=0;i<size;++i) img_ptr[i] += img1_ptr[i];
17624         img->update();
17625 
17626         EXITFUNC;
17627 }

void Util::add_img2 EMData img,
EMData img1
[static]
 

Definition at line 17648 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().

17649 {
17650         ENTERFUNC;
17651         /* Exception Handle */
17652         if (!img) {
17653                 throw NullPointerException("NULL input image");
17654         }
17655         /* ========= img += img1**2 ===================== */
17656 
17657         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17658         size_t size = (size_t)nx*ny*nz;
17659         float *img_ptr  = img->get_data();
17660         float *img1_ptr = img1->get_data();
17661         if(img->is_complex()) {
17662                 for (size_t i=0; i<size; i+=2) img_ptr[i] += img1_ptr[i] * img1_ptr[i] + img1_ptr[i+1] * img1_ptr[i+1] ;
17663         } else {
17664                 for (size_t i=0;i<size;++i) img_ptr[i] += img1_ptr[i]*img1_ptr[i];
17665         }
17666         img->update();
17667 
17668         EXITFUNC;
17669 }

void Util::add_img_abs EMData img,
EMData img1
[static]
 

Definition at line 17629 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().

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         size_t size = (size_t)nx*ny*nz;
17640         float *img_ptr  = img->get_data();
17641         float *img1_ptr = img1->get_data();
17642         for (size_t i=0;i<size;++i) img_ptr[i] += abs(img1_ptr[i]);
17643         img->update();
17644 
17645         EXITFUNC;
17646 }

EMData * Util::addn_img EMData img,
EMData img1
[static]
 

Definition at line 17427 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().

17428 {
17429         ENTERFUNC;
17430         /* Exception Handle */
17431         if (!img) {
17432                 throw NullPointerException("NULL input image");
17433         }
17434         /* ==============   output = img + img1   ================ */
17435 
17436         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17437         size_t size = (size_t)nx*ny*nz;
17438         EMData * img2 = img->copy_head();
17439         float *img_ptr  =img->get_data();
17440         float *img2_ptr = img2->get_data();
17441         float *img1_ptr = img1->get_data();
17442         for (size_t i=0;i<size;++i) img2_ptr[i] = img_ptr[i] + img1_ptr[i];
17443         img2->update();
17444         if(img->is_complex()) {
17445                 img2->set_complex(true);
17446                 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false);
17447         }
17448 
17449         EXITFUNC;
17450         return img2;
17451 }

float EMAN::Util::agauss float  a,
float  dx,
float  dy,
float  dz,
float  d
[inline, static]
 

Calculate Gaussian value.

a * exp(-(dx * dx + dy * dy + dz * dz) / d)

Parameters:
[in] a amplitude
[in] dx x center
[in] dy y center
[in] dz z center
[in] d width of gaussian
Returns:
The Gaussian value.

Definition at line 1715 of file util.h.

Referenced by EMAN::GaussFFTProjector::interp_ft_3d().

vector< float > Util::ali2d_ccf_list EMData image,
EMData crefim,
float  xrng,
float  yrng,
float  step,
string  mode,
vector< int >  numr,
float  cnx,
float  cny,
double  T
[static]
 

Determine shift and rotation between image and one reference image (crefim, weights have to be applied) using quadratic interpolation.

Definition at line 18769 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.

18771                                                                            {
18772 
18773         int   maxrin = numr[numr.size()-1];
18774 
18775         int   ky = int(2*yrng/step+0.5)/2;
18776         int   kx = int(2*xrng/step+0.5)/2;
18777 
18778         float *p_ccf1ds = (float *)malloc(maxrin*sizeof(float));
18779         float *p_ccf1dm = (float *)malloc(maxrin*sizeof(float));
18780         int vol = maxrin*(2*kx+1)*(2*ky+1);
18781         vector<ccf_point> ccf(2*vol);
18782         ccf_point temp;
18783 
18784         int index = 0;
18785         for (int i = -ky; i <= ky; i++) {
18786                 float iy = i * step;
18787                 for (int j = -kx; j <= kx; j++) {
18788                         float ix = j*step;
18789                         EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18790                         Frngs(cimage, numr);
18791                         Crosrng_msg_vec(crefim, cimage, numr, p_ccf1ds, p_ccf1dm);
18792                         for (int k=0; k<maxrin; k++) {
18793                                 temp.value = p_ccf1ds[k];
18794                                 temp.i = k;
18795                                 temp.j = j;
18796                                 temp.k = i;
18797                                 temp.mirror = 0;
18798                                 ccf[index] = temp;
18799                                 index++;
18800                                 temp.value = p_ccf1dm[k];
18801                                 temp.mirror = 1;
18802                                 ccf[index] = temp;
18803                                 index++;
18804                         }
18805                         delete cimage; cimage = 0;
18806                 }
18807         }
18808 
18809         delete p_ccf1ds;
18810         delete p_ccf1dm;
18811         std::sort(ccf.begin(), ccf.end(), ccf_value());
18812 
18813         double qt = (double)ccf[0].value;
18814         vector <double> p(2*vol), cp(2*vol);
18815 
18816         double sump = 0.0;
18817         for (int i=0; i<2*vol; i++) {
18818                 p[i] = pow(double(ccf[i].value)/qt, 1.0/T);
18819                 sump += p[i];
18820         }
18821         for (int i=0; i<2*vol; i++) {
18822                 p[i] /= sump;
18823         }
18824         for (int i=1; i<2*vol; i++) {
18825                 p[i] += p[i-1];
18826         }
18827         p[2*vol-1] = 2.0;
18828 
18829         float t = get_frand(0.0f, 1.0f);
18830         int select = 0;
18831         while (p[select] < t)   select += 1;
18832 
18833         vector<float> a(6);
18834         a[0] = ccf[select].value;
18835         a[1] = (float)ccf[select].i;
18836         a[2] = (float)ccf[select].j;
18837         a[3] = (float)ccf[select].k;
18838         a[4] = (float)ccf[select].mirror;
18839         a[5] = (float)select;
18840         return a;
18841 }

void Util::alrl_ms float *  xim,
int  nsam,
int  nrow,
float  cns2,
float  cnr2,
int *  numr,
float *  circ,
int  lcirc,
int  nring,
char  mode
[static]
 

Definition at line 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 }

float Util::ang_n float  peakp,
string  mode,
int  maxrin
[static, private]
 

Definition at line 17857 of file util_sparx.cpp.

Referenced by multiref_polar_ali_2d(), multiref_polar_ali_2d_delta(), multiref_polar_ali_2d_local(), multiref_polar_ali_2d_local_psi(), multiref_polar_ali_2d_nom(), multiref_polar_ali_2d_peaklist(), multiref_polar_ali_helical(), and multiref_polar_ali_helical_90().

17858 {
17859     if (mode == "f" || mode == "F")
17860         return fmodf(((peakp-1.0f) / maxrin+1.0f)*360.0f,360.0f);
17861     else
17862         return fmodf(((peakp-1.0f) / maxrin+1.0f)*180.0f,180.0f);
17863 }

void Util::ang_to_xyz double *  x,
double *  y,
double *  z,
int  len
[static]
 

Definition at line 7803 of file util_sparx.cpp.

References dgr_to_rad, x, and y.

07804 {
07805         ENTERFUNC;
07806         double costheta,sintheta,cosphi,sinphi;
07807         for(int i = 0;  i<len;  i++)
07808         {
07809                 cosphi = cos(y[i]*dgr_to_rad);
07810                 sinphi = sin(y[i]*dgr_to_rad);
07811                 if(fabs(x[i]-90.0)< 1.0e-5){
07812                         x[i] = cosphi;
07813                         y[i] = sinphi;
07814                         z[i] = 0.0;
07815                 }
07816                 else{
07817                         costheta = cos(x[i]*dgr_to_rad);
07818                         sintheta = sin(x[i]*dgr_to_rad);
07819                         x[i] = cosphi*sintheta;
07820                         y[i] = sinphi*sintheta;
07821                         z[i] = costheta;
07822                 }
07823         }
07824         EXITFUNC;
07825 }

float EMAN::Util::angle_err_ri float  r1,
float  i1,
float  r2,
float  i2
[inline, static]
 

Calculate the angular phase difference between two r/i vectors.

Parameters:
[in] r1/i1 first vector, 2 floats
[in] r2/i2 second vector, 2 floats
Returns:
angular difference

Definition at line 1885 of file util.h.

Referenced by EMAN::PhaseCmp::cmp().

float EMAN::Util::angle_sub_2pi float  x,
float  y
[inline, static]
 

Calculate the difference of 2 angles and makes the equivalent result to be less than Pi.

Parameters:
[in] x The first angle.
[in] y The second angle.
Returns:
The difference of 2 angles.

Definition at line 1853 of file util.h.

float EMAN::Util::angle_sub_pi float  x,
float  y
[inline, static]
 

Calculate the difference of 2 angles and makes the equivalent result to be less than Pi/2.

Parameters:
[in] x The first angle.
[in] y The second angle.
Returns:
The difference of 2 angles.

Definition at line 1870 of file util.h.

void Util::ap2ri float *  data,
size_t  n
[static]
 

convert complex data array from Amplitude/Phase format into Real/Imaginary format.

Parameters:
data complex data array.
n array size.

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 }

void EMAN::Util::apply_precision float &  value,
const float &  precision
[inline, static]
 

Definition at line 2108 of file util.h.

Referenced by EMAN::Transform::get_determinant(), EMAN::Transform::get_scale(), EMAN::Transform::get_scale_and_mirror(), EMAN::Transform::get_trans(), EMAN::Transform::is_identity(), and EMAN::Transform::set_scale().

double Util::areav_ int *  k,
int *  n,
double *  x,
double *  y,
double *  z__,
int *  list,
int *  lptr,
int *  lend,
int *  ier
[static]
 

Definition at line 8868 of file util_sparx.cpp.

References areas_(), circum_(), ierr, x, and y.

08871 {
08872     /* Initialized data */
08873 
08874     static double amax = 6.28;
08875 
08876     /* System generated locals */
08877     double ret_val;
08878 
08879     /* Local variables */
08880     static double a, c0[3], c2[3], c3[3];
08881     static int n1, n2, n3;
08882     static double v1[3], v2[3], v3[3];
08883     static int lp, lpl, ierr;
08884     static double asum;
08885     extern double areas_(double *, double *, double *);
08886     static long int first;
08887     extern /* Subroutine */ int circum_(double *, double *,
08888             double *, double *, int *);
08889 
08890 
08891 /* *********************************************************** */
08892 
08893 /*                                            Robert J. Renka */
08894 /*                                  Dept. of Computer Science */
08895 /*                                       Univ. of North Texas */
08896 /*                                           renka@cs.unt.edu */
08897 /*                                                   10/25/02 */
08898 
08899 /*   Given a Delaunay triangulation and the index K of an */
08900 /* interior node, this subroutine returns the (surface) area */
08901 /* of the Voronoi region associated with node K.  The Voronoi */
08902 /* region is the polygon whose vertices are the circumcenters */
08903 /* of the triangles that contain node K, where a triangle */
08904 /* circumcenter is the point (unit vector) lying at the same */
08905 /* angular distance from the three vertices and contained in */
08906 /* the same hemisphere as the vertices. */
08907 
08908 
08909 /* On input: */
08910 
08911 /*       K = Nodal index in the range 1 to N. */
08912 
08913 /*       N = Number of nodes in the triangulation.  N > 3. */
08914 
08915 /*       X,Y,Z = Arrays of length N containing the Cartesian */
08916 /*               coordinates of the nodes (unit vectors). */
08917 
08918 /*       LIST,LPTR,LEND = Data structure defining the trian- */
08919 /*                        gulation.  Refer to Subroutine */
08920 /*                        TRMESH. */
08921 
08922 /* Input parameters are not altered by this function. */
08923 
08924 /* On output: */
08925 
08926 /*       AREAV = Area of Voronoi region K unless IER > 0, */
08927 /*               in which case AREAV = 0. */
08928 
08929 /*       IER = Error indicator: */
08930 /*             IER = 0 if no errors were encountered. */
08931 /*             IER = 1 if K or N is outside its valid range */
08932 /*                     on input. */
08933 /*             IER = 2 if K indexes a boundary node. */
08934 /*             IER = 3 if an error flag is returned by CIRCUM */
08935 /*                     (null triangle). */
08936 /*             IER = 4 if AREAS returns a value greater than */
08937 /*                     AMAX (defined below). */
08938 
08939 /* Modules required by AREAV:  AREAS, CIRCUM */
08940 
08941 /* *********************************************************** */
08942 
08943 
08944 /* Maximum valid triangle area is less than 2*Pi: */
08945 
08946     /* Parameter adjustments */
08947     --lend;
08948     --z__;
08949     --y;
08950     --x;
08951     --list;
08952     --lptr;
08953 
08954     /* Function Body */
08955 
08956 /* Test for invalid input. */
08957 
08958     if (*k < 1 || *k > *n || *n <= 3) {
08959         goto L11;
08960     }
08961 
08962 /* Initialization:  Set N3 to the last neighbor of N1 = K. */
08963 /*   FIRST = TRUE only for the first triangle. */
08964 /*   The Voronoi region area is accumulated in ASUM. */
08965 
08966     n1 = *k;
08967     v1[0] = x[n1];
08968     v1[1] = y[n1];
08969     v1[2] = z__[n1];
08970     lpl = lend[n1];
08971     n3 = list[lpl];
08972     if (n3 < 0) {
08973         goto L12;
08974     }
08975     lp = lpl;
08976     first = TRUE_;
08977     asum = 0.;
08978 
08979 /* Loop on triangles (N1,N2,N3) containing N1 = K. */
08980 
08981 L1:
08982     n2 = n3;
08983     lp = lptr[lp];
08984     n3 = list[lp];
08985     v2[0] = x[n2];
08986     v2[1] = y[n2];
08987     v2[2] = z__[n2];
08988     v3[0] = x[n3];
08989     v3[1] = y[n3];
08990     v3[2] = z__[n3];
08991     if (first) {
08992 
08993 /* First triangle:  compute the circumcenter C3 and save a */
08994 /*   copy in C0. */
08995 
08996         circum_(v1, v2, v3, c3, &ierr);
08997         if (ierr != 0) {
08998             goto L13;
08999         }
09000         c0[0] = c3[0];
09001         c0[1] = c3[1];
09002         c0[2] = c3[2];
09003         first = FALSE_;
09004     } else {
09005 
09006 /* Set C2 to C3, compute the new circumcenter C3, and compute */
09007 /*   the area A of triangle (V1,C2,C3). */
09008 
09009         c2[0] = c3[0];
09010         c2[1] = c3[1];
09011         c2[2] = c3[2];
09012         circum_(v1, v2, v3, c3, &ierr);
09013         if (ierr != 0) {
09014             goto L13;
09015         }
09016         a = areas_(v1, c2, c3);
09017         if (a > amax) {
09018             goto L14;
09019         }
09020         asum += a;
09021     }
09022 
09023 /* Bottom on loop on neighbors of K. */
09024 
09025     if (lp != lpl) {
09026         goto L1;
09027     }
09028 
09029 /* Compute the area of triangle (V1,C3,C0). */
09030 
09031     a = areas_(v1, c3, c0);
09032     if (a > amax) {
09033         goto L14;
09034     }
09035     asum += a;
09036 
09037 /* No error encountered. */
09038 
09039     *ier = 0;
09040     ret_val = asum;
09041     return ret_val;
09042 
09043 /* Invalid input. */
09044 
09045 L11:
09046     *ier = 1;
09047     ret_val = 0.;
09048     return ret_val;
09049 
09050 /* K indexes a boundary node. */
09051 
09052 L12:
09053     *ier = 2;
09054     ret_val = 0.;
09055     return ret_val;
09056 
09057 /* Error in CIRCUM. */
09058 
09059 L13:
09060     *ier = 3;
09061     ret_val = 0.;
09062     return ret_val;
09063 
09064 /* AREAS value larger than AMAX. */
09065 
09066 L14:
09067     *ier = 4;
09068     ret_val = 0.;
09069     return ret_val;
09070 } /* areav_ */

void Util::array_mutation float *  list,
int  len_list,
float  mutation_rate,
float  min_val,
float  max_val,
int  K,
int  is_mirror
[static]
 

The purpose of this function is to convert a list to grey code and mutate them and convert them back.

Definition at line 20350 of file util_sparx.cpp.

References t.

Referenced by image_mutation().

20350                                                                                                                             {
20351 
20352         if (is_mirror != 0) {
20353                 for (int i=0; i<len_list; i++) {
20354                         int r = rand()%10000;
20355                         float f = r/10000.0f;
20356                         if (f < mutation_rate) list[i] = 1-list[i];
20357                 }
20358         } else {
20359                 map<int, vector<int> >  graycode;
20360                 map<vector<int>, int> rev_graycode;
20361                 vector <int> gray;
20362 
20363                 int K=1;
20364                 for (int i=0; i<L; i++) K*=2;
20365 
20366                 for (int k=0; k<K; k++) {
20367                         int shift = 0;
20368                         vector <int> gray;
20369                         for (int i=L-1; i>-1; i--) {
20370                                 int t = ((k>>i)%2-shift)%2;
20371                                 gray.push_back(t);
20372                                 shift += t-2;
20373                         }
20374                         graycode[k] = gray;
20375                         rev_graycode[gray] = k;
20376                 }
20377 
20378                 float gap = (K-1)/(max_val-min_val);
20379                 for (int i=0; i<len_list; i++) {
20380                         float val = list[i];
20381                         if (val < min_val) { val = min_val; }
20382                         else if  (val > max_val) { val = max_val; }
20383                         int k = int((val-min_val)*gap+0.5);
20384                         vector<int> gray = graycode[k];
20385                         bool changed = false;
20386                         for (vector<int>::iterator p=gray.begin(); p!=gray.end(); p++) {
20387                                 int r = rand()%10000;
20388                                 float f = r/10000.0f;
20389                                 if (f < mutation_rate) {
20390                                         *p = 1-*p;
20391                                         changed = true;
20392                                 }
20393                         }
20394                         if (changed) {
20395                                 k = rev_graycode[gray];
20396                                 list[i] = k/gap+min_val;
20397                         }
20398                 }
20399         }
20400 
20401 }

vector< int > Util::assign_groups const vector< float > &  d,
int  nref,
int  nima
[static]
 

Definition at line 18028 of file util_sparx.cpp.

References flag, peak_table::index, and peak_table::value.

18028                                                                           {
18029 
18030         int kt = nref;
18031         unsigned int maxasi = nima/nref;
18032         vector< vector<int> > id_list;
18033         id_list.resize(nref);
18034         int group, ima;
18035 
18036         peak_table* dd = new peak_table[nref*nima];
18037         for (int i=0; i<nref*nima; i++)  {
18038                 dd[i].value = d[i];
18039                 dd[i].index = i;
18040         }
18041         sort(dd, dd+nref*nima);
18042         int begin = 0;
18043 
18044         bool* del_row = new bool[nref];
18045         for (int i=0; i<nref; i++) del_row[i] = false;
18046         bool* del_column = new bool[nima];
18047         for (int i=0; i<nima; i++) del_column[i] = false;
18048         while (kt > 0) {
18049                 bool flag = true;
18050                 while (flag) {
18051                         int l = dd[begin].index;
18052                         group = l/nima;
18053                         ima = l%nima;
18054                         if (del_column[ima] || del_row[group]) begin++;
18055                         else flag = false;
18056                 }
18057 
18058                 id_list[group].push_back(ima);
18059                 if (kt > 1) {
18060                         if (id_list[group].size() < maxasi) group = -1;
18061                         else kt -= 1;
18062                 } else {
18063                         if (id_list[group].size() < maxasi+nima%nref) group = -1;
18064                         else kt -= 1;
18065                 }
18066                 del_column[ima] = true;
18067                 if (group != -1) {
18068                         del_row[group] = true;
18069                 }
18070         }
18071 
18072         vector<int> id_list_1; 
18073         for (int iref=0; iref<nref; iref++)
18074                 for (unsigned int im=0; im<maxasi; im++)
18075                         id_list_1.push_back(id_list[iref][im]);
18076         for (unsigned int im=maxasi; im<maxasi+nima%nref; im++)
18077                         id_list_1.push_back(id_list[group][im]);
18078         id_list_1.push_back(group);
18079 
18080         delete[] del_row;
18081         delete[] del_column;
18082         delete[] dd;
18083         return id_list_1;
18084 }

vector< int > Util::bb_enumerateMPI_ int *  argParts,
int *  dimClasses,
int  nParts,
int  K,
int  T,
int  n_guesses,
int  LARGEST_CLASS,
int  J,
int  max_branching,
float  stmult,
int  branchfunc,
int  LIM
[static]
 

K is the number of classes in each partition (should be the same for all partitions) the first element of each class is its original index in the partition, and second is dummy var MPI: if nTop <= 0, then initial prune is called, and the pruned partitions are returned in a 1D array.

The first element is reserved for max_levels (the size of the smallest partition after pruning). if nTop > 0, then partitions are assumed to have been pruned, where only dummy variables of un-pruned partitions are set to 1, and findTopLargest is called to find the top weighted matches. The matches, where each match is preceded by its cost, is returned in a one dimensional vector.

essentially the same as bb_enumerate but with the option to do mpi version.

Definition at line 20769 of file util_sparx.cpp.

References branchMPI(), initial_prune(), and sanitycheck().

20770                                                           {
20771 
20772         
20773         // 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
20774         // 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
20775         // Make a vector of nParts vectors of K int* each
20776          int* Indices = new int[nParts*K];
20777          int ind_c = 0;
20778          for (int i=0; i < nParts; i++){
20779                  for(int j = 0; j < K; j++){
20780                          Indices[i*K + j] = ind_c;
20781                          ind_c = ind_c + *(dimClasses+i*K + j);
20782 
20783                  }
20784          }
20785 
20786         // do initial pruning on argParts and return the pruned partitions
20787 
20788         // Make a vector of nParts vectors of K int* each
20789         vector <vector <int*> > Parts(nParts,vector<int*>(K));
20790         ind_c = 0;
20791         int argParts_size=0;
20792         for (int i=0; i < nParts; i++){
20793                 for(int j = 0; j < K; j++){
20794                         Parts[i][j]=argParts + ind_c;
20795                         ind_c = ind_c + *(dimClasses+i*K + j);
20796                         argParts_size = argParts_size + *(dimClasses+i*K + j);
20797 
20798                 }
20799         }
20800 
20801         // in the following we call initial_prune with Parts which is a vector. This is not the most
20802         // efficient since vector does not allow for direct addressing. But since initial_prune doesn't have very high complexity, and
20803         // 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.....
20804 
20805         // comment out for testing
20806         Util::initial_prune(Parts, dimClasses, nParts, K,T);
20807         for(int i = 0; i < nParts; i++){
20808                 for(int j=0; j < K; j++){
20809                         *(argParts + Indices[i*K + j]+1) = -1;
20810                 }
20811         }
20812 
20813         int num_classes;
20814         int old_index;
20815         for(int i=0; i<nParts; i++){
20816                 num_classes = Parts[i].size();// number of classes in partition i after pruning
20817                 for (int j=0; j < num_classes; j++){
20818                         old_index = *(Parts[i][j]);
20819                         //cout << "old_index: " << old_index<<"\n";
20820                         *(argParts + Indices[i*K + old_index]+1) = 1;
20821                 }
20822         }
20823 
20824 
20825         // if we're not doing mpi then keep going and call branchMPI and return the output
20826         //cout <<"begin partition matching\n";
20827         //int* dummy(0);
20828         int* output = Util::branchMPI(argParts, Indices,dimClasses, nParts, K, T,0,n_guesses,LARGEST_CLASS, J, max_branching, stmult,
20829         branchfunc, LIM);
20830         
20831         //cout<<"total cost: "<<*output<<"\n";
20832         //cout<<"number of matches: "<<*(output+1)<<"\n";
20833         // 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
20834         bool correct = Util::sanitycheck(argParts, Indices,dimClasses, nParts, K, T,output);
20835 
20836         // something is wrong with output of branchMPI!
20837         if (correct < 1){
20838                 cout << "something is wrong with output of branchMPI!\n";
20839                 vector<int> ret(1);
20840                 ret[0]=-1;
20841                 return ret;
20842         }
20843 
20844         // output is not nonsense, so now put it into a single dimension vector and return
20845         // 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
20846         // and the rest is the list of matches. output is one dimensional
20847 
20848         int output_size = 2+ *(output+1) * nParts;
20849         vector<int> ret(output_size);
20850         for (int i = 0; i < output_size; i++){
20851                 ret[i]=*(output+i);
20852         }
20853         return ret;
20854 
20855 }

float Util::bilinear float  xold,
float  yold,
int  nsam,
int  nrow,
float *  xim
[static]
 

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 }

float EMAN::Util::bilinear_interpolate float  p1,
float  p2,
float  p3,
float  p4,
float  t,
float  u
[inline, static]
 

Calculate bilinear interpolation.

Parameters:
[in] p1 The first number. corresponding to (x0,y0).
[in] p2 The second number. corresponding to (x1,y0).
[in] p3 The third number. corresponding to (x1,y1).
[in] p4 The fourth number. corresponding to (x0,y1).
[in] t t
[in] u u
Returns:
The bilinear interpolation value.

Definition at line 1486 of file util.h.

Referenced by EMAN::StandardProjector::project3d(), EMAN::EMData::sget_value_at_interp(), and EMAN::TransformProcessor::transform().

void Util::BPCQ EMData B,
EMData CUBE,
vector< float >  DM
[static]
 

Definition at line 5761 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.

05762 {
05763 
05764         float  *Bptr = B->get_data();
05765         float  *CUBEptr = CUBE->get_data();
05766 
05767         int NSAM,NROW,NX3D,NY3D,NZC,KZ,IQX,IQY,LDPX,LDPY,LDPZ,LDPNMX,LDPNMY,NZ1;
05768         float DIPX,DIPY,XB,YB,XBB,YBB;
05769 
05770         Transform * t = B->get_attr("xform.projection");
05771         Dict d = t->get_params("spider");
05772         if(t) {delete t; t=0;}
05773         //  Unsure about sign of shifts, check later PAP 06/28/09
05774         float x_shift = d[ "tx" ];
05775         float y_shift = d[ "ty" ];
05776         x_shift = -x_shift;
05777         y_shift = -y_shift;
05778 
05779         NSAM = B->get_xsize();
05780         NROW = B->get_ysize();
05781         NX3D = CUBE->get_xsize();
05782         NY3D = CUBE->get_ysize();
05783         NZC  = CUBE->get_zsize();
05784 
05785 
05786         LDPX   = NX3D/2 +1;
05787         LDPY   = NY3D/2 +1;
05788         LDPZ   = NZC/2 +1;
05789         LDPNMX = NSAM/2 +1;
05790         LDPNMY = NROW/2 +1;
05791         NZ1    = 1;
05792 
05793         for(int K=1;K<=NZC;K++) {
05794                 KZ=K-1+NZ1;
05795                 for(int J=1;J<=NY3D;J++) {
05796                         XBB = (1-LDPX)*DM(1)+(J-LDPY)*DM(2)+(KZ-LDPZ)*DM(3);
05797                         YBB = (1-LDPX)*DM(4)+(J-LDPY)*DM(5)+(KZ-LDPZ)*DM(6);
05798                         for(int I=1;I<=NX3D;I++) {
05799                                 XB  = (I-1)*DM(1)+XBB-x_shift;
05800                                 IQX = int(XB+float(LDPNMX));
05801                                 if (IQX <1 || IQX >= NSAM) continue;
05802                                 YB  = (I-1)*DM(4)+YBB-y_shift;
05803                                 IQY = int(YB+float(LDPNMY));
05804                                 if (IQY<1 || IQY>=NROW)  continue;
05805                                 DIPX = XB+LDPNMX-IQX;
05806                                 DIPY = YB+LDPNMY-IQY;
05807 
05808                                 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)));
05809                         }
05810                 }
05811         }
05812 }

int Util::branch_factor_2 int *  costlist,
int *  matchlist,
int  J,
int  T,
int  nParts,
int  curlevel,
int  max_branching,
int  LIM
[static]
 

Definition at line 21025 of file util_sparx.cpp.

References B, branch_all, and costlist_global.

Referenced by branchMPI().

21025                                                                                                                  {
21026         
21027         int ntot=0;
21028         for (int jit=0; jit < J; jit++){
21029                 if (*(costlist+jit) > T) ntot++;
21030         }
21031 
21032         int cur;
21033         // sort matchlist by cost
21034         int* indx = new int[J];
21035         for (int jit=0; jit < J; jit++) indx[jit]=jit;
21036         vector<int> myindx (indx, indx+J);
21037         vector<int>::iterator it;
21038         costlist_global=costlist;
21039         sort(myindx.begin(), myindx.begin()+J, jiafunc);
21040 
21041         // put matchlist in the order of mycost
21042         int* templist = new int[J];
21043         int* temp2list = new int[J*nParts];
21044         int next = 0;
21045         
21046         for (it=myindx.begin(); it!=myindx.end();++it){
21047                 cur = *(costlist + *it);
21048                 if (cur > T){
21049                         
21050                         templist[next] = cur;
21051                         for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt];
21052                         next = next + 1;
21053                 }
21054         }
21055         
21056         for (int jit=0; jit < ntot; jit++){
21057                 *(costlist+jit)=*(templist + jit);
21058                 //cout <<*(costlist+jit)<<", ";
21059                 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit];
21060         }
21061         //cout <<"\n";
21062         
21063         delete [] indx;
21064         //compute the average 
21065         
21066         // partition matches into groups where matches in each group is mutually feasible, and matches from different groups are not feasible
21067         // The number of branches to explore are the mutually exclusive matches. Take the largest of these
21068         
21069         
21070         int B=1;
21071         int B_init=B;
21072         int infeasible=0;
21073         
21074         for (int i=B_init; i<ntot; i++){
21075                 if (i==ntot) continue;
21076                 // look at the i-th match. branch on it only if it is infeasible with ALL previous matches we have decided to
21077                 // branch on
21078                 infeasible = 0;
21079                 if (LIM < 0) LIM = B;
21080                 for (int j=0; j<B; j++){
21081                         
21082                         for (int vit=0; vit<nParts; vit++){
21083                                 if (temp2list[i*nParts+vit] == matchlist[j*nParts+vit]) {infeasible++; break;}
21084                         }
21085                         if (infeasible >= LIM) break;
21086                 }
21087                 
21088                 if (infeasible >= LIM){
21089                         *(costlist+B)=*(templist+i);
21090                         for (int vit=0; vit < nParts; vit++)
21091                                 *(matchlist+B*nParts + vit)=*(temp2list+i*nParts + vit);
21092                         B=B+1;  
21093                 }
21094         }
21095         
21096         delete [] templist;
21097         delete [] temp2list;
21098         //cout<<"**************************************** "<<B<<" ***************************\n";
21099         
21100         if (branch_all < max_branching){
21101                 if (B>1)
21102                         {branch_all = branch_all + B -1 ; }
21103         }
21104         else B=1;
21105         
21106         return B;
21107         
21108 
21109 }

int Util::branch_factor_3 int *  costlist,
int *  matchlist,
int  J,
int  T,
int  nParts,
int  curlevel,
int  max_branching,
int  K,
int  LIM
[static]
 

Definition at line 21113 of file util_sparx.cpp.

References B, branch_all, and costlist_global.

Referenced by branchMPI().

21113                                                                                                                       {
21114         
21115         int ntot=0;
21116         for (int jit=0; jit < J; jit++){
21117                 if (*(costlist+jit) > T) ntot++;
21118         }
21119 
21120         int cur;
21121         // sort matchlist by cost
21122         int* indx = new int[J];
21123         for (int jit=0; jit < J; jit++) indx[jit]=jit;
21124         vector<int> myindx (indx, indx+J);
21125         vector<int>::iterator it;
21126         costlist_global=costlist;
21127         sort(myindx.begin(), myindx.begin()+J, jiafunc);
21128 
21129         // put matchlist in the order of mycost
21130         int* templist = new int[J];
21131         int* temp2list = new int[J*nParts];
21132         int next = 0;
21133         
21134         for (it=myindx.begin(); it!=myindx.end();++it){
21135                 cur = *(costlist + *it);
21136                 if (cur > T){
21137                         
21138                         templist[next] = cur;
21139                         for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt];
21140                         next = next + 1;
21141                 }
21142         }
21143         
21144         for (int jit=0; jit < ntot; jit++){
21145                 *(costlist+jit)=*(templist + jit);
21146                 //cout <<*(costlist+jit)<<", ";
21147                 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit];
21148         }
21149         //cout <<"\n";
21150         
21151         delete [] indx;
21152         //compute the average 
21153         
21154         // partition matches into groups where matches in each group is mutually feasible, and matches from different groups are not feasible
21155         // The number of branches to explore are the mutually exclusive matches. Take the largest of these
21156         
21157         
21158         int B=1;
21159         int B_init=B;
21160         int infeasible=0;
21161         // if we're near the bottom of the tree then explore more... this is because the larger weights are not likely to change much,
21162         // whereas the smaller ones can have many permutations
21163         if (LIM < 0) LIM = ntot-1;
21164         for (int i=B_init; i<ntot; i++){
21165                 if (i==ntot) continue;
21166                 // look at the i-th match. branch on it only if it is infeasible with ALL previous matches we have decided to
21167                 // branch on
21168                 infeasible = 0;
21169                 
21170                 for (int j=0; j<ntot; j++){
21171                         if (j == i) continue;
21172                         for (int vit=0; vit<nParts; vit++){
21173                                 if (temp2list[i*nParts+vit] == temp2list[j*nParts+vit]) {infeasible++; break;}
21174                         }
21175                         if (infeasible >= LIM) break;
21176                 }
21177                 
21178                 if (infeasible >= LIM){
21179                         *(costlist+B)=*(templist+i);
21180                         for (int vit=0; vit < nParts; vit++)
21181                                 *(matchlist+B*nParts + vit)=*(temp2list+i*nParts + vit);
21182                         B=B+1;  
21183                 }
21184         }
21185         
21186         delete [] templist;
21187         delete [] temp2list;
21188         //cout<<"**************************************** "<<B<<" ***************************\n";
21189         
21190         
21191         if (branch_all < max_branching){
21192                 if (B>1)
21193                         {branch_all = branch_all + B-1;}
21194         }
21195         else B=1;
21196         
21197         return B;
21198         
21199 
21200 }

int Util::branch_factor_4 int *  costlist,
int *  matchlist,
int  J,
int  T,
int  nParts,
int  curlevel,
int  max_branching,
float  stmult
[static]
 

Definition at line 21206 of file util_sparx.cpp.

References B, branch_all, and costlist_global.

Referenced by branchMPI().

21206                                                                                                                       {
21207         int sum=0;
21208         float average =0;
21209         int ntot=0;
21210         for (int jit=0; jit < J; jit++){
21211                 if (*(costlist+jit) > T) {ntot++; sum = sum +*(costlist+jit);}
21212         }
21213         average = ((float)sum)/((float)ntot);
21214         int cur;
21215         // sort matchlist by cost
21216         int* indx = new int[J];
21217         for (int jit=0; jit < J; jit++) indx[jit]=jit;
21218         vector<int> myindx (indx, indx+J);
21219         vector<int>::iterator it;
21220         costlist_global=costlist;
21221         sort(myindx.begin(), myindx.begin()+J, jiafunc);
21222 
21223         // put matchlist in the order of mycost
21224         int* templist = new int[J];
21225         int* temp2list = new int[J*nParts];
21226         int next = 0;
21227         
21228         for (it=myindx.begin(); it!=myindx.end();++it){
21229                 cur = *(costlist + *it);
21230                 if (cur > T){
21231                         
21232                         templist[next] = cur;
21233                         for (int vt = 0; vt < nParts; vt++) temp2list[next*nParts + vt] = matchlist[ (*it)*nParts + vt];
21234                         next = next + 1;
21235                 }
21236         }
21237         
21238         for (int jit=0; jit < ntot; jit++){
21239                 *(costlist+jit)=*(templist + jit);
21240                 //cout <<*(costlist+jit)<<", ";
21241                 for (int vit=0; vit < nParts; vit++) matchlist[jit*nParts + vit]= temp2list[jit*nParts + vit];
21242         }
21243         //cout <<"\n";
21244         
21245         delete [] indx;
21246         delete [] templist;
21247         delete [] temp2list;
21248         
21249         if (ntot == 1) return 1;
21250         
21251         // look at the average, standard dev etc. If standard dev very small, i.e., costs very similar, then branch on the similar
21252         // costs
21253         float sq_sum=0.0;
21254         //cout <<"costlist:";
21255         for (int i=0; i< ntot; i++){
21256                 sq_sum = sq_sum + (float) pow((float) *(costlist+i) - average, (float)2.0);
21257                 //cout <<*(costlist+i)<<", ";
21258         }       
21259         //cout <<"\n";
21260         
21261         float variance = sq_sum/ntot;
21262         float stdev = (float)pow((float)variance,(float)0.5);
21263         
21264         //cout <<"stdev: "<<int(stdev)<<"\n";
21265         
21266         int B=1;
21267         int largest = *costlist;
21268         //cout <<"largest: "<<largest<<"\n";
21269         for (int i=1; i<ntot; i++){
21270                 int cur = *(costlist+i);
21271                 if (largest-cur < (float)(stdev*stmult)) B++;
21272                 else break;
21273         
21274         }
21275         //cout <<"B: "<<B<<"\n";
21276         if (branch_all < max_branching){
21277                 if (B>1)
21278                         {branch_all = branch_all + B-1;}
21279         }
21280         else B=1;
21281         
21282         return B;
21283         
21284 
21285 }

int * Util::branchMPI int *  argParts,
int *  Indices,
int *  dimClasses,
int  nParts,
int  K,
int  T,
int  curlevel,
int  n_guesses,
int  LARGEST_CLASS,
int  J,
int  max_branching,
float  stmult,
int  branchfunc,
int  LIM
[static]
 

same as branch except the nFirst (=Levels[0]) possibilites for the first match are already chosen firstmatches stores the matches and corresponding cost, where each match is preceded by its cost....

output is an int array, the first element is the cost of the output solution, the second element is the total number of matches in the solution and the rest is the list of matches. output is in one dimensional form.

Definition at line 20859 of file util_sparx.cpp.

References branch_all, branch_factor_2(), branch_factor_3(), branch_factor_4(), branchMPI(), and search2().

20860                                                                                 {
20861 
20862 //*************************************
20863 //testing search2
20864 if (1 == 0){
20865 cout <<"begin test search2\n";
20866 int* matchlist = new int[J*nParts];
20867 int* costlist = new int[J];
20868 for (int jit = 0; jit < nParts; jit++) *(costlist+jit) = 0;
20869 Util::search2(argParts,Indices, dimClasses, nParts, K,  T, matchlist,costlist,J);
20870 
20871 for (int jit = 0; jit < J; jit++) {
20872   cout << *(costlist +jit)<<": ";
20873   for (int yit = 0; yit < nParts; yit++)
20874         cout << *(matchlist + jit*nParts + yit)<<",";
20875   cout <<"\n";  
20876 
20877 }
20878 cout <<"end test search2\n";
20879 int* ret = new int[1];
20880 *ret=1;
20881 delete [] matchlist;
20882 delete [] costlist;
20883 return ret;
20884 }
20885 //**************************************
20886 
20887         // Base Case: we're at a leaf, no more feasible matches possible
20888         if (curlevel > K -1){
20889                 int* res = new int[2];
20890                 *res = 0;
20891                 *(res+1)=0;
20892                 return res;
20893         }
20894 
20895         // branch dynamically depending on results of search 2!
20896         
20897         int* matchlist = new int[J*nParts];
20898         int* costlist = new int[J];
20899         Util::search2(argParts,Indices, dimClasses, nParts, K,  T, matchlist,costlist,J);
20900         
20901         
20902         // each class in the matches found by findTopLargest is encoded by the original index of the first element of the class in argPart
20903         // each match contains nParts classes, with the i-th class belonging to the i-th partition.
20904 
20905         // if there are no feasible matches with cost gt T, then return 0
20906         for (int jit = 0; jit < J ; jit++){
20907         
20908                 if (costlist[jit] > T) break;
20909                 if (jit == J-1){
20910                         int* res = new int[2];
20911                         *res = 0;
20912                         *(res+1)=0;
20913                         return res;
20914                 }
20915         }
20916         
20917 
20918         
20919         // note that costlist and matchlist are NOT sorted by weight, and branch factor takes care of that...
20920         if (curlevel==0) branch_all = 0;
20921         int* newcostlist;
20922         int* newmatchlist;
20923         
20924         int nBranches = -1;
20925         
20926         if (branchfunc == 2)
20927                 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
20928 
20929         if (branchfunc == 3)
20930                 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
20931 
20932         if (branchfunc == 4)
20933                 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
20934 
20935         newcostlist= new int[nBranches];
20936         newmatchlist = new int[nBranches*nParts];
20937         for (int i=0; i<nBranches; i++){
20938                 *(newcostlist + i) = *(costlist+i);
20939                 for (int j=0; j< nParts; j++)
20940                         *(newmatchlist + i*nParts + j) = *(matchlist + i*nParts+j);
20941         }
20942 
20943         delete[] costlist;
20944         delete[] matchlist;
20945         
20946         int* maxreturn = new int[2];//initialize to placeholder
20947         *maxreturn=0;
20948         *(maxreturn+1)=0;
20949         // some temporary variables
20950         int old_index;
20951         int totalcost;
20952         int nmatches;
20953         //int offset;
20954 
20955         for(int i=0; i < nBranches ; i++){
20956 
20957                 // consider the i-th match returned by findTopLargest
20958                 //if (newcostlist[i] <= T) continue;
20959 
20960                 // 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.
20961                 // After branch returns, compute overall cost, unmark  the classes just marked as 1 again in preparation for next loop.
20962 
20963                 for(int j=0; j < nParts; j++){
20964                         // matchlist[i*nParts + j] is the original index of the class belonging to the j-th partition in the i-th match.
20965                         old_index=newmatchlist[i*nParts + j];
20966                         *(argParts + Indices[j*K+old_index] + 1) = -2;
20967                 }
20968 
20969                 
20970                 int* ret = Util::branchMPI(argParts, Indices, dimClasses, nParts, K, T,curlevel+1,n_guesses, LARGEST_CLASS,
20971                 J,max_branching, stmult,branchfunc, LIM);
20972                 
20973                 // first element of ret is the total cost of all the matches in ret, and second element is the number of matches in ret
20974                 totalcost = newcostlist[i] + *ret;
20975 
20976                 //if (curlevel == 0) {
20977                 //      cout <<"totalcost*****************************************************************: "<<totalcost<<", costlist["<<i<<"]="<<newcostlist[i]<<", *ret="<<*ret<<", level: "<<curlevel<<"\n";
20978                         
20979                 //}
20980                 if (totalcost > *maxreturn) // option 1
20981                 {
20982                         nmatches = 1 + *(ret+1);
20983                         delete[] maxreturn; // get rid of the old maxreturn
20984                         maxreturn = new int[2+nmatches*nParts];
20985                         *maxreturn = totalcost;
20986                         
20987                         *(maxreturn + 1)= nmatches;
20988                         int nret = 2+(nmatches-1)*nParts;
20989                         for(int iret=2; iret <nret;iret++) *(maxreturn+iret)=*(ret+iret);
20990                         for(int imax=0; imax<nParts;imax++) *(maxreturn+nret+imax)=newmatchlist[i*nParts + imax];
20991                 }
20992 
20993 
20994                 delete[] ret;
20995 
20996                 // unmark the marked classes in preparation for the next iteration
20997 
20998                 for(int j=0; j < nParts; j++){
20999                         old_index=newmatchlist[i*nParts + j];
21000                         *(argParts + Indices[j*K+old_index] + 1) = 1;
21001                 }
21002 
21003         }
21004 
21005         delete[] newmatchlist;
21006         delete[] newcostlist;
21007         
21008         return maxreturn;
21009 
21010 }

EMData* EMAN::Util::calc_bessel const int  n,
const float &  x
[static]
 

int Util::calc_best_fft_size int  low  )  [static]
 

Search the best FFT size with good primes.

It supports FFT size up to 4096 now.

Parameters:
[in] low low size the search starts with.
Returns:
The best FFT size.

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 }

Vec3f Util::calc_bilinear_least_square const vector< float > &  points  )  [static]
 

calculate bilinear least-square fit, z = a + b x + c y Takes a set of x,y,z vectors and produces an a,b,c vector does not accept error bars on z or return goodness of fit

Parameters:
[in] points a vector<float> of x,y,z values in (x1,y1,z1,x2,y2,z2...) sequence to fit a plane to
Returns:
result as a Vec3f(a,b,c)

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 }

void Util::calc_least_square_fit size_t  nitems,
const float *  data_x,
const float *  data_y,
float *  p_slope,
float *  p_intercept,
bool  ignore_zero,
float  absmax = 0
[static]
 

calculate the least square fit value.

Parameters:
[in] nitems Number of items in array data_x and data_y.
[in] data_x x data array.
[in] data_y y data array. It should have the same number of items to data_x.
[out] p_slope pointer to the result slope.
[out] p_intercept pointer to the result intercept.
[in] ignore_zero If true, ignore data where either x or y is 0. If false, includes all 0.
[in] absmax Ignores values in y more than absmax from zero

Definition at line 509 of file util.cpp.

References Assert, div(), NullPointerException, x, and y.

Referenced by EMAN::OptVarianceCmp::cmp(), EMAN::LowpassAutoBProcessor::create_radial_func(), and EMAN::GradientRemoverProcessor::process_inplace().

00511 {
00512         Assert(nitems > 0);
00513 
00514         if (!data_x || !data_y || !slope || !intercept) {
00515                 throw NullPointerException("null float pointer");
00516         }
00517         double sum = 0;
00518         double sum_x = 0;
00519         double sum_y = 0;
00520         double sum_xx = 0;
00521         double sum_xy = 0;
00522 
00523         for (size_t i = 0; i < nitems; i++) {
00524                 if ((!ignore_zero || (data_x[i] != 0 && data_y[i] != 0))&&(!absmax ||(data_y[i]<absmax && data_y[i]>-absmax))) {
00525                         double y = data_y[i];
00526                         double x = i;
00527                         if (data_x) {
00528                                 x = data_x[i];
00529                         }
00530 
00531                         sum_x += x;
00532                         sum_y += y;
00533                         sum_xx += x * x;
00534                         sum_xy += x * y;
00535                         sum++;
00536                 }
00537         }
00538 
00539         double div = sum * sum_xx - sum_x * sum_x;
00540         if (div == 0) {
00541                 div = 0.0000001f;
00542         }
00543 
00544         *intercept = (float) ((sum_xx * sum_y - sum_x * sum_xy) / div);
00545         *slope = (float) ((sum * sum_xy - sum_x * sum_y) / div);
00546 }

vector< float > Util::call_cl1 long int *  k,
long int *  n,
float *  ps,
long int *  iswi,
float *  pw,
float *  q2,
double *  q,
double *  x,
double *  res,
double *  cu,
double *  s,
long int *  iu
[static]
 

Definition at line 6416 of file util_sparx.cpp.

References lsfit(), q, and x.

06417 {
06418     long int q2_dim1, q2_offset, q_dim1, q_offset, i__1, i__2;
06419     float r__1;
06420     int tmp__i;
06421     long int i__, j;
06422     --s;
06423     --res;
06424     iu -= 3;
06425     cu -= 3;
06426     --x;
06427     long int klm2d;
06428     klm2d= *k+*k+2;
06429     klm2d=klm2d+klm2d;
06430     q_dim1 = klm2d;
06431     q_offset = 1 + q_dim1;
06432     q -= q_offset;
06433     q2_dim1 = klm2d;
06434     q2_offset = 1 + q2_dim1;
06435     q2 -= q2_offset;
06436     i__2=0;
06437     i__1 = *n - 1;
06438     tmp__i=0;
06439     for (j = 1; j <= i__1; ++j) {
06440         i__2 = *k;
06441         tmp__i+=1;
06442         for (i__ = 1; i__ <= i__2; ++i__) {
06443             r__1 = float(i__ - 1) /(float) *k / (*ps * 2);
06444             q2[i__ + j * q2_dim1] = pow(r__1, tmp__i);
06445         }
06446     }
06447     for  (i__ = 1; i__ <= i__2; ++i__)
06448       { q2[i__ + *n * q2_dim1] = 1.f;
06449             q2[i__ + (*n + 1) * q2_dim1] = pw[i__-1];
06450         }
06451    vector<float> fit_res;
06452    fit_res=Util::lsfit(k, n, &klm2d, iswi, &q2[q2_offset], &q[q_offset], &x[1], &res[1], &cu[3], &s[1], &iu[3]);
06453    return fit_res;
06454 }

Dict Util::CANG float  PHI,
float  THETA,
float  PSI
[static]
 

Definition at line 5713 of file util_sparx.cpp.

References DGR_TO_RAD, DM, and SS.

05714 {
05715         double CPHI,SPHI,CTHE,STHE,CPSI,SPSI;
05716         vector<float>   DM,SS;
05717 
05718         for(int i =0;i<9;i++) DM.push_back(0);
05719 
05720         for(int i =0;i<6;i++) SS.push_back(0);
05721 
05722         CPHI = cos(double(PHI)*DGR_TO_RAD);
05723         SPHI = sin(double(PHI)*DGR_TO_RAD);
05724         CTHE = cos(double(THETA)*DGR_TO_RAD);
05725         STHE = sin(double(THETA)*DGR_TO_RAD);
05726         CPSI = cos(double(PSI)*DGR_TO_RAD);
05727         SPSI = sin(double(PSI)*DGR_TO_RAD);
05728 
05729         SS(1) = float(CPHI);
05730         SS(2) = float(SPHI);
05731         SS(3) = float(CTHE);
05732         SS(4) = float(STHE);
05733         SS(5) = float(CPSI);
05734         SS(6) = float(SPSI);
05735 
05736         DM(1) = float(CPHI*CTHE*CPSI-SPHI*SPSI);
05737         DM(2) = float(SPHI*CTHE*CPSI+CPHI*SPSI);
05738         DM(3) = float(-STHE*CPSI);
05739         DM(4) = float(-CPHI*CTHE*SPSI-SPHI*CPSI);
05740         DM(5) = float(-SPHI*CTHE*SPSI+CPHI*CPSI);
05741         DM(6) = float(STHE*SPSI);
05742         DM(7) = float(STHE*CPHI);
05743         DM(8) = float(STHE*SPHI);
05744         DM(9) = float(CTHE);
05745 
05746         Dict DMnSS;
05747         DMnSS["DM"] = DM;
05748         DMnSS["SS"] = SS;
05749 
05750         return(DMnSS);
05751 }

float Util::ccc_images EMData ,
EMData ,
EMData ,
float  ,
float  ,
float 
[static]
 

Definition at line 19529 of file util_sparx.cpp.

References EMAN::EMData::cmp(), and EMAN::EMData::rot_scale_trans2D().

19529                                                                                                 {
19530 
19531         EMData *rot= new EMData();
19532         float ccc;
19533 
19534         rot = image->rot_scale_trans2D(ang, sx, sy, 1.0);
19535         ccc = -rot->cmp("sqeuclidean", refim, Dict("mask", mask));
19536         delete rot;
19537         return ccc;
19538 }

float Util::ccc_images_G EMData image,
EMData refim,
EMData mask,
Util::KaiserBessel kb,
float  ang,
float  sx,
float  sy
[static]
 

Definition at line 19566 of file util_sparx.cpp.

References EMAN::EMData::cmp(), pi, and EMAN::EMData::rot_scale_conv7().

19566                                                                                                                         {
19567 
19568         EMData *rot= new EMData();
19569         float ccc;
19570 
19571         rot = image->rot_scale_conv7(static_cast<float>(ang*pi/180.0), sx, sy, kb, 1.0f);
19572         ccc = -rot->cmp("sqeuclidean", refim, Dict("mask", mask));
19573         delete rot;
19574         return ccc;
19575 }

string Util::change_filename_ext const string &  old_filename,
const string &  new_ext
[static]
 

Change a file's extension and return the new filename.

If the given new extension is empty, the old filename is not changed. If the old filename has no extension, add the new extension to it.

Parameters:
[in] old_filename Old filename.
[in] new_ext The new extension. It shouldn't have ".". e.g., for MRC file, it will be "mrc", not ".mrc".
Returns:
The new filename with the new extension.

Definition at line 430 of file util.cpp.

References Assert.

Referenced by EMAN::EMUtil::get_image_type(), EMAN::ImagicIO::ImagicIO(), and EMAN::ImagicIO2::ImagicIO2().

00432 {
00433         Assert(old_filename != "");
00434         if (ext == "") {
00435                 return old_filename;
00436         }
00437 
00438         string filename = old_filename;
00439         size_t dot_pos = filename.rfind(".");
00440         if (dot_pos != string::npos) {
00441                 filename = filename.substr(0, dot_pos+1);
00442         }
00443         else {
00444                 filename = filename + ".";
00445         }
00446         filename = filename + ext;
00447         return filename;
00448 }

bool Util::check_file_by_magic const void *  first_block,
const char *  magic
[static]
 

check whether a file starts with certain magic string.

Parameters:
first_block The first block of the file.
magic The magic string to identify a file format.
Returns:
True if file matches magic. Otherwise, false.

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 }

void Util::cl1 long int *  k,
long int *  l,
long int *  m,
long int *  n,
long int *  klm2d,
double *  q,
double *  x,
double *  res,
double *  cu,
long int *  iu,
double *  s
[static]
 

Definition at line 6601 of file util_sparx.cpp.

References abs, in, q, and x.

06603 {
06604 
06605     long int q_dim1, q_offset, i__1, i__2;
06606     double d__1;
06607 
06608     static long int i__, j;
06609     static double z__;
06610     static long int n1, n2, ia, ii, kk, in, nk, js;
06611     static double sn, zu, zv;
06612     static long int nk1, klm, nkl, jmn, jpn;
06613     static double cuv;
06614     static long int klm1, nkl1, klm2, kode, iimn, nklm, iter;
06615     static float xmin;
06616     static double xmax;
06617     static long int iout;
06618     static double xsum;
06619     static long int iineg, maxit;
06620     static double toler;
06621     static float error;
06622     static double pivot;
06623     static long int kforce, iphase;
06624     static double tpivot;
06625 
06626     --s;
06627     --res;
06628     iu -= 3;
06629     cu -= 3;
06630     --x;
06631     q_dim1 = *klm2d;
06632     q_offset = 1 + q_dim1;
06633     q -= q_offset;
06634 
06635     /* Function Body */
06636     maxit = 500;
06637     kode = 0;
06638     toler = 1e-4f;
06639     iter = 0;
06640     n1 = *n + 1;
06641     n2 = *n + 2;
06642     nk = *n + *k;
06643     nk1 = nk + 1;
06644     nkl = nk + *l;
06645     nkl1 = nkl + 1;
06646     klm = *k + *l + *m;
06647     klm1 = klm + 1;
06648     klm2 = klm + 2;
06649     nklm = *n + klm;
06650     kforce = 1;
06651     iter = 0;
06652     js = 1;
06653     ia = 0;
06654 /* SET UP LABELS IN Q. */
06655     i__1 = *n;
06656     for (j = 1; j <= i__1; ++j) {
06657         q[klm2 + j * q_dim1] = (double) j;
06658 /* L10: */
06659     }
06660     i__1 = klm;
06661     for (i__ = 1; i__ <= i__1; ++i__) {
06662         q[i__ + n2 * q_dim1] = (double) (*n + i__);
06663         if (q[i__ + n1 * q_dim1] >= 0.f) {
06664             goto L30;
06665         }
06666         i__2 = n2;
06667         for (j = 1; j <= i__2; ++j) {
06668             q[i__ + j * q_dim1] = -q[i__ + j * q_dim1];
06669 /* L20: */
06670         }
06671 L30:
06672         ;
06673     }
06674 /* SET UP PHASE 1 COSTS. */
06675     iphase = 2;
06676     i__1 = nklm;
06677     for (j = 1; j <= i__1; ++j) {
06678         cu[(j << 1) + 1] = 0.f;
06679         cu[(j << 1) + 2] = 0.f;
06680         iu[(j << 1) + 1] = 0;
06681         iu[(j << 1) + 2] = 0;
06682 /* L40: */
06683     }
06684     if (*l == 0) {
06685         goto L60;
06686     }
06687     i__1 = nkl;
06688     for (j = nk1; j <= i__1; ++j) {
06689         cu[(j << 1) + 1] = 1.f;
06690         cu[(j << 1) + 2] = 1.f;
06691         iu[(j << 1) + 1] = 1;
06692         iu[(j << 1) + 2] = 1;
06693 /* L50: */
06694     }
06695     iphase = 1;
06696 L60:
06697     if (*m == 0) {
06698         goto L80;
06699     }
06700     i__1 = nklm;
06701     for (j = nkl1; j <= i__1; ++j) {
06702         cu[(j << 1) + 2] = 1.f;
06703         iu[(j << 1) + 2] = 1;
06704         jmn = j - *n;
06705         if (q[jmn + n2 * q_dim1] < 0.f) {
06706             iphase = 1;
06707         }
06708 /* L70: */
06709     }
06710 L80:
06711     if (kode == 0) {
06712         goto L150;
06713     }
06714     i__1 = *n;
06715     for (j = 1; j <= i__1; ++j) {
06716         if ((d__1 = x[j]) < 0.) {
06717             goto L90;
06718         } else if (d__1 == 0) {
06719             goto L110;
06720         } else {
06721             goto L100;
06722         }
06723 L90:
06724         cu[(j << 1) + 1] = 1.f;
06725         iu[(j << 1) + 1] = 1;
06726         goto L110;
06727 L100:
06728         cu[(j << 1) + 2] = 1.f;
06729         iu[(j << 1) + 2] = 1;
06730 L110:
06731         ;
06732     }
06733     i__1 = *k;
06734     for (j = 1; j <= i__1; ++j) {
06735         jpn = j + *n;
06736         if ((d__1 = res[j]) < 0.) {
06737             goto L120;
06738         } else if (d__1 == 0) {
06739             goto L140;
06740         } else {
06741             goto L130;
06742         }
06743 L120:
06744         cu[(jpn << 1) + 1] = 1.f;
06745         iu[(jpn << 1) + 1] = 1;
06746         if (q[j + n2 * q_dim1] > 0.f) {
06747             iphase = 1;
06748         }
06749         goto L140;
06750 L130:
06751         cu[(jpn << 1) + 2] = 1.f;
06752         iu[(jpn << 1) + 2] = 1;
06753         if (q[j + n2 * q_dim1] < 0.f) {
06754             iphase = 1;
06755         }
06756 L140:
06757         ;
06758     }
06759 L150:
06760     if (iphase == 2) {
06761         goto L500;
06762     }
06763 /* COMPUTE THE MARGINAL COSTS. */
06764 L160:
06765     i__1 = n1;
06766     for (j = js; j <= i__1; ++j) {
06767         xsum = 0.;
06768         i__2 = klm;
06769         for (i__ = 1; i__ <= i__2; ++i__) {
06770             ii = (long int) q[i__ + n2 * q_dim1];
06771             if (ii < 0) {
06772                 goto L170;
06773             }
06774             z__ = cu[(ii << 1) + 1];
06775             goto L180;
06776 L170:
06777             iineg = -ii;
06778             z__ = cu[(iineg << 1) + 2];
06779 L180:
06780             xsum += q[i__ + j * q_dim1] * z__;
06781 /*  180       XSUM = XSUM + Q(I,J)*Z */
06782 /* L190: */
06783         }
06784         q[klm1 + j * q_dim1] = xsum;
06785 /* L200: */
06786     }
06787     i__1 = *n;
06788     for (j = js; j <= i__1; ++j) {
06789         ii = (long int) q[klm2 + j * q_dim1];
06790         if (ii < 0) {
06791             goto L210;
06792         }
06793         z__ = cu[(ii << 1) + 1];
06794         goto L220;
06795 L210:
06796         iineg = -ii;
06797         z__ = cu[(iineg << 1) + 2];
06798 L220:
06799         q[klm1 + j * q_dim1] -= z__;
06800 /* L230: */
06801     }
06802 /* DETERMINE THE VECTOR TO ENTER THE BASIS. */
06803 L240:
06804     xmax = 0.f;
06805     if (js > *n) {
06806         goto L490;
06807     }
06808     i__1 = *n;
06809     for (j = js; j <= i__1; ++j) {
06810         zu = q[klm1 + j * q_dim1];
06811         ii = (long int) q[klm2 + j * q_dim1];
06812         if (ii > 0) {
06813             goto L250;
06814         }
06815         ii = -ii;
06816         zv = zu;
06817         zu = -zu - cu[(ii << 1) + 1] - cu[(ii << 1) + 2];
06818         goto L260;
06819 L250:
06820         zv = -zu - cu[(ii << 1) + 1] - cu[(ii << 1) + 2];
06821 L260:
06822         if (kforce == 1 && ii > *n) {
06823             goto L280;
06824         }
06825         if (iu[(ii << 1) + 1] == 1) {
06826             goto L270;
06827         }
06828         if (zu <= xmax) {
06829             goto L270;
06830         }
06831         xmax = zu;
06832         in = j;
06833 L270:
06834         if (iu[(ii << 1) + 2] == 1) {
06835             goto L280;
06836         }
06837         if (zv <= xmax) {
06838             goto L280;
06839         }
06840         xmax = zv;
06841         in = j;
06842 L280:
06843         ;
06844     }
06845     if (xmax <= toler) {
06846         goto L490;
06847     }
06848     if (q[klm1 + in * q_dim1] == xmax) {
06849         goto L300;
06850     }
06851     i__1 = klm2;
06852     for (i__ = 1; i__ <= i__1; ++i__) {
06853         q[i__ + in * q_dim1] = -q[i__ + in * q_dim1];
06854 /* L290: */
06855     }
06856     q[klm1 + in * q_dim1] = xmax;
06857 /* DETERMINE THE VECTOR TO LEAVE THE BASIS. */
06858 L300:
06859     if (iphase == 1 || ia == 0) {
06860         goto L330;
06861     }
06862     xmax = 0.f;
06863     i__1 = ia;
06864     for (i__ = 1; i__ <= i__1; ++i__) {
06865         z__ = (d__1 = q[i__ + in * q_dim1], abs(d__1));
06866         if (z__ <= xmax) {
06867             goto L310;
06868         }
06869         xmax = z__;
06870         iout = i__;
06871 L310:
06872         ;
06873     }
06874     if (xmax <= toler) {
06875         goto L330;
06876     }
06877     i__1 = n2;
06878     for (j = 1; j <= i__1; ++j) {
06879         z__ = q[ia + j * q_dim1];
06880         q[ia + j * q_dim1] = q[iout + j * q_dim1];
06881         q[iout + j * q_dim1] = z__;
06882 /* L320: */
06883     }
06884     iout = ia;
06885     --ia;
06886     pivot = q[iout + in * q_dim1];
06887     goto L420;
06888 L330:
06889     kk = 0;
06890     i__1 = klm;
06891     for (i__ = 1; i__ <= i__1; ++i__) {
06892         z__ = q[i__ + in * q_dim1];
06893         if (z__ <= toler) {
06894             goto L340;
06895         }
06896         ++kk;
06897         res[kk] = q[i__ + n1 * q_dim1] / z__;
06898         s[kk] = (double) i__;
06899 L340:
06900         ;
06901     }
06902 L350:
06903     if (kk > 0) {
06904         goto L360;
06905     }
06906     kode = 2;
06907     goto L590;
06908 L360:
06909     xmin = static_cast<float>( res[1] );
06910     iout = (long int) s[1];
06911     j = 1;
06912     if (kk == 1) {
06913         goto L380;
06914     }
06915     i__1 = kk;
06916     for (i__ = 2; i__ <= i__1; ++i__) {
06917         if (res[i__] >= xmin) {
06918             goto L370;
06919         }
06920         j = i__;
06921         xmin = static_cast<float>( res[i__] );
06922         iout = (long int) s[i__];
06923 L370:
06924         ;
06925     }
06926     res[j] = res[kk];
06927     s[j] = s[kk];
06928 L380:
06929     --kk;
06930     pivot = q[iout + in * q_dim1];
06931     ii = (long int) q[iout + n2 * q_dim1];
06932     if (iphase == 1) {
06933         goto L400;
06934     }
06935     if (ii < 0) {
06936         goto L390;
06937     }
06938     if (iu[(ii << 1) + 2] == 1) {
06939         goto L420;
06940     }
06941     goto L400;
06942 L390:
06943     iineg = -ii;
06944     if (iu[(iineg << 1) + 1] == 1) {
06945         goto L420;
06946     }
06947 /* 400 II = IABS(II) */
06948 L400:
06949     ii = abs(ii);
06950     cuv = cu[(ii << 1) + 1] + cu[(ii << 1) + 2];
06951     if (q[klm1 + in * q_dim1] - pivot * cuv <= toler) {
06952         goto L420;
06953     }
06954 /* BYPASS INTERMEDIATE VERTICES. */
06955     i__1 = n1;
06956     for (j = js; j <= i__1; ++j) {
06957         z__ = q[iout + j * q_dim1];
06958         q[klm1 + j * q_dim1] -= z__ * cuv;
06959         q[iout + j * q_dim1] = -z__;
06960 /* L410: */
06961     }
06962     q[iout + n2 * q_dim1] = -q[iout + n2 * q_dim1];
06963     goto L350;
06964 /* GAUSS-JORDAN ELIMINATION. */
06965 L420:
06966     if (iter < maxit) {
06967         goto L430;
06968     }
06969     kode = 3;
06970     goto L590;
06971 L430:
06972     ++iter;
06973     i__1 = n1;
06974     for (j = js; j <= i__1; ++j) {
06975         if (j != in) {
06976             q[iout + j * q_dim1] /= pivot;
06977         }
06978 /* L440: */
06979     }
06980 /* IF PERMITTED, USE SUBROUTINE COL OF THE DESCRIPTION */
06981 /* SECTION AND REPLACE THE FOLLOWING SEVEN STATEMENTS DOWN */
06982 /* TO AND INCLUDING STATEMENT NUMBER 460 BY.. */
06983 /*     DO 460 J=JS,N1 */
06984 /*        IF(J .EQ. IN) GO TO 460 */
06985 /*        Z = -Q(IOUT,J) */
06986 /*        CALL COL(Q(1,J), Q(1,IN), Z, IOUT, KLM1) */
06987 /* 460 CONTINUE */
06988     i__1 = n1;
06989     for (j = js; j <= i__1; ++j) {
06990         if (j == in) {
06991             goto L460;
06992         }
06993         z__ = -q[iout + j * q_dim1];
06994         i__2 = klm1;
06995         for (i__ = 1; i__ <= i__2; ++i__) {
06996             if (i__ != iout) {
06997                 q[i__ + j * q_dim1] += z__ * q[i__ + in * q_dim1];
06998             }
06999 /* L450: */
07000         }
07001 L460:
07002         ;
07003     }
07004     tpivot = -pivot;
07005     i__1 = klm1;
07006     for (i__ = 1; i__ <= i__1; ++i__) {
07007         if (i__ != iout) {
07008             q[i__ + in * q_dim1] /= tpivot;
07009         }
07010 /* L470: */
07011     }
07012     q[iout + in * q_dim1] = 1.f / pivot;
07013     z__ = q[iout + n2 * q_dim1];
07014     q[iout + n2 * q_dim1] = q[klm2 + in * q_dim1];
07015     q[klm2 + in * q_dim1] = z__;
07016     ii = (long int) abs(z__);
07017     if (iu[(ii << 1) + 1] == 0 || iu[(ii << 1) + 2] == 0) {
07018         goto L240;
07019     }
07020     i__1 = klm2;
07021     for (i__ = 1; i__ <= i__1; ++i__) {
07022         z__ = q[i__ + in * q_dim1];
07023         q[i__ + in * q_dim1] = q[i__ + js * q_dim1];
07024         q[i__ + js * q_dim1] = z__;
07025 /* L480: */
07026     }
07027     ++js;
07028     goto L240;
07029 /* TEST FOR OPTIMALITY. */
07030 L490:
07031     if (kforce == 0) {
07032         goto L580;
07033     }
07034     if (iphase == 1 && q[klm1 + n1 * q_dim1] <= toler) {
07035         goto L500;
07036     }
07037     kforce = 0;
07038     goto L240;
07039 /* SET UP PHASE 2 COSTS. */
07040 L500:
07041     iphase = 2;
07042     i__1 = nklm;
07043     for (j = 1; j <= i__1; ++j) {
07044         cu[(j << 1) + 1] = 0.f;
07045         cu[(j << 1) + 2] = 0.f;
07046 /* L510: */
07047     }
07048     i__1 = nk;
07049     for (j = n1; j <= i__1; ++j) {
07050         cu[(j << 1) + 1] = 1.f;
07051         cu[(j << 1) + 2] = 1.f;
07052 /* L520: */
07053     }
07054     i__1 = klm;
07055     for (i__ = 1; i__ <= i__1; ++i__) {
07056         ii = (long int) q[i__ + n2 * q_dim1];
07057         if (ii > 0) {
07058             goto L530;
07059         }
07060         ii = -ii;
07061         if (iu[(ii << 1) + 2] == 0) {
07062             goto L560;
07063         }
07064         cu[(ii << 1) + 2] = 0.f;
07065         goto L540;
07066 L530:
07067         if (iu[(ii << 1) + 1] == 0) {
07068             goto L560;
07069         }
07070         cu[(ii << 1) + 1] = 0.f;
07071 L540:
07072         ++ia;
07073         i__2 = n2;
07074         for (j = 1; j <= i__2; ++j) {
07075             z__ = q[ia + j * q_dim1];
07076             q[ia + j * q_dim1] = q[i__ + j * q_dim1];
07077             q[i__ + j * q_dim1] = z__;
07078 /* L550: */
07079         }
07080 L560:
07081         ;
07082     }
07083     goto L160;
07084 L570:
07085     if (q[klm1 + n1 * q_dim1] <= toler) {
07086         goto L500;
07087     }
07088     kode = 1;
07089     goto L590;
07090 L580:
07091     if (iphase == 1) {
07092         goto L570;
07093     }
07094 /* PREPARE OUTPUT. */
07095     kode = 0;
07096 L590:
07097     xsum = 0.;
07098     i__1 = *n;
07099     for (j = 1; j <= i__1; ++j) {
07100         x[j] = 0.f;
07101 /* L600: */
07102     }
07103     i__1 = klm;
07104     for (i__ = 1; i__ <= i__1; ++i__) {
07105         res[i__] = 0.f;
07106 /* L610: */
07107     }
07108     i__1 = klm;
07109     for (i__ = 1; i__ <= i__1; ++i__) {
07110         ii = (long int) q[i__ + n2 * q_dim1];
07111         sn = 1.f;
07112         if (ii > 0) {
07113             goto L620;
07114         }
07115         ii = -ii;
07116         sn = -1.f;
07117 L620:
07118         if (ii > *n) {
07119             goto L630;
07120         }
07121         x[ii] = sn * q[i__ + n1 * q_dim1];
07122         goto L640;
07123 L630:
07124         iimn = ii - *n;
07125         res[iimn] = sn * q[i__ + n1 * q_dim1];
07126         if (ii >= n1 && ii <= nk) {
07127             xsum += q[i__ + n1 * q_dim1];
07128         }
07129 L640:
07130         ;
07131     }
07132     error = (float)xsum;
07133     return;
07134 }

vector< float > Util::cluster_equalsize EMData d  )  [static]
 

Definition at line 20163 of file util_sparx.cpp.

References dm, EMAN::EMData::get_xsize(), nx, and sqrt().

20163                                                {
20164         //  WORKS ONLY FOR NUMBER OF OBJECTS N=l^2   !!
20165         int nx = d->get_xsize();
20166         int N = 1 + int((sqrt(1.0 + 8.0*nx)-1.0)/2.0);
20167         int K = N/2;
20168         vector<float> group(N);
20169         if(N*(N-1)/2 != nx) {
20170                 //print  "  incorrect dimension"
20171                 return group;}
20172         //bool active[N];       //this does not compile in VS2005. --Grant Tang
20173         bool * active = new bool[N];
20174         for(int i=0; i<N; i++) active[i] = true;
20175 
20176         float dm, qd;
20177         int   ppi = 0, ppj = 0;
20178         for(int k=0; k<K; k++) {
20179                 // find pairs of most similiar objects among active
20180                 //cout<<"  k  "<<k<<endl;
20181                 dm = 1.0e23f;
20182                 for(int i=1; i<N; i++) {
20183                         if(active[i]) {
20184                                 for(int j=0; j<i; j++) {
20185                                         if(active[j]) {
20186                                                 qd = (*d)(i*(i - 1)/2 + j);
20187                                                 if(qd < dm) {
20188                                                         dm = qd;
20189                                                         ppi = i;
20190                                                         ppj = j;
20191                                                 }
20192                                         }
20193                                 }
20194                         }
20195                 }
20196                 group[2*k] = float(ppi);
20197                 group[1+2*k] = float(ppj);
20198                 active[ppi] = false;
20199                 active[ppj] = false;
20200         }
20201 
20202         delete [] active;
20203         active = NULL;
20204         return  group;
20205 }

vector< float > Util::cluster_pairwise EMData d,
int  K,
float  T,
float  F
[static]
 

Definition at line 19955 of file util_sparx.cpp.

References assign, cent, dt, EMAN::EMData::get_xsize(), mono(), nx, q, and sqrt().

19955                                                                        {
19956         int nx = d->get_xsize();
19957         int N = 1 + int((sqrt(1.0 + 8.0*nx)-1.0)/2.0);
19958         vector<float> out(N+K+2);
19959         if(N*(N-1)/2 != nx) {
19960                 //print  "  incorrect dimension"
19961                 return out;}
19962         //  assign random objects as centers
19963         for(int i=0; i<N; i++) assign(i) = float(i);
19964         // shuffle
19965         for(int i=0; i<N; i++) {
19966                 int j = Util::get_irand(0,N-1);
19967                 float temp = assign(i);
19968                 assign(i) = assign(j);
19969                 assign(j) = temp;
19970         }
19971         for(int k=0; k<K; k++) cent(k) = float(assign(k));
19972         //for(int k=0; k<K; k++) cout<<cent(k)<<"    ";cout<<endl;
19973         //
19974         for(int i=0; i<N; i++) assign(i) = 0.0f;
19975         float qm, dispold = 1.1e22f, disp = 1.0e22f, na=0.0f;
19976         bool change = true;
19977         int it = -1;
19978         int ct = -1;
19979         while ((change && disp < dispold) || ct > 0) {
19980 
19981                 change = false;
19982                 dispold = disp;
19983                 it++;
19984 
19985                 // dispersion is a sum of distance from objects to object center
19986                 disp = 0.0f;
19987                 ct = 0;
19988                 for(int i=0; i<N; i++) {
19989                         qm = 1.0e23f;
19990                         for(int k=0; k<K; k++) {
19991                                 if(float(i) == cent(k)) {
19992                                         qm = 0.0f;
19993                                         na = (float)k;
19994                                 } else {
19995                                         float dt = (*d)(mono(i,int(cent(k))));
19996                                         if(dt < qm) {
19997                                                 qm = dt;
19998                                                 na = (float)k;
19999                                         }
20000                                 }
20001                         }
20002 
20003 
20004                         // Simulated annealing
20005                         if(exp(-1.0/float(T)) > Util::get_irand(1,1000)/1000.0) {
20006                             na = (float)(Util::get_irand(0, K));
20007                             qm = (*d)(mono(i,int(na)));
20008                             ct++;
20009                         }
20010 
20011                         disp += qm;
20012 
20013                         if(na != assign(i)) {
20014                                 assign(i) = na;
20015                                 change = true;
20016                         }
20017                 }
20018 
20019                 //cout<<"Iteration:  "<<it<< " disp " <<disp << " T " << T << " disturb " << ct << endl;
20020                 T = T*F;
20021 
20022         //for(int k=0; k<N; k++) cout<<assign(k)<<"    ";cout<<endl;
20023                 //print disp
20024                 //print  assign
20025                 // find centers
20026                 for(int k=0; k<K; k++) {
20027                         qm = 1.0e23f;
20028                         for(int i=0; i<N; i++) {
20029                                 if(assign(i) == float(k)) {
20030                                         float q = 0.0;
20031                                         for(int j=0; j<N; j++) {
20032                                                 if(assign(j) == float(k)) {
20033                                                                 //it cannot be the same object
20034                                                         if(i != j)  q += (*d)(mono(i,j));
20035                                                         //cout<<q<<"   "<<i<<"   "<<j<<"   "<<k<<endl;}
20036                                                 }
20037                                         }
20038                                         if(q < qm) {
20039                                                 //cout<<qm<<"   "<<q<<"   "<<i<<"   "<<k<<endl;
20040                                                 qm = q;
20041                                                 cent(k) = float(i);
20042                                         }
20043                                 }
20044                         }
20045                 }
20046         //for(int k=0; k<K; k++) cout<<cent(k)<<"    ";cout<<endl;cout<<disp<<endl;
20047         }
20048         out[N+K] = disp;
20049         out[N+K+1] = float(it);
20050         return  out;
20051 }

double Util::cml_disc const vector< EMData * > &  data,
vector< int >  com,
vector< int >  seq,
vector< float >  weights,
int  n_lines
[static]
 

2009-03-30 15:44:05 JB.

Compute the discrepancy belong all common-lines

Definition at line 5033 of file util_sparx.cpp.

References data, EMAN::EMData::get_data(), and EMAN::EMData::get_xsize().

05033                                                                                                                        {
05034     double res = 0;
05035     double buf = 0;
05036     float* line_1;
05037     float* line_2;
05038     int i, n, ind;
05039     int lnlen = data[0]->get_xsize();
05040     for (n=0; n<n_lines; ++n) {
05041         ind = n*2;
05042         line_1 = data[seq[ind]]->get_data() + com[ind] * lnlen;
05043         line_2 = data[seq[ind+1]]->get_data() + com[ind+1] *lnlen;
05044         buf = 0;
05045         for (i=0; i<lnlen; ++i) {
05046             buf += (line_1[i]-line_2[i])*(line_1[i]-line_2[i]);
05047         }
05048         res += buf * weights[n];
05049     }
05050 
05051     return res;
05052 
05053 }

vector< double > Util::cml_init_rot vector< float >  Ori  )  [static]
 

2009-03-25 15:35:05 JB.

This function prepare rotation matrix for common-lines

Definition at line 4810 of file util_sparx.cpp.

04810                                                   {
04811     int nb_ori = Ori.size() / 4;
04812     int i, ind;
04813     float ph, th, ps;
04814     double cph, cth, cps, sph, sth, sps;
04815     vector<double> Rot(nb_ori*9);
04816     for (i=0; i<nb_ori; ++i){
04817         ind = i*4;
04818         // spider convention phi=psi-90, psi=phi+90
04819         ph = Ori[ind+2]-90;
04820         th = Ori[ind+1];
04821         ps = Ori[ind]+90;
04822         ph *= deg_rad;
04823         th *= deg_rad;
04824         ps *= deg_rad;
04825         // pre-calculate some trigo stuffs
04826         cph = cos(ph);
04827         cth = cos(th);
04828         cps = cos(ps);
04829         sph = sin(ph);
04830         sth = sin(th);
04831         sps = sin(ps);
04832         // fill rotation matrix
04833         ind = i*9;
04834         Rot[ind] = cph*cps-cth*sps*sph;
04835         Rot[ind+1] = cph*sps+cth*cps*sph;
04836         Rot[ind+2] = sth*sph;
04837         Rot[ind+3] = -sph*cps-cth*sps*cph;
04838         Rot[ind+4] = -sph*sps+cth*cps*cph;
04839         Rot[ind+5] = sth*cph;
04840         Rot[ind+6] = sth*sps;
04841         Rot[ind+7] = -sth*cps;
04842         Rot[ind+8] = cth;
04843     }
04844 
04845     return Rot;
04846 }

vector< double > Util::cml_line_in3d vector< float >  Ori,
vector< int >  seq,
int  nprj,
int  nlines
[static]
 

2009-03-26 10:46:14 JB.

This function calculate all common-lines in space for Voronoi

Definition at line 4978 of file util_sparx.cpp.

References norm(), nx, ny, rad_deg, and sqrt().

04978                                                                                      {
04979     // seq is the pairwise index ij: 0, 1, 0, 2, 0, 3, 1, 2, 1, 3, 2, 3
04980     vector<double> cml(2*nlines); // [phi, theta] / line
04981     float ph1, th1;
04982     float ph2, th2;
04983     double nx, ny, nz;
04984     double norm;
04985     double sth1=0, sph1=0, cth1=0, cph1=0;
04986     double sth2, sph2, cth2, cph2;
04987     int l, ind, c;
04988     int mem = -1;
04989     for (l=0; l<nlines; ++l){
04990         c = 2*l;
04991         if (seq[c]!=mem){
04992             mem = seq[c];
04993             ind = 4*seq[c];
04994             ph1 = Ori[ind]*deg_rad;
04995             th1 = Ori[ind+1]*deg_rad;
04996             sth1 = sin(th1);
04997             sph1 = sin(ph1);
04998             cth1 = cos(th1);
04999             cph1 = cos(ph1);
05000         }
05001         ind = 4*seq[c+1];
05002         ph2 = Ori[ind]*deg_rad;
05003         th2 = Ori[ind+1]*deg_rad;
05004         sth2 = sin(th2);
05005         cth2 = cos(th2);
05006         sph2 = sin(ph2);
05007         cph2 = cos(ph2);
05008         // cross product
05009         nx = sth1*cph1*cth2 - cth1*sth2*cph2;
05010         ny = cth1*sth2*sph2 - cth2*sth1*sph1;
05011         nz = sth1*sph1*sth2*cph2 - sth1*cph1*sth2*sph2;
05012         norm = sqrt(nx*nx+ny*ny+nz*nz);
05013         nx /= norm;
05014         ny /= norm;
05015         nz /= norm;
05016         // apply mirror if need
05017         if (nz<0) {nx=-nx; ny=-ny; nz=-nz;}
05018         // compute theta and phi
05019         cml[c+1] = acos(nz);
05020         if (cml[c+1] == 0) {cml[c] = 0;}
05021         else {
05022             cml[c+1] *= rad_deg;
05023             if (cml[c+1] > 89.99) {cml[c+1] = 89.99;} // this fix some pb in Voronoi
05024             cml[c] = rad_deg * atan2(nx, ny);
05025             cml[c] = fmod(360 + cml[c], 360);
05026 
05027         }
05028     }
05029 
05030     return cml;
05031 }

vector< int > Util::cml_line_insino vector< float >  Rot,
int  i_prj,
int  n_prj
[static]
 

2009-03-25 15:35:53 JB.

This function calculates common-lines between sinogram

Definition at line 4879 of file util_sparx.cpp.

References abs, b, nint180(), and rad_deg.

04879                                                                         {
04880     vector<int> com(2*(n_prj - 1));
04881     int a = i_prj*9;
04882     int i, b, c;
04883     int n1=0, n2=0;
04884     float vmax = 1 - 1.0e-6f;
04885     double r11, r12, r13, r23, r31, r32, r33;
04886 
04887     c = 0;
04888     for (i=0; i<n_prj; ++i){
04889         if (i!=i_prj){
04890             b = i*9;
04891             // this is equivalent to R = A*B'
04892             r11 = Rot[a]*Rot[b]+Rot[a+1]*Rot[b+1]+Rot[a+2]*Rot[b+2];
04893             r12 = Rot[a]*Rot[b+3]+Rot[a+1]*Rot[b+4]+Rot[a+2]*Rot[b+5];
04894             r13 = Rot[a]*Rot[b+6]+Rot[a+1]*Rot[b+7]+Rot[a+2]*Rot[b+8];
04895             r23 = Rot[a+3]*Rot[b+6]+Rot[a+4]*Rot[b+7]+Rot[a+5]*Rot[b+8];
04896             r31 = Rot[a+6]*Rot[b]+Rot[a+7]*Rot[b+1]+Rot[a+8]*Rot[b+2];
04897             r32 = Rot[a+6]*Rot[b+3]+Rot[a+7]*Rot[b+4]+Rot[a+8]*Rot[b+5];
04898             r33 = Rot[a+6]*Rot[b+6]+Rot[a+7]*Rot[b+7]+Rot[a+8]*Rot[b+8];
04899             if (r33 > vmax) {
04900                 n2 = 270;
04901                 n1 = 270 + nint180((float)(rad_deg*atan2(r12, r11)));
04902             }
04903             else if (r33 < -vmax) {
04904                 n2 = 270;
04905                 n1 = 270 - nint180((float)(rad_deg*atan2(r12, r11)));
04906             } else {
04907                 n2 = nint180((float)(rad_deg*atan2(r31, -r32)));
04908                 n1 = nint180((float)(rad_deg*atan2(r13, r23)));
04909                 if (n1 < 0) {n1 += 360;}
04910                 if (n2 <= 0) {n2 = abs(n2);}
04911                 else {n2 = 360 - n2;}
04912             }
04913 
04914             if (n1 >= 360){n1 = n1 % 360;}
04915             if (n2 >= 360){n2 = n2 % 360;}
04916 
04917             // store common-lines
04918             b = c*2;
04919             com[b] = n1;
04920             com[b+1] = n2;
04921             ++c;
04922         }
04923     }
04924 
04925     return com;
04926 
04927 }

vector< int > Util::cml_line_insino_all vector< float >  Rot,
vector< int >  seq,
int  n_prj,
int  n_lines
[static]
 

2009-03-30 15:35:07 JB.

This function calculates all common-lines between sinogram

Definition at line 4929 of file util_sparx.cpp.

References abs, b, nint180(), and rad_deg.

04929                                                                                           {
04930     vector<int> com(2*n_lines);
04931     int a=0, b, c, l;
04932     int n1=0, n2=0, mem=-1;
04933     float vmax = 1 - 1.0e-6f;
04934     double r11, r12, r13, r23, r31, r32, r33;
04935     c = 0;
04936     for (l=0; l<n_lines; ++l){
04937         c = 2*l;
04938         if (seq[c]!=mem){
04939             mem = seq[c];
04940             a = seq[c]*9;
04941         }
04942         b = seq[c+1]*9;
04943 
04944         // this is equivalent to R = A*B'
04945         r11 = Rot[a]*Rot[b]+Rot[a+1]*Rot[b+1]+Rot[a+2]*Rot[b+2];
04946         r12 = Rot[a]*Rot[b+3]+Rot[a+1]*Rot[b+4]+Rot[a+2]*Rot[b+5];
04947         r13 = Rot[a]*Rot[b+6]+Rot[a+1]*Rot[b+7]+Rot[a+2]*Rot[b+8];
04948         r23 = Rot[a+3]*Rot[b+6]+Rot[a+4]*Rot[b+7]+Rot[a+5]*Rot[b+8];
04949         r31 = Rot[a+6]*Rot[b]+Rot[a+7]*Rot[b+1]+Rot[a+8]*Rot[b+2];
04950         r32 = Rot[a+6]*Rot[b+3]+Rot[a+7]*Rot[b+4]+Rot[a+8]*Rot[b+5];
04951         r33 = Rot[a+6]*Rot[b+6]+Rot[a+7]*Rot[b+7]+Rot[a+8]*Rot[b+8];
04952         if (r33 > vmax) {
04953             n2 = 270;
04954             n1 = 270 + nint180((float)(rad_deg*atan2(r12, r11)));
04955         }
04956         else if (r33 < -vmax) {
04957             n2 = 270;
04958             n1 = 270 - nint180((float)(rad_deg*atan2(r12, r11)));
04959         } else {
04960             n2 = nint180((float)(rad_deg*atan2(r31, -r32)));
04961             n1 = nint180((float)(rad_deg*atan2(r13, r23)));
04962             if (n1 < 0) {n1 += 360;}
04963             if (n2 <= 0) {n2 = abs(n2);}
04964             else {n2 = 360 - n2;}
04965         }
04966         if (n1 >= 360){n1 = n1 % 360;}
04967         if (n2 >= 360){n2 = n2 % 360;}
04968 
04969         // store common-lines
04970         com[c] = n1;
04971         com[c+1] = n2;
04972     }
04973 
04974     return com;
04975 
04976 }

void Util::cml_prepare_line EMData sino,
EMData line,
int  ilf,
int  ihf,
int  pos_line,
int  nblines
[static]
 

This function prepare the line from sinogram by cutting off some frequencies, and creating the mirror part (complexe conjugate of the first part).

Then both lines (mirror and without) are drop to the sinogram. line is in Fourrier space, ilf low frequency, ihf high frequency, nblines number of lines of the half sinogram (the non miror part), sino the sinogram, pos_line the position of the line in the sino.

Definition at line 4792 of file util_sparx.cpp.

References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), nx, and EMAN::EMData::update().

04792                                                                                                   {
04793     int j;
04794     int nx = sino->get_xsize();
04795     int i = nx * pos_line;
04796     float r1, r2;
04797     float *line_ptr = line->get_data();
04798     float *sino_ptr = sino->get_data();
04799     for (j=ilf;j<=ihf; j += 2) {
04800         r1 = line_ptr[j];
04801         r2 = line_ptr[j + 1];
04802         sino_ptr[i + j - ilf] = r1;
04803         sino_ptr[i + j - ilf + 1] = r2;
04804         sino_ptr[i + nx * nblines + j - ilf] = r1;
04805         sino_ptr[i + nx * nblines + j - ilf + 1] = -r2;
04806     }
04807     sino->update();
04808 }

vector<double> EMAN::Util::cml_spin_psi const vector< EMData * > &  data,
vector< int >  com,
vector< float >  weights,
int  iprj,
vector< int >  iw,
int  n_psi,
int  d_psi,
int  n_prj
[static]
 

2009-03-26 11:37:53 JB.

This function spin all angle psi and evaluate the partial discrepancy belong common-lines

vector< float > Util::cml_update_rot vector< float >  Rot,
int  iprj,
float  nph,
float  th,
float  nps
[static]
 

2009-03-25 15:35:37 JB.

this function update only one rotation amtrix according a new orientation

Definition at line 4848 of file util_sparx.cpp.

04848                                                                                              {
04849     float ph, ps;
04850     double cph, cth, cps, sph, sth, sps;
04851     int ind = iprj*9;
04852     // spider convention phi=psi-90, psi=phi+90
04853     ph = nps-90;
04854     ps = nph+90;
04855     ph *= deg_rad;
04856     th *= deg_rad;
04857     ps *= deg_rad;
04858     // pre-calculate some trigo stuffs
04859     cph = cos(ph);
04860     cth = cos(th);
04861     cps = cos(ps);
04862     sph = sin(ph);
04863     sth = sin(th);
04864     sps = sin(ps);
04865     // fill rotation matrix
04866     Rot[ind] = (float)(cph*cps-cth*sps*sph);
04867     Rot[ind+1] = (float)(cph*sps+cth*cps*sph);
04868     Rot[ind+2] = (float)(sth*sph);
04869     Rot[ind+3] = (float)(-sph*cps-cth*sps*cph);
04870     Rot[ind+4] = (float)(-sph*sps+cth*cps*cph);
04871     Rot[ind+5] = (float)(sth*cph);
04872     Rot[ind+6] = (float)(sth*sps);
04873     Rot[ind+7] = (float)(-sth*cps);
04874     Rot[ind+8] = (float)(cth);
04875 
04876     return Rot;
04877 }

vector< double > Util::cml_weights const vector< float > &  cml  )  [static]
 

Definition at line 4702 of file util_sparx.cpp.

References Assert, ori_t::id, ori_t::iphi, ori_t::itht, PI2, and vrdg().

04702                                                         {
04703         static const int NBIN = 100;
04704         int nline=cml.size()/2;
04705         vector<double> weights(nline);
04706 
04707         vector<ori_t> angs(nline);
04708         for( int i=0; i < nline; ++i ) {
04709                 angs[i].iphi = int( NBIN*cml[2*i] );
04710                 angs[i].itht = int( NBIN*cml[2*i+1] );
04711                 if( angs[i].itht == 180*NBIN ) angs[i].itht = 0;
04712                 angs[i].id = i;
04713         }
04714 
04715         //std::cout << "# of angs: " << angs.size() << std::endl;
04716 
04717         std::sort( angs.begin(), angs.end(), cmpang() );
04718 
04719         vector<float> newphi;
04720         vector<float> newtht;
04721         vector< vector<int> > indices;
04722 
04723         int curt_iphi = -1;
04724         int curt_itht = -1;
04725         for(unsigned int i=0 ;i < angs.size(); ++i ) {
04726                 if( angs[i].iphi==curt_iphi && angs[i].itht==curt_itht ) {
04727                         Assert( indices.size() > 0 );
04728                         indices.back().push_back(angs[i].id);
04729                 } else {
04730                         curt_iphi = angs[i].iphi;
04731                         curt_itht = angs[i].itht;
04732 
04733                         newphi.push_back( float(curt_iphi)/NBIN );
04734                         newtht.push_back( float(curt_itht)/NBIN );
04735                         indices.push_back( vector<int>(1,angs[i].id) );
04736                 }
04737         }
04738 
04739         //std::cout << "# of indpendent ang: " << newphi.size() << std::endl;
04740 
04741 
04742         int num_agl = newphi.size();
04743 
04744         if(num_agl>2) {
04745                 vector<double> w=Util::vrdg(newphi, newtht);
04746 
04747                 Assert( w.size()==newphi.size() );
04748                 Assert( indices.size()==newphi.size() );
04749 
04750                 for(unsigned int i=0; i < newphi.size(); ++i ) {
04751                     /*
04752                     std::cout << "phi,tht,w,n: ";
04753                     std::cout << boost::format( "%10.3f" ) % newphi[i] << " ";
04754                     std::cout << boost::format( "%10.3f" ) % newtht[i] << " ";
04755                     std::cout << boost::format( "%8.6f"  ) % w[i] << " ";
04756                     std::cout << indices[i].size() << "(";
04757                     */
04758 
04759                     for(unsigned int j=0; j < indices[i].size(); ++j ) {
04760                             int id = indices[i][j];
04761                             weights[id] = w[i]/indices[i].size();
04762                             //std::cout << id << " ";
04763                     }
04764 
04765                     //std::cout << ")" << std::endl;
04766 
04767                 }
04768         } else {
04769                 cout<<"warning in Util.cml_weights"<<endl;
04770                 double val = PI2/float(nline);
04771                 for(int i=0; i<nline; i++)  weights[i]=val;
04772         }
04773 
04774         return weights;
04775 
04776 }

bool Util::cmp1 tmpstruct  tmp1,
tmpstruct  tmp2
[static]
 

Definition at line 7272 of file util_sparx.cpp.

References EMAN::Util::tmpstruct::theta1.

07273 {
07274         return(tmp1.theta1 < tmp2.theta1);
07275 }

bool Util::cmp2 tmpstruct  tmp1,
tmpstruct  tmp2
[static]
 

Definition at line 7277 of file util_sparx.cpp.

References EMAN::Util::tmpstruct::key1.

07278 {
07279         return(tmp1.key1 < tmp2.key1);
07280 }

void Util::colreverse float *  beg,
float *  end,
int  nx
[static]
 

Definition at line 5463 of file util_sparx.cpp.

References nx.

Referenced by cyclicshift(), and slicereverse().

05463                                                     {
05464         float* tmp = new float[nx];
05465         int n = (end - beg)/nx;
05466         int nhalf = n/2;
05467         for (int i = 0; i < nhalf; i++) {
05468                 // swap col i and col n-1-i
05469                 memcpy(tmp, beg+i*nx, nx*sizeof(float));
05470                 memcpy(beg+i*nx, beg+(n-1-i)*nx, nx*sizeof(float));
05471                 memcpy(beg+(n-1-i)*nx, tmp, nx*sizeof(float));
05472         }
05473         delete[] tmp;
05474 }

EMData * Util::compress_image_mask EMData image,
EMData mask
[static]
 

Definition at line 6155 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().

06156 {
06157         /***********
06158         ***get the size of the image for validation purpose
06159         **************/
06160         int nx = image->get_xsize(),ny = image->get_ysize(),nz = image->get_zsize();  //Aren't  these  implied?  Please check and let me know, PAP.
06161         /********
06162         ***Exception Handle
06163         *************/
06164         if(nx != mask->get_xsize() || ny != mask->get_ysize() || nz != mask->get_zsize())
06165                 throw ImageDimensionException("The dimension of the image does not match the dimension of the mask!");
06166 
06167         size_t i, size = (size_t)nx*ny*nz;
06168 
06169         float* img_ptr = image->get_data();
06170         float* mask_ptr = mask->get_data();
06171 
06172         int ln=0;  //length of the output image = number of points under the mask.
06173         for(i = 0;i < size;i++) if(mask_ptr[i] > 0.5f) ln++;
06174 
06175         EMData* new_image = new EMData();
06176         new_image->set_size(ln,1,1); /* set size of the new image */
06177         float *new_ptr    = new_image->get_data();
06178 
06179         ln=-1;
06180         for(i = 0;i < size;i++){
06181                 if(mask_ptr[i] > 0.5f) {
06182                         ln++;
06183                         new_ptr[ln]=img_ptr[i];
06184                 }
06185         }
06186 
06187         return new_image;
06188 }

int Util::coveig int  n,
float *  covmat,
float *  eigval,
float *  eigvec
[static]
 

This file is a part of util.h, To use this file's functions, you should include "util.h" NEVER directly include this file.

Definition at line 6284 of file util_sparx.cpp.

References covmat, eigval, eigvec, and ssyev_().

06285 {
06286         // n size of the covariance/correlation matrix
06287         // covmat --- covariance/correlation matrix (n by n)
06288         // eigval --- returns eigenvalues
06289         // eigvec --- returns eigenvectors
06290 
06291         ENTERFUNC;
06292 
06293         int i;
06294 
06295         // make a copy of covmat so that it will not be overwritten
06296         for ( i = 0 ; i < n * n ; i++ )   eigvec[i] = covmat[i];
06297 
06298         char NEEDV = 'V';
06299         char UPLO = 'U';
06300         int lwork = -1;
06301         int info = 0;
06302         float *work, wsize;
06303 
06304         //  query to get optimal workspace
06305         ssyev_(&NEEDV, &UPLO, &n, eigvec, &n, eigval, &wsize, &lwork, &info);
06306         lwork = (int)wsize;
06307 
06308         work = (float *)calloc(lwork, sizeof(float));
06309         //  calculate eigs
06310         ssyev_(&NEEDV, &UPLO, &n, eigvec, &n, eigval, work, &lwork, &info);
06311         free(work);
06312         EXITFUNC;
06313         return info;
06314 }

Dict Util::coveig_for_py int  ncov,
const vector< float > &  covmatpy
[static]
 

same function than Util::coveig but wrapped to use directly in python code

Definition at line 6316 of file util_sparx.cpp.

References coveig(), covmat, eigval, eigvec, EMAN::Dict::size(), and status.

06317 {
06318 
06319         ENTERFUNC;
06320         int len = covmatpy.size();
06321         float *eigvec;
06322         float *eigval;
06323         float *covmat;
06324         int status = 0;
06325         eigval = (float*)calloc(ncov,sizeof(float));
06326         eigvec = (float*)calloc(ncov*ncov,sizeof(float));
06327         covmat = (float*)calloc(ncov*ncov, sizeof(float));
06328 
06329         const float *covmat_ptr;
06330         covmat_ptr = &covmatpy[0];
06331         for(int i=0;i<len;i++){
06332             covmat[i] = covmat_ptr[i];
06333         }
06334 
06335         status = Util::coveig(ncov, covmat, eigval, eigvec);
06336 
06337         vector<float> eigval_py(ncov);
06338         const float *eigval_ptr;
06339         eigval_ptr = &eigval[0];
06340         for(int i=0;i<ncov;i++){
06341             eigval_py[i] = eigval_ptr[i];
06342         }
06343 
06344         vector<float> eigvec_py(ncov*ncov);
06345         const float *eigvec_ptr;
06346         eigvec_ptr = &eigvec[0];
06347         for(int i=0;i<ncov*ncov;i++){
06348             eigvec_py[i] = eigvec_ptr[i];
06349         }
06350 
06351         Dict res;
06352         res["eigval"] = eigval_py;
06353         res["eigvec"] = eigvec_py;
06354 
06355         EXITFUNC;
06356         return res;
06357 }

Dict Util::Crosrng_e EMData circ1,
EMData circ2,
vector< int >  numr,
int  neg
[static]
 

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 }

Dict Util::Crosrng_ew EMData circ1,
EMData circ2,
vector< int >  numr,
vector< float >  w,
int  neg
[static]
 

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 }

Dict Util::Crosrng_ms EMData circ1,
EMData circ2,
vector< int >  numr
[static]
 

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 }

Dict Util::Crosrng_ms_delta EMData circ1,
EMData circ2,
vector< int >  numr,
float  delta_start,
float  delta
[static]
 

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 }

EMData * Util::Crosrng_msg EMData circ1,
EMData circ2,
vector< int >  numr
[static]
 

checks both straight & mirrored positions input - fourier transforms of rings!! circ1 already multiplied by weights! returns EM object with 1D ccf

Definition at line 4195 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.

04195                                                                         {
04196 
04197    // dimension         circ1(lcirc),circ2(lcirc)
04198 
04199         int   ip, jc, numr3i, numr2i, i, j;
04200         float t1, t2, t3, t4, c1, c2, d1, d2;
04201 
04202         int nring = numr.size()/3;
04203         //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
04204         int maxrin = numr[numr.size()-1];
04205 
04206         float* circ1b = circ1->get_data();
04207         float* circ2b = circ2->get_data();
04208 
04209         // t(maxrin), q(maxrin)  // removed +2
04210         double *t, *q;
04211 
04212         q = (double*)calloc(maxrin,sizeof(double));
04213         t = (double*)calloc(maxrin,sizeof(double));
04214 
04215 #ifdef _WIN32
04216         ip = -(int)(log((float)maxrin)/log(2.0f));
04217 #else
04218         ip = -(int)(log2(maxrin));
04219 #endif  //_WIN32
04220 
04221         //  q - straight  = circ1 * conjg(circ2)
04222 
04223         //   t - mirrored  = conjg(circ1) * conjg(circ2)
04224 
04225         //   premultiply  arrays ie( circ12 = circ1 * circ2) much slower
04226 
04227         for (i=1; i<=nring; i++) {
04228 
04229                 numr3i = numr(3,i);
04230                 numr2i = numr(2,i);
04231 
04232                 t1   = circ1b(numr2i) * circ2b(numr2i);
04233                 q(1) = q(1)+t1;
04234                 t(1) = t(1)+t1;
04235 
04236                 t1   = circ1b(numr2i+1) * circ2b(numr2i+1);
04237                 if (numr3i == maxrin)  {
04238                         q(2) += t1;
04239                         t(2) += t1;
04240                 } else {
04241                         q(numr3i+1) += t1;
04242                         t(numr3i+1) += t1;
04243                 }
04244 
04245                 for (j=3; j<=numr3i; j=j+2) {
04246                         jc     = j+numr2i-1;
04247 
04248                         c1     = circ1b(jc);
04249                         c2     = circ1b(jc+1);
04250                         d1     = circ2b(jc);
04251                         d2     = circ2b(jc+1);
04252 
04253                         t1     = c1 * d1;
04254                         t3     = c1 * d2;
04255                         t2     = c2 * d2;
04256                         t4     = c2 * d1;
04257 
04258                         q(j)   += t1 + t2;
04259                         q(j+1) += - t3 + t4;
04260                         t(j)   += t1 - t2;
04261                         t(j+1) += - t3 - t4;
04262                 }
04263         }
04264 
04265         // straight
04266         fftr_d(q,ip);
04267 
04268         // mirrored
04269         fftr_d(t,ip);
04270 
04271         EMData* out = new EMData();
04272         out->set_size(maxrin,2,1);
04273         float *dout = out->get_data();
04274         for (int i=0; i<maxrin; i++) {dout(i,0)=static_cast<float>(q[i]); dout(i,1)=static_cast<float>(t[i]);}
04275         //out->set_size(maxrin,1,1);
04276         //float *dout = out->get_data();
04277         //for (int i=0; i<maxrin; i++) {dout(i,0)=q[i];}
04278         free(t);
04279         free(q);
04280         return out;
04281 }

EMData * Util::Crosrng_msg_m EMData circ1,
EMData circ2,
vector< int >  numr
[static]
 

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 4442 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.

04443 {
04444 
04445         int   ip, jc, numr3i, numr2i, i, j;
04446         float t1, t2, t3, t4, c1, c2, d1, d2;
04447 
04448         int nring = numr.size()/3;
04449         int maxrin = numr[numr.size()-1];
04450 
04451         float* circ1b = circ1->get_data();
04452         float* circ2b = circ2->get_data();
04453 
04454         double *t;
04455 
04456         t = (double*)calloc(maxrin,sizeof(double));
04457 
04458 #ifdef _WIN32
04459         ip = -(int)(log((float)maxrin)/log(2.0f));
04460 #else
04461         ip = -(int)(log2(maxrin));
04462 #endif  //_WIN32
04463 
04464          //   t - mirrored  = conjg(circ1) * conjg(circ2)
04465 
04466         for (i=1;i<=nring;i++) {
04467 
04468                 numr3i = numr(3,i);
04469                 numr2i = numr(2,i);
04470 
04471                 t1   = circ1b(numr2i) * circ2b(numr2i);
04472                 t(1) = t(1)+t1;
04473 
04474                 if (numr3i == maxrin)  {
04475                         t1   = circ1b(numr2i+1) * circ2b(numr2i+1);
04476                         t(2) = t(2)+t1;
04477                 }
04478 
04479                 for (j=3;j<=numr3i;j=j+2) {
04480                         jc     = j+numr2i-1;
04481 
04482                         c1     = circ1b(jc);
04483                         c2     = circ1b(jc+1);
04484                         d1     = circ2b(jc);
04485                         d2     = circ2b(jc+1);
04486 
04487                         t1     = c1 * d1;
04488                         t3     = c1 * d2;
04489                         t2     = c2 * d2;
04490                         t4     = c2 * d1;
04491 
04492                         t(j)   = t(j)   + t1 - t2;
04493                         t(j+1) = t(j+1) - t3 - t4;
04494                 }
04495         }
04496 
04497         // mirrored
04498         fftr_d(t,ip);
04499 
04500         EMData* out = new EMData();
04501         out->set_size(maxrin,1,1);
04502         float *dout = out->get_data();
04503         for (int i=0; i<maxrin; i++) dout[i]=static_cast<float>(t[i]);
04504         free(t);
04505         return out;
04506 
04507 }

EMData * Util::Crosrng_msg_s EMData circ1,
EMData circ2,
vector< int >  numr
[static]
 

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 4371 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().

04372 {
04373 
04374         int   ip, jc, numr3i, numr2i, i, j;
04375         float t1, t2, t3, t4, c1, c2, d1, d2;
04376 
04377         int nring = numr.size()/3;
04378         int maxrin = numr[numr.size()-1];
04379 
04380         float* circ1b = circ1->get_data();
04381         float* circ2b = circ2->get_data();
04382 
04383         double *q;
04384 
04385         q = (double*)calloc(maxrin,sizeof(double));
04386 
04387 #ifdef _WIN32
04388         ip = -(int)(log((float)maxrin)/log(2.0f));
04389 #else
04390         ip = -(int)(log2(maxrin));
04391 #endif  //_WIN32
04392 
04393          //  q - straight  = circ1 * conjg(circ2)
04394 
04395         for (i=1;i<=nring;i++) {
04396 
04397                 numr3i = numr(3,i);
04398                 numr2i = numr(2,i);
04399 
04400                 t1   = circ1b(numr2i) * circ2b(numr2i);
04401                 q(1) = q(1)+t1;
04402 
04403                 if (numr3i == maxrin)  {
04404                         t1   = circ1b(numr2i+1) * circ2b(numr2i+1);
04405                         q(2) = q(2)+t1;
04406                 } else {
04407                         t1              = circ1b(numr2i+1) * circ2b(numr2i+1);
04408                         q(numr3i+1) = q(numr3i+1)+t1;
04409                 }
04410 
04411                 for (j=3;j<=numr3i;j=j+2) {
04412                         jc     = j+numr2i-1;
04413 
04414                         c1     = circ1b(jc);
04415                         c2     = circ1b(jc+1);
04416                         d1     = circ2b(jc);
04417                         d2     = circ2b(jc+1);
04418 
04419                         t1     = c1 * d1;
04420                         t3     = c1 * d2;
04421                         t2     = c2 * d2;
04422                         t4     = c2 * d1;
04423 
04424                         q(j)   = q(j)   + t1 + t2;
04425                         q(j+1) = q(j+1) - t3 + t4;
04426                 }
04427         }
04428 
04429         // straight
04430         fftr_d(q,ip);
04431 
04432         EMData* out = new EMData();
04433         out->set_size(maxrin,1,1);
04434         float *dout = out->get_data();
04435         for (int i=0; i<maxrin; i++) dout[i]=static_cast<float>(q[i]);
04436         free(q);
04437         return out;
04438 
04439 }

void Util::Crosrng_msg_vec EMData circ1,
EMData circ2,
vector< int >  numr,
float *  q,
float *  t
[static]
 

checks both straight & mirrored positions input - fourier transforms of rings!! circ1 already multiplied by weights! returns EM object with 1D ccf

Definition at line 4299 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().

04299                                                                                              {
04300 
04301    // dimension         circ1(lcirc),circ2(lcirc)
04302 
04303         int   ip, jc, numr3i, numr2i, i, j;
04304         float t1, t2, t3, t4, c1, c2, d1, d2;
04305 
04306         int nring = numr.size()/3;
04307         //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
04308         int maxrin = numr[numr.size()-1];
04309 
04310         float* circ1b = circ1->get_data();
04311         float* circ2b = circ2->get_data();
04312 
04313 #ifdef _WIN32
04314         ip = -(int)(log((float)maxrin)/log(2.0f));
04315 #else
04316         ip = -(int)(log2(maxrin));
04317 #endif  //_WIN32
04318         for (int i=1; i<=maxrin; i++)  {q(i) = 0.0f; t(i) = 0.0f;}
04319 
04320         //  q - straight  = circ1 * conjg(circ2)
04321 
04322         //   t - mirrored  = conjg(circ1) * conjg(circ2)
04323 
04324         for (i=1; i<=nring; i++) {
04325 
04326                 numr3i = numr(3,i);
04327                 numr2i = numr(2,i);
04328 
04329                 t1   = circ1b(numr2i) * circ2b(numr2i);
04330                 q(1) += t1;
04331                 t(1) += t1;
04332 
04333                 t1   = circ1b(numr2i+1) * circ2b(numr2i+1);
04334                 if (numr3i == maxrin)  {
04335                         q(2) += t1;
04336                         t(2) += t1;
04337                 } else {
04338                         q(numr3i+1) += t1;
04339                         t(numr3i+1) += t1;
04340                 }
04341 
04342                 for (j=3; j<=numr3i; j=j+2) {
04343                         jc     = j+numr2i-1;
04344 
04345                         c1     = circ1b(jc);
04346                         c2     = circ1b(jc+1);
04347                         d1     = circ2b(jc);
04348                         d2     = circ2b(jc+1);
04349 
04350                         t1     = c1 * d1;
04351                         t3     = c1 * d2;
04352                         t2     = c2 * d2;
04353                         t4     = c2 * d1;
04354 
04355                         q(j)   += t1 + t2;
04356                         q(j+1) += -t3 + t4;
04357                         t(j)   += t1 - t2;
04358                         t(j+1) += -t3 - t4;
04359                 }
04360         }
04361         // straight
04362         fftr_q(q,ip);
04363         //for (int i=0; i<maxrin; i++) cout<<i<<"  B    "<<q[i]<<"       "<<t[i]<<endl;
04364 
04365         // mirrored
04366         fftr_q(t,ip);
04367 }

vector< float > Util::Crosrng_msg_vec_p EMData circ1,
EMData circ2,
vector< int >  numr
[static]
 

Definition at line 4284 of file util_sparx.cpp.

References circ1, circ2, Crosrng_msg_vec(), and numr.

04284                                                                                      {
04285 
04286         int maxrin = numr[numr.size()-1];
04287 
04288         vector<float> r(2*maxrin);
04289 
04290         Crosrng_msg_vec( circ1, circ2, numr, &r[0], &r[maxrin] );
04291 
04292         return r;
04293 }

Dict Util::Crosrng_ns EMData circ1,
EMData circ2,
vector< int >  numr
[static]
 

Definition at line 4096 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().

04096                                                                       {
04097         int nring = numr.size()/3;
04098         //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
04099         int maxrin = numr[numr.size()-1];
04100         double qn; float tot;
04101         float *circ1 = circ1p->get_data();
04102         float *circ2 = circ2p->get_data();
04103 /*
04104 c
04105 c  checks only straight position
04106 c
04107 c  input - fourier transforms of rings!!
04108 c  circ1 already multiplied by weights!
04109 c
04110 */
04111 
04112         // dimension             circ1(lcirc),circ2(lcirc)
04113 
04114         // q(maxrin), t7(-3:3)  //maxrin+2 removed
04115         double *q, t7[7];
04116 
04117         int   ip, jc, numr3i, numr2i, i, j, k, jtot = 0;
04118         float c1, c2, d1, d2, pos;
04119 
04120         qn  = 0.0;
04121         tot = 0.0;
04122 #ifdef _WIN32
04123         ip = -(int)(log((float)maxrin)/log(2.0f));
04124 #else
04125    ip = -(int)(log2(maxrin));
04126 #endif  //_WIN32
04127         //for (j=1; j<=maxrin;j++) cout <<"  "<<j<<"   "<<circ1(j)<<"   "<<circ2(j) <<endl;
04128 
04129         //  c - straight  = circ1 * conjg(circ2)
04130         //  zero q array
04131 
04132         q = (double*)calloc(maxrin,sizeof(double));
04133 
04134                         //   premultiply  arrays ie( circ12 = circ1 * circ2) much slower
04135         for (i=1; i<=nring; i++) {
04136 
04137                 numr3i = numr(3,i);   // Number of samples of this ring
04138                 numr2i = numr(2,i);   // The beginning point of this ring
04139 
04140                 q(1) += circ1(numr2i) * circ2(numr2i);
04141 
04142                 if (numr3i == maxrin)   q(2) += circ1(numr2i+1) * circ2(numr2i+1);
04143                 else  q(numr3i+1) += circ1(numr2i+1) * circ2(numr2i+1);
04144 
04145                 for (j=3; j<=numr3i; j += 2) {
04146                         jc     = j+numr2i-1;
04147 
04148 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i
04149 //                                ----- -----    ----- -----
04150 //                                 t1     t2      t3    t4
04151 
04152                         c1     = circ1(jc);
04153                         c2     = circ1(jc+1);
04154                         d1     = circ2(jc);
04155                         d2     = circ2(jc+1);
04156 
04157                         q(j)   += c1 * d1 + c2 * d2;
04158                         q(j+1) += -c1 * d2 + c2 * d1;
04159                 }
04160         }
04161 //for (j=1; j<=maxrin; j++) cout <<"  "<<j<<"   "<<q(j) <<endl;
04162         fftr_d(q,ip);
04163 
04164         qn  = -1.0e20;
04165         for (j=1; j<=maxrin; j++) {//cout <<"  "<<j<<"   "<<q(j) <<endl;
04166                 if (q(j) >= qn) {
04167                         qn  = q(j);
04168                         jtot = j;
04169                 }
04170         }
04171 
04172         for (k=-3; k<=3; k++)  {
04173                 j = ((jtot+k+maxrin-1)%maxrin)+1;
04174                 t7(k+4) = q(j);
04175         }
04176 
04177         // interpolate
04178         prb1d(t7,7,&pos);
04179         tot = (float)(jtot)+pos;
04180         // Do not interpolate
04181         //*tot = (float)(jtot);
04182 
04183         free(q);
04184 
04185         Dict retvals;
04186         retvals["qn"] = qn;
04187         retvals["tot"] = tot;
04188         return retvals;
04189 }

Dict Util::Crosrng_psi_0_180 EMData circ1,
EMData circ2,
vector< int >  numr,
float  psi_max
[static]
 

checks both straight & mirrored positions Find only positions within +/-pis_max of 0 and 180 (for helcal use) input - fourier transforms of rings! circ1 already multiplied by weights!

Definition at line 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 }

Dict Util::Crosrng_psi_0_180_no_mirror EMData circ1,
EMData circ2,
vector< int >  numr,
float  psi_max
[static]
 

Definition at line 3843 of file util_sparx.cpp.

References circ1, circ2, fftr_d(), EMAN::EMData::get_data(), log(), numr, prb1d(), q, EMAN::Dict::size(), t7, and tot.

Referenced by multiref_polar_ali_helical_90().

03843                                                                                                       {
03844         int nring = numr.size()/3;
03845         //int lcirc = numr[3*nring-2]+numr[3*nring-1]-1;
03846         int maxrin = numr[numr.size()-1];
03847         double qn; float tot;
03848         float *circ1 = circ1p->get_data();
03849         float *circ2 = circ2p->get_data();
03850 
03851         // dimension             circ1(lcirc),circ2(lcirc)
03852 
03853         // t(maxrin), q(maxrin), t7(-3:3)  //maxrin+2 removed
03854         double  *q, t7[7];
03855 
03856         int   ip, jc, numr3i, numr2i, i, j, k, jtot = 0;
03857         float t1, t2, t3, t4, c1, c2, d1, d2, pos;
03858 
03859         qn  = 0.0f;
03860         tot = 0.0f;
03861 #ifdef _WIN32
03862         ip = -(int)(log((float)maxrin)/log(2.0f));
03863 #else
03864         ip = -(int)(log2(maxrin));
03865 #endif  //_WIN32
03866   //for (j=1; j<=maxrin;j++) cout <<"  "<<j<<"   "<<circ1(j)<<"   "<<circ2(j) <<endl;
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         for (i=1; i<=nring; i++) {
03875 
03876                 numr3i = numr(3,i);   // Number of samples of this ring
03877                 numr2i = numr(2,i);   // The beginning point of this ring
03878 
03879                 t1   = circ1(numr2i) * circ2(numr2i);
03880                 q(1) += t1;
03881                 
03882 
03883                 t1   = circ1(numr2i+1) * circ2(numr2i+1);
03884                 if (numr3i == maxrin)  {
03885                         q(2) += t1;
03886                         
03887                 } else {
03888                         q(numr3i+1) += t1;
03889                 }
03890 
03891                 for (j=3; j<=numr3i; j += 2) {
03892                         jc     = j+numr2i-1;
03893 
03894 // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i
03895 //                                ----- -----    ----- -----
03896 //                                 t1     t2      t3    t4
03897 // Here, conj(c1+c2i)*conj(d1+d2i) = (c1*d1-c2*d2)+(-c1*d2-c2*d1)i
03898 //                                    ----- -----    ----- -----
03899 //                                     t1    t2       t3    t4
03900 
03901                         c1     = circ1(jc);
03902                         c2     = circ1(jc+1);
03903                         d1     = circ2(jc);
03904                         d2     = circ2(jc+1);
03905 
03906                         t1     = c1 * d1;
03907                         t2     = c2 * d2;
03908                         t3     = c1 * d2;
03909                         t4     = c2 * d1;
03910 
03911                         q(j)   += t1 + t2;
03912                         q(j+1) += -t3 + t4;
03913                 
03914                 }
03915         }
03916         //for (j=1; j<=maxrin; j++) cout <<"  "<<j<<"   "<<q(j) <<"   "<<t(j) <<endl;
03917         fftr_d(q,ip);
03918 
03919         int psi_range  = int(psi_max/360.0*maxrin+0.5);
03920         const int psi_0 = 0;
03921         int psi_180    = int(  180.0/360.0*maxrin+0.5);
03922 
03923         qn  = -1.0e20;
03924         for (k=-psi_range; k<=psi_range; k++) {
03925                 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;
03926                 if (q(j) >= qn) {
03927                         qn  = q(j);
03928                         jtot = j;
03929                 }
03930         }
03931 
03932         for (k=-psi_range; k<=psi_range; k++) {
03933                 j = (k+psi_180+maxrin-1)%maxrin+1; //cout <<" 270  "<<j<<"  "<<ang_n(j,modemo,maxrin) <<"  "<<float(j)/maxrin*360.0<<" "<<q(j) <<endl;
03934                 if (q(j) >= qn) {
03935                         qn  = q(j);
03936                         jtot = j;
03937                 }
03938         }
03939 
03940         for (k=-3; k<=3; k++) {
03941                 j = ((jtot+k+maxrin-1)%maxrin)+1;
03942                 t7(k+4) = q(j);
03943         }
03944 
03945         // interpolate
03946         prb1d(t7,7,&pos);
03947         tot = (float)(jtot)+pos;
03948         // Do not interpolate
03949         //tot = (float)(jtot);
03950 
03951         free(q);
03952 
03953         Dict retvals;
03954         retvals["qn"] = qn;
03955         retvals["tot"] = tot;
03956         
03957         return retvals;
03958 }

Dict Util::Crosrng_sm_psi EMData circ1,
EMData circ2,
vector< int >  numr,
float  psi,
int  flag
[static]
 

checks both straight & mirrored position input - fourier transforms of rings!! circ1 already multiplied by weights!

Definition at line 3962 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().

03962                                                                                                {
03963 // flag 0 - straignt, 1 - mirror
03964 
03965         int nring = numr.size()/3;
03966         int maxrin = numr[numr.size()-1];
03967         double qn; float tot; double qm; float tmt;
03968         float *circ1 = circ1p->get_data();
03969         float *circ2 = circ2p->get_data();
03970 
03971         double *q, t7[7];
03972 
03973         int   ip, jc, numr3i, numr2i, i, j, k, jtot = 0;
03974         float t1, t2, t3, t4, c1, c2, d1, d2, pos;
03975 
03976         qn  = 0.0f;
03977         qm  = 0.0f;
03978         tot = 0.0f;
03979         tmt = 0.0f;
03980 #ifdef _WIN32
03981         ip = -(int)(log((float)maxrin)/log(2.0f));
03982 #else
03983         ip = -(int)(log2(maxrin));
03984 #endif  //_WIN32
03985 
03986         //  c - straight  = circ1 * conjg(circ2)
03987         //  zero q array
03988 
03989         q = (double*)calloc(maxrin,sizeof(double));
03990 
03991    //   premultiply  arrays ie( circ12 = circ1 * circ2) much slower
03992         if (flag==0) {
03993                 for (i=1; i<=nring; i++) {
03994 
03995                         numr3i = numr(3,i);   // Number of samples of this ring
03996                         numr2i = numr(2,i);   // The beginning point of this ring
03997 
03998                         t1   = circ1(numr2i) * circ2(numr2i);
03999                         q(1) += t1;
04000 
04001                         t1   = circ1(numr2i+1) * circ2(numr2i+1);
04002                         if (numr3i == maxrin)  {
04003                                 q(2) += t1;
04004                         } else {
04005                                 q(numr3i+1) += t1;
04006                         }
04007 
04008                         for (j=3; j<=numr3i; j += 2) {
04009                                 jc     = j+numr2i-1;
04010 
04011         // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i
04012         //                                ----- -----    ----- -----
04013         //                                 t1     t2      t3    t4
04014 
04015                                 c1     = circ1(jc);
04016                                 c2     = circ1(jc+1);
04017                                 d1     = circ2(jc);
04018                                 d2     = circ2(jc+1);
04019 
04020                                 t1     = c1 * d1;
04021                                 t3     = c1 * d2;
04022                                 t2     = c2 * d2;
04023                                 t4     = c2 * d1;
04024 
04025                                 q(j)   += t1 + t2;
04026                                 q(j+1) += -t3 + t4;
04027                         }
04028                 }
04029         } else {
04030                 for (i=1; i<=nring; i++) {
04031 
04032                         numr3i = numr(3,i);   // Number of samples of this ring
04033                         numr2i = numr(2,i);   // The beginning point of this ring
04034 
04035                         t1   = circ1(numr2i) * circ2(numr2i);
04036                         q(1) += t1;
04037 
04038                         t1   = circ1(numr2i+1) * circ2(numr2i+1);
04039                         if (numr3i == maxrin)  {
04040                                 q(2) += t1;
04041                         } else {
04042                                 q(numr3i+1) += t1;
04043                         }
04044 
04045                         for (j=3; j<=numr3i; j += 2) {
04046                                 jc     = j+numr2i-1;
04047 
04048         // Here, (c1+c2i)*conj(d1+d2i) = (c1*d1+c2*d2)+(-c1*d2+c2*d1)i
04049         //                                ----- -----    ----- -----
04050         //                                 t1     t2      t3    t4
04051 
04052                                 c1     = circ1(jc);
04053                                 c2     = circ1(jc+1);
04054                                 d1     = circ2(jc);
04055                                 d2     = circ2(jc+1);
04056 
04057                                 t1     = c1 * d1;
04058                                 t3     = c1 * d2;
04059                                 t2     = c2 * d2;
04060                                 t4     = c2 * d1;
04061 
04062                                 q(j)   += t1 - t2;
04063                                 q(j+1) += -t3 - t4;
04064                         }
04065                 }
04066         }
04067         fftr_d(q,ip);
04068 
04069         qn  = -1.0e20;
04070         int psi_pos = int(psi/360.0*maxrin+0.5);
04071 
04072         for (k=-5; k<=5; k++) {
04073                 j = (psi_pos+maxrin-1)%maxrin+1;
04074                 if (q(j) >= qn) {
04075                         qn  = q(j);
04076                         jtot = j;
04077                 }
04078         }
04079 
04080         for (k=-3; k<=3; k++) {
04081                 j = ((jtot+k+maxrin-1)%maxrin)+1;
04082                 t7(k+4) = q(j);
04083         }
04084 
04085         // interpolate
04086         prb1d(t7,7,&pos);
04087         tot = (float)(jtot)+pos;
04088         free(q);
04089 
04090         Dict retvals;
04091         retvals["qn"] = qn;
04092         retvals["tot"] = tot;
04093         return retvals;
04094 }

EMData * Util::ctf_img int  nx,
int  ny,
int  nz,
float  dz,
float  ps,
float  voltage,
float  cs,
float  wgh,
float  b_factor,
float  dza,
float  azz,
float  sign
[static]
 

Definition at line 19827 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().

19828 {
19829         int   ix, iy, iz;
19830         int   i,  j, k;
19831         int   nr2, nl2;
19832         float  dzz, az, ak;
19833         float  scx, scy, scz;
19834         int offset = 2 - nx%2;
19835         int lsm = nx + offset;
19836         EMData* ctf_img1 = new EMData();
19837         ctf_img1->set_size(lsm, ny, nz);
19838         float freq = 1.0f/(2.0f*ps);
19839         scx = 2.0f/float(nx);
19840         if(ny>=1) scy = 2.0f/float(ny); else scy=0.0f;
19841         if(nz>=1) scz = 2.0f/float(nz); else scz=0.0f;
19842         nr2 = ny/2 ;
19843         nl2 = nz/2 ;
19844         for ( k=0; k<nz;k++) {
19845                 iz = k;  if(k>nl2) iz=k-nz;
19846                 for ( j=0; j<ny;j++) {
19847                         iy = j;  if(j>nr2) iy=j - ny;
19848                         for ( i=0; i<lsm/2; i++) {
19849                                 ix=i;
19850                                 ak=pow(ix*ix*scx*scx+iy*scy*iy*scy+iz*scz*iz*scz, 0.5f)*freq;
19851                                 if(ak!=0) az=0.0; else az=M_PI;
19852                                 dzz = dz + dza/2.0f*sin(2*(az-azz*M_PI/180.0f));
19853                                 (*ctf_img1) (i*2,j,k)   = Util::tf(dzz, ak, voltage, cs, wgh, b_factor, sign);
19854                                 (*ctf_img1) (i*2+1,j,k) = 0.0f;
19855                         }
19856                 }
19857         }
19858         ctf_img1->update();
19859         ctf_img1->set_complex(true);
19860         ctf_img1->set_ri(true);
19861         //ctf_img1->attr_dict["is_complex"] = 1;
19862         //ctf_img1->attr_dict["is_ri"] = 1;
19863         if(nx%2==0) ctf_img1->set_fftodd(false); else ctf_img1->set_fftodd(true);
19864         return ctf_img1;
19865 }

void Util::cyclicshift EMData image,
Dict  params
[static]
 

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/

Author:
Phani Ivatury
Date:
18-2006
See also:
http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Intro/Eg01/
A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8] A[9]

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 5483 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().

05483                                                  {
05484 
05485         if (image->is_complex()) throw ImageFormatException("Real image required for IntegerCyclicShift2DProcessor");
05486 
05487         int dx = params["dx"];
05488         int dy = params["dy"];
05489         int dz = params["dz"];
05490 
05491         // The reverse trick we're using shifts to the left (a negative shift)
05492         int nx = image->get_xsize();
05493         dx %= nx;
05494         if (dx < 0) dx += nx;
05495         int ny = image->get_ysize();
05496         dy %= ny;
05497         if (dy < 0) dy += ny;
05498         int nz = image->get_zsize();
05499         dz %= nz;
05500         if (dz < 0) dz += nz;
05501 
05502         int mx = -(dx - nx);
05503         int my = -(dy - ny);
05504         int mz = -(dz - nz);
05505 
05506         float* data = image->get_data();
05507         // x-reverses
05508         if (mx != 0) {
05509                 for (int iz = 0; iz < nz; iz++)
05510                        for (int iy = 0; iy < ny; iy++) {
05511                                 // reverses for column iy
05512                                 size_t offset = nx*iy + (size_t)nx*ny*iz; // starting location for column iy in slice iz
05513                                 reverse(&data[offset],&data[offset+mx]);
05514                                 reverse(&data[offset+mx],&data[offset+nx]);
05515                                 reverse(&data[offset],&data[offset+nx]);
05516                         }
05517         }
05518         // y-reverses
05519         if (my != 0) {
05520                 for (int iz = 0; iz < nz; iz++) {
05521                         size_t offset = (size_t)nx*ny*iz;
05522                         colreverse(&data[offset], &data[offset + my*nx], nx);
05523                         colreverse(&data[offset + my*nx], &data[offset + ny*nx], nx);
05524                         colreverse(&data[offset], &data[offset + ny*nx], nx);
05525                 }
05526         }
05527         if (mz != 0) {
05528                 slicereverse(&data[0], &data[(size_t)mz*ny*nx], nx, ny);
05529                 slicereverse(&data[mz*ny*nx], &data[(size_t)nz*ny*nx], nx, ny);
05530                 slicereverse(&data[0], &data[(size_t)nz*ny*nx], nx ,ny);
05531         }
05532         image->update();
05533 }

EMData * Util::decimate EMData img,
int  x_step,
int  y_step = 1,
int  z_step = 1
[static]
 

Definition at line 5277 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().

05278 {
05279         /* Exception Handle */
05280         if (!img) {
05281                 throw NullPointerException("NULL input image");
05282         }
05283         /* ============================== */
05284 
05285         // Get the size of the input image
05286         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
05287         /* ============================== */
05288 
05289 
05290         /* Exception Handle */
05291         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)
05292         {
05293                 LOGERR("Parameters for decimation cannot exceed the center of the image.");
05294                 throw ImageDimensionException("Parameters for decimation cannot exceed the center of the image.");
05295         }
05296         /* ============================== */
05297 
05298 
05299         /*    Calculation of the start point */
05300         int new_st_x=(nx/2)%x_step, new_st_y=(ny/2)%y_step, new_st_z=(nz/2)%z_step;
05301         /* ============================*/
05302 
05303 
05304         /* Calculation of the size of the decimated image */
05305         int rx=2*(nx/(2*x_step)), ry=2*(ny/(2*y_step)), rz=2*(nz/(2*z_step));
05306         int r1=int(ceil((nx-(x_step*rx))/(1.f*x_step))), r2=int(ceil((ny-(y_step*ry))/(1.f*y_step)));
05307         int r3=int(ceil((nz-(z_step*rz))/(1.f*z_step)));
05308         if(r1>1){r1=1;}
05309         if(r2>1){r2=1;}
05310         if(r3>1){r3=1;}
05311         int new_nx=rx+r1, new_ny=ry+r2, new_nz=rz+r3;
05312         /* ===========================================*/
05313 
05314 
05315         EMData* img2 = new EMData();
05316         img2->set_size(new_nx,new_ny,new_nz);
05317         float *new_ptr = img2->get_data();
05318         float *old_ptr = img->get_data();
05319         int iptr, jptr, kptr = 0;
05320         for (int k=new_st_z; k<nz; k+=z_step) {jptr=0;
05321                 for (int j=new_st_y; j<ny; j+=y_step) {iptr=0;
05322                         for (int i=new_st_x; i<nx; i+=x_step) {
05323                                 new_ptr(iptr,jptr,kptr) = old_ptr(i,j,k);
05324                         iptr++;}
05325                 jptr++;}
05326         kptr++;}
05327         img2->update();
05328         return img2;
05329 }

void Util::disorder2 double *  x,
double *  y,
int *  key,
int  len
[static]
 

Definition at line 7788 of file util_sparx.cpp.

References key, x, and y.

07789 {
07790         ENTERFUNC;
07791         int k, i;
07792         for(i=0; i<len; i++) key[i]=i+1;
07793 
07794         for(i = 0; i<len;i++){
07795                 k = rand()%len;
07796                 std::swap(key[k], key[i]);
07797                 std::swap(x[k], x[i]);
07798                 std::swap(y[k], y[i]);
07799         }
07800         EXITFUNC;
07801 }

void Util::div_filter EMData img,
EMData img1
[static]
 

Definition at line 17747 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().

17748 {
17749         ENTERFUNC;
17750         /* Exception Handle */
17751         if (!img) {
17752                 throw NullPointerException("NULL input image");
17753         }
17754         /* ========= img /= img1 ===================== */
17755 
17756         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17757         size_t size = (size_t)nx*ny*nz;
17758         float *img_ptr  = img->get_data();
17759         float *img1_ptr = img1->get_data();
17760         if(img->is_complex()) {
17761                 for (size_t i=0; i<size; i+=2) {
17762                         if(img1_ptr[i] > 1.e-10f) {
17763                         img_ptr[i]   /= img1_ptr[i];
17764                         img_ptr[i+1] /= img1_ptr[i];
17765                         } else img_ptr[i] = img_ptr[i+1] = 0.0f;
17766                 }
17767         } else throw ImageFormatException("Only Fourier image allowed");
17768 
17769         img->update();
17770 
17771         EXITFUNC;
17772 }

void Util::div_img EMData img,
EMData img1
[static]
 

Definition at line 17718 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().

17719 {
17720         ENTERFUNC;
17721         /* Exception Handle */
17722         if (!img) {
17723                 throw NullPointerException("NULL input image");
17724         }
17725         /* ========= img /= img1 ===================== */
17726 
17727         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17728         size_t size = (size_t)nx*ny*nz;
17729         float *img_ptr  = img->get_data();
17730         float *img1_ptr = img1->get_data();
17731         if(img->is_complex()) {
17732                 float  sq2;
17733                 for (size_t i=0; i<size; i+=2) {
17734                         sq2 = 1.0f/(img1_ptr[i] * img1_ptr[i]   + img1_ptr[i+1] * img1_ptr[i+1]);
17735                         float tmp    = sq2*(img_ptr[i] * img1_ptr[i]   + img_ptr[i+1] * img1_ptr[i+1]) ;
17736                         img_ptr[i+1] = sq2*(img_ptr[i+1] * img1_ptr[i] - img_ptr[i] * img1_ptr[i+1]) ;
17737                         img_ptr[i]   = tmp;
17738                 }
17739         } else {
17740                 for (size_t i=0; i<size; ++i) img_ptr[i] /= img1_ptr[i];
17741         }
17742         img->update();
17743 
17744         EXITFUNC;
17745 }

EMData * Util::divn_filter EMData img,
EMData img1
[static]
 

Definition at line 17543 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().

17544 {
17545         ENTERFUNC;
17546         /* Exception Handle */
17547         if (!img) {
17548                 throw NullPointerException("NULL input image");
17549         }
17550         /* ========= img /= img1 ===================== */
17551 
17552         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17553         size_t size = (size_t)nx*ny*nz;
17554         EMData * img2 = img->copy_head();
17555         float *img_ptr  =img->get_data();
17556         float *img1_ptr = img1->get_data();
17557         float *img2_ptr = img2->get_data();
17558         if(img->is_complex()) {
17559                 for (size_t i=0; i<size; i+=2) {
17560                         if(img1_ptr[i] > 1.e-10f) {
17561                         img2_ptr[i]   = img_ptr[i]  /img1_ptr[i];
17562                         img2_ptr[i+1] = img_ptr[i+1]/img1_ptr[i];
17563                         } else img2_ptr[i] = img2_ptr[i+1] = 0.0f;
17564                 }
17565         } else  throw ImageFormatException("Only Fourier image allowed");
17566 
17567         img->update();
17568 
17569         EXITFUNC;
17570         return img2;
17571 }

EMData * Util::divn_img EMData img,
EMData img1
[static]
 

Definition at line 17510 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().

17511 {
17512         ENTERFUNC;
17513         /* Exception Handle */
17514         if (!img) {
17515                 throw NullPointerException("NULL input image");
17516         }
17517         /* ==============   output = img / img1   ================ */
17518 
17519         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17520         size_t size = (size_t)nx*ny*nz;
17521         EMData * img2 = img->copy_head();
17522         float *img_ptr  =img->get_data();
17523         float *img2_ptr = img2->get_data();
17524         float *img1_ptr = img1->get_data();
17525         if(img->is_complex()) {
17526                 float  sq2;
17527                 for (size_t i=0; i<size; i+=2) {
17528                         sq2 = 1.0f/(img1_ptr[i] * img1_ptr[i]   + img1_ptr[i+1] * img1_ptr[i+1]);
17529                         img2_ptr[i]   = sq2*(img_ptr[i] * img1_ptr[i]   + img_ptr[i+1] * img1_ptr[i+1]) ;
17530                         img2_ptr[i+1] = sq2*(img_ptr[i+1] * img1_ptr[i] - img_ptr[i] * img1_ptr[i+1]) ;
17531                 }
17532                 img2->set_complex(true);
17533                 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false);
17534         } else {
17535                 for (size_t i=0; i<size; ++i) img2_ptr[i] = img_ptr[i] / img1_ptr[i];
17536                 img2->update();
17537         }
17538 
17539         EXITFUNC;
17540         return img2;
17541 }

float EMAN::Util::eman_copysign float  a,
float  b
[inline, static]
 

copy sign of a number.

return a value whose absolute value matches that of 'a', but whose sign matches that of 'b'. If 'a' is a NaN, then a NaN with the sign of 'b' is returned.

It is exactly copysign() on non-Windows system.

Parameters:
[in] a The first number.
[in] b The second number.
Returns:
Copy sign of a number.

Definition at line 1956 of file util.h.

float EMAN::Util::eman_erfc float  x  )  [inline, static]
 

complementary error function.

It is exactly erfc() on non-Windows system. On Windows, it tries to simulate erfc().

The erf() function returns the error function of x; defined as erf(x) = 2/sqrt(pi)* integral from 0 to x of exp(-t*t) dt

The erfc() function returns the complementary error function of x, that is 1.0 - erf(x).

Parameters:
[in] x A float number.
Returns:
The complementary error function of x.

Definition at line 1981 of file util.h.

Referenced by EMAN::IterationAverager::finish().

float Util::ener EMData ave,
vector< int >  numr
[static]
 

Definition at line 4524 of file util_sparx.cpp.

References EMAN::EMData::get_data(), numr, and PI2.

04524                                               {
04525         ENTERFUNC;
04526         long double ener,en;
04527 
04528         int nring = numr.size()/3;
04529         float *aveptr = ave->get_data();
04530 
04531         ener = 0.0;
04532         for (int i=1; i<=nring; i++) {
04533                 int numr3i = numr(3,i);
04534                 int np     = numr(2,i)-1;
04535                 float tq = static_cast<float>(PI2*numr(1,i)/numr3i);
04536                 en = tq*(aveptr[np]*aveptr[np]+aveptr[np+1]*aveptr[np+1])*0.5;
04537                 for (int j=np+2; j<np+numr3i-1; j++) en += tq*aveptr[j]*aveptr[j];
04538                 ener += en/numr3i;
04539         }
04540         EXITFUNC;
04541         return static_cast<float>(ener);
04542 }

float Util::ener_tot const vector< EMData * > &  data,
vector< int >  numr,
vector< float >  tot
[static]
 

Definition at line 4544 of file util_sparx.cpp.

References data, EMAN::EMData::get_data(), numr, PI2, and tot.

04544                                                                                      {
04545         ENTERFUNC;
04546         long double ener, en;
04547         float arg, cs, si;
04548 
04549         int nima = data.size();
04550         int nring = numr.size()/3;
04551         int maxrin = numr(3,nring);
04552 
04553         ener = 0.0;
04554         for (int i=1; i<=nring; i++) {
04555                 int numr3i = numr(3,i);
04556                 int np     = numr(2,i)-1;
04557                 float tq = static_cast<float>(PI2*numr(1,i)/numr3i);
04558                 float temp1 = 0.0, temp2 = 0.0;
04559                 for (int kk=0; kk<nima; kk++) {
04560                         float *ptr = data[kk]->get_data();
04561                         temp1 += ptr[np];
04562                         temp2 += static_cast<float>(ptr[np+1]*cos(PI2*(tot[kk]-1.0f)/2.0f*numr3i/maxrin));
04563                 }
04564                 en = tq*(temp1*temp1+temp2*temp2)*0.5;
04565                 for (int j=2; j<numr3i; j+=2) {
04566                         float tempr = 0.0, tempi = 0.0;
04567                         for (int kk=0; kk<nima; kk++) {
04568                                 float *ptr = data[kk]->get_data();
04569                                 arg = static_cast<float>( PI2*(tot[kk]-1.0)*(j/2)/maxrin );
04570                                 cs = cos(arg);
04571                                 si = sin(arg);
04572                                 tempr += ptr[np + j]*cs - ptr[np + j +1]*si;
04573                                 tempi += ptr[np + j]*si + ptr[np + j +1]*cs;
04574                         }
04575                         en += tq*(tempr*tempr+tempi*tempi);
04576                 }
04577                 ener += en/numr3i;
04578         }
04579         EXITFUNC;
04580         return static_cast<float>(ener);
04581 }

void Util::equation_of_plane const Vec3f p1,
const Vec3f p2,
const Vec3f p3,
float *  plane
[static]
 

Determine the equation of a plane that intersects 3 points in 3D space.

Required by Symmetry3D::reduce IMPORTANT - does no error checking, if the float pointer is less than 4 in size will get unknown behavior

Parameters:
p1 point one
p2 point two
p3 point three
plane a float pointer - should have room for 4 elements which will be A,B,C, and D (in that order) for the equation Ax+By+Cz+D=0
Returns:
there is no explicit return - data is implicitly returned in the plane pointer
Author:
David Woolford
Date:
May 2008

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 }

float Util::eval char *  images,
EMData img,
vector< int >  S,
int  N,
int  K,
int  size
[static]
 

Definition at line 7136 of file util_sparx.cpp.

References EMAN::EMData::get_data(), images, and EMAN::EMData::read_image().

07137 {
07138         int j,d;
07139         EMData * e = new EMData();
07140         float *eptr, *imgptr;
07141         imgptr = img->get_data();
07142         float SSE = 0.f;
07143         for (j = 0 ; j < N ; j++) {
07144                 e->read_image(images,S[j]);
07145                 eptr = e->get_data();
07146                 for (d = 0; d < size; d++) {
07147                         SSE += ((eptr[d] - imgptr[d])*(eptr[d] - imgptr[d]));}
07148                 }
07149         delete e;
07150         return SSE;
07151 }

vector< float > Util::even_angles float  delta,
float  t1 = 0,
float  t2 = 90,
float  p1 = 0,
float  p2 = 359.999
[static]
 

Compute a vector containing quasi-evenly spaced Euler angles.

The order of angles in the vector is phi, theta, psi.

Parameters:
[in] delta Delta theta (spacing in theta).
[in] t1 Starting (min) value of theta in degrees, default = 0.
[in] t2 Ending (max) value of theta in degrees, default = 90.
[in] p1 Starting (min) value of phi in degrees, default = 0.
[in] p2 Ending (max) value of phi in degrees, default = 359.9.
Returns:
Vector of angles as a flat list of phi_0, theta_0, psi_0, ..., phi_N, theta_N, psi_N.

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 }

bool Util::explore vector< vector< int * > > &  Parts,
int *  dimClasses,
int  nParts,
int  K,
int  T,
int  partref,
int *  curintx,
int  size_curintx,
int *  next,
int  size_next,
int  depth
[static]
 

Each class in Parts has its dummy variable set to 0 or 1.

Only consider those with its dummy variable set to 1 (the 'active' ones) First element of each class is its original index, second is the dummy variable slot.

Definition at line 20731 of file util_sparx.cpp.

References k_means_cont_table_().

Referenced by initial_prune().

20731                                                                                                                                                                                 {
20732 
20733 
20734         if (size_next <= T) return 0;
20735 
20736         // take the intx of next and cur
20737         int* curintx2(0);
20738         int nintx = Util::k_means_cont_table_(curintx, next+2, curintx2, size_curintx, size_next,0);
20739         if (nintx <= T) return 0;
20740 
20741         int old_depth=depth;
20742         if (depth == partref) depth = depth + 1; // we skip classes in partref
20743         if (depth == (nParts)) { if (old_depth>0) return 1;}
20744 
20745         // have not yet reached a leaf, and current weight is still greather than T, so keep on going.
20746 
20747         curintx2 = new int[nintx]; // put the intersection set in here
20748         Util::k_means_cont_table_(curintx,next+2,curintx2, size_curintx, size_next,1);
20749 
20750         // if (old_depth > 0) {delete[] curintx;} // don't delete when depth == 0 because curintx in that case is a pointer into Parts
20751 
20752         // we now consider each of the classes in partition (depth+1) in turn
20753         bool gt_thresh;
20754         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
20755 
20756         for (int i=0; i < num_classes; i++){
20757                 if (*(Parts[depth][i]+1) < 1) continue; // class is not active so move on
20758                 size_next = (*(dimClasses + depth*K+(*(Parts[depth][i])) ))-2;
20759                 gt_thresh = explore(Parts,dimClasses, nParts, K, T, partref, curintx2,nintx, Parts[depth][i], size_next, depth+1);
20760                 if (gt_thresh) return 1;
20761         }
20762         delete[] curintx2;
20763         return 0;
20764 }

void Util::explore2 int *  argParts,
int *  Indices,
int *  dimClasses,
int  nParts,
int  K,
int  T,
int *  curintx,
int  size_curintx,
int *  next,
int  size_next,
int  depth,
int  J,
int *  matchlist,
int *  costlist,
int *  curbranch
[static]
 

Definition at line 20564 of file util_sparx.cpp.

References explore2(), and k_means_cont_table_().

20564                                                                                                                                                                                                                    {
20565 
20566 // depth is the level which is going to be explored in the current iteration
20567         int* curintx2(0);
20568         int nintx = size_curintx;
20569         
20570         
20571         // 2. take the intx of next and cur. Prune if <= T
20572         if (depth >0){
20573                 nintx = Util::k_means_cont_table_(curintx,next, curintx2, size_curintx, size_next,0);
20574                 if (nintx <= T) return; //prune!
20575         }
20576 
20577         // 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
20578         if (depth == (nParts-1)) {
20579                 
20580                 int replace = 0;
20581                 int ind_smallest = -1;
20582                 int smallest_cost = -1;
20583                 
20584                 for (int jit = 0; jit < J; jit++){
20585                         if (*(costlist+jit) < nintx){
20586                                 replace = 1;
20587                                 if (ind_smallest == -1) {ind_smallest = jit; smallest_cost = *(costlist+jit);}
20588                                 if (*(costlist+jit) < smallest_cost) {ind_smallest = jit; smallest_cost = *(costlist+jit);}
20589                         }       
20590                 }
20591                 
20592                 if (replace > 0){
20593                         // replace the smallest cost in matchlist with the current stuff
20594                         *(costlist + ind_smallest) = nintx;
20595                         for (int xit = 0; xit < nParts; xit++)
20596                                 *(matchlist + ind_smallest*nParts + xit) = *(curbranch+xit);
20597                                 
20598                 }
20599                 
20600                 return; 
20601         }
20602         
20603 
20604         // 3. have not yet reached a leaf, and current weight is still greather than T, so keep on going.
20605 
20606         if (depth > 0){
20607                 curintx2 = new int[nintx]; // put the intersection set in here
20608                 Util::k_means_cont_table_(curintx,next,curintx2, size_curintx, size_next,1);
20609         }
20610 
20611         if (depth == 0){
20612                 // set curintx2 to curintx
20613                 curintx2 = new int[size_curintx];
20614                 for (int cp = 0; cp < size_curintx; cp++) *(curintx2+cp) = *(curintx+cp);
20615         }
20616 
20617 
20618         // recursion (non-leaf case)
20619         depth=depth+1;
20620         // we now consider each of the classes in partition depth and recurse upon each of them
20621         for (int i=0; i < K; i++){
20622 
20623                 if (*(argParts + Indices[depth*K+i] + 1) < 1) continue; // class is not active so move on
20624                 size_next = (*(dimClasses + depth*K+i ))-2;
20625                 if (size_next <= T) continue;
20626                 *(curbranch+depth) = i;
20627                 Util::explore2(argParts,Indices, dimClasses, nParts, K, T, curintx2, nintx, argParts + Indices[depth*K+i] + 2, size_next, depth,J, matchlist,
20628                         costlist, curbranch);
20629                 
20630         }
20631 
20632         delete[] curintx2;
20633 }

complex< float > Util::extractpoint2 int  nx,
int  ny,
float  nuxnew,
float  nuynew,
EMData fimage,
Util::KaiserBessel kb
[static]
 

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 }

float Util::fast_acos const float &  f  )  [static]
 

Returns an approximate of acos(x) using a cached table and linear interpolation tolerates values very slightly outside the -1 - 1 range (returning 0).

Parameters:
[in] x argument to acos(x)
Returns:
(float)acos(x)

Definition at line 783 of file util.cpp.

00783                                     {
00784 if (f>=1.0) return 0.0;
00785 if (f<=-1.0) return M_PI;
00786 
00787 static float *mem = (float *)malloc(sizeof(float)*2001);
00788 static bool needinit=true;
00789 
00790 
00791 if (needinit) {
00792         needinit=false;
00793         for (int i=0; i<=2000; i++) mem[i]=(float)acos(i/1000.0-1.0);
00794 }
00795 float f2=f*1000.0f+1000.0f;
00796 
00797 int g=(int)(f2+.5);
00798 
00799 return mem[g];
00800 
00801 // This version interpolates, but is slower
00802 /*int g=(int)f2;
00803 f2-=g;
00804 return mem[g+1]*f2+mem[g]*(1.0-f2);*/
00805 }

float Util::fast_exp const float &  f  )  [static]
 

Returns an approximate of exp(x) using a cached table uses actual exp(x) outside the cached range.

Parameters:
[in] f argument to exp(f)
Returns:
(float)exp(x)

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 }

int EMAN::Util::fast_floor float  x  )  [inline, static]
 

A fast way to calculate a floor, which is largest integral value not greater than argument.

Parameters:
[in] x A float point number.
Returns:
floor of x.

Definition at line 1686 of file util.h.

Referenced by EMAN::CtfAverager::add_image(), EMAN::CircularMaskProcessor::calc_locals(), 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().

void Util::fftc_d double *  br,
double *  bi,
int  ln,
int  ks
[static]
 

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 }

void Util::fftc_q float *  br,
float *  bi,
int  ln,
int  ks
[static]
 

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 }

void Util::fftr_d double *  xcmplx,
int  nv
[static]
 

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(), Crosrng_psi_0_180_no_mirror(), 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 }

void Util::fftr_q float *  xcmplx,
int  nv
[static]
 

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 }

int Util::file_lock_wait FILE *  file  )  [static]
 

lock a file.

If the lock fails, wait for 1 second; then try again. Repleat this wait-try for a maxinum of 5 times unless the lock succeeds.

Parameters:
file The file to be locked.
Returns:
0 if lock succeeds. 1 if fails.

Definition at line 137 of file util.cpp.

References LOGERR, and NullPointerException.

00138 {
00139 #ifdef WIN32
00140         return 1;
00141 #else
00142 
00143         if (!file) {
00144                 throw NullPointerException("Tried to lock NULL file");
00145         }
00146 
00147         int fdes = fileno(file);
00148 
00149         struct flock fl;
00150         fl.l_type = F_WRLCK;
00151         fl.l_whence = SEEK_SET;
00152         fl.l_start = 0;
00153         fl.l_len = 0;
00154 #ifdef WIN32
00155         fl.l_pid = _getpid();
00156 #else
00157         fl.l_pid = getpid();
00158 #endif
00159 
00160 #if defined __sgi
00161         fl.l_sysid = getpid();
00162 #endif
00163 
00164         int err = 0;
00165         if (fcntl(fdes, F_SETLKW, &fl) == -1) {
00166                 LOGERR("file locking error! NFS problem?");
00167 
00168                 int i = 0;
00169                 for (i = 0; i < 5; i++) {
00170                         if (fcntl(fdes, F_SETLKW, &fl) != -1) {
00171                                 break;
00172                         }
00173                         else {
00174 #ifdef WIN32
00175                                 Sleep(1000);
00176 #else
00177                                 sleep(1);
00178 #endif
00179 
00180                         }
00181                 }
00182                 if (i == 5) {
00183                         LOGERR("Fatal file locking error");
00184                         err = 1;
00185                 }
00186         }
00187 
00188         return err;
00189 #endif
00190 }

void Util::find_max const float *  data,
size_t  nitems,
float *  p_max_val,
int *  p_max_index = 0
[static]
 

Find the maximum value and (optional) its index in an array.

Parameters:
[in] data data array.
[in] nitems number of items in the data array.
[out] p_max_val pointer to the maximum value.
[out] p_max_index pointer to index of the maximum value.

Definition at line 814 of file util.cpp.

References Assert, data, max, and NullPointerException.

Referenced by EMAN::RotateTranslateFlipAlignerPawel::align(), EMAN::RotateTranslateAlignerPawel::align(), EMAN::RotationalAlignerIterative::align(), EMAN::RotatePrecenterAligner::align(), and EMAN::RotationalAligner::align_180_ambiguous().

00815 {
00816         Assert(nitems > 0);
00817 
00818         if (!data || !max_val || !max_index) {
00819                 throw NullPointerException("data/max_val/max_index");
00820         }
00821         float max = -FLT_MAX;
00822         int m = 0;
00823 
00824         for (size_t i = 0; i < nitems; i++) {
00825                 if (data[i] > max) {
00826                         max = data[i];
00827                         m = (int)i;
00828                 }
00829         }
00830 
00831         *max_val = (float)max;
00832 
00833         if (max_index) {
00834                 *max_index = m;
00835         }
00836 }

void Util::find_min_and_max const float *  data,
size_t  nitems,
float *  p_max_val,
float *  p_min_val,
int *  p_max_index = 0,
int *  p_min_index = 0
[static]
 

Find the maximum value and (optional) its index, minimum value and (optional) its index in an array.

Parameters:
[in] data data array.
[in] nitems number of items in the data array.
[out] p_max_val pointer to the maximum value.
[out] p_min_val pointer to the minimum value.
[out] p_max_index pointer to index of the maximum value.
[out] p_min_index pointer to index of the minimum value.

Definition at line 838 of file util.cpp.

References Assert, 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 }

void Util::flip23 double *  x,
double *  y,
double *  z,
int *  key,
int  k,
int  len
[static]
 

Definition at line 7827 of file util_sparx.cpp.

References key, x, and y.

07828 {
07829         ENTERFUNC;
07830         int i = k;
07831         while( i == k )  i = rand()%len;
07832         std::swap(key[i], key[k]);
07833         std::swap(x[i], x[k]);
07834         std::swap(y[i], y[k]);
07835         std::swap(z[i], z[k]);
07836         EXITFUNC;
07837 }

void Util::flip_complex_phase float *  data,
size_t  n
[static]
 

flip the phase of a complex data array.

Parameters:
data complex data array.
n array size.

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 }

void Util::flip_image float *  data,
size_t  nx,
size_t  ny
[static]
 

Vertically flip the data of a 2D real image.

Parameters:
data Data array of the 2D real image.
nx Image Width.
ny Image Height.

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 }

void Util::Frngs EMData circ,
vector< int >  numr
[static]
 

This function conducts the Single Precision Fourier Transform for a set of rings.

Definition at line 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(), multiref_polar_ali_helical(), and multiref_polar_ali_helical_90().

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 }

void Util::Frngs_inv EMData circ,
vector< int >  numr
[static]
 

This function conducts the Single Precision Inverse Fourier Transform for a set of rings.

Definition at line 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 }

int EMAN::Util::generatesubmax int *  argParts,
int *  Indices,
int *  dimClasses,
int  nParts,
int  K,
int  T,
int  n_guesses,
int  LARGEST_CLASS
[static]
 

make an intelligent "guess" at the largest weight of all possible feasible matches.

we make "n_guesses" guesses and return the largest one. the largest weight of all feasible matches is guaranteed to be larger than or equal to the returned guess.

EMData * Util::get_biggest_cluster EMData mg  )  [static]
 

Definition at line 19771 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().

19772 {
19773         int nx = mg->get_xsize();
19774         int ny = mg->get_ysize();
19775         int nz = mg->get_zsize();
19776 
19777         EMData* visited = new EMData();
19778         visited->set_size( nx, ny, nz );
19779         visited->to_zero();
19780         int grpid = 0;
19781         int maxgrp = 0;
19782         int maxsize = 0;
19783         for( int iz=0; iz < nz; ++iz ) {
19784                 for( int iy=0; iy < ny; ++iy ) {
19785                         for( int ix=0; ix < nx; ++ix ) {
19786                                 if( (*mg)(ix, iy, iz)==0.0 ) continue;
19787 
19788                                 if( (*visited)(ix, iy, iz) > 0.0 ) {
19789                                         // visited before, must be in other group.
19790                                         continue;
19791                                 }
19792 
19793                                 grpid++;
19794                                 int grpsize = find_group( ix, iy, iz, grpid, mg, visited );
19795                                 if( grpsize > maxsize ) {
19796                                         maxsize = grpsize;
19797                                         maxgrp = grpid;
19798                                 }
19799                         }
19800                 }
19801         }
19802 
19803         Assert( maxgrp > 0 );
19804 
19805         int npoint = 0;
19806         EMData* result = new EMData();
19807         result->set_size( nx, ny, nz );
19808         result->to_zero();
19809 
19810         for( int iz=0; iz < nz; ++iz ) {
19811                 for( int iy=0; iy < ny; ++iy ) {
19812                         for( int ix=0; ix < nx; ++ix ) {
19813                                 if( (*visited)(ix, iy, iz)==maxgrp ) {
19814                                         (*result)(ix,iy,iz) = 1.0;
19815                                         npoint++;
19816                                 }
19817                         }
19818                 }
19819         }
19820 
19821         Assert( npoint==maxsize );
19822         delete visited;
19823         return result;
19824 
19825 }

string Util::get_filename_ext const string &  filename  )  [static]
 

Get a filename's extension.

Parameters:
[in] filename A given filename.
Returns:
The filename's extension, or empty string if the file has no 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 }

float Util::get_frand double  low,
double  high
[static]
 

Get a float random number between low and high, [low, high).

Parameters:
[in] low The lower bound of the random number.
[in] high The upper bound of the random number.
Returns:
The random number between low and 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 }

float Util::get_frand float  low,
float  high
[static]
 

Get a float random number between low and high, [low, high).

Parameters:
[in] low The lower bound of the random number.
[in] high The upper bound of the random number.
Returns:
The random number between low and 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 }

float Util::get_frand int  low,
int  high
[static]
 

Get a float random number between low and high, [low, high).

Parameters:
[in] low The lower bound of the random number.
[in] high The upper bound of the random number.
Returns:
The random number between low and 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 }

float Util::get_gauss_rand float  mean,
float  sigma
[static]
 

Get a Gaussian random number.

Parameters:
[in] mean The gaussian mean
[in] sigma The gaussian sigma
Returns:
the 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 }

int Util::get_irand int  low,
int  high
[static]
 

Get an integer random number between low and high, [low, high].

Parameters:
[in] low The lower bound of the random number.
[in] high The upper bound of the random number.
Returns:
The random number between low and 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 }

string Util::get_line_from_string char **  str  )  [static]
 

Extract a single line from a multi-line string.

The line delimiter is '
'. The multi-line string moves forward one line. If it is the last line, move to the end of the string.

Parameters:
[in,out] str A multiple-line string.
Returns:
A single line.

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 }

float EMAN::Util::get_max float  f1,
float  f2,
float  f3,
float  f4
[inline, static]
 

Get the maximum of 4 numbers.

Parameters:
[in] f1 The first number.
[in] f2 The second number.
[in] f3 The third number.
[in] f4 The fourth number.
Returns:
The maximum of 4 numbers.

Definition at line 1831 of file util.h.

float EMAN::Util::get_max float  f1,
float  f2,
float  f3
[inline, static]
 

Get the maximum of 3 numbers.

Parameters:
[in] f1 The first number.
[in] f2 The second number.
[in] f3 The third number.
Returns:
The maximum of 3 numbers.

Definition at line 1813 of file util.h.

float EMAN::Util::get_max float  f1,
float  f2
[inline, static]
 

Get the maximum of 2 numbers.

Parameters:
[in] f1 The first number.
[in] f2 The second number.
Returns:
The maximum of 2 numbers.

Definition at line 1802 of file util.h.

float EMAN::Util::get_min float  f1,
float  f2,
float  f3,
float  f4
[inline, static]
 

Get the minimum of 4 numbers.

Parameters:
[in] f1 The first number.
[in] f2 The second number.
[in] f3 The third number.
[in] f4 The fourth number.
Returns:
The minimum of 4 numbers.

Definition at line 1782 of file util.h.

float EMAN::Util::get_min float  f1,
float  f2,
float  f3
[inline, static]
 

Get the minimum of 3 numbers.

Parameters:
[in] f1 The first number.
[in] f2 The second number.
[in] f3 The third number.
Returns:
The minimum of 3 numbers.

Definition at line 1763 of file util.h.

float EMAN::Util::get_min float  f1,
float  f2
[inline, static]
 

Get the minimum of 2 numbers.

Parameters:
[in] f1 The first number.
[in] f2 The second number.
Returns:
The minimum of 2 numbers.

Definition at line 1752 of file util.h.

int EMAN::Util::get_min int  f1,
int  f2,
int  f3
[inline, static]
 

Get the minimum of 3 numbers.

Parameters:
[in] f1 The first number.
[in] f2 The second number.
[in] f3 The third number.
Returns:
The minimum of 3 numbers.

Definition at line 1736 of file util.h.

int EMAN::Util::get_min int  f1,
int  f2
[inline, static]
 

Get the minimum of 2 numbers.

Parameters:
[in] f1 The first number.
[in] f2 The second number.
Returns:
The minimum of 2 numbers.

Definition at line 1725 of file util.h.

Referenced by EMAN::PawelProjector::backproject3d(), EMAN::ChaoProjector::backproject3d(), EMAN::ChaoProjector::project3d(), EMAN::FourierGriddingProjector::project3d(), and EMAN::PawelProjector::project3d().

float Util::get_pixel_conv_new int  nx,
int  ny,
int  nz,
float  delx,
float  dely,
float  delz,
float *  data,
Util::KaiserBessel kb
[static]
 

Definition at line 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 }

float Util::get_pixel_conv_new_background int  nx,
int  ny,
int  nz,
float  delx,
float  dely,
float  delz,
float *  data,
Util::KaiserBessel kb,
int  xnew,
int  ynew
[static]
 

Definition at line 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 }

unsigned long int Util::get_randnum_seed  )  [static]
 

Get the seed for Randnum class.

Returns:
the seed for current random number generator

Definition at line 684 of file util.cpp.

References EMAN::Randnum::get_seed().

00685 {
00686         Randnum* randnum = Randnum::Instance();
00687         return  randnum->get_seed();
00688 }

EMData * Util::get_slice EMData vol,
int  dim,
int  index
[static]
 

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 20291 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.

20291                                                        {
20292 
20293         int nx = vol->get_xsize();
20294         int ny = vol->get_ysize();
20295         int nz = vol->get_zsize();
20296         float *vol_data = vol->get_data();
20297         int new_nx, new_ny;
20298 
20299         if (nz == 1)
20300                 throw ImageDimensionException("Error: Input must be a 3-D object");
20301         if ((dim < 1) || (dim > 3))
20302                 throw ImageDimensionException("Error: dim must be 1 (x-dimension), 2 (y-dimension) or 3 (z-dimension)");
20303         if (((dim == 1) && (index < 0 || index > nx-1)) ||
20304           ((dim == 1) && (index < 0 || index > nx-1)) ||
20305           ((dim == 1) && (index < 0 || index > nx-1)))
20306                 throw ImageDimensionException("Error: index exceeds the size of the 3-D object");
20307 
20308         if (dim == 1) {
20309                 new_nx = ny;
20310                 new_ny = nz;
20311         } else if (dim == 2) {
20312                 new_nx = nx;
20313                 new_ny = nz;
20314         } else {
20315                 new_nx = nx;
20316                 new_ny = ny;
20317         }
20318 
20319         EMData *slice = new EMData();
20320         slice->set_size(new_nx, new_ny, 1);
20321         float *slice_data = slice->get_data();
20322 
20323         if (dim == 1) {
20324                 for (int x=0; x<new_nx; x++)
20325                         for (int y=0; y<new_ny; y++)
20326                                 slice_data[y*new_nx+x] = vol_data[(y*ny+x)*nx+index];
20327         } else if (dim == 2) {
20328                 for (int x=0; x<new_nx; x++)
20329                         for (int y=0; y<new_ny; y++)
20330                                 slice_data[y*new_nx+x] = vol_data[(y*ny+index)*nx+x];
20331         } else {
20332                 for (int x=0; x<new_nx; x++)
20333                         for (int y=0; y<new_ny; y++)
20334                                 slice_data[y*new_nx+x] = vol_data[((size_t)index*ny+y)*nx+x];
20335         }
20336 
20337         return slice;
20338 }

Dict Util::get_stats const vector< float > &  data  )  [static]
 

Get the mean, standard deviation, skewness and kurtosis of the input data.

Parameters:
data the vector of input data
Exceptions:
EmptyContainerException when the argument vector is empty

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 }

Dict Util::get_stats_cstyle const vector< float > &  data  )  [static]
 

Performs the same calculations as in get_stats, but uses a single pass, optimized c approach Should perform better than get_stats.

Definition at line 932 of file util.cpp.

References 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 }

bool Util::get_str_float const char *  str,
const char *  float_var,
int *  p_nvalues,
float *  p_v1,
float *  p_v2
[static]
 

Extract number of values and the float values, if any, from a string whose format is either "variable=value1,value2 " or "variable".

for example, if the string is "XYZ=1.1,1.2", then 'str' is "XYZ=1.1,1.2"; 'float_var' is "XYZ"; 'p_nvalues' points to 2. 'p_v1' points to 1.1; 'p_v2' points to 1.2. If the string is "XYZ", then 'str' is "XYZ"; 'float_var' is "XYZ". 'p_nvalues' points to 0. 'p_v1' and 'p_v2' unchanged.

Parameters:
[in] str A string like "XYZ=1.1,1.2" or "XYZ".
[in] float_var The variable name "XYZ".
[out] p_nvalues Number of values in the string.
[out] p_v1 The pointer to the first float, if any.
[out] p_v2 The pointer to the second float, if any.
Returns:
True if the extraction succeeds; False if extraction fails.

Definition at line 359 of file util.cpp.

References NullPointerException.

00361 {
00362         if (!s || !float_var || !p_v0 || !p_v1 || !p_v2) {
00363                 throw NullPointerException("string float");
00364         }
00365 
00366         size_t n = strlen(float_var);
00367         *p_v0 = 0;
00368         if (strncmp(s, float_var, n) == 0) {
00369                 if (s[n] == '=') {
00370                         *p_v0 = 2;
00371                         sscanf(&s[n + 1], "%f,%f", p_v1, p_v2);
00372                 }
00373                 else {
00374                         *p_v0 = 1;
00375                 }
00376                 return true;
00377         }
00378         return false;
00379 }

bool Util::get_str_float const char *  str,
const char *  float_var,
float *  p_v1,
float *  p_v2
[static]
 

Extract the float values from a variable=value1,value2 string with format like "XYZ=1.1,1.2", where 'str' is "XYZ=1.1,1.2"; 'float_var' is "XYZ="; 'p_v1' points to 1.1; 'p_v2' points to 1.2.

Parameters:
[in] str A string like "XYZ=1.1,1.2";
[in] float_var The variable name "XYZ=".
[out] p_v1 The pointer to the first float.
[out] p_v2 The pointer to the second float.
Returns:
True if the extraction succeeds; False if extraction fails.

Definition at line 344 of file util.cpp.

References NullPointerException.

00345 {
00346         if (!s || !float_var || !p_v1 || !p_v2) {
00347                 throw NullPointerException("string float");
00348         }
00349 
00350         size_t n = strlen(float_var);
00351         if (strncmp(s, float_var, n) == 0) {
00352                 sscanf(&s[n], "%f,%f", p_v1, p_v2);
00353                 return true;
00354         }
00355 
00356         return false;
00357 }

bool Util::get_str_float const char *  str,
const char *  float_var,
float *  p_val
[static]
 

Extract the float value from a variable=value string with format like "XYZ=1.1", where 'str' is "XYZ=1.1"; 'float_var' is "XYZ="; 'p_val' points to float number 1.1.

Parameters:
[in] str A string like "XYZ=1.1";
[in] float_var The variable name "XYZ=".
[out] p_val The pointer to the float number.
Returns:
True if the extraction succeeds; False if extraction fails.

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 }

bool Util::get_str_int const char *  str,
const char *  int_var,
int *  p_nvalues,
int *  p_v1,
int *  p_v2
[static]
 

Extract number of values and the int values, if any, from a string whose format is either "variable=value1,value2 " or "variable".

for example, if the string is "XYZ=1,2", then 'str' is "XYZ=1,2"; 'int_var' is "XYZ"; 'p_nvalues' points to 2. 'p_v1' points to 1; 'p_v2' points to 2. If the string is "XYZ", then 'str' is "XYZ"; 'int_var' is "XYZ". 'p_nvalues' points to 0. 'p_v1' and 'p_v2' unchanged.

Parameters:
[in] str A string like "XYZ=1,2" or "XYZ".
[in] int_var The variable name "XYZ".
[out] p_nvalues Number of values in the string.
[out] p_v1 The pointer to the first int, if any.
[out] p_v2 The pointer to the second int, if any.
Returns:
True if the extraction succeeds; False if extraction fails.

Definition at line 409 of file util.cpp.

References NullPointerException.

00410 {
00411         if (!s || !int_var || !p_v0 || !p_v1 || !p_v2) {
00412                 throw NullPointerException("string int");
00413         }
00414 
00415         size_t n = strlen(int_var);
00416         *p_v0 = 0;
00417         if (strncmp(s, int_var, n) == 0) {
00418                 if (s[n] == '=') {
00419                         *p_v0 = 2;
00420                         sscanf(&s[n + 1], "%d,%d", p_v1, p_v2);
00421                 }
00422                 else {
00423                         *p_v0 = 1;
00424                 }
00425                 return true;
00426         }
00427         return false;
00428 }

bool Util::get_str_int const char *  str,
const char *  int_var,
int *  p_v1,
int *  p_v2
[static]
 

Extract the int value from a variable=value1,value2 string with format like "XYZ=1,2", where 'str' is "XYZ=1,2"; 'int_var' is "XYZ="; 'p_val' points to float number 1.

Parameters:
[in] str A string like "XYZ=1";
[in] int_var The variable name "XYZ=".
[out] p_v1 The pointer to the first int.
[out] p_v2 The pointer to the second int.
Returns:
True if the extraction succeeds; False if extraction fails.

Definition at line 395 of file util.cpp.

References NullPointerException.

00396 {
00397         if (!s || !int_var || !p_v1 || !p_v2) {
00398                 throw NullPointerException("string int");
00399         }
00400 
00401         size_t n = strlen(int_var);
00402         if (strncmp(s, int_var, n) == 0) {
00403                 sscanf(&s[n], "%d,%d", p_v1, p_v2);
00404                 return true;
00405         }
00406         return false;
00407 }

bool Util::get_str_int const char *  str,
const char *  int_var,
int *  p_val
[static]
 

Extract the int value from a variable=value string with format like "XYZ=1", where 'str' is "XYZ=1"; 'int_var' is "XYZ="; 'p_val' points to float number 1.

Parameters:
[in] str A string like "XYZ=1";
[in] int_var The variable name "XYZ=".
[out] p_val The pointer to the int number.
Returns:
True if the extraction succeeds; False if extraction fails.

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 }

string Util::get_time_label  )  [static]
 

Get the current time in a string with format "mm/dd/yyyy hh:mm".

Returns:
The current time string.

Definition at line 1097 of file util.cpp.

References t.

01098 {
01099         time_t t0 = time(0);
01100         struct tm *t = localtime(&t0);
01101         char label[32];
01102         sprintf(label, "%d/%02d/%04d %d:%02d",
01103                         t->tm_mon + 1, t->tm_mday, t->tm_year + 1900, t->tm_hour, t->tm_min);
01104         return string(label);
01105 }

float * Util::getBaldwinGridWeights const int &  freq_cutoff,
const float &  P,
const float &  r,
const float &  dfreq = 1,
const float &  alpha = 0.5,
const float &  beta = 0.2
[static]
 

Parameters:
[in] freq_cutoff 
[in] P 
[in] r 
[in] dfreq 
[in] alpha 
[in] beta 
Returns:
float*

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 }

int EMAN::Util::goodf const double *  p_f  )  [inline, static]
 

Definition at line 1915 of file util.h.

int EMAN::Util::goodf const float *  p_f  )  [inline, static]
 

Check whether a number is a good float.

A number is a good float if it is not abnormal zero, and not inf, -inf or NaN

Parameters:
[in] p_f Pointer to the given float number.
Returns:
1 if it is a good float; 0 if it's not good float.

Definition at line 1898 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().

float Util::hist_comp_freq float  PA,
float  PB,
size_t  size_img,
int  hist_len,
EMData img,
vector< float >  ref_freq_hist,
EMData mask,
float  ref_h_diff,
float  ref_h_min
[static]
 

Definition at line 5688 of file util_sparx.cpp.

References EMAN::EMData::get_data(), and img_ptr.

05689 {
05690         float *img_ptr = img->get_data();
05691         float *mask_ptr = (mask == NULL)?img->get_data():mask->get_data();
05692 
05693         int *img_freq_bin = new int[3*hist_len];
05694         for(int i = 0;i < (3*hist_len);i++) img_freq_bin[i] = 0;
05695         for(size_t i = 0;i < size_img;++i) {
05696                 if(mask_ptr[i] > 0.5f) {
05697                         float img_xn = img_ptr[i]*PA + PB;
05698                         int L = static_cast<int>(((img_xn - ref_h_min)/ref_h_diff) * (hist_len-1) + hist_len+1);
05699                         if(L >= 0 && L < (3*hist_len)) img_freq_bin[L]++;
05700                 }
05701         }
05702         int freq_hist = 0;
05703 
05704         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);
05705         freq_hist = (-freq_hist);
05706         return static_cast<float>(freq_hist);
05707 }

Dict Util::histc EMData ref,
EMData img,
EMData mask
[static]
 

Definition at line 5596 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.

05597 {
05598         /* Exception Handle */
05599         if (img->is_complex() || ref->is_complex())
05600                 throw ImageFormatException("Cannot do Histogram on Fourier Image");
05601 
05602         if(mask != NULL){
05603                 if(img->get_xsize() != mask->get_xsize() || img->get_ysize() != mask->get_ysize() || img->get_zsize() != mask->get_zsize())
05604                         throw ImageDimensionException("The size of mask image should be of same size as the input image"); }
05605         /* ===================================================== */
05606 
05607         /* Image size calculation */
05608         size_t size_ref = ((size_t)(ref->get_xsize())*(ref->get_ysize())*(ref->get_zsize()));
05609         size_t size_img = ((size_t)(img->get_xsize())*(img->get_ysize())*(img->get_zsize()));
05610         /* ===================================================== */
05611 
05612         /* The reference image attributes */
05613         float *ref_ptr = ref->get_data();
05614         float ref_h_min = ref->get_attr("minimum");
05615         float ref_h_max = ref->get_attr("maximum");
05616         float ref_h_avg = ref->get_attr("mean");
05617         float ref_h_sig = ref->get_attr("sigma");
05618         /* ===================================================== */
05619 
05620         /* Input image under mask attributes */
05621         float *mask_ptr = (mask == NULL)?img->get_data():mask->get_data();
05622 
05623         vector<float> img_data = Util::infomask(img, mask);
05624         float img_avg = img_data[0];
05625         float img_sig = img_data[1];
05626 
05627         /* The image under mask -- size calculation */
05628         int cnt=0;
05629         for(size_t i=0;i<size_img;++i)
05630                 if (mask_ptr[i]>0.5f)
05631                                 cnt++;
05632         /* ===================================================== */
05633 
05634         /* Histogram of reference image calculation */
05635         float ref_h_diff = ref_h_max - ref_h_min;
05636 
05637         #ifdef _WIN32
05638                 int hist_len = _cpp_min((unsigned long)size_ref/16,_cpp_min((unsigned long)size_img/16,256lu));
05639         #else
05640                 int hist_len = std::min((unsigned long)size_ref/16,std::min((unsigned long)size_img/16,256lu));
05641         #endif  //_WIN32
05642 
05643         float *ref_freq_bin = new float[3*hist_len];
05644 
05645         //initialize value in each bin to zero
05646         for (int i = 0;i < (3*hist_len);i++) ref_freq_bin[i] = 0.f;
05647 
05648         for (size_t i = 0;i < size_ref;++i) {
05649                 int L = static_cast<int>(((ref_ptr[i] - ref_h_min)/ref_h_diff) * (hist_len-1) + hist_len+1);
05650                 ref_freq_bin[L]++;
05651         }
05652         for (int i = 0;i < (3*hist_len);i++) ref_freq_bin[i] *= static_cast<float>(cnt)/static_cast<float>(size_ref);
05653 
05654         //Parameters Calculation (i.e) 'A' x + 'B'
05655         float A = ref_h_sig/img_sig;
05656         float B = ref_h_avg - (A*img_avg);
05657 
05658         vector<float> args;
05659         args.push_back(A);
05660         args.push_back(B);
05661 
05662         vector<float> scale;
05663         scale.push_back(1.e-7f*A);
05664         scale.push_back(-1.e-7f*B);
05665 
05666         vector<float> ref_freq_hist;
05667         for(int i = 0;i < (3*hist_len);i++) ref_freq_hist.push_back((int)ref_freq_bin[i]);
05668 
05669         vector<float> data;
05670         data.push_back(ref_h_diff);
05671         data.push_back(ref_h_min);
05672 
05673         Dict parameter;
05674 
05675         /* Parameters displaying the arguments A & B, and the scaling function and the data's */
05676         parameter["args"] = args;
05677         parameter["scale"]= scale;
05678         parameter["data"] = data;
05679         parameter["ref_freq_bin"] = ref_freq_hist;
05680         parameter["size_img"]=(double)size_img;
05681         parameter["hist_len"]=hist_len;
05682         /* ===================================================== */
05683 
05684         return parameter;
05685 }

vector< float > Util::histogram EMData image,
EMData mask,
int  nbins = 128,
float  hmin = 0.0f,
float  hmax = 0.0f
[static]
 

Definition at line 5538 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.

05539 {
05540         if (image->is_complex())
05541                 throw ImageFormatException("Cannot do histogram on Fourier image");
05542         //float hmax, hmin;
05543         float *imageptr=0, *maskptr=0;
05544         int nx=image->get_xsize();
05545         int ny=image->get_ysize();
05546         int nz=image->get_zsize();
05547 
05548         if(mask != NULL){
05549                 if(nx != mask->get_xsize() || ny != mask->get_ysize() || nz != mask->get_zsize())
05550                         throw ImageDimensionException("The size of mask image should be of same size as the input image");
05551                 maskptr =mask->get_data();
05552         }
05553         if( nbins == 0) nbins = nx;
05554         vector <float> freq(2*nbins, 0.0);
05555 
05556         imageptr=image->get_data();
05557         if( hmin == hmax ) {
05558                 if(mask == NULL) {
05559                         hmax = image->get_attr("maximum");
05560                         hmin = image->get_attr("minimum");
05561                 } else {
05562                         bool  First = true;
05563                         for (size_t i = 0;i < (size_t)nx*ny*nz; i++) {
05564                         if (maskptr[i]>=0.5f) {
05565                                         if(First) {
05566                                                 hmax = imageptr[i];
05567                                                 hmin = imageptr[i];
05568                                                 First = false;
05569                                         } else {
05570                                                 hmax = (hmax < imageptr[i])?imageptr[i]:hmax;
05571                                                 hmin = (hmin > imageptr[i])?imageptr[i]:hmin;
05572                                         }
05573                                 }
05574                         }
05575                 }
05576         }
05577         float hdiff = hmax - hmin;
05578         float ff = (nbins-1)/hdiff;
05579         for (int i = 0; i < nbins; i++) freq[nbins+i] = hmin + (float(i)+0.5f)/ff;
05580         if(mask == NULL) {
05581                 for(size_t i = 0; i < (size_t)nx*ny*nz; i++) {
05582                         int jbin = static_cast<int>((imageptr[i]-hmin)*ff + 1.5);
05583                         if(jbin >= 1 && jbin <= nbins)  freq[jbin-1] += 1.0;
05584                 }
05585         } else {
05586                 for(size_t i = 0; i < (size_t)nx*ny*nz; i++) {
05587                         if(maskptr[i] >= 0.5) {
05588                                 int jbin = static_cast<int>((imageptr[i]-hmin)*ff + 1.5);
05589                                 if(jbin >= 1 && jbin <= nbins)  freq[jbin-1] += 1.0;
05590                         }
05591                 }
05592         }
05593         return freq;
05594 }

void Util::hsortd double *  theta,
double *  phi,
int *  key,
int  len,
int  option
[static]
 

Definition at line 7248 of file util_sparx.cpp.

References key, phi, and theta.

07249 {
07250         ENTERFUNC;
07251         vector<tmpstruct> tmp(len);
07252         int i;
07253         for(i = 1;i<=len;i++)
07254         {
07255                 tmp[i-1].theta1 = theta(i);
07256                 tmp[i-1].phi1 = phi(i);
07257                 tmp[i-1].key1 = key(i);
07258         }
07259 
07260         if (option == 1) sort(tmp.begin(),tmp.end(),Util::cmp1);
07261         if (option == 2) sort(tmp.begin(),tmp.end(),Util::cmp2);
07262 
07263         for(i = 1;i<=len;i++)
07264         {
07265                 theta(i) = tmp[i-1].theta1;
07266                 phi(i)   = tmp[i-1].phi1;
07267                 key(i)   = tmp[i-1].key1;
07268         }
07269         EXITFUNC;
07270 }

float EMAN::Util::hypot2 float  x,
float  y
[inline, static]
 

Euclidean distance function in 2D: f(x,y) = sqrt(x*x + y*y);.

Parameters:
[in] x The first number.
[in] y The second number.
Returns:
sqrt(x*x + y*y);

Definition at line 1606 of file util.h.

float EMAN::Util::hypot3 double  x,
double  y,
double  z
[inline, static]
 

Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);.

Parameters:
[in] x The first number.
[in] y The second number.
[in] z The third number.
Returns:
sqrt(x*x + y*y + z*z);

Definition at line 1661 of file util.h.

float EMAN::Util::hypot3 float  x,
float  y,
float  z
[inline, static]
 

Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);.

Parameters:
[in] x The first number.
[in] y The second number.
[in] z The third number.
Returns:
sqrt(x*x + y*y + z*z);

Definition at line 1650 of file util.h.

float EMAN::Util::hypot3 int  x,
int  y,
int  z
[inline, static]
 

Euclidean distance function in 3D: f(x,y,z) = sqrt(x*x + y*y + z*z);.

Parameters:
[in] x The first number.
[in] y The second number.
[in] z The third number.
Returns:
sqrt(x*x + y*y + z*z);

Definition at line 1639 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().

float EMAN::Util::hypot3sq float  x,
float  y,
float  z
[inline, static]
 

Euclidean distance function squared in 3D: f(x,y,z) = (x*x + y*y + z*z);.

Parameters:
[in] x The first number.
[in] y The second number.
[in] z The third number.
Returns:
(x*x + y*y + z*z);

Definition at line 1628 of file util.h.

int EMAN::Util::hypot3sq int  x,
int  y,
int  z
[inline, static]
 

Euclidean distance function squared in 3D: f(x,y,z) = (x*x + y*y + z*z);.

Parameters:
[in] x The first number.
[in] y The second number.
[in] z The third number.
Returns:
(int)(x*x + y*y + z*z);

Definition at line 1617 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().

float Util::hypot_fast int  x,
int  y
[static]
 

Euclidean distance in 2D for integers computed fast using a cached lookup table.

Parameters:
[in] x The first number
[in] y The second number
Returns:
sqrt(x*x+y*y)

Definition at line 713 of file util.cpp.

References abs, x, and y.

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 }

short Util::hypot_fast_int int  x,
int  y
[static]
 

Euclidean distance in 2D for integers computed fast using a cached lookup table.

Parameters:
[in] x The first number
[in] y The second number
Returns:
(int)round(sqrt(x*x+y*y))

Definition at line 739 of file util.cpp.

References abs, x, and y.

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 }

Dict Util::im_diff EMData V1,
EMData V2,
EMData mask = 0
[static]
 

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 = (size_t)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  }

void Util::image_mutation EMData img,
float  mutation_rate
[static]
 

Definition at line 20340 of file util_sparx.cpp.

References array_mutation(), EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), max, min, and nx.

20340                                                           {
20341         int nx = img->get_xsize();
20342         float min = img->get_attr("minimum");
20343         float max = img->get_attr("maximum");
20344         float* img_data = img->get_data();
20345         array_mutation(img_data, nx*nx, mutation_rate, min, max, 8, 0);
20346         return;
20347 }

vector< float > Util::infomask EMData Vol,
EMData mask,
bool 
[static]
 

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 < (size_t)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 }

void Util::initial_prune vector< vector< int * > > &  Parts,
int *  dimClasses,
int  nParts,
int  K,
int  T
[static]
 

initial_prune removes all classes C from Parts where there does not exist ANY feasible matching containing class C which has weight gt T.

The first element of each class is its original index, and second is dummy variable

Definition at line 20635 of file util_sparx.cpp.

References b, explore(), and k_means_cont_table_().

20635                                                                                                    {
20636         //cout<<"initial_prune\n";
20637         // simple initial pruning. For class indClass of partition indPart:
20638         // 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
20639         // If for some partition (not equal to indPart) for which there is no such class, then return 0 immediately.
20640 
20641         // 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
20642 
20643         // remember when calling k_means_cont_table, the first element of each class is an index, and actual number of elements in the class
20644         // (as stored in dimClasses) should be decremented by 1 accordingly, and second is dummy variable
20645 
20646         int* dummy(0);
20647         int* cref;
20648         int cref_size;
20649         int* ccomp;
20650         int ccomp_size;
20651         int nintx;
20652         for (int i=0; i < nParts; i++){
20653                 for (int j =0; j < K; j++){
20654 
20655                         // consider class Parts[i][j]
20656                         cref = Parts[i][j];//incr by 1 since first element is index and second is dummy
20657                         cref_size = (*(dimClasses+i*K+(*cref)))-2;
20658 
20659 
20660                         if (cref_size <= T){
20661 
20662                                 *cref = -1;
20663                                 continue;
20664                         }
20665                         bool done = 0;
20666                         for (int a = 0; a < nParts; a++){
20667                                 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
20668                                 bool hasActive=0;
20669                                 for (unsigned int b=0; b < Parts[a].size(); b++){
20670                                         // get the card of the intx between Parts[i][j] and Parts[a][b] using k_means_cont_table
20671                                         // remember first element of each class is the index of the class
20672                                         ccomp = Parts[a][b];
20673                                         ccomp_size= (*(dimClasses+a*K+(*ccomp)))-2;
20674                                         nintx = Util::k_means_cont_table_(cref+2,ccomp+2, dummy, cref_size, ccomp_size,0);
20675 
20676 
20677                                         if (nintx <= T)
20678                                                 *(ccomp+1) = 0; // class Parts[a][b] is 'inactive' for cref
20679                                         else{
20680                                                 *(ccomp+1)=1; // class Parts[a][b] is 'active' for cref
20681                                                 hasActive=1;
20682                                         }
20683                                 }
20684                                 // see if partition a has at least one active class.if not then we're done with cref
20685                                 if (hasActive < 1){
20686                                    done=1;
20687                                    break;
20688                                 }
20689 
20690                         }
20691 
20692                         if (done > 0){
20693                                 // remove class j from partition i
20694 
20695                                 *cref = -1; // mark for deletion later
20696                                 continue; // move on to class Parts[i][j+1]
20697                         }
20698 
20699                         // now we adopt more aggressive measures. we find the match with the largest weight which has class Parts[i][j] for partition i.
20700                         // 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.
20701 
20702                         // (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.
20703                         // Note that if there are ALOT of partitions, then sorting the partititions may actually take longer than the time saved by ordering hte
20704                         // partitions. However, we do not have a lot of partitions, (usually around 10), so sorting time will be trivial compared to exploring time.
20705 
20706                         // explore returns one if there is a feasible matching containing class cref which has weight gt T, and otherwise returns 0
20707                         //bool found = 1;
20708                         bool found = explore(Parts, dimClasses, nParts, K, T, i, cref+2, cref_size, cref, cref_size,0);
20709 
20710                         if (found<1){ // There is NO feasible matching with class j (cref)  with weight greater than T, so delete this class from Parts
20711                                 // Parts[i].erase(Parts[i].begin()+j);
20712                                 *cref = -1;
20713                         }
20714                 }
20715 
20716                 // Erase from Parts[i] all the classes that's being designated for erasure
20717 
20718                 for (int d = K-1; d > -1; d--){
20719                         if (*(Parts[i][d]) < 0) Parts[i].erase(Parts[i].begin()+d);
20720                 }
20721 
20722         }
20723         //cout <<"number of classes left in each partition after initial prune\n";      
20724         // Print out how many classes are left in each partition
20725         //for (int i =0; i < nParts; i++)
20726         //      cout << Parts[i].size()<<", ";
20727         //cout << "\n";
20728 }

string Util::int2str int  n  )  [static]
 

Get a string format of an integer, e.g.

123 will be "123".

Parameters:
[in] n The input integer.
Returns:
The string format of the given integer.

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 }

bool Util::is_file_exist const string &  filename  )  [static]
 

check whether a file exists or not

Returns:
True if the file exists; False if 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 }

bool EMAN::Util::IsPower2 int  x  )  [inline, static]
 

Return true if an integer is positive and is power of 2.

Parameters:
[in] x integer to be checked
Returns:
true if the integer is positive and is power of 2

Definition at line 2103 of file util.h.

Referenced by EMAN::WaveletProcessor::process_inplace().

int Util::k_means_cont_table_ int *  group1,
int *  group2,
int *  stb,
long int  s1,
long int  s2,
int  flag
[static]
 

helper to create the contengency table for partition matching (k-means) flag define is the list of stable obj must be store to stb, but the size st must be know before.

The trick is first start wihtout the flag to get number of elements stable, then again with the flag to get the list. This avoid to have two differents functions for the same thing.

Definition at line 5225 of file util_sparx.cpp.

References max.

05225                                                                                                     {
05226     long int d2 = group2[s2 - 1] - group2[0];
05227     long int p2 = 0;
05228     long int i1 = 0;
05229     long int i2 = 0;
05230     long int max = 0;
05231     long int cont = 0;
05232     long int i = 0;
05233     int stop1 = 0;
05234     int stop2 = 0;
05235 
05236     for (i=0; i<s1; i++) {
05237         p2 = (long int)(s2 * (double)group1[i] / (double)d2);
05238         if (p2 >= s2) {p2 = s2 - 1;}
05239         i1 = p2;
05240         i2 = p2;
05241         max = s2;
05242         if (group1[i] < group2[0] || group1[i] > group2[s2 - 1]) {continue;}
05243 
05244         stop1 = 0;
05245         stop2 = 0;
05246         while (max--) {
05247             if (group1[i] == group2[i1]) {
05248                 if (flag) {stb[cont] = group1[i];}
05249                 cont++;
05250                 break;
05251             }
05252             if (group2[i1] < group1[i]) {stop1=1;}
05253             if (group1[i] == group2[i2]) {
05254                 if (flag) {stb[cont] = group1[i];}
05255                 cont++;
05256                 break;
05257             }
05258             if (group2[i2] > group1[i]) {stop2=1;}
05259             //printf("i1 %li i2 %li    v2 %i v2 %i   stop1 %i stop2 %i\n", i1, i2, group2[i1], group2[i2], stop1, stop2);
05260 
05261             if (stop1 & stop2) {break;}
05262             i1--;
05263             i2++;
05264             if (i1 < 0) {i1 = 0;}
05265             if (i2 >= s2) {i2 = s2 - 1;}
05266         }
05267         //printf("v1: %i    ite: %li   cont: %li\n", group1[i], s2-max, cont);
05268     }
05269 
05270     return cont;
05271 }

float EMAN::Util::linear_interpolate float  p1,
float  p2,
float  t
[inline, static]
 

Calculate linear interpolation.

Parameters:
[in] p1 The first number (at x1).
[in] p2 The second number (at x2).
[in] t (x-x1)/(x2-x1)
Returns:
The linearly interpolated value at x.

Definition at line 1472 of file util.h.

Referenced by EMAN::WienerFourierReconstructor::do_insert_slice_work(), and EMAN::StandardProjector::project3d().

vector< float > Util::list_mutation vector< float >  list,
float  mutation_rate,
float  min_val,
float  max_val,
int  K,
int  is_mirror
[static]
 

Definition at line 20403 of file util_sparx.cpp.

References q, and t.

20403                                                                                                                              {
20404 
20405         if (is_mirror != 0) {
20406                 for (vector<float>::iterator q=list.begin(); q!=list.end(); q++) {
20407                         int r = rand()%10000;
20408                         float f = r/10000.0f;
20409                         if (f < mutation_rate) *q = 1-*q;
20410                 }
20411         } else {
20412                 map<int, vector<int> >  graycode;
20413                 map<vector<int>, int> rev_graycode;
20414                 vector <int> gray;
20415 
20416                 int K=1;
20417                 for (int i=0; i<L; i++) K*=2;
20418 
20419                 for (int k=0; k<K; k++) {
20420                         int shift = 0;
20421                         vector <int> gray;
20422                         for (int i=L-1; i>-1; i--) {
20423                                 int t = ((k>>i)%2-shift)%2;
20424                                 gray.push_back(t);
20425                                 shift += t-2;
20426                         }
20427                         graycode[k] = gray;
20428                         rev_graycode[gray] = k;
20429                 }
20430 
20431                 float gap = (K-1)/(max_val-min_val);
20432                 for (vector<float>::iterator q=list.begin(); q!=list.end(); q++) {
20433                         float val = *q;
20434                         if (val < min_val) { val = min_val; }
20435                         else if  (val > max_val) { val = max_val; }
20436                         int k = int((val-min_val)*gap+0.5);
20437                         vector<int> gray = graycode[k];
20438                         bool changed = false;
20439                         for (vector<int>::iterator p=gray.begin(); p!=gray.end(); p++) {
20440                                 int r = rand()%10000;
20441                                 float f = r/10000.0f;
20442                                 if (f < mutation_rate) {
20443                                         *p = 1-*p;
20444                                         changed = true;
20445                                 }
20446                         }
20447                         if (changed) {
20448                                 k = rev_graycode[gray];
20449                                 *q = k/gap+min_val;
20450                         }
20451                 }
20452         }
20453         return list;
20454 }

vector< float > Util::lsfit long int *  ks,
long int *  n,
long int *  klm2d,
long int *  iswi,
float *  q1,
double *  q,
double *  x,
double *  res,
double *  cu,
double *  s,
long int *  iu
[static]
 

Definition at line 6455 of file util_sparx.cpp.

References cl1(), q, and x.

06456 {
06457     /* System generated locals */
06458     long int q_dim1, q_offset, q1_dim1, q1_offset, i__1, i__2;
06459 
06460     /* Local variables */
06461     long int i__, j, m, n1, ii, jj;
06462     double tmp;
06463     vector<float> p;
06464     --x;
06465     q_dim1 = *klm2d;
06466     q_offset = 1 + q_dim1;
06467     q -= q_offset;
06468     q1_dim1 = *klm2d;
06469     q1_offset = 1 + q1_dim1;
06470     q1 -= q1_offset;
06471     --s;
06472     --res;
06473     iu -= 3;
06474     cu -= 3;
06475 
06476     /* Function Body */
06477     long int l = 0;
06478 
06479 /* C==ZHONG HUANG,JULY,12,02;L=0,1,2,3,4,5,6 correspond to different equality constraints */
06480     m = *ks;
06481     n1 = *n + 1;
06482     if (*iswi == 1) {
06483         i__1 = n1;
06484         for (jj = 1; jj <= i__1; ++jj) {
06485             i__2 = *ks;
06486             for (ii = 1; ii <= i__2; ++ii) {
06487         /*      q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];*/
06488 
06489                 q[*ks + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1]
06490                         ;
06491             }
06492         }
06493     } else if (*iswi == 2) {
06494         i__1 = *ks;
06495         for (ii = 1; ii <= i__1; ++ii) {
06496             i__2 = n1;
06497             for (jj = 1; jj <= i__2; ++jj) {
06498                 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06499                 q[*ks + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]);
06500             }
06501         }
06502     } else if (*iswi == 3) {
06503         l = 2;
06504         i__1 = n1;
06505         for (jj = 1; jj <= i__1; ++jj) {
06506             i__2 = *ks + 2;
06507             for (ii = 1; ii <= i__2; ++ii) {
06508                 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06509             }
06510             i__2 = *ks;
06511             for (ii = 1; ii <= i__2; ++ii) {
06512                 q[*ks + 2 + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06513             }
06514         }
06515     } else if (*iswi == 4) {
06516         l = 2;
06517         i__1 = n1;
06518         for (jj = 1; jj <= i__1; ++jj) {
06519             i__2 = *ks + 2;
06520             for (ii = 1; ii <= i__2; ++ii) {
06521                 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06522             }
06523             i__2 = *ks;
06524             for (ii = 1; ii <= i__2; ++ii) {
06525                 q[*ks + 2 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]);
06526             }
06527         }
06528     } else if (*iswi == 5) {
06529         l = 1;
06530         i__1 = n1;
06531         for (jj = 1; jj <= i__1; ++jj) {
06532             i__2 = *ks + 1;
06533             for (ii = 1; ii <= i__2; ++ii) {
06534                 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06535             }
06536             i__2 = *ks;
06537             for (ii = 1; ii <= i__2; ++ii) {
06538                 q[*ks + 1 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]);
06539             }
06540         }
06541     } else if (*iswi == 6) {
06542         l = 1;
06543         i__1 = n1;
06544         for (jj = 1; jj <= i__1; ++jj) {
06545             i__2 = *ks + 1;
06546             for (ii = 1; ii <= i__2; ++ii) {
06547                 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06548             }
06549             i__2 = *ks;
06550             for (ii = 1; ii <= i__2; ++ii) {
06551                 q[*ks + 1 + ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06552             }
06553         }
06554     } else if (*iswi == 7) {
06555         l = 3;
06556         i__1 = n1;
06557         for (jj = 1; jj <= i__1; ++jj) {
06558             i__2 = *ks + 3;
06559             for (ii = 1; ii <= i__2; ++ii) {
06560                 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06561             }
06562             i__2 = *ks;
06563             for (ii = 1; ii <= i__2; ++ii) {
06564                 q[*ks + 3 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]);
06565             }
06566         }
06567     } else if (*iswi == 8) {
06568         l = 4;
06569         i__1 = n1;
06570         for (jj = 1; jj <= i__1; ++jj) {
06571             i__2 = *ks + 4;
06572             for (ii = 1; ii <= i__2; ++ii) {
06573                 q[ii + jj * q_dim1] = (double) q1[ii + jj * q1_dim1];
06574             }
06575             i__2 = *ks;
06576             for (ii = 1; ii <= i__2; ++ii) {
06577                 q[*ks + 4 + ii + jj * q_dim1] = -((double) q1[ii + jj * q1_dim1]);
06578             }
06579         }
06580     }
06581 
06582     Util::cl1(ks, &l, &m, n, klm2d, &q[q_offset], &x[1], &res[1], &cu[3], &iu[3], &s[1]);
06583     i__1 = *ks;
06584     int tmp__j=0;
06585     for (i__ = 1; i__ <= i__1; ++i__) {
06586         tmp = 0.f;
06587         i__2 = *n - 1;
06588         for (j = 1; j <= i__2; ++j) {
06589         tmp__j=j;
06590             tmp += pow(q1[i__ + q1_dim1], tmp__j) * x[j];
06591         }
06592         tmp += x[*n];
06593         p.push_back(static_cast<float>(exp(tmp)));
06594         p.push_back(q1[i__ + q1_dim1]);
06595     }
06596     i__2=*n;
06597     for (i__=1;i__<=i__2;++i__)
06598         { p.push_back(static_cast<float>(x[i__]));}
06599     return p;
06600 }

void Util::mad_scalar EMData img,
EMData img1,
float  scalar
[static]
 

Definition at line 17591 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().

17592 {
17593         ENTERFUNC;
17594         /* Exception Handle */
17595         if (!img) {
17596                 throw NullPointerException("NULL input image");
17597         }
17598         /* ==============   img += scalar*img1   ================ */
17599 
17600         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17601         size_t size = (size_t)nx*ny*nz;
17602         float *img_ptr  =img->get_data();
17603         float *img1_ptr = img1->get_data();
17604         for (size_t i=0;i<size;++i)img_ptr[i] += img1_ptr[i]*scalar;
17605         img1->update();
17606 
17607         EXITFUNC;
17608 }

EMData * Util::madn_scalar EMData img,
EMData img1,
float  scalar
[static]
 

Definition at line 17401 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().

17402 {
17403         ENTERFUNC;
17404         /* Exception Handle */
17405         if (!img) {
17406                 throw NullPointerException("NULL input image");
17407         }
17408         /* ==============   output = img + scalar*img1   ================ */
17409 
17410         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17411         size_t size = (size_t)nx*ny*nz;
17412         EMData * img2 = img->copy_head();
17413         float *img_ptr  =img->get_data();
17414         float *img2_ptr = img2->get_data();
17415         float *img1_ptr = img1->get_data();
17416         for (size_t i=0;i<size;++i) img2_ptr[i] = img_ptr[i] + img1_ptr[i]*scalar;
17417         img2->update();
17418         if(img->is_complex()) {
17419                 img2->set_complex(true);
17420                 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false);
17421         }
17422 
17423         EXITFUNC;
17424         return img2;
17425 }

float EMAN::Util::mean float *  x,
int  n
[inline, static]
 

Definition at line 1041 of file util.h.

Referenced by get_stats(), get_stats_cstyle(), and multi_align_error_dfunc().

vector< float > Util::merge_peaks vector< float >  peak1,
vector< float >  peak2,
float  p_size
[static]
 

Definition at line 6237 of file util_sparx.cpp.

06238 {
06239         vector<float>new_peak;
06240         int n1=peak1.size()/3;
06241         float p_size2=p_size*p_size;
06242         for (int i=0;i<n1;++i) {
06243                 vector<float>::iterator it2= peak1.begin()+3*i;
06244                 bool push_back1=true;
06245                 int n2=peak2.size()/3;
06246                 /*cout<<"peak2 size==="<<n2<<"i====="<<i<<endl;
06247                        cout<<"new peak size==="<<new_peak.size()/3<<endl;*/
06248                 if(n2 ==0) {
06249                         new_peak.push_back(*it2);
06250                         new_peak.push_back(*(it2+1));
06251                         new_peak.push_back(*(it2+2));
06252                 } else  {
06253                         int j=0;
06254                         while (j< n2-1 ) {
06255                                 vector<float>::iterator it3= peak2.begin()+3*j;
06256                                 float d2=((*(it2+1))-(*(it3+1)))*((*(it2+1))-(*(it3+1)))+((*(it2+2))-(*(it3+2)))*((*(it2+2))-(*(it3+2)));
06257                                 if(d2< p_size2 ) {
06258                                         if( (*it2)<(*it3) ) {
06259                                                 new_peak.push_back(*it3);
06260                                                 new_peak.push_back(*(it3+1));
06261                                                 new_peak.push_back(*(it3+2));
06262                                                 peak2.erase(it3);
06263                                                 peak2.erase(it3);
06264                                                 peak2.erase(it3);
06265                                                 push_back1=false;
06266                                         } else {
06267                                                 peak2.erase(it3);
06268                                                 peak2.erase(it3);
06269                                                 peak2.erase(it3);
06270                                         }
06271                                 } else  j=j+1;
06272                                 n2=peak2.size()/3;
06273                         }
06274                         if(push_back1) {
06275                                 new_peak.push_back(*it2);
06276                                 new_peak.push_back(*(it2+1));
06277                                 new_peak.push_back(*(it2+2));
06278                         }
06279                 }
06280         }
06281         return new_peak;
06282 }

Dict Util::min_dist_four EMData image,
const vector< EMData * > &  data
[static]
 

helper function for k-means

Definition at line 5150 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().

05150                                                                    {
05151         ENTERFUNC;
05152 
05153         int nima = data.size();
05154         vector<float> res(nima);
05155         double result = 0.;
05156         double valmin = 1.0e20;
05157         int valpos = -1;
05158 
05159         for (int kk=0; kk<nima; kk++){
05160         result = 0;
05161         //validate_input_args(image, data[kk]);
05162 
05163         float *y_data = data[kk]->get_data();
05164         float *x_data = image->get_data();
05165 
05166         // Implemented by PAP  01/09/06 - please do not change.  If in doubts, write/call me.
05167         int nx  = data[kk]->get_xsize();
05168         int ny  = data[kk]->get_ysize();
05169         nx = (nx - 2 + data[kk]->is_fftodd()); // nx is the real-space size of the input image
05170         int lsd2 = (nx + 2 - nx%2) ; // Extended x-dimension of the complex image
05171 
05172         int ixb = 2*((nx+1)%2);
05173         int iyb = ny%2;
05174         int iz = 0;
05175 
05176         for ( int iy = 0; iy <= ny-1; iy++) {
05177             for ( int ix = 2; ix <= lsd2 - 1 - ixb; ix++) {
05178                 int ii = ix + (iy  + iz * ny)* lsd2;
05179                 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
05180             }
05181         }
05182         for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) {
05183             int ii = (iy  + iz * ny)* lsd2;
05184             result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
05185             result += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]);
05186         }
05187         if(nx%2 == 0) {
05188             for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) {
05189                 int ii = lsd2 - 2 + (iy  + iz * ny)* lsd2;
05190                 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
05191                 result += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]);
05192             }
05193 
05194         }
05195         result *= 2;
05196         result += (x_data[0] - y_data[0])*double(x_data[0] - y_data[0]);
05197         if(ny%2 == 0) {
05198             int ii = (ny/2  + iz * ny)* lsd2;
05199             result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
05200         }
05201         if(nx%2 == 0) {
05202             int ii = lsd2 - 2 + (0  + iz * ny)* lsd2;
05203             result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
05204             if(ny%2 == 0) {
05205                 int ii = lsd2 - 2 +(ny/2  + iz * ny)* lsd2;
05206                 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
05207             }
05208         }
05209 
05210         result /= (long int)nx*(long int)ny*(long int)nx*(long int)ny;
05211         res[kk] = (float)result;
05212 
05213         if(result<valmin) {valmin = result; valpos = kk;}
05214 
05215         }
05216 
05217         Dict retvals;
05218         retvals["dist"] = res;
05219         retvals["pos"]  = valpos;
05220 
05221         EXITFUNC;
05222         return retvals;
05223 }

Dict Util::min_dist_real EMData image,
const vector< EMData * > &  data
[static]
 

k-means helper

Definition at line 5115 of file util_sparx.cpp.

References data, EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), and EMAN::Dict::size().

05115                                                                    {
05116         ENTERFUNC;
05117 
05118         int nima = data.size();
05119         vector<float> res(nima);
05120         double result = 0.;
05121         double valmin = 1.0e20;
05122         int valpos = -1;
05123 
05124         for (int kk=0; kk<nima; kk++){
05125         result = 0;
05126 
05127         float *y_data = data[kk]->get_data();
05128         float *x_data = image->get_data();
05129         long totsize = image->get_xsize()*image->get_ysize();
05130         for (long i = 0; i < totsize; i++) {
05131             double temp = x_data[i]- y_data[i];
05132             result += temp*temp;
05133         }
05134         result /= totsize;
05135         res[kk] = (float)result;
05136 
05137         if(result<valmin) {valmin = result; valpos = kk;}
05138 
05139         }
05140 
05141         Dict retvals;
05142         retvals["dist"] = res;
05143         retvals["pos"]  = valpos;
05144 
05145         EXITFUNC;
05146         return retvals;
05147 
05148 }

int EMAN::Util::mono int  k1,
int  k2
[inline, static]
 

Definition at line 1026 of file util.h.

Referenced by cluster_pairwise().

EMData * Util::move_points EMData img,
float  qprob,
int  ri,
int  ro
[static]
 

Definition at line 19579 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().

19580 {
19581         ENTERFUNC;
19582         /* Exception Handle */
19583         if (!img) {
19584                 throw NullPointerException("NULL input image");
19585         }
19586 
19587         int newx, newy, newz;
19588         bool  keep_going;
19589         cout << " entered   " <<endl;
19590         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
19591         //int size = nx*ny*nz;
19592         EMData * img2 = new EMData();
19593         img2->set_size(nx,ny,nz);
19594         img2->to_zero();
19595         float *img_ptr  =img->get_data();
19596         float *img2_ptr = img2->get_data();
19597         int r2 = ro*ro;
19598         int r3 = r2*ro;
19599         int ri2 = ri*ri;
19600         int ri3 = ri2*ri;
19601 
19602         int n2 = nx/2;
19603 
19604         for (int k=-n2; k<=n2; k++) {           //cout << " k   "<<k <<endl;
19605                 float z2 = static_cast<float>(k*k);
19606                 for (int j=-n2; j<=n2; j++) {
19607                         float y2 = z2 + j*j;
19608                         if(y2 <= r2) {
19609                                                                                         //cout << "  j  "<<j <<endl;
19610 
19611                                 for (int i=-n2; i<=n2; i++) {
19612                                         float x2 = y2 + i*i;
19613                                         if(x2 <= r3) {
19614                                                                                         //cout << "  i  "<<i <<endl;
19615                                                 int ib = i+n2; int jb = j+n2; int kb = k+n2;
19616                                                 if(x2 >= ri3) {
19617                                                         //  this is the outer shell, here points can only vanish
19618                                                         if(img_ptr(ib,jb,kb) == 1.0f) {
19619                                                                 //cout << "  1  "<<ib <<endl;
19620                                                                 if(Util::get_frand(0.0f, 1.0f) > qprob){
19621                                                                         img2_ptr(ib,jb,kb) = 0.0f;
19622                                                                         keep_going = true;
19623                                                                 //cout << "  try  "<<ib <<endl;
19624                                                                         while(keep_going) {
19625                                                                                 newx = Util::get_irand(-ro,ro);
19626                                                                                 newy = Util::get_irand(-ro,ro);
19627                                                                                 newz = Util::get_irand(-ro,ro);
19628                                                                                 if(newx*newx+newy*newy+newz*newz <= r3) {
19629                                                                                         newx += n2; newy += n2; newz += n2;
19630                                                                                         if( img_ptr(newx,newy,newz) == 0.0f) {
19631                                                                                                 img2_ptr(newx,newy,newz) = 1.0f;
19632                                                                                                 keep_going = false; }
19633                                                                                 }
19634                                                                         }
19635                                                                 }   else  img2_ptr(ib,jb,kb) = 1.0f;
19636                                                         }
19637                                                 }  else  {
19638                                                         // this is inner shell, the point can only move (or vanish, if all neighbors exist)
19639                                                         if(img_ptr(ib,jb,kb) == 1.0) {
19640                                                                 if(Util::get_frand(0.0f,1.0f) > qprob) {
19641                                                                         //  find out the number of neighbors
19642                                                                         float  numn = -1.0f;  // we already know the central one is 1
19643                                                                         for (newz = -1; newz <= 1; newz++)
19644                                                                                 for (newy = -1; newy <= 1; newy++)
19645                                                                                         for (newx = -1; newx <= 1; newx++)
19646                                                                                                 numn += img_ptr(ib+newx,jb+newy,kb+newz);
19647                                                                         img2_ptr(ib,jb,kb) = 0.0;
19648                                                                         if(numn == 26.0f) {
19649                                                                                 //  all neighbors exist, it has to vanish
19650                                                                                 keep_going = true;
19651                                                                                 while(keep_going) {
19652                                                                                         newx = Util::get_irand(-ro,ro);
19653                                                                                         newy = Util::get_irand(-ro,ro);
19654                                                                                         newz = Util::get_irand(-ro,ro);
19655                                                                                         if(newx*newx+newy*newy+newz*newz < r3) {
19656                                                                                                 newx += n2; newy += n2; newz += n2;
19657                                                                                                 if( img_ptr(newx,newy,newz) == 0.0f) {
19658                                                                                                         if(newx*newx+newy*newy+newz*newz < r3) {
19659                                                                                                                 if(newx*newx+newy*newy+newz*newz < r3) {
19660                                                                                                                         newx += n2; newy += n2; newz += n2;
19661                                                                                                                         if( img_ptr(newx,newy,newz) == 0.0f) {
19662                                                                                                                                 img2_ptr(newx,newy,newz) = 1.0f;
19663                                                                                                                                 keep_going = false; }
19664                                                                                                                 }
19665                                                                                                         }
19666                                                                                                 }
19667                                                                                         }
19668                                                                                 }
19669                                                                         }  else if(numn == 25.0f) {
19670                                                                                 // there is only one empty neighbor, move there
19671                                                                                 for (newz = -1; newz <= 1; newz++) {
19672                                                                                         for (newy = -1; newy <= 1; newy++) {
19673                                                                                                 for (newx = -1; newx <= 1; newx++) {
19674                                                                                                         if( newx != 0 && newy != 0 && newz != 0) {
19675                                                                                                                 if(img_ptr(newx+ib,newy+jb,newz+kb) == 0.0f) {
19676                                                                                                                         img2_ptr(newx+ib,newy+jb,newz+kb) = 1.0f;
19677                                                                                                                         }
19678                                                                                                         }
19679                                                                                                 }
19680                                                                                         }
19681                                                                                 }
19682                                                                         }  else {
19683                                                                                 //  more than one neighbor is zero, select randomly one and move there
19684                                                                                 keep_going = true;
19685                                                                                 while(keep_going) {
19686                                                                                         newx = Util::get_irand(-1,1);
19687                                                                                         newy = Util::get_irand(-1,1);
19688                                                                                         newz = Util::get_irand(-1,1);
19689                                                                                         if(newx != 0 && newy != 0 && newz != 0)  {
19690                                                                                                 if(img_ptr(ib+newx,jb+newy,kb+newz) == 0.0f) {
19691                                                                                                         img2_ptr(ib+newx,jb+newy,kb+newz) = 1.0f;//?????
19692                                                                                                         keep_going = false;
19693                                                                                                 }
19694                                                                                         }
19695                                                                                 }
19696                                                                         }
19697                                                                 }  else img2_ptr(ib,jb,kb) = 1.0f;
19698                                                         }
19699                                                 }
19700                                         }
19701                                 }
19702                         }
19703                 }
19704         }
19705         //for (int i=0;i<size;i++) img2_ptr[i] = img_ptr[i] + Util::get_irand(1,7);
19706         img2->update();
19707 
19708         EXITFUNC;
19709         return img2;
19710 }

void Util::mul_img EMData img,
EMData img1
[static]
 

Definition at line 17690 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().

17691 {
17692         ENTERFUNC;
17693         /* Exception Handle */
17694         if (!img) {
17695                 throw NullPointerException("NULL input image");
17696         }
17697         /* ========= img *= img1 ===================== */
17698 
17699         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17700         size_t size = (size_t)nx*ny*nz;
17701         float *img_ptr  = img->get_data();
17702         float *img1_ptr = img1->get_data();
17703         if(img->is_complex()) {
17704                 for (size_t i=0; i<size; i+=2) {
17705                         float tmp     = img_ptr[i] * img1_ptr[i]   - img_ptr[i+1] * img1_ptr[i+1] ;
17706                         img_ptr[i+1] = img_ptr[i] * img1_ptr[i+1] + img_ptr[i+1] * img1_ptr[i] ;
17707                         img_ptr[i]   = tmp;
17708 
17709                 }
17710         } else {
17711                 for (size_t i=0;i<size;++i) img_ptr[i] *= img1_ptr[i];
17712         }
17713         img->update();
17714 
17715         EXITFUNC;
17716 }

void Util::mul_scalar EMData img,
float  scalar
[static]
 

Definition at line 17573 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().

17574 {
17575         ENTERFUNC;
17576         /* Exception Handle */
17577         if (!img) {
17578                 throw NullPointerException("NULL input image");
17579         }
17580         /* ============  output = scalar*input  ================== */
17581 
17582         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17583         size_t size = (size_t)nx*ny*nz;
17584         float *img_ptr  =img->get_data();
17585         for (size_t i=0;i<size;++i) img_ptr[i] *= scalar;
17586         img->update();
17587 
17588         EXITFUNC;
17589 }

EMData * Util::muln_img EMData img,
EMData img1
[static]
 

Definition at line 17479 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().

17480 {
17481         ENTERFUNC;
17482         /* Exception Handle */
17483         if (!img) {
17484                 throw NullPointerException("NULL input image");
17485         }
17486         /* ==============   output = img * img1   ================ */
17487 
17488         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17489         size_t size = (size_t)nx*ny*nz;
17490         EMData * img2 = img->copy_head();
17491         float *img_ptr  =img->get_data();
17492         float *img2_ptr = img2->get_data();
17493         float *img1_ptr = img1->get_data();
17494         if(img->is_complex()) {
17495                 for (size_t i=0; i<size; i+=2) {
17496                         img2_ptr[i]   = img_ptr[i] * img1_ptr[i]   - img_ptr[i+1] * img1_ptr[i+1] ;
17497                         img2_ptr[i+1] = img_ptr[i] * img1_ptr[i+1] + img_ptr[i+1] * img1_ptr[i] ;
17498                 }
17499                 img2->set_complex(true);
17500                 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false);
17501         } else {
17502                 for (size_t i=0; i<size; ++i) img2_ptr[i] = img_ptr[i] * img1_ptr[i];
17503                 img2->update();
17504         }
17505 
17506         EXITFUNC;
17507         return img2;
17508 }

EMData * Util::mult_scalar EMData img,
float  scalar
[static]
 

Definition at line 17376 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().

17377 {
17378         ENTERFUNC;
17379         /* Exception Handle */
17380         if (!img) {
17381                 throw NullPointerException("NULL input image");
17382         }
17383         /* ============  output = scalar*input  ================== */
17384 
17385         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17386         size_t size = (size_t)nx*ny*nz;
17387         EMData * img2 = img->copy_head();
17388         float *img_ptr  =img->get_data();
17389         float *img2_ptr = img2->get_data();
17390         for (size_t i=0;i<size;++i)img2_ptr[i] = img_ptr[i]*scalar;
17391         img2->update();
17392 
17393         if(img->is_complex()) {
17394                 img2->set_complex(true);
17395                 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false);
17396         }
17397         EXITFUNC;
17398         return img2;
17399 }

vector< float > Util::multi_align_error vector< float >  args,
vector< float >  all_ali_params
[static]
 

Definition at line 19283 of file util_sparx.cpp.

References multi_align_error_dfunc(), multi_align_error_func(), setulb_(), SIXTY, and x.

19283                                                                                       {
19284         
19285         const int nmax=args.size(), mmax=nmax;
19286         char task[60], csave[60];
19287         long int lsave[4];
19288         long int n, m, iprint, isave[44];
19289         long int* nbd = new long int[nmax];
19290         long int* iwa = new long int[3*nmax];
19291         double f, factr, pgtol;
19292         double* x = new double[nmax];
19293         double* l = new double[nmax];
19294         double* u = new double[nmax];
19295         double* g = new double[nmax];
19296         double dsave[29];
19297         double* wa = new double[2*mmax*nmax+4*nmax+12*mmax*mmax+12*mmax];
19298         long int SIXTY=60;
19299 
19300         int num_ali = nmax/3+1;
19301         int nima = all_ali_params.size()/(num_ali*4);
19302         
19303         //     We wish to have no output.
19304         iprint = -1;
19305 
19306         //c     We specify the tolerances in the stopping criteria.
19307         factr=1.0e1;
19308         pgtol=1.0e-9;
19309 
19310         //     We specify the dimension n of the sample problem and the number
19311         //        m of limited memory corrections stored.  (n and m should not
19312         //        exceed the limits nmax and mmax respectively.)
19313         n=nmax;
19314         m=mmax;
19315 
19316         //     We now provide nbd which defines the bounds on the variables:
19317         //                    l   specifies the lower bounds,
19318         //                    u   specifies the upper bounds.
19319         //                    x   specifies the initial guess
19320         for (int i=0; i<nmax; i++) {
19321                 x[i] = args[i]; 
19322                 nbd[i] = 0;
19323         }
19324 
19325         //     We start the iteration by initializing task.
19326         // (**MUST clear remaining chars in task with spaces (else crash)!**)
19327         strcpy(task,"START");
19328         for (int i=5;i<60;i++)  task[i]=' ';
19329 
19330         //     This is the call to the L-BFGS-B code.
19331         // (* call the L-BFGS-B routine with task='START' once before loop *)
19332         setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
19333         int step = 1;
19334 
19335         // (* while routine returns "FG" or "NEW_X" in task, keep calling it *)
19336         while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) {
19337 
19338                 if (strncmp(task,"FG",2)==0) {
19339                 //   the minimization routine has returned to request the
19340                 //   function f and gradient g values at the current x
19341 
19342                 //        Compute function value f for the sample problem.
19343                 f = multi_align_error_func(x, all_ali_params, nima, num_ali);
19344 
19345                 //        Compute gradient g for the sample problem.
19346                 multi_align_error_dfunc(x, all_ali_params, nima, num_ali, g);
19347                 }
19348 
19349                 //c          go back to the minimization routine.
19350                 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
19351                 step++;
19352         }
19353 
19354         //printf("Total step is %d\n", step);
19355         vector<float> res;
19356         for (int i=0; i<nmax; i++) res.push_back(static_cast<float>(x[i]));
19357         res.push_back((float)f);
19358 
19359         delete[] nbd;
19360         delete[] iwa;
19361         delete[] x;
19362         delete[] l;
19363         delete[] u;
19364         delete[] g;
19365         delete[] wa;
19366 
19367         return res;
19368 
19369 }

void Util::multi_align_error_dfunc double *  x,
vector< float >  all_ali_params,
int  nima,
int  num_ali,
double *  g
[static]
 

Definition at line 19426 of file util_sparx.cpp.

References mean(), rot_shift(), and x.

Referenced by multi_align_error().

19426                                                                                                             {
19427 
19428         
19429         for (int i=0; i<num_ali*3-3; i++) g[i] = 0.0;
19430 
19431         float x1 = 1.0;
19432         float y1 = 0.0;
19433         float x2 = 0.0;
19434         float y2 = 1.0;
19435 
19436         float* x1_new = new float[num_ali];
19437         float* y1_new = new float[num_ali];
19438         float* x2_new = new float[num_ali];
19439         float* y2_new = new float[num_ali];
19440 
19441         float* alpha12_0 = new float[num_ali-1];
19442         float* dalpha12 = new float[num_ali-1];
19443         float* dsx12 = new float[num_ali-1];
19444         float* dsy12 = new float[num_ali-1];
19445         float* mirror1_0 = new float[num_ali-1];
19446 
19447         for (int i=0; i<nima; i++) {
19448 
19449                 float alpha2 = all_ali_params[(num_ali-1)*(nima*4)+i*4];
19450                 float sx2 = all_ali_params[(num_ali-1)*(nima*4)+i*4+1];
19451                 float sy2 = all_ali_params[(num_ali-1)*(nima*4)+i*4+2];
19452 
19453                 rot_shift(x1, y1, alpha2, sx2, sy2, x1_new+num_ali-1, y1_new+num_ali-1);
19454                 rot_shift(x2, y2, alpha2, sx2, sy2, x2_new+num_ali-1, y2_new+num_ali-1);
19455 
19456                 for (int j=0; j<num_ali-1; j++) {
19457                         float alpha1 = all_ali_params[j*(nima*4)+i*4];
19458                         float sx1 = all_ali_params[j*(nima*4)+i*4+1];
19459                         float sy1 = all_ali_params[j*(nima*4)+i*4+2];
19460                         int mirror1 = static_cast<int>(all_ali_params[j*(nima*4)+i*4+3]);
19461 
19462                         float alphai = x[j*3];
19463                         float sxi = x[j*3+1];
19464                         float syi = x[j*3+2];
19465 
19466                         float cosi = cos(alphai/180.0f*M_PI);
19467                         float sini = sin(alphai/180.0f*M_PI);
19468 
19469                         float alpha12, sx12, sy12;
19470                         int mirror12;
19471                         if (mirror1 == 0) {
19472                                 alpha12 = fmod(alpha1+alphai, 360.0f);
19473                                 rot_shift(sx1, sy1, alphai, sxi, syi, &sx12, &sy12);
19474                                 mirror12 = 0;
19475                         } else {
19476                                 alpha12 = fmod(alpha1-alphai, 360.0f);
19477                                 rot_shift(sx1, sy1, -alphai, -sxi, syi, &sx12, &sy12);
19478                                 mirror12 = 1;
19479                         }
19480 
19481                         rot_shift(x1, y1, alpha12, sx12, sy12, x1_new+j, y1_new+j);
19482                         rot_shift(x2, y2, alpha12, sx12, sy12, x2_new+j, y2_new+j);
19483 
19484                         alpha12_0[j] = alpha12;
19485                         mirror1_0[j] = mirror1;
19486                         if (mirror1 == 0) {
19487                                 dalpha12[j] = M_PI/180.0f;
19488                                 dsx12[j] = (-sini*sx1+cosi*sy1)/180.0f*M_PI;
19489                                 dsy12[j] = (-cosi*sx1-sini*sy1)/180.0f*M_PI;
19490                         } else {
19491                                 dalpha12[j] = -M_PI/180.0f;
19492                                 dsx12[j] = (sini*(-sx1)-cosi*sy1)/180.0f*M_PI;
19493                                 dsy12[j] = (-cosi*(-sx1)-sini*sy1)/180.0f*M_PI;
19494                         }
19495                 }
19496 
19497                 for (int j=0; j<num_ali-1; j++) {
19498                         float cosa = cos(alpha12_0[j]/180.0f*M_PI);
19499                         float sina = sin(alpha12_0[j]/180.0f*M_PI);
19500                         float diffx1 = x1_new[j]-mean(x1_new, num_ali);
19501                         float diffx2 = x2_new[j]-mean(x2_new, num_ali);
19502                         float diffy1 = y1_new[j]-mean(y1_new, num_ali);
19503                         float diffy2 = y2_new[j]-mean(y2_new, num_ali);
19504 
19505                         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]);
19506                         g[j*3] += p;
19507                 
19508                         p = diffx1+diffx2;
19509                         if (mirror1_0[j] == 0) g[j*3+1] += p;
19510                         else g[j*3+1] -= p;
19511 
19512                         p = diffy1+diffy2;
19513                         g[j*3+2] += p;
19514                 }
19515         }
19516 
19517         delete[] x1_new;
19518         delete[] y1_new;
19519         delete[] x2_new;
19520         delete[] y2_new;
19521         delete[] alpha12_0;
19522         delete[] dalpha12;
19523         delete[] dsx12;
19524         delete[] dsy12;
19525         delete[] mirror1_0;
19526 
19527 }

float Util::multi_align_error_func double *  x,
vector< float >  all_ali_params,
int  nima,
int  num_ali
[static]
 

Definition at line 19371 of file util_sparx.cpp.

References rot_shift(), var(), and x.

Referenced by multi_align_error().

19371                                                                                                  {
19372 
19373         float x1 = 1.0;
19374         float y1 = 0.0;
19375         float x2 = 0.0;
19376         float y2 = 1.0;
19377 
19378         float all_var = 0;
19379         float* x1_new = new float[num_ali];
19380         float* y1_new = new float[num_ali];
19381         float* x2_new = new float[num_ali];
19382         float* y2_new = new float[num_ali];
19383 
19384         for (int i=0; i<nima; i++) {
19385                 float alpha2 = all_ali_params[(num_ali-1)*(nima*4)+i*4];
19386                 float sx2 = all_ali_params[(num_ali-1)*(nima*4)+i*4+1];
19387                 float sy2 = all_ali_params[(num_ali-1)*(nima*4)+i*4+2];
19388                 
19389                 rot_shift(x1, y1, alpha2, sx2, sy2, x1_new+num_ali-1, y1_new+num_ali-1);
19390                 rot_shift(x2, y2, alpha2, sx2, sy2, x2_new+num_ali-1, y2_new+num_ali-1);
19391                 for (int j=0; j<num_ali-1; j++) {
19392                         float alpha1 = all_ali_params[j*(nima*4)+i*4];
19393                         float sx1 = all_ali_params[j*(nima*4)+i*4+1];
19394                         float sy1 = all_ali_params[j*(nima*4)+i*4+2];
19395                         int mirror1 = static_cast<int>(all_ali_params[j*(nima*4)+i*4+3]);
19396 
19397                         float alphai = x[j*3];
19398                         float sxi = x[j*3+1];
19399                         float syi = x[j*3+2];
19400 
19401                         float alpha12, sx12, sy12;
19402                         int mirror12;
19403                         if (mirror1 == 0) {
19404                                 alpha12 = fmod(alpha1+alphai, 360.0f);
19405                                 rot_shift(sx1, sy1, alphai, sxi, syi, &sx12, &sy12);
19406                                 mirror12 = 0;
19407                         } else {
19408                                 alpha12 = fmod(alpha1-alphai, 360.0f);
19409                                 rot_shift(sx1, sy1, -alphai, -sxi, syi, &sx12, &sy12);
19410                                 mirror12 = 1;
19411                         }
19412 
19413                         rot_shift(x1, y1, alpha12, sx12, sy12, x1_new+j, y1_new+j);
19414                         rot_shift(x2, y2, alpha12, sx12, sy12, x2_new+j, y2_new+j);
19415                 }
19416                 
19417                 all_var += var(x1_new, num_ali)+var(y1_new, num_ali)+var(x2_new, num_ali)+var(y2_new, num_ali);
19418         }
19419         delete[] x1_new;
19420         delete[] y1_new;
19421         delete[] x2_new;
19422         delete[] y2_new;
19423         return all_var/static_cast<float>(nima-1);
19424 }

void Util::multiref_peaks_ali2d EMData image,
EMData crefim,
float  xrng,
float  yrng,
float  step,
string  mode,
vector< int >  numr,
float  cnx,
float  cny,
EMData peaks,
EMData peakm
[static]
 

Determine shift and rotation between image and one reference image (crefim, weights have to be applied) using quadratic interpolation, return a list of peaks PAP 07/21/08.

ccf1d keeps 1d ccfs stored as (maxrin, -kx-1:kx+1, -ky-1:ky+1) margin is needed for peak search and both arrays are initialized with -1.0e20

Definition at line 18661 of file util_sparx.cpp.

References Crosrng_msg_vec(), Frngs(), EMAN::EMData::get_data(), numr, Polar2Dm(), and EMAN::EMData::set_size().

18664                                                       {
18665 
18666         int   maxrin = numr[numr.size()-1];
18667 
18668         int   ky = int(2*yrng/step+0.5)/2;
18669         int   kx = int(2*xrng/step+0.5)/2;
18670 
18671         peaks->set_size(maxrin, 2*kx+3, 2*ky+3);
18672         float *p_ccf1ds = peaks->get_data();
18673 
18674         peakm->set_size(maxrin, 2*kx+3, 2*ky+3);
18675         float *p_ccf1dm = peakm->get_data();
18676 
18677         for ( int i = 0; i<maxrin*(2*kx+3)*(2*ky+3); i++) {
18678                 p_ccf1ds[i] = -1.e20f;
18679                 p_ccf1dm[i] = -1.e20f;
18680         }
18681 
18682         for (int i = -ky; i <= ky; i++) {
18683                 float iy = i * step;
18684                 for (int j = -kx; j <= kx; j++) {
18685                         float ix = j*step;
18686                         EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18687                         Frngs(cimage, numr);
18688                         Crosrng_msg_vec(crefim, cimage, numr,
18689                           p_ccf1ds+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin,
18690                           p_ccf1dm+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin);
18691                         delete cimage; cimage = 0;
18692                 }
18693         }
18694         return;
18695 }

void Util::multiref_peaks_compress_ali2d EMData image,
EMData crefim,
float  xrng,
float  yrng,
float  step,
string  mode,
vector< int >  numr,
float  cnx,
float  cny,
EMData peaks,
EMData peakm,
EMData peaks_compress,
EMData peakm_compress
[static]
 

Determine shift and rotation between image and one reference image (crefim, weights have to be applied) using quadratic interpolation, return a list of peaks PAP 07/21/08.

ccf1d keeps 1d ccfs stored as (maxrin, -kx-1:kx+1, -ky-1:ky+1) margin is needed for peak search and both arrays are initialized with -1.0e20

Definition at line 18697 of file util_sparx.cpp.

References Crosrng_msg_vec(), Frngs(), EMAN::EMData::get_data(), numr, Polar2Dm(), EMAN::EMData::set_size(), and x.

18699                                                      {
18700 
18701         int   maxrin = numr[numr.size()-1];
18702 
18703         int   ky = int(2*yrng/step+0.5)/2;
18704         int   kx = int(2*xrng/step+0.5)/2;
18705 
18706         peaks->set_size(maxrin, 2*kx+3, 2*ky+3);
18707         float *p_ccf1ds = peaks->get_data();
18708 
18709         peakm->set_size(maxrin, 2*kx+3, 2*ky+3);
18710         float *p_ccf1dm = peakm->get_data();
18711 
18712         peaks_compress->set_size(maxrin, 1, 1);
18713         float *p_ccf1ds_compress = peaks_compress->get_data();
18714 
18715         peakm_compress->set_size(maxrin, 1, 1);
18716         float *p_ccf1dm_compress = peakm_compress->get_data();
18717 
18718         for ( int i = 0; i<maxrin*(2*kx+3)*(2*ky+3); i++) {
18719                 p_ccf1ds[i] = -1.e20f;
18720                 p_ccf1dm[i] = -1.e20f;
18721         }
18722 
18723         for (int i = -ky; i <= ky; i++) {
18724                 float iy = i * step;
18725                 for (int j = -kx; j <= kx; j++) {
18726                         float ix = j*step;
18727                         EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18728                         Frngs(cimage, numr);
18729                         Crosrng_msg_vec(crefim, cimage, numr,
18730                           p_ccf1ds+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin,
18731                           p_ccf1dm+(j+kx+1+((i+ky+1)*(2*kx+3)))*maxrin);
18732                         delete cimage; cimage = 0;
18733                 }
18734         }
18735         for (int x=0; x<maxrin; x++) {
18736                 float maxs = -1.0e22f;
18737                 float maxm = -1.0e22f;
18738                 for (int i=1; i<=2*ky+1; i++) {
18739                         for (int j=1; j<=2*kx+1; j++) {
18740                                 if (p_ccf1ds[(i*(2*kx+3)+j)*maxrin+x] > maxs) maxs = p_ccf1ds[(i*(2*kx+3)+j)*maxrin+x];
18741                                 if (p_ccf1dm[(i*(2*kx+3)+j)*maxrin+x] > maxm) maxm = p_ccf1dm[(i*(2*kx+3)+j)*maxrin+x];
18742                         }
18743                 }
18744                 p_ccf1ds_compress[x] = maxs;
18745                 p_ccf1dm_compress[x] = maxm;
18746         }
18747         return;
18748 }

vector< float > Util::multiref_polar_ali_2d EMData image,
const vector< EMData * > &  crefim,
float  xrng,
float  yrng,
float  step,
string  mode,
vector< int >  numr,
float  cnx,
float  cny
[static]
 

formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation

Definition at line 17899 of file util_sparx.cpp.

References ang_n(), Crosrng_ms(), Frngs(), Normalize_ring(), numr, pi, Polar2Dm(), and EMAN::Dict::size().

17901                                                        {
17902 
17903     // Manually extract.
17904 /*    vector< EMAN::EMData* > crefim;
17905     std::size_t crefim_len = PyObject_Length(crefim_list.ptr());
17906     crefim.reserve(crefim_len);
17907 
17908     for(std::size_t i=0;i<crefim_len;i++) {
17909         boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]);
17910         crefim.push_back(proxy());
17911     }
17912 */
17913 
17914         size_t crefim_len = crefim.size();
17915 
17916         int   ky = int(2*yrng/step+0.5)/2;
17917         int   kx = int(2*xrng/step+0.5)/2;
17918         int   iref, nref=0, mirror=0;
17919         float iy, ix, sx=0, sy=0;
17920         float peak = -1.0E23f;
17921         float ang=0.0f;
17922         for (int i = -ky; i <= ky; i++) {
17923                 iy = i * step ;
17924                 for (int j = -kx; j <= kx; j++) {
17925                         ix = j*step ;
17926                         EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
17927 
17928                         Normalize_ring( cimage, numr );
17929 
17930                         Frngs(cimage, numr);
17931                         //  compare with all reference images
17932                         // for iref in xrange(len(crefim)):
17933                         for ( iref = 0; iref < (int)crefim_len; iref++) {
17934                                 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr);
17935                                 double qn = retvals["qn"];
17936                                 double qm = retvals["qm"];
17937                                 if(qn >= peak || qm >= peak) {
17938                                         sx = -ix;
17939                                         sy = -iy;
17940                                         nref = iref;
17941                                         if (qn >= qm) {
17942                                                 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
17943                                                 peak = static_cast<float>(qn);
17944                                                 mirror = 0;
17945                                         } else {
17946                                                 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
17947                                                 peak = static_cast<float>(qm);
17948                                                 mirror = 1;
17949                                         }
17950                                 }
17951                         }  delete cimage; cimage = 0;
17952                 }
17953         }
17954         float co, so, sxs, sys;
17955         co = static_cast<float>( cos(ang*pi/180.0) );
17956         so = static_cast<float>( -sin(ang*pi/180.0) );
17957         sxs = sx*co - sy*so;
17958         sys = sx*so + sy*co;
17959         vector<float> res;
17960         res.push_back(ang);
17961         res.push_back(sxs);
17962         res.push_back(sys);
17963         res.push_back(static_cast<float>(mirror));
17964         res.push_back(static_cast<float>(nref));
17965         res.push_back(peak);
17966         return res;
17967 }

vector< float > Util::multiref_polar_ali_2d_delta EMData image,
const vector< EMData * > &  crefim,
float  xrng,
float  yrng,
float  step,
string  mode,
vector< int >  numr,
float  cnx,
float  cny,
float  delta_start,
float  delta
[static]
 

formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation

Definition at line 18087 of file util_sparx.cpp.

References ang_n(), Crosrng_ms_delta(), Frngs(), Normalize_ring(), numr, pi, Polar2Dm(), and EMAN::Dict::size().

18089                                                                                        {
18090 
18091     // Manually extract.
18092 /*    vector< EMAN::EMData* > crefim;
18093     std::size_t crefim_len = PyObject_Length(crefim_list.ptr());
18094     crefim.reserve(crefim_len);
18095 
18096     for(std::size_t i=0;i<crefim_len;i++) {
18097         boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]);
18098         crefim.push_back(proxy());
18099     }
18100 */
18101 
18102         size_t crefim_len = crefim.size();
18103 
18104         int   ky = int(2*yrng/step+0.5)/2;
18105         int   kx = int(2*xrng/step+0.5)/2;
18106         int   iref, nref=0, mirror=0;
18107         float iy, ix, sx=0, sy=0;
18108         float peak = -1.0E23f;
18109         float ang=0.0f;
18110         for (int i = -ky; i <= ky; i++) {
18111                 iy = i * step ;
18112                 for (int j = -kx; j <= kx; j++) {
18113                         ix = j*step ;
18114                         EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18115 
18116                         Normalize_ring( cimage, numr );
18117 
18118                         Frngs(cimage, numr);
18119                         //  compare with all reference images
18120                         // for iref in xrange(len(crefim)):
18121                         for ( iref = 0; iref < (int)crefim_len; iref++) {
18122                                 Dict retvals = Crosrng_ms_delta(crefim[iref], cimage, numr, delta_start, delta);
18123                                 double qn = retvals["qn"];
18124                                 double qm = retvals["qm"];
18125                                 if(qn >= peak || qm >= peak) {
18126                                         sx = -ix;
18127                                         sy = -iy;
18128                                         nref = iref;
18129                                         if (qn >= qm) {
18130                                                 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18131                                                 peak = static_cast<float>(qn);
18132                                                 mirror = 0;
18133                                         } else {
18134                                                 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
18135                                                 peak = static_cast<float>(qm);
18136                                                 mirror = 1;
18137                                         }
18138                                 }
18139                         }  delete cimage; cimage = 0;
18140                 }
18141         }
18142         float co, so, sxs, sys;
18143         co = static_cast<float>( cos(ang*pi/180.0) );
18144         so = static_cast<float>( -sin(ang*pi/180.0) );
18145         sxs = sx*co - sy*so;
18146         sys = sx*so + sy*co;
18147         vector<float> res;
18148         res.push_back(ang);
18149         res.push_back(sxs);
18150         res.push_back(sys);
18151         res.push_back(static_cast<float>(mirror));
18152         res.push_back(static_cast<float>(nref));
18153         res.push_back(peak);
18154         return res;
18155 }

vector< float > Util::multiref_polar_ali_2d_local EMData image,
const vector< EMData * > &  crefim,
float  xrng,
float  yrng,
float  step,
float  ant,
string  mode,
vector< int >  numr,
float  cnx,
float  cny
[static]
 

formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation

Definition at line 18214 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.

18216                                                        {
18217 
18218     // Manually extract.
18219 /*    vector< EMAN::EMData* > crefim;
18220     std::size_t crefim_len = PyObject_Length(crefim_list.ptr());
18221     crefim.reserve(crefim_len);
18222 
18223     for(std::size_t i=0;i<crefim_len;i++) {
18224         boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]);
18225         crefim.push_back(proxy());
18226     }
18227 */
18228         size_t crefim_len = crefim.size();
18229         const float qv = static_cast<float>( pi/180.0 );
18230 
18231         Transform * t = image->get_attr("xform.projection");
18232         Dict d = t->get_params("spider");
18233         if(t) {delete t; t=0;}
18234         float phi = d["phi"];
18235         float theta = d["theta"];
18236         int   ky = int(2*yrng/step+0.5)/2;
18237         int   kx = int(2*xrng/step+0.5)/2;
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         float imn1 = sin(theta*qv)*cos(phi*qv);
18243         float imn2 = sin(theta*qv)*sin(phi*qv);
18244         float imn3 = cos(theta*qv);
18245         vector<float> n1(crefim_len);
18246         vector<float> n2(crefim_len);
18247         vector<float> n3(crefim_len);
18248         for ( iref = 0; iref < (int)crefim_len; iref++) {
18249                         n1[iref] = crefim[iref]->get_attr("n1");
18250                         n2[iref] = crefim[iref]->get_attr("n2");
18251                         n3[iref] = crefim[iref]->get_attr("n3");
18252         }
18253         for (int i = -ky; i <= ky; i++) {
18254             iy = i * step ;
18255             for (int j = -kx; j <= kx; j++) {
18256                 ix = j*step;
18257                 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18258 
18259                 Normalize_ring( cimage, numr );
18260 
18261                 Frngs(cimage, numr);
18262                 //  compare with all reference images
18263                 // for iref in xrange(len(crefim)):
18264                 for ( iref = 0; iref < (int)crefim_len; iref++) {
18265                         if(abs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) {
18266                                 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr);
18267                                 double qn = retvals["qn"];
18268                                 double qm = retvals["qm"];
18269                                 if(qn >= peak || qm >= peak) {
18270                                         sx = -ix;
18271                                         sy = -iy;
18272                                         nref = iref;
18273                                         if (qn >= qm) {
18274                                                 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18275                                                 peak = static_cast<float>( qn );
18276                                                 mirror = 0;
18277                                         } else {
18278                                                 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
18279                                                 peak = static_cast<float>( qm );
18280                                                 mirror = 1;
18281                                         }
18282                                 }
18283                         }
18284                 }  delete cimage; cimage = 0;
18285             }
18286         }
18287         float co, so, sxs, sys;
18288         if(peak == -1.0E23) {
18289                 ang=0.0; sxs=0.0; sys=0.0; mirror=0;
18290                 nref = -1;
18291         } else {
18292                 co =  cos(ang*qv);
18293                 so = -sin(ang*qv);
18294                 sxs = sx*co - sy*so;
18295                 sys = sx*so + sy*co;
18296         }
18297         vector<float> res;
18298         res.push_back(ang);
18299         res.push_back(sxs);
18300         res.push_back(sys);
18301         res.push_back(static_cast<float>(mirror));
18302         res.push_back(static_cast<float>(nref));
18303         res.push_back(peak);
18304         return res;
18305 }

vector< float > Util::multiref_polar_ali_2d_local_psi EMData image,
const vector< EMData * > &  crefim,
float  xrng,
float  yrng,
float  step,
float  ant,
float  psi_max,
string  mode,
vector< int >  numr,
float  cnx,
float  cny
[static]
 

formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation

Definition at line 18307 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.

18309                                                        {
18310 
18311     // Manually extract.
18312 /*    vector< EMAN::EMData* > crefim;
18313     std::size_t crefim_len = PyObject_Length(crefim_list.ptr());
18314     crefim.reserve(crefim_len);
18315 
18316     for(std::size_t i=0;i<crefim_len;i++) {
18317         boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]);
18318         crefim.push_back(proxy());
18319     }
18320 */
18321         size_t crefim_len = crefim.size();
18322         const float qv = static_cast<float>(pi/180.0);
18323 
18324         Transform* t = image->get_attr("xform.projection");
18325         Dict d = t->get_params("spider");
18326         if(t) {delete t; t=0;}
18327         float phi = d["phi"];
18328         float theta = d["theta"];
18329         float psi = d["psi"];
18330         int ky = int(2*yrng/step+0.5)/2;
18331         int kx = int(2*xrng/step+0.5)/2;
18332         int iref, nref = 0, mirror = 0;
18333         float iy, ix, sx = 0, sy = 0;
18334         float peak = -1.0E23f;
18335         float ang = 0.0f;
18336         float imn1 = sin(theta*qv)*cos(phi*qv);
18337         float imn2 = sin(theta*qv)*sin(phi*qv);
18338         float imn3 = cos(theta*qv);
18339         vector<float> n1(crefim_len);
18340         vector<float> n2(crefim_len);
18341         vector<float> n3(crefim_len);
18342         for (iref = 0; iref < (int)crefim_len; iref++) {
18343                         n1[iref] = crefim[iref]->get_attr("n1");
18344                         n2[iref] = crefim[iref]->get_attr("n2");
18345                         n3[iref] = crefim[iref]->get_attr("n3");
18346         }
18347         bool nomirror = (theta<90.0) || ((theta==90.0) && (psi<psi_max));
18348         if (!nomirror) {
18349                 phi = fmod(phi+540.0f, 360.0f);
18350                 theta = 180-theta;
18351                 psi = fmod(540.0f-psi, 360.0f);
18352         }
18353         for (int i = -ky; i <= ky; i++) {
18354             iy = i * step ;
18355             for (int j = -kx; j <= kx; j++) {
18356                 ix = j*step;
18357                 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18358 
18359                 Normalize_ring(cimage, numr);
18360 
18361                 Frngs(cimage, numr);
18362                 //  compare with all reference images
18363                 // for iref in xrange(len(crefim)):
18364                 for (iref = 0; iref < (int)crefim_len; iref++) {
18365                         if (abs(n1[iref]*imn1 + n2[iref]*imn2 + n3[iref]*imn3)>=ant) {
18366                                 if (nomirror) {
18367                                         Dict retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, psi, 0);
18368                                         double qn = retvals["qn"];
18369                                         if (qn >= peak) {
18370                                                 sx = -ix;
18371                                                 sy = -iy;
18372                                                 nref = iref;
18373                                                 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18374                                                 peak = static_cast<float>(qn);
18375                                                 mirror = 0;
18376                                         }
18377                                 } else {
18378                                         Dict retvals = Crosrng_sm_psi(crefim[iref], cimage, numr, psi, 1);
18379                                         double qn = retvals["qn"];
18380                                         if (qn >= peak) {
18381                                                 sx = -ix;
18382                                                 sy = -iy;
18383                                                 nref = iref;
18384                                                 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18385                                                 peak = static_cast<float>(qn);
18386                                                 mirror = 1;
18387                                         }
18388                                 }
18389                         }
18390                 }  delete cimage; cimage = 0;
18391             }
18392         }
18393         float co, so, sxs, sys;
18394         if(peak == -1.0E23) {
18395                 ang=0.0; sxs=0.0; sys=0.0; mirror=0;
18396                 nref = -1;
18397         } else {
18398                 co =  cos(ang*qv);
18399                 so = -sin(ang*qv);
18400                 sxs = sx*co - sy*so;
18401                 sys = sx*so + sy*co;
18402         }
18403         vector<float> res;
18404         res.push_back(ang);
18405         res.push_back(sxs);
18406         res.push_back(sys);
18407         res.push_back(static_cast<float>(mirror));
18408         res.push_back(static_cast<float>(nref));
18409         res.push_back(peak);
18410         return res;
18411 }

vector< float > Util::multiref_polar_ali_2d_nom EMData image,
const vector< EMData * > &  crefim,
float  xrng,
float  yrng,
float  step,
string  mode,
vector< int >  numr,
float  cnx,
float  cny
[static]
 

formerly known as apnq DO NOT CONSIDER MIRROR Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation

Definition at line 18157 of file util_sparx.cpp.

References ang_n(), Crosrng_ns(), Frngs(), numr, pi, Polar2Dm(), and EMAN::Dict::size().

18159                                                          {
18160 
18161     // Manually extract.
18162 /*    vector< EMAN::EMData* > crefim;
18163     std::size_t crefim_len = PyObject_Length(crefim_list.ptr());
18164     crefim.reserve(crefim_len);
18165 
18166     for(std::size_t i=0;i<crefim_len;i++) {
18167         boost::python::extract<EMAN::EMData*> proxy(crefim_list[i]);
18168         crefim.push_back(proxy());
18169     }
18170 */
18171         size_t crefim_len = crefim.size();
18172 
18173         int   ky = int(2*yrng/step+0.5)/2;
18174         int   kx = int(2*xrng/step+0.5)/2;
18175         int   iref, nref=0;
18176         float iy, ix, sx=0, sy=0;
18177         float peak = -1.0E23f;
18178         float ang=0.0f;
18179         for (int i = -ky; i <= ky; i++) {
18180                 iy = i * step ;
18181                 for (int j = -kx; j <= kx; j++) {
18182                         ix = j*step ;
18183                         EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18184                         Frngs(cimage, numr);
18185                         //  compare with all reference images
18186                         // for iref in xrange(len(crefim)):
18187                         for ( iref = 0; iref < (int)crefim_len; iref++) {
18188                                 Dict retvals = Crosrng_ns(crefim[iref], cimage, numr);
18189                                 double qn = retvals["qn"];
18190                                 if(qn >= peak) {
18191                                         sx = -ix;
18192                                         sy = -iy;
18193                                         nref = iref;
18194                                         ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18195                                         peak = static_cast<float>(qn);
18196                                 }
18197                         }  delete cimage; cimage = 0;
18198                 }
18199         }
18200         float co, so, sxs, sys;
18201         co = static_cast<float>( cos(ang*pi/180.0) );
18202         so = static_cast<float>( -sin(ang*pi/180.0) );
18203         sxs = sx*co - sy*so;
18204         sys = sx*so + sy*co;
18205         vector<float> res;
18206         res.push_back(ang);
18207         res.push_back(sxs);
18208         res.push_back(sys);
18209         res.push_back(static_cast<float>(nref));
18210         res.push_back(peak);
18211         return res;
18212 }

vector< float > Util::multiref_polar_ali_2d_peaklist EMData image,
const vector< EMData * > &  crefim,
float  xrng,
float  yrng,
float  step,
string  mode,
vector< int >  numr,
float  cnx,
float  cny
[static]
 

Definition at line 17969 of file util_sparx.cpp.

References ang_n(), Crosrng_ms(), Frngs(), Normalize_ring(), numr, pi, Polar2Dm(), and EMAN::Dict::size().

17971                                                        {
17972 
17973         size_t crefim_len = crefim.size();
17974 
17975         int   ky = int(2*yrng/step+0.5)/2;
17976         int   kx = int(2*xrng/step+0.5)/2;
17977         float iy, ix;
17978         vector<float> peak(crefim_len*5, -1.0e23f);
17979         for (int i = -ky; i <= ky; i++) {
17980                 iy = i * step ;
17981                 for (int j = -kx; j <= kx; j++) {
17982                         ix = j*step ;
17983                         EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
17984                         Normalize_ring( cimage, numr );
17985                         Frngs(cimage, numr);
17986                         for (int iref = 0; iref < (int)crefim_len; iref++) {
17987                                 Dict retvals = Crosrng_ms(crefim[iref], cimage, numr);
17988                                 double qn = retvals["qn"];
17989                                 double qm = retvals["qm"];
17990                                 if(qn >= peak[iref*5] || qm >= peak[iref*5]) {
17991                                         if (qn >= qm) {
17992                                                 peak[iref*5] = static_cast<float>(qn);
17993                                                 peak[iref*5+1] = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
17994                                                 peak[iref*5+2] = -ix;
17995                                                 peak[iref*5+3] = -iy;
17996                                                 peak[iref*5+4] = 0;
17997                                         } else {
17998                                                 peak[iref*5] = static_cast<float>(qm);
17999                                                 peak[iref*5+1] = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
18000                                                 peak[iref*5+2] = -ix;
18001                                                 peak[iref*5+3] = -iy;
18002                                                 peak[iref*5+4] = 1;
18003                                         }
18004                                 }
18005                         }  delete cimage; cimage = 0;
18006                 }
18007         }
18008         for (int iref = 0; iref < (int)crefim_len; iref++) {
18009                 float ang = peak[iref*5+1];
18010                 float sx = peak[iref*5+2];
18011                 float sy = peak[iref*5+3];
18012                 float co =  cos(ang*pi/180.0);
18013                 float so = -sin(ang*pi/180.0);
18014                 float sxs = sx*co - sy*so;
18015                 float sys = sx*so + sy*co;
18016                 peak[iref*5+2] = sxs;
18017                 peak[iref*5+3] = sys;
18018         }
18019         return peak;
18020 }

vector< float > Util::multiref_polar_ali_helical EMData image,
const vector< EMData * > &  crefim,
float  xrng,
float  yrng,
float  step,
float  psi_max,
string  mode,
vector< int >  numr,
float  cnx,
float  cny,
int  ynumber = -1
[static]
 

formerly known as apmq Determine shift and rotation between image and many reference images (crefim, weights have to be applied) quadratic interpolation Search for peaks only within +/-psi_max from 0 and 180 (helical)

Definition at line 18414 of file util_sparx.cpp.

References ang_n(), Crosrng_psi_0_180(), Frngs(), Normalize_ring(), numr, pi, Polar2Dm(), and EMAN::Dict::size().

18416                                                                     {
18417 
18418         size_t crefim_len = crefim.size();
18419 
18420         int   iref, nref=0, mirror=0;
18421         float iy, ix, sx=0, sy=0;
18422         float peak = -1.0E23f;
18423         float ang=0.0f;
18424         int   kx = int(2*xrng/step+0.5)/2;
18425         //if ynumber==-1, use the old code which process x and y direction equally.
18426         if(ynumber==-1) {
18427                 int   ky = int(2*yrng/step+0.5)/2;
18428                 for (int i = -ky; i <= ky; i++) {
18429                         iy = i * step ;
18430                         for (int j = -kx; j <= kx; j++)  {
18431                                 ix = j*step ;
18432                                 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18433 
18434                                 Normalize_ring( cimage, numr );
18435 
18436                                 Frngs(cimage, numr);
18437                                 //  compare with all reference images
18438                                 // for iref in xrange(len(crefim)):
18439                                 for ( iref = 0; iref < (int)crefim_len; iref++) {
18440                                         Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max);
18441                                         double qn = retvals["qn"];
18442                                         double qm = retvals["qm"];
18443                                         if(qn >= peak || qm >= peak) {
18444                                                 sx = -ix;
18445                                                 sy = -iy;
18446                                                 nref = iref;
18447                                                 if (qn >= qm) {
18448                                                         ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18449                                                         peak = static_cast<float>(qn);
18450                                                         mirror = 0;
18451                                                 } else {
18452                                                         ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
18453                                                         peak = static_cast<float>(qm);
18454                                                         mirror = 1;
18455                                                 }
18456                                         }
18457                                 }  
18458                                 delete cimage; cimage = 0;
18459                         }
18460                    }
18461         }
18462         //if ynumber is given, it should be even. We need to check whether it is zero
18463         else if(ynumber==0) {
18464                 sy = 0.0f;
18465                 for (int j = -kx; j <= kx; j++) {
18466                         ix = j*step ;
18467                         EMData* cimage = Polar2Dm(image, cnx+ix, cny, numr, mode);
18468 
18469                         Normalize_ring( cimage, numr );
18470 
18471                         Frngs(cimage, numr);
18472                         //  compare with all reference images
18473                         // for iref in xrange(len(crefim)):
18474                         for ( iref = 0; iref < (int)crefim_len; iref++)  {
18475                                 Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max);
18476                                 double qn = retvals["qn"];
18477                                 double qm = retvals["qm"];
18478                                 if(qn >= peak || qm >= peak) {
18479                                         sx = -ix;
18480                                         nref = iref;
18481                                         if (qn >= qm) {
18482                                                 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18483                                                 peak = static_cast<float>(qn);
18484                                                 mirror = 0;
18485                                         } else {
18486                                                 ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
18487                                                 peak = static_cast<float>(qm);
18488                                                 mirror = 1;
18489                                         }
18490                                 }
18491                         } 
18492                         delete cimage; cimage = 0;
18493                 }                       
18494         } else {
18495                 int   ky = int(ynumber/2);              
18496                 float stepy=2*yrng/ynumber;
18497                 //std::cout<<"yrng="<<yrng<<"ynumber="<<ynumber<<"stepy=="<<stepy<<"stepx=="<<step<<std::endl;
18498                 for (int i = -ky+1; i <= ky; i++) {
18499                         iy = i * stepy ;
18500                         for (int j = -kx; j <= kx; j++) {
18501                                 ix = j*step ;
18502                                 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18503 
18504                                 Normalize_ring( cimage, numr );
18505 
18506                                 Frngs(cimage, numr);
18507                                 //  compare with all reference images
18508                                 // for iref in xrange(len(crefim)):
18509                                 for ( iref = 0; iref < (int)crefim_len; iref++) {
18510                                         Dict retvals = Crosrng_psi_0_180(crefim[iref], cimage, numr, psi_max);
18511                                         double qn = retvals["qn"];
18512                                         double qm = retvals["qm"];
18513                                         if(qn >= peak || qm >= peak) {
18514                                                 sx = -ix;
18515                                                 sy = -iy;
18516                                                 nref = iref;
18517                                                 if (qn >= qm) {
18518                                                         ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18519                                                         peak = static_cast<float>(qn);
18520                                                         mirror = 0;
18521                                                 } else {
18522                                                         ang = ang_n(retvals["tmt"], mode, numr[numr.size()-1]);
18523                                                         peak = static_cast<float>(qm);
18524                                                         mirror = 1;
18525                                                 }
18526                                         }
18527                                 }
18528                                 delete cimage; cimage = 0;
18529                         }
18530                 }
18531         }
18532         float co, so, sxs, sys;
18533         co = static_cast<float>( cos(ang*pi/180.0) );
18534         so = static_cast<float>( -sin(ang*pi/180.0) );
18535         sxs = sx*co - sy*so;
18536         sys = sx*so + sy*co;
18537         vector<float> res;
18538         res.push_back(ang);
18539         res.push_back(sxs);
18540         res.push_back(sys);
18541         res.push_back(static_cast<float>(mirror));
18542         res.push_back(static_cast<float>(nref));
18543         res.push_back(peak);
18544         return res;
18545 }

vector< float > Util::multiref_polar_ali_helical_90 EMData image,
const vector< EMData * > &  crefim,
float  xrng,
float  yrng,
float  step,
float  psi_max,
string  mode,
vector< int >  numr,
float  cnx,
float  cny,
int  ynumber = -1
[static]
 

Definition at line 18547 of file util_sparx.cpp.

References ang_n(), Crosrng_psi_0_180_no_mirror(), Frngs(), Normalize_ring(), numr, pi, Polar2Dm(), and EMAN::Dict::size().

18549                                                                     {
18550 
18551         size_t crefim_len = crefim.size();
18552 
18553         int   iref, nref=0, mirror=0;
18554         float iy, ix, sx=0, sy=0;
18555         float peak = -1.0E23f;
18556         float ang=0.0f;
18557         int   kx = int(2*xrng/step+0.5)/2;
18558         //if ynumber==-1, use the old code which process x and y direction equally.
18559         if(ynumber==-1) {
18560                 int   ky = int(2*yrng/step+0.5)/2;
18561                 for (int i = -ky; i <= ky; i++) {
18562                         iy = i * step ;
18563                         for (int j = -kx; j <= kx; j++)  {
18564                                 ix = j*step ;
18565                                 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18566 
18567                                 Normalize_ring( cimage, numr );
18568 
18569                                 Frngs(cimage, numr);
18570                                 //  compare with all reference images
18571                                 // for iref in xrange(len(crefim)):
18572                                 for ( iref = 0; iref < (int)crefim_len; iref++) {
18573                                         Dict retvals = Crosrng_psi_0_180_no_mirror(crefim[iref], cimage, numr, psi_max);
18574                                         double qn = retvals["qn"];
18575                                         if( qn >= peak) {
18576                                                 sx = -ix;
18577                                                 sy = -iy;
18578                                                 nref = iref;
18579                                                 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18580                                                 peak = static_cast<float>(qn);
18581                                                 mirror = 0;
18582                                         }
18583                                 }  
18584                                 delete cimage; cimage = 0;
18585                         }
18586                    }
18587         }
18588         //if ynumber is given, it should be even. We need to check whether it is zero
18589         else if(ynumber==0) {
18590                 sy = 0.0f;
18591                 for (int j = -kx; j <= kx; j++) {
18592                         ix = j*step ;
18593                         iy = 0.0f ;
18594                         EMData* cimage = Polar2Dm(image, cnx+ix, cny, numr, mode);
18595 
18596                         Normalize_ring( cimage, numr );
18597 
18598                         Frngs(cimage, numr);
18599                         //  compare with all reference images
18600                         // for iref in xrange(len(crefim)):
18601                         for ( iref = 0; iref < (int)crefim_len; iref++)  {
18602                                 Dict retvals = Crosrng_psi_0_180_no_mirror(crefim[iref], cimage, numr, psi_max);
18603                                 double qn = retvals["qn"];
18604                                 if( qn >= peak ) {
18605                                         sx = -ix;
18606                                         nref = iref;
18607                                         ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18608                                         peak = static_cast<float>(qn);
18609                                         mirror = 0;
18610                                 }
18611                         } 
18612                         delete cimage; cimage = 0;
18613                 }                       
18614         } else {
18615                 int   ky = int(ynumber/2);              
18616                 float stepy=2*yrng/ynumber;
18617                 //std::cout<<"yrng="<<yrng<<"ynumber="<<ynumber<<"stepy=="<<stepy<<"stepx=="<<step<<std::endl;
18618                 for (int i = -ky+1; i <= ky; i++) {
18619                         iy = i * stepy ;
18620                         for (int j = -kx; j <= kx; j++) {
18621                                 ix = j*step ;
18622                                 EMData* cimage = Polar2Dm(image, cnx+ix, cny+iy, numr, mode);
18623 
18624                                 Normalize_ring( cimage, numr );
18625 
18626                                 Frngs(cimage, numr);
18627                                 //  compare with all reference images
18628                                 // for iref in xrange(len(crefim)):
18629                                 for ( iref = 0; iref < (int)crefim_len; iref++) {
18630                                         Dict retvals = Crosrng_psi_0_180_no_mirror(crefim[iref], cimage, numr, psi_max);
18631                                         double qn = retvals["qn"];
18632                                         if( qn >= peak) {
18633                                                 sx = -ix;
18634                                                 sy = -iy;
18635                                                 nref = iref;
18636                                                 ang = ang_n(retvals["tot"], mode, numr[numr.size()-1]);
18637                                                 peak = static_cast<float>(qn);
18638                                                 mirror = 0;
18639                                         }
18640                                 }
18641                                 delete cimage; cimage = 0;
18642                         }
18643                 }
18644         }
18645         float co, so, sxs, sys;
18646         co = static_cast<float>( cos(ang*pi/180.0) );
18647         so = static_cast<float>( -sin(ang*pi/180.0) );
18648         sxs = sx*co - sy*so;
18649         sys = sx*so + sy*co;
18650         vector<float> res;
18651         res.push_back(ang);
18652         res.push_back(sxs);
18653         res.push_back(sys);
18654         res.push_back(static_cast<float>(mirror));
18655         res.push_back(static_cast<float>(nref));
18656         res.push_back(peak);
18657         return res;
18658 }

int EMAN::Util::nint180 float  arg  )  [inline, static]
 

Definition at line 1036 of file util.h.

Referenced by cml_line_insino(), and cml_line_insino_all().

void Util::Normalize_ring EMData ring,
const vector< int > &  numr
[static]
 

Definition at line 17866 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(), multiref_polar_ali_helical(), and multiref_polar_ali_helical_90().

17867 {
17868     float* data = ring->get_data();
17869     float av=0.0;
17870     float sq=0.0;
17871     float nn=0.0;
17872     int nring = numr.size()/3;
17873     for( int i=0; i < nring; ++i )
17874     {
17875         int numr3i = numr[3*i+2];
17876         int numr2i = numr[3*i+1]-1;
17877         float w = numr[3*i]*2*M_PI/float(numr[3*i+2]);
17878         for( int j=0; j < numr3i; ++j )
17879         {
17880             int jc = numr2i+j;
17881             av += data[jc] * w;
17882             sq += data[jc] * data[jc] * w;
17883             nn += w;
17884         }
17885     }
17886 
17887     float avg = av/nn;
17888     float sgm = sqrt( (sq-av*av/nn)/nn );
17889     size_t n = (size_t)ring->get_xsize() * ring->get_ysize() * ring->get_zsize();
17890     for( size_t i=0; i < n; ++i )
17891     {
17892         data[i] -= avg;
17893         data[i] /= sgm;
17894     }
17895 
17896     ring->update();
17897 }

EMData * Util::pack_complex_to_real EMData img  )  [static]
 

Definition at line 17776 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().

17777 {
17778         ENTERFUNC;
17779         /* Exception Handle */
17780         if (!img) {
17781                 throw NullPointerException("NULL input image");
17782         }
17783         /* ==============   img is modulus of a complex image in FFT format (so its imaginary parts are zero),
17784                               output is img packed into real image with Friedel part added,   ================ */
17785 
17786         int nxo=img->get_xsize(), ny=img->get_ysize(), nz=img->get_zsize();
17787         int nx = nxo - 2 + img->is_fftodd();
17788         int lsd2 = (nx + 2 - nx%2) / 2; // Extended x-dimension of the complex image
17789         int nyt, nzt;
17790         int nx2 = nx/2;
17791         int ny2 = ny/2; if(ny2 == 0) nyt =0; else nyt=ny;
17792         int nz2 = nz/2; if(nz2 == 0) nzt =0; else nzt=nz;
17793         int nx2p = nx2+nx%2;
17794         int ny2p = ny2+ny%2;
17795         int nz2p = nz2+nz%2;
17796         EMData& power = *(new EMData()); // output image
17797         power.set_size(nx, ny, nz);
17798         power.set_array_offsets(-nx2,-ny2,-nz2);
17799         //img->set_array_offsets(1,1,1);
17800         float *img_ptr  = img->get_data();
17801         for (int iz = 1; iz <= nz; iz++) {
17802                 int jz=iz-1;
17803                 if(jz>=nz2p) jz=jz-nzt;
17804                 for (int iy = 1; iy <= ny; iy++) {
17805                         int jy=iy-1;
17806                         if(jy>=ny2p) jy=jy-nyt;
17807                         for (int ix = 1; ix <= lsd2; ix++) {
17808                                 int jx=ix-1;
17809                                 if(jx>=nx2p) jx=jx-nx;
17810                                 power(jx,jy,jz) = img_ptr(ix,iy,iz); //real(img->cmplx(ix,iy,iz));
17811                         }
17812                 }
17813         }
17814 //  Create the Friedel related half
17815         int  nzb, nze, nyb, nye, nxb, nxe;
17816         nxb =-nx2+(nx+1)%2;
17817         nxe = nx2-(nx+1)%2;
17818         if(ny2 == 0) {nyb =0; nye = 0;} else {nyb =-ny2+(ny+1)%2; nye = ny2-(ny+1)%2;}
17819         if(nz2 == 0) {nzb =0; nze = 0;} else {nzb =-nz2+(nz+1)%2; nze = nz2-(nz+1)%2;}
17820         for (int iz = nzb; iz <= nze; iz++) {
17821                 for (int iy = nyb; iy <= nye; iy++) {
17822                         for (int ix = 1; ix <= nxe; ix++) { // Note this loop begins with 1 - FFT should create correct Friedel related 0 plane
17823                                 power(-ix,-iy,-iz) = power(ix,iy,iz);
17824                         }
17825                 }
17826         }
17827         if(ny2 != 0)  {
17828                 if(nz2 != 0)  {
17829                         if(nz%2 == 0) {  //if nz even, fix the first slice
17830                                 for (int iy = nyb; iy <= nye; iy++) {
17831                                         for (int ix = nxb; ix <= -1; ix++) {
17832                                                 power(ix,iy,-nz2) = power(-ix,-iy,-nz2);
17833                                         }
17834                                 }
17835                                 if(ny%2 == 0) {  //if ny even, fix the first line
17836                                         for (int ix = nxb; ix <= -1; ix++) {
17837                                                 power(ix,-ny2,-nz2) = power(-ix,-ny2,-nz2);
17838                                         }
17839                                 }
17840                         }
17841                 }
17842                 if(ny%2 == 0) {  //if ny even, fix the first column
17843                         for (int iz = nzb; iz <= nze; iz++) {
17844                                 for (int ix = nxb; ix <= -1; ix++) {
17845                                         power(ix,-ny2,-iz) = power(-ix,-ny2,iz);
17846                                 }
17847                         }
17848                 }
17849 
17850         }
17851         power.update();
17852         power.set_array_offsets(0,0,0);
17853         return &power;
17854 }

EMData * Util::pad EMData img,
int  new_nx,
int  new_ny = 1,
int  new_nz = 1,
int  x_offset = 0,
int  y_offset = 0,
int  z_offset = 0,
char *  params = "average"
[static]
 

Definition at line 5382 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().

05383 {
05384         /* Exception Handle */
05385         if (!img)  throw NullPointerException("NULL input image");
05386         /* ============================== */
05387 
05388         // Get the size of the input image
05389         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
05390         /* ============================== */
05391 
05392         /* Exception Handle */
05393         if(new_nx<nx || new_ny<ny || new_nz<nz)
05394                 throw ImageDimensionException("The size of the padded image cannot be lower than the input image size.");
05395         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)
05396                 throw ImageDimensionException("The offset imconsistent with the input image size. Solution: Change the offset parameters");
05397         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))))
05398                 throw ImageDimensionException("The offset imconsistent with the input image size. Solution: Change the offset parameters");
05399         /* ============================== */
05400 
05401         EMData* pading = img->copy_head();
05402         pading->set_size(new_nx, new_ny, new_nz);
05403         float *inp  = img->get_data();
05404         float *outp = pading->get_data();
05405 
05406 
05407         /* Calculation of the average and the circumference values for background substitution
05408         =======================================================================================*/
05409         float background;
05410 
05411         if (strcmp(params,"average")==0) background = img->get_attr("mean");
05412         else if (strcmp(params,"circumference")==0) {
05413                 float sum1=0.0f;
05414                 size_t cnt=0;
05415                 for(int i=0;i<nx;i++) {
05416                         sum1 += inp(i,0,0) + inp(i,ny-1,nz-1);
05417                         cnt+=2;
05418                 }
05419                 if(nz-1 == 0) {
05420                         for (int j=1;j<ny-1;j++) {
05421                                 sum1 += inp(1,j,0) + inp(nx-1,j,0);
05422                                 cnt+=2;
05423                         }
05424                 } else {
05425                         for (int k=1;k<nz-1;k++) {
05426                                 for (int j=1;j<ny-1;j++) {
05427                                         sum1 += inp(1,j,0) + inp(nx-1,j,0);
05428                                         cnt+=2;
05429                                 }
05430                         }
05431                 }
05432                 background = sum1/cnt;
05433         } else {
05434                 background = static_cast<float>( atof( params ) );
05435         }
05436         /*=====================================================================================*/
05437 
05438          /*Initial Padding */
05439         int new_st_x=0,new_st_y=0,new_st_z=0;
05440         for (int k=0;k<new_nz;k++)
05441                 for(int j=0;j<new_ny;j++)
05442                         for (int i=0;i<new_nx;i++)
05443                                 outp(i,j,k)=background;
05444         /*============================== */
05445 
05446         /*    Calculation of the start point */
05447         new_st_x=int((new_nx/2-nx/2)  + x_offset);
05448         new_st_y=int((new_ny/2-ny/2)  + y_offset);
05449         new_st_z=int((new_nz/2-nz/2)  + z_offset);
05450         /* ============================== */
05451 
05452         for (int k=0;k<nz;k++)
05453                 for(int j=0;j<ny;j++)
05454                         for(int i=0;i<nx;i++)
05455                                 outp(i,j,k)=inp(i,j,k);
05456         pading->update();
05457         return pading;
05458 }

bool Util::point_is_in_convex_polygon_2d const Vec2f p1,
const Vec2f p2,
const Vec2f p3,
const Vec2f p4,
const Vec2f actual_point
[static]
 

Determines if a point is in a 2D convex polygon described by 4 points using the Barycentric method, which is a fast way of performing the query.

The points must be ordered in the way you would encounter them if you traversed the boundary of the polygon. Direction is irrelevant. Could be generalized for polygons with more points

Parameters:
p1 point one
p2 point two
p3 point three
p4 point three
actual_point the point which might be in the polygon described by p1,p2,p3 and p4
Returns:
true if the point is in the polygon, false otherwise
Author:
David Woolford
Date:
October 2008

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 }

bool Util::point_is_in_triangle_2d const Vec2f p1,
const Vec2f p2,
const Vec2f p3,
const Vec2f actual_point
[static]
 

Determines if a point is in a 2D triangle using the Barycentric method, which is a fast way of performing the query Triangle points can be specified in any order.

Parameters:
p1 point one
p2 point two
p3 point three
actual_point the point which might be in the triangle described by p1,p2 and p3
Returns:
true if the point is in the triangle, false otherwise
Author:
David Woolford
Date:
October 2008

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 }

EMData * Util::Polar2D EMData image,
vector< int >  numr,
string  mode
[static]
 

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 }

EMData * Util::Polar2Dm EMData image,
float  cns2,
float  cnr2,
vector< int >  numr,
string  cmode
[static]
 

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(), multiref_polar_ali_helical(), and multiref_polar_ali_helical_90().

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 }

EMData * Util::Polar2Dmi EMData image,
float  cns2,
float  cnr2,
vector< int >  numr,
string  cmode,
Util::KaiserBessel kb
[static]
 

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 }

void Util::prb1d double *  b,
int  npoint,
float *  pos
[static]
 

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(), Crosrng_psi_0_180_no_mirror(), 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 }

void Util::printMatI3D MIArray3D mat,
const string  str = string(""),
ostream &  out = std::cout
[static]
 

Print a 3D integer matrix to a file stream (std out by default).

Parameters:
[in] mat integer 3-d multi_array reference
[in] str Message string to be printed.
[out] out stream; cout by default.

Definition at line 1118 of file util.cpp.

References nx, and ny.

01118                                                                      {
01119         // Note: Don't need to check if 3-D because 3D is part of
01120         //       the MIArray3D typedef.
01121         out << "Printing 3D Integer data: " << str << std::endl;
01122         const multi_array_types::size_type* sizes = mat.shape();
01123         int nx = sizes[0], ny = sizes[1], nz = sizes[2];
01124         const multi_array_types::index* indices = mat.index_bases();
01125         int bx = indices[0], by = indices[1], bz = indices[2];
01126         for (int iz = bz; iz < nz+bz; iz++) {
01127                 cout << "(z = " << iz << " slice)" << endl;
01128                 for (int ix = bx; ix < nx+bx; ix++) {
01129                         for (int iy = by; iy < ny+by; iy++) {
01130                                 cout << setiosflags(ios::fixed) << setw(5)
01131                                          << mat[ix][iy][iz] << "  ";
01132                         }
01133                         cout << endl;
01134                 }
01135         }
01136 }

vector< float > Util::pw_extract vector< float >  pw,
int  n,
int  iswi,
float  ps
[static]
 

Definition at line 6359 of file util_sparx.cpp.

References call_cl1(), log(), q, EMAN::Dict::size(), and x.

06360 {
06361         int k,m,n1,klmd,klm2d,nklmd,n2d,n_larg,l, n2;
06362 
06363         k=(int)pw.size();
06364         l=0;
06365         m=k;
06366         n2=n+2;
06367         n1=n+1;
06368         klmd=k+l+m;
06369         klm2d= k+l+m+2;
06370         nklmd=k+l+m+n;
06371         n2d=n+2;
06372         /*size has to be increased when N is large*/
06373         n_larg=klmd*2;
06374         klm2d=n_larg+klm2d;
06375         klmd=n_larg+klmd;
06376         nklmd=n_larg+nklmd;
06377         int size_q=klm2d*n2d;
06378         int size_cu=nklmd*2;
06379         static int i__;
06380 
06381          double *q ;
06382          double *x ;
06383          double *res;
06384          double *cu;
06385          float *q2;
06386          float *pw_;
06387          long int *iu;
06388          double *s;
06389          q = (double*)calloc(size_q,sizeof(double));
06390          x = (double*)calloc(n2d,sizeof(double));
06391          res = (double*)calloc(klmd,sizeof(double));
06392          cu =(double*)calloc(size_cu,sizeof(double));
06393          s = (double*)calloc(klmd,sizeof(double));
06394          q2 = (float*)calloc(size_q,sizeof(float));
06395          iu = (long int*)calloc(size_cu,sizeof(long int));
06396          pw_ = (float*)calloc(k,sizeof(float));
06397 
06398         for( i__ =0;i__<k;++i__)
06399                 {
06400                 pw_[i__]=log(pw[i__]); }
06401         long int l_k=k;
06402         long int l_n=n;
06403         long int l_iswi=iswi;
06404         vector<float> cl1_res;
06405         cl1_res=Util::call_cl1(&l_k, &l_n, &ps, &l_iswi, pw_, q2, q, x, res, cu, s, iu);
06406         free(q);
06407         free(x);
06408         free(res);
06409         free(s);
06410         free(cu);
06411         free(q2);
06412         free(iu);
06413         free(pw_);
06414         return cl1_res;
06415 }

float Util::quadri float  x,
float  y,
int  nx,
int  ny,
float *  image
[static]
 

Quadratic interpolation (2D).

Note: This routine starts counting from 1, not 0!

This routine uses six image points for interpolation:

See also:
M. Abramowitz & I.E. Stegun, Handbook of Mathematical Functions (Dover, New York, 1964), Sec. 25.2.67. http://www.math.sfu.ca/~cbm/aands/page_882.htm

http://www.cl.cam.ac.uk/users/nad/pubs/quad.pdf

                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:

  • f0 = (x0, y0)
  • f1 = (xb, y0)
  • f2 = (xa, y0)
  • f3 = (x0, yb)
  • f4 = (x0, ya)
  • fc = (xc, yc)
Mesh spacings:
  • hxa -- x- mesh spacing to the left of f0
  • hxb -- x- mesh spacing to the right of f0
  • hyb -- y- mesh spacing above f0
  • hya -- y- mesh spacing below f0
Interpolant: f = f0 + c1*(x-x0) + c2*(x-x0)*(x-x1) + c3*(y-y0) + c4*(y-y0)*(y-y1) + c5*(x-x0)*(y-y0)

Parameters:
[in] x x-coord value
[in] y y-coord value
nx 
ny 
[in] image Image object (pointer)
Returns:
Interpolated value

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 }

float Util::quadri_background float  x,
float  y,
int  nx,
int  ny,
float *  image,
int  xnew,
int  ynew
[static]
 

Quadratic interpolation (2D).

This is identical to quadri except the wrap around is not done circulantly.

Note: This routine starts counting from 1, not 0!

This routine uses six image points for interpolation:

See also:
M. Abramowitz & I.E. Stegun, Handbook of Mathematical Functions (Dover, New York, 1964), Sec. 25.2.67. http://www.math.sfu.ca/~cbm/aands/page_882.htm

http://www.cl.cam.ac.uk/users/nad/pubs/quad.pdf

                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:

  • f0 = (x0, y0)
  • f1 = (xb, y0)
  • f2 = (xa, y0)
  • f3 = (x0, yb)
  • f4 = (x0, ya)
  • fc = (xc, yc)
Mesh spacings:
  • hxa -- x- mesh spacing to the left of f0
  • hxb -- x- mesh spacing to the right of f0
  • hyb -- y- mesh spacing above f0
  • hya -- y- mesh spacing below f0
Interpolant: f = f0 + c1*(x-x0) + c2*(x-x0)*(x-x1) + c3*(y-y0) + c4*(y-y0)*(y-y1) + c5*(x-x0)*(y-y0)

Parameters:
[in] x x-coord value
[in] y y-coord value
nx 
ny 
[in] image Image object (pointer)
Returns:
Interpolated value

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 }

void Util::Radialize int *  PermMatTr,
float *  kValsSorted,
float *  weightofkvalsSorted,
int  Size,
int *  SizeReturned
[static]
 

list the sorted lengths of the integer lattice sites of a square sided image of size Size.

PRB

Parameters:
[out] PermMatTr The matrix telling the ordering of the lattice sites wrt the array
[out] kValsSorted 
[out] weightofkvalsSorted the number of sites at that distance
[in] Size The length of the image
[out] SizeReturned 

Definition at line 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 }

EMData * Util::reconstitute_image_mask EMData image,
EMData mask
[static]
 

Recreates a n-d image using its compressed 1-D form and the mask.

Definition at line 6190 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().

06191 {
06192         /********
06193         ***Exception Handle
06194         *************/
06195         if(mask == NULL)
06196                 throw ImageDimensionException("The mask cannot be an null image");
06197 
06198         /***********
06199         ***get the size of the mask
06200         **************/
06201         int nx = mask->get_xsize(),ny = mask->get_ysize(),nz = mask->get_zsize();
06202 
06203         size_t i,size = (size_t)nx*ny*nz;                        /* loop counters */
06204         /* new image declaration */
06205         EMData *new_image = new EMData();
06206         new_image->set_size(nx,ny,nz);           /* set the size of new image */
06207         float *new_ptr  = new_image->get_data(); /* set size of the new image */
06208         float *mask_ptr = mask->get_data();      /* assign a pointer to the mask image */
06209         float *img_ptr  = image->get_data();     /* assign a pointer to the 1D image */
06210         int count = 0;
06211         float sum_under_mask = 0.0 ;
06212         for(i = 0;i < size;i++){
06213                         if(mask_ptr[i] > 0.5f){
06214                                 new_ptr[i] = img_ptr[count];
06215                                 sum_under_mask += img_ptr[count];
06216                                 count++;
06217                                 if( count > image->get_xsize() ) {
06218                                     throw ImageDimensionException("Error: in reconstitute_image_mask, the mask doesn't match the image, it is too large");
06219                                 }
06220                         }
06221         }
06222 
06223         if( count > image->get_xsize() ) {
06224             throw ImageDimensionException("Error: in reconstitute_image_mask, the mask doesn't match the image, it is too small");
06225         }
06226 
06227         float avg_under_mask = sum_under_mask / count;
06228         for(i = 0;i < size;i++) {
06229                 if(mask_ptr[i] <= 0.5f)  new_ptr[i] = avg_under_mask;
06230         }
06231         new_image->update();
06232         return new_image;
06233 }

string Util::recv_broadcast int  port  )  [static]
 

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 }

string Util::remove_filename_ext const string &  filename  )  [static]
 

Remove a filename's extension and return the new filename.

Parameters:
[in] filename The old filename whose extension is going to be removed.
Returns:
The new filename without extension.

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 }

float EMAN::Util::restrict1 float  x,
int  nx
[inline, static]
 

Definition at line 1086 of file util.h.

Referenced by get_pixel_conv_new(), and get_pixel_conv_new_background().

01095                                             {

void EMAN::Util::rot_shift float  x,
float  y,
float  alpha,
float  x0,
float  y0,
float *  x1,
float *  y1
[inline, static]
 

Definition at line 1054 of file util.h.

Referenced by multi_align_error_dfunc(), and multi_align_error_func().

01060                                                               {

void Util::rotate_phase_origin float *  data,
size_t  nx,
size_t  ny,
size_t  nz
[static]
 

rotate data vertically by ny/2, to make the mrc phase origin compliance with EMAN1 and TNF reader

Parameters:
data complex data array
nx x dimension size
ny y dimension size
nz z dimension size

Definition at line 95 of file util.cpp.

References 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 }

int EMAN::Util::round double  x  )  [inline, static]
 

Get ceiling round of a float number x.

Parameters:
[in] x Given float number.
Returns:
Ceiling round of x.

Definition at line 1458 of file util.h.

int EMAN::Util::round float  x  )  [inline, static]
 

Get ceiling round of a float number x.

Parameters:
[in] x Given float number.
Returns:
Ceiling round of x.

Definition at line 1446 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().

bool Util::sanitycheck int *  argParts,
int *  Indices,
int *  dimClasses,
int  nParts,
int  K,
int  T,
int *  output
[static]
 

First element of output is total cost of the matches in the output Second element of output is the total number of matches in output So output has 2+(*(output+1))nParts elements.

Definition at line 20457 of file util_sparx.cpp.

References k_means_cont_table_().

20457                                                                                                          {
20458         //cout<<"sanitycheck called\n";
20459         int total_cost = *output;
20460         int num_matches = *(output+1);
20461 
20462         int cost=0;
20463         int* intx;
20464         int intx_size;
20465         int* intx_next(0);
20466         int intx_next_size = 0;
20467         int curclass;
20468         int curclass_size;
20469         //cout<<"cost by match: [";
20470         for(int i = 0; i < num_matches; i++){
20471                 curclass = *(output+2+ i*nParts);
20472                 // check feasibility
20473                 if (*(argParts + Indices[curclass]+1) == -5) {cout<<"infeasible match!\n"; return 0;}
20474                 *(argParts + Indices[curclass]+1) = -5;
20475                 // initialize intx to the number of elements in class curclass of partition 0 of the i-th match
20476                 curclass_size = *(dimClasses+curclass)-2;
20477                 intx = new int[curclass_size];
20478                 for (int ic = 0; ic < curclass_size; ic++) *(intx+ic) = *(argParts + Indices[curclass]+2+ic);
20479                 intx_size = curclass_size;
20480 
20481                 for (int j=1; j < nParts; j++){
20482                       curclass = *(output+2+ i*nParts+j);
20483                       if (*(argParts + Indices[j*K+curclass]+1)==-5){cout<<"infeasible match!\n"; return 0;}
20484                       *(argParts + Indices[j*K+curclass]+1)=-5;
20485                       // compute the intersection of intx and class curclass of partition j of the i-th match
20486                       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);
20487                       intx_next = new int[intx_next_size];
20488                       Util::k_means_cont_table_(intx,argParts + Indices[j*K+curclass]+2, intx_next, intx_size, *(dimClasses + j*K+curclass)-2,1);
20489                       delete[] intx;
20490                       intx=intx_next;
20491                       intx_size= intx_next_size;
20492                       if (j==nParts-1) delete[] intx_next;
20493                 }
20494 
20495                 if (intx_next_size <= T) {cout << "something wrong with solution!\n"; return 0;}
20496                 //cout <<intx_next_size<<",";
20497                 cost = cost + intx_next_size;
20498         }
20499         //cout<<"]\n";
20500         if (cost != total_cost) {cout << "something wrong with solution!\n"; return 0;}
20501 
20502         return 1;
20503 
20504 }

void Util::save_data float  x0,
float  dx,
float *  y_array,
size_t  array_size,
const string &  filename
[static]
 

Save x, y data into a file.

Each line of the file have the format "x1TABy1", where x1 = x0 + dx*i; y1 = y_array[i].

Parameters:
[in] x0 The starting point of x.
[in] dx delta x. The increase step of x data.
[in] y_array The y data array.
[in] array_size The y data array size.
[in] filename The output filename.

Definition at line 618 of file util.cpp.

References Assert, FileAccessException, and NullPointerException.

00620 {
00621         Assert(dx > 0);
00622         Assert(array_size > 0);
00623         Assert(filename != "");
00624 
00625         if (!y_array) {
00626                 throw NullPointerException("y array");
00627         }
00628 
00629         FILE *out = fopen(filename.c_str(), "wb");
00630         if (!out) {
00631                 throw FileAccessException(filename);
00632         }
00633 
00634         for (size_t i = 0; i < array_size; i++) {
00635                 fprintf(out, "%g\t%g\n", x0 + dx * i, y_array[i]);
00636         }
00637         fclose(out);
00638 }

void Util::save_data float  x0,
float  dx,
const vector< float > &  y_array,
const string &  filename
[static]
 

Save x, y data into a file.

Each line of the file have the format "x1TABy1", where x1 = x0 + dx*i; y1 = y_array[i].

Parameters:
[in] x0 The starting point of x.
[in] dx delta x. The increase step of x data.
[in] y_array The y data array.
[in] filename The output filename.

Definition at line 599 of file util.cpp.

References Assert, and FileAccessException.

00601 {
00602         Assert(dx != 0);
00603         Assert(y_array.size() > 0);
00604         Assert(filename != "");
00605 
00606         FILE *out = fopen(filename.c_str(), "wb");
00607         if (!out) {
00608                 throw FileAccessException(filename);
00609         }
00610 
00611         for (size_t i = 0; i < y_array.size(); i++) {
00612                 fprintf(out, "%g\t%g\n", x0 + dx * i, y_array[i]);
00613         }
00614         fclose(out);
00615 }

void Util::save_data const vector< float > &  x_array,
const vector< float > &  y_array,
const string &  filename
[static]
 

Save (x y) data array into a file.

Each line of the file have the format "x1TABy1", where x1, y1 are elements of x array and y array. The x, y arrays must have the same number of items.

Parameters:
[in] x_array The x array.
[in] y_array The y array.
[in] filename The output filename.

Definition at line 575 of file util.cpp.

References Assert, FileAccessException, and LOGERR.

Referenced by EMAN::LowpassAutoBProcessor::create_radial_func(), and EMAN::CtfAverager::finish().

00577 {
00578         Assert(x_array.size() > 0);
00579         Assert(y_array.size() > 0);
00580         Assert(filename != "");
00581 
00582         if (x_array.size() != y_array.size()) {
00583                 LOGERR("array x and array y have different size: %d != %d\n",
00584                            x_array.size(), y_array.size());
00585                 return;
00586         }
00587 
00588         FILE *out = fopen(filename.c_str(), "wb");
00589         if (!out) {
00590                 throw FileAccessException(filename);
00591         }
00592 
00593         for (size_t i = 0; i < x_array.size(); i++) {
00594                 fprintf(out, "%g\t%g\n", x_array[i], y_array[i]);
00595         }
00596         fclose(out);
00597 }

string Util::sbasename const string &  filename  )  [static]
 

Get a filename's basename.

For example, the basename of "hello.c" is still "hello.c"; The basename of "/tmp/abc/hello.c" is "hello.c".

Parameters:
[in] filename The given filename, full path or relative path.
Returns:
The basename of the filename.

Definition at line 471 of file util.cpp.

Referenced by EMAN::Log::begin(), EMAN::TestUtil::check_image(), EMAN::TestUtil::dump_emdata(), EMAN::Log::loc(), and EMAN::TestUtil::set_progname().

00472 {
00473     if (filename == "") {
00474         return "";
00475     }
00476 
00477         char s = '/';
00478 #ifdef _WIN32
00479         s = '\\';
00480 #endif
00481         const char * c = strrchr(filename.c_str(), s);
00482     if (!c) {
00483         return filename;
00484     }
00485         else {
00486                 c++;
00487         }
00488     return string(c);
00489 }

void Util::search2 int *  argParts,
int *  Indices,
int *  dimClasses,
int  nParts,
int  K,
int  T,
int *  matchlist,
int *  costlist,
int  J
[static]
 

return the weight of the largest weighted feasible match, along with the match in the (preallocated) argument curmax.

The returned weight has to be gt newT. If there is no such feasible matching, return 0 as *curmax

Definition at line 20511 of file util_sparx.cpp.

References explore2(), flag, and k_means_cont_table_().

20511                                                                                                                               {
20512         
20513         // some temp variables
20514         bool flag = 0;
20515         int nintx;
20516         int* dummy(0);
20517         //int* ret;
20518         int* curbranch = new int[nParts];
20519         
20520         //initialize costlist to all 0
20521         for(int jit= 0; jit< J; jit++) *(costlist+jit) = 0;
20522         
20523         
20524         for(int a=0; a<K; a++)
20525         {
20526         
20527                 // 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
20528                 if (*(argParts + Indices[a] + 1) < 1) continue;
20529                 if (*(dimClasses + a)-2 <= T) continue;
20530 
20531                 // 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
20532 
20533                 for( int i=1; i < nParts; i++){
20534                         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.
20535                         for(int j=0; j < K; j++){
20536                                 if (*(argParts + Indices[i*K+j] + 1) < 1) continue;
20537                                 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);
20538                                 if (nintx > T) flag=1;
20539                                 else *(argParts + Indices[i*K+j] + 1) =-4;
20540                         }
20541                         if (flag==0) {break;}
20542                 }
20543 
20544                 // explore determines J matchs with the largest weight greater than T where class in partition 0 is class a
20545                 *curbranch = a;
20546 
20547                 if (flag > 0) // Each partition has one or more active class
20548                         Util::explore2(argParts, Indices, dimClasses, nParts, K, T, argParts+Indices[a]+2, *(dimClasses+a)-2, argParts+Indices[a]+2,
20549                         *(dimClasses+a)-2,0, J, matchlist, costlist, curbranch);
20550                         
20551                 // take all the classes marked as -4 and remark it as 1 in preparation for next round
20552                 for( int i=1; i < nParts; i++){
20553                         for(int j=0; j < K; j++){
20554                                 if (*(argParts + Indices[i*K+j] + 1) == -4) *(argParts + Indices[i*K+j] + 1) =1;
20555 
20556                         }
20557                 }
20558         }
20559         
20560         delete[] curbranch;
20561 }

void Util::set_line EMData img,
int  posline,
EMData line,
int  offset,
int  length
[static]
 

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 4782 of file util_sparx.cpp.

References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), img_ptr, nx, and EMAN::EMData::update().

04783 {
04784         int i;
04785         int nx=img->get_xsize();
04786         float *img_ptr  = img->get_data();
04787         float *line_ptr = line->get_data();
04788         for (i=0;i<length;i++) img_ptr[nx*posline + i] = line_ptr[offset + i];
04789         img->update();
04790 }

void Util::set_log_level int  argc,
char *  argv[]
[static]
 

Set program logging level through command line option "-v N", where N is the level.

Parameters:
[in] argc Number of arguments.
[in] argv Argument arrays.

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 }

void Util::set_randnum_seed unsigned long int  seed  )  [static]
 

Set the seed for Randnum class.

Parameters:
[in] seed the seed for current random number generator

Definition at line 678 of file util.cpp.

References EMAN::Randnum::set_seed().

00679 {
00680         Randnum* randnum = Randnum::Instance();
00681         randnum->set_seed(seed);
00682 }

template<class T>
T EMAN::Util::sgn T &  val  )  [inline, static]
 

Sign function.

Parameters:
[in] val value who's sign is to be checked
Returns:
+1 if the value is positive, -1 if the value is negative.

Definition at line 2068 of file util.h.

void Util::slicereverse float *  beg,
float *  end,
int  nx,
int  ny
[static]
 

Definition at line 5476 of file util_sparx.cpp.

References colreverse(), and nx.

Referenced by cyclicshift().

05477 {
05478         int nxy = nx*ny;
05479         colreverse(beg, end, nxy);
05480 }

void Util::sort_mat float *  left,
float *  right,
int *  leftPerm,
int *  rightPerm
[static]
 

does a sort as in Matlab.

Carries along the Permutation matrix

Parameters:
[in] left The array [left .. right] is sorted
[in] right The array [left .. right] is sorted
[in] leftPerm The array [leftPerm rightPerm] is shuffled due to the sorting
[in] rightPerm The array [leftPerm rightPerm] is shuffled due to the sorting Both arrays are reshuffled.

Definition at line 641 of file util.cpp.

Referenced by Radialize().

00643 {
00644         float *pivot ; int *pivotPerm;
00645 
00646         {
00647                 float *pLeft  =   left; int *pLeftPerm  =  leftPerm;
00648                 float *pRight =  right; int *pRightPerm = rightPerm;
00649                 float scratch =  *left; int scratchPerm = *leftPerm;
00650 
00651                 while (pLeft < pRight) {
00652                         while ((*pRight > scratch) && (pLeft < pRight)) {
00653                                 pRight--; pRightPerm--;
00654                         }
00655                         if (pLeft != pRight) {
00656                                 *pLeft = *pRight; *pLeftPerm = *pRightPerm;
00657                                 pLeft++; pLeftPerm++;
00658                         }
00659                         while ((*pLeft < scratch) && (pLeft < pRight)) {
00660                                 pLeft++; pLeftPerm++;
00661                         }
00662                         if (pLeft != pRight) {
00663                                 *pRight = *pLeft; *pRightPerm = *pLeftPerm;
00664                                 pRight--; pRightPerm--;
00665                         }
00666                 }
00667                 *pLeft = scratch; *pLeftPerm = scratchPerm;
00668                 pivot = pLeft; pivotPerm= pLeftPerm;
00669         }
00670         if (left < pivot) {
00671                 sort_mat(left, pivot - 1,leftPerm,pivotPerm-1);
00672         }
00673         if (right > pivot) {
00674                 sort_mat(pivot + 1, right,pivotPerm+1,rightPerm);
00675         }
00676 }

void Util::spline float *  x,
float *  y,
int  n,
float  yp1,
float  ypn,
float *  y2
[static]
 

Given a tabulated function y of x (unordered), and Given the values of the first derivatives at the end points This routine returns an array y2, that contains the second derivatives of the function at the tabulated points.

PRB This function is called by splint

Parameters:
x 
[in] y of x is the tabulated function of length n
n 
[in] yp1 : the derivatives of the first point.
[in] ypn : the derivatives of the last point.
[out] y2 is the value of the second derivatives

Definition at line 372 of file util_sparx.cpp.

References x, and y.

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 }

void Util::spline_mat float *  x,
float *  y,
int  n,
float *  xq,
float *  yq,
int  m
[static]
 

Given a tabulated function y of x (n unordered points), and Given the values of the m values xq to be interpolated This routine returns the interpolated array yq, PRB This function is called by splint.

Parameters:
x 
[in] y of x is the tabulated function of length n
n 
[in] xq is the x values to be splined: has m points.
[out] yq are the splined values
m 

Definition at line 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 }

void Util::splint float *  xa,
float *  ya,
float *  y2a,
int  n,
float *  xq,
float *  yq,
int  m
[static]
 

Given the arrays xa(ordered, ya of length n, which tabulate a function and given the array y2a which is the output of spline and an unordered array xq, this routine returns a cubic-spline interpolated array yq.

Parameters:
xa 
[in] ya of x is the tabulated function of length n
[in] y2a is returned from spline: second derivs
n 
[in] xq is the x values to be splined: has m points.
[out] yq are the splined values
m 

Definition at line 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 }

float EMAN::Util::square double  x  )  [inline, static]
 

Calculate a number's square.

Parameters:
[in] x Given number.
Returns:
(x*x).

Definition at line 1586 of file util.h.

float EMAN::Util::square float  x  )  [inline, static]
 

Calculate a number's square.

Parameters:
[in] x Given number.
Returns:
(x*x).

Definition at line 1577 of file util.h.

int EMAN::Util::square int  n  )  [inline, static]
 

Calculate a number's square.

Parameters:
[in] n Given number.
Returns:
(n*n).

Definition at line 1568 of file util.h.

Referenced by get_stats_cstyle().

float EMAN::Util::square_sum float  x,
float  y
[inline, static]
 

Calcuate (x*x + y*y).

Parameters:
[in] x The first number.
[in] y The second number.
Returns:
(x*x + y*y).

Definition at line 1596 of file util.h.

Referenced by get_stats(), and get_stats_cstyle().

bool Util::sstrncmp const char *  s1,
const char *  s2
[static]
 

Safe string compare.

It compares 's2' with the first N characters of 's1', where N is the length of 's2'.

Parameters:
s1 String 1. Its first strlen(s2) characters will be used to do the comparison.
s2 String 2. Its whole string will be used to do the comparison.
Returns:
True if the comparison is equal. False if not equal.

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 }

string Util::str_to_lower const string &  s  )  [static]
 

Return a lower case version of the argument string.

Parameters:
s the string you want to convert to lower case
Returns:
the lower case converted version s

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 }

void Util::sub_fav EMData ave,
EMData dat,
float  tot,
int  mirror,
vector< int >  numr
[static]
 

Definition at line 4625 of file util_sparx.cpp.

References EMAN::EMData::get_data(), numr, PI2, tot, and EMAN::EMData::update().

04625                                                                                       {
04626         int nring = numr.size()/3;
04627         float *ave = avep->get_data();
04628         float *dat = datp->get_data();
04629         int i, j, numr3i, np;
04630         float  arg, cs, si;
04631         int maxrin = numr(3,nring);
04632         if(mirror == 1) { //for mirrored data has to be conjugated
04633                 for (i=1; i<=nring; i++) {
04634                         numr3i = numr(3,i);
04635                         np     = numr(2,i)-1;
04636                         ave[np]   -= dat[np];
04637                         ave[np+1] -= static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) );
04638                         for (j=2; j<numr3i; j=j+2) {
04639                                 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin );
04640                                 cs = cos(arg);
04641                                 si = sin(arg);
04642                                 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg))
04643                                 ave[np + j]    -= dat[np + j]*cs - dat[np + j +1]*si;
04644                                 ave[np + j +1] += dat[np + j]*si + dat[np + j +1]*cs;
04645                         }
04646                 }
04647         } else {
04648                 for (i=1; i<=nring; i++) {
04649                         numr3i = numr(3,i);
04650                         np     = numr(2,i)-1;
04651                         ave[np]   -= dat[np];
04652                         ave[np+1] -= static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) );
04653                         for (j=2; j<numr3i; j=j+2) {
04654                                 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin );
04655                                 cs = cos(arg);
04656                                 si = sin(arg);
04657                                 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg))
04658                                 ave[np + j]    -= dat[np + j]*cs - dat[np + j +1]*si;
04659                                 ave[np + j +1] -= dat[np + j]*si + dat[np + j +1]*cs;
04660                         }
04661                 }
04662         }
04663         avep->update();
04664         EXITFUNC;
04665 }

void Util::sub_img EMData img,
EMData img1
[static]
 

Definition at line 17671 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().

17672 {
17673         ENTERFUNC;
17674         /* Exception Handle */
17675         if (!img) {
17676                 throw NullPointerException("NULL input image");
17677         }
17678         /* ========= img -= img1 ===================== */
17679 
17680         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17681         size_t size = (size_t)nx*ny*nz;
17682         float *img_ptr  = img->get_data();
17683         float *img1_ptr = img1->get_data();
17684         for (size_t i=0;i<size;++i) img_ptr[i] -= img1_ptr[i];
17685         img->update();
17686 
17687         EXITFUNC;
17688 }

EMData * Util::subn_img EMData img,
EMData img1
[static]
 

Definition at line 17453 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().

17454 {
17455         ENTERFUNC;
17456         /* Exception Handle */
17457         if (!img) {
17458                 throw NullPointerException("NULL input image");
17459         }
17460         /* ==============   output = img - img1   ================ */
17461 
17462         int nx=img->get_xsize(),ny=img->get_ysize(),nz=img->get_zsize();
17463         size_t size = (size_t)nx*ny*nz;
17464         EMData * img2 = img->copy_head();
17465         float *img_ptr  =img->get_data();
17466         float *img2_ptr = img2->get_data();
17467         float *img1_ptr = img1->get_data();
17468         for (size_t i=0;i<size;++i) img2_ptr[i] = img_ptr[i] - img1_ptr[i];
17469         img2->update();
17470         if(img->is_complex()) {
17471                 img2->set_complex(true);
17472                 if(img->is_fftodd()) img2->set_fftodd(true); else img2->set_fftodd(false);
17473         }
17474 
17475         EXITFUNC;
17476         return img2;
17477 }

vector< EMData * > Util::svdcmp const vector< EMData * > &  data,
int  nvec
[static]
 

Perform singular value decomposition on a set of images.

Parameters:
data A List of data objects to be decomposed
nvec Number of basis vectors to return, 0 returns full decomposition
Returns:
A list of images representing basis vectors in the SVD generated subspace

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 }

float Util::tf float  dzz,
float  ak,
float  voltage = 300.0f,
float  cs = 2.0f,
float  wgh = 0.1f,
float  b_factor = 0.0f,
float  sign = -1.0f
[static]
 

Definition at line 6138 of file util_sparx.cpp.

References phase(), and sqrt().

06139 {
06140         float cst  = cs*1.0e7f;
06141 
06142         wgh /= 100.0;
06143         float phase = atan(wgh/sqrt(1.0f-wgh*wgh));
06144         float lambda=12.398f/sqrt(voltage*(1022.0f+voltage));
06145         float ak2 = ak*ak;
06146         float g1 = dzz*1.0e4f*lambda*ak2;
06147         float g2 = cst*lambda*lambda*lambda*ak2*ak2/2.0f;
06148 
06149         float ctfv = static_cast<float>( sin(M_PI*(g1-g2)+phase)*sign );
06150         if(b_factor != 0.0f)  ctfv *= exp(-b_factor*ak2/4.0f);
06151 
06152         return ctfv;
06153 }

float EMAN::Util::trilinear_interpolate float  p1,
float  p2,
float  p3,
float  p4,
float  p5,
float  p6,
float  p7,
float  p8,
float  t,
float  u,
float  v
[inline, static]
 

Calculate trilinear interpolation.

Parameters:
[in] p1 The first number. corresponding to (x0,y0,z0).
[in] p2 The second number. corresponding to (x1,y0,z0).
[in] p3 The third number. corresponding to (x0,y1, z0).
[in] p4 The fourth number. corresponding to (x1,y1,z0).
[in] p5 The fifth number. corresponding to (x0,y0,z1).
[in] p6 The sixth number. corresponding to (x1,y0,z1).
[in] p7 The seventh number. corresponding to (x0,y1,z1).
[in] p8 The eighth number. corresponding to (x1,y1,z1).
[in] t t
[in] u u
[in] v v
Returns:
The trilinear interpolation value.

Definition at line 1507 of file util.h.

Referenced by EMAN::SymSearchProcessor::process_inplace(), EMAN::StandardProjector::project3d(), EMAN::EMData::sget_value_at_interp(), and EMAN::TransformProcessor::transform().

float Util::triquad float  r,
float  s,
float  t,
float *  fdata
[static]
 

Quadratic interpolation (3D).

Parameters:
r 
s 
t 
fdata 
Returns:
Interpolated value

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 }

int Util::trmsh3_ int *  n0,
double *  tol,
double *  x,
double *  y,
double *  z__,
int *  n,
int *  list,
int *  lptr,
int *  lend,
int *  lnew,
int *  indx,
int *  lcnt,
int *  near__,
int *  next,
double *  dist,
int *  ier
[static]
 

Definition at line 7890 of file util_sparx.cpp.

References abs, addnod_(), dist(), left_(), x, and y.

07894 {
07895     /* System generated locals */
07896     int i__1, i__2;
07897 
07898     /* Local variables */
07899     static double d__;
07900     static int i__, j;
07901     static double d1, d2, d3;
07902     static int i0, lp, kt, ku, lpl, nku;
07903     extern long int left_(double *, double *, double *, double
07904             *, double *, double *, double *, double *,
07905             double *);
07906     static int nexti;
07907     extern /* Subroutine */ int addnod_(int *, int *, double *,
07908             double *, double *, int *, int *, int *,
07909             int *, int *);
07910 
07911 
07912 /* *********************************************************** */
07913 
07914 /*                                              From STRIPACK */
07915 /*                                            Robert J. Renka */
07916 /*                                  Dept. of Computer Science */
07917 /*                                       Univ. of North Texas */
07918 /*                                           renka@cs.unt.edu */
07919 /*                                                   01/20/03 */
07920 
07921 /*   This is an alternative to TRMESH with the inclusion of */
07922 /* an efficient means of removing duplicate or nearly dupli- */
07923 /* cate nodes. */
07924 
07925 /*   This subroutine creates a Delaunay triangulation of a */
07926 /* set of N arbitrarily distributed points, referred to as */
07927 /* nodes, on the surface of the unit sphere.  Refer to Sub- */
07928 /* routine TRMESH for definitions and a list of additional */
07929 /* subroutines.  This routine is an alternative to TRMESH */
07930 /* with the inclusion of an efficient means of removing dup- */
07931 /* licate or nearly duplicate nodes. */
07932 
07933 /*   The algorithm has expected time complexity O(N*log(N)) */
07934 /* for random nodal distributions. */
07935 
07936 
07937 /* On input: */
07938 
07939 /*       N0 = Number of nodes, possibly including duplicates. */
07940 /*            N0 .GE. 3. */
07941 
07942 /*       TOL = Tolerance defining a pair of duplicate nodes: */
07943 /*             bound on the deviation from 1 of the cosine of */
07944 /*             the angle between the nodes.  Note that */
07945 /*             |1-cos(A)| is approximately A*A/2. */
07946 
07947 /* The above parameters are not altered by this routine. */
07948 
07949 /*       X,Y,Z = Arrays of length at least N0 containing the */
07950 /*               Cartesian coordinates of nodes.  (X(K),Y(K), */
07951 /*               Z(K)) is referred to as node K, and K is re- */
07952 /*               ferred to as a nodal index.  It is required */
07953 /*               that X(K)**2 + Y(K)**2 + Z(K)**2 = 1 for all */
07954 /*               K.  The first three nodes must not be col- */
07955 /*               linear (lie on a common great circle). */
07956 
07957 /*       LIST,LPTR = Arrays of length at least 6*N0-12. */
07958 
07959 /*       LEND = Array of length at least N0. */
07960 
07961 /*       INDX = Array of length at least N0. */
07962 
07963 /*       LCNT = Array of length at least N0 (length N is */
07964 /*              sufficient). */
07965 
07966 /*       NEAR,NEXT,DIST = Work space arrays of length at */
07967 /*                        least N0.  The space is used to */
07968 /*                        efficiently determine the nearest */
07969 /*                        triangulation node to each un- */
07970 /*                        processed node for use by ADDNOD. */
07971 
07972 /* On output: */
07973 
07974 /*       N = Number of nodes in the triangulation.  3 .LE. N */
07975 /*           .LE. N0, or N = 0 if IER < 0. */
07976 
07977 /*       X,Y,Z = Arrays containing the Cartesian coordinates */
07978 /*               of the triangulation nodes in the first N */
07979 /*               locations.  The original array elements are */
07980 /*               shifted down as necessary to eliminate dup- */
07981 /*               licate nodes. */
07982 
07983 /*       LIST = Set of nodal indexes which, along with LPTR, */
07984 /*              LEND, and LNEW, define the triangulation as a */
07985 /*              set of N adjacency lists -- counterclockwise- */
07986 /*              ordered sequences of neighboring nodes such */
07987 /*              that the first and last neighbors of a bound- */
07988 /*              ary node are boundary nodes (the first neigh- */
07989 /*              bor of an interior node is arbitrary).  In */
07990 /*              order to distinguish between interior and */
07991 /*              boundary nodes, the last neighbor of each */
07992 /*              boundary node is represented by the negative */
07993 /*              of its index. */
07994 
07995 /*       LPTR = Set of pointers (LIST indexes) in one-to-one */
07996 /*              correspondence with the elements of LIST. */
07997 /*              LIST(LPTR(I)) indexes the node which follows */
07998 /*              LIST(I) in cyclical counterclockwise order */
07999 /*              (the first neighbor follows the last neigh- */
08000 /*              bor). */
08001 
08002 /*       LEND = Set of pointers to adjacency lists.  LEND(K) */
08003 /*              points to the last neighbor of node K for */
08004 /*              K = 1,...,N.  Thus, LIST(LEND(K)) < 0 if and */
08005 /*              only if K is a boundary node. */
08006 
08007 /*       LNEW = Pointer to the first empty location in LIST */
08008 /*              and LPTR (list length plus one).  LIST, LPTR, */
08009 /*              LEND, and LNEW are not altered if IER < 0, */
08010 /*              and are incomplete if IER > 0. */
08011 
08012 /*       INDX = Array of output (triangulation) nodal indexes */
08013 /*              associated with input nodes.  For I = 1 to */
08014 /*              N0, INDX(I) is the index (for X, Y, and Z) of */
08015 /*              the triangulation node with the same (or */
08016 /*              nearly the same) coordinates as input node I. */
08017 
08018 /*       LCNT = Array of int weights (counts) associated */
08019 /*              with the triangulation nodes.  For I = 1 to */
08020 /*              N, LCNT(I) is the number of occurrences of */
08021 /*              node I in the input node set, and thus the */
08022 /*              number of duplicates is LCNT(I)-1. */
08023 
08024 /*       NEAR,NEXT,DIST = Garbage. */
08025 
08026 /*       IER = Error indicator: */
08027 /*             IER =  0 if no errors were encountered. */
08028 /*             IER = -1 if N0 < 3 on input. */
08029 /*             IER = -2 if the first three nodes are */
08030 /*                      collinear. */
08031 /*             IER = -3 if Subroutine ADDNOD returns an error */
08032 /*                      flag.  This should not occur. */
08033 
08034 /* Modules required by TRMSH3:  ADDNOD, BDYADD, COVSPH, */
08035 /*                                INSERT, INTADD, JRAND, */
08036 /*                                LEFT, LSTPTR, STORE, SWAP, */
08037 /*                                SWPTST, TRFIND */
08038 
08039 /* Intrinsic function called by TRMSH3:  ABS */
08040 
08041 /* *********************************************************** */
08042 
08043 
08044 /* Local parameters: */
08045 
08046 /* D =        (Negative cosine of) distance from node KT to */
08047 /*              node I */
08048 /* D1,D2,D3 = Distances from node KU to nodes 1, 2, and 3, */
08049 /*              respectively */
08050 /* I,J =      Nodal indexes */
08051 /* I0 =       Index of the node preceding I in a sequence of */
08052 /*              unprocessed nodes:  I = NEXT(I0) */
08053 /* KT =       Index of a triangulation node */
08054 /* KU =       Index of an unprocessed node and DO-loop index */
08055 /* LP =       LIST index (pointer) of a neighbor of KT */
08056 /* LPL =      Pointer to the last neighbor of KT */
08057 /* NEXTI =    NEXT(I) */
08058 /* NKU =      NEAR(KU) */
08059 
08060     /* Parameter adjustments */
08061     --dist;
08062     --next;
08063     --near__;
08064     --indx;
08065     --lend;
08066     --z__;
08067     --y;
08068     --x;
08069     --list;
08070     --lptr;
08071     --lcnt;
08072 
08073     /* Function Body */
08074     if (*n0 < 3) {
08075         *n = 0;
08076         *ier = -1;
08077         return 0;
08078     }
08079 
08080 /* Store the first triangle in the linked list. */
08081 
08082     if (! left_(&x[1], &y[1], &z__[1], &x[2], &y[2], &z__[2], &x[3], &y[3], &
08083             z__[3])) {
08084 
08085 /*   The first triangle is (3,2,1) = (2,1,3) = (1,3,2). */
08086 
08087         list[1] = 3;
08088         lptr[1] = 2;
08089         list[2] = -2;
08090         lptr[2] = 1;
08091         lend[1] = 2;
08092 
08093         list[3] = 1;
08094         lptr[3] = 4;
08095         list[4] = -3;
08096         lptr[4] = 3;
08097         lend[2] = 4;
08098 
08099         list[5] = 2;
08100         lptr[5] = 6;
08101         list[6] = -1;
08102         lptr[6] = 5;
08103         lend[3] = 6;
08104 
08105     } else if (! left_(&x[2], &y[2], &z__[2], &x[1], &y[1], &z__[1], &x[3], &
08106             y[3], &z__[3])) {
08107 
08108 /*   The first triangle is (1,2,3):  3 Strictly Left 1->2, */
08109 /*     i.e., node 3 lies in the left hemisphere defined by */
08110 /*     arc 1->2. */
08111 
08112         list[1] = 2;
08113         lptr[1] = 2;
08114         list[2] = -3;
08115         lptr[2] = 1;
08116         lend[1] = 2;
08117 
08118         list[3] = 3;
08119         lptr[3] = 4;
08120         list[4] = -1;
08121         lptr[4] = 3;
08122         lend[2] = 4;
08123 
08124         list[5] = 1;
08125         lptr[5] = 6;
08126         list[6] = -2;
08127         lptr[6] = 5;
08128         lend[3] = 6;
08129 
08130 
08131     } else {
08132 
08133 /*   The first three nodes are collinear. */
08134 
08135         *n = 0;
08136         *ier = -2;
08137         return 0;
08138     }
08139 
08140     //printf("pass check colinear\n");
08141 
08142 /* Initialize LNEW, INDX, and LCNT, and test for N = 3. */
08143 
08144     *lnew = 7;
08145     indx[1] = 1;
08146     indx[2] = 2;
08147     indx[3] = 3;
08148     lcnt[1] = 1;
08149     lcnt[2] = 1;
08150     lcnt[3] = 1;
08151     if (*n0 == 3) {
08152         *n = 3;
08153         *ier = 0;
08154         return 0;
08155     }
08156 
08157 /* A nearest-node data structure (NEAR, NEXT, and DIST) is */
08158 /*   used to obtain an expected-time (N*log(N)) incremental */
08159 /*   algorithm by enabling constant search time for locating */
08160 /*   each new node in the triangulation. */
08161 
08162 /* For each unprocessed node KU, NEAR(KU) is the index of the */
08163 /*   triangulation node closest to KU (used as the starting */
08164 /*   point for the search in Subroutine TRFIND) and DIST(KU) */
08165 /*   is an increasing function of the arc length (angular */
08166 /*   distance) between nodes KU and NEAR(KU):  -Cos(a) for */
08167 /*   arc length a. */
08168 
08169 /* Since it is necessary to efficiently find the subset of */
08170 /*   unprocessed nodes associated with each triangulation */
08171 /*   node J (those that have J as their NEAR entries), the */
08172 /*   subsets are stored in NEAR and NEXT as follows:  for */
08173 /*   each node J in the triangulation, I = NEAR(J) is the */
08174 /*   first unprocessed node in J's set (with I = 0 if the */
08175 /*   set is empty), L = NEXT(I) (if I > 0) is the second, */
08176 /*   NEXT(L) (if L > 0) is the third, etc.  The nodes in each */
08177 /*   set are initially ordered by increasing indexes (which */
08178 /*   maximizes efficiency) but that ordering is not main- */
08179 /*   tained as the data structure is updated. */
08180 
08181 /* Initialize the data structure for the single triangle. */
08182 
08183     near__[1] = 0;
08184     near__[2] = 0;
08185     near__[3] = 0;
08186     for (ku = *n0; ku >= 4; --ku) {
08187         d1 = -(x[ku] * x[1] + y[ku] * y[1] + z__[ku] * z__[1]);
08188         d2 = -(x[ku] * x[2] + y[ku] * y[2] + z__[ku] * z__[2]);
08189         d3 = -(x[ku] * x[3] + y[ku] * y[3] + z__[ku] * z__[3]);
08190         if (d1 <= d2 && d1 <= d3) {
08191             near__[ku] = 1;
08192             dist[ku] = d1;
08193             next[ku] = near__[1];
08194             near__[1] = ku;
08195         } else if (d2 <= d1 && d2 <= d3) {
08196             near__[ku] = 2;
08197             dist[ku] = d2;
08198             next[ku] = near__[2];
08199             near__[2] = ku;
08200         } else {
08201             near__[ku] = 3;
08202             dist[ku] = d3;
08203             next[ku] = near__[3];
08204             near__[3] = ku;
08205         }
08206 /* L1: */
08207     }
08208 
08209 /* Loop on unprocessed nodes KU.  KT is the number of nodes */
08210 /*   in the triangulation, and NKU = NEAR(KU). */
08211 
08212     kt = 3;
08213     i__1 = *n0;
08214     for (ku = 4; ku <= i__1; ++ku) {
08215         nku = near__[ku];
08216 
08217 /* Remove KU from the set of unprocessed nodes associated */
08218 /*   with NEAR(KU). */
08219         i__ = nku;
08220         if (near__[i__] == ku) {
08221             near__[i__] = next[ku];
08222         } else {
08223             i__ = near__[i__];
08224 L2:
08225             i0 = i__;
08226             i__ = next[i0];
08227             if (i__ != ku) {
08228                 goto L2;
08229             }
08230             next[i0] = next[ku];
08231         }
08232         near__[ku] = 0;
08233 
08234 /* Bypass duplicate nodes. */
08235 
08236         if (dist[ku] <= *tol - 1.) {
08237             indx[ku] = -nku;
08238             ++lcnt[nku];
08239             goto L6;
08240         }
08241 
08242 
08243 /* Add a new triangulation node KT with LCNT(KT) = 1. */
08244         ++kt;
08245         x[kt] = x[ku];
08246         y[kt] = y[ku];
08247         z__[kt] = z__[ku];
08248         indx[ku] = kt;
08249         lcnt[kt] = 1;
08250         addnod_(&nku, &kt, &x[1], &y[1], &z__[1], &list[1], &lptr[1], &lend[1]
08251                 , lnew, ier);
08252         if (*ier != 0) {
08253             *n = 0;
08254             *ier = -3;
08255             return 0;
08256         }
08257 
08258 /* Loop on neighbors J of node KT. */
08259 
08260         lpl = lend[kt];
08261         lp = lpl;
08262 L3:
08263         lp = lptr[lp];
08264         j = (i__2 = list[lp], abs(i__2));
08265 
08266 /* Loop on elements I in the sequence of unprocessed nodes */
08267 /*   associated with J:  KT is a candidate for replacing J */
08268 /*   as the nearest triangulation node to I.  The next value */
08269 /*   of I in the sequence, NEXT(I), must be saved before I */
08270 /*   is moved because it is altered by adding I to KT's set. */
08271 
08272         i__ = near__[j];
08273 L4:
08274         if (i__ == 0) {
08275             goto L5;
08276         }
08277         nexti = next[i__];
08278 
08279 /* Test for the distance from I to KT less than the distance */
08280 /*   from I to J. */
08281 
08282         d__ = -(x[i__] * x[kt] + y[i__] * y[kt] + z__[i__] * z__[kt]);
08283         if (d__ < dist[i__]) {
08284 
08285 /* Replace J by KT as the nearest triangulation node to I: */
08286 /*   update NEAR(I) and DIST(I), and remove I from J's set */
08287 /*   of unprocessed nodes and add it to KT's set. */
08288 
08289             near__[i__] = kt;
08290             dist[i__] = d__;
08291             if (i__ == near__[j]) {
08292                 near__[j] = nexti;
08293             } else {
08294                 next[i0] = nexti;
08295             }
08296             next[i__] = near__[kt];
08297             near__[kt] = i__;
08298         } else {
08299             i0 = i__;
08300         }
08301 
08302 /* Bottom of loop on I. */
08303 
08304         i__ = nexti;
08305         goto L4;
08306 
08307 /* Bottom of loop on neighbors J. */
08308 
08309 L5:
08310         if (lp != lpl) {
08311             goto L3;
08312         }
08313 L6:
08314         ;
08315     }
08316     *n = kt;
08317     *ier = 0;
08318     return 0;
08319 } /* trmsh3_ */

vector< float > Util::twoD_fine_ali EMData image,
EMData refim,
EMData mask,
float  ang,
float  sxs,
float  sys
[static]
 

Definition at line 18910 of file util_sparx.cpp.

References EMAN::EMData::cmp(), dt, EMAN::EMData::rot_scale_trans2D(), setulb_(), SIXTY, and x.

18910                                                                                                              {
18911 
18912         EMData *rot;
18913 
18914         const int nmax=3, mmax=3;
18915         char task[60], csave[60];
18916         long int lsave[4];
18917         long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44];
18918         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];
18919         long int SIXTY=60;
18920 
18921         //     We wish to have no output.
18922         iprint = -1;
18923 
18924         //c     We specify the tolerances in the stopping criteria.
18925         factr=1.0e1;
18926         pgtol=1.0e-5;
18927 
18928         //     We specify the dimension n of the sample problem and the number
18929         //        m of limited memory corrections stored.  (n and m should not
18930         //        exceed the limits nmax and mmax respectively.)
18931         n=3;
18932         m=3;
18933 
18934         //     We now provide nbd which defines the bounds on the variables:
18935         //                    l   specifies the lower bounds,
18936         //                    u   specifies the upper bounds.
18937         //                    x   specifies the initial guess
18938         x[0] = ang; nbd[0] = 2; l[0] = ang-2.0; u[0] = ang+2.0;
18939         x[1] = sxs; nbd[1] = 2; l[1] = sxs-1.5; u[1] = sxs+1.5;
18940         x[2] = sys; nbd[2] = 2; l[2] = sys-1.5; u[2] = sys+1.5;
18941 
18942 
18943         //     We start the iteration by initializing task.
18944         // (**MUST clear remaining chars in task with spaces (else crash)!**)
18945         strcpy(task,"START");
18946         for (int i=5;i<60;i++)  task[i]=' ';
18947 
18948         //     This is the call to the L-BFGS-B code.
18949         // (* call the L-BFGS-B routine with task='START' once before loop *)
18950         setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
18951         //int step = 1;
18952 
18953         // (* while routine returns "FG" or "NEW_X" in task, keep calling it *)
18954         while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) {
18955 
18956                 if (strncmp(task,"FG",2)==0) {
18957                 //   the minimization routine has returned to request the
18958                 //   function f and gradient g values at the current x
18959 
18960                 //        Compute function value f for the sample problem.
18961                 rot = new EMData();
18962                 rot = image->rot_scale_trans2D((float)x[0], (float)x[1], (float)x[2], 1.0f);
18963                 f = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
18964                 //f = -f;
18965                 delete rot;
18966 
18967                 //        Compute gradient g for the sample problem.
18968                 float dt = 1.0e-3f;
18969                 rot = new EMData();
18970                 rot = image->rot_scale_trans2D((float)x[0]+dt, (float)x[1], (float)x[2], 1.0f);
18971                 f1 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
18972                 //f1 = -f1;
18973                 g[0] = (f1-f)/dt;
18974                 delete rot;
18975 
18976                 dt = 1.0e-2f;
18977                 rot = new EMData();
18978                 rot = image->rot_scale_trans2D((float)x[0], (float)x[1]+dt, (float)x[2], 1.0f);
18979                 f2 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
18980                 //f2 = -f2;
18981                 g[1] = (f2-f)/dt;
18982                 delete rot;
18983 
18984                 rot = new EMData();
18985                 rot = image->rot_scale_trans2D((float)x[0], (float)x[1], (float)x[2]+dt, 1.0f);
18986                 f3 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
18987                 //f3 = -f3;
18988                 g[2] = (f3-f)/dt;
18989                 delete rot;
18990                 }
18991 
18992                 //c          go back to the minimization routine.
18993                 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
18994                 //step++;
18995         }
18996 
18997         //printf("Total step is %d\n", step);
18998         vector<float> res;
18999         res.push_back(static_cast<float>(x[0]));
19000         res.push_back(static_cast<float>(x[1]));
19001         res.push_back(static_cast<float>(x[2]));
19002         //res.push_back(step);
19003         return res;
19004 }

vector< float > Util::twoD_fine_ali_G EMData image,
EMData refim,
EMData mask,
Util::KaiserBessel kb,
float  ang,
float  sxs,
float  sys
[static]
 

Definition at line 19006 of file util_sparx.cpp.

References EMAN::EMData::cmp(), dt, pi, EMAN::EMData::rot_scale_conv7(), setulb_(), SIXTY, and x.

19006                                                                                                                                      {
19007 
19008         EMData *rot;
19009 
19010         const int nmax=3, mmax=3;
19011         char task[60], csave[60];
19012         long int lsave[4];
19013         long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44];
19014         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];
19015         long int SIXTY=60;
19016 
19017         //     We wish to have no output.
19018         iprint = -1;
19019 
19020         //c     We specify the tolerances in the stopping criteria.
19021         factr=1.0e1;
19022         pgtol=1.0e-5;
19023 
19024         //     We specify the dimension n of the sample problem and the number
19025         //        m of limited memory corrections stored.  (n and m should not
19026         //        exceed the limits nmax and mmax respectively.)
19027         n=3;
19028         m=3;
19029 
19030         //     We now provide nbd which defines the bounds on the variables:
19031         //                    l   specifies the lower bounds,
19032         //                    u   specifies the upper bounds.
19033         //                    x   specifies the initial guess
19034         x[0] = ang; nbd[0] = 2; l[0] = ang-2.0; u[0] = ang+2.0;
19035         x[1] = sxs; nbd[1] = 2; l[1] = sxs-1.5; u[1] = sxs+1.5;
19036         x[2] = sys; nbd[2] = 2; l[2] = sys-1.5; u[2] = sys+1.5;
19037 
19038 
19039         //     We start the iteration by initializing task.
19040         // (**MUST clear remaining chars in task with spaces (else crash)!**)
19041         strcpy(task,"START");
19042         for (int i=5;i<60;i++)  task[i]=' ';
19043 
19044         //     This is the call to the L-BFGS-B code.
19045         // (* call the L-BFGS-B routine with task='START' once before loop *)
19046         setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
19047         //int step = 1;
19048 
19049         // (* while routine returns "FG" or "NEW_X" in task, keep calling it *)
19050         while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) {
19051 
19052                 if (strncmp(task,"FG",2)==0) {
19053                 //   the minimization routine has returned to request the
19054                 //   function f and gradient g values at the current x
19055 
19056                 //        Compute function value f for the sample problem.
19057                 rot = new EMData();
19058                 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1], (float)x[2], kb, 1.0f);
19059                 f = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
19060                 //f = -f;
19061                 delete rot;
19062 
19063                 //        Compute gradient g for the sample problem.
19064                 float dt = 1.0e-3f;
19065                 rot = new EMData();
19066                 rot = image->rot_scale_conv7((float)((x[0]+dt)*pi/180), (float)x[1], (float)x[2], kb, 1.0f);
19067                 f1 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
19068                 //f1 = -f1;
19069                 g[0] = (f1-f)/dt;
19070                 delete rot;
19071 
19072                 rot = new EMData();
19073                 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1]+dt, (float)x[2], kb, 1.0);
19074                 f2 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
19075                 //f2 = -f2;
19076                 g[1] = (f2-f)/dt;
19077                 delete rot;
19078 
19079                 rot = new EMData();
19080                 rot = image->rot_scale_conv7((float)(x[0]*pi/180), (float)x[1], (float)x[2]+dt, kb, 1.0f);
19081                 f3 = rot->cmp("sqeuclidean", refim, Dict("mask", mask));
19082                 //f3 = -f3;
19083                 g[2] = (f3-f)/dt;
19084                 delete rot;
19085                 }
19086 
19087                 //c          go back to the minimization routine.
19088                 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
19089                 //step++;
19090         }
19091 
19092         //printf("Total step is %d\n", step);
19093         vector<float> res;
19094         res.push_back(static_cast<float>(x[0]));
19095         res.push_back(static_cast<float>(x[1]));
19096         res.push_back(static_cast<float>(x[2]));
19097         //res.push_back(step);
19098         return res;
19099 }

vector< float > Util::twoD_fine_ali_SD EMData image,
EMData refim,
EMData mask,
float  ang,
float  sxs,
float  sys
[static]
 

Definition at line 19258 of file util_sparx.cpp.

References Steepda(), and x.

19258                                                                                                                 {
19259 
19260         double  x[4];
19261         int n;
19262         int l = 3;
19263         int m = 200;
19264         double e = 1e-9;
19265         double step = 0.01;
19266         float (*my_func)(EMData* , EMData* , EMData* , float , float , float) = ccc_images;
19267 
19268         x[1] = ang;
19269         x[2] = sxs;
19270         x[3] = sys;
19271 
19272         Steepda(x, step, e, l, m, &n, my_func, image, refim, mask);   // Call steepest descent optimization subroutine
19273         //printf("Took %d steps\n", n);
19274 
19275         vector<float> res;
19276         res.push_back(static_cast<float>(x[1]));
19277         res.push_back(static_cast<float>(x[2]));
19278         res.push_back(static_cast<float>(x[3]));
19279         res.push_back(static_cast<float>(n));
19280         return res;
19281 }

vector< float > Util::twoD_fine_ali_SD_G EMData image,
EMData refim,
EMData mask,
Util::KaiserBessel kb,
float  ang,
float  sxs,
float  sys
[static]
 

Definition at line 19540 of file util_sparx.cpp.

References Steepda_G(), and x.

19540                                                                                                                                         {
19541 
19542         double  x[4];
19543         int n;
19544         int l = 3;
19545         int m = 200;
19546         double e = 1e-9;
19547         double step = 0.001;
19548         float (*my_func)(EMData* , EMData* , EMData* , Util::KaiserBessel&, float , float , float) = ccc_images_G;
19549 
19550         x[1] = ang;
19551         x[2] = sxs;
19552         x[3] = sys;
19553 
19554         Steepda_G(x, step, e, l, m, &n, my_func, image, refim, mask, kb);   // Call steepest descent optimization subroutine
19555         //printf("Took %d steps\n", n);
19556 
19557         vector<float> res;
19558         res.push_back(static_cast<float>(x[1]));
19559         res.push_back(static_cast<float>(x[2]));
19560         res.push_back(static_cast<float>(x[3]));
19561         res.push_back(static_cast<float>(n));
19562         return res;
19563 }

vector< float > Util::twoD_to_3D_ali EMData volft,
Util::KaiserBessel kb,
EMData refim,
EMData mask,
float  phi,
float  theta,
float  psi,
float  sxs,
float  sxy
[static]
 

Definition at line 19101 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.

19101                                                                                                                                                             {
19102 
19103         EMData *proj, *proj2;
19104 
19105         const int nmax=5, mmax=5;
19106         char task[60], csave[60];
19107         long int lsave[4];
19108         long int n, m, iprint, nbd[nmax], iwa[3*nmax], isave[44];
19109         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];
19110         long int SIXTY=60;
19111 
19112         //     We wish to have no output.
19113         iprint = -1;
19114 
19115         //c     We specify the tolerances in the stopping criteria.
19116         factr=1.0e1;
19117         pgtol=1.0e-5;
19118 
19119         //     We specify the dimension n of the sample problem and the number
19120         //        m of limited memory corrections stored.  (n and m should not
19121         //        exceed the limits nmax and mmax respectively.)
19122         n=5;
19123         m=5;
19124 
19125         //     We now provide nbd which defines the bounds on the variables:
19126         //                    l   specifies the lower bounds,
19127         //                    u   specifies the upper bounds.
19128         //                    x   specifies the initial guess
19129         x[0] = phi;     nbd[0] = 2;     l[0] = phi-2.0;         u[0] = phi+2.0;
19130         x[1] = theta;   nbd[1] = 2;     l[1] = theta-2.0;       u[1] = theta+2.0;
19131         x[2] = psi;     nbd[2] = 2;     l[2] = psi-2.0;         u[2] = psi+2.0;
19132         x[3] = sxs;     nbd[3] = 2;     l[3] = sxs-2.0;         u[3] = sxs+2.0;
19133         x[4] = sys;     nbd[4] = 2;     l[4] = sys-2.0;         u[4] = sys+2.0;
19134 
19135 
19136         //     We start the iteration by initializing task.
19137         // (**MUST clear remaining chars in task with spaces (else crash)!**)
19138         strcpy(task,"START");
19139         for (int i=5;i<60;i++)  task[i]=' ';
19140 
19141         //     This is the call to the L-BFGS-B code.
19142         // (* call the L-BFGS-B routine with task='START' once before loop *)
19143         setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
19144         int step = 1;
19145 
19146         // (* while routine returns "FG" or "NEW_X" in task, keep calling it *)
19147         while (strncmp(task,"FG",2)==0 || strncmp(task,"NEW_X",5)==0) {
19148 
19149                 if (strncmp(task,"FG",2)==0) {
19150                 //   the minimization routine has returned to request the
19151                 //   function f and gradient g values at the current x
19152 
19153                 //        Compute function value f for the sample problem.
19154                 proj = new EMData();
19155                 proj2 = new EMData();
19156                 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb);
19157                 proj->fft_shuffle();
19158                 proj->center_origin_fft();
19159                 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f));
19160                 proj->do_ift_inplace();
19161                 int M = proj->get_ysize()/2;
19162                 proj2 = proj->window_center(M);
19163                 f = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
19164                 //f = -f;
19165                 delete proj;
19166                 delete proj2;
19167 
19168                 //        Compute gradient g for the sample problem.
19169                 float dt = 1.0e-3f;
19170                 proj = new EMData();
19171                 proj2 = new EMData();
19172                 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0]+dt, "theta", (float)x[1], "psi", (float)x[2])), kb);
19173                 proj->fft_shuffle();
19174                 proj->center_origin_fft();
19175                 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f));
19176                 proj->do_ift_inplace();
19177                 proj2 = proj->window_center(M);
19178                 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
19179                 //ft = -ft;
19180                 delete proj;
19181                 delete proj2;
19182                 g[0] = (ft-f)/dt;
19183 
19184                 proj = new EMData();
19185                 proj2 = new EMData();
19186                 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1]+dt, "psi", (float)x[2])), kb);
19187                 proj->fft_shuffle();
19188                 proj->center_origin_fft();
19189                 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f));
19190                 proj->do_ift_inplace();
19191                 proj2 = proj->window_center(M);
19192                 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
19193                 //ft = -ft;
19194                 delete proj;
19195                 delete proj2;
19196                 g[1] = (ft-f)/dt;
19197 
19198                 proj = new EMData();
19199                 proj2 = new EMData();
19200                 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2]+dt)), kb);
19201                 proj->fft_shuffle();
19202                 proj->center_origin_fft();
19203                 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4], "z_shift", 0.0f));
19204                 proj->do_ift_inplace();
19205                 proj2 = proj->window_center(M);
19206                 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
19207                 //ft = -ft;
19208                 delete proj;
19209                 delete proj2;
19210                 g[2] = (ft-f)/dt;
19211 
19212                 proj = new EMData();
19213                 proj2 = new EMData();
19214                 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb);
19215                 proj->fft_shuffle();
19216                 proj->center_origin_fft();
19217                 proj->process_inplace("filter.shift", Dict("x_shift", x[3]+dt, "y_shift", x[4], "z_shift", 0.0f));
19218                 proj->do_ift_inplace();
19219                 proj2 = proj->window_center(M);
19220                 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
19221                 //ft = -ft;
19222                 delete proj;
19223                 delete proj2;
19224                 g[3] = (ft-f)/dt;
19225 
19226                 proj = new EMData();
19227                 proj2 = new EMData();
19228                 proj = volft->extract_plane(Transform(Dict("type", "SPIDER", "phi", (float)x[0], "theta", (float)x[1], "psi", (float)x[2])), kb);
19229                 proj->fft_shuffle();
19230                 proj->center_origin_fft();
19231                 proj->process_inplace("filter.shift", Dict("x_shift", x[3], "y_shift", x[4]+dt, "z_shift", 0.0f));
19232                 proj->do_ift_inplace();
19233                 proj2 = proj->window_center(M);
19234                 ft = proj2->cmp("sqeuclidean", refim, Dict("mask", mask));
19235                 //ft = -ft;
19236                 delete proj;
19237                 delete proj2;
19238                 g[4] = (ft-f)/dt;
19239                 }
19240 
19241                 //c          go back to the minimization routine.
19242                 setulb_(&n,&m,x,l,u,nbd,&f,g,&factr,&pgtol,wa,iwa,task,&iprint,csave,lsave,isave,dsave,SIXTY,SIXTY);
19243                 step++;
19244         }
19245 
19246         //printf("Total step is %d\n", step);
19247         vector<float> res;
19248         res.push_back(static_cast<float>(x[0]));
19249         res.push_back(static_cast<float>(x[1]));
19250         res.push_back(static_cast<float>(x[2]));
19251         res.push_back(static_cast<float>(x[3]));
19252         res.push_back(static_cast<float>(x[4]));
19253         //res.push_back(step);
19254         return res;
19255 }

EMData * Util::TwoDTestFunc int  Size,
float  p,
float  q,
float  a,
float  b,
int  flag = 0,
float  alphaDeg = 0
[static]
 

Creates a Two D Test Pattern.

Parameters:
[in] Size must be odd
[in] p the x frequency
[in] q the y frequency
[in] a the x falloff
b the y falloff
flag 
[in] alphaDeg the projection angle
Returns:
The 2D test pattern in real space, fourier space, or the projection in real or fourier space or the FH of the 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 }

void Util::update_fav EMData ave,
EMData dat,
float  tot,
int  mirror,
vector< int >  numr
[static]
 

Definition at line 4583 of file util_sparx.cpp.

References EMAN::EMData::get_data(), numr, PI2, tot, and EMAN::EMData::update().

04583                                                                                           {
04584         int nring = numr.size()/3;
04585         float *ave = avep->get_data();
04586         float *dat = datp->get_data();
04587         int i, j, numr3i, np;
04588         float  arg, cs, si;
04589         int maxrin = numr(3,nring);
04590         if(mirror == 1) { //for mirrored data has to be conjugated
04591                 for (i=1; i<=nring; i++) {
04592                         numr3i = numr(3,i);
04593                         np     = numr(2,i)-1;
04594                         ave[np]   += dat[np];
04595                         ave[np+1] += static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) );
04596                         for (j=2; j<numr3i; j=j+2) {
04597                                 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin );
04598                                 cs = cos(arg);
04599                                 si = sin(arg);
04600                                 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg))
04601                                 ave[np + j]    += dat[np + j]*cs - dat[np + j +1]*si;
04602                                 ave[np + j +1] -= dat[np + j]*si + dat[np + j +1]*cs;
04603                         }
04604                 }
04605         } else {
04606                 for (i=1; i<=nring; i++) {
04607                         numr3i = numr(3,i);
04608                         np     = numr(2,i)-1;
04609                         ave[np]   += dat[np];
04610                         ave[np+1] += static_cast<float>( dat[np+1]*cos(PI2*(tot-1.0f)/2.0f*numr3i/maxrin) );
04611                         for (j=2; j<numr3i; j=j+2) {
04612                                 arg = static_cast<float>( PI2*(tot-1.)*(j/2)/maxrin );
04613                                 cs = cos(arg);
04614                                 si = sin(arg);
04615                                 //complex(data[np + j],data[np + j +1])*complex(cos(arg),sin(arg))
04616                                 ave[np + j]    += dat[np + j]*cs - dat[np + j +1]*si;
04617                                 ave[np + j +1] += dat[np + j]*si + dat[np + j +1]*cs;
04618                         }
04619                 }
04620         }
04621         avep->update();
04622         EXITFUNC;
04623 }

float EMAN::Util::var float *  x,
int  n
[inline, static]
 

Definition at line 1047 of file util.h.

Referenced by multi_align_error_func().

vector< float > Util::vareas EMData d  )  [static]
 

Definition at line 20261 of file util_sparx.cpp.

References data, dm, EMAN::EMData::get_ysize(), and ny.

20261                                     {
20262         const float step=0.001f;
20263         int ny = d->get_ysize();
20264         //  input emdata should have size 2xN, where N is number of points
20265         //  output vector should be 2xN, first element is the number of elements
20266         //  associated with this point, second is 0 is the element is touching the border, 1 if it is interior
20267         vector<float> group(2*ny);
20268         for(int i=0; i<2*ny; i++) group[i] = 0.0f;
20269         int K = int(1.0f/step) +1;
20270         int hit = 0;
20271         for(int kx=0; kx<=K; kx++) {
20272                 float tx = kx*step;
20273                 for(int ky=0; ky<=K; ky++) {
20274                         float ty = ky*step;
20275                         float dm = 1.0e23f;
20276                         for(int i=0; i<ny; i++) {
20277                                 float qd = pow(tx-(*d)(0,i),2) + pow(ty-(*d)(1,i),2);
20278                                 if( qd < dm) {
20279                                         dm = qd;
20280                                         hit = i;
20281                                 }
20282                         }
20283                         data(0,hit) += 1.0f;
20284                         if(kx == 0 || ky == 0 || kx == K || ky == K)  data(1,hit) = 1.0f;
20285                 }
20286         }
20287         return  group;
20288 }

void Util::voronoi double *  phi,
double *  theta,
double *  weight,
int  nt
[static]
 

Definition at line 7600 of file util_sparx.cpp.

References ang_to_xyz(), areav_(), Assert, disorder2(), flip23(), key, phi, status, theta, trmsh3_(), weight, x, and y.

07601 {
07602 
07603         ENTERFUNC;
07604 
07605         int *list, *lptr, *lend, *iwk, *key,*lcnt,*indx,*good;
07606         int nt6, n, ier, nout, lnew, mdup, nd;
07607         int i,k,mt,status;
07608 
07609 
07610         double *ds, *x, *y, *z;
07611         double tol  = 1.0e-8;
07612         double dtol = 15;
07613         double a;
07614 
07615         /*if(last){
07616                 if(medium>nt)  n = nt+nt;
07617                 else           n = nt+nt-medium+1;
07618         }
07619         else{
07620                 n=nt;
07621         }*/
07622 
07623         n = nt + nt;
07624 
07625         nt6 = n*6;
07626 
07627         list = (int*)calloc(nt6,sizeof(int));
07628         lptr = (int*)calloc(nt6,sizeof(int));
07629         lend = (int*)calloc(n  ,sizeof(int));
07630         iwk  = (int*)calloc(n  ,sizeof(int));
07631         good = (int*)calloc(n  ,sizeof(int));
07632         key  = (int*)calloc(n  ,sizeof(int));
07633         indx = (int*)calloc(n  ,sizeof(int));
07634         lcnt = (int*)calloc(n  ,sizeof(int));
07635 
07636         ds      =       (double*) calloc(n,sizeof(double));
07637         x       =       (double*) calloc(n,sizeof(double));
07638         y       =       (double*) calloc(n,sizeof(double));
07639         z       =       (double*) calloc(n,sizeof(double));
07640 
07641         if (list == NULL ||
07642         lptr == NULL ||
07643         lend == NULL ||
07644         iwk  == NULL ||
07645         good == NULL ||
07646         key  == NULL ||
07647         indx == NULL ||
07648         lcnt == NULL ||
07649         x    == NULL ||
07650         y    == NULL ||
07651         z    == NULL ||
07652         ds   == NULL) {
07653                 printf("memory allocation failure!\n");
07654                 exit(1);
07655         }
07656 
07657         bool colinear=true;
07658         while(colinear)
07659         {
07660 
07661         L1:
07662             for(i = 0; i<nt; i++){
07663                 x[i] = theta[i];
07664                 y[i] = phi[i];
07665                 x[nt+i] = 180.0 - x[i];
07666                 y[nt+i] = 180.0 + y[i];
07667             }
07668 
07669             Util::disorder2(x, y, key, n);
07670 
07671             // check if the first three angles are not close, else shuffle
07672             double val;
07673             for(k=0; k<2; k++){
07674                 for(i=k+1; i<3; i++){
07675                     val = (x[i]-x[k])*(x[i]-x[k]) + (y[i]-y[k])*(y[i]-y[k]);
07676                     if( val  < dtol) {
07677                         goto L1;
07678                     }
07679                 }
07680             }
07681 
07682             Util::ang_to_xyz(x, y, z, n);
07683 
07684             //  Make sure that first three has no duplication
07685             bool dupnode=true;
07686             dupnode=true;
07687             while(dupnode)
07688             {
07689                 for(k=0; k<2; k++){
07690                     for(i=k+1; i<3; i++){
07691                         if(  x[i]*x[k]+y[i]*y[k]+z[i]*z[k] > 1.0-tol) {
07692                                 Util::flip23(x, y, z, key, k, n);
07693                                 continue;
07694                         }
07695                     }
07696                 }
07697                 dupnode = false;
07698             }
07699 
07700 
07701             ier = 0;
07702 
07703             status = Util::trmsh3_(&n,&tol,x,y,z,&nout,list,lptr,lend,&lnew, indx, lcnt, iwk, good, ds, &ier);
07704 
07705             if (status != 0) {
07706                 printf(" error in trmsh3 \n");
07707                 exit(1);
07708             }
07709 
07710             if (ier > 0) {
07711                 printf("*** Error in TRMESH:  duplicate nodes encountered ***\n");
07712                 exit(1);
07713             }
07714 
07715             mdup=n-nout;
07716             if (ier == -2) {
07717                 //printf("in TRMESH:the first three nodes are colinear*** disorder again\n");
07718             }
07719             else
07720             {
07721                 colinear=false;
07722             }
07723         }
07724 
07725 
07726         Assert( ier != -2 );
07727 //  Create a list of unique nodes GOOD, the numbers refer to locations on the full list
07728 //  INDX contains node numbers from the squeezed list
07729         nd=0;
07730         for (k=1; k<=n; k++){
07731                 if (indx[k-1]>0) {
07732                         nd++;
07733                         good[nd-1]=k;
07734                 }
07735         }
07736 
07737 //
07738 // *** Compute the Voronoi region areas.
07739 //
07740         for(i = 1; i<=nout; i++) {
07741                 k=good[i-1];
07742                 //  We only need n weights from hemisphere
07743                 if (key[k-1] <= nt) {
07744 //  CALCULATE THE AREA
07745                         a = Util::areav_(&i, &nout, x, y, z, list, lptr, lend, &ier);
07746                         if (ier != 0){
07747 //  We set the weight to -1, this will signal the error in the calling
07748 //   program, as the area will turn out incorrect
07749                                 printf("    *** error in areav:  ier = %d ***\n", ier);
07750                                 weight[key[k-1]-1] =-1.0;
07751                         } else {
07752 //  Assign the weight
07753                                 weight[key[k-1]-1]=a/lcnt[i-1];
07754                         }
07755                 }
07756         }
07757 
07758 
07759 // Fill out the duplicated weights
07760         for(i = 1; i<=n; i++){
07761                 mt =- indx[i-1];
07762                 if (mt>0){
07763                         k = good[mt-1];
07764 //  This is a duplicated entry, get the already calculated
07765 //   weight and assign it.
07766                 //  We only need n weights from hemisphere
07767                         if (key[i-1] <= nt && key[k-1] <= nt) { weight[key[i-1]-1] = weight[key[k-1]-1];}
07768                         }
07769         }
07770 
07771         free(list);
07772         free(lend);
07773         free(iwk);
07774         free(good);
07775         free(key);
07776         free(lptr);
07777         free(indx);
07778         free(lcnt);
07779         free(ds);
07780         free(x);
07781         free(y);
07782         free(z);
07783 
07784 
07785         EXITFUNC;
07786 }

void EMAN::Util::voronoidiag double *  theta,
double *  phi,
double *  weight,
int  n
[static]
 

vector< double > Util::vrdg const vector< float > &  ph,
const vector< float > &  th
[static]
 

Definition at line 7177 of file util_sparx.cpp.

References hsortd(), ImageFormatException, key, LOGERR, phi, theta, voronoi(), and weight.

07178 {
07179 
07180         ENTERFUNC;
07181 
07182         if ( th.size() != ph.size() ) {
07183                 LOGERR("images not same size");
07184                 throw ImageFormatException( "images not same size");
07185         }
07186 
07187         // rand_seed
07188         srand(10);
07189 
07190         int i,*key;
07191         int len = th.size();
07192         double *theta,*phi,*weight;
07193         theta   =       (double*) calloc(len,sizeof(double));
07194         phi     =       (double*) calloc(len,sizeof(double));
07195         weight  =       (double*) calloc(len,sizeof(double));
07196         key     =       (int*) calloc(len,sizeof(int));
07197         const float *thptr, *phptr;
07198 
07199         thptr = &th[0];
07200         phptr = &ph[0];
07201         for(i=1;i<=len;i++){
07202                 key(i) = i;
07203                 weight(i) = 0.0;
07204         }
07205 
07206         for(i = 0;i<len;i++){
07207                 theta[i] = thptr[i];
07208                 phi[i]   = phptr[i];
07209         }
07210 
07211         //  sort by theta
07212         Util::hsortd(theta, phi, key, len, 1);
07213 
07214         //Util::voronoidiag(theta,phi, weight, len);
07215         Util::voronoi(phi, theta, weight, len);
07216 
07217         //sort by key
07218         Util::hsortd(weight, weight, key, len, 2);
07219 
07220         free(theta);
07221         free(phi);
07222         free(key);
07223         vector<double> wt;
07224         double count = 0;
07225         for(i=1; i<= len; i++)
07226         {
07227                 wt.push_back(weight(i));
07228                 count += weight(i);
07229         }
07230 
07231         //if( abs(count-6.28) > 0.1 )
07232         //{
07233         //    printf("Warning: SUM OF VORONOI CELLS AREAS IS %lf, should 2*PI\n", count);
07234         //}
07235 
07236         free(weight);
07237 
07238         EXITFUNC;
07239         return wt;
07240 
07241 }

EMData * Util::window EMData img,
int  new_nx,
int  new_ny = 1,
int  new_nz = 1,
int  x_offset = 0,
int  y_offset = 0,
int  z_offset = 0
[static]
 

Definition at line 5335 of file util_sparx.cpp.

References EMAN::EMData::copy_empty_head(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, inp, NullPointerException, nx, ny, outp, EMAN::EMData::set_size(), and EMAN::EMData::update().

05336 {
05337         /* Exception Handle */
05338         if (!img) throw NullPointerException("NULL input image");
05339         /* ============================== */
05340 
05341         // Get the size of the input image
05342         int nx=img->get_xsize(), ny=img->get_ysize(), nz=img->get_zsize();
05343         /* ============================== */
05344 
05345         /* Exception Handle */
05346         if(new_nx>nx || new_ny>ny || new_nz>nz)
05347                 throw ImageDimensionException("The size of the windowed image cannot exceed the input image size.");
05348         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)
05349                 throw ImageDimensionException("The offset inconsistent with the input image size.");
05350         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))))
05351                 throw ImageDimensionException("The offset inconsistent with the input image size.");
05352         /* ============================== */
05353 
05354         /*    Calculation of the start point */
05355         int  new_st_x = nx/2-new_nx/2 + x_offset,
05356              new_st_y = ny/2-new_ny/2 + y_offset,
05357              new_st_z = nz/2-new_nz/2 + z_offset;
05358         /* ============================== */
05359 
05360         /* Exception Handle */
05361         if (new_st_x<0 || new_st_y<0 || new_st_z<0)   //  WHAT HAPPENS WITH THE END POINT CHECK??  PAP
05362                 throw ImageDimensionException("The offset inconsistent with the input image size.");
05363         /* ============================== */
05364 
05365         EMData* wind = img->copy_empty_head();
05366         wind->set_size(new_nx, new_ny, new_nz);
05367         float *outp=wind->get_data();
05368         float *inp=img->get_data();
05369 
05370         for (int k=0; k<new_nz; k++)
05371                 for(int j=0; j<new_ny; j++)
05372                         for(int i=0; i<new_nx; i++)
05373                                 outp(i,j,k) = inp(i,j,k);
05374         wind->update();
05375         return wind;
05376 }

void Util::WTF EMData PROJ,
vector< float >  SS,
float  SNR,
int  K
[static]
 

Definition at line 5823 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.

05824 {
05825         int NSAM,NROW,NNNN,NR2,L,JY,KX,NANG;
05826         float WW,OX,OY;
05827 
05828         NSAM = PROJ->get_xsize();
05829         NROW = PROJ->get_ysize();
05830         int ntotal = NSAM*NROW;
05831         float q = 2.0f;
05832         float qt = 8.0f/q;
05833         //  Fix for padding 2x
05834         int ipad = 1;
05835         NSAM *= ipad;
05836         NROW *= ipad;
05837         NNNN = NSAM+2-(NSAM%2);
05838         int NX2 = NSAM/2;
05839         NR2  = NROW/2;
05840 
05841         NANG = int(SS.size())/6;
05842 
05843         EMData* W = new EMData();
05844         int Wnx = NNNN/2;
05845         W->set_size(Wnx,NROW,1);
05846         W->to_zero();
05847         float *Wptr = W->get_data();
05848         float *PROJptr = PROJ->get_data();
05849         for (L=1; L<=NANG; L++) {
05850                 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);
05851                 float  tmp2 = SS(4,L)*( SS(1,K)*SS(2,L) - SS(1,L)*SS(2,K) ); 
05852                 OX = SS(6,K)*tmp2 + SS(5,K)*tmp1;
05853                 OY = SS(5,K)*tmp2 - SS(6,K)*tmp1;
05854                 if(OX < 0.0f) {
05855                         OX = -OX;
05856                         OY = -OY;
05857                 }
05858 
05859                 if( fabs(OX) > 1.0e-6f || fabs(OY) > 1.0e6f ) {
05860                         for(int J=1;J<=NROW;J++) {
05861                                 JY = (J-1);
05862                                 if(JY > NR2) JY -= NROW;
05863 #ifdef _WIN32
05864                                 int xma = _cpp_min(int(0.5f+(q-JY*OY)/OX),NX2);
05865                                 int xmi = _cpp_max(int((-q-JY*OY)/OX+0.5+NSAM)-NSAM,0);
05866 #else
05867                                 int xma = std::min(int(0.5f+(q-JY*OY)/OX),NX2);
05868                                 int xmi = std::max(int((-q-JY*OY)/OX+0.5+NSAM)-NSAM,0);
05869 #endif  //_WIN32
05870                                 if( xmi <= xma) {
05871                                         for(int I=xmi;I<=xma;I++) {
05872                                                 float Y = fabs(OX*I + OY*JY);
05873                                                 W(I+1,J) += exp(-qt*Y*Y);
05874         //cout << " L   "<<L << " I   "<<I << " JY   "<<JY << " ARG   "<<qt*Y*Y <<endl;
05875                                         }
05876                                 }
05877                         }
05878                 } else {
05879                         for(int J=1;J<=NROW;J++) for(int I=1;I<=NNNN/2;I++)  W(I,J) += 1.0f;
05880                 }
05881         }
05882         EMData* proj_in = PROJ;
05883 
05884         PROJ = PROJ->norm_pad( false, ipad);
05885         PROJ->do_fft_inplace();
05886         PROJ->update();
05887         //cout << " x   "<<PROJ->get_xsize() << " y   "<<PROJ->get_ysize() <<endl;
05888         PROJptr = PROJ->get_data();
05889 
05890         float WNRMinv,temp;
05891         float osnr = 1.0f/SNR;
05892         WNRMinv = 1.0f/W(1,1);
05893         for(int J=1;J<=NROW;J++)  {
05894                 JY = J-1;
05895                 if( JY > NR2)  JY -= NROW;
05896                 float sy = JY;
05897                 sy /= NROW;
05898                 sy *= sy;
05899                 for(int I=1;I<=NNNN;I+=2) {
05900                         KX           = (I+1)/2;
05901                         temp         = W(KX,J)*WNRMinv;
05902                         WW           = temp/(temp*temp + osnr);
05903                         // This is supposed to fix fall-off due to Gaussian function in the weighting function
05904                         float sx = KX-1;
05905                         sx /= NSAM;
05906                         WW *= exp(qt*(sy + sx*sx));
05907                         PROJ(I,J)   *= WW;
05908                         PROJ(I+1,J) *= WW;
05909                 }
05910         }
05911         delete W; W = 0;
05912         PROJ->do_ift_inplace();
05913         PROJ->depad();
05914 
05915         float* data_src = PROJ->get_data();
05916         float* data_dst = proj_in->get_data();
05917 
05918         for( int i=0; i < ntotal; ++i )  data_dst[i] = data_src[i];
05919 
05920         proj_in->update();
05921 
05922         delete PROJ;
05923 }

void Util::WTM EMData PROJ,
vector< float >  SS,
int  DIAMETER,
int  NUMP
[static]
 

Definition at line 6017 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.

06018 {
06019         float rad2deg =(180.0f/3.1415926f);
06020         float deg2rad = (3.1415926f/180.0f);
06021 
06022         int NSAM,NROW,NNNN,NR2,NANG,L,JY;
06023 
06024         NSAM = PROJ->get_xsize();
06025         NROW = PROJ->get_ysize();
06026         NNNN = NSAM+2-(NSAM%2);
06027         NR2  = NROW/2;
06028         NANG = int(SS.size())/6;
06029 
06030         float RI[9];
06031         RI(1,1)=SS(1,NUMP)*SS(3,NUMP)*SS(5,NUMP)-SS(2,NUMP)*SS(6,NUMP);
06032         RI(2,1)=-SS(1,NUMP)*SS(3,NUMP)*SS(6,NUMP)-SS(2,NUMP)*SS(5,NUMP);
06033         RI(3,1)=SS(1,NUMP)*SS(4,NUMP);
06034         RI(1,2)=SS(2,NUMP)*SS(3,NUMP)*SS(5,NUMP)+SS(1,NUMP)*SS(6,NUMP);
06035         RI(2,2)=-SS(2,NUMP)*SS(3,NUMP)*SS(6,NUMP)+SS(1,NUMP)*SS(5,NUMP);
06036         RI(3,2)=SS(2,NUMP)*SS(4,NUMP);
06037         RI(1,3)=-SS(4,NUMP)*SS(5,NUMP);
06038         RI(2,3)=SS(4,NUMP)*SS(6,NUMP);
06039         RI(3,3)=SS(3,NUMP);
06040 
06041         float THICK=static_cast<float>( NSAM)/DIAMETER/2.0f ;
06042 
06043         EMData* W = new EMData();
06044         int Wnx = NNNN/2;
06045         W->set_size(NNNN/2,NROW,1);
06046         W->to_one();
06047         float *Wptr = W->get_data();
06048 
06049         float ALPHA,TMP,FV,RT,FM,CCN,CC[3],CP[2],VP[2],VV[3];
06050 
06051         for (L=1; L<=NANG; L++) {
06052                 if (L != NUMP) {
06053                         CC(1)=SS(2,L)*SS(4,L)*SS(3,NUMP)-SS(3,L)*SS(2,NUMP)*SS(4,NUMP);
06054                         CC(2)=SS(3,L)*SS(1,NUMP)*SS(4,NUMP)-SS(1,L)*SS(4,L)*SS(3,NUMP);
06055                         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);
06056 
06057                         TMP = sqrt(CC(1)*CC(1) +  CC(2)*CC(2) + CC(3)*CC(3));
06058                         CCN=static_cast<float>( AMAX1( AMIN1(TMP,1.0) ,-1.0) );
06059                         ALPHA=rad2deg*float(asin(CCN));
06060                         if (ALPHA>180.0f) ALPHA=ALPHA-180.0f;
06061                         if (ALPHA>90.0f) ALPHA=180.0f-ALPHA;
06062                         if(ALPHA<1.0E-6) {
06063                                 for(int J=1;J<=NROW;J++) for(int I=1;I<=NNNN/2;I++) W(I,J)+=1.0;
06064                         } else {
06065                                 FM=THICK/(fabs(sin(ALPHA*deg2rad)));
06066                                 CC(1)   = CC(1)/CCN;CC(2)   = CC(2)/CCN;CC(3)   = CC(3)/CCN;
06067                                 VV(1)= SS(2,L)*SS(4,L)*CC(3)-SS(3,L)*CC(2);
06068                                 VV(2)= SS(3,L)*CC(1)-SS(1,L)*SS(4,L)*CC(3);
06069                                 VV(3)= SS(1,L)*SS(4,L)*CC(2)-SS(2,L)*SS(4,L)*CC(1);
06070                                 CP(1)   = 0.0;CP(2) = 0.0;
06071                                 VP(1)   = 0.0;VP(2) = 0.0;
06072 
06073                                 CP(1) = CP(1) + RI(1,1)*CC(1) + RI(1,2)*CC(2) + RI(1,3)*CC(3);
06074                                 CP(2) = CP(2) + RI(2,1)*CC(1) + RI(2,2)*CC(2) + RI(2,3)*CC(3);
06075                                 VP(1) = VP(1) + RI(1,1)*VV(1) + RI(1,2)*VV(2) + RI(1,3)*VV(3);
06076                                 VP(2) = VP(2) + RI(2,1)*VV(1) + RI(2,2)*VV(2) + RI(2,3)*VV(3);
06077 
06078                                 TMP = CP(1)*VP(2)-CP(2)*VP(1);
06079 
06080                                 //     PREVENT TMP TO BE TOO SMALL, SIGN IS IRRELEVANT
06081                                 TMP = AMAX1(1.0E-4f,fabs(TMP));
06082                                 float tmpinv = 1.0f/TMP;
06083                                 for(int J=1;J<=NROW;J++) {
06084                                         JY = (J-1);
06085                                         if (JY>NR2)  JY=JY-NROW;
06086                                         for(int I=1;I<=NNNN/2;I++) {
06087                                                 FV     = fabs((JY*CP(1)-(I-1)*CP(2))*tmpinv);
06088                                                 RT     = 1.0f-FV/FM;
06089                                                 W(I,J) += ((RT>0.0f)*RT);
06090                                         }
06091                                 }
06092                         }
06093                 }
06094         }
06095 
06096         EMData* proj_in = PROJ;
06097 
06098         PROJ = PROJ->norm_pad( false, 1);
06099         PROJ->do_fft_inplace();
06100         PROJ->update();
06101         float *PROJptr = PROJ->get_data();
06102 
06103         int KX;
06104         float WW;
06105         for(int J=1; J<=NROW; J++)
06106                 for(int I=1; I<=NNNN; I+=2) {
06107                         KX          =  (I+1)/2;
06108                         WW          =  1.0f/W(KX,J);
06109                         PROJ(I,J)   = PROJ(I,J)*WW;
06110                         PROJ(I+1,J) = PROJ(I+1,J)*WW;
06111                 }
06112         delete W; W = 0;
06113         PROJ->do_ift_inplace();
06114         PROJ->depad();
06115 
06116         float* data_src = PROJ->get_data();
06117         float* data_dst = proj_in->get_data();
06118 
06119         int ntotal = NSAM*NROW;
06120         for( int i=0; i < ntotal; ++i )  data_dst[i] = data_src[i];
06121 
06122         proj_in->update();
06123         delete PROJ;
06124 }


The documentation for this class was generated from the following files:
Generated on Mon May 2 13:31:34 2011 for EMAN2 by  doxygen 1.3.9.1